@langchain/langgraph 0.2.18-rc.0 → 0.2.19
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/errors.cjs +14 -1
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +12 -0
- package/dist/graph/graph.cjs +150 -0
- package/dist/graph/graph.d.ts +8 -0
- package/dist/graph/graph.js +151 -1
- package/dist/pregel/index.cjs +21 -5
- package/dist/pregel/index.d.ts +7 -25
- package/dist/pregel/index.js +21 -5
- package/dist/pregel/remote.cjs +447 -0
- package/dist/pregel/remote.d.ts +113 -0
- package/dist/pregel/remote.js +443 -0
- package/dist/pregel/types.d.ts +44 -5
- package/dist/pregel/utils/subgraph.cjs +1 -4
- package/dist/pregel/utils/subgraph.js +1 -4
- package/dist/remote.cjs +5 -0
- package/dist/remote.d.ts +1 -0
- package/dist/remote.js +1 -0
- package/package.json +21 -7
- package/remote.cjs +1 -0
- package/remote.d.cts +1 -0
- package/remote.d.ts +1 -0
- package/remote.js +1 -0
package/dist/errors.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSubgraphsSeenSet = exports.MultipleSubgraphsError = exports.InvalidUpdateError = exports.EmptyChannelError = exports.EmptyInputError = exports.isGraphInterrupt = exports.NodeInterrupt = exports.GraphInterrupt = exports.GraphValueError = exports.GraphRecursionError = exports.BaseLangGraphError = void 0;
|
|
3
|
+
exports.getSubgraphsSeenSet = exports.RemoteException = exports.MultipleSubgraphsError = exports.InvalidUpdateError = exports.EmptyChannelError = exports.EmptyInputError = exports.isGraphInterrupt = exports.NodeInterrupt = exports.GraphInterrupt = exports.GraphValueError = exports.GraphRecursionError = exports.BaseLangGraphError = void 0;
|
|
4
4
|
// TODO: Merge with base LangChain error class when we drop support for core@0.2.0
|
|
5
5
|
class BaseLangGraphError extends Error {
|
|
6
6
|
constructor(message, fields) {
|
|
@@ -120,6 +120,19 @@ class MultipleSubgraphsError extends BaseLangGraphError {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
exports.MultipleSubgraphsError = MultipleSubgraphsError;
|
|
123
|
+
/**
|
|
124
|
+
* Exception raised when an error occurs in the remote graph.
|
|
125
|
+
*/
|
|
126
|
+
class RemoteException extends BaseLangGraphError {
|
|
127
|
+
constructor(message, fields) {
|
|
128
|
+
super(message, fields);
|
|
129
|
+
this.name = "RemoteException";
|
|
130
|
+
}
|
|
131
|
+
static get unminifiable_name() {
|
|
132
|
+
return "RemoteException";
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.RemoteException = RemoteException;
|
|
123
136
|
/**
|
|
124
137
|
* Used for subgraph detection.
|
|
125
138
|
*/
|
package/dist/errors.d.ts
CHANGED
|
@@ -41,6 +41,13 @@ export declare class MultipleSubgraphsError extends BaseLangGraphError {
|
|
|
41
41
|
constructor(message?: string, fields?: BaseLangGraphErrorFields);
|
|
42
42
|
static get unminifiable_name(): string;
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Exception raised when an error occurs in the remote graph.
|
|
46
|
+
*/
|
|
47
|
+
export declare class RemoteException extends BaseLangGraphError {
|
|
48
|
+
constructor(message?: string, fields?: BaseLangGraphErrorFields);
|
|
49
|
+
static get unminifiable_name(): string;
|
|
50
|
+
}
|
|
44
51
|
/**
|
|
45
52
|
* Used for subgraph detection.
|
|
46
53
|
*/
|
package/dist/errors.js
CHANGED
|
@@ -107,6 +107,18 @@ export class MultipleSubgraphsError extends BaseLangGraphError {
|
|
|
107
107
|
return "MultipleSubgraphError";
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Exception raised when an error occurs in the remote graph.
|
|
112
|
+
*/
|
|
113
|
+
export class RemoteException extends BaseLangGraphError {
|
|
114
|
+
constructor(message, fields) {
|
|
115
|
+
super(message, fields);
|
|
116
|
+
this.name = "RemoteException";
|
|
117
|
+
}
|
|
118
|
+
static get unminifiable_name() {
|
|
119
|
+
return "RemoteException";
|
|
120
|
+
}
|
|
121
|
+
}
|
|
110
122
|
/**
|
|
111
123
|
* Used for subgraph detection.
|
|
112
124
|
*/
|
package/dist/graph/graph.cjs
CHANGED
|
@@ -357,6 +357,156 @@ class CompiledGraph extends index_js_1.Pregel {
|
|
|
357
357
|
/**
|
|
358
358
|
* Returns a drawable representation of the computation graph.
|
|
359
359
|
*/
|
|
360
|
+
async getGraphAsync(config) {
|
|
361
|
+
const xray = config?.xray;
|
|
362
|
+
const graph = new graph_1.Graph();
|
|
363
|
+
const startNodes = {
|
|
364
|
+
[exports.START]: graph.addNode({
|
|
365
|
+
schema: zod_1.z.any(),
|
|
366
|
+
}, exports.START),
|
|
367
|
+
};
|
|
368
|
+
const endNodes = {};
|
|
369
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
370
|
+
let subgraphs = {};
|
|
371
|
+
if (xray) {
|
|
372
|
+
subgraphs = Object.fromEntries((await (0, utils_js_1.gatherIterator)(this.getSubgraphsAsync())).filter(
|
|
373
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
374
|
+
(x) => isCompiledGraph(x[1])));
|
|
375
|
+
}
|
|
376
|
+
function addEdge(start, end, label, conditional = false) {
|
|
377
|
+
if (end === exports.END && endNodes[exports.END] === undefined) {
|
|
378
|
+
endNodes[exports.END] = graph.addNode({ schema: zod_1.z.any() }, exports.END);
|
|
379
|
+
}
|
|
380
|
+
return graph.addEdge(startNodes[start], endNodes[end], label !== end ? label : undefined, conditional);
|
|
381
|
+
}
|
|
382
|
+
for (const [key, nodeSpec] of Object.entries(this.builder.nodes)) {
|
|
383
|
+
const displayKey = _escapeMermaidKeywords(key);
|
|
384
|
+
const node = nodeSpec.runnable;
|
|
385
|
+
const metadata = nodeSpec.metadata ?? {};
|
|
386
|
+
if (this.interruptBefore?.includes(key) &&
|
|
387
|
+
this.interruptAfter?.includes(key)) {
|
|
388
|
+
metadata.__interrupt = "before,after";
|
|
389
|
+
}
|
|
390
|
+
else if (this.interruptBefore?.includes(key)) {
|
|
391
|
+
metadata.__interrupt = "before";
|
|
392
|
+
}
|
|
393
|
+
else if (this.interruptAfter?.includes(key)) {
|
|
394
|
+
metadata.__interrupt = "after";
|
|
395
|
+
}
|
|
396
|
+
if (xray) {
|
|
397
|
+
const newXrayValue = typeof xray === "number" ? xray - 1 : xray;
|
|
398
|
+
const drawableSubgraph = subgraphs[key] !== undefined
|
|
399
|
+
? await subgraphs[key].getGraphAsync({
|
|
400
|
+
...config,
|
|
401
|
+
xray: newXrayValue,
|
|
402
|
+
})
|
|
403
|
+
: node.getGraph(config);
|
|
404
|
+
drawableSubgraph.trimFirstNode();
|
|
405
|
+
drawableSubgraph.trimLastNode();
|
|
406
|
+
if (Object.keys(drawableSubgraph.nodes).length > 1) {
|
|
407
|
+
const [e, s] = graph.extend(drawableSubgraph, displayKey);
|
|
408
|
+
if (e === undefined) {
|
|
409
|
+
throw new Error(`Could not extend subgraph "${key}" due to missing entrypoint.`);
|
|
410
|
+
}
|
|
411
|
+
// TODO: Remove default name once we stop supporting core 0.2.0
|
|
412
|
+
// eslint-disable-next-line no-inner-declarations
|
|
413
|
+
function _isRunnableInterface(
|
|
414
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
415
|
+
thing) {
|
|
416
|
+
return thing ? thing.lc_runnable : false;
|
|
417
|
+
}
|
|
418
|
+
// eslint-disable-next-line no-inner-declarations
|
|
419
|
+
function _nodeDataStr(id, data) {
|
|
420
|
+
if (id !== undefined && !(0, uuid_1.validate)(id)) {
|
|
421
|
+
return id;
|
|
422
|
+
}
|
|
423
|
+
else if (_isRunnableInterface(data)) {
|
|
424
|
+
try {
|
|
425
|
+
let dataStr = data.getName();
|
|
426
|
+
dataStr = dataStr.startsWith("Runnable")
|
|
427
|
+
? dataStr.slice("Runnable".length)
|
|
428
|
+
: dataStr;
|
|
429
|
+
return dataStr;
|
|
430
|
+
}
|
|
431
|
+
catch (error) {
|
|
432
|
+
return data.getName();
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
return data.name ?? "UnknownSchema";
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
// TODO: Remove casts when we stop supporting core 0.2.0
|
|
440
|
+
if (s !== undefined) {
|
|
441
|
+
startNodes[displayKey] = {
|
|
442
|
+
name: _nodeDataStr(s.id, s.data),
|
|
443
|
+
...s,
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
endNodes[displayKey] = {
|
|
447
|
+
name: _nodeDataStr(e.id, e.data),
|
|
448
|
+
...e,
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
// TODO: Remove when we stop supporting core 0.2.0
|
|
453
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
454
|
+
// @ts-ignore
|
|
455
|
+
const newNode = graph.addNode(node, displayKey, metadata);
|
|
456
|
+
startNodes[displayKey] = newNode;
|
|
457
|
+
endNodes[displayKey] = newNode;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
else {
|
|
461
|
+
// TODO: Remove when we stop supporting core 0.2.0
|
|
462
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
463
|
+
// @ts-ignore
|
|
464
|
+
const newNode = graph.addNode(node, displayKey, metadata);
|
|
465
|
+
startNodes[displayKey] = newNode;
|
|
466
|
+
endNodes[displayKey] = newNode;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
const sortedEdges = [...this.builder.allEdges].sort(([a], [b]) => {
|
|
470
|
+
if (a < b) {
|
|
471
|
+
return -1;
|
|
472
|
+
}
|
|
473
|
+
else if (b > a) {
|
|
474
|
+
return 1;
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
return 0;
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
for (const [start, end] of sortedEdges) {
|
|
481
|
+
addEdge(_escapeMermaidKeywords(start), _escapeMermaidKeywords(end));
|
|
482
|
+
}
|
|
483
|
+
for (const [start, branches] of Object.entries(this.builder.branches)) {
|
|
484
|
+
const defaultEnds = {
|
|
485
|
+
...Object.fromEntries(Object.keys(this.builder.nodes)
|
|
486
|
+
.filter((k) => k !== start)
|
|
487
|
+
.map((k) => [_escapeMermaidKeywords(k), _escapeMermaidKeywords(k)])),
|
|
488
|
+
[exports.END]: exports.END,
|
|
489
|
+
};
|
|
490
|
+
for (const branch of Object.values(branches)) {
|
|
491
|
+
let ends;
|
|
492
|
+
if (branch.ends !== undefined) {
|
|
493
|
+
ends = branch.ends;
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
ends = defaultEnds;
|
|
497
|
+
}
|
|
498
|
+
for (const [label, end] of Object.entries(ends)) {
|
|
499
|
+
addEdge(_escapeMermaidKeywords(start), _escapeMermaidKeywords(end), label, true);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
return graph;
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Returns a drawable representation of the computation graph.
|
|
507
|
+
*
|
|
508
|
+
* @deprecated Use getGraphAsync instead. The async method will be the default in the next minor core release.
|
|
509
|
+
*/
|
|
360
510
|
getGraph(config) {
|
|
361
511
|
const xray = config?.xray;
|
|
362
512
|
const graph = new graph_1.Graph();
|
package/dist/graph/graph.d.ts
CHANGED
|
@@ -76,6 +76,14 @@ export declare class CompiledGraph<N extends string, RunInput = any, RunOutput =
|
|
|
76
76
|
/**
|
|
77
77
|
* Returns a drawable representation of the computation graph.
|
|
78
78
|
*/
|
|
79
|
+
getGraphAsync(config?: RunnableConfig & {
|
|
80
|
+
xray?: boolean | number;
|
|
81
|
+
}): Promise<DrawableGraph>;
|
|
82
|
+
/**
|
|
83
|
+
* Returns a drawable representation of the computation graph.
|
|
84
|
+
*
|
|
85
|
+
* @deprecated Use getGraphAsync instead. The async method will be the default in the next minor core release.
|
|
86
|
+
*/
|
|
79
87
|
getGraph(config?: RunnableConfig & {
|
|
80
88
|
xray?: boolean | number;
|
|
81
89
|
}): DrawableGraph;
|
package/dist/graph/graph.js
CHANGED
|
@@ -8,7 +8,7 @@ import { Channel, Pregel } from "../pregel/index.js";
|
|
|
8
8
|
import { EphemeralValue } from "../channels/ephemeral_value.js";
|
|
9
9
|
import { ChannelWrite, PASSTHROUGH } from "../pregel/write.js";
|
|
10
10
|
import { _isSend, CHECKPOINT_NAMESPACE_END, CHECKPOINT_NAMESPACE_SEPARATOR, TAG_HIDDEN, } from "../constants.js";
|
|
11
|
-
import { gatherIteratorSync, RunnableCallable } from "../utils.js";
|
|
11
|
+
import { gatherIterator, gatherIteratorSync, RunnableCallable, } from "../utils.js";
|
|
12
12
|
import { InvalidUpdateError, NodeInterrupt } from "../errors.js";
|
|
13
13
|
import { isPregelLike } from "../pregel/utils/subgraph.js";
|
|
14
14
|
/** Special reserved node name denoting the start of a graph. */
|
|
@@ -352,6 +352,156 @@ export class CompiledGraph extends Pregel {
|
|
|
352
352
|
/**
|
|
353
353
|
* Returns a drawable representation of the computation graph.
|
|
354
354
|
*/
|
|
355
|
+
async getGraphAsync(config) {
|
|
356
|
+
const xray = config?.xray;
|
|
357
|
+
const graph = new DrawableGraph();
|
|
358
|
+
const startNodes = {
|
|
359
|
+
[START]: graph.addNode({
|
|
360
|
+
schema: z.any(),
|
|
361
|
+
}, START),
|
|
362
|
+
};
|
|
363
|
+
const endNodes = {};
|
|
364
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
365
|
+
let subgraphs = {};
|
|
366
|
+
if (xray) {
|
|
367
|
+
subgraphs = Object.fromEntries((await gatherIterator(this.getSubgraphsAsync())).filter(
|
|
368
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
369
|
+
(x) => isCompiledGraph(x[1])));
|
|
370
|
+
}
|
|
371
|
+
function addEdge(start, end, label, conditional = false) {
|
|
372
|
+
if (end === END && endNodes[END] === undefined) {
|
|
373
|
+
endNodes[END] = graph.addNode({ schema: z.any() }, END);
|
|
374
|
+
}
|
|
375
|
+
return graph.addEdge(startNodes[start], endNodes[end], label !== end ? label : undefined, conditional);
|
|
376
|
+
}
|
|
377
|
+
for (const [key, nodeSpec] of Object.entries(this.builder.nodes)) {
|
|
378
|
+
const displayKey = _escapeMermaidKeywords(key);
|
|
379
|
+
const node = nodeSpec.runnable;
|
|
380
|
+
const metadata = nodeSpec.metadata ?? {};
|
|
381
|
+
if (this.interruptBefore?.includes(key) &&
|
|
382
|
+
this.interruptAfter?.includes(key)) {
|
|
383
|
+
metadata.__interrupt = "before,after";
|
|
384
|
+
}
|
|
385
|
+
else if (this.interruptBefore?.includes(key)) {
|
|
386
|
+
metadata.__interrupt = "before";
|
|
387
|
+
}
|
|
388
|
+
else if (this.interruptAfter?.includes(key)) {
|
|
389
|
+
metadata.__interrupt = "after";
|
|
390
|
+
}
|
|
391
|
+
if (xray) {
|
|
392
|
+
const newXrayValue = typeof xray === "number" ? xray - 1 : xray;
|
|
393
|
+
const drawableSubgraph = subgraphs[key] !== undefined
|
|
394
|
+
? await subgraphs[key].getGraphAsync({
|
|
395
|
+
...config,
|
|
396
|
+
xray: newXrayValue,
|
|
397
|
+
})
|
|
398
|
+
: node.getGraph(config);
|
|
399
|
+
drawableSubgraph.trimFirstNode();
|
|
400
|
+
drawableSubgraph.trimLastNode();
|
|
401
|
+
if (Object.keys(drawableSubgraph.nodes).length > 1) {
|
|
402
|
+
const [e, s] = graph.extend(drawableSubgraph, displayKey);
|
|
403
|
+
if (e === undefined) {
|
|
404
|
+
throw new Error(`Could not extend subgraph "${key}" due to missing entrypoint.`);
|
|
405
|
+
}
|
|
406
|
+
// TODO: Remove default name once we stop supporting core 0.2.0
|
|
407
|
+
// eslint-disable-next-line no-inner-declarations
|
|
408
|
+
function _isRunnableInterface(
|
|
409
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
410
|
+
thing) {
|
|
411
|
+
return thing ? thing.lc_runnable : false;
|
|
412
|
+
}
|
|
413
|
+
// eslint-disable-next-line no-inner-declarations
|
|
414
|
+
function _nodeDataStr(id, data) {
|
|
415
|
+
if (id !== undefined && !isUuid(id)) {
|
|
416
|
+
return id;
|
|
417
|
+
}
|
|
418
|
+
else if (_isRunnableInterface(data)) {
|
|
419
|
+
try {
|
|
420
|
+
let dataStr = data.getName();
|
|
421
|
+
dataStr = dataStr.startsWith("Runnable")
|
|
422
|
+
? dataStr.slice("Runnable".length)
|
|
423
|
+
: dataStr;
|
|
424
|
+
return dataStr;
|
|
425
|
+
}
|
|
426
|
+
catch (error) {
|
|
427
|
+
return data.getName();
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
else {
|
|
431
|
+
return data.name ?? "UnknownSchema";
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
// TODO: Remove casts when we stop supporting core 0.2.0
|
|
435
|
+
if (s !== undefined) {
|
|
436
|
+
startNodes[displayKey] = {
|
|
437
|
+
name: _nodeDataStr(s.id, s.data),
|
|
438
|
+
...s,
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
endNodes[displayKey] = {
|
|
442
|
+
name: _nodeDataStr(e.id, e.data),
|
|
443
|
+
...e,
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
// TODO: Remove when we stop supporting core 0.2.0
|
|
448
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
449
|
+
// @ts-ignore
|
|
450
|
+
const newNode = graph.addNode(node, displayKey, metadata);
|
|
451
|
+
startNodes[displayKey] = newNode;
|
|
452
|
+
endNodes[displayKey] = newNode;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
// TODO: Remove when we stop supporting core 0.2.0
|
|
457
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
458
|
+
// @ts-ignore
|
|
459
|
+
const newNode = graph.addNode(node, displayKey, metadata);
|
|
460
|
+
startNodes[displayKey] = newNode;
|
|
461
|
+
endNodes[displayKey] = newNode;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
const sortedEdges = [...this.builder.allEdges].sort(([a], [b]) => {
|
|
465
|
+
if (a < b) {
|
|
466
|
+
return -1;
|
|
467
|
+
}
|
|
468
|
+
else if (b > a) {
|
|
469
|
+
return 1;
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
return 0;
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
for (const [start, end] of sortedEdges) {
|
|
476
|
+
addEdge(_escapeMermaidKeywords(start), _escapeMermaidKeywords(end));
|
|
477
|
+
}
|
|
478
|
+
for (const [start, branches] of Object.entries(this.builder.branches)) {
|
|
479
|
+
const defaultEnds = {
|
|
480
|
+
...Object.fromEntries(Object.keys(this.builder.nodes)
|
|
481
|
+
.filter((k) => k !== start)
|
|
482
|
+
.map((k) => [_escapeMermaidKeywords(k), _escapeMermaidKeywords(k)])),
|
|
483
|
+
[END]: END,
|
|
484
|
+
};
|
|
485
|
+
for (const branch of Object.values(branches)) {
|
|
486
|
+
let ends;
|
|
487
|
+
if (branch.ends !== undefined) {
|
|
488
|
+
ends = branch.ends;
|
|
489
|
+
}
|
|
490
|
+
else {
|
|
491
|
+
ends = defaultEnds;
|
|
492
|
+
}
|
|
493
|
+
for (const [label, end] of Object.entries(ends)) {
|
|
494
|
+
addEdge(_escapeMermaidKeywords(start), _escapeMermaidKeywords(end), label, true);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
return graph;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Returns a drawable representation of the computation graph.
|
|
502
|
+
*
|
|
503
|
+
* @deprecated Use getGraphAsync instead. The async method will be the default in the next minor core release.
|
|
504
|
+
*/
|
|
355
505
|
getGraph(config) {
|
|
356
506
|
const xray = config?.xray;
|
|
357
507
|
const graph = new DrawableGraph();
|
package/dist/pregel/index.cjs
CHANGED
|
@@ -95,6 +95,12 @@ class Pregel extends runnables_1.Runnable {
|
|
|
95
95
|
writable: true,
|
|
96
96
|
value: ["langgraph", "pregel"]
|
|
97
97
|
});
|
|
98
|
+
Object.defineProperty(this, "lg_is_pregel", {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
configurable: true,
|
|
101
|
+
writable: true,
|
|
102
|
+
value: true
|
|
103
|
+
});
|
|
98
104
|
Object.defineProperty(this, "nodes", {
|
|
99
105
|
enumerable: true,
|
|
100
106
|
configurable: true,
|
|
@@ -211,8 +217,9 @@ class Pregel extends runnables_1.Runnable {
|
|
|
211
217
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
212
218
|
// @ts-ignore Remove ignore when we remove support for 0.2 versions of core
|
|
213
219
|
withConfig(config) {
|
|
220
|
+
const mergedConfig = (0, runnables_1.mergeConfigs)(this.config, config);
|
|
214
221
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
215
|
-
return new this.constructor({ ...this, config });
|
|
222
|
+
return new this.constructor({ ...this, config: mergedConfig });
|
|
216
223
|
}
|
|
217
224
|
validate() {
|
|
218
225
|
(0, validate_js_1.validateGraph)({
|
|
@@ -245,6 +252,10 @@ class Pregel extends runnables_1.Runnable {
|
|
|
245
252
|
return Object.keys(this.channels);
|
|
246
253
|
}
|
|
247
254
|
}
|
|
255
|
+
async getGraphAsync(config) {
|
|
256
|
+
return this.getGraph(config);
|
|
257
|
+
}
|
|
258
|
+
/** @deprecated Use getSubgraphsAsync instead. The async method will become the default in the next minor release. */
|
|
248
259
|
*getSubgraphs(namespace, recurse
|
|
249
260
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
250
261
|
) {
|
|
@@ -282,6 +293,11 @@ class Pregel extends runnables_1.Runnable {
|
|
|
282
293
|
}
|
|
283
294
|
}
|
|
284
295
|
}
|
|
296
|
+
async *getSubgraphsAsync(namespace, recurse
|
|
297
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
298
|
+
) {
|
|
299
|
+
yield* this.getSubgraphs(namespace, recurse);
|
|
300
|
+
}
|
|
285
301
|
async _prepareStateSnapshot({ config, saved, subgraphCheckpointer, }) {
|
|
286
302
|
if (saved === undefined) {
|
|
287
303
|
return {
|
|
@@ -295,7 +311,7 @@ class Pregel extends runnables_1.Runnable {
|
|
|
295
311
|
const { managed } = await this.prepareSpecs(config, { skipManaged: true });
|
|
296
312
|
const channels = (0, base_js_1.emptyChannels)(this.channels, saved.checkpoint);
|
|
297
313
|
const nextTasks = Object.values((0, algo_js_1._prepareNextTasks)(saved.checkpoint, this.nodes, channels, managed, saved.config, false, { step: (saved.metadata?.step ?? -1) + 1 }));
|
|
298
|
-
const subgraphs = await (0, utils_js_1.gatherIterator)(this.
|
|
314
|
+
const subgraphs = await (0, utils_js_1.gatherIterator)(this.getSubgraphsAsync());
|
|
299
315
|
const parentNamespace = saved.config.configurable?.checkpoint_ns ?? "";
|
|
300
316
|
const taskStates = {};
|
|
301
317
|
for (const task of nextTasks) {
|
|
@@ -359,7 +375,7 @@ class Pregel extends runnables_1.Runnable {
|
|
|
359
375
|
.split(constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR)
|
|
360
376
|
.map((part) => part.split(constants_js_1.CHECKPOINT_NAMESPACE_END)[0])
|
|
361
377
|
.join(constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR);
|
|
362
|
-
for (const [name, subgraph] of this.
|
|
378
|
+
for await (const [name, subgraph] of this.getSubgraphsAsync(recastCheckpointNamespace, true)) {
|
|
363
379
|
if (name === recastCheckpointNamespace) {
|
|
364
380
|
return await subgraph.getState((0, utils_js_1.patchConfigurable)(config, {
|
|
365
381
|
[constants_js_1.CONFIG_KEY_CHECKPOINTER]: checkpointer,
|
|
@@ -393,7 +409,7 @@ class Pregel extends runnables_1.Runnable {
|
|
|
393
409
|
.map((part) => part.split(constants_js_1.CHECKPOINT_NAMESPACE_END)[0])
|
|
394
410
|
.join(constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR);
|
|
395
411
|
// find the subgraph with the matching name
|
|
396
|
-
for (const [name, pregel] of this.
|
|
412
|
+
for await (const [name, pregel] of this.getSubgraphsAsync(recastCheckpointNamespace, true)) {
|
|
397
413
|
if (name === recastCheckpointNamespace) {
|
|
398
414
|
yield* pregel.getStateHistory((0, utils_js_1.patchConfigurable)(config, {
|
|
399
415
|
[constants_js_1.CONFIG_KEY_CHECKPOINTER]: checkpointer,
|
|
@@ -436,7 +452,7 @@ class Pregel extends runnables_1.Runnable {
|
|
|
436
452
|
.join(constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR);
|
|
437
453
|
// find the subgraph with the matching name
|
|
438
454
|
// eslint-disable-next-line no-unreachable-loop
|
|
439
|
-
for (const [, pregel] of this.
|
|
455
|
+
for await (const [, pregel] of this.getSubgraphsAsync(recastCheckpointNamespace, true)) {
|
|
440
456
|
return await pregel.updateState((0, utils_js_1.patchConfigurable)(inputConfig, {
|
|
441
457
|
[constants_js_1.CONFIG_KEY_CHECKPOINTER]: checkpointer,
|
|
442
458
|
}), values, asNode);
|
package/dist/pregel/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { All, BaseCheckpointSaver, BaseStore, CheckpointListOptions, CheckpointT
|
|
|
4
4
|
import { BaseChannel } from "../channels/base.js";
|
|
5
5
|
import { PregelNode } from "./read.js";
|
|
6
6
|
import { ChannelWrite } from "./write.js";
|
|
7
|
-
import { PregelInterface, PregelParams, StateSnapshot, StreamMode } from "./types.js";
|
|
7
|
+
import { PregelInterface, PregelParams, StateSnapshot, StreamMode, PregelInputType, PregelOutputType, PregelOptions } from "./types.js";
|
|
8
8
|
import { StrRecord } from "./algo.js";
|
|
9
9
|
import { RetryPolicy } from "./utils/index.js";
|
|
10
10
|
import { ManagedValueMapping, type ManagedValueSpec } from "../managed/base.js";
|
|
@@ -20,31 +20,11 @@ export declare class Channel {
|
|
|
20
20
|
}): PregelNode;
|
|
21
21
|
static writeTo(channels: string[], kwargs?: Record<string, WriteValue>): ChannelWrite;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*/
|
|
26
|
-
export interface PregelOptions<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel | ManagedValueSpec>, ConfigurableFieldType extends Record<string, any> = Record<string, any>> extends RunnableConfig<ConfigurableFieldType> {
|
|
27
|
-
/** The stream mode for the graph run. Default is ["values"]. */
|
|
28
|
-
streamMode?: StreamMode | StreamMode[];
|
|
29
|
-
inputKeys?: keyof Cc | Array<keyof Cc>;
|
|
30
|
-
/** The output keys to retrieve from the graph run. */
|
|
31
|
-
outputKeys?: keyof Cc | Array<keyof Cc>;
|
|
32
|
-
/** The nodes to interrupt the graph run before. */
|
|
33
|
-
interruptBefore?: All | Array<keyof Nn>;
|
|
34
|
-
/** The nodes to interrupt the graph run after. */
|
|
35
|
-
interruptAfter?: All | Array<keyof Nn>;
|
|
36
|
-
/** Enable debug mode for the graph run. */
|
|
37
|
-
debug?: boolean;
|
|
38
|
-
/** Whether to stream subgraphs. */
|
|
39
|
-
subgraphs?: boolean;
|
|
40
|
-
/** The shared value store */
|
|
41
|
-
store?: BaseStore;
|
|
42
|
-
}
|
|
43
|
-
export type PregelInputType = any;
|
|
44
|
-
export type PregelOutputType = any;
|
|
45
|
-
export declare class Pregel<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel | ManagedValueSpec>, ConfigurableFieldType extends Record<string, any> = StrRecord<string, any>> extends Runnable<PregelInputType, PregelOutputType, PregelOptions<Nn, Cc, ConfigurableFieldType>> implements PregelInterface<Nn, Cc> {
|
|
23
|
+
export type { PregelInputType, PregelOutputType, PregelOptions };
|
|
24
|
+
export declare class Pregel<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel | ManagedValueSpec>, ConfigurableFieldType extends Record<string, any> = StrRecord<string, any>> extends Runnable<PregelInputType, PregelOutputType, PregelOptions<Nn, Cc, ConfigurableFieldType>> implements PregelInterface<Nn, Cc, ConfigurableFieldType>, PregelParams<Nn, Cc> {
|
|
46
25
|
static lc_name(): string;
|
|
47
26
|
lc_namespace: string[];
|
|
27
|
+
lg_is_pregel: boolean;
|
|
48
28
|
nodes: Nn;
|
|
49
29
|
channels: Cc;
|
|
50
30
|
inputChannels: keyof Cc | Array<keyof Cc>;
|
|
@@ -65,7 +45,10 @@ export declare class Pregel<Nn extends StrRecord<string, PregelNode>, Cc extends
|
|
|
65
45
|
validate(): this;
|
|
66
46
|
get streamChannelsList(): Array<keyof Cc>;
|
|
67
47
|
get streamChannelsAsIs(): keyof Cc | Array<keyof Cc>;
|
|
48
|
+
getGraphAsync(config: RunnableConfig): Promise<import("@langchain/core/runnables/graph").Graph>;
|
|
49
|
+
/** @deprecated Use getSubgraphsAsync instead. The async method will become the default in the next minor release. */
|
|
68
50
|
getSubgraphs(namespace?: string, recurse?: boolean): Generator<[string, Pregel<any, any>]>;
|
|
51
|
+
getSubgraphsAsync(namespace?: string, recurse?: boolean): AsyncGenerator<[string, Pregel<any, any>]>;
|
|
69
52
|
protected _prepareStateSnapshot({ config, saved, subgraphCheckpointer, }: {
|
|
70
53
|
config: RunnableConfig;
|
|
71
54
|
saved?: CheckpointTuple;
|
|
@@ -143,4 +126,3 @@ export declare class Pregel<Nn extends StrRecord<string, PregelNode>, Cc extends
|
|
|
143
126
|
*/
|
|
144
127
|
invoke(input: PregelInputType, options?: Partial<PregelOptions<Nn, Cc, ConfigurableFieldType>>): Promise<PregelOutputType>;
|
|
145
128
|
}
|
|
146
|
-
export {};
|
package/dist/pregel/index.js
CHANGED
|
@@ -88,6 +88,12 @@ export class Pregel extends Runnable {
|
|
|
88
88
|
writable: true,
|
|
89
89
|
value: ["langgraph", "pregel"]
|
|
90
90
|
});
|
|
91
|
+
Object.defineProperty(this, "lg_is_pregel", {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
configurable: true,
|
|
94
|
+
writable: true,
|
|
95
|
+
value: true
|
|
96
|
+
});
|
|
91
97
|
Object.defineProperty(this, "nodes", {
|
|
92
98
|
enumerable: true,
|
|
93
99
|
configurable: true,
|
|
@@ -204,8 +210,9 @@ export class Pregel extends Runnable {
|
|
|
204
210
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
205
211
|
// @ts-ignore Remove ignore when we remove support for 0.2 versions of core
|
|
206
212
|
withConfig(config) {
|
|
213
|
+
const mergedConfig = mergeConfigs(this.config, config);
|
|
207
214
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
208
|
-
return new this.constructor({ ...this, config });
|
|
215
|
+
return new this.constructor({ ...this, config: mergedConfig });
|
|
209
216
|
}
|
|
210
217
|
validate() {
|
|
211
218
|
validateGraph({
|
|
@@ -238,6 +245,10 @@ export class Pregel extends Runnable {
|
|
|
238
245
|
return Object.keys(this.channels);
|
|
239
246
|
}
|
|
240
247
|
}
|
|
248
|
+
async getGraphAsync(config) {
|
|
249
|
+
return this.getGraph(config);
|
|
250
|
+
}
|
|
251
|
+
/** @deprecated Use getSubgraphsAsync instead. The async method will become the default in the next minor release. */
|
|
241
252
|
*getSubgraphs(namespace, recurse
|
|
242
253
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
243
254
|
) {
|
|
@@ -275,6 +286,11 @@ export class Pregel extends Runnable {
|
|
|
275
286
|
}
|
|
276
287
|
}
|
|
277
288
|
}
|
|
289
|
+
async *getSubgraphsAsync(namespace, recurse
|
|
290
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
291
|
+
) {
|
|
292
|
+
yield* this.getSubgraphs(namespace, recurse);
|
|
293
|
+
}
|
|
278
294
|
async _prepareStateSnapshot({ config, saved, subgraphCheckpointer, }) {
|
|
279
295
|
if (saved === undefined) {
|
|
280
296
|
return {
|
|
@@ -288,7 +304,7 @@ export class Pregel extends Runnable {
|
|
|
288
304
|
const { managed } = await this.prepareSpecs(config, { skipManaged: true });
|
|
289
305
|
const channels = emptyChannels(this.channels, saved.checkpoint);
|
|
290
306
|
const nextTasks = Object.values(_prepareNextTasks(saved.checkpoint, this.nodes, channels, managed, saved.config, false, { step: (saved.metadata?.step ?? -1) + 1 }));
|
|
291
|
-
const subgraphs = await gatherIterator(this.
|
|
307
|
+
const subgraphs = await gatherIterator(this.getSubgraphsAsync());
|
|
292
308
|
const parentNamespace = saved.config.configurable?.checkpoint_ns ?? "";
|
|
293
309
|
const taskStates = {};
|
|
294
310
|
for (const task of nextTasks) {
|
|
@@ -352,7 +368,7 @@ export class Pregel extends Runnable {
|
|
|
352
368
|
.split(CHECKPOINT_NAMESPACE_SEPARATOR)
|
|
353
369
|
.map((part) => part.split(CHECKPOINT_NAMESPACE_END)[0])
|
|
354
370
|
.join(CHECKPOINT_NAMESPACE_SEPARATOR);
|
|
355
|
-
for (const [name, subgraph] of this.
|
|
371
|
+
for await (const [name, subgraph] of this.getSubgraphsAsync(recastCheckpointNamespace, true)) {
|
|
356
372
|
if (name === recastCheckpointNamespace) {
|
|
357
373
|
return await subgraph.getState(patchConfigurable(config, {
|
|
358
374
|
[CONFIG_KEY_CHECKPOINTER]: checkpointer,
|
|
@@ -386,7 +402,7 @@ export class Pregel extends Runnable {
|
|
|
386
402
|
.map((part) => part.split(CHECKPOINT_NAMESPACE_END)[0])
|
|
387
403
|
.join(CHECKPOINT_NAMESPACE_SEPARATOR);
|
|
388
404
|
// find the subgraph with the matching name
|
|
389
|
-
for (const [name, pregel] of this.
|
|
405
|
+
for await (const [name, pregel] of this.getSubgraphsAsync(recastCheckpointNamespace, true)) {
|
|
390
406
|
if (name === recastCheckpointNamespace) {
|
|
391
407
|
yield* pregel.getStateHistory(patchConfigurable(config, {
|
|
392
408
|
[CONFIG_KEY_CHECKPOINTER]: checkpointer,
|
|
@@ -429,7 +445,7 @@ export class Pregel extends Runnable {
|
|
|
429
445
|
.join(CHECKPOINT_NAMESPACE_SEPARATOR);
|
|
430
446
|
// find the subgraph with the matching name
|
|
431
447
|
// eslint-disable-next-line no-unreachable-loop
|
|
432
|
-
for (const [, pregel] of this.
|
|
448
|
+
for await (const [, pregel] of this.getSubgraphsAsync(recastCheckpointNamespace, true)) {
|
|
433
449
|
return await pregel.updateState(patchConfigurable(inputConfig, {
|
|
434
450
|
[CONFIG_KEY_CHECKPOINTER]: checkpointer,
|
|
435
451
|
}), values, asNode);
|