wavetermdev/waveterm · error

convertFileAIMessagePart expects 'file' type, got '%s'

Error message

convertFileAIMessagePart expects 'file' type, got '%s'

What it means

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.

Source

Thrown at pkg/aiusechat/openai/openai-convertmessage.go:326

	if opts.Provider == uctypes.AIProvider_Wave {
		if chatOpts.ClientId != "" {
			req.Header.Set("X-Wave-ClientId", chatOpts.ClientId)
		}
		if chatOpts.ChatId != "" {
			req.Header.Set("X-Wave-ChatId", chatOpts.ChatId)
		}
		req.Header.Set("X-Wave-Version", wavebase.WaveVersion)
		req.Header.Set("X-Wave-APIType", uctypes.APIType_OpenAIResponses)
		req.Header.Set("X-Wave-RequestType", chatOpts.GetWaveRequestType())
	}

	return req, nil
}

// convertFileAIMessagePart converts a file AIMessagePart to OpenAI format
func convertFileAIMessagePart(part uctypes.AIMessagePart) (*OpenAIMessageContent, error) {
	if part.Type != uctypes.AIMessagePartTypeFile {
		return nil, fmt.Errorf("convertFileAIMessagePart expects 'file' type, got '%s'", part.Type)
	}
	if part.MimeType == "" {
		return nil, fmt.Errorf("file part missing mimetype")
	}

	// Handle different file types
	switch {
	case strings.HasPrefix(part.MimeType, "image/"):
		imageUrl, err := aiutil.ExtractImageUrl(part.Data, part.URL, part.MimeType)
		if err != nil {
			return nil, err
		}

		return &OpenAIMessageContent{
			Type:       "input_image",
			ImageUrl:   imageUrl,
			Filename:   part.FileName,
			PreviewUrl: part.PreviewUrl,

View on GitHub (pinned to a4447c1563)

Solutions

  1. Ensure the part's Type field is exactly uctypes.AIMessagePartTypeFile ("file") before adding it to the message
  2. Filter or preprocess parts so only file parts reach the OpenAI conversion path
  3. Update the library if you're using a new AIMessagePartType not yet supported by the OpenAI backend
  4. Log part.Type at construction time to catch typos early

Example fix

// before
part := uctypes.AIMessagePart{Type: "File", ...} // wrong case -> error
// after
part := uctypes.AIMessagePart{Type: uctypes.AIMessagePartTypeFile, ...}
Defensive patterns

Strategy: validation

Validate before calling

func validFilePart(p uctypes.AIMessagePart) bool {
    return p.Type == uctypes.AIMessagePartTypeFile
}
// filter before sending: keep only parts where validFilePart(part) or handled types

Type guard

func isFilePart(p uctypes.AIMessagePart) bool {
    return p.Type == uctypes.AIMessagePartTypeFile
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/642b2d14fe0e4855. Report an issue: GitHub.