@lobehub/chat 0.106.0 → 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 (214) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/locales/en_US/common.json +19 -0
  3. package/locales/en_US/migration.json +45 -0
  4. package/locales/en_US/setting.json +7 -7
  5. package/locales/ja_JP/common.json +19 -0
  6. package/locales/ja_JP/migration.json +45 -0
  7. package/locales/ja_JP/setting.json +2 -2
  8. package/locales/ko_KR/common.json +19 -0
  9. package/locales/ko_KR/migration.json +45 -0
  10. package/locales/ko_KR/setting.json +2 -2
  11. package/locales/ru_RU/common.json +19 -0
  12. package/locales/ru_RU/migration.json +45 -0
  13. package/locales/ru_RU/setting.json +2 -2
  14. package/locales/zh_CN/common.json +19 -0
  15. package/locales/zh_CN/migration.json +45 -0
  16. package/locales/zh_CN/setting.json +1 -1
  17. package/locales/zh_TW/common.json +19 -0
  18. package/locales/zh_TW/migration.json +45 -0
  19. package/locales/zh_TW/setting.json +2 -2
  20. package/package.json +2 -1
  21. package/src/app/api/openai/chat/createChatCompletion.test.ts +4 -4
  22. package/src/app/api/openai/chat/createChatCompletion.ts +4 -10
  23. package/src/app/api/openai/createBizOpenAI/index.ts +1 -1
  24. package/src/app/api/openai/errorResponse.test.ts +1 -1
  25. package/src/app/chat/(desktop)/features/ChatInput/Footer/index.tsx +2 -1
  26. package/src/app/chat/(mobile)/features/ChatInput/SendButton.tsx +2 -2
  27. package/src/app/chat/features/ChatHeader/ShareButton/Inner.tsx +2 -5
  28. package/src/app/chat/features/ChatHeader/ShareButton/index.tsx +2 -2
  29. package/src/app/chat/features/ChatInput/ActionBar/Clear.tsx +2 -2
  30. package/src/app/chat/features/ChatInput/ActionBar/Token/TokenTag.tsx +8 -2
  31. package/src/app/chat/features/ChatInput/InputAreaInner/index.tsx +2 -2
  32. package/src/app/chat/features/ChatInput/STT/index.tsx +2 -2
  33. package/src/app/chat/features/ChatInput/Topic/index.tsx +2 -2
  34. package/src/app/chat/features/ChatInput/useSend.ts +3 -3
  35. package/src/app/chat/features/Conversation/ChatList/Actions/index.ts +2 -2
  36. package/src/app/chat/features/Conversation/ChatList/Error/ApiKeyForm.tsx +2 -2
  37. package/src/app/chat/features/Conversation/ChatList/Error/InvalidAccess.tsx +2 -2
  38. package/src/app/chat/features/Conversation/ChatList/Error/Plugin/PluginSettings.tsx +2 -2
  39. package/src/app/chat/features/Conversation/ChatList/Extras/Assistant.test.tsx +4 -4
  40. package/src/app/chat/features/Conversation/ChatList/Extras/Assistant.tsx +30 -31
  41. package/src/app/chat/features/Conversation/ChatList/Extras/TTS.tsx +2 -2
  42. package/src/app/chat/features/Conversation/ChatList/Extras/Translate.tsx +2 -2
  43. package/src/app/chat/features/Conversation/ChatList/Extras/User.tsx +8 -5
  44. package/src/app/chat/features/Conversation/ChatList/Extras/index.ts +3 -3
  45. package/src/app/chat/features/Conversation/ChatList/Extras/type.ts +5 -0
  46. package/src/app/chat/features/Conversation/ChatList/Messages/Assistant.tsx +10 -6
  47. package/src/app/chat/features/Conversation/ChatList/Messages/Default.tsx +7 -3
  48. package/src/app/chat/features/Conversation/ChatList/Messages/Function.tsx +7 -6
  49. package/src/app/chat/features/Conversation/ChatList/Messages/index.ts +7 -7
  50. package/src/app/chat/features/Conversation/ChatList/Plugins/Render/StandaloneType/Iframe.tsx +6 -6
  51. package/src/app/chat/features/Conversation/ChatList/index.tsx +16 -24
  52. package/src/app/chat/features/Conversation/ScrollAnchor/index.tsx +2 -2
  53. package/src/app/chat/features/Conversation/index.tsx +3 -3
  54. package/src/app/chat/features/Conversation/useInitConversation.ts +43 -0
  55. package/src/app/chat/features/Migration/ExportConfigButton.tsx +33 -0
  56. package/src/app/chat/features/Migration/Failed.tsx +115 -0
  57. package/src/app/chat/features/Migration/Modal.tsx +80 -0
  58. package/src/app/chat/features/Migration/Start.tsx +106 -0
  59. package/src/app/chat/features/Migration/UpgradeButton.tsx +74 -0
  60. package/src/app/chat/features/Migration/const.ts +15 -0
  61. package/src/app/chat/features/Migration/index.tsx +44 -0
  62. package/src/app/chat/features/SessionListContent/DefaultMode.tsx +54 -0
  63. package/src/app/chat/features/SessionListContent/List/Item/Actions.tsx +5 -4
  64. package/src/app/chat/features/SessionListContent/List/Item/index.tsx +22 -28
  65. package/src/app/chat/features/SessionListContent/SearchMode.tsx +15 -0
  66. package/src/app/chat/features/SessionListContent/index.tsx +4 -44
  67. package/src/app/chat/features/SessionSearchBar/index.tsx +11 -3
  68. package/src/app/chat/features/TopicListContent/Header.tsx +4 -4
  69. package/src/app/chat/features/TopicListContent/Topic/TopicContent.tsx +11 -9
  70. package/src/app/chat/features/TopicListContent/Topic/TopicItem.tsx +15 -13
  71. package/src/app/chat/features/TopicListContent/Topic/index.tsx +9 -16
  72. package/src/app/chat/features/TopicListContent/TopicSearchBar/index.tsx +13 -4
  73. package/src/app/chat/features/TopicListContent/index.tsx +1 -2
  74. package/src/app/chat/page.tsx +6 -1
  75. package/src/app/chat/settings/features/HeaderContent.tsx +3 -3
  76. package/src/app/home/Redirect.tsx +13 -7
  77. package/src/app/settings/(mobile)/features/ExtraList.tsx +12 -4
  78. package/src/app/settings/common/Common.tsx +16 -4
  79. package/src/app/welcome/features/Banner/index.tsx +9 -10
  80. package/src/chains/summaryTitle.ts +5 -2
  81. package/src/components/DataStyleModal/index.tsx +64 -0
  82. package/src/config/client.ts +5 -0
  83. package/src/const/session.ts +21 -0
  84. package/src/const/settings.ts +1 -1
  85. package/src/database/core/__tests__/db.test.ts +8 -5
  86. package/src/database/core/__tests__/model.test.ts +3 -3
  87. package/src/database/core/db.ts +38 -10
  88. package/src/database/core/index.ts +1 -0
  89. package/src/database/core/model.ts +121 -10
  90. package/src/database/core/schemas.ts +22 -0
  91. package/src/database/core/types/db.ts +13 -0
  92. package/src/database/models/__DEBUG.ts +119 -0
  93. package/src/database/models/{file.test.ts → __tests__/file.test.ts} +19 -6
  94. package/src/database/models/__tests__/message.test.ts +314 -0
  95. package/src/database/models/__tests__/session.test.ts +117 -0
  96. package/src/database/models/__tests__/topic.test.ts +250 -0
  97. package/src/database/models/file.ts +9 -5
  98. package/src/database/models/message.ts +186 -0
  99. package/src/database/models/session.ts +160 -0
  100. package/src/database/models/topic.ts +196 -0
  101. package/src/{types/database → database/schemas}/files.ts +2 -2
  102. package/src/database/schemas/message.ts +37 -0
  103. package/src/database/schemas/session.ts +56 -0
  104. package/src/database/schemas/topic.ts +12 -0
  105. package/src/features/AgentSetting/AgentTTS/SelectWithTTSPreview.tsx +1 -1
  106. package/src/features/AgentSetting/store/action.ts +1 -1
  107. package/src/features/AgentSetting/store/initialState.ts +1 -1
  108. package/src/features/AgentSetting/store/reducers/config.ts +1 -1
  109. package/src/features/DataImporter/index.tsx +240 -0
  110. package/src/features/DebugUI/index.tsx +34 -0
  111. package/src/features/SideBar/BottomActions.tsx +8 -14
  112. package/src/hooks/useImportConfig.ts +13 -30
  113. package/src/hooks/useTTS.ts +1 -1
  114. package/src/layout/GlobalLayout/index.tsx +16 -1
  115. package/src/locales/default/common.ts +19 -0
  116. package/src/locales/default/migration.ts +47 -0
  117. package/src/locales/default/setting.ts +1 -1
  118. package/src/locales/resources/en_US.ts +2 -0
  119. package/src/locales/resources/ja_JP.ts +2 -0
  120. package/src/locales/resources/ko_KR.ts +2 -0
  121. package/src/locales/resources/ru_RU.ts +2 -0
  122. package/src/locales/resources/zh_CN.ts +2 -0
  123. package/src/locales/resources/zh_TW.ts +2 -0
  124. package/src/migrations/FromV0ToV1.ts +2 -4
  125. package/src/migrations/FromV1ToV2/fixtures/input-v1-session.json +191 -0
  126. package/src/migrations/FromV1ToV2/fixtures/output-v2.json +202 -0
  127. package/src/migrations/FromV1ToV2/index.ts +82 -0
  128. package/src/migrations/FromV1ToV2/migrations.test.ts +224 -0
  129. package/src/migrations/FromV1ToV2/types/v1.ts +78 -0
  130. package/src/migrations/FromV1ToV2/types/v2.ts +52 -0
  131. package/src/{utils → migrations}/VersionController.test.ts +1 -3
  132. package/src/{utils → migrations}/VersionController.ts +5 -2
  133. package/src/migrations/index.ts +17 -3
  134. package/src/services/__tests__/file.test.ts +3 -3
  135. package/src/services/chat.ts +66 -5
  136. package/src/services/config.ts +184 -0
  137. package/src/services/debug.ts +13 -0
  138. package/src/services/file.ts +6 -2
  139. package/src/services/github.ts +25 -0
  140. package/src/services/message.ts +79 -0
  141. package/src/services/session.ts +63 -0
  142. package/src/services/topic.ts +56 -0
  143. package/src/store/chat/actions/enhance.ts +95 -0
  144. package/src/store/{session/slices/chat → chat}/actions/message.ts +225 -247
  145. package/src/store/{session/slices/chat → chat}/actions/plugin.ts +29 -34
  146. package/src/store/{session/slices/chat → chat}/actions/share.ts +9 -13
  147. package/src/store/chat/actions/topic.ts +197 -0
  148. package/src/store/chat/helpers.ts +23 -0
  149. package/src/store/chat/index.ts +3 -0
  150. package/src/store/chat/initialState.ts +48 -0
  151. package/src/store/chat/reducers/message.test.ts +83 -0
  152. package/src/store/chat/reducers/message.ts +83 -0
  153. package/src/store/chat/selectors/__tests__/topic.test.ts +43 -0
  154. package/src/store/chat/selectors/chat.ts +119 -0
  155. package/src/store/chat/selectors/index.ts +2 -0
  156. package/src/store/chat/selectors/topic.ts +28 -0
  157. package/src/store/chat/store.ts +63 -0
  158. package/src/store/files/slices/images/action.ts +6 -4
  159. package/src/store/global/store.ts +1 -1
  160. package/src/store/middleware/createHyperStorage/index.ts +40 -24
  161. package/src/store/middleware/createHyperStorage/keyMapper.ts +8 -2
  162. package/src/store/middleware/createHyperStorage/type.ts +10 -8
  163. package/src/store/plugin/slices/plugin/action.ts +1 -1
  164. package/src/store/plugin/store.ts +2 -4
  165. package/src/store/session/helpers.ts +1 -1
  166. package/src/store/session/hooks/useSessionHydrated.ts +6 -10
  167. package/src/store/session/initialState.ts +26 -7
  168. package/src/store/session/selectors.ts +1 -2
  169. package/src/store/session/slices/agent/action.ts +26 -35
  170. package/src/store/session/slices/agent/selectors.ts +32 -37
  171. package/src/store/session/slices/session/action.ts +81 -88
  172. package/src/store/session/slices/session/helpers.ts +19 -0
  173. package/src/store/session/slices/session/initialState.ts +7 -10
  174. package/src/store/session/slices/session/selectors/export.ts +12 -9
  175. package/src/store/session/slices/session/selectors/index.ts +2 -35
  176. package/src/store/session/slices/session/selectors/list.test.ts +25 -203
  177. package/src/store/session/slices/session/selectors/list.ts +40 -78
  178. package/src/store/session/store.ts +11 -17
  179. package/src/types/agent/index.ts +61 -0
  180. package/src/types/chatMessage.ts +11 -20
  181. package/src/types/exportConfig.ts +7 -2
  182. package/src/types/files.ts +2 -2
  183. package/src/types/llm.ts +1 -1
  184. package/src/types/meta.ts +24 -12
  185. package/src/types/openai/chat.ts +9 -1
  186. package/src/types/openai/functionCall.ts +4 -0
  187. package/src/types/session.ts +10 -94
  188. package/src/types/translate.ts +2 -1
  189. package/src/utils/config.ts +5 -11
  190. package/src/utils/fetch.ts +8 -2
  191. package/src/app/chat/features/Conversation/usePluginsInit.ts +0 -14
  192. package/src/database/core/schema.ts +0 -9
  193. package/src/helpers/export.ts +0 -69
  194. package/src/hooks/useExportConfig.ts +0 -6
  195. package/src/store/session/slices/chat/actions/index.ts +0 -32
  196. package/src/store/session/slices/chat/actions/topic.ts +0 -171
  197. package/src/store/session/slices/chat/actions/translate.ts +0 -113
  198. package/src/store/session/slices/chat/helpers.ts +0 -9
  199. package/src/store/session/slices/chat/initialState.ts +0 -13
  200. package/src/store/session/slices/chat/reducers/message.test.ts +0 -319
  201. package/src/store/session/slices/chat/reducers/message.ts +0 -156
  202. package/src/store/session/slices/chat/reducers/topic.test.ts +0 -179
  203. package/src/store/session/slices/chat/reducers/topic.ts +0 -81
  204. package/src/store/session/slices/chat/selectors/chat.ts +0 -111
  205. package/src/store/session/slices/chat/selectors/index.ts +0 -26
  206. package/src/store/session/slices/chat/selectors/topic.ts +0 -30
  207. package/src/store/session/slices/chat/selectors/utils.test.ts +0 -385
  208. package/src/store/session/slices/chat/selectors/utils.ts +0 -91
  209. package/src/store/session/slices/chat/utils.ts +0 -13
  210. package/src/store/session/slices/session/reducers/session.test.ts +0 -577
  211. package/src/store/session/slices/session/reducers/session.ts +0 -182
  212. package/src/types/database/db.ts +0 -4
  213. /package/src/store/{session/slices/chat → chat}/reducers/files.test.ts +0 -0
  214. /package/src/store/{session/slices/chat → chat}/reducers/files.ts +0 -0
@@ -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
 
@@ -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 (
@@ -1,9 +1,9 @@
1
- import { ChatListProps } from '@lobehub/ui';
1
+ import { ChatListProps, RenderMessageExtra } from '@lobehub/ui';
2
2
 
3
3
  import { AssistantMessageExtra } from './Assistant';
4
4
  import { UserMessageExtra } from './User';
5
5
 
6
6
  export const renderMessagesExtra: ChatListProps['renderMessagesExtra'] = {
7
- assistant: AssistantMessageExtra,
8
- user: UserMessageExtra,
7
+ assistant: AssistantMessageExtra as unknown as RenderMessageExtra,
8
+ user: UserMessageExtra as unknown as RenderMessageExtra,
9
9
  };
@@ -0,0 +1,5 @@
1
+ import { FC } from 'react';
2
+
3
+ import { ChatMessage } from '@/types/chatMessage';
4
+
5
+ export type RenderMessageExtra = FC<ChatMessage>;
@@ -1,15 +1,19 @@
1
- import { RenderMessage } from '@lobehub/ui';
2
- import { memo } from 'react';
1
+ import { ReactNode, memo } from 'react';
3
2
 
4
- import { useSessionStore } from '@/store/session';
5
- import { chatSelectors } from '@/store/session/selectors';
3
+ import { useChatStore } from '@/store/chat';
4
+ import { chatSelectors } from '@/store/chat/selectors';
5
+ import { ChatMessage } from '@/types/chatMessage';
6
6
  import { isFunctionMessageAtStart } from '@/utils/message';
7
7
 
8
8
  import Inspector from '../Plugins/Inspector';
9
9
  import { DefaultMessage } from './Default';
10
10
 
11
- export const AssistantMessage: RenderMessage = memo(({ id, plugin, content, ...props }) => {
12
- const fcProps = useSessionStore(chatSelectors.getFunctionMessageProps({ content, id, plugin }));
11
+ export const AssistantMessage = memo<
12
+ ChatMessage & {
13
+ editableContent: ReactNode;
14
+ }
15
+ >(({ id, plugin, content, ...props }) => {
16
+ const fcProps = useChatStore(chatSelectors.getFunctionMessageProps({ content, id, plugin }));
13
17
 
14
18
  if (!isFunctionMessageAtStart(content))
15
19
  return <DefaultMessage content={content} id={id} {...props} />;
@@ -1,11 +1,15 @@
1
- import { RenderMessage } from '@lobehub/ui';
2
- import { memo } from 'react';
1
+ import { ReactNode, memo } from 'react';
3
2
 
4
3
  import { LOADING_FLAT } from '@/const/message';
4
+ import { ChatMessage } from '@/types/chatMessage';
5
5
 
6
6
  import BubblesLoading from '../Loading';
7
7
 
8
- export const DefaultMessage: RenderMessage = memo(({ id, editableContent, content }) => {
8
+ export const DefaultMessage = memo<
9
+ ChatMessage & {
10
+ editableContent: ReactNode;
11
+ }
12
+ >(({ id, editableContent, content }) => {
9
13
  if (content === LOADING_FLAT) return <BubblesLoading />;
10
14
 
11
15
  return <div id={id}>{editableContent}</div>;
@@ -1,19 +1,20 @@
1
- import { RenderMessage } from '@lobehub/ui';
2
1
  import isEqual from 'fast-deep-equal';
3
2
  import { memo, useState } from 'react';
4
3
  import { Flexbox } from 'react-layout-kit';
5
4
 
6
- import { useSessionStore } from '@/store/session';
7
- import { chatSelectors } from '@/store/session/selectors';
5
+ import { useChatStore } from '@/store/chat';
6
+ import { chatSelectors } from '@/store/chat/selectors';
7
+ import { ChatMessage } from '@/types/chatMessage';
8
8
 
9
9
  import Inspector from '../Plugins/Inspector';
10
10
  import PluginRender from '../Plugins/Render';
11
11
 
12
- export const FunctionMessage: RenderMessage = memo(({ id, content, plugin, name }) => {
13
- const fcProps = useSessionStore(
12
+ export const FunctionMessage = memo<ChatMessage>(({ id, content, plugin }) => {
13
+ const fcProps = useChatStore(
14
14
  chatSelectors.getFunctionMessageProps({ content, id, plugin }),
15
15
  isEqual,
16
16
  );
17
+
17
18
  const [showRender, setShow] = useState(true);
18
19
 
19
20
  return (
@@ -24,7 +25,7 @@ export const FunctionMessage: RenderMessage = memo(({ id, content, plugin, name
24
25
  content={content}
25
26
  id={id}
26
27
  loading={fcProps.loading}
27
- name={name}
28
+ name={plugin?.identifier}
28
29
  payload={fcProps.command}
29
30
  type={fcProps.type}
30
31
  />
@@ -4,7 +4,7 @@ import { useRouter } from 'next/navigation';
4
4
 
5
5
  import { useGlobalStore } from '@/store/global';
6
6
  import { useSessionStore } from '@/store/session';
7
- import { sessionSelectors } from '@/store/session/slices/session/selectors';
7
+ import { sessionSelectors } from '@/store/session/selectors';
8
8
  import { pathString } from '@/utils/url';
9
9
 
10
10
  import { AssistantMessage } from './Assistant';
@@ -13,10 +13,10 @@ import { FunctionMessage } from './Function';
13
13
  import { UserMessage } from './User';
14
14
 
15
15
  export const renderMessages: ChatListProps['renderMessages'] = {
16
- assistant: AssistantMessage,
17
- default: DefaultMessage,
18
- function: FunctionMessage,
19
- user: UserMessage,
16
+ assistant: AssistantMessage as any,
17
+ default: DefaultMessage as any,
18
+ function: FunctionMessage as any,
19
+ user: UserMessage as any,
20
20
  };
21
21
 
22
22
  export const useAvatarsClick = (): ChatListProps['onAvatarsClick'] => {
@@ -32,8 +32,8 @@ export const useAvatarsClick = (): ChatListProps['onAvatarsClick'] => {
32
32
  isInbox
33
33
  ? router.push('/settings/agent')
34
34
  : mobile
35
- ? router.push(pathString('/chat/settings', { hash: location.hash }))
36
- : toggleSystemRole(true);
35
+ ? router.push(pathString('/chat/settings', { hash: location.hash }))
36
+ : toggleSystemRole(true);
37
37
  }
38
38
  }
39
39
  };