Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: add an opt-in setting to read replies aloud automatically (#13357)

Daniel Hanf1eb893836df
diff --git a/studio/frontend/src/components/assistant-ui/auto-read-aloud.tsx b/studio/frontend/src/components/assistant-ui/auto-read-aloud.tsx
new file mode 100644
index 00000000000..9ce4cadc4cd
--- /dev/null
+++ b/studio/frontend/src/components/assistant-ui/auto-read-aloud.tsx
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import { decideAutoRead, useChatActive } from "@/features/chat";
+import { useVoiceSettingsStore } from "@/features/settings";
+import {
+ type AssistantRuntime,
+ useAui,
+ useAuiEvent,
+ useAuiState,
+} from "@assistant-ui/react";
+import { type FC, useCallback, useEffect, useRef } from "react";
+
+export const AutoReadAloud: FC = () => {
+ const aui = useAui();
+ // False for the single chat kept mounted behind Compare or off-route.
+ const active = useChatActive();
+ const pendingRef = useRef(false);
+ const lastSpokenRef = useRef<string | null>(null);
+ const threadId = useAuiState(({ threadListItem }) => threadListItem.id);
+ const lastId = useAuiState(({ thread }) => thread.messages.at(-1)?.id);
+ const lastStatus = useAuiState(
+ ({ thread }) => thread.messages.at(-1)?.status?.type,
+ );
+
+ // runEnd can fire before the final status lands; the effect below retries then.
+ const resolvePending = useCallback(() => {
+ if (!pendingRef.current) return;
+ const thread = aui.thread();
+ const decision = decideAutoRead(thread.getState().messages);
+ if (decision.kind === "wait") return;
+ pendingRef.current = false;
+ if (decision.kind !== "speak" || !active) return;
+ if (!useVoiceSettingsStore.getState().autoReadAloud) return;
+ if (lastSpokenRef.current === decision.messageId) return;
+ lastSpokenRef.current = decision.messageId;
+ try {
+ thread.message({ id: decision.messageId }).speak();
+ } catch {
+ // No speech adapter, or the message is gone.
+ }
+ }, [aui, active]);
+
+ useAuiEvent("thread.runStart", () => {
+ pendingRef.current = false;
+ if (!useVoiceSettingsStore.getState().autoReadAloud) return;
+ const thread = aui.thread();
+ if (!thread.getState().speech) return;
+ try {
+ thread.stopSpeaking();
+ } catch {
+ // Already ended.
+ }
+ });
+
+ useAuiEvent("thread.runEnd", () => {
+ pendingRef.current = true;
+ resolvePending();
+ });
+
+ useEffect(() => {
+ resolvePending();
+ }, [lastId, lastStatus, resolvePending]);
+
+ // The old thread's runtime stays alive, so its playback would overlap the next chat's.
+ useEffect(() => {
+ let bound: ReturnType<AssistantRuntime["threads"]["getById"]> | null = null;
+ try {
+ bound =
+ aui
+ .threads()
+ .__internal_getAssistantRuntime?.()
+ ?.threads.getById(threadId) ?? null;
+ } catch {
+ bound = null;
+ }
+ return () => {
+ pendingRef.current = false;
+ const spoken = lastSpokenRef.current;
+ if (!bound || !spoken) return;
+ try {
+ if (bound.getState().speech?.messageId === spoken) bound.stopSpeaking();
+ } catch {
+ // Thread removed or already ended.
+ }
+ };
+ }, [aui, threadId]);
+
+ return null;
+};
diff --git a/studio/frontend/src/components/assistant-ui/thread.tsx b/studio/frontend/src/components/assistant-ui/thread.tsx
index 8c7921316e4..bfa1a463bc5 100644
--- a/studio/frontend/src/components/assistant-ui/thread.tsx
+++ b/studio/frontend/src/components/assistant-ui/thread.tsx
@@ -20,6 +20,7 @@ import {
GeneratedImageOverlayProvider,
useGeneratedImageOverlay,
} from "@/components/assistant-ui/generated-image-overlay-context";
+import { AutoReadAloud } from "@/components/assistant-ui/auto-read-aloud";
import { CompactionNotice } from "@/components/assistant-ui/compaction-notice";
import { compactionNoticeMessageIds } from "@/components/assistant-ui/message-derived";
import type { ContextTruncation } from "@/features/chat/utils/context-truncation";
@@ -2181,6 +2182,7 @@ export const Thread: FC<{
onDragLeave={onDragLeave}
onDrop={onDrop}
>
+ {!hideComposer && <AutoReadAloud />}
<IntentAwareScrollProvider value={autoScrollContext}>
<ThreadPrimitive.Viewport
ref={composedViewportRef}
diff --git a/studio/frontend/src/features/chat/index.ts b/studio/frontend/src/features/chat/index.ts
index e5e7e47086f..b8e9e12441e 100644
--- a/studio/frontend/src/features/chat/index.ts
+++ b/studio/frontend/src/features/chat/index.ts
@@ -585,4 +585,5 @@ export type { ChatModelSummary, ChatLoraSummary } from "./types/runtime";
export { startLlamaCppAutoReload } from "./llama-cpp-auto-reload";
export { chatLocalModelOptions } from "./local-model-options";
export { readLastLocalModelLoad } from "./utils/last-local-model-load";
+export { decideAutoRead } from "./utils/auto-read-aloud";
export { wantsDownloadManagerStaging } from "./utils/model-download-staging";
diff --git a/studio/frontend/src/features/chat/utils/auto-read-aloud.ts b/studio/frontend/src/features/chat/utils/auto-read-aloud.ts
new file mode 100644
index 00000000000..13f66ef70b8
--- /dev/null
+++ b/studio/frontend/src/features/chat/utils/auto-read-aloud.ts
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import { readIncompleteInfo } from "./continuation.ts";
+
+export interface AutoReadMessage {
+ readonly id: string;
+ readonly role: string;
+ readonly metadata?: unknown;
+ readonly status?: { readonly type: string };
+ readonly content: readonly {
+ readonly type: string;
+ readonly text?: string;
+ }[];
+}
+
+export type AutoReadDecision =
+ | { kind: "wait" }
+ | { kind: "skip" }
+ | { kind: "speak"; messageId: string };
+
+export function decideAutoRead(
+ messages: readonly AutoReadMessage[],
+): AutoReadDecision {
+ const last = messages.at(-1);
+ if (!last || last.role !== "assistant") return { kind: "skip" };
+ if (last.status?.type === "running") return { kind: "wait" };
+ if (last.status?.type !== "complete") return { kind: "skip" };
+ // Cut-off turns can still settle as "complete".
+ if (readIncompleteInfo(last.metadata)) return { kind: "skip" };
+ const hasText = last.content.some(
+ (part) => part.type === "text" && !!part.text?.trim(),
+ );
+ return hasText ? { kind: "speak", messageId: last.id } : { kind: "skip" };
+}
diff --git a/studio/frontend/src/features/settings/settings-search.ts b/studio/frontend/src/features/settings/settings-search.ts
index 74fee4555b1..b2744da0f59 100644
--- a/studio/frontend/src/features/settings/settings-search.ts
+++ b/studio/frontend/src/features/settings/settings-search.ts
@@ -244,6 +244,7 @@ export const SETTINGS_SEARCH_INDEX: Record<SettingsTab, TranslationKey[]> = {
"settings.voice.recents.sectionTitle",
"settings.voice.readAloud.sectionTitle",
"settings.voice.readAloud.buttonLabel",
+ "settings.voice.readAloud.autoLabel",
"settings.voice.readAloud.engineLabel",
"settings.voice.readAloud.voiceLabel",
"settings.voice.readAloud.speedLabel",
diff --git a/studio/frontend/src/features/settings/stores/voice-settings-store.ts b/studio/frontend/src/features/settings/stores/voice-settings-store.ts
index 8e3a8bd3ce0..b939ae5a276 100644
--- a/studio/frontend/src/features/settings/stores/voice-settings-store.ts
+++ b/studio/frontend/src/features/settings/stores/voice-settings-store.ts
@@ -150,6 +150,10 @@ export interface VoiceSettingsState {
ttsEnabled: boolean;
setTtsEnabled: (value: boolean) => void;
+ /** Speak each finished assistant reply without a click. Off by default. */
+ autoReadAloud: boolean;
+ setAutoReadAloud: (value: boolean) => void;
+
/** "system": speechSynthesis voices. "studio": the loaded TTS audio model.
* "custom": a saved connection's /audio/speech endpoint. */
ttsEngine: TtsEngine;
@@ -340,6 +344,8 @@ export const useVoiceSettingsStore = create<VoiceSettingsState>()(
ttsEnabled: true,
setTtsEnabled: (ttsEnabled) => set({ ttsEnabled }),
+ autoReadAloud: false,
+ setAutoReadAloud: (autoReadAloud) => set({ autoReadAloud }),
ttsEngine: "system",
setTtsEngine: (ttsEngine) => set({ ttsEngine }),
@@ -410,6 +416,7 @@ export const useVoiceSettingsStore = create<VoiceSettingsState>()(
recentDictations: normalizeRecentDictations(saved?.recentDictations),
ttsEnabled:
typeof saved?.ttsEnabled === "boolean" ? saved.ttsEnabled : true,
+ autoReadAloud: saved?.autoReadAloud === true,
ttsEngine:
saved?.ttsEngine === "studio" || saved?.ttsEngine === "custom"
? saved.ttsEngine
diff --git a/studio/frontend/src/features/settings/tabs/voice-tab.tsx b/studio/frontend/src/features/settings/tabs/voice-tab.tsx
index 2dd77364f40..b251f02f1be 100644
--- a/studio/frontend/src/features/settings/tabs/voice-tab.tsx
+++ b/studio/frontend/src/features/settings/tabs/voice-tab.tsx
@@ -503,6 +503,8 @@ export function VoiceTab() {
);
const ttsEnabled = useVoiceSettingsStore((s) => s.ttsEnabled);
const setTtsEnabled = useVoiceSettingsStore((s) => s.setTtsEnabled);
+ const autoReadAloud = useVoiceSettingsStore((s) => s.autoReadAloud);
+ const setAutoReadAloud = useVoiceSettingsStore((s) => s.setAutoReadAloud);
const ttsEngine = useVoiceSettingsStore((s) => s.ttsEngine);
const setTtsEngine = useVoiceSettingsStore((s) => s.setTtsEngine);
const ttsVoiceURI = useVoiceSettingsStore((s) => s.ttsVoiceURI);
@@ -1579,6 +1581,16 @@ export function VoiceTab() {
<Switch checked={ttsEnabled} onCheckedChange={setTtsEnabled} />
</SettingsRow>
+ <SettingsRow
+ label={t("settings.voice.readAloud.autoLabel")}
+ description={t("settings.voice.readAloud.autoDescription")}
+ >
+ <Switch
+ checked={autoReadAloud}
+ onCheckedChange={setAutoReadAloud}
+ />
+ </SettingsRow>
+
<SettingsRow
label={t("settings.voice.readAloud.engineLabel")}
description={
diff --git a/studio/frontend/src/i18n/locales/ar.ts b/studio/frontend/src/i18n/locales/ar.ts
index e068bb87139..0ac228e616c 100644
--- a/studio/frontend/src/i18n/locales/ar.ts
+++ b/studio/frontend/src/i18n/locales/ar.ts
@@ -1496,6 +1496,8 @@ export const ar = {
sectionTitle: "القراءة بصوت عالٍ",
buttonLabel: "زر القراءة بصوت عالٍ",
buttonDescription: "إظهاره في ردود المساعد",
+ autoLabel: "قراءة الردود تلقائيًا",
+ autoDescription: "قراءة كل رد بصوت عالٍ فور اكتماله",
engineLabel: "محرك TTS",
engineSystemDescription: "الأصوات المدمجة في الجهاز",
engineStudioDescription: "يستخدم النموذج الصوتي المُحمَّل في قسم الصوت",
diff --git a/studio/frontend/src/i18n/locales/de.ts b/studio/frontend/src/i18n/locales/de.ts
index 79e37ec9b77..55b73e2783d 100644
--- a/studio/frontend/src/i18n/locales/de.ts
+++ b/studio/frontend/src/i18n/locales/de.ts
@@ -1508,6 +1508,8 @@ export const de = {
sectionTitle: "Vorlesen",
buttonLabel: "Vorlesen-Schaltfläche",
buttonDescription: "Bei Assistentenantworten anzeigen",
+ autoLabel: "Antworten automatisch vorlesen",
+ autoDescription: "Jede Antwort vorlesen, sobald sie fertig ist",
engineLabel: "TTS-Engine",
engineSystemDescription: "Auf dem Gerät integrierte Stimmen",
engineStudioDescription: "Verwendet das in Audio geladene Sprachmodell",
diff --git a/studio/frontend/src/i18n/locales/en.ts b/studio/frontend/src/i18n/locales/en.ts
index aa33b42f970..b15e5f56dbf 100644
--- a/studio/frontend/src/i18n/locales/en.ts
+++ b/studio/frontend/src/i18n/locales/en.ts
@@ -1543,6 +1543,8 @@ export const en = {
sectionTitle: "Read aloud",
buttonLabel: "Read aloud button",
buttonDescription: "Show on assistant responses",
+ autoLabel: "Read replies automatically",
+ autoDescription: "Read each reply aloud as soon as it finishes",
engineLabel: "TTS engine",
engineSystemDescription: "Built-in device voices",
engineStudioDescription: "Uses the speech model loaded in Audio",
diff --git a/studio/frontend/src/i18n/locales/es.ts b/studio/frontend/src/i18n/locales/es.ts
index c8aa1b709e0..fce0d0af992 100644
--- a/studio/frontend/src/i18n/locales/es.ts
+++ b/studio/frontend/src/i18n/locales/es.ts
@@ -1505,6 +1505,8 @@ export const es = {
sectionTitle: "Lectura en voz alta",
buttonLabel: "Botón de lectura en voz alta",
buttonDescription: "Mostrar en las respuestas del asistente",
+ autoLabel: "Leer las respuestas automáticamente",
+ autoDescription: "Lee en voz alta cada respuesta en cuanto termina",
engineLabel: "Motor de TTS",
engineSystemDescription: "Voces integradas del dispositivo",
engineStudioDescription: "Usa el modelo de voz cargado en Audio",
diff --git a/studio/frontend/src/i18n/locales/fr.ts b/studio/frontend/src/i18n/locales/fr.ts
index 874e26ee951..f2e605bd57a 100644
--- a/studio/frontend/src/i18n/locales/fr.ts
+++ b/studio/frontend/src/i18n/locales/fr.ts
@@ -1507,6 +1507,8 @@ export const fr = {
sectionTitle: "Lecture à voix haute",
buttonLabel: "Bouton de lecture à voix haute",
buttonDescription: "Afficher dans les réponses de l’assistant",
+ autoLabel: "Lire les réponses automatiquement",
+ autoDescription: "Lit chaque réponse à voix haute dès qu’elle est terminée",
engineLabel: "Moteur TTS",
engineSystemDescription: "Voix intégrées à l'appareil",
engineStudioDescription: "Utilise le modèle vocal chargé dans Audio",
diff --git a/studio/frontend/src/i18n/locales/he.ts b/studio/frontend/src/i18n/locales/he.ts
index d2c2cc8eb2f..96f22a8759a 100644
--- a/studio/frontend/src/i18n/locales/he.ts
+++ b/studio/frontend/src/i18n/locales/he.ts
@@ -1591,6 +1591,8 @@ export const he = {
sectionTitle: "הקראה קולית",
buttonLabel: "כפתור הקראה קולית",
buttonDescription: "הצג בתשובות העוזר",
+ autoLabel: "הקראת תשובות אוטומטית",
+ autoDescription: "הקראת כל תשובה ברגע שהיא מסתיימת",
engineLabel: "מנוע TTS",
engineSystemDescription: "קולות מובנים במכשיר",
engineStudioDescription: "משתמש במודל הדיבור שנטען באודיו",
diff --git a/studio/frontend/src/i18n/locales/hi.ts b/studio/frontend/src/i18n/locales/hi.ts
index 21f7acf3e85..77f19b4a19a 100644
--- a/studio/frontend/src/i18n/locales/hi.ts
+++ b/studio/frontend/src/i18n/locales/hi.ts
@@ -1502,6 +1502,8 @@ export const hi = {
sectionTitle: "ज़ोर से पढ़ना",
buttonLabel: "ज़ोर से पढ़ने का बटन",
buttonDescription: "असिस्टेंट के जवाबों पर दिखाएँ",
+ autoLabel: "जवाब अपने आप पढ़ें",
+ autoDescription: "हर जवाब पूरा होते ही ज़ोर से पढ़ें",
engineLabel: "TTS इंजन",
engineSystemDescription: "डिवाइस की अंतर्निहित आवाज़ें",
engineStudioDescription: "ऑडियो में लोड किए गए स्पीच मॉडल का उपयोग करता है",
diff --git a/studio/frontend/src/i18n/locales/it.ts b/studio/frontend/src/i18n/locales/it.ts
index 03dafbf51fb..d5b0fec9d1b 100644
--- a/studio/frontend/src/i18n/locales/it.ts
+++ b/studio/frontend/src/i18n/locales/it.ts
@@ -1464,6 +1464,8 @@ export const it = {
sectionTitle: "Lettura ad alta voce",
buttonLabel: "Pulsante di lettura ad alta voce",
buttonDescription: "Mostralo nelle risposte dell'assistente",
+ autoLabel: "Leggi le risposte automaticamente",
+ autoDescription: "Legge ad alta voce ogni risposta appena è completa",
engineLabel: "Motore TTS",
engineSystemDescription: "Voci integrate nel dispositivo",
engineStudioDescription: "Usa il modello vocale caricato in Audio",
diff --git a/studio/frontend/src/i18n/locales/ja.ts b/studio/frontend/src/i18n/locales/ja.ts
index d6b33da9a6d..92ee10e598f 100644
--- a/studio/frontend/src/i18n/locales/ja.ts
+++ b/studio/frontend/src/i18n/locales/ja.ts
@@ -1501,6 +1501,8 @@ export const ja = {
sectionTitle: "読み上げ",
buttonLabel: "読み上げボタン",
buttonDescription: "アシスタントの応答に表示します",
+ autoLabel: "応答を自動で読み上げ",
+ autoDescription: "応答が完了するとすぐに読み上げます",
engineLabel: "TTS エンジン",
engineSystemDescription: "デバイス内蔵の音声",
engineStudioDescription: "音声で読み込んだ音声合成モデルを使用します",
diff --git a/studio/frontend/src/i18n/locales/ko.ts b/studio/frontend/src/i18n/locales/ko.ts
index f603712fc85..926b7e14a1c 100644
--- a/studio/frontend/src/i18n/locales/ko.ts
+++ b/studio/frontend/src/i18n/locales/ko.ts
@@ -1498,6 +1498,8 @@ export const ko = {
sectionTitle: "답변 읽어주기",
buttonLabel: "답변 읽어주기 버튼",
buttonDescription: "어시스턴트 응답에 표시",
+ autoLabel: "답변 자동 읽어주기",
+ autoDescription: "답변이 끝나면 바로 소리 내어 읽습니다",
engineLabel: "TTS 엔진",
engineSystemDescription: "기기 내장 음성",
engineStudioDescription: "오디오에서 로드된 음성 모델을 사용합니다",
diff --git a/studio/frontend/src/i18n/locales/pt-br.ts b/studio/frontend/src/i18n/locales/pt-br.ts
index cd98e338264..08f725b366c 100644
--- a/studio/frontend/src/i18n/locales/pt-br.ts
+++ b/studio/frontend/src/i18n/locales/pt-br.ts
@@ -1503,6 +1503,8 @@ export const ptBR = {
sectionTitle: "Leitura em voz alta",
buttonLabel: "Botão de leitura em voz alta",
buttonDescription: "Exibe o botão nas respostas do assistente",
+ autoLabel: "Ler respostas automaticamente",
+ autoDescription: "Lê cada resposta em voz alta assim que ela termina",
engineLabel: "Mecanismo de TTS",
engineSystemDescription: "Vozes nativas do dispositivo",
engineStudioDescription: "Usa o modelo de fala carregado em Áudio",
diff --git a/studio/frontend/src/i18n/locales/ru.ts b/studio/frontend/src/i18n/locales/ru.ts
index 58ab0732faf..b73a68e0f12 100644
--- a/studio/frontend/src/i18n/locales/ru.ts
+++ b/studio/frontend/src/i18n/locales/ru.ts
@@ -1501,6 +1501,8 @@ export const ru = {
sectionTitle: "Чтение вслух",
buttonLabel: "Кнопка чтения вслух",
buttonDescription: "Показывать в ответах ассистента",
+ autoLabel: "Читать ответы автоматически",
+ autoDescription: "Читать каждый ответ вслух сразу после завершения",
engineLabel: "Движок TTS",
engineSystemDescription: "Встроенные голоса устройства",
engineStudioDescription: "Использует модель речи, загруженную в Аудио",
diff --git a/studio/frontend/src/i18n/locales/sv.ts b/studio/frontend/src/i18n/locales/sv.ts
index f4305bbe280..95183cd3e84 100644
--- a/studio/frontend/src/i18n/locales/sv.ts
+++ b/studio/frontend/src/i18n/locales/sv.ts
@@ -1634,6 +1634,8 @@ export const sv = {
sectionTitle: "Läs upp",
buttonLabel: "Knapp för uppläsning",
buttonDescription: "Visa på assistentsvar",
+ autoLabel: "Läs upp svar automatiskt",
+ autoDescription: "Läs upp varje svar så snart det är klart",
engineLabel: "TTS-motor",
engineSystemDescription: "Inbyggda enhetsröster",
engineStudioDescription:
diff --git a/studio/frontend/src/i18n/locales/zh-CN.ts b/studio/frontend/src/i18n/locales/zh-CN.ts
index 2b5c364656e..436326cf417 100644
--- a/studio/frontend/src/i18n/locales/zh-CN.ts
+++ b/studio/frontend/src/i18n/locales/zh-CN.ts
@@ -1489,6 +1489,8 @@ export const zhCN = {
sectionTitle: "朗读",
buttonLabel: "朗读按钮",
buttonDescription: "在助手回复上显示",
+ autoLabel: "自动朗读回复",
+ autoDescription: "每条回复完成后立即朗读",
engineLabel: "TTS 引擎",
engineSystemDescription: "设备内置语音",
engineStudioDescription: "使用在音频中加载的语音模型",
diff --git a/studio/frontend/tests/auto-read-aloud.test.ts b/studio/frontend/tests/auto-read-aloud.test.ts
new file mode 100644
index 00000000000..c910f09678b
--- /dev/null
+++ b/studio/frontend/tests/auto-read-aloud.test.ts
@@ -0,0 +1,92 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import {
+ type AutoReadMessage,
+ decideAutoRead,
+} from "../src/features/chat/utils/auto-read-aloud.ts";
+
+import { readSrc } from "./helpers/kit.ts";
+
+function reply(
+ status: string,
+ content: AutoReadMessage["content"] = [
+ { type: "text", text: "Hello there." },
+ ],
+): AutoReadMessage {
+ return { id: "a1", role: "assistant", status: { type: status }, content };
+}
+
+const user: AutoReadMessage = {
+ id: "u1",
+ role: "user",
+ content: [{ type: "text", text: "Hi" }],
+};
+
+test("a finished reply with text is spoken (#12303)", () => {
+ assert.deepEqual(decideAutoRead([user, reply("complete")]), {
+ kind: "speak",
+ messageId: "a1",
+ });
+});
+
+test("a reply still settling waits instead of being dropped", () => {
+ assert.deepEqual(decideAutoRead([user, reply("running")]), { kind: "wait" });
+});
+
+test("stopped, failed and tool-approval replies stay silent", () => {
+ for (const status of ["incomplete", "requires-action"]) {
+ assert.deepEqual(decideAutoRead([user, reply(status)]), { kind: "skip" });
+ }
+});
+
+test("a reply Studio marked cut off settles as complete but stays silent", () => {
+ for (const reason of [
+ "interrupted",
+ "length",
+ "cancelled",
+ "context_window",
+ ]) {
+ const cut = {
+ ...reply("complete"),
+ metadata: { custom: { incomplete: { reason } } },
+ };
+ assert.deepEqual(decideAutoRead([user, cut]), { kind: "skip" }, reason);
+ }
+});
+
+test("empty, reasoning-only and user-last threads stay silent", () => {
+ assert.deepEqual(decideAutoRead([]), { kind: "skip" });
+ assert.deepEqual(decideAutoRead([user]), { kind: "skip" });
+ assert.deepEqual(
+ decideAutoRead([
+ user,
+ reply("complete", [
+ { type: "reasoning", text: "thinking" },
+ { type: "text", text: " " },
+ ]),
+ ]),
+ { kind: "skip" },
+ );
+});
+
+test("auto read-aloud is opt-in and only a saved true turns it on", () => {
+ const store = readSrc("features/settings/stores/voice-settings-store.ts");
+ assert.match(store, /autoReadAloud: false,/);
+ assert.match(store, /autoReadAloud: saved\?\.autoReadAloud === true,/);
+});
+
+test("the thread mounts it only where a composer is shown, not in Compare panes", () => {
+ const thread = readSrc("components/assistant-ui/thread.tsx");
+ assert.match(thread, /\{!hideComposer && <AutoReadAloud \/>\}/);
+});
+
+test("a hidden chat stays silent and leaving a chat stops its own playback", () => {
+ const src = readSrc("components/assistant-ui/auto-read-aloud.tsx");
+ assert.match(src, /decision\.kind !== "speak" \|\| !active/);
+ assert.match(src, /threads\.getById\(\s*threadId,?\s*\)/);
+ assert.match(src, /speech\?\.messageId === spoken\)[\s\S]*stopSpeaking\(\)/);
+});