@burdenoff/microfe-healthybowl 2026.901.16 → 2026.901.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/assistant/voice/AssistantVoiceSession.js +25 -19
- package/dist/components/assistant/voice/AssistantVoiceSession.js.map +1 -1
- package/dist/components/assistant/voice/VoiceCaption.js +2 -2
- package/dist/components/assistant/voice/VoiceCaption.js.map +1 -1
- package/dist/components/assistant/voice/VoiceStage.js +1 -1
- package/dist/components/assistant/voice/VoiceStage.js.map +1 -1
- package/package.json +1 -1
|
@@ -35,13 +35,13 @@ var _ = ({ session: _, turns: b = [], notice: x = null, spoken: S, onInterrupt:
|
|
|
35
35
|
L,
|
|
36
36
|
B
|
|
37
37
|
]);
|
|
38
|
-
let H = t(_),
|
|
38
|
+
let H = x !== null && M === null, U = t(_), W = i({
|
|
39
39
|
snapshot: _,
|
|
40
40
|
capturing: E,
|
|
41
41
|
interrupting: D,
|
|
42
42
|
awaitingEndpoint: O
|
|
43
|
-
}),
|
|
44
|
-
switch (
|
|
43
|
+
}), G = (() => {
|
|
44
|
+
switch (W) {
|
|
45
45
|
case "connecting": return k("healthybowl.assistant.voiceSession.connecting", "Starting the microphone…");
|
|
46
46
|
case "endpoint-grace": return k("healthybowl.assistant.voiceSession.endpointGrace", "Still listening — take your time");
|
|
47
47
|
case "interrupting": return k("healthybowl.assistant.voiceSession.interrupting", "Stopped — go ahead");
|
|
@@ -50,9 +50,9 @@ var _ = ({ session: _, turns: b = [], notice: x = null, spoken: S, onInterrupt:
|
|
|
50
50
|
case "mic-error":
|
|
51
51
|
case "ended": return "";
|
|
52
52
|
case "listening": return j ? k("healthybowl.assistant.voiceSession.muted", "Microphone off") : k("healthybowl.assistant.voiceSession.listening", "Listening…");
|
|
53
|
-
default: return
|
|
53
|
+
default: return W;
|
|
54
54
|
}
|
|
55
|
-
})(),
|
|
55
|
+
})(), K = j && W !== "listening" && G !== "" ? `${G} · ${k("healthybowl.assistant.voiceSession.muted", "Microphone off")}` : G;
|
|
56
56
|
return /* @__PURE__ */ g("div", {
|
|
57
57
|
ref: P,
|
|
58
58
|
className: `flex flex-col items-center justify-between bg-bg-sunken ${F === "full" ? "fixed inset-x-0 bottom-0 top-14 z-[60] px-6 py-8" : F === "panel" ? "absolute inset-0 z-20 px-4 py-6" : "absolute inset-x-0 bottom-0 z-20 h-[11.25rem] border-t border-border-subtle px-3 py-3 shadow-lg"}`,
|
|
@@ -61,18 +61,24 @@ var _ = ({ session: _, turns: b = [], notice: x = null, spoken: S, onInterrupt:
|
|
|
61
61
|
"aria-label": k("healthybowl.assistant.voiceSession.title", "Voice conversation"),
|
|
62
62
|
"data-testid": "assistant-voice-session",
|
|
63
63
|
children: [
|
|
64
|
-
/* @__PURE__ */
|
|
64
|
+
/* @__PURE__ */ g("button", {
|
|
65
65
|
ref: N,
|
|
66
66
|
type: "button",
|
|
67
67
|
onClick: T,
|
|
68
|
-
className: `absolute ${L ? "right-6 top-6
|
|
69
|
-
"aria-label": k("healthybowl.assistant.voiceSession.end", "End the voice conversation"),
|
|
68
|
+
className: `absolute ${L ? "right-6 top-6 h-14 gap-2 px-5 text-base" : R ? "right-2 top-2 size-8" : "right-3 top-3 h-11 gap-2 px-4 text-sm"} flex items-center justify-center rounded-full border border-border-default bg-bg-elevated text-text-secondary hover:bg-bg-sunken transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong`,
|
|
69
|
+
"aria-label": R ? k("healthybowl.assistant.voiceSession.end", "End the voice conversation") : void 0,
|
|
70
70
|
"data-testid": "assistant-voice-end",
|
|
71
|
-
children: /* @__PURE__ */ h(m, {
|
|
71
|
+
children: [/* @__PURE__ */ h(m, {
|
|
72
|
+
className: L ? "size-6" : R ? "size-4" : "size-5",
|
|
73
|
+
"aria-hidden": "true"
|
|
74
|
+
}), R ? null : /* @__PURE__ */ h("span", {
|
|
75
|
+
className: "max-w-[7rem] truncate whitespace-nowrap font-medium",
|
|
76
|
+
children: k("healthybowl.assistant.voiceSession.endShort", "End")
|
|
77
|
+
})]
|
|
72
78
|
}),
|
|
73
79
|
/* @__PURE__ */ h("div", {
|
|
74
|
-
className: `flex flex-col items-center ${R ? "px-3" :
|
|
75
|
-
children:
|
|
80
|
+
className: `flex flex-col items-center ${R ? "px-3" : `min-h-[1.5rem] ${H ? L ? "pt-14" : "pt-10" : ""}`}`,
|
|
81
|
+
children: H ? /* @__PURE__ */ h("p", {
|
|
76
82
|
className: "max-w-xs text-center text-xs text-status-warning",
|
|
77
83
|
"data-testid": "assistant-voice-notice",
|
|
78
84
|
children: v(x, k)
|
|
@@ -82,21 +88,21 @@ var _ = ({ session: _, turns: b = [], notice: x = null, spoken: S, onInterrupt:
|
|
|
82
88
|
let e = /* @__PURE__ */ h(n, {
|
|
83
89
|
session: _,
|
|
84
90
|
compact: R,
|
|
85
|
-
onPress: r(
|
|
86
|
-
label: r(
|
|
87
|
-
}), t = r(
|
|
91
|
+
onPress: r(W) ? C : w,
|
|
92
|
+
label: r(W) ? k("healthybowl.assistant.voiceSession.interrupt", "Stop the assistant and speak") : j ? k("healthybowl.assistant.voiceSession.unmute", "Turn the microphone on") : k("healthybowl.assistant.voiceSession.mute", "Turn the microphone off")
|
|
93
|
+
}), t = r(W) ? S : U || null, i = M === null ? null : y(M, k);
|
|
88
94
|
return R ? /* @__PURE__ */ h(o, {
|
|
89
|
-
state:
|
|
95
|
+
state: W,
|
|
90
96
|
caption: t,
|
|
91
|
-
statusText:
|
|
97
|
+
statusText: K,
|
|
92
98
|
errorText: i,
|
|
93
99
|
control: e
|
|
94
100
|
}) : /* @__PURE__ */ h(a, {
|
|
95
|
-
state:
|
|
96
|
-
userCaption:
|
|
101
|
+
state: W,
|
|
102
|
+
userCaption: U || null,
|
|
97
103
|
assistantCaption: S,
|
|
98
104
|
expanded: L,
|
|
99
|
-
statusText:
|
|
105
|
+
statusText: K,
|
|
100
106
|
errorText: i,
|
|
101
107
|
control: e
|
|
102
108
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssistantVoiceSession.js","names":[],"sources":["../../../../src/components/assistant/voice/AssistantVoiceSession.tsx"],"sourcesContent":["import { useEffect, useRef, useState, type FC } from 'react';\nimport { Maximize2, Minimize2, ScrollText, X } from 'lucide-react';\nimport { AssistantVoiceOrb } from './AssistantVoiceOrb';\nimport { VoiceStage } from './VoiceStage';\nimport { VoiceMiniController } from './VoiceMiniController';\nimport { VoiceTranscriptDrawer } from './VoiceTranscriptDrawer';\nimport { voiceStageState, micIsInterrupt } from '../../../utils/voiceStageState';\nimport { useTr } from '../../../shared/hooks/useTr';\nimport { spokenSoFar, type VoiceSessionSnapshot } from '../../../utils/voiceSession';\nimport type { VoiceSessionError } from '../../../utils/voiceSession';\nimport type { VoiceSessionNotice } from '../../../hooks/useVoiceSession';\n\n/** How much room the voice session takes: a strip, the panel, or the screen. */\nexport type VoiceView = 'mini' | 'panel' | 'full';\n\ninterface Props {\n session: VoiceSessionSnapshot;\n /** Recent exchanges, oldest first — the running conversation. */\n turns?: ReadonlyArray<{ id: string; role: 'user' | 'assistant'; text: string }>;\n /** Cut the assistant off mid-reply. */\n onInterrupt?: () => void;\n /** A recoverable problem to surface. Null when the microphone is healthy. */\n notice?: VoiceSessionNotice | null;\n /** The assistant's last reply, captioned while it is spoken. */\n spoken: string | null;\n onToggleMute: () => void;\n onEnd: () => void;\n /** Is the recogniser actually running? Distinguishes CONNECTING from LISTENING. */\n capturing?: boolean;\n /** The user has cut the assistant off and capture has not resumed yet. */\n interrupting?: boolean;\n /** Quiet has fallen and the two-second correction window is running. */\n awaitingEndpoint?: boolean;\n}\n\n/**\n * Full-screen voice conversation (BOFF-7120).\n *\n * ★ **Voice only, by explicit product decision.** The reference (Gemini Live)\n * also offers camera and screen sharing; those are deliberately absent here.\n * Attaching images is a separate, existing capability of the assistant and\n * stays in the composer, and screen sharing could not work on the primary\n * device anyway — `getDisplayMedia` is unsupported by every iOS browser, so\n * that control would be dead on an iPhone.\n *\n * The controls are therefore the two that a voice conversation actually needs:\n * mute, and end. Anything else would be a button the user has to think about\n * while talking.\n *\n * This component is presentational: every transition is owned by\n * `voiceSessionReducer`, which is pure and tested. That split exists because\n * this file cannot be tested at all in this repo — vitest runs in `node` with\n * no DOM and no audio.\n */\nexport const AssistantVoiceSession: FC<Props> = ({\n session,\n turns = [],\n notice = null,\n spoken,\n onInterrupt,\n onToggleMute,\n onEnd,\n capturing = true,\n interrupting = false,\n awaitingEndpoint = false,\n}) => {\n const tr = useTr();\n const { phase, muted, error } = session;\n const endRef = useRef<HTMLButtonElement>(null);\n const dialogRef = useRef<HTMLDivElement>(null);\n /**\n * Docked inside the assistant panel by default; full-screen only on request.\n *\n * A voice conversation is usually a glance-and-listen thing, so taking over\n * the whole screen for it is the wrong default — the user loses the page they\n * were asking about. Expanding is opt-in and per-session: reopening starts\n * docked again, which is the behaviour that matches \"default should be the\n * same size as the assistant\".\n */\n /**\n * ★ THREE sizes, not two.\n *\n * The compact controller was added so voice stops taking over the panel — but\n * making it the only docked size removed the in-panel stage that existed\n * before, which is a genuinely useful middle: big enough to read a reply,\n * without losing the page behind it.\n *\n * mini — a strip at the bottom; the assistant panel stays visible\n * panel — fills the assistant panel (what \"docked\" used to mean)\n * full — full screen\n *\n * One button steps mini → panel → full and wraps, with the label always\n * naming where it goes next, so a single control stays predictable.\n */\n const [view, setView] = useState<VoiceView>('mini');\n const expanded = view === 'full';\n const mini = view === 'mini';\n const nextView: VoiceView = view === 'mini' ? 'panel' : view === 'panel' ? 'full' : 'mini';\n /** History is secondary: the stage shows now, this shows the session. */\n const [transcriptOpen, setTranscriptOpen] = useState(false);\n\n // A full-screen `aria-modal` overlay that cannot be dismissed from the\n // keyboard is a trap. Escape ends the session, and focus starts on End so a\n // keyboard or screen-reader user lands somewhere useful rather than behind\n // the overlay.\n // Focus lands on End ONCE, on open. Keeping this in the keydown effect below\n // meant every expand/collapse re-ran it and silently stole focus from the\n // button just pressed — a Space or Enter a beat later would then end the\n // session instead of toggling the size again.\n useEffect(() => {\n endRef.current?.focus();\n }, []);\n\n useEffect(() => {\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n // ★ Escape closes the drawer first. Ending the whole conversation\n // because someone dismissed a panel would be a surprising amount of\n // destruction for one keypress.\n if (transcriptOpen) {\n setTranscriptOpen(false);\n return;\n }\n onEnd();\n return;\n }\n // Trapping focus is only correct when the overlay actually covers\n // everything. Docked, it sits inside the panel and the rest of the page\n // is legitimately reachable, so trapping there would be the bug rather\n // than the fix.\n if (event.key !== 'Tab' || !expanded) return;\n // `aria-modal` only TELLS assistive technology this is modal; it does not\n // make it so. Without this, Tab walks straight out of the overlay into the\n // page behind it, which is still fully interactive underneath — a\n // keyboard user ends up operating a screen they cannot see.\n // ★ Scope the trap to what is actually on screen. With the transcript\n // drawer open, a flat `button` query also collects the controls it covers,\n // so Tab walked into buttons the user could not see — the same class of\n // bug the trap exists to prevent.\n const scope = transcriptOpen\n ? dialogRef.current?.querySelector<HTMLElement>('[data-testid=\"assistant-voice-transcript\"]')\n : dialogRef.current;\n const focusable = scope?.querySelectorAll<HTMLElement>('button:not([disabled])');\n if (!focusable || focusable.length === 0) return;\n const first = focusable[0];\n const last = focusable[focusable.length - 1];\n if (!first || !last) return;\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && document.activeElement === last) {\n event.preventDefault();\n first.focus();\n }\n };\n window.addEventListener('keydown', onKeyDown);\n return () => window.removeEventListener('keydown', onKeyDown);\n }, [onEnd, expanded, transcriptOpen]);\n\n // While speaking, the caption shows the REPLY; otherwise what we have heard.\n // Showing the stale transcript under the assistant's own voice reads as a\n // mis-transcription of the assistant, which is worse than showing nothing.\n const heard = spokenSoFar(session);\n\n // ★ ONE state, derived. The reducer's phase cannot tell \"listening\" from\n // \"the microphone has not started yet\", and the old overlay rendered every\n // signal at once — status, warning, transcript, caption and orb together.\n // ★ Both signals were accepted by `voiceStageState` and passed by nobody, so\n // `endpoint-grace` and `interrupting` were unreachable branches.\n const stage = voiceStageState({ snapshot: session, capturing, interrupting, awaitingEndpoint });\n\n /**\n * The label for the STAGE, not for the phase.\n *\n * ★ This used to read `phase`, which is why three derived stages were\n * invisible even once they were reachable: `connecting`, `endpoint-grace` and\n * `interrupting` are all `phase === 'listening'` underneath, so every one of\n * them said \"Listening…\". The stage exists precisely because the phase cannot\n * make these distinctions — deriving the caption from the phase threw that\n * away again, and told the user we were listening before the recogniser had\n * started, the exact lie `voiceStageState` was written to stop.\n */\n const stageText = (() => {\n switch (stage) {\n case 'connecting':\n return tr('healthybowl.assistant.voiceSession.connecting', 'Starting the microphone…');\n case 'endpoint-grace':\n // Reads as an invitation, not a countdown: the window exists so the\n // user can still correct themselves, and hurrying them defeats it.\n return tr('healthybowl.assistant.voiceSession.endpointGrace', 'Still listening — take your time');\n case 'interrupting':\n return tr('healthybowl.assistant.voiceSession.interrupting', 'Stopped — go ahead');\n case 'thinking':\n return tr('healthybowl.assistant.voiceSession.thinking', 'Thinking…');\n case 'speaking':\n return tr('healthybowl.assistant.voiceSession.speaking', 'Speaking — tap to stop');\n case 'mic-error':\n case 'ended':\n // Owned by the error branch of the stage, which gets it to itself.\n return '';\n case 'listening':\n return muted\n ? tr('healthybowl.assistant.voiceSession.muted', 'Microphone off')\n : tr('healthybowl.assistant.voiceSession.listening', 'Listening…');\n default: {\n // ★ Exhaustive on purpose, matching `errorMessage` and `noticeMessage`\n // below. A stage with no copy is the exact bug this change fixes, so a\n // new one without a label must fail the BUILD rather than silently\n // inherit \"Listening…\" the way three of them already did.\n const unhandled: never = stage;\n return unhandled;\n }\n }\n })();\n\n // Muted is reported ALONGSIDE the stage, not instead of it: the assistant may\n // still be speaking with the microphone off, and saying only \"Microphone off\"\n // would misreport that.\n //\n // ★ Gated on the STAGE, not the phase. `connecting`, `endpoint-grace` and\n // `interrupting` are all `phase === 'listening'` underneath, so a phase test\n // dropped the suffix on exactly the three stages this change introduced —\n // leaving \"Stopped — go ahead\" inviting someone to speak into a muted\n // microphone. The `!== ''` guard keeps ended/mic-error from rendering a bare\n // \" · Microphone off\".\n //\n // ★ No `error !== null` arm: `stageText` is already '' for `mic-error`, and\n // the message itself belongs to the stage's alert element. Testing the error\n // here printed the whole sentence TWICE on the one screen this change exists\n // to make visible — truncated in the status line, repeated below it, and\n // announced twice by a screen reader.\n const status =\n muted && stage !== 'listening' && stageText !== ''\n ? `${stageText} · ${tr('healthybowl.assistant.voiceSession.muted', 'Microphone off')}`\n : stageText;\n\n return (\n <div\n ref={dialogRef}\n className={`flex flex-col items-center justify-between bg-bg-sunken ${\n view === 'full'\n ? // ★ Below the app header, not behind it. The header is `z-[100]` and\n // this overlay was `z-[60]` at `inset-0`, so the top 56px sat behind\n // it — and the End button did not merely LOOK hidden, it was\n // unclickable (`elementFromPoint` returned the header). Starting at\n // `top-14` means nothing is ever behind the header, and the header\n // stays usable for orientation.\n 'fixed inset-x-0 bottom-0 top-14 z-[60] px-6 py-8'\n : view === 'panel'\n ? // The in-panel stage: covers the assistant panel, keeps the page.\n 'absolute inset-0 z-20 px-4 py-6'\n : // A strip at the bottom, ~180px, so the panel behind stays visible.\n 'absolute inset-x-0 bottom-0 z-20 h-[11.25rem] border-t border-border-subtle px-3 py-3 shadow-lg'\n }`}\n role=\"dialog\"\n // Only modal when it really is: docked, the page behind stays usable.\n // `undefined` rather than `false` — the ARIA default is already false, and\n // some older assistive technology treats an explicit \"false\" on a dialog\n // as still modal.\n aria-modal={expanded || undefined}\n aria-label={tr('healthybowl.assistant.voiceSession.title', 'Voice conversation')}\n data-testid=\"assistant-voice-session\"\n >\n {/* End sits top-right and expand bottom-left, out of the centre column.\n Absolute rather than part of the flow so the pill stays optically\n centred at both sizes — the overlay is already a positioning context\n (`fixed` when expanded, `absolute` when docked). */}\n <button\n ref={endRef}\n type=\"button\"\n onClick={onEnd}\n className={`absolute ${expanded ? 'right-6 top-6 size-14' : mini ? 'right-2 top-2 size-8' : 'right-3 top-3 size-11'} flex items-center justify-center rounded-full border border-border-default bg-bg-elevated text-text-secondary hover:bg-bg-sunken transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong`}\n aria-label={tr('healthybowl.assistant.voiceSession.end', 'End the voice conversation')}\n data-testid=\"assistant-voice-end\"\n >\n <X className={expanded ? 'size-6' : mini ? 'size-4' : 'size-5'} />\n </button>\n\n {/* ★ The notice is CHROME, not conversation. It used to sit above the\n transcript in the same column as the reply, which is why a microphone\n warning read as part of what the assistant said. The status line moved\n into the stage, where it labels the state it belongs to. */}\n <div className={`flex flex-col items-center ${mini ? 'px-3' : 'min-h-[1.5rem] px-14'}`}>\n {notice && error === null ? (\n <p className=\"max-w-xs text-center text-xs text-status-warning\" data-testid=\"assistant-voice-notice\">\n {noticeMessage(notice, tr)}\n </p>\n ) : null}\n </div>\n\n {/* ★ Two genuinely different surfaces, not one scaled. Expanded is a\n reading stage; docked is a controller. */}\n {(() => {\n const orb = (\n <AssistantVoiceOrb\n session={session}\n compact={mini}\n onPress={micIsInterrupt(stage) ? onInterrupt : onToggleMute}\n label={\n micIsInterrupt(stage)\n ? tr('healthybowl.assistant.voiceSession.interrupt', 'Stop the assistant and speak')\n : muted\n ? tr('healthybowl.assistant.voiceSession.unmute', 'Turn the microphone on')\n : tr('healthybowl.assistant.voiceSession.mute', 'Turn the microphone off')\n }\n />\n );\n const caption = micIsInterrupt(stage) ? spoken : heard || null;\n const errorText = error !== null ? errorMessage(error, tr) : null;\n return !mini ? (\n <VoiceStage\n state={stage}\n userCaption={heard || null}\n assistantCaption={spoken}\n // ★ `expanded` — the JSX shorthand — means `expanded={true}`, not\n // `expanded={expanded}`. This branch serves BOTH the docked panel and\n // full screen, so the panel was being styled as full screen: the\n // 34rem measure and the 24-34px caption clamp applied in a column far\n // too narrow for them, and VoiceCaption's non-expanded branch became\n // unreachable code. The variable it shadowed is right there on line 90.\n expanded={expanded}\n statusText={status}\n errorText={errorText}\n control={orb}\n />\n ) : (\n <VoiceMiniController\n state={stage}\n caption={caption}\n statusText={status}\n errorText={errorText}\n control={orb}\n />\n );\n })()}\n\n {transcriptOpen ? <VoiceTranscriptDrawer turns={turns} onClose={() => setTranscriptOpen(false)} /> : null}\n\n {/* History is SECONDARY — behind a button, never on the stage. */}\n <button\n type=\"button\"\n onClick={() => setTranscriptOpen((open) => !open)}\n className={`absolute ${expanded ? 'bottom-6 right-6 size-14' : mini ? 'right-11 top-2 size-8' : 'bottom-3 right-3 size-11'} flex items-center justify-center rounded-full bg-bg-elevated text-text-secondary transition-colors hover:bg-bg-raised hover:text-text-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong`}\n aria-pressed={transcriptOpen}\n aria-label={tr('healthybowl.assistant.voiceSession.transcript', 'Voice transcript')}\n data-testid=\"assistant-voice-transcript-toggle\"\n >\n <ScrollText className={expanded ? 'size-6' : mini ? 'size-4' : 'size-5'} />\n </button>\n\n <button\n type=\"button\"\n onClick={() => setView(nextView)}\n className={`absolute ${expanded ? 'bottom-6 left-6 size-14' : mini ? 'left-2 top-2 size-8' : 'bottom-3 left-3 size-11'} flex items-center justify-center rounded-full bg-bg-elevated text-text-secondary transition-colors hover:bg-bg-raised hover:text-text-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong`}\n // Not a toggle any more, so `aria-pressed` would be a lie. The label\n // names where the button GOES, which is what a stepping control needs.\n aria-label={\n nextView === 'panel'\n ? tr('healthybowl.assistant.voiceSession.expandPanel', 'Show the conversation in the panel')\n : nextView === 'full'\n ? tr('healthybowl.assistant.voiceSession.expand', 'Expand the conversation to full screen')\n : tr('healthybowl.assistant.voiceSession.collapse', 'Shrink to the compact controller')\n }\n data-testid=\"assistant-voice-expand\"\n >\n {expanded ? <Minimize2 className=\"size-5\" /> : <Maximize2 className={mini ? 'size-4' : 'size-5'} />}\n </button>\n </div>\n );\n};\n\n/**\n * Recoverable problems, shown WITHOUT ending the session.\n *\n * The bug these exist for: the overlay said \"Listening…\" while the recogniser\n * was dead, and nothing anywhere said otherwise.\n */\nfunction noticeMessage(notice: VoiceSessionNotice, tr: ReturnType<typeof useTr>): string {\n switch (notice) {\n case 'network':\n return tr(\n 'healthybowl.assistant.voiceSession.noticeNetwork',\n 'Speech recognition lost its connection. Check your network — it will retry.'\n );\n case 'not-capturing':\n return tr(\n 'healthybowl.assistant.voiceSession.noticeNotCapturing',\n 'The microphone did not start. Check that this site is allowed to use it, then try again.'\n );\n case 'recognition-failed':\n return tr(\n 'healthybowl.assistant.voiceSession.noticeRecognitionFailed',\n 'Speech recognition stopped unexpectedly. It will retry — if it keeps happening, reload the page.'\n );\n case 'nothing-heard':\n return tr(\n 'healthybowl.assistant.voiceSession.noticeNothingHeard',\n 'Nothing heard yet. Check your microphone is not muted or in use by another app.'\n );\n default: {\n const unhandled: never = notice;\n return unhandled;\n }\n }\n}\n\n/**\n * Every failure is explained rather than silently closing the session.\n *\n * A session that just vanishes is the dead-button bug in another shape — the\n * exact defect BOFF-7106 had to fix on the per-message speak control.\n */\nfunction errorMessage(error: VoiceSessionError, tr: ReturnType<typeof useTr>): string {\n switch (error) {\n case 'mic-denied':\n return tr(\n 'healthybowl.assistant.voiceSession.micDenied',\n 'Microphone access is blocked. Allow it in your browser settings to talk.'\n );\n case 'no-speech-support':\n return tr(\n 'healthybowl.assistant.voiceSession.noSpeechSupport',\n 'This browser cannot listen. Try a different browser, or type instead.'\n );\n case 'no-voice-support':\n return tr(\n 'healthybowl.assistant.voiceSession.noVoiceSupport',\n 'This device has no voice that can speak this language.'\n );\n default: {\n // Exhaustive: adding a variant without copy becomes a build error rather\n // than a silently empty status line.\n const unhandled: never = error;\n return unhandled;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAsDA,IAAa,KAAoC,EAC/C,YACA,WAAQ,CAAC,GACT,YAAS,MACT,WACA,gBACA,iBACA,UACA,eAAY,IACZ,kBAAe,IACf,sBAAmB,SACf;CACJ,IAAM,IAAK,EAAM,GACX,EAAE,UAAO,UAAO,aAAU,GAC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sDACA,uEACF;EACF,KAAK,oBACH,OAAO,EACL,qDACA,wDACF;EACF,SAIE,OAAO;CAEX;AACF"}
|
|
1
|
+
{"version":3,"file":"AssistantVoiceSession.js","names":[],"sources":["../../../../src/components/assistant/voice/AssistantVoiceSession.tsx"],"sourcesContent":["import { useEffect, useRef, useState, type FC } from 'react';\nimport { Maximize2, Minimize2, ScrollText, X } from 'lucide-react';\nimport { AssistantVoiceOrb } from './AssistantVoiceOrb';\nimport { VoiceStage } from './VoiceStage';\nimport { VoiceMiniController } from './VoiceMiniController';\nimport { VoiceTranscriptDrawer } from './VoiceTranscriptDrawer';\nimport { voiceStageState, micIsInterrupt } from '../../../utils/voiceStageState';\nimport { useTr } from '../../../shared/hooks/useTr';\nimport { spokenSoFar, type VoiceSessionSnapshot } from '../../../utils/voiceSession';\nimport type { VoiceSessionError } from '../../../utils/voiceSession';\nimport type { VoiceSessionNotice } from '../../../hooks/useVoiceSession';\n\n/** How much room the voice session takes: a strip, the panel, or the screen. */\nexport type VoiceView = 'mini' | 'panel' | 'full';\n\ninterface Props {\n session: VoiceSessionSnapshot;\n /** Recent exchanges, oldest first — the running conversation. */\n turns?: ReadonlyArray<{ id: string; role: 'user' | 'assistant'; text: string }>;\n /** Cut the assistant off mid-reply. */\n onInterrupt?: () => void;\n /** A recoverable problem to surface. Null when the microphone is healthy. */\n notice?: VoiceSessionNotice | null;\n /** The assistant's last reply, captioned while it is spoken. */\n spoken: string | null;\n onToggleMute: () => void;\n onEnd: () => void;\n /** Is the recogniser actually running? Distinguishes CONNECTING from LISTENING. */\n capturing?: boolean;\n /** The user has cut the assistant off and capture has not resumed yet. */\n interrupting?: boolean;\n /** Quiet has fallen and the two-second correction window is running. */\n awaitingEndpoint?: boolean;\n}\n\n/**\n * Full-screen voice conversation (BOFF-7120).\n *\n * ★ **Voice only, by explicit product decision.** The reference (Gemini Live)\n * also offers camera and screen sharing; those are deliberately absent here.\n * Attaching images is a separate, existing capability of the assistant and\n * stays in the composer, and screen sharing could not work on the primary\n * device anyway — `getDisplayMedia` is unsupported by every iOS browser, so\n * that control would be dead on an iPhone.\n *\n * The controls are therefore the two that a voice conversation actually needs:\n * mute, and end. Anything else would be a button the user has to think about\n * while talking.\n *\n * This component is presentational: every transition is owned by\n * `voiceSessionReducer`, which is pure and tested. That split exists because\n * this file cannot be tested at all in this repo — vitest runs in `node` with\n * no DOM and no audio.\n */\nexport const AssistantVoiceSession: FC<Props> = ({\n session,\n turns = [],\n notice = null,\n spoken,\n onInterrupt,\n onToggleMute,\n onEnd,\n capturing = true,\n interrupting = false,\n awaitingEndpoint = false,\n}) => {\n const tr = useTr();\n const { phase, muted, error } = session;\n const endRef = useRef<HTMLButtonElement>(null);\n const dialogRef = useRef<HTMLDivElement>(null);\n /**\n * Docked inside the assistant panel by default; full-screen only on request.\n *\n * A voice conversation is usually a glance-and-listen thing, so taking over\n * the whole screen for it is the wrong default — the user loses the page they\n * were asking about. Expanding is opt-in and per-session: reopening starts\n * docked again, which is the behaviour that matches \"default should be the\n * same size as the assistant\".\n */\n /**\n * ★ THREE sizes, not two.\n *\n * The compact controller was added so voice stops taking over the panel — but\n * making it the only docked size removed the in-panel stage that existed\n * before, which is a genuinely useful middle: big enough to read a reply,\n * without losing the page behind it.\n *\n * mini — a strip at the bottom; the assistant panel stays visible\n * panel — fills the assistant panel (what \"docked\" used to mean)\n * full — full screen\n *\n * One button steps mini → panel → full and wraps, with the label always\n * naming where it goes next, so a single control stays predictable.\n */\n const [view, setView] = useState<VoiceView>('mini');\n const expanded = view === 'full';\n const mini = view === 'mini';\n const nextView: VoiceView = view === 'mini' ? 'panel' : view === 'panel' ? 'full' : 'mini';\n /** History is secondary: the stage shows now, this shows the session. */\n const [transcriptOpen, setTranscriptOpen] = useState(false);\n\n // A full-screen `aria-modal` overlay that cannot be dismissed from the\n // keyboard is a trap. Escape ends the session, and focus starts on End so a\n // keyboard or screen-reader user lands somewhere useful rather than behind\n // the overlay.\n // Focus lands on End ONCE, on open. Keeping this in the keydown effect below\n // meant every expand/collapse re-ran it and silently stole focus from the\n // button just pressed — a Space or Enter a beat later would then end the\n // session instead of toggling the size again.\n useEffect(() => {\n endRef.current?.focus();\n }, []);\n\n useEffect(() => {\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n // ★ Escape closes the drawer first. Ending the whole conversation\n // because someone dismissed a panel would be a surprising amount of\n // destruction for one keypress.\n if (transcriptOpen) {\n setTranscriptOpen(false);\n return;\n }\n onEnd();\n return;\n }\n // Trapping focus is only correct when the overlay actually covers\n // everything. Docked, it sits inside the panel and the rest of the page\n // is legitimately reachable, so trapping there would be the bug rather\n // than the fix.\n if (event.key !== 'Tab' || !expanded) return;\n // `aria-modal` only TELLS assistive technology this is modal; it does not\n // make it so. Without this, Tab walks straight out of the overlay into the\n // page behind it, which is still fully interactive underneath — a\n // keyboard user ends up operating a screen they cannot see.\n // ★ Scope the trap to what is actually on screen. With the transcript\n // drawer open, a flat `button` query also collects the controls it covers,\n // so Tab walked into buttons the user could not see — the same class of\n // bug the trap exists to prevent.\n const scope = transcriptOpen\n ? dialogRef.current?.querySelector<HTMLElement>('[data-testid=\"assistant-voice-transcript\"]')\n : dialogRef.current;\n const focusable = scope?.querySelectorAll<HTMLElement>('button:not([disabled])');\n if (!focusable || focusable.length === 0) return;\n const first = focusable[0];\n const last = focusable[focusable.length - 1];\n if (!first || !last) return;\n if (event.shiftKey && document.activeElement === first) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && document.activeElement === last) {\n event.preventDefault();\n first.focus();\n }\n };\n window.addEventListener('keydown', onKeyDown);\n return () => window.removeEventListener('keydown', onKeyDown);\n }, [onEnd, expanded, transcriptOpen]);\n\n // While speaking, the caption shows the REPLY; otherwise what we have heard.\n // Showing the stale transcript under the assistant's own voice reads as a\n // mis-transcription of the assistant, which is worse than showing nothing.\n // A notice competes with the error for the same slot; the error owns the\n // stage, so they are never both shown.\n const showNotice = notice !== null && error === null;\n\n const heard = spokenSoFar(session);\n\n // ★ ONE state, derived. The reducer's phase cannot tell \"listening\" from\n // \"the microphone has not started yet\", and the old overlay rendered every\n // signal at once — status, warning, transcript, caption and orb together.\n // ★ Both signals were accepted by `voiceStageState` and passed by nobody, so\n // `endpoint-grace` and `interrupting` were unreachable branches.\n const stage = voiceStageState({ snapshot: session, capturing, interrupting, awaitingEndpoint });\n\n /**\n * The label for the STAGE, not for the phase.\n *\n * ★ This used to read `phase`, which is why three derived stages were\n * invisible even once they were reachable: `connecting`, `endpoint-grace` and\n * `interrupting` are all `phase === 'listening'` underneath, so every one of\n * them said \"Listening…\". The stage exists precisely because the phase cannot\n * make these distinctions — deriving the caption from the phase threw that\n * away again, and told the user we were listening before the recogniser had\n * started, the exact lie `voiceStageState` was written to stop.\n */\n const stageText = (() => {\n switch (stage) {\n case 'connecting':\n return tr('healthybowl.assistant.voiceSession.connecting', 'Starting the microphone…');\n case 'endpoint-grace':\n // Reads as an invitation, not a countdown: the window exists so the\n // user can still correct themselves, and hurrying them defeats it.\n return tr('healthybowl.assistant.voiceSession.endpointGrace', 'Still listening — take your time');\n case 'interrupting':\n return tr('healthybowl.assistant.voiceSession.interrupting', 'Stopped — go ahead');\n case 'thinking':\n return tr('healthybowl.assistant.voiceSession.thinking', 'Thinking…');\n case 'speaking':\n return tr('healthybowl.assistant.voiceSession.speaking', 'Speaking — tap to stop');\n case 'mic-error':\n case 'ended':\n // Owned by the error branch of the stage, which gets it to itself.\n return '';\n case 'listening':\n return muted\n ? tr('healthybowl.assistant.voiceSession.muted', 'Microphone off')\n : tr('healthybowl.assistant.voiceSession.listening', 'Listening…');\n default: {\n // ★ Exhaustive on purpose, matching `errorMessage` and `noticeMessage`\n // below. A stage with no copy is the exact bug this change fixes, so a\n // new one without a label must fail the BUILD rather than silently\n // inherit \"Listening…\" the way three of them already did.\n const unhandled: never = stage;\n return unhandled;\n }\n }\n })();\n\n // Muted is reported ALONGSIDE the stage, not instead of it: the assistant may\n // still be speaking with the microphone off, and saying only \"Microphone off\"\n // would misreport that.\n //\n // ★ Gated on the STAGE, not the phase. `connecting`, `endpoint-grace` and\n // `interrupting` are all `phase === 'listening'` underneath, so a phase test\n // dropped the suffix on exactly the three stages this change introduced —\n // leaving \"Stopped — go ahead\" inviting someone to speak into a muted\n // microphone. The `!== ''` guard keeps ended/mic-error from rendering a bare\n // \" · Microphone off\".\n //\n // ★ No `error !== null` arm: `stageText` is already '' for `mic-error`, and\n // the message itself belongs to the stage's alert element. Testing the error\n // here printed the whole sentence TWICE on the one screen this change exists\n // to make visible — truncated in the status line, repeated below it, and\n // announced twice by a screen reader.\n const status =\n muted && stage !== 'listening' && stageText !== ''\n ? `${stageText} · ${tr('healthybowl.assistant.voiceSession.muted', 'Microphone off')}`\n : stageText;\n\n return (\n <div\n ref={dialogRef}\n className={`flex flex-col items-center justify-between bg-bg-sunken ${\n view === 'full'\n ? // ★ Below the app header, not behind it. The header is `z-[100]` and\n // this overlay was `z-[60]` at `inset-0`, so the top 56px sat behind\n // it — and the End button did not merely LOOK hidden, it was\n // unclickable (`elementFromPoint` returned the header). Starting at\n // `top-14` means nothing is ever behind the header, and the header\n // stays usable for orientation.\n 'fixed inset-x-0 bottom-0 top-14 z-[60] px-6 py-8'\n : view === 'panel'\n ? // The in-panel stage: covers the assistant panel, keeps the page.\n 'absolute inset-0 z-20 px-4 py-6'\n : // A strip at the bottom, ~180px, so the panel behind stays visible.\n 'absolute inset-x-0 bottom-0 z-20 h-[11.25rem] border-t border-border-subtle px-3 py-3 shadow-lg'\n }`}\n role=\"dialog\"\n // Only modal when it really is: docked, the page behind stays usable.\n // `undefined` rather than `false` — the ARIA default is already false, and\n // some older assistive technology treats an explicit \"false\" on a dialog\n // as still modal.\n aria-modal={expanded || undefined}\n aria-label={tr('healthybowl.assistant.voiceSession.title', 'Voice conversation')}\n data-testid=\"assistant-voice-session\"\n >\n {/* End sits top-right and expand bottom-left, out of the centre column.\n Absolute rather than part of the flow so the pill stays optically\n centred at both sizes — the overlay is already a positioning context\n (`fixed` when expanded, `absolute` when docked). */}\n <button\n ref={endRef}\n type=\"button\"\n onClick={onEnd}\n // ★ Height + horizontal padding, never `size-*`. A fixed square cannot\n // grow to fit a word, so a label dropped into one spills outside its own\n // rounded border. The mini strip keeps the square: its transcript toggle\n // sits 4px away at `right-11`, and a wider button there would grow\n // leftward underneath it — which is precisely the defect the previous\n // commit on this file fixed (\"the close button was unclickable\").\n className={`absolute ${\n expanded\n ? 'right-6 top-6 h-14 gap-2 px-5 text-base'\n : mini\n ? 'right-2 top-2 size-8'\n : 'right-3 top-3 h-11 gap-2 px-4 text-sm'\n } flex items-center justify-center rounded-full border border-border-default bg-bg-elevated text-text-secondary hover:bg-bg-sunken transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong`}\n // ★ Only when the label is INVISIBLE. With visible text the accessible\n // name comes from that text, which keeps WCAG 2.5.3 (Label in Name)\n // true by construction in every locale — including before `endShort` is\n // seeded. An aria-label here would instead pin a translated sentence\n // against an untranslated visible word, and speech-input users say the\n // word they can see.\n aria-label={mini ? tr('healthybowl.assistant.voiceSession.end', 'End the voice conversation') : undefined}\n data-testid=\"assistant-voice-end\"\n >\n <X className={expanded ? 'size-6' : mini ? 'size-4' : 'size-5'} aria-hidden=\"true\" />\n {/* The glyph alone said \"close\" only to people who already knew.\n ★ Bounded: the width is a TRANSLATED string while the layout around\n it is fixed pixels — \"Beenden\" and \"Terminer\" are ~2.4x \"End\". The\n cap turns a future overflow into an ellipsis rather than a control\n that creeps over its neighbour. */}\n {!mini ? (\n <span className=\"max-w-[7rem] truncate whitespace-nowrap font-medium\">\n {tr('healthybowl.assistant.voiceSession.endShort', 'End')}\n </span>\n ) : null}\n </button>\n\n {/* ★ The notice is CHROME, not conversation. It used to sit above the\n transcript in the same column as the reply, which is why a microphone\n warning read as part of what the assistant said. The status line moved\n into the stage, where it labels the state it belongs to. */}\n {/* ★ Cleared VERTICALLY, not horizontally. This div is a flex item of a\n `flex flex-col items-center` column, so it is SHRINK-TO-FIT: side\n padding does not reserve space beside the End button, it eats the\n text's own measure — symmetrically, for a control on one side only.\n Widening `px-14` to match a labelled button collapsed the microphone\n warning to a 78px, nine-line column on a phone and in the docked\n panel, because 78px is the min-content width of the longest word in it.\n\n Dropping below the button instead makes the clearance independent of\n both the container width and the label's length — which matters\n because that label is TRANSLATED (\"Beenden\", \"Terminer\") while these\n offsets are fixed pixels. End occupies y=24..80 expanded (top-6 +\n h-14) and y=12..56 docked (top-3 + h-11); the column's own padding\n already starts content at 32 / 24, so these add the rest plus 8px.\n\n ★ NOT true of `mini`, where End, transcript and expand are ALL in the\n top band and this stays `px-3`. A notice there can still be painted\n over by those opaque buttons. Pre-existing and left alone: the strip is\n 180px tall and buying 32px of top padding would squeeze the stage. */}\n <div\n className={`flex flex-col items-center ${\n mini\n ? 'px-3'\n : // ★ The reserve is applied ONLY when there is something to clear.\n // `padding` is not subject to `min-h`, so an unconditional `pt-14`\n // would stand a permanent 56px column above an empty div and take\n // that height out of the `flex-1` stage on every session — paying\n // the cost of a warning that is not there.\n `min-h-[1.5rem] ${showNotice ? (expanded ? 'pt-14' : 'pt-10') : ''}`\n }`}\n >\n {showNotice ? (\n <p className=\"max-w-xs text-center text-xs text-status-warning\" data-testid=\"assistant-voice-notice\">\n {noticeMessage(notice, tr)}\n </p>\n ) : null}\n </div>\n\n {/* ★ Two genuinely different surfaces, not one scaled. Expanded is a\n reading stage; docked is a controller. */}\n {(() => {\n const orb = (\n <AssistantVoiceOrb\n session={session}\n compact={mini}\n onPress={micIsInterrupt(stage) ? onInterrupt : onToggleMute}\n label={\n micIsInterrupt(stage)\n ? tr('healthybowl.assistant.voiceSession.interrupt', 'Stop the assistant and speak')\n : muted\n ? tr('healthybowl.assistant.voiceSession.unmute', 'Turn the microphone on')\n : tr('healthybowl.assistant.voiceSession.mute', 'Turn the microphone off')\n }\n />\n );\n const caption = micIsInterrupt(stage) ? spoken : heard || null;\n const errorText = error !== null ? errorMessage(error, tr) : null;\n return !mini ? (\n <VoiceStage\n state={stage}\n userCaption={heard || null}\n assistantCaption={spoken}\n // ★ `expanded` — the JSX shorthand — means `expanded={true}`, not\n // `expanded={expanded}`. This branch serves BOTH the docked panel and\n // full screen, so the panel was being styled as full screen: the\n // full-screen caption measure and clamp applied in a column far\n // too narrow for them, and VoiceCaption's non-expanded branch became\n // unreachable code. The variable it shadowed is right there on line 90.\n expanded={expanded}\n statusText={status}\n errorText={errorText}\n control={orb}\n />\n ) : (\n <VoiceMiniController\n state={stage}\n caption={caption}\n statusText={status}\n errorText={errorText}\n control={orb}\n />\n );\n })()}\n\n {transcriptOpen ? <VoiceTranscriptDrawer turns={turns} onClose={() => setTranscriptOpen(false)} /> : null}\n\n {/* History is SECONDARY — behind a button, never on the stage. */}\n <button\n type=\"button\"\n onClick={() => setTranscriptOpen((open) => !open)}\n className={`absolute ${expanded ? 'bottom-6 right-6 size-14' : mini ? 'right-11 top-2 size-8' : 'bottom-3 right-3 size-11'} flex items-center justify-center rounded-full bg-bg-elevated text-text-secondary transition-colors hover:bg-bg-raised hover:text-text-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong`}\n aria-pressed={transcriptOpen}\n aria-label={tr('healthybowl.assistant.voiceSession.transcript', 'Voice transcript')}\n data-testid=\"assistant-voice-transcript-toggle\"\n >\n <ScrollText className={expanded ? 'size-6' : mini ? 'size-4' : 'size-5'} />\n </button>\n\n <button\n type=\"button\"\n onClick={() => setView(nextView)}\n className={`absolute ${expanded ? 'bottom-6 left-6 size-14' : mini ? 'left-2 top-2 size-8' : 'bottom-3 left-3 size-11'} flex items-center justify-center rounded-full bg-bg-elevated text-text-secondary transition-colors hover:bg-bg-raised hover:text-text-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-border-strong`}\n // Not a toggle any more, so `aria-pressed` would be a lie. The label\n // names where the button GOES, which is what a stepping control needs.\n aria-label={\n nextView === 'panel'\n ? tr('healthybowl.assistant.voiceSession.expandPanel', 'Show the conversation in the panel')\n : nextView === 'full'\n ? tr('healthybowl.assistant.voiceSession.expand', 'Expand the conversation to full screen')\n : tr('healthybowl.assistant.voiceSession.collapse', 'Shrink to the compact controller')\n }\n data-testid=\"assistant-voice-expand\"\n >\n {expanded ? <Minimize2 className=\"size-5\" /> : <Maximize2 className={mini ? 'size-4' : 'size-5'} />}\n </button>\n </div>\n );\n};\n\n/**\n * Recoverable problems, shown WITHOUT ending the session.\n *\n * The bug these exist for: the overlay said \"Listening…\" while the recogniser\n * was dead, and nothing anywhere said otherwise.\n */\nfunction noticeMessage(notice: VoiceSessionNotice, tr: ReturnType<typeof useTr>): string {\n switch (notice) {\n case 'network':\n return tr(\n 'healthybowl.assistant.voiceSession.noticeNetwork',\n 'Speech recognition lost its connection. Check your network — it will retry.'\n );\n case 'not-capturing':\n return tr(\n 'healthybowl.assistant.voiceSession.noticeNotCapturing',\n 'The microphone did not start. Check that this site is allowed to use it, then try again.'\n );\n case 'recognition-failed':\n return tr(\n 'healthybowl.assistant.voiceSession.noticeRecognitionFailed',\n 'Speech recognition stopped unexpectedly. It will retry — if it keeps happening, reload the page.'\n );\n case 'nothing-heard':\n return tr(\n 'healthybowl.assistant.voiceSession.noticeNothingHeard',\n 'Nothing heard yet. Check your microphone is not muted or in use by another app.'\n );\n default: {\n const unhandled: never = notice;\n return unhandled;\n }\n }\n}\n\n/**\n * Every failure is explained rather than silently closing the session.\n *\n * A session that just vanishes is the dead-button bug in another shape — the\n * exact defect BOFF-7106 had to fix on the per-message speak control.\n */\nfunction errorMessage(error: VoiceSessionError, tr: ReturnType<typeof useTr>): string {\n switch (error) {\n case 'mic-denied':\n return tr(\n 'healthybowl.assistant.voiceSession.micDenied',\n 'Microphone access is blocked. Allow it in your browser settings to talk.'\n );\n case 'no-speech-support':\n return tr(\n 'healthybowl.assistant.voiceSession.noSpeechSupport',\n 'This browser cannot listen. Try a different browser, or type instead.'\n );\n case 'no-voice-support':\n return tr(\n 'healthybowl.assistant.voiceSession.noVoiceSupport',\n 'This device has no voice that can speak this language.'\n );\n default: {\n // Exhaustive: adding a variant without copy becomes a build error rather\n // than a silently empty status line.\n const unhandled: never = error;\n return unhandled;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAsDA,IAAa,KAAoC,EAC/C,YACA,WAAQ,CAAC,GACT,YAAS,MACT,WACA,gBACA,iBACA,UACA,eAAY,IACZ,kBAAe,IACf,sBAAmB,SACf;CACJ,IAAM,IAAK,EAAM,GACX,EAAE,UAAO,UAAO,aAAU,GAC1B,IAAS,EAA0B,IAAI,GACvC,IAAY,EAAuB,IAAI,GAyBvC,CAAC,GAAM,KAAW,EAAoB,MAAM,GAC5C,IAAW,MAAS,QACpB,IAAO,MAAS,QAChB,IAAsB,MAAS,SAAS,UAAU,MAAS,UAAU,SAAS,QAE9E,CAAC,GAAgB,KAAqB,EAAS,EAAK;CAc1D,AAJA,QAAgB;EACd,EAAO,SAAS,MAAM;CACxB,GAAG,CAAC,CAAC,GAEL,QAAgB;EACd,IAAM,KAAa,MAAyB;GAC1C,IAAI,EAAM,QAAQ,UAAU;IAI1B,IAAI,GAAgB;KAClB,EAAkB,EAAK;KACvB;IACF;IACA,EAAM;IACN;GACF;GAKA,IAAI,EAAM,QAAQ,SAAS,CAAC,GAAU;GAYtC,IAAM,KAHQ,IACV,EAAU,SAAS,cAA2B,8CAA4C,IAC1F,EAAU,UACW,iBAA8B,wBAAwB;GAC/E,IAAI,CAAC,KAAa,EAAU,WAAW,GAAG;GAC1C,IAAM,IAAQ,EAAU,IAClB,IAAO,EAAU,EAAU,SAAS;GACtC,CAAC,KAAS,CAAC,MACX,EAAM,YAAY,SAAS,kBAAkB,KAC/C,EAAM,eAAe,GACrB,EAAK,MAAM,KACF,CAAC,EAAM,YAAY,SAAS,kBAAkB,MACvD,EAAM,eAAe,GACrB,EAAM,MAAM;EAEhB;EAEA,OADA,OAAO,iBAAiB,WAAW,CAAS,SAC/B,OAAO,oBAAoB,WAAW,CAAS;CAC9D,GAAG;EAAC;EAAO;EAAU;CAAc,CAAC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AAU,CAAA,IAAI,kBAAC,GAAD,EAAW,WAAW,IAAO,WAAW,SAAW,CAAA;GAC5F,CAAA;EACL;;AAET;AAQA,SAAS,EAAc,GAA4B,GAAsC;CACvF,QAAQ,GAAR;EACE,KAAK,WACH,OAAO,EACL,oDACA,6EACF;EACF,KAAK,iBACH,OAAO,EACL,yDACA,0FACF;EACF,KAAK,sBACH,OAAO,EACL,8DACA,kGACF;EACF,KAAK,iBACH,OAAO,EACL,yDACA,iFACF;EACF,SAEE,OAAO;CAEX;AACF;AAQA,SAAS,EAAa,GAA0B,GAAsC;CACpF,QAAQ,GAAR;EACE,KAAK,cACH,OAAO,EACL,gDACA,0EACF;EACF,KAAK,qBACH,OAAO,EACL,sDACA,uEACF;EACF,KAAK,oBACH,OAAO,EACL,qDACA,wDACF;EACF,SAIE,OAAO;CAEX;AACF"}
|
|
@@ -7,9 +7,9 @@ var t = ({ text: t, role: n, expanded: r, testId: i }) => {
|
|
|
7
7
|
children: /* @__PURE__ */ e("p", {
|
|
8
8
|
className: [
|
|
9
9
|
"w-full whitespace-pre-wrap text-left",
|
|
10
|
-
r ? "max-w-[
|
|
10
|
+
r ? "max-w-[45rem]" : "max-w-md",
|
|
11
11
|
a ? "font-semibold text-text-primary" : "font-medium text-text-secondary",
|
|
12
|
-
r ? a ? "text-[clamp(1.
|
|
12
|
+
r ? a ? "text-[clamp(1.625rem,2.5vw,2.25rem)] leading-[1.5]" : "text-[clamp(1.125rem,1.8vw,1.375rem)] leading-[1.5]" : a ? "text-lg leading-relaxed" : "text-base leading-relaxed"
|
|
13
13
|
].join(" "),
|
|
14
14
|
role: "status",
|
|
15
15
|
"aria-live": "polite",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VoiceCaption.js","names":[],"sources":["../../../../src/components/assistant/voice/VoiceCaption.tsx"],"sourcesContent":["import type { FC } from 'react';\n\n/**\n * One live caption — either what the user is saying or what the assistant is.\n *\n * Replaces the message-bubble list the voice overlay used to render. That list\n * was the chat transcript squeezed into a modal: bubbles, the whole scrollback,\n * and raw `##`/`**` because it printed the model's markdown as plain text.\n *\n * Three things here are deliberate and were all wrong before:\n *\n * ★ **Left-aligned, not centred.** Centring is fine for one short line and\n * unreadable for four — every line starts in a different place, so the eye has\n * to hunt for each beginning. Tamil/English mixed text makes it worse, because\n * the line lengths vary wildly. The BLOCK is centred on the stage; the text\n * inside it is not.\n *\n * ★ **Responsive type, not one fixed size.** `clamp()` so the same component is\n * legible in a 380px docked panel and from arm's length on a maximised desktop\n * window, without a second component or a transform.\n *\n * ★ **Bounded width.**
|
|
1
|
+
{"version":3,"file":"VoiceCaption.js","names":[],"sources":["../../../../src/components/assistant/voice/VoiceCaption.tsx"],"sourcesContent":["import type { FC } from 'react';\n\n/**\n * One live caption — either what the user is saying or what the assistant is.\n *\n * Replaces the message-bubble list the voice overlay used to render. That list\n * was the chat transcript squeezed into a modal: bubbles, the whole scrollback,\n * and raw `##`/`**` because it printed the model's markdown as plain text.\n *\n * Three things here are deliberate and were all wrong before:\n *\n * ★ **Left-aligned, not centred.** Centring is fine for one short line and\n * unreadable for four — every line starts in a different place, so the eye has\n * to hunt for each beginning. Tamil/English mixed text makes it worse, because\n * the line lengths vary wildly. The BLOCK is centred on the stage; the text\n * inside it is not.\n *\n * ★ **Responsive type, not one fixed size.** `clamp()` so the same component is\n * legible in a 380px docked panel and from arm's length on a maximised desktop\n * window, without a second component or a transform.\n *\n * ★ **Bounded width.** A caption spanning a 1440px window is one long line the\n * eye cannot track back from, so the measure is capped — 45rem / 720px on the\n * full-screen stage, the middle of the 680-760px the design calls for.\n *\n * ★ That measure is deliberately NOT the 60-75 characters typography usually\n * aims at: at 36px type 720px carries roughly 40. A voice caption is glanced at\n * from arm's length while someone is talking, not read as prose, and the size\n * is what makes it glanceable — so the two constraints are set independently\n * and the width follows the spec rather than the usual reading rule.\n */\n\ninterface Props {\n text: string;\n /** Who is speaking. The assistant's caption is the loud one. */\n role: 'user' | 'assistant';\n /** Full-screen rather than docked in the panel. */\n expanded: boolean;\n testId?: string;\n}\n\nexport const VoiceCaption: FC<Props> = ({ text, role, expanded, testId }) => {\n const assistant = role === 'assistant';\n return (\n <div className=\"flex w-full justify-center\">\n <p\n className={[\n // Left-aligned inside a centred block — see above.\n // ★ `toCaptionText` PRESERVES newlines; without pre-wrap they collapse\n // and a multi-paragraph answer renders as one wall of text.\n 'w-full whitespace-pre-wrap text-left',\n // 45rem = 720px, mid-band. Arbitrary value on purpose: Tailwind's\n // max-w-2xl is 672px and max-w-3xl 768px, so neither preset lands\n // inside 680-760.\n expanded ? 'max-w-[45rem]' : 'max-w-md',\n assistant ? 'font-semibold text-text-primary' : 'font-medium text-text-secondary',\n expanded\n ? assistant\n ? // 26-36px. ★ The floor is coupled to VoiceStage's empty-caption\n // reserve, which is 3x this value (two lines at 1.5 leading) so\n // the control does not jump when the first words arrive — move\n // one and the other has to move with it.\n 'text-[clamp(1.625rem,2.5vw,2.25rem)] leading-[1.5]'\n : // The USER caption is deliberately quieter and is not part of\n // the 26-36px band, which specifies the assistant's line.\n 'text-[clamp(1.125rem,1.8vw,1.375rem)] leading-[1.5]'\n : assistant\n ? 'text-lg leading-relaxed'\n : 'text-base leading-relaxed',\n ].join(' ')}\n // The stage's live region: the caption is what actually changes, so a\n // screen reader should hear it rather than only the status word.\n role=\"status\"\n aria-live=\"polite\"\n data-testid={testId}\n >\n {text}\n </p>\n </div>\n );\n};\n"],"mappings":";;AAyCA,IAAa,KAA2B,EAAE,SAAM,SAAM,aAAU,gBAAa;CAC3E,IAAM,IAAY,MAAS;CAC3B,OACE,kBAAC,OAAD;EAAK,WAAU;YACb,kBAAC,KAAD;GACE,WAAW;IAIT;IAIA,IAAW,kBAAkB;IAC7B,IAAY,oCAAoC;IAChD,IACI,IAKE,uDAGA,wDACF,IACE,4BACA;GACR,EAAE,KAAK,GAAG;GAGV,MAAK;GACL,aAAU;GACV,eAAa;aAEZ;EACA,CAAA;CACA,CAAA;AAET"}
|
|
@@ -46,7 +46,7 @@ var l = ({ state: l, userCaption: u, assistantCaption: d, expanded: f, statusTex
|
|
|
46
46
|
testId: "assistant-voice-caption"
|
|
47
47
|
})
|
|
48
48
|
}) : /* @__PURE__ */ s("div", {
|
|
49
|
-
className: f ? "mb-12 h-[4.
|
|
49
|
+
className: f ? "mb-12 h-[4.875rem]" : "mb-6 h-12",
|
|
50
50
|
"aria-hidden": "true"
|
|
51
51
|
})] }),
|
|
52
52
|
m
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VoiceStage.js","names":[],"sources":["../../../../src/components/assistant/voice/VoiceStage.tsx"],"sourcesContent":["import type { FC, ReactNode } from 'react';\nimport { VoiceCaption } from './VoiceCaption';\nimport { VoiceWaveform } from './VoiceWaveform';\nimport {\n waveformIsActive,\n waveformIsSettled,\n showsAssistantCaption,\n showsUserCaption,\n type VoiceStageState,\n} from '../../../utils/voiceStageState';\n\n/**\n * The middle of the voice panel: exactly ONE state, rendered as itself.\n *\n * What this replaces is the whole problem the operator screenshotted. The old\n * overlay showed, simultaneously: \"Listening…\", a microphone warning, the last\n * six messages of the chat conversation as bubbles (markdown syntax and all),\n * the assistant's answer AGAIN as a caption, and the orb. Five things competing,\n * none of them readable.\n *\n * ★ A stage shows one thing because the session IS one thing at a time. The\n * state is derived in `voiceStageState`, which is pure and tested; this file is\n * presentational and cannot be tested in this repo (vitest runs in `node`, no\n * DOM), so it deliberately contains no logic worth testing.\n *\n * The microphone warning is NOT rendered here. Mixing a system message into the\n * conversation area is what made it read as part of the reply; it belongs to\n * the chrome around the stage.\n */\n\ninterface Props {\n state: VoiceStageState;\n /** What the user is saying (live) or last said. */\n userCaption: string | null;\n /** What the assistant is saying. */\n assistantCaption: string | null;\n expanded: boolean;\n /** Status words — already localised by the caller. */\n statusText: string;\n /** The microphone / interrupt control. */\n control: ReactNode;\n /** Shown in the mic-error state instead of a caption. */\n errorText?: string | null;\n}\n\nexport const VoiceStage: FC<Props> = ({\n state,\n userCaption,\n assistantCaption,\n expanded,\n statusText,\n control,\n errorText = null,\n}) => {\n const caption = showsAssistantCaption(state) ? assistantCaption : showsUserCaption(state) ? userCaption : null;\n\n return (\n <div\n className={[\n 'flex min-h-0 w-full flex-1 flex-col items-center',\n expanded ? 'px-8' : 'px-14',\n // ★ Expanded, the group is anchored just above the optical centre\n // rather than centred in the whole box. Measured at 1440x900 the\n // content was 314px of a 756px stage with 221px of dead air above AND\n // below — technically centred, visually adrift. Docked the box is\n // small enough that centring is right.\n expanded ? 'justify-start pt-[16vh]' : 'justify-center',\n ].join(' ')}\n data-testid=\"assistant-voice-stage\"\n data-state={state}\n >\n {/* Status first and small: it is the label for the state, not the content. */}\n <p\n className={[\n 'text-center text-text-muted',\n expanded ? 'text-base' : 'text-sm',\n // The status LABELS the waveform, so it sits close to it. A uniform\n // gap made status, waveform, caption and control read as four\n // items of equal weight, with no hierarchy at all.\n expanded ? 'mb-3' : 'mb-2',\n ].join(' ')}\n // The stage change IS the feedback; without this a screen-reader user\n // is told nothing when connecting becomes listening becomes thinking.\n aria-live=\"polite\"\n data-testid=\"assistant-voice-status\"\n >\n {statusText}\n </p>\n\n {state === 'mic-error' ? (\n // A failure gets the stage to itself — no caption, no waveform. It is\n // not part of the conversation and must not look like it.\n <p\n className={`max-w-md text-center text-status-warning ${expanded ? 'text-lg' : 'text-sm'}`}\n role=\"alert\"\n data-testid=\"assistant-voice-stage-error\"\n >\n {errorText}\n </p>\n ) : (\n <>\n <div className={expanded ? 'mb-10' : 'mb-5'}>\n <VoiceWaveform\n // ★ `endpoint-grace` keeps the waveform ALIVE. It is the two-second\n // window in which the user may still correct themselves, so it has\n // to look like a microphone that is still open — a frozen waveform\n // would read as \"it stopped listening\", which is the opposite of\n // what the window is for. `interrupting` stays still on purpose:\n // the assistant has just been cut off and capture has not resumed.\n active={waveformIsActive(state)}\n settled={waveformIsSettled(state)}\n tone={state === 'speaking' ? 'speaking' : 'listening'}\n expanded={expanded}\n />\n </div>\n\n {caption ? (\n <div\n className={\n expanded\n ? // ★ A long reply used to run off the bottom of the screen with\n // no way to reach it. The model is asked for one to four\n // sentences, but that is guidance, not a guarantee — so the\n // caption is bounded and scrolls rather than being lost.\n 'mb-12 max-h-[46vh] w-full overflow-y-auto'\n : 'mb-6 w-full'\n }\n >\n <VoiceCaption\n text={caption}\n role={showsAssistantCaption(state) ? 'assistant' : 'user'}\n expanded={expanded}\n testId=\"assistant-voice-caption\"\n />\n </div>\n ) : (\n // Reserve the caption's space so the control does not jump when the\n // first words arrive. Two lines' worth at each size, matching what\n // a typical utterance actually occupies.\n <div className={expanded ? 'mb-12 h-[4.
|
|
1
|
+
{"version":3,"file":"VoiceStage.js","names":[],"sources":["../../../../src/components/assistant/voice/VoiceStage.tsx"],"sourcesContent":["import type { FC, ReactNode } from 'react';\nimport { VoiceCaption } from './VoiceCaption';\nimport { VoiceWaveform } from './VoiceWaveform';\nimport {\n waveformIsActive,\n waveformIsSettled,\n showsAssistantCaption,\n showsUserCaption,\n type VoiceStageState,\n} from '../../../utils/voiceStageState';\n\n/**\n * The middle of the voice panel: exactly ONE state, rendered as itself.\n *\n * What this replaces is the whole problem the operator screenshotted. The old\n * overlay showed, simultaneously: \"Listening…\", a microphone warning, the last\n * six messages of the chat conversation as bubbles (markdown syntax and all),\n * the assistant's answer AGAIN as a caption, and the orb. Five things competing,\n * none of them readable.\n *\n * ★ A stage shows one thing because the session IS one thing at a time. The\n * state is derived in `voiceStageState`, which is pure and tested; this file is\n * presentational and cannot be tested in this repo (vitest runs in `node`, no\n * DOM), so it deliberately contains no logic worth testing.\n *\n * The microphone warning is NOT rendered here. Mixing a system message into the\n * conversation area is what made it read as part of the reply; it belongs to\n * the chrome around the stage.\n */\n\ninterface Props {\n state: VoiceStageState;\n /** What the user is saying (live) or last said. */\n userCaption: string | null;\n /** What the assistant is saying. */\n assistantCaption: string | null;\n expanded: boolean;\n /** Status words — already localised by the caller. */\n statusText: string;\n /** The microphone / interrupt control. */\n control: ReactNode;\n /** Shown in the mic-error state instead of a caption. */\n errorText?: string | null;\n}\n\nexport const VoiceStage: FC<Props> = ({\n state,\n userCaption,\n assistantCaption,\n expanded,\n statusText,\n control,\n errorText = null,\n}) => {\n const caption = showsAssistantCaption(state) ? assistantCaption : showsUserCaption(state) ? userCaption : null;\n\n return (\n <div\n className={[\n 'flex min-h-0 w-full flex-1 flex-col items-center',\n expanded ? 'px-8' : 'px-14',\n // ★ Expanded, the group is anchored just above the optical centre\n // rather than centred in the whole box. Measured at 1440x900 the\n // content was 314px of a 756px stage with 221px of dead air above AND\n // below — technically centred, visually adrift. Docked the box is\n // small enough that centring is right.\n expanded ? 'justify-start pt-[16vh]' : 'justify-center',\n ].join(' ')}\n data-testid=\"assistant-voice-stage\"\n data-state={state}\n >\n {/* Status first and small: it is the label for the state, not the content. */}\n <p\n className={[\n 'text-center text-text-muted',\n expanded ? 'text-base' : 'text-sm',\n // The status LABELS the waveform, so it sits close to it. A uniform\n // gap made status, waveform, caption and control read as four\n // items of equal weight, with no hierarchy at all.\n expanded ? 'mb-3' : 'mb-2',\n ].join(' ')}\n // The stage change IS the feedback; without this a screen-reader user\n // is told nothing when connecting becomes listening becomes thinking.\n aria-live=\"polite\"\n data-testid=\"assistant-voice-status\"\n >\n {statusText}\n </p>\n\n {state === 'mic-error' ? (\n // A failure gets the stage to itself — no caption, no waveform. It is\n // not part of the conversation and must not look like it.\n <p\n className={`max-w-md text-center text-status-warning ${expanded ? 'text-lg' : 'text-sm'}`}\n role=\"alert\"\n data-testid=\"assistant-voice-stage-error\"\n >\n {errorText}\n </p>\n ) : (\n <>\n <div className={expanded ? 'mb-10' : 'mb-5'}>\n <VoiceWaveform\n // ★ `endpoint-grace` keeps the waveform ALIVE. It is the two-second\n // window in which the user may still correct themselves, so it has\n // to look like a microphone that is still open — a frozen waveform\n // would read as \"it stopped listening\", which is the opposite of\n // what the window is for. `interrupting` stays still on purpose:\n // the assistant has just been cut off and capture has not resumed.\n active={waveformIsActive(state)}\n settled={waveformIsSettled(state)}\n tone={state === 'speaking' ? 'speaking' : 'listening'}\n expanded={expanded}\n />\n </div>\n\n {caption ? (\n <div\n className={\n expanded\n ? // ★ A long reply used to run off the bottom of the screen with\n // no way to reach it. The model is asked for one to four\n // sentences, but that is guidance, not a guarantee — so the\n // caption is bounded and scrolls rather than being lost.\n 'mb-12 max-h-[46vh] w-full overflow-y-auto'\n : 'mb-6 w-full'\n }\n >\n <VoiceCaption\n text={caption}\n role={showsAssistantCaption(state) ? 'assistant' : 'user'}\n expanded={expanded}\n testId=\"assistant-voice-caption\"\n />\n </div>\n ) : (\n // Reserve the caption's space so the control does not jump when the\n // first words arrive. Two lines' worth at each size, matching what\n // a typical utterance actually occupies.\n //\n // ★ 4.875rem is 3x the assistant caption's MINIMUM (1.625rem at 1.5\n // leading = two lines), tracking the type floor as the old 4.5rem\n // tracked 1.5rem. Honest about what that does and does not buy: it\n // removes the jump only while the clamp is at its floor, i.e. up to\n // ~1040px viewport, and the reserve is sized to the ASSISTANT\n // caption while the common transition out of it is to the smaller\n // USER caption. It is a compromise between two captions of\n // different sizes, not a guarantee.\n <div className={expanded ? 'mb-12 h-[4.875rem]' : 'mb-6 h-12'} aria-hidden=\"true\" />\n )}\n </>\n )}\n\n {control}\n </div>\n );\n};\n"],"mappings":";;;;;AA6CA,IAAa,KAAyB,EACpC,UACA,gBACA,qBACA,aACA,eACA,YACA,eAAY,WACR;CACJ,IAAM,IAAU,EAAsB,CAAK,IAAI,IAAmB,EAAiB,CAAK,IAAI,IAAc;CAE1G,OACE,kBAAC,OAAD;EACE,WAAW;GACT;GACA,IAAW,SAAS;GAMpB,IAAW,4BAA4B;EACzC,EAAE,KAAK,GAAG;EACV,eAAY;EACZ,cAAY;YAZd;GAeE,kBAAC,KAAD;IACE,WAAW;KACT;KACA,IAAW,cAAc;KAIzB,IAAW,SAAS;IACtB,EAAE,KAAK,GAAG;IAGV,aAAU;IACV,eAAY;cAEX;GACA,CAAA;GAEF,MAAU,cAGT,kBAAC,KAAD;IACE,WAAW,4CAA4C,IAAW,YAAY;IAC9E,MAAK;IACL,eAAY;cAEX;GACA,CAAA,IAEH,kBAAA,GAAA,EAAA,UAAA,CACE,kBAAC,OAAD;IAAK,WAAW,IAAW,UAAU;cACnC,kBAAC,GAAD;KAOE,QAAQ,EAAiB,CAAK;KAC9B,SAAS,EAAkB,CAAK;KAChC,MAAM,MAAU,aAAa,aAAa;KAChC;IACX,CAAA;GACE,CAAA,GAEJ,IACC,kBAAC,OAAD;IACE,WACE,IAKI,8CACA;cAGN,kBAAC,GAAD;KACE,MAAM;KACN,MAAM,EAAsB,CAAK,IAAI,cAAc;KACzC;KACV,QAAO;IACR,CAAA;GACE,CAAA,IAcL,kBAAC,OAAD;IAAK,WAAW,IAAW,uBAAuB;IAAa,eAAY;GAAQ,CAAA,CAErF,EAAA,CAAA;GAGH;EACE;;AAET"}
|
package/package.json
CHANGED