@burdenoff/fe-libs 2026.1117.4 → 2026.1117.5

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.
@@ -10,331 +10,335 @@ import { useLiveAvatarEchoReference as ie, useLiveAvatarOn as ae } from "./assis
10
10
  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
- import { isTurnSuperseded as o } from "../voice/supersededTurns.js";
14
- import { INITIAL_SESSION as le, INTERRUPT_MAX_MS as ue, NOTHING_HEARD as de, advanceHeardClock as fe, isCapturing as pe, isSubmittable as me, planListeningHold as he, planReplyConsumption as ge, planVoiceAnnouncement as _e, shouldRecognise as ve, spokenSoFar as s, voiceSessionReducer as ye } from "../voice/voiceSession.js";
15
- import { useCallback as c, useEffect as l, useLayoutEffect as be, useMemo as xe, useReducer as Se, useRef as u, useState as d } from "react";
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";
16
16
  // src/shared/assistant/ui/useVoiceSession.ts
17
- var Ce = 4e3, we = 2500, Te = 5e3, Ee = 12e3;
18
- function De({ onSubmit: De, latestReply: f, language: p, graceMs: Oe, onSupersede: ke, handsFreeInterrupt: Ae, handsFreeStreamNoticeAccepted: je, onAcceptHandsFreeStreamNotice: Me, onBargeIn: Ne }) {
19
- let m = ce(Oe), h = u(null), Pe = c((e, t) => ye(e, t, h.current), []), [g, _] = Se(Pe, le), v = re(), { setSessionSpeaking: y, setSessionMicOpen: b, speakingMessageId: x, stop: S } = v, Fe = u(v.toggle), Ie = v.toggle;
20
- be(() => {
21
- Fe.current = Ie;
22
- }, [Ie]);
23
- let C = u(null), w = u({}), T = u(de), E = u(void 0), D = u(void 0), Le = u(0), O = u(void 0), k = u(/* @__PURE__ */ new Map()), Re = u(void 0);
24
- l(() => {
25
- let e = g.correctionTimingDecision;
26
- if (e && e !== Re.current) {
27
- Re.current = e;
28
- for (let [t, n] of k.current) e.accepted && t >= e.candidateId && (E.current = n.lastSpeechFrame ?? E.current, D.current = n.recognizerSpeechEnded ?? D.current), (e.accepted || t <= e.candidateId) && k.current.delete(t);
29
- O.current !== void 0 && O.current <= e.candidateId && (O.current = void 0);
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);
24
+ c(() => {
25
+ let e = h.correctionTimingDecision;
26
+ if (e && e !== ze.current) {
27
+ ze.current = e;
28
+ 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
+ D.current !== void 0 && D.current <= e.candidateId && (D.current = void 0);
30
30
  }
31
- (g.phase !== "thinking" || g.muted) && (k.current.clear(), O.current = void 0), (g.phase === "idle" || g.phase === "ended") && (E.current = void 0, D.current = void 0);
31
+ (h.phase !== "thinking" || h.muted) && (O.current.clear(), D.current = void 0), (h.phase === "idle" || h.phase === "ended") && (T.current = void 0, E.current = void 0);
32
32
  }, [
33
- g.phase,
34
- g.muted,
35
- g.correctionTimingDecision
33
+ h.phase,
34
+ h.muted,
35
+ h.correctionTimingDecision
36
36
  ]);
37
- let A = u(null), ze = u(!1), [Be, j] = d(null), M = u(null), [Ve, N] = d(null), [P, F] = d(!1), [He, I] = d(!1), [L, R] = d(!1), z = u(g);
38
- z.current = g;
39
- let B = u([]), V = u(null), H = u(!1), U = c(() => {
40
- B.current = [], V.current = null, H.current = !1;
41
- }, []), W = c(() => {
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);
38
+ R.current = h;
39
+ let z = l([]), B = l(null), V = l(!1), H = s(() => {
40
+ z.current = [], B.current = null, V.current = !1;
41
+ }, []), U = s(() => {
42
42
  for (;;) {
43
- let e = B.current.shift();
43
+ let e = z.current.shift();
44
44
  if (!e) return !1;
45
45
  if (!e.stillWanted || e.stillWanted()) {
46
- V.current = e, h.current = h.current ? `${h.current} ${e.text}` : e.text;
46
+ B.current = e, m.current = m.current ? `${m.current} ${e.text}` : e.text;
47
47
  try {
48
- Fe.current(e.id, e.text, e.lang);
48
+ Ie.current(e.id, e.text, e.lang);
49
49
  } catch {
50
- V.current = null;
50
+ B.current = null;
51
51
  continue;
52
52
  }
53
53
  return !0;
54
54
  }
55
55
  }
56
- }, []), G = u(!1), Ue = c((e) => {
57
- let t = he({
56
+ }, []), W = l(!1), We = s((e) => {
57
+ let t = ge({
58
58
  requested: e,
59
- held: G.current,
60
- muted: z.current.muted
59
+ held: W.current,
60
+ muted: R.current.muted
61
61
  });
62
- G.current = t.held, t.mute !== null && _({
62
+ W.current = t.held, t.mute !== null && g({
63
63
  type: "mute",
64
64
  muted: t.mute
65
65
  });
66
- }, []), K = c((e) => {
67
- let t = _e(z.current);
68
- t !== "drop" && (V.current?.id === e.id || B.current.some((t) => t.id === e.id) || (B.current.push(e), t === "start" && !H.current && (H.current = !0, _({ type: "announce" }))));
69
- }, []), We = c((e) => {
70
- z.current.phase === "thinking" ? (B.current.push(e), H.current = !0, _({ type: "answered-locally" })) : K(e);
71
- }, [K]), Ge = u(f);
72
- Ge.current = f, l(() => {
73
- if (g.phase === "speaking") {
74
- let e = M.current;
75
- h.current = e && A.current === e.id && f?.id !== e.id ? e.text : f?.text ?? null;
66
+ }, []), G = s((e) => {
67
+ let t = ve(R.current);
68
+ 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) => {
70
+ 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
+ if (h.phase === "speaking") {
74
+ let e = j.current;
75
+ m.current = e && k.current === e.id && d?.id !== e.id ? e.text : d?.text ?? null;
76
76
  return;
77
77
  }
78
- if (h.current === null) return;
78
+ if (m.current === null) return;
79
79
  let e = setTimeout(() => {
80
- h.current = null;
81
- }, we);
80
+ m.current = null;
81
+ }, Te);
82
82
  return () => clearTimeout(e);
83
- }, [g.phase, f]);
84
- let Ke = u(p);
85
- Ke.current = p;
86
- let qe = c((e, t) => {
87
- let n = z.current;
83
+ }, [h.phase, d]);
84
+ let qe = l(f);
85
+ qe.current = f;
86
+ let Je = s((e, t) => {
87
+ let n = R.current;
88
88
  if (!n.muted) {
89
89
  if (n.phase === "thinking") {
90
- e === "lastSpeechFrame" && (O.current = void 0);
91
- let n = O.current ?? Le.current, r = k.current.get(n) ?? {};
92
- r[e] = t, k.current.set(n, r);
93
- } else n.phase === "listening" && (e === "lastSpeechFrame" ? E.current = t : D.current = t);
90
+ e === "lastSpeechFrame" && (D.current = void 0);
91
+ let n = D.current ?? Re.current, r = O.current.get(n) ?? {};
92
+ r[e] = t, O.current.set(n, r);
93
+ } else n.phase === "listening" && (e === "lastSpeechFrame" ? T.current = t : E.current = t);
94
94
  }
95
- }, []), q = c((e) => {
96
- let t = z.current;
95
+ }, []), K = s((e) => {
96
+ let t = R.current;
97
97
  if (t.phase !== "thinking" || t.muted) return;
98
- let n = Le.current;
99
- return e && (O.current = n, Le.current += 1), n;
100
- }, []), J = c((e, t) => {
101
- _({
98
+ let n = Re.current;
99
+ return e && (D.current = n, Re.current += 1), n;
100
+ }, []), q = s((e, t) => {
101
+ g({
102
102
  type: "speech",
103
103
  transcript: e,
104
104
  final: t,
105
105
  at: Date.now(),
106
- language: Ke.current,
107
- timingCandidateId: q(t)
106
+ language: qe.current,
107
+ timingCandidateId: K(t)
108
108
  });
109
- }, [q]), Je = c((e, t, n) => {
110
- _({
109
+ }, [K]), Ye = s((e, t, n) => {
110
+ g({
111
111
  type: "speech",
112
112
  transcript: e,
113
113
  final: t,
114
114
  at: Date.now(),
115
- language: n ?? Ke.current,
115
+ language: n ?? qe.current,
116
116
  gated: !0,
117
- timingCandidateId: q(t)
117
+ timingCandidateId: K(t)
118
118
  });
119
- }, [q]), Ye = u(0), Xe = c(() => {
120
- U(), S(), Ye.current = Date.now(), F(!0), _({ type: "interrupt" });
121
- }, [S, U]), Ze = c((e) => J(e, !0), [J]), Qe = e((e) => e.micDeviceId), Y = t({
122
- onFinalize: Ze,
123
- language: p,
124
- deviceId: Qe,
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,
123
+ language: f,
124
+ deviceId: $e,
125
125
  onSpeechEnd: (e) => {
126
- qe("recognizerSpeechEnded", e);
126
+ Je("recognizerSpeechEnded", e);
127
127
  }
128
- }), $e = Y.stop, et = u(Ne);
129
- et.current = Ne;
130
- let tt = c(() => {
131
- U(), te(), S(), Ye.current = Date.now(), F(!0), _({ type: "interrupt" }), et.current?.();
132
- }, [S, U]), nt = ae(), rt = ie(), X = n({
133
- enabled: ee(Ae, r(), nt, rt),
134
- phase: g.phase,
135
- muted: g.muted,
136
- language: p,
137
- streamNoticeAccepted: je ?? null,
138
- onAcceptStreamNotice: Me,
139
- onBargeIn: tt,
140
- onTranscript: Je,
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),
134
+ phase: h.phase,
135
+ muted: h.muted,
136
+ language: f,
137
+ streamNoticeAccepted: Me ?? null,
138
+ onAcceptStreamNotice: Ne,
139
+ onBargeIn: nt,
140
+ onTranscript: Ye,
141
141
  onSpeechFrame: (e) => {
142
- qe("lastSpeechFrame", e);
142
+ Je("lastSpeechFrame", e);
143
143
  }
144
- }), it = X.mode === "notice", Z = Y.isListening || X.suppressWebSpeech && X.mode === "active";
145
- l(() => {
146
- Y.interim && J(Y.interim, !1);
147
- }, [Y.interim, J]), l(() => {
148
- C.current && clearTimeout(C.current), I(!1), T.current = fe(T.current, g, i());
144
+ }), at = Y.mode === "notice", X = J.isListening || Y.suppressWebSpeech && Y.mode === "active";
145
+ c(() => {
146
+ J.interim && q(J.interim, !1);
147
+ }, [J.interim, q]), c(() => {
148
+ S.current && clearTimeout(S.current), F(!1), w.current = pe(w.current, h, i());
149
149
  let e = se({
150
- phase: g.phase,
151
- muted: g.muted,
152
- spoken: s(g),
153
- holding: L,
154
- graceMs: m
150
+ phase: h.phase,
151
+ muted: h.muted,
152
+ spoken: o(h),
153
+ holding: I,
154
+ graceMs: p,
155
+ wordsPending: Y.wordsPending,
156
+ speechEndedAgoMs: Y.wordsAfterUtterance && T.current !== void 0 ? i() - T.current : null
155
157
  });
156
158
  if (!e.arm) return;
157
- let t = setTimeout(() => I(!0), Math.min(800, e.delayMs)), n = i();
158
- return C.current = setTimeout(() => {
159
- w.current = {
160
- speechEnded: T.current.at ?? n,
161
- lastSpeechFrame: E.current,
162
- recognizerSpeechEnded: D.current,
163
- selectedGraceMs: m,
164
- graceStarted: n,
159
+ let t = setTimeout(() => F(!0), Math.min(800, e.delayMs)), n = i(), r = n - (p - e.delayMs);
160
+ return S.current = setTimeout(() => {
161
+ C.current = {
162
+ speechEnded: Math.min(w.current.at ?? n, r),
163
+ lastSpeechFrame: T.current,
164
+ recognizerSpeechEnded: E.current,
165
+ selectedGraceMs: p,
166
+ graceStarted: r,
165
167
  graceEnded: i()
166
- }, _({
168
+ }, g({
167
169
  type: "silence",
168
170
  at: Date.now()
169
171
  });
170
172
  }, e.delayMs), () => {
171
- clearTimeout(t), C.current && clearTimeout(C.current);
173
+ clearTimeout(t), S.current && clearTimeout(S.current);
172
174
  };
173
175
  }, [
174
- g,
175
- L,
176
- m
177
- ]), l(() => {
178
- (g.phase !== "listening" || g.muted) && R(!1);
179
- }, [g.phase, g.muted]), l(() => {
180
- if (!P) return;
181
- let e = Date.now() - Ye.current, t = Z ? Math.max(0, 500 - e) : Math.max(0, ue - e), n = setTimeout(() => F(!1), t);
176
+ h,
177
+ I,
178
+ p,
179
+ Y.wordsPending,
180
+ Y.wordsAfterUtterance
181
+ ]), c(() => {
182
+ (h.phase !== "listening" || h.muted) && L(!1);
183
+ }, [h.phase, h.muted]), c(() => {
184
+ 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);
182
186
  return () => clearTimeout(n);
183
- }, [P, Z]);
184
- let at = u("");
185
- g.phase === "listening" && (at.current = s(g)), l(() => {
186
- if (g.phase !== "thinking") return;
187
- b(!1), U(), N((e) => typeof e == "object" && e ? null : e);
188
- let e = at.current.trim();
189
- e && De(e, $.current ?? `vs-orphan-${Date.now().toString(36)}`, w.current, { correction: z.current.correcting }), w.current = {}, T.current = de, E.current = void 0, D.current = void 0;
190
- }, [g.phase]), l(() => {
191
- let e = ge(f?.id, g.phase, A.current, o(f?.id));
192
- e.claim && (A.current = f?.id ?? null, e.advance && f && (f.refused ? (U(), N({
187
+ }, [N, X]);
188
+ let ot = l("");
189
+ h.phase === "listening" && (ot.current = o(h)), c(() => {
190
+ if (h.phase !== "thinking") return;
191
+ 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));
196
+ e.claim && (k.current = d?.id ?? null, e.advance && d && (d.refused ? (H(), M({
193
197
  kind: "turn-refused",
194
- text: f.text
195
- }), _({ type: "turn-refused" })) : _({
198
+ text: d.text
199
+ }), g({ type: "turn-refused" })) : g({
196
200
  type: "reply",
197
- text: f.text
201
+ text: d.text
198
202
  })));
199
203
  }, [
200
- f,
201
- g.phase,
202
- U
203
- ]), l(() => {
204
- if (x === null || g.phase !== "thinking" || A.current === x) return;
205
- if (o(x)) {
206
- S();
204
+ d,
205
+ h.phase,
206
+ H
207
+ ]), c(() => {
208
+ if (b === null || h.phase !== "thinking" || k.current === b) return;
209
+ if (le(b)) {
210
+ x();
207
211
  return;
208
212
  }
209
- let e = a.peek(x);
210
- e && e.final && e.channel === "voice" && e.voiceSessionId !== void 0 && e.voiceSessionId === $.current && (A.current = x, M.current = {
211
- id: x,
213
+ 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 = {
215
+ id: b,
212
216
  text: e.text
213
- }, _({
217
+ }, g({
214
218
  type: "reply-audio-started",
215
- replyId: x
219
+ replyId: b
216
220
  }));
217
221
  }, [
218
- x,
219
- g.phase,
220
- S
221
- ]), l(() => a.subscribe((e) => {
222
+ b,
223
+ h.phase,
224
+ x
225
+ ]), c(() => a.subscribe((e) => {
222
226
  if (e.type !== "audio") return;
223
- let t = z.current.phase;
227
+ let t = R.current.phase;
224
228
  if (t !== "thinking" && t !== "speaking") return;
225
229
  if (e.state === "retrying") {
226
- if (A.current !== e.messageId || M.current?.id !== e.messageId) return;
227
- A.current = null, M.current = null, j(e.messageId), _({ type: "reply-audio-paused" });
230
+ if (k.current !== e.messageId || j.current?.id !== e.messageId) return;
231
+ k.current = null, j.current = null, A(e.messageId), g({ type: "reply-audio-paused" });
228
232
  return;
229
233
  }
230
234
  if (e.state === "ended") {
231
- if (A.current !== e.messageId || M.current?.id !== e.messageId) return;
235
+ if (k.current !== e.messageId || j.current?.id !== e.messageId) return;
232
236
  let n = a.peek(e.messageId);
233
- n?.channel === "voice" && n.voiceSessionId === $.current && (M.current = {
237
+ n?.channel === "voice" && n.voiceSessionId === Z.current && (j.current = {
234
238
  id: e.messageId,
235
239
  text: n.text
236
- }), j(null);
237
- let r = M.current;
240
+ }), A(null);
241
+ let r = j.current;
238
242
  t === "thinking" && queueMicrotask(() => {
239
- M.current === r && z.current.phase === "thinking" && _({ type: "reply-audio-ended" });
243
+ j.current === r && R.current.phase === "thinking" && g({ type: "reply-audio-ended" });
240
244
  });
241
245
  return;
242
246
  }
243
- if (o(e.messageId)) return;
247
+ if (le(e.messageId)) return;
244
248
  let n = a.peek(e.messageId);
245
- if (n && n.channel === "voice" && n.voiceSessionId === $.current) {
246
- if (e.state === "queued") j(e.messageId), A.current = e.messageId, M.current = {
249
+ if (n && n.channel === "voice" && n.voiceSessionId === Z.current) {
250
+ if (e.state === "queued") A(e.messageId), k.current = e.messageId, j.current = {
247
251
  id: e.messageId,
248
252
  text: n.text
249
- }, $e();
250
- else if (A.current !== e.messageId) return;
251
- else e.state === "started" ? (A.current = e.messageId, M.current = {
253
+ }, et();
254
+ else if (k.current !== e.messageId) return;
255
+ else e.state === "started" ? (k.current = e.messageId, j.current = {
252
256
  id: e.messageId,
253
257
  text: n.text
254
- }, _({
258
+ }, g({
255
259
  type: "reply-audio-started",
256
260
  replyId: e.messageId,
257
261
  partial: !n.final
258
- })) : e.state === "paused" && A.current === e.messageId && _({ type: "reply-audio-paused" });
262
+ })) : e.state === "paused" && k.current === e.messageId && g({ type: "reply-audio-paused" });
259
263
  }
260
- }), [$e]), l(() => {
261
- g.phase !== "thinking" && g.phase !== "speaking" && j(null);
262
- }, [g.phase]), l(() => {
263
- let e = x !== null;
264
- ze.current && !e && (V.current = null, z.current.phase === "speaking" && W() || _({ type: "speech-ended" })), ze.current = e;
265
- }, [x, W]), l(() => {
266
- g.phase !== "listening" && N((e) => e === "nothing-heard" ? null : e);
267
- }, [g.phase]), l(() => {
268
- if (g.phase !== "speaking" || x !== null) return;
264
+ }), [et]), c(() => {
265
+ h.phase !== "thinking" && h.phase !== "speaking" && A(null);
266
+ }, [h.phase]), c(() => {
267
+ let e = b !== null;
268
+ Be.current && !e && (B.current = null, R.current.phase === "speaking" && U() || g({ type: "speech-ended" })), Be.current = e;
269
+ }, [b, U]), c(() => {
270
+ h.phase !== "listening" && M((e) => e === "nothing-heard" ? null : e);
271
+ }, [h.phase]), c(() => {
272
+ if (h.phase !== "speaking" || b !== null) return;
269
273
  let e = setTimeout(() => {
270
- ze.current || (U(), _({ type: "speech-ended" }));
271
- }, Ce);
274
+ Be.current || (H(), g({ type: "speech-ended" }));
275
+ }, we);
272
276
  return () => clearTimeout(e);
273
277
  }, [
274
- g.phase,
275
- x,
276
- U
278
+ h.phase,
279
+ b,
280
+ H
277
281
  ]);
278
- let Q = v.outputNotCleared;
279
- l(() => {
280
- if (Q === null || A.current !== Q.messageId) return;
281
- let { phase: e } = z.current;
282
- e !== "idle" && e !== "ended" && e !== "thinking" && N("reply-not-heard");
283
- }, [Q]), l(() => {
284
- g.phase !== "listening" && g.phase !== "thinking" && N((e) => e === "reply-not-heard" ? null : e);
285
- }, [g.phase]);
286
- let ot = u(ke);
287
- ot.current = ke;
288
- let st = u(0);
289
- l(() => {
290
- let e = g.superseded;
291
- e !== st.current && (st.current = e, e !== 0 && (U(), S(), ot.current?.()));
282
+ let st = _.outputNotCleared;
283
+ c(() => {
284
+ if (st === null || k.current !== st.messageId) return;
285
+ let { phase: e } = R.current;
286
+ e !== "idle" && e !== "ended" && e !== "thinking" && M("reply-not-heard");
287
+ }, [st]), c(() => {
288
+ h.phase !== "listening" && h.phase !== "thinking" && M((e) => e === "reply-not-heard" ? null : e);
289
+ }, [h.phase]);
290
+ let ct = l(Ae);
291
+ ct.current = Ae;
292
+ let lt = l(0);
293
+ c(() => {
294
+ let e = h.superseded;
295
+ e !== lt.current && (lt.current = e, e !== 0 && (H(), x(), ct.current?.()));
292
296
  }, [
293
- g.superseded,
294
- U,
295
- S
296
- ]), l(() => {
297
- let e = pe(g);
298
- b(e), ve(g) && Be === null && !X.suppressWebSpeech ? Y.isActive || Y.start("auto") : Y.isActive && Y.stop();
297
+ h.superseded,
298
+ H,
299
+ x
300
+ ]), c(() => {
301
+ let e = me(h);
302
+ y(e), ye(h) && Ve === null && !Y.suppressWebSpeech ? J.isActive || J.start("auto") : J.isActive && J.stop();
299
303
  }, [
300
- g,
301
- Y,
302
- b,
303
- X.suppressWebSpeech,
304
- Be
305
- ]), l(() => {
306
- g.phase === "speaking" && H.current && (H.current = !1, W() || _({ type: "speech-ended" }));
307
- }, [g.phase, W]), l(() => {
308
- Y.error === "not-allowed" || Y.error === "audio-capture" ? _({
304
+ h,
305
+ J,
306
+ y,
307
+ Y.suppressWebSpeech,
308
+ Ve
309
+ ]), c(() => {
310
+ h.phase === "speaking" && V.current && (V.current = !1, U() || g({ type: "speech-ended" }));
311
+ }, [h.phase, U]), c(() => {
312
+ J.error === "not-allowed" || J.error === "audio-capture" ? g({
309
313
  type: "fail",
310
314
  error: "mic-denied"
311
- }) : Y.error === "language-not-supported" ? _({
315
+ }) : J.error === "language-not-supported" ? g({
312
316
  type: "fail",
313
317
  error: "no-speech-support"
314
- }) : Y.error === "network" ? N("network") : Y.error === "unknown" && N("recognition-failed");
315
- }, [Y.error]), l(() => {
316
- Y.error === null && Z && N((e) => e === "network" || e === "recognition-failed" ? null : e);
317
- }, [Y.error, Z]), l(() => {
318
- if (Z && N((e) => e === "not-capturing" ? null : e), !pe(g) || Z || it) return;
319
- let e = setTimeout(() => N("not-capturing"), Te);
318
+ }) : J.error === "network" ? M("network") : J.error === "unknown" && M("recognition-failed");
319
+ }, [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);
320
324
  return () => clearTimeout(e);
321
325
  }, [
322
- g,
323
- Z,
324
- it
325
- ]), l(() => {
326
- if (g.phase !== "listening" || g.muted || !Z || s(g) !== "") return;
327
- let e = setTimeout(() => N("nothing-heard"), Ee);
326
+ h,
327
+ X,
328
+ at
329
+ ]), c(() => {
330
+ if (h.phase !== "listening" || h.muted || !X || o(h) !== "") return;
331
+ let e = setTimeout(() => M("nothing-heard"), De);
328
332
  return () => clearTimeout(e);
329
- }, [g, Z]), l(() => {
330
- s(g) !== "" && N(null);
331
- }, [g]);
332
- let $ = u(null), ct = c(() => {
333
- if (F(!1), I(!1), R(!1), U(), G.current = !1, !Y.isSupported) _({
333
+ }, [h, X]), c(() => {
334
+ o(h) !== "" && M(null);
335
+ }, [h]);
336
+ let Z = l(null), ut = s(() => {
337
+ if (P(!1), F(!1), L(!1), H(), W.current = !1, !J.isSupported) g({
334
338
  type: "fail",
335
339
  error: "no-speech-support"
336
340
  });
337
- else if (v.isBlocked) _({
341
+ else if (_.isBlocked) g({
338
342
  type: "fail",
339
343
  error: "no-voice-support"
340
344
  });
@@ -346,101 +350,108 @@ function De({ onSubmit: De, latestReply: f, language: p, graceMs: Oe, onSupersed
346
350
  t.volume = 0, e.speak(t);
347
351
  }
348
352
  } catch {}
349
- ne(), y(!0), N(null), A.current = Ge.current?.id ?? null, M.current = null, $.current = `vs-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`, _({ type: "start" });
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" });
350
354
  }
351
355
  }, [
352
- Y.isSupported,
353
- v.isBlocked,
354
- y,
355
- U
356
- ]), lt = c(() => {
357
- F(!1), I(!1), R(!1), U(), G.current = !1, $.current = null, _({ type: "end" }), S(), y(!1);
356
+ J.isSupported,
357
+ _.isBlocked,
358
+ 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);
358
362
  }, [
359
- S,
360
- y,
361
- U
362
- ]), ut = c((e) => $.current === e, []), dt = c(() => {
363
- let e = z.current;
364
- e.phase !== "listening" || e.muted || R(!0);
365
- }, []), ft = c(() => {
366
- R(!1);
367
- let e = z.current;
368
- if (e.phase !== "listening" || e.muted || !me(s(e))) return;
363
+ x,
364
+ v,
365
+ H
366
+ ]), ft = s((e) => Z.current === e, []), pt = s(() => {
367
+ let e = R.current;
368
+ e.phase !== "listening" || e.muted || L(!0);
369
+ }, []), Q = s(() => {
370
+ let e = R.current;
371
+ if (e.phase !== "listening" || e.muted || !he(o(e))) return;
369
372
  let t = i();
370
- w.current = {
371
- speechEnded: T.current.at ?? t,
372
- lastSpeechFrame: E.current,
373
- recognizerSpeechEnded: D.current,
374
- selectedGraceMs: m,
373
+ C.current = {
374
+ speechEnded: w.current.at ?? t,
375
+ lastSpeechFrame: T.current,
376
+ recognizerSpeechEnded: E.current,
377
+ selectedGraceMs: p,
375
378
  graceStarted: t,
376
379
  graceEnded: t
377
- }, _({
380
+ }, g({
378
381
  type: "silence",
379
382
  at: Date.now()
380
383
  });
381
- }, [m]), pt = c(() => {
382
- _({
384
+ }, [p]), $ = l(!1);
385
+ c(() => {
386
+ (h.phase !== "listening" || h.muted) && ($.current = !1);
387
+ }, [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(() => {
393
+ g({
383
394
  type: "mute",
384
- muted: !z.current.muted
395
+ muted: !R.current.muted
385
396
  });
386
397
  }, []);
387
- l(() => () => {
388
- y(!1), b(!1);
389
- }, [y, b]);
390
- let mt = oe(v.spokenChunks, g.phase, x);
391
- return xe(() => ({
392
- session: g,
393
- notice: Ve ?? (X.fallbackReason !== null && X.fallbackReason !== "notice-declined" ? "hands-free-fallback" : X.nothingHeard ? "hands-free-nothing-heard" : null),
394
- spokenChunks: mt,
395
- capturing: Z,
396
- active: g.phase !== "idle" && (g.phase !== "ended" || g.error !== null),
397
- interrupting: P,
398
- awaitingEndpoint: He,
399
- holding: L,
400
- correcting: g.correcting,
398
+ c(() => () => {
399
+ v(!1), y(!1);
400
+ }, [v, y]);
401
+ let gt = oe(_.spokenChunks, h.phase, b);
402
+ return Se(() => ({
403
+ 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,
407
+ active: h.phase !== "idle" && (h.phase !== "ended" || h.error !== null),
408
+ interrupting: N,
409
+ awaitingEndpoint: Ue,
410
+ holding: I,
411
+ correcting: h.correcting,
401
412
  handsFree: {
402
- mode: X.mode,
403
- nothingHeard: X.nothingHeard,
404
- transportKind: X.transportKind,
405
- fallbackReason: X.fallbackReason,
406
- privacyNotice: X.privacyNotice
413
+ mode: Y.mode,
414
+ nothingHeard: Y.nothingHeard,
415
+ transportKind: Y.transportKind,
416
+ fallbackReason: Y.fallbackReason,
417
+ privacyNotice: Y.privacyNotice
407
418
  },
408
- available: Y.isSupported && !v.isBlocked,
409
- start: ct,
410
- end: lt,
411
- isCurrentSession: ut,
412
- toggleMute: pt,
413
- interrupt: Xe,
414
- letMeFinish: dt,
415
- imDone: ft,
416
- announce: K,
417
- holdListening: Ue,
418
- answerLocally: We
419
+ 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,
427
+ announce: G,
428
+ holdListening: We,
429
+ answerLocally: Ge
419
430
  }), [
420
- g,
421
- Ve,
422
- P,
431
+ h,
423
432
  He,
424
- L,
425
- Z,
426
- X.mode,
427
- X.nothingHeard,
428
- X.transportKind,
429
- X.fallbackReason,
430
- X.privacyNotice,
431
- Y.isSupported,
432
- v.isBlocked,
433
- mt,
434
- ct,
435
- lt,
433
+ N,
434
+ Ue,
435
+ I,
436
+ X,
437
+ Y.mode,
438
+ Y.nothingHeard,
439
+ Y.transportKind,
440
+ Y.fallbackReason,
441
+ Y.privacyNotice,
442
+ J.isSupported,
443
+ _.isBlocked,
444
+ gt,
436
445
  ut,
437
- pt,
438
- Xe,
439
446
  dt,
440
447
  ft,
441
- K,
442
- Ue,
443
- We
448
+ ht,
449
+ Ze,
450
+ pt,
451
+ mt,
452
+ G,
453
+ We,
454
+ Ge
444
455
  ]);
445
456
  }
446
- export { De as useVoiceSession };
457
+ export { Oe as useVoiceSession };