opencode
opencode copied to clipboard
fix: enable image file reading in read tool (fixes #451)
The read tool was throwing an error for image files instead of reading them. This fix implements proper image handling by converting images to base64 data URLs, allowing opencode to read PNG, JPEG, and other image formats as documented. Should fix #451
It looks like there are server side validations enforcing a 5mb limit and a 2000px limit. It should handle if it's corrupt as well. I have some code I could push to validate client-side if we'd like to provide immediate feedback without an API request/network round trip. The trade-off is additional complexity and the need to maintain these limits in sync with the API. Happy to push the client-side validation or keep the simpler approach.
i think rather than checking against limits that may change we want to just do a resize and compress step for all image uploads greater than some threshold (or maybe just all images). lmk if you want to take a stab at that. should be done on the TS server side so that other clients benefit as well.
@adamdotdevin I've implemented the server-side image processing as you suggested. The changes include:
- Added sharp dependency for image processing
- Created an ImageProcessor utility that:
- Resizes images to max 2000x2000 pixels
- Converts images to JPEG format for better compression
- Ensures images stay under 5MB through quality optimization
- Updated tests to work with the processed images
Let me know if you'd like any adjustments to the implementation!