/** * WebSocket-backed {@link AppTransport}. * * Browser-safe: uses the standard `WebSocket` global (no `ws` dependency, no * `node:*` imports), so it runs unchanged in an embedded app's iframe and in a * lightweight Node 22+ service. The injected session identity is presented as a * bearer **subprotocol** — the same `skaile-bearer.` scheme the * platform gateway already decodes for runner connections — so the gateway * verifies identity at the WS upgrade, before any `app_hello` is processed. * * Frames are bare JSON of the app-channel messages (no `MessageV2` envelope), * matching the runner peer's on-the-wire convention. * * @category App SDK * @since 3.4.0 */ import type { AppTransport } from "./transport.js"; /** Minimal structural view of the parts of the `WebSocket` API the transport uses. */ type WebSocketLike = { readonly readyState: number; send(data: string): void; close(code?: number, reason?: string): void; addEventListener(type: "open", handler: () => void): void; addEventListener(type: "close", handler: () => void): void; addEventListener(type: "error", handler: () => void): void; addEventListener(type: "message", handler: (ev: { data: unknown; }) => void): void; }; /** Constructor shape for a `WebSocket` implementation (global or injected). */ export type WebSocketFactory = new (url: string, protocols?: string | string[]) => WebSocketLike; /** * Supplies a session identity token for one connection attempt. * * The gateway's token is **single-use** — it is consumed at `app_hello` — so a * reconnecting transport cannot replay the one it opened with. Pass a provider * (typically a call to `resolveAppConnectionParams`) and every `connect()` mints * a fresh token. * * @category App SDK * @since 3.5.0 */ export type SessionTokenProvider = () => string | Promise; /** * Options for {@link createWebSocketAppTransport}. * * @category App SDK * @since 3.4.0 */ export interface WebSocketAppTransportOptions { /** The gateway app-channel URL (e.g. `wss://platform/app-connect`). */ url: string; /** * The injected session identity token, or a {@link SessionTokenProvider} that * yields a fresh one per connection attempt. Presented as the WS bearer * subprotocol; the gateway verifies it and resolves the session/user. * * A bare string cannot survive a reconnect (the gateway consumes the token at * `app_hello`) — pass a provider whenever `reconnect` is enabled on the peer. */ sessionToken: string | SessionTokenProvider; /** * WebSocket implementation. Defaults to the `WebSocket` global (browser / * Node 22+). Injectable for tests or non-standard runtimes. */ WebSocketImpl?: WebSocketFactory; /** Connect timeout in ms. Default 10000. */ connectTimeoutMs?: number; } /** * Create a WebSocket-backed {@link AppTransport}. The session token is sent as a * bearer subprotocol at connect time; app-channel messages are JSON-framed. * * @category App SDK * @since 3.4.0 */ export declare function createWebSocketAppTransport(options: WebSocketAppTransportOptions): AppTransport; export {}; //# sourceMappingURL=ws-transport.d.ts.map