From d02848d1e1ec6ab8ee0e2b4d6e1983b5407328e1 Mon Sep 17 00:00:00 2001 From: empty Date: Thu, 8 Jan 2026 11:28:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=B5=81=E5=BC=8F?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E4=B8=8D=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E5=AE=9E=E6=97=B6=E8=A7=A3=E6=9E=90=20XML=20=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/app.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/stores/app.js b/src/stores/app.js index 3c30356..09e517e 100644 --- a/src/stores/app.js +++ b/src/stores/app.js @@ -126,10 +126,10 @@ export const useAppStore = defineStore('app', () => { console.log('Store: 开始 Ghostwriter Protocol 生成流程...') - // 流式接收并实时解析 XML 结构 + // 流式接收并实时解析 XML 结构,同时实时显示内容 await api.generateContent(userMessage, (chunk) => { rawStreamBuffer.value += chunk - const { section } = streamParser.process(chunk) + const { section, buffer } = streamParser.process(chunk) // 根据当前 section 更新 UI 状态 if (section === 'thinking' && generationStage.value !== 'thinking') { @@ -140,9 +140,26 @@ export const useAppStore = defineStore('app', () => { generationStage.value = 'draft' console.log('Store: 进入草稿生成阶段') } + + // 实时更新 UI 显示(流式输出) + // 提取当前已接收的 thinking 和 draft 内容 + const thinkingMatch = buffer.match(/([\s\S]*?)(?:<\/thinking>|$)/) + const draftMatch = buffer.match(/([\s\S]*?)(?:<\/draft>|$)/) + + if (thinkingMatch) { + thinkingContent.value = thinkingMatch[1].trim() + } + if (draftMatch) { + generatedContent.value = draftMatch[1].trim() + } + + // 如果 AI 没有按 XML 格式输出,直接显示原始内容 + if (!thinkingMatch && !draftMatch && buffer.length > 50) { + generatedContent.value = buffer + } }) - // 流式完成后,解析最终结果 + // 流式完成后,最终解析确保内容完整 const { thinking, draft, hasStructuredOutput } = streamParser.getResult() console.log('Store: XML 解析完成', { hasStructuredOutput, thinkingLength: thinking.length, draftLength: draft.length })