Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Mount the voice bundle in the app and let voice chat finish setup itself

Fei241154e85551a486
diff --git a/app/package-lock.json b/app/package-lock.json
index 988e6be6..e158d180 100644
--- a/app/package-lock.json
+++ b/app/package-lock.json
@@ -21,6 +21,7 @@
"@deepseek-ai/dsh-client-ui-slots": "0.2.1-rc.4",
"@deepseek-ai/dsh-compaction": "0.2.1-rc.4",
"@deepseek-ai/dsh-deepseek-account": "0.2.1-rc.4",
+ "@deepseek-ai/dsh-experimental-voice-input-bundle": "0.2.1-rc.4",
"@deepseek-ai/dsh-fs": "0.2.1-rc.4",
"@deepseek-ai/dsh-hook-protocol": "0.2.1-rc.4",
"@deepseek-ai/dsh-jobs": "0.2.1-rc.4",
diff --git a/app/package.json b/app/package.json
index 110ed474..c8de7c39 100644
--- a/app/package.json
+++ b/app/package.json
@@ -35,6 +35,7 @@
"@deepseek-ai/dsh-client-ui-slots": "0.2.1-rc.4",
"@deepseek-ai/dsh-compaction": "0.2.1-rc.4",
"@deepseek-ai/dsh-deepseek-account": "0.2.1-rc.4",
+ "@deepseek-ai/dsh-experimental-voice-input-bundle": "0.2.1-rc.4",
"@deepseek-ai/dsh-fs": "0.2.1-rc.4",
"@deepseek-ai/dsh-hook-protocol": "0.2.1-rc.4",
"@deepseek-ai/dsh-jobs": "0.2.1-rc.4",
diff --git a/app/src/profile.mjs b/app/src/profile.mjs
index 846a6b3e..8a054640 100644
--- a/app/src/profile.mjs
+++ b/app/src/profile.mjs
@@ -3,8 +3,9 @@ import { fileURLToPath } from 'node:url'
import { initProfile, loadProfileDirectory, readProfileManifest, resolveProfileDir, writeProfileBundles } from '@deepseek-ai/dsh-app-boot'
export const PROFILE = 'ds-bot'
-// DSH's shared core, DSH's web front end (the window), then the Bot team. Bundles the user installs follow.
-export const BUNDLES = ['@deepseek-ai/dsh-base', '@deepseek-ai/dsh-web-app', 'ds-bot']
+// DSH's shared core, DSH's web front end (the window) and voice input, then the Bot team.
+// Bundles the user installs follow.
+export const BUNDLES = ['@deepseek-ai/dsh-base', '@deepseek-ai/dsh-web-app', '@deepseek-ai/dsh-experimental-voice-input-bundle', 'ds-bot']
// The first-run check reads a copy of the team's chats without the Bot team running on them.
// DSH reads a log the same way whatever the profile mounts.
export const CHECK_PROFILE = 'import-check'
diff --git a/ds-bot/client.js b/ds-bot/client.js
index cc54a653..07736272 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -870,6 +870,9 @@ var ZH = {
"Recognizing…": "识别中…",
"Voice input needs its speech model": "语音输入还没有语音模型",
"Set up voice input": "设置语音输入",
+ "Preparing voice input…": "正在准备语音输入…",
+ "Downloading the speech model… {pct}%": "正在下载语音模型… {pct}%",
+ "Couldn't prepare voice input": "语音输入准备失败",
"That was too long to recognize": "这段太长了,识别不了",
// Usage page
"24 hours": "24 小时",
@@ -11107,6 +11110,14 @@ async function transcribeWave(speech, catalog, wave, signal) {
if (!result?.ok) throw Object.assign(new Error(result?.error?.message ?? "Transcription failed"), { kind: "service" });
return String(result.value?.text ?? "").trim();
}
+function closingReplyText(chat, turn) {
+ const location2 = chat?.timeline?.turns?.get(turn);
+ if (location2 === void 0) return void 0;
+ const closing = location2.data?.get("turn-tail")?.closing;
+ if (closing === void 0) return void 0;
+ if (closing === null) return "";
+ return (closing.blocks ?? []).filter((block) => block.kind === "text" && block.text.trim() !== "").map((block) => block.text).join("\n\n");
+}
function turnDetector({ loud = 0.12, quiet = 0.06, quietMs = 1200 } = {}) {
let spokeAt = 0;
let quietSince = 0;
@@ -14033,6 +14044,7 @@ var VOICE_LABELS = {
speaking: "Speaking",
paused: "Paused",
setup: "Voice input needs its speech model",
+ preparing: "Preparing voice input…",
unsupported: "Voice chat is not available in this browser"
};
var CAPTURE_NOTES = { blocked: "Microphone access is blocked", unavailable: "Voice chat is not available in this browser", "too-long": "That was too long to recognize" };
@@ -14086,7 +14098,7 @@ function VoiceMode({ sessionId, roster, actions, useSessions, useSessionStatus }
const lastReply = useSessions((list) => {
const outline = list.projectionsBySession?.[sessionId]?.values?.turnOutline ?? list.byId[sessionId]?.projectionValues?.turnOutline;
const entry = Array.isArray(outline) ? outline[outline.length - 1] : void 0;
- return entry ? `${outline.length}|${entry.response ?? ""}` : "0|";
+ return entry ? `${outline.length}|${entry.turn}` : "0|";
});
const [speech] = (0, import_react34.useState)(() => actions.speech());
const [phase, setPhase] = (0, import_react34.useState)(speech ? "starting" : speechApi() ? "listening" : "unsupported");
@@ -14211,30 +14223,49 @@ function VoiceMode({ sessionId, roster, actions, useSessions, useSessionStatus }
};
}, [speech, catalog, listen, cycle]);
(0, import_react34.useEffect)(() => {
- if (phase !== "thinking" || running || waiting.current === null) return;
- const [count, text] = [lastReply.slice(0, lastReply.indexOf("|")), lastReply.slice(lastReply.indexOf("|") + 1)];
- if (count === waiting.current || !text.trim()) return;
- waiting.current = null;
- const spoken = plainSpeech(text);
- setSaid(spoken);
- setHeard("");
- if (!window.speechSynthesis || !spoken) {
- setPhase("listening");
- return;
- }
- const utterance = new SpeechSynthesisUtterance(spoken);
- utterance.lang = /[\u3400-\u9fff]/.test(spoken) ? "zh-CN" : "en-US";
- utterance.onend = () => setPhase((current) => current === "speaking" ? "listening" : current);
- utterance.onerror = utterance.onend;
- setPhase("speaking");
- window.speechSynthesis.cancel();
- window.speechSynthesis.speak(utterance);
+ if (phase !== "thinking" || running || waiting.current === null) return void 0;
+ const count = lastReply.slice(0, lastReply.indexOf("|"));
+ const turn2 = Number(lastReply.slice(lastReply.indexOf("|") + 1));
+ if (count === waiting.current) return void 0;
+ const speak = (text) => {
+ waiting.current = null;
+ const spoken = plainSpeech(text);
+ setSaid(spoken);
+ setHeard("");
+ if (!window.speechSynthesis || !spoken) {
+ setPhase("listening");
+ return;
+ }
+ const utterance = new SpeechSynthesisUtterance(spoken);
+ utterance.lang = /[\u3400-\u9fff]/.test(spoken) ? "zh-CN" : "en-US";
+ utterance.onend = () => setPhase((current) => current === "speaking" ? "listening" : current);
+ utterance.onerror = utterance.onend;
+ setPhase("speaking");
+ window.speechSynthesis.cancel();
+ window.speechSynthesis.speak(utterance);
+ };
+ let off = () => {
+ };
+ const attempt = () => {
+ const text = actions.closingReply(sessionId, turn2);
+ if (text === void 0) return;
+ off();
+ if (text === null) {
+ waiting.current = null;
+ setPhase("listening");
+ return;
+ }
+ speak(text);
+ };
+ off = actions.watchTurns(sessionId, attempt);
+ attempt();
+ return () => off();
}, [phase, running, lastReply]);
(0, import_react34.useEffect)(() => () => window.speechSynthesis?.cancel(), []);
const micLevel = useMicLevel(!speech && phase === "listening" && dictation.listening);
const level = speech ? serviceLevel : micLevel;
const markState = phase === "thinking" || phase === "transcribing" ? "thinking" : phase === "speaking" ? "sending" : "idle";
- const blocked = phase === "unsupported" || phase === "setup" || phase === "starting";
+ const blocked = phase === "unsupported" || phase === "setup" || phase === "starting" || phase === "preparing";
const togglePause = () => {
if (phase === "paused") {
setPhase("listening");
@@ -14244,7 +14275,55 @@ function VoiceMode({ sessionId, roster, actions, useSessions, useSessionStatus }
window.speechSynthesis?.cancel();
setPhase("paused");
};
- const openSetup = phase === "setup" ? actions.voiceSetup() : null;
+ (0, import_react34.useEffect)(() => {
+ if (phase !== "preparing" || !speech) return void 0;
+ let stopped = false;
+ let timer;
+ const tick = async () => {
+ try {
+ const { catalog: next, usable } = await speechCatalog(speech);
+ if (stopped) return;
+ setCatalog(next);
+ if (usable) {
+ setPhase("listening");
+ return;
+ }
+ const provider = next.providers.find((item) => item.id === next.selection.providerId);
+ const preparation = provider?.preparation;
+ if (preparation?.phase === "failed") {
+ setPhase("setup");
+ setNote(t("Couldn't prepare voice input"));
+ return;
+ }
+ setNote(preparation?.phase === "downloading" && preparation.totalBytes ? t("Downloading the speech model… {pct}%", { pct: Math.floor(preparation.completedBytes / preparation.totalBytes * 100) }) : "");
+ } catch {
+ if (!stopped) {
+ setPhase("setup");
+ return;
+ }
+ }
+ timer = setTimeout(tick, 1500);
+ };
+ timer = setTimeout(tick, 800);
+ return () => {
+ stopped = true;
+ clearTimeout(timer);
+ };
+ }, [phase, speech]);
+ const openSetup = phase === "setup" ? actions.voiceSetup(catalog?.selection?.providerId) : null;
+ const startSetup = () => {
+ if (openSetup?.navigate) {
+ close();
+ openSetup.navigate();
+ return;
+ }
+ turn.current += 1;
+ setPhase("preparing");
+ void Promise.resolve(openSetup.prepare()).catch(() => {
+ setPhase("setup");
+ setNote(t("Couldn't prepare voice input"));
+ });
+ };
const caption = phase === "speaking" ? said : heard;
const shownNote = note || dictation.note;
return (0, import_react34.createElement)(
@@ -14267,10 +14346,7 @@ function VoiceMode({ sessionId, roster, actions, useSessions, useSessionStatus }
phase === "thinking" ? (0, import_react34.createElement)(Shimmer, null, t("Thinking…")) : phase === "transcribing" ? (0, import_react34.createElement)(Shimmer, null, t("Recognizing…")) : VOICE_LABELS[phase] ? t(VOICE_LABELS[phase]) : ""
),
(0, import_react34.createElement)("div", { className: "bt-voice-caption", key: `${phase}:${caption.slice(0, 12)}` }, caption),
- openSetup ? (0, import_react34.createElement)("button", { type: "button", className: "bt-voice-setup", onClick: () => {
- close();
- openSetup();
- } }, t("Set up voice input")) : null,
+ openSetup ? (0, import_react34.createElement)("button", { type: "button", className: "bt-voice-setup", onClick: startSetup }, t("Set up voice input")) : null,
shownNote ? (0, import_react34.createElement)("div", { className: "bt-voice-note" }, shownNote) : null
),
(0, import_react34.createElement)(
@@ -20859,9 +20935,20 @@ function apply(ctx) {
actions.speech = () => ctx.get("remote.speech") ?? void 0;
actions.openHarnessSettings = openHarnessSettings;
actions.openHarnessOnboarding = openHarnessOnboarding;
- actions.voiceSetup = () => {
+ actions.voiceSetup = (providerId) => {
const navigation = ctx.get("pluginNavigation");
- return navigation ? () => navigation.openBundle(VOICE_BUNDLE) : null;
+ if (navigation !== void 0) return { navigate: () => navigation.openBundle(VOICE_BUNDLE) };
+ const speech = ctx.get("remote.speech");
+ return speech === void 0 || providerId === void 0 ? null : { prepare: () => speech.prepare(providerId) };
+ };
+ actions.closingReply = (sessionId, turn) => {
+ try {
+ const binding = ctx.sessions.binding(sessionId);
+ if (binding === void 0) return null;
+ return closingReplyText(ctx.uiConversation.binding(binding).target("chat").getSnapshot(), turn);
+ } catch {
+ return null;
+ }
};
actions.seatAccount = (on) => ui2.set((state) => state.accountSeated === on ? state : { ...state, accountSeated: on });
actions.installUpdate = async () => {
diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.js
index 06962367..72cfaf15 100644
--- a/ds-bot/src/client/i18n.js
+++ b/ds-bot/src/client/i18n.js
@@ -822,6 +822,9 @@ const ZH = {
'Recognizing…': '识别中…',
'Voice input needs its speech model': '语音输入还没有语音模型',
'Set up voice input': '设置语音输入',
+ 'Preparing voice input…': '正在准备语音输入…',
+ 'Downloading the speech model… {pct}%': '正在下载语音模型… {pct}%',
+ "Couldn't prepare voice input": '语音输入准备失败',
'That was too long to recognize': '这段太长了,识别不了',
// Usage page
diff --git a/ds-bot/src/client/index.js b/ds-bot/src/client/index.js
index 31f66057..e481fb57 100644
--- a/ds-bot/src/client/index.js
+++ b/ds-bot/src/client/index.js
@@ -15,7 +15,7 @@ import { ComposerPlus, ComposerVoice, menuIcons } from './composer.js'
import { CHATS_SOURCE, atSources } from './at-menu.js'
import { BtwDock, BtwTurnTail } from './btw.js'
import { SIDE_CSS, sideSource } from './side-chat.js'
-import { VOICE_BUNDLE } from './speech.js'
+import { VOICE_BUNDLE, closingReplyText } from './speech.js'
import { sameVersion } from './dsh-offer.js'
import { QuestionCard, QuestionDock } from './questions.js'
import { AnsweredReply, WidgetDock, WIDGET_CSS } from './widget-cell.js'
@@ -633,9 +633,27 @@ export function apply(ctx) {
// DSH's own settings: models, providers, keys and its plugins.
actions.openHarnessSettings = openHarnessSettings
actions.openHarnessOnboarding = openHarnessOnboarding
- actions.voiceSetup = () => {
+ // With the plugin manager mounted, setup is its bundle page (the model's size
+ // and download notes live there). Where it is not mounted — the desktop app's
+ // profile has no plugin manager — the speech Remote prepares the provider
+ // itself, and the voice pane follows its progress.
+ actions.voiceSetup = (providerId) => {
const navigation = ctx.get('pluginNavigation')
- return navigation ? () => navigation.openBundle(VOICE_BUNDLE) : null
+ if (navigation !== undefined) return { navigate: () => navigation.openBundle(VOICE_BUNDLE) }
+ const speech = ctx.get('remote.speech')
+ return speech === undefined || providerId === undefined ? null : { prepare: () => speech.prepare(providerId) }
+ }
+ // The full text the voice chat reads aloud: the turn's closing Assistant
+ // message, not the turn outline's bounded preview. undefined while the chat
+ // view has not materialized the turn; null when the Session is not bound.
+ actions.closingReply = (sessionId, turn) => {
+ try {
+ const binding = ctx.sessions.binding(sessionId)
+ if (binding === undefined) return null
+ return closingReplyText(ctx.uiConversation.binding(binding).target('chat').getSnapshot(), turn)
+ } catch {
+ return null
+ }
}
actions.seatAccount = on => ui.set(state => (state.accountSeated === on ? state : { ...state, accountSeated: on }))
// The install runs on the host; the check loop follows it every two seconds.
diff --git a/ds-bot/src/client/speech.js b/ds-bot/src/client/speech.js
index bd9b7efc..91821ff2 100644
--- a/ds-bot/src/client/speech.js
+++ b/ds-bot/src/client/speech.js
@@ -107,6 +107,18 @@ export async function transcribeWave(speech, catalog, wave, signal) {
return String(result.value?.text ?? '').trim()
}
+// The full closing Assistant text of a finished turn: what voice chat speaks.
+// undefined while the chat view has not materialized the turn; '' when the turn
+// closed without assistant text.
+export function closingReplyText(chat, turn) {
+ const location = chat?.timeline?.turns?.get(turn)
+ if (location === undefined) return undefined
+ const closing = location.data?.get('turn-tail')?.closing
+ if (closing === undefined) return undefined
+ if (closing === null) return ''
+ return (closing.blocks ?? []).filter(block => block.kind === 'text' && block.text.trim() !== '').map(block => block.text).join('\n\n')
+}
+
// Voice activity on the loudness of each animation frame: speech starts above
// `loud`, and the turn ends after `quietMs` below `quiet`.
export function turnDetector({ loud = 0.12, quiet = 0.06, quietMs = 1200 } = {}) {
diff --git a/ds-bot/src/client/voice.js b/ds-bot/src/client/voice.js
index d68e6b6f..39a67938 100644
--- a/ds-bot/src/client/voice.js
+++ b/ds-bot/src/client/voice.js
@@ -15,7 +15,8 @@ import { openCapture, speechCatalog, transcribeWave, turnDetector } from './spee
const plainSpeech = text => stripHeader(text).replace(/```[\s\S]*?```/g, ' ').replace(/\[([^\]]*)\]\([^)]*\)/g, '$1').replace(/[*_`#>|~-]+/g, ' ').replace(/\s+/g, ' ').trim()
const VOICE_LABELS = {
listening: 'Listening', thinking: 'Thinking', speaking: 'Speaking', paused: 'Paused',
- setup: 'Voice input needs its speech model', unsupported: 'Voice chat is not available in this browser',
+ setup: 'Voice input needs its speech model', preparing: 'Preparing voice input…',
+ unsupported: 'Voice chat is not available in this browser',
}
const CAPTURE_NOTES = { blocked: 'Microphone access is blocked', unavailable: 'Voice chat is not available in this browser', 'too-long': 'That was too long to recognize' }
@@ -65,7 +66,7 @@ export function VoiceMode({ sessionId, roster, actions, useSessions, useSessionS
const lastReply = useSessions((list) => {
const outline = list.projectionsBySession?.[sessionId]?.values?.turnOutline ?? list.byId[sessionId]?.projectionValues?.turnOutline
const entry = Array.isArray(outline) ? outline[outline.length - 1] : undefined
- return entry ? `${outline.length}|${entry.response ?? ''}` : '0|'
+ return entry ? `${outline.length}|${entry.turn}` : '0|'
})
// The Voice Input plugin's Remote, read once: the engine does not change mid-chat.
const [speech] = useState(() => actions.speech())
@@ -180,34 +181,81 @@ export function VoiceMode({ sessionId, roster, actions, useSessions, useSessionS
}
}, [speech, catalog, listen, cycle])
useEffect(() => {
- if (phase !== 'thinking' || running || waiting.current === null) return
- const [count, text] = [lastReply.slice(0, lastReply.indexOf('|')), lastReply.slice(lastReply.indexOf('|') + 1)]
- if (count === waiting.current || !text.trim()) return
- waiting.current = null
- const spoken = plainSpeech(text)
- setSaid(spoken)
- setHeard('')
- if (!window.speechSynthesis || !spoken) { setPhase('listening'); return }
- const utterance = new SpeechSynthesisUtterance(spoken)
- utterance.lang = /[\u3400-\u9fff]/.test(spoken) ? 'zh-CN' : 'en-US'
- utterance.onend = () => setPhase(current => (current === 'speaking' ? 'listening' : current))
- utterance.onerror = utterance.onend
- setPhase('speaking')
- window.speechSynthesis.cancel()
- window.speechSynthesis.speak(utterance)
+ if (phase !== 'thinking' || running || waiting.current === null) return undefined
+ const count = lastReply.slice(0, lastReply.indexOf('|'))
+ const turn = Number(lastReply.slice(lastReply.indexOf('|') + 1))
+ if (count === waiting.current) return undefined
+ const speak = (text) => {
+ waiting.current = null
+ const spoken = plainSpeech(text)
+ setSaid(spoken)
+ setHeard('')
+ if (!window.speechSynthesis || !spoken) { setPhase('listening'); return }
+ const utterance = new SpeechSynthesisUtterance(spoken)
+ utterance.lang = /[\u3400-\u9fff]/.test(spoken) ? 'zh-CN' : 'en-US'
+ utterance.onend = () => setPhase(current => (current === 'speaking' ? 'listening' : current))
+ utterance.onerror = utterance.onend
+ setPhase('speaking')
+ window.speechSynthesis.cancel()
+ window.speechSynthesis.speak(utterance)
+ }
+ // The outline commits at turn/end but only holds a bounded preview; the
+ // closing Assistant text can trail it, so the answer is read through the
+ // chat view's own changes until it lands (or the Session goes away).
+ let off = () => {}
+ const attempt = () => {
+ const text = actions.closingReply(sessionId, turn)
+ if (text === undefined) return
+ off()
+ if (text === null) { waiting.current = null; setPhase('listening'); return }
+ speak(text)
+ }
+ off = actions.watchTurns(sessionId, attempt)
+ attempt()
+ return () => off()
}, [phase, running, lastReply])
useEffect(() => () => window.speechSynthesis?.cancel(), [])
const micLevel = useMicLevel(!speech && phase === 'listening' && dictation.listening)
const level = speech ? serviceLevel : micLevel
const markState = phase === 'thinking' || phase === 'transcribing' ? 'thinking' : phase === 'speaking' ? 'sending' : 'idle'
- const blocked = phase === 'unsupported' || phase === 'setup' || phase === 'starting'
+ const blocked = phase === 'unsupported' || phase === 'setup' || phase === 'starting' || phase === 'preparing'
const togglePause = () => {
if (phase === 'paused') { setPhase('listening'); return }
turn.current += 1
window.speechSynthesis?.cancel()
setPhase('paused')
}
- const openSetup = phase === 'setup' ? actions.voiceSetup() : null
+ // A 'preparing' phase follows the speech Remote's own catalog until the
+ // provider is usable; the plugin-manager path navigates away instead.
+ useEffect(() => {
+ if (phase !== 'preparing' || !speech) return undefined
+ let stopped = false
+ let timer
+ const tick = async () => {
+ try {
+ const { catalog: next, usable } = await speechCatalog(speech)
+ if (stopped) return
+ setCatalog(next)
+ if (usable) { setPhase('listening'); return }
+ const provider = next.providers.find(item => item.id === next.selection.providerId)
+ const preparation = provider?.preparation
+ if (preparation?.phase === 'failed') { setPhase('setup'); setNote(t("Couldn't prepare voice input")); return }
+ setNote(preparation?.phase === 'downloading' && preparation.totalBytes
+ ? t('Downloading the speech model… {pct}%', { pct: Math.floor((preparation.completedBytes / preparation.totalBytes) * 100) })
+ : '')
+ } catch { if (!stopped) { setPhase('setup'); return } }
+ timer = setTimeout(tick, 1500)
+ }
+ timer = setTimeout(tick, 800)
+ return () => { stopped = true; clearTimeout(timer) }
+ }, [phase, speech])
+ const openSetup = phase === 'setup' ? actions.voiceSetup(catalog?.selection?.providerId) : null
+ const startSetup = () => {
+ if (openSetup?.navigate) { close(); openSetup.navigate(); return }
+ turn.current += 1
+ setPhase('preparing')
+ void Promise.resolve(openSetup.prepare()).catch(() => { setPhase('setup'); setNote(t("Couldn't prepare voice input")) })
+ }
const caption = phase === 'speaking' ? said : heard
const shownNote = note || dictation.note
return h('div', { className: 'bt-pane bt-voice-pane', style: { left: paneLeft } },
@@ -222,7 +270,7 @@ export function VoiceMode({ sessionId, roster, actions, useSessions, useSessionS
: phase === 'transcribing' ? h(Shimmer, null, t('Recognizing…'))
: VOICE_LABELS[phase] ? t(VOICE_LABELS[phase]) : ''),
h('div', { className: 'bt-voice-caption', key: `${phase}:${caption.slice(0, 12)}` }, caption),
- openSetup ? h('button', { type: 'button', className: 'bt-voice-setup', onClick: () => { close(); openSetup() } }, t('Set up voice input')) : null,
+ openSetup ? h('button', { type: 'button', className: 'bt-voice-setup', onClick: startSetup }, t('Set up voice input')) : null,
shownNote ? h('div', { className: 'bt-voice-note' }, shownNote) : null),
h('div', { className: 'bt-voice-bar' },
h('button', {
diff --git a/ds-bot/test/speech.test.js b/ds-bot/test/speech.test.js
index b0d6b156..8de176b4 100644
--- a/ds-bot/test/speech.test.js
+++ b/ds-bot/test/speech.test.js
@@ -1,6 +1,6 @@
import { test } from 'node:test'
import assert from 'node:assert/strict'
-import { base64Of, speechCatalog, transcribeWave, turnDetector, waveBytes } from '../src/client/speech.js'
+import { base64Of, closingReplyText, speechCatalog, transcribeWave, turnDetector, waveBytes } from '../src/client/speech.js'
const catalog = (phase, extra = {}) => ({
providers: [{ id: 'sensevoice', preparation: { phase } }],
@@ -52,6 +52,22 @@ test('transcribeWave rejects audio over the limit and service failures', async (
await assert.rejects(transcribeWave(speech, catalog('ready'), new Uint8Array(10)), error => error.kind === 'service')
})
+test('closingReplyText reads the full closing text, not the preview', () => {
+ const tail = (closing) => ({ data: { get: key => (key === 'turn-tail' ? { closing } : undefined) } })
+ const chat = (...turns) => ({ timeline: { turns: new Map(turns) } })
+ const full = 'The whole answer. '.repeat(300)
+ assert.equal(closingReplyText(chat([3, tail({ blocks: [{ kind: 'text', text: full }] })]), 3), full)
+ assert.equal(closingReplyText(chat([3, tail({ blocks: [{ kind: 'text', text: 'a' }, { kind: 'tool' }, { kind: 'text', text: 'b' }] })]), 3), 'a\n\nb')
+ // Not materialized yet: the voice pane waits for the view's next change.
+ assert.equal(closingReplyText(chat([3, tail(undefined)]), 3), undefined)
+ assert.equal(closingReplyText(chat([2, tail({ blocks: [{ kind: 'text', text: 'older' }] })]), 3), undefined)
+ assert.equal(closingReplyText(undefined, 3), undefined)
+ assert.equal(closingReplyText(chat(), 3), undefined)
+ // A turn that closed with no Assistant text goes back to listening silently.
+ assert.equal(closingReplyText(chat([3, tail(null)]), 3), '')
+ assert.equal(closingReplyText(chat([3, tail({ blocks: [] })]), 3), '')
+})
+
test('turnDetector ends a turn after a pause that follows speech', () => {
const detect = turnDetector({ loud: 0.1, quiet: 0.05, quietMs: 1000 })
assert.equal(detect(0.01, 0), 'waiting')