Something went wrong. Try again.
fork of prime agent with changes i want but are not upstreamable probqbly (and some fixes)
Something went wrong. Try again.
1.7 kB · 54 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455import chalk from "chalk";import { AuthStorage } from "../core/auth-storage.js";import { initTheme } from "../modes/interactive/theme/theme.js";import { fetchUsageReports, renderUsageReportText } from "../modes/interactive/usage-report.js";
export async function runUsageCommand(json: boolean): Promise<void> { let authStorage: AuthStorage; try { authStorage = AuthStorage.create(); } catch (error) { console.error( chalk.red(`Error: failed to load auth storage: ${error instanceof Error ? error.message : String(error)}`), ); process.exitCode = 1; return; }
const result = await fetchUsageReports(authStorage);
if (json) { const jsonOutput = { fetchedAt: Date.now(), reports: result.reports.map((report) => ({ provider: report.provider, providerName: report.providerName ?? report.provider, accountId: report.accountId ?? null, email: report.email ?? null, planType: report.planType ?? null, limits: (report.limits ?? []).map((limit) => ({ label: limit.label, usedPercent: limit.usedPercent ?? null, windowLabel: limit.windowLabel ?? null, resetsAt: limit.resetsAt ?? null, status: limit.status ?? "unknown", detail: limit.detail ?? null, })), balance: report.balance ?? null, notes: report.notes ?? [], error: report.error ?? null, })), skipped: result.skipped, }; console.log(JSON.stringify(jsonOutput, null, 2)); return; }
try { initTheme(undefined, false); } catch { // Ignore theme initialization error if already initialized } const width = Math.max(60, Math.min((process.stdout.columns || 80) - 2, 120)); console.log(renderUsageReportText(result, undefined, width, { includeSession: false }));}