@langchain/langgraph 0.2.56 → 0.2.58
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 +99 -12
- package/dist/constants.d.ts +52 -6
- package/dist/constants.js +97 -11
- package/dist/constants.js.map +1 -1
- package/dist/graph/graph.d.ts +1 -1
- package/dist/graph/state.cjs +90 -11
- package/dist/graph/state.d.ts +23 -5
- package/dist/graph/state.js +90 -11
- package/dist/graph/state.js.map +1 -1
- package/dist/graph/zod/index.cjs +7 -0
- package/dist/graph/zod/index.d.ts +2 -0
- package/dist/graph/zod/index.js +3 -0
- package/dist/graph/zod/index.js.map +1 -0
- package/dist/graph/zod/plugin.cjs +41 -0
- package/dist/graph/zod/plugin.d.ts +15 -0
- package/dist/graph/zod/plugin.js +39 -0
- package/dist/graph/zod/plugin.js.map +1 -0
- package/dist/graph/zod/schema.cjs +79 -0
- package/dist/graph/zod/schema.d.ts +9 -0
- package/dist/graph/zod/schema.js +73 -0
- package/dist/graph/zod/schema.js.map +1 -0
- package/dist/graph/zod/state.cjs +73 -0
- package/dist/graph/zod/state.d.ts +30 -0
- package/dist/graph/zod/state.js +64 -0
- package/dist/graph/zod/state.js.map +1 -0
- package/dist/pregel/algo.cjs +26 -3
- package/dist/pregel/algo.js +27 -4
- package/dist/pregel/algo.js.map +1 -1
- package/dist/pregel/debug.cjs +2 -1
- package/dist/pregel/debug.d.ts +1 -1
- package/dist/pregel/debug.js +2 -1
- package/dist/pregel/debug.js.map +1 -1
- package/dist/pregel/index.cjs +133 -27
- package/dist/pregel/index.d.ts +19 -1
- package/dist/pregel/index.js +135 -29
- package/dist/pregel/index.js.map +1 -1
- package/dist/pregel/loop.cjs +48 -24
- package/dist/pregel/loop.d.ts +1 -0
- package/dist/pregel/loop.js +48 -24
- package/dist/pregel/loop.js.map +1 -1
- package/dist/pregel/retry.cjs +3 -1
- package/dist/pregel/retry.js +3 -1
- package/dist/pregel/retry.js.map +1 -1
- package/dist/pregel/runner.cjs +26 -17
- package/dist/pregel/runner.d.ts +4 -0
- package/dist/pregel/runner.js +26 -17
- package/dist/pregel/runner.js.map +1 -1
- package/dist/pregel/utils/index.d.ts +2 -0
- package/dist/pregel/utils/index.js.map +1 -1
- package/package.json +22 -3
- package/zod.cjs +1 -0
- package/zod.d.cts +1 -0
- package/zod.d.ts +1 -0
- package/zod.js +1 -0
package/dist/constants.cjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isCommand = exports.Command = exports._isSend = exports.Send = exports._isSendInterface = exports.CHECKPOINT_NAMESPACE_END = exports.CHECKPOINT_NAMESPACE_SEPARATOR = exports.RESERVED = exports.NULL_TASK_ID = exports.TASK_NAMESPACE = exports.PULL = exports.PUSH = exports.TASKS = exports.SELF = exports.TAG_NOSTREAM = exports.TAG_HIDDEN = exports.RECURSION_LIMIT_DEFAULT = exports.RUNTIME_PLACEHOLDER = exports.PREVIOUS = exports.RETURN = exports.NO_WRITES = exports.RESUME = exports.INTERRUPT = exports.CONFIG_KEY_CHECKPOINT_MAP = exports.CONFIG_KEY_CHECKPOINT_NS = exports.CONFIG_KEY_CHECKPOINT_ID = exports.CONFIG_KEY_PREVIOUS_STATE = exports.CONFIG_KEY_SCRATCHPAD = exports.CONFIG_KEY_RESUME_VALUE = exports.CONFIG_KEY_STREAM = exports.CONFIG_KEY_TASK_ID = exports.CONFIG_KEY_RESUMING = exports.CONFIG_KEY_CHECKPOINTER = exports.CONFIG_KEY_READ = exports.CONFIG_KEY_CALL = exports.CONFIG_KEY_SEND = exports.ERROR = exports.INPUT = exports.END = exports.START = void 0;
|
|
3
|
+
exports.isCommandParams = exports.isCommand = exports.Command = exports._isSend = exports.Send = exports._isSendInterface = exports.CHECKPOINT_NAMESPACE_END = exports.CHECKPOINT_NAMESPACE_SEPARATOR = exports.RESERVED = exports.NULL_TASK_ID = exports.TASK_NAMESPACE = exports.PULL = exports.PUSH = exports.TASKS = exports.SELF = exports.TAG_NOSTREAM = exports.TAG_HIDDEN = exports.RECURSION_LIMIT_DEFAULT = exports.RUNTIME_PLACEHOLDER = exports.PREVIOUS = exports.RETURN = exports.NO_WRITES = exports.RESUME = exports.INTERRUPT = exports.CONFIG_KEY_CHECKPOINT_MAP = exports.CONFIG_KEY_NODE_FINISHED = exports.CONFIG_KEY_CHECKPOINT_NS = exports.CONFIG_KEY_CHECKPOINT_ID = exports.CONFIG_KEY_PREVIOUS_STATE = exports.CONFIG_KEY_SCRATCHPAD = exports.CONFIG_KEY_RESUME_VALUE = exports.CONFIG_KEY_STREAM = exports.CONFIG_KEY_TASK_ID = exports.CONFIG_KEY_RESUMING = exports.CONFIG_KEY_CHECKPOINTER = exports.CONFIG_KEY_READ = exports.CONFIG_KEY_CALL = exports.CONFIG_KEY_SEND = exports.ERROR = exports.COPY = exports.INPUT = exports.END = exports.START = void 0;
|
|
4
4
|
/** Special reserved node name denoting the start of a graph. */
|
|
5
5
|
exports.START = "__start__";
|
|
6
6
|
/** Special reserved node name denoting the end of a graph. */
|
|
7
7
|
exports.END = "__end__";
|
|
8
8
|
exports.INPUT = "__input__";
|
|
9
|
+
exports.COPY = "__copy__";
|
|
9
10
|
exports.ERROR = "__error__";
|
|
10
11
|
exports.CONFIG_KEY_SEND = "__pregel_send";
|
|
11
12
|
/** config key containing function used to call a node (push task) */
|
|
@@ -21,6 +22,7 @@ exports.CONFIG_KEY_SCRATCHPAD = "__pregel_scratchpad";
|
|
|
21
22
|
exports.CONFIG_KEY_PREVIOUS_STATE = "__pregel_previous";
|
|
22
23
|
exports.CONFIG_KEY_CHECKPOINT_ID = "checkpoint_id";
|
|
23
24
|
exports.CONFIG_KEY_CHECKPOINT_NS = "checkpoint_ns";
|
|
25
|
+
exports.CONFIG_KEY_NODE_FINISHED = "__pregel_node_finished";
|
|
24
26
|
// this one is part of public API
|
|
25
27
|
exports.CONFIG_KEY_CHECKPOINT_MAP = "checkpoint_map";
|
|
26
28
|
/** Special channel reserved for graph interrupts */
|
|
@@ -125,24 +127,27 @@ exports._isSendInterface = _isSendInterface;
|
|
|
125
127
|
class Send {
|
|
126
128
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
127
129
|
constructor(node, args) {
|
|
128
|
-
Object.defineProperty(this, "
|
|
130
|
+
Object.defineProperty(this, "lg_name", {
|
|
129
131
|
enumerable: true,
|
|
130
132
|
configurable: true,
|
|
131
133
|
writable: true,
|
|
132
|
-
value:
|
|
134
|
+
value: "Send"
|
|
133
135
|
});
|
|
134
|
-
Object.defineProperty(this, "
|
|
136
|
+
Object.defineProperty(this, "node", {
|
|
135
137
|
enumerable: true,
|
|
136
138
|
configurable: true,
|
|
137
139
|
writable: true,
|
|
138
|
-
value:
|
|
140
|
+
value: void 0
|
|
139
141
|
});
|
|
140
|
-
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
143
|
+
Object.defineProperty(this, "args", {
|
|
141
144
|
enumerable: true,
|
|
142
145
|
configurable: true,
|
|
143
146
|
writable: true,
|
|
144
|
-
value:
|
|
147
|
+
value: void 0
|
|
145
148
|
});
|
|
149
|
+
this.node = node;
|
|
150
|
+
this.args = _convertCommandSendTree(args);
|
|
146
151
|
}
|
|
147
152
|
toJSON() {
|
|
148
153
|
return {
|
|
@@ -153,8 +158,8 @@ class Send {
|
|
|
153
158
|
}
|
|
154
159
|
exports.Send = Send;
|
|
155
160
|
function _isSend(x) {
|
|
156
|
-
|
|
157
|
-
return
|
|
161
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
162
|
+
return x instanceof Send;
|
|
158
163
|
}
|
|
159
164
|
exports._isSend = _isSend;
|
|
160
165
|
/**
|
|
@@ -233,24 +238,44 @@ class Command {
|
|
|
233
238
|
writable: true,
|
|
234
239
|
value: true
|
|
235
240
|
});
|
|
241
|
+
/**
|
|
242
|
+
* Graph to send the command to. Supported values are:
|
|
243
|
+
* - None: the current graph (default)
|
|
244
|
+
* - The specific name of the graph to send the command to
|
|
245
|
+
* - {@link Command.PARENT}: closest parent graph (only supported when returned from a node in a subgraph)
|
|
246
|
+
*/
|
|
236
247
|
Object.defineProperty(this, "graph", {
|
|
237
248
|
enumerable: true,
|
|
238
249
|
configurable: true,
|
|
239
250
|
writable: true,
|
|
240
251
|
value: void 0
|
|
241
252
|
});
|
|
253
|
+
/**
|
|
254
|
+
* Update to apply to the graph's state as a result of executing the node that is returning the command.
|
|
255
|
+
* Written to the state as if the node had simply returned this value instead of the Command object.
|
|
256
|
+
*/
|
|
242
257
|
Object.defineProperty(this, "update", {
|
|
243
258
|
enumerable: true,
|
|
244
259
|
configurable: true,
|
|
245
260
|
writable: true,
|
|
246
261
|
value: void 0
|
|
247
262
|
});
|
|
263
|
+
/**
|
|
264
|
+
* Value to resume execution with. To be used together with {@link interrupt}.
|
|
265
|
+
*/
|
|
248
266
|
Object.defineProperty(this, "resume", {
|
|
249
267
|
enumerable: true,
|
|
250
268
|
configurable: true,
|
|
251
269
|
writable: true,
|
|
252
270
|
value: void 0
|
|
253
271
|
});
|
|
272
|
+
/**
|
|
273
|
+
* Can be one of the following:
|
|
274
|
+
* - name of the node to navigate to next (any node that belongs to the specified `graph`)
|
|
275
|
+
* - sequence of node names to navigate to next
|
|
276
|
+
* - {@link Send} object (to execute a node with the exact input provided in the {@link Send} object)
|
|
277
|
+
* - sequence of {@link Send} objects
|
|
278
|
+
*/
|
|
254
279
|
Object.defineProperty(this, "goto", {
|
|
255
280
|
enumerable: true,
|
|
256
281
|
configurable: true,
|
|
@@ -261,9 +286,16 @@ class Command {
|
|
|
261
286
|
this.graph = args.graph;
|
|
262
287
|
this.update = args.update;
|
|
263
288
|
if (args.goto) {
|
|
264
|
-
this.goto = Array.isArray(args.goto)
|
|
289
|
+
this.goto = Array.isArray(args.goto)
|
|
290
|
+
? _convertCommandSendTree(args.goto)
|
|
291
|
+
: [_convertCommandSendTree(args.goto)];
|
|
265
292
|
}
|
|
266
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* Convert the update field to a list of {@link PendingWrite} tuples
|
|
296
|
+
* @returns List of {@link PendingWrite} tuples of the form `[channelKey, value]`.
|
|
297
|
+
* @internal
|
|
298
|
+
*/
|
|
267
299
|
_updateAsTuples() {
|
|
268
300
|
if (this.update &&
|
|
269
301
|
typeof this.update === "object" &&
|
|
@@ -287,7 +319,7 @@ class Command {
|
|
|
287
319
|
serializedGoto = this.goto.toJSON();
|
|
288
320
|
}
|
|
289
321
|
else {
|
|
290
|
-
serializedGoto = this.goto
|
|
322
|
+
serializedGoto = this.goto?.map((innerGoto) => {
|
|
291
323
|
if (typeof innerGoto === "string") {
|
|
292
324
|
return innerGoto;
|
|
293
325
|
}
|
|
@@ -310,8 +342,63 @@ Object.defineProperty(Command, "PARENT", {
|
|
|
310
342
|
writable: true,
|
|
311
343
|
value: "__parent__"
|
|
312
344
|
});
|
|
345
|
+
/**
|
|
346
|
+
* A type guard to check if the given value is a {@link Command}.
|
|
347
|
+
*
|
|
348
|
+
* Useful for type narrowing when working with the {@link Command} object.
|
|
349
|
+
*
|
|
350
|
+
* @param x - The value to check.
|
|
351
|
+
* @returns `true` if the value is a {@link Command}, `false` otherwise.
|
|
352
|
+
*/
|
|
313
353
|
function isCommand(x) {
|
|
314
|
-
|
|
354
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
355
|
+
return x instanceof Command;
|
|
315
356
|
}
|
|
316
357
|
exports.isCommand = isCommand;
|
|
358
|
+
/**
|
|
359
|
+
* A type guard to check if the given value is a {@link CommandParams}.
|
|
360
|
+
*
|
|
361
|
+
* Useful for type narrowing when working with the {@link CommandParams} object.
|
|
362
|
+
*
|
|
363
|
+
* @param x - The value to check.
|
|
364
|
+
* @returns `true` if the value is a {@link CommandParams}, `false` otherwise.
|
|
365
|
+
*/
|
|
366
|
+
function isCommandParams(x) {
|
|
367
|
+
if (typeof x !== "object") {
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
if (x === null || x === undefined) {
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
if ("update" in x && "resume" in x && "goto" in x) {
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
exports.isCommandParams = isCommandParams;
|
|
379
|
+
function _convertCommandSendTree(x, seen = new Set()) {
|
|
380
|
+
if (x !== undefined && x !== null && typeof x === "object") {
|
|
381
|
+
if (seen.has(x)) {
|
|
382
|
+
throw new Error("Command send tree contains a cycle");
|
|
383
|
+
}
|
|
384
|
+
seen.add(x);
|
|
385
|
+
if (Array.isArray(x)) {
|
|
386
|
+
return x.map((innerX) => _convertCommandSendTree(innerX, new Set(seen)));
|
|
387
|
+
}
|
|
388
|
+
if (isCommand(x) || _isSend(x)) {
|
|
389
|
+
return x;
|
|
390
|
+
}
|
|
391
|
+
if (isCommandParams(x)) {
|
|
392
|
+
return new Command(x);
|
|
393
|
+
}
|
|
394
|
+
if (_isSendInterface(x)) {
|
|
395
|
+
return new Send(x.node, x.args);
|
|
396
|
+
}
|
|
397
|
+
return Object.fromEntries(Object.entries(x).map(([key, value]) => [
|
|
398
|
+
key,
|
|
399
|
+
_convertCommandSendTree(value, seen),
|
|
400
|
+
]));
|
|
401
|
+
}
|
|
402
|
+
return x;
|
|
403
|
+
}
|
|
317
404
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { PendingWrite } from "@langchain/langgraph-checkpoint";
|
|
1
2
|
/** Special reserved node name denoting the start of a graph. */
|
|
2
3
|
export declare const START = "__start__";
|
|
3
4
|
/** Special reserved node name denoting the end of a graph. */
|
|
4
5
|
export declare const END = "__end__";
|
|
5
6
|
export declare const INPUT = "__input__";
|
|
7
|
+
export declare const COPY = "__copy__";
|
|
6
8
|
export declare const ERROR = "__error__";
|
|
7
9
|
export declare const CONFIG_KEY_SEND = "__pregel_send";
|
|
8
10
|
/** config key containing function used to call a node (push task) */
|
|
@@ -18,6 +20,7 @@ export declare const CONFIG_KEY_SCRATCHPAD = "__pregel_scratchpad";
|
|
|
18
20
|
export declare const CONFIG_KEY_PREVIOUS_STATE = "__pregel_previous";
|
|
19
21
|
export declare const CONFIG_KEY_CHECKPOINT_ID = "checkpoint_id";
|
|
20
22
|
export declare const CONFIG_KEY_CHECKPOINT_NS = "checkpoint_ns";
|
|
23
|
+
export declare const CONFIG_KEY_NODE_FINISHED = "__pregel_node_finished";
|
|
21
24
|
export declare const CONFIG_KEY_CHECKPOINT_MAP = "checkpoint_map";
|
|
22
25
|
/** Special channel reserved for graph interrupts */
|
|
23
26
|
export declare const INTERRUPT = "__interrupt__";
|
|
@@ -94,9 +97,9 @@ export declare function _isSendInterface(x: unknown): x is SendInterface;
|
|
|
94
97
|
* ```
|
|
95
98
|
*/
|
|
96
99
|
export declare class Send implements SendInterface {
|
|
100
|
+
lg_name: string;
|
|
97
101
|
node: string;
|
|
98
102
|
args: any;
|
|
99
|
-
lg_name: string;
|
|
100
103
|
constructor(node: string, args: any);
|
|
101
104
|
toJSON(): {
|
|
102
105
|
node: string;
|
|
@@ -118,7 +121,8 @@ export type CommandParams<R> = {
|
|
|
118
121
|
/**
|
|
119
122
|
* Graph to send the command to. Supported values are:
|
|
120
123
|
* - None: the current graph (default)
|
|
121
|
-
* -
|
|
124
|
+
* - The specific name of the graph to send the command to
|
|
125
|
+
* - {@link Command.PARENT}: closest parent graph (only supported when returned from a node in a subgraph)
|
|
122
126
|
*/
|
|
123
127
|
graph?: string;
|
|
124
128
|
/**
|
|
@@ -132,7 +136,7 @@ export type CommandParams<R> = {
|
|
|
132
136
|
* - `Send` object (to execute a node with the input provided)
|
|
133
137
|
* - sequence of `Send` objects
|
|
134
138
|
*/
|
|
135
|
-
goto?: string |
|
|
139
|
+
goto?: string | SendInterface | (string | SendInterface)[];
|
|
136
140
|
};
|
|
137
141
|
/**
|
|
138
142
|
* One or more commands to update the graph's state and send messages to nodes.
|
|
@@ -199,13 +203,38 @@ export type CommandParams<R> = {
|
|
|
199
203
|
export declare class Command<R = unknown> {
|
|
200
204
|
lg_name: string;
|
|
201
205
|
lc_direct_tool_output: boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Graph to send the command to. Supported values are:
|
|
208
|
+
* - None: the current graph (default)
|
|
209
|
+
* - The specific name of the graph to send the command to
|
|
210
|
+
* - {@link Command.PARENT}: closest parent graph (only supported when returned from a node in a subgraph)
|
|
211
|
+
*/
|
|
202
212
|
graph?: string;
|
|
213
|
+
/**
|
|
214
|
+
* Update to apply to the graph's state as a result of executing the node that is returning the command.
|
|
215
|
+
* Written to the state as if the node had simply returned this value instead of the Command object.
|
|
216
|
+
*/
|
|
203
217
|
update?: Record<string, unknown> | [string, unknown][];
|
|
218
|
+
/**
|
|
219
|
+
* Value to resume execution with. To be used together with {@link interrupt}.
|
|
220
|
+
*/
|
|
204
221
|
resume?: R;
|
|
205
|
-
|
|
222
|
+
/**
|
|
223
|
+
* Can be one of the following:
|
|
224
|
+
* - name of the node to navigate to next (any node that belongs to the specified `graph`)
|
|
225
|
+
* - sequence of node names to navigate to next
|
|
226
|
+
* - {@link Send} object (to execute a node with the exact input provided in the {@link Send} object)
|
|
227
|
+
* - sequence of {@link Send} objects
|
|
228
|
+
*/
|
|
229
|
+
goto?: string | Send | (string | Send)[];
|
|
206
230
|
static PARENT: string;
|
|
207
231
|
constructor(args: CommandParams<R>);
|
|
208
|
-
|
|
232
|
+
/**
|
|
233
|
+
* Convert the update field to a list of {@link PendingWrite} tuples
|
|
234
|
+
* @returns List of {@link PendingWrite} tuples of the form `[channelKey, value]`.
|
|
235
|
+
* @internal
|
|
236
|
+
*/
|
|
237
|
+
_updateAsTuples(): PendingWrite[];
|
|
209
238
|
toJSON(): {
|
|
210
239
|
update: Record<string, unknown> | [string, unknown][] | undefined;
|
|
211
240
|
resume: R | undefined;
|
|
@@ -215,7 +244,24 @@ export declare class Command<R = unknown> {
|
|
|
215
244
|
} | (string | {
|
|
216
245
|
node: string;
|
|
217
246
|
args: any;
|
|
218
|
-
})[];
|
|
247
|
+
})[] | undefined;
|
|
219
248
|
};
|
|
220
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* A type guard to check if the given value is a {@link Command}.
|
|
252
|
+
*
|
|
253
|
+
* Useful for type narrowing when working with the {@link Command} object.
|
|
254
|
+
*
|
|
255
|
+
* @param x - The value to check.
|
|
256
|
+
* @returns `true` if the value is a {@link Command}, `false` otherwise.
|
|
257
|
+
*/
|
|
221
258
|
export declare function isCommand(x: unknown): x is Command;
|
|
259
|
+
/**
|
|
260
|
+
* A type guard to check if the given value is a {@link CommandParams}.
|
|
261
|
+
*
|
|
262
|
+
* Useful for type narrowing when working with the {@link CommandParams} object.
|
|
263
|
+
*
|
|
264
|
+
* @param x - The value to check.
|
|
265
|
+
* @returns `true` if the value is a {@link CommandParams}, `false` otherwise.
|
|
266
|
+
*/
|
|
267
|
+
export declare function isCommandParams<R = unknown>(x: unknown): x is CommandParams<R>;
|
package/dist/constants.js
CHANGED
|
@@ -3,6 +3,7 @@ export const START = "__start__";
|
|
|
3
3
|
/** Special reserved node name denoting the end of a graph. */
|
|
4
4
|
export const END = "__end__";
|
|
5
5
|
export const INPUT = "__input__";
|
|
6
|
+
export const COPY = "__copy__";
|
|
6
7
|
export const ERROR = "__error__";
|
|
7
8
|
export const CONFIG_KEY_SEND = "__pregel_send";
|
|
8
9
|
/** config key containing function used to call a node (push task) */
|
|
@@ -18,6 +19,7 @@ export const CONFIG_KEY_SCRATCHPAD = "__pregel_scratchpad";
|
|
|
18
19
|
export const CONFIG_KEY_PREVIOUS_STATE = "__pregel_previous";
|
|
19
20
|
export const CONFIG_KEY_CHECKPOINT_ID = "checkpoint_id";
|
|
20
21
|
export const CONFIG_KEY_CHECKPOINT_NS = "checkpoint_ns";
|
|
22
|
+
export const CONFIG_KEY_NODE_FINISHED = "__pregel_node_finished";
|
|
21
23
|
// this one is part of public API
|
|
22
24
|
export const CONFIG_KEY_CHECKPOINT_MAP = "checkpoint_map";
|
|
23
25
|
/** Special channel reserved for graph interrupts */
|
|
@@ -121,24 +123,27 @@ export function _isSendInterface(x) {
|
|
|
121
123
|
export class Send {
|
|
122
124
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
123
125
|
constructor(node, args) {
|
|
124
|
-
Object.defineProperty(this, "
|
|
126
|
+
Object.defineProperty(this, "lg_name", {
|
|
125
127
|
enumerable: true,
|
|
126
128
|
configurable: true,
|
|
127
129
|
writable: true,
|
|
128
|
-
value:
|
|
130
|
+
value: "Send"
|
|
129
131
|
});
|
|
130
|
-
Object.defineProperty(this, "
|
|
132
|
+
Object.defineProperty(this, "node", {
|
|
131
133
|
enumerable: true,
|
|
132
134
|
configurable: true,
|
|
133
135
|
writable: true,
|
|
134
|
-
value:
|
|
136
|
+
value: void 0
|
|
135
137
|
});
|
|
136
|
-
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
139
|
+
Object.defineProperty(this, "args", {
|
|
137
140
|
enumerable: true,
|
|
138
141
|
configurable: true,
|
|
139
142
|
writable: true,
|
|
140
|
-
value:
|
|
143
|
+
value: void 0
|
|
141
144
|
});
|
|
145
|
+
this.node = node;
|
|
146
|
+
this.args = _convertCommandSendTree(args);
|
|
142
147
|
}
|
|
143
148
|
toJSON() {
|
|
144
149
|
return {
|
|
@@ -148,8 +153,8 @@ export class Send {
|
|
|
148
153
|
}
|
|
149
154
|
}
|
|
150
155
|
export function _isSend(x) {
|
|
151
|
-
|
|
152
|
-
return
|
|
156
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
157
|
+
return x instanceof Send;
|
|
153
158
|
}
|
|
154
159
|
/**
|
|
155
160
|
* One or more commands to update the graph's state and send messages to nodes.
|
|
@@ -227,24 +232,44 @@ export class Command {
|
|
|
227
232
|
writable: true,
|
|
228
233
|
value: true
|
|
229
234
|
});
|
|
235
|
+
/**
|
|
236
|
+
* Graph to send the command to. Supported values are:
|
|
237
|
+
* - None: the current graph (default)
|
|
238
|
+
* - The specific name of the graph to send the command to
|
|
239
|
+
* - {@link Command.PARENT}: closest parent graph (only supported when returned from a node in a subgraph)
|
|
240
|
+
*/
|
|
230
241
|
Object.defineProperty(this, "graph", {
|
|
231
242
|
enumerable: true,
|
|
232
243
|
configurable: true,
|
|
233
244
|
writable: true,
|
|
234
245
|
value: void 0
|
|
235
246
|
});
|
|
247
|
+
/**
|
|
248
|
+
* Update to apply to the graph's state as a result of executing the node that is returning the command.
|
|
249
|
+
* Written to the state as if the node had simply returned this value instead of the Command object.
|
|
250
|
+
*/
|
|
236
251
|
Object.defineProperty(this, "update", {
|
|
237
252
|
enumerable: true,
|
|
238
253
|
configurable: true,
|
|
239
254
|
writable: true,
|
|
240
255
|
value: void 0
|
|
241
256
|
});
|
|
257
|
+
/**
|
|
258
|
+
* Value to resume execution with. To be used together with {@link interrupt}.
|
|
259
|
+
*/
|
|
242
260
|
Object.defineProperty(this, "resume", {
|
|
243
261
|
enumerable: true,
|
|
244
262
|
configurable: true,
|
|
245
263
|
writable: true,
|
|
246
264
|
value: void 0
|
|
247
265
|
});
|
|
266
|
+
/**
|
|
267
|
+
* Can be one of the following:
|
|
268
|
+
* - name of the node to navigate to next (any node that belongs to the specified `graph`)
|
|
269
|
+
* - sequence of node names to navigate to next
|
|
270
|
+
* - {@link Send} object (to execute a node with the exact input provided in the {@link Send} object)
|
|
271
|
+
* - sequence of {@link Send} objects
|
|
272
|
+
*/
|
|
248
273
|
Object.defineProperty(this, "goto", {
|
|
249
274
|
enumerable: true,
|
|
250
275
|
configurable: true,
|
|
@@ -255,9 +280,16 @@ export class Command {
|
|
|
255
280
|
this.graph = args.graph;
|
|
256
281
|
this.update = args.update;
|
|
257
282
|
if (args.goto) {
|
|
258
|
-
this.goto = Array.isArray(args.goto)
|
|
283
|
+
this.goto = Array.isArray(args.goto)
|
|
284
|
+
? _convertCommandSendTree(args.goto)
|
|
285
|
+
: [_convertCommandSendTree(args.goto)];
|
|
259
286
|
}
|
|
260
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* Convert the update field to a list of {@link PendingWrite} tuples
|
|
290
|
+
* @returns List of {@link PendingWrite} tuples of the form `[channelKey, value]`.
|
|
291
|
+
* @internal
|
|
292
|
+
*/
|
|
261
293
|
_updateAsTuples() {
|
|
262
294
|
if (this.update &&
|
|
263
295
|
typeof this.update === "object" &&
|
|
@@ -281,7 +313,7 @@ export class Command {
|
|
|
281
313
|
serializedGoto = this.goto.toJSON();
|
|
282
314
|
}
|
|
283
315
|
else {
|
|
284
|
-
serializedGoto = this.goto
|
|
316
|
+
serializedGoto = this.goto?.map((innerGoto) => {
|
|
285
317
|
if (typeof innerGoto === "string") {
|
|
286
318
|
return innerGoto;
|
|
287
319
|
}
|
|
@@ -303,7 +335,61 @@ Object.defineProperty(Command, "PARENT", {
|
|
|
303
335
|
writable: true,
|
|
304
336
|
value: "__parent__"
|
|
305
337
|
});
|
|
338
|
+
/**
|
|
339
|
+
* A type guard to check if the given value is a {@link Command}.
|
|
340
|
+
*
|
|
341
|
+
* Useful for type narrowing when working with the {@link Command} object.
|
|
342
|
+
*
|
|
343
|
+
* @param x - The value to check.
|
|
344
|
+
* @returns `true` if the value is a {@link Command}, `false` otherwise.
|
|
345
|
+
*/
|
|
306
346
|
export function isCommand(x) {
|
|
307
|
-
|
|
347
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
348
|
+
return x instanceof Command;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* A type guard to check if the given value is a {@link CommandParams}.
|
|
352
|
+
*
|
|
353
|
+
* Useful for type narrowing when working with the {@link CommandParams} object.
|
|
354
|
+
*
|
|
355
|
+
* @param x - The value to check.
|
|
356
|
+
* @returns `true` if the value is a {@link CommandParams}, `false` otherwise.
|
|
357
|
+
*/
|
|
358
|
+
export function isCommandParams(x) {
|
|
359
|
+
if (typeof x !== "object") {
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
if (x === null || x === undefined) {
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
if ("update" in x && "resume" in x && "goto" in x) {
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
function _convertCommandSendTree(x, seen = new Set()) {
|
|
371
|
+
if (x !== undefined && x !== null && typeof x === "object") {
|
|
372
|
+
if (seen.has(x)) {
|
|
373
|
+
throw new Error("Command send tree contains a cycle");
|
|
374
|
+
}
|
|
375
|
+
seen.add(x);
|
|
376
|
+
if (Array.isArray(x)) {
|
|
377
|
+
return x.map((innerX) => _convertCommandSendTree(innerX, new Set(seen)));
|
|
378
|
+
}
|
|
379
|
+
if (isCommand(x) || _isSend(x)) {
|
|
380
|
+
return x;
|
|
381
|
+
}
|
|
382
|
+
if (isCommandParams(x)) {
|
|
383
|
+
return new Command(x);
|
|
384
|
+
}
|
|
385
|
+
if (_isSendInterface(x)) {
|
|
386
|
+
return new Send(x.node, x.args);
|
|
387
|
+
}
|
|
388
|
+
return Object.fromEntries(Object.entries(x).map(([key, value]) => [
|
|
389
|
+
key,
|
|
390
|
+
_convertCommandSendTree(value, seen),
|
|
391
|
+
]));
|
|
392
|
+
}
|
|
393
|
+
return x;
|
|
308
394
|
}
|
|
309
395
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,gEAAgE;AAChE,MAAM,CAAC,MAAM,KAAK,GAAG,WAAW,CAAC;AACjC,8DAA8D;AAC9D,MAAM,CAAC,MAAM,GAAG,GAAG,SAAS,CAAC;AAC7B,MAAM,CAAC,MAAM,KAAK,GAAG,WAAW,CAAC;AACjC,MAAM,CAAC,MAAM,IAAI,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AAgB,CAAC,CAAC,CAAC,EAAE;YACvB,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;SACjC;QAED,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;YACtC,GAAG;YACH,uBAAuB,CAAC,KAAK,EAAE,IAAI,CAAC;SACrC,CAAC,CACH,CAAC;KACH;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/dist/graph/graph.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export type AddNodeOptions = {
|
|
|
33
33
|
subgraphs?: Pregel<any, any>[];
|
|
34
34
|
ends?: string[];
|
|
35
35
|
};
|
|
36
|
-
export declare class Graph<N extends string = typeof END, RunInput = any, RunOutput = any, NodeSpecType extends NodeSpec<RunInput, RunOutput> = NodeSpec<RunInput, RunOutput>, C extends StateDefinition = StateDefinition> {
|
|
36
|
+
export declare class Graph<N extends string = typeof START | typeof END, RunInput = any, RunOutput = any, NodeSpecType extends NodeSpec<RunInput, RunOutput> = NodeSpec<RunInput, RunOutput>, C extends StateDefinition = StateDefinition> {
|
|
37
37
|
nodes: Record<N, NodeSpecType>;
|
|
38
38
|
edges: Set<[N | typeof START, N | typeof END]>;
|
|
39
39
|
branches: Record<string, Record<string, Branch<RunInput, N, any>>>;
|