fix(auth): billing backoff + cooldown UX
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
ensureAuthProfileStore,
|
||||
repairOAuthProfileIdMismatch,
|
||||
resolveApiKeyForProfile,
|
||||
resolveProfileUnusableUntilForDisplay,
|
||||
} from "../agents/auth-profiles.js";
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
import { stylePromptTitle } from "../terminal/prompt-style.js";
|
||||
@@ -81,6 +82,32 @@ export async function noteAuthProfileHealth(params: {
|
||||
const store = ensureAuthProfileStore(undefined, {
|
||||
allowKeychainPrompt: params.allowKeychainPrompt,
|
||||
});
|
||||
const unusable = (() => {
|
||||
const now = Date.now();
|
||||
const out: string[] = [];
|
||||
for (const profileId of Object.keys(store.usageStats ?? {})) {
|
||||
const until = resolveProfileUnusableUntilForDisplay(store, profileId);
|
||||
if (!until || now >= until) continue;
|
||||
const stats = store.usageStats?.[profileId];
|
||||
const remaining = formatRemainingShort(until - now);
|
||||
const kind =
|
||||
typeof stats?.disabledUntil === "number" && now < stats.disabledUntil
|
||||
? `disabled${stats.disabledReason ? `:${stats.disabledReason}` : ""}`
|
||||
: "cooldown";
|
||||
const hint = kind.startsWith("disabled:billing")
|
||||
? "Top up credits (provider billing) or switch provider."
|
||||
: "Wait for cooldown or switch provider.";
|
||||
out.push(
|
||||
`- ${profileId}: ${kind} (${remaining})${hint ? ` — ${hint}` : ""}`,
|
||||
);
|
||||
}
|
||||
return out;
|
||||
})();
|
||||
|
||||
if (unusable.length > 0) {
|
||||
note(unusable.join("\n"), "Auth profile cooldowns");
|
||||
}
|
||||
|
||||
let summary = buildAuthHealthSummary({
|
||||
store,
|
||||
cfg: params.cfg,
|
||||
|
||||
Reference in New Issue
Block a user