import { type AgentRuntime, type BrokerEvent, type BrokerStats, type BrokerStatus, type CrashInsightsResponse, type ProtocolError, type RestartPolicy } from './protocol.js';
export interface AgentRelayClientOptions {
    binaryPath?: string;
    binaryArgs?: string[];
    brokerName?: string;
    channels?: string[];
    cwd?: string;
    env?: NodeJS.ProcessEnv;
    requestTimeoutMs?: number;
    shutdownTimeoutMs?: number;
    clientName?: string;
    clientVersion?: string;
}
export interface SpawnPtyInput {
    name: string;
    cli: string;
    args?: string[];
    channels?: string[];
    task?: string;
    model?: string;
    cwd?: string;
    team?: string;
    shadowOf?: string;
    shadowMode?: string;
    /** Silence duration in seconds before emitting agent_idle (0 = disabled, default: 30). */
    idleThresholdSecs?: number;
    /** Auto-restart policy for crashed agents. */
    restartPolicy?: RestartPolicy;
    /** Name of a previously released agent whose continuity context should be injected. */
    continueFrom?: string;
}
export interface SpawnHeadlessClaudeInput {
    name: string;
    args?: string[];
    channels?: string[];
    task?: string;
}
export interface SendMessageInput {
    to: string;
    text: string;
    from?: string;
    threadId?: string;
    priority?: number;
    data?: Record<string, unknown>;
}
export interface ListAgent {
    name: string;
    runtime: AgentRuntime;
    cli?: string;
    model?: string;
    team?: string;
    channels: string[];
    parent?: string;
    pid?: number;
}
export declare class AgentRelayProtocolError extends Error {
    code: string;
    retryable: boolean;
    data?: unknown;
    constructor(payload: ProtocolError);
}
export declare class AgentRelayProcessError extends Error {
    constructor(message: string);
}
export declare class AgentRelayClient {
    private readonly options;
    private child?;
    private stdoutRl?;
    private stderrRl?;
    private lastStderrLine?;
    private requestSeq;
    private pending;
    private startingPromise?;
    private eventListeners;
    private stderrListeners;
    private eventBuffer;
    private maxBufferSize;
    private exitPromise?;
    /** The workspace key returned by the broker in its hello_ack response. */
    workspaceKey?: string;
    constructor(options?: AgentRelayClientOptions);
    static start(options?: AgentRelayClientOptions): Promise<AgentRelayClient>;
    onEvent(listener: (event: BrokerEvent) => void): () => void;
    queryEvents(filter?: {
        kind?: string;
        name?: string;
        since?: number;
        limit?: number;
    }): BrokerEvent[];
    getLastEvent(kind: string, name?: string): BrokerEvent | undefined;
    onBrokerStderr(listener: (line: string) => void): () => void;
    start(): Promise<void>;
    /**
     * Pre-register a batch of agents with Relaycast before their steps execute.
     * The broker warms its token cache in parallel; subsequent spawn_agent calls
     * hit the cache rather than waiting on individual HTTP registrations.
     * Fire-and-forget from the caller's perspective — broker responds immediately
     * and registers in the background.
     */
    preflightAgents(agents: Array<{
        name: string;
        cli: string | AgentRuntime;
    }>): Promise<void>;
    spawnPty(input: SpawnPtyInput): Promise<{
        name: string;
        runtime: AgentRuntime;
    }>;
    spawnHeadlessClaude(input: SpawnHeadlessClaudeInput): Promise<{
        name: string;
        runtime: AgentRuntime;
    }>;
    release(name: string, reason?: string): Promise<{
        name: string;
    }>;
    sendInput(name: string, data: string): Promise<{
        name: string;
        bytes_written: number;
    }>;
    setModel(name: string, model: string, opts?: {
        timeoutMs?: number;
    }): Promise<{
        name: string;
        model: string;
        success: boolean;
    }>;
    getMetrics(agent?: string): Promise<{
        agents: Array<{
            name: string;
            pid: number;
            memory_bytes: number;
            uptime_secs: number;
        }>;
        broker?: BrokerStats;
    }>;
    getCrashInsights(): Promise<CrashInsightsResponse>;
    sendMessage(input: SendMessageInput): Promise<{
        event_id: string;
        targets: string[];
    }>;
    listAgents(): Promise<ListAgent[]>;
    getStatus(): Promise<BrokerStatus>;
    shutdown(): Promise<void>;
    waitForExit(): Promise<void>;
    private startInternal;
    private disposeProcessHandles;
    private failAllPending;
    private handleStdoutLine;
    private requestHello;
    private requestOk;
    private sendRequest;
}
//# sourceMappingURL=client.d.ts.map