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 格式) ============== /**