@lobehub/chat 1.142.1 → 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 (107) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/changelog/v1.json +9 -0
  3. package/package.json +1 -1
  4. package/packages/context-engine/src/processors/__tests__/MessageContent.test.ts +17 -17
  5. package/packages/context-engine/src/types.ts +4 -4
  6. package/packages/database/src/models/__tests__/message.test.ts +2 -2
  7. package/packages/database/src/models/message.ts +9 -9
  8. package/packages/database/src/models/topic.ts +2 -2
  9. package/packages/prompts/src/chains/__tests__/summaryHistory.test.ts +2 -2
  10. package/packages/prompts/src/chains/summaryHistory.ts +2 -2
  11. package/packages/prompts/src/chains/summaryTitle.ts +2 -2
  12. package/packages/prompts/src/contexts/supervisor/makeDecision.ts +2 -2
  13. package/packages/prompts/src/prompts/chatMessages/index.test.ts +11 -11
  14. package/packages/prompts/src/prompts/chatMessages/index.ts +13 -10
  15. package/packages/prompts/src/prompts/groupChat/index.test.ts +3 -4
  16. package/packages/prompts/src/prompts/groupChat/index.ts +3 -3
  17. package/packages/types/src/aiChat.ts +2 -2
  18. package/packages/types/src/exportConfig.ts +3 -3
  19. package/packages/types/src/importer.ts +2 -2
  20. package/packages/types/src/message/common/base.ts +0 -146
  21. package/packages/types/src/message/common/index.ts +2 -0
  22. package/packages/types/src/message/common/metadata.ts +67 -0
  23. package/packages/types/src/message/{tools.ts → common/tools.ts} +1 -1
  24. package/packages/types/src/message/common/translate.ts +4 -0
  25. package/packages/types/src/message/db/index.ts +2 -0
  26. package/packages/types/src/message/db/item.ts +29 -0
  27. package/packages/types/src/message/db/params.ts +57 -0
  28. package/packages/types/src/message/index.ts +1 -1
  29. package/packages/types/src/message/ui/chat.ts +9 -41
  30. package/packages/types/src/message/ui/extra.ts +16 -0
  31. package/packages/types/src/message/ui/index.ts +1 -0
  32. package/packages/types/src/message/ui/rag.ts +10 -0
  33. package/src/app/[variants]/(main)/chat/(workspace)/features/ShareButton/index.tsx +0 -3
  34. package/src/app/[variants]/(main)/settings/provider/features/CreateNewProvider/index.tsx +1 -2
  35. package/src/database/_deprecated/models/__tests__/message.test.ts +6 -6
  36. package/src/database/_deprecated/models/message.ts +13 -13
  37. package/src/features/Conversation/Error/OllamaBizError/index.tsx +2 -2
  38. package/src/features/Conversation/Error/index.tsx +3 -3
  39. package/src/features/Conversation/Messages/Assistant/Actions/index.tsx +2 -2
  40. package/src/features/Conversation/Messages/Assistant/Extra/index.test.tsx +2 -2
  41. package/src/features/Conversation/Messages/Assistant/MessageContent.tsx +2 -2
  42. package/src/features/Conversation/Messages/Assistant/Tool/Render/CustomRender.tsx +2 -2
  43. package/src/features/Conversation/Messages/Assistant/index.tsx +2 -2
  44. package/src/features/Conversation/Messages/Default.tsx +3 -3
  45. package/src/features/Conversation/Messages/Supervisor/index.tsx +2 -2
  46. package/src/features/Conversation/Messages/User/Actions.tsx +2 -2
  47. package/src/features/Conversation/Messages/User/MessageContent.tsx +2 -2
  48. package/src/features/Conversation/Messages/User/index.tsx +2 -2
  49. package/src/features/Conversation/components/ChatItem/ShareMessageModal/SharePdf/index.tsx +2 -2
  50. package/src/features/Conversation/components/ChatItem/ShareMessageModal/SharePdf/template.ts +2 -2
  51. package/src/features/Conversation/components/ShareMessageModal/ShareImage/Preview.tsx +2 -2
  52. package/src/features/Conversation/components/ShareMessageModal/ShareImage/index.tsx +2 -2
  53. package/src/features/Conversation/components/ShareMessageModal/ShareText/index.tsx +2 -2
  54. package/src/features/Conversation/components/ShareMessageModal/ShareText/template.test.ts +3 -3
  55. package/src/features/Conversation/components/ShareMessageModal/ShareText/template.ts +2 -2
  56. package/src/features/Conversation/components/ShareMessageModal/index.tsx +2 -2
  57. package/src/features/Conversation/types/index.ts +5 -5
  58. package/src/features/ShareModal/ShareJSON/generateMessages.test.ts +3 -3
  59. package/src/features/ShareModal/ShareJSON/generateMessages.ts +2 -2
  60. package/src/features/ShareModal/SharePdf/index.tsx +2 -2
  61. package/src/features/ShareModal/ShareText/template.test.ts +3 -3
  62. package/src/features/ShareModal/ShareText/template.ts +2 -2
  63. package/src/server/routers/lambda/__tests__/message.test.ts +2 -2
  64. package/src/server/routers/lambda/message.ts +2 -2
  65. package/src/services/chat/chat.test.ts +27 -25
  66. package/src/services/chat/contextEngineering.test.ts +21 -21
  67. package/src/services/chat/contextEngineering.ts +2 -2
  68. package/src/services/chat/index.ts +3 -3
  69. package/src/services/message/_deprecated.test.ts +2 -2
  70. package/src/services/message/_deprecated.ts +4 -4
  71. package/src/services/message/client.test.ts +4 -4
  72. package/src/services/message/client.ts +5 -5
  73. package/src/services/message/server.ts +3 -3
  74. package/src/services/message/type.ts +7 -7
  75. package/src/store/chat/helpers.test.ts +5 -5
  76. package/src/store/chat/helpers.ts +4 -5
  77. package/src/store/chat/initialState.ts +0 -3
  78. package/src/store/chat/slices/aiChat/actions/__tests__/fixtures.ts +4 -4
  79. package/src/store/chat/slices/aiChat/actions/__tests__/generateAIChatV2.test.ts +2 -2
  80. package/src/store/chat/slices/aiChat/actions/__tests__/rag.test.ts +6 -6
  81. package/src/store/chat/slices/aiChat/actions/generateAIChat.ts +6 -6
  82. package/src/store/chat/slices/aiChat/actions/generateAIChatV2.ts +4 -4
  83. package/src/store/chat/slices/aiChat/actions/generateAIGroupChat.ts +10 -6
  84. package/src/store/chat/slices/aiChat/actions/memory.ts +2 -2
  85. package/src/store/chat/slices/builtinTool/actions/__tests__/dalle.test.ts +3 -3
  86. package/src/store/chat/slices/builtinTool/actions/__tests__/search.test.ts +3 -3
  87. package/src/store/chat/slices/message/action.test.ts +13 -8
  88. package/src/store/chat/slices/message/action.ts +4 -4
  89. package/src/store/chat/slices/message/initialState.ts +2 -2
  90. package/src/store/chat/slices/message/reducer.test.ts +6 -6
  91. package/src/store/chat/slices/message/reducer.ts +7 -4
  92. package/src/store/chat/slices/message/selectors.test.ts +9 -9
  93. package/src/store/chat/slices/message/selectors.ts +9 -9
  94. package/src/store/chat/slices/message/supervisor.ts +2 -2
  95. package/src/store/chat/slices/plugin/action.test.ts +16 -13
  96. package/src/store/chat/slices/plugin/action.ts +5 -4
  97. package/src/store/chat/slices/portal/selectors.test.ts +8 -8
  98. package/src/store/chat/slices/thread/action.test.ts +2 -2
  99. package/src/store/chat/slices/thread/action.ts +9 -5
  100. package/src/store/chat/slices/thread/selectors/index.ts +10 -11
  101. package/src/store/chat/slices/thread/selectors/util.ts +2 -4
  102. package/src/store/chat/slices/topic/action.test.ts +6 -6
  103. package/src/store/chat/slices/topic/action.ts +2 -2
  104. package/src/store/chat/store.ts +0 -3
  105. package/src/store/chat/slices/share/action.test.ts +0 -22
  106. package/src/store/chat/slices/share/action.ts +0 -18
  107. package/src/store/chat/slices/share/initialState.ts +0 -7
@@ -1,22 +1,21 @@
1
- import { ChatMessage } from '@lobechat/types';
1
+ import { OpenAIChatMessage, UIChatMessage } from '@lobechat/types';
2
2
 
3
- import { OpenAIChatMessage } from '@/types/openai/chat';
4
3
  import { encodeAsync } from '@/utils/tokenizer';
5
4
 
6
5
  export const getMessagesTokenCount = async (messages: OpenAIChatMessage[]) =>
7
6
  encodeAsync(messages.map((m) => m.content).join(''));
8
7
 
9
- export const getMessageById = (messages: ChatMessage[], id: string) =>
8
+ export const getMessageById = (messages: UIChatMessage[], id: string) =>
10
9
  messages.find((m) => m.id === id);
11
10
 
12
11
  const getSlicedMessages = (
13
- messages: ChatMessage[],
12
+ messages: UIChatMessage[],
14
13
  options: {
15
14
  enableHistoryCount?: boolean;
16
15
  historyCount?: number;
17
16
  includeNewUserMessage?: boolean;
18
17
  },
19
- ): ChatMessage[] => {
18
+ ): UIChatMessage[] => {
20
19
  // if historyCount is not enabled, return all messages
21
20
  if (!options.enableHistoryCount || options.historyCount === undefined) return messages;
22
21
 
@@ -2,7 +2,6 @@
2
2
  import { ChatToolState, initialToolState } from './slices/builtinTool/initialState';
3
3
  import { ChatPortalState, initialChatPortalState } from './slices/portal/initialState';
4
4
  import { ChatMessageState, initialMessageState } from './slices/message/initialState';
5
- import { ChatShareState, initialShareState } from './slices/share/initialState';
6
5
  import { ChatTopicState, initialTopicState } from './slices/topic/initialState';
7
6
  import { ChatAIChatState, initialAiChatState } from './slices/aiChat/initialState';
8
7
  import { ChatThreadState, initialThreadState } from './slices/thread/initialState';
@@ -11,7 +10,6 @@ export type ChatStoreState = ChatTopicState &
11
10
  ChatMessageState &
12
11
  ChatAIChatState &
13
12
  ChatToolState &
14
- ChatShareState &
15
13
  ChatThreadState &
16
14
  ChatPortalState;
17
15
 
@@ -20,7 +18,6 @@ export const initialState: ChatStoreState = {
20
18
  ...initialAiChatState,
21
19
  ...initialTopicState,
22
20
  ...initialToolState,
23
- ...initialShareState,
24
21
  ...initialThreadState,
25
22
  ...initialChatPortalState,
26
23
 
@@ -1,4 +1,4 @@
1
- import { ChatMessage } from '@lobechat/types';
1
+ import { UIChatMessage } from '@lobechat/types';
2
2
 
3
3
  import { DEFAULT_AGENT_CHAT_CONFIG, DEFAULT_AGENT_CONFIG } from '@/const/settings';
4
4
 
@@ -22,7 +22,7 @@ export const TEST_CONTENT = {
22
22
  } as const;
23
23
 
24
24
  // Mock Data Factories
25
- export const createMockMessage = (overrides: Partial<ChatMessage> = {}): ChatMessage => {
25
+ export const createMockMessage = (overrides: Partial<UIChatMessage> = {}): UIChatMessage => {
26
26
  const base: any = {
27
27
  content: TEST_CONTENT.USER_MESSAGE,
28
28
  createdAt: Date.now(),
@@ -34,10 +34,10 @@ export const createMockMessage = (overrides: Partial<ChatMessage> = {}): ChatMes
34
34
  };
35
35
 
36
36
  // Merge overrides, preserving all provided properties
37
- return { ...base, ...overrides } as ChatMessage;
37
+ return { ...base, ...overrides } as UIChatMessage;
38
38
  };
39
39
 
40
- export const createMockMessages = (count: number): ChatMessage[] =>
40
+ export const createMockMessages = (count: number): UIChatMessage[] =>
41
41
  Array.from({ length: count }, (_, i) =>
42
42
  createMockMessage({
43
43
  content: `Message ${i}`,
@@ -1,4 +1,4 @@
1
- import { ChatMessage } from '@lobechat/types';
1
+ import { UIChatMessage } from '@lobechat/types';
2
2
  import { act, renderHook } from '@testing-library/react';
3
3
  import { TRPCClientError } from '@trpc/client';
4
4
  import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
@@ -376,7 +376,7 @@ describe('generateAIChatV2 actions', () => {
376
376
  content: TEST_CONTENT.USER_MESSAGE,
377
377
  sessionId: TEST_IDS.SESSION_ID,
378
378
  topicId: TEST_IDS.TOPIC_ID,
379
- } as ChatMessage;
379
+ } as UIChatMessage;
380
380
  const messages = [userMessage];
381
381
 
382
382
  const streamSpy = vi.spyOn(chatService, 'createAssistantMessageStream');
@@ -1,4 +1,4 @@
1
- import { ChatMessage } from '@lobechat/types';
1
+ import { UIChatMessage } from '@lobechat/types';
2
2
  import { act, renderHook } from '@testing-library/react';
3
3
  import { Mock, beforeEach, describe, expect, it, vi } from 'vitest';
4
4
 
@@ -49,7 +49,7 @@ describe('chatRAG actions', () => {
49
49
  act(() => {
50
50
  useChatStore.setState({
51
51
  messagesMap: {
52
- default: [{ id: messageId }] as ChatMessage[],
52
+ default: [{ id: messageId }] as UIChatMessage[],
53
53
  },
54
54
  });
55
55
  });
@@ -75,7 +75,7 @@ describe('chatRAG actions', () => {
75
75
  ({
76
76
  id: messageId,
77
77
  ragQuery: existingRagQuery,
78
- }) as ChatMessage,
78
+ }) as UIChatMessage,
79
79
  );
80
80
 
81
81
  // Mock the semantic search response
@@ -117,7 +117,7 @@ describe('chatRAG actions', () => {
117
117
  () =>
118
118
  ({
119
119
  id: messageId,
120
- }) as ChatMessage,
120
+ }) as UIChatMessage,
121
121
  );
122
122
 
123
123
  // Mock the rewrite query function
@@ -240,12 +240,12 @@ describe('chatRAG actions', () => {
240
240
  ({
241
241
  id: messageId,
242
242
  content,
243
- }) as ChatMessage,
243
+ }) as UIChatMessage,
244
244
  );
245
245
 
246
246
  vi.spyOn(chatSelectors, 'mainAIChatsWithHistoryConfig').mockReturnValue([
247
247
  { content: 'history' },
248
- ] as ChatMessage[]);
248
+ ] as UIChatMessage[]);
249
249
 
250
250
  const rewriteSpy = vi.spyOn(result.current, 'internal_rewriteQuery');
251
251
  const deleteSpy = vi.spyOn(result.current, 'deleteUserMessageRagQuery');
@@ -4,12 +4,12 @@ import { LOADING_FLAT, MESSAGE_CANCEL_FLAT, isDesktop, isServerMode } from '@lob
4
4
  import { knowledgeBaseQAPrompts } from '@lobechat/prompts';
5
5
  import {
6
6
  ChatImageItem,
7
- ChatMessage,
8
7
  CreateMessageParams,
9
8
  MessageSemanticSearchChunk,
10
9
  SendMessageParams,
11
10
  TraceEventType,
12
11
  TraceNameMap,
12
+ UIChatMessage,
13
13
  } from '@lobechat/types';
14
14
  import { t } from 'i18next';
15
15
  import { produce } from 'immer';
@@ -76,7 +76,7 @@ export interface AIGenerateAction {
76
76
  * including preprocessing and postprocessing steps
77
77
  */
78
78
  internal_coreProcessMessage: (
79
- messages: ChatMessage[],
79
+ messages: UIChatMessage[],
80
80
  parentId: string,
81
81
  params?: ProcessMessageParams,
82
82
  ) => Promise<void>;
@@ -84,7 +84,7 @@ export interface AIGenerateAction {
84
84
  * Retrieves an AI-generated chat message from the backend service
85
85
  */
86
86
  internal_fetchAIChatMessage: (input: {
87
- messages: ChatMessage[];
87
+ messages: UIChatMessage[];
88
88
  messageId: string;
89
89
  params?: ProcessMessageParams;
90
90
  model: string;
@@ -101,7 +101,7 @@ export interface AIGenerateAction {
101
101
  id: string,
102
102
  params?: {
103
103
  traceId?: string;
104
- messages?: ChatMessage[];
104
+ messages?: UIChatMessage[];
105
105
  threadId?: string;
106
106
  inPortalThread?: boolean;
107
107
  },
@@ -341,7 +341,7 @@ export const generateAIChat: StateCreator<
341
341
 
342
342
  ragQueryId = queryId;
343
343
 
344
- const lastMsg = messages.pop() as ChatMessage;
344
+ const lastMsg = messages.pop() as UIChatMessage;
345
345
 
346
346
  // 2. build the retrieve context messages
347
347
  const knowledgeBaseQAContext = knowledgeBaseQAPrompts({
@@ -780,7 +780,7 @@ export const generateAIChat: StateCreator<
780
780
 
781
781
  const currentMessage = chats[currentIndex];
782
782
 
783
- let contextMessages: ChatMessage[] = [];
783
+ let contextMessages: UIChatMessage[] = [];
784
784
 
785
785
  switch (currentMessage.role) {
786
786
  case 'tool':
@@ -4,13 +4,13 @@ import { DEFAULT_AGENT_CHAT_CONFIG, INBOX_SESSION_ID, isDesktop } from '@lobecha
4
4
  import { knowledgeBaseQAPrompts } from '@lobechat/prompts';
5
5
  import {
6
6
  ChatImageItem,
7
- ChatMessage,
8
7
  ChatTopic,
9
8
  ChatVideoItem,
10
9
  MessageSemanticSearchChunk,
11
10
  SendMessageParams,
12
11
  SendMessageServerResponse,
13
12
  TraceNameMap,
13
+ UIChatMessage,
14
14
  } from '@lobechat/types';
15
15
  import { TRPCClientError } from '@trpc/client';
16
16
  import { t } from 'i18next';
@@ -47,7 +47,7 @@ export interface AIGenerateV2Action {
47
47
  clearSendMessageError: () => void;
48
48
  internal_refreshAiChat: (params: {
49
49
  topics?: ChatTopic[];
50
- messages: ChatMessage[];
50
+ messages: UIChatMessage[];
51
51
  sessionId: string;
52
52
  topicId?: string;
53
53
  }) => void;
@@ -56,7 +56,7 @@ export interface AIGenerateV2Action {
56
56
  * including preprocessing and postprocessing steps
57
57
  */
58
58
  internal_execAgentRuntime: (params: {
59
- messages: ChatMessage[];
59
+ messages: UIChatMessage[];
60
60
  userMessageId: string;
61
61
  assistantMessageId: string;
62
62
  isWelcomeQuestion?: boolean;
@@ -353,7 +353,7 @@ export const generateAIChatV2: StateCreator<
353
353
 
354
354
  ragQueryId = queryId;
355
355
 
356
- const lastMsg = messages.pop() as ChatMessage;
356
+ const lastMsg = messages.pop() as UIChatMessage;
357
357
 
358
358
  // 2. build the retrieve context messages
359
359
  const knowledgeBaseQAContext = knowledgeBaseQAPrompts({
@@ -5,7 +5,12 @@ import {
5
5
  buildGroupChatSystemPrompt,
6
6
  filterMessagesForAgent,
7
7
  } from '@lobechat/prompts';
8
- import { ChatMessage, CreateMessageParams, SendGroupMessageParams } from '@lobechat/types';
8
+ import {
9
+ ChatErrorType,
10
+ CreateMessageParams,
11
+ SendGroupMessageParams,
12
+ UIChatMessage,
13
+ } from '@lobechat/types';
9
14
  import { produce } from 'immer';
10
15
  import { StateCreator } from 'zustand/vanilla';
11
16
 
@@ -17,7 +22,6 @@ import { useSessionStore } from '@/store/session';
17
22
  import { sessionSelectors } from '@/store/session/selectors';
18
23
  import { userProfileSelectors } from '@/store/user/selectors';
19
24
  import { getUserStoreState } from '@/store/user/store';
20
- import { ChatErrorType } from '@/types/fetch';
21
25
  import { merge } from '@/utils/merge';
22
26
  import { setNamespace } from '@/utils/storeDebug';
23
27
 
@@ -99,7 +103,7 @@ const extractMentionsFromContent = (
99
103
  /**
100
104
  * Check if a message is a tool calling message that requires a follow-up
101
105
  */
102
- const isToolCallMessage = (message: ChatMessage): boolean => {
106
+ const isToolCallMessage = (message: UIChatMessage): boolean => {
103
107
  return message.role === 'assistant' && !!message.tools && message.tools.length > 0;
104
108
  };
105
109
 
@@ -107,7 +111,7 @@ const isToolCallMessage = (message: ChatMessage): boolean => {
107
111
  * Count consecutive assistant messages from the end of the message list
108
112
  * This helps enforce maxResponseInRow limit
109
113
  */
110
- const countConsecutiveAssistantMessages = (messages: ChatMessage[]): number => {
114
+ const countConsecutiveAssistantMessages = (messages: UIChatMessage[]): number => {
111
115
  let count = 0;
112
116
 
113
117
  // Count from the end of the array backwards
@@ -135,7 +139,7 @@ const countConsecutiveAssistantMessages = (messages: ChatMessage[]): number => {
135
139
  * Returns true if the conversation flow should continue without supervisor intervention
136
140
  */
137
141
  const shouldAvoidSupervisorDecision = (
138
- messages: ChatMessage[],
142
+ messages: UIChatMessage[],
139
143
  maxResponseInRow?: number,
140
144
  isManualTrigger: boolean = false,
141
145
  ): boolean => {
@@ -666,7 +670,7 @@ export const chatAiGroupChat: StateCreator<
666
670
 
667
671
  const assistantId = await internal_createMessage(agentMessage);
668
672
 
669
- const systemMessage: ChatMessage = {
673
+ const systemMessage: UIChatMessage = {
670
674
  id: 'group-system',
671
675
  role: 'system',
672
676
  content: groupChatSystemPrompt,
@@ -1,5 +1,5 @@
1
1
  import { chainSummaryHistory } from '@lobechat/prompts';
2
- import { TraceNameMap , ChatMessage } from '@lobechat/types';
2
+ import { TraceNameMap, UIChatMessage } from '@lobechat/types';
3
3
  import { StateCreator } from 'zustand/vanilla';
4
4
 
5
5
  import { chatService } from '@/services/chat';
@@ -9,7 +9,7 @@ import { useUserStore } from '@/store/user';
9
9
  import { systemAgentSelectors } from '@/store/user/selectors';
10
10
 
11
11
  export interface ChatMemoryAction {
12
- internal_summaryHistory: (messages: ChatMessage[]) => Promise<void>;
12
+ internal_summaryHistory: (messages: UIChatMessage[]) => Promise<void>;
13
13
  }
14
14
 
15
15
  export const chatMemory: StateCreator<
@@ -1,4 +1,4 @@
1
- import { ChatMessage } from '@lobechat/types';
1
+ import { UIChatMessage } from '@lobechat/types';
2
2
  import { act, renderHook } from '@testing-library/react';
3
3
  import { describe, expect, it, vi } from 'vitest';
4
4
 
@@ -24,7 +24,7 @@ describe('chatToolSlice - dalle', () => {
24
24
  ({
25
25
  id,
26
26
  content: initialMessageContent,
27
- }) as ChatMessage,
27
+ }) as UIChatMessage,
28
28
  );
29
29
 
30
30
  const messageId = 'message-id';
@@ -84,7 +84,7 @@ describe('chatToolSlice - dalle', () => {
84
84
  ({
85
85
  id,
86
86
  content: initialMessageContent,
87
- }) as ChatMessage,
87
+ }) as UIChatMessage,
88
88
  );
89
89
  vi.spyOn(messageService, 'updateMessage').mockResolvedValueOnce(undefined);
90
90
 
@@ -1,6 +1,6 @@
1
1
  import { crawlResultsPrompt, searchResultsPrompt } from '@lobechat/prompts';
2
2
  import { SearchContent, SearchQuery, UniformSearchResponse } from '@lobechat/types';
3
- import { ChatMessage } from '@lobechat/types';
3
+ import { UIChatMessage } from '@lobechat/types';
4
4
  import { act, renderHook } from '@testing-library/react';
5
5
  import { Mock, beforeEach, describe, expect, it, vi } from 'vitest';
6
6
 
@@ -247,7 +247,7 @@ describe('search actions', () => {
247
247
  it('should save search result as tool message', async () => {
248
248
  const messageId = 'test-message-id';
249
249
  const parentId = 'parent-message-id';
250
- const mockMessage: Partial<ChatMessage> = {
250
+ const mockMessage: Partial<UIChatMessage> = {
251
251
  id: messageId,
252
252
  parentId,
253
253
  content: 'test content',
@@ -265,7 +265,7 @@ describe('search actions', () => {
265
265
  };
266
266
 
267
267
  vi.spyOn(chatSelectors, 'getMessageById').mockImplementation(
268
- () => () => mockMessage as ChatMessage,
268
+ () => () => mockMessage as UIChatMessage,
269
269
  );
270
270
 
271
271
  const { result } = renderHook(() => useChatStore());
@@ -1,5 +1,5 @@
1
1
  import { TraceEventType } from '@lobechat/types';
2
- import { ChatMessage } from '@lobechat/types';
2
+ import { UIChatMessage } from '@lobechat/types';
3
3
  import * as lobeUIModules from '@lobehub/ui';
4
4
  import { act, renderHook, waitFor } from '@testing-library/react';
5
5
  import { mutate } from 'swr';
@@ -206,7 +206,7 @@ describe('chatMessage actions', () => {
206
206
  activeId: 'session-id',
207
207
  activeTopicId: undefined,
208
208
  messagesMap: {
209
- [messageMapKey('session-id')]: [{ id: messageId } as ChatMessage],
209
+ [messageMapKey('session-id')]: [{ id: messageId } as UIChatMessage],
210
210
  },
211
211
  });
212
212
  });
@@ -229,9 +229,9 @@ describe('chatMessage actions', () => {
229
229
  activeTopicId: undefined,
230
230
  messagesMap: {
231
231
  [messageMapKey('session-id')]: [
232
- { id: messageId, tools: [{ id: 'tool1' }, { id: 'tool2' }] } as ChatMessage,
233
- { id: '2', tool_call_id: 'tool1', role: 'tool' } as ChatMessage,
234
- { id: '3', tool_call_id: 'tool2', role: 'tool' } as ChatMessage,
232
+ { id: messageId, tools: [{ id: 'tool1' }, { id: 'tool2' }] } as UIChatMessage,
233
+ { id: '2', tool_call_id: 'tool1', role: 'tool' } as UIChatMessage,
234
+ { id: '3', tool_call_id: 'tool2', role: 'tool' } as UIChatMessage,
235
235
  ],
236
236
  },
237
237
  });
@@ -292,9 +292,14 @@ describe('chatMessage actions', () => {
292
292
  id: messageId,
293
293
  role: 'assistant',
294
294
  tools: [{ id: 'tool1' }, { id: 'tool2' }],
295
- } as ChatMessage,
296
- { id: '2', parentId: messageId, tool_call_id: 'tool1', role: 'tool' } as ChatMessage,
297
- { id: '3', tool_call_id: 'tool2', role: 'tool' } as ChatMessage,
295
+ } as UIChatMessage,
296
+ {
297
+ id: '2',
298
+ parentId: messageId,
299
+ tool_call_id: 'tool1',
300
+ role: 'tool',
301
+ } as UIChatMessage,
302
+ { id: '3', tool_call_id: 'tool2', role: 'tool' } as UIChatMessage,
298
303
  ],
299
304
  },
300
305
  });
@@ -3,7 +3,6 @@
3
3
  import {
4
4
  ChatErrorType,
5
5
  ChatImageItem,
6
- ChatMessage,
7
6
  ChatMessageError,
8
7
  ChatMessagePluginError,
9
8
  CreateMessageParams,
@@ -13,6 +12,7 @@ import {
13
12
  ModelReasoning,
14
13
  TraceEventPayloads,
15
14
  TraceEventType,
15
+ UIChatMessage,
16
16
  UpdateMessageRAGParams,
17
17
  } from '@lobechat/types';
18
18
  import { nanoid } from '@lobechat/utils';
@@ -62,10 +62,10 @@ export interface ChatMessageAction {
62
62
  messageContextId: string,
63
63
  activeTopicId?: string,
64
64
  type?: 'session' | 'group',
65
- ) => SWRResponse<ChatMessage[]>;
65
+ ) => SWRResponse<UIChatMessage[]>;
66
66
  copyMessage: (id: string, content: string) => Promise<void>;
67
67
  refreshMessages: () => Promise<void>;
68
- replaceMessages: (messages: ChatMessage[]) => void;
68
+ replaceMessages: (messages: UIChatMessage[]) => void;
69
69
  // ========= ↓ Internal Method ↓ ========== //
70
70
  // ========================================== //
71
71
  // ========================================== //
@@ -306,7 +306,7 @@ export const chatMessage: StateCreator<
306
306
  * @param messageContextId - Can be sessionId or groupId
307
307
  */
308
308
  useFetchMessages: (enable, messageContextId, activeTopicId, type = 'session') =>
309
- useClientDataSWR<ChatMessage[]>(
309
+ useClientDataSWR<UIChatMessage[]>(
310
310
  enable ? [SWR_USE_FETCH_MESSAGES, messageContextId, activeTopicId, type] : null,
311
311
  async ([, sessionId, topicId, type]: [string, string, string | undefined, string]) =>
312
312
  type === 'session'
@@ -1,4 +1,4 @@
1
- import { ChatMessage } from '@lobechat/types';
1
+ import { UIChatMessage } from '@lobechat/types';
2
2
 
3
3
  import { ChatGroupAgentItem, ChatGroupItem } from '@/database/schemas/chatGroup';
4
4
 
@@ -40,7 +40,7 @@ export interface ChatMessageState {
40
40
  * whether messages have fetched
41
41
  */
42
42
  messagesInit: boolean;
43
- messagesMap: Record<string, ChatMessage[]>;
43
+ messagesMap: Record<string, UIChatMessage[]>;
44
44
  /**
45
45
  * Supervisor decision debounce timers by group ID
46
46
  */
@@ -1,9 +1,9 @@
1
- import { ChatMessage, ChatToolPayload } from '@lobechat/types';
1
+ import { ChatToolPayload, UIChatMessage } from '@lobechat/types';
2
2
 
3
3
  import { MessageDispatch, messagesReducer } from './reducer';
4
4
 
5
5
  describe('messagesReducer', () => {
6
- let initialState: ChatMessage[];
6
+ let initialState: UIChatMessage[];
7
7
 
8
8
  beforeEach(() => {
9
9
  initialState = [
@@ -115,7 +115,7 @@ describe('messagesReducer', () => {
115
115
  role: 'user',
116
116
  meta: {},
117
117
  extra: { abc: '1' },
118
- } as ChatMessage,
118
+ } as UIChatMessage,
119
119
  ...initialState,
120
120
  ],
121
121
  payload,
@@ -189,7 +189,7 @@ describe('messagesReducer', () => {
189
189
 
190
190
  describe('updateMessagePlugin', () => {
191
191
  it('should update the plugin of a tool message', () => {
192
- const toolMessage: ChatMessage = {
192
+ const toolMessage: UIChatMessage = {
193
193
  id: 'toolMessage',
194
194
  role: 'tool',
195
195
  content: 'Tool content',
@@ -302,7 +302,7 @@ describe('messagesReducer', () => {
302
302
  };
303
303
 
304
304
  const newState = messagesReducer(
305
- [...initialState, { id: messageId, role: 'assistant', content: '' } as ChatMessage],
305
+ [...initialState, { id: messageId, role: 'assistant', content: '' } as UIChatMessage],
306
306
  payload,
307
307
  );
308
308
  const updatedMessage = newState.find((m) => m.id === messageId);
@@ -330,7 +330,7 @@ describe('messagesReducer', () => {
330
330
  };
331
331
 
332
332
  const newState = messagesReducer(
333
- [...initialState, { id: messageId, role: 'assistant', content: '' } as ChatMessage],
333
+ [...initialState, { id: messageId, role: 'assistant', content: '' } as UIChatMessage],
334
334
  payload,
335
335
  );
336
336
  const updatedMessage = newState.find((m) => m.id === messageId);
@@ -1,9 +1,9 @@
1
1
  import {
2
- ChatMessage,
3
2
  ChatMessageExtra,
4
3
  ChatPluginPayload,
5
4
  ChatToolPayload,
6
5
  CreateMessageParams,
6
+ UIChatMessage,
7
7
  } from '@lobechat/types';
8
8
  import isEqual from 'fast-deep-equal';
9
9
  import { produce } from 'immer';
@@ -12,13 +12,13 @@ import { merge } from '@/utils/merge';
12
12
 
13
13
  interface UpdateMessages {
14
14
  type: 'updateMessages';
15
- value: ChatMessage[];
15
+ value: UIChatMessage[];
16
16
  }
17
17
 
18
18
  interface UpdateMessage {
19
19
  id: string;
20
20
  type: 'updateMessage';
21
- value: Partial<ChatMessage>;
21
+ value: Partial<UIChatMessage>;
22
22
  }
23
23
 
24
24
  interface CreateMessage {
@@ -88,7 +88,10 @@ export type MessageDispatch =
88
88
  | DeleteMessageTool
89
89
  | DeleteMessages;
90
90
 
91
- export const messagesReducer = (state: ChatMessage[], payload: MessageDispatch): ChatMessage[] => {
91
+ export const messagesReducer = (
92
+ state: UIChatMessage[],
93
+ payload: MessageDispatch,
94
+ ): UIChatMessage[] => {
92
95
  switch (payload.type) {
93
96
  case 'updateMessage': {
94
97
  return produce(state, (draftState) => {
@@ -1,4 +1,5 @@
1
- import { ChatMessage } from '@lobechat/types';
1
+ import { UIChatMessage } from '@lobechat/types';
2
+ import { LobeAgentConfig } from '@lobechat/types';
2
3
  import { act } from '@testing-library/react';
3
4
  import { describe, expect, it } from 'vitest';
4
5
 
@@ -9,7 +10,6 @@ import { ChatStore } from '@/store/chat';
9
10
  import { initialState } from '@/store/chat/initialState';
10
11
  import { messageMapKey } from '@/store/chat/utils/messageMapKey';
11
12
  import { createServerConfigStore } from '@/store/serverConfig/store';
12
- import { LobeAgentConfig } from '@/types/agent';
13
13
  import { merge } from '@/utils/merge';
14
14
 
15
15
  import { chatSelectors } from './selectors';
@@ -45,7 +45,7 @@ const mockMessages = [
45
45
  },
46
46
  ],
47
47
  },
48
- ] as ChatMessage[];
48
+ ] as UIChatMessage[];
49
49
 
50
50
  const mockReasoningMessages = [
51
51
  {
@@ -66,7 +66,7 @@ const mockReasoningMessages = [
66
66
  content: 'Reasoning Content',
67
67
  },
68
68
  },
69
- ] as ChatMessage[];
69
+ ] as UIChatMessage[];
70
70
 
71
71
  const mockedChats = [
72
72
  {
@@ -105,7 +105,7 @@ const mockedChats = [
105
105
  },
106
106
  ],
107
107
  },
108
- ] as ChatMessage[];
108
+ ] as UIChatMessage[];
109
109
 
110
110
  const mockChatStore = {
111
111
  messagesMap: {
@@ -172,7 +172,7 @@ describe('chatSelectors', () => {
172
172
  apiName: 'ttt',
173
173
  type: 'default',
174
174
  },
175
- } as ChatMessage;
175
+ } as UIChatMessage;
176
176
  const state = merge(initialStore, {
177
177
  messagesMap: {
178
178
  [messageMapKey('abc')]: [...mockMessages, toolMessage],
@@ -350,7 +350,7 @@ describe('chatSelectors', () => {
350
350
  { id: '3', role: 'tool', content: 'Tool message 1' },
351
351
  { id: '4', role: 'user', content: 'Query' },
352
352
  { id: '5', role: 'tool', tools: [] },
353
- ] as ChatMessage[];
353
+ ] as UIChatMessage[];
354
354
  const state: Partial<ChatStore> = {
355
355
  activeId: 'test-id',
356
356
  messagesMap: {
@@ -366,7 +366,7 @@ describe('chatSelectors', () => {
366
366
  const messages = [
367
367
  { id: '1', role: 'user', content: 'Hello' },
368
368
  { id: '2', role: 'assistant', content: 'Hi' },
369
- ] as ChatMessage[];
369
+ ] as UIChatMessage[];
370
370
  const state: Partial<ChatStore> = {
371
371
  activeId: 'test-id',
372
372
  messagesMap: {
@@ -455,7 +455,7 @@ describe('chatSelectors', () => {
455
455
  groupId: 'group-123',
456
456
  agentId: 'agent-456',
457
457
  },
458
- ] as ChatMessage[];
458
+ ] as UIChatMessage[];
459
459
 
460
460
  const state = merge(initialStore, {
461
461
  messagesMap: {