@1930dev/opencode-usage 0.2.0 → 0.3.1
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 +1 -0
- package/dist/cli.js +34 -1
- package/dist/tui.js +34 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -119,6 +119,7 @@ Restart opencode after a rebuild: the bundle is read once at start.
|
|
|
119
119
|
Normalized percentage of budget consumed per provider, from these sources (in priority):
|
|
120
120
|
|
|
121
121
|
1. **Live quota** — provider-reported usage:
|
|
122
|
+
- `amd`: daily spend ceiling (USD/day)
|
|
122
123
|
- `github-copilot`: premium requests entitlement (7000/mo)
|
|
123
124
|
- `opencode-go` (Zen): rolling 5h / weekly / monthly % (binding window)
|
|
124
125
|
- `openrouter`: credits used / total credits
|
package/dist/cli.js
CHANGED
|
@@ -296,6 +296,38 @@ async function fetchZai(key) {
|
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
+
// packages/core/src/quota/amd.ts
|
|
300
|
+
async function fetchAmd(key) {
|
|
301
|
+
try {
|
|
302
|
+
const data = await getJson("https://developer.amd.com.cn/radeon/api/v1/usage", {
|
|
303
|
+
Authorization: `Bearer ${key}`
|
|
304
|
+
});
|
|
305
|
+
if (data.status && data.status !== "ok") {
|
|
306
|
+
return { provider: "amd", ok: false, detail: `usage endpoint reports ${data.status}`, windows: [] };
|
|
307
|
+
}
|
|
308
|
+
const limit = data.daily_cost_limit_usd ?? 0;
|
|
309
|
+
const used = data.daily_cost_used_usd ?? 0;
|
|
310
|
+
const pct = limit > 0 ? Math.round(used / limit * 1000) / 10 : 0;
|
|
311
|
+
const windows = [
|
|
312
|
+
{
|
|
313
|
+
label: "daily",
|
|
314
|
+
percentUsed: pct,
|
|
315
|
+
resetsAt: data.daily_reset_at,
|
|
316
|
+
detail: `$${used.toFixed(4)} of $${limit.toFixed(2)}`
|
|
317
|
+
}
|
|
318
|
+
];
|
|
319
|
+
return {
|
|
320
|
+
provider: "amd",
|
|
321
|
+
ok: true,
|
|
322
|
+
windows,
|
|
323
|
+
budget: limit > 0 ? { percentUsed: pct, label: `$${limit}/d` } : undefined,
|
|
324
|
+
raw: data
|
|
325
|
+
};
|
|
326
|
+
} catch (err) {
|
|
327
|
+
return { provider: "amd", ok: false, detail: err.message, windows: [] };
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
299
331
|
// packages/core/src/providers.ts
|
|
300
332
|
var TTL_MS = 15 * 60 * 1000;
|
|
301
333
|
async function readCache() {
|
|
@@ -317,7 +349,8 @@ var FETCHERS = {
|
|
|
317
349
|
"opencode-go": fetchZen,
|
|
318
350
|
openrouter: fetchOpenRouter,
|
|
319
351
|
"github-copilot": fetchCopilot,
|
|
320
|
-
zai: fetchZai
|
|
352
|
+
zai: fetchZai,
|
|
353
|
+
amd: fetchAmd
|
|
321
354
|
};
|
|
322
355
|
async function providerStatuses(opts) {
|
|
323
356
|
const auth = await readAuth();
|
package/dist/tui.js
CHANGED
|
@@ -286,6 +286,38 @@ async function fetchZai(key) {
|
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
+
// packages/core/src/quota/amd.ts
|
|
290
|
+
async function fetchAmd(key) {
|
|
291
|
+
try {
|
|
292
|
+
const data = await getJson("https://developer.amd.com.cn/radeon/api/v1/usage", {
|
|
293
|
+
Authorization: `Bearer ${key}`
|
|
294
|
+
});
|
|
295
|
+
if (data.status && data.status !== "ok") {
|
|
296
|
+
return { provider: "amd", ok: false, detail: `usage endpoint reports ${data.status}`, windows: [] };
|
|
297
|
+
}
|
|
298
|
+
const limit = data.daily_cost_limit_usd ?? 0;
|
|
299
|
+
const used = data.daily_cost_used_usd ?? 0;
|
|
300
|
+
const pct = limit > 0 ? Math.round(used / limit * 1000) / 10 : 0;
|
|
301
|
+
const windows = [
|
|
302
|
+
{
|
|
303
|
+
label: "daily",
|
|
304
|
+
percentUsed: pct,
|
|
305
|
+
resetsAt: data.daily_reset_at,
|
|
306
|
+
detail: `$${used.toFixed(4)} of $${limit.toFixed(2)}`
|
|
307
|
+
}
|
|
308
|
+
];
|
|
309
|
+
return {
|
|
310
|
+
provider: "amd",
|
|
311
|
+
ok: true,
|
|
312
|
+
windows,
|
|
313
|
+
budget: limit > 0 ? { percentUsed: pct, label: `$${limit}/d` } : undefined,
|
|
314
|
+
raw: data
|
|
315
|
+
};
|
|
316
|
+
} catch (err) {
|
|
317
|
+
return { provider: "amd", ok: false, detail: err.message, windows: [] };
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
289
321
|
// packages/core/src/providers.ts
|
|
290
322
|
var TTL_MS = 15 * 60 * 1000;
|
|
291
323
|
async function readCache() {
|
|
@@ -307,7 +339,8 @@ var FETCHERS = {
|
|
|
307
339
|
"opencode-go": fetchZen,
|
|
308
340
|
openrouter: fetchOpenRouter,
|
|
309
341
|
"github-copilot": fetchCopilot,
|
|
310
|
-
zai: fetchZai
|
|
342
|
+
zai: fetchZai,
|
|
343
|
+
amd: fetchAmd
|
|
311
344
|
};
|
|
312
345
|
async function providerStatuses(opts) {
|
|
313
346
|
const auth = await readAuth();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1930dev/opencode-usage",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Usage tracking, budget percentages and model ranking for opencode
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "Usage tracking, budget percentages and model ranking for opencode — CLI plus a /usage TUI plugin",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"opencode-usage": "./dist/cli.js"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"tokens",
|
|
29
29
|
"llm"
|
|
30
30
|
],
|
|
31
|
-
"author": "Agu
|
|
31
|
+
"author": "Agu Rodríguez <me@agu.uy>",
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@opencode-ai/plugin": "^1.18.26",
|