@langchain/langgraph 0.2.35 → 0.2.37
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 +31 -2
- package/dist/constants.d.ts +17 -2
- package/dist/constants.js +31 -2
- package/dist/graph/state.cjs +21 -5
- package/dist/graph/state.js +21 -5
- package/dist/pregel/remote.cjs +14 -3
- package/dist/pregel/remote.js +15 -4
- package/package.json +2 -2
package/dist/constants.cjs
CHANGED
|
@@ -117,6 +117,12 @@ class Send {
|
|
|
117
117
|
value: "Send"
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
|
+
toJSON() {
|
|
121
|
+
return {
|
|
122
|
+
node: this.node,
|
|
123
|
+
args: this.args,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
120
126
|
}
|
|
121
127
|
exports.Send = Send;
|
|
122
128
|
function _isSend(x) {
|
|
@@ -206,12 +212,11 @@ class Command {
|
|
|
206
212
|
writable: true,
|
|
207
213
|
value: void 0
|
|
208
214
|
});
|
|
209
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
210
215
|
Object.defineProperty(this, "update", {
|
|
211
216
|
enumerable: true,
|
|
212
217
|
configurable: true,
|
|
213
218
|
writable: true,
|
|
214
|
-
value:
|
|
219
|
+
value: void 0
|
|
215
220
|
});
|
|
216
221
|
Object.defineProperty(this, "resume", {
|
|
217
222
|
enumerable: true,
|
|
@@ -246,6 +251,30 @@ class Command {
|
|
|
246
251
|
return [["__root__", this.update]];
|
|
247
252
|
}
|
|
248
253
|
}
|
|
254
|
+
toJSON() {
|
|
255
|
+
let serializedGoto;
|
|
256
|
+
if (typeof this.goto === "string") {
|
|
257
|
+
serializedGoto = this.goto;
|
|
258
|
+
}
|
|
259
|
+
else if (_isSend(this.goto)) {
|
|
260
|
+
serializedGoto = this.goto.toJSON();
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
serializedGoto = this.goto.map((innerGoto) => {
|
|
264
|
+
if (typeof innerGoto === "string") {
|
|
265
|
+
return innerGoto;
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
return innerGoto.toJSON();
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
update: this.update,
|
|
274
|
+
resume: this.resume,
|
|
275
|
+
goto: serializedGoto,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
249
278
|
}
|
|
250
279
|
exports.Command = Command;
|
|
251
280
|
Object.defineProperty(Command, "PARENT", {
|
package/dist/constants.d.ts
CHANGED
|
@@ -83,6 +83,10 @@ export declare class Send implements SendInterface {
|
|
|
83
83
|
args: any;
|
|
84
84
|
lg_name: string;
|
|
85
85
|
constructor(node: string, args: any);
|
|
86
|
+
toJSON(): {
|
|
87
|
+
node: string;
|
|
88
|
+
args: any;
|
|
89
|
+
};
|
|
86
90
|
}
|
|
87
91
|
export declare function _isSend(x: unknown): x is Send;
|
|
88
92
|
export type Interrupt = {
|
|
@@ -105,7 +109,7 @@ export type CommandParams<R> = {
|
|
|
105
109
|
/**
|
|
106
110
|
* Update to apply to the graph's state.
|
|
107
111
|
*/
|
|
108
|
-
update?: Record<string,
|
|
112
|
+
update?: Record<string, unknown> | [string, unknown][];
|
|
109
113
|
/**
|
|
110
114
|
* Can be one of the following:
|
|
111
115
|
* - name of the node to navigate to next (any node that belongs to the specified `graph`)
|
|
@@ -181,11 +185,22 @@ export declare class Command<R = unknown> {
|
|
|
181
185
|
lg_name: string;
|
|
182
186
|
lc_direct_tool_output: boolean;
|
|
183
187
|
graph?: string;
|
|
184
|
-
update?: Record<string,
|
|
188
|
+
update?: Record<string, unknown> | [string, unknown][];
|
|
185
189
|
resume?: R;
|
|
186
190
|
goto: string | Send | (string | Send)[];
|
|
187
191
|
static PARENT: string;
|
|
188
192
|
constructor(args: CommandParams<R>);
|
|
189
193
|
_updateAsTuples(): [string, unknown][];
|
|
194
|
+
toJSON(): {
|
|
195
|
+
update: Record<string, unknown> | [string, unknown][] | undefined;
|
|
196
|
+
resume: R | undefined;
|
|
197
|
+
goto: string | {
|
|
198
|
+
node: string;
|
|
199
|
+
args: any;
|
|
200
|
+
} | (string | {
|
|
201
|
+
node: string;
|
|
202
|
+
args: any;
|
|
203
|
+
})[];
|
|
204
|
+
};
|
|
190
205
|
}
|
|
191
206
|
export declare function isCommand(x: unknown): x is Command;
|
package/dist/constants.js
CHANGED
|
@@ -113,6 +113,12 @@ export class Send {
|
|
|
113
113
|
value: "Send"
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
|
+
toJSON() {
|
|
117
|
+
return {
|
|
118
|
+
node: this.node,
|
|
119
|
+
args: this.args,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
116
122
|
}
|
|
117
123
|
export function _isSend(x) {
|
|
118
124
|
const operation = x;
|
|
@@ -200,12 +206,11 @@ export class Command {
|
|
|
200
206
|
writable: true,
|
|
201
207
|
value: void 0
|
|
202
208
|
});
|
|
203
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
204
209
|
Object.defineProperty(this, "update", {
|
|
205
210
|
enumerable: true,
|
|
206
211
|
configurable: true,
|
|
207
212
|
writable: true,
|
|
208
|
-
value:
|
|
213
|
+
value: void 0
|
|
209
214
|
});
|
|
210
215
|
Object.defineProperty(this, "resume", {
|
|
211
216
|
enumerable: true,
|
|
@@ -240,6 +245,30 @@ export class Command {
|
|
|
240
245
|
return [["__root__", this.update]];
|
|
241
246
|
}
|
|
242
247
|
}
|
|
248
|
+
toJSON() {
|
|
249
|
+
let serializedGoto;
|
|
250
|
+
if (typeof this.goto === "string") {
|
|
251
|
+
serializedGoto = this.goto;
|
|
252
|
+
}
|
|
253
|
+
else if (_isSend(this.goto)) {
|
|
254
|
+
serializedGoto = this.goto.toJSON();
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
serializedGoto = this.goto.map((innerGoto) => {
|
|
258
|
+
if (typeof innerGoto === "string") {
|
|
259
|
+
return innerGoto;
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
return innerGoto.toJSON();
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
update: this.update,
|
|
268
|
+
resume: this.resume,
|
|
269
|
+
goto: serializedGoto,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
243
272
|
}
|
|
244
273
|
Object.defineProperty(Command, "PARENT", {
|
|
245
274
|
enumerable: true,
|
package/dist/graph/state.cjs
CHANGED
|
@@ -425,7 +425,7 @@ class CompiledStateGraph extends graph_js_1.CompiledGraph {
|
|
|
425
425
|
}
|
|
426
426
|
else {
|
|
427
427
|
const typeofInput = Array.isArray(input) ? "array" : typeof input;
|
|
428
|
-
throw new errors_js_1.InvalidUpdateError(`Expected node "${nodeKey.toString()}" to return an object, received ${typeofInput}`, {
|
|
428
|
+
throw new errors_js_1.InvalidUpdateError(`Expected node "${nodeKey.toString()}" to return an object or an array containing at least one Command object, received ${typeofInput}`, {
|
|
429
429
|
lc_error_code: "INVALID_GRAPH_NODE_RETURN_VALUE",
|
|
430
430
|
});
|
|
431
431
|
}
|
|
@@ -583,13 +583,29 @@ function _controlBranch(value) {
|
|
|
583
583
|
if ((0, constants_js_1._isSend)(value)) {
|
|
584
584
|
return [value];
|
|
585
585
|
}
|
|
586
|
-
|
|
586
|
+
const commands = [];
|
|
587
|
+
if ((0, constants_js_1.isCommand)(value)) {
|
|
588
|
+
commands.push(value);
|
|
589
|
+
}
|
|
590
|
+
else if (Array.isArray(value) && value.every(constants_js_1.isCommand)) {
|
|
591
|
+
commands.push(...value);
|
|
592
|
+
}
|
|
593
|
+
else {
|
|
587
594
|
return [];
|
|
588
595
|
}
|
|
589
|
-
|
|
590
|
-
|
|
596
|
+
const destinations = [];
|
|
597
|
+
for (const command of commands) {
|
|
598
|
+
if (command.graph === constants_js_1.Command.PARENT) {
|
|
599
|
+
throw new errors_js_1.ParentCommand(command);
|
|
600
|
+
}
|
|
601
|
+
if ((0, constants_js_1._isSend)(command.goto) || typeof command.goto === "string") {
|
|
602
|
+
destinations.push(command.goto);
|
|
603
|
+
}
|
|
604
|
+
else {
|
|
605
|
+
destinations.push(...command.goto);
|
|
606
|
+
}
|
|
591
607
|
}
|
|
592
|
-
return
|
|
608
|
+
return destinations;
|
|
593
609
|
}
|
|
594
610
|
function _getControlBranch() {
|
|
595
611
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/dist/graph/state.js
CHANGED
|
@@ -421,7 +421,7 @@ export class CompiledStateGraph extends CompiledGraph {
|
|
|
421
421
|
}
|
|
422
422
|
else {
|
|
423
423
|
const typeofInput = Array.isArray(input) ? "array" : typeof input;
|
|
424
|
-
throw new InvalidUpdateError(`Expected node "${nodeKey.toString()}" to return an object, received ${typeofInput}`, {
|
|
424
|
+
throw new InvalidUpdateError(`Expected node "${nodeKey.toString()}" to return an object or an array containing at least one Command object, received ${typeofInput}`, {
|
|
425
425
|
lc_error_code: "INVALID_GRAPH_NODE_RETURN_VALUE",
|
|
426
426
|
});
|
|
427
427
|
}
|
|
@@ -578,13 +578,29 @@ function _controlBranch(value) {
|
|
|
578
578
|
if (_isSend(value)) {
|
|
579
579
|
return [value];
|
|
580
580
|
}
|
|
581
|
-
|
|
581
|
+
const commands = [];
|
|
582
|
+
if (isCommand(value)) {
|
|
583
|
+
commands.push(value);
|
|
584
|
+
}
|
|
585
|
+
else if (Array.isArray(value) && value.every(isCommand)) {
|
|
586
|
+
commands.push(...value);
|
|
587
|
+
}
|
|
588
|
+
else {
|
|
582
589
|
return [];
|
|
583
590
|
}
|
|
584
|
-
|
|
585
|
-
|
|
591
|
+
const destinations = [];
|
|
592
|
+
for (const command of commands) {
|
|
593
|
+
if (command.graph === Command.PARENT) {
|
|
594
|
+
throw new ParentCommand(command);
|
|
595
|
+
}
|
|
596
|
+
if (_isSend(command.goto) || typeof command.goto === "string") {
|
|
597
|
+
destinations.push(command.goto);
|
|
598
|
+
}
|
|
599
|
+
else {
|
|
600
|
+
destinations.push(...command.goto);
|
|
601
|
+
}
|
|
586
602
|
}
|
|
587
|
-
return
|
|
603
|
+
return destinations;
|
|
588
604
|
}
|
|
589
605
|
function _getControlBranch() {
|
|
590
606
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/dist/pregel/remote.cjs
CHANGED
|
@@ -295,8 +295,8 @@ class RemoteGraph extends runnables_1.Runnable {
|
|
|
295
295
|
const sanitizedConfig = this._sanitizeConfig(mergedConfig);
|
|
296
296
|
const streamProtocolInstance = options?.configurable?.[constants_js_1.CONFIG_KEY_STREAM];
|
|
297
297
|
const streamSubgraphs = options?.subgraphs ?? streamProtocolInstance !== undefined;
|
|
298
|
-
const interruptBefore =
|
|
299
|
-
const interruptAfter =
|
|
298
|
+
const interruptBefore = options?.interruptBefore ?? this.interruptBefore;
|
|
299
|
+
const interruptAfter = options?.interruptAfter ?? this.interruptAfter;
|
|
300
300
|
const { updatedStreamModes, reqSingle, reqUpdates } = getStreamModes(options?.streamMode);
|
|
301
301
|
const extendedStreamModes = [
|
|
302
302
|
...new Set([
|
|
@@ -304,8 +304,19 @@ class RemoteGraph extends runnables_1.Runnable {
|
|
|
304
304
|
...(streamProtocolInstance?.modes ?? new Set()),
|
|
305
305
|
]),
|
|
306
306
|
];
|
|
307
|
+
let command;
|
|
308
|
+
let serializedInput;
|
|
309
|
+
if ((0, constants_js_1.isCommand)(input)) {
|
|
310
|
+
// TODO: Remove cast when SDK type fix gets merged
|
|
311
|
+
command = input.toJSON();
|
|
312
|
+
serializedInput = undefined;
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
serializedInput = _serializeInputs(input);
|
|
316
|
+
}
|
|
307
317
|
for await (const chunk of this.client.runs.stream(sanitizedConfig.configurable.thread_id, this.graphId, {
|
|
308
|
-
|
|
318
|
+
command,
|
|
319
|
+
input: serializedInput,
|
|
309
320
|
config: sanitizedConfig,
|
|
310
321
|
streamMode: extendedStreamModes,
|
|
311
322
|
interruptBefore: interruptBefore,
|
package/dist/pregel/remote.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Graph as DrawableGraph, } from "@langchain/core/runnables/graph";
|
|
|
3
3
|
import { mergeConfigs, Runnable, } from "@langchain/core/runnables";
|
|
4
4
|
import { isBaseMessage } from "@langchain/core/messages";
|
|
5
5
|
import { GraphInterrupt, RemoteException, } from "../web.js";
|
|
6
|
-
import { CHECKPOINT_NAMESPACE_SEPARATOR, CONFIG_KEY_STREAM, INTERRUPT, } from "../constants.js";
|
|
6
|
+
import { CHECKPOINT_NAMESPACE_SEPARATOR, CONFIG_KEY_STREAM, INTERRUPT, isCommand, } from "../constants.js";
|
|
7
7
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
8
|
const _serializeInputs = (obj) => {
|
|
9
9
|
if (obj === null || typeof obj !== "object") {
|
|
@@ -292,8 +292,8 @@ export class RemoteGraph extends Runnable {
|
|
|
292
292
|
const sanitizedConfig = this._sanitizeConfig(mergedConfig);
|
|
293
293
|
const streamProtocolInstance = options?.configurable?.[CONFIG_KEY_STREAM];
|
|
294
294
|
const streamSubgraphs = options?.subgraphs ?? streamProtocolInstance !== undefined;
|
|
295
|
-
const interruptBefore =
|
|
296
|
-
const interruptAfter =
|
|
295
|
+
const interruptBefore = options?.interruptBefore ?? this.interruptBefore;
|
|
296
|
+
const interruptAfter = options?.interruptAfter ?? this.interruptAfter;
|
|
297
297
|
const { updatedStreamModes, reqSingle, reqUpdates } = getStreamModes(options?.streamMode);
|
|
298
298
|
const extendedStreamModes = [
|
|
299
299
|
...new Set([
|
|
@@ -301,8 +301,19 @@ export class RemoteGraph extends Runnable {
|
|
|
301
301
|
...(streamProtocolInstance?.modes ?? new Set()),
|
|
302
302
|
]),
|
|
303
303
|
];
|
|
304
|
+
let command;
|
|
305
|
+
let serializedInput;
|
|
306
|
+
if (isCommand(input)) {
|
|
307
|
+
// TODO: Remove cast when SDK type fix gets merged
|
|
308
|
+
command = input.toJSON();
|
|
309
|
+
serializedInput = undefined;
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
serializedInput = _serializeInputs(input);
|
|
313
|
+
}
|
|
304
314
|
for await (const chunk of this.client.runs.stream(sanitizedConfig.configurable.thread_id, this.graphId, {
|
|
305
|
-
|
|
315
|
+
command,
|
|
316
|
+
input: serializedInput,
|
|
306
317
|
config: sanitizedConfig,
|
|
307
318
|
streamMode: extendedStreamModes,
|
|
308
319
|
interruptBefore: interruptBefore,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/langgraph",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.37",
|
|
4
4
|
"description": "LangGraph",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@langchain/langgraph-checkpoint": "~0.0.13",
|
|
35
|
-
"@langchain/langgraph-sdk": "~0.0.
|
|
35
|
+
"@langchain/langgraph-sdk": "~0.0.32",
|
|
36
36
|
"uuid": "^10.0.0",
|
|
37
37
|
"zod": "^3.23.8"
|
|
38
38
|
},
|