:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(posthog-ai): remove hands-free voice mode (#115963)
Shy Alter15a33e54189e
diff --git a/ee/api/hands_free.py b/ee/api/hands_free.pydeleted file mode 100644index daedb498c2e0..000000000000--- a/ee/api/hands_free.py+++ /dev/null@@ -1,249 +0,0 @@-"""Backend support for Max's hands-free mode.--Hands-free mode lets a user talk to Max with their hands and eyes off the screen — built-for mobile-web (gym, walking, driving). Speech-to-text runs via ElevenLabs Scribe directly-from the browser using single-use tokens minted here so the ElevenLabs API key never-reaches the client. Text-to-speech is proxied through the synthesize endpoint, again to-keep the API key server-side; mp3 bytes stream back to the browser.-"""--from typing import Any--from django.conf import settings-from django.http import StreamingHttpResponse--import requests-import structlog-from drf_spectacular.utils import extend_schema-from prometheus_client import Counter-from rest_framework import serializers, status-from rest_framework.decorators import action-from rest_framework.exceptions import APIException-from rest_framework.parsers import JSONParser-from rest_framework.permissions import IsAuthenticated-from rest_framework.request import Request-from rest_framework.response import Response-from rest_framework.viewsets import GenericViewSet--from posthog.api.routing import TeamAndOrgViewSetMixin-from posthog.api.streaming import streaming_response-from posthog.permissions import PostHogFeatureFlagPermission-from posthog.rate_limit import (- MaxHandsFreeSynthesizeBurstRateThrottle,- MaxHandsFreeSynthesizeSustainedRateThrottle,- MaxHandsFreeTokenBurstRateThrottle,- MaxHandsFreeTokenSustainedRateThrottle,-)--from products.posthog_ai.backend.models.assistant import Conversation--logger = structlog.get_logger(__name__)--ELEVENLABS_TIMEOUT_SECONDS = (5, 10)-# Generous enough for any Max summary, tight enough that an attacker minting at the-# throttle ceiling can't ramp Scribe cost into the stratosphere.-TTS_MAX_INPUT_CHARS = 2000--# One counter, partitioned by outcome — lets us track abuse signal (provider rejection-# spikes, repeated empty tokens) and steady-state cost (ok counts ≈ Scribe spend) without-# blowing up cardinality via per-team labels.-HANDS_FREE_TOKEN_COUNTER = Counter(- "max_hands_free_token_total",- "Outcomes for ElevenLabs Scribe single-use token mints from the hands-free endpoint.",- labelnames=["outcome"],-)-HANDS_FREE_SYNTHESIZE_COUNTER = Counter(- "max_hands_free_synthesize_total",- "Outcomes for ElevenLabs TTS proxy requests from the hands-free endpoint.",- labelnames=["outcome"],-)-HANDS_FREE_SYNTHESIZE_CHARS_COUNTER = Counter(- "max_hands_free_synthesize_chars_total",- "Total characters submitted for ElevenLabs TTS — proxy for TTS spend.",-)---class HandsFreeNotConfigured(APIException):- status_code = status.HTTP_503_SERVICE_UNAVAILABLE- default_detail = "Hands-free mode is not configured on this PostHog instance."- default_code = "hands_free_not_configured"---class HandsFreeProviderError(APIException):- status_code = status.HTTP_502_BAD_GATEWAY- default_detail = "The hands-free provider rejected the request."- default_code = "hands_free_provider_error"---class SynthesizeSerializer(serializers.Serializer):- text = serializers.CharField(- required=True,- max_length=TTS_MAX_INPUT_CHARS,- help_text="The text the assistant should speak aloud.",- )---class HandsFreeTokenSerializer(serializers.Serializer):- token = serializers.CharField(help_text="Single-use ElevenLabs Scribe realtime token, valid for 15 minutes.")---def _require_api_key(counter: Counter) -> str:- api_key = settings.ELEVENLABS_API_KEY- if not api_key:- counter.labels(outcome="missing_key").inc()- logger.warning("max_hands_free_api_key_missing")- raise HandsFreeNotConfigured()- return api_key---@extend_schema(extensions={"x-product": "posthog_ai"})-class MaxHandsFreeViewSet(TeamAndOrgViewSetMixin, GenericViewSet):- scope_object = "INTERNAL"- # Hands-free actions are list-level and don't operate on any model — DRF's GenericViewSet- # needs a queryset attribute for the routing scaffolding but it is never read.- queryset = Conversation.objects.none()- # drf-spectacular requires every viewset to declare a serializer_class for OpenAPI- # generation. The `token` action takes no body and `synthesize` overrides this via- # its @extend_schema decorator, so SynthesizeSerializer is purely the schema-default- # — never instantiated by the viewset's own get_serializer().- serializer_class = SynthesizeSerializer- # Server-side gate on the same feature flag the frontend checks — without it an- # authenticated project member could POST directly to /token/ or /synthesize/ and- # rack up ElevenLabs spend even when their org doesn't have hands-free enabled.- posthog_feature_flag = "max-hands-free"- permission_classes = [IsAuthenticated, PostHogFeatureFlagPermission]-- @extend_schema(request=None, responses={200: HandsFreeTokenSerializer})- @action(- detail=False,- methods=["POST"],- url_path="token",- throttle_classes=[MaxHandsFreeTokenBurstRateThrottle, MaxHandsFreeTokenSustainedRateThrottle],- )- def token(self, request: Request, *args: Any, **kwargs: Any) -> Response:- """Mint a single-use ElevenLabs Scribe realtime token.-- The browser uses the token to open a WebSocket directly to ElevenLabs — audio never- transits PostHog infrastructure. Tokens are time-bound (15 min) and single-use; the- per-team rate limit on this endpoint caps how often a user can mint new ones.-- Never logs the upstream response body — provider error responses can echo PII back and- we don't want any of that landing in structured logs.- """- api_key = _require_api_key(HANDS_FREE_TOKEN_COUNTER)- try:- upstream = requests.post(- f"{settings.ELEVENLABS_API_BASE_URL}/v1/single-use-token/realtime_scribe",- headers={"xi-api-key": api_key},- timeout=ELEVENLABS_TIMEOUT_SECONDS,- )- except requests.RequestException:- HANDS_FREE_TOKEN_COUNTER.labels(outcome="provider_unreachable").inc()- logger.exception("max_hands_free_token_failed")- raise HandsFreeProviderError("Failed to reach the hands-free provider.")-- if upstream.status_code != status.HTTP_200_OK:- HANDS_FREE_TOKEN_COUNTER.labels(outcome="provider_rejected").inc()- logger.warning("max_hands_free_token_rejected", status_code=upstream.status_code)- raise HandsFreeProviderError(f"Hands-free provider returned {upstream.status_code}.")-- try:- body = upstream.json()- if not isinstance(body, dict):- raise ValueError("Expected JSON object")- token: str = body.get("token", "")- except ValueError:- HANDS_FREE_TOKEN_COUNTER.labels(outcome="provider_rejected").inc()- logger.warning("max_hands_free_token_malformed_json", status_code=upstream.status_code)- raise HandsFreeProviderError("Hands-free provider returned a malformed response.")- if not token:- HANDS_FREE_TOKEN_COUNTER.labels(outcome="empty_token").inc()- logger.warning("max_hands_free_token_empty")- raise HandsFreeProviderError("Hands-free provider returned an empty token.")- HANDS_FREE_TOKEN_COUNTER.labels(outcome="ok").inc()- return Response({"token": token})-- # Excluded on purpose: the response is streamed audio/mpeg, and Orval's shared mutator parses- # every response as JSON. The caller in lib/api.ts uses api.createResponse to read the stream.- @extend_schema(exclude=True)- @action(- detail=False,- methods=["POST"],- url_path="synthesize",- parser_classes=[JSONParser],- throttle_classes=[MaxHandsFreeSynthesizeBurstRateThrottle, MaxHandsFreeSynthesizeSustainedRateThrottle],- )- def synthesize(self, request: Request, *args: Any, **kwargs: Any) -> StreamingHttpResponse:- """Proxy text-to-speech to ElevenLabs, streaming mp3 audio back to the browser.-- The viewset has no per-action `parser_classes` other than this one because the- token endpoint takes no body. Putting JSONParser here keeps the rest of the- viewset parser-free.- """- serializer = SynthesizeSerializer(data=request.data)- serializer.is_valid(raise_exception=True)- text = serializer.validated_data["text"]-- api_key = _require_api_key(HANDS_FREE_SYNTHESIZE_COUNTER)- voice_id = settings.ELEVENLABS_VOICE_ID- if not voice_id:- HANDS_FREE_SYNTHESIZE_COUNTER.labels(outcome="missing_voice_id").inc()- logger.warning("max_hands_free_voice_id_missing")- raise HandsFreeNotConfigured("Voice ID is not configured.")- try:- upstream = requests.post(- f"{settings.ELEVENLABS_API_BASE_URL}/v1/text-to-speech/{voice_id}",- headers={- "xi-api-key": api_key,- "Accept": "audio/mpeg",- "Content-Type": "application/json",- },- json={"text": text, "model_id": settings.ELEVENLABS_TTS_MODEL_ID},- timeout=ELEVENLABS_TIMEOUT_SECONDS,- stream=True,- )- except requests.RequestException:- HANDS_FREE_SYNTHESIZE_COUNTER.labels(outcome="provider_unreachable").inc()- logger.exception("max_hands_free_synthesize_failed")- raise HandsFreeProviderError("Failed to reach the hands-free provider.")-- if upstream.status_code != status.HTTP_200_OK:- HANDS_FREE_SYNTHESIZE_COUNTER.labels(outcome="provider_rejected").inc()- # ElevenLabs 4xx responses are JSON describing the account/quota state — not the- # user's input. Safe to log a snippet so devs can see "quota_exceeded" vs- # "voice_not_found" without hitting the dashboard.- body_preview = ""- try:- body_preview = upstream.text[:300].replace("\n", " ")- except Exception:- pass- logger.warning(- "max_hands_free_synthesize_rejected",- status_code=upstream.status_code,- body_preview=body_preview,- )- upstream.close()- raise HandsFreeProviderError(f"Hands-free provider returned {upstream.status_code}.")-- # Anything between the upstream 200 and returning the StreamingHttpResponse can- # raise (a counter labels() call, the StreamingHttpResponse constructor, the- # header assignment). Without an explicit close on those paths the connection- # only releases when the unconsumed generator is garbage collected — which is- # not guaranteed to be prompt under load. Guard the whole block.- try:- HANDS_FREE_SYNTHESIZE_COUNTER.labels(outcome="ok").inc()- HANDS_FREE_SYNTHESIZE_CHARS_COUNTER.inc(len(text))-- def stream_and_close() -> Any:- try:- yield from upstream.iter_content(chunk_size=4096)- finally:- upstream.close()-- response = streaming_response(- stream_and_close(), content_type="audio/mpeg", headers={"Cache-Control": "no-store"}- )- except Exception:- upstream.close()- raise- return responsediff --git a/ee/api/test/test_hands_free.py b/ee/api/test/test_hands_free.pydeleted file mode 100644index 44ba7eae4ad8..000000000000--- a/ee/api/test/test_hands_free.py+++ /dev/null@@ -1,149 +0,0 @@-from posthog.test.base import APIBaseTest-from unittest.mock import MagicMock, patch--from django.test import override_settings---@override_settings(- ELEVENLABS_API_KEY="test-key",- ELEVENLABS_API_BASE_URL="https://api.elevenlabs.example",-)-class TestMaxHandsFreeAPI(APIBaseTest):- def setUp(self) -> None:- super().setUp()- # The viewset gates on the max-hands-free feature flag server-side; force it on- # so tests exercise the endpoint logic rather than the entitlement check.- self._ff_patcher = patch("posthoganalytics.feature_enabled", return_value=True)- self._ff_patcher.start()- self.addCleanup(self._ff_patcher.stop)-- def _token_url(self) -> str:- return f"/api/environments/{self.team.id}/max_hands_free/token/"-- @patch("ee.api.hands_free.requests.post")- def test_token_returns_signed_token_from_elevenlabs(self, mock_post: MagicMock) -> None:- mock_post.return_value = MagicMock(- status_code=200,- json=MagicMock(return_value={"token": "single-use-token-abc"}),- )-- response = self.client.post(self._token_url(), format="json")-- assert response.status_code == 200- assert response.json() == {"token": "single-use-token-abc"}- assert mock_post.call_args.args[0].endswith("/v1/single-use-token/realtime_scribe")- assert mock_post.call_args.kwargs["headers"]["xi-api-key"] == "test-key"-- @override_settings(ELEVENLABS_API_KEY="")- def test_returns_503_when_api_key_missing(self) -> None:- response = self.client.post(self._token_url(), format="json")- assert response.status_code == 503-- @patch("ee.api.hands_free.requests.post")- def test_returns_502_when_provider_errors(self, mock_post: MagicMock) -> None:- mock_post.return_value = MagicMock(status_code=429, text="rate limited")- response = self.client.post(self._token_url(), format="json")- assert response.status_code == 502-- @patch("ee.api.hands_free.requests.post")- def test_returns_502_when_provider_returns_empty_token(self, mock_post: MagicMock) -> None:- mock_post.return_value = MagicMock(status_code=200, json=MagicMock(return_value={"token": ""}))- response = self.client.post(self._token_url(), format="json")- assert response.status_code == 502-- @patch("ee.api.hands_free.requests.post")- def test_provider_error_does_not_log_response_body(self, mock_post: MagicMock) -> None:- upstream = MagicMock(status_code=500, text="ECHOED API KEY OR PII")- mock_post.return_value = upstream-- with patch("ee.api.hands_free.logger") as mock_logger:- response = self.client.post(self._token_url(), format="json")-- assert response.status_code == 502- log_calls = mock_logger.warning.call_args_list + mock_logger.exception.call_args_list- for call in log_calls:- for value in list(call.args) + list(call.kwargs.values()):- assert "ECHOED API KEY OR PII" not in str(value)-- def test_requires_authentication(self) -> None:- self.client.logout()- response = self.client.post(self._token_url(), format="json")- assert response.status_code in (401, 403)-- def _synthesize_url(self) -> str:- return f"/api/environments/{self.team.id}/max_hands_free/synthesize/"-- @patch("ee.api.hands_free.requests.post")- def test_synthesize_streams_audio_from_elevenlabs(self, mock_post: MagicMock) -> None:- mock_post.return_value = MagicMock(- status_code=200,- iter_content=MagicMock(return_value=iter([b"mp3-chunk-1", b"mp3-chunk-2"])),- )-- response = self.client.post(self._synthesize_url(), data={"text": "hello"}, format="json")-- assert response.status_code == 200- assert response["Content-Type"] == "audio/mpeg"- assert response["Cache-Control"] == "no-store"- assert b"".join(response.streaming_content) == b"mp3-chunk-1mp3-chunk-2" # type: ignore[attr-defined]- mock_post.return_value.close.assert_called_once()-- def test_synthesize_rejects_text_over_limit(self) -> None:- response = self.client.post(- self._synthesize_url(),- data={"text": "x" * 2001},- format="json",- )- assert response.status_code == 400-- def test_synthesize_rejects_empty_text(self) -> None:- response = self.client.post(self._synthesize_url(), data={"text": ""}, format="json")- assert response.status_code == 400-- @patch("ee.api.hands_free.requests.post")- def test_synthesize_502_when_provider_errors(self, mock_post: MagicMock) -> None:- mock_post.return_value = MagicMock(status_code=429, text="quota exceeded")- response = self.client.post(self._synthesize_url(), data={"text": "hello"}, format="json")- assert response.status_code == 502- mock_post.return_value.close.assert_called_once()-- @override_settings(ELEVENLABS_API_KEY="")- def test_synthesize_503_when_api_key_missing(self) -> None:- response = self.client.post(self._synthesize_url(), data={"text": "hello"}, format="json")- assert response.status_code == 503-- def test_endpoints_403_when_feature_flag_disabled_for_org(self) -> None:- # Stop the class-level patch so the real PostHogFeatureFlagPermission runs against- # an org that doesn't have the flag enabled — expect 403, no upstream calls.- self._ff_patcher.stop()- with patch("posthoganalytics.feature_enabled", return_value=False):- token_response = self.client.post(self._token_url(), format="json")- synth_response = self.client.post(self._synthesize_url(), data={"text": "hello"}, format="json")- # Restart so addCleanup doesn't double-stop.- self._ff_patcher.start()- assert token_response.status_code == 403- assert synth_response.status_code == 403-- def test_synthesize_requires_authentication(self) -> None:- self.client.logout()- response = self.client.post(self._synthesize_url(), data={"text": "hello"}, format="json")- assert response.status_code in (401, 403)-- @patch("posthog.api.streaming.StreamingHttpResponse")- @patch("ee.api.hands_free.requests.post")- def test_synthesize_closes_upstream_when_response_construction_fails(- self, mock_post: MagicMock, mock_streaming_response: MagicMock- ) -> None:- # Upstream returns 200 (so close isn't called on the error-status path) but the- # StreamingHttpResponse constructor blows up before we can return. Without the- # try/except in synthesize the upstream connection would leak — Django would- # surface a 500 to the client and the requests connection would only release on- # GC of the unconsumed iter_content generator.- upstream = MagicMock(status_code=200)- mock_post.return_value = upstream- mock_streaming_response.side_effect = RuntimeError("django blew up")-- response = self.client.post(self._synthesize_url(), data={"text": "hello"}, format="json")-- assert response.status_code == 500- upstream.close.assert_called_once()diff --git a/ee/hogai/context/context.py b/ee/hogai/context/context.pyindex 164b81ad8cc7..829184e73278 100644--- a/ee/hogai/context/context.py+++ b/ee/hogai/context/context.py@@ -634,46 +634,10 @@ class AssistantContextManager(AssistantContextMixin):prompts.append(mode_prompt)if contextual_tools := await self._get_contextual_tools_prompt():prompts.append(ContextMessage(content=contextual_tools, id=str(uuid4())))- if voice_prompt := self._get_voice_mode_prompt(ui_context):- prompts.append(ContextMessage(content=voice_prompt, id=str(uuid4())))if formatted_ui_context := await self._format_ui_context(ui_context):prompts.append(ContextMessage(content=formatted_ui_context, id=str(uuid4())))return self._deduplicate_context_messages(state, prompts)- def _get_voice_mode_prompt(self, ui_context: MaxUIContext | None) -> str | None:- """Return a voice-mode instruction reflecting the current turn's modality.-- Emits a tag whenever the frontend tells us explicitly whether voice mode is on- or off — both states need to survive in conversation history so a typed turn- that follows a spoken one cleanly overrides the earlier voice formatting rules- (otherwise the prior <voice_mode> instruction keeps steering the model toward- spelled-out numbers and no markdown).- """- if ui_context is None or ui_context.voice_mode is None:- return None- if ui_context.voice_mode:- return (- "<voice_mode>\n"- "The user is asking via hands-free voice mode. Your response will be read "- "aloud by text-to-speech. Write it so it sounds natural when spoken:\n"- "- Spell out all numbers and currencies in words "- '(e.g. "one hundred dollars from five thousand two hundred and thirty eight users", '- 'not "$100 from 5,238 users").\n'- "- Spell out percentages as words "- '(e.g. "twelve point five percent", not "12.5%").\n'- "- No markdown — no headings, no bullets, no bold, no inline code or code blocks.\n"- "- No emoji.\n"- "- Use plain sentences. Keep it concise — assume the user can't see the screen.\n"- "</voice_mode>"- )- return (- "<voice_mode>\n"- "The user is no longer in hands-free voice mode for this turn. Ignore any "- "earlier voice-mode formatting instructions in this conversation: you may use "- "markdown, numerals, currency symbols, code blocks, and emoji as normal.\n"- "</voice_mode>"- )-async def _get_contextual_tools_prompt(self) -> str | None:from ee.hogai.registry import get_contextual_tool_classdiff --git a/ee/hogai/context/test/test_context.py b/ee/hogai/context/test/test_context.pyindex 53e3a95cbdd2..9769ad170fe1 100644--- a/ee/hogai/context/test/test_context.py+++ b/ee/hogai/context/test/test_context.py@@ -597,29 +597,6 @@ class TestAssistantContextManager(BaseTest):self.assertIsNone(result)mock_capture_exception.assert_called()- def test_voice_mode_prompt_on_emits_speech_formatting_rules(self):- prompt = self.context_manager._get_voice_mode_prompt(MaxUIContext(voice_mode=True))- assert prompt is not None- assert "<voice_mode>" in prompt- assert "spelled out" in prompt.lower() or "spell out" in prompt.lower()-- def test_voice_mode_prompt_off_emits_explicit_override(self):- # Explicit False must emit a counter-instruction so a typed turn after a spoken- # turn isn't still steered by the earlier <voice_mode> prompt sitting in history.- prompt = self.context_manager._get_voice_mode_prompt(MaxUIContext(voice_mode=False))- assert prompt is not None- assert "<voice_mode>" in prompt- assert "no longer" in prompt.lower() or "ignore" in prompt.lower()-- @parameterized.expand(- [- ("voice_mode field absent", MaxUIContext(insights=None)),- ("ui_context absent", None),- ]- )- def test_voice_mode_prompt_absent_when_field_not_set(self, _name: str, ui_context: MaxUIContext | None):- assert self.context_manager._get_voice_mode_prompt(ui_context) is None-def test_deduplicate_context_messages(self):"""Test that context messages are deduplicated based on existing context message content"""# Create state with existing context messagesdiff --git a/ee/urls.py b/ee/urls.pyindex 94b2dcb8ea92..fe401c1cc5b5 100644--- a/ee/urls.py+++ b/ee/urls.py@@ -36,7 +36,7 @@ def extend_api_router() -> None:router as root_router,)- from ee.api import hands_free, max_tools+ from ee.api import max_toolsroot_router.register(r"billing", billing.BillingViewset, "billing")organizations_router.register(@@ -52,8 +52,6 @@ def extend_api_router() -> None:projects_router.register(r"max_tools", max_tools.MaxToolsViewSet, "project_max_tools", ["team_id"])- projects_router.register(r"max_hands_free", hands_free.MaxHandsFreeViewSet, "project_max_hands_free", ["team_id"])-# The admin interface is disabled on self-hosted instances, as its misuse can be unsafeif settings.ADMIN_PORTAL_ENABLED:diff --git a/frontend/package.json b/frontend/package.jsonindex 7dae8707f095..b1ec243e79c0 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -65,7 +65,6 @@"@dnd-kit/modifiers": "^6.0.1","@dnd-kit/sortable": "^7.0.2","@dnd-kit/utilities": "^3.2.1",- "@elevenlabs/client": "^1.4.0","@floating-ui/react": "^0.27.19","@marsidev/react-turnstile": "^1.4.2","@mathjax/src": "^4.1.2",diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex cb91fe0a6a5e..4f086d17fe39 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -13894,14 +13894,6 @@ snapshots:hash: v1.k794b7964.69a1e5eea52abebae062fbccdfcd613e24760bd0843e54c1576cecbee868cc5d.DWFG-7lnbtlTvNy2hvY4v-IliU1BjPk9VaDqkQt4Bh0scenes-app-posthog-ai-forms--thread-with-text-and-number-form--light:hash: v1.k794b7964.aee1550de1b97850cb1d8c27d39e40db81c28d4fe6116a13f48d45672c143710.M1lWbiiqC33CbFfL0ZdteiJH328flmdL2oPxzwPsJgw- scenes-app-posthog-ai-hands-free-surface--speaking--dark:- hash: v1.k794b7964.57e6cf1b2966bbbcac0c6dc1fc79dbcec30647b444819a36036bf414e5b2e620.VxF2LBHOgDjQ7K3quyqD7Lt7Jr7BaC9pAP7aaPI_cKQ- scenes-app-posthog-ai-hands-free-surface--speaking--light:- hash: v1.k794b7964.d8525499c1eb57dfa8f060a24aa1e27eab84613df452f32d35562496aefe72db.zCZOWI2nhLNhZRnJImG8ChEh-q4ImegCyxRl69VrFQs- scenes-app-posthog-ai-hands-free-surface--with-error--dark:- hash: v1.k794b7964.8845839d904fcee5d1cf4d98c2e1c16cde91b474a4d12033729ebd0cd8c6c206.Hall9WIzoGr43FyAUQ6iahlleJIiJ5UCYFgvouPy8Fc- scenes-app-posthog-ai-hands-free-surface--with-error--light:- hash: v1.k794b7964.988574fff8b8f14327e6234395a9200de50d0c357261037219bf56344b249369.6f9U2b-TYev-MwpxHqJjEnLrrvTDRB0fMavjcFcUn6sscenes-app-posthog-ai-tools--changelog-only--dark:hash: v1.k794b7964.f17aec31dd25e93672f7d76b065a6b49052c643eb6da67458011462b883f1c9c.sYkAo1RWtXpQRQNxl5SzUkO4ELuuEshq9Kdbc0H1L0Escenes-app-posthog-ai-tools--changelog-only--light:diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.tsindex 91d909686027..4945fbf67ad3 100644--- a/frontend/src/lib/api.ts+++ b/frontend/src/lib/api.ts@@ -1712,11 +1712,6 @@ export class ApiRequest {return this.teamProjectDetail(teamId).addPathComponent('conversations').addPathComponent(id)}- // Max hands-free mode (ElevenLabs Scribe token proxy)- public maxHandsFree(teamId?: TeamType['id']): ApiRequest {- return this.teamProjectDetail(teamId).addPathComponent('max_hands_free')- }-// Conversations (Support product)public conversationsTickets(teamId?: TeamType['id']): ApiRequest {return this.projectsDetail(teamId).addPathComponent('conversations').addPathComponent('tickets')@@ -6564,23 +6559,6 @@ const api = {},},- maxHandsFree: {- async token(options?: ApiMethodOptions): Promise<{ token: string }> {- return await api.create(- new ApiRequest().maxHandsFree().withAction('token').assembleFullUrl(),- undefined,- options- )- },- async synthesize(text: string, options?: ApiMethodOptions): Promise<Response> {- return await api.createResponse(- new ApiRequest().maxHandsFree().withAction('synthesize').assembleFullUrl(),- { text },- options- )- },- },-conversations: {async stream(data: {diff --git a/frontend/src/lib/components/Shortcuts/shortcuts.ts b/frontend/src/lib/components/Shortcuts/shortcuts.tsindex cc5d781cb2ec..a286b78fd211 100644--- a/frontend/src/lib/components/Shortcuts/shortcuts.ts+++ b/frontend/src/lib/components/Shortcuts/shortcuts.ts@@ -36,7 +36,6 @@ export const keyBinds: Record<string, string[]> = {tab9: [...baseModifier, '9'],zenMode: [...baseModifier, 'z'],newChat: ['g', 'then', 'n'],- maxHandsFree: ['h', 'then', 'f'],allChats: ['g', 'then', '1'],allProducts: ['g', 'then', '2'],theme: ['g', 'then', 't'],diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex c03a11759d4e..3f8076f4c945 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -444,7 +444,7 @@ export const FEATURE_FLAGS = {MAX_AI_INSIGHT_SEARCH: 'max-ai-insight-search', // owner: #team-posthog-aiMAX_BILLING_CONTEXT: 'max-billing-context', // owner: @pawel-cebula #team-billingMAX_DEEP_RESEARCH: 'max-deep-research', // owner: @kappa90 #team-posthog-ai- MAX_HANDS_FREE: 'max-hands-free', // owner: #team-posthog-ai+ MAX_WEB_ANALYTICS_NUDGE: 'posthog-ai-web-analytics-nudge', // owner: @jordanm-posthog #team-web-analyticsMCP_ANALYTICS_INTENT_ROUTING: 'mcp-analytics-intent-routing', // owner: #project-mcp-analyticsMCP_ANALYTICS_LEADERBOARD_HOME: 'mcp-analytics-leaderboard-home', // owner: #team-mcp-analytics, trial of the public leaderboard layout on the MCP analytics home tabMCP_GATEWAY: 'mcp-gateway', // owner: #team-context-mcp — gates the MCP gateway UI AND backend enforcement of built-in agent MCP access (delegated-only installs + restricted sandbox token scope); roll out by organizationdiff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex 96eee38e36c8..192cc8f15a6f 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -38828,9 +38828,6 @@"$ref": "#/definitions/MaxNotebookContext"},"type": "array"- },- "voice_mode": {- "type": "boolean"}},"type": "object"diff --git a/frontend/src/scenes/max/components/HandsFreeButton.tsx b/frontend/src/scenes/max/components/HandsFreeButton.tsxdeleted file mode 100644index 822f7985a519..000000000000--- a/frontend/src/scenes/max/components/HandsFreeButton.tsx+++ /dev/null@@ -1,38 +0,0 @@-import { useActions, useValues } from 'kea'--import { IconMicrophone } from '@posthog/icons'-import { LemonButton } from '@posthog/lemon-ui'--import { Shortcut } from 'lib/components/Shortcuts/Shortcut'-import { keyBinds } from 'lib/components/Shortcuts/shortcuts'-import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'--import { handsFreeLogic } from '../handsFreeLogic'--interface HandsFreeButtonProps {- panelId?: string-}--export function HandsFreeButton({ panelId }: HandsFreeButtonProps): JSX.Element | null {- const flagEnabled = useFeatureFlag('MAX_HANDS_FREE')- const { status, canUseHandsFree } = useValues(handsFreeLogic({ panelId }))- const { toggleHandsFree } = useActions(handsFreeLogic({ panelId }))-- if (!flagEnabled || !canUseHandsFree || status !== 'off') {- return null- }-- return (- <Shortcut name="maxHandsFree" keybind={[keyBinds.maxHandsFree]} intent="Enter hands-free" interaction="click">- <LemonButton- data-attr="max-hands-free-toggle"- size="small"- type="tertiary"- icon={<IconMicrophone />}- onClick={toggleHandsFree}- tooltip="Enter hands-free"- aria-label="Enter hands-free"- />- </Shortcut>- )-}diff --git a/frontend/src/scenes/max/components/HandsFreeSurface.scss b/frontend/src/scenes/max/components/HandsFreeSurface.scssdeleted file mode 100644index 6c6dfb02d618..000000000000--- a/frontend/src/scenes/max/components/HandsFreeSurface.scss+++ /dev/null@@ -1,185 +0,0 @@-.hands-free-surface {- display: grid;- grid-template-rows: minmax(2.5rem, auto) auto minmax(1.5rem, auto);- gap: 1rem;- place-items: center center;- width: 100%;- min-height: 11rem;- padding: 1.25rem 1rem;- text-align: center;-}--.hands-free-surface__top {- display: flex;- flex-direction: column;- gap: 0.25rem;- align-items: center;- justify-content: center;- width: 100%;- min-height: 2.5rem;-}--.hands-free-surface__partial {- max-width: 32rem;- margin: 0;- font-size: 1rem;- line-height: 1.4;- color: var(--color-text-primary);- word-wrap: break-word;-}--.hands-free-surface__hint {- max-width: 32rem;- margin: 0;- font-size: 0.8125rem;- font-style: italic;- color: var(--color-text-secondary);-}--.hands-free-surface__error {- margin: 0;- font-size: 0.8125rem;- color: var(--color-danger);-}--.hands-free-surface__mic {- position: relative;- display: inline-flex;- align-items: center;- justify-content: center;- width: 3rem;- height: 3rem;- color: var(--color-text-primary);- appearance: none;- cursor: pointer;- background: var(--color-bg-fill-secondary);- border: none;- border-radius: 50%;- box-shadow: 0 1px 2px rgb(0 0 0 / 20%);- transition:- transform 120ms ease,- background 120ms ease;-- svg {- width: 1.25rem;- height: 1.25rem;- }-- &:hover {- transform: scale(1.04);- }-- &:active {- transform: scale(0.97);- }-}--.hands-free-surface__mic--listening {- color: var(--color-text-on-fill);- background: var(--color-success);-}--.hands-free-surface__mic--speaking {- color: var(--color-text-on-fill);- background: var(--color-ai);-}--.hands-free-surface__mic--thinking,-.hands-free-surface__mic--starting,-.hands-free-surface__mic--reconnecting {- color: var(--color-text-on-fill);- background: var(--color-warning);-}--.hands-free-surface__mic--error {- color: var(--color-text-on-fill);- background: var(--color-danger);-}--// Larger tap target on phones — the primary affordance of a hands-free product,-// and gym/walking users need more than the 48px desktop default.-@media (max-width: 480px) {- .hands-free-surface__mic {- width: 4rem;- height: 4rem;-- svg {- width: 1.75rem;- height: 1.75rem;- }- }-}--// Pulse applied only when status === 'listening' (your turn to talk).-.hands-free-surface__mic--pulsing {- animation: HandsFreeSurface__micPulse 1.6s ease-in-out infinite;-}--// Spinner ring around the mic when thinking/starting/reconnecting — keeps the mic icon-// visible so the user still knows the button is tappable to exit.-.hands-free-surface__mic--thinking::after,-.hands-free-surface__mic--starting::after,-.hands-free-surface__mic--reconnecting::after {- position: absolute;- inset: -4px;- content: '';- border: 2px solid transparent;- border-top-color: currentColor;- border-radius: 50%;- animation: HandsFreeSurface__micSpin 1s linear infinite;-}--@keyframes HandsFreeSurface__micSpin {- to {- transform: rotate(360deg);- }-}--@keyframes HandsFreeSurface__micPulse {- 0%,- 100% {- box-shadow: 0 0 0 0 rgb(0 0 0 / 0%);- }-- 50% {- box-shadow: 0 0 0 0.75rem rgb(255 255 255 / 8%);- }-}--.hands-free-surface__bottom {- display: inline-flex;- gap: 0.5rem;- align-items: center;-}--.hands-free-surface__emoji {- display: inline-flex;- flex-shrink: 0;- align-items: center;- justify-content: center;- font-size: 1.125rem;- line-height: 1;-}--.hands-free-surface__emoji--pulsing {- animation: HandsFreeSurface__pulse 1.4s ease-in-out infinite;-}--@keyframes HandsFreeSurface__pulse {- 0%,- 100% {- opacity: 1;- transform: scale(1);- }-- 50% {- opacity: 0.7;- transform: scale(1.1);- }-}--.hands-free-surface__label {- font-size: 0.875rem;- font-weight: 600;- color: var(--color-text-primary);-}diff --git a/frontend/src/scenes/max/components/HandsFreeSurface.stories.tsx b/frontend/src/scenes/max/components/HandsFreeSurface.stories.tsxdeleted file mode 100644index 045caacf81bd..000000000000--- a/frontend/src/scenes/max/components/HandsFreeSurface.stories.tsx+++ /dev/null@@ -1,101 +0,0 @@-import { Meta, StoryObj } from '@storybook/react'-import { useActions, useMountedLogic } from 'kea'-import { useEffect } from 'react'--import { HandsFreeConnection, HandsFreeStatus, handsFreeLogic } from '../handsFreeLogic'-import { maxLogic } from '../maxLogic'-import { HandsFreeSurface } from './HandsFreeSurface'--const TAB_ID = 'hands-free-storybook'--interface DriverProps {- status: HandsFreeStatus- connection?: HandsFreeConnection- partialTranscript?: string- error?: string | null-}--// Mounts maxLogic + handsFreeLogic and drives them into a target state so each story-// captures a single visual configuration without spinning up real WebSockets or audio.-function HandsFreeSurfaceStory({ status, connection, partialTranscript, error }: DriverProps): JSX.Element {- useMountedLogic(maxLogic({ panelId: TAB_ID }))- const logic = handsFreeLogic({ panelId: TAB_ID })- useMountedLogic(logic)- const { setStatus, setConnection, setPartialTranscript, setError } = useActions(logic)-- useEffect(() => {- setStatus(status)- if (connection) {- setConnection(connection)- }- if (partialTranscript) {- setPartialTranscript(partialTranscript)- }- if (error) {- setError(error)- }- }, [status, connection, partialTranscript, error, setStatus, setConnection, setPartialTranscript, setError])-- return (- <div className="max-w-md mx-auto p-4 bg-bg-light border rounded">- <HandsFreeSurface panelId={TAB_ID} />- </div>- )-}--const meta: Meta<typeof HandsFreeSurfaceStory> = {- title: 'Scenes-App/PostHog AI/Hands-free surface',- component: HandsFreeSurfaceStory,- parameters: {- layout: 'centered',- },-}-export default meta--type Story = StoryObj<typeof HandsFreeSurfaceStory>--// Stories whose mic ring/pulse animates are excluded from visual regression — the-// running CSS animation makes the snapshot diff flake. Static visual states (speaking,-// error) keep their snapshot so we still catch unintended colour/layout drift.-const ANIMATED_SKIP_TAGS = ['test-skip']--export const Starting: Story = {- args: { status: 'starting', connection: 'connecting' },- tags: ANIMATED_SKIP_TAGS,-}--export const Listening: Story = {- args: { status: 'listening', connection: 'connected' },- tags: ANIMATED_SKIP_TAGS,-}--export const ListeningWithPartialTranscript: Story = {- args: {- status: 'listening',- connection: 'connected',- partialTranscript: 'how are the daily active users tracking against',- },- tags: ANIMATED_SKIP_TAGS,-}--export const Thinking: Story = {- args: { status: 'thinking', connection: 'connected' },- tags: ANIMATED_SKIP_TAGS,-}--export const Speaking: Story = {- args: { status: 'speaking', connection: 'connected' },-}--export const Reconnecting: Story = {- args: { status: 'listening', connection: 'reconnecting' },- tags: ANIMATED_SKIP_TAGS,-}--export const WithError: Story = {- args: {- status: 'listening',- connection: 'connected',- error: 'Microphone access was denied.',- },-}diff --git a/frontend/src/scenes/max/components/HandsFreeSurface.tsx b/frontend/src/scenes/max/components/HandsFreeSurface.tsxdeleted file mode 100644index be27f43008ab..000000000000--- a/frontend/src/scenes/max/components/HandsFreeSurface.tsx+++ /dev/null@@ -1,137 +0,0 @@-import './HandsFreeSurface.scss'--import { useActions, useValues } from 'kea'--import { IconMicrophone } from '@posthog/icons'--import { keyBinds } from 'lib/components/Shortcuts/shortcuts'-import { useShortcut } from 'lib/components/Shortcuts/useShortcut'-import { cn } from 'lib/utils/css-classes'--import { HandsFreeStatus, handsFreeLogic } from '../handsFreeLogic'--interface HandsFreeSurfaceProps {- panelId?: string-}--const STATUS_LABEL: Record<HandsFreeStatus, string> = {- off: '',- starting: 'Connecting',- listening: 'Listening',- thinking: 'Thinking',- speaking: 'Speaking',-}--// Emoji per visual state. Reconnecting + error deliberately render no emoji so-// the label sits alone and stays perfectly centered under the mic.-const STATUS_EMOJI: Record<HandsFreeStatus | 'reconnecting' | 'error', string> = {- off: '',- starting: '🎤',- listening: '🎤',- thinking: '🧠',- speaking: '🔊',- reconnecting: '',- error: '',-}--const STATUS_HINT: Record<HandsFreeStatus, string> = {- off: '',- starting: 'One moment, getting microphone ready',- listening: 'I will send your question when you pause speaking',- thinking: 'Working on your answer',- speaking: 'Start talking to interrupt',-}--function HandsFreeTopline({- panelId,- status,- isReconnecting,-}: {- panelId?: string- status: HandsFreeStatus- isReconnecting: boolean-}): JSX.Element {- const { partialTranscript, error } = useValues(handsFreeLogic({ panelId }))- const hint = isReconnecting ? 'Reconnecting your microphone' : STATUS_HINT[status]- return (- <div className="hands-free-surface__top">- {partialTranscript ? (- <p className="hands-free-surface__partial">{partialTranscript}</p>- ) : (- <p className="hands-free-surface__hint">{hint}</p>- )}- {error && <p className="hands-free-surface__error">{error}</p>}- </div>- )-}--export function HandsFreeSurface({ panelId }: HandsFreeSurfaceProps): JSX.Element | null {- const { status, connection, error } = useValues(handsFreeLogic({ panelId }))- const { toggleHandsFree } = useActions(handsFreeLogic({ panelId }))-- // Register the v-then-m exit shortcut while the surface is mounted.- // HandsFreeButton owns the same shortcut for the "enter" path; same-name- // re-registration in shortcutLogic handles the handover cleanly.- useShortcut({- name: 'maxHandsFree',- keybind: [keyBinds.maxHandsFree],- intent: 'Exit hands-free',- interaction: 'function',- callback: toggleHandsFree,- })-- if (status === 'off') {- return null- }-- const isListening = status === 'listening'- const isReconnecting = connection === 'reconnecting'- const hasError = !!error-- // Reconnecting / error visuals take precedence over the listening pulse so the user- // isn't shown a green "listening" mic when the underlying connection is dead.- const visualState: HandsFreeStatus | 'reconnecting' | 'error' = hasError- ? 'error'- : isReconnecting- ? 'reconnecting'- : status- const label = hasError ? 'Error' : isReconnecting ? 'Reconnecting' : STATUS_LABEL[status]- const shouldPulse = isListening && !isReconnecting && !hasError-- return (- <div- className="hands-free-surface"- data-attr="max-hands-free-surface"- data-status={status}- data-connection={connection}- >- <HandsFreeTopline panelId={panelId} status={status} isReconnecting={isReconnecting} />-- <button- type="button"- onClick={toggleHandsFree}- aria-label="Exit hands-free"- data-attr="max-hands-free-exit"- className={cn('hands-free-surface__mic', `hands-free-surface__mic--${visualState}`, {- 'hands-free-surface__mic--pulsing': shouldPulse,- })}- >- <IconMicrophone />- </button>-- <div className="hands-free-surface__bottom">- {STATUS_EMOJI[visualState] && (- <span- className={cn('hands-free-surface__emoji', {- 'hands-free-surface__emoji--pulsing': shouldPulse,- })}- aria-hidden- >- {STATUS_EMOJI[visualState]}- </span>- )}- <span className="hands-free-surface__label">{label}</span>- </div>- </div>- )-}diff --git a/frontend/src/scenes/max/components/QuestionInput.tsx b/frontend/src/scenes/max/components/QuestionInput.tsxindex 5a43149829a5..86cdfe45f849 100644--- a/frontend/src/scenes/max/components/QuestionInput.tsx+++ b/frontend/src/scenes/max/components/QuestionInput.tsx@@ -10,7 +10,6 @@ import { IconArrowRight, IconCheck, IconPencil, IconStopFilled, IconTrash, IconUimport { LemonButton, LemonSwitch, LemonTextArea, Spinner } from '@posthog/lemon-ui'import { KeyboardShortcut } from 'lib/components/KeyboardShortcut/KeyboardShortcut'-import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'import { cn } from 'lib/utils/css-classes'import { AIConsentPopoverWrapper } from 'scenes/settings/organization/AIConsentPopoverWrapper'import { userLogic } from 'scenes/userLogic'@@ -19,15 +18,12 @@ import { AgentMode } from '~/queries/schema/schema-assistant-messages'import { ConversationQueueMessage } from '~/types'import { ContextDisplay } from '../Context'-import { handsFreeLogic } from '../handsFreeLogic'import { MAX_MESSAGE_LENGTH, MESSAGE_TOO_LONG, messageLength } from '../max-constants'import { maxGlobalLogic } from '../maxGlobalLogic'import { maxLogic } from '../maxLogic'import { maxThreadLogic } from '../maxThreadLogic'import { MAX_SLASH_COMMANDS } from '../slash-commands'import { FillInHint } from './FillInHint'-import { HandsFreeButton } from './HandsFreeButton'-import { HandsFreeSurface } from './HandsFreeSurface'import { SlashCommandAutocomplete } from './SlashCommandAutocomplete'/**@@ -153,7 +149,7 @@ export const QuestionInput = React.forwardRef<HTMLDivElement, QuestionInputPropsref) {const { dataProcessingAccepted, isPhaiSandboxFlagOn } = useValues(maxGlobalLogic)- const { question, panelId: maxPanelId, fillInHint, typingSuggestion } = useValues(maxLogic)+ const { question, fillInHint, typingSuggestion } = useValues(maxLogic)const { setQuestion, setFillInHint, cancelSuggestionTyping, attachFilesToNewChat } = useActions(maxLogic)const { user } = useValues(userLogic)const {@@ -182,12 +178,6 @@ export const QuestionInput = React.forwardRef<HTMLDivElement, QuestionInputPropsupdateQueuedMessage,releaseSandboxPrewarm,} = useActions(maxThreadLogic)- const { isActive: handsFreeActive } = useValues(handsFreeLogic({ panelId: maxPanelId }))- // Only the hands-free row needs bottom-aligned pills — it has the mic + submit pair- // pinned to the bottom and pills sitting in normal flow look misaligned next to them.- // Keep the legacy items-start layout when the flag is off so existing screenshots- // (and the layout users without hands-free see) don't change.- const handsFreeFlagEnabled = useFeatureFlag('MAX_HANDS_FREE')// Show info banner for conversations created during impersonation (marked as internal)const isImpersonatedInternalConversation = user?.is_impersonated && conversation?.is_internal@@ -368,272 +358,245 @@ export const QuestionInput = React.forwardRef<HTMLDivElement, QuestionInputProps!streamingActive && '[--input-ring-color:var(--color-ai)]')}>- {handsFreeActive ? (- <HandsFreeSurface panelId={maxPanelId} />- ) : (- <SlashCommandAutocomplete- visible={showAutocomplete}- onClose={() => {- setShowAutocomplete(false)- setAutocompleteDismissed(true)- }}- >- <div className="relative w-full">- {!inputValue && (- <div- id="textarea-hint"- className="text-secondary absolute top-4 left-4 text-sm pointer-events-none"- >- {conversation && isSharedThread ? (- `This thread was shared with you by ${conversation.user.first_name} ${conversation.user.last_name}`- ) : threadLoading ? (- 'Thinking…'- ) : isThreadVisible ? (- placeholder || (- <>- Ask follow-up{' '}- <span className="text-tertiary opacity-80 contrast-more:opacity-100">- or / for commands- </span>- </>- )- ) : (+ <SlashCommandAutocomplete+ visible={showAutocomplete}+ onClose={() => {+ setShowAutocomplete(false)+ setAutocompleteDismissed(true)+ }}+ >+ <div className="relative w-full">+ {!inputValue && (+ <div+ id="textarea-hint"+ className="text-secondary absolute top-4 left-4 text-sm pointer-events-none"+ >+ {conversation && isSharedThread ? (+ `This thread was shared with you by ${conversation.user.first_name} ${conversation.user.last_name}`+ ) : threadLoading ? (+ 'Thinking…'+ ) : isThreadVisible ? (+ placeholder || (<>- Ask a question{' '}+ Ask follow-up{' '}<span className="text-tertiary opacity-80 contrast-more:opacity-100">or / for commands</span></>- )}- </div>- )}- {/* Postfix cue after a fill-in suggestion's typed-in prefix. */}- {showFillInHint && (- <div className="absolute top-4 left-4 right-4 overflow-hidden pointer-events-none">- <FillInHint text={inputValue} hint={fillInHint} />- </div>- )}- <LemonTextArea- aria-describedby={!inputValue ? 'textarea-hint' : undefined}- id="question-input"- data-attr="max-chat-input"- ref={textAreaRef}- value={isSharedThread ? '' : inputValue}- onChange={handleQuestionChange}- onBlur={(e) => {- debouncedSetQuestion.flush()- // Release any sandbox pre-warm when the user leaves the- // input without sending. No-op on LangGraph / unwarmed- // conversations.- //- // But clicking the send button blurs the textarea *before*- // its onClick fires the send — releasing here would cancel- // the very warm Run the send is about to consume. When focus- // moves to the send button, skip the release and let the send- // path consume the warm (it does so without a DELETE).- const next = e.relatedTarget as HTMLElement | null- if (next?.closest('[data-attr="max-send-message"]')) {+ )+ ) : (+ <>+ Ask a question{' '}+ <span className="text-tertiary opacity-80 contrast-more:opacity-100">+ or / for commands+ </span>+ </>+ )}+ </div>+ )}+ {/* Postfix cue after a fill-in suggestion's typed-in prefix. */}+ {showFillInHint && (+ <div className="absolute top-4 left-4 right-4 overflow-hidden pointer-events-none">+ <FillInHint text={inputValue} hint={fillInHint} />+ </div>+ )}+ <LemonTextArea+ aria-describedby={!inputValue ? 'textarea-hint' : undefined}+ id="question-input"+ data-attr="max-chat-input"+ ref={textAreaRef}+ value={isSharedThread ? '' : inputValue}+ onChange={handleQuestionChange}+ onBlur={(e) => {+ debouncedSetQuestion.flush()+ // Release any sandbox pre-warm when the user leaves the+ // input without sending. No-op on LangGraph / unwarmed+ // conversations.+ //+ // But clicking the send button blurs the textarea *before*+ // its onClick fires the send — releasing here would cancel+ // the very warm Run the send is about to consume. When focus+ // moves to the send button, skip the release and let the send+ // path consume the warm (it does so without a DELETE).+ const next = e.relatedTarget as HTMLElement | null+ if (next?.closest('[data-attr="max-send-message"]')) {+ return+ }+ releaseSandboxPrewarm()+ }}+ onPressEnter={() => {+ if (+ hasQuestion &&+ !submissionDisabledReason &&+ (!threadLoading || queueingEnabled)+ ) {+ onSubmit?.()+ submit(inputValue)+ }+ }}+ onKeyDown={(event) => {+ if (+ event.key === 'ArrowUp' &&+ !inputValue.trim() &&+ queuedMessages.length > 0 &&+ !editingQueueId+ ) {+ const target = event.currentTarget+ const atStart = target.selectionStart === 0 && target.selectionEnd === 0+ const isSingleLine = target.value.split('\n').length <= 1+ if (!atStart || !isSingleLine) {return}- releaseSandboxPrewarm()- }}- onPressEnter={() => {- if (- hasQuestion &&- !submissionDisabledReason &&- (!threadLoading || queueingEnabled)- ) {- onSubmit?.()- submit(inputValue)- }- }}- onKeyDown={(event) => {- if (- event.key === 'ArrowUp' &&- !inputValue.trim() &&- queuedMessages.length > 0 &&- !editingQueueId- ) {- const target = event.currentTarget- const atStart = target.selectionStart === 0 && target.selectionEnd === 0- const isSingleLine = target.value.split('\n').length <= 1- if (!atStart || !isSingleLine) {- return- }- const nextMessageId = queuedMessages[0]?.id- if (!nextMessageId) {- return- }- event.preventDefault()- setEditingQueueId(nextMessageId)+ const nextMessageId = queuedMessages[0]?.id+ if (!nextMessageId) {+ return}- }}- disabled={inputDisabled}- minRows={1}- maxRows={10}- className={cn(- '!border-none !bg-transparent min-h-16 py-2 pl-2 resize-none',- handsFreeFlagEnabled ? 'pr-20' : 'pr-12',- // Hide the native caret so only the enlarged fill-in caret shows.- showFillInHint && 'caret-transparent'- )}- hideFocus- />- </div>- </SlashCommandAutocomplete>- )}-- {!isSharedThread &&- !handsFreeActive && (- // When the hands-free flag is on, reserve ~80px (pr-20) so the chip- // row doesn't wrap under the absolutely-positioned mic + send pair.- // Without the flag the row only has send and the legacy pr-12 is- // enough — keep it so non-flagged users see the original layout.- <div className={cn('pb-2', handsFreeFlagEnabled ? 'pr-20' : 'pr-12')}>- {!isThreadVisible ? (- <div- className={cn(- 'flex justify-between',- handsFreeFlagEnabled ? 'items-end flex-wrap gap-1' : 'items-start'- )}- >- <div className="flex items-start gap-1 flex-1 min-w-0">- <div className="flex-1 min-w-0">- <ContextDisplay size={contextDisplaySize} />- </div>- {isPhaiSandboxFlagOn && !conversation && (- <div className="shrink-0">- <input- ref={attachmentInputRef}- type="file"- multiple- className="hidden"- data-attr="max-new-chat-attach-input"- onChange={(event) => {- const files = Array.from(event.target.files ?? [])- event.target.value = ''- attachFilesToNewChat(files, inputValue)- }}- />- <LemonButton- size="xxsmall"- type="tertiary"- className="border"- icon={<IconUpload />}- tooltip="Attach files in new PostHog AI. Your draft moves with you."- onClick={() => attachmentInputRef.current?.click()}- data-attr="max-new-chat-attach-file"- >- Attach- </LemonButton>- </div>- )}- </div>+ event.preventDefault()+ setEditingQueueId(nextMessageId)+ }+ }}+ disabled={inputDisabled}+ minRows={1}+ maxRows={10}+ className={cn(+ '!border-none !bg-transparent min-h-16 py-2 pl-2 resize-none',+ 'pr-12',+ // Hide the native caret so only the enlarged fill-in caret shows.+ showFillInHint && 'caret-transparent'+ )}+ hideFocus+ />+ </div>+ </SlashCommandAutocomplete>- <div- className={cn(- 'flex mr-1',- handsFreeFlagEnabled- ? 'items-end gap-1'- : 'items-start gap-1 h-full mt-1'- )}- >- {topActions}+ {!isSharedThread && (+ <div className="pb-2 pr-12">+ {!isThreadVisible ? (+ <div className="flex justify-between items-start">+ <div className="flex items-start gap-1 flex-1 min-w-0">+ <div className="flex-1 min-w-0">+ <ContextDisplay size={contextDisplaySize} /></div>- </div>- ) : (- <ContextDisplay size={contextDisplaySize} />- )}- {promptLength !== null && (- <div- className={cn(- 'text-xs text-right pr-1 pt-1',- isOverLengthLimit ? 'text-error' : 'text-secondary'+ {isPhaiSandboxFlagOn && !conversation && (+ <div className="shrink-0">+ <input+ ref={attachmentInputRef}+ type="file"+ multiple+ className="hidden"+ data-attr="max-new-chat-attach-input"+ onChange={(event) => {+ const files = Array.from(event.target.files ?? [])+ event.target.value = ''+ attachFilesToNewChat(files, inputValue)+ }}+ />+ <LemonButton+ size="xxsmall"+ type="tertiary"+ className="border"+ icon={<IconUpload />}+ tooltip="Attach files in new PostHog AI. Your draft moves with you."+ onClick={() => attachmentInputRef.current?.click()}+ data-attr="max-new-chat-attach-file"+ >+ Attach+ </LemonButton>+ </div>)}- >- {promptLength.toLocaleString()} / {MAX_MESSAGE_LENGTH.toLocaleString()}</div>- )}- </div>- )}++ <div className="flex mr-1 items-start gap-1 h-full mt-1">{topActions}</div>+ </div>+ ) : (+ <ContextDisplay size={contextDisplaySize} />+ )}+ {promptLength !== null && (+ <div+ className={cn(+ 'text-xs text-right pr-1 pt-1',+ isOverLengthLimit ? 'text-error' : 'text-secondary'+ )}+ >+ {promptLength.toLocaleString()} / {MAX_MESSAGE_LENGTH.toLocaleString()}+ </div>+ )}+ </div>+ )}</label><divclassName={cn('absolute flex items-center',- handsFreeFlagEnabled && 'gap-1',isSharedThread && 'hidden',isThreadVisible ? 'bottom-[9px] right-[9px]' : 'bottom-[7px] right-[7px]')}>- <HandsFreeButton panelId={maxPanelId} />- {!handsFreeActive && (- <AIConsentPopoverWrapper- placement="bottom-end"- showArrow- ignoreDismissal- onApprove={() => submit(pendingPrompt || inputValue)}- onDismiss={() => completeThreadGeneration()}- middleware={[- offset((state) => ({- mainAxis: state.placement.includes('top') ? 30 : 1,- })),- ]}- hidden={!threadLoading && !pendingPrompt}- >- <LemonButton- data-attr={showStopButton ? 'max-stop-generation' : 'max-send-message'}- type={(isThreadVisible && !hasQuestion) || showStopButton ? 'secondary' : 'primary'}- onClick={() => {- if (threadLoading) {- if (isQueueingSubmission) {- if (submissionDisabledReason) {- textAreaRef?.current?.focus()- return- }- submit(inputValue)+ <AIConsentPopoverWrapper+ placement="bottom-end"+ showArrow+ ignoreDismissal+ onApprove={() => submit(pendingPrompt || inputValue)}+ onDismiss={() => completeThreadGeneration()}+ middleware={[+ offset((state) => ({+ mainAxis: state.placement.includes('top') ? 30 : 1,+ })),+ ]}+ hidden={!threadLoading && !pendingPrompt}+ >+ <LemonButton+ data-attr={showStopButton ? 'max-stop-generation' : 'max-send-message'}+ type={(isThreadVisible && !hasQuestion) || showStopButton ? 'secondary' : 'primary'}+ onClick={() => {+ if (threadLoading) {+ if (isQueueingSubmission) {+ if (submissionDisabledReason) {+ textAreaRef?.current?.focus()return}- stopGeneration()- return- }- if (submissionDisabledReason) {- textAreaRef?.current?.focus()+ submit(inputValue)return}- submit(inputValue)- }}- tooltip={- // If there's a disabled reason tooltip shown below, don't show a tooltip here- // Else, show the tooltip based on the button state- disabledReason ? undefined : showStopButton ? (- <>- Let's bail <KeyboardShortcut enter />- </>- ) : isQueueingSubmission ? (- <>- Queue message <KeyboardShortcut enter />- </>- ) : (- <>- Let's go! <KeyboardShortcut enter />- </>- )+ stopGeneration()+ return}- loading={threadLoading && !dataProcessingAccepted}- disabledReason={disabledReason}- className={disabledReason ? 'opacity-[0.5]' : ''}- size="small"- icon={- showStopButton ? (- <IconStopFilled />- ) : (- MAX_SLASH_COMMANDS.find((cmd) => cmd.name === inputValue.split(' ', 1)[0])- ?.icon || <IconArrowRight />- )+ if (submissionDisabledReason) {+ textAreaRef?.current?.focus()+ return}- />- </AIConsentPopoverWrapper>- )}+ submit(inputValue)+ }}+ tooltip={+ // If there's a disabled reason tooltip shown below, don't show a tooltip here+ // Else, show the tooltip based on the button state+ disabledReason ? undefined : showStopButton ? (+ <>+ Let's bail <KeyboardShortcut enter />+ </>+ ) : isQueueingSubmission ? (+ <>+ Queue message <KeyboardShortcut enter />+ </>+ ) : (+ <>+ Let's go! <KeyboardShortcut enter />+ </>+ )+ }+ loading={threadLoading && !dataProcessingAccepted}+ disabledReason={disabledReason}+ className={disabledReason ? 'opacity-[0.5]' : ''}+ size="small"+ icon={+ showStopButton ? (+ <IconStopFilled />+ ) : (+ MAX_SLASH_COMMANDS.find((cmd) => cmd.name === inputValue.split(' ', 1)[0])+ ?.icon || <IconArrowRight />+ )+ }+ />+ </AIConsentPopoverWrapper></div></div>{/* Info banner for conversations created during impersonation (marked as internal) */}diff --git a/frontend/src/scenes/max/handsFreeLogic.test.ts b/frontend/src/scenes/max/handsFreeLogic.test.tsdeleted file mode 100644index ea4da5b20098..000000000000--- a/frontend/src/scenes/max/handsFreeLogic.test.ts+++ /dev/null@@ -1,110 +0,0 @@-import { expectLogic } from 'kea-test-utils'--import { useMocks } from '~/mocks/jest'-import { initKeaTests } from '~/test/init'--import { classifyPartial, handsFreeLogic, type SuppressionReason } from './handsFreeLogic'-import { maxLogic } from './maxLogic'-import { maxMocks } from './testUtils'--describe('handsFreeLogic state machine', () => {- let logic: ReturnType<typeof handsFreeLogic.build>- let parent: ReturnType<typeof maxLogic.build>-- beforeEach(() => {- useMocks(maxMocks)- initKeaTests()- parent = maxLogic({ panelId: 'hands-free-test-tab' })- parent.mount()- logic = handsFreeLogic({ panelId: 'hands-free-test-tab' })- logic.mount()- })-- afterEach(() => {- logic.unmount()- parent.unmount()- })-- it('starts off with idle connection and exposes isActive=false', async () => {- await expectLogic(logic).toMatchValues({ status: 'off', connection: 'idle', isActive: false })- })-- it('exitHandsFree from off keeps status off (defensive)', async () => {- await expectLogic(logic, () => {- logic.actions.exitHandsFree('test')- }).toMatchValues({ status: 'off', connection: 'idle' })- })-- it('setStatus("listening") then exitHandsFree resets back to off + connection idle', async () => {- await expectLogic(logic, () => {- logic.actions.setStatus('listening')- logic.actions.setConnection('connected')- }).toMatchValues({ status: 'listening', connection: 'connected', isActive: true })-- await expectLogic(logic, () => {- logic.actions.exitHandsFree('test')- }).toMatchValues({ status: 'off', connection: 'idle', isActive: false })- })-- it('setError stores the error string; entering hands-free clears it', async () => {- await expectLogic(logic, () => {- logic.actions.setError('something broke')- }).toMatchValues({ error: 'something broke' })-- await expectLogic(logic, () => {- logic.actions.setError(null)- }).toMatchValues({ error: null })- })-- it('setPartialTranscript stores the in-flight transcript; commitTranscript clears it', async () => {- await expectLogic(logic, () => {- logic.actions.setPartialTranscript('how is the prod')- }).toMatchValues({ partialTranscript: 'how is the prod' })-- // commit triggers askMax via the listener; thread isn't mounted here so it'll error out,- // but the reducer for partialTranscript clears regardless- await expectLogic(logic, () => {- logic.actions.commitTranscript('how is the product doing today')- }).toMatchValues({ partialTranscript: '' })- })-- it('exitHandsFree clears any in-flight partial transcript', async () => {- await expectLogic(logic, () => {- logic.actions.setPartialTranscript('mid sentence')- }).toMatchValues({ partialTranscript: 'mid sentence' })-- await expectLogic(logic, () => {- logic.actions.exitHandsFree('test')- }).toMatchValues({ partialTranscript: '' })- })-- it('speakAssistantResponse with empty summary while off is a no-op', async () => {- await expectLogic(logic, () => {- logic.actions.speakAssistantResponse({ text: '', vizCount: 0 })- }).toMatchValues({ status: 'off' })- })-})--describe('classifyPartial barge-in heuristic', () => {- const spoken = 'lets look at the daily active users for the last week'- const cases: { name: string; spoken: string; partial: string; expected: SuppressionReason }[] = [- { name: 'empty partial -> too_short', spoken, partial: '', expected: 'too_short' },- { name: '1-char partial -> too_short', spoken, partial: 'a', expected: 'too_short' },- { name: '3-char unrelated -> too_short', spoken, partial: 'xyz', expected: 'too_short' },- { name: 'allowlist "stop" bypasses too_short', spoken, partial: 'stop', expected: null },- { name: 'allowlist "no" bypasses too_short', spoken, partial: 'no', expected: null },- { name: 'allowlist "wait" bypasses too_short', spoken, partial: 'wait', expected: null },- { name: 'allowlist "max" bypasses too_short', spoken, partial: 'max', expected: null },- { name: 'substring of spoken text -> substring', spoken, partial: 'daily active', expected: 'substring' },- { name: 'unrelated longer phrase -> not suppressed', spoken, partial: 'change the chart type', expected: null },- {- name: 'partial matches mid-word run in spoken -> substring',- spoken,- partial: 'active users',- expected: 'substring',- },- ]- it.each(cases)('$name', ({ spoken, partial, expected }) => {- expect(classifyPartial(spoken, partial)).toBe(expected)- })-})diff --git a/frontend/src/scenes/max/handsFreeLogic.ts b/frontend/src/scenes/max/handsFreeLogic.tsdeleted file mode 100644index 56eb0af9f5ef..000000000000--- a/frontend/src/scenes/max/handsFreeLogic.ts+++ /dev/null@@ -1,662 +0,0 @@-// Hands-free conversational mode for Max — STT via ElevenLabs Scribe (browser → WS direct),-// TTS via the browser's native speechSynthesis. Built for mobile-web use (gym, walking).-import { MakeLogicType, actions, afterMount, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea'-import posthog from 'posthog-js'--import api from 'lib/api'-import { FEATURE_FLAGS } from 'lib/constants'-import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'--import { AssistantSummary, buildSpokenText } from './handsFreeUtils'-import { maxLogic } from './maxLogic'-import { maxThreadLogic } from './maxThreadLogic'--export type HandsFreeStatus = 'off' | 'starting' | 'listening' | 'thinking' | 'speaking'-export type HandsFreeConnection = 'idle' | 'connecting' | 'connected' | 'reconnecting' | 'closed'--const SCRIBE_REALTIME_MODEL_ID = 'scribe_v2_realtime'--export interface HandsFreeLogicProps {- panelId?: string // identifies the MaxLogic instance backing this panel (scene tab id or side panel)-}--interface ScribeConnection {- close: () => void- on: (event: string, listener: (payload: any) => void) => void- off: (event: string, listener: (payload: any) => void) => void-}--interface ScribeNamespace {- connect: (options: {- token: string- modelId: string- commitStrategy?: string- microphone?: { echoCancellation?: boolean; noiseSuppression?: boolean }- }) => ScribeConnection-}--type RealtimeEventsEnum = Record<string, string>-type CommitStrategyEnum = { MANUAL: string; VAD: string }--let cachedSdkPromise: Promise<{- Scribe: ScribeNamespace- RealtimeEvents: RealtimeEventsEnum- CommitStrategy: CommitStrategyEnum-}> | null = null--async function loadScribeSdk(): Promise<{- Scribe: ScribeNamespace- RealtimeEvents: RealtimeEventsEnum- CommitStrategy: CommitStrategyEnum-}> {- if (!cachedSdkPromise) {- cachedSdkPromise = import(/* webpackChunkName: "elevenlabs-client" */ '@elevenlabs/client')- .then((mod) => ({- Scribe: (mod as unknown as { Scribe: ScribeNamespace }).Scribe,- RealtimeEvents: (mod as unknown as { RealtimeEvents: RealtimeEventsEnum }).RealtimeEvents,- CommitStrategy: (mod as unknown as { CommitStrategy: CommitStrategyEnum }).CommitStrategy,- }))- .catch((err) => {- cachedSdkPromise = null- throw err- })- }- return cachedSdkPromise-}--// Generated by kea-typegen. Update if you're an agent, ignore if you're human.-export interface handsFreeLogicValues {- threadLogicKey: string // maxLogic- canUseHandsFree: boolean- connection: HandsFreeConnection- error: string | null- isActive: boolean- partialTranscript: string- sdkAvailable: boolean | null- status: HandsFreeStatus-}--// Generated by kea-typegen. Update if you're an agent, ignore if you're human.-export interface handsFreeLogicActions {- cancelSpeaking: () => {- value: true- }- commitTranscript: (text: string) => {- text: string- }- enterHandsFree: () => {- value: true- }- exitHandsFree: (reason?: string) => {- reason: string- }- interruptSpeaking: () => {- value: true- }- setConnection: (connection: HandsFreeConnection) => {- connection: HandsFreeConnection- }- setError: (error: string | null) => {- error: string | null- }- setPartialTranscript: (text: string) => {- text: string- }- setSdkAvailable: (available: boolean) => {- available: boolean- }- setStatus: (status: HandsFreeStatus) => {- status: HandsFreeStatus- }- speakAssistantResponse: (summary: AssistantSummary) => {- summary: AssistantSummary- }- toggleHandsFree: () => {- value: true- }-}--// Generated by kea-typegen. Update if you're an agent, ignore if you're human.-export interface handsFreeLogicMeta {- key: string- __keaTypeGenInternalSelectorTypes: {- isActive: (status: HandsFreeStatus) => boolean- canUseHandsFree: (sdkAvailable: boolean | null) => boolean- }-}--export type handsFreeLogicType = MakeLogicType<- handsFreeLogicValues,- handsFreeLogicActions,- HandsFreeLogicProps,- handsFreeLogicMeta->--export const handsFreeLogic = kea<handsFreeLogicType>([- props({} as HandsFreeLogicProps),- key((props) => props.panelId as string),- path((key) => ['scenes', 'max', 'handsFreeLogic', key]),-- connect(({ panelId }: HandsFreeLogicProps) => ({- values: [maxLogic({ panelId }), ['threadLogicKey']],- })),-- actions({- enterHandsFree: true,- exitHandsFree: (reason?: string) => ({ reason: reason ?? 'user' }),- toggleHandsFree: true,- setStatus: (status: HandsFreeStatus) => ({ status }),- setConnection: (connection: HandsFreeConnection) => ({ connection }),- setError: (error: string | null) => ({ error }),- setPartialTranscript: (text: string) => ({ text }),- commitTranscript: (text: string) => ({ text }),- speakAssistantResponse: (summary: AssistantSummary) => ({ summary }),- cancelSpeaking: true,- // Stop TTS playback and go back to listening — fired only when Scribe transcribes- // genuine user speech over Max's TTS (voice barge-in). The mic button no longer- // tap-interrupts; tapping it always exits hands-free entirely.- interruptSpeaking: true,- setSdkAvailable: (available: boolean) => ({ available }),- }),-- reducers({- status: [- 'off' as HandsFreeStatus,- {- setStatus: (_, { status }) => status,- },- ],- connection: [- 'idle' as HandsFreeConnection,- {- setConnection: (_, { connection }) => connection,- exitHandsFree: () => 'idle' as HandsFreeConnection,- },- ],- error: [- null as string | null,- {- setError: (_, { error }) => error,- enterHandsFree: () => null,- exitHandsFree: () => null,- },- ],- partialTranscript: [- '' as string,- {- setPartialTranscript: (_, { text }) => text,- commitTranscript: () => '',- exitHandsFree: () => '',- },- ],- // null = probe not yet finished, true = Scribe present, false = SDK missing or load failed- sdkAvailable: [- null as boolean | null,- {- setSdkAvailable: (_, { available }) => available,- },- ],- }),-- selectors({- isActive: [(s) => [s.status], (status: HandsFreeStatus) => status !== 'off'],- // Render the mic button when the probe hasn't completed yet (null) or has succeeded (true).- // Hide it only once we've confirmed the SDK can't be used.- canUseHandsFree: [(s) => [s.sdkAvailable], (sdkAvailable: boolean | null) => sdkAvailable !== false],- }),-- listeners(({ actions, values, cache, props }) => ({- toggleHandsFree: () => {- if (values.status === 'off') {- actions.enterHandsFree()- } else {- actions.exitHandsFree()- }- },-- enterHandsFree: async () => {- if (values.status !== 'off') {- return- }- actions.setStatus('starting')- actions.setConnection('connecting')-- // Per-session analytics counters, captured at exit so a single PostHog query can- // build session-length and turn-count distributions without re-aggregating events.- cache.sessionStartedAt = Date.now()- cache.userTurnCount = 0- cache.assistantTurnCount = 0- cache.interruptedCount = 0-- // iOS Safari requires the first audio playback (HTMLAudioElement.play()) to be- // initiated from a user-gesture handler. The mic-button click IS that gesture, so- // we prime a silent Audio element here. Subsequent .play() calls (driven by Max- // responses arriving over the network) then succeed without re-prompting.- try {- const primer = new Audio()- primer.muted = true- primer.src =- 'data:audio/mpeg;base64,SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4LjI5LjEwMAAAAAAAAAAAAAAA//tQxAADB8AhSmxhhgAAAAAAAAAAAExBTUUzLjEwMACqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq//tSxAADB8AhSmxhhgAAAAAAAAAAAExBTUUzLjEwMKqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq'- void primer.play().catch(() => undefined)- } catch {- // best-effort- }-- let sdk- try {- sdk = await loadScribeSdk()- } catch (err) {- posthog.captureException(err)- actions.setError('Could not load the hands-free SDK.')- lemonToast.error('Hands-free could not load. Please try again.')- actions.exitHandsFree('sdk_load_failed')- return- }- if (values.status === 'off') {- return- }-- const { Scribe, RealtimeEvents, CommitStrategy } = sdk- if (!Scribe || typeof Scribe.connect !== 'function') {- // Should be unreachable — the mount-time probe should have already hidden the- // button when the SDK doesn't expose Scribe. If we get here, capture so we can- // see it in PostHog and bail without confusing the user.- posthog.captureException(new Error('handsFree: Scribe namespace missing from @elevenlabs/client'))- actions.setSdkAvailable(false)- actions.exitHandsFree('sdk_missing_scribe')- return- }-- cache.reconnectAttempts = 0-- // Mints a fresh token, opens a Scribe connection, and wires event handlers.- // Called for the initial session and on reconnect after an unexpected close.- // Returns true on success, false when the caller should give up.- const establishConnection = async (isReconnect: boolean): Promise<boolean> => {- let token: string- try {- const response = await api.maxHandsFree.token()- token = response.token- } catch (err) {- posthog.captureException(err)- if (!isReconnect) {- actions.setError('Could not start hands-free session.')- lemonToast.error('Hands-free could not start. Please try again.')- }- actions.exitHandsFree(isReconnect ? 'reconnect_token_failed' : 'token_failed')- return false- }- if (values.status === 'off') {- return false- }- let connection: ScribeConnection- try {- connection = Scribe.connect({- token,- modelId: SCRIBE_REALTIME_MODEL_ID,- // SDK defaults to MANUAL — we need VAD so silence on the mic auto-commits- // the speech segment and triggers askMax. Without this it isn't hands-free.- commitStrategy: CommitStrategy?.VAD ?? 'vad',- microphone: { echoCancellation: true, noiseSuppression: true },- })- } catch (err) {- posthog.captureException(err)- const message = (err as Error)?.message ?? ''- const isPermissionError =- /permission|notallowed|denied/i.test(message) ||- (err as { name?: string })?.name === 'NotAllowedError'- if (isPermissionError) {- actions.setError('Microphone access was denied.')- lemonToast.error('Microphone access was denied. Hands-free disabled.')- actions.exitHandsFree('mic_permission_denied')- } else if (isReconnect) {- actions.exitHandsFree('reconnect_failed')- } else {- actions.setError(`Hands-free connection failed: ${message || 'unknown error'}`)- lemonToast.error('Hands-free failed to start. See console for details.')- actions.exitHandsFree('connection_failed')- }- return false- }- cache.connection = connection- wireConnectionEvents(connection)- return true- }-- const onOpen = (): void => actions.setConnection('connected')- const onSessionStarted = (): void => {- const wasStarting = values.status === 'starting'- const wasReconnecting = cache.isReconnecting === true- cache.isReconnecting = false- if (wasStarting || wasReconnecting) {- actions.setStatus('listening')- }- if (wasStarting) {- posthog.capture('max hands-free entered')- }- if (wasReconnecting) {- posthog.capture('max hands-free reconnected', {- attempts: cache.reconnectAttempts ?? 1,- })- }- }- // While 'speaking', the Scribe mic stream stays open (we can't cheaply pause it)- // and the speakers' TTS audio bleeds back into the mic — Scribe transcribes its- // own voice. To support real barge-in (user talks over Max -> Max shuts up and- // listens) without self-triggering, we compare incoming partials to what Max is- // currently saying. If the partial is a substring of the spoken text, it's- // self-transcription bleed; otherwise the user is talking over Max.- const onPartial = (payload: any): void => {- const text: string = payload?.text ?? payload?.transcript ?? ''- if (values.status === 'speaking') {- const partialLower = normaliseForBargeInMatch(text)- const spokenLower: string = cache.spokenTextLower ?? ''- const reason = classifyPartial(spokenLower, partialLower)- if (reason) {- posthog.capture('max hands-free partial suppressed', {- reason,- partial_chars: partialLower.length,- spoken_chars: spokenLower.length,- phase: 'partial',- })- return- }- // User is talking over Max — barge in: stop TTS, flip to listening, then- // let the partial-transcript reducer below pick up the user's words.- actions.interruptSpeaking()- }- if (values.status === 'listening') {- actions.setPartialTranscript(text)- }- }- const onCommitted = (payload: any): void => {- const text: string = (payload?.text ?? payload?.transcript ?? '').trim()- if (!text) {- return- }- if (values.status === 'speaking') {- const committedLower = normaliseForBargeInMatch(text)- const spokenLower: string = cache.spokenTextLower ?? ''- const reason = classifyPartial(spokenLower, committedLower)- if (reason) {- posthog.capture('max hands-free partial suppressed', {- reason,- partial_chars: committedLower.length,- spoken_chars: spokenLower.length,- phase: 'committed',- })- return- }- actions.interruptSpeaking()- }- if (values.status !== 'listening') {- return- }- actions.commitTranscript(text)- }- const onClose = (): void => {- if (values.status === 'off') {- return- }- // Single retry-with-fresh-token on unexpected close — mobile network blips- // (the exact gym/walking use case this targets) should not tear down the- // session. Beyond one attempt we give up to avoid a reconnect storm.- const attempts = (cache.reconnectAttempts ?? 0) + 1- cache.reconnectAttempts = attempts- if (attempts > 1) {- actions.setConnection('closed')- actions.exitHandsFree('connection_closed')- return- }- actions.setConnection('reconnecting')- cache.isReconnecting = true- posthog.capture('max hands-free reconnect attempted', { attempt: attempts })- cache.connection = undefined- void establishConnection(true)- }- const onError = (payload: any): void => {- posthog.captureException(new Error(`scribe error: ${JSON.stringify(payload ?? {})}`))- actions.setError('Hands-free connection error.')- actions.exitHandsFree('scribe_error')- }-- const wireConnectionEvents = (connection: ScribeConnection): void => {- connection.on(RealtimeEvents.OPEN, onOpen)- connection.on(RealtimeEvents.SESSION_STARTED, onSessionStarted)- connection.on(RealtimeEvents.PARTIAL_TRANSCRIPT, onPartial)- connection.on(RealtimeEvents.COMMITTED_TRANSCRIPT, onCommitted)- connection.on(RealtimeEvents.CLOSE, onClose)- connection.on(RealtimeEvents.ERROR, onError)- }-- await establishConnection(false)- },-- exitHandsFree: ({ reason }) => {- posthog.capture('max hands-free exited', {- reason,- duration_ms: cache.sessionStartedAt ? Date.now() - cache.sessionStartedAt : null,- user_turns: cache.userTurnCount ?? 0,- assistant_turns: cache.assistantTurnCount ?? 0,- interruptions: cache.interruptedCount ?? 0,- })- actions.cancelSpeaking()- const connection = cache.connection as ScribeConnection | undefined- if (connection) {- try {- connection.close()- } catch {- // best-effort- }- cache.connection = undefined- }- actions.setStatus('off')- },-- commitTranscript: ({ text }) => {- const threadKey = values.threadLogicKey- const threadLogic = threadKey- ? maxThreadLogic.findMounted({- panelId: props.panelId,- conversationId: threadKey,- })- : null- if (!threadLogic) {- actions.setError('Could not find an active conversation to send the message to.')- actions.exitHandsFree('no_thread')- return- }- actions.setStatus('thinking')- cache.userTurnCount = (cache.userTurnCount ?? 0) + 1- posthog.capture('max hands-free user spoke', { transcript_chars: text.length })- threadLogic.actions.askMax(text)- },-- speakAssistantResponse: async ({ summary }) => {- if (values.status === 'off') {- return- }- // guard re-entry — if two assistant turns complete back-to-back, tear down the- // previous playback (revokes blob URL, aborts inflight request) before queuing a- // new one. Otherwise the previous audio leaks and overlaps.- teardownSpeaking(cache)-- const spokenText = buildSpokenText(summary)- if (!spokenText) {- actions.setStatus('listening')- return- }- actions.setStatus('speaking')-- // Store what we're saying so onPartial can match incoming transcripts against it- // and tell self-transcription bleed apart from real user barge-in.- cache.spokenTextLower = normaliseForBargeInMatch(spokenText)-- const controller = new AbortController()- cache.speakAbortController = controller-- try {- const response = await api.maxHandsFree.synthesize(spokenText, { signal: controller.signal })- if (!response.ok) {- throw new Error(`TTS returned ${response.status}`)- }- const audioBlob = await response.blob()- if (controller.signal.aborted || values.status !== 'speaking') {- return- }- const url = URL.createObjectURL(audioBlob)- const audioElement = new Audio(url)- cache.speakAudioElement = audioElement- cache.speakAudioUrl = url-- const finished = new Promise<void>((resolve, reject) => {- audioElement.onended = () => resolve()- audioElement.onerror = () => reject(new Error('audio playback failed'))- })-- await audioElement.play()- // Capture once playback has actually started — distinguishes "Max attempted to- // speak" from "Max successfully voiced a response." Counted per session via- // assistant_turns on the exit event.- cache.assistantTurnCount = (cache.assistantTurnCount ?? 0) + 1- posthog.capture('max hands-free assistant spoke', {- text_chars: spokenText.length,- viz_count: summary.vizCount,- })- await finished- } catch (err) {- if ((err as { name?: string }).name !== 'AbortError') {- posthog.captureException(err)- }- } finally {- if (cache.speakAbortController === controller) {- teardownSpeaking(cache)- if (values.status === 'speaking') {- actions.setStatus('listening')- }- }- }- },-- cancelSpeaking: () => {- teardownSpeaking(cache)- },-- interruptSpeaking: () => {- // Only meaningful while we're actually playing audio — guard against stray- // fires from elsewhere accidentally jolting us through state transitions.- if (values.status !== 'speaking') {- return- }- teardownSpeaking(cache)- actions.setStatus('listening')- cache.interruptedCount = (cache.interruptedCount ?? 0) + 1- posthog.capture('max hands-free tts interrupted')- },- })),-- afterMount(({ actions, cache }) => {- // Probe the SDK once on mount so the mic button can decide whether to render itself.- // We capture failures to PostHog instead of surfacing dev-facing errors to end users.- // Skip the probe entirely when the feature flag is off — the logic mounts for every- // Max session, so an unconditional dynamic import would download the SDK chunk for- // every user even though only flagged users can ever use it.- if (!posthog.isFeatureEnabled(FEATURE_FLAGS.MAX_HANDS_FREE)) {- actions.setSdkAvailable(false)- return- }- cache.disposables.add(() => {- let cancelled = false- void loadScribeSdk()- .then((sdk) => {- if (cancelled) {- return- }- const available = !!sdk?.Scribe && typeof sdk.Scribe.connect === 'function'- if (!available) {- posthog.captureException(- new Error('handsFree: @elevenlabs/client loaded but Scribe is missing')- )- }- actions.setSdkAvailable(available)- })- .catch((err) => {- if (cancelled) {- return- }- posthog.captureException(err)- actions.setSdkAvailable(false)- })- return () => {- cancelled = true- }- }, 'sdkProbe')- }),-])--// Normalises a string to lowercase letters and digits separated by single spaces. Used to-// match an incoming Scribe partial against the TTS content for self-transcription detection.-function normaliseForBargeInMatch(text: string): string {- return text- .toLowerCase()- .replace(/[^a-z0-9]+/g, ' ')- .trim()-}--// Short words a gym/walking user is likely to shout to stop Max mid-sentence. These-// always trigger barge-in even though they'd otherwise fall under the too-short or-// substring suppression — a wrong barge-in is recoverable (user just keeps talking),-// a swallowed "stop" is not.-const BARGE_IN_TRIGGER_WORDS: ReadonlySet<string> = new Set(['stop', 'wait', 'cancel', 'no', 'max', 'shh', 'hey'])--export type SuppressionReason = 'too_short' | 'substring' | null--// Returns null when the partial should be treated as real user speech (barge in), or a-// reason string when it should be suppressed as TTS bleed. Callers should emit the-// reason to PostHog so we can measure misfire rate before tuning the heuristic.-export function classifyPartial(spokenLower: string, partialLower: string): SuppressionReason {- if (!partialLower) {- return 'too_short'- }- if (BARGE_IN_TRIGGER_WORDS.has(partialLower)) {- return null- }- if (partialLower.length < 4) {- return 'too_short'- }- if (spokenLower.includes(partialLower)) {- return 'substring'- }- return null-}--function teardownSpeaking(cache: Record<string, any>): void {- const controller = cache.speakAbortController as AbortController | undefined- if (controller) {- try {- controller.abort()- } catch {- // best-effort- }- cache.speakAbortController = undefined- }- const audio = cache.speakAudioElement as HTMLAudioElement | undefined- if (audio) {- try {- audio.pause()- audio.src = ''- } catch {- // best-effort- }- cache.speakAudioElement = undefined- }- if (cache.speakAudioUrl) {- try {- URL.revokeObjectURL(cache.speakAudioUrl)- } catch {- // best-effort- }- cache.speakAudioUrl = undefined- }- cache.spokenTextLower = undefined-}diff --git a/frontend/src/scenes/max/handsFreeUtils.test.ts b/frontend/src/scenes/max/handsFreeUtils.test.tsdeleted file mode 100644index 995c028b302f..000000000000--- a/frontend/src/scenes/max/handsFreeUtils.test.ts+++ /dev/null@@ -1,120 +0,0 @@-import { AssistantMessageType } from '~/queries/schema/schema-assistant-messages'--import { buildSpokenText, stripMarkdown, summariseAssistantThread } from './handsFreeUtils'--type StubMessage = Parameters<typeof summariseAssistantThread>[0][number]--const human = (content = 'hi'): StubMessage => ({ type: AssistantMessageType.Human, content })-const ai = (content: string): StubMessage => ({ type: AssistantMessageType.Assistant, content })-const viz = (): StubMessage => ({ type: AssistantMessageType.Visualization })-const multiViz = (): StubMessage => ({ type: AssistantMessageType.MultiVisualization })-const artifact = (): StubMessage => ({ type: AssistantMessageType.Artifact })--describe('handsFreeUtils', () => {- describe('summariseAssistantThread()', () => {- it('returns the assistant prose message and no viz suffix when none present', () => {- const result = summariseAssistantThread([human(), ai('here is the answer')])- expect(result).toEqual({ text: 'here is the answer', vizCount: 0 })- })-- it.each([- ['Visualization', [ai('see chart'), viz()], 1],- ['MultiVisualization', [ai('see charts'), multiViz()], 1],- ['Artifact', [ai('see notebook'), artifact()], 1],- ['mix of viz types', [ai('see charts'), viz(), multiViz(), artifact()], 3],- ] as const)('counts %s blocks since the last human message', (_label, tail, expectedCount) => {- const result = summariseAssistantThread([human(), ...tail])- expect(result.vizCount).toBe(expectedCount)- })-- it('only counts messages produced after the most recent human message', () => {- const result = summariseAssistantThread([- human('first ask'),- ai('old answer'),- viz(),- human('second ask'),- ai('new answer'),- viz(),- ])- expect(result).toEqual({ text: 'new answer', vizCount: 1 })- })-- it('returns the LATEST prose message when the assistant emits several in one turn', () => {- const result = summariseAssistantThread([- human(),- ai('first part of the answer'),- ai('second part of the answer'),- ai('final summary'),- ])- expect(result).toEqual({ text: 'final summary', vizCount: 0 })- })-- it('returns empty text when only viz messages followed the human turn', () => {- const result = summariseAssistantThread([human(), viz(), multiViz()])- expect(result).toEqual({ text: '', vizCount: 2 })- })-- it('returns empty text and zero count when thread has no assistant turn', () => {- const result = summariseAssistantThread([human()])- expect(result).toEqual({ text: '', vizCount: 0 })- })-- it('handles a thread that never had a human turn (e.g. agent-initiated)', () => {- const result = summariseAssistantThread([ai('hello there'), viz()])- expect(result).toEqual({ text: 'hello there', vizCount: 1 })- })- })-- describe('buildSpokenText()', () => {- it.each([- [{ text: 'just words', vizCount: 0 }, 'just words'],- [{ text: 'words', vizCount: 1 }, "words I've added 1 chart to the chat."],- [{ text: 'words', vizCount: 3 }, "words I've added 3 charts to the chat."],- [{ text: '', vizCount: 2 }, "I've added 2 charts to the chat."],- [{ text: '', vizCount: 0 }, ''],- ])('builds %p -> %p', (summary, expected) => {- expect(buildSpokenText(summary)).toBe(expected)- })- })-- describe('stripMarkdown()', () => {- it.each([- ['# Heading', 'Heading'],- ['**bold text**', 'bold text'],- ['_italic_', 'italic'],- ['*emphasised*', 'emphasised'],- ['~~struck~~', 'struck'],- ['`inline code`', 'inline code'],- ['1. first item\n2. second item', 'first item second item'],- ['- bullet\n- bullet', 'bullet bullet'],- ['[link text](https://example.com)', 'link text'],- [' caption', ' caption'],- ['> quoted line', 'quoted line'],- ])('strips %p -> %p', (input, expected) => {- expect(stripMarkdown(input)).toBe(expected)- })-- it('leaves identifiers like foo_bar_baz alone (bold underscore guard)', () => {- expect(stripMarkdown('the var is foo_bar_baz here')).toBe('the var is foo_bar_baz here')- })-- it('omits fenced code blocks rather than reading them verbatim', () => {- const input = 'before\n```ts\nconst x = 1\n```\nafter'- expect(stripMarkdown(input)).toContain('code block omitted')- expect(stripMarkdown(input)).not.toContain('const x')- })-- it('strips table separator rows and pipes', () => {- const input = '| col a | col b |\n| --- | --- |\n| one | two |'- const result = stripMarkdown(input)- expect(result).not.toContain('---')- expect(result).not.toContain('|')- expect(result).toContain('col a')- expect(result).toContain('one')- })-- it('collapses runs of whitespace so TTS does not over-pause', () => {- expect(stripMarkdown('one\n\n\ntwo')).toBe('one two')- })- })-})diff --git a/frontend/src/scenes/max/handsFreeUtils.ts b/frontend/src/scenes/max/handsFreeUtils.tsdeleted file mode 100644index ba42e32dbf7b..000000000000--- a/frontend/src/scenes/max/handsFreeUtils.ts+++ /dev/null@@ -1,85 +0,0 @@-import { AssistantMessageType } from '~/queries/schema/schema-assistant-messages'--const VIZ_TYPES = new Set<AssistantMessageType>([- AssistantMessageType.Visualization,- AssistantMessageType.MultiVisualization,- AssistantMessageType.Artifact,-])--export interface AssistantSummary {- text: string- vizCount: number-}--export function summariseAssistantThread(- messages: { type: AssistantMessageType; content?: unknown }[]-): AssistantSummary {- let humanCutoff = -1- for (let i = messages.length - 1; i >= 0; i--) {- if (messages[i].type === AssistantMessageType.Human) {- humanCutoff = i- break- }- }-- let latestProse = ''- let vizCount = 0- for (let i = humanCutoff + 1; i < messages.length; i++) {- const msg = messages[i]- if (VIZ_TYPES.has(msg.type)) {- vizCount += 1- continue- }- if (msg.type === AssistantMessageType.Assistant && typeof msg.content === 'string' && msg.content) {- latestProse = msg.content- }- }- return { text: latestProse, vizCount }-}--export function buildSpokenText(summary: AssistantSummary): string {- const stripped = stripMarkdown(summary.text).trim()- if (summary.vizCount === 0) {- return stripped- }- const suffix =- summary.vizCount === 1- ? "I've added 1 chart to the chat."- : `I've added ${summary.vizCount} charts to the chat.`- return stripped ? `${stripped} ${suffix}` : suffix-}--export function stripMarkdown(text: string): string {- return (- text- // fenced code blocks - replaced wholesale; never spoken- .replace(/```[\s\S]*?```/g, ' (code block omitted) ')- // inline code- .replace(/`([^`]+)`/g, '$1')- // images- .replace(/!\[[^\]]*\]\([^)]+\)/g, '')- // links - keep link text- .replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')- // tables - drop row-separator lines (| --- |) and pipe characters elsewhere- .replace(/^\s*\|?\s*:?-{2,}:?(\s*\|\s*:?-{2,}:?)*\s*\|?\s*$/gm, '')- .replace(/\|/g, ' ')- // headings- .replace(/^#+\s*/gm, '')- // bold - **foo** or __foo__ - run twice to safely handle nested markers- .replace(/\*\*([^*]+?)\*\*/g, '$1')- .replace(/__([^_]+?)__/g, '$1')- // italic - *foo* or _foo_ - but only when the marker is at a word boundary so- // identifiers like foo_bar_baz aren't mangled- .replace(/(^|[^A-Za-z0-9_])[*_]([^*_\n]+?)[*_](?=$|[^A-Za-z0-9_])/g, '$1$2')- // strikethrough- .replace(/~~([^~]+?)~~/g, '$1')- // blockquotes- .replace(/^\s*>\s?/gm, '')- // bulleted lists- .replace(/^\s*[-*+]\s+/gm, '')- // ordered lists- .replace(/^\s*\d+[.)]\s+/gm, '')- // collapse runs of whitespace - TTS reads runs of "\n\n" as awkward pauses- .replace(/\s+/g, ' ')- )-}diff --git a/frontend/src/scenes/max/maxThreadLogic.tsx b/frontend/src/scenes/max/maxThreadLogic.tsxindex 18e4611c9f64..c8877bfdc918 100644--- a/frontend/src/scenes/max/maxThreadLogic.tsx+++ b/frontend/src/scenes/max/maxThreadLogic.tsx@@ -83,8 +83,6 @@ import { isPiTaskRuntime } from 'products/posthog_ai/frontend/types/taskTypes'import type { PermissionRequestRecord } from '../../../../products/posthog_ai/frontend/types/streamTypes'import type { FeatureFlagsSet } from '../../lib/logic/featureFlagLogic'import type { BillingType } from '../../types'-import { handsFreeLogic } from './handsFreeLogic'-import { summariseAssistantThread } from './handsFreeUtils'import {EnhancedToolCall,MESSAGE_TOO_LONG,@@ -2058,16 +2056,9 @@ export const maxThreadLogic = kea<maxThreadLogicType>([})}const contextualTools = Object.fromEntries(values.tools.map((tool) => [tool.identifier, tool.context]))- // Always send voice_mode as an explicit boolean when handsFreeLogic is mounted,- // not just when active. Otherwise a typed turn following a spoken one inherits- // the earlier <voice_mode> system instruction from conversation history and- // keeps formatting for speech (no markdown, spelled-out numbers).- const handsFree = handsFreeLogic.findMounted({ panelId: props.panelId })- const voiceMode = handsFree ? { voice_mode: handsFree.values.isActive } : undefined- const mergedUiContext =- uiContext || voiceMode- ? { ...values.compiledContext, ...uiContext, ...voiceMode }- : values.compiledContext || undefined+ const mergedUiContext = uiContext+ ? { ...values.compiledContext, ...uiContext }+ : values.compiledContext || undefinedconst billingContext =values.billingContext && values.featureFlags[FEATURE_FLAGS.MAX_BILLING_CONTEXT]? values.billingContext@@ -2252,11 +2243,6 @@ export const maxThreadLogic = kea<maxThreadLogicType>([completeThreadGeneration: () => {actions.executePendingClientToolCall()- const handsFree = handsFreeLogic.findMounted({ panelId: props.panelId })- if (handsFree?.values.isActive) {- handsFree.actions.speakAssistantResponse(summariseAssistantThread(values.threadRaw))- }-// Update the conversation history to include the new conversationactions.loadConversationHistory({ doNotUpdateCurrentThread: true })diff --git a/frontend/src/scenes/max/maxTypes.ts b/frontend/src/scenes/max/maxTypes.tsindex 8a78a1c201f1..4ad3854f6392 100644--- a/frontend/src/scenes/max/maxTypes.ts+++ b/frontend/src/scenes/max/maxTypes.ts@@ -82,10 +82,6 @@ export interface MaxUIContext {evaluations?: MaxEvaluationContext[]notebooks?: MaxNotebookContext[]form_answers?: Record<string, string> // question_id -> answer for create_form tool responses- // Request modality: true when the user is asking via hands-free voice mode. Backend- // appends a voice-formatting instruction to the prompt so the response is suitable- // for TTS (numbers spelled out, no markdown, etc).- voice_mode?: boolean}// Taxonomic filter optionsdiff --git a/frontend/src/scenes/project-homepage/ai-first/HomepageInput.tsx b/frontend/src/scenes/project-homepage/ai-first/HomepageInput.tsxindex 92c5f427fc5e..e36839fb46c6 100644--- a/frontend/src/scenes/project-homepage/ai-first/HomepageInput.tsx+++ b/frontend/src/scenes/project-homepage/ai-first/HomepageInput.tsx@@ -2,11 +2,10 @@ import { BindLogic, useActions, useAsyncActions, useValues } from 'kea'import posthog from 'posthog-js'import { useCallback, useEffect, useMemo, useRef, useState } from 'react'-import { IconArrowRight, IconClock, IconInfo, IconMicrophone, IconPin, IconSparkles } from '@posthog/icons'+import { IconArrowRight, IconClock, IconInfo, IconPin, IconSparkles } from '@posthog/icons'import { LemonButton, LemonSkeleton, Tooltip } from '@posthog/lemon-ui'import { Search } from 'lib/components/Search/Search'-import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'import { Link } from 'lib/lemon-ui/Link'import { ButtonPrimitive } from 'lib/ui/Button/ButtonPrimitives'import { Label } from 'lib/ui/Label/Label'@@ -17,7 +16,6 @@ import { FillInHint } from 'scenes/max/components/FillInHint'import { SidebarQuestionInput } from 'scenes/max/components/SidebarQuestionInput'import { SuggestionCard } from 'scenes/max/components/SuggestionCard'import { SUGGESTION_CARDS_HEIGHT_PX, COLORFUL_ICONS, TopicBadges } from 'scenes/max/components/TopicBadges'-import { handsFreeLogic } from 'scenes/max/handsFreeLogic'import { Intro } from 'scenes/max/Intro'import { maxGlobalLogic } from 'scenes/max/maxGlobalLogic'import { maxLogic } from 'scenes/max/maxLogic'@@ -43,13 +41,9 @@ import { SUGGESTIONS_LIMIT } from './homepageSuggestions'function IdleInput(): JSX.Element {const { query, fillInHint } = useValues(aiFirstHomepageLogic)- const { setQuery, submitQuery, enterAiMode, startHandsFreeChat, setFillInHint } = useActions(aiFirstHomepageLogic)- const { dataProcessingAccepted } = useValues(maxGlobalLogic)- const handsFreeFlag = useFeatureFlag('MAX_HANDS_FREE')- const { canUseHandsFree } = useValues(handsFreeLogic({ panelId: HOMEPAGE_TAB_ID }))+ const { setQuery, submitQuery, enterAiMode, setFillInHint } = useActions(aiFirstHomepageLogic)const inputRef = useRef<HTMLTextAreaElement>(null)- const handsFreeAvailable = handsFreeFlag && canUseHandsFree && dataProcessingAccepted// A fill-in suggestion typed its prefix in and is waiting for the user to complete it.const showFillInHint = !!fillInHint@@ -163,18 +157,6 @@ function IdleInput(): JSX.Element {><span className="text-xxs">Tab to search</span></ButtonPrimitive>- {handsFreeAvailable && (- <Tooltip title="Start a new chat in hands-free">- <ButtonPrimitive- iconOnly- data-attr="homepage-hands-free"- className="shrink-0"- onClick={startHandsFreeChat}- >- <IconMicrophone className="size-4" />- </ButtonPrimitive>- </Tooltip>- )}<Tooltip title={!query.trim() ? 'Try asking a question' : undefined}><ButtonPrimitiveonClick={() => {diff --git a/frontend/src/scenes/project-homepage/ai-first/aiFirstHomepageLogic.ts b/frontend/src/scenes/project-homepage/ai-first/aiFirstHomepageLogic.tsindex 03af7ef62783..6a7b20c17335 100644--- a/frontend/src/scenes/project-homepage/ai-first/aiFirstHomepageLogic.ts+++ b/frontend/src/scenes/project-homepage/ai-first/aiFirstHomepageLogic.ts@@ -7,7 +7,6 @@ import type { DashboardBasicApi } from '@posthog/products-dashboards/frontend/geimport { tabUiStateLogic } from 'lib/logic/tabUiStateLogic'import { navigateToHref } from 'lib/utils/navigateToHref'-import { handsFreeLogic } from 'scenes/max/handsFreeLogic'import { type PhaiViewMode, maxGlobalLogic } from 'scenes/max/maxGlobalLogic'import { maxLogic, parseCommandString } from 'scenes/max/maxLogic'import { HOMEPAGE_SUGGESTION_TOPICS } from 'scenes/max/suggestionTopics'@@ -151,9 +150,6 @@ export interface aiFirstHomepageLogicValues {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface aiFirstHomepageLogicActions {- enterHandsFree: () => {- value: true- } // handsFreeLogicopenConversation: (conversationId: string) => {conversationId: string} // maxLogic@@ -222,9 +218,6 @@ export interface aiFirstHomepageLogicActions {setSelectedTopic: (key: string | null) => {key: string | null}- startHandsFreeChat: () => {- value: true- }submitQuery: (mode: 'ai' | 'search') => {mode: 'ai' | 'search'}@@ -297,8 +290,6 @@ export const aiFirstHomepageLogic = kea<aiFirstHomepageLogicType>([actions: [maxLogic({ panelId: HOMEPAGE_TAB_ID }),['openConversation', 'startNewConversation', 'setQuestion'],- handsFreeLogic({ panelId: HOMEPAGE_TAB_ID }),- ['enterHandsFree'],sceneLogic,['setHomepage'],tabUiStateLogic,@@ -308,7 +299,6 @@ export const aiFirstHomepageLogic = kea<aiFirstHomepageLogicType>([actions({submitQuery: (mode: 'search' | 'ai') => ({ mode }),- startHandsFreeChat: true,enterAiMode: (trigger: string) => ({ trigger }),setQuery: (query: string) => ({ query }),setAnimationPhase: (phase: AnimationPhase) => ({ phase }),@@ -635,14 +625,6 @@ export const aiFirstHomepageLogic = kea<aiFirstHomepageLogicType>([await breakpoint(200)actions.setAnimationPhase('content')},- startHandsFreeChat: () => {- posthog.capture('homepage hands-free started')- // Clear any in-progress conversation so hands-free always starts a fresh thread,- // then flip into AI mode (mounting maxThreadLogic) before Scribe starts listening.- actions.startNewConversation()- actions.submitQuery('ai')- actions.enterHandsFree()- },enterAiMode: async ({ trigger }, breakpoint) => {// Animate into AI mode without starting a conversationawait breakpoint(300)diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex ad4ef7dde2b2..789443f6f233 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -599,9 +599,6 @@ importers:'@dnd-kit/utilities':specifier: ^3.2.1version: 3.2.1([email protected])- '@elevenlabs/client':- specifier: ^1.4.0- version: 1.7.0(@types/[email protected])'@floating-ui/react':specifier: ^0.27.19@@ -7253,9 +7250,6 @@ packages:'@braintree/[email protected]':resolution: {integrity: sha512-jigsZK+sMF/cuiB7sERuo9V7N9jx+dhmHHnQyDSVdpZwVutaBu7WvNYqMDLSgFgfB30n452TP3vjDAvFC973mA==}- '@bufbuild/[email protected]':- resolution: {integrity: sha512-wJ8ReQbHxsAfXhrf9ixl0aYbZorRuOWpBNzm8pL8ftmSxQx/wnJD5Eg861NwJU/czy2VXFIebCeZnZrI9rktIQ==}-'@bufbuild/[email protected]':resolution: {integrity: sha512-i5GE2Dk5ekdlK1TR7SugY4LWRrKSfb5T1Qn4unpIMbfxoeGKERKQ59HG3iYewacGD10SR7UzevfPnh6my4tNmQ==}@@ -7691,12 +7685,6 @@ packages:resolution: {integrity: sha512-3DkkN3FKJ++BQy8PE3LONoVSVBONG7hld9D+VqBp1Dcfw2PGSnWyg20NET5cJkiygWK2y2H1ra8GWk3yixzuuA==}engines: {node: '>=18.18.2'}- '@elevenlabs/[email protected]':- resolution: {integrity: sha512-uLlR2GHM3lBAVZ+0zyACBYQ3hTJ5kcRh3H6fj/EMy8+N6pO43ru7hJhorMQbda19eY2sHwivjD5Vys0O0vR1Og==}-- '@elevenlabs/[email protected]':- resolution: {integrity: sha512-4FdEv9YYR1EHl1KJwUFNqJcm9e1zuHi92Ky3wQgCM4UkzCiWNA24SyhLGchbXxv/Hc4w4arqBObQQ6SMj3jsKA==}-'@emnapi/[email protected]':resolution: {integrity: sha512-l9Oo58x0HOP5znGzVhYW9U3e5wVuA4LAZU2AGezTmkhO1CgQRFDhDg4nneHsu/t3WniXg9QrG2nIXL/ZS8ln8Q==}@@ -9137,12 +9125,6 @@ packages:'@lezer/[email protected]':resolution: {integrity: sha512-pu0K1jCIdnQ12aWNaAVU5bzi7Bd1w54J3ECgANPmYLtQKP0HBj2cE/5coBD66MT10xbtIuUr7tg0Shbsvk0mDA==}- '@livekit/[email protected]':- resolution: {integrity: sha512-EsshAucklmpuUAfkABPxJNhzj9v2sG7JuzFDL4ML1oJQSV14sqrpTYnsaOudMAw9yOaW53NU3QQTlUQoRs4czw==}-- '@livekit/[email protected]':- resolution: {integrity: sha512-Q+l57E7w/xxOBFVWzdX5rkAZO7ffyF+rlDzNUYq2SU114+5aTyCq+PK4unaEVDNd4952Af7wteKr3sOgasGuaA==}-'@lmdb/[email protected]':resolution: {integrity: sha512-KPDeVScZgA1oq0CiPBcOa3kHIqU+pTOwRFDIhxvmf8CTNvqdZQYp5cCKW0bUk69VygB2PuTiINFWbY78aR2pQw==}cpu: [arm64]@@ -13465,9 +13447,6 @@ packages:'@types/[email protected]':resolution: {integrity: sha512-eOIHzCUSH7SMfonMG1LsC2f8vxBFtho6NGBznK41R84YzPuvSBzrhEps33IsQiOW9+VL6NQ9DbjQJznk/S4uRA==}- '@types/[email protected]':- resolution: {integrity: sha512-mUMZLK3NvwRLcAAT9qmcK+9p7tpU2FHdDsntR3YI4+GY88XrgG4XiE7u1Q2LAN2/FZOz/tdMDC3GQCR4T8nFuw==}-'@types/[email protected]':resolution: {integrity: sha512-odiGr/9/qMqjcBOe5UhcNLOFHSYmKFOyr+bJ/Xu3Qp4k1pNPAlNLUVNNLcLfjQI7+W7ObX58EdD3H+3p3voOvA==}@@ -18810,11 +18789,6 @@ packages:resolution: {integrity: sha512-iyAZCeyD+c1gPyE9qpFu8af0Y+MRtmKOncdGoA2S5EY8iFq99dmmvkNnHiWo+pj0s7yH7l3KPIgee77tKpXPWQ==}engines: {node: '>=18.0.0'}- resolution: {integrity: sha512-aolY1XDAtx0nHKBNm29W9OhzBnSz1CP5kq3phvRhFfi1NbvMXs8tcACjAkZTnIKgihkp+BiJScZZ3tZv0Gz8sA==}- peerDependencies:- '@types/dom-mediacapture-record': ^1-resolution: {integrity: sha512-9bMdFfc80S+vSldBmG3HOuLVHnxRdNTlpzR6QDnzqCQtCzGUEAGTzBKYMeIM+I/sU4oZfgbcbS7X7F65/z/oxQ==}hasBin: true@@ -18919,10 +18893,6 @@ packages:resolution: {integrity: sha512-9ie8ItPR6tjY5uYJh8K/Zrv/RMZ5VOlOWvtZdEHYSTFKZfIBPQa9tOAEeAWhd+AnIneLJ22w5fjOYtoutpWq5w==}engines: {node: '>=18'}- resolution: {integrity: sha512-HgMmCqIJSAKqo68l0rS2AanEWfkxaZ5wNiEFb5ggm08lDs9Xl2KxBlX3PTcaD2chBM1gXAYf491/M2Rv8Jwayg==}- engines: {node: '>= 0.6.0'}-resolution: {integrity: sha512-BFRuQUqc7x2NWxfJBCyUrN8iYUYznzL9JROmRz1gZ6KlOIgmoD+njPVbb+VNn2nGMKggMsK79iUNErillsrx7w==}@@ -21829,13 +21799,6 @@ packages:resolution: {integrity: sha512-49oNpRjWRvnU8NyGVmUaYG4jtTkNonFZI86MmGRDqBphEK2EXT9gdEUoQPZhuBM8yWHxCWbobltqYO5M4XrUvQ==}- resolution: {integrity: sha512-KrOH82c/W+GYQ0LHqtr3caRpM3ITglq3ljGUIb8LTki7ByacJZ9z+piSGiwZDsRyhQbYBOBJgr2k6X4BZXi3Kw==}- hasBin: true-- resolution: {integrity: sha512-xZocWwfyp4hkbN4hLWxMjmv2Q8aNa9MhmOZ7L9aCZPT+dZsgRr6wZRrSYE3HTdyk/2pZKPSgqI7ns7Een1xMSA==}-resolution: {integrity: sha512-AckIIV90rPDcBcglUwXPF3kg0P0qmPsPXAj6BBEENQE1p5yA1xfmDJzfi1Tappj37Pv2mVbKpL3Z1T+Nn7k1Qw==}@@ -23048,9 +23011,6 @@ packages:resolution: {integrity: sha512-3KS2b+kL7fsuk/eJZ7EQdnEmQoaho/r6KUef7hxvltNA5DR8NAUM+8wJMbJyZ4G9/7i3v5zPBIMN5aybAh2/Jg==}engines: {node: '>= 0.4'}- resolution: {integrity: sha512-g/KzbYKbH5C2vPkaXGu8DJlHrGKHLsM25Zg9WuC9pMGfuvT+X25tZQWo5fK1BjBm8+UrVE9LDCvaY0CQk+fXDA==}-resolution: {integrity: sha512-uzR+FzI8qrUEIu96oaeBJmd9E7CFEiQ3goA5qCVgc4s5llSubcfGHq9yUstZx/k4s9dXHVKsE35YWoFyvEqEHA==}@@ -23661,10 +23621,6 @@ packages:webpack-cli:optional: true- resolution: {integrity: sha512-U9vjByy/sK2OMXu5mmfuZFKTMIUQe34c0JXRO+oDrxJTsntdYT2iIFwYMOV7HhMTuktcZLGf2W1N/OcSf9ssWg==}- engines: {node: '>=6.0.0', npm: '>=3.10.0'}-resolution: {integrity: sha512-AMcUeyXAhbACL8S2hqqdqOLqvJ8ylmIbNwUIqQujRSouf4+eUFaXbG6F1Rbu+srlJMmxQWsiU7mOJi0nMBfM1g==}@@ -26343,8 +26299,6 @@ snapshots:'@braintree/[email protected]': {}- '@bufbuild/[email protected]': {}-'@bufbuild/[email protected]': {}'@bufbuild/[email protected]': {}@@ -26779,15 +26733,6 @@ snapshots:- bufferutil- utf-8-validate- '@elevenlabs/[email protected](@types/[email protected])':- dependencies:- '@elevenlabs/types': 0.13.0- livekit-client: 2.19.0(@types/[email protected])- transitivePeerDependencies:- - '@types/dom-mediacapture-record'-- '@elevenlabs/[email protected]': {}-'@emnapi/[email protected]':dependencies:'@emnapi/wasi-threads': 1.2.2@@ -28399,12 +28344,6 @@ snapshots:dependencies:'@lezer/common': 1.2.3- '@livekit/[email protected]': {}-- '@livekit/[email protected]':- dependencies:- '@bufbuild/protobuf': 1.10.1-'@lmdb/[email protected]':optional: true@@ -33347,8 +33286,6 @@ snapshots:'@types/[email protected]': {}- '@types/[email protected]': {}-'@types/[email protected]':dependencies:'@types/trusted-types': 2.0.4@@ -40514,19 +40451,6 @@ snapshots:rfdc: 1.4.1wrap-ansi: 9.0.2- [email protected](@types/[email protected]):- dependencies:- '@livekit/mutex': 1.1.1- '@livekit/protocol': 1.45.8- '@types/dom-mediacapture-record': 1.0.22- events: 3.3.0- jose: 6.2.3- loglevel: 1.9.2- sdp-transform: 2.15.0- tslib: 2.8.1- typed-emitter: 2.1.0- webrtc-adapter: 9.0.5-dependencies:msgpackr: 1.11.2@@ -40623,8 +40547,6 @@ snapshots:strip-ansi: 7.2.0wrap-ansi: 9.0.2- [email protected]: {}-@@ -44371,10 +44293,6 @@ snapshots:dependencies:compute-scroll-into-view: 3.1.1- [email protected]: {}-- [email protected]: {}-@@ -45815,10 +45733,6 @@ snapshots:possible-typed-array-names: 1.0.0reflect.getprototypeof: 1.0.10- optionalDependencies:- rxjs: 7.8.1-@@ -46619,10 +46533,6 @@ snapshots:- postcss- uglify-js- dependencies:- sdp: 3.2.2-diff --git a/posthog/rate_limit.py b/posthog/rate_limit.pyindex 04ad23442a53..3572c535aaa6 100644--- a/posthog/rate_limit.py+++ b/posthog/rate_limit.py@@ -836,45 +836,6 @@ class AIResearchBurstRateThrottle(_AIThrottleBase):action_name = "ai research burst rate limited"-# Hands-free throttles are split per-action so a burst on /token/ (e.g. a flapping-# mobile network triggering the reconnect path) can't lock the user out of /synthesize/-# and vice versa. Each action's burst/sustained bucket caps a different cost surface:-# token mints bound Scribe (STT) spend; synthesize calls bound ElevenLabs TTS spend.-class MaxHandsFreeTokenBurstRateThrottle(_AIThrottleBase):- # 10/min covers normal reconnects (network blip, tab refocus) and stays well below- # any plausible legitimate flow. Dev gets a far larger ceiling for the dev loop.- scope = "max_hands_free_token_burst"- rate = "1000/minute" if settings.DEBUG else "10/minute"- action_name = "max hands-free token burst rate limited"---class MaxHandsFreeTokenSustainedRateThrottle(_AIThrottleBase):- # Each token grants ~15 min of Scribe usage. A 2-hour gym session is ~8 tokens at- # minimum plus reconnects, call it 15. 60/day covers several long sessions a day- # with headroom and bounds worst-case Scribe spend per compromised account.- scope = "max_hands_free_token_sustained"- rate = "10000/day" if settings.DEBUG else "60/day"- action_name = "max hands-free token sustained rate limited"---class MaxHandsFreeSynthesizeBurstRateThrottle(_AIThrottleBase):- # TTS calls fire once per assistant turn so the burst rate has to keep pace with- # rapid back-and-forth. 20/min still well above any natural conversation cadence- # but tight enough to slow a runaway client looping on synthesize.- scope = "max_hands_free_synthesize_burst"- rate = "1000/minute" if settings.DEBUG else "20/minute"- action_name = "max hands-free synthesize burst rate limited"---class MaxHandsFreeSynthesizeSustainedRateThrottle(_AIThrottleBase):- # Bounds TTS spend per account per day. 150 calls * 2000 chars max ~= 300k chars- # ceiling/day — comfortable for power users, hard cap on a compromised account's- # daily ElevenLabs bill until the broader char-budget kill switch lands.- scope = "max_hands_free_synthesize_sustained"- rate = "10000/day" if settings.DEBUG else "150/day"- action_name = "max hands-free synthesize sustained rate limited"--class AIResearchSustainedRateThrottle(_AIThrottleBase):scope = "ai_research_sustained"rate = "10/day"diff --git a/posthog/schema.py b/posthog/schema.pyindex b1130c85171f..4c5f5440c94e 100644--- a/posthog/schema.py+++ b/posthog/schema.py@@ -33880,7 +33880,6 @@ class MaxUIContext(BaseModel):form_answers: dict[str, str] | None = Noneinsights: list[MaxInsightContext] | None = Nonenotebooks: list[MaxNotebookContext] | None = None- voice_mode: bool | None = Noneclass QueryRequest(BaseModel):diff --git a/posthog/settings/integrations.py b/posthog/settings/integrations.pyindex f68bf99450f1..4c0a438fa999 100644--- a/posthog/settings/integrations.py+++ b/posthog/settings/integrations.py@@ -186,20 +186,6 @@ WORKOS_RADAR_ENABLED = get_from_env("WORKOS_RADAR_ENABLED", False, type_cast=strCLOUDFLARE_TURNSTILE_SECRET_KEY = get_from_env("CLOUDFLARE_TURNSTILE_SECRET_KEY", "")CLOUDFLARE_TURNSTILE_SITE_KEY = get_from_env("CLOUDFLARE_TURNSTILE_SITE_KEY", "")-# ElevenLabs (Max hands-free mode)-# STT goes browser ↔ ElevenLabs over a single-use Scribe WebSocket token (backend just mints).-# TTS goes browser → PostHog → ElevenLabs → audio stream (backend proxies the key to ElevenLabs).-ELEVENLABS_API_KEY = get_from_env("ELEVENLABS_API_KEY", "")-ELEVENLABS_API_BASE_URL = get_from_env("ELEVENLABS_API_BASE_URL", "https://api.elevenlabs.io")-# Rachel is ElevenLabs' default voice — neutral, clear at gym pace. Override if you want a-# different feel without redeploying.-ELEVENLABS_VOICE_ID = get_from_env("ELEVENLABS_VOICE_ID", "21m00Tcm4TlvDq8ikWAM")-# Turbo v2.5 has ~300ms TTFB latency, sits in the free tier, and sounds clean enough for-# gym-pace narration. Flash v2.5 is marginally faster but requires Creator ($22/mo) or above-# on the ElevenLabs side, so devs running on free quota hit a 402 from the TTS proxy.-# Override at the env level if you're on a paid tier and want the extra polish.-ELEVENLABS_TTS_MODEL_ID = get_from_env("ELEVENLABS_TTS_MODEL_ID", "eleven_turbo_v2_5")-# PandaDoc (for legal documents: BAA/DPA). One template per document variant.# Each call needs the matching template id, so we keep them as separate env vars —# rotating one (e.g., when Legal updates the DPA copy) doesn't touch the others.diff --git a/products/posthog_ai/frontend/generated/api.schemas.ts b/products/posthog_ai/frontend/generated/api.schemas.tsindex 066e9d65463a..b2260c24cb5e 100644--- a/products/posthog_ai/frontend/generated/api.schemas.ts+++ b/products/posthog_ai/frontend/generated/api.schemas.ts@@ -618,11 +618,6 @@ export interface PatchedMaxCoreMemoryApi {scraping_status?: CoreMemoryScrapingStatusEnumApi | BlankEnumApi | null}-export interface HandsFreeTokenApi {- /** Single-use ElevenLabs Scribe realtime token, valid for 15 minutes. */- token: string-}-export interface JsonValueApi {}/**diff --git a/products/posthog_ai/frontend/generated/api.ts b/products/posthog_ai/frontend/generated/api.tsindex 8613e2f70541..245f332c3892 100644--- a/products/posthog_ai/frontend/generated/api.ts+++ b/products/posthog_ai/frontend/generated/api.ts@@ -14,7 +14,6 @@ import type {CoreMemoryListParams,DocsSearchRequestApi,DocsSearchResponseApi,- HandsFreeTokenApi,MCPToolRequestApi,MCPToolResponseApi,MaxCoreMemoryApi,@@ -380,27 +379,6 @@ export const coreMemoryPartialUpdate = async (})}-export const getMaxHandsFreeTokenCreateUrl = (projectId: string) => {- return `/api/projects/${projectId}/max_hands_free/token/`-}--/**- * Mint a single-use ElevenLabs Scribe realtime token.- *- * The browser uses the token to open a WebSocket directly to ElevenLabs — audio never- * transits PostHog infrastructure. Tokens are time-bound (15 min) and single-use; the- * per-team rate limit on this endpoint caps how often a user can mint new ones.- *- * Never logs the upstream response body — provider error responses can echo PII back and- * we don't want any of that landing in structured logs.- */-export const maxHandsFreeTokenCreate = async (projectId: string, options?: RequestInit): Promise<HandsFreeTokenApi> => {- return apiMutator<HandsFreeTokenApi>(getMaxHandsFreeTokenCreateUrl(projectId), {- ...options,- method: 'POST',- })-}-export const getMcpToolsCreateUrl = (projectId: string, toolName: string) => {return `/api/projects/${projectId}/mcp_tools/${toolName}/`}diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex ad53ec6cf637..67977571ab6e 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -55035,11 +55035,6 @@ export namespace Schemas {on_overflow?: OnOverflowEnum;}- export interface HandsFreeToken {- /** Single-use ElevenLabs Scribe realtime token, valid for 15 minutes. */- token: string;- }-/*** 409 body when a guarded write was based on a stale head.*/