/**
 * RemoteEngine - Connect to a remote Hypen app over WebSocket
 * Platform-agnostic client (uses standard WebSocket API)
 *
 * Usage:
 * ```typescript
 * const engine = new RemoteEngine("ws://localhost:3000", {
 *   session: {
 *     id: localStorage.getItem("sessionId") ?? undefined,
 *     props: { platform: "web", version: "1.0" }
 *   }
 * });
 *
 * engine.onSessionEstablished(({ sessionId, isNew, isRestored }) => {
 *   localStorage.setItem("sessionId", sessionId);
 *   console.log(isRestored ? "Welcome back!" : "New session");
 * });
 *
 * engine.onSessionExpired((reason) => {
 *   localStorage.removeItem("sessionId");
 * });
 *
 * const result = await engine.connect();
 * if (!result.ok) {
 *   console.error("Connection failed:", result.error);
 * }
 * ```
 */
import type { Patch } from "../types.js";
import { type Result, ConnectionError } from "../result.js";
import { type Disposable } from "../disposable.js";
export type RemoteConnectionState = "disconnected" | "connecting" | "connected" | "error";
/**
 * Session configuration for the client
 */
export interface SessionOptions {
    /** Session ID to resume (omit for new session) */
    id?: string;
    /** Client metadata (platform, version, userId, etc.) */
    props?: Record<string, unknown>;
}
/**
 * Session information received from server
 */
export interface SessionInfo {
    sessionId: string;
    isNew: boolean;
    isRestored: boolean;
}
export interface RemoteEngineOptions {
    autoReconnect?: boolean;
    reconnectInterval?: number;
    maxReconnectAttempts?: number;
    /** Session configuration */
    session?: SessionOptions;
}
/**
 * Client-side engine that connects to a remote Hypen app
 */
export declare class RemoteEngine implements Disposable {
    private ws;
    private readonly url;
    private state;
    private readonly options;
    private reconnectAttempts;
    private readonly disposables;
    private reconnectDisposable;
    private currentSessionId;
    private readonly sessionOptions?;
    private readonly patchCallbacks;
    private readonly stateCallbacks;
    private readonly connectionCallbacks;
    private readonly disconnectionCallbacks;
    private readonly errorCallbacks;
    private readonly sessionEstablishedCallbacks;
    private readonly sessionExpiredCallbacks;
    private currentState;
    private currentRevision;
    private moduleName;
    constructor(url: string, options?: RemoteEngineOptions);
    /**
     * Connect to the remote server
     * Returns a Result indicating success or failure
     */
    connect(): Promise<Result<void, ConnectionError>>;
    /**
     * Send hello message to establish session
     */
    private sendHello;
    /**
     * Disconnect from the remote server and clean up resources
     */
    disconnect(): void;
    /**
     * Dispose all resources (alias for disconnect)
     */
    dispose(): void;
    /**
     * Dispatch an action to the remote server
     */
    dispatchAction(action: string, payload?: unknown): void;
    /**
     * Subscribe to state updates after each render.
     * Only subscribed clients receive stateUpdate messages (avoids overhead for native clients).
     */
    subscribeState(): void;
    /**
     * Override the remote module's state (e.g. for time-travel).
     * The server will update state, re-render, and send back patches.
     */
    updateState(state: unknown): void;
    /**
     * Register callback for patches
     */
    onPatches(callback: (patches: Patch[]) => void): this;
    /**
     * Register callback for state updates
     */
    onStateUpdate(callback: (state: unknown) => void): this;
    /**
     * Register callback for connection
     */
    onConnect(callback: () => void): this;
    /**
     * Register callback for disconnection
     */
    onDisconnect(callback: () => void): this;
    /**
     * Register callback for errors
     */
    onError(callback: (error: Error) => void): this;
    /**
     * Register callback for session establishment
     * Called when server confirms session (new or resumed)
     */
    onSessionEstablished(callback: (info: SessionInfo) => void): this;
    /**
     * Register callback for session expiration
     * Called when session is kicked or expires
     */
    onSessionExpired(callback: (reason: string) => void): this;
    /**
     * Get current connection state
     */
    getConnectionState(): RemoteConnectionState;
    /**
     * Get current app state
     */
    getCurrentState(): unknown;
    /**
     * Get current revision
     */
    getRevision(): number;
    /**
     * Get current session ID
     */
    getSessionId(): string | null;
    private handleMessage;
    private handleSessionAck;
    private handleSessionExpired;
    private handleInitialTree;
    private handlePatch;
    private attemptReconnect;
}
