@bacnh85/pi-sub 0.1.32 → 0.1.33

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 CHANGED
@@ -4,9 +4,9 @@
4
4
  instead of the misleading aggregate windows (R:100%/5H W:0%/2D). Credit-based
5
5
  upstreams report "Unavailable" session/weekly in the usage text; pi-sub now
6
6
  recognizes that shape and fetches `credits_usd` from the management usage
7
- API. Needs `ROUTER_MGMT_TOKEN` (an `oma_` CLI token or manage-scope key) in
8
- env / `~/.pi/agent/.env.local`; without it, the footer degrades to the clean
9
- endpoint display (no aggregate leak).
7
+ API grant the router key the `manage` scope in the OmniRoute dashboard
8
+ (done), or set `ROUTER_MGMT_TOKEN`. Without it, the footer degrades to the
9
+ clean endpoint display (no aggregate leak).
10
10
  - The plain-retry fallback (drop `?provider=`) now fires only on "No cached
11
11
  usage data" (wrong/unknown slug), not on "Unavailable" windows.
12
12
  - pi-sub now reads `.env.local`/`.env` (cwd then `~/.pi/agent`) for its own
@@ -66,6 +66,12 @@
66
66
 
67
67
  # Changelog
68
68
 
69
+ ## 0.1.33 (2026-08-29)
70
+
71
+ ### Added
72
+
73
+ - `/sub` argument completion offers `refresh`.
74
+
69
75
  ## 0.1.29 (2026-08-15)
70
76
 
71
77
  ### Features
@@ -362,11 +362,13 @@ function routerOrigin(baseUrl: string): string {
362
362
  return baseUrl.replace(/\/v1\/?$/, "");
363
363
  }
364
364
 
365
- /** OmniRoute management token (oma_ CLI token or manage-scope key) from env —
366
- * unlocks /api/usage/<connectionId> which carries the raw USD balance for
367
- * credit-based upstreams (deepseek) that the key-authable endpoints strip. */
368
- function readRouterMgmtToken(): string | undefined {
369
- return process.env.ROUTER_MGMT_TOKEN || process.env.OMNIROUTE_MGMT_TOKEN || undefined;
365
+ /** OmniRoute management credential (manage-scope key or oma_ CLI token) from
366
+ * env optional override. The router key itself works when it holds the
367
+ * `manage` scope (API Keys dashboard), which unlocks
368
+ * /api/usage/<connectionId> carrying the raw USD balance for credit-based
369
+ * upstreams (deepseek) that the key-authable endpoints normalize away. */
370
+ function readRouterMgmtToken(apiKey: string | undefined): string | undefined {
371
+ return process.env.ROUTER_MGMT_TOKEN || process.env.OMNIROUTE_MGMT_TOKEN || apiKey;
370
372
  }
371
373
 
372
374
  /** Parse OmniRoute's `/api/usage/om-usage` plain-text report into windows.
@@ -667,15 +669,15 @@ interface RouterCredits {
667
669
 
668
670
  /** Fetch the raw USD balance for credit-based upstreams (deepseek: `credits_usd`)
669
671
  * via OmniRoute's management usage API. Only called when the key-authable
670
- * om-usage text reports no usable windows — the API-key surface normalizes
671
- * credits to meaningless percentages, so this needs ROUTER_MGMT_TOKEN.
672
- * Uses connection discovery from /api/v1/me/status (key-authable) +
673
- * /api/usage/<id> (management token). */
672
+ * om-usage text reports no usable windows — that surface normalizes credits
673
+ * to meaningless percentages. Needs the router key to hold the `manage`
674
+ * scope (or ROUTER_MGMT_TOKEN as override). Connection discovery comes from
675
+ * /api/v1/me/status (key-authable); the balance from /api/usage/<id>. */
674
676
  async function fetchRouterCredits(provider: string | undefined, w: ReturnType<typeof parseOmniUsageText>): Promise<RouterCredits | undefined> {
675
677
  if (!provider || w.session || w.providerWeekly) return undefined;
676
678
  const cfg = readRouterConfig();
677
679
  const apiKey = readRouterApiKey();
678
- const mgmtToken = readRouterMgmtToken();
680
+ const mgmtToken = readRouterMgmtToken(apiKey);
679
681
  if (!cfg || !apiKey || !mgmtToken) return undefined;
680
682
  const origin = routerOrigin(cfg.baseUrl);
681
683
  try {
@@ -1293,6 +1295,12 @@ export default function (pi: ExtensionAPI) {
1293
1295
 
1294
1296
  pi.registerCommand("sub", {
1295
1297
  description: "Show subscription usage for the current supported model provider (use /sub refresh to force refresh).",
1298
+ getArgumentCompletions: (prefix) => {
1299
+ const items = ["refresh"]
1300
+ .filter((k) => k.startsWith(String(prefix || "").trim().toLowerCase()))
1301
+ .map((k) => ({ value: k, label: k, description: "force refresh" }));
1302
+ return items.length > 0 ? items : null;
1303
+ },
1296
1304
  handler: async (args, ctx) => {
1297
1305
  updateActiveAdapter(ctx, state, ctx.model);
1298
1306
  const command = args.trim().toLowerCase();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bacnh85/pi-sub",
3
- "version": "0.1.32",
3
+ "version": "0.1.33",
4
4
  "description": "Pi extension showing subscription usage for supported model providers.",
5
5
  "type": "module",
6
6
  "license": "MIT",