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;
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();