@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.
Files changed (2) hide show
  1. package/index.ts +12 -11
  2. 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') child.on('exit', () => void runCycle(true));
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 > now);
311
+ .filter((time): time is number => time !== undefined && time > after);
309
312
  if (resets.length === 0) return;
310
- anthropicPingTimer = setTimeout(
311
- () => {
312
- pingProviderOnReset('anthropic');
313
- scheduleAnthropicPing(state);
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ravshansbox/pi-quota",
3
- "version": "0.10.8",
3
+ "version": "0.10.10",
4
4
  "description": "Anthropic and OpenAI Codex quota status extension for pi",
5
5
  "license": "MIT",
6
6
  "type": "module",