{"record":{"id":"bd58823bf33ae9b6","repo":"wavetermdev/waveterm","slug":"dropping-file-with-unsupported-mimetype-s-open","errorCode":null,"errorMessage":"dropping file with unsupported mimetype '%s' (OpenAI supports images, PDFs, text/plain, and directories)","messagePattern":"dropping file with unsupported mimetype '(.+?)' \\(OpenAI supports images, PDFs, text/plain, and directories\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/aiusechat/openai/openai-convertmessage.go","lineNumber":393,"sourceCode":"\t\t}, nil\n\tcase part.MimeType == \"directory\":\n\t\tvar jsonContent string\n\n\t\tif len(part.Data) > 0 {\n\t\t\tjsonContent = string(part.Data)\n\t\t} else {\n\t\t\treturn nil, fmt.Errorf(\"directory listing part missing data\")\n\t\t}\n\n\t\tformattedText := aiutil.FormatAttachedDirectoryListing(part.FileName, jsonContent)\n\n\t\treturn &OpenAIMessageContent{\n\t\t\tType: \"input_text\",\n\t\t\tText: formattedText,\n\t\t}, nil\n\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"dropping file with unsupported mimetype '%s' (OpenAI supports images, PDFs, text/plain, and directories)\", part.MimeType)\n\t}\n}\n\n// ConvertAIMessageToOpenAIChatMessage converts an AIMessage to OpenAIChatMessage\n// These messages are ALWAYS role \"user\"\n// Handles text parts, images, PDFs, and text/plain files\nfunc ConvertAIMessageToOpenAIChatMessage(aiMsg uctypes.AIMessage) (*OpenAIChatMessage, error) {\n\tif err := aiMsg.Validate(); err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid AIMessage: %w\", err)\n\t}\n\n\tvar contentBlocks []OpenAIMessageContent\n\timageCount := 0\n\timageFailCount := 0\n\n\tfor i, part := range aiMsg.Parts {\n\t\tswitch part.Type {\n\t\tcase uctypes.AIMessagePartTypeText:","sourceCodeStart":375,"sourceCodeEnd":411,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/aiusechat/openai/openai-convertmessage.go#L375-L411","documentation":"The OpenAI backend only supports file parts with mimetypes: images (image/*), application/pdf, text/plain, and 'directory' listings. Any other mimetype hits the default case and the part is rejected with this error listing the supported set. Unlike the others, this is an unsupported-feature error — the part must be converted or dropped by the caller.","triggerScenarios":"Attaching files like .docx, .xlsx, .csv, application/json, image-less binaries, or audio/video parts to a message sent through the OpenAI backend; a generic file-attachment pipeline passing arbitrary mimetypes through unfiltered.","commonSituations":"Users attaching Office documents or spreadsheets in a chat UI; CSV/JSON data files attached as-is; feature parity gaps when switching backends (e.g. Anthropic accepts more types than this OpenAI path).","solutions":["Convert unsupported files to text/plain or a supported format before attaching (e.g. extract text from .docx/.csv)","Read the file and attach as text/plain content when it's fundamentally textual","Skip unsupported parts with a user-visible notice instead of failing the whole request","Check the mimetype against the supported list (image/*, application/pdf, text/plain, directory) before adding the part"],"exampleFix":"// before\npart := uctypes.AIMessagePart{Type: \"file\", MimeType: \"text/csv\", Data: csvBytes} // unsupported\n// after\npart := uctypes.AIMessagePart{Type: \"file\", MimeType: \"text/plain\", FileName: \"data.csv\", Data: csvBytes} // send as plain text","handlingStrategy":"validation","validationCode":"var supportedPDFImage = func(mt string) bool {\n    return strings.HasPrefix(mt, \"image/\") || mt == \"application/pdf\" ||\n        mt == \"text/plain\" || mt == \"directory\"\n}\n// drop or convert parts where !supportedPDFImage(part.MimeType) before sending","typeGuard":"func isOpenAISupportedFile(p uctypes.AIMessagePart) bool {\n    if p.Type != uctypes.AIMessagePartTypeFile { return false }\n    return strings.HasPrefix(p.MimeType, \"image/\") || p.MimeType == \"application/pdf\" ||\n        p.MimeType == \"text/plain\" || p.MimeType == \"directory\"\n}","tryCatchPattern":null,"preventionTips":["Normalize or extract text from docx/csv/xlsx before attaching","Maintain a supported-mimetype allowlist in your attachment pipeline","Surface a user-facing notice when a part is dropped/converted"],"tags":["openai","message-conversion","unsupported-mimetype"],"backgroundTag":"unsupported-file-type","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}