@lobehub/chat 0.105.2 → 0.107.0
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 +50 -0
- package/README.md +18 -0
- package/README.zh-CN.md +18 -0
- package/docs/Environment-Variable.md +4 -2
- package/docs/Environment-Variable.zh-CN.md +4 -2
- package/locales/en_US/common.json +19 -0
- package/locales/en_US/migration.json +45 -0
- package/locales/en_US/setting.json +7 -7
- package/locales/ja_JP/common.json +19 -0
- package/locales/ja_JP/migration.json +45 -0
- package/locales/ja_JP/setting.json +2 -2
- package/locales/ko_KR/common.json +19 -0
- package/locales/ko_KR/migration.json +45 -0
- package/locales/ko_KR/setting.json +2 -2
- package/locales/ru_RU/common.json +19 -0
- package/locales/ru_RU/migration.json +45 -0
- package/locales/ru_RU/setting.json +2 -2
- package/locales/zh_CN/common.json +19 -0
- package/locales/zh_CN/migration.json +45 -0
- package/locales/zh_CN/setting.json +1 -1
- package/locales/zh_TW/common.json +19 -0
- package/locales/zh_TW/migration.json +45 -0
- package/locales/zh_TW/setting.json +2 -2
- package/package.json +2 -1
- package/src/app/api/openai/chat/createChatCompletion.test.ts +4 -4
- package/src/app/api/openai/chat/createChatCompletion.ts +4 -10
- package/src/app/api/openai/createBizOpenAI/index.ts +1 -1
- package/src/app/api/openai/errorResponse.test.ts +1 -1
- package/src/app/chat/(desktop)/features/ChatInput/Footer/index.tsx +2 -1
- package/src/app/chat/(mobile)/features/ChatInput/SendButton.tsx +2 -2
- package/src/app/chat/features/ChatHeader/ShareButton/Inner.tsx +2 -5
- package/src/app/chat/features/ChatHeader/ShareButton/index.tsx +2 -2
- package/src/app/chat/features/ChatInput/ActionBar/Clear.tsx +2 -2
- package/src/app/chat/features/ChatInput/ActionBar/ModelSwitch.tsx +1 -1
- package/src/app/chat/features/ChatInput/ActionBar/Token/TokenTag.tsx +8 -2
- package/src/app/chat/features/ChatInput/InputAreaInner/index.tsx +2 -2
- package/src/app/chat/features/ChatInput/STT/index.tsx +2 -2
- package/src/app/chat/features/ChatInput/Topic/index.tsx +2 -2
- package/src/app/chat/features/ChatInput/useSend.ts +3 -3
- package/src/app/chat/features/Conversation/ChatList/Actions/index.ts +2 -2
- package/src/app/chat/features/Conversation/ChatList/Error/ApiKeyForm.tsx +2 -2
- package/src/app/chat/features/Conversation/ChatList/Error/InvalidAccess.tsx +2 -2
- package/src/app/chat/features/Conversation/ChatList/Error/Plugin/PluginSettings.tsx +2 -2
- package/src/app/chat/features/Conversation/ChatList/Extras/Assistant.test.tsx +4 -4
- package/src/app/chat/features/Conversation/ChatList/Extras/Assistant.tsx +30 -31
- package/src/app/chat/features/Conversation/ChatList/Extras/TTS.tsx +2 -2
- package/src/app/chat/features/Conversation/ChatList/Extras/Translate.tsx +2 -2
- package/src/app/chat/features/Conversation/ChatList/Extras/User.tsx +8 -5
- package/src/app/chat/features/Conversation/ChatList/Extras/index.ts +3 -3
- package/src/app/chat/features/Conversation/ChatList/Extras/type.ts +5 -0
- package/src/app/chat/features/Conversation/ChatList/Messages/Assistant.tsx +10 -6
- package/src/app/chat/features/Conversation/ChatList/Messages/Default.tsx +7 -3
- package/src/app/chat/features/Conversation/ChatList/Messages/Function.tsx +7 -6
- package/src/app/chat/features/Conversation/ChatList/Messages/index.ts +7 -7
- package/src/app/chat/features/Conversation/ChatList/Plugins/Render/StandaloneType/Iframe.tsx +6 -6
- package/src/app/chat/features/Conversation/ChatList/index.tsx +16 -24
- package/src/app/chat/features/Conversation/ScrollAnchor/index.tsx +2 -2
- package/src/app/chat/features/Conversation/index.tsx +3 -3
- package/src/app/chat/features/Conversation/useInitConversation.ts +43 -0
- package/src/app/chat/features/Migration/ExportConfigButton.tsx +33 -0
- package/src/app/chat/features/Migration/Failed.tsx +115 -0
- package/src/app/chat/features/Migration/Modal.tsx +80 -0
- package/src/app/chat/features/Migration/Start.tsx +106 -0
- package/src/app/chat/features/Migration/UpgradeButton.tsx +74 -0
- package/src/app/chat/features/Migration/const.ts +15 -0
- package/src/app/chat/features/Migration/index.tsx +44 -0
- package/src/app/chat/features/SessionListContent/DefaultMode.tsx +54 -0
- package/src/app/chat/features/SessionListContent/List/Item/Actions.tsx +5 -4
- package/src/app/chat/features/SessionListContent/List/Item/index.tsx +22 -28
- package/src/app/chat/features/SessionListContent/SearchMode.tsx +15 -0
- package/src/app/chat/features/SessionListContent/index.tsx +4 -44
- package/src/app/chat/features/SessionSearchBar/index.tsx +11 -3
- package/src/app/chat/features/TopicListContent/Header.tsx +4 -4
- package/src/app/chat/features/TopicListContent/Topic/TopicContent.tsx +11 -9
- package/src/app/chat/features/TopicListContent/Topic/TopicItem.tsx +15 -13
- package/src/app/chat/features/TopicListContent/Topic/index.tsx +9 -16
- package/src/app/chat/features/TopicListContent/TopicSearchBar/index.tsx +13 -4
- package/src/app/chat/features/TopicListContent/index.tsx +1 -2
- package/src/app/chat/page.tsx +6 -1
- package/src/app/chat/settings/features/HeaderContent.tsx +3 -3
- package/src/app/home/Redirect.tsx +13 -7
- package/src/app/settings/(mobile)/features/ExtraList.tsx +12 -4
- package/src/app/settings/common/Common.tsx +16 -4
- package/src/app/welcome/features/Banner/index.tsx +9 -10
- package/src/chains/summaryTitle.ts +5 -2
- package/src/components/DataStyleModal/index.tsx +64 -0
- package/src/config/client.ts +5 -0
- package/src/const/session.ts +21 -0
- package/src/const/settings.ts +1 -1
- package/src/database/core/__tests__/db.test.ts +8 -5
- package/src/database/core/__tests__/model.test.ts +3 -3
- package/src/database/core/db.ts +38 -10
- package/src/database/core/index.ts +1 -0
- package/src/database/core/model.ts +121 -10
- package/src/database/core/schemas.ts +22 -0
- package/src/database/core/types/db.ts +13 -0
- package/src/database/models/__DEBUG.ts +119 -0
- package/src/database/models/{file.test.ts → __tests__/file.test.ts} +19 -6
- package/src/database/models/__tests__/message.test.ts +314 -0
- package/src/database/models/__tests__/session.test.ts +117 -0
- package/src/database/models/__tests__/topic.test.ts +250 -0
- package/src/database/models/file.ts +9 -5
- package/src/database/models/message.ts +186 -0
- package/src/database/models/session.ts +160 -0
- package/src/database/models/topic.ts +196 -0
- package/src/{types/database → database/schemas}/files.ts +2 -2
- package/src/database/schemas/message.ts +37 -0
- package/src/database/schemas/session.ts +56 -0
- package/src/database/schemas/topic.ts +12 -0
- package/src/features/AgentSetting/AgentConfig/index.tsx +8 -1
- package/src/features/AgentSetting/AgentTTS/SelectWithTTSPreview.tsx +1 -1
- package/src/features/AgentSetting/store/action.ts +1 -1
- package/src/features/AgentSetting/store/initialState.ts +1 -1
- package/src/features/AgentSetting/store/reducers/config.ts +1 -1
- package/src/features/DataImporter/index.tsx +240 -0
- package/src/features/DebugUI/index.tsx +34 -0
- package/src/features/SideBar/BottomActions.tsx +8 -14
- package/src/hooks/useImportConfig.ts +13 -30
- package/src/hooks/useTTS.ts +1 -1
- package/src/layout/GlobalLayout/index.tsx +16 -1
- package/src/locales/default/common.ts +19 -0
- package/src/locales/default/migration.ts +47 -0
- package/src/locales/default/setting.ts +1 -1
- package/src/locales/resources/en_US.ts +2 -0
- package/src/locales/resources/ja_JP.ts +2 -0
- package/src/locales/resources/ko_KR.ts +2 -0
- package/src/locales/resources/ru_RU.ts +2 -0
- package/src/locales/resources/zh_CN.ts +2 -0
- package/src/locales/resources/zh_TW.ts +2 -0
- package/src/migrations/FromV0ToV1.ts +2 -4
- package/src/migrations/FromV1ToV2/fixtures/input-v1-session.json +191 -0
- package/src/migrations/FromV1ToV2/fixtures/output-v2.json +202 -0
- package/src/migrations/FromV1ToV2/index.ts +82 -0
- package/src/migrations/FromV1ToV2/migrations.test.ts +224 -0
- package/src/migrations/FromV1ToV2/types/v1.ts +78 -0
- package/src/migrations/FromV1ToV2/types/v2.ts +52 -0
- package/src/{utils → migrations}/VersionController.test.ts +1 -3
- package/src/{utils → migrations}/VersionController.ts +5 -2
- package/src/migrations/index.ts +17 -3
- package/src/services/__tests__/file.test.ts +3 -3
- package/src/services/chat.ts +66 -5
- package/src/services/config.ts +184 -0
- package/src/services/debug.ts +13 -0
- package/src/services/file.ts +6 -2
- package/src/services/github.ts +25 -0
- package/src/services/message.ts +79 -0
- package/src/services/session.ts +63 -0
- package/src/services/topic.ts +56 -0
- package/src/store/chat/actions/enhance.ts +95 -0
- package/src/store/{session/slices/chat → chat}/actions/message.ts +225 -247
- package/src/store/{session/slices/chat → chat}/actions/plugin.ts +29 -34
- package/src/store/{session/slices/chat → chat}/actions/share.ts +9 -13
- package/src/store/chat/actions/topic.ts +197 -0
- package/src/store/chat/helpers.ts +23 -0
- package/src/store/chat/index.ts +3 -0
- package/src/store/chat/initialState.ts +48 -0
- package/src/store/chat/reducers/message.test.ts +83 -0
- package/src/store/chat/reducers/message.ts +83 -0
- package/src/store/chat/selectors/__tests__/topic.test.ts +43 -0
- package/src/store/chat/selectors/chat.ts +119 -0
- package/src/store/chat/selectors/index.ts +2 -0
- package/src/store/chat/selectors/topic.ts +28 -0
- package/src/store/chat/store.ts +63 -0
- package/src/store/files/slices/images/action.ts +6 -4
- package/src/store/global/selectors/__snapshots__/settings.test.ts.snap +99 -0
- package/src/store/global/selectors/settings.test.ts +51 -0
- package/src/store/global/selectors/settings.ts +36 -5
- package/src/store/global/store.ts +1 -1
- package/src/store/middleware/createHyperStorage/index.ts +40 -24
- package/src/store/middleware/createHyperStorage/keyMapper.ts +8 -2
- package/src/store/middleware/createHyperStorage/type.ts +10 -8
- package/src/store/plugin/slices/plugin/action.ts +1 -1
- package/src/store/plugin/store.ts +2 -4
- package/src/store/session/helpers.ts +1 -1
- package/src/store/session/hooks/useSessionHydrated.ts +6 -10
- package/src/store/session/initialState.ts +26 -7
- package/src/store/session/selectors.ts +1 -2
- package/src/store/session/slices/agent/action.ts +26 -35
- package/src/store/session/slices/agent/selectors.ts +32 -37
- package/src/store/session/slices/session/action.ts +81 -88
- package/src/store/session/slices/session/helpers.ts +19 -0
- package/src/store/session/slices/session/initialState.ts +7 -10
- package/src/store/session/slices/session/selectors/export.ts +12 -9
- package/src/store/session/slices/session/selectors/index.ts +2 -35
- package/src/store/session/slices/session/selectors/list.test.ts +25 -203
- package/src/store/session/slices/session/selectors/list.ts +40 -78
- package/src/store/session/store.ts +11 -17
- package/src/types/agent/index.ts +61 -0
- package/src/types/chatMessage.ts +11 -20
- package/src/types/exportConfig.ts +7 -2
- package/src/types/files.ts +2 -2
- package/src/types/llm.ts +1 -1
- package/src/types/meta.ts +24 -12
- package/src/types/openai/chat.ts +9 -1
- package/src/types/openai/functionCall.ts +4 -0
- package/src/types/session.ts +10 -94
- package/src/types/settings.ts +2 -0
- package/src/types/translate.ts +2 -1
- package/src/utils/config.ts +5 -11
- package/src/utils/fetch.ts +8 -2
- package/src/app/chat/features/Conversation/usePluginsInit.ts +0 -14
- package/src/database/core/schema.ts +0 -9
- package/src/helpers/export.ts +0 -69
- package/src/hooks/useExportConfig.ts +0 -6
- package/src/store/session/slices/chat/actions/index.ts +0 -32
- package/src/store/session/slices/chat/actions/topic.ts +0 -171
- package/src/store/session/slices/chat/actions/translate.ts +0 -113
- package/src/store/session/slices/chat/helpers.ts +0 -9
- package/src/store/session/slices/chat/initialState.ts +0 -13
- package/src/store/session/slices/chat/reducers/message.test.ts +0 -319
- package/src/store/session/slices/chat/reducers/message.ts +0 -156
- package/src/store/session/slices/chat/reducers/topic.test.ts +0 -179
- package/src/store/session/slices/chat/reducers/topic.ts +0 -81
- package/src/store/session/slices/chat/selectors/chat.ts +0 -111
- package/src/store/session/slices/chat/selectors/index.ts +0 -26
- package/src/store/session/slices/chat/selectors/topic.ts +0 -30
- package/src/store/session/slices/chat/selectors/utils.test.ts +0 -385
- package/src/store/session/slices/chat/selectors/utils.ts +0 -91
- package/src/store/session/slices/chat/utils.ts +0 -13
- package/src/store/session/slices/session/reducers/session.test.ts +0 -577
- package/src/store/session/slices/session/reducers/session.ts +0 -182
- package/src/types/database/db.ts +0 -4
- /package/src/store/{session/slices/chat → chat}/reducers/files.test.ts +0 -0
- /package/src/store/{session/slices/chat → chat}/reducers/files.ts +0 -0
|
@@ -1,577 +0,0 @@
|
|
|
1
|
-
import { produce } from 'immer';
|
|
2
|
-
|
|
3
|
-
import { ChatMessage } from '@/types/chatMessage';
|
|
4
|
-
import { LanguageModel } from '@/types/llm';
|
|
5
|
-
import { MetaData } from '@/types/meta';
|
|
6
|
-
import { LobeAgentConfig, LobeAgentSession, LobeSessionType, LobeSessions } from '@/types/session';
|
|
7
|
-
|
|
8
|
-
import { SessionDispatch, sessionsReducer } from './session';
|
|
9
|
-
|
|
10
|
-
describe('sessionsReducer', () => {
|
|
11
|
-
describe('addSession', () => {
|
|
12
|
-
it('should add session to state when valid session and type are provided', () => {
|
|
13
|
-
const state: LobeSessions = {};
|
|
14
|
-
const session = {
|
|
15
|
-
id: 'session-id',
|
|
16
|
-
config: {
|
|
17
|
-
model: LanguageModel.GPT3_5,
|
|
18
|
-
params: {},
|
|
19
|
-
systemRole: 'system-role',
|
|
20
|
-
},
|
|
21
|
-
type: LobeSessionType.Agent,
|
|
22
|
-
} as LobeAgentSession;
|
|
23
|
-
const payload: SessionDispatch = {
|
|
24
|
-
type: 'addSession',
|
|
25
|
-
session,
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const newState = sessionsReducer(state, payload);
|
|
29
|
-
|
|
30
|
-
expect(newState).toEqual({
|
|
31
|
-
'session-id': session,
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should not change state when invalid session and type are provided', () => {
|
|
36
|
-
const state: LobeSessions = {};
|
|
37
|
-
const session = undefined as unknown as LobeAgentSession;
|
|
38
|
-
const payload: SessionDispatch = {
|
|
39
|
-
type: 'addSession',
|
|
40
|
-
session,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const newState = sessionsReducer(state, payload);
|
|
44
|
-
|
|
45
|
-
expect(newState).toEqual(state);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe('removeSession', () => {
|
|
50
|
-
it('should remove session from state when valid id and type are provided', () => {
|
|
51
|
-
const state = {
|
|
52
|
-
'session-id': {
|
|
53
|
-
id: 'session-id',
|
|
54
|
-
config: {
|
|
55
|
-
model: 'gpt-3.5-turbo',
|
|
56
|
-
params: {},
|
|
57
|
-
systemRole: 'system-role',
|
|
58
|
-
},
|
|
59
|
-
type: 'agent',
|
|
60
|
-
} as LobeAgentSession,
|
|
61
|
-
} as LobeSessions;
|
|
62
|
-
const id = 'session-id';
|
|
63
|
-
const payload: SessionDispatch = {
|
|
64
|
-
type: 'removeSession',
|
|
65
|
-
id,
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const newState = sessionsReducer(state, payload);
|
|
69
|
-
|
|
70
|
-
expect(newState).toEqual({});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should not change state when invalid id and type are provided', () => {
|
|
74
|
-
const state: LobeSessions = {
|
|
75
|
-
'session-id': {
|
|
76
|
-
id: 'session-id',
|
|
77
|
-
config: {
|
|
78
|
-
model: 'gpt-3.5-turbo',
|
|
79
|
-
params: {},
|
|
80
|
-
systemRole: 'system-role',
|
|
81
|
-
},
|
|
82
|
-
type: 'agent',
|
|
83
|
-
} as LobeAgentSession,
|
|
84
|
-
};
|
|
85
|
-
const id = 'non-existent-id';
|
|
86
|
-
const payload: SessionDispatch = {
|
|
87
|
-
type: 'removeSession',
|
|
88
|
-
id,
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const newState = sessionsReducer(state, payload);
|
|
92
|
-
|
|
93
|
-
expect(newState).toEqual(state);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe('updateSessionMeta', () => {
|
|
98
|
-
it('should update session meta when valid id, key, and value are provided', () => {
|
|
99
|
-
const state: LobeSessions = {
|
|
100
|
-
'session-id': {
|
|
101
|
-
id: 'session-id',
|
|
102
|
-
config: {
|
|
103
|
-
model: 'gpt-3.5-turbo',
|
|
104
|
-
params: {},
|
|
105
|
-
systemRole: 'system-role',
|
|
106
|
-
},
|
|
107
|
-
type: 'agent',
|
|
108
|
-
meta: {
|
|
109
|
-
avatar: 'avatar-url',
|
|
110
|
-
backgroundColor: 'background-color',
|
|
111
|
-
description: 'description',
|
|
112
|
-
tags: ['tag1', 'tag2'],
|
|
113
|
-
title: 'title',
|
|
114
|
-
},
|
|
115
|
-
} as LobeAgentSession,
|
|
116
|
-
};
|
|
117
|
-
const id = 'session-id';
|
|
118
|
-
const key: keyof MetaData = 'title';
|
|
119
|
-
const value = 'new-title';
|
|
120
|
-
const payload: SessionDispatch = {
|
|
121
|
-
type: 'updateSessionMeta',
|
|
122
|
-
id,
|
|
123
|
-
key,
|
|
124
|
-
value,
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
const newState = sessionsReducer(state, payload);
|
|
128
|
-
|
|
129
|
-
expect(newState).toEqual({
|
|
130
|
-
'session-id': {
|
|
131
|
-
...state['session-id'],
|
|
132
|
-
meta: {
|
|
133
|
-
...state['session-id'].meta,
|
|
134
|
-
title: 'new-title',
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('should not change state when invalid id, key, and value are provided', () => {
|
|
141
|
-
const state: LobeSessions = {
|
|
142
|
-
'session-id': {
|
|
143
|
-
id: 'session-id',
|
|
144
|
-
config: {
|
|
145
|
-
model: 'gpt-3.5-turbo',
|
|
146
|
-
params: {},
|
|
147
|
-
systemRole: 'system-role',
|
|
148
|
-
},
|
|
149
|
-
type: 'agent',
|
|
150
|
-
meta: {
|
|
151
|
-
avatar: 'avatar-url',
|
|
152
|
-
backgroundColor: 'background-color',
|
|
153
|
-
description: 'description',
|
|
154
|
-
tags: ['tag1', 'tag2'],
|
|
155
|
-
title: 'title',
|
|
156
|
-
},
|
|
157
|
-
} as LobeAgentSession,
|
|
158
|
-
};
|
|
159
|
-
const id = 'non-existent-id';
|
|
160
|
-
const key = 'invalid-key' as keyof MetaData;
|
|
161
|
-
const value = 'new-value';
|
|
162
|
-
const payload: SessionDispatch = {
|
|
163
|
-
type: 'updateSessionMeta',
|
|
164
|
-
id,
|
|
165
|
-
key,
|
|
166
|
-
value,
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
const newState = sessionsReducer(state, payload);
|
|
170
|
-
|
|
171
|
-
expect(newState).toEqual(state);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('should not change state when valid id, invalid key, and value are provided', () => {
|
|
175
|
-
const state: LobeSessions = {
|
|
176
|
-
'session-id': {
|
|
177
|
-
id: 'session-id',
|
|
178
|
-
config: {
|
|
179
|
-
model: 'gpt-3.5-turbo',
|
|
180
|
-
params: {},
|
|
181
|
-
systemRole: 'system-role',
|
|
182
|
-
},
|
|
183
|
-
type: 'agent',
|
|
184
|
-
meta: {
|
|
185
|
-
avatar: 'avatar-url',
|
|
186
|
-
backgroundColor: 'background-color',
|
|
187
|
-
description: 'description',
|
|
188
|
-
tags: ['tag1', 'tag2'],
|
|
189
|
-
title: 'title',
|
|
190
|
-
},
|
|
191
|
-
} as LobeAgentSession,
|
|
192
|
-
};
|
|
193
|
-
const id = 'session-id';
|
|
194
|
-
const key = 'invalid-key' as keyof MetaData;
|
|
195
|
-
const value = 'new-value';
|
|
196
|
-
const payload: SessionDispatch = {
|
|
197
|
-
type: 'updateSessionMeta',
|
|
198
|
-
id,
|
|
199
|
-
key,
|
|
200
|
-
value,
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
const newState = sessionsReducer(state, payload);
|
|
204
|
-
|
|
205
|
-
expect(newState).toEqual(state);
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
describe('updateSessionFiles', () => {
|
|
210
|
-
it('should update session files when valid id, key, and value are provided', () => {
|
|
211
|
-
const state: LobeSessions = {
|
|
212
|
-
'session-id': {
|
|
213
|
-
id: 'session-id',
|
|
214
|
-
config: {
|
|
215
|
-
model: 'gpt-3.5-turbo',
|
|
216
|
-
params: {},
|
|
217
|
-
systemRole: 'system-role',
|
|
218
|
-
},
|
|
219
|
-
type: 'agent',
|
|
220
|
-
meta: {
|
|
221
|
-
avatar: 'avatar-url',
|
|
222
|
-
backgroundColor: 'background-color',
|
|
223
|
-
description: 'description',
|
|
224
|
-
tags: ['tag1', 'tag2'],
|
|
225
|
-
title: 'title',
|
|
226
|
-
},
|
|
227
|
-
} as LobeAgentSession,
|
|
228
|
-
};
|
|
229
|
-
const id = 'session-id';
|
|
230
|
-
const files = ['new-file'];
|
|
231
|
-
const payload: SessionDispatch = { type: 'updateSessionFiles', id, files };
|
|
232
|
-
|
|
233
|
-
const newState = sessionsReducer(state, payload);
|
|
234
|
-
|
|
235
|
-
expect(newState).toEqual({
|
|
236
|
-
'session-id': {
|
|
237
|
-
...state['session-id'],
|
|
238
|
-
files: ['new-file'],
|
|
239
|
-
},
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it('should not change state when invalid id, key, and value are provided', () => {
|
|
244
|
-
const state: LobeSessions = {
|
|
245
|
-
'session-id': {
|
|
246
|
-
id: 'session-id',
|
|
247
|
-
config: {
|
|
248
|
-
model: 'gpt-3.5-turbo',
|
|
249
|
-
params: {},
|
|
250
|
-
systemRole: 'system-role',
|
|
251
|
-
},
|
|
252
|
-
type: 'agent',
|
|
253
|
-
meta: {
|
|
254
|
-
avatar: 'avatar-url',
|
|
255
|
-
backgroundColor: 'background-color',
|
|
256
|
-
description: 'description',
|
|
257
|
-
tags: ['tag1', 'tag2'],
|
|
258
|
-
title: 'title',
|
|
259
|
-
},
|
|
260
|
-
} as LobeAgentSession,
|
|
261
|
-
};
|
|
262
|
-
const id = 'non-existent-id';
|
|
263
|
-
const files = ['new-file'];
|
|
264
|
-
const payload: SessionDispatch = { type: 'updateSessionFiles', id, files };
|
|
265
|
-
|
|
266
|
-
const newState = sessionsReducer(state, payload);
|
|
267
|
-
|
|
268
|
-
expect(newState).toEqual(state);
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
it('should not change state when valid id, invalid files are provided', () => {
|
|
272
|
-
const state: LobeSessions = {
|
|
273
|
-
'session-id': {
|
|
274
|
-
id: 'session-id',
|
|
275
|
-
config: {
|
|
276
|
-
model: 'gpt-3.5-turbo',
|
|
277
|
-
params: {},
|
|
278
|
-
systemRole: 'system-role',
|
|
279
|
-
},
|
|
280
|
-
type: 'agent',
|
|
281
|
-
meta: {
|
|
282
|
-
avatar: 'avatar-url',
|
|
283
|
-
backgroundColor: 'background-color',
|
|
284
|
-
description: 'description',
|
|
285
|
-
tags: ['tag1', 'tag2'],
|
|
286
|
-
title: 'title',
|
|
287
|
-
},
|
|
288
|
-
} as LobeAgentSession,
|
|
289
|
-
};
|
|
290
|
-
const id = 'session-id';
|
|
291
|
-
|
|
292
|
-
const errFile1 = 123213412 as any;
|
|
293
|
-
const res1 = sessionsReducer(state, { type: 'updateSessionFiles', id, files: errFile1 });
|
|
294
|
-
expect(res1).toEqual(state);
|
|
295
|
-
|
|
296
|
-
const errFile2 = undefined as any;
|
|
297
|
-
const res2 = sessionsReducer(state, { type: 'updateSessionFiles', id, files: errFile2 });
|
|
298
|
-
expect(res2).toEqual(state);
|
|
299
|
-
|
|
300
|
-
const errFile3 = ['state', 123] as any;
|
|
301
|
-
const res3 = sessionsReducer(state, { type: 'updateSessionFiles', id, files: errFile3 });
|
|
302
|
-
expect(res3).toEqual(state);
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
describe('updateSessionConfig', () => {
|
|
307
|
-
it('should update session config when valid id and partial config are provided', () => {
|
|
308
|
-
const state: LobeSessions = {
|
|
309
|
-
'session-id': {
|
|
310
|
-
id: 'session-id',
|
|
311
|
-
config: {
|
|
312
|
-
model: 'gpt-3.5-turbo',
|
|
313
|
-
params: {},
|
|
314
|
-
systemRole: 'system-role',
|
|
315
|
-
tts: {
|
|
316
|
-
showAllLocaleVoice: false,
|
|
317
|
-
sttLocale: 'auto',
|
|
318
|
-
ttsService: 'openai',
|
|
319
|
-
voice: {
|
|
320
|
-
openai: 'alloy',
|
|
321
|
-
},
|
|
322
|
-
},
|
|
323
|
-
},
|
|
324
|
-
type: 'agent',
|
|
325
|
-
meta: {
|
|
326
|
-
avatar: 'avatar-url',
|
|
327
|
-
backgroundColor: 'background-color',
|
|
328
|
-
description: 'description',
|
|
329
|
-
tags: ['tag1', 'tag2'],
|
|
330
|
-
title: 'title',
|
|
331
|
-
},
|
|
332
|
-
} as LobeAgentSession,
|
|
333
|
-
};
|
|
334
|
-
const id = 'session-id';
|
|
335
|
-
const config: Partial<LobeAgentConfig> = {
|
|
336
|
-
model: LanguageModel.GPT4,
|
|
337
|
-
};
|
|
338
|
-
const payload: SessionDispatch = {
|
|
339
|
-
type: 'updateSessionConfig',
|
|
340
|
-
id,
|
|
341
|
-
config,
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
const newState = sessionsReducer(state, payload);
|
|
345
|
-
|
|
346
|
-
expect(newState).toEqual({
|
|
347
|
-
'session-id': {
|
|
348
|
-
...state['session-id'],
|
|
349
|
-
config: {
|
|
350
|
-
...state['session-id'].config,
|
|
351
|
-
model: 'gpt-4',
|
|
352
|
-
},
|
|
353
|
-
},
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
it('should update session agent config correctly', () => {
|
|
358
|
-
const state: LobeSessions = {
|
|
359
|
-
session1: {
|
|
360
|
-
id: 'session1',
|
|
361
|
-
config: {
|
|
362
|
-
model: 'gpt-3.5-turbo',
|
|
363
|
-
params: {},
|
|
364
|
-
systemRole: 'system',
|
|
365
|
-
tts: {
|
|
366
|
-
showAllLocaleVoice: false,
|
|
367
|
-
sttLocale: 'auto',
|
|
368
|
-
ttsService: 'openai',
|
|
369
|
-
voice: {
|
|
370
|
-
openai: 'alloy',
|
|
371
|
-
},
|
|
372
|
-
},
|
|
373
|
-
},
|
|
374
|
-
} as LobeAgentSession,
|
|
375
|
-
session2: {
|
|
376
|
-
id: 'session2',
|
|
377
|
-
config: {
|
|
378
|
-
model: 'gpt-3.5-turbo',
|
|
379
|
-
params: {},
|
|
380
|
-
systemRole: 'system',
|
|
381
|
-
},
|
|
382
|
-
} as LobeAgentSession,
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
const payload: SessionDispatch = {
|
|
386
|
-
type: 'updateSessionConfig',
|
|
387
|
-
id: 'session1',
|
|
388
|
-
config: {
|
|
389
|
-
model: LanguageModel.GPT4,
|
|
390
|
-
params: {},
|
|
391
|
-
},
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
const expectedState = produce(state, (draft) => {
|
|
395
|
-
draft.session1.config = {
|
|
396
|
-
model: LanguageModel.GPT4,
|
|
397
|
-
params: {},
|
|
398
|
-
tts: {
|
|
399
|
-
ttsService: 'openai',
|
|
400
|
-
sttLocale: 'auto',
|
|
401
|
-
showAllLocaleVoice: false,
|
|
402
|
-
voice: {
|
|
403
|
-
openai: 'alloy',
|
|
404
|
-
},
|
|
405
|
-
},
|
|
406
|
-
systemRole: 'system',
|
|
407
|
-
} as LobeAgentConfig;
|
|
408
|
-
});
|
|
409
|
-
|
|
410
|
-
const newState = sessionsReducer(state, payload);
|
|
411
|
-
|
|
412
|
-
expect(newState).toEqual(expectedState);
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
it('should not change state when invalid session ID is provided for updating session agent config', () => {
|
|
416
|
-
const state: LobeSessions = {
|
|
417
|
-
session1: {
|
|
418
|
-
id: 'session1',
|
|
419
|
-
config: {
|
|
420
|
-
model: 'gpt-3.5-turbo',
|
|
421
|
-
params: {},
|
|
422
|
-
systemRole: 'system',
|
|
423
|
-
},
|
|
424
|
-
} as LobeAgentSession,
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
const payload: SessionDispatch = {
|
|
428
|
-
type: 'updateSessionConfig',
|
|
429
|
-
id: 'session2',
|
|
430
|
-
config: {
|
|
431
|
-
model: LanguageModel.GPT4,
|
|
432
|
-
params: {},
|
|
433
|
-
},
|
|
434
|
-
};
|
|
435
|
-
|
|
436
|
-
const newState = sessionsReducer(state, payload);
|
|
437
|
-
|
|
438
|
-
expect(newState).toEqual(state);
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
it.skip('should not change state when invalid session agent config is provided for updating session agent config', () => {
|
|
442
|
-
const state: LobeSessions = {
|
|
443
|
-
session1: {
|
|
444
|
-
id: 'session1',
|
|
445
|
-
config: {
|
|
446
|
-
model: 'gpt-3.5-turbo',
|
|
447
|
-
params: {},
|
|
448
|
-
systemRole: 'system',
|
|
449
|
-
},
|
|
450
|
-
} as LobeAgentSession,
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
const payload: SessionDispatch = {
|
|
454
|
-
type: 'updateSessionConfig',
|
|
455
|
-
id: 'session1',
|
|
456
|
-
config: {
|
|
457
|
-
model: LanguageModel.GPT4,
|
|
458
|
-
params: {},
|
|
459
|
-
invalidKey: 'invalidValue',
|
|
460
|
-
} as unknown as LobeAgentConfig,
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
const newState = sessionsReducer(state, payload);
|
|
464
|
-
|
|
465
|
-
expect(newState).toEqual(state);
|
|
466
|
-
});
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
it('should not change state when invalid operation type is provided', () => {
|
|
470
|
-
const state: LobeSessions = {
|
|
471
|
-
session1: {
|
|
472
|
-
id: 'session1',
|
|
473
|
-
config: {
|
|
474
|
-
model: 'gpt-3.5-turbo',
|
|
475
|
-
params: {},
|
|
476
|
-
systemRole: 'system',
|
|
477
|
-
},
|
|
478
|
-
} as LobeAgentSession,
|
|
479
|
-
};
|
|
480
|
-
|
|
481
|
-
const payload = {
|
|
482
|
-
type: 'invalidOperation',
|
|
483
|
-
} as unknown as SessionDispatch;
|
|
484
|
-
|
|
485
|
-
const newState = sessionsReducer(state, payload);
|
|
486
|
-
|
|
487
|
-
expect(newState).toEqual(state);
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
describe('updateSessionChat', () => {
|
|
491
|
-
it('should update session chat correctly', () => {
|
|
492
|
-
const state: LobeSessions = {
|
|
493
|
-
session1: {
|
|
494
|
-
id: 'session1',
|
|
495
|
-
chats: {},
|
|
496
|
-
} as LobeAgentSession,
|
|
497
|
-
session2: {
|
|
498
|
-
id: 'session2',
|
|
499
|
-
chats: {},
|
|
500
|
-
} as LobeAgentSession,
|
|
501
|
-
};
|
|
502
|
-
|
|
503
|
-
const payload: SessionDispatch = {
|
|
504
|
-
type: 'updateSessionChat',
|
|
505
|
-
id: 'session1',
|
|
506
|
-
chats: {
|
|
507
|
-
message1: {
|
|
508
|
-
id: 'message1',
|
|
509
|
-
content: 'Hello',
|
|
510
|
-
} as ChatMessage,
|
|
511
|
-
},
|
|
512
|
-
};
|
|
513
|
-
|
|
514
|
-
const expectedState = produce(state, (draft) => {
|
|
515
|
-
draft.session1.chats = {
|
|
516
|
-
message1: {
|
|
517
|
-
id: 'message1',
|
|
518
|
-
content: 'Hello',
|
|
519
|
-
} as ChatMessage,
|
|
520
|
-
};
|
|
521
|
-
});
|
|
522
|
-
|
|
523
|
-
const newState = sessionsReducer(state, payload);
|
|
524
|
-
|
|
525
|
-
expect(newState).toEqual(expectedState);
|
|
526
|
-
});
|
|
527
|
-
|
|
528
|
-
it('should not change state when invalid session ID is provided for updating session chat', () => {
|
|
529
|
-
const state: LobeSessions = {
|
|
530
|
-
session1: {
|
|
531
|
-
id: 'session1',
|
|
532
|
-
chats: {},
|
|
533
|
-
} as LobeAgentSession,
|
|
534
|
-
};
|
|
535
|
-
|
|
536
|
-
const payload: SessionDispatch = {
|
|
537
|
-
type: 'updateSessionChat',
|
|
538
|
-
id: 'session2',
|
|
539
|
-
chats: {
|
|
540
|
-
message1: {
|
|
541
|
-
id: 'message1',
|
|
542
|
-
content: 'Hello',
|
|
543
|
-
} as ChatMessage,
|
|
544
|
-
},
|
|
545
|
-
};
|
|
546
|
-
|
|
547
|
-
const newState = sessionsReducer(state, payload);
|
|
548
|
-
|
|
549
|
-
expect(newState).toEqual(state);
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
it.skip('should not change state when invalid chat data is provided for updating session chat', () => {
|
|
553
|
-
const state: LobeSessions = {
|
|
554
|
-
session1: {
|
|
555
|
-
id: 'session1',
|
|
556
|
-
chats: {},
|
|
557
|
-
} as LobeAgentSession,
|
|
558
|
-
};
|
|
559
|
-
|
|
560
|
-
const payload: SessionDispatch = {
|
|
561
|
-
type: 'updateSessionChat',
|
|
562
|
-
id: 'session1',
|
|
563
|
-
chats: {
|
|
564
|
-
message1: {
|
|
565
|
-
id: 'message1',
|
|
566
|
-
content: 'Hello',
|
|
567
|
-
invalidKey: 'invalidValue',
|
|
568
|
-
} as unknown as ChatMessage,
|
|
569
|
-
},
|
|
570
|
-
};
|
|
571
|
-
|
|
572
|
-
const newState = sessionsReducer(state, payload);
|
|
573
|
-
|
|
574
|
-
expect(newState).toEqual(state);
|
|
575
|
-
});
|
|
576
|
-
});
|
|
577
|
-
});
|