UNPKG

@entro314labs/ai-changelog-generator

Version:

AI-powered changelog generator with MCP server support - works with most providers, online and local models

67 lines (66 loc) 2.95 kB
/** * Language-model response cache, as a Vercel AI SDK middleware. * * Changelog generation is highly repetitive across runs: previewing with * `--dry-run` and then generating for real, re-running after a failed provider * call, or regenerating the same release, all re-send byte-identical prompts for * commits whose diffs have not changed. Caching on the model boundary removes * that repeat cost without any call site having to know about it. * * Key: SHA-256 over the model identity plus the RESPONSE-AFFECTING call * parameters only (see `responseAffectingParams`). Transport/runtime fields * (`abortSignal`, `headers`) are deliberately excluded — they vary per call and * would defeat the cache entirely without changing what the model returns. * * Storage is a small in-memory LRU in front of a JSON-file cache under the * user's cache directory, so hits survive across CLI invocations (the case that * actually matters here — a single run rarely repeats a prompt). * * Every failure path falls OPEN: a cache problem returns the freshly generated * result rather than turning a working generation into an error. Streaming * (`wrapStream`) is intentionally not cached — this package never streams model * output into a changelog. */ import type { LanguageModelMiddleware } from 'ai'; export declare function defaultCacheDirectory(): string; /** * Opt-out via AI_CACHE_ENABLED=false. Caching is on by default because a stale * entry can only occur for a byte-identical prompt to the same model, which by * construction would have produced an equivalent answer. */ export declare function isModelCacheEnabled(): boolean; /** * Deterministic serialization: plain JSON.stringify is key-order dependent, so * two structurally identical parameter objects could hash differently and miss. */ export declare function stableStringify(value: unknown): string; /** * The subset of call parameters that can change what the model returns. * Anything omitted here is transport or bookkeeping. */ export declare function responseAffectingParams(params: Record<string, any>): { prompt: any; maxOutputTokens: any; temperature: any; stopSequences: any; topP: any; topK: any; presencePenalty: any; frequencyPenalty: any; responseFormat: any; seed: any; tools: any; toolChoice: any; providerOptions: any; }; export declare function fingerprint(model: Record<string, any>, params: Record<string, any>): string; export interface ModelCacheOptions { ttlSeconds?: number; cacheDir?: string; /** Reported on a hit so callers can surface cache usage. */ onHit?: (key: string) => void; onMiss?: (key: string) => void; } export declare function createModelCacheMiddleware(options?: ModelCacheOptions): LanguageModelMiddleware; /** Exposed for tests: drops the in-process layer without touching disk. */ export declare function clearModelCacheMemory(): void;