@langchain/langgraph 0.4.8 → 1.0.0-alpha.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.
- package/CHANGELOG.md +7 -2
- package/README.md +1 -2
- package/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/channels/any_value.d.cts +26 -0
- package/dist/channels/any_value.d.cts.map +1 -0
- package/dist/channels/any_value.d.ts +16 -9
- package/dist/channels/any_value.d.ts.map +1 -0
- package/dist/channels/base.cjs +97 -133
- package/dist/channels/base.cjs.map +1 -0
- package/dist/channels/base.d.cts +73 -0
- package/dist/channels/base.d.cts.map +1 -0
- package/dist/channels/base.d.ts +73 -74
- package/dist/channels/base.d.ts.map +1 -0
- package/dist/channels/base.js +94 -127
- package/dist/channels/base.js.map +1 -1
- package/dist/channels/binop.cjs +47 -77
- 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 +17 -12
- package/dist/channels/binop.d.ts.map +1 -0
- package/dist/channels/binop.js +45 -71
- package/dist/channels/binop.js.map +1 -1
- package/dist/channels/dynamic_barrier_value.d.cts +43 -0
- package/dist/channels/dynamic_barrier_value.d.cts.map +1 -0
- package/dist/channels/dynamic_barrier_value.d.ts +20 -34
- package/dist/channels/dynamic_barrier_value.d.ts.map +1 -0
- package/dist/channels/ephemeral_value.cjs +46 -70
- package/dist/channels/ephemeral_value.cjs.map +1 -0
- package/dist/channels/ephemeral_value.d.cts +23 -0
- package/dist/channels/ephemeral_value.d.cts.map +1 -0
- package/dist/channels/ephemeral_value.d.ts +18 -11
- package/dist/channels/ephemeral_value.d.ts.map +1 -0
- package/dist/channels/ephemeral_value.js +45 -65
- package/dist/channels/ephemeral_value.js.map +1 -1
- package/dist/channels/index.cjs +2 -10
- package/dist/channels/index.js +4 -3
- package/dist/channels/last_value.cjs +91 -140
- package/dist/channels/last_value.cjs.map +1 -0
- package/dist/channels/last_value.d.cts +30 -0
- package/dist/channels/last_value.d.cts.map +1 -0
- package/dist/channels/last_value.d.ts +15 -23
- package/dist/channels/last_value.d.ts.map +1 -0
- package/dist/channels/last_value.js +88 -133
- package/dist/channels/last_value.js.map +1 -1
- package/dist/channels/named_barrier_value.cjs +114 -170
- package/dist/channels/named_barrier_value.cjs.map +1 -0
- package/dist/channels/named_barrier_value.d.cts +33 -0
- package/dist/channels/named_barrier_value.d.cts.map +1 -0
- package/dist/channels/named_barrier_value.d.ts +19 -29
- package/dist/channels/named_barrier_value.d.ts.map +1 -0
- package/dist/channels/named_barrier_value.js +112 -163
- package/dist/channels/named_barrier_value.js.map +1 -1
- package/dist/channels/topic.cjs +63 -96
- package/dist/channels/topic.cjs.map +1 -0
- package/dist/channels/topic.d.cts +26 -0
- package/dist/channels/topic.d.cts.map +1 -0
- package/dist/channels/topic.d.ts +21 -18
- package/dist/channels/topic.d.ts.map +1 -0
- package/dist/channels/topic.js +61 -90
- package/dist/channels/topic.js.map +1 -1
- package/dist/constants.cjs +373 -452
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +284 -0
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.ts +112 -148
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +333 -444
- package/dist/constants.js.map +1 -1
- package/dist/errors.cjs +150 -179
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +80 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.ts +55 -46
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +139 -165
- package/dist/errors.js.map +1 -1
- package/dist/func/index.cjs +289 -290
- package/dist/func/index.cjs.map +1 -0
- package/dist/func/index.d.cts +289 -0
- package/dist/func/index.d.cts.map +1 -0
- package/dist/func/index.d.ts +81 -71
- package/dist/func/index.d.ts.map +1 -0
- package/dist/func/index.js +285 -284
- package/dist/func/index.js.map +1 -1
- package/dist/func/types.d.cts +64 -0
- package/dist/func/types.d.cts.map +1 -0
- package/dist/func/types.d.ts +24 -19
- package/dist/func/types.d.ts.map +1 -0
- package/dist/graph/annotation.cjs +96 -120
- 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 +33 -34
- package/dist/graph/annotation.d.ts.map +1 -0
- package/dist/graph/annotation.js +91 -112
- package/dist/graph/annotation.js.map +1 -1
- package/dist/graph/graph.cjs +419 -723
- package/dist/graph/graph.cjs.map +1 -0
- package/dist/graph/graph.d.cts +131 -0
- package/dist/graph/graph.d.cts.map +1 -0
- package/dist/graph/graph.d.ts +122 -91
- package/dist/graph/graph.d.ts.map +1 -0
- package/dist/graph/graph.js +412 -713
- package/dist/graph/graph.js.map +1 -1
- package/dist/graph/index.cjs +4 -17
- package/dist/graph/index.js +6 -5
- package/dist/graph/message.cjs +59 -104
- package/dist/graph/message.cjs.map +1 -0
- package/dist/graph/message.d.cts +19 -0
- package/dist/graph/message.d.cts.map +1 -0
- package/dist/graph/message.d.ts +11 -10
- package/dist/graph/message.d.ts.map +1 -0
- package/dist/graph/message.js +56 -98
- package/dist/graph/message.js.map +1 -1
- package/dist/graph/messages_annotation.cjs +106 -106
- package/dist/graph/messages_annotation.cjs.map +1 -0
- package/dist/graph/messages_annotation.d.cts +111 -0
- package/dist/graph/messages_annotation.d.cts.map +1 -0
- package/dist/graph/messages_annotation.d.ts +18 -9
- package/dist/graph/messages_annotation.d.ts.map +1 -0
- package/dist/graph/messages_annotation.js +100 -100
- package/dist/graph/messages_annotation.js.map +1 -1
- package/dist/graph/state.cjs +476 -777
- package/dist/graph/state.cjs.map +1 -0
- package/dist/graph/state.d.cts +216 -0
- package/dist/graph/state.d.cts.map +1 -0
- package/dist/graph/state.d.ts +129 -134
- package/dist/graph/state.d.ts.map +1 -0
- package/dist/graph/state.js +470 -768
- package/dist/graph/state.js.map +1 -1
- package/dist/graph/zod/index.cjs +10 -21
- package/dist/graph/zod/index.d.cts +3 -0
- package/dist/graph/zod/index.d.ts +3 -3
- package/dist/graph/zod/index.js +4 -4
- package/dist/graph/zod/meta.cjs +142 -177
- package/dist/graph/zod/meta.cjs.map +1 -0
- package/dist/graph/zod/meta.d.cts +116 -0
- package/dist/graph/zod/meta.d.cts.map +1 -0
- package/dist/graph/zod/meta.d.ts +99 -97
- package/dist/graph/zod/meta.d.ts.map +1 -0
- package/dist/graph/zod/meta.js +136 -170
- package/dist/graph/zod/meta.js.map +1 -1
- package/dist/graph/zod/plugin.cjs +36 -39
- package/dist/graph/zod/plugin.cjs.map +1 -0
- package/dist/graph/zod/plugin.js +34 -35
- package/dist/graph/zod/plugin.js.map +1 -1
- package/dist/graph/zod/schema.cjs +82 -110
- 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 +12 -6
- package/dist/graph/zod/schema.d.ts.map +1 -0
- package/dist/graph/zod/schema.js +77 -103
- package/dist/graph/zod/schema.js.map +1 -1
- package/dist/graph/zod/zod-registry.cjs +41 -47
- package/dist/graph/zod/zod-registry.cjs.map +1 -0
- package/dist/graph/zod/zod-registry.d.cts +51 -0
- package/dist/graph/zod/zod-registry.d.cts.map +1 -0
- package/dist/graph/zod/zod-registry.d.ts +34 -26
- package/dist/graph/zod/zod-registry.d.ts.map +1 -0
- package/dist/graph/zod/zod-registry.js +37 -41
- package/dist/graph/zod/zod-registry.js.map +1 -1
- package/dist/hash.cjs +205 -267
- package/dist/hash.cjs.map +1 -0
- package/dist/hash.js +205 -265
- package/dist/hash.js.map +1 -1
- package/dist/index.cjs +110 -33
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +25 -0
- package/dist/index.d.ts +25 -5
- package/dist/index.js +18 -7
- package/dist/index.js.map +1 -1
- package/dist/interrupt.cjs +79 -85
- package/dist/interrupt.cjs.map +1 -0
- package/dist/interrupt.d.cts +49 -0
- package/dist/interrupt.d.cts.map +1 -0
- package/dist/interrupt.d.ts +6 -1
- package/dist/interrupt.d.ts.map +1 -0
- package/dist/interrupt.js +76 -80
- package/dist/interrupt.js.map +1 -1
- package/dist/prebuilt/agentName.cjs +139 -172
- 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 +13 -21
- package/dist/prebuilt/agentName.d.ts.map +1 -0
- package/dist/prebuilt/agentName.js +139 -168
- package/dist/prebuilt/agentName.js.map +1 -1
- package/dist/prebuilt/agent_executor.cjs +42 -80
- package/dist/prebuilt/agent_executor.cjs.map +1 -0
- package/dist/prebuilt/agent_executor.d.cts +57 -0
- package/dist/prebuilt/agent_executor.d.cts.map +1 -0
- package/dist/prebuilt/agent_executor.d.ts +46 -37
- package/dist/prebuilt/agent_executor.d.ts.map +1 -0
- package/dist/prebuilt/agent_executor.js +40 -75
- package/dist/prebuilt/agent_executor.js.map +1 -1
- package/dist/prebuilt/chat_agent_executor.cjs +66 -128
- 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 +18 -10
- package/dist/prebuilt/chat_agent_executor.d.ts.map +1 -0
- package/dist/prebuilt/chat_agent_executor.js +63 -123
- package/dist/prebuilt/chat_agent_executor.js.map +1 -1
- package/dist/prebuilt/index.cjs +15 -18
- package/dist/prebuilt/index.d.cts +8 -0
- package/dist/prebuilt/index.d.ts +8 -8
- package/dist/prebuilt/index.js +8 -7
- package/dist/prebuilt/interrupt.d.cts +73 -0
- package/dist/prebuilt/interrupt.d.cts.map +1 -0
- package/dist/prebuilt/interrupt.d.ts +32 -15
- package/dist/prebuilt/interrupt.d.ts.map +1 -0
- package/dist/prebuilt/react_agent_executor.cjs +317 -473
- package/dist/prebuilt/react_agent_executor.cjs.map +1 -0
- package/dist/prebuilt/react_agent_executor.d.cts +229 -0
- package/dist/prebuilt/react_agent_executor.d.cts.map +1 -0
- package/dist/prebuilt/react_agent_executor.d.ts +171 -143
- package/dist/prebuilt/react_agent_executor.d.ts.map +1 -0
- package/dist/prebuilt/react_agent_executor.js +315 -465
- package/dist/prebuilt/react_agent_executor.js.map +1 -1
- package/dist/prebuilt/tool_executor.cjs +45 -67
- package/dist/prebuilt/tool_executor.cjs.map +1 -0
- package/dist/prebuilt/tool_executor.d.cts +42 -0
- package/dist/prebuilt/tool_executor.d.cts.map +1 -0
- package/dist/prebuilt/tool_executor.d.ts +30 -24
- package/dist/prebuilt/tool_executor.d.ts.map +1 -0
- package/dist/prebuilt/tool_executor.js +44 -63
- package/dist/prebuilt/tool_executor.js.map +1 -1
- package/dist/prebuilt/tool_node.cjs +213 -275
- package/dist/prebuilt/tool_node.cjs.map +1 -0
- package/dist/prebuilt/tool_node.d.cts +151 -0
- package/dist/prebuilt/tool_node.d.cts.map +1 -0
- package/dist/prebuilt/tool_node.d.ts +30 -17
- package/dist/prebuilt/tool_node.d.ts.map +1 -0
- package/dist/prebuilt/tool_node.js +209 -268
- package/dist/prebuilt/tool_node.js.map +1 -1
- package/dist/pregel/algo.cjs +521 -692
- 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 +8 -38
- package/dist/pregel/algo.d.ts.map +1 -0
- package/dist/pregel/algo.js +516 -683
- package/dist/pregel/algo.js.map +1 -1
- package/dist/pregel/call.cjs +46 -42
- package/dist/pregel/call.cjs.map +1 -0
- package/dist/pregel/call.js +43 -37
- package/dist/pregel/call.js.map +1 -1
- package/dist/pregel/debug.cjs +153 -223
- package/dist/pregel/debug.cjs.map +1 -0
- package/dist/pregel/debug.js +152 -215
- package/dist/pregel/debug.js.map +1 -1
- package/dist/pregel/index.cjs +1134 -1604
- package/dist/pregel/index.cjs.map +1 -0
- package/dist/pregel/index.d.cts +534 -0
- package/dist/pregel/index.d.cts.map +1 -0
- package/dist/pregel/index.d.ts +458 -422
- package/dist/pregel/index.d.ts.map +1 -0
- package/dist/pregel/index.js +1125 -1592
- package/dist/pregel/index.js.map +1 -1
- package/dist/pregel/io.cjs +127 -234
- package/dist/pregel/io.cjs.map +1 -0
- package/dist/pregel/io.js +122 -225
- package/dist/pregel/io.js.map +1 -1
- package/dist/pregel/loop.cjs +539 -954
- package/dist/pregel/loop.cjs.map +1 -0
- package/dist/pregel/loop.js +536 -948
- package/dist/pregel/loop.js.map +1 -1
- package/dist/pregel/messages.cjs +104 -196
- package/dist/pregel/messages.cjs.map +1 -0
- package/dist/pregel/messages.js +102 -191
- package/dist/pregel/messages.js.map +1 -1
- package/dist/pregel/read.cjs +150 -280
- package/dist/pregel/read.cjs.map +1 -0
- package/dist/pregel/read.d.cts +51 -0
- package/dist/pregel/read.d.cts.map +1 -0
- package/dist/pregel/read.d.ts +48 -46
- package/dist/pregel/read.d.ts.map +1 -0
- package/dist/pregel/read.js +147 -274
- package/dist/pregel/read.js.map +1 -1
- package/dist/pregel/remote.cjs +339 -458
- package/dist/pregel/remote.cjs.map +1 -0
- package/dist/pregel/remote.d.cts +121 -0
- package/dist/pregel/remote.d.cts.map +1 -0
- package/dist/pregel/remote.d.ts +79 -69
- package/dist/pregel/remote.d.ts.map +1 -0
- package/dist/pregel/remote.js +337 -453
- package/dist/pregel/remote.js.map +1 -1
- package/dist/pregel/retry.cjs +87 -138
- package/dist/pregel/retry.cjs.map +1 -0
- package/dist/pregel/retry.js +83 -130
- package/dist/pregel/retry.js.map +1 -1
- package/dist/pregel/runnable_types.d.cts +25 -0
- package/dist/pregel/runnable_types.d.cts.map +1 -0
- package/dist/pregel/runnable_types.d.ts +22 -16
- package/dist/pregel/runnable_types.d.ts.map +1 -0
- package/dist/pregel/runner.cjs +222 -315
- package/dist/pregel/runner.cjs.map +1 -0
- package/dist/pregel/runner.js +219 -308
- package/dist/pregel/runner.js.map +1 -1
- package/dist/pregel/stream.cjs +89 -130
- package/dist/pregel/stream.cjs.map +1 -0
- package/dist/pregel/stream.js +87 -125
- package/dist/pregel/stream.js.map +1 -1
- package/dist/pregel/types.cjs +25 -62
- package/dist/pregel/types.cjs.map +1 -0
- package/dist/pregel/types.d.cts +437 -0
- package/dist/pregel/types.d.cts.map +1 -0
- package/dist/pregel/types.d.ts +377 -431
- package/dist/pregel/types.d.ts.map +1 -0
- package/dist/pregel/types.js +23 -57
- package/dist/pregel/types.js.map +1 -1
- package/dist/pregel/utils/config.cjs +100 -147
- 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 +12 -9
- package/dist/pregel/utils/config.d.ts.map +1 -0
- package/dist/pregel/utils/config.js +98 -143
- package/dist/pregel/utils/config.js.map +1 -1
- package/dist/pregel/utils/index.cjs +87 -125
- 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 +45 -61
- package/dist/pregel/utils/index.d.ts.map +1 -0
- package/dist/pregel/utils/index.js +86 -120
- package/dist/pregel/utils/index.js.map +1 -1
- package/dist/pregel/utils/subgraph.cjs +15 -26
- package/dist/pregel/utils/subgraph.cjs.map +1 -0
- package/dist/pregel/utils/subgraph.js +12 -21
- package/dist/pregel/utils/subgraph.js.map +1 -1
- package/dist/pregel/validate.cjs +42 -92
- package/dist/pregel/validate.cjs.map +1 -0
- package/dist/pregel/validate.js +39 -84
- package/dist/pregel/validate.js.map +1 -1
- package/dist/pregel/write.cjs +87 -137
- package/dist/pregel/write.cjs.map +1 -0
- package/dist/pregel/write.d.cts +35 -0
- package/dist/pregel/write.d.cts.map +1 -0
- package/dist/pregel/write.d.ts +27 -23
- package/dist/pregel/write.d.ts.map +1 -0
- package/dist/pregel/write.js +83 -131
- package/dist/pregel/write.js.map +1 -1
- package/dist/remote.cjs +3 -6
- package/dist/remote.d.cts +2 -0
- package/dist/remote.d.ts +2 -1
- package/dist/remote.js +3 -2
- package/dist/setup/async_local_storage.cjs +10 -7
- package/dist/setup/async_local_storage.cjs.map +1 -0
- package/dist/setup/async_local_storage.js +7 -2
- package/dist/setup/async_local_storage.js.map +1 -1
- package/dist/ui/index.cjs +4 -0
- package/dist/ui/index.d.cts +5 -0
- package/dist/ui/index.d.ts +5 -0
- package/dist/ui/index.js +3 -0
- package/dist/ui/stream.cjs +145 -0
- package/dist/ui/stream.cjs.map +1 -0
- package/dist/ui/stream.d.cts +25 -0
- package/dist/ui/stream.d.cts.map +1 -0
- package/dist/ui/stream.d.ts +25 -0
- package/dist/ui/stream.d.ts.map +1 -0
- package/dist/ui/stream.js +143 -0
- package/dist/ui/stream.js.map +1 -0
- package/dist/ui/types.infer.d.cts +53 -0
- package/dist/ui/types.infer.d.cts.map +1 -0
- package/dist/ui/types.infer.d.ts +53 -0
- package/dist/ui/types.infer.d.ts.map +1 -0
- package/dist/ui/types.message.d.cts +95 -0
- package/dist/ui/types.message.d.cts.map +1 -0
- package/dist/ui/types.message.d.ts +95 -0
- package/dist/ui/types.message.d.ts.map +1 -0
- package/dist/ui/types.schema.d.cts +228 -0
- package/dist/ui/types.schema.d.cts.map +1 -0
- package/dist/ui/types.schema.d.ts +228 -0
- package/dist/ui/types.schema.d.ts.map +1 -0
- package/dist/utils.cjs +77 -147
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +32 -0
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.ts +29 -25
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +73 -140
- package/dist/utils.js.map +1 -1
- package/dist/web.cjs +97 -55
- package/dist/web.d.cts +23 -0
- package/dist/web.d.ts +23 -14
- package/dist/web.js +15 -8
- package/package.json +83 -86
- package/dist/channels/any_value.cjs +0 -65
- package/dist/channels/any_value.js +0 -61
- package/dist/channels/any_value.js.map +0 -1
- package/dist/channels/dynamic_barrier_value.cjs +0 -212
- package/dist/channels/dynamic_barrier_value.js +0 -207
- package/dist/channels/dynamic_barrier_value.js.map +0 -1
- package/dist/channels/index.d.ts +0 -7
- package/dist/channels/index.js.map +0 -1
- package/dist/func/types.cjs +0 -15
- package/dist/func/types.js +0 -12
- package/dist/func/types.js.map +0 -1
- package/dist/graph/index.d.ts +0 -4
- package/dist/graph/index.js.map +0 -1
- package/dist/graph/message.test.cjs +0 -196
- package/dist/graph/message.test.d.ts +0 -1
- package/dist/graph/message.test.js +0 -194
- package/dist/graph/message.test.js.map +0 -1
- package/dist/graph/zod/index.js.map +0 -1
- package/dist/graph/zod/plugin.d.ts +0 -28
- package/dist/hash.d.ts +0 -2
- package/dist/prebuilt/index.js.map +0 -1
- package/dist/prebuilt/interrupt.cjs +0 -3
- package/dist/prebuilt/interrupt.js +0 -2
- package/dist/prebuilt/interrupt.js.map +0 -1
- package/dist/pregel/call.d.ts +0 -16
- package/dist/pregel/debug.d.ts +0 -41
- package/dist/pregel/debug.test.cjs +0 -258
- package/dist/pregel/debug.test.d.ts +0 -1
- package/dist/pregel/debug.test.js +0 -256
- package/dist/pregel/debug.test.js.map +0 -1
- package/dist/pregel/io.d.ts +0 -30
- package/dist/pregel/io.mapCommand.test.cjs +0 -150
- package/dist/pregel/io.mapCommand.test.d.ts +0 -1
- package/dist/pregel/io.mapCommand.test.js +0 -148
- package/dist/pregel/io.mapCommand.test.js.map +0 -1
- package/dist/pregel/loop.d.ts +0 -147
- package/dist/pregel/messages.d.ts +0 -30
- package/dist/pregel/messages.test.cjs +0 -369
- package/dist/pregel/messages.test.d.ts +0 -1
- package/dist/pregel/messages.test.js +0 -367
- package/dist/pregel/messages.test.js.map +0 -1
- package/dist/pregel/read.test.cjs +0 -194
- package/dist/pregel/read.test.d.ts +0 -1
- package/dist/pregel/read.test.js +0 -192
- package/dist/pregel/read.test.js.map +0 -1
- package/dist/pregel/retry.d.ts +0 -17
- package/dist/pregel/runnable_types.cjs +0 -3
- package/dist/pregel/runnable_types.js +0 -2
- package/dist/pregel/runnable_types.js.map +0 -1
- package/dist/pregel/runner.d.ts +0 -79
- package/dist/pregel/runner.test.cjs +0 -66
- package/dist/pregel/runner.test.d.ts +0 -1
- package/dist/pregel/runner.test.js +0 -64
- package/dist/pregel/runner.test.js.map +0 -1
- package/dist/pregel/stream.d.ts +0 -40
- package/dist/pregel/utils/config.test.cjs +0 -214
- package/dist/pregel/utils/config.test.d.ts +0 -1
- package/dist/pregel/utils/config.test.js +0 -212
- package/dist/pregel/utils/config.test.js.map +0 -1
- package/dist/pregel/utils/subgraph.d.ts +0 -4
- package/dist/pregel/utils/subgraph.test.cjs +0 -83
- package/dist/pregel/utils/subgraph.test.d.ts +0 -1
- package/dist/pregel/utils/subgraph.test.js +0 -81
- package/dist/pregel/utils/subgraph.test.js.map +0 -1
- package/dist/pregel/validate.d.ts +0 -16
- package/dist/pregel/validate.test.cjs +0 -220
- package/dist/pregel/validate.test.d.ts +0 -1
- package/dist/pregel/validate.test.js +0 -218
- package/dist/pregel/validate.test.js.map +0 -1
- package/dist/pregel/write.test.cjs +0 -181
- package/dist/pregel/write.test.d.ts +0 -1
- package/dist/pregel/write.test.js +0 -179
- package/dist/pregel/write.test.js.map +0 -1
- package/dist/remote.js.map +0 -1
- package/dist/setup/async_local_storage.d.ts +0 -1
- package/dist/web.js.map +0 -1
- package/index.cjs +0 -1
- package/index.d.cts +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/prebuilt.cjs +0 -1
- package/prebuilt.d.cts +0 -1
- package/prebuilt.d.ts +0 -1
- package/prebuilt.js +0 -1
- package/pregel.cjs +0 -1
- package/pregel.d.cts +0 -1
- package/pregel.d.ts +0 -1
- package/pregel.js +0 -1
- package/remote.cjs +0 -1
- package/remote.d.cts +0 -1
- package/remote.d.ts +0 -1
- package/remote.js +0 -1
- package/web.cjs +0 -1
- package/web.d.cts +0 -1
- package/web.d.ts +0 -1
- package/web.js +0 -1
- package/zod/schema.cjs +0 -1
- package/zod/schema.d.cts +0 -1
- package/zod/schema.d.ts +0 -1
- package/zod/schema.js +0 -1
- package/zod.cjs +0 -1
- package/zod.d.cts +0 -1
- package/zod.d.ts +0 -1
- package/zod.js +0 -1
package/dist/graph/state.js
CHANGED
|
@@ -1,795 +1,497 @@
|
|
|
1
|
-
|
|
2
|
-
import { _coerceToRunnable, Runnable } from "@langchain/core/runnables";
|
|
3
|
-
import { interopParse, interopZodObjectPartial, isInteropZodObject, } from "@langchain/core/utils/types";
|
|
1
|
+
import { InvalidUpdateError, ParentCommand } from "../errors.js";
|
|
4
2
|
import { isBaseChannel } from "../channels/base.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { NamedBarrierValue, NamedBarrierValueAfterFinish, } from "../channels/named_barrier_value.js";
|
|
9
|
-
import { EphemeralValue } from "../channels/ephemeral_value.js";
|
|
3
|
+
import { LastValueAfterFinish } from "../channels/last_value.js";
|
|
4
|
+
import { getChannel } from "./annotation.js";
|
|
5
|
+
import { CHECKPOINT_NAMESPACE_END, CHECKPOINT_NAMESPACE_SEPARATOR, Command, END, SELF, START, TAG_HIDDEN, _isSend, isCommand } from "../constants.js";
|
|
10
6
|
import { RunnableCallable } from "../utils.js";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { getChannel, } from "./annotation.js";
|
|
7
|
+
import { ChannelWrite, PASSTHROUGH } from "../pregel/write.js";
|
|
8
|
+
import { ChannelRead, PregelNode } from "../pregel/read.js";
|
|
14
9
|
import { isPregelLike } from "../pregel/utils/subgraph.js";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
10
|
+
import { EphemeralValue } from "../channels/ephemeral_value.js";
|
|
11
|
+
import { Branch, CompiledGraph, Graph } from "./graph.js";
|
|
12
|
+
import { NamedBarrierValue, NamedBarrierValueAfterFinish } from "../channels/named_barrier_value.js";
|
|
13
|
+
import { schemaMetaRegistry } from "./zod/meta.js";
|
|
14
|
+
import { Runnable, _coerceToRunnable } from "@langchain/core/runnables";
|
|
15
|
+
import { interopParse, interopZodObjectPartial, isInteropZodObject } from "@langchain/core/utils/types";
|
|
16
|
+
|
|
17
|
+
//#region src/graph/state.ts
|
|
17
18
|
const ROOT = "__root__";
|
|
18
19
|
const PartialStateSchema = Symbol.for("langgraph.state.partial");
|
|
19
20
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
CHECKPOINT_NAMESPACE_END,
|
|
282
|
-
]) {
|
|
283
|
-
if (key.includes(reservedChar)) {
|
|
284
|
-
throw new Error(`"${reservedChar}" is a reserved character and is not allowed in node names.`);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
this.warnIfCompiled(`Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
|
|
288
|
-
if (key in this.nodes) {
|
|
289
|
-
throw new Error(`Node \`${key}\` already present.`);
|
|
290
|
-
}
|
|
291
|
-
if (key === END || key === START) {
|
|
292
|
-
throw new Error(`Node \`${key}\` is reserved.`);
|
|
293
|
-
}
|
|
294
|
-
let inputSpec = this._schemaDefinition;
|
|
295
|
-
if (options?.input !== undefined) {
|
|
296
|
-
if (isInteropZodObject(options.input)) {
|
|
297
|
-
inputSpec = this._metaRegistry.getChannelsForSchema(options.input);
|
|
298
|
-
}
|
|
299
|
-
else if (options.input.spec !== undefined) {
|
|
300
|
-
inputSpec = options.input.spec;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
if (inputSpec !== undefined) {
|
|
304
|
-
this._addSchema(inputSpec);
|
|
305
|
-
}
|
|
306
|
-
let runnable;
|
|
307
|
-
if (Runnable.isRunnable(action)) {
|
|
308
|
-
runnable = action;
|
|
309
|
-
}
|
|
310
|
-
else if (typeof action === "function") {
|
|
311
|
-
runnable = new RunnableCallable({
|
|
312
|
-
func: action,
|
|
313
|
-
name: key,
|
|
314
|
-
trace: false,
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
runnable = _coerceToRunnable(action);
|
|
319
|
-
}
|
|
320
|
-
let cachePolicy = options?.cachePolicy;
|
|
321
|
-
if (typeof cachePolicy === "boolean") {
|
|
322
|
-
cachePolicy = cachePolicy ? {} : undefined;
|
|
323
|
-
}
|
|
324
|
-
const nodeSpec = {
|
|
325
|
-
runnable: runnable,
|
|
326
|
-
retryPolicy: options?.retryPolicy,
|
|
327
|
-
cachePolicy,
|
|
328
|
-
metadata: options?.metadata,
|
|
329
|
-
input: inputSpec ?? this._schemaDefinition,
|
|
330
|
-
subgraphs: isPregelLike(runnable)
|
|
331
|
-
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
332
|
-
[runnable]
|
|
333
|
-
: options?.subgraphs,
|
|
334
|
-
ends: options?.ends,
|
|
335
|
-
defer: options?.defer,
|
|
336
|
-
};
|
|
337
|
-
this.nodes[key] = nodeSpec;
|
|
338
|
-
}
|
|
339
|
-
return this;
|
|
340
|
-
}
|
|
341
|
-
addEdge(startKey, endKey) {
|
|
342
|
-
if (typeof startKey === "string") {
|
|
343
|
-
return super.addEdge(startKey, endKey);
|
|
344
|
-
}
|
|
345
|
-
if (this.compiled) {
|
|
346
|
-
console.warn("Adding an edge to a graph that has already been compiled. This will " +
|
|
347
|
-
"not be reflected in the compiled graph.");
|
|
348
|
-
}
|
|
349
|
-
for (const start of startKey) {
|
|
350
|
-
if (start === END) {
|
|
351
|
-
throw new Error("END cannot be a start node");
|
|
352
|
-
}
|
|
353
|
-
if (!Object.keys(this.nodes).some((node) => node === start)) {
|
|
354
|
-
throw new Error(`Need to add a node named "${start}" first`);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
if (endKey === END) {
|
|
358
|
-
throw new Error("END cannot be an end node");
|
|
359
|
-
}
|
|
360
|
-
if (!Object.keys(this.nodes).some((node) => node === endKey)) {
|
|
361
|
-
throw new Error(`Need to add a node named "${endKey}" first`);
|
|
362
|
-
}
|
|
363
|
-
this.waitingEdges.add([startKey, endKey]);
|
|
364
|
-
return this;
|
|
365
|
-
}
|
|
366
|
-
addSequence(nodes) {
|
|
367
|
-
const parsedNodes = Array.isArray(nodes)
|
|
368
|
-
? nodes
|
|
369
|
-
: Object.entries(nodes).map(([key, action]) => [
|
|
370
|
-
key,
|
|
371
|
-
action,
|
|
372
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
373
|
-
action[Symbol.for("langgraph.state.node")] ?? undefined,
|
|
374
|
-
]);
|
|
375
|
-
if (parsedNodes.length === 0) {
|
|
376
|
-
throw new Error("Sequence requires at least one node.");
|
|
377
|
-
}
|
|
378
|
-
let previousNode;
|
|
379
|
-
for (const [key, action, options] of parsedNodes) {
|
|
380
|
-
if (key in this.nodes) {
|
|
381
|
-
throw new Error(`Node names must be unique: node with the name "${key}" already exists.`);
|
|
382
|
-
}
|
|
383
|
-
const validKey = key;
|
|
384
|
-
this.addNode(validKey, action, options);
|
|
385
|
-
if (previousNode != null) {
|
|
386
|
-
this.addEdge(previousNode, validKey);
|
|
387
|
-
}
|
|
388
|
-
previousNode = validKey;
|
|
389
|
-
}
|
|
390
|
-
return this;
|
|
391
|
-
}
|
|
392
|
-
compile({ checkpointer, store, cache, interruptBefore, interruptAfter, name, description, } = {}) {
|
|
393
|
-
// validate the graph
|
|
394
|
-
this.validate([
|
|
395
|
-
...(Array.isArray(interruptBefore) ? interruptBefore : []),
|
|
396
|
-
...(Array.isArray(interruptAfter) ? interruptAfter : []),
|
|
397
|
-
]);
|
|
398
|
-
// prepare output channels
|
|
399
|
-
const outputKeys = Object.keys(this._schemaDefinitions.get(this._outputDefinition));
|
|
400
|
-
const outputChannels = outputKeys.length === 1 && outputKeys[0] === ROOT ? ROOT : outputKeys;
|
|
401
|
-
const streamKeys = Object.keys(this.channels);
|
|
402
|
-
const streamChannels = streamKeys.length === 1 && streamKeys[0] === ROOT ? ROOT : streamKeys;
|
|
403
|
-
// create empty compiled graph
|
|
404
|
-
const compiled = new CompiledStateGraph({
|
|
405
|
-
builder: this,
|
|
406
|
-
checkpointer,
|
|
407
|
-
interruptAfter,
|
|
408
|
-
interruptBefore,
|
|
409
|
-
autoValidate: false,
|
|
410
|
-
nodes: {},
|
|
411
|
-
channels: {
|
|
412
|
-
...this.channels,
|
|
413
|
-
[START]: new EphemeralValue(),
|
|
414
|
-
},
|
|
415
|
-
inputChannels: START,
|
|
416
|
-
outputChannels,
|
|
417
|
-
streamChannels,
|
|
418
|
-
streamMode: "updates",
|
|
419
|
-
store,
|
|
420
|
-
cache,
|
|
421
|
-
name,
|
|
422
|
-
description,
|
|
423
|
-
});
|
|
424
|
-
// attach nodes, edges and branches
|
|
425
|
-
compiled.attachNode(START);
|
|
426
|
-
for (const [key, node] of Object.entries(this.nodes)) {
|
|
427
|
-
compiled.attachNode(key, node);
|
|
428
|
-
}
|
|
429
|
-
compiled.attachBranch(START, SELF, _getControlBranch(), {
|
|
430
|
-
withReader: false,
|
|
431
|
-
});
|
|
432
|
-
for (const [key] of Object.entries(this.nodes)) {
|
|
433
|
-
compiled.attachBranch(key, SELF, _getControlBranch(), {
|
|
434
|
-
withReader: false,
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
for (const [start, end] of this.edges) {
|
|
438
|
-
compiled.attachEdge(start, end);
|
|
439
|
-
}
|
|
440
|
-
for (const [starts, end] of this.waitingEdges) {
|
|
441
|
-
compiled.attachEdge(starts, end);
|
|
442
|
-
}
|
|
443
|
-
for (const [start, branches] of Object.entries(this.branches)) {
|
|
444
|
-
for (const [name, branch] of Object.entries(branches)) {
|
|
445
|
-
compiled.attachBranch(start, name, branch);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
return compiled.validate();
|
|
449
|
-
}
|
|
450
|
-
}
|
|
21
|
+
* A graph whose nodes communicate by reading and writing to a shared state.
|
|
22
|
+
* Each node takes a defined `State` as input and returns a `Partial<State>`.
|
|
23
|
+
*
|
|
24
|
+
* Each state key can optionally be annotated with a reducer function that
|
|
25
|
+
* will be used to aggregate the values of that key received from multiple nodes.
|
|
26
|
+
* The signature of a reducer function is (left: Value, right: UpdateValue) => Value.
|
|
27
|
+
*
|
|
28
|
+
* See {@link Annotation} for more on defining state.
|
|
29
|
+
*
|
|
30
|
+
* After adding nodes and edges to your graph, you must call `.compile()` on it before
|
|
31
|
+
* you can use it.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import {
|
|
36
|
+
* type BaseMessage,
|
|
37
|
+
* AIMessage,
|
|
38
|
+
* HumanMessage,
|
|
39
|
+
* } from "@langchain/core/messages";
|
|
40
|
+
* import { StateGraph, Annotation } from "@langchain/langgraph";
|
|
41
|
+
*
|
|
42
|
+
* // Define a state with a single key named "messages" that will
|
|
43
|
+
* // combine a returned BaseMessage or arrays of BaseMessages
|
|
44
|
+
* const StateAnnotation = Annotation.Root({
|
|
45
|
+
* sentiment: Annotation<string>,
|
|
46
|
+
* messages: Annotation<BaseMessage[]>({
|
|
47
|
+
* reducer: (left: BaseMessage[], right: BaseMessage | BaseMessage[]) => {
|
|
48
|
+
* if (Array.isArray(right)) {
|
|
49
|
+
* return left.concat(right);
|
|
50
|
+
* }
|
|
51
|
+
* return left.concat([right]);
|
|
52
|
+
* },
|
|
53
|
+
* default: () => [],
|
|
54
|
+
* }),
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* const graphBuilder = new StateGraph(StateAnnotation);
|
|
58
|
+
*
|
|
59
|
+
* // A node in the graph that returns an object with a "messages" key
|
|
60
|
+
* // will update the state by combining the existing value with the returned one.
|
|
61
|
+
* const myNode = (state: typeof StateAnnotation.State) => {
|
|
62
|
+
* return {
|
|
63
|
+
* messages: [new AIMessage("Some new response")],
|
|
64
|
+
* sentiment: "positive",
|
|
65
|
+
* };
|
|
66
|
+
* };
|
|
67
|
+
*
|
|
68
|
+
* const graph = graphBuilder
|
|
69
|
+
* .addNode("myNode", myNode)
|
|
70
|
+
* .addEdge("__start__", "myNode")
|
|
71
|
+
* .addEdge("myNode", "__end__")
|
|
72
|
+
* .compile();
|
|
73
|
+
*
|
|
74
|
+
* await graph.invoke({ messages: [new HumanMessage("how are you?")] });
|
|
75
|
+
*
|
|
76
|
+
* // {
|
|
77
|
+
* // messages: [HumanMessage("how are you?"), AIMessage("Some new response")],
|
|
78
|
+
* // sentiment: "positive",
|
|
79
|
+
* // }
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
var StateGraph = class extends Graph {
|
|
83
|
+
channels = {};
|
|
84
|
+
waitingEdges = /* @__PURE__ */ new Set();
|
|
85
|
+
/** @internal */
|
|
86
|
+
_schemaDefinition;
|
|
87
|
+
/** @internal */
|
|
88
|
+
_schemaRuntimeDefinition;
|
|
89
|
+
/** @internal */
|
|
90
|
+
_inputDefinition;
|
|
91
|
+
/** @internal */
|
|
92
|
+
_inputRuntimeDefinition;
|
|
93
|
+
/** @internal */
|
|
94
|
+
_outputDefinition;
|
|
95
|
+
/** @internal */
|
|
96
|
+
_outputRuntimeDefinition;
|
|
97
|
+
/**
|
|
98
|
+
* Map schemas to managed values
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
_schemaDefinitions = /* @__PURE__ */ new Map();
|
|
102
|
+
/** @internal */
|
|
103
|
+
_metaRegistry = schemaMetaRegistry;
|
|
104
|
+
/** @internal Used only for typing. */
|
|
105
|
+
_configSchema;
|
|
106
|
+
/** @internal */
|
|
107
|
+
_configRuntimeSchema;
|
|
108
|
+
constructor(fields, contextSchema) {
|
|
109
|
+
super();
|
|
110
|
+
if (isZodStateGraphArgsWithStateSchema(fields)) {
|
|
111
|
+
const stateDef = this._metaRegistry.getChannelsForSchema(fields.state);
|
|
112
|
+
const inputDef = fields.input != null ? this._metaRegistry.getChannelsForSchema(fields.input) : stateDef;
|
|
113
|
+
const outputDef = fields.output != null ? this._metaRegistry.getChannelsForSchema(fields.output) : stateDef;
|
|
114
|
+
this._schemaDefinition = stateDef;
|
|
115
|
+
this._schemaRuntimeDefinition = fields.state;
|
|
116
|
+
this._inputDefinition = inputDef;
|
|
117
|
+
this._inputRuntimeDefinition = fields.input ?? PartialStateSchema;
|
|
118
|
+
this._outputDefinition = outputDef;
|
|
119
|
+
this._outputRuntimeDefinition = fields.output ?? fields.state;
|
|
120
|
+
} else if (isInteropZodObject(fields)) {
|
|
121
|
+
const stateDef = this._metaRegistry.getChannelsForSchema(fields);
|
|
122
|
+
this._schemaDefinition = stateDef;
|
|
123
|
+
this._schemaRuntimeDefinition = fields;
|
|
124
|
+
this._inputDefinition = stateDef;
|
|
125
|
+
this._inputRuntimeDefinition = PartialStateSchema;
|
|
126
|
+
this._outputDefinition = stateDef;
|
|
127
|
+
this._outputRuntimeDefinition = fields;
|
|
128
|
+
} else if (isStateGraphArgsWithInputOutputSchemas(fields)) {
|
|
129
|
+
this._schemaDefinition = fields.input.spec;
|
|
130
|
+
this._inputDefinition = fields.input.spec;
|
|
131
|
+
this._outputDefinition = fields.output.spec;
|
|
132
|
+
} else if (isStateGraphArgsWithStateSchema(fields)) {
|
|
133
|
+
this._schemaDefinition = fields.stateSchema.spec;
|
|
134
|
+
this._inputDefinition = fields.input?.spec ?? this._schemaDefinition;
|
|
135
|
+
this._outputDefinition = fields.output?.spec ?? this._schemaDefinition;
|
|
136
|
+
} else if (isStateDefinition(fields) || isAnnotationRoot(fields)) {
|
|
137
|
+
const spec = isAnnotationRoot(fields) ? fields.spec : fields;
|
|
138
|
+
this._schemaDefinition = spec;
|
|
139
|
+
} else if (isStateGraphArgs(fields)) {
|
|
140
|
+
const spec = _getChannels(fields.channels);
|
|
141
|
+
this._schemaDefinition = spec;
|
|
142
|
+
} else throw new Error("Invalid StateGraph input. Make sure to pass a valid Annotation.Root or Zod schema.");
|
|
143
|
+
this._inputDefinition ??= this._schemaDefinition;
|
|
144
|
+
this._outputDefinition ??= this._schemaDefinition;
|
|
145
|
+
this._addSchema(this._schemaDefinition);
|
|
146
|
+
this._addSchema(this._inputDefinition);
|
|
147
|
+
this._addSchema(this._outputDefinition);
|
|
148
|
+
if (isInteropZodObject(contextSchema)) this._configRuntimeSchema = contextSchema;
|
|
149
|
+
}
|
|
150
|
+
get allEdges() {
|
|
151
|
+
return new Set([...this.edges, ...Array.from(this.waitingEdges).flatMap(([starts, end]) => starts.map((start) => [start, end]))]);
|
|
152
|
+
}
|
|
153
|
+
_addSchema(stateDefinition) {
|
|
154
|
+
if (this._schemaDefinitions.has(stateDefinition)) return;
|
|
155
|
+
this._schemaDefinitions.set(stateDefinition, stateDefinition);
|
|
156
|
+
for (const [key, val] of Object.entries(stateDefinition)) {
|
|
157
|
+
let channel;
|
|
158
|
+
if (typeof val === "function") channel = val();
|
|
159
|
+
else channel = val;
|
|
160
|
+
if (this.channels[key] !== void 0) {
|
|
161
|
+
if (this.channels[key] !== channel) {
|
|
162
|
+
if (channel.lc_graph_name !== "LastValue") throw new Error(`Channel "${key}" already exists with a different type.`);
|
|
163
|
+
}
|
|
164
|
+
} else this.channels[key] = channel;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
addNode(...args) {
|
|
168
|
+
function isMultipleNodes(args$1) {
|
|
169
|
+
return args$1.length >= 1 && typeof args$1[0] !== "string";
|
|
170
|
+
}
|
|
171
|
+
const nodes = isMultipleNodes(args) ? Array.isArray(args[0]) ? args[0] : Object.entries(args[0]).map(([key, action]) => [
|
|
172
|
+
key,
|
|
173
|
+
action,
|
|
174
|
+
action[Symbol.for("langgraph.state.node")] ?? void 0
|
|
175
|
+
]) : [[
|
|
176
|
+
args[0],
|
|
177
|
+
args[1],
|
|
178
|
+
args[2]
|
|
179
|
+
]];
|
|
180
|
+
if (nodes.length === 0) throw new Error("No nodes provided in `addNode`");
|
|
181
|
+
for (const [key, action, options] of nodes) {
|
|
182
|
+
if (key in this.channels) throw new Error(`${key} is already being used as a state attribute (a.k.a. a channel), cannot also be used as a node name.`);
|
|
183
|
+
for (const reservedChar of [CHECKPOINT_NAMESPACE_SEPARATOR, CHECKPOINT_NAMESPACE_END]) if (key.includes(reservedChar)) throw new Error(`"${reservedChar}" is a reserved character and is not allowed in node names.`);
|
|
184
|
+
this.warnIfCompiled(`Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
|
|
185
|
+
if (key in this.nodes) throw new Error(`Node \`${key}\` already present.`);
|
|
186
|
+
if (key === END || key === START) throw new Error(`Node \`${key}\` is reserved.`);
|
|
187
|
+
let inputSpec = this._schemaDefinition;
|
|
188
|
+
if (options?.input !== void 0) {
|
|
189
|
+
if (isInteropZodObject(options.input)) inputSpec = this._metaRegistry.getChannelsForSchema(options.input);
|
|
190
|
+
else if (options.input.spec !== void 0) inputSpec = options.input.spec;
|
|
191
|
+
}
|
|
192
|
+
if (inputSpec !== void 0) this._addSchema(inputSpec);
|
|
193
|
+
let runnable;
|
|
194
|
+
if (Runnable.isRunnable(action)) runnable = action;
|
|
195
|
+
else if (typeof action === "function") runnable = new RunnableCallable({
|
|
196
|
+
func: action,
|
|
197
|
+
name: key,
|
|
198
|
+
trace: false
|
|
199
|
+
});
|
|
200
|
+
else runnable = _coerceToRunnable(action);
|
|
201
|
+
let cachePolicy = options?.cachePolicy;
|
|
202
|
+
if (typeof cachePolicy === "boolean") cachePolicy = cachePolicy ? {} : void 0;
|
|
203
|
+
const nodeSpec = {
|
|
204
|
+
runnable,
|
|
205
|
+
retryPolicy: options?.retryPolicy,
|
|
206
|
+
cachePolicy,
|
|
207
|
+
metadata: options?.metadata,
|
|
208
|
+
input: inputSpec ?? this._schemaDefinition,
|
|
209
|
+
subgraphs: isPregelLike(runnable) ? [runnable] : options?.subgraphs,
|
|
210
|
+
ends: options?.ends,
|
|
211
|
+
defer: options?.defer
|
|
212
|
+
};
|
|
213
|
+
this.nodes[key] = nodeSpec;
|
|
214
|
+
}
|
|
215
|
+
return this;
|
|
216
|
+
}
|
|
217
|
+
addEdge(startKey, endKey) {
|
|
218
|
+
if (typeof startKey === "string") return super.addEdge(startKey, endKey);
|
|
219
|
+
if (this.compiled) console.warn("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.");
|
|
220
|
+
for (const start of startKey) {
|
|
221
|
+
if (start === END) throw new Error("END cannot be a start node");
|
|
222
|
+
if (!Object.keys(this.nodes).some((node) => node === start)) throw new Error(`Need to add a node named "${start}" first`);
|
|
223
|
+
}
|
|
224
|
+
if (endKey === END) throw new Error("END cannot be an end node");
|
|
225
|
+
if (!Object.keys(this.nodes).some((node) => node === endKey)) throw new Error(`Need to add a node named "${endKey}" first`);
|
|
226
|
+
this.waitingEdges.add([startKey, endKey]);
|
|
227
|
+
return this;
|
|
228
|
+
}
|
|
229
|
+
addSequence(nodes) {
|
|
230
|
+
const parsedNodes = Array.isArray(nodes) ? nodes : Object.entries(nodes).map(([key, action]) => [
|
|
231
|
+
key,
|
|
232
|
+
action,
|
|
233
|
+
action[Symbol.for("langgraph.state.node")] ?? void 0
|
|
234
|
+
]);
|
|
235
|
+
if (parsedNodes.length === 0) throw new Error("Sequence requires at least one node.");
|
|
236
|
+
let previousNode;
|
|
237
|
+
for (const [key, action, options] of parsedNodes) {
|
|
238
|
+
if (key in this.nodes) throw new Error(`Node names must be unique: node with the name "${key}" already exists.`);
|
|
239
|
+
const validKey = key;
|
|
240
|
+
this.addNode(validKey, action, options);
|
|
241
|
+
if (previousNode != null) this.addEdge(previousNode, validKey);
|
|
242
|
+
previousNode = validKey;
|
|
243
|
+
}
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
compile({ checkpointer, store, cache, interruptBefore, interruptAfter, name, description } = {}) {
|
|
247
|
+
this.validate([...Array.isArray(interruptBefore) ? interruptBefore : [], ...Array.isArray(interruptAfter) ? interruptAfter : []]);
|
|
248
|
+
const outputKeys = Object.keys(this._schemaDefinitions.get(this._outputDefinition));
|
|
249
|
+
const outputChannels = outputKeys.length === 1 && outputKeys[0] === ROOT ? ROOT : outputKeys;
|
|
250
|
+
const streamKeys = Object.keys(this.channels);
|
|
251
|
+
const streamChannels = streamKeys.length === 1 && streamKeys[0] === ROOT ? ROOT : streamKeys;
|
|
252
|
+
const compiled = new CompiledStateGraph({
|
|
253
|
+
builder: this,
|
|
254
|
+
checkpointer,
|
|
255
|
+
interruptAfter,
|
|
256
|
+
interruptBefore,
|
|
257
|
+
autoValidate: false,
|
|
258
|
+
nodes: {},
|
|
259
|
+
channels: {
|
|
260
|
+
...this.channels,
|
|
261
|
+
[START]: new EphemeralValue()
|
|
262
|
+
},
|
|
263
|
+
inputChannels: START,
|
|
264
|
+
outputChannels,
|
|
265
|
+
streamChannels,
|
|
266
|
+
streamMode: "updates",
|
|
267
|
+
store,
|
|
268
|
+
cache,
|
|
269
|
+
name,
|
|
270
|
+
description
|
|
271
|
+
});
|
|
272
|
+
compiled.attachNode(START);
|
|
273
|
+
for (const [key, node] of Object.entries(this.nodes)) compiled.attachNode(key, node);
|
|
274
|
+
compiled.attachBranch(START, SELF, _getControlBranch(), { withReader: false });
|
|
275
|
+
for (const [key] of Object.entries(this.nodes)) compiled.attachBranch(key, SELF, _getControlBranch(), { withReader: false });
|
|
276
|
+
for (const [start, end] of this.edges) compiled.attachEdge(start, end);
|
|
277
|
+
for (const [starts, end] of this.waitingEdges) compiled.attachEdge(starts, end);
|
|
278
|
+
for (const [start, branches] of Object.entries(this.branches)) for (const [name$1, branch] of Object.entries(branches)) compiled.attachBranch(start, name$1, branch);
|
|
279
|
+
return compiled.validate();
|
|
280
|
+
}
|
|
281
|
+
};
|
|
451
282
|
function _getChannels(schema) {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
else {
|
|
458
|
-
const key = name;
|
|
459
|
-
channels[name] = getChannel(val);
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
return channels;
|
|
283
|
+
const channels = {};
|
|
284
|
+
for (const [name, val] of Object.entries(schema)) if (name === ROOT) channels[name] = getChannel(val);
|
|
285
|
+
else channels[name] = getChannel(val);
|
|
286
|
+
return channels;
|
|
463
287
|
}
|
|
464
288
|
/**
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
subgraphs: node?.subgraphs,
|
|
619
|
-
ends: node?.ends,
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
attachEdge(starts, end) {
|
|
624
|
-
if (end === END)
|
|
625
|
-
return;
|
|
626
|
-
if (typeof starts === "string") {
|
|
627
|
-
this.nodes[starts].writers.push(new ChannelWrite([{ channel: `branch:to:${end}`, value: null }], [TAG_HIDDEN]));
|
|
628
|
-
}
|
|
629
|
-
else if (Array.isArray(starts)) {
|
|
630
|
-
const channelName = `join:${starts.join("+")}:${end}`;
|
|
631
|
-
// register channel
|
|
632
|
-
this.channels[channelName] = this.builder.nodes[end].defer
|
|
633
|
-
? new NamedBarrierValueAfterFinish(new Set(starts))
|
|
634
|
-
: new NamedBarrierValue(new Set(starts));
|
|
635
|
-
// subscribe to channel
|
|
636
|
-
this.nodes[end].triggers.push(channelName);
|
|
637
|
-
// publish to channel
|
|
638
|
-
for (const start of starts) {
|
|
639
|
-
this.nodes[start].writers.push(new ChannelWrite([{ channel: channelName, value: start }], [TAG_HIDDEN]));
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
attachBranch(start, _, branch, options = { withReader: true }) {
|
|
644
|
-
const branchWriter = async (packets, config) => {
|
|
645
|
-
const filteredPackets = packets.filter((p) => p !== END);
|
|
646
|
-
if (!filteredPackets.length)
|
|
647
|
-
return;
|
|
648
|
-
const writes = filteredPackets.map((p) => {
|
|
649
|
-
if (_isSend(p))
|
|
650
|
-
return p;
|
|
651
|
-
return { channel: p === END ? p : `branch:to:${p}`, value: start };
|
|
652
|
-
});
|
|
653
|
-
await ChannelWrite.doWrite({ ...config, tags: (config.tags ?? []).concat([TAG_HIDDEN]) }, writes);
|
|
654
|
-
};
|
|
655
|
-
// attach branch publisher
|
|
656
|
-
this.nodes[start].writers.push(branch.run(branchWriter,
|
|
657
|
-
// reader
|
|
658
|
-
options.withReader
|
|
659
|
-
? (config) => ChannelRead.doRead(config, this.streamChannels ?? this.outputChannels, true)
|
|
660
|
-
: undefined));
|
|
661
|
-
}
|
|
662
|
-
async _validateInput(input) {
|
|
663
|
-
if (input == null)
|
|
664
|
-
return input;
|
|
665
|
-
const schema = (() => {
|
|
666
|
-
const input = this.builder._inputRuntimeDefinition;
|
|
667
|
-
const schema = this.builder._schemaRuntimeDefinition;
|
|
668
|
-
const apply = (schema) => {
|
|
669
|
-
if (schema == null)
|
|
670
|
-
return undefined;
|
|
671
|
-
return this._metaRegistry.getExtendedChannelSchemas(schema, {
|
|
672
|
-
withReducerSchema: true,
|
|
673
|
-
});
|
|
674
|
-
};
|
|
675
|
-
if (isInteropZodObject(input))
|
|
676
|
-
return apply(input);
|
|
677
|
-
if (input === PartialStateSchema) {
|
|
678
|
-
return interopZodObjectPartial(apply(schema));
|
|
679
|
-
}
|
|
680
|
-
return undefined;
|
|
681
|
-
})();
|
|
682
|
-
if (isCommand(input)) {
|
|
683
|
-
const parsedInput = input;
|
|
684
|
-
if (input.update && schema != null)
|
|
685
|
-
parsedInput.update = interopParse(schema, input.update);
|
|
686
|
-
return parsedInput;
|
|
687
|
-
}
|
|
688
|
-
if (schema != null)
|
|
689
|
-
return interopParse(schema, input);
|
|
690
|
-
return input;
|
|
691
|
-
}
|
|
692
|
-
async _validateContext(config) {
|
|
693
|
-
const configSchema = this.builder._configRuntimeSchema;
|
|
694
|
-
if (isInteropZodObject(configSchema))
|
|
695
|
-
interopParse(configSchema, config);
|
|
696
|
-
return config;
|
|
697
|
-
}
|
|
698
|
-
}
|
|
289
|
+
* Final result from building and compiling a {@link StateGraph}.
|
|
290
|
+
* Should not be instantiated directly, only using the StateGraph `.compile()`
|
|
291
|
+
* instance method.
|
|
292
|
+
*/
|
|
293
|
+
var CompiledStateGraph = class extends CompiledGraph {
|
|
294
|
+
/**
|
|
295
|
+
* The description of the compiled graph.
|
|
296
|
+
* This is used by the supervisor agent to describe the handoff to the agent.
|
|
297
|
+
*/
|
|
298
|
+
description;
|
|
299
|
+
/** @internal */
|
|
300
|
+
_metaRegistry = schemaMetaRegistry;
|
|
301
|
+
constructor({ description,...rest }) {
|
|
302
|
+
super(rest);
|
|
303
|
+
this.description = description;
|
|
304
|
+
}
|
|
305
|
+
attachNode(key, node) {
|
|
306
|
+
let outputKeys;
|
|
307
|
+
if (key === START) outputKeys = Object.entries(this.builder._schemaDefinitions.get(this.builder._inputDefinition)).map(([k]) => k);
|
|
308
|
+
else outputKeys = Object.keys(this.builder.channels);
|
|
309
|
+
function _getRoot(input) {
|
|
310
|
+
if (isCommand(input)) {
|
|
311
|
+
if (input.graph === Command.PARENT) return null;
|
|
312
|
+
return input._updateAsTuples();
|
|
313
|
+
} else if (Array.isArray(input) && input.length > 0 && input.some((i) => isCommand(i))) {
|
|
314
|
+
const updates = [];
|
|
315
|
+
for (const i of input) if (isCommand(i)) {
|
|
316
|
+
if (i.graph === Command.PARENT) continue;
|
|
317
|
+
updates.push(...i._updateAsTuples());
|
|
318
|
+
} else updates.push([ROOT, i]);
|
|
319
|
+
return updates;
|
|
320
|
+
} else if (input != null) return [[ROOT, input]];
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
323
|
+
const nodeKey = key;
|
|
324
|
+
function _getUpdates(input) {
|
|
325
|
+
if (!input) return null;
|
|
326
|
+
else if (isCommand(input)) {
|
|
327
|
+
if (input.graph === Command.PARENT) return null;
|
|
328
|
+
return input._updateAsTuples().filter(([k]) => outputKeys.includes(k));
|
|
329
|
+
} else if (Array.isArray(input) && input.length > 0 && input.some(isCommand)) {
|
|
330
|
+
const updates = [];
|
|
331
|
+
for (const item of input) if (isCommand(item)) {
|
|
332
|
+
if (item.graph === Command.PARENT) continue;
|
|
333
|
+
updates.push(...item._updateAsTuples().filter(([k]) => outputKeys.includes(k)));
|
|
334
|
+
} else {
|
|
335
|
+
const itemUpdates = _getUpdates(item);
|
|
336
|
+
if (itemUpdates) updates.push(...itemUpdates ?? []);
|
|
337
|
+
}
|
|
338
|
+
return updates;
|
|
339
|
+
} else if (typeof input === "object" && !Array.isArray(input)) return Object.entries(input).filter(([k]) => outputKeys.includes(k));
|
|
340
|
+
else {
|
|
341
|
+
const typeofInput = Array.isArray(input) ? "array" : typeof input;
|
|
342
|
+
throw new InvalidUpdateError(`Expected node "${nodeKey.toString()}" to return an object or an array containing at least one Command object, received ${typeofInput}`, { lc_error_code: "INVALID_GRAPH_NODE_RETURN_VALUE" });
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
const stateWriteEntries = [{
|
|
346
|
+
value: PASSTHROUGH,
|
|
347
|
+
mapper: new RunnableCallable({
|
|
348
|
+
func: outputKeys.length && outputKeys[0] === ROOT ? _getRoot : _getUpdates,
|
|
349
|
+
trace: false,
|
|
350
|
+
recurse: false
|
|
351
|
+
})
|
|
352
|
+
}];
|
|
353
|
+
if (key === START) this.nodes[key] = new PregelNode({
|
|
354
|
+
tags: [TAG_HIDDEN],
|
|
355
|
+
triggers: [START],
|
|
356
|
+
channels: [START],
|
|
357
|
+
writers: [new ChannelWrite(stateWriteEntries, [TAG_HIDDEN])]
|
|
358
|
+
});
|
|
359
|
+
else {
|
|
360
|
+
const inputDefinition = node?.input ?? this.builder._schemaDefinition;
|
|
361
|
+
const inputValues = Object.fromEntries(Object.keys(this.builder._schemaDefinitions.get(inputDefinition)).map((k) => [k, k]));
|
|
362
|
+
const isSingleInput = Object.keys(inputValues).length === 1 && ROOT in inputValues;
|
|
363
|
+
const branchChannel = `branch:to:${key}`;
|
|
364
|
+
this.channels[branchChannel] = node?.defer ? new LastValueAfterFinish() : new EphemeralValue(false);
|
|
365
|
+
this.nodes[key] = new PregelNode({
|
|
366
|
+
triggers: [branchChannel],
|
|
367
|
+
channels: isSingleInput ? Object.keys(inputValues) : inputValues,
|
|
368
|
+
writers: [new ChannelWrite(stateWriteEntries, [TAG_HIDDEN])],
|
|
369
|
+
mapper: isSingleInput ? void 0 : (input) => {
|
|
370
|
+
return Object.fromEntries(Object.entries(input).filter(([k]) => k in inputValues));
|
|
371
|
+
},
|
|
372
|
+
bound: node?.runnable,
|
|
373
|
+
metadata: node?.metadata,
|
|
374
|
+
retryPolicy: node?.retryPolicy,
|
|
375
|
+
cachePolicy: node?.cachePolicy,
|
|
376
|
+
subgraphs: node?.subgraphs,
|
|
377
|
+
ends: node?.ends
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
attachEdge(starts, end) {
|
|
382
|
+
if (end === END) return;
|
|
383
|
+
if (typeof starts === "string") this.nodes[starts].writers.push(new ChannelWrite([{
|
|
384
|
+
channel: `branch:to:${end}`,
|
|
385
|
+
value: null
|
|
386
|
+
}], [TAG_HIDDEN]));
|
|
387
|
+
else if (Array.isArray(starts)) {
|
|
388
|
+
const channelName = `join:${starts.join("+")}:${end}`;
|
|
389
|
+
this.channels[channelName] = this.builder.nodes[end].defer ? new NamedBarrierValueAfterFinish(new Set(starts)) : new NamedBarrierValue(new Set(starts));
|
|
390
|
+
this.nodes[end].triggers.push(channelName);
|
|
391
|
+
for (const start of starts) this.nodes[start].writers.push(new ChannelWrite([{
|
|
392
|
+
channel: channelName,
|
|
393
|
+
value: start
|
|
394
|
+
}], [TAG_HIDDEN]));
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
attachBranch(start, _, branch, options = { withReader: true }) {
|
|
398
|
+
const branchWriter = async (packets, config) => {
|
|
399
|
+
const filteredPackets = packets.filter((p) => p !== END);
|
|
400
|
+
if (!filteredPackets.length) return;
|
|
401
|
+
const writes = filteredPackets.map((p) => {
|
|
402
|
+
if (_isSend(p)) return p;
|
|
403
|
+
return {
|
|
404
|
+
channel: p === END ? p : `branch:to:${p}`,
|
|
405
|
+
value: start
|
|
406
|
+
};
|
|
407
|
+
});
|
|
408
|
+
await ChannelWrite.doWrite({
|
|
409
|
+
...config,
|
|
410
|
+
tags: (config.tags ?? []).concat([TAG_HIDDEN])
|
|
411
|
+
}, writes);
|
|
412
|
+
};
|
|
413
|
+
this.nodes[start].writers.push(branch.run(branchWriter, options.withReader ? (config) => ChannelRead.doRead(config, this.streamChannels ?? this.outputChannels, true) : void 0));
|
|
414
|
+
}
|
|
415
|
+
async _validateInput(input) {
|
|
416
|
+
if (input == null) return input;
|
|
417
|
+
const schema = (() => {
|
|
418
|
+
const input$1 = this.builder._inputRuntimeDefinition;
|
|
419
|
+
const schema$1 = this.builder._schemaRuntimeDefinition;
|
|
420
|
+
const apply = (schema$2) => {
|
|
421
|
+
if (schema$2 == null) return void 0;
|
|
422
|
+
return this._metaRegistry.getExtendedChannelSchemas(schema$2, { withReducerSchema: true });
|
|
423
|
+
};
|
|
424
|
+
if (isInteropZodObject(input$1)) return apply(input$1);
|
|
425
|
+
if (input$1 === PartialStateSchema) return interopZodObjectPartial(apply(schema$1));
|
|
426
|
+
return void 0;
|
|
427
|
+
})();
|
|
428
|
+
if (isCommand(input)) {
|
|
429
|
+
const parsedInput = input;
|
|
430
|
+
if (input.update && schema != null) parsedInput.update = interopParse(schema, input.update);
|
|
431
|
+
return parsedInput;
|
|
432
|
+
}
|
|
433
|
+
if (schema != null) return interopParse(schema, input);
|
|
434
|
+
return input;
|
|
435
|
+
}
|
|
436
|
+
async _validateContext(config) {
|
|
437
|
+
const configSchema = this.builder._configRuntimeSchema;
|
|
438
|
+
if (isInteropZodObject(configSchema)) interopParse(configSchema, config);
|
|
439
|
+
return config;
|
|
440
|
+
}
|
|
441
|
+
};
|
|
699
442
|
function isStateDefinition(obj) {
|
|
700
|
-
|
|
701
|
-
obj !== null &&
|
|
702
|
-
!Array.isArray(obj) &&
|
|
703
|
-
Object.keys(obj).length > 0 &&
|
|
704
|
-
Object.values(obj).every((v) => typeof v === "function" || isBaseChannel(v)));
|
|
443
|
+
return typeof obj === "object" && obj !== null && !Array.isArray(obj) && Object.keys(obj).length > 0 && Object.values(obj).every((v) => typeof v === "function" || isBaseChannel(v));
|
|
705
444
|
}
|
|
706
445
|
function isAnnotationRoot(obj) {
|
|
707
|
-
|
|
708
|
-
obj !== null &&
|
|
709
|
-
"lc_graph_name" in obj &&
|
|
710
|
-
obj.lc_graph_name === "AnnotationRoot");
|
|
446
|
+
return typeof obj === "object" && obj !== null && "lc_graph_name" in obj && obj.lc_graph_name === "AnnotationRoot";
|
|
711
447
|
}
|
|
712
448
|
function isStateGraphArgs(obj) {
|
|
713
|
-
|
|
714
|
-
obj !== null &&
|
|
715
|
-
obj.channels !== undefined);
|
|
449
|
+
return typeof obj === "object" && obj !== null && obj.channels !== void 0;
|
|
716
450
|
}
|
|
717
451
|
function isStateGraphArgsWithStateSchema(obj) {
|
|
718
|
-
|
|
719
|
-
obj !== null &&
|
|
720
|
-
obj.stateSchema !== undefined);
|
|
452
|
+
return typeof obj === "object" && obj !== null && obj.stateSchema !== void 0;
|
|
721
453
|
}
|
|
722
454
|
function isStateGraphArgsWithInputOutputSchemas(obj) {
|
|
723
|
-
|
|
724
|
-
obj !== null &&
|
|
725
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
726
|
-
obj.stateSchema === undefined &&
|
|
727
|
-
obj.input !== undefined &&
|
|
728
|
-
obj.output !== undefined);
|
|
455
|
+
return typeof obj === "object" && obj !== null && obj.stateSchema === void 0 && obj.input !== void 0 && obj.output !== void 0;
|
|
729
456
|
}
|
|
730
457
|
function isZodStateGraphArgsWithStateSchema(value) {
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
}
|
|
737
|
-
if ("input" in value && !isInteropZodObject(value.input)) {
|
|
738
|
-
return false;
|
|
739
|
-
}
|
|
740
|
-
if ("output" in value && !isInteropZodObject(value.output)) {
|
|
741
|
-
return false;
|
|
742
|
-
}
|
|
743
|
-
return true;
|
|
458
|
+
if (typeof value !== "object" || value == null) return false;
|
|
459
|
+
if (!("state" in value) || !isInteropZodObject(value.state)) return false;
|
|
460
|
+
if ("input" in value && !isInteropZodObject(value.input)) return false;
|
|
461
|
+
if ("output" in value && !isInteropZodObject(value.output)) return false;
|
|
462
|
+
return true;
|
|
744
463
|
}
|
|
745
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
746
464
|
function _controlBranch(value) {
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
if (command.graph === Command.PARENT) {
|
|
760
|
-
throw new ParentCommand(command);
|
|
761
|
-
}
|
|
762
|
-
if (_isSend(command.goto)) {
|
|
763
|
-
destinations.push(command.goto);
|
|
764
|
-
}
|
|
765
|
-
else if (typeof command.goto === "string") {
|
|
766
|
-
destinations.push(command.goto);
|
|
767
|
-
}
|
|
768
|
-
else {
|
|
769
|
-
if (Array.isArray(command.goto)) {
|
|
770
|
-
destinations.push(...command.goto);
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
return destinations;
|
|
465
|
+
if (_isSend(value)) return [value];
|
|
466
|
+
const commands = [];
|
|
467
|
+
if (isCommand(value)) commands.push(value);
|
|
468
|
+
else if (Array.isArray(value)) commands.push(...value.filter(isCommand));
|
|
469
|
+
const destinations = [];
|
|
470
|
+
for (const command of commands) {
|
|
471
|
+
if (command.graph === Command.PARENT) throw new ParentCommand(command);
|
|
472
|
+
if (_isSend(command.goto)) destinations.push(command.goto);
|
|
473
|
+
else if (typeof command.goto === "string") destinations.push(command.goto);
|
|
474
|
+
else if (Array.isArray(command.goto)) destinations.push(...command.goto);
|
|
475
|
+
}
|
|
476
|
+
return destinations;
|
|
775
477
|
}
|
|
776
478
|
function _getControlBranch() {
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
return new Branch({
|
|
786
|
-
path: CONTROL_BRANCH_PATH,
|
|
787
|
-
});
|
|
479
|
+
const CONTROL_BRANCH_PATH = new RunnableCallable({
|
|
480
|
+
func: _controlBranch,
|
|
481
|
+
tags: [TAG_HIDDEN],
|
|
482
|
+
trace: false,
|
|
483
|
+
recurse: false,
|
|
484
|
+
name: "<control_branch>"
|
|
485
|
+
});
|
|
486
|
+
return new Branch({ path: CONTROL_BRANCH_PATH });
|
|
788
487
|
}
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
488
|
+
function typedNode(_state, _options) {
|
|
489
|
+
return (func, options) => {
|
|
490
|
+
Object.assign(func, { [Symbol.for("langgraph.state.node")]: options });
|
|
491
|
+
return func;
|
|
492
|
+
};
|
|
794
493
|
}
|
|
494
|
+
|
|
495
|
+
//#endregion
|
|
496
|
+
export { CompiledStateGraph, StateGraph, typedNode };
|
|
795
497
|
//# sourceMappingURL=state.js.map
|