Skip to content

Commit 56865fe

Browse files
authored
✨ feat: support topic agent (#2683)
* ✨ feat: support topic agent * ✅ test: fix test * ✅ test: fix test * ✅ test: add tests * 🌐 chore: add i18n
1 parent 48da563 commit 56865fe

File tree

36 files changed

+383
-127
lines changed

36 files changed

+383
-127
lines changed

locales/ar/setting.json

+5
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@
369369
},
370370
"systemAgent": {
371371
"title": "مساعد النظام",
372+
"topic": {
373+
"label": "نموذج تسمية الموضوع",
374+
"modelDesc": "يحدد النموذج المستخدم لإعادة تسمية الموضوع تلقائيًا",
375+
"title": "إعادة تسمية الموضوع"
376+
},
372377
"translation": {
373378
"label": "نموذج الترجمة",
374379
"modelDesc": "النموذج المحدد للاستخدام في الترجمة",

locales/bg-BG/setting.json

+5
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@
369369
},
370370
"systemAgent": {
371371
"title": "Системен асистент",
372+
"topic": {
373+
"label": "Модел за именуване на теми",
374+
"modelDesc": "Модел, определен за автоматично преименуване на теми",
375+
"title": "Автоматично именуване на теми"
376+
},
372377
"translation": {
373378
"label": "Модел за превод",
374379
"modelDesc": "Определя модела, използван за превод",

locales/de-DE/setting.json

+5
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@
369369
},
370370
"systemAgent": {
371371
"title": "Systemassistent",
372+
"topic": {
373+
"label": "Themenbenennungsmodell",
374+
"modelDesc": "Das Modell, das für die automatische Umbenennung von Themen verwendet wird",
375+
"title": "Automatische Themenbenennung"
376+
},
372377
"translation": {
373378
"label": "Übersetzungsmodell",
374379
"modelDesc": "Das für die Übersetzung verwendete Modell",

locales/en-US/setting.json

+5
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@
369369
},
370370
"systemAgent": {
371371
"title": "System Agents",
372+
"topic": {
373+
"label": "Topic Naming Model",
374+
"modelDesc": "Model designated for automatic topic renaming",
375+
"title": "Automatic Topic Naming"
376+
},
372377
"translation": {
373378
"label": "Translation Agent",
374379
"modelDesc": "Specific model for translate message",

locales/es-ES/setting.json

+5
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@
369369
},
370370
"systemAgent": {
371371
"title": "Asistente del sistema",
372+
"topic": {
373+
"label": "Modelo de nombramiento de temas",
374+
"modelDesc": "Modelo designado para el renombramiento automático de temas",
375+
"title": "Renombramiento automático de temas"
376+
},
372377
"translation": {
373378
"label": "Modelo de traducción",
374379
"modelDesc": "Especifica el modelo a utilizar para la traducción",

locales/fr-FR/setting.json

+5
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@
369369
},
370370
"systemAgent": {
371371
"title": "Assistant système",
372+
"topic": {
373+
"label": "Modèle de nommage des sujets",
374+
"modelDesc": "Modèle spécifié pour le renommage automatique des sujets",
375+
"title": "Renommage automatique des sujets"
376+
},
372377
"translation": {
373378
"label": "Modèle de traduction",
374379
"modelDesc": "Modèle spécifié pour la traduction",

locales/it-IT/setting.json

+5
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@
369369
},
370370
"systemAgent": {
371371
"title": "Assistente di sistema",
372+
"topic": {
373+
"label": "Modello di denominazione degli argomenti",
374+
"modelDesc": "Modello designato per la ridenominazione automatica degli argomenti",
375+
"title": "Ridenominazione automatica degli argomenti"
376+
},
372377
"translation": {
373378
"label": "Modello di traduzione",
374379
"modelDesc": "Modello specificato per la traduzione",

locales/ja-JP/setting.json

+5
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@
369369
},
370370
"systemAgent": {
371371
"title": "システムアシスタント",
372+
"topic": {
373+
"label": "トピックネーミングモデル",
374+
"modelDesc": "トピックの自動リネームに使用されるモデルを指定します",
375+
"title": "トピックの自動リネーム"
376+
},
372377
"translation": {
373378
"label": "翻訳モデル",
374379
"modelDesc": "翻訳に使用するモデルを指定します",

locales/ko-KR/setting.json

+5
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@
369369
},
370370
"systemAgent": {
371371
"title": "시스템 도우미",
372+
"topic": {
373+
"label": "주제 명명 모델",
374+
"modelDesc": "주제 자동 재명명에 사용되는 모델 지정",
375+
"title": "주제 자동 명명"
376+
},
372377
"translation": {
373378
"label": "번역 모델",
374379
"modelDesc": "번역에 사용되는 모델 지정",

locales/nl-NL/setting.json

+5
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@
369369
},
370370
"systemAgent": {
371371
"title": "Systeemassistent",
372+
"topic": {
373+
"label": "Onderwerp Naamgevingsmodel",
374+
"modelDesc": "Specificeer het model dat wordt gebruikt voor automatische hernoeming van onderwerpen",
375+
"title": "Automatische Onderwerpnaamgeving"
376+
},
372377
"translation": {
373378
"label": "Vertaalmodel",
374379
"modelDesc": "Specificeer het model voor vertaling",

locales/pl-PL/setting.json

+5
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@
369369
},
370370
"systemAgent": {
371371
"title": "Asystent Systemowy",
372+
"topic": {
373+
"label": "Model nazewnictwa tematów",
374+
"modelDesc": "Określa model używany do automatycznego zmieniania nazw tematów",
375+
"title": "Automatyczne nadawanie nazw tematom"
376+
},
372377
"translation": {
373378
"label": "Model Tłumaczenia",
374379
"modelDesc": "Określ model używany do tłumaczenia",

locales/pt-BR/setting.json

+5
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@
369369
},
370370
"systemAgent": {
371371
"title": "Assistente do Sistema",
372+
"topic": {
373+
"label": "Modelo de Nomeação de Tópicos",
374+
"modelDesc": "Especifica o modelo usado para renomeação automática de tópicos",
375+
"title": "Renomeação Automática de Tópicos"
376+
},
372377
"translation": {
373378
"label": "Modelo de Tradução",
374379
"modelDesc": "Especifica o modelo usado para tradução",

locales/ru-RU/setting.json

+5
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@
369369
},
370370
"systemAgent": {
371371
"title": "Системный агент",
372+
"topic": {
373+
"label": "Модель именования тем",
374+
"modelDesc": "Модель, используемая для автоматического переименования тем",
375+
"title": "Автоматическое именование тем"
376+
},
372377
"translation": {
373378
"label": "Модель перевода",
374379
"modelDesc": "Модель, используемая для перевода",

locales/tr-TR/setting.json

+5
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@
369369
},
370370
"systemAgent": {
371371
"title": "Sistem Asistanı",
372+
"topic": {
373+
"label": "Konu Adlandırma Modeli",
374+
"modelDesc": "Konuların otomatik olarak yeniden adlandırılması için belirlenen model",
375+
"title": "Konu Otomatik Adlandırma"
376+
},
372377
"translation": {
373378
"label": "Çeviri Modeli",
374379
"modelDesc": "Çeviri için belirlenen model",

locales/vi-VN/setting.json

+5
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@
369369
},
370370
"systemAgent": {
371371
"title": "Trợ lý hệ thống",
372+
"topic": {
373+
"label": "Mô hình đặt tên chủ đề",
374+
"modelDesc": "Mô hình được chỉ định để tự động đặt tên chủ đề",
375+
"title": "Tự động đặt tên chủ đề"
376+
},
372377
"translation": {
373378
"label": "Mô hình dịch",
374379
"modelDesc": "Chọn mô hình để dịch",

locales/zh-CN/setting.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,15 @@
369369
},
370370
"systemAgent": {
371371
"title": "系统助手",
372+
"topic": {
373+
"label": "话题命名模型",
374+
"modelDesc": "指定用于话题自动重命名的模型",
375+
"title": "话题自动命名"
376+
},
372377
"translation": {
373378
"label": "翻译模型",
374379
"modelDesc": "指定用于翻译的模型",
375-
"title": "翻译助手设置"
380+
"title": "消息内容翻译"
376381
}
377382
},
378383
"tab": {

locales/zh-TW/setting.json

+5
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@
369369
},
370370
"systemAgent": {
371371
"title": "系統助手",
372+
"topic": {
373+
"label": "話題命名模型",
374+
"modelDesc": "指定用於話題自動重命名的模型",
375+
"title": "話題自動命名"
376+
},
372377
"translation": {
373378
"label": "翻譯模型",
374379
"modelDesc": "指定用於翻譯的模型",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 Topic = memo(() => {
19+
const { t } = useTranslation('setting');
20+
const [form] = AntForm.useForm();
21+
22+
const settings = useUserStore(settingsSelectors.currentSystemAgent, isEqual);
23+
const [updateSystemAgent] = useUserStore((s) => [s.updateSystemAgent]);
24+
25+
const systemAgentSettings: SettingItemGroup = {
26+
children: [
27+
{
28+
children: (
29+
<ModelSelect
30+
onChange={(props) => {
31+
updateSystemAgent('topic', props);
32+
}}
33+
/>
34+
),
35+
desc: t('systemAgent.topic.modelDesc'),
36+
label: t('systemAgent.topic.label'),
37+
name: ['topic', 'model'],
38+
},
39+
],
40+
title: t('systemAgent.topic.title'),
41+
};
42+
43+
useSyncSystemAgent(form);
44+
45+
return (
46+
<Form
47+
form={form}
48+
initialValues={settings}
49+
items={[systemAgentSettings]}
50+
variant={'pure'}
51+
{...FORM_STYLE}
52+
/>
53+
);
54+
});
55+
56+
export default Topic;

src/app/(main)/settings/system-agent/features/Translation.tsx

+6-8
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,36 @@ import ModelSelect from '@/features/ModelSelect';
1111
import { useUserStore } from '@/store/user';
1212
import { settingsSelectors } from '@/store/user/selectors';
1313

14-
import { useSyncSettings } from '../../hooks/useSyncSettings';
15-
16-
const SYSTEM_AGENT_SETTING_KEY = 'systemAgent';
14+
import { useSyncSystemAgent } from './useSync';
1715

1816
type SettingItemGroup = ItemGroup;
1917

2018
const Translation = memo(() => {
2119
const { t } = useTranslation('setting');
2220
const [form] = AntForm.useForm();
2321

24-
const settings = useUserStore(settingsSelectors.currentSettings, isEqual);
25-
const [setTranslationSystemAgent] = useUserStore((s) => [s.setTranslationSystemAgent]);
22+
const settings = useUserStore(settingsSelectors.currentSystemAgent, isEqual);
23+
const [updateSystemAgent] = useUserStore((s) => [s.updateSystemAgent]);
2624

2725
const systemAgentSettings: SettingItemGroup = {
2826
children: [
2927
{
3028
children: (
3129
<ModelSelect
3230
onChange={(props) => {
33-
setTranslationSystemAgent(props.provider, props.model);
31+
updateSystemAgent('translation', props);
3432
}}
3533
/>
3634
),
3735
desc: t('systemAgent.translation.modelDesc'),
3836
label: t('systemAgent.translation.label'),
39-
name: [SYSTEM_AGENT_SETTING_KEY, 'translation', 'model'],
37+
name: ['translation', 'model'],
4038
},
4139
],
4240
title: t('systemAgent.translation.title'),
4341
};
4442

45-
useSyncSettings(form);
43+
useSyncSystemAgent(form);
4644

4745
return (
4846
<Form
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { FormInstance } from 'antd';
2+
import { useLayoutEffect } from 'react';
3+
4+
import { useUserStore } from '@/store/user';
5+
6+
export const useSyncSystemAgent = (form: FormInstance) => {
7+
useLayoutEffect(() => {
8+
// set the first time
9+
form.setFieldsValue(useUserStore.getState().settings.systemAgent);
10+
11+
// sync with later updated settings
12+
const unsubscribe = useUserStore.subscribe(
13+
(s) => s.settings.systemAgent,
14+
(settings) => {
15+
form.setFieldsValue(settings);
16+
},
17+
);
18+
19+
return () => {
20+
unsubscribe();
21+
};
22+
}, []);
23+
};

src/app/(main)/settings/system-agent/index.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import Topic from './features/Topic';
12
import Translation from './features/Translation';
23

34
const Page = () => {
4-
return <Translation />;
5+
return (
6+
<>
7+
<Topic />
8+
<Translation />
9+
</>
10+
);
511
};
612

713
Page.displayName = 'SystemAgent';

0 commit comments

Comments
 (0)