( headers: globalThis.Headers, )
| 452 | } |
| 453 | |
| 454 | export function extractQuotaStatusFromHeaders( |
| 455 | headers: globalThis.Headers, |
| 456 | ): void { |
| 457 | // Check if we need to process rate limits |
| 458 | const isSubscriber = isClaudeAISubscriber() |
| 459 | |
| 460 | if (!shouldProcessRateLimits(isSubscriber)) { |
| 461 | // If we have any rate limit state, clear it |
| 462 | rawUtilization = {} |
| 463 | if (currentLimits.status !== 'allowed' || currentLimits.resetsAt) { |
| 464 | const defaultLimits: ClaudeAILimits = { |
| 465 | status: 'allowed', |
| 466 | unifiedRateLimitFallbackAvailable: false, |
| 467 | isUsingOverage: false, |
| 468 | } |
| 469 | emitStatusChange(defaultLimits) |
| 470 | } |
| 471 | return |
| 472 | } |
| 473 | |
| 474 | // Process headers (applies mocks from /mock-limits command if active) |
| 475 | const headersToUse = processRateLimitHeaders(headers) |
| 476 | rawUtilization = extractRawUtilization(headersToUse) |
| 477 | const newLimits = computeNewLimitsFromHeaders(headersToUse) |
| 478 | |
| 479 | // Cache extra usage status (persists across sessions) |
| 480 | cacheExtraUsageDisabledReason(headersToUse) |
| 481 | |
| 482 | if (!isEqual(currentLimits, newLimits)) { |
| 483 | emitStatusChange(newLimits) |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | export function extractQuotaStatusFromError(error: APIError): void { |
| 488 | if ( |
no test coverage detected