@langchain/langgraph-api 1.4.1 → 1.4.2
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 -24
- package/dist/protocol/service.mjs +3 -0
- package/dist/utils/run-auth.d.mts +13 -0
- package/dist/utils/run-auth.mjs +42 -0
- package/package.json +8 -8
package/dist/api/runs.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import { logError, logger } from "../logging.mjs";
|
|
|
9
9
|
import * as schemas from "../schemas.mjs";
|
|
10
10
|
import { runs, threads } from "../storage/context.mjs";
|
|
11
11
|
import { getDisconnectAbortSignal, jsonExtra, waitKeepAlive, } from "../utils/hono.mjs";
|
|
12
|
+
import { applyAuthToRunConfig, applyRequestHeadersToRunConfig, } from "../utils/run-auth.mjs";
|
|
12
13
|
import { serialiseAsDict } from "../utils/serde.mjs";
|
|
13
14
|
const api = new Hono();
|
|
14
15
|
const createValidRun = async (threadId, payload, kwargs) => {
|
|
@@ -40,30 +41,8 @@ const createValidRun = async (threadId, payload, kwargs) => {
|
|
|
40
41
|
langsmith_example_id: run.langsmith_tracer.example_id,
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const key = rawKey.toLowerCase();
|
|
46
|
-
if (key.startsWith("x-")) {
|
|
47
|
-
if (["x-api-key", "x-tenant-id", "x-service-key"].includes(key)) {
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
config.configurable ??= {};
|
|
51
|
-
config.configurable[key] = value;
|
|
52
|
-
}
|
|
53
|
-
else if (key === "user-agent") {
|
|
54
|
-
config.configurable ??= {};
|
|
55
|
-
config.configurable[key] = value;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
let userId;
|
|
60
|
-
if (auth) {
|
|
61
|
-
userId = auth.user.identity ?? auth.user.id;
|
|
62
|
-
config.configurable ??= {};
|
|
63
|
-
config.configurable["langgraph_auth_user"] = auth.user;
|
|
64
|
-
config.configurable["langgraph_auth_user_id"] = userId;
|
|
65
|
-
config.configurable["langgraph_auth_permissions"] = auth.scopes;
|
|
66
|
-
}
|
|
44
|
+
applyRequestHeadersToRunConfig(config, headers);
|
|
45
|
+
const userId = applyAuthToRunConfig(config, auth);
|
|
67
46
|
let feedbackKeys = run.feedback_keys != null
|
|
68
47
|
? Array.isArray(run.feedback_keys)
|
|
69
48
|
? run.feedback_keys
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { inferChannel, isPrefixMatch } from "@langchain/langgraph/stream";
|
|
2
2
|
import { v7 as uuid7 } from "@langchain/core/utils/uuid";
|
|
3
3
|
import { getAssistantId } from "../graph/load.mjs";
|
|
4
|
+
import { applyAuthToRunConfig } from "../utils/run-auth.mjs";
|
|
4
5
|
import { PROTOCOL_STREAM_RUN_KEY } from "./constants.mjs";
|
|
5
6
|
import { RunProtocolSession } from "./session/index.mjs";
|
|
6
7
|
const DEFAULT_RUN_STREAM_MODES = [
|
|
@@ -326,6 +327,7 @@ export class ProtocolService {
|
|
|
326
327
|
thread_id: record.threadId,
|
|
327
328
|
},
|
|
328
329
|
};
|
|
330
|
+
const userId = applyAuthToRunConfig(runConfig, record.auth);
|
|
329
331
|
const runPayload = {
|
|
330
332
|
assistant_id: assistantId,
|
|
331
333
|
input: isResume ? null : params.input,
|
|
@@ -366,6 +368,7 @@ export class ProtocolService {
|
|
|
366
368
|
[PROTOCOL_STREAM_RUN_KEY]: true,
|
|
367
369
|
}, {
|
|
368
370
|
threadId: record.threadId,
|
|
371
|
+
userId,
|
|
369
372
|
metadata: runPayload.metadata,
|
|
370
373
|
status: "pending",
|
|
371
374
|
multitaskStrategy: runPayload.multitask_strategy,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AuthContext } from "../auth/index.mjs";
|
|
2
|
+
import type { RunnableConfig } from "../storage/types.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Copy allowed request headers into `config.configurable`, matching the REST
|
|
5
|
+
* runs API (`createValidRun`). Used by both REST and protocol-v2 run creation.
|
|
6
|
+
*/
|
|
7
|
+
export declare function applyRequestHeadersToRunConfig(config: RunnableConfig, headers: Headers | undefined): void;
|
|
8
|
+
/**
|
|
9
|
+
* Stamp the authenticated user onto `config.configurable` so graph nodes and
|
|
10
|
+
* tools can read `langgraph_auth_user`. Returns the resolved user id for run
|
|
11
|
+
* metadata when auth is present.
|
|
12
|
+
*/
|
|
13
|
+
export declare function applyAuthToRunConfig(config: RunnableConfig, auth: AuthContext | undefined): string | undefined;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const BLOCKED_CONFIGURABLE_HEADERS = new Set([
|
|
2
|
+
"x-api-key",
|
|
3
|
+
"x-tenant-id",
|
|
4
|
+
"x-service-key",
|
|
5
|
+
]);
|
|
6
|
+
/**
|
|
7
|
+
* Copy allowed request headers into `config.configurable`, matching the REST
|
|
8
|
+
* runs API (`createValidRun`). Used by both REST and protocol-v2 run creation.
|
|
9
|
+
*/
|
|
10
|
+
export function applyRequestHeadersToRunConfig(config, headers) {
|
|
11
|
+
if (!headers)
|
|
12
|
+
return;
|
|
13
|
+
for (const [rawKey, value] of headers.entries()) {
|
|
14
|
+
const key = rawKey.toLowerCase();
|
|
15
|
+
if (key.startsWith("x-")) {
|
|
16
|
+
if (BLOCKED_CONFIGURABLE_HEADERS.has(key))
|
|
17
|
+
continue;
|
|
18
|
+
config.configurable ??= {};
|
|
19
|
+
config.configurable[key] = value;
|
|
20
|
+
}
|
|
21
|
+
else if (key === "user-agent") {
|
|
22
|
+
config.configurable ??= {};
|
|
23
|
+
config.configurable[key] = value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Stamp the authenticated user onto `config.configurable` so graph nodes and
|
|
29
|
+
* tools can read `langgraph_auth_user`. Returns the resolved user id for run
|
|
30
|
+
* metadata when auth is present.
|
|
31
|
+
*/
|
|
32
|
+
export function applyAuthToRunConfig(config, auth) {
|
|
33
|
+
if (!auth)
|
|
34
|
+
return undefined;
|
|
35
|
+
const userId = auth.user.identity ??
|
|
36
|
+
(typeof auth.user.id === "string" ? auth.user.id : undefined);
|
|
37
|
+
config.configurable ??= {};
|
|
38
|
+
config.configurable.langgraph_auth_user = auth.user;
|
|
39
|
+
config.configurable.langgraph_auth_user_id = userId;
|
|
40
|
+
config.configurable.langgraph_auth_permissions = auth.scopes;
|
|
41
|
+
return userId;
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/langgraph-api",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
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": "^3.25.76 || ^4",
|
|
74
|
-
"@langchain/langgraph-ui": "1.4.
|
|
74
|
+
"@langchain/langgraph-ui": "1.4.2"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
77
|
"@langchain/core": "^1.1.48",
|
|
@@ -93,20 +93,20 @@
|
|
|
93
93
|
"@langchain/core": "^1.2.1",
|
|
94
94
|
"@types/babel__code-frame": "^7.0.6",
|
|
95
95
|
"@types/node": "^18.15.11",
|
|
96
|
-
"@types/react": "^19.2.
|
|
96
|
+
"@types/react": "^19.2.17",
|
|
97
97
|
"@types/react-dom": "^19.0.3",
|
|
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.2",
|
|
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.9",
|
|
106
106
|
"wait-port": "^1.1.0",
|
|
107
|
-
"@langchain/langgraph": "1.4.
|
|
108
|
-
"@langchain/langgraph-
|
|
109
|
-
"@langchain/langgraph-
|
|
107
|
+
"@langchain/langgraph": "1.4.7",
|
|
108
|
+
"@langchain/langgraph-sdk": "1.9.25",
|
|
109
|
+
"@langchain/langgraph-checkpoint": "1.1.3"
|
|
110
110
|
},
|
|
111
111
|
"scripts": {
|
|
112
112
|
"clean": "rm -rf dist/ .turbo/ ./tests/graphs/.langgraph_api/ ./tests/protocol-v2/graphs/.langgraph_api/",
|