From 748fc18c847358ce93aa0e747055610786ebc303 Mon Sep 17 00:00:00 2001 From: Peanut Date: Tue, 21 Jul 2026 23:43:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=89=8D=E7=AB=AF=E6=B7=BB=E5=8A=A0=20?= =?UTF-8?q?SSE=20=E4=BA=8B=E4=BB=B6=E8=AF=8A=E6=96=AD=E6=97=A5=E5=BF=97?= =?UTF-8?q?=EF=BC=8C=E7=A1=AE=E8=AE=A4=20originalQuery=20=E4=BC=A0?= =?UTF-8?q?=E9=80=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mini-program/src/pages/main/ScriptView.vue | 44 +++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/mini-program/src/pages/main/ScriptView.vue b/mini-program/src/pages/main/ScriptView.vue index f2c268e..0eac66d 100644 --- a/mini-program/src/pages/main/ScriptView.vue +++ b/mini-program/src/pages/main/ScriptView.vue @@ -288,6 +288,7 @@ const conversationId = ref('') const currentVersionMessageId = ref('') // 短篇小说 SSE 流式生成新增字段 const novelSessionId = ref('') +const firstQuery = ref('') // 首次发送的原始心愿,用于保存剧本时记录 const novelFullText = ref('') const novelOutline = ref(null) const clarificationCard = ref(null) @@ -1646,6 +1647,8 @@ const runGeneration = async ({ prompt, displayText, source = 'text', saveTheme } novelOutline.value = null clarificationCard.value = null novelSessionId.value = '' + firstQuery.value = text // 记住首次心愿,用于后续 followup 保存剧本 + console.log('[ScriptView] 设置 firstQuery:', { text, length: text.length }) pendingNextResponse.value = true // 标记等待下一个 assistant 响应 resumeableSessionId.value = '' outlineFeedback.value = '' @@ -1688,6 +1691,10 @@ const runGeneration = async ({ prompt, displayText, source = 'text', saveTheme } const handleShortNovelEvent = (event) => { const { type, session_id, payload = {} } = event + const timestamp = Date.now() + + console.log('[ScriptView] 收到事件:', { type, session_id, timestamp, payload }) + if (session_id) novelSessionId.value = session_id switch (type) { @@ -1714,13 +1721,24 @@ const handleShortNovelEvent = (event) => { // 往最后一条 pending novel 消息直接累加 delta,保证流式显示 const lastNovel = [...resultMessages.value].reverse().find(m => m.kind === 'novel' && m.pending) if (lastNovel) { - lastNovel.content += payload.delta || '' + const delta = payload.delta || '' + console.log('[ScriptView] novel_delta:', { + deltaLength: delta.length, + currentLength: lastNovel.content.length, + timestamp + }) + lastNovel.content += delta } keepResultAtBottom() break } case 'novel_done': { // 标记最后一条 novel 消息完成 + console.log('[ScriptView] novel_done:', { + scriptId: payload.scriptId, + hasFullText: !!payload.full_text, + timestamp + }) const lastNovel = [...resultMessages.value].reverse().find(m => m.kind === 'novel') if (lastNovel) { if (payload.full_text) lastNovel.content = payload.full_text @@ -1763,10 +1781,16 @@ const submitClarification = (answer) => { } pendingNextResponse.value = true // 标记等待下一个 assistant 响应 answeringClarification.value = true + console.log('[ScriptView] submitClarification:', { + sessionId: novelSessionId.value, + originalQuery: firstQuery.value, + originalQueryLength: firstQuery.value?.length + }) currentStreamTask.value = followupStream({ sessionId: novelSessionId.value, action: 'answer_clarification', payload: { answer }, // 后端仍收 value + originalQuery: firstQuery.value, // 首次心愿文本,用于后续 novel_done 保存 onEvent: handleShortNovelEvent, onError: (errMsg) => markGenerationFailed(errMsg) }) @@ -1777,10 +1801,16 @@ const confirmOutline = (msg) => { if (msg) msg.confirmed = true pendingNextResponse.value = true addResultMessage({ role: 'user', kind: 'text', content: '确认大纲' }) + console.log('[ScriptView] confirmOutline:', { + sessionId: novelSessionId.value, + originalQuery: firstQuery.value, + originalQueryLength: firstQuery.value?.length + }) currentStreamTask.value = followupStream({ sessionId: novelSessionId.value, action: 'confirm_outline', payload: null, + originalQuery: firstQuery.value, onEvent: handleShortNovelEvent, onError: (errMsg) => markGenerationFailed(errMsg) }) @@ -1795,10 +1825,16 @@ const modifyOutline = (msg) => { if (msg) msg.confirmed = true pendingNextResponse.value = true addResultMessage({ role: 'user', kind: 'text', content: feedback }) + console.log('[ScriptView] modifyOutline:', { + sessionId: novelSessionId.value, + originalQuery: firstQuery.value, + originalQueryLength: firstQuery.value?.length + }) currentStreamTask.value = followupStream({ sessionId: novelSessionId.value, action: 'modify_outline', payload: { feedback }, + originalQuery: firstQuery.value, onEvent: handleShortNovelEvent, onError: (errMsg) => markGenerationFailed(errMsg) }) @@ -1818,10 +1854,16 @@ const resumeSession = () => { keepResultAtBottom() try { + console.log('[ScriptView] resumeSession:', { + sessionId: novelSessionId.value, + originalQuery: firstQuery.value, + originalQueryLength: firstQuery.value?.length + }) currentStreamTask.value = followupStream({ sessionId: novelSessionId.value, action: 'retry', payload: null, + originalQuery: firstQuery.value, onEvent: handleShortNovelEvent, onError: (errMsg) => { markGenerationFailed(errMsg)