@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.
- package/dist/constants.cjs +12 -2
- package/dist/constants.d.ts +7 -1
- package/dist/constants.js +11 -1
- package/dist/errors.cjs +5 -4
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +5 -4
- package/dist/graph/graph.cjs +7 -2
- package/dist/graph/graph.js +8 -3
- package/dist/graph/message.cjs +2 -0
- package/dist/graph/message.js +2 -0
- package/dist/graph/state.cjs +8 -3
- package/dist/graph/state.d.ts +1 -1
- package/dist/graph/state.js +9 -4
- package/dist/managed/shared_value.cjs +1 -1
- package/dist/managed/shared_value.js +1 -1
- package/dist/pregel/algo.cjs +119 -54
- package/dist/pregel/algo.d.ts +5 -2
- package/dist/pregel/algo.js +117 -53
- package/dist/pregel/debug.cjs +15 -18
- package/dist/pregel/debug.d.ts +3 -2
- package/dist/pregel/debug.js +16 -19
- package/dist/pregel/index.cjs +295 -110
- package/dist/pregel/index.d.ts +16 -4
- package/dist/pregel/index.js +292 -110
- package/dist/pregel/io.cjs +15 -8
- package/dist/pregel/io.d.ts +2 -2
- package/dist/pregel/io.js +15 -8
- package/dist/pregel/loop.cjs +256 -111
- package/dist/pregel/loop.d.ts +21 -5
- package/dist/pregel/loop.js +256 -109
- package/dist/pregel/read.cjs +9 -2
- package/dist/pregel/read.d.ts +2 -1
- package/dist/pregel/read.js +9 -2
- package/dist/pregel/retry.d.ts +1 -1
- package/dist/pregel/types.d.ts +5 -1
- package/dist/pregel/utils/config.cjs +72 -0
- package/dist/pregel/utils/config.d.ts +2 -0
- package/dist/pregel/utils/config.js +68 -0
- package/dist/pregel/{utils.cjs → utils/index.cjs} +33 -10
- package/dist/pregel/{utils.d.ts → utils/index.d.ts} +4 -7
- package/dist/pregel/{utils.js → utils/index.js} +30 -8
- package/dist/utils.cjs +5 -3
- package/dist/utils.js +5 -3
- package/dist/web.d.ts +2 -1
- package/package.json +1 -1
package/dist/pregel/algo.js
CHANGED
|
@@ -3,9 +3,9 @@ import { mergeConfigs, patchConfig, } from "@langchain/core/runnables";
|
|
|
3
3
|
import { copyCheckpoint, uuid5, maxChannelVersion, } from "@langchain/langgraph-checkpoint";
|
|
4
4
|
import { createCheckpoint, emptyChannels, isBaseChannel, } from "../channels/base.js";
|
|
5
5
|
import { readChannel, readChannels } from "./io.js";
|
|
6
|
-
import { _isSend, _isSendInterface, CHECKPOINT_NAMESPACE_SEPARATOR, CONFIG_KEY_CHECKPOINTER, CONFIG_KEY_READ,
|
|
6
|
+
import { _isSend, _isSendInterface, CONFIG_KEY_CHECKPOINT_MAP, CHECKPOINT_NAMESPACE_SEPARATOR, CONFIG_KEY_CHECKPOINTER, CONFIG_KEY_READ, CONFIG_KEY_TASK_ID, CONFIG_KEY_SEND, INTERRUPT, RESERVED, TAG_HIDDEN, TASKS, CHECKPOINT_NAMESPACE_END, PUSH, PULL, } from "../constants.js";
|
|
7
7
|
import { EmptyChannelError, InvalidUpdateError } from "../errors.js";
|
|
8
|
-
import {
|
|
8
|
+
import { getNullChannelVersion } from "./utils/index.js";
|
|
9
9
|
export const increment = (current) => {
|
|
10
10
|
return current !== undefined ? current + 1 : 1;
|
|
11
11
|
};
|
|
@@ -196,48 +196,83 @@ getNextVersion) {
|
|
|
196
196
|
return pendingWritesByManaged;
|
|
197
197
|
}
|
|
198
198
|
export function _prepareNextTasks(checkpoint, processes, channels, managed, config, forExecution, extra) {
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
199
|
+
const tasks = {};
|
|
200
|
+
// Consume pending packets
|
|
201
|
+
for (let i = 0; i < checkpoint.pending_sends.length; i += 1) {
|
|
202
|
+
const task = _prepareSingleTask([PUSH, i], checkpoint, processes, channels, managed, config, forExecution, extra);
|
|
203
|
+
if (task !== undefined) {
|
|
204
|
+
tasks[task.id] = task;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// Check if any processes should be run in next step
|
|
208
|
+
// If so, prepare the values to be passed to them
|
|
209
|
+
for (const name of Object.keys(processes)) {
|
|
210
|
+
const task = _prepareSingleTask([PULL, name], checkpoint, processes, channels, managed, config, forExecution, extra);
|
|
211
|
+
if (task !== undefined) {
|
|
212
|
+
tasks[task.id] = task;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return tasks;
|
|
216
|
+
}
|
|
217
|
+
export function _prepareSingleTask(taskPath, checkpoint, processes, channels, managed, config, forExecution, extra) {
|
|
218
|
+
const { step, checkpointer, manager } = extra;
|
|
219
|
+
const configurable = config.configurable ?? {};
|
|
220
|
+
const parentNamespace = configurable.checkpoint_ns ?? "";
|
|
221
|
+
if (taskPath[0] === PUSH) {
|
|
222
|
+
const index = typeof taskPath[1] === "number" ? taskPath[1] : parseInt(taskPath[1], 10);
|
|
223
|
+
if (index >= checkpoint.pending_sends.length) {
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
const packet = checkpoint.pending_sends[index];
|
|
204
227
|
if (!_isSendInterface(packet)) {
|
|
205
228
|
console.warn(`Ignoring invalid packet ${JSON.stringify(packet)} in pending sends.`);
|
|
206
|
-
|
|
229
|
+
return undefined;
|
|
207
230
|
}
|
|
208
231
|
if (!(packet.node in processes)) {
|
|
209
232
|
console.warn(`Ignoring unknown node name ${packet.node} in pending sends.`);
|
|
210
|
-
|
|
233
|
+
return undefined;
|
|
211
234
|
}
|
|
212
|
-
const triggers = [
|
|
213
|
-
const metadata = _getIdMetadata({
|
|
214
|
-
langgraph_step: step,
|
|
215
|
-
langgraph_node: packet.node,
|
|
216
|
-
langgraph_triggers: triggers,
|
|
217
|
-
langgraph_task_idx: forExecution ? tasks.length : taskDescriptions.length,
|
|
218
|
-
});
|
|
235
|
+
const triggers = [PUSH];
|
|
219
236
|
const checkpointNamespace = parentNamespace === ""
|
|
220
237
|
? packet.node
|
|
221
238
|
: `${parentNamespace}${CHECKPOINT_NAMESPACE_SEPARATOR}${packet.node}`;
|
|
222
|
-
const taskId = uuid5(JSON.stringify([
|
|
239
|
+
const taskId = uuid5(JSON.stringify([
|
|
240
|
+
checkpointNamespace,
|
|
241
|
+
step.toString(),
|
|
242
|
+
packet.node,
|
|
243
|
+
PUSH,
|
|
244
|
+
index.toString(),
|
|
245
|
+
]), checkpoint.id);
|
|
246
|
+
const taskCheckpointNamespace = `${checkpointNamespace}${CHECKPOINT_NAMESPACE_END}${taskId}`;
|
|
247
|
+
let metadata = {
|
|
248
|
+
langgraph_step: step,
|
|
249
|
+
langgraph_node: packet.node,
|
|
250
|
+
langgraph_triggers: triggers,
|
|
251
|
+
langgraph_path: taskPath,
|
|
252
|
+
langgraph_checkpoint_ns: taskCheckpointNamespace,
|
|
253
|
+
};
|
|
223
254
|
if (forExecution) {
|
|
224
255
|
const proc = processes[packet.node];
|
|
225
256
|
const node = proc.getNode();
|
|
226
257
|
if (node !== undefined) {
|
|
227
|
-
const writes = [];
|
|
228
258
|
managed.replaceRuntimePlaceholders(step, packet.args);
|
|
229
|
-
|
|
259
|
+
if (proc.metadata !== undefined) {
|
|
260
|
+
metadata = { ...metadata, ...proc.metadata };
|
|
261
|
+
}
|
|
262
|
+
const writes = [];
|
|
263
|
+
return {
|
|
230
264
|
name: packet.node,
|
|
231
265
|
input: packet.args,
|
|
232
266
|
proc: node,
|
|
233
267
|
writes,
|
|
234
|
-
|
|
235
|
-
config: patchConfig(mergeConfigs(config, processes[packet.node].config, {
|
|
268
|
+
config: patchConfig(mergeConfigs(config, {
|
|
236
269
|
metadata,
|
|
270
|
+
tags: proc.tags,
|
|
237
271
|
}), {
|
|
238
272
|
runName: packet.node,
|
|
239
273
|
callbacks: manager?.getChild(`graph:step:${step}`),
|
|
240
274
|
configurable: {
|
|
275
|
+
[CONFIG_KEY_TASK_ID]: taskId,
|
|
241
276
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
242
277
|
[CONFIG_KEY_SEND]: (writes_) => _localWrite(step, (items) => writes.push(...items), processes, channels, managed, writes_),
|
|
243
278
|
[CONFIG_KEY_READ]: (select_, fresh_ = false) => _localRead(step, checkpoint, channels, managed, {
|
|
@@ -245,24 +280,36 @@ export function _prepareNextTasks(checkpoint, processes, channels, managed, conf
|
|
|
245
280
|
writes: writes,
|
|
246
281
|
triggers,
|
|
247
282
|
}, select_, fresh_),
|
|
283
|
+
[CONFIG_KEY_CHECKPOINTER]: checkpointer ?? configurable[CONFIG_KEY_CHECKPOINTER],
|
|
284
|
+
[CONFIG_KEY_CHECKPOINT_MAP]: {
|
|
285
|
+
...configurable[CONFIG_KEY_CHECKPOINT_MAP],
|
|
286
|
+
[parentNamespace]: checkpoint.id,
|
|
287
|
+
},
|
|
288
|
+
checkpoint_id: undefined,
|
|
289
|
+
checkpoint_ns: taskCheckpointNamespace,
|
|
248
290
|
},
|
|
249
291
|
}),
|
|
250
|
-
|
|
292
|
+
triggers,
|
|
251
293
|
retry_policy: proc.retryPolicy,
|
|
252
|
-
|
|
294
|
+
id: taskId,
|
|
295
|
+
path: taskPath,
|
|
296
|
+
};
|
|
253
297
|
}
|
|
254
298
|
}
|
|
255
299
|
else {
|
|
256
|
-
|
|
300
|
+
return { id: taskId, name: packet.node, interrupts: [], path: taskPath };
|
|
257
301
|
}
|
|
258
302
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
303
|
+
else if (taskPath[0] === PULL) {
|
|
304
|
+
const name = taskPath[1].toString();
|
|
305
|
+
const proc = processes[name];
|
|
306
|
+
if (proc === undefined) {
|
|
307
|
+
return undefined;
|
|
308
|
+
}
|
|
309
|
+
const nullVersion = getNullChannelVersion(checkpoint.channel_versions);
|
|
310
|
+
if (nullVersion === undefined) {
|
|
311
|
+
return undefined;
|
|
312
|
+
}
|
|
266
313
|
const seen = checkpoint.versions_seen[name] ?? {};
|
|
267
314
|
const triggers = proc.triggers
|
|
268
315
|
.filter((chan) => {
|
|
@@ -280,58 +327,75 @@ export function _prepareNextTasks(checkpoint, processes, channels, managed, conf
|
|
|
280
327
|
if (triggers.length > 0) {
|
|
281
328
|
const val = _procInput(step, proc, managed, channels, forExecution);
|
|
282
329
|
if (val === undefined) {
|
|
283
|
-
|
|
330
|
+
return undefined;
|
|
284
331
|
}
|
|
285
|
-
const metadata = _getIdMetadata({
|
|
286
|
-
langgraph_step: step,
|
|
287
|
-
langgraph_node: name,
|
|
288
|
-
langgraph_triggers: triggers,
|
|
289
|
-
langgraph_task_idx: forExecution
|
|
290
|
-
? tasks.length
|
|
291
|
-
: taskDescriptions.length,
|
|
292
|
-
});
|
|
293
332
|
const checkpointNamespace = parentNamespace === ""
|
|
294
333
|
? name
|
|
295
334
|
: `${parentNamespace}${CHECKPOINT_NAMESPACE_SEPARATOR}${name}`;
|
|
296
|
-
const taskId = uuid5(JSON.stringify([
|
|
335
|
+
const taskId = uuid5(JSON.stringify([
|
|
336
|
+
checkpointNamespace,
|
|
337
|
+
step.toString(),
|
|
338
|
+
name,
|
|
339
|
+
PULL,
|
|
340
|
+
triggers,
|
|
341
|
+
]), checkpoint.id);
|
|
342
|
+
const taskCheckpointNamespace = `${checkpointNamespace}${CHECKPOINT_NAMESPACE_END}${taskId}`;
|
|
343
|
+
let metadata = {
|
|
344
|
+
langgraph_step: step,
|
|
345
|
+
langgraph_node: name,
|
|
346
|
+
langgraph_triggers: triggers,
|
|
347
|
+
langgraph_path: taskPath,
|
|
348
|
+
langgraph_checkpoint_ns: taskCheckpointNamespace,
|
|
349
|
+
};
|
|
297
350
|
if (forExecution) {
|
|
298
351
|
const node = proc.getNode();
|
|
299
352
|
if (node !== undefined) {
|
|
353
|
+
if (proc.metadata !== undefined) {
|
|
354
|
+
metadata = { ...metadata, ...proc.metadata };
|
|
355
|
+
}
|
|
300
356
|
const writes = [];
|
|
301
|
-
|
|
357
|
+
const taskCheckpointNamespace = `${checkpointNamespace}${CHECKPOINT_NAMESPACE_END}${taskId}`;
|
|
358
|
+
return {
|
|
302
359
|
name,
|
|
303
360
|
input: val,
|
|
304
361
|
proc: node,
|
|
305
362
|
writes,
|
|
306
|
-
|
|
307
|
-
config: patchConfig(mergeConfigs(config, proc.config, { metadata }), {
|
|
363
|
+
config: patchConfig(mergeConfigs(config, { metadata, tags: proc.tags }), {
|
|
308
364
|
runName: name,
|
|
309
365
|
callbacks: manager?.getChild(`graph:step:${step}`),
|
|
310
366
|
configurable: {
|
|
367
|
+
[CONFIG_KEY_TASK_ID]: taskId,
|
|
311
368
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
312
|
-
[CONFIG_KEY_SEND]: (writes_) => _localWrite(step, (items) =>
|
|
369
|
+
[CONFIG_KEY_SEND]: (writes_) => _localWrite(step, (items) => {
|
|
370
|
+
writes.push(...items);
|
|
371
|
+
}, processes, channels, managed, writes_),
|
|
313
372
|
[CONFIG_KEY_READ]: (select_, fresh_ = false) => _localRead(step, checkpoint, channels, managed, {
|
|
314
373
|
name,
|
|
315
374
|
writes: writes,
|
|
316
375
|
triggers,
|
|
317
376
|
}, select_, fresh_),
|
|
318
|
-
[CONFIG_KEY_CHECKPOINTER]: checkpointer,
|
|
319
|
-
[
|
|
320
|
-
|
|
321
|
-
|
|
377
|
+
[CONFIG_KEY_CHECKPOINTER]: checkpointer ?? configurable[CONFIG_KEY_CHECKPOINTER],
|
|
378
|
+
[CONFIG_KEY_CHECKPOINT_MAP]: {
|
|
379
|
+
...configurable[CONFIG_KEY_CHECKPOINT_MAP],
|
|
380
|
+
[parentNamespace]: checkpoint.id,
|
|
381
|
+
},
|
|
382
|
+
checkpoint_id: undefined,
|
|
383
|
+
checkpoint_ns: taskCheckpointNamespace,
|
|
322
384
|
},
|
|
323
385
|
}),
|
|
324
|
-
|
|
386
|
+
triggers,
|
|
325
387
|
retry_policy: proc.retryPolicy,
|
|
326
|
-
|
|
388
|
+
id: taskId,
|
|
389
|
+
path: taskPath,
|
|
390
|
+
};
|
|
327
391
|
}
|
|
328
392
|
}
|
|
329
393
|
else {
|
|
330
|
-
|
|
394
|
+
return { id: taskId, name, interrupts: [], path: taskPath };
|
|
331
395
|
}
|
|
332
396
|
}
|
|
333
397
|
}
|
|
334
|
-
return
|
|
398
|
+
return undefined;
|
|
335
399
|
}
|
|
336
400
|
function _procInput(step, proc, managed, channels, forExecution) {
|
|
337
401
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/dist/pregel/debug.cjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.printStepWrites = exports.printStepTasks = exports.printStepCheckpoint = exports.tasksWithWrites = exports.mapDebugCheckpoint = exports.mapDebugTaskResults = exports.mapDebugTasks = exports.printCheckpoint = void 0;
|
|
4
|
-
const langgraph_checkpoint_1 = require("@langchain/langgraph-checkpoint");
|
|
5
4
|
const constants_js_1 = require("../constants.cjs");
|
|
6
5
|
const errors_js_1 = require("../errors.cjs");
|
|
7
6
|
const io_js_1 = require("./io.cjs");
|
|
8
|
-
const utils_js_1 = require("./utils.cjs");
|
|
9
7
|
const COLORS_MAP = {
|
|
10
8
|
blue: {
|
|
11
9
|
start: "\x1b[34m",
|
|
@@ -56,13 +54,6 @@ function* mapDebugTasks(step, tasks) {
|
|
|
56
54
|
for (const { id, name, input, config, triggers, writes } of tasks) {
|
|
57
55
|
if (config?.tags?.includes(constants_js_1.TAG_HIDDEN))
|
|
58
56
|
continue;
|
|
59
|
-
const metadata = { ...config?.metadata };
|
|
60
|
-
const idMetadata = (0, utils_js_1._getIdMetadata)({
|
|
61
|
-
langgraph_step: metadata.langgraph_step,
|
|
62
|
-
langgraph_node: metadata.langgraph_node,
|
|
63
|
-
langgraph_triggers: metadata.langgraph_triggers,
|
|
64
|
-
langgraph_task_idx: metadata.langgraph_task_idx,
|
|
65
|
-
});
|
|
66
57
|
const interrupts = writes
|
|
67
58
|
.filter(([writeId, n]) => {
|
|
68
59
|
return writeId === id && n === constants_js_1.INTERRUPT;
|
|
@@ -75,7 +66,7 @@ function* mapDebugTasks(step, tasks) {
|
|
|
75
66
|
timestamp: ts,
|
|
76
67
|
step,
|
|
77
68
|
payload: {
|
|
78
|
-
id
|
|
69
|
+
id,
|
|
79
70
|
name,
|
|
80
71
|
input,
|
|
81
72
|
triggers,
|
|
@@ -87,21 +78,24 @@ function* mapDebugTasks(step, tasks) {
|
|
|
87
78
|
exports.mapDebugTasks = mapDebugTasks;
|
|
88
79
|
function* mapDebugTaskResults(step, tasks, streamChannels) {
|
|
89
80
|
const ts = new Date().toISOString();
|
|
90
|
-
for (const [{ name, config }, writes] of tasks) {
|
|
81
|
+
for (const [{ id, name, config }, writes] of tasks) {
|
|
91
82
|
if (config?.tags?.includes(constants_js_1.TAG_HIDDEN))
|
|
92
83
|
continue;
|
|
93
|
-
const metadata = { ...config?.metadata };
|
|
94
|
-
const idMetadata = (0, utils_js_1._getIdMetadata)(metadata);
|
|
95
84
|
yield {
|
|
96
85
|
type: "task_result",
|
|
97
86
|
timestamp: ts,
|
|
98
87
|
step,
|
|
99
88
|
payload: {
|
|
100
|
-
id
|
|
89
|
+
id,
|
|
101
90
|
name,
|
|
102
|
-
result: writes.filter(([channel]) =>
|
|
103
|
-
|
|
104
|
-
|
|
91
|
+
result: writes.filter(([channel]) => {
|
|
92
|
+
return Array.isArray(streamChannels)
|
|
93
|
+
? streamChannels.includes(channel)
|
|
94
|
+
: channel === streamChannels;
|
|
95
|
+
}),
|
|
96
|
+
interrupts: writes.filter(([channel]) => {
|
|
97
|
+
return channel === constants_js_1.INTERRUPT;
|
|
98
|
+
}),
|
|
105
99
|
},
|
|
106
100
|
};
|
|
107
101
|
}
|
|
@@ -148,7 +142,7 @@ function* mapDebugCheckpoint(step, config, channels, streamChannels, metadata, t
|
|
|
148
142
|
};
|
|
149
143
|
}
|
|
150
144
|
exports.mapDebugCheckpoint = mapDebugCheckpoint;
|
|
151
|
-
function tasksWithWrites(tasks, pendingWrites) {
|
|
145
|
+
function tasksWithWrites(tasks, pendingWrites, states) {
|
|
152
146
|
return tasks.map((task) => {
|
|
153
147
|
const error = pendingWrites.find(([id, n]) => id === task.id && n === constants_js_1.ERROR)?.[2];
|
|
154
148
|
const interrupts = pendingWrites
|
|
@@ -162,6 +156,7 @@ function tasksWithWrites(tasks, pendingWrites) {
|
|
|
162
156
|
return {
|
|
163
157
|
id: task.id,
|
|
164
158
|
name: task.name,
|
|
159
|
+
path: task.path,
|
|
165
160
|
error,
|
|
166
161
|
interrupts,
|
|
167
162
|
};
|
|
@@ -169,7 +164,9 @@ function tasksWithWrites(tasks, pendingWrites) {
|
|
|
169
164
|
return {
|
|
170
165
|
id: task.id,
|
|
171
166
|
name: task.name,
|
|
167
|
+
path: task.path,
|
|
172
168
|
interrupts,
|
|
169
|
+
state: states?.[task.id],
|
|
173
170
|
};
|
|
174
171
|
});
|
|
175
172
|
}
|
package/dist/pregel/debug.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RunnableConfig } from "@langchain/core/runnables";
|
|
2
2
|
import { CheckpointMetadata, CheckpointPendingWrite, PendingWrite } from "@langchain/langgraph-checkpoint";
|
|
3
3
|
import { BaseChannel } from "../channels/base.js";
|
|
4
|
-
import { PregelExecutableTask, PregelTaskDescription } from "./types.js";
|
|
4
|
+
import { PregelExecutableTask, PregelTaskDescription, StateSnapshot } from "./types.js";
|
|
5
5
|
export declare function printCheckpoint<Value>(step: number, channels: Record<string, BaseChannel<Value>>): void;
|
|
6
6
|
export declare function mapDebugTasks<N extends PropertyKey, C extends PropertyKey>(step: number, tasks: readonly PregelExecutableTask<N, C>[]): Generator<{
|
|
7
7
|
type: string;
|
|
@@ -23,6 +23,7 @@ export declare function mapDebugTaskResults<N extends PropertyKey, C extends Pro
|
|
|
23
23
|
id: string;
|
|
24
24
|
name: N;
|
|
25
25
|
result: PendingWrite<C>[];
|
|
26
|
+
interrupts: PendingWrite<C>[];
|
|
26
27
|
};
|
|
27
28
|
}, void, unknown>;
|
|
28
29
|
export declare function mapDebugCheckpoint<N extends PropertyKey, C extends PropertyKey>(step: number, config: RunnableConfig, channels: Record<string, BaseChannel>, streamChannels: string | string[], metadata: CheckpointMetadata, tasks: readonly PregelExecutableTask<N, C>[], pendingWrites: CheckpointPendingWrite[]): Generator<{
|
|
@@ -37,7 +38,7 @@ export declare function mapDebugCheckpoint<N extends PropertyKey, C extends Prop
|
|
|
37
38
|
tasks: PregelTaskDescription[];
|
|
38
39
|
};
|
|
39
40
|
}, void, unknown>;
|
|
40
|
-
export declare function tasksWithWrites<N extends PropertyKey, C extends PropertyKey>(tasks: PregelTaskDescription[] | readonly PregelExecutableTask<N, C>[], pendingWrites: CheckpointPendingWrite[]): PregelTaskDescription[];
|
|
41
|
+
export declare function tasksWithWrites<N extends PropertyKey, C extends PropertyKey>(tasks: PregelTaskDescription[] | readonly PregelExecutableTask<N, C>[], pendingWrites: CheckpointPendingWrite[], states?: Record<string, RunnableConfig | StateSnapshot>): PregelTaskDescription[];
|
|
41
42
|
export declare function printStepCheckpoint(step: number, channels: Record<string, BaseChannel<unknown>>, whitelist: string[]): void;
|
|
42
43
|
export declare function printStepTasks<N extends PropertyKey, C extends PropertyKey>(step: number, nextTasks: readonly PregelExecutableTask<N, C>[]): void;
|
|
43
44
|
export declare function printStepWrites(step: number, writes: PendingWrite[], whitelist: string[]): void;
|
package/dist/pregel/debug.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ERROR, INTERRUPT, TAG_HIDDEN, TASK_NAMESPACE, } from "../constants.js";
|
|
1
|
+
import { ERROR, INTERRUPT, TAG_HIDDEN } from "../constants.js";
|
|
3
2
|
import { EmptyChannelError } from "../errors.js";
|
|
4
3
|
import { readChannels } from "./io.js";
|
|
5
|
-
import { _getIdMetadata } from "./utils.js";
|
|
6
4
|
const COLORS_MAP = {
|
|
7
5
|
blue: {
|
|
8
6
|
start: "\x1b[34m",
|
|
@@ -52,13 +50,6 @@ export function* mapDebugTasks(step, tasks) {
|
|
|
52
50
|
for (const { id, name, input, config, triggers, writes } of tasks) {
|
|
53
51
|
if (config?.tags?.includes(TAG_HIDDEN))
|
|
54
52
|
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
53
|
const interrupts = writes
|
|
63
54
|
.filter(([writeId, n]) => {
|
|
64
55
|
return writeId === id && n === INTERRUPT;
|
|
@@ -71,7 +62,7 @@ export function* mapDebugTasks(step, tasks) {
|
|
|
71
62
|
timestamp: ts,
|
|
72
63
|
step,
|
|
73
64
|
payload: {
|
|
74
|
-
id
|
|
65
|
+
id,
|
|
75
66
|
name,
|
|
76
67
|
input,
|
|
77
68
|
triggers,
|
|
@@ -82,21 +73,24 @@ export function* mapDebugTasks(step, tasks) {
|
|
|
82
73
|
}
|
|
83
74
|
export function* mapDebugTaskResults(step, tasks, streamChannels) {
|
|
84
75
|
const ts = new Date().toISOString();
|
|
85
|
-
for (const [{ name, config }, writes] of tasks) {
|
|
76
|
+
for (const [{ id, name, config }, writes] of tasks) {
|
|
86
77
|
if (config?.tags?.includes(TAG_HIDDEN))
|
|
87
78
|
continue;
|
|
88
|
-
const metadata = { ...config?.metadata };
|
|
89
|
-
const idMetadata = _getIdMetadata(metadata);
|
|
90
79
|
yield {
|
|
91
80
|
type: "task_result",
|
|
92
81
|
timestamp: ts,
|
|
93
82
|
step,
|
|
94
83
|
payload: {
|
|
95
|
-
id
|
|
84
|
+
id,
|
|
96
85
|
name,
|
|
97
|
-
result: writes.filter(([channel]) =>
|
|
98
|
-
|
|
99
|
-
|
|
86
|
+
result: writes.filter(([channel]) => {
|
|
87
|
+
return Array.isArray(streamChannels)
|
|
88
|
+
? streamChannels.includes(channel)
|
|
89
|
+
: channel === streamChannels;
|
|
90
|
+
}),
|
|
91
|
+
interrupts: writes.filter(([channel]) => {
|
|
92
|
+
return channel === INTERRUPT;
|
|
93
|
+
}),
|
|
100
94
|
},
|
|
101
95
|
};
|
|
102
96
|
}
|
|
@@ -141,7 +135,7 @@ export function* mapDebugCheckpoint(step, config, channels, streamChannels, meta
|
|
|
141
135
|
},
|
|
142
136
|
};
|
|
143
137
|
}
|
|
144
|
-
export function tasksWithWrites(tasks, pendingWrites) {
|
|
138
|
+
export function tasksWithWrites(tasks, pendingWrites, states) {
|
|
145
139
|
return tasks.map((task) => {
|
|
146
140
|
const error = pendingWrites.find(([id, n]) => id === task.id && n === ERROR)?.[2];
|
|
147
141
|
const interrupts = pendingWrites
|
|
@@ -155,6 +149,7 @@ export function tasksWithWrites(tasks, pendingWrites) {
|
|
|
155
149
|
return {
|
|
156
150
|
id: task.id,
|
|
157
151
|
name: task.name,
|
|
152
|
+
path: task.path,
|
|
158
153
|
error,
|
|
159
154
|
interrupts,
|
|
160
155
|
};
|
|
@@ -162,7 +157,9 @@ export function tasksWithWrites(tasks, pendingWrites) {
|
|
|
162
157
|
return {
|
|
163
158
|
id: task.id,
|
|
164
159
|
name: task.name,
|
|
160
|
+
path: task.path,
|
|
165
161
|
interrupts,
|
|
162
|
+
state: states?.[task.id],
|
|
166
163
|
};
|
|
167
164
|
});
|
|
168
165
|
}
|