@langchain/langgraph 1.2.8 → 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 (166) 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 +3 -3
  10. package/dist/graph/state.cjs +3 -2
  11. package/dist/graph/state.cjs.map +1 -1
  12. package/dist/graph/state.d.cts +14 -6
  13. package/dist/graph/state.d.cts.map +1 -1
  14. package/dist/graph/state.d.ts +14 -6
  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 +16 -6
  21. package/dist/index.d.ts +16 -6
  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/algo.cjs +6 -3
  27. package/dist/pregel/algo.cjs.map +1 -1
  28. package/dist/pregel/algo.js +6 -3
  29. package/dist/pregel/algo.js.map +1 -1
  30. package/dist/pregel/index.cjs +96 -25
  31. package/dist/pregel/index.cjs.map +1 -1
  32. package/dist/pregel/index.d.cts +25 -3
  33. package/dist/pregel/index.d.cts.map +1 -1
  34. package/dist/pregel/index.d.ts +25 -3
  35. package/dist/pregel/index.d.ts.map +1 -1
  36. package/dist/pregel/index.js +97 -26
  37. package/dist/pregel/index.js.map +1 -1
  38. package/dist/pregel/loop.cjs +51 -10
  39. package/dist/pregel/loop.cjs.map +1 -1
  40. package/dist/pregel/loop.js +51 -10
  41. package/dist/pregel/loop.js.map +1 -1
  42. package/dist/pregel/messages-v2.cjs +231 -0
  43. package/dist/pregel/messages-v2.cjs.map +1 -0
  44. package/dist/pregel/messages-v2.js +231 -0
  45. package/dist/pregel/messages-v2.js.map +1 -0
  46. package/dist/pregel/messages.cjs +14 -10
  47. package/dist/pregel/messages.cjs.map +1 -1
  48. package/dist/pregel/messages.js +14 -10
  49. package/dist/pregel/messages.js.map +1 -1
  50. package/dist/pregel/remote.cjs +15 -0
  51. package/dist/pregel/remote.cjs.map +1 -1
  52. package/dist/pregel/remote.d.cts.map +1 -1
  53. package/dist/pregel/remote.d.ts.map +1 -1
  54. package/dist/pregel/remote.js +15 -0
  55. package/dist/pregel/remote.js.map +1 -1
  56. package/dist/pregel/stream.cjs.map +1 -1
  57. package/dist/pregel/stream.d.cts +30 -0
  58. package/dist/pregel/stream.d.cts.map +1 -0
  59. package/dist/pregel/stream.d.ts +30 -1
  60. package/dist/pregel/stream.d.ts.map +1 -0
  61. package/dist/pregel/stream.js.map +1 -1
  62. package/dist/pregel/types.cjs.map +1 -1
  63. package/dist/pregel/types.d.cts +8 -1
  64. package/dist/pregel/types.d.cts.map +1 -1
  65. package/dist/pregel/types.d.ts +8 -1
  66. package/dist/pregel/types.d.ts.map +1 -1
  67. package/dist/pregel/types.js.map +1 -1
  68. package/dist/pregel/utils/config.cjs +21 -4
  69. package/dist/pregel/utils/config.cjs.map +1 -1
  70. package/dist/pregel/utils/config.d.cts.map +1 -1
  71. package/dist/pregel/utils/config.d.ts.map +1 -1
  72. package/dist/pregel/utils/config.js +21 -5
  73. package/dist/pregel/utils/config.js.map +1 -1
  74. package/dist/pregel/utils/index.d.ts +0 -1
  75. package/dist/pregel/utils/index.d.ts.map +1 -1
  76. package/dist/state/index.d.ts +1 -1
  77. package/dist/state/schema.d.cts +1 -1
  78. package/dist/state/schema.d.ts +1 -1
  79. package/dist/stream/convert.cjs +207 -0
  80. package/dist/stream/convert.cjs.map +1 -0
  81. package/dist/stream/convert.d.cts +69 -0
  82. package/dist/stream/convert.d.cts.map +1 -0
  83. package/dist/stream/convert.d.ts +69 -0
  84. package/dist/stream/convert.d.ts.map +1 -0
  85. package/dist/stream/convert.js +206 -0
  86. package/dist/stream/convert.js.map +1 -0
  87. package/dist/stream/index.cjs +11 -0
  88. package/dist/stream/index.d.cts +12 -0
  89. package/dist/stream/index.d.ts +12 -0
  90. package/dist/stream/index.js +12 -0
  91. package/dist/stream/mux.cjs +350 -0
  92. package/dist/stream/mux.cjs.map +1 -0
  93. package/dist/stream/mux.d.cts +160 -0
  94. package/dist/stream/mux.d.cts.map +1 -0
  95. package/dist/stream/mux.d.ts +160 -0
  96. package/dist/stream/mux.d.ts.map +1 -0
  97. package/dist/stream/mux.js +345 -0
  98. package/dist/stream/mux.js.map +1 -0
  99. package/dist/stream/run-stream.cjs +439 -0
  100. package/dist/stream/run-stream.cjs.map +1 -0
  101. package/dist/stream/run-stream.d.cts +286 -0
  102. package/dist/stream/run-stream.d.cts.map +1 -0
  103. package/dist/stream/run-stream.d.ts +285 -0
  104. package/dist/stream/run-stream.d.ts.map +1 -0
  105. package/dist/stream/run-stream.js +434 -0
  106. package/dist/stream/run-stream.js.map +1 -0
  107. package/dist/stream/stream-channel.cjs +208 -0
  108. package/dist/stream/stream-channel.cjs.map +1 -0
  109. package/dist/stream/stream-channel.d.cts +129 -0
  110. package/dist/stream/stream-channel.d.cts.map +1 -0
  111. package/dist/stream/stream-channel.d.ts +129 -0
  112. package/dist/stream/stream-channel.d.ts.map +1 -0
  113. package/dist/stream/stream-channel.js +207 -0
  114. package/dist/stream/stream-channel.js.map +1 -0
  115. package/dist/stream/transformers/index.cjs +4 -0
  116. package/dist/stream/transformers/index.d.ts +5 -0
  117. package/dist/stream/transformers/index.js +5 -0
  118. package/dist/stream/transformers/lifecycle.cjs +326 -0
  119. package/dist/stream/transformers/lifecycle.cjs.map +1 -0
  120. package/dist/stream/transformers/lifecycle.d.cts +53 -0
  121. package/dist/stream/transformers/lifecycle.d.cts.map +1 -0
  122. package/dist/stream/transformers/lifecycle.d.ts +53 -0
  123. package/dist/stream/transformers/lifecycle.d.ts.map +1 -0
  124. package/dist/stream/transformers/lifecycle.js +325 -0
  125. package/dist/stream/transformers/lifecycle.js.map +1 -0
  126. package/dist/stream/transformers/messages.cjs +94 -0
  127. package/dist/stream/transformers/messages.cjs.map +1 -0
  128. package/dist/stream/transformers/messages.d.cts +23 -0
  129. package/dist/stream/transformers/messages.d.cts.map +1 -0
  130. package/dist/stream/transformers/messages.d.ts +23 -0
  131. package/dist/stream/transformers/messages.d.ts.map +1 -0
  132. package/dist/stream/transformers/messages.js +94 -0
  133. package/dist/stream/transformers/messages.js.map +1 -0
  134. package/dist/stream/transformers/subgraphs.cjs +125 -0
  135. package/dist/stream/transformers/subgraphs.cjs.map +1 -0
  136. package/dist/stream/transformers/subgraphs.d.cts +95 -0
  137. package/dist/stream/transformers/subgraphs.d.cts.map +1 -0
  138. package/dist/stream/transformers/subgraphs.d.ts +95 -0
  139. package/dist/stream/transformers/subgraphs.d.ts.map +1 -0
  140. package/dist/stream/transformers/subgraphs.js +124 -0
  141. package/dist/stream/transformers/subgraphs.js.map +1 -0
  142. package/dist/stream/transformers/types.d.cts +89 -0
  143. package/dist/stream/transformers/types.d.cts.map +1 -0
  144. package/dist/stream/transformers/types.d.ts +89 -0
  145. package/dist/stream/transformers/types.d.ts.map +1 -0
  146. package/dist/stream/transformers/values.cjs +39 -0
  147. package/dist/stream/transformers/values.cjs.map +1 -0
  148. package/dist/stream/transformers/values.d.cts +21 -0
  149. package/dist/stream/transformers/values.d.cts.map +1 -0
  150. package/dist/stream/transformers/values.d.ts +21 -0
  151. package/dist/stream/transformers/values.d.ts.map +1 -0
  152. package/dist/stream/transformers/values.js +39 -0
  153. package/dist/stream/transformers/values.js.map +1 -0
  154. package/dist/stream/types.cjs +11 -0
  155. package/dist/stream/types.cjs.map +1 -0
  156. package/dist/stream/types.d.cts +255 -0
  157. package/dist/stream/types.d.cts.map +1 -0
  158. package/dist/stream/types.d.ts +255 -0
  159. package/dist/stream/types.d.ts.map +1 -0
  160. package/dist/stream/types.js +11 -0
  161. package/dist/stream/types.js.map +1 -0
  162. package/dist/web.cjs +39 -9
  163. package/dist/web.d.cts +16 -6
  164. package/dist/web.d.ts +16 -6
  165. package/dist/web.js +10 -1
  166. package/package.json +9 -8
@@ -0,0 +1,286 @@
1
+ import { ChatModelStreamHandle, InferExtensions, InterruptPayload, Namespace, ProtocolEvent, StreamTransformer } from "./types.cjs";
2
+ import { StreamChunk } from "../pregel/stream.cjs";
3
+ import { StreamChannel } from "./stream-channel.cjs";
4
+ import { REJECT_VALUES, RESOLVE_VALUES, StreamMux } from "./mux.cjs";
5
+ import { LifecycleEntry } from "./transformers/types.cjs";
6
+
7
+ //#region src/stream/run-stream.d.ts
8
+ /**
9
+ * Symbol key for attaching the values log to a stream handle.
10
+ * Using a symbol keeps this off the public autocomplete surface.
11
+ */
12
+ declare const SET_VALUES_LOG: unique symbol;
13
+ /**
14
+ * Symbol key for attaching the messages iterable to a stream handle.
15
+ * Using a symbol keeps this off the public autocomplete surface.
16
+ */
17
+ declare const SET_MESSAGES_ITERABLE: unique symbol;
18
+ /**
19
+ * Symbol key for attaching the lifecycle iterable to a stream handle.
20
+ * Using a symbol keeps this off the public autocomplete surface.
21
+ */
22
+ declare const SET_LIFECYCLE_ITERABLE: unique symbol;
23
+ /**
24
+ * Symbol key for attaching the subgraphs iterable to a stream handle.
25
+ * Using a symbol keeps this off the public autocomplete surface.
26
+ */
27
+ declare const SET_SUBGRAPHS_ITERABLE: unique symbol;
28
+ /**
29
+ * Primary run stream for a LangGraph execution.
30
+ *
31
+ * Implements {@link AsyncIterable} over {@link ProtocolEvent} and exposes
32
+ * ergonomic projections for values, messages, subgraphs, output, and
33
+ * interrupts. Created by {@link createGraphRunStream}.
34
+ *
35
+ * @typeParam TValues - Shape of the graph's state values.
36
+ * @typeParam TExtensions - Shape of additional transformer projections merged
37
+ * into {@link GraphRunStream.extensions}.
38
+ */
39
+ declare class GraphRunStream<TValues = Record<string, unknown>, TExtensions extends Record<string, unknown> = Record<string, unknown>> implements AsyncIterable<ProtocolEvent> {
40
+ #private;
41
+ /**
42
+ * Namespace path identifying this stream's position in the agent tree.
43
+ * An empty array for the root stream.
44
+ */
45
+ readonly path: Namespace;
46
+ /**
47
+ * Merged projections from user-supplied {@link StreamTransformer} factories.
48
+ * Each transformer's `init()` return value is spread into this object.
49
+ */
50
+ readonly extensions: TExtensions;
51
+ /**
52
+ * The central stream multiplexer that drives event dispatch and transformer
53
+ * pipelines. Accessible to subclasses for direct event subscription.
54
+ *
55
+ * @internal
56
+ */
57
+ protected readonly _mux: StreamMux;
58
+ /**
59
+ * @param path - Namespace path for this stream (empty array for root).
60
+ * @param mux - The {@link StreamMux} driving this run.
61
+ * @param discoveryStart - Cursor offset into the mux discovery log.
62
+ * @param eventStart - Cursor offset into the mux event log.
63
+ * @param extensions - Pre-initialized transformer projections.
64
+ * @param abortController - Controller for programmatic cancellation.
65
+ */
66
+ constructor(path: Namespace, mux: StreamMux, discoveryStart?: number, eventStart?: number, extensions?: TExtensions, abortController?: AbortController);
67
+ /**
68
+ * Async iterator over all {@link ProtocolEvent}s at or below this
69
+ * stream's namespace, starting from the configured event offset.
70
+ *
71
+ * @returns An async iterator yielding protocol events in arrival order.
72
+ */
73
+ [Symbol.asyncIterator](): AsyncIterator<ProtocolEvent>;
74
+ /**
75
+ * Async iterable of child {@link SubgraphRunStream} instances discovered
76
+ * during the run. Each yielded stream represents a direct child namespace.
77
+ *
78
+ * Backed by the shared `_discoveries` log on the mux, populated by
79
+ * {@link createSubgraphDiscoveryTransformer}. For streams created
80
+ * through {@link createGraphRunStream} the iterable is pre-wired
81
+ * (via {@link SET_SUBGRAPHS_ITERABLE}) so iteration is cheap.
82
+ * Streams constructed directly (e.g. in unit tests) fall back to
83
+ * filtering `_mux._discoveries` on demand, preserving the original
84
+ * behavior without requiring explicit wiring.
85
+ *
86
+ * @returns An async iterable of subgraph run streams.
87
+ */
88
+ get subgraphs(): AsyncIterable<SubgraphRunStream>;
89
+ /**
90
+ * Dual-interface accessor for graph state snapshots.
91
+ *
92
+ * As an {@link AsyncIterable}, yields each intermediate state snapshot
93
+ * as it arrives. As a {@link PromiseLike}, resolves with the final
94
+ * state value when the run completes.
95
+ *
96
+ * @returns A combined async iterable and promise-like for state values.
97
+ */
98
+ get values(): AsyncIterable<TValues> & PromiseLike<TValues>;
99
+ /**
100
+ * All AI message lifecycles observed at this namespace level, in order.
101
+ * Each yielded {@link ChatModelStream} represents one message-start →
102
+ * message-finish lifecycle with streaming `.text`, `.reasoning`, and
103
+ * `.usage` projections.
104
+ *
105
+ * @returns An async iterable of chat model streams.
106
+ */
107
+ get messages(): AsyncIterable<ChatModelStreamHandle>;
108
+ /**
109
+ * Sequence of {@link LifecycleEntry} records tracking the
110
+ * `lifecycle` channel: when the run starts, when each subgraph
111
+ * enters/exits, and the terminal status of the run as a whole.
112
+ *
113
+ * Backed by the built-in {@link createLifecycleTransformer}; the
114
+ * root stream's iterable is wired during
115
+ * {@link createGraphRunStream} setup, and each
116
+ * {@link SubgraphRunStream} is wired in the subgraph discovery
117
+ * factory with a subtree-scoped view (via
118
+ * {@link filterLifecycleEntries}). Streams constructed outside
119
+ * `createGraphRunStream` and not wired will yield nothing.
120
+ *
121
+ * @returns An async iterable of lifecycle entries in emission order.
122
+ */
123
+ get lifecycle(): AsyncIterable<LifecycleEntry>;
124
+ /**
125
+ * Messages produced by a specific graph node. Use when the run has
126
+ * multiple model-calling nodes and you only want messages from one.
127
+ *
128
+ * @param node - The graph node name to filter messages by.
129
+ * @returns An async iterable of chat model streams from the given node.
130
+ */
131
+ messagesFrom(node: string): AsyncIterable<ChatModelStreamHandle>;
132
+ /**
133
+ * Promise that resolves with the final graph state when the run completes,
134
+ * or rejects if the run fails.
135
+ *
136
+ * @returns A promise resolving to the final state values.
137
+ */
138
+ get output(): Promise<TValues>;
139
+ /**
140
+ * Whether the run ended due to a human-in-the-loop interrupt.
141
+ *
142
+ * @returns `true` if the run was interrupted.
143
+ */
144
+ get interrupted(): boolean;
145
+ /**
146
+ * Interrupt payloads collected during the run, if any.
147
+ *
148
+ * @returns A readonly array of interrupt payloads.
149
+ */
150
+ get interrupts(): readonly InterruptPayload[];
151
+ /**
152
+ * Programmatically abort this run. Equivalent to calling
153
+ * `signal.abort(reason)`.
154
+ *
155
+ * @param reason - Optional abort reason passed to the signal.
156
+ */
157
+ abort(reason?: unknown): void;
158
+ /**
159
+ * The {@link AbortSignal} wired into this run for cancellation support.
160
+ *
161
+ * @returns The abort signal for this stream.
162
+ */
163
+ get signal(): AbortSignal;
164
+ /**
165
+ * Resolve the output/values promise with the final state snapshot.
166
+ * Called by {@link StreamMux.close}.
167
+ *
168
+ * @param values - The final state values, or `undefined` if none.
169
+ * @internal
170
+ */
171
+ [RESOLVE_VALUES](values: TValues | undefined): void;
172
+ /**
173
+ * Reject the output/values promise with a run error.
174
+ * Called by {@link StreamMux.fail}.
175
+ *
176
+ * @param err - The error that caused the run to fail.
177
+ * @internal
178
+ */
179
+ [REJECT_VALUES](err: unknown): void;
180
+ /**
181
+ * Attach the transformer-populated event log backing the `.values` iterable.
182
+ * Called during stream setup in {@link createGraphRunStream}.
183
+ *
184
+ * @param log - The event log from the values transformer projection.
185
+ * @internal
186
+ */
187
+ [SET_VALUES_LOG](log: StreamChannel<Record<string, unknown>>): void;
188
+ /**
189
+ * Attach the transformer-populated async iterable backing the `.messages`
190
+ * accessor. Called during stream setup in {@link createGraphRunStream}.
191
+ *
192
+ * @param iterable - The async iterable from the messages transformer projection.
193
+ * @internal
194
+ */
195
+ [SET_MESSAGES_ITERABLE](iterable: AsyncIterable<ChatModelStreamHandle>): void;
196
+ /**
197
+ * Attach the transformer-populated async iterable backing the
198
+ * `.lifecycle` accessor. Called during stream setup in
199
+ * {@link createGraphRunStream}.
200
+ *
201
+ * @param iterable - The async iterable from the lifecycle transformer projection.
202
+ * @internal
203
+ */
204
+ [SET_LIFECYCLE_ITERABLE](iterable: AsyncIterable<LifecycleEntry>): void;
205
+ /**
206
+ * Attach the transformer-populated async iterable backing the
207
+ * `.subgraphs` accessor. Called during root stream setup in
208
+ * {@link createGraphRunStream} and during child stream
209
+ * construction in the discovery transformer factory.
210
+ *
211
+ * @param iterable - The async iterable of direct-child stream handles.
212
+ * @internal
213
+ */
214
+ [SET_SUBGRAPHS_ITERABLE](iterable: AsyncIterable<SubgraphRunStream>): void;
215
+ }
216
+ /**
217
+ * A run stream for a child subgraph within a parent graph execution.
218
+ *
219
+ * Extends {@link GraphRunStream} with a parsed {@link name} and
220
+ * {@link index} extracted from the last segment of the namespace path.
221
+ * The segment is expected to follow the `"name:index"` convention;
222
+ * when no numeric suffix is present, {@link index} defaults to `0`.
223
+ *
224
+ * @typeParam TValues - Shape of the subgraph's state values.
225
+ * @typeParam TExtensions - Shape of additional transformer projections.
226
+ */
227
+ declare class SubgraphRunStream<TValues = Record<string, unknown>, TExtensions extends Record<string, unknown> = Record<string, unknown>> extends GraphRunStream<TValues, TExtensions> {
228
+ /**
229
+ * The node name extracted from the last segment of the namespace path
230
+ * (everything before the final colon, or the full segment if no colon).
231
+ */
232
+ readonly name: string;
233
+ /**
234
+ * The invocation index parsed from the `"name:N"` suffix of the last
235
+ * namespace segment. Defaults to `0` when no numeric suffix is present.
236
+ */
237
+ readonly index: number;
238
+ /**
239
+ * @param path - Namespace path for this subgraph stream.
240
+ * @param mux - The {@link StreamMux} driving this run.
241
+ * @param discoveryStart - Cursor offset into the mux discovery log.
242
+ * @param eventStart - Cursor offset into the mux event log.
243
+ * @param extensions - Pre-initialized transformer projections.
244
+ * @param abortController - Controller for programmatic cancellation.
245
+ */
246
+ constructor(path: Namespace, mux: StreamMux, discoveryStart?: number, eventStart?: number, extensions?: TExtensions, abortController?: AbortController);
247
+ }
248
+ /**
249
+ * Options accepted by {@link createGraphRunStream}.
250
+ */
251
+ interface CreateGraphRunStreamOptions {
252
+ /**
253
+ * Optional abort controller shared with the outer run; if omitted, a
254
+ * fresh controller is allocated for the returned stream.
255
+ */
256
+ abortController?: AbortController;
257
+ }
258
+ /**
259
+ * Creates a {@link GraphRunStream} with built-in transformers and kicks off the
260
+ * background pump that feeds raw stream chunks through the transformer pipeline.
261
+ *
262
+ * Built-in transformers are registered in this order:
263
+ * 1. subgraph discovery — materializes SubgraphRunStream handles
264
+ * for each newly observed top-level namespace and announces them
265
+ * on the mux `_discoveries` log.
266
+ * 2. lifecycle — synthesizes `lifecycle` channel events.
267
+ * 3. values — powers `run.values` / `run.output`.
268
+ * 4. messages — powers `run.messages` / `.messagesFrom`.
269
+ *
270
+ * Subgraph discovery is registered first so that downstream
271
+ * transformers (notably lifecycle) observe child namespaces with
272
+ * their stream handles already in place. User-supplied transformer
273
+ * factories are registered afterwards.
274
+ *
275
+ * @typeParam TValues - Shape of the graph's state values.
276
+ * @param source - Raw async iterable from `graph.stream(…, { subgraphs: true })`.
277
+ * @param transformers - User-supplied transformer factories.
278
+ * @param optionsOrAbortController - Either a full
279
+ * {@link CreateGraphRunStreamOptions} object or (for backward
280
+ * compatibility) a bare `AbortController`.
281
+ * @returns A {@link GraphRunStream} for the root namespace.
282
+ */
283
+ declare function createGraphRunStream<TValues = Record<string, unknown>, const TTransformers extends ReadonlyArray<() => StreamTransformer<any>> = []>(source: AsyncIterable<StreamChunk>, transformers?: TTransformers, optionsOrAbortController?: CreateGraphRunStreamOptions | AbortController): GraphRunStream<TValues, InferExtensions<TTransformers>>;
284
+ //#endregion
285
+ export { CreateGraphRunStreamOptions, GraphRunStream, SET_LIFECYCLE_ITERABLE, SET_MESSAGES_ITERABLE, SET_VALUES_LOG, SubgraphRunStream, createGraphRunStream };
286
+ //# sourceMappingURL=run-stream.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-stream.d.cts","names":[],"sources":["../../src/stream/run-stream.ts"],"mappings":";;;;;;;;;;AAoGA;cAtDa,cAAA;;;;;cAM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AiCjB;;EAjCiB,CAvGd,cAAA,EAAgB,GAAA,EAAK,aAAA,CAAc,MAAA;EAyI1B;;;;;;;EAAA,CA9HT,qBAAA,EACC,QAAA,EAAU,aAAA,CAAc,qBAAA;EAoIV;;;;;;;;EAAA,CAvHf,sBAAA,EAAwB,QAAA,EAAU,aAAA,CAAc,cAAA;EAkHrB;;;;;;;;;EAAA,CArG3B,sBAAA,EAAwB,QAAA,EAAU,aAAA,CAAc,iBAAA;AAAA;;;;;;;;;;;;cAgBtC,iBAAA,WACD,MAAA,uCACU,MAAA,oBAA0B,MAAA,2BACtC,cAAA,CAAe,OAAA,EAAS,WAAA;;;;;WAKvB,IAAA;;;;;WAMA,KAAA;;;;;;;;;EAUT,WAAA,CACE,IAAA,EAAM,SAAA,EACN,GAAA,EAAK,SAAA,EACL,cAAA,WACA,UAAA,WACA,UAAA,GAAa,WAAA,EACb,eAAA,GAAkB,eAAA;AAAA;;;;UAmBL,2BAAA;;;;;EAKf,eAAA,GAAkB,eAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4BJ,oBAAA,WACJ,MAAA,+CAEkB,aAAA,OAAoB,iBAAA,YAAA,CAEhD,MAAA,EAAQ,aAAA,CAAc,WAAA,GACtB,YAAA,GAAc,aAAA,EACd,wBAAA,GAA2B,2BAAA,GAA8B,eAAA,GACxD,cAAA,CAAe,OAAA,EAAS,eAAA,CAAgB,aAAA"}
@@ -0,0 +1,285 @@
1
+ import { ChatModelStreamHandle, InferExtensions, InterruptPayload, Namespace, ProtocolEvent, StreamTransformer } from "./types.js";
2
+ import { StreamChunk } from "../pregel/stream.js";
3
+ import { StreamChannel } from "./stream-channel.js";
4
+ import { REJECT_VALUES, RESOLVE_VALUES, StreamMux } from "./mux.js";
5
+ import { LifecycleEntry } from "./transformers/types.js";
6
+ //#region src/stream/run-stream.d.ts
7
+ /**
8
+ * Symbol key for attaching the values log to a stream handle.
9
+ * Using a symbol keeps this off the public autocomplete surface.
10
+ */
11
+ declare const SET_VALUES_LOG: unique symbol;
12
+ /**
13
+ * Symbol key for attaching the messages iterable to a stream handle.
14
+ * Using a symbol keeps this off the public autocomplete surface.
15
+ */
16
+ declare const SET_MESSAGES_ITERABLE: unique symbol;
17
+ /**
18
+ * Symbol key for attaching the lifecycle iterable to a stream handle.
19
+ * Using a symbol keeps this off the public autocomplete surface.
20
+ */
21
+ declare const SET_LIFECYCLE_ITERABLE: unique symbol;
22
+ /**
23
+ * Symbol key for attaching the subgraphs iterable to a stream handle.
24
+ * Using a symbol keeps this off the public autocomplete surface.
25
+ */
26
+ declare const SET_SUBGRAPHS_ITERABLE: unique symbol;
27
+ /**
28
+ * Primary run stream for a LangGraph execution.
29
+ *
30
+ * Implements {@link AsyncIterable} over {@link ProtocolEvent} and exposes
31
+ * ergonomic projections for values, messages, subgraphs, output, and
32
+ * interrupts. Created by {@link createGraphRunStream}.
33
+ *
34
+ * @typeParam TValues - Shape of the graph's state values.
35
+ * @typeParam TExtensions - Shape of additional transformer projections merged
36
+ * into {@link GraphRunStream.extensions}.
37
+ */
38
+ declare class GraphRunStream<TValues = Record<string, unknown>, TExtensions extends Record<string, unknown> = Record<string, unknown>> implements AsyncIterable<ProtocolEvent> {
39
+ #private;
40
+ /**
41
+ * Namespace path identifying this stream's position in the agent tree.
42
+ * An empty array for the root stream.
43
+ */
44
+ readonly path: Namespace;
45
+ /**
46
+ * Merged projections from user-supplied {@link StreamTransformer} factories.
47
+ * Each transformer's `init()` return value is spread into this object.
48
+ */
49
+ readonly extensions: TExtensions;
50
+ /**
51
+ * The central stream multiplexer that drives event dispatch and transformer
52
+ * pipelines. Accessible to subclasses for direct event subscription.
53
+ *
54
+ * @internal
55
+ */
56
+ protected readonly _mux: StreamMux;
57
+ /**
58
+ * @param path - Namespace path for this stream (empty array for root).
59
+ * @param mux - The {@link StreamMux} driving this run.
60
+ * @param discoveryStart - Cursor offset into the mux discovery log.
61
+ * @param eventStart - Cursor offset into the mux event log.
62
+ * @param extensions - Pre-initialized transformer projections.
63
+ * @param abortController - Controller for programmatic cancellation.
64
+ */
65
+ constructor(path: Namespace, mux: StreamMux, discoveryStart?: number, eventStart?: number, extensions?: TExtensions, abortController?: AbortController);
66
+ /**
67
+ * Async iterator over all {@link ProtocolEvent}s at or below this
68
+ * stream's namespace, starting from the configured event offset.
69
+ *
70
+ * @returns An async iterator yielding protocol events in arrival order.
71
+ */
72
+ [Symbol.asyncIterator](): AsyncIterator<ProtocolEvent>;
73
+ /**
74
+ * Async iterable of child {@link SubgraphRunStream} instances discovered
75
+ * during the run. Each yielded stream represents a direct child namespace.
76
+ *
77
+ * Backed by the shared `_discoveries` log on the mux, populated by
78
+ * {@link createSubgraphDiscoveryTransformer}. For streams created
79
+ * through {@link createGraphRunStream} the iterable is pre-wired
80
+ * (via {@link SET_SUBGRAPHS_ITERABLE}) so iteration is cheap.
81
+ * Streams constructed directly (e.g. in unit tests) fall back to
82
+ * filtering `_mux._discoveries` on demand, preserving the original
83
+ * behavior without requiring explicit wiring.
84
+ *
85
+ * @returns An async iterable of subgraph run streams.
86
+ */
87
+ get subgraphs(): AsyncIterable<SubgraphRunStream>;
88
+ /**
89
+ * Dual-interface accessor for graph state snapshots.
90
+ *
91
+ * As an {@link AsyncIterable}, yields each intermediate state snapshot
92
+ * as it arrives. As a {@link PromiseLike}, resolves with the final
93
+ * state value when the run completes.
94
+ *
95
+ * @returns A combined async iterable and promise-like for state values.
96
+ */
97
+ get values(): AsyncIterable<TValues> & PromiseLike<TValues>;
98
+ /**
99
+ * All AI message lifecycles observed at this namespace level, in order.
100
+ * Each yielded {@link ChatModelStream} represents one message-start →
101
+ * message-finish lifecycle with streaming `.text`, `.reasoning`, and
102
+ * `.usage` projections.
103
+ *
104
+ * @returns An async iterable of chat model streams.
105
+ */
106
+ get messages(): AsyncIterable<ChatModelStreamHandle>;
107
+ /**
108
+ * Sequence of {@link LifecycleEntry} records tracking the
109
+ * `lifecycle` channel: when the run starts, when each subgraph
110
+ * enters/exits, and the terminal status of the run as a whole.
111
+ *
112
+ * Backed by the built-in {@link createLifecycleTransformer}; the
113
+ * root stream's iterable is wired during
114
+ * {@link createGraphRunStream} setup, and each
115
+ * {@link SubgraphRunStream} is wired in the subgraph discovery
116
+ * factory with a subtree-scoped view (via
117
+ * {@link filterLifecycleEntries}). Streams constructed outside
118
+ * `createGraphRunStream` and not wired will yield nothing.
119
+ *
120
+ * @returns An async iterable of lifecycle entries in emission order.
121
+ */
122
+ get lifecycle(): AsyncIterable<LifecycleEntry>;
123
+ /**
124
+ * Messages produced by a specific graph node. Use when the run has
125
+ * multiple model-calling nodes and you only want messages from one.
126
+ *
127
+ * @param node - The graph node name to filter messages by.
128
+ * @returns An async iterable of chat model streams from the given node.
129
+ */
130
+ messagesFrom(node: string): AsyncIterable<ChatModelStreamHandle>;
131
+ /**
132
+ * Promise that resolves with the final graph state when the run completes,
133
+ * or rejects if the run fails.
134
+ *
135
+ * @returns A promise resolving to the final state values.
136
+ */
137
+ get output(): Promise<TValues>;
138
+ /**
139
+ * Whether the run ended due to a human-in-the-loop interrupt.
140
+ *
141
+ * @returns `true` if the run was interrupted.
142
+ */
143
+ get interrupted(): boolean;
144
+ /**
145
+ * Interrupt payloads collected during the run, if any.
146
+ *
147
+ * @returns A readonly array of interrupt payloads.
148
+ */
149
+ get interrupts(): readonly InterruptPayload[];
150
+ /**
151
+ * Programmatically abort this run. Equivalent to calling
152
+ * `signal.abort(reason)`.
153
+ *
154
+ * @param reason - Optional abort reason passed to the signal.
155
+ */
156
+ abort(reason?: unknown): void;
157
+ /**
158
+ * The {@link AbortSignal} wired into this run for cancellation support.
159
+ *
160
+ * @returns The abort signal for this stream.
161
+ */
162
+ get signal(): AbortSignal;
163
+ /**
164
+ * Resolve the output/values promise with the final state snapshot.
165
+ * Called by {@link StreamMux.close}.
166
+ *
167
+ * @param values - The final state values, or `undefined` if none.
168
+ * @internal
169
+ */
170
+ [RESOLVE_VALUES](values: TValues | undefined): void;
171
+ /**
172
+ * Reject the output/values promise with a run error.
173
+ * Called by {@link StreamMux.fail}.
174
+ *
175
+ * @param err - The error that caused the run to fail.
176
+ * @internal
177
+ */
178
+ [REJECT_VALUES](err: unknown): void;
179
+ /**
180
+ * Attach the transformer-populated event log backing the `.values` iterable.
181
+ * Called during stream setup in {@link createGraphRunStream}.
182
+ *
183
+ * @param log - The event log from the values transformer projection.
184
+ * @internal
185
+ */
186
+ [SET_VALUES_LOG](log: StreamChannel<Record<string, unknown>>): void;
187
+ /**
188
+ * Attach the transformer-populated async iterable backing the `.messages`
189
+ * accessor. Called during stream setup in {@link createGraphRunStream}.
190
+ *
191
+ * @param iterable - The async iterable from the messages transformer projection.
192
+ * @internal
193
+ */
194
+ [SET_MESSAGES_ITERABLE](iterable: AsyncIterable<ChatModelStreamHandle>): void;
195
+ /**
196
+ * Attach the transformer-populated async iterable backing the
197
+ * `.lifecycle` accessor. Called during stream setup in
198
+ * {@link createGraphRunStream}.
199
+ *
200
+ * @param iterable - The async iterable from the lifecycle transformer projection.
201
+ * @internal
202
+ */
203
+ [SET_LIFECYCLE_ITERABLE](iterable: AsyncIterable<LifecycleEntry>): void;
204
+ /**
205
+ * Attach the transformer-populated async iterable backing the
206
+ * `.subgraphs` accessor. Called during root stream setup in
207
+ * {@link createGraphRunStream} and during child stream
208
+ * construction in the discovery transformer factory.
209
+ *
210
+ * @param iterable - The async iterable of direct-child stream handles.
211
+ * @internal
212
+ */
213
+ [SET_SUBGRAPHS_ITERABLE](iterable: AsyncIterable<SubgraphRunStream>): void;
214
+ }
215
+ /**
216
+ * A run stream for a child subgraph within a parent graph execution.
217
+ *
218
+ * Extends {@link GraphRunStream} with a parsed {@link name} and
219
+ * {@link index} extracted from the last segment of the namespace path.
220
+ * The segment is expected to follow the `"name:index"` convention;
221
+ * when no numeric suffix is present, {@link index} defaults to `0`.
222
+ *
223
+ * @typeParam TValues - Shape of the subgraph's state values.
224
+ * @typeParam TExtensions - Shape of additional transformer projections.
225
+ */
226
+ declare class SubgraphRunStream<TValues = Record<string, unknown>, TExtensions extends Record<string, unknown> = Record<string, unknown>> extends GraphRunStream<TValues, TExtensions> {
227
+ /**
228
+ * The node name extracted from the last segment of the namespace path
229
+ * (everything before the final colon, or the full segment if no colon).
230
+ */
231
+ readonly name: string;
232
+ /**
233
+ * The invocation index parsed from the `"name:N"` suffix of the last
234
+ * namespace segment. Defaults to `0` when no numeric suffix is present.
235
+ */
236
+ readonly index: number;
237
+ /**
238
+ * @param path - Namespace path for this subgraph stream.
239
+ * @param mux - The {@link StreamMux} driving this run.
240
+ * @param discoveryStart - Cursor offset into the mux discovery log.
241
+ * @param eventStart - Cursor offset into the mux event log.
242
+ * @param extensions - Pre-initialized transformer projections.
243
+ * @param abortController - Controller for programmatic cancellation.
244
+ */
245
+ constructor(path: Namespace, mux: StreamMux, discoveryStart?: number, eventStart?: number, extensions?: TExtensions, abortController?: AbortController);
246
+ }
247
+ /**
248
+ * Options accepted by {@link createGraphRunStream}.
249
+ */
250
+ interface CreateGraphRunStreamOptions {
251
+ /**
252
+ * Optional abort controller shared with the outer run; if omitted, a
253
+ * fresh controller is allocated for the returned stream.
254
+ */
255
+ abortController?: AbortController;
256
+ }
257
+ /**
258
+ * Creates a {@link GraphRunStream} with built-in transformers and kicks off the
259
+ * background pump that feeds raw stream chunks through the transformer pipeline.
260
+ *
261
+ * Built-in transformers are registered in this order:
262
+ * 1. subgraph discovery — materializes SubgraphRunStream handles
263
+ * for each newly observed top-level namespace and announces them
264
+ * on the mux `_discoveries` log.
265
+ * 2. lifecycle — synthesizes `lifecycle` channel events.
266
+ * 3. values — powers `run.values` / `run.output`.
267
+ * 4. messages — powers `run.messages` / `.messagesFrom`.
268
+ *
269
+ * Subgraph discovery is registered first so that downstream
270
+ * transformers (notably lifecycle) observe child namespaces with
271
+ * their stream handles already in place. User-supplied transformer
272
+ * factories are registered afterwards.
273
+ *
274
+ * @typeParam TValues - Shape of the graph's state values.
275
+ * @param source - Raw async iterable from `graph.stream(…, { subgraphs: true })`.
276
+ * @param transformers - User-supplied transformer factories.
277
+ * @param optionsOrAbortController - Either a full
278
+ * {@link CreateGraphRunStreamOptions} object or (for backward
279
+ * compatibility) a bare `AbortController`.
280
+ * @returns A {@link GraphRunStream} for the root namespace.
281
+ */
282
+ declare function createGraphRunStream<TValues = Record<string, unknown>, const TTransformers extends ReadonlyArray<() => StreamTransformer<any>> = []>(source: AsyncIterable<StreamChunk>, transformers?: TTransformers, optionsOrAbortController?: CreateGraphRunStreamOptions | AbortController): GraphRunStream<TValues, InferExtensions<TTransformers>>;
283
+ //#endregion
284
+ export { CreateGraphRunStreamOptions, GraphRunStream, SET_LIFECYCLE_ITERABLE, SET_MESSAGES_ITERABLE, SET_VALUES_LOG, SubgraphRunStream, createGraphRunStream };
285
+ //# sourceMappingURL=run-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-stream.d.ts","names":[],"sources":["../../src/stream/run-stream.ts"],"mappings":";;;;;;;;;;cA8Ca,cAAA;;;;;cAMA,qBAAA;;;;;cAQA,sBAAA;;;;;cAQA,sBAAA;;;;;;;;;;;;cAgCA,cAAA,WACD,MAAA,uCACU,MAAA,oBAA0B,MAAA,8BACnC,aAAA,CAAc,aAAA;EAAA;EAuNH;;;;EAAA,SAlNb,IAAA,EAAM,SAAA;EAkQd;;;;EAAA,SA5PQ,UAAA,EAAY,WAAA;EAgSK;;;;;;EAAA,mBAxRP,IAAA,EAAM,SAAA;EAkTU;;;;;;;;EA1RnC,WAAA,CACE,IAAA,EAAM,SAAA,EACN,GAAA,EAAK,SAAA,EACL,cAAA,WACA,UAAA,WACA,UAAA,GAAa,WAAA,EACb,eAAA,GAAkB,eAAA;EAlD0B;;;;;;EAAA,CA2E7C,MAAA,CAAO,aAAA,KAAkB,aAAA,CAAc,aAAA;EA/DnB;;;;;;;;;;;;;;EAAA,IAiFjB,SAAA,CAAA,GAAa,aAAA,CAAc,iBAAA;EAlBvB;;;;;;;;;EAAA,IAoCJ,MAAA,CAAA,GAAU,aAAA,C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