| 132 | } |
| 133 | |
| 134 | function formatUsage( |
| 135 | tokens: Tokens | undefined, |
| 136 | limit: number | undefined, |
| 137 | cost: number | undefined, |
| 138 | ): string | undefined { |
| 139 | const total = |
| 140 | (tokens?.input ?? 0) + |
| 141 | (tokens?.output ?? 0) + |
| 142 | (tokens?.reasoning ?? 0) + |
| 143 | (tokens?.cache?.read ?? 0) + |
| 144 | (tokens?.cache?.write ?? 0) |
| 145 | |
| 146 | if (total <= 0) { |
| 147 | if (typeof cost === "number" && cost > 0) { |
| 148 | return money.format(cost) |
| 149 | } |
| 150 | return undefined |
| 151 | } |
| 152 | |
| 153 | const text = |
| 154 | limit && limit > 0 ? `${Locale.number(total)} (${Math.round((total / limit) * 100)}%)` : Locale.number(total) |
| 155 | |
| 156 | if (typeof cost === "number" && cost > 0) { |
| 157 | return `${text} · ${money.format(cost)}` |
| 158 | } |
| 159 | |
| 160 | return text |
| 161 | } |
| 162 | |
| 163 | export function formatError(error: { |
| 164 | name?: string |