UNPKG

adk-typescript

Version:

TypeScript port of Google's Agent Development Kit (ADK)

67 lines (66 loc) 2.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); // A test script to verify that sessions are created and retrieved correctly const inMemorySessionService_1 = require("../sessions/inMemorySessionService"); const uuid_1 = require("uuid"); console.log('Testing session creation and retrieval...'); // Create the session service const sessionService = new inMemorySessionService_1.InMemorySessionService(); // Test parameters const appName = 'test_app'; const userId = 'test_user'; const sessionId = (0, uuid_1.v4)(); const state = { key: 'value' }; console.log(`Creating session with appName=${appName}, userId=${userId}, sessionId=${sessionId}`); // Create a session const session = sessionService.createSession({ appName, userId, sessionId, state }); console.log(`Created session: id=${session.id}, appName=${session.appName}`); // Try to retrieve the session console.log(`Retrieving session with appName=${appName}, userId=${userId}, sessionId=${sessionId}`); const retrievedSession = sessionService.getSession({ appName, userId, sessionId }); if (retrievedSession) { console.log(`Retrieved session: id=${retrievedSession.id}, appName=${retrievedSession.appName}`); console.log('Session state:', retrievedSession.state); console.log('Session was retrieved successfully!'); } else { console.error('Failed to retrieve session!'); } // Try with a non-existent session ID const nonExistentSessionId = (0, uuid_1.v4)(); console.log(`Attempting to retrieve non-existent session with id=${nonExistentSessionId}`); const nonExistentSession = sessionService.getSession({ appName, userId, sessionId: nonExistentSessionId }); if (!nonExistentSession) { console.log('Correctly returned null for non-existent session'); } else { console.error('ERROR: Retrieved a session that should not exist!'); } // Try with a non-existent app name const nonExistentAppName = 'non_existent_app'; console.log(`Attempting to retrieve session with non-existent appName=${nonExistentAppName}`); const nonExistentAppSession = sessionService.getSession({ appName: nonExistentAppName, userId, sessionId }); if (!nonExistentAppSession) { console.log('Correctly returned null for session with non-existent app name'); } else { console.error('ERROR: Retrieved a session with non-existent app name!'); } console.log('Session testing complete!');