/** * WebSocketServerTransport — `ws`-based WebSocket server. * * Accepts one client at a time. Implements ServerTransport from @skaile/workspaces/types. * Built on the `ws` package + `node:http`, both of which run under Node and Bun. */ import type { AgentCommand, AgentEvent, ServerTransport } from "@skaile/workspaces/types"; /** * Options for {@link WebSocketServerTransport}. * * @param port - TCP port to bind to. * @param onLog - Optional callback for internal log lines (client connect/disconnect events). * @param authToken - When set, every upgrade must present this token via the * `skaile-bearer.` subprotocol or the handshake is rejected with * HTTP 401. When unset, no auth is enforced (back-compatible default). * * @docLink packages/transport/dev-guide#websocket-server-transport */ export interface WebSocketServerOptions { port: number; onLog?: (line: string) => void; authToken?: string; } /** * `ServerTransport` implementation backed by the `ws` package on top of a * `node:http` server. * * Enforces a single-client policy: if a new connection arrives while a client is * already connected, the stale connection is closed with code 4001 and replaced. * Incoming frames are parsed as JSON `AgentCommand` messages and fanned out to * registered `onCommand` handlers; outgoing `AgentEvent` objects are JSON-serialised * before sending. Call `listen()` to start accepting connections and `close()` to * shut down cleanly — `close()` terminates the active socket immediately rather * than keeping the event loop alive. * * @example * ```ts * const server = new WebSocketServerTransport({ port: 8080 }); * await server.listen(); * server.onCommand((cmd) => console.log(cmd)); * server.send({ type: 'agent_end' }); * await server.close(); * ``` * * @docLink packages/transport/dev-guide#websocket-server-transport */ export declare class WebSocketServerTransport implements ServerTransport { private httpServer; private wss; private activeClient; private readonly port; private readonly log; private readonly authToken?; private readonly commandHandlers; private readonly connectHandlers; private readonly disconnectHandlers; constructor(options: WebSocketServerOptions); /** Start the server and accept connections. */ listen(): Promise; private handleConnection; /** * Stop the server. * * Terminates the active socket immediately — otherwise a still-connected * client would keep the event loop alive and block process shutdown. */ close(): Promise; send(event: AgentEvent): void; onCommand(handler: (command: AgentCommand) => void): () => void; onConnect(handler: () => void): () => void; onDisconnect(handler: () => void): () => void; get connected(): boolean; private sendRaw; } //# sourceMappingURL=server.d.ts.map