/** * Z.AI Reader Adapter (DESIGN.md §18; reader-migration-tech-plan D4; * PRD FR-??? — reader migration Ticket 03). * * Owns the Provider-facing half of the provider-neutral Reader * Capability defined in `src/capabilities/reader.ts`: * * - URL rewrite (gist.github.com// -> /raw) applied BEFORE * invocation; the rewritten URL surfaces as `finalUrl` in the * result. The rewrite is Z.AI-specific because Z.AI's WebReader * MCP recognizes the rewritten URL. * - a total parser for the characterized Z.AI WebReader response * (`ReaderRawResponse`: object on success, bare string for MCP- * level error envelopes); * - encoded MCP error classification BEFORE success parsing * (`quota` is terminal `QUOTA_ERROR`; the rest of the taxonomy * uses the shared retry/terminal classification); the parsing * helpers live in `./encoded-error.ts` and are shared with * `./repository.ts`; * - a single resolved-credential fingerprint per cache identity and * exact per-operation legacy cache candidate using Ticket 01's * `buildLegacyReaderCacheKey` helper; * - `decodeCached` delegates to Ticket 01's total decoder * (`decodeReaderFetchResult`); * - a fresh transport per invocation attempt and exactly one * best-effort close in `finally`; close failure never replaces * success nor masks the primary failure; * - no leakage of raw WebReader response types outside this module. * * Boundary rules (ARCHITECTURE.md §2): * - May import capability types, normalized errors, the Z.AI MCP * tool-name helpers, the legacy cache-key helper, the shared * `ZaiAdapterClientPort` typed client port, and the shared * encoded-error helpers. * - Must NOT import another Provider's Adapter, command * presentation, or extract/maxChars projection logic. * * Scope: * - implements the single `reader-fetch` operation only. URL scheme * validation, `--extract`, `--max-chars`, and `--full-envelope` * belong to the command layer (Ticket 04 cuts the handler over). * - descriptor metadata sequencing: Ticket 03 introduces this Adapter * handle and wires it through `ProviderAdapter.reader` WITHOUT * advertising `reader` on `createZaiDescriptor.capabilities()`; * Ticket 04 then flips the descriptor to advertise `reader` so * Provider selection and Doctor inventory derive from a single * source of truth, AND cuts `commands/read.ts` over to dispatch * through `adapter.reader.fetch`. This module owns no registry, * selection, or command cutover. */ import type { ZaiAdapterClientPort, ZaiMcpClientOptions } from "../types.js"; import { type ReaderCapability } from "../../capabilities/reader.js"; /** * Production close bound (ms). Matches the existing * `ZaiMcpClient.close(timeoutMs = 2000)` semantic; the Adapter races * the close against a 2 second timer that resolves silently so a stuck * close cannot stall the attempt. Tests may inject a shorter bound via * {@link ZaiReaderCapabilityOptions.closeTimeoutMs}. */ export declare const ZAI_READER_CLOSE_BOUND_MS = 2000; /** * Options accepted by {@link createZaiReaderCapability}. * * `closeTimeoutMs` defaults to {@link ZAI_READER_CLOSE_BOUND_MS} * (2000 ms) — the existing `ZaiMcpClient.close(timeoutMs = 2000)` * semantic. Tests may inject a shorter bound to bound a never- * resolving `close()` without waiting for the production default. */ export interface ZaiReaderCapabilityOptions { readonly env: NodeJS.ProcessEnv; readonly clientFactory: (options: ZaiMcpClientOptions) => ZaiAdapterClientPort; readonly closeTimeoutMs?: number; } /** * Build the Z.AI Reader Capability. The capability is composed of a * single typed `ReaderOperation` descriptor (`fetch`); the Adapter * owns credentials, transport lifecycle, raw request/response mapping, * URL rewrite, and error normalization. No transport, credential * resolution, or I/O happens during construction. */ export declare function createZaiReaderCapability(options: ZaiReaderCapabilityOptions): ReaderCapability; //# sourceMappingURL=reader.d.ts.map