@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.
Files changed (224) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +18 -0
  3. package/README.zh-CN.md +18 -0
  4. package/docs/Environment-Variable.md +4 -2
  5. package/docs/Environment-Variable.zh-CN.md +4 -2
  6. package/locales/en_US/common.json +19 -0
  7. package/locales/en_US/migration.json +45 -0
  8. package/locales/en_US/setting.json +7 -7
  9. package/locales/ja_JP/common.json +19 -0
  10. package/locales/ja_JP/migration.json +45 -0
  11. package/locales/ja_JP/setting.json +2 -2
  12. package/locales/ko_KR/common.json +19 -0
  13. package/locales/ko_KR/migration.json +45 -0
  14. package/locales/ko_KR/setting.json +2 -2
  15. package/locales/ru_RU/common.json +19 -0
  16. package/locales/ru_RU/migration.json +45 -0
  17. package/locales/ru_RU/setting.json +2 -2
  18. package/locales/zh_CN/common.json +19 -0
  19. package/locales/zh_CN/migration.json +45 -0
  20. package/locales/zh_CN/setting.json +1 -1
  21. package/locales/zh_TW/common.json +19 -0
  22. package/locales/zh_TW/migration.json +45 -0
  23. package/locales/zh_TW/setting.json +2 -2
  24. package/package.json +2 -1
  25. package/src/app/api/openai/chat/createChatCompletion.test.ts +4 -4
  26. package/src/app/api/openai/chat/createChatCompletion.ts +4 -10
  27. package/src/app/api/openai/createBizOpenAI/index.ts +1 -1
  28. package/src/app/api/openai/errorResponse.test.ts +1 -1
  29. package/src/app/chat/(desktop)/features/ChatInput/Footer/index.tsx +2 -1
  30. package/src/app/chat/(mobile)/features/ChatInput/SendButton.tsx +2 -2
  31. package/src/app/chat/features/ChatHeader/ShareButton/Inner.tsx +2 -5
  32. package/src/app/chat/features/ChatHeader/ShareButton/index.tsx +2 -2
  33. package/src/app/chat/features/ChatInput/ActionBar/Clear.tsx +2 -2
  34. package/src/app/chat/features/ChatInput/ActionBar/ModelSwitch.tsx +1 -1
  35. package/src/app/chat/features/ChatInput/ActionBar/Token/TokenTag.tsx +8 -2
  36. package/src/app/chat/features/ChatInput/InputAreaInner/index.tsx +2 -2
  37. package/src/app/chat/features/ChatInput/STT/index.tsx +2 -2
  38. package/src/app/chat/features/ChatInput/Topic/index.tsx +2 -2
  39. package/src/app/chat/features/ChatInput/useSend.ts +3 -3
  40. package/src/app/chat/features/Conversation/ChatList/Actions/index.ts +2 -2
  41. package/src/app/chat/features/Conversation/ChatList/Error/ApiKeyForm.tsx +2 -2
  42. package/src/app/chat/features/Conversation/ChatList/Error/InvalidAccess.tsx +2 -2
  43. package/src/app/chat/features/Conversation/ChatList/Error/Plugin/PluginSettings.tsx +2 -2
  44. package/src/app/chat/features/Conversation/ChatList/Extras/Assistant.test.tsx +4 -4
  45. package/src/app/chat/features/Conversation/ChatList/Extras/Assistant.tsx +30 -31
  46. package/src/app/chat/features/Conversation/ChatList/Extras/TTS.tsx +2 -2
  47. package/src/app/chat/features/Conversation/ChatList/Extras/Translate.tsx +2 -2
  48. package/src/app/chat/features/Conversation/ChatList/Extras/User.tsx +8 -5
  49. package/src/app/chat/features/Conversation/ChatList/Extras/index.ts +3 -3
  50. package/src/app/chat/features/Conversation/ChatList/Extras/type.ts +5 -0
  51. package/src/app/chat/features/Conversation/ChatList/Messages/Assistant.tsx +10 -6
  52. package/src/app/chat/features/Conversation/ChatList/Messages/Default.tsx +7 -3
  53. package/src/app/chat/features/Conversation/ChatList/Messages/Function.tsx +7 -6
  54. package/src/app/chat/features/Conversation/ChatList/Messages/index.ts +7 -7
  55. package/src/app/chat/features/Conversation/ChatList/Plugins/Render/StandaloneType/Iframe.tsx +6 -6
  56. package/src/app/chat/features/Conversation/ChatList/index.tsx +16 -24
  57. package/src/app/chat/features/Conversation/ScrollAnchor/index.tsx +2 -2
  58. package/src/app/chat/features/Conversation/index.tsx +3 -3
  59. package/src/app/chat/features/Conversation/useInitConversation.ts +43 -0
  60. package/src/app/chat/features/Migration/ExportConfigButton.tsx +33 -0
  61. package/src/app/chat/features/Migration/Failed.tsx +115 -0
  62. package/src/app/chat/features/Migration/Modal.tsx +80 -0
  63. package/src/app/chat/features/Migration/Start.tsx +106 -0
  64. package/src/app/chat/features/Migration/UpgradeButton.tsx +74 -0
  65. package/src/app/chat/features/Migration/const.ts +15 -0
  66. package/src/app/chat/features/Migration/index.tsx +44 -0
  67. package/src/app/chat/features/SessionListContent/DefaultMode.tsx +54 -0
  68. package/src/app/chat/features/SessionListContent/List/Item/Actions.tsx +5 -4
  69. package/src/app/chat/features/SessionListContent/List/Item/index.tsx +22 -28
  70. package/src/app/chat/features/SessionListContent/SearchMode.tsx +15 -0
  71. package/src/app/chat/features/SessionListContent/index.tsx +4 -44
  72. package/src/app/chat/features/SessionSearchBar/index.tsx +11 -3
  73. package/src/app/chat/features/TopicListContent/Header.tsx +4 -4
  74. package/src/app/chat/features/TopicListContent/Topic/TopicContent.tsx +11 -9
  75. package/src/app/chat/features/TopicListContent/Topic/TopicItem.tsx +15 -13
  76. package/src/app/chat/features/TopicListContent/Topic/index.tsx +9 -16
  77. package/src/app/chat/features/TopicListContent/TopicSearchBar/index.tsx +13 -4
  78. package/src/app/chat/features/TopicListContent/index.tsx +1 -2
  79. package/src/app/chat/page.tsx +6 -1
  80. package/src/app/chat/settings/features/HeaderContent.tsx +3 -3
  81. package/src/app/home/Redirect.tsx +13 -7
  82. package/src/app/settings/(mobile)/features/ExtraList.tsx +12 -4
  83. package/src/app/settings/common/Common.tsx +16 -4
  84. package/src/app/welcome/features/Banner/index.tsx +9 -10
  85. package/src/chains/summaryTitle.ts +5 -2
  86. package/src/components/DataStyleModal/index.tsx +64 -0
  87. package/src/config/client.ts +5 -0
  88. package/src/const/session.ts +21 -0
  89. package/src/const/settings.ts +1 -1
  90. package/src/database/core/__tests__/db.test.ts +8 -5
  91. package/src/database/core/__tests__/model.test.ts +3 -3
  92. package/src/database/core/db.ts +38 -10
  93. package/src/database/core/index.ts +1 -0
  94. package/src/database/core/model.ts +121 -10
  95. package/src/database/core/schemas.ts +22 -0
  96. package/src/database/core/types/db.ts +13 -0
  97. package/src/database/models/__DEBUG.ts +119 -0
  98. package/src/database/models/{file.test.ts → __tests__/file.test.ts} +19 -6
  99. package/src/database/models/__tests__/message.test.ts +314 -0
  100. package/src/database/models/__tests__/session.test.ts +117 -0
  101. package/src/database/models/__tests__/topic.test.ts +250 -0
  102. package/src/database/models/file.ts +9 -5
  103. package/src/database/models/message.ts +186 -0
  104. package/src/database/models/session.ts +160 -0
  105. package/src/database/models/topic.ts +196 -0
  106. package/src/{types/database → database/schemas}/files.ts +2 -2
  107. package/src/database/schemas/message.ts +37 -0
  108. package/src/database/schemas/session.ts +56 -0
  109. package/src/database/schemas/topic.ts +12 -0
  110. package/src/features/AgentSetting/AgentConfig/index.tsx +8 -1
  111. package/src/features/AgentSetting/AgentTTS/SelectWithTTSPreview.tsx +1 -1
  112. package/src/features/AgentSetting/store/action.ts +1 -1
  113. package/src/features/AgentSetting/store/initialState.ts +1 -1
  114. package/src/features/AgentSetting/store/reducers/config.ts +1 -1
  115. package/src/features/DataImporter/index.tsx +240 -0
  116. package/src/features/DebugUI/index.tsx +34 -0
  117. package/src/features/SideBar/BottomActions.tsx +8 -14
  118. package/src/hooks/useImportConfig.ts +13 -30
  119. package/src/hooks/useTTS.ts +1 -1
  120. package/src/layout/GlobalLayout/index.tsx +16 -1
  121. package/src/locales/default/common.ts +19 -0
  122. package/src/locales/default/migration.ts +47 -0
  123. package/src/locales/default/setting.ts +1 -1
  124. package/src/locales/resources/en_US.ts +2 -0
  125. package/src/locales/resources/ja_JP.ts +2 -0
  126. package/src/locales/resources/ko_KR.ts +2 -0
  127. package/src/locales/resources/ru_RU.ts +2 -0
  128. package/src/locales/resources/zh_CN.ts +2 -0
  129. package/src/locales/resources/zh_TW.ts +2 -0
  130. package/src/migrations/FromV0ToV1.ts +2 -4
  131. package/src/migrations/FromV1ToV2/fixtures/input-v1-session.json +191 -0
  132. package/src/migrations/FromV1ToV2/fixtures/output-v2.json +202 -0
  133. package/src/migrations/FromV1ToV2/index.ts +82 -0
  134. package/src/migrations/FromV1ToV2/migrations.test.ts +224 -0
  135. package/src/migrations/FromV1ToV2/types/v1.ts +78 -0
  136. package/src/migrations/FromV1ToV2/types/v2.ts +52 -0
  137. package/src/{utils → migrations}/VersionController.test.ts +1 -3
  138. package/src/{utils → migrations}/VersionController.ts +5 -2
  139. package/src/migrations/index.ts +17 -3
  140. package/src/services/__tests__/file.test.ts +3 -3
  141. package/src/services/chat.ts +66 -5
  142. package/src/services/config.ts +184 -0
  143. package/src/services/debug.ts +13 -0
  144. package/src/services/file.ts +6 -2
  145. package/src/services/github.ts +25 -0
  146. package/src/services/message.ts +79 -0
  147. package/src/services/session.ts +63 -0
  148. package/src/services/topic.ts +56 -0
  149. package/src/store/chat/actions/enhance.ts +95 -0
  150. package/src/store/{session/slices/chat → chat}/actions/message.ts +225 -247
  151. package/src/store/{session/slices/chat → chat}/actions/plugin.ts +29 -34
  152. package/src/store/{session/slices/chat → chat}/actions/share.ts +9 -13
  153. package/src/store/chat/actions/topic.ts +197 -0
  154. package/src/store/chat/helpers.ts +23 -0
  155. package/src/store/chat/index.ts +3 -0
  156. package/src/store/chat/initialState.ts +48 -0
  157. package/src/store/chat/reducers/message.test.ts +83 -0
  158. package/src/store/chat/reducers/message.ts +83 -0
  159. package/src/store/chat/selectors/__tests__/topic.test.ts +43 -0
  160. package/src/store/chat/selectors/chat.ts +119 -0
  161. package/src/store/chat/selectors/index.ts +2 -0
  162. package/src/store/chat/selectors/topic.ts +28 -0
  163. package/src/store/chat/store.ts +63 -0
  164. package/src/store/files/slices/images/action.ts +6 -4
  165. package/src/store/global/selectors/__snapshots__/settings.test.ts.snap +99 -0
  166. package/src/store/global/selectors/settings.test.ts +51 -0
  167. package/src/store/global/selectors/settings.ts +36 -5
  168. package/src/store/global/store.ts +1 -1
  169. package/src/store/middleware/createHyperStorage/index.ts +40 -24
  170. package/src/store/middleware/createHyperStorage/keyMapper.ts +8 -2
  171. package/src/store/middleware/createHyperStorage/type.ts +10 -8
  172. package/src/store/plugin/slices/plugin/action.ts +1 -1
  173. package/src/store/plugin/store.ts +2 -4
  174. package/src/store/session/helpers.ts +1 -1
  175. package/src/store/session/hooks/useSessionHydrated.ts +6 -10
  176. package/src/store/session/initialState.ts +26 -7
  177. package/src/store/session/selectors.ts +1 -2
  178. package/src/store/session/slices/agent/action.ts +26 -35
  179. package/src/store/session/slices/agent/selectors.ts +32 -37
  180. package/src/store/session/slices/session/action.ts +81 -88
  181. package/src/store/session/slices/session/helpers.ts +19 -0
  182. package/src/store/session/slices/session/initialState.ts +7 -10
  183. package/src/store/session/slices/session/selectors/export.ts +12 -9
  184. package/src/store/session/slices/session/selectors/index.ts +2 -35
  185. package/src/store/session/slices/session/selectors/list.test.ts +25 -203
  186. package/src/store/session/slices/session/selectors/list.ts +40 -78
  187. package/src/store/session/store.ts +11 -17
  188. package/src/types/agent/index.ts +61 -0
  189. package/src/types/chatMessage.ts +11 -20
  190. package/src/types/exportConfig.ts +7 -2
  191. package/src/types/files.ts +2 -2
  192. package/src/types/llm.ts +1 -1
  193. package/src/types/meta.ts +24 -12
  194. package/src/types/openai/chat.ts +9 -1
  195. package/src/types/openai/functionCall.ts +4 -0
  196. package/src/types/session.ts +10 -94
  197. package/src/types/settings.ts +2 -0
  198. package/src/types/translate.ts +2 -1
  199. package/src/utils/config.ts +5 -11
  200. package/src/utils/fetch.ts +8 -2
  201. package/src/app/chat/features/Conversation/usePluginsInit.ts +0 -14
  202. package/src/database/core/schema.ts +0 -9
  203. package/src/helpers/export.ts +0 -69
  204. package/src/hooks/useExportConfig.ts +0 -6
  205. package/src/store/session/slices/chat/actions/index.ts +0 -32
  206. package/src/store/session/slices/chat/actions/topic.ts +0 -171
  207. package/src/store/session/slices/chat/actions/translate.ts +0 -113
  208. package/src/store/session/slices/chat/helpers.ts +0 -9
  209. package/src/store/session/slices/chat/initialState.ts +0 -13
  210. package/src/store/session/slices/chat/reducers/message.test.ts +0 -319
  211. package/src/store/session/slices/chat/reducers/message.ts +0 -156
  212. package/src/store/session/slices/chat/reducers/topic.test.ts +0 -179
  213. package/src/store/session/slices/chat/reducers/topic.ts +0 -81
  214. package/src/store/session/slices/chat/selectors/chat.ts +0 -111
  215. package/src/store/session/slices/chat/selectors/index.ts +0 -26
  216. package/src/store/session/slices/chat/selectors/topic.ts +0 -30
  217. package/src/store/session/slices/chat/selectors/utils.test.ts +0 -385
  218. package/src/store/session/slices/chat/selectors/utils.ts +0 -91
  219. package/src/store/session/slices/chat/utils.ts +0 -13
  220. package/src/store/session/slices/session/reducers/session.test.ts +0 -577
  221. package/src/store/session/slices/session/reducers/session.ts +0 -182
  222. package/src/types/database/db.ts +0 -4
  223. /package/src/store/{session/slices/chat → chat}/reducers/files.test.ts +0 -0
  224. /package/src/store/{session/slices/chat → chat}/reducers/files.ts +0 -0
@@ -30,6 +30,25 @@
30
30
  "feedback": "回饋與建議",
31
31
  "historyRange": "歷史範圍",
32
32
  "import": "匯入設定",
33
+ "importModal": {
34
+ "finish": {
35
+ "onlySettings": "系統設置匯入成功",
36
+ "start": "開始使用",
37
+ "subTitle": "數據匯入成功,耗時 {{duration}} 秒。匯入明細如下:",
38
+ "title": "數據匯入完成"
39
+ },
40
+ "loading": "數據匯入中,請耐心等待...",
41
+ "result": {
42
+ "added": "匯入成功",
43
+ "errors": "匯入出錯",
44
+ "messages": "消息",
45
+ "sessions": "助手",
46
+ "skips": "重複跳過",
47
+ "topics": "話題",
48
+ "type": "數據類型"
49
+ },
50
+ "title": "匯入數據"
51
+ },
33
52
  "lang": {
34
53
  "en": "英語",
35
54
  "en-US": "英語",
@@ -0,0 +1,45 @@
1
+ {
2
+ "dbV1": {
3
+ "action": {
4
+ "clearDB": "清空本地資料",
5
+ "downloadBackup": "下載資料備份",
6
+ "reUpgrade": "重新升級",
7
+ "start": "開始使用",
8
+ "upgrade": "一鍵升級"
9
+ },
10
+ "clear": {
11
+ "confirm": "即將清空本地資料(全域設定不受影響),請確認你已經下載了資料備份。"
12
+ },
13
+ "description": "在新版本中,LobeChat 的資料存儲有了巨大的飛躍。因此我們要對舊版資料進行升級,進而為你帶來更好的使用體驗。",
14
+ "features": {
15
+ "capability": {
16
+ "desc": "基於 IndexedDB 技術,足以裝下你一生的對話消息",
17
+ "title": "大容量"
18
+ },
19
+ "performance": {
20
+ "title": "高性能",
21
+ "desc": "百萬條消息自動索引,檢索查詢毫秒級響應"
22
+ },
23
+ "use": {
24
+ "desc": "支持標題、描述、標籤、消息內容乃至翻譯文本檢索,日常搜索效率大大提升",
25
+ "title": "更易用"
26
+ }
27
+ },
28
+ "title": "LobeChat 資料進化",
29
+ "upgrade": {
30
+ "error": {
31
+ "title": "資料庫升級失敗",
32
+ "subTitle": "非常抱歉,資料庫升級過程發生異常。請嘗試以下方案:A. 清空本地數據後,重新導入備份數據; B.點擊「重新升級」按鈕。<br><br> 如仍然出錯,請 <1>提交問題</1> ,我們將會第一時間幫你排查"
33
+ },
34
+ "success": {
35
+ "subTitle": "LobeChat 的資料庫已經升級到最新版本,立即開始體驗吧",
36
+ "title": "資料庫升級成功"
37
+ }
38
+ },
39
+ "upgradeTip": "升級大致需要 1~2 秒,升級過程中請不要關閉 LobeChat"
40
+ },
41
+ "migrateError": {
42
+ "missVersion": "導入數據缺少版本號,請檢查文件後重試",
43
+ "noMigration": "沒有找到當前版本對應的遷移方案,請檢查版本號後重試。如仍有問題請提交問題反饋"
44
+ }
45
+ }
@@ -3,9 +3,9 @@
3
3
  "clear": {
4
4
  "action": "立即清除",
5
5
  "confirm": "確定要清除所有聊天資料嗎?",
6
- "desc": "清除所有對話資料",
7
6
  "success": "已清除所有對話訊息",
8
- "title": "清除所有對話訊息"
7
+ "title": "清除所有對話訊息",
8
+ "desc": "將會清除所有會話資料,包括助手、檔案、訊息、插件等"
9
9
  },
10
10
  "reset": {
11
11
  "action": "立即重設",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.105.2",
3
+ "version": "0.107.0",
4
4
  "description": "An open-source, extensible (Function Calling), high-performance chatbot framework. It supports one-click free deployment of your private ChatGPT/LLM web application",
5
5
  "keywords": [
6
6
  "chatbot",
@@ -107,6 +107,7 @@
107
107
  "react-layout-kit": "^1",
108
108
  "react-lazy-load": "^4",
109
109
  "react-spring-lightbox": "^1",
110
+ "react-wrap-balancer": "^1.1.0",
110
111
  "remark": "^14",
111
112
  "remark-gfm": "^3",
112
113
  "remark-html": "^15",
@@ -33,7 +33,7 @@ describe('createChatCompletion', () => {
33
33
  const result = await createChatCompletion({
34
34
  openai: openaiInstance,
35
35
  payload: {
36
- messages: [{ content: 'Hello', name: 'User', role: 'user' }],
36
+ messages: [{ content: 'Hello', role: 'user' }],
37
37
  model: 'text-davinci-003',
38
38
  temperature: 0,
39
39
  },
@@ -63,7 +63,7 @@ describe('createChatCompletion', () => {
63
63
  const result = await createChatCompletion({
64
64
  openai: openaiInstance,
65
65
  payload: {
66
- messages: [{ content: 'Hello', name: 'User', role: 'user' }],
66
+ messages: [{ content: 'Hello', role: 'user' }],
67
67
  model: 'text-davinci-003',
68
68
  temperature: 0,
69
69
  },
@@ -89,7 +89,7 @@ describe('createChatCompletion', () => {
89
89
  const result = await createChatCompletion({
90
90
  openai: openaiInstance,
91
91
  payload: {
92
- messages: [{ content: 'Hello', name: 'User', role: 'user' }],
92
+ messages: [{ content: 'Hello', role: 'user' }],
93
93
  model: 'text-davinci-003',
94
94
  temperature: 0,
95
95
  },
@@ -114,7 +114,7 @@ describe('createChatCompletion', () => {
114
114
  const result = await createChatCompletion({
115
115
  openai: openaiInstance,
116
116
  payload: {
117
- messages: [{ content: 'Hello', name: 'User', role: 'user' }],
117
+ messages: [{ content: 'Hello', role: 'user' }],
118
118
  model: 'text-davinci-003',
119
119
  temperature: 0,
120
120
  },
@@ -1,10 +1,11 @@
1
1
  import { OpenAIStream, StreamingTextResponse } from 'ai';
2
2
  import OpenAI from 'openai';
3
3
 
4
- import { createErrorResponse } from '@/app/api/openai/errorResponse';
5
4
  import { ChatErrorType } from '@/types/fetch';
6
5
  import { OpenAIChatStreamPayload } from '@/types/openai/chat';
7
6
 
7
+ import { createErrorResponse } from '../errorResponse';
8
+
8
9
  interface CreateChatCompletionOptions {
9
10
  openai: OpenAI;
10
11
  payload: OpenAIChatStreamPayload;
@@ -14,22 +15,15 @@ export const createChatCompletion = async ({ payload, openai }: CreateChatComple
14
15
  // ============ 1. preprocess messages ============ //
15
16
  const { messages, ...params } = payload;
16
17
 
17
- // remove unnecessary fields like `plugins` or `files` by lobe-chat
18
- const formatMessages = messages.map((m) => ({
19
- content: m.content,
20
- name: m.name,
21
- role: m.role,
22
- })) as OpenAI.ChatCompletionMessageParam[];
23
-
24
18
  // ============ 2. send api ============ //
25
19
 
26
20
  try {
27
21
  const response = await openai.chat.completions.create(
28
22
  {
29
- messages: formatMessages,
23
+ messages,
30
24
  ...params,
31
25
  stream: true,
32
- },
26
+ } as unknown as OpenAI.ChatCompletionCreateParamsStreaming,
33
27
  { headers: { Accept: '*/*' } },
34
28
  );
35
29
  const stream = OpenAIStream(response);
@@ -1,4 +1,4 @@
1
- import OpenAI from 'openai/index';
1
+ import OpenAI from 'openai';
2
2
 
3
3
  import { checkAuth } from '@/app/api/auth';
4
4
  import { getServerConfig } from '@/config/server';
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
 
3
- import { ChatErrorType, ErrorResponse, ErrorType } from '@/types/fetch';
3
+ import { ChatErrorType } from '@/types/fetch';
4
4
 
5
5
  import { createErrorResponse } from './errorResponse';
6
6
 
@@ -8,6 +8,7 @@ import { Flexbox } from 'react-layout-kit';
8
8
 
9
9
  import SaveTopic from '@/app/chat/features/ChatInput/Topic';
10
10
  import { useSendMessage } from '@/app/chat/features/ChatInput/useSend';
11
+ import { useChatStore } from '@/store/chat';
11
12
  import { useSessionStore } from '@/store/session';
12
13
  import { agentSelectors } from '@/store/session/selectors';
13
14
 
@@ -16,7 +17,7 @@ import { LocalFiles } from './LocalFiles';
16
17
  const Footer = memo(() => {
17
18
  const { t } = useTranslation('chat');
18
19
  const theme = useTheme();
19
- const [loading, onStop] = useSessionStore((s) => [!!s.chatLoadingId, s.stopGenerateMessage]);
20
+ const [loading, onStop] = useChatStore((s) => [!!s.chatLoadingId, s.stopGenerateMessage]);
20
21
 
21
22
  const onSend = useSendMessage();
22
23
  const canUpload = useSessionStore(agentSelectors.modelHasVisionAbility);
@@ -4,10 +4,10 @@ import { Loader2, SendHorizonal } from 'lucide-react';
4
4
  import { memo } from 'react';
5
5
 
6
6
  import { useSendMessage } from '@/app/chat/features/ChatInput/useSend';
7
- import { useSessionStore } from '@/store/session';
7
+ import { useChatStore } from '@/store/chat';
8
8
 
9
9
  const SendButton = memo(() => {
10
- const [loading, onStop] = useSessionStore((s) => [!!s.chatLoadingId, s.stopGenerateMessage]);
10
+ const [loading, onStop] = useChatStore((s) => [!!s.chatLoadingId, s.stopGenerateMessage]);
11
11
 
12
12
  const handleSend = useSendMessage();
13
13
 
@@ -7,8 +7,8 @@ import { Flexbox } from 'react-layout-kit';
7
7
 
8
8
  import MobilePadding from '@/components/MobilePadding';
9
9
  import { FORM_STYLE } from '@/const/layoutTokens';
10
+ import { useChatStore } from '@/store/chat';
10
11
  import { useGlobalStore } from '@/store/global';
11
- import { useSessionStore } from '@/store/session';
12
12
 
13
13
  import Preview, { ImageType, imageTypeOptions } from './Preview';
14
14
 
@@ -27,10 +27,7 @@ const Inner = memo(() => {
27
27
  const { t } = useTranslation('chat');
28
28
 
29
29
  const avatar = useGlobalStore((s) => s.settings.avatar);
30
- const [shareLoading, shareToShareGPT] = useSessionStore((s) => [
31
- s.shareLoading,
32
- s.shareToShareGPT,
33
- ]);
30
+ const [shareLoading, shareToShareGPT] = useChatStore((s) => [s.shareLoading, s.shareToShareGPT]);
34
31
 
35
32
  const options: SegmentedProps['options'] = useMemo(
36
33
  () => [
@@ -6,7 +6,7 @@ import { useTranslation } from 'react-i18next';
6
6
  import useMergeState from 'use-merge-value';
7
7
 
8
8
  import { DESKTOP_HEADER_ICON_SIZE } from '@/const/layoutTokens';
9
- import { useSessionStore } from '@/store/session';
9
+ import { useChatStore } from '@/store/chat';
10
10
 
11
11
  const Inner = dynamic(() => import('./Inner'));
12
12
  interface ShareButtonProps {
@@ -22,7 +22,7 @@ const ShareButton = memo<ShareButtonProps>(({ mobile, setOpen, open }) => {
22
22
  value: open,
23
23
  });
24
24
  const { t } = useTranslation('common');
25
- const [shareLoading] = useSessionStore((s) => [s.shareLoading]);
25
+ const [shareLoading] = useChatStore((s) => [s.shareLoading]);
26
26
 
27
27
  return (
28
28
  <>
@@ -7,12 +7,12 @@ import { useTranslation } from 'react-i18next';
7
7
 
8
8
  import HotKeys from '@/components/HotKeys';
9
9
  import { CLEAN_MESSAGE_KEY, PREFIX_KEY } from '@/const/hotkeys';
10
+ import { useChatStore } from '@/store/chat';
10
11
  import { useFileStore } from '@/store/files';
11
- import { useSessionStore } from '@/store/session';
12
12
 
13
13
  const Clear = memo(() => {
14
14
  const { t } = useTranslation('setting');
15
- const [clearMessage] = useSessionStore((s) => [s.clearMessage]);
15
+ const [clearMessage] = useChatStore((s) => [s.clearMessage]);
16
16
  const [clearImageList] = useFileStore((s) => [s.clearImageList]);
17
17
  const hotkeys = [PREFIX_KEY, CLEAN_MESSAGE_KEY].join('+');
18
18
 
@@ -22,7 +22,7 @@ const ModelSwitch = memo(() => {
22
22
  <Dropdown
23
23
  menu={{
24
24
  activeKey: model,
25
- items: modelList.map((i) => ({ key: i, label: i })),
25
+ items: modelList.map(({ name, displayName }) => ({ key: name, label: displayName })),
26
26
  onClick: (e) => {
27
27
  updateAgentConfig({ model: e.key as LanguageModel });
28
28
  },
@@ -4,19 +4,25 @@ import { useTranslation } from 'react-i18next';
4
4
 
5
5
  import { ModelTokens } from '@/const/modelTokens';
6
6
  import { useTokenCount } from '@/hooks/useTokenCount';
7
+ import { useChatStore } from '@/store/chat';
8
+ import { chatSelectors } from '@/store/chat/selectors';
7
9
  import { useSessionStore } from '@/store/session';
8
- import { agentSelectors, chatSelectors } from '@/store/session/selectors';
10
+ import { agentSelectors } from '@/store/session/selectors';
9
11
  import { LanguageModel } from '@/types/llm';
10
12
 
11
13
  const Token = memo(() => {
12
14
  const { t } = useTranslation('chat');
13
15
 
14
- const [input, messageString, systemRole, model] = useSessionStore((s) => [
16
+ const [input, messageString] = useChatStore((s) => [
15
17
  s.inputMessage,
16
18
  chatSelectors.chatsMessageString(s),
19
+ ]);
20
+
21
+ const [systemRole, model] = useSessionStore((s) => [
17
22
  agentSelectors.currentAgentSystemRole(s),
18
23
  agentSelectors.currentAgentModel(s) as LanguageModel,
19
24
  ]);
25
+
20
26
  const inputTokenCount = useTokenCount(input);
21
27
 
22
28
  const systemRoleToken = useTokenCount(systemRole);
@@ -2,7 +2,7 @@ import { Input, TextArea } from '@lobehub/ui';
2
2
  import { memo, useRef } from 'react';
3
3
  import { useTranslation } from 'react-i18next';
4
4
 
5
- import { useSessionStore } from '@/store/session';
5
+ import { useChatStore } from '@/store/chat';
6
6
 
7
7
  import { useSendMessage } from '../useSend';
8
8
 
@@ -15,7 +15,7 @@ const InputAreaInner = memo<InputAreaInnerProps>(({ className, mobile }) => {
15
15
  const { t } = useTranslation('chat');
16
16
  const isChineseInput = useRef(false);
17
17
 
18
- const [loading, message, updateInputMessage] = useSessionStore((s) => [
18
+ const [loading, message, updateInputMessage] = useChatStore((s) => [
19
19
  !!s.chatLoadingId,
20
20
  s.inputMessage,
21
21
  s.updateInputMessage,
@@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next';
7
7
  import { Flexbox } from 'react-layout-kit';
8
8
 
9
9
  import { useSTT } from '@/hooks/useSTT';
10
- import { useSessionStore } from '@/store/session';
10
+ import { useChatStore } from '@/store/chat';
11
11
  import { ChatMessageError } from '@/types/chatMessage';
12
12
  import { getMessageError } from '@/utils/fetch';
13
13
 
@@ -25,7 +25,7 @@ const STT = memo<{ mobile?: boolean }>(({ mobile }) => {
25
25
  const { t } = useTranslation('chat');
26
26
  const { styles } = useStyles();
27
27
 
28
- const [loading, updateInputMessage] = useSessionStore((s) => [
28
+ const [loading, updateInputMessage] = useChatStore((s) => [
29
29
  !!s.chatLoadingId,
30
30
  s.updateInputMessage,
31
31
  ]);
@@ -7,11 +7,11 @@ import { useTranslation } from 'react-i18next';
7
7
 
8
8
  import HotKeys from '@/components/HotKeys';
9
9
  import { PREFIX_KEY, SAVE_TOPIC_KEY } from '@/const/hotkeys';
10
- import { useSessionStore } from '@/store/session';
10
+ import { useChatStore } from '@/store/chat';
11
11
 
12
12
  const SaveTopic = memo<{ mobile?: boolean }>(({ mobile }) => {
13
13
  const { t } = useTranslation('chat');
14
- const [hasTopic, openNewTopicOrSaveTopic] = useSessionStore((s) => [
14
+ const [hasTopic, openNewTopicOrSaveTopic] = useChatStore((s) => [
15
15
  !!s.activeTopicId,
16
16
  s.openNewTopicOrSaveTopic,
17
17
  ]);
@@ -1,16 +1,16 @@
1
1
  import { useCallback } from 'react';
2
2
 
3
3
  import { filesSelectors, useFileStore } from '@/store/files';
4
- import { useSessionStore } from '@/store/session';
4
+ import { useChatStore } from 'src/store/chat';
5
5
 
6
6
  export const useSendMessage = () => {
7
- const [sendMessage, updateInputMessage] = useSessionStore((s) => [
7
+ const [sendMessage, updateInputMessage] = useChatStore((s) => [
8
8
  s.sendMessage,
9
9
  s.updateInputMessage,
10
10
  ]);
11
11
 
12
12
  return useCallback(() => {
13
- const store = useSessionStore.getState();
13
+ const store = useChatStore.getState();
14
14
  if (!!store.chatLoadingId) return;
15
15
  const imageList = filesSelectors.imageUrlOrBase64List(useFileStore.getState());
16
16
 
@@ -1,6 +1,6 @@
1
1
  import { ChatListProps } from '@lobehub/ui';
2
2
 
3
- import { useSessionStore } from '@/store/session';
3
+ import { useChatStore } from '@/store/chat';
4
4
 
5
5
  import { AssistantActionsBar } from './Assistant';
6
6
  import { DefaultActionsBar } from './Fallback';
@@ -20,7 +20,7 @@ interface ActionsClick {
20
20
  }
21
21
 
22
22
  export const useActionsClick = (): ChatListProps['onActionsClick'] => {
23
- const [deleteMessage, resendMessage, translateMessage, ttsMessage] = useSessionStore((s) => [
23
+ const [deleteMessage, resendMessage, translateMessage, ttsMessage] = useChatStore((s) => [
24
24
  s.deleteMessage,
25
25
  s.resendMessage,
26
26
  s.translateMessage,
@@ -5,8 +5,8 @@ import { memo, useState } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
6
  import { Center, Flexbox } from 'react-layout-kit';
7
7
 
8
+ import { useChatStore } from '@/store/chat';
8
9
  import { settingsSelectors, useGlobalStore } from '@/store/global';
9
- import { useSessionStore } from '@/store/session';
10
10
 
11
11
  import { FormAction } from './style';
12
12
 
@@ -20,7 +20,7 @@ const APIKeyForm = memo<{ id: string }>(({ id }) => {
20
20
  s.setOpenAIConfig,
21
21
  ]);
22
22
 
23
- const [resend, deleteMessage] = useSessionStore((s) => [s.resendMessage, s.deleteMessage]);
23
+ const [resend, deleteMessage] = useChatStore((s) => [s.resendMessage, s.deleteMessage]);
24
24
 
25
25
  return (
26
26
  <Center gap={16} style={{ maxWidth: 300 }}>
@@ -5,8 +5,8 @@ import { memo, useState } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
6
  import { Flexbox } from 'react-layout-kit';
7
7
 
8
+ import { useChatStore } from '@/store/chat';
8
9
  import { useGlobalStore } from '@/store/global';
9
- import { useSessionStore } from '@/store/session';
10
10
 
11
11
  import APIKeyForm from './ApiKeyForm';
12
12
  import { ErrorActionContainer, FormAction } from './style';
@@ -20,7 +20,7 @@ const InvalidAccess: RenderErrorMessage['Render'] = memo(({ id }) => {
20
20
  const { t } = useTranslation('error');
21
21
  const [mode, setMode] = useState<Tab>(Tab.Password);
22
22
  const [password, setSettings] = useGlobalStore((s) => [s.settings.password, s.setSettings]);
23
- const [resend, deleteMessage] = useSessionStore((s) => [s.resendMessage, s.deleteMessage]);
23
+ const [resend, deleteMessage] = useChatStore((s) => [s.resendMessage, s.deleteMessage]);
24
24
 
25
25
  return (
26
26
  <ErrorActionContainer>
@@ -7,9 +7,9 @@ import { useTranslation } from 'react-i18next';
7
7
  import { Center, Flexbox } from 'react-layout-kit';
8
8
 
9
9
  import PluginSettingsConfig from '@/features/PluginSettings';
10
+ import { useChatStore } from '@/store/chat';
10
11
  import { pluginHelpers, usePluginStore } from '@/store/plugin';
11
12
  import { pluginSelectors } from '@/store/plugin/selectors';
12
- import { useSessionStore } from '@/store/session';
13
13
 
14
14
  import { ErrorActionContainer, useStyles } from '../style';
15
15
 
@@ -17,7 +17,7 @@ const PluginSettings: RenderErrorMessage['Render'] = memo(({ id, plugin }) => {
17
17
  const { styles } = useStyles();
18
18
  const { t } = useTranslation('error');
19
19
  const theme = useTheme();
20
- const [resend, deleteMessage] = useSessionStore((s) => [s.resendMessage, s.deleteMessage]);
20
+ const [resend, deleteMessage] = useChatStore((s) => [s.resendMessage, s.deleteMessage]);
21
21
  const pluginIdentifier = plugin?.identifier as string;
22
22
  const pluginMeta = usePluginStore(pluginSelectors.getPluginMetaById(pluginIdentifier), isEqual);
23
23
  const manifest = usePluginStore(pluginSelectors.getPluginManifestById(pluginIdentifier), isEqual);
@@ -27,11 +27,11 @@ vi.mock('@/store/session/selectors', () => ({
27
27
 
28
28
  const mockData: ChatMessage = {
29
29
  content: 'test-content',
30
- createAt: 0,
30
+ createdAt: 0,
31
31
  id: 'abc',
32
32
  meta: { avatar: '', backgroundColor: '', description: '', tags: [], title: '' },
33
33
  role: 'assistant',
34
- updateAt: 0,
34
+ updatedAt: 0,
35
35
  };
36
36
 
37
37
  describe('AssistantMessageExtra', () => {
@@ -71,7 +71,7 @@ describe('AssistantMessageExtra', () => {
71
71
  });
72
72
 
73
73
  it('should render Translate component if extra.translate exists', async () => {
74
- render(<AssistantMessageExtra {...mockData} extra={{ translate: {} }} />);
74
+ render(<AssistantMessageExtra {...mockData} extra={{ translate: { to: 'abc' } }} />);
75
75
  expect(screen.getByText('Translate Component')).toBeInTheDocument();
76
76
  });
77
77
 
@@ -79,7 +79,7 @@ describe('AssistantMessageExtra', () => {
79
79
  (useSessionStore as unknown as Mock).mockImplementation(() => ({
80
80
  chatLoadingId: 'test-id',
81
81
  }));
82
- render(<AssistantMessageExtra {...mockData} extra={{ translate: {}, tts: {} }} />);
82
+ render(<AssistantMessageExtra {...mockData} extra={{ translate: { to: 'abc' }, tts: {} }} />);
83
83
  expect(screen.getByText('TTS Component')).toBeInTheDocument();
84
84
  expect(screen.getByText('Translate Component')).toBeInTheDocument();
85
85
  });
@@ -1,8 +1,9 @@
1
1
  import { SiOpenai } from '@icons-pack/react-simple-icons';
2
- import { RenderMessageExtra, Tag } from '@lobehub/ui';
2
+ import { Tag } from '@lobehub/ui';
3
3
  import { memo } from 'react';
4
4
  import { Flexbox } from 'react-layout-kit';
5
5
 
6
+ import { useChatStore } from '@/store/chat';
6
7
  import { useSessionStore } from '@/store/session';
7
8
  import { agentSelectors } from '@/store/session/selectors';
8
9
  import { ChatMessage } from '@/types/chatMessage';
@@ -11,39 +12,37 @@ import ExtraContainer from './ExtraContainer';
11
12
  import TTS from './TTS';
12
13
  import Translate from './Translate';
13
14
 
14
- export const AssistantMessageExtra: RenderMessageExtra = memo<ChatMessage>(
15
- ({ extra, id, content }) => {
16
- const model = useSessionStore(agentSelectors.currentAgentModel);
17
- const loading = useSessionStore((s) => s.chatLoadingId === id);
15
+ export const AssistantMessageExtra = memo<ChatMessage>(({ extra, id, content }) => {
16
+ const model = useSessionStore(agentSelectors.currentAgentModel);
17
+ const loading = useChatStore((s) => s.chatLoadingId === id);
18
18
 
19
- const showModelTag = extra?.fromModel && model !== extra?.fromModel;
20
- const showTranslate = !!extra?.translate;
21
- const showTTS = !!extra?.tts;
19
+ const showModelTag = extra?.fromModel && model !== extra?.fromModel;
20
+ const showTranslate = !!extra?.translate;
21
+ const showTTS = !!extra?.tts;
22
22
 
23
- const showExtra = showModelTag || showTranslate || showTTS;
23
+ const showExtra = showModelTag || showTranslate || showTTS;
24
24
 
25
- if (!showExtra) return;
25
+ if (!showExtra) return;
26
26
 
27
- return (
28
- <Flexbox gap={8} style={{ marginTop: 8 }}>
29
- {showModelTag && (
30
- <div>
31
- <Tag icon={<SiOpenai size={'1em'} />}>{extra?.fromModel as string}</Tag>
32
- </div>
33
- )}
27
+ return (
28
+ <Flexbox gap={8} style={{ marginTop: 8 }}>
29
+ {showModelTag && (
34
30
  <div>
35
- {extra?.tts && (
36
- <ExtraContainer>
37
- <TTS content={content} id={id} loading={loading} {...extra?.tts} />
38
- </ExtraContainer>
39
- )}
40
- {extra?.translate && (
41
- <ExtraContainer>
42
- <Translate id={id} loading={loading} {...extra?.translate} />
43
- </ExtraContainer>
44
- )}
31
+ <Tag icon={<SiOpenai size={'1em'} />}>{extra?.fromModel as string}</Tag>
45
32
  </div>
46
- </Flexbox>
47
- );
48
- },
49
- );
33
+ )}
34
+ <div>
35
+ {extra?.tts && (
36
+ <ExtraContainer>
37
+ <TTS content={content} id={id} loading={loading} {...extra?.tts} />
38
+ </ExtraContainer>
39
+ )}
40
+ {extra?.translate && (
41
+ <ExtraContainer>
42
+ <Translate id={id} loading={loading} {...extra?.translate} />
43
+ </ExtraContainer>
44
+ )}
45
+ </div>
46
+ </Flexbox>
47
+ );
48
+ });
@@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next';
7
7
  import { Flexbox } from 'react-layout-kit';
8
8
 
9
9
  import { useTTS } from '@/hooks/useTTS';
10
- import { useSessionStore } from '@/store/session';
10
+ import { useChatStore } from '@/store/chat';
11
11
  import { ChatMessageError, ChatTTS } from '@/types/chatMessage';
12
12
  import { getMessageError } from '@/utils/fetch';
13
13
 
@@ -22,7 +22,7 @@ const TTS = memo<TTSProps>(({ id, init, content }) => {
22
22
  const [error, setError] = useState<ChatMessageError>();
23
23
  const { t } = useTranslation('chat');
24
24
 
25
- const [ttsMessage, clearTTS] = useSessionStore((s) => [s.ttsMessage, s.clearTTS]);
25
+ const [ttsMessage, clearTTS] = useChatStore((s) => [s.ttsMessage, s.clearTTS]);
26
26
 
27
27
  const setDefaultError = useCallback(
28
28
  (err?: any) => {
@@ -7,7 +7,7 @@ import { memo, useState } from 'react';
7
7
  import { useTranslation } from 'react-i18next';
8
8
  import { Flexbox } from 'react-layout-kit';
9
9
 
10
- import { useSessionStore } from '@/store/session';
10
+ import { useChatStore } from '@/store/chat';
11
11
  import { ChatTranslate } from '@/types/chatMessage';
12
12
 
13
13
  import BubblesLoading from '../Loading';
@@ -25,7 +25,7 @@ const Translate = memo<TranslateProps>(({ content = '', from, to, id, loading })
25
25
  const { theme, styles } = useStyles();
26
26
  const { t } = useTranslation('common');
27
27
  const [show, setShow] = useState(true);
28
- const clearTranslate = useSessionStore((s) => s.clearTranslate);
28
+ const clearTranslate = useChatStore((s) => s.clearTranslate);
29
29
 
30
30
  const { message } = App.useApp();
31
31
  return (
@@ -1,17 +1,20 @@
1
- import { RenderMessageExtra } from '@lobehub/ui';
2
1
  import { memo } from 'react';
3
2
 
4
- import { useSessionStore } from '@/store/session';
3
+ import { useChatStore } from '@/store/chat';
5
4
  import { ChatMessage } from '@/types/chatMessage';
6
5
 
7
6
  import ExtraContainer from './ExtraContainer';
8
7
  import TTS from './TTS';
9
8
  import Translate from './Translate';
10
9
 
11
- export const UserMessageExtra: RenderMessageExtra = memo<ChatMessage>(({ extra, id, content }) => {
12
- const loading = useSessionStore((s) => s.chatLoadingId === id);
10
+ export const UserMessageExtra = memo<ChatMessage>(({ extra, id, content }) => {
11
+ const loading = useChatStore((s) => s.chatLoadingId === id);
12
+
13
+ const showTranslate = !!extra?.translate;
14
+ const showTTS = !!extra?.tts;
15
+
16
+ const showExtra = showTranslate || showTTS;
13
17
 
14
- const showExtra = extra?.translate || extra?.tts;
15
18
  if (!showExtra) return;
16
19
 
17
20
  return (