UNPKG

@tehreet/conduit

Version:

LLM API gateway with intelligent routing, robust process management, and health monitoring

143 lines (121 loc) 3.56 kB
#!/usr/bin/env node // Test Phase 3 implementation const { SynapseIntegration, UsageTracker, UsageStorage, MetricsCollector, ContextExtractor } = require('./dist/lib/index.js'); async function testPhase3() { console.log('Testing Phase 3 - Synapse Integration Layer...'); // Test 1: Context Extraction console.log('\n1. Testing Context Extraction...'); const testEnv = { SYNAPSE_PROJECT_ID: 'test-project-123', SYNAPSE_AGENT_ID: 'test-agent-456', SYNAPSE_AGENT_TYPE: 'code-assistant', SYNAPSE_PROJECT_MODEL_CONFIG: JSON.stringify({ enabled: true, defaultModel: 'anthropic/claude-3-5-sonnet-20241022', maxTokens: 100000 }) }; const context = ContextExtractor.extractSynapseContext(testEnv); console.log('✅ Context extracted:', { projectId: context.projectId, agentId: context.agentId, agentType: context.agentType, hasProjectConfig: !!context.projectModelConfig }); // Test 2: Usage Tracking console.log('\n2. Testing Usage Tracking...'); const usageTracker = new UsageTracker({ enabled: true, storage: { type: 'memory' } }); await usageTracker.initialize(); // Track some usage await usageTracker.trackUsage({ id: 'test-usage-1', timestamp: new Date(), model: 'claude-3-5-sonnet-20241022', tokenCount: 1000, cost: 0.05, routingReason: 'test' }); const stats = await usageTracker.getUsageStats(); console.log('✅ Usage tracking working:', { totalRequests: stats.totalRequests, totalTokens: stats.totalTokens, totalCost: stats.totalCost }); // Test 3: Metrics Collection console.log('\n3. Testing Metrics Collection...'); const metricsCollector = new MetricsCollector({ enabled: true, provider: 'custom' }); await metricsCollector.initialize(); await metricsCollector.record({ id: 'test-metric-1', timestamp: new Date(), model: 'claude-3-5-sonnet-20241022', tokenCount: 500, cost: 0.025, routingReason: 'test' }); const metrics = metricsCollector.getMetrics(); console.log('✅ Metrics collection working:', { totalMetrics: metrics.length, sampleMetric: metrics[0]?.name }); // Test 4: Usage Storage console.log('\n4. Testing Usage Storage...'); const usageStorage = new UsageStorage({ type: 'memory', maxSize: 1000 }); await usageStorage.initialize(); await usageStorage.store({ id: 'test-storage-1', timestamp: new Date(), model: 'claude-3-5-sonnet-20241022', tokenCount: 750, cost: 0.0375, routingReason: 'test' }); const stored = await usageStorage.query({ limit: 10 }); console.log('✅ Usage storage working:', { storedCount: stored.length, firstItem: stored[0]?.id }); // Test 5: Synapse Integration console.log('\n5. Testing Synapse Integration...'); const synapseIntegration = new SynapseIntegration({ Router: { enabled: true }, monitoring: { enabled: true, usage: { enabled: true } }, Providers: [] }); await synapseIntegration.initialize(); // Test routing const result = await synapseIntegration.routeClaudeRequest( ['--model', 'claude-3-5-sonnet-20241022', 'Hello, world!'], testEnv ); console.log('✅ Synapse integration working:', { modelUsed: result.selectedModel, routingSource: result.routingSource, hasContext: !!result.synapseContext }); console.log('\n🎉 All Phase 3 tests passed!'); } // Run the test testPhase3().catch(console.error);