trellis
Version:
Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications
45 lines • 1.75 kB
TypeScript
/**
* Node.js HTTP + WebSocket adapter for the Trellis server.
*
* Runs the same request handler as the Bun.serve path, but via Node's
* `node:http` module and the `ws` library. Used when the host runtime is
* Node (or WebContainer) rather than Bun.
*
* Optional dependency: `ws`. Install only if you intend to run Trellis
* outside of Bun.
*
* @module trellis/server
*/
import type { RealtimeRelayOptions } from '../realtime/relay-server.js';
import type { TrellisHttpServer } from './server-shared.js';
export interface NodeAdapterOptions {
port: number;
hostname?: string;
/**
* Fetch-style request handler. Receives a standard `Request`, returns a
* standard `Response`. The HTTP routing module already produces these.
*/
fetch: (req: Request) => Promise<Response>;
/** Hooks invoked for each WebSocket lifecycle event. */
websocket: {
open: (ws: WsLike) => void | Promise<void>;
message: (ws: WsLike, data: string | Buffer) => void | Promise<void>;
close: (ws: WsLike) => void;
};
/**
* Mount a presence relay on `/rt` (or custom path). Coexists with the graph
* subscription socket at `/realtime` when upgrades are path-scoped.
* Pass full {@link RealtimeRelayOptions} to enable `/blob` via `blobStore`.
*/
attachPresenceRelay?: boolean | RealtimeRelayOptions;
}
/**
* Minimal interface satisfied by both Bun's WebSocket and the `ws` library's
* WebSocket. The subscription manager only uses `readyState` and `send`.
*/
export interface WsLike {
readyState: number;
send(data: string): void;
}
export declare function startNodeServer(opts: NodeAdapterOptions): Promise<TrellisHttpServer>;
//# sourceMappingURL=node-adapter.d.ts.map