feat(chat): add image attachment support to composer
Closes #2662
Summary
- Users can attach images (PNG, JPEG, WebP, GIF, BMP) to chat messages via a paperclip button in the text composer
- Attachments render as thumbnail chips above the textarea with per-item remove buttons
- Images are encoded as
[IMAGE:<data-uri>]markers in the message string — the existing Rust backend (agent/multimodal.rs) already parses these and routes them to the inference provider, so no backend changes were needed - Limits match the existing
MultimodalConfigdefaults: up to 4 images per message, 8 MB each - Validation errors (unsupported type, oversized file, count exceeded) surface in the existing composer error banner
- Send button activates when attachments are present even with empty text
Files changed
| File | Role |
|---|---|
app/src/lib/attachments.ts |
Validation, FileReader util, [IMAGE:] marker composition, parseMessageImages util |
app/src/components/chat/AttachmentPreview.tsx |
Thumbnail chip strip component |
app/src/pages/Conversations.tsx |
Hidden file input, attachment state, composer toolbar button, send wiring, bubble rendering |
app/src/lib/i18n/en.ts + 12 locale chunk files |
i18n keys for attachment labels and errors |
app/src/lib/attachments.test.ts |
19 Vitest unit tests covering validation, composition, parsing, and formatting |
Test plan
- [x] Attach a PNG/JPEG — thumbnail preview appears above textarea
- [x] Remove a chip — it disappears without affecting others
- [x] Attach more than 4 images — error banner shows the limit message
- [x] Attach a file > 8 MB — error banner shows the size limit message
- [x] Attach a PDF — error banner shows unsupported type message
- [x] Send with attachment + text — both reach the agent
- [x] Send with attachment only (no text) — send button active, message goes through
- [x] Attachments clear after send
Notes
Pre-push hook fails on cargo fmt --check due to cargo not being in PATH in this dev environment. This is a pre-existing environment issue unrelated to the changes here (no Rust files were modified). TypeScript typecheck, ESLint, Prettier, and Vitest all pass.
Summary by CodeRabbit
-
New Features
- Image attachment support in chat with compact thumbnail previews (image, filename, formatted size), per-item remove, and up to 4 images per message.
- Composer and send behavior updated to allow sending messages with only attachments and show attachment thumbnails in the chat transcript.
-
Tests
- Added tests covering MIME/type/size validation, data-URI conversion, message building/parsing, and file-size formatting.
-
Documentation
- Added localized attachment UI strings across 15+ languages (including camera prompts).
[!NOTE]
Reviews paused
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
- [ ] ▶️ Resume reviews
- [ ] 🔍 Trigger review
📝 Walkthrough
Walkthrough
Adds image attachment support: utilities to validate/convert files, AttachmentPreview UI, i18n strings, and composer integration to select, validate, preview, compose, send, and render image attachments with metadata.
Changes
Image Attachments in Chat
| Layer / File(s) | Summary |
|---|---|
Attachment utilities and types app/src/lib/attachments.ts |
Core types and constants (Attachment, AllowedImageMimeType, ATTACHMENT_MAX_IMAGES, ATTACHMENT_MAX_SIZE_BYTES), isAllowedMimeType, fileToDataUri, validateAndReadFile (deterministic error codes), buildMessageWithAttachments, parseMessageImages, and formatFileSize. |
Attachment unit tests app/src/lib/attachments.test.ts |
Vitest suite covering MIME allowlist, file→dataURI conversion, validation/read failure codes and success, message composition/parsing, and file-size formatting. |
Attachment preview component & tests app/src/components/chat/AttachmentPreview.tsx, app/src/components/chat/__tests__/AttachmentPreview.test.tsx |
New React component rendering a flex-wrapped list of attachment thumbnails with truncated filenames, formatted sizes, per-item remove buttons, disabled state, and i18n aria-labels; tests exercise rendering, remove actions, disabled state, and multiple items. |
Internationalization translations app/src/lib/i18n/en.ts, app/src/lib/i18n/chunks/{en,de,fr,es,pt,ru,it,ko,zh-CN,hi,bn,ar,id}-2.ts |
Adds chat.attachment.* keys across locale chunks for attach/remove labels, limits, validation/read errors, and placeholders. |
Chat composer attachment integration app/src/pages/Conversations.tsx |
Adds attachments state and hidden multi-file input, handleAttachFiles using validateAndReadFile with attach-specific error reporting, renders AttachmentPreview, allows sends when text is empty if attachments exist, composes message text with buildMessageWithAttachments, embeds attachment metadata into outgoing messages, displays attachment thumbnails in the transcript, and clears attachment state after send. |
Conversations attachment integration tests app/src/pages/__tests__/Conversations.attachments.test.tsx |
End-to-end style tests for the Conversations page covering attach UI, validation errors (too many/unsupported/too large/read failure), removal, send behavior, and transcript rendering from attachment metadata. |
Chat send error code app/src/chat/chatSendError.ts |
Extends ChatSendErrorCode union with 'prompt_review'. |
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related issues
#2725: i18n chunk placeholders overlap with this PR'schat.attachment.*keys and may need translation updates.
Suggested reviewers
- graycyrus
Poem
🐇 I found a file, a glossy square,
I read its bits and showed it there,
Tiny markers stitched the view,
Composer cleared — the images flew,
Hop, the chat now shares anew!
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title 'feat(chat): add image attachment support to composer' accurately describes the main change: adding image attachment functionality to the chat composer UI. |
| Linked Issues check | ✅ Passed | The PR implements image upload/attachment preview/composer integration and validation limits matching #2662 acceptance criteria [#2662]. Camera capture and file upload are deferred; privacy controls and memory integration left for follow-up work. |
| Out of Scope Changes check | ✅ Passed | All changes directly support image attachment in the composer: attachments.ts library, AttachmentPreview component, Conversations.tsx integration, i18n keys, and tests. One minor out-of-scope item: removal of unused camera i18n keys from prior work. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
[!WARNING] There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.
🔧 ESLint
If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add
eslintto devDependencies.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
Hey @graycyrus — both points addressed:
[major] Wired parseMessageImages as a fallback in the bubble renderer. Local sends use extraMetadata.attachmentDataUris (fast path); messages rehydrated from the API fall back to parsing [IMAGE:] markers from content, so images survive page reloads and history scrolls.
[minor] Opened #2725 to track translations for the 8 chat.attachment.* keys across all 12 non-English locales.
Let me know if anything else needs attention.
@graycyrus — could you re-review when you have a moment?
I posted a review walkthrough + 5 inline findings, then landed 79b79c99 to address the two cleanup items:
- #1 dead
chat.attachment.camera/cameraUnavailablekeys removed fromen.tsand all 13 locale chunks - #5
FileReadermock wrapped intry/finallyinattachments.test.ts
Left unresolved for the author to weigh in:
- #2
extraMetadata.attachmentDataUrispersisted verbatim to JSONL (~32 MB/turn at the 4×8 MB cap) andseed_resume_from_messagesnot re-injecting markers on restart - #3
cloud_send_failedused for local validation errors - #4
parseMessageImagesregex narrower than the Rust marker grammar
CI is at 23/24 green, 1 still running (Windows secrets ACL — flaky on main).
@graycyrus — all findings from the last round are addressed and all 6 threads are resolved. Your approval was auto-dismissed by GitHub when the fix commits landed after your review. Everything is green (26/27 — the Windows ACL job is the known compile-timeout flake). Happy for a re-review when you get a chance.
@coderabbitai review
Review triggered. Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.✅ Actions performed
Hi @graycyrus @oxoxDev — round-4 rfix4 shepherding complete: CR comments addressed, CI green/converging, I've approved. Would appreciate a second-maintainer review when you have a moment 🙏