Add event codegen script and generated event types - #742
Conversation
Move AsyncAPI schemas from packages/types/schemas/ to schemas/ at repo root, with symlinks from both packages. Move manually maintained types (Role, Mode, Status, Callbacks, etc.) from @elevenlabs/types to @elevenlabs/client, making the types package generated-code-only. This is preparation for event codegen in the client package, which needs direct access to the schemas. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Records the removal of manual types from @elevenlabs/types as a minor bump (pre-v1). Consumers should import these types from @elevenlabs/client instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add `scripts/generate-events.ts` to the client package that reads `agent.asyncapi.yaml` and generates: - `GeneratedEventMap` with typed event callbacks for each wire event - `GeneratedWireType` union of all generated wire type strings - `WIRE_TYPE_TO_EVENT_NAME` / `WIRE_TYPE_TO_PAYLOAD_FIELD` lookup tables - `dispatchGeneratedEvent()` helper for runtime dispatch Internally handled events (audio, agent_response, user_transcript, client_tool_call, ping, error, internal_tentative_agent_response) are excluded — they need custom dispatch logic in BaseConversation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
63ea99c to
ccc9b90
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ccc9b90. Configure here.
| // --------------------------------------------------------------------------- | ||
|
|
||
| function generateEventsFile(): string { | ||
| const imports = events.map((e) => ` ${e.typeName},`).join("\n"); |
There was a problem hiding this comment.
Codegen emits unused import for payload-less events
Low Severity
The codegen script imports the type name for every event (events.map((e) => e.typeName)), but only references the type in GeneratedEventMap when payloadField is non-null (line 160). For guardrail_triggered, which has payloadField: null, GuardrailTriggered is imported but never used in the generated events.ts. The imports list needs to filter out events with no payload field.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit ccc9b90. Configure here.


Summary
scripts/generate-events.tsthat readsagent.asyncapi.yamland generates typed event mappingssrc/generated/events.tswithGeneratedEventMap,GeneratedWireType, and runtime lookup tablessrc/generated/dispatch.tswithdispatchGeneratedEvent()helpergenerate-eventstask to turbo pipelineyamlandprettieras dev dependenciesThe codegen excludes 7 internally-handled wire events (
audio,agent_response,user_transcript,client_tool_call,ping,error,internal_tentative_agent_response) that need custom dispatch logic. All other 13 server→client events are generated mechanically.Stacks on #739. Part of #738 (PR 2/6)
Test plan
pnpm -C packages/client run generate-eventsproduces correct outputpnpm turbo build— all packages compilepnpm turbo check-types— no type errorspnpm turbo lint— no lint errorspnpm turbo test— all tests pass🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
Note
Low Risk
Low risk: changes are build-time tooling plus generated type/lookup tables; runtime impact is limited to adding new source files without modifying existing conversation logic.
Overview
Adds an event codegen pipeline for the JS client:
scripts/generate-events.tsnow readsschemas/agent.asyncapi.yamland generatessrc/generated/events.ts(typedGeneratedEventMap/GeneratedWireTypeplus wire-type lookup tables) andsrc/generated/dispatch.ts(dispatchGeneratedEvent()helper).Wires this into the monorepo build via a new
generate-eventsscript and Turbo task (with declared inputs/outputs), and addsyaml+prettierdev dependencies to support parsing and formatting of generated files.Reviewed by Cursor Bugbot for commit ccc9b90. Bugbot is set up for automated code reviews on this repo. Configure here.