example.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { createOpencodeClient, createOpencodeServer } from "@opencode-ai/sdk"
  2. const server = await createOpencodeServer()
  3. const client = createOpencodeClient({ baseUrl: server.url })
  4. const input = await Array.fromAsync(new Bun.Glob("packages/core/*.ts").scan())
  5. const tasks: Promise<void>[] = []
  6. for await (const file of input) {
  7. console.log("processing", file)
  8. const session = await client.session.create()
  9. tasks.push(
  10. client.session.prompt({
  11. path: { id: session.data.id },
  12. body: {
  13. parts: [
  14. {
  15. type: "file",
  16. mime: "text/plain",
  17. url: `file://${file}`,
  18. },
  19. {
  20. type: "text",
  21. text: `Write tests for every public function in this file.`,
  22. },
  23. ],
  24. },
  25. }),
  26. )
  27. console.log("done", file)
  28. }
  29. await Promise.all(
  30. input.map(async (file) => {
  31. const session = await client.session.create()
  32. console.log("processing", file)
  33. await client.session.prompt({
  34. path: { id: session.data.id },
  35. body: {
  36. parts: [
  37. {
  38. type: "file",
  39. mime: "text/plain",
  40. url: `file://${file}`,
  41. },
  42. {
  43. type: "text",
  44. text: `Write tests for every public function in this file.`,
  45. },
  46. ],
  47. },
  48. })
  49. console.log("done", file)
  50. }),
  51. )