Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

feat: add service model assignments settings (#14712)

AmAzing-eb924ec88160
diff --git a/locales/en-US/setting.json b/locales/en-US/setting.json
index 98b6ecf4550..63668f41041 100644
--- a/locales/en-US/setting.json
+++ b/locales/en-US/setting.json
@@ -268,9 +268,9 @@
"danger.reset.desc": "Restore all settings to defaults. Your data wont be deleted.",
"danger.reset.success": "All settings have been reset",
"danger.reset.title": "Reset All Settings",
- "defaultAgent.model.desc": "Default model used when creating a new Agent",
+ "defaultAgent.model.desc": "Model used when creating new agents",
"defaultAgent.model.title": "Model",
- "defaultAgent.title": "Default Agent Settings",
+ "defaultAgent.title": "New Agent",
"group.aiConfig": "Agent",
"group.common": "General",
"group.profile": "Account",
@@ -492,6 +492,8 @@
"plugin.settings.tooltip": "Skill Configuration",
"plugin.store": "Skill Store",
"publishToCommunity": "Publish to Community",
+ "serviceModel.modelAssignments.title": "Model Assignments",
+ "serviceModel.optionalFeatures.title": "Optional Features",
"settingAgent.avatar.sizeExceeded": "Image size exceeds 1MB limit, please choose a smaller image",
"settingAgent.avatar.title": "Avatar",
"settingAgent.backgroundColor.title": "Background Color",
@@ -813,35 +815,35 @@
"sync.webrtc.signaling.title": "Signaling Server",
"sync.webrtc.title": "WebRTC Sync",
"systemAgent.agentMeta.label": "Model",
- "systemAgent.agentMeta.modelDesc": "Model designated for generating agent name, description, avatar, and tags",
- "systemAgent.agentMeta.title": "Agent Info Generation Helper",
+ "systemAgent.agentMeta.modelDesc": "Model used to generate names, descriptions, avatars, and tags",
+ "systemAgent.agentMeta.title": "Profile Generation",
"systemAgent.customPrompt.addPrompt": "Add Custom Prompt",
"systemAgent.customPrompt.desc": "Once filled out, the system agent will use the custom prompt when generating content",
"systemAgent.customPrompt.placeholder": "Please enter custom prompt",
"systemAgent.customPrompt.title": "Custom Prompt",
"systemAgent.generationTopic.label": "Model",
- "systemAgent.generationTopic.modelDesc": "Model designated for automatic naming of AI image topics",
- "systemAgent.generationTopic.title": "AI Image Topic Naming Agent",
+ "systemAgent.generationTopic.modelDesc": "Model used to name AI image topics",
+ "systemAgent.generationTopic.title": "AI Image Topic Naming",
"systemAgent.helpInfo": "When creating a new agent, the default agent settings will be used as preset values.",
"systemAgent.historyCompress.label": "Model",
- "systemAgent.historyCompress.modelDesc": "Specify the model used to compress conversation history",
- "systemAgent.historyCompress.title": "Conversation History Compression Agent",
+ "systemAgent.historyCompress.modelDesc": "Model used to compress conversation history",
+ "systemAgent.historyCompress.title": "Conversation History Compression",
"systemAgent.inputCompletion.label": "Model",
- "systemAgent.inputCompletion.modelDesc": "Model used for input auto-completion suggestions (like GitHub Copilot ghost text)",
- "systemAgent.inputCompletion.title": "Input Auto-Completion Agent",
+ "systemAgent.inputCompletion.modelDesc": "Suggests text while you type. When enabled, this model generates the suggestions.",
+ "systemAgent.inputCompletion.title": "Input Suggestions",
"systemAgent.promptRewrite.label": "Model",
- "systemAgent.promptRewrite.modelDesc": "Specify the model used to rewrite prompts",
- "systemAgent.promptRewrite.title": "Prompt Rewrite Agent",
+ "systemAgent.promptRewrite.modelDesc": "Improves prompts before generation. When enabled, this model rewrites the prompt.",
+ "systemAgent.promptRewrite.title": "Prompt Rewriting",
"systemAgent.thread.label": "Model",
- "systemAgent.thread.modelDesc": "The model designated for automatic renaming of subtopics",
- "systemAgent.thread.title": "Subtopic Auto-Naming Agent",
- "systemAgent.title": "System Agents",
+ "systemAgent.thread.modelDesc": "Model used to rename subtopics",
+ "systemAgent.thread.title": "Subtopic Auto-Naming",
+ "systemAgent.title": "System Tasks",
"systemAgent.topic.label": "Model",
- "systemAgent.topic.modelDesc": "Model designated for automatic topic renaming",
- "systemAgent.topic.title": "Topic Auto-Naming Agent",
+ "systemAgent.topic.modelDesc": "Model used to rename topics",
+ "systemAgent.topic.title": "Topic Auto-Naming",
"systemAgent.translation.label": "Model",
- "systemAgent.translation.modelDesc": "Specify the model used for translation",
- "systemAgent.translation.title": "Message Translation Agent",
+ "systemAgent.translation.modelDesc": "Model used to translate messages",
+ "systemAgent.translation.title": "Message Translation",
"tab.about": "About",
"tab.addAgentSkill": "Add Agent Skill",
"tab.addCustomMcp": "Add Custom MCP Skill",
diff --git a/locales/zh-CN/setting.json b/locales/zh-CN/setting.json
index 3adc1a9a192..957ffef738c 100644
--- a/locales/zh-CN/setting.json
+++ b/locales/zh-CN/setting.json
@@ -268,9 +268,9 @@
"danger.reset.desc": "恢复所有设置为默认值。您的数据不会被删除。",
"danger.reset.success": "已重置所有设置",
"danger.reset.title": "重置所有设置",
- "defaultAgent.model.desc": "创建新助理时使用的默认模型",
+ "defaultAgent.model.desc": "创建新助理时使用的模型",
"defaultAgent.model.title": "模型",
- "defaultAgent.title": "默认助理设置",
+ "defaultAgent.title": "新建助理",
"group.aiConfig": "智能体",
"group.common": "通用",
"group.profile": "账号",
@@ -492,6 +492,8 @@
"plugin.settings.tooltip": "技能配置",
"plugin.store": "技能商店",
"publishToCommunity": "发布到社区",
+ "serviceModel.modelAssignments.title": "模型分配",
+ "serviceModel.optionalFeatures.title": "可选功能",
"settingAgent.avatar.sizeExceeded": "图片大小超过 1MB 限制,请选择更小的图片",
"settingAgent.avatar.title": "助理头像",
"settingAgent.backgroundColor.title": "头像背景色",
@@ -813,35 +815,35 @@
"sync.webrtc.signaling.title": "信令服务器",
"sync.webrtc.title": "WebRTC 同步",
"systemAgent.agentMeta.label": "模型",
- "systemAgent.agentMeta.modelDesc": "指定用于生成助理名称、描述、头像、标签的模型",
- "systemAgent.agentMeta.title": "助理信息生成助理",
+ "systemAgent.agentMeta.modelDesc": "用于生成名称、描述、头像和标签的模型",
+ "systemAgent.agentMeta.title": "档案信息生成",
"systemAgent.customPrompt.addPrompt": "添加自定义提示",
"systemAgent.customPrompt.desc": "填写后,系统助理将在生成内容时使用自定义提示",
"systemAgent.customPrompt.placeholder": "请输入自定义提示词",
"systemAgent.customPrompt.title": "自定义提示词",
"systemAgent.generationTopic.label": "模型",
- "systemAgent.generationTopic.modelDesc": "指定用于 AI 图片自动命名话题的模型",
- "systemAgent.generationTopic.title": "AI 图片话题命名助理",
+ "systemAgent.generationTopic.modelDesc": "用于自动命名 AI 图片话题的模型",
+ "systemAgent.generationTopic.title": "AI 图片话题命名",
"systemAgent.helpInfo": "当创建新助理时,将以默认助理设置作为预设值。",
"systemAgent.historyCompress.label": "模型",
- "systemAgent.historyCompress.modelDesc": "指定用于压缩会话历史的模型",
- "systemAgent.historyCompress.title": "会话历史压缩助理",
+ "systemAgent.historyCompress.modelDesc": "用于压缩会话历史的模型",
+ "systemAgent.historyCompress.title": "会话历史压缩",
"systemAgent.inputCompletion.label": "模型",
- "systemAgent.inputCompletion.modelDesc": "指定用于输入自动补全建议的模型(类似 GitHub Copilot 幽灵文本)",
- "systemAgent.inputCompletion.title": "输入自动补全助理",
+ "systemAgent.inputCompletion.modelDesc": "输入时生成文本建议。开启后,由该模型生成建议。",
+ "systemAgent.inputCompletion.title": "输入建议",
"systemAgent.promptRewrite.label": "模型",
- "systemAgent.promptRewrite.modelDesc": "指定用于重写提示词的模型",
- "systemAgent.promptRewrite.title": "提示词重写助理",
+ "systemAgent.promptRewrite.modelDesc": "生成前优化提示词。开启后,由该模型改写提示词。",
+ "systemAgent.promptRewrite.title": "提示词改写",
"systemAgent.thread.label": "模型",
- "systemAgent.thread.modelDesc": "指定用于子话题自动重命名的模型",
- "systemAgent.thread.title": "子话题自动命名助理",
- "systemAgent.title": "系统助理",
+ "systemAgent.thread.modelDesc": "用于自动命名子话题的模型",
+ "systemAgent.thread.title": "子话题自动命名",
+ "systemAgent.title": "系统任务",
"systemAgent.topic.label": "模型",
- "systemAgent.topic.modelDesc": "指定用于话题自动重命名的模型",
- "systemAgent.topic.title": "话题自动命名助理",
+ "systemAgent.topic.modelDesc": "用于自动命名话题的模型",
+ "systemAgent.topic.title": "话题自动命名",
"systemAgent.translation.label": "模型",
- "systemAgent.translation.modelDesc": "指定用于翻译的模型",
- "systemAgent.translation.title": "消息内容翻译助理",
+ "systemAgent.translation.modelDesc": "用于翻译消息内容的模型",
+ "systemAgent.translation.title": "消息内容翻译",
"tab.about": "关于",
"tab.addAgentSkill": "添加 Agent 技能",
"tab.addCustomMcp": "添加自定义 MCP 技能",
diff --git a/src/features/ServiceModel/ModelAssignmentsForm.tsx b/src/features/ServiceModel/ModelAssignmentsForm.tsx
new file mode 100644
index 00000000000..427bdad27f6
--- /dev/null
+++ b/src/features/ServiceModel/ModelAssignmentsForm.tsx
@@ -0,0 +1,198 @@
+'use client';
+
+import type { FormGroupItemType, FormItemProps } from '@lobehub/ui';
+import { Flexbox, Form, Icon, Skeleton } from '@lobehub/ui';
+import { Switch } from 'antd';
+import isEqual from 'fast-deep-equal';
+import { Loader2Icon } from 'lucide-react';
+import { memo, useEffect, useState } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { FORM_STYLE } from '@/const/layoutTokens';
+import ModelSelect from '@/features/ModelSelect';
+import { useUserStore } from '@/store/user';
+import { settingsSelectors } from '@/store/user/selectors';
+import type { SystemAgentItem, UserSystemAgentConfigKey } from '@/types/user/settings';
+
+interface SystemAgentModelItem {
+ key: UserSystemAgentConfigKey;
+}
+
+type LoadingKey = 'defaultAgent' | UserSystemAgentConfigKey;
+
+const SYSTEM_AGENT_MODEL_ITEMS: SystemAgentModelItem[] = [
+ { key: 'topic' },
+ { key: 'generationTopic' },
+ { key: 'translation' },
+ { key: 'historyCompress' },
+ { key: 'agentMeta' },
+];
+
+const OPTIONAL_FEATURE_ITEMS: SystemAgentModelItem[] = [
+ { key: 'inputCompletion' },
+ { key: 'promptRewrite' },
+];
+
+const ModelAssignmentsForm = memo(() => {
+ const { t } = useTranslation('setting');
+ const [defaultAgent, systemAgentSettings] = useUserStore(
+ (s) => [settingsSelectors.defaultAgent(s), settingsSelectors.currentSystemAgent(s)],
+ isEqual,
+ );
+ const [updateDefaultAgent, updateSystemAgent, isUserStateInit] = useUserStore((s) => [
+ s.updateDefaultAgent,
+ s.updateSystemAgent,
+ s.isUserStateInit,
+ ]);
+ const [loadingKey, setLoadingKey] = useState<LoadingKey>();
+
+ useEffect(() => {
+ if (loadingKey === 'defaultAgent') setLoadingKey(undefined);
+ }, [defaultAgent.config.model, defaultAgent.config.provider, loadingKey]);
+
+ if (!isUserStateInit) return <Skeleton active paragraph={{ rows: 8 }} title={false} />;
+
+ const updateDefaultAgentModel = async ({
+ model,
+ provider,
+ }: {
+ model: string;
+ provider: string;
+ }) => {
+ setLoadingKey('defaultAgent');
+ try {
+ await updateDefaultAgent({ config: { model, provider } });
+ } finally {
+ setLoadingKey(undefined);
+ }
+ };
+
+ const updateSystemAgentModel = async (
+ key: UserSystemAgentConfigKey,
+ value: Partial<SystemAgentItem>,
+ ) => {
+ setLoadingKey(key);
+ try {
+ await updateSystemAgent(key, value);
+ } finally {
+ setLoadingKey(undefined);
+ }
+ };
+
+ const defaultAgentItem: FormItemProps = {
+ children: (
+ <Flexbox align="center" direction="horizontal" gap={12} style={{ width: 'min(100%, 448px)' }}>
+ <ModelSelect
+ showAbility={false}
+ style={{ minWidth: 0, width: '100%' }}
+ value={defaultAgent.config}
+ onChange={updateDefaultAgentModel}
+ />
+ </Flexbox>
+ ),
+ desc: t('defaultAgent.model.desc'),
+ label: t('defaultAgent.title'),
+ minWidth: undefined,
+ };
+
+ const systemModelItems: FormItemProps[] = SYSTEM_AGENT_MODEL_ITEMS.map(({ key }) => {
+ const value = systemAgentSettings[key];
+
+ return {
+ children: (
+ <Flexbox
+ align="center"
+ direction="horizontal"
+ gap={12}
+ style={{ width: 'min(100%, 448px)' }}
+ >
+ <ModelSelect
+ showAbility={false}
+ style={{ minWidth: 0, width: '100%' }}
+ value={value}
+ onChange={(props) => updateSystemAgentModel(key, props)}
+ />
+ </Flexbox>
+ ),
+ desc: t(`systemAgent.${key}.modelDesc`),
+ label: t(`systemAgent.${key}.title`),
+ minWidth: undefined,
+ } satisfies FormItemProps;
+ });
+
+ const optionalFeatureItems: FormItemProps[] = OPTIONAL_FEATURE_ITEMS.map(({ key }) => {
+ const value = systemAgentSettings[key];
+ const disabled = value.enabled === false;
+
+ return {
+ children: (
+ <Flexbox
+ align="center"
+ direction="horizontal"
+ gap={12}
+ style={{ width: 'min(100%, 448px)' }}
+ >
+ <ModelSelect
+ showAbility={false}
+ style={{ minWidth: 0, width: '100%' }}
+ value={value}
+ onChange={(props) => updateSystemAgentModel(key, props)}
+ />
+ <Flexbox align="center" direction="horizontal" gap={8}>
+ <Switch
+ aria-label={t(`systemAgent.${key}.title`)}
+ checked={value.enabled}
+ loading={loadingKey === key}
+ onChange={(enabled) => updateSystemAgentModel(key, { enabled })}
+ />
+ </Flexbox>
+ </Flexbox>
+ ),
+ desc: t(`systemAgent.${key}.modelDesc`),
+ label: (
+ <span
+ style={{
+ opacity: disabled ? 0.45 : 1,
+ }}
+ >
+ {t(`systemAgent.${key}.title`)}
+ </span>
+ ),
+ minWidth: undefined,
+ } satisfies FormItemProps;
+ });
+
+ const isOptionalFeatureLoading =
+ loadingKey === 'inputCompletion' || loadingKey === 'promptRewrite';
+ const isModelAssignmentLoading = loadingKey && !isOptionalFeatureLoading;
+
+ const modelAssignments: FormGroupItemType = {
+ children: [defaultAgentItem, ...systemModelItems],
+ extra: isModelAssignmentLoading && (
+ <Icon spin icon={Loader2Icon} size={16} style={{ opacity: 0.5 }} />
+ ),
+ title: t('serviceModel.modelAssignments.title'),
+ };
+
+ const optionalFeatures: FormGroupItemType = {
+ children: optionalFeatureItems,
+ extra: isOptionalFeatureLoading && (
+ <Icon spin icon={Loader2Icon} size={16} style={{ opacity: 0.5 }} />
+ ),
+ title: t('serviceModel.optionalFeatures.title'),
+ };
+
+ return (
+ <Form
+ collapsible={false}
+ items={[modelAssignments, optionalFeatures]}
+ itemsType={'group'}
+ variant={'filled'}
+ {...FORM_STYLE}
+ />
+ );
+});
+
+ModelAssignmentsForm.displayName = 'ModelAssignmentsForm';
+
+export default ModelAssignmentsForm;
diff --git a/src/features/ServiceModel/index.ts b/src/features/ServiceModel/index.ts
new file mode 100644
index 00000000000..bdf25a7735b
--- /dev/null
+++ b/src/features/ServiceModel/index.ts
@@ -0,0 +1 @@
+export { default as ModelAssignmentsForm } from './ModelAssignmentsForm';
diff --git a/src/locales/default/setting.ts b/src/locales/default/setting.ts
index 9d513211994..a90baab60f8 100644
--- a/src/locales/default/setting.ts
+++ b/src/locales/default/setting.ts
@@ -325,9 +325,9 @@ export default {
'danger.reset.desc': 'Restore all settings to defaults. Your data wont be deleted.',
'danger.reset.success': 'All settings have been reset',
'danger.reset.title': 'Reset All Settings',
- 'defaultAgent.model.desc': 'Default model used when creating a new Agent',
+ 'defaultAgent.model.desc': 'Model used when creating new agents',
'defaultAgent.model.title': 'Model',
- 'defaultAgent.title': 'Default Agent Settings',
+ 'defaultAgent.title': 'New Agent',
'group.aiConfig': 'Agent',
'group.common': 'General',
'group.profile': 'Account',
@@ -785,6 +785,8 @@ export default {
'settingSystem.oauth.signout.confirm': 'Confirm sign out?',
'settingSystem.oauth.signout.success': 'Sign out successful',
'settingSystem.title': 'System Settings',
+ 'serviceModel.modelAssignments.title': 'Model Assignments',
+ 'serviceModel.optionalFeatures.title': 'Optional Features',
'settingSystemTools.appEnvironment.chromium.desc': 'Chromium browser engine version',
'settingSystemTools.appEnvironment.desc': 'Built-in runtime versions in the desktop app',
'settingSystemTools.appEnvironment.electron.desc': 'Electron framework version',
@@ -940,40 +942,39 @@ When I am ___, I need ___
'sync.webrtc.title': 'WebRTC Sync',
'systemAgent.agentMeta.label': 'Model',
'systemAgent.agentMeta.modelDesc':
- 'Model designated for generating agent name, description, avatar, and tags',
- 'systemAgent.agentMeta.title': 'Agent Info Generation Helper',
+ 'Model used to generate names, descriptions, avatars, and tags',
+ 'systemAgent.agentMeta.title': 'Profile Generation',
'systemAgent.customPrompt.addPrompt': 'Add Custom Prompt',
'systemAgent.customPrompt.desc':
'Once filled out, the system agent will use the custom prompt when generating content',
'systemAgent.customPrompt.placeholder': 'Please enter custom prompt',
'systemAgent.customPrompt.title': 'Custom Prompt',
'systemAgent.generationTopic.label': 'Model',
- 'systemAgent.generationTopic.modelDesc':
- 'Model designated for automatic naming of AI image topics',
- 'systemAgent.generationTopic.title': 'AI Image Topic Naming Agent',
+ 'systemAgent.generationTopic.modelDesc': 'Model used to name AI image topics',
+ 'systemAgent.generationTopic.title': 'AI Image Topic Naming',
'systemAgent.helpInfo':
'When creating a new agent, the default agent settings will be used as preset values.',
'systemAgent.historyCompress.label': 'Model',
- 'systemAgent.historyCompress.modelDesc':
- 'Specify the model used to compress conversation history',
- 'systemAgent.historyCompress.title': 'Conversation History Compression Agent',
+ 'systemAgent.historyCompress.modelDesc': 'Model used to compress conversation history',
+ 'systemAgent.historyCompress.title': 'Conversation History Compression',
'systemAgent.inputCompletion.label': 'Model',
'systemAgent.inputCompletion.modelDesc':
- 'Model used for input auto-completion suggestions (like GitHub Copilot ghost text)',
- 'systemAgent.inputCompletion.title': 'Input Auto-Completion Agent',
+ 'Suggests text while you type. When enabled, this model generates the suggestions.',
+ 'systemAgent.inputCompletion.title': 'Input Suggestions',
'systemAgent.promptRewrite.label': 'Model',
- 'systemAgent.promptRewrite.modelDesc': 'Specify the model used to rewrite prompts',
- 'systemAgent.promptRewrite.title': 'Prompt Rewrite Agent',
+ 'systemAgent.promptRewrite.modelDesc':
+ 'Improves prompts before generation. When enabled, this model rewrites the prompt.',
+ 'systemAgent.promptRewrite.title': 'Prompt Rewriting',
'systemAgent.thread.label': 'Model',
- 'systemAgent.thread.modelDesc': 'The model designated for automatic renaming of subtopics',
- 'systemAgent.thread.title': 'Subtopic Auto-Naming Agent',
- 'systemAgent.title': 'System Agents',
+ 'systemAgent.thread.modelDesc': 'Model used to rename subtopics',
+ 'systemAgent.thread.title': 'Subtopic Auto-Naming',
+ 'systemAgent.title': 'System Tasks',
'systemAgent.topic.label': 'Model',
- 'systemAgent.topic.modelDesc': 'Model designated for automatic topic renaming',
- 'systemAgent.topic.title': 'Topic Auto-Naming Agent',
+ 'systemAgent.topic.modelDesc': 'Model used to rename topics',
+ 'systemAgent.topic.title': 'Topic Auto-Naming',
'systemAgent.translation.label': 'Model',
- 'systemAgent.translation.modelDesc': 'Specify the model used for translation',
- 'systemAgent.translation.title': 'Message Translation Agent',
+ 'systemAgent.translation.modelDesc': 'Model used to translate messages',
+ 'systemAgent.translation.title': 'Message Translation',
'tab.about': 'About',
'tab.advanced': 'Advanced',
'tab.addAgentSkill': 'Add Agent Skill',
diff --git a/src/routes/(main)/settings/service-model/index.tsx b/src/routes/(main)/settings/service-model/index.tsx
index 504e98f492c..13a394ddf3a 100644
--- a/src/routes/(main)/settings/service-model/index.tsx
+++ b/src/routes/(main)/settings/service-model/index.tsx
@@ -2,10 +2,10 @@
import { useTranslation } from 'react-i18next';
+import { ModelAssignmentsForm } from '@/features/ServiceModel';
import SettingHeader from '@/routes/(main)/settings/features/SettingHeader';
import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig';
-import SystemAgentForm from '../agent/features/SystemAgentForm';
import Image from '../image/features/Image';
import OpenAI from '../tts/features/OpenAI';
import STT from '../tts/features/STT';
@@ -16,13 +16,7 @@ const Page = () => {
return (
<>
<SettingHeader title={t('tab.serviceModel')} />
- <SystemAgentForm systemAgentKey="topic" />
- <SystemAgentForm systemAgentKey="generationTopic" />
- <SystemAgentForm systemAgentKey="translation" />
- <SystemAgentForm systemAgentKey="historyCompress" />
- <SystemAgentForm systemAgentKey="agentMeta" />
- <SystemAgentForm allowDisable systemAgentKey="inputCompletion" />
- <SystemAgentForm allowDisable systemAgentKey="promptRewrite" />
+ <ModelAssignmentsForm />
{enableSTT && (
<>
<STT />
diff --git a/src/store/user/slices/settings/action.test.ts b/src/store/user/slices/settings/action.test.ts
index d8a8e395f40..c51217b413a 100644
--- a/src/store/user/slices/settings/action.test.ts
+++ b/src/store/user/slices/settings/action.test.ts
@@ -127,6 +127,28 @@ describe('SettingsAction', () => {
expect.any(AbortSignal),
);
});
+
+ it('should persist default agent model and provider together', async () => {
+ const { result } = renderHook(() => useUserStore());
+
+ await act(async () => {
+ await result.current.updateDefaultAgent({
+ config: { model: 'claude-opus-4-6' },
+ });
+ });
+
+ expect(userService.updateUserSettings).toHaveBeenLastCalledWith(
+ {
+ defaultAgent: {
+ config: {
+ model: 'claude-opus-4-6',
+ provider: DEFAULT_SETTINGS.defaultAgent.config.provider,
+ },
+ },
+ },
+ expect.any(AbortSignal),
+ );
+ });
});
describe('updateSystemAgent', () => {
diff --git a/src/store/user/slices/settings/action.ts b/src/store/user/slices/settings/action.ts
index 51bf8a37c9b..f217d911116 100644
--- a/src/store/user/slices/settings/action.ts
+++ b/src/store/user/slices/settings/action.ts
@@ -17,6 +17,8 @@ import {
import { difference } from '@/utils/difference';
import { merge } from '@/utils/merge';
+import { settingsSelectors } from './selectors/settings';
+
type Setter = StoreSetter<UserStore>;
export const createSettingsSlice = (set: Setter, get: () => UserStore, _api?: unknown) =>
new UserSettingsActionImpl(set, get, _api);
@@ -89,7 +91,10 @@ export class UserSettingsActionImpl {
const diffs = difference(nextSettings, defaultSettings);
const isEmptyObjectDiff = (value: unknown): boolean =>
- !!value && typeof value === 'object' && !Array.isArray(value) && Object.keys(value as object).length === 0;
+ !!value &&
+ typeof value === 'object' &&
+ !Array.isArray(value) &&
+ Object.keys(value as object).length === 0;
// When user resets a field to default value, we need to explicitly include it in diffs
// to override the previously saved non-default value in the backend
@@ -102,6 +107,34 @@ export class UserSettingsActionImpl {
}
}
+ const nextDefaultAgentConfig = nextSettings.defaultAgent?.config;
+ const changedDefaultAgentConfig = changedFields.defaultAgent?.config;
+ const hasDefaultAgentModelProviderChange =
+ !!changedDefaultAgentConfig &&
+ ('model' in changedDefaultAgentConfig || 'provider' in changedDefaultAgentConfig);
+ const defaultAgentModelProviderDiffersFromDefault =
+ nextDefaultAgentConfig?.model !== defaultSettings.defaultAgent?.config?.model ||
+ nextDefaultAgentConfig?.provider !== defaultSettings.defaultAgent?.config?.provider;
+
+ if (
+ hasDefaultAgentModelProviderChange &&
+ (defaultAgentModelProviderDiffersFromDefault || 'defaultAgent' in prevSetting) &&
+ nextDefaultAgentConfig?.model &&
+ nextDefaultAgentConfig.provider
+ ) {
+ const defaultAgentDiff = diffs.defaultAgent || {};
+ const configDiff = defaultAgentDiff.config || {};
+
+ diffs.defaultAgent = {
+ ...defaultAgentDiff,
+ config: {
+ ...configDiff,
+ model: nextDefaultAgentConfig.model,
+ provider: nextDefaultAgentConfig.provider,
+ },
+ };
+ }
+
this.#set({ settings: diffs }, false, 'optimistic_updateSettings');
const abortController = this.#get().internal_createSignal();
@@ -110,7 +143,27 @@ export class UserSettingsActionImpl {
};
updateDefaultAgent = async (defaultAgent: PartialDeep<LobeAgentSettings>): Promise<void> => {
- await this.#get().setSettings({ defaultAgent });
+ const config = defaultAgent.config;
+ const shouldNormalizeModelProvider =
+ config && (config.model !== undefined || config.provider !== undefined);
+
+ if (!shouldNormalizeModelProvider) {
+ await this.#get().setSettings({ defaultAgent });
+ return;
+ }
+
+ const currentConfig = settingsSelectors.defaultAgentConfig(this.#get());
+
+ await this.#get().setSettings({
+ defaultAgent: {
+ ...defaultAgent,
+ config: {
+ ...config,
+ model: config.model ?? currentConfig.model,
+ provider: config.provider ?? currentConfig.provider,
+ },
+ },
+ });
};
updateGeneralConfig = async (general: Partial<UserGeneralConfig>): Promise<void> => {