UNPKG

@langchain/langgraph-sdk

Version:

Client library for interacting with the LangGraph API

68 lines (67 loc) • 2.77 kB
import { TransportAdapter } from "../transport.js"; import { ProtocolWebSocketTransportOptions } from "./types.js"; import { Command, CommandResponse, ErrorResponse, Message } from "@langchain/protocol"; //#region src/client/stream/transport/websocket.d.ts /** * Transport adapter that speaks the thread-centric protocol over a * bidirectional WebSocket. Bound to a `threadId` at construction or later * via {@link setThreadId} — the socket connects to * `ws://.../threads/:thread_id/stream/events`. * * On unexpected disconnect the adapter reconnects with exponential * backoff (see {@link ProtocolWebSocketTransportOptions.maxReconnectAttempts}), * except when the server closes with a code for a 4xx status other than * 408 or 429 (4403, 4404, 4422), which ends the event stream with an error * carrying that `status`. * The server replays buffered events on the new socket; the SDK * deduplicates by `event_id`. {@link ProtocolWebSocketTransportOptions.onReconnected} * runs after each successful reconnect so `ThreadStream` can re-issue * `subscription.subscribe` commands. */ declare class ProtocolWebSocketTransportAdapter implements TransportAdapter { #private; threadId: string; private readonly queue; private readonly apiUrl; private readonly defaultHeaders?; private readonly onRequest?; private readonly webSocketFactory; private readonly paths?; private readonly maxReconnectAttempts; private readonly onReconnect?; private readonly onConnected?; private readonly reconnectDelayMs; private onReconnected?; private readonly pending; private socket; private closed; private intentionalClose; private reconnectInFlight; constructor(options: ProtocolWebSocketTransportOptions); /** {@inheritDoc TransportAdapter.setThreadId} */ setThreadId(threadId: string): void; /** * Socket URL derives from the currently-bound thread so a single adapter * can follow {@link setThreadId} re-binds; the next {@link open} connects * to the new thread. A fixed `paths.stream` string overrides the default. */ private get streamUrl(); /** * Register a callback invoked after each successful reconnect. Used * by {@link ThreadStream} to re-send active `subscription.subscribe` * commands. */ setOnReconnected(handler: () => void | Promise<void>): void; open(): Promise<void>; send(command: Command): Promise<CommandResponse | ErrorResponse | void>; events(): AsyncIterable<Message>; close(): Promise<void>; private assertBrowserSafeTransportConfig; private sendCommand; private readonly handleMessage; private readonly handleClose; private readonly handleSocketError; } //#endregion export { ProtocolWebSocketTransportAdapter }; //# sourceMappingURL=websocket.d.ts.map