fix(agents): fail over on billing/credits errors

This commit is contained in:
Peter Steinberger
2026-01-09 21:17:00 +01:00
parent e0089bb4eb
commit 65cb9dc3f7
6 changed files with 85 additions and 4 deletions

View File

@@ -261,6 +261,30 @@ export function isRateLimitErrorMessage(raw: string): boolean {
);
}
export function isBillingErrorMessage(raw: string): boolean {
const value = raw.toLowerCase();
if (!value) return false;
return (
/\b402\b/.test(value) ||
value.includes("payment required") ||
value.includes("insufficient credits") ||
value.includes("credit balance") ||
value.includes("plans & billing") ||
(value.includes("billing") &&
(value.includes("upgrade") ||
value.includes("credits") ||
value.includes("payment") ||
value.includes("plan")))
);
}
export function isBillingAssistantError(
msg: AssistantMessage | undefined,
): boolean {
if (!msg || msg.stopReason !== "error") return false;
return isBillingErrorMessage(msg.errorMessage ?? "");
}
export function isAuthErrorMessage(raw: string): boolean {
const value = raw.toLowerCase();
if (!value) return false;