fix(chat): 修改回复不流式输出,回退useChat.ts

This commit is contained in:
sophie committed 2026-06-24 17:24:24 +08:00
1 parent b89d93d738
commit 1bd9f278fe
1 file changed
+11 -10
@@ -210,20 +210,19 @@ export function useChat() {
activeRunId.value = run.runId; activeRunId.value = run.runId;
runMessages.push({ role: 'user', content: query }); runMessages.push({ role: 'user', content: query });
let botMsgRef: ChatMessage | null = null; let botMsgIndex: number | null = null;
let hasAssistantContent = false; let hasAssistantContent = false;
let hasTerminalEvent = false; let hasTerminalEvent = false;
const ensureBotMessage = () => { const ensureBotMessage = () => {
if (!botMsgRef) { if (botMsgIndex === null) {
botMsgRef = { botMsgIndex = runMessages.push({
role: 'assistant', role: 'assistant',
content: '', content: '',
retriever_resources: [], retriever_resources: [],
attribution_parts: [], attribution_parts: [],
}; }) - 1;
runMessages.push(botMsgRef);
} }
return botMsgRef; return runMessages[botMsgIndex] || null;
}; };
isThinking.value = true; isThinking.value = true;
@@ -299,8 +298,9 @@ export function useChat() {
botMsg.content += normalizeStreamText(data.answer); botMsg.content += normalizeStreamText(data.answer);
hasAssistantContent = true; hasAssistantContent = true;
} }
if (botMsgRef) { if (botMsgIndex !== null) {
applyEventMetadata(botMsgRef, data); const currentBotMsg = runMessages[botMsgIndex];
if (currentBotMsg) applyEventMetadata(currentBotMsg, data);
} }
} else if (eventName === 'message_end' || eventName === 'workflow_finished') { } else if (eventName === 'message_end' || eventName === 'workflow_finished') {
hasTerminalEvent = true; hasTerminalEvent = true;
@@ -324,8 +324,9 @@ export function useChat() {
botMsg.content += normalizedAnswer; botMsg.content += normalizedAnswer;
} }
} }
if (botMsgRef) { if (botMsgIndex !== null) {
applyEventMetadata(botMsgRef, data); const currentBotMsg = runMessages[botMsgIndex];
if (currentBotMsg) applyEventMetadata(currentBotMsg, data);
} }
} else if (eventName === 'error') { } else if (eventName === 'error') {
const botMsg = ensureBotMessage(); const botMsg = ensureBotMessage();