@ravshansbox/pi-quota 0.10.8 → 0.10.10
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 +12 -11
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -294,26 +294,27 @@ export default function (pi: ExtensionAPI) {
|
|
|
294
294
|
child.on('error', (error: unknown) => {
|
|
295
295
|
void logError(`Reset ping failed for ${provider}:`, error);
|
|
296
296
|
});
|
|
297
|
-
if (provider === 'anthropic')
|
|
297
|
+
if (provider === 'anthropic') {
|
|
298
|
+
child.on('exit', () => {
|
|
299
|
+
void (cycle ?? Promise.resolve()).then(() => (ctxRef ? runCycle(true) : undefined));
|
|
300
|
+
});
|
|
301
|
+
}
|
|
298
302
|
|
|
299
303
|
child.unref();
|
|
300
304
|
}
|
|
301
305
|
|
|
302
|
-
function scheduleAnthropicPing(state: QuotaState) {
|
|
306
|
+
function scheduleAnthropicPing(state: QuotaState, after = Date.now()) {
|
|
303
307
|
if (anthropicPingTimer) clearTimeout(anthropicPingTimer);
|
|
304
308
|
anthropicPingTimer = null;
|
|
305
|
-
const now = Date.now();
|
|
306
309
|
const resets = [state.fiveHourReset, state.sevenDayReset]
|
|
307
310
|
.map((reset) => reset?.getTime())
|
|
308
|
-
.filter((time): time is number => time !== undefined && time >
|
|
311
|
+
.filter((time): time is number => time !== undefined && time > after);
|
|
309
312
|
if (resets.length === 0) return;
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
Math.min(...resets) - now,
|
|
316
|
-
);
|
|
313
|
+
const next = Math.min(...resets);
|
|
314
|
+
anthropicPingTimer = setTimeout(() => {
|
|
315
|
+
pingProviderOnReset('anthropic');
|
|
316
|
+
scheduleAnthropicPing(state, next);
|
|
317
|
+
}, next - Date.now());
|
|
317
318
|
}
|
|
318
319
|
|
|
319
320
|
function updateState(parsed: QuotaState) {
|