@langchain/langgraph 0.2.7 → 0.2.9
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 +12 -2
- package/dist/constants.d.ts +7 -1
- package/dist/constants.js +11 -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 +9 -7
- package/dist/graph/state.d.ts +2 -2
- package/dist/graph/state.js +10 -8
- package/dist/managed/shared_value.cjs +1 -1
- package/dist/managed/shared_value.js +1 -1
- package/dist/pregel/algo.cjs +119 -54
- package/dist/pregel/algo.d.ts +5 -2
- package/dist/pregel/algo.js +117 -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 +295 -123
- package/dist/pregel/index.d.ts +16 -5
- package/dist/pregel/index.js +292 -123
- 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 +256 -111
- package/dist/pregel/loop.d.ts +21 -5
- package/dist/pregel/loop.js +256 -109
- package/dist/pregel/read.cjs +9 -2
- package/dist/pregel/read.d.ts +2 -1
- package/dist/pregel/read.js +9 -2
- package/dist/pregel/retry.d.ts +1 -1
- package/dist/pregel/types.d.ts +5 -2
- package/dist/pregel/utils/config.cjs +72 -0
- package/dist/pregel/utils/config.d.ts +2 -0
- package/dist/pregel/utils/config.js +68 -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.d.ts +2 -1
- package/package.json +1 -1
package/dist/pregel/types.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Runnable, RunnableConfig } from "@langchain/core/runnables";
|
|
|
2
2
|
import type { All, PendingWrite, CheckpointMetadata, BaseCheckpointSaver } from "@langchain/langgraph-checkpoint";
|
|
3
3
|
import type { BaseChannel } from "../channels/base.js";
|
|
4
4
|
import type { PregelNode } from "./read.js";
|
|
5
|
-
import { RetryPolicy } from "./utils.js";
|
|
5
|
+
import { RetryPolicy } from "./utils/index.js";
|
|
6
6
|
import { Interrupt } from "../constants.js";
|
|
7
7
|
import { BaseStore } from "../store/base.js";
|
|
8
8
|
import { type ManagedValueSpec } from "../managed/base.js";
|
|
@@ -26,7 +26,6 @@ export interface PregelInterface<Nn extends StrRecord<string, PregelNode>, Cc ex
|
|
|
26
26
|
streamMode?: StreamMode | StreamMode[];
|
|
27
27
|
inputChannels: keyof Cc | Array<keyof Cc>;
|
|
28
28
|
outputChannels: keyof Cc | Array<keyof Cc>;
|
|
29
|
-
configKeys?: string[];
|
|
30
29
|
/**
|
|
31
30
|
* @default []
|
|
32
31
|
*/
|
|
@@ -47,6 +46,7 @@ export interface PregelInterface<Nn extends StrRecord<string, PregelNode>, Cc ex
|
|
|
47
46
|
debug?: boolean;
|
|
48
47
|
checkpointer?: BaseCheckpointSaver;
|
|
49
48
|
retryPolicy?: RetryPolicy;
|
|
49
|
+
config?: RunnableConfig;
|
|
50
50
|
/**
|
|
51
51
|
* Memory store to use for SharedValues.
|
|
52
52
|
*/
|
|
@@ -58,6 +58,8 @@ export interface PregelTaskDescription {
|
|
|
58
58
|
readonly name: string;
|
|
59
59
|
readonly error?: unknown;
|
|
60
60
|
readonly interrupts: Interrupt[];
|
|
61
|
+
readonly state?: RunnableConfig | StateSnapshot;
|
|
62
|
+
readonly path?: [string, ...(string | number)[]];
|
|
61
63
|
}
|
|
62
64
|
export interface PregelExecutableTask<N extends PropertyKey, C extends PropertyKey> {
|
|
63
65
|
readonly name: N;
|
|
@@ -68,6 +70,7 @@ export interface PregelExecutableTask<N extends PropertyKey, C extends PropertyK
|
|
|
68
70
|
readonly triggers: Array<string>;
|
|
69
71
|
readonly retry_policy?: RetryPolicy;
|
|
70
72
|
readonly id: string;
|
|
73
|
+
readonly path?: [string, ...(string | number)[]];
|
|
71
74
|
}
|
|
72
75
|
export interface StateSnapshot {
|
|
73
76
|
/**
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureLangGraphConfig = void 0;
|
|
4
|
+
const singletons_1 = require("@langchain/core/singletons");
|
|
5
|
+
const COPIABLE_KEYS = ["tags", "metadata", "callbacks", "configurable"];
|
|
6
|
+
const CONFIG_KEYS = [
|
|
7
|
+
"tags",
|
|
8
|
+
"metadata",
|
|
9
|
+
"callbacks",
|
|
10
|
+
"runName",
|
|
11
|
+
"maxConcurrency",
|
|
12
|
+
"recursionLimit",
|
|
13
|
+
"configurable",
|
|
14
|
+
"runId",
|
|
15
|
+
"outputKeys",
|
|
16
|
+
"streamMode",
|
|
17
|
+
];
|
|
18
|
+
const DEFAULT_RECURSION_LIMIT = 25;
|
|
19
|
+
function ensureLangGraphConfig(...configs) {
|
|
20
|
+
const empty = {
|
|
21
|
+
tags: [],
|
|
22
|
+
metadata: {},
|
|
23
|
+
callbacks: undefined,
|
|
24
|
+
recursionLimit: DEFAULT_RECURSION_LIMIT,
|
|
25
|
+
configurable: {},
|
|
26
|
+
};
|
|
27
|
+
const implicitConfig = singletons_1.AsyncLocalStorageProviderSingleton.getRunnableConfig();
|
|
28
|
+
if (implicitConfig !== undefined) {
|
|
29
|
+
for (const [k, v] of Object.entries(implicitConfig)) {
|
|
30
|
+
if (v !== undefined) {
|
|
31
|
+
if (COPIABLE_KEYS.includes(k)) {
|
|
32
|
+
let copiedValue;
|
|
33
|
+
if (Array.isArray(v)) {
|
|
34
|
+
copiedValue = [...v];
|
|
35
|
+
}
|
|
36
|
+
else if (typeof v === "object") {
|
|
37
|
+
copiedValue = { ...v };
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
copiedValue = v;
|
|
41
|
+
}
|
|
42
|
+
empty[k] = copiedValue;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
empty[k] = v;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
for (const config of configs) {
|
|
51
|
+
if (config === undefined) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
for (const [k, v] of Object.entries(config)) {
|
|
55
|
+
if (v !== undefined && CONFIG_KEYS.includes(k)) {
|
|
56
|
+
empty[k] = v;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for (const [key, value] of Object.entries(empty.configurable)) {
|
|
61
|
+
empty.metadata = empty.metadata ?? {};
|
|
62
|
+
if (!key.startsWith("__") &&
|
|
63
|
+
(typeof value === "string" ||
|
|
64
|
+
typeof value === "number" ||
|
|
65
|
+
typeof value === "boolean") &&
|
|
66
|
+
!(key in empty.metadata)) {
|
|
67
|
+
empty.metadata[key] = value;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return empty;
|
|
71
|
+
}
|
|
72
|
+
exports.ensureLangGraphConfig = ensureLangGraphConfig;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { AsyncLocalStorageProviderSingleton } from "@langchain/core/singletons";
|
|
2
|
+
const COPIABLE_KEYS = ["tags", "metadata", "callbacks", "configurable"];
|
|
3
|
+
const CONFIG_KEYS = [
|
|
4
|
+
"tags",
|
|
5
|
+
"metadata",
|
|
6
|
+
"callbacks",
|
|
7
|
+
"runName",
|
|
8
|
+
"maxConcurrency",
|
|
9
|
+
"recursionLimit",
|
|
10
|
+
"configurable",
|
|
11
|
+
"runId",
|
|
12
|
+
"outputKeys",
|
|
13
|
+
"streamMode",
|
|
14
|
+
];
|
|
15
|
+
const DEFAULT_RECURSION_LIMIT = 25;
|
|
16
|
+
export function ensureLangGraphConfig(...configs) {
|
|
17
|
+
const empty = {
|
|
18
|
+
tags: [],
|
|
19
|
+
metadata: {},
|
|
20
|
+
callbacks: undefined,
|
|
21
|
+
recursionLimit: DEFAULT_RECURSION_LIMIT,
|
|
22
|
+
configurable: {},
|
|
23
|
+
};
|
|
24
|
+
const implicitConfig = AsyncLocalStorageProviderSingleton.getRunnableConfig();
|
|
25
|
+
if (implicitConfig !== undefined) {
|
|
26
|
+
for (const [k, v] of Object.entries(implicitConfig)) {
|
|
27
|
+
if (v !== undefined) {
|
|
28
|
+
if (COPIABLE_KEYS.includes(k)) {
|
|
29
|
+
let copiedValue;
|
|
30
|
+
if (Array.isArray(v)) {
|
|
31
|
+
copiedValue = [...v];
|
|
32
|
+
}
|
|
33
|
+
else if (typeof v === "object") {
|
|
34
|
+
copiedValue = { ...v };
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
copiedValue = v;
|
|
38
|
+
}
|
|
39
|
+
empty[k] = copiedValue;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
empty[k] = v;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
for (const config of configs) {
|
|
48
|
+
if (config === undefined) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
for (const [k, v] of Object.entries(config)) {
|
|
52
|
+
if (v !== undefined && CONFIG_KEYS.includes(k)) {
|
|
53
|
+
empty[k] = v;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
for (const [key, value] of Object.entries(empty.configurable)) {
|
|
58
|
+
empty.metadata = empty.metadata ?? {};
|
|
59
|
+
if (!key.startsWith("__") &&
|
|
60
|
+
(typeof value === "string" ||
|
|
61
|
+
typeof value === "number" ||
|
|
62
|
+
typeof value === "boolean") &&
|
|
63
|
+
!(key in empty.metadata)) {
|
|
64
|
+
empty.metadata[key] = value;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return empty;
|
|
68
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.patchCheckpointMap = exports.patchConfigurable = exports._coerceToDict = exports.getNewChannelVersions = exports.getNullChannelVersion = void 0;
|
|
4
|
+
const constants_js_1 = require("../../constants.cjs");
|
|
4
5
|
function getNullChannelVersion(currentVersions) {
|
|
5
6
|
const versionValues = Object.values(currentVersions);
|
|
6
7
|
const versionType = versionValues.length > 0 ? typeof versionValues[0] : undefined;
|
|
@@ -36,13 +37,35 @@ function _coerceToDict(value, defaultKey) {
|
|
|
36
37
|
: { [defaultKey]: value };
|
|
37
38
|
}
|
|
38
39
|
exports._coerceToDict = _coerceToDict;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
function patchConfigurable(config,
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
+
patch) {
|
|
43
|
+
if (config === null) {
|
|
44
|
+
return { configurable: patch };
|
|
45
|
+
}
|
|
46
|
+
else if (config?.configurable === undefined) {
|
|
47
|
+
return { ...config, configurable: patch };
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return {
|
|
51
|
+
...config,
|
|
52
|
+
configurable: { ...config.configurable, ...patch },
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.patchConfigurable = patchConfigurable;
|
|
57
|
+
function patchCheckpointMap(config, metadata) {
|
|
58
|
+
const parents = metadata?.parents ?? {};
|
|
59
|
+
if (Object.keys(parents).length > 0) {
|
|
60
|
+
return patchConfigurable(config, {
|
|
61
|
+
[constants_js_1.CONFIG_KEY_CHECKPOINT_MAP]: {
|
|
62
|
+
...parents,
|
|
63
|
+
[config.configurable?.checkpoint_ns ?? ""]: config.configurable?.checkpoint_id,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return config;
|
|
69
|
+
}
|
|
47
70
|
}
|
|
48
|
-
exports.
|
|
71
|
+
exports.patchCheckpointMap = patchCheckpointMap;
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RunnableConfig } from "@langchain/core/runnables";
|
|
2
|
+
import type { ChannelVersions, CheckpointMetadata } from "@langchain/langgraph-checkpoint";
|
|
2
3
|
export declare function getNullChannelVersion(currentVersions: ChannelVersions): string | number | undefined;
|
|
3
4
|
export declare function getNewChannelVersions(previousVersions: ChannelVersions, currentVersions: ChannelVersions): ChannelVersions;
|
|
4
5
|
export declare function _coerceToDict(value: any, defaultKey: string): any;
|
|
5
|
-
export declare function _getIdMetadata(metadata: Record<string, unknown>): {
|
|
6
|
-
langgraph_step: unknown;
|
|
7
|
-
langgraph_node: unknown;
|
|
8
|
-
langgraph_triggers: unknown;
|
|
9
|
-
langgraph_task_idx: unknown;
|
|
10
|
-
};
|
|
11
6
|
export type RetryPolicy = {
|
|
12
7
|
/**
|
|
13
8
|
* Amount of time that must elapse before the first retry occurs in milliseconds.
|
|
@@ -34,3 +29,5 @@ export type RetryPolicy = {
|
|
|
34
29
|
/** A function that returns True for exceptions that should trigger a retry. */
|
|
35
30
|
retryOn?: (e: any) => boolean;
|
|
36
31
|
};
|
|
32
|
+
export declare function patchConfigurable(config: RunnableConfig | undefined, patch: Record<string, any>): RunnableConfig;
|
|
33
|
+
export declare function patchCheckpointMap(config: RunnableConfig, metadata?: CheckpointMetadata): RunnableConfig;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CONFIG_KEY_CHECKPOINT_MAP } from "../../constants.js";
|
|
1
2
|
export function getNullChannelVersion(currentVersions) {
|
|
2
3
|
const versionValues = Object.values(currentVersions);
|
|
3
4
|
const versionType = versionValues.length > 0 ? typeof versionValues[0] : undefined;
|
|
@@ -30,12 +31,33 @@ export function _coerceToDict(value, defaultKey) {
|
|
|
30
31
|
? value
|
|
31
32
|
: { [defaultKey]: value };
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
export function patchConfigurable(config,
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
patch) {
|
|
37
|
+
if (config === null) {
|
|
38
|
+
return { configurable: patch };
|
|
39
|
+
}
|
|
40
|
+
else if (config?.configurable === undefined) {
|
|
41
|
+
return { ...config, configurable: patch };
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return {
|
|
45
|
+
...config,
|
|
46
|
+
configurable: { ...config.configurable, ...patch },
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export function patchCheckpointMap(config, metadata) {
|
|
51
|
+
const parents = metadata?.parents ?? {};
|
|
52
|
+
if (Object.keys(parents).length > 0) {
|
|
53
|
+
return patchConfigurable(config, {
|
|
54
|
+
[CONFIG_KEY_CHECKPOINT_MAP]: {
|
|
55
|
+
...parents,
|
|
56
|
+
[config.configurable?.checkpoint_ns ?? ""]: config.configurable?.checkpoint_id,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return config;
|
|
62
|
+
}
|
|
41
63
|
}
|
package/dist/utils.cjs
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.patchConfigurable = exports.gatherIteratorSync = exports.gatherIterator = exports.prefixGenerator = exports.RunnableCallable = void 0;
|
|
4
4
|
const runnables_1 = require("@langchain/core/runnables");
|
|
5
5
|
const singletons_1 = require("@langchain/core/singletons");
|
|
6
|
+
const config_js_1 = require("./pregel/utils/config.cjs");
|
|
6
7
|
class RunnableCallable extends runnables_1.Runnable {
|
|
7
8
|
constructor(fields) {
|
|
8
9
|
super();
|
|
@@ -72,14 +73,15 @@ class RunnableCallable extends runnables_1.Runnable {
|
|
|
72
73
|
) {
|
|
73
74
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
74
75
|
let returnValue;
|
|
76
|
+
const config = (0, config_js_1.ensureLangGraphConfig)(options);
|
|
75
77
|
if (this.trace) {
|
|
76
|
-
returnValue = await this._callWithConfig(this._tracedInvoke, input, (0, runnables_1.mergeConfigs)(this.config,
|
|
78
|
+
returnValue = await this._callWithConfig(this._tracedInvoke, input, (0, runnables_1.mergeConfigs)(this.config, config));
|
|
77
79
|
}
|
|
78
80
|
else {
|
|
79
|
-
returnValue = await this.func(input, (0, runnables_1.mergeConfigs)(this.config,
|
|
81
|
+
returnValue = await this.func(input, (0, runnables_1.mergeConfigs)(this.config, config));
|
|
80
82
|
}
|
|
81
83
|
if (runnables_1.Runnable.isRunnable(returnValue) && this.recurse) {
|
|
82
|
-
return await returnValue.invoke(input,
|
|
84
|
+
return await returnValue.invoke(input, config);
|
|
83
85
|
}
|
|
84
86
|
return returnValue;
|
|
85
87
|
}
|
package/dist/utils.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mergeConfigs, patchConfig, Runnable, } from "@langchain/core/runnables";
|
|
2
2
|
import { AsyncLocalStorageProviderSingleton } from "@langchain/core/singletons";
|
|
3
|
+
import { ensureLangGraphConfig } from "./pregel/utils/config.js";
|
|
3
4
|
export class RunnableCallable extends Runnable {
|
|
4
5
|
constructor(fields) {
|
|
5
6
|
super();
|
|
@@ -69,14 +70,15 @@ export class RunnableCallable extends Runnable {
|
|
|
69
70
|
) {
|
|
70
71
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
72
|
let returnValue;
|
|
73
|
+
const config = ensureLangGraphConfig(options);
|
|
72
74
|
if (this.trace) {
|
|
73
|
-
returnValue = await this._callWithConfig(this._tracedInvoke, input, mergeConfigs(this.config,
|
|
75
|
+
returnValue = await this._callWithConfig(this._tracedInvoke, input, mergeConfigs(this.config, config));
|
|
74
76
|
}
|
|
75
77
|
else {
|
|
76
|
-
returnValue = await this.func(input, mergeConfigs(this.config,
|
|
78
|
+
returnValue = await this.func(input, mergeConfigs(this.config, config));
|
|
77
79
|
}
|
|
78
80
|
if (Runnable.isRunnable(returnValue) && this.recurse) {
|
|
79
|
-
return await returnValue.invoke(input,
|
|
81
|
+
return await returnValue.invoke(input, config);
|
|
80
82
|
}
|
|
81
83
|
return returnValue;
|
|
82
84
|
}
|
package/dist/web.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { END, Graph, type StateGraphArgs, START, StateGraph, type CompiledStateGraph, MessageGraph, messagesStateReducer, type Messages, Annotation, type StateType, type UpdateType, type NodeType, type StateDefinition, type SingleReducer, type CompiledGraph, } from "./graph/index.js";
|
|
2
|
+
export type { StateSnapshot } from "./pregel/types.js";
|
|
2
3
|
export * from "./errors.js";
|
|
3
4
|
export { BaseChannel, type BinaryOperator, BinaryOperatorAggregate, type AnyValue, type WaitForNames, type DynamicBarrierValue, type LastValue, type NamedBarrierValue, type Topic, } from "./channels/index.js";
|
|
4
5
|
export { type AnnotationRoot as _INTERNAL_ANNOTATION_ROOT } from "./graph/index.js";
|
|
5
|
-
export { type RetryPolicy } from "./pregel/utils.js";
|
|
6
|
+
export { type RetryPolicy } from "./pregel/utils/index.js";
|
|
6
7
|
export { Send } from "./constants.js";
|
|
7
8
|
export { MemorySaver, type Checkpoint, type CheckpointMetadata, type CheckpointTuple, copyCheckpoint, emptyCheckpoint, BaseCheckpointSaver, } from "@langchain/langgraph-checkpoint";
|
|
8
9
|
export * from "./store/index.js";
|