import { isContextOverflow, matchQuotaRule, matchTransientRule, normalizeProviderError, providerFamily } from "./rules"; import type { ClassifierInput, Verdict } from "./types"; export function classify(input: ClassifierInput, now = Date.now()): Verdict { const text = normalizeProviderError(input.errorMessage, input.diagnostics); if (isContextOverflow(text)) return { kind: "none", matchedRule: "context-overflow-guard" }; const family = providerFamily(input.provider); const quota = matchQuotaRule(family, text, now); if (quota) return { kind: "quota", ...quota }; const transient = matchTransientRule(text, input.httpHint?.status); if (transient) return { kind: "transient", matchedRule: transient }; return { kind: family === "unknown" ? "unknown" : "none" }; }