/** * Error classification for SDK errors. * Maps raw error messages to structured HTTP error responses. */ export interface ClassifiedError { status: number; type: string; message: string; } /** * Detect specific SDK errors and return helpful messages to the client. */ export declare function classifyError(errMsg: string): ClassifiedError; /** * Detect errors caused by an expired or missing OAuth access token. * Triggers an inline token refresh + retry in server.ts. * * Patterns, in order of specificity: * - "OAuth token has expired" / "Not logged in" — CLI-emitted (subprocess * either got 401 with this wording from Anthropic or detected expiry * locally before sending). * - "invalid_token" / "token_expired" — RFC 6750 resource-server errors that * can appear in the API response body. * - "401" + ("authentication" | "unauthorized" | "invalid") — generic 401 * wrapping. Anthropic's API does not always echo the CLI-specific wording, * so without this branch a stale access token returns a generic 401 to the * proxy and refresh-and-retry never fires (caller sees the 401). * * False positives only cost one OAuth round-trip — the refresh is single-shot * per request (gated by `tokenRefreshed` in server.ts) and surfaces the * original error if it doesn't help. */ export declare function isExpiredTokenError(errMsg: string): boolean; /** * Detect errors caused by stale session/message UUIDs. * These happen when the upstream Claude session no longer contains * the referenced message or conversation (expired, evicted server-side, etc.). */ export declare function isStaleSessionError(error: unknown): boolean; /** * Quick check whether an error message indicates a rate limit. * Used by server.ts to decide whether to retry with a smaller context window. */ export declare function isRateLimitError(errMsg: string): boolean; /** * Detect errors caused by the 1M context window requiring Extra Usage. * Max subscribers without Extra Usage enabled get this error when using * sonnet[1m] or opus[1m]. The fix is to fall back to the base model. */ export declare function isExtraUsageRequiredError(errMsg: string): boolean; /** * Structured SDK-termination metadata extracted from raw error text. * Used by diagnosticLog to surface why the SDK subprocess ended (max_turns, * exit, abort) plus the captured stderr tail — info that classifyError * collapses into a generic api_error. */ export interface SdkTermination { reason: "max_turns" | "process_exit" | "aborted" | "unknown"; /** Turn count when reason=max_turns and parseable. */ turns?: number; /** Exit code when reason=process_exit and parseable. */ exitCode?: number; /** Captured "Subprocess stderr: …" tail (truncated). */ stderrTail?: string; /** Truncated raw error message — set only when reason="unknown" so the log * line stays self-contained for unrecognized SDK errors (e.g. so we can * add a new pattern next time). */ rawTail?: string; } /** * Parse the raw error message thrown by the Claude Agent SDK into structured * termination metadata. Pure function — no I/O. * * Returns reason="unknown" when the message doesn't match any recognized * pattern; callers can still log it with whatever surrounding context they have. */ export declare function extractSdkTermination(errMsg: string): SdkTermination; /** * Render an SdkTermination plus request context as a single greppable log line. * Matches the key=value style used by token-health diagnostic messages so all * /telemetry/logs entries are uniform. * * Session IDs are truncated to 8 chars to keep lines short — full IDs are * already on the parent telemetry record. */ export declare function formatSdkTermination(t: SdkTermination, ctx: { model?: string; requestSource?: string; isResume?: boolean; hasDeferredTools?: boolean; sdkSessionId?: string; }): string; //# sourceMappingURL=errors.d.ts.map