Derive session event envelopes from schema#1184
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Updates the C# session-events generator to derive top-level (envelope) properties directly from the SessionEvent schema variants so the generated .NET model stays aligned with schema evolution (e.g., adds support for agentId).
Changes:
- Refactors the C# session-events generator to compute shared envelope fields from the schema variants instead of hard-coding a fixed set.
- Regenerates
dotnet/src/Generated/SessionEvents.csto includeSessionEvent.AgentId(and keep existing envelope fields). - Extends .NET tests to cover serialization and forward-compatibility behavior for
agentIdon known and unknown events.
Show a summary per file
| File | Description |
|---|---|
| scripts/codegen/csharp.ts | Adds schema-driven extraction of shared SessionEvent envelope properties and emits them into the generated base class. |
| dotnet/src/Generated/SessionEvents.cs | Regenerated output reflecting the new envelope property (AgentId) in SessionEvent. |
| dotnet/test/SessionEventSerializationTests.cs | Verifies agentId is emitted when serializing events that set AgentId. |
| dotnet/test/ForwardCompatibilityTests.cs | Verifies agentId deserializes for both known and unknown event types. |
Copilot's findings
- Files reviewed: 3/4 changed files
- Comments generated: 1
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Generated by SDK Consistency Review Agent for issue #1184 · ● 848.9K
|
@stephentoub This looks great! Since Copilot mentions that a similar fix would help Go/Python codegen, I wonder if it's worth moving some of this "shared property" utility code into the shared utils file and consuming it from the other codegenerators too. Longer term - probably after May - I'm super keep to rip up most of our per-language codegen logic and replace the whole thing with something a lot more coherent. Right now it's so expensive to have to keep extending codegen with more and more logic on a per-language basis. Longer term I would love to pick whichever one of our codegenerators is best (probably the C# one) and generalize it into something that maps the JSON schema an intermediate representation of all the types/properties/methods, and then have very simple per-language generators that render that out into the syntax for each language. As far as I can tell, there isn't that much per-language semantic difference to worry about so it seems like it should work. |
Yeah, I'm cleaning that up now. I hadn't realized the others were missing it as well until I saw copilot's review.
Sounds good. |
Share schema-level session event envelope discovery across code generators and use it for Go and Python session-event wrappers so top-level envelope fields like agentId round-trip consistently. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Cross-SDK Consistency Review ✅This PR is a well-targeted consistency improvement. Here's the cross-SDK analysis: What's changing
Consistency assessment✅ Naming conventions — all four SDKs follow their respective language idioms correctly: ✅ Type equivalence — all SDKs model ✅ Structural approach — Node.js uses TypeScript union types so the field lives on each variant; the other three SDKs use class/struct hierarchies where it naturally belongs on the base type. Both patterns provide the same access pattern for consumers. ✅ Codegen alignment — extracting ✅ Test coverage — all three modified SDKs have added round-trip and forward-compatibility tests for No consistency issues found. The PR closes the gap that existed between Node.js and the other SDKs.
|
* Generate C# session event envelope properties Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Remove unused session event initializer helper Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Derive session event envelopes across SDKs Share schema-level session event envelope discovery across code generators and use it for Go and Python session-event wrappers so top-level envelope fields like agentId round-trip consistently. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Session-event wrappers in C#, Go, and Python were relying on hard-coded sets of top-level envelope properties, so schema-level fields like
agentIdcould be omitted from language base event models. This derives shared envelope fields from theSessionEventschema variants and shares that schema discovery across generators, keeping SDKs aligned as the envelope evolves.SessionEventvariants and collect envelope properties present on every variant.agentIdwhile keeping language-specific emission local.agentIdon known and unknown event types.agentId.