Share generated schema definitions across SDKs#1289
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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
$refrewriting/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
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 #1289 · ● 3.8M
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@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>
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
|
@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:
... 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>
Implemented this in the PR. The Python session-events generator now emits named exports for Generated by Copilot. |
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 #1289 · ● 3.7M
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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 doesThe 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: Per-SDK analysis
Notable design points
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.
|
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
go/rpc, with rootcopilotaliases and const re-exports so there is one Go type identity for session events.