Skip to content

[TASK] Refactor Part deserialization to use concrete types instead of map[string]any #102

@edenreich

Description

@edenreich

Summary

Currently, when messages are deserialized from JSON responses (e.g., in the client after receiving task status), the Part type (defined as type Part any) becomes map[string]any instead of concrete types like TextPart, DataPart, etc.

This causes issues in client code where developers need to use type assertions for map[string]any and manually extract fields, rather than being able to directly work with typed structs.

Current Behavior

In server/utils/message_converter.go, the ConvertFromSDK method creates parts as map[string]any:

message.Parts = append(message.Parts, map[string]any{
    "kind": string(types.MessagePartKindText),
    "text": response.Content,
})

When clients deserialize the JSON response, they receive map[string]any and must handle it like:

if partMap, ok := part.(map[string]any); ok {
    if kind, hasKind := partMap["kind"]; hasKind && kind == "text" {
        if text, exists := partMap["text"]; exists {
            if textStr, ok := text.(string); ok {
                fmt.Printf("Response: %s\n", textStr)
            }
        }
    }
}

Desired Behavior

Clients should be able to work with concrete types:

if textPart, ok := part.(types.TextPart); ok {
    fmt.Printf("Response: %s\n", textPart.Text)
}

Acceptance Criteria

  • Implement custom JSON marshaling/unmarshaling for Part interface to deserialize into concrete types (TextPart, DataPart, FilePart) based on the "kind" field
  • Update ConvertFromSDK to return concrete part types instead of map[string]any
  • Update all examples to use typed part assertions instead of map handling
  • Add tests to verify part deserialization produces correct concrete types
  • Ensure backward compatibility or document breaking changes

Related Files

  • types/generated_types.go - Part type definition
  • server/utils/message_converter.go - ConvertFromSDK method
  • examples/ai-powered/client/main.go - Client usage example

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions