@inferencesh/belt 1.9.6
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/install.js +95 -0
- package/package.json +30 -0
- package/run.js +18 -0
package/install.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const https = require("https");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const { execSync } = require("child_process");
|
|
7
|
+
const crypto = require("crypto");
|
|
8
|
+
|
|
9
|
+
const MANIFEST_URL = "https://dist.inference.sh/cli/manifest.json";
|
|
10
|
+
const BIN_DIR = path.join(__dirname, "bin");
|
|
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 fetch(url) {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
https
|
|
27
|
+
.get(url, (res) => {
|
|
28
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
29
|
+
return fetch(res.headers.location).then(resolve, reject);
|
|
30
|
+
}
|
|
31
|
+
if (res.statusCode !== 200) {
|
|
32
|
+
return reject(new Error(`HTTP ${res.statusCode} for ${url}`));
|
|
33
|
+
}
|
|
34
|
+
const chunks = [];
|
|
35
|
+
res.on("data", (c) => chunks.push(c));
|
|
36
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
37
|
+
res.on("error", reject);
|
|
38
|
+
})
|
|
39
|
+
.on("error", reject);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function main() {
|
|
44
|
+
console.log(`Downloading belt for ${PLATFORM}/${ARCH}...`);
|
|
45
|
+
|
|
46
|
+
const manifest = JSON.parse(await fetch(MANIFEST_URL));
|
|
47
|
+
const build = manifest.builds[KEY];
|
|
48
|
+
if (!build) {
|
|
49
|
+
console.error(`No build found for ${KEY}`);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const archive = await fetch(build.url);
|
|
54
|
+
|
|
55
|
+
// Verify checksum
|
|
56
|
+
const actual = crypto.createHash("sha256").update(archive).digest("hex");
|
|
57
|
+
if (build.sha256 && actual !== build.sha256) {
|
|
58
|
+
console.error(`Checksum mismatch!\n expected: ${build.sha256}\n got: ${actual}`);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fs.mkdirSync(BIN_DIR, { recursive: true });
|
|
63
|
+
|
|
64
|
+
const archivePath = path.join(BIN_DIR, path.basename(build.url));
|
|
65
|
+
fs.writeFileSync(archivePath, archive);
|
|
66
|
+
|
|
67
|
+
// Extract
|
|
68
|
+
if (archivePath.endsWith(".zip")) {
|
|
69
|
+
execSync(`unzip -o "${archivePath}" -d "${BIN_DIR}"`, { stdio: "pipe" });
|
|
70
|
+
} else {
|
|
71
|
+
execSync(`tar -xzf "${archivePath}" -C "${BIN_DIR}"`, { stdio: "pipe" });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Find the binary and rename to belt
|
|
75
|
+
const ext = PLATFORM === "windows" ? ".exe" : "";
|
|
76
|
+
const beltBin = path.join(BIN_DIR, `belt${ext}`);
|
|
77
|
+
const files = fs.readdirSync(BIN_DIR).filter((f) => f.startsWith("inferencesh-cli"));
|
|
78
|
+
if (files.length > 0) {
|
|
79
|
+
fs.renameSync(path.join(BIN_DIR, files[0]), beltBin);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (PLATFORM !== "windows") {
|
|
83
|
+
fs.chmodSync(beltBin, 0o755);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Clean up archive
|
|
87
|
+
fs.unlinkSync(archivePath);
|
|
88
|
+
|
|
89
|
+
console.log(`Installed belt ${manifest.version}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
main().catch((err) => {
|
|
93
|
+
console.error("Installation failed:", err.message);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@inferencesh/belt",
|
|
3
|
+
"version": "1.9.6",
|
|
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));
|