/** * The identity inputs that define a cache entry. Two requests with the same * model, prompt, system instructions and schema are considered the same call and share a cache slot. * The schema is included because changing the requested shape changes the model * output, so it must change the key. */ export interface CacheKeyParts { /** * The requested model id or alias (e.g. `haiku`). The exact requested string * enters the key, so an alias keeps hitting its existing cache entries even * when the provider later resolves fresh requests to a newer model snapshot. */ model: string; /** The fully-rendered prompt string. */ prompt: string; /** Optional system instructions that can change the requested behavior. */ system?: string; /** The JSON Schema the response must conform to. */ schema: Record; } /** * Provenance recorded on entries written under the FINGERPRINT-keyed scheme * (`src/pipeline/fingerprint.ts`). Purely informational โ€” the key is still the * request's `cacheKey` โ€” but it lets a human (or a migration) tell which * function an entry belongs to without recomputing anything. Absent on entries * written by older versions; readers must tolerate that. */ export interface CacheEntryMeta { /** The structural fingerprint of the function text the entry was proposed for. */ fingerprint: string; /** The absolute file the function lived in when the entry was written. */ fileName?: string; /** The function's name when it has one (declarations, methods). */ functionName?: string; } /** * The on-disk shape of one cached entry. Stores the validated value plus the * call metadata reporting needs so a cache hit reconstructs a full result * without a fresh model call. */ export interface CacheEntry { /** The schema-validated value the provider returned. */ value: T; /** Cost in USD of the ORIGINAL call that produced this entry. */ costUsd: number; /** The model id that actually served the original call. */ model: string; /** Raw model text before parsing, when the original call exposed it. */ rawText?: string; /** Fingerprint provenance; written on new entries, absent on legacy ones. */ meta?: CacheEntryMeta; } /** * Compute the content-addressed cache key for a request: the hex SHA-256 of the * model, prompt, system instructions and stably-serialized schema joined by delimiters that cannot * occur in the inputs themselves. Deterministic: identical inputs always yield * an identical key, across processes and machines. */ export declare function computeCacheKey(parts: CacheKeyParts): string; /** * A small content-addressed JSON-file cache rooted at a single directory. Each * entry lives in its own `.json` file, so reads and writes are independent * and the cache can be shared or committed (development-plan ยง8 open question * #4) without a central index file to contend on. */ export declare class ResponseCache { #private; /** * @param dir Directory under which cache files are stored. Created lazily on * the first {@link set}. Relative paths resolve against the process cwd โ€” * callers pass the configured `cacheDir` (default `.stryker-llm-cache`). */ constructor(dir: string); /** * Look up a cached entry by its precomputed key. Resolves to the stored * {@link CacheEntry} on a hit, or `undefined` on a miss (including when the * cache directory does not exist yet). A corrupt/unparseable file is treated * as a miss rather than throwing, so a damaged cache degrades to a cold run. */ get(key: string): Promise | undefined>; /** * Store an entry under its key, creating the cache directory if needed. The * write is atomic-ish per file (a single `writeFile`); entries never share a * file so concurrent writes to distinct keys do not clobber each other. */ set(key: string, entry: CacheEntry): Promise; /** * Every key currently stored: ONE directory listing (not a stat per probe), * so a caller that must ask "is this target cached?" for thousands of * targets does it against an in-memory set. An absent cache directory is an * empty set. Only `.json` files count; other files are ignored. */ keys(): Promise>; /** * Convenience over {@link computeCacheKey} + {@link get}: look up by the * request's content parts directly. */ getByParts(parts: CacheKeyParts): Promise | undefined>; /** * Convenience over {@link computeCacheKey} + {@link set}: store by the * request's content parts directly. */ setByParts(parts: CacheKeyParts, entry: CacheEntry): Promise; }