Skip to content

A programming framework for agentic AI

Add support for default model client, in AGS updates to settings UI (#5763)

Victor Dibia6625f89c28bb
diff --git a/python/packages/autogen-studio/autogenstudio/datamodel/types.py b/python/packages/autogen-studio/autogenstudio/datamodel/types.py
index 31767606a..28b6d1b78 100644
--- a/python/packages/autogen-studio/autogenstudio/datamodel/types.py
+++ b/python/packages/autogen-studio/autogenstudio/datamodel/types.py
@@ -5,7 +5,8 @@ from typing import Any, Dict, List, Literal, Optional
from autogen_agentchat.base import TaskResult
from autogen_agentchat.messages import BaseChatMessage
from autogen_core import ComponentModel
-from pydantic import BaseModel, ConfigDict, Field
+from autogen_ext.models.openai import OpenAIChatCompletionClient
+from pydantic import BaseModel, ConfigDict
class MessageConfig(BaseModel):
@@ -84,8 +85,16 @@ class EnvironmentVariable(BaseModel):
required: bool = False
+class UISettings(BaseModel):
+ show_llm_call_events: bool = False
+ expanded_messages_by_default: bool = True
+ show_agent_flow_by_default: bool = True
+
+
class SettingsConfig(BaseModel):
environment: List[EnvironmentVariable] = []
+ default_model_client: Optional[ComponentModel] = OpenAIChatCompletionClient(model="gpt-4o-mini").dump_component()
+ ui: UISettings = UISettings()
# web request/response data models
diff --git a/python/packages/autogen-studio/autogenstudio/web/routes/settingsroute.py b/python/packages/autogen-studio/autogenstudio/web/routes/settingsroute.py
index e4468c957..0e6a0466e 100644
--- a/python/packages/autogen-studio/autogenstudio/web/routes/settingsroute.py
+++ b/python/packages/autogen-studio/autogenstudio/web/routes/settingsroute.py
@@ -15,10 +15,11 @@ async def get_settings(user_id: str, db=Depends(get_db)) -> Dict:
response = db.get(Settings, filters={"user_id": user_id})
if not response.status or not response.data:
# create a default settings
- config = SettingsConfig(environment=[])
+ config = SettingsConfig()
default_settings = Settings(user_id=user_id, config=config.model_dump())
db.upsert(default_settings)
response = db.get(Settings, filters={"user_id": user_id})
+ # print(response.data[0])
return {"status": True, "data": response.data[0]}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e)) from e
diff --git a/python/packages/autogen-studio/frontend/src/components/types/datamodel.ts b/python/packages/autogen-studio/frontend/src/components/types/datamodel.ts
index 027188d11..228a0f1a4 100644
--- a/python/packages/autogen-studio/frontend/src/components/types/datamodel.ts
+++ b/python/packages/autogen-studio/frontend/src/components/types/datamodel.ts
@@ -356,8 +356,17 @@ export interface EnvironmentVariable {
required: boolean;
}
+export interface UISettings {
+ show_llm_call_events: boolean;
+ expanded_messages_by_default?: boolean;
+ show_agent_flow_by_default?: boolean;
+ // You can add more UI settings here as needed
+}
+
export interface SettingsConfig {
environment: EnvironmentVariable[];
+ default_model_client?: Component<ModelConfig>;
+ ui: UISettings;
}
export interface Settings extends DBModel {
diff --git a/python/packages/autogen-studio/frontend/src/components/views/playground/chat/logrenderer.tsx b/python/packages/autogen-studio/frontend/src/components/views/playground/chat/logrenderer.tsx
index d4f3d61aa..4b626bccd 100644
--- a/python/packages/autogen-studio/frontend/src/components/views/playground/chat/logrenderer.tsx
+++ b/python/packages/autogen-studio/frontend/src/components/views/playground/chat/logrenderer.tsx
@@ -164,8 +164,6 @@ const LLMLogRenderer: React.FC<LLMLogRendererProps> = ({ content }) => {
const totalTokens = response.usage.total_tokens;
const shortAgentId = agent_id ? `${agent_id.split("/")[0]}` : "";
- console.log("log event full", content);
-
return (
<>
<div className="flex items-center gap-2 py-2 bg-secondary/20 rounded-lg text-sm text-secondary hover:text-primary transition-colors group">
diff --git a/python/packages/autogen-studio/frontend/src/components/views/playground/chat/runview.tsx b/python/packages/autogen-studio/frontend/src/components/views/playground/chat/runview.tsx
index 99cbc527b..9e4f362fa 100644
--- a/python/packages/autogen-studio/frontend/src/components/views/playground/chat/runview.tsx
+++ b/python/packages/autogen-studio/frontend/src/components/views/playground/chat/runview.tsx
@@ -100,18 +100,18 @@ const RunView: React.FC<RunViewProps> = ({
const [isExpanded, setIsExpanded] = useState(true);
const threadContainerRef = useRef<HTMLDivElement | null>(null);
const isActive = run.status === "active" || run.status === "awaiting_input";
- const [isFlowVisible, setIsFlowVisible] = useState(true);
- const showLLMEvents = useSettingsStore(
- (state) => state.playground.showLLMEvents
+ const { uiSettings } = useSettingsStore();
+ const [isFlowVisible, setIsFlowVisible] = useState(
+ uiSettings.show_agent_flow_by_default ?? true
);
const visibleMessages = useMemo(() => {
- if (showLLMEvents) {
+ if (uiSettings.show_llm_call_events) {
return run.messages;
}
return run.messages.filter((msg) => msg.config.source !== "llm_call_event");
- }, [run.messages, showLLMEvents]);
+ }, [run.messages, uiSettings.show_llm_call_events]);
// Replace existing scroll effect with this simpler one
useEffect(() => {
diff --git a/python/packages/autogen-studio/frontend/src/components/views/settings/environment.tsx b/python/packages/autogen-studio/frontend/src/components/views/settings/environment.tsx
deleted file mode 100644
index 9d5f27626..000000000
--- a/python/packages/autogen-studio/frontend/src/components/views/settings/environment.tsx
+++ /dev/null
@@ -1,238 +0,0 @@
-import React, { useState, useEffect, useContext } from "react";
-import { Button, Input, Select, Table, Switch, message, Tooltip } from "antd";
-import { Plus, Trash2, Save } from "lucide-react";
-import { appContext } from "../../../hooks/provider";
-import { settingsAPI } from "./api";
-import {
- Settings,
- EnvironmentVariable,
- EnvironmentVariableType,
-} from "../../types/datamodel";
-
-const DEFAULT_SETTINGS: Settings = {
- config: {
- environment: [],
- },
-};
-
-export const EnvironmentVariables: React.FC = () => {
- const [settings, setSettings] = useState<Settings>(DEFAULT_SETTINGS);
- const [loading, setLoading] = useState(true);
- const [isDirty, setIsDirty] = useState(false);
- const [messageApi, contextHolder] = message.useMessage();
-
- const { user } = useContext(appContext);
- const userId = user?.email || "";
-
- useEffect(() => {
- loadSettings();
- }, []);
-
- const loadSettings = async () => {
- try {
- setLoading(true);
- const data = await settingsAPI.getSettings(userId);
- setSettings(data);
- setIsDirty(false);
- } catch (error) {
- console.error("Failed to load settings:", error);
- setSettings(DEFAULT_SETTINGS);
- messageApi.error("Failed to load environment variables");
- } finally {
- setLoading(false);
- }
- };
-
- const handleAddVariable = () => {
- const newVar: EnvironmentVariable = {
- name: "",
- value: "",
- type: "string",
- required: false,
- };
-
- const newSettings = {
- ...settings,
- config: {
- ...settings.config,
- environment: [...settings.config.environment, newVar],
- },
- };
-
- setSettings(newSettings);
- handleSave(newSettings);
- };
-
- const handleSave = async (settingsToSave: Settings) => {
- try {
- const sanitizedSettings = {
- id: settingsToSave.id,
- config: settingsToSave.config,
- user_id: userId,
- };
- await settingsAPI.updateSettings(sanitizedSettings, userId);
- setIsDirty(false);
- messageApi.success("Environment variables saved successfully");
- } catch (error) {
- console.error("Failed to save settings:", error);
- messageApi.error("Failed to save environment variables");
- }
- };
-
- const updateEnvironmentVariable = (
- index: number,
- updates: Partial<EnvironmentVariable>
- ) => {
- const newEnv = [...settings.config.environment];
- newEnv[index] = { ...newEnv[index], ...updates };
- setSettings({
- ...settings,
- config: { ...settings.config, environment: newEnv },
- });
- setIsDirty(true);
- };
-
- const ENVIRONMENT_VARIABLE_TYPES: EnvironmentVariableType[] = [
- "string",
- "number",
- "boolean",
- "secret",
- ];
-
- const columns = [
- {
- title: "Name",
- dataIndex: "name",
- key: "name",
- render: (text: string, _: EnvironmentVariable, index: number) => (
- <Input
- value={text}
- placeholder="Variable name"
- onChange={(e) =>
- updateEnvironmentVariable(index, { name: e.target.value })
- }
- />
- ),
- },
- {
- title: "Value",
- dataIndex: "value",
- key: "value",
- render: (_: string, record: EnvironmentVariable, index: number) => (
- <Input.Password
- value={record.value}
- placeholder="Variable value"
- onChange={(e) =>
- updateEnvironmentVariable(index, { value: e.target.value })
- }
- visibilityToggle
- />
- ),
- },
- {
- title: "Type",
- dataIndex: "type",
- key: "type",
- render: (text: string, _: EnvironmentVariable, index: number) => (
- <Select<EnvironmentVariableType>
- value={text as EnvironmentVariableType}
- style={{ width: 120 }}
- onChange={(value) =>
- updateEnvironmentVariable(index, { type: value })
- }
- options={ENVIRONMENT_VARIABLE_TYPES.map((type) => ({
- value: type,
- label: type.charAt(0).toUpperCase() + type.slice(1),
- }))}
- />
- ),
- },
- {
- title: "Required",
- dataIndex: "required",
- key: "required",
- render: (value: boolean, _: EnvironmentVariable, index: number) => (
- <Tooltip title={value ? "Mark as optional" : "Mark as required"}>
- <Switch
- checked={value}
- onChange={(checked) =>
- updateEnvironmentVariable(index, { required: checked })
- }
- />
- </Tooltip>
- ),
- },
- {
- title: "Actions",
- key: "actions",
- render: (_: any, __: any, index: number) => (
- <Tooltip title="Delete variable">
- <Button
- type="text"
- danger
- icon={<Trash2 className="w-4 h-4" />}
- onClick={() => {
- const newEnv = [...settings.config.environment];
- newEnv.splice(index, 1);
- setSettings({
- ...settings,
- config: { ...settings.config, environment: newEnv },
- });
- setIsDirty(true);
- // save
- handleSave({
- ...settings,
- config: { ...settings.config, environment: newEnv },
- });
- }}
- />
- </Tooltip>
- ),
- },
- ];
-
- return (
- <div className="space-y-4">
- {contextHolder}
- <div className="flex justify-between items-center">
- <h3 className="text-lg font-medium"> </h3>
- <div className="space-x-2 inline-flex">
- <Tooltip title="Add new variable">
- <Button
- type="primary"
- icon={<Plus className="w-4 h-4" />}
- onClick={handleAddVariable}
- >
- Add
- </Button>
- </Tooltip>
- <Tooltip title={isDirty ? "Save your changes" : "No unsaved changes"}>
- <Button
- type="primary"
- icon={
- <div className="relative">
- <Save className="w-4 h-4" />
- {isDirty && (
- <div className="absolute -top-1 -right-1 w-2 h-2 bg-red-500 rounded-full" />
- )}
- </div>
- }
- onClick={() => handleSave(settings)}
- >
- Save
- </Button>
- </Tooltip>
- </div>
- </div>
- <Table
- loading={loading}
- dataSource={settings.config.environment}
- columns={columns}
- rowKey={(record) => record.name + record.value}
- pagination={false}
- />
- </div>
- );
-};
-
-export default EnvironmentVariables;
diff --git a/python/packages/autogen-studio/frontend/src/components/views/settings/manager.tsx b/python/packages/autogen-studio/frontend/src/components/views/settings/manager.tsx
index 088981acb..3adfccd1d 100644
--- a/python/packages/autogen-studio/frontend/src/components/views/settings/manager.tsx
+++ b/python/packages/autogen-studio/frontend/src/components/views/settings/manager.tsx
@@ -1,62 +1,19 @@
-import React, { useState, useEffect } from "react";
-import { ChevronRight, RotateCcw, TriangleAlert, Variable } from "lucide-react";
-import { Switch, Button, Tooltip } from "antd";
-import { MessagesSquare } from "lucide-react";
+import React, { useState, useEffect, useContext } from "react";
+import { Tabs, TabsProps } from "antd";
+import {
+ ChevronRight,
+ RotateCcw,
+ Variable,
+ Settings,
+ Palette,
+ Brain,
+} from "lucide-react";
import { useSettingsStore } from "./store";
import { SettingsSidebar } from "./sidebar";
-import { SettingsSection } from "./types";
-import { LucideIcon } from "lucide-react";
-import { EnvironmentVariables } from "./environment";
-
-interface SettingToggleProps {
- checked: boolean;
- onChange: (checked: boolean) => void;
- label: string;
- description?: string;
-}
-
-interface SectionHeaderProps {
- title: string;
- icon: LucideIcon;
- onReset: () => void;
-}
-
-const SettingToggle: React.FC<SettingToggleProps> = ({
- checked,
- onChange,
- label,
- description,
-}) => (
- <div className="flex justify-between items-start p-4 hover:bg-secondary/5 rounded transition-colors">
- <div className="flex flex-col gap-1">
- <label className="font-medium">{label}</label>
- {description && (
- <span className="text-sm text-secondary">{description}</span>
- )}
- </div>
- <Switch defaultValue={checked} onChange={onChange} />
- </div>
-);
-
-const SectionHeader: React.FC<SectionHeaderProps> = ({
- title,
- icon: Icon,
- onReset,
-}) => (
- <div className="flex items-center justify-between mb-6">
- <div className="flex items-center gap-2">
- <Icon className="text-accent" size={20} />
- <h2 className="text-lg font-semibold">{title}</h2>
- </div>
- {/* <Tooltip title="Reset section settings">
- <Button
- icon={<RotateCcw className="w-4 h-4" />}
- onClick={onReset}
- type="text"
- />
- </Tooltip> */}
- </div>
-);
+import { appContext } from "../../../hooks/provider";
+import UISettingsPanel from "./view/ui";
+import { ModelConfigPanel } from "./view/modelconfig";
+import { EnvironmentVariablesPanel } from "./view/environment";
export const SettingsManager: React.FC = () => {
const [isSidebarOpen, setIsSidebarOpen] = useState(() => {
@@ -67,85 +24,91 @@ export const SettingsManager: React.FC = () => {
return true;
});
- const {
- playground,
- updatePlaygroundSettings,
- resetPlaygroundSettings,
- resetAllSettings,
- } = useSettingsStore();
+ const { user } = useContext(appContext);
+ const userId = user?.email || "";
- const sections: SettingsSection[] = [
+ const { serverSettings, resetUISettings, initializeSettings, isLoading } =
+ useSettingsStore();
+
+ // Initialize settings when component mounts
+ useEffect(() => {
+ if (userId) {
+ initializeSettings(userId);
+ }
+ }, [userId, initializeSettings]);
+
+ useEffect(() => {
+ if (typeof window !== "undefined") {
+ localStorage.setItem("settingsSidebar", JSON.stringify(isSidebarOpen));
+ }
+ }, [isSidebarOpen]);
+
+ if (isLoading) {
+ return <div className="p-8 text-center">Loading settings...</div>;
+ }
+
+ // Get model component for the model config panel
+ const modelComponent = serverSettings?.config.default_model_client || {
+ provider: "openai",
+ component_type: "model",
+ label: "Default Model Client",
+ description: "Default model client for this environment",
+ config: {
+ model: "gpt-3.5-turbo",
+ temperature: 0.7,
+ max_tokens: 1000,
+ },
+ };
+
+ const tabItems: TabsProps["items"] = [
+ {
+ key: "ui",
+ label: (
+ <span className="flex items-center gap-2">
+ <Palette className="w-4 h-4" />
+ UI Settings
+ </span>
+ ),
+ children: <UISettingsPanel userId={userId} />,
+ },
{
- id: "playground",
- title: "Playground",
- icon: MessagesSquare,
- content: () => (
- <>
- <SectionHeader
- title="Playground"
- icon={MessagesSquare}
- onReset={resetPlaygroundSettings}
+ key: "model",
+ label: (
+ <span className="flex items-center gap-2">
+ <Brain className="w-4 h-4" />
+ Default Model
+ </span>
+ ),
+ children: (
+ <div className="mt-4">
+ <ModelConfigPanel
+ modelComponent={modelComponent}
+ onModelUpdate={async () => {}}
/>
- <div className="space-y-2 rounded border border-secondary">
- <SettingToggle
- checked={playground.showLLMEvents}
- onChange={(checked) =>
- updatePlaygroundSettings({ showLLMEvents: checked })
- }
- label={"Show LLM Events"}
- description="Display detailed LLM call logs in the message thread"
- />
- </div>
- <div className="mt-12 pt-6 border-t border-secondary">
- <p className="text-xs text-secondary">
- These settings are automatically saved and synced across browser
- sessions
- </p>
- </div>
- </>
+ </div>
),
},
{
- id: "environment",
- title: "Environment Variables",
- icon: Variable,
- content: () => (
- <>
- <SectionHeader
- title="Environment Variables"
- icon={Variable}
- onReset={() => {
- /* Add reset handler */
- }}
+ key: "environment",
+ label: (
+ <span className="flex items-center gap-2">
+ <Variable className="w-4 h-4" />
+ Environment Variables
+ </span>
+ ),
+ children: (
+ <div className="mt-4">
+ <EnvironmentVariablesPanel
+ serverSettings={serverSettings}
+ loading={false}
+ userId={userId}
+ initializeSettings={initializeSettings}
/>
- <div>
- <EnvironmentVariables />
- <div className="mt-12 pt-6 border-t border-secondary">
- <p className="text-xs text-secondary">
- <TriangleAlert
- strokeWidth={1.5}
- className="inline-block mr-1 h-4 w-4 "
- />{" "}
- Note: Environment variables are currently available to all
- processes on the server.
- </p>
- </div>
- </div>
- </>
+ </div>
),
},
];
- const [currentSection, setCurrentSection] = useState<SettingsSection>(
- sections[0]
- );
-
- useEffect(() => {
- if (typeof window !== "undefined") {
- localStorage.setItem("settingsSidebar", JSON.stringify(isSidebarOpen));
- }
- }, [isSidebarOpen]);
-
return (
<div className="relative flex h-full w-full">
<div
@@ -155,10 +118,22 @@ export const SettingsManager: React.FC = () => {
>
<SettingsSidebar
isOpen={isSidebarOpen}
- sections={sections}
- currentSection={currentSection}
+ sections={[
+ {
+ id: "settings",
+ title: "Settings",
+ icon: Variable,
+ content: () => <></>,
+ },
+ ]}
+ currentSection={{
+ id: "settings",
+ title: "Settings",
+ icon: Variable,
+ content: () => <></>,
+ }}
onToggle={() => setIsSidebarOpen(!isSidebarOpen)}
- onSelectSection={setCurrentSection}
+ onSelectSection={() => {}}
/>
</div>
@@ -170,11 +145,23 @@ export const SettingsManager: React.FC = () => {
<div className="p-4 pt-2">
<div className="flex items-center gap-2 mb-4 text-sm">
<span className="text-primary font-medium">Settings</span>
- <ChevronRight className="w-4 h-4 text-secondary" />
- <span className="text-secondary">{currentSection.title}</span>
</div>
- <currentSection.content />
+ <div className="flex items-center gap-2 mb-8 text-sm">
+ <span className="text-secondary">
+ Manage your settings and preferences
+ </span>
+ </div>
+
+ <div className=" rounded-lg shadow-sm">
+ <Tabs
+ defaultActiveKey="ui"
+ items={tabItems}
+ // type="card"
+ size="large"
+ className="settings-tabs"
+ />
+ </div>
</div>
</div>
</div>
diff --git a/python/packages/autogen-studio/frontend/src/components/views/settings/store.tsx b/python/packages/autogen-studio/frontend/src/components/views/settings/store.tsx
index 9ffffd1ef..201f185de 100644
--- a/python/packages/autogen-studio/frontend/src/components/views/settings/store.tsx
+++ b/python/packages/autogen-studio/frontend/src/components/views/settings/store.tsx
@@ -1,121 +1,97 @@
-//settings/store.tsx
+// store.tsx
import { create } from "zustand";
import { persist } from "zustand/middleware";
-
-interface PlaygroundSettings {
- showLLMEvents: boolean;
- // Future playground settings
- expandedMessagesByDefault?: boolean;
- showAgentFlowByDefault?: boolean;
-}
-
-interface TeamBuilderSettings {
- // Future teambuilder settings
- showAdvancedOptions?: boolean;
- defaultAgentLayout?: "grid" | "list";
-}
-
-interface GallerySettings {
- // Future gallery settings
- viewMode?: "grid" | "list";
- sortBy?: "date" | "popularity";
-}
+import { settingsAPI } from "./api";
+import { Settings, UISettings } from "../../types/datamodel";
+
+// Default UI settings that match the backend defaults
+const DEFAULT_UI_SETTINGS: UISettings = {
+ show_llm_call_events: false,
+ expanded_messages_by_default: false,
+ show_agent_flow_by_default: false,
+};
interface SettingsState {
- playground: PlaygroundSettings;
- teamBuilder: TeamBuilderSettings;
- gallery: GallerySettings;
- // Actions to update settings
- updatePlaygroundSettings: (settings: Partial<PlaygroundSettings>) => void;
- updateTeamBuilderSettings: (settings: Partial<TeamBuilderSettings>) => void;
- updateGallerySettings: (settings: Partial<GallerySettings>) => void;
- // Reset functions
- resetPlaygroundSettings: () => void;
- resetTeamBuilderSettings: () => void;
- resetGallerySettings: () => void;
- resetAllSettings: () => void;
+ // Server-synced settings
+ serverSettings: Settings | null;
+ isLoading: boolean;
+ error: string | null;
+
+ // UI settings - these will be synced with server but kept in local state for performance
+ uiSettings: UISettings;
+
+ // Actions
+ initializeSettings: (userId: string) => Promise<void>;
+ updateUISettings: (settings: Partial<UISettings>) => void; // Simplified to avoid async issues
+ resetUISettings: () => Promise<void>;
}
-const DEFAULT_PLAYGROUND_SETTINGS: PlaygroundSettings = {
- showLLMEvents: true, // Default to hiding LLM events
-};
-
-const DEFAULT_TEAMBUILDER_SETTINGS: TeamBuilderSettings = {
- showAdvancedOptions: false,
- defaultAgentLayout: "grid",
-};
-
-const DEFAULT_GALLERY_SETTINGS: GallerySettings = {
- viewMode: "grid",
- sortBy: "date",
+// Helper function to safely access nested properties
+const getUISettings = (settings: Settings | null): UISettings => {
+ if (!settings || !settings.config || !settings.config.ui) {
+ return DEFAULT_UI_SETTINGS;
+ }
+ return settings.config.ui;
};
export const useSettingsStore = create<SettingsState>()(
persist(
- (set) => ({
+ (set, get) => ({
// Initial state
- playground: DEFAULT_PLAYGROUND_SETTINGS,
- teamBuilder: DEFAULT_TEAMBUILDER_SETTINGS,
- gallery: DEFAULT_GALLERY_SETTINGS,
-
- // Update functions
- updatePlaygroundSettings: (settings) =>
- set((state) => ({
- playground: { ...state.playground, ...settings },
- })),
-
- updateTeamBuilderSettings: (settings) =>
- set((state) => ({
- teamBuilder: { ...state.teamBuilder, ...settings },
- })),
-
- updateGallerySettings: (settings) =>
- set((state) => ({
- gallery: { ...state.gallery, ...settings },
- })),
-
- // Reset functions
- resetPlaygroundSettings: () =>
- set((state) => ({
- playground: DEFAULT_PLAYGROUND_SETTINGS,
- })),
-
- resetTeamBuilderSettings: () =>
- set((state) => ({
- teamBuilder: DEFAULT_TEAMBUILDER_SETTINGS,
- })),
-
- resetGallerySettings: () =>
- set((state) => ({
- gallery: DEFAULT_GALLERY_SETTINGS,
- })),
-
- resetAllSettings: () =>
- set({
- playground: DEFAULT_PLAYGROUND_SETTINGS,
- teamBuilder: DEFAULT_TEAMBUILDER_SETTINGS,
- gallery: DEFAULT_GALLERY_SETTINGS,
- }),
+ serverSettings: null,
+ isLoading: false,
+ error: null,
+ uiSettings: DEFAULT_UI_SETTINGS,
+
+ // Load settings from server
+ initializeSettings: async (userId: string) => {
+ // Skip if already loading
+ if (get().isLoading) return;
+
+ try {
+ set({ isLoading: true, error: null });
+ const settings = await settingsAPI.getSettings(userId);
+
+ // Extract UI settings from server response
+ const uiSettings = getUISettings(settings);
+
+ set({
+ serverSettings: settings,
+ uiSettings,
+ isLoading: false,
+ });
+ } catch (error) {
+ console.error("Failed to load settings:", error);
+ set({
+ error: "Failed to load settings",
+ isLoading: false,
+ // Use defaults if server fails
+ uiSettings: DEFAULT_UI_SETTINGS,
+ });
+ }
+ },
+
+ // Update UI settings locally only
+ // The UISettingsPanel component will handle server syncing
+ updateUISettings: (partialSettings: Partial<UISettings>) => {
+ const { uiSettings } = get();
+ const newUISettings = { ...uiSettings, ...partialSettings };
+ set({ uiSettings: newUISettings });
+ },
+
+ // Reset UI settings to defaults - now just resets local state
+ // The UISettingsPanel component will handle actual server resets
+ resetUISettings: async () => {
+ set({ uiSettings: DEFAULT_UI_SETTINGS });
+ return Promise.resolve();
+ },
}),
{
- name: "ags-app-settings",
+ name: "ags-app-settings-0",
partialize: (state) => ({
- playground: state.playground,
- teamBuilder: state.teamBuilder,
- gallery: state.gallery,
+ // Only persist UI settings locally for performance
+ uiSettings: state.uiSettings,
}),
}
)
);
-
-// Example usage:
-/*
-import { useSettingsStore } from './stores/settings';
-
-// In a component:
-const { showLLMEvents } = useSettingsStore((state) => state.playground);
-const updatePlaygroundSettings = useSettingsStore((state) => state.updatePlaygroundSettings);
-
-// Toggle LLM events
-updatePlaygroundSettings({ showLLMEvents: !showLLMEvents });
-*/
diff --git a/python/packages/autogen-studio/frontend/src/components/views/settings/view/environment.tsx b/python/packages/autogen-studio/frontend/src/components/views/settings/view/environment.tsx
new file mode 100644
index 000000000..1ff72e618
--- /dev/null
+++ b/python/packages/autogen-studio/frontend/src/components/views/settings/view/environment.tsx
@@ -0,0 +1,409 @@
+import React, { useContext, useEffect, useRef, useState } from "react";
+import type { BaseSelectRef } from "rc-select";
+import {
+ Button,
+ Form,
+ Input,
+ Select,
+ Table,
+ message,
+ Tooltip,
+ Card,
+} from "antd";
+import type { FormInstance, InputRef } from "antd";
+import { Plus, Trash2, Save, Edit, TriangleAlert } from "lucide-react";
+import { settingsAPI } from "../api";
+import {
+ Settings as SettingsType,
+ EnvironmentVariable,
+ EnvironmentVariableType,
+} from "../../../types/datamodel";
+
+// Create a form context
+const EditableContext = React.createContext<FormInstance | null>(null);
+
+// Define item type for table data
+interface EnvVariableItem {
+ key: string;
+ name: string;
+ value: string;
+ type: EnvironmentVariableType;
+}
+
+// Define editable row props
+interface EditableRowProps {
+ index: number;
+}
+
+// Component for editable rows
+const EditableRow: React.FC<EditableRowProps> = ({ index, ...props }) => {
+ const [form] = Form.useForm();
+ return (
+ <Form form={form} component={false}>
+ <EditableContext.Provider value={form}>
+ <tr {...props} />
+ </EditableContext.Provider>
+ </Form>
+ );
+};
+
+// Define editable cell props
+interface EditableCellProps {
+ title: React.ReactNode;
+ editable: boolean;
+ children: React.ReactNode;
+ dataIndex: keyof EnvVariableItem;
+ record: EnvVariableItem;
+ handleSave: (record: EnvVariableItem) => void;
+ inputType: "text" | "password" | "select";
+ options?: { value: string; label: string }[];
+}
+
+// Component for editable cells
+const EditableCell: React.FC<EditableCellProps> = ({
+ title,
+ editable,
+ children,
+ dataIndex,
+ record,
+ handleSave,
+ inputType,
+ options,
+ ...restProps
+}) => {
+ const [editing, setEditing] = useState(false);
+ const inputRef = useRef<InputRef>(null);
+ const selectRef = useRef<BaseSelectRef>(null);
+ const form = useContext(EditableContext)!;
+
+ useEffect(() => {
+ if (editing) {
+ if (inputType === "select") {
+ selectRef.current?.focus();
+ } else {
+ inputRef.current?.focus();
+ }
+ }
+ }, [editing, inputType]);
+
+ const toggleEdit = () => {
+ setEditing(!editing);
+ form.setFieldsValue({ [dataIndex]: record[dataIndex] });
+ };
+
+ const save = async () => {
+ try {
+ const values = await form.validateFields();
+ toggleEdit();
+ handleSave({ ...record, ...values });
+ } catch (errInfo) {
+ console.log("Save failed:", errInfo);
+ }
+ };
+
+ let childNode = children;
+
+ if (editable) {
+ childNode = editing ? (
+ <Form.Item
+ style={{ margin: 0 }}
+ name={dataIndex}
+ rules={
+ dataIndex === "name"
+ ? [{ required: true, message: `${title} is required.` }]
+ : []
+ }
+ >
+ {inputType === "text" ? (
+ <Input ref={inputRef} onPressEnter={save} onBlur={save} />
+ ) : inputType === "select" ? (
+ <Select
+ ref={selectRef}
+ options={options}
+ onBlur={save}
+ onChange={() => setTimeout(save, 100)}
+ open={editing}
+ style={{ width: "100%" }}
+ />
+ ) : inputType === "password" ? (
+ <Input.Password
+ ref={inputRef}
+ onPressEnter={save}
+ onBlur={save}
+ visibilityToggle
+ />
+ ) : (
+ <Input ref={inputRef} onPressEnter={save} onBlur={save} />
+ )}
+ </Form.Item>
+ ) : (
+ <div
+ className="editable-cell-value-wrap group cursor-pointer"
+ style={{ paddingRight: 24, minHeight: 20 }}
+ onClick={toggleEdit}
+ >
+ <div className="flex items-center">
+ <span className="flex-grow">
+ {inputType === "password"
+ ? "••••••••"
+ : inputType === "select" && options
+ ? options.find((opt) => opt.value === children)?.label || children
+ : children || " "}
+ </span>
+ <Edit className="w-3 h-3 text-gray-400 opacity-0 group-hover:opacity-100 transition-opacity" />
+ </div>
+ </div>
+ );
+ }
+
+ return <td {...restProps}>{childNode}</td>;
+};
+
+type ColumnTypes = {
+ title: string;
+ dataIndex: string;
+ width?: string;
+ editable?: boolean;
+ inputType?: "text" | "password" | "select";
+ options?: { value: string; label: string }[];
+ render?: (text: any, record: EnvVariableItem) => React.ReactNode;
+};
+
+interface EnvironmentVariablesPanelProps {
+ serverSettings: SettingsType | null;
+ loading: boolean;
+ userId: string;
+ initializeSettings: (userId: string) => Promise<void>;
+}
+
+export const EnvironmentVariablesPanel: React.FC<
+ EnvironmentVariablesPanelProps
+> = ({ serverSettings, loading, userId, initializeSettings }) => {
+ const [dataSource, setDataSource] = useState<EnvVariableItem[]>([]);
+ const [isDirty, setIsDirty] = useState(false);
+ const [messageApi, contextHolder] = message.useMessage();
+
+ // Update local state when serverSettings change
+ useEffect(() => {
+ if (serverSettings) {
+ // Transform environment variables into table data
+ const tableData = serverSettings.config.environment.map((env, index) => ({
+ key: `${index}`,
+ name: env.name,
+ value: env.value,
+ type: env.type,
+ }));
+
+ setDataSource(tableData);
+ setIsDirty(false);
+ }
+ }, [serverSettings]);
+
+ // Save settings to API
+ const handleSave = async () => {
+ try {
+ // Transform table data back to environment variables
+ const environment: EnvironmentVariable[] = dataSource.map((item) => ({
+ name: item.name,
+ value: item.value,
+ type: item.type,
+ required: false, // Setting required to false for all items
+ }));
+
+ // Only update if we have serverSettings
+ if (!serverSettings) {
+ messageApi.error("Settings not loaded yet");
+ return;
+ }
+
+ const updatedSettings: SettingsType = {
+ ...serverSettings,
+ config: {
+ ...serverSettings.config,
+ environment,
+ },
+ };
+
+ const sanitizedSettings = {
+ id: updatedSettings.id,
+ config: updatedSettings.config,
+ user_id: userId,
+ };
+
+ await settingsAPI.updateSettings(sanitizedSettings, userId);
+
+ // Refresh settings from server to ensure everything is in sync
+ await initializeSettings(userId);
+
+ setIsDirty(false);
+ messageApi.success("Environment variables saved successfully");
+ } catch (error) {
+ console.error("Failed to save settings:", error);
+ messageApi.error("Failed to save environment variables");
+ }
+ };
+
+ // Handle adding a new variable
+ const handleAdd = async () => {
+ const newVariable: EnvVariableItem = {
+ key: `${dataSource.length + 1}`,
+ name: "",
+ value: "",
+ type: "string",
+ };
+
+ const newDataSource = [...dataSource, newVariable];
+ setDataSource(newDataSource);
+
+ // No auto-save for add since the name field will be empty
+ // Just mark as dirty so user can edit and then save
+ setIsDirty(true);
+ };
+
+ // Handle deleting a variable and auto-save
+ const handleDelete = async (key: string) => {
+ const newDataSource = dataSource.filter((item) => item.key !== key);
+ setDataSource(newDataSource);
+ setIsDirty(true);
+ };
+
+ // Handle saving a cell edit
+ const handleCellSave = async (row: EnvVariableItem) => {
+ const newData = [...dataSource];
+ const index = newData.findIndex((item) => row.key === item.key);
+ const item = newData[index];
+ newData.splice(index, 1, { ...item, ...row });
+ setDataSource(newData);
+ setIsDirty(true);
+ };
+
+ // Environment variable types for select options
+ const ENVIRONMENT_VARIABLE_TYPES: EnvironmentVariableType[] = [
+ "string",
+ "number",
+ "boolean",
+ "secret",
+ ];
+
+ const typeOptions = ENVIRONMENT_VARIABLE_TYPES.map((type) => ({
+ value: type,
+ label: type.charAt(0).toUpperCase() + type.slice(1),
+ }));
+
+ // Define columns
+ const columns: ColumnTypes[] = [
+ {
+ title: "Name",
+ dataIndex: "name",
+ width: "55%",
+ editable: true,
+ inputType: "text",
+ },
+ {
+ title: "Value",
+ dataIndex: "value",
+ width: "45%",
+ editable: true,
+ inputType: "password",
+ },
+ {
+ title: "Actions",
+ dataIndex: "operation",
+ render: (_, record) => (
+ <Tooltip title="Delete variable">
+ <Button
+ type="text"
+ danger
+ icon={<Trash2 className="w-4 h-4" />}
+ onClick={() => handleDelete(record.key)}
+ />
+ </Tooltip>
+ ),
+ },
+ ];
+
+ // Map columns to include cell properties
+ const mergedColumns = columns.map((col) => {
+ if (!col.editable) {
+ return col;
+ }
+ return {
+ ...col,
+ onCell: (record: EnvVariableItem) => ({
+ record,
+ editable: col.editable,
+ dataIndex: col.dataIndex,
+ title: col.title,
+ inputType: col.inputType,
+ options: col.options,
+ handleSave: handleCellSave,
+ }),
+ };
+ });
+
+ // Define custom table components
+ const components = {
+ body: {
+ row: EditableRow,
+ cell: EditableCell,
+ },
+ };
+
+ return (
+ <Card className="shadow-sm">
+ {contextHolder}
+ <div className="flex justify-between items-center mb-4">
+ <h3 className="text-lg font-medium">Environment Variables</h3>
+ <div className="space-x-2 inline-flex">
+ <Tooltip title="Add new variable">
+ <Button
+ type="default"
+ icon={<Plus className="w-4 h-4" />}
+ onClick={handleAdd}
+ >
+ Add
+ </Button>
+ </Tooltip>
+ <Tooltip title={isDirty ? "Save your changes" : "No unsaved changes"}>
+ <Button
+ type="primary"
+ icon={
+ <div className="relative">
+ <Save className="w-4 h-4" />
+ {isDirty && (
+ <div className="absolute -top-1 -right-1 w-2 h-2 bg-red-500 rounded-full" />
+ )}
+ </div>
+ }
+ onClick={handleSave}
+ disabled={!isDirty}
+ >
+ Save
+ </Button>
+ </Tooltip>
+ </div>
+ </div>
+
+ <Table
+ components={components}
+ rowClassName={() => "editable-row"}
+ bordered
+ dataSource={dataSource}
+ columns={mergedColumns as any}
+ pagination={false}
+ loading={loading}
+ />
+
+ <div className="mt-6 pt-4 border-t border-secondary">
+ <p className="text-xs text-secondary">
+ <TriangleAlert
+ strokeWidth={1.5}
+ className="inline-block mr-1 h-4 w-4"
+ />{" "}
+ Note: Environment variables are currently available to all processes
+ on the server.
+ </p>
+ </div>
+ </Card>
+ );
+};
diff --git a/python/packages/autogen-studio/frontend/src/components/views/settings/view/modelconfig.tsx b/python/packages/autogen-studio/frontend/src/components/views/settings/view/modelconfig.tsx
new file mode 100644
index 000000000..f845756c2
--- /dev/null
+++ b/python/packages/autogen-studio/frontend/src/components/views/settings/view/modelconfig.tsx
@@ -0,0 +1,107 @@
+import React, { useState } from "react";
+import { Button, Tooltip, Drawer } from "antd";
+import { Edit2, Settings } from "lucide-react";
+import { truncateText } from "../../../utils";
+import {
+ Component,
+ ComponentConfig,
+ ModelConfig,
+} from "../../../types/datamodel";
+import { ComponentEditor } from "../../teambuilder/builder/component-editor/component-editor";
+
+interface ModelConfigPanelProps {
+ modelComponent: Component<ModelConfig>;
+ onModelUpdate: (updatedModel: Component<ComponentConfig>) => Promise<void>;
+}
+
+export const ModelConfigPanel: React.FC<ModelConfigPanelProps> = ({
+ modelComponent,
+ onModelUpdate,
+}) => {
+ const [isModelEditorOpen, setIsModelEditorOpen] = useState(false);
+
+ const handleOpenModelEditor = () => {
+ setIsModelEditorOpen(true);
+ };
+
+ const handleCloseModelEditor = () => {
+ setIsModelEditorOpen(false);
+ };
+
+ const handleModelUpdate = async (
+ updatedModel: Component<ComponentConfig>
+ ) => {
+ await onModelUpdate(updatedModel);
+ setIsModelEditorOpen(false);
+ };
+
+ return (
+ <>
+ <div className=" ">
+ <div className="flex justify-between items-center mb-4">
+ <h3 className="text-lg font-medium">Default Model Configuration</h3>
+ <Tooltip title="Edit Default Model Settings">
+ <Button
+ type="primary"
+ icon={<Edit2 className="w-4 h-4 mr-1" />}
+ onClick={handleOpenModelEditor}
+ className="flex items-center"
+ >
+ Edit Model
+ </Button>
+ </Tooltip>
+ </div>
+
+ <div className="mb-6">
+ Configure a default model that will be used for system level tasks.
+ </div>
+ <div className="bg-secondary p-4 rounded">
+ <div className="grid grid-cols-2 gap-4">
+ <div>
+ <p className="text-sm font-medium text-primary">Model</p>
+ <p className="text-sm">
+ {modelComponent.label || "" || "Not set"}
+ </p>
+ <p className="text-base">
+ {modelComponent.config?.model || "Not set"}
+ </p>
+ </div>
+ <div>
+ <p className="text-sm font-medium text-primary">Model Provider</p>
+ <p className=" break-all text-sm">
+ {modelComponent.provider || "Not set"}
+ </p>
+ </div>
+ {modelComponent.config?.temperature && (
+ <div>
+ <p className="text-sm font-medium text-primary">Temperature</p>
+ <p className="text-base">
+ {modelComponent.config?.temperature}
+ </p>
+ </div>
+ )}
+ </div>
+ </div>
+ </div>
+
+ {/* Model Editor Drawer */}
+ <Drawer
+ title="Edit Default Model Client"
+ placement="right"
+ size="large"
+ onClose={handleCloseModelEditor}
+ open={isModelEditorOpen}
+ className="component-editor-drawer"
+ >
+ <ComponentEditor
+ component={modelComponent}
+ onChange={handleModelUpdate}
+ onClose={handleCloseModelEditor}
+ navigationDepth={true}
+ />
+ </Drawer>
+ </>
+ );
+};
+
+export default ModelConfigPanel;
diff --git a/python/packages/autogen-studio/frontend/src/components/views/settings/view/panel.tsx b/python/packages/autogen-studio/frontend/src/components/views/settings/view/panel.tsx
new file mode 100644
index 000000000..47bd614dd
--- /dev/null
+++ b/python/packages/autogen-studio/frontend/src/components/views/settings/view/panel.tsx
@@ -0,0 +1,131 @@
+import React, { useContext, useEffect, useState } from "react";
+import { message, Card } from "antd";
+import { appContext } from "../../../../hooks/provider";
+import { settingsAPI } from "../api";
+import {
+ Component,
+ ComponentConfig,
+ ModelConfig,
+ Settings as SettingsType,
+ EnvironmentVariable,
+} from "../../../types/datamodel";
+import { useSettingsStore } from "../store";
+import { EnvironmentVariablesPanel } from "./environment";
+import { ModelConfigPanel } from "./modelconfig";
+
+const DEFAULT_SETTINGS: SettingsType = {
+ config: {
+ environment: [],
+ ui: {
+ show_llm_call_events: false,
+ expanded_messages_by_default: false,
+ show_agent_flow_by_default: false,
+ },
+ },
+};
+
+export const SettingsPanel: React.FC = () => {
+ // const [loading, setLoading] = useState(true);
+ const [messageApi, contextHolder] = message.useMessage();
+ const [isModelEditorOpen, setIsModelEditorOpen] = useState(false);
+
+ const { user } = useContext(appContext);
+ const userId = user?.email || "";
+
+ // Get settings from the store
+ const { serverSettings, initializeSettings } = useSettingsStore();
+
+ // Initialize settings once on component mount
+ // useEffect(() => {
+ // if (userId) {
+ // setLoading(true);
+ // initializeSettings(userId)
+ // .catch((error) => {
+ // console.error("Failed to initialize settings:", error);
+ // messageApi.error("Failed to load settings");
+ // })
+ // .finally(() => {
+ // setLoading(false);
+ // });
+ // }
+ // }, [userId]); // Removed initializeSettings from dependencies
+
+ // Function to create a default model client if none exists
+ const createDefaultModelClient = (): Component<ModelConfig> => {
+ return {
+ provider: "openai",
+ component_type: "model",
+ label: "Default Model Client",
+ description: "Default model client for this environment",
+ config: {
+ model: "gpt-3.5-turbo",
+ temperature: 0.7,
+ max_tokens: 1000,
+ },
+ };
+ };
+
+ // Handle updating the default model client
+ const handleModelUpdate = async (
+ updatedModel: Component<ComponentConfig>
+ ) => {
+ try {
+ if (!serverSettings) {
+ messageApi.error("Settings not loaded yet");
+ return;
+ }
+
+ const updatedSettings: SettingsType = {
+ ...serverSettings,
+ config: {
+ ...serverSettings.config,
+ default_model_client: updatedModel as Component<ModelConfig>,
+ },
+ };
+
+ const sanitizedSettings = {
+ id: updatedSettings.id,
+ config: updatedSettings.config,
+ user_id: userId,
+ };
+
+ await settingsAPI.updateSettings(sanitizedSettings, userId);
+
+ // Refresh settings from server
+ await initializeSettings(userId);
+
+ messageApi.success("Default model client updated successfully");
+ setIsModelEditorOpen(false);
+ } catch (error) {
+ console.error("Failed to update default model client:", error);
+ messageApi.error("Failed to update default model client");
+ }
+ };
+
+ // Get the model component to edit
+ const modelComponent = serverSettings?.config.default_model_client
+ ? serverSettings.config.default_model_client
+ : createDefaultModelClient();
+
+ return (
+ <div className="settings-panel space-y-8">
+ {contextHolder}
+
+ {/* Model Configuration Panel */}
+ <ModelConfigPanel
+ modelComponent={modelComponent}
+ onModelUpdate={handleModelUpdate}
+ />
+
+ {/* Environment Variables Panel */}
+ <EnvironmentVariablesPanel
+ serverSettings={serverSettings}
+ loading={false}
+ userId={userId}
+ initializeSettings={initializeSettings}
+ />
+ </div>
+ );
+};
+
+export default SettingsPanel;
diff --git a/python/packages/autogen-studio/frontend/src/components/views/settings/view/ui.tsx b/python/packages/autogen-studio/frontend/src/components/views/settings/view/ui.tsx
new file mode 100644
index 000000000..896a622be
--- /dev/null
+++ b/python/packages/autogen-studio/frontend/src/components/views/settings/view/ui.tsx
@@ -0,0 +1,259 @@
+import React, { useEffect, useState } from "react";
+import { Button, Tooltip, message } from "antd";
+import { RotateCcw, Save, TriangleAlert } from "lucide-react";
+import { settingsAPI } from "../api";
+import { Settings, UISettings } from "../../../types/datamodel";
+import { useSettingsStore } from "../store";
+
+interface SettingToggleProps {
+ checked: boolean;
+ onChange: (checked: boolean) => void;
+ label: string;
+ description?: string;
+ disabled?: boolean;
+}
+
+const SettingToggle: React.FC<SettingToggleProps> = ({
+ checked,
+ onChange,
+ label,
+ description,
+ disabled = false,
+}) => (
+ <div className="flex justify-between items-start p-4 hover:bg-secondary/5 rounded transition-colors">
+ <div className="flex flex-col gap-1">
+ <label className="font-medium">{label}</label>
+ {description && (
+ <span className="text-sm text-secondary">{description}</span>
+ )}
+ </div>
+ <div className="relative">
+ <input
+ type="checkbox"
+ checked={checked}
+ onChange={(e) => onChange(e.target.checked)}
+ disabled={disabled}
+ className="sr-only"
+ id={`toggle-${label.replace(/\s+/g, "-").toLowerCase()}`}
+ />
+ <label
+ htmlFor={`toggle-${label.replace(/\s+/g, "-").toLowerCase()}`}
+ className={`relative inline-flex items-center h-6 rounded-full w-11 transition-colors focus:outline-none focus:ring-2 focus:ring-accent focus:ring-opacity-50 cursor-pointer ${
+ disabled ? "opacity-50 cursor-not-allowed" : ""
+ } ${checked ? "bg-accent" : "bg-gray-300"}`}
+ >
+ <span
+ className={`inline-block w-4 h-4 transform bg-white rounded-full transition-transform ${
+ checked ? "translate-x-6" : "translate-x-1"
+ }`}
+ />
+ </label>
+ </div>
+ </div>
+);
+
+interface UISettingsPanelProps {
+ userId: string;
+}
+
+export const UISettingsPanel: React.FC<UISettingsPanelProps> = ({ userId }) => {
+ const {
+ serverSettings,
+ uiSettings: storeUISettings,
+ initializeSettings,
+ } = useSettingsStore();
+
+ // Local state for UI settings
+ const [localUISettings, setLocalUISettings] = useState<UISettings>({
+ show_llm_call_events: false,
+ expanded_messages_by_default: false,
+ show_agent_flow_by_default: false,
+ });
+
+ const [isDirty, setIsDirty] = useState(false);
+ const [isSaving, setIsSaving] = useState(false);
+ const [messageApi, contextHolder] = message.useMessage();
+
+ // Initialize local state from store
+ useEffect(() => {
+ setLocalUISettings(storeUISettings);
+ }, [storeUISettings]);
+
+ // Update local state when a setting is changed
+ const handleSettingChange = (key: keyof UISettings, value: boolean) => {
+ setLocalUISettings((prev) => ({
+ ...prev,
+ [key]: value,
+ }));
+ setIsDirty(true);
+ };
+
+ // Reset UI settings to defaults
+ const handleReset = async () => {
+ try {
+ setIsSaving(true);
+
+ if (!serverSettings) {
+ messageApi.error("Settings not loaded");
+ setIsSaving(false);
+ return;
+ }
+
+ // Define default UI settings
+ const DEFAULT_UI_SETTINGS: UISettings = {
+ show_llm_call_events: false,
+ expanded_messages_by_default: false,
+ show_agent_flow_by_default: false,
+ };
+
+ // Update local state
+ setLocalUISettings(DEFAULT_UI_SETTINGS);
+
+ // Prepare for server update
+ const updatedSettings: Settings = {
+ ...serverSettings,
+ config: {
+ ...serverSettings.config,
+ ui: DEFAULT_UI_SETTINGS,
+ },
+ created_at: undefined,
+ updated_at: undefined,
+ };
+
+ console.log("Updated settings:", updatedSettings);
+
+ // Update on server
+ await settingsAPI.updateSettings(updatedSettings, userId);
+
+ // Refresh from server
+ await initializeSettings(userId);
+
+ setIsDirty(false);
+ messageApi.success("UI settings reset successfully");
+ } catch (error) {
+ console.error("Failed to reset UI settings:", error);
+ messageApi.error("Failed to reset UI settings");
+ } finally {
+ setIsSaving(false);
+ }
+ };
+
+ // Save settings to server
+ const handleSave = async () => {
+ try {
+ setIsSaving(true);
+
+ if (!serverSettings) {
+ messageApi.error("Settings not loaded");
+ setIsSaving(false);
+ return;
+ }
+
+ // Prepare updated settings
+ const updatedSettings: Settings = {
+ ...serverSettings,
+ config: {
+ ...serverSettings.config,
+ ui: localUISettings,
+ },
+ created_at: undefined,
+ updated_at: undefined,
+ };
+
+ // Update on server
+ await settingsAPI.updateSettings(updatedSettings, userId);
+
+ // Refresh from server to ensure sync
+ await initializeSettings(userId);
+
+ setIsDirty(false);
+ messageApi.success("UI settings saved successfully");
+ } catch (error) {
+ console.error("Failed to save UI settings:", error);
+ messageApi.error("Failed to save UI settings");
+ } finally {
+ setIsSaving(false);
+ }
+ };
+
+ return (
+ <div className=" ">
+ {contextHolder}
+ <div className="flex justify-between items-center mb-4">
+ <h3 className="text-lg font-medium">UI Settings</h3>
+ <div className="space-x-2 inline-flex">
+ <Tooltip title="Reset to defaults">
+ <Button
+ icon={<RotateCcw className="w-4 h-4" />}
+ onClick={handleReset}
+ disabled={isSaving}
+ >
+ Reset
+ </Button>
+ </Tooltip>
+ <Tooltip title={isDirty ? "Save your changes" : "No unsaved changes"}>
+ <Button
+ type="primary"
+ icon={
+ <div className="relative">
+ <Save className="w-4 h-4" />
+ {isDirty && (
+ <div className="absolute -top-1 -right-1 w-2 h-2 bg-red-500 rounded-full" />
+ )}
+ </div>
+ }
+ onClick={handleSave}
+ disabled={!isDirty || isSaving}
+ loading={isSaving}
+ >
+ Save
+ </Button>
+ </Tooltip>
+ </div>
+ </div>
+
+ <div className="space-y-0 rounded border border-secondary">
+ <SettingToggle
+ checked={localUISettings.show_llm_call_events}
+ onChange={(checked) =>
+ handleSettingChange("show_llm_call_events", checked)
+ }
+ label="Show LLM Events"
+ description="Display detailed LLM call logs in the message thread"
+ disabled={isSaving}
+ />
+
+ <SettingToggle
+ checked={localUISettings.expanded_messages_by_default ?? false}
+ onChange={(checked) =>
+ handleSettingChange("expanded_messages_by_default", checked)
+ }
+ label="Expand Messages by Default"
+ description="Automatically expand message threads when they load"
+ disabled={isSaving}
+ />
+
+ <SettingToggle
+ checked={localUISettings.show_agent_flow_by_default ?? false}
+ onChange={(checked) =>
+ handleSettingChange("show_agent_flow_by_default", checked)
+ }
+ label="Show Agent Flow by Default"
+ description="Display the agent flow diagram automatically"
+ disabled={isSaving}
+ />
+ </div>
+
+ <div className="mt-4 hidden text-xs text-secondary">
+ <TriangleAlert
+ strokeWidth={1.5}
+ className="inline-block mr-1 h-4 w-4"
+ />{" "}
+ These settings are automatically saved and synced across browser
+ sessions
+ </div>
+ </div>
+ );
+};
+
+export default UISettingsPanel;