@langchain/langgraph 0.0.34 → 0.1.0-rc.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 (86) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +11 -15
  3. package/dist/channels/any_value.cjs +3 -1
  4. package/dist/channels/any_value.d.ts +1 -1
  5. package/dist/channels/any_value.js +3 -1
  6. package/dist/channels/base.cjs +28 -15
  7. package/dist/channels/base.d.ts +14 -4
  8. package/dist/channels/base.js +26 -13
  9. package/dist/channels/binop.cjs +2 -1
  10. package/dist/channels/binop.d.ts +1 -1
  11. package/dist/channels/binop.js +2 -1
  12. package/dist/channels/dynamic_barrier_value.cjs +30 -18
  13. package/dist/channels/dynamic_barrier_value.d.ts +2 -1
  14. package/dist/channels/dynamic_barrier_value.js +30 -18
  15. package/dist/channels/ephemeral_value.cjs +3 -1
  16. package/dist/channels/ephemeral_value.d.ts +1 -1
  17. package/dist/channels/ephemeral_value.js +3 -1
  18. package/dist/channels/last_value.cjs +3 -2
  19. package/dist/channels/last_value.d.ts +1 -1
  20. package/dist/channels/last_value.js +3 -2
  21. package/dist/channels/named_barrier_value.cjs +14 -6
  22. package/dist/channels/named_barrier_value.d.ts +2 -1
  23. package/dist/channels/named_barrier_value.js +15 -7
  24. package/dist/channels/topic.cjs +10 -11
  25. package/dist/channels/topic.d.ts +1 -1
  26. package/dist/channels/topic.js +10 -11
  27. package/dist/checkpoint/sqlite.cjs +14 -170
  28. package/dist/checkpoint/sqlite.d.ts +1 -14
  29. package/dist/checkpoint/sqlite.js +1 -166
  30. package/dist/constants.cjs +17 -1
  31. package/dist/constants.d.ts +7 -0
  32. package/dist/constants.js +16 -0
  33. package/dist/errors.cjs +21 -1
  34. package/dist/errors.d.ts +8 -0
  35. package/dist/errors.js +18 -0
  36. package/dist/graph/graph.cjs +6 -3
  37. package/dist/graph/graph.d.ts +7 -3
  38. package/dist/graph/graph.js +7 -4
  39. package/dist/graph/index.d.ts +1 -1
  40. package/dist/graph/state.cjs +9 -8
  41. package/dist/graph/state.d.ts +1 -1
  42. package/dist/graph/state.js +9 -8
  43. package/dist/prebuilt/react_agent_executor.d.ts +1 -1
  44. package/dist/pregel/algo.cjs +391 -0
  45. package/dist/pregel/algo.d.ts +35 -0
  46. package/dist/pregel/algo.js +381 -0
  47. package/dist/pregel/debug.cjs +155 -9
  48. package/dist/pregel/debug.d.ts +40 -2
  49. package/dist/pregel/debug.js +147 -7
  50. package/dist/pregel/index.cjs +286 -512
  51. package/dist/pregel/index.d.ts +66 -65
  52. package/dist/pregel/index.js +285 -506
  53. package/dist/pregel/io.cjs +2 -2
  54. package/dist/pregel/io.d.ts +5 -4
  55. package/dist/pregel/io.js +2 -2
  56. package/dist/pregel/loop.cjs +432 -0
  57. package/dist/pregel/loop.d.ts +83 -0
  58. package/dist/pregel/loop.js +425 -0
  59. package/dist/pregel/types.d.ts +56 -4
  60. package/dist/pregel/utils.cjs +48 -0
  61. package/dist/pregel/utils.d.ts +10 -0
  62. package/dist/pregel/utils.js +41 -0
  63. package/dist/pregel/write.cjs +3 -1
  64. package/dist/pregel/write.js +3 -1
  65. package/dist/utils.cjs +21 -1
  66. package/dist/utils.d.ts +4 -0
  67. package/dist/utils.js +18 -0
  68. package/dist/web.cjs +6 -7
  69. package/dist/web.d.ts +2 -4
  70. package/dist/web.js +1 -2
  71. package/package.json +6 -12
  72. package/dist/checkpoint/base.cjs +0 -66
  73. package/dist/checkpoint/base.d.ts +0 -73
  74. package/dist/checkpoint/base.js +0 -57
  75. package/dist/checkpoint/id.cjs +0 -8
  76. package/dist/checkpoint/id.d.ts +0 -1
  77. package/dist/checkpoint/id.js +0 -4
  78. package/dist/checkpoint/index.cjs +0 -9
  79. package/dist/checkpoint/index.d.ts +0 -2
  80. package/dist/checkpoint/index.js +0 -2
  81. package/dist/checkpoint/memory.cjs +0 -82
  82. package/dist/checkpoint/memory.d.ts +0 -10
  83. package/dist/checkpoint/memory.js +0 -78
  84. package/dist/serde/base.cjs +0 -8
  85. package/dist/serde/base.d.ts +0 -12
  86. package/dist/serde/base.js +0 -5
@@ -1,22 +1,32 @@
1
+ import { uuid5, } from "@langchain/langgraph-checkpoint";
2
+ import { ERROR, TAG_HIDDEN, TASK_NAMESPACE } from "../constants.js";
1
3
  import { EmptyChannelError } from "../errors.js";
4
+ import { readChannels } from "./io.js";
5
+ import { _getIdMetadata } from "./utils.js";
2
6
  const COLORS_MAP = {
3
7
  blue: {
4
8
  start: "\x1b[34m",
5
9
  end: "\x1b[0m",
6
10
  },
11
+ green: {
12
+ start: "\x1b[32m",
13
+ end: "\x1b[0m",
14
+ },
15
+ yellow: {
16
+ start: "\x1b[33;1m",
17
+ end: "\x1b[0m",
18
+ },
7
19
  };
8
20
  /**
9
21
  * Wrap some text in a color for printing to the console.
10
22
  */
11
23
  const wrap = (color, text) => `${color.start}${text}${color.end}`;
12
- export function printStepStart(step, nextTasks) {
13
- const nTasks = nextTasks.length;
14
- console.log(`${wrap(COLORS_MAP.blue, "[langgraph/step]")}`, `Starting step ${step} with ${nTasks} task${nTasks === 1 ? "" : "s"}. Next tasks:\n`, `\n${nextTasks
15
- .map((task) => `${String(task.name)}(${JSON.stringify(task.input, null, 2)})`)
16
- .join("\n")}`);
17
- }
18
24
  export function printCheckpoint(step, channels) {
19
- console.log(`${wrap(COLORS_MAP.blue, "[langgraph/checkpoint]")}`, `Finishing step ${step}. Channel values:\n`, `\n${JSON.stringify(Object.fromEntries(_readChannels(channels)), null, 2)}`);
25
+ console.log([
26
+ `${wrap(COLORS_MAP.blue, "[langgraph/checkpoint]")}`,
27
+ `Finishing step ${step}. Channel values:\n`,
28
+ `\n${JSON.stringify(Object.fromEntries(_readChannels(channels)), null, 2)}`,
29
+ ].join(""));
20
30
  }
21
31
  function* _readChannels(channels
22
32
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -37,3 +47,133 @@ function* _readChannels(channels
37
47
  }
38
48
  }
39
49
  }
50
+ export function* mapDebugTasks(step, tasks) {
51
+ const ts = new Date().toISOString();
52
+ for (const { name, input, config, triggers } of tasks) {
53
+ if (config?.tags?.includes(TAG_HIDDEN))
54
+ continue;
55
+ const metadata = { ...config?.metadata };
56
+ const idMetadata = _getIdMetadata({
57
+ langgraph_step: metadata.langgraph_step,
58
+ langgraph_node: metadata.langgraph_node,
59
+ langgraph_triggers: metadata.langgraph_triggers,
60
+ langgraph_task_idx: metadata.langgraph_task_idx,
61
+ });
62
+ yield {
63
+ type: "task",
64
+ timestamp: ts,
65
+ step,
66
+ payload: {
67
+ id: uuid5(JSON.stringify([name, step, idMetadata]), TASK_NAMESPACE),
68
+ name,
69
+ input,
70
+ triggers,
71
+ },
72
+ };
73
+ }
74
+ }
75
+ export function* mapDebugTaskResults(step, tasks, streamChannelsList) {
76
+ const ts = new Date().toISOString();
77
+ for (const { name, writes, config } of tasks) {
78
+ if (config?.tags?.includes(TAG_HIDDEN))
79
+ continue;
80
+ const metadata = { ...config?.metadata };
81
+ const idMetadata = _getIdMetadata(metadata);
82
+ yield {
83
+ type: "task_result",
84
+ timestamp: ts,
85
+ step,
86
+ payload: {
87
+ id: uuid5(JSON.stringify([name, step, idMetadata]), TASK_NAMESPACE),
88
+ name,
89
+ result: writes.filter(([channel]) => streamChannelsList.includes(channel)),
90
+ },
91
+ };
92
+ }
93
+ }
94
+ export function* mapDebugCheckpoint(step, config, channels, streamChannels, metadata, tasks, pendingWrites) {
95
+ function formatConfig(config) {
96
+ // make sure the config is consistent with Python
97
+ const pyConfig = {};
98
+ if (config.callbacks != null)
99
+ pyConfig.callbacks = config.callbacks;
100
+ if (config.configurable != null)
101
+ pyConfig.configurable = config.configurable;
102
+ if (config.maxConcurrency != null)
103
+ pyConfig.max_concurrency = config.maxConcurrency;
104
+ if (config.metadata != null)
105
+ pyConfig.metadata = config.metadata;
106
+ if (config.recursionLimit != null)
107
+ pyConfig.recursion_limit = config.recursionLimit;
108
+ if (config.runId != null)
109
+ pyConfig.run_id = config.runId;
110
+ if (config.runName != null)
111
+ pyConfig.run_name = config.runName;
112
+ if (config.tags != null)
113
+ pyConfig.tags = config.tags;
114
+ return pyConfig;
115
+ }
116
+ function getCurrentUTC() {
117
+ const now = new Date();
118
+ return new Date(now.getTime() - now.getTimezoneOffset() * 60 * 1000);
119
+ }
120
+ const ts = getCurrentUTC().toISOString();
121
+ yield {
122
+ type: "checkpoint",
123
+ timestamp: ts,
124
+ step,
125
+ payload: {
126
+ config: formatConfig(config),
127
+ values: readChannels(channels, streamChannels),
128
+ metadata,
129
+ next: tasks.map((task) => task.name),
130
+ tasks: tasksWithWrites(tasks, pendingWrites),
131
+ },
132
+ };
133
+ }
134
+ export function tasksWithWrites(tasks, pendingWrites) {
135
+ return tasks.map((task) => {
136
+ const error = pendingWrites.find(([id, n]) => id === task.id && n === ERROR)?.[2];
137
+ if (error)
138
+ return { id: task.id, name: task.name, error };
139
+ return { id: task.id, name: task.name };
140
+ });
141
+ }
142
+ export function printStepCheckpoint(step, channels, whitelist) {
143
+ console.log([
144
+ `${wrap(COLORS_MAP.blue, `[${step}:checkpoint]`)}`,
145
+ `\x1b[1m State at the end of step ${step}:\x1b[0m\n`,
146
+ JSON.stringify(readChannels(channels, whitelist), null, 2),
147
+ ].join(""));
148
+ }
149
+ export function printStepTasks(step, nextTasks) {
150
+ const nTasks = nextTasks.length;
151
+ console.log([
152
+ `${wrap(COLORS_MAP.blue, `[${step}:tasks]`)}`,
153
+ `\x1b[1m Starting step ${step} with ${nTasks} task${nTasks === 1 ? "" : "s"}:\x1b[0m\n`,
154
+ nextTasks
155
+ .map((task) => `- ${wrap(COLORS_MAP.green, String(task.name))} -> ${JSON.stringify(task.input, null, 2)}`)
156
+ .join("\n"),
157
+ ].join(""));
158
+ }
159
+ export function printStepWrites(step, writes, whitelist) {
160
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
161
+ const byChannel = {};
162
+ for (const [channel, value] of writes) {
163
+ if (whitelist.includes(channel)) {
164
+ if (!byChannel[channel]) {
165
+ byChannel[channel] = [];
166
+ }
167
+ byChannel[channel].push(value);
168
+ }
169
+ }
170
+ console.log([
171
+ `${wrap(COLORS_MAP.blue, `[${step}:writes]`)}`,
172
+ `\x1b[1m Finished step ${step} with writes to ${Object.keys(byChannel).length} channel${Object.keys(byChannel).length !== 1 ? "s" : ""}:\x1b[0m\n`,
173
+ Object.entries(byChannel)
174
+ .map(([name, vals]) => `- ${wrap(COLORS_MAP.yellow, name)} -> ${vals
175
+ .map((v) => JSON.stringify(v))
176
+ .join(", ")}`)
177
+ .join("\n"),
178
+ ].join(""));
179
+ }