/** * Shared encoded MCP error envelope helpers (DESIGN.md §18). * * The ZRead and WebReader MCP transports occasionally surface a * bare-string error envelope of the shape: * * MCP error -\n * error.code: \n * error.message: * * * The Repository Adapter (P6-04) and the Reader Adapter (Ticket 03) * both recognise this shape BEFORE attempting any success parsing. * Classification is centralized here so the taxonomy stays consistent * across Adapter implementations; each Adapter supplies an operation * `label` ("repository", "reader", …) that becomes part of the * sanitized outward message. Auth-message labels (401/403) are NOT * operation-specific and stay stable. * * Boundary rules: * - This module imports normalized errors only; it imports no * transport, no capability contract, and no other Adapter. * - The raw Provider body, `error.message`, `reset`, etc. are * discarded; outward messages and help text are stable sanitized * labels. * * Historical note: P6-04A corrected the original mapping (status 403 * must keep exact status 403, not collapse to 401) and P6-04B refined * the exhausted-quota phrase matching so that the bare word "limit" * inside "rate limited" does NOT trigger terminal QuotaError. Those * corrections are baked in here. */ /** Regex that captures the status of an encoded MCP error envelope. */ export declare const ENCODED_MCP_ERROR_RE: RegExp; /** * Test whether `raw` looks like an encoded MCP error envelope. Returning * `true` forces the caller into the error classification path before any * success parser runs. The presence of a numeric status on the first * line is the only requirement; the body lines are still parsed lazily. */ export declare function looksLikeEncodedMcpError(raw: unknown): boolean; /** * Extract the numeric status code from an encoded MCP error envelope. * Returns `null` when the prefix is not present or the trailing digits * do not parse to a finite integer. */ export declare function extractEncodedStatus(raw: string): number | null; /** Extract the documented `error.code:` numeric value, if present. */ export declare function extractEncodedCode(raw: string): number | null; /** Extract the documented `error.message:` line text, if present. */ export declare function extractEncodedMessage(raw: string): string | null; /** * Classify an encoded MCP error into a normalized error. * * The caller MUST have established that the response is an encoded * envelope (via {@link looksLikeEncodedMcpError}). This function NEVER * embeds the raw Provider body, message, or help into the outward text; * it uses stable sanitized labels instead. * * `label` is the operation name used in the outward ApiError / QuotaError * messages (e.g. "repository", "reader"). Auth messages (401, 403) do * not carry the label — they read "Z.AI authentication failed" regardless * of which Adapter surfaced them. * * Mapping (DESIGN.md §18; corrected by P6-04A, refined by P6-04B): * - code 1310 OR explicit exhausted/limit/quota meaning * -> terminal QuotaError * (REGARDLESS of the encoded * status line; a non-429 line * with code 1310 is still an * exhausted-quota failure); * - 401 -> AuthError, status 401, terminal; * - 403 -> normalized ScoutlineError * with code AUTH_ERROR and * statusCode 403, terminal * (avoids widening the * global AuthError * constructor); * - 429 (without exhausted quota) -> ApiError, status 429, * retryable through the shared * taxonomy; * - 5xx -> ApiError matching status, * retryable; * - other 4xx -> ApiError matching status, * terminal; * - malformed envelope (no parseable status) * -> ApiError 502, retryable. */ export declare function classifyEncodedMcpError(raw: string, label: string): Error; //# sourceMappingURL=encoded-error.d.ts.map