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

173 lines • 6.46 kB
import { BaseToolHandler } from './base-handler.js'; import { PhoenixTestGeneratorAI } from '../phoenix-test-generator-ai.js'; export class PhoenixTestGenerationHandler extends BaseToolHandler { phoenixGenerator; tools = [ { name: 'phoenix_generate_tests', description: 'Generate ExUnit test code from Phoenix/LiveView debugging session', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'The debugging session ID containing Phoenix events' }, framework: { type: 'string', enum: ['exunit'], default: 'exunit', description: 'Test framework to generate for' }, options: { type: 'object', properties: { includeVisualAssertions: { type: 'boolean', default: false }, includeChannelTests: { type: 'boolean', default: false }, includeEctoTests: { type: 'boolean', default: false }, includeSetupFunctions: { type: 'boolean', default: false }, testModule: { type: 'string', description: 'Custom test module name' } } } }, required: ['sessionId'] } }, { name: 'phoenix_analyze_events', description: 'Analyze Phoenix debugging events to understand patterns and complexity', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'The debugging session ID to analyze' } }, required: ['sessionId'] } } ]; constructor() { super(); this.phoenixGenerator = new PhoenixTestGeneratorAI(); } async handle(toolName, args, sessions) { switch (toolName) { case 'phoenix_generate_tests': return this.handlePhoenixGenerateTests(args, sessions); case 'phoenix_analyze_events': return this.handlePhoenixAnalyzeEvents(args, sessions); default: throw new Error(`Tool not found: ${toolName}`); } } // Compatibility method for tests getToolNames() { return this.tools.map(tool => tool.name); } // Compatibility method for tests async callTool(name, args, providedSessions) { const sessions = providedSessions || new Map(); return this.handle(name, args, sessions); } async handlePhoenixGenerateTests(args, sessions) { // Validate required arguments if (!args.sessionId) { throw new Error('Missing required argument: sessionId'); } const { sessionId, framework = 'exunit', options = {} } = args; // Get session from storage or create a mock session for testing let session = sessions.get(sessionId); if (!session) { // For now, create a simple empty session to handle the case // In real implementation, this would come from actual session storage session = { id: sessionId, timestamp: new Date(), duration: 0, url: 'http://localhost:4000', events: [], metadata: { testIntent: 'Generated Phoenix test' } }; } try { // Configure the Phoenix generator with options const generator = new PhoenixTestGeneratorAI({ framework: 'phoenix', includeVisualAssertions: options.includeVisualAssertions || false, includeChannelTests: options.includeChannelTests || false, includeEctoTests: options.includeEctoTests || false, includeSetupFunctions: options.includeSetupFunctions || false, testModule: options.testModule }); // Generate the test code const testCode = await generator.generateTest(session); return { content: [ { type: 'text', text: testCode } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error generating Phoenix tests: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } } async handlePhoenixAnalyzeEvents(args, sessions) { // Validate required arguments if (!args.sessionId) { throw new Error('Missing required argument: sessionId'); } const { sessionId } = args; // Get session from storage let session = sessions.get(sessionId); if (!session) { return { content: [ { type: 'text', text: 'Session not found' } ], isError: true }; } try { // Analyze the Phoenix events using the generator const analysis = this.phoenixGenerator.analyzePhoenixEvents(session.events); return { content: [ { type: 'text', text: JSON.stringify(analysis, null, 2) } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error analyzing Phoenix events: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } } } //# sourceMappingURL=phoenix-test-generation-handler.js.map