Skip to content

Attach clipboard images pasted into the chat box#1740

Open
iyernaveenr wants to merge 1 commit into
eigent-ai:mainfrom
iyernaveenr:naveen_r_iyer/fix-image-paste
Open

Attach clipboard images pasted into the chat box#1740
iyernaveenr wants to merge 1 commit into
eigent-ai:mainfrom
iyernaveenr:naveen_r_iyer/fix-image-paste

Conversation

@iyernaveenr

Copy link
Copy Markdown

Problem

Pasting an image from the clipboard (e.g. a screenshot) into the chat input does nothing. Only plain text pastes work; attaching an image requires the file picker or drag-and-drop, which is a detour for the most common flow of sharing a screenshot with the agent.

Root cause

The rich input's paste handler calls preventDefault() and then reads only clipboardData.getData('text/plain'); clipboard file items are never inspected, so pasted images are silently discarded. The attachment pipeline is path-based (FileAttachment.filePath), and unlike drag-and-dropped files, pasted File objects carry no filesystem path, so they could not simply be forwarded to the existing drop handler.

Fix

Route pasted file items into the existing attachment flow:

  • RichChatInput gains an onPasteFiles callback; its paste handler now extracts clipboard file items (clipboardData.items -> getAsFile()) and forwards them, while still inserting any plain text on the clipboard (some sources provide both).
  • Desktop: a new save-pasted-file IPC handler persists the pasted bytes to a temporary directory and returns the path, since pasted files have no path of their own. A new processPastedFiles helper (mirroring processDroppedFiles) uses it and merges the result into the existing attachments, deduplicated by path.
  • Web: pasted files are uploaded exactly like dropped files.
  • The input box applies the same gating as drag-and-drop (attachments disabled in privacy-off / cloud-model-in-dev states) and shows the same success/error toasts.

All pasted file kinds are forwarded, so copying a file from a file manager and pasting it also attaches it.

Testing

Verified on Linux desktop: copying a screenshot to the clipboard and pressing Ctrl+V in the chat box attaches it as a file chip (with toast), and the agent can read the attached image in the run; plain-text paste and drag-and-drop behave as before. tsc passes; lint passes for the changed files.

Pasting into the chat box previously handled only plain text; clipboard
file items such as screenshots were silently dropped. Route pasted file
items into the existing attachment flow: persist the pasted bytes to a
temporary file through the desktop bridge (pasted files carry no
filesystem path), or upload them like dropped files on web, and attach
the result exactly like drag-and-drop. Text on the clipboard is still
inserted as before.

Signed-off-by: Naveen R. Iyer <iyernaveenr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants