@ravshansbox/pi-quota 0.10.2 → 0.10.4
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/index.ts +21 -20
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -88,13 +88,12 @@ function clampPercent(value: number): number {
|
|
|
88
88
|
|
|
89
89
|
function parseCreditExpiry(value: string | number | undefined): Date | null {
|
|
90
90
|
if (value === undefined || value === null) return null;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const date = /^\d+$/.test(text) ? new Date(Number(text) * 1000) : new Date(text);
|
|
91
|
+
const text = String(value).trim();
|
|
92
|
+
const numeric = /^\d+(\.\d+)?$/.test(text) ? Number(text) : null;
|
|
93
|
+
const date =
|
|
94
|
+
numeric === null
|
|
95
|
+
? new Date(text)
|
|
96
|
+
: new Date(numeric > 10_000_000_000 ? numeric : numeric * 1000);
|
|
98
97
|
return Number.isNaN(date.getTime()) ? null : date;
|
|
99
98
|
}
|
|
100
99
|
|
|
@@ -197,7 +196,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
197
196
|
let anthropicPingTimer: ReturnType<typeof setTimeout> | null = null;
|
|
198
197
|
let ctxRef: ExtensionContext | null = null;
|
|
199
198
|
let codexRedeemAttempted = false;
|
|
200
|
-
let
|
|
199
|
+
let cycle: Promise<void> | null = null;
|
|
201
200
|
|
|
202
201
|
function notifyRefreshOnce(provider: string, message: string) {
|
|
203
202
|
if (refreshNotified.has(provider)) return;
|
|
@@ -618,17 +617,19 @@ export default function (pi: ExtensionAPI) {
|
|
|
618
617
|
}
|
|
619
618
|
|
|
620
619
|
async function runCycle(includeAnthropic: boolean) {
|
|
621
|
-
if (
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
620
|
+
if (cycle) return;
|
|
621
|
+
cycle = (async () => {
|
|
622
|
+
try {
|
|
623
|
+
await pollQuotaStatus(includeAnthropic);
|
|
624
|
+
await tryAutoRedeemCodexReset();
|
|
625
|
+
updateStatus();
|
|
626
|
+
} catch (error) {
|
|
627
|
+
await logError('Run cycle error:', error);
|
|
628
|
+
} finally {
|
|
629
|
+
cycle = null;
|
|
630
|
+
}
|
|
631
|
+
})();
|
|
632
|
+
await cycle;
|
|
632
633
|
}
|
|
633
634
|
|
|
634
635
|
function scheduleCheck() {
|
|
@@ -655,7 +656,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
655
656
|
ctxRef = ctx;
|
|
656
657
|
codexRedeemAttempted = false;
|
|
657
658
|
|
|
658
|
-
void runCycle(true);
|
|
659
|
+
void (cycle ?? Promise.resolve()).then(() => runCycle(true));
|
|
659
660
|
scheduleCheck();
|
|
660
661
|
});
|
|
661
662
|
|