@inferhub/usage 0.1.7 → 0.1.8
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/dist/format.d.ts +2 -0
- package/dist/format.js +14 -7
- package/dist/format.test.js +4 -4
- package/package.json +1 -1
- package/src/format.test.ts +4 -4
- package/src/format.ts +14 -7
package/dist/format.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { AccountUsage } from "./types.js";
|
|
2
2
|
export declare function money(usdc: string | number | null | undefined, digits?: number): string;
|
|
3
3
|
export declare function tokens(n: number | null | undefined): string;
|
|
4
|
+
/** Compact integer for statusline: 3943 → 3.9k, 28000000 → 28.0M */
|
|
5
|
+
export declare function compactCount(n: number | null | undefined): string;
|
|
4
6
|
export declare function shortModel(model: string | null | undefined): string;
|
|
5
7
|
/**
|
|
6
8
|
* One-line Claude statusline.
|
package/dist/format.js
CHANGED
|
@@ -9,12 +9,19 @@ export function money(usdc, digits = 2) {
|
|
|
9
9
|
return `$${n.toFixed(2)}`;
|
|
10
10
|
}
|
|
11
11
|
export function tokens(n) {
|
|
12
|
+
return compactCount(n);
|
|
13
|
+
}
|
|
14
|
+
/** Compact integer for statusline: 3943 → 3.9k, 28000000 → 28.0M */
|
|
15
|
+
export function compactCount(n) {
|
|
12
16
|
const v = Number(n ?? 0);
|
|
13
|
-
if (v
|
|
17
|
+
if (!Number.isFinite(v))
|
|
18
|
+
return "0";
|
|
19
|
+
const abs = Math.abs(v);
|
|
20
|
+
if (abs >= 1_000_000_000)
|
|
14
21
|
return `${(v / 1_000_000_000).toFixed(1)}B`;
|
|
15
|
-
if (
|
|
22
|
+
if (abs >= 1_000_000)
|
|
16
23
|
return `${(v / 1_000_000).toFixed(1)}M`;
|
|
17
|
-
if (
|
|
24
|
+
if (abs >= 1_000)
|
|
18
25
|
return `${(v / 1_000).toFixed(1)}k`;
|
|
19
26
|
return String(Math.round(v));
|
|
20
27
|
}
|
|
@@ -25,8 +32,8 @@ export function shortModel(model) {
|
|
|
25
32
|
return parts[parts.length - 1] || model;
|
|
26
33
|
}
|
|
27
34
|
/**
|
|
28
|
-
* Compact metric: "4r/1.2M" free, or "$0.
|
|
29
|
-
*
|
|
35
|
+
* Compact metric: "4r/1.2M" free, or "$0.41/3.9kr/355.7M" when billed.
|
|
36
|
+
* Both requests and tokens use k/M/B.
|
|
30
37
|
*/
|
|
31
38
|
function compact(spendUsdc, requests, totalTokens) {
|
|
32
39
|
const spend = Number(spendUsdc ?? 0);
|
|
@@ -38,9 +45,9 @@ function compact(spendUsdc, requests, totalTokens) {
|
|
|
38
45
|
if (spend > 0)
|
|
39
46
|
bits.push(money(spend));
|
|
40
47
|
if (req > 0)
|
|
41
|
-
bits.push(`${req}r`);
|
|
48
|
+
bits.push(`${compactCount(req)}r`);
|
|
42
49
|
if (tok > 0)
|
|
43
|
-
bits.push(
|
|
50
|
+
bits.push(compactCount(tok));
|
|
44
51
|
return bits.join("/") || "—";
|
|
45
52
|
}
|
|
46
53
|
/**
|
package/dist/format.test.js
CHANGED
|
@@ -49,11 +49,11 @@ test("formatStatusLine includes tokens compactly", () => {
|
|
|
49
49
|
cache: { cached: false, ttl_seconds: 30 },
|
|
50
50
|
};
|
|
51
51
|
const line = formatStatusLine(usage, { model: "grok-4.5", contextPct: 8 });
|
|
52
|
-
assert.equal(line, "InferHub · sess 19r/6.0M · day 129r/26.4M · all $0.41/
|
|
53
|
-
assert.ok(line.length <
|
|
54
|
-
assert.match(line, /
|
|
55
|
-
assert.match(line, /26\.4M/);
|
|
52
|
+
assert.equal(line, "InferHub · sess 19r/6.0M · day 129r/26.4M · all $0.41/3.9kr/354.2M · bal $1.31 · top gpt-5.5");
|
|
53
|
+
assert.ok(line.length < 100, `too long: ${line.length} ${line}`);
|
|
54
|
+
assert.match(line, /3\.9kr/);
|
|
56
55
|
assert.match(line, /354\.2M/);
|
|
56
|
+
assert.doesNotMatch(line, /3933r/);
|
|
57
57
|
// empty session omitted
|
|
58
58
|
const noSess = { ...usage, session: null };
|
|
59
59
|
assert.doesNotMatch(formatStatusLine(noSess), /sess /);
|
package/package.json
CHANGED
package/src/format.test.ts
CHANGED
|
@@ -59,12 +59,12 @@ test("formatStatusLine includes tokens compactly", () => {
|
|
|
59
59
|
const line = formatStatusLine(usage, { model: "grok-4.5", contextPct: 8 });
|
|
60
60
|
assert.equal(
|
|
61
61
|
line,
|
|
62
|
-
"InferHub · sess 19r/6.0M · day 129r/26.4M · all $0.41/
|
|
62
|
+
"InferHub · sess 19r/6.0M · day 129r/26.4M · all $0.41/3.9kr/354.2M · bal $1.31 · top gpt-5.5",
|
|
63
63
|
);
|
|
64
|
-
assert.ok(line.length <
|
|
65
|
-
assert.match(line, /
|
|
66
|
-
assert.match(line, /26\.4M/);
|
|
64
|
+
assert.ok(line.length < 100, `too long: ${line.length} ${line}`);
|
|
65
|
+
assert.match(line, /3\.9kr/);
|
|
67
66
|
assert.match(line, /354\.2M/);
|
|
67
|
+
assert.doesNotMatch(line, /3933r/);
|
|
68
68
|
|
|
69
69
|
// empty session omitted
|
|
70
70
|
const noSess = { ...usage, session: null };
|
package/src/format.ts
CHANGED
|
@@ -9,10 +9,17 @@ export function money(usdc: string | number | null | undefined, digits = 2): str
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export function tokens(n: number | null | undefined): string {
|
|
12
|
+
return compactCount(n);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Compact integer for statusline: 3943 → 3.9k, 28000000 → 28.0M */
|
|
16
|
+
export function compactCount(n: number | null | undefined): string {
|
|
12
17
|
const v = Number(n ?? 0);
|
|
13
|
-
if (v
|
|
14
|
-
|
|
15
|
-
if (
|
|
18
|
+
if (!Number.isFinite(v)) return "0";
|
|
19
|
+
const abs = Math.abs(v);
|
|
20
|
+
if (abs >= 1_000_000_000) return `${(v / 1_000_000_000).toFixed(1)}B`;
|
|
21
|
+
if (abs >= 1_000_000) return `${(v / 1_000_000).toFixed(1)}M`;
|
|
22
|
+
if (abs >= 1_000) return `${(v / 1_000).toFixed(1)}k`;
|
|
16
23
|
return String(Math.round(v));
|
|
17
24
|
}
|
|
18
25
|
|
|
@@ -23,8 +30,8 @@ export function shortModel(model: string | null | undefined): string {
|
|
|
23
30
|
}
|
|
24
31
|
|
|
25
32
|
/**
|
|
26
|
-
* Compact metric: "4r/1.2M" free, or "$0.
|
|
27
|
-
*
|
|
33
|
+
* Compact metric: "4r/1.2M" free, or "$0.41/3.9kr/355.7M" when billed.
|
|
34
|
+
* Both requests and tokens use k/M/B.
|
|
28
35
|
*/
|
|
29
36
|
function compact(
|
|
30
37
|
spendUsdc: string | number | null | undefined,
|
|
@@ -38,8 +45,8 @@ function compact(
|
|
|
38
45
|
|
|
39
46
|
const bits: string[] = [];
|
|
40
47
|
if (spend > 0) bits.push(money(spend));
|
|
41
|
-
if (req > 0) bits.push(`${req}r`);
|
|
42
|
-
if (tok > 0) bits.push(
|
|
48
|
+
if (req > 0) bits.push(`${compactCount(req)}r`);
|
|
49
|
+
if (tok > 0) bits.push(compactCount(tok));
|
|
43
50
|
return bits.join("/") || "—";
|
|
44
51
|
}
|
|
45
52
|
|