// 多 Agent 协作系统 - 类型定义

export type AgentType = 'planner' | 'browser' | 'file' | 'terminal' | 'combiner' | 'custom';
export type AgentStatus = 'idle' | 'busy' | 'error' | 'terminated';

export interface AgentConfig {
  name?: string;
  systemPrompt?: string;
  model?: string;
  maxRetries?: number;
  timeout?: number;
}

export interface AgentInfo {
  id: string;
  type: AgentType;
  name: string;
  status: AgentStatus;
  capabilities: string[];
  currentTaskId?: string;
  createdAt: Date;
}

export interface AgentTask {
  id: string;
  type: string;
  description: string;
  params: Record<string, any>;
  context: Record<string, any>;
  dependencies: string[];
}

export interface AgentResult {
  taskId: string;
  agentId: string;
  success: boolean;
  data?: any;
  error?: string;
  duration: number;
}

// 消息总线
export interface AgentMessage {
  id: string;
  from: string;
  to: string;       // agent ID 或 '*' 表示广播
  type: 'task' | 'result' | 'status' | 'data' | 'error' | 'control';
  payload: any;
  timestamp: Date;
}

export type MessageHandler = (message: AgentMessage) => void | Promise<void>;

// 多 Agent 任务
export interface MultiAgentPlan {
  id: string;
  goal: string;
  steps: AgentTask[];
  agentAssignments: Map<string, string>; // taskId -> agentId
  status: 'planning' | 'executing' | 'completed' | 'failed';
  results: AgentResult[];
  createdAt: Date;
}
