feat: accept any file drag into the chat input - #344
Open
wuxiangru915 wants to merge 2 commits into
Open
Conversation
Dropping a file from the OS file manager onto the chat window now works for any file type, not just images. - Images keep the existing behavior: they are attached as base64 multimodal content and sent with the message. - Other files get their real filesystem path inserted into the input at the caret, so the agent can read them with its own tools. Browsers do not expose the path on File objects, but OS-originated drags carry file:// URIs on the dataTransfer's text/uri-list; since pi-web is a local app the path is directly usable. Falls back to the bare file name when no path is available. - The drop overlay icon now distinguishes image vs file drags. Adds lib/dropped-files.ts with unit-tested parsing logic.
Images were filtered out before resolving paths, so the file count no longer matched the text/uri-list entries and mixed drops (image + file) fell back to bare file names. Resolve paths against the full file list first, then split images from path references.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The chat input currently only accepts image drags (
useDragDropgates onimage/*, andChatInput.addImagesfilters to images). Dropping any other file silently does nothing. This PR makes the drop zone accept any file from the OS file manager.Behavior
Fileobjects, but OS-originated drags putfile://URIs on thedataTransfer'stext/uri-list; since pi-web is a local app, that path is directly usable. Falls back to the bare file name when no path is available (e.g. drag from another browser tab).Why path insertion (not file upload)
pi's agent core
prompt()only supportsimagesattachments, so arbitrary file content cannot be attached end-to-end. Inserting the path lets the agent fetch the file itself and works for every file type, any size.Implementation
lib/dropped-files.ts(new): parsestext/uri-listfile://URIs (POSIX + Windows drive paths, URL decoding, comment/blank lines), a single-filetext/plainfallback, and name fallback. Unit-tested inlib/dropped-files.test.mjs.hooks/useDragDrop.ts: accept anykind === "file"drag, exposedragHasImages, pass thedataTransferto the drop callback (needed to readtext/uri-list, only readable at drop time).components/ChatInput.tsx: newaddFiles(files, dataTransfer)imperative method (images → existing attach flow; others → path insertion). TheinsertTextlogic is factored into a reusableinsertTextAtCursor.components/ChatWindow.tsx: routes drops toaddFiles, swaps the overlay icon based ondragHasImages.hooks/useAgentSession.ts:ChatInputHandleinterface updated in sync.Verification
tsc --noEmitcleaneslintclean on changed filesChatInput.test.mjs