prompt-content.subprocess.test.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import type { PromptResponse } from "@agentclientprotocol/sdk"
  2. import { describe, expect, test } from "bun:test"
  3. import path from "node:path"
  4. import { pathToFileURL } from "node:url"
  5. import { createAcpFixture, expectOk, initialize, newSession } from "./subprocess"
  6. const tinyPng = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+ip1sAAAAASUVORK5CYII="
  7. describe("acp prompt content subprocess", () => {
  8. test("accepts embedded text resource image and file resource link prompt content", async () => {
  9. await using fixture = await createAcpFixture()
  10. await Bun.write(path.join(fixture.home, "README.md"), "# ACP content smoke\n")
  11. const acp = fixture.spawn()
  12. await initialize(acp)
  13. const session = await newSession(acp, fixture.home)
  14. expectOk(
  15. await acp.request<PromptResponse>("session/prompt", {
  16. sessionId: session.sessionId,
  17. prompt: [
  18. { type: "text", text: "Use this embedded resource." },
  19. {
  20. type: "resource",
  21. resource: { uri: "file:///context.txt", mimeType: "text/plain", text: "embedded context" },
  22. },
  23. ],
  24. }),
  25. )
  26. expectOk(
  27. await acp.request<PromptResponse>("session/prompt", {
  28. sessionId: session.sessionId,
  29. prompt: [
  30. { type: "text", text: "Use this image." },
  31. {
  32. type: "image",
  33. mimeType: "image/png",
  34. data: tinyPng,
  35. },
  36. ],
  37. }),
  38. )
  39. const linked = expectOk(
  40. await acp.request<PromptResponse>("session/prompt", {
  41. sessionId: session.sessionId,
  42. prompt: [
  43. { type: "text", text: "Use this linked file." },
  44. {
  45. type: "resource_link",
  46. uri: pathToFileURL(path.join(fixture.home, "README.md")).href,
  47. name: "README.md",
  48. mimeType: "text/markdown",
  49. },
  50. ],
  51. }),
  52. )
  53. expect(linked.stopReason).toBe("end_turn")
  54. expect(fixture.llm.requests.length).toBeGreaterThanOrEqual(3)
  55. }, 60_000)
  56. })