UNPKG

contextual-agent-sdk

Version:

SDK for building AI agents with seamless voice-text context switching

139 lines (111 loc) โ€ข 4.61 kB
// Integration test for Context Bridging Innovation // Run with: npm test or node tests/integration/context-bridging.test.js const { ContextualAgent } = require('../../dist/index.js'); async function testContextBridging() { console.log('๐Ÿงช INTEGRATION TEST: Context Bridging Innovation\n'); const agentConfig = { name: 'Test Agent', mode: 'conversation', systemPrompt: 'You are a helpful assistant.', capabilities: { voiceEnabled: true, textEnabled: true, contextBridging: true, memoryRetention: true, emotionRecognition: false, taskExecution: false }, contextSettings: { maxHistoryLength: 10, contextWindowSize: 4000, relevanceThreshold: 0.7, memoryRetentionDays: 7, modalitySwitchSensitivity: 0.8 } }; const agent = new ContextualAgent(agentConfig); console.log('โœ… Agent initialized successfully'); // Test event system let modalitySwitched = false; let contextBridged = false; agent.on('modality_switched', (event) => { modalitySwitched = true; console.log('๐Ÿ”„ Modality switched:', event.data.from, 'โ†’', event.data.to); }); agent.on('context_bridged', (event) => { contextBridged = true; console.log('๐ŸŒ‰ Context bridged:', event.data.bridgeType); }); const sessionId = 'integration-test-' + Date.now(); try { console.log('\n๐Ÿ“ TEST 1: Text conversation'); const textResponse = await agent.processMessage( 'Hello, I need help with order #12345', 'text', sessionId ); console.log('โœ… Text response received'); console.log(' Content length:', textResponse.data?.message.content.length); console.log(' Response time:', textResponse.metadata.responseTime + 'ms'); console.log('\n๐ŸŽค TEST 2: THE INNOVATION - Modality switch'); const voiceResponse = await agent.switchModality('voice', sessionId); console.log('โœ… Voice switch completed'); console.log(' Modality switched:', modalitySwitched ? 'โœ…' : 'โŒ'); console.log(' Context bridged:', contextBridged ? 'โœ…' : 'โŒ'); console.log('\n๐Ÿ—ฃ๏ธ TEST 3: Voice conversation'); const voiceInput = { type: 'audio', transcription: 'Status update please' }; const voiceContinue = await agent.processMessage(voiceInput, 'voice', sessionId); console.log('โœ… Voice message processed'); console.log('\n๐Ÿ’ฌ TEST 4: Back to text'); const textSwitch = await agent.switchModality('text', sessionId); console.log('โœ… Text switch completed'); // Verify session state const session = await agent.getSession(sessionId); const summary = await agent.getConversationSummary(sessionId); console.log('\n๐Ÿ“Š INTEGRATION TEST RESULTS:'); console.log('โœ… Total messages:', session?.totalMessages); console.log('โœ… Modality switches:', session?.metadata.modalitySwitches); console.log('โœ… Session active:', session ? 'YES' : 'NO'); console.log('โœ… Summary generated:', summary.length > 0 ? 'YES' : 'NO'); // Test assertions const tests = [ { name: 'Agent initialization', passed: agent !== null }, { name: 'Text message processing', passed: textResponse.success }, { name: 'Modality switching', passed: modalitySwitched }, { name: 'Context bridging', passed: contextBridged }, { name: 'Voice processing', passed: voiceContinue.success }, { name: 'Session management', passed: session !== null }, { name: 'Conversation summary', passed: summary.length > 0 } ]; console.log('\n๐Ÿงช TEST RESULTS:'); let passedTests = 0; tests.forEach(test => { const status = test.passed ? 'โœ… PASS' : 'โŒ FAIL'; console.log(` ${status}: ${test.name}`); if (test.passed) passedTests++; }); console.log(`\n๐ŸŽฏ FINAL SCORE: ${passedTests}/${tests.length} tests passed`); if (passedTests === tests.length) { console.log('๐ŸŽ‰ ALL TESTS PASSED - Context Bridging Innovation Works!'); } else { console.log('โš ๏ธ Some tests failed - Check implementation'); } // Cleanup await agent.destroySession(sessionId); await agent.shutdown(); return passedTests === tests.length; } catch (error) { console.error('โŒ Integration test failed:', error.message); return false; } } // Export for test runner or run directly if (require.main === module) { testContextBridging() .then(success => process.exit(success ? 0 : 1)) .catch(error => { console.error(error); process.exit(1); }); } module.exports = { testContextBridging };