Skip to content

fix(ai-elevenlabs): prevent duplicate user messages and fix client tools#419

Merged
jherr merged 2 commits intomainfrom
elevenlabs-dupe-fix
Apr 5, 2026
Merged

fix(ai-elevenlabs): prevent duplicate user messages and fix client tools#419
jherr merged 2 commits intomainfrom
elevenlabs-dupe-fix

Conversation

@jherr
Copy link
Copy Markdown
Contributor

@jherr jherr commented Apr 5, 2026

Summary

  • Duplicate messages: The ElevenLabs adapter emitted both transcript and message_complete for every message regardless of role. Since RealtimeClient already creates user messages from final transcripts, this caused every user message to appear twice. Fixed by only emitting transcript for user messages and message_complete for assistant messages.
  • Broken client tools: Tools were passed as { handler, description, parameters } objects, but @11labs/client@0.2.0 expects plain async functions. The SDK silently ignored the non-callable values. Fixed by passing plain functions directly.

Test plan

  • Added unit tests for message event routing (user → transcript only, assistant → message_complete only)
  • Added unit tests verifying client tools are registered as plain functions callable by the SDK
  • All 6 tests pass

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed ElevenLabs Realtime adapter to emit correct event types based on message source: transcript events for user messages and message completion events for assistant responses.
    • Corrected tool registration with ElevenLabs client to properly handle configured tools.
  • Tests

    • Added comprehensive test suite for ElevenLabs Realtime adapter validating event routing accuracy and tool integration behavior.

The ElevenLabs adapter had two bugs:

1. onMessage emitted both transcript and message_complete for all roles,
   causing duplicate user messages since RealtimeClient already creates
   user messages from final transcripts.

2. Client tools were passed as { handler, description, parameters } objects
   but @11labs/client@0.2.0 expects plain async functions, so tools were
   silently ignored.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8615b6ce-7f20-4154-8cba-a3a4b0f93771

📥 Commits

Reviewing files that changed from the base of the PR and between 297fd75 and 3654649.

📒 Files selected for processing (3)
  • .changeset/fix-elevenlabs-dupe-and-tools.md
  • packages/typescript/ai-elevenlabs/src/realtime/adapter.ts
  • packages/typescript/ai-elevenlabs/tests/realtime-adapter.test.ts

📝 Walkthrough

Walkthrough

The changes fix two behavioral issues in the ElevenLabs Realtime adapter: adjusting message event emission so transcript events are emitted only for user messages and message_complete events only for assistant messages, and correcting tool registration to pass plain async functions instead of tool definition objects to the ElevenLabs client.

Changes

Cohort / File(s) Summary
Changeset Documentation
.changeset/fix-elevenlabs-dupe-and-tools.md
Metadata documenting patch release fixes for message event routing and tool registration behavior.
Adapter Implementation
packages/typescript/ai-elevenlabs/src/realtime/adapter.ts
Modified event emission logic to conditionally emit transcript for user-sourced messages and message_complete for assistant-sourced messages. Updated tool integration to register client tools as plain async functions instead of tool definition objects.
Test Coverage
packages/typescript/ai-elevenlabs/tests/realtime-adapter.test.ts
New test suite validating event routing to prevent duplicate events, tool registration behavior, and sequential message handling scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Through the labs of eleven, our messages now roam,
User transcripts here, assistant's message home,
Tools as functions plain, no wrappers in sight,
Events route correctly—swish—everything's right!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes both main fixes: preventing duplicate user messages and fixing client tools registration in the ElevenLabs adapter.
Description check ✅ Passed The description provides a clear summary of changes, test plan verification, but is missing the required checklist items and explicit changeset confirmation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch elevenlabs-dupe-fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 5, 2026

🚀 Changeset Version Preview

1 package(s) bumped directly, 0 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/ai-elevenlabs 0.1.3 → 0.1.4 Changeset

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Apr 5, 2026

View your CI Pipeline Execution ↗ for commit 3654649

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 41s View ↗
nx run-many --targets=build --exclude=examples/** ✅ Succeeded 2s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-05 20:25:24 UTC

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 5, 2026

Open in StackBlitz

@tanstack/ai

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai@419

@tanstack/ai-anthropic

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-anthropic@419

@tanstack/ai-client

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-client@419

@tanstack/ai-code-mode

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode@419

@tanstack/ai-code-mode-skills

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode-skills@419

@tanstack/ai-devtools-core

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-devtools-core@419

@tanstack/ai-elevenlabs

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-elevenlabs@419

@tanstack/ai-event-client

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-event-client@419

@tanstack/ai-fal

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-fal@419

@tanstack/ai-gemini

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-gemini@419

@tanstack/ai-grok

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok@419

@tanstack/ai-groq

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-groq@419

@tanstack/ai-isolate-cloudflare

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-cloudflare@419

@tanstack/ai-isolate-node

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-node@419

@tanstack/ai-isolate-quickjs

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs@419

@tanstack/ai-ollama

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollama@419

@tanstack/ai-openai

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openai@419

@tanstack/ai-openrouter

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openrouter@419

@tanstack/ai-preact

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-preact@419

@tanstack/ai-react

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react@419

@tanstack/ai-react-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react-ui@419

@tanstack/ai-solid

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid@419

@tanstack/ai-solid-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid-ui@419

@tanstack/ai-svelte

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-svelte@419

@tanstack/ai-vue

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue@419

@tanstack/ai-vue-ui

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue-ui@419

@tanstack/preact-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/preact-ai-devtools@419

@tanstack/react-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/react-ai-devtools@419

@tanstack/solid-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/solid-ai-devtools@419

commit: 3654649

@jherr jherr merged commit 122a913 into main Apr 5, 2026
7 checks passed
@jherr jherr deleted the elevenlabs-dupe-fix branch April 5, 2026 20:26
@github-actions github-actions bot mentioned this pull request Apr 5, 2026
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