beltsh 0.0.2 → 1.9.15

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.
Files changed (4) hide show
  1. package/install.js +127 -0
  2. package/package.json +30 -1
  3. package/run.js +18 -0
  4. package/index.js +0 -3
package/install.js ADDED
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env node
2
+
3
+ const https = require("https");
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const os = require("os");
7
+ const { execSync } = require("child_process");
8
+ const crypto = require("crypto");
9
+
10
+ const MANIFEST_URL = "https://dist.inference.sh/cli/manifest.json";
11
+
12
+ const PLATFORM = { darwin: "darwin", linux: "linux", win32: "windows" }[
13
+ process.platform
14
+ ];
15
+ const ARCH = { x64: "amd64", arm64: "arm64" }[process.arch];
16
+
17
+ if (!PLATFORM || !ARCH) {
18
+ console.error(`Unsupported platform: ${process.platform}/${process.arch}`);
19
+ process.exit(1);
20
+ }
21
+
22
+ const KEY = `${PLATFORM}-${ARCH}`;
23
+
24
+ function getInstallDir() {
25
+ // Same logic as the curl installer
26
+ if (process.platform === "win32") {
27
+ return path.join(os.homedir(), ".local", "bin");
28
+ }
29
+ if (process.getuid && process.getuid() === 0) {
30
+ return "/usr/local/bin";
31
+ }
32
+ return path.join(os.homedir(), ".local", "bin");
33
+ }
34
+
35
+ function fetch(url) {
36
+ return new Promise((resolve, reject) => {
37
+ https
38
+ .get(url, (res) => {
39
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
40
+ return fetch(res.headers.location).then(resolve, reject);
41
+ }
42
+ if (res.statusCode !== 200) {
43
+ return reject(new Error(`HTTP ${res.statusCode} for ${url}`));
44
+ }
45
+ const chunks = [];
46
+ res.on("data", (c) => chunks.push(c));
47
+ res.on("end", () => resolve(Buffer.concat(chunks)));
48
+ res.on("error", reject);
49
+ })
50
+ .on("error", reject);
51
+ });
52
+ }
53
+
54
+ async function main() {
55
+ const installDir = getInstallDir();
56
+ console.log(`Downloading belt for ${PLATFORM}/${ARCH}...`);
57
+
58
+ const manifest = JSON.parse(await fetch(MANIFEST_URL));
59
+ const build = manifest.builds[KEY];
60
+ if (!build) {
61
+ console.error(`No build found for ${KEY}`);
62
+ process.exit(1);
63
+ }
64
+
65
+ const archive = await fetch(build.url);
66
+
67
+ // Verify checksum
68
+ const actual = crypto.createHash("sha256").update(archive).digest("hex");
69
+ if (build.sha256 && actual !== build.sha256) {
70
+ console.error(`Checksum mismatch!\n expected: ${build.sha256}\n got: ${actual}`);
71
+ process.exit(1);
72
+ }
73
+
74
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "belt-"));
75
+ const archivePath = path.join(tmpDir, path.basename(build.url));
76
+ fs.writeFileSync(archivePath, archive);
77
+
78
+ // Extract
79
+ if (archivePath.endsWith(".zip")) {
80
+ execSync(`unzip -o "${archivePath}" -d "${tmpDir}"`, { stdio: "pipe" });
81
+ } else {
82
+ execSync(`tar -xzf "${archivePath}" -C "${tmpDir}"`, { stdio: "pipe" });
83
+ }
84
+
85
+ // Find the extracted binary
86
+ const ext = PLATFORM === "windows" ? ".exe" : "";
87
+ const files = fs.readdirSync(tmpDir).filter((f) => f.startsWith("inferencesh-cli"));
88
+ if (files.length === 0) {
89
+ console.error("Binary not found in archive");
90
+ process.exit(1);
91
+ }
92
+
93
+ // Install to persistent location
94
+ fs.mkdirSync(installDir, { recursive: true });
95
+ const src = path.join(tmpDir, files[0]);
96
+ const dest = path.join(installDir, `belt${ext}`);
97
+
98
+ fs.copyFileSync(src, dest);
99
+ if (PLATFORM !== "windows") {
100
+ fs.chmodSync(dest, 0o755);
101
+ }
102
+
103
+ // Create symlinks (same as curl installer)
104
+ for (const alias of ["infsh", "inferencesh"]) {
105
+ const link = path.join(installDir, `${alias}${ext}`);
106
+ try { fs.unlinkSync(link); } catch {}
107
+ fs.symlinkSync(`belt${ext}`, link);
108
+ }
109
+
110
+ // Clean up temp
111
+ fs.rmSync(tmpDir, { recursive: true });
112
+
113
+ // Also install into npm bin/ so run.js works for npm install -g
114
+ const npmBin = path.join(__dirname, "bin");
115
+ fs.mkdirSync(npmBin, { recursive: true });
116
+ fs.copyFileSync(dest, path.join(npmBin, `belt${ext}`));
117
+ if (PLATFORM !== "windows") {
118
+ fs.chmodSync(path.join(npmBin, `belt${ext}`), 0o755);
119
+ }
120
+
121
+ console.log(`Installed belt ${manifest.version} to ${installDir}`);
122
+ }
123
+
124
+ main().catch((err) => {
125
+ console.error("Installation failed:", err.message);
126
+ process.exit(1);
127
+ });
package/package.json CHANGED
@@ -1 +1,30 @@
1
- {"name":"beltsh","version":"0.0.2","description":"inference.sh CLI — run AI apps, manage skills, connect MCP servers. Install: npx @inferencesh/belt","repository":"https://github.com/inference-sh/cli","bin":{"beltsh":"index.js"}}
1
+ {
2
+ "name": "beltsh",
3
+ "version": "1.9.15",
4
+ "description": "inference.sh CLI — run AI apps, manage skills, connect MCP servers",
5
+ "homepage": "https://inference.sh",
6
+ "repository": "https://github.com/inference-sh/cli",
7
+ "license": "MIT",
8
+ "bin": {
9
+ "belt": "run.js",
10
+ "infsh": "run.js",
11
+ "inferencesh": "run.js"
12
+ },
13
+ "scripts": {
14
+ "postinstall": "node install.js"
15
+ },
16
+ "os": [
17
+ "darwin",
18
+ "linux",
19
+ "win32"
20
+ ],
21
+ "cpu": [
22
+ "x64",
23
+ "arm64"
24
+ ],
25
+ "files": [
26
+ "install.js",
27
+ "run.js",
28
+ "bin/"
29
+ ]
30
+ }
package/run.js ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawn } = require("child_process");
4
+ const path = require("path");
5
+
6
+ const ext = process.platform === "win32" ? ".exe" : "";
7
+ const bin = path.join(__dirname, "bin", `belt${ext}`);
8
+
9
+ const child = spawn(bin, process.argv.slice(2), { stdio: "inherit" });
10
+ child.on("error", (err) => {
11
+ if (err.code === "ENOENT") {
12
+ console.error("belt binary not found. Try reinstalling: npm install @inferencesh/belt");
13
+ } else {
14
+ console.error(err.message);
15
+ }
16
+ process.exit(1);
17
+ });
18
+ child.on("exit", (code) => process.exit(code ?? 1));
package/index.js DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- console.log("Install the inference.sh CLI: npx @inferencesh/belt");
3
- process.exit(1);