feat: add gpt usage reset time
CI / verify (pull_request) Successful in 8s

This commit is contained in:
2026-09-14 21:27:28 +02:00
parent 3b79f24d83
commit c9ff8dc629
3 changed files with 75 additions and 16 deletions
+23 -4
View File
@@ -13,13 +13,32 @@ function percent(value: number) {
return value < 0.1 && value > 0 ? "<0.1" : value.toFixed(value < 10 ? 1 : 0);
}
export function formatQuotaWindow(
window: QuotaWindow & { remaining: number; sessionConsumed: number },
) {
function resetTiming(resetsAt: number, now: number) {
if (!Number.isFinite(resetsAt) || resetsAt <= 0 || !Number.isFinite(now))
return "reset unavailable";
const remaining = resetsAt - now;
if (remaining <= 0) return "reset due";
if (remaining < 60_000) return "resets in <1m";
const minutes = Math.floor(remaining / 60_000);
const days = Math.floor(minutes / 1_440);
if (days > 0) {
const hours = Math.floor((minutes % 1_440) / 60);
return `resets in ${days}d${hours > 0 ? ` ${hours}h` : ""}`;
}
const hours = Math.floor(minutes / 60);
if (hours > 0) {
const rest = minutes % 60;
return `resets in ${hours}h${rest > 0 ? ` ${rest}m` : ""}`;
}
return `resets in ${minutes}m`;
}
export function formatQuotaWindow(window: QuotaWindow & { remaining: number }, now = Date.now()) {
const label = window.label
? `${window.label} ${duration(window.seconds)}`
: duration(window.seconds);
return `${label}: ${percent(window.remaining)}% left · ~${percent(window.sessionConsumed)}pp this session`;
return `${label}: ${percent(window.remaining)}% left · ${resetTiming(window.resetsAt, now)}`;
}
export async function loadQuotaStatus(load: () => Promise<QuotaStatus | null>) {