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