/**
 * UI Bridge Native HTTP Server
 *
 * Abstract HTTP server implementation for React Native.
 * This provides a framework-agnostic server interface that can be
 * implemented using various React Native HTTP server libraries.
 *
 * Supported libraries:
 * - react-native-http-bridge (recommended)
 * - @aspect/react-native-http-server
 * - Custom implementations
 */
import type { NativeUIBridgeRegistry } from '../core/registry';
import type { NativeActionExecutor } from '../control/types';
import type { NativeServerConfig, NavigationProvider, RouteProvider, ScreenshotProvider, KeepAwakeProvider } from './types';
import type { WebSocketEventBridge } from './ws-event-bridge';
import type { JsonRpcRequest, JsonRpcResponse } from './ws-types';
/**
 * HTTP Request interface (library-agnostic)
 */
export interface HTTPRequest {
    method: string;
    path: string;
    headers: Record<string, string>;
    query: Record<string, string>;
    body?: unknown;
}
/**
 * HTTP Response interface (library-agnostic)
 */
export interface HTTPResponse {
    status: number;
    headers: Record<string, string>;
    body: string;
}
/**
 * Request handler type
 */
export type RequestHandler = (request: HTTPRequest) => Promise<HTTPResponse>;
/**
 * Server adapter interface
 *
 * Implement this interface to integrate with your chosen HTTP server library.
 */
export interface ServerAdapter {
    /** Start the server */
    start(port: number, handler: RequestHandler): Promise<void>;
    /** Stop the server */
    stop(): Promise<void>;
    /** Check if server is running */
    isRunning(): boolean;
}
/**
 * WebSocket-aware server adapter interface.
 *
 * Extends ServerAdapter with callbacks for WebSocket connections.
 * The adapter manages the raw TCP/WS layer; these callbacks let the
 * UI Bridge server handle message routing and event broadcasting.
 */
export interface WebSocketServerAdapter extends ServerAdapter {
    /** Called when a JSON text frame is received from a WS client. Returns response string or null. */
    onWebSocketMessage?: (connId: string, message: string) => Promise<string | null>;
    /** Called when a new WS connection is established after the HTTP 101 upgrade. */
    onWebSocketConnect?: (connId: string) => void;
    /** Called when a WS connection is closed or drops. */
    onWebSocketDisconnect?: (connId: string) => void;
    /** Send a message to a specific WS connection by ID. */
    sendToConnection?: (connId: string, message: string) => void;
    /** Send a message to all connected WS clients. */
    broadcast?: (message: string) => void;
}
/**
 * Native UI Bridge HTTP Server
 */
export declare class NativeUIBridgeServer {
    private registry;
    private executor;
    private config;
    private handlers;
    private adapter?;
    private running;
    private keepAwakeProvider?;
    /**
     * Per-connection cleanup thunks for in-flight waiters (waitForElement,
     * waitForCondition, ...). Aborted when a client disconnects so the
     * underlying timers/listeners don't leak.
     */
    private pendingWaiters;
    /**
     * Observability ring buffers backing `/control/console-errors` and
     * `/sdk/network-requests`. Allocated unconditionally so the handler can
     * always read them, but the global patches (`install()`) only fire on
     * `start()` when observability is enabled (the dedicated `observability`
     * flag, defaulting to `testHooks`) — builds with both off don't
     * monkey-patch.
     */
    private consoleErrorBuffer;
    private networkRequestBuffer;
    /**
     * Whether the console/network capture should be installed. The dedicated
     * `observability` flag wins when set; otherwise falls back to `testHooks`
     * so consumers predating the flag keep their exact behavior.
     */
    private observabilityEnabled;
    constructor(registry: NativeUIBridgeRegistry, executor: NativeActionExecutor, config?: NativeServerConfig);
    /**
     * Set the server adapter
     */
    setAdapter(adapter: ServerAdapter): void;
    /**
     * Set a navigation provider for programmatic route navigation.
     * This enables `control/page/navigate` and `control/page/back` on native.
     */
    setNavigationProvider(provider: NavigationProvider): void;
    /**
     * Set a route provider for reporting the current navigation route.
     * When set, `control/snapshot` responses include `currentRoute` and `segments`.
     *
     * Also forwards the provider into the registry so the *default*
     * `getSnapshot` handler (and any other call site of
     * `registry.createSnapshot`) reads the route too — without this the
     * cloud-relay/bare-server path returned `currentRoute: null` even when
     * a `RouteTracker` was wired, because that path never installed the
     * server-level handler override below.
     */
    setRouteProvider(provider: RouteProvider): void;
    /**
     * Set a screenshot provider for native screen capture.
     * This enables `control/screenshot` on native.
     */
    setScreenshotProvider(provider: ScreenshotProvider): void;
    /**
     * Set a keep-awake provider for native screen-wake control.
     * This enables `control/keep-awake` and arms the auto-arm hook in
     * handleRequest (every request keeps the screen alive for 60s).
     */
    setKeepAwakeProvider(provider: KeepAwakeProvider): void;
    /**
     * Start the HTTP server
     */
    start(): Promise<void>;
    /**
     * Stop the HTTP server
     */
    stop(): Promise<void>;
    /**
     * Check if server is running
     */
    isRunning(): boolean;
    private eventBridge?;
    /**
     * Set the event bridge for WebSocket event broadcasting and subscriptions.
     */
    setEventBridge(bridge: WebSocketEventBridge): void;
    /**
     * Handle a JSON-RPC message from a WebSocket client.
     * Parses the message, routes to the appropriate handler, and returns
     * a JSON string response (or null for events that need no response).
     */
    handleWebSocketMessage(connId: string, rawMessage: string): Promise<string | null>;
    /**
     * Execute a batch of JSON-RPC requests concurrently.
     */
    handleBatchRequest(batch: JsonRpcRequest[]): Promise<JsonRpcResponse[]>;
    /**
     * Register an in-flight waiter's cleanup thunk under the given connection.
     * Returns an `unregister` thunk that the natural-resolution path should
     * call so the cleanup isn't re-invoked on disconnect.
     */
    private registerWaiter;
    /**
     * Abort all pending waiters associated with a connection. Called by the
     * provider's WS disconnect handler so timers/listeners don't leak after
     * the client goes away.
     */
    abortWaitersForConnection(connId: string): void;
    /**
     * Wait for an element to be registered, or resolve immediately if it already exists.
     * Returns a JsonRpcResponse JSON string.
     */
    private handleWaitForElement;
    /**
     * Wait for an arbitrary element-state predicate to become true.
     *
     * Supported `condition` shapes:
     *   {field: "mounted"|"visible"|"enabled"|"focused", equals: boolean}
     *   {field: "layout", exists: true}
     *   {field: string, equals: unknown}  // generic: state[field] === equals
     *
     * Resolves immediately with `waited:false` if the predicate already
     * holds. Otherwise subscribes to `element:registered` and
     * `element:stateChanged` until the predicate matches or timeout fires.
     */
    private handleWaitForCondition;
    /**
     * Execute a sequence of JSON-RPC steps in order, stopping on first failure.
     * Returns a JsonRpcResponse JSON string with per-step results.
     */
    private handleSequence;
    /**
     * Route a JSON-RPC method string to the appropriate handler using path-style matching.
     *
     * Method strings mirror HTTP routes but without the /ui-bridge/ prefix.
     * Path params are extracted from :name placeholders in the route pattern.
     *
     * Examples:
     *   "health"                                           → handlers.health
     *   "control/snapshot"                                 → handlers.getSnapshot
     *   "control/element/tab-runs/action"                  → handlers.executeAction ({id:'tab-runs'})
     *   "control/component/my-comp/action/submit"          → handlers.executeComponentAction
     */
    private routeMethodToHandler;
    /**
     * Handle incoming HTTP request
     *
     * Exposed as public so that CloudRelayClient can call it directly (without
     * loopback TCP overhead) when processing tunneled requests.
     */
    handleRequest(request: HTTPRequest): Promise<HTTPResponse>;
    /**
     * Route an HTTP request to the appropriate handler using WS_ROUTES.
     *
     * Strips the `/ui-bridge/` prefix from the path, then iterates the shared
     * WS_ROUTES table. Each route's `pattern` is matched against the stripped
     * path via the module-level `parsePath` helper; path params are merged
     * with the request body into a HandlerContext.
     *
     * `httpMethods` disambiguates routes that share a pattern but differ
     * by verb (e.g. GET vs DELETE on `design/style-guide`). A route without
     * `httpMethods` is WS-only and will not be matched on HTTP.
     */
    private routeRequest;
}
/**
 * Create a UI Bridge Native server
 */
export declare function createNativeServer(registry: NativeUIBridgeRegistry, executor: NativeActionExecutor, config?: NativeServerConfig): NativeUIBridgeServer;
/**
 * Example adapter using react-native-http-bridge
 *
 * To use this adapter:
 * 1. Install: npm install react-native-http-bridge
 * 2. Link native modules
 * 3. Create adapter and pass to server
 *
 * ```tsx
 * import httpBridge from 'react-native-http-bridge';
 *
 * const adapter: ServerAdapter = {
 *   start: async (port, handler) => {
 *     httpBridge.start(port, 'ui-bridge', async (request) => {
 *       const response = await handler({
 *         method: request.type,
 *         path: request.url,
 *         headers: request.headers || {},
 *         query: parseQuery(request.url),
 *         body: request.postData ? JSON.parse(request.postData) : undefined,
 *       });
 *       httpBridge.respond(
 *         request.requestId,
 *         response.status,
 *         response.headers['Content-Type'],
 *         response.body
 *       );
 *     });
 *   },
 *   stop: async () => {
 *     httpBridge.stop();
 *   },
 *   isRunning: () => true,
 * };
 *
 * server.setAdapter(adapter);
 * await server.start();
 * ```
 */
//# sourceMappingURL=http-server.d.ts.map