@langchain/langgraph-api 1.4.3 → 1.4.5
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/api/assistants.mjs +5 -2
- package/dist/queue.mjs +31 -21
- package/dist/stream.mjs +12 -5
- package/dist/utils/runnableConfig.d.mts +19 -0
- package/dist/utils/runnableConfig.mjs +3 -0
- package/package.json +13 -13
package/dist/api/assistants.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import { getRuntimeGraphSchema } from "../graph/parser/index.mjs";
|
|
|
7
7
|
import { HTTPException } from "hono/http-exception";
|
|
8
8
|
import * as schemas from "../schemas.mjs";
|
|
9
9
|
import { assistants } from "../storage/context.mjs";
|
|
10
|
+
import { omitUndefined } from "../utils/runnableConfig.mjs";
|
|
10
11
|
const api = new Hono();
|
|
11
12
|
const RunnableConfigSchema = z.object({
|
|
12
13
|
tags: z.array(z.string()).optional(),
|
|
@@ -20,7 +21,9 @@ const RunnableConfigSchema = z.object({
|
|
|
20
21
|
const getRunnableConfig = (userConfig) => {
|
|
21
22
|
if (!userConfig)
|
|
22
23
|
return {};
|
|
23
|
-
|
|
24
|
+
// Omit undefined keys so callers that spread this into Pregel options do not
|
|
25
|
+
// wipe graph `withConfig` defaults (notably recursionLimit → 25).
|
|
26
|
+
return omitUndefined({
|
|
24
27
|
configurable: userConfig.configurable,
|
|
25
28
|
tags: userConfig.tags,
|
|
26
29
|
metadata: userConfig.metadata,
|
|
@@ -28,7 +31,7 @@ const getRunnableConfig = (userConfig) => {
|
|
|
28
31
|
maxConcurrency: userConfig.max_concurrency,
|
|
29
32
|
recursionLimit: userConfig.recursion_limit,
|
|
30
33
|
runId: userConfig.run_id,
|
|
31
|
-
};
|
|
34
|
+
});
|
|
32
35
|
};
|
|
33
36
|
api.post("/assistants", zValidator("json", schemas.AssistantCreate), async (c) => {
|
|
34
37
|
// Create Assistant
|
package/dist/queue.mjs
CHANGED
|
@@ -41,6 +41,7 @@ const worker = async (ops, run, attempt, signal) => {
|
|
|
41
41
|
...result,
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
|
+
const isInterrupted = () => signal.aborted && signal.reason === "interrupt";
|
|
44
45
|
try {
|
|
45
46
|
if (attempt > MAX_RETRY_ATTEMPTS) {
|
|
46
47
|
throw new Error(`Run ${run.run_id} exceeded max attempts`);
|
|
@@ -65,12 +66,14 @@ const worker = async (ops, run, attempt, signal) => {
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
catch (error) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
if (!isInterrupted()) {
|
|
70
|
+
await ops.runs.stream.publish({
|
|
71
|
+
runId,
|
|
72
|
+
resumable,
|
|
73
|
+
event: "error",
|
|
74
|
+
data: serializeError(error),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
74
77
|
throw error;
|
|
75
78
|
}
|
|
76
79
|
endedAt = new Date();
|
|
@@ -87,21 +90,28 @@ const worker = async (ops, run, attempt, signal) => {
|
|
|
87
90
|
}
|
|
88
91
|
catch (error) {
|
|
89
92
|
endedAt = new Date();
|
|
90
|
-
if (
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
93
|
+
if (isInterrupted()) {
|
|
94
|
+
checkpoint = undefined;
|
|
95
|
+
status = "interrupted";
|
|
96
|
+
await ops.runs.setStatus(run.run_id, status);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
if (error instanceof Error)
|
|
100
|
+
exception = error;
|
|
101
|
+
logError(error, {
|
|
102
|
+
prefix: "Background run failed",
|
|
103
|
+
context: {
|
|
104
|
+
run_id: run.run_id,
|
|
105
|
+
run_attempt: attempt,
|
|
106
|
+
run_created_at: run.created_at,
|
|
107
|
+
run_started_at: startedAt,
|
|
108
|
+
run_ended_at: endedAt,
|
|
109
|
+
run_exec_ms: endedAt.valueOf() - startedAt.valueOf(),
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
status = "error";
|
|
113
|
+
await ops.runs.setStatus(run.run_id, status);
|
|
114
|
+
}
|
|
105
115
|
}
|
|
106
116
|
finally {
|
|
107
117
|
if (temporary) {
|
package/dist/stream.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { Client as LangSmithClient, getDefaultProjectName } from "langsmith";
|
|
|
5
5
|
import { getLangGraphCommand } from "./command.mjs";
|
|
6
6
|
import { PROTOCOL_STREAM_RUN_KEY } from "./protocol/constants.mjs";
|
|
7
7
|
import { checkLangGraphSemver } from "./semver/index.mjs";
|
|
8
|
-
import { runnableConfigToCheckpoint, taskRunnableConfigToCheckpoint, } from "./utils/runnableConfig.mjs";
|
|
8
|
+
import { omitUndefined, runnableConfigToCheckpoint, taskRunnableConfigToCheckpoint, } from "./utils/runnableConfig.mjs";
|
|
9
9
|
const isRunnableConfig = (config) => {
|
|
10
10
|
if (typeof config !== "object" || config == null)
|
|
11
11
|
return false;
|
|
@@ -114,7 +114,11 @@ export async function* streamState(run, options) {
|
|
|
114
114
|
: undefined;
|
|
115
115
|
const events = graph.streamEvents(kwargs.command != null
|
|
116
116
|
? getLangGraphCommand(kwargs.command)
|
|
117
|
-
: (kwargs.input ?? null),
|
|
117
|
+
: (kwargs.input ?? null),
|
|
118
|
+
// Omit undefined keys: Pregel spreads options over the graph's withConfig
|
|
119
|
+
// defaults, so `recursionLimit: undefined` would wipe a bound limit back
|
|
120
|
+
// to langchain-core's DEFAULT_RECURSION_LIMIT (25).
|
|
121
|
+
omitUndefined({
|
|
118
122
|
version: "v2",
|
|
119
123
|
interruptAfter: kwargs.interrupt_after,
|
|
120
124
|
interruptBefore: kwargs.interrupt_before,
|
|
@@ -128,7 +132,7 @@ export async function* streamState(run, options) {
|
|
|
128
132
|
streamMode: [...libStreamMode],
|
|
129
133
|
signal: options?.signal,
|
|
130
134
|
...(tracer && { callbacks: [tracer] }),
|
|
131
|
-
});
|
|
135
|
+
}));
|
|
132
136
|
const messages = {};
|
|
133
137
|
const completedIds = new Set();
|
|
134
138
|
for await (const event of events) {
|
|
@@ -330,7 +334,10 @@ export async function* streamStateV2(run, options) {
|
|
|
330
334
|
const graphInput = kwargs.command != null
|
|
331
335
|
? getLangGraphCommand(kwargs.command)
|
|
332
336
|
: (kwargs.input ?? null);
|
|
333
|
-
|
|
337
|
+
// Omit undefined keys: Pregel spreads options over the graph's withConfig
|
|
338
|
+
// defaults, so `recursionLimit: undefined` would wipe a bound limit back
|
|
339
|
+
// to langchain-core's DEFAULT_RECURSION_LIMIT (25).
|
|
340
|
+
const graphOptions = omitUndefined({
|
|
334
341
|
version: "v3",
|
|
335
342
|
interruptAfter: kwargs.interrupt_after,
|
|
336
343
|
interruptBefore: kwargs.interrupt_before,
|
|
@@ -342,7 +349,7 @@ export async function* streamStateV2(run, options) {
|
|
|
342
349
|
runId: run.run_id,
|
|
343
350
|
signal: options?.signal,
|
|
344
351
|
...(tracer && { callbacks: [tracer] }),
|
|
345
|
-
};
|
|
352
|
+
});
|
|
346
353
|
let graphRun;
|
|
347
354
|
try {
|
|
348
355
|
graphRun = await graph.streamEvents(graphInput, graphOptions);
|
|
@@ -1,3 +1,22 @@
|
|
|
1
1
|
import type { Checkpoint, RunnableConfig } from "../storage/types.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Drop keys whose value is `undefined`.
|
|
4
|
+
*
|
|
5
|
+
* Pregel merges invoke/stream options roughly as:
|
|
6
|
+
* `{ recursionLimit: this.config?.recursionLimit, ...options }`.
|
|
7
|
+
* An explicit `recursionLimit: undefined` (e.g. from
|
|
8
|
+
* `kwargs.config?.recursion_limit` when the run omits it) overwrites the
|
|
9
|
+
* graph's `withConfig` default and falls back to langchain-core's 25.
|
|
10
|
+
*
|
|
11
|
+
* Keys whose value type cannot be `undefined` stay required so call sites
|
|
12
|
+
* preserve discriminators like `version: "v2" | "v3"` for streamEvents.
|
|
13
|
+
*/
|
|
14
|
+
type OmitUndefinedKeys<T> = {
|
|
15
|
+
[K in keyof T as undefined extends T[K] ? never : K]: Exclude<T[K], undefined>;
|
|
16
|
+
} & {
|
|
17
|
+
[K in keyof T as undefined extends T[K] ? K : never]?: Exclude<T[K], undefined>;
|
|
18
|
+
};
|
|
19
|
+
export declare function omitUndefined<T extends Record<string, unknown>>(obj: T): OmitUndefinedKeys<T>;
|
|
2
20
|
export declare const runnableConfigToCheckpoint: (config: RunnableConfig | null | undefined) => Checkpoint | null;
|
|
3
21
|
export declare const taskRunnableConfigToCheckpoint: (config: RunnableConfig | null | undefined) => Partial<Checkpoint> | null;
|
|
22
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/langgraph-api",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": "^18.19.0 || >=20.16.0"
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@babel/code-frame": "^7.26.2",
|
|
55
|
-
"@hono/node-server": "^1.
|
|
55
|
+
"@hono/node-server": "^2.1.0",
|
|
56
56
|
"@hono/node-ws": "^1.3.0",
|
|
57
57
|
"@hono/zod-validator": "^0.7.6",
|
|
58
58
|
"@langchain/protocol": "^0.0.18",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"dedent": "^1.5.3",
|
|
62
62
|
"dotenv": "^16.4.7",
|
|
63
63
|
"exit-hook": "^4.0.0",
|
|
64
|
-
"hono": "^4.12.
|
|
64
|
+
"hono": "^4.12.34",
|
|
65
65
|
"langsmith": ">=0.5.19 <1.0.0",
|
|
66
66
|
"open": "^10.1.0",
|
|
67
67
|
"semver": "^7.7.1",
|
|
@@ -71,12 +71,12 @@
|
|
|
71
71
|
"winston": "^3.17.0",
|
|
72
72
|
"winston-console-format": "^1.0.8",
|
|
73
73
|
"zod": "^3.25.76 || ^4",
|
|
74
|
-
"@langchain/langgraph-ui": "1.4.
|
|
74
|
+
"@langchain/langgraph-ui": "1.4.5"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
77
|
"@langchain/core": "^1.1.48",
|
|
78
78
|
"@langchain/langgraph": "^1.3.6",
|
|
79
|
-
"@langchain/langgraph-checkpoint": "
|
|
79
|
+
"@langchain/langgraph-checkpoint": "^1.1.4",
|
|
80
80
|
"@langchain/langgraph-sdk": "^1.9.3-rc.0",
|
|
81
81
|
"ts-node": "^10.9.2",
|
|
82
82
|
"typescript": "^5.5.4"
|
|
@@ -90,23 +90,23 @@
|
|
|
90
90
|
}
|
|
91
91
|
},
|
|
92
92
|
"devDependencies": {
|
|
93
|
-
"@langchain/core": "^1.2.
|
|
93
|
+
"@langchain/core": "^1.2.4",
|
|
94
94
|
"@types/babel__code-frame": "^7.0.6",
|
|
95
95
|
"@types/node": "^18.15.11",
|
|
96
|
-
"@types/react": "^19.2.
|
|
97
|
-
"@types/react-dom": "^19.
|
|
96
|
+
"@types/react": "^19.2.18",
|
|
97
|
+
"@types/react-dom": "^19.2.4",
|
|
98
98
|
"@types/semver": "^7.7.0",
|
|
99
99
|
"deepagents": "^1.10.5",
|
|
100
100
|
"jose": "^6.0.10",
|
|
101
|
-
"langchain": "^1.5.
|
|
101
|
+
"langchain": "^1.5.4",
|
|
102
102
|
"postgres": "^3.4.5",
|
|
103
103
|
"ts-node": "^10.9.2",
|
|
104
104
|
"typescript": "^4.9.5 || ^5.4.5",
|
|
105
|
-
"vitest": "^4.1.
|
|
105
|
+
"vitest": "^4.1.10",
|
|
106
106
|
"wait-port": "^1.1.0",
|
|
107
|
-
"@langchain/langgraph": "1.4.
|
|
108
|
-
"@langchain/langgraph-checkpoint": "1.1.
|
|
109
|
-
"@langchain/langgraph-sdk": "1.9.
|
|
107
|
+
"@langchain/langgraph": "1.4.12",
|
|
108
|
+
"@langchain/langgraph-checkpoint": "1.1.5",
|
|
109
|
+
"@langchain/langgraph-sdk": "1.9.30"
|
|
110
110
|
},
|
|
111
111
|
"scripts": {
|
|
112
112
|
"clean": "rm -rf dist/ .turbo/ ./tests/graphs/.langgraph_api/ ./tests/protocol-v2/graphs/.langgraph_api/",
|