Skip to content

Conversation

@kylecarbs
Copy link
Member

The file_read tool now properly reads images and sends them to AI models as media content instead of trying to parse them as text.

Implementation:

Added toModelOutput function to file_read tool that detects images by MIME type and returns them in the AI SDK's media content format. The AI SDK's convertToModelMessages automatically uses this when converting tool results.

Changes:

  • Detect MIME types using mime-types package
  • Read images as base64-encoded binary data
  • Use toModelOutput to convert images to media content blocks
  • Update UI component to display image previews
  • Text files continue to work with existing line-numbered format

Testing:

Added tests for PNG/JPEG reading, MIME type detection, and toModelOutput conversion. All 18 file_read tests pass.


Generated with cmux

@kylecarbs kylecarbs requested a review from ammario October 20, 2025 22:59
- Detect MIME types using mime-types package
- Read images as base64 binary data
- Use toModelOutput to send images as media content to AI models
- Update UI to display image previews
- Add comprehensive tests for image reading and conversion
This is the critical missing piece - without passing tools to
convertToModelMessages, the toModelOutput function is never called
and images are sent as JSON instead of media content.

Added test to verify image tool results are converted to media
content when tools are provided to convertToModelMessages.
- Use async fs.promises.writeFile instead of sync
- Use optional chaining for toolMessage checks
- Add eslint-disable for unavoidable any assignment
@kylecarbs kylecarbs force-pushed the allow-reading-images branch from 58c4326 to c728067 Compare October 20, 2025 23:55
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.

1 participant