UNPKG

@agentx-ai/agentx-js

Version:

Official JavaScript/TypeScript SDK for AgentX (https://www.agentx.so/)

105 lines (87 loc) • 3.57 kB
import { AgentX } from "./src/agentx"; import { Conversation } from "./src/resources/conversation"; const API_KEY = "your agentx api key"; const AGENT_ID = "your agent id"; const CONVERSATION_ID = "your conversation id"; async function testStreaming() { try { // Initialize AgentX with your API key const agentx = new AgentX(API_KEY); console.log("šŸ” Testing AgentX Streaming Functionality"); console.log("=".repeat(60)); // Test 1: List agents console.log("\nšŸ“‹ Step 1: Listing available agents..."); const agents = await agentx.listAgents(); console.log(`āœ… Found ${agents.length} agents`); if (agents.length > 0) { console.log("Available agents:"); agents.forEach((agent, index) => { console.log(` ${index + 1}. ${agent.name} (${agent.id})`); }); } // Test 2: List workforces console.log("\nšŸ“‹ Step 2: Listing available workforces..."); const workforces = await agentx.listWorkforces(); console.log(`āœ… Found ${workforces.length} workforces`); if (workforces.length > 0) { console.log("Available workforces:"); workforces.forEach((workforce, index) => { console.log(` ${index + 1}. ${workforce.name} (${workforce.id})`); }); } // Test 3: Get profile console.log("\nšŸ“‹ Step 3: Getting user profile..."); const profile = await agentx.getProfile(); console.log("āœ… Profile retrieved successfully"); console.log("User info:", { name: profile.name, email: profile.email, id: profile._id, }); // Test 4: Test streaming (if you have a conversation ID) console.log("\nšŸ“‹ Step 4: Testing chat streaming..."); console.log("šŸš€ Starting stream test with existing conversation..."); // Using the conversation ID from the curl example const conversation = new Conversation({ agent_id: AGENT_ID, // Website Prompter agent id: CONVERSATION_ID, // Conversation ID from curl example users: [], agents: [], }); console.log("šŸš€ Starting stream test..."); const stream = conversation.chatStream("How can you help me?", 0); let chunkCount = 0; const startTime = Date.now(); for await (const chunk of stream) { chunkCount++; const elapsed = Date.now() - startTime; console.log(`\nšŸ“¦ Chunk ${chunkCount} (${elapsed}ms)`); console.log(" Text:", chunk.text || "null"); console.log(" CoT:", chunk.cot || "null"); console.log(" Bot ID:", chunk.botId); } const totalTime = Date.now() - startTime; console.log( `\nāœ… Stream completed in ${totalTime}ms with ${chunkCount} chunks` ); console.log("\nšŸŽÆ Testing Summary:"); console.log("āœ… API connection: Working"); console.log("āœ… Agents listing: Working"); console.log("āœ… Workforces listing: Working"); console.log("āœ… Profile retrieval: Working"); console.log("āš ļø Streaming test: Requires conversation ID"); console.log("\nšŸ“ To test streaming:"); console.log("1. Create a conversation in AgentX platform"); console.log("2. Update the conversation ID in the test script"); console.log("3. Uncomment the streaming test section"); console.log("4. Run: npx ts-node test-streaming.ts"); } catch (error: any) { console.error("āŒ Error during testing:", error); if (error.response) { console.error("Response status:", error.response.status); console.error("Response data:", error.response.data); } } } // Run the test testStreaming();