@ravshansbox/pi-quota 0.10.1 → 0.10.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.
Files changed (2) hide show
  1. package/index.ts +37 -29
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -479,40 +479,48 @@ export default function (pi: ExtensionAPI) {
479
479
  }
480
480
  }
481
481
 
482
+ async function pollAnthropicQuota(auth: AuthFile) {
483
+ try {
484
+ const anthropicAuth = await ensureAnthropicAccess(auth);
485
+ if (!anthropicAuth?.access) return;
486
+ const response = await fetch('https://api.anthropic.com/api/oauth/usage', {
487
+ headers: {
488
+ Authorization: `Bearer ${anthropicAuth.access}`,
489
+ 'anthropic-beta': 'claude-code-20250219,oauth-2025-04-20',
490
+ accept: 'application/json',
491
+ },
492
+ signal: AbortSignal.timeout(requestTimeoutMs),
493
+ });
494
+
495
+ if (!response.ok) {
496
+ logError(`Anthropic usage request failed: ${response.status}`);
497
+ return;
498
+ }
499
+
500
+ const data = (await response.json()) as AnthropicUsageResponse;
501
+ const fiveHour = data.five_hour;
502
+ const sevenDay = data.seven_day;
503
+ updateState({
504
+ provider: 'anthropic',
505
+ fiveHourUsed: fiveHour ? clampPercent(fiveHour.utilization ?? 0) : null,
506
+ fiveHourReset: fiveHour?.resets_at ? new Date(fiveHour.resets_at) : null,
507
+ sevenDayUsed: sevenDay ? clampPercent(sevenDay.utilization ?? 0) : null,
508
+ sevenDayReset: sevenDay?.resets_at ? new Date(sevenDay.resets_at) : null,
509
+ resetsAvailable: 0,
510
+ resetSoonestExpiry: null,
511
+ lastUpdated: new Date(),
512
+ });
513
+ } catch (error) {
514
+ logError('Anthropic poll error:', error);
515
+ }
516
+ }
517
+
482
518
  async function pollQuotaStatus(includeAnthropic: boolean) {
483
519
  try {
484
520
  const auth = await loadAuth();
485
521
  if (!auth) return;
486
522
 
487
- const anthropicAuth = includeAnthropic ? await ensureAnthropicAccess(auth) : undefined;
488
- if (anthropicAuth?.access) {
489
- const response = await fetch('https://api.anthropic.com/api/oauth/usage', {
490
- headers: {
491
- Authorization: `Bearer ${anthropicAuth.access}`,
492
- 'anthropic-beta': 'claude-code-20250219,oauth-2025-04-20',
493
- accept: 'application/json',
494
- },
495
- signal: AbortSignal.timeout(requestTimeoutMs),
496
- });
497
-
498
- if (response.ok) {
499
- const data = (await response.json()) as AnthropicUsageResponse;
500
- const fiveHour = data.five_hour;
501
- const sevenDay = data.seven_day;
502
- updateState({
503
- provider: 'anthropic',
504
- fiveHourUsed: fiveHour ? clampPercent(fiveHour.utilization ?? 0) : null,
505
- fiveHourReset: fiveHour?.resets_at ? new Date(fiveHour.resets_at) : null,
506
- sevenDayUsed: sevenDay ? clampPercent(sevenDay.utilization ?? 0) : null,
507
- sevenDayReset: sevenDay?.resets_at ? new Date(sevenDay.resets_at) : null,
508
- resetsAvailable: 0,
509
- resetSoonestExpiry: null,
510
- lastUpdated: new Date(),
511
- });
512
- } else {
513
- logError(`Anthropic usage request failed: ${response.status}`);
514
- }
515
- }
523
+ if (includeAnthropic) await pollAnthropicQuota(auth);
516
524
 
517
525
  const openaiAuth = await ensureOpenAIAccess(auth);
518
526
  if (openaiAuth?.access) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ravshansbox/pi-quota",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "description": "Anthropic and OpenAI Codex quota status extension for pi",
5
5
  "license": "MIT",
6
6
  "type": "module",