@langchain/langgraph 0.0.34 → 0.1.0-rc.1
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/LICENSE +1 -1
- package/README.md +11 -15
- package/dist/channels/any_value.cjs +3 -1
- package/dist/channels/any_value.d.ts +1 -1
- package/dist/channels/any_value.js +3 -1
- package/dist/channels/base.cjs +28 -15
- package/dist/channels/base.d.ts +14 -4
- package/dist/channels/base.js +26 -13
- package/dist/channels/binop.cjs +2 -1
- package/dist/channels/binop.d.ts +1 -1
- package/dist/channels/binop.js +2 -1
- package/dist/channels/dynamic_barrier_value.cjs +30 -18
- package/dist/channels/dynamic_barrier_value.d.ts +2 -1
- package/dist/channels/dynamic_barrier_value.js +30 -18
- package/dist/channels/ephemeral_value.cjs +3 -1
- package/dist/channels/ephemeral_value.d.ts +1 -1
- package/dist/channels/ephemeral_value.js +3 -1
- package/dist/channels/last_value.cjs +3 -2
- package/dist/channels/last_value.d.ts +1 -1
- package/dist/channels/last_value.js +3 -2
- package/dist/channels/named_barrier_value.cjs +14 -6
- package/dist/channels/named_barrier_value.d.ts +2 -1
- package/dist/channels/named_barrier_value.js +15 -7
- package/dist/channels/topic.cjs +10 -11
- package/dist/channels/topic.d.ts +1 -1
- package/dist/channels/topic.js +10 -11
- package/dist/checkpoint/sqlite.cjs +14 -170
- package/dist/checkpoint/sqlite.d.ts +1 -14
- package/dist/checkpoint/sqlite.js +1 -166
- package/dist/constants.cjs +17 -1
- package/dist/constants.d.ts +7 -0
- package/dist/constants.js +16 -0
- package/dist/errors.cjs +21 -1
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +18 -0
- package/dist/graph/graph.cjs +6 -3
- package/dist/graph/graph.d.ts +7 -3
- package/dist/graph/graph.js +7 -4
- package/dist/graph/index.d.ts +1 -1
- package/dist/graph/state.cjs +9 -8
- package/dist/graph/state.d.ts +1 -1
- package/dist/graph/state.js +9 -8
- package/dist/prebuilt/react_agent_executor.d.ts +1 -1
- package/dist/pregel/algo.cjs +391 -0
- package/dist/pregel/algo.d.ts +35 -0
- package/dist/pregel/algo.js +381 -0
- package/dist/pregel/debug.cjs +155 -9
- package/dist/pregel/debug.d.ts +40 -2
- package/dist/pregel/debug.js +147 -7
- package/dist/pregel/index.cjs +286 -512
- package/dist/pregel/index.d.ts +66 -65
- package/dist/pregel/index.js +285 -506
- package/dist/pregel/io.cjs +2 -2
- package/dist/pregel/io.d.ts +5 -4
- package/dist/pregel/io.js +2 -2
- package/dist/pregel/loop.cjs +432 -0
- package/dist/pregel/loop.d.ts +83 -0
- package/dist/pregel/loop.js +425 -0
- package/dist/pregel/types.d.ts +56 -4
- package/dist/pregel/utils.cjs +48 -0
- package/dist/pregel/utils.d.ts +10 -0
- package/dist/pregel/utils.js +41 -0
- package/dist/pregel/write.cjs +3 -1
- package/dist/pregel/write.js +3 -1
- package/dist/utils.cjs +21 -1
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +18 -0
- package/dist/web.cjs +6 -7
- package/dist/web.d.ts +2 -4
- package/dist/web.js +1 -2
- package/package.json +6 -12
- package/dist/checkpoint/base.cjs +0 -66
- package/dist/checkpoint/base.d.ts +0 -73
- package/dist/checkpoint/base.js +0 -57
- package/dist/checkpoint/id.cjs +0 -8
- package/dist/checkpoint/id.d.ts +0 -1
- package/dist/checkpoint/id.js +0 -4
- package/dist/checkpoint/index.cjs +0 -9
- package/dist/checkpoint/index.d.ts +0 -2
- package/dist/checkpoint/index.js +0 -2
- package/dist/checkpoint/memory.cjs +0 -82
- package/dist/checkpoint/memory.d.ts +0 -10
- package/dist/checkpoint/memory.js +0 -78
- package/dist/serde/base.cjs +0 -8
- package/dist/serde/base.d.ts +0 -12
- package/dist/serde/base.js +0 -5
package/dist/pregel/debug.js
CHANGED
|
@@ -1,22 +1,32 @@
|
|
|
1
|
+
import { uuid5, } from "@langchain/langgraph-checkpoint";
|
|
2
|
+
import { ERROR, TAG_HIDDEN, TASK_NAMESPACE } from "../constants.js";
|
|
1
3
|
import { EmptyChannelError } from "../errors.js";
|
|
4
|
+
import { readChannels } from "./io.js";
|
|
5
|
+
import { _getIdMetadata } from "./utils.js";
|
|
2
6
|
const COLORS_MAP = {
|
|
3
7
|
blue: {
|
|
4
8
|
start: "\x1b[34m",
|
|
5
9
|
end: "\x1b[0m",
|
|
6
10
|
},
|
|
11
|
+
green: {
|
|
12
|
+
start: "\x1b[32m",
|
|
13
|
+
end: "\x1b[0m",
|
|
14
|
+
},
|
|
15
|
+
yellow: {
|
|
16
|
+
start: "\x1b[33;1m",
|
|
17
|
+
end: "\x1b[0m",
|
|
18
|
+
},
|
|
7
19
|
};
|
|
8
20
|
/**
|
|
9
21
|
* Wrap some text in a color for printing to the console.
|
|
10
22
|
*/
|
|
11
23
|
const wrap = (color, text) => `${color.start}${text}${color.end}`;
|
|
12
|
-
export function printStepStart(step, nextTasks) {
|
|
13
|
-
const nTasks = nextTasks.length;
|
|
14
|
-
console.log(`${wrap(COLORS_MAP.blue, "[langgraph/step]")}`, `Starting step ${step} with ${nTasks} task${nTasks === 1 ? "" : "s"}. Next tasks:\n`, `\n${nextTasks
|
|
15
|
-
.map((task) => `${String(task.name)}(${JSON.stringify(task.input, null, 2)})`)
|
|
16
|
-
.join("\n")}`);
|
|
17
|
-
}
|
|
18
24
|
export function printCheckpoint(step, channels) {
|
|
19
|
-
console.log(
|
|
25
|
+
console.log([
|
|
26
|
+
`${wrap(COLORS_MAP.blue, "[langgraph/checkpoint]")}`,
|
|
27
|
+
`Finishing step ${step}. Channel values:\n`,
|
|
28
|
+
`\n${JSON.stringify(Object.fromEntries(_readChannels(channels)), null, 2)}`,
|
|
29
|
+
].join(""));
|
|
20
30
|
}
|
|
21
31
|
function* _readChannels(channels
|
|
22
32
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -37,3 +47,133 @@ function* _readChannels(channels
|
|
|
37
47
|
}
|
|
38
48
|
}
|
|
39
49
|
}
|
|
50
|
+
export function* mapDebugTasks(step, tasks) {
|
|
51
|
+
const ts = new Date().toISOString();
|
|
52
|
+
for (const { name, input, config, triggers } of tasks) {
|
|
53
|
+
if (config?.tags?.includes(TAG_HIDDEN))
|
|
54
|
+
continue;
|
|
55
|
+
const metadata = { ...config?.metadata };
|
|
56
|
+
const idMetadata = _getIdMetadata({
|
|
57
|
+
langgraph_step: metadata.langgraph_step,
|
|
58
|
+
langgraph_node: metadata.langgraph_node,
|
|
59
|
+
langgraph_triggers: metadata.langgraph_triggers,
|
|
60
|
+
langgraph_task_idx: metadata.langgraph_task_idx,
|
|
61
|
+
});
|
|
62
|
+
yield {
|
|
63
|
+
type: "task",
|
|
64
|
+
timestamp: ts,
|
|
65
|
+
step,
|
|
66
|
+
payload: {
|
|
67
|
+
id: uuid5(JSON.stringify([name, step, idMetadata]), TASK_NAMESPACE),
|
|
68
|
+
name,
|
|
69
|
+
input,
|
|
70
|
+
triggers,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export function* mapDebugTaskResults(step, tasks, streamChannelsList) {
|
|
76
|
+
const ts = new Date().toISOString();
|
|
77
|
+
for (const { name, writes, config } of tasks) {
|
|
78
|
+
if (config?.tags?.includes(TAG_HIDDEN))
|
|
79
|
+
continue;
|
|
80
|
+
const metadata = { ...config?.metadata };
|
|
81
|
+
const idMetadata = _getIdMetadata(metadata);
|
|
82
|
+
yield {
|
|
83
|
+
type: "task_result",
|
|
84
|
+
timestamp: ts,
|
|
85
|
+
step,
|
|
86
|
+
payload: {
|
|
87
|
+
id: uuid5(JSON.stringify([name, step, idMetadata]), TASK_NAMESPACE),
|
|
88
|
+
name,
|
|
89
|
+
result: writes.filter(([channel]) => streamChannelsList.includes(channel)),
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export function* mapDebugCheckpoint(step, config, channels, streamChannels, metadata, tasks, pendingWrites) {
|
|
95
|
+
function formatConfig(config) {
|
|
96
|
+
// make sure the config is consistent with Python
|
|
97
|
+
const pyConfig = {};
|
|
98
|
+
if (config.callbacks != null)
|
|
99
|
+
pyConfig.callbacks = config.callbacks;
|
|
100
|
+
if (config.configurable != null)
|
|
101
|
+
pyConfig.configurable = config.configurable;
|
|
102
|
+
if (config.maxConcurrency != null)
|
|
103
|
+
pyConfig.max_concurrency = config.maxConcurrency;
|
|
104
|
+
if (config.metadata != null)
|
|
105
|
+
pyConfig.metadata = config.metadata;
|
|
106
|
+
if (config.recursionLimit != null)
|
|
107
|
+
pyConfig.recursion_limit = config.recursionLimit;
|
|
108
|
+
if (config.runId != null)
|
|
109
|
+
pyConfig.run_id = config.runId;
|
|
110
|
+
if (config.runName != null)
|
|
111
|
+
pyConfig.run_name = config.runName;
|
|
112
|
+
if (config.tags != null)
|
|
113
|
+
pyConfig.tags = config.tags;
|
|
114
|
+
return pyConfig;
|
|
115
|
+
}
|
|
116
|
+
function getCurrentUTC() {
|
|
117
|
+
const now = new Date();
|
|
118
|
+
return new Date(now.getTime() - now.getTimezoneOffset() * 60 * 1000);
|
|
119
|
+
}
|
|
120
|
+
const ts = getCurrentUTC().toISOString();
|
|
121
|
+
yield {
|
|
122
|
+
type: "checkpoint",
|
|
123
|
+
timestamp: ts,
|
|
124
|
+
step,
|
|
125
|
+
payload: {
|
|
126
|
+
config: formatConfig(config),
|
|
127
|
+
values: readChannels(channels, streamChannels),
|
|
128
|
+
metadata,
|
|
129
|
+
next: tasks.map((task) => task.name),
|
|
130
|
+
tasks: tasksWithWrites(tasks, pendingWrites),
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
export function tasksWithWrites(tasks, pendingWrites) {
|
|
135
|
+
return tasks.map((task) => {
|
|
136
|
+
const error = pendingWrites.find(([id, n]) => id === task.id && n === ERROR)?.[2];
|
|
137
|
+
if (error)
|
|
138
|
+
return { id: task.id, name: task.name, error };
|
|
139
|
+
return { id: task.id, name: task.name };
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
export function printStepCheckpoint(step, channels, whitelist) {
|
|
143
|
+
console.log([
|
|
144
|
+
`${wrap(COLORS_MAP.blue, `[${step}:checkpoint]`)}`,
|
|
145
|
+
`\x1b[1m State at the end of step ${step}:\x1b[0m\n`,
|
|
146
|
+
JSON.stringify(readChannels(channels, whitelist), null, 2),
|
|
147
|
+
].join(""));
|
|
148
|
+
}
|
|
149
|
+
export function printStepTasks(step, nextTasks) {
|
|
150
|
+
const nTasks = nextTasks.length;
|
|
151
|
+
console.log([
|
|
152
|
+
`${wrap(COLORS_MAP.blue, `[${step}:tasks]`)}`,
|
|
153
|
+
`\x1b[1m Starting step ${step} with ${nTasks} task${nTasks === 1 ? "" : "s"}:\x1b[0m\n`,
|
|
154
|
+
nextTasks
|
|
155
|
+
.map((task) => `- ${wrap(COLORS_MAP.green, String(task.name))} -> ${JSON.stringify(task.input, null, 2)}`)
|
|
156
|
+
.join("\n"),
|
|
157
|
+
].join(""));
|
|
158
|
+
}
|
|
159
|
+
export function printStepWrites(step, writes, whitelist) {
|
|
160
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
161
|
+
const byChannel = {};
|
|
162
|
+
for (const [channel, value] of writes) {
|
|
163
|
+
if (whitelist.includes(channel)) {
|
|
164
|
+
if (!byChannel[channel]) {
|
|
165
|
+
byChannel[channel] = [];
|
|
166
|
+
}
|
|
167
|
+
byChannel[channel].push(value);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
console.log([
|
|
171
|
+
`${wrap(COLORS_MAP.blue, `[${step}:writes]`)}`,
|
|
172
|
+
`\x1b[1m Finished step ${step} with writes to ${Object.keys(byChannel).length} channel${Object.keys(byChannel).length !== 1 ? "s" : ""}:\x1b[0m\n`,
|
|
173
|
+
Object.entries(byChannel)
|
|
174
|
+
.map(([name, vals]) => `- ${wrap(COLORS_MAP.yellow, name)} -> ${vals
|
|
175
|
+
.map((v) => JSON.stringify(v))
|
|
176
|
+
.join(", ")}`)
|
|
177
|
+
.join("\n"),
|
|
178
|
+
].join(""));
|
|
179
|
+
}
|