feat(web): binary file attachments for Ask#1375
Draft
whoisthey wants to merge 6 commits into
Draft
Conversation
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
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.
Adds support for binary (image) file attachments in Ask Sourcebot, building on the inline-text attachment work in the base branch. Users can attach PNG/JPEG/WebP/GIF images (drag-and-drop or file picker) to a chat message; the bytes are uploaded to app-mediated blob storage and sent to vision-capable models as native image content. Unlike text attachments, image bytes never travel in the
messagesJSON — they're referenced by id and served through an access-controlled route.This is an enterprise (
ee) feature, gated by theaskentitlement.What's included
Data model & storage
Attachmentmodel +ChatAttachmentjoin table +AttachmentStatus(PENDING→COMMITTED) enum, with migration. Attachments are uploaded before any chat exists and linked to chats viaChatAttachment, keeping access purely chat-derived.StorageBackendabstraction with aLocalFsStorageBackend(bytes underDATA_CACHE_DIR/attachments); an S3 driver is planned as a follow-up.blobvariant on theAttachmentDatadiscriminated union (references stored bytes by id; bytes stay out of message JSON).Upload & serving
POST /api/ee/chat/attachments: authenticated (no anonymous uploads), entitlement-gated, validates content type by magic bytes (not client MIME/extension; SVG intentionally excluded), enforces a server-side size cap, and returns theattachmentId. Images upload on select.commitMessageAttachmentslinks referenced blobs to the chat and flipsPENDING → COMMITTED, rejecting forged/unauthorized ids before the agent runs.GET /api/ee/chat/{chatId}/attachments/{attachmentId}: serves bytes only when the caller can view the chat and aChatAttachmentlink exists; setsX-Content-Type-Options: nosniffand a header-safeContent-Disposition.Agent / model integration
resolveLatestTurnImagesloads bytes from storage for the latest user turn (only for blobs linked to that chat) andbuildUserModelMessageattaches native image content parts. Image bytes are only sent on the turn they were added; a short marker is left when images are dropped (older turn or a text-only model).Client UI
acceptincludes image types only when supported.uploading/uploaded/error), on-hover preview, and a full viewer dialog. Submit is blocked while uploads are in flight.Lifecycle & cleanup
PENDING(uploaded-but-never-sent) blobs older than a TTL, along with their bytes.Config / observability
SOURCEBOT_CHAT_ATTACHMENT_MAX_IMAGE_BYTES(default 10 MiB) andSOURCEBOT_CHAT_ATTACHMENT_ORPHAN_TTL_HOURS(default 24,0disables). Documented inenvironment-variables.mdx.chat_attachment_uploaded,chat_attachment_degraded.