@burdenoff/fe-libs 2026.1029.5 → 2026.1029.7

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