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
168 lines • 5.74 kB
JavaScript
// Lazy Server Integration - Integrates lazy loading with main server
// Target: 30% startup time improvement through optimized handler loading
import { LazyHandlerRegistry } from './lazy-handler-registry.js';
import { StartupPerformanceTracker } from './startup-performance-tracker.js';
/**
* LazyServerIntegration - Integrates lazy loading with existing server
*/
export class LazyServerIntegration {
lazyRegistry;
tracker;
config;
constructor(config = {}) {
this.lazyRegistry = new LazyHandlerRegistry();
this.tracker = new StartupPerformanceTracker();
this.config = {
coreHandlers: ['core', 'interaction', 'audit'],
lazyHandlers: ['flutter', 'nextjs', 'ai', 'phoenix', 'elixir'],
startupTimeTarget: 1800, // 1.8 seconds
enableProfiling: true,
...config
};
}
/**
* Create optimized handler registration method
*/
createOptimizedRegistration(originalRegistry) {
const coreHandlers = new Set(this.config.coreHandlers);
const lazyHandlers = new Set(this.config.lazyHandlers);
return {
registerHandler: (handler) => {
const handlerName = this.getHandlerName(handler);
if (coreHandlers.has(handlerName)) {
// Register core handlers immediately
originalRegistry.registerHandler(handler);
}
else if (lazyHandlers.has(handlerName) || this.shouldLazyLoad(handlerName)) {
// Register for lazy loading
this.lazyRegistry.registerLazyHandler(handlerName, () => handler, {
priority: this.getHandlerPriority(handlerName),
toolNames: this.extractToolNames(handler),
category: this.getHandlerCategory(handlerName)
});
}
else {
// Default to immediate registration for safety
originalRegistry.registerHandler(handler);
}
},
getHandler: async (name) => {
// Try lazy loading
return await this.lazyRegistry.loadHandler(name);
},
getAllTools: () => {
const immediateTools = originalRegistry.getAllTools();
const lazyTools = this.lazyRegistry.getAvailableToolNames().map(name => ({ name }));
return [...immediateTools, ...lazyTools];
},
getStartupMetrics: () => {
return this.tracker.getMetrics();
}
};
}
/**
* Get handler name from handler instance
*/
getHandlerName(handler) {
if (handler.constructor.name) {
return handler.constructor.name.toLowerCase().replace('handler', '');
}
return 'unknown';
}
/**
* Determine if handler should be lazy loaded
*/
shouldLazyLoad(handlerName) {
// Lazy load handlers that are not core functionality
const lazyPatterns = [
'flutter', 'nextjs', 'ai', 'phoenix', 'elixir', 'graphql',
'bundle', 'route', 'meta', 'evolution', 'ecto', 'liveview'
];
return lazyPatterns.some(pattern => handlerName.includes(pattern));
}
/**
* Get handler priority
*/
getHandlerPriority(handlerName) {
const highPriorityHandlers = ['core', 'interaction', 'audit'];
const lowPriorityHandlers = ['ai', 'evolution', 'maintenance'];
if (highPriorityHandlers.includes(handlerName)) {
return 'high';
}
else if (lowPriorityHandlers.includes(handlerName)) {
return 'low';
}
return 'medium';
}
/**
* Extract tool names from handler
*/
extractToolNames(handler) {
if (handler.tools && Array.isArray(handler.tools)) {
return handler.tools.map((tool) => tool.name);
}
return [];
}
/**
* Get handler category
*/
getHandlerCategory(handlerName) {
const categories = {
'flutter': 'frontend',
'nextjs': 'frontend',
'ai': 'intelligence',
'phoenix': 'backend',
'elixir': 'backend',
'graphql': 'api',
'audit': 'quality',
'core': 'essential',
'interaction': 'essential'
};
for (const [pattern, category] of Object.entries(categories)) {
if (handlerName.includes(pattern)) {
return category;
}
}
return 'utility';
}
/**
* Start performance tracking
*/
startPerformanceTracking() {
this.tracker.startPhase('handler-registration');
}
/**
* End performance tracking
*/
endPerformanceTracking() {
this.tracker.endPhase('handler-registration');
this.tracker.markComplete();
}
/**
* Get performance improvement
*/
getPerformanceImprovement(baselineTime) {
const currentTime = this.tracker.getMetrics().totalStartupTime;
return ((baselineTime - currentTime) / baselineTime) * 100;
}
/**
* Check if startup target is met
*/
meetsStartupTarget() {
const metrics = this.tracker.getMetrics();
return metrics.totalStartupTime <= this.config.startupTimeTarget;
}
/**
* Get lazy registry for advanced operations
*/
getLazyRegistry() {
return this.lazyRegistry;
}
/**
* Get performance tracker
*/
getTracker() {
return this.tracker;
}
}
//# sourceMappingURL=lazy-server-integration.js.map