Skip to content

feat(site): display file attachments in chat UI - #24281

Merged
ethanndickson merged 3 commits into
mainfrom
ethan/chat-file-attachments-ui
Apr 22, 2026
Merged

ethanndickson merged 3 commits into
mainfrom
ethan/chat-file-attachments-ui

Conversation

@ethanndickson

@ethanndickson ethanndickson commented Apr 13, 2026 •

Copy link
Copy Markdown
Member

Renders the durable file attachments introduced in #24280 in the chat interface. Without this, attachments were stored and served correctly but the UI showed raw file parts with no previews or download UX.

Every attachment gets a download affordance, split into three rendering tiers:

  • Images — thumbnail with a hover/focus overlay containing a download link. onFocusCapture/onBlurCapture with contains(relatedTarget) keeps the overlay open while tabbing between the image and its download link.
  • Text-like files (text/*, application/json) — expandable preview button with loading + error-with-retry states and the same download overlay. Preview fetches throw a typed FetchTextAttachmentError with a .status field instead of a stringly-typed error.
  • Everything else — compact FileCard with extension badge, filename, and download link.

User-side and assistant-side rendering now share AttachmentBlocks.tsx (AttachmentPreviewFrame, TextAttachmentButton, ImageAttachmentButton, FileCard, plus getAttachmentHref/getAttachmentName) instead of two near-duplicate implementations. The text-attachment overlay anchors to the preview surface so the download button stays pinned even when a loading/error status line widens the row below.

ComputerRenderer detects when a screenshot was stored as a durable attachment (attachment_file_id) and suppresses the stale base64 rendering — the screenshot appears as a proper file part instead. ToolLabel shows the attached filename for attach_file tool calls.

Storybook coverage in ConversationTimeline.stories.tsx was expanded to cover every tier (single/multiple images, inline + file-id text, JSON, download-only files, fetch-failure retry, mixed attachments + file references) with play-function assertions.

image

Cleanup

Per Mathias' post-merge suggestion on #24280, this PR also relocates coderd/chatfiles → coderd/x/chatfiles so the durable-attachment helpers live beside the rest of the chatd experimental surface.

Closes CODAGT-91

ethanndickson commented Apr 13, 2026 •

Copy link
Copy Markdown
Member Author

@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments-ui branch 3 times, most recently from c536eee to aa5f35c Compare April 13, 2026 10:04
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments branch from b181308 to 09619fc Compare April 13, 2026 14:24
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments-ui branch from aa5f35c to 785e4a0 Compare April 13, 2026 14:24
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments branch from 09619fc to f2f766d Compare April 14, 2026 07:38
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments-ui branch 2 times, most recently from be57d92 to f6dea5a Compare April 14, 2026 08:05
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments branch from 2429f26 to 0c202b2 Compare April 14, 2026 13:41
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments-ui branch from f6dea5a to a12df00 Compare April 14, 2026 13:42
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments branch from 0c202b2 to b865dc9 Compare April 15, 2026 05:32
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments-ui branch 2 times, most recently from d3e53a0 to c18090d Compare April 15, 2026 06:56
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments branch from 11095b3 to 6c530e8 Compare April 15, 2026 11:24
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments-ui branch 2 times, most recently from 5c8027c to 1363433 Compare April 15, 2026 14:42
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments branch from deeba77 to 0e4bde5 Compare April 16, 2026 05:49
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments-ui branch 3 times, most recently from ce10201 to 16e23a6 Compare April 16, 2026 08:24
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments branch from 87b1c7e to 83d9c9b Compare April 17, 2026 03:41
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments-ui branch from 16e23a6 to 8d433df Compare April 17, 2026 03:41
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments branch from 83d9c9b to cf835bc Compare April 20, 2026 04:10
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments-ui branch from 8d433df to 260443f Compare April 20, 2026 04:10
@ethanndickson
ethanndickson changed the base branch from ethan/chat-file-attachments to graphite-base/24281 April 20, 2026 08:04
ethanndickson added a commit that referenced this pull request Apr 20, 2026
Agents can already see workspace files and take screenshots, but users could not download those artifacts from chat. This PR adds durable chat attachments to chatd. `attach_file`, explicit `computer` screenshot actions (not the automatic post-action screenshots), and `propose_plan` now fetch bytes over the agent connection, store them in `chat_files`, link them to the chat, and carry attachment metadata in tool responses so `buildAssistantPartsForPersist` can materialize ordinary `type:"file"` assistant parts that the chat file APIs serve.

The same storage helpers are reused for other artifact-producing paths. `wait_agent` recordings and thumbnails are stored as chat files and linked back to the parent chat, with best-effort relinking so parent chats retain those artifacts without leaving orphaned rows when chat-file caps reject links. `storeChatAttachment` wraps insert + link in one transaction, files are capped at 10 MB each and 20 per chat, and serving defaults to `Content-Disposition: attachment` with an explicit inline-safe allowlist.

This PR also consolidates chat-file media policy in `coderd/chatfiles`. Uploads and tool-generated attachments share byte-based MIME detection, SVG blocking, inline-safety rules, and compatible `text/plain` refinement for JSON, CSV, and Markdown. Prompt construction still only inlines synthetic pasted text for model consumption; assistant-created attachments are persisted for the user and intentionally not replayed into later LLM turns.

UI follow-up lives in #24281.

Relates to CODAGT-91
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments-ui branch from 260443f to 74b83a7 Compare April 20, 2026 08:04
@graphite-app
graphite-app Bot changed the base branch from graphite-base/24281 to main April 20, 2026 08:05
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments-ui branch 4 times, most recently from 27d5ddb to d457cdb Compare April 20, 2026 11:22
@ethanndickson
ethanndickson marked this pull request as ready for review April 20, 2026 11:49

@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: d457cdbb13

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

@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments-ui branch from d457cdb to e094490 Compare April 21, 2026 02:32
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

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

@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments-ui branch 2 times, most recently from c2e45b7 to bf2e784 Compare April 21, 2026 07:11

@ethanndickson ethanndickson left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Clean consolidation — collapsing the two near-duplicate FileBlock/TextAttachmentButton implementations into a shared AttachmentBlock is the right structural move, and FetchTextAttachmentError + getTextAttachmentErrorMessage replacing string-matching across two files is a clear win. The new story coverage for user-side attachments, JSON previews, and the fetch-failure retry message is well targeted.

The findings cluster around the new attachment-identity handoff (backend persistedMediaResult ↔ ComputerRenderer) and a couple of a11y/touch gaps in the shared frame. 4 P2, 9 P3, 3 Nits, 2 Obs across 18 inline comments. The P2s are worth addressing before merge; most of the P3s are one-line fixes while the code is fresh.

Comment thread coderd/x/chatd/chatprompt/chatprompt.go Resolved
Comment thread coderd/x/chatd/chatprompt/chatprompt.go Resolved
Comment thread coderd/x/chatd/chatprompt/chatprompt.go Resolved
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments-ui branch from bf2e784 to 24a2a69 Compare April 22, 2026 06:46
@ethanndickson
ethanndickson force-pushed the ethan/chat-file-attachments-ui branch from 24a2a69 to f0f9a65 Compare April 22, 2026 08:13
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

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

@ethanndickson
ethanndickson merged commit cc4e04a into main Apr 22, 2026
29 of 30 checks passed
@ethanndickson
ethanndickson deleted the ethan/chat-file-attachments-ui branch April 22, 2026 10:11
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants