feat: 前端添加 SSE 事件诊断日志,确认 originalQuery 传递

This commit is contained in:
2026-07-21 23:43:48 +08:00
parent adeaa7a506
commit 748fc18c84
+43 -1
View File
@@ -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)