fix: align chat attachment picker with allowed file types (#24917)

The agent chat composer only advertised image uploads to the OS file
picker and filtered drag-and-drop and paste events to `image/*`, even
though the backend accepts text, CSV, JSON, PDF, and a narrower set of
image types.

Move the allowed chat attachment media types into `codersdk` so the
frontend picker and backend enforcement share one source of truth. Use
the generated TypeScript list to drive the file input `accept` attribute
and the drag-and-drop and paste filters, while adding common text
extensions so platforms without MIME registrations still surface those
files in the picker.
This commit is contained in:
Ethan
2026-05-05 12:25:13 +10:00
committed by GitHub
parent 632dcdb63a
commit 7e01edeb8e
10 changed files with 236 additions and 37 deletions
+34
View File
@@ -33,6 +33,40 @@ const ChatCompactionThresholdKeyPrefix = "chat_compaction_threshold_pct:"
// this limit than to lower it.
const MaxChatFileIDs = 20
// ChatAttachmentMediaType is a media type that is allowed for durable
// chat file storage. The set is intentionally narrow; byte-level
// classification and inline-render rules live alongside the enforcement
// helpers in coderd/chatfiles.
type ChatAttachmentMediaType string
const (
ChatAttachmentMediaTypeApplicationJSON ChatAttachmentMediaType = "application/json"
ChatAttachmentMediaTypeApplicationPDF ChatAttachmentMediaType = "application/pdf"
ChatAttachmentMediaTypeImageGIF ChatAttachmentMediaType = "image/gif"
ChatAttachmentMediaTypeImageJPEG ChatAttachmentMediaType = "image/jpeg"
ChatAttachmentMediaTypeImagePNG ChatAttachmentMediaType = "image/png"
ChatAttachmentMediaTypeImageWEBP ChatAttachmentMediaType = "image/webp"
ChatAttachmentMediaTypeTextCSV ChatAttachmentMediaType = "text/csv"
ChatAttachmentMediaTypeTextMarkdown ChatAttachmentMediaType = "text/markdown"
ChatAttachmentMediaTypeTextPlain ChatAttachmentMediaType = "text/plain"
)
// AllChatAttachmentMediaTypes enumerates every durable chat attachment
// media type in the same lexical order the guts-generated TypeScript
// list uses, so the frontend file picker and the backend enforcement
// map stay in lockstep. Add new values in sorted order.
var AllChatAttachmentMediaTypes = []ChatAttachmentMediaType{
ChatAttachmentMediaTypeApplicationJSON,
ChatAttachmentMediaTypeApplicationPDF,
ChatAttachmentMediaTypeImageGIF,
ChatAttachmentMediaTypeImageJPEG,
ChatAttachmentMediaTypeImagePNG,
ChatAttachmentMediaTypeImageWEBP,
ChatAttachmentMediaTypeTextCSV,
ChatAttachmentMediaTypeTextMarkdown,
ChatAttachmentMediaTypeTextPlain,
}
// CompactionThresholdKey returns the user-config key for a specific
// model configuration's compaction threshold.
func CompactionThresholdKey(modelConfigID uuid.UUID) string {