From 082ef923b2c82a31e7504f46175d5c91e52ec3d3 Mon Sep 17 00:00:00 2001 From: XiaoFeng <117837368+Fzhiyu1@users.noreply.github.com> Date: Mon, 29 Dec 2025 09:22:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=99=BA=E8=83=BD?= =?UTF-8?q?=E4=BD=93=E4=BA=8B=E4=BB=B6=E7=B1=BB=E5=9E=8B=E5=92=8CSSE?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - api.ts 添加4个智能体事件类型定义 - sseHandler.ts 添加智能体事件回调和分发 --- src/services/sseHandler.ts | 26 ++++++++++++++++++++++- src/types/api.ts | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/services/sseHandler.ts b/src/services/sseHandler.ts index 7bae62a..b6aba4b 100644 --- a/src/services/sseHandler.ts +++ b/src/services/sseHandler.ts @@ -21,7 +21,11 @@ import type { ToolErrorEvent, WarningEvent, NotificationEvent, - DepthUpdateEvent + DepthUpdateEvent, + AgentStartEvent, + AgentProgressEvent, + AgentCompleteEvent, + AgentErrorEvent } from '../types/api'; /** @@ -50,6 +54,14 @@ export interface SSECallbacks { onNotification?: (data: NotificationEvent) => void; /** 深度更新 */ onDepthUpdate?: (data: DepthUpdateEvent) => void; + /** 子智能体启动 */ + onAgentStart?: (data: AgentStartEvent) => void; + /** 子智能体进度 */ + onAgentProgress?: (data: AgentProgressEvent) => void; + /** 子智能体完成 */ + onAgentComplete?: (data: AgentCompleteEvent) => void; + /** 子智能体错误 */ + onAgentError?: (data: AgentErrorEvent) => void; /** 连接打开 */ onOpen?: () => void; /** 连接关闭 */ @@ -283,6 +295,18 @@ function dispatchEvent( case 'depth_update': callbacks.onDepthUpdate?.(data as DepthUpdateEvent); break; + case 'agent_start': + callbacks.onAgentStart?.(data as AgentStartEvent); + break; + case 'agent_progress': + callbacks.onAgentProgress?.(data as AgentProgressEvent); + break; + case 'agent_complete': + callbacks.onAgentComplete?.(data as AgentCompleteEvent); + break; + case 'agent_error': + callbacks.onAgentError?.(data as AgentErrorEvent); + break; default: console.log(`[SSE] 未知事件类型: ${eventType}`, data); } diff --git a/src/types/api.ts b/src/types/api.ts index 7927f4f..5b8c514 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -30,6 +30,10 @@ export type SSEEventType = | 'tool_complete' // 工具执行完成 | 'tool_error' // 工具执行错误 | 'ask_user' // 向用户提问 + | 'agent_start' // 子智能体启动 + | 'agent_progress' // 子智能体进度 + | 'agent_complete' // 子智能体完成 + | 'agent_error' // 子智能体错误 | 'complete' // 对话完成 | 'error' // 错误 | 'warning' // 警告 @@ -92,6 +96,45 @@ export interface DepthUpdateEvent { depth: number; } +// ============== 智能体事件类型 ============== + +/** agent_start 事件数据 */ +export interface AgentStartEvent { + agentId: string; + agentType: string; + agentName: string; + instruction: string; + timestamp: number; +} + +/** agent_progress 事件数据 */ +export interface AgentProgressEvent { + agentId: string; + step: number; + toolName: string; + toolInput?: unknown; + toolResult?: string; + status: 'running' | 'completed' | 'error'; + timestamp: number; +} + +/** agent_complete 事件数据 */ +export interface AgentCompleteEvent { + agentId: string; + agentType: string; + summary: string; + stats: Record; + timestamp: number; +} + +/** agent_error 事件数据 */ +export interface AgentErrorEvent { + agentId: string; + agentType: string; + error: string; + timestamp: number; +} + // ============== 工具调用协议 (MCP 格式) ============== /**