@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,179 +0,0 @@
|
|
|
1
|
-
import { produce } from 'immer';
|
|
2
|
-
|
|
3
|
-
import { ChatTopic, ChatTopicMap } from '@/types/topic';
|
|
4
|
-
|
|
5
|
-
import { ChatTopicDispatch, topicReducer } from './topic';
|
|
6
|
-
|
|
7
|
-
describe('topicReducer', () => {
|
|
8
|
-
let state: ChatTopicMap;
|
|
9
|
-
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
state = {};
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe('addChatTopic', () => {
|
|
15
|
-
it('should add a new ChatTopic object to state', () => {
|
|
16
|
-
const payload: ChatTopicDispatch = {
|
|
17
|
-
type: 'addChatTopic',
|
|
18
|
-
topic: {
|
|
19
|
-
id: '1',
|
|
20
|
-
title: 'Test Topic',
|
|
21
|
-
createAt: Date.now(),
|
|
22
|
-
updateAt: Date.now(),
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const newState = topicReducer(state, payload);
|
|
27
|
-
|
|
28
|
-
expect(newState).toMatchObject({
|
|
29
|
-
'1': payload.topic,
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('should add a ChatTopic object with correct id', () => {
|
|
34
|
-
const payload: ChatTopicDispatch = {
|
|
35
|
-
type: 'addChatTopic',
|
|
36
|
-
topic: {
|
|
37
|
-
id: '1',
|
|
38
|
-
title: 'Test Topic',
|
|
39
|
-
createAt: Date.now(),
|
|
40
|
-
updateAt: Date.now(),
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const newState = topicReducer(state, payload);
|
|
45
|
-
|
|
46
|
-
expect(newState['1']).toBeDefined();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('should add a ChatTopic object with correct properties', () => {
|
|
50
|
-
const payload: ChatTopicDispatch = {
|
|
51
|
-
type: 'addChatTopic',
|
|
52
|
-
topic: {
|
|
53
|
-
id: '1',
|
|
54
|
-
title: 'Test Topic',
|
|
55
|
-
createAt: Date.now(),
|
|
56
|
-
updateAt: Date.now(),
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const newState = topicReducer(state, payload);
|
|
61
|
-
|
|
62
|
-
expect(newState['1']).toMatchObject(payload.topic);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe('updateChatTopic', () => {
|
|
67
|
-
it('should update the ChatTopic object in state', () => {
|
|
68
|
-
const topic: ChatTopic = {
|
|
69
|
-
id: '1',
|
|
70
|
-
title: 'Test Topic',
|
|
71
|
-
createAt: Date.now(),
|
|
72
|
-
updateAt: Date.now(),
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
state['1'] = topic;
|
|
76
|
-
|
|
77
|
-
const payload: ChatTopicDispatch = {
|
|
78
|
-
type: 'updateChatTopic',
|
|
79
|
-
id: '1',
|
|
80
|
-
key: 'title',
|
|
81
|
-
value: 'Updated Topic',
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const newState = topicReducer(state, payload);
|
|
85
|
-
|
|
86
|
-
expect(newState['1'].title).toBe('Updated Topic');
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('should update the ChatTopic object with correct properties', () => {
|
|
90
|
-
const topic: ChatTopic = {
|
|
91
|
-
id: '1',
|
|
92
|
-
title: 'Test Topic',
|
|
93
|
-
createAt: Date.now() - 1,
|
|
94
|
-
updateAt: Date.now() - 1, // 设定比当前时间前面一点
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
state['1'] = topic;
|
|
98
|
-
|
|
99
|
-
const payload: ChatTopicDispatch = {
|
|
100
|
-
type: 'updateChatTopic',
|
|
101
|
-
id: '1',
|
|
102
|
-
key: 'title',
|
|
103
|
-
value: 'Updated Topic',
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const newState = topicReducer(state, payload);
|
|
107
|
-
|
|
108
|
-
expect(newState['1'].updateAt).toBeGreaterThan(topic.updateAt);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
describe('deleteChatTopic', () => {
|
|
113
|
-
it('should delete the specified ChatTopic object from state', () => {
|
|
114
|
-
const topic: ChatTopic = {
|
|
115
|
-
id: '1',
|
|
116
|
-
title: 'Test Topic',
|
|
117
|
-
createAt: Date.now(),
|
|
118
|
-
updateAt: Date.now(),
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
state['1'] = topic;
|
|
122
|
-
|
|
123
|
-
const payload: ChatTopicDispatch = {
|
|
124
|
-
type: 'deleteChatTopic',
|
|
125
|
-
id: '1',
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const newState = topicReducer(state, payload);
|
|
129
|
-
|
|
130
|
-
expect(newState['1']).toBeUndefined();
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe('default', () => {
|
|
135
|
-
it('should return the original state object', () => {
|
|
136
|
-
const payload = {
|
|
137
|
-
type: 'unknown',
|
|
138
|
-
} as unknown as ChatTopicDispatch;
|
|
139
|
-
|
|
140
|
-
const newState = topicReducer(state, payload);
|
|
141
|
-
|
|
142
|
-
expect(newState).toBe(state);
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
describe('produce', () => {
|
|
147
|
-
it('should generate immutable state object', () => {
|
|
148
|
-
const payload: ChatTopicDispatch = {
|
|
149
|
-
type: 'addChatTopic',
|
|
150
|
-
topic: {
|
|
151
|
-
id: '1',
|
|
152
|
-
title: 'Test Topic',
|
|
153
|
-
createAt: Date.now(),
|
|
154
|
-
updateAt: Date.now(),
|
|
155
|
-
},
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
const newState = topicReducer(state, payload);
|
|
159
|
-
|
|
160
|
-
expect(newState).not.toBe(state);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('should not modify the original state object', () => {
|
|
164
|
-
const payload: ChatTopicDispatch = {
|
|
165
|
-
type: 'addChatTopic',
|
|
166
|
-
topic: {
|
|
167
|
-
id: '1',
|
|
168
|
-
title: 'Test Topic',
|
|
169
|
-
createAt: Date.now(),
|
|
170
|
-
updateAt: Date.now(),
|
|
171
|
-
},
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
const newState = topicReducer(state, payload);
|
|
175
|
-
|
|
176
|
-
expect(state).toMatchObject({});
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
});
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { produce } from 'immer';
|
|
2
|
-
|
|
3
|
-
import { ChatTopic, ChatTopicMap } from '@/types/topic';
|
|
4
|
-
|
|
5
|
-
interface AddChatTopicAction {
|
|
6
|
-
topic: ChatTopic;
|
|
7
|
-
type: 'addChatTopic';
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface UpdateChatTopicAction {
|
|
11
|
-
id: string;
|
|
12
|
-
key: keyof ChatTopic;
|
|
13
|
-
type: 'updateChatTopic';
|
|
14
|
-
value: any;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface FavorChatTopicAction {
|
|
18
|
-
favorite: boolean;
|
|
19
|
-
id: string;
|
|
20
|
-
type: 'favorChatTopic';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface DeleteChatTopicAction {
|
|
24
|
-
id: string;
|
|
25
|
-
type: 'deleteChatTopic';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type ChatTopicDispatch =
|
|
29
|
-
| AddChatTopicAction
|
|
30
|
-
| UpdateChatTopicAction
|
|
31
|
-
| DeleteChatTopicAction
|
|
32
|
-
| FavorChatTopicAction;
|
|
33
|
-
|
|
34
|
-
export const topicReducer = (state: ChatTopicMap, payload: ChatTopicDispatch): ChatTopicMap => {
|
|
35
|
-
switch (payload.type) {
|
|
36
|
-
case 'addChatTopic': {
|
|
37
|
-
return produce(state, (draftState) => {
|
|
38
|
-
draftState[payload.topic.id] = payload.topic;
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
case 'updateChatTopic': {
|
|
43
|
-
return produce(state, (draftState) => {
|
|
44
|
-
const { key, value, id } = payload;
|
|
45
|
-
|
|
46
|
-
if (!draftState[id]) return;
|
|
47
|
-
|
|
48
|
-
const topic = draftState[id];
|
|
49
|
-
|
|
50
|
-
if (value !== undefined) {
|
|
51
|
-
// @ts-ignore
|
|
52
|
-
topic[key] = value;
|
|
53
|
-
|
|
54
|
-
topic.updateAt = Date.now();
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
case 'favorChatTopic': {
|
|
60
|
-
return produce(state, (draftState) => {
|
|
61
|
-
const { favorite, id } = payload;
|
|
62
|
-
|
|
63
|
-
if (!draftState[id]) return;
|
|
64
|
-
|
|
65
|
-
const topic = draftState[id];
|
|
66
|
-
|
|
67
|
-
topic.favorite = favorite;
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
case 'deleteChatTopic': {
|
|
72
|
-
return produce(state, (draftState) => {
|
|
73
|
-
delete draftState[payload.id];
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
default: {
|
|
78
|
-
return state;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
};
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { LobePluginType } from '@lobehub/chat-plugin-sdk';
|
|
2
|
-
import { t } from 'i18next';
|
|
3
|
-
|
|
4
|
-
import { DEFAULT_INBOX_AVATAR, DEFAULT_USER_AVATAR } from '@/const/meta';
|
|
5
|
-
import { INBOX_SESSION_ID } from '@/const/session';
|
|
6
|
-
import { useGlobalStore } from '@/store/global';
|
|
7
|
-
import { ChatMessage } from '@/types/chatMessage';
|
|
8
|
-
|
|
9
|
-
import type { SessionStore } from '../../../store';
|
|
10
|
-
import { agentSelectors } from '../../agent';
|
|
11
|
-
import { sessionSelectors } from '../../session/selectors';
|
|
12
|
-
import { getSlicedMessagesWithConfig } from '../utils';
|
|
13
|
-
import { currentTopics } from './topic';
|
|
14
|
-
import { organizeChats } from './utils';
|
|
15
|
-
|
|
16
|
-
export const getChatsById =
|
|
17
|
-
(id: string) =>
|
|
18
|
-
(s: SessionStore): ChatMessage[] => {
|
|
19
|
-
const session = sessionSelectors.getSessionById(id)(s);
|
|
20
|
-
|
|
21
|
-
if (!session) return [];
|
|
22
|
-
|
|
23
|
-
return organizeChats(session, {
|
|
24
|
-
meta: {
|
|
25
|
-
assistant: {
|
|
26
|
-
avatar: agentSelectors.currentAgentAvatar(s),
|
|
27
|
-
backgroundColor: agentSelectors.currentAgentBackgroundColor(s),
|
|
28
|
-
},
|
|
29
|
-
user: {
|
|
30
|
-
avatar: useGlobalStore.getState().settings.avatar || DEFAULT_USER_AVATAR,
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
topicId: s.activeTopicId,
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// 当前激活的消息列表
|
|
38
|
-
export const currentChats = (s: SessionStore): ChatMessage[] => {
|
|
39
|
-
if (!s.activeId) return [];
|
|
40
|
-
|
|
41
|
-
return getChatsById(s.activeId)(s);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const initTime = Date.now();
|
|
45
|
-
// 针对新助手添加初始化时的自定义消息
|
|
46
|
-
export const currentChatsWithGuideMessage = (s: SessionStore): ChatMessage[] => {
|
|
47
|
-
const data = currentChats(s);
|
|
48
|
-
const noTopic = currentTopics(s);
|
|
49
|
-
|
|
50
|
-
const isBrandNewChat = data.length === 0 && noTopic;
|
|
51
|
-
|
|
52
|
-
if (!isBrandNewChat) return data;
|
|
53
|
-
|
|
54
|
-
const [activeId, isInbox] = [s.activeId, s.activeId === INBOX_SESSION_ID];
|
|
55
|
-
const meta = agentSelectors.currentAgentMeta(s);
|
|
56
|
-
|
|
57
|
-
const inboxMsg = t('inbox.defaultMessage', { ns: 'chat' });
|
|
58
|
-
const agentSystemRoleMsg = t('agentDefaultMessageWithSystemRole', {
|
|
59
|
-
name: meta.title || t('defaultAgent'),
|
|
60
|
-
ns: 'chat',
|
|
61
|
-
systemRole: meta.description,
|
|
62
|
-
});
|
|
63
|
-
const agentMsg = t('agentDefaultMessage', {
|
|
64
|
-
id: activeId,
|
|
65
|
-
name: meta.title || t('defaultAgent'),
|
|
66
|
-
ns: 'chat',
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
const emptyInboxGuideMessage = {
|
|
70
|
-
content: isInbox ? inboxMsg : !!meta.description ? agentSystemRoleMsg : agentMsg,
|
|
71
|
-
createAt: initTime,
|
|
72
|
-
extra: {},
|
|
73
|
-
id: 'default',
|
|
74
|
-
meta: meta || {
|
|
75
|
-
avatar: DEFAULT_INBOX_AVATAR,
|
|
76
|
-
},
|
|
77
|
-
role: 'assistant',
|
|
78
|
-
updateAt: initTime,
|
|
79
|
-
} as ChatMessage;
|
|
80
|
-
|
|
81
|
-
return [emptyInboxGuideMessage];
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export const currentChatsWithHistoryConfig = (s: SessionStore): ChatMessage[] => {
|
|
85
|
-
const chats = currentChats(s);
|
|
86
|
-
const config = agentSelectors.currentAgentConfig(s);
|
|
87
|
-
|
|
88
|
-
return getSlicedMessagesWithConfig(chats, config);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export const chatsMessageString = (s: SessionStore): string => {
|
|
92
|
-
const chats = currentChatsWithHistoryConfig(s);
|
|
93
|
-
return chats.map((m) => m.content).join('');
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export const getFunctionMessageProps =
|
|
97
|
-
({ plugin, content, id }: Pick<ChatMessage, 'plugin' | 'content' | 'id'>) =>
|
|
98
|
-
(s: SessionStore) => ({
|
|
99
|
-
arguments: plugin?.arguments,
|
|
100
|
-
command: plugin,
|
|
101
|
-
content,
|
|
102
|
-
id: plugin?.identifier,
|
|
103
|
-
loading: id === s.chatLoadingId,
|
|
104
|
-
type: plugin?.type as LobePluginType,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
export const getMessageById = (id: string) => (s: SessionStore) => {
|
|
108
|
-
for (const e of Object.values(s.sessions)) {
|
|
109
|
-
if (e.chats[id]) return e.chats[id];
|
|
110
|
-
}
|
|
111
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
chatsMessageString,
|
|
3
|
-
currentChats,
|
|
4
|
-
currentChatsWithGuideMessage,
|
|
5
|
-
currentChatsWithHistoryConfig,
|
|
6
|
-
getChatsById,
|
|
7
|
-
getFunctionMessageProps,
|
|
8
|
-
getMessageById,
|
|
9
|
-
} from './chat';
|
|
10
|
-
import { currentTopicLength, currentTopics, getTopicMessages } from './topic';
|
|
11
|
-
|
|
12
|
-
export const chatSelectors = {
|
|
13
|
-
chatsMessageString,
|
|
14
|
-
currentChats,
|
|
15
|
-
currentChatsWithGuideMessage,
|
|
16
|
-
currentChatsWithHistoryConfig,
|
|
17
|
-
getChatsById,
|
|
18
|
-
getFunctionMessageProps,
|
|
19
|
-
getMessageById,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const topicSelectors = {
|
|
23
|
-
currentTopicLength,
|
|
24
|
-
currentTopics,
|
|
25
|
-
getTopicMessages,
|
|
26
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// 展示在聊天框中的消息
|
|
2
|
-
import { ChatTopic } from '@/types/topic';
|
|
3
|
-
|
|
4
|
-
import { SessionStore } from '../../../store';
|
|
5
|
-
import { sessionSelectors } from '../../session/selectors';
|
|
6
|
-
import { organizeChats } from './utils';
|
|
7
|
-
|
|
8
|
-
export const currentTopics = (s: SessionStore): ChatTopic[] => {
|
|
9
|
-
const session = sessionSelectors.currentSession(s);
|
|
10
|
-
if (!session) return [];
|
|
11
|
-
|
|
12
|
-
const topics = Object.values(session.topics || {});
|
|
13
|
-
|
|
14
|
-
// 按时间倒序
|
|
15
|
-
const favTopics = topics.filter((t) => t.favorite).sort((a, b) => b.updateAt - a.updateAt);
|
|
16
|
-
const defaultTopics = topics.filter((t) => !t.favorite).sort((a, b) => b.updateAt - a.updateAt);
|
|
17
|
-
|
|
18
|
-
return [...favTopics, ...defaultTopics];
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const currentTopicLength = (s: SessionStore): number => {
|
|
22
|
-
return currentTopics(s).length;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const getTopicMessages = (topicId: string) => (s: SessionStore) => {
|
|
26
|
-
const session = sessionSelectors.currentSession(s);
|
|
27
|
-
if (!session) return [];
|
|
28
|
-
|
|
29
|
-
return organizeChats(session, { topicId });
|
|
30
|
-
};
|