@langchain/langgraph 1.3.7 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/dist/channels/base.cjs +78 -2
  2. package/dist/channels/base.cjs.map +1 -1
  3. package/dist/channels/base.d.cts +35 -2
  4. package/dist/channels/base.d.cts.map +1 -1
  5. package/dist/channels/base.d.ts +35 -2
  6. package/dist/channels/base.d.ts.map +1 -1
  7. package/dist/channels/base.js +77 -4
  8. package/dist/channels/base.js.map +1 -1
  9. package/dist/channels/delta.cjs +136 -0
  10. package/dist/channels/delta.cjs.map +1 -0
  11. package/dist/channels/delta.d.cts +99 -0
  12. package/dist/channels/delta.d.cts.map +1 -0
  13. package/dist/channels/delta.d.ts +99 -0
  14. package/dist/channels/delta.d.ts.map +1 -0
  15. package/dist/channels/delta.js +136 -0
  16. package/dist/channels/delta.js.map +1 -0
  17. package/dist/channels/index.cjs +5 -0
  18. package/dist/channels/index.d.cts +3 -2
  19. package/dist/channels/index.d.ts +3 -2
  20. package/dist/channels/index.js +3 -2
  21. package/dist/constants.cjs +63 -4
  22. package/dist/constants.cjs.map +1 -1
  23. package/dist/constants.d.cts +33 -2
  24. package/dist/constants.d.cts.map +1 -1
  25. package/dist/constants.d.ts +33 -2
  26. package/dist/constants.d.ts.map +1 -1
  27. package/dist/constants.js +59 -5
  28. package/dist/constants.js.map +1 -1
  29. package/dist/errors.cjs +128 -0
  30. package/dist/errors.cjs.map +1 -1
  31. package/dist/errors.d.cts +86 -1
  32. package/dist/errors.d.cts.map +1 -1
  33. package/dist/errors.d.ts +86 -1
  34. package/dist/errors.d.ts.map +1 -1
  35. package/dist/errors.js +123 -1
  36. package/dist/errors.js.map +1 -1
  37. package/dist/func/index.cjs +9 -2
  38. package/dist/func/index.cjs.map +1 -1
  39. package/dist/func/index.d.cts +14 -0
  40. package/dist/func/index.d.cts.map +1 -1
  41. package/dist/func/index.d.ts +14 -0
  42. package/dist/func/index.d.ts.map +1 -1
  43. package/dist/func/index.js +9 -2
  44. package/dist/func/index.js.map +1 -1
  45. package/dist/graph/graph.cjs +44 -7
  46. package/dist/graph/graph.cjs.map +1 -1
  47. package/dist/graph/graph.d.cts +24 -2
  48. package/dist/graph/graph.d.cts.map +1 -1
  49. package/dist/graph/graph.d.ts +24 -2
  50. package/dist/graph/graph.d.ts.map +1 -1
  51. package/dist/graph/graph.js +44 -7
  52. package/dist/graph/graph.js.map +1 -1
  53. package/dist/graph/index.d.ts +3 -3
  54. package/dist/graph/messages_reducer.cjs +55 -0
  55. package/dist/graph/messages_reducer.cjs.map +1 -1
  56. package/dist/graph/messages_reducer.d.cts +28 -1
  57. package/dist/graph/messages_reducer.d.cts.map +1 -1
  58. package/dist/graph/messages_reducer.d.ts +28 -1
  59. package/dist/graph/messages_reducer.d.ts.map +1 -1
  60. package/dist/graph/messages_reducer.js +56 -2
  61. package/dist/graph/messages_reducer.js.map +1 -1
  62. package/dist/graph/state.cjs +208 -12
  63. package/dist/graph/state.cjs.map +1 -1
  64. package/dist/graph/state.d.cts +193 -17
  65. package/dist/graph/state.d.cts.map +1 -1
  66. package/dist/graph/state.d.ts +193 -17
  67. package/dist/graph/state.d.ts.map +1 -1
  68. package/dist/graph/state.js +210 -14
  69. package/dist/graph/state.js.map +1 -1
  70. package/dist/graph/zod/schema.cjs +5 -0
  71. package/dist/graph/zod/schema.cjs.map +1 -1
  72. package/dist/graph/zod/schema.d.cts.map +1 -1
  73. package/dist/graph/zod/schema.d.ts.map +1 -1
  74. package/dist/graph/zod/schema.js +5 -0
  75. package/dist/graph/zod/schema.js.map +1 -1
  76. package/dist/index.cjs +11 -0
  77. package/dist/index.cjs.map +1 -1
  78. package/dist/index.d.cts +11 -8
  79. package/dist/index.d.ts +11 -8
  80. package/dist/index.js +5 -3
  81. package/dist/index.js.map +1 -1
  82. package/dist/prebuilt/react_agent_executor.d.cts +1 -1
  83. package/dist/prebuilt/tool_node.cjs +69 -6
  84. package/dist/prebuilt/tool_node.cjs.map +1 -1
  85. package/dist/prebuilt/tool_node.d.cts +55 -3
  86. package/dist/prebuilt/tool_node.d.cts.map +1 -1
  87. package/dist/prebuilt/tool_node.d.ts +55 -3
  88. package/dist/prebuilt/tool_node.d.ts.map +1 -1
  89. package/dist/prebuilt/tool_node.js +69 -6
  90. package/dist/prebuilt/tool_node.js.map +1 -1
  91. package/dist/pregel/algo.cjs +182 -21
  92. package/dist/pregel/algo.cjs.map +1 -1
  93. package/dist/pregel/algo.d.cts +1 -1
  94. package/dist/pregel/algo.d.cts.map +1 -1
  95. package/dist/pregel/algo.d.ts +1 -1
  96. package/dist/pregel/algo.d.ts.map +1 -1
  97. package/dist/pregel/algo.js +185 -25
  98. package/dist/pregel/algo.js.map +1 -1
  99. package/dist/pregel/call.cjs +2 -1
  100. package/dist/pregel/call.cjs.map +1 -1
  101. package/dist/pregel/call.js +2 -1
  102. package/dist/pregel/call.js.map +1 -1
  103. package/dist/pregel/index.cjs +15 -3
  104. package/dist/pregel/index.cjs.map +1 -1
  105. package/dist/pregel/index.d.cts.map +1 -1
  106. package/dist/pregel/index.d.ts.map +1 -1
  107. package/dist/pregel/index.js +17 -5
  108. package/dist/pregel/index.js.map +1 -1
  109. package/dist/pregel/loop.cjs +362 -41
  110. package/dist/pregel/loop.cjs.map +1 -1
  111. package/dist/pregel/loop.js +365 -44
  112. package/dist/pregel/loop.js.map +1 -1
  113. package/dist/pregel/messages-v2.cjs +1 -1
  114. package/dist/pregel/messages-v2.js +1 -1
  115. package/dist/pregel/messages.cjs +1 -1
  116. package/dist/pregel/messages.js +1 -1
  117. package/dist/pregel/read.cjs +15 -5
  118. package/dist/pregel/read.cjs.map +1 -1
  119. package/dist/pregel/read.d.cts +9 -0
  120. package/dist/pregel/read.d.cts.map +1 -1
  121. package/dist/pregel/read.d.ts +9 -0
  122. package/dist/pregel/read.d.ts.map +1 -1
  123. package/dist/pregel/read.js +15 -5
  124. package/dist/pregel/read.js.map +1 -1
  125. package/dist/pregel/remote-run-stream.cjs +107 -0
  126. package/dist/pregel/remote-run-stream.cjs.map +1 -0
  127. package/dist/pregel/remote-run-stream.d.cts +33 -0
  128. package/dist/pregel/remote-run-stream.d.cts.map +1 -0
  129. package/dist/pregel/remote-run-stream.d.ts +33 -0
  130. package/dist/pregel/remote-run-stream.d.ts.map +1 -0
  131. package/dist/pregel/remote-run-stream.js +107 -0
  132. package/dist/pregel/remote-run-stream.js.map +1 -0
  133. package/dist/pregel/remote.cjs +61 -1
  134. package/dist/pregel/remote.cjs.map +1 -1
  135. package/dist/pregel/remote.d.cts +17 -0
  136. package/dist/pregel/remote.d.cts.map +1 -1
  137. package/dist/pregel/remote.d.ts +17 -0
  138. package/dist/pregel/remote.d.ts.map +1 -1
  139. package/dist/pregel/remote.js +61 -1
  140. package/dist/pregel/remote.js.map +1 -1
  141. package/dist/pregel/replay.cjs +62 -0
  142. package/dist/pregel/replay.cjs.map +1 -0
  143. package/dist/pregel/replay.js +62 -0
  144. package/dist/pregel/replay.js.map +1 -0
  145. package/dist/pregel/retry.cjs +8 -6
  146. package/dist/pregel/retry.cjs.map +1 -1
  147. package/dist/pregel/retry.js +8 -6
  148. package/dist/pregel/retry.js.map +1 -1
  149. package/dist/pregel/runnable_types.d.cts +20 -0
  150. package/dist/pregel/runnable_types.d.cts.map +1 -1
  151. package/dist/pregel/runnable_types.d.ts +20 -0
  152. package/dist/pregel/runnable_types.d.ts.map +1 -1
  153. package/dist/pregel/runner.cjs +48 -7
  154. package/dist/pregel/runner.cjs.map +1 -1
  155. package/dist/pregel/runner.js +50 -9
  156. package/dist/pregel/runner.js.map +1 -1
  157. package/dist/pregel/runtime.cjs +64 -0
  158. package/dist/pregel/runtime.cjs.map +1 -0
  159. package/dist/pregel/runtime.d.cts +57 -0
  160. package/dist/pregel/runtime.d.cts.map +1 -0
  161. package/dist/pregel/runtime.d.ts +57 -0
  162. package/dist/pregel/runtime.d.ts.map +1 -0
  163. package/dist/pregel/runtime.js +64 -0
  164. package/dist/pregel/runtime.js.map +1 -0
  165. package/dist/pregel/stream.cjs +2 -0
  166. package/dist/pregel/stream.cjs.map +1 -1
  167. package/dist/pregel/stream.js +2 -0
  168. package/dist/pregel/stream.js.map +1 -1
  169. package/dist/pregel/timeout.cjs +216 -0
  170. package/dist/pregel/timeout.cjs.map +1 -0
  171. package/dist/pregel/timeout.js +216 -0
  172. package/dist/pregel/timeout.js.map +1 -0
  173. package/dist/pregel/types.cjs +3 -1
  174. package/dist/pregel/types.cjs.map +1 -1
  175. package/dist/pregel/types.d.cts +13 -0
  176. package/dist/pregel/types.d.cts.map +1 -1
  177. package/dist/pregel/types.d.ts +14 -1
  178. package/dist/pregel/types.d.ts.map +1 -1
  179. package/dist/pregel/types.js +3 -1
  180. package/dist/pregel/types.js.map +1 -1
  181. package/dist/pregel/utils/config.cjs +18 -2
  182. package/dist/pregel/utils/config.cjs.map +1 -1
  183. package/dist/pregel/utils/config.d.cts +15 -1
  184. package/dist/pregel/utils/config.d.cts.map +1 -1
  185. package/dist/pregel/utils/config.d.ts +15 -1
  186. package/dist/pregel/utils/config.d.ts.map +1 -1
  187. package/dist/pregel/utils/config.js +18 -2
  188. package/dist/pregel/utils/config.js.map +1 -1
  189. package/dist/pregel/utils/index.cjs +1 -0
  190. package/dist/pregel/utils/index.cjs.map +1 -1
  191. package/dist/pregel/utils/index.d.cts +6 -1
  192. package/dist/pregel/utils/index.d.cts.map +1 -1
  193. package/dist/pregel/utils/index.d.ts +6 -1
  194. package/dist/pregel/utils/index.d.ts.map +1 -1
  195. package/dist/pregel/utils/index.js +1 -0
  196. package/dist/pregel/utils/index.js.map +1 -1
  197. package/dist/pregel/utils/timeout.cjs +34 -0
  198. package/dist/pregel/utils/timeout.cjs.map +1 -0
  199. package/dist/pregel/utils/timeout.d.cts +45 -0
  200. package/dist/pregel/utils/timeout.d.cts.map +1 -0
  201. package/dist/pregel/utils/timeout.d.ts +45 -0
  202. package/dist/pregel/utils/timeout.d.ts.map +1 -0
  203. package/dist/pregel/utils/timeout.js +34 -0
  204. package/dist/pregel/utils/timeout.js.map +1 -0
  205. package/dist/state/schema.cjs +12 -2
  206. package/dist/state/schema.cjs.map +1 -1
  207. package/dist/state/schema.d.cts.map +1 -1
  208. package/dist/state/schema.d.ts.map +1 -1
  209. package/dist/state/schema.js +12 -2
  210. package/dist/state/schema.js.map +1 -1
  211. package/dist/web.cjs +11 -0
  212. package/dist/web.d.cts +11 -8
  213. package/dist/web.d.ts +11 -8
  214. package/dist/web.js +5 -3
  215. package/package.json +5 -5
package/dist/index.d.cts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { BaseChannel } from "./channels/base.cjs";
2
- import { COMMAND_SYMBOL, Command, CommandInstance, CommandParams, END, INTERRUPT, Interrupt, Overwrite, OverwriteValue, START, Send, isCommand, isInterrupted } from "./constants.cjs";
2
+ import { TimeoutPolicy } from "./pregel/utils/timeout.cjs";
3
+ import { COMMAND_SYMBOL, Command, CommandInstance, CommandParams, END, INTERRUPT, Interrupt, Overwrite, OverwriteValue, START, Send, SendOptions, isCommand, isInterrupted } from "./constants.cjs";
4
+ import { DeltaChannel, DeltaReducer } from "./channels/delta.cjs";
3
5
  import { BinaryOperator, BinaryOperatorAggregate } from "./channels/binop.cjs";
4
6
  import { AnyValue } from "./channels/any_value.cjs";
5
7
  import { LastValue } from "./channels/last_value.cjs";
@@ -8,6 +10,7 @@ import { EphemeralValue } from "./channels/ephemeral_value.cjs";
8
10
  import { NamedBarrierValue } from "./channels/named_barrier_value.cjs";
9
11
  import { Topic } from "./channels/topic.cjs";
10
12
  import { UntrackedValueChannel } from "./channels/untracked_value.cjs";
13
+ import { RunControl } from "./pregel/runtime.cjs";
11
14
  import { ExecutionInfo, LangGraphRunnableConfig, Runtime, ServerInfo } from "./pregel/runnable_types.cjs";
12
15
  import { Annotation, AnnotationRoot, NodeType, SingleReducer, StateDefinition, StateType, UpdateType } from "./graph/annotation.cjs";
13
16
  import { CachePolicy, RetryPolicy } from "./pregel/utils/index.cjs";
@@ -24,22 +27,22 @@ import { createValuesTransformer } from "./stream/transformers/values.cjs";
24
27
  import { CreateGraphRunStreamOptions, GraphRunStream, SubgraphRunStream, createGraphRunStream } from "./stream/run-stream.cjs";
25
28
  import { ChatModelStreamImpl } from "./stream/index.cjs";
26
29
  import { Pregel } from "./pregel/index.cjs";
27
- import { AddNodeOptions, CompiledGraph, CompiledGraphType, Graph, NodeSpec } from "./graph/graph.cjs";
28
- import { InferInterruptInputType, InferInterruptResumeType, interrupt } from "./interrupt.cjs";
29
- import { InferWriterType, writer } from "./writer.cjs";
30
+ import { BaseLangGraphError, BaseLangGraphErrorFields, EmptyChannelError, EmptyInputError, GraphBubbleUp, GraphDrained, GraphInterrupt, GraphRecursionError, GraphValueError, InvalidUpdateError, MultipleSubgraphsError, NodeError, NodeInterrupt, NodeTimeoutError, ParentCommand, RemoteException, StateGraphInputError, UnreachableNodeError, getSubgraphsSeenSet, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isNodeError, isNodeTimeoutError, isParentCommand } from "./errors.cjs";
30
31
  import { isSerializableSchema, isStandardSchema } from "./state/types.cjs";
31
32
  import { ReducedValue, ReducedValueInit } from "./state/values/reduced.cjs";
32
33
  import { UntrackedValue, UntrackedValueInit } from "./state/values/untracked.cjs";
33
34
  import { AnyStateSchema, InferStateSchemaUpdate, InferStateSchemaValue, StateSchema, StateSchemaField, StateSchemaFieldToChannel, StateSchemaFields, StateSchemaFieldsToStateDefinition } from "./state/schema.cjs";
34
35
  import { ConditionalEdgeRouter, ConditionalEdgeRouterTypes, ContextSchemaInit, ExtractStateType, ExtractUpdateType, GraphNode, GraphNodeReturnValue, GraphNodeTypes, StateDefinitionInit, StateGraphInit, StateGraphOptions, ToStateDefinition } from "./graph/types.cjs";
35
- import { CompiledStateGraph, StateGraph, StateGraphAddNodeOptions, StateGraphArgs, StateGraphArgsWithInputOutputSchemas, StateGraphArgsWithStateSchema, StateGraphNodeSpec } from "./graph/state.cjs";
36
- import { Messages, REMOVE_ALL_MESSAGES, messagesStateReducer } from "./graph/messages_reducer.cjs";
36
+ import { AddNodeOptions, CompiledGraph, CompiledGraphType, Graph, NodeSpec } from "./graph/graph.cjs";
37
+ import { InferInterruptInputType, InferInterruptResumeType, interrupt } from "./interrupt.cjs";
38
+ import { InferWriterType, writer } from "./writer.cjs";
39
+ import { CompiledStateGraph, NodePolicyOptions, StateGraph, StateGraphAddNodeOptions, StateGraphArgs, StateGraphArgsWithInputOutputSchemas, StateGraphArgsWithStateSchema, StateGraphNodeSpec } from "./graph/state.cjs";
40
+ import { Messages, REMOVE_ALL_MESSAGES, messagesDeltaReducer, messagesStateReducer } from "./graph/messages_reducer.cjs";
37
41
  import { MessageGraph, pushMessage } from "./graph/message.cjs";
38
- import { BaseLangGraphError, BaseLangGraphErrorFields, EmptyChannelError, EmptyInputError, GraphBubbleUp, GraphInterrupt, GraphRecursionError, GraphValueError, InvalidUpdateError, MultipleSubgraphsError, NodeInterrupt, ParentCommand, RemoteException, StateGraphInputError, UnreachableNodeError, getSubgraphsSeenSet, isGraphBubbleUp, isGraphInterrupt, isParentCommand } from "./errors.cjs";
39
42
  import { EntrypointOptions, TaskOptions, entrypoint, getPreviousState, task } from "./func/index.cjs";
40
43
  import { MessagesAnnotation, MessagesZodMeta, MessagesZodState } from "./graph/messages_annotation.cjs";
41
44
  import { getJsonSchemaFromSchema, getSchemaDefaultGetter } from "./state/adapter.cjs";
42
45
  import { MessagesValue } from "./state/prebuilt/messages.cjs";
43
46
  import { getConfig, getCurrentTaskInput, getStore, getWriter } from "./pregel/utils/config.cjs";
44
47
  import { AsyncBatchedStore, BaseCheckpointSaver, BaseStore, Checkpoint, CheckpointMetadata, CheckpointTuple, GetOperation, InMemoryStore, Item, ListNamespacesOperation, MatchCondition, MemorySaver, NameSpacePath, NamespaceMatchType, Operation, OperationResults, PutOperation, SearchOperation, copyCheckpoint, emptyCheckpoint } from "./web.cjs";
45
- export { AddNodeOptions, AgentStatus, Annotation, AnnotationRoot, AnyStateSchema, AnyValue, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseLangGraphErrorFields, BaseStore, BinaryOperator, BinaryOperatorAggregate, COMMAND_SYMBOL, CachePolicy, ChatModelStream, ChatModelStreamImpl, Checkpoint, CheckpointMetadata, CheckpointTuple, Command, CommandInstance, CommandParams, CompiledGraph, CompiledGraphType, CompiledStateGraph, ConditionalEdgeRouter, ConditionalEdgeRouterTypes, ContextSchemaInit, ConvertToProtocolEventOptions, CreateGraphRunStreamOptions, DynamicBarrierValue, END, EmptyChannelError, EmptyInputError, EntrypointOptions, EphemeralValue, StreamChannel as EventLog, ExecutionInfo, ExtractStateType, ExtractUpdateType, GetOperation, GetStateOptions, Graph, GraphBubbleUp, GraphInterrupt, GraphNode, GraphNodeReturnValue, GraphNodeTypes, GraphRecursionError, GraphRunStream, GraphValueError, INTERRUPT, InMemoryStore, InferExtensions, InferInterruptInputType, InferInterruptResumeType, InferStateSchemaUpdate, InferStateSchemaValue, InferWriterType, Interrupt, InterruptPayload, InvalidUpdateError, Item, LangGraphRunnableConfig, LastValue, LifecycleCause, LifecycleData, LifecycleEntry, LifecycleProjection, LifecycleTransformerOptions, ListNamespacesOperation, MatchCondition, MemorySaver, MessageGraph, Messages, MessagesAnnotation, MessagesEventData, MessagesValue, MessagesZodMeta, MessagesZodState, MultipleChannelSubscriptionOptions, MultipleSubgraphsError, NameSpacePath, NamedBarrierValue, Namespace, NamespaceMatchType, NativeStreamTransformer, NodeInterrupt, NodeSpec, NodeType, Operation, OperationResults, Overwrite, OverwriteValue, ParentCommand, Pregel, PregelNode, PregelOptions, PregelParams, ProtocolEvent, PutOperation, REMOVE_ALL_MESSAGES, ReducedValue, ReducedValueInit, RemoteException, RetryPolicy, Runtime, START, STREAM_EVENTS_V3_MODES, SearchOperation, Send, ServerInfo, SingleChannelSubscriptionOptions, SingleReducer, StateDefinition, StateDefinitionInit, StateGraph, StateGraphAddNodeOptions, StateGraphArgs, StateGraphArgsWithInputOutputSchemas, StateGraphArgsWithStateSchema, StateGraphInit, StateGraphInputError, StateGraphNodeSpec, StateGraphOptions, StateSchema, StateSchemaField, StateSchemaFieldToChannel, StateSchemaFields, StateSchemaFieldsToStateDefinition, StateSnapshot, StateType, StreamChannel, StreamEmitter, StreamMode, StreamOutputMap, StreamTransformer, SubgraphDiscoveryProjection, SubgraphDiscoveryTransformerOptions, SubgraphRunStream, TaskOptions, ToStateDefinition, ToolCallStatus, ToolCallStream, ToolsEventData, Topic, UnreachableNodeError, UntrackedValue, UntrackedValueChannel, UntrackedValueInit, UpdateType, UpdatesEventData, UsageInfo, WaitForNames, messagesStateReducer as addMessages, convertToProtocolEvent, copyCheckpoint, createGraphRunStream, createLifecycleTransformer, createMessagesTransformer, createSubgraphDiscoveryTransformer, createValuesTransformer, emptyCheckpoint, entrypoint, filterLifecycleEntries, filterSubgraphHandles, getConfig, getCurrentTaskInput, getJsonSchemaFromSchema, getPreviousState, getSchemaDefaultGetter, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCheckpointEnvelope, isCommand, isGraphBubbleUp, isGraphInterrupt, isInterrupted, isNativeTransformer, isParentCommand, isSerializableSchema, isStandardSchema, messagesStateReducer, pushMessage, task, writer };
48
+ export { AddNodeOptions, AgentStatus, Annotation, AnnotationRoot, AnyStateSchema, AnyValue, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseLangGraphErrorFields, BaseStore, BinaryOperator, BinaryOperatorAggregate, COMMAND_SYMBOL, CachePolicy, ChatModelStream, ChatModelStreamImpl, Checkpoint, CheckpointMetadata, CheckpointTuple, Command, CommandInstance, CommandParams, CompiledGraph, CompiledGraphType, CompiledStateGraph, ConditionalEdgeRouter, ConditionalEdgeRouterTypes, ContextSchemaInit, ConvertToProtocolEventOptions, CreateGraphRunStreamOptions, DeltaChannel, DeltaReducer, DynamicBarrierValue, END, EmptyChannelError, EmptyInputError, EntrypointOptions, EphemeralValue, StreamChannel as EventLog, ExecutionInfo, ExtractStateType, ExtractUpdateType, GetOperation, GetStateOptions, Graph, GraphBubbleUp, GraphDrained, GraphInterrupt, GraphNode, GraphNodeReturnValue, GraphNodeTypes, GraphRecursionError, GraphRunStream, GraphValueError, INTERRUPT, InMemoryStore, InferExtensions, InferInterruptInputType, InferInterruptResumeType, InferStateSchemaUpdate, InferStateSchemaValue, InferWriterType, Interrupt, InterruptPayload, InvalidUpdateError, Item, LangGraphRunnableConfig, LastValue, LifecycleCause, LifecycleData, LifecycleEntry, LifecycleProjection, LifecycleTransformerOptions, ListNamespacesOperation, MatchCondition, MemorySaver, MessageGraph, Messages, MessagesAnnotation, MessagesEventData, MessagesValue, MessagesZodMeta, MessagesZodState, MultipleChannelSubscriptionOptions, MultipleSubgraphsError, NameSpacePath, NamedBarrierValue, Namespace, NamespaceMatchType, NativeStreamTransformer, NodeError, NodeInterrupt, NodePolicyOptions, NodeSpec, NodeTimeoutError, NodeType, Operation, OperationResults, Overwrite, OverwriteValue, ParentCommand, Pregel, PregelNode, PregelOptions, PregelParams, ProtocolEvent, PutOperation, REMOVE_ALL_MESSAGES, ReducedValue, ReducedValueInit, RemoteException, RetryPolicy, RunControl, Runtime, START, STREAM_EVENTS_V3_MODES, SearchOperation, Send, SendOptions, ServerInfo, SingleChannelSubscriptionOptions, SingleReducer, StateDefinition, StateDefinitionInit, StateGraph, StateGraphAddNodeOptions, StateGraphArgs, StateGraphArgsWithInputOutputSchemas, StateGraphArgsWithStateSchema, StateGraphInit, StateGraphInputError, StateGraphNodeSpec, StateGraphOptions, StateSchema, StateSchemaField, StateSchemaFieldToChannel, StateSchemaFields, StateSchemaFieldsToStateDefinition, StateSnapshot, StateType, StreamChannel, StreamEmitter, StreamMode, StreamOutputMap, StreamTransformer, SubgraphDiscoveryProjection, SubgraphDiscoveryTransformerOptions, SubgraphRunStream, TaskOptions, TimeoutPolicy, ToStateDefinition, ToolCallStatus, ToolCallStream, ToolsEventData, Topic, UnreachableNodeError, UntrackedValue, UntrackedValueChannel, UntrackedValueInit, UpdateType, UpdatesEventData, UsageInfo, WaitForNames, messagesStateReducer as addMessages, convertToProtocolEvent, copyCheckpoint, createGraphRunStream, createLifecycleTransformer, createMessagesTransformer, createSubgraphDiscoveryTransformer, createValuesTransformer, emptyCheckpoint, entrypoint, filterLifecycleEntries, filterSubgraphHandles, getConfig, getCurrentTaskInput, getJsonSchemaFromSchema, getPreviousState, getSchemaDefaultGetter, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCheckpointEnvelope, isCommand, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isInterrupted, isNativeTransformer, isNodeError, isNodeTimeoutError, isParentCommand, isSerializableSchema, isStandardSchema, messagesDeltaReducer, messagesStateReducer, pushMessage, task, writer };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { BaseChannel } from "./channels/base.js";
2
- import { COMMAND_SYMBOL, Command, CommandInstance, CommandParams, END, INTERRUPT, Interrupt, Overwrite, OverwriteValue, START, Send, isCommand, isInterrupted } from "./constants.js";
2
+ import { TimeoutPolicy } from "./pregel/utils/timeout.js";
3
+ import { COMMAND_SYMBOL, Command, CommandInstance, CommandParams, END, INTERRUPT, Interrupt, Overwrite, OverwriteValue, START, Send, SendOptions, isCommand, isInterrupted } from "./constants.js";
4
+ import { DeltaChannel, DeltaReducer } from "./channels/delta.js";
3
5
  import { BinaryOperator, BinaryOperatorAggregate } from "./channels/binop.js";
4
6
  import { AnyValue } from "./channels/any_value.js";
5
7
  import { LastValue } from "./channels/last_value.js";
@@ -8,6 +10,7 @@ import { EphemeralValue } from "./channels/ephemeral_value.js";
8
10
  import { NamedBarrierValue } from "./channels/named_barrier_value.js";
9
11
  import { Topic } from "./channels/topic.js";
10
12
  import { UntrackedValueChannel } from "./channels/untracked_value.js";
13
+ import { RunControl } from "./pregel/runtime.js";
11
14
  import { ExecutionInfo, LangGraphRunnableConfig, Runtime, ServerInfo } from "./pregel/runnable_types.js";
12
15
  import { Annotation, AnnotationRoot, NodeType, SingleReducer, StateDefinition, StateType, UpdateType } from "./graph/annotation.js";
13
16
  import { CachePolicy, RetryPolicy } from "./pregel/utils/index.js";
@@ -24,22 +27,22 @@ import { createValuesTransformer } from "./stream/transformers/values.js";
24
27
  import { CreateGraphRunStreamOptions, GraphRunStream, SubgraphRunStream, createGraphRunStream } from "./stream/run-stream.js";
25
28
  import { ChatModelStreamImpl } from "./stream/index.js";
26
29
  import { Pregel } from "./pregel/index.js";
27
- import { AddNodeOptions, CompiledGraph, CompiledGraphType, Graph, NodeSpec } from "./graph/graph.js";
28
- import { InferInterruptInputType, InferInterruptResumeType, interrupt } from "./interrupt.js";
29
- import { InferWriterType, writer } from "./writer.js";
30
+ import { BaseLangGraphError, BaseLangGraphErrorFields, EmptyChannelError, EmptyInputError, GraphBubbleUp, GraphDrained, GraphInterrupt, GraphRecursionError, GraphValueError, InvalidUpdateError, MultipleSubgraphsError, NodeError, NodeInterrupt, NodeTimeoutError, ParentCommand, RemoteException, StateGraphInputError, UnreachableNodeError, getSubgraphsSeenSet, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isNodeError, isNodeTimeoutError, isParentCommand } from "./errors.js";
30
31
  import { isSerializableSchema, isStandardSchema } from "./state/types.js";
31
32
  import { ReducedValue, ReducedValueInit } from "./state/values/reduced.js";
32
33
  import { UntrackedValue, UntrackedValueInit } from "./state/values/untracked.js";
33
34
  import { AnyStateSchema, InferStateSchemaUpdate, InferStateSchemaValue, StateSchema, StateSchemaField, StateSchemaFieldToChannel, StateSchemaFields, StateSchemaFieldsToStateDefinition } from "./state/schema.js";
34
35
  import { ConditionalEdgeRouter, ConditionalEdgeRouterTypes, ContextSchemaInit, ExtractStateType, ExtractUpdateType, GraphNode, GraphNodeReturnValue, GraphNodeTypes, StateDefinitionInit, StateGraphInit, StateGraphOptions, ToStateDefinition } from "./graph/types.js";
35
- import { CompiledStateGraph, StateGraph, StateGraphAddNodeOptions, StateGraphArgs, StateGraphArgsWithInputOutputSchemas, StateGraphArgsWithStateSchema, StateGraphNodeSpec } from "./graph/state.js";
36
- import { Messages, REMOVE_ALL_MESSAGES, messagesStateReducer } from "./graph/messages_reducer.js";
36
+ import { AddNodeOptions, CompiledGraph, CompiledGraphType, Graph, NodeSpec } from "./graph/graph.js";
37
+ import { InferInterruptInputType, InferInterruptResumeType, interrupt } from "./interrupt.js";
38
+ import { InferWriterType, writer } from "./writer.js";
39
+ import { CompiledStateGraph, NodePolicyOptions, StateGraph, StateGraphAddNodeOptions, StateGraphArgs, StateGraphArgsWithInputOutputSchemas, StateGraphArgsWithStateSchema, StateGraphNodeSpec } from "./graph/state.js";
40
+ import { Messages, REMOVE_ALL_MESSAGES, messagesDeltaReducer, messagesStateReducer } from "./graph/messages_reducer.js";
37
41
  import { MessageGraph, pushMessage } from "./graph/message.js";
38
- import { BaseLangGraphError, BaseLangGraphErrorFields, EmptyChannelError, EmptyInputError, GraphBubbleUp, GraphInterrupt, GraphRecursionError, GraphValueError, InvalidUpdateError, MultipleSubgraphsError, NodeInterrupt, ParentCommand, RemoteException, StateGraphInputError, UnreachableNodeError, getSubgraphsSeenSet, isGraphBubbleUp, isGraphInterrupt, isParentCommand } from "./errors.js";
39
42
  import { EntrypointOptions, TaskOptions, entrypoint, getPreviousState, task } from "./func/index.js";
40
43
  import { MessagesAnnotation, MessagesZodMeta, MessagesZodState } from "./graph/messages_annotation.js";
41
44
  import { getJsonSchemaFromSchema, getSchemaDefaultGetter } from "./state/adapter.js";
42
45
  import { MessagesValue } from "./state/prebuilt/messages.js";
43
46
  import { getConfig, getCurrentTaskInput, getStore, getWriter } from "./pregel/utils/config.js";
44
47
  import { AsyncBatchedStore, BaseCheckpointSaver, BaseStore, Checkpoint, CheckpointMetadata, CheckpointTuple, GetOperation, InMemoryStore, Item, ListNamespacesOperation, MatchCondition, MemorySaver, NameSpacePath, NamespaceMatchType, Operation, OperationResults, PutOperation, SearchOperation, copyCheckpoint, emptyCheckpoint } from "./web.js";
45
- export { AddNodeOptions, AgentStatus, Annotation, AnnotationRoot, AnyStateSchema, AnyValue, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseLangGraphErrorFields, BaseStore, BinaryOperator, BinaryOperatorAggregate, COMMAND_SYMBOL, CachePolicy, ChatModelStream, ChatModelStreamImpl, Checkpoint, CheckpointMetadata, CheckpointTuple, Command, CommandInstance, CommandParams, CompiledGraph, CompiledGraphType, CompiledStateGraph, ConditionalEdgeRouter, ConditionalEdgeRouterTypes, ContextSchemaInit, ConvertToProtocolEventOptions, CreateGraphRunStreamOptions, DynamicBarrierValue, END, EmptyChannelError, EmptyInputError, EntrypointOptions, EphemeralValue, StreamChannel as EventLog, ExecutionInfo, ExtractStateType, ExtractUpdateType, GetOperation, GetStateOptions, Graph, GraphBubbleUp, GraphInterrupt, GraphNode, GraphNodeReturnValue, GraphNodeTypes, GraphRecursionError, GraphRunStream, GraphValueError, INTERRUPT, InMemoryStore, InferExtensions, InferInterruptInputType, InferInterruptResumeType, InferStateSchemaUpdate, InferStateSchemaValue, InferWriterType, Interrupt, InterruptPayload, InvalidUpdateError, Item, LangGraphRunnableConfig, LastValue, LifecycleCause, LifecycleData, LifecycleEntry, LifecycleProjection, LifecycleTransformerOptions, ListNamespacesOperation, MatchCondition, MemorySaver, MessageGraph, Messages, MessagesAnnotation, MessagesEventData, MessagesValue, MessagesZodMeta, MessagesZodState, MultipleChannelSubscriptionOptions, MultipleSubgraphsError, NameSpacePath, NamedBarrierValue, Namespace, NamespaceMatchType, NativeStreamTransformer, NodeInterrupt, NodeSpec, NodeType, Operation, OperationResults, Overwrite, OverwriteValue, ParentCommand, Pregel, PregelNode, PregelOptions, PregelParams, ProtocolEvent, PutOperation, REMOVE_ALL_MESSAGES, ReducedValue, ReducedValueInit, RemoteException, RetryPolicy, Runtime, START, STREAM_EVENTS_V3_MODES, SearchOperation, Send, ServerInfo, SingleChannelSubscriptionOptions, SingleReducer, StateDefinition, StateDefinitionInit, StateGraph, StateGraphAddNodeOptions, StateGraphArgs, StateGraphArgsWithInputOutputSchemas, StateGraphArgsWithStateSchema, StateGraphInit, StateGraphInputError, StateGraphNodeSpec, StateGraphOptions, StateSchema, StateSchemaField, StateSchemaFieldToChannel, StateSchemaFields, StateSchemaFieldsToStateDefinition, StateSnapshot, StateType, StreamChannel, StreamEmitter, StreamMode, StreamOutputMap, StreamTransformer, SubgraphDiscoveryProjection, SubgraphDiscoveryTransformerOptions, SubgraphRunStream, TaskOptions, ToStateDefinition, ToolCallStatus, ToolCallStream, ToolsEventData, Topic, UnreachableNodeError, UntrackedValue, UntrackedValueChannel, UntrackedValueInit, UpdateType, UpdatesEventData, UsageInfo, WaitForNames, messagesStateReducer as addMessages, convertToProtocolEvent, copyCheckpoint, createGraphRunStream, createLifecycleTransformer, createMessagesTransformer, createSubgraphDiscoveryTransformer, createValuesTransformer, emptyCheckpoint, entrypoint, filterLifecycleEntries, filterSubgraphHandles, getConfig, getCurrentTaskInput, getJsonSchemaFromSchema, getPreviousState, getSchemaDefaultGetter, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCheckpointEnvelope, isCommand, isGraphBubbleUp, isGraphInterrupt, isInterrupted, isNativeTransformer, isParentCommand, isSerializableSchema, isStandardSchema, messagesStateReducer, pushMessage, task, writer };
48
+ export { AddNodeOptions, AgentStatus, Annotation, AnnotationRoot, AnyStateSchema, AnyValue, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseLangGraphErrorFields, BaseStore, BinaryOperator, BinaryOperatorAggregate, COMMAND_SYMBOL, CachePolicy, ChatModelStream, ChatModelStreamImpl, Checkpoint, CheckpointMetadata, CheckpointTuple, Command, CommandInstance, CommandParams, CompiledGraph, CompiledGraphType, CompiledStateGraph, ConditionalEdgeRouter, ConditionalEdgeRouterTypes, ContextSchemaInit, ConvertToProtocolEventOptions, CreateGraphRunStreamOptions, DeltaChannel, DeltaReducer, DynamicBarrierValue, END, EmptyChannelError, EmptyInputError, EntrypointOptions, EphemeralValue, StreamChannel as EventLog, ExecutionInfo, ExtractStateType, ExtractUpdateType, GetOperation, GetStateOptions, Graph, GraphBubbleUp, GraphDrained, GraphInterrupt, GraphNode, GraphNodeReturnValue, GraphNodeTypes, GraphRecursionError, GraphRunStream, GraphValueError, INTERRUPT, InMemoryStore, InferExtensions, InferInterruptInputType, InferInterruptResumeType, InferStateSchemaUpdate, InferStateSchemaValue, InferWriterType, Interrupt, InterruptPayload, InvalidUpdateError, Item, LangGraphRunnableConfig, LastValue, LifecycleCause, LifecycleData, LifecycleEntry, LifecycleProjection, LifecycleTransformerOptions, ListNamespacesOperation, MatchCondition, MemorySaver, MessageGraph, Messages, MessagesAnnotation, MessagesEventData, MessagesValue, MessagesZodMeta, MessagesZodState, MultipleChannelSubscriptionOptions, MultipleSubgraphsError, NameSpacePath, NamedBarrierValue, Namespace, NamespaceMatchType, NativeStreamTransformer, NodeError, NodeInterrupt, NodePolicyOptions, NodeSpec, NodeTimeoutError, NodeType, Operation, OperationResults, Overwrite, OverwriteValue, ParentCommand, Pregel, PregelNode, PregelOptions, PregelParams, ProtocolEvent, PutOperation, REMOVE_ALL_MESSAGES, ReducedValue, ReducedValueInit, RemoteException, RetryPolicy, RunControl, Runtime, START, STREAM_EVENTS_V3_MODES, SearchOperation, Send, SendOptions, ServerInfo, SingleChannelSubscriptionOptions, SingleReducer, StateDefinition, StateDefinitionInit, StateGraph, StateGraphAddNodeOptions, StateGraphArgs, StateGraphArgsWithInputOutputSchemas, StateGraphArgsWithStateSchema, StateGraphInit, StateGraphInputError, StateGraphNodeSpec, StateGraphOptions, StateSchema, StateSchemaField, StateSchemaFieldToChannel, StateSchemaFields, StateSchemaFieldsToStateDefinition, StateSnapshot, StateType, StreamChannel, StreamEmitter, StreamMode, StreamOutputMap, StreamTransformer, SubgraphDiscoveryProjection, SubgraphDiscoveryTransformerOptions, SubgraphRunStream, TaskOptions, TimeoutPolicy, ToStateDefinition, ToolCallStatus, ToolCallStream, ToolsEventData, Topic, UnreachableNodeError, UntrackedValue, UntrackedValueChannel, UntrackedValueInit, UpdateType, UpdatesEventData, UsageInfo, WaitForNames, messagesStateReducer as addMessages, convertToProtocolEvent, copyCheckpoint, createGraphRunStream, createLifecycleTransformer, createMessagesTransformer, createSubgraphDiscoveryTransformer, createValuesTransformer, emptyCheckpoint, entrypoint, filterLifecycleEntries, filterSubgraphHandles, getConfig, getCurrentTaskInput, getJsonSchemaFromSchema, getPreviousState, getSchemaDefaultGetter, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCheckpointEnvelope, isCommand, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isInterrupted, isNativeTransformer, isNodeError, isNodeTimeoutError, isParentCommand, isSerializableSchema, isStandardSchema, messagesDeltaReducer, messagesStateReducer, pushMessage, task, writer };
package/dist/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import { initializeAsyncLocalStorageSingleton } from "./node.js";
2
2
  import { COMMAND_SYMBOL, Command, CommandInstance, END, INTERRUPT, Overwrite, START, Send, isCommand, isInterrupted } from "./constants.js";
3
- import { BaseLangGraphError, EmptyChannelError, EmptyInputError, GraphBubbleUp, GraphInterrupt, GraphRecursionError, GraphValueError, InvalidUpdateError, MultipleSubgraphsError, NodeInterrupt, ParentCommand, RemoteException, StateGraphInputError, UnreachableNodeError, getSubgraphsSeenSet, isGraphBubbleUp, isGraphInterrupt, isParentCommand } from "./errors.js";
3
+ import { BaseLangGraphError, EmptyChannelError, EmptyInputError, GraphBubbleUp, GraphDrained, GraphInterrupt, GraphRecursionError, GraphValueError, InvalidUpdateError, MultipleSubgraphsError, NodeError, NodeInterrupt, NodeTimeoutError, ParentCommand, RemoteException, StateGraphInputError, UnreachableNodeError, getSubgraphsSeenSet, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isNodeError, isNodeTimeoutError, isParentCommand } from "./errors.js";
4
4
  import { BaseChannel } from "./channels/base.js";
5
5
  import { BinaryOperatorAggregate } from "./channels/binop.js";
6
6
  import { Annotation } from "./graph/annotation.js";
7
7
  import { getConfig, getCurrentTaskInput, getStore, getWriter } from "./pregel/utils/config.js";
8
+ import { RunControl } from "./pregel/runtime.js";
8
9
  import { STREAM_EVENTS_V3_MODES, convertToProtocolEvent, isCheckpointEnvelope } from "./stream/convert.js";
9
10
  import { StreamChannel } from "./stream/stream-channel.js";
10
11
  import { createLifecycleTransformer, filterLifecycleEntries } from "./stream/transformers/lifecycle.js";
@@ -18,11 +19,12 @@ import { interrupt } from "./interrupt.js";
18
19
  import { Graph } from "./graph/graph.js";
19
20
  import { isSerializableSchema, isStandardSchema } from "./state/types.js";
20
21
  import { getJsonSchemaFromSchema, getSchemaDefaultGetter } from "./state/adapter.js";
22
+ import { DeltaChannel } from "./channels/delta.js";
21
23
  import { UntrackedValueChannel } from "./channels/untracked_value.js";
22
24
  import { ReducedValue } from "./state/values/reduced.js";
23
25
  import { UntrackedValue } from "./state/values/untracked.js";
24
26
  import { StateSchema } from "./state/schema.js";
25
- import { REMOVE_ALL_MESSAGES, messagesStateReducer } from "./graph/messages_reducer.js";
27
+ import { REMOVE_ALL_MESSAGES, messagesDeltaReducer, messagesStateReducer } from "./graph/messages_reducer.js";
26
28
  import { MessagesValue } from "./state/prebuilt/messages.js";
27
29
  import { CompiledStateGraph, StateGraph } from "./graph/state.js";
28
30
  import { MessageGraph, pushMessage } from "./graph/message.js";
@@ -33,6 +35,6 @@ import { AsyncBatchedStore, BaseCheckpointSaver, BaseStore, InMemoryStore, Memor
33
35
  //#region src/index.ts
34
36
  initializeAsyncLocalStorageSingleton();
35
37
  //#endregion
36
- export { Annotation, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseStore, BinaryOperatorAggregate, COMMAND_SYMBOL, ChatModelStreamImpl, Command, CommandInstance, CompiledStateGraph, END, EmptyChannelError, EmptyInputError, StreamChannel as EventLog, Graph, GraphBubbleUp, GraphInterrupt, GraphRecursionError, GraphRunStream, GraphValueError, INTERRUPT, InMemoryStore, InvalidUpdateError, MemorySaver, MessageGraph, MessagesAnnotation, MessagesValue, MessagesZodMeta, MessagesZodState, MultipleSubgraphsError, NodeInterrupt, Overwrite, ParentCommand, REMOVE_ALL_MESSAGES, ReducedValue, RemoteException, START, STREAM_EVENTS_V3_MODES, Send, StateGraph, StateGraphInputError, StateSchema, StreamChannel, SubgraphRunStream, UnreachableNodeError, UntrackedValue, UntrackedValueChannel, messagesStateReducer as addMessages, convertToProtocolEvent, copyCheckpoint, createGraphRunStream, createLifecycleTransformer, createMessagesTransformer, createSubgraphDiscoveryTransformer, createValuesTransformer, emptyCheckpoint, entrypoint, filterLifecycleEntries, filterSubgraphHandles, getConfig, getCurrentTaskInput, getJsonSchemaFromSchema, getPreviousState, getSchemaDefaultGetter, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCheckpointEnvelope, isCommand, isGraphBubbleUp, isGraphInterrupt, isInterrupted, isNativeTransformer, isParentCommand, isSerializableSchema, isStandardSchema, messagesStateReducer, pushMessage, task, writer };
38
+ export { Annotation, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseStore, BinaryOperatorAggregate, COMMAND_SYMBOL, ChatModelStreamImpl, Command, CommandInstance, CompiledStateGraph, DeltaChannel, END, EmptyChannelError, EmptyInputError, StreamChannel as EventLog, Graph, GraphBubbleUp, GraphDrained, GraphInterrupt, GraphRecursionError, GraphRunStream, GraphValueError, INTERRUPT, InMemoryStore, InvalidUpdateError, MemorySaver, MessageGraph, MessagesAnnotation, MessagesValue, MessagesZodMeta, MessagesZodState, MultipleSubgraphsError, NodeError, NodeInterrupt, NodeTimeoutError, Overwrite, ParentCommand, REMOVE_ALL_MESSAGES, ReducedValue, RemoteException, RunControl, START, STREAM_EVENTS_V3_MODES, Send, StateGraph, StateGraphInputError, StateSchema, StreamChannel, SubgraphRunStream, UnreachableNodeError, UntrackedValue, UntrackedValueChannel, messagesStateReducer as addMessages, convertToProtocolEvent, copyCheckpoint, createGraphRunStream, createLifecycleTransformer, createMessagesTransformer, createSubgraphDiscoveryTransformer, createValuesTransformer, emptyCheckpoint, entrypoint, filterLifecycleEntries, filterSubgraphHandles, getConfig, getCurrentTaskInput, getJsonSchemaFromSchema, getPreviousState, getSchemaDefaultGetter, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCheckpointEnvelope, isCommand, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isInterrupted, isNativeTransformer, isNodeError, isNodeTimeoutError, isParentCommand, isSerializableSchema, isStandardSchema, messagesDeltaReducer, messagesStateReducer, pushMessage, task, writer };
37
39
 
38
40
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\nimport { initializeAsyncLocalStorageSingleton } from \"./node.js\";\n\n// Initialize global async local storage instance for tracing\ninitializeAsyncLocalStorageSingleton();\n\nexport * from \"./web.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,sCAAsC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\nimport { initializeAsyncLocalStorageSingleton } from \"./node.js\";\n\n// Initialize global async local storage instance for tracing\ninitializeAsyncLocalStorageSingleton();\n\nexport * from \"./web.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,sCAAsC"}
@@ -9,8 +9,8 @@ import { Messages } from "../graph/messages_reducer.cjs";
9
9
  import { MessagesAnnotation } from "../graph/messages_annotation.cjs";
10
10
  import { ToolNode } from "./tool_node.cjs";
11
11
  import { All, BaseCheckpointSaver, BaseStore } from "@langchain/langgraph-checkpoint";
12
- import { InteropZodObject, InteropZodType } from "@langchain/core/utils/types";
13
12
  import { Runnable, RunnableBinding, RunnableLike, RunnableToolLike } from "@langchain/core/runnables";
13
+ import { InteropZodObject, InteropZodType } from "@langchain/core/utils/types";
14
14
  import * as _langchain_core_messages0 from "@langchain/core/messages";
15
15
  import { BaseMessage, BaseMessageLike, SystemMessage } from "@langchain/core/messages";
16
16
  import { DynamicTool, StructuredToolInterface } from "@langchain/core/tools";
@@ -122,6 +122,57 @@ const isSendInput = (input) => typeof input === "object" && input != null && "lg
122
122
  * }
123
123
  * // Returns the messages in the state at each step of execution
124
124
  * ```
125
+ *
126
+ * ### Accessing graph state and runtime context from tools
127
+ *
128
+ * Tools executed by a `ToolNode` only receive the arguments produced by the
129
+ * model. To give a tool access to the surrounding graph state or other runtime
130
+ * context, read them from the {@link ToolRuntime} that is passed as the
131
+ * second argument to every tool:
132
+ *
133
+ * - `runtime.state` — the input the `ToolNode` was invoked with. When the
134
+ * `ToolNode` runs as a graph node (e.g. inside `createReactAgent`), this is
135
+ * the current graph state. This works in any runtime, including web browsers,
136
+ * because it does not rely on `node:async_hooks`/`AsyncLocalStorage`.
137
+ * - `runtime.config`, `runtime.context`, `runtime.store`, etc. — other
138
+ * run-scoped values.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * import { ToolNode } from "@langchain/langgraph/prebuilt";
143
+ * import { StateGraph, MessagesZodState } from "@langchain/langgraph";
144
+ * import { tool, type ToolRuntime } from "@langchain/core/tools";
145
+ * import { z } from "zod";
146
+ *
147
+ * // Define the graph state with a Zod schema. The extra `userId` key becomes
148
+ * // part of the state that the ToolNode forwards to its tools via `runtime.state`.
149
+ * const AgentState = z.object({
150
+ * ...MessagesZodState.shape,
151
+ * userId: z.string(),
152
+ * });
153
+ *
154
+ * const getUserInfo = tool(
155
+ * async (_input, runtime: ToolRuntime<typeof AgentState>) => {
156
+ * // Read the current graph state directly from the second argument.
157
+ * const userId = runtime.state.userId;
158
+ * return userId === "user_123" ? "User is John Smith" : "Unknown user";
159
+ * },
160
+ * {
161
+ * name: "get_user_info",
162
+ * description: "Look up user info.",
163
+ * schema: z.object({}),
164
+ * }
165
+ * );
166
+ *
167
+ * // Wire the ToolNode into a StateGraph that uses `AgentState`. Because the
168
+ * // node runs with the graph state as its input, the tool can read `userId`.
169
+ * const graph = new StateGraph(AgentState)
170
+ * .addNode("tools", new ToolNode([getUserInfo]))
171
+ * .addEdge("__start__", "tools")
172
+ * .compile();
173
+ *
174
+ * await graph.invoke({ messages: [...], userId: "user_123" });
175
+ * ```
125
176
  */
126
177
  var ToolNode = class extends require_utils.RunnableCallable {
127
178
  tools;
@@ -137,14 +188,24 @@ var ToolNode = class extends require_utils.RunnableCallable {
137
188
  this.tools = tools;
138
189
  this.handleToolErrors = handleToolErrors ?? this.handleToolErrors;
139
190
  }
140
- async runTool(call, config) {
191
+ async runTool(call, config, state) {
141
192
  const tool = this.tools.find((tool) => tool.name === call.name);
142
193
  try {
143
194
  if (tool === void 0) throw new Error(`Tool "${call.name}" not found.`);
144
- const output = await tool.invoke({
195
+ const toolCall = {
145
196
  ...call,
146
197
  type: "tool_call"
147
- }, config);
198
+ };
199
+ const runtime = {
200
+ ...config,
201
+ state,
202
+ toolCallId: call.id ?? "",
203
+ config,
204
+ context: config.context,
205
+ store: config.store ?? null,
206
+ writer: config.writer ?? config.configurable?.writer ?? null
207
+ };
208
+ const output = await tool.invoke(toolCall, runtime);
148
209
  if ((0, _langchain_core_messages.isBaseMessage)(output) && output.getType() === "tool" || require_constants.isCommand(output)) return output;
149
210
  return new _langchain_core_messages.ToolMessage({
150
211
  status: "success",
@@ -165,8 +226,10 @@ var ToolNode = class extends require_utils.RunnableCallable {
165
226
  }
166
227
  async run(input, config) {
167
228
  let outputs;
168
- if (isSendInput(input)) outputs = [await this.runTool(input.lg_tool_call, config)];
169
- else {
229
+ if (isSendInput(input)) {
230
+ const { lg_tool_call: toolCall, ...state } = input;
231
+ outputs = [await this.runTool(toolCall, config, state)];
232
+ } else {
170
233
  let messages;
171
234
  if (isBaseMessageArray(input)) messages = input;
172
235
  else if (isMessagesState(input)) messages = input.messages;
@@ -181,7 +244,7 @@ var ToolNode = class extends require_utils.RunnableCallable {
181
244
  }
182
245
  }
183
246
  if (aiMessage == null || !(0, _langchain_core_messages.isAIMessage)(aiMessage)) throw new Error("ToolNode only accepts AIMessages as input.");
184
- outputs = await Promise.all(aiMessage.tool_calls?.filter((call) => call.id == null || !toolMessageIds.has(call.id)).map((call) => this.runTool(call, config)) ?? []);
247
+ outputs = await Promise.all(aiMessage.tool_calls?.filter((call) => call.id == null || !toolMessageIds.has(call.id)).map((call) => this.runTool(call, config, input)) ?? []);
185
248
  }
186
249
  if (!outputs.some(require_constants.isCommand)) return Array.isArray(input) ? outputs : { messages: outputs };
187
250
  const combinedOutputs = [];
@@ -1 +1 @@
1
- {"version":3,"file":"tool_node.cjs","names":["isBaseMessage","RunnableCallable","isCommand","ToolMessage","isGraphInterrupt","Command","_isSend","END"],"sources":["../../src/prebuilt/tool_node.ts"],"sourcesContent":["import {\n BaseMessage,\n ToolMessage,\n AIMessage,\n isBaseMessage,\n isAIMessage,\n} from \"@langchain/core/messages\";\nimport { RunnableConfig, RunnableToolLike } from \"@langchain/core/runnables\";\nimport { DynamicTool, StructuredToolInterface } from \"@langchain/core/tools\";\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\nimport { RunnableCallable } from \"../utils.js\";\nimport { MessagesAnnotation } from \"../graph/messages_annotation.js\";\nimport { isGraphInterrupt } from \"../errors.js\";\nimport { END, isCommand, Command, _isSend, Send } from \"../constants.js\";\n\nexport type ToolNodeOptions = {\n name?: string;\n tags?: string[];\n handleToolErrors?: boolean;\n};\n\nconst isBaseMessageArray = (input: unknown): input is BaseMessage[] =>\n Array.isArray(input) && input.every(isBaseMessage);\n\nconst isMessagesState = (\n input: unknown\n): input is { messages: BaseMessage[] } =>\n typeof input === \"object\" &&\n input != null &&\n \"messages\" in input &&\n isBaseMessageArray(input.messages);\n\nconst isSendInput = (input: unknown): input is { lg_tool_call: ToolCall } =>\n typeof input === \"object\" && input != null && \"lg_tool_call\" in input;\n\n/**\n * A node that runs the tools requested in the last AIMessage. It can be used\n * either in StateGraph with a \"messages\" key or in MessageGraph. If multiple\n * tool calls are requested, they will be run in parallel. The output will be\n * a list of ToolMessages, one for each tool call.\n *\n * @example\n * ```ts\n * import { ToolNode } from \"@langchain/langgraph/prebuilt\";\n * import { tool } from \"@langchain/core/tools\";\n * import { z } from \"zod\";\n * import { AIMessage } from \"@langchain/core/messages\";\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * }),\n * });\n *\n * const tools = [getWeather];\n * const toolNode = new ToolNode(tools);\n *\n * const messageWithSingleToolCall = new AIMessage({\n * content: \"\",\n * tool_calls: [\n * {\n * name: \"get_weather\",\n * args: { location: \"sf\" },\n * id: \"tool_call_id\",\n * type: \"tool_call\",\n * }\n * ]\n * })\n *\n * await toolNode.invoke({ messages: [messageWithSingleToolCall] });\n * // Returns tool invocation responses as:\n * // { messages: ToolMessage[] }\n * ```\n *\n * @example\n * ```ts\n * import {\n * StateGraph,\n * MessagesAnnotation,\n * } from \"@langchain/langgraph\";\n * import { ToolNode } from \"@langchain/langgraph/prebuilt\";\n * import { tool } from \"@langchain/core/tools\";\n * import { z } from \"zod\";\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * }),\n * });\n *\n * const tools = [getWeather];\n * const modelWithTools = new ChatAnthropic({\n * model: \"claude-3-haiku-20240307\",\n * temperature: 0\n * }).bindTools(tools);\n *\n * const toolNodeForGraph = new ToolNode(tools)\n *\n * const shouldContinue = (state: typeof MessagesAnnotation.State) => {\n * const { messages } = state;\n * const lastMessage = messages[messages.length - 1];\n * if (\"tool_calls\" in lastMessage && Array.isArray(lastMessage.tool_calls) && lastMessage.tool_calls?.length) {\n * return \"tools\";\n * }\n * return \"__end__\";\n * }\n *\n * const callModel = async (state: typeof MessagesAnnotation.State) => {\n * const { messages } = state;\n * const response = await modelWithTools.invoke(messages);\n * return { messages: response };\n * }\n *\n * const graph = new StateGraph(MessagesAnnotation)\n * .addNode(\"agent\", callModel)\n * .addNode(\"tools\", toolNodeForGraph)\n * .addEdge(\"__start__\", \"agent\")\n * .addConditionalEdges(\"agent\", shouldContinue)\n * .addEdge(\"tools\", \"agent\")\n * .compile();\n *\n * const inputs = {\n * messages: [{ role: \"user\", content: \"what is the weather in SF?\" }],\n * };\n *\n * const stream = await graph.stream(inputs, {\n * streamMode: \"values\",\n * });\n *\n * for await (const { messages } of stream) {\n * console.log(messages);\n * }\n * // Returns the messages in the state at each step of execution\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class ToolNode<T = any> extends RunnableCallable<T, T> {\n tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[];\n\n handleToolErrors = true;\n\n trace = false;\n\n constructor(\n tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[],\n options?: ToolNodeOptions\n ) {\n const { name, tags, handleToolErrors } = options ?? {};\n super({ name, tags, func: (input, config) => this.run(input, config) });\n this.tools = tools;\n this.handleToolErrors = handleToolErrors ?? this.handleToolErrors;\n }\n\n protected async runTool(\n call: ToolCall,\n config: RunnableConfig\n ): Promise<ToolMessage | Command> {\n const tool = this.tools.find((tool) => tool.name === call.name);\n try {\n if (tool === undefined) {\n throw new Error(`Tool \"${call.name}\" not found.`);\n }\n const output = await tool.invoke({ ...call, type: \"tool_call\" }, config);\n\n if (\n (isBaseMessage(output) && output.getType() === \"tool\") ||\n isCommand(output)\n ) {\n return output as ToolMessage | Command;\n }\n\n return new ToolMessage({\n status: \"success\",\n name: tool.name,\n content: typeof output === \"string\" ? output : JSON.stringify(output),\n tool_call_id: call.id!,\n });\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n if (!this.handleToolErrors) throw e;\n\n if (isGraphInterrupt(e)) {\n // `NodeInterrupt` errors are a breakpoint to bring a human into the loop.\n // As such, they are not recoverable by the agent and shouldn't be fed\n // back. Instead, re-throw these errors even when `handleToolErrors = true`.\n throw e;\n }\n\n return new ToolMessage({\n status: \"error\",\n content: `Error: ${e.message}\\n Please fix your mistakes.`,\n name: call.name,\n tool_call_id: call.id ?? \"\",\n });\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n protected async run(input: unknown, config: RunnableConfig): Promise<T> {\n let outputs: (ToolMessage | Command)[];\n\n if (isSendInput(input)) {\n outputs = [await this.runTool(input.lg_tool_call, config)];\n } else {\n let messages: BaseMessage[];\n if (isBaseMessageArray(input)) {\n messages = input;\n } else if (isMessagesState(input)) {\n messages = input.messages;\n } else {\n throw new Error(\n \"ToolNode only accepts BaseMessage[] or { messages: BaseMessage[] } as input.\"\n );\n }\n\n const toolMessageIds: Set<string> = new Set(\n messages\n .filter((msg) => msg.getType() === \"tool\")\n .map((msg) => (msg as ToolMessage).tool_call_id)\n );\n\n let aiMessage: AIMessage | undefined;\n for (let i = messages.length - 1; i >= 0; i -= 1) {\n const message = messages[i];\n if (isAIMessage(message)) {\n aiMessage = message;\n break;\n }\n }\n\n if (aiMessage == null || !isAIMessage(aiMessage)) {\n throw new Error(\"ToolNode only accepts AIMessages as input.\");\n }\n\n outputs = await Promise.all(\n aiMessage.tool_calls\n ?.filter((call) => call.id == null || !toolMessageIds.has(call.id))\n .map((call) => this.runTool(call, config)) ?? []\n );\n }\n\n // Preserve existing behavior for non-command tool outputs for backwards compatibility\n if (!outputs.some(isCommand)) {\n return (Array.isArray(input) ? outputs : { messages: outputs }) as T;\n }\n\n // Handle mixed Command and non-Command outputs\n const combinedOutputs: (\n | { messages: BaseMessage[] }\n | BaseMessage[]\n | Command\n )[] = [];\n let parentCommand: Command | null = null;\n\n for (const output of outputs) {\n if (isCommand(output)) {\n if (\n output.graph === Command.PARENT &&\n Array.isArray(output.goto) &&\n output.goto.every((send) => _isSend(send))\n ) {\n if (parentCommand) {\n (parentCommand.goto as Send[]).push(...(output.goto as Send[]));\n } else {\n parentCommand = new Command({\n graph: Command.PARENT,\n goto: output.goto,\n });\n }\n } else {\n combinedOutputs.push(output);\n }\n } else {\n combinedOutputs.push(\n Array.isArray(input) ? [output] : { messages: [output] }\n );\n }\n }\n\n if (parentCommand) {\n combinedOutputs.push(parentCommand);\n }\n\n return combinedOutputs as T;\n }\n}\n\n/**\n * A conditional edge function that determines whether to route to a tools node or end the graph.\n *\n * This function is designed to be used as a conditional edge in a LangGraph state graph to implement\n * the common pattern of checking if an AI message contains tool calls that need to be executed.\n *\n * @param state - The current state of the graph, which can be either:\n * - An array of `BaseMessage` objects, where the last message is checked for tool calls\n * - A state object conforming to `MessagesAnnotation.State`, which contains a `messages` array\n *\n * @returns A string indicating the next node to route to:\n * - `\"tools\"` - If the last message contains tool calls that need to be executed\n * - `END` - If there are no tool calls, indicating the graph should terminate\n *\n * @example\n * ```typescript\n * import { StateGraph, MessagesAnnotation, END, START } from \"@langchain/langgraph\";\n * import { ToolNode, toolsCondition } from \"@langchain/langgraph/prebuilt\";\n *\n * const graph = new StateGraph(MessagesAnnotation)\n * .addNode(\"agent\", agentNode)\n * .addNode(\"tools\", new ToolNode([searchTool, calculatorTool]))\n * .addEdge(START, \"agent\")\n * .addConditionalEdges(\"agent\", toolsCondition, [\"tools\", END])\n * .addEdge(\"tools\", \"agent\")\n * .compile();\n * ```\n *\n * @remarks\n * The function checks the last message in the state for the presence of `tool_calls`.\n * If the message is an `AIMessage` with one or more tool calls, it returns `\"tools\"`,\n * indicating that the graph should route to a tools node (typically a `ToolNode`) to\n * execute those tool calls. Otherwise, it returns `END` to terminate the graph execution.\n *\n * This is a common pattern in agentic workflows where an AI model decides whether to\n * use tools or provide a final response.\n */\nexport function toolsCondition(\n state: BaseMessage[] | typeof MessagesAnnotation.State\n): \"tools\" | typeof END {\n const message = Array.isArray(state)\n ? state[state.length - 1]\n : state.messages[state.messages.length - 1];\n\n if (\n message !== undefined &&\n \"tool_calls\" in message &&\n ((message as AIMessage).tool_calls?.length ?? 0) > 0\n ) {\n return \"tools\";\n } else {\n return END;\n }\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"tool_node.cjs","names":["isBaseMessage","RunnableCallable","isCommand","ToolMessage","isGraphInterrupt","Command","_isSend","END"],"sources":["../../src/prebuilt/tool_node.ts"],"sourcesContent":["import {\n BaseMessage,\n ToolMessage,\n AIMessage,\n isBaseMessage,\n isAIMessage,\n} from \"@langchain/core/messages\";\nimport { RunnableToolLike } from \"@langchain/core/runnables\";\nimport {\n DynamicTool,\n StructuredToolInterface,\n type ToolRuntime,\n} from \"@langchain/core/tools\";\nimport type { ToolCall } from \"@langchain/core/messages/tool\";\nimport { RunnableCallable } from \"../utils.js\";\nimport { MessagesAnnotation } from \"../graph/messages_annotation.js\";\nimport { isGraphInterrupt } from \"../errors.js\";\nimport { END, isCommand, Command, _isSend, Send } from \"../constants.js\";\nimport type { LangGraphRunnableConfig } from \"../pregel/runnable_types.js\";\n\nexport type ToolNodeOptions = {\n name?: string;\n tags?: string[];\n handleToolErrors?: boolean;\n};\n\nconst isBaseMessageArray = (input: unknown): input is BaseMessage[] =>\n Array.isArray(input) && input.every(isBaseMessage);\n\nconst isMessagesState = (\n input: unknown\n): input is { messages: BaseMessage[] } =>\n typeof input === \"object\" &&\n input != null &&\n \"messages\" in input &&\n isBaseMessageArray(input.messages);\n\nconst isSendInput = (input: unknown): input is { lg_tool_call: ToolCall } =>\n typeof input === \"object\" && input != null && \"lg_tool_call\" in input;\n\n/**\n * A node that runs the tools requested in the last AIMessage. It can be used\n * either in StateGraph with a \"messages\" key or in MessageGraph. If multiple\n * tool calls are requested, they will be run in parallel. The output will be\n * a list of ToolMessages, one for each tool call.\n *\n * @example\n * ```ts\n * import { ToolNode } from \"@langchain/langgraph/prebuilt\";\n * import { tool } from \"@langchain/core/tools\";\n * import { z } from \"zod\";\n * import { AIMessage } from \"@langchain/core/messages\";\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * }),\n * });\n *\n * const tools = [getWeather];\n * const toolNode = new ToolNode(tools);\n *\n * const messageWithSingleToolCall = new AIMessage({\n * content: \"\",\n * tool_calls: [\n * {\n * name: \"get_weather\",\n * args: { location: \"sf\" },\n * id: \"tool_call_id\",\n * type: \"tool_call\",\n * }\n * ]\n * })\n *\n * await toolNode.invoke({ messages: [messageWithSingleToolCall] });\n * // Returns tool invocation responses as:\n * // { messages: ToolMessage[] }\n * ```\n *\n * @example\n * ```ts\n * import {\n * StateGraph,\n * MessagesAnnotation,\n * } from \"@langchain/langgraph\";\n * import { ToolNode } from \"@langchain/langgraph/prebuilt\";\n * import { tool } from \"@langchain/core/tools\";\n * import { z } from \"zod\";\n * import { ChatAnthropic } from \"@langchain/anthropic\";\n *\n * const getWeather = tool((input) => {\n * if ([\"sf\", \"san francisco\"].includes(input.location.toLowerCase())) {\n * return \"It's 60 degrees and foggy.\";\n * } else {\n * return \"It's 90 degrees and sunny.\";\n * }\n * }, {\n * name: \"get_weather\",\n * description: \"Call to get the current weather.\",\n * schema: z.object({\n * location: z.string().describe(\"Location to get the weather for.\"),\n * }),\n * });\n *\n * const tools = [getWeather];\n * const modelWithTools = new ChatAnthropic({\n * model: \"claude-3-haiku-20240307\",\n * temperature: 0\n * }).bindTools(tools);\n *\n * const toolNodeForGraph = new ToolNode(tools)\n *\n * const shouldContinue = (state: typeof MessagesAnnotation.State) => {\n * const { messages } = state;\n * const lastMessage = messages[messages.length - 1];\n * if (\"tool_calls\" in lastMessage && Array.isArray(lastMessage.tool_calls) && lastMessage.tool_calls?.length) {\n * return \"tools\";\n * }\n * return \"__end__\";\n * }\n *\n * const callModel = async (state: typeof MessagesAnnotation.State) => {\n * const { messages } = state;\n * const response = await modelWithTools.invoke(messages);\n * return { messages: response };\n * }\n *\n * const graph = new StateGraph(MessagesAnnotation)\n * .addNode(\"agent\", callModel)\n * .addNode(\"tools\", toolNodeForGraph)\n * .addEdge(\"__start__\", \"agent\")\n * .addConditionalEdges(\"agent\", shouldContinue)\n * .addEdge(\"tools\", \"agent\")\n * .compile();\n *\n * const inputs = {\n * messages: [{ role: \"user\", content: \"what is the weather in SF?\" }],\n * };\n *\n * const stream = await graph.stream(inputs, {\n * streamMode: \"values\",\n * });\n *\n * for await (const { messages } of stream) {\n * console.log(messages);\n * }\n * // Returns the messages in the state at each step of execution\n * ```\n *\n * ### Accessing graph state and runtime context from tools\n *\n * Tools executed by a `ToolNode` only receive the arguments produced by the\n * model. To give a tool access to the surrounding graph state or other runtime\n * context, read them from the {@link ToolRuntime} that is passed as the\n * second argument to every tool:\n *\n * - `runtime.state` — the input the `ToolNode` was invoked with. When the\n * `ToolNode` runs as a graph node (e.g. inside `createReactAgent`), this is\n * the current graph state. This works in any runtime, including web browsers,\n * because it does not rely on `node:async_hooks`/`AsyncLocalStorage`.\n * - `runtime.config`, `runtime.context`, `runtime.store`, etc. — other\n * run-scoped values.\n *\n * @example\n * ```ts\n * import { ToolNode } from \"@langchain/langgraph/prebuilt\";\n * import { StateGraph, MessagesZodState } from \"@langchain/langgraph\";\n * import { tool, type ToolRuntime } from \"@langchain/core/tools\";\n * import { z } from \"zod\";\n *\n * // Define the graph state with a Zod schema. The extra `userId` key becomes\n * // part of the state that the ToolNode forwards to its tools via `runtime.state`.\n * const AgentState = z.object({\n * ...MessagesZodState.shape,\n * userId: z.string(),\n * });\n *\n * const getUserInfo = tool(\n * async (_input, runtime: ToolRuntime<typeof AgentState>) => {\n * // Read the current graph state directly from the second argument.\n * const userId = runtime.state.userId;\n * return userId === \"user_123\" ? \"User is John Smith\" : \"Unknown user\";\n * },\n * {\n * name: \"get_user_info\",\n * description: \"Look up user info.\",\n * schema: z.object({}),\n * }\n * );\n *\n * // Wire the ToolNode into a StateGraph that uses `AgentState`. Because the\n * // node runs with the graph state as its input, the tool can read `userId`.\n * const graph = new StateGraph(AgentState)\n * .addNode(\"tools\", new ToolNode([getUserInfo]))\n * .addEdge(\"__start__\", \"tools\")\n * .compile();\n *\n * await graph.invoke({ messages: [...], userId: \"user_123\" });\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class ToolNode<T = any> extends RunnableCallable<T, T> {\n tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[];\n\n handleToolErrors = true;\n\n trace = false;\n\n constructor(\n tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[],\n options?: ToolNodeOptions\n ) {\n const { name, tags, handleToolErrors } = options ?? {};\n super({ name, tags, func: (input, config) => this.run(input, config) });\n this.tools = tools;\n this.handleToolErrors = handleToolErrors ?? this.handleToolErrors;\n }\n\n protected async runTool(\n call: ToolCall,\n config: LangGraphRunnableConfig,\n state: unknown\n ): Promise<ToolMessage | Command> {\n const tool = this.tools.find((tool) => tool.name === call.name);\n try {\n if (tool === undefined) {\n throw new Error(`Tool \"${call.name}\" not found.`);\n }\n const toolCall = { ...call, type: \"tool_call\" } as ToolCall;\n const runtime: ToolRuntime = {\n ...config,\n state,\n toolCallId: call.id ?? \"\",\n config,\n context: config.context,\n store: (config.store as ToolRuntime[\"store\"] | undefined) ?? null,\n writer: config.writer ?? config.configurable?.writer ?? null,\n };\n const output = await tool.invoke(toolCall, runtime);\n\n if (\n (isBaseMessage(output) && output.getType() === \"tool\") ||\n isCommand(output)\n ) {\n return output as ToolMessage | Command;\n }\n\n return new ToolMessage({\n status: \"success\",\n name: tool.name,\n content: typeof output === \"string\" ? output : JSON.stringify(output),\n tool_call_id: call.id!,\n });\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n if (!this.handleToolErrors) throw e;\n\n if (isGraphInterrupt(e)) {\n // `NodeInterrupt` errors are a breakpoint to bring a human into the loop.\n // As such, they are not recoverable by the agent and shouldn't be fed\n // back. Instead, re-throw these errors even when `handleToolErrors = true`.\n throw e;\n }\n\n return new ToolMessage({\n status: \"error\",\n content: `Error: ${e.message}\\n Please fix your mistakes.`,\n name: call.name,\n tool_call_id: call.id ?? \"\",\n });\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n protected async run(\n input: unknown,\n config: LangGraphRunnableConfig\n ): Promise<T> {\n let outputs: (ToolMessage | Command)[];\n\n if (isSendInput(input)) {\n // Drop the internal `lg_tool_call` routing key so tools only see state.\n const { lg_tool_call: toolCall, ...state } = input as {\n lg_tool_call: ToolCall;\n } & Record<string, unknown>;\n outputs = [await this.runTool(toolCall, config, state)];\n } else {\n let messages: BaseMessage[];\n if (isBaseMessageArray(input)) {\n messages = input;\n } else if (isMessagesState(input)) {\n messages = input.messages;\n } else {\n throw new Error(\n \"ToolNode only accepts BaseMessage[] or { messages: BaseMessage[] } as input.\"\n );\n }\n\n const toolMessageIds: Set<string> = new Set(\n messages\n .filter((msg) => msg.getType() === \"tool\")\n .map((msg) => (msg as ToolMessage).tool_call_id)\n );\n\n let aiMessage: AIMessage | undefined;\n for (let i = messages.length - 1; i >= 0; i -= 1) {\n const message = messages[i];\n if (isAIMessage(message)) {\n aiMessage = message;\n break;\n }\n }\n\n if (aiMessage == null || !isAIMessage(aiMessage)) {\n throw new Error(\"ToolNode only accepts AIMessages as input.\");\n }\n\n outputs = await Promise.all(\n aiMessage.tool_calls\n ?.filter((call) => call.id == null || !toolMessageIds.has(call.id))\n .map((call) => this.runTool(call, config, input)) ?? []\n );\n }\n\n // Preserve existing behavior for non-command tool outputs for backwards compatibility\n if (!outputs.some(isCommand)) {\n return (Array.isArray(input) ? outputs : { messages: outputs }) as T;\n }\n\n // Handle mixed Command and non-Command outputs\n const combinedOutputs: (\n | { messages: BaseMessage[] }\n | BaseMessage[]\n | Command\n )[] = [];\n let parentCommand: Command | null = null;\n\n for (const output of outputs) {\n if (isCommand(output)) {\n if (\n output.graph === Command.PARENT &&\n Array.isArray(output.goto) &&\n output.goto.every((send) => _isSend(send))\n ) {\n if (parentCommand) {\n (parentCommand.goto as Send[]).push(...(output.goto as Send[]));\n } else {\n parentCommand = new Command({\n graph: Command.PARENT,\n goto: output.goto,\n });\n }\n } else {\n combinedOutputs.push(output);\n }\n } else {\n combinedOutputs.push(\n Array.isArray(input) ? [output] : { messages: [output] }\n );\n }\n }\n\n if (parentCommand) {\n combinedOutputs.push(parentCommand);\n }\n\n return combinedOutputs as T;\n }\n}\n\n/**\n * A conditional edge function that determines whether to route to a tools node or end the graph.\n *\n * This function is designed to be used as a conditional edge in a LangGraph state graph to implement\n * the common pattern of checking if an AI message contains tool calls that need to be executed.\n *\n * @param state - The current state of the graph, which can be either:\n * - An array of `BaseMessage` objects, where the last message is checked for tool calls\n * - A state object conforming to `MessagesAnnotation.State`, which contains a `messages` array\n *\n * @returns A string indicating the next node to route to:\n * - `\"tools\"` - If the last message contains tool calls that need to be executed\n * - `END` - If there are no tool calls, indicating the graph should terminate\n *\n * @example\n * ```typescript\n * import { StateGraph, MessagesAnnotation, END, START } from \"@langchain/langgraph\";\n * import { ToolNode, toolsCondition } from \"@langchain/langgraph/prebuilt\";\n *\n * const graph = new StateGraph(MessagesAnnotation)\n * .addNode(\"agent\", agentNode)\n * .addNode(\"tools\", new ToolNode([searchTool, calculatorTool]))\n * .addEdge(START, \"agent\")\n * .addConditionalEdges(\"agent\", toolsCondition, [\"tools\", END])\n * .addEdge(\"tools\", \"agent\")\n * .compile();\n * ```\n *\n * @remarks\n * The function checks the last message in the state for the presence of `tool_calls`.\n * If the message is an `AIMessage` with one or more tool calls, it returns `\"tools\"`,\n * indicating that the graph should route to a tools node (typically a `ToolNode`) to\n * execute those tool calls. Otherwise, it returns `END` to terminate the graph execution.\n *\n * This is a common pattern in agentic workflows where an AI model decides whether to\n * use tools or provide a final response.\n */\nexport function toolsCondition(\n state: BaseMessage[] | typeof MessagesAnnotation.State\n): \"tools\" | typeof END {\n const message = Array.isArray(state)\n ? state[state.length - 1]\n : state.messages[state.messages.length - 1];\n\n if (\n message !== undefined &&\n \"tool_calls\" in message &&\n ((message as AIMessage).tool_calls?.length ?? 0) > 0\n ) {\n return \"tools\";\n } else {\n return END;\n }\n}\n"],"mappings":"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"}
@@ -1,7 +1,8 @@
1
1
  import { Command, END } from "../constants.cjs";
2
+ import { LangGraphRunnableConfig } from "../pregel/runnable_types.cjs";
2
3
  import { RunnableCallable } from "../utils.cjs";
3
4
  import { MessagesAnnotation } from "../graph/messages_annotation.cjs";
4
- import { RunnableConfig, RunnableToolLike } from "@langchain/core/runnables";
5
+ import { RunnableToolLike } from "@langchain/core/runnables";
5
6
  import { BaseMessage, ToolMessage } from "@langchain/core/messages";
6
7
  import { DynamicTool, StructuredToolInterface } from "@langchain/core/tools";
7
8
  import { ToolCall } from "@langchain/core/messages/tool";
@@ -128,14 +129,65 @@ type ToolNodeOptions = {
128
129
  * }
129
130
  * // Returns the messages in the state at each step of execution
130
131
  * ```
132
+ *
133
+ * ### Accessing graph state and runtime context from tools
134
+ *
135
+ * Tools executed by a `ToolNode` only receive the arguments produced by the
136
+ * model. To give a tool access to the surrounding graph state or other runtime
137
+ * context, read them from the {@link ToolRuntime} that is passed as the
138
+ * second argument to every tool:
139
+ *
140
+ * - `runtime.state` — the input the `ToolNode` was invoked with. When the
141
+ * `ToolNode` runs as a graph node (e.g. inside `createReactAgent`), this is
142
+ * the current graph state. This works in any runtime, including web browsers,
143
+ * because it does not rely on `node:async_hooks`/`AsyncLocalStorage`.
144
+ * - `runtime.config`, `runtime.context`, `runtime.store`, etc. — other
145
+ * run-scoped values.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * import { ToolNode } from "@langchain/langgraph/prebuilt";
150
+ * import { StateGraph, MessagesZodState } from "@langchain/langgraph";
151
+ * import { tool, type ToolRuntime } from "@langchain/core/tools";
152
+ * import { z } from "zod";
153
+ *
154
+ * // Define the graph state with a Zod schema. The extra `userId` key becomes
155
+ * // part of the state that the ToolNode forwards to its tools via `runtime.state`.
156
+ * const AgentState = z.object({
157
+ * ...MessagesZodState.shape,
158
+ * userId: z.string(),
159
+ * });
160
+ *
161
+ * const getUserInfo = tool(
162
+ * async (_input, runtime: ToolRuntime<typeof AgentState>) => {
163
+ * // Read the current graph state directly from the second argument.
164
+ * const userId = runtime.state.userId;
165
+ * return userId === "user_123" ? "User is John Smith" : "Unknown user";
166
+ * },
167
+ * {
168
+ * name: "get_user_info",
169
+ * description: "Look up user info.",
170
+ * schema: z.object({}),
171
+ * }
172
+ * );
173
+ *
174
+ * // Wire the ToolNode into a StateGraph that uses `AgentState`. Because the
175
+ * // node runs with the graph state as its input, the tool can read `userId`.
176
+ * const graph = new StateGraph(AgentState)
177
+ * .addNode("tools", new ToolNode([getUserInfo]))
178
+ * .addEdge("__start__", "tools")
179
+ * .compile();
180
+ *
181
+ * await graph.invoke({ messages: [...], userId: "user_123" });
182
+ * ```
131
183
  */
132
184
  declare class ToolNode<T = any> extends RunnableCallable<T, T> {
133
185
  tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[];
134
186
  handleToolErrors: boolean;
135
187
  trace: boolean;
136
188
  constructor(tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[], options?: ToolNodeOptions);
137
- protected runTool(call: ToolCall, config: RunnableConfig): Promise<ToolMessage | Command>;
138
- protected run(input: unknown, config: RunnableConfig): Promise<T>;
189
+ protected runTool(call: ToolCall, config: LangGraphRunnableConfig, state: unknown): Promise<ToolMessage | Command>;
190
+ protected run(input: unknown, config: LangGraphRunnableConfig): Promise<T>;
139
191
  }
140
192
  /**
141
193
  * A conditional edge function that determines whether to route to a tools node or end the graph.
@@ -1 +1 @@
1
- {"version":3,"file":"tool_node.d.cts","names":[],"sources":["../../src/prebuilt/tool_node.ts"],"mappings":";;;;;;;;;KAeY,eAAA;EACV,IAAA;EACA,IAAA;EACA,gBAAA;AAAA;;;;;;;AAuIF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4LA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA5La,QAAA,kBAA0B,gBAAA,CAAiB,CAAA,EAAG,CAAA;EACzD,KAAA,GAAQ,uBAAA,GAA0B,WAAA,GAAc,gBAAA;EAEhD,gBAAA;EAEA,KAAA;EAEA,WAAA,CACE,KAAA,GAAQ,uBAAA,GAA0B,WAAA,GAAc,gBAAA,KAChD,OAAA,GAAU,eAAA;EAAA,UAQI,OAAA,CACd,IAAA,EAAM,QAAA,EACN,MAAA,EAAQ,cAAA,GACP,OAAA,CAAQ,WAAA,GAAc,OAAA;EAAA,UA0CT,GAAA,CAAI,KAAA,WAAgB,MAAA,EAAQ,cAAA,GAAiB,OAAA,CAAQ,CAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8HvD,cAAA,CACd,KAAA,EAAO,WAAA,YAAuB,kBAAA,CAAmB,KAAA,oBAC/B,GAAA"}
1
+ {"version":3,"file":"tool_node.d.cts","names":[],"sources":["../../src/prebuilt/tool_node.ts"],"mappings":";;;;;;;;;;KAoBY,eAAA;EACV,IAAA;EACA,IAAA;EACA,gBAAA;AAAA;;;;;;;AA0LF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8MA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA9Ma,QAAA,kBAA0B,gBAAA,CAAiB,CAAA,EAAG,CAAA;EACzD,KAAA,GAAQ,uBAAA,GAA0B,WAAA,GAAc,gBAAA;EAEhD,gBAAA;EAEA,KAAA;EAEA,WAAA,CACE,KAAA,GAAQ,uBAAA,GAA0B,WAAA,GAAc,gBAAA,KAChD,OAAA,GAAU,eAAA;EAAA,UAQI,OAAA,CACd,IAAA,EAAM,QAAA,EACN,MAAA,EAAQ,uBAAA,EACR,KAAA,YACC,OAAA,CAAQ,WAAA,GAAc,OAAA;EAAA,UAoDT,GAAA,CACd,KAAA,WACA,MAAA,EAAQ,uBAAA,GACP,OAAA,CAAQ,CAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkIG,cAAA,CACd,KAAA,EAAO,WAAA,YAAuB,kBAAA,CAAmB,KAAA,oBAC/B,GAAA"}
@@ -1,7 +1,8 @@
1
1
  import { Command, END } from "../constants.js";
2
+ import { LangGraphRunnableConfig } from "../pregel/runnable_types.js";
2
3
  import { RunnableCallable } from "../utils.js";
3
4
  import { MessagesAnnotation } from "../graph/messages_annotation.js";
4
- import { RunnableConfig, RunnableToolLike } from "@langchain/core/runnables";
5
+ import { RunnableToolLike } from "@langchain/core/runnables";
5
6
  import { BaseMessage, ToolMessage } from "@langchain/core/messages";
6
7
  import { DynamicTool, StructuredToolInterface } from "@langchain/core/tools";
7
8
  import { ToolCall } from "@langchain/core/messages/tool";
@@ -128,14 +129,65 @@ type ToolNodeOptions = {
128
129
  * }
129
130
  * // Returns the messages in the state at each step of execution
130
131
  * ```
132
+ *
133
+ * ### Accessing graph state and runtime context from tools
134
+ *
135
+ * Tools executed by a `ToolNode` only receive the arguments produced by the
136
+ * model. To give a tool access to the surrounding graph state or other runtime
137
+ * context, read them from the {@link ToolRuntime} that is passed as the
138
+ * second argument to every tool:
139
+ *
140
+ * - `runtime.state` — the input the `ToolNode` was invoked with. When the
141
+ * `ToolNode` runs as a graph node (e.g. inside `createReactAgent`), this is
142
+ * the current graph state. This works in any runtime, including web browsers,
143
+ * because it does not rely on `node:async_hooks`/`AsyncLocalStorage`.
144
+ * - `runtime.config`, `runtime.context`, `runtime.store`, etc. — other
145
+ * run-scoped values.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * import { ToolNode } from "@langchain/langgraph/prebuilt";
150
+ * import { StateGraph, MessagesZodState } from "@langchain/langgraph";
151
+ * import { tool, type ToolRuntime } from "@langchain/core/tools";
152
+ * import { z } from "zod";
153
+ *
154
+ * // Define the graph state with a Zod schema. The extra `userId` key becomes
155
+ * // part of the state that the ToolNode forwards to its tools via `runtime.state`.
156
+ * const AgentState = z.object({
157
+ * ...MessagesZodState.shape,
158
+ * userId: z.string(),
159
+ * });
160
+ *
161
+ * const getUserInfo = tool(
162
+ * async (_input, runtime: ToolRuntime<typeof AgentState>) => {
163
+ * // Read the current graph state directly from the second argument.
164
+ * const userId = runtime.state.userId;
165
+ * return userId === "user_123" ? "User is John Smith" : "Unknown user";
166
+ * },
167
+ * {
168
+ * name: "get_user_info",
169
+ * description: "Look up user info.",
170
+ * schema: z.object({}),
171
+ * }
172
+ * );
173
+ *
174
+ * // Wire the ToolNode into a StateGraph that uses `AgentState`. Because the
175
+ * // node runs with the graph state as its input, the tool can read `userId`.
176
+ * const graph = new StateGraph(AgentState)
177
+ * .addNode("tools", new ToolNode([getUserInfo]))
178
+ * .addEdge("__start__", "tools")
179
+ * .compile();
180
+ *
181
+ * await graph.invoke({ messages: [...], userId: "user_123" });
182
+ * ```
131
183
  */
132
184
  declare class ToolNode<T = any> extends RunnableCallable<T, T> {
133
185
  tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[];
134
186
  handleToolErrors: boolean;
135
187
  trace: boolean;
136
188
  constructor(tools: (StructuredToolInterface | DynamicTool | RunnableToolLike)[], options?: ToolNodeOptions);
137
- protected runTool(call: ToolCall, config: RunnableConfig): Promise<ToolMessage | Command>;
138
- protected run(input: unknown, config: RunnableConfig): Promise<T>;
189
+ protected runTool(call: ToolCall, config: LangGraphRunnableConfig, state: unknown): Promise<ToolMessage | Command>;
190
+ protected run(input: unknown, config: LangGraphRunnableConfig): Promise<T>;
139
191
  }
140
192
  /**
141
193
  * A conditional edge function that determines whether to route to a tools node or end the graph.
@@ -1 +1 @@
1
- {"version":3,"file":"tool_node.d.ts","names":[],"sources":["../../src/prebuilt/tool_node.ts"],"mappings":";;;;;;;;;KAeY,eAAA;EACV,IAAA;EACA,IAAA;EACA,gBAAA;AAAA;;;;;;;AAuIF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4LA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA5La,QAAA,kBAA0B,gBAAA,CAAiB,CAAA,EAAG,CAAA;EACzD,KAAA,GAAQ,uBAAA,GAA0B,WAAA,GAAc,gBAAA;EAEhD,gBAAA;EAEA,KAAA;EAEA,WAAA,CACE,KAAA,GAAQ,uBAAA,GAA0B,WAAA,GAAc,gBAAA,KAChD,OAAA,GAAU,eAAA;EAAA,UAQI,OAAA,CACd,IAAA,EAAM,QAAA,EACN,MAAA,EAAQ,cAAA,GACP,OAAA,CAAQ,WAAA,GAAc,OAAA;EAAA,UA0CT,GAAA,CAAI,KAAA,WAAgB,MAAA,EAAQ,cAAA,GAAiB,OAAA,CAAQ,CAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8HvD,cAAA,CACd,KAAA,EAAO,WAAA,YAAuB,kBAAA,CAAmB,KAAA,oBAC/B,GAAA"}
1
+ {"version":3,"file":"tool_node.d.ts","names":[],"sources":["../../src/prebuilt/tool_node.ts"],"mappings":";;;;;;;;;;KAoBY,eAAA;EACV,IAAA;EACA,IAAA;EACA,gBAAA;AAAA;;;;;;;AA0LF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8MA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA9Ma,QAAA,kBAA0B,gBAAA,CAAiB,CAAA,EAAG,CAAA;EACzD,KAAA,GAAQ,uBAAA,GAA0B,WAAA,GAAc,gBAAA;EAEhD,gBAAA;EAEA,KAAA;EAEA,WAAA,CACE,KAAA,GAAQ,uBAAA,GAA0B,WAAA,GAAc,gBAAA,KAChD,OAAA,GAAU,eAAA;EAAA,UAQI,OAAA,CACd,IAAA,EAAM,QAAA,EACN,MAAA,EAAQ,uBAAA,EACR,KAAA,YACC,OAAA,CAAQ,WAAA,GAAc,OAAA;EAAA,UAoDT,GAAA,CACd,KAAA,WACA,MAAA,EAAQ,uBAAA,GACP,OAAA,CAAQ,CAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkIG,cAAA,CACd,KAAA,EAAO,WAAA,YAAuB,kBAAA,CAAmB,KAAA,oBAC/B,GAAA"}