import type { Api } from "../types.js"; import type { AbortSourceTracker } from "../utils/abort.js"; import type { CapturedHttpErrorResponse, RawHttpRequestDump } from "../utils/http-inspector.js"; /** Context a provider catch block hands to {@link finalize}. */ export interface FinalizeOptions { /** Wire API, for api-specific text classification (e.g. stale-responses items). */ api?: Api; /** Provider id; forwarded to the message formatter for copilot rewrites. */ provider?: string; /** Requested model id; paired with provider for model-entitlement classification. */ model?: string; /** Caller signal, for providers that don't run an abort tracker. */ signal?: AbortSignal; /** Abort tracker, preferred over `signal`: distinguishes caller vs. local aborts. */ abortTracker?: AbortSourceTracker; /** Raw request, dumped into the message for 400-class failures. */ rawRequestDump?: RawHttpRequestDump; /** Captured non-2xx response body, used for status fallback and message detail. */ capturedErrorResponse?: CapturedHttpErrorResponse; } /** The full bundle a provider assigns onto its `AssistantMessage` error fields. */ export interface FinalizeResult { /** Structured flag id from {@link classify}. */ id: number; /** HTTP status, from the error or the captured response. */ status: number | undefined; /** `"aborted"` when the caller cancelled, otherwise `"error"`. */ stopReason: "aborted" | "error"; /** User-facing message: a local abort reason, else the caller's abort reason, else from {@link formatMessage}. */ message: string; } /** * Build the complete error bundle for a provider catch block, replacing the * `stopReason` / `errorStatus` / `errorId` / `errorMessage` boilerplate. * * `stopReason` comes from the abort tracker (caller intent dominates) or, when * no tracker is supplied, the raw `signal.aborted`. The message is, in order, a * local abort reason (e.g. a first-event timeout), the reason the caller passed * to `abort()` (e.g. "Interrupted by user"), or the formatted error. Message * formatting is wrapped so a formatter throw can never skip the caller's `stream.end()`. */ export declare function finalize(error: unknown, opts?: FinalizeOptions): Promise;