/** * Error classifier for LLM and network errors. * * Maps error strings to actionable categories using regex pattern matching. * Follows the same pattern pi-ai uses for context overflow detection, * extended to cover authentication, rate limits, server errors, and network errors. * * The classifier is a pure function. It does not throw, does not modify state. * It takes an error (or error string) and returns a classification. * * Reference: error-recovery.md */ import type { ClassifiedError } from './types.js'; /** * Options for the error classifier. */ export interface ClassifyErrorOptions { /** * The model's context window size in tokens. * Used for context overflow detection when delegating to pi-ai. */ contextWindow?: number; /** * Whether the agent was aborted (user or system cancellation). * When true, the error is immediately classified as 'cancelled'. * The caller checks agent.state or AbortSignal.aborted and passes this flag; * the classifier itself remains pure. */ wasAborted?: boolean; } /** * Classify an error into an actionable category. * * Checks error strings against regex patterns in priority order (first match wins): * 1. Cancelled (if wasAborted is true) * 2. Authentication (9 patterns) * 3. Rate limit (7 patterns) * 4. Context overflow (4 fallback patterns; delegates to pi-ai isContextOverflow when available) * 5. Server error (7 patterns) * 6. Network (8 patterns) * 7. Unknown (catch-all) * * @param error - The error to classify (Error object or string) * @param options - Optional classification options * @returns A ClassifiedError with category, severity, original message, and suggested action */ export declare function classifyError(error: Error | string, options?: ClassifyErrorOptions): ClassifiedError; //# sourceMappingURL=error-classifier.d.ts.map