@lobehub/chat 0.151.0 → 0.151.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 +50 -0
- package/locales/ar/chat.json +2 -3
- package/locales/ar/welcome.json +34 -0
- package/locales/bg-BG/chat.json +2 -3
- package/locales/bg-BG/welcome.json +34 -0
- package/locales/de-DE/chat.json +0 -1
- package/locales/de-DE/welcome.json +34 -0
- package/locales/en-US/chat.json +0 -1
- package/locales/en-US/welcome.json +34 -0
- package/locales/es-ES/chat.json +0 -1
- package/locales/es-ES/welcome.json +34 -0
- package/locales/fr-FR/chat.json +0 -1
- package/locales/fr-FR/welcome.json +34 -0
- package/locales/it-IT/chat.json +0 -1
- package/locales/it-IT/welcome.json +34 -0
- package/locales/ja-JP/chat.json +0 -1
- package/locales/ja-JP/welcome.json +35 -1
- package/locales/ko-KR/chat.json +0 -1
- package/locales/ko-KR/welcome.json +34 -0
- package/locales/nl-NL/chat.json +3 -4
- package/locales/nl-NL/welcome.json +34 -0
- package/locales/pl-PL/chat.json +2 -3
- package/locales/pl-PL/welcome.json +34 -0
- package/locales/pt-BR/chat.json +0 -1
- package/locales/pt-BR/welcome.json +34 -0
- package/locales/ru-RU/chat.json +0 -1
- package/locales/ru-RU/welcome.json +34 -0
- package/locales/tr-TR/chat.json +1 -2
- package/locales/tr-TR/welcome.json +34 -0
- package/locales/vi-VN/chat.json +0 -1
- package/locales/vi-VN/welcome.json +34 -0
- package/locales/zh-CN/chat.json +0 -1
- package/locales/zh-CN/welcome.json +34 -0
- package/locales/zh-TW/chat.json +0 -1
- package/locales/zh-TW/welcome.json +34 -0
- package/next.config.mjs +1 -0
- package/package.json +2 -2
- package/src/app/chat/(desktop)/features/ChatInput/Footer/SendMore.tsx +2 -2
- package/src/app/chat/features/Migration/Failed.tsx +2 -1
- package/src/config/client.ts +0 -5
- package/src/const/guide.ts +86 -0
- package/src/const/url.ts +15 -8
- package/src/features/ChatInput/useSend.ts +8 -2
- package/src/features/Conversation/components/InboxWelcome/AgentsSuggest.tsx +108 -0
- package/src/features/Conversation/components/InboxWelcome/QuestionSuggest.tsx +99 -0
- package/src/features/Conversation/components/InboxWelcome/index.tsx +76 -0
- package/src/features/Conversation/components/VirtualizedList/index.tsx +18 -5
- package/src/features/Conversation/index.tsx +6 -9
- package/src/layout/GlobalProvider/AppTheme.tsx +2 -1
- package/src/locales/default/chat.ts +0 -2
- package/src/locales/default/welcome.ts +35 -0
- package/src/services/chat.ts +50 -25
- package/src/store/chat/slices/message/action.test.ts +1 -5
- package/src/store/chat/slices/message/action.ts +23 -10
- package/src/store/chat/slices/message/selectors.test.ts +27 -1
- package/src/store/chat/slices/message/selectors.ts +11 -1
- package/src/store/chat/slices/plugin/action.test.ts +1 -1
- package/src/store/chat/slices/plugin/action.ts +1 -1
|
@@ -29,10 +29,20 @@ const n = setNamespace('message');
|
|
|
29
29
|
|
|
30
30
|
const SWR_USE_FETCH_MESSAGES = 'SWR_USE_FETCH_MESSAGES';
|
|
31
31
|
|
|
32
|
-
interface SendMessageParams {
|
|
32
|
+
export interface SendMessageParams {
|
|
33
33
|
message: string;
|
|
34
34
|
files?: { id: string; url: string }[];
|
|
35
35
|
onlyAddUserMessage?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* https://github.com/lobehub/lobe-chat/pull/2086
|
|
39
|
+
*/
|
|
40
|
+
isWelcomeQuestion?: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface ProcessMessageParams {
|
|
44
|
+
traceId?: string;
|
|
45
|
+
isWelcomeQuestion?: boolean;
|
|
36
46
|
}
|
|
37
47
|
|
|
38
48
|
export interface ChatMessageAction {
|
|
@@ -77,7 +87,7 @@ export interface ChatMessageAction {
|
|
|
77
87
|
coreProcessMessage: (
|
|
78
88
|
messages: ChatMessage[],
|
|
79
89
|
parentId: string,
|
|
80
|
-
|
|
90
|
+
params?: ProcessMessageParams,
|
|
81
91
|
) => Promise<void>;
|
|
82
92
|
/**
|
|
83
93
|
* 实际获取 AI 响应
|
|
@@ -87,7 +97,7 @@ export interface ChatMessageAction {
|
|
|
87
97
|
fetchAIChatMessage: (
|
|
88
98
|
messages: ChatMessage[],
|
|
89
99
|
assistantMessageId: string,
|
|
90
|
-
|
|
100
|
+
params?: ProcessMessageParams,
|
|
91
101
|
) => Promise<{
|
|
92
102
|
content: string;
|
|
93
103
|
functionCallAtEnd: boolean;
|
|
@@ -173,7 +183,7 @@ export const chatMessage: StateCreator<
|
|
|
173
183
|
await messageService.removeAllMessages();
|
|
174
184
|
await refreshMessages();
|
|
175
185
|
},
|
|
176
|
-
sendMessage: async ({ message, files, onlyAddUserMessage }) => {
|
|
186
|
+
sendMessage: async ({ message, files, onlyAddUserMessage, isWelcomeQuestion }) => {
|
|
177
187
|
const { coreProcessMessage, activeTopicId, activeId } = get();
|
|
178
188
|
if (!activeId) return;
|
|
179
189
|
|
|
@@ -200,7 +210,7 @@ export const chatMessage: StateCreator<
|
|
|
200
210
|
// Get the current messages to generate AI response
|
|
201
211
|
const messages = chatSelectors.currentChats(get());
|
|
202
212
|
|
|
203
|
-
await coreProcessMessage(messages, id);
|
|
213
|
+
await coreProcessMessage(messages, id, { isWelcomeQuestion });
|
|
204
214
|
|
|
205
215
|
// check activeTopic and then auto create topic
|
|
206
216
|
const chats = chatSelectors.currentChats(get());
|
|
@@ -263,6 +273,8 @@ export const chatMessage: StateCreator<
|
|
|
263
273
|
async ([, sessionId, topicId]: [string, string, string | undefined]) =>
|
|
264
274
|
messageService.getMessages(sessionId, topicId),
|
|
265
275
|
{
|
|
276
|
+
suspense: true,
|
|
277
|
+
fallbackData: [],
|
|
266
278
|
onSuccess: (messages, key) => {
|
|
267
279
|
set(
|
|
268
280
|
{ activeId: sessionId, messages, messagesInit: true },
|
|
@@ -280,7 +292,7 @@ export const chatMessage: StateCreator<
|
|
|
280
292
|
},
|
|
281
293
|
|
|
282
294
|
// the internal process method of the AI message
|
|
283
|
-
coreProcessMessage: async (messages, userMessageId,
|
|
295
|
+
coreProcessMessage: async (messages, userMessageId, params) => {
|
|
284
296
|
const { fetchAIChatMessage, triggerFunctionCall, refreshMessages, activeTopicId } = get();
|
|
285
297
|
|
|
286
298
|
const { model, provider } = getAgentConfig();
|
|
@@ -301,7 +313,7 @@ export const chatMessage: StateCreator<
|
|
|
301
313
|
|
|
302
314
|
// 2. fetch the AI response
|
|
303
315
|
const { isFunctionCall, content, functionCallAtEnd, functionCallContent, traceId } =
|
|
304
|
-
await fetchAIChatMessage(messages, mid,
|
|
316
|
+
await fetchAIChatMessage(messages, mid, params);
|
|
305
317
|
|
|
306
318
|
// 3. if it's the function call message, trigger the function method
|
|
307
319
|
if (isFunctionCall) {
|
|
@@ -341,7 +353,7 @@ export const chatMessage: StateCreator<
|
|
|
341
353
|
|
|
342
354
|
set({ messages }, false, n(`dispatchMessage/${payload.type}`, payload));
|
|
343
355
|
},
|
|
344
|
-
fetchAIChatMessage: async (messages, assistantId,
|
|
356
|
+
fetchAIChatMessage: async (messages, assistantId, params) => {
|
|
345
357
|
const {
|
|
346
358
|
toggleChatLoading,
|
|
347
359
|
refreshMessages,
|
|
@@ -421,11 +433,12 @@ export const chatMessage: StateCreator<
|
|
|
421
433
|
plugins: config.plugins,
|
|
422
434
|
},
|
|
423
435
|
trace: {
|
|
424
|
-
traceId,
|
|
436
|
+
traceId: params?.traceId,
|
|
425
437
|
sessionId: get().activeId,
|
|
426
438
|
topicId: get().activeTopicId,
|
|
427
439
|
traceName: TraceNameMap.Conversation,
|
|
428
440
|
},
|
|
441
|
+
isWelcomeQuestion: params?.isWelcomeQuestion,
|
|
429
442
|
onErrorHandle: async (error) => {
|
|
430
443
|
await messageService.updateMessageError(assistantId, error);
|
|
431
444
|
await refreshMessages();
|
|
@@ -567,7 +580,7 @@ export const chatMessage: StateCreator<
|
|
|
567
580
|
|
|
568
581
|
if (!latestMsg) return;
|
|
569
582
|
|
|
570
|
-
await coreProcessMessage(contextMessages, latestMsg.id, traceId);
|
|
583
|
+
await coreProcessMessage(contextMessages, latestMsg.id, { traceId });
|
|
571
584
|
},
|
|
572
585
|
|
|
573
586
|
internalUpdateMessageContent: async (id, content) => {
|
|
@@ -225,7 +225,7 @@ describe('chatSelectors', () => {
|
|
|
225
225
|
|
|
226
226
|
const chats = chatSelectors.currentChatsWithGuideMessage(metaData)(state);
|
|
227
227
|
|
|
228
|
-
expect(chats[0].content).toEqual('
|
|
228
|
+
expect(chats[0].content).toEqual(''); // Assuming translation returns a string containing this
|
|
229
229
|
});
|
|
230
230
|
|
|
231
231
|
it('should use agent default message for non-inbox sessions', () => {
|
|
@@ -260,4 +260,30 @@ describe('chatSelectors', () => {
|
|
|
260
260
|
vi.restoreAllMocks();
|
|
261
261
|
});
|
|
262
262
|
});
|
|
263
|
+
|
|
264
|
+
describe('showInboxWelcome', () => {
|
|
265
|
+
it('should return false if the active session is not the inbox session', () => {
|
|
266
|
+
const state = merge(initialStore, { activeId: 'someActiveId' });
|
|
267
|
+
const result = chatSelectors.showInboxWelcome(state);
|
|
268
|
+
expect(result).toBe(false);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('should return false if there are existing messages in the inbox session', () => {
|
|
272
|
+
const state = merge(initialStore, {
|
|
273
|
+
activeId: INBOX_SESSION_ID,
|
|
274
|
+
messages: mockMessages,
|
|
275
|
+
});
|
|
276
|
+
const result = chatSelectors.showInboxWelcome(state);
|
|
277
|
+
expect(result).toBe(false);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('should return true if the active session is the inbox session and there are no existing messages', () => {
|
|
281
|
+
const state = merge(initialStore, {
|
|
282
|
+
activeId: INBOX_SESSION_ID,
|
|
283
|
+
messages: [],
|
|
284
|
+
});
|
|
285
|
+
const result = chatSelectors.showInboxWelcome(state);
|
|
286
|
+
expect(result).toBe(true);
|
|
287
|
+
});
|
|
288
|
+
});
|
|
263
289
|
});
|
|
@@ -52,6 +52,15 @@ const currentChats = (s: ChatStore): ChatMessage[] => {
|
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
const initTime = Date.now();
|
|
55
|
+
|
|
56
|
+
const showInboxWelcome = (s: ChatStore): boolean => {
|
|
57
|
+
const isInbox = s.activeId === INBOX_SESSION_ID;
|
|
58
|
+
if (!isInbox) return false;
|
|
59
|
+
const data = currentChats(s);
|
|
60
|
+
const isBrandNewChat = data.length === 0;
|
|
61
|
+
return isBrandNewChat;
|
|
62
|
+
};
|
|
63
|
+
|
|
55
64
|
// 针对新助手添加初始化时的自定义消息
|
|
56
65
|
const currentChatsWithGuideMessage =
|
|
57
66
|
(meta: MetaData) =>
|
|
@@ -64,7 +73,7 @@ const currentChatsWithGuideMessage =
|
|
|
64
73
|
|
|
65
74
|
const [activeId, isInbox] = [s.activeId, s.activeId === INBOX_SESSION_ID];
|
|
66
75
|
|
|
67
|
-
const inboxMsg =
|
|
76
|
+
const inboxMsg = '';
|
|
68
77
|
const agentSystemRoleMsg = t('agentDefaultMessageWithSystemRole', {
|
|
69
78
|
name: meta.title || t('defaultAgent'),
|
|
70
79
|
ns: 'chat',
|
|
@@ -137,4 +146,5 @@ export const chatSelectors = {
|
|
|
137
146
|
getMessageById,
|
|
138
147
|
getTraceIdByMessageId,
|
|
139
148
|
latestMessage,
|
|
149
|
+
showInboxWelcome,
|
|
140
150
|
};
|
|
@@ -174,7 +174,7 @@ export const chatPlugin: StateCreator<
|
|
|
174
174
|
triggerAIMessage: async (id, traceId) => {
|
|
175
175
|
const { coreProcessMessage } = get();
|
|
176
176
|
const chats = chatSelectors.currentChats(get());
|
|
177
|
-
await coreProcessMessage(chats, id, traceId);
|
|
177
|
+
await coreProcessMessage(chats, id, { traceId });
|
|
178
178
|
},
|
|
179
179
|
|
|
180
180
|
triggerFunctionCall: async (id) => {
|