/** * Guards a provider-prepared model request at the final dispatch seam. * Providers supply the complete JSON-safe request projection they assembled; * the guard admits it once, freezes its plain request graph, and proves every * retry is byte-identical before the transport can run. */ import { type ModelAttemptLease } from "../streaming-context.js"; export interface PreparedModelRequestBudget { provider: string; model: string; inputTokens: number; contextWindowTokens: number; outputReserveTokens: number; dispatchThresholdTokens: number; countSource: "provider-tokenizer" | "tokenizer-estimate" | "utf8-upper-bound"; rejectionAuthority: "exact-provider-tokenizer-with-explicit-limits" | "diagnostic-only"; resolvedModelKey: string | null; } export interface PreparedModelRequestGuard { readonly budget: Readonly; readonly attempts: number; /** Rechecks preparation after asynchronous serialization without counting a dispatch. */ assertUnchanged(): void; /** Revalidates the exact admitted body immediately before one transport try. */ assertBeforeAttempt(): void; } export interface CreatePreparedModelRequestGuardArgs { provider: string; model: string; /** Actual provider transport route, required only by bounded host policy. */ route?: string; /** Trusted provider closure; null keeps an earlier graph check non-financial. */ attemptLease?: ModelAttemptLease | null; /** * Rebuild the complete provider request projection from the actual dispatch * object. The projection must contain every model-visible field, but omit * transport-only collaborators such as fetch functions and AbortSignal. */ projectRequest?: () => unknown; /** * Return the exact already-serialized transport body. Use this at fetch and * SDK seams where re-projecting JSON would not prove wire-byte identity. */ serializeRequest?: () => string; /** Provider/model hard ceiling when it is known more precisely than lookup. */ contextWindowTokens?: number; /** Actual requested output cap, or the model maximum when the field is omitted. */ outputReserveTokens?: number; /** Provider tokenizer over the serialized prepared body, when available. */ countInputTokens?: (serializedRequest: string) => number; /** * Assert that `countInputTokens` uses the exact tokenizer for the selected * provider deployment. Static fallback encodings and estimates must omit it. */ countInputTokensIsExact?: true; } /** * Admit one complete provider-prepared request and return its retry guard. * Construction itself is the zero-dispatch rejection point; callers then must * invoke `assertBeforeAttempt` directly before every SDK/fetch attempt. */ export declare function createPreparedModelRequestGuard(args: CreatePreparedModelRequestGuardArgs): PreparedModelRequestGuard;