Add typed event emitter to BaseConversation#744
Conversation
Replace direct this.options.onXxx() callback invocations with this.emit() calls through a typed event emitter. Constructor-provided callbacks are automatically registered as initial listeners. The emitter supports multiple listeners per event, with on() returning an unsubscribe function for ergonomic cleanup. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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 269e93c. Configure here.
| if (event !== "error") { | ||
| this.emit("error", String(error)); | ||
| } | ||
| } |
There was a problem hiding this comment.
Listener errors silently swallowed, bypassing console.error
Medium Severity
When a non-error listener throws, the emit catch block calls this.emit("error", String(error)) instead of this.onError(...). This bypasses the console.error call in the private onError method. Since getFullOptions registers a default no-op onError: () => {} as a listener, listener errors are completely silenced when no custom error handler is provided. Calling this.onError(String(error)) instead would preserve console visibility while still being safe from infinite recursion (the existing event !== "error" guard in the catch block would prevent it).
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 269e93c. Configure here.


Summary
on(),off(), andemit()methods toBaseConversationwith fullConversationEventMaptypingon()returns an unsubscribe function; multiple listeners per event are supportedCALLBACK_KEY_TO_EVENT_NAMEthis.options.onXxx()invocations inBaseConversationwiththis.emit()calls@elevenlabs/clientminor bumpPart of #738 (PR 4/6).
Test plan
agent_response_correctioncallback test)Conversation.startSession({ onMessage: ... })API unchanged🤖 Generated with Claude Code
Note
Medium Risk
Refactors how conversation events are dispatched (callbacks now routed through an emitter), which could subtly change event ordering/duplication and error propagation across the SDK.
Overview
Adds a typed event emitter API to conversations via new
BaseConversation.on()/off()(withon()returning an unsubscribe) and an internalemit().Re-routes all existing constructor callback options (
onMessage,onDisconnect, etc.) through the emitter by auto-registering them at construction time and replacing directoptions.onXxx()calls withemit()invocations (including guarded handling forunhandled-client-tool-call).Includes a
@elevenlabs/clientchangeset for a minor version bump and updates theBaseConversationtest harness to call the renamed message handler.Reviewed by Cursor Bugbot for commit 269e93c. Bugbot is set up for automated code reviews on this repo. Configure here.