/**
 * AgentRelayClient — single client for communicating with an agent-relay broker
 * over HTTP/WS. Works identically for local and remote brokers.
 *
 * Usage:
 *   // Remote broker (Daytona sandbox, cloud, etc.)
 *   const client = new AgentRelayClient({ baseUrl, apiKey });
 *
 *   // Local broker (spawn and connect)
 *   const client = await AgentRelayClient.spawn({ cwd: '/my/project' });
 */
import type { AgentRuntime, BrokerEvent, BrokerStats, BrokerStatus, CrashInsightsResponse } from './protocol.js';
import type { SpawnHeadlessInput, SpawnPtyInput, SpawnProviderInput, SendMessageInput, ListAgent } from './types.js';
export interface AgentRelayClientOptions {
    baseUrl: string;
    apiKey?: string;
    /** Timeout in ms for HTTP requests. Default: 30000. */
    requestTimeoutMs?: number;
}
export interface AgentRelayBrokerInitArgs {
    /** Optional HTTP API port for dashboard proxy (0 = disabled). */
    apiPort?: number;
    /** Bind address for the HTTP API. Defaults to 127.0.0.1 in the broker. */
    apiBind?: string;
    /** Enable persistence for broker state under the working directory. */
    persist?: boolean;
    /** Override the directory used for broker state files. */
    stateDir?: string;
}
export interface AgentRelaySpawnOptions {
    /** Path to the agent-relay-broker binary. Auto-resolved if omitted. */
    binaryPath?: string;
    /** Structured options mapped to the broker's Rust `init` CLI flags. */
    binaryArgs?: AgentRelayBrokerInitArgs;
    /** Broker name. Defaults to cwd basename. */
    brokerName?: string;
    /** Default channels for spawned agents. */
    channels?: string[];
    /** Working directory for the broker process. */
    cwd?: string;
    /** Environment variables for the broker process. */
    env?: NodeJS.ProcessEnv;
    /** Forward broker stderr to this callback. */
    onStderr?: (line: string) => void;
    /** Timeout in ms to wait for broker to become ready. Default: 45000. */
    startupTimeoutMs?: number;
    /** Timeout in ms for HTTP requests to the broker. Default: 30000. */
    requestTimeoutMs?: number;
}
export interface SessionInfo {
    broker_version: string;
    protocol_version: number;
    workspace_key?: string;
    default_workspace_id?: string;
    mode: string;
    uptime_secs: number;
}
export declare class AgentRelayClient {
    private readonly transport;
    /** Set after spawn() — the managed child process. */
    private child;
    /** Lease renewal timer (only for spawned brokers). */
    private leaseTimer;
    workspaceKey?: string;
    constructor(options: AgentRelayClientOptions);
    /**
     * Connect to an already-running broker by reading its connection file.
     *
     * The broker writes `connection.json` to its data directory ({cwd}/.agent-relay/
     * in persist mode). This method reads that file to get the URL and API key.
     *
     * @param cwd — project directory (default: process.cwd())
     * @param connectionPath — explicit path to connection.json (overrides cwd)
     */
    static connect(options?: {
        cwd?: string;
        connectionPath?: string;
    }): AgentRelayClient;
    /**
     * Spawn a local broker process and return a connected client.
     *
     * 1. Generates a random API key
     * 2. Spawns the broker binary (attached)
     * 3. Parses the API port from stdout
     * 4. Connects HTTP/WS transport
     * 5. Fetches session metadata
     * 6. Starts event stream + lease renewal
     */
    static spawn(options?: AgentRelaySpawnOptions): Promise<AgentRelayClient>;
    /** PID of the managed broker process, if spawned locally. */
    get brokerPid(): number | undefined;
    getSession(): Promise<SessionInfo>;
    healthCheck(): Promise<{
        service: string;
    }>;
    connectEvents(sinceSeq?: number): void;
    disconnectEvents(): void;
    onEvent(listener: (event: BrokerEvent) => void): () => void;
    queryEvents(filter?: {
        kind?: string;
        name?: string;
        since?: number;
        limit?: number;
    }): BrokerEvent[];
    getLastEvent(kind: string, name?: string): BrokerEvent | undefined;
    spawnPty(input: SpawnPtyInput): Promise<{
        name: string;
        runtime: AgentRuntime;
    }>;
    spawnProvider(input: SpawnProviderInput): Promise<{
        name: string;
        runtime: AgentRuntime;
    }>;
    spawnHeadless(input: SpawnHeadlessInput): 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;
    }>;
    listAgents(): Promise<ListAgent[]>;
    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;
    }>;
    sendMessage(input: SendMessageInput): Promise<{
        event_id: string;
        targets: string[];
    }>;
    setModel(name: string, model: string, opts?: {
        timeoutMs?: number;
    }): Promise<{
        name: string;
        model: string;
        success: boolean;
    }>;
    subscribeChannels(name: string, channels: string[]): Promise<void>;
    unsubscribeChannels(name: string, channels: string[]): Promise<void>;
    getMetrics(agent?: string): Promise<{
        agents: Array<{
            name: string;
            pid: number;
            memory_bytes: number;
            uptime_secs: number;
        }>;
        broker?: BrokerStats;
    }>;
    getStatus(): Promise<BrokerStatus>;
    getCrashInsights(): Promise<CrashInsightsResponse>;
    preflight(agents: Array<{
        name: string;
        cli: string;
    }>): Promise<{
        queued: number;
    }>;
    renewLease(): Promise<{
        renewed: boolean;
        expires_in_secs: number;
    }>;
    /**
     * Shut down and clean up.
     * - For spawned brokers (via .spawn()): sends POST /api/shutdown to kill the broker, waits for exit.
     * - For connected brokers (via .connect() or constructor): just disconnects the transport.
     *   Does NOT kill the broker — the caller doesn't own it.
     */
    shutdown(): Promise<void>;
    /** Disconnect without shutting down the broker. Alias for cases where the intent is clear. */
    disconnect(): void;
    getConfig(): Promise<{
        workspaceKey?: string;
    }>;
}
//# sourceMappingURL=client.d.ts.map