@langchain/langgraph 0.2.8 → 0.2.10-rc.0
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 +11 -2
- package/dist/constants.d.ts +6 -1
- package/dist/constants.js +10 -1
- package/dist/errors.cjs +5 -4
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +5 -4
- package/dist/graph/graph.cjs +7 -2
- package/dist/graph/graph.js +8 -3
- package/dist/graph/message.cjs +2 -0
- package/dist/graph/message.js +2 -0
- package/dist/graph/state.cjs +8 -3
- package/dist/graph/state.d.ts +2 -3
- package/dist/graph/state.js +9 -4
- package/dist/managed/shared_value.cjs +12 -10
- package/dist/managed/shared_value.d.ts +6 -5
- package/dist/managed/shared_value.js +12 -10
- package/dist/pregel/algo.cjs +124 -54
- package/dist/pregel/algo.d.ts +13 -3
- package/dist/pregel/algo.js +122 -53
- package/dist/pregel/debug.cjs +15 -18
- package/dist/pregel/debug.d.ts +3 -2
- package/dist/pregel/debug.js +16 -19
- package/dist/pregel/index.cjs +307 -116
- package/dist/pregel/index.d.ts +21 -6
- package/dist/pregel/index.js +305 -117
- package/dist/pregel/io.cjs +15 -8
- package/dist/pregel/io.d.ts +2 -2
- package/dist/pregel/io.js +15 -8
- package/dist/pregel/loop.cjs +258 -113
- package/dist/pregel/loop.d.ts +24 -9
- package/dist/pregel/loop.js +258 -111
- package/dist/pregel/read.cjs +9 -2
- package/dist/pregel/read.d.ts +3 -2
- package/dist/pregel/read.js +9 -2
- package/dist/pregel/retry.d.ts +1 -1
- package/dist/pregel/runnable_types.cjs +2 -0
- package/dist/pregel/runnable_types.d.ts +5 -0
- package/dist/pregel/runnable_types.js +1 -0
- package/dist/pregel/types.d.ts +8 -4
- package/dist/pregel/utils/config.cjs +73 -0
- package/dist/pregel/utils/config.d.ts +3 -0
- package/dist/pregel/utils/config.js +69 -0
- package/dist/pregel/{utils.cjs → utils/index.cjs} +33 -10
- package/dist/pregel/{utils.d.ts → utils/index.d.ts} +4 -7
- package/dist/pregel/{utils.js → utils/index.js} +30 -8
- package/dist/utils.cjs +5 -3
- package/dist/utils.js +5 -3
- package/dist/web.cjs +4 -2
- package/dist/web.d.ts +4 -3
- package/dist/web.js +1 -2
- package/package.json +1 -1
- package/dist/store/base.cjs +0 -12
- package/dist/store/base.d.ts +0 -7
- package/dist/store/base.js +0 -8
- package/dist/store/batch.cjs +0 -126
- package/dist/store/batch.d.ts +0 -55
- package/dist/store/batch.js +0 -122
- package/dist/store/index.cjs +0 -19
- package/dist/store/index.d.ts +0 -3
- package/dist/store/index.js +0 -3
- package/dist/store/memory.cjs +0 -43
- package/dist/store/memory.d.ts +0 -6
- package/dist/store/memory.js +0 -39
package/dist/constants.cjs
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._isSend = exports.Send = exports._isSendInterface = exports.CHECKPOINT_NAMESPACE_SEPARATOR = exports.RESERVED = exports.TASK_NAMESPACE = exports.TASKS = exports.TAG_HIDDEN = exports.RECURSION_LIMIT_DEFAULT = exports.RUNTIME_PLACEHOLDER = exports.
|
|
3
|
+
exports._isSend = exports.Send = exports._isSendInterface = exports.CHECKPOINT_NAMESPACE_END = exports.CHECKPOINT_NAMESPACE_SEPARATOR = exports.RESERVED = exports.TASK_NAMESPACE = exports.PULL = exports.PUSH = exports.TASKS = exports.TAG_HIDDEN = exports.RECURSION_LIMIT_DEFAULT = exports.RUNTIME_PLACEHOLDER = exports.INTERRUPT = exports.CONFIG_KEY_CHECKPOINT_MAP = exports.CONFIG_KEY_STREAM = exports.CONFIG_KEY_TASK_ID = exports.CONFIG_KEY_RESUMING = exports.CONFIG_KEY_CHECKPOINTER = exports.CONFIG_KEY_READ = exports.CONFIG_KEY_SEND = exports.ERROR = exports.INPUT = void 0;
|
|
4
4
|
exports.INPUT = "__input__";
|
|
5
5
|
exports.ERROR = "__error__";
|
|
6
6
|
exports.CONFIG_KEY_SEND = "__pregel_send";
|
|
7
7
|
exports.CONFIG_KEY_READ = "__pregel_read";
|
|
8
8
|
exports.CONFIG_KEY_CHECKPOINTER = "__pregel_checkpointer";
|
|
9
9
|
exports.CONFIG_KEY_RESUMING = "__pregel_resuming";
|
|
10
|
+
exports.CONFIG_KEY_TASK_ID = "__pregel_task_id";
|
|
11
|
+
exports.CONFIG_KEY_STREAM = "__pregel_stream";
|
|
12
|
+
// this one is part of public API
|
|
13
|
+
exports.CONFIG_KEY_CHECKPOINT_MAP = "checkpoint_map";
|
|
10
14
|
exports.INTERRUPT = "__interrupt__";
|
|
11
|
-
exports.CONFIG_KEY_STORE = "__pregel_store";
|
|
12
15
|
exports.RUNTIME_PLACEHOLDER = "__pregel_runtime_placeholder__";
|
|
13
16
|
exports.RECURSION_LIMIT_DEFAULT = 25;
|
|
14
17
|
exports.TAG_HIDDEN = "langsmith:hidden";
|
|
15
18
|
exports.TASKS = "__pregel_tasks";
|
|
19
|
+
exports.PUSH = "__pregel_push";
|
|
20
|
+
exports.PULL = "__pregel_pull";
|
|
16
21
|
exports.TASK_NAMESPACE = "6ba7b831-9dad-11d1-80b4-00c04fd430c8";
|
|
17
22
|
exports.RESERVED = [
|
|
18
23
|
exports.INTERRUPT,
|
|
@@ -22,9 +27,13 @@ exports.RESERVED = [
|
|
|
22
27
|
exports.CONFIG_KEY_READ,
|
|
23
28
|
exports.CONFIG_KEY_CHECKPOINTER,
|
|
24
29
|
exports.CONFIG_KEY_RESUMING,
|
|
30
|
+
exports.CONFIG_KEY_TASK_ID,
|
|
31
|
+
exports.CONFIG_KEY_STREAM,
|
|
32
|
+
exports.CONFIG_KEY_CHECKPOINT_MAP,
|
|
25
33
|
exports.INPUT,
|
|
26
34
|
];
|
|
27
35
|
exports.CHECKPOINT_NAMESPACE_SEPARATOR = "|";
|
|
36
|
+
exports.CHECKPOINT_NAMESPACE_END = ":";
|
|
28
37
|
function _isSendInterface(x) {
|
|
29
38
|
const operation = x;
|
|
30
39
|
return typeof operation.node === "string" && operation.args !== undefined;
|
package/dist/constants.d.ts
CHANGED
|
@@ -4,15 +4,20 @@ export declare const CONFIG_KEY_SEND = "__pregel_send";
|
|
|
4
4
|
export declare const CONFIG_KEY_READ = "__pregel_read";
|
|
5
5
|
export declare const CONFIG_KEY_CHECKPOINTER = "__pregel_checkpointer";
|
|
6
6
|
export declare const CONFIG_KEY_RESUMING = "__pregel_resuming";
|
|
7
|
+
export declare const CONFIG_KEY_TASK_ID = "__pregel_task_id";
|
|
8
|
+
export declare const CONFIG_KEY_STREAM = "__pregel_stream";
|
|
9
|
+
export declare const CONFIG_KEY_CHECKPOINT_MAP = "checkpoint_map";
|
|
7
10
|
export declare const INTERRUPT = "__interrupt__";
|
|
8
|
-
export declare const CONFIG_KEY_STORE = "__pregel_store";
|
|
9
11
|
export declare const RUNTIME_PLACEHOLDER = "__pregel_runtime_placeholder__";
|
|
10
12
|
export declare const RECURSION_LIMIT_DEFAULT = 25;
|
|
11
13
|
export declare const TAG_HIDDEN = "langsmith:hidden";
|
|
12
14
|
export declare const TASKS = "__pregel_tasks";
|
|
15
|
+
export declare const PUSH = "__pregel_push";
|
|
16
|
+
export declare const PULL = "__pregel_pull";
|
|
13
17
|
export declare const TASK_NAMESPACE = "6ba7b831-9dad-11d1-80b4-00c04fd430c8";
|
|
14
18
|
export declare const RESERVED: string[];
|
|
15
19
|
export declare const CHECKPOINT_NAMESPACE_SEPARATOR = "|";
|
|
20
|
+
export declare const CHECKPOINT_NAMESPACE_END = ":";
|
|
16
21
|
export interface SendInterface {
|
|
17
22
|
node: string;
|
|
18
23
|
args: any;
|
package/dist/constants.js
CHANGED
|
@@ -4,12 +4,17 @@ export const CONFIG_KEY_SEND = "__pregel_send";
|
|
|
4
4
|
export const CONFIG_KEY_READ = "__pregel_read";
|
|
5
5
|
export const CONFIG_KEY_CHECKPOINTER = "__pregel_checkpointer";
|
|
6
6
|
export const CONFIG_KEY_RESUMING = "__pregel_resuming";
|
|
7
|
+
export const CONFIG_KEY_TASK_ID = "__pregel_task_id";
|
|
8
|
+
export const CONFIG_KEY_STREAM = "__pregel_stream";
|
|
9
|
+
// this one is part of public API
|
|
10
|
+
export const CONFIG_KEY_CHECKPOINT_MAP = "checkpoint_map";
|
|
7
11
|
export const INTERRUPT = "__interrupt__";
|
|
8
|
-
export const CONFIG_KEY_STORE = "__pregel_store";
|
|
9
12
|
export const RUNTIME_PLACEHOLDER = "__pregel_runtime_placeholder__";
|
|
10
13
|
export const RECURSION_LIMIT_DEFAULT = 25;
|
|
11
14
|
export const TAG_HIDDEN = "langsmith:hidden";
|
|
12
15
|
export const TASKS = "__pregel_tasks";
|
|
16
|
+
export const PUSH = "__pregel_push";
|
|
17
|
+
export const PULL = "__pregel_pull";
|
|
13
18
|
export const TASK_NAMESPACE = "6ba7b831-9dad-11d1-80b4-00c04fd430c8";
|
|
14
19
|
export const RESERVED = [
|
|
15
20
|
INTERRUPT,
|
|
@@ -19,9 +24,13 @@ export const RESERVED = [
|
|
|
19
24
|
CONFIG_KEY_READ,
|
|
20
25
|
CONFIG_KEY_CHECKPOINTER,
|
|
21
26
|
CONFIG_KEY_RESUMING,
|
|
27
|
+
CONFIG_KEY_TASK_ID,
|
|
28
|
+
CONFIG_KEY_STREAM,
|
|
29
|
+
CONFIG_KEY_CHECKPOINT_MAP,
|
|
22
30
|
INPUT,
|
|
23
31
|
];
|
|
24
32
|
export const CHECKPOINT_NAMESPACE_SEPARATOR = "|";
|
|
33
|
+
export const CHECKPOINT_NAMESPACE_END = ":";
|
|
25
34
|
export function _isSendInterface(x) {
|
|
26
35
|
const operation = x;
|
|
27
36
|
return typeof operation.node === "string" && operation.args !== undefined;
|
package/dist/errors.cjs
CHANGED
|
@@ -55,10 +55,11 @@ class NodeInterrupt extends GraphInterrupt {
|
|
|
55
55
|
}
|
|
56
56
|
exports.NodeInterrupt = NodeInterrupt;
|
|
57
57
|
function isGraphInterrupt(e) {
|
|
58
|
-
return
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
return (e !== undefined &&
|
|
59
|
+
[
|
|
60
|
+
GraphInterrupt.unminifiable_name,
|
|
61
|
+
NodeInterrupt.unminifiable_name,
|
|
62
|
+
].includes(e.name));
|
|
62
63
|
}
|
|
63
64
|
exports.isGraphInterrupt = isGraphInterrupt;
|
|
64
65
|
class EmptyInputError extends Error {
|
package/dist/errors.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare class NodeInterrupt extends GraphInterrupt {
|
|
|
17
17
|
constructor(message: string);
|
|
18
18
|
static get unminifiable_name(): string;
|
|
19
19
|
}
|
|
20
|
-
export declare function isGraphInterrupt(e
|
|
20
|
+
export declare function isGraphInterrupt(e?: GraphInterrupt | Error): e is GraphInterrupt;
|
|
21
21
|
export declare class EmptyInputError extends Error {
|
|
22
22
|
constructor(message?: string);
|
|
23
23
|
static get unminifiable_name(): string;
|
package/dist/errors.js
CHANGED
|
@@ -48,10 +48,11 @@ export class NodeInterrupt extends GraphInterrupt {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
export function isGraphInterrupt(e) {
|
|
51
|
-
return
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
return (e !== undefined &&
|
|
52
|
+
[
|
|
53
|
+
GraphInterrupt.unminifiable_name,
|
|
54
|
+
NodeInterrupt.unminifiable_name,
|
|
55
|
+
].includes(e.name));
|
|
55
56
|
}
|
|
56
57
|
export class EmptyInputError extends Error {
|
|
57
58
|
constructor(message) {
|
package/dist/graph/graph.cjs
CHANGED
|
@@ -123,8 +123,13 @@ class Graph {
|
|
|
123
123
|
return this.edges;
|
|
124
124
|
}
|
|
125
125
|
addNode(key, action, options) {
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
for (const reservedChar of [
|
|
127
|
+
constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR,
|
|
128
|
+
constants_js_1.CHECKPOINT_NAMESPACE_END,
|
|
129
|
+
]) {
|
|
130
|
+
if (key.includes(reservedChar)) {
|
|
131
|
+
throw new Error(`"${reservedChar}" is a reserved character and is not allowed in node names.`);
|
|
132
|
+
}
|
|
128
133
|
}
|
|
129
134
|
this.warnIfCompiled(`Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
|
|
130
135
|
if (key in this.nodes) {
|
package/dist/graph/graph.js
CHANGED
|
@@ -6,7 +6,7 @@ import { PregelNode } from "../pregel/read.js";
|
|
|
6
6
|
import { Channel, Pregel } from "../pregel/index.js";
|
|
7
7
|
import { EphemeralValue } from "../channels/ephemeral_value.js";
|
|
8
8
|
import { ChannelWrite, PASSTHROUGH } from "../pregel/write.js";
|
|
9
|
-
import { _isSend, CHECKPOINT_NAMESPACE_SEPARATOR, TAG_HIDDEN, } from "../constants.js";
|
|
9
|
+
import { _isSend, CHECKPOINT_NAMESPACE_END, CHECKPOINT_NAMESPACE_SEPARATOR, TAG_HIDDEN, } from "../constants.js";
|
|
10
10
|
import { RunnableCallable } from "../utils.js";
|
|
11
11
|
import { InvalidUpdateError, NodeInterrupt } from "../errors.js";
|
|
12
12
|
/** Special reserved node name denoting the start of a graph. */
|
|
@@ -119,8 +119,13 @@ export class Graph {
|
|
|
119
119
|
return this.edges;
|
|
120
120
|
}
|
|
121
121
|
addNode(key, action, options) {
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
for (const reservedChar of [
|
|
123
|
+
CHECKPOINT_NAMESPACE_SEPARATOR,
|
|
124
|
+
CHECKPOINT_NAMESPACE_END,
|
|
125
|
+
]) {
|
|
126
|
+
if (key.includes(reservedChar)) {
|
|
127
|
+
throw new Error(`"${reservedChar}" is a reserved character and is not allowed in node names.`);
|
|
128
|
+
}
|
|
124
129
|
}
|
|
125
130
|
this.warnIfCompiled(`Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
|
|
126
131
|
if (key in this.nodes) {
|
package/dist/graph/message.cjs
CHANGED
|
@@ -19,11 +19,13 @@ function messagesStateReducer(left, right) {
|
|
|
19
19
|
for (const m of leftMessages) {
|
|
20
20
|
if (m.id === null || m.id === undefined) {
|
|
21
21
|
m.id = (0, uuid_1.v4)();
|
|
22
|
+
m.lc_kwargs.id = m.id;
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
for (const m of rightMessages) {
|
|
25
26
|
if (m.id === null || m.id === undefined) {
|
|
26
27
|
m.id = (0, uuid_1.v4)();
|
|
28
|
+
m.lc_kwargs.id = m.id;
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
// merge
|
package/dist/graph/message.js
CHANGED
|
@@ -16,11 +16,13 @@ export function messagesStateReducer(left, right) {
|
|
|
16
16
|
for (const m of leftMessages) {
|
|
17
17
|
if (m.id === null || m.id === undefined) {
|
|
18
18
|
m.id = v4();
|
|
19
|
+
m.lc_kwargs.id = m.id;
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
for (const m of rightMessages) {
|
|
22
23
|
if (m.id === null || m.id === undefined) {
|
|
23
24
|
m.id = v4();
|
|
25
|
+
m.lc_kwargs.id = m.id;
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
// merge
|
package/dist/graph/state.cjs
CHANGED
|
@@ -198,8 +198,13 @@ class StateGraph extends graph_js_1.Graph {
|
|
|
198
198
|
if (key in this.channels) {
|
|
199
199
|
throw new Error(`${key} is already being used as a state attribute (a.k.a. a channel), cannot also be used as a node name.`);
|
|
200
200
|
}
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
for (const reservedChar of [
|
|
202
|
+
constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR,
|
|
203
|
+
constants_js_1.CHECKPOINT_NAMESPACE_END,
|
|
204
|
+
]) {
|
|
205
|
+
if (key.includes(reservedChar)) {
|
|
206
|
+
throw new Error(`"${reservedChar}" is a reserved character and is not allowed in node names.`);
|
|
207
|
+
}
|
|
203
208
|
}
|
|
204
209
|
this.warnIfCompiled(`Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
|
|
205
210
|
if (key in this.nodes) {
|
|
@@ -385,7 +390,7 @@ class CompiledStateGraph extends graph_js_1.CompiledGraph {
|
|
|
385
390
|
}
|
|
386
391
|
}
|
|
387
392
|
else if (start === graph_js_1.START) {
|
|
388
|
-
const channelName =
|
|
393
|
+
const channelName = `${graph_js_1.START}:${end}`;
|
|
389
394
|
// register channel
|
|
390
395
|
this.channels[channelName] =
|
|
391
396
|
new ephemeral_value_js_1.EphemeralValue();
|
package/dist/graph/state.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { RunnableLike } from "@langchain/core/runnables";
|
|
2
|
-
import { All, BaseCheckpointSaver } from "@langchain/langgraph-checkpoint";
|
|
2
|
+
import { All, BaseCheckpointSaver, BaseStore } from "@langchain/langgraph-checkpoint";
|
|
3
3
|
import { BaseChannel } from "../channels/base.js";
|
|
4
4
|
import { END, CompiledGraph, Graph, START, Branch, AddNodeOptions, NodeSpec } from "./graph.js";
|
|
5
5
|
import { AnnotationRoot, SingleReducer, StateDefinition, StateType, UpdateType } from "./annotation.js";
|
|
6
|
-
import type { RetryPolicy } from "../pregel/utils.js";
|
|
7
|
-
import { BaseStore } from "../store/base.js";
|
|
6
|
+
import type { RetryPolicy } from "../pregel/utils/index.js";
|
|
8
7
|
import { ManagedValueSpec } from "../managed/base.js";
|
|
9
8
|
export type ChannelReducers<Channels extends object> = {
|
|
10
9
|
[K in keyof Channels]: SingleReducer<Channels[K], any>;
|
package/dist/graph/state.js
CHANGED
|
@@ -7,7 +7,7 @@ import { ChannelRead, PregelNode } from "../pregel/read.js";
|
|
|
7
7
|
import { NamedBarrierValue } from "../channels/named_barrier_value.js";
|
|
8
8
|
import { EphemeralValue } from "../channels/ephemeral_value.js";
|
|
9
9
|
import { RunnableCallable } from "../utils.js";
|
|
10
|
-
import { _isSend, CHECKPOINT_NAMESPACE_SEPARATOR, TAG_HIDDEN, } from "../constants.js";
|
|
10
|
+
import { _isSend, CHECKPOINT_NAMESPACE_END, CHECKPOINT_NAMESPACE_SEPARATOR, TAG_HIDDEN, } from "../constants.js";
|
|
11
11
|
import { InvalidUpdateError } from "../errors.js";
|
|
12
12
|
import { getChannel, } from "./annotation.js";
|
|
13
13
|
import { isConfiguredManagedValue } from "../managed/base.js";
|
|
@@ -195,8 +195,13 @@ export class StateGraph extends Graph {
|
|
|
195
195
|
if (key in this.channels) {
|
|
196
196
|
throw new Error(`${key} is already being used as a state attribute (a.k.a. a channel), cannot also be used as a node name.`);
|
|
197
197
|
}
|
|
198
|
-
|
|
199
|
-
|
|
198
|
+
for (const reservedChar of [
|
|
199
|
+
CHECKPOINT_NAMESPACE_SEPARATOR,
|
|
200
|
+
CHECKPOINT_NAMESPACE_END,
|
|
201
|
+
]) {
|
|
202
|
+
if (key.includes(reservedChar)) {
|
|
203
|
+
throw new Error(`"${reservedChar}" is a reserved character and is not allowed in node names.`);
|
|
204
|
+
}
|
|
200
205
|
}
|
|
201
206
|
this.warnIfCompiled(`Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`);
|
|
202
207
|
if (key in this.nodes) {
|
|
@@ -381,7 +386,7 @@ export class CompiledStateGraph extends CompiledGraph {
|
|
|
381
386
|
}
|
|
382
387
|
}
|
|
383
388
|
else if (start === START) {
|
|
384
|
-
const channelName =
|
|
389
|
+
const channelName = `${START}:${end}`;
|
|
385
390
|
// register channel
|
|
386
391
|
this.channels[channelName] =
|
|
387
392
|
new EphemeralValue();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.SharedValue = void 0;
|
|
4
5
|
const base_js_1 = require("./base.cjs");
|
|
5
|
-
const constants_js_1 = require("../constants.cjs");
|
|
6
6
|
const errors_js_1 = require("../errors.cjs");
|
|
7
7
|
class SharedValue extends base_js_1.WritableManagedValue {
|
|
8
8
|
constructor(config, params) {
|
|
@@ -32,7 +32,7 @@ class SharedValue extends base_js_1.WritableManagedValue {
|
|
|
32
32
|
value: {}
|
|
33
33
|
});
|
|
34
34
|
this.scope = params.scope;
|
|
35
|
-
this.store = config.
|
|
35
|
+
this.store = config.store || null;
|
|
36
36
|
if (!this.store) {
|
|
37
37
|
this.ns = null;
|
|
38
38
|
}
|
|
@@ -41,13 +41,12 @@ class SharedValue extends base_js_1.WritableManagedValue {
|
|
|
41
41
|
const scopedValueString = typeof scopeValue === "string"
|
|
42
42
|
? scopeValue
|
|
43
43
|
: JSON.stringify(scopeValue);
|
|
44
|
-
this.ns =
|
|
44
|
+
this.ns = ["scoped", this.scope, params.key, scopedValueString];
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
|
-
throw new Error(`
|
|
47
|
+
throw new Error(`Required scope "${this.scope}" for shared state key was not passed in "config.configurable".`);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
50
|
static async initialize(config, args) {
|
|
52
51
|
const instance = new this(config, args);
|
|
53
52
|
await instance.loadStore();
|
|
@@ -73,7 +72,7 @@ class SharedValue extends base_js_1.WritableManagedValue {
|
|
|
73
72
|
if (k in this.value) {
|
|
74
73
|
delete this.value[k];
|
|
75
74
|
if (this.ns) {
|
|
76
|
-
writes.push(
|
|
75
|
+
writes.push({ namespace: this.ns, id: k, value: null });
|
|
77
76
|
}
|
|
78
77
|
}
|
|
79
78
|
}
|
|
@@ -83,7 +82,7 @@ class SharedValue extends base_js_1.WritableManagedValue {
|
|
|
83
82
|
else {
|
|
84
83
|
this.value[k] = v;
|
|
85
84
|
if (this.ns) {
|
|
86
|
-
writes.push(
|
|
85
|
+
writes.push({ namespace: this.ns, id: k, value: v });
|
|
87
86
|
}
|
|
88
87
|
}
|
|
89
88
|
}
|
|
@@ -95,13 +94,16 @@ class SharedValue extends base_js_1.WritableManagedValue {
|
|
|
95
94
|
this.processUpdate(values);
|
|
96
95
|
}
|
|
97
96
|
else {
|
|
98
|
-
await this.store.
|
|
97
|
+
await this.store.batch(this.processUpdate(values));
|
|
99
98
|
}
|
|
100
99
|
}
|
|
101
100
|
async loadStore() {
|
|
102
101
|
if (this.store && this.ns) {
|
|
103
|
-
const saved = await this.store.
|
|
104
|
-
this.value = saved
|
|
102
|
+
const saved = await this.store.search(this.ns);
|
|
103
|
+
this.value = saved.reduce((acc, item) => {
|
|
104
|
+
acc[item.id] = item.value;
|
|
105
|
+
return acc;
|
|
106
|
+
}, {});
|
|
105
107
|
}
|
|
106
108
|
return false;
|
|
107
109
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { RunnableConfig } from "@langchain/core/runnables";
|
|
2
|
-
import { BaseStore
|
|
2
|
+
import { BaseStore } from "@langchain/langgraph-checkpoint";
|
|
3
3
|
import { ConfiguredManagedValue, ManagedValue, ManagedValueParams, WritableManagedValue } from "./base.js";
|
|
4
|
-
|
|
5
|
-
type
|
|
4
|
+
import { LangGraphRunnableConfig } from "../pregel/runnable_types.js";
|
|
5
|
+
type Value = Record<string, Record<string, any>>;
|
|
6
|
+
type Update = Record<string, Record<string, any> | null>;
|
|
6
7
|
export interface SharedValueParams extends ManagedValueParams {
|
|
7
8
|
scope: string;
|
|
8
9
|
key: string;
|
|
@@ -10,9 +11,9 @@ export interface SharedValueParams extends ManagedValueParams {
|
|
|
10
11
|
export declare class SharedValue extends WritableManagedValue<Value, Update> {
|
|
11
12
|
scope: string;
|
|
12
13
|
store: BaseStore | null;
|
|
13
|
-
ns: string | null;
|
|
14
|
+
ns: ["scoped", string, string, any] | null;
|
|
14
15
|
value: Value;
|
|
15
|
-
constructor(config:
|
|
16
|
+
constructor(config: LangGraphRunnableConfig, params: SharedValueParams);
|
|
16
17
|
static initialize<Value = any>(config: RunnableConfig, args: SharedValueParams): Promise<ManagedValue<Value>>;
|
|
17
18
|
static on(scope: string): ConfiguredManagedValue<Value>;
|
|
18
19
|
call(_step: number): Value;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
import { ChannelKeyPlaceholder, WritableManagedValue, } from "./base.js";
|
|
2
|
-
import { CONFIG_KEY_STORE } from "../constants.js";
|
|
3
3
|
import { InvalidUpdateError } from "../errors.js";
|
|
4
4
|
export class SharedValue extends WritableManagedValue {
|
|
5
5
|
constructor(config, params) {
|
|
@@ -29,7 +29,7 @@ export class SharedValue extends WritableManagedValue {
|
|
|
29
29
|
value: {}
|
|
30
30
|
});
|
|
31
31
|
this.scope = params.scope;
|
|
32
|
-
this.store = config.
|
|
32
|
+
this.store = config.store || null;
|
|
33
33
|
if (!this.store) {
|
|
34
34
|
this.ns = null;
|
|
35
35
|
}
|
|
@@ -38,13 +38,12 @@ export class SharedValue extends WritableManagedValue {
|
|
|
38
38
|
const scopedValueString = typeof scopeValue === "string"
|
|
39
39
|
? scopeValue
|
|
40
40
|
: JSON.stringify(scopeValue);
|
|
41
|
-
this.ns =
|
|
41
|
+
this.ns = ["scoped", this.scope, params.key, scopedValueString];
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
|
-
throw new Error(`
|
|
44
|
+
throw new Error(`Required scope "${this.scope}" for shared state key was not passed in "config.configurable".`);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
47
|
static async initialize(config, args) {
|
|
49
48
|
const instance = new this(config, args);
|
|
50
49
|
await instance.loadStore();
|
|
@@ -70,7 +69,7 @@ export class SharedValue extends WritableManagedValue {
|
|
|
70
69
|
if (k in this.value) {
|
|
71
70
|
delete this.value[k];
|
|
72
71
|
if (this.ns) {
|
|
73
|
-
writes.push(
|
|
72
|
+
writes.push({ namespace: this.ns, id: k, value: null });
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
75
|
}
|
|
@@ -80,7 +79,7 @@ export class SharedValue extends WritableManagedValue {
|
|
|
80
79
|
else {
|
|
81
80
|
this.value[k] = v;
|
|
82
81
|
if (this.ns) {
|
|
83
|
-
writes.push(
|
|
82
|
+
writes.push({ namespace: this.ns, id: k, value: v });
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
85
|
}
|
|
@@ -92,13 +91,16 @@ export class SharedValue extends WritableManagedValue {
|
|
|
92
91
|
this.processUpdate(values);
|
|
93
92
|
}
|
|
94
93
|
else {
|
|
95
|
-
await this.store.
|
|
94
|
+
await this.store.batch(this.processUpdate(values));
|
|
96
95
|
}
|
|
97
96
|
}
|
|
98
97
|
async loadStore() {
|
|
99
98
|
if (this.store && this.ns) {
|
|
100
|
-
const saved = await this.store.
|
|
101
|
-
this.value = saved
|
|
99
|
+
const saved = await this.store.search(this.ns);
|
|
100
|
+
this.value = saved.reduce((acc, item) => {
|
|
101
|
+
acc[item.id] = item.value;
|
|
102
|
+
return acc;
|
|
103
|
+
}, {});
|
|
102
104
|
}
|
|
103
105
|
return false;
|
|
104
106
|
}
|