import type { CacheAdapter } from '../cache-adapter.js'; /** * The cache store the registry can use. This is the framework's neutral * {@link CacheAdapter} — the AiProvider hands in a real adapter at boot, and * the registry falls back to an in-process `Map` when none is supplied. */ export type CacheStoreLike = CacheAdapter; export interface GoogleCacheRegistryOptions { /** Optional cache backend (cross-process / cross-restart). Falls back to in-process Map. */ store?: CacheStoreLike; /** Default TTL for newly-created Google `cachedContent` resources. Default `'1h'`. */ defaultTtl?: string; } export interface ResolveArgs { /** Live `@google/genai` client. */ client: GoogleClientLike; /** Model id the request is going to. Caches are model-bound. */ model: string; /** Stable hash of cached regions (system + tools + leading-N messages, by model). */ cacheKey: string; systemInstruction?: { parts: { text: string; }[]; } | undefined; contents?: unknown[] | undefined; tools?: unknown[] | undefined; /** Override the registry's default TTL for this call. Duration string. */ ttl?: string | undefined; } export interface GoogleClientLike { caches: { create(args: { model: string; config: { systemInstruction?: { parts: { text: string; }[]; }; contents?: unknown[]; tools?: unknown[]; ttl?: string; displayName?: string; }; }): Promise<{ name: string; expireTime?: string; }>; delete?(args: { name: string; }): Promise; }; } /** * Owns the `cacheKey → cachedContents/*` resource-name map for the Google * provider. Coordinates concurrent creates, memoizes "too-small" failures, * and drops stale entries on demand (so the adapter can recreate-on-404). * * Storage is pluggable: the AiProvider passes a {@link CacheAdapter} when one * is available, otherwise the registry uses an in-process `Map` and warns once. * Either way, in-process locking keeps concurrent same-key requests from racing * on `caches.create` within one worker. */ export declare class GoogleCacheRegistry { private readonly store?; private readonly memory; private readonly inFlight; private readonly defaultTtl; private readonly now; private warnedNoStore; constructor(opts?: GoogleCacheRegistryOptions); /** * Returns the `cachedContents/*` resource name for `args.cacheKey`, * creating a Google cache resource if one doesn't exist yet. Returns * `null` when the prompt is below the model's minimum-cacheable size * (the failure is memoized for ~5min so a tight loop doesn't pound the * create endpoint). */ resolve(args: ResolveArgs): Promise; /** * Drop a cached entry — used when `generateContent` returns 404 because * the resource expired between create and use. The adapter recreates by * calling `resolve()` again. */ forget(cacheKey: string): Promise; private lookup; private remember; private expiryFromTtl; } /** * Build a stable cache key for a Google request. The key combines the * model id with the marked regions — switching models invalidates the * cache (Google ties resources to a single model id). */ export declare function buildGoogleCacheKey(model: string, cache: { instructions?: boolean; tools?: boolean; messages?: number; } | undefined, system: string | undefined, contents: unknown[], tools: unknown[] | undefined): string | undefined; /** * Split a `contents` array at the cache breakpoint. The first part is what * lives inside the cached resource; the second part is what the request * sends fresh on every call. */ export declare function splitContentsAtCache(contents: unknown[], cache: { messages?: number; } | undefined): { cached: unknown[]; fresh: unknown[]; }; /** * Parse a duration string into milliseconds. Accepts plain seconds-string * (`'3600s'`) or compact units (`'1h'`, `'30m'`, `'1d'`). Falls back to * 1 hour on unparseable input. */ declare function parseDurationMs(s: string): number; declare function isTooSmallError(err: unknown): boolean; declare function isNotFoundError(err: unknown): boolean; export declare const _internals: { isTooSmallError: typeof isTooSmallError; isNotFoundError: typeof isNotFoundError; parseDurationMs: typeof parseDurationMs; }; export {}; //# sourceMappingURL=google-cache-registry.d.ts.map