import { EnclaveClient } from '@enclave-vm/client';
async function main() {
// Create client
const client = new EnclaveClient({
serverUrl: 'http://localhost:3001',
auth: {
type: 'bearer',
token: process.env.API_TOKEN,
},
reconnection: {
enabled: true,
maxAttempts: 3,
},
timeout: 60000,
});
// Check health
const health = await client.health();
console.log('Broker status:', health.status);
// Execute with tool handling
const code = `
const users = await callTool('users:list', { limit: 5 });
console.log('Found', users.length, 'users');
for (const user of users) {
console.log('Processing:', user.name);
}
return { count: users.length };
`;
const result = await client.executeWithToolHandler(
code,
async (name, args) => {
switch (name) {
case 'users:list':
return [
{ id: '1', name: 'Alice' },
{ id: '2', name: 'Bob' },
].slice(0, args.limit);
default:
throw new Error(`Unknown tool: ${name}`);
}
},
{
timeout: 30000,
filter: {
blockedTypes: ['heartbeat'],
},
}
);
console.log('Result:', result.value);
console.log('Stats:', result.stats);
}
main().catch(console.error);