pi-provider-qoder-cn 0.2.16 → 0.2.17

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
@@ -129,6 +129,10 @@ Notes:
129
129
  not reserve space for one it does not have.
130
130
  - Colour is suppressed automatically for a `NO_COLOR` environment, a dumb
131
131
  terminal, and any non-TTY output that is not the interactive UI.
132
+ - The gauge and the `%` column are derived from `used / total`, so they always
133
+ agree with the numbers on the same row. The API's own `percentage` field is a
134
+ 0-1 fraction (94% arrives as `0.94`) and is only used — scaled by 100 — when a
135
+ bucket comes back without numbers.
132
136
  - `Expires never` means the API reported the year-9999 sentinel, i.e. the
133
137
  allowance has no expiry date.
134
138
  - `Note plan quota is prorated` appears after a mid-cycle plan change.
package/dist/index.js CHANGED
@@ -2456,6 +2456,10 @@ function formatPercent(value) {
2456
2456
  if (typeof value !== "number" || !Number.isFinite(value)) return void 0;
2457
2457
  return Math.round(value * 10) / 10;
2458
2458
  }
2459
+ function normalizePercent(value) {
2460
+ if (typeof value !== "number" || !Number.isFinite(value)) return void 0;
2461
+ return value >= 0 && value <= 1 ? value * 100 : value;
2462
+ }
2459
2463
  function formatDailyResetCountdown(now = Date.now()) {
2460
2464
  const diffMs = msUntilBeijingMidnight(now);
2461
2465
  const totalMinutes = Math.max(1, Math.round(diffMs / 6e4));
@@ -2512,11 +2516,8 @@ function renderUsageRows(rows, notes, color) {
2512
2516
  return lines.map((line) => line.replace(/ +$/, ""));
2513
2517
  }
2514
2518
  function bucketRow(label, bucket, danger) {
2515
- const rawPercent = bucket?.percentage;
2516
2519
  const derivedPercent = typeof bucket?.used === "number" && typeof bucket?.total === "number" && bucket.total > 0 ? bucket.used / bucket.total * 100 : void 0;
2517
- const percent = formatPercent(
2518
- typeof rawPercent === "number" && Number.isFinite(rawPercent) ? rawPercent : derivedPercent
2519
- );
2520
+ const percent = formatPercent(derivedPercent ?? normalizePercent(bucket?.percentage));
2520
2521
  return {
2521
2522
  label,
2522
2523
  percent,
@@ -2546,7 +2547,9 @@ function formatQoderUsage(raw, mode, now = Date.now(), options = {}) {
2546
2547
  const org = pickBucket(raw, "orgResourcePackage") ?? pickBucket(raw, "sharedQuota");
2547
2548
  const showOrg = hasBucket(org);
2548
2549
  const orgPercent = typeof org?.used === "number" && typeof org?.cap === "number" && org.cap > 0 ? formatPercent(org.used / org.cap * 100) : void 0;
2549
- const overallPercent = formatPercent(showOrg ? raw?.totalUsagePercentage || orgPercent : raw?.totalUsagePercentage);
2550
+ const overallPercent = formatPercent(
2551
+ showOrg ? normalizePercent(raw?.totalUsagePercentage) || orgPercent : normalizePercent(raw?.totalUsagePercentage)
2552
+ );
2550
2553
  const rows = [{ label: "Overall", percent: overallPercent, tail: "used", danger }];
2551
2554
  if (showUserQuota) rows.push(bucketRow("Plan quota", pickBucket(raw, "userQuota"), danger));
2552
2555
  if (showAddOnQuota) rows.push(bucketRow("Add-on", pickBucket(raw, "addOnQuota"), danger));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-provider-qoder-cn",
3
- "version": "0.2.16",
3
+ "version": "0.2.17",
4
4
  "description": "Pi extension for Qoder CN — PAT/OAuth auth, /qoder-cn.usage quota command, and enterprise VPC endpoint support",
5
5
  "type": "module",
6
6
  "license": "MIT",