import { type BaseEvent } from '@lensmcp/protocol-types'; import type { EventBus } from '@lensmcp/core'; import type { EnvSink } from './types.js'; /** * Where bridge events go. Both are optional: * • `bus` — publish in-process (tests, or a host that embeds the bridge * inside the same process as its reducers). * • `sink` — forward cross-process over the env transport * (`LENSMCP_EVENT_FILE` / `LENSMCP_UDS` / `LENSMCP_IPC_SOCKET`). * When neither is given, the sink is resolved lazily from env — the * standalone sidecar case, where the MCP server tails the same file. */ export interface BridgeDeps { bus?: EventBus; sink?: EnvSink; /** Session id stamped onto each event. */ sessionId?: string; } export interface BridgeServerOptions extends BridgeDeps { /** Bind host. Default `127.0.0.1`. */ host?: string; /** Bind port. `0` selects an ephemeral port; default {@link DEFAULT_WS_PORT}. */ port?: number; } export interface BridgeServer { /** The actual bound port (resolved even when `port: 0` was requested). */ readonly port: number; readonly host: string; /** Stop accepting connections and release the port. */ close(): Promise; } /** * Build a `publish` function honouring the bus → sink → env-sink → console * precedence. Mirrors the logic the Vite plugin used to inline, lifted here * so the standalone sidecar and the plugin share one path. */ export declare function makePublisher(deps: BridgeDeps): (event: BaseEvent) => void; /** * Parse one raw WebSocket message from the injected client runtime and * forward the resulting event via `publish`. Exported so it can be * exercised over a real WebSocket without booting any bundler. */ export declare function handleClientEnvelope(raw: string, publish: (event: BaseEvent) => void, sessionId?: string): void; /** The tab a raw envelope belongs to, or undefined for a malformed/untagged one. */ export declare function readTabId(raw: string): string | undefined; /** * Stand up the browser-event bridge: a WebSocket server the injected * `@lensmcp/client-runtime` connects to, forwarding every envelope onto * the event bus (in-process or cross-process). Build-agnostic — the Vite * plugin uses it on an ephemeral port; the standalone sidecar uses it on a * fixed port for webpack / Next.js / no-build hosts. * * Resolves once the server is listening, with the actual bound `port`. */ export declare function createBridgeServer(options?: BridgeServerOptions): Promise; /** Allocate an ephemeral free port (used when `port: 0` is requested). */ export declare function findFreePort(): Promise;