@langchain/langgraph 1.0.0-alpha.0 → 1.0.0-alpha.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 (191) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/channels/any_value.cjs +46 -0
  3. package/dist/channels/any_value.cjs.map +1 -0
  4. package/dist/channels/any_value.d.cts +0 -2
  5. package/dist/channels/any_value.d.cts.map +1 -1
  6. package/dist/channels/any_value.d.ts +0 -2
  7. package/dist/channels/any_value.d.ts.map +1 -1
  8. package/dist/channels/any_value.js +46 -0
  9. package/dist/channels/any_value.js.map +1 -0
  10. package/dist/channels/base.cjs +3 -7
  11. package/dist/channels/base.cjs.map +1 -1
  12. package/dist/channels/base.d.cts +8 -2
  13. package/dist/channels/base.d.cts.map +1 -1
  14. package/dist/channels/base.d.ts +7 -2
  15. package/dist/channels/base.d.ts.map +1 -1
  16. package/dist/channels/base.js +3 -7
  17. package/dist/channels/base.js.map +1 -1
  18. package/dist/channels/dynamic_barrier_value.cjs +76 -0
  19. package/dist/channels/dynamic_barrier_value.cjs.map +1 -0
  20. package/dist/channels/dynamic_barrier_value.d.cts +0 -1
  21. package/dist/channels/dynamic_barrier_value.d.cts.map +1 -1
  22. package/dist/channels/dynamic_barrier_value.d.ts +0 -1
  23. package/dist/channels/dynamic_barrier_value.d.ts.map +1 -1
  24. package/dist/channels/dynamic_barrier_value.js +76 -0
  25. package/dist/channels/dynamic_barrier_value.js.map +1 -0
  26. package/dist/channels/ephemeral_value.cjs +0 -2
  27. package/dist/channels/ephemeral_value.cjs.map +1 -1
  28. package/dist/channels/ephemeral_value.d.cts +0 -1
  29. package/dist/channels/ephemeral_value.d.cts.map +1 -1
  30. package/dist/channels/ephemeral_value.d.ts +0 -1
  31. package/dist/channels/ephemeral_value.d.ts.map +1 -1
  32. package/dist/channels/ephemeral_value.js +0 -2
  33. package/dist/channels/ephemeral_value.js.map +1 -1
  34. package/dist/channels/index.cjs +19 -0
  35. package/dist/channels/index.d.cts +9 -0
  36. package/dist/channels/index.d.ts +9 -0
  37. package/dist/channels/index.js +7 -1
  38. package/dist/channels/last_value.cjs +0 -1
  39. package/dist/channels/last_value.cjs.map +1 -1
  40. package/dist/channels/last_value.d.cts +14 -2
  41. package/dist/channels/last_value.d.cts.map +1 -1
  42. package/dist/channels/last_value.d.ts +14 -2
  43. package/dist/channels/last_value.d.ts.map +1 -1
  44. package/dist/channels/last_value.js +0 -1
  45. package/dist/channels/last_value.js.map +1 -1
  46. package/dist/channels/named_barrier_value.cjs +1 -1
  47. package/dist/channels/named_barrier_value.cjs.map +1 -1
  48. package/dist/channels/named_barrier_value.d.cts +15 -2
  49. package/dist/channels/named_barrier_value.d.cts.map +1 -1
  50. package/dist/channels/named_barrier_value.d.ts +15 -2
  51. package/dist/channels/named_barrier_value.d.ts.map +1 -1
  52. package/dist/channels/named_barrier_value.js +1 -2
  53. package/dist/channels/named_barrier_value.js.map +1 -1
  54. package/dist/channels/topic.cjs +1 -1
  55. package/dist/channels/topic.cjs.map +1 -1
  56. package/dist/channels/topic.d.cts +7 -1
  57. package/dist/channels/topic.d.cts.map +1 -1
  58. package/dist/channels/topic.d.ts +7 -1
  59. package/dist/channels/topic.d.ts.map +1 -1
  60. package/dist/channels/topic.js +1 -1
  61. package/dist/channels/topic.js.map +1 -1
  62. package/dist/constants.cjs +4 -1
  63. package/dist/constants.cjs.map +1 -1
  64. package/dist/constants.d.cts +5 -4
  65. package/dist/constants.d.cts.map +1 -1
  66. package/dist/constants.d.ts +5 -4
  67. package/dist/constants.d.ts.map +1 -1
  68. package/dist/constants.js +4 -1
  69. package/dist/constants.js.map +1 -1
  70. package/dist/errors.cjs +2 -1
  71. package/dist/errors.cjs.map +1 -1
  72. package/dist/errors.d.cts +2 -1
  73. package/dist/errors.d.cts.map +1 -1
  74. package/dist/errors.d.ts +2 -1
  75. package/dist/errors.d.ts.map +1 -1
  76. package/dist/errors.js +2 -1
  77. package/dist/errors.js.map +1 -1
  78. package/dist/func/index.cjs +3 -0
  79. package/dist/func/index.cjs.map +1 -1
  80. package/dist/func/index.d.cts +5 -1
  81. package/dist/func/index.d.cts.map +1 -1
  82. package/dist/func/index.d.ts +5 -1
  83. package/dist/func/index.d.ts.map +1 -1
  84. package/dist/func/index.js +3 -0
  85. package/dist/func/index.js.map +1 -1
  86. package/dist/graph/annotation.d.cts +1 -1
  87. package/dist/graph/annotation.d.ts +1 -1
  88. package/dist/graph/graph.cjs +5 -5
  89. package/dist/graph/graph.cjs.map +1 -1
  90. package/dist/graph/graph.d.cts +4 -2
  91. package/dist/graph/graph.d.cts.map +1 -1
  92. package/dist/graph/graph.d.ts +4 -2
  93. package/dist/graph/graph.d.ts.map +1 -1
  94. package/dist/graph/graph.js +1 -1
  95. package/dist/graph/graph.js.map +1 -1
  96. package/dist/graph/index.js +1 -1
  97. package/dist/graph/messages_annotation.d.cts +1 -1
  98. package/dist/graph/messages_annotation.d.cts.map +1 -1
  99. package/dist/graph/messages_annotation.d.ts +1 -1
  100. package/dist/graph/state.cjs +15 -18
  101. package/dist/graph/state.cjs.map +1 -1
  102. package/dist/graph/state.d.cts +40 -25
  103. package/dist/graph/state.d.cts.map +1 -1
  104. package/dist/graph/state.d.ts +39 -24
  105. package/dist/graph/state.d.ts.map +1 -1
  106. package/dist/graph/state.js +17 -19
  107. package/dist/graph/state.js.map +1 -1
  108. package/dist/graph/zod/plugin.cjs +1 -1
  109. package/dist/graph/zod/plugin.js +3 -3
  110. package/dist/graph/zod/plugin.js.map +1 -1
  111. package/dist/graph/zod/zod-registry.d.cts.map +1 -1
  112. package/dist/graph/zod/zod-registry.d.ts.map +1 -1
  113. package/dist/index.cjs +3 -2
  114. package/dist/index.cjs.map +1 -1
  115. package/dist/index.d.cts +10 -9
  116. package/dist/index.d.ts +10 -9
  117. package/dist/index.js +4 -3
  118. package/dist/index.js.map +1 -1
  119. package/dist/interrupt.cjs +1 -1
  120. package/dist/interrupt.cjs.map +1 -1
  121. package/dist/interrupt.js +1 -1
  122. package/dist/interrupt.js.map +1 -1
  123. package/dist/prebuilt/agent_executor.d.cts +1 -1
  124. package/dist/prebuilt/agent_executor.d.cts.map +1 -1
  125. package/dist/prebuilt/agent_executor.d.ts +1 -1
  126. package/dist/prebuilt/agent_executor.d.ts.map +1 -1
  127. package/dist/prebuilt/react_agent_executor.cjs +1 -1
  128. package/dist/prebuilt/react_agent_executor.cjs.map +1 -1
  129. package/dist/prebuilt/react_agent_executor.d.cts +5 -5
  130. package/dist/prebuilt/react_agent_executor.d.cts.map +1 -1
  131. package/dist/prebuilt/react_agent_executor.d.ts +4 -4
  132. package/dist/prebuilt/react_agent_executor.d.ts.map +1 -1
  133. package/dist/prebuilt/react_agent_executor.js +1 -1
  134. package/dist/prebuilt/react_agent_executor.js.map +1 -1
  135. package/dist/pregel/algo.cjs +36 -6
  136. package/dist/pregel/algo.cjs.map +1 -1
  137. package/dist/pregel/algo.d.cts +1 -1
  138. package/dist/pregel/algo.d.cts.map +1 -1
  139. package/dist/pregel/algo.d.ts +1 -1
  140. package/dist/pregel/algo.d.ts.map +1 -1
  141. package/dist/pregel/algo.js +37 -7
  142. package/dist/pregel/algo.js.map +1 -1
  143. package/dist/pregel/index.cjs +8 -4
  144. package/dist/pregel/index.cjs.map +1 -1
  145. package/dist/pregel/index.d.cts +8 -6
  146. package/dist/pregel/index.d.cts.map +1 -1
  147. package/dist/pregel/index.d.ts +8 -6
  148. package/dist/pregel/index.d.ts.map +1 -1
  149. package/dist/pregel/index.js +8 -4
  150. package/dist/pregel/index.js.map +1 -1
  151. package/dist/pregel/loop.cjs +7 -4
  152. package/dist/pregel/loop.cjs.map +1 -1
  153. package/dist/pregel/loop.js +7 -4
  154. package/dist/pregel/loop.js.map +1 -1
  155. package/dist/pregel/remote.d.cts +2 -2
  156. package/dist/pregel/remote.d.cts.map +1 -1
  157. package/dist/pregel/remote.d.ts +2 -2
  158. package/dist/pregel/remote.d.ts.map +1 -1
  159. package/dist/pregel/runnable_types.d.cts +34 -10
  160. package/dist/pregel/runnable_types.d.cts.map +1 -1
  161. package/dist/pregel/runnable_types.d.ts +34 -10
  162. package/dist/pregel/runnable_types.d.ts.map +1 -1
  163. package/dist/pregel/stream.cjs +3 -3
  164. package/dist/pregel/stream.cjs.map +1 -1
  165. package/dist/pregel/stream.js +3 -3
  166. package/dist/pregel/stream.js.map +1 -1
  167. package/dist/pregel/types.cjs.map +1 -1
  168. package/dist/pregel/types.d.cts +10 -7
  169. package/dist/pregel/types.d.cts.map +1 -1
  170. package/dist/pregel/types.d.ts +10 -7
  171. package/dist/pregel/types.d.ts.map +1 -1
  172. package/dist/pregel/types.js.map +1 -1
  173. package/dist/pregel/utils/config.cjs +1 -0
  174. package/dist/pregel/utils/config.cjs.map +1 -1
  175. package/dist/pregel/utils/config.js +1 -0
  176. package/dist/pregel/utils/config.js.map +1 -1
  177. package/dist/ui/stream.cjs.map +1 -1
  178. package/dist/ui/stream.js.map +1 -1
  179. package/dist/web.cjs +4 -5
  180. package/dist/web.d.cts +8 -8
  181. package/dist/web.d.ts +8 -8
  182. package/dist/web.js +3 -3
  183. package/dist/writer.cjs +15 -0
  184. package/dist/writer.cjs.map +1 -0
  185. package/dist/writer.d.cts +5 -0
  186. package/dist/writer.d.cts.map +1 -0
  187. package/dist/writer.d.ts +5 -0
  188. package/dist/writer.d.ts.map +1 -0
  189. package/dist/writer.js +14 -0
  190. package/dist/writer.js.map +1 -0
  191. package/package.json +18 -8
@@ -1 +1 @@
1
- {"version":3,"file":"state.js","names":["args","nodeSpec: StateGraphNodeSpec<S, U>","previousNode: N | undefined","name","channels: Record<string, BaseChannel>","outputKeys: string[]","updates: [string, unknown][]","stateWriteEntries: (ChannelWriteTupleEntry | ChannelWriteEntry)[]","writes: (ChannelWriteEntry | Send)[]","input","schema","destinations: (string | Send)[]"],"sources":["../../src/graph/state.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\nimport { _coerceToRunnable, Runnable } from \"@langchain/core/runnables\";\nimport {\n All,\n type BaseCache,\n BaseCheckpointSaver,\n BaseStore,\n} from \"@langchain/langgraph-checkpoint\";\nimport {\n type InteropZodObject,\n interopParse,\n interopZodObjectPartial,\n isInteropZodObject,\n} from \"@langchain/core/utils/types\";\nimport type {\n RunnableLike,\n LangGraphRunnableConfig,\n} from \"../pregel/runnable_types.js\";\nimport { BaseChannel, isBaseChannel } from \"../channels/base.js\";\nimport {\n CompiledGraph,\n Graph,\n Branch,\n AddNodeOptions,\n NodeSpec,\n} from \"./graph.js\";\nimport {\n ChannelWrite,\n ChannelWriteEntry,\n ChannelWriteTupleEntry,\n PASSTHROUGH,\n} from \"../pregel/write.js\";\nimport { ChannelRead, PregelNode } from \"../pregel/read.js\";\nimport {\n NamedBarrierValue,\n NamedBarrierValueAfterFinish,\n} from \"../channels/named_barrier_value.js\";\nimport { EphemeralValue } from \"../channels/ephemeral_value.js\";\nimport { RunnableCallable } from \"../utils.js\";\nimport {\n isCommand,\n _isSend,\n CHECKPOINT_NAMESPACE_END,\n CHECKPOINT_NAMESPACE_SEPARATOR,\n Command,\n END,\n SELF,\n Send,\n START,\n TAG_HIDDEN,\n} from \"../constants.js\";\nimport { InvalidUpdateError, ParentCommand } from \"../errors.js\";\nimport {\n AnnotationRoot,\n getChannel,\n SingleReducer,\n StateDefinition,\n StateType,\n UpdateType,\n} from \"./annotation.js\";\nimport type { CachePolicy, RetryPolicy } from \"../pregel/utils/index.js\";\nimport { isPregelLike } from \"../pregel/utils/subgraph.js\";\nimport { LastValueAfterFinish } from \"../channels/last_value.js\";\nimport {\n type SchemaMetaRegistry,\n InteropZodToStateDefinition,\n schemaMetaRegistry,\n} from \"./zod/meta.js\";\n\nconst ROOT = \"__root__\";\n\nexport type ChannelReducers<Channels extends object> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [K in keyof Channels]: SingleReducer<Channels[K], any>;\n};\n\nexport interface StateGraphArgs<Channels extends object | unknown> {\n channels: Channels extends object\n ? Channels extends unknown[]\n ? ChannelReducers<{ __root__: Channels }>\n : ChannelReducers<Channels>\n : ChannelReducers<{ __root__: Channels }>;\n}\n\nexport type StateGraphNodeSpec<RunInput, RunOutput> = NodeSpec<\n RunInput,\n RunOutput\n> & {\n input?: StateDefinition;\n retryPolicy?: RetryPolicy;\n cachePolicy?: CachePolicy;\n};\n\nexport type StateGraphAddNodeOptions<Nodes extends string = string> = {\n retryPolicy?: RetryPolicy;\n cachePolicy?: CachePolicy | boolean;\n // TODO: Fix generic typing for annotations\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n input?: AnnotationRoot<any> | InteropZodObject;\n} & AddNodeOptions<Nodes>;\n\nexport type StateGraphArgsWithStateSchema<\n SD extends StateDefinition,\n I extends StateDefinition,\n O extends StateDefinition\n> = {\n stateSchema: AnnotationRoot<SD>;\n input?: AnnotationRoot<I>;\n output?: AnnotationRoot<O>;\n};\n\nexport type StateGraphArgsWithInputOutputSchemas<\n SD extends StateDefinition,\n O extends StateDefinition = SD\n> = {\n input: AnnotationRoot<SD>;\n output: AnnotationRoot<O>;\n};\n\ntype ZodStateGraphArgsWithStateSchema<\n SD extends InteropZodObject,\n I extends SDZod,\n O extends SDZod\n> = { state: SD; input?: I; output?: O };\n\ntype SDZod = StateDefinition | InteropZodObject;\n\ntype ToStateDefinition<T> = T extends InteropZodObject\n ? InteropZodToStateDefinition<T>\n : T extends StateDefinition\n ? T\n : never;\n\ntype NodeAction<S, U, C extends SDZod> = RunnableLike<\n S,\n U extends object ? U & Record<string, any> : U, // eslint-disable-line @typescript-eslint/no-explicit-any\n LangGraphRunnableConfig<StateType<ToStateDefinition<C>>>\n>;\n\nconst PartialStateSchema = Symbol.for(\"langgraph.state.partial\");\ntype PartialStateSchema = typeof PartialStateSchema;\n\ntype MergeReturnType<Prev, Curr> = Prev & Curr extends infer T\n ? { [K in keyof T]: T[K] } & unknown\n : never;\n\ntype Prettify<T> = {\n [K in keyof T]: T[K];\n // eslint-disable-next-line @typescript-eslint/ban-types\n} & {};\n\n/**\n * A graph whose nodes communicate by reading and writing to a shared state.\n * Each node takes a defined `State` as input and returns a `Partial<State>`.\n *\n * Each state key can optionally be annotated with a reducer function that\n * will be used to aggregate the values of that key received from multiple nodes.\n * The signature of a reducer function is (left: Value, right: UpdateValue) => Value.\n *\n * See {@link Annotation} for more on defining state.\n *\n * After adding nodes and edges to your graph, you must call `.compile()` on it before\n * you can use it.\n *\n * @example\n * ```ts\n * import {\n * type BaseMessage,\n * AIMessage,\n * HumanMessage,\n * } from \"@langchain/core/messages\";\n * import { StateGraph, Annotation } from \"@langchain/langgraph\";\n *\n * // Define a state with a single key named \"messages\" that will\n * // combine a returned BaseMessage or arrays of BaseMessages\n * const StateAnnotation = Annotation.Root({\n * sentiment: Annotation<string>,\n * messages: Annotation<BaseMessage[]>({\n * reducer: (left: BaseMessage[], right: BaseMessage | BaseMessage[]) => {\n * if (Array.isArray(right)) {\n * return left.concat(right);\n * }\n * return left.concat([right]);\n * },\n * default: () => [],\n * }),\n * });\n *\n * const graphBuilder = new StateGraph(StateAnnotation);\n *\n * // A node in the graph that returns an object with a \"messages\" key\n * // will update the state by combining the existing value with the returned one.\n * const myNode = (state: typeof StateAnnotation.State) => {\n * return {\n * messages: [new AIMessage(\"Some new response\")],\n * sentiment: \"positive\",\n * };\n * };\n *\n * const graph = graphBuilder\n * .addNode(\"myNode\", myNode)\n * .addEdge(\"__start__\", \"myNode\")\n * .addEdge(\"myNode\", \"__end__\")\n * .compile();\n *\n * await graph.invoke({ messages: [new HumanMessage(\"how are you?\")] });\n *\n * // {\n * // messages: [HumanMessage(\"how are you?\"), AIMessage(\"Some new response\")],\n * // sentiment: \"positive\",\n * // }\n * ```\n */\nexport class StateGraph<\n SD extends SDZod | unknown,\n S = SD extends SDZod ? StateType<ToStateDefinition<SD>> : SD,\n U = SD extends SDZod ? UpdateType<ToStateDefinition<SD>> : Partial<S>,\n N extends string = typeof START,\n I extends SDZod = SD extends SDZod ? ToStateDefinition<SD> : StateDefinition,\n O extends SDZod = SD extends SDZod ? ToStateDefinition<SD> : StateDefinition,\n C extends SDZod = StateDefinition,\n NodeReturnType = unknown\n> extends Graph<N, S, U, StateGraphNodeSpec<S, U>, ToStateDefinition<C>> {\n channels: Record<string, BaseChannel> = {};\n\n // TODO: this doesn't dedupe edges as in py, so worth fixing at some point\n waitingEdges: Set<[N[], N]> = new Set();\n\n /** @internal */\n _schemaDefinition: StateDefinition;\n\n /** @internal */\n _schemaRuntimeDefinition: InteropZodObject | undefined;\n\n /** @internal */\n _inputDefinition: I;\n\n /** @internal */\n _inputRuntimeDefinition: InteropZodObject | PartialStateSchema | undefined;\n\n /** @internal */\n _outputDefinition: O;\n\n /** @internal */\n _outputRuntimeDefinition: InteropZodObject | undefined;\n\n /**\n * Map schemas to managed values\n * @internal\n */\n _schemaDefinitions = new Map();\n\n /** @internal */\n _metaRegistry: SchemaMetaRegistry = schemaMetaRegistry;\n\n /** @internal Used only for typing. */\n _configSchema: ToStateDefinition<C> | undefined;\n\n /** @internal */\n _configRuntimeSchema: InteropZodObject | undefined;\n\n constructor(\n fields: SD extends StateDefinition\n ? StateGraphArgsWithInputOutputSchemas<SD, ToStateDefinition<O>>\n : never,\n contextSchema?: C | AnnotationRoot<ToStateDefinition<C>>\n );\n\n constructor(\n fields: SD extends StateDefinition\n ?\n | AnnotationRoot<SD>\n | StateGraphArgsWithStateSchema<\n SD,\n ToStateDefinition<I>,\n ToStateDefinition<O>\n >\n : never,\n contextSchema?: C | AnnotationRoot<ToStateDefinition<C>>\n );\n\n /** @deprecated Use `Annotation.Root` or `zod` for state definition instead. */\n constructor(\n fields: SD extends StateDefinition\n ? SD | StateGraphArgs<S>\n : StateGraphArgs<S>,\n contextSchema?: C | AnnotationRoot<ToStateDefinition<C>>\n );\n\n constructor(\n fields: SD extends InteropZodObject\n ? SD | ZodStateGraphArgsWithStateSchema<SD, I, O>\n : never,\n contextSchema?: C | AnnotationRoot<ToStateDefinition<C>>\n );\n\n constructor(\n fields: SD extends InteropZodObject\n ? SD | ZodStateGraphArgsWithStateSchema<SD, I, O>\n : SD extends StateDefinition\n ?\n | SD\n | AnnotationRoot<SD>\n | StateGraphArgs<S>\n | StateGraphArgsWithStateSchema<\n SD,\n ToStateDefinition<I>,\n ToStateDefinition<O>\n >\n | StateGraphArgsWithInputOutputSchemas<SD, ToStateDefinition<O>>\n : StateGraphArgs<S>,\n contextSchema?: C | AnnotationRoot<ToStateDefinition<C>>\n ) {\n super();\n\n if (isZodStateGraphArgsWithStateSchema(fields)) {\n const stateDef = this._metaRegistry.getChannelsForSchema(fields.state);\n const inputDef =\n fields.input != null\n ? this._metaRegistry.getChannelsForSchema(fields.input)\n : stateDef;\n const outputDef =\n fields.output != null\n ? this._metaRegistry.getChannelsForSchema(fields.output)\n : stateDef;\n\n this._schemaDefinition = stateDef;\n this._schemaRuntimeDefinition = fields.state;\n\n this._inputDefinition = inputDef as I;\n this._inputRuntimeDefinition = fields.input ?? PartialStateSchema;\n\n this._outputDefinition = outputDef as O;\n this._outputRuntimeDefinition = fields.output ?? fields.state;\n } else if (isInteropZodObject(fields)) {\n const stateDef = this._metaRegistry.getChannelsForSchema(fields);\n\n this._schemaDefinition = stateDef;\n this._schemaRuntimeDefinition = fields;\n\n this._inputDefinition = stateDef as I;\n this._inputRuntimeDefinition = PartialStateSchema;\n\n this._outputDefinition = stateDef as O;\n this._outputRuntimeDefinition = fields;\n } else if (\n isStateGraphArgsWithInputOutputSchemas<\n SD extends StateDefinition ? SD : never,\n O extends StateDefinition ? O : never\n >(fields)\n ) {\n this._schemaDefinition = fields.input.spec;\n this._inputDefinition = fields.input.spec as unknown as I;\n this._outputDefinition = fields.output.spec;\n } else if (isStateGraphArgsWithStateSchema(fields)) {\n this._schemaDefinition = fields.stateSchema.spec;\n this._inputDefinition = (fields.input?.spec ??\n this._schemaDefinition) as I;\n this._outputDefinition = (fields.output?.spec ??\n this._schemaDefinition) as O;\n } else if (isStateDefinition(fields) || isAnnotationRoot(fields)) {\n const spec = isAnnotationRoot(fields) ? fields.spec : fields;\n this._schemaDefinition = spec;\n } else if (isStateGraphArgs(fields)) {\n const spec = _getChannels(fields.channels);\n this._schemaDefinition = spec;\n } else {\n throw new Error(\n \"Invalid StateGraph input. Make sure to pass a valid Annotation.Root or Zod schema.\"\n );\n }\n\n this._inputDefinition ??= this._schemaDefinition as I;\n this._outputDefinition ??= this._schemaDefinition as O;\n\n this._addSchema(this._schemaDefinition);\n this._addSchema(this._inputDefinition);\n this._addSchema(this._outputDefinition);\n\n if (isInteropZodObject(contextSchema)) {\n this._configRuntimeSchema = contextSchema;\n }\n }\n\n get allEdges(): Set<[string, string]> {\n return new Set([\n ...this.edges,\n ...Array.from(this.waitingEdges).flatMap(([starts, end]) =>\n starts.map((start) => [start, end] as [string, string])\n ),\n ]);\n }\n\n _addSchema(stateDefinition: SDZod) {\n if (this._schemaDefinitions.has(stateDefinition)) {\n return;\n }\n // TODO: Support managed values\n this._schemaDefinitions.set(stateDefinition, stateDefinition);\n for (const [key, val] of Object.entries(stateDefinition)) {\n let channel;\n if (typeof val === \"function\") {\n channel = val();\n } else {\n channel = val;\n }\n if (this.channels[key] !== undefined) {\n if (this.channels[key] !== channel) {\n if (channel.lc_graph_name !== \"LastValue\") {\n throw new Error(\n `Channel \"${key}\" already exists with a different type.`\n );\n }\n }\n } else {\n this.channels[key] = channel;\n }\n }\n }\n\n override addNode<\n K extends string,\n NodeMap extends Record<K, NodeAction<S, U, C>>\n >(\n nodes: NodeMap\n ): StateGraph<\n SD,\n S,\n U,\n N | K,\n I,\n O,\n C,\n MergeReturnType<\n NodeReturnType,\n {\n [key in keyof NodeMap]: NodeMap[key] extends NodeAction<S, infer U, C>\n ? U\n : never;\n }\n >\n >;\n\n override addNode<K extends string, NodeInput = S, NodeOutput extends U = U>(\n nodes:\n | [\n key: K,\n action: NodeAction<NodeInput, NodeOutput, C>,\n options?: StateGraphAddNodeOptions\n ][]\n ): StateGraph<\n SD,\n S,\n U,\n N | K,\n I,\n O,\n C,\n MergeReturnType<NodeReturnType, { [key in K]: NodeOutput }>\n >;\n\n override addNode<K extends string, NodeInput = S, NodeOutput extends U = U>(\n key: K,\n action: NodeAction<NodeInput, NodeOutput, C>,\n options?: StateGraphAddNodeOptions\n ): StateGraph<\n SD,\n S,\n U,\n N | K,\n I,\n O,\n C,\n MergeReturnType<NodeReturnType, { [key in K]: NodeOutput }>\n >;\n\n override addNode<K extends string, NodeInput = S>(\n key: K,\n action: NodeAction<NodeInput, U, C>,\n options?: StateGraphAddNodeOptions\n ): StateGraph<SD, S, U, N | K, I, O, C, NodeReturnType>;\n\n override addNode<K extends string, NodeInput = S, NodeOutput extends U = U>(\n ...args:\n | [\n key: K,\n action: NodeAction<NodeInput, NodeOutput, C>,\n options?: StateGraphAddNodeOptions\n ]\n | [\n nodes:\n | Record<K, NodeAction<NodeInput, U, C>>\n | [\n key: K,\n action: NodeAction<NodeInput, U, C>,\n options?: StateGraphAddNodeOptions\n ][]\n ]\n ): StateGraph<SD, S, U, N | K, I, O, C> {\n function isMultipleNodes(\n args: unknown[]\n ): args is [\n nodes:\n | Record<K, NodeAction<NodeInput, U, C>>\n | [\n key: K,\n action: NodeAction<NodeInput, U, C>,\n options?: AddNodeOptions\n ][]\n ] {\n return args.length >= 1 && typeof args[0] !== \"string\";\n }\n\n const nodes = (\n isMultipleNodes(args) // eslint-disable-line no-nested-ternary\n ? Array.isArray(args[0])\n ? args[0]\n : Object.entries(args[0]).map(([key, action]) => [\n key,\n action,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (action as any)[Symbol.for(\"langgraph.state.node\")] ?? undefined,\n ])\n : [[args[0], args[1], args[2]]]\n ) as [\n K,\n NodeAction<NodeInput, U, C>,\n StateGraphAddNodeOptions | undefined\n ][];\n\n if (nodes.length === 0) {\n throw new Error(\"No nodes provided in `addNode`\");\n }\n\n for (const [key, action, options] of nodes) {\n if (key in this.channels) {\n throw new Error(\n `${key} is already being used as a state attribute (a.k.a. a channel), cannot also be used as a node name.`\n );\n }\n\n for (const reservedChar of [\n CHECKPOINT_NAMESPACE_SEPARATOR,\n CHECKPOINT_NAMESPACE_END,\n ]) {\n if (key.includes(reservedChar)) {\n throw new Error(\n `\"${reservedChar}\" is a reserved character and is not allowed in node names.`\n );\n }\n }\n this.warnIfCompiled(\n `Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`\n );\n\n if (key in this.nodes) {\n throw new Error(`Node \\`${key}\\` already present.`);\n }\n if (key === END || key === START) {\n throw new Error(`Node \\`${key}\\` is reserved.`);\n }\n\n let inputSpec = this._schemaDefinition;\n if (options?.input !== undefined) {\n if (isInteropZodObject(options.input)) {\n inputSpec = this._metaRegistry.getChannelsForSchema(options.input);\n } else if (options.input.spec !== undefined) {\n inputSpec = options.input.spec;\n }\n }\n if (inputSpec !== undefined) {\n this._addSchema(inputSpec);\n }\n\n let runnable;\n if (Runnable.isRunnable(action)) {\n runnable = action;\n } else if (typeof action === \"function\") {\n runnable = new RunnableCallable({\n func: action,\n name: key,\n trace: false,\n });\n } else {\n runnable = _coerceToRunnable(action);\n }\n\n let cachePolicy = options?.cachePolicy;\n if (typeof cachePolicy === \"boolean\") {\n cachePolicy = cachePolicy ? {} : undefined;\n }\n\n const nodeSpec: StateGraphNodeSpec<S, U> = {\n runnable: runnable as unknown as Runnable<S, U>,\n retryPolicy: options?.retryPolicy,\n cachePolicy,\n metadata: options?.metadata,\n input: inputSpec ?? this._schemaDefinition,\n subgraphs: isPregelLike(runnable)\n ? // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [runnable as any]\n : options?.subgraphs,\n ends: options?.ends,\n defer: options?.defer,\n };\n\n this.nodes[key as unknown as N] = nodeSpec;\n }\n\n return this as StateGraph<SD, S, U, N | K, I, O, C>;\n }\n\n override addEdge(\n startKey: typeof START | N | N[],\n endKey: N | typeof END\n ): this {\n if (typeof startKey === \"string\") {\n return super.addEdge(startKey, endKey);\n }\n\n if (this.compiled) {\n console.warn(\n \"Adding an edge to a graph that has already been compiled. This will \" +\n \"not be reflected in the compiled graph.\"\n );\n }\n\n for (const start of startKey) {\n if (start === END) {\n throw new Error(\"END cannot be a start node\");\n }\n if (!Object.keys(this.nodes).some((node) => node === start)) {\n throw new Error(`Need to add a node named \"${start}\" first`);\n }\n }\n if (endKey === END) {\n throw new Error(\"END cannot be an end node\");\n }\n if (!Object.keys(this.nodes).some((node) => node === endKey)) {\n throw new Error(`Need to add a node named \"${endKey}\" first`);\n }\n\n this.waitingEdges.add([startKey, endKey]);\n\n return this;\n }\n\n addSequence<K extends string, NodeInput = S, NodeOutput extends U = U>(\n nodes: [\n key: K,\n action: NodeAction<NodeInput, NodeOutput, C>,\n options?: StateGraphAddNodeOptions\n ][]\n ): StateGraph<\n SD,\n S,\n U,\n N | K,\n I,\n O,\n C,\n MergeReturnType<NodeReturnType, { [key in K]: NodeOutput }>\n >;\n\n addSequence<K extends string, NodeMap extends Record<K, NodeAction<S, U, C>>>(\n nodes: NodeMap\n ): StateGraph<\n SD,\n S,\n U,\n N | K,\n I,\n O,\n C,\n MergeReturnType<\n NodeReturnType,\n {\n [key in keyof NodeMap]: NodeMap[key] extends NodeAction<S, infer U, C>\n ? U\n : never;\n }\n >\n >;\n\n addSequence<K extends string, NodeInput = S, NodeOutput extends U = U>(\n nodes:\n | [\n key: K,\n action: NodeAction<NodeInput, NodeOutput, C>,\n options?: StateGraphAddNodeOptions\n ][]\n | Record<K, NodeAction<NodeInput, NodeOutput, C>>\n ): StateGraph<\n SD,\n S,\n U,\n N | K,\n I,\n O,\n C,\n MergeReturnType<NodeReturnType, { [key in K]: NodeOutput }>\n > {\n const parsedNodes = Array.isArray(nodes)\n ? nodes\n : (Object.entries(nodes).map(([key, action]) => [\n key,\n action,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (action as any)[Symbol.for(\"langgraph.state.node\")] ?? undefined,\n ]) as [K, NodeAction<S, U, C>, StateGraphAddNodeOptions | undefined][]);\n\n if (parsedNodes.length === 0) {\n throw new Error(\"Sequence requires at least one node.\");\n }\n\n let previousNode: N | undefined;\n for (const [key, action, options] of parsedNodes) {\n if (key in this.nodes) {\n throw new Error(\n `Node names must be unique: node with the name \"${key}\" already exists.`\n );\n }\n\n const validKey = key as unknown as N;\n this.addNode(validKey, action as NodeAction<S, U, C>, options);\n if (previousNode != null) {\n this.addEdge(previousNode, validKey);\n }\n\n previousNode = validKey;\n }\n\n return this as StateGraph<\n SD,\n S,\n U,\n N | K,\n I,\n O,\n C,\n MergeReturnType<NodeReturnType, { [key in K]: NodeOutput }>\n >;\n }\n\n override compile({\n checkpointer,\n store,\n cache,\n interruptBefore,\n interruptAfter,\n name,\n description,\n }: {\n checkpointer?: BaseCheckpointSaver | boolean;\n store?: BaseStore;\n cache?: BaseCache;\n interruptBefore?: N[] | All;\n interruptAfter?: N[] | All;\n name?: string;\n description?: string;\n } = {}): CompiledStateGraph<\n Prettify<S>,\n Prettify<U>,\n N,\n I,\n O,\n C,\n NodeReturnType\n > {\n // validate the graph\n this.validate([\n ...(Array.isArray(interruptBefore) ? interruptBefore : []),\n ...(Array.isArray(interruptAfter) ? interruptAfter : []),\n ]);\n\n // prepare output channels\n const outputKeys = Object.keys(\n this._schemaDefinitions.get(this._outputDefinition)\n );\n const outputChannels =\n outputKeys.length === 1 && outputKeys[0] === ROOT ? ROOT : outputKeys;\n\n const streamKeys = Object.keys(this.channels);\n const streamChannels =\n streamKeys.length === 1 && streamKeys[0] === ROOT ? ROOT : streamKeys;\n\n // create empty compiled graph\n const compiled = new CompiledStateGraph<S, U, N, I, O, C, NodeReturnType>({\n builder: this,\n checkpointer,\n interruptAfter,\n interruptBefore,\n autoValidate: false,\n nodes: {} as Record<N | typeof START, PregelNode<S, U>>,\n channels: {\n ...this.channels,\n [START]: new EphemeralValue(),\n } as Record<N | typeof START | typeof END | string, BaseChannel>,\n inputChannels: START,\n outputChannels,\n streamChannels,\n streamMode: \"updates\",\n store,\n cache,\n name,\n description,\n });\n\n // attach nodes, edges and branches\n compiled.attachNode(START);\n for (const [key, node] of Object.entries<StateGraphNodeSpec<S, U>>(\n this.nodes\n )) {\n compiled.attachNode(key as N, node);\n }\n compiled.attachBranch(START, SELF, _getControlBranch() as Branch<S, N>, {\n withReader: false,\n });\n for (const [key] of Object.entries<StateGraphNodeSpec<S, U>>(this.nodes)) {\n compiled.attachBranch(\n key as N,\n SELF,\n _getControlBranch() as Branch<S, N>,\n {\n withReader: false,\n }\n );\n }\n for (const [start, end] of this.edges) {\n compiled.attachEdge(start, end);\n }\n for (const [starts, end] of this.waitingEdges) {\n compiled.attachEdge(starts, end);\n }\n for (const [start, branches] of Object.entries(this.branches)) {\n for (const [name, branch] of Object.entries(branches)) {\n compiled.attachBranch(start as N, name, branch);\n }\n }\n\n return compiled.validate();\n }\n}\n\nfunction _getChannels<Channels extends Record<string, unknown> | unknown>(\n schema: StateGraphArgs<Channels>[\"channels\"]\n): Record<string, BaseChannel> {\n const channels: Record<string, BaseChannel> = {};\n for (const [name, val] of Object.entries(schema)) {\n if (name === ROOT) {\n channels[name] = getChannel<Channels>(val as SingleReducer<Channels>);\n } else {\n const key = name as keyof Channels;\n channels[name] = getChannel<Channels[typeof key]>(\n val as SingleReducer<Channels[typeof key]>\n );\n }\n }\n return channels;\n}\n\n/**\n * Final result from building and compiling a {@link StateGraph}.\n * Should not be instantiated directly, only using the StateGraph `.compile()`\n * instance method.\n */\nexport class CompiledStateGraph<\n S,\n U,\n N extends string = typeof START,\n I extends SDZod = StateDefinition,\n O extends SDZod = StateDefinition,\n C extends SDZod = StateDefinition,\n NodeReturnType = unknown\n> extends CompiledGraph<\n N,\n S,\n U,\n StateType<ToStateDefinition<C>>,\n UpdateType<ToStateDefinition<I>>,\n StateType<ToStateDefinition<O>>,\n NodeReturnType\n> {\n declare builder: StateGraph<unknown, S, U, N, I, O, C, NodeReturnType>;\n\n /**\n * The description of the compiled graph.\n * This is used by the supervisor agent to describe the handoff to the agent.\n */\n description?: string;\n\n /** @internal */\n _metaRegistry: SchemaMetaRegistry = schemaMetaRegistry;\n\n constructor({\n description,\n ...rest\n }: { description?: string } & ConstructorParameters<\n typeof CompiledGraph<\n N,\n S,\n U,\n StateType<ToStateDefinition<C>>,\n UpdateType<ToStateDefinition<I>>,\n StateType<ToStateDefinition<O>>,\n NodeReturnType\n >\n >[0]) {\n super(rest);\n this.description = description;\n }\n\n attachNode(key: typeof START, node?: never): void;\n\n attachNode(key: N, node: StateGraphNodeSpec<S, U>): void;\n\n attachNode(key: N | typeof START, node?: StateGraphNodeSpec<S, U>): void {\n let outputKeys: string[];\n if (key === START) {\n // Get input schema keys excluding managed values\n outputKeys = Object.entries(\n this.builder._schemaDefinitions.get(this.builder._inputDefinition)\n ).map(([k]) => k);\n } else {\n outputKeys = Object.keys(this.builder.channels);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function _getRoot(input: unknown): [string, any][] | null {\n if (isCommand(input)) {\n if (input.graph === Command.PARENT) {\n return null;\n }\n return input._updateAsTuples();\n } else if (\n Array.isArray(input) &&\n input.length > 0 &&\n input.some((i) => isCommand(i))\n ) {\n const updates: [string, unknown][] = [];\n for (const i of input) {\n if (isCommand(i)) {\n if (i.graph === Command.PARENT) {\n continue;\n }\n updates.push(...i._updateAsTuples());\n } else {\n updates.push([ROOT, i]);\n }\n }\n return updates;\n } else if (input != null) {\n return [[ROOT, input]];\n }\n return null;\n }\n\n // to avoid name collision below\n const nodeKey = key;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function _getUpdates(input: U): [string, any][] | null {\n if (!input) {\n return null;\n } else if (isCommand(input)) {\n if (input.graph === Command.PARENT) {\n return null;\n }\n return input._updateAsTuples().filter(([k]) => outputKeys.includes(k));\n } else if (\n Array.isArray(input) &&\n input.length > 0 &&\n input.some(isCommand)\n ) {\n const updates: [string, unknown][] = [];\n for (const item of input) {\n if (isCommand(item)) {\n if (item.graph === Command.PARENT) {\n continue;\n }\n updates.push(\n ...item._updateAsTuples().filter(([k]) => outputKeys.includes(k))\n );\n } else {\n const itemUpdates = _getUpdates(item);\n if (itemUpdates) {\n updates.push(...(itemUpdates ?? []));\n }\n }\n }\n return updates;\n } else if (typeof input === \"object\" && !Array.isArray(input)) {\n return Object.entries(input).filter(([k]) => outputKeys.includes(k));\n } else {\n const typeofInput = Array.isArray(input) ? \"array\" : typeof input;\n throw new InvalidUpdateError(\n `Expected node \"${nodeKey.toString()}\" to return an object or an array containing at least one Command object, received ${typeofInput}`,\n {\n lc_error_code: \"INVALID_GRAPH_NODE_RETURN_VALUE\",\n }\n );\n }\n }\n\n const stateWriteEntries: (ChannelWriteTupleEntry | ChannelWriteEntry)[] = [\n {\n value: PASSTHROUGH,\n mapper: new RunnableCallable({\n func:\n outputKeys.length && outputKeys[0] === ROOT\n ? _getRoot\n : _getUpdates,\n trace: false,\n recurse: false,\n }),\n },\n ];\n\n // add node and output channel\n if (key === START) {\n this.nodes[key] = new PregelNode<S, U>({\n tags: [TAG_HIDDEN],\n triggers: [START],\n channels: [START],\n writers: [new ChannelWrite(stateWriteEntries, [TAG_HIDDEN])],\n });\n } else {\n const inputDefinition = node?.input ?? this.builder._schemaDefinition;\n const inputValues = Object.fromEntries(\n Object.keys(this.builder._schemaDefinitions.get(inputDefinition)).map(\n (k) => [k, k]\n )\n );\n const isSingleInput =\n Object.keys(inputValues).length === 1 && ROOT in inputValues;\n const branchChannel = `branch:to:${key}` as string | N;\n this.channels[branchChannel] = node?.defer\n ? new LastValueAfterFinish()\n : new EphemeralValue(false);\n this.nodes[key] = new PregelNode<S, U>({\n triggers: [branchChannel],\n // read state keys\n channels: isSingleInput ? Object.keys(inputValues) : inputValues,\n // publish to state keys\n writers: [new ChannelWrite(stateWriteEntries, [TAG_HIDDEN])],\n mapper: isSingleInput\n ? undefined\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (input: Record<string, any>) => {\n return Object.fromEntries(\n Object.entries(input).filter(([k]) => k in inputValues)\n );\n },\n bound: node?.runnable,\n metadata: node?.metadata,\n retryPolicy: node?.retryPolicy,\n cachePolicy: node?.cachePolicy,\n subgraphs: node?.subgraphs,\n ends: node?.ends,\n });\n }\n }\n\n attachEdge(starts: N | N[] | \"__start__\", end: N | \"__end__\"): void {\n if (end === END) return;\n if (typeof starts === \"string\") {\n this.nodes[starts].writers.push(\n new ChannelWrite(\n [{ channel: `branch:to:${end}`, value: null }],\n [TAG_HIDDEN]\n )\n );\n } else if (Array.isArray(starts)) {\n const channelName = `join:${starts.join(\"+\")}:${end}`;\n // register channel\n this.channels[channelName as string | N] = this.builder.nodes[end].defer\n ? new NamedBarrierValueAfterFinish(new Set(starts))\n : new NamedBarrierValue(new Set(starts));\n // subscribe to channel\n this.nodes[end].triggers.push(channelName);\n // publish to channel\n for (const start of starts) {\n this.nodes[start].writers.push(\n new ChannelWrite(\n [{ channel: channelName, value: start }],\n [TAG_HIDDEN]\n )\n );\n }\n }\n }\n\n attachBranch(\n start: N | typeof START,\n _: string,\n branch: Branch<S, N>,\n options: { withReader?: boolean } = { withReader: true }\n ): void {\n const branchWriter = async (\n packets: (string | Send)[],\n config: LangGraphRunnableConfig\n ) => {\n const filteredPackets = packets.filter((p) => p !== END);\n if (!filteredPackets.length) return;\n\n const writes: (ChannelWriteEntry | Send)[] = filteredPackets.map((p) => {\n if (_isSend(p)) return p;\n return { channel: p === END ? p : `branch:to:${p}`, value: start };\n });\n await ChannelWrite.doWrite(\n { ...config, tags: (config.tags ?? []).concat([TAG_HIDDEN]) },\n writes\n );\n };\n // attach branch publisher\n this.nodes[start].writers.push(\n branch.run(\n branchWriter,\n // reader\n options.withReader\n ? (config) =>\n ChannelRead.doRead<S>(\n config,\n this.streamChannels ?? this.outputChannels,\n true\n )\n : undefined\n )\n );\n }\n\n protected async _validateInput(\n input: UpdateType<ToStateDefinition<I>>\n ): Promise<UpdateType<ToStateDefinition<I>>> {\n if (input == null) return input;\n\n const schema = (() => {\n const input = this.builder._inputRuntimeDefinition;\n const schema = this.builder._schemaRuntimeDefinition;\n\n const apply = (schema: InteropZodObject | undefined) => {\n if (schema == null) return undefined;\n return this._metaRegistry.getExtendedChannelSchemas(schema, {\n withReducerSchema: true,\n });\n };\n\n if (isInteropZodObject(input)) return apply(input);\n if (input === PartialStateSchema) {\n return interopZodObjectPartial(apply(schema)!);\n }\n return undefined;\n })();\n\n if (isCommand(input)) {\n const parsedInput = input;\n if (input.update && schema != null)\n parsedInput.update = interopParse(schema, input.update);\n return parsedInput;\n }\n if (schema != null) return interopParse(schema, input);\n return input;\n }\n\n protected async _validateContext(\n config: Partial<Record<string, unknown>>\n ): Promise<Partial<Record<string, unknown>>> {\n const configSchema = this.builder._configRuntimeSchema;\n if (isInteropZodObject(configSchema)) interopParse(configSchema, config);\n return config;\n }\n}\n\nfunction isStateDefinition(obj: unknown): obj is StateDefinition {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n !Array.isArray(obj) &&\n Object.keys(obj).length > 0 &&\n Object.values(obj).every((v) => typeof v === \"function\" || isBaseChannel(v))\n );\n}\n\nfunction isAnnotationRoot<SD extends StateDefinition>(\n obj: unknown | AnnotationRoot<SD>\n): obj is AnnotationRoot<SD> {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n \"lc_graph_name\" in obj &&\n obj.lc_graph_name === \"AnnotationRoot\"\n );\n}\n\nfunction isStateGraphArgs<Channels extends object | unknown>(\n obj: unknown | StateGraphArgs<Channels>\n): obj is StateGraphArgs<Channels> {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n (obj as StateGraphArgs<Channels>).channels !== undefined\n );\n}\n\nfunction isStateGraphArgsWithStateSchema<\n SD extends StateDefinition,\n I extends StateDefinition,\n O extends StateDefinition\n>(\n obj: unknown | StateGraphArgsWithStateSchema<SD, I, O>\n): obj is StateGraphArgsWithStateSchema<SD, I, O> {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n (obj as StateGraphArgsWithStateSchema<SD, I, O>).stateSchema !== undefined\n );\n}\n\nfunction isStateGraphArgsWithInputOutputSchemas<\n SD extends StateDefinition,\n O extends StateDefinition\n>(\n obj: unknown | StateGraphArgsWithInputOutputSchemas<SD, O>\n): obj is StateGraphArgsWithInputOutputSchemas<SD, O> {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (obj as any).stateSchema === undefined &&\n (obj as StateGraphArgsWithInputOutputSchemas<SD, O>).input !== undefined &&\n (obj as StateGraphArgsWithInputOutputSchemas<SD, O>).output !== undefined\n );\n}\n\nfunction isZodStateGraphArgsWithStateSchema<\n SD extends InteropZodObject,\n I extends InteropZodObject,\n O extends InteropZodObject\n>(value: unknown): value is ZodStateGraphArgsWithStateSchema<SD, I, O> {\n if (typeof value !== \"object\" || value == null) {\n return false;\n }\n\n if (!(\"state\" in value) || !isInteropZodObject(value.state)) {\n return false;\n }\n\n if (\"input\" in value && !isInteropZodObject(value.input)) {\n return false;\n }\n\n if (\"output\" in value && !isInteropZodObject(value.output)) {\n return false;\n }\n\n return true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction _controlBranch(value: any): (string | Send)[] {\n if (_isSend(value)) {\n return [value];\n }\n const commands = [];\n if (isCommand(value)) {\n commands.push(value);\n } else if (Array.isArray(value)) {\n commands.push(...value.filter(isCommand));\n }\n const destinations: (string | Send)[] = [];\n\n for (const command of commands) {\n if (command.graph === Command.PARENT) {\n throw new ParentCommand(command);\n }\n\n if (_isSend(command.goto)) {\n destinations.push(command.goto);\n } else if (typeof command.goto === \"string\") {\n destinations.push(command.goto);\n } else {\n if (Array.isArray(command.goto)) {\n destinations.push(...command.goto);\n }\n }\n }\n return destinations;\n}\n\nfunction _getControlBranch() {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const CONTROL_BRANCH_PATH = new RunnableCallable<any, (string | Send)[]>({\n func: _controlBranch,\n tags: [TAG_HIDDEN],\n trace: false,\n recurse: false,\n name: \"<control_branch>\",\n });\n return new Branch({\n path: CONTROL_BRANCH_PATH,\n });\n}\n\ntype TypedNodeAction<\n SD extends StateDefinition,\n Nodes extends string,\n C extends StateDefinition = StateDefinition\n> = RunnableLike<\n StateType<SD>,\n UpdateType<SD> | Command<unknown, UpdateType<SD>, Nodes>,\n LangGraphRunnableConfig<StateType<C>>\n>;\n\nexport function typedNode<\n SD extends SDZod,\n Nodes extends string,\n C extends SDZod = StateDefinition\n>(\n _state: SD extends StateDefinition ? AnnotationRoot<SD> : never,\n _options?: {\n nodes?: Nodes[];\n config?: C extends StateDefinition ? AnnotationRoot<C> : never;\n }\n): (\n func: TypedNodeAction<ToStateDefinition<SD>, Nodes, ToStateDefinition<C>>,\n options?: StateGraphAddNodeOptions<Nodes>\n) => TypedNodeAction<ToStateDefinition<SD>, Nodes, ToStateDefinition<C>>;\n\nexport function typedNode<\n SD extends SDZod,\n Nodes extends string,\n C extends SDZod = StateDefinition\n>(\n _state: SD extends InteropZodObject ? SD : never,\n _options?: {\n nodes?: Nodes[];\n config?: C extends InteropZodObject ? C : never;\n }\n): (\n func: TypedNodeAction<ToStateDefinition<SD>, Nodes, ToStateDefinition<C>>,\n options?: StateGraphAddNodeOptions<Nodes>\n) => TypedNodeAction<ToStateDefinition<SD>, Nodes, ToStateDefinition<C>>;\n\nexport function typedNode<\n SD extends SDZod,\n Nodes extends string,\n C extends SDZod = StateDefinition\n>(\n _state: SD extends InteropZodObject\n ? SD\n : SD extends StateDefinition\n ? AnnotationRoot<SD>\n : never,\n _options?: { nodes?: Nodes[]; config?: AnnotationRoot<ToStateDefinition<C>> }\n) {\n return (\n func: TypedNodeAction<ToStateDefinition<SD>, Nodes, ToStateDefinition<C>>,\n options?: StateGraphAddNodeOptions<Nodes>\n ) => {\n Object.assign(func, { [Symbol.for(\"langgraph.state.node\")]: options });\n return func;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqEA,MAAM,OAAO;AAsEb,MAAM,qBAAqB,OAAO,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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SAAgB,UAKd,QAKA,UACA;AACA,SACE,MACA,YACG;AACH,SAAO,OAAO,MAAM,GAAG,OAAO,IAAI,0BAA0B;AAC5D,SAAO"}
1
+ {"version":3,"file":"state.js","names":["args","nodeSpec: StateGraphNodeSpec<S, U>","previousNode: N | undefined","name","channels: Record<string, BaseChannel>","outputKeys: string[]","updates: [string, unknown][]","stateWriteEntries: (ChannelWriteTupleEntry | ChannelWriteEntry)[]","writes: (ChannelWriteEntry | Send)[]","input","schema","destinations: (string | Send)[]"],"sources":["../../src/graph/state.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\nimport { _coerceToRunnable, Runnable } from \"@langchain/core/runnables\";\nimport {\n All,\n type BaseCache,\n BaseCheckpointSaver,\n BaseStore,\n} from \"@langchain/langgraph-checkpoint\";\nimport {\n type InteropZodObject,\n interopParse,\n interopZodObjectPartial,\n isInteropZodObject,\n} from \"@langchain/core/utils/types\";\nimport type {\n RunnableLike,\n LangGraphRunnableConfig,\n Runtime,\n} from \"../pregel/runnable_types.js\";\nimport { BaseChannel, isBaseChannel } from \"../channels/base.js\";\nimport {\n CompiledGraph,\n Graph,\n Branch,\n AddNodeOptions,\n NodeSpec,\n} from \"./graph.js\";\nimport {\n ChannelWrite,\n ChannelWriteEntry,\n ChannelWriteTupleEntry,\n PASSTHROUGH,\n} from \"../pregel/write.js\";\nimport { ChannelRead, PregelNode } from \"../pregel/read.js\";\nimport {\n NamedBarrierValue,\n NamedBarrierValueAfterFinish,\n} from \"../channels/named_barrier_value.js\";\nimport { EphemeralValue } from \"../channels/ephemeral_value.js\";\nimport { RunnableCallable } from \"../utils.js\";\nimport {\n isCommand,\n _isSend,\n CHECKPOINT_NAMESPACE_END,\n CHECKPOINT_NAMESPACE_SEPARATOR,\n Command,\n END,\n SELF,\n Send,\n START,\n TAG_HIDDEN,\n CommandInstance,\n isInterrupted,\n Interrupt,\n INTERRUPT,\n} from \"../constants.js\";\nimport { InvalidUpdateError, ParentCommand } from \"../errors.js\";\nimport {\n AnnotationRoot,\n getChannel,\n SingleReducer,\n StateDefinition,\n StateType,\n UpdateType,\n} from \"./annotation.js\";\nimport type { CachePolicy, RetryPolicy } from \"../pregel/utils/index.js\";\nimport { isPregelLike } from \"../pregel/utils/subgraph.js\";\nimport { LastValueAfterFinish } from \"../channels/last_value.js\";\nimport {\n type SchemaMetaRegistry,\n InteropZodToStateDefinition,\n schemaMetaRegistry,\n} from \"./zod/meta.js\";\nimport { interrupt } from \"../interrupt.js\";\nimport { writer } from \"../writer.js\";\n\nconst ROOT = \"__root__\";\n\nexport type ChannelReducers<Channels extends object> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [K in keyof Channels]: SingleReducer<Channels[K], any>;\n};\n\nexport interface StateGraphArgs<Channels extends object | unknown> {\n channels: Channels extends object\n ? Channels extends unknown[]\n ? ChannelReducers<{ __root__: Channels }>\n : ChannelReducers<Channels>\n : ChannelReducers<{ __root__: Channels }>;\n}\n\nexport type StateGraphNodeSpec<RunInput, RunOutput> = NodeSpec<\n RunInput,\n RunOutput\n> & {\n input?: StateDefinition;\n retryPolicy?: RetryPolicy;\n cachePolicy?: CachePolicy;\n};\n\nexport type StateGraphAddNodeOptions<Nodes extends string = string> = {\n retryPolicy?: RetryPolicy;\n cachePolicy?: CachePolicy | boolean;\n // TODO: Fix generic typing for annotations\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n input?: AnnotationRoot<any> | InteropZodObject;\n} & AddNodeOptions<Nodes>;\n\nexport type StateGraphArgsWithStateSchema<\n SD extends StateDefinition,\n I extends StateDefinition,\n O extends StateDefinition\n> = {\n stateSchema: AnnotationRoot<SD>;\n input?: AnnotationRoot<I>;\n output?: AnnotationRoot<O>;\n};\n\nexport type StateGraphArgsWithInputOutputSchemas<\n SD extends StateDefinition,\n O extends StateDefinition = SD\n> = {\n input: AnnotationRoot<SD>;\n output: AnnotationRoot<O>;\n};\n\ntype ZodStateGraphArgsWithStateSchema<\n SD extends InteropZodObject,\n I extends SDZod,\n O extends SDZod\n> = { state: SD; input?: I; output?: O };\n\ntype SDZod = StateDefinition | InteropZodObject;\n\ntype ToStateDefinition<T> = T extends InteropZodObject\n ? InteropZodToStateDefinition<T>\n : T extends StateDefinition\n ? T\n : never;\n\ntype InterruptResumeType<T> = T extends typeof interrupt<unknown, infer R>\n ? R\n : unknown;\n\ntype InterruptInputType<T> = T extends typeof interrupt<infer I, unknown>\n ? I\n : unknown;\n\ntype InferWriterType<T> = T extends typeof writer<infer C> ? C : any; // eslint-disable-line @typescript-eslint/no-explicit-any\n\ntype NodeAction<\n S,\n U,\n C extends SDZod,\n InterruptType,\n WriterType\n> = RunnableLike<\n S,\n U extends object ? U & Record<string, any> : U, // eslint-disable-line @typescript-eslint/no-explicit-any\n Runtime<StateType<ToStateDefinition<C>>, InterruptType, WriterType>\n>;\n\ntype StrictNodeAction<\n S,\n U,\n C extends SDZod,\n Nodes extends string,\n InterruptType,\n WriterType\n> = RunnableLike<\n Prettify<S>,\n | U\n | Command<\n InterruptResumeType<InterruptType>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n U & Record<string, any>,\n Nodes\n >,\n Runtime<StateType<ToStateDefinition<C>>, InterruptType, WriterType>\n>;\n\nconst PartialStateSchema = Symbol.for(\"langgraph.state.partial\");\ntype PartialStateSchema = typeof PartialStateSchema;\n\ntype MergeReturnType<Prev, Curr> = Prev & Curr extends infer T\n ? { [K in keyof T]: T[K] } & unknown\n : never;\n\ntype Prettify<T> = {\n [K in keyof T]: T[K];\n // eslint-disable-next-line @typescript-eslint/ban-types\n} & {};\n\n/**\n * A graph whose nodes communicate by reading and writing to a shared state.\n * Each node takes a defined `State` as input and returns a `Partial<State>`.\n *\n * Each state key can optionally be annotated with a reducer function that\n * will be used to aggregate the values of that key received from multiple nodes.\n * The signature of a reducer function is (left: Value, right: UpdateValue) => Value.\n *\n * See {@link Annotation} for more on defining state.\n *\n * After adding nodes and edges to your graph, you must call `.compile()` on it before\n * you can use it.\n *\n * @example\n * ```ts\n * import {\n * type BaseMessage,\n * AIMessage,\n * HumanMessage,\n * } from \"@langchain/core/messages\";\n * import { StateGraph, Annotation } from \"@langchain/langgraph\";\n *\n * // Define a state with a single key named \"messages\" that will\n * // combine a returned BaseMessage or arrays of BaseMessages\n * const StateAnnotation = Annotation.Root({\n * sentiment: Annotation<string>,\n * messages: Annotation<BaseMessage[]>({\n * reducer: (left: BaseMessage[], right: BaseMessage | BaseMessage[]) => {\n * if (Array.isArray(right)) {\n * return left.concat(right);\n * }\n * return left.concat([right]);\n * },\n * default: () => [],\n * }),\n * });\n *\n * const graphBuilder = new StateGraph(StateAnnotation);\n *\n * // A node in the graph that returns an object with a \"messages\" key\n * // will update the state by combining the existing value with the returned one.\n * const myNode = (state: typeof StateAnnotation.State) => {\n * return {\n * messages: [new AIMessage(\"Some new response\")],\n * sentiment: \"positive\",\n * };\n * };\n *\n * const graph = graphBuilder\n * .addNode(\"myNode\", myNode)\n * .addEdge(\"__start__\", \"myNode\")\n * .addEdge(\"myNode\", \"__end__\")\n * .compile();\n *\n * await graph.invoke({ messages: [new HumanMessage(\"how are you?\")] });\n *\n * // {\n * // messages: [HumanMessage(\"how are you?\"), AIMessage(\"Some new response\")],\n * // sentiment: \"positive\",\n * // }\n * ```\n */\nexport class StateGraph<\n SD extends SDZod | unknown,\n S = SD extends SDZod ? StateType<ToStateDefinition<SD>> : SD,\n U = SD extends SDZod ? UpdateType<ToStateDefinition<SD>> : Partial<S>,\n N extends string = typeof START,\n I extends SDZod = SD extends SDZod ? ToStateDefinition<SD> : StateDefinition,\n O extends SDZod = SD extends SDZod ? ToStateDefinition<SD> : StateDefinition,\n C extends SDZod = StateDefinition,\n NodeReturnType = unknown,\n InterruptType = unknown,\n WriterType = unknown\n> extends Graph<N, S, U, StateGraphNodeSpec<S, U>, ToStateDefinition<C>> {\n channels: Record<string, BaseChannel> = {};\n\n // TODO: this doesn't dedupe edges as in py, so worth fixing at some point\n waitingEdges: Set<[N[], N]> = new Set();\n\n /** @internal */\n _schemaDefinition: StateDefinition;\n\n /** @internal */\n _schemaRuntimeDefinition: InteropZodObject | undefined;\n\n /** @internal */\n _inputDefinition: I;\n\n /** @internal */\n _inputRuntimeDefinition: InteropZodObject | PartialStateSchema | undefined;\n\n /** @internal */\n _outputDefinition: O;\n\n /** @internal */\n _outputRuntimeDefinition: InteropZodObject | undefined;\n\n /**\n * Map schemas to managed values\n * @internal\n */\n _schemaDefinitions = new Map();\n\n /** @internal */\n _metaRegistry: SchemaMetaRegistry = schemaMetaRegistry;\n\n /** @internal Used only for typing. */\n _configSchema: ToStateDefinition<C> | undefined;\n\n /** @internal */\n _configRuntimeSchema: InteropZodObject | undefined;\n\n /** @internal */\n _interrupt: InterruptType;\n\n /** @internal */\n _writer: WriterType;\n\n declare Node: StrictNodeAction<S, U, C, N, InterruptType, WriterType>;\n\n constructor(\n state: SD extends InteropZodObject\n ? SD\n : SD extends StateDefinition\n ? AnnotationRoot<SD>\n : never,\n options?: {\n context?: C | AnnotationRoot<ToStateDefinition<C>>;\n input?: I | AnnotationRoot<ToStateDefinition<I>>;\n output?: O | AnnotationRoot<ToStateDefinition<O>>;\n\n interrupt?: InterruptType;\n writer?: WriterType;\n\n nodes?: N[];\n }\n );\n\n constructor(\n fields: SD extends StateDefinition\n ? StateGraphArgsWithInputOutputSchemas<SD, ToStateDefinition<O>>\n : never,\n contextSchema?: C | AnnotationRoot<ToStateDefinition<C>>\n );\n\n constructor(\n fields: SD extends StateDefinition\n ?\n | AnnotationRoot<SD>\n | StateGraphArgsWithStateSchema<\n SD,\n ToStateDefinition<I>,\n ToStateDefinition<O>\n >\n : never,\n contextSchema?: C | AnnotationRoot<ToStateDefinition<C>>\n );\n\n /** @deprecated Use `Annotation.Root` or `zod` for state definition instead. */\n constructor(\n fields: SD extends StateDefinition\n ? SD | StateGraphArgs<S>\n : StateGraphArgs<S>,\n contextSchema?: C | AnnotationRoot<ToStateDefinition<C>>\n );\n\n constructor(\n fields: SD extends InteropZodObject\n ? SD | ZodStateGraphArgsWithStateSchema<SD, I, O>\n : never,\n contextSchema?: C | AnnotationRoot<ToStateDefinition<C>>\n );\n\n constructor(\n fields: SD extends InteropZodObject\n ? SD | ZodStateGraphArgsWithStateSchema<SD, I, O>\n : SD extends StateDefinition\n ?\n | SD\n | AnnotationRoot<SD>\n | StateGraphArgs<S>\n | StateGraphArgsWithStateSchema<\n SD,\n ToStateDefinition<I>,\n ToStateDefinition<O>\n >\n | StateGraphArgsWithInputOutputSchemas<SD, ToStateDefinition<O>>\n : StateGraphArgs<S>,\n contextSchema?:\n | C\n | AnnotationRoot<ToStateDefinition<C>>\n | {\n input?: I | AnnotationRoot<ToStateDefinition<I>>;\n output?: O | AnnotationRoot<ToStateDefinition<O>>;\n context?: C | AnnotationRoot<ToStateDefinition<C>>;\n interrupt?: InterruptType;\n writer?: WriterType;\n nodes?: N[];\n }\n ) {\n super();\n\n if (isZodStateGraphArgsWithStateSchema(fields)) {\n const stateDef = this._metaRegistry.getChannelsForSchema(fields.state);\n const inputDef =\n fields.input != null\n ? this._metaRegistry.getChannelsForSchema(fields.input)\n : stateDef;\n const outputDef =\n fields.output != null\n ? this._metaRegistry.getChannelsForSchema(fields.output)\n : stateDef;\n\n this._schemaDefinition = stateDef;\n this._schemaRuntimeDefinition = fields.state;\n\n this._inputDefinition = inputDef as I;\n this._inputRuntimeDefinition = fields.input ?? PartialStateSchema;\n\n this._outputDefinition = outputDef as O;\n this._outputRuntimeDefinition = fields.output ?? fields.state;\n } else if (isInteropZodObject(fields)) {\n const stateDef = this._metaRegistry.getChannelsForSchema(fields);\n\n this._schemaDefinition = stateDef;\n this._schemaRuntimeDefinition = fields;\n\n this._inputDefinition = stateDef as I;\n this._inputRuntimeDefinition = PartialStateSchema;\n\n this._outputDefinition = stateDef as O;\n this._outputRuntimeDefinition = fields;\n } else if (\n isStateGraphArgsWithInputOutputSchemas<\n SD extends StateDefinition ? SD : never,\n O extends StateDefinition ? O : never\n >(fields)\n ) {\n this._schemaDefinition = fields.input.spec;\n this._inputDefinition = fields.input.spec as unknown as I;\n this._outputDefinition = fields.output.spec;\n } else if (isStateGraphArgsWithStateSchema(fields)) {\n this._schemaDefinition = fields.stateSchema.spec;\n this._inputDefinition = (fields.input?.spec ??\n this._schemaDefinition) as I;\n this._outputDefinition = (fields.output?.spec ??\n this._schemaDefinition) as O;\n } else if (isStateDefinition(fields) || isAnnotationRoot(fields)) {\n const spec = isAnnotationRoot(fields) ? fields.spec : fields;\n this._schemaDefinition = spec;\n } else if (isStateGraphArgs(fields)) {\n const spec = _getChannels(fields.channels);\n this._schemaDefinition = spec;\n } else {\n throw new Error(\n \"Invalid StateGraph input. Make sure to pass a valid Annotation.Root or Zod schema.\"\n );\n }\n\n this._inputDefinition ??= this._schemaDefinition as I;\n this._outputDefinition ??= this._schemaDefinition as O;\n\n this._addSchema(this._schemaDefinition);\n this._addSchema(this._inputDefinition);\n this._addSchema(this._outputDefinition);\n\n function isOptions(options: unknown): options is {\n context?: C | AnnotationRoot<ToStateDefinition<C>>;\n input?: I | AnnotationRoot<ToStateDefinition<I>>;\n output?: O | AnnotationRoot<ToStateDefinition<O>>;\n interrupt?: InterruptType;\n writer?: WriterType;\n nodes?: N[];\n } {\n return (\n typeof options === \"object\" &&\n options != null &&\n !(\"spec\" in options) &&\n !isInteropZodObject(options)\n );\n }\n\n // Handle runtime config options\n\n if (isOptions(contextSchema)) {\n if (isInteropZodObject(contextSchema.context)) {\n this._configRuntimeSchema = contextSchema.context;\n }\n } else if (isInteropZodObject(contextSchema)) {\n this._configRuntimeSchema = contextSchema;\n }\n }\n\n get allEdges(): Set<[string, string]> {\n return new Set([\n ...this.edges,\n ...Array.from(this.waitingEdges).flatMap(([starts, end]) =>\n starts.map((start) => [start, end] as [string, string])\n ),\n ]);\n }\n\n _addSchema(stateDefinition: SDZod) {\n if (this._schemaDefinitions.has(stateDefinition)) {\n return;\n }\n // TODO: Support managed values\n this._schemaDefinitions.set(stateDefinition, stateDefinition);\n for (const [key, val] of Object.entries(stateDefinition)) {\n let channel;\n if (typeof val === \"function\") {\n channel = val();\n } else {\n channel = val;\n }\n if (this.channels[key] !== undefined) {\n if (this.channels[key] !== channel) {\n if (channel.lc_graph_name !== \"LastValue\") {\n throw new Error(\n `Channel \"${key}\" already exists with a different type.`\n );\n }\n }\n } else {\n this.channels[key] = channel;\n }\n }\n }\n\n override addNode<\n K extends string,\n NodeMap extends Record<K, NodeAction<S, U, C, InterruptType, WriterType>>\n >(\n nodes: NodeMap\n ): StateGraph<\n SD,\n S,\n U,\n N | K,\n I,\n O,\n C,\n MergeReturnType<\n NodeReturnType,\n {\n [key in keyof NodeMap]: NodeMap[key] extends NodeAction<\n S,\n infer U,\n C,\n InterruptType,\n WriterType\n >\n ? U\n : never;\n }\n >\n >;\n\n override addNode<K extends string, NodeInput = S, NodeOutput extends U = U>(\n nodes:\n | [\n key: K,\n action: NodeAction<\n NodeInput,\n NodeOutput,\n C,\n InterruptType,\n WriterType\n >,\n options?: StateGraphAddNodeOptions\n ][]\n ): StateGraph<\n SD,\n S,\n U,\n N | K,\n I,\n O,\n C,\n MergeReturnType<NodeReturnType, { [key in K]: NodeOutput }>\n >;\n\n override addNode<K extends string, NodeInput = S, NodeOutput extends U = U>(\n key: K,\n action: NodeAction<NodeInput, NodeOutput, C, InterruptType, WriterType>,\n options?: StateGraphAddNodeOptions\n ): StateGraph<\n SD,\n S,\n U,\n N | K,\n I,\n O,\n C,\n MergeReturnType<NodeReturnType, { [key in K]: NodeOutput }>\n >;\n\n override addNode<K extends string, NodeInput = S>(\n key: K,\n action: NodeAction<NodeInput, U, C, InterruptType, WriterType>,\n options?: StateGraphAddNodeOptions\n ): StateGraph<SD, S, U, N | K, I, O, C, NodeReturnType>;\n\n override addNode<K extends string, NodeInput = S, NodeOutput extends U = U>(\n ...args:\n | [\n key: K,\n action: NodeAction<\n NodeInput,\n NodeOutput,\n C,\n InterruptType,\n WriterType\n >,\n options?: StateGraphAddNodeOptions\n ]\n | [\n nodes:\n | Record<K, NodeAction<NodeInput, U, C, InterruptType, WriterType>>\n | [\n key: K,\n action: NodeAction<NodeInput, U, C, InterruptType, WriterType>,\n options?: StateGraphAddNodeOptions\n ][]\n ]\n ): StateGraph<SD, S, U, N | K, I, O, C> {\n function isMultipleNodes(\n args: unknown[]\n ): args is [\n nodes:\n | Record<K, NodeAction<NodeInput, U, C, InterruptType, WriterType>>\n | [\n key: K,\n action: NodeAction<NodeInput, U, C, InterruptType, WriterType>,\n options?: AddNodeOptions\n ][]\n ] {\n return args.length >= 1 && typeof args[0] !== \"string\";\n }\n\n const nodes = (\n isMultipleNodes(args) // eslint-disable-line no-nested-ternary\n ? Array.isArray(args[0])\n ? args[0]\n : Object.entries(args[0]).map(([key, action]) => [key, action])\n : [[args[0], args[1], args[2]]]\n ) as [\n K,\n NodeAction<NodeInput, U, C, InterruptType, WriterType>,\n StateGraphAddNodeOptions | undefined\n ][];\n\n if (nodes.length === 0) {\n throw new Error(\"No nodes provided in `addNode`\");\n }\n\n for (const [key, action, options] of nodes) {\n if (key in this.channels) {\n throw new Error(\n `${key} is already being used as a state attribute (a.k.a. a channel), cannot also be used as a node name.`\n );\n }\n\n for (const reservedChar of [\n CHECKPOINT_NAMESPACE_SEPARATOR,\n CHECKPOINT_NAMESPACE_END,\n ]) {\n if (key.includes(reservedChar)) {\n throw new Error(\n `\"${reservedChar}\" is a reserved character and is not allowed in node names.`\n );\n }\n }\n this.warnIfCompiled(\n `Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`\n );\n\n if (key in this.nodes) {\n throw new Error(`Node \\`${key}\\` already present.`);\n }\n if (key === END || key === START) {\n throw new Error(`Node \\`${key}\\` is reserved.`);\n }\n\n let inputSpec = this._schemaDefinition;\n if (options?.input !== undefined) {\n if (isInteropZodObject(options.input)) {\n inputSpec = this._metaRegistry.getChannelsForSchema(options.input);\n } else if (options.input.spec !== undefined) {\n inputSpec = options.input.spec;\n }\n }\n if (inputSpec !== undefined) {\n this._addSchema(inputSpec);\n }\n\n let runnable;\n if (Runnable.isRunnable(action)) {\n runnable = action;\n } else if (typeof action === \"function\") {\n runnable = new RunnableCallable({\n func: action,\n name: key,\n trace: false,\n });\n } else {\n runnable = _coerceToRunnable(action);\n }\n\n let cachePolicy = options?.cachePolicy;\n if (typeof cachePolicy === \"boolean\") {\n cachePolicy = cachePolicy ? {} : undefined;\n }\n\n const nodeSpec: StateGraphNodeSpec<S, U> = {\n runnable: runnable as unknown as Runnable<S, U>,\n retryPolicy: options?.retryPolicy,\n cachePolicy,\n metadata: options?.metadata,\n input: inputSpec ?? this._schemaDefinition,\n subgraphs: isPregelLike(runnable)\n ? // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [runnable as any]\n : options?.subgraphs,\n ends: options?.ends,\n defer: options?.defer,\n };\n\n this.nodes[key as unknown as N] = nodeSpec;\n }\n\n return this as StateGraph<SD, S, U, N | K, I, O, C>;\n }\n\n override addEdge(\n startKey: typeof START | N | N[],\n endKey: N | typeof END\n ): this {\n if (typeof startKey === \"string\") {\n return super.addEdge(startKey, endKey);\n }\n\n if (this.compiled) {\n console.warn(\n \"Adding an edge to a graph that has already been compiled. This will \" +\n \"not be reflected in the compiled graph.\"\n );\n }\n\n for (const start of startKey) {\n if (start === END) {\n throw new Error(\"END cannot be a start node\");\n }\n if (!Object.keys(this.nodes).some((node) => node === start)) {\n throw new Error(`Need to add a node named \"${start}\" first`);\n }\n }\n if (endKey === END) {\n throw new Error(\"END cannot be an end node\");\n }\n if (!Object.keys(this.nodes).some((node) => node === endKey)) {\n throw new Error(`Need to add a node named \"${endKey}\" first`);\n }\n\n this.waitingEdges.add([startKey, endKey]);\n\n return this;\n }\n\n addSequence<K extends string, NodeInput = S, NodeOutput extends U = U>(\n nodes: [\n key: K,\n action: NodeAction<NodeInput, NodeOutput, C, InterruptType, WriterType>,\n options?: StateGraphAddNodeOptions\n ][]\n ): StateGraph<\n SD,\n S,\n U,\n N | K,\n I,\n O,\n C,\n MergeReturnType<NodeReturnType, { [key in K]: NodeOutput }>\n >;\n\n addSequence<\n K extends string,\n NodeMap extends Record<K, NodeAction<S, U, C, InterruptType, WriterType>>\n >(\n nodes: NodeMap\n ): StateGraph<\n SD,\n S,\n U,\n N | K,\n I,\n O,\n C,\n MergeReturnType<\n NodeReturnType,\n {\n [key in keyof NodeMap]: NodeMap[key] extends NodeAction<\n S,\n infer U,\n C,\n InterruptType,\n WriterType\n >\n ? U\n : never;\n }\n >\n >;\n\n addSequence<K extends string, NodeInput = S, NodeOutput extends U = U>(\n nodes:\n | [\n key: K,\n action: NodeAction<\n NodeInput,\n NodeOutput,\n C,\n InterruptType,\n WriterType\n >,\n options?: StateGraphAddNodeOptions\n ][]\n | Record<\n K,\n NodeAction<NodeInput, NodeOutput, C, InterruptType, WriterType>\n >\n ): StateGraph<\n SD,\n S,\n U,\n N | K,\n I,\n O,\n C,\n MergeReturnType<NodeReturnType, { [key in K]: NodeOutput }>\n > {\n const parsedNodes = Array.isArray(nodes) ? nodes : Object.entries(nodes);\n\n if (parsedNodes.length === 0) {\n throw new Error(\"Sequence requires at least one node.\");\n }\n\n let previousNode: N | undefined;\n for (const [key, action, options] of parsedNodes) {\n if (key in this.nodes) {\n throw new Error(\n `Node names must be unique: node with the name \"${key}\" already exists.`\n );\n }\n\n const validKey = key as unknown as N;\n this.addNode(\n validKey,\n action as NodeAction<S, U, C, InterruptType, WriterType>,\n options\n );\n if (previousNode != null) {\n this.addEdge(previousNode, validKey);\n }\n\n previousNode = validKey;\n }\n\n return this as StateGraph<\n SD,\n S,\n U,\n N | K,\n I,\n O,\n C,\n MergeReturnType<NodeReturnType, { [key in K]: NodeOutput }>\n >;\n }\n\n override compile({\n checkpointer,\n store,\n cache,\n interruptBefore,\n interruptAfter,\n name,\n description,\n }: {\n checkpointer?: BaseCheckpointSaver | boolean;\n store?: BaseStore;\n cache?: BaseCache;\n interruptBefore?: N[] | All;\n interruptAfter?: N[] | All;\n name?: string;\n description?: string;\n } = {}): CompiledStateGraph<\n Prettify<S>,\n Prettify<U>,\n N,\n I,\n O,\n C,\n NodeReturnType,\n InterruptType,\n WriterType\n > {\n // validate the graph\n this.validate([\n ...(Array.isArray(interruptBefore) ? interruptBefore : []),\n ...(Array.isArray(interruptAfter) ? interruptAfter : []),\n ]);\n\n // prepare output channels\n const outputKeys = Object.keys(\n this._schemaDefinitions.get(this._outputDefinition)\n );\n const outputChannels =\n outputKeys.length === 1 && outputKeys[0] === ROOT ? ROOT : outputKeys;\n\n const streamKeys = Object.keys(this.channels);\n const streamChannels =\n streamKeys.length === 1 && streamKeys[0] === ROOT ? ROOT : streamKeys;\n\n // create empty compiled graph\n const compiled = new CompiledStateGraph<S, U, N, I, O, C, NodeReturnType>({\n builder: this,\n checkpointer,\n interruptAfter,\n interruptBefore,\n autoValidate: false,\n nodes: {} as Record<N | typeof START, PregelNode<S, U>>,\n channels: {\n ...this.channels,\n [START]: new EphemeralValue(),\n } as Record<N | typeof START | typeof END | string, BaseChannel>,\n inputChannels: START,\n outputChannels,\n streamChannels,\n streamMode: \"updates\",\n store,\n cache,\n name,\n description,\n });\n\n // attach nodes, edges and branches\n compiled.attachNode(START);\n for (const [key, node] of Object.entries<StateGraphNodeSpec<S, U>>(\n this.nodes\n )) {\n compiled.attachNode(key as N, node);\n }\n compiled.attachBranch(START, SELF, _getControlBranch() as Branch<S, N>, {\n withReader: false,\n });\n for (const [key] of Object.entries<StateGraphNodeSpec<S, U>>(this.nodes)) {\n compiled.attachBranch(\n key as N,\n SELF,\n _getControlBranch() as Branch<S, N>,\n {\n withReader: false,\n }\n );\n }\n for (const [start, end] of this.edges) {\n compiled.attachEdge(start, end);\n }\n for (const [starts, end] of this.waitingEdges) {\n compiled.attachEdge(starts, end);\n }\n for (const [start, branches] of Object.entries(this.branches)) {\n for (const [name, branch] of Object.entries(branches)) {\n compiled.attachBranch(start as N, name, branch);\n }\n }\n\n return compiled.validate();\n }\n}\n\nfunction _getChannels<Channels extends Record<string, unknown> | unknown>(\n schema: StateGraphArgs<Channels>[\"channels\"]\n): Record<string, BaseChannel> {\n const channels: Record<string, BaseChannel> = {};\n for (const [name, val] of Object.entries(schema)) {\n if (name === ROOT) {\n channels[name] = getChannel<Channels>(val as SingleReducer<Channels>);\n } else {\n const key = name as keyof Channels;\n channels[name] = getChannel<Channels[typeof key]>(\n val as SingleReducer<Channels[typeof key]>\n );\n }\n }\n return channels;\n}\n\n/**\n * Final result from building and compiling a {@link StateGraph}.\n * Should not be instantiated directly, only using the StateGraph `.compile()`\n * instance method.\n */\nexport class CompiledStateGraph<\n S,\n U,\n N extends string = typeof START,\n I extends SDZod = StateDefinition,\n O extends SDZod = StateDefinition,\n C extends SDZod = StateDefinition,\n NodeReturnType = unknown,\n InterruptType = unknown,\n WriterType = unknown\n> extends CompiledGraph<\n N,\n S,\n U,\n StateType<ToStateDefinition<C>>,\n UpdateType<ToStateDefinition<I>>,\n StateType<ToStateDefinition<O>>,\n NodeReturnType,\n CommandInstance<InterruptResumeType<InterruptType>, Prettify<U>, N>,\n InferWriterType<WriterType>\n> {\n declare builder: StateGraph<unknown, S, U, N, I, O, C, NodeReturnType>;\n\n /**\n * The description of the compiled graph.\n * This is used by the supervisor agent to describe the handoff to the agent.\n */\n description?: string;\n\n /** @internal */\n _metaRegistry: SchemaMetaRegistry = schemaMetaRegistry;\n\n constructor({\n description,\n ...rest\n }: { description?: string } & ConstructorParameters<\n typeof CompiledGraph<\n N,\n S,\n U,\n StateType<ToStateDefinition<C>>,\n UpdateType<ToStateDefinition<I>>,\n StateType<ToStateDefinition<O>>,\n NodeReturnType,\n CommandInstance<InterruptResumeType<InterruptType>, Prettify<U>, N>,\n InferWriterType<WriterType>\n >\n >[0]) {\n super(rest);\n this.description = description;\n }\n\n attachNode(key: typeof START, node?: never): void;\n\n attachNode(key: N, node: StateGraphNodeSpec<S, U>): void;\n\n attachNode(key: N | typeof START, node?: StateGraphNodeSpec<S, U>): void {\n let outputKeys: string[];\n if (key === START) {\n // Get input schema keys excluding managed values\n outputKeys = Object.entries(\n this.builder._schemaDefinitions.get(this.builder._inputDefinition)\n ).map(([k]) => k);\n } else {\n outputKeys = Object.keys(this.builder.channels);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function _getRoot(input: unknown): [string, any][] | null {\n if (isCommand(input)) {\n if (input.graph === Command.PARENT) {\n return null;\n }\n return input._updateAsTuples();\n } else if (\n Array.isArray(input) &&\n input.length > 0 &&\n input.some((i) => isCommand(i))\n ) {\n const updates: [string, unknown][] = [];\n for (const i of input) {\n if (isCommand(i)) {\n if (i.graph === Command.PARENT) {\n continue;\n }\n updates.push(...i._updateAsTuples());\n } else {\n updates.push([ROOT, i]);\n }\n }\n return updates;\n } else if (input != null) {\n return [[ROOT, input]];\n }\n return null;\n }\n\n // to avoid name collision below\n const nodeKey = key;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function _getUpdates(input: U): [string, any][] | null {\n if (!input) {\n return null;\n } else if (isCommand(input)) {\n if (input.graph === Command.PARENT) {\n return null;\n }\n return input._updateAsTuples().filter(([k]) => outputKeys.includes(k));\n } else if (\n Array.isArray(input) &&\n input.length > 0 &&\n input.some(isCommand)\n ) {\n const updates: [string, unknown][] = [];\n for (const item of input) {\n if (isCommand(item)) {\n if (item.graph === Command.PARENT) {\n continue;\n }\n updates.push(\n ...item._updateAsTuples().filter(([k]) => outputKeys.includes(k))\n );\n } else {\n const itemUpdates = _getUpdates(item);\n if (itemUpdates) {\n updates.push(...(itemUpdates ?? []));\n }\n }\n }\n return updates;\n } else if (typeof input === \"object\" && !Array.isArray(input)) {\n return Object.entries(input).filter(([k]) => outputKeys.includes(k));\n } else {\n const typeofInput = Array.isArray(input) ? \"array\" : typeof input;\n throw new InvalidUpdateError(\n `Expected node \"${nodeKey.toString()}\" to return an object or an array containing at least one Command object, received ${typeofInput}`,\n {\n lc_error_code: \"INVALID_GRAPH_NODE_RETURN_VALUE\",\n }\n );\n }\n }\n\n const stateWriteEntries: (ChannelWriteTupleEntry | ChannelWriteEntry)[] = [\n {\n value: PASSTHROUGH,\n mapper: new RunnableCallable({\n func:\n outputKeys.length && outputKeys[0] === ROOT\n ? _getRoot\n : _getUpdates,\n trace: false,\n recurse: false,\n }),\n },\n ];\n\n // add node and output channel\n if (key === START) {\n this.nodes[key] = new PregelNode<S, U>({\n tags: [TAG_HIDDEN],\n triggers: [START],\n channels: [START],\n writers: [new ChannelWrite(stateWriteEntries, [TAG_HIDDEN])],\n });\n } else {\n const inputDefinition = node?.input ?? this.builder._schemaDefinition;\n const inputValues = Object.fromEntries(\n Object.keys(this.builder._schemaDefinitions.get(inputDefinition)).map(\n (k) => [k, k]\n )\n );\n const isSingleInput =\n Object.keys(inputValues).length === 1 && ROOT in inputValues;\n const branchChannel = `branch:to:${key}` as string | N;\n this.channels[branchChannel] = node?.defer\n ? new LastValueAfterFinish()\n : new EphemeralValue(false);\n this.nodes[key] = new PregelNode<S, U>({\n triggers: [branchChannel],\n // read state keys\n channels: isSingleInput ? Object.keys(inputValues) : inputValues,\n // publish to state keys\n writers: [new ChannelWrite(stateWriteEntries, [TAG_HIDDEN])],\n mapper: isSingleInput\n ? undefined\n : // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (input: Record<string, any>) => {\n return Object.fromEntries(\n Object.entries(input).filter(([k]) => k in inputValues)\n );\n },\n bound: node?.runnable,\n metadata: node?.metadata,\n retryPolicy: node?.retryPolicy,\n cachePolicy: node?.cachePolicy,\n subgraphs: node?.subgraphs,\n ends: node?.ends,\n });\n }\n }\n\n attachEdge(starts: N | N[] | \"__start__\", end: N | \"__end__\"): void {\n if (end === END) return;\n if (typeof starts === \"string\") {\n this.nodes[starts].writers.push(\n new ChannelWrite(\n [{ channel: `branch:to:${end}`, value: null }],\n [TAG_HIDDEN]\n )\n );\n } else if (Array.isArray(starts)) {\n const channelName = `join:${starts.join(\"+\")}:${end}`;\n // register channel\n this.channels[channelName as string | N] = this.builder.nodes[end].defer\n ? new NamedBarrierValueAfterFinish(new Set(starts))\n : new NamedBarrierValue(new Set(starts));\n // subscribe to channel\n this.nodes[end].triggers.push(channelName);\n // publish to channel\n for (const start of starts) {\n this.nodes[start].writers.push(\n new ChannelWrite(\n [{ channel: channelName, value: start }],\n [TAG_HIDDEN]\n )\n );\n }\n }\n }\n\n attachBranch(\n start: N | typeof START,\n _: string,\n branch: Branch<S, N>,\n options: { withReader?: boolean } = { withReader: true }\n ): void {\n const branchWriter = async (\n packets: (string | Send)[],\n config: LangGraphRunnableConfig\n ) => {\n const filteredPackets = packets.filter((p) => p !== END);\n if (!filteredPackets.length) return;\n\n const writes: (ChannelWriteEntry | Send)[] = filteredPackets.map((p) => {\n if (_isSend(p)) return p;\n return { channel: p === END ? p : `branch:to:${p}`, value: start };\n });\n await ChannelWrite.doWrite(\n { ...config, tags: (config.tags ?? []).concat([TAG_HIDDEN]) },\n writes\n );\n };\n // attach branch publisher\n this.nodes[start].writers.push(\n branch.run(\n branchWriter,\n // reader\n options.withReader\n ? (config) =>\n ChannelRead.doRead<S>(\n config,\n this.streamChannels ?? this.outputChannels,\n true\n )\n : undefined\n )\n );\n }\n\n protected async _validateInput(\n input: UpdateType<ToStateDefinition<I>>\n ): Promise<UpdateType<ToStateDefinition<I>>> {\n if (input == null) return input;\n\n const schema = (() => {\n const input = this.builder._inputRuntimeDefinition;\n const schema = this.builder._schemaRuntimeDefinition;\n\n const apply = (schema: InteropZodObject | undefined) => {\n if (schema == null) return undefined;\n return this._metaRegistry.getExtendedChannelSchemas(schema, {\n withReducerSchema: true,\n });\n };\n\n if (isInteropZodObject(input)) return apply(input);\n if (input === PartialStateSchema) {\n return interopZodObjectPartial(apply(schema)!);\n }\n return undefined;\n })();\n\n if (isCommand(input)) {\n const parsedInput = input;\n if (input.update && schema != null)\n parsedInput.update = interopParse(schema, input.update);\n return parsedInput;\n }\n if (schema != null) return interopParse(schema, input);\n return input;\n }\n\n public isInterrupted(input: unknown): input is {\n [INTERRUPT]: Interrupt<InterruptInputType<InterruptType>>[];\n } {\n return isInterrupted(input);\n }\n\n protected async _validateContext(\n config: Partial<Record<string, unknown>>\n ): Promise<Partial<Record<string, unknown>>> {\n const configSchema = this.builder._configRuntimeSchema;\n if (isInteropZodObject(configSchema)) interopParse(configSchema, config);\n return config;\n }\n}\n\nfunction isStateDefinition(obj: unknown): obj is StateDefinition {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n !Array.isArray(obj) &&\n Object.keys(obj).length > 0 &&\n Object.values(obj).every((v) => typeof v === \"function\" || isBaseChannel(v))\n );\n}\n\nfunction isAnnotationRoot<SD extends StateDefinition>(\n obj: unknown | AnnotationRoot<SD>\n): obj is AnnotationRoot<SD> {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n \"lc_graph_name\" in obj &&\n obj.lc_graph_name === \"AnnotationRoot\"\n );\n}\n\nfunction isStateGraphArgs<Channels extends object | unknown>(\n obj: unknown | StateGraphArgs<Channels>\n): obj is StateGraphArgs<Channels> {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n (obj as StateGraphArgs<Channels>).channels !== undefined\n );\n}\n\nfunction isStateGraphArgsWithStateSchema<\n SD extends StateDefinition,\n I extends StateDefinition,\n O extends StateDefinition\n>(\n obj: unknown | StateGraphArgsWithStateSchema<SD, I, O>\n): obj is StateGraphArgsWithStateSchema<SD, I, O> {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n (obj as StateGraphArgsWithStateSchema<SD, I, O>).stateSchema !== undefined\n );\n}\n\nfunction isStateGraphArgsWithInputOutputSchemas<\n SD extends StateDefinition,\n O extends StateDefinition\n>(\n obj: unknown | StateGraphArgsWithInputOutputSchemas<SD, O>\n): obj is StateGraphArgsWithInputOutputSchemas<SD, O> {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (obj as any).stateSchema === undefined &&\n (obj as StateGraphArgsWithInputOutputSchemas<SD, O>).input !== undefined &&\n (obj as StateGraphArgsWithInputOutputSchemas<SD, O>).output !== undefined\n );\n}\n\nfunction isZodStateGraphArgsWithStateSchema<\n SD extends InteropZodObject,\n I extends InteropZodObject,\n O extends InteropZodObject\n>(value: unknown): value is ZodStateGraphArgsWithStateSchema<SD, I, O> {\n if (typeof value !== \"object\" || value == null) {\n return false;\n }\n\n if (!(\"state\" in value) || !isInteropZodObject(value.state)) {\n return false;\n }\n\n if (\"input\" in value && !isInteropZodObject(value.input)) {\n return false;\n }\n\n if (\"output\" in value && !isInteropZodObject(value.output)) {\n return false;\n }\n\n return true;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction _controlBranch(value: any): (string | Send)[] {\n if (_isSend(value)) {\n return [value];\n }\n const commands = [];\n if (isCommand(value)) {\n commands.push(value);\n } else if (Array.isArray(value)) {\n commands.push(...value.filter(isCommand));\n }\n const destinations: (string | Send)[] = [];\n\n for (const command of commands) {\n if (command.graph === Command.PARENT) {\n throw new ParentCommand(command);\n }\n\n if (_isSend(command.goto)) {\n destinations.push(command.goto);\n } else if (typeof command.goto === \"string\") {\n destinations.push(command.goto);\n } else {\n if (Array.isArray(command.goto)) {\n destinations.push(...command.goto);\n }\n }\n }\n return destinations;\n}\n\nfunction _getControlBranch() {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const CONTROL_BRANCH_PATH = new RunnableCallable<any, (string | Send)[]>({\n func: _controlBranch,\n tags: [TAG_HIDDEN],\n trace: false,\n recurse: false,\n name: \"<control_branch>\",\n });\n return new Branch({\n path: CONTROL_BRANCH_PATH,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA4EA,MAAM,OAAO;AAyGb,MAAM,qBAAqB,OAAO,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0EtC,IAAa,aAAb,cAWU,MAA+D;CACvE,WAAwC;CAGxC,+BAA8B,IAAI;;CAGlC;;CAGA;;CAGA;;CAGA;;CAGA;;CAGA;;;;;CAMA,qCAAqB,IAAI;;C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own_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
2
  const require_meta = require('./meta.cjs');
3
- const zod = require_rolldown_runtime.__toESM(require("zod"));
4
3
  const __langchain_core_utils_types = require_rolldown_runtime.__toESM(require("@langchain/core/utils/types"));
5
4
  const zod_v3 = require_rolldown_runtime.__toESM(require("zod/v3"));
5
+ const zod = require_rolldown_runtime.__toESM(require("zod"));
6
6
 
7
7
  //#region src/graph/zod/plugin.ts
8
8
  const metaSymbol = Symbol.for("langgraph-zod");
@@ -1,7 +1,7 @@
1
1
  import { withLangGraph } from "./meta.js";
2
- import { z } from "zod";
3
2
  import { getInteropZodDefaultGetter } from "@langchain/core/utils/types";
4
- import { z as z$1 } from "zod/v3";
3
+ import { z } from "zod/v3";
4
+ import { z as z$1 } from "zod";
5
5
 
6
6
  //#region src/graph/zod/plugin.ts
7
7
  const metaSymbol = Symbol.for("langgraph-zod");
@@ -30,8 +30,8 @@ function applyPluginPrototype(prototype) {
30
30
  cache.add(prototype);
31
31
  }
32
32
  try {
33
- applyPluginPrototype(z$1.ZodType.prototype);
34
33
  applyPluginPrototype(z.ZodType.prototype);
34
+ applyPluginPrototype(z$1.ZodType.prototype);
35
35
  } catch (error) {
36
36
  throw new Error("Failed to extend Zod with LangGraph-related methods. This is most likely a bug, consider opening an issue and/or using `withLangGraph` to augment your Zod schema.", { cause: error });
37
37
  }
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","names":["z3","zd"],"sources":["../../../src/graph/zod/plugin.ts"],"sourcesContent":["import { z as zd } from \"zod\";\nimport { z as z3 } from \"zod/v3\";\nimport { getInteropZodDefaultGetter } from \"@langchain/core/utils/types\";\nimport { SchemaMeta, withLangGraph } from \"./meta.js\";\n\nconst metaSymbol = Symbol.for(\"langgraph-zod\");\n\ninterface ZodLangGraphTypes<T extends zd.ZodTypeAny, Output> {\n reducer<Input = zd.output<T>>(\n transform: (a: Output, arg: Input) => Output,\n options?: zd.ZodType<Input>\n ): zd.ZodType<Output, zd.ZodEffectsDef<T>, Input>;\n\n metadata(payload: {\n langgraph_nodes?: string[];\n langgraph_type?: \"prompt\";\n\n [key: string]: unknown;\n }): T;\n}\n\ndeclare module \"zod\" {\n interface ZodType<Output> {\n /**\n * @deprecated Using the langgraph zod plugin is deprecated and will be removed in future versions\n * Consider upgrading to zod 4 and using the exported langgraph meta registry. {@link langgraphRegistry}\n */\n langgraph: ZodLangGraphTypes<this, Output>;\n }\n}\n\ndeclare module \"zod/v3\" {\n interface ZodType<Output> {\n /**\n * @deprecated Using the langgraph zod plugin is deprecated and will be removed in future versions\n * Consider upgrading to zod 4 and using the exported langgraph meta registry. {@link langgraphRegistry}\n */\n langgraph: ZodLangGraphTypes<this, Output>;\n }\n}\n\ninterface PluginGlobalType {\n [metaSymbol]?: WeakSet<object>;\n}\n\nif (!(metaSymbol in globalThis)) {\n (globalThis as PluginGlobalType)[metaSymbol] = new WeakSet();\n}\n\nfunction applyPluginPrototype<\n PrototypeToExtend extends\n | typeof zd.ZodType.prototype\n | typeof z3.ZodType.prototype\n>(prototype: PrototypeToExtend) {\n const cache = (globalThis as PluginGlobalType)[metaSymbol]!;\n if (cache.has(prototype)) {\n return; // Already applied\n }\n\n Object.defineProperty(\n prototype,\n \"langgraph\" satisfies keyof PrototypeToExtend,\n {\n get(): zd.ZodType[\"langgraph\"] {\n // Return type is any, actual type provided by module augmentation\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const zodThis = this as zd.ZodTypeAny;\n type Output = zd.infer<typeof zodThis>;\n\n return {\n metadata(\n jsonSchemaExtra: SchemaMeta<Output, Output>[\"jsonSchemaExtra\"]\n ) {\n return withLangGraph(zodThis, { jsonSchemaExtra });\n },\n reducer<Input>(\n fn: (a: Output, arg: Input) => Output,\n schema?: zd.ZodType<Input>\n ) {\n const defaultFn = getInteropZodDefaultGetter(zodThis);\n return withLangGraph(zodThis, {\n default: defaultFn,\n reducer: { schema, fn },\n });\n },\n };\n },\n }\n );\n cache.add(prototype);\n}\n\ntry {\n applyPluginPrototype(z3.ZodType.prototype);\n applyPluginPrototype(zd.ZodType.prototype);\n} catch (error) {\n throw new Error(\n \"Failed to extend Zod with LangGraph-related methods. This is most likely a bug, consider opening an issue and/or using `withLangGraph` to augment your Zod schema.\",\n { cause: error }\n );\n}\n"],"mappings":";;;;;;AAKA,MAAM,aAAa,OAAO,IAAI;AAwC9B,IAAI,EAAE,cAAc,YAClB,CAAC,WAAgC,8BAAc,IAAI;AAGrD,SAAS,qBAIP,WAA8B;CAC9B,MAAM,QAAS,WAAgC;AAC/C,KAAI,MAAM,IAAI,WACZ;AAGF,QAAO,eACL,WACA,aACA,EACE,MAA+B;EAG7B,MAAM,UAAU;AAGhB,SAAO;GACL,SACE,iBACA;AACA,WAAO,cAAc,SAAS,EAAE;;GAElC,QACE,IACA,QACA;IACA,MAAM,YAAY,2BAA2B;AAC7C,WAAO,cAAc,SAAS;KAC5B,SAAS;KACT,SAAS;MAAE;MAAQ;;;;;;AAO/B,OAAM,IAAI;;AAGZ,IAAI;AACF,sBAAqBA,IAAG,QAAQ;AAChC,sBAAqBC,EAAG,QAAQ;SACzB,OAAO;AACd,OAAM,IAAI,MACR,sKACA,EAAE,OAAO"}
1
+ {"version":3,"file":"plugin.js","names":["z3","zd"],"sources":["../../../src/graph/zod/plugin.ts"],"sourcesContent":["import { z as zd } from \"zod\";\nimport { z as z3 } from \"zod/v3\";\nimport { getInteropZodDefaultGetter } from \"@langchain/core/utils/types\";\nimport { SchemaMeta, withLangGraph } from \"./meta.js\";\n\nconst metaSymbol = Symbol.for(\"langgraph-zod\");\n\ninterface ZodLangGraphTypes<T extends zd.ZodTypeAny, Output> {\n reducer<Input = zd.output<T>>(\n transform: (a: Output, arg: Input) => Output,\n options?: zd.ZodType<Input>\n ): zd.ZodType<Output, zd.ZodEffectsDef<T>, Input>;\n\n metadata(payload: {\n langgraph_nodes?: string[];\n langgraph_type?: \"prompt\";\n\n [key: string]: unknown;\n }): T;\n}\n\ndeclare module \"zod\" {\n interface ZodType<Output> {\n /**\n * @deprecated Using the langgraph zod plugin is deprecated and will be removed in future versions\n * Consider upgrading to zod 4 and using the exported langgraph meta registry. {@link langgraphRegistry}\n */\n langgraph: ZodLangGraphTypes<this, Output>;\n }\n}\n\ndeclare module \"zod/v3\" {\n interface ZodType<Output> {\n /**\n * @deprecated Using the langgraph zod plugin is deprecated and will be removed in future versions\n * Consider upgrading to zod 4 and using the exported langgraph meta registry. {@link langgraphRegistry}\n */\n langgraph: ZodLangGraphTypes<this, Output>;\n }\n}\n\ninterface PluginGlobalType {\n [metaSymbol]?: WeakSet<object>;\n}\n\nif (!(metaSymbol in globalThis)) {\n (globalThis as PluginGlobalType)[metaSymbol] = new WeakSet();\n}\n\nfunction applyPluginPrototype<\n PrototypeToExtend extends\n | typeof zd.ZodType.prototype\n | typeof z3.ZodType.prototype\n>(prototype: PrototypeToExtend) {\n const cache = (globalThis as PluginGlobalType)[metaSymbol]!;\n if (cache.has(prototype)) {\n return; // Already applied\n }\n\n Object.defineProperty(\n prototype,\n \"langgraph\" satisfies keyof PrototypeToExtend,\n {\n get(): zd.ZodType[\"langgraph\"] {\n // Return type is any, actual type provided by module augmentation\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const zodThis = this as zd.ZodTypeAny;\n type Output = zd.infer<typeof zodThis>;\n\n return {\n metadata(\n jsonSchemaExtra: SchemaMeta<Output, Output>[\"jsonSchemaExtra\"]\n ) {\n return withLangGraph(zodThis, { jsonSchemaExtra });\n },\n reducer<Input>(\n fn: (a: Output, arg: Input) => Output,\n schema?: zd.ZodType<Input>\n ) {\n const defaultFn = getInteropZodDefaultGetter(zodThis);\n return withLangGraph(zodThis, {\n default: defaultFn,\n reducer: { schema, fn },\n });\n },\n };\n },\n }\n );\n cache.add(prototype);\n}\n\ntry {\n applyPluginPrototype(z3.ZodType.prototype);\n applyPluginPrototype(zd.ZodType.prototype);\n} catch (error) {\n throw new Error(\n \"Failed to extend Zod with LangGraph-related methods. This is most likely a bug, consider opening an issue and/or using `withLangGraph` to augment your Zod schema.\",\n { cause: error }\n );\n}\n"],"mappings":";;;;;;AAKA,MAAM,aAAa,OAAO,IAAI;AAwC9B,IAAI,EAAE,cAAc,YAClB,CAAC,WAAgC,8BAAc,IAAI;AAGrD,SAAS,qBAIP,WAA8B;CAC9B,MAAM,QAAS,WAAgC;AAC/C,KAAI,MAAM,IAAI,WACZ;AAGF,QAAO,eACL,WACA,aACA,EACE,MAA+B;EAG7B,MAAM,UAAU;AAGhB,SAAO;GACL,SACE,iBACA;AACA,WAAO,cAAc,SAAS,EAAE;;GAElC,QACE,IACA,QACA;IACA,MAAM,YAAY,2BAA2B;AAC7C,WAAO,cAAc,SAAS;KAC5B,SAAS;KACT,SAAS;MAAE;MAAQ;;;;;;AAO/B,OAAM,IAAI;;AAGZ,IAAI;AACF,sBAAqBA,EAAG,QAAQ;AAChC,sBAAqBC,IAAG,QAAQ;SACzB,OAAO;AACd,OAAM,IAAI,MACR,sKACA,EAAE,OAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"zod-registry.d.cts","names":["core","$ZodType","$ZodRegistry","$replace","ReducedZodChannel","SchemaMeta","SchemaMetaRegistry","LanggraphZodMetaRegistry","Meta","Schema","S","_0","Output","Input","$ZodTypeInternals","Internals","output","input","TOutput","TInput","R","TInternals","ZodType","sideEffect","ZodMiniType","registry"],"sources":["../../../src/graph/zod/zod-registry.d.ts"],"sourcesContent":["import type * as core from \"zod/v4/core\";\nimport { $ZodType, $ZodRegistry, $replace } from \"zod/v4/core\";\nimport { type ReducedZodChannel, type SchemaMeta, type SchemaMetaRegistry } from \"./meta.js\";\n/**\n * A Zod v4-compatible meta registry that extends the base registry.\n *\n * This registry allows you to associate and retrieve metadata for Zod schemas,\n * leveraging the base registry for storage. It is compatible with Zod v4 and\n * interoperates with the base registry to ensure consistent metadata management\n * across different Zod versions.\n *\n * @template Meta - The type of metadata associated with each schema.\n * @template Schema - The Zod schema type.\n */\nexport declare class LanggraphZodMetaRegistry<Meta extends SchemaMeta = SchemaMeta, Schema extends $ZodType = $ZodType> extends $ZodRegistry<Meta & {\n [key: string]: unknown;\n}, Schema> {\n protected parent: SchemaMetaRegistry;\n /**\n * Creates a new LanggraphZodMetaRegistry instance.\n *\n * @param parent - The base SchemaMetaRegistry to use for metadata storage.\n */\n constructor(parent: SchemaMetaRegistry);\n add<S extends Schema>(schema: S, ..._meta: undefined extends Meta & {\n [key: string]: unknown;\n } ? [$replace<Meta & {\n [key: string]: unknown;\n }, S>?] : [$replace<Meta & {\n [key: string]: unknown;\n }, S>]): this;\n}\n// Augment the zod/v4 module nudging the `register` method\n// to use the user provided input schema if specified.\ndeclare module \"zod/v4\" {\n interface ZodType<out Output = unknown, out Input = unknown, out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>> extends core.$ZodType<Output, Input, Internals> {\n register<R extends LanggraphZodMetaRegistry, TOutput = core.output<this>, TInput = core.input<this>, TInternals extends core.$ZodTypeInternals<TOutput, TInput> = core.$ZodTypeInternals<TOutput, TInput>>(registry: R, meta: SchemaMeta<TOutput, TInput>): ReducedZodChannel<this, ZodType<TOutput, TInput, TInternals>>;\n }\n}\ndeclare module \"zod/v4-mini\" {\n interface ZodMiniType<out Output = unknown, out Input = unknown, out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>> extends core.$ZodType<Output, Input, Internals> {\n register<R extends LanggraphZodMetaRegistry, TOutput = core.output<this>, TInput = core.input<this>, TInternals extends core.$ZodTypeInternals<TOutput, TInput> = core.$ZodTypeInternals<TOutput, TInput>>(registry: R, meta: SchemaMeta<TOutput, TInput>): ReducedZodChannel<this, ZodMiniType<TOutput, TInput, TInternals>>;\n }\n}\nexport declare const registry: LanggraphZodMetaRegistry<SchemaMeta<any, any>, $ZodType<unknown, unknown, core.$ZodTypeInternals<unknown, unknown>>>;\n"],"mappings":";;;;;;;;AAcA;;;;;;;;;AASwBM,cATHC,wBASGD,CAAAA,aATmCD,UASnCC,GAT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ARkJc,CAAAA,GAAAA,EAAAA,GAAAA,CAAAA,EAQ5HlB,QAR4HkB,CAAAA,OAAAA,EAAAA,OAAAA,EAQjGnB,IAAAA,CAAKc,iBAR4FK,CAAAA,OAAAA,EAAAA,OAAAA,CAAAA,CAAAA,CAAAA"}
1
+ {"version":3,"file":"zod-registry.d.cts","names":["core","$ZodType","$ZodRegistry","$replace","ReducedZodChannel","SchemaMeta","SchemaMetaRegistry","LanggraphZodMetaRegistry","Meta","Schema","S","_1","Output","Input","$ZodTypeInternals","Internals","output","input","TOutput","TInput","R","TInternals","ZodType","sideEffect","_2","ZodMiniType","registry"],"sources":["../../../src/graph/zod/zod-registry.d.ts"],"sourcesContent":["import type * as core from \"zod/v4/core\";\nimport { $ZodType, $ZodRegistry, $replace } from \"zod/v4/core\";\nimport { type ReducedZodChannel, type SchemaMeta, type SchemaMetaRegistry } from \"./meta.js\";\n/**\n * A Zod v4-compatible meta registry that extends the base registry.\n *\n * This registry allows you to associate and retrieve metadata for Zod schemas,\n * leveraging the base registry for storage. It is compatible with Zod v4 and\n * interoperates with the base registry to ensure consistent metadata management\n * across different Zod versions.\n *\n * @template Meta - The type of metadata associated with each schema.\n * @template Schema - The Zod schema type.\n */\nexport declare class LanggraphZodMetaRegistry<Meta extends SchemaMeta = SchemaMeta, Schema extends $ZodType = $ZodType> extends $ZodRegistry<Meta & {\n [key: string]: unknown;\n}, Schema> {\n protected parent: SchemaMetaRegistry;\n /**\n * Creates a new LanggraphZodMetaRegistry instance.\n *\n * @param parent - The base SchemaMetaRegistry to use for metadata storage.\n */\n constructor(parent: SchemaMetaRegistry);\n add<S extends Schema>(schema: S, ..._meta: undefined extends Meta & {\n [key: string]: unknown;\n } ? [$replace<Meta & {\n [key: string]: unknown;\n }, S>?] : [$replace<Meta & {\n [key: string]: unknown;\n }, S>]): this;\n}\n// Augment the zod/v4 module nudging the `register` method\n// to use the user provided input schema if specified.\ndeclare module \"zod/v4\" {\n interface ZodType<out Output = unknown, out Input = unknown, out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>> extends core.$ZodType<Output, Input, Internals> {\n register<R extends LanggraphZodMetaRegistry, TOutput = core.output<this>, TInput = core.input<this>, TInternals extends core.$ZodTypeInternals<TOutput, TInput> = core.$ZodTypeInternals<TOutput, TInput>>(registry: R, meta: SchemaMeta<TOutput, TInput>): ReducedZodChannel<this, ZodType<TOutput, TInput, TInternals>>;\n }\n}\ndeclare module \"zod/v4-mini\" {\n interface ZodMiniType<out Output = unknown, out Input = unknown, out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>> extends core.$ZodType<Output, Input, Internals> {\n register<R extends LanggraphZodMetaRegistry, TOutput = core.output<this>, TInput = core.input<this>, TInternals extends core.$ZodTypeInternals<TOutput, TInput> = core.$ZodTypeInternals<TOutput, TInput>>(registry: R, meta: SchemaMeta<TOutput, TInput>): ReducedZodChannel<this, ZodMiniType<TOutput, TInput, TInternals>>;\n }\n}\nexport declare const registry: LanggraphZodMetaRegistry<SchemaMeta<any, any>, $ZodType<unknown, unknown, core.$ZodTypeInternals<unknown, unknown>>>;\n"],"mappings":";;;;;;;;AAcA;;;;;;;;;AASwBM,cATHC,wBASGD,CAAAA,aATmCD,UASnCC,GATgDD,UAShDC,EAAAA,eAT2EL,QAS3EK,GATsFL,QAStFK,CAAAA,SATwGJ,YASxGI,CATqHE,IASrHF,GAAAA;MACNG,EAAAA,MAAAA,CAAAA,EAAAA,OAAAA;GARfA,MAQ+BC,CAAAA,CAAAA;YAA+BF,MAAAA,EAP3CF,kBAO2CE;;;;;;aAIlDL,CAAAA,MAAAA,EALSG,kBAKTH;KAdiHD,CAAAA,UAU9GO,MAV8GP,CAAAA,CAAAA,MAAAA,EAU9FQ,CAV8FR,EAAAA,GAAAA,KAAAA,EAAAA,SAAAA,SAU/DM,IAV+DN,GAAAA;;EAiB/HS,CAAAA,GAAAA,CALQR,QAKR,CALiBK,IAKjB,GAAA;IAAA,CAA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EAI7BL,KAJ6BK,CAAAA,GAIpBlB,IAAAA,CAAKc,iBAJeI,CAIGN,MAJHM,EAIWL,KAJXK,CAAAA,CAAAA,SAI2BlB,IAAAA,CAAKC,QAJhCiB,CAIyCN,MAJzCM,EAIiDL,KAJjDK,EAIwDH,SAJxDG,CAAAA,CAAAA;IAASC,QAAAA,CAAAA,UAKrIZ,wBALqIY,EAAAA,UAKjGnB,IAAAA,CAAKgB,MAL4FG,CAAAA,IAAAA,CAAAA,EAAAA,SAKrEnB,IAAAA,CAAKiB,KALgEE,CAAAA,IAAAA,CAAAA,EAAAA,mBAKhCnB,IAAAA,CAAKc,iBAL2BK,CAKTD,OALSC,EAKAA,MALAA,CAAAA,GAKUnB,IAAAA,CAAKc,iBALfK,CAKiCD,OALjCC,EAK0CA,MAL1CA,CAAAA,CAAAA,CAAAA,QAAAA,EAK6DC,CAL7DD,EAAAA,IAAAA,EAKsEd,UALtEc,CAKiFD,OALjFC,EAK0FA,MAL1FA,CAAAA,CAAAA,EAKoGf,iBALpGe,CAAAA,IAAAA,EAK4HM,WAL5HN,CAKwID,OALxIC,EAKiJA,MALjJA,EAKyJE,UALzJF,CAAAA,CAAAA;;;AAA0CA,cAQrLO,QARqLP,EAQ3KZ,wBAR2KY,CAQlJd,UARkJc,CAAAA,GAAAA,EAAAA,GAAAA,CAAAA,EAQ5HlB,QAR4HkB,CAAAA,OAAAA,EAAAA,OAAAA,EAQjGnB,IAAAA,CAAKc,iBAR4FK,CAAAA,OAAAA,EAAAA,OAAAA,CAAAA,CAAAA,CAAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"zod-registry.d.ts","names":["core","$ZodType","$ZodRegistry","$replace","ReducedZodChannel","SchemaMeta","SchemaMetaRegistry","LanggraphZodMetaRegistry","Meta","Schema","S","_0","Output","Input","$ZodTypeInternals","Internals","output","input","TOutput","TInput","R","TInternals","ZodType","sideEffect","ZodMiniType","registry"],"sources":["../../../src/graph/zod/zod-registry.d.ts"],"sourcesContent":["import type * as core from \"zod/v4/core\";\nimport { $ZodType, $ZodRegistry, $replace } from \"zod/v4/core\";\nimport { type ReducedZodChannel, type SchemaMeta, type SchemaMetaRegistry } from \"./meta.js\";\n/**\n * A Zod v4-compatible meta registry that extends the base registry.\n *\n * This registry allows you to associate and retrieve metadata for Zod schemas,\n * leveraging the base registry for storage. It is compatible with Zod v4 and\n * interoperates with the base registry to ensure consistent metadata management\n * across different Zod versions.\n *\n * @template Meta - The type of metadata associated with each schema.\n * @template Schema - The Zod schema type.\n */\nexport declare class LanggraphZodMetaRegistry<Meta extends SchemaMeta = SchemaMeta, Schema extends $ZodType = $ZodType> extends $ZodRegistry<Meta & {\n [key: string]: unknown;\n}, Schema> {\n protected parent: SchemaMetaRegistry;\n /**\n * Creates a new LanggraphZodMetaRegistry instance.\n *\n * @param parent - The base SchemaMetaRegistry to use for metadata storage.\n */\n constructor(parent: SchemaMetaRegistry);\n add<S extends Schema>(schema: S, ..._meta: undefined extends Meta & {\n [key: string]: unknown;\n } ? [$replace<Meta & {\n [key: string]: unknown;\n }, S>?] : [$replace<Meta & {\n [key: string]: unknown;\n }, S>]): this;\n}\n// Augment the zod/v4 module nudging the `register` method\n// to use the user provided input schema if specified.\ndeclare module \"zod/v4\" {\n interface ZodType<out Output = unknown, out Input = unknown, out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>> extends core.$ZodType<Output, Input, Internals> {\n register<R extends LanggraphZodMetaRegistry, TOutput = core.output<this>, TInput = core.input<this>, TInternals extends core.$ZodTypeInternals<TOutput, TInput> = core.$ZodTypeInternals<TOutput, TInput>>(registry: R, meta: SchemaMeta<TOutput, TInput>): ReducedZodChannel<this, ZodType<TOutput, TInput, TInternals>>;\n }\n}\ndeclare module \"zod/v4-mini\" {\n interface ZodMiniType<out Output = unknown, out Input = unknown, out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>> extends core.$ZodType<Output, Input, Internals> {\n register<R extends LanggraphZodMetaRegistry, TOutput = core.output<this>, TInput = core.input<this>, TInternals extends core.$ZodTypeInternals<TOutput, TInput> = core.$ZodTypeInternals<TOutput, TInput>>(registry: R, meta: SchemaMeta<TOutput, TInput>): ReducedZodChannel<this, ZodMiniType<TOutput, TInput, TInternals>>;\n }\n}\nexport declare const registry: LanggraphZodMetaRegistry<SchemaMeta<any, any>, $ZodType<unknown, unknown, core.$ZodTypeInternals<unknown, unknown>>>;\n"],"mappings":";;;;;;;;AAcA;;;;;;;;;AASwBM,cATHC,wBASGD,CAAAA,aATmCD,UASnCC,GATgDD,UAShDC,EAAAA,eAT2EL,QAS3EK,GATsFL,QAStFK,CAAAA,SATwGJ,YASxGI,CATqHE,IASrHF,GAAAA;MACNG,EAAAA,MAAAA,CAAAA,EAAAA,OAAAA;GARfA,MAQ+BC,CAAAA,CAAAA;YAA+BF,MAAAA,EAP3CF,kBAO2CE;;;;;;aAIlDL,CAAAA,MAAAA,EALSG,kBAKTH;KAdiHD,CAAAA,UAU9GO,MAV8GP,CAAAA,CAAAA,MAAAA,EAU9FQ,CAV8FR,EAAAA,GAAAA,KAAAA,EAAAA,SAAAA,SAU/DM,IAV+DN,GAAAA;;EAiB/HS,CAAAA,GAAAA,CALQR,QAKR,CALiBK,IAKjB,GAAA;IAAA,CAAA,GAAA,EAAA,MAAA,CAAA,EAAA,OAAA;KAHME,CAOuGE,CAAAA,CAAAA,CAAAA,GAAAA,CAP/FT,QAO+FS,CAPtFJ,IAOsFI,GAAAA;IAAQC,CAAAA,GAAAA,EAAAA,MAAAA,CAAAA,EAAAA,OAAAA;KAL/GH,CAKgFV,CAAAA,CAAAA,CAAAA,EAAKc,IAAAA;;;;eAAgGF,QAAAA,CAAAA;YAAQC,OAAAA,CAAAA,aAAAA,OAAAA,EAAAA,YAAAA,OAAAA,EAAAA,sBAA7Gb,IAAAA,CAAKc,iBAAwGD,CAAtFD,MAAsFC,EAA9EA,KAA8EA,CAAAA,GAArEb,IAAAA,CAAKc,iBAAgED,CA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AA,GAKUnB,IAAAA,CAAKc,iBALfK,CAKiCD,OALjCC,EAK0CA,MAL1CA,CAAAA,CAAAA,CAAAA,QAAAA,EAK6DC,CAL7DD,EAAAA,IAAAA,EAKsEd,UALtEc,CAKiFD,OALjFC,EAK0FA,MAL1FA,CAAAA,CAAAA,EAKoGf,iBALpGe,CAAAA,IAAAA,EAK4HK,WAL5HL,CAKwID,OALxIC,EAKiJA,MALjJA,EAKyJE,UALzJF,CAAAA,CAAAA;;;AAA0CA,cAQrLM,QARqLN,EAQ3KZ,wBAR2KY,CAQlJd,UARkJc,CAAAA,GAAAA,EAAAA,GAAAA,CAAAA,EAQ5HlB,QAR4HkB,CAAAA,OAAAA,EAAAA,OAAAA,EAQjGnB,IAAAA,CAAKc,iBAR4FK,CAAAA,OAAAA,EAAAA,OAAAA,CAAAA,CAAAA,CAAAA"}
1
+ {"version":3,"file":"zod-registry.d.ts","names":["core","$ZodType","$ZodRegistry","$replace","ReducedZodChannel","SchemaMeta","SchemaMetaRegistry","LanggraphZodMetaRegistry","Meta","Schema","S","_1","Output","Input","$ZodTypeInternals","Internals","output","input","TOutput","TInput","R","TInternals","ZodType","sideEffect","_2","ZodMiniType","registry"],"sources":["../../../src/graph/zod/zod-registry.d.ts"],"sourcesContent":["import type * as core from \"zod/v4/core\";\nimport { $ZodType, $ZodRegistry, $replace } from \"zod/v4/core\";\nimport { type ReducedZodChannel, type SchemaMeta, type SchemaMetaRegistry } from \"./meta.js\";\n/**\n * A Zod v4-compatible meta registry that extends the base registry.\n *\n * This registry allows you to associate and retrieve metadata for Zod schemas,\n * leveraging the base registry for storage. It is compatible with Zod v4 and\n * interoperates with the base registry to ensure consistent metadata management\n * across different Zod versions.\n *\n * @template Meta - The type of metadata associated with each schema.\n * @template Schema - The Zod schema type.\n */\nexport declare class LanggraphZodMetaRegistry<Meta extends SchemaMeta = SchemaMeta, Schema extends $ZodType = $ZodType> extends $ZodRegistry<Meta & {\n [key: string]: unknown;\n}, Schema> {\n protected parent: SchemaMetaRegistry;\n /**\n * Creates a new LanggraphZodMetaRegistry instance.\n *\n * @param parent - The base SchemaMetaRegistry to use for metadata storage.\n */\n constructor(parent: SchemaMetaRegistry);\n add<S extends Schema>(schema: S, ..._meta: undefined extends Meta & {\n [key: string]: unknown;\n } ? [$replace<Meta & {\n [key: string]: unknown;\n }, S>?] : [$replace<Meta & {\n [key: string]: unknown;\n }, S>]): this;\n}\n// Augment the zod/v4 module nudging the `register` method\n// to use the user provided input schema if specified.\ndeclare module \"zod/v4\" {\n interface ZodType<out Output = unknown, out Input = unknown, out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>> extends core.$ZodType<Output, Input, Internals> {\n register<R extends LanggraphZodMetaRegistry, TOutput = core.output<this>, TInput = core.input<this>, TInternals extends core.$ZodTypeInternals<TOutput, TInput> = core.$ZodTypeInternals<TOutput, TInput>>(registry: R, meta: SchemaMeta<TOutput, TInput>): ReducedZodChannel<this, ZodType<TOutput, TInput, TInternals>>;\n }\n}\ndeclare module \"zod/v4-mini\" {\n interface ZodMiniType<out Output = unknown, out Input = unknown, out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>> extends core.$ZodType<Output, Input, Internals> {\n register<R extends LanggraphZodMetaRegistry, TOutput = core.output<this>, TInput = core.input<this>, TInternals extends core.$ZodTypeInternals<TOutput, TInput> = core.$ZodTypeInternals<TOutput, TInput>>(registry: R, meta: SchemaMeta<TOutput, TInput>): ReducedZodChannel<this, ZodMiniType<TOutput, TInput, TInternals>>;\n }\n}\nexport declare const registry: LanggraphZodMetaRegistry<SchemaMeta<any, any>, $ZodType<unknown, unknown, core.$ZodTypeInternals<unknown, unknown>>>;\n"],"mappings":";;;;;;;;AAcA;;;;;;;;;AASwBM,cATHC,wBASGD,CAAAA,aATmCD,UASnCC,GATgDD,UAShDC,EAAAA,eAT2EL,QAS3EK,GATsFL,QAStFK,CAAAA,SATwGJ,YASxGI,CATqHE,IASrHF,GA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,EAQjGnB,IAAAA,CAAKc,iBAR4FK,CAAAA,OAAAA,EAAAA,OAAAA,CAAAA,CAAAA,CAAAA"}
package/dist/index.cjs CHANGED
@@ -6,13 +6,14 @@ const require_binop = require('./channels/binop.cjs');
6
6
  const require_annotation = require('./graph/annotation.cjs');
7
7
  const require_constants = require('./constants.cjs');
8
8
  const require_config = require('./pregel/utils/config.cjs');
9
+ const require_interrupt = require('./interrupt.cjs');
9
10
  const require_graph = require('./graph/graph.cjs');
10
11
  const require_state = require('./graph/state.cjs');
11
12
  const require_message = require('./graph/message.cjs');
12
13
  const require_index = require('./func/index.cjs');
13
14
  const require_messages_annotation = require('./graph/messages_annotation.cjs');
14
15
  require('./web.cjs');
15
- const require_interrupt = require('./interrupt.cjs');
16
+ const require_writer = require('./writer.cjs');
16
17
  const __langchain_langgraph_checkpoint = require_rolldown_runtime.__toESM(require("@langchain/langgraph-checkpoint"));
17
18
 
18
19
  //#region src/index.ts
@@ -106,5 +107,5 @@ exports.isInterrupted = require_constants.isInterrupted;
106
107
  exports.isParentCommand = require_errors.isParentCommand;
107
108
  exports.messagesStateReducer = require_message.messagesStateReducer;
108
109
  exports.task = require_index.task;
109
- exports.typedNode = require_state.typedNode;
110
+ exports.writer = require_writer.writer;
110
111
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["initializeAsyncLocalStorageSingleton"],"sources":["../src/index.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\nimport { initializeAsyncLocalStorageSingleton } from \"./setup/async_local_storage.js\";\n\n// Initialize global async local storage instance for tracing\ninitializeAsyncLocalStorageSingleton();\n\nexport * from \"./web.js\";\n\nexport { interrupt } from \"./interrupt.js\";\nexport { getStore, getWriter, getConfig } from \"./pregel/utils/config.js\";\nexport { getPreviousState } from \"./func/index.js\";\nexport { getCurrentTaskInput } from \"./pregel/utils/config.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAKAA"}
1
+ {"version":3,"file":"index.cjs","names":["initializeAsyncLocalStorageSingleton"],"sources":["../src/index.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\nimport { initializeAsyncLocalStorageSingleton } from \"./setup/async_local_storage.js\";\n\n// Initialize global async local storage instance for tracing\ninitializeAsyncLocalStorageSingleton();\n\nexport * from \"./web.js\";\n\nexport { interrupt } from \"./interrupt.js\";\nexport { writer } from \"./writer.js\";\nexport { getStore, getWriter, getConfig } from \"./pregel/utils/config.js\";\nexport { getPreviousState } from \"./func/index.js\";\nexport { getCurrentTaskInput } from \"./pregel/utils/config.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAKAA"}
package/dist/index.d.cts CHANGED
@@ -1,7 +1,12 @@
1
1
  import { BaseChannel } from "./channels/base.cjs";
2
- import { LangGraphRunnableConfig, Runtime } from "./pregel/runnable_types.cjs";
3
2
  import { BinaryOperator, BinaryOperatorAggregate } from "./channels/binop.cjs";
3
+ import { AnyValue } from "./channels/any_value.cjs";
4
4
  import { LastValue } from "./channels/last_value.cjs";
5
+ import { DynamicBarrierValue, WaitForNames } from "./channels/dynamic_barrier_value.cjs";
6
+ import { EphemeralValue } from "./channels/ephemeral_value.cjs";
7
+ import { NamedBarrierValue } from "./channels/named_barrier_value.cjs";
8
+ import { Topic } from "./channels/topic.cjs";
9
+ import { LangGraphRunnableConfig, Runtime } from "./pregel/runnable_types.cjs";
5
10
  import { Annotation, AnnotationRoot, NodeType, SingleReducer, StateDefinition, StateType, UpdateType } from "./graph/annotation.cjs";
6
11
  import { RetryPolicy } from "./pregel/utils/index.cjs";
7
12
  import { PregelNode } from "./pregel/read.cjs";
@@ -9,17 +14,13 @@ import { Command, CommandParams, END, INTERRUPT, Interrupt, START, Send, isComma
9
14
  import { GetStateOptions, MultipleChannelSubscriptionOptions, PregelOptions, PregelParams, SingleChannelSubscriptionOptions, StateSnapshot, StreamMode, StreamOutputMap } from "./pregel/types.cjs";
10
15
  import { Pregel } from "./pregel/index.cjs";
11
16
  import { CompiledGraph, Graph } from "./graph/graph.cjs";
12
- import { CompiledStateGraph, StateGraph, StateGraphArgs, typedNode } from "./graph/state.cjs";
17
+ import { interrupt } from "./interrupt.cjs";
18
+ import { writer } from "./writer.cjs";
19
+ import { CompiledStateGraph, StateGraph, StateGraphArgs } from "./graph/state.cjs";
13
20
  import { MessageGraph, Messages, REMOVE_ALL_MESSAGES, messagesStateReducer } from "./graph/message.cjs";
14
21
  import { BaseLangGraphError, BaseLangGraphErrorFields, EmptyChannelError, EmptyInputError, GraphBubbleUp, GraphInterrupt, GraphRecursionError, GraphValueError, InvalidUpdateError, MultipleSubgraphsError, NodeInterrupt, ParentCommand, RemoteException, UnreachableNodeError, getSubgraphsSeenSet, isGraphBubbleUp, isGraphInterrupt, isParentCommand } from "./errors.cjs";
15
- import { AnyValue } from "./channels/any_value.cjs";
16
- import { DynamicBarrierValue, WaitForNames } from "./channels/dynamic_barrier_value.cjs";
17
- import { NamedBarrierValue } from "./channels/named_barrier_value.cjs";
18
- import { Topic } from "./channels/topic.cjs";
19
- import { EphemeralValue } from "./channels/ephemeral_value.cjs";
20
22
  import { EntrypointOptions, TaskOptions, entrypoint, getPreviousState, task } from "./func/index.cjs";
21
23
  import { MessagesAnnotation, MessagesZodMeta, MessagesZodState } from "./graph/messages_annotation.cjs";
22
24
  import { AsyncBatchedStore, BaseCheckpointSaver, BaseStore, Checkpoint, CheckpointMetadata, CheckpointTuple, GetOperation, InMemoryStore, Item, ListNamespacesOperation, MatchCondition, MemorySaver, NameSpacePath, NamespaceMatchType, Operation, OperationResults, PutOperation, SearchOperation, copyCheckpoint, emptyCheckpoint } from "./web.cjs";
23
- import { interrupt } from "./interrupt.cjs";
24
25
  import { getConfig, getCurrentTaskInput, getStore, getWriter } from "./pregel/utils/config.cjs";
25
- export { Annotation, AnnotationRoot, AnyValue, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseLangGraphErrorFields, BaseStore, BinaryOperator, BinaryOperatorAggregate, Checkpoint, CheckpointMetadata, CheckpointTuple, Command, CommandParams, CompiledGraph, CompiledStateGraph, DynamicBarrierValue, END, EmptyChannelError, EmptyInputError, EntrypointOptions, EphemeralValue, GetOperation, GetStateOptions, Graph, GraphBubbleUp, GraphInterrupt, GraphRecursionError, GraphValueError, INTERRUPT, InMemoryStore, Interrupt, InvalidUpdateError, Item, LangGraphRunnableConfig, LastValue, ListNamespacesOperation, MatchCondition, MemorySaver, MessageGraph, Messages, MessagesAnnotation, MessagesZodMeta, MessagesZodState, MultipleChannelSubscriptionOptions, MultipleSubgraphsError, NameSpacePath, NamedBarrierValue, NamespaceMatchType, NodeInterrupt, NodeType, Operation, OperationResults, ParentCommand, Pregel, PregelNode, PregelOptions, PregelParams, PutOperation, REMOVE_ALL_MESSAGES, RemoteException, RetryPolicy, Runtime, START, SearchOperation, Send, SingleChannelSubscriptionOptions, SingleReducer, StateDefinition, StateGraph, StateGraphArgs, StateSnapshot, StateType, StreamMode, StreamOutputMap, TaskOptions, Topic, UnreachableNodeError, UpdateType, WaitForNames, messagesStateReducer as addMessages, copyCheckpoint, emptyCheckpoint, entrypoint, getConfig, getCurrentTaskInput, getPreviousState, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCommand, isGraphBubbleUp, isGraphInterrupt, isInterrupted, isParentCommand, messagesStateReducer, task, typedNode };
26
+ export { Annotation, AnnotationRoot, AnyValue, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseLangGraphErrorFields, BaseStore, BinaryOperator, BinaryOperatorAggregate, Checkpoint, CheckpointMetadata, CheckpointTuple, Command, CommandParams, CompiledGraph, CompiledStateGraph, DynamicBarrierValue, END, EmptyChannelError, EmptyInputError, EntrypointOptions, EphemeralValue, GetOperation, GetStateOptions, Graph, GraphBubbleUp, GraphInterrupt, GraphRecursionError, GraphValueError, INTERRUPT, InMemoryStore, Interrupt, InvalidUpdateError, Item, LangGraphRunnableConfig, LastValue, ListNamespacesOperation, MatchCondition, MemorySaver, MessageGraph, Messages, MessagesAnnotation, MessagesZodMeta, MessagesZodState, MultipleChannelSubscriptionOptions, MultipleSubgraphsError, NameSpacePath, NamedBarrierValue, NamespaceMatchType, NodeInterrupt, NodeType, Operation, OperationResults, ParentCommand, Pregel, PregelNode, PregelOptions, PregelParams, PutOperation, REMOVE_ALL_MESSAGES, RemoteException, RetryPolicy, Runtime, START, SearchOperation, Send, SingleChannelSubscriptionOptions, SingleReducer, StateDefinition, StateGraph, StateGraphArgs, StateSnapshot, StateType, StreamMode, StreamOutputMap, TaskOptions, Topic, UnreachableNodeError, UpdateType, WaitForNames, messagesStateReducer as addMessages, copyCheckpoint, emptyCheckpoint, entrypoint, getConfig, getCurrentTaskInput, getPreviousState, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCommand, isGraphBubbleUp, isGraphInterrupt, isInterrupted, isParentCommand, messagesStateReducer, task, writer };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,12 @@
1
1
  import { BaseChannel } from "./channels/base.js";
2
- import { LangGraphRunnableConfig, Runtime } from "./pregel/runnable_types.js";
3
2
  import { BinaryOperator, BinaryOperatorAggregate } from "./channels/binop.js";
3
+ import { AnyValue } from "./channels/any_value.js";
4
4
  import { LastValue } from "./channels/last_value.js";
5
+ import { DynamicBarrierValue, WaitForNames } from "./channels/dynamic_barrier_value.js";
6
+ import { EphemeralValue } from "./channels/ephemeral_value.js";
7
+ import { NamedBarrierValue } from "./channels/named_barrier_value.js";
8
+ import { Topic } from "./channels/topic.js";
9
+ import { LangGraphRunnableConfig, Runtime } from "./pregel/runnable_types.js";
5
10
  import { Annotation, AnnotationRoot, NodeType, SingleReducer, StateDefinition, StateType, UpdateType } from "./graph/annotation.js";
6
11
  import { RetryPolicy } from "./pregel/utils/index.js";
7
12
  import { PregelNode } from "./pregel/read.js";
@@ -9,17 +14,13 @@ import { Command, CommandParams, END, INTERRUPT, Interrupt, START, Send, isComma
9
14
  import { GetStateOptions, MultipleChannelSubscriptionOptions, PregelOptions, PregelParams, SingleChannelSubscriptionOptions, StateSnapshot, StreamMode, StreamOutputMap } from "./pregel/types.js";
10
15
  import { Pregel } from "./pregel/index.js";
11
16
  import { CompiledGraph, Graph } from "./graph/graph.js";
12
- import { CompiledStateGraph, StateGraph, StateGraphArgs, typedNode } from "./graph/state.js";
17
+ import { interrupt } from "./interrupt.js";
18
+ import { writer } from "./writer.js";
19
+ import { CompiledStateGraph, StateGraph, StateGraphArgs } from "./graph/state.js";
13
20
  import { MessageGraph, Messages, REMOVE_ALL_MESSAGES, messagesStateReducer } from "./graph/message.js";
14
21
  import { BaseLangGraphError, BaseLangGraphErrorFields, EmptyChannelError, EmptyInputError, GraphBubbleUp, GraphInterrupt, GraphRecursionError, GraphValueError, InvalidUpdateError, MultipleSubgraphsError, NodeInterrupt, ParentCommand, RemoteException, UnreachableNodeError, getSubgraphsSeenSet, isGraphBubbleUp, isGraphInterrupt, isParentCommand } from "./errors.js";
15
- import { AnyValue } from "./channels/any_value.js";
16
- import { DynamicBarrierValue, WaitForNames } from "./channels/dynamic_barrier_value.js";
17
- import { NamedBarrierValue } from "./channels/named_barrier_value.js";
18
- import { Topic } from "./channels/topic.js";
19
- import { EphemeralValue } from "./channels/ephemeral_value.js";
20
22
  import { EntrypointOptions, TaskOptions, entrypoint, getPreviousState, task } from "./func/index.js";
21
23
  import { MessagesAnnotation, MessagesZodMeta, MessagesZodState } from "./graph/messages_annotation.js";
22
24
  import { AsyncBatchedStore, BaseCheckpointSaver, BaseStore, Checkpoint, CheckpointMetadata, CheckpointTuple, GetOperation, InMemoryStore, Item, ListNamespacesOperation, MatchCondition, MemorySaver, NameSpacePath, NamespaceMatchType, Operation, OperationResults, PutOperation, SearchOperation, copyCheckpoint, emptyCheckpoint } from "./web.js";
23
- import { interrupt } from "./interrupt.js";
24
25
  import { getConfig, getCurrentTaskInput, getStore, getWriter } from "./pregel/utils/config.js";
25
- export { Annotation, AnnotationRoot, AnyValue, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseLangGraphErrorFields, BaseStore, BinaryOperator, BinaryOperatorAggregate, Checkpoint, CheckpointMetadata, CheckpointTuple, Command, CommandParams, CompiledGraph, CompiledStateGraph, DynamicBarrierValue, END, EmptyChannelError, EmptyInputError, EntrypointOptions, EphemeralValue, GetOperation, GetStateOptions, Graph, GraphBubbleUp, GraphInterrupt, GraphRecursionError, GraphValueError, INTERRUPT, InMemoryStore, Interrupt, InvalidUpdateError, Item, LangGraphRunnableConfig, LastValue, ListNamespacesOperation, MatchCondition, MemorySaver, MessageGraph, Messages, MessagesAnnotation, MessagesZodMeta, MessagesZodState, MultipleChannelSubscriptionOptions, MultipleSubgraphsError, NameSpacePath, NamedBarrierValue, NamespaceMatchType, NodeInterrupt, NodeType, Operation, OperationResults, ParentCommand, Pregel, PregelNode, PregelOptions, PregelParams, PutOperation, REMOVE_ALL_MESSAGES, RemoteException, RetryPolicy, Runtime, START, SearchOperation, Send, SingleChannelSubscriptionOptions, SingleReducer, StateDefinition, StateGraph, StateGraphArgs, StateSnapshot, StateType, StreamMode, StreamOutputMap, TaskOptions, Topic, UnreachableNodeError, UpdateType, WaitForNames, messagesStateReducer as addMessages, copyCheckpoint, emptyCheckpoint, entrypoint, getConfig, getCurrentTaskInput, getPreviousState, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCommand, isGraphBubbleUp, isGraphInterrupt, isInterrupted, isParentCommand, messagesStateReducer, task, typedNode };
26
+ export { Annotation, AnnotationRoot, AnyValue, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseLangGraphErrorFields, BaseStore, BinaryOperator, BinaryOperatorAggregate, Checkpoint, CheckpointMetadata, CheckpointTuple, Command, CommandParams, CompiledGraph, CompiledStateGraph, DynamicBarrierValue, END, EmptyChannelError, EmptyInputError, EntrypointOptions, EphemeralValue, GetOperation, GetStateOptions, Graph, GraphBubbleUp, GraphInterrupt, GraphRecursionError, GraphValueError, INTERRUPT, InMemoryStore, Interrupt, InvalidUpdateError, Item, LangGraphRunnableConfig, LastValue, ListNamespacesOperation, MatchCondition, MemorySaver, MessageGraph, Messages, MessagesAnnotation, MessagesZodMeta, MessagesZodState, MultipleChannelSubscriptionOptions, MultipleSubgraphsError, NameSpacePath, NamedBarrierValue, NamespaceMatchType, NodeInterrupt, NodeType, Operation, OperationResults, ParentCommand, Pregel, PregelNode, PregelOptions, PregelParams, PutOperation, REMOVE_ALL_MESSAGES, RemoteException, RetryPolicy, Runtime, START, SearchOperation, Send, SingleChannelSubscriptionOptions, SingleReducer, StateDefinition, StateGraph, StateGraphArgs, StateSnapshot, StateType, StreamMode, StreamOutputMap, TaskOptions, Topic, UnreachableNodeError, UpdateType, WaitForNames, messagesStateReducer as addMessages, copyCheckpoint, emptyCheckpoint, entrypoint, getConfig, getCurrentTaskInput, getPreviousState, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCommand, isGraphBubbleUp, isGraphInterrupt, isInterrupted, isParentCommand, messagesStateReducer, task, writer };
package/dist/index.js CHANGED
@@ -5,17 +5,18 @@ import { BinaryOperatorAggregate } from "./channels/binop.js";
5
5
  import { Annotation } from "./graph/annotation.js";
6
6
  import { Command, END, INTERRUPT, START, Send, isCommand, isInterrupted } from "./constants.js";
7
7
  import { getConfig, getCurrentTaskInput, getStore, getWriter } from "./pregel/utils/config.js";
8
+ import { interrupt } from "./interrupt.js";
8
9
  import { Graph } from "./graph/graph.js";
9
- import { CompiledStateGraph, StateGraph, typedNode } from "./graph/state.js";
10
+ import { CompiledStateGraph, StateGraph } from "./graph/state.js";
10
11
  import { MessageGraph, REMOVE_ALL_MESSAGES, messagesStateReducer } from "./graph/message.js";
11
12
  import { entrypoint, getPreviousState, task } from "./func/index.js";
12
13
  import { MessagesAnnotation, MessagesZodMeta, MessagesZodState } from "./graph/messages_annotation.js";
13
14
  import { AsyncBatchedStore, BaseCheckpointSaver, BaseStore, InMemoryStore, MemorySaver, copyCheckpoint, emptyCheckpoint } from "./web.js";
14
- import { interrupt } from "./interrupt.js";
15
+ import { writer } from "./writer.js";
15
16
 
16
17
  //#region src/index.ts
17
18
  initializeAsyncLocalStorageSingleton();
18
19
 
19
20
  //#endregion
20
- export { Annotation, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseStore, BinaryOperatorAggregate, Command, CompiledStateGraph, END, EmptyChannelError, EmptyInputError, Graph, GraphBubbleUp, GraphInterrupt, GraphRecursionError, GraphValueError, INTERRUPT, InMemoryStore, InvalidUpdateError, MemorySaver, MessageGraph, MessagesAnnotation, MessagesZodMeta, MessagesZodState, MultipleSubgraphsError, NodeInterrupt, ParentCommand, REMOVE_ALL_MESSAGES, RemoteException, START, Send, StateGraph, UnreachableNodeError, messagesStateReducer as addMessages, copyCheckpoint, emptyCheckpoint, entrypoint, getConfig, getCurrentTaskInput, getPreviousState, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCommand, isGraphBubbleUp, isGraphInterrupt, isInterrupted, isParentCommand, messagesStateReducer, task, typedNode };
21
+ export { Annotation, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseStore, BinaryOperatorAggregate, Command, CompiledStateGraph, END, EmptyChannelError, EmptyInputError, Graph, GraphBubbleUp, GraphInterrupt, GraphRecursionError, GraphValueError, INTERRUPT, InMemoryStore, InvalidUpdateError, MemorySaver, MessageGraph, MessagesAnnotation, MessagesZodMeta, MessagesZodState, MultipleSubgraphsError, NodeInterrupt, ParentCommand, REMOVE_ALL_MESSAGES, RemoteException, START, Send, StateGraph, UnreachableNodeError, messagesStateReducer as addMessages, copyCheckpoint, emptyCheckpoint, entrypoint, getConfig, getCurrentTaskInput, getPreviousState, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCommand, isGraphBubbleUp, isGraphInterrupt, isInterrupted, isParentCommand, messagesStateReducer, task, writer };
21
22
  //# 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 \"./setup/async_local_storage.js\";\n\n// Initialize global async local storage instance for tracing\ninitializeAsyncLocalStorageSingleton();\n\nexport * from \"./web.js\";\n\nexport { interrupt } from \"./interrupt.js\";\nexport { getStore, getWriter, getConfig } from \"./pregel/utils/config.js\";\nexport { getPreviousState } from \"./func/index.js\";\nexport { getCurrentTaskInput } from \"./pregel/utils/config.js\";\n"],"mappings":";;;;;;;;;;;;;;;;AAKA"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\nimport { initializeAsyncLocalStorageSingleton } from \"./setup/async_local_storage.js\";\n\n// Initialize global async local storage instance for tracing\ninitializeAsyncLocalStorageSingleton();\n\nexport * from \"./web.js\";\n\nexport { interrupt } from \"./interrupt.js\";\nexport { writer } from \"./writer.js\";\nexport { getStore, getWriter, getConfig } from \"./pregel/utils/config.js\";\nexport { getPreviousState } from \"./func/index.js\";\nexport { getCurrentTaskInput } from \"./pregel/utils/config.js\";\n"],"mappings":";;;;;;;;;;;;;;;;;AAKA"}
@@ -54,7 +54,7 @@ function interrupt(value) {
54
54
  const conf = config.configurable;
55
55
  if (!conf) throw new Error("No configurable found in config");
56
56
  const checkpointer = conf[require_constants.CONFIG_KEY_CHECKPOINTER];
57
- if (!checkpointer) throw new require_errors.GraphValueError("No checkpointer set");
57
+ if (!checkpointer) throw new require_errors.GraphValueError("No checkpointer set", { lc_error_code: "MISSING_CHECKPOINTER" });
58
58
  const scratchpad = conf[require_constants.CONFIG_KEY_SCRATCHPAD];
59
59
  scratchpad.interruptCounter += 1;
60
60
  const idx = scratchpad.interruptCounter;
@@ -1 +1 @@
1
- {"version":3,"file":"interrupt.cjs","names":["config: RunnableConfig | undefined","AsyncLocalStorageProviderSingleton","checkpointer: BaseCheckpointSaver","CONFIG_KEY_CHECKPOINTER","GraphValueError","scratchpad: PregelScratchpad","CONFIG_KEY_SCRATCHPAD","CONFIG_KEY_SEND","RESUME","ns: string[] | undefined","CONFIG_KEY_CHECKPOINT_NS","CHECKPOINT_NAMESPACE_SEPARATOR","XXH3","GraphInterrupt"],"sources":["../src/interrupt.ts"],"sourcesContent":["import { AsyncLocalStorageProviderSingleton } from \"@langchain/core/singletons\";\nimport { RunnableConfig } from \"@langchain/core/runnables\";\nimport {\n BaseCheckpointSaver,\n type PendingWrite,\n} from \"@langchain/langgraph-checkpoint\";\nimport { GraphInterrupt, GraphValueError } from \"./errors.js\";\nimport {\n CONFIG_KEY_CHECKPOINT_NS,\n CONFIG_KEY_SCRATCHPAD,\n CONFIG_KEY_SEND,\n CONFIG_KEY_CHECKPOINTER,\n CHECKPOINT_NAMESPACE_SEPARATOR,\n RESUME,\n} from \"./constants.js\";\nimport { PregelScratchpad } from \"./pregel/types.js\";\nimport { XXH3 } from \"./hash.js\";\n\n/**\n * Interrupts the execution of a graph node.\n * This function can be used to pause execution of a node, and return the value of the `resume`\n * input when the graph is re-invoked using `Command`.\n * Multiple interrupts can be called within a single node, and each will be handled sequentially.\n *\n * When an interrupt is called:\n * 1. If there's a `resume` value available (from a previous `Command`), it returns that value.\n * 2. Otherwise, it throws a `GraphInterrupt` with the provided value\n * 3. The graph can be resumed by passing a `Command` with a `resume` value\n *\n * Because the `interrupt` function propagates by throwing a special `GraphInterrupt` error,\n * you should avoid using `try/catch` blocks around the `interrupt` function,\n * or if you do, ensure that the `GraphInterrupt` error is thrown again within your `catch` block.\n *\n * @param value - The value to include in the interrupt. This will be available in task.interrupts[].value\n * @returns The `resume` value provided when the graph is re-invoked with a Command\n *\n * @example\n * ```typescript\n * // Define a node that uses multiple interrupts\n * const nodeWithInterrupts = () => {\n * // First interrupt - will pause execution and include {value: 1} in task values\n * const answer1 = interrupt({ value: 1 });\n *\n * // Second interrupt - only called after first interrupt is resumed\n * const answer2 = interrupt({ value: 2 });\n *\n * // Use the resume values\n * return { myKey: answer1 + \" \" + answer2 };\n * };\n *\n * // Resume the graph after first interrupt\n * await graph.stream(new Command({ resume: \"answer 1\" }));\n *\n * // Resume the graph after second interrupt\n * await graph.stream(new Command({ resume: \"answer 2\" }));\n * // Final result: { myKey: \"answer 1 answer 2\" }\n * ```\n *\n * @throws {Error} If called outside the context of a graph\n * @throws {GraphInterrupt} When no resume value is available\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function interrupt<I = unknown, R = any>(value: I): R {\n const config: RunnableConfig | undefined =\n AsyncLocalStorageProviderSingleton.getRunnableConfig();\n if (!config) {\n throw new Error(\"Called interrupt() outside the context of a graph.\");\n }\n\n const conf = config.configurable;\n if (!conf) {\n throw new Error(\"No configurable found in config\");\n }\n\n const checkpointer: BaseCheckpointSaver = conf[CONFIG_KEY_CHECKPOINTER];\n if (!checkpointer) throw new GraphValueError(\"No checkpointer set\");\n\n // Track interrupt index\n const scratchpad: PregelScratchpad = conf[CONFIG_KEY_SCRATCHPAD];\n scratchpad.interruptCounter += 1;\n const idx = scratchpad.interruptCounter;\n\n // Find previous resume values\n if (scratchpad.resume.length > 0 && idx < scratchpad.resume.length) {\n conf[CONFIG_KEY_SEND]?.([[RESUME, scratchpad.resume] as PendingWrite]);\n return scratchpad.resume[idx] as R;\n }\n\n // Find current resume value\n if (scratchpad.nullResume !== undefined) {\n if (scratchpad.resume.length !== idx) {\n throw new Error(\n `Resume length mismatch: ${scratchpad.resume.length} !== ${idx}`\n );\n }\n const v = scratchpad.consumeNullResume();\n scratchpad.resume.push(v);\n conf[CONFIG_KEY_SEND]?.([[RESUME, scratchpad.resume] as PendingWrite]);\n return v as R;\n }\n\n // No resume value found\n const ns: string[] | undefined = conf[CONFIG_KEY_CHECKPOINT_NS]?.split(\n CHECKPOINT_NAMESPACE_SEPARATOR\n );\n\n const id = ns ? XXH3(ns.join(CHECKPOINT_NAMESPACE_SEPARATOR)) : undefined;\n throw new GraphInterrupt([{ id, value }]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,SAAgB,UAAgC,OAAa;CAC3D,MAAMA,SACJC,+DAAmC;AACrC,KAAI,CAAC,OACH,OAAM,IAAI,MAAM;CAGlB,MAAM,OAAO,OAAO;AACpB,KAAI,CAAC,KACH,OAAM,IAAI,MAAM;CAGlB,MAAMC,eAAoC,KAAKC;AAC/C,KAAI,CAAC,aAAc,OAAM,IAAIC,+BAAgB;CAG7C,MAAMC,aAA+B,KAAKC;AAC1C,YAAW,oBAAoB;CAC/B,MAAM,MAAM,WAAW;AAGvB,KAAI,WAAW,OAAO,SAAS,KAAK,MAAM,WAAW,OAAO,QAAQ;AAClE,OAAKC,qCAAmB,CAAC,CAACC,0BAAQ,WAAW;AAC7C,SAAO,WAAW,OAAO;;AAI3B,KAAI,WAAW,eAAe,QAAW;AACvC,MAAI,WAAW,OAAO,WAAW,IAC/B,OAAM,IAAI,MACR,2BAA2B,WAAW,OAAO,OAAO,OAAO;EAG/D,MAAM,IAAI,WAAW;AACrB,aAAW,OAAO,KAAK;AACvB,OAAKD,qCAAmB,CAAC,CAACC,0BAAQ,WAAW;AAC7C,SAAO;;CAIT,MAAMC,KAA2B,KAAKC,6CAA2B,MAC/DC;CAGF,MAAM,KAAK,KAAKC,kBAAK,GAAG,KAAKD,qDAAmC;AAChE,OAAM,IAAIE,8BAAe,CAAC;EAAE;EAAI"}
1
+ {"version":3,"file":"interrupt.cjs","names":["config: RunnableConfig | undefined","AsyncLocalStorageProviderSingleton","checkpointer: BaseCheckpointSaver","CONFIG_KEY_CHECKPOINTER","GraphValueError","scratchpad: PregelScratchpad","CONFIG_KEY_SCRATCHPAD","CONFIG_KEY_SEND","RESUME","ns: string[] | undefined","CONFIG_KEY_CHECKPOINT_NS","CHECKPOINT_NAMESPACE_SEPARATOR","XXH3","GraphInterrupt"],"sources":["../src/interrupt.ts"],"sourcesContent":["import { AsyncLocalStorageProviderSingleton } from \"@langchain/core/singletons\";\nimport { RunnableConfig } from \"@langchain/core/runnables\";\nimport {\n BaseCheckpointSaver,\n type PendingWrite,\n} from \"@langchain/langgraph-checkpoint\";\nimport { GraphInterrupt, GraphValueError } from \"./errors.js\";\nimport {\n CONFIG_KEY_CHECKPOINT_NS,\n CONFIG_KEY_SCRATCHPAD,\n CONFIG_KEY_SEND,\n CONFIG_KEY_CHECKPOINTER,\n CHECKPOINT_NAMESPACE_SEPARATOR,\n RESUME,\n} from \"./constants.js\";\nimport { PregelScratchpad } from \"./pregel/types.js\";\nimport { XXH3 } from \"./hash.js\";\n\n/**\n * Interrupts the execution of a graph node.\n * This function can be used to pause execution of a node, and return the value of the `resume`\n * input when the graph is re-invoked using `Command`.\n * Multiple interrupts can be called within a single node, and each will be handled sequentially.\n *\n * When an interrupt is called:\n * 1. If there's a `resume` value available (from a previous `Command`), it returns that value.\n * 2. Otherwise, it throws a `GraphInterrupt` with the provided value\n * 3. The graph can be resumed by passing a `Command` with a `resume` value\n *\n * Because the `interrupt` function propagates by throwing a special `GraphInterrupt` error,\n * you should avoid using `try/catch` blocks around the `interrupt` function,\n * or if you do, ensure that the `GraphInterrupt` error is thrown again within your `catch` block.\n *\n * @param value - The value to include in the interrupt. This will be available in task.interrupts[].value\n * @returns The `resume` value provided when the graph is re-invoked with a Command\n *\n * @example\n * ```typescript\n * // Define a node that uses multiple interrupts\n * const nodeWithInterrupts = () => {\n * // First interrupt - will pause execution and include {value: 1} in task values\n * const answer1 = interrupt({ value: 1 });\n *\n * // Second interrupt - only called after first interrupt is resumed\n * const answer2 = interrupt({ value: 2 });\n *\n * // Use the resume values\n * return { myKey: answer1 + \" \" + answer2 };\n * };\n *\n * // Resume the graph after first interrupt\n * await graph.stream(new Command({ resume: \"answer 1\" }));\n *\n * // Resume the graph after second interrupt\n * await graph.stream(new Command({ resume: \"answer 2\" }));\n * // Final result: { myKey: \"answer 1 answer 2\" }\n * ```\n *\n * @throws {Error} If called outside the context of a graph\n * @throws {GraphInterrupt} When no resume value is available\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function interrupt<I = unknown, R = any>(value: I): R {\n const config: RunnableConfig | undefined =\n AsyncLocalStorageProviderSingleton.getRunnableConfig();\n if (!config) {\n throw new Error(\"Called interrupt() outside the context of a graph.\");\n }\n\n const conf = config.configurable;\n if (!conf) {\n throw new Error(\"No configurable found in config\");\n }\n\n const checkpointer: BaseCheckpointSaver = conf[CONFIG_KEY_CHECKPOINTER];\n if (!checkpointer) {\n throw new GraphValueError(\"No checkpointer set\", {\n lc_error_code: \"MISSING_CHECKPOINTER\",\n });\n }\n\n // Track interrupt index\n const scratchpad: PregelScratchpad = conf[CONFIG_KEY_SCRATCHPAD];\n scratchpad.interruptCounter += 1;\n const idx = scratchpad.interruptCounter;\n\n // Find previous resume values\n if (scratchpad.resume.length > 0 && idx < scratchpad.resume.length) {\n conf[CONFIG_KEY_SEND]?.([[RESUME, scratchpad.resume] as PendingWrite]);\n return scratchpad.resume[idx] as R;\n }\n\n // Find current resume value\n if (scratchpad.nullResume !== undefined) {\n if (scratchpad.resume.length !== idx) {\n throw new Error(\n `Resume length mismatch: ${scratchpad.resume.length} !== ${idx}`\n );\n }\n const v = scratchpad.consumeNullResume();\n scratchpad.resume.push(v);\n conf[CONFIG_KEY_SEND]?.([[RESUME, scratchpad.resume] as PendingWrite]);\n return v as R;\n }\n\n // No resume value found\n const ns: string[] | undefined = conf[CONFIG_KEY_CHECKPOINT_NS]?.split(\n CHECKPOINT_NAMESPACE_SEPARATOR\n );\n\n const id = ns ? XXH3(ns.join(CHECKPOINT_NAMESPACE_SEPARATOR)) : undefined;\n throw new GraphInterrupt([{ id, value }]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DA,SAAgB,UAAgC,OAAa;CAC3D,MAAMA,SACJC,+DAAmC;AACrC,KAAI,CAAC,OACH,OAAM,IAAI,MAAM;CAGlB,MAAM,OAAO,OAAO;AACpB,KAAI,CAAC,KACH,OAAM,IAAI,MAAM;CAGlB,MAAMC,eAAoC,KAAKC;AAC/C,KAAI,CAAC,aACH,OAAM,IAAIC,+BAAgB,uBAAuB,EAC/C,eAAe;CAKnB,MAAMC,aAA+B,KAAKC;AAC1C,YAAW,oBAAoB;CAC/B,MAAM,MAAM,WAAW;AAGvB,KAAI,WAAW,OAAO,SAAS,KAAK,MAAM,WAAW,OAAO,QAAQ;AAClE,OAAKC,qCAAmB,CAAC,CAACC,0BAAQ,WAAW;AAC7C,SAAO,WAAW,OAAO;;AAI3B,KAAI,WAAW,eAAe,QAAW;AACvC,MAAI,WAAW,OAAO,WAAW,IAC/B,OAAM,IAAI,MACR,2BAA2B,WAAW,OAAO,OAAO,OAAO;EAG/D,MAAM,IAAI,WAAW;AACrB,aAAW,OAAO,KAAK;AACvB,OAAKD,qCAAmB,CAAC,CAACC,0BAAQ,WAAW;AAC7C,SAAO;;CAIT,MAAMC,KAA2B,KAAKC,6CAA2B,MAC/DC;CAGF,MAAM,KAAK,KAAKC,kBAAK,GAAG,KAAKD,qDAAmC;AAChE,OAAM,IAAIE,8BAAe,CAAC;EAAE;EAAI"}
package/dist/interrupt.js CHANGED
@@ -53,7 +53,7 @@ function interrupt(value) {
53
53
  const conf = config.configurable;
54
54
  if (!conf) throw new Error("No configurable found in config");
55
55
  const checkpointer = conf[CONFIG_KEY_CHECKPOINTER];
56
- if (!checkpointer) throw new GraphValueError("No checkpointer set");
56
+ if (!checkpointer) throw new GraphValueError("No checkpointer set", { lc_error_code: "MISSING_CHECKPOINTER" });
57
57
  const scratchpad = conf[CONFIG_KEY_SCRATCHPAD];
58
58
  scratchpad.interruptCounter += 1;
59
59
  const idx = scratchpad.interruptCounter;