@lobehub/chat 1.142.0 → 1.142.2

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 (210) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/Dockerfile +3 -3
  3. package/Dockerfile.database +3 -3
  4. package/Dockerfile.pglite +3 -3
  5. package/README.md +1 -1
  6. package/README.zh-CN.md +1 -1
  7. package/changelog/v1.json +18 -0
  8. package/docs/self-hosting/advanced/model-list.mdx +11 -0
  9. package/docs/self-hosting/advanced/model-list.zh-CN.mdx +11 -0
  10. package/docs/self-hosting/environment-variables/model-provider.mdx +23 -14
  11. package/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx +23 -14
  12. package/docs/usage/providers/aihubmix.zh-CN.mdx +1 -4
  13. package/locales/ar/models.json +17 -8
  14. package/locales/bg-BG/models.json +17 -8
  15. package/locales/de-DE/models.json +17 -8
  16. package/locales/en-US/models.json +17 -8
  17. package/locales/es-ES/models.json +17 -8
  18. package/locales/fa-IR/models.json +17 -8
  19. package/locales/fr-FR/models.json +17 -8
  20. package/locales/it-IT/models.json +17 -8
  21. package/locales/ja-JP/models.json +17 -8
  22. package/locales/ko-KR/models.json +17 -8
  23. package/locales/nl-NL/models.json +17 -8
  24. package/locales/pl-PL/models.json +17 -8
  25. package/locales/pt-BR/models.json +17 -8
  26. package/locales/ru-RU/models.json +17 -8
  27. package/locales/tr-TR/models.json +17 -8
  28. package/locales/vi-VN/models.json +17 -8
  29. package/locales/zh-CN/models.json +17 -8
  30. package/locales/zh-TW/models.json +17 -8
  31. package/package.json +2 -2
  32. package/packages/context-engine/src/processors/__tests__/MessageContent.test.ts +17 -17
  33. package/packages/context-engine/src/types.ts +4 -4
  34. package/packages/database/src/models/__tests__/generation.test.ts +2 -2
  35. package/packages/database/src/models/__tests__/generationBatch.test.ts +1 -1
  36. package/packages/database/src/models/__tests__/generationTopic.test.ts +2 -4
  37. package/packages/database/src/models/__tests__/message.test.ts +2 -2
  38. package/packages/database/src/models/asyncTask.ts +3 -4
  39. package/packages/database/src/models/chatGroup.ts +2 -2
  40. package/packages/database/src/models/chunk.ts +2 -3
  41. package/packages/database/src/models/drizzleMigration.ts +1 -1
  42. package/packages/database/src/models/file.ts +1 -2
  43. package/packages/database/src/models/generation.ts +8 -4
  44. package/packages/database/src/models/generationBatch.ts +1 -1
  45. package/packages/database/src/models/generationTopic.ts +2 -2
  46. package/packages/database/src/models/knowledgeBase.ts +2 -3
  47. package/packages/database/src/models/message.ts +9 -9
  48. package/packages/database/src/models/session.ts +8 -10
  49. package/packages/database/src/models/thread.ts +2 -3
  50. package/packages/database/src/models/topic.ts +2 -4
  51. package/packages/database/src/models/user.ts +1 -2
  52. package/packages/database/src/schemas/generation.ts +1 -2
  53. package/packages/database/src/schemas/message.ts +1 -3
  54. package/packages/model-runtime/src/core/streams/anthropic.ts +1 -2
  55. package/packages/model-runtime/src/core/streams/protocol.ts +1 -2
  56. package/packages/model-runtime/src/core/usageConverters/anthropic.ts +1 -2
  57. package/packages/model-runtime/src/core/usageConverters/google-ai.ts +1 -2
  58. package/packages/model-runtime/src/core/usageConverters/utils/computeChatCost.test.ts +1 -2
  59. package/packages/model-runtime/src/core/usageConverters/utils/computeChatCost.ts +1 -2
  60. package/packages/model-runtime/src/core/usageConverters/utils/withUsageCost.ts +1 -2
  61. package/packages/model-runtime/src/types/image.ts +1 -2
  62. package/packages/prompts/src/chains/__tests__/summaryHistory.test.ts +2 -2
  63. package/packages/prompts/src/chains/summaryHistory.ts +2 -2
  64. package/packages/prompts/src/chains/summaryTitle.ts +2 -3
  65. package/packages/prompts/src/contexts/supervisor/makeDecision.ts +2 -2
  66. package/packages/prompts/src/prompts/chatMessages/index.test.ts +11 -11
  67. package/packages/prompts/src/prompts/chatMessages/index.ts +13 -10
  68. package/packages/prompts/src/prompts/groupChat/index.test.ts +3 -4
  69. package/packages/prompts/src/prompts/groupChat/index.ts +3 -3
  70. package/packages/types/src/aiChat.ts +2 -2
  71. package/packages/types/src/exportConfig.ts +6 -6
  72. package/packages/types/src/importer.ts +2 -2
  73. package/packages/types/src/index.ts +2 -0
  74. package/packages/types/src/message/common/base.ts +27 -0
  75. package/packages/types/src/message/common/index.ts +5 -0
  76. package/packages/types/src/message/common/metadata.ts +67 -0
  77. package/packages/types/src/message/{tools.ts → common/tools.ts} +1 -1
  78. package/packages/types/src/message/common/translate.ts +8 -0
  79. package/packages/types/src/message/db/index.ts +2 -0
  80. package/packages/types/src/message/db/item.ts +29 -0
  81. package/packages/types/src/message/db/params.ts +57 -0
  82. package/packages/types/src/message/index.ts +3 -6
  83. package/packages/types/src/message/{chat.ts → ui/chat.ts} +13 -40
  84. package/packages/types/src/message/ui/extra.ts +16 -0
  85. package/packages/types/src/message/ui/index.ts +4 -0
  86. package/packages/types/src/message/{rag.ts → ui/rag.ts} +11 -1
  87. package/src/app/[variants]/(main)/chat/(workspace)/@conversation/features/ChatInput/V1Mobile/useSend.ts +1 -1
  88. package/src/app/[variants]/(main)/chat/(workspace)/features/ShareButton/index.tsx +0 -3
  89. package/src/app/[variants]/(main)/profile/stats/features/ModelsRank.tsx +1 -1
  90. package/src/app/[variants]/(main)/settings/llm/components/Checker.tsx +1 -2
  91. package/src/app/[variants]/(main)/settings/provider/detail/ollama/CheckError.tsx +1 -2
  92. package/src/app/[variants]/(main)/settings/provider/features/CreateNewProvider/index.tsx +1 -2
  93. package/src/app/[variants]/(main)/settings/provider/features/ProviderConfig/Checker.tsx +1 -2
  94. package/src/database/_deprecated/models/__tests__/message.test.ts +6 -7
  95. package/src/database/_deprecated/models/message.ts +13 -13
  96. package/src/features/AgentSetting/AgentTTS/SelectWithTTSPreview.tsx +1 -1
  97. package/src/features/ChatInput/ActionBar/STT/browser.tsx +1 -1
  98. package/src/features/ChatInput/ActionBar/STT/common.tsx +1 -2
  99. package/src/features/ChatInput/ActionBar/STT/openai.tsx +1 -1
  100. package/src/features/ChatItem/components/ErrorContent.tsx +5 -0
  101. package/src/features/Conversation/Error/ErrorJsonViewer.tsx +1 -2
  102. package/src/features/Conversation/Error/OllamaBizError/index.tsx +2 -3
  103. package/src/features/Conversation/Error/index.tsx +3 -4
  104. package/src/features/Conversation/Error/style.tsx +5 -1
  105. package/src/features/Conversation/Messages/Assistant/Actions/index.tsx +2 -2
  106. package/src/features/Conversation/Messages/Assistant/Block.tsx +1 -1
  107. package/src/features/Conversation/Messages/Assistant/Extra/index.test.tsx +2 -2
  108. package/src/features/Conversation/Messages/Assistant/Extra/index.tsx +1 -1
  109. package/src/features/Conversation/Messages/Assistant/FileChunks/Item/index.tsx +1 -1
  110. package/src/features/Conversation/Messages/Assistant/FileChunks/index.tsx +1 -2
  111. package/src/features/Conversation/Messages/Assistant/MessageContent.tsx +2 -2
  112. package/src/features/Conversation/Messages/Assistant/Tool/Render/CustomRender.tsx +2 -2
  113. package/src/features/Conversation/Messages/Assistant/Tool/Render/ErrorResponse.tsx +1 -2
  114. package/src/features/Conversation/Messages/Assistant/Tool/Render/PluginSettings.tsx +1 -1
  115. package/src/features/Conversation/Messages/Assistant/index.tsx +2 -2
  116. package/src/features/Conversation/Messages/Default.tsx +3 -3
  117. package/src/features/Conversation/Messages/Supervisor/index.tsx +2 -2
  118. package/src/features/Conversation/Messages/User/Actions.tsx +2 -2
  119. package/src/features/Conversation/Messages/User/FileListViewer/Item.tsx +1 -1
  120. package/src/features/Conversation/Messages/User/FileListViewer/index.tsx +1 -2
  121. package/src/features/Conversation/Messages/User/MessageContent.tsx +2 -3
  122. package/src/features/Conversation/Messages/User/VideoFileListViewer.tsx +1 -2
  123. package/src/features/Conversation/Messages/User/index.tsx +2 -2
  124. package/src/features/Conversation/components/ChatItem/ShareMessageModal/SharePdf/index.tsx +2 -2
  125. package/src/features/Conversation/components/ChatItem/ShareMessageModal/SharePdf/template.ts +2 -2
  126. package/src/features/Conversation/components/Extras/TTS/InitPlayer.tsx +1 -1
  127. package/src/features/Conversation/components/Extras/TTS/Player.tsx +1 -2
  128. package/src/features/Conversation/components/Extras/Translate.tsx +1 -1
  129. package/src/features/Conversation/components/Extras/Usage/UsageDetail/index.tsx +1 -1
  130. package/src/features/Conversation/components/Extras/Usage/UsageDetail/tokens.ts +1 -1
  131. package/src/features/Conversation/components/Extras/Usage/index.tsx +1 -2
  132. package/src/features/Conversation/components/ShareMessageModal/ShareImage/Preview.tsx +2 -2
  133. package/src/features/Conversation/components/ShareMessageModal/ShareImage/index.tsx +2 -2
  134. package/src/features/Conversation/components/ShareMessageModal/ShareText/index.tsx +2 -2
  135. package/src/features/Conversation/components/ShareMessageModal/ShareText/template.test.ts +3 -3
  136. package/src/features/Conversation/components/ShareMessageModal/ShareText/template.ts +2 -2
  137. package/src/features/Conversation/components/ShareMessageModal/index.tsx +3 -3
  138. package/src/features/Conversation/types/index.ts +5 -5
  139. package/src/features/Portal/Home/Body/Files/FileList/Item.tsx +1 -1
  140. package/src/features/Portal/Home/Body/Plugins/ArtifactList/Item/index.tsx +1 -1
  141. package/src/features/Portal/Thread/Chat/ChatInput/useSend.ts +1 -1
  142. package/src/features/ShareModal/ShareJSON/generateMessages.test.ts +3 -3
  143. package/src/features/ShareModal/ShareJSON/generateMessages.ts +3 -2
  144. package/src/features/ShareModal/SharePdf/index.tsx +2 -2
  145. package/src/features/ShareModal/ShareText/template.test.ts +3 -3
  146. package/src/features/ShareModal/ShareText/template.ts +2 -2
  147. package/src/libs/langchain/loaders/code/__tests__/long.json +1 -1
  148. package/src/libs/langchain/loaders/code/__tests__/long.txt +1 -1
  149. package/src/server/routers/lambda/__tests__/message.test.ts +2 -3
  150. package/src/server/routers/lambda/message.ts +2 -4
  151. package/src/services/chat/chat.test.ts +27 -25
  152. package/src/services/chat/contextEngineering.test.ts +21 -21
  153. package/src/services/chat/contextEngineering.ts +2 -2
  154. package/src/services/chat/index.ts +5 -8
  155. package/src/services/message/_deprecated.test.ts +7 -7
  156. package/src/services/message/_deprecated.ts +10 -10
  157. package/src/services/message/client.test.ts +10 -10
  158. package/src/services/message/client.ts +6 -5
  159. package/src/services/message/server.ts +4 -3
  160. package/src/services/message/type.ts +10 -11
  161. package/src/services/thread/type.ts +2 -1
  162. package/src/store/chat/helpers.test.ts +5 -5
  163. package/src/store/chat/helpers.ts +5 -5
  164. package/src/store/chat/initialState.ts +0 -3
  165. package/src/store/chat/slices/aiChat/actions/__tests__/fixtures.ts +5 -4
  166. package/src/store/chat/slices/aiChat/actions/__tests__/generateAIChatV2.test.ts +4 -4
  167. package/src/store/chat/slices/aiChat/actions/__tests__/rag.test.ts +6 -6
  168. package/src/store/chat/slices/aiChat/actions/generateAIChat.ts +17 -12
  169. package/src/store/chat/slices/aiChat/actions/generateAIChatV2.ts +7 -8
  170. package/src/store/chat/slices/aiChat/actions/generateAIGroupChat.ts +10 -6
  171. package/src/store/chat/slices/aiChat/actions/memory.ts +2 -3
  172. package/src/store/chat/slices/builtinTool/actions/__tests__/dalle.test.ts +3 -3
  173. package/src/store/chat/slices/builtinTool/actions/__tests__/search.test.ts +3 -3
  174. package/src/store/chat/slices/message/action.test.ts +13 -8
  175. package/src/store/chat/slices/message/action.ts +19 -18
  176. package/src/store/chat/slices/message/initialState.ts +3 -2
  177. package/src/store/chat/slices/message/reducer.test.ts +6 -6
  178. package/src/store/chat/slices/message/reducer.ts +11 -8
  179. package/src/store/chat/slices/message/selectors.test.ts +9 -9
  180. package/src/store/chat/slices/message/selectors.ts +10 -9
  181. package/src/store/chat/slices/message/supervisor.ts +2 -2
  182. package/src/store/chat/slices/plugin/action.test.ts +16 -13
  183. package/src/store/chat/slices/plugin/action.ts +11 -11
  184. package/src/store/chat/slices/portal/selectors.test.ts +8 -8
  185. package/src/store/chat/slices/thread/action.test.ts +2 -2
  186. package/src/store/chat/slices/thread/action.ts +9 -5
  187. package/src/store/chat/slices/thread/selectors/index.ts +11 -11
  188. package/src/store/chat/slices/thread/selectors/util.ts +2 -3
  189. package/src/store/chat/slices/topic/action.test.ts +6 -6
  190. package/src/store/chat/slices/topic/action.ts +2 -3
  191. package/src/store/chat/slices/translate/action.ts +2 -3
  192. package/src/store/chat/slices/tts/action.ts +1 -1
  193. package/src/store/chat/store.ts +0 -3
  194. package/src/store/image/slices/createImage/action.test.ts +9 -2
  195. package/src/store/image/slices/createImage/action.ts +6 -4
  196. package/src/tools/local-system/Render/ListFiles/Result.tsx +1 -1
  197. package/src/tools/local-system/Render/ListFiles/index.tsx +1 -1
  198. package/src/tools/local-system/Render/ReadLocalFile/index.tsx +1 -1
  199. package/src/tools/local-system/Render/RenameLocalFile/index.tsx +1 -1
  200. package/src/tools/local-system/Render/RunCommand/index.tsx +1 -1
  201. package/src/tools/local-system/Render/SearchFiles/index.tsx +1 -1
  202. package/src/tools/local-system/Render/WriteFile/index.tsx +1 -1
  203. package/src/tools/web-browsing/Render/Search/index.tsx +1 -3
  204. package/packages/types/src/message/base.ts +0 -173
  205. package/packages/types/src/message/translate.ts +0 -4
  206. package/src/store/chat/slices/share/action.test.ts +0 -22
  207. package/src/store/chat/slices/share/action.ts +0 -18
  208. package/src/store/chat/slices/share/initialState.ts +0 -7
  209. /package/packages/types/src/message/{image.ts → common/image.ts} +0 -0
  210. /package/packages/types/src/message/{video.ts → ui/video.ts} +0 -0
@@ -1,10 +1,10 @@
1
- import { THREAD_DRAFT_ID } from '@/const/message';
1
+ import { THREAD_DRAFT_ID } from '@lobechat/const';
2
+ import { ThreadItem, UIChatMessage } from '@lobechat/types';
3
+
2
4
  import { useAgentStore } from '@/store/agent';
3
5
  import { agentChatConfigSelectors } from '@/store/agent/selectors';
4
6
  import type { ChatStoreState } from '@/store/chat';
5
7
  import { chatHelpers } from '@/store/chat/helpers';
6
- import { ChatMessage } from '@/types/message';
7
- import { ThreadItem } from '@/types/topic';
8
8
 
9
9
  import { chatSelectors } from '../../message/selectors';
10
10
  import { genMessage } from './util';
@@ -32,7 +32,7 @@ const threadSourceMessageId = (s: ChatStoreState) => {
32
32
  return portalThread?.sourceMessageId;
33
33
  };
34
34
 
35
- const getTheadParentMessages = (s: ChatStoreState, data: ChatMessage[]) => {
35
+ const getTheadParentMessages = (s: ChatStoreState, data: UIChatMessage[]) => {
36
36
  if (s.startToForkThread) {
37
37
  const startMessageId = threadStartMessageId(s)!;
38
38
 
@@ -51,7 +51,7 @@ const getTheadParentMessages = (s: ChatStoreState, data: ChatMessage[]) => {
51
51
  /**
52
52
  * 获取当前 thread 的父级消息
53
53
  */
54
- const portalDisplayParentMessages = (s: ChatStoreState): ChatMessage[] => {
54
+ const portalDisplayParentMessages = (s: ChatStoreState): UIChatMessage[] => {
55
55
  const data = chatSelectors.activeBaseChatsWithoutTool(s);
56
56
 
57
57
  return getTheadParentMessages(s, data);
@@ -63,7 +63,7 @@ const portalDisplayParentMessages = (s: ChatStoreState): ChatMessage[] => {
63
63
  */
64
64
  const portalDisplayChildChatsByThreadId =
65
65
  (id?: string) =>
66
- (s: ChatStoreState): ChatMessage[] => {
66
+ (s: ChatStoreState): UIChatMessage[] => {
67
67
  // skip tool message
68
68
  const data = chatSelectors.activeBaseChatsWithoutTool(s);
69
69
 
@@ -76,7 +76,7 @@ const portalDisplayChats = (s: ChatStoreState) => {
76
76
  // use for optimistic update
77
77
  const draftMessage = chatSelectors.activeBaseChats(s).find((m) => m.threadId === THREAD_DRAFT_ID);
78
78
 
79
- return [...parentMessages, draftMessage, ...afterMessages].filter(Boolean) as ChatMessage[];
79
+ return [...parentMessages, draftMessage, ...afterMessages].filter(Boolean) as UIChatMessage[];
80
80
  };
81
81
 
82
82
  const portalDisplayChatsLength = (s: ChatStoreState) => {
@@ -95,7 +95,7 @@ const portalDisplayChatIDs = (s: ChatStoreState): string[] =>
95
95
  // ========= Portal Thread AI Chats ========= //
96
96
  // ========================================== //
97
97
 
98
- const portalAIParentMessages = (s: ChatStoreState): ChatMessage[] => {
98
+ const portalAIParentMessages = (s: ChatStoreState): UIChatMessage[] => {
99
99
  const data = chatSelectors.activeBaseChats(s);
100
100
 
101
101
  return getTheadParentMessages(s, data);
@@ -103,7 +103,7 @@ const portalAIParentMessages = (s: ChatStoreState): ChatMessage[] => {
103
103
 
104
104
  const portalAIChildChatsByThreadId =
105
105
  (id?: string) =>
106
- (s: ChatStoreState): ChatMessage[] => {
106
+ (s: ChatStoreState): UIChatMessage[] => {
107
107
  // skip tool message
108
108
  const data = chatSelectors.activeBaseChats(s);
109
109
 
@@ -114,14 +114,14 @@ const portalAIChats = (s: ChatStoreState) => {
114
114
  const parentMessages = portalAIParentMessages(s);
115
115
  const afterMessages = portalAIChildChatsByThreadId(s.portalThreadId)(s);
116
116
 
117
- return [...parentMessages, ...afterMessages].filter(Boolean) as ChatMessage[];
117
+ return [...parentMessages, ...afterMessages].filter(Boolean) as UIChatMessage[];
118
118
  };
119
119
 
120
120
  const portalAIChatsWithHistoryConfig = (s: ChatStoreState) => {
121
121
  const parentMessages = portalAIParentMessages(s);
122
122
  const afterMessages = portalAIChildChatsByThreadId(s.portalThreadId)(s);
123
123
 
124
- const messages = [...parentMessages, ...afterMessages].filter(Boolean) as ChatMessage[];
124
+ const messages = [...parentMessages, ...afterMessages].filter(Boolean) as UIChatMessage[];
125
125
 
126
126
  const enableHistoryCount = agentChatConfigSelectors.enableHistoryCount(useAgentStore.getState());
127
127
  const historyCount = agentChatConfigSelectors.historyCount(useAgentStore.getState());
@@ -1,8 +1,7 @@
1
- import { ChatMessage } from '@/types/message';
2
- import { ThreadType } from '@/types/topic';
1
+ import { ThreadType, UIChatMessage } from '@lobechat/types';
3
2
 
4
3
  export const genMessage = (
5
- messages: ChatMessage[],
4
+ messages: UIChatMessage[],
6
5
  startMessageId: string | undefined,
7
6
  threadMode?: ThreadType,
8
7
  ) => {
@@ -1,3 +1,4 @@
1
+ import { UIChatMessage } from '@lobechat/types';
1
2
  import { act, renderHook, waitFor } from '@testing-library/react';
2
3
  import { mutate } from 'swr';
3
4
  import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
@@ -8,7 +9,6 @@ import { messageService } from '@/services/message';
8
9
  import { topicService } from '@/services/topic';
9
10
  import { messageMapKey } from '@/store/chat/utils/messageMapKey';
10
11
  import { useSessionStore } from '@/store/session';
11
- import { ChatMessage } from '@/types/message';
12
12
  import { LobeSessionType } from '@/types/session';
13
13
  import { ChatTopic } from '@/types/topic';
14
14
 
@@ -135,7 +135,7 @@ describe('topic action', () => {
135
135
 
136
136
  it('should create a topic and bind messages to it', async () => {
137
137
  const { result } = renderHook(() => useChatStore());
138
- const messages = [{ id: 'message1' }, { id: 'message2' }] as ChatMessage[];
138
+ const messages = [{ id: 'message1' }, { id: 'message2' }] as UIChatMessage[];
139
139
  act(() => {
140
140
  useChatStore.setState({
141
141
  messagesMap: {
@@ -164,7 +164,7 @@ describe('topic action', () => {
164
164
  const { result } = renderHook(() => useChatStore());
165
165
  const groupId = 'group-session';
166
166
  const todoKey = messageMapKey(groupId, null);
167
- const messages = [{ id: 'group-message-1' }] as ChatMessage[];
167
+ const messages = [{ id: 'group-message-1' }] as UIChatMessage[];
168
168
 
169
169
  await act(async () => {
170
170
  useChatStore.setState({
@@ -567,7 +567,7 @@ describe('topic action', () => {
567
567
  describe('summaryTopicTitle', () => {
568
568
  it('should auto-summarize the topic title and update it', async () => {
569
569
  const topicId = 'topic-1';
570
- const messages = [{ id: 'message-1', content: 'Hello' }] as ChatMessage[];
570
+ const messages = [{ id: 'message-1', content: 'Hello' }] as UIChatMessage[];
571
571
  const topics = [{ id: 'topic-1', title: 'Test Topic' }] as ChatTopic[];
572
572
  const { result } = renderHook(() => useChatStore());
573
573
  await act(async () => {
@@ -605,7 +605,7 @@ describe('topic action', () => {
605
605
  const { result } = renderHook(() => useChatStore());
606
606
  const activeId = 'test-session-id';
607
607
  const newTopicId = 'new-topic-id';
608
- const messages = [{ id: 'message-1' }, { id: 'message-2' }] as ChatMessage[];
608
+ const messages = [{ id: 'message-1' }, { id: 'message-2' }] as UIChatMessage[];
609
609
 
610
610
  await act(async () => {
611
611
  useChatStore.setState({
@@ -661,7 +661,7 @@ describe('topic action', () => {
661
661
  const { result } = renderHook(() => useChatStore());
662
662
  const topicId = 'topic-1';
663
663
  const activeId = 'test-session-id';
664
- const messages = [{ id: 'message-1', content: 'Hello' }] as ChatMessage[];
664
+ const messages = [{ id: 'message-1', content: 'Hello' }] as UIChatMessage[];
665
665
 
666
666
  await act(async () => {
667
667
  useChatStore.setState({ activeId });
@@ -2,7 +2,7 @@
2
2
  // Note: To make the code more logic and readable, we just disable the auto sort key eslint rule
3
3
  // DON'T REMOVE THE FIRST LINE
4
4
  import { chainSummaryTitle } from '@lobechat/prompts';
5
- import { TraceNameMap } from '@lobechat/types';
5
+ import { TraceNameMap, UIChatMessage } from '@lobechat/types';
6
6
  import isEqual from 'fast-deep-equal';
7
7
  import { t } from 'i18next';
8
8
  import { produce } from 'immer';
@@ -24,7 +24,6 @@ import { useSessionStore } from '@/store/session';
24
24
  import { sessionSelectors } from '@/store/session/selectors';
25
25
  import { useUserStore } from '@/store/user';
26
26
  import { systemAgentSelectors } from '@/store/user/selectors';
27
- import { ChatMessage } from '@/types/message';
28
27
  import { ChatTopic } from '@/types/topic';
29
28
  import { merge } from '@/utils/merge';
30
29
  import { setNamespace } from '@/utils/storeDebug';
@@ -52,7 +51,7 @@ export interface ChatTopicAction {
52
51
 
53
52
  autoRenameTopicTitle: (id: string) => Promise<void>;
54
53
  duplicateTopic: (id: string) => Promise<void>;
55
- summaryTopicTitle: (topicId: string, messages: ChatMessage[]) => Promise<void>;
54
+ summaryTopicTitle: (topicId: string, messages: UIChatMessage[]) => Promise<void>;
56
55
  switchTopic: (id?: string, skipRefreshMessage?: boolean) => Promise<void>;
57
56
  updateTopicTitle: (id: string, title: string) => Promise<void>;
58
57
  useFetchTopics: (
@@ -1,5 +1,5 @@
1
- import { chainLangDetect , chainTranslate } from '@lobechat/prompts';
2
- import { TraceNameMap, TracePayload } from '@lobechat/types';
1
+ import { chainLangDetect, chainTranslate } from '@lobechat/prompts';
2
+ import { TraceNameMap, TracePayload , ChatTranslate } from '@lobechat/types';
3
3
  import { produce } from 'immer';
4
4
  import { StateCreator } from 'zustand/vanilla';
5
5
 
@@ -10,7 +10,6 @@ import { chatSelectors } from '@/store/chat/selectors';
10
10
  import { ChatStore } from '@/store/chat/store';
11
11
  import { useUserStore } from '@/store/user';
12
12
  import { systemAgentSelectors } from '@/store/user/selectors';
13
- import { ChatTranslate } from '@/types/message';
14
13
  import { merge } from '@/utils/merge';
15
14
  import { setNamespace } from '@/utils/storeDebug';
16
15
 
@@ -1,8 +1,8 @@
1
+ import { ChatTTS } from '@lobechat/types';
1
2
  import { StateCreator } from 'zustand/vanilla';
2
3
 
3
4
  import { messageService } from '@/services/message';
4
5
  import { ChatStore } from '@/store/chat/store';
5
- import { ChatTTS } from '@/types/message';
6
6
 
7
7
  /**
8
8
  * enhance chat action like translate,tts
@@ -11,7 +11,6 @@ import { ChatPortalAction, chatPortalSlice } from './slices/portal/action';
11
11
  import { ChatTranslateAction, chatTranslate } from './slices/translate/action';
12
12
  import { ChatMessageAction, chatMessage } from './slices/message/action';
13
13
  import { ChatPluginAction, chatPlugin } from './slices/plugin/action';
14
- import { ShareAction, chatShare } from './slices/share/action';
15
14
  import { ChatTopicAction, chatTopic } from './slices/topic/action';
16
15
  import { ChatAIChatAction, chatAiChat } from './slices/aiChat/actions';
17
16
  import { ChatTTSAction, chatTTS } from './slices/tts/action';
@@ -24,7 +23,6 @@ export interface ChatStoreAction
24
23
  ChatAIChatAction,
25
24
  ChatGroupChatAction,
26
25
  ChatTopicAction,
27
- ShareAction,
28
26
  ChatTranslateAction,
29
27
  ChatTTSAction,
30
28
  ChatPluginAction,
@@ -43,7 +41,6 @@ const createStore: StateCreator<ChatStore, [['zustand/devtools', never]]> = (...
43
41
  ...chatAiChat(...params),
44
42
  ...chatAiGroupChat(...params),
45
43
  ...chatTopic(...params),
46
- ...chatShare(...params),
47
44
  ...chatTranslate(...params),
48
45
  ...chatTTS(...params),
49
46
  ...chatToolSlice(...params),
@@ -54,6 +54,9 @@ describe('CreateImageAction', () => {
54
54
  provider: 'batch-provider',
55
55
  model: 'batch-model',
56
56
  config: { prompt: 'batch prompt' },
57
+ generations: [{}, {}, {}, {}], // 4 generations to match expected imageNum
58
+ createdAt: new Date(),
59
+ prompt: 'batch prompt',
57
60
  } as any,
58
61
  ],
59
62
  },
@@ -280,6 +283,10 @@ describe('CreateImageAction', () => {
280
283
  });
281
284
  });
282
285
 
286
+ // Get batch to verify imageNum uses batch.generations.length
287
+ const batch = result.current.generationBatchesMap['active-topic-id']?.[0];
288
+ const expectedImageNum = batch?.generations.length ?? 0;
289
+
283
290
  await act(async () => {
284
291
  await result.current.recreateImage('batch-id');
285
292
  });
@@ -290,12 +297,12 @@ describe('CreateImageAction', () => {
290
297
  // Verify batch removal
291
298
  expect(mockRemoveGenerationBatch).toHaveBeenCalledWith('batch-id', 'active-topic-id');
292
299
 
293
- // Verify service call
300
+ // Verify service call uses batch.generations.length for imageNum
294
301
  expect(mockImageService.createImage).toHaveBeenCalledWith({
295
302
  generationTopicId: 'active-topic-id',
296
303
  provider: 'batch-provider',
297
304
  model: 'batch-model',
298
- imageNum: 4,
305
+ imageNum: expectedImageNum,
299
306
  params: { prompt: 'batch prompt' },
300
307
  });
301
308
 
@@ -112,15 +112,17 @@ export const createCreateImageSlice: StateCreator<
112
112
  set({ isCreating: true }, false, 'recreateImage/startCreateImage');
113
113
 
114
114
  const store = get();
115
- const imageNum = imageGenerationConfigSelectors.imageNum(store);
116
115
  const activeGenerationTopicId = generationTopicSelectors.activeGenerationTopicId(store);
117
- const batch = generationBatchSelectors.getGenerationBatchByBatchId(generationBatchId)(store)!;
118
- const { removeGenerationBatch } = store;
119
-
120
116
  if (!activeGenerationTopicId) {
121
117
  throw new Error('No active generation topic');
122
118
  }
123
119
 
120
+ const { removeGenerationBatch } = store;
121
+ const batch = generationBatchSelectors.getGenerationBatchByBatchId(generationBatchId)(store)!;
122
+
123
+ // Use batch.generations.length to preserve original imageNum (not UI config)
124
+ const imageNum = batch.generations.length;
125
+
124
126
  try {
125
127
  // 1. Delete generation batch
126
128
  await removeGenerationBatch(generationBatchId, activeGenerationTopicId);
@@ -1,4 +1,5 @@
1
1
  import { LocalFileItem } from '@lobechat/electron-client-ipc';
2
+ import { ChatMessagePluginError } from '@lobechat/types';
2
3
  import { Skeleton } from 'antd';
3
4
  import { memo } from 'react';
4
5
  import { Flexbox } from 'react-layout-kit';
@@ -6,7 +7,6 @@ import { Flexbox } from 'react-layout-kit';
6
7
  import { useChatStore } from '@/store/chat';
7
8
  import { chatToolSelectors } from '@/store/chat/selectors';
8
9
  import FileItem from '@/tools/local-system/components/FileItem';
9
- import { ChatMessagePluginError } from '@/types/message';
10
10
 
11
11
  interface SearchFilesProps {
12
12
  listResults?: LocalFileItem[];
@@ -1,9 +1,9 @@
1
1
  import { ListLocalFileParams } from '@lobechat/electron-client-ipc';
2
+ import { ChatMessagePluginError } from '@lobechat/types';
2
3
  import React, { memo } from 'react';
3
4
 
4
5
  import { LocalFolder } from '@/features/LocalFile';
5
6
  import { LocalFileListState } from '@/tools/local-system/type';
6
- import { ChatMessagePluginError } from '@/types/message';
7
7
 
8
8
  import SearchResult from './Result';
9
9
 
@@ -1,10 +1,10 @@
1
1
  import { LocalReadFileParams } from '@lobechat/electron-client-ipc';
2
+ import { ChatMessagePluginError } from '@lobechat/types';
2
3
  import { memo } from 'react';
3
4
 
4
5
  import { useChatStore } from '@/store/chat';
5
6
  import { chatToolSelectors } from '@/store/chat/slices/builtinTool/selectors';
6
7
  import { LocalReadFileState } from '@/tools/local-system/type';
7
- import { ChatMessagePluginError } from '@/types/message';
8
8
 
9
9
  import ReadFileSkeleton from './ReadFileSkeleton';
10
10
  import ReadFileView from './ReadFileView';
@@ -1,4 +1,5 @@
1
1
  import { RenameLocalFileParams } from '@lobechat/electron-client-ipc';
2
+ import { ChatMessagePluginError } from '@lobechat/types';
2
3
  import { Icon } from '@lobehub/ui';
3
4
  import { createStyles } from 'antd-style';
4
5
  import { ArrowRightIcon } from 'lucide-react';
@@ -8,7 +9,6 @@ import { Flexbox } from 'react-layout-kit';
8
9
 
9
10
  import { LocalFile } from '@/features/LocalFile';
10
11
  import { LocalReadFileState } from '@/tools/local-system/type';
11
- import { ChatMessagePluginError } from '@/types/message';
12
12
 
13
13
  const useStyles = createStyles(({ css, token }) => ({
14
14
  container: css`
@@ -1,10 +1,10 @@
1
1
  import { RunCommandParams } from '@lobechat/electron-client-ipc';
2
+ import { ChatMessagePluginError } from '@lobechat/types';
2
3
  import { Terminal } from '@xterm/xterm';
3
4
  import '@xterm/xterm/css/xterm.css';
4
5
  import { memo, useEffect, useRef } from 'react';
5
6
 
6
7
  import { LocalReadFileState } from '@/tools/local-system/type';
7
- import { ChatMessagePluginError } from '@/types/message';
8
8
 
9
9
  interface RunCommandProps {
10
10
  args: RunCommandParams;
@@ -1,9 +1,9 @@
1
1
  import { LocalSearchFilesParams } from '@lobechat/electron-client-ipc';
2
+ import { ChatMessagePluginError } from '@lobechat/types';
2
3
  import { memo } from 'react';
3
4
  import { Flexbox } from 'react-layout-kit';
4
5
 
5
6
  import { LocalFileSearchState } from '@/tools/local-system/type';
6
- import { ChatMessagePluginError } from '@/types/message';
7
7
 
8
8
  import SearchResult from './Result';
9
9
  import SearchQuery from './SearchQuery';
@@ -1,4 +1,5 @@
1
1
  import { WriteLocalFileParams } from '@lobechat/electron-client-ipc';
2
+ import { ChatMessagePluginError } from '@lobechat/types';
2
3
  import { Icon } from '@lobehub/ui';
3
4
  import { Skeleton } from 'antd';
4
5
  import { ChevronRight } from 'lucide-react';
@@ -7,7 +8,6 @@ import { memo } from 'react';
7
8
  import { Flexbox } from 'react-layout-kit';
8
9
 
9
10
  import { LocalFile, LocalFolder } from '@/features/LocalFile';
10
- import { ChatMessagePluginError } from '@/types/message';
11
11
 
12
12
  interface WriteFileProps {
13
13
  args: WriteLocalFileParams;
@@ -1,10 +1,8 @@
1
- import { SearchQuery, UniformSearchResponse } from '@lobechat/types';
1
+ import { SearchQuery, UniformSearchResponse , ChatMessagePluginError } from '@lobechat/types';
2
2
  import { Alert, Highlighter } from '@lobehub/ui';
3
3
  import { memo, useState } from 'react';
4
4
  import { Flexbox } from 'react-layout-kit';
5
5
 
6
- import { ChatMessagePluginError } from '@/types/message';
7
-
8
6
  import ConfigForm from './ConfigForm';
9
7
  import SearchQueryView from './SearchQuery';
10
8
  import SearchResult from './SearchResult';
@@ -1,173 +0,0 @@
1
- /* eslint-disable sort-keys-fix/sort-keys-fix , typescript-sort-keys/interface */
2
- import type { ILobeAgentRuntimeErrorType } from '@lobechat/model-runtime';
3
- import type { IPluginErrorType } from '@lobehub/chat-plugin-sdk';
4
-
5
- import { ErrorType } from '../fetch';
6
- import { GroundingSearch } from '../search';
7
- import { ChatImageItem } from './image';
8
- import { ChatToolPayload, MessageToolCall } from './tools';
9
-
10
- /**
11
- * 聊天消息错误对象
12
- */
13
- export interface ChatMessageError {
14
- body?: any;
15
- message: string;
16
- type: ErrorType | IPluginErrorType | ILobeAgentRuntimeErrorType;
17
- }
18
-
19
- export interface ChatCitationItem {
20
- id?: string;
21
- onlyUrl?: boolean;
22
- title?: string;
23
- url: string;
24
- }
25
-
26
- export interface ModelReasoning {
27
- content?: string;
28
- duration?: number;
29
- signature?: string;
30
- }
31
-
32
- export interface ModelTokensUsage {
33
- // Input tokens breakdown
34
- /**
35
- * user prompt input
36
- */
37
- // Input cache tokens
38
- inputCachedTokens?: number;
39
- inputCacheMissTokens?: number;
40
- inputWriteCacheTokens?: number;
41
-
42
- inputTextTokens?: number;
43
- /**
44
- * user prompt image
45
- */
46
- inputImageTokens?: number;
47
- inputAudioTokens?: number;
48
- /**
49
- * currently only pplx has citation_tokens
50
- */
51
- inputCitationTokens?: number;
52
-
53
- // Output tokens breakdown
54
- outputTextTokens?: number;
55
- outputImageTokens?: number;
56
- outputAudioTokens?: number;
57
- outputReasoningTokens?: number;
58
-
59
- // Prediction tokens
60
- acceptedPredictionTokens?: number;
61
- rejectedPredictionTokens?: number;
62
-
63
- // Total tokens
64
- // TODO: make all following fields required
65
- totalInputTokens?: number;
66
- totalOutputTokens?: number;
67
- totalTokens?: number;
68
- }
69
-
70
- export interface ModelUsage extends ModelTokensUsage {
71
- /**
72
- * dollar
73
- */
74
- cost?: number;
75
- }
76
-
77
- export interface ModelSpeed {
78
- /**
79
- * tokens per second
80
- */
81
- tps?: number;
82
- /**
83
- * time to first token
84
- */
85
- ttft?: number;
86
- /**
87
- * from output start to output finish
88
- */
89
- duration?: number;
90
- /**
91
- * from input start to output finish
92
- */
93
- latency?: number;
94
- }
95
-
96
- export interface MessageMetadata extends ModelUsage, ModelSpeed {}
97
-
98
- export type MessageRoleType = 'user' | 'system' | 'assistant' | 'tool' | 'supervisor';
99
-
100
- export interface MessageItem {
101
- agentId: string | null;
102
- clientId: string | null;
103
- content: string | null;
104
- createdAt: Date;
105
- error: any | null;
106
- favorite: boolean | null;
107
- id: string;
108
- metadata?: MessageMetadata | null;
109
- model: string | null;
110
- observationId: string | null;
111
- parentId: string | null;
112
- provider: string | null;
113
- quotaId: string | null;
114
- reasoning: ModelReasoning | null;
115
- role: string;
116
- search: GroundingSearch | null;
117
- sessionId: string | null;
118
- threadId: string | null;
119
- tools: any | null;
120
- topicId: string | null;
121
- // jsonb type
122
- traceId: string | null;
123
- updatedAt: Date;
124
- userId: string;
125
- }
126
-
127
- export interface NewMessage {
128
- agentId?: string | null;
129
- clientId?: string | null;
130
- content?: string | null;
131
- createdAt?: Date;
132
- // optional because it has a default value
133
- error?: any | null;
134
- favorite?: boolean;
135
- id?: string;
136
- model?: string | null;
137
- observationId?: string | null;
138
- parentId?: string | null;
139
- provider?: string | null;
140
- quotaId?: string | null;
141
- // optional because it has a default function
142
- role: 'user' | 'system' | 'assistant' | 'tool';
143
- // required because it's notNull
144
- sessionId?: string | null;
145
- threadId?: string | null;
146
- tools?: any | null;
147
- topicId?: string | null;
148
- traceId?: string | null;
149
- // optional because it's generated
150
- updatedAt?: Date;
151
- userId: string; // optional because it's generated
152
- }
153
-
154
- export interface UpdateMessageParams {
155
- content?: string;
156
- error?: ChatMessageError | null;
157
- imageList?: ChatImageItem[];
158
- metadata?: MessageMetadata;
159
- model?: string;
160
- provider?: string;
161
- reasoning?: ModelReasoning;
162
- role?: string;
163
- search?: GroundingSearch;
164
- toolCalls?: MessageToolCall[];
165
- tools?: ChatToolPayload[] | null;
166
- }
167
-
168
- export interface NewMessageQueryParams {
169
- embeddingsId: string;
170
- messageId: string;
171
- rewriteQuery: string;
172
- userQuery: string;
173
- }
@@ -1,4 +0,0 @@
1
- export interface Translate {
2
- from?: string;
3
- to: string;
4
- }
@@ -1,22 +0,0 @@
1
- import { act, renderHook } from '@testing-library/react';
2
-
3
- import { DEFAULT_USER_AVATAR_URL } from '@/const/meta';
4
- import { shareService } from '@/services/share';
5
- import { useChatStore } from '@/store/chat';
6
- import { messageMapKey } from '@/store/chat/utils/messageMapKey';
7
- import { ChatMessage } from '@/types/message';
8
-
9
- afterEach(() => {
10
- vi.restoreAllMocks();
11
- });
12
-
13
- describe('shareSlice actions', () => {
14
- describe('genShareUrl', () => {
15
- it('TODO', async () => {
16
- const { result } = renderHook(() => useChatStore());
17
- await act(async () => {
18
- await result.current.genShareUrl();
19
- });
20
- });
21
- });
22
- });
@@ -1,18 +0,0 @@
1
- import { StateCreator } from 'zustand/vanilla';
2
-
3
- import { ChatStore } from '../../store';
4
-
5
- export interface ShareAction {
6
- genShareUrl: () => Promise<string>;
7
- }
8
-
9
- export const chatShare: StateCreator<
10
- ChatStore,
11
- [['zustand/devtools', never]],
12
- [],
13
- ShareAction
14
- > = () => ({
15
- genShareUrl: () => {
16
- return Promise.resolve('TODO');
17
- },
18
- });
@@ -1,7 +0,0 @@
1
- export interface ChatShareState {
2
- shareLoading?: boolean;
3
- }
4
-
5
- export const initialShareState: ChatShareState = {
6
- shareLoading: false,
7
- };