wattage-cli 0.1.0
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/bin/wattage.js +40 -0
- package/package.json +24 -0
package/bin/wattage.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// npx wattage-cli shim: wattage's actual implementation is the Python core
|
|
5
|
+
// (src/wattage/) — this just shells out to it via uvx (preferred, since it
|
|
6
|
+
// needs no separate install step) or pipx, whichever is available. No
|
|
7
|
+
// bundled/reimplemented logic here; the Python package is the single
|
|
8
|
+
// source of truth.
|
|
9
|
+
|
|
10
|
+
const { spawnSync } = require("child_process");
|
|
11
|
+
|
|
12
|
+
const args = process.argv.slice(2);
|
|
13
|
+
|
|
14
|
+
function commandExists(command) {
|
|
15
|
+
const probe = spawnSync(command, ["--version"], { stdio: "ignore" });
|
|
16
|
+
return !probe.error;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function run(command, commandArgs) {
|
|
20
|
+
const result = spawnSync(command, commandArgs, { stdio: "inherit" });
|
|
21
|
+
if (result.error) {
|
|
22
|
+
console.error(`Failed to run ${command}: ${result.error.message}`);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
process.exit(result.status === null ? 1 : result.status);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (commandExists("uvx")) {
|
|
29
|
+
run("uvx", ["wattage", ...args]);
|
|
30
|
+
} else if (commandExists("pipx")) {
|
|
31
|
+
run("pipx", ["run", "wattage", ...args]);
|
|
32
|
+
} else {
|
|
33
|
+
console.error(
|
|
34
|
+
"wattage-cli needs either `uvx` (https://docs.astral.sh/uv/) or " +
|
|
35
|
+
"`pipx` (https://pipx.pypa.io/) installed to run the Python core.\n" +
|
|
36
|
+
"Install uv (curl -LsSf https://astral.sh/uv/install.sh | sh), then re-run:\n" +
|
|
37
|
+
` npx wattage-cli ${args.join(" ")}`
|
|
38
|
+
);
|
|
39
|
+
process.exit(2);
|
|
40
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wattage-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "npx shim for wattage, a token-spend profiler and cost-regression gate for AI agents. Shells out to the Python core via uvx/pipx.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"wattage": "bin/wattage.js"
|
|
7
|
+
},
|
|
8
|
+
"license": "Apache-2.0",
|
|
9
|
+
"homepage": "https://github.com/faizannraza/wattage",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/faizannraza/wattage.git"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"llm",
|
|
16
|
+
"agents",
|
|
17
|
+
"opentelemetry",
|
|
18
|
+
"cost",
|
|
19
|
+
"tokens"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=16"
|
|
23
|
+
}
|
|
24
|
+
}
|