import type { TwinStream } from './twin-fetch.js'; export declare function connectWebSocket(url: string, headers: Record, protocols?: string[]): Promise; export type HttpHandler = (request: Request) => Response | Promise; export type WebSocketPeer = { send: (data: string | Uint8Array) => unknown; close: (code?: number, reason?: string) => unknown; }; export type WebSocketUpgrade = { accepts: (request: Request) => boolean | Promise; /** The subprotocol the server selects for this request, answered in `Sec-WebSocket-Protocol`; none when undefined. */ protocol?: (request: Request) => string | undefined; open: (peer: WebSocketPeer, request: Request) => void; message: (peer: WebSocketPeer, data: string | Uint8Array) => void | Promise; close: (peer: WebSocketPeer) => void; }; export type ServeHttpOptions = { /** Multiplexing infrastructure fronts leave vendor journaling to the downstream twins. */ twinRequestJournal?: boolean; /** Optional persistent transport, with the same callbacks on Node and Bun. */ upgrade?: WebSocketUpgrade; tls?: { key: string | Uint8Array; cert: string | Uint8Array; }; /** the interface to listen on: loopback unless a caller names another. A twin is reached by its * World over loopback; a front that is meant to be reached (a served world, a host) names its own. */ hostname?: string; port?: number; fetch: HttpHandler; /** seconds a connection may idle (Bun honors it; Node's keep-alive timeout is set from it) */ idleTimeout?: number; /** Explicit transport limit in bytes; absent, 128 MiB on both runtimes. */ maxRequestBodySize?: number; /** what a thrown handler answers with; absent, a 500 carrying the error (as Bun.serve) */ error?: (error: Error) => Response | Promise; }; export type HttpServer = { hostname: string; port: number; /** as Bun's: a URL, whose string form ends in `/` — packs build `${server.url}path` on that */ url: URL; /** stop listening; `closeActive` (default true) drops in-flight connections as well */ stop: (closeActive?: boolean) => Promise; }; export declare function setServeDecorator(fn: ((options: ServeHttpOptions) => HttpHandler) | undefined): void; /** The path a World asks a service it booted, when that service's port answers, which boot it belongs to. */ export declare const WORLD_BOOT_PATH = "/__volter/world-boot"; /** The handler serving `port` in this process, when a server made through the seam listens there. */ export declare function servedHandlerOf(port: number): HttpHandler | undefined; export declare function serveHttp(options: ServeHttpOptions): Promise; /** A Node builtin without a static import — `process.getBuiltinModule` (Node 22.3+, Bun): what a * module that also rides into a browser bundle reaches `node:crypto` with. A bare `require()` * is Bun's alone; Node's ESM has none. */ export declare function nodeBuiltin(name: string): T; /** What `serveStream` throws when the runtime has no TCP layer to listen with at all (no `process.getBuiltinModule`, or * no `node:net` behind it), as opposed to a listen that failed (EADDRINUSE, EACCES), which it throws as it came. A * server that can serve without its byte-stream listener (a live ingest beside its HTTP host) falls back on this alone. */ export declare class StreamListenerUnavailable extends Error { } /** A raw-TCP twin's listener (the seam's byte-stream half): its `createTwinStream` served on a TCP port, each * socket one connection, on loopback unless the caller names a hostname. Runtime-neutral, as `serveHttp` is: Node's * `net` reached at call time, never imported. A stream that declares `maxConnections` (a live ingest) is held to it. */ export declare function serveStream(options: { port?: number; hostname?: string; stream: TwinStream; maxConnections?: number; }): Promise<{ port: number; stop: () => Promise; }>; export type WebSocketRelay = { url: string; headers?: Record; outgoing?: (frame: string | Uint8Array) => string | Uint8Array | Promise; }; /** Attach an authenticated native WebSocket relay to an existing Node front. * The shared socket library owns handshake, fragmentation, masking, compression and control frames. * Payload transforms are ordered; unknown vendor messages remain opaque bytes. */ export declare function attachWebSocketRelay(server: import('node:http').Server, route: (request: import('node:http').IncomingMessage) => WebSocketRelay | undefined): Promise<{ stop: () => void; }>;