Skip to content

Share generated schema definitions across SDKs#1289

Merged
stephentoub merged 8 commits into
mainfrom
stephentoub/shared-reasoning-summary-enum
May 14, 2026
Merged

Share generated schema definitions across SDKs#1289
stephentoub merged 8 commits into
mainfrom
stephentoub/shared-reasoning-summary-enum

Conversation

@stephentoub
Copy link
Copy Markdown
Collaborator

@stephentoub stephentoub commented May 14, 2026

Identical definitions can now appear in both runtime schema artifacts, including upcoming RPC references to session-event models. This updates SDK codegen so those definitions keep one semantic SDK type instead of being duplicated or degraded to strings.

Summary

  • Adds shared schema definition detection and reference rewriting across the language generators.
  • Regenerates SDK outputs so RPC/API models reuse session-event generated types for shared definitions and direct external session-event refs.
  • Moves Go's real generated session-event hierarchy into go/rpc, with root copilot aliases and const re-exports so there is one Go type identity for session events.
  • Adds focused shared-codegen regression coverage and Go alias identity checks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 14, 2026 02:39
@stephentoub stephentoub requested a review from a team as a code owner May 14, 2026 02:39
Comment thread scripts/codegen/csharp.ts Fixed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the multi-language code generators to detect identical JSON Schema definitions shared between api.schema.json and session-events.schema.json, and to rewrite $refs so SDKs reuse a single semantic type instead of duplicating models or degrading them (e.g., to strings). It also restructures Go’s generated session-event code into the go/rpc package and adds regression tests to lock in the new shared-definition behavior.

Changes:

  • Add shared-definition comparison, reachability analysis, external-ref parsing/collection, and $ref rewriting/inlining utilities to the codegen shared helpers.
  • Update TS/Python/Rust/C# (and Go) generators to rewrite schema references so generated RPC/API types can reuse session-event (or shared) models and emit the necessary imports/registrations.
  • Regenerate outputs and add focused regression coverage (Node shared-codegen tests; Go alias identity checks; Go rpc session encoding relocation).
Show a summary per file
File Description
scripts/codegen/utils.ts Adds stable stringify + external-ref parsing/collection + shared-definition detection + $ref rewriting/inlining helpers.
scripts/codegen/typescript.ts Rewrites RPC schema refs to shared session-event definitions and emits TS type-only imports for external refs.
scripts/codegen/rust.ts Supports external $ref type naming/imports and rewrites shared definitions to session-events types when generating Rust outputs.
scripts/codegen/python.ts Rewrites shared refs and post-processes quicktype output to replace external-ref placeholders with imported session-event types.
scripts/codegen/go.ts Adds external-ref-aware Go type resolution, moves session-events generation to go/rpc, emits root aliases/stubs, and adds duplicate-definition conflict checks.
scripts/codegen/csharp.ts Rewrites shared refs and extends source-gen JSON context to include externally referenced session-event types.
python/copilot/generated/rpc.py Regenerated Python RPC models to import and reuse session-event models instead of duplicating them.
nodejs/test/shared-codegen.test.ts Adds regression tests for shared-definition detection/rewriting and external definition inlining utilities.
nodejs/src/generated/rpc.ts Regenerated Node RPC types to import and reuse session-event types instead of duplicating interfaces.
go/zsession_encoding.go Replaced root encoding implementation with a stub comment (encoding now lives in go/rpc).
go/session_event_serialization_test.go Adds compile-time alias identity assertions between copilot and rpc session-event types.
go/rpc/zsession_encoding.go New generated session-event encoding implementation under the rpc package.

Copilot's findings

Files not reviewed (2)
  • go/rpc/zsession_encoding.go: Language not supported
  • go/zsession_encoding.go: Language not supported
  • Files reviewed: 8/14 changed files
  • Comments generated: 3

Comment thread scripts/codegen/utils.ts Outdated
Comment thread scripts/codegen/typescript.ts Outdated
Comment thread scripts/codegen/go.ts
@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated by SDK Consistency Review Agent for issue #1289 · ● 3.8M

Comment thread python/copilot/generated/rpc.py
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@stephentoub
Copy link
Copy Markdown
Collaborator Author

@SteveSandersonMS, how do you feel about this? We have a few changes coming down the pike from the runtime that will benefit from sharing a single set of types across both session events and rpc, e.g. rpc methods that return session events.

@qmuntal, Go by default would end up with a cycle. To address that, I have it emitting the types into rpc and then aliasing them from session events. An alternative would be putting the types into a third shared package. Preferences? Recommendations?

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread go/zsession_encoding.go Outdated
@github-actions

This comment has been minimized.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

@SteveSandersonMS
Copy link
Copy Markdown
Contributor

@stephentoub Looks good conceptually!

What's your take on the Python feedback from Copilot? Perhaps we don't need to deduplicate non-exported types, so it's fine as-is. But it seems like:

Is there a follow-up planned to also emit EmbeddedBlobResourceContents/EmbeddedTextResourceContents from the Python session events generator?

... would be an improvement. Totally OK if you want to leave that for me or Brett to follow up on.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@stephentoub
Copy link
Copy Markdown
Collaborator Author

Is there a follow-up planned to also emit EmbeddedBlobResourceContents/EmbeddedTextResourceContents from the Python session events generator?

Implemented this in the PR. The Python session-events generator now emits named exports for EmbeddedBlobResourceContents, EmbeddedTextResourceContents, and the ToolExecutionCompleteContentResourceDetails union, so ToolExecutionCompleteContent.resource is strongly typed and RPC code imports the shared embedded resource types instead of defining duplicates.

Generated by Copilot.

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated by SDK Consistency Review Agent for issue #1289 · ● 3.7M

Comment thread scripts/codegen/rust.ts
Comment thread scripts/codegen/csharp.ts
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread scripts/codegen/csharp.ts Fixed
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread scripts/codegen/csharp.ts Fixed
Comment thread scripts/codegen/csharp.ts Fixed
Comment thread scripts/codegen/csharp.ts Fixed
@github-actions

This comment has been minimized.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

Cross-SDK Consistency Review ✅

PR #1289 ("Share generated schema definitions across SDKs") has been reviewed for cross-language consistency. All five SDK implementations are updated consistently.

What this PR does

The codegen infrastructure now detects when schema definitions are identical across the API/RPC schema and the session-events schema, and eliminates duplicates. The canonical definition lives in session events; the RPC/API side imports/references it instead of maintaining its own copy.

The immediate effect: EmbeddedTextResourceContents and EmbeddedBlobResourceContents are no longer duplicated — they now exist only in session-events and are referenced from the API/RPC generated types. Additionally, ToolExecutionCompleteContentResource.Resource is now properly typed (instead of object/Any/serde_json::Value).

Per-SDK analysis

SDK Approach Status
Node.js/TypeScript Import EmbeddedTextResourceContents, EmbeddedBlobResourceContents from session-events.js; removed duplicate definitions from rpc.ts ✅ Consistent
Python Import from session_events.py; removed duplicate definitions from rpc.py ✅ Consistent
Go Moved canonical types to go/rpc/zsession_events.go; go/zsession_events.go now provides type aliases (= rpc.T) and const re-exports for source compatibility ✅ Consistent (language-appropriate approach)
.NET Added EmbeddedTextResourceContents/EmbeddedBlobResourceContents/ToolExecutionCompleteContentResourceDetails to SessionEvents.cs; registered in Rpc.cs JSON context with TypeInfoPropertyName for disambiguation ✅ Consistent
Rust Removed duplicate structs from api_types.rs; types now live only in session_events.rs and are accessible via pub use session_events::* in generated/mod.rs ✅ Consistent

Notable design points

  • Go type identity: The serialization test adds compile-time checks (var _ rpc.SessionEvent = SessionEvent{}) confirming that aliases are truly interchangeable types — important for callers using type switches.
  • Union type naming: The union wrapper type gets a context-specific name (ToolExecutionCompleteContentResourceDetails in session events vs ExternalToolTextResultForLlmContentResourceDetails in RPC) — this is intentional and consistent across all SDKs.
  • Codegen utility tests: nodejs/test/shared-codegen.test.ts adds regression coverage for the shared utils.ts logic used by all language generators.

No cross-SDK consistency issues found. The changes are generated from a shared codegen infrastructure and apply the same conceptual improvement uniformly across all languages.

Generated by SDK Consistency Review Agent for issue #1289 · ● 2.3M ·

@stephentoub stephentoub added this pull request to the merge queue May 14, 2026
Merged via the queue into main with commit 81bb92b May 14, 2026
44 checks passed
@stephentoub stephentoub deleted the stephentoub/shared-reasoning-summary-enum branch May 14, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants