@langchain/react 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -8,10 +8,10 @@ import { UseSuspenseStreamReturn, useSuspenseStream } from "./suspense-stream.cj
8
8
  import { StreamProvider, StreamProviderCustomProps, StreamProviderProps, useStreamContext } from "./context.cjs";
9
9
  import { AIMessage, ToolMessage } from "@langchain/core/messages";
10
10
  import { AnyHeadlessToolImplementation, DefaultToolCall, DefaultToolCall as DefaultToolCall$1, FlushPendingHeadlessToolInterruptsOptions, HeadlessToolImplementation, HeadlessToolInterrupt, HttpAgentServerAdapter, HttpAgentServerAdapterOptions, OnToolCallback, ToolCallState, ToolCallWithResult as ToolCallWithResult$1, ToolCallsFromTools, ToolEvent, executeHeadlessTool, filterOutHeadlessToolInterrupts, findHeadlessTool, flushPendingHeadlessToolInterrupts, handleHeadlessToolInterrupt, headlessToolResumeCommand, isHeadlessToolInterrupt, parseHeadlessToolInterruptPayload } from "@langchain/langgraph-sdk";
11
- import { AgentServerAdapter, AnyMediaHandle, AssembledToolCall, AssembledToolCallFromTool as ToolCallFromTool, AudioMedia, Channel, Event, FileMedia, ImageMedia, InferStateType, InferSubagentStates, InferToolCalls, InferToolOutput, MediaAssemblyError, MediaAssemblyErrorKind, MediaBase, MediaBlockType, MessageMetadata, MessageMetadataMap, StreamSubmitOptions, SubagentDiscoverySnapshot, SubgraphDiscoverySnapshot, ToolCallStatus, VideoMedia, WidenUpdateMessages } from "@langchain/langgraph-sdk/stream";
11
+ import { AgentServerAdapter, AnyMediaHandle, AssembledToolCall, AssembledToolCallFromTool as ToolCallFromTool, AudioMedia, Channel, Event, FileMedia, ImageMedia, InferStateType, InferSubagentStates, InferToolCalls, InferToolOutput, MediaAssemblyError, MediaAssemblyErrorKind, MediaBase, MediaBlockType, MessageMetadata, MessageMetadataMap, StreamStopOptions, StreamSubmitOptions, SubagentDiscoverySnapshot, SubgraphDiscoverySnapshot, ToolCallStatus, VideoMedia, WidenUpdateMessages } from "@langchain/langgraph-sdk/stream";
12
12
 
13
13
  //#region src/index.d.ts
14
14
  type ToolCallWithResult<ToolCall = DefaultToolCall$1> = ToolCallWithResult$1<ToolCall, ToolMessage, AIMessage>;
15
15
  //#endregion
16
- export { type AgentServerAdapter, type AgentServerOptions, type AnyHeadlessToolImplementation, type AnyMediaHandle, type AnyStream, type AssembledToolCall, type AudioMedia, type AudioPlayerHandle, type Channel, type CustomAdapterOptions, type DefaultToolCall, type Event, type FileMedia, type FlushPendingHeadlessToolInterruptsOptions, type HeadlessToolImplementation, type HeadlessToolInterrupt, HttpAgentServerAdapter, type HttpAgentServerAdapterOptions, type ImageMedia, type InferStateType, type InferSubagentStates, type InferToolCalls, type InferToolOutput, MediaAssemblyError, type MediaAssemblyErrorKind, type MediaBase, type MediaBlockType, type MessageMetadata, type MessageMetadataMap, type OnToolCallback, type PlayerStatus, STREAM_CONTROLLER, type SelectorTarget, StreamProvider, type StreamProviderCustomProps, type StreamProviderProps, type StreamSubmitOptions, type SubagentDiscoverySnapshot, type SubgraphDiscoverySnapshot, type SubmissionQueueEntry, type SubmissionQueueSnapshot, type ToolCallFromTool, type ToolCallState, type ToolCallStatus, ToolCallWithResult, type ToolCallsFromTools, type ToolEvent, type UseAudioPlayerOptions, type UseStreamOptions, type UseStreamResult, type UseStreamReturn, type UseSubmissionQueueReturn, type UseSuspenseStreamReturn, type UseVideoPlayerOptions, type VideoMedia, type VideoPlayerHandle, type WidenUpdateMessages, executeHeadlessTool, filterOutHeadlessToolInterrupts, findHeadlessTool, flushPendingHeadlessToolInterrupts, handleHeadlessToolInterrupt, headlessToolResumeCommand, isHeadlessToolInterrupt, parseHeadlessToolInterruptPayload, useAudio, useAudioPlayer, useChannel, useExtension, useFiles, useImages, useMediaURL, useMessageMetadata, useMessages, useProjection, useStream, useStreamContext, useSubmissionQueue, useSuspenseStream, useToolCalls, useValues, useVideo, useVideoPlayer };
16
+ export { type AgentServerAdapter, type AgentServerOptions, type AnyHeadlessToolImplementation, type AnyMediaHandle, type AnyStream, type AssembledToolCall, type AudioMedia, type AudioPlayerHandle, type Channel, type CustomAdapterOptions, type DefaultToolCall, type Event, type FileMedia, type FlushPendingHeadlessToolInterruptsOptions, type HeadlessToolImplementation, type HeadlessToolInterrupt, HttpAgentServerAdapter, type HttpAgentServerAdapterOptions, type ImageMedia, type InferStateType, type InferSubagentStates, type InferToolCalls, type InferToolOutput, MediaAssemblyError, type MediaAssemblyErrorKind, type MediaBase, type MediaBlockType, type MessageMetadata, type MessageMetadataMap, type OnToolCallback, type PlayerStatus, STREAM_CONTROLLER, type SelectorTarget, StreamProvider, type StreamProviderCustomProps, type StreamProviderProps, type StreamStopOptions, type StreamSubmitOptions, type SubagentDiscoverySnapshot, type SubgraphDiscoverySnapshot, type SubmissionQueueEntry, type SubmissionQueueSnapshot, type ToolCallFromTool, type ToolCallState, type ToolCallStatus, ToolCallWithResult, type ToolCallsFromTools, type ToolEvent, type UseAudioPlayerOptions, type UseStreamOptions, type UseStreamResult, type UseStreamReturn, type UseSubmissionQueueReturn, type UseSuspenseStreamReturn, type UseVideoPlayerOptions, type VideoMedia, type VideoPlayerHandle, type WidenUpdateMessages, executeHeadlessTool, filterOutHeadlessToolInterrupts, findHeadlessTool, flushPendingHeadlessToolInterrupts, handleHeadlessToolInterrupt, headlessToolResumeCommand, isHeadlessToolInterrupt, parseHeadlessToolInterruptPayload, useAudio, useAudioPlayer, useChannel, useExtension, useFiles, useImages, useMediaURL, useMessageMetadata, useMessages, useProjection, useStream, useStreamContext, useSubmissionQueue, useSuspenseStream, useToolCalls, useValues, useVideo, useVideoPlayer };
17
17
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;KAoGY,kBAAA,YAA8B,iBAAA,IACxC,oBAAA,CAAoB,QAAA,EAAU,WAAA,EAAiB,SAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;KAqGY,kBAAA,YAA8B,iBAAA,IACxC,oBAAA,CAAoB,QAAA,EAAU,WAAA,EAAiB,SAAA"}
package/dist/index.d.ts CHANGED
@@ -7,11 +7,11 @@ import { UseVideoPlayerOptions, VideoPlayerHandle, useVideoPlayer } from "./use-
7
7
  import { UseSuspenseStreamReturn, useSuspenseStream } from "./suspense-stream.js";
8
8
  import { StreamProvider, StreamProviderCustomProps, StreamProviderProps, useStreamContext } from "./context.js";
9
9
  import { AnyHeadlessToolImplementation, DefaultToolCall, DefaultToolCall as DefaultToolCall$1, FlushPendingHeadlessToolInterruptsOptions, HeadlessToolImplementation, HeadlessToolInterrupt, HttpAgentServerAdapter, HttpAgentServerAdapterOptions, OnToolCallback, ToolCallState, ToolCallWithResult as ToolCallWithResult$1, ToolCallsFromTools, ToolEvent, executeHeadlessTool, filterOutHeadlessToolInterrupts, findHeadlessTool, flushPendingHeadlessToolInterrupts, handleHeadlessToolInterrupt, headlessToolResumeCommand, isHeadlessToolInterrupt, parseHeadlessToolInterruptPayload } from "@langchain/langgraph-sdk";
10
- import { AgentServerAdapter, AnyMediaHandle, AssembledToolCall, AssembledToolCallFromTool as ToolCallFromTool, AudioMedia, Channel, Event, FileMedia, ImageMedia, InferStateType, InferSubagentStates, InferToolCalls, InferToolOutput, MediaAssemblyError, MediaAssemblyErrorKind, MediaBase, MediaBlockType, MessageMetadata, MessageMetadataMap, StreamSubmitOptions, SubagentDiscoverySnapshot, SubgraphDiscoverySnapshot, ToolCallStatus, VideoMedia, WidenUpdateMessages } from "@langchain/langgraph-sdk/stream";
10
+ import { AgentServerAdapter, AnyMediaHandle, AssembledToolCall, AssembledToolCallFromTool as ToolCallFromTool, AudioMedia, Channel, Event, FileMedia, ImageMedia, InferStateType, InferSubagentStates, InferToolCalls, InferToolOutput, MediaAssemblyError, MediaAssemblyErrorKind, MediaBase, MediaBlockType, MessageMetadata, MessageMetadataMap, StreamStopOptions, StreamSubmitOptions, SubagentDiscoverySnapshot, SubgraphDiscoverySnapshot, ToolCallStatus, VideoMedia, WidenUpdateMessages } from "@langchain/langgraph-sdk/stream";
11
11
  import { AIMessage, ToolMessage } from "@langchain/core/messages";
12
12
 
13
13
  //#region src/index.d.ts
14
14
  type ToolCallWithResult<ToolCall = DefaultToolCall$1> = ToolCallWithResult$1<ToolCall, ToolMessage, AIMessage>;
15
15
  //#endregion
16
- export { type AgentServerAdapter, type AgentServerOptions, type AnyHeadlessToolImplementation, type AnyMediaHandle, type AnyStream, type AssembledToolCall, type AudioMedia, type AudioPlayerHandle, type Channel, type CustomAdapterOptions, type DefaultToolCall, type Event, type FileMedia, type FlushPendingHeadlessToolInterruptsOptions, type HeadlessToolImplementation, type HeadlessToolInterrupt, HttpAgentServerAdapter, type HttpAgentServerAdapterOptions, type ImageMedia, type InferStateType, type InferSubagentStates, type InferToolCalls, type InferToolOutput, MediaAssemblyError, type MediaAssemblyErrorKind, type MediaBase, type MediaBlockType, type MessageMetadata, type MessageMetadataMap, type OnToolCallback, type PlayerStatus, STREAM_CONTROLLER, type SelectorTarget, StreamProvider, type StreamProviderCustomProps, type StreamProviderProps, type StreamSubmitOptions, type SubagentDiscoverySnapshot, type SubgraphDiscoverySnapshot, type SubmissionQueueEntry, type SubmissionQueueSnapshot, type ToolCallFromTool, type ToolCallState, type ToolCallStatus, ToolCallWithResult, type ToolCallsFromTools, type ToolEvent, type UseAudioPlayerOptions, type UseStreamOptions, type UseStreamResult, type UseStreamReturn, type UseSubmissionQueueReturn, type UseSuspenseStreamReturn, type UseVideoPlayerOptions, type VideoMedia, type VideoPlayerHandle, type WidenUpdateMessages, executeHeadlessTool, filterOutHeadlessToolInterrupts, findHeadlessTool, flushPendingHeadlessToolInterrupts, handleHeadlessToolInterrupt, headlessToolResumeCommand, isHeadlessToolInterrupt, parseHeadlessToolInterruptPayload, useAudio, useAudioPlayer, useChannel, useExtension, useFiles, useImages, useMediaURL, useMessageMetadata, useMessages, useProjection, useStream, useStreamContext, useSubmissionQueue, useSuspenseStream, useToolCalls, useValues, useVideo, useVideoPlayer };
16
+ export { type AgentServerAdapter, type AgentServerOptions, type AnyHeadlessToolImplementation, type AnyMediaHandle, type AnyStream, type AssembledToolCall, type AudioMedia, type AudioPlayerHandle, type Channel, type CustomAdapterOptions, type DefaultToolCall, type Event, type FileMedia, type FlushPendingHeadlessToolInterruptsOptions, type HeadlessToolImplementation, type HeadlessToolInterrupt, HttpAgentServerAdapter, type HttpAgentServerAdapterOptions, type ImageMedia, type InferStateType, type InferSubagentStates, type InferToolCalls, type InferToolOutput, MediaAssemblyError, type MediaAssemblyErrorKind, type MediaBase, type MediaBlockType, type MessageMetadata, type MessageMetadataMap, type OnToolCallback, type PlayerStatus, STREAM_CONTROLLER, type SelectorTarget, StreamProvider, type StreamProviderCustomProps, type StreamProviderProps, type StreamStopOptions, type StreamSubmitOptions, type SubagentDiscoverySnapshot, type SubgraphDiscoverySnapshot, type SubmissionQueueEntry, type SubmissionQueueSnapshot, type ToolCallFromTool, type ToolCallState, type ToolCallStatus, ToolCallWithResult, type ToolCallsFromTools, type ToolEvent, type UseAudioPlayerOptions, type UseStreamOptions, type UseStreamResult, type UseStreamReturn, type UseSubmissionQueueReturn, type UseSuspenseStreamReturn, type UseVideoPlayerOptions, type VideoMedia, type VideoPlayerHandle, type WidenUpdateMessages, executeHeadlessTool, filterOutHeadlessToolInterrupts, findHeadlessTool, flushPendingHeadlessToolInterrupts, handleHeadlessToolInterrupt, headlessToolResumeCommand, isHeadlessToolInterrupt, parseHeadlessToolInterruptPayload, useAudio, useAudioPlayer, useChannel, useExtension, useFiles, useImages, useMediaURL, useMessageMetadata, useMessages, useProjection, useStream, useStreamContext, useSubmissionQueue, useSuspenseStream, useToolCalls, useValues, useVideo, useVideoPlayer };
17
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;KAoGY,kBAAA,YAA8B,iBAAA,IACxC,oBAAA,CAAoB,QAAA,EAAU,WAAA,EAAiB,SAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;KAqGY,kBAAA,YAA8B,iBAAA,IACxC,oBAAA,CAAoB,QAAA,EAAU,WAAA,EAAiB,SAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"selectors.cjs","names":["NAMESPACE_SEPARATOR","useProjection","getRegistry","STREAM_CONTROLLER"],"sources":["../src/selectors.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\n\"use client\";\n\nimport { useMemo, useSyncExternalStore } from \"react\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport type {\n MessageMetadata,\n MessageMetadataMap,\n SubmissionQueueEntry,\n SubmissionQueueSnapshot,\n} from \"@langchain/langgraph-sdk/stream\";\nimport {\n NAMESPACE_SEPARATOR,\n audioProjection,\n channelProjection,\n extensionProjection,\n filesProjection,\n imagesProjection,\n messagesProjection,\n toolCallsProjection,\n valuesProjection,\n videoProjection,\n type AssembledToolCall,\n type AudioMedia,\n type Channel,\n type ChannelProjectionOptions,\n type Event,\n type FileMedia,\n type ImageMedia,\n type InferToolCalls,\n type InferStateType,\n type SubagentDiscoverySnapshot,\n type SubgraphDiscoverySnapshot,\n type VideoMedia,\n} from \"@langchain/langgraph-sdk/stream\";\nimport {\n getRegistry,\n STREAM_CONTROLLER,\n type UseStreamReturn,\n} from \"./use-stream.js\";\nimport { useProjection } from \"./use-projection.js\";\n\n/**\n * Selector hooks don't need to carry `InterruptType` /\n * `ConfigurableType` — they only ever read state. Accepting a\n * `StateType`-parameterised stream (with the other two generics\n * widened to `any`) lets callers keep their full\n * `useStream<State, Interrupt, Configurable>()` handle\n * without re-declaring the interrupt / configurable shapes at every\n * selector call site.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype StreamHandle<StateType extends object> = UseStreamReturn<\n StateType,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any\n>;\n\n/**\n * What a selector hook can be targeted at. Callers can pass any of:\n * - `undefined` — root namespace (cheap: served by the always-on root store)\n * - a {@link SubagentDiscoverySnapshot} — the snapshot returned by `stream.subagents.get(...)`\n * - a {@link SubgraphDiscoverySnapshot} — the snapshot returned by `stream.subgraphs.get(...)`\n * - an explicit `{ namespace: string[] }` — any other namespaced scope\n * - a raw `string[]` — escape hatch identical to the object form\n */\nexport type SelectorTarget =\n | undefined\n | null\n | readonly string[]\n | { namespace: readonly string[] }\n | SubagentDiscoverySnapshot\n | SubgraphDiscoverySnapshot;\n\nfunction resolveNamespace(target: SelectorTarget): readonly string[] {\n if (target == null) return EMPTY_NAMESPACE;\n if (Array.isArray(target)) return target;\n const obj = target as { namespace?: readonly string[] };\n return obj.namespace ?? EMPTY_NAMESPACE;\n}\n\nconst EMPTY_NAMESPACE: readonly string[] = [];\n\nfunction isRoot(namespace: readonly string[]): boolean {\n return namespace.length === 0;\n}\n\nfunction namespaceKey(namespace: readonly string[]): string {\n return namespace.join(NAMESPACE_SEPARATOR);\n}\n\n// The stream type we accept for selectors — purposely loose so\n// selector hooks remain callable from components that don't carry\n// the exact State/Interrupt/Configurable generics. We use `any` for\n// all three generics because `UseStreamReturn` is\n// invariant in `State` and `Configurable` (they flow through both\n// reader and writer positions), so a concrete\n// `useStream<typeof agent>()` handle wouldn't flow into\n// a `<object, unknown, object>` slot otherwise.\n//\n// Typed selectors (`useValues<S>` etc.) use {@link StreamHandle}\n// above so the concrete `StateType` flows into the return; hooks\n// that don't depend on state (`useMessages`, `useAudio`, …) stay on\n// `AnyStream` for maximum flexibility.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyStream = UseStreamReturn<any, any, any>;\n\n/**\n * Subscribe to a scoped `messages` stream. Pass `stream` and\n * optionally a subagent/subgraph snapshot (or any namespaced target).\n *\n * Contract:\n * - At the root (no target) this returns `stream.messages` directly\n * — no extra subscription is opened. `stream.messages` is the\n * live merge of `messages`-channel token deltas and\n * `values.messages` snapshots (see\n * {@link UseStreamReturn.messages}), so token-by-token\n * streaming here depends on the backend emitting `messages`\n * channel events. Backends that only emit `values` updates will\n * render full turns at once rather than streaming.\n * - For any other namespace, the mount triggers a ref-counted\n * `messages` subscription scoped to that namespace. Unmounting\n * the last component that watches this namespace closes the\n * subscription automatically.\n *\n * Messages are always `BaseMessage` class instances from\n * `@langchain/core/messages`.\n */\nexport function useMessages(\n stream: AnyStream,\n target?: SelectorTarget\n): BaseMessage[] {\n const namespace = resolveNamespace(target);\n const key = `messages|${namespaceKey(namespace)}`;\n const registry = isRoot(namespace) ? null : getRegistry(stream);\n const scoped = useProjection<BaseMessage[]>(\n registry,\n () => messagesProjection(namespace),\n key,\n EMPTY_MESSAGES\n );\n return isRoot(namespace) ? stream.messages : scoped;\n}\n\nconst EMPTY_MESSAGES: BaseMessage[] = [];\n\n/**\n * Subscribe to a scoped `tools` (tool-call) stream. Same target and\n * lifecycle rules as {@link useMessages}; at the root this just returns\n * `stream.toolCalls`.\n *\n * The optional generic `T` can be passed to narrow the type of\n * assembled tool calls on the returned array. Accepts either:\n * - an agent brand (`typeof agent`) — union is derived from the\n * agent's declared tools via {@link InferToolCalls};\n * - an array of LangGraph tools (`typeof tools`) — union is derived\n * from {@link InferToolCalls} (parallel to {@link ToolCallsFromTools}).\n *\n * When omitted, returns the plain `AssembledToolCall[]` union used by\n * the controller.\n */\nexport function useToolCalls(\n stream: AnyStream,\n target?: SelectorTarget\n): AssembledToolCall[];\nexport function useToolCalls<T>(\n stream: AnyStream,\n target?: SelectorTarget\n): InferToolCalls<T>[];\nexport function useToolCalls(\n stream: AnyStream,\n target?: SelectorTarget\n): AssembledToolCall[] {\n const namespace = resolveNamespace(target);\n const key = `toolCalls|${namespaceKey(namespace)}`;\n const registry = isRoot(namespace) ? null : getRegistry(stream);\n const scoped = useProjection<AssembledToolCall[]>(\n registry,\n () => toolCallsProjection(namespace),\n key,\n EMPTY_TOOLCALLS\n );\n return isRoot(namespace) ? stream.toolCalls : scoped;\n}\n\nconst EMPTY_TOOLCALLS: AssembledToolCall[] = [];\n\n/**\n * Subscribe to a scoped `values` stream — most-recent state payload\n * for a namespace. Equivalent to reading `stream.values` at the root.\n *\n * When the payload carries a `messages` array, it is coerced to\n * `BaseMessage` instances to keep parity with the root projection.\n *\n * Typing:\n * - **Root** (`useValues(stream)`): returns the `StateType` declared\n * on the parent `useStream<State>()` — no explicit\n * generic required. Non-nullable because the root snapshot always\n * carries `values` (falling back to `initialValues ?? {}`).\n * - **Scoped** (`useValues(stream, target)`): the scoped payload can\n * have a different shape than the root state (e.g. a subagent\n * returning its own substate). Callers should annotate the\n * expected shape explicitly: `useValues<SubagentState>(stream, sub)`.\n * Defaults to `unknown` when not annotated.\n */\nexport function useValues<StateType extends object>(\n stream: StreamHandle<StateType>\n): StateType;\n/**\n * Explicit-generic override. Accepts:\n * - an agent brand or compiled graph (unwrapped via\n * {@link InferStateType});\n * - a plain state shape (returned as-is).\n *\n * The root-call form is non-nullable (the root snapshot is always\n * present); the scoped form returns `T | undefined` because a\n * projection may not have emitted a payload yet.\n */\nexport function useValues<T>(stream: AnyStream): InferStateType<T>;\nexport function useValues<T = unknown>(\n stream: AnyStream,\n target: SelectorTarget,\n options?: { messagesKey?: string }\n): T | undefined;\nexport function useValues(\n stream: AnyStream,\n target?: SelectorTarget,\n options?: { messagesKey?: string }\n): unknown {\n const namespace = resolveNamespace(target);\n const messagesKey = options?.messagesKey ?? \"messages\";\n const key = `values|${messagesKey}|${namespaceKey(namespace)}`;\n const registry = isRoot(namespace) ? null : getRegistry(stream);\n const scoped = useProjection<unknown>(\n registry,\n () => valuesProjection<unknown>(namespace, messagesKey),\n key,\n undefined\n );\n return isRoot(namespace) ? stream.values : scoped;\n}\n\n/**\n * Subscribe to a `custom:<name>` stream extension — most-recent\n * payload emitted by the transformer, scoped to the target namespace.\n */\nexport function useExtension<T = unknown>(\n stream: AnyStream,\n name: string,\n target?: SelectorTarget\n): T | undefined {\n const namespace = resolveNamespace(target);\n const key = `extension|${name}|${namespaceKey(namespace)}`;\n return useProjection<T | undefined>(\n getRegistry(stream),\n () => extensionProjection<T>(name, namespace),\n key,\n undefined\n );\n}\n\n/**\n * Raw-events escape hatch. Subscribes to one or more channels at a\n * namespace and returns a bounded buffer of raw protocol events.\n * Prefer {@link useMessages} / {@link useToolCalls} / {@link useValues}\n * for the common cases.\n */\n/**\n * Subscribe to a scoped audio-media stream. Returns an array of\n * {@link AudioMedia} handles, one per message containing at least one\n * `AudioBlock` in the target namespace.\n *\n * Each handle is yielded on its first matching `content-block-start`,\n * exposes `.partialBytes` for live access, settles `.blob` /\n * `.objectURL` / `.transcript` on `message-finish`, and surfaces\n * fail-loud errors via `.error`.\n *\n * Pair with {@link useMediaURL} to turn a handle into an `<audio src>`.\n */\nexport function useAudio(\n stream: AnyStream,\n target?: SelectorTarget\n): AudioMedia[] {\n const namespace = resolveNamespace(target);\n const key = `audio|${namespaceKey(namespace)}`;\n return useProjection<AudioMedia[]>(\n getRegistry(stream),\n () => audioProjection(namespace),\n key,\n EMPTY_AUDIO\n );\n}\n\nconst EMPTY_AUDIO: AudioMedia[] = [];\n\n/**\n * Subscribe to a scoped image-media stream. See {@link useAudio} for\n * shared semantics; pair with {@link useMediaURL} for `<img src>`.\n */\nexport function useImages(\n stream: AnyStream,\n target?: SelectorTarget\n): ImageMedia[] {\n const namespace = resolveNamespace(target);\n const key = `images|${namespaceKey(namespace)}`;\n return useProjection<ImageMedia[]>(\n getRegistry(stream),\n () => imagesProjection(namespace),\n key,\n EMPTY_IMAGES\n );\n}\n\nconst EMPTY_IMAGES: ImageMedia[] = [];\n\n/**\n * Subscribe to a scoped video-media stream. See {@link useAudio} for\n * shared semantics; pair with {@link useMediaURL} for `<video src>`.\n */\nexport function useVideo(\n stream: AnyStream,\n target?: SelectorTarget\n): VideoMedia[] {\n const namespace = resolveNamespace(target);\n const key = `video|${namespaceKey(namespace)}`;\n return useProjection<VideoMedia[]>(\n getRegistry(stream),\n () => videoProjection(namespace),\n key,\n EMPTY_VIDEO\n );\n}\n\nconst EMPTY_VIDEO: VideoMedia[] = [];\n\n/**\n * Subscribe to a scoped file-media stream. See {@link useAudio} for\n * shared semantics; pair with {@link useMediaURL} for an\n * `<a download href>` target.\n */\nexport function useFiles(\n stream: AnyStream,\n target?: SelectorTarget\n): FileMedia[] {\n const namespace = resolveNamespace(target);\n const key = `files|${namespaceKey(namespace)}`;\n return useProjection<FileMedia[]>(\n getRegistry(stream),\n () => filesProjection(namespace),\n key,\n EMPTY_FILES\n );\n}\n\nconst EMPTY_FILES: FileMedia[] = [];\n\nexport type UseChannelOptions = ChannelProjectionOptions;\n\nexport function useChannel(\n stream: AnyStream,\n channels: readonly Channel[],\n target?: SelectorTarget,\n options?: UseChannelOptions\n): Event[] {\n const namespace = resolveNamespace(target);\n const channelKey = useMemo(() => [...channels].sort().join(\",\"), [channels]);\n const key = `channel|${options?.bufferSize ?? \"default\"}|${(options?.replay ?? true) ? \"replay\" : \"live\"}|${channelKey}|${namespaceKey(namespace)}`;\n return useProjection<Event[]>(\n getRegistry(stream),\n () => channelProjection(channels, namespace, options),\n key,\n EMPTY_EVENTS\n );\n}\n\nconst EMPTY_EVENTS: Event[] = [];\n\n/**\n * Read metadata recorded for a specific message id — today exposes\n * `parentCheckpointId`, the checkpoint the message was first seen on.\n * Designed for fork / edit flows:\n *\n * ```tsx\n * const { parentCheckpointId } = useMessageMetadata(stream, msg.id) ?? {};\n * if (parentCheckpointId) {\n * await stream.submit(input, { forkFrom: { checkpointId: parentCheckpointId } });\n * }\n * ```\n *\n * Returns `undefined` when the id isn't known yet (e.g. the server\n * hasn't emitted `parent_checkpoint` for that message, or the message\n * arrived via `messages`-channel deltas only and no `values` snapshot\n * has landed for it yet).\n */\nexport function useMessageMetadata(\n stream: AnyStream,\n messageId: string | undefined\n): MessageMetadata | undefined {\n const store = stream[STREAM_CONTROLLER].messageMetadataStore;\n const snapshot = useSyncExternalStore<MessageMetadataMap>(\n store.subscribe,\n store.getSnapshot,\n store.getSnapshot\n );\n return messageId == null ? undefined : snapshot.get(messageId);\n}\n\n/**\n * Reactive handle on the server-side submission queue.\n *\n * Populated when `submit()` is invoked with `multitaskStrategy:\n * \"enqueue\"` while another run is in flight. The returned object is\n * stable per snapshot so consumers can pass `entries` straight into a\n * `<Fragment key={e.id}>` list without extra memoisation.\n *\n * Today the queue is maintained client-side; once the server starts\n * emitting a dedicated queue channel (roadmap A0.3) the controller\n * will mirror that state directly — the hook surface will not change.\n */\nexport interface UseSubmissionQueueReturn<\n StateType extends object = Record<string, unknown>,\n> {\n readonly entries: SubmissionQueueSnapshot<StateType>;\n readonly size: number;\n cancel(id: string): Promise<boolean>;\n clear(): Promise<void>;\n}\n\nexport function useSubmissionQueue<StateType extends object>(\n stream: StreamHandle<StateType>\n): UseSubmissionQueueReturn<StateType>;\nexport function useSubmissionQueue(stream: AnyStream): UseSubmissionQueueReturn;\nexport function useSubmissionQueue(\n stream: AnyStream\n): UseSubmissionQueueReturn {\n const controller = stream[STREAM_CONTROLLER];\n const store = controller.queueStore;\n const entries = useSyncExternalStore<SubmissionQueueSnapshot>(\n store.subscribe,\n store.getSnapshot,\n store.getSnapshot\n );\n return useMemo<UseSubmissionQueueReturn>(\n () => ({\n entries,\n size: entries.length,\n cancel: (id) => controller.cancelQueued(id),\n clear: () => controller.clearQueue(),\n }),\n [entries, controller]\n );\n}\n\nexport type { SubmissionQueueEntry, SubmissionQueueSnapshot };\n"],"mappings":";;;;;;AA6EA,SAAS,iBAAiB,QAA2C;AACnE,KAAI,UAAU,KAAM,QAAO;AAC3B,KAAI,MAAM,QAAQ,OAAO,CAAE,QAAO;AAElC,QADY,OACD,aAAa;;AAG1B,MAAM,kBAAqC,EAAE;AAE7C,SAAS,OAAO,WAAuC;AACrD,Q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AAa,UAAU;AACjJ,QAAOD,uBAAAA,cACLC,mBAAAA,YAAY,OAAO,SAAA,GAAA,gCAAA,mBACK,UAAU,WAAW,QAAQ,EACrD,KACA,aACD;;AAGH,MAAM,eAAwB,EAAE;;;;;;;;;;;;;;;;;;AAmBhC,SAAgB,mBACd,QACA,WAC6B;CAC7B,MAAM,QAAQ,OAAOC,mBAAAA,mBAAmB;CACxC,MAAM,YAAA,GAAA,MAAA,sBACJ,MAAM,WACN,MAAM,aACN,MAAM,YACP;AACD,QAAO,aAAa,OAAO,KAAA,IAAY,SAAS,IAAI,UAAU;;AA4BhE,SAAgB,mBACd,QAC0B;CAC1B,MAAM,aAAa,OAAOA,mBAAAA;CAC1B,MAAM,QAAQ,WAAW;CACzB,MAAM,WAAA,GAAA,MAAA,sBACJ,MAAM,WACN,MAAM,aACN,MAAM,YACP;AACD,SAAA,GAAA,MAAA,gBACS;EACL;EACA,MAAM,QAAQ;EACd,SAAS,OAAO,WAAW,aAAa,GAAG;EAC3C,aAAa,WAAW,YAAY;EACrC,GACD,CAAC,SAAS,WAAW,CACtB"}
1
+ {"version":3,"file":"selectors.cjs","names":["NAMESPACE_SEPARATOR","useProjection","getRegistry","STREAM_CONTROLLER"],"sources":["../src/selectors.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\n\"use client\";\n\nimport { useMemo, useSyncExternalStore } from \"react\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport type {\n MessageMetadata,\n MessageMetadataMap,\n SubmissionQueueEntry,\n SubmissionQueueSnapshot,\n} from \"@langchain/langgraph-sdk/stream\";\nimport {\n NAMESPACE_SEPARATOR,\n audioProjection,\n channelProjection,\n extensionProjection,\n filesProjection,\n imagesProjection,\n messagesProjection,\n toolCallsProjection,\n valuesProjection,\n videoProjection,\n type AssembledToolCall,\n type AudioMedia,\n type Channel,\n type ChannelProjectionOptions,\n type Event,\n type FileMedia,\n type ImageMedia,\n type InferToolCalls,\n type InferStateType,\n type SubagentDiscoverySnapshot,\n type SubgraphDiscoverySnapshot,\n type VideoMedia,\n} from \"@langchain/langgraph-sdk/stream\";\nimport {\n getRegistry,\n STREAM_CONTROLLER,\n type UseStreamReturn,\n} from \"./use-stream.js\";\nimport { useProjection } from \"./use-projection.js\";\n\n/**\n * Selector hooks don't need to carry `InterruptType` /\n * `ConfigurableType` — they only ever read state. Accepting a\n * `StateType`-parameterised stream (with the other two generics\n * widened to `any`) lets callers keep their full\n * `useStream<State, Interrupt, Configurable>()` handle\n * without re-declaring the interrupt / configurable shapes at every\n * selector call site.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype StreamHandle<StateType extends object> = UseStreamReturn<\n StateType,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any\n>;\n\n/**\n * What a selector hook can be targeted at. Callers can pass any of:\n * - `undefined` — root namespace (cheap: served by the always-on root store)\n * - a {@link SubagentDiscoverySnapshot} — the snapshot returned by `stream.subagents.get(...)`\n * - a {@link SubgraphDiscoverySnapshot} — the snapshot returned by `stream.subgraphs.get(...)`\n * - an explicit `{ namespace: string[] }` — any other namespaced scope\n * - a raw `string[]` — escape hatch identical to the object form\n */\nexport type SelectorTarget =\n | undefined\n | null\n | readonly string[]\n | { namespace: readonly string[] }\n | SubagentDiscoverySnapshot\n | SubgraphDiscoverySnapshot;\n\nfunction resolveNamespace(target: SelectorTarget): readonly string[] {\n if (target == null) return EMPTY_NAMESPACE;\n if (Array.isArray(target)) return target;\n const obj = target as { namespace?: readonly string[] };\n return obj.namespace ?? EMPTY_NAMESPACE;\n}\n\nconst EMPTY_NAMESPACE: readonly string[] = [];\n\nfunction isRoot(namespace: readonly string[]): boolean {\n return namespace.length === 0;\n}\n\nfunction namespaceKey(namespace: readonly string[]): string {\n return namespace.join(NAMESPACE_SEPARATOR);\n}\n\n// The stream type we accept for selectors — purposely loose so\n// selector hooks remain callable from components that don't carry\n// the exact State/Interrupt/Configurable generics. We use `any` for\n// all three generics because `UseStreamReturn` is\n// invariant in `State` and `Configurable` (they flow through both\n// reader and writer positions), so a concrete\n// `useStream<typeof agent>()` handle wouldn't flow into\n// a `<object, unknown, object>` slot otherwise.\n//\n// Typed selectors (`useValues<S>` etc.) use {@link StreamHandle}\n// above so the concrete `StateType` flows into the return; hooks\n// that don't depend on state (`useMessages`, `useAudio`, …) stay on\n// `AnyStream` for maximum flexibility.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyStream = UseStreamReturn<any, any, any>;\n\n/**\n * Subscribe to a scoped `messages` stream. Pass `stream` and\n * optionally a subagent/subgraph snapshot (or any namespaced target).\n *\n * Contract:\n * - At the root (no target) this returns `stream.messages` directly\n * — no extra subscription is opened. `stream.messages` is the\n * live merge of `messages`-channel token deltas and\n * `values.messages` snapshots (see\n * {@link UseStreamReturn.messages}), so token-by-token\n * streaming here depends on the backend emitting `messages`\n * channel events. Backends that only emit `values` updates will\n * render full turns at once rather than streaming.\n * - For any other namespace, the mount triggers a ref-counted\n * `messages` subscription scoped to that namespace. Unmounting\n * the last component that watches this namespace closes the\n * subscription automatically.\n *\n * Messages are always `BaseMessage` class instances from\n * `@langchain/core/messages`.\n */\nexport function useMessages(\n stream: AnyStream,\n target?: SelectorTarget\n): BaseMessage[] {\n const namespace = resolveNamespace(target);\n const key = `messages|${namespaceKey(namespace)}`;\n const registry = isRoot(namespace) ? null : getRegistry(stream);\n const scoped = useProjection<BaseMessage[]>(\n registry,\n () => messagesProjection(namespace),\n key,\n EMPTY_MESSAGES\n );\n return isRoot(namespace) ? stream.messages : scoped;\n}\n\nconst EMPTY_MESSAGES: BaseMessage[] = [];\n\n/**\n * Subscribe to a scoped `tools` (tool-call) stream. Same target and\n * lifecycle rules as {@link useMessages}; at the root this just returns\n * `stream.toolCalls`.\n *\n * The optional generic `T` can be passed to narrow the type of\n * assembled tool calls on the returned array. Accepts either:\n * - an agent brand (`typeof agent`) — union is derived from the\n * agent's declared tools via {@link InferToolCalls};\n * - an array of LangGraph tools (`typeof tools`) — union is derived\n * from {@link InferToolCalls} (parallel to {@link ToolCallsFromTools}).\n *\n * When omitted, returns the plain `AssembledToolCall[]` union used by\n * the controller.\n */\nexport function useToolCalls(\n stream: AnyStream,\n target?: SelectorTarget\n): AssembledToolCall[];\nexport function useToolCalls<T>(\n stream: AnyStream,\n target?: SelectorTarget\n): InferToolCalls<T>[];\nexport function useToolCalls(\n stream: AnyStream,\n target?: SelectorTarget\n): AssembledToolCall[] {\n const namespace = resolveNamespace(target);\n const key = `toolCalls|${namespaceKey(namespace)}`;\n const registry = isRoot(namespace) ? null : getRegistry(stream);\n const scoped = useProjection<AssembledToolCall[]>(\n registry,\n () => toolCallsProjection(namespace),\n key,\n EMPTY_TOOLCALLS\n );\n return isRoot(namespace) ? stream.toolCalls : scoped;\n}\n\nconst EMPTY_TOOLCALLS: AssembledToolCall[] = [];\n\n/**\n * Subscribe to a scoped `values` stream — most-recent state payload\n * for a namespace. Equivalent to reading `stream.values` at the root.\n *\n * When the payload carries a `messages` array, it is coerced to\n * `BaseMessage` instances to keep parity with the root projection.\n *\n * Typing:\n * - **Root** (`useValues(stream)`): returns the `StateType` declared\n * on the parent `useStream<State>()` — no explicit\n * generic required. Non-nullable because the root snapshot always\n * carries `values` (falling back to `initialValues ?? {}`).\n * - **Scoped** (`useValues(stream, target)`): the scoped payload can\n * have a different shape than the root state (e.g. a subagent\n * returning its own substate). Callers should annotate the\n * expected shape explicitly: `useValues<SubagentState>(stream, sub)`.\n * Defaults to `unknown` when not annotated.\n */\nexport function useValues<StateType extends object>(\n stream: StreamHandle<StateType>\n): StateType;\n/**\n * Explicit-generic override. Accepts:\n * - an agent brand or compiled graph (unwrapped via\n * {@link InferStateType});\n * - a plain state shape (returned as-is).\n *\n * The root-call form is non-nullable (the root snapshot is always\n * present); the scoped form returns `T | undefined` because a\n * projection may not have emitted a payload yet.\n */\nexport function useValues<T>(stream: AnyStream): InferStateType<T>;\nexport function useValues<T = unknown>(\n stream: AnyStream,\n target: SelectorTarget,\n options?: { messagesKey?: string }\n): T | undefined;\nexport function useValues(\n stream: AnyStream,\n target?: SelectorTarget,\n options?: { messagesKey?: string }\n): unknown {\n const namespace = resolveNamespace(target);\n const messagesKey = options?.messagesKey ?? \"messages\";\n const key = `values|${messagesKey}|${namespaceKey(namespace)}`;\n const registry = isRoot(namespace) ? null : getRegistry(stream);\n const scoped = useProjection<unknown>(\n registry,\n () => valuesProjection<unknown>(namespace, messagesKey),\n key,\n undefined\n );\n return isRoot(namespace) ? stream.values : scoped;\n}\n\n/**\n * Subscribe to a `custom:<name>` stream extension — most-recent\n * payload emitted by the transformer, scoped to the target namespace.\n */\nexport function useExtension<T = unknown>(\n stream: AnyStream,\n name: string,\n target?: SelectorTarget\n): T | undefined {\n const namespace = resolveNamespace(target);\n const key = `extension|${name}|${namespaceKey(namespace)}`;\n return useProjection<T | undefined>(\n getRegistry(stream),\n () => extensionProjection<T>(name, namespace),\n key,\n undefined\n );\n}\n\n/**\n * Raw-events escape hatch. Subscribes to one or more channels at a\n * namespace and returns a bounded buffer of raw protocol events.\n * Prefer {@link useMessages} / {@link useToolCalls} / {@link useValues}\n * for the common cases.\n */\n/**\n * Subscribe to a scoped audio-media stream. Returns an array of\n * {@link AudioMedia} handles, one per message containing at least one\n * `AudioBlock` in the target namespace.\n *\n * Each handle is yielded on its first matching `content-block-start`,\n * exposes `.partialBytes` for live access, settles `.blob` /\n * `.objectURL` / `.transcript` on `message-finish`, and surfaces\n * fail-loud errors via `.error`.\n *\n * Pair with {@link useMediaURL} to turn a handle into an `<audio src>`.\n */\nexport function useAudio(\n stream: AnyStream,\n target?: SelectorTarget\n): AudioMedia[] {\n const namespace = resolveNamespace(target);\n const key = `audio|${namespaceKey(namespace)}`;\n return useProjection<AudioMedia[]>(\n getRegistry(stream),\n () => audioProjection(namespace),\n key,\n EMPTY_AUDIO\n );\n}\n\nconst EMPTY_AUDIO: AudioMedia[] = [];\n\n/**\n * Subscribe to a scoped image-media stream. See {@link useAudio} for\n * shared semantics; pair with {@link useMediaURL} for `<img src>`.\n */\nexport function useImages(\n stream: AnyStream,\n target?: SelectorTarget\n): ImageMedia[] {\n const namespace = resolveNamespace(target);\n const key = `images|${namespaceKey(namespace)}`;\n return useProjection<ImageMedia[]>(\n getRegistry(stream),\n () => imagesProjection(namespace),\n key,\n EMPTY_IMAGES\n );\n}\n\nconst EMPTY_IMAGES: ImageMedia[] = [];\n\n/**\n * Subscribe to a scoped video-media stream. See {@link useAudio} for\n * shared semantics; pair with {@link useMediaURL} for `<video src>`.\n */\nexport function useVideo(\n stream: AnyStream,\n target?: SelectorTarget\n): VideoMedia[] {\n const namespace = resolveNamespace(target);\n const key = `video|${namespaceKey(namespace)}`;\n return useProjection<VideoMedia[]>(\n getRegistry(stream),\n () => videoProjection(namespace),\n key,\n EMPTY_VIDEO\n );\n}\n\nconst EMPTY_VIDEO: VideoMedia[] = [];\n\n/**\n * Subscribe to a scoped file-media stream. See {@link useAudio} for\n * shared semantics; pair with {@link useMediaURL} for an\n * `<a download href>` target.\n */\nexport function useFiles(\n stream: AnyStream,\n target?: SelectorTarget\n): FileMedia[] {\n const namespace = resolveNamespace(target);\n const key = `files|${namespaceKey(namespace)}`;\n return useProjection<FileMedia[]>(\n getRegistry(stream),\n () => filesProjection(namespace),\n key,\n EMPTY_FILES\n );\n}\n\nconst EMPTY_FILES: FileMedia[] = [];\n\nexport type UseChannelOptions = ChannelProjectionOptions;\n\nexport function useChannel(\n stream: AnyStream,\n channels: readonly Channel[],\n target?: SelectorTarget,\n options?: UseChannelOptions\n): Event[] {\n const namespace = resolveNamespace(target);\n const channelKey = useMemo(() => [...channels].sort().join(\",\"), [channels]);\n const key = `channel|${options?.bufferSize ?? \"default\"}|${(options?.replay ?? true) ? \"replay\" : \"live\"}|${channelKey}|${namespaceKey(namespace)}`;\n return useProjection<Event[]>(\n getRegistry(stream),\n () => channelProjection(channels, namespace, options),\n key,\n EMPTY_EVENTS\n );\n}\n\nconst EMPTY_EVENTS: Event[] = [];\n\n/**\n * Read metadata recorded for a specific message id — today exposes\n * `parentCheckpointId`, the checkpoint the message was first seen on.\n * Designed for fork / edit flows:\n *\n * ```tsx\n * const { parentCheckpointId } = useMessageMetadata(stream, msg.id) ?? {};\n * if (parentCheckpointId) {\n * await stream.submit(input, { forkFrom: { checkpointId: parentCheckpointId } });\n * }\n * ```\n *\n * Returns `undefined` when the id isn't known yet (e.g. the server\n * hasn't emitted `parent_checkpoint` for that message, or the message\n * arrived via `messages`-channel deltas only and no `values` snapshot\n * has landed for it yet).\n */\nexport function useMessageMetadata(\n stream: AnyStream,\n messageId: string | undefined\n): MessageMetadata | undefined {\n const store = stream[STREAM_CONTROLLER].messageMetadataStore;\n const snapshot = useSyncExternalStore<MessageMetadataMap>(\n store.subscribe,\n store.getSnapshot,\n store.getSnapshot\n );\n return messageId == null ? undefined : snapshot.get(messageId);\n}\n\n/**\n * Reactive handle on the server-side submission queue.\n *\n * Populated when `submit()` is invoked with `multitaskStrategy:\n * \"enqueue\"` while another run is in flight. The returned object is\n * stable per snapshot so consumers can pass `entries` straight into a\n * `<Fragment key={e.id}>` list without extra memoisation.\n */\nexport interface UseSubmissionQueueReturn<\n StateType extends object = Record<string, unknown>,\n> {\n readonly entries: SubmissionQueueSnapshot<StateType>;\n readonly size: number;\n cancel(id: string): Promise<boolean>;\n clear(): Promise<void>;\n}\n\nexport function useSubmissionQueue<StateType extends object>(\n stream: StreamHandle<StateType>\n): UseSubmissionQueueReturn<StateType>;\nexport function useSubmissionQueue(stream: AnyStream): UseSubmissionQueueReturn;\nexport function useSubmissionQueue(\n stream: AnyStream\n): UseSubmissionQueueReturn {\n const controller = stream[STREAM_CONTROLLER];\n const store = controller.queueStore;\n const entries = useSyncExternalStore<SubmissionQueueSnapshot>(\n store.subscribe,\n store.getSnapshot,\n store.getSnapshot\n );\n return useMemo<UseSubmissionQueueReturn>(\n () => ({\n entries,\n size: entries.length,\n cancel: (id) => controller.cancelQueued(id),\n clear: () => controller.clearQueue(),\n }),\n [entries, controller]\n );\n}\n\nexport type { SubmissionQueueEntry, SubmissionQueueSnapshot };\n"],"mappings":";;;;;;AA6EA,SAAS,iBAAiB,QAA2C;AACnE,KAAI,UAAU,KAAM,QAAO;AAC3B,KAAI,MAAM,QAAQ,OAAO,CAAE,QAAO;AAElC,QADY,OACD,aAAa;;AAG1B,MAAM,kBAAqC,EAAE;AAE7C,SAAS,OAAO,WAAuC;AACrD,QAAO,UAAU,WAAW;;AAG9B,SAAS,aAAa,WAAsC;AAC1D,QAAO,UAAU,KAAKA,gCAAAA,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;AAwC5C,SAAgB,YACd,QACA,QACe;CACf,MAAM,YAAY,iBAAiB,OAAO;CAC1C,MAAM,MAAM,YAAY,aAAa,UAAU;CAE/C,MAAM,SAASC,uBAAAA,cADE,OAAO,UAAU,GAAG,OAAOC,mBAAAA,YAAY,OAAO,SAAA,GAAA,gCAAA,oBAGpC,UAAU,EACnC,KACA,eACD;AACD,QAAO,OAAO,UAAU,GAAG,OAAO,WAAW;;AAG/C,MAAM,iBAAgC,EAAE;AAyBxC,SAAgB,aACd,QACA,QACqB;CACrB,MAAM,YAAY,iBAAiB,OAAO;CAC1C,MAAM,MAAM,aAAa,aAAa,UAAU;CAEhD,MAAM,SAASD,uBAAAA,cADE,OAAO,UAAU,GAAG,OAAOC,mBAAAA,YAAY,OAAO,SAAA,GAAA,gCAAA,qBAGnC,UAAU,EACpC,KACA,gBACD;AACD,QAAO,OAAO,UAAU,GAAG,OAAO,YAAY;;AAGhD,MAAM,kBAAuC,EAAE;AAuC/C,SAAgB,UACd,QACA,QACA,SACS;CACT,MAAM,YAAY,iBAAiB,OAAO;CAC1C,MAAM,cAAc,SAAS,eAAe;CAC5C,MAAM,MAAM,UAAU,YAAY,GAAG,aAAa,UAAU;CAE5D,MAAM,SAASD,uBAAAA,cADE,OAAO,UAAU,GAAG,OAAOC,mBAAAA,Y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D;;AAGH,MAAM,cAA2B,EAAE;AAInC,SAAgB,WACd,QACA,UACA,QACA,SACS;CACT,MAAM,YAAY,iBAAiB,OAAO;CAC1C,MAAM,cAAA,GAAA,MAAA,eAA2B,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,SAAS,CAAC;CAC5E,MAAM,MAAM,WAAW,SAAS,cAAc,UAAU,GAAI,SAAS,UAAU,OAAQ,WAAW,OAAO,GAAG,WAAW,GAAG,aAAa,UAAU;AACjJ,QAAOD,uBAAAA,cACLC,mBAAAA,YAAY,OAAO,SAAA,GAAA,gCAAA,mBACK,UAAU,WAAW,QAAQ,EACrD,KACA,aACD;;AAGH,MAAM,eAAwB,EAAE;;;;;;;;;;;;;;;;;;AAmBhC,SAAgB,mBACd,QACA,WAC6B;CAC7B,MAAM,QAAQ,OAAOC,mBAAAA,mBAAmB;CACxC,MAAM,YAAA,GAAA,MAAA,sBACJ,MAAM,WACN,MAAM,aACN,MAAM,YACP;AACD,QAAO,aAAa,OAAO,KAAA,IAAY,SAAS,IAAI,UAAU;;AAwBhE,SAAgB,mBACd,QAC0B;CAC1B,MAAM,aAAa,OAAOA,mBAAAA;CAC1B,MAAM,QAAQ,WAAW;CACzB,MAAM,WAAA,GAAA,MAAA,sBACJ,MAAM,WACN,MAAM,aACN,MAAM,YACP;AACD,SAAA,GAAA,MAAA,gBACS;EACL;EACA,MAAM,QAAQ;EACd,SAAS,OAAO,WAAW,aAAa,GAAG;EAC3C,aAAa,WAAW,YAAY;EACrC,GACD,CAAC,SAAS,WAAW,CACtB"}
@@ -164,10 +164,6 @@ declare function useMessageMetadata(stream: AnyStream, messageId: string | undef
164
164
  * "enqueue"` while another run is in flight. The returned object is
165
165
  * stable per snapshot so consumers can pass `entries` straight into a
166
166
  * `<Fragment key={e.id}>` list without extra memoisation.
167
- *
168
- * Today the queue is maintained client-side; once the server starts
169
- * emitting a dedicated queue channel (roadmap A0.3) the controller
170
- * will mirror that state directly — the hook surface will not change.
171
167
  */
172
168
  interface UseSubmissionQueueReturn<StateType extends object = Record<string, unknown>> {
173
169
  readonly entries: SubmissionQueueSnapshot<StateType>;
@@ -1 +1 @@
1
- {"version":3,"file":"selectors.d.cts","names":[],"sources":["../src/selectors.ts"],"mappings":";;;;;;AAwCyB;;;;;;;;KAapB,YAAA,6BAAyC,eAAA,CAC5C,SAAA;AAeF;;;;;;;;AAAA,KAAY,cAAA;EAIN,SAAA;AAAA,IACF,yBAAA,GACA,yBAAA;AAAA,KAiCC,SAAA,GAAY,eAAA;;;AAuBjB;;;;;;;;;;;;;;;AAiCA;;;;iBAjCgB,WAAA,CACd,MAAA,EAAQ,SAAA,EACR,MAAA,GAAS,cAAA,GACR,WAAA;;;;;;;;;;;AAkCH;;;;;iBAJgB,YAAA,CACd,MAAA,EAAQ,SAAA,EACR,MAAA,GAAS,cAAA,GACR,iBAAA;AAAA,iBACa,YAAA,GAAA,CACd,MAAA,EAAQ,SAAA,EACR,MAAA,GAAS,cAAA,GACR,cAAA,CAAe,CAAA;;;;;;;;;;;;AAqClB;;;;;;;iBAAgB,SAAA,0BAAA,CACd,MAAA,EAAQ,YAAA,CAAa,SAAA,IACpB,SAAA;;;;;;;;AAWH;;;iBAAgB,SAAA,GAAA,CAAa,MAAA,EAAQ,SAAA,GAAY,cAAA,CAAe,CAAA;AAAA,iBAChD,SAAA,aAAA,CACd,MAAA,EAAQ,SAAA,EACR,MAAA,EAAQ,cAAA,EACR,OAAA;EAAY,WAAA;AAAA,IACX,CAAA;;;;;iBAuBa,YAAA,aAAA,CACd,MAAA,EAAQ,SAAA,EACR,IAAA,UACA,MAAA,GAAS,cAAA,GACR,CAAA;;;;AA/BH;;;;;;;;;;;;;;;iBA4DgB,QAAA,CACd,MAAA,EAAQ,SAAA,EACR,MAAA,GAAS,cAAA,GACR,UAAA;;;AApCH;;iBAqDgB,SAAA,CACd,MAAA,EAAQ,SAAA,EACR,MAAA,GAAS,cAAA,GACR,UAAA;;;;;iBA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AAA,IACpB,wBAAA,CAAyB,SAAA;AAAA,iBACZ,kBAAA,CAAmB,MAAA,EAAQ,SAAA,GAAY,wBAAA"}
@@ -164,10 +164,6 @@ declare function useMessageMetadata(stream: AnyStream, messageId: string | undef
164
164
  * "enqueue"` while another run is in flight. The returned object is
165
165
  * stable per snapshot so consumers can pass `entries` straight into a
166
166
  * `<Fragment key={e.id}>` list without extra memoisation.
167
- *
168
- * Today the queue is maintained client-side; once the server starts
169
- * emitting a dedicated queue channel (roadmap A0.3) the controller
170
- * will mirror that state directly — the hook surface will not change.
171
167
  */
172
168
  interface UseSubmissionQueueReturn<StateType extends object = Record<string, unknown>> {
173
169
  readonly entries: SubmissionQueueSnapshot<StateType>;
@@ -1 +1 @@
1
- {"version":3,"file":"selectors.d.ts","names":[],"sources":["../src/selectors.ts"],"mappings":";;;;;;AAwCyB;;;;;;;;KAapB,YAAA,6BAAyC,eAAA,CAC5C,SAAA;AAeF;;;;;;;;AAAA,KAAY,cAAA;EAIN,SAAA;AAAA,IACF,yBAAA,GACA,yBAAA;AAAA,KAiCC,SAAA,GAAY,eAAA;;;AAuBjB;;;;;;;;;;;;;;;AAiCA;;;;iBAjCgB,WAAA,CACd,MAAA,EAAQ,SAAA,EACR,MAAA,GAAS,cAAA,GACR,WAAA;;;;;;;;;;;AAkCH;;;;;iBAJgB,YAAA,CACd,MAAA,EAAQ,SAAA,EACR,MAAA,GAAS,cAAA,GACR,iBAAA;AAAA,iBACa,YAAA,GAAA,CACd,MAAA,EAAQ,SAAA,EACR,MAAA,GAAS,cAAA,GACR,cAAA,CAAe,CAAA;;;;;;;;;;;;AAqClB;;;;;;;iBAAgB,SAAA,0BAAA,CACd,MAAA,EAAQ,YAAA,CAAa,SAAA,IACpB,SAAA;;;;;;;;AAWH;;;iBAAgB,SAAA,GAAA,CAAa,MAAA,EAAQ,SAAA,GAAY,cAAA,CAAe,CAAA;AAAA,iBAChD,SAAA,aAAA,CACd,MAAA,EAAQ,SAAA,EACR,MAAA,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AU,iBAAA,GACT,KAAA;;AApFH;;;;;;;;;;;;;;;AAoBA;iBA+FgB,kBAAA,CACd,MAAA,EAAQ,SAAA,EACR,SAAA,uBACC,eAAA;;;;;;;;;UAkBc,wBAAA,4BACY,MAAA;EAAA,SAElB,OAAA,EAAS,uBAAA,CAAwB,SAAA;EAAA,SACjC,IAAA;EACT,MAAA,CAAO,EAAA,WAAa,OAAA;EACpB,KAAA,IAAS,OAAA;AAAA;AAAA,iBAGK,kBAAA,0BAAA,CACd,MAAA,EAAQ,YAAA,CAAa,SAAA,IACpB,wBAAA,CAAyB,SAAA;AAAA,iBACZ,kBAAA,CAAmB,MAAA,EAAQ,SAAA,GAAY,wBAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"selectors.js","names":[],"sources":["../src/selectors.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\n\"use client\";\n\nimport { useMemo, useSyncExternalStore } from \"react\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport type {\n MessageMetadata,\n MessageMetadataMap,\n SubmissionQueueEntry,\n SubmissionQueueSnapshot,\n} from \"@langchain/langgraph-sdk/stream\";\nimport {\n NAMESPACE_SEPARATOR,\n audioProjection,\n channelProjection,\n extensionProjection,\n filesProjection,\n imagesProjection,\n messagesProjection,\n toolCallsProjection,\n valuesProjection,\n videoProjection,\n type AssembledToolCall,\n type AudioMedia,\n type Channel,\n type ChannelProjectionOptions,\n type Event,\n type FileMedia,\n type ImageMedia,\n type InferToolCalls,\n type InferStateType,\n type SubagentDiscoverySnapshot,\n type SubgraphDiscoverySnapshot,\n type VideoMedia,\n} from \"@langchain/langgraph-sdk/stream\";\nimport {\n getRegistry,\n STREAM_CONTROLLER,\n type UseStreamReturn,\n} from \"./use-stream.js\";\nimport { useProjection } from \"./use-projection.js\";\n\n/**\n * Selector hooks don't need to carry `InterruptType` /\n * `ConfigurableType` — they only ever read state. Accepting a\n * `StateType`-parameterised stream (with the other two generics\n * widened to `any`) lets callers keep their full\n * `useStream<State, Interrupt, Configurable>()` handle\n * without re-declaring the interrupt / configurable shapes at every\n * selector call site.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype StreamHandle<StateType extends object> = UseStreamReturn<\n StateType,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any\n>;\n\n/**\n * What a selector hook can be targeted at. Callers can pass any of:\n * - `undefined` — root namespace (cheap: served by the always-on root store)\n * - a {@link SubagentDiscoverySnapshot} — the snapshot returned by `stream.subagents.get(...)`\n * - a {@link SubgraphDiscoverySnapshot} — the snapshot returned by `stream.subgraphs.get(...)`\n * - an explicit `{ namespace: string[] }` — any other namespaced scope\n * - a raw `string[]` — escape hatch identical to the object form\n */\nexport type SelectorTarget =\n | undefined\n | null\n | readonly string[]\n | { namespace: readonly string[] }\n | SubagentDiscoverySnapshot\n | SubgraphDiscoverySnapshot;\n\nfunction resolveNamespace(target: SelectorTarget): readonly string[] {\n if (target == null) return EMPTY_NAMESPACE;\n if (Array.isArray(target)) return target;\n const obj = target as { namespace?: readonly string[] };\n return obj.namespace ?? EMPTY_NAMESPACE;\n}\n\nconst EMPTY_NAMESPACE: readonly string[] = [];\n\nfunction isRoot(namespace: readonly string[]): boolean {\n return namespace.length === 0;\n}\n\nfunction namespaceKey(namespace: readonly string[]): string {\n return namespace.join(NAMESPACE_SEPARATOR);\n}\n\n// The stream type we accept for selectors — purposely loose so\n// selector hooks remain callable from components that don't carry\n// the exact State/Interrupt/Configurable generics. We use `any` for\n// all three generics because `UseStreamReturn` is\n// invariant in `State` and `Configurable` (they flow through both\n// reader and writer positions), so a concrete\n// `useStream<typeof agent>()` handle wouldn't flow into\n// a `<object, unknown, object>` slot otherwise.\n//\n// Typed selectors (`useValues<S>` etc.) use {@link StreamHandle}\n// above so the concrete `StateType` flows into the return; hooks\n// that don't depend on state (`useMessages`, `useAudio`, …) stay on\n// `AnyStream` for maximum flexibility.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyStream = UseStreamReturn<any, any, any>;\n\n/**\n * Subscribe to a scoped `messages` stream. Pass `stream` and\n * optionally a subagent/subgraph snapshot (or any namespaced target).\n *\n * Contract:\n * - At the root (no target) this returns `stream.messages` directly\n * — no extra subscription is opened. `stream.messages` is the\n * live merge of `messages`-channel token deltas and\n * `values.messages` snapshots (see\n * {@link UseStreamReturn.messages}), so token-by-token\n * streaming here depends on the backend emitting `messages`\n * channel events. Backends that only emit `values` updates will\n * render full turns at once rather than streaming.\n * - For any other namespace, the mount triggers a ref-counted\n * `messages` subscription scoped to that namespace. Unmounting\n * the last component that watches this namespace closes the\n * subscription automatically.\n *\n * Messages are always `BaseMessage` class instances from\n * `@langchain/core/messages`.\n */\nexport function useMessages(\n stream: AnyStream,\n target?: SelectorTarget\n): BaseMessage[] {\n const namespace = resolveNamespace(target);\n const key = `messages|${namespaceKey(namespace)}`;\n const registry = isRoot(namespace) ? null : getRegistry(stream);\n const scoped = useProjection<BaseMessage[]>(\n registry,\n () => messagesProjection(namespace),\n key,\n EMPTY_MESSAGES\n );\n return isRoot(namespace) ? stream.messages : scoped;\n}\n\nconst EMPTY_MESSAGES: BaseMessage[] = [];\n\n/**\n * Subscribe to a scoped `tools` (tool-call) stream. Same target and\n * lifecycle rules as {@link useMessages}; at the root this just returns\n * `stream.toolCalls`.\n *\n * The optional generic `T` can be passed to narrow the type of\n * assembled tool calls on the returned array. Accepts either:\n * - an agent brand (`typeof agent`) — union is derived from the\n * agent's declared tools via {@link InferToolCalls};\n * - an array of LangGraph tools (`typeof tools`) — union is derived\n * from {@link InferToolCalls} (parallel to {@link ToolCallsFromTools}).\n *\n * When omitted, returns the plain `AssembledToolCall[]` union used by\n * the controller.\n */\nexport function useToolCalls(\n stream: AnyStream,\n target?: SelectorTarget\n): AssembledToolCall[];\nexport function useToolCalls<T>(\n stream: AnyStream,\n target?: SelectorTarget\n): InferToolCalls<T>[];\nexport function useToolCalls(\n stream: AnyStream,\n target?: SelectorTarget\n): AssembledToolCall[] {\n const namespace = resolveNamespace(target);\n const key = `toolCalls|${namespaceKey(namespace)}`;\n const registry = isRoot(namespace) ? null : getRegistry(stream);\n const scoped = useProjection<AssembledToolCall[]>(\n registry,\n () => toolCallsProjection(namespace),\n key,\n EMPTY_TOOLCALLS\n );\n return isRoot(namespace) ? stream.toolCalls : scoped;\n}\n\nconst EMPTY_TOOLCALLS: AssembledToolCall[] = [];\n\n/**\n * Subscribe to a scoped `values` stream — most-recent state payload\n * for a namespace. Equivalent to reading `stream.values` at the root.\n *\n * When the payload carries a `messages` array, it is coerced to\n * `BaseMessage` instances to keep parity with the root projection.\n *\n * Typing:\n * - **Root** (`useValues(stream)`): returns the `StateType` declared\n * on the parent `useStream<State>()` — no explicit\n * generic required. Non-nullable because the root snapshot always\n * carries `values` (falling back to `initialValues ?? {}`).\n * - **Scoped** (`useValues(stream, target)`): the scoped payload can\n * have a different shape than the root state (e.g. a subagent\n * returning its own substate). Callers should annotate the\n * expected shape explicitly: `useValues<SubagentState>(stream, sub)`.\n * Defaults to `unknown` when not annotated.\n */\nexport function useValues<StateType extends object>(\n stream: StreamHandle<StateType>\n): StateType;\n/**\n * Explicit-generic override. Accepts:\n * - an agent brand or compiled graph (unwrapped via\n * {@link InferStateType});\n * - a plain state shape (returned as-is).\n *\n * The root-call form is non-nullable (the root snapshot is always\n * present); the scoped form returns `T | undefined` because a\n * projection may not have emitted a payload yet.\n */\nexport function useValues<T>(stream: AnyStream): InferStateType<T>;\nexport function useValues<T = unknown>(\n stream: AnyStream,\n target: SelectorTarget,\n options?: { messagesKey?: string }\n): T | undefined;\nexport function useValues(\n stream: AnyStream,\n target?: SelectorTarget,\n options?: { messagesKey?: string }\n): unknown {\n const namespace = resolveNamespace(target);\n const messagesKey = options?.messagesKey ?? \"messages\";\n const key = `values|${messagesKey}|${namespaceKey(namespace)}`;\n const registry = isRoot(namespace) ? null : getRegistry(stream);\n const scoped = useProjection<unknown>(\n registry,\n () => valuesProjection<unknown>(namespace, messagesKey),\n key,\n undefined\n );\n return isRoot(namespace) ? stream.values : scoped;\n}\n\n/**\n * Subscribe to a `custom:<name>` stream extension — most-recent\n * payload emitted by the transformer, scoped to the target namespace.\n */\nexport function useExtension<T = unknown>(\n stream: AnyStream,\n name: string,\n target?: SelectorTarget\n): T | undefined {\n const namespace = resolveNamespace(target);\n const key = `extension|${name}|${namespaceKey(namespace)}`;\n return useProjection<T | undefined>(\n getRegistry(stream),\n () => extensionProjection<T>(name, namespace),\n key,\n undefined\n );\n}\n\n/**\n * Raw-events escape hatch. Subscribes to one or more channels at a\n * namespace and returns a bounded buffer of raw protocol events.\n * Prefer {@link useMessages} / {@link useToolCalls} / {@link useValues}\n * for the common cases.\n */\n/**\n * Subscribe to a scoped audio-media stream. Returns an array of\n * {@link AudioMedia} handles, one per message containing at least one\n * `AudioBlock` in the target namespace.\n *\n * Each handle is yielded on its first matching `content-block-start`,\n * exposes `.partialBytes` for live access, settles `.blob` /\n * `.objectURL` / `.transcript` on `message-finish`, and surfaces\n * fail-loud errors via `.error`.\n *\n * Pair with {@link useMediaURL} to turn a handle into an `<audio src>`.\n */\nexport function useAudio(\n stream: AnyStream,\n target?: SelectorTarget\n): AudioMedia[] {\n const namespace = resolveNamespace(target);\n const key = `audio|${namespaceKey(namespace)}`;\n return useProjection<AudioMedia[]>(\n getRegistry(stream),\n () => audioProjection(namespace),\n key,\n EMPTY_AUDIO\n );\n}\n\nconst EMPTY_AUDIO: AudioMedia[] = [];\n\n/**\n * Subscribe to a scoped image-media stream. See {@link useAudio} for\n * shared semantics; pair with {@link useMediaURL} for `<img src>`.\n */\nexport function useImages(\n stream: AnyStream,\n target?: SelectorTarget\n): ImageMedia[] {\n const namespace = resolveNamespace(target);\n const key = `images|${namespaceKey(namespace)}`;\n return useProjection<ImageMedia[]>(\n getRegistry(stream),\n () => imagesProjection(namespace),\n key,\n EMPTY_IMAGES\n );\n}\n\nconst EMPTY_IMAGES: ImageMedia[] = [];\n\n/**\n * Subscribe to a scoped video-media stream. See {@link useAudio} for\n * shared semantics; pair with {@link useMediaURL} for `<video src>`.\n */\nexport function useVideo(\n stream: AnyStream,\n target?: SelectorTarget\n): VideoMedia[] {\n const namespace = resolveNamespace(target);\n const key = `video|${namespaceKey(namespace)}`;\n return useProjection<VideoMedia[]>(\n getRegistry(stream),\n () => videoProjection(namespace),\n key,\n EMPTY_VIDEO\n );\n}\n\nconst EMPTY_VIDEO: VideoMedia[] = [];\n\n/**\n * Subscribe to a scoped file-media stream. See {@link useAudio} for\n * shared semantics; pair with {@link useMediaURL} for an\n * `<a download href>` target.\n */\nexport function useFiles(\n stream: AnyStream,\n target?: SelectorTarget\n): FileMedia[] {\n const namespace = resolveNamespace(target);\n const key = `files|${namespaceKey(namespace)}`;\n return useProjection<FileMedia[]>(\n getRegistry(stream),\n () => filesProjection(namespace),\n key,\n EMPTY_FILES\n );\n}\n\nconst EMPTY_FILES: FileMedia[] = [];\n\nexport type UseChannelOptions = ChannelProjectionOptions;\n\nexport function useChannel(\n stream: AnyStream,\n channels: readonly Channel[],\n target?: SelectorTarget,\n options?: UseChannelOptions\n): Event[] {\n const namespace = resolveNamespace(target);\n const channelKey = useMemo(() => [...channels].sort().join(\",\"), [channels]);\n const key = `channel|${options?.bufferSize ?? \"default\"}|${(options?.replay ?? true) ? \"replay\" : \"live\"}|${channelKey}|${namespaceKey(namespace)}`;\n return useProjection<Event[]>(\n getRegistry(stream),\n () => channelProjection(channels, namespace, options),\n key,\n EMPTY_EVENTS\n );\n}\n\nconst EMPTY_EVENTS: Event[] = [];\n\n/**\n * Read metadata recorded for a specific message id — today exposes\n * `parentCheckpointId`, the checkpoint the message was first seen on.\n * Designed for fork / edit flows:\n *\n * ```tsx\n * const { parentCheckpointId } = useMessageMetadata(stream, msg.id) ?? {};\n * if (parentCheckpointId) {\n * await stream.submit(input, { forkFrom: { checkpointId: parentCheckpointId } });\n * }\n * ```\n *\n * Returns `undefined` when the id isn't known yet (e.g. the server\n * hasn't emitted `parent_checkpoint` for that message, or the message\n * arrived via `messages`-channel deltas only and no `values` snapshot\n * has landed for it yet).\n */\nexport function useMessageMetadata(\n stream: AnyStream,\n messageId: string | undefined\n): MessageMetadata | undefined {\n const store = stream[STREAM_CONTROLLER].messageMetadataStore;\n const snapshot = useSyncExternalStore<MessageMetadataMap>(\n store.subscribe,\n store.getSnapshot,\n store.getSnapshot\n );\n return messageId == null ? undefined : snapshot.get(messageId);\n}\n\n/**\n * Reactive handle on the server-side submission queue.\n *\n * Populated when `submit()` is invoked with `multitaskStrategy:\n * \"enqueue\"` while another run is in flight. The returned object is\n * stable per snapshot so consumers can pass `entries` straight into a\n * `<Fragment key={e.id}>` list without extra memoisation.\n *\n * Today the queue is maintained client-side; once the server starts\n * emitting a dedicated queue channel (roadmap A0.3) the controller\n * will mirror that state directly — the hook surface will not change.\n */\nexport interface UseSubmissionQueueReturn<\n StateType extends object = Record<string, unknown>,\n> {\n readonly entries: SubmissionQueueSnapshot<StateType>;\n readonly size: number;\n cancel(id: string): Promise<boolean>;\n clear(): Promise<void>;\n}\n\nexport function useSubmissionQueue<StateType extends object>(\n stream: StreamHandle<StateType>\n): UseSubmissionQueueReturn<StateType>;\nexport function useSubmissionQueue(stream: AnyStream): UseSubmissionQueueReturn;\nexport function useSubmissionQueue(\n stream: AnyStream\n): UseSubmissionQueueReturn {\n const controller = stream[STREAM_CONTROLLER];\n const store = controller.queueStore;\n const entries = useSyncExternalStore<SubmissionQueueSnapshot>(\n store.subscribe,\n store.getSnapshot,\n store.getSnapshot\n );\n return useMemo<UseSubmissionQueueReturn>(\n () => ({\n entries,\n size: entries.length,\n cancel: (id) => controller.cancelQueued(id),\n clear: () => controller.clearQueue(),\n }),\n [entries, controller]\n );\n}\n\nexport type { SubmissionQueueEntry, SubmissionQueueSnapshot };\n"],"mappings":";;;;;;AA6EA,SAAS,iBAAiB,QAA2C;AACnE,KAAI,UAAU,KAAM,QAAO;AAC3B,KAAI,MA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,QACA,WAC6B;CAC7B,MAAM,QAAQ,OAAO,mBAAmB;CACxC,MAAM,WAAW,qBACf,MAAM,WACN,MAAM,aACN,MAAM,YACP;AACD,QAAO,aAAa,OAAO,KAAA,IAAY,SAAS,IAAI,UAAU;;AA4BhE,SAAgB,mBACd,QAC0B;CAC1B,MAAM,aAAa,OAAO;CAC1B,MAAM,QAAQ,WAAW;CACzB,MAAM,UAAU,qBACd,MAAM,WACN,MAAM,aACN,MAAM,YACP;AACD,QAAO,eACE;EACL;EACA,MAAM,QAAQ;EACd,SAAS,OAAO,WAAW,aAAa,GAAG;EAC3C,aAAa,WAAW,YAAY;EACrC,GACD,CAAC,SAAS,WAAW,CACtB"}
1
+ {"version":3,"file":"selectors.js","names":[],"sources":["../src/selectors.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\n\"use client\";\n\nimport { useMemo, useSyncExternalStore } from \"react\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport type {\n MessageMetadata,\n MessageMetadataMap,\n SubmissionQueueEntry,\n SubmissionQueueSnapshot,\n} from \"@langchain/langgraph-sdk/stream\";\nimport {\n NAMESPACE_SEPARATOR,\n audioProjection,\n channelProjection,\n extensionProjection,\n filesProjection,\n imagesProjection,\n messagesProjection,\n toolCallsProjection,\n valuesProjection,\n videoProjection,\n type AssembledToolCall,\n type AudioMedia,\n type Channel,\n type ChannelProjectionOptions,\n type Event,\n type FileMedia,\n type ImageMedia,\n type InferToolCalls,\n type InferStateType,\n type SubagentDiscoverySnapshot,\n type SubgraphDiscoverySnapshot,\n type VideoMedia,\n} from \"@langchain/langgraph-sdk/stream\";\nimport {\n getRegistry,\n STREAM_CONTROLLER,\n type UseStreamReturn,\n} from \"./use-stream.js\";\nimport { useProjection } from \"./use-projection.js\";\n\n/**\n * Selector hooks don't need to carry `InterruptType` /\n * `ConfigurableType` — they only ever read state. Accepting a\n * `StateType`-parameterised stream (with the other two generics\n * widened to `any`) lets callers keep their full\n * `useStream<State, Interrupt, Configurable>()` handle\n * without re-declaring the interrupt / configurable shapes at every\n * selector call site.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype StreamHandle<StateType extends object> = UseStreamReturn<\n StateType,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any\n>;\n\n/**\n * What a selector hook can be targeted at. Callers can pass any of:\n * - `undefined` — root namespace (cheap: served by the always-on root store)\n * - a {@link SubagentDiscoverySnapshot} — the snapshot returned by `stream.subagents.get(...)`\n * - a {@link SubgraphDiscoverySnapshot} — the snapshot returned by `stream.subgraphs.get(...)`\n * - an explicit `{ namespace: string[] }` — any other namespaced scope\n * - a raw `string[]` — escape hatch identical to the object form\n */\nexport type SelectorTarget =\n | undefined\n | null\n | readonly string[]\n | { namespace: readonly string[] }\n | SubagentDiscoverySnapshot\n | SubgraphDiscoverySnapshot;\n\nfunction resolveNamespace(target: SelectorTarget): readonly string[] {\n if (target == null) return EMPTY_NAMESPACE;\n if (Array.isArray(target)) return target;\n const obj = target as { namespace?: readonly string[] };\n return obj.namespace ?? EMPTY_NAMESPACE;\n}\n\nconst EMPTY_NAMESPACE: readonly string[] = [];\n\nfunction isRoot(namespace: readonly string[]): boolean {\n return namespace.length === 0;\n}\n\nfunction namespaceKey(namespace: readonly string[]): string {\n return namespace.join(NAMESPACE_SEPARATOR);\n}\n\n// The stream type we accept for selectors — purposely loose so\n// selector hooks remain callable from components that don't carry\n// the exact State/Interrupt/Configurable generics. We use `any` for\n// all three generics because `UseStreamReturn` is\n// invariant in `State` and `Configurable` (they flow through both\n// reader and writer positions), so a concrete\n// `useStream<typeof agent>()` handle wouldn't flow into\n// a `<object, unknown, object>` slot otherwise.\n//\n// Typed selectors (`useValues<S>` etc.) use {@link StreamHandle}\n// above so the concrete `StateType` flows into the return; hooks\n// that don't depend on state (`useMessages`, `useAudio`, …) stay on\n// `AnyStream` for maximum flexibility.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyStream = UseStreamReturn<any, any, any>;\n\n/**\n * Subscribe to a scoped `messages` stream. Pass `stream` and\n * optionally a subagent/subgraph snapshot (or any namespaced target).\n *\n * Contract:\n * - At the root (no target) this returns `stream.messages` directly\n * — no extra subscription is opened. `stream.messages` is the\n * live merge of `messages`-channel token deltas and\n * `values.messages` snapshots (see\n * {@link UseStreamReturn.messages}), so token-by-token\n * streaming here depends on the backend emitting `messages`\n * channel events. Backends that only emit `values` updates will\n * render full turns at once rather than streaming.\n * - For any other namespace, the mount triggers a ref-counted\n * `messages` subscription scoped to that namespace. Unmounting\n * the last component that watches this namespace closes the\n * subscription automatically.\n *\n * Messages are always `BaseMessage` class instances from\n * `@langchain/core/messages`.\n */\nexport function useMessages(\n stream: AnyStream,\n target?: SelectorTarget\n): BaseMessage[] {\n const namespace = resolveNamespace(target);\n const key = `messages|${namespaceKey(namespace)}`;\n const registry = isRoot(namespace) ? null : getRegistry(stream);\n const scoped = useProjection<BaseMessage[]>(\n registry,\n () => messagesProjection(namespace),\n key,\n EMPTY_MESSAGES\n );\n return isRoot(namespace) ? stream.messages : scoped;\n}\n\nconst EMPTY_MESSAGES: BaseMessage[] = [];\n\n/**\n * Subscribe to a scoped `tools` (tool-call) stream. Same target and\n * lifecycle rules as {@link useMessages}; at the root this just returns\n * `stream.toolCalls`.\n *\n * The optional generic `T` can be passed to narrow the type of\n * assembled tool calls on the returned array. Accepts either:\n * - an agent brand (`typeof agent`) — union is derived from the\n * agent's declared tools via {@link InferToolCalls};\n * - an array of LangGraph tools (`typeof tools`) — union is derived\n * from {@link InferToolCalls} (parallel to {@link ToolCallsFromTools}).\n *\n * When omitted, returns the plain `AssembledToolCall[]` union used by\n * the controller.\n */\nexport function useToolCalls(\n stream: AnyStream,\n target?: SelectorTarget\n): AssembledToolCall[];\nexport function useToolCalls<T>(\n stream: AnyStream,\n target?: SelectorTarget\n): InferToolCalls<T>[];\nexport function useToolCalls(\n stream: AnyStream,\n target?: SelectorTarget\n): AssembledToolCall[] {\n const namespace = resolveNamespace(target);\n const key = `toolCalls|${namespaceKey(namespace)}`;\n const registry = isRoot(namespace) ? null : getRegistry(stream);\n const scoped = useProjection<AssembledToolCall[]>(\n registry,\n () => toolCallsProjection(namespace),\n key,\n EMPTY_TOOLCALLS\n );\n return isRoot(namespace) ? stream.toolCalls : scoped;\n}\n\nconst EMPTY_TOOLCALLS: AssembledToolCall[] = [];\n\n/**\n * Subscribe to a scoped `values` stream — most-recent state payload\n * for a namespace. Equivalent to reading `stream.values` at the root.\n *\n * When the payload carries a `messages` array, it is coerced to\n * `BaseMessage` instances to keep parity with the root projection.\n *\n * Typing:\n * - **Root** (`useValues(stream)`): returns the `StateType` declared\n * on the parent `useStream<State>()` — no explicit\n * generic required. Non-nullable because the root snapshot always\n * carries `values` (falling back to `initialValues ?? {}`).\n * - **Scoped** (`useValues(stream, target)`): the scoped payload can\n * have a different shape than the root state (e.g. a subagent\n * returning its own substate). Callers should annotate the\n * expected shape explicitly: `useValues<SubagentState>(stream, sub)`.\n * Defaults to `unknown` when not annotated.\n */\nexport function useValues<StateType extends object>(\n stream: StreamHandle<StateType>\n): StateType;\n/**\n * Explicit-generic override. Accepts:\n * - an agent brand or compiled graph (unwrapped via\n * {@link InferStateType});\n * - a plain state shape (returned as-is).\n *\n * The root-call form is non-nullable (the root snapshot is always\n * present); the scoped form returns `T | undefined` because a\n * projection may not have emitted a payload yet.\n */\nexport function useValues<T>(stream: AnyStream): InferStateType<T>;\nexport function useValues<T = unknown>(\n stream: AnyStream,\n target: SelectorTarget,\n options?: { messagesKey?: string }\n): T | undefined;\nexport function useValues(\n stream: AnyStream,\n target?: SelectorTarget,\n options?: { messagesKey?: string }\n): unknown {\n const namespace = resolveNamespace(target);\n const messagesKey = options?.messagesKey ?? \"messages\";\n const key = `values|${messagesKey}|${namespaceKey(namespace)}`;\n const registry = isRoot(namespace) ? null : getRegistry(stream);\n const scoped = useProjection<unknown>(\n registry,\n () => valuesProjection<unknown>(namespace, messagesKey),\n key,\n undefined\n );\n return isRoot(namespace) ? stream.values : scoped;\n}\n\n/**\n * Subscribe to a `custom:<name>` stream extension — most-recent\n * payload emitted by the transformer, scoped to the target namespace.\n */\nexport function useExtension<T = unknown>(\n stream: AnyStream,\n name: string,\n target?: SelectorTarget\n): T | undefined {\n const namespace = resolveNamespace(target);\n const key = `extension|${name}|${namespaceKey(namespace)}`;\n return useProjection<T | undefined>(\n getRegistry(stream),\n () => extensionProjection<T>(name, namespace),\n key,\n undefined\n );\n}\n\n/**\n * Raw-events escape hatch. Subscribes to one or more channels at a\n * namespace and returns a bounded buffer of raw protocol events.\n * Prefer {@link useMessages} / {@link useToolCalls} / {@link useValues}\n * for the common cases.\n */\n/**\n * Subscribe to a scoped audio-media stream. Returns an array of\n * {@link AudioMedia} handles, one per message containing at least one\n * `AudioBlock` in the target namespace.\n *\n * Each handle is yielded on its first matching `content-block-start`,\n * exposes `.partialBytes` for live access, settles `.blob` /\n * `.objectURL` / `.transcript` on `message-finish`, and surfaces\n * fail-loud errors via `.error`.\n *\n * Pair with {@link useMediaURL} to turn a handle into an `<audio src>`.\n */\nexport function useAudio(\n stream: AnyStream,\n target?: SelectorTarget\n): AudioMedia[] {\n const namespace = resolveNamespace(target);\n const key = `audio|${namespaceKey(namespace)}`;\n return useProjection<AudioMedia[]>(\n getRegistry(stream),\n () => audioProjection(namespace),\n key,\n EMPTY_AUDIO\n );\n}\n\nconst EMPTY_AUDIO: AudioMedia[] = [];\n\n/**\n * Subscribe to a scoped image-media stream. See {@link useAudio} for\n * shared semantics; pair with {@link useMediaURL} for `<img src>`.\n */\nexport function useImages(\n stream: AnyStream,\n target?: SelectorTarget\n): ImageMedia[] {\n const namespace = resolveNamespace(target);\n const key = `images|${namespaceKey(namespace)}`;\n return useProjection<ImageMedia[]>(\n getRegistry(stream),\n () => imagesProjection(namespace),\n key,\n EMPTY_IMAGES\n );\n}\n\nconst EMPTY_IMAGES: ImageMedia[] = [];\n\n/**\n * Subscribe to a scoped video-media stream. See {@link useAudio} for\n * shared semantics; pair with {@link useMediaURL} for `<video src>`.\n */\nexport function useVideo(\n stream: AnyStream,\n target?: SelectorTarget\n): VideoMedia[] {\n const namespace = resolveNamespace(target);\n const key = `video|${namespaceKey(namespace)}`;\n return useProjection<VideoMedia[]>(\n getRegistry(stream),\n () => videoProjection(namespace),\n key,\n EMPTY_VIDEO\n );\n}\n\nconst EMPTY_VIDEO: VideoMedia[] = [];\n\n/**\n * Subscribe to a scoped file-media stream. See {@link useAudio} for\n * shared semantics; pair with {@link useMediaURL} for an\n * `<a download href>` target.\n */\nexport function useFiles(\n stream: AnyStream,\n target?: SelectorTarget\n): FileMedia[] {\n const namespace = resolveNamespace(target);\n const key = `files|${namespaceKey(namespace)}`;\n return useProjection<FileMedia[]>(\n getRegistry(stream),\n () => filesProjection(namespace),\n key,\n EMPTY_FILES\n );\n}\n\nconst EMPTY_FILES: FileMedia[] = [];\n\nexport type UseChannelOptions = ChannelProjectionOptions;\n\nexport function useChannel(\n stream: AnyStream,\n channels: readonly Channel[],\n target?: SelectorTarget,\n options?: UseChannelOptions\n): Event[] {\n const namespace = resolveNamespace(target);\n const channelKey = useMemo(() => [...channels].sort().join(\",\"), [channels]);\n const key = `channel|${options?.bufferSize ?? \"default\"}|${(options?.replay ?? true) ? \"replay\" : \"live\"}|${channelKey}|${namespaceKey(namespace)}`;\n return useProjection<Event[]>(\n getRegistry(stream),\n () => channelProjection(channels, namespace, options),\n key,\n EMPTY_EVENTS\n );\n}\n\nconst EMPTY_EVENTS: Event[] = [];\n\n/**\n * Read metadata recorded for a specific message id — today exposes\n * `parentCheckpointId`, the checkpoint the message was first seen on.\n * Designed for fork / edit flows:\n *\n * ```tsx\n * const { parentCheckpointId } = useMessageMetadata(stream, msg.id) ?? {};\n * if (parentCheckpointId) {\n * await stream.submit(input, { forkFrom: { checkpointId: parentCheckpointId } });\n * }\n * ```\n *\n * Returns `undefined` when the id isn't known yet (e.g. the server\n * hasn't emitted `parent_checkpoint` for that message, or the message\n * arrived via `messages`-channel deltas only and no `values` snapshot\n * has landed for it yet).\n */\nexport function useMessageMetadata(\n stream: AnyStream,\n messageId: string | undefined\n): MessageMetadata | undefined {\n const store = stream[STREAM_CONTROLLER].messageMetadataStore;\n const snapshot = useSyncExternalStore<MessageMetadataMap>(\n store.subscribe,\n store.getSnapshot,\n store.getSnapshot\n );\n return messageId == null ? undefined : snapshot.get(messageId);\n}\n\n/**\n * Reactive handle on the server-side submission queue.\n *\n * Populated when `submit()` is invoked with `multitaskStrategy:\n * \"enqueue\"` while another run is in flight. The returned object is\n * stable per snapshot so consumers can pass `entries` straight into a\n * `<Fragment key={e.id}>` list without extra memoisation.\n */\nexport interface UseSubmissionQueueReturn<\n StateType extends object = Record<string, unknown>,\n> {\n readonly entries: SubmissionQueueSnapshot<StateType>;\n readonly size: number;\n cancel(id: string): Promise<boolean>;\n clear(): Promise<void>;\n}\n\nexport function useSubmissionQueue<StateType extends object>(\n stream: StreamHandle<StateType>\n): UseSubmissionQueueReturn<StateType>;\nexport function useSubmissionQueue(stream: AnyStream): UseSubmissionQueueReturn;\nexport function useSubmissionQueue(\n stream: AnyStream\n): UseSubmissionQueueReturn {\n const controller = stream[STREAM_CONTROLLER];\n const store = controller.queueStore;\n const entries = useSyncExternalStore<SubmissionQueueSnapshot>(\n store.subscribe,\n store.getSnapshot,\n store.getSnapshot\n );\n return useMemo<UseSubmissionQueueReturn>(\n () => ({\n entries,\n size: entries.length,\n cancel: (id) => controller.cancelQueued(id),\n clear: () => controller.clearQueue(),\n }),\n [entries, controller]\n );\n}\n\nexport type { SubmissionQueueEntry, SubmissionQueueSnapshot };\n"],"mappings":";;;;;;AA6EA,SAAS,iBAAiB,QAA2C;AACnE,KAAI,UAAU,KAAM,QAAO;AAC3B,KAAI,MAAM,QAAQ,OAAO,CAAE,QAAO;AAElC,QADY,OACD,aAAa;;AAG1B,MAAM,kBAAqC,EAAE;AAE7C,SAAS,OAAO,WAA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P;AACD,QAAO,aAAa,OAAO,KAAA,IAAY,SAAS,IAAI,UAAU;;AAwBhE,SAAgB,mBACd,QAC0B;CAC1B,MAAM,aAAa,OAAO;CAC1B,MAAM,QAAQ,WAAW;CACzB,MAAM,UAAU,qBACd,MAAM,WACN,MAAM,aACN,MAAM,YACP;AACD,QAAO,eACE;EACL;EACA,MAAM,QAAQ;EACd,SAAS,OAAO,WAAW,aAAa,GAAG;EAC3C,aAAa,WAAW,YAAY;EACrC,GACD,CAAC,SAAS,WAAW,CACtB"}
@@ -53,6 +53,7 @@ function useSuspenseStream(options) {
53
53
  },
54
54
  submit: stream.submit,
55
55
  stop: stream.stop,
56
+ disconnect: stream.disconnect,
56
57
  respond: stream.respond,
57
58
  getThread: stream.getThread,
58
59
  get client() {
@@ -1 +1 @@
1
- {"version":3,"file":"suspense-stream.cjs","names":["useStream"],"sources":["../src/suspense-stream.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\n\"use client\";\n\n/**\n * Slim v1 port of `useSuspenseStream`.\n *\n * Rebuilt on top of the v2-native {@link useStream} hook. The legacy\n * implementation (pre-v1) prefetched `threads.getHistory(threadId)`\n * into an external `SuspenseCache` because the legacy hook had no\n * hydration affordance. v1 drops the `history` surface entirely and\n * exposes {@link StreamController.hydrationPromise} directly, so the\n * suspense integration reduces to:\n *\n * 1. Suspend (throw the hydration promise) while the first hydrate\n * call for the current thread is in flight.\n * 2. Throw non-streaming errors to the nearest Error Boundary.\n * 3. Rename `isLoading` → `isStreaming` so the caller can model a\n * rendered-but-streaming state distinct from the suspended\n * initial-load state.\n *\n * Dropped from the pre-v1 surface (replaced by the built-in hydrate\n * lifecycle or no longer applicable once `history` is gone):\n *\n * - `SuspenseCache`, `createSuspenseCache`, `invalidateSuspenseCache`\n * - the `suspenseCache` option\n * - the `fetchStateHistory: { limit }` prefetch knob\n */\n\nimport type { Interrupt } from \"@langchain/langgraph-sdk\";\nimport type {\n AssembledToolCall,\n SubagentDiscoverySnapshot,\n SubgraphDiscoverySnapshot,\n SubmissionQueueEntry,\n SubmissionQueueSnapshot,\n InferStateType,\n} from \"@langchain/langgraph-sdk/stream\";\nimport {\n useStream,\n type UseStreamOptions,\n type UseStreamReturn,\n} from \"./use-stream.js\";\n\n/**\n * Return shape of {@link useSuspenseStream}. Identical to the\n * {@link UseStreamReturn} surface except:\n *\n * - `isLoading` / `isThreadLoading` / `hydrationPromise` are removed\n * (Suspense and Error Boundaries handle those phases).\n * - `isStreaming: boolean` is added so callers can show a streaming\n * indicator distinct from the suspended initial-load state.\n */\nexport type UseSuspenseStreamReturn<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n> = Omit<\n UseStreamReturn<T, InterruptType, ConfigurableType>,\n \"isLoading\" | \"isThreadLoading\" | \"hydrationPromise\"\n> & {\n /**\n * Whether the stream is currently receiving data from the server.\n * Unlike the suspended initial-load state, the component stays\n * mounted while `isStreaming` is `true`.\n */\n isStreaming: boolean;\n};\n\n/**\n * Suspense-compatible variant of {@link useStream}.\n *\n * Suspends the component while the initial thread hydration is in\n * flight and throws non-streaming errors to the nearest Error\n * Boundary. During active streaming the component stays rendered and\n * {@link UseSuspenseStreamReturn.isStreaming} indicates whether\n * tokens are arriving.\n *\n * @example\n * ```tsx\n * <ErrorBoundary fallback={<ErrorDisplay />}>\n * <Suspense fallback={<Spinner />}>\n * <Chat />\n * </Suspense>\n * </ErrorBoundary>\n *\n * function Chat() {\n * const { messages, submit, isStreaming } = useSuspenseStream({\n * assistantId: \"agent\",\n * apiUrl: \"http://localhost:2024\",\n * threadId,\n * });\n * return <MessageList messages={messages} streaming={isStreaming} />;\n * }\n * ```\n */\n/**\n * Module-level cache of in-flight / settled hydration attempts keyed\n * on a stable `(apiUrl, assistantId, threadId)` tuple. Required\n * because React Suspense discards the suspended fiber while the\n * thrown promise is unresolved, so the `StreamController` (and its\n * `hydrationPromise`) created in one render is thrown away before\n * the next render runs. Without this external store we'd spawn a\n * fresh controller on every retry and never converge.\n *\n * The cache stores the settled outcome (success/failure) so\n * re-renders after commit short-circuit without waiting. Entries are\n * keyed loosely — two mounts of the same `(apiUrl, assistantId,\n * threadId)` tuple share a single hydration.\n */\ninterface SuspenseEntry {\n promise: Promise<void>;\n settled: boolean;\n error?: Error;\n}\nconst suspenseEntries = new Map<string, SuspenseEntry>();\n\nfunction suspenseKey(options: {\n apiUrl?: string;\n assistantId?: string;\n threadId?: string | null;\n}): string | null {\n if (options.threadId == null) return null;\n return `${options.apiUrl ?? \"_\"}::${options.assistantId ?? \"_\"}::${options.threadId}`;\n}\n\nexport function useSuspenseStream<T = Record<string, unknown>>(\n options: UseStreamOptions<InferStateType<T>>\n): UseSuspenseStreamReturn<T> {\n const asBag = options as {\n apiUrl?: string;\n assistantId?: string;\n threadId?: string | null;\n };\n const key = suspenseKey(asBag);\n\n const stream = useStream<T>(options as Parameters<typeof useStream<T>>[0]);\n\n // First render for this `(apiUrl, assistantId, threadId)`: install\n // an entry that tracks the current controller's hydration. The\n // same promise is thrown on every retry, so React Suspense sees a\n // stable dependency even when the fiber — and its controller — is\n // discarded and rebuilt between retries.\n if (key != null && !suspenseEntries.has(key)) {\n const entry: SuspenseEntry = {\n promise: stream.hydrationPromise.then(\n () => {\n entry.settled = true;\n },\n (error) => {\n entry.settled = true;\n entry.error =\n // eslint-disable-next-line no-instanceof/no-instanceof\n error instanceof Error ? error : new Error(String(error));\n throw entry.error;\n }\n ),\n settled: false,\n };\n suspenseEntries.set(key, entry);\n }\n\n const entry = key != null ? suspenseEntries.get(key) : undefined;\n\n // Suspend until the first hydrate settles. The promise is stable\n // across Suspense retries because it's anchored in the module-\n // level cache, not in the per-render controller.\n if (entry && !entry.settled) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw entry.promise;\n }\n\n // Propagate hydrate failures to the nearest Error Boundary once.\n if (entry?.error != null) {\n throw entry.error;\n }\n\n // Hydration errors surface via `stream.error` after the promise\n // rejects; hand them to the nearest Error Boundary when no run is\n // currently active (streaming errors must stay in-hook so the UI\n // can recover without losing partial content).\n if (stream.error != null && !stream.isLoading) {\n // eslint-disable-next-line no-instanceof/no-instanceof\n throw stream.error instanceof Error\n ? stream.error\n : new Error(String(stream.error));\n }\n\n // Build the return object with explicit getters so lazy access\n // still reflects the latest snapshot even if the caller destructures\n // late in a render.\n return {\n get values() {\n return stream.values as UseSuspenseStreamReturn<T>[\"values\"];\n },\n get messages() {\n return stream.messages;\n },\n get toolCalls(): AssembledToolCall[] {\n return stream.toolCalls;\n },\n get interrupt(): Interrupt | undefined {\n return stream.interrupt as Interrupt | undefined;\n },\n get interrupts(): Interrupt[] {\n return stream.interrupts as Interrupt[];\n },\n get subagents() {\n return stream.subagents as ReadonlyMap<\n string,\n SubagentDiscoverySnapshot\n > as UseSuspenseStreamReturn<T>[\"subagents\"];\n },\n get subgraphs(): ReadonlyMap<string, SubgraphDiscoverySnapshot> {\n return stream.subgraphs;\n },\n get subgraphsByNode(): ReadonlyMap<\n string,\n readonly SubgraphDiscoverySnapshot[]\n > {\n return stream.subgraphsByNode;\n },\n submit: stream.submit as UseSuspenseStreamReturn<T>[\"submit\"],\n stop: stream.stop,\n respond: stream.respond as UseSuspenseStreamReturn<T>[\"respond\"],\n getThread: stream.getThread,\n get client() {\n return stream.client;\n },\n get assistantId() {\n return stream.assistantId;\n },\n get threadId() {\n return stream.threadId;\n },\n get error() {\n return stream.error;\n },\n get isStreaming() {\n return stream.isLoading;\n },\n } as UseSuspenseStreamReturn<T>;\n}\n\n// Re-export the transitional companion types so existing call sites\n// keep resolving without reaching into `./use-stream.js` directly.\nexport type { SubmissionQueueEntry, SubmissionQueueSnapshot };\n"],"mappings":";;;AAmHA,MAAM,kCAAkB,IAAI,KAA4B;AAExD,SAAS,YAAY,SAIH;AAChB,KAAI,QAAQ,YAAY,KAAM,QAAO;AACrC,QAAO,GAAG,QAAQ,UAAU,IAAI,IAAI,QAAQ,eAAe,IAAI,IAAI,QAAQ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;;EAEhB,IAAI,cAAc;AAChB,UAAO,OAAO;;EAEjB"}
1
+ {"version":3,"file":"suspense-stream.cjs","names":["useStream"],"sources":["../src/suspense-stream.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\n\"use client\";\n\n/**\n * Slim v1 port of `useSuspenseStream`.\n *\n * Rebuilt on top of the v2-native {@link useStream} hook. The legacy\n * implementation (pre-v1) prefetched `threads.getHistory(threadId)`\n * into an external `SuspenseCache` because the legacy hook had no\n * hydration affordance. v1 drops the `history` surface entirely and\n * exposes {@link StreamController.hydrationPromise} directly, so the\n * suspense integration reduces to:\n *\n * 1. Suspend (throw the hydration promise) while the first hydrate\n * call for the current thread is in flight.\n * 2. Throw non-streaming errors to the nearest Error Boundary.\n * 3. Rename `isLoading` → `isStreaming` so the caller can model a\n * rendered-but-streaming state distinct from the suspended\n * initial-load state.\n *\n * Dropped from the pre-v1 surface (replaced by the built-in hydrate\n * lifecycle or no longer applicable once `history` is gone):\n *\n * - `SuspenseCache`, `createSuspenseCache`, `invalidateSuspenseCache`\n * - the `suspenseCache` option\n * - the `fetchStateHistory: { limit }` prefetch knob\n */\n\nimport type { Interrupt } from \"@langchain/langgraph-sdk\";\nimport type {\n AssembledToolCall,\n SubagentDiscoverySnapshot,\n SubgraphDiscoverySnapshot,\n SubmissionQueueEntry,\n SubmissionQueueSnapshot,\n InferStateType,\n} from \"@langchain/langgraph-sdk/stream\";\nimport {\n useStream,\n type UseStreamOptions,\n type UseStreamReturn,\n} from \"./use-stream.js\";\n\n/**\n * Return shape of {@link useSuspenseStream}. Identical to the\n * {@link UseStreamReturn} surface except:\n *\n * - `isLoading` / `isThreadLoading` / `hydrationPromise` are removed\n * (Suspense and Error Boundaries handle those phases).\n * - `isStreaming: boolean` is added so callers can show a streaming\n * indicator distinct from the suspended initial-load state.\n */\nexport type UseSuspenseStreamReturn<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n> = Omit<\n UseStreamReturn<T, InterruptType, ConfigurableType>,\n \"isLoading\" | \"isThreadLoading\" | \"hydrationPromise\"\n> & {\n /**\n * Whether the stream is currently receiving data from the server.\n * Unlike the suspended initial-load state, the component stays\n * mounted while `isStreaming` is `true`.\n */\n isStreaming: boolean;\n};\n\n/**\n * Suspense-compatible variant of {@link useStream}.\n *\n * Suspends the component while the initial thread hydration is in\n * flight and throws non-streaming errors to the nearest Error\n * Boundary. During active streaming the component stays rendered and\n * {@link UseSuspenseStreamReturn.isStreaming} indicates whether\n * tokens are arriving.\n *\n * @example\n * ```tsx\n * <ErrorBoundary fallback={<ErrorDisplay />}>\n * <Suspense fallback={<Spinner />}>\n * <Chat />\n * </Suspense>\n * </ErrorBoundary>\n *\n * function Chat() {\n * const { messages, submit, isStreaming } = useSuspenseStream({\n * assistantId: \"agent\",\n * apiUrl: \"http://localhost:2024\",\n * threadId,\n * });\n * return <MessageList messages={messages} streaming={isStreaming} />;\n * }\n * ```\n */\n/**\n * Module-level cache of in-flight / settled hydration attempts keyed\n * on a stable `(apiUrl, assistantId, threadId)` tuple. Required\n * because React Suspense discards the suspended fiber while the\n * thrown promise is unresolved, so the `StreamController` (and its\n * `hydrationPromise`) created in one render is thrown away before\n * the next render runs. Without this external store we'd spawn a\n * fresh controller on every retry and never converge.\n *\n * The cache stores the settled outcome (success/failure) so\n * re-renders after commit short-circuit without waiting. Entries are\n * keyed loosely — two mounts of the same `(apiUrl, assistantId,\n * threadId)` tuple share a single hydration.\n */\ninterface SuspenseEntry {\n promise: Promise<void>;\n settled: boolean;\n error?: Error;\n}\nconst suspenseEntries = new Map<string, SuspenseEntry>();\n\nfunction suspenseKey(options: {\n apiUrl?: string;\n assistantId?: string;\n threadId?: string | null;\n}): string | null {\n if (options.threadId == null) return null;\n return `${options.apiUrl ?? \"_\"}::${options.assistantId ?? \"_\"}::${options.threadId}`;\n}\n\nexport function useSuspenseStream<T = Record<string, unknown>>(\n options: UseStreamOptions<InferStateType<T>>\n): UseSuspenseStreamReturn<T> {\n const asBag = options as {\n apiUrl?: string;\n assistantId?: string;\n threadId?: string | null;\n };\n const key = suspenseKey(asBag);\n\n const stream = useStream<T>(options as Parameters<typeof useStream<T>>[0]);\n\n // First render for this `(apiUrl, assistantId, threadId)`: install\n // an entry that tracks the current controller's hydration. The\n // same promise is thrown on every retry, so React Suspense sees a\n // stable dependency even when the fiber — and its controller — is\n // discarded and rebuilt between retries.\n if (key != null && !suspenseEntries.has(key)) {\n const entry: SuspenseEntry = {\n promise: stream.hydrationPromise.then(\n () => {\n entry.settled = true;\n },\n (error) => {\n entry.settled = true;\n entry.error =\n // eslint-disable-next-line no-instanceof/no-instanceof\n error instanceof Error ? error : new Error(String(error));\n throw entry.error;\n }\n ),\n settled: false,\n };\n suspenseEntries.set(key, entry);\n }\n\n const entry = key != null ? suspenseEntries.get(key) : undefined;\n\n // Suspend until the first hydrate settles. The promise is stable\n // across Suspense retries because it's anchored in the module-\n // level cache, not in the per-render controller.\n if (entry && !entry.settled) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw entry.promise;\n }\n\n // Propagate hydrate failures to the nearest Error Boundary once.\n if (entry?.error != null) {\n throw entry.error;\n }\n\n // Hydration errors surface via `stream.error` after the promise\n // rejects; hand them to the nearest Error Boundary when no run is\n // currently active (streaming errors must stay in-hook so the UI\n // can recover without losing partial content).\n if (stream.error != null && !stream.isLoading) {\n // eslint-disable-next-line no-instanceof/no-instanceof\n throw stream.error instanceof Error\n ? stream.error\n : new Error(String(stream.error));\n }\n\n // Build the return object with explicit getters so lazy access\n // still reflects the latest snapshot even if the caller destructures\n // late in a render.\n return {\n get values() {\n return stream.values as UseSuspenseStreamReturn<T>[\"values\"];\n },\n get messages() {\n return stream.messages;\n },\n get toolCalls(): AssembledToolCall[] {\n return stream.toolCalls;\n },\n get interrupt(): Interrupt | undefined {\n return stream.interrupt as Interrupt | undefined;\n },\n get interrupts(): Interrupt[] {\n return stream.interrupts as Interrupt[];\n },\n get subagents() {\n return stream.subagents as ReadonlyMap<\n string,\n SubagentDiscoverySnapshot\n > as UseSuspenseStreamReturn<T>[\"subagents\"];\n },\n get subgraphs(): ReadonlyMap<string, SubgraphDiscoverySnapshot> {\n return stream.subgraphs;\n },\n get subgraphsByNode(): ReadonlyMap<\n string,\n readonly SubgraphDiscoverySnapshot[]\n > {\n return stream.subgraphsByNode;\n },\n submit: stream.submit as UseSuspenseStreamReturn<T>[\"submit\"],\n stop: stream.stop,\n disconnect: stream.disconnect,\n respond: stream.respond as UseSuspenseStreamReturn<T>[\"respond\"],\n getThread: stream.getThread,\n get client() {\n return stream.client;\n },\n get assistantId() {\n return stream.assistantId;\n },\n get threadId() {\n return stream.threadId;\n },\n get error() {\n return stream.error;\n },\n get isStreaming() {\n return stream.isLoading;\n },\n } as UseSuspenseStreamReturn<T>;\n}\n\n// Re-export the transitional companion types so existing call sites\n// keep resolving without reaching into `./use-stream.js` directly.\nexport type { SubmissionQueueEntry, SubmissionQueueSnapshot };\n"],"mappings":";;;AAmHA,MAAM,kCAAkB,IAAI,KAA4B;AAExD,SAAS,YAAY,SAIH;AAChB,KAAI,QAAQ,YAAY,KAAM,QAAO;AACrC,QAAO,GAAG,QAAQ,UAAU,IAAI,IAAI,QAAQ,eAAe,IAAI,IAAI,QAAQ;;AAG7E,SAAgB,kBACd,SAC4B;CAM5B,MAAM,MAAM,YALE,QAKgB;CAE9B,MAAM,SAASA,mBAAAA,UAAa,QAA8C;AAO1E,KAAI,OAAO,QAAQ,CAAC,gBAAgB,IAAI,IAAI,EAAE;EAC5C,MAAM,QAAuB;GAC3B,SAAS,OAAO,iBAAiB,WACzB;AACJ,UAAM,UAAU;OAEjB,UAAU;AACT,UAAM,UAAU;AAChB,UAAM,QAEJ,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;AAC3D,UAAM,MAAM;KAEf;GACD,SAAS;GACV;AACD,kBAAgB,IAAI,KAAK,MAAM;;CAGjC,MAAM,QAAQ,OAAO,OAAO,gBAAgB,IAAI,IAAI,GAAG,KAAA;AAKvD,KAAI,SAAS,CAAC,MAAM,QAElB,OAAM,MAAM;AAId,KAAI,OAAO,SAAS,KAClB,OAAM,MAAM;AAOd,KAAI,OAAO,SAAS,QAAQ,CAAC,OAAO,UAElC,OAAM,OAAO,iBAAiB,QAC1B,OAAO,QACP,IAAI,MAAM,OAAO,OAAO,MAAM,CAAC;AAMrC,QAAO;EACL,IAAI,SAAS;AACX,UAAO,OAAO;;EAEhB,IAAI,WAAW;AACb,UAAO,OAAO;;EAEhB,IAAI,YAAiC;AACnC,UAAO,OAAO;;EAEhB,IAAI,YAAmC;AACrC,UAAO,OAAO;;EAEhB,IAAI,aAA0B;AAC5B,UAAO,OAAO;;EAEhB,IAAI,YAAY;AACd,UAAO,OAAO;;EAKhB,IAAI,YAA4D;AAC9D,UAAO,OAAO;;EAEhB,IAAI,kBAGF;AACA,UAAO,OAAO;;EAEhB,QAAQ,OAAO;EACf,MAAM,OAAO;EACb,YAAY,OAAO;EACnB,SAAS,OAAO;EAChB,WAAW,OAAO;EAClB,IAAI,SAAS;AACX,UAAO,OAAO;;EAEhB,IAAI,cAAc;AAChB,UAAO,OAAO;;EAEhB,IAAI,WAAW;AACb,UAAO,OAAO;;EAEhB,IAAI,QAAQ;AACV,UAAO,OAAO;;EAEhB,IAAI,cAAc;AAChB,UAAO,OAAO;;EAEjB"}
@@ -53,6 +53,7 @@ function useSuspenseStream(options) {
53
53
  },
54
54
  submit: stream.submit,
55
55
  stop: stream.stop,
56
+ disconnect: stream.disconnect,
56
57
  respond: stream.respond,
57
58
  getThread: stream.getThread,
58
59
  get client() {
@@ -1 +1 @@
1
- {"version":3,"file":"suspense-stream.js","names":[],"sources":["../src/suspense-stream.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\n\"use client\";\n\n/**\n * Slim v1 port of `useSuspenseStream`.\n *\n * Rebuilt on top of the v2-native {@link useStream} hook. The legacy\n * implementation (pre-v1) prefetched `threads.getHistory(threadId)`\n * into an external `SuspenseCache` because the legacy hook had no\n * hydration affordance. v1 drops the `history` surface entirely and\n * exposes {@link StreamController.hydrationPromise} directly, so the\n * suspense integration reduces to:\n *\n * 1. Suspend (throw the hydration promise) while the first hydrate\n * call for the current thread is in flight.\n * 2. Throw non-streaming errors to the nearest Error Boundary.\n * 3. Rename `isLoading` → `isStreaming` so the caller can model a\n * rendered-but-streaming state distinct from the suspended\n * initial-load state.\n *\n * Dropped from the pre-v1 surface (replaced by the built-in hydrate\n * lifecycle or no longer applicable once `history` is gone):\n *\n * - `SuspenseCache`, `createSuspenseCache`, `invalidateSuspenseCache`\n * - the `suspenseCache` option\n * - the `fetchStateHistory: { limit }` prefetch knob\n */\n\nimport type { Interrupt } from \"@langchain/langgraph-sdk\";\nimport type {\n AssembledToolCall,\n SubagentDiscoverySnapshot,\n SubgraphDiscoverySnapshot,\n SubmissionQueueEntry,\n SubmissionQueueSnapshot,\n InferStateType,\n} from \"@langchain/langgraph-sdk/stream\";\nimport {\n useStream,\n type UseStreamOptions,\n type UseStreamReturn,\n} from \"./use-stream.js\";\n\n/**\n * Return shape of {@link useSuspenseStream}. Identical to the\n * {@link UseStreamReturn} surface except:\n *\n * - `isLoading` / `isThreadLoading` / `hydrationPromise` are removed\n * (Suspense and Error Boundaries handle those phases).\n * - `isStreaming: boolean` is added so callers can show a streaming\n * indicator distinct from the suspended initial-load state.\n */\nexport type UseSuspenseStreamReturn<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n> = Omit<\n UseStreamReturn<T, InterruptType, ConfigurableType>,\n \"isLoading\" | \"isThreadLoading\" | \"hydrationPromise\"\n> & {\n /**\n * Whether the stream is currently receiving data from the server.\n * Unlike the suspended initial-load state, the component stays\n * mounted while `isStreaming` is `true`.\n */\n isStreaming: boolean;\n};\n\n/**\n * Suspense-compatible variant of {@link useStream}.\n *\n * Suspends the component while the initial thread hydration is in\n * flight and throws non-streaming errors to the nearest Error\n * Boundary. During active streaming the component stays rendered and\n * {@link UseSuspenseStreamReturn.isStreaming} indicates whether\n * tokens are arriving.\n *\n * @example\n * ```tsx\n * <ErrorBoundary fallback={<ErrorDisplay />}>\n * <Suspense fallback={<Spinner />}>\n * <Chat />\n * </Suspense>\n * </ErrorBoundary>\n *\n * function Chat() {\n * const { messages, submit, isStreaming } = useSuspenseStream({\n * assistantId: \"agent\",\n * apiUrl: \"http://localhost:2024\",\n * threadId,\n * });\n * return <MessageList messages={messages} streaming={isStreaming} />;\n * }\n * ```\n */\n/**\n * Module-level cache of in-flight / settled hydration attempts keyed\n * on a stable `(apiUrl, assistantId, threadId)` tuple. Required\n * because React Suspense discards the suspended fiber while the\n * thrown promise is unresolved, so the `StreamController` (and its\n * `hydrationPromise`) created in one render is thrown away before\n * the next render runs. Without this external store we'd spawn a\n * fresh controller on every retry and never converge.\n *\n * The cache stores the settled outcome (success/failure) so\n * re-renders after commit short-circuit without waiting. Entries are\n * keyed loosely — two mounts of the same `(apiUrl, assistantId,\n * threadId)` tuple share a single hydration.\n */\ninterface SuspenseEntry {\n promise: Promise<void>;\n settled: boolean;\n error?: Error;\n}\nconst suspenseEntries = new Map<string, SuspenseEntry>();\n\nfunction suspenseKey(options: {\n apiUrl?: string;\n assistantId?: string;\n threadId?: string | null;\n}): string | null {\n if (options.threadId == null) return null;\n return `${options.apiUrl ?? \"_\"}::${options.assistantId ?? \"_\"}::${options.threadId}`;\n}\n\nexport function useSuspenseStream<T = Record<string, unknown>>(\n options: UseStreamOptions<InferStateType<T>>\n): UseSuspenseStreamReturn<T> {\n const asBag = options as {\n apiUrl?: string;\n assistantId?: string;\n threadId?: string | null;\n };\n const key = suspenseKey(asBag);\n\n const stream = useStream<T>(options as Parameters<typeof useStream<T>>[0]);\n\n // First render for this `(apiUrl, assistantId, threadId)`: install\n // an entry that tracks the current controller's hydration. The\n // same promise is thrown on every retry, so React Suspense sees a\n // stable dependency even when the fiber — and its controller — is\n // discarded and rebuilt between retries.\n if (key != null && !suspenseEntries.has(key)) {\n const entry: SuspenseEntry = {\n promise: stream.hydrationPromise.then(\n () => {\n entry.settled = true;\n },\n (error) => {\n entry.settled = true;\n entry.error =\n // eslint-disable-next-line no-instanceof/no-instanceof\n error instanceof Error ? error : new Error(String(error));\n throw entry.error;\n }\n ),\n settled: false,\n };\n suspenseEntries.set(key, entry);\n }\n\n const entry = key != null ? suspenseEntries.get(key) : undefined;\n\n // Suspend until the first hydrate settles. The promise is stable\n // across Suspense retries because it's anchored in the module-\n // level cache, not in the per-render controller.\n if (entry && !entry.settled) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw entry.promise;\n }\n\n // Propagate hydrate failures to the nearest Error Boundary once.\n if (entry?.error != null) {\n throw entry.error;\n }\n\n // Hydration errors surface via `stream.error` after the promise\n // rejects; hand them to the nearest Error Boundary when no run is\n // currently active (streaming errors must stay in-hook so the UI\n // can recover without losing partial content).\n if (stream.error != null && !stream.isLoading) {\n // eslint-disable-next-line no-instanceof/no-instanceof\n throw stream.error instanceof Error\n ? stream.error\n : new Error(String(stream.error));\n }\n\n // Build the return object with explicit getters so lazy access\n // still reflects the latest snapshot even if the caller destructures\n // late in a render.\n return {\n get values() {\n return stream.values as UseSuspenseStreamReturn<T>[\"values\"];\n },\n get messages() {\n return stream.messages;\n },\n get toolCalls(): AssembledToolCall[] {\n return stream.toolCalls;\n },\n get interrupt(): Interrupt | undefined {\n return stream.interrupt as Interrupt | undefined;\n },\n get interrupts(): Interrupt[] {\n return stream.interrupts as Interrupt[];\n },\n get subagents() {\n return stream.subagents as ReadonlyMap<\n string,\n SubagentDiscoverySnapshot\n > as UseSuspenseStreamReturn<T>[\"subagents\"];\n },\n get subgraphs(): ReadonlyMap<string, SubgraphDiscoverySnapshot> {\n return stream.subgraphs;\n },\n get subgraphsByNode(): ReadonlyMap<\n string,\n readonly SubgraphDiscoverySnapshot[]\n > {\n return stream.subgraphsByNode;\n },\n submit: stream.submit as UseSuspenseStreamReturn<T>[\"submit\"],\n stop: stream.stop,\n respond: stream.respond as UseSuspenseStreamReturn<T>[\"respond\"],\n getThread: stream.getThread,\n get client() {\n return stream.client;\n },\n get assistantId() {\n return stream.assistantId;\n },\n get threadId() {\n return stream.threadId;\n },\n get error() {\n return stream.error;\n },\n get isStreaming() {\n return stream.isLoading;\n },\n } as UseSuspenseStreamReturn<T>;\n}\n\n// Re-export the transitional companion types so existing call sites\n// keep resolving without reaching into `./use-stream.js` directly.\nexport type { SubmissionQueueEntry, SubmissionQueueSnapshot };\n"],"mappings":";;;AAmHA,MAAM,kCAAkB,IAAI,KAA4B;AAExD,SAAS,YAAY,SAIH;AAChB,KAAI,QAAQ,YAAY,KAAM,QAAO;AACrC,QAAO,GAAG,QAAQ,UAAU,IAAI,IAAI,QAAQ,eAAe,IAAI,IAAI,QAAQ;;AAG7E,SAAgB,kBACd,SAC4B;CAM5B,MAAM,MAAM,YALE,QAKgB;CAE9B,MAAM,SAAS,UAAa,QAA8C;AAO1E,KAAI,OAAO,QAAQ,CAAC,gBAAgB,IAAI,IAAI,EAAE;EAC5C,MAAM,QAAuB;GAC3B,SAAS,OAAO,iBAAiB,WACzB;AACJ,UAAM,UAAU;OAEjB,UAAU;AACT,UAAM,UAAU;AAChB,UAAM,QAEJ,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;AAC3D,UAAM,MAAM;KAEf;GACD,SAAS;GACV;AACD,kBAAgB,IAAI,KAAK,MAAM;;CAGjC,MAAM,QAAQ,OAAO,OAAO,gBAAgB,IAAI,IAAI,GAAG,KAAA;AAKvD,KAAI,SAAS,CAAC,MAAM,QAElB,OAAM,MAAM;AAId,KAAI,OAAO,SAAS,KAClB,OAAM,MAAM;AAOd,KAAI,OAAO,SAAS,QAAQ,CAAC,OAAO,UAElC,OAAM,OAAO,iBAAiB,QAC1B,OAAO,QACP,IAAI,MAAM,OAAO,OAAO,MAAM,CAAC;AAMrC,QAAO;EACL,IAAI,SAAS;AACX,UAAO,OAAO;;EAEhB,IAAI,WAAW;AACb,UAAO,OAAO;;EAEhB,IAAI,YAAiC;AACnC,UAAO,OAAO;;EAEhB,IAAI,YAAmC;AACrC,UAAO,OAAO;;EAEhB,IAAI,aAA0B;AAC5B,UAAO,OAAO;;EAEhB,IAAI,YAAY;AACd,UAAO,OAAO;;EAKhB,IAAI,YAA4D;AAC9D,UAAO,OAAO;;EAEhB,IAAI,kBAGF;AACA,UAAO,OAAO;;EAEhB,QAAQ,OAAO;EACf,MAAM,OAAO;EACb,SAAS,OAAO;EAChB,WAAW,OAAO;EAClB,IAAI,SAAS;AACX,UAAO,OAAO;;EAEhB,IAAI,cAAc;AAChB,UAAO,OAAO;;EAEhB,IAAI,WAAW;AACb,UAAO,OAAO;;EAEhB,IAAI,QAAQ;AACV,UAAO,OAAO;;EAEhB,IAAI,cAAc;AAChB,UAAO,OAAO;;EAEjB"}
1
+ {"version":3,"file":"suspense-stream.js","names":[],"sources":["../src/suspense-stream.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\n\"use client\";\n\n/**\n * Slim v1 port of `useSuspenseStream`.\n *\n * Rebuilt on top of the v2-native {@link useStream} hook. The legacy\n * implementation (pre-v1) prefetched `threads.getHistory(threadId)`\n * into an external `SuspenseCache` because the legacy hook had no\n * hydration affordance. v1 drops the `history` surface entirely and\n * exposes {@link StreamController.hydrationPromise} directly, so the\n * suspense integration reduces to:\n *\n * 1. Suspend (throw the hydration promise) while the first hydrate\n * call for the current thread is in flight.\n * 2. Throw non-streaming errors to the nearest Error Boundary.\n * 3. Rename `isLoading` → `isStreaming` so the caller can model a\n * rendered-but-streaming state distinct from the suspended\n * initial-load state.\n *\n * Dropped from the pre-v1 surface (replaced by the built-in hydrate\n * lifecycle or no longer applicable once `history` is gone):\n *\n * - `SuspenseCache`, `createSuspenseCache`, `invalidateSuspenseCache`\n * - the `suspenseCache` option\n * - the `fetchStateHistory: { limit }` prefetch knob\n */\n\nimport type { Interrupt } from \"@langchain/langgraph-sdk\";\nimport type {\n AssembledToolCall,\n SubagentDiscoverySnapshot,\n SubgraphDiscoverySnapshot,\n SubmissionQueueEntry,\n SubmissionQueueSnapshot,\n InferStateType,\n} from \"@langchain/langgraph-sdk/stream\";\nimport {\n useStream,\n type UseStreamOptions,\n type UseStreamReturn,\n} from \"./use-stream.js\";\n\n/**\n * Return shape of {@link useSuspenseStream}. Identical to the\n * {@link UseStreamReturn} surface except:\n *\n * - `isLoading` / `isThreadLoading` / `hydrationPromise` are removed\n * (Suspense and Error Boundaries handle those phases).\n * - `isStreaming: boolean` is added so callers can show a streaming\n * indicator distinct from the suspended initial-load state.\n */\nexport type UseSuspenseStreamReturn<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n> = Omit<\n UseStreamReturn<T, InterruptType, ConfigurableType>,\n \"isLoading\" | \"isThreadLoading\" | \"hydrationPromise\"\n> & {\n /**\n * Whether the stream is currently receiving data from the server.\n * Unlike the suspended initial-load state, the component stays\n * mounted while `isStreaming` is `true`.\n */\n isStreaming: boolean;\n};\n\n/**\n * Suspense-compatible variant of {@link useStream}.\n *\n * Suspends the component while the initial thread hydration is in\n * flight and throws non-streaming errors to the nearest Error\n * Boundary. During active streaming the component stays rendered and\n * {@link UseSuspenseStreamReturn.isStreaming} indicates whether\n * tokens are arriving.\n *\n * @example\n * ```tsx\n * <ErrorBoundary fallback={<ErrorDisplay />}>\n * <Suspense fallback={<Spinner />}>\n * <Chat />\n * </Suspense>\n * </ErrorBoundary>\n *\n * function Chat() {\n * const { messages, submit, isStreaming } = useSuspenseStream({\n * assistantId: \"agent\",\n * apiUrl: \"http://localhost:2024\",\n * threadId,\n * });\n * return <MessageList messages={messages} streaming={isStreaming} />;\n * }\n * ```\n */\n/**\n * Module-level cache of in-flight / settled hydration attempts keyed\n * on a stable `(apiUrl, assistantId, threadId)` tuple. Required\n * because React Suspense discards the suspended fiber while the\n * thrown promise is unresolved, so the `StreamController` (and its\n * `hydrationPromise`) created in one render is thrown away before\n * the next render runs. Without this external store we'd spawn a\n * fresh controller on every retry and never converge.\n *\n * The cache stores the settled outcome (success/failure) so\n * re-renders after commit short-circuit without waiting. Entries are\n * keyed loosely — two mounts of the same `(apiUrl, assistantId,\n * threadId)` tuple share a single hydration.\n */\ninterface SuspenseEntry {\n promise: Promise<void>;\n settled: boolean;\n error?: Error;\n}\nconst suspenseEntries = new Map<string, SuspenseEntry>();\n\nfunction suspenseKey(options: {\n apiUrl?: string;\n assistantId?: string;\n threadId?: string | null;\n}): string | null {\n if (options.threadId == null) return null;\n return `${options.apiUrl ?? \"_\"}::${options.assistantId ?? \"_\"}::${options.threadId}`;\n}\n\nexport function useSuspenseStream<T = Record<string, unknown>>(\n options: UseStreamOptions<InferStateType<T>>\n): UseSuspenseStreamReturn<T> {\n const asBag = options as {\n apiUrl?: string;\n assistantId?: string;\n threadId?: string | null;\n };\n const key = suspenseKey(asBag);\n\n const stream = useStream<T>(options as Parameters<typeof useStream<T>>[0]);\n\n // First render for this `(apiUrl, assistantId, threadId)`: install\n // an entry that tracks the current controller's hydration. The\n // same promise is thrown on every retry, so React Suspense sees a\n // stable dependency even when the fiber — and its controller — is\n // discarded and rebuilt between retries.\n if (key != null && !suspenseEntries.has(key)) {\n const entry: SuspenseEntry = {\n promise: stream.hydrationPromise.then(\n () => {\n entry.settled = true;\n },\n (error) => {\n entry.settled = true;\n entry.error =\n // eslint-disable-next-line no-instanceof/no-instanceof\n error instanceof Error ? error : new Error(String(error));\n throw entry.error;\n }\n ),\n settled: false,\n };\n suspenseEntries.set(key, entry);\n }\n\n const entry = key != null ? suspenseEntries.get(key) : undefined;\n\n // Suspend until the first hydrate settles. The promise is stable\n // across Suspense retries because it's anchored in the module-\n // level cache, not in the per-render controller.\n if (entry && !entry.settled) {\n // eslint-disable-next-line @typescript-eslint/no-throw-literal\n throw entry.promise;\n }\n\n // Propagate hydrate failures to the nearest Error Boundary once.\n if (entry?.error != null) {\n throw entry.error;\n }\n\n // Hydration errors surface via `stream.error` after the promise\n // rejects; hand them to the nearest Error Boundary when no run is\n // currently active (streaming errors must stay in-hook so the UI\n // can recover without losing partial content).\n if (stream.error != null && !stream.isLoading) {\n // eslint-disable-next-line no-instanceof/no-instanceof\n throw stream.error instanceof Error\n ? stream.error\n : new Error(String(stream.error));\n }\n\n // Build the return object with explicit getters so lazy access\n // still reflects the latest snapshot even if the caller destructures\n // late in a render.\n return {\n get values() {\n return stream.values as UseSuspenseStreamReturn<T>[\"values\"];\n },\n get messages() {\n return stream.messages;\n },\n get toolCalls(): AssembledToolCall[] {\n return stream.toolCalls;\n },\n get interrupt(): Interrupt | undefined {\n return stream.interrupt as Interrupt | undefined;\n },\n get interrupts(): Interrupt[] {\n return stream.interrupts as Interrupt[];\n },\n get subagents() {\n return stream.subagents as ReadonlyMap<\n string,\n SubagentDiscoverySnapshot\n > as UseSuspenseStreamReturn<T>[\"subagents\"];\n },\n get subgraphs(): ReadonlyMap<string, SubgraphDiscoverySnapshot> {\n return stream.subgraphs;\n },\n get subgraphsByNode(): ReadonlyMap<\n string,\n readonly SubgraphDiscoverySnapshot[]\n > {\n return stream.subgraphsByNode;\n },\n submit: stream.submit as UseSuspenseStreamReturn<T>[\"submit\"],\n stop: stream.stop,\n disconnect: stream.disconnect,\n respond: stream.respond as UseSuspenseStreamReturn<T>[\"respond\"],\n getThread: stream.getThread,\n get client() {\n return stream.client;\n },\n get assistantId() {\n return stream.assistantId;\n },\n get threadId() {\n return stream.threadId;\n },\n get error() {\n return stream.error;\n },\n get isStreaming() {\n return stream.isLoading;\n },\n } as UseSuspenseStreamReturn<T>;\n}\n\n// Re-export the transitional companion types so existing call sites\n// keep resolving without reaching into `./use-stream.js` directly.\nexport type { SubmissionQueueEntry, SubmissionQueueSnapshot };\n"],"mappings":";;;AAmHA,MAAM,kCAAkB,IAAI,KAA4B;AAExD,SAAS,YAAY,SAIH;AAChB,KAAI,QAAQ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AAI,cAAc;AAChB,UAAO,OAAO;;EAEhB,IAAI,WAAW;AACb,UAAO,OAAO;;EAEhB,IAAI,QAAQ;AACV,UAAO,OAAO;;EAEhB,IAAI,cAAc;AAChB,UAAO,OAAO;;EAEjB"}
@@ -152,7 +152,8 @@ function useStream(options) {
152
152
  subgraphs,
153
153
  subgraphsByNode,
154
154
  submit: (input, submitOptions) => controller.submit(input, submitOptions),
155
- stop: () => controller.stop(),
155
+ stop: (options) => controller.stop(options),
156
+ disconnect: () => controller.disconnect(),
156
157
  respond: (response, target) => controller.respond(response, target),
157
158
  getThread: () => controller.getThread(),
158
159
  client,
@@ -1 +1 @@
1
- {"version":3,"file":"use-stream.cjs","names":["ClientCtor","StreamController"],"sources":["../src/use-stream.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\n\"use client\";\n\nimport { useEffect, useMemo, useRef, useSyncExternalStore } from \"react\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport type { Client, Interrupt } from \"@langchain/langgraph-sdk\";\nimport {\n filterOutHeadlessToolInterrupts,\n flushPendingHeadlessToolInterrupts,\n} from \"@langchain/langgraph-sdk\";\nimport {\n Client as ClientCtor,\n type ClientConfig,\n type ThreadStream,\n} from \"@langchain/langgraph-sdk/client\";\nimport {\n StreamController,\n type AgentServerAdapter,\n type AgentServerOptions as StreamAgentServerOptions,\n type ChannelRegistry,\n type CustomAdapterOptions as StreamCustomAdapterOptions,\n type InferStateType,\n type InferSubagentStates,\n type InferToolCalls,\n type RootSnapshot,\n type RunCompletedInfo,\n type RunExecutionInfo,\n type StreamSubmitOptions,\n type SubagentDiscoverySnapshot,\n type SubagentMap,\n type SubgraphByNodeMap,\n type SubgraphDiscoverySnapshot,\n type SubgraphMap,\n type UseStreamOptions as StreamUseStreamOptions,\n type WidenUpdateMessages,\n} from \"@langchain/langgraph-sdk/stream\";\n\nexport type AgentServerOptions<StateType extends object> =\n StreamAgentServerOptions<StateType>;\n\nexport type CustomAdapterOptions<StateType extends object> =\n StreamCustomAdapterOptions<StateType>;\n\nexport type UseStreamOptions<\n StateType extends object = Record<string, unknown>,\n> = StreamUseStreamOptions<StateType>;\n\n/**\n * Private field on the hook return that carries the\n * {@link StreamController} reference. Selector hooks (`useMessages`,\n * `useToolCalls`, …) read this to reach the shared\n * {@link ChannelRegistry}. Typed as a symbol-keyed field to discourage\n * end-user access — use the selector hooks instead.\n *\n * Exported as a unique symbol so type narrowing works across\n * `useMessages(stream, target)` call sites.\n */\nexport const STREAM_CONTROLLER: unique symbol = Symbol.for(\n \"@langchain/react/controller\"\n);\n\nexport interface UseStreamReturn<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n StateType extends object = InferStateType<T>,\n SubagentStates = InferSubagentStates<T>,\n> {\n // ----- always-on root projections -----\n /**\n * The most recent `values`-channel snapshot emitted at the root\n * namespace — i.e. the thread-level state as the server sees it\n * after each superstep. Updated on every root `values` event, not\n * on token-level deltas: if you render `values.messages` directly\n * you'll see full turns appear at once instead of streaming\n * token-by-token. Use {@link messages} (or `useMessages`) for the\n * token-streamed view.\n *\n * Equivalent to calling `useValues(stream)`.\n */\n readonly values: StateType;\n /**\n * Type-only: the resolved state shape. Exposed so consumers can\n * derive companion hook argument types (`useValues<typeof stream>`)\n * without plumbing `T` through their component hierarchy.\n *\n * @internal\n */\n readonly \"~stateType\"?: StateType;\n /**\n * The root message projection. Assembled from two sources and\n * merged in real time:\n *\n * 1. `messages`-channel deltas — token-level streaming events\n * (`message-start`, `content-block-delta`, `message-finish`)\n * emitted by the runtime. These drive live, token-by-token\n * updates.\n * 2. `values.messages` snapshots — the authoritative ordering\n * and any messages the agent produces without token streaming\n * (human turns, tool results, echoes from subagents).\n *\n * If the backend only emits `values` events (no `messages`\n * channel), every message will appear fully-formed on each\n * values update rather than streaming. This is a backend/runtime\n * concern — the React layer faithfully renders whatever the\n * server sends.\n *\n * Equivalent to calling `useMessages(stream)` with no target.\n */\n readonly messages: BaseMessage[];\n /**\n * Root-namespace tool calls assembled from the `tools` channel.\n * Each entry is a fully parsed {@link AssembledToolCall} with\n * name, args, and id — suitable for rendering approval UIs or\n * forwarding to headless tool handlers.\n *\n * When the stream is typed with an agent brand or tool list,\n * entries are narrowed via {@link InferToolCalls}. Equivalent to\n * calling `useToolCalls(stream)` with no target.\n */\n readonly toolCalls: InferToolCalls<T>[];\n /**\n * All unresolved protocol interrupts observed on the root\n * namespace during the active thread. Populated from lifecycle /\n * input events and seeded on hydration from `thread.getState()`.\n * Cleared optimistically when a new run starts or an interrupt is\n * resolved via {@link respond} / `submit({ command: { resume } })`.\n */\n readonly interrupts: Interrupt<InterruptType>[];\n /**\n * Convenience alias for {@link interrupts}[0] — the primary\n * interrupt most UIs should act on when only one is pending.\n * `undefined` when no interrupt is active.\n */\n readonly interrupt: Interrupt<InterruptType> | undefined;\n /**\n * `true` while a run is active or being started on the current\n * thread. Driven by root-namespace lifecycle events (`running` →\n * `true`, terminal phases → `false`). Use this to disable submit\n * buttons and show in-flight spinners.\n */\n readonly isLoading: boolean;\n /**\n * `true` while the initial `thread.getState()` hydration for the\n * active thread is in flight. Distinct from {@link isLoading} —\n * thread loading covers the one-time fetch that seeds\n * {@link values} / {@link messages} before any user submit.\n */\n readonly isThreadLoading: boolean;\n /**\n * Promise that settles when the current thread's initial hydration\n * completes. Exposed so Suspense wrappers can `throw` it until the\n * first {@link StreamController.hydrate} call resolves (or rejects)\n * for the active thread. A fresh promise is installed on every\n * `switchThread`/`threadId` change.\n */\n readonly hydrationPromise: Promise<void>;\n /**\n * The last error observed on the active run or hydration attempt.\n * `undefined` when no error has occurred. Cleared optimistically\n * when a new {@link submit} starts.\n */\n readonly error: unknown;\n /**\n * Id of the thread the controller is bound to. `null` until the\n * first {@link submit} creates or selects a thread (or until an\n * explicit `threadId` option is provided and hydrated).\n */\n readonly threadId: string | null;\n\n // ----- always-on discovery -----\n /**\n * Subagents discovered on the root run. For DeepAgent-typed\n * streams the key set is narrowed to the subagent names declared\n * on the agent brand (`keyof InferSubagentStates<T>`).\n */\n readonly subagents: ReadonlyMap<\n keyof SubagentStates & string extends never\n ? string\n : keyof SubagentStates & string,\n SubagentDiscoverySnapshot\n >;\n /**\n * Subgraphs discovered on the root run.\n *\n * A namespace is classified as a subgraph iff at least one\n * strictly-deeper namespace has been observed with it as a prefix.\n * This is inferred from the lifecycle event stream — plain function\n * nodes (`orchestrator`, `writer` in the nested-stategraph example)\n * never appear here even though the server emits namespaced\n * lifecycle events for them. Promotion is monotonic and retroactive;\n * an entry appears as soon as the first descendant event lands.\n */\n readonly subgraphs: ReadonlyMap<string, SubgraphDiscoverySnapshot>;\n /**\n * Subgraphs indexed by the graph node that produced them\n * (`addNode(\"visualizer_0\", …)`). Each value is an array because\n * parallel fan-outs and loops can spawn multiple invocations of\n * the same node; arrays preserve insertion order. Updates in\n * lock-step with {@link subgraphs}.\n */\n readonly subgraphsByNode: ReadonlyMap<\n string,\n readonly SubgraphDiscoverySnapshot[]\n >;\n\n // ----- imperatives -----\n /**\n * Dispatch a new run on the bound thread.\n *\n * `input` is typed as `Partial<StateType>` so IDE autocompletion\n * surfaces the state keys declared on the root hook. Pass `null`\n * (or omit fields) when resuming an interrupt via `options.command.resume`\n * — the server accepts a null payload in that case.\n */\n submit(\n input: WidenUpdateMessages<Partial<StateType>> | null | undefined,\n options?: StreamSubmitOptions<StateType, ConfigurableType>\n ): Promise<void>;\n /**\n * Abort the in-flight run on the current thread without clearing\n * accumulated state. Sets {@link isLoading} to `false` immediately;\n * {@link values} and {@link messages} are preserved.\n */\n stop(): Promise<void>;\n /**\n * Resume a pending protocol interrupt by sending a response payload\n * back to the interrupted namespace.\n *\n * When `target` is omitted, responds to the latest unresolved\n * interrupt in {@link interrupts}. Pass an explicit\n * `{ interruptId, namespace? }` when multiple interrupts are\n * pending or the interrupt lives in a subgraph namespace.\n */\n respond(\n response: unknown,\n target?: { interruptId: string; namespace?: string[] }\n ): Promise<void>;\n\n // ----- identity -----\n /** LangGraph SDK client used to construct thread streams. */\n readonly client: Client;\n /** Assistant id the thread is bound to for its lifetime. */\n readonly assistantId: string;\n\n /**\n * Returns the bound {@link ThreadStream}, if one exists (`undefined`\n * until the thread is hydrated or the first submit completes). Prefer\n * the projections and selector hooks for UI work; use this for\n * low-level protocol access (raw subscriptions, state commands, etc.).\n */\n getThread(): ThreadStream | undefined;\n\n /** @internal Used by selector hooks (`useMessages`, `useToolCalls`, …). */\n readonly [STREAM_CONTROLLER]: StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >;\n}\n\n/**\n * Erased stream handle useful as a parameter type for helpers and\n * wrapper components that pass a `stream` through to selector hooks\n * (`useMessages`, `useChannel`, …) without reading `values` directly.\n * Any fully-typed `UseStreamReturn<S, I, C>` is\n * assignable to `AnyStream` because the generic slots are `any`\n * (bivariant), which avoids the `CompiledStateGraph` → `Record<string,\n * unknown>` assignment friction you hit when using the bare\n * `UseStreamReturn` default.\n *\n * @example\n * ```tsx\n * function SubgraphCard({ stream, subgraph }: {\n * stream: AnyStream;\n * subgraph: SubgraphDiscoverySnapshot;\n * }) {\n * const messages = useMessages(stream, subgraph);\n * return <Feed messages={messages} />;\n * }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyStream = UseStreamReturn<any, any, any>;\n\n/**\n * React binding for the v2-native stream runtime.\n *\n * `useStream` exposes three always-on projections\n * (`values` / `messages` / `toolCalls`) at the thread root plus\n * cheap discovery maps for subagents / subgraphs. Scoped views of\n * subagents, subgraphs, or any namespaced projection are surfaced via\n * the companion selector hooks:\n *\n * ```tsx\n * const stream = useStream({ assistantId: \"deep-agent\" });\n *\n * // Root messages — always on, already class instances.\n * stream.messages.map((m) => <Bubble key={m.id} msg={m} />);\n *\n * // Subagent view — mount = subscribe, unmount = unsubscribe.\n * function SubagentCard({ subagent }) {\n * const messages = useMessages(stream, subagent);\n * const toolCalls = useToolCalls(stream, subagent);\n * return <>{messages.map(...)}</>;\n * }\n * ```\n *\n * The first generic accepts either a plain state type\n * (`useStream<MyState>()`) *or* a compiled graph type\n * (`useStream<typeof agent>()`); in the latter case the\n * state shape is unwrapped from the graph via {@link InferStateType}, so\n * `stream.values` is always typed as the state, never as the graph\n * class itself.\n */\nexport function useStream<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n>(\n options: UseStreamOptions<InferStateType<T>>\n): UseStreamReturn<T, InterruptType, ConfigurableType> {\n type StateType = InferStateType<T>;\n // Branch-stable narrowings for each code path. The custom-adapter\n // branch can skip LGP client construction entirely, which keeps\n // bundles that *only* use a custom adapter free of the default\n // `sse`/`websocket` transport factories (tree-shaken).\n // Treat the options as a flat bag here — the discriminated union\n // exists to give call sites a nice error message, but at runtime\n // both branches are reachable through the same set of fields.\n interface OptionsBag {\n assistantId?: string;\n threadId?: string | null;\n client?: Client;\n apiUrl?: string;\n apiKey?: string;\n callerOptions?: ClientConfig[\"callerOptions\"];\n defaultHeaders?: ClientConfig[\"defaultHeaders\"];\n transport?: \"sse\" | \"websocket\" | AgentServerAdapter;\n fetch?: typeof fetch;\n webSocketFactory?: (url: string) => WebSocket;\n onThreadId?: (threadId: string) => void;\n onCreated?: (info: RunExecutionInfo) => void;\n onCompleted?: (info: RunCompletedInfo) => void;\n initialValues?: StateType;\n messagesKey?: string;\n }\n const asBag = options as OptionsBag;\n // Narrow once: a non-string `transport` is a custom adapter; anything\n // else (`\"sse\"` / `\"websocket\"` / `undefined`) is a built-in.\n const hasCustomAdapter =\n asBag.transport != null && typeof asBag.transport !== \"string\";\n const transport = asBag.transport;\n\n const client = useMemo<Client>(\n () =>\n asBag.client ??\n (new ClientCtor({\n apiUrl: asBag.apiUrl,\n apiKey: asBag.apiKey,\n callerOptions: asBag.callerOptions,\n defaultHeaders: asBag.defaultHeaders,\n }) as unknown as Client),\n [\n asBag.client,\n asBag.apiUrl,\n asBag.apiKey,\n asBag.callerOptions,\n asBag.defaultHeaders,\n ]\n );\n\n // Custom adapters may omit `assistantId`; the controller still\n // requires one so it has something to forward to `threads.stream`.\n // `\"_\"` is the well-known sentinel for \"adapter doesn't care\".\n const sentinel = \"_\";\n const assistantId =\n \"assistantId\" in options ? (options.assistantId ?? sentinel) : sentinel;\n\n // Recreate the controller only on assistantId / client / transport\n // change; the ThreadStream is bound to one assistant for its\n // lifetime and we want selector-hook subscriptions to stay stable\n // across renders.\n const controller = useMemo(\n () =>\n new StreamController<StateType, InterruptType, ConfigurableType>({\n assistantId,\n // Cast: the runtime `Client` is state-shape agnostic, but the\n // controller declares `client: Client<StateType>` so its own\n // typings line up. Tightening `submit`'s `input` parameter to\n // `Partial<StateType>` surfaced this variance mismatch that\n // was previously masked — the cast is equivalent to the\n // ClientCtor cast above.\n client: client as unknown as Client<StateType>,\n threadId: options.threadId ?? null,\n transport,\n fetch: hasCustomAdapter ? undefined : asBag.fetch,\n webSocketFactory: hasCustomAdapter ? undefined : asBag.webSocketFactory,\n onThreadId: options.onThreadId,\n onCreated: options.onCreated,\n onCompleted: options.onCompleted,\n initialValues: options.initialValues,\n messagesKey: options.messagesKey,\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [client, assistantId, transport]\n );\n\n // Rehydrate on threadId change. The initial hydrate is fired\n // synchronously inside the controller constructor so Suspense\n // callers don't deadlock waiting for an effect that never runs\n // (throwing `hydrationPromise` during render unmounts the subtree\n // before effects fire). We only re-hydrate here when the threadId\n // prop changes after the controller was already constructed with a\n // matching id.\n const lastHydratedRef = useRef<{\n controller: StreamController<StateType, InterruptType, ConfigurableType>;\n threadId: string | null;\n } | null>(null);\n useEffect(() => {\n const target = options.threadId ?? null;\n const last = lastHydratedRef.current;\n if (last?.controller !== controller) {\n // Freshly constructed controller already seeded the hydrate in\n // its constructor — record the id and skip the redundant call.\n lastHydratedRef.current = { controller, threadId: target };\n return;\n }\n if (last.threadId === target) return;\n lastHydratedRef.current = { controller, threadId: target };\n void controller.hydrate(target);\n }, [controller, options.threadId]);\n\n // Dispose on unmount / controller swap.\n //\n // We use `controller.activate()` instead of a naive\n // `() => controller.dispose()` cleanup because React 18+\n // `<StrictMode>` in dev mounts → unmounts → remounts components\n // synchronously to surface cleanup bugs. A naive cleanup would\n // permanently tear the controller down on that first synthetic\n // unmount and turn every subsequent `submit()` into a silent\n // no-op. `activate()` defers disposal to the next microtask and\n // cancels it if the effect re-runs — which is exactly the\n // StrictMode remount pattern.\n useEffect(() => controller.activate(), [controller]);\n\n // Headless-tool handling: if the caller supplied `tools`, watch the\n // root `values.__interrupt__` channel for protocol interrupts that\n // target a registered tool, invoke the handler, and auto-resume the\n // run. Ref-tracks the ids we've already handled so the same\n // interrupt on a subsequent render is never executed twice\n // (StrictMode safe).\n const handledToolsRef = useRef<Set<string>>(new Set());\n useEffect(() => {\n handledToolsRef.current.clear();\n }, [options.threadId]);\n const tools = options.tools;\n const onTool = options.onTool;\n // Subscribe to values + interrupt updates via the root store so the\n // effect re-runs whenever a protocol interrupt lands or the\n // `__interrupt__` key is projected into values, not only on hook\n // re-render. Prefer protocol interrupts from `rootStore.interrupts`\n // (`input.requested` events) because their ids are accepted directly\n // by `Command({ resume })`; fall back to `values.__interrupt__` for\n // older streams that only expose interrupts through values.\n const rootValuesForTools = useSyncExternalStore<StateType>(\n controller.rootStore.subscribe,\n () => controller.rootStore.getSnapshot().values,\n () => controller.rootStore.getSnapshot().values\n );\n const rootInterruptsForTools = useSyncExternalStore<\n readonly Interrupt<InterruptType>[]\n >(\n controller.rootStore.subscribe,\n () => controller.rootStore.getSnapshot().interrupts,\n () => controller.rootStore.getSnapshot().interrupts\n );\n useEffect(() => {\n if (!tools?.length) return;\n const valuesBag = rootValuesForTools as unknown as Record<string, unknown>;\n const protocolInterrupts = rootInterruptsForTools as unknown as Interrupt[];\n const valuesInterrupts = Array.isArray(valuesBag?.__interrupt__)\n ? (valuesBag.__interrupt__ as Interrupt[])\n : [];\n const headlessInterrupts =\n protocolInterrupts.length > 0 ? protocolInterrupts : valuesInterrupts;\n if (headlessInterrupts.length === 0) return;\n flushPendingHeadlessToolInterrupts(\n { ...valuesBag, __interrupt__: headlessInterrupts },\n tools,\n handledToolsRef.current,\n {\n onTool,\n defer: (run) => {\n void Promise.resolve().then(run);\n },\n resumeSubmit: (command) =>\n controller.submit(null, {\n command,\n } as StreamSubmitOptions<StateType, ConfigurableType>),\n }\n );\n }, [controller, tools, onTool, rootValuesForTools, rootInterruptsForTools]);\n\n const root = useSyncExternalStore<RootSnapshot<StateType, InterruptType>>(\n controller.rootStore.subscribe,\n controller.rootStore.getSnapshot,\n controller.rootStore.getSnapshot\n );\n const subagents = useSyncExternalStore<SubagentMap>(\n controller.subagentStore.subscribe,\n controller.subagentStore.getSnapshot,\n controller.subagentStore.getSnapshot\n );\n const subgraphs = useSyncExternalStore<SubgraphMap>(\n controller.subgraphStore.subscribe,\n controller.subgraphStore.getSnapshot,\n controller.subgraphStore.getSnapshot\n );\n const subgraphsByNode = useSyncExternalStore<SubgraphByNodeMap>(\n controller.subgraphByNodeStore.subscribe,\n controller.subgraphByNodeStore.getSnapshot,\n controller.subgraphByNodeStore.getSnapshot\n );\n\n return useMemo<UseStreamReturn<T, InterruptType, ConfigurableType>>(() => {\n const userFacingInterrupts = filterOutHeadlessToolInterrupts(\n root.interrupts\n );\n return {\n values: root.values,\n messages: root.messages,\n toolCalls: root.toolCalls as InferToolCalls<T>[],\n interrupts: userFacingInterrupts,\n interrupt: userFacingInterrupts[0],\n isLoading: root.isLoading,\n isThreadLoading: root.isThreadLoading,\n hydrationPromise: controller.hydrationPromise,\n error: root.error,\n threadId: root.threadId,\n subagents: subagents as UseStreamReturn<\n T,\n InterruptType,\n ConfigurableType\n >[\"subagents\"],\n subgraphs,\n subgraphsByNode,\n submit: (input, submitOptions) => controller.submit(input, submitOptions),\n stop: () => controller.stop(),\n respond: (response, target) => controller.respond(response, target),\n getThread: () => controller.getThread(),\n client,\n assistantId,\n [STREAM_CONTROLLER]: controller,\n } as UseStreamReturn<T, InterruptType, ConfigurableType>;\n }, [\n root,\n subagents,\n subgraphs,\n subgraphsByNode,\n controller,\n client,\n assistantId,\n ]);\n}\n\n/**\n * Convenience alias for the fully-resolved stream handle type.\n */\nexport type UseStreamResult<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n> = UseStreamReturn<T, InterruptType, ConfigurableType>;\n\n/**\n * Helper used by the selector hooks to reach the underlying\n * {@link ChannelRegistry} from a stream handle. Kept internal —\n * application code should call `useMessages`, `useToolCalls`, etc.\n * instead of reading this directly.\n *\n * @internal\n */\nexport function getRegistry(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n stream: UseStreamReturn<any, any, any>\n): ChannelRegistry {\n return stream[STREAM_CONTROLLER].registry;\n}\n\nexport type { ThreadStream };\n"],"mappings":";;;;;;;;;;;;;;;;AA0DA,MAAa,oBAAmC,OAAO,IACrD,8BACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgQD,SAAgB,UAKd,SACqD;CA0BrD,MAAM,QAAQ;CAGd,MAAM,mBACJ,MAAM,aAAa,QAAQ,OAAO,MAAM,cAAc;CACxD,MAAM,YAAY,MAAM;CAExB,MAAM,UAAA,GAAA,MAAA,eAEF,MAAM,UACL,IAAIA,gCAAAA,OAAW;EACd,QAAQ,MAAM;EACd,QAAQ,MAAM;EACd,eAAe,MAAM;EACrB,gBAAgB,MAAM;EACvB,CAAC,EACJ;EACE,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACP,CACF;CAKD,MAAM,WAAW;CACjB,MAAM,cACJ,iBAAiB,UAAW,QAAQ,eAAe,WAAY;CAMjE,MAAM,cAAA,GAAA,MAAA,eAEF,IAAIC,gCAAAA,iBAA6D;EAC/D;EAOQ;EACR,UAAU,QAAQ,YAAY;EAC9B;EACA,OAAO,mBAAmB,KAAA,IAAY,MAAM;EAC5C,kBAAkB,mBAAmB,KAAA,IAAY,MAAM;EACvD,YAAY,QAAQ;EACpB,WA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1
+ {"version":3,"file":"use-stream.cjs","names":["ClientCtor","StreamController"],"sources":["../src/use-stream.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\n\"use client\";\n\nimport { useEffect, useMemo, useRef, useSyncExternalStore } from \"react\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport type { Client, Interrupt } from \"@langchain/langgraph-sdk\";\nimport {\n filterOutHeadlessToolInterrupts,\n flushPendingHeadlessToolInterrupts,\n} from \"@langchain/langgraph-sdk\";\nimport {\n Client as ClientCtor,\n type ClientConfig,\n type ThreadStream,\n} from \"@langchain/langgraph-sdk/client\";\nimport {\n StreamController,\n type AgentServerAdapter,\n type AgentServerOptions as StreamAgentServerOptions,\n type ChannelRegistry,\n type CustomAdapterOptions as StreamCustomAdapterOptions,\n type InferStateType,\n type InferSubagentStates,\n type InferToolCalls,\n type RootSnapshot,\n type RunCompletedInfo,\n type RunExecutionInfo,\n type StreamStopOptions,\n type StreamSubmitOptions,\n type SubagentDiscoverySnapshot,\n type SubagentMap,\n type SubgraphByNodeMap,\n type SubgraphDiscoverySnapshot,\n type SubgraphMap,\n type UseStreamOptions as StreamUseStreamOptions,\n type WidenUpdateMessages,\n} from \"@langchain/langgraph-sdk/stream\";\n\nexport type AgentServerOptions<StateType extends object> =\n StreamAgentServerOptions<StateType>;\n\nexport type CustomAdapterOptions<StateType extends object> =\n StreamCustomAdapterOptions<StateType>;\n\nexport type UseStreamOptions<\n StateType extends object = Record<string, unknown>,\n> = StreamUseStreamOptions<StateType>;\n\n/**\n * Private field on the hook return that carries the\n * {@link StreamController} reference. Selector hooks (`useMessages`,\n * `useToolCalls`, …) read this to reach the shared\n * {@link ChannelRegistry}. Typed as a symbol-keyed field to discourage\n * end-user access — use the selector hooks instead.\n *\n * Exported as a unique symbol so type narrowing works across\n * `useMessages(stream, target)` call sites.\n */\nexport const STREAM_CONTROLLER: unique symbol = Symbol.for(\n \"@langchain/react/controller\"\n);\n\nexport interface UseStreamReturn<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n StateType extends object = InferStateType<T>,\n SubagentStates = InferSubagentStates<T>,\n> {\n // ----- always-on root projections -----\n /**\n * The most recent `values`-channel snapshot emitted at the root\n * namespace — i.e. the thread-level state as the server sees it\n * after each superstep. Updated on every root `values` event, not\n * on token-level deltas: if you render `values.messages` directly\n * you'll see full turns appear at once instead of streaming\n * token-by-token. Use {@link messages} (or `useMessages`) for the\n * token-streamed view.\n *\n * Equivalent to calling `useValues(stream)`.\n */\n readonly values: StateType;\n /**\n * Type-only: the resolved state shape. Exposed so consumers can\n * derive companion hook argument types (`useValues<typeof stream>`)\n * without plumbing `T` through their component hierarchy.\n *\n * @internal\n */\n readonly \"~stateType\"?: StateType;\n /**\n * The root message projection. Assembled from two sources and\n * merged in real time:\n *\n * 1. `messages`-channel deltas — token-level streaming events\n * (`message-start`, `content-block-delta`, `message-finish`)\n * emitted by the runtime. These drive live, token-by-token\n * updates.\n * 2. `values.messages` snapshots — the authoritative ordering\n * and any messages the agent produces without token streaming\n * (human turns, tool results, echoes from subagents).\n *\n * If the backend only emits `values` events (no `messages`\n * channel), every message will appear fully-formed on each\n * values update rather than streaming. This is a backend/runtime\n * concern — the React layer faithfully renders whatever the\n * server sends.\n *\n * Equivalent to calling `useMessages(stream)` with no target.\n */\n readonly messages: BaseMessage[];\n /**\n * Root-namespace tool calls assembled from the `tools` channel.\n * Each entry is a fully parsed {@link AssembledToolCall} with\n * name, args, and id — suitable for rendering approval UIs or\n * forwarding to headless tool handlers.\n *\n * When the stream is typed with an agent brand or tool list,\n * entries are narrowed via {@link InferToolCalls}. Equivalent to\n * calling `useToolCalls(stream)` with no target.\n */\n readonly toolCalls: InferToolCalls<T>[];\n /**\n * All unresolved protocol interrupts observed on the root\n * namespace during the active thread. Populated from lifecycle /\n * input events and seeded on hydration from `thread.getState()`.\n * Cleared optimistically when a new run starts or an interrupt is\n * resolved via {@link respond} / `submit({ command: { resume } })`.\n */\n readonly interrupts: Interrupt<InterruptType>[];\n /**\n * Convenience alias for {@link interrupts}[0] — the primary\n * interrupt most UIs should act on when only one is pending.\n * `undefined` when no interrupt is active.\n */\n readonly interrupt: Interrupt<InterruptType> | undefined;\n /**\n * `true` while a run is active or being started on the current\n * thread. Driven by root-namespace lifecycle events (`running` →\n * `true`, terminal phases → `false`). Use this to disable submit\n * buttons and show in-flight spinners.\n */\n readonly isLoading: boolean;\n /**\n * `true` while the initial `thread.getState()` hydration for the\n * active thread is in flight. Distinct from {@link isLoading} —\n * thread loading covers the one-time fetch that seeds\n * {@link values} / {@link messages} before any user submit.\n */\n readonly isThreadLoading: boolean;\n /**\n * Promise that settles when the current thread's initial hydration\n * completes. Exposed so Suspense wrappers can `throw` it until the\n * first {@link StreamController.hydrate} call resolves (or rejects)\n * for the active thread. A fresh promise is installed on every\n * `switchThread`/`threadId` change.\n */\n readonly hydrationPromise: Promise<void>;\n /**\n * The last error observed on the active run or hydration attempt.\n * `undefined` when no error has occurred. Cleared optimistically\n * when a new {@link submit} starts.\n */\n readonly error: unknown;\n /**\n * Id of the thread the controller is bound to. `null` until the\n * first {@link submit} creates or selects a thread (or until an\n * explicit `threadId` option is provided and hydrated).\n */\n readonly threadId: string | null;\n\n // ----- always-on discovery -----\n /**\n * Subagents discovered on the root run. For DeepAgent-typed\n * streams the key set is narrowed to the subagent names declared\n * on the agent brand (`keyof InferSubagentStates<T>`).\n */\n readonly subagents: ReadonlyMap<\n keyof SubagentStates & string extends never\n ? string\n : keyof SubagentStates & string,\n SubagentDiscoverySnapshot\n >;\n /**\n * Subgraphs discovered on the root run.\n *\n * A namespace is classified as a subgraph iff at least one\n * strictly-deeper namespace has been observed with it as a prefix.\n * This is inferred from the lifecycle event stream — plain function\n * nodes (`orchestrator`, `writer` in the nested-stategraph example)\n * never appear here even though the server emits namespaced\n * lifecycle events for them. Promotion is monotonic and retroactive;\n * an entry appears as soon as the first descendant event lands.\n */\n readonly subgraphs: ReadonlyMap<string, SubgraphDiscoverySnapshot>;\n /**\n * Subgraphs indexed by the graph node that produced them\n * (`addNode(\"visualizer_0\", …)`). Each value is an array because\n * parallel fan-outs and loops can spawn multiple invocations of\n * the same node; arrays preserve insertion order. Updates in\n * lock-step with {@link subgraphs}.\n */\n readonly subgraphsByNode: ReadonlyMap<\n string,\n readonly SubgraphDiscoverySnapshot[]\n >;\n\n // ----- imperatives -----\n /**\n * Dispatch a new run on the bound thread.\n *\n * `input` is typed as `Partial<StateType>` so IDE autocompletion\n * surfaces the state keys declared on the root hook. Pass `null`\n * (or omit fields) when resuming an interrupt via `options.command.resume`\n * — the server accepts a null payload in that case.\n */\n submit(\n input: WidenUpdateMessages<Partial<StateType>> | null | undefined,\n options?: StreamSubmitOptions<StateType, ConfigurableType>\n ): Promise<void>;\n /**\n * Stop the active run on the current thread. By default cancels the\n * run server-side and disconnects the client; pass `{ cancel: false }`\n * or use {@link disconnect} for join/rejoin. Sets {@link isLoading} to\n * `false` immediately; {@link values} and {@link messages} are preserved.\n */\n stop(options?: StreamStopOptions): Promise<void>;\n /**\n * Disconnect the client without cancelling the run server-side.\n * Alias for `stop({ cancel: false })`.\n */\n disconnect(): Promise<void>;\n /**\n * Resume a pending protocol interrupt by sending a response payload\n * back to the interrupted namespace.\n *\n * When `target` is omitted, responds to the latest unresolved\n * interrupt in {@link interrupts}. Pass an explicit\n * `{ interruptId, namespace? }` when multiple interrupts are\n * pending or the interrupt lives in a subgraph namespace.\n */\n respond(\n response: unknown,\n target?: { interruptId: string; namespace?: string[] }\n ): Promise<void>;\n\n // ----- identity -----\n /** LangGraph SDK client used to construct thread streams. */\n readonly client: Client;\n /** Assistant id the thread is bound to for its lifetime. */\n readonly assistantId: string;\n\n /**\n * Returns the bound {@link ThreadStream}, if one exists (`undefined`\n * until the thread is hydrated or the first submit completes). Prefer\n * the projections and selector hooks for UI work; use this for\n * low-level protocol access (raw subscriptions, state commands, etc.).\n */\n getThread(): ThreadStream | undefined;\n\n /** @internal Used by selector hooks (`useMessages`, `useToolCalls`, …). */\n readonly [STREAM_CONTROLLER]: StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >;\n}\n\n/**\n * Erased stream handle useful as a parameter type for helpers and\n * wrapper components that pass a `stream` through to selector hooks\n * (`useMessages`, `useChannel`, …) without reading `values` directly.\n * Any fully-typed `UseStreamReturn<S, I, C>` is\n * assignable to `AnyStream` because the generic slots are `any`\n * (bivariant), which avoids the `CompiledStateGraph` → `Record<string,\n * unknown>` assignment friction you hit when using the bare\n * `UseStreamReturn` default.\n *\n * @example\n * ```tsx\n * function SubgraphCard({ stream, subgraph }: {\n * stream: AnyStream;\n * subgraph: SubgraphDiscoverySnapshot;\n * }) {\n * const messages = useMessages(stream, subgraph);\n * return <Feed messages={messages} />;\n * }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyStream = UseStreamReturn<any, any, any>;\n\n/**\n * React binding for the v2-native stream runtime.\n *\n * `useStream` exposes three always-on projections\n * (`values` / `messages` / `toolCalls`) at the thread root plus\n * cheap discovery maps for subagents / subgraphs. Scoped views of\n * subagents, subgraphs, or any namespaced projection are surfaced via\n * the companion selector hooks:\n *\n * ```tsx\n * const stream = useStream({ assistantId: \"deep-agent\" });\n *\n * // Root messages — always on, already class instances.\n * stream.messages.map((m) => <Bubble key={m.id} msg={m} />);\n *\n * // Subagent view — mount = subscribe, unmount = unsubscribe.\n * function SubagentCard({ subagent }) {\n * const messages = useMessages(stream, subagent);\n * const toolCalls = useToolCalls(stream, subagent);\n * return <>{messages.map(...)}</>;\n * }\n * ```\n *\n * The first generic accepts either a plain state type\n * (`useStream<MyState>()`) *or* a compiled graph type\n * (`useStream<typeof agent>()`); in the latter case the\n * state shape is unwrapped from the graph via {@link InferStateType}, so\n * `stream.values` is always typed as the state, never as the graph\n * class itself.\n */\nexport function useStream<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n>(\n options: UseStreamOptions<InferStateType<T>>\n): UseStreamReturn<T, InterruptType, ConfigurableType> {\n type StateType = InferStateType<T>;\n // Branch-stable narrowings for each code path. The custom-adapter\n // branch can skip LGP client construction entirely, which keeps\n // bundles that *only* use a custom adapter free of the default\n // `sse`/`websocket` transport factories (tree-shaken).\n // Treat the options as a flat bag here — the discriminated union\n // exists to give call sites a nice error message, but at runtime\n // both branches are reachable through the same set of fields.\n interface OptionsBag {\n assistantId?: string;\n threadId?: string | null;\n client?: Client;\n apiUrl?: string;\n apiKey?: string;\n callerOptions?: ClientConfig[\"callerOptions\"];\n defaultHeaders?: ClientConfig[\"defaultHeaders\"];\n transport?: \"sse\" | \"websocket\" | AgentServerAdapter;\n fetch?: typeof fetch;\n webSocketFactory?: (url: string) => WebSocket;\n onThreadId?: (threadId: string) => void;\n onCreated?: (info: RunExecutionInfo) => void;\n onCompleted?: (info: RunCompletedInfo) => void;\n initialValues?: StateType;\n messagesKey?: string;\n }\n const asBag = options as OptionsBag;\n // Narrow once: a non-string `transport` is a custom adapter; anything\n // else (`\"sse\"` / `\"websocket\"` / `undefined`) is a built-in.\n const hasCustomAdapter =\n asBag.transport != null && typeof asBag.transport !== \"string\";\n const transport = asBag.transport;\n\n const client = useMemo<Client>(\n () =>\n asBag.client ??\n (new ClientCtor({\n apiUrl: asBag.apiUrl,\n apiKey: asBag.apiKey,\n callerOptions: asBag.callerOptions,\n defaultHeaders: asBag.defaultHeaders,\n }) as unknown as Client),\n [\n asBag.client,\n asBag.apiUrl,\n asBag.apiKey,\n asBag.callerOptions,\n asBag.defaultHeaders,\n ]\n );\n\n // Custom adapters may omit `assistantId`; the controller still\n // requires one so it has something to forward to `threads.stream`.\n // `\"_\"` is the well-known sentinel for \"adapter doesn't care\".\n const sentinel = \"_\";\n const assistantId =\n \"assistantId\" in options ? (options.assistantId ?? sentinel) : sentinel;\n\n // Recreate the controller only on assistantId / client / transport\n // change; the ThreadStream is bound to one assistant for its\n // lifetime and we want selector-hook subscriptions to stay stable\n // across renders.\n const controller = useMemo(\n () =>\n new StreamController<StateType, InterruptType, ConfigurableType>({\n assistantId,\n // Cast: the runtime `Client` is state-shape agnostic, but the\n // controller declares `client: Client<StateType>` so its own\n // typings line up. Tightening `submit`'s `input` parameter to\n // `Partial<StateType>` surfaced this variance mismatch that\n // was previously masked — the cast is equivalent to the\n // ClientCtor cast above.\n client: client as unknown as Client<StateType>,\n threadId: options.threadId ?? null,\n transport,\n fetch: hasCustomAdapter ? undefined : asBag.fetch,\n webSocketFactory: hasCustomAdapter ? undefined : asBag.webSocketFactory,\n onThreadId: options.onThreadId,\n onCreated: options.onCreated,\n onCompleted: options.onCompleted,\n initialValues: options.initialValues,\n messagesKey: options.messagesKey,\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [client, assistantId, transport]\n );\n\n // Rehydrate on threadId change. The initial hydrate is fired\n // synchronously inside the controller constructor so Suspense\n // callers don't deadlock waiting for an effect that never runs\n // (throwing `hydrationPromise` during render unmounts the subtree\n // before effects fire). We only re-hydrate here when the threadId\n // prop changes after the controller was already constructed with a\n // matching id.\n const lastHydratedRef = useRef<{\n controller: StreamController<StateType, InterruptType, ConfigurableType>;\n threadId: string | null;\n } | null>(null);\n useEffect(() => {\n const target = options.threadId ?? null;\n const last = lastHydratedRef.current;\n if (last?.controller !== controller) {\n // Freshly constructed controller already seeded the hydrate in\n // its constructor — record the id and skip the redundant call.\n lastHydratedRef.current = { controller, threadId: target };\n return;\n }\n if (last.threadId === target) return;\n lastHydratedRef.current = { controller, threadId: target };\n void controller.hydrate(target);\n }, [controller, options.threadId]);\n\n // Dispose on unmount / controller swap.\n //\n // We use `controller.activate()` instead of a naive\n // `() => controller.dispose()` cleanup because React 18+\n // `<StrictMode>` in dev mounts → unmounts → remounts components\n // synchronously to surface cleanup bugs. A naive cleanup would\n // permanently tear the controller down on that first synthetic\n // unmount and turn every subsequent `submit()` into a silent\n // no-op. `activate()` defers disposal to the next microtask and\n // cancels it if the effect re-runs — which is exactly the\n // StrictMode remount pattern.\n useEffect(() => controller.activate(), [controller]);\n\n // Headless-tool handling: if the caller supplied `tools`, watch the\n // root `values.__interrupt__` channel for protocol interrupts that\n // target a registered tool, invoke the handler, and auto-resume the\n // run. Ref-tracks the ids we've already handled so the same\n // interrupt on a subsequent render is never executed twice\n // (StrictMode safe).\n const handledToolsRef = useRef<Set<string>>(new Set());\n useEffect(() => {\n handledToolsRef.current.clear();\n }, [options.threadId]);\n const tools = options.tools;\n const onTool = options.onTool;\n // Subscribe to values + interrupt updates via the root store so the\n // effect re-runs whenever a protocol interrupt lands or the\n // `__interrupt__` key is projected into values, not only on hook\n // re-render. Prefer protocol interrupts from `rootStore.interrupts`\n // (`input.requested` events) because their ids are accepted directly\n // by `Command({ resume })`; fall back to `values.__interrupt__` for\n // older streams that only expose interrupts through values.\n const rootValuesForTools = useSyncExternalStore<StateType>(\n controller.rootStore.subscribe,\n () => controller.rootStore.getSnapshot().values,\n () => controller.rootStore.getSnapshot().values\n );\n const rootInterruptsForTools = useSyncExternalStore<\n readonly Interrupt<InterruptType>[]\n >(\n controller.rootStore.subscribe,\n () => controller.rootStore.getSnapshot().interrupts,\n () => controller.rootStore.getSnapshot().interrupts\n );\n useEffect(() => {\n if (!tools?.length) return;\n const valuesBag = rootValuesForTools as unknown as Record<string, unknown>;\n const protocolInterrupts = rootInterruptsForTools as unknown as Interrupt[];\n const valuesInterrupts = Array.isArray(valuesBag?.__interrupt__)\n ? (valuesBag.__interrupt__ as Interrupt[])\n : [];\n const headlessInterrupts =\n protocolInterrupts.length > 0 ? protocolInterrupts : valuesInterrupts;\n if (headlessInterrupts.length === 0) return;\n flushPendingHeadlessToolInterrupts(\n { ...valuesBag, __interrupt__: headlessInterrupts },\n tools,\n handledToolsRef.current,\n {\n onTool,\n defer: (run) => {\n void Promise.resolve().then(run);\n },\n resumeSubmit: (command) =>\n controller.submit(null, {\n command,\n } as StreamSubmitOptions<StateType, ConfigurableType>),\n }\n );\n }, [controller, tools, onTool, rootValuesForTools, rootInterruptsForTools]);\n\n const root = useSyncExternalStore<RootSnapshot<StateType, InterruptType>>(\n controller.rootStore.subscribe,\n controller.rootStore.getSnapshot,\n controller.rootStore.getSnapshot\n );\n const subagents = useSyncExternalStore<SubagentMap>(\n controller.subagentStore.subscribe,\n controller.subagentStore.getSnapshot,\n controller.subagentStore.getSnapshot\n );\n const subgraphs = useSyncExternalStore<SubgraphMap>(\n controller.subgraphStore.subscribe,\n controller.subgraphStore.getSnapshot,\n controller.subgraphStore.getSnapshot\n );\n const subgraphsByNode = useSyncExternalStore<SubgraphByNodeMap>(\n controller.subgraphByNodeStore.subscribe,\n controller.subgraphByNodeStore.getSnapshot,\n controller.subgraphByNodeStore.getSnapshot\n );\n\n return useMemo<UseStreamReturn<T, InterruptType, ConfigurableType>>(() => {\n const userFacingInterrupts = filterOutHeadlessToolInterrupts(\n root.interrupts\n );\n return {\n values: root.values,\n messages: root.messages,\n toolCalls: root.toolCalls as InferToolCalls<T>[],\n interrupts: userFacingInterrupts,\n interrupt: userFacingInterrupts[0],\n isLoading: root.isLoading,\n isThreadLoading: root.isThreadLoading,\n hydrationPromise: controller.hydrationPromise,\n error: root.error,\n threadId: root.threadId,\n subagents: subagents as UseStreamReturn<\n T,\n InterruptType,\n ConfigurableType\n >[\"subagents\"],\n subgraphs,\n subgraphsByNode,\n submit: (input, submitOptions) => controller.submit(input, submitOptions),\n stop: (options) => controller.stop(options),\n disconnect: () => controller.disconnect(),\n respond: (response, target) => controller.respond(response, target),\n getThread: () => controller.getThread(),\n client,\n assistantId,\n [STREAM_CONTROLLER]: controller,\n } as UseStreamReturn<T, InterruptType, ConfigurableType>;\n }, [\n root,\n subagents,\n subgraphs,\n subgraphsByNode,\n controller,\n client,\n assistantId,\n ]);\n}\n\n/**\n * Convenience alias for the fully-resolved stream handle type.\n */\nexport type UseStreamResult<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n> = UseStreamReturn<T, InterruptType, ConfigurableType>;\n\n/**\n * Helper used by the selector hooks to reach the underlying\n * {@link ChannelRegistry} from a stream handle. Kept internal —\n * application code should call `useMessages`, `useToolCalls`, etc.\n * instead of reading this directly.\n *\n * @internal\n */\nexport function getRegistry(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n stream: UseStreamReturn<any, any, any>\n): ChannelRegistry {\n return stream[STREAM_CONTROLLER].registry;\n}\n\nexport type { ThreadStream };\n"],"mappings":";;;;;;;;;;;;;;;;AA2DA,MAAa,oBAAmC,OAAO,IACrD,8BACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsQD,SAAgB,UAKd,SACqD;CA0BrD,MAAM,QAAQ;CAGd,MAAM,mBACJ,MAAM,aAAa,QAAQ,OAAO,MAAM,cAAc;CACxD,MAAM,YAAY,MAAM;CAExB,MAAM,UAAA,GAAA,MAAA,eAEF,MAAM,UACL,IAAIA,gCAAAA,OAAW;EACd,QAAQ,MAAM;EACd,QAAQ,MAAM;EACd,eAAe,MAAM;EACrB,gBAAgB,MAAM;EACvB,CAAC,EACJ;EACE,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACP,CACF;CAKD,MAAM,WAAW;CACjB,MAAM,cACJ,iBAAiB,UAAW,QAAQ,eAAe,WAAY;CAMjE,MAAM,cAAA,GAAA,MAAA,eAEF,IAAIC,gCAAAA,iBAA6D;EAC/D;EAOQ;EACR,UAAU,QAAQ,YAAY;EAC9B;EACA,OAAO,mBAAmB,KAAA,IAAY,MAAM;EAC5C,kBAAkB,mBAAmB,KAAA,IAAY,MAAM;EACvD,YAAY,QAAQ;EACpB,WAAW,QAAQ;EACnB,aAAa,QAAQ;EACrB,eAAe,QAAQ;EACvB,aAAa,QAAQ;EACtB,CAAC,EAEJ;EAAC;EAAQ;EAAa;EAAU,CACjC;CASD,MAAM,mBAAA,GAAA,MAAA,QAGI,KAAK;AACf,EAAA,GAAA,MAAA,iBAAgB;EACd,MAAM,SAAS,QAAQ,YAAY;EACn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AC;EAAY;EAAO;EAAQ;EAAoB;EAAuB,CAAC;CAE3E,MAAM,QAAA,GAAA,MAAA,sBACJ,WAAW,UAAU,WACrB,WAAW,UAAU,aACrB,WAAW,UAAU,YACtB;CACD,MAAM,aAAA,GAAA,MAAA,sBACJ,WAAW,cAAc,WACzB,WAAW,cAAc,aACzB,WAAW,cAAc,YAC1B;CACD,MAAM,aAAA,GAAA,MAAA,sBACJ,WAAW,cAAc,WACzB,WAAW,cAAc,aACzB,WAAW,cAAc,YAC1B;CACD,MAAM,mBAAA,GAAA,MAAA,sBACJ,WAAW,oBAAoB,WAC/B,WAAW,oBAAoB,aAC/B,WAAW,oBAAoB,YAChC;AAED,SAAA,GAAA,MAAA,eAA0E;EACxE,MAAM,wBAAA,GAAA,yBAAA,iCACJ,KAAK,WACN;AACD,SAAO;GACL,QAAQ,KAAK;GACb,UAAU,KAAK;GACf,WAAW,KAAK;GAChB,YAAY;GACZ,WAAW,qBAAqB;GAChC,WAAW,KAAK;GAChB,iBAAiB,KAAK;GACtB,kBAAkB,WAAW;GAC7B,OAAO,KAAK;GACZ,UAAU,KAAK;GACJ;GAKX;GACA;GACA,SAAS,OAAO,kBAAkB,WAAW,OAAO,OAAO,cAAc;GACzE,OAAO,YAAY,WAAW,KAAK,QAAQ;GAC3C,kBAAkB,WAAW,YAAY;GACzC,UAAU,UAAU,WAAW,WAAW,QAAQ,UAAU,OAAO;GACnE,iBAAiB,WAAW,WAAW;GACvC;GACA;IACC,oBAAoB;GACtB;IACA;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;;;;;;;;;;AAoBJ,SAAgB,YAEd,QACiB;AACjB,QAAO,OAAO,mBAAmB"}
@@ -1,7 +1,7 @@
1
1
  import { BaseMessage } from "@langchain/core/messages";
2
2
  import { Client, Interrupt } from "@langchain/langgraph-sdk";
3
3
  import { ThreadStream } from "@langchain/langgraph-sdk/client";
4
- import { AgentServerOptions, ChannelRegistry, CustomAdapterOptions, InferStateType, InferSubagentStates, InferToolCalls, StreamController, StreamSubmitOptions, SubagentDiscoverySnapshot, SubgraphDiscoverySnapshot, UseStreamOptions, WidenUpdateMessages } from "@langchain/langgraph-sdk/stream";
4
+ import { AgentServerOptions, ChannelRegistry, CustomAdapterOptions, InferStateType, InferSubagentStates, InferToolCalls, StreamController, StreamStopOptions, StreamSubmitOptions, SubagentDiscoverySnapshot, SubgraphDiscoverySnapshot, UseStreamOptions, WidenUpdateMessages } from "@langchain/langgraph-sdk/stream";
5
5
 
6
6
  //#region src/use-stream.d.ts
7
7
  type AgentServerOptions$1<StateType extends object> = AgentServerOptions<StateType>;
@@ -155,11 +155,17 @@ interface UseStreamReturn<T = Record<string, unknown>, InterruptType = unknown,
155
155
  */
156
156
  submit(input: WidenUpdateMessages<Partial<StateType>> | null | undefined, options?: StreamSubmitOptions<StateType, ConfigurableType>): Promise<void>;
157
157
  /**
158
- * Abort the in-flight run on the current thread without clearing
159
- * accumulated state. Sets {@link isLoading} to `false` immediately;
160
- * {@link values} and {@link messages} are preserved.
158
+ * Stop the active run on the current thread. By default cancels the
159
+ * run server-side and disconnects the client; pass `{ cancel: false }`
160
+ * or use {@link disconnect} for join/rejoin. Sets {@link isLoading} to
161
+ * `false` immediately; {@link values} and {@link messages} are preserved.
161
162
  */
162
- stop(): Promise<void>;
163
+ stop(options?: StreamStopOptions): Promise<void>;
164
+ /**
165
+ * Disconnect the client without cancelling the run server-side.
166
+ * Alias for `stop({ cancel: false })`.
167
+ */
168
+ disconnect(): Promise<void>;
163
169
  /**
164
170
  * Resume a pending protocol interrupt by sending a response payload
165
171
  * back to the interrupted namespace.
@@ -1 +1 @@
1
- {"version":3,"file":"use-stream.d.cts","names":[],"sources":["../src/use-stream.ts"],"mappings":";;;;;;KAsCY,oBAAA,6BACV,kBAAA,CAAyB,SAAA;AAAA,KAEf,sBAAA,6BACV,oBAAA,CAA2B,SAAA;AAAA,KAEjB,kBAAA,4BACiB,MAAA,qBACzB,gBAAA,CAAuB,SAAA;;;;;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ThreadStream } from "@langchain/langgraph-sdk/client";
3
- import { AgentServerOptions, ChannelRegistry, CustomAdapterOptions, InferStateType, InferSubagentStates, InferToolCalls, StreamController, StreamSubmitOptions, SubagentDiscoverySnapshot, SubgraphDiscoverySnapshot, UseStreamOptions, WidenUpdateMessages } from "@langchain/langgraph-sdk/stream";
3
+ import { AgentServerOptions, ChannelRegistry, CustomAdapterOptions, InferStateType, InferSubagentStates, InferToolCalls, StreamController, StreamStopOptions, StreamSubmitOptions, SubagentDiscoverySnapshot, SubgraphDiscoverySnapshot, UseStreamOptions, WidenUpdateMessages } from "@langchain/langgraph-sdk/stream";
4
4
  import { BaseMessage } from "@langchain/core/messages";
5
5
 
6
6
  //#region src/use-stream.d.ts
@@ -155,11 +155,17 @@ interface UseStreamReturn<T = Record<string, unknown>, InterruptType = unknown,
155
155
  */
156
156
  submit(input: WidenUpdateMessages<Partial<StateType>> | null | undefined, options?: StreamSubmitOptions<StateType, ConfigurableType>): Promise<void>;
157
157
  /**
158
- * Abort the in-flight run on the current thread without clearing
159
- * accumulated state. Sets {@link isLoading} to `false` immediately;
160
- * {@link values} and {@link messages} are preserved.
158
+ * Stop the active run on the current thread. By default cancels the
159
+ * run server-side and disconnects the client; pass `{ cancel: false }`
160
+ * or use {@link disconnect} for join/rejoin. Sets {@link isLoading} to
161
+ * `false` immediately; {@link values} and {@link messages} are preserved.
161
162
  */
162
- stop(): Promise<void>;
163
+ stop(options?: StreamStopOptions): Promise<void>;
164
+ /**
165
+ * Disconnect the client without cancelling the run server-side.
166
+ * Alias for `stop({ cancel: false })`.
167
+ */
168
+ disconnect(): Promise<void>;
163
169
  /**
164
170
  * Resume a pending protocol interrupt by sending a response payload
165
171
  * back to the interrupted namespace.
@@ -1 +1 @@
1
- {"version":3,"file":"use-stream.d.ts","names":[],"sources":["../src/use-stream.ts"],"mappings":";;;;;;KAsCY,oBAAA,6BACV,kBAAA,CAAyB,SAAA;AAAA,KAEf,sBAAA,6BACV,oBAAA,CAA2B,S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"}
@@ -152,7 +152,8 @@ function useStream(options) {
152
152
  subgraphs,
153
153
  subgraphsByNode,
154
154
  submit: (input, submitOptions) => controller.submit(input, submitOptions),
155
- stop: () => controller.stop(),
155
+ stop: (options) => controller.stop(options),
156
+ disconnect: () => controller.disconnect(),
156
157
  respond: (response, target) => controller.respond(response, target),
157
158
  getThread: () => controller.getThread(),
158
159
  client,
@@ -1 +1 @@
1
- {"version":3,"file":"use-stream.js","names":["ClientCtor"],"sources":["../src/use-stream.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\n\"use client\";\n\nimport { useEffect, useMemo, useRef, useSyncExternalStore } from \"react\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport type { Client, Interrupt } from \"@langchain/langgraph-sdk\";\nimport {\n filterOutHeadlessToolInterrupts,\n flushPendingHeadlessToolInterrupts,\n} from \"@langchain/langgraph-sdk\";\nimport {\n Client as ClientCtor,\n type ClientConfig,\n type ThreadStream,\n} from \"@langchain/langgraph-sdk/client\";\nimport {\n StreamController,\n type AgentServerAdapter,\n type AgentServerOptions as StreamAgentServerOptions,\n type ChannelRegistry,\n type CustomAdapterOptions as StreamCustomAdapterOptions,\n type InferStateType,\n type InferSubagentStates,\n type InferToolCalls,\n type RootSnapshot,\n type RunCompletedInfo,\n type RunExecutionInfo,\n type StreamSubmitOptions,\n type SubagentDiscoverySnapshot,\n type SubagentMap,\n type SubgraphByNodeMap,\n type SubgraphDiscoverySnapshot,\n type SubgraphMap,\n type UseStreamOptions as StreamUseStreamOptions,\n type WidenUpdateMessages,\n} from \"@langchain/langgraph-sdk/stream\";\n\nexport type AgentServerOptions<StateType extends object> =\n StreamAgentServerOptions<StateType>;\n\nexport type CustomAdapterOptions<StateType extends object> =\n StreamCustomAdapterOptions<StateType>;\n\nexport type UseStreamOptions<\n StateType extends object = Record<string, unknown>,\n> = StreamUseStreamOptions<StateType>;\n\n/**\n * Private field on the hook return that carries the\n * {@link StreamController} reference. Selector hooks (`useMessages`,\n * `useToolCalls`, …) read this to reach the shared\n * {@link ChannelRegistry}. Typed as a symbol-keyed field to discourage\n * end-user access — use the selector hooks instead.\n *\n * Exported as a unique symbol so type narrowing works across\n * `useMessages(stream, target)` call sites.\n */\nexport const STREAM_CONTROLLER: unique symbol = Symbol.for(\n \"@langchain/react/controller\"\n);\n\nexport interface UseStreamReturn<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n StateType extends object = InferStateType<T>,\n SubagentStates = InferSubagentStates<T>,\n> {\n // ----- always-on root projections -----\n /**\n * The most recent `values`-channel snapshot emitted at the root\n * namespace — i.e. the thread-level state as the server sees it\n * after each superstep. Updated on every root `values` event, not\n * on token-level deltas: if you render `values.messages` directly\n * you'll see full turns appear at once instead of streaming\n * token-by-token. Use {@link messages} (or `useMessages`) for the\n * token-streamed view.\n *\n * Equivalent to calling `useValues(stream)`.\n */\n readonly values: StateType;\n /**\n * Type-only: the resolved state shape. Exposed so consumers can\n * derive companion hook argument types (`useValues<typeof stream>`)\n * without plumbing `T` through their component hierarchy.\n *\n * @internal\n */\n readonly \"~stateType\"?: StateType;\n /**\n * The root message projection. Assembled from two sources and\n * merged in real time:\n *\n * 1. `messages`-channel deltas — token-level streaming events\n * (`message-start`, `content-block-delta`, `message-finish`)\n * emitted by the runtime. These drive live, token-by-token\n * updates.\n * 2. `values.messages` snapshots — the authoritative ordering\n * and any messages the agent produces without token streaming\n * (human turns, tool results, echoes from subagents).\n *\n * If the backend only emits `values` events (no `messages`\n * channel), every message will appear fully-formed on each\n * values update rather than streaming. This is a backend/runtime\n * concern — the React layer faithfully renders whatever the\n * server sends.\n *\n * Equivalent to calling `useMessages(stream)` with no target.\n */\n readonly messages: BaseMessage[];\n /**\n * Root-namespace tool calls assembled from the `tools` channel.\n * Each entry is a fully parsed {@link AssembledToolCall} with\n * name, args, and id — suitable for rendering approval UIs or\n * forwarding to headless tool handlers.\n *\n * When the stream is typed with an agent brand or tool list,\n * entries are narrowed via {@link InferToolCalls}. Equivalent to\n * calling `useToolCalls(stream)` with no target.\n */\n readonly toolCalls: InferToolCalls<T>[];\n /**\n * All unresolved protocol interrupts observed on the root\n * namespace during the active thread. Populated from lifecycle /\n * input events and seeded on hydration from `thread.getState()`.\n * Cleared optimistically when a new run starts or an interrupt is\n * resolved via {@link respond} / `submit({ command: { resume } })`.\n */\n readonly interrupts: Interrupt<InterruptType>[];\n /**\n * Convenience alias for {@link interrupts}[0] — the primary\n * interrupt most UIs should act on when only one is pending.\n * `undefined` when no interrupt is active.\n */\n readonly interrupt: Interrupt<InterruptType> | undefined;\n /**\n * `true` while a run is active or being started on the current\n * thread. Driven by root-namespace lifecycle events (`running` →\n * `true`, terminal phases → `false`). Use this to disable submit\n * buttons and show in-flight spinners.\n */\n readonly isLoading: boolean;\n /**\n * `true` while the initial `thread.getState()` hydration for the\n * active thread is in flight. Distinct from {@link isLoading} —\n * thread loading covers the one-time fetch that seeds\n * {@link values} / {@link messages} before any user submit.\n */\n readonly isThreadLoading: boolean;\n /**\n * Promise that settles when the current thread's initial hydration\n * completes. Exposed so Suspense wrappers can `throw` it until the\n * first {@link StreamController.hydrate} call resolves (or rejects)\n * for the active thread. A fresh promise is installed on every\n * `switchThread`/`threadId` change.\n */\n readonly hydrationPromise: Promise<void>;\n /**\n * The last error observed on the active run or hydration attempt.\n * `undefined` when no error has occurred. Cleared optimistically\n * when a new {@link submit} starts.\n */\n readonly error: unknown;\n /**\n * Id of the thread the controller is bound to. `null` until the\n * first {@link submit} creates or selects a thread (or until an\n * explicit `threadId` option is provided and hydrated).\n */\n readonly threadId: string | null;\n\n // ----- always-on discovery -----\n /**\n * Subagents discovered on the root run. For DeepAgent-typed\n * streams the key set is narrowed to the subagent names declared\n * on the agent brand (`keyof InferSubagentStates<T>`).\n */\n readonly subagents: ReadonlyMap<\n keyof SubagentStates & string extends never\n ? string\n : keyof SubagentStates & string,\n SubagentDiscoverySnapshot\n >;\n /**\n * Subgraphs discovered on the root run.\n *\n * A namespace is classified as a subgraph iff at least one\n * strictly-deeper namespace has been observed with it as a prefix.\n * This is inferred from the lifecycle event stream — plain function\n * nodes (`orchestrator`, `writer` in the nested-stategraph example)\n * never appear here even though the server emits namespaced\n * lifecycle events for them. Promotion is monotonic and retroactive;\n * an entry appears as soon as the first descendant event lands.\n */\n readonly subgraphs: ReadonlyMap<string, SubgraphDiscoverySnapshot>;\n /**\n * Subgraphs indexed by the graph node that produced them\n * (`addNode(\"visualizer_0\", …)`). Each value is an array because\n * parallel fan-outs and loops can spawn multiple invocations of\n * the same node; arrays preserve insertion order. Updates in\n * lock-step with {@link subgraphs}.\n */\n readonly subgraphsByNode: ReadonlyMap<\n string,\n readonly SubgraphDiscoverySnapshot[]\n >;\n\n // ----- imperatives -----\n /**\n * Dispatch a new run on the bound thread.\n *\n * `input` is typed as `Partial<StateType>` so IDE autocompletion\n * surfaces the state keys declared on the root hook. Pass `null`\n * (or omit fields) when resuming an interrupt via `options.command.resume`\n * — the server accepts a null payload in that case.\n */\n submit(\n input: WidenUpdateMessages<Partial<StateType>> | null | undefined,\n options?: StreamSubmitOptions<StateType, ConfigurableType>\n ): Promise<void>;\n /**\n * Abort the in-flight run on the current thread without clearing\n * accumulated state. Sets {@link isLoading} to `false` immediately;\n * {@link values} and {@link messages} are preserved.\n */\n stop(): Promise<void>;\n /**\n * Resume a pending protocol interrupt by sending a response payload\n * back to the interrupted namespace.\n *\n * When `target` is omitted, responds to the latest unresolved\n * interrupt in {@link interrupts}. Pass an explicit\n * `{ interruptId, namespace? }` when multiple interrupts are\n * pending or the interrupt lives in a subgraph namespace.\n */\n respond(\n response: unknown,\n target?: { interruptId: string; namespace?: string[] }\n ): Promise<void>;\n\n // ----- identity -----\n /** LangGraph SDK client used to construct thread streams. */\n readonly client: Client;\n /** Assistant id the thread is bound to for its lifetime. */\n readonly assistantId: string;\n\n /**\n * Returns the bound {@link ThreadStream}, if one exists (`undefined`\n * until the thread is hydrated or the first submit completes). Prefer\n * the projections and selector hooks for UI work; use this for\n * low-level protocol access (raw subscriptions, state commands, etc.).\n */\n getThread(): ThreadStream | undefined;\n\n /** @internal Used by selector hooks (`useMessages`, `useToolCalls`, …). */\n readonly [STREAM_CONTROLLER]: StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >;\n}\n\n/**\n * Erased stream handle useful as a parameter type for helpers and\n * wrapper components that pass a `stream` through to selector hooks\n * (`useMessages`, `useChannel`, …) without reading `values` directly.\n * Any fully-typed `UseStreamReturn<S, I, C>` is\n * assignable to `AnyStream` because the generic slots are `any`\n * (bivariant), which avoids the `CompiledStateGraph` → `Record<string,\n * unknown>` assignment friction you hit when using the bare\n * `UseStreamReturn` default.\n *\n * @example\n * ```tsx\n * function SubgraphCard({ stream, subgraph }: {\n * stream: AnyStream;\n * subgraph: SubgraphDiscoverySnapshot;\n * }) {\n * const messages = useMessages(stream, subgraph);\n * return <Feed messages={messages} />;\n * }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyStream = UseStreamReturn<any, any, any>;\n\n/**\n * React binding for the v2-native stream runtime.\n *\n * `useStream` exposes three always-on projections\n * (`values` / `messages` / `toolCalls`) at the thread root plus\n * cheap discovery maps for subagents / subgraphs. Scoped views of\n * subagents, subgraphs, or any namespaced projection are surfaced via\n * the companion selector hooks:\n *\n * ```tsx\n * const stream = useStream({ assistantId: \"deep-agent\" });\n *\n * // Root messages — always on, already class instances.\n * stream.messages.map((m) => <Bubble key={m.id} msg={m} />);\n *\n * // Subagent view — mount = subscribe, unmount = unsubscribe.\n * function SubagentCard({ subagent }) {\n * const messages = useMessages(stream, subagent);\n * const toolCalls = useToolCalls(stream, subagent);\n * return <>{messages.map(...)}</>;\n * }\n * ```\n *\n * The first generic accepts either a plain state type\n * (`useStream<MyState>()`) *or* a compiled graph type\n * (`useStream<typeof agent>()`); in the latter case the\n * state shape is unwrapped from the graph via {@link InferStateType}, so\n * `stream.values` is always typed as the state, never as the graph\n * class itself.\n */\nexport function useStream<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n>(\n options: UseStreamOptions<InferStateType<T>>\n): UseStreamReturn<T, InterruptType, ConfigurableType> {\n type StateType = InferStateType<T>;\n // Branch-stable narrowings for each code path. The custom-adapter\n // branch can skip LGP client construction entirely, which keeps\n // bundles that *only* use a custom adapter free of the default\n // `sse`/`websocket` transport factories (tree-shaken).\n // Treat the options as a flat bag here — the discriminated union\n // exists to give call sites a nice error message, but at runtime\n // both branches are reachable through the same set of fields.\n interface OptionsBag {\n assistantId?: string;\n threadId?: string | null;\n client?: Client;\n apiUrl?: string;\n apiKey?: string;\n callerOptions?: ClientConfig[\"callerOptions\"];\n defaultHeaders?: ClientConfig[\"defaultHeaders\"];\n transport?: \"sse\" | \"websocket\" | AgentServerAdapter;\n fetch?: typeof fetch;\n webSocketFactory?: (url: string) => WebSocket;\n onThreadId?: (threadId: string) => void;\n onCreated?: (info: RunExecutionInfo) => void;\n onCompleted?: (info: RunCompletedInfo) => void;\n initialValues?: StateType;\n messagesKey?: string;\n }\n const asBag = options as OptionsBag;\n // Narrow once: a non-string `transport` is a custom adapter; anything\n // else (`\"sse\"` / `\"websocket\"` / `undefined`) is a built-in.\n const hasCustomAdapter =\n asBag.transport != null && typeof asBag.transport !== \"string\";\n const transport = asBag.transport;\n\n const client = useMemo<Client>(\n () =>\n asBag.client ??\n (new ClientCtor({\n apiUrl: asBag.apiUrl,\n apiKey: asBag.apiKey,\n callerOptions: asBag.callerOptions,\n defaultHeaders: asBag.defaultHeaders,\n }) as unknown as Client),\n [\n asBag.client,\n asBag.apiUrl,\n asBag.apiKey,\n asBag.callerOptions,\n asBag.defaultHeaders,\n ]\n );\n\n // Custom adapters may omit `assistantId`; the controller still\n // requires one so it has something to forward to `threads.stream`.\n // `\"_\"` is the well-known sentinel for \"adapter doesn't care\".\n const sentinel = \"_\";\n const assistantId =\n \"assistantId\" in options ? (options.assistantId ?? sentinel) : sentinel;\n\n // Recreate the controller only on assistantId / client / transport\n // change; the ThreadStream is bound to one assistant for its\n // lifetime and we want selector-hook subscriptions to stay stable\n // across renders.\n const controller = useMemo(\n () =>\n new StreamController<StateType, InterruptType, ConfigurableType>({\n assistantId,\n // Cast: the runtime `Client` is state-shape agnostic, but the\n // controller declares `client: Client<StateType>` so its own\n // typings line up. Tightening `submit`'s `input` parameter to\n // `Partial<StateType>` surfaced this variance mismatch that\n // was previously masked — the cast is equivalent to the\n // ClientCtor cast above.\n client: client as unknown as Client<StateType>,\n threadId: options.threadId ?? null,\n transport,\n fetch: hasCustomAdapter ? undefined : asBag.fetch,\n webSocketFactory: hasCustomAdapter ? undefined : asBag.webSocketFactory,\n onThreadId: options.onThreadId,\n onCreated: options.onCreated,\n onCompleted: options.onCompleted,\n initialValues: options.initialValues,\n messagesKey: options.messagesKey,\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [client, assistantId, transport]\n );\n\n // Rehydrate on threadId change. The initial hydrate is fired\n // synchronously inside the controller constructor so Suspense\n // callers don't deadlock waiting for an effect that never runs\n // (throwing `hydrationPromise` during render unmounts the subtree\n // before effects fire). We only re-hydrate here when the threadId\n // prop changes after the controller was already constructed with a\n // matching id.\n const lastHydratedRef = useRef<{\n controller: StreamController<StateType, InterruptType, ConfigurableType>;\n threadId: string | null;\n } | null>(null);\n useEffect(() => {\n const target = options.threadId ?? null;\n const last = lastHydratedRef.current;\n if (last?.controller !== controller) {\n // Freshly constructed controller already seeded the hydrate in\n // its constructor — record the id and skip the redundant call.\n lastHydratedRef.current = { controller, threadId: target };\n return;\n }\n if (last.threadId === target) return;\n lastHydratedRef.current = { controller, threadId: target };\n void controller.hydrate(target);\n }, [controller, options.threadId]);\n\n // Dispose on unmount / controller swap.\n //\n // We use `controller.activate()` instead of a naive\n // `() => controller.dispose()` cleanup because React 18+\n // `<StrictMode>` in dev mounts → unmounts → remounts components\n // synchronously to surface cleanup bugs. A naive cleanup would\n // permanently tear the controller down on that first synthetic\n // unmount and turn every subsequent `submit()` into a silent\n // no-op. `activate()` defers disposal to the next microtask and\n // cancels it if the effect re-runs — which is exactly the\n // StrictMode remount pattern.\n useEffect(() => controller.activate(), [controller]);\n\n // Headless-tool handling: if the caller supplied `tools`, watch the\n // root `values.__interrupt__` channel for protocol interrupts that\n // target a registered tool, invoke the handler, and auto-resume the\n // run. Ref-tracks the ids we've already handled so the same\n // interrupt on a subsequent render is never executed twice\n // (StrictMode safe).\n const handledToolsRef = useRef<Set<string>>(new Set());\n useEffect(() => {\n handledToolsRef.current.clear();\n }, [options.threadId]);\n const tools = options.tools;\n const onTool = options.onTool;\n // Subscribe to values + interrupt updates via the root store so the\n // effect re-runs whenever a protocol interrupt lands or the\n // `__interrupt__` key is projected into values, not only on hook\n // re-render. Prefer protocol interrupts from `rootStore.interrupts`\n // (`input.requested` events) because their ids are accepted directly\n // by `Command({ resume })`; fall back to `values.__interrupt__` for\n // older streams that only expose interrupts through values.\n const rootValuesForTools = useSyncExternalStore<StateType>(\n controller.rootStore.subscribe,\n () => controller.rootStore.getSnapshot().values,\n () => controller.rootStore.getSnapshot().values\n );\n const rootInterruptsForTools = useSyncExternalStore<\n readonly Interrupt<InterruptType>[]\n >(\n controller.rootStore.subscribe,\n () => controller.rootStore.getSnapshot().interrupts,\n () => controller.rootStore.getSnapshot().interrupts\n );\n useEffect(() => {\n if (!tools?.length) return;\n const valuesBag = rootValuesForTools as unknown as Record<string, unknown>;\n const protocolInterrupts = rootInterruptsForTools as unknown as Interrupt[];\n const valuesInterrupts = Array.isArray(valuesBag?.__interrupt__)\n ? (valuesBag.__interrupt__ as Interrupt[])\n : [];\n const headlessInterrupts =\n protocolInterrupts.length > 0 ? protocolInterrupts : valuesInterrupts;\n if (headlessInterrupts.length === 0) return;\n flushPendingHeadlessToolInterrupts(\n { ...valuesBag, __interrupt__: headlessInterrupts },\n tools,\n handledToolsRef.current,\n {\n onTool,\n defer: (run) => {\n void Promise.resolve().then(run);\n },\n resumeSubmit: (command) =>\n controller.submit(null, {\n command,\n } as StreamSubmitOptions<StateType, ConfigurableType>),\n }\n );\n }, [controller, tools, onTool, rootValuesForTools, rootInterruptsForTools]);\n\n const root = useSyncExternalStore<RootSnapshot<StateType, InterruptType>>(\n controller.rootStore.subscribe,\n controller.rootStore.getSnapshot,\n controller.rootStore.getSnapshot\n );\n const subagents = useSyncExternalStore<SubagentMap>(\n controller.subagentStore.subscribe,\n controller.subagentStore.getSnapshot,\n controller.subagentStore.getSnapshot\n );\n const subgraphs = useSyncExternalStore<SubgraphMap>(\n controller.subgraphStore.subscribe,\n controller.subgraphStore.getSnapshot,\n controller.subgraphStore.getSnapshot\n );\n const subgraphsByNode = useSyncExternalStore<SubgraphByNodeMap>(\n controller.subgraphByNodeStore.subscribe,\n controller.subgraphByNodeStore.getSnapshot,\n controller.subgraphByNodeStore.getSnapshot\n );\n\n return useMemo<UseStreamReturn<T, InterruptType, ConfigurableType>>(() => {\n const userFacingInterrupts = filterOutHeadlessToolInterrupts(\n root.interrupts\n );\n return {\n values: root.values,\n messages: root.messages,\n toolCalls: root.toolCalls as InferToolCalls<T>[],\n interrupts: userFacingInterrupts,\n interrupt: userFacingInterrupts[0],\n isLoading: root.isLoading,\n isThreadLoading: root.isThreadLoading,\n hydrationPromise: controller.hydrationPromise,\n error: root.error,\n threadId: root.threadId,\n subagents: subagents as UseStreamReturn<\n T,\n InterruptType,\n ConfigurableType\n >[\"subagents\"],\n subgraphs,\n subgraphsByNode,\n submit: (input, submitOptions) => controller.submit(input, submitOptions),\n stop: () => controller.stop(),\n respond: (response, target) => controller.respond(response, target),\n getThread: () => controller.getThread(),\n client,\n assistantId,\n [STREAM_CONTROLLER]: controller,\n } as UseStreamReturn<T, InterruptType, ConfigurableType>;\n }, [\n root,\n subagents,\n subgraphs,\n subgraphsByNode,\n controller,\n client,\n assistantId,\n ]);\n}\n\n/**\n * Convenience alias for the fully-resolved stream handle type.\n */\nexport type UseStreamResult<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n> = UseStreamReturn<T, InterruptType, ConfigurableType>;\n\n/**\n * Helper used by the selector hooks to reach the underlying\n * {@link ChannelRegistry} from a stream handle. Kept internal —\n * application code should call `useMessages`, `useToolCalls`, etc.\n * instead of reading this directly.\n *\n * @internal\n */\nexport function getRegistry(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n stream: UseStreamReturn<any, any, any>\n): ChannelRegistry {\n return stream[STREAM_CONTROLLER].registry;\n}\n\nexport type { ThreadStream };\n"],"mappings":";;;;;;;;;;;;;;;;AA0DA,MAAa,oBAAmC,OAAO,IACrD,8BACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgQD,SAAgB,UAKd,SACqD;CA0BrD,MAAM,QAAQ;CAGd,MAAM,mBACJ,MAAM,aAAa,QAAQ,OAAO,MAAM,cAAc;CACxD,MAAM,YAAY,MAAM;CAExB,MAAM,SAAS,cAEX,MAAM,UACL,IAAIA,SAAW;EACd,QAAQ,MAAM;EACd,QAAQ,MAAM;EACd,eAAe,MAAM;EACrB,gBAAgB,MAAM;EACvB,CAAC,EACJ;EACE,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACP,CACF;CAKD,MAAM,WAAW;CACjB,MAAM,cACJ,iBAAiB,UAAW,QAAQ,eAAe,WAAY;CAMjE,MAAM,aAAa,cAEf,IAAI,iBAA6D;EAC/D;EAOQ;EACR,UAAU,QAAQ,YAAY;EAC9B;EACA,OAAO,mBAAmB,KAAA,IAAY,MAAM;EAC5C,kBAAkB,mBAAmB,KAAA,IAAY,MAAM;EACvD,YAAY,QAAQ;EACpB,WAAW,QAAQ;EACnB,aAAa,QAAQ;EACrB,eAAe,QAAQ;EACvB,aAAa,QAAQ;EACtB,CAAC,EAEJ;EAAC;EAAQ;EAAa;EAAU,CACjC;CASD,MAAM,kBAAkB,OAGd,KAAK;AACf,iBAAgB;EACd,MAAM,SAAS,QAAQ,YAAY;EACnC,M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,UAAU,YACtB;CACD,MAAM,YAAY,qBAChB,WAAW,cAAc,WACzB,WAAW,cAAc,aACzB,WAAW,cAAc,YAC1B;CACD,MAAM,YAAY,qBAChB,WAAW,cAAc,WACzB,WAAW,cAAc,aACzB,WAAW,cAAc,YAC1B;CACD,MAAM,kBAAkB,qBACtB,WAAW,oBAAoB,WAC/B,WAAW,oBAAoB,aAC/B,WAAW,oBAAoB,YAChC;AAED,QAAO,cAAmE;EACxE,MAAM,uBAAuB,gCAC3B,KAAK,WACN;AACD,SAAO;GACL,QAAQ,KAAK;GACb,UAAU,KAAK;GACf,WAAW,KAAK;GAChB,YAAY;GACZ,WAAW,qBAAqB;GAChC,WAAW,KAAK;GAChB,iBAAiB,KAAK;GACtB,kBAAkB,WAAW;GAC7B,OAAO,KAAK;GACZ,UAAU,KAAK;GACJ;GAKX;GACA;GACA,SAAS,OAAO,kBAAkB,WAAW,OAAO,OAAO,cAAc;GACzE,YAAY,WAAW,MAAM;GAC7B,UAAU,UAAU,WAAW,WAAW,QAAQ,UAAU,OAAO;GACnE,iBAAiB,WAAW,WAAW;GACvC;GACA;IACC,oBAAoB;GACtB;IACA;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;;;;;;;;;;AAoBJ,SAAgB,YAEd,QACiB;AACjB,QAAO,OAAO,mBAAmB"}
1
+ {"version":3,"file":"use-stream.js","names":["ClientCtor"],"sources":["../src/use-stream.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\n\"use client\";\n\nimport { useEffect, useMemo, useRef, useSyncExternalStore } from \"react\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport type { Client, Interrupt } from \"@langchain/langgraph-sdk\";\nimport {\n filterOutHeadlessToolInterrupts,\n flushPendingHeadlessToolInterrupts,\n} from \"@langchain/langgraph-sdk\";\nimport {\n Client as ClientCtor,\n type ClientConfig,\n type ThreadStream,\n} from \"@langchain/langgraph-sdk/client\";\nimport {\n StreamController,\n type AgentServerAdapter,\n type AgentServerOptions as StreamAgentServerOptions,\n type ChannelRegistry,\n type CustomAdapterOptions as StreamCustomAdapterOptions,\n type InferStateType,\n type InferSubagentStates,\n type InferToolCalls,\n type RootSnapshot,\n type RunCompletedInfo,\n type RunExecutionInfo,\n type StreamStopOptions,\n type StreamSubmitOptions,\n type SubagentDiscoverySnapshot,\n type SubagentMap,\n type SubgraphByNodeMap,\n type SubgraphDiscoverySnapshot,\n type SubgraphMap,\n type UseStreamOptions as StreamUseStreamOptions,\n type WidenUpdateMessages,\n} from \"@langchain/langgraph-sdk/stream\";\n\nexport type AgentServerOptions<StateType extends object> =\n StreamAgentServerOptions<StateType>;\n\nexport type CustomAdapterOptions<StateType extends object> =\n StreamCustomAdapterOptions<StateType>;\n\nexport type UseStreamOptions<\n StateType extends object = Record<string, unknown>,\n> = StreamUseStreamOptions<StateType>;\n\n/**\n * Private field on the hook return that carries the\n * {@link StreamController} reference. Selector hooks (`useMessages`,\n * `useToolCalls`, …) read this to reach the shared\n * {@link ChannelRegistry}. Typed as a symbol-keyed field to discourage\n * end-user access — use the selector hooks instead.\n *\n * Exported as a unique symbol so type narrowing works across\n * `useMessages(stream, target)` call sites.\n */\nexport const STREAM_CONTROLLER: unique symbol = Symbol.for(\n \"@langchain/react/controller\"\n);\n\nexport interface UseStreamReturn<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n StateType extends object = InferStateType<T>,\n SubagentStates = InferSubagentStates<T>,\n> {\n // ----- always-on root projections -----\n /**\n * The most recent `values`-channel snapshot emitted at the root\n * namespace — i.e. the thread-level state as the server sees it\n * after each superstep. Updated on every root `values` event, not\n * on token-level deltas: if you render `values.messages` directly\n * you'll see full turns appear at once instead of streaming\n * token-by-token. Use {@link messages} (or `useMessages`) for the\n * token-streamed view.\n *\n * Equivalent to calling `useValues(stream)`.\n */\n readonly values: StateType;\n /**\n * Type-only: the resolved state shape. Exposed so consumers can\n * derive companion hook argument types (`useValues<typeof stream>`)\n * without plumbing `T` through their component hierarchy.\n *\n * @internal\n */\n readonly \"~stateType\"?: StateType;\n /**\n * The root message projection. Assembled from two sources and\n * merged in real time:\n *\n * 1. `messages`-channel deltas — token-level streaming events\n * (`message-start`, `content-block-delta`, `message-finish`)\n * emitted by the runtime. These drive live, token-by-token\n * updates.\n * 2. `values.messages` snapshots — the authoritative ordering\n * and any messages the agent produces without token streaming\n * (human turns, tool results, echoes from subagents).\n *\n * If the backend only emits `values` events (no `messages`\n * channel), every message will appear fully-formed on each\n * values update rather than streaming. This is a backend/runtime\n * concern — the React layer faithfully renders whatever the\n * server sends.\n *\n * Equivalent to calling `useMessages(stream)` with no target.\n */\n readonly messages: BaseMessage[];\n /**\n * Root-namespace tool calls assembled from the `tools` channel.\n * Each entry is a fully parsed {@link AssembledToolCall} with\n * name, args, and id — suitable for rendering approval UIs or\n * forwarding to headless tool handlers.\n *\n * When the stream is typed with an agent brand or tool list,\n * entries are narrowed via {@link InferToolCalls}. Equivalent to\n * calling `useToolCalls(stream)` with no target.\n */\n readonly toolCalls: InferToolCalls<T>[];\n /**\n * All unresolved protocol interrupts observed on the root\n * namespace during the active thread. Populated from lifecycle /\n * input events and seeded on hydration from `thread.getState()`.\n * Cleared optimistically when a new run starts or an interrupt is\n * resolved via {@link respond} / `submit({ command: { resume } })`.\n */\n readonly interrupts: Interrupt<InterruptType>[];\n /**\n * Convenience alias for {@link interrupts}[0] — the primary\n * interrupt most UIs should act on when only one is pending.\n * `undefined` when no interrupt is active.\n */\n readonly interrupt: Interrupt<InterruptType> | undefined;\n /**\n * `true` while a run is active or being started on the current\n * thread. Driven by root-namespace lifecycle events (`running` →\n * `true`, terminal phases → `false`). Use this to disable submit\n * buttons and show in-flight spinners.\n */\n readonly isLoading: boolean;\n /**\n * `true` while the initial `thread.getState()` hydration for the\n * active thread is in flight. Distinct from {@link isLoading} —\n * thread loading covers the one-time fetch that seeds\n * {@link values} / {@link messages} before any user submit.\n */\n readonly isThreadLoading: boolean;\n /**\n * Promise that settles when the current thread's initial hydration\n * completes. Exposed so Suspense wrappers can `throw` it until the\n * first {@link StreamController.hydrate} call resolves (or rejects)\n * for the active thread. A fresh promise is installed on every\n * `switchThread`/`threadId` change.\n */\n readonly hydrationPromise: Promise<void>;\n /**\n * The last error observed on the active run or hydration attempt.\n * `undefined` when no error has occurred. Cleared optimistically\n * when a new {@link submit} starts.\n */\n readonly error: unknown;\n /**\n * Id of the thread the controller is bound to. `null` until the\n * first {@link submit} creates or selects a thread (or until an\n * explicit `threadId` option is provided and hydrated).\n */\n readonly threadId: string | null;\n\n // ----- always-on discovery -----\n /**\n * Subagents discovered on the root run. For DeepAgent-typed\n * streams the key set is narrowed to the subagent names declared\n * on the agent brand (`keyof InferSubagentStates<T>`).\n */\n readonly subagents: ReadonlyMap<\n keyof SubagentStates & string extends never\n ? string\n : keyof SubagentStates & string,\n SubagentDiscoverySnapshot\n >;\n /**\n * Subgraphs discovered on the root run.\n *\n * A namespace is classified as a subgraph iff at least one\n * strictly-deeper namespace has been observed with it as a prefix.\n * This is inferred from the lifecycle event stream — plain function\n * nodes (`orchestrator`, `writer` in the nested-stategraph example)\n * never appear here even though the server emits namespaced\n * lifecycle events for them. Promotion is monotonic and retroactive;\n * an entry appears as soon as the first descendant event lands.\n */\n readonly subgraphs: ReadonlyMap<string, SubgraphDiscoverySnapshot>;\n /**\n * Subgraphs indexed by the graph node that produced them\n * (`addNode(\"visualizer_0\", …)`). Each value is an array because\n * parallel fan-outs and loops can spawn multiple invocations of\n * the same node; arrays preserve insertion order. Updates in\n * lock-step with {@link subgraphs}.\n */\n readonly subgraphsByNode: ReadonlyMap<\n string,\n readonly SubgraphDiscoverySnapshot[]\n >;\n\n // ----- imperatives -----\n /**\n * Dispatch a new run on the bound thread.\n *\n * `input` is typed as `Partial<StateType>` so IDE autocompletion\n * surfaces the state keys declared on the root hook. Pass `null`\n * (or omit fields) when resuming an interrupt via `options.command.resume`\n * — the server accepts a null payload in that case.\n */\n submit(\n input: WidenUpdateMessages<Partial<StateType>> | null | undefined,\n options?: StreamSubmitOptions<StateType, ConfigurableType>\n ): Promise<void>;\n /**\n * Stop the active run on the current thread. By default cancels the\n * run server-side and disconnects the client; pass `{ cancel: false }`\n * or use {@link disconnect} for join/rejoin. Sets {@link isLoading} to\n * `false` immediately; {@link values} and {@link messages} are preserved.\n */\n stop(options?: StreamStopOptions): Promise<void>;\n /**\n * Disconnect the client without cancelling the run server-side.\n * Alias for `stop({ cancel: false })`.\n */\n disconnect(): Promise<void>;\n /**\n * Resume a pending protocol interrupt by sending a response payload\n * back to the interrupted namespace.\n *\n * When `target` is omitted, responds to the latest unresolved\n * interrupt in {@link interrupts}. Pass an explicit\n * `{ interruptId, namespace? }` when multiple interrupts are\n * pending or the interrupt lives in a subgraph namespace.\n */\n respond(\n response: unknown,\n target?: { interruptId: string; namespace?: string[] }\n ): Promise<void>;\n\n // ----- identity -----\n /** LangGraph SDK client used to construct thread streams. */\n readonly client: Client;\n /** Assistant id the thread is bound to for its lifetime. */\n readonly assistantId: string;\n\n /**\n * Returns the bound {@link ThreadStream}, if one exists (`undefined`\n * until the thread is hydrated or the first submit completes). Prefer\n * the projections and selector hooks for UI work; use this for\n * low-level protocol access (raw subscriptions, state commands, etc.).\n */\n getThread(): ThreadStream | undefined;\n\n /** @internal Used by selector hooks (`useMessages`, `useToolCalls`, …). */\n readonly [STREAM_CONTROLLER]: StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >;\n}\n\n/**\n * Erased stream handle useful as a parameter type for helpers and\n * wrapper components that pass a `stream` through to selector hooks\n * (`useMessages`, `useChannel`, …) without reading `values` directly.\n * Any fully-typed `UseStreamReturn<S, I, C>` is\n * assignable to `AnyStream` because the generic slots are `any`\n * (bivariant), which avoids the `CompiledStateGraph` → `Record<string,\n * unknown>` assignment friction you hit when using the bare\n * `UseStreamReturn` default.\n *\n * @example\n * ```tsx\n * function SubgraphCard({ stream, subgraph }: {\n * stream: AnyStream;\n * subgraph: SubgraphDiscoverySnapshot;\n * }) {\n * const messages = useMessages(stream, subgraph);\n * return <Feed messages={messages} />;\n * }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyStream = UseStreamReturn<any, any, any>;\n\n/**\n * React binding for the v2-native stream runtime.\n *\n * `useStream` exposes three always-on projections\n * (`values` / `messages` / `toolCalls`) at the thread root plus\n * cheap discovery maps for subagents / subgraphs. Scoped views of\n * subagents, subgraphs, or any namespaced projection are surfaced via\n * the companion selector hooks:\n *\n * ```tsx\n * const stream = useStream({ assistantId: \"deep-agent\" });\n *\n * // Root messages — always on, already class instances.\n * stream.messages.map((m) => <Bubble key={m.id} msg={m} />);\n *\n * // Subagent view — mount = subscribe, unmount = unsubscribe.\n * function SubagentCard({ subagent }) {\n * const messages = useMessages(stream, subagent);\n * const toolCalls = useToolCalls(stream, subagent);\n * return <>{messages.map(...)}</>;\n * }\n * ```\n *\n * The first generic accepts either a plain state type\n * (`useStream<MyState>()`) *or* a compiled graph type\n * (`useStream<typeof agent>()`); in the latter case the\n * state shape is unwrapped from the graph via {@link InferStateType}, so\n * `stream.values` is always typed as the state, never as the graph\n * class itself.\n */\nexport function useStream<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n>(\n options: UseStreamOptions<InferStateType<T>>\n): UseStreamReturn<T, InterruptType, ConfigurableType> {\n type StateType = InferStateType<T>;\n // Branch-stable narrowings for each code path. The custom-adapter\n // branch can skip LGP client construction entirely, which keeps\n // bundles that *only* use a custom adapter free of the default\n // `sse`/`websocket` transport factories (tree-shaken).\n // Treat the options as a flat bag here — the discriminated union\n // exists to give call sites a nice error message, but at runtime\n // both branches are reachable through the same set of fields.\n interface OptionsBag {\n assistantId?: string;\n threadId?: string | null;\n client?: Client;\n apiUrl?: string;\n apiKey?: string;\n callerOptions?: ClientConfig[\"callerOptions\"];\n defaultHeaders?: ClientConfig[\"defaultHeaders\"];\n transport?: \"sse\" | \"websocket\" | AgentServerAdapter;\n fetch?: typeof fetch;\n webSocketFactory?: (url: string) => WebSocket;\n onThreadId?: (threadId: string) => void;\n onCreated?: (info: RunExecutionInfo) => void;\n onCompleted?: (info: RunCompletedInfo) => void;\n initialValues?: StateType;\n messagesKey?: string;\n }\n const asBag = options as OptionsBag;\n // Narrow once: a non-string `transport` is a custom adapter; anything\n // else (`\"sse\"` / `\"websocket\"` / `undefined`) is a built-in.\n const hasCustomAdapter =\n asBag.transport != null && typeof asBag.transport !== \"string\";\n const transport = asBag.transport;\n\n const client = useMemo<Client>(\n () =>\n asBag.client ??\n (new ClientCtor({\n apiUrl: asBag.apiUrl,\n apiKey: asBag.apiKey,\n callerOptions: asBag.callerOptions,\n defaultHeaders: asBag.defaultHeaders,\n }) as unknown as Client),\n [\n asBag.client,\n asBag.apiUrl,\n asBag.apiKey,\n asBag.callerOptions,\n asBag.defaultHeaders,\n ]\n );\n\n // Custom adapters may omit `assistantId`; the controller still\n // requires one so it has something to forward to `threads.stream`.\n // `\"_\"` is the well-known sentinel for \"adapter doesn't care\".\n const sentinel = \"_\";\n const assistantId =\n \"assistantId\" in options ? (options.assistantId ?? sentinel) : sentinel;\n\n // Recreate the controller only on assistantId / client / transport\n // change; the ThreadStream is bound to one assistant for its\n // lifetime and we want selector-hook subscriptions to stay stable\n // across renders.\n const controller = useMemo(\n () =>\n new StreamController<StateType, InterruptType, ConfigurableType>({\n assistantId,\n // Cast: the runtime `Client` is state-shape agnostic, but the\n // controller declares `client: Client<StateType>` so its own\n // typings line up. Tightening `submit`'s `input` parameter to\n // `Partial<StateType>` surfaced this variance mismatch that\n // was previously masked — the cast is equivalent to the\n // ClientCtor cast above.\n client: client as unknown as Client<StateType>,\n threadId: options.threadId ?? null,\n transport,\n fetch: hasCustomAdapter ? undefined : asBag.fetch,\n webSocketFactory: hasCustomAdapter ? undefined : asBag.webSocketFactory,\n onThreadId: options.onThreadId,\n onCreated: options.onCreated,\n onCompleted: options.onCompleted,\n initialValues: options.initialValues,\n messagesKey: options.messagesKey,\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [client, assistantId, transport]\n );\n\n // Rehydrate on threadId change. The initial hydrate is fired\n // synchronously inside the controller constructor so Suspense\n // callers don't deadlock waiting for an effect that never runs\n // (throwing `hydrationPromise` during render unmounts the subtree\n // before effects fire). We only re-hydrate here when the threadId\n // prop changes after the controller was already constructed with a\n // matching id.\n const lastHydratedRef = useRef<{\n controller: StreamController<StateType, InterruptType, ConfigurableType>;\n threadId: string | null;\n } | null>(null);\n useEffect(() => {\n const target = options.threadId ?? null;\n const last = lastHydratedRef.current;\n if (last?.controller !== controller) {\n // Freshly constructed controller already seeded the hydrate in\n // its constructor — record the id and skip the redundant call.\n lastHydratedRef.current = { controller, threadId: target };\n return;\n }\n if (last.threadId === target) return;\n lastHydratedRef.current = { controller, threadId: target };\n void controller.hydrate(target);\n }, [controller, options.threadId]);\n\n // Dispose on unmount / controller swap.\n //\n // We use `controller.activate()` instead of a naive\n // `() => controller.dispose()` cleanup because React 18+\n // `<StrictMode>` in dev mounts → unmounts → remounts components\n // synchronously to surface cleanup bugs. A naive cleanup would\n // permanently tear the controller down on that first synthetic\n // unmount and turn every subsequent `submit()` into a silent\n // no-op. `activate()` defers disposal to the next microtask and\n // cancels it if the effect re-runs — which is exactly the\n // StrictMode remount pattern.\n useEffect(() => controller.activate(), [controller]);\n\n // Headless-tool handling: if the caller supplied `tools`, watch the\n // root `values.__interrupt__` channel for protocol interrupts that\n // target a registered tool, invoke the handler, and auto-resume the\n // run. Ref-tracks the ids we've already handled so the same\n // interrupt on a subsequent render is never executed twice\n // (StrictMode safe).\n const handledToolsRef = useRef<Set<string>>(new Set());\n useEffect(() => {\n handledToolsRef.current.clear();\n }, [options.threadId]);\n const tools = options.tools;\n const onTool = options.onTool;\n // Subscribe to values + interrupt updates via the root store so the\n // effect re-runs whenever a protocol interrupt lands or the\n // `__interrupt__` key is projected into values, not only on hook\n // re-render. Prefer protocol interrupts from `rootStore.interrupts`\n // (`input.requested` events) because their ids are accepted directly\n // by `Command({ resume })`; fall back to `values.__interrupt__` for\n // older streams that only expose interrupts through values.\n const rootValuesForTools = useSyncExternalStore<StateType>(\n controller.rootStore.subscribe,\n () => controller.rootStore.getSnapshot().values,\n () => controller.rootStore.getSnapshot().values\n );\n const rootInterruptsForTools = useSyncExternalStore<\n readonly Interrupt<InterruptType>[]\n >(\n controller.rootStore.subscribe,\n () => controller.rootStore.getSnapshot().interrupts,\n () => controller.rootStore.getSnapshot().interrupts\n );\n useEffect(() => {\n if (!tools?.length) return;\n const valuesBag = rootValuesForTools as unknown as Record<string, unknown>;\n const protocolInterrupts = rootInterruptsForTools as unknown as Interrupt[];\n const valuesInterrupts = Array.isArray(valuesBag?.__interrupt__)\n ? (valuesBag.__interrupt__ as Interrupt[])\n : [];\n const headlessInterrupts =\n protocolInterrupts.length > 0 ? protocolInterrupts : valuesInterrupts;\n if (headlessInterrupts.length === 0) return;\n flushPendingHeadlessToolInterrupts(\n { ...valuesBag, __interrupt__: headlessInterrupts },\n tools,\n handledToolsRef.current,\n {\n onTool,\n defer: (run) => {\n void Promise.resolve().then(run);\n },\n resumeSubmit: (command) =>\n controller.submit(null, {\n command,\n } as StreamSubmitOptions<StateType, ConfigurableType>),\n }\n );\n }, [controller, tools, onTool, rootValuesForTools, rootInterruptsForTools]);\n\n const root = useSyncExternalStore<RootSnapshot<StateType, InterruptType>>(\n controller.rootStore.subscribe,\n controller.rootStore.getSnapshot,\n controller.rootStore.getSnapshot\n );\n const subagents = useSyncExternalStore<SubagentMap>(\n controller.subagentStore.subscribe,\n controller.subagentStore.getSnapshot,\n controller.subagentStore.getSnapshot\n );\n const subgraphs = useSyncExternalStore<SubgraphMap>(\n controller.subgraphStore.subscribe,\n controller.subgraphStore.getSnapshot,\n controller.subgraphStore.getSnapshot\n );\n const subgraphsByNode = useSyncExternalStore<SubgraphByNodeMap>(\n controller.subgraphByNodeStore.subscribe,\n controller.subgraphByNodeStore.getSnapshot,\n controller.subgraphByNodeStore.getSnapshot\n );\n\n return useMemo<UseStreamReturn<T, InterruptType, ConfigurableType>>(() => {\n const userFacingInterrupts = filterOutHeadlessToolInterrupts(\n root.interrupts\n );\n return {\n values: root.values,\n messages: root.messages,\n toolCalls: root.toolCalls as InferToolCalls<T>[],\n interrupts: userFacingInterrupts,\n interrupt: userFacingInterrupts[0],\n isLoading: root.isLoading,\n isThreadLoading: root.isThreadLoading,\n hydrationPromise: controller.hydrationPromise,\n error: root.error,\n threadId: root.threadId,\n subagents: subagents as UseStreamReturn<\n T,\n InterruptType,\n ConfigurableType\n >[\"subagents\"],\n subgraphs,\n subgraphsByNode,\n submit: (input, submitOptions) => controller.submit(input, submitOptions),\n stop: (options) => controller.stop(options),\n disconnect: () => controller.disconnect(),\n respond: (response, target) => controller.respond(response, target),\n getThread: () => controller.getThread(),\n client,\n assistantId,\n [STREAM_CONTROLLER]: controller,\n } as UseStreamReturn<T, InterruptType, ConfigurableType>;\n }, [\n root,\n subagents,\n subgraphs,\n subgraphsByNode,\n controller,\n client,\n assistantId,\n ]);\n}\n\n/**\n * Convenience alias for the fully-resolved stream handle type.\n */\nexport type UseStreamResult<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n> = UseStreamReturn<T, InterruptType, ConfigurableType>;\n\n/**\n * Helper used by the selector hooks to reach the underlying\n * {@link ChannelRegistry} from a stream handle. Kept internal —\n * application code should call `useMessages`, `useToolCalls`, etc.\n * instead of reading this directly.\n *\n * @internal\n */\nexport function getRegistry(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n stream: UseStreamReturn<any, any, any>\n): ChannelRegistry {\n return stream[STREAM_CONTROLLER].registry;\n}\n\nexport type { ThreadStream };\n"],"mappings":";;;;;;;;;;;;;;;;AA2DA,MAAa,oBAAmC,OAAO,IACrD,8BACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsQD,SAAgB,UAKd,SACqD;CA0BrD,MAAM,QAAQ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AAO,KAAK;GACZ,UAAU,KAAK;GACJ;GAKX;GACA;GACA,SAAS,OAAO,kBAAkB,WAAW,OAAO,OAAO,cAAc;GACzE,OAAO,YAAY,WAAW,KAAK,QAAQ;GAC3C,kBAAkB,WAAW,YAAY;GACzC,UAAU,UAAU,WAAW,WAAW,QAAQ,UAAU,OAAO;GACnE,iBAAiB,WAAW,WAAW;GACvC;GACA;IACC,oBAAoB;GACtB;IACA;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;;;;;;;;;;AAoBJ,SAAgB,YAEd,QACiB;AACjB,QAAO,OAAO,mBAAmB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/react",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "React integration for LangGraph & LangChain",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -10,7 +10,7 @@
10
10
  "directory": "libs/sdk-react"
11
11
  },
12
12
  "dependencies": {
13
- "@langchain/langgraph-sdk": "1.9.7"
13
+ "@langchain/langgraph-sdk": "1.9.9"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@hono/node-server": "^1.19.13",