/** * In-memory cache for documents the viewer pages through. * * The chunk tool addresses a document by character offset, so it has to keep * reading the *same* string the first response was cut from — a re-fetch can * produce a different metadata header and shift every offset. The cache is what * makes that string outlive a single tool call. * * It is created per `registerAllTools()` call, which means per session on HTTP * and per process on stdio, and is bounded by a character budget rather than by * entry count alone: with `MAX_SESSIONS = 100` any per-session entry limit is * multiplied by a hundred, and RIS documents differ in size by two orders of * magnitude. */ import type { OutlineEntry } from './formatting.js'; /** A document as the viewer consumes it: rendered text plus its jump targets. */ export interface CachedDocument { /** Markdown rendering, exactly as ris_dokument produced it — before truncation. */ text: string; outline: OutlineEntry[]; /** URL the HTML came from. */ sourceUrl: string; } export interface DocumentCache { /** Looks up `key` directly, then as an alias. */ get(key: string): CachedDocument | undefined; /** `alias` is the resolved content URL; ignored when equal to `key`. */ set(key: string, value: CachedDocument, alias?: string): void; /** Live entries — for tests and diagnostics. */ readonly size: number; /** Characters currently held — the bound that actually matters. */ readonly chars: number; } export interface DocumentCacheOptions { maxEntries?: number; maxChars?: number; ttlMs?: number; /** Injectable clock; tests drive TTL expiry without timers. */ now?: () => number; } /** * Create a bounded, least-recently-used document cache. * * A document is reachable under two keys: its Dokumentnummer and its resolved * content URL. `ris_dokument` and the chunk tool may each be called with either * one, and nothing guarantees the viewer holds the same identifier the document * was opened with — a single key would miss on exactly that crossing and turn * every chunk into a fetch, which looks correct and is merely slow. */ export declare function createDocumentCache(options?: DocumentCacheOptions): DocumentCache; //# sourceMappingURL=document-cache.d.ts.map