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