mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user