@langchain/langgraph 0.2.40 → 0.2.42

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.
Files changed (86) hide show
  1. package/README.md +237 -154
  2. package/dist/channels/any_value.cjs +10 -10
  3. package/dist/channels/any_value.d.ts +1 -1
  4. package/dist/channels/any_value.js +10 -10
  5. package/dist/channels/ephemeral_value.cjs +10 -9
  6. package/dist/channels/ephemeral_value.d.ts +1 -1
  7. package/dist/channels/ephemeral_value.js +10 -9
  8. package/dist/channels/last_value.cjs +8 -7
  9. package/dist/channels/last_value.d.ts +1 -1
  10. package/dist/channels/last_value.js +8 -7
  11. package/dist/constants.cjs +33 -6
  12. package/dist/constants.d.ts +17 -2
  13. package/dist/constants.js +32 -5
  14. package/dist/errors.d.ts +3 -3
  15. package/dist/func/index.cjs +272 -0
  16. package/dist/func/index.d.ts +310 -0
  17. package/dist/func/index.js +267 -0
  18. package/dist/func/types.cjs +15 -0
  19. package/dist/func/types.d.ts +59 -0
  20. package/dist/func/types.js +11 -0
  21. package/dist/graph/graph.cjs +31 -35
  22. package/dist/graph/graph.d.ts +1 -5
  23. package/dist/graph/graph.js +1 -5
  24. package/dist/graph/index.cjs +1 -3
  25. package/dist/graph/index.d.ts +1 -1
  26. package/dist/graph/index.js +1 -1
  27. package/dist/graph/message.d.ts +1 -1
  28. package/dist/graph/state.cjs +17 -17
  29. package/dist/graph/state.d.ts +2 -1
  30. package/dist/graph/state.js +2 -2
  31. package/dist/index.cjs +8 -0
  32. package/dist/index.d.ts +3 -0
  33. package/dist/index.js +3 -0
  34. package/dist/interrupt.cjs +21 -34
  35. package/dist/interrupt.d.ts +1 -1
  36. package/dist/interrupt.js +22 -35
  37. package/dist/prebuilt/agent_executor.cjs +3 -3
  38. package/dist/prebuilt/agent_executor.d.ts +1 -1
  39. package/dist/prebuilt/agent_executor.js +1 -1
  40. package/dist/prebuilt/chat_agent_executor.cjs +3 -3
  41. package/dist/prebuilt/chat_agent_executor.d.ts +1 -1
  42. package/dist/prebuilt/chat_agent_executor.js +1 -1
  43. package/dist/prebuilt/react_agent_executor.cjs +79 -12
  44. package/dist/prebuilt/react_agent_executor.d.ts +35 -4
  45. package/dist/prebuilt/react_agent_executor.js +79 -13
  46. package/dist/prebuilt/tool_node.cjs +1 -2
  47. package/dist/prebuilt/tool_node.d.ts +1 -1
  48. package/dist/prebuilt/tool_node.js +1 -2
  49. package/dist/pregel/algo.cjs +121 -12
  50. package/dist/pregel/algo.d.ts +8 -6
  51. package/dist/pregel/algo.js +122 -13
  52. package/dist/pregel/call.cjs +77 -0
  53. package/dist/pregel/call.d.ts +15 -0
  54. package/dist/pregel/call.js +71 -0
  55. package/dist/pregel/index.cjs +59 -96
  56. package/dist/pregel/index.d.ts +1 -10
  57. package/dist/pregel/index.js +61 -98
  58. package/dist/pregel/io.cjs +6 -1
  59. package/dist/pregel/io.js +7 -2
  60. package/dist/pregel/loop.cjs +109 -75
  61. package/dist/pregel/loop.d.ts +17 -23
  62. package/dist/pregel/loop.js +110 -75
  63. package/dist/pregel/messages.d.ts +1 -1
  64. package/dist/pregel/retry.cjs +22 -50
  65. package/dist/pregel/retry.d.ts +6 -6
  66. package/dist/pregel/retry.js +22 -50
  67. package/dist/pregel/runner.cjs +275 -0
  68. package/dist/pregel/runner.d.ts +64 -0
  69. package/dist/pregel/runner.js +271 -0
  70. package/dist/pregel/stream.cjs +71 -0
  71. package/dist/pregel/stream.d.ts +17 -0
  72. package/dist/pregel/stream.js +67 -0
  73. package/dist/pregel/types.cjs +54 -0
  74. package/dist/pregel/types.d.ts +78 -6
  75. package/dist/pregel/types.js +51 -1
  76. package/dist/pregel/utils/config.cjs +26 -1
  77. package/dist/pregel/utils/config.d.ts +14 -0
  78. package/dist/pregel/utils/config.js +22 -0
  79. package/dist/pregel/write.d.ts +1 -1
  80. package/dist/utils.cjs +15 -1
  81. package/dist/utils.d.ts +3 -1
  82. package/dist/utils.js +12 -0
  83. package/dist/web.cjs +7 -5
  84. package/dist/web.d.ts +4 -4
  85. package/dist/web.js +3 -3
  86. package/package.json +8 -8
@@ -0,0 +1,271 @@
1
+ import { Call } from "./types.js";
2
+ import { CONFIG_KEY_SEND, CONFIG_KEY_SCRATCHPAD, PUSH, ERROR, INTERRUPT, RESUME, NO_WRITES, TAG_HIDDEN, RETURN, CONFIG_KEY_CALL, } from "../constants.js";
3
+ import { isGraphBubbleUp, isGraphInterrupt, } from "../errors.js";
4
+ import { _runWithRetry } from "./retry.js";
5
+ /**
6
+ * Responsible for handling task execution on each tick of the {@link PregelLoop}.
7
+ */
8
+ export class PregelRunner {
9
+ /**
10
+ * Construct a new PregelRunner, which executes tasks from the provided PregelLoop.
11
+ * @param loop - The PregelLoop that produces tasks for this runner to execute.
12
+ */
13
+ constructor({ loop, nodeFinished, }) {
14
+ Object.defineProperty(this, "nodeFinished", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: void 0
19
+ });
20
+ Object.defineProperty(this, "loop", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: void 0
25
+ });
26
+ this.loop = loop;
27
+ this.nodeFinished = nodeFinished;
28
+ }
29
+ /**
30
+ * Execute tasks from the current step of the PregelLoop.
31
+ *
32
+ * Note: this method does NOT call {@link PregelLoop}#tick. That must be handled externally.
33
+ * @param options - Options for the execution.
34
+ */
35
+ async tick(options = {}) {
36
+ const { timeout, signal, retryPolicy, onStepWrite } = options;
37
+ let graphInterrupt;
38
+ // Start task execution
39
+ const pendingTasks = Object.values(this.loop.tasks).filter((t) => t.writes.length === 0);
40
+ const taskStream = this._executeTasksWithRetry(pendingTasks, {
41
+ stepTimeout: timeout,
42
+ signal,
43
+ retryPolicy,
44
+ });
45
+ for await (const { task, error } of taskStream) {
46
+ graphInterrupt = this._commit(task, error) ?? graphInterrupt;
47
+ }
48
+ onStepWrite?.(this.loop.step, Object.values(this.loop.tasks)
49
+ .map((task) => task.writes)
50
+ .flat());
51
+ if (graphInterrupt) {
52
+ throw graphInterrupt;
53
+ }
54
+ }
55
+ /**
56
+ * Concurrently executes tasks with the requested retry policy, yielding a {@link SettledPregelTask} for each task as it completes.
57
+ * @param tasks - The tasks to execute.
58
+ * @param options - Options for the execution.
59
+ */
60
+ async *_executeTasksWithRetry(tasks, options) {
61
+ const { stepTimeout, retryPolicy } = options ?? {};
62
+ let signal = options?.signal;
63
+ const promiseAddedSymbol = Symbol.for("promiseAdded");
64
+ let addedPromiseSignal;
65
+ let addedPromiseWait;
66
+ function waitHandler(resolve) {
67
+ addedPromiseSignal = () => {
68
+ addedPromiseWait = new Promise(waitHandler);
69
+ resolve(promiseAddedSymbol);
70
+ };
71
+ }
72
+ addedPromiseWait = new Promise(waitHandler);
73
+ const executingTasksMap = {};
74
+ const writer = (task, writes, { calls } = {}) => {
75
+ if (writes.every(([channel]) => channel !== PUSH)) {
76
+ return task.config?.configurable?.[CONFIG_KEY_SEND]?.(writes) ?? [];
77
+ }
78
+ // Schedule PUSH tasks, collect promises
79
+ const scratchpad = task.config?.configurable?.[CONFIG_KEY_SCRATCHPAD];
80
+ const rtn = {};
81
+ for (const [idx, write] of writes.entries()) {
82
+ const [channel] = write;
83
+ if (channel !== PUSH) {
84
+ continue;
85
+ }
86
+ const wcall = calls?.[idx];
87
+ const cnt = scratchpad.callCounter;
88
+ scratchpad.callCounter += 1;
89
+ if (wcall == null) {
90
+ throw new Error("BUG: No call found");
91
+ }
92
+ const nextTask = this.loop.acceptPush(task, cnt, wcall);
93
+ if (!nextTask) {
94
+ continue;
95
+ }
96
+ // Check if this task is already running
97
+ const existingPromise = executingTasksMap[nextTask.id];
98
+ if (existingPromise !== undefined) {
99
+ // If the parent task was retried, the next task might already be running
100
+ rtn[idx] = existingPromise;
101
+ }
102
+ else if (nextTask.writes.length > 0) {
103
+ // If it already ran, return the result
104
+ const returns = nextTask.writes.filter(([c]) => c === RETURN);
105
+ const errors = nextTask.writes.filter(([c]) => c === ERROR);
106
+ if (returns.length > 0) {
107
+ // Task completed successfully
108
+ if (returns.length === 1) {
109
+ rtn[idx] = Promise.resolve(returns[0][1]);
110
+ }
111
+ else {
112
+ // should be unreachable
113
+ throw new Error(`BUG: multiple returns found for task ${nextTask.name}__${nextTask.id}`);
114
+ }
115
+ }
116
+ else if (errors.length > 0) {
117
+ if (errors.length === 1) {
118
+ const errorValue = errors[0][1];
119
+ // Task failed
120
+ const error =
121
+ // eslint-disable-next-line no-instanceof/no-instanceof
122
+ errorValue instanceof Error
123
+ ? errorValue
124
+ : new Error(String(errorValue));
125
+ rtn[idx] = Promise.reject(error);
126
+ }
127
+ else {
128
+ // the only way this should happen is if the task executes multiple times and writes aren't cleared
129
+ throw new Error(`BUG: multiple errors found for task ${nextTask.name}__${nextTask.id}`);
130
+ }
131
+ }
132
+ }
133
+ else {
134
+ // Schedule the next task with retry
135
+ const prom = _runWithRetry(nextTask, retryPolicy, {
136
+ [CONFIG_KEY_SEND]: writer.bind(this, nextTask),
137
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
138
+ [CONFIG_KEY_CALL]: call.bind(this, nextTask),
139
+ });
140
+ executingTasksMap[nextTask.id] = prom;
141
+ addedPromiseSignal();
142
+ rtn[idx] = prom.then(({ result, error }) => {
143
+ if (error) {
144
+ return Promise.reject(error);
145
+ }
146
+ return result;
147
+ });
148
+ }
149
+ }
150
+ return Object.values(rtn);
151
+ };
152
+ const call = (task, func, name, input, options = {}) => {
153
+ const result = writer(task, [[PUSH, null]], {
154
+ calls: [
155
+ new Call({
156
+ func,
157
+ name,
158
+ input,
159
+ retry: options.retry,
160
+ callbacks: options.callbacks,
161
+ }),
162
+ ],
163
+ });
164
+ // eslint-disable-next-line no-instanceof/no-instanceof
165
+ if (result !== undefined) {
166
+ if (result.length === 1) {
167
+ return result[0];
168
+ }
169
+ return Promise.all(result);
170
+ }
171
+ return Promise.resolve();
172
+ };
173
+ if (stepTimeout && signal) {
174
+ if ("any" in AbortSignal) {
175
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
176
+ signal = AbortSignal.any([
177
+ signal,
178
+ AbortSignal.timeout(stepTimeout),
179
+ ]);
180
+ }
181
+ }
182
+ else if (stepTimeout) {
183
+ signal = AbortSignal.timeout(stepTimeout);
184
+ }
185
+ if (signal?.aborted) {
186
+ // note: don't use throwIfAborted here because it throws a DOMException,
187
+ // which isn't consistent with how we throw on abort below.
188
+ throw new Error("Abort");
189
+ }
190
+ // Start tasks
191
+ Object.assign(executingTasksMap, Object.fromEntries(tasks.map((pregelTask) => {
192
+ return [
193
+ pregelTask.id,
194
+ _runWithRetry(pregelTask, retryPolicy, {
195
+ [CONFIG_KEY_SEND]: writer?.bind(this, pregelTask),
196
+ [CONFIG_KEY_CALL]: call?.bind(this, pregelTask),
197
+ }).catch((error) => {
198
+ return { task: pregelTask, error };
199
+ }),
200
+ ];
201
+ })));
202
+ let listener;
203
+ const signalPromise = new Promise((_resolve, reject) => {
204
+ listener = () => reject(new Error("Abort"));
205
+ signal?.addEventListener("abort", listener);
206
+ }).finally(() => signal?.removeEventListener("abort", listener));
207
+ while (Object.keys(executingTasksMap).length > 0) {
208
+ const settledTask = await Promise.race([
209
+ ...Object.values(executingTasksMap),
210
+ signalPromise,
211
+ addedPromiseWait,
212
+ ]);
213
+ if (settledTask === promiseAddedSymbol) {
214
+ continue;
215
+ }
216
+ yield settledTask;
217
+ delete executingTasksMap[settledTask.task.id];
218
+ }
219
+ }
220
+ /**
221
+ * Determines what writes to apply based on whether the task completed successfully, and what type of error occurred.
222
+ *
223
+ * Throws an error if the error is a {@link GraphBubbleUp} error and {@link PregelLoop}#isNested is true.
224
+ *
225
+ * Note that in the case of a {@link GraphBubbleUp} error that is not a {@link GraphInterrupt}, like a {@link Command}, this method does not apply any writes.
226
+ *
227
+ * @param task - The task to commit.
228
+ * @param error - The error that occurred, if any.
229
+ * @returns The {@link GraphInterrupt} that occurred, if the user's code threw one.
230
+ */
231
+ _commit(task, error) {
232
+ let graphInterrupt;
233
+ if (error !== undefined) {
234
+ if (isGraphBubbleUp(error)) {
235
+ if (this.loop.isNested) {
236
+ throw error;
237
+ }
238
+ if (isGraphInterrupt(error)) {
239
+ graphInterrupt = error;
240
+ if (error.interrupts.length) {
241
+ const interrupts = error.interrupts.map((interrupt) => [INTERRUPT, interrupt]);
242
+ const resumes = task.writes.filter((w) => w[0] === RESUME);
243
+ if (resumes.length) {
244
+ interrupts.push(...resumes);
245
+ }
246
+ this.loop.putWrites(task.id, interrupts);
247
+ }
248
+ }
249
+ }
250
+ else {
251
+ this.loop.putWrites(task.id, [
252
+ [ERROR, { message: error.message, name: error.name }],
253
+ ]);
254
+ throw error;
255
+ }
256
+ }
257
+ else {
258
+ if (this.nodeFinished &&
259
+ (task.config?.tags == null || !task.config.tags.includes(TAG_HIDDEN))) {
260
+ this.nodeFinished(String(task.name));
261
+ }
262
+ if (task.writes.length === 0) {
263
+ // Add no writes marker
264
+ task.writes.push([NO_WRITES, null]);
265
+ }
266
+ // Save task writes to checkpointer
267
+ this.loop.putWrites(task.id, task.writes);
268
+ }
269
+ return graphInterrupt;
270
+ }
271
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IterableReadableWritableStream = void 0;
4
+ const stream_1 = require("@langchain/core/utils/stream");
5
+ class IterableReadableWritableStream extends stream_1.IterableReadableStream {
6
+ get closed() {
7
+ return this._closed;
8
+ }
9
+ constructor(params) {
10
+ let streamControllerPromiseResolver;
11
+ const streamControllerPromise = new Promise((resolve) => {
12
+ streamControllerPromiseResolver = resolve;
13
+ });
14
+ super({
15
+ start: (controller) => {
16
+ streamControllerPromiseResolver(controller);
17
+ },
18
+ });
19
+ Object.defineProperty(this, "modes", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: void 0
24
+ });
25
+ Object.defineProperty(this, "controller", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: void 0
30
+ });
31
+ Object.defineProperty(this, "passthroughFn", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: void 0
36
+ });
37
+ Object.defineProperty(this, "_closed", {
38
+ enumerable: true,
39
+ configurable: true,
40
+ writable: true,
41
+ value: false
42
+ });
43
+ // .start() will always be called before the stream can be interacted
44
+ // with anyway
45
+ void streamControllerPromise.then((controller) => {
46
+ this.controller = controller;
47
+ });
48
+ this.passthroughFn = params.passthroughFn;
49
+ this.modes = params.modes;
50
+ }
51
+ push(chunk) {
52
+ this.passthroughFn?.(chunk);
53
+ this.controller.enqueue(chunk);
54
+ }
55
+ close() {
56
+ try {
57
+ this.controller.close();
58
+ }
59
+ catch (e) {
60
+ // pass
61
+ }
62
+ finally {
63
+ this._closed = true;
64
+ }
65
+ }
66
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
+ error(e) {
68
+ this.controller.error(e);
69
+ }
70
+ }
71
+ exports.IterableReadableWritableStream = IterableReadableWritableStream;
@@ -0,0 +1,17 @@
1
+ import { IterableReadableStream } from "@langchain/core/utils/stream";
2
+ import { StreamMode } from "./types.js";
3
+ export type StreamChunk = [string[], StreamMode, unknown];
4
+ export declare class IterableReadableWritableStream extends IterableReadableStream<StreamChunk> {
5
+ modes: Set<StreamMode>;
6
+ private controller;
7
+ private passthroughFn?;
8
+ private _closed;
9
+ get closed(): boolean;
10
+ constructor(params: {
11
+ passthroughFn?: (chunk: StreamChunk) => void;
12
+ modes: Set<StreamMode>;
13
+ });
14
+ push(chunk: StreamChunk): void;
15
+ close(): void;
16
+ error(e: any): void;
17
+ }
@@ -0,0 +1,67 @@
1
+ import { IterableReadableStream } from "@langchain/core/utils/stream";
2
+ export class IterableReadableWritableStream extends IterableReadableStream {
3
+ get closed() {
4
+ return this._closed;
5
+ }
6
+ constructor(params) {
7
+ let streamControllerPromiseResolver;
8
+ const streamControllerPromise = new Promise((resolve) => {
9
+ streamControllerPromiseResolver = resolve;
10
+ });
11
+ super({
12
+ start: (controller) => {
13
+ streamControllerPromiseResolver(controller);
14
+ },
15
+ });
16
+ Object.defineProperty(this, "modes", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: void 0
21
+ });
22
+ Object.defineProperty(this, "controller", {
23
+ enumerable: true,
24
+ configurable: true,
25
+ writable: true,
26
+ value: void 0
27
+ });
28
+ Object.defineProperty(this, "passthroughFn", {
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true,
32
+ value: void 0
33
+ });
34
+ Object.defineProperty(this, "_closed", {
35
+ enumerable: true,
36
+ configurable: true,
37
+ writable: true,
38
+ value: false
39
+ });
40
+ // .start() will always be called before the stream can be interacted
41
+ // with anyway
42
+ void streamControllerPromise.then((controller) => {
43
+ this.controller = controller;
44
+ });
45
+ this.passthroughFn = params.passthroughFn;
46
+ this.modes = params.modes;
47
+ }
48
+ push(chunk) {
49
+ this.passthroughFn?.(chunk);
50
+ this.controller.enqueue(chunk);
51
+ }
52
+ close() {
53
+ try {
54
+ this.controller.close();
55
+ }
56
+ catch (e) {
57
+ // pass
58
+ }
59
+ finally {
60
+ this._closed = true;
61
+ }
62
+ }
63
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
+ error(e) {
65
+ this.controller.error(e);
66
+ }
67
+ }
@@ -1,2 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCall = exports.Call = void 0;
4
+ class Call {
5
+ constructor({ func, name, input, retry, callbacks }) {
6
+ Object.defineProperty(this, "func", {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value: void 0
11
+ });
12
+ Object.defineProperty(this, "name", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: void 0
17
+ });
18
+ Object.defineProperty(this, "input", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ Object.defineProperty(this, "retry", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: void 0
29
+ });
30
+ Object.defineProperty(this, "callbacks", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: void 0
35
+ });
36
+ Object.defineProperty(this, "__lg_type", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: "call"
41
+ });
42
+ this.func = func;
43
+ this.name = name;
44
+ this.input = input;
45
+ this.retry = retry;
46
+ this.callbacks = callbacks;
47
+ }
48
+ }
49
+ exports.Call = Call;
50
+ function isCall(value) {
51
+ return (typeof value === "object" &&
52
+ value !== null &&
53
+ "__lg_type" in value &&
54
+ value.__lg_type === "call");
55
+ }
56
+ exports.isCall = isCall;
@@ -8,6 +8,9 @@ import { RetryPolicy } from "./utils/index.js";
8
8
  import { Interrupt } from "../constants.js";
9
9
  import { type ManagedValueSpec } from "../managed/base.js";
10
10
  import { LangGraphRunnableConfig } from "./runnable_types.js";
11
+ /**
12
+ * Selects the type of output you'll receive when streaming from the graph. See [Streaming](/langgraphjs/how-tos/#streaming) for more details.
13
+ */
11
14
  export type StreamMode = "values" | "updates" | "debug" | "messages" | "custom";
12
15
  export type PregelInputType = any;
13
16
  export type PregelOutputType = any;
@@ -15,8 +18,12 @@ export type PregelOutputType = any;
15
18
  * Config for executing the graph.
16
19
  */
17
20
  export interface PregelOptions<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel | ManagedValueSpec>, ConfigurableFieldType extends Record<string, any> = Record<string, any>> extends RunnableConfig<ConfigurableFieldType> {
18
- /** The stream mode for the graph run. Default is ["values"]. */
21
+ /**
22
+ * The stream mode for the graph run. See [Streaming](/langgraphjs/how-tos/#streaming) for more details.
23
+ * @default ["values"]
24
+ */
19
25
  streamMode?: StreamMode | StreamMode[];
26
+ /** The input keys to retrieve from the checkpoint on resume. You generally don't need to set this. */
20
27
  inputKeys?: keyof Cc | Array<keyof Cc>;
21
28
  /** The output keys to retrieve from the graph run. */
22
29
  outputKeys?: keyof Cc | Array<keyof Cc>;
@@ -54,27 +61,57 @@ export interface PregelInterface<Nn extends StrRecord<string, PregelNode>, Cc ex
54
61
  stream(input: PregelInputType, options?: Partial<PregelOptions<Nn, Cc, ConfigurableFieldType>>): Promise<IterableReadableStream<PregelOutputType>>;
55
62
  invoke(input: PregelInputType, options?: Partial<PregelOptions<Nn, Cc, ConfigurableFieldType>>): Promise<PregelOutputType>;
56
63
  }
64
+ /**
65
+ * Parameters for creating a Pregel graph.
66
+ * @internal
67
+ */
57
68
  export type PregelParams<Nn extends StrRecord<string, PregelNode>, Cc extends StrRecord<string, BaseChannel | ManagedValueSpec>> = {
69
+ /**
70
+ * The name of the graph. @see {@link Runnable.name}
71
+ */
72
+ name?: string;
73
+ /**
74
+ * The nodes in the graph.
75
+ */
58
76
  nodes: Nn;
77
+ /**
78
+ * The channels in the graph.
79
+ */
59
80
  channels: Cc;
60
81
  /**
82
+ * Whether to validate the graph.
83
+ *
61
84
  * @default true
62
85
  */
63
86
  autoValidate?: boolean;
64
87
  /**
65
- * @default "values"
88
+ * The stream mode for the graph run. See [Streaming](/langgraphjs/how-tos/#streaming) for more details.
89
+ *
90
+ * @default ["values"]
66
91
  */
67
92
  streamMode?: StreamMode | StreamMode[];
93
+ /**
94
+ * The input channels for the graph run.
95
+ */
68
96
  inputChannels: keyof Cc | Array<keyof Cc>;
97
+ /**
98
+ * The output channels for the graph run.
99
+ */
69
100
  outputChannels: keyof Cc | Array<keyof Cc>;
70
101
  /**
102
+ * After processing one of the nodes named in this list, the graph will be interrupted and a resume {@link Command} must be provided to proceed with the execution of this thread.
71
103
  * @default []
72
104
  */
73
105
  interruptAfter?: Array<keyof Nn> | All;
74
106
  /**
107
+ * Before processing one of the nodes named in this list, the graph will be interrupted and a resume {@link Command} must be provided to proceed with the execution of this thread.
75
108
  * @default []
76
109
  */
77
110
  interruptBefore?: Array<keyof Nn> | All;
111
+ /**
112
+ * The channels to stream from the graph run.
113
+ * @default []
114
+ */
78
115
  streamChannels?: keyof Cc | Array<keyof Cc>;
79
116
  /**
80
117
  * @default undefined
@@ -84,8 +121,17 @@ export type PregelParams<Nn extends StrRecord<string, PregelNode>, Cc extends St
84
121
  * @default false
85
122
  */
86
123
  debug?: boolean;
124
+ /**
125
+ * The {@link BaseCheckpointSaver | checkpointer} to use for the graph run.
126
+ */
87
127
  checkpointer?: BaseCheckpointSaver | false;
128
+ /**
129
+ * The default retry policy for this graph. For defaults, see {@link RetryPolicy}.
130
+ */
88
131
  retryPolicy?: RetryPolicy;
132
+ /**
133
+ * The configuration for the graph run.
134
+ */
89
135
  config?: LangGraphRunnableConfig;
90
136
  /**
91
137
  * Memory store to use for SharedValues.
@@ -98,7 +144,7 @@ export interface PregelTaskDescription {
98
144
  readonly error?: unknown;
99
145
  readonly interrupts: Interrupt[];
100
146
  readonly state?: LangGraphRunnableConfig | StateSnapshot;
101
- readonly path?: [string, ...(string | number)[]];
147
+ readonly path?: TaskPath;
102
148
  }
103
149
  export interface PregelExecutableTask<N extends PropertyKey, C extends PropertyKey> {
104
150
  readonly name: N;
@@ -109,7 +155,7 @@ export interface PregelExecutableTask<N extends PropertyKey, C extends PropertyK
109
155
  readonly triggers: Array<string>;
110
156
  readonly retry_policy?: RetryPolicy;
111
157
  readonly id: string;
112
- readonly path?: [string, ...(string | number)[]];
158
+ readonly path?: TaskPath;
113
159
  readonly subgraphs?: Runnable[];
114
160
  readonly writers: Runnable[];
115
161
  }
@@ -144,9 +190,35 @@ export interface StateSnapshot {
144
190
  */
145
191
  readonly tasks: PregelTaskDescription[];
146
192
  }
147
- export type PregelScratchpad<Resume> = {
193
+ export type PregelScratchpad<Resume = unknown> = {
194
+ /** Counter for tracking call invocations */
195
+ callCounter: number;
196
+ /** Counter for tracking interrupts */
148
197
  interruptCounter: number;
149
- usedNullResume: boolean;
198
+ /** List of resume values */
150
199
  resume: Resume[];
200
+ /** Single resume value for null task ID */
201
+ nullResume: Resume;
202
+ };
203
+ export type CallOptions = {
204
+ func: (...args: unknown[]) => unknown | Promise<unknown>;
205
+ name: string;
206
+ input: unknown;
207
+ retry?: RetryPolicy;
208
+ callbacks?: unknown;
151
209
  };
210
+ export declare class Call {
211
+ func: (...args: unknown[]) => unknown | Promise<unknown>;
212
+ name: string;
213
+ input: unknown;
214
+ retry?: RetryPolicy;
215
+ callbacks?: unknown;
216
+ readonly __lg_type = "call";
217
+ constructor({ func, name, input, retry, callbacks }: CallOptions);
218
+ }
219
+ export declare function isCall(value: unknown): value is Call;
220
+ export type SimpleTaskPath = [string, string | number];
221
+ export type VariadicTaskPath = [string, ...(string | number)[]];
222
+ export type CallTaskPath = [string, ...(string | number)[], Call] | [string, TaskPath, ...(string | number)[], Call];
223
+ export type TaskPath = SimpleTaskPath | CallTaskPath | VariadicTaskPath;
152
224
  export {};
@@ -1 +1,51 @@
1
- export {};
1
+ export class Call {
2
+ constructor({ func, name, input, retry, callbacks }) {
3
+ Object.defineProperty(this, "func", {
4
+ enumerable: true,
5
+ configurable: true,
6
+ writable: true,
7
+ value: void 0
8
+ });
9
+ Object.defineProperty(this, "name", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: void 0
14
+ });
15
+ Object.defineProperty(this, "input", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: void 0
20
+ });
21
+ Object.defineProperty(this, "retry", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: void 0
26
+ });
27
+ Object.defineProperty(this, "callbacks", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: void 0
32
+ });
33
+ Object.defineProperty(this, "__lg_type", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: "call"
38
+ });
39
+ this.func = func;
40
+ this.name = name;
41
+ this.input = input;
42
+ this.retry = retry;
43
+ this.callbacks = callbacks;
44
+ }
45
+ }
46
+ export function isCall(value) {
47
+ return (typeof value === "object" &&
48
+ value !== null &&
49
+ "__lg_type" in value &&
50
+ value.__lg_type === "call");
51
+ }