feat: 添加智能体事件类型和SSE处理
- api.ts 添加4个智能体事件类型定义 - sseHandler.ts 添加智能体事件回调和分发
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
@ -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<string, unknown>;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
/** agent_error 事件数据 */
|
||||
export interface AgentErrorEvent {
|
||||
agentId: string;
|
||||
agentType: string;
|
||||
error: string;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
// ============== 工具调用协议 (MCP 格式) ==============
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user