@langchain/langgraph-api 1.5.7 → 1.5.8
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/runs.mjs +3 -32
- package/dist/experimental/embed/runs.mjs +5 -2
- package/dist/schemas.d.mts +10 -0
- package/dist/schemas.mjs +18 -0
- package/dist/stream.d.mts +1 -0
- package/dist/stream.mjs +12 -0
- package/package.json +7 -7
package/dist/api/runs.mjs
CHANGED
|
@@ -8,40 +8,11 @@ import { getAssistantId } from "../graph/load.mjs";
|
|
|
8
8
|
import { logError, logger } from "../logging.mjs";
|
|
9
9
|
import * as schemas from "../schemas.mjs";
|
|
10
10
|
import { runs, threads } from "../storage/context.mjs";
|
|
11
|
+
import { matchesStreamMode } from "../stream.mjs";
|
|
11
12
|
import { getDisconnectAbortSignal, jsonExtra, waitKeepAlive, } from "../utils/hono.mjs";
|
|
12
13
|
import { applyAuthToRunConfig, applyRequestHeadersToRunConfig, } from "../utils/run-auth.mjs";
|
|
13
14
|
import { serialiseAsDict } from "../utils/serde.mjs";
|
|
14
15
|
const api = new Hono();
|
|
15
|
-
// JS SDKs before 1.12 send several stream modes as one JSON array.
|
|
16
|
-
const parseStreamMode = (value) => {
|
|
17
|
-
if (!value.startsWith("["))
|
|
18
|
-
return value ? [value] : [];
|
|
19
|
-
try {
|
|
20
|
-
return JSON.parse(value);
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
return [value];
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
const JoinStreamQuery = z.object({
|
|
27
|
-
cancel_on_disconnect: schemas.coercedBoolean.optional(),
|
|
28
|
-
stream_mode: z
|
|
29
|
-
.union([z.string(), z.array(z.string())])
|
|
30
|
-
.optional()
|
|
31
|
-
.transform((value) => [value ?? []].flat().flatMap(parseStreamMode)),
|
|
32
|
-
});
|
|
33
|
-
const matchesStreamMode = (event, streamMode) => {
|
|
34
|
-
// A run's error is its outcome, not a mode, so no filter drops it.
|
|
35
|
-
if (streamMode.length === 0 || event === "error")
|
|
36
|
-
return true;
|
|
37
|
-
const mode = event.split("|")[0];
|
|
38
|
-
if (streamMode.includes(mode))
|
|
39
|
-
return true;
|
|
40
|
-
// The messages modes stream `messages` (messages-tuple) and `messages/*`
|
|
41
|
-
// (messages) events; as on the Agent Server, either mode keeps both.
|
|
42
|
-
return (mode.startsWith("messages") &&
|
|
43
|
-
(streamMode.includes("messages") || streamMode.includes("messages-tuple")));
|
|
44
|
-
};
|
|
45
16
|
const createValidRun = async (threadId, payload, kwargs) => {
|
|
46
17
|
const { assistant_id: assistantId, ...run } = payload;
|
|
47
18
|
const { auth, headers } = kwargs ?? {};
|
|
@@ -173,7 +144,7 @@ api.post("/runs/stream", zValidator("json", schemas.RunCreate), async (c) => {
|
|
|
173
144
|
});
|
|
174
145
|
});
|
|
175
146
|
// TODO: port to Python API
|
|
176
|
-
api.get("/runs/:run_id/stream", zValidator("param", z.object({ run_id: z.string().uuid() })), zValidator("query", JoinStreamQuery), async (c) => {
|
|
147
|
+
api.get("/runs/:run_id/stream", zValidator("param", z.object({ run_id: z.string().uuid() })), zValidator("query", schemas.JoinStreamQuery), async (c) => {
|
|
177
148
|
const { run_id } = c.req.valid("param");
|
|
178
149
|
const query = c.req.valid("query");
|
|
179
150
|
const lastEventId = c.req.header("Last-Event-ID") || undefined;
|
|
@@ -313,7 +284,7 @@ api.get("/threads/:thread_id/runs/:run_id/join", zValidator("param", z.object({
|
|
|
313
284
|
const { thread_id, run_id } = c.req.valid("param");
|
|
314
285
|
return jsonExtra(c, await runs().join(run_id, thread_id, c.var.auth));
|
|
315
286
|
});
|
|
316
|
-
api.get("/threads/:thread_id/runs/:run_id/stream", zValidator("param", z.object({ thread_id: z.string().uuid(), run_id: z.string().uuid() })), zValidator("query", JoinStreamQuery), async (c) => {
|
|
287
|
+
api.get("/threads/:thread_id/runs/:run_id/stream", zValidator("param", z.object({ thread_id: z.string().uuid(), run_id: z.string().uuid() })), zValidator("query", schemas.JoinStreamQuery), async (c) => {
|
|
317
288
|
// Stream Run Http
|
|
318
289
|
const { thread_id, run_id } = c.req.valid("param");
|
|
319
290
|
const { cancel_on_disconnect, stream_mode } = c.req.valid("query");
|
|
@@ -3,7 +3,7 @@ import { streamSSE } from "hono/streaming";
|
|
|
3
3
|
import { v7 as uuidv7 } from "@langchain/core/utils/uuid";
|
|
4
4
|
import { z } from "zod/v3";
|
|
5
5
|
import * as schemas from "../../schemas.mjs";
|
|
6
|
-
import { streamState } from "../../stream.mjs";
|
|
6
|
+
import { matchesStreamMode, streamState } from "../../stream.mjs";
|
|
7
7
|
import { serialiseAsDict, serializeError } from "../../utils/serde.mjs";
|
|
8
8
|
import { getDisconnectAbortSignal, jsonExtra } from "../../utils/hono.mjs";
|
|
9
9
|
import { createStubRun } from "./utils.mjs";
|
|
@@ -59,8 +59,9 @@ export function registerRunRoutes(api, context) {
|
|
|
59
59
|
api.get("/threads/:thread_id/runs/:run_id/stream", zValidator("param", z.object({
|
|
60
60
|
thread_id: z.string().uuid(),
|
|
61
61
|
run_id: z.string().uuid(),
|
|
62
|
-
})), async (c) => {
|
|
62
|
+
})), zValidator("query", schemas.JoinStreamQuery), async (c) => {
|
|
63
63
|
const { thread_id, run_id } = c.req.valid("param");
|
|
64
|
+
const { stream_mode } = c.req.valid("query");
|
|
64
65
|
const thread = await context.threads.get(thread_id);
|
|
65
66
|
if (thread == null)
|
|
66
67
|
return c.json({ error: "Thread not found" }, 404);
|
|
@@ -87,6 +88,8 @@ export function registerRunRoutes(api, context) {
|
|
|
87
88
|
getGraph: context.getGraph,
|
|
88
89
|
signal,
|
|
89
90
|
})) {
|
|
91
|
+
if (!matchesStreamMode(event, stream_mode))
|
|
92
|
+
continue;
|
|
90
93
|
await stream.writeSSE({ data: serialiseAsDict(data), event });
|
|
91
94
|
}
|
|
92
95
|
}
|
package/dist/schemas.d.mts
CHANGED
|
@@ -1550,3 +1550,13 @@ export declare const StoreGetItem: z.ZodObject<{
|
|
|
1550
1550
|
namespace?: string | undefined;
|
|
1551
1551
|
}>;
|
|
1552
1552
|
export declare const coercedBoolean: z.ZodEffects<z.ZodString, boolean, string>;
|
|
1553
|
+
export declare const JoinStreamQuery: z.ZodObject<{
|
|
1554
|
+
cancel_on_disconnect: z.ZodOptional<z.ZodEffects<z.ZodString, boolean, string>>;
|
|
1555
|
+
stream_mode: z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>, string[], string | string[] | undefined>;
|
|
1556
|
+
}, "strip", z.ZodTypeAny, {
|
|
1557
|
+
stream_mode: string[];
|
|
1558
|
+
cancel_on_disconnect?: boolean | undefined;
|
|
1559
|
+
}, {
|
|
1560
|
+
stream_mode?: string | string[] | undefined;
|
|
1561
|
+
cancel_on_disconnect?: string | undefined;
|
|
1562
|
+
}>;
|
package/dist/schemas.mjs
CHANGED
|
@@ -492,3 +492,21 @@ export const coercedBoolean = z.string().transform((val) => {
|
|
|
492
492
|
const lower = val.toLowerCase();
|
|
493
493
|
return lower === "true" || lower === "1" || lower === "yes";
|
|
494
494
|
});
|
|
495
|
+
// JS SDKs before 1.12 send several stream modes as one JSON array.
|
|
496
|
+
const parseStreamMode = (value) => {
|
|
497
|
+
if (!value.startsWith("["))
|
|
498
|
+
return value ? [value] : [];
|
|
499
|
+
try {
|
|
500
|
+
return JSON.parse(value);
|
|
501
|
+
}
|
|
502
|
+
catch {
|
|
503
|
+
return [value];
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
export const JoinStreamQuery = z.object({
|
|
507
|
+
cancel_on_disconnect: coercedBoolean.optional(),
|
|
508
|
+
stream_mode: z
|
|
509
|
+
.union([z.string(), z.array(z.string())])
|
|
510
|
+
.optional()
|
|
511
|
+
.transform((value) => [value ?? []].flat().flatMap(parseStreamMode)),
|
|
512
|
+
});
|
package/dist/stream.d.mts
CHANGED
|
@@ -41,6 +41,7 @@ export declare function streamState(run: Run, options: {
|
|
|
41
41
|
onTaskResult?: (taskResult: StreamTaskResult) => void;
|
|
42
42
|
signal?: AbortSignal;
|
|
43
43
|
}): AsyncGenerator<SourceStreamEvent>;
|
|
44
|
+
export declare const matchesStreamMode: (event: string, streamMode: string[]) => boolean;
|
|
44
45
|
/**
|
|
45
46
|
* Executes a graph run using `graph.streamEvents(..., { version: "v3" })`
|
|
46
47
|
* and maps the resulting `ProtocolEvent` objects into the `{ event, data }`
|
package/dist/stream.mjs
CHANGED
|
@@ -277,6 +277,18 @@ export async function* streamState(run, options) {
|
|
|
277
277
|
yield { event: "feedback", data };
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
|
+
export const matchesStreamMode = (event, streamMode) => {
|
|
281
|
+
// A run's error is its outcome, not a mode, so no filter drops it.
|
|
282
|
+
if (streamMode.length === 0 || event === "error")
|
|
283
|
+
return true;
|
|
284
|
+
const mode = event.split("|")[0];
|
|
285
|
+
if (streamMode.includes(mode))
|
|
286
|
+
return true;
|
|
287
|
+
// The messages modes stream `messages` (messages-tuple) and `messages/*`
|
|
288
|
+
// (messages) events; as on the Agent Server, either mode keeps both.
|
|
289
|
+
return (mode.startsWith("messages") &&
|
|
290
|
+
(streamMode.includes("messages") || streamMode.includes("messages-tuple")));
|
|
291
|
+
};
|
|
280
292
|
function isUnsupportedStreamEventsV3Error(error) {
|
|
281
293
|
return (error instanceof Error &&
|
|
282
294
|
error.message.includes('Only versions "v1" and "v2" of the schema are currently supported'));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/langgraph-api",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": "^18.19.0 || >=20.16.0"
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"winston": "^3.17.0",
|
|
72
72
|
"winston-console-format": "^1.0.8",
|
|
73
73
|
"zod": "^4.6.6",
|
|
74
|
-
"@langchain/langgraph-ui": "1.5.
|
|
74
|
+
"@langchain/langgraph-ui": "1.5.8"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
77
|
"@langchain/core": "^1.1.48",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
}
|
|
91
91
|
},
|
|
92
92
|
"devDependencies": {
|
|
93
|
-
"@langchain/core": "^1.2
|
|
93
|
+
"@langchain/core": "^1.3.2",
|
|
94
94
|
"@types/babel__code-frame": "^7.0.6",
|
|
95
95
|
"@types/node": "^18.15.11",
|
|
96
96
|
"@types/react": "^19.3.0",
|
|
@@ -98,15 +98,15 @@
|
|
|
98
98
|
"@types/semver": "^7.7.0",
|
|
99
99
|
"deepagents": "^1.10.5",
|
|
100
100
|
"jose": "^6.0.10",
|
|
101
|
-
"langchain": "^1.
|
|
101
|
+
"langchain": "^1.6.0",
|
|
102
102
|
"postgres": "^3.4.5",
|
|
103
103
|
"ts-node": "^10.9.2",
|
|
104
104
|
"typescript": "^4.9.5 || ^5.4.5",
|
|
105
105
|
"vitest": "^4.1.12",
|
|
106
106
|
"wait-port": "^1.1.0",
|
|
107
|
-
"@langchain/langgraph": "1.6.
|
|
108
|
-
"@langchain/langgraph-
|
|
109
|
-
"@langchain/langgraph-
|
|
107
|
+
"@langchain/langgraph": "1.6.1",
|
|
108
|
+
"@langchain/langgraph-sdk": "1.12.10",
|
|
109
|
+
"@langchain/langgraph-checkpoint": "1.2.2"
|
|
110
110
|
},
|
|
111
111
|
"scripts": {
|
|
112
112
|
"clean": "rm -rf dist/ .turbo/ ./tests/graphs/.langgraph_api/ ./tests/protocol-v2/graphs/.langgraph_api/",
|