@specode/pi-subscription-usage 1.0.1 → 1.0.2
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/package.json +1 -1
- package/src/display.ts +2 -4
- package/src/providers/kimi.ts +8 -1
package/package.json
CHANGED
package/src/display.ts
CHANGED
|
@@ -45,11 +45,9 @@ export function usageAmount(
|
|
|
45
45
|
: Math.max(0, bucket.limit - opposite);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/** Integer presentation only; keep the original number for semantic decisions. */
|
|
48
49
|
export function formatUsagePercent(value: number): string {
|
|
49
|
-
|
|
50
|
-
return Number.isInteger(hundredths)
|
|
51
|
-
? String(hundredths)
|
|
52
|
-
: hundredths.toFixed(2);
|
|
50
|
+
return String(Math.round(clampPercent(value)));
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
function clampPercent(value: number): number {
|
package/src/providers/kimi.ts
CHANGED
|
@@ -80,7 +80,13 @@ function parseQuota(
|
|
|
80
80
|
let used = asFiniteNumber(record.used);
|
|
81
81
|
let remaining = asFiniteNumber(record.remaining);
|
|
82
82
|
if (limit === undefined || limit <= 0) return undefined;
|
|
83
|
-
//
|
|
83
|
+
// Missing fields can be derived; present-but-invalid data must not become zero.
|
|
84
|
+
if (
|
|
85
|
+
(record.used !== undefined && used === undefined) ||
|
|
86
|
+
(record.remaining !== undefined && remaining === undefined)
|
|
87
|
+
)
|
|
88
|
+
return undefined;
|
|
89
|
+
// Observed: used=limit=100 with remaining omitted. The cause is undocumented.
|
|
84
90
|
if (used === undefined && remaining !== undefined) {
|
|
85
91
|
used = Math.max(0, limit - remaining);
|
|
86
92
|
}
|
|
@@ -137,6 +143,7 @@ function asObject(value: unknown): Record<string, unknown> | undefined {
|
|
|
137
143
|
|
|
138
144
|
function asFiniteNumber(value: unknown): number | undefined {
|
|
139
145
|
if (typeof value !== "number" && typeof value !== "string") return undefined;
|
|
146
|
+
if (typeof value === "string" && !value.trim()) return undefined;
|
|
140
147
|
const parsed = Number(value);
|
|
141
148
|
return Number.isFinite(parsed) ? parsed : undefined;
|
|
142
149
|
}
|