@langchain/langgraph-cli 1.1.2 → 1.1.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.
@@ -1,93 +0,0 @@
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
- };
@@ -1,29 +0,0 @@
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
- };
@@ -1,40 +0,0 @@
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}`);
@@ -1,18 +0,0 @@
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
- }
@@ -1,90 +0,0 @@
1
- import { Transform } from "node:stream";
2
- const CR = "\r".charCodeAt(0);
3
- const LF = "\n".charCodeAt(0);
4
- const TRAILING_NEWLINE = [CR, LF];
5
- function joinArrays(data) {
6
- const totalLength = data.reduce((acc, curr) => acc + curr.length, 0);
7
- let merged = new Uint8Array(totalLength);
8
- let offset = 0;
9
- for (const c of data) {
10
- merged.set(c, offset);
11
- offset += c.length;
12
- }
13
- return merged;
14
- }
15
- export class BytesLineDecoder extends TransformStream {
16
- constructor() {
17
- let buffer = [];
18
- let trailingCr = false;
19
- super({
20
- start() {
21
- buffer = [];
22
- trailingCr = false;
23
- },
24
- transform(chunk, controller) {
25
- // See https://docs.python.org/3/glossary.html#term-universal-newlines
26
- let text = chunk;
27
- // Handle trailing CR from previous chunk
28
- if (trailingCr) {
29
- text = joinArrays([[CR], text]);
30
- trailingCr = false;
31
- }
32
- // Check for trailing CR in current chunk
33
- if (text.length > 0 && text.at(-1) === CR) {
34
- trailingCr = true;
35
- text = text.subarray(0, -1);
36
- }
37
- if (!text.length)
38
- return;
39
- const trailingNewline = TRAILING_NEWLINE.includes(text.at(-1));
40
- const lastIdx = text.length - 1;
41
- const { lines } = text.reduce((acc, cur, idx) => {
42
- if (acc.from > idx)
43
- return acc;
44
- if (cur === CR || cur === LF) {
45
- acc.lines.push(text.subarray(acc.from, idx));
46
- if (cur === CR && text[idx + 1] === LF) {
47
- acc.from = idx + 2;
48
- }
49
- else {
50
- acc.from = idx + 1;
51
- }
52
- }
53
- if (idx === lastIdx && acc.from <= lastIdx) {
54
- acc.lines.push(text.subarray(acc.from));
55
- }
56
- return acc;
57
- }, { lines: [], from: 0 });
58
- if (lines.length === 1 && !trailingNewline) {
59
- buffer.push(lines[0]);
60
- return;
61
- }
62
- if (buffer.length) {
63
- // Include existing buffer in first line
64
- buffer.push(lines[0]);
65
- lines[0] = joinArrays(buffer);
66
- buffer = [];
67
- }
68
- if (!trailingNewline) {
69
- // If the last segment is not newline terminated,
70
- // buffer it for the next chunk
71
- if (lines.length)
72
- buffer = [lines.pop()];
73
- }
74
- // Enqueue complete lines
75
- for (const line of lines) {
76
- controller.enqueue(line);
77
- }
78
- },
79
- flush(controller) {
80
- if (buffer.length) {
81
- controller.enqueue(joinArrays(buffer));
82
- }
83
- },
84
- });
85
- }
86
- fromWeb() {
87
- // @ts-expect-error invalid types for response.body
88
- return Transform.fromWeb(this);
89
- }
90
- }
@@ -1,13 +0,0 @@
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();
@@ -1,185 +0,0 @@
1
- import { $ } from "execa";
2
- import * as yaml from "yaml";
3
- import { z } from "zod/v3";
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
- }