The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 19:30 UTC
fix(chat): mark tool images beyond the preview limit (#23595)
Co-authored-by: GPT-6.1 Sol <noreply@openai.com>
Victor Vogel committed
Oct 22, 2026 at 11:58 UTC
f05599504ae10c395a6a39f5e7db31b7810ac239
2 files changed
+66
-7
packages/client-runtime/src/work-log/itemDetail.test.ts
new
+54
@@ -0,0 +1,54 @@
1
+import { describe, expect, it } from "vite-plus/test";
2
+import { ThreadId, TurnItemId, type OrchestrationV2TurnItem } from "@t3tools/contracts";
3
+import * as DateTime from "effect/DateTime";
4
+
5
+import { turnItemOutputImages, turnItemOutputText } from "./itemDetail.ts";
6
+
7
+function 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
+
30
+describe("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
+});
packages/client-runtime/src/work-log/itemDetail.ts
+12
-7
@@ -1,5 +1,5 @@
1
import type { AssetResource, OrchestrationV2TurnItem } from "@t3tools/contracts";
2
-import { readToolOutputImage, toolOutputImages } from "@t3tools/shared/toolOutput";
2
+import { toolOutputImageBlocks, toolOutputImages } from "@t3tools/shared/toolOutput";
3
import * as DateTime from "effect/DateTime";
4
5
const MAX_TEXT_BLOCK_DEPTH = 4;
@@ -12,18 +12,22 @@ function isSummarizedValue(value: unknown): boolean {
12
return isRecord(value) && value.truncated === true && typeof value.summary === "string";
13
}
14
15
-function textFromBlocks(value: unknown, depth: number): string | null {
15
+function textFromBlocks(
16
+ value: unknown,
17
+ depth: number,
18
+ imageBlocks: ReadonlyArray<unknown>,
19
+): string | null {
20
if (depth > MAX_TEXT_BLOCK_DEPTH) return null;
21
if (typeof value === "string") return value;
22
if (Array.isArray(value)) {
19
- const parts = value.map((block) => textFromBlocks(block, depth + 1));
23
+ const parts = value.map((block) => textFromBlocks(block, depth + 1, imageBlocks));
24
return parts.every((part) => part !== null)
25
? parts.filter((part) => part !== "").join("\n")
26
: null;
27
}
28
if (!isRecord(value)) return null;
29
if (value.type === "text" && typeof value.text === "string") return value.text;
26
- if (value.type === "image") return readToolOutputImage(value) ? "" : "[image]";
30
+ if (value.type === "image") return imageBlocks.includes(value) ? "" : "[image]";
31
if (value.type === "resource_link" && typeof value.uri === "string") return value.uri;
32
if (value.type === "resource" && isRecord(value.resource)) {
33
const resource = value.resource;
@@ -31,9 +35,10 @@ function textFromBlocks(value: unknown, depth: number): string | null {
35
if (typeof resource.uri === "string") return resource.uri;
36
}
37
const keys = Object.keys(value).filter((key) => key !== "isError" && key !== "is_error");
34
- if (keys.length === 1 && keys[0] === "content") return textFromBlocks(value.content, depth + 1);
38
+ if (keys.length === 1 && keys[0] === "content")
39
+ return textFromBlocks(value.content, depth + 1, imageBlocks);
40
if (keys.length === 2 && keys.includes("content") && keys.includes("structuredContent")) {
36
- const text = textFromBlocks(value.content, depth + 1);
41
+ const text = textFromBlocks(value.content, depth + 1, imageBlocks);
42
return text?.trim() ? text : null;
43
}
44
return null;
@@ -61,7 +66,7 @@ function prettyJsonText(text: string): string {
66
function formatToolValue(value: unknown, hasImagePreview = false): string | null {
67
if (value === undefined || value === null) return null;
68
if (hasImagePreview && isRecord(value) && value.type === "image") return null;
64
- const text = textFromBlocks(value, 0);
69
+ const text = textFromBlocks(value, 0, toolOutputImageBlocks(value));
70
if (text !== null) return text.trim() ? prettyJsonText(text) : null;
71
let json: string | undefined;
72
try {