| 184 | |
| 185 | // Helper to update retry-after based on current state |
| 186 | function updateRetryAfter(): void { |
| 187 | const status = mockHeaders['anthropic-ratelimit-unified-status'] |
| 188 | const overageStatus = |
| 189 | mockHeaders['anthropic-ratelimit-unified-overage-status'] |
| 190 | const reset = mockHeaders['anthropic-ratelimit-unified-reset'] |
| 191 | |
| 192 | if ( |
| 193 | status === 'rejected' && |
| 194 | (!overageStatus || overageStatus === 'rejected') && |
| 195 | reset |
| 196 | ) { |
| 197 | // Calculate seconds until reset |
| 198 | const resetTimestamp = Number(reset) |
| 199 | const secondsUntilReset = Math.max( |
| 200 | 0, |
| 201 | resetTimestamp - Math.floor(Date.now() / 1000), |
| 202 | ) |
| 203 | mockHeaders['retry-after'] = String(secondsUntilReset) |
| 204 | } else { |
| 205 | delete mockHeaders['retry-after'] |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | // Update the representative claim based on exceeded limits |
| 210 | function updateRepresentativeClaim(): void { |