paseo-plugin-account-switcher 0.3.3 → 0.4.0

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.
@@ -66,6 +66,9 @@ OAuth credentials; this module performs no custom refresh or forced refresh. The
66
66
  quota response account ID is checked against a known profile identity. If an older
67
67
  response omits that ID and credentials rotated during the call, it cannot replace
68
68
  the previous snapshot. The process is terminated on success, failure or cancellation.
69
+ Usage-based workspace plans (for example `enterprise_cbp_usage_based`) report no
70
+ `primary` or `secondary` window; their bucket's `individualLimit` monthly credit
71
+ allowance becomes a window with `usedPercent = 100 - remainingPercent`.
69
72
 
70
73
  **Claude:** on macOS the exact Keychain service/account is preferred. A missing
71
74
  or inaccessible item falls back only to `.credentials.json` in the supplied home,
@@ -81,6 +84,10 @@ uses its effective credential home, including an empty override for the default.
81
84
  There is no global profile search. Only the OAuth usage GET endpoint is requested; no
82
85
  token refresh or inference request is sent. Before HTTP, the actual selected token
83
86
  must still match the credential hash used to verify a known account identity.
87
+ Enterprise seats return every plan window as `null` and report an enabled
88
+ `extra_usage` monthly spend allowance in minor currency units. It becomes a
89
+ "Monthly spend" window from `utilization`; when no plan window has a value, the
90
+ empty plan windows are dropped.
84
91
 
85
92
  Tests use synthetic credentials and a synthetic stdio CLI. They establish local
86
93
  protocol, parsing, isolation, scheduling and cache behavior. They do not establish
@@ -11,6 +11,11 @@ function date(value: unknown, seconds = false): string | null {
11
11
  const time = seconds ? (value as number) * 1000 : Date.parse(value as string);
12
12
  return Number.isFinite(time) && Math.abs(time) <= 8.64e15 ? new Date(time).toISOString() : null;
13
13
  }
14
+ function amount(value: unknown): number | null {
15
+ const parsed = typeof value === "string" && value.trim() ? Number(value) : NaN;
16
+ return Number.isFinite(parsed) && parsed >= 0 ? parsed : null;
17
+ }
18
+ const credits = (value: number) => Math.round(value).toLocaleString("en-US");
14
19
  function durationLabel(minutes: number | null, fallback: string): string {
15
20
  if (minutes === null) return fallback;
16
21
  if (minutes % 1440 === 0) return `${minutes / 1440} days`;
@@ -34,6 +39,15 @@ export function parseCodexUsage(payload: unknown): CollectedUsage {
34
39
  const duration = numeric(window.windowDurationMins);
35
40
  windows.push({ id: `${id}:${key}`, label: `${string(bucket.limitName) ?? id} · ${durationLabel(duration, key)}`, usedPercent: numeric(window.usedPercent), windowDurationMins: duration, resetsAt: date(window.resetsAt, true) });
36
41
  }
42
+ // Usage-based workspaces (e.g. enterprise_cbp_usage_based) report a monthly credit allowance instead of windows.
43
+ const spend = object(bucket.individualLimit);
44
+ const remaining = numeric(spend?.remainingPercent);
45
+ if (spend && remaining !== null) {
46
+ const limit = amount(spend.limit);
47
+ const used = amount(spend.used);
48
+ windows.push({ id: `${id}:individual`, label: `${string(bucket.limitName) ?? id} · monthly credits`, usedPercent: 100 - Math.min(100, remaining), windowDurationMins: null, resetsAt: date(spend.resetsAt, true),
49
+ detail: limit !== null && used !== null ? `${credits(Math.max(0, limit - used))} of ${credits(limit)} credits left` : null });
50
+ }
37
51
  }
38
52
  return { identityKey: string(root.accountId), plan, windows };
39
53
  }
@@ -59,5 +73,18 @@ export function parseClaudeUsage(payload: unknown): CollectedUsage {
59
73
  if (!labels.length) continue;
60
74
  windows.push({ id: `weekly_scoped:${index}`, label: `Weekly · ${labels.join(" · ")}`, usedPercent: numeric(row.percent), windowDurationMins: 10080, resetsAt: date(row.resets_at) });
61
75
  }
76
+ // Enterprise seats report a monthly spend allowance; amounts are in minor units of `currency`.
77
+ const extra = object(root.extra_usage);
78
+ const limit = numeric(extra?.monthly_limit);
79
+ const used = numeric(extra?.used_credits);
80
+ if (extra?.is_enabled === true && limit) {
81
+ const scale = 10 ** (numeric(extra.decimal_places) ?? 2);
82
+ const currency = string(extra.currency) ?? "USD";
83
+ const money = (value: number) => { try { return (value / scale).toLocaleString("en-US", { style: "currency", currency }); } catch { return `${(value / scale).toFixed(2)} ${currency}`; } };
84
+ const spend: UsageWindow = { id: "extra_usage", label: "Monthly spend", usedPercent: numeric(extra.utilization) ?? (used === null ? null : used / limit * 100), windowDurationMins: null, resetsAt: null,
85
+ detail: used === null ? null : `${money(Math.max(0, limit - used))} of ${money(limit)} left` };
86
+ // Without any plan limits the empty plan rows are noise; the spend allowance is the only quota.
87
+ return { identityKey: null, plan: null, windows: windows.some((quota) => quota.usedPercent !== null) ? [...windows, spend] : [spend] };
88
+ }
62
89
  return { identityKey: null, plan: null, windows };
63
90
  }
@@ -40,6 +40,8 @@ export type AccountState = z.infer<typeof StateSchema>;
40
40
  export const UsageWindowSchema = z.object({
41
41
  id: z.string(), label: z.string(), usedPercent: z.number().nullable(),
42
42
  windowDurationMins: z.number().nullable(), resetsAt: z.string().nullable(),
43
+ // Provider-reported amounts behind the percentage, such as "3,765 of 5,000 credits left".
44
+ detail: z.string().nullable().optional(),
43
45
  });
44
46
  export type UsageWindow = z.infer<typeof UsageWindowSchema>;
45
47
  export const UsageSnapshotSchema = z.object({