From f17ab497722478943814533ff9f1c8afd515c2da Mon Sep 17 00:00:00 2001 From: Arvin Xu Date: Mon, 14 Oct 2024 02:58:10 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20fix=20images=20not=20go?= =?UTF-8?q?=20in=20to=20chat=20context=20(#4361)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 💡 chore: add jsdoc * 🐛 fix: fix the image not in ai chat message * 💡 chore: add jsdoc * 🐛 fix: fix --- .../Conversation/components/SkeletonList.tsx | 2 +- src/store/chat/slices/aiChat/action.ts | 45 ++++++++++--------- src/store/chat/slices/message/action.ts | 1 + src/store/chat/utils/index.ts | 2 +- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/features/Conversation/components/SkeletonList.tsx b/src/features/Conversation/components/SkeletonList.tsx index d3ec5e868d28..2570e87bfa64 100644 --- a/src/features/Conversation/components/SkeletonList.tsx +++ b/src/features/Conversation/components/SkeletonList.tsx @@ -30,7 +30,7 @@ const SkeletonList = memo(({ mobile }) => { const { cx, styles } = useStyles(); return ( - + Promise; /** - * regenerate message - * trace enabled - * @param id + * Regenerates a specific message in the chat */ regenerateMessage: (id: string) => Promise; - - // delete + /** + * Deletes an existing message and generates a new one in its place + */ delAndRegenerateMessage: (id: string) => Promise; + /** + * Interrupts the ongoing ai message generation process + */ stopGenerateMessage: () => void; // ========= ↓ Internal Method ↓ ========== // @@ -65,7 +69,8 @@ export interface ChatAIChatAction extends ChatRAGAction { // ========================================== // /** - * core process of the AI message (include preprocess and postprocess) + * Executes the core processing logic for AI messages + * including preprocessing and postprocessing steps */ internal_coreProcessMessage: ( messages: ChatMessage[], @@ -73,7 +78,7 @@ export interface ChatAIChatAction extends ChatRAGAction { params?: ProcessMessageParams, ) => Promise; /** - * the method to fetch the AI message + * Retrieves an AI-generated chat message from the backend service */ internal_fetchAIChatMessage: ( messages: ChatMessage[], @@ -83,11 +88,12 @@ export interface ChatAIChatAction extends ChatRAGAction { isFunctionCall: boolean; traceId?: string; }>; - + /** + * Resends a specific message, optionally using a trace ID for tracking + */ internal_resendMessage: (id: string, traceId?: string) => Promise; - /** - * method to toggle ai message generating loading + * Toggles the loading state for AI message generation, managing the UI feedback */ internal_toggleChatLoading: ( loading: boolean, @@ -95,7 +101,7 @@ export interface ChatAIChatAction extends ChatRAGAction { action?: string, ) => AbortController | undefined; /** - * method to toggle the tool calling loading state + * Controls the streaming state of tool calling processes, updating the UI accordingly */ internal_toggleToolCallingStreaming: (id: string, streaming: boolean[] | undefined) => void; } @@ -139,7 +145,7 @@ export const chatAiChat: StateCreator< // if message is empty or no files, then stop if (!message && !hasFile) return; - set({ isCreatingMessage: true }, false, 'creatingMessage/start'); + set({ isCreatingMessage: true }, false, n('creatingMessage/start')); const newMessage: CreateMessageParams = { content: message, @@ -184,10 +190,7 @@ export const chatAiChat: StateCreator< ...get().messagesMap, [messageMapKey(activeId, topicId)]: get().messagesMap[mapKey], }; - set({ messagesMap: newMaps }, false, 'internal_copyMessages'); - - // get().internal_dispatchMessage({ type: 'deleteMessage', id: tempMessageId }); - get().internal_toggleMessageLoading(false, tempMessageId); + set({ messagesMap: newMaps }, false, n('moveMessagesToNewTopic')); // make the topic loading get().internal_updateTopicLoading(topicId, true); @@ -199,9 +202,11 @@ export const chatAiChat: StateCreator< const id = await get().internal_createMessage(newMessage, { tempMessageId, - skipRefresh: !onlyAddUserMessage, + skipRefresh: !onlyAddUserMessage && newMessage.fileList?.length === 0, }); + if (tempMessageId) get().internal_toggleMessageLoading(false, tempMessageId); + // switch to the new topic if create the new topic if (!!newTopicId) { await get().switchTopic(newTopicId, true); @@ -228,7 +233,7 @@ export const chatAiChat: StateCreator< ragQuery: get().internal_shouldUseRAG() ? message : undefined, }); - set({ isCreatingMessage: false }, false, 'creatingMessage/stop'); + set({ isCreatingMessage: false }, false, n('creatingMessage/stop')); const summaryTitle = async () => { // if autoCreateTopic is false, then stop diff --git a/src/store/chat/slices/message/action.ts b/src/store/chat/slices/message/action.ts index 14a6857bad6c..969b10514869 100644 --- a/src/store/chat/slices/message/action.ts +++ b/src/store/chat/slices/message/action.ts @@ -301,6 +301,7 @@ export const chatMessage: StateCreator< const id = await messageService.createMessage(message); if (!context?.skipRefresh) { + internal_toggleMessageLoading(true, tempId); await refreshMessages(); } diff --git a/src/store/chat/utils/index.ts b/src/store/chat/utils/index.ts index 889bc3919fff..87450fa30f3c 100644 --- a/src/store/chat/utils/index.ts +++ b/src/store/chat/utils/index.ts @@ -9,7 +9,7 @@ export const preventLeavingFn = (e: BeforeUnloadEvent) => { export const toggleBooleanList = (ids: string[], id: string, loading: boolean) => { return produce(ids, (draft) => { if (loading) { - draft.push(id); + if (!draft.includes(id)) draft.push(id); } else { const index = draft.indexOf(id);