()
| 209 | |
| 210 | // Update the representative claim based on exceeded limits |
| 211 | function updateRepresentativeClaim(): void { |
| 212 | if (exceededLimits.length === 0) { |
| 213 | delete mockHeaders['anthropic-ratelimit-unified-representative-claim'] |
| 214 | delete mockHeaders['anthropic-ratelimit-unified-reset'] |
| 215 | delete mockHeaders['retry-after'] |
| 216 | return |
| 217 | } |
| 218 | |
| 219 | // Find the limit with the furthest reset time |
| 220 | const furthest = exceededLimits.reduce((prev, curr) => |
| 221 | curr.resetsAt > prev.resetsAt ? curr : prev, |
| 222 | ) |
| 223 | |
| 224 | // Set the representative claim (appears for both warning and rejected) |
| 225 | mockHeaders['anthropic-ratelimit-unified-representative-claim'] = |
| 226 | furthest.type |
| 227 | mockHeaders['anthropic-ratelimit-unified-reset'] = String(furthest.resetsAt) |
| 228 | |
| 229 | // Add retry-after if rejected and no overage available |
| 230 | if (mockHeaders['anthropic-ratelimit-unified-status'] === 'rejected') { |
| 231 | const overageStatus = |
| 232 | mockHeaders['anthropic-ratelimit-unified-overage-status'] |
| 233 | if (!overageStatus || overageStatus === 'rejected') { |
| 234 | // Calculate seconds until reset |
| 235 | const secondsUntilReset = Math.max( |
| 236 | 0, |
| 237 | furthest.resetsAt - Math.floor(Date.now() / 1000), |
| 238 | ) |
| 239 | mockHeaders['retry-after'] = String(secondsUntilReset) |
| 240 | } else { |
| 241 | // Overage is available, no retry-after |
| 242 | delete mockHeaders['retry-after'] |
| 243 | } |
| 244 | } else { |
| 245 | delete mockHeaders['retry-after'] |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | // Add function to add exceeded limit with custom reset time |
| 250 | export function addExceededLimit( |
no test coverage detected