UNPKG

ai-debug-local-mcp

Version:

🎯 ENHANCED AI GUIDANCE v4.1.2: Dramatically improved tool descriptions help AI users choose the right tools instead of 'close enough' options. Ultra-fast keyboard automation (10x speed), universal recording, multi-ecosystem debugging support, and compreh

111 lines 3.91 kB
/** * Lazy Loading System for Third-Party Dependencies * Loads heavyweight dependencies only when actually needed */ export class LazyLoader { static loadedModules = new Map(); static loadingPromises = new Map(); /** * Create a lazy-loaded module wrapper */ static createLazyModule(name, loader, cleanup) { return { async load() { // Return cached module if already loaded if (LazyLoader.loadedModules.has(name)) { console.log(`♻️ Reusing cached module: ${name}`); return LazyLoader.loadedModules.get(name); } // Return existing loading promise if already loading if (LazyLoader.loadingPromises.has(name)) { console.log(`⏳ Waiting for module to load: ${name}`); return LazyLoader.loadingPromises.get(name); } // Start loading console.log(`📦 Lazy loading module: ${name}`); const loadingPromise = loader().then(module => { LazyLoader.loadedModules.set(name, module); LazyLoader.loadingPromises.delete(name); console.log(`✅ Loaded module: ${name}`); return module; }).catch(error => { LazyLoader.loadingPromises.delete(name); console.error(`❌ Failed to load module ${name}:`, error); throw error; }); LazyLoader.loadingPromises.set(name, loadingPromise); return loadingPromise; }, isLoaded() { return LazyLoader.loadedModules.has(name); }, unload() { if (LazyLoader.loadedModules.has(name)) { if (cleanup) { cleanup(); } LazyLoader.loadedModules.delete(name); console.log(`🧹 Unloaded module: ${name}`); } } }; } /** * Get memory usage of loaded modules */ static getLoadedModulesInfo() { return { loaded: Array.from(this.loadedModules.keys()), memoryUsage: process.memoryUsage() }; } /** * Unload all modules to free memory */ static unloadAll() { console.log(`🧹 Unloading all ${this.loadedModules.size} lazy-loaded modules`); this.loadedModules.clear(); this.loadingPromises.clear(); // Force garbage collection if available if (global.gc) { global.gc(); } } } /** * Tool dependency mapping */ export const TOOL_DEPENDENCIES = { // Browser automation tools 'inject_debugging': ['playwright'], 'simulate_user_action': ['playwright'], 'take_screenshot': ['playwright'], 'monitor_realtime': ['playwright'], 'run_audit': ['playwright'], 'mock_network': ['playwright'], // Tidewave integration 'phoenix_debug_liveview': ['tidewave'], 'elixir_attach_to_beam': ['tidewave'], // Framework-specific 'nextjs_debug_hydration': ['playwright', 'nextjs-engine'], 'flutter_debug_canvas': ['playwright', 'flutter-engine'], // Python backend 'python_trace_request': ['python-engine'], 'django_debug_orm': ['python-engine'], // Database 'trace_database_query': ['database-engine'], 'analyze_slow_queries': ['database-engine'] }; /** * Get required dependencies for a tool */ export function getToolDependencies(toolName) { return TOOL_DEPENDENCIES[toolName] || []; } /** * Check if a tool requires any third-party dependencies */ export function requiresThirdPartyDeps(toolName) { return getToolDependencies(toolName).length > 0; } //# sourceMappingURL=lazy-loader.js.map