fix: persist clipboard images as temp files with file:// URLs#22218
fix: persist clipboard images as temp files with file:// URLs#22218dorukardahan wants to merge 2 commits intoanomalyco:devfrom
Conversation
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate FoundPR #21633: fix(tui): save clipboard-pasted images to temp files for MCP tool access Reason: This PR appears to be addressing the same issue as PR #22218. Both are focused on saving clipboard-pasted images to temp files for MCP tool access. PR #21633 specifically mentions the same core functionality of persisting clipboard images for MCP tools. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
Pushed an update: added error handling for the file:// → data: URL conversion in both locations (async path and sync callback). If a temp file has been deleted before conversion, it falls back to a text placeholder instead of crashing the message pipeline. All tests pass. |
Clipboard images are now saved to temp files and referenced via file:// URLs instead of inline data: URLs. This allows MCP tools (look_at, understand_image) to access the file path. Before sending to the AI SDK, file:// URLs are converted back to data: URLs since the SDK rejects file:// schemes. Fixes anomalyco#14673
Add error handling for clipboard image temp files that may be deleted before conversion. Uses async readFile in Promise.all path and try/catch with text fallback in both conversion locations.
4567d68 to
c4f7119
Compare
Issue for this PR
Closes #14673
Type of change
What does this PR do?
When an image is pasted from clipboard, OpenCode stored it as an inline
data:image/...;base64,...URL. MCP tools (look_at,understand_image) expect a file path on disk, not a base64 string, so they couldn't analyze pasted images.This PR:
os.tmpdir()/opencode-clipboard-<timestamp>.png) and keeps the file pathfile://URLs so MCP tools can access the filefile://back todata:URLs before sending to AI SDK (which rejectsfile://scheme)Changes:
clipboard.ts— save temp file, returnfilepathin Content, unique filenames with timestampprompt/index.tsx— passfilepaththrough attachment flow, usefile://URL when filepath existsprompt.ts— usepart.urldirectly instead of re-reading the filemessage-v2.ts— convertfile://→data:before AI SDK consumption (in both user message parts and tool output attachments)How did you verify your code works?
message-v2tests passtsgo --noEmittypecheck passesScreenshots / recordings
No UI changes — purely internal data handling.
Checklist