@langchain/langgraph-cli 0.0.0-preview.4 → 0.0.0-preview.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/LICENSE +93 -0
- package/README.md +55 -10
- package/dist/cli/build.mjs +3 -3
- package/dist/cli/cli.mjs +2 -2
- package/dist/cli/dev.mjs +2 -2
- package/dist/cli/docker.mjs +107 -0
- package/dist/cli/up.mjs +126 -0
- package/dist/utils/config.mjs +16 -4
- package/package.json +2 -1
- package/dist/cli/dockerfile.mjs +0 -35
- /package/dist/docker/{dockerfile.mjs → docker.mjs} +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Elastic License 2.0
|
|
2
|
+
|
|
3
|
+
URL: https://www.elastic.co/licensing/elastic-license
|
|
4
|
+
|
|
5
|
+
## Acceptance
|
|
6
|
+
|
|
7
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
8
|
+
|
|
9
|
+
## Copyright License
|
|
10
|
+
|
|
11
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide,
|
|
12
|
+
non-sublicensable, non-transferable license to use, copy, distribute, make
|
|
13
|
+
available, and prepare derivative works of the software, in each case subject to
|
|
14
|
+
the limitations and conditions below.
|
|
15
|
+
|
|
16
|
+
## Limitations
|
|
17
|
+
|
|
18
|
+
You may not provide the software to third parties as a hosted or managed
|
|
19
|
+
service, where the service provides users with access to any substantial set of
|
|
20
|
+
the features or functionality of the software.
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,24 +1,69 @@
|
|
|
1
|
-
# LangGraph.js
|
|
1
|
+
# LangGraph.js CLI
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
For production use, see the various [deployment options](https://langchain-ai.github.io/langgraph/concepts/deployment_options/) for the LangGraph API, which are backed by a production-grade database.
|
|
3
|
+
The official command-line interface for LangGraph.js, providing tools to create, develop, and deploy LangGraph.js applications.
|
|
6
4
|
|
|
7
5
|
## Installation
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
The `@langchain/langgraph-cli` is a CLI binary that can be run via `npx` or installed via your package manager of choice:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx @langchain/langgraph-cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Commands
|
|
14
|
+
|
|
15
|
+
### `langgraph dev`
|
|
16
|
+
|
|
17
|
+
Run LangGraph.js API server in development mode with hot reloading.
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
langgraph dev
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### `langgraph build`
|
|
24
|
+
|
|
25
|
+
Build a Docker image for your LangGraph.js application.
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
langgraph build
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### `langgraph up`
|
|
32
|
+
|
|
33
|
+
Run LangGraph.js API server in Docker.
|
|
10
34
|
|
|
11
35
|
```bash
|
|
12
|
-
|
|
36
|
+
langgraph up
|
|
13
37
|
```
|
|
14
38
|
|
|
15
|
-
|
|
39
|
+
### `langgraph dockerfile`
|
|
16
40
|
|
|
17
|
-
|
|
41
|
+
Generate a Dockerfile for custom deployments
|
|
18
42
|
|
|
19
43
|
```bash
|
|
20
|
-
|
|
44
|
+
langgraph dockerfile <save path>
|
|
21
45
|
```
|
|
22
46
|
|
|
23
|
-
|
|
47
|
+
## Configuration
|
|
48
|
+
|
|
49
|
+
The CLI uses a `langgraph.json` configuration file with these key settings:
|
|
50
|
+
|
|
51
|
+
```json5
|
|
52
|
+
{
|
|
53
|
+
// Required: Graph definitions
|
|
54
|
+
"graphs": {
|
|
55
|
+
"graph": "./src/graph.ts:graph"
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
// Optional: Node version (20 only at the moment)
|
|
59
|
+
"node_version": "20",
|
|
60
|
+
|
|
61
|
+
// Optional: Environment variables
|
|
62
|
+
"env": ".env",
|
|
63
|
+
|
|
64
|
+
// Optional: Additional Dockerfile commands
|
|
65
|
+
"dockerfile_lines": []
|
|
66
|
+
}
|
|
67
|
+
```
|
|
24
68
|
|
|
69
|
+
See the [full documentation](https://langchain-ai.github.io/langgraph/cloud/reference/cli) for detailed configuration options.
|
package/dist/cli/build.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getDockerCapabilities } from "../docker/compose.mjs";
|
|
2
|
-
import { assembleLocalDeps, configToDocker, getBaseImage, } from "../docker/
|
|
2
|
+
import { assembleLocalDeps, configToDocker, getBaseImage, } from "../docker/docker.mjs";
|
|
3
3
|
import { getExecaOptions } from "../docker/shell.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { getConfig } from "../utils/config.mjs";
|
|
5
5
|
import { builder } from "./utils/builder.mjs";
|
|
6
6
|
import { getProjectPath } from "./utils/project.mjs";
|
|
7
7
|
import { $ } from "execa";
|
|
@@ -24,7 +24,7 @@ builder
|
|
|
24
24
|
const configPath = await getProjectPath(params.config);
|
|
25
25
|
await getDockerCapabilities();
|
|
26
26
|
const projectDir = path.dirname(configPath);
|
|
27
|
-
const config =
|
|
27
|
+
const config = getConfig(await fs.readFile(configPath, "utf-8"));
|
|
28
28
|
const opts = await getExecaOptions({
|
|
29
29
|
cwd: projectDir,
|
|
30
30
|
stderr: "inherit",
|
package/dist/cli/cli.mjs
CHANGED
package/dist/cli/dev.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { spawn } from "node:child_process";
|
|
|
5
5
|
import open from "open";
|
|
6
6
|
import * as dotenv from "dotenv";
|
|
7
7
|
import { logger } from "../logging.mjs";
|
|
8
|
-
import {
|
|
8
|
+
import { getConfig } from "../utils/config.mjs";
|
|
9
9
|
import { createIpcServer } from "./utils/ipc/server.mjs";
|
|
10
10
|
import { z } from "zod";
|
|
11
11
|
import { watch } from "chokidar";
|
|
@@ -70,7 +70,7 @@ For production use, please use LangGraph Cloud.
|
|
|
70
70
|
await fs.appendFile(gitignorePath, "\n# LangGraph API\n.langgraph_api\n");
|
|
71
71
|
}
|
|
72
72
|
const prepareContext = async () => {
|
|
73
|
-
const config =
|
|
73
|
+
const config = getConfig(await fs.readFile(configPath, "utf-8"));
|
|
74
74
|
const newWatch = [configPath];
|
|
75
75
|
const env = { ...process.env };
|
|
76
76
|
const configEnv = config?.env;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { assembleLocalDeps, configToCompose, configToDocker, } from "../docker/docker.mjs";
|
|
2
|
+
import { createCompose, getDockerCapabilities } from "../docker/compose.mjs";
|
|
3
|
+
import { getConfig } from "../utils/config.mjs";
|
|
4
|
+
import { getProjectPath } from "./utils/project.mjs";
|
|
5
|
+
import { builder } from "./utils/builder.mjs";
|
|
6
|
+
import * as fs from "node:fs/promises";
|
|
7
|
+
import * as path from "node:path";
|
|
8
|
+
import dedent from "dedent";
|
|
9
|
+
import { logger } from "../logging.mjs";
|
|
10
|
+
const fileExists = async (path) => {
|
|
11
|
+
try {
|
|
12
|
+
await fs.access(path);
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
builder
|
|
20
|
+
.command("dockerfile")
|
|
21
|
+
.description("Generate a Dockerfile for the LangGraph API server, with Docker Compose options.")
|
|
22
|
+
.argument("<save-path>", "Path to save the Dockerfile")
|
|
23
|
+
.option("--add-docker-compose", "Add additional files for running the LangGraph API server with docker-compose. These files include a docker-compose.yml, .env file, and a .dockerignore file.")
|
|
24
|
+
.option("-c, --config <path>", "Path to configuration file", process.cwd())
|
|
25
|
+
.action(async (savePath, options) => {
|
|
26
|
+
const configPath = await getProjectPath(options.config);
|
|
27
|
+
const config = getConfig(await fs.readFile(configPath, "utf-8"));
|
|
28
|
+
const localDeps = await assembleLocalDeps(configPath, config);
|
|
29
|
+
const dockerfile = await configToDocker(configPath, config, localDeps);
|
|
30
|
+
if (savePath === "-") {
|
|
31
|
+
process.stdout.write(dockerfile);
|
|
32
|
+
process.stdout.write("\n");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const targetPath = path.resolve(process.cwd(), savePath);
|
|
36
|
+
await fs.writeFile(targetPath, dockerfile);
|
|
37
|
+
logger.info(`✅ Created: ${path.basename(targetPath)}`);
|
|
38
|
+
if (options.addDockerCompose) {
|
|
39
|
+
const { apiDef } = await configToCompose(configPath, config, {
|
|
40
|
+
watch: false,
|
|
41
|
+
});
|
|
42
|
+
const capabilities = await getDockerCapabilities();
|
|
43
|
+
const compose = createCompose(capabilities, { apiDef });
|
|
44
|
+
const composePath = path.resolve(path.dirname(targetPath), "docker-compose.yml");
|
|
45
|
+
await fs.writeFile(composePath, compose);
|
|
46
|
+
logger.info("✅ Created: .docker-compose.yml");
|
|
47
|
+
const dockerignorePath = path.resolve(path.dirname(targetPath), ".dockerignore");
|
|
48
|
+
if (!fileExists(dockerignorePath)) {
|
|
49
|
+
await fs.writeFile(dockerignorePath, dedent `
|
|
50
|
+
# Ignore node_modules and other dependency directories
|
|
51
|
+
node_modules
|
|
52
|
+
bower_components
|
|
53
|
+
vendor
|
|
54
|
+
|
|
55
|
+
# Ignore logs and temporary files
|
|
56
|
+
*.log
|
|
57
|
+
*.tmp
|
|
58
|
+
*.swp
|
|
59
|
+
|
|
60
|
+
# Ignore .env files and other environment files
|
|
61
|
+
.env
|
|
62
|
+
.env.*
|
|
63
|
+
*.local
|
|
64
|
+
|
|
65
|
+
# Ignore git-related files
|
|
66
|
+
.git
|
|
67
|
+
.gitignore
|
|
68
|
+
|
|
69
|
+
# Ignore Docker-related files and configs
|
|
70
|
+
.dockerignore
|
|
71
|
+
docker-compose.yml
|
|
72
|
+
|
|
73
|
+
# Ignore build and cache directories
|
|
74
|
+
dist
|
|
75
|
+
build
|
|
76
|
+
.cache
|
|
77
|
+
__pycache__
|
|
78
|
+
|
|
79
|
+
# Ignore IDE and editor configurations
|
|
80
|
+
.vscode
|
|
81
|
+
.idea
|
|
82
|
+
*.sublime-project
|
|
83
|
+
*.sublime-workspace
|
|
84
|
+
.DS_Store # macOS-specific
|
|
85
|
+
|
|
86
|
+
# Ignore test and coverage files
|
|
87
|
+
coverage
|
|
88
|
+
*.coverage
|
|
89
|
+
*.test.js
|
|
90
|
+
*.spec.js
|
|
91
|
+
tests
|
|
92
|
+
`);
|
|
93
|
+
logger.info(`✅ Created: ${path.basename(dockerignorePath)}`);
|
|
94
|
+
}
|
|
95
|
+
const envPath = path.resolve(path.dirname(targetPath), ".env");
|
|
96
|
+
if (!fileExists(envPath)) {
|
|
97
|
+
await fs.writeFile(envPath, dedent `
|
|
98
|
+
# Uncomment the following line to add your LangSmith API key
|
|
99
|
+
# LANGSMITH_API_KEY=your-api-key
|
|
100
|
+
# Or if you have a LangGraph Cloud license key, then uncomment the following line:
|
|
101
|
+
# LANGGRAPH_CLOUD_LICENSE_KEY=your-license-key
|
|
102
|
+
# Add any other environment variables go below...
|
|
103
|
+
`);
|
|
104
|
+
logger.info(`✅ Created: ${path.basename(envPath)}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
package/dist/cli/up.mjs
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
const sha256 = (input) => createHash("sha256").update(input).digest("hex");
|
|
14
|
+
const getProjectName = (configPath) => {
|
|
15
|
+
const cwd = path.dirname(configPath).toLocaleLowerCase();
|
|
16
|
+
return `${path.basename(cwd)}-${sha256(cwd)}`;
|
|
17
|
+
};
|
|
18
|
+
const stream = (proc) => {
|
|
19
|
+
logger.debug(`Running "${proc.spawnargs.join(" ")}"`);
|
|
20
|
+
return proc;
|
|
21
|
+
};
|
|
22
|
+
const waitForHealthcheck = async (port) => {
|
|
23
|
+
const now = Date.now();
|
|
24
|
+
while (Date.now() - now < 10_000) {
|
|
25
|
+
const ok = await fetch(`http://localhost:${port}/ok`).then((res) => res.ok, () => false);
|
|
26
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
27
|
+
if (ok)
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
throw new Error("Healthcheck timed out");
|
|
31
|
+
};
|
|
32
|
+
builder
|
|
33
|
+
.command("up")
|
|
34
|
+
.description("Launch LangGraph API server.")
|
|
35
|
+
.option("-c, --config <path>", "Path to configuration file", process.cwd())
|
|
36
|
+
.option("-d, --docker-compose <path>", "Advanced: Path to docker-compose.yml file with additional services to launch")
|
|
37
|
+
.option("-p, --port <port>", "Port to run the server on", "8000")
|
|
38
|
+
.option("--recreate", "Force recreate containers and volumes", false)
|
|
39
|
+
.option("--no-pull", "Running the server with locally-built images. By default LangGraph will pull the latest images from the registry")
|
|
40
|
+
.option("--watch", "Restart on file changes", false)
|
|
41
|
+
.option("--wait", "Wait for services to start before returning. Implies --detach", false)
|
|
42
|
+
.option("--postgres-uri <uri>", "Postgres URI to use for the database. Defaults to launching a local database")
|
|
43
|
+
.action(async (params) => {
|
|
44
|
+
logger.info("Starting LangGraph API server...");
|
|
45
|
+
logger.warn(dedent `
|
|
46
|
+
For local dev, requires env var LANGSMITH_API_KEY with access to LangGraph Cloud closed beta.
|
|
47
|
+
For production use, requires a license key in env var LANGGRAPH_CLOUD_LICENSE_KEY.
|
|
48
|
+
`);
|
|
49
|
+
const configPath = await getProjectPath(params.config);
|
|
50
|
+
const config = getConfig(await fs.readFile(configPath, "utf-8"));
|
|
51
|
+
const cwd = path.dirname(configPath);
|
|
52
|
+
const capabilities = await getDockerCapabilities();
|
|
53
|
+
const fullRestartFiles = [configPath];
|
|
54
|
+
if (typeof config.env === "string") {
|
|
55
|
+
fullRestartFiles.push(path.resolve(cwd, config.env));
|
|
56
|
+
}
|
|
57
|
+
const { apiDef } = await configToCompose(configPath, config, {
|
|
58
|
+
watch: capabilities.watchAvailable,
|
|
59
|
+
});
|
|
60
|
+
const name = getProjectName(configPath);
|
|
61
|
+
const execOpts = await getExecaOptions({
|
|
62
|
+
cwd,
|
|
63
|
+
stdout: "inherit",
|
|
64
|
+
stderr: "inherit",
|
|
65
|
+
});
|
|
66
|
+
const exec = $(execOpts);
|
|
67
|
+
if (!config._INTERNAL_docker_tag && params.pull) {
|
|
68
|
+
// pull the image
|
|
69
|
+
logger.info(`Pulling image ${getBaseImage(config)}...`);
|
|
70
|
+
await stream(exec `docker pull ${getBaseImage(config)}`);
|
|
71
|
+
}
|
|
72
|
+
// remove dangling images
|
|
73
|
+
logger.info(`Pruning dangling images...`);
|
|
74
|
+
await stream(exec `docker image prune -f --filter ${`label=com.docker.compose.project=${name}`}`);
|
|
75
|
+
// remove stale containers
|
|
76
|
+
logger.info(`Pruning stale containers...`);
|
|
77
|
+
await stream(exec `docker container prune -f --filter ${`label=com.docker.compose.project=${name}`}`);
|
|
78
|
+
const input = createCompose(capabilities, {
|
|
79
|
+
port: +params.port,
|
|
80
|
+
postgresUri: params.postgresUri,
|
|
81
|
+
apiDef,
|
|
82
|
+
});
|
|
83
|
+
const args = ["--remove-orphans"];
|
|
84
|
+
if (params.recreate) {
|
|
85
|
+
args.push("--force-recreate", "--renew-anon-volumes");
|
|
86
|
+
try {
|
|
87
|
+
await stream(exec `docker volume rm langgraph-data`);
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
// ignore
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (params.watch) {
|
|
94
|
+
if (capabilities.watchAvailable) {
|
|
95
|
+
args.push("--watch");
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
logger.warn("Watch mode is not available. Please upgrade your Docker Engine.");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else if (params.wait) {
|
|
102
|
+
args.push("--wait");
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
args.push("--abort-on-container-exit");
|
|
106
|
+
}
|
|
107
|
+
logger.info(`Launching docker-compose...`);
|
|
108
|
+
const cmd = capabilities.composeType === "plugin"
|
|
109
|
+
? ["docker", "compose"]
|
|
110
|
+
: ["docker-compose"];
|
|
111
|
+
cmd.push("--project-directory", cwd, "--project-name", name);
|
|
112
|
+
const userCompose = params.dockerCompose || config.docker_compose_file;
|
|
113
|
+
if (userCompose)
|
|
114
|
+
cmd.push("-f", userCompose);
|
|
115
|
+
cmd.push("-f", "-");
|
|
116
|
+
const up = stream($({ ...execOpts, input }) `${cmd} up ${args}`);
|
|
117
|
+
waitForHealthcheck(+params.port).then(() => {
|
|
118
|
+
logger.info(`
|
|
119
|
+
Ready!
|
|
120
|
+
- API: http://localhost:${params.port}
|
|
121
|
+
- Docs: http://localhost:${params.port}/docs
|
|
122
|
+
- LangGraph Studio: https://smith.langchain.com/studio/?baseUrl=http://127.0.0.1:${params.port}
|
|
123
|
+
`);
|
|
124
|
+
}, () => void 0);
|
|
125
|
+
await up.catch(() => void 0);
|
|
126
|
+
});
|
package/dist/utils/config.mjs
CHANGED
|
@@ -14,7 +14,7 @@ const StoreConfigSchema = z.object({
|
|
|
14
14
|
const BaseConfigSchema = z.object({
|
|
15
15
|
docker_compose_file: z.string().optional(),
|
|
16
16
|
dockerfile_lines: z.array(z.string()).default([]),
|
|
17
|
-
graphs: z.record(z.string())
|
|
17
|
+
graphs: z.record(z.string()),
|
|
18
18
|
env: z
|
|
19
19
|
.union([z.array(z.string()), z.record(z.string()), z.string()])
|
|
20
20
|
.default({}),
|
|
@@ -22,7 +22,7 @@ const BaseConfigSchema = z.object({
|
|
|
22
22
|
_INTERNAL_docker_tag: z.string().optional(),
|
|
23
23
|
auth: AuthConfigSchema.optional(),
|
|
24
24
|
});
|
|
25
|
-
|
|
25
|
+
const PythonConfigSchema = BaseConfigSchema.merge(z.object({
|
|
26
26
|
python_version: z
|
|
27
27
|
.union([z.literal("3.11"), z.literal("3.12")])
|
|
28
28
|
.default("3.11"),
|
|
@@ -31,5 +31,17 @@ export const PythonConfigSchema = BaseConfigSchema.merge(z.object({
|
|
|
31
31
|
.array(z.string())
|
|
32
32
|
.nonempty("You need to specify at least one dependency"),
|
|
33
33
|
}));
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
const NodeConfigSchema = BaseConfigSchema.merge(z.object({ node_version: z.literal("20").default("20") }));
|
|
35
|
+
const ConfigSchema = z.union([NodeConfigSchema, PythonConfigSchema]);
|
|
36
|
+
import * as path from "node:path";
|
|
37
|
+
const PYTHON_EXTENSIONS = [".py", ".pyx", ".pyd", ".pyi"];
|
|
38
|
+
// TODO: implement this in Python CLI
|
|
39
|
+
export const getConfig = (config) => {
|
|
40
|
+
const rawConfig = typeof config === "string" ? JSON.parse(config) : config;
|
|
41
|
+
const { graphs } = BaseConfigSchema.parse(rawConfig);
|
|
42
|
+
const preferPython = Object.values(graphs).every((i) => PYTHON_EXTENSIONS.includes(path.extname(i.split(":")[0])));
|
|
43
|
+
if (preferPython) {
|
|
44
|
+
return z.union([PythonConfigSchema, NodeConfigSchema]).parse(rawConfig);
|
|
45
|
+
}
|
|
46
|
+
return z.union([NodeConfigSchema, PythonConfigSchema]).parse(rawConfig);
|
|
47
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/langgraph-cli",
|
|
3
|
-
"version": "0.0.0-preview.
|
|
3
|
+
"version": "0.0.0-preview.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18"
|
|
7
7
|
},
|
|
8
|
+
"license": "Elastic-2.0",
|
|
8
9
|
"main": "./dist/server.mjs",
|
|
9
10
|
"bin": {
|
|
10
11
|
"langgraph": "dist/cli/cli.mjs"
|
package/dist/cli/dockerfile.mjs
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { assembleLocalDeps, configToCompose, configToDocker, } from "../docker/dockerfile.mjs";
|
|
2
|
-
import { createCompose, getDockerCapabilities } from "../docker/compose.mjs";
|
|
3
|
-
import { ConfigSchema } from "../utils/config.mjs";
|
|
4
|
-
import { getProjectPath } from "./utils/project.mjs";
|
|
5
|
-
import { builder } from "./utils/builder.mjs";
|
|
6
|
-
import * as fs from "node:fs/promises";
|
|
7
|
-
import * as path from "node:path";
|
|
8
|
-
builder
|
|
9
|
-
.command("dockerfile")
|
|
10
|
-
.description("Generate a Dockerfile for the LangGraph API server, with Docker Compose options.")
|
|
11
|
-
.argument("<save-path>", "Path to save the Dockerfile")
|
|
12
|
-
.option("--add-docker-compose", "Add additional files for running the LangGraph API server with docker-compose. These files include a docker-compose.yml, .env file, and a .dockerignore file.")
|
|
13
|
-
.option("-c, --config <path>", "Path to configuration file", process.cwd())
|
|
14
|
-
.action(async (savePath, options) => {
|
|
15
|
-
const configPath = await getProjectPath(options.config);
|
|
16
|
-
const config = ConfigSchema.parse(JSON.parse(await fs.readFile(configPath, "utf-8")));
|
|
17
|
-
const localDeps = await assembleLocalDeps(configPath, config);
|
|
18
|
-
const dockerfile = await configToDocker(configPath, config, localDeps);
|
|
19
|
-
if (savePath === "-") {
|
|
20
|
-
console.log(dockerfile);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const targetPath = path.resolve(process.cwd(), savePath, "Dockerfile");
|
|
24
|
-
await fs.writeFile(targetPath, dockerfile);
|
|
25
|
-
if (options.addDockerCompose) {
|
|
26
|
-
const { apiDef } = await configToCompose(configPath, config, {
|
|
27
|
-
watch: false,
|
|
28
|
-
});
|
|
29
|
-
const capabilities = await getDockerCapabilities();
|
|
30
|
-
const compose = createCompose(capabilities, { apiDef });
|
|
31
|
-
const composePath = path.resolve(process.cwd(), savePath, "docker-compose.yml");
|
|
32
|
-
await fs.writeFile(composePath, compose);
|
|
33
|
-
// TODO: add .dockerignore and .env files
|
|
34
|
-
}
|
|
35
|
-
});
|
|
File without changes
|