@burdenoff/microfe-healthybowl 2026.901.1 → 2026.901.2

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.
@@ -1,93 +1,94 @@
1
1
  import { useAssistantSpeech as e } from "../components/assistant/AssistantSpeechProvider.js";
2
2
  import { useVoiceInput as t } from "./useVoiceInput.js";
3
- import { INITIAL_SESSION as n, SILENCE_SUBMIT_MS as r, isCapturing as i, isSubmittable as a, spokenSoFar as o, voiceSessionReducer as s } from "../utils/voiceSession.js";
4
- import { useCallback as c, useEffect as l, useMemo as u, useReducer as d, useRef as f, useState as p } from "react";
3
+ import { INITIAL_SESSION as n, SILENCE_SUBMIT_MS as r, isCapturing as i, isSubmittable as a, planReplyConsumption as o, spokenSoFar as s, voiceSessionReducer as c } from "../utils/voiceSession.js";
4
+ import { useCallback as l, useEffect as u, useMemo as d, useReducer as f, useRef as p, useState as m } from "react";
5
5
  //#region src/hooks/useVoiceSession.ts
6
- var m = 4e3, h = 2500, g = 5e3, _ = 12e3, v = "data:audio/wav;base64,UklGRiQAAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQAAAAA=";
7
- function y({ onSubmit: y, latestReply: b, language: x }) {
8
- let S = f(null), [C, w] = d(c((e, t) => s(e, t, S.current), []), n), T = e(), { autoSpeakEnabled: E, setAutoSpeak: D, speakingMessageId: O, stop: k } = T, A = f(null), j = f(null), M = f(null), N = f(!1), [P, F] = p(null), I = f(C);
9
- I.current = C;
10
- let L = f(b);
11
- L.current = b, l(() => {
12
- if (C.phase === "speaking") {
13
- S.current = b?.text ?? null;
6
+ var h = 4e3, g = 2500, _ = 5e3, v = 12e3, y = "data:audio/wav;base64,UklGRiQAAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQAAAAA=";
7
+ function b({ onSubmit: b, latestReply: x, language: S }) {
8
+ let C = p(null), [w, T] = f(l((e, t) => c(e, t, C.current), []), n), E = e(), { autoSpeakEnabled: D, setAutoSpeak: O, speakingMessageId: k, stop: A } = E, j = p(null), M = p(null), N = p(null), P = p(!1), [F, I] = m(null), L = p(w);
9
+ L.current = w;
10
+ let R = p(x);
11
+ R.current = x, u(() => {
12
+ if (w.phase === "speaking") {
13
+ C.current = x?.text ?? null;
14
14
  return;
15
15
  }
16
- if (S.current === null) return;
16
+ if (C.current === null) return;
17
17
  let e = setTimeout(() => {
18
- S.current = null;
19
- }, h);
18
+ C.current = null;
19
+ }, g);
20
20
  return () => clearTimeout(e);
21
- }, [C.phase, b]);
22
- let R = c((e, t) => {
23
- w({
21
+ }, [w.phase, x]);
22
+ let z = l((e, t) => {
23
+ T({
24
24
  type: "speech",
25
25
  transcript: e,
26
26
  final: t
27
27
  });
28
- }, []), z = c(() => {
29
- k(), w({ type: "interrupt" });
30
- }, [k]), B = t({
31
- onFinalize: c((e) => R(e, !0), [R]),
32
- language: x
28
+ }, []), B = l(() => {
29
+ A(), T({ type: "interrupt" });
30
+ }, [A]), V = t({
31
+ onFinalize: l((e) => z(e, !0), [z]),
32
+ language: S
33
33
  });
34
- l(() => {
35
- B.interim && R(B.interim, !1);
36
- }, [B.interim, R]), l(() => {
37
- if (A.current && clearTimeout(A.current), !(C.phase !== "listening" || C.muted || !a(o(C)))) return A.current = setTimeout(() => w({ type: "silence" }), r), () => {
38
- A.current && clearTimeout(A.current);
34
+ u(() => {
35
+ V.interim && z(V.interim, !1);
36
+ }, [V.interim, z]), u(() => {
37
+ if (j.current && clearTimeout(j.current), !(w.phase !== "listening" || w.muted || !a(s(w)))) return j.current = setTimeout(() => T({ type: "silence" }), r), () => {
38
+ j.current && clearTimeout(j.current);
39
39
  };
40
- }, [C]);
41
- let V = f("");
42
- C.phase === "listening" && (V.current = o(C)), l(() => {
43
- if (C.phase !== "thinking") return;
44
- let e = V.current.trim();
45
- e && y(e);
46
- }, [C.phase]), l(() => {
47
- !b || C.phase !== "thinking" || M.current !== b.id && (M.current = b.id, w({
40
+ }, [w]);
41
+ let H = p("");
42
+ w.phase === "listening" && (H.current = s(w)), u(() => {
43
+ if (w.phase !== "thinking") return;
44
+ let e = H.current.trim();
45
+ e && b(e);
46
+ }, [w.phase]), u(() => {
47
+ let e = o(x?.id, w.phase, N.current);
48
+ e.claim && (N.current = x?.id ?? null, e.advance && x && T({
48
49
  type: "reply",
49
- text: b.text
50
+ text: x.text
50
51
  }));
51
- }, [b, C.phase]), l(() => {
52
- let e = O !== null;
53
- N.current && !e && w({ type: "speech-ended" }), N.current = e;
54
- }, [O]), l(() => {
55
- if (C.phase !== "speaking" || O !== null) return;
52
+ }, [x, w.phase]), u(() => {
53
+ let e = k !== null;
54
+ P.current && !e && T({ type: "speech-ended" }), P.current = e;
55
+ }, [k]), u(() => {
56
+ if (w.phase !== "speaking" || k !== null) return;
56
57
  let e = setTimeout(() => {
57
- N.current || w({ type: "speech-ended" });
58
- }, m);
58
+ P.current || T({ type: "speech-ended" });
59
+ }, h);
59
60
  return () => clearTimeout(e);
60
- }, [C.phase, O]), l(() => {
61
- i(C) ? B.isListening || B.start() : B.isListening && B.stop();
62
- }, [C, B]), l(() => {
63
- B.error === "not-allowed" || B.error === "audio-capture" ? w({
61
+ }, [w.phase, k]), u(() => {
62
+ i(w) ? V.isListening || V.start() : V.isListening && V.stop();
63
+ }, [w, V]), u(() => {
64
+ V.error === "not-allowed" || V.error === "audio-capture" ? T({
64
65
  type: "fail",
65
66
  error: "mic-denied"
66
- }) : B.error === "language-not-supported" ? w({
67
+ }) : V.error === "language-not-supported" ? T({
67
68
  type: "fail",
68
69
  error: "no-speech-support"
69
- }) : B.error === "network" && F("network");
70
- }, [B.error]), l(() => {
71
- if (!i(C) || B.isListening) return;
72
- let e = setTimeout(() => F("not-capturing"), g);
70
+ }) : V.error === "network" && I("network");
71
+ }, [V.error]), u(() => {
72
+ if (!i(w) || V.isListening) return;
73
+ let e = setTimeout(() => I("not-capturing"), _);
73
74
  return () => clearTimeout(e);
74
- }, [C, B.isListening]), l(() => {
75
- if (C.phase !== "listening" || C.muted || !B.isListening || o(C) !== "") return;
76
- let e = setTimeout(() => F("nothing-heard"), _);
75
+ }, [w, V.isListening]), u(() => {
76
+ if (w.phase !== "listening" || w.muted || !V.isListening || s(w) !== "") return;
77
+ let e = setTimeout(() => I("nothing-heard"), v);
77
78
  return () => clearTimeout(e);
78
- }, [C, B.isListening]), l(() => {
79
- o(C) !== "" && F(null);
80
- }, [C]);
81
- let H = c(() => {
82
- if (!B.isSupported) {
83
- w({
79
+ }, [w, V.isListening]), u(() => {
80
+ s(w) !== "" && I(null);
81
+ }, [w]);
82
+ let U = l(() => {
83
+ if (!V.isSupported) {
84
+ T({
84
85
  type: "fail",
85
86
  error: "no-speech-support"
86
87
  });
87
88
  return;
88
89
  }
89
- if (T.isBlocked) {
90
- w({
90
+ if (E.isBlocked) {
91
+ T({
91
92
  type: "fail",
92
93
  error: "no-voice-support"
93
94
  });
@@ -102,49 +103,49 @@ function y({ onSubmit: y, latestReply: b, language: x }) {
102
103
  } catch {}
103
104
  try {
104
105
  if (typeof window < "u" && typeof window.Audio == "function") {
105
- let e = new window.Audio(v);
106
+ let e = new window.Audio(y);
106
107
  e.volume = 0, e.play().catch(() => {});
107
108
  }
108
109
  } catch {}
109
- j.current = E, E || D(!0), F(null), M.current = L.current?.id ?? null, w({ type: "start" });
110
+ M.current = D, D || O(!0), I(null), N.current = R.current?.id ?? null, T({ type: "start" });
110
111
  }, [
111
- B.isSupported,
112
- T.isBlocked,
113
- E,
114
- D
115
- ]), U = c(() => {
116
- w({ type: "end" }), k(), j.current !== null && D(j.current), j.current = null;
117
- }, [k, D]), W = c(() => {
118
- w({
112
+ V.isSupported,
113
+ E.isBlocked,
114
+ D,
115
+ O
116
+ ]), W = l(() => {
117
+ T({ type: "end" }), A(), M.current !== null && O(M.current), M.current = null;
118
+ }, [A, O]), G = l(() => {
119
+ T({
119
120
  type: "mute",
120
- muted: !I.current.muted
121
+ muted: !L.current.muted
121
122
  });
122
123
  }, []);
123
- return l(() => () => {
124
- j.current !== null && D(j.current);
125
- }, [D]), u(() => ({
126
- session: C,
127
- notice: P,
128
- capturing: B.isListening,
129
- active: C.phase !== "idle" && C.phase !== "ended",
130
- available: B.isSupported && !T.isBlocked,
131
- start: H,
132
- end: U,
133
- toggleMute: W,
134
- interrupt: z
124
+ return u(() => () => {
125
+ M.current !== null && O(M.current);
126
+ }, [O]), d(() => ({
127
+ session: w,
128
+ notice: F,
129
+ capturing: V.isListening,
130
+ active: w.phase !== "idle" && w.phase !== "ended",
131
+ available: V.isSupported && !E.isBlocked,
132
+ start: U,
133
+ end: W,
134
+ toggleMute: G,
135
+ interrupt: B
135
136
  }), [
136
- C,
137
- P,
138
- B.isListening,
139
- B.isSupported,
140
- T.isBlocked,
141
- H,
137
+ w,
138
+ F,
139
+ V.isListening,
140
+ V.isSupported,
141
+ E.isBlocked,
142
142
  U,
143
143
  W,
144
- z
144
+ G,
145
+ B
145
146
  ]);
146
147
  }
147
148
  //#endregion
148
- export { y as useVoiceSession };
149
+ export { b as useVoiceSession };
149
150
 
150
151
  //# sourceMappingURL=useVoiceSession.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useVoiceSession.js","names":[],"sources":["../../src/hooks/useVoiceSession.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react';\nimport { useVoiceInput } from './useVoiceInput';\nimport { useAssistantSpeech } from '../components/assistant/AssistantSpeechProvider';\nimport {\n INITIAL_SESSION,\n SILENCE_SUBMIT_MS,\n isCapturing,\n isSubmittable,\n spokenSoFar,\n voiceSessionReducer,\n type VoiceSessionEvent,\n type VoiceSessionSnapshot,\n} from '../utils/voiceSession';\n\n/**\n * How long to wait for playback to actually start before assuming it never will.\n *\n * Generous enough to cover a hosted round trip (the voice is fetched, not local)\n * and short enough that a silent failure does not strand the session.\n */\nconst SPEECH_START_GRACE_MS = 4000;\n\n/**\n * How long the assistant's last reply stays usable as an echo reference after\n * playback ends.\n *\n * The recogniser emits a trailing FINAL result for speaker leakage a beat after\n * the audio stops. Without this window that result is treated as a fresh user\n * utterance and submitted, and the assistant answers itself — indefinitely.\n */\nconst ECHO_GRACE_MS = 2500;\n\n/**\n * How long the session may claim to be listening while the recogniser is not\n * actually running before saying so.\n *\n * Covers the permission prompt and the recogniser's own start-up, and is short\n * enough that a dead microphone is reported rather than mimed.\n */\nconst CAPTURE_START_GRACE_MS = 5000;\n\n/**\n * How long to listen with NOTHING heard at all before hinting that we may not\n * be hearing the user.\n *\n * Deliberately generous: a person thinking before they speak is normal, and a\n * hint that fires during a pause would be worse than no hint.\n */\nconst NOTHING_HEARD_MS = 12000;\n\n/**\n * A problem worth TELLING the user about that does not warrant killing the\n * session.\n *\n * These exist because the previous behaviour was the failure mode this whole\n * feature keeps hitting: the overlay said \"Listening…\" while the recogniser was\n * dead, and nothing anywhere said otherwise. `useVoiceInput` reports `network`\n * and `unknown` and the session ignored both.\n */\nexport type VoiceSessionNotice = 'network' | 'not-capturing' | 'nothing-heard';\n\n/** 44 bytes of silence — just enough to satisfy an autoplay unlock. */\nconst SILENT_WAV = 'data:audio/wav;base64,UklGRiQAAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQAAAAA=';\n\ninterface Options {\n /** Send a turn. The reply is observed via `latestReply`, not returned here. */\n onSubmit: (text: string) => void;\n /**\n * Id + text of the newest assistant reply. A CHANGE of id is what advances\n * the session out of `thinking` — the text alone is not enough, because two\n * consecutive replies can be identical.\n */\n latestReply: { id: string; text: string } | null;\n /** Language the user is speaking, so the recogniser is pointed correctly. */\n language: string;\n}\n\n/**\n * Drives a live voice conversation (BOFF-7120).\n *\n * Deliberately thin: the loop itself is `voiceSessionReducer`, which is pure and\n * tested, and playback is the assistant's EXISTING auto-speak path rather than a\n * second speaking mechanism. Reusing auto-speak is what keeps the \"never speak a\n * reply in a language this device has no voice for\" guarantee from BOFF-7106/7107\n * true inside the session too — a bespoke playback path here would have quietly\n * bypassed all of it.\n *\n * What this hook owns is only the parts a reducer cannot: the silence timer, the\n * microphone's lifetime, and turning \"auto-speak is currently on\" back off again\n * when the session ends.\n */\nexport function useVoiceSession({ onSubmit, latestReply, language }: Options) {\n /**\n * What the assistant is saying right now, so the reducer can tell an\n * interruption from its own voice echoing back through the speaker. Held in a\n * ref so the reducer identity stays stable across renders.\n */\n const spokenTextRef = useRef<string | null>(null);\n const reduce = useCallback(\n (snapshot: VoiceSessionSnapshot, event: VoiceSessionEvent) =>\n voiceSessionReducer(snapshot, event, spokenTextRef.current),\n []\n );\n const [session, dispatch] = useReducer(reduce, INITIAL_SESSION);\n const speech = useAssistantSpeech();\n const { autoSpeakEnabled, setAutoSpeak, speakingMessageId, stop: stopSpeaking } = speech;\n\n const silenceTimer = useRef<ReturnType<typeof setTimeout> | null>(null);\n /** Auto-speak as the user had it, so ending the session restores their choice. */\n const priorAutoSpeak = useRef<boolean | null>(null);\n /** The reply id already consumed, so one reply cannot advance two turns. */\n const consumedReplyId = useRef<string | null>(null);\n const wasSpeaking = useRef(false);\n const [notice, setNotice] = useState<VoiceSessionNotice | null>(null);\n\n const sessionRef = useRef(session);\n sessionRef.current = session;\n\n /**\n * The latest reply, readable from `start` without making it a dependency.\n *\n * `start` is a `useCallback` the UI holds across renders; adding `latestReply`\n * to its deps would rebuild the handler every time a message arrives.\n */\n const latestReplyRef = useRef(latestReply);\n latestReplyRef.current = latestReply;\n\n // The echo reference: the reply being spoken, held for a grace period after\n // playback stops. Cleared only once that window expires, so the recogniser's\n // trailing final result is still recognisable as echo.\n useEffect(() => {\n if (session.phase === 'speaking') {\n spokenTextRef.current = latestReply?.text ?? null;\n return;\n }\n if (spokenTextRef.current === null) return;\n const timer = setTimeout(() => {\n spokenTextRef.current = null;\n }, ECHO_GRACE_MS);\n return () => clearTimeout(timer);\n }, [session.phase, latestReply]);\n\n const handleSpeech = useCallback((transcript: string, final: boolean) => {\n dispatch({ type: 'speech', transcript, final });\n }, []);\n\n /**\n * Cut the assistant off. An explicit tap, never inferred from audio — the\n * microphone is closed while it speaks, precisely so its own voice cannot be\n * mistaken for the user's.\n */\n const interrupt = useCallback(() => {\n stopSpeaking();\n dispatch({ type: 'interrupt' });\n }, [stopSpeaking]);\n\n // `onFinalize` delivers each NEWLY finalised phrase on its own, so these are\n // committed and accumulated by the reducer rather than replacing what came\n // before — see the composer's `appendTranscript` for the same contract.\n const handleFinal = useCallback((phrase: string) => handleSpeech(phrase, true), [handleSpeech]);\n const voice = useVoiceInput({ onFinalize: handleFinal, language });\n\n // Interim results are what make barge-in feel immediate; waiting for the\n // recogniser to finalise would leave the assistant talking over the user.\n useEffect(() => {\n if (voice.interim) handleSpeech(voice.interim, false);\n }, [voice.interim, handleSpeech]);\n\n // Silence submits the turn. Restarted on every new fragment, so the timer\n // measures silence rather than elapsed time since the turn began.\n useEffect(() => {\n if (silenceTimer.current) clearTimeout(silenceTimer.current);\n if (session.phase !== 'listening' || session.muted || !isSubmittable(spokenSoFar(session))) return;\n silenceTimer.current = setTimeout(() => dispatch({ type: 'silence' }), SILENCE_SUBMIT_MS);\n return () => {\n if (silenceTimer.current) clearTimeout(silenceTimer.current);\n };\n }, [session]);\n\n // Submitting is a side effect OF entering `thinking`, not part of the\n // reduction — the reducer stays pure.\n const pendingAtSubmit = useRef('');\n if (session.phase === 'listening') pendingAtSubmit.current = spokenSoFar(session);\n useEffect(() => {\n if (session.phase !== 'thinking') return;\n const text = pendingAtSubmit.current.trim();\n if (text) onSubmit(text);\n // `onSubmit` deliberately not a dependency: a parent that recreates it each\n // render would otherwise resubmit the same turn repeatedly.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [session.phase]);\n\n // A NEW reply id advances the session. Guarded so a re-render, or two\n // identical answers in a row, cannot double-advance it.\n useEffect(() => {\n if (!latestReply || session.phase !== 'thinking') return;\n if (consumedReplyId.current === latestReply.id) return;\n consumedReplyId.current = latestReply.id;\n dispatch({ type: 'reply', text: latestReply.text });\n }, [latestReply, session.phase]);\n\n // Playback finishing returns us to listening, detected on the FALLING edge of\n // `speakingMessageId`.\n useEffect(() => {\n const speakingNow = speakingMessageId !== null;\n if (wasSpeaking.current && !speakingNow) dispatch({ type: 'speech-ended' });\n wasSpeaking.current = speakingNow;\n }, [speakingMessageId]);\n\n /**\n * ★ A falling edge needs a RISING edge first.\n *\n * When a reply is never spoken at all — no installed voice for that language,\n * or the browser's autoplay policy refuses because auto-speak is not a user\n * gesture — `speakingMessageId` never becomes non-null, so the effect above\n * can never fire and the session hangs in `speaking` forever with the\n * microphone open and no way back except ending it.\n *\n * So entering `speaking` starts a watchdog: if nothing has actually begun\n * speaking shortly after, the turn is handed back and the conversation\n * continues silently rather than dying.\n */\n useEffect(() => {\n if (session.phase !== 'speaking' || speakingMessageId !== null) return;\n const timer = setTimeout(() => {\n if (!wasSpeaking.current) dispatch({ type: 'speech-ended' });\n }, SPEECH_START_GRACE_MS);\n return () => clearTimeout(timer);\n }, [session.phase, speakingMessageId]);\n\n // The microphone follows the state machine, including while the assistant\n // speaks — barge-in is impossible with a closed microphone.\n useEffect(() => {\n if (isCapturing(session)) {\n if (!voice.isListening) voice.start();\n } else if (voice.isListening) {\n voice.stop();\n }\n }, [session, voice]);\n\n // Only the FATAL recognition errors end the session. `no-speech`, `network`\n // and `unknown` are transient — the recogniser recovers from them, and tearing\n // the session down on a moment's silence or a network blip would be worse than\n // the problem.\n useEffect(() => {\n if (voice.error === 'not-allowed' || voice.error === 'audio-capture') {\n dispatch({ type: 'fail', error: 'mic-denied' });\n } else if (voice.error === 'language-not-supported') {\n dispatch({ type: 'fail', error: 'no-speech-support' });\n } else if (voice.error === 'network') {\n // Chrome's recogniser is a NETWORK service. Losing it leaves the session\n // deaf while still looking alive, so it is reported rather than ignored —\n // but not fatal, because it recovers on its own.\n setNotice('network');\n }\n }, [voice.error]);\n\n // Say so when we claim to be listening but the recogniser never actually\n // started. `useVoiceInput.start()` swallows a throw and simply leaves\n // `isListening` false, which previously produced a silent, permanent\n // \"Listening…\".\n useEffect(() => {\n if (!isCapturing(session) || voice.isListening) return;\n const timer = setTimeout(() => setNotice('not-capturing'), CAPTURE_START_GRACE_MS);\n return () => clearTimeout(timer);\n }, [session, voice.isListening]);\n\n // And say so when the microphone IS running but has heard nothing at all.\n useEffect(() => {\n if (session.phase !== 'listening' || session.muted || !voice.isListening) return;\n if (spokenSoFar(session) !== '') return;\n const timer = setTimeout(() => setNotice('nothing-heard'), NOTHING_HEARD_MS);\n return () => clearTimeout(timer);\n }, [session, voice.isListening]);\n\n // Any successful capture clears the complaint — the recogniser recovered.\n useEffect(() => {\n if (spokenSoFar(session) !== '') setNotice(null);\n }, [session]);\n\n const start = useCallback(() => {\n if (!voice.isSupported) {\n dispatch({ type: 'fail', error: 'no-speech-support' });\n return;\n }\n if (speech.isBlocked) {\n dispatch({ type: 'fail', error: 'no-voice-support' });\n return;\n }\n // Replies must be spoken for a voice conversation to be a conversation, so\n // auto-speak is forced on for the session and the user's own setting is\n // restored on exit.\n // ★ Unlock audio while we still hold a user gesture.\n //\n // iOS refuses `speechSynthesis.speak()` unless it originates from a user\n // interaction. In a session the reply arrives asynchronously and auto-speak\n // fires on its own, which is NOT a gesture — so on iPhone the assistant\n // answered on screen and stayed silent. Speaking an empty utterance inside\n // this click unlocks synthesis for the rest of the session.\n // BOTH media paths, because they are gated independently. `speechSynthesis`\n // is what the device engine uses; the hosted engine plays an\n // `HTMLAudioElement` (`new Audio(...).play()` in hostedTtsSpeechEngine), and\n // unlocking one does NOT unlock the other. Priming only synthesis would work\n // today and go silent again the moment hosted TTS is switched on — the same\n // iOS silence, reintroduced by a fix for it.\n try {\n const synthesis = typeof window !== 'undefined' ? window.speechSynthesis : null;\n if (synthesis && typeof window.SpeechSynthesisUtterance === 'function') {\n const primer = new window.SpeechSynthesisUtterance('');\n primer.volume = 0;\n synthesis.speak(primer);\n }\n } catch {\n // Best effort: a platform that throws here is one where playback was\n // never going to work, and the watchdog reports that.\n }\n\n try {\n if (typeof window !== 'undefined' && typeof window.Audio === 'function') {\n // A minimal silent WAV. Playing it inside the gesture is what grants the\n // media element permission for the rest of the session.\n const silent = new window.Audio(SILENT_WAV);\n silent.volume = 0;\n void silent.play().catch(() => {});\n }\n } catch {\n /* same rationale as above */\n }\n\n priorAutoSpeak.current = autoSpeakEnabled;\n if (!autoSpeakEnabled) setAutoSpeak(true);\n setNotice(null);\n\n /**\n * ★ Claim whatever reply already exists, so the first turn cannot consume it.\n *\n * `consumedReplyId` starts null, and conversations are persisted — so on the\n * first turn of a reopened session `latestReply` is the PREVIOUS answer. The\n * reply effect fired the moment the phase became `thinking`, consumed that\n * stale answer and advanced to `speaking`. Nothing was actually playing, so\n * the watchdog handed the turn back to `listening` while the real reply was\n * still in flight — with the echo reference already cleared. The microphone\n * was then open when the real answer came out of the speaker, transcribed\n * it, and submitted the assistant's own words as the next question.\n *\n * It never re-synced either: the real reply then arrived while the phase was\n * `listening`, so the effect returned early without updating the id, and\n * every following turn repeated the same stale advance. That is the \"it\n * gives result different things\" report, and it is not mis-hearing anyone.\n */\n consumedReplyId.current = latestReplyRef.current?.id ?? null;\n dispatch({ type: 'start' });\n }, [voice.isSupported, speech.isBlocked, autoSpeakEnabled, setAutoSpeak]);\n\n const end = useCallback(() => {\n dispatch({ type: 'end' });\n stopSpeaking();\n if (priorAutoSpeak.current !== null) setAutoSpeak(priorAutoSpeak.current);\n priorAutoSpeak.current = null;\n }, [stopSpeaking, setAutoSpeak]);\n\n const toggleMute = useCallback(() => {\n dispatch({ type: 'mute', muted: !sessionRef.current.muted });\n }, []);\n\n // Leaving the panel mid-session must not leave the microphone open or the\n // user's auto-speak preference flipped.\n useEffect(\n () => () => {\n if (priorAutoSpeak.current !== null) setAutoSpeak(priorAutoSpeak.current);\n },\n [setAutoSpeak]\n );\n\n return useMemo(\n () => ({\n session,\n /** A recoverable problem worth showing, or null when all is well. */\n notice,\n /** Whether the microphone is genuinely capturing right now. */\n capturing: voice.isListening,\n /** True once started and not yet ended — what decides whether to render. */\n active: session.phase !== 'idle' && session.phase !== 'ended',\n /** Can a session be offered at all on this device? */\n available: voice.isSupported && !speech.isBlocked,\n start,\n end,\n toggleMute,\n interrupt,\n }),\n [session, notice, voice.isListening, voice.isSupported, speech.isBlocked, start, end, toggleMute, interrupt]\n );\n}\n"],"mappings":";;;;;AAoBA,IAAM,IAAwB,KAUxB,IAAgB,MAShB,IAAyB,KASzB,IAAmB,MAcnB,IAAa;AA6BnB,SAAgB,EAAgB,EAAE,aAAU,gBAAa,eAAqB;CAM5E,IAAM,IAAgB,EAAsB,IAAI,GAM1C,CAAC,GAAS,KAAY,EALb,GACZ,GAAgC,MAC/B,EAAoB,GAAU,GAAO,EAAc,OAAO,GAC5D,CAAC,CAEoC,GAAQ,CAAe,GACxD,IAAS,EAAmB,GAC5B,EAAE,qBAAkB,iBAAc,sBAAmB,MAAM,MAAiB,GAE5E,IAAe,EAA6C,IAAI,GAEhE,IAAiB,EAAuB,IAAI,GAE5C,IAAkB,EAAsB,IAAI,GAC5C,IAAc,EAAO,EAAK,GAC1B,CAAC,GAAQ,KAAa,EAAoC,IAAI,GAE9D,IAAa,EAAO,CAAO;CACjC,EAAW,UAAU;CAQrB,IAAM,IAAiB,EAAO,CAAW;CAMzC,AALA,EAAe,UAAU,GAKzB,QAAgB;EACd,IAAI,EAAQ,UAAU,YAAY;GAChC,EAAc,UAAU,GAAa,QAAQ;GAC7C;EACF;EACA,IAAI,EAAc,YAAY,MAAM;EACpC,IAAM,IAAQ,iBAAiB;GAC7B,EAAc,UAAU;EAC1B,GAAG,CAAa;EAChB,aAAa,aAAa,CAAK;CACjC,GAAG,CAAC,EAAQ,OAAO,CAAW,CAAC;CAE/B,IAAM,IAAe,GAAa,GAAoB,MAAmB;EACvE,EAAS;GAAE,MAAM;GAAU;GAAY;EAAM,CAAC;CAChD,GAAG,CAAC,CAAC,GAOC,IAAY,QAAkB;EAElC,AADA,EAAa,GACb,EAAS,EAAE,MAAM,YAAY,CAAC;CAChC,GAAG,CAAC,CAAY,CAAC,GAMX,IAAQ,EAAc;EAAE,YAD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sourcesContent":["import { useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react';\nimport { useVoiceInput } from './useVoiceInput';\nimport { useAssistantSpeech } from '../components/assistant/AssistantSpeechProvider';\nimport {\n INITIAL_SESSION,\n SILENCE_SUBMIT_MS,\n isCapturing,\n isSubmittable,\n planReplyConsumption,\n spokenSoFar,\n type VoiceSessionEvent,\n type VoiceSessionSnapshot,\n voiceSessionReducer,\n} from '../utils/voiceSession';\n\n/**\n * How long to wait for playback to actually start before assuming it never will.\n *\n * Generous enough to cover a hosted round trip (the voice is fetched, not local)\n * and short enough that a silent failure does not strand the session.\n */\nconst SPEECH_START_GRACE_MS = 4000;\n\n/**\n * How long the assistant's last reply stays usable as an echo reference after\n * playback ends.\n *\n * The recogniser emits a trailing FINAL result for speaker leakage a beat after\n * the audio stops. Without this window that result is treated as a fresh user\n * utterance and submitted, and the assistant answers itself — indefinitely.\n */\nconst ECHO_GRACE_MS = 2500;\n\n/**\n * How long the session may claim to be listening while the recogniser is not\n * actually running before saying so.\n *\n * Covers the permission prompt and the recogniser's own start-up, and is short\n * enough that a dead microphone is reported rather than mimed.\n */\nconst CAPTURE_START_GRACE_MS = 5000;\n\n/**\n * How long to listen with NOTHING heard at all before hinting that we may not\n * be hearing the user.\n *\n * Deliberately generous: a person thinking before they speak is normal, and a\n * hint that fires during a pause would be worse than no hint.\n */\nconst NOTHING_HEARD_MS = 12000;\n\n/**\n * A problem worth TELLING the user about that does not warrant killing the\n * session.\n *\n * These exist because the previous behaviour was the failure mode this whole\n * feature keeps hitting: the overlay said \"Listening…\" while the recogniser was\n * dead, and nothing anywhere said otherwise. `useVoiceInput` reports `network`\n * and `unknown` and the session ignored both.\n */\nexport type VoiceSessionNotice = 'network' | 'not-capturing' | 'nothing-heard';\n\n/** 44 bytes of silence — just enough to satisfy an autoplay unlock. */\nconst SILENT_WAV = 'data:audio/wav;base64,UklGRiQAAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQAAAAA=';\n\ninterface Options {\n /** Send a turn. The reply is observed via `latestReply`, not returned here. */\n onSubmit: (text: string) => void;\n /**\n * Id + text of the newest assistant reply. A CHANGE of id is what advances\n * the session out of `thinking` — the text alone is not enough, because two\n * consecutive replies can be identical.\n */\n latestReply: { id: string; text: string } | null;\n /** Language the user is speaking, so the recogniser is pointed correctly. */\n language: string;\n}\n\n/**\n * Drives a live voice conversation (BOFF-7120).\n *\n * Deliberately thin: the loop itself is `voiceSessionReducer`, which is pure and\n * tested, and playback is the assistant's EXISTING auto-speak path rather than a\n * second speaking mechanism. Reusing auto-speak is what keeps the \"never speak a\n * reply in a language this device has no voice for\" guarantee from BOFF-7106/7107\n * true inside the session too — a bespoke playback path here would have quietly\n * bypassed all of it.\n *\n * What this hook owns is only the parts a reducer cannot: the silence timer, the\n * microphone's lifetime, and turning \"auto-speak is currently on\" back off again\n * when the session ends.\n */\nexport function useVoiceSession({ onSubmit, latestReply, language }: Options) {\n /**\n * What the assistant is saying right now, so the reducer can tell an\n * interruption from its own voice echoing back through the speaker. Held in a\n * ref so the reducer identity stays stable across renders.\n */\n const spokenTextRef = useRef<string | null>(null);\n const reduce = useCallback(\n (snapshot: VoiceSessionSnapshot, event: VoiceSessionEvent) =>\n voiceSessionReducer(snapshot, event, spokenTextRef.current),\n []\n );\n const [session, dispatch] = useReducer(reduce, INITIAL_SESSION);\n const speech = useAssistantSpeech();\n const { autoSpeakEnabled, setAutoSpeak, speakingMessageId, stop: stopSpeaking } = speech;\n\n const silenceTimer = useRef<ReturnType<typeof setTimeout> | null>(null);\n /** Auto-speak as the user had it, so ending the session restores their choice. */\n const priorAutoSpeak = useRef<boolean | null>(null);\n /** The reply id already consumed, so one reply cannot advance two turns. */\n const consumedReplyId = useRef<string | null>(null);\n const wasSpeaking = useRef(false);\n const [notice, setNotice] = useState<VoiceSessionNotice | null>(null);\n\n const sessionRef = useRef(session);\n sessionRef.current = session;\n\n /**\n * The latest reply, readable from `start` without making it a dependency.\n *\n * `start` is a `useCallback` the UI holds across renders; adding `latestReply`\n * to its deps would rebuild the handler every time a message arrives.\n */\n const latestReplyRef = useRef(latestReply);\n latestReplyRef.current = latestReply;\n\n // The echo reference: the reply being spoken, held for a grace period after\n // playback stops. Cleared only once that window expires, so the recogniser's\n // trailing final result is still recognisable as echo.\n useEffect(() => {\n if (session.phase === 'speaking') {\n spokenTextRef.current = latestReply?.text ?? null;\n return;\n }\n if (spokenTextRef.current === null) return;\n const timer = setTimeout(() => {\n spokenTextRef.current = null;\n }, ECHO_GRACE_MS);\n return () => clearTimeout(timer);\n }, [session.phase, latestReply]);\n\n const handleSpeech = useCallback((transcript: string, final: boolean) => {\n dispatch({ type: 'speech', transcript, final });\n }, []);\n\n /**\n * Cut the assistant off. An explicit tap, never inferred from audio — the\n * microphone is closed while it speaks, precisely so its own voice cannot be\n * mistaken for the user's.\n */\n const interrupt = useCallback(() => {\n stopSpeaking();\n dispatch({ type: 'interrupt' });\n }, [stopSpeaking]);\n\n // `onFinalize` delivers each NEWLY finalised phrase on its own, so these are\n // committed and accumulated by the reducer rather than replacing what came\n // before — see the composer's `appendTranscript` for the same contract.\n const handleFinal = useCallback((phrase: string) => handleSpeech(phrase, true), [handleSpeech]);\n const voice = useVoiceInput({ onFinalize: handleFinal, language });\n\n // Interim results are what make barge-in feel immediate; waiting for the\n // recogniser to finalise would leave the assistant talking over the user.\n useEffect(() => {\n if (voice.interim) handleSpeech(voice.interim, false);\n }, [voice.interim, handleSpeech]);\n\n // Silence submits the turn. Restarted on every new fragment, so the timer\n // measures silence rather than elapsed time since the turn began.\n useEffect(() => {\n if (silenceTimer.current) clearTimeout(silenceTimer.current);\n if (session.phase !== 'listening' || session.muted || !isSubmittable(spokenSoFar(session))) return;\n silenceTimer.current = setTimeout(() => dispatch({ type: 'silence' }), SILENCE_SUBMIT_MS);\n return () => {\n if (silenceTimer.current) clearTimeout(silenceTimer.current);\n };\n }, [session]);\n\n // Submitting is a side effect OF entering `thinking`, not part of the\n // reduction — the reducer stays pure.\n const pendingAtSubmit = useRef('');\n if (session.phase === 'listening') pendingAtSubmit.current = spokenSoFar(session);\n useEffect(() => {\n if (session.phase !== 'thinking') return;\n const text = pendingAtSubmit.current.trim();\n if (text) onSubmit(text);\n // `onSubmit` deliberately not a dependency: a parent that recreates it each\n // render would otherwise resubmit the same turn repeatedly.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [session.phase]);\n\n /**\n * A NEW reply id advances the session. Guarded so a re-render, or two\n * identical answers in a row, cannot double-advance it.\n *\n * ★ A reply that lands while we are NOT thinking is CLAIMED, not ignored.\n *\n * Interrupting only stops playback — nothing cancels the model, so the\n * abandoned answer still arrives seconds later, while the phase is\n * `listening`. The old guard returned early WITHOUT recording its id, which\n * left it sitting there unconsumed; the next question then entered\n * `thinking`, found that stale reply, and spoke the answer to the question\n * the user had already cut off. Ending and restarting a session had the same\n * shape.\n *\n * So the rule is: a reply arriving outside a thinking phase belongs to a turn\n * that is over. Record it so it can never advance a LATER turn, and do not\n * act on it. This is the general form of the seeding fix — that one stopped\n * the FIRST turn consuming a persisted reply, this one stops every abandoned\n * turn doing the same thing.\n */\n useEffect(() => {\n const plan = planReplyConsumption(latestReply?.id, session.phase, consumedReplyId.current);\n if (!plan.claim) return;\n consumedReplyId.current = latestReply?.id ?? null;\n if (plan.advance && latestReply) dispatch({ type: 'reply', text: latestReply.text });\n }, [latestReply, session.phase]);\n\n // Playback finishing returns us to listening, detected on the FALLING edge of\n // `speakingMessageId`.\n useEffect(() => {\n const speakingNow = speakingMessageId !== null;\n if (wasSpeaking.current && !speakingNow) dispatch({ type: 'speech-ended' });\n wasSpeaking.current = speakingNow;\n }, [speakingMessageId]);\n\n /**\n * ★ A falling edge needs a RISING edge first.\n *\n * When a reply is never spoken at all — no installed voice for that language,\n * or the browser's autoplay policy refuses because auto-speak is not a user\n * gesture — `speakingMessageId` never becomes non-null, so the effect above\n * can never fire and the session hangs in `speaking` forever with the\n * microphone open and no way back except ending it.\n *\n * So entering `speaking` starts a watchdog: if nothing has actually begun\n * speaking shortly after, the turn is handed back and the conversation\n * continues silently rather than dying.\n */\n useEffect(() => {\n if (session.phase !== 'speaking' || speakingMessageId !== null) return;\n const timer = setTimeout(() => {\n if (!wasSpeaking.current) dispatch({ type: 'speech-ended' });\n }, SPEECH_START_GRACE_MS);\n return () => clearTimeout(timer);\n }, [session.phase, speakingMessageId]);\n\n // The microphone follows the state machine, including while the assistant\n // speaks — barge-in is impossible with a closed microphone.\n useEffect(() => {\n if (isCapturing(session)) {\n if (!voice.isListening) voice.start();\n } else if (voice.isListening) {\n voice.stop();\n }\n }, [session, voice]);\n\n // Only the FATAL recognition errors end the session. `no-speech`, `network`\n // and `unknown` are transient — the recogniser recovers from them, and tearing\n // the session down on a moment's silence or a network blip would be worse than\n // the problem.\n useEffect(() => {\n if (voice.error === 'not-allowed' || voice.error === 'audio-capture') {\n dispatch({ type: 'fail', error: 'mic-denied' });\n } else if (voice.error === 'language-not-supported') {\n dispatch({ type: 'fail', error: 'no-speech-support' });\n } else if (voice.error === 'network') {\n // Chrome's recogniser is a NETWORK service. Losing it leaves the session\n // deaf while still looking alive, so it is reported rather than ignored —\n // but not fatal, because it recovers on its own.\n setNotice('network');\n }\n }, [voice.error]);\n\n // Say so when we claim to be listening but the recogniser never actually\n // started. `useVoiceInput.start()` swallows a throw and simply leaves\n // `isListening` false, which previously produced a silent, permanent\n // \"Listening…\".\n useEffect(() => {\n if (!isCapturing(session) || voice.isListening) return;\n const timer = setTimeout(() => setNotice('not-capturing'), CAPTURE_START_GRACE_MS);\n return () => clearTimeout(timer);\n }, [session, voice.isListening]);\n\n // And say so when the microphone IS running but has heard nothing at all.\n useEffect(() => {\n if (session.phase !== 'listening' || session.muted || !voice.isListening) return;\n if (spokenSoFar(session) !== '') return;\n const timer = setTimeout(() => setNotice('nothing-heard'), NOTHING_HEARD_MS);\n return () => clearTimeout(timer);\n }, [session, voice.isListening]);\n\n // Any successful capture clears the complaint — the recogniser recovered.\n useEffect(() => {\n if (spokenSoFar(session) !== '') setNotice(null);\n }, [session]);\n\n const start = useCallback(() => {\n if (!voice.isSupported) {\n dispatch({ type: 'fail', error: 'no-speech-support' });\n return;\n }\n if (speech.isBlocked) {\n dispatch({ type: 'fail', error: 'no-voice-support' });\n return;\n }\n // Replies must be spoken for a voice conversation to be a conversation, so\n // auto-speak is forced on for the session and the user's own setting is\n // restored on exit.\n // ★ Unlock audio while we still hold a user gesture.\n //\n // iOS refuses `speechSynthesis.speak()` unless it originates from a user\n // interaction. In a session the reply arrives asynchronously and auto-speak\n // fires on its own, which is NOT a gesture — so on iPhone the assistant\n // answered on screen and stayed silent. Speaking an empty utterance inside\n // this click unlocks synthesis for the rest of the session.\n // BOTH media paths, because they are gated independently. `speechSynthesis`\n // is what the device engine uses; the hosted engine plays an\n // `HTMLAudioElement` (`new Audio(...).play()` in hostedTtsSpeechEngine), and\n // unlocking one does NOT unlock the other. Priming only synthesis would work\n // today and go silent again the moment hosted TTS is switched on — the same\n // iOS silence, reintroduced by a fix for it.\n try {\n const synthesis = typeof window !== 'undefined' ? window.speechSynthesis : null;\n if (synthesis && typeof window.SpeechSynthesisUtterance === 'function') {\n const primer = new window.SpeechSynthesisUtterance('');\n primer.volume = 0;\n synthesis.speak(primer);\n }\n } catch {\n // Best effort: a platform that throws here is one where playback was\n // never going to work, and the watchdog reports that.\n }\n\n try {\n if (typeof window !== 'undefined' && typeof window.Audio === 'function') {\n // A minimal silent WAV. Playing it inside the gesture is what grants the\n // media element permission for the rest of the session.\n const silent = new window.Audio(SILENT_WAV);\n silent.volume = 0;\n void silent.play().catch(() => {});\n }\n } catch {\n /* same rationale as above */\n }\n\n priorAutoSpeak.current = autoSpeakEnabled;\n if (!autoSpeakEnabled) setAutoSpeak(true);\n setNotice(null);\n\n /**\n * ★ Claim whatever reply already exists, so the first turn cannot consume it.\n *\n * `consumedReplyId` starts null, and conversations are persisted — so on the\n * first turn of a reopened session `latestReply` is the PREVIOUS answer. The\n * reply effect fired the moment the phase became `thinking`, consumed that\n * stale answer and advanced to `speaking`. Nothing was actually playing, so\n * the watchdog handed the turn back to `listening` while the real reply was\n * still in flight — with the echo reference already cleared. The microphone\n * was then open when the real answer came out of the speaker, transcribed\n * it, and submitted the assistant's own words as the next question.\n *\n * It never re-synced either: the real reply then arrived while the phase was\n * `listening`, so the effect returned early without updating the id, and\n * every following turn repeated the same stale advance. That is the \"it\n * gives result different things\" report, and it is not mis-hearing anyone.\n */\n consumedReplyId.current = latestReplyRef.current?.id ?? null;\n dispatch({ type: 'start' });\n }, [voice.isSupported, speech.isBlocked, autoSpeakEnabled, setAutoSpeak]);\n\n const end = useCallback(() => {\n dispatch({ type: 'end' });\n stopSpeaking();\n if (priorAutoSpeak.current !== null) setAutoSpeak(priorAutoSpeak.current);\n priorAutoSpeak.current = null;\n }, [stopSpeaking, setAutoSpeak]);\n\n const toggleMute = useCallback(() => {\n dispatch({ type: 'mute', muted: !sessionRef.current.muted });\n }, []);\n\n // Leaving the panel mid-session must not leave the microphone open or the\n // user's auto-speak preference flipped.\n useEffect(\n () => () => {\n if (priorAutoSpeak.current !== null) setAutoSpeak(priorAutoSpeak.current);\n },\n [setAutoSpeak]\n );\n\n return useMemo(\n () => ({\n session,\n /** A recoverable problem worth showing, or null when all is well. */\n notice,\n /** Whether the microphone is genuinely capturing right now. */\n capturing: voice.isListening,\n /** True once started and not yet ended — what decides whether to render. */\n active: session.phase !== 'idle' && session.phase !== 'ended',\n /** Can a session be offered at all on this device? */\n available: voice.isSupported && !speech.isBlocked,\n start,\n end,\n toggleMute,\n interrupt,\n }),\n [session, notice, voice.isListening, voice.isSupported, speech.isBlocked, start, end, toggleMute, interrupt]\n );\n}\n"],"mappings":";;;;;AAqBA,IAAM,IAAwB,KAUxB,IAAgB,MAShB,IAAyB,KASzB,IAAmB,MAcnB,IAAa;AA6BnB,SAAgB,EAAgB,EAAE,aAAU,gBAAa,eAAqB;CAM5E,IAAM,IAAgB,EAAsB,IAAI,GAM1C,CAAC,GAAS,K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AAE,YAAY,CAAC,CAAC;GACnC;EACF,QAAQ,CAER;EAwBA,AAtBA,EAAe,UAAU,GACpB,KAAkB,EAAa,EAAI,GACxC,EAAU,IAAI,GAmBd,EAAgB,UAAU,EAAe,SAAS,MAAM,MACxD,EAAS,EAAE,MAAM,QAAQ,CAAC;CAC5B,GAAG;EAAC,EAAM;EAAa,EAAO;EAAW;EAAkB;CAAY,CAAC,GAElE,IAAM,QAAkB;EAI5B,AAHA,EAAS,EAAE,MAAM,MAAM,CAAC,GACxB,EAAa,GACT,EAAe,YAAY,QAAM,EAAa,EAAe,OAAO,GACxE,EAAe,UAAU;CAC3B,GAAG,CAAC,GAAc,CAAY,CAAC,GAEzB,IAAa,QAAkB;EACnC,EAAS;GAAE,MAAM;GAAQ,OAAO,CAAC,EAAW,QAAQ;EAAM,CAAC;CAC7D,GAAG,CAAC,CAAC;CAWL,OAPA,cACc;EACV,AAAI,EAAe,YAAY,QAAM,EAAa,EAAe,OAAO;CAC1E,GACA,CAAC,CAAY,CACf,GAEO,SACE;EACL;EAEA;EAEA,WAAW,EAAM;EAEjB,QAAQ,EAAQ,UAAU,UAAU,EAAQ,UAAU;EAEtD,WAAW,EAAM,eAAe,CAAC,EAAO;EACxC;EACA;EACA;EACA;CACF,IACA;EAAC;EAAS;EAAQ,EAAM;EAAa,EAAM;EAAa,EAAO;EAAW;EAAO;EAAK;EAAY;CAAS,CAC7G;AACF"}
@@ -15,16 +15,25 @@ function a(e, t) {
15
15
  let n = r(e);
16
16
  return n.length === 0 ? !0 : n.split(" ").length < i ? !1 : ` ${r(t)} `.includes(` ${n} `);
17
17
  }
18
- var o = Object.freeze({
18
+ function o(e, t, n) {
19
+ return !e || e === n ? {
20
+ claim: !1,
21
+ advance: !1
22
+ } : {
23
+ claim: !0,
24
+ advance: t === "thinking"
25
+ };
26
+ }
27
+ var s = Object.freeze({
19
28
  phase: "idle",
20
29
  muted: !1,
21
30
  pending: "",
22
31
  interim: "",
23
32
  error: null
24
33
  });
25
- function s(e, r, i = null) {
34
+ function c(e, r, i = null) {
26
35
  if (r.type === "start") return {
27
- ...o,
36
+ ...s,
28
37
  phase: "listening"
29
38
  };
30
39
  if (e.phase === "ended") return e;
@@ -83,10 +92,10 @@ function s(e, r, i = null) {
83
92
  default: return e;
84
93
  }
85
94
  }
86
- function c(e) {
95
+ function l(e) {
87
96
  return e.muted ? !1 : e.phase === "listening";
88
97
  }
89
- function l(e) {
98
+ function u(e) {
90
99
  switch (e.phase) {
91
100
  case "thinking": return "thinking";
92
101
  case "speaking": return "speaking";
@@ -95,6 +104,6 @@ function l(e) {
95
104
  }
96
105
  }
97
106
  //#endregion
98
- export { o as INITIAL_SESSION, e as SILENCE_SUBMIT_MS, c as isCapturing, t as isSubmittable, l as orbMode, n as spokenSoFar, s as voiceSessionReducer };
107
+ export { s as INITIAL_SESSION, e as SILENCE_SUBMIT_MS, l as isCapturing, t as isSubmittable, u as orbMode, o as planReplyConsumption, n as spokenSoFar, c as voiceSessionReducer };
99
108
 
100
109
  //# sourceMappingURL=voiceSession.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"voiceSession.js","names":[],"sources":["../../src/utils/voiceSession.ts"],"sourcesContent":["/**\n * The voice-conversation state machine (BOFF-7120).\n *\n * A live voice session is a loop — listen, submit, wait, speak, listen again —\n * and every interesting decision in it is about TIMING and INTERRUPTION rather\n * than about rendering. Those decisions live here, with no DOM, no audio and no\n * React, for the same reason `browserSpeechEngine` pushed its logic into\n * `speakableText`/`speechVoices`: this repo's vitest runs in the `node`\n * environment, so anything touching `window` cannot be tested at all.\n *\n * ★ **The microphone is CLOSED while the assistant speaks.** It was open, so\n * that talking over the assistant could interrupt it, guarded by matching the\n * transcript against the text being spoken. That guard was too weak to survive\n * contact with reality: speech recognition of synthesised speech mis-hears it\n * (\"sow ragi\" -> \"so ragi\"), so exact containment fails, the mis-heard echo is\n * accepted as a new question, submitted, answered, spoken — and round it goes.\n * The operator hit this loop on a real device.\n *\n * Browsers do not give the Web Speech API the acoustic echo cancellation that a\n * native duplex app has, so there is no text-level fix for this. Interruption is\n * now an explicit tap instead, which is reliable, and the echo check survives\n * only as a guard on the moments just after playback stops.\n *\n * ★ **Mute is NOT a phase.** It is a property of the microphone, orthogonal to\n * where the conversation is. Modelling it as a state meant muting while the\n * assistant was thinking discarded the `thinking` phase, so the reply — already\n * in flight — was then ignored, and unmuting landed in `listening` with nothing\n * pending and nothing coming. The session dead-ended and the user's question was\n * silently lost.\n *\n * What this deliberately does NOT model: the assistant is turn-based\n * (speech -> text -> LLM -> text -> speech), so `thinking` is a real, visible\n * phase lasting seconds. A native speech-to-speech API would collapse\n * listening/thinking/speaking into one duplex stream; we are not that, and\n * pretending otherwise would hide latency the UI must show.\n */\n\n/** Where the CONVERSATION is. Independent of whether the mic is capturing. */\nexport type VoiceSessionPhase = 'idle' | 'listening' | 'thinking' | 'speaking' | 'ended';\n\nexport interface VoiceSessionSnapshot {\n phase: VoiceSessionPhase;\n /** Microphone off. Orthogonal to `phase` — see the header. */\n muted: boolean;\n /** FINALISED speech for the turn not yet submitted, accumulated. */\n pending: string;\n /** The recogniser's current guess, replaced wholesale until it finalises. */\n interim: string;\n /** Why the session stopped, when it stopped abnormally. */\n error: VoiceSessionError | null;\n}\n\n/**\n * Deliberately does NOT include a \"playback blocked\" variant. Nothing can\n * detect it — the speech provider does not surface a per-message playback\n * refusal — and the watchdog in `useVoiceSession` already recovers by handing\n * the turn back silently, which continues the conversation rather than killing\n * it. An error the code cannot raise is dead UI copy.\n */\nexport type VoiceSessionError = 'no-speech-support' | 'no-voice-support' | 'mic-denied';\n\nexport type VoiceSessionEvent =\n /** `final` distinguishes a committed phrase from a revisable guess. */\n | { type: 'start' }\n | { type: 'speech'; transcript: string; final: boolean }\n /** Nothing heard for `SILENCE_SUBMIT_MS`. */\n | { type: 'silence' }\n | { type: 'reply'; text: string }\n | { type: 'speech-ended' }\n | { type: 'mute'; muted: boolean }\n /** The user tapped to cut the assistant off. Explicit, not inferred. */\n | { type: 'interrupt' }\n | { type: 'fail'; error: VoiceSessionError }\n | { type: 'end' };\n\n/**\n * How long the user must stop talking before the turn is submitted.\n *\n * Long enough to survive a mid-sentence breath — a farmer describing a problem\n * pauses — and short enough that the session does not feel unresponsive. A\n * premature send truncates the question, which costs a whole 2-5s round trip to\n * recover from.\n *\n * ★ Raised from 1200ms because 1.2s does not survive an ordinary pause: the\n * operator reported being cut off mid-sentence, and the cost is worse than a\n * truncated prompt — once the turn is submitted the reducer discards every\n * `speech` event outside `listening`, so the rest of the sentence is not\n * queued, it is thrown away, and the assistant answers half a question.\n *\n * The asymmetry is what settles the number: waiting 800ms longer costs a moment\n * of silence, while cutting someone off costs the whole round trip AND makes\n * them repeat themselves.\n */\nexport const SILENCE_SUBMIT_MS = 2000;\n\n/** A turn is submitted only when there is something worth sending. */\nexport function isSubmittable(text: string): boolean {\n return text.trim().length > 0;\n}\n\n/** Everything heard this turn: committed phrases plus the current guess. */\nexport function spokenSoFar(snapshot: VoiceSessionSnapshot): string {\n return `${snapshot.pending} ${snapshot.interim}`.replace(/\\s+/g, ' ').trim();\n}\n\n/** Comparable form for echo detection: letters and digits only. */\nfunction normalise(text: string): string {\n return text\n .toLowerCase()\n .replace(/[^\\p{L}\\p{N}]+/gu, ' ')\n .trim();\n}\n\n/**\n * Is this transcript the assistant's OWN voice coming back through the mic?\n *\n * The microphone stays open while the assistant speaks so interruption is\n * possible at all, which means on any device using a speaker the recogniser will\n * happily transcribe the reply. Every such transcript is long enough to pass a\n * length threshold, so without this the assistant interrupts ITSELF on the first\n * phrase it utters — the feature would be unusable on a phone held normally.\n *\n * Containment is the signal length cannot provide: whatever we are currently\n * speaking is known, so anything already inside it is echo, not a person.\n */\n/**\n * Below this many words, a transcript is treated as a person interrupting\n * rather than as the assistant's own voice.\n *\n * Containment alone cannot tell \"no\" (a correction) from \"no\" (a word inside a\n * long reply), and the assistant's own voice arrives as long phrases, not as\n * one or two words. Anything shorter is far more likely to be the user cutting\n * in — which is precisely the case that must not be swallowed.\n */\nconst ECHO_MIN_WORDS = 3;\n\nexport function isEcho(transcript: string, spokenText: string | null): boolean {\n if (!spokenText) return false;\n const heard = normalise(transcript);\n if (heard.length === 0) return true;\n\n // A short utterance during playback is a correction, not an echo.\n if (heard.split(' ').length < ECHO_MIN_WORDS) return false;\n\n // ★ Word-boundary containment, not raw substring. `includes('no')` matched\n // inside \"know\", \"not\" and \"another\", so single-word corrections were\n // silently discarded — the user spoke and nothing happened at all.\n return ` ${normalise(spokenText)} `.includes(` ${heard} `);\n}\n\nexport const INITIAL_SESSION: Readonly<VoiceSessionSnapshot> = Object.freeze({\n phase: 'idle' as const,\n muted: false,\n pending: '',\n interim: '',\n error: null,\n});\n\n/**\n * The whole session loop, as one pure reduction.\n *\n * `spokenText` is what the assistant is currently saying, supplied so echo can\n * be told from interruption. It is an argument rather than snapshot state\n * because it belongs to the speech engine, not to the session.\n */\nexport function voiceSessionReducer(\n snapshot: VoiceSessionSnapshot,\n event: VoiceSessionEvent,\n spokenText: string | null = null\n): VoiceSessionSnapshot {\n // ★ An explicit `start` is handled BEFORE the terminal guard, because it is\n // the one event that legitimately follows `ended`: the user tapping the\n // launcher again. Without this the reducer is never reset, `start` is ignored\n // from `ended`, and the voice session is one-time-use per page load — the\n // launcher does nothing after the first conversation.\n if (event.type === 'start') return { ...INITIAL_SESSION, phase: 'listening' };\n\n // Terminal otherwise. A late recognition result, a trailing playback error or\n // a reply still in flight must never reanimate a session the user dismissed,\n // nor rewrite a clean exit into a failure during teardown.\n if (snapshot.phase === 'ended') return snapshot;\n if (event.type === 'end') return { ...snapshot, phase: 'ended', pending: '', interim: '' };\n if (event.type === 'fail') {\n return { ...snapshot, phase: 'ended', pending: '', interim: '', error: event.error };\n }\n\n switch (event.type) {\n case 'mute':\n // Only the microphone changes. An in-flight turn keeps its phase, so the\n // reply that is already coming still lands and is still spoken.\n return {\n ...snapshot,\n muted: event.muted,\n // A half-heard fragment is dropped on mute rather than being submitted\n // later as a truncated question.\n ...(event.muted ? { pending: '', interim: '' } : {}),\n };\n\n case 'interrupt':\n // Cutting the assistant off starts a fresh turn. Explicit, because\n // inferring it from audio is what caused the feedback loop.\n return snapshot.phase === 'speaking' ? { ...snapshot, phase: 'listening', pending: '', interim: '' } : snapshot;\n\n case 'speech': {\n if (snapshot.muted) return snapshot;\n // Nothing heard outside `listening` is ever the user: while the assistant\n // speaks the microphone is closed, and anything arriving during\n // `thinking` is a trailing result from the turn just submitted.\n if (snapshot.phase !== 'listening') return snapshot;\n // ★ Still echo, even though playback has finished. The recogniser emits a\n // trailing FINAL result for speaker leakage after `speech-ended` has\n // returned us to listening; accepted, it is submitted 1.2s later and the\n // assistant answers its own reply — a self-sustaining loop that costs a\n // turn every round. The caller keeps `spokenText` set for a grace window\n // past the end of playback precisely so this check still has a reference.\n if (isEcho(event.transcript, spokenText)) return snapshot;\n // ★ Finalised phrases ACCUMULATE. `useVoiceInput` emits each newly\n // finalised phrase on its own — which is why the composer's handler is\n // called `appendTranscript` — so replacing here would reduce \"when should\n // I\" + \"sow ragi\" to just \"sow ragi\" and submit a truncated question.\n return event.final\n ? { ...snapshot, pending: `${snapshot.pending} ${event.transcript}`.replace(/\\s+/g, ' ').trim(), interim: '' }\n : { ...snapshot, interim: event.transcript };\n }\n\n case 'silence':\n // Submits only while listening, unmuted, and with something actually said\n // — otherwise an idle session would fire empty turns forever.\n if (snapshot.phase !== 'listening' || snapshot.muted) return snapshot;\n if (!isSubmittable(spokenSoFar(snapshot))) return snapshot;\n return { ...snapshot, phase: 'thinking' };\n\n case 'reply':\n // A reply arriving after the user already started talking again must not\n // yank the session back into `speaking`.\n if (snapshot.phase !== 'thinking') return snapshot;\n return { ...snapshot, phase: 'speaking', pending: '', interim: '' };\n\n case 'speech-ended':\n return snapshot.phase === 'speaking' ? { ...snapshot, phase: 'listening', pending: '', interim: '' } : snapshot;\n\n default:\n return snapshot;\n }\n}\n\n/**\n * Is the microphone capturing right now?\n *\n * False while the assistant speaks, which is the whole point: an open\n * microphone during playback is what created the feedback loop. False whenever\n * muted, whatever the phase.\n */\nexport function isCapturing(snapshot: VoiceSessionSnapshot): boolean {\n if (snapshot.muted) return false;\n // ONLY while listening. Capturing during `speaking` fed the assistant's own\n // voice back in as a question — see the header. Interruption is a tap.\n return snapshot.phase === 'listening';\n}\n\n/** The orb's visual mode. Kept here so the UI has no state logic of its own. */\nexport function orbMode(snapshot: VoiceSessionSnapshot): 'idle' | 'listening' | 'thinking' | 'speaking' {\n switch (snapshot.phase) {\n case 'thinking':\n return 'thinking';\n case 'speaking':\n // Still speaking even if the mic is muted — muting does not stop the\n // assistant, and showing idle here would misreport what is happening.\n return 'speaking';\n case 'listening':\n return snapshot.muted ? 'idle' : 'listening';\n default:\n return 'idle';\n }\n}\n"],"mappings":";AA6FA,IAAa,IAAoB;AAGjC,SAAgB,EAAc,GAAuB;CACnD,OAAO,EAAK,KAAK,EAAE,SAAS;AAC9B;AAGA,SAAgB,EAAY,GAAwC;CAClE,OAAO,GAAG,EAAS,QAAQ,GAAG,EAAS,UAAU,QAAQ,QAAQ,GAAG,EAAE,KAAK;AAC7E;AAGA,SAAS,EAAU,GAAsB;CACvC,OAAO,EACJ,YAAY,EACZ,QAAQ,oBAAoB,GAAG,EAC/B,KAAK;AACV;AAuBA,IAAM,IAAiB;AAEvB,SAAgB,EAAO,GAAoB,GAAoC;CAC7E,IAAI,CAAC,GAAY,OAAO;CACxB,IAAM,IAAQ,EAAU,CAAU;CASlC,OARI,EAAM,WAAW,IAAU,KAG3B,EAAM,MAAM,GAAG,EAAE,SAAS,IAAuB,KAK9C,IAAI,EAAU,CAAU,EAAE,GAAG,SAAS,IAAI,EAAM,EAAE;AAC3D;AAEA,IAAa,IAAkD,OAAO,OAAO;CAC3E,OAAO;CACP,OAAO;CACP,SAAS;CACT,SAAS;CACT,OAAO;AACT,CAAC;AASD,SAAgB,EACd,GACA,GACA,IAA4B,MACN;CAMtB,IAAI,EAAM,SAAS,SAAS,OAAO;EAAE,GAAG;EAAi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;CACtG,QAAQ,EAAS,OAAjB;EACE,KAAK,YACH,OAAO;EACT,KAAK,YAGH,OAAO;EACT,KAAK,aACH,OAAO,EAAS,QAAQ,SAAS;EACnC,SACE,OAAO;CACX;AACF"}
1
+ {"version":3,"file":"voiceSession.js","names":[],"sources":["../../src/utils/voiceSession.ts"],"sourcesContent":["/**\n * The voice-conversation state machine (BOFF-7120).\n *\n * A live voice session is a loop — listen, submit, wait, speak, listen again —\n * and every interesting decision in it is about TIMING and INTERRUPTION rather\n * than about rendering. Those decisions live here, with no DOM, no audio and no\n * React, for the same reason `browserSpeechEngine` pushed its logic into\n * `speakableText`/`speechVoices`: this repo's vitest runs in the `node`\n * environment, so anything touching `window` cannot be tested at all.\n *\n * ★ **The microphone is CLOSED while the assistant speaks.** It was open, so\n * that talking over the assistant could interrupt it, guarded by matching the\n * transcript against the text being spoken. That guard was too weak to survive\n * contact with reality: speech recognition of synthesised speech mis-hears it\n * (\"sow ragi\" -> \"so ragi\"), so exact containment fails, the mis-heard echo is\n * accepted as a new question, submitted, answered, spoken — and round it goes.\n * The operator hit this loop on a real device.\n *\n * Browsers do not give the Web Speech API the acoustic echo cancellation that a\n * native duplex app has, so there is no text-level fix for this. Interruption is\n * now an explicit tap instead, which is reliable, and the echo check survives\n * only as a guard on the moments just after playback stops.\n *\n * ★ **Mute is NOT a phase.** It is a property of the microphone, orthogonal to\n * where the conversation is. Modelling it as a state meant muting while the\n * assistant was thinking discarded the `thinking` phase, so the reply — already\n * in flight — was then ignored, and unmuting landed in `listening` with nothing\n * pending and nothing coming. The session dead-ended and the user's question was\n * silently lost.\n *\n * What this deliberately does NOT model: the assistant is turn-based\n * (speech -> text -> LLM -> text -> speech), so `thinking` is a real, visible\n * phase lasting seconds. A native speech-to-speech API would collapse\n * listening/thinking/speaking into one duplex stream; we are not that, and\n * pretending otherwise would hide latency the UI must show.\n */\n\n/** Where the CONVERSATION is. Independent of whether the mic is capturing. */\nexport type VoiceSessionPhase = 'idle' | 'listening' | 'thinking' | 'speaking' | 'ended';\n\nexport interface VoiceSessionSnapshot {\n phase: VoiceSessionPhase;\n /** Microphone off. Orthogonal to `phase` — see the header. */\n muted: boolean;\n /** FINALISED speech for the turn not yet submitted, accumulated. */\n pending: string;\n /** The recogniser's current guess, replaced wholesale until it finalises. */\n interim: string;\n /** Why the session stopped, when it stopped abnormally. */\n error: VoiceSessionError | null;\n}\n\n/**\n * Deliberately does NOT include a \"playback blocked\" variant. Nothing can\n * detect it — the speech provider does not surface a per-message playback\n * refusal — and the watchdog in `useVoiceSession` already recovers by handing\n * the turn back silently, which continues the conversation rather than killing\n * it. An error the code cannot raise is dead UI copy.\n */\nexport type VoiceSessionError = 'no-speech-support' | 'no-voice-support' | 'mic-denied';\n\nexport type VoiceSessionEvent =\n /** `final` distinguishes a committed phrase from a revisable guess. */\n | { type: 'start' }\n | { type: 'speech'; transcript: string; final: boolean }\n /** Nothing heard for `SILENCE_SUBMIT_MS`. */\n | { type: 'silence' }\n | { type: 'reply'; text: string }\n | { type: 'speech-ended' }\n | { type: 'mute'; muted: boolean }\n /** The user tapped to cut the assistant off. Explicit, not inferred. */\n | { type: 'interrupt' }\n | { type: 'fail'; error: VoiceSessionError }\n | { type: 'end' };\n\n/**\n * How long the user must stop talking before the turn is submitted.\n *\n * Long enough to survive a mid-sentence breath — a farmer describing a problem\n * pauses — and short enough that the session does not feel unresponsive. A\n * premature send truncates the question, which costs a whole 2-5s round trip to\n * recover from.\n *\n * ★ Raised from 1200ms because 1.2s does not survive an ordinary pause: the\n * operator reported being cut off mid-sentence, and the cost is worse than a\n * truncated prompt — once the turn is submitted the reducer discards every\n * `speech` event outside `listening`, so the rest of the sentence is not\n * queued, it is thrown away, and the assistant answers half a question.\n *\n * The asymmetry is what settles the number: waiting 800ms longer costs a moment\n * of silence, while cutting someone off costs the whole round trip AND makes\n * them repeat themselves.\n */\nexport const SILENCE_SUBMIT_MS = 2000;\n\n/** A turn is submitted only when there is something worth sending. */\nexport function isSubmittable(text: string): boolean {\n return text.trim().length > 0;\n}\n\n/** Everything heard this turn: committed phrases plus the current guess. */\nexport function spokenSoFar(snapshot: VoiceSessionSnapshot): string {\n return `${snapshot.pending} ${snapshot.interim}`.replace(/\\s+/g, ' ').trim();\n}\n\n/** Comparable form for echo detection: letters and digits only. */\nfunction normalise(text: string): string {\n return text\n .toLowerCase()\n .replace(/[^\\p{L}\\p{N}]+/gu, ' ')\n .trim();\n}\n\n/**\n * Is this transcript the assistant's OWN voice coming back through the mic?\n *\n * The microphone stays open while the assistant speaks so interruption is\n * possible at all, which means on any device using a speaker the recogniser will\n * happily transcribe the reply. Every such transcript is long enough to pass a\n * length threshold, so without this the assistant interrupts ITSELF on the first\n * phrase it utters — the feature would be unusable on a phone held normally.\n *\n * Containment is the signal length cannot provide: whatever we are currently\n * speaking is known, so anything already inside it is echo, not a person.\n */\n/**\n * Below this many words, a transcript is treated as a person interrupting\n * rather than as the assistant's own voice.\n *\n * Containment alone cannot tell \"no\" (a correction) from \"no\" (a word inside a\n * long reply), and the assistant's own voice arrives as long phrases, not as\n * one or two words. Anything shorter is far more likely to be the user cutting\n * in — which is precisely the case that must not be swallowed.\n */\nconst ECHO_MIN_WORDS = 3;\n\nexport function isEcho(transcript: string, spokenText: string | null): boolean {\n if (!spokenText) return false;\n const heard = normalise(transcript);\n if (heard.length === 0) return true;\n\n // A short utterance during playback is a correction, not an echo.\n if (heard.split(' ').length < ECHO_MIN_WORDS) return false;\n\n // ★ Word-boundary containment, not raw substring. `includes('no')` matched\n // inside \"know\", \"not\" and \"another\", so single-word corrections were\n // silently discarded — the user spoke and nothing happened at all.\n return ` ${normalise(spokenText)} `.includes(` ${heard} `);\n}\n\n/**\n * What to do with a reply the app has just observed.\n *\n * Pure, because the rule is subtle and the hook that used to hold it has no\n * test file at all — which is how the original defect shipped.\n *\n * Three outcomes:\n * - already claimed -> do nothing (a re-render, or two identical answers)\n * - arrived while thinking -> claim it AND advance the turn\n * - arrived any other time -> ★ CLAIM IT, but do not advance\n *\n * That last case is the one that matters. Interrupting stops playback but\n * nothing cancels the model, so the abandoned answer still lands seconds later\n * while the phase is `listening`. Leaving it unclaimed meant the NEXT question\n * found it waiting and spoke the answer to the question the user had cut off.\n */\nexport function planReplyConsumption(\n replyId: string | null | undefined,\n phase: VoiceSessionPhase,\n consumedReplyId: string | null\n): { claim: boolean; advance: boolean } {\n if (!replyId) return { claim: false, advance: false };\n if (replyId === consumedReplyId) return { claim: false, advance: false };\n return { claim: true, advance: phase === 'thinking' };\n}\n\nexport const INITIAL_SESSION: Readonly<VoiceSessionSnapshot> = Object.freeze({\n phase: 'idle' as const,\n muted: false,\n pending: '',\n interim: '',\n error: null,\n});\n\n/**\n * The whole session loop, as one pure reduction.\n *\n * `spokenText` is what the assistant is currently saying, supplied so echo can\n * be told from interruption. It is an argument rather than snapshot state\n * because it belongs to the speech engine, not to the session.\n */\nexport function voiceSessionReducer(\n snapshot: VoiceSessionSnapshot,\n event: VoiceSessionEvent,\n spokenText: string | null = null\n): VoiceSessionSnapshot {\n // ★ An explicit `start` is handled BEFORE the terminal guard, because it is\n // the one event that legitimately follows `ended`: the user tapping the\n // launcher again. Without this the reducer is never reset, `start` is ignored\n // from `ended`, and the voice session is one-time-use per page load — the\n // launcher does nothing after the first conversation.\n if (event.type === 'start') return { ...INITIAL_SESSION, phase: 'listening' };\n\n // Terminal otherwise. A late recognition result, a trailing playback error or\n // a reply still in flight must never reanimate a session the user dismissed,\n // nor rewrite a clean exit into a failure during teardown.\n if (snapshot.phase === 'ended') return snapshot;\n if (event.type === 'end') return { ...snapshot, phase: 'ended', pending: '', interim: '' };\n if (event.type === 'fail') {\n return { ...snapshot, phase: 'ended', pending: '', interim: '', error: event.error };\n }\n\n switch (event.type) {\n case 'mute':\n // Only the microphone changes. An in-flight turn keeps its phase, so the\n // reply that is already coming still lands and is still spoken.\n return {\n ...snapshot,\n muted: event.muted,\n // A half-heard fragment is dropped on mute rather than being submitted\n // later as a truncated question.\n ...(event.muted ? { pending: '', interim: '' } : {}),\n };\n\n case 'interrupt':\n // Cutting the assistant off starts a fresh turn. Explicit, because\n // inferring it from audio is what caused the feedback loop.\n return snapshot.phase === 'speaking' ? { ...snapshot, phase: 'listening', pending: '', interim: '' } : snapshot;\n\n case 'speech': {\n if (snapshot.muted) return snapshot;\n // Nothing heard outside `listening` is ever the user: while the assistant\n // speaks the microphone is closed, and anything arriving during\n // `thinking` is a trailing result from the turn just submitted.\n if (snapshot.phase !== 'listening') return snapshot;\n // ★ Still echo, even though playback has finished. The recogniser emits a\n // trailing FINAL result for speaker leakage after `speech-ended` has\n // returned us to listening; accepted, it is submitted 1.2s later and the\n // assistant answers its own reply — a self-sustaining loop that costs a\n // turn every round. The caller keeps `spokenText` set for a grace window\n // past the end of playback precisely so this check still has a reference.\n if (isEcho(event.transcript, spokenText)) return snapshot;\n // ★ Finalised phrases ACCUMULATE. `useVoiceInput` emits each newly\n // finalised phrase on its own — which is why the composer's handler is\n // called `appendTranscript` — so replacing here would reduce \"when should\n // I\" + \"sow ragi\" to just \"sow ragi\" and submit a truncated question.\n return event.final\n ? { ...snapshot, pending: `${snapshot.pending} ${event.transcript}`.replace(/\\s+/g, ' ').trim(), interim: '' }\n : { ...snapshot, interim: event.transcript };\n }\n\n case 'silence':\n // Submits only while listening, unmuted, and with something actually said\n // — otherwise an idle session would fire empty turns forever.\n if (snapshot.phase !== 'listening' || snapshot.muted) return snapshot;\n if (!isSubmittable(spokenSoFar(snapshot))) return snapshot;\n return { ...snapshot, phase: 'thinking' };\n\n case 'reply':\n // A reply arriving after the user already started talking again must not\n // yank the session back into `speaking`.\n if (snapshot.phase !== 'thinking') return snapshot;\n return { ...snapshot, phase: 'speaking', pending: '', interim: '' };\n\n case 'speech-ended':\n return snapshot.phase === 'speaking' ? { ...snapshot, phase: 'listening', pending: '', interim: '' } : snapshot;\n\n default:\n return snapshot;\n }\n}\n\n/**\n * Is the microphone capturing right now?\n *\n * False while the assistant speaks, which is the whole point: an open\n * microphone during playback is what created the feedback loop. False whenever\n * muted, whatever the phase.\n */\nexport function isCapturing(snapshot: VoiceSessionSnapshot): boolean {\n if (snapshot.muted) return false;\n // ONLY while listening. Capturing during `speaking` fed the assistant's own\n // voice back in as a question — see the header. Interruption is a tap.\n return snapshot.phase === 'listening';\n}\n\n/** The orb's visual mode. Kept here so the UI has no state logic of its own. */\nexport function orbMode(snapshot: VoiceSessionSnapshot): 'idle' | 'listening' | 'thinking' | 'speaking' {\n switch (snapshot.phase) {\n case 'thinking':\n return 'thinking';\n case 'speaking':\n // Still speaking even if the mic is muted — muting does not stop the\n // assistant, and showing idle here would misreport what is happening.\n return 'speaking';\n case 'listening':\n return snapshot.muted ? 'idle' : 'listening';\n default:\n return 'idle';\n }\n}\n"],"mappings":";AA6FA,IAAa,IAAoB;AAGjC,SAAgB,EAAc,GAAuB;CACnD,OAAO,EAAK,KAAK,EAAE,SAAS;AAC9B;AAGA,SAAgB,EAAY,GAAwC;CAClE,OAAO,GAAG,EAAS,QAAQ,GAAG,EAAS,UAAU,QAAQ,QAAQ,GAAG,EAAE,KAAK;AAC7E;AAGA,SAAS,EAAU,GAAsB;CACvC,OAAO,EACJ,YAAY,EACZ,QAAQ,oBAAoB,GAAG,EAC/B,KAAK;AACV;AAuBA,IAAM,IAAiB;AAEvB,SAAgB,EAAO,GAAoB,GAAoC;CAC7E,IAAI,CAAC,GAAY,OAAO;CACxB,IAAM,IAAQ,EAAU,CAAU;CASlC,OARI,EAAM,WAAW,IAAU,KAG3B,EAAM,MAAM,GAAG,EAAE,SAAS,IAAuB,KAK9C,IAAI,EAAU,CAAU,EAAE,GAAG,SAAS,IAAI,EAAM,EAAE;AAC3D;AAkBA,SAAgB,EACd,GACA,GACA,GACsC;CAGtC,OAFI,CAAC,KACD,MAAY,IAAwB;EAAE,OAAO;EAAO,SAAS;CAAM,IAChE;EAAE,OAAO;EAAM,SAAS,MAAU;CAAW;AACtD;AAEA,IAAa,IAAkD,OAAO,OAAO;CAC3E,OAAO;CACP,OAAO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,IAAI;EAEzG,SACE,OAAO;CACX;AACF;AASA,SAAgB,EAAY,GAAyC;CAInE,OAHI,EAAS,QAAc,KAGpB,EAAS,UAAU;AAC5B;AAGA,SAAgB,EAAQ,GAAgF;CACtG,QAAQ,EAAS,OAAjB;EACE,KAAK,YACH,OAAO;EACT,KAAK,YAGH,OAAO;EACT,KAAK,aACH,OAAO,EAAS,QAAQ,SAAS;EACnC,SACE,OAAO;CACX;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@burdenoff/microfe-healthybowl",
3
- "version": "2026.901.1",
3
+ "version": "2026.901.2",
4
4
  "description": "Burdenoff HealthyBowl Microfrontend - Comprehensive organic farming and agro-foods management platform",
5
5
  "type": "module",
6
6
  "files": [