@langchain/langgraph-cli 1.1.1 → 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.
- package/package.json +6 -5
- package/CHANGELOG.md +0 -292
- package/dist/cli/build.mjs +0 -52
- package/dist/cli/cli.mjs +0 -13
- package/dist/cli/cloudflare.mjs +0 -172
- package/dist/cli/dev.mjs +0 -143
- package/dist/cli/dev.python.mjs +0 -129
- package/dist/cli/docker.mjs +0 -114
- package/dist/cli/new.mjs +0 -13
- package/dist/cli/sysinfo.mjs +0 -63
- package/dist/cli/up.mjs +0 -139
- package/dist/cli/utils/analytics.mjs +0 -39
- package/dist/cli/utils/builder.mjs +0 -7
- package/dist/cli/utils/ipc/server.mjs +0 -93
- package/dist/cli/utils/ipc/utils/get-pipe-path.mjs +0 -29
- package/dist/cli/utils/ipc/utils/temporary-directory.mjs +0 -40
- package/dist/cli/utils/project.mjs +0 -18
- package/dist/cli/utils/stream.mjs +0 -90
- package/dist/cli/utils/version.mjs +0 -13
- package/dist/docker/compose.mjs +0 -185
- package/dist/docker/docker.mjs +0 -390
- package/dist/docker/shell.mjs +0 -62
- package/dist/utils/config.mjs +0 -104
- package/dist/utils/logging.mjs +0 -96
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/langgraph-cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": "^18.19.0 || >=20.16.0"
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
],
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "git@github.com
|
|
19
|
+
"url": "git+ssh://git@github.com/langchain-ai/langgraphjs.git",
|
|
20
|
+
"directory": "libs/langgraph-cli"
|
|
20
21
|
},
|
|
21
22
|
"scripts": {
|
|
22
23
|
"clean": "rm -rf dist/ .turbo/",
|
|
@@ -33,10 +34,10 @@
|
|
|
33
34
|
"dependencies": {
|
|
34
35
|
"@babel/code-frame": "^7.26.2",
|
|
35
36
|
"@commander-js/extra-typings": "^13.0.0",
|
|
36
|
-
"@langchain/langgraph-api": "
|
|
37
|
+
"@langchain/langgraph-api": "workspace:*",
|
|
37
38
|
"chokidar": "^4.0.3",
|
|
38
39
|
"commander": "^13.0.0",
|
|
39
|
-
"create-langgraph": "
|
|
40
|
+
"create-langgraph": "workspace:*",
|
|
40
41
|
"dedent": "^1.5.3",
|
|
41
42
|
"dotenv": "^16.4.7",
|
|
42
43
|
"execa": "^9.5.2",
|
|
@@ -60,4 +61,4 @@
|
|
|
60
61
|
"typescript": "^4.9.5 || ^5.4.5",
|
|
61
62
|
"vitest": "^3.2.4"
|
|
62
63
|
}
|
|
63
|
-
}
|
|
64
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
# @langchain/langgraph-cli
|
|
2
|
-
|
|
3
|
-
## 1.1.1
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- Updated dependencies [35e8fc7]
|
|
8
|
-
- @langchain/langgraph-api@1.1.1
|
|
9
|
-
|
|
10
|
-
## 1.1.0
|
|
11
|
-
|
|
12
|
-
### Minor Changes
|
|
13
|
-
|
|
14
|
-
- c71b92b: Updated the uv version to latest 0.9.11. Fixed error fixed EXDEV: cross-device link when using Python adapter
|
|
15
|
-
|
|
16
|
-
### Patch Changes
|
|
17
|
-
|
|
18
|
-
- @langchain/langgraph-api@1.1.0
|
|
19
|
-
|
|
20
|
-
## 1.0.4
|
|
21
|
-
|
|
22
|
-
### Patch Changes
|
|
23
|
-
|
|
24
|
-
- Updated dependencies [b9be526]
|
|
25
|
-
- @langchain/langgraph-api@1.0.4
|
|
26
|
-
|
|
27
|
-
## 1.0.3
|
|
28
|
-
|
|
29
|
-
### Patch Changes
|
|
30
|
-
|
|
31
|
-
- 6cd8ecb: Remove Zod 3.x dependency constraint to allow Zod 4.x and avoid installing duplicate Zod packages
|
|
32
|
-
- Updated dependencies [6cd8ecb]
|
|
33
|
-
- @langchain/langgraph-api@1.0.3
|
|
34
|
-
|
|
35
|
-
## 1.0.2
|
|
36
|
-
|
|
37
|
-
### Patch Changes
|
|
38
|
-
|
|
39
|
-
- Updated dependencies [ebe5ae7]
|
|
40
|
-
- @langchain/langgraph-api@1.0.2
|
|
41
|
-
|
|
42
|
-
## 1.0.1
|
|
43
|
-
|
|
44
|
-
### Patch Changes
|
|
45
|
-
|
|
46
|
-
- Updated dependencies [610e1e1]
|
|
47
|
-
- @langchain/langgraph-api@1.0.1
|
|
48
|
-
|
|
49
|
-
## 1.0.0
|
|
50
|
-
|
|
51
|
-
### Major Changes
|
|
52
|
-
|
|
53
|
-
- 1e1ecbb: This release updates the package for compatibility with LangGraph v1.0. See the [v1.0 release notes](https://docs.langchain.com/oss/javascript/releases/langgraph-v1) for details on what's new.
|
|
54
|
-
|
|
55
|
-
### Patch Changes
|
|
56
|
-
|
|
57
|
-
- Updated dependencies [1e1ecbb]
|
|
58
|
-
- create-langgraph@1.0.0
|
|
59
|
-
- @langchain/langgraph-api@1.0.0
|
|
60
|
-
|
|
61
|
-
## 0.0.71
|
|
62
|
-
|
|
63
|
-
### Patch Changes
|
|
64
|
-
|
|
65
|
-
- Updated dependencies [f5865ac]
|
|
66
|
-
- @langchain/langgraph-api@0.0.71
|
|
67
|
-
|
|
68
|
-
## 0.0.70
|
|
69
|
-
|
|
70
|
-
### Patch Changes
|
|
71
|
-
|
|
72
|
-
- Updated dependencies [636e142]
|
|
73
|
-
- @langchain/langgraph-api@0.0.70
|
|
74
|
-
|
|
75
|
-
## 0.0.69
|
|
76
|
-
|
|
77
|
-
### Patch Changes
|
|
78
|
-
|
|
79
|
-
- Updated dependencies [f2aa533]
|
|
80
|
-
- @langchain/langgraph-api@0.0.69
|
|
81
|
-
|
|
82
|
-
## 0.0.68
|
|
83
|
-
|
|
84
|
-
### Patch Changes
|
|
85
|
-
|
|
86
|
-
- 7770c6a: Add `new` command to `@langchain/langgraph-cli` CLI
|
|
87
|
-
- Updated dependencies [7770c6a]
|
|
88
|
-
- create-langgraph@0.0.4
|
|
89
|
-
- @langchain/langgraph-api@0.0.68
|
|
90
|
-
|
|
91
|
-
## 0.0.67
|
|
92
|
-
|
|
93
|
-
### Patch Changes
|
|
94
|
-
|
|
95
|
-
- Updated dependencies [e23fa7f]
|
|
96
|
-
- @langchain/langgraph-api@0.0.67
|
|
97
|
-
|
|
98
|
-
## 0.0.66
|
|
99
|
-
|
|
100
|
-
### Patch Changes
|
|
101
|
-
|
|
102
|
-
- Updated dependencies [5176f1c]
|
|
103
|
-
- Updated dependencies [68a1aa8]
|
|
104
|
-
- @langchain/langgraph-api@0.0.66
|
|
105
|
-
|
|
106
|
-
## 0.0.65
|
|
107
|
-
|
|
108
|
-
### Patch Changes
|
|
109
|
-
|
|
110
|
-
- Updated dependencies [0aefafe]
|
|
111
|
-
- @langchain/langgraph-api@0.0.65
|
|
112
|
-
|
|
113
|
-
## 0.0.64
|
|
114
|
-
|
|
115
|
-
### Patch Changes
|
|
116
|
-
|
|
117
|
-
- Updated dependencies [30bcfcd]
|
|
118
|
-
- Updated dependencies [572de43]
|
|
119
|
-
- @langchain/langgraph-api@0.0.64
|
|
120
|
-
|
|
121
|
-
## 0.0.63
|
|
122
|
-
|
|
123
|
-
### Patch Changes
|
|
124
|
-
|
|
125
|
-
- Updated dependencies [c9d4dfd]
|
|
126
|
-
- @langchain/langgraph-api@0.0.63
|
|
127
|
-
|
|
128
|
-
## 0.0.62
|
|
129
|
-
|
|
130
|
-
### Patch Changes
|
|
131
|
-
|
|
132
|
-
- Updated dependencies [c868796]
|
|
133
|
-
- @langchain/langgraph-api@0.0.62
|
|
134
|
-
|
|
135
|
-
## 0.0.61
|
|
136
|
-
|
|
137
|
-
### Patch Changes
|
|
138
|
-
|
|
139
|
-
- Updated dependencies [a334897]
|
|
140
|
-
- Updated dependencies [9357bb7]
|
|
141
|
-
- Updated dependencies [9f13d74]
|
|
142
|
-
- @langchain/langgraph-api@0.0.61
|
|
143
|
-
|
|
144
|
-
## 0.0.60
|
|
145
|
-
|
|
146
|
-
### Patch Changes
|
|
147
|
-
|
|
148
|
-
- Updated dependencies [9c57526]
|
|
149
|
-
- @langchain/langgraph-api@0.0.60
|
|
150
|
-
|
|
151
|
-
## 0.0.59
|
|
152
|
-
|
|
153
|
-
### Patch Changes
|
|
154
|
-
|
|
155
|
-
- d28a9d7: fix(cli): sysinfo command failing to obtain dep versions for Node.js 20.x
|
|
156
|
-
- Updated dependencies [3412f9f]
|
|
157
|
-
- @langchain/langgraph-api@0.0.59
|
|
158
|
-
|
|
159
|
-
## 0.0.58
|
|
160
|
-
|
|
161
|
-
### Patch Changes
|
|
162
|
-
|
|
163
|
-
- Updated dependencies [f65f619]
|
|
164
|
-
- Updated dependencies [c857357]
|
|
165
|
-
- @langchain/langgraph-api@0.0.58
|
|
166
|
-
|
|
167
|
-
## 0.0.57
|
|
168
|
-
|
|
169
|
-
### Patch Changes
|
|
170
|
-
|
|
171
|
-
- 31cc9f7: support description property for `langgraph.json`
|
|
172
|
-
- 679a1be: Fix sysinfo command for PNPM
|
|
173
|
-
- 2f179e5: feat(cli): accept BROWSER=none to prevent spawning a browser
|
|
174
|
-
- Updated dependencies [31cc9f7]
|
|
175
|
-
- @langchain/langgraph-api@0.0.57
|
|
176
|
-
|
|
177
|
-
## 0.0.56
|
|
178
|
-
|
|
179
|
-
### Patch Changes
|
|
180
|
-
|
|
181
|
-
- Updated dependencies [3c390c9]
|
|
182
|
-
- @langchain/langgraph-api@0.0.56
|
|
183
|
-
|
|
184
|
-
## 0.0.55
|
|
185
|
-
|
|
186
|
-
### Patch Changes
|
|
187
|
-
|
|
188
|
-
- Updated dependencies [ef84039]
|
|
189
|
-
- Updated dependencies [7edf347]
|
|
190
|
-
- Updated dependencies [77b21d5]
|
|
191
|
-
- @langchain/langgraph-api@0.0.55
|
|
192
|
-
|
|
193
|
-
## 0.0.54
|
|
194
|
-
|
|
195
|
-
### Patch Changes
|
|
196
|
-
|
|
197
|
-
- Updated dependencies [1777878]
|
|
198
|
-
- @langchain/langgraph-api@0.0.54
|
|
199
|
-
|
|
200
|
-
## 0.0.53
|
|
201
|
-
|
|
202
|
-
### Patch Changes
|
|
203
|
-
|
|
204
|
-
- Updated dependencies [f1bcec7]
|
|
205
|
-
- @langchain/langgraph-api@0.0.53
|
|
206
|
-
|
|
207
|
-
## 0.0.52
|
|
208
|
-
|
|
209
|
-
### Patch Changes
|
|
210
|
-
|
|
211
|
-
- Updated dependencies [030698f]
|
|
212
|
-
- @langchain/langgraph-api@0.0.52
|
|
213
|
-
|
|
214
|
-
## 0.0.51
|
|
215
|
-
|
|
216
|
-
### Patch Changes
|
|
217
|
-
|
|
218
|
-
- 11319f7: fix(cli): allow node_version: 22 when pulling and building image
|
|
219
|
-
- @langchain/langgraph-api@0.0.51
|
|
220
|
-
|
|
221
|
-
## 0.0.50
|
|
222
|
-
|
|
223
|
-
### Patch Changes
|
|
224
|
-
|
|
225
|
-
- 337b419: fix(cli): enable correct passthrough of docker build args
|
|
226
|
-
- @langchain/langgraph-api@0.0.50
|
|
227
|
-
|
|
228
|
-
## 0.0.49
|
|
229
|
-
|
|
230
|
-
### Patch Changes
|
|
231
|
-
|
|
232
|
-
- 78a15a1: feat(cli): add sysinfo command to obtain actual version
|
|
233
|
-
- Updated dependencies [ee1defa]
|
|
234
|
-
- @langchain/langgraph-api@0.0.49
|
|
235
|
-
|
|
236
|
-
## 0.0.48
|
|
237
|
-
|
|
238
|
-
### Patch Changes
|
|
239
|
-
|
|
240
|
-
- ac7b067: fix(sdk): use `kind` when checking for Studio user
|
|
241
|
-
- Updated dependencies [ac7b067]
|
|
242
|
-
- @langchain/langgraph-api@0.0.48
|
|
243
|
-
|
|
244
|
-
## 0.0.47
|
|
245
|
-
|
|
246
|
-
### Patch Changes
|
|
247
|
-
|
|
248
|
-
- 39cc88f: Fix apply namespace to messages-tuple stream mode
|
|
249
|
-
- c1ddda1: Embed methods for obtaining state should use `getGraph(...)`
|
|
250
|
-
- Updated dependencies [39cc88f]
|
|
251
|
-
- Updated dependencies [c1ddda1]
|
|
252
|
-
- @langchain/langgraph-api@0.0.47
|
|
253
|
-
|
|
254
|
-
## 0.0.46
|
|
255
|
-
|
|
256
|
-
### Patch Changes
|
|
257
|
-
|
|
258
|
-
- d172de3: Fix apply namespace to messages-tuple stream mode
|
|
259
|
-
- Updated dependencies [d172de3]
|
|
260
|
-
- @langchain/langgraph-api@0.0.46
|
|
261
|
-
|
|
262
|
-
## 0.0.45
|
|
263
|
-
|
|
264
|
-
### Patch Changes
|
|
265
|
-
|
|
266
|
-
- 603daa6: Embed should properly handle `payload.checkpoint` and `payload.checkpoint_id`
|
|
267
|
-
- Updated dependencies [603daa6]
|
|
268
|
-
- @langchain/langgraph-api@0.0.45
|
|
269
|
-
|
|
270
|
-
## 0.0.44
|
|
271
|
-
|
|
272
|
-
### Patch Changes
|
|
273
|
-
|
|
274
|
-
- 2f26f2f: Expose get/delete thread endpoint to embed server
|
|
275
|
-
- Updated dependencies [2f26f2f]
|
|
276
|
-
- @langchain/langgraph-api@0.0.44
|
|
277
|
-
|
|
278
|
-
## 0.0.43
|
|
279
|
-
|
|
280
|
-
### Patch Changes
|
|
281
|
-
|
|
282
|
-
- ce0a39a: Fix invalid package.json dependencies
|
|
283
|
-
- Updated dependencies [ce0a39a]
|
|
284
|
-
- @langchain/langgraph-api@0.0.43
|
|
285
|
-
|
|
286
|
-
## 0.0.42
|
|
287
|
-
|
|
288
|
-
### Patch Changes
|
|
289
|
-
|
|
290
|
-
- 972b66a: Support gen UI components namespaced with a hyphen
|
|
291
|
-
- Updated dependencies [972b66a]
|
|
292
|
-
- @langchain/langgraph-api@0.0.42
|
package/dist/cli/build.mjs
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { getDockerCapabilities } from "../docker/compose.mjs";
|
|
2
|
-
import { assembleLocalDeps, configToDocker, getBaseImage, } from "../docker/docker.mjs";
|
|
3
|
-
import { getExecaOptions } from "../docker/shell.mjs";
|
|
4
|
-
import { getConfig } from "../utils/config.mjs";
|
|
5
|
-
import { builder } from "./utils/builder.mjs";
|
|
6
|
-
import { getProjectPath } from "./utils/project.mjs";
|
|
7
|
-
import { $ } from "execa";
|
|
8
|
-
import * as path from "node:path";
|
|
9
|
-
import * as fs from "node:fs/promises";
|
|
10
|
-
import { logger } from "../utils/logging.mjs";
|
|
11
|
-
import { withAnalytics } from "./utils/analytics.mjs";
|
|
12
|
-
import { gracefulExit } from "exit-hook";
|
|
13
|
-
const stream = (proc) => {
|
|
14
|
-
logger.info(`Running "${proc.spawnargs.join(" ")}"`);
|
|
15
|
-
return proc;
|
|
16
|
-
};
|
|
17
|
-
builder
|
|
18
|
-
.command("build")
|
|
19
|
-
.description("Build LangGraph API server Docker image.")
|
|
20
|
-
.requiredOption("-t, --tag <tag>", "Tag for the Docker image.")
|
|
21
|
-
.option("-c, --config <path>", "Path to configuration file", process.cwd())
|
|
22
|
-
.option("--no-pull", "Running the server with locally-built images. By default LangGraph will pull the latest images from the registry")
|
|
23
|
-
.argument("[args...]")
|
|
24
|
-
.passThroughOptions()
|
|
25
|
-
.allowUnknownOption()
|
|
26
|
-
.exitOverride((error) => gracefulExit(error.exitCode))
|
|
27
|
-
.hook("preAction", withAnalytics((command) => ({
|
|
28
|
-
config: command.opts().config !== process.cwd(),
|
|
29
|
-
pull: command.opts().pull,
|
|
30
|
-
})))
|
|
31
|
-
.action(async (pass, params) => {
|
|
32
|
-
const configPath = await getProjectPath(params.config);
|
|
33
|
-
await getDockerCapabilities();
|
|
34
|
-
const projectDir = path.dirname(configPath);
|
|
35
|
-
const config = getConfig(await fs.readFile(configPath, "utf-8"));
|
|
36
|
-
const opts = await getExecaOptions({
|
|
37
|
-
cwd: projectDir,
|
|
38
|
-
stderr: "inherit",
|
|
39
|
-
stdout: "inherit",
|
|
40
|
-
});
|
|
41
|
-
const localDeps = await assembleLocalDeps(configPath, config);
|
|
42
|
-
const input = await configToDocker(configPath, config, localDeps, {
|
|
43
|
-
watch: false,
|
|
44
|
-
dockerCommand: "build",
|
|
45
|
-
});
|
|
46
|
-
let exec = $({ ...opts, input });
|
|
47
|
-
if (params.pull) {
|
|
48
|
-
await stream(exec `docker pull ${getBaseImage(config)}`);
|
|
49
|
-
}
|
|
50
|
-
exec = $({ ...opts, input });
|
|
51
|
-
await stream(exec `docker build -f - -t ${params.tag} ${projectDir} ${pass}`);
|
|
52
|
-
});
|
package/dist/cli/cli.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { builder } from "./utils/builder.mjs";
|
|
3
|
-
import { flushAnalytics } from "./utils/analytics.mjs";
|
|
4
|
-
import { asyncExitHook, gracefulExit } from "exit-hook";
|
|
5
|
-
import "./dev.mjs";
|
|
6
|
-
import "./docker.mjs";
|
|
7
|
-
import "./build.mjs";
|
|
8
|
-
import "./up.mjs";
|
|
9
|
-
import "./new.mjs";
|
|
10
|
-
import "./sysinfo.mjs";
|
|
11
|
-
builder.exitOverride((error) => gracefulExit(error.exitCode));
|
|
12
|
-
asyncExitHook(() => flushAnalytics(), { wait: 2000 });
|
|
13
|
-
builder.parse();
|
package/dist/cli/cloudflare.mjs
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import * as os from "node:os";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import * as fs from "node:fs/promises";
|
|
4
|
-
import { Readable, Transform, Writable } from "node:stream";
|
|
5
|
-
import { ChildProcess, spawn } from "node:child_process";
|
|
6
|
-
import { extract as tarExtract } from "tar";
|
|
7
|
-
import * as nodeStream from "node:stream/web";
|
|
8
|
-
import { fileURLToPath } from "node:url";
|
|
9
|
-
import { logger } from "../utils/logging.mjs";
|
|
10
|
-
import { BytesLineDecoder } from "./utils/stream.mjs";
|
|
11
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
-
const CLOUDFLARED_VERSION = "2025.2.1";
|
|
13
|
-
const CLOUDFLARED_CACHE_DIR = path.join(__dirname, ".cloudflare", CLOUDFLARED_VERSION);
|
|
14
|
-
const writeFile = async (path, stream) => {
|
|
15
|
-
if (stream == null)
|
|
16
|
-
throw new Error("Stream is null");
|
|
17
|
-
return await fs.writeFile(path, Readable.fromWeb(stream));
|
|
18
|
-
};
|
|
19
|
-
class CloudflareLoggerStream extends WritableStream {
|
|
20
|
-
constructor() {
|
|
21
|
-
const decoder = new TextDecoder();
|
|
22
|
-
super({
|
|
23
|
-
write(chunk) {
|
|
24
|
-
const text = decoder.decode(chunk);
|
|
25
|
-
const [_timestamp, level, ...rest] = text.split(" ");
|
|
26
|
-
const message = rest.join(" ");
|
|
27
|
-
if (level === "INF") {
|
|
28
|
-
logger.debug(message);
|
|
29
|
-
}
|
|
30
|
-
else if (level === "ERR") {
|
|
31
|
-
logger.error(message);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
logger.info(message);
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
fromWeb() {
|
|
40
|
-
return Writable.fromWeb(this);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
class CloudflareUrlStream extends TransformStream {
|
|
44
|
-
constructor() {
|
|
45
|
-
const decoder = new TextDecoder();
|
|
46
|
-
super({
|
|
47
|
-
transform(chunk, controller) {
|
|
48
|
-
const str = decoder.decode(chunk);
|
|
49
|
-
const urlMatch = str.match(/https:\/\/[a-z0-9-]+\.trycloudflare\.com/)?.[0];
|
|
50
|
-
if (urlMatch)
|
|
51
|
-
controller.enqueue(urlMatch);
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
fromWeb() {
|
|
56
|
-
// @ts-expect-error
|
|
57
|
-
return Transform.fromWeb(this, { objectMode: true });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
export async function startCloudflareTunnel(port) {
|
|
61
|
-
const targetBinaryPath = await ensureCloudflared();
|
|
62
|
-
logger.info("Starting tunnel");
|
|
63
|
-
const child = spawn(targetBinaryPath, ["tunnel", "--url", `http://localhost:${port}`], { stdio: ["inherit", "pipe", "pipe"] });
|
|
64
|
-
child.stdout
|
|
65
|
-
.pipe(new BytesLineDecoder().fromWeb())
|
|
66
|
-
.pipe(new CloudflareLoggerStream().fromWeb());
|
|
67
|
-
child.stderr
|
|
68
|
-
.pipe(new BytesLineDecoder().fromWeb())
|
|
69
|
-
.pipe(new CloudflareLoggerStream().fromWeb());
|
|
70
|
-
const tunnelUrl = new Promise((resolve) => {
|
|
71
|
-
child.stderr
|
|
72
|
-
.pipe(new CloudflareUrlStream().fromWeb())
|
|
73
|
-
.once("data", (data) => {
|
|
74
|
-
logger.info(`Tunnel URL: "${data}"`);
|
|
75
|
-
resolve(data);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
return { child, tunnelUrl };
|
|
79
|
-
}
|
|
80
|
-
function getFiles() {
|
|
81
|
-
const platform = getPlatform();
|
|
82
|
-
const arch = getArchitecture();
|
|
83
|
-
if (platform === "windows") {
|
|
84
|
-
if (arch !== "386" && arch !== "amd64") {
|
|
85
|
-
throw new Error(`Unsupported architecture: ${arch}`);
|
|
86
|
-
}
|
|
87
|
-
return { binary: `cloudflared-${platform}-${arch}.exe` };
|
|
88
|
-
}
|
|
89
|
-
if (platform === "darwin") {
|
|
90
|
-
if (arch !== "arm64" && arch !== "amd64") {
|
|
91
|
-
throw new Error(`Unsupported architecture: ${arch}`);
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
archive: `cloudflared-${platform}-${arch}.tgz`,
|
|
95
|
-
binary: "cloudflared",
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
if (platform === "linux") {
|
|
99
|
-
if (arch !== "arm64" && arch !== "amd64" && arch !== "386") {
|
|
100
|
-
throw new Error(`Unsupported architecture: ${arch}`);
|
|
101
|
-
}
|
|
102
|
-
return { binary: `cloudflared-${platform}-${arch}` };
|
|
103
|
-
}
|
|
104
|
-
throw new Error(`Unsupported platform: ${platform}`);
|
|
105
|
-
}
|
|
106
|
-
async function downloadCloudflared() {
|
|
107
|
-
await fs.mkdir(CLOUDFLARED_CACHE_DIR, { recursive: true });
|
|
108
|
-
logger.info("Requesting download of `cloudflared`");
|
|
109
|
-
const { binary, archive } = getFiles();
|
|
110
|
-
const downloadFile = archive ?? binary;
|
|
111
|
-
const tempDirPath = await fs.mkdtemp(path.join(os.tmpdir(), "cloudflared-"));
|
|
112
|
-
const tempFilePath = path.join(tempDirPath, downloadFile);
|
|
113
|
-
const url = `https://github.com/cloudflare/cloudflared/releases/download/${CLOUDFLARED_VERSION}/${downloadFile}`;
|
|
114
|
-
logger.debug("Downloading `${archive}`", { url, target: tempDirPath });
|
|
115
|
-
const response = await fetch(url);
|
|
116
|
-
if (!response.ok || !response.body) {
|
|
117
|
-
throw new Error(`Failed to download cloudflared: ${response.statusText}`);
|
|
118
|
-
}
|
|
119
|
-
await writeFile(tempFilePath, response.body);
|
|
120
|
-
if (archive != null) {
|
|
121
|
-
if (path.extname(archive) !== ".tgz") {
|
|
122
|
-
throw new Error(`Invalid archive type: "${path.extname(archive)}"`);
|
|
123
|
-
}
|
|
124
|
-
logger.debug("Extracting `cloudflared`");
|
|
125
|
-
await tarExtract({ file: tempFilePath, cwd: tempDirPath });
|
|
126
|
-
}
|
|
127
|
-
const sourceBinaryPath = path.resolve(tempDirPath, binary);
|
|
128
|
-
const targetBinaryPath = path.resolve(CLOUDFLARED_CACHE_DIR, binary);
|
|
129
|
-
logger.debug("Moving `cloudflared` to target directory", {
|
|
130
|
-
targetBinaryPath,
|
|
131
|
-
});
|
|
132
|
-
await fs.rename(sourceBinaryPath, targetBinaryPath);
|
|
133
|
-
await fs.chmod(targetBinaryPath, 0o755);
|
|
134
|
-
}
|
|
135
|
-
async function ensureCloudflared() {
|
|
136
|
-
const { binary } = getFiles();
|
|
137
|
-
const targetBinaryPath = path.resolve(CLOUDFLARED_CACHE_DIR, binary);
|
|
138
|
-
try {
|
|
139
|
-
await fs.access(targetBinaryPath);
|
|
140
|
-
}
|
|
141
|
-
catch {
|
|
142
|
-
await downloadCloudflared();
|
|
143
|
-
}
|
|
144
|
-
return targetBinaryPath;
|
|
145
|
-
}
|
|
146
|
-
function getArchitecture() {
|
|
147
|
-
const arch = os.arch();
|
|
148
|
-
switch (arch) {
|
|
149
|
-
case "x64":
|
|
150
|
-
return "amd64";
|
|
151
|
-
case "arm64":
|
|
152
|
-
return "arm64";
|
|
153
|
-
case "ia32":
|
|
154
|
-
case "x86":
|
|
155
|
-
return "386";
|
|
156
|
-
default:
|
|
157
|
-
throw new Error(`Unsupported architecture: ${arch}`);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
function getPlatform() {
|
|
161
|
-
const platform = os.platform();
|
|
162
|
-
switch (platform) {
|
|
163
|
-
case "darwin":
|
|
164
|
-
return "darwin";
|
|
165
|
-
case "linux":
|
|
166
|
-
return "linux";
|
|
167
|
-
case "win32":
|
|
168
|
-
return "windows";
|
|
169
|
-
default:
|
|
170
|
-
throw new Error(`Unsupported platform: ${platform}`);
|
|
171
|
-
}
|
|
172
|
-
}
|