/** * Context limits LEARNED from what a deployment actually said when it refused a request. * * The catalog can only report what a provider publishes in `/models`, and most of the free * providers this proxy fronts publish nothing at all. But a deployment that rejects an * over-length request usually states its real ceiling in the error message — a first-party fact * about the exact deployment that will serve the next request, and therefore *better* evidence * than a published catalogue figure, which can be generic or stale. * * ⚠ **Only an explicitly STATED maximum is recorded.** "We sent an estimated N tokens and it was * rejected" is not a limit — it is an upper bound on a number this proxy estimated at four * characters per token, and persisting it would put a guess into the one store whose whole value * is that it contains measurements. If nothing parses, nothing is learned. Same rule as * `resolveMetadata`: no rung may be a guess. * * The OUTPUT-token sibling lives here too (the `max-output` half below): a deployment that * rejects an over-sized `max_tokens` often states its real output ceiling in the same kind of * error body, under the same discipline. */ /** * ⚠ **The storage moved; the PARSING is what this module is.** Ceilings now live in * `target-facts.ts` as a `context-limit` fact at deployment scope, so scope and keying are decided * in one place rather than reinvented per store. What stays here is the part that is genuinely * specific to what it reads: knowing which error bodies state a maximum, and extracting it without * ever mistaking the REQUESTED count for the ceiling. * * A context limit is a MEASUREMENT, not a condition, which is why the shared store refuses to let * a success clear it — a normally-sized request succeeding says nothing about the ceiling. */ /** Retained for callers and docs that name the ceiling's staleness window. */ export declare const OBSERVED_LIMIT_TTL_MS: number; /** * Extract a stated context ceiling from an error body, or null. * * Returns null for anything it cannot read as an explicit maximum — including a body that merely * proves the request was too long. See the file header for why that asymmetry is deliberate. */ export declare function parseStatedContextLimit(body: string): number | null; /** Does this error body describe a context-length rejection at all? */ export declare function looksLikeContextLengthError(body: string): boolean; /** * Record a ceiling a deployment stated about itself. A fresh observation always replaces an older * one: the deployment is the authority on its own ceiling, and a provider that raised or lowered * it is telling us so. */ export declare function recordObservedContextLimit(provider: string, model: string, tokens: number, opts?: { path?: string; now?: number; }): void; /** The learned ceiling for a deployment, or null when none was observed or it has expired. */ export declare function observedContextLimit(provider: string, model: string, opts?: { path?: string; now?: number; }): number | null; /** Retained for callers and docs that name the output ceiling's staleness window (30 days). */ export declare const OBSERVED_MAX_OUTPUT_TTL_MS: number; /** * Extract a stated output-token ceiling from an error body, or null. * * Returns null for anything it cannot read as an explicit maximum — "max_tokens is too large" * alone proves the request overshot but states no ceiling. Same fail-safe as * `parseStatedContextLimit`: if nothing parses, nothing is learned. */ export declare function parseStatedMaxOutput(body: string): number | null; /** Does this error body describe a `max_tokens` / output-cap rejection at all? */ export declare function looksLikeMaxOutputError(body: string): boolean; /** * Record an output ceiling a deployment stated about itself. Deployment scope — the message names * the model, never the account. A fresh observation replaces an older one, same as the context * half: the deployment is the authority on its own ceiling. */ export declare function recordObservedMaxOutput(provider: string, model: string, tokens: number, opts?: { path?: string; now?: number; }): void; /** The learned output ceiling for a deployment, or null when none was observed or it expired. */ export declare function observedMaxOutput(provider: string, model: string, opts?: { path?: string; now?: number; }): number | null; /** Flush pending observations — BOTH halves; the store is shared. Called on shutdown. */ export declare function flushObservedContextLimits(opts?: { path?: string; }): void; /** Test seam: drop the in-memory store so a suite can point at a fresh path. */ export declare function resetObservedContextLimits(): void;