Skip to content

Commit 9efa40b

Browse files
edgarsskoreclaude
andauthored
refactor(read_file): carry image base64 once in structuredContent (#526)
The image read_file result duplicated the base64 in structuredContent as both `content` and `imageData`. Drop the `imageData` field and have the preview widget render from the single `content` field, halving the image structuredContent payload. No behavior change: the content[] image block (LLM vision) and the widget's data URI are both intact. Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
1 parent cd4a80d commit 9efa40b

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/handlers/filesystem-handlers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ export async function handleReadFile(args: unknown): Promise<ServerResult> {
175175
fileType: 'image',
176176
sourceTool: 'read_file',
177177
...await getDefaultEditorMetadata(resolvedFilePath),
178+
// Image bytes for the preview widget, carried once. Deduped from the
179+
// old `content` + `imageData` pair down to this single `content` field.
178180
content: imageData,
179-
imageData,
180181
mimeType: fileResult.mimeType
181182
}
182183
};

src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ export interface FilePreviewStructuredContent {
8282
sourceTool?: 'read_file' | 'write_file' | 'edit_block';
8383
defaultEditorName?: string;
8484
defaultEditorPath?: string;
85+
// For text/markdown this is the file text; for images it is the base64 image
86+
// payload (single source — the preview UI renders the <img> from this).
8587
content?: string;
86-
imageData?: string;
8788
mimeType?: string;
8889
}
8990

src/ui/file-preview/src/file-type-handlers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ function renderImageBody(payload: RenderPayload): RenderBodyResult {
2222
};
2323
}
2424

25-
if (!payload.imageData || payload.imageData.trim().length === 0) {
25+
if (!payload.content || payload.content.trim().length === 0) {
2626
return {
2727
notice: 'Preview is unavailable because image data is missing.',
2828
html: '<div class="panel-content source-content"></div>',
2929
};
3030
}
3131

32-
const src = `data:${mimeType};base64,${payload.imageData}`;
32+
const src = `data:${mimeType};base64,${payload.content}`;
3333
return {
3434
html: `<div class="panel-content image-content"><div class="image-preview"><img src="${escapeHtml(src)}" alt="${escapeHtml(payload.fileName)}" loading="eager" decoding="async"></div></div>`,
3535
};

0 commit comments

Comments
 (0)