From 1bd9f278fedcae3587e34809fa55b176bdea9040 Mon Sep 17 00:00:00 2001 From: sophie Date: Wed, 24 Jun 2026 17:24:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(chat):=20=E4=BF=AE=E6=94=B9=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D=E4=B8=8D=E6=B5=81=E5=BC=8F=E8=BE=93=E5=87=BA=EF=BC=8C?= =?UTF-8?q?=E5=9B=9E=E9=80=80useChat.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/features/chat/composables/useChat.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/frontend/src/features/chat/composables/useChat.ts b/frontend/src/features/chat/composables/useChat.ts index 2c38d5bd..5a4415a0 100644 --- a/frontend/src/features/chat/composables/useChat.ts +++ b/frontend/src/features/chat/composables/useChat.ts @@ -210,20 +210,19 @@ export function useChat() { activeRunId.value = run.runId; runMessages.push({ role: 'user', content: query }); - let botMsgRef: ChatMessage | null = null; + let botMsgIndex: number | null = null; let hasAssistantContent = false; let hasTerminalEvent = false; const ensureBotMessage = () => { - if (!botMsgRef) { - botMsgRef = { + if (botMsgIndex === null) { + botMsgIndex = runMessages.push({ role: 'assistant', content: '', retriever_resources: [], attribution_parts: [], - }; - runMessages.push(botMsgRef); + }) - 1; } - return botMsgRef; + return runMessages[botMsgIndex] || null; }; isThinking.value = true; @@ -299,8 +298,9 @@ export function useChat() { botMsg.content += normalizeStreamText(data.answer); hasAssistantContent = true; } - if (botMsgRef) { - applyEventMetadata(botMsgRef, data); + if (botMsgIndex !== null) { + const currentBotMsg = runMessages[botMsgIndex]; + if (currentBotMsg) applyEventMetadata(currentBotMsg, data); } } else if (eventName === 'message_end' || eventName === 'workflow_finished') { hasTerminalEvent = true; @@ -324,8 +324,9 @@ export function useChat() { botMsg.content += normalizedAnswer; } } - if (botMsgRef) { - applyEventMetadata(botMsgRef, data); + if (botMsgIndex !== null) { + const currentBotMsg = runMessages[botMsgIndex]; + if (currentBotMsg) applyEventMetadata(currentBotMsg, data); } } else if (eventName === 'error') { const botMsg = ensureBotMessage();