@inferhub/usage 0.1.1 → 0.1.2
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.test.js +38 -35
- package/package.json +1 -1
- package/src/format.test.ts +41 -35
package/dist/format.test.js
CHANGED
|
@@ -9,7 +9,7 @@ test("usageUrl", () => {
|
|
|
9
9
|
assert.equal(usageUrl("https://api.inferhub.dev", "day", "UTC"), "https://api.inferhub.dev/v1/me/usage?window=day&tz=UTC");
|
|
10
10
|
assert.equal(usageUrl("https://api.inferhub.dev", "day", "UTC", "abc"), "https://api.inferhub.dev/v1/me/usage?window=day&tz=UTC&session_id=abc");
|
|
11
11
|
});
|
|
12
|
-
test("formatStatusLine", () => {
|
|
12
|
+
test("formatStatusLine is plain language", () => {
|
|
13
13
|
const usage = {
|
|
14
14
|
object: "account.usage",
|
|
15
15
|
currency: "USDC",
|
|
@@ -19,64 +19,67 @@ test("formatStatusLine", () => {
|
|
|
19
19
|
tz: "UTC",
|
|
20
20
|
since: "",
|
|
21
21
|
until: "",
|
|
22
|
-
requests:
|
|
23
|
-
prompt_tokens:
|
|
24
|
-
completion_tokens:
|
|
25
|
-
total_tokens:
|
|
26
|
-
spend_usdc: "0
|
|
22
|
+
requests: 86,
|
|
23
|
+
prompt_tokens: 14_000_000,
|
|
24
|
+
completion_tokens: 100_000,
|
|
25
|
+
total_tokens: 14_100_000,
|
|
26
|
+
spend_usdc: "0",
|
|
27
27
|
},
|
|
28
28
|
all_time: {
|
|
29
|
-
requests:
|
|
30
|
-
prompt_tokens:
|
|
31
|
-
completion_tokens:
|
|
32
|
-
total_tokens:
|
|
33
|
-
spend_usdc: "0.
|
|
29
|
+
requests: 3890,
|
|
30
|
+
prompt_tokens: 300_000_000,
|
|
31
|
+
completion_tokens: 1_000_000,
|
|
32
|
+
total_tokens: 301_000_000,
|
|
33
|
+
spend_usdc: "0.410000",
|
|
34
34
|
},
|
|
35
35
|
session: {
|
|
36
36
|
id: "sess-1",
|
|
37
|
-
requests:
|
|
38
|
-
prompt_tokens:
|
|
39
|
-
completion_tokens:
|
|
40
|
-
total_tokens:
|
|
41
|
-
spend_usdc: "0
|
|
37
|
+
requests: 12,
|
|
38
|
+
prompt_tokens: 200_000,
|
|
39
|
+
completion_tokens: 5_000,
|
|
40
|
+
total_tokens: 205_000,
|
|
41
|
+
spend_usdc: "0",
|
|
42
42
|
since: null,
|
|
43
43
|
until: null,
|
|
44
44
|
},
|
|
45
45
|
top_model: {
|
|
46
|
-
model: "
|
|
47
|
-
requests:
|
|
48
|
-
tokens:
|
|
49
|
-
spend_usdc: "0.
|
|
46
|
+
model: "cx/gpt-5.5",
|
|
47
|
+
requests: 212,
|
|
48
|
+
tokens: 239830,
|
|
49
|
+
spend_usdc: "0.137155",
|
|
50
50
|
},
|
|
51
51
|
cache: { cached: false, ttl_seconds: 30 },
|
|
52
52
|
};
|
|
53
53
|
const line = formatStatusLine(usage, {
|
|
54
|
-
sessionCostUsd: 2.69,
|
|
55
|
-
contextPct: 12,
|
|
56
54
|
model: "free/grok/grok-4.5",
|
|
55
|
+
contextPct: 8,
|
|
56
|
+
sessionCostUsd: 2.69,
|
|
57
57
|
});
|
|
58
58
|
assert.match(line, /^InferHub/);
|
|
59
|
+
assert.match(line, /session 12 req \/ 205\.0k tok \/ \$0/);
|
|
60
|
+
assert.match(line, /today 86 req \/ 14\.1M tok \/ \$0/);
|
|
61
|
+
assert.match(line, /all-time 3,890 req \/ 301\.0M tok \/ \$0\.41/);
|
|
62
|
+
assert.match(line, /balance \$1\.25/);
|
|
63
|
+
assert.match(line, /top gpt-5\.5/);
|
|
64
|
+
assert.match(line, /8% context/);
|
|
59
65
|
assert.doesNotMatch(line, /\bIH\b/);
|
|
60
|
-
assert.
|
|
61
|
-
assert.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const freeDay = {
|
|
66
|
+
assert.doesNotMatch(line, /0r\/0/);
|
|
67
|
+
assert.doesNotMatch(line, /claude-est/); // estimate off by default
|
|
68
|
+
// empty/zero session should be omitted (not "sess 0r/0")
|
|
69
|
+
const noSess = {
|
|
65
70
|
...usage,
|
|
66
71
|
session: {
|
|
67
|
-
id: "
|
|
68
|
-
requests:
|
|
69
|
-
prompt_tokens:
|
|
72
|
+
id: "empty",
|
|
73
|
+
requests: 0,
|
|
74
|
+
prompt_tokens: 0,
|
|
70
75
|
completion_tokens: 0,
|
|
71
|
-
total_tokens:
|
|
76
|
+
total_tokens: 0,
|
|
72
77
|
spend_usdc: "0",
|
|
73
78
|
since: null,
|
|
74
79
|
until: null,
|
|
75
80
|
},
|
|
76
|
-
window: { ...usage.window, spend_usdc: "0", requests: 86, total_tokens: 14_100_000 },
|
|
77
81
|
};
|
|
78
|
-
const
|
|
79
|
-
assert.
|
|
80
|
-
assert.match(freeLine, /day 86r\/14\.1M/);
|
|
82
|
+
const line2 = formatStatusLine(noSess, { model: "Grok" });
|
|
83
|
+
assert.doesNotMatch(line2, /session /);
|
|
81
84
|
assert.equal(money("0.001"), "$0.0010");
|
|
82
85
|
});
|
package/package.json
CHANGED
package/src/format.test.ts
CHANGED
|
@@ -19,7 +19,7 @@ test("usageUrl", () => {
|
|
|
19
19
|
);
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
test("formatStatusLine", () => {
|
|
22
|
+
test("formatStatusLine is plain language", () => {
|
|
23
23
|
const usage: AccountUsage = {
|
|
24
24
|
object: "account.usage",
|
|
25
25
|
currency: "USDC",
|
|
@@ -29,65 +29,71 @@ test("formatStatusLine", () => {
|
|
|
29
29
|
tz: "UTC",
|
|
30
30
|
since: "",
|
|
31
31
|
until: "",
|
|
32
|
-
requests:
|
|
33
|
-
prompt_tokens:
|
|
34
|
-
completion_tokens:
|
|
35
|
-
total_tokens:
|
|
36
|
-
spend_usdc: "0
|
|
32
|
+
requests: 86,
|
|
33
|
+
prompt_tokens: 14_000_000,
|
|
34
|
+
completion_tokens: 100_000,
|
|
35
|
+
total_tokens: 14_100_000,
|
|
36
|
+
spend_usdc: "0",
|
|
37
37
|
},
|
|
38
38
|
all_time: {
|
|
39
|
-
requests:
|
|
40
|
-
prompt_tokens:
|
|
41
|
-
completion_tokens:
|
|
42
|
-
total_tokens:
|
|
43
|
-
spend_usdc: "0.
|
|
39
|
+
requests: 3890,
|
|
40
|
+
prompt_tokens: 300_000_000,
|
|
41
|
+
completion_tokens: 1_000_000,
|
|
42
|
+
total_tokens: 301_000_000,
|
|
43
|
+
spend_usdc: "0.410000",
|
|
44
44
|
},
|
|
45
45
|
session: {
|
|
46
46
|
id: "sess-1",
|
|
47
|
-
requests:
|
|
48
|
-
prompt_tokens:
|
|
49
|
-
completion_tokens:
|
|
50
|
-
total_tokens:
|
|
51
|
-
spend_usdc: "0
|
|
47
|
+
requests: 12,
|
|
48
|
+
prompt_tokens: 200_000,
|
|
49
|
+
completion_tokens: 5_000,
|
|
50
|
+
total_tokens: 205_000,
|
|
51
|
+
spend_usdc: "0",
|
|
52
52
|
since: null,
|
|
53
53
|
until: null,
|
|
54
54
|
},
|
|
55
55
|
top_model: {
|
|
56
|
-
model: "
|
|
57
|
-
requests:
|
|
58
|
-
tokens:
|
|
59
|
-
spend_usdc: "0.
|
|
56
|
+
model: "cx/gpt-5.5",
|
|
57
|
+
requests: 212,
|
|
58
|
+
tokens: 239830,
|
|
59
|
+
spend_usdc: "0.137155",
|
|
60
60
|
},
|
|
61
61
|
cache: { cached: false, ttl_seconds: 30 },
|
|
62
62
|
};
|
|
63
|
+
|
|
63
64
|
const line = formatStatusLine(usage, {
|
|
64
|
-
sessionCostUsd: 2.69,
|
|
65
|
-
contextPct: 12,
|
|
66
65
|
model: "free/grok/grok-4.5",
|
|
66
|
+
contextPct: 8,
|
|
67
|
+
sessionCostUsd: 2.69,
|
|
67
68
|
});
|
|
69
|
+
|
|
68
70
|
assert.match(line, /^InferHub/);
|
|
71
|
+
assert.match(line, /session 12 req \/ 205\.0k tok \/ \$0/);
|
|
72
|
+
assert.match(line, /today 86 req \/ 14\.1M tok \/ \$0/);
|
|
73
|
+
assert.match(line, /all-time 3,890 req \/ 301\.0M tok \/ \$0\.41/);
|
|
74
|
+
assert.match(line, /balance \$1\.25/);
|
|
75
|
+
assert.match(line, /top gpt-5\.5/);
|
|
76
|
+
assert.match(line, /8% context/);
|
|
69
77
|
assert.doesNotMatch(line, /\bIH\b/);
|
|
70
|
-
assert.
|
|
71
|
-
assert.
|
|
72
|
-
assert.match(line, /top grok-4\.5/);
|
|
73
|
-
assert.doesNotMatch(line, /est /);
|
|
78
|
+
assert.doesNotMatch(line, /0r\/0/);
|
|
79
|
+
assert.doesNotMatch(line, /claude-est/); // estimate off by default
|
|
74
80
|
|
|
75
|
-
|
|
81
|
+
// empty/zero session should be omitted (not "sess 0r/0")
|
|
82
|
+
const noSess: AccountUsage = {
|
|
76
83
|
...usage,
|
|
77
84
|
session: {
|
|
78
|
-
id: "
|
|
79
|
-
requests:
|
|
80
|
-
prompt_tokens:
|
|
85
|
+
id: "empty",
|
|
86
|
+
requests: 0,
|
|
87
|
+
prompt_tokens: 0,
|
|
81
88
|
completion_tokens: 0,
|
|
82
|
-
total_tokens:
|
|
89
|
+
total_tokens: 0,
|
|
83
90
|
spend_usdc: "0",
|
|
84
91
|
since: null,
|
|
85
92
|
until: null,
|
|
86
93
|
},
|
|
87
|
-
window: { ...usage.window, spend_usdc: "0", requests: 86, total_tokens: 14_100_000 },
|
|
88
94
|
};
|
|
89
|
-
const
|
|
90
|
-
assert.
|
|
91
|
-
|
|
95
|
+
const line2 = formatStatusLine(noSess, { model: "Grok" });
|
|
96
|
+
assert.doesNotMatch(line2, /session /);
|
|
97
|
+
|
|
92
98
|
assert.equal(money("0.001"), "$0.0010");
|
|
93
99
|
});
|