-
Notifications
You must be signed in to change notification settings - Fork 1
[TASK] Refactor Part deserialization to use concrete types instead of map[string]any #102
Copy link
Copy link
Closed
Closed
Copy link
Description
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
Partinterface to deserialize into concrete types (TextPart, DataPart, FilePart) based on the "kind" field - Update
ConvertFromSDKto return concrete part types instead ofmap[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 definitionserver/utils/message_converter.go- ConvertFromSDK methodexamples/ai-powered/client/main.go- Client usage example
Reactions are currently unavailable
Metadata
Metadata
Assignees
Type
Projects
Status
Done