badgr-cli 1.0.3 → 1.0.4
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 +3 -11
- package/src/api.js +36 -10
- package/src/commands/run.js +3 -1
- package/src/commands/serve.js +3 -1
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "badgr-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Badgr — run or serve GPU workloads from one command",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
|
-
"badgr": "src/badgr.js"
|
|
7
|
+
"badgr": "./src/badgr.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"start": "node src/badgr.js",
|
|
@@ -21,14 +21,6 @@
|
|
|
21
21
|
"engines": {
|
|
22
22
|
"node": ">=18.0.0"
|
|
23
23
|
},
|
|
24
|
-
"keywords": [
|
|
25
|
-
"gpu",
|
|
26
|
-
"cli",
|
|
27
|
-
"ai",
|
|
28
|
-
"compute",
|
|
29
|
-
"modal",
|
|
30
|
-
"gateway",
|
|
31
|
-
"openai"
|
|
32
|
-
],
|
|
24
|
+
"keywords": ["gpu", "cli", "ai", "compute", "modal", "gateway", "openai"],
|
|
33
25
|
"license": "MIT"
|
|
34
26
|
}
|
package/src/api.js
CHANGED
|
@@ -1,16 +1,42 @@
|
|
|
1
1
|
export async function callApi(path, { method = 'GET', apiKey, baseUrl, body } = {}) {
|
|
2
2
|
const url = `${baseUrl}${path}`;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
let res;
|
|
4
|
+
try {
|
|
5
|
+
res = await fetch(url, {
|
|
6
|
+
method,
|
|
7
|
+
headers: {
|
|
8
|
+
'Content-Type': 'application/json',
|
|
9
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
10
|
+
},
|
|
11
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
12
|
+
});
|
|
13
|
+
} catch (cause) {
|
|
14
|
+
// Network-level failure: DNS, connection refused, timeout, etc.
|
|
15
|
+
const msg = cause?.message ?? String(cause);
|
|
16
|
+
const hint =
|
|
17
|
+
msg.includes('ECONNREFUSED') ? `\n Hint: Connection refused — is the server running at ${baseUrl}?` :
|
|
18
|
+
msg.includes('ENOTFOUND') ? `\n Hint: DNS lookup failed — check your internet connection or BADGR_API_URL` :
|
|
19
|
+
msg.includes('ETIMEDOUT') ? `\n Hint: Request timed out — the server may be overloaded` :
|
|
20
|
+
`\n Hint: Check your network connection and that BADGR_API_URL is correct`;
|
|
21
|
+
throw new Error(`Cannot reach ${url} (${msg})${hint}`);
|
|
22
|
+
}
|
|
11
23
|
if (!res.ok) {
|
|
12
|
-
|
|
13
|
-
|
|
24
|
+
let detail = '';
|
|
25
|
+
try {
|
|
26
|
+
const text = await res.text();
|
|
27
|
+
// Try to extract a readable detail from JSON error bodies
|
|
28
|
+
const json = JSON.parse(text);
|
|
29
|
+
detail = json?.detail ?? json?.message ?? json?.error ?? text;
|
|
30
|
+
} catch {
|
|
31
|
+
detail = res.statusText || '';
|
|
32
|
+
}
|
|
33
|
+
const hint =
|
|
34
|
+
res.status === 401 ? '\n Hint: Invalid or missing API key — run: badgr login' :
|
|
35
|
+
res.status === 403 ? '\n Hint: Access denied — check your API key permissions' :
|
|
36
|
+
res.status === 404 ? `\n Hint: Endpoint not found — check BADGR_API_URL (currently: ${baseUrl})` :
|
|
37
|
+
res.status === 502 || res.status === 503 ? '\n Hint: Server error — no GPU capacity available or backend is down' :
|
|
38
|
+
'';
|
|
39
|
+
throw new Error(`${method} ${path} → HTTP ${res.status}: ${detail}${hint}`);
|
|
14
40
|
}
|
|
15
41
|
return res.json();
|
|
16
42
|
}
|
package/src/commands/run.js
CHANGED
|
@@ -118,7 +118,9 @@ export async function runCommand(config, args, chalk) {
|
|
|
118
118
|
},
|
|
119
119
|
});
|
|
120
120
|
} catch (err) {
|
|
121
|
-
console.error(chalk.red(`\n ✗ Job failed to start: ${err.message}
|
|
121
|
+
console.error(chalk.red(`\n ✗ Job failed to start: ${err.message}`));
|
|
122
|
+
console.error(chalk.dim(`\n API URL: ${config.baseUrl}`));
|
|
123
|
+
console.error(chalk.dim(` Config: badgr config Docs: badgr --help\n`));
|
|
122
124
|
process.exit(1);
|
|
123
125
|
}
|
|
124
126
|
|
package/src/commands/serve.js
CHANGED
|
@@ -86,7 +86,9 @@ export async function serveCommand(config, args, chalk) {
|
|
|
86
86
|
},
|
|
87
87
|
});
|
|
88
88
|
} catch (err) {
|
|
89
|
-
console.error(chalk.red(`\n ✗ Serve failed: ${err.message}
|
|
89
|
+
console.error(chalk.red(`\n ✗ Serve failed: ${err.message}`));
|
|
90
|
+
console.error(chalk.dim(`\n API URL: ${config.baseUrl}`));
|
|
91
|
+
console.error(chalk.dim(` Config: badgr config Docs: badgr --help\n`));
|
|
90
92
|
return;
|
|
91
93
|
}
|
|
92
94
|
|