/** * Provider HTTP error formatting helpers. * * Ported from openclaw/src/agents/provider-http-errors.ts (commit baseline 2026-05-08). * * DECISION (per docs/voice-rearchitecture.md §6): * - Body read is hard-capped at 16 KiB to avoid memory blowups on misbehaving * providers that return huge HTML 5xx pages. * - Both `error.message` (OpenAI shape) and `error.detail` (DashScope shape) are * normalized into a single human-readable string for logs. * - Request id is taken from `x-request-id` first, then `request-id` (Alibaba uses * the latter on some endpoints). */ export declare function truncateErrorDetail(detail: string, limit?: number): string; export declare function readResponseTextLimited(response: Response, limitBytes?: number): Promise; /** Best-effort vendor `code` + human message from a JSON error body (image providers, failover). */ export declare function extractVendorErrorFields(body: string): { code?: string; message?: string; }; export declare function formatProviderErrorPayload(payload: unknown): string | undefined; export declare function extractProviderErrorDetail(response: Response): Promise; export declare function extractProviderRequestId(response: Response): string | undefined; export interface ProviderHttpErrorParts { label: string; status: number; detail?: string; requestId?: string; /** Prefix in front of the status code, e.g. "HTTP " for non-provider transports. */ statusPrefix?: string; /** Vendor error code when JSON body could be parsed (OpenAI, DashScope, MiniMax, …). */ code?: string; /** Request URL for diagnostics (image-generation assertOk path). */ url?: string; /** Raw body preview for non-JSON failures (image-generation assertOk path). */ bodyPreview?: string; /** * When set, used as {@link Error.message} verbatim instead of * {@link formatProviderHttpErrorMessage}. */ messageOverride?: string; } export declare function formatProviderHttpErrorMessage(parts: ProviderHttpErrorParts): string; /** * ProviderHttpError carries the parsed status / detail / requestId so callers * (e.g. STT runner, TTS fallback chain) can classify failures without re-parsing. */ export declare class ProviderHttpError extends Error { readonly status: number; readonly detail?: string; readonly requestId?: string; readonly label: string; readonly code?: string; readonly url?: string; readonly bodyPreview?: string; constructor(parts: ProviderHttpErrorParts); } export declare function createProviderHttpError(response: Response, label: string, options?: { statusPrefix?: string; }): Promise; export declare function assertOkOrThrowProviderError(response: Response, label: string): Promise; export declare function assertOkOrThrowHttpError(response: Response, label: string): Promise; /** * Throws {@link ProviderHttpError} when the response is not OK; otherwise returns * the response. Body is consumed on failure (do not re-read). * * Used by bundled image-generation HTTP helpers (vendor code extraction + body preview). */ export declare function assertOk(res: Response, contextUrl?: string): Promise;