@inferhub/usage 0.1.11 → 0.1.12
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 +4 -6
- package/dist/format.js +9 -11
- package/package.json +1 -1
- package/src/format.ts +25 -14
package/dist/format.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
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
|
|
4
|
+
/** Compact integer: 3943 → 3.9k, 28000000 → 28.0M */
|
|
5
5
|
export declare function compactCount(n: number | null | undefined): string;
|
|
6
6
|
export declare function shortModel(model: string | null | undefined): string;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Shared one-line status for Claude statusline and OpenCode TUI.
|
|
9
9
|
*
|
|
10
10
|
* Example:
|
|
11
|
-
* InferHub · sess 4r/1.2M · day 135r/26.4M · all $0.41/3.
|
|
12
|
-
*
|
|
13
|
-
* Keep under ~90 chars when possible; tokens use k/M/B.
|
|
11
|
+
* InferHub · sess 4r/1.2M · day 135r/26.4M · all $0.41/3.9kr/354.2M · bal $1.31
|
|
14
12
|
*/
|
|
15
13
|
export declare function formatStatusLine(usage: AccountUsage, extras?: {
|
|
16
14
|
sessionCostUsd?: number | null;
|
|
@@ -18,5 +16,5 @@ export declare function formatStatusLine(usage: AccountUsage, extras?: {
|
|
|
18
16
|
model?: string | null;
|
|
19
17
|
showEstimate?: boolean;
|
|
20
18
|
}): string;
|
|
21
|
-
/** Multi-line human report for /
|
|
19
|
+
/** Multi-line human report for skills / tools. */
|
|
22
20
|
export declare function formatReport(usage: AccountUsage): string;
|
package/dist/format.js
CHANGED
|
@@ -11,7 +11,7 @@ export function money(usdc, digits = 2) {
|
|
|
11
11
|
export function tokens(n) {
|
|
12
12
|
return compactCount(n);
|
|
13
13
|
}
|
|
14
|
-
/** Compact integer
|
|
14
|
+
/** Compact integer: 3943 → 3.9k, 28000000 → 28.0M */
|
|
15
15
|
export function compactCount(n) {
|
|
16
16
|
const v = Number(n ?? 0);
|
|
17
17
|
if (!Number.isFinite(v))
|
|
@@ -51,27 +51,25 @@ function compact(spendUsdc, requests, totalTokens) {
|
|
|
51
51
|
return bits.join("/") || "—";
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
|
-
*
|
|
54
|
+
* Shared one-line status for Claude statusline and OpenCode TUI.
|
|
55
55
|
*
|
|
56
56
|
* Example:
|
|
57
|
-
* InferHub · sess 4r/1.2M · day 135r/26.4M · all $0.41/3.
|
|
58
|
-
*
|
|
59
|
-
* Keep under ~90 chars when possible; tokens use k/M/B.
|
|
57
|
+
* InferHub · sess 4r/1.2M · day 135r/26.4M · all $0.41/3.9kr/354.2M · bal $1.31
|
|
60
58
|
*/
|
|
61
59
|
export function formatStatusLine(usage, extras) {
|
|
62
60
|
const parts = ["InferHub"];
|
|
63
|
-
if (usage.session &&
|
|
61
|
+
if (usage.session &&
|
|
62
|
+
(usage.session.requests > 0 ||
|
|
63
|
+
Number(usage.session.spend_usdc) > 0 ||
|
|
64
|
+
usage.session.total_tokens > 0)) {
|
|
64
65
|
parts.push(`sess ${compact(usage.session.spend_usdc, usage.session.requests, usage.session.total_tokens)}`);
|
|
65
66
|
}
|
|
66
67
|
parts.push(`day ${compact(usage.window.spend_usdc, usage.window.requests, usage.window.total_tokens)}`);
|
|
67
68
|
parts.push(`all ${compact(usage.all_time.spend_usdc, usage.all_time.requests, usage.all_time.total_tokens)}`);
|
|
68
69
|
parts.push(`bal ${money(usage.balance.amount_usdc)}`);
|
|
69
|
-
const top = shortModel(usage.top_model?.model);
|
|
70
|
-
if (top && top !== "—")
|
|
71
|
-
parts.push(`top ${top}`);
|
|
72
70
|
return parts.join(" · ");
|
|
73
71
|
}
|
|
74
|
-
/** Multi-line human report for /
|
|
72
|
+
/** Multi-line human report for skills / tools. */
|
|
75
73
|
export function formatReport(usage) {
|
|
76
74
|
const lines = [
|
|
77
75
|
"InferHub usage (billed USDC)",
|
|
@@ -80,7 +78,7 @@ export function formatReport(usage) {
|
|
|
80
78
|
if (usage.session) {
|
|
81
79
|
lines.push(` Session: ${usage.session.requests} requests · ${tokens(usage.session.total_tokens)} tokens · ${money(usage.session.spend_usdc)} billed`);
|
|
82
80
|
}
|
|
83
|
-
lines.push(` Today: ${usage.window.requests} requests · ${tokens(usage.window.total_tokens)} tokens · ${money(usage.window.spend_usdc)} billed`, ` All-time: ${usage.all_time.requests} requests · ${tokens(usage.all_time.total_tokens)} tokens · ${money(usage.all_time.spend_usdc)} billed
|
|
81
|
+
lines.push(` Today: ${usage.window.requests} requests · ${tokens(usage.window.total_tokens)} tokens · ${money(usage.window.spend_usdc)} billed`, ` All-time: ${usage.all_time.requests} requests · ${tokens(usage.all_time.total_tokens)} tokens · ${money(usage.all_time.spend_usdc)} billed`);
|
|
84
82
|
if (usage.cache?.cached)
|
|
85
83
|
lines.push(` (cached ${usage.cache.ttl_seconds}s)`);
|
|
86
84
|
return lines.join("\n");
|
package/package.json
CHANGED
package/src/format.ts
CHANGED
|
@@ -12,7 +12,7 @@ export function tokens(n: number | null | undefined): string {
|
|
|
12
12
|
return compactCount(n);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
/** Compact integer
|
|
15
|
+
/** Compact integer: 3943 → 3.9k, 28000000 → 28.0M */
|
|
16
16
|
export function compactCount(n: number | null | undefined): string {
|
|
17
17
|
const v = Number(n ?? 0);
|
|
18
18
|
if (!Number.isFinite(v)) return "0";
|
|
@@ -51,12 +51,10 @@ function compact(
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
*
|
|
54
|
+
* Shared one-line status for Claude statusline and OpenCode TUI.
|
|
55
55
|
*
|
|
56
56
|
* Example:
|
|
57
|
-
* InferHub · sess 4r/1.2M · day 135r/26.4M · all $0.41/3.
|
|
58
|
-
*
|
|
59
|
-
* Keep under ~90 chars when possible; tokens use k/M/B.
|
|
57
|
+
* InferHub · sess 4r/1.2M · day 135r/26.4M · all $0.41/3.9kr/354.2M · bal $1.31
|
|
60
58
|
*/
|
|
61
59
|
export function formatStatusLine(
|
|
62
60
|
usage: AccountUsage,
|
|
@@ -69,27 +67,41 @@ export function formatStatusLine(
|
|
|
69
67
|
): string {
|
|
70
68
|
const parts: string[] = ["InferHub"];
|
|
71
69
|
|
|
72
|
-
if (
|
|
70
|
+
if (
|
|
71
|
+
usage.session &&
|
|
72
|
+
(usage.session.requests > 0 ||
|
|
73
|
+
Number(usage.session.spend_usdc) > 0 ||
|
|
74
|
+
usage.session.total_tokens > 0)
|
|
75
|
+
) {
|
|
73
76
|
parts.push(
|
|
74
|
-
`sess ${compact(
|
|
77
|
+
`sess ${compact(
|
|
78
|
+
usage.session.spend_usdc,
|
|
79
|
+
usage.session.requests,
|
|
80
|
+
usage.session.total_tokens,
|
|
81
|
+
)}`,
|
|
75
82
|
);
|
|
76
83
|
}
|
|
77
84
|
|
|
78
85
|
parts.push(
|
|
79
|
-
`day ${compact(
|
|
86
|
+
`day ${compact(
|
|
87
|
+
usage.window.spend_usdc,
|
|
88
|
+
usage.window.requests,
|
|
89
|
+
usage.window.total_tokens,
|
|
90
|
+
)}`,
|
|
80
91
|
);
|
|
81
92
|
parts.push(
|
|
82
|
-
`all ${compact(
|
|
93
|
+
`all ${compact(
|
|
94
|
+
usage.all_time.spend_usdc,
|
|
95
|
+
usage.all_time.requests,
|
|
96
|
+
usage.all_time.total_tokens,
|
|
97
|
+
)}`,
|
|
83
98
|
);
|
|
84
99
|
parts.push(`bal ${money(usage.balance.amount_usdc)}`);
|
|
85
100
|
|
|
86
|
-
const top = shortModel(usage.top_model?.model);
|
|
87
|
-
if (top && top !== "—") parts.push(`top ${top}`);
|
|
88
|
-
|
|
89
101
|
return parts.join(" · ");
|
|
90
102
|
}
|
|
91
103
|
|
|
92
|
-
/** Multi-line human report for /
|
|
104
|
+
/** Multi-line human report for skills / tools. */
|
|
93
105
|
export function formatReport(usage: AccountUsage): string {
|
|
94
106
|
const lines = [
|
|
95
107
|
"InferHub usage (billed USDC)",
|
|
@@ -103,7 +115,6 @@ export function formatReport(usage: AccountUsage): string {
|
|
|
103
115
|
lines.push(
|
|
104
116
|
` Today: ${usage.window.requests} requests · ${tokens(usage.window.total_tokens)} tokens · ${money(usage.window.spend_usdc)} billed`,
|
|
105
117
|
` All-time: ${usage.all_time.requests} requests · ${tokens(usage.all_time.total_tokens)} tokens · ${money(usage.all_time.spend_usdc)} billed`,
|
|
106
|
-
` Top model: ${usage.top_model?.model ?? "—"} (${usage.top_model?.requests ?? 0} req · ${money(usage.top_model?.spend_usdc ?? 0)})`,
|
|
107
118
|
);
|
|
108
119
|
if (usage.cache?.cached) lines.push(` (cached ${usage.cache.ttl_seconds}s)`);
|
|
109
120
|
return lines.join("\n");
|