/** * Tool Approval Cache Module * * Features: * - Session-scoped approval caching for tool execution * - Isolated cache per chatId to prevent cross-chat approval leakage * - Timestamp tracking for audit and expiration capabilities * - Singleton pattern for global cache access * * Implementation: * - Two-level Map structure: chatId -> (toolName -> entry) * - Thread-safe operations (no async needed for in-memory cache) * - Automatic cleanup on chat deletion (external trigger) * * Changes: * - 2025-11-03: Initial implementation for tool approval system */ export interface ApprovalCacheEntry { approved: boolean; timestamp: Date; } /** * Approval cache for storing session-scoped tool approvals. * * Architecture: * - chatId isolation: Each chat has its own approval cache * - Session lifecycle: Cleared when chat ends or deleted * - No persistence: In-memory only (cleared on server restart) * * Usage: * ```typescript * // Grant session approval * approvalCache.set('chat-123', 'mcp__filesystem__write_file', true); * * // Check approval * if (approvalCache.get('chat-123', 'mcp__filesystem__write_file')) { * await executeTool(); * } * * // Clear on chat end * approvalCache.clear('chat-123'); * ``` */ export declare class ApprovalCache { private cache; /** * Set approval status for a tool in a specific chat session * * @param chatId - Chat session identifier * @param toolName - Full tool name (e.g., 'mcp__server__toolName') * @param approved - Whether tool is approved */ set(chatId: string, toolName: string, approved: boolean): void; /** * Get approval status for a tool in a specific chat session * * @param chatId - Chat session identifier * @param toolName - Full tool name * @returns true if approved, false if denied, undefined if not cached */ get(chatId: string, toolName: string): boolean | undefined; /** * Check if approval exists for a tool in a specific chat session * * @param chatId - Chat session identifier * @param toolName - Full tool name * @returns true if approval decision exists (approved or denied) */ has(chatId: string, toolName: string): boolean; /** * Clear all approvals for a specific chat session * Called when chat ends or is deleted * * @param chatId - Chat session identifier */ clear(chatId: string): void; /** * Clear all approvals across all chats * Primarily for testing and server restart scenarios */ clearAll(): void; /** * Get all cached tools for a specific chat (for debugging/UI) * * @param chatId - Chat session identifier * @returns Array of [toolName, entry] pairs */ getChatApprovals(chatId: string): Array<[string, ApprovalCacheEntry]>; /** * Get statistics about cache usage (for monitoring) */ getStats(): { totalChats: number; totalApprovals: number; chatsWithApprovals: Array<{ chatId: string; approvalCount: number; }>; }; } /** * Global singleton approval cache instance */ export declare const approvalCache: ApprovalCache;