From 04ff358dc700984b300dd0ac9efd2b747ad5ae4a Mon Sep 17 00:00:00 2001 From: BiggerRain <15911122312@163.COM> Date: Wed, 12 Mar 2025 14:24:24 +0800 Subject: [PATCH] fix: chat end type (#280) * fix: chat end type * docs: update release notes --- docs/content.en/docs/release-notes/_index.md | 1 + src-tauri/src/server/websocket.rs | 2 +- src/components/Assistant/Chat.tsx | 4 +++- src/components/ChatMessage/QueryIntent.tsx | 6 +++--- src/components/ChatMessage/markdown.css | 1 - src/hooks/useMessageHandler.ts | 15 +++++++-------- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/docs/content.en/docs/release-notes/_index.md b/docs/content.en/docs/release-notes/_index.md index b2ef81b5..24d52e1d 100644 --- a/docs/content.en/docs/release-notes/_index.md +++ b/docs/content.en/docs/release-notes/_index.md @@ -16,6 +16,7 @@ Information about release notes of Coco Server is provided here. ### Bug fix - Fix the issue that the fusion search include disabled servers - Fix incorrect version type: should be string instead of u32 +- Fix the chat end judgment type #280 ### Improvements diff --git a/src-tauri/src/server/websocket.rs b/src-tauri/src/server/websocket.rs index 75aa81d5..a736c4a7 100644 --- a/src-tauri/src/server/websocket.rs +++ b/src-tauri/src/server/websocket.rs @@ -128,7 +128,7 @@ pub async fn connect_to_server( msg = ws.next() => { match msg { Some(Ok(Message::Text(text))) => { - //println!("Received message: {}", text); + println!("Received message: {}", text); let _ = app_handle_clone.emit("ws-message", text); }, Some(Err(WsError::ConnectionClosed)) => { diff --git a/src/components/Assistant/Chat.tsx b/src/components/Assistant/Chat.tsx index 6d7f4b82..1cf67316 100644 --- a/src/components/Assistant/Chat.tsx +++ b/src/components/Assistant/Chat.tsx @@ -207,6 +207,8 @@ const ChatAI = memo( const onSelectChat = useCallback( async (chat: Chat) => { + setTimedoutShow(false); + setErrorShow(false); clearAllChunkData(); await cancelChat(activeChat); await chatClose(activeChat); @@ -320,7 +322,7 @@ const ChatAI = memo( timedoutShow={timedoutShow} errorShow={errorShow} Question={Question} - handleSendMessage={handleSendMessage} + handleSendMessage={(value) => handleSendMessage(value, activeChat)} /> ) : ( diff --git a/src/components/ChatMessage/QueryIntent.tsx b/src/components/ChatMessage/QueryIntent.tsx index 51107a06..d6900aac 100644 --- a/src/components/ChatMessage/QueryIntent.tsx +++ b/src/components/ChatMessage/QueryIntent.tsx @@ -108,7 +108,7 @@ export const QueryIntent = ({
{Data?.keyword?.map((keyword, index) => ( {keyword} @@ -144,8 +144,8 @@ export const QueryIntent = ({ - {t("assistant.message.steps.relatedQuestions")}:
- {Data?.query?.map((question) => ( - - {question} + {Data?.query?.map((question, qIndex) => ( + - {question} ))}
diff --git a/src/components/ChatMessage/markdown.css b/src/components/ChatMessage/markdown.css index 63b1bc20..7362c488 100644 --- a/src/components/ChatMessage/markdown.css +++ b/src/components/ChatMessage/markdown.css @@ -235,7 +235,6 @@ padding: 0; margin: 24px 0; background-color: var(--color-border-default); - border: 0; } .markdown-body input { diff --git a/src/hooks/useMessageHandler.ts b/src/hooks/useMessageHandler.ts index 56e37732..92e40ff0 100644 --- a/src/hooks/useMessageHandler.ts +++ b/src/hooks/useMessageHandler.ts @@ -33,13 +33,6 @@ export function useMessageHandler( onCancel(); }, 60000); - if (msg.includes("assistant finished output")) { - clearTimeout(messageTimeoutRef.current); - console.log("AI finished output"); - setCurChatEnd(true); - return; - } - const cleanedData = msg.replace(/^PRIVATE /, ""); try { const chunkData = JSON.parse(cleanedData); @@ -56,7 +49,6 @@ export function useMessageHandler( [chunkData.chunk_type]: true, })); - if (chunkData.chunk_type === "query_intent") { handlers.deal_query_intent(chunkData); } else if (chunkData.chunk_type === "fetch_source") { @@ -69,6 +61,13 @@ export function useMessageHandler( handlers.deal_think(chunkData); } else if (chunkData.chunk_type === "response") { handlers.deal_response(chunkData); + } else if (chunkData.chunk_type === "reply_end") { + if (messageTimeoutRef.current) { + clearTimeout(messageTimeoutRef.current); + } + setCurChatEnd(true); + console.log("AI finished output"); + return; } } catch (error) { console.error("parse error:", error);