contextual-agent-sdk
Version:
SDK for building AI agents with seamless voice-text context switching
139 lines (111 loc) โข 4.61 kB
JavaScript
// 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 };