@burdenoff/fe-libs 2026.1118.7 → 2026.1118.9

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.
Files changed (29) hide show
  1. package/dist/shared/assistant/index.d.ts +2 -0
  2. package/dist/shared/assistant/ui/useVoiceSession.js +188 -142
  3. package/dist/shared/assistant/voice/handsFree.d.ts +3 -1
  4. package/dist/shared/assistant/voice/handsfree/audioTrackTransport.d.ts +8 -0
  5. package/dist/shared/assistant/voice/handsfree/audioTrackTransport.js +36 -31
  6. package/dist/shared/assistant/voice/handsfree/backendStreamTransport.js +1 -0
  7. package/dist/shared/assistant/voice/handsfree/echoGate.d.ts +21 -0
  8. package/dist/shared/assistant/voice/handsfree/echoGate.js +11 -2
  9. package/dist/shared/assistant/voice/handsfree/handsFreeController.d.ts +7 -0
  10. package/dist/shared/assistant/voice/handsfree/handsFreeController.js +46 -42
  11. package/dist/shared/assistant/voice/handsfree/playbackReference.d.ts +63 -5
  12. package/dist/shared/assistant/voice/handsfree/playbackReference.js +56 -29
  13. package/dist/shared/assistant/voice/handsfree/preRollRing.d.ts +7 -0
  14. package/dist/shared/assistant/voice/handsfree/preRollRing.js +3 -0
  15. package/dist/shared/assistant/voice/handsfree/sttTransport.d.ts +16 -0
  16. package/dist/shared/assistant/voice/handsfree/useHandsFreeInterrupt.js +55 -54
  17. package/dist/shared/assistant/voice/handsfree/vad.d.ts +9 -0
  18. package/dist/shared/assistant/voice/handsfree/vad.js +10 -7
  19. package/dist/shared/assistant/voice/handsfree/webSpeechTransport.js +1 -0
  20. package/dist/shared/assistant/voice/thinkingTone.d.ts +213 -0
  21. package/dist/shared/assistant/voice/thinkingTone.js +182 -0
  22. package/dist/shared/assistant/voice/thinkingToneConfig.d.ts +4 -0
  23. package/dist/shared/assistant/voice/thinkingToneConfig.js +9 -0
  24. package/dist/shared/assistant/voice/voiceSession.d.ts +24 -0
  25. package/dist/shared/assistant/voice/voiceSession.js +18 -11
  26. package/dist/shared/backgrounds/useBackgroundPreference.d.ts +10 -4
  27. package/dist/shared/backgrounds/useBackgroundPreference.js +69 -47
  28. package/dist/shared-assistant.js +404 -402
  29. package/package.json +1 -1
@@ -424,6 +424,8 @@ export * from './promptDelivery';
424
424
  export * from './speech/appendSpeechQueue';
425
425
  export * from './voice/phraseSpeechConfig';
426
426
  export * from './voice/firstClipPrefetchConfig';
427
+ export * from './voice/thinkingToneConfig';
428
+ export * from './voice/thinkingTone';
427
429
  export * from './voice/phraseGate';
428
430
  export * from './voice/livePhraseSpeech';
429
431
  export * from './voice/phrasePlayback';
@@ -11,20 +11,22 @@ import { captionChunks as oe } from "../voice/speechPlayback.js";
11
11
  import { speechFeed as a } from "../speech/speechFeed.js";
12
12
  import { planSubmitTimer as se, resolveVoiceGraceMs as ce } from "../voice/handsFree.js";
13
13
  import { isTurnSuperseded as le } from "../voice/supersededTurns.js";
14
- import { INITIAL_SESSION as ue, INTERRUPT_MAX_MS as de, NOTHING_HEARD as fe, advanceHeardClock as pe, isCapturing as me, isSubmittable as he, planListeningHold as ge, planReplyConsumption as _e, planVoiceAnnouncement as ve, shouldRecognise as ye, spokenSoFar as o, voiceSessionReducer as be } from "../voice/voiceSession.js";
15
- import { useCallback as s, useEffect as c, useLayoutEffect as xe, useMemo as Se, useReducer as Ce, useRef as l, useState as u } from "react";
14
+ import { THINKING_TONE_PHRASE_WAIT_MS as ue, createThinkingTonePlayer as de, planThinkingTone as fe, shouldPlayThinkingTone as pe, thinkingToneHeardUntil as me } from "../voice/thinkingTone.js";
15
+ import { thinkingToneEnabled as he } from "../voice/thinkingToneConfig.js";
16
+ import { INITIAL_SESSION as ge, INTERRUPT_MAX_MS as _e, NOTHING_HEARD as ve, advanceHeardClock as ye, isCapturing as be, isSubmittable as xe, planListeningHold as Se, planReplyConsumption as Ce, planVoiceAnnouncement as we, shouldRecognise as Te, spokenSoFar as o, voiceSessionReducer as Ee } from "../voice/voiceSession.js";
17
+ import { useCallback as s, useEffect as c, useLayoutEffect as De, useMemo as Oe, useReducer as ke, useRef as l, useState as u } from "react";
16
18
  // src/shared/assistant/ui/useVoiceSession.ts
17
- var we = 4e3, Te = 2500, Ee = 5e3, De = 12e3;
18
- function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersede: Ae, handsFreeInterrupt: je, handsFreeStreamNoticeAccepted: Me, onAcceptHandsFreeStreamNotice: Ne, onBargeIn: Pe }) {
19
- let p = ce(ke), m = l(null), Fe = s((e, t) => be(e, t, m.current), []), [h, g] = Ce(Fe, ue), _ = re(), { setSessionSpeaking: v, setSessionMicOpen: y, speakingMessageId: b, stop: x } = _, Ie = l(_.toggle), Le = _.toggle;
20
- xe(() => {
21
- Ie.current = Le;
22
- }, [Le]);
23
- let S = l(null), C = l({}), w = l(fe), T = l(void 0), E = l(void 0), Re = l(0), D = l(void 0), O = l(/* @__PURE__ */ new Map()), ze = l(void 0);
19
+ var Ae = 4e3, je = 2500, Me = 5e3, Ne = 12e3;
20
+ function Pe({ onSubmit: Pe, latestReply: d, language: f, graceMs: Fe, onSupersede: Ie, handsFreeInterrupt: Le, handsFreeStreamNoticeAccepted: Re, onAcceptHandsFreeStreamNotice: ze, onBargeIn: Be }) {
21
+ let p = ce(Fe), m = l(null), Ve = s((e, t) => Ee(e, t, m.current), []), [h, g] = ke(Ve, ge), _ = re(), { setSessionSpeaking: v, setSessionMicOpen: y, speakingMessageId: b, stop: x } = _, He = l(_.toggle), Ue = _.toggle;
22
+ De(() => {
23
+ He.current = Ue;
24
+ }, [Ue]);
25
+ let S = l(null), C = l({}), w = l(ve), T = l(void 0), E = l(void 0), We = l(0), D = l(void 0), O = l(/* @__PURE__ */ new Map()), Ge = l(void 0);
24
26
  c(() => {
25
27
  let e = h.correctionTimingDecision;
26
- if (e && e !== ze.current) {
27
- ze.current = e;
28
+ if (e && e !== Ge.current) {
29
+ Ge.current = e;
28
30
  for (let [t, n] of O.current) e.accepted && t >= e.candidateId && (T.current = n.lastSpeechFrame ?? T.current, E.current = n.recognizerSpeechEnded ?? E.current), (e.accepted || t <= e.candidateId) && O.current.delete(t);
29
31
  D.current !== void 0 && D.current <= e.candidateId && (D.current = void 0);
30
32
  }
@@ -34,7 +36,7 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
34
36
  h.muted,
35
37
  h.correctionTimingDecision
36
38
  ]);
37
- let k = l(null), Be = l(!1), [Ve, A] = u(null), j = l(null), [He, M] = u(null), [N, P] = u(!1), [Ue, F] = u(!1), [I, L] = u(!1), R = l(h);
39
+ let k = l(null), Ke = l(!1), [qe, A] = u(null), j = l(null), [Je, M] = u(null), [N, P] = u(!1), [Ye, F] = u(!1), [I, L] = u(!1), R = l(h);
38
40
  R.current = h;
39
41
  let z = l([]), B = l(null), V = l(!1), H = s(() => {
40
42
  z.current = [], B.current = null, V.current = !1;
@@ -45,7 +47,7 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
45
47
  if (!e.stillWanted || e.stillWanted()) {
46
48
  B.current = e, m.current = m.current ? `${m.current} ${e.text}` : e.text;
47
49
  try {
48
- Ie.current(e.id, e.text, e.lang);
50
+ He.current(e.id, e.text, e.lang);
49
51
  } catch {
50
52
  B.current = null;
51
53
  continue;
@@ -53,8 +55,8 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
53
55
  return !0;
54
56
  }
55
57
  }
56
- }, []), W = l(!1), We = s((e) => {
57
- let t = ge({
58
+ }, []), W = l(!1), Xe = s((e) => {
59
+ let t = Se({
58
60
  requested: e,
59
61
  held: W.current,
60
62
  muted: R.current.muted
@@ -64,12 +66,12 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
64
66
  muted: t.mute
65
67
  });
66
68
  }, []), G = s((e) => {
67
- let t = ve(R.current);
69
+ let t = we(R.current);
68
70
  t !== "drop" && (B.current?.id === e.id || z.current.some((t) => t.id === e.id) || (z.current.push(e), t === "start" && !V.current && (V.current = !0, g({ type: "announce" }))));
69
- }, []), Ge = s((e) => {
71
+ }, []), Ze = s((e) => {
70
72
  R.current.phase === "thinking" ? (z.current.push(e), V.current = !0, g({ type: "answered-locally" })) : G(e);
71
- }, [G]), Ke = l(d);
72
- Ke.current = d, c(() => {
73
+ }, [G]), Qe = l(d);
74
+ Qe.current = d, c(() => {
73
75
  if (h.phase === "speaking") {
74
76
  let e = j.current;
75
77
  m.current = e && k.current === e.id && d?.id !== e.id ? e.text : d?.text ?? null;
@@ -78,82 +80,82 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
78
80
  if (m.current === null) return;
79
81
  let e = setTimeout(() => {
80
82
  m.current = null;
81
- }, Te);
83
+ }, je);
82
84
  return () => clearTimeout(e);
83
85
  }, [h.phase, d]);
84
- let qe = l(f);
85
- qe.current = f;
86
- let Je = s((e, t) => {
86
+ let $e = l(f);
87
+ $e.current = f;
88
+ let et = s((e, t) => {
87
89
  let n = R.current;
88
90
  if (!n.muted) {
89
91
  if (n.phase === "thinking") {
90
92
  e === "lastSpeechFrame" && (D.current = void 0);
91
- let n = D.current ?? Re.current, r = O.current.get(n) ?? {};
93
+ let n = D.current ?? We.current, r = O.current.get(n) ?? {};
92
94
  r[e] = t, O.current.set(n, r);
93
95
  } else n.phase === "listening" && (e === "lastSpeechFrame" ? T.current = t : E.current = t);
94
96
  }
95
97
  }, []), K = s((e) => {
96
98
  let t = R.current;
97
99
  if (t.phase !== "thinking" || t.muted) return;
98
- let n = Re.current;
99
- return e && (D.current = n, Re.current += 1), n;
100
+ let n = We.current;
101
+ return e && (D.current = n, We.current += 1), n;
100
102
  }, []), q = s((e, t) => {
101
103
  g({
102
104
  type: "speech",
103
105
  transcript: e,
104
106
  final: t,
105
107
  at: Date.now(),
106
- language: qe.current,
108
+ language: $e.current,
107
109
  timingCandidateId: K(t)
108
110
  });
109
- }, [K]), Ye = s((e, t, n) => {
111
+ }, [K]), tt = s((e, t, n) => {
110
112
  g({
111
113
  type: "speech",
112
114
  transcript: e,
113
115
  final: t,
114
116
  at: Date.now(),
115
- language: n ?? qe.current,
117
+ language: n ?? $e.current,
116
118
  gated: !0,
117
119
  timingCandidateId: K(t)
118
120
  });
119
- }, [K]), Xe = l(0), Ze = s(() => {
120
- H(), x(), Xe.current = Date.now(), P(!0), g({ type: "interrupt" });
121
- }, [x, H]), Qe = s((e) => q(e, !0), [q]), $e = e((e) => e.micDeviceId), J = t({
122
- onFinalize: Qe,
121
+ }, [K]), nt = l(0), rt = s(() => {
122
+ H(), x(), nt.current = Date.now(), P(!0), g({ type: "interrupt" });
123
+ }, [x, H]), it = s((e) => q(e, !0), [q]), at = e((e) => e.micDeviceId), J = t({
124
+ onFinalize: it,
123
125
  language: f,
124
- deviceId: $e,
126
+ deviceId: at,
125
127
  onSpeechEnd: (e) => {
126
- Je("recognizerSpeechEnded", e);
128
+ et("recognizerSpeechEnded", e);
127
129
  }
128
- }), et = J.stop, tt = l(Pe);
129
- tt.current = Pe;
130
- let nt = s(() => {
131
- H(), te(), x(), Xe.current = Date.now(), P(!0), g({ type: "interrupt" }), tt.current?.();
132
- }, [x, H]), rt = ae(), it = ie(), Y = n({
133
- enabled: ee(je, r(), rt, it),
130
+ }), ot = J.stop, st = l(Be);
131
+ st.current = Be;
132
+ let ct = s(() => {
133
+ H(), te(), x(), nt.current = Date.now(), P(!0), g({ type: "interrupt" }), st.current?.();
134
+ }, [x, H]), Y = ae(), lt = ie(), X = n({
135
+ enabled: ee(Le, r(), Y, lt),
134
136
  phase: h.phase,
135
137
  muted: h.muted,
136
138
  language: f,
137
- streamNoticeAccepted: Me ?? null,
138
- onAcceptStreamNotice: Ne,
139
- onBargeIn: nt,
140
- onTranscript: Ye,
139
+ streamNoticeAccepted: Re ?? null,
140
+ onAcceptStreamNotice: ze,
141
+ onBargeIn: ct,
142
+ onTranscript: tt,
141
143
  onSpeechFrame: (e) => {
142
- Je("lastSpeechFrame", e);
144
+ et("lastSpeechFrame", e);
143
145
  }
144
- }), at = Y.mode === "notice", X = J.isListening || Y.suppressWebSpeech && Y.mode === "active";
146
+ }), ut = X.mode === "notice", Z = J.isListening || X.suppressWebSpeech && X.mode === "active";
145
147
  c(() => {
146
148
  J.interim && q(J.interim, !1);
147
149
  }, [J.interim, q]), c(() => {
148
- S.current && clearTimeout(S.current), F(!1), w.current = pe(w.current, h, i());
150
+ S.current && clearTimeout(S.current), F(!1), h.phase !== "thinking" && (w.current = ye(w.current, h, i()));
149
151
  let e = se({
150
152
  phase: h.phase,
151
153
  muted: h.muted,
152
154
  spoken: o(h),
153
155
  holding: I,
154
156
  graceMs: p,
155
- wordsPending: Y.wordsPending,
156
- speechEndedAgoMs: Y.wordsAfterUtterance && T.current !== void 0 ? i() - T.current : null
157
+ wordsPending: X.wordsPending,
158
+ speechEndedAgoMs: X.wordsAfterUtterance && T.current !== void 0 ? i() - T.current : null
157
159
  });
158
160
  if (!e.arm) return;
159
161
  let t = setTimeout(() => F(!0), Math.min(800, e.delayMs)), n = i(), r = n - (p - e.delayMs);
@@ -176,23 +178,66 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
176
178
  h,
177
179
  I,
178
180
  p,
179
- Y.wordsPending,
180
- Y.wordsAfterUtterance
181
+ X.wordsPending,
182
+ X.wordsAfterUtterance
181
183
  ]), c(() => {
182
184
  (h.phase !== "listening" || h.muted) && L(!1);
183
185
  }, [h.phase, h.muted]), c(() => {
184
186
  if (!N) return;
185
- let e = Date.now() - Xe.current, t = X ? Math.max(0, 500 - e) : Math.max(0, de - e), n = setTimeout(() => P(!1), t);
187
+ let e = Date.now() - nt.current, t = Z ? Math.max(0, 500 - e) : Math.max(0, _e - e), n = setTimeout(() => P(!1), t);
186
188
  return () => clearTimeout(n);
187
- }, [N, X]);
188
- let ot = l("");
189
- h.phase === "listening" && (ot.current = o(h)), c(() => {
189
+ }, [N, Z]);
190
+ let dt = l("");
191
+ h.phase === "listening" && (dt.current = o(h)), c(() => {
190
192
  if (h.phase !== "thinking") return;
191
193
  y(!1), H(), M((e) => typeof e == "object" && e ? null : e);
192
- let e = ot.current.trim();
193
- e && Oe(e, Z.current ?? `vs-orphan-${Date.now().toString(36)}`, C.current, { correction: R.current.correcting }), C.current = {}, w.current = fe, T.current = void 0, E.current = void 0;
194
- }, [h.phase]), c(() => {
195
- let e = _e(d?.id, h.phase, k.current, le(d?.id));
194
+ let e = dt.current.trim();
195
+ e && Pe(e, $.current ?? `vs-orphan-${Date.now().toString(36)}`, C.current, { correction: R.current.correcting }), C.current = {}, w.current = ve, T.current = void 0, E.current = void 0;
196
+ }, [h.phase]);
197
+ let [Q] = u(de), ft = l(h.phase), pt = l(null), mt = J.interim.trim() !== "";
198
+ c(() => {
199
+ let e = ft.current;
200
+ ft.current = h.phase;
201
+ let t = he(), n = Date.now();
202
+ pe({
203
+ enabled: t,
204
+ from: e,
205
+ to: h.phase,
206
+ muted: h.muted,
207
+ avatarOn: Y
208
+ }) && (pt.current = n + ue);
209
+ let r = pt.current;
210
+ if (r === null) return;
211
+ let ee = fe({
212
+ enabled: t,
213
+ phase: h.phase,
214
+ muted: h.muted,
215
+ avatarOn: Y,
216
+ phraseOpen: mt,
217
+ now: n,
218
+ until: r
219
+ });
220
+ if (ee === "wait" || (pt.current = null, ee === "skip")) return;
221
+ let te = Q.play();
222
+ te !== null && g({
223
+ type: "thinking-tone",
224
+ until: me(Date.now(), te)
225
+ });
226
+ }, [
227
+ h.phase,
228
+ h.muted,
229
+ Y,
230
+ Q,
231
+ mt
232
+ ]), c(() => {
233
+ h.phase === "ended" ? Q.dispose() : (h.phase === "listening" || h.muted || Y) && Q.stop();
234
+ }, [
235
+ h.phase,
236
+ h.muted,
237
+ Y,
238
+ Q
239
+ ]), c(() => () => Q.dispose(), [Q]), c(() => {
240
+ let e = Ce(d?.id, h.phase, k.current, le(d?.id));
196
241
  e.claim && (k.current = d?.id ?? null, e.advance && d && (d.refused ? (H(), M({
197
242
  kind: "turn-refused",
198
243
  text: d.text
@@ -211,7 +256,7 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
211
256
  return;
212
257
  }
213
258
  let e = a.peek(b);
214
- e && e.final && e.channel === "voice" && e.voiceSessionId !== void 0 && e.voiceSessionId === Z.current && (k.current = b, j.current = {
259
+ e && e.final && e.channel === "voice" && e.voiceSessionId !== void 0 && e.voiceSessionId === $.current && (k.current = b, j.current = {
215
260
  id: b,
216
261
  text: e.text
217
262
  }, g({
@@ -234,7 +279,7 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
234
279
  if (e.state === "ended") {
235
280
  if (k.current !== e.messageId || j.current?.id !== e.messageId) return;
236
281
  let n = a.peek(e.messageId);
237
- n?.channel === "voice" && n.voiceSessionId === Z.current && (j.current = {
282
+ n?.channel === "voice" && n.voiceSessionId === $.current && (j.current = {
238
283
  id: e.messageId,
239
284
  text: n.text
240
285
  }), A(null);
@@ -246,11 +291,11 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
246
291
  }
247
292
  if (le(e.messageId)) return;
248
293
  let n = a.peek(e.messageId);
249
- if (n && n.channel === "voice" && n.voiceSessionId === Z.current) {
294
+ if (n && n.channel === "voice" && n.voiceSessionId === $.current) {
250
295
  if (e.state === "queued") A(e.messageId), k.current = e.messageId, j.current = {
251
296
  id: e.messageId,
252
297
  text: n.text
253
- }, et();
298
+ }, ot();
254
299
  else if (k.current !== e.messageId) return;
255
300
  else e.state === "started" ? (k.current = e.messageId, j.current = {
256
301
  id: e.messageId,
@@ -261,51 +306,51 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
261
306
  partial: !n.final
262
307
  })) : e.state === "paused" && k.current === e.messageId && g({ type: "reply-audio-paused" });
263
308
  }
264
- }), [et]), c(() => {
309
+ }), [ot]), c(() => {
265
310
  h.phase !== "thinking" && h.phase !== "speaking" && A(null);
266
311
  }, [h.phase]), c(() => {
267
312
  let e = b !== null;
268
- Be.current && !e && (B.current = null, R.current.phase === "speaking" && U() || g({ type: "speech-ended" })), Be.current = e;
313
+ Ke.current && !e && (B.current = null, R.current.phase === "speaking" && U() || g({ type: "speech-ended" })), Ke.current = e;
269
314
  }, [b, U]), c(() => {
270
315
  h.phase !== "listening" && M((e) => e === "nothing-heard" ? null : e);
271
316
  }, [h.phase]), c(() => {
272
317
  if (h.phase !== "speaking" || b !== null) return;
273
318
  let e = setTimeout(() => {
274
- Be.current || (H(), g({ type: "speech-ended" }));
275
- }, we);
319
+ Ke.current || (H(), g({ type: "speech-ended" }));
320
+ }, Ae);
276
321
  return () => clearTimeout(e);
277
322
  }, [
278
323
  h.phase,
279
324
  b,
280
325
  H
281
326
  ]);
282
- let st = _.outputNotCleared;
327
+ let ht = _.outputNotCleared;
283
328
  c(() => {
284
- if (st === null || k.current !== st.messageId) return;
329
+ if (ht === null || k.current !== ht.messageId) return;
285
330
  let { phase: e } = R.current;
286
331
  e !== "idle" && e !== "ended" && e !== "thinking" && M("reply-not-heard");
287
- }, [st]), c(() => {
332
+ }, [ht]), c(() => {
288
333
  h.phase !== "listening" && h.phase !== "thinking" && M((e) => e === "reply-not-heard" ? null : e);
289
334
  }, [h.phase]);
290
- let ct = l(Ae);
291
- ct.current = Ae;
292
- let lt = l(0);
335
+ let gt = l(Ie);
336
+ gt.current = Ie;
337
+ let _t = l(0);
293
338
  c(() => {
294
339
  let e = h.superseded;
295
- e !== lt.current && (lt.current = e, e !== 0 && (H(), x(), ct.current?.()));
340
+ e !== _t.current && (_t.current = e, e !== 0 && (H(), x(), gt.current?.()));
296
341
  }, [
297
342
  h.superseded,
298
343
  H,
299
344
  x
300
345
  ]), c(() => {
301
- let e = me(h);
302
- y(e), ye(h) && Ve === null && !Y.suppressWebSpeech ? J.isActive || J.start("auto") : J.isActive && J.stop();
346
+ let e = be(h);
347
+ y(e), Te(h) && qe === null && !X.suppressWebSpeech ? J.isActive || J.start("auto") : J.isActive && J.stop();
303
348
  }, [
304
349
  h,
305
350
  J,
306
351
  y,
307
- Y.suppressWebSpeech,
308
- Ve
352
+ X.suppressWebSpeech,
353
+ qe
309
354
  ]), c(() => {
310
355
  h.phase === "speaking" && V.current && (V.current = !1, U() || g({ type: "speech-ended" }));
311
356
  }, [h.phase, U]), c(() => {
@@ -317,23 +362,23 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
317
362
  error: "no-speech-support"
318
363
  }) : J.error === "network" ? M("network") : J.error === "unknown" && M("recognition-failed");
319
364
  }, [J.error]), c(() => {
320
- J.error === null && X && M((e) => e === "network" || e === "recognition-failed" ? null : e);
321
- }, [J.error, X]), c(() => {
322
- if (X && M((e) => e === "not-capturing" ? null : e), !me(h) || X || at) return;
323
- let e = setTimeout(() => M("not-capturing"), Ee);
365
+ J.error === null && Z && M((e) => e === "network" || e === "recognition-failed" ? null : e);
366
+ }, [J.error, Z]), c(() => {
367
+ if (Z && M((e) => e === "not-capturing" ? null : e), !be(h) || Z || ut) return;
368
+ let e = setTimeout(() => M("not-capturing"), Me);
324
369
  return () => clearTimeout(e);
325
370
  }, [
326
371
  h,
327
- X,
328
- at
372
+ Z,
373
+ ut
329
374
  ]), c(() => {
330
- if (h.phase !== "listening" || h.muted || !X || o(h) !== "") return;
331
- let e = setTimeout(() => M("nothing-heard"), De);
375
+ if (h.phase !== "listening" || h.muted || !Z || o(h) !== "") return;
376
+ let e = setTimeout(() => M("nothing-heard"), Ne);
332
377
  return () => clearTimeout(e);
333
- }, [h, X]), c(() => {
378
+ }, [h, Z]), c(() => {
334
379
  o(h) !== "" && M(null);
335
380
  }, [h]);
336
- let Z = l(null), ut = s(() => {
381
+ let $ = l(null), vt = s(() => {
337
382
  if (P(!1), F(!1), L(!1), H(), W.current = !1, !J.isSupported) g({
338
383
  type: "fail",
339
384
  error: "no-speech-support"
@@ -350,25 +395,26 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
350
395
  t.volume = 0, e.speak(t);
351
396
  }
352
397
  } catch {}
353
- ne(), v(!0), M(null), k.current = Ke.current?.id ?? null, j.current = null, Z.current = `vs-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`, g({ type: "start" });
398
+ ne(), he() && Q.prime(), v(!0), M(null), k.current = Qe.current?.id ?? null, j.current = null, $.current = `vs-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`, g({ type: "start" });
354
399
  }
355
400
  }, [
356
401
  J.isSupported,
357
402
  _.isBlocked,
358
403
  v,
359
- H
360
- ]), dt = s(() => {
361
- P(!1), F(!1), L(!1), H(), W.current = !1, Z.current = null, g({ type: "end" }), x(), v(!1);
404
+ H,
405
+ Q
406
+ ]), yt = s(() => {
407
+ P(!1), F(!1), L(!1), H(), W.current = !1, $.current = null, g({ type: "end" }), x(), v(!1);
362
408
  }, [
363
409
  x,
364
410
  v,
365
411
  H
366
- ]), ft = s((e) => Z.current === e, []), pt = s(() => {
412
+ ]), bt = s((e) => $.current === e, []), xt = s(() => {
367
413
  let e = R.current;
368
414
  e.phase !== "listening" || e.muted || L(!0);
369
- }, []), Q = s(() => {
415
+ }, []), St = s(() => {
370
416
  let e = R.current;
371
- if (e.phase !== "listening" || e.muted || !he(o(e))) return;
417
+ if (e.phase !== "listening" || e.muted || !xe(o(e))) return;
372
418
  let t = i();
373
419
  C.current = {
374
420
  speechEnded: w.current.at ?? t,
@@ -381,15 +427,15 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
381
427
  type: "silence",
382
428
  at: Date.now()
383
429
  });
384
- }, [p]), $ = l(!1);
430
+ }, [p]), Ct = l(!1);
385
431
  c(() => {
386
- (h.phase !== "listening" || h.muted) && ($.current = !1);
432
+ (h.phase !== "listening" || h.muted) && (Ct.current = !1);
387
433
  }, [h.phase, h.muted]), c(() => {
388
- !Y.wordsPending && $.current && ($.current = !1, Q());
389
- }, [Y.wordsPending, Q]);
390
- let mt = s(() => {
391
- L(!1), Y.wordsPending ? $.current = !0 : Q();
392
- }, [Y.wordsPending, Q]), ht = s(() => {
434
+ !X.wordsPending && Ct.current && (Ct.current = !1, St());
435
+ }, [X.wordsPending, St]);
436
+ let wt = s(() => {
437
+ L(!1), X.wordsPending ? Ct.current = !0 : St();
438
+ }, [X.wordsPending, St]), Tt = s(() => {
393
439
  g({
394
440
  type: "mute",
395
441
  muted: !R.current.muted
@@ -398,60 +444,60 @@ function Oe({ onSubmit: Oe, latestReply: d, language: f, graceMs: ke, onSupersed
398
444
  c(() => () => {
399
445
  v(!1), y(!1);
400
446
  }, [v, y]);
401
- let gt = oe(_.spokenChunks, h.phase, b);
402
- return Se(() => ({
447
+ let Et = oe(_.spokenChunks, h.phase, b);
448
+ return Oe(() => ({
403
449
  session: h,
404
- notice: He ?? (Y.fallbackReason !== null && Y.fallbackReason !== "notice-declined" ? "hands-free-fallback" : Y.nothingHeard ? "hands-free-nothing-heard" : null),
405
- spokenChunks: gt,
406
- capturing: X,
450
+ notice: Je ?? (X.fallbackReason !== null && X.fallbackReason !== "notice-declined" ? "hands-free-fallback" : X.nothingHeard ? "hands-free-nothing-heard" : null),
451
+ spokenChunks: Et,
452
+ capturing: Z,
407
453
  active: h.phase !== "idle" && (h.phase !== "ended" || h.error !== null),
408
454
  interrupting: N,
409
- awaitingEndpoint: Ue,
455
+ awaitingEndpoint: Ye,
410
456
  holding: I,
411
457
  correcting: h.correcting,
412
458
  handsFree: {
413
- mode: Y.mode,
414
- nothingHeard: Y.nothingHeard,
415
- transportKind: Y.transportKind,
416
- fallbackReason: Y.fallbackReason,
417
- privacyNotice: Y.privacyNotice
459
+ mode: X.mode,
460
+ nothingHeard: X.nothingHeard,
461
+ transportKind: X.transportKind,
462
+ fallbackReason: X.fallbackReason,
463
+ privacyNotice: X.privacyNotice
418
464
  },
419
465
  available: J.isSupported && !_.isBlocked,
420
- start: ut,
421
- end: dt,
422
- isCurrentSession: ft,
423
- toggleMute: ht,
424
- interrupt: Ze,
425
- letMeFinish: pt,
426
- imDone: mt,
466
+ start: vt,
467
+ end: yt,
468
+ isCurrentSession: bt,
469
+ toggleMute: Tt,
470
+ interrupt: rt,
471
+ letMeFinish: xt,
472
+ imDone: wt,
427
473
  announce: G,
428
- holdListening: We,
429
- answerLocally: Ge
474
+ holdListening: Xe,
475
+ answerLocally: Ze
430
476
  }), [
431
477
  h,
432
- He,
478
+ Je,
433
479
  N,
434
- Ue,
480
+ Ye,
435
481
  I,
436
- X,
437
- Y.mode,
438
- Y.nothingHeard,
439
- Y.transportKind,
440
- Y.fallbackReason,
441
- Y.privacyNotice,
482
+ Z,
483
+ X.mode,
484
+ X.nothingHeard,
485
+ X.transportKind,
486
+ X.fallbackReason,
487
+ X.privacyNotice,
442
488
  J.isSupported,
443
489
  _.isBlocked,
444
- gt,
445
- ut,
446
- dt,
447
- ft,
448
- ht,
449
- Ze,
450
- pt,
451
- mt,
490
+ Et,
491
+ vt,
492
+ yt,
493
+ bt,
494
+ Tt,
495
+ rt,
496
+ xt,
497
+ wt,
452
498
  G,
453
- We,
454
- Ge
499
+ Xe,
500
+ Ze
455
501
  ]);
456
502
  }
457
- export { Oe as useVoiceSession };
503
+ export { Pe as useVoiceSession };
@@ -167,7 +167,9 @@ export type ThinkingSpeechPlan = {
167
167
  *
168
168
  * Echo is not checked here: nothing plays during `thinking`. The caller still
169
169
  * passes the previous reply through `isEcho` first, because its tail can sound
170
- * for a moment after playback ends.
170
+ * for a moment after playback ends. The one thing that does play then, the
171
+ * thinking tone (D3, BOFF-12936), is refused by the caller before this
172
+ * (`mayBeThinkingTone` in `voiceSession.ts`): no words are ever read into it.
171
173
  */
172
174
  export declare function planThinkingSpeech(input: {
173
175
  transcript: string;
@@ -1,6 +1,14 @@
1
1
  import { SttTransport } from './sttTransport';
2
2
  export declare const BRANCH_DELAY_S = 0.3;
3
3
  export declare const TRAILING_RESULT_MS = 1500;
4
+ /** How long the branch stays open after an utterance closes, so its last word is not clipped. */
5
+ export declare const CLOSE_HOLD_MS = 400;
6
+ /**
7
+ * The branch opens and closes as an exponential approach with this time
8
+ * constant: smooth, so the recogniser hears no click, and within 1% of the
9
+ * target after five of them.
10
+ */
11
+ export declare const GAIN_TIME_CONSTANT_S = 0.005;
4
12
  /** The slice of `SpeechRecognition` this transport uses. */
5
13
  export interface TrackRecognitionLike {
6
14
  lang: string;