@hk_net/pi-usage-bars 0.4.0 → 0.4.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/CHANGELOG.md +103 -77
- package/LICENSE +21 -21
- package/README.md +127 -126
- package/docs/releasing.md +84 -106
- package/extensions/usage-bars/core.ts +1274 -1240
- package/extensions/usage-bars/index.ts +665 -656
- package/package.json +66 -67
- package/docs/financial-metrics-plan.md +0 -75
package/package.json
CHANGED
|
@@ -1,67 +1,66 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@hk_net/pi-usage-bars",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"description": "Quota, balance, and spend indicators for current Pi providers",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"pi-package",
|
|
7
|
-
"pi",
|
|
8
|
-
"extension",
|
|
9
|
-
"usage",
|
|
10
|
-
"codex",
|
|
11
|
-
"anthropic",
|
|
12
|
-
"zai",
|
|
13
|
-
"kimi",
|
|
14
|
-
"minimax",
|
|
15
|
-
"openrouter",
|
|
16
|
-
"deepseek",
|
|
17
|
-
"moonshot"
|
|
18
|
-
],
|
|
19
|
-
"license": "MIT",
|
|
20
|
-
"repository": {
|
|
21
|
-
"type": "git",
|
|
22
|
-
"url": "git+https://github.com/hknet/pi-usage-bars.git"
|
|
23
|
-
},
|
|
24
|
-
"homepage": "https://github.com/hknet/pi-usage-bars#readme",
|
|
25
|
-
"bugs": {
|
|
26
|
-
"url": "https://github.com/hknet/pi-usage-bars/issues"
|
|
27
|
-
},
|
|
28
|
-
"publishConfig": {
|
|
29
|
-
"access": "public",
|
|
30
|
-
"provenance": true
|
|
31
|
-
},
|
|
32
|
-
"type": "module",
|
|
33
|
-
"files": [
|
|
34
|
-
"extensions",
|
|
35
|
-
"docs",
|
|
36
|
-
"README.md",
|
|
37
|
-
"CHANGELOG.md",
|
|
38
|
-
"LICENSE"
|
|
39
|
-
],
|
|
40
|
-
"scripts": {
|
|
41
|
-
"test": "bun test tests",
|
|
42
|
-
"typecheck": "tsc --noEmit",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"@earendil-works/pi-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"@earendil-works/pi-
|
|
56
|
-
"@
|
|
57
|
-
"@types/
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@hk_net/pi-usage-bars",
|
|
3
|
+
"version": "0.4.2",
|
|
4
|
+
"description": "Quota, balance, and spend indicators for current Pi providers",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package",
|
|
7
|
+
"pi",
|
|
8
|
+
"extension",
|
|
9
|
+
"usage",
|
|
10
|
+
"codex",
|
|
11
|
+
"anthropic",
|
|
12
|
+
"zai",
|
|
13
|
+
"kimi",
|
|
14
|
+
"minimax",
|
|
15
|
+
"openrouter",
|
|
16
|
+
"deepseek",
|
|
17
|
+
"moonshot"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/hknet/pi-usage-bars.git"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/hknet/pi-usage-bars#readme",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/hknet/pi-usage-bars/issues"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public",
|
|
30
|
+
"provenance": true
|
|
31
|
+
},
|
|
32
|
+
"type": "module",
|
|
33
|
+
"files": [
|
|
34
|
+
"extensions",
|
|
35
|
+
"docs",
|
|
36
|
+
"README.md",
|
|
37
|
+
"CHANGELOG.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"test": "bun test tests",
|
|
42
|
+
"typecheck": "tsc --noEmit",
|
|
43
|
+
"check": "npm run typecheck && npm test",
|
|
44
|
+
"prepublishOnly": "npm run check"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=22.19.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@earendil-works/pi-coding-agent": ">=0.81.1",
|
|
51
|
+
"@earendil-works/pi-tui": ">=0.81.1"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@earendil-works/pi-coding-agent": "0.84.1",
|
|
55
|
+
"@earendil-works/pi-tui": "0.84.1",
|
|
56
|
+
"@types/bun": "1.3.14",
|
|
57
|
+
"@types/node": "24.13.3",
|
|
58
|
+
"typescript": "5.9.3"
|
|
59
|
+
},
|
|
60
|
+
"pi": {
|
|
61
|
+
"extensions": [
|
|
62
|
+
"./extensions/usage-bars/index.ts"
|
|
63
|
+
],
|
|
64
|
+
"image": "https://raw.githubusercontent.com/hknet/pi-usage-bars/main/assets/usage-command.png"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# Financial metrics plan
|
|
2
|
-
|
|
3
|
-
## Goal
|
|
4
|
-
|
|
5
|
-
Add an optional account-value view without treating balances and spend as subscription quota. Quota usage increases toward exhaustion; a balance decreases toward exhaustion; spend may be meaningful only relative to a budget. Those metrics must retain distinct labels and color rules.
|
|
6
|
-
|
|
7
|
-
## Normalized model
|
|
8
|
-
|
|
9
|
-
A future core revision should replace the two fixed quota fields with a list of typed metrics:
|
|
10
|
-
|
|
11
|
-
```ts
|
|
12
|
-
type UsageMetric =
|
|
13
|
-
| {
|
|
14
|
-
kind: "quota";
|
|
15
|
-
id: string;
|
|
16
|
-
label: string;
|
|
17
|
-
usedPercent: number;
|
|
18
|
-
resetsAt?: string;
|
|
19
|
-
}
|
|
20
|
-
| {
|
|
21
|
-
kind: "money";
|
|
22
|
-
id: string;
|
|
23
|
-
label: string;
|
|
24
|
-
currency: string;
|
|
25
|
-
balance?: number;
|
|
26
|
-
spent?: number;
|
|
27
|
-
limit?: number;
|
|
28
|
-
period?: "day" | "week" | "month" | "lifetime";
|
|
29
|
-
resetsAt?: string;
|
|
30
|
-
};
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
Provider fetchers should return normalized metrics. Rendering, not provider parsing, decides which metrics appear in the footer or `/usage` dialog.
|
|
34
|
-
|
|
35
|
-
## View behavior
|
|
36
|
-
|
|
37
|
-
The initial OpenRouter implementation displays both balance and spend in `/usage`. The footer prefers the balance and current-month spend, while a configured per-key limit remains the primary bar. A later persistent view setting may provide:
|
|
38
|
-
|
|
39
|
-
- `auto`: prefer quota windows; otherwise show a financial summary.
|
|
40
|
-
- `balance`: show remaining prepaid/credit balance.
|
|
41
|
-
- `spent`: show spend and a percentage only when a real limit or budget exists.
|
|
42
|
-
- `off`: retain quota-only behavior.
|
|
43
|
-
|
|
44
|
-
No environment variable or config key is reserved for that future view selector yet.
|
|
45
|
-
|
|
46
|
-
Color semantics:
|
|
47
|
-
|
|
48
|
-
- quota `usedPercent`: high is bad;
|
|
49
|
-
- balance: low remaining balance is bad only when a known starting balance or warning threshold exists;
|
|
50
|
-
- spend/limit: high is bad;
|
|
51
|
-
- unconstrained spend and raw balance: neutral colors, never a manufactured percentage.
|
|
52
|
-
|
|
53
|
-
## Provider rollout
|
|
54
|
-
|
|
55
|
-
1. **OpenRouter — implemented in 0.4.0**
|
|
56
|
-
- `GET /api/v1/credits`: purchased credits, total usage, derived balance.
|
|
57
|
-
- `GET /api/v1/key`: configured key limit and daily/weekly/monthly spend where supplied.
|
|
58
|
-
- Uses only the API key resolved through Pi's provider registry.
|
|
59
|
-
2. **Balance providers**
|
|
60
|
-
- DeepSeek and Moonshot/Kimi API prepaid balances are implemented in 0.4.0 using their official key-authenticated endpoints.
|
|
61
|
-
- Mistral balance or monthly-plan data when available through an API credential.
|
|
62
|
-
- MiniMax purchased Credits have a limited provider-specific implementation: when a first-party key-authenticated quota response includes `points_balance` or `credits_balance`, it is rendered neutrally. In current MiniMax deployments, the dedicated `/backend/account/token_plan_credit` endpoint requires browser-cookie authentication and does not accept the Subscription Key, so it remains out of scope. API status `2062` is rendered as a neutral “No active Token Plan” account state and never converted into a quota percentage.
|
|
63
|
-
3. **Spend providers**
|
|
64
|
-
- OpenAI organization spend requires an Admin API key and therefore should appear only when Pi can resolve an appropriate credential.
|
|
65
|
-
- AWS Bedrock spend requires explicit Cost Explorer permissions and should remain a separate opt-in integration.
|
|
66
|
-
|
|
67
|
-
Browser cookies and direct reads of Pi's credential files remain out of scope.
|
|
68
|
-
|
|
69
|
-
## Migration steps
|
|
70
|
-
|
|
71
|
-
1. Introduce `UsageMetric` alongside the existing `session`/`weekly` compatibility fields.
|
|
72
|
-
2. Convert quota fetchers and both renderers to metric lists.
|
|
73
|
-
3. Add persistent view selection; neutral financial formatting is already covered by OpenRouter tests.
|
|
74
|
-
4. Add further key-authenticated financial providers beyond OpenRouter, DeepSeek, and Moonshot.
|
|
75
|
-
5. Remove compatibility fields only in a documented major release.
|