@smithers-orchestrator/usage 0.24.2 → 0.25.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithers-orchestrator/usage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.1",
|
|
4
4
|
"description": "Report how much rate limit or subscription quota each registered Smithers account has consumed, across Claude, Codex, OpenAI, Anthropic, and Google providers.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -20,8 +20,7 @@
|
|
|
20
20
|
"src/"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@smithers-orchestrator/
|
|
24
|
-
"@smithers-orchestrator/accounts": "0.24.2"
|
|
23
|
+
"@smithers-orchestrator/accounts": "0.25.1"
|
|
25
24
|
},
|
|
26
25
|
"devDependencies": {
|
|
27
26
|
"@types/bun": "latest",
|
package/src/claudeOauthUsage.js
CHANGED
|
@@ -25,6 +25,9 @@ export async function claudeOauthUsage(account) {
|
|
|
25
25
|
if (!creds) {
|
|
26
26
|
return { source: "none", error: "No Claude OAuth credentials in configDir or Keychain" };
|
|
27
27
|
}
|
|
28
|
+
if (typeof creds.expiresAt === "number" && creds.expiresAt <= Date.now()) {
|
|
29
|
+
return { source: "none", error: "Claude OAuth token expired; run `claude` to refresh" };
|
|
30
|
+
}
|
|
28
31
|
try {
|
|
29
32
|
const res = await fetch(USAGE_URL, {
|
|
30
33
|
headers: {
|
package/src/getAccountUsage.js
CHANGED
|
@@ -22,7 +22,7 @@ function countWindow(get, prefix, id, label) {
|
|
|
22
22
|
const remaining = int(get(`${prefix}-remaining`));
|
|
23
23
|
if (limit === undefined && remaining === undefined) return undefined;
|
|
24
24
|
const reset = get(`${prefix}-reset`);
|
|
25
|
-
const used = limit !== undefined && remaining !== undefined ? limit - remaining : undefined;
|
|
25
|
+
const used = limit !== undefined && remaining !== undefined ? Math.max(0, limit - remaining) : undefined;
|
|
26
26
|
return {
|
|
27
27
|
id,
|
|
28
28
|
label,
|
|
@@ -20,8 +20,11 @@ export function parseDurationSeconds(value) {
|
|
|
20
20
|
const re = /(\d+(?:\.\d+)?)(ms|us|µs|ns|s|m|h)/g;
|
|
21
21
|
let total = 0;
|
|
22
22
|
let matched = false;
|
|
23
|
+
let position = 0;
|
|
23
24
|
let match;
|
|
24
25
|
while ((match = re.exec(trimmed)) !== null) {
|
|
26
|
+
if (match.index !== position) return undefined;
|
|
27
|
+
position = re.lastIndex;
|
|
25
28
|
matched = true;
|
|
26
29
|
const amount = Number(match[1]);
|
|
27
30
|
switch (match[2]) {
|
|
@@ -34,5 +37,5 @@ export function parseDurationSeconds(value) {
|
|
|
34
37
|
case "ns": total += amount / 1_000_000_000; break;
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
|
-
return matched ? total : undefined;
|
|
40
|
+
return matched && position === trimmed.length ? total : undefined;
|
|
38
41
|
}
|
|
@@ -25,7 +25,7 @@ function countWindow(get, suffix, id, label, nowMs) {
|
|
|
25
25
|
const remaining = int(get(`x-ratelimit-remaining-${suffix}`));
|
|
26
26
|
if (limit === undefined && remaining === undefined) return undefined;
|
|
27
27
|
const resetSeconds = parseDurationSeconds(get(`x-ratelimit-reset-${suffix}`));
|
|
28
|
-
const used = limit !== undefined && remaining !== undefined ? limit - remaining : undefined;
|
|
28
|
+
const used = limit !== undefined && remaining !== undefined ? Math.max(0, limit - remaining) : undefined;
|
|
29
29
|
return {
|
|
30
30
|
id,
|
|
31
31
|
label,
|
package/src/usageCache.js
CHANGED
|
@@ -28,7 +28,8 @@ export function readUsageCache(env = process.env) {
|
|
|
28
28
|
if (!existsSync(path)) return { version: 1, entries: {} };
|
|
29
29
|
try {
|
|
30
30
|
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
31
|
-
if (parsed && typeof parsed === "object" && parsed.
|
|
31
|
+
if (parsed && typeof parsed === "object" && parsed.version === 1
|
|
32
|
+
&& parsed.entries && typeof parsed.entries === "object" && !Array.isArray(parsed.entries)) {
|
|
32
33
|
return { version: 1, entries: parsed.entries };
|
|
33
34
|
}
|
|
34
35
|
} catch {
|