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

162 lines 6.67 kB
/** * Base Workflow Engine * Revolutionary AI-powered workflow orchestration system * Transforms manual tool selection into intelligent workflow automation */ /** * Base Workflow Engine * Orchestrates intelligent tool sequences with adaptive execution */ export class WorkflowEngine { async execute(context, sessions, toolHandlers) { const template = this.getTemplate(); const results = []; // Execute initial workflow steps let steps = template.steps; for (const step of steps) { // Check conditions for conditional steps if (step.condition && !step.condition(results)) { continue; } try { const startTime = Date.now(); const handler = this.findHandler(step.tool, toolHandlers); if (!handler) { if (!step.optional) { throw new Error(`Required tool handler not found: ${step.tool}`); } continue; } const result = await handler.handle(step.tool, step.args, sessions); const duration = Date.now() - startTime; results.push({ tool: step.tool, result, success: !result.isError, duration, metadata: { optional: step.optional } }); // Adaptive execution - adjust remaining steps based on results const adaptedSteps = template.adaptiveLogic(results); if (adaptedSteps.length > 0) { steps = [...steps, ...adaptedSteps]; } } catch (error) { results.push({ tool: step.tool, result: { error: error instanceof Error ? error.message : String(error) }, success: false, duration: 0 }); if (!step.optional) { break; // Stop workflow on critical failures } } } // Generate intelligent summary const summary = template.generateSummary(results, context); const nextSteps = this.generateNextSteps(results, context); return { results, summary, nextSteps }; } findHandler(toolName, toolHandlers) { // Find the handler that contains this tool for (const handler of toolHandlers.values()) { if (handler.tools && handler.tools.some((t) => t.name === toolName)) { return handler; } } return null; } generateNextSteps(results, context) { const nextSteps = []; const failures = results.filter(r => !r.success); const successes = results.filter(r => r.success); // AI-powered next step generation based on results if (failures.length > 0) { nextSteps.push(`🔧 Address ${failures.length} failed operations`); failures.forEach(failure => { nextSteps.push(` - Retry ${failure.tool} with adjusted parameters`); }); } if (successes.length > 0) { nextSteps.push(`✅ Successfully completed ${successes.length} operations`); // Suggest follow-up workflows based on intelligence level if (context.intelligenceLevel === 'expert') { nextSteps.push(`🧠 Consider advanced analysis workflows`); nextSteps.push(`📊 Run comparative analysis with previous sessions`); } } // Context-specific recommendations if (context.frameworks.includes('flutter')) { nextSteps.push(`🎯 Use smart_flutter_analysis for deeper Flutter insights`); } return nextSteps; } /** * Format workflow results into rich, narrative output */ formatResults(workflowName, results, context) { const sections = [ `🚀 **${workflowName} Workflow Complete**`, '', `**Context**: ${context.userIntent}`, `**Intelligence Level**: ${context.intelligenceLevel.toUpperCase()}`, `**Frameworks**: ${context.frameworks.join(', ') || 'Auto-detected'}`, `**Session ID**: ${context.sessionId || 'Standalone'}`, '' ]; // Execution summary const successful = results.filter(r => r.success).length; const total = results.length; const totalTime = results.reduce((sum, r) => sum + r.duration, 0); sections.push('## 📊 **Workflow Execution Summary**'); sections.push(`**Tools Executed**: ${total}`); sections.push(`**✅ Successful**: ${successful}`); sections.push(`**❌ Failed**: ${total - successful}`); sections.push(`**⏱️ Total Time**: ${totalTime}ms`); sections.push(`**Success Rate**: ${Math.round((successful / total) * 100)}%`); sections.push(''); return sections; } /** * Extract key insights from workflow results */ extractInsights(results) { const insights = []; // Analyze patterns in results const errorPatterns = this.detectErrorPatterns(results); const performancePatterns = this.detectPerformancePatterns(results); if (errorPatterns.length > 0) { insights.push('🔍 **Error Patterns Detected**:'); errorPatterns.forEach(pattern => insights.push(` - ${pattern}`)); insights.push(''); } if (performancePatterns.length > 0) { insights.push('⚡ **Performance Insights**:'); performancePatterns.forEach(pattern => insights.push(` - ${pattern}`)); insights.push(''); } return insights; } detectErrorPatterns(results) { const patterns = []; const failures = results.filter(r => !r.success); if (failures.length > 0) { patterns.push(`${failures.length} operations failed - investigate tool dependencies`); } return patterns; } detectPerformancePatterns(results) { const patterns = []; const slowOperations = results.filter(r => r.duration > 5000); if (slowOperations.length > 0) { patterns.push(`${slowOperations.length} slow operations detected (>5s)`); slowOperations.forEach(op => { patterns.push(`${op.tool}: ${op.duration}ms`); }); } return patterns; } } //# sourceMappingURL=workflow-engine.js.map