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 4.02 kB
/** * V2 Lazy Loading System for Third-Party Dependencies * Loads heavyweight dependencies only when actually needed * Optimized for stateless HTTP server architecture */ export class V2LazyLoader { static loadedModules = new Map(); static loadingPromises = new Map(); /** * Create a lazy-loaded module wrapper for V2 architecture */ static createLazyModule(name, loader, cleanup) { return { async load() { // Return cached module if already loaded if (V2LazyLoader.loadedModules.has(name)) { console.error(`♻️ V2 Reusing cached module: ${name}`); return V2LazyLoader.loadedModules.get(name); } // Return existing loading promise if already loading if (V2LazyLoader.loadingPromises.has(name)) { console.log(`⏳ V2 Waiting for module to load: ${name}`); return V2LazyLoader.loadingPromises.get(name); } // Start loading console.error(`📦 V2 Lazy loading module: ${name}`); const loadingPromise = loader().then(module => { V2LazyLoader.loadedModules.set(name, module); V2LazyLoader.loadingPromises.delete(name); console.error(`✅ V2 Loaded module: ${name}`); return module; }).catch(error => { V2LazyLoader.loadingPromises.delete(name); console.error(`❌ V2 Failed to load module ${name}:`, error); throw error; }); V2LazyLoader.loadingPromises.set(name, loadingPromise); return loadingPromise; }, isLoaded() { return V2LazyLoader.loadedModules.has(name); }, unload() { if (V2LazyLoader.loadedModules.has(name)) { if (cleanup) { cleanup(); } V2LazyLoader.loadedModules.delete(name); console.error(`🧹 V2 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.error(`🧹 V2 Unloading all ${this.loadedModules.size} lazy-loaded modules`); this.loadedModules.clear(); this.loadingPromises.clear(); // Force garbage collection if available if (global.gc) { global.gc(); } } } /** * V2 Tool dependency mapping */ export const V2_TOOL_DEPENDENCIES = { // Browser automation tools 'inject_debugging': ['playwright'], 'simulate_user_action': ['playwright'], 'take_screenshot': ['playwright'], 'monitor_realtime': ['playwright'], 'run_audit': ['playwright'], 'mock_network': ['playwright'], // Sub-agent delegation tools 'delegate_to_debug_agent': ['task-tool'], 'smart_debug': ['task-tool'], 'auto_audit': ['task-tool'], // Framework-specific 'nextjs_debug_hydration': ['playwright', 'nextjs-engine'], 'flutter_debug_canvas': ['playwright', 'flutter-engine'], // Performance analysis 'performance_baseline': ['playwright'], 'performance_profile': ['playwright'], 'analyze_bundles': ['webpack-analyzer'] }; /** * Get required dependencies for a tool */ export function getV2ToolDependencies(toolName) { return V2_TOOL_DEPENDENCIES[toolName] || []; } /** * Check if a tool requires any third-party dependencies */ export function v2RequiresThirdPartyDeps(toolName) { return getV2ToolDependencies(toolName).length > 0; } //# sourceMappingURL=lazy-loader.js.map