@langchain/langgraph 1.5.0 → 1.5.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 (55) hide show
  1. package/dist/channels/base.cjs +10 -3
  2. package/dist/channels/base.cjs.map +1 -1
  3. package/dist/channels/base.d.cts.map +1 -1
  4. package/dist/channels/base.d.ts.map +1 -1
  5. package/dist/channels/base.js +10 -3
  6. package/dist/channels/base.js.map +1 -1
  7. package/dist/channels/binop.cjs +2 -1
  8. package/dist/channels/binop.cjs.map +1 -1
  9. package/dist/channels/binop.d.cts.map +1 -1
  10. package/dist/channels/binop.d.ts.map +1 -1
  11. package/dist/channels/binop.js +2 -1
  12. package/dist/channels/binop.js.map +1 -1
  13. package/dist/errors.cjs +22 -0
  14. package/dist/errors.cjs.map +1 -1
  15. package/dist/errors.d.cts +10 -1
  16. package/dist/errors.d.cts.map +1 -1
  17. package/dist/errors.d.ts +10 -1
  18. package/dist/errors.d.ts.map +1 -1
  19. package/dist/errors.js +21 -1
  20. package/dist/errors.js.map +1 -1
  21. package/dist/graph/messages_reducer.cjs +23 -6
  22. package/dist/graph/messages_reducer.cjs.map +1 -1
  23. package/dist/graph/messages_reducer.d.cts +4 -2
  24. package/dist/graph/messages_reducer.d.cts.map +1 -1
  25. package/dist/graph/messages_reducer.d.ts +4 -2
  26. package/dist/graph/messages_reducer.d.ts.map +1 -1
  27. package/dist/graph/messages_reducer.js +24 -7
  28. package/dist/graph/messages_reducer.js.map +1 -1
  29. package/dist/index.cjs +2 -0
  30. package/dist/index.d.cts +2 -2
  31. package/dist/index.d.ts +2 -2
  32. package/dist/index.js +2 -2
  33. package/dist/interrupt.cjs +9 -1
  34. package/dist/interrupt.cjs.map +1 -1
  35. package/dist/interrupt.d.cts.map +1 -1
  36. package/dist/interrupt.d.ts.map +1 -1
  37. package/dist/interrupt.js +10 -2
  38. package/dist/interrupt.js.map +1 -1
  39. package/dist/pregel/debug.cjs +1 -0
  40. package/dist/pregel/debug.cjs.map +1 -1
  41. package/dist/pregel/debug.js +1 -0
  42. package/dist/pregel/debug.js.map +1 -1
  43. package/dist/pregel/loop.cjs +15 -8
  44. package/dist/pregel/loop.cjs.map +1 -1
  45. package/dist/pregel/loop.js +15 -8
  46. package/dist/pregel/loop.js.map +1 -1
  47. package/dist/pregel/runner.cjs +1 -1
  48. package/dist/pregel/runner.cjs.map +1 -1
  49. package/dist/pregel/runner.js +2 -2
  50. package/dist/pregel/runner.js.map +1 -1
  51. package/dist/web.cjs +2 -0
  52. package/dist/web.d.cts +2 -2
  53. package/dist/web.d.ts +2 -2
  54. package/dist/web.js +2 -2
  55. package/package.json +2 -2
package/dist/errors.d.cts CHANGED
@@ -84,6 +84,15 @@ declare class ParentCommand extends GraphBubbleUp {
84
84
  }
85
85
  declare function isParentCommand(e?: unknown): e is ParentCommand;
86
86
  declare function isGraphBubbleUp(e?: unknown): e is GraphBubbleUp;
87
+ /** @internal */
88
+ declare function _markInvalidResume(error: unknown): void;
89
+ /**
90
+ * Whether `error` was thrown because a resume value didn't match the interrupt's
91
+ * `responseSchema`, directly or as the `cause` of a wrapping error (such as one
92
+ * from agent middleware). The resume fails once the step's other tasks finish,
93
+ * and the interrupt can be answered again.
94
+ */
95
+ declare function isInvalidResume(error: unknown): boolean;
87
96
  declare function isGraphInterrupt(e?: unknown): e is GraphInterrupt;
88
97
  /**
89
98
  * Raised when a node invocation exceeds one of its configured timeouts.
@@ -187,5 +196,5 @@ declare class StateGraphInputError extends BaseLangGraphError {
187
196
  */
188
197
  declare const getSubgraphsSeenSet: () => any;
189
198
  //#endregion
190
- export { BaseLangGraphError, BaseLangGraphErrorFields, EmptyChannelError, EmptyInputError, GraphBubbleUp, GraphDrained, GraphInterrupt, GraphRecursionError, GraphValueError, InvalidUpdateError, MultipleSubgraphsError, NodeError, NodeInterrupt, NodeTimeoutError, ParentCommand, RemoteException, StateGraphInputError, UnreachableNodeError, getSubgraphsSeenSet, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isNodeError, isNodeTimeoutError, isParentCommand };
199
+ export { BaseLangGraphError, BaseLangGraphErrorFields, EmptyChannelError, EmptyInputError, GraphBubbleUp, GraphDrained, GraphInterrupt, GraphRecursionError, GraphValueError, InvalidUpdateError, MultipleSubgraphsError, NodeError, NodeInterrupt, NodeTimeoutError, ParentCommand, RemoteException, StateGraphInputError, UnreachableNodeError, _markInvalidResume, getSubgraphsSeenSet, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isInvalidResume, isNodeError, isNodeTimeoutError, isParentCommand };
191
200
  //# sourceMappingURL=errors.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.cts","names":[],"sources":["../src/errors.ts"],"mappings":";;;KAIY,wBAAA;EACV,aAAA;AAAA;;cAWW,kBAAA,SAA2B,KAAA;EACtC,aAAA;EAEA,WAAA,CAAY,OAAA,WAAkB,MAAA,GAAS,wBAAA;AAAA;AAAA,cAU5B,aAAA,SAAsB,kBAAA;EAAA,IAC7B,YAAA,CAAA;AAAA;AAAA,cAKO,mBAAA,SAA4B,kBAAA;EACvC,WAAA,CAAY,OAAA,WAAkB,MAAA,GAAS,wBAAA;EAAA,WAK5B,iBAAA,CAAA;AAAA;AAAA,cAKA,eAAA,SAAwB,kBAAA;EACnC,WAAA,CAAY,OAAA,WAAkB,MAAA,GAAS,wBAAA;EAAA,WAK5B,iBAAA,CAAA;AAAA;AAvBb;;;;;AAMA;;AANA,cAmCa,YAAA,SAAqB,aAAA;EAChC,MAAA;EAEA,WAAA,CAAY,MAAA,WAA6B,MAAA,GAAS,wBAAA;EAAA,WAMvC,iBAAA,CAAA;AAAA;AAAA,iBAKG,cAAA,CAAe,CAAA,aAAc,CAAA,IAAK,YAAA;AAAA,cAMrC,cAAA,SAAuB,aAAA;EAClC,UAAA,EAAY,SAAA;EAEZ,WAAA,CAAY,UAAA,GAAa,SAAA,IAAa,MAAA,GAAS,wBAAA;EAAA,WAMpC,iBAAA,CAAA;AAAA;;cAMA,a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ACA,WAAA;EAAA,GAEF,WAAA,GAAc,wBAAA;EAAA,WAgCL,iBAAA,CAAA;AAAA;AAAA,iBAKG,kBAAA,CAAmB,CAAA,aAAc,CAAA,IAAK,gBAAA;AAAA,cAOzC,eAAA,SAAwB,kBAAA;EACnC,WAAA,CAAY,OAAA,WAAkB,MAAA,GAAS,wBAAA;EAAA,WAK5B,iBAAA,CAAA;AAAA;AAAA,cAKA,iBAAA,SAA0B,kBAAA;EACrC,WAAA,CAAY,OAAA,WAAkB,MAAA,GAAS,wBAAA;EAAA,WAS5B,iBAAA,CAAA;AAAA;AAAA,cAKA,kBAAA,SAA2B,kBAAA;EACtC,WAAA,CAAY,OAAA,WAAkB,MAAA,GAAS,wBAAA;EAAA,WAK5B,iBAAA,CAAA;AAAA;;;;cAQA,sBAAA,SAA+B,kBAAA;EAC1C,WAAA,CAAY,OAAA,WAAkB,MAAA,GAAS,wBAAA;EAAA,WAK5B,iBAAA,CAAA;AAAA;AAAA,cAKA,oBAAA,SAA6B,kBAAA;EACxC,WAAA,CAAY,OAAA,WAAkB,MAAA,GAAS,wBAAA;EAAA,WAK5B,iBAAA,CAAA;AAAA;;;;cAQA,eAAA,SAAwB,kBAAA;EACnC,WAAA,CAAY,OAAA,WAAkB,MAAA,GAAS,wBAAA;EAAA,WAK5B,iBAAA,CAAA;AAAA;;;;;AApLb;;;;;AAaA;;;;;;;;cA6La,oBAAA,SAA6B,kBAAA;EApK7B;;;;;EA0KX,WAAA,CAAY,OAAA,WAAkB,MAAA,GAAS,wBAAA;EArKvC;;;EAAA,WA+KW,iBAAA,CAAA;AAAA;;;;cAQA,mBAAA"}
package/dist/errors.d.ts CHANGED
@@ -84,6 +84,15 @@ declare class ParentCommand extends GraphBubbleUp {
84
84
  }
85
85
  declare function isParentCommand(e?: unknown): e is ParentCommand;
86
86
  declare function isGraphBubbleUp(e?: unknown): e is GraphBubbleUp;
87
+ /** @internal */
88
+ declare function _markInvalidResume(error: unknown): void;
89
+ /**
90
+ * Whether `error` was thrown because a resume value didn't match the interrupt's
91
+ * `responseSchema`, directly or as the `cause` of a wrapping error (such as one
92
+ * from agent middleware). The resume fails once the step's other tasks finish,
93
+ * and the interrupt can be answered again.
94
+ */
95
+ declare function isInvalidResume(error: unknown): boolean;
87
96
  declare function isGraphInterrupt(e?: unknown): e is GraphInterrupt;
88
97
  /**
89
98
  * Raised when a node invocation exceeds one of its configured timeouts.
@@ -187,5 +196,5 @@ declare class StateGraphInputError extends BaseLangGraphError {
187
196
  */
188
197
  declare const getSubgraphsSeenSet: () => any;
189
198
  //#endregion
190
- export { BaseLangGraphError, BaseLangGraphErrorFields, EmptyChannelError, EmptyInputError, GraphBubbleUp, GraphDrained, GraphInterrupt, GraphRecursionError, GraphValueError, InvalidUpdateError, MultipleSubgraphsError, NodeError, NodeInterrupt, NodeTimeoutError, ParentCommand, RemoteException, StateGraphInputError, UnreachableNodeError, getSubgraphsSeenSet, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isNodeError, isNodeTimeoutError, isParentCommand };
199
+ export { BaseLangGraphError, BaseLangGraphErrorFields, EmptyChannelError, EmptyInputError, GraphBubbleUp, GraphDrained, GraphInterrupt, GraphRecursionError, GraphValueError, InvalidUpdateError, MultipleSubgraphsError, NodeError, NodeInterrupt, NodeTimeoutError, ParentCommand, RemoteException, StateGraphInputError, UnreachableNodeError, _markInvalidResume, getSubgraphsSeenSet, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isInvalidResume, isNodeError, isNodeTimeoutError, isParentCommand };
191
200
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","names":[],"sources":["../src/errors.ts"],"mappings":";;;KAIY,wBAAA;EACV,aAAA;AAAA;;cAWW,kBAAA,SAA2B,KAAA;EACtC,aAAA;EAEA,WAAA,CAAY,OAAA,WAAkB,MAAA,GAAS,wBAAA;AAAA;AAAA,cAU5B,aAAA,SAAsB,kBAAA;EAAA,IAC7B,YAAA,CAAA;AAAA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WAAA,CAAY,OAAA,WAAkB,MAAA,GAAS,wBAAA;EAAA,WAK5B,iBAAA,CAAA;AAAA;;;;cAQA,eAAA,SAAwB,kBAAA;EACnC,WAAA,CAAY,OAAA,WAAkB,MAAA,GAAS,wBAAA;EAAA,WAK5B,iBAAA,CAAA;AAAA;;;;;AApLb;;;;;AAaA;;;;;;;;cA6La,oBAAA,SAA6B,kBAAA;EApK7B;;;;;EA0KX,WAAA,CAAY,OAAA,WAAkB,MAAA,GAAS,wBAAA;EArKvC;;;EAAA,WA+KW,iBAAA,CAAA;AAAA;;;;cAQA,mBAAA"}
package/dist/errors.js CHANGED
@@ -132,6 +132,26 @@ function isParentCommand(e) {
132
132
  function isGraphBubbleUp(e) {
133
133
  return e !== void 0 && e.is_bubble_up === true;
134
134
  }
135
+ const INVALID_RESUME = Symbol.for("langgraph.invalid_resume");
136
+ /** @internal */
137
+ function _markInvalidResume(error) {
138
+ if (typeof error === "object" && error !== null) Object.defineProperty(error, INVALID_RESUME, { value: true });
139
+ }
140
+ /**
141
+ * Whether `error` was thrown because a resume value didn't match the interrupt's
142
+ * `responseSchema`, directly or as the `cause` of a wrapping error (such as one
143
+ * from agent middleware). The resume fails once the step's other tasks finish,
144
+ * and the interrupt can be answered again.
145
+ */
146
+ function isInvalidResume(error) {
147
+ let current = error;
148
+ for (let depth = 0; depth < 10; depth += 1) {
149
+ if (typeof current !== "object" || current === null) return false;
150
+ if (current[INVALID_RESUME] === true) return true;
151
+ current = current.cause;
152
+ }
153
+ return false;
154
+ }
135
155
  function isGraphInterrupt(e) {
136
156
  return e !== void 0 && [GraphInterrupt.unminifiable_name, NodeInterrupt.unminifiable_name].includes(e.name);
137
157
  }
@@ -298,6 +318,6 @@ const getSubgraphsSeenSet = () => {
298
318
  return globalThis[Symbol.for("LG_CHECKPOINT_SEEN_NS_SET")];
299
319
  };
300
320
  //#endregion
301
- export { BaseLangGraphError, EmptyChannelError, EmptyInputError, GraphBubbleUp, GraphDrained, GraphInterrupt, GraphRecursionError, GraphValueError, InvalidUpdateError, MultipleSubgraphsError, NodeError, NodeInterrupt, NodeTimeoutError, ParentCommand, RemoteException, StateGraphInputError, UnreachableNodeError, getSubgraphsSeenSet, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isNodeError, isNodeTimeoutError, isParentCommand };
321
+ export { BaseLangGraphError, EmptyChannelError, EmptyInputError, GraphBubbleUp, GraphDrained, GraphInterrupt, GraphRecursionError, GraphValueError, InvalidUpdateError, MultipleSubgraphsError, NodeError, NodeInterrupt, NodeTimeoutError, ParentCommand, RemoteException, StateGraphInputError, UnreachableNodeError, _markInvalidResume, getSubgraphsSeenSet, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isInvalidResume, isNodeError, isNodeTimeoutError, isParentCommand };
302
322
 
303
323
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { Command, Interrupt } from \"./constants.js\";\n\n// When editing, make sure to update the index found here:\n// https://langchain-ai.github.io/langgraphjs/troubleshooting/errors/\nexport type BaseLangGraphErrorFields = {\n lc_error_code?:\n | \"GRAPH_RECURSION_LIMIT\"\n | \"INVALID_CONCURRENT_GRAPH_UPDATE\"\n | \"INVALID_GRAPH_NODE_RETURN_VALUE\"\n | \"MISSING_CHECKPOINTER\"\n | \"MULTIPLE_SUBGRAPHS\"\n | \"UNREACHABLE_NODE\";\n};\n\n// TODO: Merge with base LangChain error class when we drop support for core@0.2.0\n/** @category Errors */\nexport class BaseLangGraphError extends Error {\n lc_error_code?: string;\n\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n let finalMessage = message ?? \"\";\n if (fields?.lc_error_code) {\n finalMessage = `${finalMessage}\\n\\nTroubleshooting URL: https://docs.langchain.com/oss/javascript/langgraph/${fields.lc_error_code}/\\n`;\n }\n super(finalMessage);\n this.lc_error_code = fields?.lc_error_code;\n }\n}\n\nexport class GraphBubbleUp extends BaseLangGraphError {\n get is_bubble_up() {\n return true;\n }\n}\n\nexport class GraphRecursionError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"GraphRecursionError\";\n }\n\n static get unminifiable_name() {\n return \"GraphRecursionError\";\n }\n}\n\nexport class GraphValueError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"GraphValueError\";\n }\n\n static get unminifiable_name() {\n return \"GraphValueError\";\n }\n}\n\n/**\n * Raised when a graph run exits early due to a drain request.\n *\n * This indicates the graph stopped cooperatively at a superstep boundary\n * because {@link RunControl#requestDrain} was called (e.g., in response to\n * SIGTERM). The checkpoint is saved and the run can be resumed later.\n */\nexport class GraphDrained extends GraphBubbleUp {\n reason: string;\n\n constructor(reason: string = \"shutdown\", fields?: BaseLangGraphErrorFields) {\n super(`Graph drained: ${reason}`, fields);\n this.name = \"GraphDrained\";\n this.reason = reason;\n }\n\n static get unminifiable_name() {\n return \"GraphDrained\";\n }\n}\n\nexport function isGraphDrained(e?: unknown): e is GraphDrained {\n return (\n e !== undefined && (e as Error).name === GraphDrained.unminifiable_name\n );\n}\n\nexport class GraphInterrupt extends GraphBubbleUp {\n interrupts: Interrupt[];\n\n constructor(interrupts?: Interrupt[], fields?: BaseLangGraphErrorFields) {\n super(JSON.stringify(interrupts, null, 2), fields);\n this.name = \"GraphInterrupt\";\n this.interrupts = interrupts ?? [];\n }\n\n static get unminifiable_name() {\n return \"GraphInterrupt\";\n }\n}\n\n/** Raised by a node to interrupt execution. */\nexport class NodeInterrupt extends GraphInterrupt {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(message: any, fields?: BaseLangGraphErrorFields) {\n super([{ value: message }], fields);\n this.name = \"NodeInterrupt\";\n }\n\n static get unminifiable_name() {\n return \"NodeInterrupt\";\n }\n}\n\n/**\n * Failure context passed to a node-level error handler.\n *\n * A node-level error handler is registered via\n * `StateGraph.addNode(name, fn, { errorHandler })`. The handler runs ONLY after\n * the failing node's {@link RetryPolicy} is exhausted, so retry and handling\n * stay decoupled. The handler receives the failed node's name and the thrown\n * error via a `NodeError` instance, can return a state update, and can route to\n * a recovery branch via `new Command({ goto })` (saga / compensation flows).\n *\n * @example\n * ```ts\n * import { NodeError } from \"@langchain/langgraph\";\n *\n * function handler(state: State, error: NodeError) {\n * return new Command({\n * update: { status: `recovered from ${error.node}: ${error.error.message}` },\n * goto: \"finalize\",\n * });\n * }\n * ```\n */\nexport class NodeError {\n /** Name of the node whose execution failed. */\n node: string;\n\n /** Error thrown by the failed node. */\n error: Error;\n\n constructor(node: string, error: Error) {\n this.node = node;\n this.error = error;\n }\n\n static get unminifiable_name() {\n return \"NodeError\";\n }\n}\n\n/**\n * Type guard that checks whether a value is a {@link NodeError}.\n */\nexport function isNodeError(e?: unknown): e is NodeError {\n return (\n e != null &&\n typeof e === \"object\" &&\n e.constructor != null &&\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (e.constructor as any).unminifiable_name === NodeError.unminifiable_name\n );\n}\n\nexport class ParentCommand extends GraphBubbleUp {\n command: Command;\n\n constructor(command: Command) {\n super();\n this.name = \"ParentCommand\";\n this.command = command;\n }\n\n static get unminifiable_name() {\n return \"ParentCommand\";\n }\n}\n\nexport function isParentCommand(e?: unknown): e is ParentCommand {\n return (\n e !== undefined &&\n (e as ParentCommand).name === ParentCommand.unminifiable_name\n );\n}\n\nexport function isGraphBubbleUp(e?: unknown): e is GraphBubbleUp {\n return e !== undefined && (e as GraphBubbleUp).is_bubble_up === true;\n}\n\nexport function isGraphInterrupt(e?: unknown): e is GraphInterrupt {\n return (\n e !== undefined &&\n [\n GraphInterrupt.unminifiable_name,\n NodeInterrupt.unminifiable_name,\n ].includes((e as Error).name)\n );\n}\n\n/**\n * Raised when a node invocation exceeds one of its configured timeouts.\n *\n * Does **not** extend {@link GraphBubbleUp} (so it flows through the normal node\n * error path) and is intentionally treated as retryable by the default retry\n * policy — its message/name do not match the default `retryOn` blocklist, so a\n * configured {@link RetryPolicy} will retry it (see langchain-ai/langgraph#7659).\n *\n * Both {@link NodeTimeoutError.runTimeout} and {@link NodeTimeoutError.idleTimeout}\n * reflect the configured policy at the time of the failure (each `undefined` if\n * not configured). {@link NodeTimeoutError.kind} and {@link NodeTimeoutError.timeout}\n * identify which one fired.\n *\n * @category Errors\n */\nexport class NodeTimeoutError extends BaseLangGraphError {\n /** Name of the node/task that timed out. */\n node: string;\n\n /** Which timeout fired: a hard `\"run\"` cap or a progress-resetting `\"idle\"` cap. */\n kind: \"run\" | \"idle\";\n\n /** The value (ms) of the timeout that fired (`runTimeout` or `idleTimeout`). */\n timeout: number;\n\n /** Elapsed time (ms) since the attempt started, at the moment the timeout fired. */\n elapsed: number;\n\n /** Configured run timeout (ms), if any. */\n runTimeout?: number;\n\n /** Configured idle timeout (ms), if any. */\n idleTimeout?: number;\n\n constructor(\n fields: {\n node: string;\n elapsed: number;\n kind: \"run\" | \"idle\";\n runTimeout?: number;\n idleTimeout?: number;\n },\n errorFields?: BaseLangGraphErrorFields\n ) {\n const { node, elapsed, kind, runTimeout, idleTimeout } = fields;\n let message: string;\n let timeout: number;\n if (kind === \"idle\") {\n if (idleTimeout === undefined) {\n throw new Error(\"idleTimeout is required when kind='idle'\");\n }\n timeout = idleTimeout;\n message =\n `Node \"${node}\" exceeded its idle timeout of ${idleTimeout}ms ` +\n `without making progress (elapsed: ${elapsed}ms).`;\n } else {\n if (runTimeout === undefined) {\n throw new Error(\"runTimeout is required when kind='run'\");\n }\n timeout = runTimeout;\n message =\n `Node \"${node}\" exceeded its run timeout of ${runTimeout}ms ` +\n `(elapsed: ${elapsed}ms).`;\n }\n super(message, errorFields);\n this.name = \"NodeTimeoutError\";\n this.node = node;\n this.kind = kind;\n this.timeout = timeout;\n this.elapsed = elapsed;\n this.runTimeout = runTimeout;\n this.idleTimeout = idleTimeout;\n }\n\n static get unminifiable_name() {\n return \"NodeTimeoutError\";\n }\n}\n\nexport function isNodeTimeoutError(e?: unknown): e is NodeTimeoutError {\n return (\n e !== undefined &&\n (e as NodeTimeoutError).name === NodeTimeoutError.unminifiable_name\n );\n}\n\nexport class EmptyInputError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"EmptyInputError\";\n }\n\n static get unminifiable_name() {\n return \"EmptyInputError\";\n }\n}\n\nexport class EmptyChannelError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n // Skip expensive stack trace capture — used for control flow on channel reads.\n const prevLimit = Error.stackTraceLimit;\n Error.stackTraceLimit = 0;\n super(message, fields);\n Error.stackTraceLimit = prevLimit;\n this.name = \"EmptyChannelError\";\n }\n\n static get unminifiable_name() {\n return \"EmptyChannelError\";\n }\n}\n\nexport class InvalidUpdateError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"InvalidUpdateError\";\n }\n\n static get unminifiable_name() {\n return \"InvalidUpdateError\";\n }\n}\n\n/**\n * @deprecated This exception type is no longer thrown.\n */\nexport class MultipleSubgraphsError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"MultipleSubgraphError\";\n }\n\n static get unminifiable_name() {\n return \"MultipleSubgraphError\";\n }\n}\n\nexport class UnreachableNodeError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"UnreachableNodeError\";\n }\n\n static get unminifiable_name() {\n return \"UnreachableNodeError\";\n }\n}\n\n/**\n * Exception raised when an error occurs in the remote graph.\n */\nexport class RemoteException extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"RemoteException\";\n }\n\n static get unminifiable_name() {\n return \"RemoteException\";\n }\n}\n\n/**\n * Error thrown when invalid input is provided to a StateGraph.\n *\n * This typically means that the input to the StateGraph constructor or builder\n * did not match the required types. A valid input should be a\n * StateDefinition, an Annotation.Root, or a Zod schema.\n *\n * @example\n * // Example of incorrect usage:\n * try {\n * new StateGraph({ foo: \"bar\" }); // Not a valid input\n * } catch (err) {\n * if (err instanceof StateGraphInputError) {\n * console.error(err.message);\n * }\n * }\n */\nexport class StateGraphInputError extends BaseLangGraphError {\n /**\n * Create a new StateGraphInputError.\n * @param message - Optional custom error message.\n * @param fields - Optional additional error fields.\n */\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"StateGraphInputError\";\n this.message =\n \"Invalid StateGraph input. Make sure to pass a valid StateDefinition, Annotation.Root, or Zod schema.\";\n }\n\n /**\n * The unminifiable (static, human-readable) error name for this error class.\n */\n static get unminifiable_name() {\n return \"StateGraphInputError\";\n }\n}\n\n/**\n * Used for subgraph detection.\n */\nexport const getSubgraphsSeenSet = () => {\n if (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (globalThis as any)[Symbol.for(\"LG_CHECKPOINT_SEEN_NS_SET\")] === undefined\n ) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (globalThis as any)[Symbol.for(\"LG_CHECKPOINT_SEEN_NS_SET\")] = new Set();\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (globalThis as any)[Symbol.for(\"LG_CHECKPOINT_SEEN_NS_SET\")];\n};\n"],"mappings":";;AAgBA,IAAa,qBAAb,cAAwC,MAAM;CAC5C;CAEA,YAAY,SAAkB,QAAmC;EAC/D,IAAI,eAAe,WAAW;AAC9B,MAAI,QAAQ,cACV,gBAAe,GAAG,aAAa,+EAA+E,OAAO,cAAc;AAErI,QAAM,aAAa;AACnB,OAAK,gBAAgB,QAAQ;;;AAIjC,IAAa,gBAAb,cAAmC,mBAAmB;CACpD,IAAI,eAAe;AACjB,SAAO;;;AAIX,IAAa,sBAAb,cAAyC,mBAAmB;CAC1D,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS,OAAO;AACtB,OAAK,OAAO;;CAGd,WAAW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AY,MAAM;AACxB,QAAM,kBAAkB;AACxB,QAAM,SAAS,OAAO;AACtB,QAAM,kBAAkB;AACxB,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;AAIX,IAAa,qBAAb,cAAwC,mBAAmB;CACzD,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS,OAAO;AACtB,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;;;;AAOX,IAAa,yBAAb,cAA4C,mBAAmB;CAC7D,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS,OAAO;AACtB,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;AAIX,IAAa,uBAAb,cAA0C,mBAAmB;CAC3D,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS,OAAO;AACtB,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;;;;AAOX,IAAa,kBAAb,cAAqC,mBAAmB;CACtD,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS,OAAO;AACtB,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;;;;;;;;;;;;;;;;;;AAqBX,IAAa,uBAAb,cAA0C,mBAAmB;;;;;;CAM3D,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS,OAAO;AACtB,OAAK,OAAO;AACZ,OAAK,UACH;;;;;CAMJ,WAAW,oBAAoB;AAC7B,SAAO;;;;;;AAOX,MAAa,4BAA4B;AACvC,KAEG,WAAmB,OAAO,IAAI,4BAA4B,MAAM,KAAA,EAGhE,YAAmB,OAAO,IAAI,4BAA4B,oBAAI,IAAI,KAAK;AAG1E,QAAQ,WAAmB,OAAO,IAAI,4BAA4B"}
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { Command, Interrupt } from \"./constants.js\";\n\n// When editing, make sure to update the index found here:\n// https://langchain-ai.github.io/langgraphjs/troubleshooting/errors/\nexport type BaseLangGraphErrorFields = {\n lc_error_code?:\n | \"GRAPH_RECURSION_LIMIT\"\n | \"INVALID_CONCURRENT_GRAPH_UPDATE\"\n | \"INVALID_GRAPH_NODE_RETURN_VALUE\"\n | \"MISSING_CHECKPOINTER\"\n | \"MULTIPLE_SUBGRAPHS\"\n | \"UNREACHABLE_NODE\";\n};\n\n// TODO: Merge with base LangChain error class when we drop support for core@0.2.0\n/** @category Errors */\nexport class BaseLangGraphError extends Error {\n lc_error_code?: string;\n\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n let finalMessage = message ?? \"\";\n if (fields?.lc_error_code) {\n finalMessage = `${finalMessage}\\n\\nTroubleshooting URL: https://docs.langchain.com/oss/javascript/langgraph/${fields.lc_error_code}/\\n`;\n }\n super(finalMessage);\n this.lc_error_code = fields?.lc_error_code;\n }\n}\n\nexport class GraphBubbleUp extends BaseLangGraphError {\n get is_bubble_up() {\n return true;\n }\n}\n\nexport class GraphRecursionError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"GraphRecursionError\";\n }\n\n static get unminifiable_name() {\n return \"GraphRecursionError\";\n }\n}\n\nexport class GraphValueError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"GraphValueError\";\n }\n\n static get unminifiable_name() {\n return \"GraphValueError\";\n }\n}\n\n/**\n * Raised when a graph run exits early due to a drain request.\n *\n * This indicates the graph stopped cooperatively at a superstep boundary\n * because {@link RunControl#requestDrain} was called (e.g., in response to\n * SIGTERM). The checkpoint is saved and the run can be resumed later.\n */\nexport class GraphDrained extends GraphBubbleUp {\n reason: string;\n\n constructor(reason: string = \"shutdown\", fields?: BaseLangGraphErrorFields) {\n super(`Graph drained: ${reason}`, fields);\n this.name = \"GraphDrained\";\n this.reason = reason;\n }\n\n static get unminifiable_name() {\n return \"GraphDrained\";\n }\n}\n\nexport function isGraphDrained(e?: unknown): e is GraphDrained {\n return (\n e !== undefined && (e as Error).name === GraphDrained.unminifiable_name\n );\n}\n\nexport class GraphInterrupt extends GraphBubbleUp {\n interrupts: Interrupt[];\n\n constructor(interrupts?: Interrupt[], fields?: BaseLangGraphErrorFields) {\n super(JSON.stringify(interrupts, null, 2), fields);\n this.name = \"GraphInterrupt\";\n this.interrupts = interrupts ?? [];\n }\n\n static get unminifiable_name() {\n return \"GraphInterrupt\";\n }\n}\n\n/** Raised by a node to interrupt execution. */\nexport class NodeInterrupt extends GraphInterrupt {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(message: any, fields?: BaseLangGraphErrorFields) {\n super([{ value: message }], fields);\n this.name = \"NodeInterrupt\";\n }\n\n static get unminifiable_name() {\n return \"NodeInterrupt\";\n }\n}\n\n/**\n * Failure context passed to a node-level error handler.\n *\n * A node-level error handler is registered via\n * `StateGraph.addNode(name, fn, { errorHandler })`. The handler runs ONLY after\n * the failing node's {@link RetryPolicy} is exhausted, so retry and handling\n * stay decoupled. The handler receives the failed node's name and the thrown\n * error via a `NodeError` instance, can return a state update, and can route to\n * a recovery branch via `new Command({ goto })` (saga / compensation flows).\n *\n * @example\n * ```ts\n * import { NodeError } from \"@langchain/langgraph\";\n *\n * function handler(state: State, error: NodeError) {\n * return new Command({\n * update: { status: `recovered from ${error.node}: ${error.error.message}` },\n * goto: \"finalize\",\n * });\n * }\n * ```\n */\nexport class NodeError {\n /** Name of the node whose execution failed. */\n node: string;\n\n /** Error thrown by the failed node. */\n error: Error;\n\n constructor(node: string, error: Error) {\n this.node = node;\n this.error = error;\n }\n\n static get unminifiable_name() {\n return \"NodeError\";\n }\n}\n\n/**\n * Type guard that checks whether a value is a {@link NodeError}.\n */\nexport function isNodeError(e?: unknown): e is NodeError {\n return (\n e != null &&\n typeof e === \"object\" &&\n e.constructor != null &&\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (e.constructor as any).unminifiable_name === NodeError.unminifiable_name\n );\n}\n\nexport class ParentCommand extends GraphBubbleUp {\n command: Command;\n\n constructor(command: Command) {\n super();\n this.name = \"ParentCommand\";\n this.command = command;\n }\n\n static get unminifiable_name() {\n return \"ParentCommand\";\n }\n}\n\nexport function isParentCommand(e?: unknown): e is ParentCommand {\n return (\n e !== undefined &&\n (e as ParentCommand).name === ParentCommand.unminifiable_name\n );\n}\n\nexport function isGraphBubbleUp(e?: unknown): e is GraphBubbleUp {\n return e !== undefined && (e as GraphBubbleUp).is_bubble_up === true;\n}\n\n// Set by `interrupt()` on the error from a resume value that fails its\n// `responseSchema`. `Symbol.for`, so another copy of this package recognizes it.\nconst INVALID_RESUME = Symbol.for(\"langgraph.invalid_resume\");\n\n/** @internal */\nexport function _markInvalidResume(error: unknown): void {\n if (typeof error === \"object\" && error !== null) {\n Object.defineProperty(error, INVALID_RESUME, { value: true });\n }\n}\n\n/**\n * Whether `error` was thrown because a resume value didn't match the interrupt's\n * `responseSchema`, directly or as the `cause` of a wrapping error (such as one\n * from agent middleware). The resume fails once the step's other tasks finish,\n * and the interrupt can be answered again.\n */\nexport function isInvalidResume(error: unknown): boolean {\n let current = error;\n // Bounded, in case a `cause` chain loops.\n for (let depth = 0; depth < 10; depth += 1) {\n if (typeof current !== \"object\" || current === null) return false;\n if ((current as Record<symbol, unknown>)[INVALID_RESUME] === true) {\n return true;\n }\n current = (current as { cause?: unknown }).cause;\n }\n return false;\n}\n\nexport function isGraphInterrupt(e?: unknown): e is GraphInterrupt {\n return (\n e !== undefined &&\n [\n GraphInterrupt.unminifiable_name,\n NodeInterrupt.unminifiable_name,\n ].includes((e as Error).name)\n );\n}\n\n/**\n * Raised when a node invocation exceeds one of its configured timeouts.\n *\n * Does **not** extend {@link GraphBubbleUp} (so it flows through the normal node\n * error path) and is intentionally treated as retryable by the default retry\n * policy — its message/name do not match the default `retryOn` blocklist, so a\n * configured {@link RetryPolicy} will retry it (see langchain-ai/langgraph#7659).\n *\n * Both {@link NodeTimeoutError.runTimeout} and {@link NodeTimeoutError.idleTimeout}\n * reflect the configured policy at the time of the failure (each `undefined` if\n * not configured). {@link NodeTimeoutError.kind} and {@link NodeTimeoutError.timeout}\n * identify which one fired.\n *\n * @category Errors\n */\nexport class NodeTimeoutError extends BaseLangGraphError {\n /** Name of the node/task that timed out. */\n node: string;\n\n /** Which timeout fired: a hard `\"run\"` cap or a progress-resetting `\"idle\"` cap. */\n kind: \"run\" | \"idle\";\n\n /** The value (ms) of the timeout that fired (`runTimeout` or `idleTimeout`). */\n timeout: number;\n\n /** Elapsed time (ms) since the attempt started, at the moment the timeout fired. */\n elapsed: number;\n\n /** Configured run timeout (ms), if any. */\n runTimeout?: number;\n\n /** Configured idle timeout (ms), if any. */\n idleTimeout?: number;\n\n constructor(\n fields: {\n node: string;\n elapsed: number;\n kind: \"run\" | \"idle\";\n runTimeout?: number;\n idleTimeout?: number;\n },\n errorFields?: BaseLangGraphErrorFields\n ) {\n const { node, elapsed, kind, runTimeout, idleTimeout } = fields;\n let message: string;\n let timeout: number;\n if (kind === \"idle\") {\n if (idleTimeout === undefined) {\n throw new Error(\"idleTimeout is required when kind='idle'\");\n }\n timeout = idleTimeout;\n message =\n `Node \"${node}\" exceeded its idle timeout of ${idleTimeout}ms ` +\n `without making progress (elapsed: ${elapsed}ms).`;\n } else {\n if (runTimeout === undefined) {\n throw new Error(\"runTimeout is required when kind='run'\");\n }\n timeout = runTimeout;\n message =\n `Node \"${node}\" exceeded its run timeout of ${runTimeout}ms ` +\n `(elapsed: ${elapsed}ms).`;\n }\n super(message, errorFields);\n this.name = \"NodeTimeoutError\";\n this.node = node;\n this.kind = kind;\n this.timeout = timeout;\n this.elapsed = elapsed;\n this.runTimeout = runTimeout;\n this.idleTimeout = idleTimeout;\n }\n\n static get unminifiable_name() {\n return \"NodeTimeoutError\";\n }\n}\n\nexport function isNodeTimeoutError(e?: unknown): e is NodeTimeoutError {\n return (\n e !== undefined &&\n (e as NodeTimeoutError).name === NodeTimeoutError.unminifiable_name\n );\n}\n\nexport class EmptyInputError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"EmptyInputError\";\n }\n\n static get unminifiable_name() {\n return \"EmptyInputError\";\n }\n}\n\nexport class EmptyChannelError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n // Skip expensive stack trace capture — used for control flow on channel reads.\n const prevLimit = Error.stackTraceLimit;\n Error.stackTraceLimit = 0;\n super(message, fields);\n Error.stackTraceLimit = prevLimit;\n this.name = \"EmptyChannelError\";\n }\n\n static get unminifiable_name() {\n return \"EmptyChannelError\";\n }\n}\n\nexport class InvalidUpdateError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"InvalidUpdateError\";\n }\n\n static get unminifiable_name() {\n return \"InvalidUpdateError\";\n }\n}\n\n/**\n * @deprecated This exception type is no longer thrown.\n */\nexport class MultipleSubgraphsError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"MultipleSubgraphError\";\n }\n\n static get unminifiable_name() {\n return \"MultipleSubgraphError\";\n }\n}\n\nexport class UnreachableNodeError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"UnreachableNodeError\";\n }\n\n static get unminifiable_name() {\n return \"UnreachableNodeError\";\n }\n}\n\n/**\n * Exception raised when an error occurs in the remote graph.\n */\nexport class RemoteException extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"RemoteException\";\n }\n\n static get unminifiable_name() {\n return \"RemoteException\";\n }\n}\n\n/**\n * Error thrown when invalid input is provided to a StateGraph.\n *\n * This typically means that the input to the StateGraph constructor or builder\n * did not match the required types. A valid input should be a\n * StateDefinition, an Annotation.Root, or a Zod schema.\n *\n * @example\n * // Example of incorrect usage:\n * try {\n * new StateGraph({ foo: \"bar\" }); // Not a valid input\n * } catch (err) {\n * if (err instanceof StateGraphInputError) {\n * console.error(err.message);\n * }\n * }\n */\nexport class StateGraphInputError extends BaseLangGraphError {\n /**\n * Create a new StateGraphInputError.\n * @param message - Optional custom error message.\n * @param fields - Optional additional error fields.\n */\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"StateGraphInputError\";\n this.message =\n \"Invalid StateGraph input. Make sure to pass a valid StateDefinition, Annotation.Root, or Zod schema.\";\n }\n\n /**\n * The unminifiable (static, human-readable) error name for this error class.\n */\n static get unminifiable_name() {\n return \"StateGraphInputError\";\n }\n}\n\n/**\n * Used for subgraph detection.\n */\nexport const getSubgraphsSeenSet = () => {\n if (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (globalThis as any)[Symbol.for(\"LG_CHECKPOINT_SEEN_NS_SET\")] === undefined\n ) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (globalThis as any)[Symbol.for(\"LG_CHECKPOINT_SEEN_NS_SET\")] = new Set();\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (globalThis as any)[Symbol.for(\"LG_CHECKPOINT_SEEN_NS_SET\")];\n};\n"],"mappings":";;AAgBA,IAAa,qBAAb,cAAwC,MAAM;CAC5C;CAEA,YAAY,SAAkB,QAAmC;EAC/D,IAAI,eAAe,WAAW;AAC9B,MAAI,QAAQ,cACV,gBAAe,GAAG,aAAa,+EAA+E,OAAO,cAAc;AAErI,QAAM,aAAa;AACnB,OAAK,gBAAgB,QAAQ;;;AAIjC,IAAa,gBAAb,cAAmC,mBAAmB;CACpD,IAAI,eAAe;AACjB,SAAO;;;AAIX,IAAa,sBAAb,cAAyC,mBAAmB;CAC1D,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS,OAAO;AACtB,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;AAIX,IAAa,kBAAb,cAAqC,mBAAmB;CACtD,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS,OAAO;AACtB,OAAK,OA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4BAA4B,MAAM,KAAA,EAGhE,YAAmB,OAAO,IAAI,4BAA4B,oBAAI,IAAI,KAAK;AAG1E,QAAQ,WAAmB,OAAO,IAAI,4BAA4B"}
@@ -7,12 +7,28 @@ let _langchain_core_messages = require("@langchain/core/messages");
7
7
  * causes all prior messages to be discarded, leaving only those following this marker.
8
8
  */
9
9
  const REMOVE_ALL_MESSAGES = "__remove_all__";
10
+ const MESSAGE_CLASS_BY_TYPE = {
11
+ human: _langchain_core_messages.HumanMessage,
12
+ ai: _langchain_core_messages.AIMessage,
13
+ system: _langchain_core_messages.SystemMessage,
14
+ tool: _langchain_core_messages.ToolMessage,
15
+ function: _langchain_core_messages.FunctionMessage,
16
+ generic: _langchain_core_messages.ChatMessage
17
+ };
18
+ function toMessage(messageLike) {
19
+ const message = (0, _langchain_core_messages.coerceMessageLikeToMessage)(messageLike);
20
+ if (!_langchain_core_messages.BaseMessageChunk.isInstance(message)) return message;
21
+ const MessageClass = MESSAGE_CLASS_BY_TYPE[message.getType()];
22
+ if (MessageClass === void 0) return message;
23
+ return new MessageClass(Object.fromEntries(Object.entries(message).filter(([key]) => key !== "type" && key !== "tool_call_chunks" && !key.startsWith("lc_"))));
24
+ }
10
25
  /**
11
26
  * Reducer function for combining two sets of messages in LangGraph's state system.
12
27
  *
13
28
  * This reducer handles several tasks:
14
29
  * 1. Normalizes both `left` and `right` message inputs to arrays.
15
- * 2. Coerces any message-like objects into real `BaseMessage` instances.
30
+ * 2. Coerces any message-like objects into real `BaseMessage` instances, and
31
+ * message chunks (e.g. `AIMessageChunk`) into their non-chunk class.
16
32
  * 3. Ensures all messages have unique, stable IDs by generating missing ones.
17
33
  * 4. If a `RemoveMessage` instance is encountered in `right` with the ID `REMOVE_ALL_MESSAGES`,
18
34
  * all previous messages are discarded and only the subsequent messages in `right` are returned.
@@ -43,8 +59,8 @@ const REMOVE_ALL_MESSAGES = "__remove_all__";
43
59
  function messagesStateReducer(left, right) {
44
60
  const leftArray = Array.isArray(left) ? left : [left];
45
61
  const rightArray = Array.isArray(right) ? right : [right];
46
- const leftMessages = leftArray.map(_langchain_core_messages.coerceMessageLikeToMessage);
47
- const rightMessages = rightArray.map(_langchain_core_messages.coerceMessageLikeToMessage);
62
+ const leftMessages = leftArray.map(toMessage);
63
+ const rightMessages = rightArray.map(toMessage);
48
64
  for (const m of leftMessages) if (m.id === null || m.id === void 0) {
49
65
  m.id = (0, _langchain_core_utils_uuid.v4)();
50
66
  m.lc_kwargs.id = m.id;
@@ -93,7 +109,8 @@ function messagesStateReducer(left, right) {
93
109
  * pass, so the batching-invariant still holds.
94
110
  *
95
111
  * Raw object / string inputs are coerced to typed `BaseMessage` objects so
96
- * that HTTP-driven graphs work without a separate coercion step. This is not
112
+ * that HTTP-driven graphs work without a separate coercion step, and message
113
+ * chunks are converted to their non-chunk class. This is not
97
114
  * full {@link messagesStateReducer} parity — unknown-id `RemoveMessage`
98
115
  * errors and missing-id UUID assignment are not handled here.
99
116
  *
@@ -112,8 +129,8 @@ function messagesDeltaReducer(state, writes) {
112
129
  const flat = [];
113
130
  for (const w of writes) if (Array.isArray(w)) flat.push(...w);
114
131
  else flat.push(w);
115
- const stateMsgs = state.length > 0 && _langchain_core_messages.BaseMessage.isInstance(state[0]) ? state : state.map(_langchain_core_messages.coerceMessageLikeToMessage);
116
- const msgs = flat.map(_langchain_core_messages.coerceMessageLikeToMessage);
132
+ const stateMsgs = state.length > 0 && _langchain_core_messages.BaseMessage.isInstance(state[0]) ? state : state.map(toMessage);
133
+ const msgs = flat.map(toMessage);
117
134
  const index = /* @__PURE__ */ new Map();
118
135
  for (let i = 0; i < stateMsgs.length; i += 1) {
119
136
  const mid = stateMsgs[i].id;
@@ -1 +1 @@
1
- {"version":3,"file":"messages_reducer.cjs","names":["coerceMessageLikeToMessage","RemoveMessage","BaseMessage"],"sources":["../../src/graph/messages_reducer.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageLike,\n coerceMessageLikeToMessage,\n RemoveMessage,\n} from \"@langchain/core/messages\";\nimport { v4 } from \"@langchain/core/utils/uuid\";\n\n/**\n * Special value that signifies the intent to remove all previous messages in the state reducer.\n * Used as the unique identifier for a `RemoveMessage` instance which, when encountered,\n * causes all prior messages to be discarded, leaving only those following this marker.\n */\nexport const REMOVE_ALL_MESSAGES = \"__remove_all__\";\n\n/**\n * Type that represents an acceptable input for the messages state reducer.\n *\n * - Can be a single `BaseMessage` or `BaseMessageLike`.\n * - Can be an array of `BaseMessage` or `BaseMessageLike`.\n */\nexport type Messages =\n | Array<BaseMessage | BaseMessageLike>\n | BaseMessage\n | BaseMessageLike;\n\n/**\n * Reducer function for combining two sets of messages in LangGraph's state system.\n *\n * This reducer handles several tasks:\n * 1. Normalizes both `left` and `right` message inputs to arrays.\n * 2. Coerces any message-like objects into real `BaseMessage` instances.\n * 3. Ensures all messages have unique, stable IDs by generating missing ones.\n * 4. If a `RemoveMessage` instance is encountered in `right` with the ID `REMOVE_ALL_MESSAGES`,\n * all previous messages are discarded and only the subsequent messages in `right` are returned.\n * 5. Otherwise, merges `left` and `right` messages together following these rules:\n * - If a message in `right` shares an ID with a message in `left`:\n * - If it is a `RemoveMessage`, that message (by ID) is marked for removal.\n * - If it is a normal message, it replaces the message with the same ID from `left`.\n * - If a message in `right` **does not exist** in `left`:\n * - If it is a `RemoveMessage`, this is considered an error (cannot remove non-existent ID).\n * - Otherwise, the message is appended.\n * - Messages flagged for removal are omitted from the final output.\n *\n * @param left - The existing array (or single message) of messages from current state.\n * @param right - The new array (or single message) of messages to be applied.\n * @returns A new array of `BaseMessage` objects representing the updated state.\n *\n * @throws Error if a `RemoveMessage` is used to delete a message with an ID that does not exist in the merged list.\n *\n * @example\n * ```ts\n * const msg1 = new AIMessage(\"hello\");\n * const msg2 = new HumanMessage(\"hi\");\n * const removal = new RemoveMessage({ id: msg1.id });\n * const newState = messagesStateReducer([msg1], [msg2, removal]);\n * // newState will only contain msg2 (msg1 is removed)\n * ```\n */\nexport function messagesStateReducer(\n left: Messages,\n right: Messages\n): BaseMessage[] {\n // Ensure both left and right are arrays\n const leftArray = Array.isArray(left) ? left : [left];\n const rightArray = Array.isArray(right) ? right : [right];\n\n // Convert all input to BaseMessage instances\n const leftMessages = (leftArray as BaseMessageLike[]).map(\n coerceMessageLikeToMessage\n );\n const rightMessages = (rightArray as BaseMessageLike[]).map(\n coerceMessageLikeToMessage\n );\n\n // Assign missing IDs to any message in the left array\n for (const m of leftMessages) {\n if (m.id === null || m.id === undefined) {\n m.id = v4();\n m.lc_kwargs.id = m.id;\n }\n }\n\n // Assign missing IDs and check for \"remove all\" marker in right array\n let removeAllIdx: number | undefined;\n for (let i = 0; i < rightMessages.length; i += 1) {\n const m = rightMessages[i];\n if (m.id === null || m.id === undefined) {\n m.id = v4();\n m.lc_kwargs.id = m.id;\n }\n\n // If RemoveMessage with special REMOVE_ALL_MESSAGES id is found\n if (RemoveMessage.isInstance(m) && m.id === REMOVE_ALL_MESSAGES) {\n removeAllIdx = i;\n }\n }\n\n // If remove-all is present, all previous messages are wiped; return only subsequent ones\n if (removeAllIdx != null) return rightMessages.slice(removeAllIdx + 1);\n\n // Begin normal merging logic\n const merged = [...leftMessages];\n const mergedById = new Map(merged.map((m, i) => [m.id, i]));\n const idsToRemove = new Set();\n\n for (const m of rightMessages) {\n const existingIdx = mergedById.get(m.id);\n if (existingIdx !== undefined) {\n // Case: updating or removing an existing message by id\n if (RemoveMessage.isInstance(m)) {\n idsToRemove.add(m.id);\n } else {\n idsToRemove.delete(m.id);\n merged[existingIdx] = m;\n }\n } else {\n // Case: inserting a completely new message\n if (RemoveMessage.isInstance(m)) {\n throw new Error(\n `Attempting to delete a message with an ID that doesn't exist ('${m.id}')`\n );\n }\n mergedById.set(m.id, merged.length);\n merged.push(m);\n }\n }\n\n // Remove any messages whose IDs are marked for removal\n return merged.filter((m) => !idsToRemove.has(m.id));\n}\n\n/**\n * **Experimental.** Batch reducer for use with `DeltaChannel`.\n *\n * Processes all writes in one pass — dedup by ID and `RemoveMessage`\n * tombstoning — without calling {@link messagesStateReducer}.\n *\n * This reducer is batching-invariant, as required by `DeltaChannel`:\n * `reducer(reducer(state, xs), ys) === reducer(state, xs.concat(ys))`.\n *\n * A `RemoveMessage` carrying the {@link REMOVE_ALL_MESSAGES} sentinel id\n * clears all messages accumulated so far (prior state plus earlier writes in\n * the same batch) and keeps only the messages that follow it, mirroring\n * {@link messagesStateReducer}. Clearing happens in the same single linear\n * pass, so the batching-invariant still holds.\n *\n * Raw object / string inputs are coerced to typed `BaseMessage` objects so\n * that HTTP-driven graphs work without a separate coercion step. This is not\n * full {@link messagesStateReducer} parity — unknown-id `RemoveMessage`\n * errors and missing-id UUID assignment are not handled here.\n *\n * @param state - The current accumulated list of messages.\n * @param writes - Batch of writes, each a single message-like or an array.\n * @returns The new accumulated list of messages.\n *\n * @example\n * ```typescript\n * import { DeltaChannel, messagesDeltaReducer } from \"@langchain/langgraph\";\n *\n * const channel = new DeltaChannel(messagesDeltaReducer);\n * ```\n */\nexport function messagesDeltaReducer(\n state: BaseMessage[],\n writes: Messages[]\n): BaseMessage[] {\n // Each write is either an array of message-likes or a single message-like.\n // Only arrays flatten; everything else is one message.\n const flat: BaseMessageLike[] = [];\n for (const w of writes) {\n if (Array.isArray(w)) {\n flat.push(...(w as BaseMessageLike[]));\n } else {\n flat.push(w as BaseMessageLike);\n }\n }\n\n // Steady state: the reducer's own output is already typed, so skip coercion\n // on state when the first element is a BaseMessage. Only raw input (initial\n // objects, deserialized blobs) hits the slow path.\n const stateMsgs: BaseMessage[] =\n state.length > 0 && BaseMessage.isInstance(state[0])\n ? state\n : (state as BaseMessageLike[]).map(coerceMessageLikeToMessage);\n const msgs: BaseMessage[] = flat.map(coerceMessageLikeToMessage);\n\n const index = new Map<string, number>();\n for (let i = 0; i < stateMsgs.length; i += 1) {\n const mid = stateMsgs[i].id;\n if (mid != null) index.set(mid, i);\n }\n\n const result: (BaseMessage | null)[] = [...stateMsgs];\n for (const msg of msgs) {\n const mid = msg.id;\n if (RemoveMessage.isInstance(msg) && mid === REMOVE_ALL_MESSAGES) {\n // Discard everything accumulated so far (prior state and earlier writes\n // in this batch); only messages following the sentinel are kept. Doing\n // this inline keeps the reducer batching-invariant.\n result.length = 0;\n index.clear();\n } else if (mid == null) {\n result.push(msg);\n } else if (RemoveMessage.isInstance(msg)) {\n if (index.has(mid)) {\n result[index.get(mid)!] = null;\n index.delete(mid);\n }\n } else if (index.has(mid)) {\n result[index.get(mid)!] = msg;\n } else {\n index.set(mid, result.length);\n result.push(msg);\n }\n }\n return result.filter((m): m is BaseMessage => m !== null);\n}\n\n// A brand rather than reference equality, so the reducer is still recognized\n// from another copy of this package (its ESM and CJS builds both loaded, or a\n// copy nested under another package).\nconst MESSAGES_DELTA_REDUCER = Symbol.for(\"langgraph.messages_delta_reducer\");\nObject.defineProperty(messagesDeltaReducer, MESSAGES_DELTA_REDUCER, {\n value: true,\n});\n\n/** @internal */\nexport function isMessagesDeltaReducer(reducer: unknown): boolean {\n return (\n typeof reducer === \"function\" &&\n (reducer as unknown as Record<symbol, unknown>)[MESSAGES_DELTA_REDUCER] ===\n true\n );\n}\n"],"mappings":";;;;;;;;AAaA,MAAa,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CnC,SAAgB,qBACd,MACA,OACe;CAEf,MAAM,YAAY,MAAM,QAAQ,KAAK,GAAG,OAAO,CAAC,KAAK;CACrD,MAAM,aAAa,MAAM,QAAQ,MAAM,GAAG,QAAQ,CAAC,MAAM;CAGzD,MAAM,eAAgB,UAAgC,IACpDA,yBAAAA,2BACD;CACD,MAAM,gBAAiB,WAAiC,IACtDA,yBAAAA,2BACD;AAGD,MAAK,MAAM,KAAK,aACd,KAAI,EAAE,OAAO,QAAQ,EAAE,OAAO,KAAA,GAAW;AACvC,IAAE,MAAA,GAAA,2BAAA,KAAS;AACX,IAAE,UAAU,KAAK,EAAE;;CAKvB,IAAI;AACJ,MAAK,IAAI,IAAI,GAAG,IAAI,cAAc,QAAQ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B;CAClE,MAAM,OAAsB,KAAK,IAAIA,yBAAAA,2BAA2B;CAEhE,MAAM,wBAAQ,IAAI,KAAqB;AACvC,MAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK,GAAG;EAC5C,MAAM,MAAM,UAAU,GAAG;AACzB,MAAI,OAAO,KAAM,OAAM,IAAI,KAAK,EAAE;;CAGpC,MAAM,SAAiC,CAAC,GAAG,UAAU;AACrD,MAAK,MAAM,OAAO,MAAM;EACtB,MAAM,MAAM,IAAI;AAChB,MAAIC,yBAAAA,cAAc,WAAW,IAAI,IAAI,QAAA,kBAA6B;AAIhE,UAAO,SAAS;AAChB,SAAM,OAAO;aACJ,OAAO,KAChB,QAAO,KAAK,IAAI;WACPA,yBAAAA,cAAc,WAAW,IAAI;OAClC,MAAM,IAAI,IAAI,EAAE;AAClB,WAAO,MAAM,IAAI,IAAI,IAAK;AAC1B,UAAM,OAAO,IAAI;;aAEV,MAAM,IAAI,IAAI,CACvB,QAAO,MAAM,IAAI,IAAI,IAAK;OACrB;AACL,SAAM,IAAI,KAAK,OAAO,OAAO;AAC7B,UAAO,KAAK,IAAI;;;AAGpB,QAAO,OAAO,QAAQ,MAAwB,MAAM,KAAK;;AAM3D,MAAM,yBAAyB,OAAO,IAAI,mCAAmC;AAC7E,OAAO,eAAe,sBAAsB,wBAAwB,EAClE,OAAO,MACR,CAAC;;AAGF,SAAgB,uBAAuB,SAA2B;AAChE,QACE,OAAO,YAAY,cAClB,QAA+C,4BAC9C"}
1
+ {"version":3,"file":"messages_reducer.cjs","names":["HumanMessage","AIMessage","SystemMessage","ToolMessage","FunctionMessage","ChatMessage","BaseMessageChunk","RemoveMessage","BaseMessage"],"sources":["../../src/graph/messages_reducer.ts"],"sourcesContent":["import {\n AIMessage,\n BaseMessage,\n BaseMessageChunk,\n BaseMessageLike,\n ChatMessage,\n coerceMessageLikeToMessage,\n FunctionMessage,\n HumanMessage,\n RemoveMessage,\n SystemMessage,\n ToolMessage,\n} from \"@langchain/core/messages\";\nimport { v4 } from \"@langchain/core/utils/uuid\";\n\n/**\n * Special value that signifies the intent to remove all previous messages in the state reducer.\n * Used as the unique identifier for a `RemoveMessage` instance which, when encountered,\n * causes all prior messages to be discarded, leaving only those following this marker.\n */\nexport const REMOVE_ALL_MESSAGES = \"__remove_all__\";\n\n/**\n * Type that represents an acceptable input for the messages state reducer.\n *\n * - Can be a single `BaseMessage` or `BaseMessageLike`.\n * - Can be an array of `BaseMessage` or `BaseMessageLike`.\n */\nexport type Messages =\n | Array<BaseMessage | BaseMessageLike>\n | BaseMessage\n | BaseMessageLike;\n\nconst MESSAGE_CLASS_BY_TYPE: Record<\n string,\n new (fields: never) => BaseMessage\n> = {\n human: HumanMessage,\n ai: AIMessage,\n system: SystemMessage,\n tool: ToolMessage,\n function: FunctionMessage,\n generic: ChatMessage,\n};\n\n// A chat model called under a streaming callback (`streamMode: \"messages\"`,\n// `streamEvents`) returns the aggregated chunk. Stored as-is, the checkpoint\n// would depend on how the graph was run, and on reload an `AIMessageChunk`\n// rebuilds `tool_calls` from `tool_call_chunks`, undoing in-place edits.\n// Same conversion as Python's `add_messages`.\nfunction toMessage(messageLike: BaseMessageLike): BaseMessage {\n const message = coerceMessageLikeToMessage(messageLike);\n if (!BaseMessageChunk.isInstance(message)) return message;\n const MessageClass = MESSAGE_CLASS_BY_TYPE[message.getType()];\n if (MessageClass === undefined) return message;\n const fields = Object.fromEntries(\n Object.entries(message).filter(\n ([key]) =>\n key !== \"type\" && key !== \"tool_call_chunks\" && !key.startsWith(\"lc_\")\n )\n );\n return new MessageClass(fields as never);\n}\n\n/**\n * Reducer function for combining two sets of messages in LangGraph's state system.\n *\n * This reducer handles several tasks:\n * 1. Normalizes both `left` and `right` message inputs to arrays.\n * 2. Coerces any message-like objects into real `BaseMessage` instances, and\n * message chunks (e.g. `AIMessageChunk`) into their non-chunk class.\n * 3. Ensures all messages have unique, stable IDs by generating missing ones.\n * 4. If a `RemoveMessage` instance is encountered in `right` with the ID `REMOVE_ALL_MESSAGES`,\n * all previous messages are discarded and only the subsequent messages in `right` are returned.\n * 5. Otherwise, merges `left` and `right` messages together following these rules:\n * - If a message in `right` shares an ID with a message in `left`:\n * - If it is a `RemoveMessage`, that message (by ID) is marked for removal.\n * - If it is a normal message, it replaces the message with the same ID from `left`.\n * - If a message in `right` **does not exist** in `left`:\n * - If it is a `RemoveMessage`, this is considered an error (cannot remove non-existent ID).\n * - Otherwise, the message is appended.\n * - Messages flagged for removal are omitted from the final output.\n *\n * @param left - The existing array (or single message) of messages from current state.\n * @param right - The new array (or single message) of messages to be applied.\n * @returns A new array of `BaseMessage` objects representing the updated state.\n *\n * @throws Error if a `RemoveMessage` is used to delete a message with an ID that does not exist in the merged list.\n *\n * @example\n * ```ts\n * const msg1 = new AIMessage(\"hello\");\n * const msg2 = new HumanMessage(\"hi\");\n * const removal = new RemoveMessage({ id: msg1.id });\n * const newState = messagesStateReducer([msg1], [msg2, removal]);\n * // newState will only contain msg2 (msg1 is removed)\n * ```\n */\nexport function messagesStateReducer(\n left: Messages,\n right: Messages\n): BaseMessage[] {\n // Ensure both left and right are arrays\n const leftArray = Array.isArray(left) ? left : [left];\n const rightArray = Array.isArray(right) ? right : [right];\n\n // Convert all input to BaseMessage instances\n const leftMessages = (leftArray as BaseMessageLike[]).map(toMessage);\n const rightMessages = (rightArray as BaseMessageLike[]).map(toMessage);\n\n // Assign missing IDs to any message in the left array\n for (const m of leftMessages) {\n if (m.id === null || m.id === undefined) {\n m.id = v4();\n m.lc_kwargs.id = m.id;\n }\n }\n\n // Assign missing IDs and check for \"remove all\" marker in right array\n let removeAllIdx: number | undefined;\n for (let i = 0; i < rightMessages.length; i += 1) {\n const m = rightMessages[i];\n if (m.id === null || m.id === undefined) {\n m.id = v4();\n m.lc_kwargs.id = m.id;\n }\n\n // If RemoveMessage with special REMOVE_ALL_MESSAGES id is found\n if (RemoveMessage.isInstance(m) && m.id === REMOVE_ALL_MESSAGES) {\n removeAllIdx = i;\n }\n }\n\n // If remove-all is present, all previous messages are wiped; return only subsequent ones\n if (removeAllIdx != null) return rightMessages.slice(removeAllIdx + 1);\n\n // Begin normal merging logic\n const merged = [...leftMessages];\n const mergedById = new Map(merged.map((m, i) => [m.id, i]));\n const idsToRemove = new Set();\n\n for (const m of rightMessages) {\n const existingIdx = mergedById.get(m.id);\n if (existingIdx !== undefined) {\n // Case: updating or removing an existing message by id\n if (RemoveMessage.isInstance(m)) {\n idsToRemove.add(m.id);\n } else {\n idsToRemove.delete(m.id);\n merged[existingIdx] = m;\n }\n } else {\n // Case: inserting a completely new message\n if (RemoveMessage.isInstance(m)) {\n throw new Error(\n `Attempting to delete a message with an ID that doesn't exist ('${m.id}')`\n );\n }\n mergedById.set(m.id, merged.length);\n merged.push(m);\n }\n }\n\n // Remove any messages whose IDs are marked for removal\n return merged.filter((m) => !idsToRemove.has(m.id));\n}\n\n/**\n * **Experimental.** Batch reducer for use with `DeltaChannel`.\n *\n * Processes all writes in one pass — dedup by ID and `RemoveMessage`\n * tombstoning — without calling {@link messagesStateReducer}.\n *\n * This reducer is batching-invariant, as required by `DeltaChannel`:\n * `reducer(reducer(state, xs), ys) === reducer(state, xs.concat(ys))`.\n *\n * A `RemoveMessage` carrying the {@link REMOVE_ALL_MESSAGES} sentinel id\n * clears all messages accumulated so far (prior state plus earlier writes in\n * the same batch) and keeps only the messages that follow it, mirroring\n * {@link messagesStateReducer}. Clearing happens in the same single linear\n * pass, so the batching-invariant still holds.\n *\n * Raw object / string inputs are coerced to typed `BaseMessage` objects so\n * that HTTP-driven graphs work without a separate coercion step, and message\n * chunks are converted to their non-chunk class. This is not\n * full {@link messagesStateReducer} parity — unknown-id `RemoveMessage`\n * errors and missing-id UUID assignment are not handled here.\n *\n * @param state - The current accumulated list of messages.\n * @param writes - Batch of writes, each a single message-like or an array.\n * @returns The new accumulated list of messages.\n *\n * @example\n * ```typescript\n * import { DeltaChannel, messagesDeltaReducer } from \"@langchain/langgraph\";\n *\n * const channel = new DeltaChannel(messagesDeltaReducer);\n * ```\n */\nexport function messagesDeltaReducer(\n state: BaseMessage[],\n writes: Messages[]\n): BaseMessage[] {\n // Each write is either an array of message-likes or a single message-like.\n // Only arrays flatten; everything else is one message.\n const flat: BaseMessageLike[] = [];\n for (const w of writes) {\n if (Array.isArray(w)) {\n flat.push(...(w as BaseMessageLike[]));\n } else {\n flat.push(w as BaseMessageLike);\n }\n }\n\n // Steady state: the reducer's own output is already typed, so skip coercion\n // on state when the first element is a BaseMessage. Only raw input (initial\n // objects, deserialized blobs) hits the slow path.\n const stateMsgs: BaseMessage[] =\n state.length > 0 && BaseMessage.isInstance(state[0])\n ? state\n : (state as BaseMessageLike[]).map(toMessage);\n const msgs: BaseMessage[] = flat.map(toMessage);\n\n const index = new Map<string, number>();\n for (let i = 0; i < stateMsgs.length; i += 1) {\n const mid = stateMsgs[i].id;\n if (mid != null) index.set(mid, i);\n }\n\n const result: (BaseMessage | null)[] = [...stateMsgs];\n for (const msg of msgs) {\n const mid = msg.id;\n if (RemoveMessage.isInstance(msg) && mid === REMOVE_ALL_MESSAGES) {\n // Discard everything accumulated so far (prior state and earlier writes\n // in this batch); only messages following the sentinel are kept. Doing\n // this inline keeps the reducer batching-invariant.\n result.length = 0;\n index.clear();\n } else if (mid == null) {\n result.push(msg);\n } else if (RemoveMessage.isInstance(msg)) {\n if (index.has(mid)) {\n result[index.get(mid)!] = null;\n index.delete(mid);\n }\n } else if (index.has(mid)) {\n result[index.get(mid)!] = msg;\n } else {\n index.set(mid, result.length);\n result.push(msg);\n }\n }\n return result.filter((m): m is BaseMessage => m !== null);\n}\n\n// A brand rather than reference equality, so the reducer is still recognized\n// from another copy of this package (its ESM and CJS builds both loaded, or a\n// copy nested under another package).\nconst MESSAGES_DELTA_REDUCER = Symbol.for(\"langgraph.messages_delta_reducer\");\nObject.defineProperty(messagesDeltaReducer, MESSAGES_DELTA_REDUCER, {\n value: true,\n});\n\n/** @internal */\nexport function isMessagesDeltaReducer(reducer: unknown): bool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AQ,KAAK,GAAG;EAC5C,MAAM,MAAM,UAAU,GAAG;AACzB,MAAI,OAAO,KAAM,OAAM,IAAI,KAAK,EAAE;;CAGpC,MAAM,SAAiC,CAAC,GAAG,UAAU;AACrD,MAAK,MAAM,OAAO,MAAM;EACtB,MAAM,MAAM,IAAI;AAChB,MAAID,yBAAAA,cAAc,WAAW,IAAI,IAAI,QAAA,kBAA6B;AAIhE,UAAO,SAAS;AAChB,SAAM,OAAO;aACJ,OAAO,KAChB,QAAO,KAAK,IAAI;WACPA,yBAAAA,cAAc,WAAW,IAAI;OAClC,MAAM,IAAI,IAAI,EAAE;AAClB,WAAO,MAAM,IAAI,IAAI,IAAK;AAC1B,UAAM,OAAO,IAAI;;aAEV,MAAM,IAAI,IAAI,CACvB,QAAO,MAAM,IAAI,IAAI,IAAK;OACrB;AACL,SAAM,IAAI,KAAK,OAAO,OAAO;AAC7B,UAAO,KAAK,IAAI;;;AAGpB,QAAO,OAAO,QAAQ,MAAwB,MAAM,KAAK;;AAM3D,MAAM,yBAAyB,OAAO,IAAI,mCAAmC;AAC7E,OAAO,eAAe,sBAAsB,wBAAwB,EAClE,OAAO,MACR,CAAC;;AAGF,SAAgB,uBAAuB,SAA2B;AAChE,QACE,OAAO,YAAY,cAClB,QAA+C,4BAC9C"}
@@ -19,7 +19,8 @@ type Messages = Array<BaseMessage | BaseMessageLike> | BaseMessage | BaseMessage
19
19
  *
20
20
  * This reducer handles several tasks:
21
21
  * 1. Normalizes both `left` and `right` message inputs to arrays.
22
- * 2. Coerces any message-like objects into real `BaseMessage` instances.
22
+ * 2. Coerces any message-like objects into real `BaseMessage` instances, and
23
+ * message chunks (e.g. `AIMessageChunk`) into their non-chunk class.
23
24
  * 3. Ensures all messages have unique, stable IDs by generating missing ones.
24
25
  * 4. If a `RemoveMessage` instance is encountered in `right` with the ID `REMOVE_ALL_MESSAGES`,
25
26
  * all previous messages are discarded and only the subsequent messages in `right` are returned.
@@ -64,7 +65,8 @@ declare function messagesStateReducer(left: Messages, right: Messages): BaseMess
64
65
  * pass, so the batching-invariant still holds.
65
66
  *
66
67
  * Raw object / string inputs are coerced to typed `BaseMessage` objects so
67
- * that HTTP-driven graphs work without a separate coercion step. This is not
68
+ * that HTTP-driven graphs work without a separate coercion step, and message
69
+ * chunks are converted to their non-chunk class. This is not
68
70
  * full {@link messagesStateReducer} parity — unknown-id `RemoveMessage`
69
71
  * errors and missing-id UUID assignment are not handled here.
70
72
  *
@@ -1 +1 @@
1
- {"version":3,"file":"messages_reducer.d.cts","names":[],"sources":["../../src/graph/messages_reducer.ts"],"mappings":";;;;;AAaA;;;cAAa,mBAAA;;AAQb;;;;;KAAY,QAAA,GACR,KAAA,CAAM,WAAA,GAAc,eAAA,IACpB,WAAA,GACA,eAAA;;;;;;;;;;;;AAmCJ;;;;;;;;;;;;;;;AAwGA;;;;;;;iBAxGgB,oBAAA,CACd,IAAA,EAAM,QAAA,EACN,KAAA,EAAO,QAAA,GACN,WAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqGa,oBAAA,CACd,KAAA,EAAO,WAAA,IACP,MAAA,EAAQ,QAAA,KACP,WAAA"}
1
+ {"version":3,"file":"messages_reducer.d.cts","names":[],"sources":["../../src/graph/messages_reducer.ts"],"mappings":";;;;;AAoBA;;;cAAa,mBAAA;;AAQb;;;;;KAAY,QAAA,GACR,KAAA,CAAM,WAAA,GAAc,eAAA,IACpB,WAAA,GACA,eAAA;;;;;;;;;;;;AAmEJ;;;;;;;;;;;;;;;AAqGA;;;;;;;;iBArGgB,oBAAA,CACd,IAAA,EAAM,QAAA,EACN,KAAA,EAAO,QAAA,GACN,WAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkGa,oBAAA,CACd,KAAA,EAAO,WAAA,IACP,MAAA,EAAQ,QAAA,KACP,WAAA"}
@@ -19,7 +19,8 @@ type Messages = Array<BaseMessage | BaseMessageLike> | BaseMessage | BaseMessage
19
19
  *
20
20
  * This reducer handles several tasks:
21
21
  * 1. Normalizes both `left` and `right` message inputs to arrays.
22
- * 2. Coerces any message-like objects into real `BaseMessage` instances.
22
+ * 2. Coerces any message-like objects into real `BaseMessage` instances, and
23
+ * message chunks (e.g. `AIMessageChunk`) into their non-chunk class.
23
24
  * 3. Ensures all messages have unique, stable IDs by generating missing ones.
24
25
  * 4. If a `RemoveMessage` instance is encountered in `right` with the ID `REMOVE_ALL_MESSAGES`,
25
26
  * all previous messages are discarded and only the subsequent messages in `right` are returned.
@@ -64,7 +65,8 @@ declare function messagesStateReducer(left: Messages, right: Messages): BaseMess
64
65
  * pass, so the batching-invariant still holds.
65
66
  *
66
67
  * Raw object / string inputs are coerced to typed `BaseMessage` objects so
67
- * that HTTP-driven graphs work without a separate coercion step. This is not
68
+ * that HTTP-driven graphs work without a separate coercion step, and message
69
+ * chunks are converted to their non-chunk class. This is not
68
70
  * full {@link messagesStateReducer} parity — unknown-id `RemoveMessage`
69
71
  * errors and missing-id UUID assignment are not handled here.
70
72
  *
@@ -1 +1 @@
1
- {"version":3,"file":"messages_reducer.d.ts","names":[],"sources":["../../src/graph/messages_reducer.ts"],"mappings":";;;;;AAaA;;;cAAa,mBAAA;;AAQb;;;;;KAAY,QAAA,GACR,KAAA,CAAM,WAAA,GAAc,eAAA,IACpB,WAAA,GACA,eAAA;;;;;;;;;;;;AAmCJ;;;;;;;;;;;;;;;AAwGA;;;;;;;iBAxGgB,oBAAA,CACd,IAAA,EAAM,QAAA,EACN,KAAA,EAAO,QAAA,GACN,WAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqGa,oBAAA,CACd,KAAA,EAAO,WAAA,IACP,MAAA,EAAQ,QAAA,KACP,WAAA"}
1
+ {"version":3,"file":"messages_reducer.d.ts","names":[],"sources":["../../src/graph/messages_reducer.ts"],"mappings":";;;;;AAoBA;;;cAAa,mBAAA;;AAQb;;;;;KAAY,QAAA,GACR,KAAA,CAAM,WAAA,GAAc,eAAA,IACpB,WAAA,GACA,eAAA;;;;;;;;;;;;AAmEJ;;;;;;;;;;;;;;;AAqGA;;;;;;;;iBArGgB,oBAAA,CACd,IAAA,EAAM,QAAA,EACN,KAAA,EAAO,QAAA,GACN,WAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkGa,oBAAA,CACd,KAAA,EAAO,WAAA,IACP,MAAA,EAAQ,QAAA,KACP,WAAA"}
@@ -1,5 +1,5 @@
1
1
  import { v4 } from "@langchain/core/utils/uuid";
2
- import { BaseMessage, RemoveMessage, coerceMessageLikeToMessage } from "@langchain/core/messages";
2
+ import { AIMessage, BaseMessage, BaseMessageChunk, ChatMessage, FunctionMessage, HumanMessage, RemoveMessage, SystemMessage, ToolMessage, coerceMessageLikeToMessage } from "@langchain/core/messages";
3
3
  //#region src/graph/messages_reducer.ts
4
4
  /**
5
5
  * Special value that signifies the intent to remove all previous messages in the state reducer.
@@ -7,12 +7,28 @@ import { BaseMessage, RemoveMessage, coerceMessageLikeToMessage } from "@langcha
7
7
  * causes all prior messages to be discarded, leaving only those following this marker.
8
8
  */
9
9
  const REMOVE_ALL_MESSAGES = "__remove_all__";
10
+ const MESSAGE_CLASS_BY_TYPE = {
11
+ human: HumanMessage,
12
+ ai: AIMessage,
13
+ system: SystemMessage,
14
+ tool: ToolMessage,
15
+ function: FunctionMessage,
16
+ generic: ChatMessage
17
+ };
18
+ function toMessage(messageLike) {
19
+ const message = coerceMessageLikeToMessage(messageLike);
20
+ if (!BaseMessageChunk.isInstance(message)) return message;
21
+ const MessageClass = MESSAGE_CLASS_BY_TYPE[message.getType()];
22
+ if (MessageClass === void 0) return message;
23
+ return new MessageClass(Object.fromEntries(Object.entries(message).filter(([key]) => key !== "type" && key !== "tool_call_chunks" && !key.startsWith("lc_"))));
24
+ }
10
25
  /**
11
26
  * Reducer function for combining two sets of messages in LangGraph's state system.
12
27
  *
13
28
  * This reducer handles several tasks:
14
29
  * 1. Normalizes both `left` and `right` message inputs to arrays.
15
- * 2. Coerces any message-like objects into real `BaseMessage` instances.
30
+ * 2. Coerces any message-like objects into real `BaseMessage` instances, and
31
+ * message chunks (e.g. `AIMessageChunk`) into their non-chunk class.
16
32
  * 3. Ensures all messages have unique, stable IDs by generating missing ones.
17
33
  * 4. If a `RemoveMessage` instance is encountered in `right` with the ID `REMOVE_ALL_MESSAGES`,
18
34
  * all previous messages are discarded and only the subsequent messages in `right` are returned.
@@ -43,8 +59,8 @@ const REMOVE_ALL_MESSAGES = "__remove_all__";
43
59
  function messagesStateReducer(left, right) {
44
60
  const leftArray = Array.isArray(left) ? left : [left];
45
61
  const rightArray = Array.isArray(right) ? right : [right];
46
- const leftMessages = leftArray.map(coerceMessageLikeToMessage);
47
- const rightMessages = rightArray.map(coerceMessageLikeToMessage);
62
+ const leftMessages = leftArray.map(toMessage);
63
+ const rightMessages = rightArray.map(toMessage);
48
64
  for (const m of leftMessages) if (m.id === null || m.id === void 0) {
49
65
  m.id = v4();
50
66
  m.lc_kwargs.id = m.id;
@@ -93,7 +109,8 @@ function messagesStateReducer(left, right) {
93
109
  * pass, so the batching-invariant still holds.
94
110
  *
95
111
  * Raw object / string inputs are coerced to typed `BaseMessage` objects so
96
- * that HTTP-driven graphs work without a separate coercion step. This is not
112
+ * that HTTP-driven graphs work without a separate coercion step, and message
113
+ * chunks are converted to their non-chunk class. This is not
97
114
  * full {@link messagesStateReducer} parity — unknown-id `RemoveMessage`
98
115
  * errors and missing-id UUID assignment are not handled here.
99
116
  *
@@ -112,8 +129,8 @@ function messagesDeltaReducer(state, writes) {
112
129
  const flat = [];
113
130
  for (const w of writes) if (Array.isArray(w)) flat.push(...w);
114
131
  else flat.push(w);
115
- const stateMsgs = state.length > 0 && BaseMessage.isInstance(state[0]) ? state : state.map(coerceMessageLikeToMessage);
116
- const msgs = flat.map(coerceMessageLikeToMessage);
132
+ const stateMsgs = state.length > 0 && BaseMessage.isInstance(state[0]) ? state : state.map(toMessage);
133
+ const msgs = flat.map(toMessage);
117
134
  const index = /* @__PURE__ */ new Map();
118
135
  for (let i = 0; i < stateMsgs.length; i += 1) {
119
136
  const mid = stateMsgs[i].id;
@@ -1 +1 @@
1
- {"version":3,"file":"messages_reducer.js","names":[],"sources":["../../src/graph/messages_reducer.ts"],"sourcesContent":["import {\n BaseMessage,\n BaseMessageLike,\n coerceMessageLikeToMessage,\n RemoveMessage,\n} from \"@langchain/core/messages\";\nimport { v4 } from \"@langchain/core/utils/uuid\";\n\n/**\n * Special value that signifies the intent to remove all previous messages in the state reducer.\n * Used as the unique identifier for a `RemoveMessage` instance which, when encountered,\n * causes all prior messages to be discarded, leaving only those following this marker.\n */\nexport const REMOVE_ALL_MESSAGES = \"__remove_all__\";\n\n/**\n * Type that represents an acceptable input for the messages state reducer.\n *\n * - Can be a single `BaseMessage` or `BaseMessageLike`.\n * - Can be an array of `BaseMessage` or `BaseMessageLike`.\n */\nexport type Messages =\n | Array<BaseMessage | BaseMessageLike>\n | BaseMessage\n | BaseMessageLike;\n\n/**\n * Reducer function for combining two sets of messages in LangGraph's state system.\n *\n * This reducer handles several tasks:\n * 1. Normalizes both `left` and `right` message inputs to arrays.\n * 2. Coerces any message-like objects into real `BaseMessage` instances.\n * 3. Ensures all messages have unique, stable IDs by generating missing ones.\n * 4. If a `RemoveMessage` instance is encountered in `right` with the ID `REMOVE_ALL_MESSAGES`,\n * all previous messages are discarded and only the subsequent messages in `right` are returned.\n * 5. Otherwise, merges `left` and `right` messages together following these rules:\n * - If a message in `right` shares an ID with a message in `left`:\n * - If it is a `RemoveMessage`, that message (by ID) is marked for removal.\n * - If it is a normal message, it replaces the message with the same ID from `left`.\n * - If a message in `right` **does not exist** in `left`:\n * - If it is a `RemoveMessage`, this is considered an error (cannot remove non-existent ID).\n * - Otherwise, the message is appended.\n * - Messages flagged for removal are omitted from the final output.\n *\n * @param left - The existing array (or single message) of messages from current state.\n * @param right - The new array (or single message) of messages to be applied.\n * @returns A new array of `BaseMessage` objects representing the updated state.\n *\n * @throws Error if a `RemoveMessage` is used to delete a message with an ID that does not exist in the merged list.\n *\n * @example\n * ```ts\n * const msg1 = new AIMessage(\"hello\");\n * const msg2 = new HumanMessage(\"hi\");\n * const removal = new RemoveMessage({ id: msg1.id });\n * const newState = messagesStateReducer([msg1], [msg2, removal]);\n * // newState will only contain msg2 (msg1 is removed)\n * ```\n */\nexport function messagesStateReducer(\n left: Messages,\n right: Messages\n): BaseMessage[] {\n // Ensure both left and right are arrays\n const leftArray = Array.isArray(left) ? left : [left];\n const rightArray = Array.isArray(right) ? right : [right];\n\n // Convert all input to BaseMessage instances\n const leftMessages = (leftArray as BaseMessageLike[]).map(\n coerceMessageLikeToMessage\n );\n const rightMessages = (rightArray as BaseMessageLike[]).map(\n coerceMessageLikeToMessage\n );\n\n // Assign missing IDs to any message in the left array\n for (const m of leftMessages) {\n if (m.id === null || m.id === undefined) {\n m.id = v4();\n m.lc_kwargs.id = m.id;\n }\n }\n\n // Assign missing IDs and check for \"remove all\" marker in right array\n let removeAllIdx: number | undefined;\n for (let i = 0; i < rightMessages.length; i += 1) {\n const m = rightMessages[i];\n if (m.id === null || m.id === undefined) {\n m.id = v4();\n m.lc_kwargs.id = m.id;\n }\n\n // If RemoveMessage with special REMOVE_ALL_MESSAGES id is found\n if (RemoveMessage.isInstance(m) && m.id === REMOVE_ALL_MESSAGES) {\n removeAllIdx = i;\n }\n }\n\n // If remove-all is present, all previous messages are wiped; return only subsequent ones\n if (removeAllIdx != null) return rightMessages.slice(removeAllIdx + 1);\n\n // Begin normal merging logic\n const merged = [...leftMessages];\n const mergedById = new Map(merged.map((m, i) => [m.id, i]));\n const idsToRemove = new Set();\n\n for (const m of rightMessages) {\n const existingIdx = mergedById.get(m.id);\n if (existingIdx !== undefined) {\n // Case: updating or removing an existing message by id\n if (RemoveMessage.isInstance(m)) {\n idsToRemove.add(m.id);\n } else {\n idsToRemove.delete(m.id);\n merged[existingIdx] = m;\n }\n } else {\n // Case: inserting a completely new message\n if (RemoveMessage.isInstance(m)) {\n throw new Error(\n `Attempting to delete a message with an ID that doesn't exist ('${m.id}')`\n );\n }\n mergedById.set(m.id, merged.length);\n merged.push(m);\n }\n }\n\n // Remove any messages whose IDs are marked for removal\n return merged.filter((m) => !idsToRemove.has(m.id));\n}\n\n/**\n * **Experimental.** Batch reducer for use with `DeltaChannel`.\n *\n * Processes all writes in one pass — dedup by ID and `RemoveMessage`\n * tombstoning — without calling {@link messagesStateReducer}.\n *\n * This reducer is batching-invariant, as required by `DeltaChannel`:\n * `reducer(reducer(state, xs), ys) === reducer(state, xs.concat(ys))`.\n *\n * A `RemoveMessage` carrying the {@link REMOVE_ALL_MESSAGES} sentinel id\n * clears all messages accumulated so far (prior state plus earlier writes in\n * the same batch) and keeps only the messages that follow it, mirroring\n * {@link messagesStateReducer}. Clearing happens in the same single linear\n * pass, so the batching-invariant still holds.\n *\n * Raw object / string inputs are coerced to typed `BaseMessage` objects so\n * that HTTP-driven graphs work without a separate coercion step. This is not\n * full {@link messagesStateReducer} parity — unknown-id `RemoveMessage`\n * errors and missing-id UUID assignment are not handled here.\n *\n * @param state - The current accumulated list of messages.\n * @param writes - Batch of writes, each a single message-like or an array.\n * @returns The new accumulated list of messages.\n *\n * @example\n * ```typescript\n * import { DeltaChannel, messagesDeltaReducer } from \"@langchain/langgraph\";\n *\n * const channel = new DeltaChannel(messagesDeltaReducer);\n * ```\n */\nexport function messagesDeltaReducer(\n state: BaseMessage[],\n writes: Messages[]\n): BaseMessage[] {\n // Each write is either an array of message-likes or a single message-like.\n // Only arrays flatten; everything else is one message.\n const flat: BaseMessageLike[] = [];\n for (const w of writes) {\n if (Array.isArray(w)) {\n flat.push(...(w as BaseMessageLike[]));\n } else {\n flat.push(w as BaseMessageLike);\n }\n }\n\n // Steady state: the reducer's own output is already typed, so skip coercion\n // on state when the first element is a BaseMessage. Only raw input (initial\n // objects, deserialized blobs) hits the slow path.\n const stateMsgs: BaseMessage[] =\n state.length > 0 && BaseMessage.isInstance(state[0])\n ? state\n : (state as BaseMessageLike[]).map(coerceMessageLikeToMessage);\n const msgs: BaseMessage[] = flat.map(coerceMessageLikeToMessage);\n\n const index = new Map<string, number>();\n for (let i = 0; i < stateMsgs.length; i += 1) {\n const mid = stateMsgs[i].id;\n if (mid != null) index.set(mid, i);\n }\n\n const result: (BaseMessage | null)[] = [...stateMsgs];\n for (const msg of msgs) {\n const mid = msg.id;\n if (RemoveMessage.isInstance(msg) && mid === REMOVE_ALL_MESSAGES) {\n // Discard everything accumulated so far (prior state and earlier writes\n // in this batch); only messages following the sentinel are kept. Doing\n // this inline keeps the reducer batching-invariant.\n result.length = 0;\n index.clear();\n } else if (mid == null) {\n result.push(msg);\n } else if (RemoveMessage.isInstance(msg)) {\n if (index.has(mid)) {\n result[index.get(mid)!] = null;\n index.delete(mid);\n }\n } else if (index.has(mid)) {\n result[index.get(mid)!] = msg;\n } else {\n index.set(mid, result.length);\n result.push(msg);\n }\n }\n return result.filter((m): m is BaseMessage => m !== null);\n}\n\n// A brand rather than reference equality, so the reducer is still recognized\n// from another copy of this package (its ESM and CJS builds both loaded, or a\n// copy nested under another package).\nconst MESSAGES_DELTA_REDUCER = Symbol.for(\"langgraph.messages_delta_reducer\");\nObject.defineProperty(messagesDeltaReducer, MESSAGES_DELTA_REDUCER, {\n value: true,\n});\n\n/** @internal */\nexport function isMessagesDeltaReducer(reducer: unknown): boolean {\n return (\n typeof reducer === \"function\" &&\n (reducer as unknown as Record<symbol, unknown>)[MESSAGES_DELTA_REDUCER] ===\n true\n );\n}\n"],"mappings":";;;;;;;;AAaA,MAAa,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CnC,SAAgB,qBACd,MACA,OACe;CAEf,MAAM,YAAY,MAAM,QAAQ,KAAK,GAAG,OAAO,CAAC,KAAK;CACrD,MAAM,aAAa,MAAM,QAAQ,MAAM,GAAG,QAAQ,CAAC,MAAM;CAGzD,MAAM,eAAgB,UAAgC,IACpD,2BACD;CACD,MAAM,gBAAiB,WAAiC,IACtD,2BACD;AAGD,MAAK,MAA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EtC,MAAK,KAAK,EAAqB;CAOnC,MAAM,YACJ,MAAM,SAAS,KAAK,YAAY,WAAW,MAAM,GAAG,GAChD,QACC,MAA4B,IAAI,2BAA2B;CAClE,MAAM,OAAsB,KAAK,IAAI,2BAA2B;CAEhE,MAAM,wBAAQ,IAAI,KAAqB;AACvC,MAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK,GAAG;EAC5C,MAAM,MAAM,UAAU,GAAG;AACzB,MAAI,OAAO,KAAM,OAAM,IAAI,KAAK,EAAE;;CAGpC,MAAM,SAAiC,CAAC,GAAG,UAAU;AACrD,MAAK,MAAM,OAAO,MAAM;EACtB,MAAM,MAAM,IAAI;AAChB,MAAI,cAAc,WAAW,IAAI,IAAI,QAAA,kBAA6B;AAIhE,UAAO,SAAS;AAChB,SAAM,OAAO;aACJ,OAAO,KAChB,QAAO,KAAK,IAAI;WACP,cAAc,WAAW,IAAI;OAClC,MAAM,IAAI,IAAI,EAAE;AAClB,WAAO,MAAM,IAAI,IAAI,IAAK;AAC1B,UAAM,OAAO,IAAI;;aAEV,MAAM,IAAI,IAAI,CACvB,QAAO,MAAM,IAAI,IAAI,IAAK;OACrB;AACL,SAAM,IAAI,KAAK,OAAO,OAAO;AAC7B,UAAO,KAAK,IAAI;;;AAGpB,QAAO,OAAO,QAAQ,MAAwB,MAAM,KAAK;;AAM3D,MAAM,yBAAyB,OAAO,IAAI,mCAAmC;AAC7E,OAAO,eAAe,sBAAsB,wBAAwB,EAClE,OAAO,MACR,CAAC;;AAGF,SAAgB,uBAAuB,SAA2B;AAChE,QACE,OAAO,YAAY,cAClB,QAA+C,4BAC9C"}
1
+ {"version":3,"file":"messages_reducer.js","names":[],"sources":["../../src/graph/messages_reducer.ts"],"sourcesContent":["import {\n AIMessage,\n BaseMessage,\n BaseMessageChunk,\n BaseMessageLike,\n ChatMessage,\n coerceMessageLikeToMessage,\n FunctionMessage,\n HumanMessage,\n RemoveMessage,\n SystemMessage,\n ToolMessage,\n} from \"@langchain/core/messages\";\nimport { v4 } from \"@langchain/core/utils/uuid\";\n\n/**\n * Special value that signifies the intent to remove all previous messages in the state reducer.\n * Used as the unique identifier for a `RemoveMessage` instance which, when encountered,\n * causes all prior messages to be discarded, leaving only those following this marker.\n */\nexport const REMOVE_ALL_MESSAGES = \"__remove_all__\";\n\n/**\n * Type that represents an acceptable input for the messages state reducer.\n *\n * - Can be a single `BaseMessage` or `BaseMessageLike`.\n * - Can be an array of `BaseMessage` or `BaseMessageLike`.\n */\nexport type Messages =\n | Array<BaseMessage | BaseMessageLike>\n | BaseMessage\n | BaseMessageLike;\n\nconst MESSAGE_CLASS_BY_TYPE: Record<\n string,\n new (fields: never) => BaseMessage\n> = {\n human: HumanMessage,\n ai: AIMessage,\n system: SystemMessage,\n tool: ToolMessage,\n function: FunctionMessage,\n generic: ChatMessage,\n};\n\n// A chat model called under a streaming callback (`streamMode: \"messages\"`,\n// `streamEvents`) returns the aggregated chunk. Stored as-is, the checkpoint\n// would depend on how the graph was run, and on reload an `AIMessageChunk`\n// rebuilds `tool_calls` from `tool_call_chunks`, undoing in-place edits.\n// Same conversion as Python's `add_messages`.\nfunction toMessage(messageLike: BaseMessageLike): BaseMessage {\n const message = coerceMessageLikeToMessage(messageLike);\n if (!BaseMessageChunk.isInstance(message)) return message;\n const MessageClass = MESSAGE_CLASS_BY_TYPE[message.getType()];\n if (MessageClass === undefined) return message;\n const fields = Object.fromEntries(\n Object.entries(message).filter(\n ([key]) =>\n key !== \"type\" && key !== \"tool_call_chunks\" && !key.startsWith(\"lc_\")\n )\n );\n return new MessageClass(fields as never);\n}\n\n/**\n * Reducer function for combining two sets of messages in LangGraph's state system.\n *\n * This reducer handles several tasks:\n * 1. Normalizes both `left` and `right` message inputs to arrays.\n * 2. Coerces any message-like objects into real `BaseMessage` instances, and\n * message chunks (e.g. `AIMessageChunk`) into their non-chunk class.\n * 3. Ensures all messages have unique, stable IDs by generating missing ones.\n * 4. If a `RemoveMessage` instance is encountered in `right` with the ID `REMOVE_ALL_MESSAGES`,\n * all previous messages are discarded and only the subsequent messages in `right` are returned.\n * 5. Otherwise, merges `left` and `right` messages together following these rules:\n * - If a message in `right` shares an ID with a message in `left`:\n * - If it is a `RemoveMessage`, that message (by ID) is marked for removal.\n * - If it is a normal message, it replaces the message with the same ID from `left`.\n * - If a message in `right` **does not exist** in `left`:\n * - If it is a `RemoveMessage`, this is considered an error (cannot remove non-existent ID).\n * - Otherwise, the message is appended.\n * - Messages flagged for removal are omitted from the final output.\n *\n * @param left - The existing array (or single message) of messages from current state.\n * @param right - The new array (or single message) of messages to be applied.\n * @returns A new array of `BaseMessage` objects representing the updated state.\n *\n * @throws Error if a `RemoveMessage` is used to delete a message with an ID that does not exist in the merged list.\n *\n * @example\n * ```ts\n * const msg1 = new AIMessage(\"hello\");\n * const msg2 = new HumanMessage(\"hi\");\n * const removal = new RemoveMessage({ id: msg1.id });\n * const newState = messagesStateReducer([msg1], [msg2, removal]);\n * // newState will only contain msg2 (msg1 is removed)\n * ```\n */\nexport function messagesStateReducer(\n left: Messages,\n right: Messages\n): BaseMessage[] {\n // Ensure both left and right are arrays\n const leftArray = Array.isArray(left) ? left : [left];\n const rightArray = Array.isArray(right) ? right : [right];\n\n // Convert all input to BaseMessage instances\n const leftMessages = (leftArray as BaseMessageLike[]).map(toMessage);\n const rightMessages = (rightArray as BaseMessageLike[]).map(toMessage);\n\n // Assign missing IDs to any message in the left array\n for (const m of leftMessages) {\n if (m.id === null || m.id === undefined) {\n m.id = v4();\n m.lc_kwargs.id = m.id;\n }\n }\n\n // Assign missing IDs and check for \"remove all\" marker in right array\n let removeAllIdx: number | undefined;\n for (let i = 0; i < rightMessages.length; i += 1) {\n const m = rightMessages[i];\n if (m.id === null || m.id === undefined) {\n m.id = v4();\n m.lc_kwargs.id = m.id;\n }\n\n // If RemoveMessage with special REMOVE_ALL_MESSAGES id is found\n if (RemoveMessage.isInstance(m) && m.id === REMOVE_ALL_MESSAGES) {\n removeAllIdx = i;\n }\n }\n\n // If remove-all is present, all previous messages are wiped; return only subsequent ones\n if (removeAllIdx != null) return rightMessages.slice(removeAllIdx + 1);\n\n // Begin normal merging logic\n const merged = [...leftMessages];\n const mergedById = new Map(merged.map((m, i) => [m.id, i]));\n const idsToRemove = new Set();\n\n for (const m of rightMessages) {\n const existingIdx = mergedById.get(m.id);\n if (existingIdx !== undefined) {\n // Case: updating or removing an existing message by id\n if (RemoveMessage.isInstance(m)) {\n idsToRemove.add(m.id);\n } else {\n idsToRemove.delete(m.id);\n merged[existingIdx] = m;\n }\n } else {\n // Case: inserting a completely new message\n if (RemoveMessage.isInstance(m)) {\n throw new Error(\n `Attempting to delete a message with an ID that doesn't exist ('${m.id}')`\n );\n }\n mergedById.set(m.id, merged.length);\n merged.push(m);\n }\n }\n\n // Remove any messages whose IDs are marked for removal\n return merged.filter((m) => !idsToRemove.has(m.id));\n}\n\n/**\n * **Experimental.** Batch reducer for use with `DeltaChannel`.\n *\n * Processes all writes in one pass — dedup by ID and `RemoveMessage`\n * tombstoning — without calling {@link messagesStateReducer}.\n *\n * This reducer is batching-invariant, as required by `DeltaChannel`:\n * `reducer(reducer(state, xs), ys) === reducer(state, xs.concat(ys))`.\n *\n * A `RemoveMessage` carrying the {@link REMOVE_ALL_MESSAGES} sentinel id\n * clears all messages accumulated so far (prior state plus earlier writes in\n * the same batch) and keeps only the messages that follow it, mirroring\n * {@link messagesStateReducer}. Clearing happens in the same single linear\n * pass, so the batching-invariant still holds.\n *\n * Raw object / string inputs are coerced to typed `BaseMessage` objects so\n * that HTTP-driven graphs work without a separate coercion step, and message\n * chunks are converted to their non-chunk class. This is not\n * full {@link messagesStateReducer} parity — unknown-id `RemoveMessage`\n * errors and missing-id UUID assignment are not handled here.\n *\n * @param state - The current accumulated list of messages.\n * @param writes - Batch of writes, each a single message-like or an array.\n * @returns The new accumulated list of messages.\n *\n * @example\n * ```typescript\n * import { DeltaChannel, messagesDeltaReducer } from \"@langchain/langgraph\";\n *\n * const channel = new DeltaChannel(messagesDeltaReducer);\n * ```\n */\nexport function messagesDeltaReducer(\n state: BaseMessage[],\n writes: Messages[]\n): BaseMessage[] {\n // Each write is either an array of message-likes or a single message-like.\n // Only arrays flatten; everything else is one message.\n const flat: BaseMessageLike[] = [];\n for (const w of writes) {\n if (Array.isArray(w)) {\n flat.push(...(w as BaseMessageLike[]));\n } else {\n flat.push(w as BaseMessageLike);\n }\n }\n\n // Steady state: the reducer's own output is already typed, so skip coercion\n // on state when the first element is a BaseMessage. Only raw input (initial\n // objects, deserialized blobs) hits the slow path.\n const stateMsgs: BaseMessage[] =\n state.length > 0 && BaseMessage.isInstance(state[0])\n ? state\n : (state as BaseMessageLike[]).map(toMessage);\n const msgs: BaseMessage[] = flat.map(toMessage);\n\n const index = new Map<string, number>();\n for (let i = 0; i < stateMsgs.length; i += 1) {\n const mid = stateMsgs[i].id;\n if (mid != null) index.set(mid, i);\n }\n\n const result: (BaseMessage | null)[] = [...stateMsgs];\n for (const msg of msgs) {\n const mid = msg.id;\n if (RemoveMessage.isInstance(msg) && mid === REMOVE_ALL_MESSAGES) {\n // Discard everything accumulated so far (prior state and earlier writes\n // in this batch); only messages following the sentinel are kept. Doing\n // this inline keeps the reducer batching-invariant.\n result.length = 0;\n index.clear();\n } else if (mid == null) {\n result.push(msg);\n } else if (RemoveMessage.isInstance(msg)) {\n if (index.has(mid)) {\n result[index.get(mid)!] = null;\n index.delete(mid);\n }\n } else if (index.has(mid)) {\n result[index.get(mid)!] = msg;\n } else {\n index.set(mid, result.length);\n result.push(msg);\n }\n }\n return result.filter((m): m is BaseMessage => m !== null);\n}\n\n// A brand rather than reference equality, so the reducer is still recognized\n// from another copy of this package (its ESM and CJS builds both loaded, or a\n// copy nested under another package).\nconst MESSAGES_DELTA_REDUCER = Symbol.for(\"langgraph.messages_delta_reducer\");\nObject.defineProperty(messagesDeltaReducer, MESSAGES_DELTA_REDUCER, {\n value: true,\n});\n\n/** @internal */\nexport function isMessagesDeltaReducer(reducer: unknown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rD,MAAK,MAAM,OAAO,MAAM;EACtB,MAAM,MAAM,IAAI;AAChB,MAAI,cAAc,WAAW,IAAI,IAAI,QAAA,kBAA6B;AAIhE,UAAO,SAAS;AAChB,SAAM,OAAO;aACJ,OAAO,KAChB,QAAO,KAAK,IAAI;WACP,cAAc,WAAW,IAAI;OAClC,MAAM,IAAI,IAAI,EAAE;AAClB,WAAO,MAAM,IAAI,IAAI,IAAK;AAC1B,UAAM,OAAO,IAAI;;aAEV,MAAM,IAAI,IAAI,CACvB,QAAO,MAAM,IAAI,IAAI,IAAK;OACrB;AACL,SAAM,IAAI,KAAK,OAAO,OAAO;AAC7B,UAAO,KAAK,IAAI;;;AAGpB,QAAO,OAAO,QAAQ,MAAwB,MAAM,KAAK;;AAM3D,MAAM,yBAAyB,OAAO,IAAI,mCAAmC;AAC7E,OAAO,eAAe,sBAAsB,wBAAwB,EAClE,OAAO,MACR,CAAC;;AAGF,SAAgB,uBAAuB,SAA2B;AAChE,QACE,OAAO,YAAY,cAClB,QAA+C,4BAC9C"}
package/dist/index.cjs CHANGED
@@ -126,6 +126,7 @@ exports.SubgraphRunStream = require_run_stream.SubgraphRunStream;
126
126
  exports.UnreachableNodeError = require_errors.UnreachableNodeError;
127
127
  exports.UntrackedValue = require_untracked.UntrackedValue;
128
128
  exports.UntrackedValueChannel = require_untracked_value.UntrackedValueChannel;
129
+ exports._markInvalidResume = require_errors._markInvalidResume;
129
130
  exports.addMessages = require_messages_reducer.messagesStateReducer;
130
131
  exports.convertToProtocolEvent = require_convert.convertToProtocolEvent;
131
132
  Object.defineProperty(exports, "copyCheckpoint", {
@@ -163,6 +164,7 @@ exports.isGraphBubbleUp = require_errors.isGraphBubbleUp;
163
164
  exports.isGraphDrained = require_errors.isGraphDrained;
164
165
  exports.isGraphInterrupt = require_errors.isGraphInterrupt;
165
166
  exports.isInterrupted = require_constants.isInterrupted;
167
+ exports.isInvalidResume = require_errors.isInvalidResume;
166
168
  exports.isNativeTransformer = require_types.isNativeTransformer;
167
169
  exports.isNodeError = require_errors.isNodeError;
168
170
  exports.isNodeTimeoutError = require_errors.isNodeTimeoutError;
package/dist/index.d.cts CHANGED
@@ -27,7 +27,7 @@ import { createValuesTransformer } from "./stream/transformers/values.cjs";
27
27
  import { CreateGraphRunStreamOptions, GraphRunStream, SubgraphRunStream, createGraphRunStream } from "./stream/run-stream.cjs";
28
28
  import { ChatModelStreamImpl } from "./stream/index.cjs";
29
29
  import { Pregel } from "./pregel/index.cjs";
30
- import { BaseLangGraphError, BaseLangGraphErrorFields, EmptyChannelError, EmptyInputError, GraphBubbleUp, GraphDrained, GraphInterrupt, GraphRecursionError, GraphValueError, InvalidUpdateError, MultipleSubgraphsError, NodeError, NodeInterrupt, NodeTimeoutError, ParentCommand, RemoteException, StateGraphInputError, UnreachableNodeError, getSubgraphsSeenSet, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isNodeError, isNodeTimeoutError, isParentCommand } from "./errors.cjs";
30
+ import { BaseLangGraphError, BaseLangGraphErrorFields, EmptyChannelError, EmptyInputError, GraphBubbleUp, GraphDrained, GraphInterrupt, GraphRecursionError, GraphValueError, InvalidUpdateError, MultipleSubgraphsError, NodeError, NodeInterrupt, NodeTimeoutError, ParentCommand, RemoteException, StateGraphInputError, UnreachableNodeError, _markInvalidResume, getSubgraphsSeenSet, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isInvalidResume, isNodeError, isNodeTimeoutError, isParentCommand } from "./errors.cjs";
31
31
  import { isSerializableSchema, isStandardSchema } from "./state/types.cjs";
32
32
  import { ReducedValue, ReducedValueInit } from "./state/values/reduced.cjs";
33
33
  import { UntrackedValue, UntrackedValueInit } from "./state/values/untracked.cjs";
@@ -47,4 +47,4 @@ import { MessagesDeltaValue, MessagesValue } from "./state/prebuilt/messages.cjs
47
47
  import { getConfig, getCurrentTaskInput, getStore, getWriter } from "./pregel/utils/config.cjs";
48
48
  import { GraphCallbackHandler, GraphInterruptEvent, GraphLifecycleEvent, GraphLifecycleStatus, GraphResumeEvent } from "./callbacks.cjs";
49
49
  import { AsyncBatchedStore, BaseCheckpointSaver, BaseStore, Checkpoint, CheckpointMetadata, CheckpointTuple, GetOperation, InMemoryStore, Item, ListNamespacesOperation, MatchCondition, MemorySaver, NameSpacePath, NamespaceMatchType, Operation, OperationResults, PutOperation, SearchOperation, copyCheckpoint, emptyCheckpoint } from "./web.cjs";
50
- export { AddNodeOptions, AgentStatus, Annotation, AnnotationRoot, AnyStateSchema, AnyValue, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseLangGraphErrorFields, BaseStore, BinaryOperator, BinaryOperatorAggregate, COMMAND_SYMBOL, CachePolicy, ChatModelStream, ChatModelStreamImpl, Checkpoint, CheckpointMetadata, CheckpointTuple, Command, CommandInstance, CommandParams, CompiledGraph, CompiledGraphType, CompiledStateGraph, ConditionalEdgeRouter, ConditionalEdgeRouterTypes, ContextSchemaInit, ConvertToProtocolEventOptions, CreateGraphRunStreamOptions, DeltaChannel, DeltaReducer, DeltaValue, DeltaValueInit, DynamicBarrierValue, END, EmptyChannelError, EmptyInputError, EntrypointOptions, EphemeralValue, StreamChannel as EventLog, ExecutionInfo, ExtractStateType, ExtractUpdateType, GetOperation, GetStateOptions, Graph, GraphBubbleUp, GraphCallbackHandler, GraphDrained, GraphInterrupt, GraphInterruptEvent, GraphLifecycleEvent, GraphLifecycleStatus, GraphNode, GraphNodeReturnValue, GraphNodeTypes, GraphRecursionError, GraphResumeEvent, GraphRunStream, GraphValueError, INTERRUPT, InMemoryStore, InferExtensions, InferInterruptInputType, InferInterruptResumeType, InferStateSchemaUpdate, InferStateSchemaValue, InferWriterType, Interrupt, InterruptOptions, InterruptPayload, InvalidUpdateError, Item, LangGraphRunnableConfig, LastValue, LifecycleCause, LifecycleData, LifecycleEntry, LifecycleProjection, LifecycleTransformerOptions, ListNamespacesOperation, MatchCondition, MemorySaver, MessageGraph, Messages, MessagesAnnotation, MessagesDeltaValue, MessagesEventData, MessagesValue, MessagesZodMeta, MessagesZodState, MultipleChannelSubscriptionOptions, MultipleSubgraphsError, NameSpacePath, NamedBarrierValue, Namespace, NamespaceMatchType, NativeStreamTransformer, NodeError, NodeInterrupt, NodePolicyOptions, NodeSpec, NodeTimeoutError, NodeType, Operation, OperationResults, Overwrite, OverwriteValue, ParentCommand, Pregel, PregelNode, PregelOptions, PregelParams, ProtocolEvent, PutOperation, REMOVE_ALL_MESSAGES, ReducedValue, ReducedValueInit, RemoteException, RetryPolicy, RunControl, Runtime, START, STREAM_EVENTS_V3_MODES, SearchOperation, Send, SendOptions, ServerInfo, SingleChannelSubscriptionOptions, SingleReducer, StateDefinition, StateDefinitionInit, StateGraph, StateGraphAddNodeOptions, StateGraphArgs, StateGraphArgsWithInputOutputSchemas, StateGraphArgsWithStateSchema, StateGraphInit, StateGraphInputError, StateGraphNodeSpec, StateGraphOptions, StateSchema, StateSchemaField, StateSchemaFieldToChannel, StateSchemaFields, StateSchemaFieldsToStateDefinition, StateSnapshot, StateType, StreamChannel, StreamEmitter, StreamMode, StreamOutputMap, StreamTransformer, SubgraphDiscoveryProjection, SubgraphDiscoveryTransformerOptions, SubgraphRunStream, TaskOptions, TimeoutPolicy, ToStateDefinition, ToolCallStatus, ToolCallStream, ToolsEventData, Topic, UnreachableNodeError, UntrackedValue, UntrackedValueChannel, UntrackedValueInit, UpdateType, UpdatesEventData, UsageInfo, WaitForNames, messagesStateReducer as addMessages, convertToProtocolEvent, copyCheckpoint, createGraphRunStream, createLifecycleTransformer, createMessagesTransformer, createSubgraphDiscoveryTransformer, createValuesTransformer, emptyCheckpoint, entrypoint, filterLifecycleEntries, filterSubgraphHandles, getConfig, getCurrentTaskInput, getJsonSchemaFromSchema, getPreviousState, getSchemaDefaultGetter, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCheckpointEnvelope, isCommand, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isInterrupted, isNativeTransformer, isNodeError, isNodeTimeoutError, isParentCommand, isSerializableSchema, isStandardSchema, messagesDeltaReducer, messagesStateReducer, pushMessage, task, writer };
50
+ export { AddNodeOptions, AgentStatus, Annotation, AnnotationRoot, AnyStateSchema, AnyValue, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseLangGraphErrorFields, BaseStore, BinaryOperator, BinaryOperatorAggregate, COMMAND_SYMBOL, CachePolicy, ChatModelStream, ChatModelStreamImpl, Checkpoint, CheckpointMetadata, CheckpointTuple, Command, CommandInstance, CommandParams, CompiledGraph, CompiledGraphType, CompiledStateGraph, ConditionalEdgeRouter, ConditionalEdgeRouterTypes, ContextSchemaInit, ConvertToProtocolEventOptions, CreateGraphRunStreamOptions, DeltaChannel, DeltaReducer, DeltaValue, DeltaValueInit, DynamicBarrierValue, END, EmptyChannelError, EmptyInputError, EntrypointOptions, EphemeralValue, StreamChannel as EventLog, ExecutionInfo, ExtractStateType, ExtractUpdateType, GetOperation, GetStateOptions, Graph, GraphBubbleUp, GraphCallbackHandler, GraphDrained, GraphInterrupt, GraphInterruptEvent, GraphLifecycleEvent, GraphLifecycleStatus, GraphNode, GraphNodeReturnValue, GraphNodeTypes, GraphRecursionError, GraphResumeEvent, GraphRunStream, GraphValueError, INTERRUPT, InMemoryStore, InferExtensions, InferInterruptInputType, InferInterruptResumeType, InferStateSchemaUpdate, InferStateSchemaValue, InferWriterType, Interrupt, InterruptOptions, InterruptPayload, InvalidUpdateError, Item, LangGraphRunnableConfig, LastValue, LifecycleCause, LifecycleData, LifecycleEntry, LifecycleProjection, LifecycleTransformerOptions, ListNamespacesOperation, MatchCondition, MemorySaver, MessageGraph, Messages, MessagesAnnotation, MessagesDeltaValue, MessagesEventData, MessagesValue, MessagesZodMeta, MessagesZodState, MultipleChannelSubscriptionOptions, MultipleSubgraphsError, NameSpacePath, NamedBarrierValue, Namespace, NamespaceMatchType, NativeStreamTransformer, NodeError, NodeInterrupt, NodePolicyOptions, NodeSpec, NodeTimeoutError, NodeType, Operation, OperationResults, Overwrite, OverwriteValue, ParentCommand, Pregel, PregelNode, PregelOptions, PregelParams, ProtocolEvent, PutOperation, REMOVE_ALL_MESSAGES, ReducedValue, ReducedValueInit, RemoteException, RetryPolicy, RunControl, Runtime, START, STREAM_EVENTS_V3_MODES, SearchOperation, Send, SendOptions, ServerInfo, SingleChannelSubscriptionOptions, SingleReducer, StateDefinition, StateDefinitionInit, StateGraph, StateGraphAddNodeOptions, StateGraphArgs, StateGraphArgsWithInputOutputSchemas, StateGraphArgsWithStateSchema, StateGraphInit, StateGraphInputError, StateGraphNodeSpec, StateGraphOptions, StateSchema, StateSchemaField, StateSchemaFieldToChannel, StateSchemaFields, StateSchemaFieldsToStateDefinition, StateSnapshot, StateType, StreamChannel, StreamEmitter, StreamMode, StreamOutputMap, StreamTransformer, SubgraphDiscoveryProjection, SubgraphDiscoveryTransformerOptions, SubgraphRunStream, TaskOptions, TimeoutPolicy, ToStateDefinition, ToolCallStatus, ToolCallStream, ToolsEventData, Topic, UnreachableNodeError, UntrackedValue, UntrackedValueChannel, UntrackedValueInit, UpdateType, UpdatesEventData, UsageInfo, WaitForNames, _markInvalidResume, messagesStateReducer as addMessages, convertToProtocolEvent, copyCheckpoint, createGraphRunStream, createLifecycleTransformer, createMessagesTransformer, createSubgraphDiscoveryTransformer, createValuesTransformer, emptyCheckpoint, entrypoint, filterLifecycleEntries, filterSubgraphHandles, getConfig, getCurrentTaskInput, getJsonSchemaFromSchema, getPreviousState, getSchemaDefaultGetter, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCheckpointEnvelope, isCommand, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isInterrupted, isInvalidResume, isNativeTransformer, isNodeError, isNodeTimeoutError, isParentCommand, isSerializableSchema, isStandardSchema, messagesDeltaReducer, messagesStateReducer, pushMessage, task, writer };
package/dist/index.d.ts CHANGED
@@ -27,7 +27,7 @@ import { createValuesTransformer } from "./stream/transformers/values.js";
27
27
  import { CreateGraphRunStreamOptions, GraphRunStream, SubgraphRunStream, createGraphRunStream } from "./stream/run-stream.js";
28
28
  import { ChatModelStreamImpl } from "./stream/index.js";
29
29
  import { Pregel } from "./pregel/index.js";
30
- import { BaseLangGraphError, BaseLangGraphErrorFields, EmptyChannelError, EmptyInputError, GraphBubbleUp, GraphDrained, GraphInterrupt, GraphRecursionError, GraphValueError, InvalidUpdateError, MultipleSubgraphsError, NodeError, NodeInterrupt, NodeTimeoutError, ParentCommand, RemoteException, StateGraphInputError, UnreachableNodeError, getSubgraphsSeenSet, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isNodeError, isNodeTimeoutError, isParentCommand } from "./errors.js";
30
+ import { BaseLangGraphError, BaseLangGraphErrorFields, EmptyChannelError, EmptyInputError, GraphBubbleUp, GraphDrained, GraphInterrupt, GraphRecursionError, GraphValueError, InvalidUpdateError, MultipleSubgraphsError, NodeError, NodeInterrupt, NodeTimeoutError, ParentCommand, RemoteException, StateGraphInputError, UnreachableNodeError, _markInvalidResume, getSubgraphsSeenSet, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isInvalidResume, isNodeError, isNodeTimeoutError, isParentCommand } from "./errors.js";
31
31
  import { isSerializableSchema, isStandardSchema } from "./state/types.js";
32
32
  import { ReducedValue, ReducedValueInit } from "./state/values/reduced.js";
33
33
  import { UntrackedValue, UntrackedValueInit } from "./state/values/untracked.js";
@@ -47,4 +47,4 @@ import { MessagesDeltaValue, MessagesValue } from "./state/prebuilt/messages.js"
47
47
  import { getConfig, getCurrentTaskInput, getStore, getWriter } from "./pregel/utils/config.js";
48
48
  import { GraphCallbackHandler, GraphInterruptEvent, GraphLifecycleEvent, GraphLifecycleStatus, GraphResumeEvent } from "./callbacks.js";
49
49
  import { AsyncBatchedStore, BaseCheckpointSaver, BaseStore, Checkpoint, CheckpointMetadata, CheckpointTuple, GetOperation, InMemoryStore, Item, ListNamespacesOperation, MatchCondition, MemorySaver, NameSpacePath, NamespaceMatchType, Operation, OperationResults, PutOperation, SearchOperation, copyCheckpoint, emptyCheckpoint } from "./web.js";
50
- export { AddNodeOptions, AgentStatus, Annotation, AnnotationRoot, AnyStateSchema, AnyValue, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseLangGraphErrorFields, BaseStore, BinaryOperator, BinaryOperatorAggregate, COMMAND_SYMBOL, CachePolicy, ChatModelStream, ChatModelStreamImpl, Checkpoint, CheckpointMetadata, CheckpointTuple, Command, CommandInstance, CommandParams, CompiledGraph, CompiledGraphType, CompiledStateGraph, ConditionalEdgeRouter, ConditionalEdgeRouterTypes, ContextSchemaInit, ConvertToProtocolEventOptions, CreateGraphRunStreamOptions, DeltaChannel, DeltaReducer, DeltaValue, DeltaValueInit, DynamicBarrierValue, END, EmptyChannelError, EmptyInputError, EntrypointOptions, EphemeralValue, StreamChannel as EventLog, ExecutionInfo, ExtractStateType, ExtractUpdateType, GetOperation, GetStateOptions, Graph, GraphBubbleUp, GraphCallbackHandler, GraphDrained, GraphInterrupt, GraphInterruptEvent, GraphLifecycleEvent, GraphLifecycleStatus, GraphNode, GraphNodeReturnValue, GraphNodeTypes, GraphRecursionError, GraphResumeEvent, GraphRunStream, GraphValueError, INTERRUPT, InMemoryStore, InferExtensions, InferInterruptInputType, InferInterruptResumeType, InferStateSchemaUpdate, InferStateSchemaValue, InferWriterType, Interrupt, InterruptOptions, InterruptPayload, InvalidUpdateError, Item, LangGraphRunnableConfig, LastValue, LifecycleCause, LifecycleData, LifecycleEntry, LifecycleProjection, LifecycleTransformerOptions, ListNamespacesOperation, MatchCondition, MemorySaver, MessageGraph, Messages, MessagesAnnotation, MessagesDeltaValue, MessagesEventData, MessagesValue, MessagesZodMeta, MessagesZodState, MultipleChannelSubscriptionOptions, MultipleSubgraphsError, NameSpacePath, NamedBarrierValue, Namespace, NamespaceMatchType, NativeStreamTransformer, NodeError, NodeInterrupt, NodePolicyOptions, NodeSpec, NodeTimeoutError, NodeType, Operation, OperationResults, Overwrite, OverwriteValue, ParentCommand, Pregel, PregelNode, PregelOptions, PregelParams, ProtocolEvent, PutOperation, REMOVE_ALL_MESSAGES, ReducedValue, ReducedValueInit, RemoteException, RetryPolicy, RunControl, Runtime, START, STREAM_EVENTS_V3_MODES, SearchOperation, Send, SendOptions, ServerInfo, SingleChannelSubscriptionOptions, SingleReducer, StateDefinition, StateDefinitionInit, StateGraph, StateGraphAddNodeOptions, StateGraphArgs, StateGraphArgsWithInputOutputSchemas, StateGraphArgsWithStateSchema, StateGraphInit, StateGraphInputError, StateGraphNodeSpec, StateGraphOptions, StateSchema, StateSchemaField, StateSchemaFieldToChannel, StateSchemaFields, StateSchemaFieldsToStateDefinition, StateSnapshot, StateType, StreamChannel, StreamEmitter, StreamMode, StreamOutputMap, StreamTransformer, SubgraphDiscoveryProjection, SubgraphDiscoveryTransformerOptions, SubgraphRunStream, TaskOptions, TimeoutPolicy, ToStateDefinition, ToolCallStatus, ToolCallStream, ToolsEventData, Topic, UnreachableNodeError, UntrackedValue, UntrackedValueChannel, UntrackedValueInit, UpdateType, UpdatesEventData, UsageInfo, WaitForNames, messagesStateReducer as addMessages, convertToProtocolEvent, copyCheckpoint, createGraphRunStream, createLifecycleTransformer, createMessagesTransformer, createSubgraphDiscoveryTransformer, createValuesTransformer, emptyCheckpoint, entrypoint, filterLifecycleEntries, filterSubgraphHandles, getConfig, getCurrentTaskInput, getJsonSchemaFromSchema, getPreviousState, getSchemaDefaultGetter, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCheckpointEnvelope, isCommand, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isInterrupted, isNativeTransformer, isNodeError, isNodeTimeoutError, isParentCommand, isSerializableSchema, isStandardSchema, messagesDeltaReducer, messagesStateReducer, pushMessage, task, writer };
50
+ export { AddNodeOptions, AgentStatus, Annotation, AnnotationRoot, AnyStateSchema, AnyValue, AsyncBatchedStore, BaseChannel, BaseCheckpointSaver, BaseLangGraphError, BaseLangGraphErrorFields, BaseStore, BinaryOperator, BinaryOperatorAggregate, COMMAND_SYMBOL, CachePolicy, ChatModelStream, ChatModelStreamImpl, Checkpoint, CheckpointMetadata, CheckpointTuple, Command, CommandInstance, CommandParams, CompiledGraph, CompiledGraphType, CompiledStateGraph, ConditionalEdgeRouter, ConditionalEdgeRouterTypes, ContextSchemaInit, ConvertToProtocolEventOptions, CreateGraphRunStreamOptions, DeltaChannel, DeltaReducer, DeltaValue, DeltaValueInit, DynamicBarrierValue, END, EmptyChannelError, EmptyInputError, EntrypointOptions, EphemeralValue, StreamChannel as EventLog, ExecutionInfo, ExtractStateType, ExtractUpdateType, GetOperation, GetStateOptions, Graph, GraphBubbleUp, GraphCallbackHandler, GraphDrained, GraphInterrupt, GraphInterruptEvent, GraphLifecycleEvent, GraphLifecycleStatus, GraphNode, GraphNodeReturnValue, GraphNodeTypes, GraphRecursionError, GraphResumeEvent, GraphRunStream, GraphValueError, INTERRUPT, InMemoryStore, InferExtensions, InferInterruptInputType, InferInterruptResumeType, InferStateSchemaUpdate, InferStateSchemaValue, InferWriterType, Interrupt, InterruptOptions, InterruptPayload, InvalidUpdateError, Item, LangGraphRunnableConfig, LastValue, LifecycleCause, LifecycleData, LifecycleEntry, LifecycleProjection, LifecycleTransformerOptions, ListNamespacesOperation, MatchCondition, MemorySaver, MessageGraph, Messages, MessagesAnnotation, MessagesDeltaValue, MessagesEventData, MessagesValue, MessagesZodMeta, MessagesZodState, MultipleChannelSubscriptionOptions, MultipleSubgraphsError, NameSpacePath, NamedBarrierValue, Namespace, NamespaceMatchType, NativeStreamTransformer, NodeError, NodeInterrupt, NodePolicyOptions, NodeSpec, NodeTimeoutError, NodeType, Operation, OperationResults, Overwrite, OverwriteValue, ParentCommand, Pregel, PregelNode, PregelOptions, PregelParams, ProtocolEvent, PutOperation, REMOVE_ALL_MESSAGES, ReducedValue, ReducedValueInit, RemoteException, RetryPolicy, RunControl, Runtime, START, STREAM_EVENTS_V3_MODES, SearchOperation, Send, SendOptions, ServerInfo, SingleChannelSubscriptionOptions, SingleReducer, StateDefinition, StateDefinitionInit, StateGraph, StateGraphAddNodeOptions, StateGraphArgs, StateGraphArgsWithInputOutputSchemas, StateGraphArgsWithStateSchema, StateGraphInit, StateGraphInputError, StateGraphNodeSpec, StateGraphOptions, StateSchema, StateSchemaField, StateSchemaFieldToChannel, StateSchemaFields, StateSchemaFieldsToStateDefinition, StateSnapshot, StateType, StreamChannel, StreamEmitter, StreamMode, StreamOutputMap, StreamTransformer, SubgraphDiscoveryProjection, SubgraphDiscoveryTransformerOptions, SubgraphRunStream, TaskOptions, TimeoutPolicy, ToStateDefinition, ToolCallStatus, ToolCallStream, ToolsEventData, Topic, UnreachableNodeError, UntrackedValue, UntrackedValueChannel, UntrackedValueInit, UpdateType, UpdatesEventData, UsageInfo, WaitForNames, _markInvalidResume, messagesStateReducer as addMessages, convertToProtocolEvent, copyCheckpoint, createGraphRunStream, createLifecycleTransformer, createMessagesTransformer, createSubgraphDiscoveryTransformer, createValuesTransformer, emptyCheckpoint, entrypoint, filterLifecycleEntries, filterSubgraphHandles, getConfig, getCurrentTaskInput, getJsonSchemaFromSchema, getPreviousState, getSchemaDefaultGetter, getStore, getSubgraphsSeenSet, getWriter, interrupt, isCheckpointEnvelope, isCommand, isGraphBubbleUp, isGraphDrained, isGraphInterrupt, isInterrupted, isInvalidResume, isNativeTransformer, isNodeError, isNodeTimeoutError, isParentCommand, isSerializableSchema, isStandardSchema, messagesDeltaReducer, messagesStateReducer, pushMessage, task, writer };