-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-cloud.js
More file actions
81 lines (65 loc) · 2.44 KB
/
test-cloud.js
File metadata and controls
81 lines (65 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env node
import { ContinuationHandler } from './cli/continuation-handler.js';
import { generateAgentUrls } from './cli/config-utils.js';
// Test cloud agent tool call flow
async function testCloudAgentFlow() {
console.log('🧪 Testing Cloud Agent Tool Call Flow...\n');
// Get dynamic cloud agent URL
const { cloudCoderUrl } = await generateAgentUrls('local');
const CLOUD_AGENT_URL = cloudCoderUrl;
const API_KEY = process.env.API_KEY || 'test-key-for-demo';
const sessionId = `test_${Date.now()}`;
try {
// Step 1: Send message to cloud agent
console.log('📤 Step 1: Sending message to cloud agent...');
const response = await fetch(CLOUD_AGENT_URL, {
method: 'POST',
headers: {
'Content-Type': 'text/plain',
Authorization: `Bearer ${API_KEY}`,
'x-session-id': sessionId,
},
body: 'Please list the files in the current directory',
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
// Step 2: Read the streaming response
console.log('📥 Step 2: Reading streaming response...');
let fullResponse = '';
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value, { stream: true });
fullResponse += chunk;
process.stdout.write(chunk);
}
console.log('\n\n🔍 Step 3: Checking for tool calls...');
// Step 3: Handle tool calls with continuation handler
const continuationHandler = new ContinuationHandler();
const result = await continuationHandler.handleToolCallFlow(
fullResponse,
CLOUD_AGENT_URL,
API_KEY,
sessionId
);
if (result.needsContinuation && result.continuationResponse) {
console.log('\n📤 Step 4: Streaming continuation response...');
const contReader = result.continuationResponse.body.getReader();
while (true) {
const { done, value } = await contReader.read();
if (done) break;
const chunk = decoder.decode(value, { stream: true });
process.stdout.write(chunk);
}
console.log('\n\n✅ Cloud agent tool call flow completed successfully!');
} else {
console.log('\n⚠️ No tool calls detected in response');
}
} catch (error) {
console.error('\n❌ Test failed:', error);
}
}
testCloudAgentFlow();