@lobehub/chat 1.0.11 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/locales/ar/setting.json +5 -0
  3. package/locales/bg-BG/setting.json +5 -0
  4. package/locales/de-DE/setting.json +5 -0
  5. package/locales/en-US/setting.json +5 -0
  6. package/locales/es-ES/setting.json +5 -0
  7. package/locales/fr-FR/setting.json +5 -0
  8. package/locales/it-IT/setting.json +5 -0
  9. package/locales/ja-JP/setting.json +5 -0
  10. package/locales/ko-KR/setting.json +5 -0
  11. package/locales/nl-NL/setting.json +5 -0
  12. package/locales/pl-PL/setting.json +5 -0
  13. package/locales/pt-BR/setting.json +5 -0
  14. package/locales/ru-RU/setting.json +5 -0
  15. package/locales/tr-TR/setting.json +5 -0
  16. package/locales/vi-VN/setting.json +5 -0
  17. package/locales/zh-CN/setting.json +5 -0
  18. package/locales/zh-TW/setting.json +5 -0
  19. package/package.json +4 -3
  20. package/src/app/(main)/chat/(workspace)/@conversation/default.tsx +1 -1
  21. package/src/app/(main)/chat/settings/features/EditPage.tsx +2 -2
  22. package/src/app/(main)/settings/agent/index.tsx +1 -1
  23. package/src/app/(main)/settings/system-agent/features/AgentMeta.tsx +58 -0
  24. package/src/app/(main)/settings/system-agent/features/Topic.tsx +1 -0
  25. package/src/app/(main)/settings/system-agent/features/Translation.tsx +1 -0
  26. package/src/app/(main)/settings/system-agent/index.tsx +2 -0
  27. package/src/app/(main)/settings/system-agent/page.tsx +1 -1
  28. package/src/const/settings/systemAgent.ts +1 -0
  29. package/src/features/AgentSetting/AgentMeta/AutoGenerateAvatar.tsx +59 -0
  30. package/src/features/AgentSetting/AgentMeta/index.tsx +6 -9
  31. package/src/features/AgentSetting/AgentSettings.tsx +24 -0
  32. package/src/features/AgentSetting/AgentSettingsStore.tsx +14 -0
  33. package/src/features/AgentSetting/StoreUpdater.tsx +10 -5
  34. package/src/features/AgentSetting/hooks/useAgentSettings.ts +31 -0
  35. package/src/features/AgentSetting/index.tsx +3 -26
  36. package/src/features/AgentSetting/store/action.ts +36 -18
  37. package/src/features/ChatInput/useSend.ts +8 -0
  38. package/src/features/Conversation/Error/ErrorJsonViewer.tsx +1 -1
  39. package/src/features/Conversation/Messages/Assistant/ToolCalls/index.tsx +3 -2
  40. package/src/features/Conversation/Messages/Tool/index.tsx +3 -5
  41. package/src/features/Conversation/Messages/components/Arguments.tsx +20 -0
  42. package/src/features/Conversation/Messages/hooks/useYamlArguments.ts +11 -0
  43. package/src/features/ModelSelect/index.tsx +6 -4
  44. package/src/libs/agent-runtime/anthropic/index.test.ts +1 -31
  45. package/src/libs/agent-runtime/anthropic/index.ts +9 -63
  46. package/src/libs/agent-runtime/openai/index.test.ts +7 -7
  47. package/src/libs/agent-runtime/openai/index.ts +0 -6
  48. package/src/libs/agent-runtime/utils/anthropicHelpers.ts +2 -2
  49. package/src/libs/agent-runtime/utils/streams/anthropic.test.ts +102 -28
  50. package/src/libs/agent-runtime/utils/streams/anthropic.ts +29 -12
  51. package/src/libs/agent-runtime/utils/streams/protocol.ts +6 -1
  52. package/src/locales/default/setting.ts +5 -0
  53. package/src/services/message/server.ts +4 -0
  54. package/src/services/message/type.ts +1 -1
  55. package/src/store/agent/slices/chat/initialState.ts +2 -0
  56. package/src/store/chat/slices/message/action.ts +48 -48
  57. package/src/store/chat/slices/message/initialState.ts +2 -0
  58. package/src/store/chat/slices/message/selectors.ts +3 -0
  59. package/src/store/chat/slices/plugin/action.test.ts +15 -15
  60. package/src/store/chat/slices/plugin/action.ts +128 -115
  61. package/src/store/chat/utils/index.ts +19 -0
  62. package/src/store/user/slices/settings/action.ts +8 -2
  63. package/src/store/user/slices/settings/selectors/systemAgent.ts +2 -0
  64. package/src/types/message/index.ts +1 -1
  65. package/src/types/user/settings/systemAgent.ts +3 -0
  66. /package/src/{components/StoreHydration → app/(main)/chat/(workspace)/@conversation/features}/ChatHydration/index.tsx +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,56 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.0.13](https://github.com/lobehub/lobe-chat/compare/v1.0.12...v1.0.13)
6
+
7
+ <sup>Released on **2024-06-19**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **misc**: Fix and improve tool calling.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **misc**: Fix and improve tool calling, closes [#2941](https://github.com/lobehub/lobe-chat/issues/2941) ([ea06536](https://github.com/lobehub/lobe-chat/commit/ea06536))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
30
+ ### [Version 1.0.12](https://github.com/lobehub/lobe-chat/compare/v1.0.11...v1.0.12)
31
+
32
+ <sup>Released on **2024-06-19**</sup>
33
+
34
+ #### 🐛 Bug Fixes
35
+
36
+ - **misc**: Fix auto avatar.
37
+
38
+ <br/>
39
+
40
+ <details>
41
+ <summary><kbd>Improvements and Fixes</kbd></summary>
42
+
43
+ #### What's fixed
44
+
45
+ - **misc**: Fix auto avatar, closes [#2939](https://github.com/lobehub/lobe-chat/issues/2939) ([f40300c](https://github.com/lobehub/lobe-chat/commit/f40300c))
46
+
47
+ </details>
48
+
49
+ <div align="right">
50
+
51
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
52
+
53
+ </div>
54
+
5
55
  ### [Version 1.0.11](https://github.com/lobehub/lobe-chat/compare/v1.0.10...v1.0.11)
6
56
 
7
57
  <sup>Released on **2024-06-19**</sup>
@@ -366,6 +366,11 @@
366
366
  }
367
367
  },
368
368
  "systemAgent": {
369
+ "agentMeta": {
370
+ "label": "نموذج إنشاء بيانات المساعد",
371
+ "modelDesc": "يحدد النموذج المستخدم لإنشاء اسم المساعد ووصفه وصورته وعلامته",
372
+ "title": "توليد معلومات المساعد تلقائيًا"
373
+ },
369
374
  "title": "مساعد النظام",
370
375
  "topic": {
371
376
  "label": "نموذج تسمية الموضوع",
@@ -366,6 +366,11 @@
366
366
  }
367
367
  },
368
368
  "systemAgent": {
369
+ "agentMeta": {
370
+ "label": "Модел за генериране на помощни метаданни",
371
+ "modelDesc": "Модел, определен за генериране на име, описание, профилна снимка и етикети на помощник",
372
+ "title": "Автоматично генериране на информация за помощник"
373
+ },
369
374
  "title": "Системен асистент",
370
375
  "topic": {
371
376
  "label": "Модел за именуване на теми",
@@ -366,6 +366,11 @@
366
366
  }
367
367
  },
368
368
  "systemAgent": {
369
+ "agentMeta": {
370
+ "label": "Assistentenmetadaten-Generierungsmodell",
371
+ "modelDesc": "Das Modell, das zur Generierung von Assistentennamen, -beschreibungen, -avatars und -tags verwendet wird",
372
+ "title": "Automatische Generierung von Assistenteninformationen"
373
+ },
369
374
  "title": "Systemassistent",
370
375
  "topic": {
371
376
  "label": "Themenbenennungsmodell",
@@ -366,6 +366,11 @@
366
366
  }
367
367
  },
368
368
  "systemAgent": {
369
+ "agentMeta": {
370
+ "label": "Assistant Metadata Generation Model",
371
+ "modelDesc": "Model designated for generating assistant name, description, avatar, and tags",
372
+ "title": "Automatically Generate Assistant Information"
373
+ },
369
374
  "title": "System Assistants",
370
375
  "topic": {
371
376
  "label": "Topic Naming Model",
@@ -366,6 +366,11 @@
366
366
  }
367
367
  },
368
368
  "systemAgent": {
369
+ "agentMeta": {
370
+ "label": "Modelo de generación de metadatos de asistente",
371
+ "modelDesc": "Modelo designado para generar el nombre, descripción, avatar y etiquetas del asistente",
372
+ "title": "Generación automática de información del asistente"
373
+ },
369
374
  "title": "Asistente del sistema",
370
375
  "topic": {
371
376
  "label": "Modelo de nombramiento de temas",
@@ -366,6 +366,11 @@
366
366
  }
367
367
  },
368
368
  "systemAgent": {
369
+ "agentMeta": {
370
+ "label": "Modèle de génération de métadonnées d'assistant",
371
+ "modelDesc": "Modèle spécifié pour générer le nom, la description, l'avatar et les balises de l'assistant",
372
+ "title": "Génération automatique des informations de l'assistant"
373
+ },
369
374
  "title": "Agent système",
370
375
  "topic": {
371
376
  "label": "Modèle de nommage des sujets",
@@ -366,6 +366,11 @@
366
366
  }
367
367
  },
368
368
  "systemAgent": {
369
+ "agentMeta": {
370
+ "label": "Modello di generazione metadati assistente",
371
+ "modelDesc": "Modello specificato per generare nome, descrizione, avatar e etichetta dell'assistente",
372
+ "title": "Genera automaticamente informazioni sull'assistente"
373
+ },
369
374
  "title": "Assistente di sistema",
370
375
  "topic": {
371
376
  "label": "Modello di denominazione degli argomenti",
@@ -366,6 +366,11 @@
366
366
  }
367
367
  },
368
368
  "systemAgent": {
369
+ "agentMeta": {
370
+ "label": "アシスタントメタデータ生成モデル",
371
+ "modelDesc": "アシスタントの名前、説明、アバター、ラベルを生成するために指定されたモデル",
372
+ "title": "アシスタント情報の自動生成"
373
+ },
369
374
  "title": "システムアシスタント",
370
375
  "topic": {
371
376
  "label": "トピックネーミングモデル",
@@ -366,6 +366,11 @@
366
366
  }
367
367
  },
368
368
  "systemAgent": {
369
+ "agentMeta": {
370
+ "label": "어시스턴트 메타 생성 모델",
371
+ "modelDesc": "어시스턴트 이름, 설명, 프로필 이미지, 레이블을 생성하는 데 사용되는 모델을 지정합니다.",
372
+ "title": "어시스턴트 정보 자동 생성"
373
+ },
369
374
  "title": "시스템 도우미",
370
375
  "topic": {
371
376
  "label": "주제 명명 모델",
@@ -366,6 +366,11 @@
366
366
  }
367
367
  },
368
368
  "systemAgent": {
369
+ "agentMeta": {
370
+ "label": "Assistentmetadata-generatiemodel",
371
+ "modelDesc": "Model voor het genereren van assistentnaam, beschrijving, profielfoto en labels",
372
+ "title": "Automatisch assistentinformatie genereren"
373
+ },
369
374
  "title": "Systeemassistent",
370
375
  "topic": {
371
376
  "label": "Onderwerp Naamgevingsmodel",
@@ -366,6 +366,11 @@
366
366
  }
367
367
  },
368
368
  "systemAgent": {
369
+ "agentMeta": {
370
+ "label": "Model generowania metadanych asystenta",
371
+ "modelDesc": "Określa model używany do generowania nazwy, opisu, awatara i etykiety asystenta",
372
+ "title": "Automatyczne generowanie informacji o asystencie"
373
+ },
369
374
  "title": "Asystent Systemowy",
370
375
  "topic": {
371
376
  "label": "Model nazewnictwa tematów",
@@ -366,6 +366,11 @@
366
366
  }
367
367
  },
368
368
  "systemAgent": {
369
+ "agentMeta": {
370
+ "label": "Modelo de Geração de Metadados do Assistente",
371
+ "modelDesc": "Especifica o modelo usado para gerar o nome, descrição, avatar e tags do assistente",
372
+ "title": "Geração Automática de Informações do Assistente"
373
+ },
369
374
  "title": "Assistente do Sistema",
370
375
  "topic": {
371
376
  "label": "Modelo de Nomeação de Tópicos",
@@ -366,6 +366,11 @@
366
366
  }
367
367
  },
368
368
  "systemAgent": {
369
+ "agentMeta": {
370
+ "label": "Модель генерации метаданных агента",
371
+ "modelDesc": "Модель, используемая для генерации имени агента, описания, аватара и меток",
372
+ "title": "Автоматическое создание информации об агенте"
373
+ },
369
374
  "title": "Системный агент",
370
375
  "topic": {
371
376
  "label": "Модель именования тем",
@@ -366,6 +366,11 @@
366
366
  }
367
367
  },
368
368
  "systemAgent": {
369
+ "agentMeta": {
370
+ "label": "Asistan Meta Veri Oluşturma Modeli",
371
+ "modelDesc": "Asistan adı, açıklaması, avatar ve etiket oluşturmak için belirlenen model",
372
+ "title": "Asistan Bilgilerini Otomatik Oluştur"
373
+ },
369
374
  "title": "Sistem Asistanı",
370
375
  "topic": {
371
376
  "label": "Konu Adlandırma Modeli",
@@ -366,6 +366,11 @@
366
366
  }
367
367
  },
368
368
  "systemAgent": {
369
+ "agentMeta": {
370
+ "label": "Mô hình tạo siêu dữ liệu trợ lý",
371
+ "modelDesc": "Xác định mô hình được sử dụng để tạo tên, mô tả, hình đại diện, nhãn cho trợ lý",
372
+ "title": "Tự động tạo thông tin trợ lý"
373
+ },
369
374
  "title": "Trợ lý hệ thống",
370
375
  "topic": {
371
376
  "label": "Mô hình đặt tên chủ đề",
@@ -366,6 +366,11 @@
366
366
  }
367
367
  },
368
368
  "systemAgent": {
369
+ "agentMeta": {
370
+ "label": "助理元数据生成模型",
371
+ "modelDesc": "指定用于生成助理名称、描述、头像、标签的模型",
372
+ "title": "自动生成助理信息"
373
+ },
369
374
  "title": "系统助手",
370
375
  "topic": {
371
376
  "label": "话题命名模型",
@@ -366,6 +366,11 @@
366
366
  }
367
367
  },
368
368
  "systemAgent": {
369
+ "agentMeta": {
370
+ "label": "助理元數據生成模型",
371
+ "modelDesc": "指定用於生成助理名稱、描述、頭像、標籤的模型",
372
+ "title": "自動生成助理資訊"
373
+ },
369
374
  "title": "系統助手",
370
375
  "topic": {
371
376
  "label": "話題命名模型",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
5
5
  "keywords": [
6
6
  "framework",
@@ -92,7 +92,7 @@
92
92
  },
93
93
  "dependencies": {
94
94
  "@ant-design/icons": "^5.3.7",
95
- "@anthropic-ai/sdk": "^0.21.0",
95
+ "@anthropic-ai/sdk": "^0.23.0",
96
96
  "@auth/core": "0.28.0",
97
97
  "@aws-sdk/client-bedrock-runtime": "^3.583.0",
98
98
  "@aws-sdk/client-s3": "^3.583.0",
@@ -109,7 +109,7 @@
109
109
  "@lobehub/chat-plugins-gateway": "^1.9.0",
110
110
  "@lobehub/icons": "^1.23.0",
111
111
  "@lobehub/tts": "^1.24.1",
112
- "@lobehub/ui": "^1.143.3",
112
+ "@lobehub/ui": "^1.143.5",
113
113
  "@microsoft/fetch-event-source": "^2.0.1",
114
114
  "@neondatabase/serverless": "^0.9.3",
115
115
  "@next/third-parties": "^14.2.3",
@@ -154,6 +154,7 @@
154
154
  "nuqs": "^1.17.4",
155
155
  "ollama": "^0.5.1",
156
156
  "openai": "^4.47.1",
157
+ "partial-json": "^0.1.7",
157
158
  "pg": "^8.11.5",
158
159
  "pino": "^9.1.0",
159
160
  "polished": "^4.3.1",
@@ -1,7 +1,7 @@
1
- import ChatHydration from '@/components/StoreHydration/ChatHydration';
2
1
  import Conversation from '@/features/Conversation';
3
2
  import { isMobileDevice } from '@/utils/responsive';
4
3
 
4
+ import ChatHydration from './features/ChatHydration';
5
5
  import DesktopChatInput from './features/ChatInput/Desktop';
6
6
  import MobileChatInput from './features/ChatInput/Mobile';
7
7
 
@@ -5,7 +5,7 @@ import { memo } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
6
 
7
7
  import PageTitle from '@/components/PageTitle';
8
- import AgentSetting from '@/features/AgentSetting';
8
+ import { AgentSettings } from '@/features/AgentSetting';
9
9
  import { useAgentStore } from '@/store/agent';
10
10
  import { agentSelectors } from '@/store/agent/selectors';
11
11
  import { useSessionStore } from '@/store/session';
@@ -26,7 +26,7 @@ const EditPage = memo(() => {
26
26
  return (
27
27
  <>
28
28
  <PageTitle title={t('header.sessionWithName', { name: title })} />
29
- <AgentSetting
29
+ <AgentSettings
30
30
  config={config}
31
31
  id={id}
32
32
  meta={meta}
@@ -4,7 +4,7 @@ import isEqual from 'fast-deep-equal';
4
4
  import { memo } from 'react';
5
5
 
6
6
  import { INBOX_SESSION_ID } from '@/const/session';
7
- import AgentSettings from '@/features/AgentSetting';
7
+ import { AgentSettings } from '@/features/AgentSetting';
8
8
  import { useUserStore } from '@/store/user';
9
9
  import { settingsSelectors } from '@/store/user/selectors';
10
10
 
@@ -0,0 +1,58 @@
1
+ 'use client';
2
+
3
+ import { Form, type ItemGroup } from '@lobehub/ui';
4
+ import { Form as AntForm } from 'antd';
5
+ import isEqual from 'fast-deep-equal';
6
+ import { memo } from 'react';
7
+ import { useTranslation } from 'react-i18next';
8
+
9
+ import { FORM_STYLE } from '@/const/layoutTokens';
10
+ import ModelSelect from '@/features/ModelSelect';
11
+ import { useUserStore } from '@/store/user';
12
+ import { settingsSelectors } from '@/store/user/selectors';
13
+
14
+ import { useSyncSystemAgent } from './useSync';
15
+
16
+ type SettingItemGroup = ItemGroup;
17
+
18
+ const systemAgentKey = 'agentMeta';
19
+ const AgentMeta = memo(() => {
20
+ const { t } = useTranslation('setting');
21
+ const [form] = AntForm.useForm();
22
+
23
+ const settings = useUserStore(settingsSelectors.currentSystemAgent, isEqual);
24
+ const [updateSystemAgent] = useUserStore((s) => [s.updateSystemAgent]);
25
+
26
+ const systemAgentSettings: SettingItemGroup = {
27
+ children: [
28
+ {
29
+ children: (
30
+ <ModelSelect
31
+ onChange={(props) => {
32
+ updateSystemAgent(systemAgentKey, props);
33
+ }}
34
+ showAbility={false}
35
+ />
36
+ ),
37
+ desc: t(`systemAgent.${systemAgentKey}.modelDesc`),
38
+ label: t(`systemAgent.${systemAgentKey}.label`),
39
+ name: [systemAgentKey, 'model'],
40
+ },
41
+ ],
42
+ title: t(`systemAgent.${systemAgentKey}.title`),
43
+ };
44
+
45
+ useSyncSystemAgent(form);
46
+
47
+ return (
48
+ <Form
49
+ form={form}
50
+ initialValues={settings}
51
+ items={[systemAgentSettings]}
52
+ variant={'pure'}
53
+ {...FORM_STYLE}
54
+ />
55
+ );
56
+ });
57
+
58
+ export default AgentMeta;
@@ -30,6 +30,7 @@ const Topic = memo(() => {
30
30
  onChange={(props) => {
31
31
  updateSystemAgent('topic', props);
32
32
  }}
33
+ showAbility={false}
33
34
  />
34
35
  ),
35
36
  desc: t('systemAgent.topic.modelDesc'),
@@ -30,6 +30,7 @@ const Translation = memo(() => {
30
30
  onChange={(props) => {
31
31
  updateSystemAgent('translation', props);
32
32
  }}
33
+ showAbility={false}
33
34
  />
34
35
  ),
35
36
  desc: t('systemAgent.translation.modelDesc'),
@@ -1,3 +1,4 @@
1
+ import AgentMeta from './features/AgentMeta';
1
2
  import Topic from './features/Topic';
2
3
  import Translation from './features/Translation';
3
4
 
@@ -6,6 +7,7 @@ const Page = () => {
6
7
  <>
7
8
  <Topic />
8
9
  <Translation />
10
+ <AgentMeta />
9
11
  </>
10
12
  );
11
13
  };
@@ -6,7 +6,7 @@ export const generateMetadata = async () => {
6
6
 
7
7
  return metadataModule.generate({
8
8
  description: t('header.desc'),
9
- title: t('tab.systemAgent'),
9
+ title: t('tab.system-agent'),
10
10
  url: '/settings/system-agent',
11
11
  });
12
12
  };
@@ -8,6 +8,7 @@ export const DEFAULT_SYSTEM_AGENT_ITEM: SystemAgentItem = {
8
8
  };
9
9
 
10
10
  export const DEFAULT_SYSTEM_AGENT_CONFIG: UserSystemAgentConfig = {
11
+ agentMeta: DEFAULT_SYSTEM_AGENT_ITEM,
11
12
  topic: DEFAULT_SYSTEM_AGENT_ITEM,
12
13
  translation: DEFAULT_SYSTEM_AGENT_ITEM,
13
14
  };
@@ -0,0 +1,59 @@
1
+ import { ActionIcon } from '@lobehub/ui';
2
+ import { useTheme } from 'antd-style';
3
+ import { Wand2 } from 'lucide-react';
4
+ import dynamic from 'next/dynamic';
5
+ import { memo } from 'react';
6
+ import { useTranslation } from 'react-i18next';
7
+ import { Flexbox } from 'react-layout-kit';
8
+
9
+ import { useUserStore } from '@/store/user';
10
+ import { userGeneralSettingsSelectors } from '@/store/user/selectors';
11
+
12
+ const EmojiPicker = dynamic(() => import('@lobehub/ui/es/EmojiPicker'), { ssr: false });
13
+
14
+ export interface AutoGenerateAvatarProps {
15
+ background?: string;
16
+ canAutoGenerate?: boolean;
17
+ loading?: boolean;
18
+ onChange?: (value: string) => void;
19
+ onGenerate?: () => void;
20
+ value?: string;
21
+ }
22
+
23
+ const AutoGenerateAvatar = memo<AutoGenerateAvatarProps>(
24
+ ({ loading, background, value, onChange, onGenerate, canAutoGenerate }) => {
25
+ const { t } = useTranslation('common');
26
+ const theme = useTheme();
27
+ const locale = useUserStore(userGeneralSettingsSelectors.currentLanguage);
28
+
29
+ return (
30
+ <Flexbox>
31
+ <div style={{ opacity: loading ? 0.6 : undefined }}>
32
+ <EmojiPicker
33
+ backgroundColor={background}
34
+ locale={locale}
35
+ onChange={onChange}
36
+ value={value}
37
+ />
38
+ </div>
39
+ <ActionIcon
40
+ active
41
+ disable={!canAutoGenerate}
42
+ icon={Wand2}
43
+ loading={loading}
44
+ onClick={onGenerate}
45
+ size="small"
46
+ style={{
47
+ bottom: -4,
48
+ color: theme.colorInfo,
49
+ insetInlineEnd: -4,
50
+ position: 'absolute',
51
+ }}
52
+ title={!canAutoGenerate ? t('autoGenerateTooltipDisabled') : t('autoGenerate')}
53
+ />
54
+ </Flexbox>
55
+ );
56
+ },
57
+ );
58
+
59
+ export default AutoGenerateAvatar;
@@ -5,22 +5,18 @@ import { Button } from 'antd';
5
5
  import isEqual from 'fast-deep-equal';
6
6
  import { isString } from 'lodash-es';
7
7
  import { Wand2 } from 'lucide-react';
8
- import dynamic from 'next/dynamic';
9
8
  import { memo } from 'react';
10
9
  import { useTranslation } from 'react-i18next';
11
10
 
12
11
  import { FORM_STYLE } from '@/const/layoutTokens';
13
- import { useUserStore } from '@/store/user';
14
- import { userGeneralSettingsSelectors } from '@/store/user/selectors';
15
12
 
16
13
  import { useStore } from '../store';
17
14
  import { SessionLoadingState } from '../store/initialState';
15
+ import AutoGenerateAvatar from './AutoGenerateAvatar';
18
16
  import AutoGenerateInput from './AutoGenerateInput';
19
17
  import AutoGenerateSelect from './AutoGenerateSelect';
20
18
  import BackgroundSwatches from './BackgroundSwatches';
21
19
 
22
- const EmojiPicker = dynamic(() => import('@lobehub/ui/es/EmojiPicker'), { ssr: false });
23
-
24
20
  const AgentMeta = memo(() => {
25
21
  const { t } = useTranslation('setting');
26
22
 
@@ -30,7 +26,6 @@ const AgentMeta = memo(() => {
30
26
  s.autocompleteMeta,
31
27
  s.autocompleteAllMeta,
32
28
  ]);
33
- const locale = useUserStore(userGeneralSettingsSelectors.currentLanguage);
34
29
  const loading = useStore((s) => s.autocompleteLoading);
35
30
  const meta = useStore((s) => s.meta, isEqual);
36
31
 
@@ -81,10 +76,12 @@ const AgentMeta = memo(() => {
81
76
  children: [
82
77
  {
83
78
  children: (
84
- <EmojiPicker
85
- backgroundColor={meta.backgroundColor}
86
- locale={locale}
79
+ <AutoGenerateAvatar
80
+ background={meta.backgroundColor}
81
+ canAutoGenerate={hasSystemRole}
82
+ loading={loading['avatar']}
87
83
  onChange={(avatar) => updateMeta({ avatar })}
84
+ onGenerate={() => autocompleteMeta('avatar')}
88
85
  value={meta.avatar}
89
86
  />
90
87
  ),
@@ -0,0 +1,24 @@
1
+ import AgentChat from './AgentChat';
2
+ import AgentMeta from './AgentMeta';
3
+ import AgentModal from './AgentModal';
4
+ import AgentPlugin from './AgentPlugin';
5
+ import AgentPrompt from './AgentPrompt';
6
+ import AgentTTS from './AgentTTS';
7
+ import StoreUpdater, { StoreUpdaterProps } from './StoreUpdater';
8
+ import { Provider, createStore } from './store';
9
+
10
+ type AgentSettingsProps = StoreUpdaterProps;
11
+
12
+ export const AgentSettings = (props: AgentSettingsProps) => {
13
+ return (
14
+ <Provider createStore={createStore}>
15
+ <StoreUpdater {...props} />
16
+ <AgentPrompt />
17
+ <AgentMeta />
18
+ <AgentChat />
19
+ <AgentModal />
20
+ <AgentTTS />
21
+ <AgentPlugin />
22
+ </Provider>
23
+ );
24
+ };
@@ -0,0 +1,14 @@
1
+ import { memo } from 'react';
2
+
3
+ import StoreUpdater, { StoreUpdaterProps } from './StoreUpdater';
4
+ import { Provider, createStore } from './store';
5
+
6
+ type AgentSettingsProps = StoreUpdaterProps;
7
+
8
+ export const AgentSettingsStore = memo<AgentSettingsProps>((props) => {
9
+ return (
10
+ <Provider createStore={createStore}>
11
+ <StoreUpdater {...props} />
12
+ </Provider>
13
+ );
14
+ });
@@ -1,16 +1,18 @@
1
1
  'use client';
2
2
 
3
- import { memo } from 'react';
3
+ import { ForwardedRef, memo, useImperativeHandle } from 'react';
4
4
  import { createStoreUpdater } from 'zustand-utils';
5
5
 
6
+ import { AgentSettingsInstance, useAgentSettings } from './hooks/useAgentSettings';
6
7
  import { State, useStoreApi } from './store';
7
8
 
8
- export type StoreUpdaterProps = Partial<
9
- Pick<State, 'onMetaChange' | 'onConfigChange' | 'meta' | 'config' | 'id'>
10
- >;
9
+ export interface StoreUpdaterProps
10
+ extends Partial<Pick<State, 'onMetaChange' | 'onConfigChange' | 'meta' | 'config' | 'id'>> {
11
+ instanceRef?: ForwardedRef<AgentSettingsInstance> | null;
12
+ }
11
13
 
12
14
  const StoreUpdater = memo<StoreUpdaterProps>(
13
- ({ onConfigChange, id, onMetaChange, meta, config }) => {
15
+ ({ onConfigChange, instanceRef, id, onMetaChange, meta, config }) => {
14
16
  const storeApi = useStoreApi();
15
17
  const useStoreUpdater = createStoreUpdater(storeApi);
16
18
 
@@ -20,6 +22,9 @@ const StoreUpdater = memo<StoreUpdaterProps>(
20
22
  useStoreUpdater('onMetaChange', onMetaChange);
21
23
  useStoreUpdater('id', id);
22
24
 
25
+ const instance = useAgentSettings();
26
+ useImperativeHandle(instanceRef, () => instance);
27
+
23
28
  return null;
24
29
  },
25
30
  );