/**
 * BRAIN 積木 - AI 處理器介面
 * 用途: LLM Router, RAG, Triage, MCP Bridge
 */

import type { LeWOOOgoPlugin } from './plugin'

/**
 * Agent 能力類型
 */
export type AgentCapability =
  | 'chat'
  | 'completion'
  | 'embedding'
  | 'tool_use'
  | 'vision'
  | 'code_generation'

/**
 * Agent 輸入
 */
export interface AgentInput {
  conversationId?: string
  message: string
  context?: Record<string, unknown>
  tools?: AgentTool[]
}

/**
 * Agent 工具定義
 */
export interface AgentTool {
  name: string
  description: string
  parameters: Record<string, unknown>
}

/**
 * Agent 輸出
 */
export interface AgentOutput {
  message: string
  conversationId: string
  toolCalls?: AgentToolCall[]
  requiresApproval?: boolean
  suggestedAction?: SuggestedAction
  metadata?: Record<string, unknown>
}

/**
 * 工具調用
 */
export interface AgentToolCall {
  toolName: string
  arguments: Record<string, unknown>
  result?: unknown
}

/**
 * 建議的操作
 */
export interface SuggestedAction {
  id: string
  label: string
  description?: string
  riskLevel: 'low' | 'medium' | 'high' | 'critical'
  parameters?: Record<string, unknown>
}

/**
 * BRAIN AI 處理器 Plugin
 */
export interface AgentProvider extends LeWOOOgoPlugin {
  category: 'BRAIN'

  /**
   * 處理 Agent 請求
   */
  process(input: AgentInput): Promise<AgentOutput>

  /**
   * 串流處理 (可選)
   */
  processStream?(
    input: AgentInput,
    onChunk: (chunk: string) => void
  ): Promise<AgentOutput>

  /**
   * 取得支援的能力
   */
  getCapabilities(): AgentCapability[]
}
