@langchain/langgraph 0.2.8 → 0.2.9

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 (45) hide show
  1. package/dist/constants.cjs +12 -2
  2. package/dist/constants.d.ts +7 -1
  3. package/dist/constants.js +11 -1
  4. package/dist/errors.cjs +5 -4
  5. package/dist/errors.d.ts +1 -1
  6. package/dist/errors.js +5 -4
  7. package/dist/graph/graph.cjs +7 -2
  8. package/dist/graph/graph.js +8 -3
  9. package/dist/graph/message.cjs +2 -0
  10. package/dist/graph/message.js +2 -0
  11. package/dist/graph/state.cjs +8 -3
  12. package/dist/graph/state.d.ts +1 -1
  13. package/dist/graph/state.js +9 -4
  14. package/dist/managed/shared_value.cjs +1 -1
  15. package/dist/managed/shared_value.js +1 -1
  16. package/dist/pregel/algo.cjs +119 -54
  17. package/dist/pregel/algo.d.ts +5 -2
  18. package/dist/pregel/algo.js +117 -53
  19. package/dist/pregel/debug.cjs +15 -18
  20. package/dist/pregel/debug.d.ts +3 -2
  21. package/dist/pregel/debug.js +16 -19
  22. package/dist/pregel/index.cjs +295 -110
  23. package/dist/pregel/index.d.ts +16 -4
  24. package/dist/pregel/index.js +292 -110
  25. package/dist/pregel/io.cjs +15 -8
  26. package/dist/pregel/io.d.ts +2 -2
  27. package/dist/pregel/io.js +15 -8
  28. package/dist/pregel/loop.cjs +256 -111
  29. package/dist/pregel/loop.d.ts +21 -5
  30. package/dist/pregel/loop.js +256 -109
  31. package/dist/pregel/read.cjs +9 -2
  32. package/dist/pregel/read.d.ts +2 -1
  33. package/dist/pregel/read.js +9 -2
  34. package/dist/pregel/retry.d.ts +1 -1
  35. package/dist/pregel/types.d.ts +5 -1
  36. package/dist/pregel/utils/config.cjs +72 -0
  37. package/dist/pregel/utils/config.d.ts +2 -0
  38. package/dist/pregel/utils/config.js +68 -0
  39. package/dist/pregel/{utils.cjs → utils/index.cjs} +33 -10
  40. package/dist/pregel/{utils.d.ts → utils/index.d.ts} +4 -7
  41. package/dist/pregel/{utils.js → utils/index.js} +30 -8
  42. package/dist/utils.cjs +5 -3
  43. package/dist/utils.js +5 -3
  44. package/dist/web.d.ts +2 -1
  45. package/package.json +1 -1
@@ -1,18 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._isSend = exports.Send = exports._isSendInterface = exports.CHECKPOINT_NAMESPACE_SEPARATOR = exports.RESERVED = exports.TASK_NAMESPACE = exports.TASKS = exports.TAG_HIDDEN = exports.RECURSION_LIMIT_DEFAULT = exports.RUNTIME_PLACEHOLDER = exports.CONFIG_KEY_STORE = exports.INTERRUPT = exports.CONFIG_KEY_RESUMING = exports.CONFIG_KEY_CHECKPOINTER = exports.CONFIG_KEY_READ = exports.CONFIG_KEY_SEND = exports.ERROR = exports.INPUT = void 0;
3
+ exports._isSend = exports.Send = exports._isSendInterface = exports.CHECKPOINT_NAMESPACE_END = exports.CHECKPOINT_NAMESPACE_SEPARATOR = exports.RESERVED = exports.TASK_NAMESPACE = exports.PULL = exports.PUSH = exports.TASKS = exports.TAG_HIDDEN = exports.RECURSION_LIMIT_DEFAULT = exports.RUNTIME_PLACEHOLDER = exports.INTERRUPT = exports.CONFIG_KEY_CHECKPOINT_MAP = exports.CONFIG_KEY_STREAM = exports.CONFIG_KEY_TASK_ID = exports.CONFIG_KEY_RESUMING = exports.CONFIG_KEY_STORE = exports.CONFIG_KEY_CHECKPOINTER = exports.CONFIG_KEY_READ = exports.CONFIG_KEY_SEND = exports.ERROR = exports.INPUT = void 0;
4
4
  exports.INPUT = "__input__";
5
5
  exports.ERROR = "__error__";
6
6
  exports.CONFIG_KEY_SEND = "__pregel_send";
7
7
  exports.CONFIG_KEY_READ = "__pregel_read";
8
8
  exports.CONFIG_KEY_CHECKPOINTER = "__pregel_checkpointer";
9
+ exports.CONFIG_KEY_STORE = "__pregel_store";
9
10
  exports.CONFIG_KEY_RESUMING = "__pregel_resuming";
11
+ exports.CONFIG_KEY_TASK_ID = "__pregel_task_id";
12
+ exports.CONFIG_KEY_STREAM = "__pregel_stream";
13
+ // this one is part of public API
14
+ exports.CONFIG_KEY_CHECKPOINT_MAP = "checkpoint_map";
10
15
  exports.INTERRUPT = "__interrupt__";
11
- exports.CONFIG_KEY_STORE = "__pregel_store";
12
16
  exports.RUNTIME_PLACEHOLDER = "__pregel_runtime_placeholder__";
13
17
  exports.RECURSION_LIMIT_DEFAULT = 25;
14
18
  exports.TAG_HIDDEN = "langsmith:hidden";
15
19
  exports.TASKS = "__pregel_tasks";
20
+ exports.PUSH = "__pregel_push";
21
+ exports.PULL = "__pregel_pull";
16
22
  exports.TASK_NAMESPACE = "6ba7b831-9dad-11d1-80b4-00c04fd430c8";
17
23
  exports.RESERVED = [
18
24
  exports.INTERRUPT,
@@ -22,9 +28,13 @@ exports.RESERVED = [
22
28
  exports.CONFIG_KEY_READ,
23
29
  exports.CONFIG_KEY_CHECKPOINTER,
24
30
  exports.CONFIG_KEY_RESUMING,
31
+ exports.CONFIG_KEY_TASK_ID,
32
+ exports.CONFIG_KEY_STREAM,
33
+ exports.CONFIG_KEY_CHECKPOINT_MAP,
25
34
  exports.INPUT,
26
35
  ];
27
36
  exports.CHECKPOINT_NAMESPACE_SEPARATOR = "|";
37
+ exports.CHECKPOINT_NAMESPACE_END = ":";
28
38
  function _isSendInterface(x) {
29
39
  const operation = x;
30
40
  return typeof operation.node === "string" && operation.args !== undefined;
@@ -3,16 +3,22 @@ export declare const ERROR = "__error__";
3
3
  export declare const CONFIG_KEY_SEND = "__pregel_send";
4
4
  export declare const CONFIG_KEY_READ = "__pregel_read";
5
5
  export declare const CONFIG_KEY_CHECKPOINTER = "__pregel_checkpointer";
6
+ export declare const CONFIG_KEY_STORE = "__pregel_store";
6
7
  export declare const CONFIG_KEY_RESUMING = "__pregel_resuming";
8
+ export declare const CONFIG_KEY_TASK_ID = "__pregel_task_id";
9
+ export declare const CONFIG_KEY_STREAM = "__pregel_stream";
10
+ export declare const CONFIG_KEY_CHECKPOINT_MAP = "checkpoint_map";
7
11
  export declare const INTERRUPT = "__interrupt__";
8
- export declare const CONFIG_KEY_STORE = "__pregel_store";
9
12
  export declare const RUNTIME_PLACEHOLDER = "__pregel_runtime_placeholder__";
10
13
  export declare const RECURSION_LIMIT_DEFAULT = 25;
11
14
  export declare const TAG_HIDDEN = "langsmith:hidden";
12
15
  export declare const TASKS = "__pregel_tasks";
16
+ export declare const PUSH = "__pregel_push";
17
+ export declare const PULL = "__pregel_pull";
13
18
  export declare const TASK_NAMESPACE = "6ba7b831-9dad-11d1-80b4-00c04fd430c8";
14
19
  export declare const RESERVED: string[];
15
20
  export declare const CHECKPOINT_NAMESPACE_SEPARATOR = "|";
21
+ export declare const CHECKPOINT_NAMESPACE_END = ":";
16
22
  export interface SendInterface {
17
23
  node: string;
18
24
  args: any;
package/dist/constants.js CHANGED
@@ -3,13 +3,19 @@ export const ERROR = "__error__";
3
3
  export const CONFIG_KEY_SEND = "__pregel_send";
4
4
  export const CONFIG_KEY_READ = "__pregel_read";
5
5
  export const CONFIG_KEY_CHECKPOINTER = "__pregel_checkpointer";
6
+ export const CONFIG_KEY_STORE = "__pregel_store";
6
7
  export const CONFIG_KEY_RESUMING = "__pregel_resuming";
8
+ export const CONFIG_KEY_TASK_ID = "__pregel_task_id";
9
+ export const CONFIG_KEY_STREAM = "__pregel_stream";
10
+ // this one is part of public API
11
+ export const CONFIG_KEY_CHECKPOINT_MAP = "checkpoint_map";
7
12
  export const INTERRUPT = "__interrupt__";
8
- export const CONFIG_KEY_STORE = "__pregel_store";
9
13
  export const RUNTIME_PLACEHOLDER = "__pregel_runtime_placeholder__";
10
14
  export const RECURSION_LIMIT_DEFAULT = 25;
11
15
  export const TAG_HIDDEN = "langsmith:hidden";
12
16
  export const TASKS = "__pregel_tasks";
17
+ export const PUSH = "__pregel_push";
18
+ export const PULL = "__pregel_pull";
13
19
  export const TASK_NAMESPACE = "6ba7b831-9dad-11d1-80b4-00c04fd430c8";
14
20
  export const RESERVED = [
15
21
  INTERRUPT,
@@ -19,9 +25,13 @@ export const RESERVED = [
19
25
  CONFIG_KEY_READ,
20
26
  CONFIG_KEY_CHECKPOINTER,
21
27
  CONFIG_KEY_RESUMING,
28
+ CONFIG_KEY_TASK_ID,
29
+ CONFIG_KEY_STREAM,
30
+ CONFIG_KEY_CHECKPOINT_MAP,
22
31
  INPUT,
23
32
  ];
24
33
  export const CHECKPOINT_NAMESPACE_SEPARATOR = "|";
34
+ export const CHECKPOINT_NAMESPACE_END = ":";
25
35
  export function _isSendInterface(x) {
26
36
  const operation = x;
27
37
  return typeof operation.node === "string" && operation.args !== undefined;
package/dist/errors.cjs CHANGED
@@ -55,10 +55,11 @@ class NodeInterrupt extends GraphInterrupt {
55
55
  }
56
56
  exports.NodeInterrupt = NodeInterrupt;
57
57
  function isGraphInterrupt(e) {
58
- return [
59
- GraphInterrupt.unminifiable_name,
60
- NodeInterrupt.unminifiable_name,
61
- ].includes(e.name);
58
+ return (e !== undefined &&
59
+ [
60
+ GraphInterrupt.unminifiable_name,
61
+ NodeInterrupt.unminifiable_name,
62
+ ].includes(e.name));
62
63
  }
63
64
  exports.isGraphInterrupt = isGraphInterrupt;
64
65
  class EmptyInputError extends Error {
package/dist/errors.d.ts CHANGED
@@ -17,7 +17,7 @@ export declare class NodeInterrupt extends GraphInterrupt {
17
17
  constructor(message: string);
18
18
  static get unminifiable_name(): string;
19
19
  }
20
- export declare function isGraphInterrupt(e: GraphInterrupt | Error): e is GraphInterrupt;
20
+ export declare function isGraphInterrupt(e?: GraphInterrupt | Error): e is GraphInterrupt;
21
21
  export declare class EmptyInputError extends Error {
22
22
  constructor(message?: string);
23
23
  static get unminifiable_name(): string;
package/dist/errors.js CHANGED
@@ -48,10 +48,11 @@ export class NodeInterrupt extends GraphInterrupt {
48
48
  }
49
49
  }
50
50
  export function isGraphInterrupt(e) {
51
- return [
52
- GraphInterrupt.unminifiable_name,
53
- NodeInterrupt.unminifiable_name,
54
- ].includes(e.name);
51
+ return (e !== undefined &&
52
+ [
53
+ GraphInterrupt.unminifiable_name,
54
+ NodeInterrupt.unminifiable_name,
55
+ ].includes(e.name));
55
56
  }
56
57
  export class EmptyInputError extends Error {
57
58
  constructor(message) {
@@ -123,8 +123,13 @@ class Graph {
123
123
  return this.edges;
124
124
  }
125
125
  addNode(key, action, options) {
126
- if (key.includes(constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR)) {
127
- throw new Error(`"${constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR}" is a reserved character and is not allowed in node names.`);
126
+ for (const reservedChar of [
127
+ constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR,
128
+ constants_js_1.CHECKPOINT_NAMESPACE_END,
129
+ ]) {
130
+ if (key.includes(reservedChar)) {
131
+ throw new Error(`"${reservedChar}" is a reserved character and is not allowed in node names.`);
132
+ }
128
133
  }
129
134
  this.warnIfCompiled(`Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
130
135
  if (key in this.nodes) {
@@ -6,7 +6,7 @@ import { PregelNode } from "../pregel/read.js";
6
6
  import { Channel, Pregel } from "../pregel/index.js";
7
7
  import { EphemeralValue } from "../channels/ephemeral_value.js";
8
8
  import { ChannelWrite, PASSTHROUGH } from "../pregel/write.js";
9
- import { _isSend, CHECKPOINT_NAMESPACE_SEPARATOR, TAG_HIDDEN, } from "../constants.js";
9
+ import { _isSend, CHECKPOINT_NAMESPACE_END, CHECKPOINT_NAMESPACE_SEPARATOR, TAG_HIDDEN, } from "../constants.js";
10
10
  import { RunnableCallable } from "../utils.js";
11
11
  import { InvalidUpdateError, NodeInterrupt } from "../errors.js";
12
12
  /** Special reserved node name denoting the start of a graph. */
@@ -119,8 +119,13 @@ export class Graph {
119
119
  return this.edges;
120
120
  }
121
121
  addNode(key, action, options) {
122
- if (key.includes(CHECKPOINT_NAMESPACE_SEPARATOR)) {
123
- throw new Error(`"${CHECKPOINT_NAMESPACE_SEPARATOR}" is a reserved character and is not allowed in node names.`);
122
+ for (const reservedChar of [
123
+ CHECKPOINT_NAMESPACE_SEPARATOR,
124
+ CHECKPOINT_NAMESPACE_END,
125
+ ]) {
126
+ if (key.includes(reservedChar)) {
127
+ throw new Error(`"${reservedChar}" is a reserved character and is not allowed in node names.`);
128
+ }
124
129
  }
125
130
  this.warnIfCompiled(`Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
126
131
  if (key in this.nodes) {
@@ -19,11 +19,13 @@ function messagesStateReducer(left, right) {
19
19
  for (const m of leftMessages) {
20
20
  if (m.id === null || m.id === undefined) {
21
21
  m.id = (0, uuid_1.v4)();
22
+ m.lc_kwargs.id = m.id;
22
23
  }
23
24
  }
24
25
  for (const m of rightMessages) {
25
26
  if (m.id === null || m.id === undefined) {
26
27
  m.id = (0, uuid_1.v4)();
28
+ m.lc_kwargs.id = m.id;
27
29
  }
28
30
  }
29
31
  // merge
@@ -16,11 +16,13 @@ export function messagesStateReducer(left, right) {
16
16
  for (const m of leftMessages) {
17
17
  if (m.id === null || m.id === undefined) {
18
18
  m.id = v4();
19
+ m.lc_kwargs.id = m.id;
19
20
  }
20
21
  }
21
22
  for (const m of rightMessages) {
22
23
  if (m.id === null || m.id === undefined) {
23
24
  m.id = v4();
25
+ m.lc_kwargs.id = m.id;
24
26
  }
25
27
  }
26
28
  // merge
@@ -198,8 +198,13 @@ class StateGraph extends graph_js_1.Graph {
198
198
  if (key in this.channels) {
199
199
  throw new Error(`${key} is already being used as a state attribute (a.k.a. a channel), cannot also be used as a node name.`);
200
200
  }
201
- if (key.includes(constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR)) {
202
- throw new Error(`"${constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR}" is a reserved character and is not allowed in node names.`);
201
+ for (const reservedChar of [
202
+ constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR,
203
+ constants_js_1.CHECKPOINT_NAMESPACE_END,
204
+ ]) {
205
+ if (key.includes(reservedChar)) {
206
+ throw new Error(`"${reservedChar}" is a reserved character and is not allowed in node names.`);
207
+ }
203
208
  }
204
209
  this.warnIfCompiled(`Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
205
210
  if (key in this.nodes) {
@@ -385,7 +390,7 @@ class CompiledStateGraph extends graph_js_1.CompiledGraph {
385
390
  }
386
391
  }
387
392
  else if (start === graph_js_1.START) {
388
- const channelName = `start:${end}`;
393
+ const channelName = `${graph_js_1.START}:${end}`;
389
394
  // register channel
390
395
  this.channels[channelName] =
391
396
  new ephemeral_value_js_1.EphemeralValue();
@@ -3,7 +3,7 @@ import { All, BaseCheckpointSaver } from "@langchain/langgraph-checkpoint";
3
3
  import { BaseChannel } from "../channels/base.js";
4
4
  import { END, CompiledGraph, Graph, START, Branch, AddNodeOptions, NodeSpec } from "./graph.js";
5
5
  import { AnnotationRoot, SingleReducer, StateDefinition, StateType, UpdateType } from "./annotation.js";
6
- import type { RetryPolicy } from "../pregel/utils.js";
6
+ import type { RetryPolicy } from "../pregel/utils/index.js";
7
7
  import { BaseStore } from "../store/base.js";
8
8
  import { ManagedValueSpec } from "../managed/base.js";
9
9
  export type ChannelReducers<Channels extends object> = {
@@ -7,7 +7,7 @@ import { ChannelRead, PregelNode } from "../pregel/read.js";
7
7
  import { NamedBarrierValue } from "../channels/named_barrier_value.js";
8
8
  import { EphemeralValue } from "../channels/ephemeral_value.js";
9
9
  import { RunnableCallable } from "../utils.js";
10
- import { _isSend, CHECKPOINT_NAMESPACE_SEPARATOR, TAG_HIDDEN, } from "../constants.js";
10
+ import { _isSend, CHECKPOINT_NAMESPACE_END, CHECKPOINT_NAMESPACE_SEPARATOR, TAG_HIDDEN, } from "../constants.js";
11
11
  import { InvalidUpdateError } from "../errors.js";
12
12
  import { getChannel, } from "./annotation.js";
13
13
  import { isConfiguredManagedValue } from "../managed/base.js";
@@ -195,8 +195,13 @@ export class StateGraph extends Graph {
195
195
  if (key in this.channels) {
196
196
  throw new Error(`${key} is already being used as a state attribute (a.k.a. a channel), cannot also be used as a node name.`);
197
197
  }
198
- if (key.includes(CHECKPOINT_NAMESPACE_SEPARATOR)) {
199
- throw new Error(`"${CHECKPOINT_NAMESPACE_SEPARATOR}" is a reserved character and is not allowed in node names.`);
198
+ for (const reservedChar of [
199
+ CHECKPOINT_NAMESPACE_SEPARATOR,
200
+ CHECKPOINT_NAMESPACE_END,
201
+ ]) {
202
+ if (key.includes(reservedChar)) {
203
+ throw new Error(`"${reservedChar}" is a reserved character and is not allowed in node names.`);
204
+ }
200
205
  }
201
206
  this.warnIfCompiled(`Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
202
207
  if (key in this.nodes) {
@@ -381,7 +386,7 @@ export class CompiledStateGraph extends CompiledGraph {
381
386
  }
382
387
  }
383
388
  else if (start === START) {
384
- const channelName = `start:${end}`;
389
+ const channelName = `${START}:${end}`;
385
390
  // register channel
386
391
  this.channels[channelName] =
387
392
  new EphemeralValue();
@@ -44,7 +44,7 @@ class SharedValue extends base_js_1.WritableManagedValue {
44
44
  this.ns = `scoped:${this.scope}:${params.key}:${scopedValueString}`;
45
45
  }
46
46
  else {
47
- throw new Error(`Scope ${this.scope} for shared state key not in config.configurable`);
47
+ throw new Error(`Required scope "${this.scope}" for shared state key was not passed in "config.configurable".`);
48
48
  }
49
49
  }
50
50
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -41,7 +41,7 @@ export class SharedValue extends WritableManagedValue {
41
41
  this.ns = `scoped:${this.scope}:${params.key}:${scopedValueString}`;
42
42
  }
43
43
  else {
44
- throw new Error(`Scope ${this.scope} for shared state key not in config.configurable`);
44
+ throw new Error(`Required scope "${this.scope}" for shared state key was not passed in "config.configurable".`);
45
45
  }
46
46
  }
47
47
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._prepareNextTasks = exports._applyWrites = exports._localWrite = exports._localRead = exports.shouldInterrupt = exports.increment = void 0;
3
+ exports._prepareSingleTask = exports._prepareNextTasks = exports._applyWrites = exports._localWrite = exports._localRead = exports.shouldInterrupt = exports.increment = void 0;
4
4
  /* eslint-disable no-param-reassign */
5
5
  const runnables_1 = require("@langchain/core/runnables");
6
6
  const langgraph_checkpoint_1 = require("@langchain/langgraph-checkpoint");
@@ -8,7 +8,7 @@ const base_js_1 = require("../channels/base.cjs");
8
8
  const io_js_1 = require("./io.cjs");
9
9
  const constants_js_1 = require("../constants.cjs");
10
10
  const errors_js_1 = require("../errors.cjs");
11
- const utils_js_1 = require("./utils.cjs");
11
+ const index_js_1 = require("./utils/index.cjs");
12
12
  const increment = (current) => {
13
13
  return current !== undefined ? current + 1 : 1;
14
14
  };
@@ -204,48 +204,84 @@ getNextVersion) {
204
204
  }
205
205
  exports._applyWrites = _applyWrites;
206
206
  function _prepareNextTasks(checkpoint, processes, channels, managed, config, forExecution, extra) {
207
- const parentNamespace = config.configurable?.checkpoint_ns ?? "";
208
- const tasks = [];
209
- const taskDescriptions = [];
210
- const { step, isResuming = false, checkpointer, manager } = extra;
211
- for (const packet of checkpoint.pending_sends) {
207
+ const tasks = {};
208
+ // Consume pending packets
209
+ for (let i = 0; i < checkpoint.pending_sends.length; i += 1) {
210
+ const task = _prepareSingleTask([constants_js_1.PUSH, i], checkpoint, processes, channels, managed, config, forExecution, extra);
211
+ if (task !== undefined) {
212
+ tasks[task.id] = task;
213
+ }
214
+ }
215
+ // Check if any processes should be run in next step
216
+ // If so, prepare the values to be passed to them
217
+ for (const name of Object.keys(processes)) {
218
+ const task = _prepareSingleTask([constants_js_1.PULL, name], checkpoint, processes, channels, managed, config, forExecution, extra);
219
+ if (task !== undefined) {
220
+ tasks[task.id] = task;
221
+ }
222
+ }
223
+ return tasks;
224
+ }
225
+ exports._prepareNextTasks = _prepareNextTasks;
226
+ function _prepareSingleTask(taskPath, checkpoint, processes, channels, managed, config, forExecution, extra) {
227
+ const { step, checkpointer, manager } = extra;
228
+ const configurable = config.configurable ?? {};
229
+ const parentNamespace = configurable.checkpoint_ns ?? "";
230
+ if (taskPath[0] === constants_js_1.PUSH) {
231
+ const index = typeof taskPath[1] === "number" ? taskPath[1] : parseInt(taskPath[1], 10);
232
+ if (index >= checkpoint.pending_sends.length) {
233
+ return undefined;
234
+ }
235
+ const packet = checkpoint.pending_sends[index];
212
236
  if (!(0, constants_js_1._isSendInterface)(packet)) {
213
237
  console.warn(`Ignoring invalid packet ${JSON.stringify(packet)} in pending sends.`);
214
- continue;
238
+ return undefined;
215
239
  }
216
240
  if (!(packet.node in processes)) {
217
241
  console.warn(`Ignoring unknown node name ${packet.node} in pending sends.`);
218
- continue;
242
+ return undefined;
219
243
  }
220
- const triggers = [constants_js_1.TASKS];
221
- const metadata = (0, utils_js_1._getIdMetadata)({
222
- langgraph_step: step,
223
- langgraph_node: packet.node,
224
- langgraph_triggers: triggers,
225
- langgraph_task_idx: forExecution ? tasks.length : taskDescriptions.length,
226
- });
244
+ const triggers = [constants_js_1.PUSH];
227
245
  const checkpointNamespace = parentNamespace === ""
228
246
  ? packet.node
229
247
  : `${parentNamespace}${constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR}${packet.node}`;
230
- const taskId = (0, langgraph_checkpoint_1.uuid5)(JSON.stringify([checkpointNamespace, metadata]), checkpoint.id);
248
+ const taskId = (0, langgraph_checkpoint_1.uuid5)(JSON.stringify([
249
+ checkpointNamespace,
250
+ step.toString(),
251
+ packet.node,
252
+ constants_js_1.PUSH,
253
+ index.toString(),
254
+ ]), checkpoint.id);
255
+ const taskCheckpointNamespace = `${checkpointNamespace}${constants_js_1.CHECKPOINT_NAMESPACE_END}${taskId}`;
256
+ let metadata = {
257
+ langgraph_step: step,
258
+ langgraph_node: packet.node,
259
+ langgraph_triggers: triggers,
260
+ langgraph_path: taskPath,
261
+ langgraph_checkpoint_ns: taskCheckpointNamespace,
262
+ };
231
263
  if (forExecution) {
232
264
  const proc = processes[packet.node];
233
265
  const node = proc.getNode();
234
266
  if (node !== undefined) {
235
- const writes = [];
236
267
  managed.replaceRuntimePlaceholders(step, packet.args);
237
- tasks.push({
268
+ if (proc.metadata !== undefined) {
269
+ metadata = { ...metadata, ...proc.metadata };
270
+ }
271
+ const writes = [];
272
+ return {
238
273
  name: packet.node,
239
274
  input: packet.args,
240
275
  proc: node,
241
276
  writes,
242
- triggers,
243
- config: (0, runnables_1.patchConfig)((0, runnables_1.mergeConfigs)(config, processes[packet.node].config, {
277
+ config: (0, runnables_1.patchConfig)((0, runnables_1.mergeConfigs)(config, {
244
278
  metadata,
279
+ tags: proc.tags,
245
280
  }), {
246
281
  runName: packet.node,
247
282
  callbacks: manager?.getChild(`graph:step:${step}`),
248
283
  configurable: {
284
+ [constants_js_1.CONFIG_KEY_TASK_ID]: taskId,
249
285
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
250
286
  [constants_js_1.CONFIG_KEY_SEND]: (writes_) => _localWrite(step, (items) => writes.push(...items), processes, channels, managed, writes_),
251
287
  [constants_js_1.CONFIG_KEY_READ]: (select_, fresh_ = false) => _localRead(step, checkpoint, channels, managed, {
@@ -253,24 +289,36 @@ function _prepareNextTasks(checkpoint, processes, channels, managed, config, for
253
289
  writes: writes,
254
290
  triggers,
255
291
  }, select_, fresh_),
292
+ [constants_js_1.CONFIG_KEY_CHECKPOINTER]: checkpointer ?? configurable[constants_js_1.CONFIG_KEY_CHECKPOINTER],
293
+ [constants_js_1.CONFIG_KEY_CHECKPOINT_MAP]: {
294
+ ...configurable[constants_js_1.CONFIG_KEY_CHECKPOINT_MAP],
295
+ [parentNamespace]: checkpoint.id,
296
+ },
297
+ checkpoint_id: undefined,
298
+ checkpoint_ns: taskCheckpointNamespace,
256
299
  },
257
300
  }),
258
- id: taskId,
301
+ triggers,
259
302
  retry_policy: proc.retryPolicy,
260
- });
303
+ id: taskId,
304
+ path: taskPath,
305
+ };
261
306
  }
262
307
  }
263
308
  else {
264
- taskDescriptions.push({ id: taskId, name: packet.node, interrupts: [] });
309
+ return { id: taskId, name: packet.node, interrupts: [], path: taskPath };
265
310
  }
266
311
  }
267
- // Check if any processes should be run in next step
268
- // If so, prepare the values to be passed to them
269
- const nullVersion = (0, utils_js_1.getNullChannelVersion)(checkpoint.channel_versions);
270
- if (nullVersion === undefined) {
271
- return forExecution ? tasks : taskDescriptions;
272
- }
273
- for (const [name, proc] of Object.entries(processes)) {
312
+ else if (taskPath[0] === constants_js_1.PULL) {
313
+ const name = taskPath[1].toString();
314
+ const proc = processes[name];
315
+ if (proc === undefined) {
316
+ return undefined;
317
+ }
318
+ const nullVersion = (0, index_js_1.getNullChannelVersion)(checkpoint.channel_versions);
319
+ if (nullVersion === undefined) {
320
+ return undefined;
321
+ }
274
322
  const seen = checkpoint.versions_seen[name] ?? {};
275
323
  const triggers = proc.triggers
276
324
  .filter((chan) => {
@@ -288,60 +336,77 @@ function _prepareNextTasks(checkpoint, processes, channels, managed, config, for
288
336
  if (triggers.length > 0) {
289
337
  const val = _procInput(step, proc, managed, channels, forExecution);
290
338
  if (val === undefined) {
291
- continue;
339
+ return undefined;
292
340
  }
293
- const metadata = (0, utils_js_1._getIdMetadata)({
294
- langgraph_step: step,
295
- langgraph_node: name,
296
- langgraph_triggers: triggers,
297
- langgraph_task_idx: forExecution
298
- ? tasks.length
299
- : taskDescriptions.length,
300
- });
301
341
  const checkpointNamespace = parentNamespace === ""
302
342
  ? name
303
343
  : `${parentNamespace}${constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR}${name}`;
304
- const taskId = (0, langgraph_checkpoint_1.uuid5)(JSON.stringify([checkpointNamespace, metadata]), checkpoint.id);
344
+ const taskId = (0, langgraph_checkpoint_1.uuid5)(JSON.stringify([
345
+ checkpointNamespace,
346
+ step.toString(),
347
+ name,
348
+ constants_js_1.PULL,
349
+ triggers,
350
+ ]), checkpoint.id);
351
+ const taskCheckpointNamespace = `${checkpointNamespace}${constants_js_1.CHECKPOINT_NAMESPACE_END}${taskId}`;
352
+ let metadata = {
353
+ langgraph_step: step,
354
+ langgraph_node: name,
355
+ langgraph_triggers: triggers,
356
+ langgraph_path: taskPath,
357
+ langgraph_checkpoint_ns: taskCheckpointNamespace,
358
+ };
305
359
  if (forExecution) {
306
360
  const node = proc.getNode();
307
361
  if (node !== undefined) {
362
+ if (proc.metadata !== undefined) {
363
+ metadata = { ...metadata, ...proc.metadata };
364
+ }
308
365
  const writes = [];
309
- tasks.push({
366
+ const taskCheckpointNamespace = `${checkpointNamespace}${constants_js_1.CHECKPOINT_NAMESPACE_END}${taskId}`;
367
+ return {
310
368
  name,
311
369
  input: val,
312
370
  proc: node,
313
371
  writes,
314
- triggers,
315
- config: (0, runnables_1.patchConfig)((0, runnables_1.mergeConfigs)(config, proc.config, { metadata }), {
372
+ config: (0, runnables_1.patchConfig)((0, runnables_1.mergeConfigs)(config, { metadata, tags: proc.tags }), {
316
373
  runName: name,
317
374
  callbacks: manager?.getChild(`graph:step:${step}`),
318
375
  configurable: {
376
+ [constants_js_1.CONFIG_KEY_TASK_ID]: taskId,
319
377
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
320
- [constants_js_1.CONFIG_KEY_SEND]: (writes_) => _localWrite(step, (items) => writes.push(...items), processes, channels, managed, writes_),
378
+ [constants_js_1.CONFIG_KEY_SEND]: (writes_) => _localWrite(step, (items) => {
379
+ writes.push(...items);
380
+ }, processes, channels, managed, writes_),
321
381
  [constants_js_1.CONFIG_KEY_READ]: (select_, fresh_ = false) => _localRead(step, checkpoint, channels, managed, {
322
382
  name,
323
383
  writes: writes,
324
384
  triggers,
325
385
  }, select_, fresh_),
326
- [constants_js_1.CONFIG_KEY_CHECKPOINTER]: checkpointer,
327
- [constants_js_1.CONFIG_KEY_RESUMING]: isResuming,
328
- checkpoint_id: checkpoint.id,
329
- checkpoint_ns: checkpointNamespace,
386
+ [constants_js_1.CONFIG_KEY_CHECKPOINTER]: checkpointer ?? configurable[constants_js_1.CONFIG_KEY_CHECKPOINTER],
387
+ [constants_js_1.CONFIG_KEY_CHECKPOINT_MAP]: {
388
+ ...configurable[constants_js_1.CONFIG_KEY_CHECKPOINT_MAP],
389
+ [parentNamespace]: checkpoint.id,
390
+ },
391
+ checkpoint_id: undefined,
392
+ checkpoint_ns: taskCheckpointNamespace,
330
393
  },
331
394
  }),
332
- id: taskId,
395
+ triggers,
333
396
  retry_policy: proc.retryPolicy,
334
- });
397
+ id: taskId,
398
+ path: taskPath,
399
+ };
335
400
  }
336
401
  }
337
402
  else {
338
- taskDescriptions.push({ id: taskId, name, interrupts: [] });
403
+ return { id: taskId, name, interrupts: [], path: taskPath };
339
404
  }
340
405
  }
341
406
  }
342
- return forExecution ? tasks : taskDescriptions;
407
+ return undefined;
343
408
  }
344
- exports._prepareNextTasks = _prepareNextTasks;
409
+ exports._prepareSingleTask = _prepareSingleTask;
345
410
  function _procInput(step, proc, managed, channels, forExecution) {
346
411
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
347
412
  let val;
@@ -27,5 +27,8 @@ export type NextTaskExtraFields = {
27
27
  checkpointer?: BaseCheckpointSaver;
28
28
  manager?: CallbackManagerForChainRun;
29
29
  };
30
- export declare function _prepareNextTasks<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel>>(checkpoint: ReadonlyCheckpoint, processes: Nn, channels: Cc, managed: ManagedValueMapping, config: RunnableConfig, forExecution: false, extra: NextTaskExtraFields): PregelTaskDescription[];
31
- export declare function _prepareNextTasks<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel>>(checkpoint: ReadonlyCheckpoint, processes: Nn, channels: Cc, managed: ManagedValueMapping, config: RunnableConfig, forExecution: true, extra: NextTaskExtraFields): PregelExecutableTask<keyof Nn, keyof Cc>[];
30
+ export declare function _prepareNextTasks<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel>>(checkpoint: ReadonlyCheckpoint, processes: Nn, channels: Cc, managed: ManagedValueMapping, config: RunnableConfig, forExecution: false, extra: NextTaskExtraFields): Record<string, PregelTaskDescription>;
31
+ export declare function _prepareNextTasks<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel>>(checkpoint: ReadonlyCheckpoint, processes: Nn, channels: Cc, managed: ManagedValueMapping, config: RunnableConfig, forExecution: true, extra: NextTaskExtraFields): Record<string, PregelExecutableTask<keyof Nn, keyof Cc>>;
32
+ export declare function _prepareSingleTask<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel>>(taskPath: [string, string | number], checkpoint: ReadonlyCheckpoint, processes: Nn, channels: Cc, managed: ManagedValueMapping, config: RunnableConfig, forExecution: false, extra: NextTaskExtraFields): PregelTaskDescription | undefined;
33
+ export declare function _prepareSingleTask<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel>>(taskPath: [string, string | number], checkpoint: ReadonlyCheckpoint, processes: Nn, channels: Cc, managed: ManagedValueMapping, config: RunnableConfig, forExecution: true, extra: NextTaskExtraFields): PregelExecutableTask<keyof Nn, keyof Cc> | undefined;
34
+ export declare function _prepareSingleTask<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel>>(taskPath: [string, string | number], checkpoint: ReadonlyCheckpoint, processes: Nn, channels: Cc, managed: ManagedValueMapping, config: RunnableConfig, forExecution: boolean, extra: NextTaskExtraFields): PregelTaskDescription | PregelExecutableTask<keyof Nn, keyof Cc> | undefined;