@langchain/langgraph 0.1.0-rc.0 → 0.1.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/LICENSE +1 -1
- package/dist/channels/base.cjs +20 -15
- package/dist/channels/base.d.ts +2 -3
- package/dist/channels/base.js +18 -13
- package/dist/checkpoint/sqlite.cjs +14 -199
- package/dist/checkpoint/sqlite.d.ts +1 -16
- package/dist/checkpoint/sqlite.js +1 -195
- package/dist/graph/graph.d.ts +1 -1
- package/dist/graph/message.d.ts +0 -3
- package/dist/graph/messages_annotation.cjs +12 -0
- package/dist/graph/messages_annotation.d.ts +4 -0
- package/dist/graph/messages_annotation.js +9 -0
- package/dist/graph/state.cjs +2 -1
- package/dist/graph/state.d.ts +1 -1
- package/dist/graph/state.js +2 -1
- package/dist/index.cjs +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/prebuilt/react_agent_executor.d.ts +3 -3
- package/dist/prebuilt/tool_node.d.ts +3 -3
- package/dist/pregel/algo.cjs +112 -105
- package/dist/pregel/algo.d.ts +8 -5
- package/dist/pregel/algo.js +109 -102
- package/dist/pregel/debug.cjs +9 -12
- package/dist/pregel/debug.d.ts +3 -2
- package/dist/pregel/debug.js +6 -10
- package/dist/pregel/index.cjs +92 -26
- package/dist/pregel/index.d.ts +41 -3
- package/dist/pregel/index.js +90 -24
- package/dist/pregel/io.d.ts +1 -1
- package/dist/pregel/loop.cjs +13 -9
- package/dist/pregel/loop.d.ts +1 -2
- package/dist/pregel/loop.js +8 -4
- package/dist/pregel/types.d.ts +5 -2
- package/dist/pregel/utils.cjs +25 -10
- package/dist/pregel/utils.d.ts +8 -1
- package/dist/pregel/utils.js +22 -9
- package/dist/web.cjs +6 -7
- package/dist/web.d.ts +1 -4
- package/dist/web.js +1 -2
- package/package.json +12 -12
- package/dist/checkpoint/base.cjs +0 -75
- package/dist/checkpoint/base.d.ts +0 -78
- package/dist/checkpoint/base.js +0 -66
- package/dist/checkpoint/id.cjs +0 -20
- package/dist/checkpoint/id.d.ts +0 -2
- package/dist/checkpoint/id.js +0 -15
- package/dist/checkpoint/index.cjs +0 -9
- package/dist/checkpoint/index.d.ts +0 -3
- package/dist/checkpoint/index.js +0 -2
- package/dist/checkpoint/memory.cjs +0 -195
- package/dist/checkpoint/memory.d.ts +0 -13
- package/dist/checkpoint/memory.js +0 -191
- package/dist/checkpoint/serde/types.cjs +0 -2
- package/dist/checkpoint/serde/types.d.ts +0 -40
- package/dist/checkpoint/serde/types.js +0 -1
- package/dist/checkpoint/types.cjs +0 -2
- package/dist/checkpoint/types.d.ts +0 -28
- package/dist/checkpoint/types.js +0 -1
- package/dist/serde/base.cjs +0 -8
- package/dist/serde/base.d.ts +0 -12
- package/dist/serde/base.js +0 -5
|
@@ -2,9 +2,9 @@ import { BaseChatModel } from "@langchain/core/language_models/chat_models";
|
|
|
2
2
|
import { BaseMessage, SystemMessage } from "@langchain/core/messages";
|
|
3
3
|
import { Runnable, RunnableToolLike } from "@langchain/core/runnables";
|
|
4
4
|
import { StructuredToolInterface } from "@langchain/core/tools";
|
|
5
|
-
import { BaseCheckpointSaver } from "
|
|
5
|
+
import { BaseCheckpointSaver } from "@langchain/langgraph-checkpoint";
|
|
6
6
|
import { START } from "../graph/index.js";
|
|
7
|
-
import {
|
|
7
|
+
import { MessagesAnnotation } from "../graph/messages_annotation.js";
|
|
8
8
|
import { CompiledStateGraph } from "../graph/state.js";
|
|
9
9
|
import { All } from "../pregel/types.js";
|
|
10
10
|
import { ToolNode } from "./tool_node.js";
|
|
@@ -14,7 +14,7 @@ export interface AgentState {
|
|
|
14
14
|
export type N = typeof START | "agent" | "tools";
|
|
15
15
|
export type CreateReactAgentParams = {
|
|
16
16
|
llm: BaseChatModel;
|
|
17
|
-
tools: ToolNode<
|
|
17
|
+
tools: ToolNode<typeof MessagesAnnotation.State> | (StructuredToolInterface | RunnableToolLike)[];
|
|
18
18
|
messageModifier?: SystemMessage | string | ((messages: BaseMessage[]) => BaseMessage[]) | ((messages: BaseMessage[]) => Promise<BaseMessage[]>) | Runnable;
|
|
19
19
|
checkpointSaver?: BaseCheckpointSaver;
|
|
20
20
|
interruptBefore?: N[] | All;
|
|
@@ -3,13 +3,13 @@ import { RunnableToolLike } from "@langchain/core/runnables";
|
|
|
3
3
|
import { StructuredToolInterface } from "@langchain/core/tools";
|
|
4
4
|
import { RunnableCallable } from "../utils.js";
|
|
5
5
|
import { END } from "../graph/graph.js";
|
|
6
|
-
import {
|
|
6
|
+
import { MessagesAnnotation } from "../graph/messages_annotation.js";
|
|
7
7
|
export type ToolNodeOptions = {
|
|
8
8
|
name?: string;
|
|
9
9
|
tags?: string[];
|
|
10
10
|
handleToolErrors?: boolean;
|
|
11
11
|
};
|
|
12
|
-
export declare class ToolNode<T extends BaseMessage[] |
|
|
12
|
+
export declare class ToolNode<T extends BaseMessage[] | typeof MessagesAnnotation.State> extends RunnableCallable<T, T> {
|
|
13
13
|
/**
|
|
14
14
|
A node that runs the tools requested in the last AIMessage. It can be used
|
|
15
15
|
either in StateGraph with a "messages" key or in MessageGraph. If multiple
|
|
@@ -21,4 +21,4 @@ export declare class ToolNode<T extends BaseMessage[] | MessagesState> extends R
|
|
|
21
21
|
constructor(tools: (StructuredToolInterface | RunnableToolLike)[], options?: ToolNodeOptions);
|
|
22
22
|
private run;
|
|
23
23
|
}
|
|
24
|
-
export declare function toolsCondition(state: BaseMessage[] |
|
|
24
|
+
export declare function toolsCondition(state: BaseMessage[] | typeof MessagesAnnotation.State): "tools" | typeof END;
|
package/dist/pregel/algo.cjs
CHANGED
|
@@ -3,17 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports._prepareNextTasks = exports._applyWrites = exports._localWrite = exports._localRead = exports.shouldInterrupt = exports.executeTasks = exports.increment = void 0;
|
|
4
4
|
/* eslint-disable no-param-reassign */
|
|
5
5
|
const runnables_1 = require("@langchain/core/runnables");
|
|
6
|
+
const langgraph_checkpoint_1 = require("@langchain/langgraph-checkpoint");
|
|
6
7
|
const base_js_1 = require("../channels/base.cjs");
|
|
7
|
-
const base_js_2 = require("../checkpoint/base.cjs");
|
|
8
8
|
const io_js_1 = require("./io.cjs");
|
|
9
9
|
const constants_js_1 = require("../constants.cjs");
|
|
10
10
|
const errors_js_1 = require("../errors.cjs");
|
|
11
|
-
const
|
|
11
|
+
const utils_js_1 = require("./utils.cjs");
|
|
12
12
|
const increment = (current) => {
|
|
13
13
|
return current !== undefined ? current + 1 : 1;
|
|
14
14
|
};
|
|
15
15
|
exports.increment = increment;
|
|
16
|
-
async function executeTasks(tasks, stepTimeout, signal
|
|
16
|
+
async function* executeTasks(tasks, stepTimeout, signal
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
) {
|
|
17
19
|
if (stepTimeout && signal) {
|
|
18
20
|
if ("any" in AbortSignal) {
|
|
19
21
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -29,19 +31,26 @@ async function executeTasks(tasks, stepTimeout, signal) {
|
|
|
29
31
|
// Abort if signal is aborted
|
|
30
32
|
signal?.throwIfAborted();
|
|
31
33
|
// Start all tasks
|
|
32
|
-
const
|
|
34
|
+
const executingTasks = Object.fromEntries(Object.entries(tasks).map(([taskId, task]) => {
|
|
35
|
+
return [taskId, task()];
|
|
36
|
+
}));
|
|
33
37
|
let listener;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
const signalPromise = new Promise((_resolve, reject) => {
|
|
39
|
+
listener = () => reject(new Error("Abort"));
|
|
40
|
+
signal?.addEventListener("abort", listener);
|
|
41
|
+
}).finally(() => signal?.removeEventListener("abort", listener));
|
|
42
|
+
while (Object.keys(executingTasks).length > 0) {
|
|
43
|
+
const { task, error } = await Promise.race([
|
|
44
|
+
...Object.values(executingTasks),
|
|
45
|
+
signalPromise,
|
|
46
|
+
]);
|
|
47
|
+
if (error !== undefined) {
|
|
48
|
+
// TODO: don't stop others if exception is interrupt
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
yield task;
|
|
52
|
+
delete executingTasks[task.id];
|
|
53
|
+
}
|
|
45
54
|
}
|
|
46
55
|
exports.executeTasks = executeTasks;
|
|
47
56
|
function shouldInterrupt(checkpoint, interruptNodes, tasks) {
|
|
@@ -54,7 +63,7 @@ function shouldInterrupt(checkpoint, interruptNodes, tasks) {
|
|
|
54
63
|
else if (versionType === "string") {
|
|
55
64
|
nullVersion = "";
|
|
56
65
|
}
|
|
57
|
-
const seen = checkpoint.versions_seen[constants_js_1.INTERRUPT]
|
|
66
|
+
const seen = checkpoint.versions_seen[constants_js_1.INTERRUPT] ?? {};
|
|
58
67
|
const anyChannelUpdated = Object.entries(checkpoint.channel_versions).some(([chan, version]) => {
|
|
59
68
|
return version > (seen[chan] ?? nullVersion);
|
|
60
69
|
});
|
|
@@ -70,7 +79,7 @@ function _localRead(checkpoint, channels, task, select, fresh = false) {
|
|
|
70
79
|
// create a new copy of channels
|
|
71
80
|
const newChannels = (0, base_js_1.emptyChannels)(channels, newCheckpoint);
|
|
72
81
|
// Note: _applyWrites contains side effects
|
|
73
|
-
_applyWrites((0,
|
|
82
|
+
_applyWrites((0, langgraph_checkpoint_1.copyCheckpoint)(newCheckpoint), newChannels, [task]);
|
|
74
83
|
return (0, io_js_1.readChannels)(newChannels, select);
|
|
75
84
|
}
|
|
76
85
|
else {
|
|
@@ -181,9 +190,6 @@ getNextVersion) {
|
|
|
181
190
|
}
|
|
182
191
|
updatedChannels.add(chan);
|
|
183
192
|
}
|
|
184
|
-
else {
|
|
185
|
-
console.warn(`Skipping write for channel ${chan} which has no readers`);
|
|
186
|
-
}
|
|
187
193
|
}
|
|
188
194
|
// Channels that weren't updated in this step are notified of a new step
|
|
189
195
|
for (const chan of Object.keys(channels)) {
|
|
@@ -198,7 +204,6 @@ getNextVersion) {
|
|
|
198
204
|
exports._applyWrites = _applyWrites;
|
|
199
205
|
function _prepareNextTasks(checkpoint, processes, channels, config, forExecution, extra) {
|
|
200
206
|
const parentNamespace = config.configurable?.checkpoint_ns ?? "";
|
|
201
|
-
const newCheckpoint = (0, base_js_2.copyCheckpoint)(checkpoint);
|
|
202
207
|
const tasks = [];
|
|
203
208
|
const taskDescriptions = [];
|
|
204
209
|
const { step, isResuming = false, checkpointer, manager } = extra;
|
|
@@ -212,16 +217,16 @@ function _prepareNextTasks(checkpoint, processes, channels, config, forExecution
|
|
|
212
217
|
continue;
|
|
213
218
|
}
|
|
214
219
|
const triggers = [constants_js_1.TASKS];
|
|
215
|
-
const metadata = {
|
|
220
|
+
const metadata = (0, utils_js_1._getIdMetadata)({
|
|
216
221
|
langgraph_step: step,
|
|
217
222
|
langgraph_node: packet.node,
|
|
218
223
|
langgraph_triggers: triggers,
|
|
219
|
-
langgraph_task_idx: tasks.length,
|
|
220
|
-
};
|
|
224
|
+
langgraph_task_idx: forExecution ? tasks.length : taskDescriptions.length,
|
|
225
|
+
});
|
|
221
226
|
const checkpointNamespace = parentNamespace === ""
|
|
222
227
|
? packet.node
|
|
223
228
|
: `${parentNamespace}${constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR}${packet.node}`;
|
|
224
|
-
const taskId = (0,
|
|
229
|
+
const taskId = (0, langgraph_checkpoint_1.uuid5)(JSON.stringify([checkpointNamespace, metadata]), checkpoint.id);
|
|
225
230
|
if (forExecution) {
|
|
226
231
|
const proc = processes[packet.node];
|
|
227
232
|
const node = proc.getNode();
|
|
@@ -257,94 +262,43 @@ function _prepareNextTasks(checkpoint, processes, channels, config, forExecution
|
|
|
257
262
|
}
|
|
258
263
|
// Check if any processes should be run in next step
|
|
259
264
|
// If so, prepare the values to be passed to them
|
|
265
|
+
const nullVersion = (0, utils_js_1.getNullChannelVersion)(checkpoint.channel_versions);
|
|
266
|
+
if (nullVersion === undefined) {
|
|
267
|
+
return forExecution ? tasks : taskDescriptions;
|
|
268
|
+
}
|
|
260
269
|
for (const [name, proc] of Object.entries(processes)) {
|
|
261
|
-
const
|
|
270
|
+
const seen = checkpoint.versions_seen[name] ?? {};
|
|
271
|
+
const triggers = proc.triggers
|
|
262
272
|
.filter((chan) => {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
273
|
+
const result = (0, io_js_1.readChannel)(channels, chan, false, true);
|
|
274
|
+
const isEmptyChannelError =
|
|
275
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
276
|
+
result instanceof Error &&
|
|
277
|
+
result.name === errors_js_1.EmptyChannelError.unminifiable_name;
|
|
278
|
+
return (!isEmptyChannelError &&
|
|
279
|
+
(checkpoint.channel_versions[chan] ?? nullVersion) >
|
|
280
|
+
(seen[chan] ?? nullVersion));
|
|
270
281
|
})
|
|
271
|
-
.
|
|
272
|
-
(0, base_js_2.getVersionSeen)(newCheckpoint, name, chan));
|
|
273
|
-
const hasUpdatedChannels = updatedChannels.length > 0;
|
|
282
|
+
.sort();
|
|
274
283
|
// If any of the channels read by this process were updated
|
|
275
|
-
if (
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
// then invoke the process with the values of all non-empty channels
|
|
280
|
-
if (Array.isArray(proc.channels)) {
|
|
281
|
-
let emptyChannels = 0;
|
|
282
|
-
for (const chan of proc.channels) {
|
|
283
|
-
try {
|
|
284
|
-
val = (0, io_js_1.readChannel)(channels, chan, false);
|
|
285
|
-
break;
|
|
286
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
287
|
-
}
|
|
288
|
-
catch (e) {
|
|
289
|
-
if (e.name === errors_js_1.EmptyChannelError.unminifiable_name) {
|
|
290
|
-
emptyChannels += 1;
|
|
291
|
-
continue;
|
|
292
|
-
}
|
|
293
|
-
else {
|
|
294
|
-
throw e;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
if (emptyChannels === proc.channels.length) {
|
|
299
|
-
continue;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
else if (typeof proc.channels === "object") {
|
|
303
|
-
val = {};
|
|
304
|
-
try {
|
|
305
|
-
for (const [k, chan] of Object.entries(proc.channels)) {
|
|
306
|
-
val[k] = (0, io_js_1.readChannel)(channels, chan, !proc.triggers.includes(chan));
|
|
307
|
-
}
|
|
308
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
309
|
-
}
|
|
310
|
-
catch (e) {
|
|
311
|
-
if (e.name === errors_js_1.EmptyChannelError.unminifiable_name) {
|
|
312
|
-
continue;
|
|
313
|
-
}
|
|
314
|
-
else {
|
|
315
|
-
throw e;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
else {
|
|
320
|
-
throw new Error(`Invalid channels type, expected list or dict, got ${proc.channels}`);
|
|
321
|
-
}
|
|
322
|
-
// If the process has a mapper, apply it to the value
|
|
323
|
-
if (proc.mapper !== undefined) {
|
|
324
|
-
val = proc.mapper(val);
|
|
284
|
+
if (triggers.length > 0) {
|
|
285
|
+
const val = _procInput(proc, channels, forExecution);
|
|
286
|
+
if (val === undefined) {
|
|
287
|
+
continue;
|
|
325
288
|
}
|
|
326
|
-
const metadata = {
|
|
289
|
+
const metadata = (0, utils_js_1._getIdMetadata)({
|
|
327
290
|
langgraph_step: step,
|
|
328
291
|
langgraph_node: name,
|
|
329
|
-
langgraph_triggers:
|
|
330
|
-
langgraph_task_idx:
|
|
331
|
-
|
|
292
|
+
langgraph_triggers: triggers,
|
|
293
|
+
langgraph_task_idx: forExecution
|
|
294
|
+
? tasks.length
|
|
295
|
+
: taskDescriptions.length,
|
|
296
|
+
});
|
|
332
297
|
const checkpointNamespace = parentNamespace === ""
|
|
333
298
|
? name
|
|
334
299
|
: `${parentNamespace}${constants_js_1.CHECKPOINT_NAMESPACE_SEPARATOR}${name}`;
|
|
335
|
-
const taskId = (0,
|
|
300
|
+
const taskId = (0, langgraph_checkpoint_1.uuid5)(JSON.stringify([checkpointNamespace, metadata]), checkpoint.id);
|
|
336
301
|
if (forExecution) {
|
|
337
|
-
// Update seen versions
|
|
338
|
-
if (!newCheckpoint.versions_seen[name]) {
|
|
339
|
-
newCheckpoint.versions_seen[name] = {};
|
|
340
|
-
}
|
|
341
|
-
proc.triggers.forEach((chan) => {
|
|
342
|
-
const version = newCheckpoint.channel_versions[chan];
|
|
343
|
-
if (version !== undefined) {
|
|
344
|
-
// side effect: updates newCheckpoint
|
|
345
|
-
newCheckpoint.versions_seen[name][chan] = version;
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
302
|
const node = proc.getNode();
|
|
349
303
|
if (node !== undefined) {
|
|
350
304
|
const writes = [];
|
|
@@ -353,7 +307,7 @@ function _prepareNextTasks(checkpoint, processes, channels, config, forExecution
|
|
|
353
307
|
input: val,
|
|
354
308
|
proc: node,
|
|
355
309
|
writes,
|
|
356
|
-
triggers
|
|
310
|
+
triggers,
|
|
357
311
|
config: (0, runnables_1.patchConfig)((0, runnables_1.mergeConfigs)(config, proc.config, { metadata }), {
|
|
358
312
|
runName: name,
|
|
359
313
|
callbacks: manager?.getChild(`graph:step:${step}`),
|
|
@@ -362,7 +316,7 @@ function _prepareNextTasks(checkpoint, processes, channels, config, forExecution
|
|
|
362
316
|
[constants_js_1.CONFIG_KEY_READ]: _localRead.bind(undefined, checkpoint, channels, {
|
|
363
317
|
name,
|
|
364
318
|
writes: writes,
|
|
365
|
-
triggers
|
|
319
|
+
triggers,
|
|
366
320
|
}),
|
|
367
321
|
[constants_js_1.CONFIG_KEY_CHECKPOINTER]: checkpointer,
|
|
368
322
|
[constants_js_1.CONFIG_KEY_RESUMING]: isResuming,
|
|
@@ -379,6 +333,59 @@ function _prepareNextTasks(checkpoint, processes, channels, config, forExecution
|
|
|
379
333
|
}
|
|
380
334
|
}
|
|
381
335
|
}
|
|
382
|
-
return
|
|
336
|
+
return forExecution ? tasks : taskDescriptions;
|
|
383
337
|
}
|
|
384
338
|
exports._prepareNextTasks = _prepareNextTasks;
|
|
339
|
+
function _procInput(proc, channels, forExecution) {
|
|
340
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
341
|
+
let val;
|
|
342
|
+
// If all trigger channels subscribed by this process are not empty
|
|
343
|
+
// then invoke the process with the values of all non-empty channels
|
|
344
|
+
if (Array.isArray(proc.channels)) {
|
|
345
|
+
let successfulRead = false;
|
|
346
|
+
for (const chan of proc.channels) {
|
|
347
|
+
try {
|
|
348
|
+
val = (0, io_js_1.readChannel)(channels, chan, false);
|
|
349
|
+
successfulRead = true;
|
|
350
|
+
break;
|
|
351
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
352
|
+
}
|
|
353
|
+
catch (e) {
|
|
354
|
+
if (e.name === errors_js_1.EmptyChannelError.unminifiable_name) {
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
throw e;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (!successfulRead) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
else if (typeof proc.channels === "object") {
|
|
367
|
+
val = {};
|
|
368
|
+
try {
|
|
369
|
+
for (const [k, chan] of Object.entries(proc.channels)) {
|
|
370
|
+
val[k] = (0, io_js_1.readChannel)(channels, chan, !proc.triggers.includes(chan));
|
|
371
|
+
}
|
|
372
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
373
|
+
}
|
|
374
|
+
catch (e) {
|
|
375
|
+
if (e.name === errors_js_1.EmptyChannelError.unminifiable_name) {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
throw e;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
throw new Error(`Invalid channels type, expected list or dict, got ${proc.channels}`);
|
|
385
|
+
}
|
|
386
|
+
// If the process has a mapper, apply it to the value
|
|
387
|
+
if (forExecution && proc.mapper !== undefined) {
|
|
388
|
+
val = proc.mapper(val);
|
|
389
|
+
}
|
|
390
|
+
return val;
|
|
391
|
+
}
|
package/dist/pregel/algo.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { RunnableConfig } from "@langchain/core/runnables";
|
|
2
2
|
import { CallbackManagerForChainRun } from "@langchain/core/callbacks/manager";
|
|
3
|
+
import { BaseCheckpointSaver, Checkpoint, ReadonlyCheckpoint, type PendingWrite } from "@langchain/langgraph-checkpoint";
|
|
3
4
|
import { BaseChannel } from "../channels/base.js";
|
|
4
|
-
import { BaseCheckpointSaver, Checkpoint, ReadonlyCheckpoint } from "../checkpoint/base.js";
|
|
5
5
|
import { PregelNode } from "./read.js";
|
|
6
6
|
import { All, PregelExecutableTask, PregelTaskDescription } from "./types.js";
|
|
7
|
-
import { PendingWrite } from "../checkpoint/types.js";
|
|
8
7
|
/**
|
|
9
8
|
* Construct a type with a set of properties K of type T
|
|
10
9
|
*/
|
|
@@ -17,7 +16,11 @@ export type WritesProtocol<C = string> = {
|
|
|
17
16
|
triggers: string[];
|
|
18
17
|
};
|
|
19
18
|
export declare const increment: (current?: number) => number;
|
|
20
|
-
export declare function executeTasks
|
|
19
|
+
export declare function executeTasks(tasks: Record<string, () => Promise<{
|
|
20
|
+
task: PregelExecutableTask<any, any>;
|
|
21
|
+
result: any;
|
|
22
|
+
error: Error;
|
|
23
|
+
}>>, stepTimeout?: number, signal?: AbortSignal): AsyncGenerator<PregelExecutableTask<any, any>>;
|
|
21
24
|
export declare function shouldInterrupt<N extends PropertyKey, C extends PropertyKey>(checkpoint: Checkpoint, interruptNodes: All | N[], tasks: PregelExecutableTask<N, C>[]): boolean;
|
|
22
25
|
export declare function _localRead<Cc extends StrRecord<string, BaseChannel>>(checkpoint: ReadonlyCheckpoint, channels: Cc, task: WritesProtocol<keyof Cc>, select: Array<keyof Cc> | keyof Cc, fresh?: boolean): Record<string, unknown> | unknown;
|
|
23
26
|
export declare function _localWrite(commit: (writes: [string, any][]) => void, processes: Record<string, PregelNode>, channels: Record<string, BaseChannel>, writes: [string, any][]): void;
|
|
@@ -28,5 +31,5 @@ export type NextTaskExtraFields = {
|
|
|
28
31
|
checkpointer?: BaseCheckpointSaver;
|
|
29
32
|
manager?: CallbackManagerForChainRun;
|
|
30
33
|
};
|
|
31
|
-
export declare function _prepareNextTasks<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel>>(checkpoint: ReadonlyCheckpoint, processes: Nn, channels: Cc, config: RunnableConfig, forExecution: false, extra: NextTaskExtraFields): [
|
|
32
|
-
export declare function _prepareNextTasks<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel>>(checkpoint: ReadonlyCheckpoint, processes: Nn, channels: Cc, config: RunnableConfig, forExecution: true, extra: NextTaskExtraFields):
|
|
34
|
+
export declare function _prepareNextTasks<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel>>(checkpoint: ReadonlyCheckpoint, processes: Nn, channels: Cc, config: RunnableConfig, forExecution: false, extra: NextTaskExtraFields): PregelTaskDescription[];
|
|
35
|
+
export declare function _prepareNextTasks<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel>>(checkpoint: ReadonlyCheckpoint, processes: Nn, channels: Cc, config: RunnableConfig, forExecution: true, extra: NextTaskExtraFields): PregelExecutableTask<keyof Nn, keyof Cc>[];
|