Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apps/mobile/src/features/threads/thread-work-log.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -962,20 +962,21 @@ const ThreadWorkLogRow = memo(function ThreadWorkLogRow(
: row.getFullDetail()
: null;
const outputImages = expanded && fetchedItem ? turnItemOutputImages(fetchedItem) : [];
const viewedImagePath = workEntryViewedImagePath(row.workEntry);
const fetchedOutput = !expanded
? null
: shownItem.type === "file_search" || shownItem.type === "web_search"
? turnItemOutputText(shownItem)
: fetchedItem
? (turnItemOutputText(fetchedItem) ?? (outputImages.length > 0 ? null : "No output."))
? (turnItemOutputText(fetchedItem) ??
(outputImages.length > 0 || viewedImagePath ? null : "No output."))
: fetchedDetail.error
? `Couldn't load output: ${fetchedDetail.error}`
: row.fetchesDetail
? fetchedDetail.data
? "Output is no longer available."
: "Loading output…"
: null;
const viewedImagePath = workEntryViewedImagePath(row.workEntry);
const toolPresentation = resolveWorkEntryToolPresentation(row.workEntry);
const previewText = workEntryRowLabel(row.workEntry);
const answerPreview = row.workEntry.questionAnswer
Expand Down
38 changes: 38 additions & 0 deletions packages/client-runtime/src/work-log/itemDetail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,42 @@ describe("tool output images", () => {
expect(turnItemOutputImages({ ...screenshot, output })).toEqual([]);
expect(turnItemOutputText({ ...screenshot, output })).toBe("[image]");
});

it("omits Claude Read's image placeholder when the file has a preview", () => {
const output = {
type: "image",
file: { filePath: "/tmp/blk.png", type: "image/png", sizeBytes: 1024 },
};
const item = { ...screenshot, toolName: "Read", viewedImagePath: "/tmp/blk.png", output };

expect(turnItemOutputImages(item)).toEqual([]);
expect(turnItemOutputText(item)).toBeNull();
expect(turnItemOutputText({ ...item, viewedImagePath: undefined })).toBe("[image]");
});

it("keeps accompanying text and literal image markers when the file has a preview", () => {
const output = {
content: [
{ type: "text", text: "Read /tmp/blk.png. Literal marker: [image]" },
screenshot.output.content[1],
],
};
expect(turnItemOutputText({ ...screenshot, viewedImagePath: "/tmp/blk.png", output })).toBe(
"Read /tmp/blk.png. Literal marker: [image]",
);
});

it("keeps placeholders for unserved images in a list despite a file preview", () => {
const blocks = [
{ type: "text", text: "Read /tmp/blk.png." },
{ type: "image", file: { type: "image/png", sizeBytes: 1024 } },
screenshot.output.content[1],
{ type: "image", mimeType: "image/svg+xml" },
];
for (const output of [blocks, { content: blocks }, { content: blocks, isError: false }]) {
const item = { ...screenshot, viewedImagePath: "/tmp/blk.png", output };
expect(turnItemOutputText(item)).toBe("Read /tmp/blk.png.\n[image]\n[image]");
expect(turnItemOutputImages(item)).toHaveLength(1);
}
});
});
8 changes: 6 additions & 2 deletions packages/client-runtime/src/work-log/itemDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ function prettyJsonText(text: string): string {
}

/** Formats a tool input or output for display: text blocks as text, the rest as JSON. */
function formatToolValue(value: unknown): string | null {
function formatToolValue(value: unknown, hasImagePreview = false): string | null {
if (value === undefined || value === null) return null;
// Claude Read returns one structured image; lists may contain other images.
if (hasImagePreview && isRecord(value) && value.type === "image") return null;
const text = textFromBlocks(value, 0);
if (text !== null) return text.trim() ? prettyJsonText(text) : null;
let json: string | undefined;
Expand Down Expand Up @@ -171,7 +173,9 @@ export function turnItemOutputText(item: OrchestrationV2TurnItem): string | null
case "command_execution":
return item.output?.trim() ? commandOutputText(item.output) || null : null;
case "dynamic_tool":
return item.outputOmitted === true ? null : formatToolValue(item.output);
return item.outputOmitted === true
? null
: formatToolValue(item.output, item.viewedImagePath !== undefined);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
case "file_search":
return item.results?.length
? item.results
Expand Down
Loading