@langchain/langgraph-cli 0.0.9 → 0.0.11
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 +21 -93
- package/README.md +6 -6
- package/dist/cli/build.mjs +1 -1
- package/dist/cli/cli.mjs +0 -0
- package/dist/cli/dev.mjs +3 -3
- package/dist/cli/dev.python.mjs +1 -1
- package/dist/cli/docker.mjs +1 -1
- package/dist/cli/up.mjs +1 -1
- package/dist/cli/utils/ipc/utils/temporary-directory.mjs +5 -5
- package/dist/{logging.mjs → utils/logging.mjs} +0 -4
- package/package.json +22 -31
- package/dist/api/assistants.mjs +0 -144
- package/dist/api/runs.mjs +0 -239
- package/dist/api/store.mjs +0 -83
- package/dist/api/threads.mjs +0 -143
- package/dist/cli/dev.node.entrypoint.mjs +0 -42
- package/dist/cli/dev.node.mjs +0 -35
- package/dist/cli/utils/ipc/client.mjs +0 -47
- package/dist/graph/load.hooks.mjs +0 -17
- package/dist/graph/load.mjs +0 -72
- package/dist/graph/load.utils.mjs +0 -50
- package/dist/graph/parser/parser.mjs +0 -308
- package/dist/graph/parser/parser.worker.mjs +0 -7
- package/dist/graph/parser/schema/types.mjs +0 -1607
- package/dist/graph/parser/schema/types.template.mts +0 -83
- package/dist/preload.mjs +0 -3
- package/dist/queue.mjs +0 -93
- package/dist/schemas.mjs +0 -407
- package/dist/server.mjs +0 -74
- package/dist/state.mjs +0 -32
- package/dist/storage/checkpoint.mjs +0 -127
- package/dist/storage/importMap.mjs +0 -55
- package/dist/storage/ops.mjs +0 -792
- package/dist/storage/persist.mjs +0 -79
- package/dist/storage/store.mjs +0 -41
- package/dist/stream.mjs +0 -215
- package/dist/utils/abort.mjs +0 -8
- package/dist/utils/error.mjs +0 -1
- package/dist/utils/hono.mjs +0 -27
- package/dist/utils/importMap.mjs +0 -55
- package/dist/utils/runnableConfig.mjs +0 -45
- package/dist/utils/serde.mjs +0 -20
package/LICENSE
CHANGED
|
@@ -1,93 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
The
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
You may not move, change, disable, or circumvent the license key functionality
|
|
23
|
-
in the software, and you may not remove or obscure any functionality in the
|
|
24
|
-
software that is protected by the license key.
|
|
25
|
-
|
|
26
|
-
You may not alter, remove, or obscure any licensing, copyright, or other notices
|
|
27
|
-
of the licensor in the software. Any use of the licensor’s trademarks is subject
|
|
28
|
-
to applicable law.
|
|
29
|
-
|
|
30
|
-
## Patents
|
|
31
|
-
|
|
32
|
-
The licensor grants you a license, under any patent claims the licensor can
|
|
33
|
-
license, or becomes able to license, to make, have made, use, sell, offer for
|
|
34
|
-
sale, import and have imported the software, in each case subject to the
|
|
35
|
-
limitations and conditions in this license. This license does not cover any
|
|
36
|
-
patent claims that you cause to be infringed by modifications or additions to
|
|
37
|
-
the software. If you or your company make any written claim that the software
|
|
38
|
-
infringes or contributes to infringement of any patent, your patent license for
|
|
39
|
-
the software granted under these terms ends immediately. If your company makes
|
|
40
|
-
such a claim, your patent license ends immediately for work on behalf of your
|
|
41
|
-
company.
|
|
42
|
-
|
|
43
|
-
## Notices
|
|
44
|
-
|
|
45
|
-
You must ensure that anyone who gets a copy of any part of the software from you
|
|
46
|
-
also gets a copy of these terms.
|
|
47
|
-
|
|
48
|
-
If you modify the software, you must include in any modified copies of the
|
|
49
|
-
software prominent notices stating that you have modified the software.
|
|
50
|
-
|
|
51
|
-
## No Other Rights
|
|
52
|
-
|
|
53
|
-
These terms do not imply any licenses other than those expressly granted in
|
|
54
|
-
these terms.
|
|
55
|
-
|
|
56
|
-
## Termination
|
|
57
|
-
|
|
58
|
-
If you use the software in violation of these terms, such use is not licensed,
|
|
59
|
-
and your licenses will automatically terminate. If the licensor provides you
|
|
60
|
-
with a notice of your violation, and you cease all violation of this license no
|
|
61
|
-
later than 30 days after you receive that notice, your licenses will be
|
|
62
|
-
reinstated retroactively. However, if you violate these terms after such
|
|
63
|
-
reinstatement, any additional violation of these terms will cause your licenses
|
|
64
|
-
to terminate automatically and permanently.
|
|
65
|
-
|
|
66
|
-
## No Liability
|
|
67
|
-
|
|
68
|
-
*As far as the law allows, the software comes as is, without any warranty or
|
|
69
|
-
condition, and the licensor will not be liable to you for any damages arising
|
|
70
|
-
out of these terms or the use or nature of the software, under any kind of
|
|
71
|
-
legal claim.*
|
|
72
|
-
|
|
73
|
-
## Definitions
|
|
74
|
-
|
|
75
|
-
The **licensor** is the entity offering these terms, and the **software** is the
|
|
76
|
-
software the licensor makes available under these terms, including any portion
|
|
77
|
-
of it.
|
|
78
|
-
|
|
79
|
-
**you** refers to the individual or entity agreeing to these terms.
|
|
80
|
-
|
|
81
|
-
**your company** is any legal entity, sole proprietorship, or other kind of
|
|
82
|
-
organization that you work for, plus all organizations that have control over,
|
|
83
|
-
are under the control of, or are under common control with that
|
|
84
|
-
organization. **control** means ownership of substantially all the assets of an
|
|
85
|
-
entity, or the power to direct its management and policies by vote, contract, or
|
|
86
|
-
otherwise. Control can be direct or indirect.
|
|
87
|
-
|
|
88
|
-
**your licenses** are all the licenses granted to you for the software under
|
|
89
|
-
these terms.
|
|
90
|
-
|
|
91
|
-
**use** means anything you do with the software requiring one of your licenses.
|
|
92
|
-
|
|
93
|
-
**trademark** means trademarks, service marks, and similar rights.
|
|
1
|
+
MIT License Copyright (c) 2025 LangChain
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free
|
|
4
|
+
of charge, to any person obtaining a copy of this software and associated
|
|
5
|
+
documentation files (the "Software"), to deal in the Software without
|
|
6
|
+
restriction, including without limitation the rights to use, copy, modify, merge,
|
|
7
|
+
publish, distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice
|
|
12
|
+
(including the next paragraph) shall be included in all copies or substantial
|
|
13
|
+
portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
16
|
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
|
18
|
+
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
19
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
20
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -51,18 +51,18 @@ The CLI uses a `langgraph.json` configuration file with these key settings:
|
|
|
51
51
|
```json5
|
|
52
52
|
{
|
|
53
53
|
// Required: Graph definitions
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
graphs: {
|
|
55
|
+
graph: "./src/graph.ts:graph",
|
|
56
56
|
},
|
|
57
57
|
|
|
58
58
|
// Optional: Node version (20 only at the moment)
|
|
59
|
-
|
|
59
|
+
node_version: "20",
|
|
60
60
|
|
|
61
61
|
// Optional: Environment variables
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
env: ".env",
|
|
63
|
+
|
|
64
64
|
// Optional: Additional Dockerfile commands
|
|
65
|
-
|
|
65
|
+
dockerfile_lines: [],
|
|
66
66
|
}
|
|
67
67
|
```
|
|
68
68
|
|
package/dist/cli/build.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { getProjectPath } from "./utils/project.mjs";
|
|
|
7
7
|
import { $ } from "execa";
|
|
8
8
|
import * as path from "node:path";
|
|
9
9
|
import * as fs from "node:fs/promises";
|
|
10
|
-
import { logger } from "../logging.mjs";
|
|
10
|
+
import { logger } from "../utils/logging.mjs";
|
|
11
11
|
import { withAnalytics } from "./utils/analytics.mjs";
|
|
12
12
|
const stream = (proc) => {
|
|
13
13
|
logger.info(`Running "${proc.spawnargs.join(" ")}"`);
|
package/dist/cli/cli.mjs
CHANGED
|
File without changes
|
package/dist/cli/dev.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { createIpcServer } from "./utils/ipc/server.mjs";
|
|
|
8
8
|
import { getProjectPath } from "./utils/project.mjs";
|
|
9
9
|
import { getConfig } from "../utils/config.mjs";
|
|
10
10
|
import { builder } from "./utils/builder.mjs";
|
|
11
|
-
import { logError, logger } from "../logging.mjs";
|
|
11
|
+
import { logError, logger } from "../utils/logging.mjs";
|
|
12
12
|
import { withAnalytics } from "./utils/analytics.mjs";
|
|
13
13
|
builder
|
|
14
14
|
.command("dev")
|
|
@@ -101,8 +101,8 @@ builder
|
|
|
101
101
|
child = await spawnPythonServer({ ...options, rest: args }, { configPath, config, env, hostUrl }, { pid, projectCwd });
|
|
102
102
|
}
|
|
103
103
|
else {
|
|
104
|
-
const {
|
|
105
|
-
child = await
|
|
104
|
+
const { spawnServer } = await import("@langchain/langgraph-api");
|
|
105
|
+
child = await spawnServer(options, { config, env, hostUrl }, { pid, projectCwd });
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
108
|
watcher.on("all", async (_name, path) => {
|
package/dist/cli/dev.python.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import path from "node:path";
|
|
|
6
6
|
import os from "node:os";
|
|
7
7
|
import { extract as tarExtract } from "tar";
|
|
8
8
|
import zipExtract from "extract-zip";
|
|
9
|
-
import { logger } from "../logging.mjs";
|
|
9
|
+
import { logger } from "../utils/logging.mjs";
|
|
10
10
|
import { assembleLocalDeps } from "../docker/docker.mjs";
|
|
11
11
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
12
12
|
const UV_VERSION = "0.5.20";
|
package/dist/cli/docker.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { builder } from "./utils/builder.mjs";
|
|
|
6
6
|
import * as fs from "node:fs/promises";
|
|
7
7
|
import * as path from "node:path";
|
|
8
8
|
import dedent from "dedent";
|
|
9
|
-
import { logger } from "../logging.mjs";
|
|
9
|
+
import { logger } from "../utils/logging.mjs";
|
|
10
10
|
import { withAnalytics } from "./utils/analytics.mjs";
|
|
11
11
|
const fileExists = async (path) => {
|
|
12
12
|
try {
|
package/dist/cli/up.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import * as fs from "node:fs/promises";
|
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import { getConfig } from "../utils/config.mjs";
|
|
5
5
|
import { getProjectPath } from "./utils/project.mjs";
|
|
6
|
-
import { logger } from "../logging.mjs";
|
|
6
|
+
import { logger } from "../utils/logging.mjs";
|
|
7
7
|
import { createCompose, getDockerCapabilities } from "../docker/compose.mjs";
|
|
8
8
|
import { configToCompose, getBaseImage } from "../docker/docker.mjs";
|
|
9
9
|
import { getExecaOptions } from "../docker/shell.mjs";
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
// MIT License
|
|
2
|
-
//
|
|
2
|
+
//
|
|
3
3
|
// Copyright (c) Hiroki Osame <hiroki.osame@gmail.com>
|
|
4
|
-
//
|
|
4
|
+
//
|
|
5
5
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
// of this software and associated documentation files (the "Software"), to deal
|
|
7
7
|
// in the Software without restriction, including without limitation the rights
|
|
8
8
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
9
|
// copies of the Software, and to permit persons to whom the Software is
|
|
10
10
|
// furnished to do so, subject to the following conditions:
|
|
11
|
-
//
|
|
11
|
+
//
|
|
12
12
|
// The above copyright notice and this permission notice shall be included in all
|
|
13
13
|
// copies or substantial portions of the Software.
|
|
14
|
-
//
|
|
14
|
+
//
|
|
15
15
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
16
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
17
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
// SOFTWARE.
|
|
22
|
-
//
|
|
22
|
+
//
|
|
23
23
|
// https://github.com/privatenumber/tsx/tree/28a3e7d2b8fd72b683aab8a98dd1fcee4624e4cb
|
|
24
24
|
import path from "node:path";
|
|
25
25
|
import os from "node:os";
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createLogger, format, transports } from "winston";
|
|
2
|
-
import { logger as honoLogger } from "hono/logger";
|
|
3
2
|
import { consoleFormat } from "winston-console-format";
|
|
4
3
|
import { parse as stacktraceParser } from "stacktrace-parser";
|
|
5
4
|
import { readFileSync } from "fs";
|
|
@@ -95,6 +94,3 @@ export const logError = (error, options) => {
|
|
|
95
94
|
};
|
|
96
95
|
process.on("uncaughtException", (error) => logError(error));
|
|
97
96
|
process.on("unhandledRejection", (error) => logError(error));
|
|
98
|
-
export const requestLogger = () => honoLogger((message, ...rest) => {
|
|
99
|
-
logger.info(message, ...rest);
|
|
100
|
-
});
|
package/package.json
CHANGED
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/langgraph-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18"
|
|
7
7
|
},
|
|
8
|
-
"license": "
|
|
8
|
+
"license": "MIT",
|
|
9
9
|
"main": "./dist/server.mjs",
|
|
10
|
+
"types": "./dist/server.d.mts",
|
|
10
11
|
"bin": {
|
|
11
12
|
"langgraphjs": "dist/cli/cli.mjs"
|
|
12
13
|
},
|
|
13
14
|
"files": [
|
|
14
15
|
"dist/"
|
|
15
16
|
],
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"typecheck": "tsc --noEmit",
|
|
20
|
-
"cli": "tsx src/cli/cli.mts",
|
|
21
|
-
"cli:watch": "tsx watch src/cli/cli.mts",
|
|
22
|
-
"test:cli": "pnpm run cli dev --no-browser --config ./tests/graphs/langgraph.json",
|
|
23
|
-
"test": "vitest",
|
|
24
|
-
"test:ci": "node scripts/spawn.mjs test"
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git@github.com:langchain-ai/langgraphjs-api.git"
|
|
25
20
|
},
|
|
26
21
|
"dependencies": {
|
|
27
22
|
"@commander-js/extra-typings": "^13.0.0",
|
|
28
|
-
"@hono/node-server": "^1.12.0",
|
|
29
|
-
"@hono/zod-validator": "^0.2.2",
|
|
30
|
-
"@types/json-schema": "^7.0.15",
|
|
31
|
-
"@typescript/vfs": "^1.6.0",
|
|
32
23
|
"chokidar": "^4.0.3",
|
|
33
24
|
"commander": "^13.0.0",
|
|
34
25
|
"dedent": "^1.5.3",
|
|
@@ -36,33 +27,33 @@
|
|
|
36
27
|
"execa": "^9.5.2",
|
|
37
28
|
"exit-hook": "^4.0.0",
|
|
38
29
|
"extract-zip": "^2.0.1",
|
|
39
|
-
"hono": "^4.5.4",
|
|
40
30
|
"langsmith": "^0.2.15",
|
|
41
31
|
"open": "^10.1.0",
|
|
42
32
|
"stacktrace-parser": "^0.1.10",
|
|
43
|
-
"superjson": "^2.2.2",
|
|
44
33
|
"tar": "^7.4.3",
|
|
45
|
-
"tsx": "^4.19.2",
|
|
46
|
-
"uuid": "^10.0.0",
|
|
47
34
|
"winston": "^3.17.0",
|
|
48
35
|
"winston-console-format": "^1.0.8",
|
|
49
36
|
"yaml": "^2.7.0",
|
|
50
37
|
"zod": "^3.23.8",
|
|
51
|
-
"@babel/code-frame": "^7.26.2"
|
|
52
|
-
|
|
53
|
-
"peerDependencies": {
|
|
54
|
-
"@langchain/core": "^0.3.36",
|
|
55
|
-
"@langchain/langgraph": "^0.2.43",
|
|
56
|
-
"@langchain/langgraph-checkpoint": "^0.0.14",
|
|
57
|
-
"typescript": "^5.5.4"
|
|
38
|
+
"@babel/code-frame": "^7.26.2",
|
|
39
|
+
"@langchain/langgraph-api": "0.0.11"
|
|
58
40
|
},
|
|
59
41
|
"devDependencies": {
|
|
60
|
-
"
|
|
42
|
+
"tsx": "^4.19.2",
|
|
61
43
|
"@types/babel__code-frame": "^7.0.6",
|
|
62
44
|
"@types/node": "^22.2.0",
|
|
63
|
-
"@types/uuid": "^10.0.0",
|
|
64
|
-
"postgres": "^3.4.5",
|
|
65
45
|
"prettier": "^3.3.3",
|
|
66
|
-
"vitest": "^
|
|
46
|
+
"vitest": "^3.0.5",
|
|
47
|
+
"typescript": "^5.5.4"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"clean": "npx -y bun scripts/clean.mjs",
|
|
51
|
+
"build": "npx -y bun scripts/build.mjs",
|
|
52
|
+
"typecheck": "tsc --noEmit",
|
|
53
|
+
"cli": "tsx src/cli/cli.mts",
|
|
54
|
+
"cli:watch": "tsx watch src/cli/cli.mts",
|
|
55
|
+
"test": "vitest",
|
|
56
|
+
"format": "prettier --write .",
|
|
57
|
+
"format:check": "prettier --check ."
|
|
67
58
|
}
|
|
68
|
-
}
|
|
59
|
+
}
|
package/dist/api/assistants.mjs
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { Hono } from "hono";
|
|
2
|
-
import { zValidator } from "@hono/zod-validator";
|
|
3
|
-
import { v4 as uuid } from "uuid";
|
|
4
|
-
import { z } from "zod";
|
|
5
|
-
import { getAssistantId, getGraph, getGraphSchema } from "../graph/load.mjs";
|
|
6
|
-
import { Assistants } from "../storage/ops.mjs";
|
|
7
|
-
import * as schemas from "../schemas.mjs";
|
|
8
|
-
import { HTTPException } from "hono/http-exception";
|
|
9
|
-
const api = new Hono();
|
|
10
|
-
api.post("/assistants", zValidator("json", schemas.AssistantCreate), async (c) => {
|
|
11
|
-
// Create Assistant
|
|
12
|
-
const payload = c.req.valid("json");
|
|
13
|
-
const assistant = await Assistants.put(payload.assistant_id ?? uuid(), {
|
|
14
|
-
config: payload.config ?? {},
|
|
15
|
-
graph_id: payload.graph_id,
|
|
16
|
-
metadata: payload.metadata ?? {},
|
|
17
|
-
if_exists: payload.if_exists ?? "raise",
|
|
18
|
-
name: payload.name ?? "Untitled",
|
|
19
|
-
});
|
|
20
|
-
return c.json(assistant);
|
|
21
|
-
});
|
|
22
|
-
api.post("/assistants/search", zValidator("json", schemas.AssistantSearchRequest), async (c) => {
|
|
23
|
-
// Search Assistants
|
|
24
|
-
const payload = c.req.valid("json");
|
|
25
|
-
const result = [];
|
|
26
|
-
for await (const item of Assistants.search({
|
|
27
|
-
graph_id: payload.graph_id,
|
|
28
|
-
metadata: payload.metadata,
|
|
29
|
-
limit: payload.limit ?? 10,
|
|
30
|
-
offset: payload.offset ?? 0,
|
|
31
|
-
})) {
|
|
32
|
-
result.push(item);
|
|
33
|
-
}
|
|
34
|
-
return c.json(result);
|
|
35
|
-
});
|
|
36
|
-
api.get("/assistants/:assistant_id", async (c) => {
|
|
37
|
-
// Get Assistant
|
|
38
|
-
const assistantId = getAssistantId(c.req.param("assistant_id"));
|
|
39
|
-
return c.json(await Assistants.get(assistantId));
|
|
40
|
-
});
|
|
41
|
-
api.delete("/assistants/:assistant_id", async (c) => {
|
|
42
|
-
// Delete Assistant
|
|
43
|
-
const assistantId = getAssistantId(c.req.param("assistant_id"));
|
|
44
|
-
return c.json(await Assistants.delete(assistantId));
|
|
45
|
-
});
|
|
46
|
-
api.patch("/assistants/:assistant_id", zValidator("json", schemas.AssistantPatch), async (c) => {
|
|
47
|
-
// Patch Assistant
|
|
48
|
-
const assistantId = getAssistantId(c.req.param("assistant_id"));
|
|
49
|
-
const payload = c.req.valid("json");
|
|
50
|
-
return c.json(await Assistants.patch(assistantId, payload));
|
|
51
|
-
});
|
|
52
|
-
const RunnableConfigSchema = z.object({
|
|
53
|
-
tags: z.array(z.string()).optional(),
|
|
54
|
-
metadata: z.record(z.unknown()).optional(),
|
|
55
|
-
run_name: z.string().optional(),
|
|
56
|
-
max_concurrency: z.number().optional(),
|
|
57
|
-
recursion_limit: z.number().optional(),
|
|
58
|
-
configurable: z.record(z.unknown()).optional(),
|
|
59
|
-
run_id: z.string().uuid().optional(),
|
|
60
|
-
});
|
|
61
|
-
const getRunnableConfig = (userConfig) => {
|
|
62
|
-
if (!userConfig)
|
|
63
|
-
return {};
|
|
64
|
-
return {
|
|
65
|
-
configurable: userConfig.configurable,
|
|
66
|
-
tags: userConfig.tags,
|
|
67
|
-
metadata: userConfig.metadata,
|
|
68
|
-
runName: userConfig.run_name,
|
|
69
|
-
maxConcurrency: userConfig.max_concurrency,
|
|
70
|
-
recursionLimit: userConfig.recursion_limit,
|
|
71
|
-
runId: userConfig.run_id,
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
api.get("/assistants/:assistant_id/graph", zValidator("query", z.object({ xray: schemas.coercedBoolean.optional() })), async (c) => {
|
|
75
|
-
// Get Assistant Graph
|
|
76
|
-
const assistantId = getAssistantId(c.req.param("assistant_id"));
|
|
77
|
-
const assistant = await Assistants.get(assistantId);
|
|
78
|
-
const { xray } = c.req.valid("query");
|
|
79
|
-
const graph = getGraph(assistant.graph_id);
|
|
80
|
-
return c.json(graph.getGraph({ ...getRunnableConfig(assistant.config), xray }).toJSON());
|
|
81
|
-
});
|
|
82
|
-
api.get("/assistants/:assistant_id/schemas", async (c) => {
|
|
83
|
-
// Get Assistant Schemas
|
|
84
|
-
const assistantId = getAssistantId(c.req.param("assistant_id"));
|
|
85
|
-
const assistant = await Assistants.get(assistantId);
|
|
86
|
-
const graphSchema = await getGraphSchema(assistant.graph_id);
|
|
87
|
-
const rootGraphId = Object.keys(graphSchema).find((i) => !i.includes("|"));
|
|
88
|
-
if (!rootGraphId)
|
|
89
|
-
throw new Error("Failed to find root graph");
|
|
90
|
-
const rootGraphSchema = graphSchema[rootGraphId];
|
|
91
|
-
return c.json({
|
|
92
|
-
graph_id: assistant.graph_id,
|
|
93
|
-
input_schema: rootGraphSchema.input,
|
|
94
|
-
output_schema: rootGraphSchema.output,
|
|
95
|
-
state_schema: rootGraphSchema.state,
|
|
96
|
-
config_schema: rootGraphSchema.config,
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
api.get("/assistants/:assistant_id/subgraphs/:namespace?", zValidator("param", z.object({ assistant_id: z.string(), namespace: z.string().optional() })), zValidator("query", z.object({ recurse: schemas.coercedBoolean.optional() })), async (c) => {
|
|
100
|
-
// Get Assistant Subgraphs
|
|
101
|
-
const { assistant_id, namespace } = c.req.valid("param");
|
|
102
|
-
const { recurse } = c.req.valid("query");
|
|
103
|
-
const assistantId = getAssistantId(assistant_id);
|
|
104
|
-
const assistant = await Assistants.get(assistantId);
|
|
105
|
-
const graph = getGraph(assistant.graph_id);
|
|
106
|
-
const graphSchema = await getGraphSchema(assistant.graph_id);
|
|
107
|
-
const rootGraphId = Object.keys(graphSchema).find((i) => !i.includes("|"));
|
|
108
|
-
if (!rootGraphId) {
|
|
109
|
-
throw new HTTPException(404, { message: "Failed to find root graph" });
|
|
110
|
-
}
|
|
111
|
-
const result = [];
|
|
112
|
-
const subgraphsGenerator = "getSubgraphsAsync" in graph
|
|
113
|
-
? graph.getSubgraphsAsync.bind(graph)
|
|
114
|
-
: // @ts-expect-error older versions of langgraph don't have getSubgraphsAsync
|
|
115
|
-
graph.getSubgraphs.bind(graph);
|
|
116
|
-
for await (const [ns] of subgraphsGenerator(namespace, recurse)) {
|
|
117
|
-
result.push([
|
|
118
|
-
ns,
|
|
119
|
-
graphSchema[`${rootGraphId}|${ns}`] || graphSchema[rootGraphId],
|
|
120
|
-
]);
|
|
121
|
-
}
|
|
122
|
-
return c.json(Object.fromEntries(result));
|
|
123
|
-
});
|
|
124
|
-
api.post("/assistants/:assistant_id/latest", zValidator("json", schemas.AssistantLatestVersion), async (c) => {
|
|
125
|
-
// Set Latest Assistant Version
|
|
126
|
-
const assistantId = getAssistantId(c.req.param("assistant_id"));
|
|
127
|
-
const { version } = c.req.valid("json");
|
|
128
|
-
return c.json(await Assistants.setLatest(assistantId, version));
|
|
129
|
-
});
|
|
130
|
-
api.post("/assistants/:assistant_id/versions", zValidator("json", z.object({
|
|
131
|
-
limit: z.number().min(1).max(1000).optional().default(10),
|
|
132
|
-
offset: z.number().min(0).optional().default(0),
|
|
133
|
-
metadata: z.record(z.unknown()).optional(),
|
|
134
|
-
})), async (c) => {
|
|
135
|
-
// Get Assistant Versions
|
|
136
|
-
const assistantId = getAssistantId(c.req.param("assistant_id"));
|
|
137
|
-
const { limit, offset, metadata } = c.req.valid("json");
|
|
138
|
-
return c.json(await Assistants.getVersions(assistantId, {
|
|
139
|
-
limit,
|
|
140
|
-
offset,
|
|
141
|
-
metadata,
|
|
142
|
-
}));
|
|
143
|
-
});
|
|
144
|
-
export default api;
|