feat(tui): support drag-and-drop for .docx and .xlsx files#32104
Open
GP-commits wants to merge 3 commits into
Open
feat(tui): support drag-and-drop for .docx and .xlsx files#32104GP-commits wants to merge 3 commits into
GP-commits wants to merge 3 commits into
Conversation
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.
Issue for this PR
Closes #27689
Type of change
What does this PR do?
The TUI had no way to attach
.docxor.xlsxfiles — they were either rejected outright or fell through to the binary-file error in the read tool. This PR adds Office file support across three surfaces:TUI drag-and-drop (
packages/tui)When a
.docxor.xlsxis dropped into the prompt, a newoffice-converter.tsmodule converts it to Markdown text and inlines it into the prompt. For.docx, we usemammoth.convertToHtml()(the currently recommended API —convertToMarkdownis deprecated per the mammoth README) and then convert the HTML to GFM Markdown, preserving headings, tables, lists, bold/italic, and links. For.xlsx, we use SheetJSsheet_to_json({ header: 1 })to render each sheet as a Markdown table.Read tool (
packages/opencode)read.tspreviously had.docxand.xlsxhardcoded inisBinaryFile()and would fail with "Cannot read binary file". Now, before that check, it detects Office extensions and runs the same converter, returning the Markdown inside<content>tags so the LLM can process it like any other file.Desktop file picker (
packages/app)Added the two MIME types to
ACCEPTED_FILE_TYPESandMIME_EXTso the Electron file picker dialog accepts.docx/.xlsx.How did you verify your code works?
bun test test/prompt/).docxconversion,.xlsxconversion (with Markdown table output), and graceful handling of empty/unreadable files.xlsxround-trip smoke test: built a workbook with SheetJS, converted it back, confirmed the Markdown table output including correct pipe-escaping in cellsbun typecheckpasses clean in bothpackages/opencodeandpackages/tuiScreenshots / recordings
This is a TUI/backend change with no visual UI difference beyond the drag-and-drop accepting the new file types. The prompt behaviour after dropping a file is the same as pasting text — the file content appears inline with a
[DOCX: filename]label.Checklist