Repository navigation
Generate the public client types from the schema - #549
Merged
Merged
Conversation
This comment has been minimized.
This comment has been minimized.
SaladDay
force-pushed
the
refactor/generated-public-ts
branch
from
October 8, 2026 07:38
4bb3623 to
084ed90
Compare
make openapi now projects the public schema onto packages/agents-client/src/generated/public-api.ts: each schema's TypeScript type, each enum's values and each object's field names, with required lists and per-union field maps. make check-openapi rejects a stale copy. The emitter takes a parsed schema dict and accepts the Swagger 2.0 forms of the Core document (x-nullable, allOf, any ref prefix), so the /core/v1 projection can reuse it. The client aliases the generated types and validates responses with the generated field sets and enums instead of hand-written copies. Where the schema and the validators disagreed, the schema wins: snapshot events carry no session_id, Item events require output_index, terminal Turn events require usage, list envelopes are complete, input_image is accepted in user messages, and older-Core allowances are gone. The client no longer re-checks limits Core enforces. Core now sends turn_id null on Environment events, null cwd, output, exit_code and duration_ms on command_execution Items, and param null on the stream interruption error, as the pinned schema requires.
This was referenced Oct 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Generates the TypeScript client's
/v1types, enum values and field names from the same public schema that already produces Core's Go types, and deletes the hand-written copies.Generator.
scripts/generate-public-api.pygains a 72-line emitter (ts_module) that writespackages/agents-client/src/generated/public-api.ts: each schema's type, enums asxValuesplus a union, objects asxFields(andxRequiredwhen some fields are optional), and discriminated unions as{tag: variantFields}.make openapiwrites it andmake check-openapifails when it is stale. No new dependency. The emitter takes any parsed schema dict (OpenAPI 3.1 or Swagger 2.0), so the/core/v1types can follow fromcore.openapi.yaml.Client.
types.tsaliases the generated types, and every/v1field set and enum inclient.tsand the projection files reads the generated one (66 hand-written sets inclient.tsdown to 13 that are client-defined or/core/v1). The strict validators stay. Where a hand-written set disagreed with the schema, the schema wins:session_id;item_idand requireoutput_index;usage;turn.waitingpasses through as an unknown event;function_call_outputhas noduration_ms;web_search_callItems have nofailedstatus;{code, type, message};input_image;SessionError.codemay be null.Required fields Core always sends are now required. The client no longer re-checks limits Core enforces: batch and idempotency-key sizes, list ranges, and upload and name bounds. The two known differences between the schema and the service, null File
expires_at/status_detailsand nullfirst_id/last_idon empty File pages, keep their recorded allowance (coverage ledger).Core, to match the pinned schema.
turn_id, null when no Turn is linked.command_executionItems always carry nullablecwd,output,exit_codeandduration_ms.param: null.Docs. The client README, the contract index (en/zh) and the Session events rules (en/zh).
Net: hand-written non-test code −514 lines; generated +1,970; tests −105.
Checks:
make openapi(idempotent) andmake check-openapi, including a stale-file probe;tscand vitest (711);tscand vitest (382);tscand tests;go build ./...andgo vet;contracts/agents-api/v1,api,items,sessionpg,executionandtests/integration. One environment test expected four event fields; it now expectsturn_id: null.check-names.py,check-docsand the translation test.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.