/** * Z.AI Quota Capability (DESIGN.md §13, P4-02). * * Maps the Z.AI monitor quota-limit response into the normalized * Provider-quota Interface. The normalizer is pure; the capability * factory owns credential resolution, the single monitor transport * attempt, and failure normalization. Shared execution owns retry. * * Z.AI mapping (DESIGN.md §13): * - `level` -> `plan`. * - Rolling `TIME_LIMIT` -> `requests` category with current counts, * duration in seconds, the Provider's own remaining percentage, and * ISO reset. The entry is trusted only when self-consistent * (GitHub #191); an inconsistent counter emits the category with an * empty window rather than a fabricated one. * - `TIME_LIMIT.usageDetails` -> the additive optional `toolUsage` * field on `requests` (`modelCode` -> `tool`, `usage` -> `usage`; * entries without a name or without a positive count are dropped, * and an all-dropped list omits the field rather than publishing an * empty array). Mapped independently of the consistency guard: the * per-tool rows are informational and survive a corrupt window. * - `TOKENS_LIMIT` -> `tokens` category; convert the Provider's used * percentage to a remaining percentage. * - Categories are named `requests` then `tokens` when present. * - When a payload carries MULTIPLE entries per category (#204, * never observed live), `requests` picks the first SELF-CONSISTENT * TIME_LIMIT, falling back to the first entry when none is; `tokens` * takes the first TOKENS_LIMIT. * * Boundary rules (ARCHITECTURE.md §2): * - May import the quota capability contract, Provider-local monitor * transport, and normalized errors. * - Must NOT import command presentation or another Provider's Adapter. */ import type { ProviderQuotaSuccess, QuotaCapability } from "../../capabilities/quota.js"; import { type ZaiMonitorDeps } from "./monitor-client.js"; /** * Normalize a raw Z.AI quota-limit payload into the shared Interface. * * The `requests` category trusts the RAW fields (`remaining` / * `percentage`, converted to a remaining percentage) over anything * derived from the counts, and only while {@link isConsistentTimeLimit} * holds. An inconsistent entry emits the category with an EMPTY * `current` window rather than a fabricated one: downstream consumers * read an absent `remainingPercent` as unknown (never `exhausted`, * never `KNOWN_EXHAUSTED` demotion, `PERCENT_CORRUPT` when scoring), * which is the honest report for a counter that contradicts itself. * * The per-tool `toolUsage` rows are mapped from the SAME entry but * INDEPENDENTLY of that guard: they are informational detail that * stands on its own filter, so a corrupt window suppresses the window * only. A category whose counts contradicted each other is exactly when * per-tool detail is most useful. */ export declare function normalizeZaiQuota(raw: unknown): ProviderQuotaSuccess; /** * Options for the Z.AI QuotaCapability. `env` resolves the API key and * monitor base/timeout. The transport dependencies (`fetch`, timer) are * injectable for deterministic tests. */ export interface ZaiQuotaCapabilityOptions extends ZaiMonitorDeps { readonly env: NodeJS.ProcessEnv; } /** * Build the Z.AI QuotaCapability. `invoke` resolves the credential, * performs one monitor transport attempt (auth-scheme fallback inside), * and normalizes the response. Shared execution wraps this in the retry * policy; quota never uses the response cache. */ export declare function createZaiQuotaCapability(options: ZaiQuotaCapabilityOptions): QuotaCapability; //# sourceMappingURL=quota.d.ts.map