(limits: ClaudeAILimits)
| 197 | } |
| 198 | |
| 199 | function getEarlyWarningText(limits: ClaudeAILimits): string | null { |
| 200 | let limitName: string | null = null |
| 201 | switch (limits.rateLimitType) { |
| 202 | case 'seven_day': |
| 203 | limitName = 'weekly limit' |
| 204 | break |
| 205 | case 'five_hour': |
| 206 | limitName = 'session limit' |
| 207 | break |
| 208 | case 'seven_day_opus': |
| 209 | limitName = 'Opus limit' |
| 210 | break |
| 211 | case 'seven_day_sonnet': |
| 212 | limitName = 'Sonnet limit' |
| 213 | break |
| 214 | case 'overage': |
| 215 | limitName = 'extra usage' |
| 216 | break |
| 217 | case undefined: |
| 218 | return null |
| 219 | } |
| 220 | |
| 221 | // utilization and resetsAt should be defined since early warning is calculated with them |
| 222 | const used = limits.utilization |
| 223 | ? Math.floor(limits.utilization * 100) |
| 224 | : undefined |
| 225 | const resetTime = limits.resetsAt |
| 226 | ? formatResetTime(limits.resetsAt, true) |
| 227 | : undefined |
| 228 | |
| 229 | // Get upsell command based on subscription type and limit type |
| 230 | const upsell = getWarningUpsellText(limits.rateLimitType) |
| 231 | |
| 232 | if (used && resetTime) { |
| 233 | const base = `You've used ${used}% of your ${limitName} · resets ${resetTime}` |
| 234 | return upsell ? `${base} · ${upsell}` : base |
| 235 | } |
| 236 | |
| 237 | if (used) { |
| 238 | const base = `You've used ${used}% of your ${limitName}` |
| 239 | return upsell ? `${base} · ${upsell}` : base |
| 240 | } |
| 241 | |
| 242 | if (limits.rateLimitType === 'overage') { |
| 243 | // For the "Approaching <x>" verbiage, "extra usage limit" makes more sense than "extra usage" |
| 244 | limitName += ' limit' |
| 245 | } |
| 246 | |
| 247 | if (resetTime) { |
| 248 | const base = `Approaching ${limitName} · resets ${resetTime}` |
| 249 | return upsell ? `${base} · ${upsell}` : base |
| 250 | } |
| 251 | |
| 252 | const base = `Approaching ${limitName}` |
| 253 | return upsell ? `${base} · ${upsell}` : base |
| 254 | } |
| 255 | |
| 256 | /** |
no test coverage detected