@langchain/angular 1.0.5 → 1.0.6

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.
@@ -96,20 +96,25 @@ function useStream(options, destroyRef) {
96
96
  (0, _angular_core.untracked)(() => handledTools.clear());
97
97
  });
98
98
  (0, _angular_core.effect)(() => {
99
- const snapshot = rootSignal();
100
- const bag = snapshot.values;
101
- const combined = [...Array.isArray(bag?.__interrupt__) ? bag.__interrupt__ : [], ...snapshot.interrupts];
102
- if (combined.length === 0) return;
99
+ rootSignal();
103
100
  (0, _angular_core.untracked)(() => {
104
- (0, _langchain_langgraph_sdk.flushPendingHeadlessToolInterrupts)({
105
- ...bag,
106
- __interrupt__: combined
107
- }, tools, handledTools, {
108
- onTool,
109
- defer: (run) => {
110
- Promise.resolve().then(run);
111
- },
112
- resumeSubmit: (command) => controller.submit(null, { command })
101
+ (0, _langchain_langgraph_sdk.scheduleCoalescedHeadlessToolFlush)(handledTools, () => {
102
+ const snapshot = rootSignal();
103
+ const bag = snapshot.values;
104
+ const protocolInterrupts = snapshot.interrupts;
105
+ const valuesInterrupts = Array.isArray(bag?.__interrupt__) ? bag.__interrupt__ : [];
106
+ const headlessInterrupts = protocolInterrupts.length > 0 ? protocolInterrupts : valuesInterrupts;
107
+ if (headlessInterrupts.length === 0) return;
108
+ (0, _langchain_langgraph_sdk.flushPendingHeadlessToolInterrupts)({
109
+ ...bag,
110
+ __interrupt__: headlessInterrupts
111
+ }, tools, handledTools, {
112
+ onTool,
113
+ defer: (run) => {
114
+ Promise.resolve().then(run);
115
+ },
116
+ resumeSubmit: (command) => controller.submit(null, { command })
117
+ });
113
118
  });
114
119
  });
115
120
  });
@@ -1 +1 @@
1
- {"version":3,"file":"use-stream.cjs","names":["ClientCtor","StreamController","DestroyRef"],"sources":["../src/use-stream.ts"],"sourcesContent":["import {\n DestroyRef,\n computed,\n effect,\n inject,\n isSignal,\n signal,\n untracked,\n type Signal,\n} from \"@angular/core\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport type { Client, Interrupt } from \"@langchain/langgraph-sdk\";\nimport {\n filterOutHeadlessToolInterrupts,\n flushPendingHeadlessToolInterrupts,\n type AnyHeadlessToolImplementation,\n type OnToolCallback,\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 InferToolCalls,\n type InferSubagentStates,\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\ntype AngularThreadId = string | null | Signal<string | null | undefined>;\n\nexport type AgentServerOptions<StateType extends object> =\n StreamAgentServerOptions<StateType, AngularThreadId>;\n\nexport type CustomAdapterOptions<StateType extends object> =\n StreamCustomAdapterOptions<StateType, AngularThreadId, string>;\n\nexport type UseStreamOptions<\n StateType extends object = Record<string, unknown>,\n> = StreamUseStreamOptions<\n StateType,\n AngularThreadId,\n string | undefined,\n string | undefined,\n string\n>;\n\n/**\n * Private field on the handle that carries the\n * {@link StreamController} reference. Selector primitives read this\n * to reach the shared {@link ChannelRegistry}. Use the companion\n * `inject*` selectors (`injectMessages`, `injectToolCalls`,\n * `injectValues`, …) instead of reading this directly.\n */\nexport const STREAM_CONTROLLER: unique symbol = Symbol.for(\n \"@langchain/angular/controller\"\n);\n\n/**\n * Return shape of {@link useStream} — the Angular `StreamApi`.\n *\n * Reactivity primitives follow Angular conventions:\n *\n * - Data projections are `Signal<T>`; call them as functions in\n * templates (`stream.messages()`). They are snapshots — never\n * mutate the returned arrays / maps.\n * - Imperative methods (`submit` / `stop` / `respond`) are plain\n * functions. No `WritableSignal`s are exposed on the root handle.\n * - Identity values captured at construction time (`client`,\n * `assistantId`) are exposed as plain values; remount the\n * component to swap them.\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 readonly values: Signal<StateType>;\n readonly messages: Signal<BaseMessage[]>;\n readonly toolCalls: Signal<InferToolCalls<T>[]>;\n readonly interrupts: Signal<Interrupt<InterruptType>[]>;\n readonly interrupt: Signal<Interrupt<InterruptType> | undefined>;\n readonly isLoading: Signal<boolean>;\n readonly isThreadLoading: Signal<boolean>;\n readonly error: Signal<unknown>;\n readonly threadId: Signal<string | null>;\n\n /**\n * Promise that settles when the active thread's initial hydration\n * completes. Exposed so SSR/render-before-flush pipelines can\n * `await stream.hydrationPromise` before serialising.\n */\n readonly hydrationPromise: Signal<Promise<void>>;\n\n readonly subagents: Signal<\n ReadonlyMap<\n keyof SubagentStates & string extends never\n ? string\n : keyof SubagentStates & string,\n SubagentDiscoverySnapshot\n >\n >;\n readonly subgraphs: Signal<ReadonlyMap<string, SubgraphDiscoverySnapshot>>;\n readonly subgraphsByNode: Signal<\n ReadonlyMap<string, readonly SubgraphDiscoverySnapshot[]>\n >;\n\n submit(\n input: WidenUpdateMessages<Partial<StateType>> | null | undefined,\n options?: StreamSubmitOptions<StateType, ConfigurableType>\n ): Promise<void>;\n stop(): Promise<void>;\n respond(\n response: unknown,\n target?: { interruptId: string; namespace?: string[] }\n ): Promise<void>;\n\n readonly client: Client;\n readonly assistantId: string;\n\n /** v2 escape hatch — returns the bound {@link ThreadStream}. */\n getThread(): ThreadStream | undefined;\n\n /** @internal Used by selector primitives. */\n readonly [STREAM_CONTROLLER]: StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >;\n}\n\n/**\n * Erased handle useful as a parameter type for helper components that\n * pass a `stream` through to selector primitives without reading\n * `values` directly. Mirrors the React/Vue `AnyStream` alias.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyStream = UseStreamReturn<any, any, any>;\n\n/**\n * Convenience alias — the fully-resolved return type of\n * {@link useStream} for a given source type `T`.\n */\nexport type StreamApi<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n> = UseStreamReturn<T, InterruptType, ConfigurableType>;\n\n/**\n * React-compatible alias for the fully-resolved stream handle type.\n * Angular docs prefer {@link StreamApi}, but shared libraries can use\n * this name across framework bindings.\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 * Framework-free factory that constructs a {@link StreamController}\n * and wraps its stores in Angular Signals. Callers must supply the\n * {@link DestroyRef} that owns the controller's lifetime — it's\n * already captured by the public `injectStream` helper.\n *\n * Exported for advanced callers (e.g. testing utilities, custom\n * factories) that prefer to manage injection scope themselves.\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 destroyRef?: DestroyRef\n): UseStreamReturn<T, InterruptType, ConfigurableType> {\n type StateType = InferStateType<T>;\n\n interface OptionsBag {\n assistantId?: string;\n threadId?: string | null | Signal<string | null | undefined>;\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 tools?: AnyHeadlessToolImplementation[];\n onTool?: OnToolCallback;\n }\n const asBag = options as OptionsBag;\n\n const hasCustomAdapter =\n asBag.transport != null && typeof asBag.transport !== \"string\";\n const transport = asBag.transport;\n\n const client: Client =\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 // Custom adapters may omit `assistantId`; the controller still\n // requires one so it has something to forward to `threads.stream`.\n const sentinel = \"_\";\n const assistantId =\n \"assistantId\" in options ? (options.assistantId ?? sentinel) : sentinel;\n\n // Normalize threadId input to a signal — callers may pass plain\n // values, nulls, or their own signals.\n const threadIdInput: Signal<string | null> = (() => {\n const raw = asBag.threadId;\n if (isSignal(raw)) {\n return computed(\n () => (raw as Signal<string | null | undefined>)() ?? null\n );\n }\n const initial: string | null = (raw as string | null | undefined) ?? null;\n return signal(initial) as unknown as Signal<string | null>;\n })();\n\n const controller = new StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >({\n assistantId,\n // Cast: the runtime `Client` is state-shape agnostic, but the\n // controller declares `client: Client<StateType>` for its own\n // typings. Same cast is applied in the React/Vue bindings.\n client: client as unknown as Client<StateType>,\n threadId: untracked(() => threadIdInput()),\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\n // Deferred dispose — matches the React `useEffect(() =>\n // controller.activate())` and Vue `onScopeDispose(deactivate)`\n // patterns. HMR / scope-reuse scenarios stay clean because\n // `activate()` cancels the pending dispose if the scope survives.\n const deactivate = controller.activate();\n const ref = destroyRef ?? inject(DestroyRef);\n ref.onDestroy(deactivate);\n\n // ─── Reactivity bridge: StreamStore → Signal ────────────────────────\n function bindStore<S>(\n subscribe: (listener: () => void) => () => void,\n getSnapshot: () => S\n ): Signal<S> {\n const s = signal<S>(getSnapshot());\n const unsubscribe = subscribe(() => {\n s.set(getSnapshot());\n });\n ref.onDestroy(unsubscribe);\n return computed(() => s());\n }\n\n const rootSignal = bindStore<RootSnapshot<StateType, InterruptType>>(\n controller.rootStore.subscribe,\n controller.rootStore.getSnapshot\n );\n const subagentSignal = bindStore<SubagentMap>(\n controller.subagentStore.subscribe,\n controller.subagentStore.getSnapshot\n );\n const subgraphSignal = bindStore<SubgraphMap>(\n controller.subgraphStore.subscribe,\n controller.subgraphStore.getSnapshot\n );\n const subgraphByNodeSignal = bindStore<SubgraphByNodeMap>(\n controller.subgraphByNodeStore.subscribe,\n controller.subgraphByNodeStore.getSnapshot\n );\n\n const values = computed(() => rootSignal().values);\n const messages = computed(() => rootSignal().messages);\n const toolCalls = computed(\n () => rootSignal().toolCalls as InferToolCalls<T>[]\n );\n const interrupts = computed(() =>\n filterOutHeadlessToolInterrupts(rootSignal().interrupts)\n );\n const interrupt = computed(() => interrupts()[0]);\n const isLoading = computed(() => rootSignal().isLoading);\n const isThreadLoading = computed(() => rootSignal().isThreadLoading);\n const error = computed(() => rootSignal().error);\n const threadId = computed(() => rootSignal().threadId);\n\n // `hydrationPromise` is a property on the controller that gets\n // swapped on every `hydrate()` call. Exposing it as a signal lets\n // templates `await stream.hydrationPromise()` reactively; we\n // refresh the reference when the root store settles a new promise.\n const hydrationPromise = computed(() => {\n rootSignal();\n return controller.hydrationPromise;\n });\n\n // ─── threadId reactivity ────────────────────────────────────────────\n //\n // Re-hydrate whenever the caller's threadId input changes after\n // construction. The initial hydrate already fired synchronously in\n // the controller constructor, so we compare against the snapshot\n // captured at construction time rather than blindly skipping the\n // first run — in Angular, `@Input()` bindings apply *between*\n // construction and the first effect tick, so the first read can\n // legitimately be a different (updated) value that needs to\n // hydrate.\n const initialThreadId = untracked(() => threadIdInput()) ?? null;\n let lastAppliedThreadId: string | null = initialThreadId;\n effect(() => {\n const next = threadIdInput() ?? null;\n if (next === lastAppliedThreadId) return;\n lastAppliedThreadId = next;\n untracked(() => {\n void controller.hydrate(next);\n });\n });\n\n // ─── Headless-tool handling ─────────────────────────────────────────\n const tools = options.tools;\n const onTool = options.onTool;\n if (tools?.length) {\n const handledTools = new Set<string>();\n\n // Clear the dedup set whenever the thread id changes.\n effect(() => {\n threadIdInput();\n untracked(() => handledTools.clear());\n });\n\n effect(() => {\n const snapshot = rootSignal();\n const bag = snapshot.values as unknown as Record<string, unknown>;\n const existing = Array.isArray(bag?.__interrupt__)\n ? (bag.__interrupt__ as Interrupt[])\n : [];\n const combined: Interrupt[] = [\n ...existing,\n ...(snapshot.interrupts as unknown as Interrupt[]),\n ];\n if (combined.length === 0) return;\n untracked(() => {\n flushPendingHeadlessToolInterrupts(\n { ...bag, __interrupt__: combined },\n tools,\n handledTools,\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 });\n });\n }\n\n const handle: UseStreamReturn<T, InterruptType, ConfigurableType> = {\n values: values as UseStreamReturn<\n T,\n InterruptType,\n ConfigurableType\n >[\"values\"],\n messages,\n toolCalls,\n interrupts,\n interrupt,\n isLoading,\n isThreadLoading,\n error,\n threadId,\n hydrationPromise,\n subagents: subagentSignal as UseStreamReturn<\n T,\n InterruptType,\n ConfigurableType\n >[\"subagents\"],\n subgraphs: subgraphSignal,\n subgraphsByNode: subgraphByNodeSignal,\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 };\n\n return handle;\n}\n\n/**\n * Helper used by the selector primitives to reach the underlying\n * {@link ChannelRegistry} from a stream handle. Kept internal —\n * application code should call `injectMessages`, `injectToolCalls`,\n * etc. 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":";;;;;;;;;;;;AAsEA,MAAa,oBAAmC,OAAO,IACrD,gCACD;;;;;;;;;;AAmHD,SAAgB,UAKd,SACA,YACqD;CAsBrD,MAAM,QAAQ;CAEd,MAAM,mBACJ,MAAM,aAAa,QAAQ,OAAO,MAAM,cAAc;CACxD,MAAM,YAAY,MAAM;CAExB,MAAM,SACJ,MAAM,UACL,IAAIA,gCAAAA,OAAW;EACd,QAAQ,MAAM;EACd,QAAQ,MAAM;EACd,eAAe,MAAM;EACrB,gBAAgB,MAAM;EACvB,CAAC;CAIJ,MAAM,WAAW;CACjB,MAAM,cACJ,iBAAiB,UAAW,QAAQ,eAAe,WAAY;CAIjE,MAAM,uBAA8C;EAClD,MAAM,MAAM,MAAM;AAClB,OAAA,GAAA,cAAA,UAAa,IAAI,CACf,SAAA,GAAA,cAAA,gBACS,KAA2C,IAAI,KACvD;AAGH,UAAA,GAAA,cAAA,QADgC,OAAqC,KAC/C;KACpB;CAEJ,MAAM,aAAa,IAAIC,gCAAAA,iBAIrB;EACA;EAIQ;EACR,WAAA,GAAA,cAAA,iBAA0B,eAAe,CAAC;EAC1C;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;CAMF,MAAM,aAAa,WAAW,UAAU;CACxC,MAAM,MAAM,eAAA,GAAA,cAAA,QAAqBC,cAAAA,WAAW;AAC5C,KAAI,UAAU,WAAW;CAGzB,SAAS,UACP,WACA,aACW;EACX,MAAM,KAAA,GAAA,cAAA,QAAc,aAAa,CAAC;EAClC,MAAM,cAAc,gBAAg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MAAM,SAAS,QAAQ;AACvB,KAAI,OAAO,QAAQ;EACjB,MAAM,+BAAe,IAAI,KAAa;AAGtC,GAAA,GAAA,cAAA,cAAa;AACX,kBAAe;AACf,IAAA,GAAA,cAAA,iBAAgB,aAAa,OAAO,CAAC;IACrC;AAEF,GAAA,GAAA,cAAA,cAAa;GACX,MAAM,WAAW,YAAY;GAC7B,MAAM,MAAM,SAAS;GAIrB,MAAM,WAAwB,CAC5B,GAJe,MAAM,QAAQ,KAAK,cAAc,GAC7C,IAAI,gBACL,EAAE,EAGJ,GAAI,SAAS,WACd;AACD,OAAI,SAAS,WAAW,EAAG;AAC3B,IAAA,GAAA,cAAA,iBAAgB;AACd,KAAA,GAAA,yBAAA,oCACE;KAAE,GAAG;KAAK,eAAe;KAAU,EACnC,OACA,cACA;KACE;KACA,QAAQ,QAAQ;AACT,cAAQ,SAAS,CAAC,KAAK,IAAI;;KAElC,eAAe,YACb,WAAW,OAAO,MAAM,EACtB,SACD,CAAqD;KACzD,CACF;KACD;IACF;;AAkCJ,QA/BoE;EAC1D;EAKR;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,WAAW;EAKX,WAAW;EACX,iBAAiB;EACjB,SAAS,OAAO,kBAAkB,WAAW,OAAO,OAAO,cAAc;EACzE,YAAY,WAAW,MAAM;EAC7B,UAAU,UAAU,WAAW,WAAW,QAAQ,UAAU,OAAO;EACnE,iBAAiB,WAAW,WAAW;EACvC;EACA;GACC,oBAAoB;EACtB;;;;;;;;;;AAaH,SAAgB,YAEd,QACiB;AACjB,QAAO,OAAO,mBAAmB"}
1
+ {"version":3,"file":"use-stream.cjs","names":["ClientCtor","StreamController","DestroyRef"],"sources":["../src/use-stream.ts"],"sourcesContent":["import {\n DestroyRef,\n computed,\n effect,\n inject,\n isSignal,\n signal,\n untracked,\n type Signal,\n} from \"@angular/core\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport type { Client, Interrupt } from \"@langchain/langgraph-sdk\";\nimport {\n filterOutHeadlessToolInterrupts,\n flushPendingHeadlessToolInterrupts,\n scheduleCoalescedHeadlessToolFlush,\n type AnyHeadlessToolImplementation,\n type OnToolCallback,\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 InferToolCalls,\n type InferSubagentStates,\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\ntype AngularThreadId = string | null | Signal<string | null | undefined>;\n\nexport type AgentServerOptions<StateType extends object> =\n StreamAgentServerOptions<StateType, AngularThreadId>;\n\nexport type CustomAdapterOptions<StateType extends object> =\n StreamCustomAdapterOptions<StateType, AngularThreadId, string>;\n\nexport type UseStreamOptions<\n StateType extends object = Record<string, unknown>,\n> = StreamUseStreamOptions<\n StateType,\n AngularThreadId,\n string | undefined,\n string | undefined,\n string\n>;\n\n/**\n * Private field on the handle that carries the\n * {@link StreamController} reference. Selector primitives read this\n * to reach the shared {@link ChannelRegistry}. Use the companion\n * `inject*` selectors (`injectMessages`, `injectToolCalls`,\n * `injectValues`, …) instead of reading this directly.\n */\nexport const STREAM_CONTROLLER: unique symbol = Symbol.for(\n \"@langchain/angular/controller\"\n);\n\n/**\n * Return shape of {@link useStream} — the Angular `StreamApi`.\n *\n * Reactivity primitives follow Angular conventions:\n *\n * - Data projections are `Signal<T>`; call them as functions in\n * templates (`stream.messages()`). They are snapshots — never\n * mutate the returned arrays / maps.\n * - Imperative methods (`submit` / `stop` / `respond`) are plain\n * functions. No `WritableSignal`s are exposed on the root handle.\n * - Identity values captured at construction time (`client`,\n * `assistantId`) are exposed as plain values; remount the\n * component to swap them.\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 `stream.values().messages`\n * directly you'll see full turns appear at once instead of\n * streaming token-by-token. Use {@link messages} (or\n * `injectMessages`) for the token-streamed view.\n *\n * Equivalent to calling `injectValues(stream)`.\n */\n readonly values: Signal<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 Angular layer faithfully renders whatever the\n * server sends.\n *\n * Equivalent to calling `injectMessages(stream)` with no target.\n */\n readonly messages: Signal<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 `injectToolCalls(stream)` with no target.\n */\n readonly toolCalls: Signal<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: Signal<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: Signal<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: Signal<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: Signal<boolean>;\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: Signal<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: Signal<string | null>;\n /**\n * Promise that settles when the active thread's initial hydration\n * completes. Exposed so SSR/render-before-flush pipelines can\n * `await stream.hydrationPromise()` before serialising. A fresh\n * promise is installed on every `threadId` change.\n */\n readonly hydrationPromise: Signal<Promise<void>>;\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: Signal<\n ReadonlyMap<\n keyof SubagentStates & string extends never\n ? string\n : keyof SubagentStates & string,\n SubagentDiscoverySnapshot\n >\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: Signal<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: Signal<\n ReadonlyMap<string, 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 primitive. Pass\n * `null` (or omit fields) when resuming an interrupt via\n * `options.command.resume` — the server accepts a null payload\n * 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 primitives 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 primitives. */\n readonly [STREAM_CONTROLLER]: StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >;\n}\n\n/**\n * Erased handle useful as a parameter type for helper components that\n * pass a `stream` through to selector primitives without reading\n * `values` directly. Mirrors the React/Vue `AnyStream` alias.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyStream = UseStreamReturn<any, any, any>;\n\n/**\n * Convenience alias — the fully-resolved return type of\n * {@link useStream} for a given source type `T`.\n */\nexport type StreamApi<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n> = UseStreamReturn<T, InterruptType, ConfigurableType>;\n\n/**\n * React-compatible alias for the fully-resolved stream handle type.\n * Angular docs prefer {@link StreamApi}, but shared libraries can use\n * this name across framework bindings.\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 * Framework-free factory that constructs a {@link StreamController}\n * and wraps its stores in Angular Signals. Callers must supply the\n * {@link DestroyRef} that owns the controller's lifetime — it's\n * already captured by the public `injectStream` helper.\n *\n * Exported for advanced callers (e.g. testing utilities, custom\n * factories) that prefer to manage injection scope themselves.\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 destroyRef?: DestroyRef\n): UseStreamReturn<T, InterruptType, ConfigurableType> {\n type StateType = InferStateType<T>;\n\n interface OptionsBag {\n assistantId?: string;\n threadId?: string | null | Signal<string | null | undefined>;\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 tools?: AnyHeadlessToolImplementation[];\n onTool?: OnToolCallback;\n }\n const asBag = options as OptionsBag;\n\n const hasCustomAdapter =\n asBag.transport != null && typeof asBag.transport !== \"string\";\n const transport = asBag.transport;\n\n const client: Client =\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 // Custom adapters may omit `assistantId`; the controller still\n // requires one so it has something to forward to `threads.stream`.\n const sentinel = \"_\";\n const assistantId =\n \"assistantId\" in options ? (options.assistantId ?? sentinel) : sentinel;\n\n // Normalize threadId input to a signal — callers may pass plain\n // values, nulls, or their own signals.\n const threadIdInput: Signal<string | null> = (() => {\n const raw = asBag.threadId;\n if (isSignal(raw)) {\n return computed(\n () => (raw as Signal<string | null | undefined>)() ?? null\n );\n }\n const initial: string | null = (raw as string | null | undefined) ?? null;\n return signal(initial) as unknown as Signal<string | null>;\n })();\n\n const controller = new StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >({\n assistantId,\n // Cast: the runtime `Client` is state-shape agnostic, but the\n // controller declares `client: Client<StateType>` for its own\n // typings. Same cast is applied in the React/Vue bindings.\n client: client as unknown as Client<StateType>,\n threadId: untracked(() => threadIdInput()),\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\n // Deferred dispose — matches the React `useEffect(() =>\n // controller.activate())` and Vue `onScopeDispose(deactivate)`\n // patterns. HMR / scope-reuse scenarios stay clean because\n // `activate()` cancels the pending dispose if the scope survives.\n const deactivate = controller.activate();\n const ref = destroyRef ?? inject(DestroyRef);\n ref.onDestroy(deactivate);\n\n // ─── Reactivity bridge: StreamStore → Signal ────────────────────────\n function bindStore<S>(\n subscribe: (listener: () => void) => () => void,\n getSnapshot: () => S\n ): Signal<S> {\n const s = signal<S>(getSnapshot());\n const unsubscribe = subscribe(() => {\n s.set(getSnapshot());\n });\n ref.onDestroy(unsubscribe);\n return computed(() => s());\n }\n\n const rootSignal = bindStore<RootSnapshot<StateType, InterruptType>>(\n controller.rootStore.subscribe,\n controller.rootStore.getSnapshot\n );\n const subagentSignal = bindStore<SubagentMap>(\n controller.subagentStore.subscribe,\n controller.subagentStore.getSnapshot\n );\n const subgraphSignal = bindStore<SubgraphMap>(\n controller.subgraphStore.subscribe,\n controller.subgraphStore.getSnapshot\n );\n const subgraphByNodeSignal = bindStore<SubgraphByNodeMap>(\n controller.subgraphByNodeStore.subscribe,\n controller.subgraphByNodeStore.getSnapshot\n );\n\n const values = computed(() => rootSignal().values);\n const messages = computed(() => rootSignal().messages);\n const toolCalls = computed(\n () => rootSignal().toolCalls as InferToolCalls<T>[]\n );\n const interrupts = computed(() =>\n filterOutHeadlessToolInterrupts(rootSignal().interrupts)\n );\n const interrupt = computed(() => interrupts()[0]);\n const isLoading = computed(() => rootSignal().isLoading);\n const isThreadLoading = computed(() => rootSignal().isThreadLoading);\n const error = computed(() => rootSignal().error);\n const threadId = computed(() => rootSignal().threadId);\n\n // `hydrationPromise` is a property on the controller that gets\n // swapped on every `hydrate()` call. Exposing it as a signal lets\n // templates `await stream.hydrationPromise()` reactively; we\n // refresh the reference when the root store settles a new promise.\n const hydrationPromise = computed(() => {\n rootSignal();\n return controller.hydrationPromise;\n });\n\n // ─── threadId reactivity ────────────────────────────────────────────\n //\n // Re-hydrate whenever the caller's threadId input changes after\n // construction. The initial hydrate already fired synchronously in\n // the controller constructor, so we compare against the snapshot\n // captured at construction time rather than blindly skipping the\n // first run — in Angular, `@Input()` bindings apply *between*\n // construction and the first effect tick, so the first read can\n // legitimately be a different (updated) value that needs to\n // hydrate.\n const initialThreadId = untracked(() => threadIdInput()) ?? null;\n let lastAppliedThreadId: string | null = initialThreadId;\n effect(() => {\n const next = threadIdInput() ?? null;\n if (next === lastAppliedThreadId) return;\n lastAppliedThreadId = next;\n untracked(() => {\n void controller.hydrate(next);\n });\n });\n\n // ─── Headless-tool handling ─────────────────────────────────────────\n const tools = options.tools;\n const onTool = options.onTool;\n if (tools?.length) {\n const handledTools = new Set<string>();\n\n // Clear the dedup set whenever the thread id changes.\n effect(() => {\n threadIdInput();\n untracked(() => handledTools.clear());\n });\n\n effect(() => {\n rootSignal();\n untracked(() => {\n scheduleCoalescedHeadlessToolFlush(handledTools, () => {\n const snapshot = rootSignal();\n const bag = snapshot.values as unknown as Record<string, unknown>;\n const protocolInterrupts =\n snapshot.interrupts as unknown as Interrupt[];\n const valuesInterrupts = Array.isArray(bag?.__interrupt__)\n ? (bag.__interrupt__ as Interrupt[])\n : [];\n const headlessInterrupts =\n protocolInterrupts.length > 0\n ? protocolInterrupts\n : valuesInterrupts;\n if (headlessInterrupts.length === 0) return;\n flushPendingHeadlessToolInterrupts(\n { ...bag, __interrupt__: headlessInterrupts },\n tools,\n handledTools,\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 });\n });\n });\n }\n\n const handle: UseStreamReturn<T, InterruptType, ConfigurableType> = {\n values: values as UseStreamReturn<\n T,\n InterruptType,\n ConfigurableType\n >[\"values\"],\n messages,\n toolCalls,\n interrupts,\n interrupt,\n isLoading,\n isThreadLoading,\n error,\n threadId,\n hydrationPromise,\n subagents: subagentSignal as UseStreamReturn<\n T,\n InterruptType,\n ConfigurableType\n >[\"subagents\"],\n subgraphs: subgraphSignal,\n subgraphsByNode: subgraphByNodeSignal,\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 };\n\n return handle;\n}\n\n/**\n * Helper used by the selector primitives to reach the underlying\n * {@link ChannelRegistry} from a stream handle. Kept internal —\n * application code should call `injectMessages`, `injectToolCalls`,\n * etc. 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":";;;;;;;;;;;;AAuEA,MAAa,oBAAmC,OAAO,IACrD,gCACD;;;;;;;;;;AAuPD,SAAgB,UAKd,SACA,YACqD;CAsBrD,MAAM,QAAQ;CAEd,MAAM,mBACJ,MAAM,aAAa,QAAQ,OAAO,MAAM,cAAc;CACxD,MAAM,YAAY,MAAM;CAExB,MAAM,SACJ,MAAM,UACL,IAAIA,gCAAAA,OAAW;EACd,QAAQ,MAAM;EACd,QAAQ,MAAM;EACd,eAAe,MAAM;EACrB,gBAAgB,MAAM;EACvB,CAAC;CAIJ,MAAM,WAAW;CACjB,MAAM,cACJ,iBAAiB,UAAW,QAAQ,eAAe,WAAY;CAIjE,MAAM,uBAA8C;EAClD,MAAM,MAAM,MAAM;AAClB,OAAA,GAAA,cAAA,UAAa,IAAI,CACf,SAAA,GAAA,cAAA,gBACS,KAA2C,IAAI,KACvD;AAGH,UAAA,GAAA,cAAA,QADgC,OAAqC,KAC/C;KACpB;CAEJ,MAAM,aAAa,IAAIC,gCAAAA,iBAIrB;EACA;EAIQ;EACR,WAAA,GAAA,cAAA,iBAA0B,eAAe,CAAC;EAC1C;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;CAMF,MAAM,aAAa,WAAW,UAAU;CACxC,MAAM,MAAM,eAAA,GAAA,cAAA,QAAqBC,cAAAA,WA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AM_CONTROLLER: unique symbol;
32
32
  * component to swap them.
33
33
  */
34
34
  interface UseStreamReturn<T = Record<string, unknown>, InterruptType = unknown, ConfigurableType extends object = Record<string, unknown>, StateType extends object = InferStateType<T>, SubagentStates = InferSubagentStates<T>> {
35
+ /**
36
+ * The most recent `values`-channel snapshot emitted at the root
37
+ * namespace — i.e. the thread-level state as the server sees it
38
+ * after each superstep. Updated on every root `values` event, not
39
+ * on token-level deltas: if you render `stream.values().messages`
40
+ * directly you'll see full turns appear at once instead of
41
+ * streaming token-by-token. Use {@link messages} (or
42
+ * `injectMessages`) for the token-streamed view.
43
+ *
44
+ * Equivalent to calling `injectValues(stream)`.
45
+ */
35
46
  readonly values: Signal<StateType>;
47
+ /**
48
+ * The root message projection. Assembled from two sources and
49
+ * merged in real time:
50
+ *
51
+ * 1. `messages`-channel deltas — token-level streaming events
52
+ * (`message-start`, `content-block-delta`, `message-finish`)
53
+ * emitted by the runtime. These drive live, token-by-token
54
+ * updates.
55
+ * 2. `values.messages` snapshots — the authoritative ordering
56
+ * and any messages the agent produces without token streaming
57
+ * (human turns, tool results, echoes from subagents).
58
+ *
59
+ * If the backend only emits `values` events (no `messages`
60
+ * channel), every message will appear fully-formed on each
61
+ * values update rather than streaming. This is a backend/runtime
62
+ * concern — the Angular layer faithfully renders whatever the
63
+ * server sends.
64
+ *
65
+ * Equivalent to calling `injectMessages(stream)` with no target.
66
+ */
36
67
  readonly messages: Signal<BaseMessage[]>;
68
+ /**
69
+ * Root-namespace tool calls assembled from the `tools` channel.
70
+ * Each entry is a fully parsed {@link AssembledToolCall} with
71
+ * name, args, and id — suitable for rendering approval UIs or
72
+ * forwarding to headless tool handlers.
73
+ *
74
+ * When the stream is typed with an agent brand or tool list,
75
+ * entries are narrowed via {@link InferToolCalls}. Equivalent to
76
+ * calling `injectToolCalls(stream)` with no target.
77
+ */
37
78
  readonly toolCalls: Signal<InferToolCalls<T>[]>;
79
+ /**
80
+ * All unresolved protocol interrupts observed on the root
81
+ * namespace during the active thread. Populated from lifecycle /
82
+ * input events and seeded on hydration from `thread.getState()`.
83
+ * Cleared optimistically when a new run starts or an interrupt is
84
+ * resolved via {@link respond} / `submit({ command: { resume } })`.
85
+ */
38
86
  readonly interrupts: Signal<Interrupt<InterruptType>[]>;
87
+ /**
88
+ * Convenience alias for {@link interrupts}[0] — the primary
89
+ * interrupt most UIs should act on when only one is pending.
90
+ * `undefined` when no interrupt is active.
91
+ */
39
92
  readonly interrupt: Signal<Interrupt<InterruptType> | undefined>;
93
+ /**
94
+ * `true` while a run is active or being started on the current
95
+ * thread. Driven by root-namespace lifecycle events (`running` →
96
+ * `true`, terminal phases → `false`). Use this to disable submit
97
+ * buttons and show in-flight spinners.
98
+ */
40
99
  readonly isLoading: Signal<boolean>;
100
+ /**
101
+ * `true` while the initial `thread.getState()` hydration for the
102
+ * active thread is in flight. Distinct from {@link isLoading} —
103
+ * thread loading covers the one-time fetch that seeds
104
+ * {@link values} / {@link messages} before any user submit.
105
+ */
41
106
  readonly isThreadLoading: Signal<boolean>;
107
+ /**
108
+ * The last error observed on the active run or hydration attempt.
109
+ * `undefined` when no error has occurred. Cleared optimistically
110
+ * when a new {@link submit} starts.
111
+ */
42
112
  readonly error: Signal<unknown>;
113
+ /**
114
+ * Id of the thread the controller is bound to. `null` until the
115
+ * first {@link submit} creates or selects a thread (or until an
116
+ * explicit `threadId` option is provided and hydrated).
117
+ */
43
118
  readonly threadId: Signal<string | null>;
44
119
  /**
45
120
  * Promise that settles when the active thread's initial hydration
46
121
  * completes. Exposed so SSR/render-before-flush pipelines can
47
- * `await stream.hydrationPromise` before serialising.
122
+ * `await stream.hydrationPromise()` before serialising. A fresh
123
+ * promise is installed on every `threadId` change.
48
124
  */
49
125
  readonly hydrationPromise: Signal<Promise<void>>;
126
+ /**
127
+ * Subagents discovered on the root run. For DeepAgent-typed
128
+ * streams the key set is narrowed to the subagent names declared
129
+ * on the agent brand (`keyof InferSubagentStates<T>`).
130
+ */
50
131
  readonly subagents: Signal<ReadonlyMap<keyof SubagentStates & string extends never ? string : keyof SubagentStates & string, SubagentDiscoverySnapshot>>;
132
+ /**
133
+ * Subgraphs discovered on the root run.
134
+ *
135
+ * A namespace is classified as a subgraph iff at least one
136
+ * strictly-deeper namespace has been observed with it as a prefix.
137
+ * This is inferred from the lifecycle event stream — plain function
138
+ * nodes (`orchestrator`, `writer` in the nested-stategraph example)
139
+ * never appear here even though the server emits namespaced
140
+ * lifecycle events for them. Promotion is monotonic and retroactive;
141
+ * an entry appears as soon as the first descendant event lands.
142
+ */
51
143
  readonly subgraphs: Signal<ReadonlyMap<string, SubgraphDiscoverySnapshot>>;
144
+ /**
145
+ * Subgraphs indexed by the graph node that produced them
146
+ * (`addNode("visualizer_0", …)`). Each value is an array because
147
+ * parallel fan-outs and loops can spawn multiple invocations of
148
+ * the same node; arrays preserve insertion order. Updates in
149
+ * lock-step with {@link subgraphs}.
150
+ */
52
151
  readonly subgraphsByNode: Signal<ReadonlyMap<string, readonly SubgraphDiscoverySnapshot[]>>;
152
+ /**
153
+ * Dispatch a new run on the bound thread.
154
+ *
155
+ * `input` is typed as `Partial<StateType>` so IDE autocompletion
156
+ * surfaces the state keys declared on the root primitive. Pass
157
+ * `null` (or omit fields) when resuming an interrupt via
158
+ * `options.command.resume` — the server accepts a null payload
159
+ * in that case.
160
+ */
53
161
  submit(input: WidenUpdateMessages<Partial<StateType>> | null | undefined, options?: StreamSubmitOptions<StateType, ConfigurableType>): Promise<void>;
162
+ /**
163
+ * Abort the in-flight run on the current thread without clearing
164
+ * accumulated state. Sets {@link isLoading} to `false` immediately;
165
+ * {@link values} and {@link messages} are preserved.
166
+ */
54
167
  stop(): Promise<void>;
168
+ /**
169
+ * Resume a pending protocol interrupt by sending a response payload
170
+ * back to the interrupted namespace.
171
+ *
172
+ * When `target` is omitted, responds to the latest unresolved
173
+ * interrupt in {@link interrupts}. Pass an explicit
174
+ * `{ interruptId, namespace? }` when multiple interrupts are
175
+ * pending or the interrupt lives in a subgraph namespace.
176
+ */
55
177
  respond(response: unknown, target?: {
56
178
  interruptId: string;
57
179
  namespace?: string[];
58
180
  }): Promise<void>;
181
+ /** LangGraph SDK client used to construct thread streams. */
59
182
  readonly client: Client;
183
+ /** Assistant id the thread is bound to for its lifetime. */
60
184
  readonly assistantId: string;
61
- /** v2 escape hatch — returns the bound {@link ThreadStream}. */
185
+ /**
186
+ * Returns the bound {@link ThreadStream}, if one exists (`undefined`
187
+ * until the thread is hydrated or the first submit completes). Prefer
188
+ * the projections and selector primitives for UI work; use this for
189
+ * low-level protocol access (raw subscriptions, state commands, etc.).
190
+ */
62
191
  getThread(): ThreadStream$1 | undefined;
63
192
  /** @internal Used by selector primitives. */
64
193
  readonly [STREAM_CONTROLLER]: StreamController<StateType, InterruptType, ConfigurableType>;
@@ -1 +1 @@
1
- {"version":3,"file":"use-stream.d.cts","names":[],"sources":["../src/use-stream.ts"],"mappings":";;;;;;;KA6CK,eAAA,mBAAkC,MAAA;AAAA,KAE3B,oBAAA,6BACV,kBAAA,CAAyB,SAAA,EAAW,eAAA;AAAA,KAE1B,sBAAA,6BACV,oBAAA,CAA2B,SAAA,EAAW,eAAA;AAAA,KAE5B,kBAAA,4BACiB,MAAA,qBACzB,gBAAA,CACF,SAAA,EACA,eAAA;;;;AAVF;;;;cAuBa,iBAAA;;;;;;;;;;AApBb;;;;;UAsCiB,eAAA,KACX,MAAA,8EAE8B,MAAA,8CACP,cAAA,CAAe,CAAA,oBACzB,mBAAA,CAAoB,CAAA;EAAA,SAE5B,MAAA,EAAQ,MAAA,CAAO,SAAA;EAAA,SACf,QAAA,EAAU,MAAA,CAAO,WAAA;EAAA,SACjB,SAAA,EAAW,MAAA,CAAO,cAAA,CAAe,CAAA;EAAA,SACjC,UAAA,EAAY,MAAA,CAAO,SAAA,CAAU,aAAA;EAAA,SAC7B,SAAA,EAAW,MAAA,CAAO,SAAA,CAAU,aAAA;EAAA,SAC5B,SAAA,EAAW,MAAA;EAAA,SACX,eAAA,EAAiB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AAA,CAAQ,SAAA,uBACnC,OAAA,GAAU,mBAAA,CAAoB,SAAA,EAAW,gBAAA,IACxC,OAAA;EA5CiB;;;;;EAkDpB,IAAA,IAAQ,OAAA;EA/BY;;;;;;;;;EAyCpB,OAAA,CACE,QAAA,WACA,MAAA;IAAW,WAAA;IAAqB,SAAA;EAAA,IAC/B,OAAA;EApB6B;EAAA,SAwBvB,MAAA,EAAQ,MAAA;EAxBf;EAAA,SA0BO,WAAA;EAnBT;;;;;;EA2BA,SAAA,IAAa,cAAA;EAdV;EAAA,UAiBO,iBAAA,GAAoB,gBAAA,CAC5B,SAAA,EACA,aAAA,EACA,gBAAA;AAAA;;;;;;KAUQ,SAAA,GAAY,eAAA;;;;;KAMZ,SAAA,KACN,MAAA,8EAE8B,MAAA,qBAChC,eAAA,CAAgB,CAAA,EAAG,aAAA,EAAe,gBAAA;;;;;AAJtC;KAWY,eAAA,KACN,MAAA,8EAE8B,MAAA,qBAChC,eAAA,CAAgB,CAAA,EAAG,aAAA,EAAe,gBAAA;;;;;;;;;;iBAWtB,SAAA,KACV,MAAA,8EAE8B,MAAA,kBAAA,CAElC,OAAA,EAAS,kBAAA,CAAiB,cAAA,CAAe,CAAA,IACzC,UAAA,GAAa,UAAA,GACZ,eAAA,CAAgB,CAAA,EAAG,aAAA,EAAe,gBAAA"}
@@ -32,33 +32,162 @@ declare const STREAM_CONTROLLER: unique symbol;
32
32
  * component to swap them.
33
33
  */
34
34
  interface UseStreamReturn<T = Record<string, unknown>, InterruptType = unknown, ConfigurableType extends object = Record<string, unknown>, StateType extends object = InferStateType<T>, SubagentStates = InferSubagentStates<T>> {
35
+ /**
36
+ * The most recent `values`-channel snapshot emitted at the root
37
+ * namespace — i.e. the thread-level state as the server sees it
38
+ * after each superstep. Updated on every root `values` event, not
39
+ * on token-level deltas: if you render `stream.values().messages`
40
+ * directly you'll see full turns appear at once instead of
41
+ * streaming token-by-token. Use {@link messages} (or
42
+ * `injectMessages`) for the token-streamed view.
43
+ *
44
+ * Equivalent to calling `injectValues(stream)`.
45
+ */
35
46
  readonly values: Signal<StateType>;
47
+ /**
48
+ * The root message projection. Assembled from two sources and
49
+ * merged in real time:
50
+ *
51
+ * 1. `messages`-channel deltas — token-level streaming events
52
+ * (`message-start`, `content-block-delta`, `message-finish`)
53
+ * emitted by the runtime. These drive live, token-by-token
54
+ * updates.
55
+ * 2. `values.messages` snapshots — the authoritative ordering
56
+ * and any messages the agent produces without token streaming
57
+ * (human turns, tool results, echoes from subagents).
58
+ *
59
+ * If the backend only emits `values` events (no `messages`
60
+ * channel), every message will appear fully-formed on each
61
+ * values update rather than streaming. This is a backend/runtime
62
+ * concern — the Angular layer faithfully renders whatever the
63
+ * server sends.
64
+ *
65
+ * Equivalent to calling `injectMessages(stream)` with no target.
66
+ */
36
67
  readonly messages: Signal<BaseMessage[]>;
68
+ /**
69
+ * Root-namespace tool calls assembled from the `tools` channel.
70
+ * Each entry is a fully parsed {@link AssembledToolCall} with
71
+ * name, args, and id — suitable for rendering approval UIs or
72
+ * forwarding to headless tool handlers.
73
+ *
74
+ * When the stream is typed with an agent brand or tool list,
75
+ * entries are narrowed via {@link InferToolCalls}. Equivalent to
76
+ * calling `injectToolCalls(stream)` with no target.
77
+ */
37
78
  readonly toolCalls: Signal<InferToolCalls<T>[]>;
79
+ /**
80
+ * All unresolved protocol interrupts observed on the root
81
+ * namespace during the active thread. Populated from lifecycle /
82
+ * input events and seeded on hydration from `thread.getState()`.
83
+ * Cleared optimistically when a new run starts or an interrupt is
84
+ * resolved via {@link respond} / `submit({ command: { resume } })`.
85
+ */
38
86
  readonly interrupts: Signal<Interrupt<InterruptType>[]>;
87
+ /**
88
+ * Convenience alias for {@link interrupts}[0] — the primary
89
+ * interrupt most UIs should act on when only one is pending.
90
+ * `undefined` when no interrupt is active.
91
+ */
39
92
  readonly interrupt: Signal<Interrupt<InterruptType> | undefined>;
93
+ /**
94
+ * `true` while a run is active or being started on the current
95
+ * thread. Driven by root-namespace lifecycle events (`running` →
96
+ * `true`, terminal phases → `false`). Use this to disable submit
97
+ * buttons and show in-flight spinners.
98
+ */
40
99
  readonly isLoading: Signal<boolean>;
100
+ /**
101
+ * `true` while the initial `thread.getState()` hydration for the
102
+ * active thread is in flight. Distinct from {@link isLoading} —
103
+ * thread loading covers the one-time fetch that seeds
104
+ * {@link values} / {@link messages} before any user submit.
105
+ */
41
106
  readonly isThreadLoading: Signal<boolean>;
107
+ /**
108
+ * The last error observed on the active run or hydration attempt.
109
+ * `undefined` when no error has occurred. Cleared optimistically
110
+ * when a new {@link submit} starts.
111
+ */
42
112
  readonly error: Signal<unknown>;
113
+ /**
114
+ * Id of the thread the controller is bound to. `null` until the
115
+ * first {@link submit} creates or selects a thread (or until an
116
+ * explicit `threadId` option is provided and hydrated).
117
+ */
43
118
  readonly threadId: Signal<string | null>;
44
119
  /**
45
120
  * Promise that settles when the active thread's initial hydration
46
121
  * completes. Exposed so SSR/render-before-flush pipelines can
47
- * `await stream.hydrationPromise` before serialising.
122
+ * `await stream.hydrationPromise()` before serialising. A fresh
123
+ * promise is installed on every `threadId` change.
48
124
  */
49
125
  readonly hydrationPromise: Signal<Promise<void>>;
126
+ /**
127
+ * Subagents discovered on the root run. For DeepAgent-typed
128
+ * streams the key set is narrowed to the subagent names declared
129
+ * on the agent brand (`keyof InferSubagentStates<T>`).
130
+ */
50
131
  readonly subagents: Signal<ReadonlyMap<keyof SubagentStates & string extends never ? string : keyof SubagentStates & string, SubagentDiscoverySnapshot>>;
132
+ /**
133
+ * Subgraphs discovered on the root run.
134
+ *
135
+ * A namespace is classified as a subgraph iff at least one
136
+ * strictly-deeper namespace has been observed with it as a prefix.
137
+ * This is inferred from the lifecycle event stream — plain function
138
+ * nodes (`orchestrator`, `writer` in the nested-stategraph example)
139
+ * never appear here even though the server emits namespaced
140
+ * lifecycle events for them. Promotion is monotonic and retroactive;
141
+ * an entry appears as soon as the first descendant event lands.
142
+ */
51
143
  readonly subgraphs: Signal<ReadonlyMap<string, SubgraphDiscoverySnapshot>>;
144
+ /**
145
+ * Subgraphs indexed by the graph node that produced them
146
+ * (`addNode("visualizer_0", …)`). Each value is an array because
147
+ * parallel fan-outs and loops can spawn multiple invocations of
148
+ * the same node; arrays preserve insertion order. Updates in
149
+ * lock-step with {@link subgraphs}.
150
+ */
52
151
  readonly subgraphsByNode: Signal<ReadonlyMap<string, readonly SubgraphDiscoverySnapshot[]>>;
152
+ /**
153
+ * Dispatch a new run on the bound thread.
154
+ *
155
+ * `input` is typed as `Partial<StateType>` so IDE autocompletion
156
+ * surfaces the state keys declared on the root primitive. Pass
157
+ * `null` (or omit fields) when resuming an interrupt via
158
+ * `options.command.resume` — the server accepts a null payload
159
+ * in that case.
160
+ */
53
161
  submit(input: WidenUpdateMessages<Partial<StateType>> | null | undefined, options?: StreamSubmitOptions<StateType, ConfigurableType>): Promise<void>;
162
+ /**
163
+ * Abort the in-flight run on the current thread without clearing
164
+ * accumulated state. Sets {@link isLoading} to `false` immediately;
165
+ * {@link values} and {@link messages} are preserved.
166
+ */
54
167
  stop(): Promise<void>;
168
+ /**
169
+ * Resume a pending protocol interrupt by sending a response payload
170
+ * back to the interrupted namespace.
171
+ *
172
+ * When `target` is omitted, responds to the latest unresolved
173
+ * interrupt in {@link interrupts}. Pass an explicit
174
+ * `{ interruptId, namespace? }` when multiple interrupts are
175
+ * pending or the interrupt lives in a subgraph namespace.
176
+ */
55
177
  respond(response: unknown, target?: {
56
178
  interruptId: string;
57
179
  namespace?: string[];
58
180
  }): Promise<void>;
181
+ /** LangGraph SDK client used to construct thread streams. */
59
182
  readonly client: Client;
183
+ /** Assistant id the thread is bound to for its lifetime. */
60
184
  readonly assistantId: string;
61
- /** v2 escape hatch — returns the bound {@link ThreadStream}. */
185
+ /**
186
+ * Returns the bound {@link ThreadStream}, if one exists (`undefined`
187
+ * until the thread is hydrated or the first submit completes). Prefer
188
+ * the projections and selector primitives for UI work; use this for
189
+ * low-level protocol access (raw subscriptions, state commands, etc.).
190
+ */
62
191
  getThread(): ThreadStream$1 | undefined;
63
192
  /** @internal Used by selector primitives. */
64
193
  readonly [STREAM_CONTROLLER]: StreamController<StateType, InterruptType, ConfigurableType>;
@@ -1 +1 @@
1
- {"version":3,"file":"use-stream.d.ts","names":[],"sources":["../src/use-stream.ts"],"mappings":";;;;;;;KA6CK,eAAA,mBAAkC,MAAA;AAAA,KAE3B,oBAAA,6BACV,kBAAA,CAAyB,SAAA,EAAW,eAAA;AAAA,KAE1B,sBAAA,6BACV,oBAAA,CAA2B,SAAA,EAAW,eAAA;AAAA,KAE5B,kBAAA,4BACiB,MAAA,qBACzB,gBAAA,CACF,SAAA,EACA,eAAA;;;;AAVF;;;;cAuBa,iBAAA;;;;;;;;;;AApBb;;;;;UAsCiB,eAAA,KACX,MAAA,8EAE8B,MAAA,8CACP,cAAA,CAAe,CAAA,oBACzB,mBAAA,CAAoB,CAAA;EAAA,SAE5B,MAAA,EAAQ,MAAA,CAAO,SAAA;EAAA,SACf,QAAA,EAAU,MAAA,CAAO,WAAA;EAAA,SACjB,SAAA,EAAW,MAAA,CAAO,cAAA,CAAe,CAAA;EAAA,SACjC,UAAA,EAAY,MAAA,CAAO,SAAA,CAAU,aAAA;EAAA,SAC7B,SAAA,EAAW,MAAA,CAAO,SAAA,CAAU,aAAA;EAAA,SAC5B,SAAA,EAAW,MAAA;EAAA,SACX,eAAA,EAAiB,MAAA;EAAA,SACjB,KAAA,EAAO,MAAA;EAAA,SACP,QAAA,EAAU,MAAA;EAlDO;;;;;EAAA,SAyDjB,gBAAA,EAAkB,MAAA,CAAO,OAAA;EAAA,SAEzB,SAAA,EAAW,MAAA,CAClB,WAAA,OACQ,cAAA,yCAEI,cAAA,WACV,yBAAA;EAAA,SAGK,SAAA,EAAW,MAAA,CAAO,WAAA,SAAoB,yBAAA;EAAA,SACtC,eAAA,EAAiB,MAAA,CACxB,WAAA,kBAA6B,yBAAA;EAG/B,MAAA,CACE,KAAA,EAAO,mBAAA,CAAoB,OAAA,CAAQ,SAAA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A,aAAA,EACA,gBAAA;AAAA;;;;;;KAUQ,SAAA,GAAY,eAAA;;;;;KAMZ,SAAA,KACN,MAAA,8EAE8B,MAAA,qBAChC,eAAA,CAAgB,CAAA,EAAG,aAAA,EAAe,gBAAA;;;;;AAJtC;KAWY,eAAA,KACN,MAAA,8EAE8B,MAAA,qBAChC,eAAA,CAAgB,CAAA,EAAG,aAAA,EAAe,gBAAA;;;;;;;;;;iBAWtB,SAAA,KACV,MAAA,8EAE8B,MAAA,kBAAA,CAElC,OAAA,EAAS,kBAAA,CAAiB,cAAA,CAAe,CAAA,IACzC,UAAA,GAAa,UAAA,GACZ,eAAA,CAAgB,CAAA,EAAG,aAAA,EAAe,gBAAA"}
@@ -1,5 +1,5 @@
1
1
  import { DestroyRef, computed, effect, inject, isSignal, signal, untracked } from "@angular/core";
2
- import { filterOutHeadlessToolInterrupts, flushPendingHeadlessToolInterrupts } from "@langchain/langgraph-sdk";
2
+ import { filterOutHeadlessToolInterrupts, flushPendingHeadlessToolInterrupts, scheduleCoalescedHeadlessToolFlush } from "@langchain/langgraph-sdk";
3
3
  import { Client as Client$1 } from "@langchain/langgraph-sdk/client";
4
4
  import { StreamController } from "@langchain/langgraph-sdk/stream";
5
5
  //#region src/use-stream.ts
@@ -96,20 +96,25 @@ function useStream(options, destroyRef) {
96
96
  untracked(() => handledTools.clear());
97
97
  });
98
98
  effect(() => {
99
- const snapshot = rootSignal();
100
- const bag = snapshot.values;
101
- const combined = [...Array.isArray(bag?.__interrupt__) ? bag.__interrupt__ : [], ...snapshot.interrupts];
102
- if (combined.length === 0) return;
99
+ rootSignal();
103
100
  untracked(() => {
104
- flushPendingHeadlessToolInterrupts({
105
- ...bag,
106
- __interrupt__: combined
107
- }, tools, handledTools, {
108
- onTool,
109
- defer: (run) => {
110
- Promise.resolve().then(run);
111
- },
112
- resumeSubmit: (command) => controller.submit(null, { command })
101
+ scheduleCoalescedHeadlessToolFlush(handledTools, () => {
102
+ const snapshot = rootSignal();
103
+ const bag = snapshot.values;
104
+ const protocolInterrupts = snapshot.interrupts;
105
+ const valuesInterrupts = Array.isArray(bag?.__interrupt__) ? bag.__interrupt__ : [];
106
+ const headlessInterrupts = protocolInterrupts.length > 0 ? protocolInterrupts : valuesInterrupts;
107
+ if (headlessInterrupts.length === 0) return;
108
+ flushPendingHeadlessToolInterrupts({
109
+ ...bag,
110
+ __interrupt__: headlessInterrupts
111
+ }, tools, handledTools, {
112
+ onTool,
113
+ defer: (run) => {
114
+ Promise.resolve().then(run);
115
+ },
116
+ resumeSubmit: (command) => controller.submit(null, { command })
117
+ });
113
118
  });
114
119
  });
115
120
  });
@@ -1 +1 @@
1
- {"version":3,"file":"use-stream.js","names":["ClientCtor"],"sources":["../src/use-stream.ts"],"sourcesContent":["import {\n DestroyRef,\n computed,\n effect,\n inject,\n isSignal,\n signal,\n untracked,\n type Signal,\n} from \"@angular/core\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport type { Client, Interrupt } from \"@langchain/langgraph-sdk\";\nimport {\n filterOutHeadlessToolInterrupts,\n flushPendingHeadlessToolInterrupts,\n type AnyHeadlessToolImplementation,\n type OnToolCallback,\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 InferToolCalls,\n type InferSubagentStates,\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\ntype AngularThreadId = string | null | Signal<string | null | undefined>;\n\nexport type AgentServerOptions<StateType extends object> =\n StreamAgentServerOptions<StateType, AngularThreadId>;\n\nexport type CustomAdapterOptions<StateType extends object> =\n StreamCustomAdapterOptions<StateType, AngularThreadId, string>;\n\nexport type UseStreamOptions<\n StateType extends object = Record<string, unknown>,\n> = StreamUseStreamOptions<\n StateType,\n AngularThreadId,\n string | undefined,\n string | undefined,\n string\n>;\n\n/**\n * Private field on the handle that carries the\n * {@link StreamController} reference. Selector primitives read this\n * to reach the shared {@link ChannelRegistry}. Use the companion\n * `inject*` selectors (`injectMessages`, `injectToolCalls`,\n * `injectValues`, …) instead of reading this directly.\n */\nexport const STREAM_CONTROLLER: unique symbol = Symbol.for(\n \"@langchain/angular/controller\"\n);\n\n/**\n * Return shape of {@link useStream} — the Angular `StreamApi`.\n *\n * Reactivity primitives follow Angular conventions:\n *\n * - Data projections are `Signal<T>`; call them as functions in\n * templates (`stream.messages()`). They are snapshots — never\n * mutate the returned arrays / maps.\n * - Imperative methods (`submit` / `stop` / `respond`) are plain\n * functions. No `WritableSignal`s are exposed on the root handle.\n * - Identity values captured at construction time (`client`,\n * `assistantId`) are exposed as plain values; remount the\n * component to swap them.\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 readonly values: Signal<StateType>;\n readonly messages: Signal<BaseMessage[]>;\n readonly toolCalls: Signal<InferToolCalls<T>[]>;\n readonly interrupts: Signal<Interrupt<InterruptType>[]>;\n readonly interrupt: Signal<Interrupt<InterruptType> | undefined>;\n readonly isLoading: Signal<boolean>;\n readonly isThreadLoading: Signal<boolean>;\n readonly error: Signal<unknown>;\n readonly threadId: Signal<string | null>;\n\n /**\n * Promise that settles when the active thread's initial hydration\n * completes. Exposed so SSR/render-before-flush pipelines can\n * `await stream.hydrationPromise` before serialising.\n */\n readonly hydrationPromise: Signal<Promise<void>>;\n\n readonly subagents: Signal<\n ReadonlyMap<\n keyof SubagentStates & string extends never\n ? string\n : keyof SubagentStates & string,\n SubagentDiscoverySnapshot\n >\n >;\n readonly subgraphs: Signal<ReadonlyMap<string, SubgraphDiscoverySnapshot>>;\n readonly subgraphsByNode: Signal<\n ReadonlyMap<string, readonly SubgraphDiscoverySnapshot[]>\n >;\n\n submit(\n input: WidenUpdateMessages<Partial<StateType>> | null | undefined,\n options?: StreamSubmitOptions<StateType, ConfigurableType>\n ): Promise<void>;\n stop(): Promise<void>;\n respond(\n response: unknown,\n target?: { interruptId: string; namespace?: string[] }\n ): Promise<void>;\n\n readonly client: Client;\n readonly assistantId: string;\n\n /** v2 escape hatch — returns the bound {@link ThreadStream}. */\n getThread(): ThreadStream | undefined;\n\n /** @internal Used by selector primitives. */\n readonly [STREAM_CONTROLLER]: StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >;\n}\n\n/**\n * Erased handle useful as a parameter type for helper components that\n * pass a `stream` through to selector primitives without reading\n * `values` directly. Mirrors the React/Vue `AnyStream` alias.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyStream = UseStreamReturn<any, any, any>;\n\n/**\n * Convenience alias — the fully-resolved return type of\n * {@link useStream} for a given source type `T`.\n */\nexport type StreamApi<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n> = UseStreamReturn<T, InterruptType, ConfigurableType>;\n\n/**\n * React-compatible alias for the fully-resolved stream handle type.\n * Angular docs prefer {@link StreamApi}, but shared libraries can use\n * this name across framework bindings.\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 * Framework-free factory that constructs a {@link StreamController}\n * and wraps its stores in Angular Signals. Callers must supply the\n * {@link DestroyRef} that owns the controller's lifetime — it's\n * already captured by the public `injectStream` helper.\n *\n * Exported for advanced callers (e.g. testing utilities, custom\n * factories) that prefer to manage injection scope themselves.\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 destroyRef?: DestroyRef\n): UseStreamReturn<T, InterruptType, ConfigurableType> {\n type StateType = InferStateType<T>;\n\n interface OptionsBag {\n assistantId?: string;\n threadId?: string | null | Signal<string | null | undefined>;\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 tools?: AnyHeadlessToolImplementation[];\n onTool?: OnToolCallback;\n }\n const asBag = options as OptionsBag;\n\n const hasCustomAdapter =\n asBag.transport != null && typeof asBag.transport !== \"string\";\n const transport = asBag.transport;\n\n const client: Client =\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 // Custom adapters may omit `assistantId`; the controller still\n // requires one so it has something to forward to `threads.stream`.\n const sentinel = \"_\";\n const assistantId =\n \"assistantId\" in options ? (options.assistantId ?? sentinel) : sentinel;\n\n // Normalize threadId input to a signal — callers may pass plain\n // values, nulls, or their own signals.\n const threadIdInput: Signal<string | null> = (() => {\n const raw = asBag.threadId;\n if (isSignal(raw)) {\n return computed(\n () => (raw as Signal<string | null | undefined>)() ?? null\n );\n }\n const initial: string | null = (raw as string | null | undefined) ?? null;\n return signal(initial) as unknown as Signal<string | null>;\n })();\n\n const controller = new StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >({\n assistantId,\n // Cast: the runtime `Client` is state-shape agnostic, but the\n // controller declares `client: Client<StateType>` for its own\n // typings. Same cast is applied in the React/Vue bindings.\n client: client as unknown as Client<StateType>,\n threadId: untracked(() => threadIdInput()),\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\n // Deferred dispose — matches the React `useEffect(() =>\n // controller.activate())` and Vue `onScopeDispose(deactivate)`\n // patterns. HMR / scope-reuse scenarios stay clean because\n // `activate()` cancels the pending dispose if the scope survives.\n const deactivate = controller.activate();\n const ref = destroyRef ?? inject(DestroyRef);\n ref.onDestroy(deactivate);\n\n // ─── Reactivity bridge: StreamStore → Signal ────────────────────────\n function bindStore<S>(\n subscribe: (listener: () => void) => () => void,\n getSnapshot: () => S\n ): Signal<S> {\n const s = signal<S>(getSnapshot());\n const unsubscribe = subscribe(() => {\n s.set(getSnapshot());\n });\n ref.onDestroy(unsubscribe);\n return computed(() => s());\n }\n\n const rootSignal = bindStore<RootSnapshot<StateType, InterruptType>>(\n controller.rootStore.subscribe,\n controller.rootStore.getSnapshot\n );\n const subagentSignal = bindStore<SubagentMap>(\n controller.subagentStore.subscribe,\n controller.subagentStore.getSnapshot\n );\n const subgraphSignal = bindStore<SubgraphMap>(\n controller.subgraphStore.subscribe,\n controller.subgraphStore.getSnapshot\n );\n const subgraphByNodeSignal = bindStore<SubgraphByNodeMap>(\n controller.subgraphByNodeStore.subscribe,\n controller.subgraphByNodeStore.getSnapshot\n );\n\n const values = computed(() => rootSignal().values);\n const messages = computed(() => rootSignal().messages);\n const toolCalls = computed(\n () => rootSignal().toolCalls as InferToolCalls<T>[]\n );\n const interrupts = computed(() =>\n filterOutHeadlessToolInterrupts(rootSignal().interrupts)\n );\n const interrupt = computed(() => interrupts()[0]);\n const isLoading = computed(() => rootSignal().isLoading);\n const isThreadLoading = computed(() => rootSignal().isThreadLoading);\n const error = computed(() => rootSignal().error);\n const threadId = computed(() => rootSignal().threadId);\n\n // `hydrationPromise` is a property on the controller that gets\n // swapped on every `hydrate()` call. Exposing it as a signal lets\n // templates `await stream.hydrationPromise()` reactively; we\n // refresh the reference when the root store settles a new promise.\n const hydrationPromise = computed(() => {\n rootSignal();\n return controller.hydrationPromise;\n });\n\n // ─── threadId reactivity ────────────────────────────────────────────\n //\n // Re-hydrate whenever the caller's threadId input changes after\n // construction. The initial hydrate already fired synchronously in\n // the controller constructor, so we compare against the snapshot\n // captured at construction time rather than blindly skipping the\n // first run — in Angular, `@Input()` bindings apply *between*\n // construction and the first effect tick, so the first read can\n // legitimately be a different (updated) value that needs to\n // hydrate.\n const initialThreadId = untracked(() => threadIdInput()) ?? null;\n let lastAppliedThreadId: string | null = initialThreadId;\n effect(() => {\n const next = threadIdInput() ?? null;\n if (next === lastAppliedThreadId) return;\n lastAppliedThreadId = next;\n untracked(() => {\n void controller.hydrate(next);\n });\n });\n\n // ─── Headless-tool handling ─────────────────────────────────────────\n const tools = options.tools;\n const onTool = options.onTool;\n if (tools?.length) {\n const handledTools = new Set<string>();\n\n // Clear the dedup set whenever the thread id changes.\n effect(() => {\n threadIdInput();\n untracked(() => handledTools.clear());\n });\n\n effect(() => {\n const snapshot = rootSignal();\n const bag = snapshot.values as unknown as Record<string, unknown>;\n const existing = Array.isArray(bag?.__interrupt__)\n ? (bag.__interrupt__ as Interrupt[])\n : [];\n const combined: Interrupt[] = [\n ...existing,\n ...(snapshot.interrupts as unknown as Interrupt[]),\n ];\n if (combined.length === 0) return;\n untracked(() => {\n flushPendingHeadlessToolInterrupts(\n { ...bag, __interrupt__: combined },\n tools,\n handledTools,\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 });\n });\n }\n\n const handle: UseStreamReturn<T, InterruptType, ConfigurableType> = {\n values: values as UseStreamReturn<\n T,\n InterruptType,\n ConfigurableType\n >[\"values\"],\n messages,\n toolCalls,\n interrupts,\n interrupt,\n isLoading,\n isThreadLoading,\n error,\n threadId,\n hydrationPromise,\n subagents: subagentSignal as UseStreamReturn<\n T,\n InterruptType,\n ConfigurableType\n >[\"subagents\"],\n subgraphs: subgraphSignal,\n subgraphsByNode: subgraphByNodeSignal,\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 };\n\n return handle;\n}\n\n/**\n * Helper used by the selector primitives to reach the underlying\n * {@link ChannelRegistry} from a stream handle. Kept internal —\n * application code should call `injectMessages`, `injectToolCalls`,\n * etc. 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":";;;;;;;;;;;;AAsEA,MAAa,oBAAmC,OAAO,IACrD,gCACD;;;;;;;;;;AAmHD,SAAgB,UAKd,SACA,YACqD;CAsBrD,MAAM,QAAQ;CAEd,MAAM,mBACJ,MAAM,aAAa,QAAQ,OAAO,MAAM,cAAc;CACxD,MAAM,YAAY,MAAM;CAExB,MAAM,SACJ,MAAM,UACL,IAAIA,SAAW;EACd,QAAQ,MAAM;EACd,QAAQ,MAAM;EACd,eAAe,MAAM;EACrB,gBAAgB,MAAM;EACvB,CAAC;CAIJ,MAAM,WAAW;CACjB,MAAM,cACJ,iBAAiB,UAAW,QAAQ,eAAe,WAAY;CAIjE,MAAM,uBAA8C;EAClD,MAAM,MAAM,MAAM;AAClB,MAAI,SAAS,IAAI,CACf,QAAO,eACE,KAA2C,IAAI,KACvD;AAGH,SAAO,OADyB,OAAqC,KAC/C;KACpB;CA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ACZ,SAAO,WAAW;GAClB;CAaF,IAAI,sBADoB,gBAAgB,eAAe,CAAC,IAAI;AAE5D,cAAa;EACX,MAAM,OAAO,eAAe,IAAI;AAChC,MAAI,SAAS,oBAAqB;AAClC,wBAAsB;AACtB,kBAAgB;AACT,cAAW,QAAQ,KAAK;IAC7B;GACF;CAGF,MAAM,QAAQ,QAAQ;CACtB,MAAM,SAAS,QAAQ;AACvB,KAAI,OAAO,QAAQ;EACjB,MAAM,+BAAe,IAAI,KAAa;AAGtC,eAAa;AACX,kBAAe;AACf,mBAAgB,aAAa,OAAO,CAAC;IACrC;AAEF,eAAa;GACX,MAAM,WAAW,YAAY;GAC7B,MAAM,MAAM,SAAS;GAIrB,MAAM,WAAwB,CAC5B,GAJe,MAAM,QAAQ,KAAK,cAAc,GAC7C,IAAI,gBACL,EAAE,EAGJ,GAAI,SAAS,WACd;AACD,OAAI,SAAS,WAAW,EAAG;AAC3B,mBAAgB;AACd,uCACE;KAAE,GAAG;KAAK,eAAe;KAAU,EACnC,OACA,cACA;KACE;KACA,QAAQ,QAAQ;AACT,cAAQ,SAAS,CAAC,KAAK,IAAI;;KAElC,eAAe,YACb,WAAW,OAAO,MAAM,EACtB,SACD,CAAqD;KACzD,CACF;KACD;IACF;;AAkCJ,QA/BoE;EAC1D;EAKR;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,WAAW;EAKX,WAAW;EACX,iBAAiB;EACjB,SAAS,OAAO,kBAAkB,WAAW,OAAO,OAAO,cAAc;EACzE,YAAY,WAAW,MAAM;EAC7B,UAAU,UAAU,WAAW,WAAW,QAAQ,UAAU,OAAO;EACnE,iBAAiB,WAAW,WAAW;EACvC;EACA;GACC,oBAAoB;EACtB;;;;;;;;;;AAaH,SAAgB,YAEd,QACiB;AACjB,QAAO,OAAO,mBAAmB"}
1
+ {"version":3,"file":"use-stream.js","names":["ClientCtor"],"sources":["../src/use-stream.ts"],"sourcesContent":["import {\n DestroyRef,\n computed,\n effect,\n inject,\n isSignal,\n signal,\n untracked,\n type Signal,\n} from \"@angular/core\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport type { Client, Interrupt } from \"@langchain/langgraph-sdk\";\nimport {\n filterOutHeadlessToolInterrupts,\n flushPendingHeadlessToolInterrupts,\n scheduleCoalescedHeadlessToolFlush,\n type AnyHeadlessToolImplementation,\n type OnToolCallback,\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 InferToolCalls,\n type InferSubagentStates,\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\ntype AngularThreadId = string | null | Signal<string | null | undefined>;\n\nexport type AgentServerOptions<StateType extends object> =\n StreamAgentServerOptions<StateType, AngularThreadId>;\n\nexport type CustomAdapterOptions<StateType extends object> =\n StreamCustomAdapterOptions<StateType, AngularThreadId, string>;\n\nexport type UseStreamOptions<\n StateType extends object = Record<string, unknown>,\n> = StreamUseStreamOptions<\n StateType,\n AngularThreadId,\n string | undefined,\n string | undefined,\n string\n>;\n\n/**\n * Private field on the handle that carries the\n * {@link StreamController} reference. Selector primitives read this\n * to reach the shared {@link ChannelRegistry}. Use the companion\n * `inject*` selectors (`injectMessages`, `injectToolCalls`,\n * `injectValues`, …) instead of reading this directly.\n */\nexport const STREAM_CONTROLLER: unique symbol = Symbol.for(\n \"@langchain/angular/controller\"\n);\n\n/**\n * Return shape of {@link useStream} — the Angular `StreamApi`.\n *\n * Reactivity primitives follow Angular conventions:\n *\n * - Data projections are `Signal<T>`; call them as functions in\n * templates (`stream.messages()`). They are snapshots — never\n * mutate the returned arrays / maps.\n * - Imperative methods (`submit` / `stop` / `respond`) are plain\n * functions. No `WritableSignal`s are exposed on the root handle.\n * - Identity values captured at construction time (`client`,\n * `assistantId`) are exposed as plain values; remount the\n * component to swap them.\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 `stream.values().messages`\n * directly you'll see full turns appear at once instead of\n * streaming token-by-token. Use {@link messages} (or\n * `injectMessages`) for the token-streamed view.\n *\n * Equivalent to calling `injectValues(stream)`.\n */\n readonly values: Signal<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 Angular layer faithfully renders whatever the\n * server sends.\n *\n * Equivalent to calling `injectMessages(stream)` with no target.\n */\n readonly messages: Signal<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 `injectToolCalls(stream)` with no target.\n */\n readonly toolCalls: Signal<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: Signal<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: Signal<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: Signal<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: Signal<boolean>;\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: Signal<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: Signal<string | null>;\n /**\n * Promise that settles when the active thread's initial hydration\n * completes. Exposed so SSR/render-before-flush pipelines can\n * `await stream.hydrationPromise()` before serialising. A fresh\n * promise is installed on every `threadId` change.\n */\n readonly hydrationPromise: Signal<Promise<void>>;\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: Signal<\n ReadonlyMap<\n keyof SubagentStates & string extends never\n ? string\n : keyof SubagentStates & string,\n SubagentDiscoverySnapshot\n >\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: Signal<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: Signal<\n ReadonlyMap<string, 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 primitive. Pass\n * `null` (or omit fields) when resuming an interrupt via\n * `options.command.resume` — the server accepts a null payload\n * 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 primitives 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 primitives. */\n readonly [STREAM_CONTROLLER]: StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >;\n}\n\n/**\n * Erased handle useful as a parameter type for helper components that\n * pass a `stream` through to selector primitives without reading\n * `values` directly. Mirrors the React/Vue `AnyStream` alias.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyStream = UseStreamReturn<any, any, any>;\n\n/**\n * Convenience alias — the fully-resolved return type of\n * {@link useStream} for a given source type `T`.\n */\nexport type StreamApi<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n> = UseStreamReturn<T, InterruptType, ConfigurableType>;\n\n/**\n * React-compatible alias for the fully-resolved stream handle type.\n * Angular docs prefer {@link StreamApi}, but shared libraries can use\n * this name across framework bindings.\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 * Framework-free factory that constructs a {@link StreamController}\n * and wraps its stores in Angular Signals. Callers must supply the\n * {@link DestroyRef} that owns the controller's lifetime — it's\n * already captured by the public `injectStream` helper.\n *\n * Exported for advanced callers (e.g. testing utilities, custom\n * factories) that prefer to manage injection scope themselves.\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 destroyRef?: DestroyRef\n): UseStreamReturn<T, InterruptType, ConfigurableType> {\n type StateType = InferStateType<T>;\n\n interface OptionsBag {\n assistantId?: string;\n threadId?: string | null | Signal<string | null | undefined>;\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 tools?: AnyHeadlessToolImplementation[];\n onTool?: OnToolCallback;\n }\n const asBag = options as OptionsBag;\n\n const hasCustomAdapter =\n asBag.transport != null && typeof asBag.transport !== \"string\";\n const transport = asBag.transport;\n\n const client: Client =\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 // Custom adapters may omit `assistantId`; the controller still\n // requires one so it has something to forward to `threads.stream`.\n const sentinel = \"_\";\n const assistantId =\n \"assistantId\" in options ? (options.assistantId ?? sentinel) : sentinel;\n\n // Normalize threadId input to a signal — callers may pass plain\n // values, nulls, or their own signals.\n const threadIdInput: Signal<string | null> = (() => {\n const raw = asBag.threadId;\n if (isSignal(raw)) {\n return computed(\n () => (raw as Signal<string | null | undefined>)() ?? null\n );\n }\n const initial: string | null = (raw as string | null | undefined) ?? null;\n return signal(initial) as unknown as Signal<string | null>;\n })();\n\n const controller = new StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >({\n assistantId,\n // Cast: the runtime `Client` is state-shape agnostic, but the\n // controller declares `client: Client<StateType>` for its own\n // typings. Same cast is applied in the React/Vue bindings.\n client: client as unknown as Client<StateType>,\n threadId: untracked(() => threadIdInput()),\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\n // Deferred dispose — matches the React `useEffect(() =>\n // controller.activate())` and Vue `onScopeDispose(deactivate)`\n // patterns. HMR / scope-reuse scenarios stay clean because\n // `activate()` cancels the pending dispose if the scope survives.\n const deactivate = controller.activate();\n const ref = destroyRef ?? inject(DestroyRef);\n ref.onDestroy(deactivate);\n\n // ─── Reactivity bridge: StreamStore → Signal ────────────────────────\n function bindStore<S>(\n subscribe: (listener: () => void) => () => void,\n getSnapshot: () => S\n ): Signal<S> {\n const s = signal<S>(getSnapshot());\n const unsubscribe = subscribe(() => {\n s.set(getSnapshot());\n });\n ref.onDestroy(unsubscribe);\n return computed(() => s());\n }\n\n const rootSignal = bindStore<RootSnapshot<StateType, InterruptType>>(\n controller.rootStore.subscribe,\n controller.rootStore.getSnapshot\n );\n const subagentSignal = bindStore<SubagentMap>(\n controller.subagentStore.subscribe,\n controller.subagentStore.getSnapshot\n );\n const subgraphSignal = bindStore<SubgraphMap>(\n controller.subgraphStore.subscribe,\n controller.subgraphStore.getSnapshot\n );\n const subgraphByNodeSignal = bindStore<SubgraphByNodeMap>(\n controller.subgraphByNodeStore.subscribe,\n controller.subgraphByNodeStore.getSnapshot\n );\n\n const values = computed(() => rootSignal().values);\n const messages = computed(() => rootSignal().messages);\n const toolCalls = computed(\n () => rootSignal().toolCalls as InferToolCalls<T>[]\n );\n const interrupts = computed(() =>\n filterOutHeadlessToolInterrupts(rootSignal().interrupts)\n );\n const interrupt = computed(() => interrupts()[0]);\n const isLoading = computed(() => rootSignal().isLoading);\n const isThreadLoading = computed(() => rootSignal().isThreadLoading);\n const error = computed(() => rootSignal().error);\n const threadId = computed(() => rootSignal().threadId);\n\n // `hydrationPromise` is a property on the controller that gets\n // swapped on every `hydrate()` call. Exposing it as a signal lets\n // templates `await stream.hydrationPromise()` reactively; we\n // refresh the reference when the root store settles a new promise.\n const hydrationPromise = computed(() => {\n rootSignal();\n return controller.hydrationPromise;\n });\n\n // ─── threadId reactivity ────────────────────────────────────────────\n //\n // Re-hydrate whenever the caller's threadId input changes after\n // construction. The initial hydrate already fired synchronously in\n // the controller constructor, so we compare against the snapshot\n // captured at construction time rather than blindly skipping the\n // first run — in Angular, `@Input()` bindings apply *between*\n // construction and the first effect tick, so the first read can\n // legitimately be a different (updated) value that needs to\n // hydrate.\n const initialThreadId = untracked(() => threadIdInput()) ?? null;\n let lastAppliedThreadId: string | null = initialThreadId;\n effect(() => {\n const next = threadIdInput() ?? null;\n if (next === lastAppliedThreadId) return;\n lastAppliedThreadId = next;\n untracked(() => {\n void controller.hydrate(next);\n });\n });\n\n // ─── Headless-tool handling ─────────────────────────────────────────\n const tools = options.tools;\n const onTool = options.onTool;\n if (tools?.length) {\n const handledTools = new Set<string>();\n\n // Clear the dedup set whenever the thread id changes.\n effect(() => {\n threadIdInput();\n untracked(() => handledTools.clear());\n });\n\n effect(() => {\n rootSignal();\n untracked(() => {\n scheduleCoalescedHeadlessToolFlush(handledTools, () => {\n const snapshot = rootSignal();\n const bag = snapshot.values as unknown as Record<string, unknown>;\n const protocolInterrupts =\n snapshot.interrupts as unknown as Interrupt[];\n const valuesInterrupts = Array.isArray(bag?.__interrupt__)\n ? (bag.__interrupt__ as Interrupt[])\n : [];\n const headlessInterrupts =\n protocolInterrupts.length > 0\n ? protocolInterrupts\n : valuesInterrupts;\n if (headlessInterrupts.length === 0) return;\n flushPendingHeadlessToolInterrupts(\n { ...bag, __interrupt__: headlessInterrupts },\n tools,\n handledTools,\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 });\n });\n });\n }\n\n const handle: UseStreamReturn<T, InterruptType, ConfigurableType> = {\n values: values as UseStreamReturn<\n T,\n InterruptType,\n ConfigurableType\n >[\"values\"],\n messages,\n toolCalls,\n interrupts,\n interrupt,\n isLoading,\n isThreadLoading,\n error,\n threadId,\n hydrationPromise,\n subagents: subagentSignal as UseStreamReturn<\n T,\n InterruptType,\n ConfigurableType\n >[\"subagents\"],\n subgraphs: subgraphSignal,\n subgraphsByNode: subgraphByNodeSignal,\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 };\n\n return handle;\n}\n\n/**\n * Helper used by the selector primitives to reach the underlying\n * {@link ChannelRegistry} from a stream handle. Kept internal —\n * application code should call `injectMessages`, `injectToolCalls`,\n * etc. 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":";;;;;;;;;;;;AAuEA,MAAa,oBAAmC,OAAO,IACrD,gCACD;;;;;;;;;;AAuPD,SAAgB,UAKd,SACA,YACqD;CAsBrD,MAAM,QAAQ;CAEd,MAAM,mBACJ,MAAM,aAAa,QAAQ,OAAO,MAAM,cAAc;CACxD,MAAM,YAAY,MAAM;CAExB,MAAM,SACJ,MAAM,UACL,IAAIA,SAAW;EACd,QAAQ,MAAM;EACd,QAAQ,MAAM;EACd,eAAe,MAAM;EACrB,gBAAgB,MAAM;EACvB,CAAC;CAIJ,MAAM,WAAW;CACjB,MAAM,cACJ,iBAAiB,UAAW,QAAQ,eAAe,WAAY;CAIjE,MAAM,uBAA8C;EAClD,MAAM,MAAM,MAAM;AAClB,MAAI,SAAS,IAAI,CACf,QAAO,eACE,KAA2C,IAAI,KACvD;AAGH,SAAO,OADyB,OAAqC,KAC/C;KACpB;CAEJ,MAAM,aAAa,IAAI,iBAIrB;EACA;EAIQ;EACR,UAAU,gBAAgB,eAAe,CAAC;EAC1C;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;CAMF,MAAM,aAAa,WAAW,U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Ae,IAAI,KAAa;AAGtC,eAAa;AACX,kBAAe;AACf,mBAAgB,aAAa,OAAO,CAAC;IACrC;AAEF,eAAa;AACX,eAAY;AACZ,mBAAgB;AACd,uCAAmC,oBAAoB;KACrD,MAAM,WAAW,YAAY;KAC7B,MAAM,MAAM,SAAS;KACrB,MAAM,qBACJ,SAAS;KACX,MAAM,mBAAmB,MAAM,QAAQ,KAAK,cAAc,GACrD,IAAI,gBACL,EAAE;KACN,MAAM,qBACJ,mBAAmB,SAAS,IACxB,qBACA;AACN,SAAI,mBAAmB,WAAW,EAAG;AACrC,wCACE;MAAE,GAAG;MAAK,eAAe;MAAoB,EAC7C,OACA,cACA;MACE;MACA,QAAQ,QAAQ;AACT,eAAQ,SAAS,CAAC,KAAK,IAAI;;MAElC,eAAe,YACb,WAAW,OAAO,MAAM,EACtB,SACD,CAAqD;MACzD,CACF;MACD;KACF;IACF;;AAkCJ,QA/BoE;EAC1D;EAKR;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,WAAW;EAKX,WAAW;EACX,iBAAiB;EACjB,SAAS,OAAO,kBAAkB,WAAW,OAAO,OAAO,cAAc;EACzE,YAAY,WAAW,MAAM;EAC7B,UAAU,UAAU,WAAW,WAAW,QAAQ,UAAU,OAAO;EACnE,iBAAiB,WAAW,WAAW;EACvC;EACA;GACC,oBAAoB;EACtB;;;;;;;;;;AAaH,SAAgB,YAEd,QACiB;AACjB,QAAO,OAAO,mBAAmB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/angular",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Angular integration for LangGraph & LangChain",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -10,7 +10,7 @@
10
10
  "directory": "libs/sdk-angular"
11
11
  },
12
12
  "dependencies": {
13
- "@langchain/langgraph-sdk": "1.9.5"
13
+ "@langchain/langgraph-sdk": "1.9.6"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@analogjs/vite-plugin-angular": "^2.5.0",