Skip to content

feat(tools): add image support to read_file tool#5172

Merged
mrubens merged 21 commits intoRooCodeInc:mainfrom
samhvw8:feat/read-file-image
Jul 29, 2025
Merged

feat(tools): add image support to read_file tool#5172
mrubens merged 21 commits intoRooCodeInc:mainfrom
samhvw8:feat/read-file-image

Conversation

@samhvw8
Copy link
Contributor

@samhvw8 samhvw8 commented Jun 27, 2025

Related GitHub Issue

Closes: #5169

Description

  • Add support for reading and displaying image files (PNG, JPG, JPEG, GIF, WebP, SVG, BMP, ICO, TIFF)
  • Implement readImageAsDataUrl function to convert images to base64 data URLs with proper MIME types
  • Return multi-part responses containing both XML metadata and image data
  • Add dimension extraction for PNG files when possible
  • Add comprehensive test coverage for image reading functionality including format detection, error handling, and edge cases
  • Maintain backward compatibility for non-image binary files

Test Procedure

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

Documentation Updates

Additional Notes

Get in Touch


Important

Adds image support to read_file tool, enabling reading and displaying images as base64 data URLs with comprehensive test coverage.

  • Behavior:
    • Adds image support to read_file tool in readFileTool.ts, supporting formats like PNG, JPG, GIF, etc.
    • Implements readImageAsDataUrl() to convert images to base64 data URLs.
    • Returns multi-part responses with XML metadata and image data.
    • Extracts dimensions for PNG files when possible.
    • Maintains backward compatibility for non-image binary files.
  • Tests:
    • Adds tests in readFileTool.spec.ts for image reading, format detection, error handling, and edge cases.
    • Mocks fs/promises and other dependencies for testing.
  • Misc:
    • Updates SUPPORTED_IMAGE_FORMATS and MAX_IMAGE_FILE_SIZE_BYTES constants in readFileTool.ts.

This description was created by Ellipsis for 3214f02b7b429926adb744e5911e9c1a4cc5858a. You can customize this summary. It will automatically update as commits are pushed.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jun 27, 2025
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. Enhancement New feature or request labels Jun 27, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jun 27, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jun 27, 2025
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Draft / In Progress] in Roo Code Roadmap Jun 27, 2025
@samhvw8 samhvw8 force-pushed the feat/read-file-image branch from 0ad2410 to e85d4d5 Compare July 1, 2025 15:26
@samhvw8 samhvw8 marked this pull request as ready for review July 1, 2025 15:48
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jul 1, 2025
@samhvw8 samhvw8 force-pushed the feat/read-file-image branch 2 times, most recently from 119bc82 to df342d7 Compare July 2, 2025 13:58
@daniel-lxs daniel-lxs moved this from PR [Draft / In Progress] to PR [Needs Prelim Review] in Roo Code Roadmap Jul 2, 2025
Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @samhvw8, I know that different providers have different implementations for image handling, so I'm concerned this centralized approach might break with some providers.

Should we use the provider specific implementations for reading images?

Let me know what you think.

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jul 2, 2025
@samhvw8 samhvw8 force-pushed the feat/read-file-image branch from 85d7699 to 1dc79ce Compare July 25, 2025 16:56
@daniel-lxs daniel-lxs moved this from PR [Changes Requested] to PR [Needs Prelim Review] in Roo Code Roadmap Jul 25, 2025
@daniel-lxs
Copy link
Member

Hey @samhvw8 thank you for addressing the review! I noticed an unit test is failing, can you take a look?

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jul 25, 2025
@samhvw8
Copy link
Contributor Author

samhvw8 commented Jul 26, 2025

@daniel-lxs i fixed the test can you review it again

- Replace maxTotalImageMemory with maxTotalImageSize throughout codebase
- Update all translation files with new terminology
- Fix incorrect key names in pt-BR, zh-CN, and zh-TW translations
- Improve clarity of size limit messages
- Update tests to reflect new terminology
- Extract image validation logic into validateImageForProcessing function
- Extract image processing logic into processImageFile function
- Add ImageMemoryTracker class to encapsulate memory tracking
- Add proper TypeScript interfaces for validation and processing results
- Reduce code duplication and improve separation of concerns
Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @samhvw8

@rwydaegh rwydaegh mentioned this pull request Aug 7, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request lgtm This PR has been approved by a maintainer PR - Needs Review size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

Support read image in read file tool

4 participants