test-agent-manual.mjs 886 B

123456789101112131415161718192021222324252627282930313233
  1. import { createOpencodeClient } from '@opencode-ai/sdk';
  2. const client = createOpencodeClient({
  3. baseUrl: 'http://localhost:3721'
  4. });
  5. // Create session
  6. const session = await client.session.create({
  7. body: { title: 'Manual Agent Test' }
  8. });
  9. console.log('Session created:', session.data.id);
  10. // Send prompt with openagent
  11. const response = await client.session.prompt({
  12. path: { id: session.data.id },
  13. body: {
  14. agent: 'openagent',
  15. parts: [{
  16. type: 'text',
  17. text: 'Create a simple TypeScript function called add that takes two numbers and returns their sum. Save it to src/utils/math.ts'
  18. }]
  19. }
  20. });
  21. console.log('\nResponse:', response.data.info);
  22. console.log('\nParts:', response.data.parts.length);
  23. response.data.parts.forEach((p, i) => {
  24. console.log(` Part ${i + 1}: ${p.type}`);
  25. if (p.type === 'tool') {
  26. console.log(` Tool: ${p.tool}`);
  27. }
  28. });