@langchain/langgraph 0.0.12 → 0.0.14
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/checkpoint/sqlite.cjs +1 -0
- package/checkpoint/sqlite.d.cts +1 -0
- package/checkpoint/sqlite.d.ts +1 -0
- package/checkpoint/sqlite.js +1 -0
- package/dist/channels/any_value.cjs +57 -0
- package/dist/channels/any_value.d.ts +16 -0
- package/dist/channels/any_value.js +53 -0
- package/dist/channels/base.cjs +19 -28
- package/dist/channels/base.d.ts +13 -19
- package/dist/channels/base.js +17 -24
- package/dist/channels/binop.cjs +4 -3
- package/dist/channels/binop.d.ts +1 -1
- package/dist/channels/binop.js +3 -2
- package/dist/channels/dynamic_barrier_value.cjs +88 -0
- package/dist/channels/dynamic_barrier_value.d.ts +26 -0
- package/dist/channels/dynamic_barrier_value.js +84 -0
- package/dist/channels/ephemeral_value.cjs +64 -0
- package/dist/channels/ephemeral_value.d.ts +14 -0
- package/dist/channels/ephemeral_value.js +60 -0
- package/dist/channels/index.cjs +1 -3
- package/dist/channels/index.d.ts +1 -1
- package/dist/channels/index.js +1 -1
- package/dist/channels/last_value.cjs +11 -5
- package/dist/channels/last_value.d.ts +5 -1
- package/dist/channels/last_value.js +9 -3
- package/dist/channels/named_barrier_value.cjs +71 -0
- package/dist/channels/named_barrier_value.d.ts +18 -0
- package/dist/channels/named_barrier_value.js +66 -0
- package/dist/channels/topic.cjs +5 -3
- package/dist/channels/topic.d.ts +3 -3
- package/dist/channels/topic.js +5 -3
- package/dist/checkpoint/base.cjs +30 -12
- package/dist/checkpoint/base.d.ts +39 -22
- package/dist/checkpoint/base.js +28 -11
- package/dist/checkpoint/id.cjs +40 -0
- package/dist/checkpoint/id.d.ts +2 -0
- package/dist/checkpoint/id.js +35 -0
- package/dist/checkpoint/index.cjs +2 -2
- package/dist/checkpoint/index.d.ts +2 -2
- package/dist/checkpoint/index.js +2 -2
- package/dist/checkpoint/memory.cjs +66 -49
- package/dist/checkpoint/memory.d.ts +7 -10
- package/dist/checkpoint/memory.js +65 -47
- package/dist/checkpoint/sqlite.cjs +173 -0
- package/dist/checkpoint/sqlite.d.ts +14 -0
- package/dist/checkpoint/sqlite.js +166 -0
- package/dist/constants.cjs +3 -1
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +2 -0
- package/dist/errors.cjs +31 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.js +24 -0
- package/dist/graph/graph.cjs +235 -95
- package/dist/graph/graph.d.ts +52 -23
- package/dist/graph/graph.js +234 -96
- package/dist/graph/index.cjs +2 -2
- package/dist/graph/index.d.ts +2 -2
- package/dist/graph/index.js +2 -2
- package/dist/graph/message.cjs +4 -3
- package/dist/graph/message.d.ts +4 -1
- package/dist/graph/message.js +4 -3
- package/dist/graph/state.cjs +237 -102
- package/dist/graph/state.d.ts +41 -18
- package/dist/graph/state.js +238 -104
- package/dist/index.cjs +12 -7
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/prebuilt/agent_executor.cjs +22 -36
- package/dist/prebuilt/agent_executor.d.ts +7 -10
- package/dist/prebuilt/agent_executor.js +23 -37
- package/dist/prebuilt/chat_agent_executor.cjs +13 -13
- package/dist/prebuilt/chat_agent_executor.d.ts +3 -1
- package/dist/prebuilt/chat_agent_executor.js +15 -15
- package/dist/prebuilt/index.cjs +4 -1
- package/dist/prebuilt/index.d.ts +1 -0
- package/dist/prebuilt/index.js +1 -0
- package/dist/prebuilt/tool_node.cjs +59 -0
- package/dist/prebuilt/tool_node.d.ts +17 -0
- package/dist/prebuilt/tool_node.js +54 -0
- package/dist/pregel/debug.cjs +6 -8
- package/dist/pregel/debug.d.ts +2 -2
- package/dist/pregel/debug.js +5 -7
- package/dist/pregel/index.cjs +504 -232
- package/dist/pregel/index.d.ts +80 -41
- package/dist/pregel/index.js +507 -238
- package/dist/pregel/io.cjs +117 -30
- package/dist/pregel/io.d.ts +11 -3
- package/dist/pregel/io.js +111 -28
- package/dist/pregel/read.cjs +126 -46
- package/dist/pregel/read.d.ts +27 -18
- package/dist/pregel/read.js +125 -45
- package/dist/pregel/types.cjs +2 -0
- package/dist/pregel/types.d.ts +37 -0
- package/dist/pregel/types.js +1 -0
- package/dist/pregel/validate.cjs +58 -51
- package/dist/pregel/validate.d.ts +14 -13
- package/dist/pregel/validate.js +56 -50
- package/dist/pregel/write.cjs +46 -30
- package/dist/pregel/write.d.ts +18 -8
- package/dist/pregel/write.js +45 -29
- package/dist/serde/base.cjs +2 -0
- package/dist/serde/base.d.ts +4 -0
- package/dist/serde/base.js +1 -0
- package/dist/setup/async_local_storage.cjs +2 -2
- package/dist/setup/async_local_storage.js +1 -1
- package/dist/tests/channels.test.d.ts +1 -0
- package/dist/tests/channels.test.js +151 -0
- package/dist/tests/chatbot.int.test.d.ts +1 -0
- package/dist/tests/chatbot.int.test.js +61 -0
- package/dist/tests/checkpoints.test.d.ts +1 -0
- package/dist/tests/checkpoints.test.js +190 -0
- package/dist/tests/graph.test.d.ts +1 -0
- package/dist/tests/graph.test.js +15 -0
- package/dist/tests/prebuilt.int.test.d.ts +1 -0
- package/dist/tests/prebuilt.int.test.js +101 -0
- package/dist/tests/prebuilt.test.d.ts +1 -0
- package/dist/tests/prebuilt.test.js +195 -0
- package/dist/tests/pregel.io.test.d.ts +1 -0
- package/dist/tests/pregel.io.test.js +332 -0
- package/dist/tests/pregel.read.test.d.ts +1 -0
- package/dist/tests/pregel.read.test.js +109 -0
- package/dist/tests/pregel.test.d.ts +1 -0
- package/dist/tests/pregel.test.js +1879 -0
- package/dist/tests/pregel.validate.test.d.ts +1 -0
- package/dist/tests/pregel.validate.test.js +198 -0
- package/dist/tests/pregel.write.test.d.ts +1 -0
- package/dist/tests/pregel.write.test.js +44 -0
- package/dist/tests/tracing.int.test.d.ts +1 -0
- package/dist/tests/tracing.int.test.js +449 -0
- package/dist/tests/utils.d.ts +22 -0
- package/dist/tests/utils.js +76 -0
- package/dist/utils.cjs +74 -0
- package/dist/utils.d.ts +18 -0
- package/dist/utils.js +70 -0
- package/package.json +33 -8
- package/dist/pregel/reserved.cjs +0 -6
- package/dist/pregel/reserved.d.ts +0 -3
- package/dist/pregel/reserved.js +0 -3
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseChannel } from "./index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Stores the value received in the step immediately preceding, clears after.
|
|
4
|
+
*/
|
|
5
|
+
export declare class EphemeralValue<Value> extends BaseChannel<Value, Value, Value> {
|
|
6
|
+
lc_graph_name: string;
|
|
7
|
+
guard: boolean;
|
|
8
|
+
value?: Value;
|
|
9
|
+
constructor(guard?: boolean);
|
|
10
|
+
fromCheckpoint(checkpoint?: Value): this;
|
|
11
|
+
update(values: Value[]): void;
|
|
12
|
+
get(): Value;
|
|
13
|
+
checkpoint(): Value;
|
|
14
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { EmptyChannelError, InvalidUpdateError } from "../errors.js";
|
|
2
|
+
import { BaseChannel } from "./index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Stores the value received in the step immediately preceding, clears after.
|
|
5
|
+
*/
|
|
6
|
+
export class EphemeralValue extends BaseChannel {
|
|
7
|
+
constructor(guard = true) {
|
|
8
|
+
super();
|
|
9
|
+
Object.defineProperty(this, "lc_graph_name", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: "EphemeralValue"
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(this, "guard", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: void 0
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(this, "value", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: void 0
|
|
26
|
+
});
|
|
27
|
+
this.guard = guard;
|
|
28
|
+
}
|
|
29
|
+
fromCheckpoint(checkpoint) {
|
|
30
|
+
const empty = new EphemeralValue();
|
|
31
|
+
if (checkpoint) {
|
|
32
|
+
empty.value = checkpoint;
|
|
33
|
+
}
|
|
34
|
+
return empty;
|
|
35
|
+
}
|
|
36
|
+
update(values) {
|
|
37
|
+
if (values.length === 0) {
|
|
38
|
+
// If there are no updates for this specific channel at the end of the step, wipe it.
|
|
39
|
+
this.value = undefined;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (values.length !== 1 && this.guard) {
|
|
43
|
+
throw new InvalidUpdateError("EphemeralValue can only receive one value per step.");
|
|
44
|
+
}
|
|
45
|
+
// eslint-disable-next-line prefer-destructuring
|
|
46
|
+
this.value = values[values.length - 1];
|
|
47
|
+
}
|
|
48
|
+
get() {
|
|
49
|
+
if (this.value === undefined) {
|
|
50
|
+
throw new EmptyChannelError();
|
|
51
|
+
}
|
|
52
|
+
return this.value;
|
|
53
|
+
}
|
|
54
|
+
checkpoint() {
|
|
55
|
+
if (this.value === undefined) {
|
|
56
|
+
throw new EmptyChannelError();
|
|
57
|
+
}
|
|
58
|
+
return this.value;
|
|
59
|
+
}
|
|
60
|
+
}
|
package/dist/channels/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.empty = exports.createCheckpoint = exports.
|
|
3
|
+
exports.empty = exports.createCheckpoint = exports.BaseChannel = void 0;
|
|
4
4
|
var base_js_1 = require("./base.cjs");
|
|
5
5
|
Object.defineProperty(exports, "BaseChannel", { enumerable: true, get: function () { return base_js_1.BaseChannel; } });
|
|
6
|
-
Object.defineProperty(exports, "EmptyChannelError", { enumerable: true, get: function () { return base_js_1.EmptyChannelError; } });
|
|
7
|
-
Object.defineProperty(exports, "InvalidUpdateError", { enumerable: true, get: function () { return base_js_1.InvalidUpdateError; } });
|
|
8
6
|
Object.defineProperty(exports, "createCheckpoint", { enumerable: true, get: function () { return base_js_1.createCheckpoint; } });
|
|
9
7
|
Object.defineProperty(exports, "empty", { enumerable: true, get: function () { return base_js_1.emptyChannels; } });
|
package/dist/channels/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { BaseChannel,
|
|
1
|
+
export { BaseChannel, createCheckpoint, emptyChannels as empty, } from "./base.js";
|
package/dist/channels/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { BaseChannel,
|
|
1
|
+
export { BaseChannel, createCheckpoint, emptyChannels as empty, } from "./base.js";
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LastValue = void 0;
|
|
4
|
+
const errors_js_1 = require("../errors.cjs");
|
|
4
5
|
const index_js_1 = require("./index.cjs");
|
|
5
6
|
/**
|
|
6
7
|
* Stores the last value received, can receive at most one value per step.
|
|
8
|
+
*
|
|
9
|
+
* Since `update` is only called once per step and value can only be of length 1,
|
|
10
|
+
* LastValue always stores the last value of a single node. If multiple nodes attempt to
|
|
11
|
+
* write to this channel in a single step, an error will be thrown.
|
|
7
12
|
*/
|
|
8
13
|
class LastValue extends index_js_1.BaseChannel {
|
|
9
14
|
constructor() {
|
|
@@ -21,7 +26,7 @@ class LastValue extends index_js_1.BaseChannel {
|
|
|
21
26
|
value: void 0
|
|
22
27
|
});
|
|
23
28
|
}
|
|
24
|
-
|
|
29
|
+
fromCheckpoint(checkpoint) {
|
|
25
30
|
const empty = new LastValue();
|
|
26
31
|
if (checkpoint) {
|
|
27
32
|
empty.value = checkpoint;
|
|
@@ -33,19 +38,20 @@ class LastValue extends index_js_1.BaseChannel {
|
|
|
33
38
|
return;
|
|
34
39
|
}
|
|
35
40
|
if (values.length !== 1) {
|
|
36
|
-
throw new
|
|
41
|
+
throw new errors_js_1.InvalidUpdateError();
|
|
37
42
|
}
|
|
38
|
-
|
|
43
|
+
// eslint-disable-next-line prefer-destructuring
|
|
44
|
+
this.value = values[values.length - 1];
|
|
39
45
|
}
|
|
40
46
|
get() {
|
|
41
47
|
if (this.value === undefined) {
|
|
42
|
-
throw new
|
|
48
|
+
throw new errors_js_1.EmptyChannelError();
|
|
43
49
|
}
|
|
44
50
|
return this.value;
|
|
45
51
|
}
|
|
46
52
|
checkpoint() {
|
|
47
53
|
if (this.value === undefined) {
|
|
48
|
-
throw new
|
|
54
|
+
throw new errors_js_1.EmptyChannelError();
|
|
49
55
|
}
|
|
50
56
|
return this.value;
|
|
51
57
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { BaseChannel } from "./index.js";
|
|
2
2
|
/**
|
|
3
3
|
* Stores the last value received, can receive at most one value per step.
|
|
4
|
+
*
|
|
5
|
+
* Since `update` is only called once per step and value can only be of length 1,
|
|
6
|
+
* LastValue always stores the last value of a single node. If multiple nodes attempt to
|
|
7
|
+
* write to this channel in a single step, an error will be thrown.
|
|
4
8
|
*/
|
|
5
9
|
export declare class LastValue<Value> extends BaseChannel<Value, Value, Value> {
|
|
6
10
|
lc_graph_name: string;
|
|
7
11
|
value?: Value;
|
|
8
|
-
|
|
12
|
+
fromCheckpoint(checkpoint?: Value): this;
|
|
9
13
|
update(values: Value[]): void;
|
|
10
14
|
get(): Value;
|
|
11
15
|
checkpoint(): Value;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EmptyChannelError, InvalidUpdateError } from "../errors.js";
|
|
2
|
+
import { BaseChannel } from "./index.js";
|
|
2
3
|
/**
|
|
3
4
|
* Stores the last value received, can receive at most one value per step.
|
|
5
|
+
*
|
|
6
|
+
* Since `update` is only called once per step and value can only be of length 1,
|
|
7
|
+
* LastValue always stores the last value of a single node. If multiple nodes attempt to
|
|
8
|
+
* write to this channel in a single step, an error will be thrown.
|
|
4
9
|
*/
|
|
5
10
|
export class LastValue extends BaseChannel {
|
|
6
11
|
constructor() {
|
|
@@ -18,7 +23,7 @@ export class LastValue extends BaseChannel {
|
|
|
18
23
|
value: void 0
|
|
19
24
|
});
|
|
20
25
|
}
|
|
21
|
-
|
|
26
|
+
fromCheckpoint(checkpoint) {
|
|
22
27
|
const empty = new LastValue();
|
|
23
28
|
if (checkpoint) {
|
|
24
29
|
empty.value = checkpoint;
|
|
@@ -32,7 +37,8 @@ export class LastValue extends BaseChannel {
|
|
|
32
37
|
if (values.length !== 1) {
|
|
33
38
|
throw new InvalidUpdateError();
|
|
34
39
|
}
|
|
35
|
-
|
|
40
|
+
// eslint-disable-next-line prefer-destructuring
|
|
41
|
+
this.value = values[values.length - 1];
|
|
36
42
|
}
|
|
37
43
|
get() {
|
|
38
44
|
if (this.value === undefined) {
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NamedBarrierValue = exports.areSetsEqual = void 0;
|
|
4
|
+
const errors_js_1 = require("../errors.cjs");
|
|
5
|
+
const index_js_1 = require("./index.cjs");
|
|
6
|
+
const areSetsEqual = (a, b) => a.size === b.size && [...a].every((value) => b.has(value));
|
|
7
|
+
exports.areSetsEqual = areSetsEqual;
|
|
8
|
+
/**
|
|
9
|
+
* A channel that waits until all named values are received before making the value available.
|
|
10
|
+
*
|
|
11
|
+
* This ensures that if node N and node M both write to channel C, the value of C will not be updated
|
|
12
|
+
* until N and M have completed updating.
|
|
13
|
+
*/
|
|
14
|
+
class NamedBarrierValue extends index_js_1.BaseChannel {
|
|
15
|
+
constructor(names) {
|
|
16
|
+
super();
|
|
17
|
+
Object.defineProperty(this, "lc_graph_name", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: "NamedBarrierValue"
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "names", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
}); // Names of nodes that we want to wait for.
|
|
29
|
+
Object.defineProperty(this, "seen", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true,
|
|
33
|
+
value: void 0
|
|
34
|
+
});
|
|
35
|
+
this.names = names;
|
|
36
|
+
this.seen = new Set();
|
|
37
|
+
}
|
|
38
|
+
fromCheckpoint(checkpoint) {
|
|
39
|
+
const empty = new NamedBarrierValue(this.names);
|
|
40
|
+
if (checkpoint) {
|
|
41
|
+
empty.seen = new Set(checkpoint);
|
|
42
|
+
}
|
|
43
|
+
return empty;
|
|
44
|
+
}
|
|
45
|
+
update(values) {
|
|
46
|
+
// We have seen all nodes, so we can reset the seen set in preparation for the next round of updates.
|
|
47
|
+
if ((0, exports.areSetsEqual)(this.names, this.seen)) {
|
|
48
|
+
this.seen = new Set();
|
|
49
|
+
}
|
|
50
|
+
for (const nodeName of values) {
|
|
51
|
+
if (this.names.has(nodeName)) {
|
|
52
|
+
this.seen.add(nodeName);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
throw new Error(`Value ${JSON.stringify(nodeName)} not in names ${JSON.stringify(this.names)}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// If we have not yet seen all the node names we want to wait for,
|
|
60
|
+
// throw an error to prevent continuing.
|
|
61
|
+
get() {
|
|
62
|
+
if (!(0, exports.areSetsEqual)(this.names, this.seen)) {
|
|
63
|
+
throw new errors_js_1.EmptyChannelError();
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
checkpoint() {
|
|
68
|
+
return [...this.seen];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.NamedBarrierValue = NamedBarrierValue;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BaseChannel } from "./index.js";
|
|
2
|
+
export declare const areSetsEqual: <T>(a: Set<T>, b: Set<T>) => boolean;
|
|
3
|
+
/**
|
|
4
|
+
* A channel that waits until all named values are received before making the value available.
|
|
5
|
+
*
|
|
6
|
+
* This ensures that if node N and node M both write to channel C, the value of C will not be updated
|
|
7
|
+
* until N and M have completed updating.
|
|
8
|
+
*/
|
|
9
|
+
export declare class NamedBarrierValue<Value> extends BaseChannel<void, Value, Value[]> {
|
|
10
|
+
lc_graph_name: string;
|
|
11
|
+
names: Set<Value>;
|
|
12
|
+
seen: Set<Value>;
|
|
13
|
+
constructor(names: Set<Value>);
|
|
14
|
+
fromCheckpoint(checkpoint?: Value[]): this;
|
|
15
|
+
update(values: Value[]): void;
|
|
16
|
+
get(): void;
|
|
17
|
+
checkpoint(): Value[];
|
|
18
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { EmptyChannelError } from "../errors.js";
|
|
2
|
+
import { BaseChannel } from "./index.js";
|
|
3
|
+
export const areSetsEqual = (a, b) => a.size === b.size && [...a].every((value) => b.has(value));
|
|
4
|
+
/**
|
|
5
|
+
* A channel that waits until all named values are received before making the value available.
|
|
6
|
+
*
|
|
7
|
+
* This ensures that if node N and node M both write to channel C, the value of C will not be updated
|
|
8
|
+
* until N and M have completed updating.
|
|
9
|
+
*/
|
|
10
|
+
export class NamedBarrierValue extends BaseChannel {
|
|
11
|
+
constructor(names) {
|
|
12
|
+
super();
|
|
13
|
+
Object.defineProperty(this, "lc_graph_name", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: "NamedBarrierValue"
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(this, "names", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: void 0
|
|
24
|
+
}); // Names of nodes that we want to wait for.
|
|
25
|
+
Object.defineProperty(this, "seen", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: void 0
|
|
30
|
+
});
|
|
31
|
+
this.names = names;
|
|
32
|
+
this.seen = new Set();
|
|
33
|
+
}
|
|
34
|
+
fromCheckpoint(checkpoint) {
|
|
35
|
+
const empty = new NamedBarrierValue(this.names);
|
|
36
|
+
if (checkpoint) {
|
|
37
|
+
empty.seen = new Set(checkpoint);
|
|
38
|
+
}
|
|
39
|
+
return empty;
|
|
40
|
+
}
|
|
41
|
+
update(values) {
|
|
42
|
+
// We have seen all nodes, so we can reset the seen set in preparation for the next round of updates.
|
|
43
|
+
if (areSetsEqual(this.names, this.seen)) {
|
|
44
|
+
this.seen = new Set();
|
|
45
|
+
}
|
|
46
|
+
for (const nodeName of values) {
|
|
47
|
+
if (this.names.has(nodeName)) {
|
|
48
|
+
this.seen.add(nodeName);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
throw new Error(`Value ${JSON.stringify(nodeName)} not in names ${JSON.stringify(this.names)}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// If we have not yet seen all the node names we want to wait for,
|
|
56
|
+
// throw an error to prevent continuing.
|
|
57
|
+
get() {
|
|
58
|
+
if (!areSetsEqual(this.names, this.seen)) {
|
|
59
|
+
throw new EmptyChannelError();
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
checkpoint() {
|
|
64
|
+
return [...this.seen];
|
|
65
|
+
}
|
|
66
|
+
}
|
package/dist/channels/topic.cjs
CHANGED
|
@@ -51,13 +51,15 @@ class Topic extends base_js_1.BaseChannel {
|
|
|
51
51
|
this.seen = new Set();
|
|
52
52
|
this.values = [];
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
fromCheckpoint(checkpoint) {
|
|
55
55
|
const empty = new Topic({
|
|
56
56
|
unique: this.unique,
|
|
57
57
|
accumulate: this.accumulate,
|
|
58
58
|
});
|
|
59
59
|
if (checkpoint) {
|
|
60
|
-
|
|
60
|
+
empty.seen = new Set(checkpoint[0]);
|
|
61
|
+
// eslint-disable-next-line prefer-destructuring
|
|
62
|
+
empty.values = checkpoint[1];
|
|
61
63
|
}
|
|
62
64
|
return empty;
|
|
63
65
|
}
|
|
@@ -84,7 +86,7 @@ class Topic extends base_js_1.BaseChannel {
|
|
|
84
86
|
return this.values;
|
|
85
87
|
}
|
|
86
88
|
checkpoint() {
|
|
87
|
-
return [this.seen, this.values];
|
|
89
|
+
return [[...this.seen], this.values];
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
92
|
exports.Topic = Topic;
|
package/dist/channels/topic.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseChannel } from "./base.js";
|
|
2
2
|
export declare class Topic<Value> extends BaseChannel<Array<Value>, Value | Value[], [
|
|
3
|
-
|
|
3
|
+
Value[],
|
|
4
4
|
Value[]
|
|
5
5
|
]> {
|
|
6
6
|
lc_graph_name: string;
|
|
@@ -12,8 +12,8 @@ export declare class Topic<Value> extends BaseChannel<Array<Value>, Value | Valu
|
|
|
12
12
|
unique?: boolean;
|
|
13
13
|
accumulate?: boolean;
|
|
14
14
|
});
|
|
15
|
-
|
|
15
|
+
fromCheckpoint(checkpoint?: [Value[], Value[]]): this;
|
|
16
16
|
update(values: Array<Value | Value[]>): void;
|
|
17
17
|
get(): Array<Value>;
|
|
18
|
-
checkpoint(): [
|
|
18
|
+
checkpoint(): [Value[], Value[]];
|
|
19
19
|
}
|
package/dist/channels/topic.js
CHANGED
|
@@ -48,13 +48,15 @@ export class Topic extends BaseChannel {
|
|
|
48
48
|
this.seen = new Set();
|
|
49
49
|
this.values = [];
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
fromCheckpoint(checkpoint) {
|
|
52
52
|
const empty = new Topic({
|
|
53
53
|
unique: this.unique,
|
|
54
54
|
accumulate: this.accumulate,
|
|
55
55
|
});
|
|
56
56
|
if (checkpoint) {
|
|
57
|
-
|
|
57
|
+
empty.seen = new Set(checkpoint[0]);
|
|
58
|
+
// eslint-disable-next-line prefer-destructuring
|
|
59
|
+
empty.values = checkpoint[1];
|
|
58
60
|
}
|
|
59
61
|
return empty;
|
|
60
62
|
}
|
|
@@ -81,6 +83,6 @@ export class Topic extends BaseChannel {
|
|
|
81
83
|
return this.values;
|
|
82
84
|
}
|
|
83
85
|
checkpoint() {
|
|
84
|
-
return [this.seen, this.values];
|
|
86
|
+
return [[...this.seen], this.values];
|
|
85
87
|
}
|
|
86
88
|
}
|
package/dist/checkpoint/base.cjs
CHANGED
|
@@ -1,37 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseCheckpointSaver = exports.copyCheckpoint = exports.emptyCheckpoint = void 0;
|
|
3
|
+
exports.BaseCheckpointSaver = exports.copyCheckpoint = exports.emptyCheckpoint = exports.deepCopy = void 0;
|
|
4
|
+
const id_js_1 = require("./id.cjs");
|
|
5
|
+
function deepCopy(obj) {
|
|
6
|
+
if (typeof obj !== "object" || obj === null) {
|
|
7
|
+
return obj;
|
|
8
|
+
}
|
|
9
|
+
const newObj = Array.isArray(obj) ? [] : {};
|
|
10
|
+
for (const key in obj) {
|
|
11
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
12
|
+
newObj[key] = deepCopy(obj[key]);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return newObj;
|
|
16
|
+
}
|
|
17
|
+
exports.deepCopy = deepCopy;
|
|
4
18
|
function emptyCheckpoint() {
|
|
5
19
|
return {
|
|
6
20
|
v: 1,
|
|
21
|
+
id: (0, id_js_1.uuid6)(-2),
|
|
7
22
|
ts: new Date().toISOString(),
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
23
|
+
channel_values: {},
|
|
24
|
+
channel_versions: {},
|
|
25
|
+
versions_seen: {},
|
|
11
26
|
};
|
|
12
27
|
}
|
|
13
28
|
exports.emptyCheckpoint = emptyCheckpoint;
|
|
14
29
|
function copyCheckpoint(checkpoint) {
|
|
15
30
|
return {
|
|
16
31
|
v: checkpoint.v,
|
|
32
|
+
id: checkpoint.id,
|
|
17
33
|
ts: checkpoint.ts,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
34
|
+
channel_values: { ...checkpoint.channel_values },
|
|
35
|
+
channel_versions: { ...checkpoint.channel_versions },
|
|
36
|
+
versions_seen: deepCopy(checkpoint.versions_seen),
|
|
21
37
|
};
|
|
22
38
|
}
|
|
23
39
|
exports.copyCheckpoint = copyCheckpoint;
|
|
24
40
|
class BaseCheckpointSaver {
|
|
25
|
-
constructor() {
|
|
26
|
-
Object.defineProperty(this, "
|
|
41
|
+
constructor(serde) {
|
|
42
|
+
Object.defineProperty(this, "serde", {
|
|
27
43
|
enumerable: true,
|
|
28
44
|
configurable: true,
|
|
29
45
|
writable: true,
|
|
30
|
-
value:
|
|
46
|
+
value: JSON
|
|
31
47
|
});
|
|
48
|
+
this.serde = serde || this.serde;
|
|
32
49
|
}
|
|
33
|
-
get
|
|
34
|
-
|
|
50
|
+
async get(config) {
|
|
51
|
+
const value = await this.getTuple(config);
|
|
52
|
+
return value ? value.checkpoint : undefined;
|
|
35
53
|
}
|
|
36
54
|
}
|
|
37
55
|
exports.BaseCheckpointSaver = BaseCheckpointSaver;
|
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
import { RunnableConfig } from "@langchain/core/runnables";
|
|
2
|
-
|
|
3
|
-
export interface
|
|
4
|
-
|
|
5
|
-
annotation: any;
|
|
6
|
-
name: string | null;
|
|
7
|
-
description: string | null;
|
|
8
|
-
default: any;
|
|
2
|
+
import { SerializerProtocol } from "../serde/base.js";
|
|
3
|
+
export interface CheckpointMetadata {
|
|
4
|
+
source: "input" | "loop" | "update";
|
|
9
5
|
/**
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
* The source of the checkpoint.
|
|
7
|
+
* - "input": The checkpoint was created from an input to invoke/stream/batch.
|
|
8
|
+
* - "loop": The checkpoint was created from inside the pregel loop.
|
|
9
|
+
* - "update": The checkpoint was created from a manual state update. */
|
|
10
|
+
step: number;
|
|
11
|
+
/**
|
|
12
|
+
* The step number of the checkpoint.
|
|
13
|
+
* -1 for the first "input" checkpoint.
|
|
14
|
+
* 0 for the first "loop" checkpoint.
|
|
15
|
+
* ... for the nth checkpoint afterwards. */
|
|
16
|
+
writes?: Record<string, unknown>;
|
|
14
17
|
}
|
|
15
18
|
export interface Checkpoint {
|
|
16
19
|
/**
|
|
17
20
|
* Version number
|
|
18
21
|
*/
|
|
19
22
|
v: number;
|
|
23
|
+
/**
|
|
24
|
+
* Checkpoint ID {uuid6}
|
|
25
|
+
*/
|
|
26
|
+
id: string;
|
|
20
27
|
/**
|
|
21
28
|
* Timestamp {new Date().toISOString()}
|
|
22
29
|
*/
|
|
@@ -24,25 +31,35 @@ export interface Checkpoint {
|
|
|
24
31
|
/**
|
|
25
32
|
* @default {}
|
|
26
33
|
*/
|
|
27
|
-
|
|
34
|
+
channel_values: Record<string, unknown>;
|
|
28
35
|
/**
|
|
29
36
|
* @default {}
|
|
30
37
|
*/
|
|
31
|
-
|
|
38
|
+
channel_versions: Record<string, number>;
|
|
32
39
|
/**
|
|
33
40
|
* @default {}
|
|
34
41
|
*/
|
|
35
|
-
|
|
42
|
+
versions_seen: Record<string, Record<string, number>>;
|
|
43
|
+
}
|
|
44
|
+
export interface ReadonlyCheckpoint extends Readonly<Checkpoint> {
|
|
45
|
+
readonly channel_values: Readonly<Record<string, unknown>>;
|
|
46
|
+
readonly channel_versions: Readonly<Record<string, number>>;
|
|
47
|
+
readonly versions_seen: Readonly<Record<string, Readonly<Record<string, number>>>>;
|
|
36
48
|
}
|
|
49
|
+
export declare function deepCopy<T>(obj: T): T;
|
|
37
50
|
export declare function emptyCheckpoint(): Checkpoint;
|
|
38
|
-
export declare function copyCheckpoint(checkpoint:
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
|
|
51
|
+
export declare function copyCheckpoint(checkpoint: ReadonlyCheckpoint): Checkpoint;
|
|
52
|
+
export interface CheckpointTuple {
|
|
53
|
+
config: RunnableConfig;
|
|
54
|
+
checkpoint: Checkpoint;
|
|
55
|
+
metadata?: CheckpointMetadata;
|
|
56
|
+
parentConfig?: RunnableConfig;
|
|
42
57
|
}
|
|
43
58
|
export declare abstract class BaseCheckpointSaver {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
abstract
|
|
59
|
+
serde: SerializerProtocol<unknown>;
|
|
60
|
+
constructor(serde?: SerializerProtocol<unknown>);
|
|
61
|
+
get(config: RunnableConfig): Promise<Checkpoint | undefined>;
|
|
62
|
+
abstract getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;
|
|
63
|
+
abstract list(config: RunnableConfig, limit?: number, before?: RunnableConfig): AsyncGenerator<CheckpointTuple>;
|
|
64
|
+
abstract put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata): Promise<RunnableConfig>;
|
|
48
65
|
}
|
package/dist/checkpoint/base.js
CHANGED
|
@@ -1,31 +1,48 @@
|
|
|
1
|
+
import { uuid6 } from "./id.js";
|
|
2
|
+
export function deepCopy(obj) {
|
|
3
|
+
if (typeof obj !== "object" || obj === null) {
|
|
4
|
+
return obj;
|
|
5
|
+
}
|
|
6
|
+
const newObj = Array.isArray(obj) ? [] : {};
|
|
7
|
+
for (const key in obj) {
|
|
8
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
9
|
+
newObj[key] = deepCopy(obj[key]);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return newObj;
|
|
13
|
+
}
|
|
1
14
|
export function emptyCheckpoint() {
|
|
2
15
|
return {
|
|
3
16
|
v: 1,
|
|
17
|
+
id: uuid6(-2),
|
|
4
18
|
ts: new Date().toISOString(),
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
19
|
+
channel_values: {},
|
|
20
|
+
channel_versions: {},
|
|
21
|
+
versions_seen: {},
|
|
8
22
|
};
|
|
9
23
|
}
|
|
10
24
|
export function copyCheckpoint(checkpoint) {
|
|
11
25
|
return {
|
|
12
26
|
v: checkpoint.v,
|
|
27
|
+
id: checkpoint.id,
|
|
13
28
|
ts: checkpoint.ts,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
29
|
+
channel_values: { ...checkpoint.channel_values },
|
|
30
|
+
channel_versions: { ...checkpoint.channel_versions },
|
|
31
|
+
versions_seen: deepCopy(checkpoint.versions_seen),
|
|
17
32
|
};
|
|
18
33
|
}
|
|
19
34
|
export class BaseCheckpointSaver {
|
|
20
|
-
constructor() {
|
|
21
|
-
Object.defineProperty(this, "
|
|
35
|
+
constructor(serde) {
|
|
36
|
+
Object.defineProperty(this, "serde", {
|
|
22
37
|
enumerable: true,
|
|
23
38
|
configurable: true,
|
|
24
39
|
writable: true,
|
|
25
|
-
value:
|
|
40
|
+
value: JSON
|
|
26
41
|
});
|
|
42
|
+
this.serde = serde || this.serde;
|
|
27
43
|
}
|
|
28
|
-
get
|
|
29
|
-
|
|
44
|
+
async get(config) {
|
|
45
|
+
const value = await this.getTuple(config);
|
|
46
|
+
return value ? value.checkpoint : undefined;
|
|
30
47
|
}
|
|
31
48
|
}
|