@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 @@
1
+ {"version":3,"file":"mux.cjs","names":["StreamChannel","#transformers","#channels","#streamMap","#latestValues","#interrupts","#finalValues","#closed","#error","isStreamChannel","#nextEmitSeq","#currentNamespace","#interrupted","isInterrupted","INTERRUPT","convertToProtocolEvent"],"sources":["../../src/stream/mux.ts"],"sourcesContent":["/**\n * StreamMux — central dispatcher with transformer pipeline.\n *\n * Routes raw stream chunks through registered StreamTransformers, then appends\n * the resulting ProtocolEvents to the main local channel. Also tracks\n * namespace discovery for SubgraphRunStream creation.\n *\n * lifecycle:\n * graph.streamEvents(input, { version: \"v3\" })\n * ├─ StreamMux starts pumping from graph.stream(…, { subgraphs: true })\n * ├─ For each ProtocolEvent:\n * │ ├─ transformer_1.process(event)\n * │ ├─ transformer_2.process(event)\n * │ └─ event appended to _events (unless suppressed)\n * └─ On close: transformer_n.finalize() called in registration order\n */\n\nimport type { StreamChunk } from \"../pregel/stream.js\";\nimport { INTERRUPT, isInterrupted, type Interrupt } from \"../constants.js\";\nimport { convertToProtocolEvent, STREAM_EVENTS_V3_MODES } from \"./convert.js\";\nimport { StreamChannel, isStreamChannel } from \"./stream-channel.js\";\nimport type {\n InterruptPayload,\n Namespace,\n ProtocolEvent,\n StreamEmitter,\n StreamTransformer,\n} from \"./types.js\";\n\nexport { STREAM_EVENTS_V3_MODES };\n\n/**\n * Structural `PromiseLike<T>` predicate — true for thenables including\n * native promises, user-constructed `{ then }` objects, and helper\n * wrappers. Used by {@link StreamMux.wireChannels} to detect final-value\n * projections distinctly from streaming `StreamChannel` values.\n */\nfunction isPromiseLike(value: unknown): value is PromiseLike<unknown> {\n return (\n value != null &&\n (typeof value === \"object\" || typeof value === \"function\") &&\n typeof (value as { then?: unknown }).then === \"function\"\n );\n}\n\n/**\n * Symbol key used by {@link StreamMux} to resolve the values promise on a\n * stream handle. Using a symbol keeps this off the public autocomplete surface.\n */\nexport const RESOLVE_VALUES: unique symbol = Symbol(\"resolveValues\");\n\n/**\n * Symbol key used by {@link StreamMux} to reject the values promise on a\n * stream handle. Using a symbol keeps this off the public autocomplete surface.\n */\nexport const REJECT_VALUES: unique symbol = Symbol(\"rejectValues\");\n\n/**\n * Minimal interface that {@link StreamMux} requires from stream handles\n * for lifecycle resolution. This avoids a direct dependency on\n * `GraphRunStream` / `SubgraphRunStream`.\n */\nexport interface StreamHandle {\n [RESOLVE_VALUES](values: unknown): void;\n [REJECT_VALUES](err: unknown): void;\n}\n\n/**\n * Factory function that creates a subgraph stream handle for a newly\n * discovered namespace.\n *\n * Historically consumed by {@link StreamMux} at construction time;\n * today factories are consumed by\n * `createSubgraphDiscoveryTransformer` (via its `createStream`\n * option). This shape is retained for consumers that still thread a\n * mux reference through the factory — the narrower transformer\n * option omits `mux` because it captures the mux in a closure.\n */\nexport type SubgraphStreamFactory = (\n path: Namespace,\n mux: StreamMux,\n discoveryStart: number,\n eventStart: number\n) => StreamHandle;\n\n/**\n * A discovered subgraph namespace paired with its run stream handle.\n */\nexport type SubgraphDiscovery = {\n ns: Namespace;\n stream: StreamHandle;\n};\n\n/**\n * Central event dispatcher that routes {@link ProtocolEvent}s through a\n * pipeline of {@link StreamTransformer}s, manages namespace discovery for\n * subgraph streams, and exposes async iteration over filtered event\n * sequences.\n *\n * One `StreamMux` instance exists per top-level\n * `streamEvents(..., { version: \"v3\" })` invocation.\n */\nexport class StreamMux {\n /** @internal All protocol events in arrival order (after reducer pipeline). */\n readonly _events = StreamChannel.local<ProtocolEvent>();\n\n /** @internal New-namespace discovery notifications. */\n readonly _discoveries = StreamChannel.local<SubgraphDiscovery>();\n\n /** Monotonic counter for auto-forwarded channel events. */\n #nextEmitSeq = 0;\n\n /** Whether the mux has been closed or failed. */\n #closed = false;\n\n /** The error passed to {@link fail}, if any. */\n #error: unknown;\n\n /** Whether the run was interrupted. */\n #interrupted = false;\n\n /**\n * Namespace of the event currently being processed by\n * {@link push}. Read by {@link StreamChannel} wiring callbacks so\n * auto-forwarded events inherit the triggering event's namespace.\n */\n #currentNamespace: Namespace = [];\n\n readonly #transformers: StreamTransformer<unknown>[] = [];\n readonly #channels: StreamChannel<unknown>[] = [];\n readonly #streamMap = new Map<string, StreamHandle>();\n readonly #latestValues = new Map<string, Record<string, unknown>>();\n readonly #interrupts: InterruptPayload[] = [];\n\n /**\n * Final-value projection keys tracked for remote surfacing. Populated\n * by {@link wireChannels} when a transformer's projection contains a\n * `PromiseLike` value. Each entry is flushed as a `custom:<name>`\n * protocol event during {@link close} so that remote clients can\n * observe final-value transformers via `thread.extensions.<name>`.\n */\n readonly #finalValues: Array<{ name: string; promise: Promise<unknown> }> =\n [];\n\n /**\n * Associates a pre-existing stream handle with a namespace so that\n * {@link close} can resolve its values promise later.\n *\n * @param path - The namespace path to register.\n * @param stream - The run stream handle for that namespace.\n */\n register(path: Namespace, stream: StreamHandle): void {\n this.#streamMap.set(nsKey(path), stream);\n }\n\n /**\n * Registers a transformer and replays all buffered events through it so\n * it catches up with events already processed by the mux. When the event\n * log is empty (typical at construction time) the replay is a no-op.\n *\n * The transformer must already have been initialised (i.e. `init()` called\n * and any projection wired). The sequence is:\n *\n * 1. Snapshot the current event log length.\n * 2. Append the transformer so future {@link push} calls reach it.\n * 3. Replay events `[0, snapshot)` through `process()`.\n * 4. If the mux is already closed, call `finalize()` (or `fail()`)\n * immediately so the transformer's log/channel terminates cleanly.\n *\n * @param transformer - An already-initialised transformer to register.\n */\n addTransformer(transformer: StreamTransformer<unknown>): void {\n const snapshot = this._events.size;\n this.#transformers.push(transformer);\n\n // Hand the transformer a narrow emitter handle *before* replay so\n // synthetic-emission transformers (e.g. deepagents\n // `SubagentTransformer`) can inject events into the mux during\n // their own `process()` calls — including the initial replay\n // triggered just below.\n if (transformer.onRegister) {\n const emitter: StreamEmitter = {\n // Transformer-originated events use a placeholder `seq` of\n // `0`. `push()` is the single authority for sequence numbers\n // and will re-stamp this event with the next monotonically\n // increasing value.\n push: (ns, event) => this.push(ns, event),\n };\n transformer.onRegister(emitter);\n }\n\n for (let i = 0; i < snapshot; i += 1) {\n transformer.process(this._events.get(i));\n }\n\n if (this.#closed) {\n if (this.#error !== undefined) {\n transformer.fail?.(this.#error);\n } else {\n transformer.finalize?.();\n }\n }\n }\n\n /**\n * Scans a transformer projection for streaming and final-value primitives.\n * Remote stream channels are wired to auto-forward to the protocol event\n * stream; local stream channels are tracked for lifecycle only.\n *\n * Two projection shapes are recognised:\n *\n * - {@link StreamChannel} values — named channels forward each `push()`\n * immediately as a protocol event on the channel's declared\n * `channelName` method. Unnamed channels remain in-process-only.\n *\n * - `PromiseLike<unknown>` values — tracked as final-value\n * projections and flushed on {@link close} as a single\n * `custom:<key>` event, where `<key>` is the projection key.\n * This mirrors the in-process `await run.extensions.<key>`\n * ergonomics on remote clients via\n * `await thread.extensions.<key>`.\n *\n * Plain values that are neither are ignored — they remain in-process-only,\n * matching prior behaviour.\n *\n * @param projection - The object returned by `transformer.init()`.\n */\n wireChannels(projection: Record<string, unknown>): void {\n for (const [key, value] of Object.entries(projection)) {\n if (isStreamChannel(value)) {\n this.#channels.push(value);\n if (typeof value.channelName !== \"string\") {\n continue;\n }\n value._wire((item: unknown) => {\n this._events.push({\n type: \"event\",\n seq: this.#nextEmitSeq++,\n method: value.channelName as ProtocolEvent[\"method\"],\n params: {\n namespace: this.#currentNamespace,\n timestamp: Date.now(),\n data: item,\n },\n });\n });\n continue;\n }\n if (isPromiseLike(value)) {\n this.#finalValues.push({\n name: key,\n promise: Promise.resolve(value),\n });\n }\n }\n }\n\n /**\n * Distributes an event through the transformer pipeline, then appends it to\n * the main event log.\n *\n * Subgraph discovery (materializing a {@link StreamHandle} for each\n * newly observed top-level namespace) is handled by the\n * {@link createSubgraphDiscoveryTransformer} when installed, not here.\n *\n * @param ns - The namespace path that produced the event.\n * @param event - The protocol event to process and store.\n */\n push(ns: Namespace, event: ProtocolEvent): void {\n if (event.method === \"values\") {\n this.#latestValues.set(\n nsKey(ns),\n event.params.data as Record<string, unknown>\n );\n }\n\n // Save the outer namespace so re-entrant `push()` calls (e.g. from\n // `StreamTransformer.onRegister` emitters synthesizing events\n // inside a transformer's `process()`) can set their own namespace\n // without clobbering the outer scope's `StreamChannel` routing\n // when control returns to the outer transformer loop.\n const outerNamespace = this.#currentNamespace;\n this.#currentNamespace = ns;\n\n let keep = true;\n for (const transformer of this.#transformers) {\n if (!transformer.process(event)) {\n keep = false;\n }\n }\n\n this.#currentNamespace = outerNamespace;\n\n if (keep) {\n // The mux is the single authority for sequence numbers. Callers\n // (the `pump`, transformer emitters, channel forwarders) pass a\n // placeholder `seq`; we re-stamp every event here so the log is\n // strictly monotonic across all origination paths. Stamping\n // happens *after* `process()` so that any channel-forwarded\n // events pushed during processing get earlier sequence numbers\n // than the triggering event, matching their in-order appearance\n // in `_events`.\n this._events.push({ ...event, seq: this.#nextEmitSeq++ });\n }\n }\n\n /**\n * Gracefully ends the stream: resolves values promises on all known\n * streams, finalizes every transformer, auto-closes streaming\n * channels, flushes any final-value projections as `custom:<name>`\n * events, and closes both event logs.\n *\n * When final-value projections are present, `_events.close()` is\n * deferred until every tracked projection promise has settled so\n * remote consumers observe the flushed values before their event\n * stream ends. Callers do not need to await — `close()` returns\n * synchronously and any downstream consumer iterating\n * {@link _events} naturally waits for the final events.\n */\n close(): void {\n this.#closed = true;\n for (const [key, values] of this.#latestValues.entries()) {\n const ns = key ? key.split(\"\\x00\") : [];\n const stream = this.#streamMap.get(nsKey(ns));\n stream?.[RESOLVE_VALUES](values);\n }\n\n const finalizePromises: PromiseLike<void>[] = [];\n for (const transformer of this.#transformers) {\n const result = transformer.finalize?.();\n if (\n result != null &&\n typeof (result as PromiseLike<void>).then === \"function\"\n ) {\n finalizePromises.push(result as PromiseLike<void>);\n }\n }\n\n for (const channel of this.#channels) {\n channel._close();\n }\n\n const finalValues = this.#finalValues;\n if (finalValues.length === 0 && finalizePromises.length === 0) {\n this._events.close();\n this._discoveries.close();\n } else {\n void Promise.allSettled([\n ...finalizePromises,\n ...finalValues.map(async ({ name, promise }) => {\n try {\n const resolved = await promise;\n if (!this._events.done) {\n this._events.push({\n type: \"event\",\n seq: this.#nextEmitSeq++,\n method: \"custom\",\n params: {\n namespace: [],\n timestamp: Date.now(),\n data: { name, payload: resolved },\n },\n });\n }\n } catch {\n // Rejected final-value projections are intentionally dropped\n // so a single failing extension can't poison the protocol\n // stream. The corresponding in-process Promise still\n // surfaces the rejection to its direct awaiters via the\n // transformer's own `fail()` hook.\n }\n }),\n ]).then(() => {\n this._events.close();\n this._discoveries.close();\n });\n }\n\n for (const stream of this.#streamMap.values()) {\n stream[RESOLVE_VALUES](undefined);\n }\n }\n\n /**\n * Propagates a failure to all transformers, channels, event logs, and\n * stream handles.\n *\n * @param err - The error that caused the run to fail.\n */\n fail(err: unknown): void {\n this.#closed = true;\n this.#error = err;\n for (const transformer of this.#transformers) {\n transformer.fail?.(err);\n }\n for (const channel of this.#channels) {\n channel._fail(err);\n }\n this._events.fail(err);\n this._discoveries.fail(err);\n for (const stream of this.#streamMap.values()) {\n stream[REJECT_VALUES](err);\n }\n }\n\n /**\n * Records that the run was interrupted, appending the supplied payloads\n * for later retrieval.\n *\n * @param interrupts - The interrupt payloads to store.\n */\n markInterrupted(interrupts: InterruptPayload[]): void {\n this.#interrupted = true;\n this.#interrupts.push(...interrupts);\n }\n\n /**\n * Whether the run ended due to an interrupt.\n *\n * @returns `true` if {@link markInterrupted} was called.\n */\n get interrupted(): boolean {\n return this.#interrupted;\n }\n\n /**\n * All interrupt payloads collected during the run.\n *\n * @returns A readonly view of the accumulated interrupt payloads.\n */\n get interrupts(): readonly InterruptPayload[] {\n return this.#interrupts;\n }\n\n /**\n * Returns an async iterator that yields only events whose namespace\n * starts with {@link path}.\n *\n * @param path - Namespace prefix to filter on.\n * @param startAt - Zero-based index into the event log to begin from.\n * @returns An async iterator over matching {@link ProtocolEvent}s.\n */\n subscribeEvents(path: Namespace, startAt = 0): AsyncIterator<ProtocolEvent> {\n const base = this._events.iterate(startAt);\n return {\n async next(): Promise<IteratorResult<ProtocolEvent>> {\n // eslint-disable-next-line no-constant-condition\n while (true) {\n const result = await base.next();\n if (result.done) return result;\n if (hasPrefix(result.value.params.namespace, path)) {\n return result;\n }\n }\n },\n };\n }\n}\n\n/**\n * Background consumer that drains a raw `graph.stream()` source into a\n * {@link StreamMux}. Converts each chunk to a {@link ProtocolEvent} and\n * pushes it; calls {@link StreamMux.close} on normal completion or\n * {@link StreamMux.fail} on error.\n *\n * @param source - The async iterable of raw stream chunks from the engine.\n * @param mux - The mux instance to feed.\n * @returns A promise that resolves when the source is fully consumed.\n */\nexport async function pump(\n source: AsyncIterable<StreamChunk>,\n mux: StreamMux\n): Promise<void> {\n let seq = 0;\n try {\n for await (const chunk of source) {\n const [ns, mode, payload, meta] = chunk;\n\n // Detect interrupt payloads attached to values-mode chunks.\n if (mode === \"values\" && isInterrupted(payload)) {\n const interrupts = (payload as { [INTERRUPT]: Interrupt[] })[INTERRUPT];\n mux.markInterrupted(\n interrupts.map((i) => ({\n interruptId: i.id ?? \"\",\n payload: i.value,\n }))\n );\n }\n\n const events = convertToProtocolEvent({\n namespace: ns,\n mode,\n payload,\n seq,\n meta,\n });\n seq += events.length;\n for (const event of events) {\n mux.push(ns, event);\n }\n }\n } catch (err) {\n mux.fail(err);\n return;\n }\n mux.close();\n}\n\n/**\n * Serialises a {@link Namespace} array into a single string key using the\n * null byte (`\\x00`) as separator, suitable for `Map`/`Set` lookups.\n *\n * @param ns - The namespace segments to join.\n * @returns A null-byte-joined string key.\n */\nexport function nsKey(ns: Namespace): string {\n return ns.join(\"\\x00\");\n}\n\n/**\n * Tests whether {@link ns} starts with every segment in {@link prefix}.\n *\n * @param ns - The full namespace to check.\n * @param prefix - The prefix to match against.\n * @returns `true` if `ns` begins with `prefix` segment-by-segment.\n */\nexport function hasPrefix(ns: Namespace, prefix: Namespace): boolean {\n if (prefix.length > ns.length) return false;\n for (let i = 0; i < prefix.length; i += 1) {\n if (ns[i] !== prefix[i]) return false;\n }\n return true;\n}\n"],"mappings":";;;;;;;;;;AAqCA,SAAS,cAAc,OAA+C;AACpE,QACE,SAAS,SACR,OAAO,UAAU,YAAY,OAAO,UAAU,eAC/C,OAAQ,MAA6B,SAAS;;;;;;AAQlD,MAAa,iBAAgC,OAAO,gBAAgB;;;;;AAMpE,MAAa,gBAA+B,OAAO,eAAe;;;;;;;;;;AA+ClE,IAAa,YAAb,MAAuB;;CAErB,UAAmBA,uBAAAA,cAAc,OAAsB;;CAGvD,eAAwBA,uBAAAA,cAAc,OAA0B;;CAGhE,eAAe;;CAGf,UAAU;;CAGV;;CAGA,eAAe;;;;;;CAOf,oBAA+B,EAAE;CAEjC,gBAAuD,EAAE;CACzD,YAA+C,EAAE;CACjD,6BAAsB,IAAI,KAA2B;CACrD,gCAAyB,IAAI,KAAsC;CACnE,cAA2C,EAAE;;;;;;;;CAS7C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AM;;UAGhB,KAAK;AACZ,MAAI,KAAK,IAAI;AACb;;AAEF,KAAI,OAAO;;;;;;;;;AAUb,SAAgB,MAAM,IAAuB;AAC3C,QAAO,GAAG,KAAK,KAAO;;;;;;;;;AAUxB,SAAgB,UAAU,IAAe,QAA4B;AACnE,KAAI,OAAO,SAAS,GAAG,OAAQ,QAAO;AACtC,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,EACtC,KAAI,GAAG,OAAO,OAAO,GAAI,QAAO;AAElC,QAAO"}
@@ -0,0 +1,160 @@
1
+ import { InterruptPayload, Namespace, ProtocolEvent, StreamTransformer } from "./types.cjs";
2
+ import { StreamChannel } from "./stream-channel.cjs";
3
+ import { STREAM_EVENTS_V3_MODES } from "./convert.cjs";
4
+
5
+ //#region src/stream/mux.d.ts
6
+ /**
7
+ * Symbol key used by {@link StreamMux} to resolve the values promise on a
8
+ * stream handle. Using a symbol keeps this off the public autocomplete surface.
9
+ */
10
+ declare const RESOLVE_VALUES: unique symbol;
11
+ /**
12
+ * Symbol key used by {@link StreamMux} to reject the values promise on a
13
+ * stream handle. Using a symbol keeps this off the public autocomplete surface.
14
+ */
15
+ declare const REJECT_VALUES: unique symbol;
16
+ /**
17
+ * Minimal interface that {@link StreamMux} requires from stream handles
18
+ * for lifecycle resolution. This avoids a direct dependency on
19
+ * `GraphRunStream` / `SubgraphRunStream`.
20
+ */
21
+ interface StreamHandle {
22
+ [RESOLVE_VALUES](values: unknown): void;
23
+ [REJECT_VALUES](err: unknown): void;
24
+ }
25
+ /**
26
+ * A discovered subgraph namespace paired with its run stream handle.
27
+ */
28
+ type SubgraphDiscovery = {
29
+ ns: Namespace;
30
+ stream: StreamHandle;
31
+ };
32
+ /**
33
+ * Central event dispatcher that routes {@link ProtocolEvent}s through a
34
+ * pipeline of {@link StreamTransformer}s, manages namespace discovery for
35
+ * subgraph streams, and exposes async iteration over filtered event
36
+ * sequences.
37
+ *
38
+ * One `StreamMux` instance exists per top-level
39
+ * `streamEvents(..., { version: "v3" })` invocation.
40
+ */
41
+ declare class StreamMux {
42
+ #private;
43
+ /** @internal All protocol events in arrival order (after reducer pipeline). */
44
+ readonly _events: StreamChannel<ProtocolEvent>;
45
+ /** @internal New-namespace discovery notifications. */
46
+ readonly _discoveries: StreamChannel<SubgraphDiscovery>;
47
+ /**
48
+ * Associates a pre-existing stream handle with a namespace so that
49
+ * {@link close} can resolve its values promise later.
50
+ *
51
+ * @param path - The namespace path to register.
52
+ * @param stream - The run stream handle for that namespace.
53
+ */
54
+ register(path: Namespace, stream: StreamHandle): void;
55
+ /**
56
+ * Registers a transformer and replays all buffered events through it so
57
+ * it catches up with events already processed by the mux. When the event
58
+ * log is empty (typical at construction time) the replay is a no-op.
59
+ *
60
+ * The transformer must already have been initialised (i.e. `init()` called
61
+ * and any projection wired). The sequence is:
62
+ *
63
+ * 1. Snapshot the current event log length.
64
+ * 2. Append the transformer so future {@link push} calls reach it.
65
+ * 3. Replay events `[0, snapshot)` through `process()`.
66
+ * 4. If the mux is already closed, call `finalize()` (or `fail()`)
67
+ * immediately so the transformer's log/channel terminates cleanly.
68
+ *
69
+ * @param transformer - An already-initialised transformer to register.
70
+ */
71
+ addTransformer(transformer: StreamTransformer<unknown>): void;
72
+ /**
73
+ * Scans a transformer projection for streaming and final-value primitives.
74
+ * Remote stream channels are wired to auto-forward to the protocol event
75
+ * stream; local stream channels are tracked for lifecycle only.
76
+ *
77
+ * Two projection shapes are recognised:
78
+ *
79
+ * - {@link StreamChannel} values — named channels forward each `push()`
80
+ * immediately as a protocol event on the channel's declared
81
+ * `channelName` method. Unnamed channels remain in-process-only.
82
+ *
83
+ * - `PromiseLike<unknown>` values — tracked as final-value
84
+ * projections and flushed on {@link close} as a single
85
+ * `custom:<key>` event, where `<key>` is the projection key.
86
+ * This mirrors the in-process `await run.extensions.<key>`
87
+ * ergonomics on remote clients via
88
+ * `await thread.extensions.<key>`.
89
+ *
90
+ * Plain values that are neither are ignored — they remain in-process-only,
91
+ * matching prior behaviour.
92
+ *
93
+ * @param projection - The object returned by `transformer.init()`.
94
+ */
95
+ wireChannels(projection: Record<string, unknown>): void;
96
+ /**
97
+ * Distributes an event through the transformer pipeline, then appends it to
98
+ * the main event log.
99
+ *
100
+ * Subgraph discovery (materializing a {@link StreamHandle} for each
101
+ * newly observed top-level namespace) is handled by the
102
+ * {@link createSubgraphDiscoveryTransformer} when installed, not here.
103
+ *
104
+ * @param ns - The namespace path that produced the event.
105
+ * @param event - The protocol event to process and store.
106
+ */
107
+ push(ns: Namespace, event: ProtocolEvent): void;
108
+ /**
109
+ * Gracefully ends the stream: resolves values promises on all known
110
+ * streams, finalizes every transformer, auto-closes streaming
111
+ * channels, flushes any final-value projections as `custom:<name>`
112
+ * events, and closes both event logs.
113
+ *
114
+ * When final-value projections are present, `_events.close()` is
115
+ * deferred until every tracked projection promise has settled so
116
+ * remote consumers observe the flushed values before their event
117
+ * stream ends. Callers do not need to await — `close()` returns
118
+ * synchronously and any downstream consumer iterating
119
+ * {@link _events} naturally waits for the final events.
120
+ */
121
+ close(): void;
122
+ /**
123
+ * Propagates a failure to all transformers, channels, event logs, and
124
+ * stream handles.
125
+ *
126
+ * @param err - The error that caused the run to fail.
127
+ */
128
+ fail(err: unknown): void;
129
+ /**
130
+ * Records that the run was interrupted, appending the supplied payloads
131
+ * for later retrieval.
132
+ *
133
+ * @param interrupts - The interrupt payloads to store.
134
+ */
135
+ markInterrupted(interrupts: InterruptPayload[]): void;
136
+ /**
137
+ * Whether the run ended due to an interrupt.
138
+ *
139
+ * @returns `true` if {@link markInterrupted} was called.
140
+ */
141
+ get interrupted(): boolean;
142
+ /**
143
+ * All interrupt payloads collected during the run.
144
+ *
145
+ * @returns A readonly view of the accumulated interrupt payloads.
146
+ */
147
+ get interrupts(): readonly InterruptPayload[];
148
+ /**
149
+ * Returns an async iterator that yields only events whose namespace
150
+ * starts with {@link path}.
151
+ *
152
+ * @param path - Namespace prefix to filter on.
153
+ * @param startAt - Zero-based index into the event log to begin from.
154
+ * @returns An async iterator over matching {@link ProtocolEvent}s.
155
+ */
156
+ subscribeEvents(path: Namespace, startAt?: number): AsyncIterator<ProtocolEvent>;
157
+ }
158
+ //#endregion
159
+ export { REJECT_VALUES, RESOLVE_VALUES, StreamHandle, StreamMux, SubgraphDiscovery };
160
+ //# sourceMappingURL=mux.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mux.d.cts","names":[],"sources":["../../src/stream/mux.ts"],"mappings":";;;;;;;;;cAiDa,cAAA;;;;;cAMA,aAAA;;;;;AA+Cb;UAxCiB,YAAA;EAAA,CACd,cAAA,EAAgB,MAAA;EAAA,CAChB,aAAA,EAAe,GAAA;AAAA;;;;KAwBN,iBAAA;EACV,EAAA,EAAI,SAAA;EACJ,MAAA,EAAQ,YAAA;AAAA;;;;;;;;;;cAYG,SAAA;EAAA;EA6HX;EAAA,SA3HS,OAAA,EAAO,aAAA,CAAA,aAAA;EA2HH;EAAA,SAxHJ,YAAA,EAAY,aAAA,CAAA,iBAAA;EAiKZ;;;;;;;EArHT,QAAA,CAAS,IAAA,EAAM,SAAA,EAAW,MAAA,EAAQ,YAAA;EAoQN;;;;;;;;;;;;;;;;EAhP5B,cAAA,CAAe,WAAA,EAAa,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;EAwD5B,YAAA,CAAa,UAAA,EAAY,MAAA;;;;;;;;;;;;EAyCzB,IAAA,CAAK,EAAA,EAAI,SAAA,EAAW,KAAA,EAAO,aAAA;;;;;;;;;;;;;;EAmD3B,KAAA,CAAA;;;;;;;EAsEA,IAAA,CAAK,GAAA;;;;;;;EAsBL,eAAA,CAAgB,UAAA,EAAY,gBAAA;;;;;;MAUxB,WAAA,CAAA;;;;;;MASA,UAAA,CAAA,YAAuB,gBAAA;;;;;;;;;EAY3B,eAAA,CAAgB,IAAA,EAAM,SAAA,EAAW,OAAA,YAAc,aAAA,CAAc,aAAA;AAAA"}
@@ -0,0 +1,160 @@
1
+ import { InterruptPayload, Namespace, ProtocolEvent, StreamTransformer } from "./types.js";
2
+ import { StreamChannel } from "./stream-channel.js";
3
+ import { STREAM_EVENTS_V3_MODES } from "./convert.js";
4
+
5
+ //#region src/stream/mux.d.ts
6
+ /**
7
+ * Symbol key used by {@link StreamMux} to resolve the values promise on a
8
+ * stream handle. Using a symbol keeps this off the public autocomplete surface.
9
+ */
10
+ declare const RESOLVE_VALUES: unique symbol;
11
+ /**
12
+ * Symbol key used by {@link StreamMux} to reject the values promise on a
13
+ * stream handle. Using a symbol keeps this off the public autocomplete surface.
14
+ */
15
+ declare const REJECT_VALUES: unique symbol;
16
+ /**
17
+ * Minimal interface that {@link StreamMux} requires from stream handles
18
+ * for lifecycle resolution. This avoids a direct dependency on
19
+ * `GraphRunStream` / `SubgraphRunStream`.
20
+ */
21
+ interface StreamHandle {
22
+ [RESOLVE_VALUES](values: unknown): void;
23
+ [REJECT_VALUES](err: unknown): void;
24
+ }
25
+ /**
26
+ * A discovered subgraph namespace paired with its run stream handle.
27
+ */
28
+ type SubgraphDiscovery = {
29
+ ns: Namespace;
30
+ stream: StreamHandle;
31
+ };
32
+ /**
33
+ * Central event dispatcher that routes {@link ProtocolEvent}s through a
34
+ * pipeline of {@link StreamTransformer}s, manages namespace discovery for
35
+ * subgraph streams, and exposes async iteration over filtered event
36
+ * sequences.
37
+ *
38
+ * One `StreamMux` instance exists per top-level
39
+ * `streamEvents(..., { version: "v3" })` invocation.
40
+ */
41
+ declare class StreamMux {
42
+ #private;
43
+ /** @internal All protocol events in arrival order (after reducer pipeline). */
44
+ readonly _events: StreamChannel<ProtocolEvent>;
45
+ /** @internal New-namespace discovery notifications. */
46
+ readonly _discoveries: StreamChannel<SubgraphDiscovery>;
47
+ /**
48
+ * Associates a pre-existing stream handle with a namespace so that
49
+ * {@link close} can resolve its values promise later.
50
+ *
51
+ * @param path - The namespace path to register.
52
+ * @param stream - The run stream handle for that namespace.
53
+ */
54
+ register(path: Namespace, stream: StreamHandle): void;
55
+ /**
56
+ * Registers a transformer and replays all buffered events through it so
57
+ * it catches up with events already processed by the mux. When the event
58
+ * log is empty (typical at construction time) the replay is a no-op.
59
+ *
60
+ * The transformer must already have been initialised (i.e. `init()` called
61
+ * and any projection wired). The sequence is:
62
+ *
63
+ * 1. Snapshot the current event log length.
64
+ * 2. Append the transformer so future {@link push} calls reach it.
65
+ * 3. Replay events `[0, snapshot)` through `process()`.
66
+ * 4. If the mux is already closed, call `finalize()` (or `fail()`)
67
+ * immediately so the transformer's log/channel terminates cleanly.
68
+ *
69
+ * @param transformer - An already-initialised transformer to register.
70
+ */
71
+ addTransformer(transformer: StreamTransformer<unknown>): void;
72
+ /**
73
+ * Scans a transformer projection for streaming and final-value primitives.
74
+ * Remote stream channels are wired to auto-forward to the protocol event
75
+ * stream; local stream channels are tracked for lifecycle only.
76
+ *
77
+ * Two projection shapes are recognised:
78
+ *
79
+ * - {@link StreamChannel} values — named channels forward each `push()`
80
+ * immediately as a protocol event on the channel's declared
81
+ * `channelName` method. Unnamed channels remain in-process-only.
82
+ *
83
+ * - `PromiseLike<unknown>` values — tracked as final-value
84
+ * projections and flushed on {@link close} as a single
85
+ * `custom:<key>` event, where `<key>` is the projection key.
86
+ * This mirrors the in-process `await run.extensions.<key>`
87
+ * ergonomics on remote clients via
88
+ * `await thread.extensions.<key>`.
89
+ *
90
+ * Plain values that are neither are ignored — they remain in-process-only,
91
+ * matching prior behaviour.
92
+ *
93
+ * @param projection - The object returned by `transformer.init()`.
94
+ */
95
+ wireChannels(projection: Record<string, unknown>): void;
96
+ /**
97
+ * Distributes an event through the transformer pipeline, then appends it to
98
+ * the main event log.
99
+ *
100
+ * Subgraph discovery (materializing a {@link StreamHandle} for each
101
+ * newly observed top-level namespace) is handled by the
102
+ * {@link createSubgraphDiscoveryTransformer} when installed, not here.
103
+ *
104
+ * @param ns - The namespace path that produced the event.
105
+ * @param event - The protocol event to process and store.
106
+ */
107
+ push(ns: Namespace, event: ProtocolEvent): void;
108
+ /**
109
+ * Gracefully ends the stream: resolves values promises on all known
110
+ * streams, finalizes every transformer, auto-closes streaming
111
+ * channels, flushes any final-value projections as `custom:<name>`
112
+ * events, and closes both event logs.
113
+ *
114
+ * When final-value projections are present, `_events.close()` is
115
+ * deferred until every tracked projection promise has settled so
116
+ * remote consumers observe the flushed values before their event
117
+ * stream ends. Callers do not need to await — `close()` returns
118
+ * synchronously and any downstream consumer iterating
119
+ * {@link _events} naturally waits for the final events.
120
+ */
121
+ close(): void;
122
+ /**
123
+ * Propagates a failure to all transformers, channels, event logs, and
124
+ * stream handles.
125
+ *
126
+ * @param err - The error that caused the run to fail.
127
+ */
128
+ fail(err: unknown): void;
129
+ /**
130
+ * Records that the run was interrupted, appending the supplied payloads
131
+ * for later retrieval.
132
+ *
133
+ * @param interrupts - The interrupt payloads to store.
134
+ */
135
+ markInterrupted(interrupts: InterruptPayload[]): void;
136
+ /**
137
+ * Whether the run ended due to an interrupt.
138
+ *
139
+ * @returns `true` if {@link markInterrupted} was called.
140
+ */
141
+ get interrupted(): boolean;
142
+ /**
143
+ * All interrupt payloads collected during the run.
144
+ *
145
+ * @returns A readonly view of the accumulated interrupt payloads.
146
+ */
147
+ get interrupts(): readonly InterruptPayload[];
148
+ /**
149
+ * Returns an async iterator that yields only events whose namespace
150
+ * starts with {@link path}.
151
+ *
152
+ * @param path - Namespace prefix to filter on.
153
+ * @param startAt - Zero-based index into the event log to begin from.
154
+ * @returns An async iterator over matching {@link ProtocolEvent}s.
155
+ */
156
+ subscribeEvents(path: Namespace, startAt?: number): AsyncIterator<ProtocolEvent>;
157
+ }
158
+ //#endregion
159
+ export { REJECT_VALUES, RESOLVE_VALUES, StreamHandle, StreamMux, SubgraphDiscovery };
160
+ //# sourceMappingURL=mux.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mux.d.ts","names":[],"sources":["../../src/stream/mux.ts"],"mappings":";;;;;;;;;cAiDa,cAAA;AAuCb;;;;AAAA,cAjCa,aAAA;;;;;;UAOI,YAAA;EAAA,CACd,cAAA,EAAgB,MAAA;EAAA,CAChB,aAAA,EAAe,GAAA;AAAA;;;;KAwBN,iBAAA;EACV,EAAA,EAAI,SAAA;EACJ,MAAA,EAAQ,YAAA;AAAA;;;;;;;;;;cAYG,SAAA;EAAA;EAqEI;EAAA,SAnEN,OAAA,EAAO,aAAA,CAAA,aAAA;EA2HS;EAAA,SAxHhB,YAAA,EAAY,aAAA,CAAA,iBAAA;EAiKrB;;;;;;;EArHA,QAAA,CAAS,IAAA,EAAM,SAAA,EAAW,MAAA,EAAQ,YAAA;EAoQlC;;;;;;;;;;;;;;;;EAhPA,cAAA,CAAe,WAAA,EAAa,iBAAA;;;;;;;;;;;;;;;;;;;;;;;;EAwD5B,YAAA,CAAa,UAAA,EAAY,MAAA;;;;;;;;;;;;EAyCzB,IAAA,CAAK,EAAA,EAAI,SAAA,EAAW,KAAA,EAAO,aAAA;;;;;;;;;;;;;;EAmD3B,KAAA,CAAA;;;;;;;EAsEA,IAAA,CAAK,GAAA;;;;;;;EAsBL,eAAA,CAAgB,UAAA,EAAY,gBAAA;;;;;;MAUxB,WAAA,CAAA;;;;;;MASA,UAAA,CAAA,YAAuB,gBAAA;;;;;;;;;EAY3B,eAAA,CAAgB,IAAA,EAAM,SAAA,EAAW,OAAA,YAAc,aAAA,CAAc,aAAA;AAAA"}