Fix CreateMessageRequestParams.Metadata type to JsonObject#1354
Fix CreateMessageRequestParams.Metadata type to JsonObject#1354stephentoub merged 4 commits intomainfrom
Conversation
…nObject? Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
halter73
left a comment
There was a problem hiding this comment.
Honestly, I'm still a little unsure when we use JsonObject vs JsonElement vs IDictionary<string, JsonElement>. I remember discussing this back in the "Audit protocol types" PR in #892, but I don't think JsonObject was in the mix then.
This does align with what we did for _meta in #1341, but I don't really know why we did that. I guess this is sorta similar, so this is arguably more consistent. I don't know why _meta was changed to be different than all the other DTO properties though, and I'm not sure if this is more similar to _meta or other untyped collections in JSON DTOs. I feel like @eiriktsarpalis and/or @MackinnonBuck might be better to review this.
halter73
left a comment
There was a problem hiding this comment.
Approving based on this explanation from @stephentoub
JsonObject is the only one of the three that requires it be a JSON object: both JsonElement and JsonNode can represent primitives in addition to objects. JsonObject is also mutable, which means you can treat it like a dictionary and easily add things into it. I think both of those make it appropriate for _meta, which is required by spec to be a JSON object and which from a usability perspective benefits from being able to treat like a dictionary.
CreateMessageRequestParams.metadata isn't _meta, but it has the same constraints, e.g. required by schema to be an object
|
FWIW, I also asked the GH copilot agent with Opus 4.6:
Here's the relevant part of the response: The Pattern
The key distinction is mutability and construction intent: Outliers FoundOnly two properties deviate from this pattern:
All other properties follow the pattern correctly — including |
There are nuanced differences between the three. When it comes to the other alternatives, |
CreateMessageRequest.params.metadataasobjecttype ({ [key: string]: unknown })_meta/Metaproperties in C# SDK useJsonObject?CreateMessageRequestParams.MetadatafromJsonElement?toJsonObject?MetadatainCreateMessageRequestParamsTests🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.