Skip to content

refactor(read_file): carry image base64 once in structuredContent - #526

Merged
wonderwhy-er merged 1 commit into
mainfrom
refactor/dedup-image-base64
Jun 26, 2026
Merged

refactor(read_file): carry image base64 once in structuredContent#526
wonderwhy-er merged 1 commit into
mainfrom
refactor/dedup-image-base64

Conversation

@edgarsskore

@edgarsskore edgarsskore commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

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.

Summary by CodeRabbit

  • Bug Fixes
    • Simplified file preview data handling so image previews now rely on a single content field.
    • Improved image preview validation to better detect missing or empty image data.
    • Kept preview output behavior the same while making image rendering more consistent.

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) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e4f54687-2358-4126-8a0d-8c0bc3c8a006

📥 Commits

Reviewing files that changed from the base of the PR and between cd4a80d and 26ef999.

📒 Files selected for processing (3)
  • src/handlers/filesystem-handlers.ts
  • src/types.ts
  • src/ui/file-preview/src/file-type-handlers.ts

📝 Walkthrough

Walkthrough

The PR consolidates file preview image payloads onto a single content field in shared types, the filesystem read handler, and the image preview renderer. The image preview UI now reads and validates that field when building the base64 data URL.

Changes

Unified file preview payload

Layer / File(s) Summary
Shared payload contract
src/types.ts, src/handlers/filesystem-handlers.ts
FilePreviewStructuredContent uses a single content field for preview data, and the image branch in handleReadFile emits that field for image bytes.
Image preview rendering
src/ui/file-preview/src/file-type-handlers.ts
renderImageBody validates payload.content and uses it to construct the data:<mime>;base64,... image source.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

size:L

Poem

🐇 I hopped through bytes of image light,
One content field made everything right.
No extra fluff, just base64 gleam,
A tidy preview in a rabbit dream.
Ears up high, the pixels sing!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main change: refactoring read_file to store image base64 once in structuredContent.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/dedup-image-base64

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@wonderwhy-er
wonderwhy-er merged commit 9efa40b into main Jun 26, 2026
2 checks passed
wonderwhy-er added a commit that referenced this pull request Jun 26, 2026
* test: align file-preview tests with #524 and #526

Two tests trailed the latest contract changes:

- test-file-handlers.js: #526 dropped structuredContent.imageData and
  carries the image base64 only in structuredContent.content. Update the
  image/SVG assertions to read content instead of the removed field.
- test-markdown-preview.js: #524 tags read_file calls with origin:'ui'.
  The Test 9 and Test 11 mocks asserted exact read_file args via
  deepStrictEqual; add origin:'ui' so the full-document reload and the
  failed-save resync paths match again.

No source changes; both were stale tests, not regressions.

* Release v0.2.43

Automated release commit with version bump from 0.2.42 to 0.2.43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants