test-image-artifact-store.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import type { ToolArtifactStorePort } from "@zcode/contracts";
  2. export function createTestImageArtifactStore(): ToolArtifactStorePort {
  3. const artifacts = new Map<string, { content: string; contentType: string }>();
  4. let artifactIndex = 0;
  5. return {
  6. async writeToolResultArtifact(request) {
  7. artifactIndex++;
  8. const id = `test-image-${artifactIndex}`;
  9. const uri = `zcode-artifact://${encodeURIComponent(request.sessionId)}/${id}`;
  10. const contentType = request.contentType ?? "text/plain";
  11. artifacts.set(uri, { content: request.content, contentType });
  12. return {
  13. bytes: Buffer.byteLength(request.content, "utf8"),
  14. contentType,
  15. createdAt: new Date(0),
  16. id,
  17. uri,
  18. };
  19. },
  20. async readToolResultArtifact(request) {
  21. const artifact = artifacts.get(request.uri);
  22. if (!artifact) throw new Error(`Missing test image artifact: ${request.uri}`);
  23. return {
  24. bytes: Buffer.byteLength(artifact.content, "utf8"),
  25. content: artifact.content,
  26. contentType: artifact.contentType,
  27. uri: request.uri,
  28. };
  29. },
  30. async ensureMediaAttachmentPath(request) {
  31. return {
  32. status: "ready",
  33. path: `/tmp/zcode-test-image-cache/${encodeURIComponent(request.uri)}.png`,
  34. } as const;
  35. },
  36. };
  37. }