@burdenoff/fe-libs 2026.1117.6 → 2026.1117.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.
@@ -5,26 +5,27 @@ import { getSpeechEngine as r, subscribeSpeechEngine as i } from "../speech/crea
5
5
  import { HOSTED_VOICES as a } from "../speech/hostedVoiceCatalogue.js";
6
6
  import { speechFeed as o } from "../speech/speechFeed.js";
7
7
  import { hasPendingReplyRequests as s, releaseReplyRequestsOutside as c, replyWantsAvatar as ee, settleReplyRequest as l, subscribeReplyRequests as u } from "../speech/replySpeechRequests.js";
8
- import { chunkForSpeech as te, toSpeakableText as d } from "../voice/speakableText.js";
9
- import { createPhrasePlayback as ne } from "../voice/phrasePlayback.js";
8
+ import { chunkForSpeech as te, settledFirstChunk as ne, toSpeakableText as d } from "../voice/speakableText.js";
9
+ import { createPhrasePlayback as re } from "../voice/phrasePlayback.js";
10
10
  import { phraseSpeechEnabled as f } from "../voice/phraseSpeechConfig.js";
11
+ import { firstClipPrefetchEnabled as ie } from "../voice/firstClipPrefetchConfig.js";
11
12
  import { speechLabelsFor as p } from "../voice/speechLabels.js";
12
- import { VOICE_LIST_TIMEOUT_MS as re, languageDisplayName as ie, selectVoiceForLocale as ae, speechGate as oe, speechLangForLocale as se, voiceAvailability as ce, voicesForLocale as le } from "../voice/speechVoices.js";
13
- import { resolveSpeechLocale as m } from "../voice/replyLanguage.js";
14
- import { findAssistantLanguage as h } from "../voice/languages.js";
15
- import { resolveLanguagePair as g } from "../voice/languagePair.js";
16
- import { IDLE_PLAYBACK as _, isSpeakingMessage as v, publishedChunks as ue, speechPlaybackReducer as y } from "../voice/speechPlayback.js";
17
- import { isVoiceTurn as de } from "../voice/turnVisibility.js";
18
- import { isTurnSuperseded as fe } from "../voice/supersededTurns.js";
19
- import { isTurnInFlight as pe } from "../turnState.js";
20
- import { beginListenTurn as me, describeTurn as he, finishListenTurn as b, markTurn as ge } from "../turnTimeline.js";
21
- import { registerTurnTimingPageExit as _e } from "../turnTimingReporter.js";
22
- import { parseToolActivity as ve } from "./AssistantToolActivity.js";
23
- import { useAssistantTr as ye } from "../i18n.js";
24
- import { createContext as be, useCallback as x, useContext as xe, useEffect as S, useMemo as C, useReducer as Se, useRef as w, useState as T, useSyncExternalStore as Ce } from "react";
25
- import { jsx as we } from "react/jsx-runtime";
13
+ import { VOICE_LIST_TIMEOUT_MS as ae, languageDisplayName as oe, selectVoiceForLocale as se, speechGate as ce, speechLangForLocale as m, voiceAvailability as le, voicesForLocale as h } from "../voice/speechVoices.js";
14
+ import { resolveSpeechLocale as g } from "../voice/replyLanguage.js";
15
+ import { findAssistantLanguage as _ } from "../voice/languages.js";
16
+ import { resolveLanguagePair as v } from "../voice/languagePair.js";
17
+ import { IDLE_PLAYBACK as ue, isSpeakingMessage as y, publishedChunks as de, speechPlaybackReducer as fe } from "../voice/speechPlayback.js";
18
+ import { isVoiceTurn as pe } from "../voice/turnVisibility.js";
19
+ import { isTurnSuperseded as me } from "../voice/supersededTurns.js";
20
+ import { isTurnInFlight as he } from "../turnState.js";
21
+ import { beginListenTurn as ge, describeTurn as _e, finishListenTurn as b, markTurn as ve } from "../turnTimeline.js";
22
+ import { registerTurnTimingPageExit as ye } from "../turnTimingReporter.js";
23
+ import { parseToolActivity as be } from "./AssistantToolActivity.js";
24
+ import { useAssistantTr as xe } from "../i18n.js";
25
+ import { createContext as Se, useCallback as x, useContext as Ce, useEffect as S, useMemo as C, useReducer as we, useRef as w, useState as T, useSyncExternalStore as Te } from "react";
26
+ import { jsx as Ee } from "react/jsx-runtime";
26
27
  // src/shared/assistant/ui/AssistantSpeechProvider.tsx
27
- var Te = {
28
+ var De = {
28
29
  codeBlock: "",
29
30
  codeBlockAgain: "",
30
31
  image: "",
@@ -35,30 +36,30 @@ var Te = {
35
36
  emailAt: "at",
36
37
  emailDot: "dot",
37
38
  nestedItem: ""
38
- }, Ee = 4e3, E = () => {}, De = {
39
+ }, Oe = 4e3, E = () => {}, ke = {
39
40
  subscribe: () => E,
40
41
  getSnapshot: () => !1
41
- }, Oe = {
42
+ }, Ae = {
42
43
  subscribe: u,
43
44
  getSnapshot: s
44
45
  };
45
- function ke(e, t) {
46
+ function je(e, t) {
46
47
  return ee(t) ? {
47
48
  ...e,
48
49
  autoSpeakEnabled: !0
49
50
  } : e;
50
51
  }
51
- function Ae(e, t) {
52
+ function Me(e, t) {
52
53
  let n = e.activeConversationId;
53
54
  if (!n || n !== t.activeConversationId) return null;
54
55
  let r = e.processingByConversationId[n], i = t.processingByConversationId[n];
55
- if (r?.status !== "complete" || !pe(i?.status)) return null;
56
+ if (r?.status !== "complete" || !he(i?.status)) return null;
56
57
  let a = r.messageId ?? i?.messageId ?? null;
57
58
  if (!a) return null;
58
59
  let o = e.conversations.find((e) => e.id === n)?.messages.find((e) => e.id === a);
59
60
  return o && o.role === "assistant" ? o : null;
60
61
  }
61
- var je = be({
62
+ var Ne = Se({
62
63
  isSupported: !1,
63
64
  availability: "unsupported",
64
65
  isBlocked: !0,
@@ -84,35 +85,35 @@ var je = be({
84
85
  previewVoice: () => {}
85
86
  });
86
87
  function D() {
87
- return xe(je);
88
+ return Ce(Ne);
88
89
  }
89
- var O = ({ children: s, visible: u = !0, engine: be }) => {
90
- let xe = Ce(i, r, r), E = be ?? xe, D = ye(), { locale: O } = e(), [k, A] = Se(y, _), [j, M] = T(() => E.listVoices()), [N, Me] = T(!1), [Ne, P] = T(() => /* @__PURE__ */ new Map()), [Pe, Fe] = T(() => /* @__PURE__ */ new Set()), [Ie, Le] = T(null), F = w(0), Re = w(null), ze = w(null), I = w(void 0), L = w(null), R = w(null), z = w(/* @__PURE__ */ new Set()), B = w(null);
90
+ var O = ({ children: s, visible: u = !0, engine: Se }) => {
91
+ let Ce = Te(i, r, r), E = Se ?? Ce, D = xe(), { locale: O } = e(), [k, A] = we(fe, ue), [j, Pe] = T(() => E.listVoices()), [M, Fe] = T(!1), [Ie, N] = T(() => /* @__PURE__ */ new Map()), [Le, Re] = T(() => /* @__PURE__ */ new Set()), [ze, Be] = T(null), P = w(0), Ve = w(null), He = w(null), F = w(void 0), I = w(null), L = w(null), Ue = w(/* @__PURE__ */ new Set()), R = w(null);
91
92
  S(() => () => {
92
- B.current !== null && clearTimeout(B.current);
93
+ R.current !== null && clearTimeout(R.current);
93
94
  }, []);
94
- let [Be, Ve] = T(null), V = w(null), He = w(() => {}), H = x(() => {
95
- V.current?.(), V.current = null;
96
- }, []), U = t((e) => e.autoSpeakEnabled), Ue = t((e) => e.setAutoSpeak), [W, We] = T(!1), Ge = w(!1), Ke = x((e) => {
97
- Ge.current = e;
98
- }, []), qe = t((e) => e.activeConversationId), G = C(() => E.isSupported(), [E]), Je = E.wouldSpeakOnAvatar === void 0 ? De : Oe, Ye = Ce(Je.subscribe, Je.getSnapshot, Je.getSnapshot);
95
+ let [We, Ge] = T(null), z = w(null), Ke = w(() => {}), B = x(() => {
96
+ z.current?.(), z.current = null;
97
+ }, []), V = t((e) => e.autoSpeakEnabled), qe = t((e) => e.setAutoSpeak), [H, Je] = T(!1), Ye = w(!1), Xe = x((e) => {
98
+ Ye.current = e;
99
+ }, []), Ze = t((e) => e.activeConversationId), U = C(() => E.isSupported(), [E]), Qe = E.wouldSpeakOnAvatar === void 0 ? ke : Ae, $e = Te(Qe.subscribe, Qe.getSnapshot, Qe.getSnapshot);
99
100
  S(() => {
100
- if (!G) return;
101
+ if (!U) return;
101
102
  let e = () => {
102
- M(E.listVoices()), P((e) => e.size === 0 ? e : /* @__PURE__ */ new Map());
103
+ Pe(E.listVoices()), N((e) => e.size === 0 ? e : /* @__PURE__ */ new Map());
103
104
  };
104
105
  return e(), E.subscribeVoices(e);
105
- }, [E, G]);
106
- let Xe = t((e) => e.assistantLanguage), Ze = t((e) => e.replyLanguage), K = t((e) => e.preferredVoices), Qe = t((e) => e.setPreferredVoice), q = C(() => g(Xe, Ze, O).reply, [
107
- Xe,
108
- Ze,
106
+ }, [E, U]);
107
+ let et = t((e) => e.assistantLanguage), tt = t((e) => e.replyLanguage), W = t((e) => e.preferredVoices), nt = t((e) => e.setPreferredVoice), G = C(() => v(et, tt, O).reply, [
108
+ et,
109
+ tt,
109
110
  O
110
- ]), J = q.code, $e = x((e) => h(e)?.tag ?? se(e), []), et = x((e) => h(e)?.rate ?? .9, []), tt = C(() => ce(G, j, q.tag, N), [
111
- G,
111
+ ]), K = G.code, q = x((e) => _(e)?.tag ?? m(e), []), rt = x((e) => _(e)?.rate ?? .9, []), it = C(() => le(U, j, G.tag, M), [
112
+ U,
112
113
  j,
113
- q,
114
- N
115
- ]), nt = C(() => ({
114
+ G,
115
+ M
116
+ ]), J = C(() => ({
116
117
  codeBlock: D("speech.codeBlock", "There’s a code example on screen"),
117
118
  codeBlockAgain: D("speech.codeBlockAgain", "There’s another code example on screen"),
118
119
  image: D("speech.image", "an image"),
@@ -124,7 +125,7 @@ var O = ({ children: s, visible: u = !0, engine: be }) => {
124
125
  emailAt: D("speech.emailAt", "at"),
125
126
  emailDot: D("speech.emailDot", "dot")
126
127
  }), [D]), Y = x((e = "ended") => {
127
- let t = R.current;
128
+ let t = L.current;
128
129
  if (t) {
129
130
  e === "retrying" && t.notifyEnded(e);
130
131
  try {
@@ -133,97 +134,107 @@ var O = ({ children: s, visible: u = !0, engine: be }) => {
133
134
  t.notifyEnded();
134
135
  }
135
136
  }
136
- }, []), rt = x((e) => {
137
- H(), ze.current = null, b(I.current, "stopped"), I.current = void 0, Y(e), E.cancel(), l(Re.current, "stopped"), A({ type: "stop" });
137
+ }, []), at = x((e) => {
138
+ B(), He.current = null, b(F.current, "stopped"), F.current = void 0, Y(e), E.cancel(), l(Ve.current, "stopped"), A({ type: "stop" });
138
139
  }, [
139
- H,
140
+ B,
140
141
  Y,
141
142
  E
142
- ]), X = x(() => rt("ended"), [rt]), it = x((e) => {
143
+ ]), X = x(() => at("ended"), [at]), ot = x((e) => {
143
144
  let t = E.listVoices().find((t) => t.name === e) ?? null;
144
145
  if (t) {
145
146
  X();
146
147
  try {
147
- E.speak([n(J)], {
148
+ E.speak([n(K)], {
148
149
  voice: t,
149
- lang: $e(J),
150
+ lang: q(K),
150
151
  fallback: !1
151
152
  });
152
153
  } catch {}
153
154
  }
154
155
  }, [
155
156
  E,
156
- J,
157
+ K,
157
158
  X,
158
- $e
159
- ]), at = x((e) => Ne.get(e) ?? null, [Ne]), ot = x((e) => Pe.has(e) ? D("speech.deviceFallback", "Device voice used: the selected voice was unavailable.") : null, [Pe, D]), st = x((e, t, n, r, i) => {
160
- H();
159
+ q
160
+ ]), st = x((e) => Ie.get(e) ?? null, [Ie]), ct = x((e) => Le.has(e) ? D("speech.deviceFallback", "Device voice used: the selected voice was unavailable.") : null, [Le, D]), lt = x((e, t, n, r, i) => {
161
+ B();
161
162
  let a = !1, o = () => {}, s = (s) => {
162
- a || (a = !0, V.current = null, clearTimeout(c), o(), s.length === 0 ? (Me(!0), l(e, "declined")) : (M(s), He.current(e, t, s, n, r, i)));
163
- }, c = setTimeout(() => s(E.listVoices()), re);
164
- o = E.subscribeVoices(() => s(E.listVoices())), V.current = () => {
165
- a || (a = !0, clearTimeout(c), o(), V.current = null, l(e, "stopped"));
163
+ a || (a = !0, z.current = null, clearTimeout(c), o(), s.length === 0 ? (Fe(!0), l(e, "declined")) : (Pe(s), Ke.current(e, t, s, n, r, i)));
164
+ }, c = setTimeout(() => s(E.listVoices()), ae);
165
+ o = E.subscribeVoices(() => s(E.listVoices())), z.current = () => {
166
+ a || (a = !0, clearTimeout(c), o(), z.current = null, l(e, "stopped"));
167
+ };
168
+ }, [B, E]), ut = x((e, t) => {
169
+ let n = q(t);
170
+ return {
171
+ voice: se(e, n, W[t]),
172
+ lang: n,
173
+ rate: rt(t)
166
174
  };
167
- }, [H, E]), ct = x((e, t, n, r, i = !1, s, c = !1) => {
175
+ }, [
176
+ W,
177
+ rt,
178
+ q
179
+ ]), dt = x((e, t, n, r, i = !1, s, c = !1) => {
168
180
  let u = n;
169
181
  if (u.length === 0) {
170
182
  let e = E.listVoices();
171
- e.length > 0 && (u = e, M(e));
183
+ e.length > 0 && (u = e, Pe(e));
172
184
  }
173
- let d = $e(r), f = oe(ce(!0, u, r, N));
174
- if (f === "block") {
175
- let t = D("speech.noVoiceForReply", "This reply is in {{language}}, and no {{language}} voice is installed on this device.", { language: ie(d, O) });
176
- P((n) => new Map(n).set(e, t)), l(e, "declined");
185
+ let ne = q(r), d = ce(le(!0, u, r, M));
186
+ if (d === "block") {
187
+ let t = D("speech.noVoiceForReply", "This reply is in {{language}}, and no {{language}} voice is installed on this device.", { language: oe(ne, O) });
188
+ N((n) => new Map(n).set(e, t)), l(e, "declined");
177
189
  return;
178
190
  }
179
- if (c && (f !== "speak" || !E.open)) return;
180
- if (f === "wait-for-voices") {
181
- st(e, t, r, i, s);
191
+ if (c && (d !== "speak" || !E.open)) return;
192
+ if (d === "wait-for-voices") {
193
+ lt(e, t, r, i, s);
182
194
  return;
183
195
  }
184
- let p = {
185
- voice: ae(u, d, K[r]),
186
- lang: d,
187
- rate: et(r)
188
- }, re = ut.current;
189
- if (i && !re.autoSpeakEnabled && !re.sessionSpeaking && ee(e)) {
190
- if (E.wouldSpeakOnAvatar?.(p) !== !0) {
196
+ let f = ut(u, r), p = Q.current;
197
+ if (i && !p.autoSpeakEnabled && !p.sessionSpeaking && ee(e)) {
198
+ if (E.wouldSpeakOnAvatar?.(f) !== !0) {
191
199
  l(e, "declined");
192
200
  return;
193
201
  }
194
- p.avatarOnly = !0;
202
+ f.avatarOnly = !0;
195
203
  }
196
- P((t) => {
204
+ N((t) => {
197
205
  if (!t.has(e)) return t;
198
206
  let n = new Map(t);
199
207
  return n.delete(e), n;
200
208
  });
201
- let se = K[r], le = typeof se == "string" && a.some((e) => e.name === se) && !u.some((e) => e.name === se);
202
- Fe((t) => {
203
- if (t.has(e) === le) return t;
209
+ let ae = W[r], se = typeof ae == "string" && a.some((e) => e.name === ae) && !u.some((e) => e.name === ae);
210
+ Re((t) => {
211
+ if (t.has(e) === se) return t;
204
212
  let n = new Set(t);
205
- return le ? n.add(e) : n.delete(e), n;
206
- }), H(), Y();
207
- let m = F.current + 1;
208
- F.current = m, Re.current !== e && l(Re.current, "stopped"), Re.current = e, l(e, "speaking"), A({
213
+ return se ? n.add(e) : n.delete(e), n;
214
+ }), B(), Y();
215
+ let m = P.current + 1;
216
+ P.current = m, Ve.current !== e && l(Ve.current, "stopped"), Ve.current = e, l(e, "speaking"), A({
209
217
  type: "start",
210
218
  messageId: e,
211
219
  requestId: m
212
- }), ze.current = i ? m : null, i && ge(e, "ttsStarted"), b(I.current, "stopped");
213
- let h = i ? void 0 : me(e);
214
- I.current = h;
215
- let g = s === void 0 ? te(t) : te(t, void 0, void 0, { firstChunkMaxChars: s });
216
- Ve({
220
+ }), He.current = i ? m : null, i && ve(e, "ttsStarted"), b(F.current, "stopped");
221
+ let h = i ? void 0 : ge(e);
222
+ F.current = h;
223
+ let g = s === void 0 ? te(t) : te(t, void 0, void 0, {
224
+ firstChunkMaxChars: s,
225
+ ...ie() ? { leadSentenceMinChars: 40 } : {}
226
+ });
227
+ Ge({
217
228
  requestId: m,
218
229
  chunks: g,
219
230
  index: -1
220
- }), B.current !== null && clearTimeout(B.current), B.current = setTimeout(() => {
221
- c || Ve((e) => e?.requestId === m && e.index < 0 ? null : e);
222
- }, Ee);
231
+ }), R.current !== null && clearTimeout(R.current), R.current = setTimeout(() => {
232
+ c || Ge((e) => e?.requestId === m && e.index < 0 ? null : e);
233
+ }, Oe);
223
234
  let _ = !1, v = (t = "ended") => {
224
- _ || (_ = !0, c && F.current === m && (R.current = null, o.audio(e, t)));
235
+ _ || (_ = !0, c && P.current === m && (L.current = null, o.audio(e, t)));
225
236
  }, ue = () => {
226
- b(h, "failed"), v(), F.current === m && B.current !== null && (clearTimeout(B.current), B.current = null), l(e, "failed"), A({
237
+ b(h, "failed"), v(), P.current === m && R.current !== null && (clearTimeout(R.current), R.current = null), l(e, "failed"), A({
227
238
  type: "failed",
228
239
  requestId: m
229
240
  });
@@ -231,36 +242,36 @@ var O = ({ children: s, visible: u = !0, engine: be }) => {
231
242
  try {
232
243
  let n = {
233
244
  onStart: () => {
234
- F.current === m && b(h, "answered"), F.current === m && ze.current === m && ge(e, "firstAudio");
245
+ P.current === m && b(h, "answered"), P.current === m && He.current === m && ve(e, "firstAudio");
235
246
  },
236
247
  onChunkStart: (t) => {
237
- y = !0, c && F.current === m && (o.peek(e)?.final === !1 && he(e, { spokeNarration: !0 }), o.audio(e, "started")), F.current === m && B.current !== null && (clearTimeout(B.current), B.current = null), Ve((e) => e?.requestId === m ? {
248
+ y = !0, c && P.current === m && (o.peek(e)?.final === !1 && _e(e, { spokeNarration: !0 }), o.audio(e, "started")), P.current === m && R.current !== null && (clearTimeout(R.current), R.current = null), Ge((e) => e?.requestId === m ? {
238
249
  ...e,
239
250
  index: t
240
- } : F.current === m ? {
251
+ } : P.current === m ? {
241
252
  requestId: m,
242
253
  chunks: g,
243
254
  index: t
244
255
  } : e);
245
256
  },
246
257
  onPause: () => {
247
- c && F.current === m && o.audio(e, "paused");
258
+ c && P.current === m && o.audio(e, "paused");
248
259
  },
249
260
  onDeviceFallback: () => {
250
- F.current === m && Fe((t) => t.has(e) ? t : new Set(t).add(e));
261
+ P.current === m && Re((t) => t.has(e) ? t : new Set(t).add(e));
251
262
  },
252
263
  onEnd: () => {
253
- b(h, "stopped"), v(), F.current === m && ze.current === m && ge(e, "audioEnded"), l(e, "spoken"), A({
264
+ b(h, "stopped"), v(), P.current === m && He.current === m && ve(e, "audioEnded"), l(e, "spoken"), A({
254
265
  type: "finished",
255
266
  requestId: m
256
267
  });
257
268
  },
258
269
  onError: (t) => {
259
- b(h, t === "cancelled" ? "stopped" : "failed"), v(), !y && F.current === m && Fe((t) => {
270
+ b(h, t === "cancelled" ? "stopped" : "failed"), v(), !y && P.current === m && Re((t) => {
260
271
  if (!t.has(e)) return t;
261
272
  let n = new Set(t);
262
273
  return n.delete(e), n;
263
- }), t === "output-not-cleared" && F.current === m && Le({ messageId: e }), l(e, t === "output-not-cleared" ? "not-cleared" : t === "output-left" ? y ? "cut" : "declined" : t === "cancelled" ? "stopped" : "failed"), A({
274
+ }), t === "output-not-cleared" && P.current === m && Be({ messageId: e }), l(e, t === "output-not-cleared" ? "not-cleared" : t === "output-left" ? y ? "cut" : "declined" : t === "cancelled" ? "stopped" : "failed"), A({
264
275
  type: "failed",
265
276
  requestId: m
266
277
  });
@@ -269,53 +280,53 @@ var O = ({ children: s, visible: u = !0, engine: be }) => {
269
280
  if (c && E.open) {
270
281
  let i = E.open.bind(E);
271
282
  o.audio(e, "queued");
272
- let a = ne((e) => i(p, e), n, (e) => {
273
- g = [...e], Ve((e) => e?.requestId === m ? {
283
+ let a = re((e) => i(f, e), n, (e) => {
284
+ g = [...e], Ge((e) => e?.requestId === m ? {
274
285
  ...e,
275
286
  chunks: g
276
287
  } : e);
277
- }, () => he(e, { speechDivergence: !0 }));
278
- _ ? a.cancel() : (R.current = {
288
+ }, () => _e(e, { speechDivergence: !0 }));
289
+ _ ? a.cancel() : (L.current = {
279
290
  messageId: e,
280
291
  requestId: m,
281
292
  locale: r,
282
293
  playback: a,
283
294
  notifyEnded: v
284
295
  }, a.append(t));
285
- } else E.speak(g, p, n);
296
+ } else E.speak(g, f, n);
286
297
  } catch {
287
298
  ue();
288
299
  }
289
300
  }, [
290
- H,
301
+ B,
291
302
  Y,
292
303
  E,
293
304
  O,
294
- K,
295
- et,
296
- $e,
305
+ W,
306
+ ut,
307
+ q,
297
308
  D,
298
- N,
299
- st
309
+ M,
310
+ lt
300
311
  ]);
301
312
  S(() => {
302
- He.current = ct;
303
- }, [ct]);
313
+ Ke.current = dt;
314
+ }, [dt]);
304
315
  let Z = x((e, t, n, r) => {
305
- if (!G) return;
306
- let i = m(d(t, { labels: Te }), n ?? J), a = d(t, {
307
- labels: p(i, nt),
316
+ if (!U) return;
317
+ let i = g(d(t, { labels: De }), n ?? K), a = d(t, {
318
+ labels: p(i, J),
308
319
  locale: i
309
320
  });
310
- a && ct(e, a, j, i, r?.auto === !0, r?.firstChunkMaxChars, r?.phraseStream);
321
+ a && dt(e, a, j, i, r?.auto === !0, r?.firstChunkMaxChars, r?.phraseStream);
311
322
  }, [
312
- G,
313
- nt,
323
+ U,
314
324
  J,
315
- ct,
325
+ K,
326
+ dt,
316
327
  j
317
- ]), lt = x((e, t, n) => {
318
- v(k, e) ? X() : Z(e, t, n);
328
+ ]), ft = x((e, t, n) => {
329
+ y(k, e) ? X() : Z(e, t, n);
319
330
  }, [
320
331
  k,
321
332
  Z,
@@ -324,220 +335,245 @@ var O = ({ children: s, visible: u = !0, engine: be }) => {
324
335
  S(() => {
325
336
  u || X();
326
337
  }, [u, X]);
327
- let ut = w({
328
- autoSpeakEnabled: U,
329
- sessionSpeaking: W,
338
+ let Q = w({
339
+ autoSpeakEnabled: V,
340
+ sessionSpeaking: H,
330
341
  visible: u,
331
- isSupported: G
342
+ isSupported: U
332
343
  });
333
344
  S(() => {
334
- ut.current = {
335
- autoSpeakEnabled: U,
336
- sessionSpeaking: W,
345
+ Q.current = {
346
+ autoSpeakEnabled: V,
347
+ sessionSpeaking: H,
337
348
  visible: u,
338
- isSupported: G
349
+ isSupported: U
339
350
  };
340
351
  }, [
341
- U,
342
- W,
352
+ V,
353
+ H,
343
354
  u,
344
- G
355
+ U
345
356
  ]);
346
- let dt = w(null), ft = w(null), pt = w(() => {});
357
+ let pt = w(null), mt = w(null), ht = w(() => {});
347
358
  S(() => {
348
- X(), z.current.clear(), P(/* @__PURE__ */ new Map()), Fe(/* @__PURE__ */ new Set()), c(t.getState().activeConversationId), dt.current = qe;
349
- let e = ft.current;
350
- ft.current = null, e && e.conversationId === qe && pt.current(e.conversationId, e.messageId);
351
- }, [qe, X]), S(() => {
352
- P((e) => e.size === 0 ? e : /* @__PURE__ */ new Map()), X();
353
- }, [J, X]), S(() => () => {
354
- V.current?.(), V.current = null, b(I.current, "stopped"), I.current = void 0, Y(), E.cancel();
359
+ X(), Ue.current.clear(), N(/* @__PURE__ */ new Map()), Re(/* @__PURE__ */ new Set()), c(t.getState().activeConversationId), pt.current = Ze;
360
+ let e = mt.current;
361
+ mt.current = null, e && e.conversationId === Ze && ht.current(e.conversationId, e.messageId);
362
+ }, [Ze, X]), S(() => {
363
+ N((e) => e.size === 0 ? e : /* @__PURE__ */ new Map()), X();
364
+ }, [K, X]), S(() => () => {
365
+ z.current?.(), z.current = null, b(F.current, "stopped"), F.current = void 0, Y(), E.cancel();
355
366
  }, [Y, E]), S(() => {
356
367
  if (typeof window > "u") return;
357
- let { settle: e, unregister: t } = _e(() => (b(I.current, "stopped"), I.current)), n = () => {
358
- e(), I.current = void 0, Y(), E.cancel();
368
+ let { settle: e, unregister: t } = ye(() => (b(F.current, "stopped"), F.current)), n = () => {
369
+ e(), F.current = void 0, Y(), E.cancel();
359
370
  };
360
371
  return window.addEventListener("pagehide", n), () => {
361
372
  t(), window.removeEventListener("pagehide", n);
362
373
  };
363
374
  }, [Y, E]), S(() => {
364
- if (typeof document > "u" || !G) return;
375
+ if (typeof document > "u" || !U) return;
365
376
  let e = () => {
366
377
  if (document.visibilityState !== "visible") return;
367
378
  let e = E.listVoices();
368
- e.length > 0 && H(), M(e), Me(!1), P((e) => e.size === 0 ? e : /* @__PURE__ */ new Map());
379
+ e.length > 0 && B(), Pe(e), Fe(!1), N((e) => e.size === 0 ? e : /* @__PURE__ */ new Map());
369
380
  };
370
381
  return document.addEventListener("visibilitychange", e), window.addEventListener("focus", e), () => {
371
382
  document.removeEventListener("visibilitychange", e), window.removeEventListener("focus", e);
372
383
  };
373
384
  }, [
374
- H,
385
+ B,
375
386
  E,
376
- G
387
+ U
377
388
  ]);
378
- let mt = w(Z);
389
+ let gt = w(Z);
379
390
  S(() => {
380
- mt.current = Z;
391
+ gt.current = Z;
381
392
  }, [Z]);
382
- let Q = x((e, t) => {
383
- if (de(e) !== t || fe(e.id) || L.current?.messageId === e.id || Ge.current) return;
384
- let { text: n } = ve(e.content);
393
+ let $ = x((e, t) => {
394
+ if (pe(e) !== t || me(e.id) || I.current?.messageId === e.id || Ye.current) return;
395
+ let { text: n } = be(e.content);
385
396
  if (n.trim()) try {
386
- mt.current(e.id, n, e.metadata?.lang, { auto: !0 });
397
+ gt.current(e.id, n, e.metadata?.lang, { auto: !0 });
387
398
  } catch {}
388
- }, []), $ = x((e, n) => {
389
- if (e !== dt.current) {
390
- t.getState().activeConversationId === e && (ft.current = {
399
+ }, []), _t = x((e, n) => {
400
+ if (e !== pt.current) {
401
+ t.getState().activeConversationId === e && (mt.current = {
391
402
  conversationId: e,
392
403
  messageId: n
393
404
  });
394
405
  return;
395
406
  }
396
- let r = ke(ut.current, n);
407
+ let r = je(Q.current, n);
397
408
  if (!r.autoSpeakEnabled && !r.sessionSpeaking || !r.visible || !r.isSupported) return;
398
409
  let i = t.getState();
399
410
  if (i.activeConversationId !== e) return;
400
411
  let a = i.conversations.find((t) => t.id === e)?.messages.find((e) => e.id === n);
401
- a && a.role === "assistant" && Q(a, r.sessionSpeaking);
402
- }, [Q]);
412
+ a && a.role === "assistant" && $(a, r.sessionSpeaking);
413
+ }, [$]);
403
414
  S(() => {
404
- pt.current = $;
405
- }, [$]), S(() => {
406
- if ((U || W) && u && G) return t.subscribe((e, t) => {
415
+ ht.current = _t;
416
+ }, [_t]), S(() => {
417
+ if ((V || H) && u && U) return t.subscribe((e, t) => {
407
418
  let n = e.activeConversationId;
408
419
  if (!n || n !== t.activeConversationId) return;
409
420
  let r = e.processingByConversationId[n], i = t.processingByConversationId[n];
410
- if (r?.status !== "complete" || !pe(i?.status)) return;
421
+ if (r?.status !== "complete" || !he(i?.status)) return;
411
422
  let a = r.messageId ?? i?.messageId ?? null;
412
423
  if (!a) return;
413
424
  let o = e.conversations.find((e) => e.id === n)?.messages.find((e) => e.id === a);
414
- o && o.role === "assistant" && Q(o, W);
425
+ o && o.role === "assistant" && $(o, H);
415
426
  });
416
427
  }, [
428
+ V,
429
+ H,
417
430
  U,
418
- W,
419
- G,
420
431
  u,
421
- Q
432
+ $
422
433
  ]), S(() => {
423
- if (!U && !W && Ye && u && G) return t.subscribe((e, t) => {
424
- let n = Ae(e, t);
425
- n && ee(n.id) && Q(n, !1);
434
+ if (!V && !H && $e && u && U) return t.subscribe((e, t) => {
435
+ let n = Me(e, t);
436
+ n && ee(n.id) && $(n, !1);
426
437
  });
427
438
  }, [
439
+ V,
440
+ H,
441
+ $e,
428
442
  U,
429
- W,
430
- Ye,
431
- G,
432
443
  u,
433
- Q
444
+ $
434
445
  ]);
435
- let ht = x((e) => {
446
+ let vt = w(null), yt = x((e, n) => {
447
+ if (!ie() || !E.prefetch || !U || vt.current === e || n.channel !== "voice") return;
448
+ let r = je(Q.current, e);
449
+ if (!r.sessionSpeaking || !r.visible || !r.isSupported || me(e) || t.getState().activeConversationId !== n.conversationId) return;
450
+ let i = be(n.text).text, a = g(d(i, { labels: De }), n.lang ?? K), o = d(i, {
451
+ labels: p(a, J),
452
+ locale: a
453
+ }), s = ne(o, {
454
+ firstChunkMaxChars: 110,
455
+ leadSentenceMinChars: 40
456
+ });
457
+ s !== null && ce(le(!0, j, a, M)) === "speak" && (vt.current = e, E.prefetch(s, ut(j, a)));
458
+ }, [
459
+ E,
460
+ U,
461
+ J,
462
+ ut,
463
+ K,
464
+ M,
465
+ j
466
+ ]), bt = x((e) => {
436
467
  if (e.type === "audio") return;
468
+ if (e.type === "prefetch") {
469
+ yt(e.messageId, e.item);
470
+ return;
471
+ }
437
472
  if (e.type === "retract") {
438
- R.current?.messageId === e.messageId && R.current.playback.retract();
473
+ L.current?.messageId === e.messageId && L.current.playback.retract();
439
474
  return;
440
475
  }
441
476
  if (e.type === "abort") {
442
- z.current.delete(e.messageId);
443
- let t = L.current;
477
+ Ue.current.delete(e.messageId), vt.current === e.messageId && (vt.current = null, E.cancelPrefetch?.());
478
+ let t = I.current;
444
479
  if (!t || t.messageId !== e.messageId) return;
445
- L.current = null, (t.requestId === null ? t.waiting && V.current !== null : F.current === t.requestId) && rt(e.retrying ? "retrying" : "ended");
480
+ I.current = null, (t.requestId === null ? t.waiting && z.current !== null : P.current === t.requestId) && at(e.retrying ? "retrying" : "ended");
446
481
  return;
447
482
  }
448
483
  let { messageId: n, item: r } = e;
449
- if (e.type === "append" && R.current?.messageId !== n) {
450
- if (z.current.has(n)) return;
451
- z.current.add(n);
484
+ if (e.type === "append" && L.current?.messageId !== n) {
485
+ if (Ue.current.has(n)) return;
486
+ Ue.current.add(n);
452
487
  }
453
- let i = ke(ut.current, n);
454
- if (!i.autoSpeakEnabled && !i.sessionSpeaking || !i.visible || !i.isSupported || r.channel === "voice" !== i.sessionSpeaking || fe(n) || Ge.current || t.getState().activeConversationId !== r.conversationId || dt.current !== r.conversationId) return;
455
- let a = R.current;
456
- if (a?.messageId === n && a.requestId === F.current) {
457
- let t = d(e.type === "append" ? e.phrases.join(" ") : ve(r.text).text, {
458
- labels: p(a.locale, nt),
488
+ let i = je(Q.current, n);
489
+ if (!i.autoSpeakEnabled && !i.sessionSpeaking || !i.visible || !i.isSupported || r.channel === "voice" !== i.sessionSpeaking || me(n) || Ye.current || t.getState().activeConversationId !== r.conversationId || pt.current !== r.conversationId) return;
490
+ let a = L.current;
491
+ if (a?.messageId === n && a.requestId === P.current) {
492
+ let t = d(e.type === "append" ? e.phrases.join(" ") : be(r.text).text, {
493
+ labels: p(a.locale, J),
459
494
  locale: a.locale
460
495
  });
461
496
  e.type === "append" ? a.playback.append(t) : a.playback.finish(t);
462
497
  return;
463
498
  }
464
- if (L.current?.messageId === n || e.type === "append" && (!f() || !E.open || r.channel !== "voice")) return;
465
- let { text: o } = ve(e.type === "append" ? e.phrases.join(" ") : r.text);
499
+ if (I.current?.messageId === n || e.type === "append" && (!f() || !E.open || r.channel !== "voice")) return;
500
+ let { text: o } = be(e.type === "append" ? e.phrases.join(" ") : r.text);
466
501
  if (!o.trim()) return;
467
- let s = F.current;
502
+ let s = P.current;
468
503
  try {
469
- mt.current(n, o, r.lang, {
504
+ gt.current(n, o, r.lang, {
470
505
  auto: !0,
471
506
  firstChunkMaxChars: 110,
472
507
  phraseStream: e.type === "append"
473
508
  });
474
509
  } catch {}
475
- let c = F.current !== s;
476
- (e.type !== "append" || c) && (z.current.delete(n), L.current = {
510
+ let c = P.current !== s;
511
+ (e.type !== "append" || c) && (Ue.current.delete(n), I.current = {
477
512
  messageId: n,
478
- requestId: c ? F.current : null,
479
- waiting: !c && V.current !== null
513
+ requestId: c ? P.current : null,
514
+ waiting: !c && z.current !== null
480
515
  });
481
516
  }, [
482
- rt,
517
+ at,
483
518
  E,
484
- nt
519
+ J,
520
+ yt
485
521
  ]);
486
- S(() => o.subscribe(ht), [ht]);
487
- let gt = C(() => le(j, q.tag), [j, q]), _t = C(() => ae(j, q.tag, K[J]), [
522
+ S(() => o.subscribe(bt), [bt]);
523
+ let xt = C(() => h(j, G.tag), [j, G]), St = C(() => se(j, G.tag, W[K]), [
488
524
  j,
489
- q,
490
- K,
491
- J
492
- ]), vt = C(() => ({
493
- isSupported: G,
494
- availability: tt,
495
- isBlocked: tt === "no-voices",
496
- disabledReason: tt === "no-voices" ? D("speech.noVoicesOnDevice", "This device has no speech voices installed. Add one in your device speech or accessibility settings.") : null,
497
- blockedFor: at,
498
- deviceFallbackFor: ot,
499
- voiceChoices: gt,
500
- spokenChunks: ue(k, Be),
501
- activeVoiceName: _t?.name ?? null,
502
- preferredVoiceName: K[J] ?? null,
503
- setVoice: (e) => Qe(J, e),
525
+ G,
526
+ W,
527
+ K
528
+ ]), Ct = C(() => ({
529
+ isSupported: U,
530
+ availability: it,
531
+ isBlocked: it === "no-voices",
532
+ disabledReason: it === "no-voices" ? D("speech.noVoicesOnDevice", "This device has no speech voices installed. Add one in your device speech or accessibility settings.") : null,
533
+ blockedFor: st,
534
+ deviceFallbackFor: ct,
535
+ voiceChoices: xt,
536
+ spokenChunks: de(k, We),
537
+ activeVoiceName: St?.name ?? null,
538
+ preferredVoiceName: W[K] ?? null,
539
+ setVoice: (e) => nt(K, e),
504
540
  speakingMessageId: k.status === "speaking" ? k.messageId : null,
505
- outputNotCleared: Ie,
506
- isSpeaking: (e) => v(k, e),
507
- toggle: lt,
541
+ outputNotCleared: ze,
542
+ isSpeaking: (e) => y(k, e),
543
+ toggle: ft,
508
544
  stop: X,
509
- autoSpeakEnabled: U,
510
- setAutoSpeak: Ue,
511
- sessionSpeaking: W,
512
- setSessionSpeaking: We,
513
- setSessionMicOpen: Ke,
514
- speakFinishedReply: $,
515
- previewVoice: it
545
+ autoSpeakEnabled: V,
546
+ setAutoSpeak: qe,
547
+ sessionSpeaking: H,
548
+ setSessionSpeaking: Je,
549
+ setSessionMicOpen: Xe,
550
+ speakFinishedReply: _t,
551
+ previewVoice: ot
516
552
  }), [
517
- G,
518
- tt,
519
- at,
520
- ot,
521
- gt,
522
- _t,
553
+ U,
554
+ it,
555
+ st,
556
+ ct,
557
+ xt,
558
+ St,
559
+ W,
560
+ nt,
523
561
  K,
524
- Qe,
525
- J,
526
562
  k,
527
- Ie,
528
- lt,
563
+ ze,
564
+ ft,
529
565
  X,
530
- U,
531
- Ue,
532
- W,
533
- Ke,
534
- $,
535
- it,
566
+ V,
567
+ qe,
568
+ H,
569
+ Xe,
570
+ _t,
571
+ ot,
536
572
  D,
537
- Be
573
+ We
538
574
  ]);
539
- return /* @__PURE__ */ we(je.Provider, {
540
- value: vt,
575
+ return /* @__PURE__ */ Ee(Ne.Provider, {
576
+ value: Ct,
541
577
  children: s
542
578
  });
543
579
  };