fix(useChat): 修复 task_started 事件过滤及日志输出

- 增加 task_started 消息的调试日志,输出 task_id、topic_id、parent_task_id 和当前选中的话题
- 对 topic_id 不匹配的 task_started 消息进行过滤,并打印日志提示
- 对带有 parent_task_id 的孙智能体 TaskStarted 消息进行过滤,避免回填主视图,并打印日志
- 在更新消息状态时添加日志,记录查找 task tool_call 消息的数量及索引
- 处理未找到匹配 task tool_call 的情况并打印对应日志
This commit is contained in:
oudecheng 2026-06-18 17:50:44 +08:00
parent edc975e6d0
commit 82eab7ad8d

View File

@ -445,20 +445,30 @@ export function useChat(): UseChatReturn {
case 'task_started': { case 'task_started': {
const msg = message as TaskStarted 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避免跨话题串扰 // 只 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 到主视图 // 孙智能体的 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让用户可以点击查看实时进度 // 设置 navigateToTaskId让用户可以点击查看实时进度
setMessages((prev) => { 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--) { for (let i = prev.length - 1; i >= 0; i--) {
if (prev[i].type === 'tool_call' && prev[i].toolName === 'task' && !prev[i].navigateToTaskId) { 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] const updated = [...prev]
updated[i] = { ...updated[i], navigateToTaskId: msg.task_id } updated[i] = { ...updated[i], navigateToTaskId: msg.task_id }
return updated return updated
} }
} }
console.log('[useChat] task_started NO matching task tool_call found in messages')
return prev return prev
}) })
break break