Repository navigation
open every attachment type in a preview modal - #8655
Conversation
Clicking an attachment tile only opened a lightbox for images. Documents, PDFs and audio had no way to see what was attached beyond the filename tooltip. Every attachment kind now opens a modal: images keep the existing lightbox, audio plays through AudioPlayer, and anything text-bearing (txt, code, csv, html, pdf, docx, odt, ods) renders in a scrollable panel with the filename, size, line count and the source format the text came from. Text comes from the same extraction the adapters send to the model, so a composer preview shows exactly what the model will receive. The PDF, DOCX and HTML extractors move into features/chat/attachment-content.ts and the adapters in runtime-provider.tsx call them instead of inlining their own copy. A sent attachment no longer holds its File, so the preview unwraps the "[PDF: name]" header or <attachment name=...> tag the adapter wrote. Extraction starts on first open, not on mount, and long files stop at 200k characters. AudioPlayer takes an optional filename so an attachment download keeps its own name instead of "generated-audio.wav".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 27ae1bd2aa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (isPdfAttachment(name, contentType)) { | ||
| return { label: "PDF", text: await extractPdfAttachmentText(file) }; |
There was a problem hiding this comment.
Match preview extraction to the adapter that accepted the file
When a file's MIME and extension disagree, these extension-or-MIME checks can select a different extractor from the attachment adapter. For example, runtime-provider.tsx registers TextAttachmentAdapter before PDFAttachmentAdapter, so a report.pdf whose browser reports text/plain is sent to the model as plain text, but this branch attempts to parse it with unpdf and shows an error instead of the text the model receives. Reuse the adapter's resolved kind or apply the same precedence when choosing the preview extractor.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this. It needs a file whose extension and MIME disagree, which the browser does not produce for a real .pdf (it derives application/pdf from the extension). Matching the composite adapter's precedence would mean duplicating its accept-matching in the preview, which is more surface than the case is worth.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7cf1afffa8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (isPdfAttachment(name, contentType)) { | ||
| return { label: "PDF", text: await extractPdfAttachmentText(file) }; | ||
| } | ||
| if (isDocxAttachment(name, contentType)) { | ||
| return { label: "DOCX", text: await extractDocxAttachmentText(file) }; |
There was a problem hiding this comment.
Bound PDF and DOCX files before extracting previews
When a user opens a large or highly compressed PDF/DOCX attachment in the composer, these branches still materialize the entire file and its extracted text before the 200,000-character display cap is applied; unlike OpenDocument files, the corresponding adapters impose no size limit. Clicking such an attachment can therefore freeze or exhaust the webview without sending it, so reject oversized files or use a bounded/worker-based preview extraction path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this. PDF and DOCX are container formats: a byte slice is not parseable, so there is no bounded read to do, and the same full-file extraction already runs in PDFAttachmentAdapter.send and DocxAttachmentAdapter.send when the message is sent. The preview adds no failure mode that sending does not already have; an upload size gate belongs in those adapters' accept path, which is outside this PR.
| if (isOpenDocumentAttachment(name, contentType)) { | ||
| const { label, text } = await readOpenDocumentAttachmentContent( | ||
| file, | ||
| name, | ||
| contentType ?? "", | ||
| ); |
There was a problem hiding this comment.
Reuse the OpenDocument extraction already in progress
When a user clicks an ODT/ODS attachment in the composer, OpenDocumentAttachmentAdapter.add is already parsing and caching that file, but this branch starts an independent arrayBuffer read, synchronous unzip, DOM parse, and text extraction. For an allowed archive near the 50 MB limit this duplicates substantial main-thread work and memory—potentially concurrently if the tile is opened while upload status is still running—so expose/reuse the adapter's cached extraction rather than parsing the same document again for its preview.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this. The duplicate parse is extra work, not wrong output, and the adapter's cache is keyed by attachment id inside OpenDocumentAttachmentAdapter with no route to a React component. Threading an adapter instance through the preview for a repeat parse that is already capped at 50 MB is more surface than the case warrants.
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Built two isolated Studios, one at this PR's merge base The control shot, the composer with the chip attached before any click, is byte-identical on the two sides, which is what makes the second shot mean something. The thing most likely to be wrong here is not wrongThe preview text and the text actually sent to the model cannot drift. The extraction bodies moved out of the adapters into I also expected the remove X to end up nested inside the new Two real gaps, both about unbounded parsing on the main thread
Smaller
Tests
It leaves untested exactly the three branches from the findings above: PDF, DOCX and ODT in Nice change, and the modal itself reads well. |
6ce75e0 to
c3f91f6
Compare
|
Took this over and pushed a commit bounding the document parsers. Re-ran the two-install evidence afterwards against the fixed head. Before and afterBefore: a non-image attachment was filename-only. Clicking the chip did nothing. After: it opens a preview modal with the extracted text. The control shot, the composer with the chip attached before any click, is byte-identical on the two sides, which is what makes the second shot mean anything. Real feature gap. Cross-browser, driven against the real Studio: the modal opens with the full extracted text in Chromium, Firefox and WebKit alike. WebKit counts double here since Tauri uses the platform webview, WebKitGTK on Linux and WKWebView on macOS. What I pushed1. PDF and DOCX preview extraction had no size guard. Both branches called
2. DOCX was an unbounded decompression-bomb vector; ODT was not. The two ceilings are the existing 3. Audio. The guards live in the extractors rather than in Does it break anythingOnly in the intended direction, and the ceilings were chosen so ordinary files are unaffected: a normal PDF and a normal DOCX still extract, which the new tests pin as controls. The thing most likely to have been wrong in this PR was not: the preview text and the text actually sent to the model cannot drift. The extraction bodies moved out of the adapters into I also expected the remove X to end up nested inside the new Object URLs are created per open and revoked in the effect cleanup, including unmount-while-open. An image attachment holds two at once, since TestsFive new cases, and they were checked against a stashed source tree so they actually bite: The bomb test builds a real zip whose Still not covered by testsThe PDF, DOCX and ODT branches of One thing to know before mergingThis branch now conflicts with main in Nice change, and the modal reads well. |
|
Before/after evidence for the preview modal, produced with Both homes are fed the same two files, written from constants by the scene, so the size and the line count the dialog reports are properties of the build and not of the input: Clicking the Clicking the Read off the two servers that were photographed:
The tile count is the control. Both halves attach both files, so the pair isolates what the click does rather than whether the attach worked. Those 18 lines are the extraction change turning up in the evidence: the same 849 B read through Out of scene on purpose: the image lightbox and the audio player. Downloadable copy. The same two composites plus the fixtures that produced them, published by a disposable workflow on the staging branch Run: https://github.com/mahiatlinux/unsloth/actions/runs/32025582308 (green)
Both fixtures are byte-identical to what the two installs read, so |
|
Ran a targeted live A/B on the exact base (44afbdf) and this PR. The CI run reproduces the bug before the change in Edge—clicking a document opens no dialog—then passes on Windows Chrome, Windows Edge, and macOS WebKit after it. The after-cases cover TXT, HTML, PDF, DOCX, ODT, truncation, oversized-file rejection with the draft preserved, and mobile dialog bounds. I also got 3,632/3,632 frontend tests plus typecheck/build locally. So the issue is real and I found no regression in the tested attachment paths. Small cleanup before merge: the restricted deep import and unused audio blob URL are still worth addressing. Also, macOS here is Playwright WebKit, not branded Safari. |
|
Fixed both attachment-preview findings in 0fb5837: PDF document proxies are now destroyed in a finally block after successful or failed extraction, and preview dispatch now shares the text adapter accept list and honors its precedence for text/plain files named .pdf, .docx, or .html. Validation: 59 attachment-focused tests passed; frontend typecheck and production build passed; targeted ESLint had 0 errors (3 existing react-refresh warnings). No full native browser modal journey was rerun. |
|
is it intentional that Html preview extracts the text instead of showing the actual html file contents? |
The preview modal extracted an html file's rendered text, so the dialog never showed the file itself. The html branch of readAttachmentText now returns the raw bounded source with no label, and the html extensions map to shiki's html grammar, so a page previews with syntax colours the same way a python file does. The adapter still sends the extracted text to the model, and a sent attachment keeps previewing that extraction.
|
It was intentional at first: the preview mirrored the extraction the model receives. But you are right that for an HTML file the source is more useful, so as of 26e427c an HTML attachment previews as its raw markup with syntax highlighting, exactly like the Python preview. The adapter still sends the extracted text to the model, so opening a sent attachment keeps showing that extraction, which is the payload the model actually got. |
|
@codex review |
The desktop reliability contract pinned downloadUrl(src, "generated-audio.wav"), but audio-player.tsx now passes the attachment's own filename and keeps generated-audio.wav only as the default. Assert the new call shape and the preserved default instead.
|
Confirmed the extraction problem is real on main, where runtime-provider.tsx collapses PDF and HTML text to a single line before it reaches the model, so the fix is worth having. The direction is right, but this lands the preview modal, the extraction normaliser and the DOCX unpacking swap in one branch, so could you split the extraction fixes out first? |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…9520) attachment-content.ts imported OPEN_DOCUMENT_SPREADSHEET_MIME and OPEN_DOCUMENT_TEXT_MIME from ./open-document, which exports neither. Both are declared in ./open-document-accept; open-document.ts only imports the first of them from there, so the name existed locally without being re-exported. TS2459 and TS2305, so the frontend build fails on main and on every open pull request that merges it. #9455 and #8655 landed minutes apart. Each was consistent on its own branch and neither could see the other.



Clicking an attachment tile in chat only opened a lightbox for images. Documents, PDFs and audio had no way to see what was attached beyond the filename tooltip.
Every attachment kind now opens a modal:
AudioPlayerThe text is the same extraction the adapters send to the model, so a composer preview shows exactly what the model will receive. The PDF, DOCX and HTML extractors move into
features/chat/attachment-content.tsand the adapters inruntime-provider.tsxcall them instead of keeping their own copy. A sent attachment no longer holds itsFile, so the preview unwraps the[PDF: name]header or<attachment name=...>tag the adapter wrote. Extraction starts on first open rather than on mount, and long files stop at 200k characters so a single<pre>cannot stall the webview.AudioPlayertakes an optionalfilenameso an attachment download keeps its own name instead ofgenerated-audio.wav.Testing
Manually verified in Studio: attached
.txt,.csv,.html,.odt,.pdfand.docxin the chat composer and opened each tile. Every one shows its extracted text with the right size, line count and source-format label.New unit tests in
tests/attachment-preview-text.test.tscover the wrapper round-trip ([PDF: ...]header,<attachment name=...>tag), the preview truncation cap, line counting and audio detection by MIME and extension.tsc,eslintandbiome checkare clean on the touched files.Extraction changes this pulled in
Opening the preview made two existing problems visible, so both are fixed here rather than left to the modal.
PDF and HTML text kept no line structure. unpdf's
mergePagescollapses\s+to a single space and the HTML branch readbody.textContentthe same way, so a 250 KB PDF and an 8.9 KB page both previewed, and were sent to the model, as one line. PDF text is now joined per page and HTML walks block elements, both through one normalizer that collapses runs of spaces without folding newlines.DOCX parts are bounded by what mammoth can inflate rather than by what the archive declares. jszip takes each part's size from the central directory and inflates it in full before anything can reject it, so a part declaring 1 KB and expanding to 1 GB exhausted the webview on a preview click. mammoth is now handed
zipSyncof fflate's unpack, and fflate allocates each entry at its declared size and stops there, so a lying part arrives truncated. The part set is still resolved the wayfindPartPathsresolves it, now off the same bytes mammoth reads.Source files preview with syntax colours through the Streamdown code plugin the transcript already uses, under the shared
MAX_HIGHLIGHT_CHARSceiling. Text extracted from a document stays plain.