| 23 | } |
| 24 | |
| 25 | function formatCreditsLabel(accountRateLimits: RateLimitSnapshot | null) { |
| 26 | const credits = accountRateLimits?.credits ?? null; |
| 27 | if (!credits?.hasCredits) { |
| 28 | return null; |
| 29 | } |
| 30 | if (credits.unlimited) { |
| 31 | return "Available credits: Unlimited"; |
| 32 | } |
| 33 | const balance = credits.balance?.trim() ?? ""; |
| 34 | if (!balance) { |
| 35 | return null; |
| 36 | } |
| 37 | const intValue = Number.parseInt(balance, 10); |
| 38 | if (Number.isFinite(intValue) && intValue > 0) { |
| 39 | return `Available credits: ${intValue}`; |
| 40 | } |
| 41 | const floatValue = Number.parseFloat(balance); |
| 42 | if (Number.isFinite(floatValue) && floatValue > 0) { |
| 43 | const rounded = Math.round(floatValue); |
| 44 | return rounded > 0 ? `Available credits: ${rounded}` : null; |
| 45 | } |
| 46 | return null; |
| 47 | } |
| 48 | |
| 49 | export function getUsageLabels( |
| 50 | accountRateLimits: RateLimitSnapshot | null, |