MCPcopy Create free account
hub / github.com/astercloud/aster / handleAgentEvent

Function handleAgentEvent

ui/src/composables/useChat.ts:271–495  ·  view source on GitHub ↗
(type: string, ev: any, messageId?: string)

Source from the content-addressed store, hash-verified

269 };
270
271 const handleAgentEvent = (type: string, ev: any, messageId?: string) => {
272 // 获取当前活跃消息 ID (如果没有提供)
273 const currentMessageId = messageId || chatStore.activeMessageId || "";
274
275 // 1. 思维事件 → thinkingStore
276 if (type === "think_chunk_start") {
277 thinkingStore.startThinking(currentMessageId);
278 chatStore.setActiveMessage(currentMessageId);
279 return;
280 }
281 if (type === "think_chunk") {
282 thinkingStore.handleThinkChunk(ev.delta || ev.content || "");
283 return;
284 }
285 if (type === "think_chunk_end") {
286 thinkingStore.endThinking();
287 return;
288 }
289
290 // 2. 工具事件 → toolsStore + thinkingStore
291 if (type === "tool:start" || type === "tool_call_start" || (type.startsWith("tool") && type.includes("start"))) {
292 const call = ev.Call || ev.call || {};
293 const toolCall = {
294 id: call.id || call.ID || call.tool_call_id || generateId("tool"),
295 name: call.name || "unknown",
296 state: "executing" as const,
297 progress: 0,
298 arguments: call.arguments || {},
299 cancelable: call.cancelable ?? false,
300 pausable: call.pausable ?? false,
301 };
302
303 toolsStore.handleToolStart(toolCall);
304
305 // 同时添加到思维步骤
306 thinkingStore.addStep(currentMessageId, {
307 type: "tool_call",
308 tool: {
309 name: toolCall.name,
310 args: toolCall.arguments,
311 },
312 timestamp: Date.now(),
313 });
314 return;
315 }
316
317 if (type === "tool:progress" || type === "tool_call_progress" || (type.startsWith("tool") && type.includes("progress"))) {
318 const call = ev.Call || ev.call || {};
319 const id = call.id || call.ID || call.tool_call_id;
320 if (id) {
321 toolsStore.handleToolProgress(id, ev.progress ?? call.progress ?? 0, ev.message || "");
322 }
323 return;
324 }
325
326 if (type === "tool:end" || type === "tool_call_end" || (type.startsWith("tool") && type.includes("end"))) {
327 const call = ev.Call || ev.call || {};
328 const id = call.id || call.ID || call.tool_call_id;

Callers 1

sendMessageFunction · 0.70

Calls 3

generateIdFunction · 0.90
handleToolProgressMethod · 0.80
logMethod · 0.80

Tested by

no test coverage detected