@langchain/langgraph 1.2.9 → 1.3.0

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.
Files changed (141) hide show
  1. package/dist/graph/graph.cjs +6 -2
  2. package/dist/graph/graph.cjs.map +1 -1
  3. package/dist/graph/graph.d.cts +58 -7
  4. package/dist/graph/graph.d.cts.map +1 -1
  5. package/dist/graph/graph.d.ts +58 -7
  6. package/dist/graph/graph.d.ts.map +1 -1
  7. package/dist/graph/graph.js +6 -2
  8. package/dist/graph/graph.js.map +1 -1
  9. package/dist/graph/index.d.ts +1 -1
  10. package/dist/graph/state.cjs +3 -2
  11. package/dist/graph/state.cjs.map +1 -1
  12. package/dist/graph/state.d.cts +13 -5
  13. package/dist/graph/state.d.cts.map +1 -1
  14. package/dist/graph/state.d.ts +13 -5
  15. package/dist/graph/state.d.ts.map +1 -1
  16. package/dist/graph/state.js +3 -2
  17. package/dist/graph/state.js.map +1 -1
  18. package/dist/index.cjs +34 -5
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +12 -2
  21. package/dist/index.d.ts +12 -2
  22. package/dist/index.js +10 -1
  23. package/dist/index.js.map +1 -1
  24. package/dist/prebuilt/agent_executor.d.cts +1 -1
  25. package/dist/prebuilt/agent_executor.d.ts +1 -1
  26. package/dist/pregel/index.cjs +69 -25
  27. package/dist/pregel/index.cjs.map +1 -1
  28. package/dist/pregel/index.d.cts +25 -3
  29. package/dist/pregel/index.d.cts.map +1 -1
  30. package/dist/pregel/index.d.ts +25 -3
  31. package/dist/pregel/index.d.ts.map +1 -1
  32. package/dist/pregel/index.js +69 -25
  33. package/dist/pregel/index.js.map +1 -1
  34. package/dist/pregel/loop.cjs +51 -10
  35. package/dist/pregel/loop.cjs.map +1 -1
  36. package/dist/pregel/loop.js +51 -10
  37. package/dist/pregel/loop.js.map +1 -1
  38. package/dist/pregel/messages-v2.cjs +231 -0
  39. package/dist/pregel/messages-v2.cjs.map +1 -0
  40. package/dist/pregel/messages-v2.js +231 -0
  41. package/dist/pregel/messages-v2.js.map +1 -0
  42. package/dist/pregel/stream.cjs.map +1 -1
  43. package/dist/pregel/stream.d.cts +30 -0
  44. package/dist/pregel/stream.d.cts.map +1 -0
  45. package/dist/pregel/stream.d.ts +30 -1
  46. package/dist/pregel/stream.d.ts.map +1 -0
  47. package/dist/pregel/stream.js.map +1 -1
  48. package/dist/pregel/types.cjs.map +1 -1
  49. package/dist/pregel/types.d.cts +8 -1
  50. package/dist/pregel/types.d.cts.map +1 -1
  51. package/dist/pregel/types.d.ts +8 -1
  52. package/dist/pregel/types.d.ts.map +1 -1
  53. package/dist/pregel/types.js.map +1 -1
  54. package/dist/stream/convert.cjs +207 -0
  55. package/dist/stream/convert.cjs.map +1 -0
  56. package/dist/stream/convert.d.cts +69 -0
  57. package/dist/stream/convert.d.cts.map +1 -0
  58. package/dist/stream/convert.d.ts +69 -0
  59. package/dist/stream/convert.d.ts.map +1 -0
  60. package/dist/stream/convert.js +206 -0
  61. package/dist/stream/convert.js.map +1 -0
  62. package/dist/stream/index.cjs +11 -0
  63. package/dist/stream/index.d.cts +12 -0
  64. package/dist/stream/index.d.ts +12 -0
  65. package/dist/stream/index.js +12 -0
  66. package/dist/stream/mux.cjs +350 -0
  67. package/dist/stream/mux.cjs.map +1 -0
  68. package/dist/stream/mux.d.cts +160 -0
  69. package/dist/stream/mux.d.cts.map +1 -0
  70. package/dist/stream/mux.d.ts +160 -0
  71. package/dist/stream/mux.d.ts.map +1 -0
  72. package/dist/stream/mux.js +345 -0
  73. package/dist/stream/mux.js.map +1 -0
  74. package/dist/stream/run-stream.cjs +439 -0
  75. package/dist/stream/run-stream.cjs.map +1 -0
  76. package/dist/stream/run-stream.d.cts +286 -0
  77. package/dist/stream/run-stream.d.cts.map +1 -0
  78. package/dist/stream/run-stream.d.ts +285 -0
  79. package/dist/stream/run-stream.d.ts.map +1 -0
  80. package/dist/stream/run-stream.js +434 -0
  81. package/dist/stream/run-stream.js.map +1 -0
  82. package/dist/stream/stream-channel.cjs +208 -0
  83. package/dist/stream/stream-channel.cjs.map +1 -0
  84. package/dist/stream/stream-channel.d.cts +129 -0
  85. package/dist/stream/stream-channel.d.cts.map +1 -0
  86. package/dist/stream/stream-channel.d.ts +129 -0
  87. package/dist/stream/stream-channel.d.ts.map +1 -0
  88. package/dist/stream/stream-channel.js +207 -0
  89. package/dist/stream/stream-channel.js.map +1 -0
  90. package/dist/stream/transformers/index.cjs +4 -0
  91. package/dist/stream/transformers/index.d.ts +5 -0
  92. package/dist/stream/transformers/index.js +5 -0
  93. package/dist/stream/transformers/lifecycle.cjs +326 -0
  94. package/dist/stream/transformers/lifecycle.cjs.map +1 -0
  95. package/dist/stream/transformers/lifecycle.d.cts +53 -0
  96. package/dist/stream/transformers/lifecycle.d.cts.map +1 -0
  97. package/dist/stream/transformers/lifecycle.d.ts +53 -0
  98. package/dist/stream/transformers/lifecycle.d.ts.map +1 -0
  99. package/dist/stream/transformers/lifecycle.js +325 -0
  100. package/dist/stream/transformers/lifecycle.js.map +1 -0
  101. package/dist/stream/transformers/messages.cjs +94 -0
  102. package/dist/stream/transformers/messages.cjs.map +1 -0
  103. package/dist/stream/transformers/messages.d.cts +23 -0
  104. package/dist/stream/transformers/messages.d.cts.map +1 -0
  105. package/dist/stream/transformers/messages.d.ts +23 -0
  106. package/dist/stream/transformers/messages.d.ts.map +1 -0
  107. package/dist/stream/transformers/messages.js +94 -0
  108. package/dist/stream/transformers/messages.js.map +1 -0
  109. package/dist/stream/transformers/subgraphs.cjs +125 -0
  110. package/dist/stream/transformers/subgraphs.cjs.map +1 -0
  111. package/dist/stream/transformers/subgraphs.d.cts +95 -0
  112. package/dist/stream/transformers/subgraphs.d.cts.map +1 -0
  113. package/dist/stream/transformers/subgraphs.d.ts +95 -0
  114. package/dist/stream/transformers/subgraphs.d.ts.map +1 -0
  115. package/dist/stream/transformers/subgraphs.js +124 -0
  116. package/dist/stream/transformers/subgraphs.js.map +1 -0
  117. package/dist/stream/transformers/types.d.cts +89 -0
  118. package/dist/stream/transformers/types.d.cts.map +1 -0
  119. package/dist/stream/transformers/types.d.ts +89 -0
  120. package/dist/stream/transformers/types.d.ts.map +1 -0
  121. package/dist/stream/transformers/values.cjs +39 -0
  122. package/dist/stream/transformers/values.cjs.map +1 -0
  123. package/dist/stream/transformers/values.d.cts +21 -0
  124. package/dist/stream/transformers/values.d.cts.map +1 -0
  125. package/dist/stream/transformers/values.d.ts +21 -0
  126. package/dist/stream/transformers/values.d.ts.map +1 -0
  127. package/dist/stream/transformers/values.js +39 -0
  128. package/dist/stream/transformers/values.js.map +1 -0
  129. package/dist/stream/types.cjs +11 -0
  130. package/dist/stream/types.cjs.map +1 -0
  131. package/dist/stream/types.d.cts +255 -0
  132. package/dist/stream/types.d.cts.map +1 -0
  133. package/dist/stream/types.d.ts +255 -0
  134. package/dist/stream/types.d.ts.map +1 -0
  135. package/dist/stream/types.js +11 -0
  136. package/dist/stream/types.js.map +1 -0
  137. package/dist/web.cjs +39 -9
  138. package/dist/web.d.cts +12 -2
  139. package/dist/web.d.ts +12 -2
  140. package/dist/web.js +10 -1
  141. package/package.json +9 -8
@@ -0,0 +1,434 @@
1
+ import { REJECT_VALUES, RESOLVE_VALUES, StreamMux, pump } from "./mux.js";
2
+ import { createLifecycleTransformer, filterLifecycleEntries } from "./transformers/lifecycle.js";
3
+ import { createMessagesTransformer } from "./transformers/messages.js";
4
+ import { createSubgraphDiscoveryTransformer, filterSubgraphHandles } from "./transformers/subgraphs.js";
5
+ import { createValuesTransformer } from "./transformers/values.js";
6
+ import "./transformers/index.js";
7
+ import { isNativeTransformer } from "./types.js";
8
+ //#region src/stream/run-stream.ts
9
+ /**
10
+ * Symbol key for attaching the values log to a stream handle.
11
+ * Using a symbol keeps this off the public autocomplete surface.
12
+ */
13
+ const SET_VALUES_LOG = Symbol("setValuesLog");
14
+ /**
15
+ * Symbol key for attaching the messages iterable to a stream handle.
16
+ * Using a symbol keeps this off the public autocomplete surface.
17
+ */
18
+ const SET_MESSAGES_ITERABLE = Symbol("setMessagesIterable");
19
+ /**
20
+ * Symbol key for attaching the lifecycle iterable to a stream handle.
21
+ * Using a symbol keeps this off the public autocomplete surface.
22
+ */
23
+ const SET_LIFECYCLE_ITERABLE = Symbol("setLifecycleIterable");
24
+ /**
25
+ * Symbol key for attaching the subgraphs iterable to a stream handle.
26
+ * Using a symbol keeps this off the public autocomplete surface.
27
+ */
28
+ const SET_SUBGRAPHS_ITERABLE = Symbol("setSubgraphsIterable");
29
+ /**
30
+ * Shared empty async iterable, returned from getters that haven't
31
+ * been wired by {@link createGraphRunStream}. Avoids allocating a
32
+ * fresh empty iterable on every access.
33
+ */
34
+ const EMPTY_ASYNC_ITERABLE = { [Symbol.asyncIterator]() {
35
+ return { next: () => Promise.resolve({
36
+ value: void 0,
37
+ done: true
38
+ }) };
39
+ } };
40
+ /**
41
+ * Primary run stream for a LangGraph execution.
42
+ *
43
+ * Implements {@link AsyncIterable} over {@link ProtocolEvent} and exposes
44
+ * ergonomic projections for values, messages, subgraphs, output, and
45
+ * interrupts. Created by {@link createGraphRunStream}.
46
+ *
47
+ * @typeParam TValues - Shape of the graph's state values.
48
+ * @typeParam TExtensions - Shape of additional transformer projections merged
49
+ * into {@link GraphRunStream.extensions}.
50
+ */
51
+ var GraphRunStream = class {
52
+ /**
53
+ * Namespace path identifying this stream's position in the agent tree.
54
+ * An empty array for the root stream.
55
+ */
56
+ path;
57
+ /**
58
+ * Merged projections from user-supplied {@link StreamTransformer} factories.
59
+ * Each transformer's `init()` return value is spread into this object.
60
+ */
61
+ extensions;
62
+ /**
63
+ * The central stream multiplexer that drives event dispatch and transformer
64
+ * pipelines. Accessible to subclasses for direct event subscription.
65
+ *
66
+ * @internal
67
+ */
68
+ _mux;
69
+ #eventStart;
70
+ #discoveryStart;
71
+ #abortController;
72
+ #resolveValuesFn;
73
+ #rejectValuesFn;
74
+ #valuesDone;
75
+ #valuesLog;
76
+ #messagesIterable;
77
+ #lifecycleIterable;
78
+ #subgraphsIterable;
79
+ /**
80
+ * @param path - Namespace path for this stream (empty array for root).
81
+ * @param mux - The {@link StreamMux} driving this run.
82
+ * @param discoveryStart - Cursor offset into the mux discovery log.
83
+ * @param eventStart - Cursor offset into the mux event log.
84
+ * @param extensions - Pre-initialized transformer projections.
85
+ * @param abortController - Controller for programmatic cancellation.
86
+ */
87
+ constructor(path, mux, discoveryStart = 0, eventStart = 0, extensions, abortController) {
88
+ this.path = path;
89
+ this._mux = mux;
90
+ this.#discoveryStart = discoveryStart;
91
+ this.#eventStart = eventStart;
92
+ this.extensions = extensions ?? {};
93
+ this.#abortController = abortController ?? new AbortController();
94
+ this.#valuesDone = new Promise((resolve, reject) => {
95
+ this.#resolveValuesFn = resolve;
96
+ this.#rejectValuesFn = reject;
97
+ });
98
+ this.#valuesDone.catch(() => {});
99
+ }
100
+ /**
101
+ * Async iterator over all {@link ProtocolEvent}s at or below this
102
+ * stream's namespace, starting from the configured event offset.
103
+ *
104
+ * @returns An async iterator yielding protocol events in arrival order.
105
+ */
106
+ [Symbol.asyncIterator]() {
107
+ return this._mux.subscribeEvents(this.path, this.#eventStart);
108
+ }
109
+ /**
110
+ * Async iterable of child {@link SubgraphRunStream} instances discovered
111
+ * during the run. Each yielded stream represents a direct child namespace.
112
+ *
113
+ * Backed by the shared `_discoveries` log on the mux, populated by
114
+ * {@link createSubgraphDiscoveryTransformer}. For streams created
115
+ * through {@link createGraphRunStream} the iterable is pre-wired
116
+ * (via {@link SET_SUBGRAPHS_ITERABLE}) so iteration is cheap.
117
+ * Streams constructed directly (e.g. in unit tests) fall back to
118
+ * filtering `_mux._discoveries` on demand, preserving the original
119
+ * behavior without requiring explicit wiring.
120
+ *
121
+ * @returns An async iterable of subgraph run streams.
122
+ */
123
+ get subgraphs() {
124
+ if (this.#subgraphsIterable) return this.#subgraphsIterable;
125
+ return filterSubgraphHandles(this._mux._discoveries, this.path, this.#discoveryStart);
126
+ }
127
+ /**
128
+ * Dual-interface accessor for graph state snapshots.
129
+ *
130
+ * As an {@link AsyncIterable}, yields each intermediate state snapshot
131
+ * as it arrives. As a {@link PromiseLike}, resolves with the final
132
+ * state value when the run completes.
133
+ *
134
+ * @returns A combined async iterable and promise-like for state values.
135
+ */
136
+ get values() {
137
+ const log = this.#valuesLog;
138
+ const done = this.#valuesDone;
139
+ const mux = this._mux;
140
+ const eventStart = this.#eventStart;
141
+ const path = this.path;
142
+ const iterable = log ? log.toAsyncIterable() : { [Symbol.asyncIterator]: () => {
143
+ const base = mux.subscribeEvents(path, eventStart);
144
+ return { async next() {
145
+ while (true) {
146
+ const result = await base.next();
147
+ if (result.done) return {
148
+ value: void 0,
149
+ done: true
150
+ };
151
+ if (result.value.method === "values" && result.value.params.namespace.length === path.length) return {
152
+ value: result.value.params.data,
153
+ done: false
154
+ };
155
+ }
156
+ } };
157
+ } };
158
+ return {
159
+ [Symbol.asyncIterator]: () => iterable[Symbol.asyncIterator](),
160
+ then: done.then.bind(done)
161
+ };
162
+ }
163
+ /**
164
+ * All AI message lifecycles observed at this namespace level, in order.
165
+ * Each yielded {@link ChatModelStream} represents one message-start →
166
+ * message-finish lifecycle with streaming `.text`, `.reasoning`, and
167
+ * `.usage` projections.
168
+ *
169
+ * @returns An async iterable of chat model streams.
170
+ */
171
+ get messages() {
172
+ if (this.#messagesIterable) return this.#messagesIterable;
173
+ const transformer = createMessagesTransformer(this.path);
174
+ const projection = transformer.init();
175
+ this._mux.addTransformer(transformer);
176
+ this.#messagesIterable = projection.messages;
177
+ return this.#messagesIterable;
178
+ }
179
+ /**
180
+ * Sequence of {@link LifecycleEntry} records tracking the
181
+ * `lifecycle` channel: when the run starts, when each subgraph
182
+ * enters/exits, and the terminal status of the run as a whole.
183
+ *
184
+ * Backed by the built-in {@link createLifecycleTransformer}; the
185
+ * root stream's iterable is wired during
186
+ * {@link createGraphRunStream} setup, and each
187
+ * {@link SubgraphRunStream} is wired in the subgraph discovery
188
+ * factory with a subtree-scoped view (via
189
+ * {@link filterLifecycleEntries}). Streams constructed outside
190
+ * `createGraphRunStream` and not wired will yield nothing.
191
+ *
192
+ * @returns An async iterable of lifecycle entries in emission order.
193
+ */
194
+ get lifecycle() {
195
+ return this.#lifecycleIterable ?? EMPTY_ASYNC_ITERABLE;
196
+ }
197
+ /**
198
+ * Messages produced by a specific graph node. Use when the run has
199
+ * multiple model-calling nodes and you only want messages from one.
200
+ *
201
+ * @param node - The graph node name to filter messages by.
202
+ * @returns An async iterable of chat model streams from the given node.
203
+ */
204
+ messagesFrom(node) {
205
+ const transformer = createMessagesTransformer(this.path, node);
206
+ const projection = transformer.init();
207
+ this._mux.addTransformer(transformer);
208
+ return projection.messages;
209
+ }
210
+ /**
211
+ * Promise that resolves with the final graph state when the run completes,
212
+ * or rejects if the run fails.
213
+ *
214
+ * @returns A promise resolving to the final state values.
215
+ */
216
+ get output() {
217
+ return this.#valuesDone;
218
+ }
219
+ /**
220
+ * Whether the run ended due to a human-in-the-loop interrupt.
221
+ *
222
+ * @returns `true` if the run was interrupted.
223
+ */
224
+ get interrupted() {
225
+ return this._mux.interrupted;
226
+ }
227
+ /**
228
+ * Interrupt payloads collected during the run, if any.
229
+ *
230
+ * @returns A readonly array of interrupt payloads.
231
+ */
232
+ get interrupts() {
233
+ return this._mux.interrupts;
234
+ }
235
+ /**
236
+ * Programmatically abort this run. Equivalent to calling
237
+ * `signal.abort(reason)`.
238
+ *
239
+ * @param reason - Optional abort reason passed to the signal.
240
+ */
241
+ abort(reason) {
242
+ this.#abortController.abort(reason);
243
+ }
244
+ /**
245
+ * The {@link AbortSignal} wired into this run for cancellation support.
246
+ *
247
+ * @returns The abort signal for this stream.
248
+ */
249
+ get signal() {
250
+ return this.#abortController.signal;
251
+ }
252
+ /**
253
+ * Resolve the output/values promise with the final state snapshot.
254
+ * Called by {@link StreamMux.close}.
255
+ *
256
+ * @param values - The final state values, or `undefined` if none.
257
+ * @internal
258
+ */
259
+ [RESOLVE_VALUES](values) {
260
+ this.#resolveValuesFn?.(values);
261
+ this.#resolveValuesFn = void 0;
262
+ }
263
+ /**
264
+ * Reject the output/values promise with a run error.
265
+ * Called by {@link StreamMux.fail}.
266
+ *
267
+ * @param err - The error that caused the run to fail.
268
+ * @internal
269
+ */
270
+ [REJECT_VALUES](err) {
271
+ this.#rejectValuesFn?.(err);
272
+ this.#rejectValuesFn = void 0;
273
+ }
274
+ /**
275
+ * Attach the transformer-populated event log backing the `.values` iterable.
276
+ * Called during stream setup in {@link createGraphRunStream}.
277
+ *
278
+ * @param log - The event log from the values transformer projection.
279
+ * @internal
280
+ */
281
+ [SET_VALUES_LOG](log) {
282
+ this.#valuesLog = log;
283
+ }
284
+ /**
285
+ * Attach the transformer-populated async iterable backing the `.messages`
286
+ * accessor. Called during stream setup in {@link createGraphRunStream}.
287
+ *
288
+ * @param iterable - The async iterable from the messages transformer projection.
289
+ * @internal
290
+ */
291
+ [SET_MESSAGES_ITERABLE](iterable) {
292
+ this.#messagesIterable = iterable;
293
+ }
294
+ /**
295
+ * Attach the transformer-populated async iterable backing the
296
+ * `.lifecycle` accessor. Called during stream setup in
297
+ * {@link createGraphRunStream}.
298
+ *
299
+ * @param iterable - The async iterable from the lifecycle transformer projection.
300
+ * @internal
301
+ */
302
+ [SET_LIFECYCLE_ITERABLE](iterable) {
303
+ this.#lifecycleIterable = iterable;
304
+ }
305
+ /**
306
+ * Attach the transformer-populated async iterable backing the
307
+ * `.subgraphs` accessor. Called during root stream setup in
308
+ * {@link createGraphRunStream} and during child stream
309
+ * construction in the discovery transformer factory.
310
+ *
311
+ * @param iterable - The async iterable of direct-child stream handles.
312
+ * @internal
313
+ */
314
+ [SET_SUBGRAPHS_ITERABLE](iterable) {
315
+ this.#subgraphsIterable = iterable;
316
+ }
317
+ };
318
+ /**
319
+ * A run stream for a child subgraph within a parent graph execution.
320
+ *
321
+ * Extends {@link GraphRunStream} with a parsed {@link name} and
322
+ * {@link index} extracted from the last segment of the namespace path.
323
+ * The segment is expected to follow the `"name:index"` convention;
324
+ * when no numeric suffix is present, {@link index} defaults to `0`.
325
+ *
326
+ * @typeParam TValues - Shape of the subgraph's state values.
327
+ * @typeParam TExtensions - Shape of additional transformer projections.
328
+ */
329
+ var SubgraphRunStream = class extends GraphRunStream {
330
+ /**
331
+ * The node name extracted from the last segment of the namespace path
332
+ * (everything before the final colon, or the full segment if no colon).
333
+ */
334
+ name;
335
+ /**
336
+ * The invocation index parsed from the `"name:N"` suffix of the last
337
+ * namespace segment. Defaults to `0` when no numeric suffix is present.
338
+ */
339
+ index;
340
+ /**
341
+ * @param path - Namespace path for this subgraph stream.
342
+ * @param mux - The {@link StreamMux} driving this run.
343
+ * @param discoveryStart - Cursor offset into the mux discovery log.
344
+ * @param eventStart - Cursor offset into the mux event log.
345
+ * @param extensions - Pre-initialized transformer projections.
346
+ * @param abortController - Controller for programmatic cancellation.
347
+ */
348
+ constructor(path, mux, discoveryStart = 0, eventStart = 0, extensions, abortController) {
349
+ super(path, mux, discoveryStart, eventStart, extensions, abortController);
350
+ const lastSegment = path[path.length - 1] ?? "";
351
+ const colonIdx = lastSegment.lastIndexOf(":");
352
+ if (colonIdx >= 0) {
353
+ this.name = lastSegment.slice(0, colonIdx);
354
+ const suffix = lastSegment.slice(colonIdx + 1);
355
+ this.index = /^\d+$/.test(suffix) ? Number(suffix) : 0;
356
+ } else {
357
+ this.name = lastSegment;
358
+ this.index = 0;
359
+ }
360
+ }
361
+ };
362
+ /**
363
+ * Creates a {@link GraphRunStream} with built-in transformers and kicks off the
364
+ * background pump that feeds raw stream chunks through the transformer pipeline.
365
+ *
366
+ * Built-in transformers are registered in this order:
367
+ * 1. subgraph discovery — materializes SubgraphRunStream handles
368
+ * for each newly observed top-level namespace and announces them
369
+ * on the mux `_discoveries` log.
370
+ * 2. lifecycle — synthesizes `lifecycle` channel events.
371
+ * 3. values — powers `run.values` / `run.output`.
372
+ * 4. messages — powers `run.messages` / `.messagesFrom`.
373
+ *
374
+ * Subgraph discovery is registered first so that downstream
375
+ * transformers (notably lifecycle) observe child namespaces with
376
+ * their stream handles already in place. User-supplied transformer
377
+ * factories are registered afterwards.
378
+ *
379
+ * @typeParam TValues - Shape of the graph's state values.
380
+ * @param source - Raw async iterable from `graph.stream(…, { subgraphs: true })`.
381
+ * @param transformers - User-supplied transformer factories.
382
+ * @param optionsOrAbortController - Either a full
383
+ * {@link CreateGraphRunStreamOptions} object or (for backward
384
+ * compatibility) a bare `AbortController`.
385
+ * @returns A {@link GraphRunStream} for the root namespace.
386
+ */
387
+ function createGraphRunStream(source, transformers = [], optionsOrAbortController) {
388
+ const { abortController } = optionsOrAbortController instanceof AbortController ? { abortController: optionsOrAbortController } : optionsOrAbortController ?? {};
389
+ const mux = new StreamMux();
390
+ const lifecycleTransformer = createLifecycleTransformer();
391
+ const lifecycleProjection = lifecycleTransformer.init();
392
+ const lifecycleLog = lifecycleProjection._lifecycleLog;
393
+ const subgraphDiscoveryTransformer = createSubgraphDiscoveryTransformer(mux, { createStream: (path, discoveryStart, eventStart) => {
394
+ const sub = new SubgraphRunStream(path, mux, discoveryStart, eventStart);
395
+ sub[SET_SUBGRAPHS_ITERABLE](filterSubgraphHandles(mux._discoveries, path, discoveryStart));
396
+ sub[SET_LIFECYCLE_ITERABLE](filterLifecycleEntries(lifecycleLog, path, lifecycleLog.size));
397
+ return sub;
398
+ } });
399
+ const subgraphsProjection = subgraphDiscoveryTransformer.init();
400
+ mux.addTransformer(subgraphDiscoveryTransformer);
401
+ mux.addTransformer(lifecycleTransformer);
402
+ const valuesTransformer = createValuesTransformer([]);
403
+ const messagesTransformer = createMessagesTransformer([]);
404
+ mux.addTransformer(valuesTransformer);
405
+ mux.addTransformer(messagesTransformer);
406
+ const extensions = {};
407
+ const nativeProjections = [];
408
+ for (const factory of transformers) {
409
+ const transformer = factory();
410
+ mux.addTransformer(transformer);
411
+ const projection = transformer.init();
412
+ if (isNativeTransformer(transformer)) nativeProjections.push(projection);
413
+ else Object.assign(extensions, projection);
414
+ if (typeof projection === "object" && projection !== null && !isNativeTransformer(transformer)) mux.wireChannels(projection);
415
+ }
416
+ const root = new GraphRunStream([], mux, 0, 0, extensions, abortController);
417
+ /**
418
+ * Assign native transformer projections to the root stream.
419
+ */
420
+ for (const proj of nativeProjections) Object.assign(root, proj);
421
+ const valuesProjection = valuesTransformer.init();
422
+ root[SET_VALUES_LOG](valuesProjection._valuesLog);
423
+ const messagesProjection = messagesTransformer.init();
424
+ root[SET_MESSAGES_ITERABLE](messagesProjection.messages);
425
+ root[SET_LIFECYCLE_ITERABLE](lifecycleProjection.lifecycle);
426
+ root[SET_SUBGRAPHS_ITERABLE](subgraphsProjection.subgraphs);
427
+ mux.register([], root);
428
+ pump(source, mux).catch((err) => {});
429
+ return root;
430
+ }
431
+ //#endregion
432
+ export { GraphRunStream, SET_LIFECYCLE_ITERABLE, SET_MESSAGES_ITERABLE, SET_VALUES_LOG, SubgraphRunStream, createGraphRunStream };
433
+
434
+ //# sourceMappingURL=run-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-stream.js","names":["#valuesDone","#discoveryStart","#eventStart","#abortController","#resolveValuesFn","#rejectValuesFn","#subgraphsIterable","#valuesLog","#messagesIterable","#lifecycleIterable"],"sources":["../../src/stream/run-stream.ts"],"sourcesContent":["/**\n * GraphRunStream and SubgraphRunStream — the public run stream classes.\n *\n * Built-in projections:\n * .subgraphs — recursive child subgraph discovery\n * .values — state snapshots (AsyncIterable & PromiseLike)\n * .messages — per-message ChatModelStream lifecycle\n * .messagesFrom — node-filtered messages\n * .output — final state Promise\n * .interrupted — whether the run ended due to an interrupt\n * .interrupts — interrupt payloads\n * .abort() — programmatic cancellation\n * .extensions — merged transformer projections\n *\n * Internal LangChain products (ReactAgent, DeepAgent) can subclass\n * GraphRunStream to add native projections (e.g. `run.toolCalls`,\n * `run.subagents`). See docs/native-stream-transformers.md for the\n * pattern.\n */\n\nimport type { StreamChunk } from \"../pregel/stream.js\";\nimport {\n createLifecycleTransformer,\n createMessagesTransformer,\n createSubgraphDiscoveryTransformer,\n createValuesTransformer,\n filterLifecycleEntries,\n filterSubgraphHandles,\n type LifecycleEntry,\n} from \"./transformers/index.js\";\nimport { StreamMux, pump, RESOLVE_VALUES, REJECT_VALUES } from \"./mux.js\";\nimport {\n isNativeTransformer,\n type ChatModelStreamHandle,\n type InferExtensions,\n type InterruptPayload,\n type Namespace,\n type ProtocolEvent,\n type StreamTransformer,\n} from \"./types.js\";\nimport type { StreamChannel } from \"./stream-channel.js\";\n\n/**\n * Symbol key for attaching the values log to a stream handle.\n * Using a symbol keeps this off the public autocomplete surface.\n */\nexport const SET_VALUES_LOG: unique symbol = Symbol(\"setValuesLog\");\n\n/**\n * Symbol key for attaching the messages iterable to a stream handle.\n * Using a symbol keeps this off the public autocomplete surface.\n */\nexport const SET_MESSAGES_ITERABLE: unique symbol = Symbol(\n \"setMessagesIterable\"\n);\n\n/**\n * Symbol key for attaching the lifecycle iterable to a stream handle.\n * Using a symbol keeps this off the public autocomplete surface.\n */\nexport const SET_LIFECYCLE_ITERABLE: unique symbol = Symbol(\n \"setLifecycleIterable\"\n);\n\n/**\n * Symbol key for attaching the subgraphs iterable to a stream handle.\n * Using a symbol keeps this off the public autocomplete surface.\n */\nexport const SET_SUBGRAPHS_ITERABLE: unique symbol = Symbol(\n \"setSubgraphsIterable\"\n);\n\n/**\n * Shared empty async iterable, returned from getters that haven't\n * been wired by {@link createGraphRunStream}. Avoids allocating a\n * fresh empty iterable on every access.\n */\nconst EMPTY_ASYNC_ITERABLE: AsyncIterable<never> = {\n [Symbol.asyncIterator](): AsyncIterator<never> {\n return {\n next: () =>\n Promise.resolve({\n value: undefined as never,\n done: true,\n }),\n };\n },\n};\n\n/**\n * Primary run stream for a LangGraph execution.\n *\n * Implements {@link AsyncIterable} over {@link ProtocolEvent} and exposes\n * ergonomic projections for values, messages, subgraphs, output, and\n * interrupts. Created by {@link createGraphRunStream}.\n *\n * @typeParam TValues - Shape of the graph's state values.\n * @typeParam TExtensions - Shape of additional transformer projections merged\n * into {@link GraphRunStream.extensions}.\n */\nexport class GraphRunStream<\n TValues = Record<string, unknown>,\n TExtensions extends Record<string, unknown> = Record<string, unknown>,\n> implements AsyncIterable<ProtocolEvent> {\n /**\n * Namespace path identifying this stream's position in the agent tree.\n * An empty array for the root stream.\n */\n readonly path: Namespace;\n\n /**\n * Merged projections from user-supplied {@link StreamTransformer} factories.\n * Each transformer's `init()` return value is spread into this object.\n */\n readonly extensions: TExtensions;\n\n /**\n * The central stream multiplexer that drives event dispatch and transformer\n * pipelines. Accessible to subclasses for direct event subscription.\n *\n * @internal\n */\n protected readonly _mux: StreamMux;\n\n #eventStart: number;\n #discoveryStart: number;\n #abortController: AbortController;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n #resolveValuesFn?: (v: any) => void;\n #rejectValuesFn?: (e: unknown) => void;\n readonly #valuesDone: Promise<TValues>;\n\n #valuesLog?: StreamChannel<Record<string, unknown>>;\n #messagesIterable?: AsyncIterable<ChatModelStreamHandle>;\n #lifecycleIterable?: AsyncIterable<LifecycleEntry>;\n #subgraphsIterable?: AsyncIterable<SubgraphRunStream>;\n\n /**\n * @param path - Namespace path for this stream (empty array for root).\n * @param mux - The {@link StreamMux} driving this run.\n * @param discoveryStart - Cursor offset into the mux discovery log.\n * @param eventStart - Cursor offset into the mux event log.\n * @param extensions - Pre-initialized transformer projections.\n * @param abortController - Controller for programmatic cancellation.\n */\n constructor(\n path: Namespace,\n mux: StreamMux,\n discoveryStart = 0,\n eventStart = 0,\n extensions?: TExtensions,\n abortController?: AbortController\n ) {\n this.path = path;\n this._mux = mux;\n this.#discoveryStart = discoveryStart;\n this.#eventStart = eventStart;\n this.extensions = extensions ?? ({} as TExtensions);\n this.#abortController = abortController ?? new AbortController();\n this.#valuesDone = new Promise<TValues>((resolve, reject) => {\n this.#resolveValuesFn = resolve;\n this.#rejectValuesFn = reject;\n });\n this.#valuesDone.catch(() => {\n // Keep run failures observable to explicit `await run.output` callers\n // without reporting unhandled rejections when consumers only iterate\n // protocol events.\n });\n }\n\n /**\n * Async iterator over all {@link ProtocolEvent}s at or below this\n * stream's namespace, starting from the configured event offset.\n *\n * @returns An async iterator yielding protocol events in arrival order.\n */\n [Symbol.asyncIterator](): AsyncIterator<ProtocolEvent> {\n return this._mux.subscribeEvents(this.path, this.#eventStart);\n }\n\n /**\n * Async iterable of child {@link SubgraphRunStream} instances discovered\n * during the run. Each yielded stream represents a direct child namespace.\n *\n * Backed by the shared `_discoveries` log on the mux, populated by\n * {@link createSubgraphDiscoveryTransformer}. For streams created\n * through {@link createGraphRunStream} the iterable is pre-wired\n * (via {@link SET_SUBGRAPHS_ITERABLE}) so iteration is cheap.\n * Streams constructed directly (e.g. in unit tests) fall back to\n * filtering `_mux._discoveries` on demand, preserving the original\n * behavior without requiring explicit wiring.\n *\n * @returns An async iterable of subgraph run streams.\n */\n get subgraphs(): AsyncIterable<SubgraphRunStream> {\n if (this.#subgraphsIterable) return this.#subgraphsIterable;\n return filterSubgraphHandles<SubgraphRunStream>(\n this._mux._discoveries,\n this.path,\n this.#discoveryStart\n );\n }\n\n /**\n * Dual-interface accessor for graph state snapshots.\n *\n * As an {@link AsyncIterable}, yields each intermediate state snapshot\n * as it arrives. As a {@link PromiseLike}, resolves with the final\n * state value when the run completes.\n *\n * @returns A combined async iterable and promise-like for state values.\n */\n get values(): AsyncIterable<TValues> & PromiseLike<TValues> {\n const log = this.#valuesLog;\n const done = this.#valuesDone;\n const mux = this._mux;\n const eventStart = this.#eventStart;\n const path = this.path;\n\n const iterable: AsyncIterable<TValues> = log\n ? (log.toAsyncIterable() as AsyncIterable<TValues>)\n : {\n [Symbol.asyncIterator]: () => {\n const base = mux.subscribeEvents(path, eventStart);\n return {\n async next(): Promise<IteratorResult<TValues>> {\n // eslint-disable-next-line no-constant-condition\n while (true) {\n const result = await base.next();\n if (result.done) {\n return {\n value: undefined as unknown as TValues,\n done: true,\n };\n }\n if (\n result.value.method === \"values\" &&\n result.value.params.namespace.length === path.length\n ) {\n return {\n value: result.value.params.data as TValues,\n done: false,\n };\n }\n }\n },\n };\n },\n };\n\n return {\n [Symbol.asyncIterator]: () => iterable[Symbol.asyncIterator](),\n then: done.then.bind(done),\n };\n }\n\n /**\n * All AI message lifecycles observed at this namespace level, in order.\n * Each yielded {@link ChatModelStream} represents one message-start →\n * message-finish lifecycle with streaming `.text`, `.reasoning`, and\n * `.usage` projections.\n *\n * @returns An async iterable of chat model streams.\n */\n get messages(): AsyncIterable<ChatModelStreamHandle> {\n if (this.#messagesIterable) return this.#messagesIterable;\n // Lazily create a messages transformer scoped to this stream's path.\n // This handles SubgraphRunStream instances that are created\n // dynamically by StreamMux and don't have a transformer pre-wired.\n // Uses addTransformer (which replays buffered events) so that\n // messages emitted before the getter is first accessed are not lost.\n const transformer = createMessagesTransformer(this.path);\n const projection = transformer.init();\n this._mux.addTransformer(transformer);\n this.#messagesIterable = projection.messages;\n return this.#messagesIterable;\n }\n\n /**\n * Sequence of {@link LifecycleEntry} records tracking the\n * `lifecycle` channel: when the run starts, when each subgraph\n * enters/exits, and the terminal status of the run as a whole.\n *\n * Backed by the built-in {@link createLifecycleTransformer}; the\n * root stream's iterable is wired during\n * {@link createGraphRunStream} setup, and each\n * {@link SubgraphRunStream} is wired in the subgraph discovery\n * factory with a subtree-scoped view (via\n * {@link filterLifecycleEntries}). Streams constructed outside\n * `createGraphRunStream` and not wired will yield nothing.\n *\n * @returns An async iterable of lifecycle entries in emission order.\n */\n get lifecycle(): AsyncIterable<LifecycleEntry> {\n return this.#lifecycleIterable ?? EMPTY_ASYNC_ITERABLE;\n }\n\n /**\n * Messages produced by a specific graph node. Use when the run has\n * multiple model-calling nodes and you only want messages from one.\n *\n * @param node - The graph node name to filter messages by.\n * @returns An async iterable of chat model streams from the given node.\n */\n messagesFrom(node: string): AsyncIterable<ChatModelStreamHandle> {\n const transformer = createMessagesTransformer(this.path, node);\n const projection = transformer.init();\n this._mux.addTransformer(transformer);\n return projection.messages;\n }\n\n /**\n * Promise that resolves with the final graph state when the run completes,\n * or rejects if the run fails.\n *\n * @returns A promise resolving to the final state values.\n */\n get output(): Promise<TValues> {\n return this.#valuesDone;\n }\n\n /**\n * Whether the run ended due to a human-in-the-loop interrupt.\n *\n * @returns `true` if the run was interrupted.\n */\n get interrupted(): boolean {\n return this._mux.interrupted;\n }\n\n /**\n * Interrupt payloads collected during the run, if any.\n *\n * @returns A readonly array of interrupt payloads.\n */\n get interrupts(): readonly InterruptPayload[] {\n return this._mux.interrupts;\n }\n\n /**\n * Programmatically abort this run. Equivalent to calling\n * `signal.abort(reason)`.\n *\n * @param reason - Optional abort reason passed to the signal.\n */\n abort(reason?: unknown): void {\n this.#abortController.abort(reason);\n }\n\n /**\n * The {@link AbortSignal} wired into this run for cancellation support.\n *\n * @returns The abort signal for this stream.\n */\n get signal(): AbortSignal {\n return this.#abortController.signal;\n }\n\n /**\n * Resolve the output/values promise with the final state snapshot.\n * Called by {@link StreamMux.close}.\n *\n * @param values - The final state values, or `undefined` if none.\n * @internal\n */\n [RESOLVE_VALUES](values: TValues | undefined): void {\n this.#resolveValuesFn?.(values as TValues);\n this.#resolveValuesFn = undefined;\n }\n\n /**\n * Reject the output/values promise with a run error.\n * Called by {@link StreamMux.fail}.\n *\n * @param err - The error that caused the run to fail.\n * @internal\n */\n [REJECT_VALUES](err: unknown): void {\n this.#rejectValuesFn?.(err);\n this.#rejectValuesFn = undefined;\n }\n\n /**\n * Attach the transformer-populated event log backing the `.values` iterable.\n * Called during stream setup in {@link createGraphRunStream}.\n *\n * @param log - The event log from the values transformer projection.\n * @internal\n */\n [SET_VALUES_LOG](log: StreamChannel<Record<string, unknown>>): void {\n this.#valuesLog = log;\n }\n\n /**\n * Attach the transformer-populated async iterable backing the `.messages`\n * accessor. Called during stream setup in {@link createGraphRunStream}.\n *\n * @param iterable - The async iterable from the messages transformer projection.\n * @internal\n */\n [SET_MESSAGES_ITERABLE](\n iterable: AsyncIterable<ChatModelStreamHandle>\n ): void {\n this.#messagesIterable = iterable;\n }\n\n /**\n * Attach the transformer-populated async iterable backing the\n * `.lifecycle` accessor. Called during stream setup in\n * {@link createGraphRunStream}.\n *\n * @param iterable - The async iterable from the lifecycle transformer projection.\n * @internal\n */\n [SET_LIFECYCLE_ITERABLE](iterable: AsyncIterable<LifecycleEntry>): void {\n this.#lifecycleIterable = iterable;\n }\n\n /**\n * Attach the transformer-populated async iterable backing the\n * `.subgraphs` accessor. Called during root stream setup in\n * {@link createGraphRunStream} and during child stream\n * construction in the discovery transformer factory.\n *\n * @param iterable - The async iterable of direct-child stream handles.\n * @internal\n */\n [SET_SUBGRAPHS_ITERABLE](iterable: AsyncIterable<SubgraphRunStream>): void {\n this.#subgraphsIterable = iterable;\n }\n}\n\n/**\n * A run stream for a child subgraph within a parent graph execution.\n *\n * Extends {@link GraphRunStream} with a parsed {@link name} and\n * {@link index} extracted from the last segment of the namespace path.\n * The segment is expected to follow the `\"name:index\"` convention;\n * when no numeric suffix is present, {@link index} defaults to `0`.\n *\n * @typeParam TValues - Shape of the subgraph's state values.\n * @typeParam TExtensions - Shape of additional transformer projections.\n */\nexport class SubgraphRunStream<\n TValues = Record<string, unknown>,\n TExtensions extends Record<string, unknown> = Record<string, unknown>,\n> extends GraphRunStream<TValues, TExtensions> {\n /**\n * The node name extracted from the last segment of the namespace path\n * (everything before the final colon, or the full segment if no colon).\n */\n readonly name: string;\n\n /**\n * The invocation index parsed from the `\"name:N\"` suffix of the last\n * namespace segment. Defaults to `0` when no numeric suffix is present.\n */\n readonly index: number;\n\n /**\n * @param path - Namespace path for this subgraph stream.\n * @param mux - The {@link StreamMux} driving this run.\n * @param discoveryStart - Cursor offset into the mux discovery log.\n * @param eventStart - Cursor offset into the mux event log.\n * @param extensions - Pre-initialized transformer projections.\n * @param abortController - Controller for programmatic cancellation.\n */\n constructor(\n path: Namespace,\n mux: StreamMux,\n discoveryStart = 0,\n eventStart = 0,\n extensions?: TExtensions,\n abortController?: AbortController\n ) {\n super(path, mux, discoveryStart, eventStart, extensions, abortController);\n const lastSegment = path[path.length - 1] ?? \"\";\n const colonIdx = lastSegment.lastIndexOf(\":\");\n if (colonIdx >= 0) {\n this.name = lastSegment.slice(0, colonIdx);\n const suffix = lastSegment.slice(colonIdx + 1);\n this.index = /^\\d+$/.test(suffix) ? Number(suffix) : 0;\n } else {\n this.name = lastSegment;\n this.index = 0;\n }\n }\n}\n\n/**\n * Options accepted by {@link createGraphRunStream}.\n */\nexport interface CreateGraphRunStreamOptions {\n /**\n * Optional abort controller shared with the outer run; if omitted, a\n * fresh controller is allocated for the returned stream.\n */\n abortController?: AbortController;\n}\n\n/**\n * Creates a {@link GraphRunStream} with built-in transformers and kicks off the\n * background pump that feeds raw stream chunks through the transformer pipeline.\n *\n * Built-in transformers are registered in this order:\n * 1. subgraph discovery — materializes SubgraphRunStream handles\n * for each newly observed top-level namespace and announces them\n * on the mux `_discoveries` log.\n * 2. lifecycle — synthesizes `lifecycle` channel events.\n * 3. values — powers `run.values` / `run.output`.\n * 4. messages — powers `run.messages` / `.messagesFrom`.\n *\n * Subgraph discovery is registered first so that downstream\n * transformers (notably lifecycle) observe child namespaces with\n * their stream handles already in place. User-supplied transformer\n * factories are registered afterwards.\n *\n * @typeParam TValues - Shape of the graph's state values.\n * @param source - Raw async iterable from `graph.stream(…, { subgraphs: true })`.\n * @param transformers - User-supplied transformer factories.\n * @param optionsOrAbortController - Either a full\n * {@link CreateGraphRunStreamOptions} object or (for backward\n * compatibility) a bare `AbortController`.\n * @returns A {@link GraphRunStream} for the root namespace.\n */\nexport function createGraphRunStream<\n TValues = Record<string, unknown>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const TTransformers extends ReadonlyArray<() => StreamTransformer<any>> = [],\n>(\n source: AsyncIterable<StreamChunk>,\n transformers: TTransformers = [] as unknown as TTransformers,\n optionsOrAbortController?: CreateGraphRunStreamOptions | AbortController\n): GraphRunStream<TValues, InferExtensions<TTransformers>> {\n const options: CreateGraphRunStreamOptions =\n // oxlint-disable-next-line no-instanceof/no-instanceof\n optionsOrAbortController instanceof AbortController\n ? { abortController: optionsOrAbortController }\n : (optionsOrAbortController ?? {});\n const { abortController } = options;\n\n const mux = new StreamMux();\n\n // Init lifecycle first so the subgraph discovery factory can close\n // over its log to wire each new child's `.lifecycle` view.\n const lifecycleTransformer = createLifecycleTransformer();\n const lifecycleProjection = lifecycleTransformer.init();\n const lifecycleLog = lifecycleProjection._lifecycleLog;\n\n const subgraphDiscoveryTransformer =\n createSubgraphDiscoveryTransformer<SubgraphRunStream>(mux, {\n createStream: (path, discoveryStart, eventStart) => {\n const sub = new SubgraphRunStream(\n path,\n mux,\n discoveryStart,\n eventStart\n );\n // Wire the child's `.subgraphs` to the shared discoveries log,\n // scoped to the child's path and its construction-time offset.\n sub[SET_SUBGRAPHS_ITERABLE](\n filterSubgraphHandles<SubgraphRunStream>(\n mux._discoveries,\n path,\n discoveryStart\n )\n );\n // Wire the child's `.lifecycle` to the shared lifecycle log,\n // filtered to its subtree. Capture the current log size so\n // entries emitted before discovery (e.g. root's `started`)\n // aren't replayed to the child. Entries emitted for this\n // discovery event itself land after the factory returns (the\n // subgraph transformer runs before the lifecycle transformer),\n // so the child still receives its own `started`.\n sub[SET_LIFECYCLE_ITERABLE](\n filterLifecycleEntries(lifecycleLog, path, lifecycleLog.size)\n );\n return sub;\n },\n });\n const subgraphsProjection = subgraphDiscoveryTransformer.init();\n\n // Registration order matters: subgraph discovery runs first so that\n // lifecycle and downstream transformers see child stream handles\n // already materialized.\n mux.addTransformer(subgraphDiscoveryTransformer);\n mux.addTransformer(lifecycleTransformer);\n\n const valuesTransformer = createValuesTransformer([]);\n const messagesTransformer = createMessagesTransformer([]);\n mux.addTransformer(valuesTransformer);\n mux.addTransformer(messagesTransformer);\n\n const extensions: Record<string, unknown> = {};\n const nativeProjections: Record<string, unknown>[] = [];\n for (const factory of transformers) {\n const transformer = factory();\n mux.addTransformer(transformer);\n const projection = transformer.init();\n if (isNativeTransformer(transformer)) {\n nativeProjections.push(projection);\n } else {\n Object.assign(extensions, projection);\n }\n // Only wire channels for extension transformers. Native transformers\n // produce non-serializable projections (Promises, AsyncIterables) that\n // must stay in-process — wiring them would inject garbage into the\n // protocol event stream.\n if (\n typeof projection === \"object\" &&\n projection !== null &&\n !isNativeTransformer(transformer)\n ) {\n mux.wireChannels(projection as Record<string, unknown>);\n }\n }\n\n const root = new GraphRunStream<TValues, InferExtensions<TTransformers>>(\n [],\n mux,\n 0,\n 0,\n extensions as InferExtensions<TTransformers>,\n abortController\n );\n\n /**\n * Assign native transformer projections to the root stream.\n */\n for (const proj of nativeProjections) {\n Object.assign(root, proj);\n }\n\n // Wire transformer projections into the root stream.\n const valuesProjection = valuesTransformer.init();\n root[SET_VALUES_LOG](valuesProjection._valuesLog);\n\n const messagesProjection = messagesTransformer.init();\n root[SET_MESSAGES_ITERABLE](messagesProjection.messages);\n root[SET_LIFECYCLE_ITERABLE](lifecycleProjection.lifecycle);\n root[SET_SUBGRAPHS_ITERABLE](subgraphsProjection.subgraphs);\n\n mux.register([], root);\n\n // Start background pump.\n pump(source, mux).catch((err) => {\n void err;\n });\n\n return root;\n}\n"],"mappings":";;;;;;;;;;;;AA8CA,MAAa,iBAAgC,OAAO,eAAe;;;;;AAMnE,MAAa,wBAAuC,OAClD,sBACD;;;;;AAMD,MAAa,yBAAwC,OACnD,uBACD;;;;;AAMD,MAAa,yBAAwC,OACnD,uBACD;;;;;;AAOD,MAAM,uBAA6C,EACjD,CAAC,OAAO,iBAAuC;AAC7C,QAAO,EACL,YACE,QAAQ,QAAQ;EACd,OAAO,KAAA;EACP,MAAM;EACP,CAAC,EACL;GAEJ;;;;;;;;;;;;AAaD,IAAa,iBAAb,MAG0C;;;;;CAKxC;;;;;CAMA;;;;;;;CAQA;CAEA;CACA;CACA;CAGA;CACA;CACA;CAEA;CACA;CACA;CACA;;;;;;;;;CAUA,YACE,MACA,KACA,iBAAiB,GACjB,aAAa,GACb,YACA,iBACA;AACA,OAAK,OAAO;AACZ,O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