import type { Api, AssistantMessage, Usage } from "../types.js"; export declare const Flag: { readonly Class: 4096; readonly ThinkingLoop: 65536; readonly Transient: 131072; readonly Timeout: 262144; readonly UsageLimit: 524288; readonly StaleResponsesItem: 1048576; readonly MalformedFunctionCall: 2097152; readonly ProviderFinishError: 4194304; readonly EmptyResponse: 8192; readonly ContentBlocked: 32768; /** Account-scoped provider policy denial that may succeed with another credential. */ readonly AccountPolicy: 16384; readonly ContextOverflow: 8388608; readonly AuthFailed: 16777216; readonly SilentAbort: 33554432; readonly UserInterrupt: 67108864; readonly Abort: 134217728; /** Strict-tool rejection (400): grammar too large, schema too complex, or structured outputs unsupported by the model/endpoint. */ readonly Grammar: 268435456; /** Anthropic model/account does not support fast mode / the `speed` parameter. */ readonly FastModeUnsupported: 536870912; /** OAuth refresh failed definitively — the stored grant is dead, re-login required. */ readonly OAuthExpiry: 1073741824; /** HTTP 413 byte/media rejection — token compaction cannot shrink bytes or media budgets (#9235). */ readonly PayloadRejected: 2147483648; }; export type Flag = (typeof Flag)[keyof typeof Flag]; export declare const STREAM_READ_ERROR_PATTERN: RegExp; /** Python h2/httpx diagnostics forwarded through provider or proxy error events. */ export declare const PYTHON_HTTP2_STREAM_RESET_PATTERN: RegExp; /** Python h11/httpx EOF while reading an HTTP/1.1 chunked response body. */ export declare const PYTHON_HTTP_INCOMPLETE_CHUNK_PATTERN: RegExp; /** reqwest body-frame failures forwarded by the Codex HTTP proxy. */ export declare const CODEX_HTTP_BODY_READ_ERROR_PATTERN: RegExp; /** Exact HTTP request-body-read timeout diagnostic. */ export declare function isRequestBodyReadTimeout(status: number | undefined, message: string | undefined): boolean; /** Exact pre-output Responses 408 that needs a changed-request recovery path. */ export declare function isResponsesRequestBodyReadTimeout(message: { api?: Api; errorStatus?: number; errorMessage?: string; requestBodyReadTimeoutFullReplay?: boolean; }): boolean; export declare const TRANSIENT_TRANSPORT_PATTERN: RegExp; export declare const ANTHROPIC_ACCOUNT_POLICY_PATTERN: RegExp; /** Whether an error message represents an Anthropic account-scoped permission/policy denial. */ export declare function isAnthropicAccountPolicyText(text: string, provider?: string, statusArg?: number): boolean; /** * Local llama.cpp / Ollama deterministic tool-call argument JSON parse failure. * The model emitted invalid JSON in a tool call and the server returned HTTP 500 * with this exact text — replaying the same prompt yields the same malformed * output, so callers strip {@link Flag.Transient} when this matches. */ export declare const LLAMA_CPP_TOOL_CALL_PARSE_PATTERN: RegExp; /** Whether an OAuth refresh error message means the grant is definitively dead. */ export declare function isOAuthExpiry(errorMessage: string): boolean; export declare function create(...flags: number[]): number; export declare function is(id: number | undefined, flag: Flag): boolean; export declare function retriable(id: number | undefined, opts?: { replayUnsafe?: boolean; }): boolean; export declare function status(error: unknown): number | undefined; export declare function isStreamReadErrorText(text: string): boolean; /** Persisted-text form of {@link isStreamEnvelopeError}: recognizes the * prefix-tagged envelope diagnostic on an aborted turn's `errorMessage` / * `stopDetails.explanation` so loop-level salvage can classify it after the * original `Error` instance is gone. */ export declare function isStreamEnvelopeErrorText(text: string): boolean; export declare function classify(error: unknown, api?: Api): number; /** * Whether an error (or message string) classifies as an account usage/quota * limit — the persistent, credential-rotation-worthy kind. This is the public * accessor for {@link Flag.UsageLimit}; prefer it over re-running message * regexes at call sites. */ export declare function isUsageLimit(error: unknown, api?: Api): boolean; /** Whether an upstream rejection is an account-scoped policy denial worth retrying with a sibling credential. */ export declare function isAccountPolicyError(error: unknown, api?: Api): boolean; /** * Model id from Codex's exact ChatGPT-account entitlement denial. Generic * unsupported-model invalid requests deliberately do not match. */ export declare function codexChatGPTAccountPolicyModel(error: unknown, depth?: number): string | undefined; /** Whether the exact Codex entitlement denial applies to this provider and requested model. */ export declare function isCodexChatGPTAccountPolicyError(error: unknown, provider: string, modelId: string | undefined): boolean; /** Whether Cursor returned a non-retryable plan entitlement denial for this account. */ export declare function isCursorPlanAccountPolicyError(error: unknown, provider: string, depth?: number): boolean; /** * Strict-tool rejection: grammar too large, schema too complex, or structured * outputs unsupported by the model/endpoint. * Accessor for {@link Flag.Grammar}. */ export declare function isGrammarError(error: unknown): boolean; /** * Anthropic model/account does not support fast mode / the `speed` parameter. * Accessor for {@link Flag.FastModeUnsupported}. */ export declare function isFastModeUnsupported(error: unknown): boolean; /** * Cline's gateway gates some roster entries (certain free-tier models) to its * own product surfaces with a 403. The API key is valid — the restriction is * per-model client policy — so it must neither rotate sibling credentials (they * fail identically) nor surface as an auth failure. */ export declare function isClinePassSurfaceGateMessage(errorMessage: string | undefined): boolean; /** * GitHub Copilot 403s are plan/model-policy/org denials against a valid token — * never a revoked credential (those arrive as 401). Wiping stored credentials * on them hides the whole provider from `/model` and forces a pointless * re-login, so credential-lifetime decisions must exempt them even though * they still classify as `Flag.AuthFailed` (issue #11275). Mirrors the 403 * contract in `rewriteCopilotError` (`utils/http-inspector.ts`). */ export declare function isGitHubCopilotPolicyDenial(provider: string | undefined, status: number | undefined, errorMessage: string | undefined): boolean; export declare function classifyMessage(message: { api?: Api; provider?: string; model?: string; errorId?: number; errorMessage?: string; errorClassificationMessage?: string; errorStatus?: number; }): number; export declare function attach(error: E, id: number): E; /** Overflow-classification evidence, including errors received before token usage is available. */ export interface ContextOverflowMessage extends Pick { readonly usage?: Pick; } /** * Provider-reported usage proves context-window excess — authoritative, compaction-owned (#9235). * * Prefers `contextTokens` when the provider reports it: providers that run * several model calls per turn (Cursor's server-side tool loop) report * `input`/`cacheRead` summed across those calls, which can exceed the window * many times over while the conversation itself stays small. */ export declare function isUsageBackedContextOverflow(message: ContextOverflowMessage, contextWindow?: number): boolean; /** Classify overflow from error flags, available token usage, or provider error text. */ export declare function isContextOverflow(message: ContextOverflowMessage, contextWindow?: number): boolean; /** HTTP 413 byte/media rejection (#9235); may co-occur with {@link isContextOverflow} for bare `413 (no body)`. * Callers with local headroom should skip compaction when this returns true. */ export declare function isPayloadRejection(message: AssistantMessage): boolean; /** Dual-flagged 413 (PayloadRejected + ContextOverflow) with no provider-reported token excess (#9235). * The co-flag means a different provider's larger byte/media budget may accept the request. * Usage-backed overflows are authoritative window excesses and never ambiguous. */ export declare function isTextAmbiguousContextOverflow(errorId: number, message: ContextOverflowMessage | undefined, contextWindow?: number): boolean; export declare function stringify(id: number | undefined): string; /** * Transient stream corruption where the response was truncated mid-JSON. * * Strings (persisted `stopDetails.explanation`/`errorMessage` diagnostics) are matched with the * stricter {@link STREAM_PARSE_DIAGNOSTIC_PATTERN} — bare "truncated"/"end of file" text is too * low-signal to trust once detached from a live transport `Error`, which keeps the broad pattern. */ export declare function isTransientStreamParseError(error: unknown): boolean; /** * Transport stream-drop diagnostic (see {@link STREAM_DROP_PATTERN}). Unlike * {@link isTransientStreamParseError}, one pattern serves both the live `Error` * and the persisted-string forms: the phrasings are high-signal enough to trust * detached from a transport `Error`. */ export declare function isTransientStreamDropError(error: unknown): boolean; /** Any malformed stream-envelope error (prefix-tagged or out-of-order events). */ export declare function isStreamEnvelopeError(error: unknown): boolean; /** Stream-envelope errors safe to retry against the provider (event ordering only). */ export declare function isRetryableStreamEnvelopeError(error: unknown): boolean;