@langchain/langgraph-cli 0.0.0-preview.10
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 +93 -0
- package/README.md +69 -0
- package/dist/api/assistants.mjs +144 -0
- package/dist/api/runs.mjs +239 -0
- package/dist/api/store.mjs +83 -0
- package/dist/api/threads.mjs +145 -0
- package/dist/cli/build.mjs +49 -0
- package/dist/cli/cli.mjs +11 -0
- package/dist/cli/dev.mjs +113 -0
- package/dist/cli/dev.node.entrypoint.mjs +40 -0
- package/dist/cli/dev.node.mjs +35 -0
- package/dist/cli/dev.python.mjs +128 -0
- package/dist/cli/docker.mjs +112 -0
- package/dist/cli/up.mjs +137 -0
- package/dist/cli/utils/analytics.mjs +39 -0
- package/dist/cli/utils/builder.mjs +7 -0
- package/dist/cli/utils/ipc/client.mjs +47 -0
- package/dist/cli/utils/ipc/server.mjs +93 -0
- package/dist/cli/utils/ipc/utils/get-pipe-path.mjs +29 -0
- package/dist/cli/utils/ipc/utils/temporary-directory.mjs +40 -0
- package/dist/cli/utils/project.mjs +18 -0
- package/dist/cli/utils/version.mjs +13 -0
- package/dist/docker/compose.mjs +185 -0
- package/dist/docker/docker.mjs +390 -0
- package/dist/docker/shell.mjs +62 -0
- package/dist/graph/load.hooks.mjs +17 -0
- package/dist/graph/load.mjs +71 -0
- package/dist/graph/load.utils.mjs +50 -0
- package/dist/graph/parser/parser.mjs +308 -0
- package/dist/graph/parser/parser.worker.mjs +7 -0
- package/dist/graph/parser/schema/types.mjs +1607 -0
- package/dist/graph/parser/schema/types.template.mts +81 -0
- package/dist/logging.mjs +95 -0
- package/dist/preload.mjs +3 -0
- package/dist/queue.mjs +93 -0
- package/dist/schemas.mjs +399 -0
- package/dist/server.mjs +63 -0
- package/dist/state.mjs +32 -0
- package/dist/storage/checkpoint.mjs +127 -0
- package/dist/storage/ops.mjs +786 -0
- package/dist/storage/persist.mjs +69 -0
- package/dist/storage/store.mjs +41 -0
- package/dist/stream.mjs +215 -0
- package/dist/utils/abort.mjs +8 -0
- package/dist/utils/config.mjs +47 -0
- package/dist/utils/error.mjs +1 -0
- package/dist/utils/hono.mjs +27 -0
- package/dist/utils/importMap.mjs +55 -0
- package/dist/utils/runnableConfig.mjs +45 -0
- package/dist/utils/serde.mjs +20 -0
- package/package.json +68 -0
package/dist/cli/up.mjs
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { builder } from "./utils/builder.mjs";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { getConfig } from "../utils/config.mjs";
|
|
5
|
+
import { getProjectPath } from "./utils/project.mjs";
|
|
6
|
+
import { logger } from "../logging.mjs";
|
|
7
|
+
import { createCompose, getDockerCapabilities } from "../docker/compose.mjs";
|
|
8
|
+
import { configToCompose, getBaseImage } from "../docker/docker.mjs";
|
|
9
|
+
import { getExecaOptions } from "../docker/shell.mjs";
|
|
10
|
+
import { $ } from "execa";
|
|
11
|
+
import { createHash } from "node:crypto";
|
|
12
|
+
import dedent from "dedent";
|
|
13
|
+
import { withAnalytics } from "./utils/analytics.mjs";
|
|
14
|
+
const sha256 = (input) => createHash("sha256").update(input).digest("hex");
|
|
15
|
+
const getProjectName = (configPath) => {
|
|
16
|
+
const cwd = path.dirname(configPath).toLocaleLowerCase();
|
|
17
|
+
return `${path.basename(cwd)}-${sha256(cwd)}`;
|
|
18
|
+
};
|
|
19
|
+
const stream = (proc) => {
|
|
20
|
+
logger.debug(`Running "${proc.spawnargs.join(" ")}"`);
|
|
21
|
+
return proc;
|
|
22
|
+
};
|
|
23
|
+
const waitForHealthcheck = async (port) => {
|
|
24
|
+
const now = Date.now();
|
|
25
|
+
while (Date.now() - now < 10_000) {
|
|
26
|
+
const ok = await fetch(`http://localhost:${port}/ok`).then((res) => res.ok, () => false);
|
|
27
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
28
|
+
if (ok)
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
throw new Error("Healthcheck timed out");
|
|
32
|
+
};
|
|
33
|
+
builder
|
|
34
|
+
.command("up")
|
|
35
|
+
.description("Launch LangGraph API server.")
|
|
36
|
+
.option("-c, --config <path>", "Path to configuration file", process.cwd())
|
|
37
|
+
.option("-d, --docker-compose <path>", "Advanced: Path to docker-compose.yml file with additional services to launch")
|
|
38
|
+
.option("-p, --port <port>", "Port to run the server on", "8123")
|
|
39
|
+
.option("--recreate", "Force recreate containers and volumes", false)
|
|
40
|
+
.option("--no-pull", "Running the server with locally-built images. By default LangGraph will pull the latest images from the registry")
|
|
41
|
+
.option("--watch", "Restart on file changes", false)
|
|
42
|
+
.option("--wait", "Wait for services to start before returning. Implies --detach", false)
|
|
43
|
+
.option("--postgres-uri <uri>", "Postgres URI to use for the database. Defaults to launching a local database")
|
|
44
|
+
.hook("preAction", withAnalytics((command) => ({
|
|
45
|
+
config: command.opts().config !== process.cwd(),
|
|
46
|
+
port: command.opts().port !== "8123",
|
|
47
|
+
postgres_uri: !!command.opts().postgresUri,
|
|
48
|
+
docker_compose: !!command.opts().dockerCompose,
|
|
49
|
+
recreate: command.opts().recreate,
|
|
50
|
+
pull: command.opts().pull,
|
|
51
|
+
watch: command.opts().watch,
|
|
52
|
+
wait: command.opts().wait,
|
|
53
|
+
})))
|
|
54
|
+
.action(async (params) => {
|
|
55
|
+
logger.info("Starting LangGraph API server...");
|
|
56
|
+
logger.warn(dedent `
|
|
57
|
+
For local dev, requires env var LANGSMITH_API_KEY with access to LangGraph Cloud closed beta.
|
|
58
|
+
For production use, requires a license key in env var LANGGRAPH_CLOUD_LICENSE_KEY.
|
|
59
|
+
`);
|
|
60
|
+
const configPath = await getProjectPath(params.config);
|
|
61
|
+
const config = getConfig(await fs.readFile(configPath, "utf-8"));
|
|
62
|
+
const cwd = path.dirname(configPath);
|
|
63
|
+
const capabilities = await getDockerCapabilities();
|
|
64
|
+
const fullRestartFiles = [configPath];
|
|
65
|
+
if (typeof config.env === "string") {
|
|
66
|
+
fullRestartFiles.push(path.resolve(cwd, config.env));
|
|
67
|
+
}
|
|
68
|
+
const { apiDef } = await configToCompose(configPath, config, {
|
|
69
|
+
watch: capabilities.watchAvailable,
|
|
70
|
+
});
|
|
71
|
+
const name = getProjectName(configPath);
|
|
72
|
+
const execOpts = await getExecaOptions({
|
|
73
|
+
cwd,
|
|
74
|
+
stdout: "inherit",
|
|
75
|
+
stderr: "inherit",
|
|
76
|
+
});
|
|
77
|
+
const exec = $(execOpts);
|
|
78
|
+
if (!config._INTERNAL_docker_tag && params.pull) {
|
|
79
|
+
// pull the image
|
|
80
|
+
logger.info(`Pulling image ${getBaseImage(config)}...`);
|
|
81
|
+
await stream(exec `docker pull ${getBaseImage(config)}`);
|
|
82
|
+
}
|
|
83
|
+
// remove dangling images
|
|
84
|
+
logger.info(`Pruning dangling images...`);
|
|
85
|
+
await stream(exec `docker image prune -f --filter ${`label=com.docker.compose.project=${name}`}`);
|
|
86
|
+
// remove stale containers
|
|
87
|
+
logger.info(`Pruning stale containers...`);
|
|
88
|
+
await stream(exec `docker container prune -f --filter ${`label=com.docker.compose.project=${name}`}`);
|
|
89
|
+
const input = createCompose(capabilities, {
|
|
90
|
+
port: +params.port,
|
|
91
|
+
postgresUri: params.postgresUri,
|
|
92
|
+
apiDef,
|
|
93
|
+
});
|
|
94
|
+
const args = ["--remove-orphans"];
|
|
95
|
+
if (params.recreate) {
|
|
96
|
+
args.push("--force-recreate", "--renew-anon-volumes");
|
|
97
|
+
try {
|
|
98
|
+
await stream(exec `docker volume rm langgraph-data`);
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
// ignore
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (params.watch) {
|
|
105
|
+
if (capabilities.watchAvailable) {
|
|
106
|
+
args.push("--watch");
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
logger.warn("Watch mode is not available. Please upgrade your Docker Engine.");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (params.wait) {
|
|
113
|
+
args.push("--wait");
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
args.push("--abort-on-container-exit");
|
|
117
|
+
}
|
|
118
|
+
logger.info(`Launching docker-compose...`);
|
|
119
|
+
const cmd = capabilities.composeType === "plugin"
|
|
120
|
+
? ["docker", "compose"]
|
|
121
|
+
: ["docker-compose"];
|
|
122
|
+
cmd.push("--project-directory", cwd, "--project-name", name);
|
|
123
|
+
const userCompose = params.dockerCompose || config.docker_compose_file;
|
|
124
|
+
if (userCompose)
|
|
125
|
+
cmd.push("-f", userCompose);
|
|
126
|
+
cmd.push("-f", "-");
|
|
127
|
+
const up = stream($({ ...execOpts, input }) `${cmd} up ${args}`);
|
|
128
|
+
waitForHealthcheck(+params.port).then(() => {
|
|
129
|
+
logger.info(`
|
|
130
|
+
Ready!
|
|
131
|
+
- API: http://localhost:${params.port}
|
|
132
|
+
- Docs: http://localhost:${params.port}/docs
|
|
133
|
+
- LangGraph Studio: https://smith.langchain.com/studio/?baseUrl=http://127.0.0.1:${params.port}
|
|
134
|
+
`);
|
|
135
|
+
}, () => void 0);
|
|
136
|
+
await up.catch(() => void 0);
|
|
137
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import { version } from "./version.mjs";
|
|
3
|
+
const SUPABASE_PUBLIC_API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imt6cmxwcG9qaW5wY3l5YWlweG5iIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MTkyNTc1NzksImV4cCI6MjAzNDgzMzU3OX0.kkVOlLz3BxemA5nP-vat3K4qRtrDuO4SwZSR_htcX9c";
|
|
4
|
+
const SUPABASE_URL = "https://kzrlppojinpcyyaipxnb.supabase.co";
|
|
5
|
+
async function logData(data) {
|
|
6
|
+
try {
|
|
7
|
+
await fetch(`${SUPABASE_URL}/rest/v1/js_logs`, {
|
|
8
|
+
method: "POST",
|
|
9
|
+
headers: {
|
|
10
|
+
"Content-Type": "application/json",
|
|
11
|
+
apikey: SUPABASE_PUBLIC_API_KEY,
|
|
12
|
+
"User-Agent": "Mozilla/5.0",
|
|
13
|
+
},
|
|
14
|
+
body: JSON.stringify(data),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
// pass
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
let analyticsPromise = Promise.resolve();
|
|
22
|
+
export function withAnalytics(fn) {
|
|
23
|
+
if (process.env.LANGGRAPH_CLI_NO_ANALYTICS === "1") {
|
|
24
|
+
return () => void 0;
|
|
25
|
+
}
|
|
26
|
+
return function (actionCommand) {
|
|
27
|
+
analyticsPromise = analyticsPromise.then(() => logData({
|
|
28
|
+
os: os.platform(),
|
|
29
|
+
os_version: os.release(),
|
|
30
|
+
node_version: process.version,
|
|
31
|
+
cli_version: version,
|
|
32
|
+
cli_command: actionCommand.name(),
|
|
33
|
+
params: fn?.(actionCommand) ?? {},
|
|
34
|
+
}).catch(() => { }));
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export async function flushAnalytics() {
|
|
38
|
+
await analyticsPromise;
|
|
39
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// MIT License
|
|
2
|
+
//
|
|
3
|
+
// Copyright (c) Hiroki Osame <hiroki.osame@gmail.com>
|
|
4
|
+
//
|
|
5
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
// in the Software without restriction, including without limitation the rights
|
|
8
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
// furnished to do so, subject to the following conditions:
|
|
11
|
+
//
|
|
12
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
// copies or substantial portions of the Software.
|
|
14
|
+
//
|
|
15
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
// SOFTWARE.
|
|
22
|
+
//
|
|
23
|
+
// https://github.com/privatenumber/tsx/tree/28a3e7d2b8fd72b683aab8a98dd1fcee4624e4cb
|
|
24
|
+
import net from "node:net";
|
|
25
|
+
import { getPipePath } from "./utils/get-pipe-path.mjs";
|
|
26
|
+
export const connectToServer = (processId = process.ppid) => new Promise((resolve) => {
|
|
27
|
+
const pipePath = getPipePath(processId);
|
|
28
|
+
const socket = net.createConnection(pipePath, () => {
|
|
29
|
+
const sendToParent = (data) => {
|
|
30
|
+
const messageBuffer = Buffer.from(JSON.stringify(data));
|
|
31
|
+
const lengthBuffer = Buffer.alloc(4);
|
|
32
|
+
lengthBuffer.writeInt32BE(messageBuffer.length, 0);
|
|
33
|
+
socket.write(Buffer.concat([lengthBuffer, messageBuffer]));
|
|
34
|
+
};
|
|
35
|
+
resolve(sendToParent);
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Ignore error when:
|
|
39
|
+
* - Called as a loader and there is no server
|
|
40
|
+
* - Nested process when using --test and the ppid is incorrect
|
|
41
|
+
*/
|
|
42
|
+
socket.on("error", () => {
|
|
43
|
+
resolve(undefined);
|
|
44
|
+
});
|
|
45
|
+
// Prevent Node from waiting for this socket to close before exiting
|
|
46
|
+
socket.unref();
|
|
47
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// MIT License
|
|
2
|
+
//
|
|
3
|
+
// Copyright (c) Hiroki Osame <hiroki.osame@gmail.com>
|
|
4
|
+
//
|
|
5
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
// in the Software without restriction, including without limitation the rights
|
|
8
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
// furnished to do so, subject to the following conditions:
|
|
11
|
+
//
|
|
12
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
// copies or substantial portions of the Software.
|
|
14
|
+
//
|
|
15
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
// SOFTWARE.
|
|
22
|
+
//
|
|
23
|
+
// https://github.com/privatenumber/tsx/tree/28a3e7d2b8fd72b683aab8a98dd1fcee4624e4cb
|
|
24
|
+
import net from "node:net";
|
|
25
|
+
import fs from "node:fs";
|
|
26
|
+
import { tmpdir } from "./utils/temporary-directory.mjs";
|
|
27
|
+
import { getPipePath } from "./utils/get-pipe-path.mjs";
|
|
28
|
+
const bufferData = (onMessage) => {
|
|
29
|
+
let buffer = Buffer.alloc(0);
|
|
30
|
+
return (data) => {
|
|
31
|
+
buffer = Buffer.concat([buffer, data]);
|
|
32
|
+
while (buffer.length > 4) {
|
|
33
|
+
const messageLength = buffer.readInt32BE(0);
|
|
34
|
+
if (buffer.length >= 4 + messageLength) {
|
|
35
|
+
const message = buffer.slice(4, 4 + messageLength);
|
|
36
|
+
onMessage(message);
|
|
37
|
+
buffer = buffer.slice(4 + messageLength);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export const createIpcServer = async () => {
|
|
46
|
+
const server = net.createServer((socket) => {
|
|
47
|
+
socket.on("data", bufferData((message) => {
|
|
48
|
+
const data = JSON.parse(message.toString());
|
|
49
|
+
server.emit("data", data);
|
|
50
|
+
}));
|
|
51
|
+
});
|
|
52
|
+
const pipePath = getPipePath(process.pid);
|
|
53
|
+
await fs.promises.mkdir(tmpdir, { recursive: true });
|
|
54
|
+
/**
|
|
55
|
+
* Fix #457 (https://github.com/privatenumber/tsx/issues/457)
|
|
56
|
+
*
|
|
57
|
+
* Avoid the error "EADDRINUSE: address already in use"
|
|
58
|
+
*
|
|
59
|
+
* If the pipe file already exists, it means that the previous process has been closed abnormally.
|
|
60
|
+
*
|
|
61
|
+
* We can safely delete the pipe file, the previous process must has been closed,
|
|
62
|
+
* as pid is unique at the same.
|
|
63
|
+
*/
|
|
64
|
+
await fs.promises.rm(pipePath, { force: true });
|
|
65
|
+
await new Promise((resolve, reject) => {
|
|
66
|
+
server.listen(pipePath, resolve);
|
|
67
|
+
server.on("error", reject);
|
|
68
|
+
});
|
|
69
|
+
// Prevent Node from waiting for this socket to close before exiting
|
|
70
|
+
server.unref();
|
|
71
|
+
process.on("exit", () => {
|
|
72
|
+
server.close();
|
|
73
|
+
/**
|
|
74
|
+
* Only clean on Unix
|
|
75
|
+
*
|
|
76
|
+
* https://nodejs.org/api/net.html#ipc-support:
|
|
77
|
+
* On Windows, the local domain is implemented using a named pipe.
|
|
78
|
+
* The path must refer to an entry in \\?\pipe\ or \\.\pipe\.
|
|
79
|
+
* Any characters are permitted, but the latter may do some processing
|
|
80
|
+
* of pipe names, such as resolving .. sequences. Despite how it might
|
|
81
|
+
* look, the pipe namespace is flat. Pipes will not persist. They are
|
|
82
|
+
* removed when the last reference to them is closed. Unlike Unix domain
|
|
83
|
+
* sockets, Windows will close and remove the pipe when the owning process exits.
|
|
84
|
+
*/
|
|
85
|
+
if (process.platform !== "win32") {
|
|
86
|
+
try {
|
|
87
|
+
fs.rmSync(pipePath);
|
|
88
|
+
}
|
|
89
|
+
catch { }
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
return [process.pid, server];
|
|
93
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// MIT License
|
|
2
|
+
//
|
|
3
|
+
// Copyright (c) Hiroki Osame <hiroki.osame@gmail.com>
|
|
4
|
+
//
|
|
5
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
// in the Software without restriction, including without limitation the rights
|
|
8
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
// furnished to do so, subject to the following conditions:
|
|
11
|
+
//
|
|
12
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
// copies or substantial portions of the Software.
|
|
14
|
+
//
|
|
15
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
// SOFTWARE.
|
|
22
|
+
//
|
|
23
|
+
// https://github.com/privatenumber/tsx/tree/28a3e7d2b8fd72b683aab8a98dd1fcee4624e4cb
|
|
24
|
+
import path from "node:path";
|
|
25
|
+
import { tmpdir } from "./temporary-directory.mjs";
|
|
26
|
+
export const getPipePath = (processId) => {
|
|
27
|
+
const pipePath = path.join(tmpdir, `${processId}.pipe`);
|
|
28
|
+
return process.platform === "win32" ? `\\\\?\\pipe\\${pipePath}` : pipePath;
|
|
29
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// MIT License
|
|
2
|
+
//
|
|
3
|
+
// Copyright (c) Hiroki Osame <hiroki.osame@gmail.com>
|
|
4
|
+
//
|
|
5
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
// in the Software without restriction, including without limitation the rights
|
|
8
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
// furnished to do so, subject to the following conditions:
|
|
11
|
+
//
|
|
12
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
// copies or substantial portions of the Software.
|
|
14
|
+
//
|
|
15
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
// SOFTWARE.
|
|
22
|
+
//
|
|
23
|
+
// https://github.com/privatenumber/tsx/tree/28a3e7d2b8fd72b683aab8a98dd1fcee4624e4cb
|
|
24
|
+
import path from "node:path";
|
|
25
|
+
import os from "node:os";
|
|
26
|
+
/**
|
|
27
|
+
* Cache directory is based on the user's identifier
|
|
28
|
+
* to avoid permission issues when accessed by a different user
|
|
29
|
+
*/
|
|
30
|
+
const { geteuid } = process;
|
|
31
|
+
const userId = geteuid
|
|
32
|
+
? // For Linux users with virtual users on CI (e.g. Docker)
|
|
33
|
+
geteuid()
|
|
34
|
+
: // Use username on Windows because it doesn't have id
|
|
35
|
+
os.userInfo().username;
|
|
36
|
+
/**
|
|
37
|
+
* This ensures that the cache directory is unique per user
|
|
38
|
+
* and has the appropriate permissions
|
|
39
|
+
*/
|
|
40
|
+
export const tmpdir = path.join(os.tmpdir(), `tsx-${userId}`);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as url from "node:url";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
export async function getProjectPath(key) {
|
|
5
|
+
const configPathOrFile = key.startsWith("file://")
|
|
6
|
+
? url.fileURLToPath(key)
|
|
7
|
+
: path.resolve(process.cwd(), key);
|
|
8
|
+
let configPath = undefined;
|
|
9
|
+
if ((await fs.stat(configPathOrFile)).isDirectory()) {
|
|
10
|
+
configPath = path.join(configPathOrFile, "langgraph.json");
|
|
11
|
+
}
|
|
12
|
+
else if (path.basename(configPathOrFile) === "langgraph.json") {
|
|
13
|
+
configPath = configPathOrFile;
|
|
14
|
+
}
|
|
15
|
+
if (!configPath)
|
|
16
|
+
throw new Error("Invalid path");
|
|
17
|
+
return configPath;
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import * as url from "node:url";
|
|
3
|
+
async function getVersion() {
|
|
4
|
+
try {
|
|
5
|
+
const packageJson = url.fileURLToPath(new URL("../../../package.json", import.meta.url));
|
|
6
|
+
const { version } = JSON.parse(await fs.readFile(packageJson, "utf-8"));
|
|
7
|
+
return version + "+js";
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return "0.0.0-unknown";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export const version = await getVersion();
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { $ } from "execa";
|
|
2
|
+
import * as yaml from "yaml";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { getExecaOptions } from "./shell.mjs";
|
|
5
|
+
export const DEFAULT_POSTGRES_URI = "postgres://postgres:postgres@langgraph-postgres:5432/postgres?sslmode=disable";
|
|
6
|
+
const REDIS = {
|
|
7
|
+
image: "redis:6",
|
|
8
|
+
healthcheck: {
|
|
9
|
+
test: "redis-cli ping",
|
|
10
|
+
start_period: "10s",
|
|
11
|
+
timeout: "1s",
|
|
12
|
+
retries: 5,
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
const DB = {
|
|
16
|
+
image: "pgvector/pgvector:pg16",
|
|
17
|
+
// TODO: make exposing postgres optional
|
|
18
|
+
// ports: ['5433:5432'],
|
|
19
|
+
expose: ["5432"],
|
|
20
|
+
command: ["postgres", "-c", "shared_preload_libraries=vector"],
|
|
21
|
+
environment: {
|
|
22
|
+
POSTGRES_DB: "postgres",
|
|
23
|
+
POSTGRES_USER: "postgres",
|
|
24
|
+
POSTGRES_PASSWORD: "postgres",
|
|
25
|
+
},
|
|
26
|
+
volumes: ["langgraph-data:/var/lib/postgresql/data"],
|
|
27
|
+
healthcheck: {
|
|
28
|
+
test: "pg_isready -U postgres",
|
|
29
|
+
start_period: "10s",
|
|
30
|
+
timeout: "1s",
|
|
31
|
+
retries: 5,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
function parseVersion(input) {
|
|
35
|
+
const parts = input.trim().split(".", 3);
|
|
36
|
+
const majorStr = parts[0] ?? "0";
|
|
37
|
+
const minorStr = parts[1] ?? "0";
|
|
38
|
+
const patchStr = parts[2] ?? "0";
|
|
39
|
+
const major = Number.parseInt(majorStr.startsWith("v") ? majorStr.slice(1) : majorStr);
|
|
40
|
+
const minor = Number.parseInt(minorStr);
|
|
41
|
+
const patch = Number.parseInt(patchStr.split("-").at(0) ?? "0");
|
|
42
|
+
return { major, minor, patch };
|
|
43
|
+
}
|
|
44
|
+
function compareVersion(a, b) {
|
|
45
|
+
if (a.major !== b.major) {
|
|
46
|
+
return Math.sign(a.major - b.major);
|
|
47
|
+
}
|
|
48
|
+
if (a.minor !== b.minor) {
|
|
49
|
+
return Math.sign(a.minor - b.minor);
|
|
50
|
+
}
|
|
51
|
+
return Math.sign(a.patch - b.patch);
|
|
52
|
+
}
|
|
53
|
+
export async function getDockerCapabilities() {
|
|
54
|
+
let rawInfo = null;
|
|
55
|
+
try {
|
|
56
|
+
const { stdout } = await $(await getExecaOptions()) `docker info -f json`;
|
|
57
|
+
rawInfo = JSON.parse(stdout);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
throw new Error("Docker not installed or not running: " + error);
|
|
61
|
+
}
|
|
62
|
+
const info = z
|
|
63
|
+
.object({
|
|
64
|
+
ServerVersion: z.string(),
|
|
65
|
+
ClientInfo: z.object({
|
|
66
|
+
Plugins: z.array(z.object({
|
|
67
|
+
Name: z.string(),
|
|
68
|
+
Version: z.string().optional(),
|
|
69
|
+
})),
|
|
70
|
+
}),
|
|
71
|
+
})
|
|
72
|
+
.safeParse(rawInfo);
|
|
73
|
+
if (!info.success || !info.data.ServerVersion) {
|
|
74
|
+
throw new Error("Docker not running");
|
|
75
|
+
}
|
|
76
|
+
const composePlugin = info.data.ClientInfo.Plugins.find((i) => i.Name === "compose" && i.Version != null);
|
|
77
|
+
const buildxPlugin = info.data.ClientInfo.Plugins.find((i) => i.Name === "buildx" && i.Version != null);
|
|
78
|
+
let composeRes;
|
|
79
|
+
if (composePlugin != null) {
|
|
80
|
+
composeRes = {
|
|
81
|
+
composeType: "plugin",
|
|
82
|
+
versionCompose: parseVersion(composePlugin.Version),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
try {
|
|
87
|
+
const standalone = await $(await getExecaOptions()) `docker-compose --version --short`;
|
|
88
|
+
composeRes = {
|
|
89
|
+
composeType: "standalone",
|
|
90
|
+
versionCompose: parseVersion(standalone.stdout),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
console.error(error);
|
|
95
|
+
throw new Error("Docker Compose not installed");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const versionDocker = parseVersion(info.data.ServerVersion);
|
|
99
|
+
if (compareVersion(versionDocker, parseVersion("23.0.5")) < 0) {
|
|
100
|
+
throw new Error("Please upgrade Docker to at least 23.0.5");
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
...composeRes,
|
|
104
|
+
healthcheckStartInterval: compareVersion(versionDocker, parseVersion("25.0.0")) >= 0,
|
|
105
|
+
watchAvailable: compareVersion(composeRes.versionCompose, parseVersion("2.25.0")) >= 0,
|
|
106
|
+
buildAvailable: buildxPlugin != null,
|
|
107
|
+
versionDocker,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function isPlainObject(value) {
|
|
111
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
112
|
+
}
|
|
113
|
+
export function createCompose(capabilities, options) {
|
|
114
|
+
let includeDb = false;
|
|
115
|
+
let postgresUri = options.postgresUri;
|
|
116
|
+
if (!options.postgresUri) {
|
|
117
|
+
includeDb = true;
|
|
118
|
+
postgresUri = DEFAULT_POSTGRES_URI;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
includeDb = false;
|
|
122
|
+
}
|
|
123
|
+
const compose = {
|
|
124
|
+
services: {},
|
|
125
|
+
};
|
|
126
|
+
compose.services["langgraph-redis"] = { ...REDIS };
|
|
127
|
+
if (includeDb) {
|
|
128
|
+
compose.volumes = {
|
|
129
|
+
"langgraph-data": { driver: "local" },
|
|
130
|
+
};
|
|
131
|
+
compose.services["langgraph-postgres"] = { ...DB };
|
|
132
|
+
if (capabilities.healthcheckStartInterval) {
|
|
133
|
+
compose.services["langgraph-postgres"].healthcheck.interval = "60s";
|
|
134
|
+
compose.services["langgraph-postgres"].healthcheck.start_interval = "1s";
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
compose.services["langgraph-postgres"].healthcheck.interval = "5s";
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
compose.services["langgraph-api"] = {
|
|
141
|
+
ports: [options.port ? `${options.port}:8000` : "8000"],
|
|
142
|
+
environment: {
|
|
143
|
+
REDIS_URI: "redis://langgraph-redis:6379",
|
|
144
|
+
POSTGRES_URI: postgresUri,
|
|
145
|
+
},
|
|
146
|
+
depends_on: {
|
|
147
|
+
"langgraph-redis": { condition: "service_healthy" },
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
if (includeDb) {
|
|
151
|
+
compose.services["langgraph-api"].depends_on["langgraph-postgres"] = {
|
|
152
|
+
condition: "service_healthy",
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
if (capabilities.healthcheckStartInterval) {
|
|
156
|
+
compose.services["langgraph-api"].healthcheck = {
|
|
157
|
+
test: "python /api/healthcheck.py",
|
|
158
|
+
interval: "60s",
|
|
159
|
+
start_interval: "1s",
|
|
160
|
+
start_period: "10s",
|
|
161
|
+
};
|
|
162
|
+
compose.services["langgraph-redis"].healthcheck.interval = "60s";
|
|
163
|
+
compose.services["langgraph-redis"].healthcheck.start_interval = "1s";
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
compose.services["langgraph-redis"].healthcheck.interval = "5s";
|
|
167
|
+
}
|
|
168
|
+
// merge in with rest of the payload
|
|
169
|
+
if (options.apiDef) {
|
|
170
|
+
for (const key in options.apiDef) {
|
|
171
|
+
const prevValue = compose.services["langgraph-api"][key];
|
|
172
|
+
const newValue = options.apiDef[key];
|
|
173
|
+
if (isPlainObject(prevValue) && isPlainObject(newValue)) {
|
|
174
|
+
compose.services["langgraph-api"][key] = {
|
|
175
|
+
...prevValue,
|
|
176
|
+
...newValue,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
compose.services["langgraph-api"][key] = newValue;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return yaml.stringify(compose, { blockQuote: "literal" });
|
|
185
|
+
}
|