{"record":{"id":"642b2d14fe0e4855","repo":"wavetermdev/waveterm","slug":"convertfileaimessagepart-expects-file-type-got-642b2d","errorCode":null,"errorMessage":"convertFileAIMessagePart expects 'file' type, got '%s'","messagePattern":"convertFileAIMessagePart expects 'file' type, got '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/aiusechat/openai/openai-convertmessage.go","lineNumber":326,"sourceCode":"\tif opts.Provider == uctypes.AIProvider_Wave {\n\t\tif chatOpts.ClientId != \"\" {\n\t\t\treq.Header.Set(\"X-Wave-ClientId\", chatOpts.ClientId)\n\t\t}\n\t\tif chatOpts.ChatId != \"\" {\n\t\t\treq.Header.Set(\"X-Wave-ChatId\", chatOpts.ChatId)\n\t\t}\n\t\treq.Header.Set(\"X-Wave-Version\", wavebase.WaveVersion)\n\t\treq.Header.Set(\"X-Wave-APIType\", uctypes.APIType_OpenAIResponses)\n\t\treq.Header.Set(\"X-Wave-RequestType\", chatOpts.GetWaveRequestType())\n\t}\n\n\treturn req, nil\n}\n\n// convertFileAIMessagePart converts a file AIMessagePart to OpenAI format\nfunc convertFileAIMessagePart(part uctypes.AIMessagePart) (*OpenAIMessageContent, error) {\n\tif part.Type != uctypes.AIMessagePartTypeFile {\n\t\treturn nil, fmt.Errorf(\"convertFileAIMessagePart expects 'file' type, got '%s'\", part.Type)\n\t}\n\tif part.MimeType == \"\" {\n\t\treturn nil, fmt.Errorf(\"file part missing mimetype\")\n\t}\n\n\t// Handle different file types\n\tswitch {\n\tcase strings.HasPrefix(part.MimeType, \"image/\"):\n\t\timageUrl, err := aiutil.ExtractImageUrl(part.Data, part.URL, part.MimeType)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\treturn &OpenAIMessageContent{\n\t\t\tType:       \"input_image\",\n\t\t\tImageUrl:   imageUrl,\n\t\t\tFilename:   part.FileName,\n\t\t\tPreviewUrl: part.PreviewUrl,","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/aiusechat/openai/openai-convertmessage.go#L308-L344","documentation":"convertFileAIMessagePart validates that the part it was handed has type 'file'. This error means a message part with a different Type reached this converter, indicating an internal dispatch bug in ConvertAIMessageToOpenAIChatMessage or a caller constructing parts manually with a mismatched type.","triggerScenarios":"ConvertAIMessageToOpenAIChatMessage encounters a part whose Type is not uctypes.AIMessagePartTypeFile but is routed to convertFileAIMessagePart; user code builds AIMessagePart structs by hand with a wrong/typo'd Type string and passes them into the chat request.","commonSituations":"Typos in part type strings when constructing messages programmatically; newer part types added upstream but not handled by the OpenAI converter; mixing message formats from different providers.","solutions":["Ensure the part's Type field is exactly uctypes.AIMessagePartTypeFile (\"file\") before adding it to the message","Filter or preprocess parts so only file parts reach the OpenAI conversion path","Update the library if you're using a new AIMessagePartType not yet supported by the OpenAI backend","Log part.Type at construction time to catch typos early"],"exampleFix":"// before\npart := uctypes.AIMessagePart{Type: \"File\", ...} // wrong case -> error\n// after\npart := uctypes.AIMessagePart{Type: uctypes.AIMessagePartTypeFile, ...}","handlingStrategy":"validation","validationCode":"func validFilePart(p uctypes.AIMessagePart) bool {\n    return p.Type == uctypes.AIMessagePartTypeFile\n}\n// filter before sending: keep only parts where validFilePart(part) or handled types","typeGuard":"func isFilePart(p uctypes.AIMessagePart) bool {\n    return p.Type == uctypes.AIMessagePartTypeFile\n}","tryCatchPattern":null,"preventionTips":["Always use the uctypes.AIMessagePartType* constants, never raw strings","Unit-test message construction helpers","Filter parts by type before invoking backend conversion"],"tags":["openai","message-conversion","validation"],"backgroundTag":"invalid-message-part-type","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}