@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.
- package/CHANGELOG.md +25 -0
- package/changelog/v1.json +9 -0
- package/package.json +1 -1
- package/packages/context-engine/src/processors/__tests__/MessageContent.test.ts +17 -17
- package/packages/context-engine/src/types.ts +4 -4
- package/packages/database/src/models/__tests__/message.test.ts +2 -2
- package/packages/database/src/models/message.ts +9 -9
- package/packages/database/src/models/topic.ts +2 -2
- package/packages/prompts/src/chains/__tests__/summaryHistory.test.ts +2 -2
- package/packages/prompts/src/chains/summaryHistory.ts +2 -2
- package/packages/prompts/src/chains/summaryTitle.ts +2 -2
- package/packages/prompts/src/contexts/supervisor/makeDecision.ts +2 -2
- package/packages/prompts/src/prompts/chatMessages/index.test.ts +11 -11
- package/packages/prompts/src/prompts/chatMessages/index.ts +13 -10
- package/packages/prompts/src/prompts/groupChat/index.test.ts +3 -4
- package/packages/prompts/src/prompts/groupChat/index.ts +3 -3
- package/packages/types/src/aiChat.ts +2 -2
- package/packages/types/src/exportConfig.ts +3 -3
- package/packages/types/src/importer.ts +2 -2
- package/packages/types/src/message/common/base.ts +0 -146
- package/packages/types/src/message/common/index.ts +2 -0
- package/packages/types/src/message/common/metadata.ts +67 -0
- package/packages/types/src/message/{tools.ts → common/tools.ts} +1 -1
- package/packages/types/src/message/common/translate.ts +4 -0
- package/packages/types/src/message/db/index.ts +2 -0
- package/packages/types/src/message/db/item.ts +29 -0
- package/packages/types/src/message/db/params.ts +57 -0
- package/packages/types/src/message/index.ts +1 -1
- package/packages/types/src/message/ui/chat.ts +9 -41
- package/packages/types/src/message/ui/extra.ts +16 -0
- package/packages/types/src/message/ui/index.ts +1 -0
- package/packages/types/src/message/ui/rag.ts +10 -0
- package/src/app/[variants]/(main)/chat/(workspace)/features/ShareButton/index.tsx +0 -3
- package/src/app/[variants]/(main)/settings/provider/features/CreateNewProvider/index.tsx +1 -2
- package/src/database/_deprecated/models/__tests__/message.test.ts +6 -6
- package/src/database/_deprecated/models/message.ts +13 -13
- package/src/features/Conversation/Error/OllamaBizError/index.tsx +2 -2
- package/src/features/Conversation/Error/index.tsx +3 -3
- package/src/features/Conversation/Messages/Assistant/Actions/index.tsx +2 -2
- package/src/features/Conversation/Messages/Assistant/Extra/index.test.tsx +2 -2
- package/src/features/Conversation/Messages/Assistant/MessageContent.tsx +2 -2
- package/src/features/Conversation/Messages/Assistant/Tool/Render/CustomRender.tsx +2 -2
- package/src/features/Conversation/Messages/Assistant/index.tsx +2 -2
- package/src/features/Conversation/Messages/Default.tsx +3 -3
- package/src/features/Conversation/Messages/Supervisor/index.tsx +2 -2
- package/src/features/Conversation/Messages/User/Actions.tsx +2 -2
- package/src/features/Conversation/Messages/User/MessageContent.tsx +2 -2
- package/src/features/Conversation/Messages/User/index.tsx +2 -2
- package/src/features/Conversation/components/ChatItem/ShareMessageModal/SharePdf/index.tsx +2 -2
- package/src/features/Conversation/components/ChatItem/ShareMessageModal/SharePdf/template.ts +2 -2
- package/src/features/Conversation/components/ShareMessageModal/ShareImage/Preview.tsx +2 -2
- package/src/features/Conversation/components/ShareMessageModal/ShareImage/index.tsx +2 -2
- package/src/features/Conversation/components/ShareMessageModal/ShareText/index.tsx +2 -2
- package/src/features/Conversation/components/ShareMessageModal/ShareText/template.test.ts +3 -3
- package/src/features/Conversation/components/ShareMessageModal/ShareText/template.ts +2 -2
- package/src/features/Conversation/components/ShareMessageModal/index.tsx +2 -2
- package/src/features/Conversation/types/index.ts +5 -5
- package/src/features/ShareModal/ShareJSON/generateMessages.test.ts +3 -3
- package/src/features/ShareModal/ShareJSON/generateMessages.ts +2 -2
- package/src/features/ShareModal/SharePdf/index.tsx +2 -2
- package/src/features/ShareModal/ShareText/template.test.ts +3 -3
- package/src/features/ShareModal/ShareText/template.ts +2 -2
- package/src/server/routers/lambda/__tests__/message.test.ts +2 -2
- package/src/server/routers/lambda/message.ts +2 -2
- package/src/services/chat/chat.test.ts +27 -25
- package/src/services/chat/contextEngineering.test.ts +21 -21
- package/src/services/chat/contextEngineering.ts +2 -2
- package/src/services/chat/index.ts +3 -3
- package/src/services/message/_deprecated.test.ts +2 -2
- package/src/services/message/_deprecated.ts +4 -4
- package/src/services/message/client.test.ts +4 -4
- package/src/services/message/client.ts +5 -5
- package/src/services/message/server.ts +3 -3
- package/src/services/message/type.ts +7 -7
- package/src/store/chat/helpers.test.ts +5 -5
- package/src/store/chat/helpers.ts +4 -5
- package/src/store/chat/initialState.ts +0 -3
- package/src/store/chat/slices/aiChat/actions/__tests__/fixtures.ts +4 -4
- package/src/store/chat/slices/aiChat/actions/__tests__/generateAIChatV2.test.ts +2 -2
- package/src/store/chat/slices/aiChat/actions/__tests__/rag.test.ts +6 -6
- package/src/store/chat/slices/aiChat/actions/generateAIChat.ts +6 -6
- package/src/store/chat/slices/aiChat/actions/generateAIChatV2.ts +4 -4
- package/src/store/chat/slices/aiChat/actions/generateAIGroupChat.ts +10 -6
- package/src/store/chat/slices/aiChat/actions/memory.ts +2 -2
- package/src/store/chat/slices/builtinTool/actions/__tests__/dalle.test.ts +3 -3
- package/src/store/chat/slices/builtinTool/actions/__tests__/search.test.ts +3 -3
- package/src/store/chat/slices/message/action.test.ts +13 -8
- package/src/store/chat/slices/message/action.ts +4 -4
- package/src/store/chat/slices/message/initialState.ts +2 -2
- package/src/store/chat/slices/message/reducer.test.ts +6 -6
- package/src/store/chat/slices/message/reducer.ts +7 -4
- package/src/store/chat/slices/message/selectors.test.ts +9 -9
- package/src/store/chat/slices/message/selectors.ts +9 -9
- package/src/store/chat/slices/message/supervisor.ts +2 -2
- package/src/store/chat/slices/plugin/action.test.ts +16 -13
- package/src/store/chat/slices/plugin/action.ts +5 -4
- package/src/store/chat/slices/portal/selectors.test.ts +8 -8
- package/src/store/chat/slices/thread/action.test.ts +2 -2
- package/src/store/chat/slices/thread/action.ts +9 -5
- package/src/store/chat/slices/thread/selectors/index.ts +10 -11
- package/src/store/chat/slices/thread/selectors/util.ts +2 -4
- package/src/store/chat/slices/topic/action.test.ts +6 -6
- package/src/store/chat/slices/topic/action.ts +2 -2
- package/src/store/chat/store.ts +0 -3
- package/src/store/chat/slices/share/action.test.ts +0 -22
- package/src/store/chat/slices/share/action.ts +0 -18
- package/src/store/chat/slices/share/initialState.ts +0 -7
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { LobeTool } from '@lobechat/types';
|
|
2
|
-
import {
|
|
2
|
+
import { UIChatMessage } from '@lobechat/types';
|
|
3
|
+
import { ChatErrorType } from '@lobechat/types';
|
|
4
|
+
import { ChatStreamPayload } from '@lobechat/types';
|
|
3
5
|
import { LobeChatPluginManifest } from '@lobehub/chat-plugin-sdk';
|
|
4
6
|
import { act } from '@testing-library/react';
|
|
5
7
|
import { type Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
@@ -15,8 +17,6 @@ import { toolSelectors } from '@/store/tool/selectors';
|
|
|
15
17
|
import { modelProviderSelectors } from '@/store/user/selectors';
|
|
16
18
|
import { DalleManifest } from '@/tools/dalle';
|
|
17
19
|
import { WebBrowsingManifest } from '@/tools/web-browsing';
|
|
18
|
-
import { ChatErrorType } from '@/types/index';
|
|
19
|
-
import { ChatStreamPayload, type OpenAIChatMessage } from '@/types/openai/chat';
|
|
20
20
|
|
|
21
21
|
import { API_ENDPOINTS } from '../_url';
|
|
22
22
|
import * as helpers from './helper';
|
|
@@ -80,7 +80,7 @@ describe('ChatService', () => {
|
|
|
80
80
|
describe('createAssistantMessage', () => {
|
|
81
81
|
it('should process messages and call getChatCompletion with the right parameters', async () => {
|
|
82
82
|
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
83
|
-
const messages = [{ content: 'Hello', role: 'user' }] as
|
|
83
|
+
const messages = [{ content: 'Hello', role: 'user' }] as UIChatMessage[];
|
|
84
84
|
const enabledPlugins = ['plugin1'];
|
|
85
85
|
await act(async () => {
|
|
86
86
|
useToolStore.setState({
|
|
@@ -127,7 +127,7 @@ describe('ChatService', () => {
|
|
|
127
127
|
describe('extendParams functionality', () => {
|
|
128
128
|
it('should add reasoning parameters when model supports enableReasoning and user enables it', async () => {
|
|
129
129
|
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
130
|
-
const messages = [{ content: 'Test reasoning', role: 'user' }] as
|
|
130
|
+
const messages = [{ content: 'Test reasoning', role: 'user' }] as UIChatMessage[];
|
|
131
131
|
|
|
132
132
|
// Mock aiModelSelectors for extend params support
|
|
133
133
|
vi.spyOn(aiModelSelectors, 'isModelHasExtendParams').mockReturnValue(() => true);
|
|
@@ -160,7 +160,7 @@ describe('ChatService', () => {
|
|
|
160
160
|
|
|
161
161
|
it('should disable reasoning when model supports enableReasoning but user disables it', async () => {
|
|
162
162
|
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
163
|
-
const messages = [{ content: 'Test no reasoning', role: 'user' }] as
|
|
163
|
+
const messages = [{ content: 'Test no reasoning', role: 'user' }] as UIChatMessage[];
|
|
164
164
|
|
|
165
165
|
// Mock aiModelSelectors for extend params support
|
|
166
166
|
vi.spyOn(aiModelSelectors, 'isModelHasExtendParams').mockReturnValue(() => true);
|
|
@@ -192,7 +192,7 @@ describe('ChatService', () => {
|
|
|
192
192
|
|
|
193
193
|
it('should use default budget when reasoningBudgetToken is not set', async () => {
|
|
194
194
|
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
195
|
-
const messages = [{ content: 'Test default budget', role: 'user' }] as
|
|
195
|
+
const messages = [{ content: 'Test default budget', role: 'user' }] as UIChatMessage[];
|
|
196
196
|
|
|
197
197
|
// Mock aiModelSelectors for extend params support
|
|
198
198
|
vi.spyOn(aiModelSelectors, 'isModelHasExtendParams').mockReturnValue(() => true);
|
|
@@ -225,7 +225,7 @@ describe('ChatService', () => {
|
|
|
225
225
|
|
|
226
226
|
it('should set reasoning_effort when model supports reasoningEffort and user configures it', async () => {
|
|
227
227
|
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
228
|
-
const messages = [{ content: 'Test reasoning effort', role: 'user' }] as
|
|
228
|
+
const messages = [{ content: 'Test reasoning effort', role: 'user' }] as UIChatMessage[];
|
|
229
229
|
|
|
230
230
|
// Mock aiModelSelectors for extend params support
|
|
231
231
|
vi.spyOn(aiModelSelectors, 'isModelHasExtendParams').mockReturnValue(() => true);
|
|
@@ -254,7 +254,7 @@ describe('ChatService', () => {
|
|
|
254
254
|
|
|
255
255
|
it('should set thinkingBudget when model supports thinkingBudget and user configures it', async () => {
|
|
256
256
|
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
257
|
-
const messages = [{ content: 'Test thinking budget', role: 'user' }] as
|
|
257
|
+
const messages = [{ content: 'Test thinking budget', role: 'user' }] as UIChatMessage[];
|
|
258
258
|
|
|
259
259
|
// Mock aiModelSelectors for extend params support
|
|
260
260
|
vi.spyOn(aiModelSelectors, 'isModelHasExtendParams').mockReturnValue(() => true);
|
|
@@ -302,7 +302,7 @@ describe('ChatService', () => {
|
|
|
302
302
|
},
|
|
303
303
|
],
|
|
304
304
|
}, // Message with files
|
|
305
|
-
] as
|
|
305
|
+
] as UIChatMessage[];
|
|
306
306
|
|
|
307
307
|
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
308
308
|
await chatService.createAssistantMessage({
|
|
@@ -342,7 +342,7 @@ describe('ChatService', () => {
|
|
|
342
342
|
const messages = [
|
|
343
343
|
{ content: 'Hello', role: 'user', files: ['file2'] }, // Message with files
|
|
344
344
|
{ content: 'Hey', role: 'assistant' }, // Regular user message
|
|
345
|
-
] as
|
|
345
|
+
] as UIChatMessage[];
|
|
346
346
|
|
|
347
347
|
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
348
348
|
await chatService.createAssistantMessage({ messages, plugins: [] });
|
|
@@ -391,7 +391,7 @@ describe('ChatService', () => {
|
|
|
391
391
|
meta: {},
|
|
392
392
|
updatedAt: Date.now(),
|
|
393
393
|
},
|
|
394
|
-
] as
|
|
394
|
+
] as UIChatMessage[];
|
|
395
395
|
|
|
396
396
|
// Spy on processImageList method
|
|
397
397
|
// const processImageListSpy = vi.spyOn(chatService as any, 'processImageList');
|
|
@@ -463,7 +463,7 @@ describe('ChatService', () => {
|
|
|
463
463
|
meta: {},
|
|
464
464
|
updatedAt: Date.now(),
|
|
465
465
|
},
|
|
466
|
-
] as
|
|
466
|
+
] as UIChatMessage[];
|
|
467
467
|
|
|
468
468
|
// Spy on processImageList method
|
|
469
469
|
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
@@ -550,7 +550,7 @@ describe('ChatService', () => {
|
|
|
550
550
|
meta: {},
|
|
551
551
|
updatedAt: Date.now(),
|
|
552
552
|
},
|
|
553
|
-
] as
|
|
553
|
+
] as UIChatMessage[];
|
|
554
554
|
|
|
555
555
|
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
556
556
|
|
|
@@ -605,7 +605,7 @@ describe('ChatService', () => {
|
|
|
605
605
|
avatar: DEFAULT_USER_AVATAR,
|
|
606
606
|
},
|
|
607
607
|
},
|
|
608
|
-
] as
|
|
608
|
+
] as UIChatMessage[];
|
|
609
609
|
|
|
610
610
|
act(() => {
|
|
611
611
|
useToolStore.setState({
|
|
@@ -705,7 +705,7 @@ describe('ChatService', () => {
|
|
|
705
705
|
role: 'user',
|
|
706
706
|
content: 'https://vercel.com/ 请分析 chatGPT 关键词\n\n',
|
|
707
707
|
},
|
|
708
|
-
] as
|
|
708
|
+
] as UIChatMessage[];
|
|
709
709
|
|
|
710
710
|
act(() => {
|
|
711
711
|
useToolStore.setState({
|
|
@@ -807,7 +807,7 @@ describe('ChatService', () => {
|
|
|
807
807
|
role: 'user',
|
|
808
808
|
content: 'https://vercel.com/ 请分析 chatGPT 关键词\n\n',
|
|
809
809
|
},
|
|
810
|
-
] as
|
|
810
|
+
] as UIChatMessage[];
|
|
811
811
|
|
|
812
812
|
await chatService.createAssistantMessage({
|
|
813
813
|
messages,
|
|
@@ -847,7 +847,7 @@ describe('ChatService', () => {
|
|
|
847
847
|
avatar: DEFAULT_USER_AVATAR,
|
|
848
848
|
},
|
|
849
849
|
},
|
|
850
|
-
] as
|
|
850
|
+
] as UIChatMessage[];
|
|
851
851
|
|
|
852
852
|
await chatService.createAssistantMessage({
|
|
853
853
|
messages,
|
|
@@ -870,7 +870,7 @@ describe('ChatService', () => {
|
|
|
870
870
|
it('should add WebBrowsingManifest when search is enabled and not using model built-in search', async () => {
|
|
871
871
|
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
872
872
|
|
|
873
|
-
const messages = [{ content: 'Search for something', role: 'user' }] as
|
|
873
|
+
const messages = [{ content: 'Search for something', role: 'user' }] as UIChatMessage[];
|
|
874
874
|
|
|
875
875
|
// Mock agent store state with search enabled
|
|
876
876
|
vi.spyOn(agentChatConfigSelectors, 'currentChatConfig').mockReturnValueOnce({
|
|
@@ -921,7 +921,7 @@ describe('ChatService', () => {
|
|
|
921
921
|
it('should enable built-in search when model supports it and useModelBuiltinSearch is true', async () => {
|
|
922
922
|
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
923
923
|
|
|
924
|
-
const messages = [{ content: 'Search for something', role: 'user' }] as
|
|
924
|
+
const messages = [{ content: 'Search for something', role: 'user' }] as UIChatMessage[];
|
|
925
925
|
|
|
926
926
|
// Mock agent store state with search enabled and useModelBuiltinSearch enabled
|
|
927
927
|
vi.spyOn(agentChatConfigSelectors, 'currentChatConfig').mockReturnValueOnce({
|
|
@@ -966,7 +966,7 @@ describe('ChatService', () => {
|
|
|
966
966
|
it('should not enable search when searchMode is off', async () => {
|
|
967
967
|
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
968
968
|
|
|
969
|
-
const messages = [{ content: 'Search for something', role: 'user' }] as
|
|
969
|
+
const messages = [{ content: 'Search for something', role: 'user' }] as UIChatMessage[];
|
|
970
970
|
|
|
971
971
|
// Mock agent store state with search disabled
|
|
972
972
|
vi.spyOn(agentChatConfigSelectors, 'currentChatConfig').mockReturnValueOnce({
|
|
@@ -1278,7 +1278,7 @@ describe('ChatService private methods', () => {
|
|
|
1278
1278
|
describe('extendParams', () => {
|
|
1279
1279
|
it('should set enabledContextCaching to false when model supports disableContextCaching and user enables it', async () => {
|
|
1280
1280
|
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
1281
|
-
const messages = [{ content: 'Test context caching', role: 'user' }] as
|
|
1281
|
+
const messages = [{ content: 'Test context caching', role: 'user' }] as UIChatMessage[];
|
|
1282
1282
|
|
|
1283
1283
|
// Mock aiModelSelectors for extend params support
|
|
1284
1284
|
vi.spyOn(aiModelSelectors, 'isModelHasExtendParams').mockReturnValue(() => true);
|
|
@@ -1309,7 +1309,9 @@ describe('ChatService private methods', () => {
|
|
|
1309
1309
|
|
|
1310
1310
|
it('should not set enabledContextCaching when disableContextCaching is false', async () => {
|
|
1311
1311
|
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
1312
|
-
const messages = [
|
|
1312
|
+
const messages = [
|
|
1313
|
+
{ content: 'Test context caching enabled', role: 'user' },
|
|
1314
|
+
] as UIChatMessage[];
|
|
1313
1315
|
|
|
1314
1316
|
// Mock aiModelSelectors for extend params support
|
|
1315
1317
|
vi.spyOn(aiModelSelectors, 'isModelHasExtendParams').mockReturnValue(() => true);
|
|
@@ -1337,7 +1339,7 @@ describe('ChatService private methods', () => {
|
|
|
1337
1339
|
|
|
1338
1340
|
it('should set reasoning_effort when model supports reasoningEffort and user configures it', async () => {
|
|
1339
1341
|
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
1340
|
-
const messages = [{ content: 'Test reasoning effort', role: 'user' }] as
|
|
1342
|
+
const messages = [{ content: 'Test reasoning effort', role: 'user' }] as UIChatMessage[];
|
|
1341
1343
|
|
|
1342
1344
|
// Mock aiModelSelectors for extend params support
|
|
1343
1345
|
vi.spyOn(aiModelSelectors, 'isModelHasExtendParams').mockReturnValue(() => true);
|
|
@@ -1366,7 +1368,7 @@ describe('ChatService private methods', () => {
|
|
|
1366
1368
|
|
|
1367
1369
|
it('should set thinkingBudget when model supports thinkingBudget and user configures it', async () => {
|
|
1368
1370
|
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
1369
|
-
const messages = [{ content: 'Test thinking budget', role: 'user' }] as
|
|
1371
|
+
const messages = [{ content: 'Test thinking budget', role: 'user' }] as UIChatMessage[];
|
|
1370
1372
|
|
|
1371
1373
|
// Mock aiModelSelectors for extend params support
|
|
1372
1374
|
vi.spyOn(aiModelSelectors, 'isModelHasExtendParams').mockReturnValue(() => true);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UIChatMessage } from '@lobechat/types';
|
|
2
2
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
3
3
|
|
|
4
4
|
import * as isCanUseFCModule from '@/helpers/isCanUseFC';
|
|
@@ -72,7 +72,7 @@ describe('contextEngineering', () => {
|
|
|
72
72
|
],
|
|
73
73
|
}, // Message with files
|
|
74
74
|
{ content: 'Hey', role: 'assistant' }, // Regular user message
|
|
75
|
-
] as
|
|
75
|
+
] as UIChatMessage[];
|
|
76
76
|
|
|
77
77
|
const output = await contextEngineering({
|
|
78
78
|
messages,
|
|
@@ -140,7 +140,7 @@ describe('contextEngineering', () => {
|
|
|
140
140
|
],
|
|
141
141
|
}, // Message with files
|
|
142
142
|
{ content: 'Hey', role: 'assistant' }, // Regular user message
|
|
143
|
-
] as
|
|
143
|
+
] as UIChatMessage[];
|
|
144
144
|
const output = await contextEngineering({
|
|
145
145
|
messages,
|
|
146
146
|
provider: 'openai',
|
|
@@ -192,7 +192,7 @@ describe('contextEngineering', () => {
|
|
|
192
192
|
role: 'assistant',
|
|
193
193
|
tool_calls: [],
|
|
194
194
|
},
|
|
195
|
-
] as
|
|
195
|
+
] as UIChatMessage[];
|
|
196
196
|
|
|
197
197
|
const result = await contextEngineering({
|
|
198
198
|
messages,
|
|
@@ -222,7 +222,7 @@ describe('contextEngineering', () => {
|
|
|
222
222
|
signature: 'thinking_process',
|
|
223
223
|
},
|
|
224
224
|
},
|
|
225
|
-
] as
|
|
225
|
+
] as UIChatMessage[];
|
|
226
226
|
|
|
227
227
|
const result = await contextEngineering({
|
|
228
228
|
messages,
|
|
@@ -250,7 +250,7 @@ describe('contextEngineering', () => {
|
|
|
250
250
|
|
|
251
251
|
it('should inject INBOX_GUIDE_SYSTEM_ROLE for welcome questions in inbox session', async () => {
|
|
252
252
|
// Don't mock INBOX_GUIDE_SYSTEMROLE, use the real one
|
|
253
|
-
const messages:
|
|
253
|
+
const messages: UIChatMessage[] = [
|
|
254
254
|
{
|
|
255
255
|
role: 'user',
|
|
256
256
|
content: 'Hello, this is my first question',
|
|
@@ -281,7 +281,7 @@ describe('contextEngineering', () => {
|
|
|
281
281
|
it('should inject historySummary into system message when provided', async () => {
|
|
282
282
|
const historySummary = 'Previous conversation summary: User discussed AI topics.';
|
|
283
283
|
|
|
284
|
-
const messages:
|
|
284
|
+
const messages: UIChatMessage[] = [
|
|
285
285
|
{
|
|
286
286
|
role: 'user',
|
|
287
287
|
content: 'Continue our discussion',
|
|
@@ -310,7 +310,7 @@ describe('contextEngineering', () => {
|
|
|
310
310
|
// Mock isCanUseVision to return true for vision models
|
|
311
311
|
vi.spyOn(helpers, 'isCanUseVision').mockReturnValue(true);
|
|
312
312
|
|
|
313
|
-
const messages:
|
|
313
|
+
const messages: UIChatMessage[] = [
|
|
314
314
|
{
|
|
315
315
|
role: 'assistant',
|
|
316
316
|
content: 'Here is an image.',
|
|
@@ -337,7 +337,7 @@ describe('contextEngineering', () => {
|
|
|
337
337
|
// Mock isCanUseVision to return true for vision models
|
|
338
338
|
vi.spyOn(helpers, 'isCanUseVision').mockReturnValue(true);
|
|
339
339
|
|
|
340
|
-
const messages:
|
|
340
|
+
const messages: UIChatMessage[] = [
|
|
341
341
|
{
|
|
342
342
|
role: 'assistant',
|
|
343
343
|
content: '',
|
|
@@ -364,7 +364,7 @@ describe('contextEngineering', () => {
|
|
|
364
364
|
// Mock isCanUseFC to return false
|
|
365
365
|
vi.spyOn(isCanUseFCModule, 'isCanUseFC').mockReturnValue(false);
|
|
366
366
|
|
|
367
|
-
const messages:
|
|
367
|
+
const messages: UIChatMessage[] = [
|
|
368
368
|
{
|
|
369
369
|
role: 'assistant',
|
|
370
370
|
content: 'I have a tool call.',
|
|
@@ -396,7 +396,7 @@ describe('contextEngineering', () => {
|
|
|
396
396
|
|
|
397
397
|
describe('Process placeholder variables', () => {
|
|
398
398
|
it('should process placeholder variables in string content', async () => {
|
|
399
|
-
const messages:
|
|
399
|
+
const messages: UIChatMessage[] = [
|
|
400
400
|
{
|
|
401
401
|
role: 'user',
|
|
402
402
|
content: 'Hello {{username}}, today is {{date}} and the time is {{time}}',
|
|
@@ -461,7 +461,7 @@ describe('contextEngineering', () => {
|
|
|
461
461
|
});
|
|
462
462
|
|
|
463
463
|
it('should handle missing placeholder variables gracefully', async () => {
|
|
464
|
-
const messages:
|
|
464
|
+
const messages: UIChatMessage[] = [
|
|
465
465
|
{
|
|
466
466
|
role: 'user',
|
|
467
467
|
content: 'Hello {{username}}, missing: {{missing_var}}',
|
|
@@ -482,7 +482,7 @@ describe('contextEngineering', () => {
|
|
|
482
482
|
});
|
|
483
483
|
|
|
484
484
|
it('should not modify messages without placeholder variables', async () => {
|
|
485
|
-
const messages:
|
|
485
|
+
const messages: UIChatMessage[] = [
|
|
486
486
|
{
|
|
487
487
|
role: 'user',
|
|
488
488
|
content: 'Hello there, no variables here',
|
|
@@ -506,7 +506,7 @@ describe('contextEngineering', () => {
|
|
|
506
506
|
isServerMode = true;
|
|
507
507
|
vi.spyOn(helpers, 'isCanUseVision').mockReturnValue(true);
|
|
508
508
|
|
|
509
|
-
const messages:
|
|
509
|
+
const messages: UIChatMessage[] = [
|
|
510
510
|
{
|
|
511
511
|
role: 'user',
|
|
512
512
|
content: 'Hello {{username}}, check this image from {{date}}',
|
|
@@ -549,7 +549,7 @@ describe('contextEngineering', () => {
|
|
|
549
549
|
|
|
550
550
|
describe('Message preprocessing processors', () => {
|
|
551
551
|
it('should truncate message history when enabled', async () => {
|
|
552
|
-
const messages:
|
|
552
|
+
const messages: UIChatMessage[] = [
|
|
553
553
|
{
|
|
554
554
|
role: 'user',
|
|
555
555
|
content: 'Message 1',
|
|
@@ -611,7 +611,7 @@ describe('contextEngineering', () => {
|
|
|
611
611
|
});
|
|
612
612
|
|
|
613
613
|
it('should apply input template to user messages', async () => {
|
|
614
|
-
const messages:
|
|
614
|
+
const messages: UIChatMessage[] = [
|
|
615
615
|
{
|
|
616
616
|
role: 'user',
|
|
617
617
|
content: 'Original user input',
|
|
@@ -652,7 +652,7 @@ describe('contextEngineering', () => {
|
|
|
652
652
|
});
|
|
653
653
|
|
|
654
654
|
it('should inject system role at the beginning', async () => {
|
|
655
|
-
const messages:
|
|
655
|
+
const messages: UIChatMessage[] = [
|
|
656
656
|
{
|
|
657
657
|
role: 'user',
|
|
658
658
|
content: 'User message',
|
|
@@ -678,7 +678,7 @@ describe('contextEngineering', () => {
|
|
|
678
678
|
});
|
|
679
679
|
|
|
680
680
|
it('should combine all preprocessing steps correctly', async () => {
|
|
681
|
-
const messages:
|
|
681
|
+
const messages: UIChatMessage[] = [
|
|
682
682
|
{
|
|
683
683
|
role: 'user',
|
|
684
684
|
content: 'Old message 1',
|
|
@@ -733,7 +733,7 @@ describe('contextEngineering', () => {
|
|
|
733
733
|
});
|
|
734
734
|
|
|
735
735
|
it('should skip preprocessing when no configuration is provided', async () => {
|
|
736
|
-
const messages:
|
|
736
|
+
const messages: UIChatMessage[] = [
|
|
737
737
|
{
|
|
738
738
|
role: 'user',
|
|
739
739
|
content: 'Simple message',
|
|
@@ -760,7 +760,7 @@ describe('contextEngineering', () => {
|
|
|
760
760
|
});
|
|
761
761
|
|
|
762
762
|
it('should handle history truncation with system role injection correctly', async () => {
|
|
763
|
-
const messages:
|
|
763
|
+
const messages: UIChatMessage[] = [
|
|
764
764
|
{
|
|
765
765
|
role: 'user',
|
|
766
766
|
content: 'Message 1',
|
|
@@ -810,7 +810,7 @@ describe('contextEngineering', () => {
|
|
|
810
810
|
});
|
|
811
811
|
|
|
812
812
|
it('should handle input template compilation errors gracefully', async () => {
|
|
813
|
-
const messages:
|
|
813
|
+
const messages: UIChatMessage[] = [
|
|
814
814
|
{
|
|
815
815
|
role: 'user',
|
|
816
816
|
content: 'User message',
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
ToolSystemRoleProvider,
|
|
16
16
|
} from '@lobechat/context-engine';
|
|
17
17
|
import { historySummaryPrompt } from '@lobechat/prompts';
|
|
18
|
-
import {
|
|
18
|
+
import { OpenAIChatMessage, UIChatMessage } from '@lobechat/types';
|
|
19
19
|
import { VARIABLE_GENERATORS } from '@lobechat/utils/client';
|
|
20
20
|
|
|
21
21
|
import { isCanUseFC } from '@/helpers/isCanUseFC';
|
|
@@ -30,7 +30,7 @@ interface ContextEngineeringContext {
|
|
|
30
30
|
historySummary?: string;
|
|
31
31
|
inputTemplate?: string;
|
|
32
32
|
isWelcomeQuestion?: boolean;
|
|
33
|
-
messages:
|
|
33
|
+
messages: UIChatMessage[];
|
|
34
34
|
model: string;
|
|
35
35
|
provider: string;
|
|
36
36
|
sessionId?: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AgentRuntimeError, ChatCompletionErrorPayload } from '@lobechat/model-runtime';
|
|
2
|
-
import { ChatErrorType, TracePayload, TraceTagMap
|
|
2
|
+
import { ChatErrorType, TracePayload, TraceTagMap, UIChatMessage } from '@lobechat/types';
|
|
3
3
|
import { PluginRequestPayload, createHeadersWithPluginSettings } from '@lobehub/chat-plugin-sdk';
|
|
4
4
|
import { merge } from 'lodash-es';
|
|
5
5
|
import { ModelProvider } from 'model-bank';
|
|
@@ -41,11 +41,11 @@ import { findDeploymentName, isEnableFetchOnClient, resolveRuntimeProvider } fro
|
|
|
41
41
|
import { FetchOptions } from './types';
|
|
42
42
|
|
|
43
43
|
interface GetChatCompletionPayload extends Partial<Omit<ChatStreamPayload, 'messages'>> {
|
|
44
|
-
messages:
|
|
44
|
+
messages: UIChatMessage[];
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
type ChatStreamInputParams = Partial<Omit<ChatStreamPayload, 'messages'>> & {
|
|
48
|
-
messages?: (
|
|
48
|
+
messages?: (UIChatMessage | OpenAIChatMessage)[];
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
interface FetchAITaskResultParams extends FetchSSEOptions {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ChatMessage,
|
|
3
2
|
ChatMessageError,
|
|
4
3
|
ChatPluginPayload,
|
|
5
4
|
ChatTTS,
|
|
6
5
|
ChatTranslate,
|
|
6
|
+
UIChatMessage,
|
|
7
7
|
} from '@lobechat/types';
|
|
8
8
|
import dayjs from 'dayjs';
|
|
9
9
|
import { Mock, describe, expect, it, vi } from 'vitest';
|
|
@@ -47,7 +47,7 @@ describe('MessageClientService', () => {
|
|
|
47
47
|
updatedAt: 100,
|
|
48
48
|
role: 'user',
|
|
49
49
|
// ... other properties
|
|
50
|
-
} as
|
|
50
|
+
} as UIChatMessage;
|
|
51
51
|
const mockMessages = [mockMessage];
|
|
52
52
|
|
|
53
53
|
beforeEach(() => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ChatFileItem,
|
|
3
|
-
ChatMessage,
|
|
4
3
|
ChatMessageError,
|
|
5
4
|
ChatTTS,
|
|
6
5
|
ChatTranslate,
|
|
7
6
|
CreateMessageParams,
|
|
8
7
|
ModelRankItem,
|
|
8
|
+
UIChatMessage,
|
|
9
9
|
} from '@lobechat/types';
|
|
10
10
|
import dayjs from 'dayjs';
|
|
11
11
|
|
|
@@ -23,11 +23,11 @@ export class ClientService implements IMessageService {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// @ts-ignore
|
|
26
|
-
async batchCreateMessages(messages:
|
|
26
|
+
async batchCreateMessages(messages: UIChatMessage[]) {
|
|
27
27
|
return MessageModel.batchCreate(messages);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
async getMessages(sessionId: string, topicId?: string): Promise<
|
|
30
|
+
async getMessages(sessionId: string, topicId?: string): Promise<UIChatMessage[]> {
|
|
31
31
|
const messages = await MessageModel.query({ sessionId, topicId });
|
|
32
32
|
|
|
33
33
|
const fileList = (await Promise.all(
|
|
@@ -49,7 +49,7 @@ export class ClientService implements IMessageService {
|
|
|
49
49
|
}));
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
async getGroupMessages(groupId: string, topicId?: string): Promise<
|
|
52
|
+
async getGroupMessages(groupId: string, topicId?: string): Promise<UIChatMessage[]> {
|
|
53
53
|
// For the deprecated service, group messages are the same as regular messages
|
|
54
54
|
// since the old schema doesn't differentiate between session and group messages
|
|
55
55
|
return this.getMessages(groupId, topicId);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ChatMessage,
|
|
3
2
|
ChatMessageError,
|
|
4
3
|
ChatTTS,
|
|
5
4
|
ChatTranslate,
|
|
6
5
|
CreateMessageParams,
|
|
7
|
-
|
|
6
|
+
DBMessageItem,
|
|
7
|
+
UIChatMessage,
|
|
8
8
|
} from '@lobechat/types';
|
|
9
9
|
import { and, eq } from 'drizzle-orm';
|
|
10
10
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
@@ -34,7 +34,7 @@ const mockMessage = {
|
|
|
34
34
|
content: 'Mock message content',
|
|
35
35
|
sessionId,
|
|
36
36
|
role: 'user',
|
|
37
|
-
} as
|
|
37
|
+
} as UIChatMessage;
|
|
38
38
|
|
|
39
39
|
const mockMessages = [mockMessage];
|
|
40
40
|
|
|
@@ -98,7 +98,7 @@ describe('MessageClientService', () => {
|
|
|
98
98
|
sessionId,
|
|
99
99
|
role: 'user',
|
|
100
100
|
},
|
|
101
|
-
] as
|
|
101
|
+
] as DBMessageItem[]);
|
|
102
102
|
const count = await clientDB.$count(messages);
|
|
103
103
|
|
|
104
104
|
// Assert
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UIChatMessage } from '@lobechat/types';
|
|
2
2
|
|
|
3
3
|
import { INBOX_SESSION_ID } from '@/const/session';
|
|
4
4
|
import { clientDB } from '@/database/client/db';
|
|
@@ -42,7 +42,7 @@ export class ClientService extends BaseClientService implements IMessageService
|
|
|
42
42
|
},
|
|
43
43
|
);
|
|
44
44
|
|
|
45
|
-
return data as unknown as
|
|
45
|
+
return data as unknown as UIChatMessage[];
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
getGroupMessages: IMessageService['getGroupMessages'] = async (groupId, topicId) => {
|
|
@@ -62,13 +62,13 @@ export class ClientService extends BaseClientService implements IMessageService
|
|
|
62
62
|
},
|
|
63
63
|
);
|
|
64
64
|
|
|
65
|
-
return data as unknown as
|
|
65
|
+
return data as unknown as UIChatMessage[];
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
getAllMessages: IMessageService['getAllMessages'] = async () => {
|
|
69
69
|
const data = await this.messageModel.queryAll();
|
|
70
70
|
|
|
71
|
-
return data as unknown as
|
|
71
|
+
return data as unknown as UIChatMessage[];
|
|
72
72
|
};
|
|
73
73
|
|
|
74
74
|
countMessages: IMessageService['countMessages'] = async (params) => {
|
|
@@ -90,7 +90,7 @@ export class ClientService extends BaseClientService implements IMessageService
|
|
|
90
90
|
getAllMessagesInSession: IMessageService['getAllMessagesInSession'] = async (sessionId) => {
|
|
91
91
|
const data = this.messageModel.queryBySessionId(this.toDbSessionId(sessionId));
|
|
92
92
|
|
|
93
|
-
return data as unknown as
|
|
93
|
+
return data as unknown as UIChatMessage[];
|
|
94
94
|
};
|
|
95
95
|
|
|
96
96
|
updateMessageError: IMessageService['updateMessageError'] = async (id, error) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
-
import {
|
|
2
|
+
import { ChatTranslate, UIChatMessage } from '@lobechat/types';
|
|
3
3
|
|
|
4
4
|
import { INBOX_SESSION_ID } from '@/const/session';
|
|
5
5
|
import { lambdaClient } from '@/libs/trpc/client';
|
|
@@ -25,7 +25,7 @@ export class ServerService implements IMessageService {
|
|
|
25
25
|
topicId,
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
return data as unknown as
|
|
28
|
+
return data as unknown as UIChatMessage[];
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
getGroupMessages: IMessageService['getGroupMessages'] = async (groupId, topicId) => {
|
|
@@ -33,7 +33,7 @@ export class ServerService implements IMessageService {
|
|
|
33
33
|
groupId,
|
|
34
34
|
topicId,
|
|
35
35
|
});
|
|
36
|
-
return data as unknown as
|
|
36
|
+
return data as unknown as UIChatMessage[];
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
getAllMessages: IMessageService['getAllMessages'] = async () => {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ChatMessage,
|
|
3
2
|
ChatMessageError,
|
|
4
3
|
ChatMessagePluginError,
|
|
5
4
|
ChatTTS,
|
|
6
5
|
ChatTranslate,
|
|
7
6
|
CreateMessageParams,
|
|
8
|
-
|
|
7
|
+
DBMessageItem,
|
|
9
8
|
ModelRankItem,
|
|
9
|
+
UIChatMessage,
|
|
10
10
|
UpdateMessageParams,
|
|
11
11
|
UpdateMessageRAGParams,
|
|
12
12
|
} from '@lobechat/types';
|
|
@@ -16,12 +16,12 @@ import type { HeatmapsProps } from '@lobehub/charts';
|
|
|
16
16
|
|
|
17
17
|
export interface IMessageService {
|
|
18
18
|
createMessage(data: CreateMessageParams): Promise<string>;
|
|
19
|
-
batchCreateMessages(messages:
|
|
19
|
+
batchCreateMessages(messages: DBMessageItem[]): Promise<any>;
|
|
20
20
|
|
|
21
|
-
getMessages(sessionId: string, topicId?: string, groupId?: string): Promise<
|
|
22
|
-
getGroupMessages(groupId: string, topicId?: string): Promise<
|
|
23
|
-
getAllMessages(): Promise<
|
|
24
|
-
getAllMessagesInSession(sessionId: string): Promise<
|
|
21
|
+
getMessages(sessionId: string, topicId?: string, groupId?: string): Promise<UIChatMessage[]>;
|
|
22
|
+
getGroupMessages(groupId: string, topicId?: string): Promise<UIChatMessage[]>;
|
|
23
|
+
getAllMessages(): Promise<UIChatMessage[]>;
|
|
24
|
+
getAllMessagesInSession(sessionId: string): Promise<UIChatMessage[]>;
|
|
25
25
|
countMessages(params?: {
|
|
26
26
|
endDate?: string;
|
|
27
27
|
range?: [string, string];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UIChatMessage } from '@lobechat/types';
|
|
2
|
+
import { LobeAgentChatConfig } from '@lobechat/types';
|
|
3
|
+
import { OpenAIChatMessage } from '@lobechat/types';
|
|
2
4
|
import { describe, expect, it, vi } from 'vitest';
|
|
3
5
|
|
|
4
|
-
import { LobeAgentChatConfig, LobeAgentConfig } from '@/types/agent';
|
|
5
|
-
import { OpenAIChatMessage } from '@/types/openai/chat';
|
|
6
6
|
import { encodeAsync } from '@/utils/tokenizer';
|
|
7
7
|
import * as tokenizerObj from '@/utils/tokenizer';
|
|
8
8
|
|
|
@@ -48,7 +48,7 @@ describe('chatHelpers', () => {
|
|
|
48
48
|
const messages = [
|
|
49
49
|
{ id: '1', content: 'Hello' },
|
|
50
50
|
{ id: '2', content: 'World' },
|
|
51
|
-
] as
|
|
51
|
+
] as UIChatMessage[];
|
|
52
52
|
|
|
53
53
|
it('finds a message by id', () => {
|
|
54
54
|
const message = chatHelpers.getMessageById(messages, '1');
|
|
@@ -71,7 +71,7 @@ describe('chatHelpers', () => {
|
|
|
71
71
|
{ id: '1', content: 'First' },
|
|
72
72
|
{ id: '2', content: 'Second' },
|
|
73
73
|
{ id: '3', content: 'Third' },
|
|
74
|
-
] as
|
|
74
|
+
] as UIChatMessage[];
|
|
75
75
|
|
|
76
76
|
it('returns all messages if history is disabled', () => {
|
|
77
77
|
const config = { enableHistoryCount: false, historyCount: undefined } as LobeAgentChatConfig;
|