Skip to content

Add event codegen script and generated event types - #742

Draft
kraenhansen wants to merge 3 commits into
kh/event-emitterfrom
kh/event-emitter-codegen
Draft

Add event codegen script and generated event types#742
kraenhansen wants to merge 3 commits into
kh/event-emitterfrom
kh/event-emitter-codegen

Conversation

@kraenhansen

@kraenhansen kraenhansen commented May 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Add scripts/generate-events.ts that reads agent.asyncapi.yaml and generates typed event mappings
  • Generate src/generated/events.ts with GeneratedEventMap, GeneratedWireType, and runtime lookup tables
  • Generate src/generated/dispatch.ts with dispatchGeneratedEvent() helper
  • Add generate-events task to turbo pipeline
  • Add yaml and prettier as dev dependencies

The 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-events produces correct output
  • pnpm turbo build — all packages compile
  • pnpm turbo check-types — no type errors
  • pnpm turbo lint — no lint errors
  • pnpm 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.ts now reads schemas/agent.asyncapi.yaml and generates src/generated/events.ts (typed GeneratedEventMap/GeneratedWireType plus wire-type lookup tables) and src/generated/dispatch.ts (dispatchGeneratedEvent() helper).

Wires this into the monorepo build via a new generate-events script and Turbo task (with declared inputs/outputs), and adds yaml + prettier dev 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.

kraenhansen and others added 3 commits May 7, 2026 13:21
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>
@kraenhansen
kraenhansen force-pushed the kh/event-emitter-codegen branch from 63ea99c to ccc9b90 Compare May 7, 2026 11:55

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ccc9b90. Configure here.

@kraenhansen
kraenhansen marked this pull request as draft May 7, 2026 14:22
Base automatically changed from kh/event-emitter-move-schemas-types to kh/event-emitter May 8, 2026 17: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.

1 participant