@cwillam/pi-minimax-usage 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +28 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cwillam/pi-minimax-usage",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Pi extension: live MiniMax Token Plan usage (5h + weekly) in the status bar. Not affiliated with MiniMax Inc.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/index.ts CHANGED
@@ -89,8 +89,11 @@ const state: PollingState = {
89
89
  };
90
90
 
91
91
  function getSettings(): ExtensionSettings["minimaxUsage"] {
92
- // `settings` exists on the runtime context but isn't surfaced in the
93
- // public ExtensionContext type; access via a typed cast.
92
+ // SAFETY: `settings` exists on the runtime context (populated by pi from
93
+ // `~/.pi/agent/settings.json` at session start) but isn't surfaced in the
94
+ // public ExtensionContext type. The double-assertion widens through
95
+ // `unknown` so TypeScript accepts the structural narrowing to a record
96
+ // with an optional `settings` field. Falls through to `undefined` if absent.
94
97
  const raw = (
95
98
  state.ctx as unknown as { settings?: ExtensionSettings } | undefined
96
99
  )?.settings;
@@ -374,25 +377,13 @@ export default function (pi: ExtensionAPI): void {
374
377
 
375
378
  pi.registerCommand(COMMAND_NAME, {
376
379
  description: "MiniMax Token Plan usage: show status, refresh, or help",
377
- handler: async (args: string, cmdCtx: ExtensionCommandContext) => {
378
- const sub = args.trim().split(/\s+/)[0]?.toLowerCase() ?? "";
379
- if (sub === "refresh") {
380
- if (state.activeProviderId !== PROVIDER_ID) {
381
- cmdCtx.ui.notify("MiniMax is not the active provider.", "warning");
382
- return;
383
- }
384
- if (!state.apiKey) {
385
- cmdCtx.ui.notify(
386
- "No API key configured for provider 'minimax'.",
387
- "warning",
388
- );
389
- return;
390
- }
391
- await pollOnce();
392
- render();
393
- cmdCtx.ui.notify(formatSnapshotForNotify(snapshot()), "info");
394
- return;
395
- }
380
+ handler: async (
381
+ args: string | undefined,
382
+ cmdCtx: ExtensionCommandContext,
383
+ ) => {
384
+ // Defensive: pi may invoke with `args === undefined` when no arguments
385
+ // were passed on the command line.
386
+ const sub = (args ?? "").trim().split(/\s+/)[0]?.toLowerCase() ?? "";
396
387
  if (sub === "help" || sub === "--help" || sub === "-h") {
397
388
  cmdCtx.ui.notify(
398
389
  [
@@ -412,6 +403,22 @@ export default function (pi: ExtensionAPI): void {
412
403
  );
413
404
  return;
414
405
  }
406
+ if (sub === "refresh") {
407
+ if (state.activeProviderId !== PROVIDER_ID) {
408
+ cmdCtx.ui.notify("MiniMax is not the active provider.", "warning");
409
+ return;
410
+ }
411
+ if (!state.apiKey) {
412
+ cmdCtx.ui.notify(
413
+ "No API key configured for provider 'minimax'.",
414
+ "warning",
415
+ );
416
+ return;
417
+ }
418
+ await pollOnce();
419
+ render();
420
+ }
421
+ // Always show status (covers both /minimax-usage and /minimax-usage refresh).
415
422
  cmdCtx.ui.notify(formatSnapshotForNotify(snapshot()), "info");
416
423
  },
417
424
  });