@lobehub/chat 0.161.16 → 0.161.17
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.
- package/CHANGELOG.md +25 -0
- package/package.json +1 -1
- package/src/app/(main)/chat/@session/features/SessionListContent/List/Item/index.tsx +1 -1
- package/src/app/(main)/chat/_layout/Desktop/index.tsx +3 -0
- package/src/app/(main)/chat/settings/features/EditPage.tsx +5 -1
- package/src/app/(main)/welcome/_layout/Desktop.tsx +21 -16
- package/src/app/@modal/chat/(.)settings/modal/layout.tsx +5 -2
- package/src/app/metadata.ts +1 -1
- package/src/const/session.ts +2 -2
- package/src/const/settings/agent.ts +6 -2
- package/src/database/client/core/db.ts +22 -0
- package/src/database/client/core/migrations/migrateSettingsToUser/index.ts +3 -5
- package/src/database/client/core/migrations/migrateSettingsToUser/type.ts +18 -10
- package/src/database/client/models/session.ts +4 -0
- package/src/database/client/schemas/session.ts +2 -9
- package/src/features/AgentSetting/AgentChat/index.tsx +19 -10
- package/src/features/AgentSetting/AgentModal/index.tsx +2 -1
- package/src/features/AgentSetting/StoreUpdater.tsx +3 -2
- package/src/features/AgentSetting/store/action.ts +12 -5
- package/src/features/AgentSetting/store/initialState.ts +2 -1
- package/src/features/AgentSetting/store/selectors.ts +11 -0
- package/src/features/ChatInput/ActionBar/History.tsx +2 -2
- package/src/features/Conversation/components/ChatItem/index.tsx +2 -2
- package/src/migrations/FromV5ToV6/fixtures/from-v1-to-v6-output.json +247 -0
- package/src/migrations/FromV5ToV6/fixtures/session-input-v5.json +81 -0
- package/src/migrations/FromV5ToV6/fixtures/session-output-v6.json +85 -0
- package/src/migrations/FromV5ToV6/index.ts +61 -0
- package/src/migrations/FromV5ToV6/migrations.test.ts +50 -0
- package/src/migrations/FromV5ToV6/types/v5.ts +48 -0
- package/src/migrations/FromV5ToV6/types/v6.ts +60 -0
- package/src/migrations/index.ts +8 -1
- package/src/services/session/client.test.ts +1 -1
- package/src/services/session/client.ts +18 -2
- package/src/services/session/type.ts +11 -2
- package/src/store/agent/slices/chat/__snapshots__/selectors.test.ts.snap +6 -4
- package/src/store/agent/slices/chat/action.test.ts +15 -3
- package/src/store/agent/slices/chat/action.ts +51 -5
- package/src/store/agent/slices/chat/initialState.ts +2 -0
- package/src/store/agent/slices/chat/selectors.test.ts +0 -3
- package/src/store/agent/slices/chat/selectors.ts +10 -2
- package/src/store/chat/helpers.test.ts +6 -6
- package/src/store/chat/helpers.ts +2 -2
- package/src/store/chat/slices/message/action.test.ts +9 -4
- package/src/store/chat/slices/message/action.ts +19 -15
- package/src/store/chat/slices/message/selectors.test.ts +4 -2
- package/src/store/chat/slices/message/selectors.ts +1 -1
- package/src/store/session/slices/session/action.test.ts +6 -7
- package/src/store/user/slices/settings/selectors/__snapshots__/settings.test.ts.snap +6 -4
- package/src/types/agent/index.ts +37 -19
- package/src/types/session/agentSession.ts +35 -0
- package/src/types/session/index.ts +10 -0
- package/src/types/session/sessionGroup.ts +24 -0
- package/vitest.config.ts +7 -1
- package/src/types/session.ts +0 -57
- /package/public/{icons/apple-touch-icon.png → apple-touch-icon.png} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.161.17](https://github.com/lobehub/lobe-chat/compare/v0.161.16...v0.161.17)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2024-05-25**</sup>
|
|
8
|
+
|
|
9
|
+
#### ♻ Code Refactoring
|
|
10
|
+
|
|
11
|
+
- **misc**: Migrate some agent config to `chatConfig`.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### Code refactoring
|
|
19
|
+
|
|
20
|
+
- **misc**: Migrate some agent config to `chatConfig`, closes [#2646](https://github.com/lobehub/lobe-chat/issues/2646) ([2f311dc](https://github.com/lobehub/lobe-chat/commit/2f311dc))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
5
30
|
### [Version 0.161.16](https://github.com/lobehub/lobe-chat/compare/v0.161.15...v0.161.16)
|
|
6
31
|
|
|
7
32
|
<sup>Released on **2024-05-25**</sup>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "0.161.
|
|
3
|
+
"version": "0.161.17",
|
|
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",
|
|
@@ -16,7 +16,10 @@ const EditPage = memo(() => {
|
|
|
16
16
|
const id = useSessionStore((s) => s.activeId);
|
|
17
17
|
const config = useAgentStore(agentSelectors.currentAgentConfig, isEqual);
|
|
18
18
|
const meta = useSessionStore(sessionMetaSelectors.currentAgentMeta, isEqual);
|
|
19
|
-
const [updateAgentConfig] = useAgentStore((s) => [
|
|
19
|
+
const [updateAgentConfig, updateAgentChatConfig] = useAgentStore((s) => [
|
|
20
|
+
s.updateAgentConfig,
|
|
21
|
+
s.updateAgentChatConfig,
|
|
22
|
+
]);
|
|
20
23
|
|
|
21
24
|
const [updateAgentMeta, title] = useSessionStore((s) => [
|
|
22
25
|
s.updateSessionMeta,
|
|
@@ -30,6 +33,7 @@ const EditPage = memo(() => {
|
|
|
30
33
|
config={config}
|
|
31
34
|
id={id}
|
|
32
35
|
meta={meta}
|
|
36
|
+
onChatConfigChange={updateAgentChatConfig}
|
|
33
37
|
onConfigChange={updateAgentConfig}
|
|
34
38
|
onMetaChange={updateAgentMeta}
|
|
35
39
|
/>
|
|
@@ -8,23 +8,28 @@ const COPYRIGHT = `© ${new Date().getFullYear()} LobeHub, LLC`;
|
|
|
8
8
|
|
|
9
9
|
const DesktopLayout = ({ children }: PropsWithChildren) => {
|
|
10
10
|
return (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
<
|
|
25
|
-
|
|
11
|
+
<>
|
|
12
|
+
<Flexbox
|
|
13
|
+
align={'center'}
|
|
14
|
+
height={'100%'}
|
|
15
|
+
justify={'space-between'}
|
|
16
|
+
padding={16}
|
|
17
|
+
style={{ overflow: 'hidden', position: 'relative' }}
|
|
18
|
+
width={'100%'}
|
|
19
|
+
>
|
|
20
|
+
<Logo size={36} style={{ alignSelf: 'flex-start' }} type={'text'} />
|
|
21
|
+
<GridShowcase innerProps={{ gap: 24 }} style={{ maxWidth: 1024 }} width={'100%'}>
|
|
22
|
+
{children}
|
|
23
|
+
</GridShowcase>
|
|
24
|
+
<Flexbox align={'center'} horizontal justify={'space-between'}>
|
|
25
|
+
<span style={{ opacity: 0.5 }}>{COPYRIGHT}</span>
|
|
26
|
+
<Follow />
|
|
27
|
+
</Flexbox>
|
|
26
28
|
</Flexbox>
|
|
27
|
-
|
|
29
|
+
{/* ↓ cloud slot ↓ */}
|
|
30
|
+
|
|
31
|
+
{/* ↑ cloud slot ↑ */}
|
|
32
|
+
</>
|
|
28
33
|
);
|
|
29
34
|
};
|
|
30
35
|
|
|
@@ -28,8 +28,10 @@ const Layout = memo<PropsWithChildren>(({ children }) => {
|
|
|
28
28
|
const id = useSessionStore((s) => s.activeId);
|
|
29
29
|
const config = useAgentStore(agentSelectors.currentAgentConfig, isEqual);
|
|
30
30
|
const meta = useSessionStore(sessionMetaSelectors.currentAgentMeta, isEqual);
|
|
31
|
-
const [updateAgentConfig] = useAgentStore((s) => [
|
|
32
|
-
|
|
31
|
+
const [updateAgentConfig, updateAgentChatConfig] = useAgentStore((s) => [
|
|
32
|
+
s.updateAgentConfig,
|
|
33
|
+
s.updateAgentChatConfig,
|
|
34
|
+
]);
|
|
33
35
|
const [updateAgentMeta] = useSessionStore((s) => [
|
|
34
36
|
s.updateSessionMeta,
|
|
35
37
|
sessionMetaSelectors.currentAgentTitle(s),
|
|
@@ -47,6 +49,7 @@ const Layout = memo<PropsWithChildren>(({ children }) => {
|
|
|
47
49
|
config={config}
|
|
48
50
|
id={id}
|
|
49
51
|
meta={meta}
|
|
52
|
+
onChatConfigChange={updateAgentChatConfig}
|
|
50
53
|
onConfigChange={updateAgentConfig}
|
|
51
54
|
onMetaChange={updateAgentMeta}
|
|
52
55
|
/>
|
package/src/app/metadata.ts
CHANGED
|
@@ -21,7 +21,7 @@ export const generateMetadata = async (): Promise<Metadata> => {
|
|
|
21
21
|
},
|
|
22
22
|
description: t('chat.description'),
|
|
23
23
|
icons: {
|
|
24
|
-
apple: '/
|
|
24
|
+
apple: '/apple-touch-icon.png',
|
|
25
25
|
icon: '/favicon.ico',
|
|
26
26
|
shortcut: '/favicon-32x32.ico',
|
|
27
27
|
},
|
package/src/const/session.ts
CHANGED
|
@@ -9,12 +9,12 @@ export const WELCOME_GUIDE_CHAT_ID = 'welcome';
|
|
|
9
9
|
|
|
10
10
|
export const DEFAULT_AGENT_LOBE_SESSION: LobeAgentSession = {
|
|
11
11
|
config: DEFAULT_AGENT_CONFIG,
|
|
12
|
-
createdAt: Date
|
|
12
|
+
createdAt: new Date(),
|
|
13
13
|
id: '',
|
|
14
14
|
meta: DEFAULT_AGENT_META,
|
|
15
15
|
model: DEFAULT_AGENT_CONFIG.model,
|
|
16
16
|
type: LobeSessionType.Agent,
|
|
17
|
-
updatedAt: Date
|
|
17
|
+
updatedAt: new Date(),
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
export const DEFAULT_INBOX_SESSION: LobeAgentSession = merge(DEFAULT_AGENT_LOBE_SESSION, {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_AGENT_META } from '@/const/meta';
|
|
2
2
|
import { ModelProvider } from '@/libs/agent-runtime';
|
|
3
|
-
import { LobeAgentConfig, LobeAgentTTSConfig } from '@/types/agent';
|
|
3
|
+
import { LobeAgentChatConfig, LobeAgentConfig, LobeAgentTTSConfig } from '@/types/agent';
|
|
4
4
|
import { GlobalDefaultAgent } from '@/types/settings';
|
|
5
5
|
|
|
6
6
|
export const DEFAUTT_AGENT_TTS_CONFIG: LobeAgentTTSConfig = {
|
|
@@ -12,11 +12,15 @@ export const DEFAUTT_AGENT_TTS_CONFIG: LobeAgentTTSConfig = {
|
|
|
12
12
|
},
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
export const
|
|
15
|
+
export const DEFAULT_AGENT_CHAT_CONFIG: LobeAgentChatConfig = {
|
|
16
16
|
autoCreateTopicThreshold: 2,
|
|
17
17
|
displayMode: 'chat',
|
|
18
18
|
enableAutoCreateTopic: true,
|
|
19
19
|
historyCount: 1,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const DEFAULT_AGENT_CONFIG: LobeAgentConfig = {
|
|
23
|
+
chatConfig: DEFAULT_AGENT_CHAT_CONFIG,
|
|
20
24
|
model: 'gpt-3.5-turbo',
|
|
21
25
|
params: {
|
|
22
26
|
frequency_penalty: 0,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Dexie, { Transaction } from 'dexie';
|
|
2
2
|
|
|
3
3
|
import { MigrationLLMSettings } from '@/migrations/FromV3ToV4';
|
|
4
|
+
import { MigrationAgentChatConfig } from '@/migrations/FromV5ToV6';
|
|
4
5
|
import { uuid } from '@/utils/uuid';
|
|
5
6
|
|
|
6
7
|
import { DB_File } from '../schemas/files';
|
|
@@ -72,6 +73,10 @@ export class BrowserDB extends Dexie {
|
|
|
72
73
|
.stores(dbSchemaV9)
|
|
73
74
|
.upgrade((trans) => this.upgradeToV9(trans));
|
|
74
75
|
|
|
76
|
+
this.version(10)
|
|
77
|
+
.stores(dbSchemaV9)
|
|
78
|
+
.upgrade((trans) => this.upgradeToV10(trans));
|
|
79
|
+
|
|
75
80
|
this.files = this.table('files');
|
|
76
81
|
this.sessions = this.table('sessions');
|
|
77
82
|
this.messages = this.table('messages');
|
|
@@ -159,6 +164,11 @@ export class BrowserDB extends Dexie {
|
|
|
159
164
|
});
|
|
160
165
|
};
|
|
161
166
|
|
|
167
|
+
/**
|
|
168
|
+
* 2024.05.11
|
|
169
|
+
*
|
|
170
|
+
* message role=function to role=tool
|
|
171
|
+
*/
|
|
162
172
|
upgradeToV9 = async (trans: Transaction) => {
|
|
163
173
|
const messages = trans.table('messages');
|
|
164
174
|
await messages.toCollection().modify(async (message: DBModel<DB_Message>) => {
|
|
@@ -185,6 +195,18 @@ export class BrowserDB extends Dexie {
|
|
|
185
195
|
}
|
|
186
196
|
});
|
|
187
197
|
};
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* 2024.05.25
|
|
201
|
+
* migrate some agent config to chatConfig
|
|
202
|
+
*/
|
|
203
|
+
upgradeToV10 = async (trans: Transaction) => {
|
|
204
|
+
const sessions = trans.table('sessions');
|
|
205
|
+
await sessions.toCollection().modify(async (session: DBModel<DB_Session>) => {
|
|
206
|
+
if (session.config)
|
|
207
|
+
session.config = MigrationAgentChatConfig.migrateChatConfig(session.config as any);
|
|
208
|
+
});
|
|
209
|
+
};
|
|
188
210
|
}
|
|
189
211
|
|
|
190
212
|
export const browserDB = new BrowserDB();
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { V4Settings } from './type';
|
|
1
|
+
import { V4Settings, V5Settings } from './type';
|
|
4
2
|
|
|
5
3
|
export const migrateSettingsToUser = (
|
|
6
4
|
settings: V4Settings,
|
|
7
|
-
): { avatar: string; settings:
|
|
8
|
-
const dbSettings:
|
|
5
|
+
): { avatar: string; settings: V5Settings } => {
|
|
6
|
+
const dbSettings: V5Settings = {
|
|
9
7
|
defaultAgent: settings.defaultAgent,
|
|
10
8
|
fontSize: settings.fontSize,
|
|
11
9
|
language: settings.language,
|
|
@@ -58,7 +58,7 @@ interface V4DefaultAgent {
|
|
|
58
58
|
meta: MetaData;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
interface
|
|
61
|
+
interface OpenAIConfig {
|
|
62
62
|
OPENAI_API_KEY: string;
|
|
63
63
|
azureApiVersion?: string;
|
|
64
64
|
customModelName?: string;
|
|
@@ -68,15 +68,10 @@ interface V4OpenAIConfig {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
interface V4LLMConfig {
|
|
71
|
-
openAI:
|
|
71
|
+
openAI: OpenAIConfig;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
interface
|
|
75
|
-
dalle: {
|
|
76
|
-
autoGenerate: boolean;
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
interface V4TTSConfig {
|
|
74
|
+
interface TTSConfig {
|
|
80
75
|
openAI: {
|
|
81
76
|
sttModel: 'whisper-1';
|
|
82
77
|
ttsModel: 'tts-1' | 'tts-1-hd';
|
|
@@ -95,6 +90,19 @@ export interface V4Settings {
|
|
|
95
90
|
password: string;
|
|
96
91
|
primaryColor?: string;
|
|
97
92
|
themeMode: ThemeMode;
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
tts: TTSConfig;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface V5Settings {
|
|
97
|
+
defaultAgent: V4DefaultAgent;
|
|
98
|
+
fontSize: number;
|
|
99
|
+
language: string;
|
|
100
|
+
languageModel: {
|
|
101
|
+
openai: OpenAIConfig;
|
|
102
|
+
};
|
|
103
|
+
neutralColor?: string;
|
|
104
|
+
password: string;
|
|
105
|
+
primaryColor?: string;
|
|
106
|
+
themeMode: ThemeMode;
|
|
107
|
+
tts: TTSConfig;
|
|
100
108
|
}
|
|
@@ -246,16 +246,20 @@ class _SessionModel extends BaseModel {
|
|
|
246
246
|
private mapToDB_Session(session: LobeAgentSession): DBModel<DB_Session> {
|
|
247
247
|
return {
|
|
248
248
|
...session,
|
|
249
|
+
createdAt: session.createdAt?.valueOf(),
|
|
249
250
|
group: session.group || SessionDefaultGroup.Default,
|
|
250
251
|
pinned: session.pinned ? 1 : 0,
|
|
252
|
+
updatedAt: session.updatedAt?.valueOf(),
|
|
251
253
|
};
|
|
252
254
|
}
|
|
253
255
|
|
|
254
256
|
private DB_SessionToAgentSession(session: DBModel<DB_Session>) {
|
|
255
257
|
return {
|
|
256
258
|
...session,
|
|
259
|
+
createdAt: new Date(session.createdAt),
|
|
257
260
|
model: session.config.model,
|
|
258
261
|
pinned: !!session.pinned,
|
|
262
|
+
updatedAt: new Date(session.updatedAt),
|
|
259
263
|
} as LobeAgentSession;
|
|
260
264
|
}
|
|
261
265
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
+
import { AgentChatConfigSchema } from '@/types/agent';
|
|
3
4
|
import { LobeMetaDataSchema } from '@/types/meta';
|
|
4
5
|
|
|
5
6
|
const fewShotsSchema = z.array(
|
|
@@ -23,16 +24,8 @@ const ttsSchema = z.object({
|
|
|
23
24
|
});
|
|
24
25
|
|
|
25
26
|
export const AgentSchema = z.object({
|
|
26
|
-
|
|
27
|
-
compressThreshold: z.number().optional(),
|
|
28
|
-
displayMode: z.enum(['chat', 'docs']).optional(),
|
|
29
|
-
enableAutoCreateTopic: z.boolean().default(true),
|
|
30
|
-
enableCompressThreshold: z.boolean().optional(),
|
|
31
|
-
enableHistoryCount: z.boolean().optional(),
|
|
32
|
-
enableMaxTokens: z.boolean().optional(),
|
|
27
|
+
chatConfig: AgentChatConfigSchema,
|
|
33
28
|
fewShots: fewShotsSchema.optional(),
|
|
34
|
-
historyCount: z.number().default(8).optional(),
|
|
35
|
-
inputTemplate: z.string().optional(),
|
|
36
29
|
model: z.string().default('gpt-3.5-turbo'),
|
|
37
30
|
params: z.object({
|
|
38
31
|
frequency_penalty: z.number().default(0).optional(),
|
|
@@ -3,15 +3,16 @@
|
|
|
3
3
|
import { Form, ItemGroup, SelectWithImg, SliderWithInput } from '@lobehub/ui';
|
|
4
4
|
import { Input, Switch } from 'antd';
|
|
5
5
|
import { useThemeMode } from 'antd-style';
|
|
6
|
+
import isEqual from 'fast-deep-equal';
|
|
6
7
|
import { LayoutList, MessagesSquare } from 'lucide-react';
|
|
7
|
-
import { memo } from 'react';
|
|
8
|
+
import { memo, useLayoutEffect } from 'react';
|
|
8
9
|
import { useTranslation } from 'react-i18next';
|
|
9
10
|
|
|
10
11
|
import { FORM_STYLE } from '@/const/layoutTokens';
|
|
11
12
|
import { imageUrl } from '@/const/url';
|
|
12
13
|
|
|
13
14
|
import { useStore } from '../store';
|
|
14
|
-
import {
|
|
15
|
+
import { selectors } from '../store/selectors';
|
|
15
16
|
|
|
16
17
|
const AgentChat = memo(() => {
|
|
17
18
|
const { t } = useTranslation('setting');
|
|
@@ -23,15 +24,23 @@ const AgentChat = memo(() => {
|
|
|
23
24
|
enableHistoryCount,
|
|
24
25
|
enableCompressThreshold,
|
|
25
26
|
updateConfig,
|
|
26
|
-
] = useStore((s) =>
|
|
27
|
-
|
|
28
|
-
s.config.enableAutoCreateTopic,
|
|
29
|
-
s.config.enableHistoryCount,
|
|
30
|
-
s.config.enableCompressThreshold,
|
|
31
|
-
s.setAgentConfig,
|
|
32
|
-
]);
|
|
27
|
+
] = useStore((s) => {
|
|
28
|
+
const config = selectors.chatConfig(s);
|
|
33
29
|
|
|
34
|
-
|
|
30
|
+
return [
|
|
31
|
+
config.displayMode,
|
|
32
|
+
config.enableAutoCreateTopic,
|
|
33
|
+
config.enableHistoryCount,
|
|
34
|
+
config.enableCompressThreshold,
|
|
35
|
+
s.setChatConfig,
|
|
36
|
+
];
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const config = useStore(selectors.chatConfig, isEqual);
|
|
40
|
+
|
|
41
|
+
useLayoutEffect(() => {
|
|
42
|
+
form.setFieldsValue(config);
|
|
43
|
+
}, [config]);
|
|
35
44
|
|
|
36
45
|
const chat: ItemGroup = {
|
|
37
46
|
children: [
|
|
@@ -9,6 +9,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
9
9
|
import { FORM_STYLE } from '@/const/layoutTokens';
|
|
10
10
|
|
|
11
11
|
import { useStore } from '../store';
|
|
12
|
+
import { selectors } from '../store/selectors';
|
|
12
13
|
import { useAgentSyncSettings } from '../useSyncAgemtSettings';
|
|
13
14
|
import ModelSelect from './ModelSelect';
|
|
14
15
|
|
|
@@ -17,7 +18,7 @@ const AgentModal = memo(() => {
|
|
|
17
18
|
const [form] = Form.useForm();
|
|
18
19
|
|
|
19
20
|
const [enableMaxTokens, updateConfig] = useStore((s) => [
|
|
20
|
-
s.
|
|
21
|
+
selectors.chatConfig(s).enableMaxTokens,
|
|
21
22
|
s.setAgentConfig,
|
|
22
23
|
]);
|
|
23
24
|
|
|
@@ -6,11 +6,11 @@ import { createStoreUpdater } from 'zustand-utils';
|
|
|
6
6
|
import { State, useStoreApi } from './store';
|
|
7
7
|
|
|
8
8
|
export type StoreUpdaterProps = Partial<
|
|
9
|
-
Pick<State, 'onMetaChange' | 'onConfigChange' | 'meta' | 'config' | 'id'>
|
|
9
|
+
Pick<State, 'onMetaChange' | 'onChatConfigChange' | 'onConfigChange' | 'meta' | 'config' | 'id'>
|
|
10
10
|
>;
|
|
11
11
|
|
|
12
12
|
const StoreUpdater = memo<StoreUpdaterProps>(
|
|
13
|
-
({ onConfigChange, id, onMetaChange, meta, config }) => {
|
|
13
|
+
({ onConfigChange, onChatConfigChange, id, onMetaChange, meta, config }) => {
|
|
14
14
|
const storeApi = useStoreApi();
|
|
15
15
|
const useStoreUpdater = createStoreUpdater(storeApi);
|
|
16
16
|
|
|
@@ -18,6 +18,7 @@ const StoreUpdater = memo<StoreUpdaterProps>(
|
|
|
18
18
|
useStoreUpdater('config', config);
|
|
19
19
|
useStoreUpdater('onConfigChange', onConfigChange);
|
|
20
20
|
useStoreUpdater('onMetaChange', onMetaChange);
|
|
21
|
+
useStoreUpdater('onChatConfigChange', onChatConfigChange);
|
|
21
22
|
useStoreUpdater('id', id);
|
|
22
23
|
|
|
23
24
|
return null;
|
|
@@ -6,7 +6,7 @@ import { chainSummaryDescription } from '@/chains/summaryDescription';
|
|
|
6
6
|
import { chainSummaryTags } from '@/chains/summaryTags';
|
|
7
7
|
import { TraceNameMap, TracePayload, TraceTopicType } from '@/const/trace';
|
|
8
8
|
import { chatService } from '@/services/chat';
|
|
9
|
-
import { LobeAgentConfig } from '@/types/agent';
|
|
9
|
+
import { LobeAgentChatConfig, LobeAgentConfig } from '@/types/agent';
|
|
10
10
|
import { MetaData } from '@/types/meta';
|
|
11
11
|
import { MessageTextChunk } from '@/utils/fetch';
|
|
12
12
|
import { setNamespace } from '@/utils/storeDebug';
|
|
@@ -45,15 +45,15 @@ export interface Action {
|
|
|
45
45
|
autocompleteMeta: (key: keyof MetaData) => void;
|
|
46
46
|
dispatchConfig: (payload: ConfigDispatch) => void;
|
|
47
47
|
dispatchMeta: (payload: MetaDataDispatch) => void;
|
|
48
|
-
|
|
49
48
|
getCurrentTracePayload: (data: Partial<TracePayload>) => TracePayload;
|
|
50
|
-
resetAgentConfig: () => void;
|
|
51
49
|
|
|
50
|
+
resetAgentConfig: () => void;
|
|
52
51
|
resetAgentMeta: () => void;
|
|
53
52
|
|
|
54
53
|
setAgentConfig: (config: Partial<LobeAgentConfig>) => void;
|
|
55
|
-
|
|
56
54
|
setAgentMeta: (meta: Partial<MetaData>) => void;
|
|
55
|
+
setChatConfig: (config: Partial<LobeAgentChatConfig>) => void;
|
|
56
|
+
|
|
57
57
|
streamUpdateMetaArray: (key: keyof MetaData) => any;
|
|
58
58
|
streamUpdateMetaString: (key: keyof MetaData) => any;
|
|
59
59
|
toggleAgentPlugin: (pluginId: string, state?: boolean) => void;
|
|
@@ -230,10 +230,10 @@ export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, g
|
|
|
230
230
|
topicId: TraceTopicType.AgentSettings,
|
|
231
231
|
...data,
|
|
232
232
|
}),
|
|
233
|
-
|
|
234
233
|
resetAgentConfig: () => {
|
|
235
234
|
get().dispatchConfig({ type: 'reset' });
|
|
236
235
|
},
|
|
236
|
+
|
|
237
237
|
resetAgentMeta: () => {
|
|
238
238
|
get().dispatchMeta({ type: 'reset' });
|
|
239
239
|
},
|
|
@@ -244,6 +244,13 @@ export const store: StateCreator<Store, [['zustand/devtools', never]]> = (set, g
|
|
|
244
244
|
setAgentMeta: (meta) => {
|
|
245
245
|
get().dispatchMeta({ type: 'update', value: meta });
|
|
246
246
|
},
|
|
247
|
+
setChatConfig: (config) => {
|
|
248
|
+
const nextConfig = { ...get().config.chatConfig, ...config };
|
|
249
|
+
|
|
250
|
+
set({ config: { ...get().config, chatConfig: nextConfig } }, false, 'updateChatConfig');
|
|
251
|
+
|
|
252
|
+
get().onChatConfigChange?.(nextConfig);
|
|
253
|
+
},
|
|
247
254
|
|
|
248
255
|
streamUpdateMetaArray: (key: keyof MetaData) => {
|
|
249
256
|
let value = '';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_AGENT_META } from '@/const/meta';
|
|
2
2
|
import { DEFAULT_AGENT_CONFIG } from '@/const/settings';
|
|
3
|
-
import { LobeAgentConfig } from '@/types/agent';
|
|
3
|
+
import { LobeAgentChatConfig, LobeAgentConfig } from '@/types/agent';
|
|
4
4
|
import { MetaData } from '@/types/meta';
|
|
5
5
|
|
|
6
6
|
export interface State {
|
|
@@ -9,6 +9,7 @@ export interface State {
|
|
|
9
9
|
id?: string;
|
|
10
10
|
meta: MetaData;
|
|
11
11
|
|
|
12
|
+
onChatConfigChange?: (config: LobeAgentChatConfig) => void;
|
|
12
13
|
onConfigChange?: (config: LobeAgentConfig) => void;
|
|
13
14
|
onMetaChange?: (meta: MetaData) => void;
|
|
14
15
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DEFAULT_AGENT_CHAT_CONFIG } from '@/const/settings';
|
|
2
|
+
import { LobeAgentChatConfig } from '@/types/agent';
|
|
3
|
+
|
|
4
|
+
import { Store } from './action';
|
|
5
|
+
|
|
6
|
+
const chatConfig = (s: Store): LobeAgentChatConfig =>
|
|
7
|
+
s.config.chatConfig || DEFAULT_AGENT_CHAT_CONFIG;
|
|
8
|
+
|
|
9
|
+
export const selectors = {
|
|
10
|
+
chatConfig,
|
|
11
|
+
};
|
|
@@ -12,8 +12,8 @@ const History = memo(() => {
|
|
|
12
12
|
const { t } = useTranslation('setting');
|
|
13
13
|
|
|
14
14
|
const [historyCount, unlimited, updateAgentConfig] = useAgentStore((s) => {
|
|
15
|
-
const config = agentSelectors.
|
|
16
|
-
return [config.historyCount, !config.enableHistoryCount, s.
|
|
15
|
+
const config = agentSelectors.currentAgentChatConfig(s);
|
|
16
|
+
return [config.historyCount, !config.enableHistoryCount, s.updateAgentChatConfig];
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
return (
|
|
@@ -42,7 +42,7 @@ const Item = memo<ChatListItemProps>(({ index, id }) => {
|
|
|
42
42
|
const { t } = useTranslation('common');
|
|
43
43
|
const { styles, cx } = useStyles();
|
|
44
44
|
const [type = 'chat'] = useAgentStore((s) => {
|
|
45
|
-
const config = agentSelectors.
|
|
45
|
+
const config = agentSelectors.currentAgentChatConfig(s);
|
|
46
46
|
return [config.displayMode];
|
|
47
47
|
});
|
|
48
48
|
|
|
@@ -103,7 +103,7 @@ const Item = memo<ChatListItemProps>(({ index, id }) => {
|
|
|
103
103
|
}, [item?.error]);
|
|
104
104
|
|
|
105
105
|
const enableHistoryDivider = useAgentStore((s) => {
|
|
106
|
-
const config = agentSelectors.
|
|
106
|
+
const config = agentSelectors.currentAgentChatConfig(s);
|
|
107
107
|
return (
|
|
108
108
|
config.enableHistoryCount &&
|
|
109
109
|
historyLength > (config.historyCount ?? 0) &&
|