refactor: dedupe provider usage auth/fetch logic and expand coverage

This commit is contained in:
Peter Steinberger
2026-02-19 13:27:40 +00:00
parent 2d485cd47a
commit 14b4c7fd56
6 changed files with 283 additions and 86 deletions

View File

@@ -33,13 +33,6 @@ function formatResetRemaining(targetMs?: number, now?: number): string | null {
}).format(new Date(targetMs));
}
function pickPrimaryWindow(windows: UsageWindow[]): UsageWindow | undefined {
if (windows.length === 0) {
return undefined;
}
return windows.reduce((best, next) => (next.usedPercent > best.usedPercent ? next : best));
}
function formatWindowShort(window: UsageWindow, now?: number): string {
const remaining = clampPercent(100 - window.usedPercent);
const reset = formatResetRemaining(window.resetAt, now);
@@ -84,19 +77,12 @@ export function formatUsageSummaryLine(
return null;
}
const parts = providers
.map((entry) => {
const window = pickPrimaryWindow(entry.windows);
if (!window) {
return null;
}
return `${entry.displayName} ${formatWindowShort(window, opts?.now)}`;
})
.filter(Boolean) as string[];
if (parts.length === 0) {
return null;
}
const parts = providers.map((entry) => {
const window = entry.windows.reduce((best, next) =>
next.usedPercent > best.usedPercent ? next : best,
);
return `${entry.displayName} ${formatWindowShort(window, opts?.now)}`;
});
return `📊 Usage: ${parts.join(" · ")}`;
}