Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import { ThreadId, TurnItemId, type OrchestrationV2TurnItem } from "@t3tools/contracts";
3import * as DateTime from "effect/DateTime";
4
5import { turnItemOutputImages, turnItemOutputText } from "./itemDetail.ts";
6
7function toolItem(output: unknown): OrchestrationV2TurnItem {
8 return {
9 id: TurnItemId.make("images"),
10 threadId: ThreadId.make("thread"),
11 runId: null,
12 nodeId: null,
13 providerThreadId: null,
14 providerTurnId: null,
15 nativeItemRef: null,
16 parentItemId: null,
17 ordinal: 1,
18 status: "completed",
19 title: null,
20 startedAt: null,
21 completedAt: null,
22 updatedAt: DateTime.makeUnsafe("2026-10-01T00:00:00Z"),
23 type: "dynamic_tool",
24 toolName: "screenshots",
25 input: {},
26 output,
27 };
28}
29
30describe("tool image output parsing", () => {
31 it.each(["array", "content"] as const)(
32 "keeps markers for images beyond the served positions in %s output",
33 (shape) => {
34 // Detail responses retain image metadata after the server strips image bytes.
35 const image = { type: "image", mimeType: "image/png" };
36 const blocks = Array.from({ length: 8 }, () => ({ ...image }));
37 const wrap = (content: unknown[]) => (shape === "array" ? content : { content });
38 const withinLimit = toolItem(wrap(blocks));
39 expect(turnItemOutputText(withinLimit)).toBeNull();
40 expect(turnItemOutputImages(withinLimit)).toHaveLength(8);
41
42 const overflow = toolItem(
43 wrap([
44 ...blocks,
45 { type: "text", text: "Two additional screenshots:" },
46 { ...image, sizeBytes: 100 },
47 { type: "image", source: { type: "base64", media_type: "image/jpeg" } },
48 ]),
49 );
50 expect(turnItemOutputImages(overflow)).toHaveLength(8);
51 expect(turnItemOutputText(overflow)).toBe("Two additional screenshots:\n[image]\n[image]");
52 },
53 );
54});