export declare const PROTOCOL_VERSION: 2;
export type AgentRuntime = 'pty' | 'headless';
export type HeadlessProvider = 'claude' | 'opencode';
export type InboundDeliveryMode = 'auto_inject' | 'manual_flush';
export type SnapshotFormat = 'plain' | 'ansi';
export interface RestartPolicy {
    enabled?: boolean;
    max_restarts?: number;
    cooldown_ms?: number;
    max_consecutive_failures?: number;
}
export interface AgentSpec {
    name: string;
    runtime: AgentRuntime;
    provider?: HeadlessProvider;
    cli?: string;
    args?: string[];
    channels?: string[];
    model?: string;
    cwd?: string;
    team?: string;
    shadow_of?: string;
    shadow_mode?: string;
    restart_policy?: RestartPolicy;
}
export type MessageInjectionMode = 'wait' | 'steer';
export interface RelayDelivery {
    delivery_id: string;
    event_id: string;
    workspace_id?: string;
    workspace_alias?: string;
    from: string;
    target: string;
    body: string;
    thread_id?: string;
    priority?: number;
    injection_mode?: MessageInjectionMode;
}
export interface PendingRelayMessage {
    from: string;
    body: string;
    target: string;
    thread_id?: string;
    workspace_id?: string;
    workspace_alias?: string;
    priority: number;
    mode: MessageInjectionMode;
    queued_at_ms: number;
    event_id?: string;
}
export interface PtySnapshot {
    format: SnapshotFormat;
    rows: number;
    cols: number;
    cursor: [number, number];
    /** Plain text for `format=plain`; base64-encoded ANSI bytes for `format=ansi`. */
    screen: string;
}
export interface ProtocolEnvelope<TPayload> {
    v: number;
    type: string;
    request_id?: string;
    payload: TPayload;
}
export type SdkToBroker = {
    type: 'hello';
    payload: {
        client_name: string;
        client_version: string;
    };
} | {
    type: 'spawn_agent';
    payload: {
        agent: AgentSpec;
        initial_task?: string;
        skip_relay_prompt?: boolean;
    };
} | {
    type: 'send_message';
    payload: {
        to: string;
        text: string;
        from?: string;
        thread_id?: string;
        workspace_id?: string;
        workspace_alias?: string;
        priority?: number;
        data?: Record<string, unknown>;
        mode?: MessageInjectionMode;
    };
} | {
    type: 'release_agent';
    payload: {
        name: string;
        reason?: string;
    };
} | {
    type: 'send_input';
    payload: {
        name: string;
        data: string;
    };
} | {
    type: 'subscribe_channels';
    payload: {
        name: string;
        channels: string[];
    };
} | {
    type: 'unsubscribe_channels';
    payload: {
        name: string;
        channels: string[];
    };
} | {
    type: 'set_model';
    payload: {
        name: string;
        model: string;
        timeout_ms?: number;
    };
} | {
    type: 'get_metrics';
    payload: {
        agent?: string;
    };
} | {
    type: 'list_agents';
    payload: Record<string, never>;
} | {
    type: 'get_status';
    payload: Record<string, never>;
} | {
    type: 'get_crash_insights';
    payload: Record<string, never>;
} | {
    type: 'shutdown';
    payload: Record<string, never>;
} | {
    /** Pre-register a batch of agents with Relaycast before their steps execute.
     *  Broker warms its token cache in parallel; subsequent spawn_agent calls hit
     *  the cache instead of waiting on individual HTTP registrations. */
    type: 'preflight_agents';
    payload: {
        agents: Array<{
            name: string;
            cli: string;
        }>;
    };
} | {
    /** Resize a PTY agent's terminal dimensions. */
    type: 'resize_pty';
    payload: {
        name: string;
        rows: number;
        cols: number;
    };
};
export interface PendingDeliveryInfo {
    delivery_id: string;
    worker_name: string;
    event_id: string;
    from?: string;
    to?: string;
    attempts: number;
    queued_at_ms?: number;
    age_ms?: number;
    last_error?: string;
}
export interface BrokerStatus {
    agent_count: number;
    agents: Array<{
        name: string;
        runtime: AgentRuntime;
        provider?: HeadlessProvider;
        cli?: string;
        model?: string;
        team?: string;
        channels: string[];
        parent?: string;
        pid?: number;
        last_activity_at?: string;
        last_activity_ms?: number;
        context_budget_pct?: number | null;
        current_state?: AgentCurrentState;
    }>;
    pending_delivery_count: number;
    pending_deliveries: PendingDeliveryInfo[];
    auth?: BrokerAuthStatus;
}
export type AgentCurrentState = 'working' | 'idle' | 'blocked_on_send';
export interface BrokerAuthStatus {
    authenticated: boolean;
    workspace_count: number;
    default_workspace_id?: string | null;
    workspaces: Array<{
        workspace_id: string;
        workspace_alias?: string | null;
        self_name: string;
        self_agent_id: string;
        authenticated: boolean;
        default: boolean;
    }>;
}
export type BrokerAgentStatus = 'healthy' | 'restarting' | 'dead' | 'released';
export interface AgentStats {
    spawns: number;
    crashes: number;
    restarts: number;
    releases: number;
    status: BrokerAgentStatus;
    current_uptime_secs: number;
    memory_bytes: number;
}
export interface BrokerStats {
    uptime_secs: number;
    total_agents_spawned: number;
    total_crashes: number;
    total_restarts: number;
    active_agents: number;
}
export type CrashCategory = 'oom' | 'segfault' | 'error' | 'signal' | 'unknown';
export interface CrashRecord {
    agent_name: string;
    exit_code?: number;
    signal?: string;
    timestamp: number;
    uptime_secs: number;
    category: CrashCategory;
    description: string;
}
export interface CrashPattern {
    category: CrashCategory;
    count: number;
    agents: string[];
}
export interface CrashInsightsResponse {
    total_crashes: number;
    recent: CrashRecord[];
    patterns: CrashPattern[];
    health_score: number;
}
export interface ProtocolError {
    code: string;
    message: string;
    retryable: boolean;
    data?: unknown;
}
export type BrokerEvent = {
    kind: 'agent_spawned';
    name: string;
    runtime: AgentRuntime;
    provider?: HeadlessProvider;
    cli?: string;
    model?: string;
    parent?: string;
    pid?: number;
    source?: string;
} | {
    kind: 'agent_released';
    name: string;
} | {
    kind: 'agent_exit';
    name: string;
    reason: string;
} | {
    kind: 'agent_exited';
    name: string;
    code?: number;
    signal?: string;
    reason?: string;
} | {
    kind: 'agent_context_low';
    name: string;
    pct: number;
} | {
    kind: 'relay_inbound';
    event_id: string;
    from: string;
    target: string;
    body: string;
    thread_id?: string;
    mode?: MessageInjectionMode;
    injection_mode?: MessageInjectionMode;
} | {
    kind: 'worker_stream';
    name: string;
    stream: string;
    chunk: string;
} | {
    kind: 'delivery_retry';
    name: string;
    delivery_id: string;
    event_id: string;
    attempts: number;
} | {
    kind: 'delivery_dropped';
    name: string;
    count: number;
    reason: string;
} | {
    kind: 'delivery_queued';
    name: string;
    delivery_id: string;
    event_id: string;
    timestamp?: unknown;
} | {
    kind: 'agent_pending_drained';
    name: string;
    count: number;
    reason?: string;
} | {
    kind: 'agent_inbound_delivery_mode_changed';
    name: string;
    previous_mode: InboundDeliveryMode;
    mode: InboundDeliveryMode;
} | {
    kind: 'delivery_injected';
    name: string;
    delivery_id: string;
    event_id: string;
    timestamp?: unknown;
} | {
    kind: 'delivery_verified';
    name: string;
    delivery_id: string;
    event_id: string;
} | {
    kind: 'delivery_failed';
    name: string;
    delivery_id: string;
    event_id: string;
    reason: string;
} | {
    kind: 'message_delivery_confirmed';
    name: string;
    delivery_id: string;
    event_id: string;
    from: string;
    to: string;
} | {
    kind: 'message_delivery_failed';
    name: string;
    delivery_id?: string;
    event_id?: string;
    from: string;
    to: string;
    attempts: number;
    lastError: string;
} | {
    kind: 'delivery_active';
    name: string;
    delivery_id: string;
    event_id: string;
} | {
    kind: 'delivery_ack';
    name: string;
    delivery_id: string;
    event_id: string;
} | {
    kind: 'channel_subscribed';
    name: string;
    channels: string[];
} | {
    kind: 'channel_unsubscribed';
    name: string;
    channels: string[];
} | {
    kind: 'worker_ready';
    name: string;
    runtime: AgentRuntime;
    provider?: HeadlessProvider;
    cli?: string;
    model?: string;
} | {
    kind: 'worker_error';
    name: string;
    code: string;
    message: string;
} | {
    kind: 'relaycast_published';
    event_id: string;
    to: string;
    target_type: string;
} | {
    kind: 'relaycast_publish_failed';
    event_id: string;
    to: string;
    reason: string;
} | {
    kind: 'acl_denied';
    name: string;
    sender: string;
    owner_chain: string[];
} | {
    kind: 'agent_idle';
    name: string;
    idle_secs: number;
    since?: string;
} | {
    kind: 'agent_blocked_on_send';
    name: string;
    blocked_secs: number;
    pending_delivery_count: number;
} | {
    kind: 'agent_restarting';
    name: string;
    code?: number;
    signal?: string;
    restart_count: number;
    delay_ms: number;
} | {
    kind: 'agent_restarted';
    name: string;
    restart_count: number;
} | {
    kind: 'agent_permanently_dead';
    name: string;
    reason: string;
};
export type BrokerToSdk = {
    type: 'hello_ack';
    payload: {
        broker_version: string;
        protocol_version: number;
    };
} | {
    type: 'ok';
    payload: {
        result: unknown;
    };
} | {
    type: 'error';
    payload: ProtocolError;
} | {
    type: 'event';
    payload: BrokerEvent;
};
export type BrokerToWorker = {
    type: 'init_worker';
    payload: {
        agent: AgentSpec;
    };
} | {
    type: 'deliver_relay';
    payload: RelayDelivery;
} | {
    type: 'shutdown_worker';
    payload: {
        reason: string;
        grace_ms?: number;
    };
} | {
    type: 'ping';
    payload: {
        ts_ms: number;
    };
} | {
    type: 'resize_pty';
    payload: {
        rows: number;
        cols: number;
    };
};
export type WorkerToBroker = {
    type: 'worker_ready';
    payload: {
        name: string;
        runtime: AgentRuntime;
        provider?: HeadlessProvider;
    };
} | {
    type: 'delivery_ack';
    payload: {
        delivery_id: string;
        event_id: string;
    };
} | {
    type: 'delivery_verified';
    payload: {
        delivery_id: string;
        event_id: string;
        verification?: string;
        reason?: string;
    };
} | {
    type: 'delivery_failed';
    payload: {
        delivery_id: string;
        event_id: string;
        reason: string;
    };
} | {
    type: 'worker_stream';
    payload: {
        stream: string;
        chunk: string;
    };
} | {
    type: 'worker_error';
    payload: ProtocolError;
} | {
    type: 'worker_exited';
    payload: {
        code?: number;
        signal?: string;
    };
} | {
    type: 'pong';
    payload: {
        ts_ms: number;
    };
};
//# sourceMappingURL=protocol.d.ts.map