import type { Database } from "bun:sqlite";
import { type TaskRun } from "../db/task-runs.js";
import { type AgentRunAdapterConfig } from "./config.js";
export type AgentRunDispatchState = "queued" | "running" | "completed" | "failed" | "cancelled";
export interface QueueAgentRunInput {
    task_id: string;
    agent_id?: string;
    adapter?: string;
    command?: string;
    sandbox?: string;
    cwd?: string;
    title?: string;
    summary?: string;
    claim?: boolean;
    metadata?: Record<string, unknown>;
}
export interface QueuedAgentRun {
    run: TaskRun;
    dispatcher: AgentRunDispatchMetadata;
}
export interface AgentRunDispatchMetadata {
    state: AgentRunDispatchState;
    adapter?: string;
    command: string;
    sandbox?: string;
    cwd?: string;
    attempt: number;
    queued_at: string;
    started_at?: string;
    completed_at?: string;
    last_error?: string;
}
export interface RunNextAgentDispatchInput {
    adapter?: string;
    dry_run?: boolean;
    limit?: number;
}
export interface RunAgentDispatchResult {
    run_id: string;
    task_id: string;
    command: string;
    dry_run: boolean;
    status: "queued" | "completed" | "failed" | "cancelled";
    exit_code: number | null;
    output_summary: string | null;
}
export interface UpsertAgentRunAdapterInput {
    name: string;
    command: string;
    sandbox?: string;
    cwd?: string;
    env?: Record<string, string>;
}
export declare function upsertAgentRunAdapter(input: UpsertAgentRunAdapterInput): AgentRunAdapterConfig;
export declare function listAgentRunAdapters(): AgentRunAdapterConfig[];
export declare function removeAgentRunAdapter(name: string): boolean;
export declare function queueAgentRun(input: QueueAgentRunInput, db?: Database): QueuedAgentRun;
export declare function listAgentRunQueue(db?: Database): QueuedAgentRun[];
export declare function cancelAgentRunDispatch(runId: string, db?: Database): QueuedAgentRun;
export declare function retryAgentRunDispatch(runId: string, db?: Database): QueuedAgentRun;
export declare function runNextAgentDispatch(input?: RunNextAgentDispatchInput, db?: Database): Promise<RunAgentDispatchResult | null>;
export declare function listAgentRuns(filter?: {
    task_id?: string;
    status?: string;
    agent_id?: string;
    limit?: number;
}, db?: Database): AgentRun[];
export declare function retryAgentRun(runId: string, db?: Database): AgentRun;
export declare const AGENT_RUN_SCHEMA_VERSION = "todos.agent_run.v1";
export type AgentRunStatus = AgentRunDispatchState;
export type AgentAdapterConfig = AgentRunAdapterConfig;
export interface EnqueueAgentRunInput {
    task_id: string;
    adapter?: string;
    agent_id?: string;
    command?: string;
    plan_id?: string;
    evidence?: Record<string, unknown>;
    metadata?: Record<string, unknown>;
}
export interface AgentRun {
    id: string;
    task_id: string;
    agent_id: string | null;
    adapter: string | null;
    status: AgentRunStatus;
    command: string | null;
    error: string | null;
    evidence: Record<string, unknown>;
    retry_count: number;
    max_retries: number;
    queued_at: string;
    started_at: string | null;
    completed_at: string | null;
    metadata: Record<string, unknown>;
}
export interface ListAgentRunsFilter {
    task_id?: string;
    agent_id?: string;
    status?: AgentRunStatus;
    adapter?: string;
    limit?: number;
}
export declare function enqueueAgentRun(input: EnqueueAgentRunInput, db?: Database): AgentRun;
export declare function claimNextAgentRun(agentId: string, options?: {
    adapter?: string;
}, db?: Database): AgentRun | null;
export declare function completeAgentRun(runId: string, evidence?: Record<string, unknown>, db?: Database): AgentRun;
export declare function failAgentRun(runId: string, error?: string, db?: Database): AgentRun;
export declare function cancelAgentRun(runId: string, db?: Database): AgentRun;
export declare function getAgentRun(runId: string, db?: Database): AgentRun | null;
export declare function loadAgentAdapters(): AgentAdapterConfig[];
export declare function saveAgentAdapters(adapters: AgentAdapterConfig[]): void;
export declare function getAgentAdapter(name: string): AgentAdapterConfig | null;
export declare function getDefaultAgentAdapters(): AgentAdapterConfig[];
export declare function resetAgentAdapterCache(): void;
//# sourceMappingURL=agent-run-dispatcher.d.ts.map