/**
 * Bridges NativeUIBridgeRegistry events to WebSocket clients.
 *
 * Subscribes to all registry event types and broadcasts them as
 * JsonRpcEvent messages to connected WebSocket clients based on
 * their per-connection subscription sets.
 */
import type { NativeUIBridgeRegistry } from '../core/registry';
import type { WebSocketConnection } from './ws-connection';
import type { JsonRpcEvent } from './ws-types';
/**
 * Convert a glob-style pattern (supports `*` / `**` wildcards) to a RegExp.
 * All other regex metacharacters are escaped, so colons and other
 * event-name characters pass through literally.
 *
 *   globToRegex("*")                 → /^.*$/
 *   globToRegex("element:*")         → /^element:.*$/
 *   globToRegex("*:stateChanged")    → /^.*:stateChanged$/
 */
export declare function globToRegex(pattern: string): RegExp;
/** Options for the WebSocketEventBridge constructor. */
export interface WebSocketEventBridgeOptions {
    /** Heartbeat ping interval in ms (default 30000) */
    heartbeatIntervalMs?: number;
    /** Max number of events to retain in the replay history buffer (default 100, 0 disables) */
    maxHistory?: number;
}
export declare class WebSocketEventBridge {
    private connections;
    private throttles;
    private unsubscribers;
    private heartbeatTimer;
    private registry;
    private heartbeatIntervalMs;
    /**
     * True ring buffer for event replay history.
     *
     * `historyBuf` is a fixed-capacity slot array; `historyHead` points at the
     * NEXT write position; `historyCount` is the number of valid slots
     * (clamped to capacity). Append is O(1) — no array shifting.
     */
    private historyBuf;
    private historyHead;
    private historyCount;
    constructor(registry: NativeUIBridgeRegistry, optionsOrHeartbeatMs?: WebSocketEventBridgeOptions | number);
    /** Effective ring buffer capacity. 0 means history is disabled. */
    private get historyCapacity();
    /**
     * Start listening to registry events and broadcasting to WS clients.
     * Also starts the heartbeat timer.
     */
    start(): void;
    /** Stop listening to registry events and clear connections. */
    stop(): void;
    /** Register a new WebSocket connection. */
    addConnection(conn: WebSocketConnection): void;
    /** Remove a WebSocket connection (called on disconnect). */
    removeConnection(connId: string): void;
    /** Get the number of active connections. */
    get connectionCount(): number;
    /**
     * Add event subscriptions for a connection.
     *
     * Event names are stored as glob patterns. Supported forms:
     *   - Exact:  "element:registered"
     *   - Prefix: "element:*"
     *   - Suffix: "*:stateChanged"
     *   - All:    "*"
     *
     * @param throttleMs — if >0, batch rapid events within this window before sending
     */
    handleSubscribe(connId: string, events: string[], throttleMs?: number): boolean;
    /**
     * Remove event subscriptions for a connection.
     * If all subscriptions are cleared, also drops the throttle entry
     * (and any pending flush timer) so a subsequent resubscribe starts clean.
     */
    handleUnsubscribe(connId: string, events: string[]): boolean;
    /**
     * Get the subscription set for a connection.
     * Returns the original pattern strings (not compiled regexes).
     */
    getSubscriptions(connId: string): string[];
    /**
     * Check if a connection is subscribed to a specific event.
     * Matches exact names first (fast path), then tests each stored
     * pattern as a glob against the event type.
     */
    isSubscribed(connId: string, eventType: string): boolean;
    /** Get the throttle window (in ms) configured for a connection, or undefined if none. */
    getThrottleMs(connId: string): number | undefined;
    /**
     * Get recent events from the replay history buffer.
     *
     * @param filter.events — optional list of glob patterns to match event types against
     * @param filter.since — optional timestamp (ms); only events at or after this time
     */
    getHistory(filter?: {
        events?: string[];
        since?: number;
    }): JsonRpcEvent[];
    /**
     * Configure the max history buffer size at runtime. 0 disables history.
     * Reallocates the ring buffer, preserving the most recent
     * min(historyCount, newCapacity) events in chronological order.
     */
    setMaxHistory(maxHistory: number): void;
    private broadcastEvent;
    /** Queue an event for throttled delivery, flushing after the throttle window. */
    private enqueueThrottled;
    private startHeartbeat;
}
//# sourceMappingURL=ws-event-bridge.d.ts.map