Commit bc42b10
[Codegen] Honor internal flag on session event types in Node codegen (#2177)
* [Codegen] Keep Internal Types That Public Declarations Reference
* Fix @internal stripping: filter union arms correctly, fail hard on violations
The root cause of dangling @internal types in the emitted .d.ts was in the
publicVariants filter inside generateSessionEvents. The filter checked only
the 'data' sub-property of each resolved variant for internal visibility,
but missed the case where the arm object itself or its resolved definition is
marked visibility:internal. Internal event types (AssistantTurnRetryEvent,
ModelCallStartEvent) therefore passed through the filter and appeared in the
generated SessionEvent union — while their declarations were separately tagged
@internal and stripped — leaving dangling references that collapsed to 'any'.
Fix the filter to also check isSchemaInternal on the arm object and on the
resolved definition. With this, internal union arms are excluded from
compilation entirely: no declaration, no union member, no dangling reference.
For RPC, fix emitClientGlobalApiRegistration to filter internal methods from
the generated handler interface (HooksHandler), so internal method param types
(HookInvokeRequest, HookType, etc.) are no longer referenced by any public
declaration. The registration function body still wires up the internal RPC
handler internally, but function bodies are not emitted in declaration files.
Replace the PR's strippableInternalTypes workaround (which silently promoted
internal types to public rather than failing) with assertNoPublicInternalReferences,
which throws hard if the codegen ever produces a public declaration referencing
an internal type. The schema lint in the runtime already guarantees the schema
is valid; a violation here means the codegen has a bug, not something to paper over.
Export filterPublicSessionEventVariants and assertNoPublicInternalReferences
and add unit tests covering: public arms kept, internal arms excluded (by arm
visibility, by definition visibility, and by data-property visibility), the
validator passing on @internal-tagged members and function bodies, and the
validator throwing on direct public references to internal types.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: skip all-internal client global handler groups from public interface
When all methods in a client-global RPC group are marked visibility:internal
(currently: hooks.invoke), do not include the group in the generated
HooksHandler interface or ClientGlobalApiHandlers. The registration body
likewise only wires up public methods.
The SDK handles hooks.invoke internally: client.ts registers the handler
directly via connection.onRequest, bypassing ClientGlobalApiHandlers, so
that HookInvokeRequest/HookType never appear in the public .d.ts surface.
Tests that exercised clientGlobalHandlers.hooks.invoke are updated to call
handleHooksInvoke directly — the same validation of the wire-format contract
without depending on the now-removed public handler plumbing.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* style: apply prettier formatting to client hooks registration
Fix the CI-only formatting failure in nodejs/src/client.ts introduced by the
previous hooks.invoke plumbing change.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* test: tighten internal reference validation and coverage
Fix assertNoPublicInternalReferences so it only strips function bodies,
preserving interface/type member signatures for validation. Also remove
@internal-tagged members before scanning and add a regression test that a
public interface member referencing an internal type fails validation.
Add an explicit unit test that attachConnectionHandlers registers the
hand-written hooks.invoke JSON-RPC entry point and routes it to
handleHooksInvoke. Rename the legacy-pattern session-event test to match its
actual assertions.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: ignore internal object-valued members in TS validator
The fail-hard validator correctly ignores simple @internal-tagged members,
but it still treated inline object-shaped members like
as public references. That caused false failures
when public event payloads contained internal members whose types are removed
by stripInternal.
Extend the member-removal pass to drop both simple and inline object-valued
@internal members before scanning for public references, and add a regression
test covering that shape.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent e9a0f22 commit bc42b10
6 files changed
Lines changed: 432 additions & 159 deletions
File tree
- nodejs
- src
- generated
- test
- scripts/codegen
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
831 | 831 | | |
832 | 832 | | |
833 | 833 | | |
834 | | - | |
835 | | - | |
836 | | - | |
837 | | - | |
838 | | - | |
839 | 834 | | |
840 | 835 | | |
841 | 836 | | |
| |||
2850 | 2845 | | |
2851 | 2846 | | |
2852 | 2847 | | |
| 2848 | + | |
| 2849 | + | |
| 2850 | + | |
| 2851 | + | |
| 2852 | + | |
| 2853 | + | |
| 2854 | + | |
| 2855 | + | |
| 2856 | + | |
| 2857 | + | |
| 2858 | + | |
2853 | 2859 | | |
2854 | 2860 | | |
2855 | 2861 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3139 | 3139 | | |
3140 | 3140 | | |
3141 | 3141 | | |
| 3142 | + | |
| 3143 | + | |
| 3144 | + | |
| 3145 | + | |
| 3146 | + | |
| 3147 | + | |
| 3148 | + | |
| 3149 | + | |
| 3150 | + | |
| 3151 | + | |
| 3152 | + | |
| 3153 | + | |
| 3154 | + | |
| 3155 | + | |
| 3156 | + | |
| 3157 | + | |
| 3158 | + | |
| 3159 | + | |
| 3160 | + | |
| 3161 | + | |
| 3162 | + | |
| 3163 | + | |
| 3164 | + | |
| 3165 | + | |
| 3166 | + | |
| 3167 | + | |
| 3168 | + | |
| 3169 | + | |
| 3170 | + | |
| 3171 | + | |
| 3172 | + | |
| 3173 | + | |
| 3174 | + | |
| 3175 | + | |
| 3176 | + | |
| 3177 | + | |
| 3178 | + | |
| 3179 | + | |
3142 | 3180 | | |
3143 | | - | |
3144 | | - | |
3145 | | - | |
3146 | | - | |
3147 | | - | |
3148 | | - | |
3149 | | - | |
3150 | | - | |
3151 | | - | |
| 3181 | + | |
| 3182 | + | |
3152 | 3183 | | |
3153 | 3184 | | |
3154 | 3185 | | |
| |||
3172 | 3203 | | |
3173 | 3204 | | |
3174 | 3205 | | |
3175 | | - | |
| 3206 | + | |
3176 | 3207 | | |
3177 | 3208 | | |
3178 | 3209 | | |
| |||
3249 | 3280 | | |
3250 | 3281 | | |
3251 | 3282 | | |
3252 | | - | |
| 3283 | + | |
3253 | 3284 | | |
3254 | 3285 | | |
3255 | 3286 | | |
| |||
0 commit comments