/**
 * ACP (Agent-Client Protocol) type definitions for third-party agent management.
 *
 * These types define the contract for discovering, registering, and managing
 * external ACP-compatible agent CLIs alongside qlogicagent's internal agents.
 */
import type { AgentCapabilities, CustomAgentDef, AgentConfig, ProductTaskStatus, ProductInstanceDef, ProductTaskDef } from "./agent-methods.js";
export type { AgentCategory, AgentProtocol, AgentStatus, AgentCapabilities, AgentDescriptor, CustomAgentDef, AgentConfig, SoloState, SoloAgentState, SoloAgentResult, SoloStatus, ProductPhase, ProductTaskStatus, ProductInstanceDef, ProductTaskDef, ProductStatus, ProductSummary, } from "./agent-methods.js";
/** Pre-defined configuration for a known ACP backend. */
export interface AcpBackendConfig {
    /** Backend ID, e.g. "claude" | "codex" | "goose". */
    id: string;
    /** Display name. */
    name: string;
    /** CLI command name (target for which/where scan). */
    cliCommand: string;
    /** ACP mode launch arguments. */
    acpArgs: string[];
    /** npx fallback path when CLI is not in PATH. */
    defaultCliPath?: string;
    /** Environment variables injected at launch. */
    env?: Record<string, string>;
    /** Whether authentication is required. */
    authRequired: boolean;
    /** Native skill directories. */
    skillsDirs?: string[];
    /** Whether this backend supports base URL override. */
    supportsBaseUrlOverride: boolean;
    /** Environment variable name for the API key. */
    apiKeyEnvVar?: string;
    /** Environment variable name for the base URL. */
    baseUrlEnvVar?: string;
    /** Official-logo key for AgentBrandIcon. */
    brandId?: string;
    /** Real-world usage scenario for grouping in the discover UI (not a capability tag). */
    category?: "coding" | "writing" | "design" | "creative" | "research" | "assistant";
    /** How the agent is driven in-app: "acp" via the ACP adapter, "custom" via a dedicated non-ACP adapter. */
    integration?: "acp" | "custom";
    /** Where the injected key comes from: gateway-issued (llmrouter), the user's direct third-party key, or none (OAuth). */
    keySource?: "llmrouter" | "direct" | "none";
    /** Auth model: "key" = login-free key injection; "oauth" = no key bypass, user account required. */
    authMode?: "key" | "oauth";
    /** One-click install spec (official commands per platform). */
    install?: AgentInstallSpec;
    /** Short UI note (e.g. "需 GitHub 账号", "非 ACP,自定义适配器驱动"). */
    note?: string;
}
/** Official install commands for the one-click installer (no self-hosted CDN — runs upstream). */
export interface AgentInstallSpec {
    npm?: string;
    brew?: string;
    curl?: string;
    pip?: string;
    /** Executable name after install (probe target). */
    cliCommand: string;
    /** Probe command (default `<cliCommand> --version`). */
    verifyCmd?: string;
    /** Official docs / source URL (shown in the install confirmation). */
    docsUrl: string;
}
/**
 * Extended descriptor for external agents,
 * used internally by AgentProcessManager to spawn.
 */
export interface ExternalAgentDescriptor {
    /** Backend ID. */
    id: string;
    /** Resolved CLI binary path. */
    cliPath: string;
    /** ACP launch arguments. */
    acpArgs: string[];
    /** Extra environment variables for spawn. */
    env?: Record<string, string>;
    /** Communication protocol. */
    protocol: "acp";
}
/** Root config store schema (persisted to JSON). */
export interface AgentConfigStoreData {
    /** Global gateway proxy URL. */
    gatewayUrl?: string;
    /** Per-agent override configurations. */
    agents: Record<string, AgentConfig>;
    /** User-registered custom agents. */
    customAgents?: Record<string, CustomAgentDef>;
}
/** ACP initialize result (from agent's response). */
export interface AcpInitializeResult {
    protocolVersion: number;
    /** Standard ACP agentCapabilities (official SDK field). */
    agentCapabilities: {
        loadSession?: boolean;
        mcpCapabilities?: {
            http?: boolean;
            sse?: boolean;
        };
        promptCapabilities?: {
            audio?: boolean;
            embeddedContext?: boolean;
            image?: boolean;
        };
        sessionCapabilities?: Record<string, unknown>;
        [key: string]: unknown;
    };
    /** Standard ACP agentInfo (official SDK field). */
    agentInfo?: {
        name: string;
        version?: string;
    };
    authMethods?: Array<{
        type: string;
        [key: string]: unknown;
    }>;
}
/** ACP session/new result (official: { sessionId, configOptions?, models?, modes? }). */
export interface AcpSessionResult {
    sessionId: string;
}
/** Standard ACP stopReason. */
export type AcpStopReason = "end_turn" | "max_tokens" | "max_turn_requests" | "refusal" | "cancelled";
/** ACP prompt response (official: { stopReason, usage?, userMessageId? }). */
export interface AcpPromptResponse {
    stopReason: AcpStopReason;
    usage?: AcpPromptResponseUsage;
    userMessageId?: string;
    /** Aggregated text from session/update notifications (populated by adapter). */
    text?: string;
}
/** ACP per-turn usage stats (aligned with SDK zUsage). */
export interface AcpPromptResponseUsage {
    inputTokens?: number;
    outputTokens?: number;
    totalTokens?: number;
    cachedReadTokens?: number;
    cachedWriteTokens?: number;
    thoughtTokens?: number;
}
/** ACP usage_update notification payload (session-level). */
export interface AcpUsageUpdatePayload {
    used?: number;
    size?: number;
    cost?: number;
    inputTokens?: number;
    outputTokens?: number;
    totalTokens?: number;
}
/** MCP server config to inject into ACP session/new. */
export interface McpServerConfig {
    name: string;
    command: string;
    args: string[];
    env?: Record<string, string>;
}
export interface AgentsScanParams {
    force?: boolean;
}
export interface AgentsConfigParams {
    action: "register" | "unregister" | "update";
    agent: CustomAgentDef;
}
export interface AgentsSetConfigParams {
    agentId: string;
    apiKey?: string;
    baseUrl?: string;
    model?: string;
    env?: Record<string, string>;
    customArgs?: string[];
    customCliPath?: string;
    modelIdMap?: Record<string, string>;
}
export interface AgentsGetConfigParams {
    agentId: string;
}
export interface AgentsRemoveConfigParams {
    agentId: string;
}
export interface AgentsSetGatewayParams {
    url: string;
}
export interface SoloEvaluation {
    winnerId: string;
    reasoning: string;
}
/** Lightweight Spec (design D3): goal + constraints + acceptance, fits one screen. */
export interface SoloSpec {
    goal: string;
    constraints: string[];
    /** 3-5 checkable acceptance criteria — the evaluate scoring rubric. */
    acceptance: string[];
    /** Original raw task, kept for reference. */
    rawTask: string;
    /** Clarification Q&A trail (optional). */
    clarifications?: {
        question: string;
        answer: string;
    }[];
}
/** x/solo.specChat RPC params (R3 多轮对话式 spec)。history 含到本轮为止的完整对话(末条为用户最新消息)。 */
export interface SoloSpecChatParams {
    rawTask: string;
    history: {
        role: "user" | "assistant";
        content: string;
    }[];
    projectId?: string;
}
/** x/solo.specChat RPC result. */
export interface SoloSpecChatResult {
    reply?: string;
    spec?: SoloSpec;
    error?: string;
}
/** x/solo.specJudge RPC params/result(启动软门防呆:judge 最终 spec 质量)。 */
export interface SoloSpecJudgeParams {
    spec: SoloSpec;
}
export interface SoloSpecJudgeResult {
    ok: boolean;
    issues: string[];
}
/** x/workflow.chat RPC params(M4 自动化页对话式搭图/改图)。history 含到本轮的完整对话;
 *  currentWorkflow 为已有图的渲染文本(改图上下文,前端从 store 提供)。 */
export interface WorkflowChatParams {
    history: {
        role: "user" | "assistant";
        content: string;
    }[];
    currentWorkflow?: string;
    /** D19 框选局部修改:框选的节点 id;非空 → agent 产 scoped patch(前端再以同 scope 调 workflow.patch)。 */
    scope?: string[];
}
/** x/workflow.chat RPC result:propose-only —— 新建给 def,改已有给 patch(均为松类型,前端转发给
 *  既有 workflow.create/patch 落库,引擎做强校验)。 */
export interface WorkflowChatResult {
    reply?: string;
    def?: Record<string, unknown>;
    patch?: unknown[];
    trigger?: Record<string, unknown>;
    error?: string;
    /** propose 全被校验拒(无任何提案落地)时的显式失败:前端展示真实错误 + 重试出路,不许当正常回复。 */
    rejected?: {
        attempts: number;
        errors: string[];
    };
}
/** solo.start RPC params. */
export interface SoloStartParams {
    task: string;
    agents: string[];
    cwd: string;
    /** Project ID that owns this solo session. Used for session storage routing. */
    projectId?: string;
    /** Optional shared config injected into all agents (memory seed, rules, etc). */
    sharedConfig?: {
        /** Initial memory entries to seed into each agent's context. */
        memory?: string[];
        /** Rules/instructions to inject as system prompt prefix. */
        rules?: string[];
        /** Model override for all agents. */
        model?: string;
    };
    /** Spec from the Spec phase; when present, injected into enrichedTask + persisted + used as evaluate rubric. */
    spec?: SoloSpec;
}
/** solo.status / solo.cancel / solo.select RPC params. */
export interface SoloIdParams {
    soloId: string;
}
/** solo.select RPC params. */
export interface SoloSelectParams {
    soloId: string;
    winnerId: string;
}
/** solo.message RPC params — send follow-up to individual agent. */
export interface SoloMessageParams {
    soloId: string;
    agentId: string;
    content: string;
    /** For duplicate agentIds, specify which instance (0-based index). */
    agentIndex?: number;
}
/** solo.evaluate RPC params — user-triggered evaluation with chosen evaluator. */
export interface SoloEvaluateParams {
    soloId: string;
    /** Which agent in the solo session should perform the evaluation comparison. */
    evaluatorAgentId: string;
    /** For duplicate agentIds, specify which instance (0-based index). */
    evaluatorIndex?: number;
}
export type ProductInstanceState = "idle" | "running" | "completed" | "failed" | "paused";
/** Product budget configuration & runtime counters. */
export interface ProductBudget {
    maxTotalTokens?: number;
    maxDuration?: number;
    usedTokens: number;
    elapsed: number;
}
/** product.create RPC params. */
export interface ProductCreateParams {
    /** Optional existing product ID, used when a confirmed planning session transitions into execution. */
    productId?: string;
    name: string;
    cwd: string;
    /** Project ID that owns this product session. Used for session storage routing. */
    projectId?: string;
    instances: ProductInstanceDef[];
    tasks: ProductTaskDef[];
    budget?: {
        maxTotalTokens?: number;
        maxDuration?: number;
    };
}
/**
 * product.plan RPC params — starts an interactive planning session.
 * The leader agent decomposes the goal into modules and proposes a DAG.
 */
export interface ProductPlanParams {
    /** High-level project goal (e.g. "build a multiplayer MMO game"). */
    goal: string;
    /** Working directory for the project. */
    cwd: string;
    /** Which agent acts as the team leader (must be ACP-compatible). */
    leaderAgentId: string;
    /** Optional: project name. Leader can suggest one if omitted. */
    name?: string;
    /** Optional: budget constraints communicated to leader during planning. */
    budget?: {
        maxTotalTokens?: number;
        maxDuration?: number;
    };
}
/** The structured plan produced by the leader agent. */
export interface ProductPlan {
    /** Product/project name. */
    name: string;
    /** Modules the project is decomposed into. */
    modules: Array<{
        name: string;
        description: string;
        /** Suggested agent for this module (leader's recommendation). */
        suggestedAgentId?: string;
    }>;
    /** Proposed team members (leader may suggest agents for each module). */
    instances: ProductInstanceDef[];
    /** Proposed task DAG. */
    tasks: ProductTaskDef[];
    /** Leader's explanation of the decomposition strategy. */
    reasoning: string;
}
/**
 * product.confirm RPC params — user confirms (optionally modified) plan.
 * This starts the actual DAG execution with the leader managing progress.
 */
export interface ProductConfirmParams {
    /** The planning session product ID (returned by product.plan). */
    productId: string;
    /** Final instances (user may have reassigned agents). */
    instances: ProductInstanceDef[];
    /** Final task DAG (user may have modified). */
    tasks: ProductTaskDef[];
    /** Budget for execution phase. */
    budget?: {
        maxTotalTokens?: number;
        maxDuration?: number;
    };
}
/**
 * product.message RPC params — user sends a message to the leader during any phase.
 * Supports: multi-turn planning dialogue, and user intervention during execution.
 */
export interface ProductMessageParams {
    productId: string;
    /** User's message content. */
    content: string;
}
/** product.resume / product.pause / product.checkpoint / product.status RPC params. */
export interface ProductIdParams {
    productId: string;
}
/** Runtime instance state. */
export interface ProductInstanceStatus {
    instanceId: string;
    name: string;
    agentId: string;
    state: ProductInstanceState;
    worktreePath?: string;
    usage?: {
        inputTokens: number;
        outputTokens: number;
    };
}
/** Runtime task state. */
export interface ProductTaskState {
    taskId: string;
    assignee: string;
    status: ProductTaskStatus;
    result?: string;
    error?: string;
    startedAt?: string;
    completedAt?: string;
}
/** agents.getGateway response. */
export interface AgentsGetGatewayResult {
    url?: string;
}
/** agents.listConfigured response item. */
export interface AgentsListConfiguredItem {
    agentId: string;
    hasApiKey: boolean;
    hasBaseUrl: boolean;
    hasModel: boolean;
}
/** agents.processes response item. */
export interface AgentsProcessInfo {
    memberId: string;
    name: string;
    pid: number;
    state: string;
    startedAt: number;
    endedAt?: number;
    source: "solo" | "product";
}
/** agents.kill RPC params. */
export interface AgentsKillParams {
    memberId: string;
}
/** agents.getLog RPC params. */
export interface AgentsGetLogParams {
    agentId: string;
    tail?: number;
}
/** agents.getLog response. */
export interface AgentsGetLogResult {
    log: string;
}
/** agents.testConnection RPC params. */
export interface AgentsTestConnectionParams {
    agentId: string;
    timeoutMs?: number;
}
/** agents.testConnection response. */
export interface AgentsTestConnectionResult {
    ok: boolean;
    version?: string;
    capabilities?: AgentCapabilities;
    error?: string;
    durationMs: number;
}
/** solo.delete / solo.cancel cleanup RPC params. */
export interface SoloDeleteParams {
    soloId: string;
}
/** product.delete cleanup RPC params. */
export interface ProductDeleteParams {
    productId: string;
}
export type { AgentSource } from "./notification-payloads.js";
