@cloudless-ai/node-agent 0.0.2 → 0.0.13

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/README.md CHANGED
@@ -11,7 +11,7 @@ npm install -g @cloudless-ai/node-agent
11
11
  During install, the script:
12
12
 
13
13
  1. Detects your OS/CPU architecture.
14
- 2. Installs the matching `cloudless-agent` binary.
14
+ 2. Installs the matching precompiled binary bundled in this package.
15
15
  3. On macOS, also installs `CloudlessMenuBar`.
16
16
  4. Prompts for your router API key and writes `~/.cloudless/agent.yaml`.
17
17
 
@@ -35,4 +35,4 @@ CLOUDLESS_NODE_API_KEY=your_key CLOUDLESS_ROUTER_URL=http://router-host:8080 npm
35
35
 
36
36
  - By default binaries are installed to `~/.cloudless/bin`.
37
37
  - Configuration is written to `~/.cloudless/agent.yaml`.
38
- - Set `CLOUDLESS_RELEASE_BASE_URL` to override release download source.
38
+ - Installation has no GitHub release dependency; binaries are bundled in the npm tarball.
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@cloudless-ai/node-agent",
3
- "version": "0.0.2",
3
+ "version": "0.0.13",
4
4
  "description": "Cloudless AI node agent installer and launcher",
5
5
  "license": "MIT",
6
+ "homepage": "https://cloudless-ai.app",
6
7
  "repository": {
7
8
  "type": "git",
8
- "url": "https://github.com/cloudless-ai/cloudless-ai.git",
9
- "directory": "apps/node-agent/npm"
9
+ "url": "https://github.com/cloudless-ai/node-agent"
10
10
  },
11
11
  "bin": {
12
- "cloudless-node": "./bin/cloudless-node.js"
12
+ "cloudless-node": "bin/cloudless-node.js"
13
13
  },
14
14
  "scripts": {
15
15
  "postinstall": "node ./scripts/postinstall.js"
@@ -19,6 +19,7 @@
19
19
  },
20
20
  "files": [
21
21
  "bin",
22
+ "platform",
22
23
  "scripts",
23
24
  "README.md"
24
25
  ],
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/scripts/common.js CHANGED
@@ -1,8 +1,6 @@
1
1
  const fs = require("node:fs");
2
2
  const os = require("node:os");
3
3
  const path = require("node:path");
4
- const https = require("node:https");
5
- const { execFileSync } = require("node:child_process");
6
4
  const readline = require("node:readline");
7
5
 
8
6
  const HOME = os.homedir();
@@ -30,82 +28,11 @@ function detectTarget() {
30
28
  return { goos, goarch };
31
29
  }
32
30
 
33
- function normalizeVersion(rawVersion) {
34
- if (!rawVersion) {
35
- return "dev";
36
- }
37
- return rawVersion.startsWith("v") ? rawVersion.slice(1) : rawVersion;
38
- }
39
-
40
- function releaseBaseURL(version) {
41
- const override = process.env.CLOUDLESS_RELEASE_BASE_URL;
42
- if (override && override.trim()) {
43
- return override.trim().replace(/\/+$/, "");
44
- }
45
- return `https://github.com/cloudless-ai/cloudless-ai/releases/download/v${version}`;
46
- }
47
-
48
31
  function ensureDirs() {
49
32
  fs.mkdirSync(BIN_DIR, { recursive: true });
50
33
  fs.mkdirSync(path.dirname(CONFIG_PATH), { recursive: true });
51
34
  }
52
35
 
53
- function fetchToFile(url, destPath, redirects = 5) {
54
- return new Promise((resolve, reject) => {
55
- const req = https.get(url, (res) => {
56
- const location = res.headers.location;
57
- if (location && res.statusCode && res.statusCode >= 300 && res.statusCode < 400) {
58
- res.resume();
59
- if (redirects <= 0) {
60
- reject(new Error(`Too many redirects for ${url}`));
61
- return;
62
- }
63
- fetchToFile(location, destPath, redirects - 1).then(resolve).catch(reject);
64
- return;
65
- }
66
- if (res.statusCode !== 200) {
67
- res.resume();
68
- reject(new Error(`Download failed (${res.statusCode}) for ${url}`));
69
- return;
70
- }
71
- const out = fs.createWriteStream(destPath);
72
- res.pipe(out);
73
- out.on("finish", () => {
74
- out.close();
75
- resolve();
76
- });
77
- out.on("error", reject);
78
- });
79
- req.on("error", reject);
80
- });
81
- }
82
-
83
- function extractArchive(archivePath, destination) {
84
- fs.mkdirSync(destination, { recursive: true });
85
- if (archivePath.endsWith(".zip")) {
86
- execFileSync("unzip", ["-o", archivePath, "-d", destination], { stdio: "ignore" });
87
- return;
88
- }
89
- execFileSync("tar", ["-xzf", archivePath, "-C", destination], { stdio: "ignore" });
90
- }
91
-
92
- function findFileRecursive(rootDir, fileName) {
93
- const entries = fs.readdirSync(rootDir, { withFileTypes: true });
94
- for (const entry of entries) {
95
- const fullPath = path.join(rootDir, entry.name);
96
- if (entry.isFile() && entry.name === fileName) {
97
- return fullPath;
98
- }
99
- if (entry.isDirectory()) {
100
- const found = findFileRecursive(fullPath, fileName);
101
- if (found) {
102
- return found;
103
- }
104
- }
105
- }
106
- return null;
107
- }
108
-
109
36
  function installBinary(sourcePath, binaryName) {
110
37
  const targetPath = path.join(BIN_DIR, binaryName);
111
38
  fs.copyFileSync(sourcePath, targetPath);
@@ -272,14 +199,9 @@ module.exports = {
272
199
  defaultAgentConfig,
273
200
  detectTarget,
274
201
  ensureDirs,
275
- extractArchive,
276
- fetchToFile,
277
- findFileRecursive,
278
202
  installBinary,
279
- normalizeVersion,
280
203
  promptLine,
281
204
  promptSecret,
282
- releaseBaseURL,
283
205
  updateRouterConfig,
284
206
  writeOrUpdateConfig,
285
207
  };
@@ -1,128 +1,47 @@
1
1
  #!/usr/bin/env node
2
2
  const fs = require("node:fs");
3
3
  const path = require("node:path");
4
- const os = require("node:os");
5
- const { execFileSync } = require("node:child_process");
6
4
 
7
5
  const {
8
6
  AGENT_BINARY_NAME,
9
7
  MENUBAR_BINARY_NAME,
10
- BIN_DIR,
11
8
  CONFIG_PATH,
12
9
  detectTarget,
13
10
  ensureDirs,
14
- extractArchive,
15
- fetchToFile,
16
- findFileRecursive,
17
11
  installBinary,
18
- normalizeVersion,
19
12
  promptSecret,
20
- releaseBaseURL,
21
13
  writeOrUpdateConfig,
22
14
  } = require("./common");
23
15
 
24
- const pkg = require("../package.json");
25
- let downloadedSourceRoot = null;
26
- let downloadedSourceTempDir = null;
27
-
28
- async function ensureSourceTree(version) {
29
- if (downloadedSourceRoot) {
30
- return downloadedSourceRoot;
31
- }
32
- const localRoot = path.resolve(__dirname, "..", "..");
33
- if (fs.existsSync(path.join(localRoot, "go.mod"))) {
34
- downloadedSourceRoot = path.resolve(localRoot, "..", "..");
35
- return downloadedSourceRoot;
36
- }
37
- if (version === "dev") {
38
- return null;
39
- }
40
-
41
- const tarballURL = `https://codeload.github.com/cloudless-ai/cloudless-ai/tar.gz/refs/tags/v${version}`;
42
- const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "cloudless-source-"));
43
- downloadedSourceTempDir = tempDir;
44
- const archivePath = path.join(tempDir, `cloudless-ai-v${version}.tar.gz`);
45
- const extractDir = path.join(tempDir, "extract");
46
-
47
- await fetchToFile(tarballURL, archivePath);
48
- extractArchive(archivePath, extractDir);
49
- const entries = fs.readdirSync(extractDir, { withFileTypes: true }).filter((entry) => entry.isDirectory());
50
- if (entries.length !== 1) {
51
- throw new Error("Unable to locate extracted source directory");
16
+ function resolveBundledPlatformDir(target) {
17
+ const key = `${target.goos}/${target.goarch}`;
18
+ const dirName = `${target.goos}-${target.goarch}`;
19
+ const platformDir = path.resolve(__dirname, "..", "platform", dirName);
20
+ if (!fs.existsSync(platformDir)) {
21
+ throw new Error(`Unsupported platform/arch: ${key}`);
52
22
  }
53
- downloadedSourceRoot = path.join(extractDir, entries[0].name);
54
- return downloadedSourceRoot;
23
+ return platformDir;
55
24
  }
56
25
 
57
- async function installAgent(version, target) {
58
- const ext = target.goos === "windows" ? ".zip" : ".tar.gz";
59
- const archiveName = `cloudless-agent_${version}_${target.goos}_${target.goarch}${ext}`;
60
- const url = `${releaseBaseURL(version)}/${archiveName}`;
61
- const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "cloudless-agent-"));
62
- const archivePath = path.join(tempDir, archiveName);
63
- const extractDir = path.join(tempDir, "extract");
64
-
65
- try {
66
- await fetchToFile(url, archivePath);
67
- extractArchive(archivePath, extractDir);
68
- const binary = findFileRecursive(extractDir, AGENT_BINARY_NAME);
69
- if (!binary) {
70
- throw new Error(`Release archive does not contain ${AGENT_BINARY_NAME}`);
71
- }
72
- return installBinary(binary, AGENT_BINARY_NAME);
73
- } catch (error) {
74
- const sourceTree = await ensureSourceTree(version);
75
- const sourceRoot = sourceTree ? path.join(sourceTree, "apps", "node-agent") : null;
76
- if (!sourceRoot || !fs.existsSync(path.join(sourceRoot, "go.mod"))) {
77
- throw error;
78
- }
79
- execFileSync("go", ["build", "-o", path.join(BIN_DIR, AGENT_BINARY_NAME), "./cmd/agent"], {
80
- cwd: sourceRoot,
81
- stdio: "inherit",
82
- });
83
- fs.chmodSync(path.join(BIN_DIR, AGENT_BINARY_NAME), 0o755);
84
- return path.join(BIN_DIR, AGENT_BINARY_NAME);
85
- } finally {
86
- fs.rmSync(tempDir, { recursive: true, force: true });
87
- }
88
- }
26
+ function installFromPlatformPackage(target) {
27
+ const platformDir = resolveBundledPlatformDir(target);
28
+ const agentSource = path.join(platformDir, AGENT_BINARY_NAME);
89
29
 
90
- async function installMenubar(version) {
91
- if (process.platform !== "darwin") {
92
- return null;
30
+ if (!fs.existsSync(agentSource)) {
31
+ throw new Error(`Bundled binaries are missing ${AGENT_BINARY_NAME} for ${target.goos}/${target.goarch}`);
93
32
  }
94
- const archiveName = `CloudlessMenuBar_${version}_darwin_universal.tar.gz`;
95
- const url = `${releaseBaseURL(version)}/${archiveName}`;
96
- const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "cloudless-menubar-"));
97
- const archivePath = path.join(tempDir, archiveName);
98
- const extractDir = path.join(tempDir, "extract");
33
+ const agentPath = installBinary(agentSource, AGENT_BINARY_NAME);
99
34
 
100
- try {
101
- await fetchToFile(url, archivePath);
102
- extractArchive(archivePath, extractDir);
103
- const binary = findFileRecursive(extractDir, MENUBAR_BINARY_NAME);
104
- if (!binary) {
105
- throw new Error(`Release archive does not contain ${MENUBAR_BINARY_NAME}`);
35
+ let menubarPath = null;
36
+ if (target.goos === "darwin") {
37
+ const menuBarSource = path.join(platformDir, MENUBAR_BINARY_NAME);
38
+ if (!fs.existsSync(menuBarSource)) {
39
+ throw new Error(`Bundled binaries are missing ${MENUBAR_BINARY_NAME} for ${target.goos}/${target.goarch}`);
106
40
  }
107
- return installBinary(binary, MENUBAR_BINARY_NAME);
108
- } catch {
109
- const sourceTree = await ensureSourceTree(version);
110
- const menubarRoot = sourceTree ? path.join(sourceTree, "apps", "menubar-macos") : null;
111
- if (!menubarRoot || !fs.existsSync(path.join(menubarRoot, "Package.swift"))) {
112
- return null;
113
- }
114
- execFileSync("swift", ["build", "-c", "release", "--product", "CloudlessMenuBar"], {
115
- cwd: menubarRoot,
116
- stdio: "inherit",
117
- });
118
- const builtBinary = path.join(menubarRoot, ".build", "release", MENUBAR_BINARY_NAME);
119
- if (!fs.existsSync(builtBinary)) {
120
- return null;
121
- }
122
- return installBinary(builtBinary, MENUBAR_BINARY_NAME);
123
- } finally {
124
- fs.rmSync(tempDir, { recursive: true, force: true });
41
+ menubarPath = installBinary(menuBarSource, MENUBAR_BINARY_NAME);
125
42
  }
43
+
44
+ return { agentPath, menubarPath };
126
45
  }
127
46
 
128
47
  async function promptConfig() {
@@ -143,30 +62,18 @@ async function promptConfig() {
143
62
  }
144
63
 
145
64
  async function main() {
146
- try {
147
- ensureDirs();
148
- const version = normalizeVersion(pkg.version);
149
- const target = detectTarget();
150
-
151
- process.stdout.write(`Installing Cloudless node agent for ${target.goos}/${target.goarch}...\n`);
152
- const agentPath = await installAgent(version, target);
153
- process.stdout.write(`Installed ${agentPath}\n`);
154
-
155
- const menubarPath = await installMenubar(version);
156
- if (menubarPath) {
157
- process.stdout.write(`Installed ${menubarPath}\n`);
158
- }
159
-
160
- await promptConfig();
161
- process.stdout.write("Done. Run `cloudless-node start` to launch the node agent.\n");
162
- if (process.platform === "darwin") {
163
- process.stdout.write("Run `cloudless-node menubar` to start the menu bar app.\n");
164
- }
165
- } finally {
166
- if (downloadedSourceTempDir) {
167
- fs.rmSync(downloadedSourceTempDir, { recursive: true, force: true });
168
- downloadedSourceTempDir = null;
169
- }
65
+ ensureDirs();
66
+ const target = detectTarget();
67
+ process.stdout.write(`Installing Cloudless node agent for ${target.goos}/${target.goarch}...\n`);
68
+ const result = installFromPlatformPackage(target);
69
+ process.stdout.write(`Installed ${result.agentPath}\n`);
70
+ if (result.menubarPath) {
71
+ process.stdout.write(`Installed ${result.menubarPath}\n`);
72
+ }
73
+ await promptConfig();
74
+ process.stdout.write("Done. Run `cloudless-node start` to launch the node agent.\n");
75
+ if (target.goos === "darwin") {
76
+ process.stdout.write("Run `cloudless-node menubar` to start the menu bar app.\n");
170
77
  }
171
78
  }
172
79
 
@@ -1,121 +0,0 @@
1
- #!/usr/bin/env node
2
- const fs = require("node:fs");
3
- const { spawnSync } = require("node:child_process");
4
- const path = require("node:path");
5
-
6
- const {
7
- AGENT_BINARY_NAME,
8
- MENUBAR_BINARY_NAME,
9
- BIN_DIR,
10
- CONFIG_PATH,
11
- promptSecret,
12
- writeOrUpdateConfig,
13
- } = require("../scripts/common");
14
-
15
- function usage() {
16
- process.stdout.write(`Cloudless AI Node CLI
17
-
18
- Usage:
19
- cloudless-node start
20
- cloudless-node menubar
21
- cloudless-node set-api-key
22
- cloudless-node configure --router <url> --token <api-key>
23
- cloudless-node paths
24
- `);
25
- }
26
-
27
- function requiredBinaryPath(name) {
28
- const fullPath = path.join(BIN_DIR, name);
29
- if (!fs.existsSync(fullPath)) {
30
- process.stderr.write(`Binary not found: ${fullPath}\n`);
31
- process.stderr.write("Reinstall package: npm install -g @cloudless-ai/node-agent\n");
32
- process.exit(1);
33
- }
34
- return fullPath;
35
- }
36
-
37
- function run(command, args, extraEnv = {}) {
38
- const result = spawnSync(command, args, {
39
- stdio: "inherit",
40
- env: { ...process.env, ...extraEnv },
41
- });
42
- process.exit(result.status ?? 1);
43
- }
44
-
45
- function parseFlag(flag) {
46
- const idx = process.argv.indexOf(flag);
47
- if (idx < 0 || idx + 1 >= process.argv.length) {
48
- return "";
49
- }
50
- return process.argv[idx + 1];
51
- }
52
-
53
- async function setAPIKeyFromPrompt() {
54
- const token = await promptSecret("Enter Cloudless router API key (hidden): ");
55
- if (!token) {
56
- process.stderr.write("No API key provided.\n");
57
- process.exit(1);
58
- }
59
- const routerURL = process.env.CLOUDLESS_ROUTER_URL?.trim() || "http://localhost:8080";
60
- writeOrUpdateConfig({ routerURL, token });
61
- process.stdout.write(`Updated API key in ${CONFIG_PATH}\n`);
62
- }
63
-
64
- async function main() {
65
- const command = process.argv[2] ?? "help";
66
- if (command === "help" || command === "--help" || command === "-h") {
67
- usage();
68
- return;
69
- }
70
-
71
- if (command === "paths") {
72
- process.stdout.write(`Agent binary: ${path.join(BIN_DIR, AGENT_BINARY_NAME)}\n`);
73
- process.stdout.write(`Menu bar binary: ${path.join(BIN_DIR, MENUBAR_BINARY_NAME)}\n`);
74
- process.stdout.write(`Config: ${CONFIG_PATH}\n`);
75
- return;
76
- }
77
-
78
- if (command === "set-api-key") {
79
- await setAPIKeyFromPrompt();
80
- return;
81
- }
82
-
83
- if (command === "configure") {
84
- const router = parseFlag("--router") || process.env.CLOUDLESS_ROUTER_URL || "http://localhost:8080";
85
- const token = parseFlag("--token") || process.env.CLOUDLESS_NODE_API_KEY || "";
86
- if (!token) {
87
- process.stderr.write("Missing API key. Use --token or CLOUDLESS_NODE_API_KEY.\n");
88
- process.exit(1);
89
- }
90
- writeOrUpdateConfig({ routerURL: router, token });
91
- process.stdout.write(`Updated config: ${CONFIG_PATH}\n`);
92
- return;
93
- }
94
-
95
- if (command === "start") {
96
- const agent = requiredBinaryPath(AGENT_BINARY_NAME);
97
- run(agent, ["--config", CONFIG_PATH]);
98
- return;
99
- }
100
-
101
- if (command === "menubar") {
102
- if (process.platform !== "darwin") {
103
- process.stderr.write("Menu bar app is only available on macOS.\n");
104
- process.exit(1);
105
- }
106
- const menubar = requiredBinaryPath(MENUBAR_BINARY_NAME);
107
- run(menubar, [], {
108
- CLOUDLESS_AGENT_CONFIG_PATH: CONFIG_PATH,
109
- CLOUDLESS_AGENT_STATUS_URL: process.env.CLOUDLESS_AGENT_STATUS_URL || "http://127.0.0.1:9090/v1/local/status",
110
- });
111
- return;
112
- }
113
-
114
- usage();
115
- process.exit(1);
116
- }
117
-
118
- main().catch((error) => {
119
- process.stderr.write(`${error.message}\n`);
120
- process.exit(1);
121
- });