@langchain/langgraph 1.0.12 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/channels/any_value.cjs +46 -0
- package/dist/channels/any_value.cjs.map +1 -0
- package/dist/channels/any_value.d.cts +23 -0
- package/dist/channels/any_value.d.cts.map +1 -0
- package/dist/channels/any_value.d.ts +23 -0
- package/dist/channels/any_value.d.ts.map +1 -0
- package/dist/channels/any_value.js +46 -0
- package/dist/channels/any_value.js.map +1 -0
- package/dist/channels/base.cjs +101 -0
- package/dist/channels/base.cjs.map +1 -0
- package/dist/channels/base.d.cts +79 -0
- package/dist/channels/base.d.cts.map +1 -0
- package/dist/channels/base.d.ts +79 -0
- package/dist/channels/base.d.ts.map +1 -0
- package/dist/channels/base.js +97 -0
- package/dist/channels/base.js.map +1 -0
- package/dist/channels/binop.cjs +49 -0
- package/dist/channels/binop.cjs.map +1 -0
- package/dist/channels/binop.d.cts +22 -0
- package/dist/channels/binop.d.cts.map +1 -0
- package/dist/channels/binop.d.ts +22 -0
- package/dist/channels/binop.d.ts.map +1 -0
- package/dist/channels/binop.js +49 -0
- package/dist/channels/binop.js.map +1 -0
- package/dist/channels/dynamic_barrier_value.cjs +75 -0
- package/dist/channels/dynamic_barrier_value.cjs.map +1 -0
- package/dist/channels/dynamic_barrier_value.d.cts +40 -0
- package/dist/channels/dynamic_barrier_value.d.cts.map +1 -0
- package/dist/channels/dynamic_barrier_value.d.ts +40 -0
- package/dist/channels/dynamic_barrier_value.d.ts.map +1 -0
- package/dist/channels/dynamic_barrier_value.js +75 -0
- package/dist/channels/dynamic_barrier_value.js.map +1 -0
- package/dist/channels/ephemeral_value.cjs +46 -0
- package/dist/channels/ephemeral_value.cjs.map +1 -0
- package/dist/channels/ephemeral_value.d.cts +21 -0
- package/dist/channels/ephemeral_value.d.cts.map +1 -0
- package/dist/channels/ephemeral_value.d.ts +21 -0
- package/dist/channels/ephemeral_value.d.ts.map +1 -0
- package/dist/channels/ephemeral_value.js +46 -0
- package/dist/channels/ephemeral_value.js.map +1 -0
- package/dist/channels/index.cjs +21 -0
- package/dist/channels/index.d.cts +9 -0
- package/dist/channels/index.d.ts +9 -0
- package/dist/channels/index.js +10 -0
- package/dist/channels/last_value.cjs +98 -0
- package/dist/channels/last_value.cjs.map +1 -0
- package/dist/channels/last_value.d.cts +42 -0
- package/dist/channels/last_value.d.cts.map +1 -0
- package/dist/channels/last_value.d.ts +42 -0
- package/dist/channels/last_value.d.ts.map +1 -0
- package/dist/channels/last_value.js +97 -0
- package/dist/channels/last_value.js.map +1 -0
- package/dist/channels/named_barrier_value.cjs +116 -0
- package/dist/channels/named_barrier_value.cjs.map +1 -0
- package/dist/channels/named_barrier_value.d.cts +44 -0
- package/dist/channels/named_barrier_value.d.cts.map +1 -0
- package/dist/channels/named_barrier_value.d.ts +44 -0
- package/dist/channels/named_barrier_value.d.ts.map +1 -0
- package/dist/channels/named_barrier_value.js +114 -0
- package/dist/channels/named_barrier_value.js.map +1 -0
- package/dist/channels/topic.cjs +65 -0
- package/dist/channels/topic.cjs.map +1 -0
- package/dist/channels/topic.d.cts +32 -0
- package/dist/channels/topic.d.cts.map +1 -0
- package/dist/channels/topic.d.ts +32 -0
- package/dist/channels/topic.d.ts.map +1 -0
- package/dist/channels/topic.js +65 -0
- package/dist/channels/topic.js.map +1 -0
- package/dist/constants.cjs +406 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +281 -0
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.ts +281 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +362 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors.cjs +163 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +77 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.ts +77 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +146 -0
- package/dist/errors.js.map +1 -0
- package/dist/func/index.cjs +299 -0
- package/dist/func/index.cjs.map +1 -0
- package/dist/func/index.d.cts +288 -0
- package/dist/func/index.d.cts.map +1 -0
- package/dist/func/index.d.ts +288 -0
- package/dist/func/index.d.ts.map +1 -0
- package/dist/func/index.js +297 -0
- package/dist/func/index.js.map +1 -0
- package/dist/func/types.d.cts +62 -0
- package/dist/func/types.d.cts.map +1 -0
- package/dist/func/types.d.ts +62 -0
- package/dist/func/types.d.ts.map +1 -0
- package/dist/graph/annotation.cjs +101 -0
- package/dist/graph/annotation.cjs.map +1 -0
- package/dist/graph/annotation.d.cts +116 -0
- package/dist/graph/annotation.d.cts.map +1 -0
- package/dist/graph/annotation.d.ts +116 -0
- package/dist/graph/annotation.d.ts.map +1 -0
- package/dist/graph/annotation.js +99 -0
- package/dist/graph/annotation.js.map +1 -0
- package/dist/graph/graph.cjs +420 -0
- package/dist/graph/graph.cjs.map +1 -0
- package/dist/graph/graph.d.cts +108 -0
- package/dist/graph/graph.d.cts.map +1 -0
- package/dist/graph/graph.d.ts +108 -0
- package/dist/graph/graph.d.ts.map +1 -0
- package/dist/graph/graph.js +418 -0
- package/dist/graph/graph.js.map +1 -0
- package/dist/graph/index.cjs +5 -0
- package/dist/graph/index.js +7 -0
- package/dist/graph/message.cjs +97 -0
- package/dist/graph/message.cjs.map +1 -0
- package/dist/graph/message.d.cts +40 -0
- package/dist/graph/message.d.cts.map +1 -0
- package/dist/graph/message.d.ts +40 -0
- package/dist/graph/message.d.ts.map +1 -0
- package/dist/graph/message.js +94 -0
- package/dist/graph/message.js.map +1 -0
- package/dist/graph/messages_annotation.cjs +109 -0
- package/dist/graph/messages_annotation.cjs.map +1 -0
- package/dist/graph/messages_annotation.d.cts +112 -0
- package/dist/graph/messages_annotation.d.cts.map +1 -0
- package/dist/graph/messages_annotation.d.ts +112 -0
- package/dist/graph/messages_annotation.d.ts.map +1 -0
- package/dist/graph/messages_annotation.js +107 -0
- package/dist/graph/messages_annotation.js.map +1 -0
- package/dist/graph/state.cjs +494 -0
- package/dist/graph/state.cjs.map +1 -0
- package/dist/graph/state.d.cts +229 -0
- package/dist/graph/state.d.cts.map +1 -0
- package/dist/graph/state.d.ts +229 -0
- package/dist/graph/state.d.ts.map +1 -0
- package/dist/graph/state.js +493 -0
- package/dist/graph/state.js.map +1 -0
- package/dist/graph/zod/index.cjs +10 -0
- package/dist/graph/zod/index.d.cts +3 -0
- package/dist/graph/zod/index.d.ts +3 -0
- package/dist/graph/zod/index.js +5 -0
- package/dist/graph/zod/meta.cjs +144 -0
- package/dist/graph/zod/meta.cjs.map +1 -0
- package/dist/graph/zod/meta.d.cts +115 -0
- package/dist/graph/zod/meta.d.cts.map +1 -0
- package/dist/graph/zod/meta.d.ts +115 -0
- package/dist/graph/zod/meta.d.ts.map +1 -0
- package/dist/graph/zod/meta.js +141 -0
- package/dist/graph/zod/meta.js.map +1 -0
- package/dist/graph/zod/plugin.cjs +39 -0
- package/dist/graph/zod/plugin.cjs.map +1 -0
- package/dist/graph/zod/plugin.js +40 -0
- package/dist/graph/zod/plugin.js.map +1 -0
- package/dist/graph/zod/schema.cjs +98 -0
- package/dist/graph/zod/schema.cjs.map +1 -0
- package/dist/graph/zod/schema.d.cts +38 -0
- package/dist/graph/zod/schema.d.cts.map +1 -0
- package/dist/graph/zod/schema.d.ts +38 -0
- package/dist/graph/zod/schema.d.ts.map +1 -0
- package/dist/graph/zod/schema.js +94 -0
- package/dist/graph/zod/schema.js.map +1 -0
- package/dist/graph/zod/zod-registry.cjs +42 -0
- package/dist/graph/zod/zod-registry.cjs.map +1 -0
- package/dist/graph/zod/zod-registry.d.cts +49 -0
- package/dist/graph/zod/zod-registry.d.cts.map +1 -0
- package/dist/graph/zod/zod-registry.d.ts +49 -0
- package/dist/graph/zod/zod-registry.d.ts.map +1 -0
- package/dist/graph/zod/zod-registry.js +41 -0
- package/dist/graph/zod/zod-registry.js.map +1 -0
- package/dist/hash.cjs +265 -0
- package/dist/hash.cjs.map +1 -0
- package/dist/hash.js +263 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.cjs +111 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +26 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/interrupt.cjs +79 -0
- package/dist/interrupt.cjs.map +1 -0
- package/dist/interrupt.d.cts +55 -0
- package/dist/interrupt.d.cts.map +1 -0
- package/dist/interrupt.d.ts +55 -0
- package/dist/interrupt.d.ts.map +1 -0
- package/dist/interrupt.js +79 -0
- package/dist/interrupt.js.map +1 -0
- package/dist/prebuilt/agentName.cjs +148 -0
- package/dist/prebuilt/agentName.cjs.map +1 -0
- package/dist/prebuilt/agentName.d.cts +42 -0
- package/dist/prebuilt/agentName.d.cts.map +1 -0
- package/dist/prebuilt/agentName.d.ts +42 -0
- package/dist/prebuilt/agentName.d.ts.map +1 -0
- package/dist/prebuilt/agentName.js +148 -0
- package/dist/prebuilt/agentName.js.map +1 -0
- package/dist/prebuilt/agent_executor.cjs +41 -0
- package/dist/prebuilt/agent_executor.cjs.map +1 -0
- package/dist/prebuilt/agent_executor.d.cts +58 -0
- package/dist/prebuilt/agent_executor.d.cts.map +1 -0
- package/dist/prebuilt/agent_executor.d.ts +58 -0
- package/dist/prebuilt/agent_executor.d.ts.map +1 -0
- package/dist/prebuilt/agent_executor.js +41 -0
- package/dist/prebuilt/agent_executor.js.map +1 -0
- package/dist/prebuilt/chat_agent_executor.cjs +62 -0
- package/dist/prebuilt/chat_agent_executor.cjs.map +1 -0
- package/dist/prebuilt/chat_agent_executor.d.cts +23 -0
- package/dist/prebuilt/chat_agent_executor.d.cts.map +1 -0
- package/dist/prebuilt/chat_agent_executor.d.ts +23 -0
- package/dist/prebuilt/chat_agent_executor.d.ts.map +1 -0
- package/dist/prebuilt/chat_agent_executor.js +62 -0
- package/dist/prebuilt/chat_agent_executor.js.map +1 -0
- package/dist/prebuilt/index.cjs +15 -0
- package/dist/prebuilt/index.d.cts +8 -0
- package/dist/prebuilt/index.d.ts +8 -0
- package/dist/prebuilt/index.js +8 -0
- package/dist/prebuilt/interrupt.d.cts +60 -0
- package/dist/prebuilt/interrupt.d.cts.map +1 -0
- package/dist/prebuilt/interrupt.d.ts +60 -0
- package/dist/prebuilt/interrupt.d.ts.map +1 -0
- package/dist/prebuilt/react_agent_executor.cjs +339 -0
- package/dist/prebuilt/react_agent_executor.cjs.map +1 -0
- package/dist/prebuilt/react_agent_executor.d.cts +211 -0
- package/dist/prebuilt/react_agent_executor.d.cts.map +1 -0
- package/dist/prebuilt/react_agent_executor.d.ts +211 -0
- package/dist/prebuilt/react_agent_executor.d.ts.map +1 -0
- package/dist/prebuilt/react_agent_executor.js +338 -0
- package/dist/prebuilt/react_agent_executor.js.map +1 -0
- package/dist/prebuilt/tool_executor.cjs +43 -0
- package/dist/prebuilt/tool_executor.cjs.map +1 -0
- package/dist/prebuilt/tool_executor.d.cts +40 -0
- package/dist/prebuilt/tool_executor.d.cts.map +1 -0
- package/dist/prebuilt/tool_executor.d.ts +40 -0
- package/dist/prebuilt/tool_executor.d.ts.map +1 -0
- package/dist/prebuilt/tool_executor.js +43 -0
- package/dist/prebuilt/tool_executor.js.map +1 -0
- package/dist/prebuilt/tool_node.cjs +247 -0
- package/dist/prebuilt/tool_node.cjs.map +1 -0
- package/dist/prebuilt/tool_node.d.cts +180 -0
- package/dist/prebuilt/tool_node.d.cts.map +1 -0
- package/dist/prebuilt/tool_node.d.ts +180 -0
- package/dist/prebuilt/tool_node.d.ts.map +1 -0
- package/dist/prebuilt/tool_node.js +246 -0
- package/dist/prebuilt/tool_node.js.map +1 -0
- package/dist/pregel/algo.cjs +565 -0
- package/dist/pregel/algo.cjs.map +1 -0
- package/dist/pregel/algo.d.cts +13 -0
- package/dist/pregel/algo.d.cts.map +1 -0
- package/dist/pregel/algo.d.ts +13 -0
- package/dist/pregel/algo.d.ts.map +1 -0
- package/dist/pregel/algo.js +560 -0
- package/dist/pregel/algo.js.map +1 -0
- package/dist/pregel/call.cjs +50 -0
- package/dist/pregel/call.cjs.map +1 -0
- package/dist/pregel/call.js +48 -0
- package/dist/pregel/call.js.map +1 -0
- package/dist/pregel/debug.cjs +172 -0
- package/dist/pregel/debug.cjs.map +1 -0
- package/dist/pregel/debug.js +166 -0
- package/dist/pregel/debug.js.map +1 -0
- package/dist/pregel/index.cjs +1163 -0
- package/dist/pregel/index.cjs.map +1 -0
- package/dist/pregel/index.d.cts +498 -0
- package/dist/pregel/index.d.cts.map +1 -0
- package/dist/pregel/index.d.ts +498 -0
- package/dist/pregel/index.d.ts.map +1 -0
- package/dist/pregel/index.js +1162 -0
- package/dist/pregel/index.js.map +1 -0
- package/dist/pregel/io.cjs +140 -0
- package/dist/pregel/io.cjs.map +1 -0
- package/dist/pregel/io.js +135 -0
- package/dist/pregel/io.js.map +1 -0
- package/dist/pregel/loop.cjs +545 -0
- package/dist/pregel/loop.cjs.map +1 -0
- package/dist/pregel/loop.js +545 -0
- package/dist/pregel/loop.js.map +1 -0
- package/dist/pregel/messages.cjs +107 -0
- package/dist/pregel/messages.cjs.map +1 -0
- package/dist/pregel/messages.js +107 -0
- package/dist/pregel/messages.js.map +1 -0
- package/dist/pregel/read.cjs +151 -0
- package/dist/pregel/read.cjs.map +1 -0
- package/dist/pregel/read.d.cts +45 -0
- package/dist/pregel/read.d.cts.map +1 -0
- package/dist/pregel/read.d.ts +45 -0
- package/dist/pregel/read.d.ts.map +1 -0
- package/dist/pregel/read.js +150 -0
- package/dist/pregel/read.js.map +1 -0
- package/dist/pregel/remote.cjs +341 -0
- package/dist/pregel/remote.cjs.map +1 -0
- package/dist/pregel/remote.d.cts +118 -0
- package/dist/pregel/remote.d.cts.map +1 -0
- package/dist/pregel/remote.d.ts +118 -0
- package/dist/pregel/remote.d.ts.map +1 -0
- package/dist/pregel/remote.js +341 -0
- package/dist/pregel/remote.js.map +1 -0
- package/dist/pregel/retry.cjs +91 -0
- package/dist/pregel/retry.cjs.map +1 -0
- package/dist/pregel/retry.js +91 -0
- package/dist/pregel/retry.js.map +1 -0
- package/dist/pregel/runnable_types.d.cts +43 -0
- package/dist/pregel/runnable_types.d.cts.map +1 -0
- package/dist/pregel/runnable_types.d.ts +43 -0
- package/dist/pregel/runnable_types.d.ts.map +1 -0
- package/dist/pregel/runner.cjs +228 -0
- package/dist/pregel/runner.cjs.map +1 -0
- package/dist/pregel/runner.js +228 -0
- package/dist/pregel/runner.js.map +1 -0
- package/dist/pregel/stream.cjs +197 -0
- package/dist/pregel/stream.cjs.map +1 -0
- package/dist/pregel/stream.js +195 -0
- package/dist/pregel/stream.js.map +1 -0
- package/dist/pregel/types.cjs +27 -0
- package/dist/pregel/types.cjs.map +1 -0
- package/dist/pregel/types.d.cts +440 -0
- package/dist/pregel/types.d.cts.map +1 -0
- package/dist/pregel/types.d.ts +440 -0
- package/dist/pregel/types.d.ts.map +1 -0
- package/dist/pregel/types.js +25 -0
- package/dist/pregel/types.js.map +1 -0
- package/dist/pregel/utils/config.cjs +121 -0
- package/dist/pregel/utils/config.cjs.map +1 -0
- package/dist/pregel/utils/config.d.cts +36 -0
- package/dist/pregel/utils/config.d.cts.map +1 -0
- package/dist/pregel/utils/config.d.ts +36 -0
- package/dist/pregel/utils/config.d.ts.map +1 -0
- package/dist/pregel/utils/config.js +115 -0
- package/dist/pregel/utils/config.js.map +1 -0
- package/dist/pregel/utils/index.cjs +102 -0
- package/dist/pregel/utils/index.cjs.map +1 -0
- package/dist/pregel/utils/index.d.cts +51 -0
- package/dist/pregel/utils/index.d.cts.map +1 -0
- package/dist/pregel/utils/index.d.ts +51 -0
- package/dist/pregel/utils/index.d.ts.map +1 -0
- package/dist/pregel/utils/index.js +96 -0
- package/dist/pregel/utils/index.js.map +1 -0
- package/dist/pregel/utils/subgraph.cjs +18 -0
- package/dist/pregel/utils/subgraph.cjs.map +1 -0
- package/dist/pregel/utils/subgraph.js +16 -0
- package/dist/pregel/utils/subgraph.js.map +1 -0
- package/dist/pregel/validate.cjs +45 -0
- package/dist/pregel/validate.cjs.map +1 -0
- package/dist/pregel/validate.js +44 -0
- package/dist/pregel/validate.js.map +1 -0
- package/dist/pregel/write.cjs +96 -0
- package/dist/pregel/write.cjs.map +1 -0
- package/dist/pregel/write.d.cts +31 -0
- package/dist/pregel/write.d.cts.map +1 -0
- package/dist/pregel/write.d.ts +31 -0
- package/dist/pregel/write.d.ts.map +1 -0
- package/dist/pregel/write.js +95 -0
- package/dist/pregel/write.js.map +1 -0
- package/dist/remote.cjs +3 -0
- package/dist/remote.d.cts +2 -0
- package/dist/remote.d.ts +2 -0
- package/dist/remote.js +3 -0
- package/dist/setup/async_local_storage.cjs +11 -0
- package/dist/setup/async_local_storage.cjs.map +1 -0
- package/dist/setup/async_local_storage.js +11 -0
- package/dist/setup/async_local_storage.js.map +1 -0
- package/dist/utils.cjs +86 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +25 -0
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.ts +25 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +80 -0
- package/dist/utils.js.map +1 -0
- package/dist/web.cjs +95 -0
- package/dist/web.d.cts +23 -0
- package/dist/web.d.ts +23 -0
- package/dist/web.js +15 -0
- package/dist/writer.cjs +14 -0
- package/dist/writer.cjs.map +1 -0
- package/dist/writer.d.cts +6 -0
- package/dist/writer.d.cts.map +1 -0
- package/dist/writer.d.ts +6 -0
- package/dist/writer.d.ts.map +1 -0
- package/dist/writer.js +14 -0
- package/dist/writer.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { IterableReadableStream } from "@langchain/core/utils/stream";
|
|
2
|
+
|
|
3
|
+
//#region src/pregel/stream.ts
|
|
4
|
+
/**
|
|
5
|
+
* A wrapper around an IterableReadableStream that allows for aborting the stream when
|
|
6
|
+
* {@link cancel} is called.
|
|
7
|
+
*/
|
|
8
|
+
var IterableReadableStreamWithAbortSignal = class extends IterableReadableStream {
|
|
9
|
+
_abortController;
|
|
10
|
+
_innerReader;
|
|
11
|
+
/**
|
|
12
|
+
* @param readableStream - The stream to wrap.
|
|
13
|
+
* @param abortController - The abort controller to use. Optional. One will be created if not provided.
|
|
14
|
+
*/
|
|
15
|
+
constructor(readableStream, abortController) {
|
|
16
|
+
const reader = readableStream.getReader();
|
|
17
|
+
const ac = abortController ?? new AbortController();
|
|
18
|
+
super({ start(controller) {
|
|
19
|
+
return pump();
|
|
20
|
+
function pump() {
|
|
21
|
+
return reader.read().then(({ done, value }) => {
|
|
22
|
+
if (done) {
|
|
23
|
+
controller.close();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
controller.enqueue(value);
|
|
27
|
+
return pump();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
} });
|
|
31
|
+
this._abortController = ac;
|
|
32
|
+
this._innerReader = reader;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Aborts the stream, abandoning any pending operations in progress. Calling this triggers an
|
|
36
|
+
* {@link AbortSignal} that is propagated to the tasks that are producing the data for this stream.
|
|
37
|
+
* @param reason - The reason for aborting the stream. Optional.
|
|
38
|
+
*/
|
|
39
|
+
async cancel(reason) {
|
|
40
|
+
this._abortController.abort(reason);
|
|
41
|
+
this._innerReader.releaseLock();
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The {@link AbortSignal} for the stream. Aborted when {@link cancel} is called.
|
|
45
|
+
*/
|
|
46
|
+
get signal() {
|
|
47
|
+
return this._abortController.signal;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var IterableReadableWritableStream = class extends IterableReadableStream {
|
|
51
|
+
modes;
|
|
52
|
+
controller;
|
|
53
|
+
passthroughFn;
|
|
54
|
+
_closed = false;
|
|
55
|
+
get closed() {
|
|
56
|
+
return this._closed;
|
|
57
|
+
}
|
|
58
|
+
constructor(params) {
|
|
59
|
+
let streamControllerPromiseResolver;
|
|
60
|
+
const streamControllerPromise = new Promise((resolve) => {
|
|
61
|
+
streamControllerPromiseResolver = resolve;
|
|
62
|
+
});
|
|
63
|
+
super({ start: (controller) => {
|
|
64
|
+
streamControllerPromiseResolver(controller);
|
|
65
|
+
} });
|
|
66
|
+
streamControllerPromise.then((controller) => {
|
|
67
|
+
this.controller = controller;
|
|
68
|
+
});
|
|
69
|
+
this.passthroughFn = params.passthroughFn;
|
|
70
|
+
this.modes = params.modes;
|
|
71
|
+
}
|
|
72
|
+
push(chunk) {
|
|
73
|
+
this.passthroughFn?.(chunk);
|
|
74
|
+
this.controller.enqueue(chunk);
|
|
75
|
+
}
|
|
76
|
+
close() {
|
|
77
|
+
try {
|
|
78
|
+
this.controller.close();
|
|
79
|
+
} catch (e) {} finally {
|
|
80
|
+
this._closed = true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
error(e) {
|
|
84
|
+
this.controller.error(e);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
function _stringifyAsDict(obj) {
|
|
88
|
+
return JSON.stringify(obj, function(key, value) {
|
|
89
|
+
const rawValue = this[key];
|
|
90
|
+
if (rawValue != null && typeof rawValue === "object" && "toDict" in rawValue && typeof rawValue.toDict === "function") {
|
|
91
|
+
const { type, data } = rawValue.toDict();
|
|
92
|
+
return {
|
|
93
|
+
...data,
|
|
94
|
+
type
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return value;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function _serializeError(error) {
|
|
101
|
+
if (error instanceof Error) return {
|
|
102
|
+
error: error.name,
|
|
103
|
+
message: error.message
|
|
104
|
+
};
|
|
105
|
+
return {
|
|
106
|
+
error: "Error",
|
|
107
|
+
message: JSON.stringify(error)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function _isRunnableConfig(config) {
|
|
111
|
+
if (typeof config !== "object" || config == null) return false;
|
|
112
|
+
return "configurable" in config && typeof config.configurable === "object" && config.configurable != null;
|
|
113
|
+
}
|
|
114
|
+
function _extractCheckpointFromConfig(config) {
|
|
115
|
+
if (!_isRunnableConfig(config) || !config.configurable.thread_id) return null;
|
|
116
|
+
return {
|
|
117
|
+
thread_id: config.configurable.thread_id,
|
|
118
|
+
checkpoint_ns: config.configurable.checkpoint_ns || "",
|
|
119
|
+
checkpoint_id: config.configurable.checkpoint_id || null,
|
|
120
|
+
checkpoint_map: config.configurable.checkpoint_map || null
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function _serializeConfig(config) {
|
|
124
|
+
if (_isRunnableConfig(config)) {
|
|
125
|
+
const configurable = Object.fromEntries(Object.entries(config.configurable).filter(([key]) => !key.startsWith("__")));
|
|
126
|
+
const newConfig = {
|
|
127
|
+
...config,
|
|
128
|
+
configurable
|
|
129
|
+
};
|
|
130
|
+
delete newConfig.callbacks;
|
|
131
|
+
return newConfig;
|
|
132
|
+
}
|
|
133
|
+
return config;
|
|
134
|
+
}
|
|
135
|
+
function _serializeCheckpoint(payload) {
|
|
136
|
+
const result = {
|
|
137
|
+
...payload,
|
|
138
|
+
checkpoint: _extractCheckpointFromConfig(payload.config),
|
|
139
|
+
parent_checkpoint: _extractCheckpointFromConfig(payload.parentConfig),
|
|
140
|
+
config: _serializeConfig(payload.config),
|
|
141
|
+
parent_config: _serializeConfig(payload.parentConfig),
|
|
142
|
+
tasks: payload.tasks.map((task) => {
|
|
143
|
+
if (_isRunnableConfig(task.state)) {
|
|
144
|
+
const checkpoint = _extractCheckpointFromConfig(task.state);
|
|
145
|
+
if (checkpoint != null) {
|
|
146
|
+
const cloneTask = {
|
|
147
|
+
...task,
|
|
148
|
+
checkpoint
|
|
149
|
+
};
|
|
150
|
+
delete cloneTask.state;
|
|
151
|
+
return cloneTask;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return task;
|
|
155
|
+
})
|
|
156
|
+
};
|
|
157
|
+
delete result.parentConfig;
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
function toEventStream(stream) {
|
|
161
|
+
const encoder = new TextEncoder();
|
|
162
|
+
return new ReadableStream({ async start(controller) {
|
|
163
|
+
const enqueueChunk = (sse) => {
|
|
164
|
+
controller.enqueue(encoder.encode(`event: ${sse.event}\ndata: ${_stringifyAsDict(sse.data)}\n\n`));
|
|
165
|
+
};
|
|
166
|
+
try {
|
|
167
|
+
for await (const payload of stream) {
|
|
168
|
+
const [ns, mode, chunk] = payload;
|
|
169
|
+
let data = chunk;
|
|
170
|
+
if (mode === "debug") {
|
|
171
|
+
const debugChunk = chunk;
|
|
172
|
+
if (debugChunk.type === "checkpoint") data = {
|
|
173
|
+
...debugChunk,
|
|
174
|
+
payload: _serializeCheckpoint(debugChunk.payload)
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
if (mode === "checkpoints") data = _serializeCheckpoint(chunk);
|
|
178
|
+
enqueueChunk({
|
|
179
|
+
event: ns?.length ? `${mode}|${ns.join("|")}` : mode,
|
|
180
|
+
data
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
} catch (error) {
|
|
184
|
+
enqueueChunk({
|
|
185
|
+
event: "error",
|
|
186
|
+
data: _serializeError(error)
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
controller.close();
|
|
190
|
+
} });
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
//#endregion
|
|
194
|
+
export { IterableReadableStreamWithAbortSignal, IterableReadableWritableStream, toEventStream };
|
|
195
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","names":[],"sources":["../../src/pregel/stream.ts"],"sourcesContent":["import { IterableReadableStream } from \"@langchain/core/utils/stream\";\nimport type { RunnableConfig } from \"@langchain/core/runnables\";\nimport type { StreamMode, StreamOutputMap } from \"./types.js\";\n\n// [namespace, streamMode, payload]\nexport type StreamChunk = [string[], StreamMode, unknown];\n\ntype StreamCheckpointsOutput<StreamValues> = StreamOutputMap<\n \"checkpoints\",\n false,\n StreamValues,\n unknown,\n string,\n unknown,\n unknown,\n undefined\n>;\n\ntype AnyStreamOutput = StreamOutputMap<\n StreamMode[],\n true,\n unknown,\n unknown,\n string,\n unknown,\n unknown,\n undefined\n>;\n\n/**\n * A wrapper around an IterableReadableStream that allows for aborting the stream when\n * {@link cancel} is called.\n */\nexport class IterableReadableStreamWithAbortSignal<\n T\n> extends IterableReadableStream<T> {\n protected _abortController: AbortController;\n\n protected _innerReader: ReadableStreamDefaultReader<T>;\n\n /**\n * @param readableStream - The stream to wrap.\n * @param abortController - The abort controller to use. Optional. One will be created if not provided.\n */\n constructor(\n readableStream: ReadableStream<T>,\n abortController?: AbortController\n ) {\n const reader = readableStream.getReader();\n const ac = abortController ?? new AbortController();\n super({\n start(controller: ReadableStreamDefaultController<T>) {\n return pump();\n function pump(): Promise<T | undefined> {\n return reader.read().then(({ done, value }) => {\n // When no more data needs to be consumed, close the stream\n if (done) {\n controller.close();\n return;\n }\n // Enqueue the next data chunk into our target stream\n controller.enqueue(value);\n return pump();\n });\n }\n },\n });\n this._abortController = ac;\n this._innerReader = reader;\n }\n\n /**\n * Aborts the stream, abandoning any pending operations in progress. Calling this triggers an\n * {@link AbortSignal} that is propagated to the tasks that are producing the data for this stream.\n * @param reason - The reason for aborting the stream. Optional.\n */\n override async cancel(reason?: unknown) {\n this._abortController.abort(reason);\n this._innerReader.releaseLock();\n }\n\n /**\n * The {@link AbortSignal} for the stream. Aborted when {@link cancel} is called.\n */\n get signal() {\n return this._abortController.signal;\n }\n}\n\nexport class IterableReadableWritableStream extends IterableReadableStream<StreamChunk> {\n modes: Set<StreamMode>;\n\n private controller: ReadableStreamDefaultController;\n\n private passthroughFn?: (chunk: StreamChunk) => void;\n\n private _closed: boolean = false;\n\n get closed() {\n return this._closed;\n }\n\n constructor(params: {\n passthroughFn?: (chunk: StreamChunk) => void;\n modes: Set<StreamMode>;\n }) {\n let streamControllerPromiseResolver: (\n controller: ReadableStreamDefaultController\n ) => void;\n const streamControllerPromise: Promise<ReadableStreamDefaultController> =\n new Promise<ReadableStreamDefaultController>((resolve) => {\n streamControllerPromiseResolver = resolve;\n });\n\n super({\n start: (controller) => {\n streamControllerPromiseResolver!(controller);\n },\n });\n\n // .start() will always be called before the stream can be interacted\n // with anyway\n void streamControllerPromise.then((controller) => {\n this.controller = controller;\n });\n\n this.passthroughFn = params.passthroughFn;\n this.modes = params.modes;\n }\n\n push(chunk: StreamChunk) {\n this.passthroughFn?.(chunk);\n this.controller.enqueue(chunk);\n }\n\n close() {\n try {\n this.controller.close();\n } catch (e) {\n // pass\n } finally {\n this._closed = true;\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error(e: any) {\n this.controller.error(e);\n }\n}\n\nfunction _stringifyAsDict(obj: unknown) {\n return JSON.stringify(obj, function (key: string | number, value: unknown) {\n const rawValue = this[key];\n if (\n rawValue != null &&\n typeof rawValue === \"object\" &&\n \"toDict\" in rawValue &&\n typeof rawValue.toDict === \"function\"\n ) {\n const { type, data } = rawValue.toDict();\n return { ...data, type };\n }\n\n return value;\n });\n}\n\nfunction _serializeError(error: unknown) {\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof Error) {\n return { error: error.name, message: error.message };\n }\n return { error: \"Error\", message: JSON.stringify(error) };\n}\n\nfunction _isRunnableConfig(\n config: unknown\n): config is RunnableConfig & { configurable: Record<string, unknown> } {\n if (typeof config !== \"object\" || config == null) return false;\n return (\n \"configurable\" in config &&\n typeof config.configurable === \"object\" &&\n config.configurable != null\n );\n}\n\nfunction _extractCheckpointFromConfig(\n config: RunnableConfig | null | undefined\n) {\n if (!_isRunnableConfig(config) || !config.configurable.thread_id) {\n return null;\n }\n\n return {\n thread_id: config.configurable.thread_id,\n checkpoint_ns: config.configurable.checkpoint_ns || \"\",\n checkpoint_id: config.configurable.checkpoint_id || null,\n checkpoint_map: config.configurable.checkpoint_map || null,\n };\n}\n\nfunction _serializeConfig(config: unknown) {\n if (_isRunnableConfig(config)) {\n const configurable = Object.fromEntries(\n Object.entries(config.configurable).filter(\n ([key]) => !key.startsWith(\"__\")\n )\n );\n\n const newConfig = { ...config, configurable };\n delete newConfig.callbacks;\n return newConfig;\n }\n\n return config;\n}\n\nfunction _serializeCheckpoint(payload: StreamCheckpointsOutput<unknown>) {\n const result: Record<string, unknown> = {\n ...payload,\n checkpoint: _extractCheckpointFromConfig(payload.config),\n parent_checkpoint: _extractCheckpointFromConfig(payload.parentConfig),\n\n config: _serializeConfig(payload.config),\n parent_config: _serializeConfig(payload.parentConfig),\n\n tasks: payload.tasks.map((task) => {\n if (_isRunnableConfig(task.state)) {\n const checkpoint = _extractCheckpointFromConfig(task.state);\n if (checkpoint != null) {\n const cloneTask: Record<string, unknown> = { ...task, checkpoint };\n delete cloneTask.state;\n return cloneTask;\n }\n }\n\n return task;\n }),\n };\n\n delete result.parentConfig;\n return result;\n}\n\nexport function toEventStream(stream: AsyncGenerator) {\n const encoder = new TextEncoder();\n return new ReadableStream<Uint8Array>({\n async start(controller) {\n const enqueueChunk = (sse: {\n id?: string;\n event: string;\n data: unknown;\n }) => {\n controller.enqueue(\n encoder.encode(\n `event: ${sse.event}\\ndata: ${_stringifyAsDict(sse.data)}\\n\\n`\n )\n );\n };\n\n try {\n for await (const payload of stream) {\n const [ns, mode, chunk] = payload as AnyStreamOutput;\n\n let data: unknown = chunk;\n if (mode === \"debug\") {\n const debugChunk = chunk;\n\n if (debugChunk.type === \"checkpoint\") {\n data = {\n ...debugChunk,\n payload: _serializeCheckpoint(debugChunk.payload),\n };\n }\n }\n\n if (mode === \"checkpoints\") {\n data = _serializeCheckpoint(chunk);\n }\n\n const event = ns?.length ? `${mode}|${ns.join(\"|\")}` : mode;\n enqueueChunk({ event, data });\n }\n } catch (error) {\n enqueueChunk({ event: \"error\", data: _serializeError(error) });\n }\n\n controller.close();\n },\n });\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/pregel/types.ts
|
|
3
|
+
var Call = class {
|
|
4
|
+
func;
|
|
5
|
+
name;
|
|
6
|
+
input;
|
|
7
|
+
retry;
|
|
8
|
+
cache;
|
|
9
|
+
callbacks;
|
|
10
|
+
__lg_type = "call";
|
|
11
|
+
constructor({ func, name, input, retry, cache, callbacks }) {
|
|
12
|
+
this.func = func;
|
|
13
|
+
this.name = name;
|
|
14
|
+
this.input = input;
|
|
15
|
+
this.retry = retry;
|
|
16
|
+
this.cache = cache;
|
|
17
|
+
this.callbacks = callbacks;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
function isCall(value) {
|
|
21
|
+
return typeof value === "object" && value !== null && "__lg_type" in value && value.__lg_type === "call";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.Call = Call;
|
|
26
|
+
exports.isCall = isCall;
|
|
27
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","names":[],"sources":["../../src/pregel/types.ts"],"sourcesContent":["import type { Runnable, RunnableConfig } from \"@langchain/core/runnables\";\nimport type {\n All,\n PendingWrite,\n CheckpointMetadata,\n BaseCheckpointSaver,\n BaseStore,\n CheckpointListOptions,\n BaseCache,\n} from \"@langchain/langgraph-checkpoint\";\nimport { Graph as DrawableGraph } from \"@langchain/core/runnables/graph\";\nimport { IterableReadableStream } from \"@langchain/core/utils/stream\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport type { BaseChannel } from \"../channels/base.js\";\nimport type { PregelNode } from \"./read.js\";\nimport type { Interrupt } from \"../constants.js\";\nimport { CachePolicy, RetryPolicy } from \"./utils/index.js\";\nimport { LangGraphRunnableConfig } from \"./runnable_types.js\";\n\n/**\n * Selects the type of output you'll receive when streaming from the graph. See [Streaming](/langgraphjs/how-tos/#streaming) for more details.\n */\nexport type StreamMode =\n | \"values\"\n | \"updates\"\n | \"debug\"\n | \"messages\"\n | \"checkpoints\"\n | \"tasks\"\n | \"custom\";\n\nexport type Durability = \"exit\" | \"async\" | \"sync\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type PregelInputType = any;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type PregelOutputType = any;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype StreamMessageOutput = [BaseMessage, Record<string, any>];\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype StreamDebugOutput = Record<string, any>;\n\ntype StreamCheckpointsOutput<StreamValues> = {\n values: StreamValues;\n next: string[];\n config: RunnableConfig;\n metadata?: CheckpointMetadata;\n parentConfig?: RunnableConfig | undefined;\n tasks: PregelTaskDescription[];\n};\n\ninterface StreamTasksOutputBase {\n id: string;\n name: string;\n interrupts: Interrupt[];\n}\n\ninterface StreamTasksCreateOutput<StreamValues> extends StreamTasksOutputBase {\n input: StreamValues;\n triggers: string[];\n}\n\ninterface StreamTasksResultOutput<Keys, StreamUpdates>\n extends StreamTasksOutputBase {\n result: [Keys, StreamUpdates][];\n}\n\ntype StreamTasksOutput<StreamUpdates, StreamValues, Nodes = string> =\n | StreamTasksCreateOutput<StreamValues>\n | StreamTasksResultOutput<Nodes, StreamUpdates>;\n\ntype DefaultStreamMode = \"updates\";\n\nexport type IsEventStream<T> = [T] extends [\"text/event-stream\"]\n ? [\"text/event-stream\"] extends [T]\n ? true\n : false\n : false;\n\nexport type StreamOutputMap<\n TStreamMode extends StreamMode | StreamMode[] | undefined,\n TStreamSubgraphs extends boolean,\n StreamUpdates,\n StreamValues,\n Nodes,\n NodeReturnType,\n StreamCustom,\n TEncoding extends \"text/event-stream\" | undefined\n> = IsEventStream<TEncoding> extends true\n ? Uint8Array\n : (\n undefined extends TStreamMode\n ? []\n : StreamMode | StreamMode[] extends TStreamMode\n ? TStreamMode extends StreamMode[]\n ? TStreamMode[number]\n : TStreamMode\n : TStreamMode extends StreamMode[]\n ? TStreamMode[number]\n : []\n ) extends infer Multiple extends StreamMode\n ? [TStreamSubgraphs] extends [true]\n ? {\n values: [string[], \"values\", StreamValues];\n updates: [\n string[],\n \"updates\",\n NodeReturnType extends Record<string, unknown>\n ? { [K in keyof NodeReturnType]?: NodeReturnType[K] }\n : Record<Nodes extends string ? Nodes : string, StreamUpdates>\n ];\n messages: [string[], \"messages\", StreamMessageOutput];\n custom: [string[], \"custom\", StreamCustom];\n checkpoints: [\n string[],\n \"checkpoints\",\n StreamCheckpointsOutput<StreamValues>\n ];\n tasks: [\n string[],\n \"tasks\",\n StreamTasksOutput<StreamUpdates, StreamValues>\n ];\n debug: [string[], \"debug\", StreamDebugOutput];\n }[Multiple]\n : {\n values: [\"values\", StreamValues];\n updates: [\n \"updates\",\n NodeReturnType extends Record<string, unknown>\n ? { [K in keyof NodeReturnType]?: NodeReturnType[K] }\n : Record<Nodes extends string ? Nodes : string, StreamUpdates>\n ];\n messages: [\"messages\", StreamMessageOutput];\n custom: [\"custom\", StreamCustom];\n checkpoints: [\"checkpoints\", StreamCheckpointsOutput<StreamValues>];\n tasks: [\"tasks\", StreamTasksOutput<StreamUpdates, StreamValues, Nodes>];\n debug: [\"debug\", StreamDebugOutput];\n }[Multiple]\n : (\n undefined extends TStreamMode ? DefaultStreamMode : TStreamMode\n ) extends infer Single extends StreamMode\n ? [TStreamSubgraphs] extends [true]\n ? {\n values: [string[], StreamValues];\n updates: [\n string[],\n NodeReturnType extends Record<string, unknown>\n ? { [K in keyof NodeReturnType]?: NodeReturnType[K] }\n : Record<Nodes extends string ? Nodes : string, StreamUpdates>\n ];\n messages: [string[], StreamMessageOutput];\n custom: [string[], StreamCustom];\n checkpoints: [string[], StreamCheckpointsOutput<StreamValues>];\n tasks: [\n string[],\n StreamTasksOutput<StreamUpdates, StreamValues, Nodes>\n ];\n debug: [string[], StreamDebugOutput];\n }[Single]\n : {\n values: StreamValues;\n updates: NodeReturnType extends Record<string, unknown>\n ? { [K in keyof NodeReturnType]?: NodeReturnType[K] }\n : Record<Nodes extends string ? Nodes : string, StreamUpdates>;\n messages: StreamMessageOutput;\n custom: StreamCustom;\n checkpoints: StreamCheckpointsOutput<StreamValues>;\n tasks: StreamTasksOutput<StreamUpdates, StreamValues, Nodes>;\n debug: StreamDebugOutput;\n }[Single]\n : never;\n\n/**\n * Configuration options for executing a Pregel graph.\n * These options control how the graph executes, what data is streamed, and how interrupts are handled.\n *\n * @typeParam Nodes - Mapping of node names to their {@link PregelNode} implementations\n * @typeParam Channels - Mapping of channel names to their {@link BaseChannel} implementations\n * @typeParam ContextType - Type of context that can be passed to the graph\n */\nexport interface PregelOptions<\n Nodes extends StrRecord<string, PregelNode>,\n Channels extends StrRecord<string, BaseChannel>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ContextType extends Record<string, any> = Record<string, any>,\n TStreamMode extends StreamMode | StreamMode[] | undefined =\n | StreamMode\n | StreamMode[]\n | undefined,\n TSubgraphs extends boolean = boolean,\n TEncoding extends \"text/event-stream\" | undefined =\n | \"text/event-stream\"\n | undefined\n> extends RunnableConfig<ContextType> {\n /**\n * Controls what information is streamed during graph execution.\n * Multiple modes can be enabled simultaneously.\n *\n * Supported modes:\n * - \"values\": Streams complete state after each step\n * - \"updates\": Streams only state changes after each step\n * - \"messages\": Streams messages from within nodes\n * - \"custom\": Streams custom events from within nodes\n * - \"debug\": Streams detailed execution events for tracing & debugging\n *\n * @example\n * ```typescript\n * // Stream only values\n * streamMode: \"values\"\n *\n * // Stream both values and debug info\n * streamMode: [\"values\", \"debug\"]\n * ```\n *\n * @default [\"values\"]\n */\n streamMode?: TStreamMode;\n\n /**\n * Specifies which channel keys to retrieve from the checkpoint when resuming execution.\n * This is an advanced option that you generally don't need to set manually.\n * The graph will automatically determine the appropriate input keys based on its configuration.\n */\n inputKeys?: keyof Channels | Array<keyof Channels>;\n\n /**\n * Specifies which channel keys to include in the output stream and final result.\n * Use this to filter which parts of the graph state you want to observe.\n *\n * @example\n * ```typescript\n * // Stream only the 'result' channel\n * outputKeys: \"result\"\n *\n * // Stream multiple channels\n * outputKeys: [\"result\", \"intermediateState\"]\n * ```\n */\n outputKeys?: keyof Channels | Array<keyof Channels>;\n\n /**\n * List of nodes where execution should be interrupted BEFORE the node runs.\n * Can be used for debugging and advanced state manipulation use cases. For\n * human-in-the-loop workflows, developers should prefer the\n * @link {interrupt} function instead.\n *\n * When interrupted, a resume @link {Command} must be provided to continue\n * execution.\n *\n * @example\n * ```typescript\n * // Interrupt before specific nodes\n * interruptBefore: [\"humanReview\", \"qualityCheck\"]\n *\n * // Interrupt before all nodes\n * interruptBefore: \"all\"\n * ```\n */\n interruptBefore?: All | Array<keyof Nodes>;\n\n /**\n * List of nodes where execution should be interrupted AFTER the node runs.\n * Similar to interruptBefore, but interrupts after node completion.\n * Useful when the node's output needs to be reviewed before proceeding.\n *\n * @example\n * ```typescript\n * // Interrupt after specific nodes\n * interruptAfter: [\"generateContent\", \"analyze\"]\n *\n * // Interrupt after all nodes\n * interruptAfter: \"all\"\n * ```\n */\n interruptAfter?: All | Array<keyof Nodes>;\n\n /**\n * Enables detailed debug logging during graph execution.\n * When enabled, prints information about:\n * - Task execution\n * - Channel updates\n * - Checkpoint writes\n *\n * @default false\n */\n debug?: boolean;\n\n /**\n * Whether to include subgraph execution details in the stream.\n * When true, state updates from nested graphs will also be streamed.\n *\n * @default false\n */\n subgraphs?: TSubgraphs;\n\n /**\n * Whether to checkpoint intermediate steps, defaults to `true`.\n * If `false`, only the final checkpoint is saved.\n * @deprecated Use `durability` instead.\n */\n checkpointDuring?: boolean;\n\n /**\n * Whether to checkpoint during the run (or only at the end/interruption).\n * - `\"async\"`: Save checkpoint asynchronously while the next step executes (default).\n * - `\"sync\"`: Save checkpoint synchronously before the next step starts.\n * - `\"exit\"`: Save checkpoint only when the graph exits.\n * @default \"async\"\n */\n durability?: Durability;\n\n /**\n * A shared value store that allows you to store and retrieve state across\n * threads. Useful for implementing long-term memory patterns.\n */\n store?: BaseStore;\n\n /**\n * Optional cache for the graph, useful for caching tasks.\n */\n cache?: BaseCache;\n\n /**\n * Static context for the graph run, like `userId`, `dbConnection` etc.\n */\n context?: ContextType;\n\n /**\n * The encoding to use for the stream.\n * - `undefined`: Use the default format.\n * - `\"text/event-stream\"`: Use the Server-Sent Events format.\n * @default undefined\n */\n encoding?: TEncoding;\n}\n\n/**\n * Construct a type with a set of properties K of type T\n */\ntype StrRecord<K extends string, T> = {\n [P in K]: T;\n};\n\nexport interface PregelInterface<\n Nodes extends StrRecord<string, PregelNode>,\n Channels extends StrRecord<string, BaseChannel>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ContextType extends Record<string, any> = StrRecord<string, any>\n> {\n lg_is_pregel: boolean;\n\n withConfig(config: RunnableConfig): PregelInterface<Nodes, Channels>;\n\n getGraphAsync(\n config: RunnableConfig & { xray?: boolean | number }\n ): Promise<DrawableGraph>;\n\n /** @deprecated Use getSubgraphsAsync instead. The async method will become the default in the next minor release. */\n getSubgraphs(\n namespace?: string,\n recurse?: boolean\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Generator<[string, PregelInterface<any, any>]>;\n\n getSubgraphsAsync(\n namespace?: string,\n recurse?: boolean\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): AsyncGenerator<[string, PregelInterface<any, any>]>;\n\n getState(\n config: RunnableConfig,\n options?: { subgraphs?: boolean }\n ): Promise<StateSnapshot>;\n\n getStateHistory(\n config: RunnableConfig,\n options?: CheckpointListOptions\n ): AsyncIterableIterator<StateSnapshot>;\n\n updateState(\n inputConfig: LangGraphRunnableConfig,\n values: Record<string, unknown> | unknown,\n asNode?: keyof Nodes | string\n ): Promise<RunnableConfig>;\n\n stream(\n input: PregelInputType,\n options?: Partial<PregelOptions<Nodes, Channels, ContextType>>\n ): Promise<IterableReadableStream<PregelOutputType>>;\n\n invoke(\n input: PregelInputType,\n options?: Partial<PregelOptions<Nodes, Channels, ContextType>>\n ): Promise<PregelOutputType>;\n}\n\n/**\n * Parameters for creating a Pregel graph.\n * @internal\n */\nexport type PregelParams<\n Nodes extends StrRecord<string, PregelNode>,\n Channels extends StrRecord<string, BaseChannel>\n> = {\n /**\n * The name of the graph. @see {@link Runnable.name}\n */\n name?: string;\n\n /**\n * The nodes in the graph.\n */\n nodes: Nodes;\n\n /**\n * The channels in the graph.\n */\n channels: Channels;\n\n /**\n * Whether to validate the graph.\n *\n * @default true\n */\n autoValidate?: boolean;\n\n /**\n * The stream mode for the graph run. See [Streaming](/langgraphjs/how-tos/#streaming) for more details.\n *\n * @default [\"values\"]\n */\n streamMode?: StreamMode | StreamMode[];\n\n /**\n * The input channels for the graph run.\n */\n inputChannels: keyof Channels | Array<keyof Channels>;\n\n /**\n * The output channels for the graph run.\n */\n outputChannels: keyof Channels | Array<keyof Channels>;\n\n /**\n * After processing one of the nodes named in this list, the graph will be interrupted and a resume {@link Command} must be provided to proceed with the execution of this thread.\n * @default []\n */\n interruptAfter?: Array<keyof Nodes> | All;\n\n /**\n * Before processing one of the nodes named in this list, the graph will be interrupted and a resume {@link Command} must be provided to proceed with the execution of this thread.\n * @default []\n */\n interruptBefore?: Array<keyof Nodes> | All;\n\n /**\n * The channels to stream from the graph run.\n * @default []\n */\n streamChannels?: keyof Channels | Array<keyof Channels>;\n\n /**\n * @default undefined\n */\n stepTimeout?: number;\n\n /**\n * @default false\n */\n debug?: boolean;\n\n /**\n * The {@link BaseCheckpointSaver | checkpointer} to use for the graph run.\n */\n checkpointer?: BaseCheckpointSaver | boolean;\n\n /**\n * The default retry policy for this graph. For defaults, see {@link RetryPolicy}.\n */\n retryPolicy?: RetryPolicy;\n\n /**\n * The configuration for the graph run.\n */\n config?: LangGraphRunnableConfig;\n\n /**\n * External key-value store.\n */\n store?: BaseStore;\n\n /**\n * Storage used for node caching.\n */\n cache?: BaseCache;\n\n /**\n * The trigger to node mapping for the graph run.\n * @internal\n */\n triggerToNodes?: Record<string, string[]>;\n\n /**\n * Interrupt helper function.\n * @internal\n */\n userInterrupt?: unknown;\n};\n\nexport interface PregelTaskDescription {\n readonly id: string;\n readonly name: string;\n readonly error?: unknown;\n readonly interrupts: Interrupt[];\n readonly state?: LangGraphRunnableConfig | StateSnapshot;\n readonly path?: TaskPath;\n readonly result?: unknown;\n}\n\ninterface CacheKey {\n ns: string[];\n key: string;\n ttl?: number;\n}\n\nexport interface PregelExecutableTask<\n NodeKey extends PropertyKey,\n ChannelKey extends PropertyKey\n> {\n readonly name: NodeKey;\n readonly input: unknown;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n readonly proc: Runnable<any, any, LangGraphRunnableConfig>;\n readonly writes: PendingWrite<ChannelKey>[];\n readonly config?: LangGraphRunnableConfig;\n readonly triggers: Array<string>;\n readonly retry_policy?: RetryPolicy;\n readonly cache_key?: CacheKey;\n readonly id: string;\n readonly path?: TaskPath;\n readonly subgraphs?: Runnable[];\n readonly writers: Runnable[];\n}\n\nexport interface StateSnapshot {\n /**\n * Current values of channels\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n readonly values: Record<string, any> | any;\n /**\n * Nodes to execute in the next step, if any\n */\n readonly next: Array<string>;\n /**\n * Config used to fetch this snapshot\n */\n readonly config: RunnableConfig;\n /**\n * Metadata about the checkpoint\n */\n readonly metadata?: CheckpointMetadata;\n /**\n * Time when the snapshot was created\n */\n readonly createdAt?: string;\n /**\n * Config used to fetch the parent snapshot, if any\n * @default undefined\n */\n readonly parentConfig?: RunnableConfig | undefined;\n /**\n * Tasks to execute in this step. If already attempted, may contain an error.\n */\n readonly tasks: PregelTaskDescription[];\n}\n\n/**\n * Options for subscribing to multiple channels.\n */\nexport type MultipleChannelSubscriptionOptions = {\n /**\n * Optional tags to associate with the subscription.\n */\n tags?: string[];\n};\n\n/**\n * Options for subscribing to a single channel.\n */\nexport type SingleChannelSubscriptionOptions = {\n /**\n * When specified, the channel mapping will be an object with this key pointing\n * to the array of channels to subscribe to. Otherwise, the channel mapping\n * will be an array of channels.\n */\n key?: string;\n /**\n * Optional tags to associate with the subscription.\n */\n tags?: string[];\n};\n\n/**\n * Options for getting the state of the graph.\n */\nexport type GetStateOptions = {\n /**\n * Whether to include subgraph states.\n * @default false\n */\n subgraphs?: boolean;\n};\n\n/**\n * Used for storing/retrieving internal execution state.\n *\n * @internal\n */\nexport type PregelScratchpad<Resume = unknown> = {\n /** Counter for tracking call invocations */\n callCounter: number;\n /** Counter for tracking interrupts */\n interruptCounter: number;\n /** List of resume values */\n resume: Resume[];\n /** Single resume value for null task ID */\n nullResume: Resume;\n\n consumeNullResume: () => Resume | undefined;\n /** Counter for tracking subgraph invocations */\n subgraphCounter: number;\n\n /** The input to the currently executing task */\n currentTaskInput: unknown;\n};\n\n/**\n * @internal\n */\nexport type PregelAbortSignals = {\n /** Aborts when the user calls `stream.cancel()` or aborts the {@link AbortSignal} that they passed in via the `signal` option */\n externalAbortSignal?: AbortSignal;\n\n /**\n * Aborts when the currently executing task throws any error other than a {@link GraphBubbleUp}\n */\n timeoutAbortSignal?: AbortSignal;\n\n /**\n * A reference to the AbortSignal that is passed to the node. Aborts on step timeout, stream cancel, or when an error is thrown.\n */\n composedAbortSignal?: AbortSignal;\n};\n\nexport type CallOptions = {\n func: (...args: unknown[]) => unknown | Promise<unknown>;\n name: string;\n input: unknown;\n cache?: CachePolicy;\n retry?: RetryPolicy;\n callbacks?: unknown;\n};\n\nexport class Call {\n func: (...args: unknown[]) => unknown | Promise<unknown>;\n\n name: string;\n\n input: unknown;\n\n retry?: RetryPolicy;\n\n cache?: CachePolicy;\n\n callbacks?: unknown;\n\n readonly __lg_type = \"call\";\n\n constructor({ func, name, input, retry, cache, callbacks }: CallOptions) {\n this.func = func;\n this.name = name;\n this.input = input;\n this.retry = retry;\n this.cache = cache;\n this.callbacks = callbacks;\n }\n}\n\nexport function isCall(value: unknown): value is Call {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"__lg_type\" in value &&\n value.__lg_type === \"call\"\n );\n}\n\nexport type SimpleTaskPath = [string, string | number];\nexport type VariadicTaskPath = [string, ...(string | number)[], boolean];\nexport type CallTaskPath =\n | [string, ...(string | number)[], Call]\n | [string, TaskPath, ...(string | number)[], Call];\nexport type TaskPath = SimpleTaskPath | CallTaskPath | VariadicTaskPath;\n"],"mappings":";;AA6pBA,IAAa,OAAb,MAAkB;CAChB;CAEA;CAEA;CAEA;CAEA;CAEA;CAEA,AAAS,YAAY;CAErB,YAAY,EAAE,MAAM,MAAM,OAAO,OAAO,OAAO,aAA0B;AACvE,OAAK,OAAO;AACZ,OAAK,OAAO;AACZ,OAAK,QAAQ;AACb,OAAK,QAAQ;AACb,OAAK,QAAQ;AACb,OAAK,YAAY;;;AAIrB,SAAgB,OAAO,OAA+B;AACpD,QACE,OAAO,UAAU,YACjB,UAAU,QACV,eAAe,SACf,MAAM,cAAc"}
|