import { AssembledMessage } from "./messages.js"; import { AgentServerAdapter } from "./transport.js"; import { AgentResult, Channel, Event, InputInjectParams, InputRespondParams, ListCheckpointsParams, ListCheckpointsResult, RunResult, RunStartParams, StateForkParams, StateForkResult, StateGetParams, StateGetResult, SubscribeParams } from "@langchain/protocol"; //#region src/client/stream/types.d.ts interface ExtendedRunStartParams extends RunStartParams { forkFrom?: { checkpointId: string; }; multitaskStrategy?: "reject" | "rollback" | "interrupt" | "enqueue"; } type SubscribeOptions = Omit; type EventMethodByChannel = { values: "values"; updates: "updates"; messages: "messages"; tools: "tools"; custom: "custom"; lifecycle: "lifecycle"; input: "input.requested"; debug: "debug"; checkpoints: "checkpoints"; tasks: "tasks"; }; type EventForChannel = TChannel extends keyof EventMethodByChannel ? Extract : TChannel extends `custom:${string}` ? Extract : never; type EventForChannels = EventForChannel; /** * Maps a subscribable channel to the type yielded by its subscription handle. * * - `"custom:name"` channels yield `unknown` (the raw emitted payload). * - All other channels yield the full protocol `Event`. */ type YieldForChannel = TChannel extends `custom:${string}` ? unknown : EventForChannel; type YieldForChannels = YieldForChannel; /** * Built-in wire transport used by {@link ThreadStream}. * * - `"sse"`: HTTP commands + one SSE event stream per subscription. * Works in browsers without extra setup. * - `"websocket"`: single bidirectional WebSocket. Lower overhead for * long-lived, multi-subscription sessions. */ type ThreadStreamTransportKind = "sse" | "websocket"; /** * Accepted values for `ThreadStreamOptions["transport"]`. * * - A {@link ThreadStreamTransportKind} string picks one of the * built-in factories; `fetch` / `webSocketFactory` tune that path. * - An {@link AgentServerAdapter} bypasses the built-in factories * entirely; the adapter is used for every command and subscription. */ type ThreadStreamTransport = ThreadStreamTransportKind | AgentServerAdapter; /** * Options for {@link ThreadStream} construction. */ interface ThreadStreamOptions { /** * Assistant that this thread runs on. A thread is bound to one * assistant for its lifetime — subsequent `run.start` calls always * use this assistant. */ assistantId: string; /** * How this thread talks to the agent server. Accepts either a * built-in transport string or a custom {@link AgentServerAdapter}: * * - `"sse"`: HTTP commands + one SSE event stream per subscription. * - `"websocket"`: single bidirectional WebSocket. * - an {@link AgentServerAdapter}: custom transport that replaces * the built-in factories entirely. `fetch` / `webSocketFactory` * are ignored in this mode. * * Defaults to the client-level `streamProtocol` * (`"v2-websocket"` → `"websocket"`, otherwise `"sse"`). */ transport?: ThreadStreamTransport; /** * Starting command ID for the internal command counter. Mostly * useful for tests. */ startingCommandId?: number; /** * Optional `fetch` implementation for the built-in SSE transport. * Useful for test environments, custom auth/proxy layers, or * non-global fetch (e.g. Node without a global fetch, or injected * mocks). Ignored for the WebSocket transport and for custom * {@link AgentServerAdapter}s. */ fetch?: typeof fetch; /** * Optional WebSocket factory for the built-in WebSocket transport. * Useful for test environments that don't ship a global `WebSocket`, * or to wrap the socket with custom headers/subprotocols. Ignored * for the SSE transport and for custom {@link AgentServerAdapter}s. */ webSocketFactory?: (url: string) => WebSocket; } interface SessionOrderingState { lastSeenSeq?: number; lastAppliedThroughSeq?: number; lastEventId?: string; } interface EventSubscription extends AsyncIterable { readonly subscriptionId: string; readonly params: SubscribeParams; unsubscribe(): Promise; } interface MessageSubscription extends AsyncIterable { readonly subscriptionId: string; readonly params: SubscribeParams; unsubscribe(): Promise; } interface InputModule { respond(params: InputRespondParams): Promise; inject(params: InputInjectParams): Promise; } interface StateModule { get(params: StateGetParams): Promise; listCheckpoints(params: ListCheckpointsParams): Promise; fork(params: StateForkParams): Promise; } /** * Modules exposed by the high-level {@link ThreadStream} wrapper. */ interface ThreadModules { run: { /** * Start a new run, resume an interrupted run, or inject input into * an active run on this thread. The assistant is fixed by the * {@link ThreadStream} constructor and cannot be changed per-call. */ start(params: Omit): Promise; }; agent: { getTree(params?: { run_id?: string; }): Promise; }; input: InputModule; state: StateModule; } /** * Human-in-the-loop interrupt payload surfaced from lifecycle events. * Matches the in-process `InterruptPayload` type. */ interface InterruptPayload { interruptId: string; payload: TPayload; namespace: string[]; } /** * Remote counterpart of an in-process `run.extensions.` projection. * * Each extension is the client-side view of a compile-time * {@link StreamTransformer} projection. The server auto-forwards named * `StreamChannel.remote(name)` outputs on the `custom:` channel, and * this handle exposes them via two dual interfaces: * * - `AsyncIterable` — iterate every item pushed by a streaming * transformer (e.g. a `StreamChannel`). * - `PromiseLike` — `await` resolves with the final value observed * when the run terminates. For streaming transformers this is the * last item pushed; for final-value transformers it is the single * value emitted on run end. * * Subscribing is lazy: the underlying `custom:` subscription is * opened on first property access and cached. */ interface ThreadExtension extends AsyncIterable, PromiseLike {} /** * Unwrap a single in-process projection value to its observable payload * type: * * - `Promise` / `PromiseLike` → `T` (final-value transformers) * - `StreamChannel` / `AsyncIterable` → `T` (streaming transformers) * - anything else → the value itself * * This lets a `ThreadStream` generic accept the same shape * that `graph.streamEvents(..., { version: "v3" })` returns in-process * (via `InferExtensions` from `@langchain/langgraph`), * without forcing users to redeclare payload types on the remote side. */ type UnwrapExtension = T extends PromiseLike ? U : T extends AsyncIterable ? U : T; /** * Keyed map of {@link ThreadExtension} handles, typed off a declared * transformer projection shape. * * Used as the return type of `ThreadStream.extensions`. `TExtensions` * is expected to match the in-process `run.extensions` shape (i.e. the * output of `InferExtensions` from * `@langchain/langgraph`); each value type is unwrapped via * {@link UnwrapExtension} so `thread.extensions.foo` resolves with the * transformer's emitted payload, not the in-process `Promise` / * `StreamChannel` wrapper. * * Access any string key to obtain a `ThreadExtension`; keys * that appear in `TExtensions` narrow to their declared payload type. */ type ThreadExtensions = Record> = { readonly [K in keyof TExtensions]: ThreadExtension> } & { readonly [name: string]: ThreadExtension; }; //#endregion export { EventForChannel, EventForChannels, EventMethodByChannel, EventSubscription, ExtendedRunStartParams, InputModule, InterruptPayload, MessageSubscription, SessionOrderingState, StateModule, SubscribeOptions, ThreadExtension, ThreadExtensions, ThreadModules, ThreadStreamOptions, ThreadStreamTransport, ThreadStreamTransportKind, UnwrapExtension, YieldForChannel, YieldForChannels }; //# sourceMappingURL=types.d.ts.map