import type { TokenUsage } from "../types/model.js"; export declare function isTransientModelError(error: unknown): boolean; /** * A failed funded operation must retain its payer and original intent across * wrappers and retries, so this walks the whole error graph: a funding denial * anywhere in it blocks provider fallback and retry. */ export declare function isModelFundingAuthorityError(error: unknown): boolean; /** True only for provider terminal reasons that explicitly mean output exhaustion. */ export declare function isModelOutputLimitFinishReason(reason: unknown): boolean; /** Safe accounting evidence for a rejected model output. */ export interface ModelOutputEvidence { /** The gateway's wire reason need not be the underlying provider's reason. */ finishReasonSource?: "cloud-chat-completions"; emptyVisibleOutput?: boolean; /** null records an omitted wire cap; undefined means it was not observed. */ maxTokens?: number | null; usage?: Partial; costUsd?: number; } /** Only terminal metadata and numeric accounting may cross this error boundary. */ export declare function modelOutputIncompleteEvidence(error: unknown): (ModelOutputEvidence & { provider?: string; model?: string; finishReason: string; }) | undefined; /** Reject partial model output instead of returning it as successful context. */ export declare function assertModelOutputComplete(options: { finishReason: unknown; provider: string; model?: string; } & ModelOutputEvidence): void; /** Structural HTTP status of one provider-error node: `statusCode`, then `status`. */ export declare function readHttpStatus(node: object): number | undefined; /** Reads provider HTTP status through cause and retry envelopes, accepting statusCode and status. Returns undefined when no status is present. */ export declare function modelProviderErrorStatus(error: unknown): number | undefined; /** * Structured diagnostic detail for a model/provider failure: the HTTP status, * the provider's own error message parsed out of the response body, and a * bounded excerpt of that body. The AI SDK keeps the raw body on * `APICallError.responseBody` but derives `error.message` from the OpenAI * `{"error": {...}}` envelope only — providers that return a FLAT error shape * (Cerebras: `{"message", "type", "param", "code"}`) surface as a bare * statusText ("Bad Request") with the real cause silently dropped. This * extractor recovers that cause so reportError context, logs, and trajectory * records can carry it. */ export interface ModelProviderErrorDetail { status?: number; providerMessage?: string; responseBodyExcerpt?: string; url?: string; } /** * Best-effort extraction of {@link ModelProviderErrorDetail} from a thrown * model-call error, walking the same bounded `.cause`/`RetryError` graph as * {@link modelProviderErrorStatus}. Returns undefined when the chain carries * neither a status nor a response body, so callers can spread it into context * objects without manufacturing empty fields. */ export declare function modelProviderErrorDetail(error: unknown): ModelProviderErrorDetail | undefined; /** * True when a thrown model-call error is an EXPECTED provider/transport failure * — the provider returned an HTTP error status (>= 400) or the request failed * at the network layer — as opposed to a programmer or schema-validation error * (`TypeError`, `SchemaValidationFailedError`) that indicates a real bug and * must propagate. Purely structural: HTTP status and network error codes, never * a message-substring guess. Used to gate the planner-loop's post-tool * evaluator relay so a transient provider failure degrades to an already * completed tool's truthful output while genuine bugs still surface. */ export declare function isModelProviderError(error: unknown): boolean; /** A rejected output/tool schema cannot be repaired by generating an apology. */ export declare function isProviderSchemaRejection(error: unknown): boolean; /** Classification code for a typed provider context-overflow rejection. */ export declare const PROVIDER_CONTEXT_OVERFLOW = "PROVIDER_CONTEXT_OVERFLOW"; /** * True when a thrown model-call error is a provider CONTEXT-LENGTH rejection — * the provider refused to dispatch the request because the input exceeded its * documented context limit. Walks the same bounded `.cause`/`RetryError` graph * as {@link modelProviderErrorStatus} and scans `message` and `responseBody` * (the AI SDK masks flat error bodies to a bare "Bad Request" statusText, so * the actionable phrase often lives only on the body). Conservative: matches * only unambiguous length-rejection phrases AND structural provider evidence * somewhere in the bounded chain: an HTTP error status, an AI SDK API-error * type, or a provider context-overflow code. Message text alone is never * authority — a status-less TypeError that happens to contain the same phrase * remains a programmer error and propagates. Ordinary 400s, schema errors, and * rate limits never classify. */ export declare function isProviderContextOverflowError(error: unknown): boolean; /** * True for the whole typed overflow class at a consuming boundary: either a * raw provider length rejection ({@link isProviderContextOverflowError}) or * the {@link PROVIDER_CONTEXT_OVERFLOW} `ElizaError` the planner loop throws * once its lossless substitution recovery is exhausted. */ export declare function isProviderContextOverflowFailure(error: unknown): boolean;