export function classifyProviderFallbackFailure( stopReason: unknown, errorMessage: unknown, ): string | null { if (stopReason !== "error" || typeof errorMessage !== "string") return null; const diagnostic = errorMessage.trim(); if (diagnostic.length === 0) return null; const normalized = diagnostic.toLowerCase(); const category = /auth|credential|api[ _-]?key|unauthori[sz]ed|forbidden/.test(normalized) ? "provider-auth" : /quota|rate[ _-]?limit|resource exhausted|billing limit/.test(normalized) ? "provider-quota" : /capacity|overloaded|temporarily unavailable|no available.*server/.test(normalized) ? "provider-capacity" : null; return category ? `${category}: ${diagnostic}` : null; }