Skip to content

Studio: document viewer for PDF, Word, Excel and PowerPoint, with origin links in Library - #12001

Merged
danielhanchen merged 55 commits into
mainfrom
studio-document-viewer
Sep 27, 2026
Merged

danielhanchen merged 55 commits into
mainfrom
studio-document-viewer

Conversation

@shimmyshimmer

@shimmyshimmer shimmyshimmer commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Library and chat can now open PDF, Word, Excel, PowerPoint, CSV and TSV files as they look, instead of as extracted text. Every Library item also links back to where it came from.

Changes

Viewer (components/file-viewer)

  • PDF: pdf.js pages, rendered as they scroll into view.
  • DOCX: mammoth HTML, passed through a tag and attribute allowlist. Stops after 50,000 elements, with a note.
  • XLSX, XLSM, CSV and TSV: grid with sheet tabs, column widths and the common number formats (currency, percent, dates, times, exponents). Rows and columns are both virtualized. Capped at 5,000 rows and 200 columns.
  • Sheet XML is read as text, only up to the rows kept, and only the parts the workbook uses are unpacked. Each number format is parsed once.
  • PPTX: slides with positioned text, images, tables, chart data and SmartArt labels. Pictures get object URLs only while their slide is mounted.
  • All readers load lazily, so none of them are in the main bundle. Files over 50 MB are offered as a download.

Library preview

  • The body fills the dialog below the header, with no side or bottom padding. Pages and slides fit the full pane width, up to the scrollbar.
  • Zoom applies to documents, markdown, text and web pages. Content wider than the pane scrolls sideways, and zoomed images can be dragged.
  • An unsaved CSV edit shows in its grid.
  • Smaller corner radius on the viewer (24px), and a narrower toolbar search bar.

Library grid and sort

  • The column count now includes the gap between cards, and the minimum card widths are 140, 170 and 210px (small, medium, large). A grid about 950px wide shows 5 medium columns instead of 4.
  • Thinner selection ring on grid cards (2px).
  • Smaller radio circles in the Sort menu.
  • Last activity (Modified outside Suggested) gets Ascending and Descending options, kept in the URL and shared with the list view's column sort.

Origin links (the ... menu)

  • Chat attachments and chat sandbox files: View original chat. Opens the compare pair or project when the file came from one.
  • Fine-tuned models: View training run, matched by output folder, including -gguf, -adapter and -merged exports.
  • Generated images, video and audio keep View in Images, Video or Audio.
  • Direct Library uploads have no origin link.
  • Files from a chat show From chat · <chat title> in the subtitle, so they read apart from a direct upload of the same file.

Chat

  • CSV and markdown sent in chat are served without the wrapper chat adds for the model, so they open as a grid or rendered markdown in the Library, and download as the original text.
  • PDF, DOCX, XLSX and PPTX attachments open in the same viewer, from the composer and from sent messages. CSV and markdown open from their stored text.
  • XLSX, XLSM and PPTX can now be attached. The model receives sheet rows as TSV and slide text.
  • On send, the original file is stored by SHA-256 under chat-originals/ through POST /api/chat/attachment-originals, and the attachment records it as original. Temporary chats store nothing, and a failed upload only affects viewing.
  • GET /api/chat/attachments/{message_id}/{attachment_id}/file serves the original when there is one, as application/octet-stream with nosniff.
  • Unreferenced originals older than an hour are removed by a throttled sweep, run on upload and on thread or attachment deletion.
  • The attachment inventory moves to version 4 to record original_sha256, so the Library lists sent documents with their originals.

Performance

Measured in Chromium, before and after the reader and grid changes:

Case Before After
Open a 1M-cell sheet (5,000 x 200) 4.8 s 1.4 s
Open a 60k-row workbook with a 60 MB custom XML part 2.6 s 0.39 s
Open a 24-slide deck with 29 MB of images 690 ms 13 ms
One scroll step in a wide sheet (dev build) 330 ms 11 ms

Testing

  • Opened each format in the Library and in chat (composer and sent messages) in the browser, from 50% to 200% zoom.
  • View original chat, project and training run land on the right thread, project and run.
  • Frontend: tsc clean, tests pass (including new reader tests in tests/file-viewer-office.test.ts), build within budget, no new missing keys in i18n:check:strict.
  • Backend: library, chat attachment, chat history and studio DB tests pass.

Notes

  • Chats sent before this change only kept the extracted text, so their PDF, DOCX, XLSX and PPTX attachments cannot be opened as documents. CSV and markdown still can.
  • Native drag and drop in the desktop app does not accept .xlsx or .pptx yet. The attach button does.

Screenshots

Before is the merge base on main, after is this branch, each in its own Studio install.

XLSX in the Library: before, "No preview for this file type"; after, the sheet as a grid with its sheet tabs.

XLSX preview before and after

DOCX in the Library: before, "No preview for this file type"; after, the rendered page including its table.

DOCX preview before and after

@chatgpt-codex-connector

This comment has been minimized.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

Spreadsheets
- Read sheet XML as text instead of through DOMParser, and only up to the
  rows kept. Unpack only the parts the workbook uses, so custom XML and
  pivot caches are skipped. Shared strings decode lazily.
- Parse each number format once per workbook instead of once per cell.
- Grid renders only the columns in view, with memoized rows.
- Quoted semicolons no longer split format sections, scientific formats
  keep their literals, and elapsed times show fractional seconds.

Presentations
- Pictures stay as Blobs with object URLs made per mounted slide, instead
  of base64 data URLs for the whole deck. Video and audio are not unpacked.
- Native tables are capped like chart tables. SmartArt labels are read.

Word
- Rendering stops after 50,000 elements, with a note.

Chat
- Office text for the model is budgeted in UTF-8 bytes, delimiters included.
- Attaching an XLSX or PPTX reads the file once.

Chat originals
- Sweeps no longer create the originals folder, so a late sweep cannot
  recreate a deleted account's workspace.
- Startup sweeps every account. Deleting an attachment from the Library
  sweeps too.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

- A negative value in its own fraction section, such as (# ?/?), no longer
  gets an extra minus.
- String cells use the format's text section: the fourth section, or a
  single section with @. ABC in 0;0;0;"SKU-"@ shows SKU-ABC.
- Shared strings are scanned from the part's bytes only up to the highest
  index a cell uses, and decoded one at a time, instead of building the
  whole table.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 27, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 27, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 27, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 27, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Sep 27, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Sep 27, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Sep 27, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Sep 27, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Sep 27, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 27, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 27, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 27, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex security review

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5b3e2a5334

ℹ️ 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".

with _due_changed:
if directory in _due:
return
_due[directory] = (time.monotonic() + _SWEEP_GRACE_SECONDS + 60, contextvars.copy_context())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Schedule throttled sweeps for the earliest eligible time

When a sweep is throttled, or finds an unreferenced file already close to the one-hour grace limit, this always delays the next attempt by another 61 minutes. For example, deleting a days-old attachment one minute after another sweep leaves its original on disk for over an hour rather than only the remaining nine-minute throttle interval; a 59-minute-old orphan can remain for roughly two hours. Compute the due time from the remaining throttle/grace interval so deleted originals are not retained substantially longer than configured.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below the bar: this only changes when an orphaned original is deleted, not whether it is; nothing referenced is ever removed and the file still goes on the next sweep.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f763e4f2a0

ℹ️ 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".

Comment on lines +60 to +61
: "utf-8";
const text = new TextDecoder(encoding).decode(bytes);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor the declared charset when decoding delimited files

For CSV or TSV files whose MIME type declares a non-UTF-8 charset, such as text/csv; charset=windows-1252, this path ignores the declaration and always decodes BOM-less data as UTF-8. The viewer therefore silently replaces or corrupts accented and non-Latin cell values even though TextDecoder supports the declared encoding; parse the MIME charset before falling back to UTF-8.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not reachable: browsers type a File from its extension with no charset parameter, and Library types uploads by extension on the server (test_uploads_are_listed_and_typed_by_their_extension_not_the_client), so no contentType reaching this decoder carries a charset.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: f763e4f2a0

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 6168819a8a

ℹ️ 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".

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.

4 participants