-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_opencode_connection.js
More file actions
56 lines (47 loc) · 1.44 KB
/
Copy pathtest_opencode_connection.js
File metadata and controls
56 lines (47 loc) · 1.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
import { createOpencode } from '@opencode-ai/sdk';
async function testOpenCodeConnection() {
try {
console.log('Testing OpenCode connection...');
const result = await createOpencode({
hostname: '127.0.0.1',
port: 4096,
provider: {
default: {
options: {
timeout: false,
},
},
},
});
console.log('Connection successful!');
console.log('Client:', !!result.client);
console.log('Server:', !!result.server);
// Test a simple prompt
if (result.client) {
console.log('Testing prompt...');
const session = await result.client.session.create({
body: { title: 'Test Session' }
});
console.log('Session created:', session.data?.id);
if (session.data?.id) {
const promptResult = await result.client.session.prompt({
path: { id: session.data.id },
body: {
parts: [{ type: 'text', text: 'Say hello!' }]
}
});
console.log('Prompt result:', promptResult);
// Clean up
await result.client.session.delete({ path: { id: session.data.id } });
}
}
return true;
} catch (error) {
console.error('Connection test failed:', error);
console.error('Error details:', JSON.stringify(error, null, 2));
return false;
}
}
testOpenCodeConnection().then(success => {
process.exit(success ? 0 : 1);
});