(type: string, ev: any, messageId?: string)
| 76 | * 处理 Agent 事件(统一分发) |
| 77 | */ |
| 78 | const handleAgentEvent = (type: string, ev: any, messageId?: string) => { |
| 79 | const currentMessageId = messageId || chatStore.lastAssistantMessage?.id || ""; |
| 80 | |
| 81 | // === 思维事件 === |
| 82 | if (type === "think_chunk_start") { |
| 83 | thinkingStore.startThinking(currentMessageId); |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | if (type === "think_chunk") { |
| 88 | thinkingStore.handleThinkChunk(ev.delta || ""); |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | if (type === "think_chunk_end") { |
| 93 | thinkingStore.endThinking(); |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | // === 工具事件 === |
| 98 | if (type === "tool:start") { |
| 99 | const call = ev.Call || ev.call || {}; |
| 100 | toolsStore.handleToolStart(call); |
| 101 | // 添加工具调用步骤到思维块 |
| 102 | if (currentMessageId) { |
| 103 | thinkingStore.addToolCallStep(currentMessageId, call.name, call.arguments); |
| 104 | } |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | if (type === "tool:progress") { |
| 109 | const call = ev.Call || ev.call || {}; |
| 110 | toolsStore.handleToolProgress(call.id || call.ID, ev.progress ?? call.progress ?? 0, ev.message, ev.metadata); |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | if (type === "tool:intermediate") { |
| 115 | const call = ev.Call || ev.call || {}; |
| 116 | toolsStore.handleToolIntermediate(call.id || call.ID, ev.label || "", ev.data); |
| 117 | return; |
| 118 | } |
| 119 | |
| 120 | if (type === "tool:end") { |
| 121 | const call = ev.Call || ev.call || {}; |
| 122 | toolsStore.handleToolEnd(call); |
| 123 | // 添加工具结果步骤到思维块 |
| 124 | if (currentMessageId) { |
| 125 | thinkingStore.addToolResultStep(currentMessageId, call.result); |
| 126 | } |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | if (type === "tool:error") { |
| 131 | const call = ev.Call || ev.call || {}; |
| 132 | toolsStore.handleToolError(call.id || call.ID, ev.error || call.error); |
| 133 | return; |
| 134 | } |
| 135 |
no test coverage detected