@lobehub/chat 1.0.11 → 1.0.12

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 (44) hide show
  1. package/CHANGELOG.md +25 -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 +1 -1
  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/ModelSelect/index.tsx +6 -4
  39. package/src/locales/default/setting.ts +5 -0
  40. package/src/store/agent/slices/chat/initialState.ts +2 -0
  41. package/src/store/user/slices/settings/action.ts +8 -2
  42. package/src/store/user/slices/settings/selectors/systemAgent.ts +2 -0
  43. package/src/types/user/settings/systemAgent.ts +3 -0
  44. /package/src/{components/StoreHydration → app/(main)/chat/(workspace)/@conversation/features}/ChatHydration/index.tsx +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.0.12](https://github.com/lobehub/lobe-chat/compare/v1.0.11...v1.0.12)
6
+
7
+ <sup>Released on **2024-06-19**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **misc**: Fix auto avatar.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **misc**: Fix auto avatar, closes [#2939](https://github.com/lobehub/lobe-chat/issues/2939) ([f40300c](https://github.com/lobehub/lobe-chat/commit/f40300c))
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
+
5
30
  ### [Version 1.0.11](https://github.com/lobehub/lobe-chat/compare/v1.0.10...v1.0.11)
6
31
 
7
32
  <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.12",
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",
@@ -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
  );
@@ -0,0 +1,31 @@
1
+ import { useMemo } from 'react';
2
+
3
+ import { useStoreApi } from '../store';
4
+ import { PublicAction } from '../store/action';
5
+
6
+ export type AgentSettingsInstance = PublicAction;
7
+
8
+ export const useAgentSettings = (): AgentSettingsInstance => {
9
+ const storeApi = useStoreApi();
10
+
11
+ const {
12
+ autocompleteMeta,
13
+ autocompleteAllMeta,
14
+ autocompleteAgentTitle,
15
+ autocompleteAgentDescription,
16
+ autocompleteAgentTags,
17
+ autoPickEmoji,
18
+ } = storeApi.getState();
19
+
20
+ return useMemo(
21
+ () => ({
22
+ autoPickEmoji,
23
+ autocompleteAgentDescription,
24
+ autocompleteAgentTags,
25
+ autocompleteAgentTitle,
26
+ autocompleteAllMeta,
27
+ autocompleteMeta,
28
+ }),
29
+ [],
30
+ );
31
+ };
@@ -1,26 +1,3 @@
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
- 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
- };
25
-
26
- export default AgentSettings;
1
+ export { AgentSettings } from './AgentSettings';
2
+ export { AgentSettingsStore } from './AgentSettingsStore';
3
+ export type { AgentSettingsInstance } from './hooks/useAgentSettings';
@@ -7,9 +7,13 @@ import { chainSummaryDescription } from '@/chains/summaryDescription';
7
7
  import { chainSummaryTags } from '@/chains/summaryTags';
8
8
  import { TraceNameMap, TracePayload, TraceTopicType } from '@/const/trace';
9
9
  import { chatService } from '@/services/chat';
10
+ import { useUserStore } from '@/store/user';
11
+ import { systemAgentSelectors } from '@/store/user/slices/settings/selectors';
10
12
  import { LobeAgentChatConfig, LobeAgentConfig } from '@/types/agent';
11
13
  import { MetaData } from '@/types/meta';
14
+ import { SystemAgentItem } from '@/types/user/settings';
12
15
  import { MessageTextChunk } from '@/utils/fetch';
16
+ import { merge } from '@/utils/merge';
13
17
  import { setNamespace } from '@/utils/storeDebug';
14
18
 
15
19
  import { SessionLoadingState } from '../store/initialState';
@@ -17,15 +21,12 @@ import { State, initialState } from './initialState';
17
21
  import { ConfigDispatch, configReducer } from './reducers/config';
18
22
  import { MetaDataDispatch, metaDataReducer } from './reducers/meta';
19
23
 
20
- /**
21
- * 设置操作
22
- */
23
- export interface Action {
24
+ export interface PublicAction {
24
25
  /**
25
26
  * 自动选择表情
26
27
  * @param id - 表情的 ID
27
28
  */
28
- autoPickEmoji: () => void;
29
+ autoPickEmoji: () => Promise<void>;
29
30
  /**
30
31
  * 自动完成代理描述
31
32
  * @param id - 代理的 ID
@@ -44,20 +45,25 @@ export interface Action {
44
45
  */
45
46
  autocompleteAllMeta: (replace?: boolean) => void;
46
47
  autocompleteMeta: (key: keyof MetaData) => void;
48
+ }
49
+
50
+ export interface Action extends PublicAction {
47
51
  dispatchConfig: (payload: ConfigDispatch) => void;
48
52
  dispatchMeta: (payload: MetaDataDispatch) => void;
49
53
  getCurrentTracePayload: (data: Partial<TracePayload>) => TracePayload;
50
54
 
55
+ internal_getSystemAgentForMeta: () => SystemAgentItem;
51
56
  resetAgentConfig: () => void;
52
- resetAgentMeta: () => void;
53
57
 
58
+ resetAgentMeta: () => void;
54
59
  setAgentConfig: (config: DeepPartial<LobeAgentConfig>) => void;
55
60
  setAgentMeta: (meta: Partial<MetaData>) => void;
56
- setChatConfig: (config: Partial<LobeAgentChatConfig>) => void;
57
61
 
62
+ setChatConfig: (config: Partial<LobeAgentChatConfig>) => void;
58
63
  streamUpdateMetaArray: (key: keyof MetaData) => any;
59
64
  streamUpdateMetaString: (key: keyof MetaData) => any;
60
65
  toggleAgentPlugin: (pluginId: string, state?: boolean) => void;
66
+
61
67
  /**
62
68
  * 更新加载状态
63
69
  * @param key - SessionLoadingState 的键
@@ -77,17 +83,19 @@ export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, g
77
83
 
78
84
  const systemRole = config.systemRole;
79
85
 
80
- const emoji = await chatService.fetchPresetTaskResult({
86
+ chatService.fetchPresetTaskResult({
87
+ onFinish: async (emoji) => {
88
+ dispatchMeta({ type: 'update', value: { avatar: emoji } });
89
+ },
81
90
  onLoadingChange: (loading) => {
82
91
  get().updateLoadingState('avatar', loading);
83
92
  },
84
- params: chainPickEmoji([meta.title, meta.description, systemRole].filter(Boolean).join(',')),
93
+ params: merge(
94
+ get().internal_getSystemAgentForMeta(),
95
+ chainPickEmoji([meta.title, meta.description, systemRole].filter(Boolean).join(',')),
96
+ ),
85
97
  trace: get().getCurrentTracePayload({ traceName: TraceNameMap.EmojiPicker }),
86
98
  });
87
-
88
- if (emoji) {
89
- dispatchMeta({ type: 'update', value: { avatar: emoji } });
90
- }
91
99
  },
92
100
  autocompleteAgentDescription: async () => {
93
101
  const { dispatchMeta, config, meta, updateLoadingState, streamUpdateMetaString } = get();
@@ -109,7 +117,7 @@ export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, g
109
117
  updateLoadingState('description', loading);
110
118
  },
111
119
  onMessageHandle: streamUpdateMetaString('description'),
112
- params: chainSummaryDescription(systemRole),
120
+ params: merge(get().internal_getSystemAgentForMeta(), chainSummaryDescription(systemRole)),
113
121
  trace: get().getCurrentTracePayload({ traceName: TraceNameMap.SummaryAgentDescription }),
114
122
  });
115
123
  },
@@ -125,6 +133,7 @@ export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, g
125
133
  // 替换为 ...
126
134
  dispatchMeta({ type: 'update', value: { tags: ['...'] } });
127
135
 
136
+ // Get current agent for agentMeta
128
137
  chatService.fetchPresetTaskResult({
129
138
  onError: () => {
130
139
  dispatchMeta({ type: 'update', value: { tags: preValue } });
@@ -133,8 +142,9 @@ export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, g
133
142
  updateLoadingState('tags', loading);
134
143
  },
135
144
  onMessageHandle: streamUpdateMetaArray('tags'),
136
- params: chainSummaryTags(
137
- [meta.title, meta.description, systemRole].filter(Boolean).join(','),
145
+ params: merge(
146
+ get().internal_getSystemAgentForMeta(),
147
+ chainSummaryTags([meta.title, meta.description, systemRole].filter(Boolean).join(',')),
138
148
  ),
139
149
  trace: get().getCurrentTracePayload({ traceName: TraceNameMap.SummaryAgentTags }),
140
150
  });
@@ -159,7 +169,10 @@ export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, g
159
169
  updateLoadingState('title', loading);
160
170
  },
161
171
  onMessageHandle: streamUpdateMetaString('title'),
162
- params: chainSummaryAgentName([meta.description, systemRole].filter(Boolean).join(',')),
172
+ params: merge(
173
+ get().internal_getSystemAgentForMeta(),
174
+ chainSummaryAgentName([meta.description, systemRole].filter(Boolean).join(',')),
175
+ ),
163
176
  trace: get().getCurrentTracePayload({ traceName: TraceNameMap.SummaryAgentTitle }),
164
177
  });
165
178
  },
@@ -231,6 +244,11 @@ export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, g
231
244
  topicId: TraceTopicType.AgentSettings,
232
245
  ...data,
233
246
  }),
247
+
248
+ internal_getSystemAgentForMeta: () => {
249
+ return systemAgentSelectors.agentMeta(useUserStore.getState());
250
+ },
251
+
234
252
  resetAgentConfig: () => {
235
253
  get().dispatchConfig({ type: 'reset' });
236
254
  },
@@ -238,13 +256,13 @@ export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, g
238
256
  resetAgentMeta: () => {
239
257
  get().dispatchMeta({ type: 'reset' });
240
258
  },
241
-
242
259
  setAgentConfig: (config) => {
243
260
  get().dispatchConfig({ config, type: 'update' });
244
261
  },
245
262
  setAgentMeta: (meta) => {
246
263
  get().dispatchMeta({ type: 'update', value: meta });
247
264
  },
265
+
248
266
  setChatConfig: (config) => {
249
267
  get().setAgentConfig({ chatConfig: config });
250
268
  },
@@ -31,5 +31,13 @@ export const useSendMessage = () => {
31
31
 
32
32
  updateInputMessage('');
33
33
  useFileStore.getState().clearImageList();
34
+
35
+ // const hasSystemRole = agentSelectors.hasSystemRole(useAgentStore.getState());
36
+ // const agentSetting = useAgentStore.getState().agentSettingInstance;
37
+
38
+ // // if there is a system role, then we need to use agent setting instance to autocomplete agent meta
39
+ // if (hasSystemRole && !!agentSetting) {
40
+ // agentSetting.autocompleteAllMeta();
41
+ // }
34
42
  }, []);
35
43
  };
@@ -10,11 +10,12 @@ import { ModelProviderCard } from '@/types/llm';
10
10
 
11
11
  const useStyles = createStyles(({ css, prefixCls }) => ({
12
12
  select: css`
13
- .${prefixCls}-select-dropdown .${prefixCls}-select-item-option-grouped {
13
+ &.${prefixCls}-select-dropdown .${prefixCls}-select-item-option-grouped {
14
14
  padding-inline-start: 12px;
15
15
  }
16
16
  `,
17
17
  }));
18
+
18
19
  interface ModelOption {
19
20
  label: any;
20
21
  provider: string;
@@ -23,10 +24,11 @@ interface ModelOption {
23
24
 
24
25
  interface ModelSelectProps {
25
26
  onChange?: (props: { model: string; provider: string }) => void;
27
+ showAbility?: boolean;
26
28
  value?: string;
27
29
  }
28
30
 
29
- const ModelSelect = memo<ModelSelectProps>(({ value, onChange }) => {
31
+ const ModelSelect = memo<ModelSelectProps>(({ value, onChange, showAbility = true }) => {
30
32
  const enabledList = useUserStore(modelProviderSelectors.modelProviderListForModelSelect, isEqual);
31
33
 
32
34
  const { styles } = useStyles();
@@ -34,7 +36,7 @@ const ModelSelect = memo<ModelSelectProps>(({ value, onChange }) => {
34
36
  const options = useMemo<SelectProps['options']>(() => {
35
37
  const getChatModels = (provider: ModelProviderCard) =>
36
38
  provider.chatModels.map((model) => ({
37
- label: <ModelItemRender {...model} />,
39
+ label: <ModelItemRender {...model} showInfoTag={showAbility} />,
38
40
  provider: provider.id,
39
41
  value: model.id,
40
42
  }));
@@ -53,11 +55,11 @@ const ModelSelect = memo<ModelSelectProps>(({ value, onChange }) => {
53
55
 
54
56
  return (
55
57
  <Select
56
- className={styles.select}
57
58
  onChange={(model, option) => {
58
59
  onChange?.({ model, provider: (option as unknown as ModelOption).provider });
59
60
  }}
60
61
  options={options}
62
+ popupClassName={styles.select}
61
63
  popupMatchSelectWidth={false}
62
64
  value={value}
63
65
  />
@@ -370,6 +370,11 @@ export default {
370
370
  },
371
371
  },
372
372
  systemAgent: {
373
+ agentMeta: {
374
+ label: '助理元数据生成模型',
375
+ modelDesc: '指定用于生成助理名称、描述、头像、标签的模型',
376
+ title: '自动生成助理信息',
377
+ },
373
378
  title: '系统助手',
374
379
  topic: {
375
380
  label: '话题命名模型',
@@ -1,11 +1,13 @@
1
1
  import { DeepPartial } from 'utility-types';
2
2
 
3
3
  import { DEFAULT_AGENT_CONFIG } from '@/const/settings';
4
+ import { AgentSettingsInstance } from '@/features/AgentSetting';
4
5
  import { LobeAgentConfig } from '@/types/agent';
5
6
 
6
7
  export interface AgentState {
7
8
  activeId: string;
8
9
  agentMap: Record<string, DeepPartial<LobeAgentConfig>>;
10
+ agentSettingInstance?: AgentSettingsInstance | null;
9
11
  defaultAgentConfig: LobeAgentConfig;
10
12
  isInboxAgentConfigInit: boolean;
11
13
  updateAgentChatConfigSignal?: AbortController;
@@ -8,7 +8,13 @@ import { userService } from '@/services/user';
8
8
  import type { UserStore } from '@/store/user';
9
9
  import { LocaleMode } from '@/types/locale';
10
10
  import { LobeAgentSettings } from '@/types/session';
11
- import { UserGeneralConfig, UserKeyVaults, UserSettings } from '@/types/user/settings';
11
+ import {
12
+ SystemAgentItem,
13
+ UserGeneralConfig,
14
+ UserKeyVaults,
15
+ UserSettings,
16
+ UserSystemAgentConfigKey,
17
+ } from '@/types/user/settings';
12
18
  import { switchLang } from '@/utils/client/switchLang';
13
19
  import { difference } from '@/utils/difference';
14
20
  import { merge } from '@/utils/merge';
@@ -25,7 +31,7 @@ export interface UserSettingsAction {
25
31
  updateGeneralConfig: (settings: Partial<UserGeneralConfig>) => Promise<void>;
26
32
  updateKeyVaults: (settings: Partial<UserKeyVaults>) => Promise<void>;
27
33
 
28
- updateSystemAgent: (key: string, value: { model: string; provider: string }) => Promise<void>;
34
+ updateSystemAgent: (key: UserSystemAgentConfigKey, value: SystemAgentItem) => Promise<void>;
29
35
  }
30
36
 
31
37
  export const createSettingsSlice: StateCreator<
@@ -9,8 +9,10 @@ const currentSystemAgent = (s: UserStore) =>
9
9
 
10
10
  const translation = (s: UserStore) => currentSystemAgent(s).translation;
11
11
  const topic = (s: UserStore) => currentSystemAgent(s).topic;
12
+ const agentMeta = (s: UserStore) => currentSystemAgent(s).agentMeta;
12
13
 
13
14
  export const systemAgentSelectors = {
15
+ agentMeta,
14
16
  topic,
15
17
  translation,
16
18
  };
@@ -4,6 +4,9 @@ export interface SystemAgentItem {
4
4
  }
5
5
 
6
6
  export interface UserSystemAgentConfig {
7
+ agentMeta: SystemAgentItem;
7
8
  topic: SystemAgentItem;
8
9
  translation: SystemAgentItem;
9
10
  }
11
+
12
+ export type UserSystemAgentConfigKey = keyof UserSystemAgentConfig;