/** * Discovery Cache * * Provides lazy-loaded caching for adapter discovery operations. * Reduces latency for validation and repeated discovery calls. */ import type { DiscoveryCache as IDiscoveryCache } from "@wavespec/types"; /** * Cached tool definition */ export interface CachedTool { /** Tool name (unique identifier) */ name: string; /** Human-readable description */ description?: string; /** JSON Schema for tool input validation */ inputSchema?: Record; } /** * Cached prompt definition */ export interface CachedPrompt { /** Prompt name (unique identifier) */ name: string; /** Human-readable description */ description?: string; /** Prompt arguments */ arguments?: Array<{ name: string; description?: string; required?: boolean; }>; } /** * Cached resource definition */ export interface CachedResource { /** Resource URI (unique identifier) */ uri: string; /** Human-readable name */ name?: string; /** Human-readable description */ description?: string; /** MIME type of the resource */ mimeType?: string; } /** * Fetcher function for lazy loading */ export type Fetcher = () => Promise; /** * Discovery Cache * * In-memory cache for adapter discovery operations (tools, prompts, resources). * Uses lazy loading with fetcher functions - only calls the fetcher once, * then caches the result for subsequent accesses. * * Benefits: * - <10ms cache hits after initial fetch * - Reduces load on protocol servers * - Enables fast pre-validation * * @example * ```typescript * const cache = new DiscoveryCache("server-123"); * * // First call - executes fetcher * const tools1 = await cache.getTools(async () => { * const result = await client.listTools(); * return result.tools; * }); * * // Second call - returns cached value (no fetcher execution) * const tools2 = await cache.getTools(async () => { * // This function never executes * }); * ``` */ export declare class DiscoveryCache implements IDiscoveryCache { private tools?; private prompts?; private resources?; private readonly serverFingerprint; private toolsFetch?; private promptsFetch?; private resourcesFetch?; /** * Create a new discovery cache * * @param serverFingerprint - Unique identifier for the server * (e.g., config hash, URL, connection string) */ constructor(serverFingerprint: string); /** * Get cached tools, fetching on first access * * Uses lazy loading - the fetcher is only called if the cache is empty. * Concurrent calls to this method will share the same fetch promise. * * @param fetcher - Function to fetch tools from server * @returns Cached or freshly-fetched tools */ getTools(fetcher: Fetcher): Promise; /** * Get cached prompts, fetching on first access * * @param fetcher - Function to fetch prompts from server * @returns Cached or freshly-fetched prompts */ getPrompts(fetcher: Fetcher): Promise; /** * Get cached resources, fetching on first access * * @param fetcher - Function to fetch resources from server * @returns Cached or freshly-fetched resources */ getResources(fetcher: Fetcher): Promise; /** * Invalidate cache * * Clears cached values, forcing a re-fetch on next access. * Useful when server capabilities change or for testing. * * @param type - Specific cache to invalidate, or undefined for all */ invalidate(type?: "tools" | "prompts" | "resources"): void; /** * Get server fingerprint * * @returns The server fingerprint this cache is associated with */ getServerFingerprint(): string; /** * Check if a specific cache type is populated * * @param type - Cache type to check * @returns true if cache is populated, false otherwise */ isPopulated(type: "tools" | "prompts" | "resources"): boolean; /** * Get cache statistics * * Useful for debugging and performance monitoring. * * @returns Object with cache population status */ getStats(): { serverFingerprint: string; toolsPopulated: boolean; promptsPopulated: boolean; resourcesPopulated: boolean; toolCount?: number; promptCount?: number; resourceCount?: number; }; } //# sourceMappingURL=cache.d.ts.map