@narumitw/pi-usage 0.59.0 β†’ 0.60.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/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
  [![npm](https://img.shields.io/npm/v/@narumitw/pi-usage)](https://www.npmjs.com/package/@narumitw/pi-usage) [![Pi extension](https://img.shields.io/badge/Pi-extension-blue)](https://pi.dev) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](./LICENSE)
4
4
 
5
5
  Inspect usage and DeepSeek API balance for Pi's active provider account, query other configured providers, and toggle Fast mode for supported OpenAI Codex models.
6
-
7
6
  The extension keeps each provider's native quota, allowance, and spending semantics instead of treating unlike values as equivalent.
8
7
  xAI OAuth subscription reporting follows the reviewed Grok Build contract and runs only after an explicit `/usage` action.
9
8
 
@@ -17,7 +16,7 @@ xAI OAuth subscription reporting follows the reviewed Grok Build contract and ru
17
16
  - Reports GitHub Copilot allowances and OpenRouter per-key limits and spending windows.
18
17
  - Reports exact DeepSeek API balances with separate CNY and USD values.
19
18
  - Reports OpenCode Go plan windows and Z.AI Coding Plan quotas.
20
- - Reports Fireworks rated API spend for the last 30 days with per-series subtotals.
19
+ - Reports Fireworks rated API spend for the last 30 days with per-series subtotals and account selection.
21
20
  - Reports Vercel AI Gateway credit balance and lifetime spend.
22
21
  - Reports Baseten organization Model APIs spend after credits for the last 30 days.
23
22
  - Reports xAI OAuth subscription allowances and credits.
@@ -57,6 +56,7 @@ The package declares `dist/index.ts`, so an unbuilt local checkout must run the
57
56
  ## πŸš€ Quick start
58
57
 
59
58
  Run `/usage` in TUI or RPC mode to inspect the active provider, refresh its usage, or choose another configured provider.
59
+ When a provider exposes several billing targets, `/usage` asks for one target before querying usage.
60
60
  Run `/fast` to toggle Fast mode for a supported active Codex model.
61
61
 
62
62
  ## πŸ’¬ Commands
@@ -85,6 +85,21 @@ Escape returns from provider selection or closes the root menu.
85
85
  Print and JSON modes reject `/usage` because they cannot host the interactive flow.
86
86
  The extension owns the cancellable live-query progress view because it streams provider work and supports in-flight abort.
87
87
 
88
+ ### Provider targets
89
+
90
+ A target is the provider-owned account, organization, project, team, or workspace used for one usage query.
91
+ Providers without target discovery query immediately, and a single returned target is selected automatically without writing settings.
92
+ When several targets are available, `/usage` remembers an explicit selection by provider and reuses it only while it remains in a fresh listing.
93
+ A missing remembered target returns **Selection required** instead of querying another target silently.
94
+ The current provider then offers **Select <target>…**, while a ready current or individually viewed provider offers **Change <target>…**.
95
+
96
+ Selecting another provider may open one Pi target prompt after that provider is queried lazily.
97
+ Cancelling the prompt changes nothing.
98
+ Auth and target membership are revalidated before an explicit selection is saved, then both are resolved again before billing is queried.
99
+ **View all configured providers…** never opens nested target prompts: unresolved providers remain visible with guidance to view them individually.
100
+ Background status refresh also stays non-interactive and shows `selection required` until `/usage` completes the choice.
101
+ Fireworks accounts are the first implementation of this provider-neutral flow.
102
+
88
103
  For the current OpenAI Codex provider, **Redeem usage limit reset…** first checks fresh earned-reset details.
89
104
  When details are available, you select a reset and review its exact effect before confirmation.
90
105
  **No, go back** is the safe default and cancellation before confirmation sends no mutation.
@@ -94,7 +109,7 @@ Successful, already-completed, not-needed, and no-credit outcomes are reported s
94
109
 
95
110
  ## βš™οΈ Settings
96
111
 
97
- Choose **Settings** in `/usage` to edit Codex Fast mode, the Codex reset countdown, and the Fireworks account selector through Pi's settings-list interaction in TUI mode.
112
+ Choose **Settings** in `/usage` to edit Codex Fast mode and the Codex reset countdown through Pi's settings-list interaction in TUI mode.
98
113
  RPC mode reports the active manual settings path instead of opening terminal UI.
99
114
 
100
115
  These preferences live in `pi-usage.json` under Pi's user agent directory, normally `~/.pi/agent/pi-usage.json`.
@@ -105,24 +120,13 @@ Malformed or invalid files remain untouched.
105
120
  A failed save restores the prior displayed and effective value, while shutdown waits for queued writes.
106
121
  Separate Pi processes are not mutually locked.
107
122
 
108
- ### Fireworks account
109
-
110
- A Fireworks key that can see one account needs no setting.
111
- For a key that can see several accounts, choose **Fireworks account** in the TUI Settings screen, or set the exact visible account slug in `pi-usage.json` and run `/reload`:
112
-
113
- ```json
114
- {
115
- "fireworksAccountId": "acme"
116
- }
117
- ```
118
-
119
- The `fireworksAccountId` setting is validated as a URL-safe account slug and then checked against the official account listing before billing data is requested.
120
- Submit a blank value from the TUI input, or remove the JSON field and run `/reload`, to restore single-account auto-selection.
123
+ Target selections are stored only as IDs in the provider-neutral `selectedTargets` object in this file and are managed through `/usage`, not the Settings screen.
124
+ The former `fireworksAccountId` field remains read-compatible: it supplies `selectedTargets.fireworks` in memory only when the generic value is absent.
125
+ A successful explicit Fireworks account selection writes the generic field and removes the legacy field atomically; ordinary reads do not rewrite the file.
121
126
 
122
127
  ### Codex Fast mode
123
128
 
124
129
  Run `/fast` without arguments to toggle Fast for the active supported Codex model, or use **Turn Fast mode on/off** in `/usage`.
125
-
126
130
  Fast is about 1.5Γ— faster and uses more of your plan allowance.
127
131
  The `codexFastMode` preference defaults to Off.
128
132
 
@@ -138,7 +142,6 @@ Repair or remove an invalid file, then run `/reload` before trying the toggle ag
138
142
  ### Codex statusline reset countdown
139
143
 
140
144
  The `codexStatusResetCountdown` preference defaults to `true`. It replaces the window labels with the time remaining until each returned limit resets.
141
-
142
145
  Turn **Codex reset countdown** Off in the TUI Settings screen, or set it to `false` in `pi-usage.json` and run `/reload`, to restore the legacy `5h` and `wk` labels:
143
146
 
144
147
  ```json
@@ -282,7 +285,8 @@ DeepSeek Harness `cd5ef8148158c3a752a658978873241fdf8e2bbc` reports only per-req
282
285
  - Statusline example: `fireworks USD 12.345678901`
283
286
 
284
287
  The extension queries the fixed endpoints only when the selected model origin is `https://api.fireworks.ai` and any resolved-auth origin override, when present, has the same official origin.
285
- The account slug is discovered through the documented account listing; a key that can see several accounts must set `fireworksAccountId` in `pi-usage.json` to one of the listed account slugs, and the slug must remain visible to the key.
288
+ The account slug is discovered through the documented account listing.
289
+ One visible account is selected automatically; several visible accounts use the remembered selection or ask through `/usage`, and a disappeared selection returns **Selection required** without a billing request.
286
290
  Monetary `units` and `nanos` values are summed exactly with integer arithmetic and stay exact through display.
287
291
  Fireworks does not expose credit balance, spend caps, per-window quota, or reset times through its API, so `pi-usage` does not claim those Fireworks capabilities; the web console remains the authoritative balance source.
288
292
  Rated line items may differ from the final invoice once credits or adjustments are applied.
@@ -374,9 +378,9 @@ xAI identity and billing requests occur only after an explicit current, configur
374
378
 
375
379
  - Provider ID: `zai` and `zai-coding-cn`
376
380
  - Semantics: GLM Coding Plan quota windowsβ€”the rolling 5-hour and weekly plan-usage windows plus the monthly MCP allowance
377
- - Source: the undocumented `GET {origin}/api/monitor/usage/quota/limit` endpoint also used by Z.AI's official coding plugin
381
+ - Source: the undocumented `GET {origin}/api/monitor/usage/quota/limit` endpoint also used by Z.AI's official coding plugin, plus the undocumented `GET {origin}/api/biz/subscription/list` plan endpoint
378
382
  - Allowed origins: the model base URL must resolve to `https://api.z.ai` or `https://open.bigmodel.cn`
379
- - Displayed data: explicit used and remaining values, reset times, provider-reported per-tool MCP details, and the reported plan level
383
+ - Displayed data: explicit used and remaining values, reset times, provider-reported per-tool MCP details, and the plan name with its renewal date
380
384
  - Percentage-only windows remain percent-based
381
385
  - Statusline: publishes remaining plan percentages such as `zai 87% 5h 76% wk`; monthly MCP details remain available through `/usage`
382
386
 
@@ -385,6 +389,7 @@ The extension classifies both forms by the provider's window unit and does not l
385
389
  The quota monitor expects a raw API key without a `Bearer` prefix.
386
390
  The extension removes that prefix from resolved authorization before sending it to the monitor endpoint.
387
391
  Fingerprinting and redaction keep using the original resolved credential.
392
+ The plan endpoint only contributes the plan name and renewal date; when it is unavailable or fails, the quota windows remain reported and the plan note falls back to the quota response's plan level.
388
393
  Only the official `api.z.ai` and `open.bigmodel.cn` origins are queried; other origins fail before sending the credential.
389
394
 
390
395
  ## 🧭 Current and configured accounts
@@ -392,8 +397,8 @@ Only the official `api.z.ai` and `open.bigmodel.cn` origins are queried; other o
392
397
  `Current` identifies the provider and credential used by Pi's selected model.
393
398
  `Configured` identifies runtime auth for another supported provider, not an active provider.
394
399
 
395
- The extension does not enumerate multiple accounts inside one provider and does not switch accounts.
396
- Account selection remains owned by Pi or an account-management extension.
400
+ The extension selects one provider target for one query and never flattens targets into provider rows or aggregates every visible target.
401
+ Provider adapters own target discovery and validation; core owns one-target selection, persistence, cache identity, cancellation, and UI.
397
402
  A compatible credential owner may offer the verified active named account through the versioned process-local protocol without exposing its account label or storage.
398
403
  Without such an owner, `pi-usage` retains its standalone Pi `auth.json` behavior.
399
404
  An older or incompatible owner degrades to the existing authentication-unavailable result when the stored login does not match runtime auth.
@@ -459,7 +464,7 @@ An absent or incompatible peer preserves standalone fallback and fail-closed mis
459
464
  - Credentials resolved for custom provider base URLs are never forwarded to the providers' official usage endpoints; effective auth origin validation requires Pi 0.81.0 or newer.
460
465
  - Provider reports are snapshots and may themselves be delayed by the provider.
461
466
  - DeepSeek reports current API balance only; it does not expose historical usage, quota windows, reset times, or account-wide token totals through the balance endpoint.
462
- - Fireworks reports rated 30-day spend only; credit balance and spend caps are visible only in the Fireworks web console, and keys that can see several accounts must set `fireworksAccountId` in `pi-usage.json`.
467
+ - Fireworks reports rated 30-day spend only; credit balance and spend caps are visible only in the Fireworks web console, and `/usage` must select one visible account before querying a multi-account key.
463
468
  - Moonshot AI reports current API balance only; it does not expose historical spend, aggregate token usage, quota windows, or reset times through the balance endpoint.
464
469
  - Vercel AI Gateway reports current team credits and lifetime spend only; Custom Reporting and request-rate counters are not queried.
465
470
  - MiniMax Token Plan field semantics have changed over time; contradictory counts and percentages are reported as unavailable rather than guessed.
@@ -486,6 +491,7 @@ packages/pi-usage/
486
491
  β”‚ β”œβ”€β”€ codex-fast-runtime.ts # Fast command, persistence lifecycle, and request hooks
487
492
  β”‚ β”œβ”€β”€ settings.ts # Validated user settings and atomic persistence
488
493
  β”‚ β”œβ”€β”€ usage-helpers.ts # Small orchestration helpers
494
+ β”‚ β”œβ”€β”€ usage-targets.ts # Provider-neutral target resolution and safe picker descriptors
489
495
  β”‚ β”œβ”€β”€ query.ts # Runtime auth resolution and bounded provider queries
490
496
  β”‚ β”œβ”€β”€ oauth-credential-source.ts # Ephemeral OAuth candidate collection
491
497
  β”‚ β”œβ”€β”€ codex-resets.ts # Codex reset auth, API contracts, and normalization
@@ -501,7 +507,6 @@ packages/pi-usage/
501
507
  ```
502
508
 
503
509
  `index.ts` is the Pi entrypoint and forwards the default factory from `usage.ts` while retaining the package's named helper exports; other source modules are internal.
504
-
505
510
  The generated runtime is built from the authoritative `src/index.ts` graph and does not import back into `src`.
506
511
 
507
512
  ## πŸ”Ž Keywords