import { type AgentRuntime, type BrokerEvent, type BrokerStats, type BrokerStatus, type CrashInsightsResponse, type HeadlessProvider, 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;
    /** When true, skip injecting the relay MCP configuration and protocol prompt into the spawned agent.
     *  Useful for minor tasks where relay messaging is not needed, saving tokens. */
    skipRelayPrompt?: boolean;
}
export interface SpawnHeadlessInput {
    name: string;
    provider: HeadlessProvider;
    args?: string[];
    channels?: string[];
    task?: string;
    /** When true, skip injecting the relay MCP configuration and protocol prompt into the spawned agent.
     *  Useful for minor tasks where relay messaging is not needed, saving tokens. */
    skipRelayPrompt?: boolean;
}
export type AgentTransport = 'pty' | 'headless';
export interface SpawnProviderInput {
    name: string;
    provider: string;
    transport?: AgentTransport;
    args?: string[];
    channels?: string[];
    task?: string;
    model?: string;
    cwd?: string;
    team?: string;
    shadowOf?: string;
    shadowMode?: string;
    idleThresholdSecs?: number;
    restartPolicy?: RestartPolicy;
    continueFrom?: string;
    /** When true, skip injecting the relay MCP configuration and protocol prompt into the spawned agent.
     *  Useful for minor tasks where relay messaging is not needed, saving tokens. */
    skipRelayPrompt?: boolean;
}
export interface SendMessageInput {
    to: string;
    text: string;
    from?: string;
    threadId?: string;
    workspaceId?: string;
    workspaceAlias?: string;
    priority?: number;
    data?: Record<string, unknown>;
}
export interface ListAgent {
    name: string;
    runtime: AgentRuntime;
    provider?: HeadlessProvider;
    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;
    get brokerPid(): number | undefined;
    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;
    }>;
    spawnHeadless(input: SpawnHeadlessInput): Promise<{
        name: string;
        runtime: AgentRuntime;
    }>;
    spawnProvider(input: SpawnProviderInput): Promise<{
        name: string;
        runtime: AgentRuntime;
    }>;
    spawnClaude(input: Omit<SpawnProviderInput, 'provider'>): Promise<{
        name: string;
        runtime: AgentRuntime;
    }>;
    spawnOpencode(input: Omit<SpawnProviderInput, 'provider'>): Promise<{
        name: string;
        runtime: AgentRuntime;
    }>;
    release(name: string, reason?: string): Promise<{
        name: string;
    }>;
    sendInput(name: string, data: string): Promise<{
        name: string;
        bytes_written: number;
    }>;
    resizePty(name: string, rows: number, cols: number): Promise<{
        name: string;
        rows: number;
        cols: 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;
}
export interface HttpAgentRelayClientOptions {
    port: number;
    apiKey?: string;
}
export interface DiscoverAndConnectOptions {
    cwd?: string;
    apiKey?: string;
    /** Auto-start the broker if not running (default: false). */
    autoStart?: boolean;
    /**
     * Path to the broker binary for auto-start.
     * If not provided, the SDK resolves it automatically via standard install locations
     * (~/.agent-relay/bin, bundled platform binary, or Cargo release build).
     * Only used when `autoStart: true`.
     */
    brokerBinaryPath?: string;
}
export declare class HttpAgentRelayClient {
    private readonly port;
    private readonly apiKey?;
    constructor(options: HttpAgentRelayClientOptions);
    /**
     * Connect to an already-running broker on the given port.
     */
    static connectHttp(port: number, options?: {
        apiKey?: string;
    }): Promise<HttpAgentRelayClient>;
    /**
     * Discover a running broker for the current project and connect to it.
     * Reads the broker PID file, verifies the process is alive, scans ports
     * for the HTTP API, and returns a connected client.
     */
    static discoverAndConnect(options?: DiscoverAndConnectOptions): Promise<HttpAgentRelayClient>;
    private static scanForBrokerPort;
    private request;
    private static extractErrorMessage;
    healthCheck(): Promise<{
        service: string;
    }>;
    /** No-op — broker is already running. */
    start(): Promise<void>;
    /** No-op — don't kill an externally-managed broker. */
    shutdown(): Promise<void>;
    spawnPty(input: SpawnPtyInput): Promise<{
        name: string;
        runtime: AgentRuntime;
    }>;
    sendMessage(input: SendMessageInput): Promise<{
        event_id: string;
        targets: string[];
    }>;
    listAgents(): Promise<ListAgent[]>;
    release(name: string, reason?: string): Promise<{
        name: string;
    }>;
    setModel(name: string, model: string, opts?: {
        timeoutMs?: number;
    }): Promise<{
        name: string;
        model: string;
        success: boolean;
    }>;
    getConfig(): Promise<{
        workspace_key?: string;
    }>;
}
//# sourceMappingURL=client.d.ts.map