/**
 * Remote Session Bridge — TUI ↔ Hub ↔ Sandbox
 *
 * Handles the WebSocket connection and RPC protocol bridge for remote mode.
 * In remote mode, the local Pi TUI connects to an existing sandbox session
 * through the Hub, acting as a thin client:
 *   - User input → rpc_command → Hub → sandbox
 *   - Sandbox events → rpc_event → Hub → TUI rendering
 *   - Extension UI dialogs → rpc_ui_request/response → Hub ↔ TUI
 *
 * This module manages the connection lifecycle and provides an API
 * for the extension to send commands and receive events.
 */
import type { ExtensionAPI, ExtensionContext } from '@mariozechner/pi-coding-agent';
import { type RemoteLifecycleState } from './remote-lifecycle.ts';
export interface RpcCommand {
    type: string;
    [key: string]: unknown;
}
export interface RpcEvent {
    type: string;
    [key: string]: unknown;
}
export interface RpcUiRequest {
    id: string;
    method: string;
    params: Record<string, unknown>;
}
/** RPC response from sandbox (correlated by id) */
export interface RpcResponse {
    type: 'response';
    id: string;
    command: string;
    success: boolean;
    data?: unknown;
    error?: string;
}
export type RemoteEventHandler = (event: RpcEvent) => void;
export type RemoteResponseHandler = (response: RpcResponse) => void;
export type RemoteUiHandler = (request: RpcUiRequest) => Promise<unknown>;
export type RemoteConnectionHandler = (state: 'connected' | 'reconnecting' | 'disconnected') => void;
export type RemoteLifecycleHandler = (state: RemoteLifecycleState) => void;
export declare class RemoteSession {
    private ws;
    private connected;
    private intentionallyClosed;
    private hubWsUrl;
    private reconnectAttempts;
    private reconnectTimer;
    private eventHandlers;
    private uiHandler;
    private responseHandlers;
    private connectionHandlers;
    private lifecycleHandlers;
    private lifecycleState;
    private replaySettledTimer;
    /** Session ID this client is connected to */
    sessionId: string;
    /** Session label (populated after connection) */
    label: string;
    /** API key for Hub authentication (Hub API key or CLI/platform key) */
    apiKey: string | null;
    /** Organization ID for CLI/platform key auth (sent as x-agentuity-orgid header) */
    orgId: string | null;
    constructor(sessionId: string);
    private dispatchEvent;
    private dispatchResponse;
    private applyLifecycle;
    private clearReplaySettledTimer;
    private scheduleReplaySettled;
    private observeLiveSignal;
    private getLiveSignalStreamingState;
    private shouldMarkResuming;
    private shouldObserveRpcResponseAsLive;
    /** Register a handler for RPC events from the sandbox */
    onEvent(handler: RemoteEventHandler): void;
    /** Register a handler for RPC responses from the sandbox */
    onResponse(handler: RemoteResponseHandler): void;
    /** Register the UI dialog handler (select, confirm, input, editor) */
    setUiHandler(handler: RemoteUiHandler): void;
    /** Register a connection state change handler */
    onConnectionChange(handler: RemoteConnectionHandler): void;
    /** Register a lifecycle state handler for remote attach/replay/live transitions. */
    onLifecycleChange(handler: RemoteLifecycleHandler): void;
    getLifecycleState(): RemoteLifecycleState;
    /** Connect to the Hub WebSocket as a controller for the remote session */
    connect(hubWsUrl: string): Promise<void>;
    private doConnect;
    private scheduleReconnect;
    private notifyConnectionChange;
    /** Send an RPC command to the sandbox (prompt, steer, abort, etc.) */
    sendCommand(command: RpcCommand): void;
    /** Send a user prompt to the remote sandbox */
    prompt(message: string, images?: string[]): void;
    /** Steer the agent mid-turn */
    steer(message: string): void;
    /** Abort current operation */
    abort(): void;
    /** Get current session state */
    getState(): void;
    /** Get all messages in current session */
    getMessages(): void;
    /** Compact the session context */
    compact(): void;
    /** Close the connection */
    close(): void;
    get isConnected(): boolean;
    /** Handle UI request from sandbox — delegate to registered handler */
    private handleUiRequest;
    /** Send UI response back to sandbox */
    private sendUiResponse;
}
/**
 * Set up remote mode for the Pi extension.
 *
 * Connects to an existing sandbox session through the Hub and bridges
 * user input → RPC commands and sandbox events → TUI rendering.
 *
 * Uses Pi's extension APIs for rich rendering:
 * - pi.sendMessage() for completed assistant messages
 * - ctx.ui.setWidget() for streaming output
 * - ctx.ui.setWorkingMessage() for tool execution status
 * - ctx.ui.setStatus() for connection and agent state
 */
export declare function setupRemoteMode(pi: ExtensionAPI, hubWsUrl: string, sessionId: string): Promise<RemoteSession>;
/** Internal interface for passing extension context to RemoteSession */
export interface RemoteSessionInternal extends RemoteSession {
    _setExtensionCtx?: (ctx: ExtensionContext) => void;
}
//# sourceMappingURL=remote-session.d.ts.map