import { OnModuleDestroy } from "@nestjs/common"; import { ConfigService } from "@nestjs/config"; import { Redis } from "ioredis"; import { BaseConfigInterface } from "../../../config/interfaces"; import { ModelWeight } from "../enums/model.weight"; /** * Builds the cache key for an LLM response. * * GOLDEN RULE: this package is a domain-agnostic library (used by multiple * applications). The key is derived ONLY from generic LLM parameters — model * tier, sampling temperature, system prompts and the prompt itself. It MUST * NOT incorporate any application concept (game/round/memory/etc.); doing so * would both leak app semantics into the library and fragment the cache. * * `CACHE_VERSION` (default `"v1"`) is mixed in so a deployment can invalidate * every cached response at once by bumping the env var — useful when a prompt * template or model mapping changes in a way that should not serve stale hits. * * The hash is sha256 (hex) prefixed with `"llm:"` so keys are easy to scan and * collision-resistant across the whole keyspace. */ export declare function buildCacheKey(params: { modelWeight: ModelWeight; temperature?: number; systemPrompts: string[]; prompt: string; }): string; /** * Redis-backed cache for LLM responses. * * Failure-tolerant by design: Redis is an optimisation, never a dependency of * the primary request path. Any Redis error on read is treated as a miss * (pass-through to the provider); any Redis error on write is swallowed. A * cache outage therefore degrades to "no cache", never to a failed LLM call. * * Follows the package's Redis convention (mirrors `RedisLockService` / * `CacheService`): the client is constructed in-service from `ConfigService` * using `ioredis`. The optional `clientOverride` constructor argument exists * purely as a unit-test seam — Nest's DI never supplies it, so production * always builds a real client. */ export declare class LLMCacheService implements OnModuleDestroy { private readonly logger; private readonly redis; constructor(configService: ConfigService, clientOverride?: Redis); /** * Reads a cached value. A miss, or ANY Redis error, returns `null` so the * caller proceeds to invoke the provider normally. */ get(key: string): Promise; /** * Write-through of a value with a TTL (default 24h). Any Redis error is * swallowed — a failed write must never break the LLM call that produced the * value. */ set(key: string, value: T, ttlSeconds?: number): Promise; onModuleDestroy(): Promise; } //# sourceMappingURL=llm-cache.service.d.ts.map