From 82eab7ad8dbdebb81bde8fc569e9ded338ae1ebc Mon Sep 17 00:00:00 2001 From: oudecheng <13802883547@139.com> Date: Thu, 18 Jun 2026 17:50:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(useChat):=20=E4=BF=AE=E5=A4=8D=20task=5Fsta?= =?UTF-8?q?rted=20=E4=BA=8B=E4=BB=B6=E8=BF=87=E6=BB=A4=E5=8F=8A=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 增加 task_started 消息的调试日志,输出 task_id、topic_id、parent_task_id 和当前选中的话题 - 对 topic_id 不匹配的 task_started 消息进行过滤,并打印日志提示 - 对带有 parent_task_id 的孙智能体 TaskStarted 消息进行过滤,避免回填主视图,并打印日志 - 在更新消息状态时添加日志,记录查找 task tool_call 消息的数量及索引 - 处理未找到匹配 task tool_call 的情况并打印对应日志 --- web/src/hooks/useChat.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/web/src/hooks/useChat.ts b/web/src/hooks/useChat.ts index 28f3496..69f5614 100644 --- a/web/src/hooks/useChat.ts +++ b/web/src/hooks/useChat.ts @@ -445,20 +445,30 @@ export function useChat(): UseChatReturn { case 'task_started': { const msg = message as TaskStarted + console.log('[useChat] task_started received:', { task_id: msg.task_id, topic_id: msg.topic_id, parent_task_id: msg.parent_task_id, selectedTopic: selectedTopicRef.current }) // 只 backfill 当前话题的 task tool_call,避免跨话题串扰 - if (msg.topic_id && msg.topic_id !== selectedTopicRef.current) break + if (msg.topic_id && msg.topic_id !== selectedTopicRef.current) { + console.log('[useChat] task_started filtered by topic_id') + break + } // 孙智能体的 TaskStarted 不应 backfill 到主视图 - if (msg.parent_task_id) break + if (msg.parent_task_id) { + console.log('[useChat] task_started filtered by parent_task_id') + break + } // 设置 navigateToTaskId,让用户可以点击查看实时进度 setMessages((prev) => { + console.log('[useChat] task_started searching messages for task tool_call, total messages:', prev.length) for (let i = prev.length - 1; i >= 0; i--) { if (prev[i].type === 'tool_call' && prev[i].toolName === 'task' && !prev[i].navigateToTaskId) { + console.log('[useChat] task_started SET navigateToTaskId at index', i, 'task_id:', msg.task_id) const updated = [...prev] updated[i] = { ...updated[i], navigateToTaskId: msg.task_id } return updated } } + console.log('[useChat] task_started NO matching task tool_call found in messages') return prev }) break