@streamoji/aitwin 0.2.8 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/aitwin.js CHANGED
@@ -1,76 +1,76 @@
1
- import { jsxs as In, jsx as Mt } from "react/jsx-runtime";
2
- import { forwardRef as Rn, useRef as L, useState as Ve, useCallback as me, useEffect as Me, useMemo as Pt, useImperativeHandle as Dn } from "react";
3
- import { PipecatClient as xn } from "@pipecat-ai/client-js";
4
- import { WebSocketTransport as Cn, DailyMediaManager as Mn, ProtobufFrameSerializer as Pn } from "@pipecat-ai/websocket-transport";
5
- const Bn = "https://pub-607ad1fc22e2400eb57d17240aab857c.r2.dev", en = {
6
- publicBase: Bn
7
- }, On = "0.2.8", Fn = {
8
- version: On
9
- }, Ln = {}, Te = "https://ai.streamoji.com", St = `${en.publicBase}/custom-faces`, Un = `${en.publicBase}/aitwin-workers/v${Fn.version}/visemeDiffPreview.worker.js`;
10
- function Nn(e) {
1
+ import { jsxs as Dn, jsx as Bt } from "react/jsx-runtime";
2
+ import { forwardRef as Cn, useRef as U, useState as We, useCallback as he, useEffect as Be, useMemo as Ft, useImperativeHandle as xn } from "react";
3
+ import { PipecatClient as Mn } from "@pipecat-ai/client-js";
4
+ import { WebSocketTransport as Pn, DailyMediaManager as Bn, ProtobufFrameSerializer as Fn } from "@pipecat-ai/websocket-transport";
5
+ const On = "https://pub-607ad1fc22e2400eb57d17240aab857c.r2.dev", nn = {
6
+ publicBase: On
7
+ }, Ln = "0.2.9", Un = {
8
+ version: Ln
9
+ }, Nn = {}, Ae = "https://ai.streamoji.com", Et = `${nn.publicBase}/custom-faces`, Vn = `${nn.publicBase}/aitwin-workers/v${Un.version}/visemeDiffPreview.worker.js`;
10
+ function $n(e) {
11
11
  if (e) return e;
12
- const t = typeof import.meta < "u" ? Ln?.VITE_AITWIN_WORKER_URL : void 0;
13
- return t?.trim() ? t.trim() : Un;
14
- }
15
- const Vn = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", tn = "eng_a7f2b9c1", Et = "eng_d4e8f3a2", Oe = "eng_c9b1e6d4", Be = Oe, nn = /* @__PURE__ */ new Set([
16
- Et,
17
- Oe
18
- ]), rn = {
19
- [tn]: "oculus_direct",
20
- [Oe]: "oculus_direct",
21
- [Et]: "inworld_word"
22
- }, Bt = {
23
- google: tn,
24
- inworld: Et,
25
- cartesia: Oe
12
+ const t = typeof import.meta < "u" ? Nn?.VITE_AITWIN_WORKER_URL : void 0;
13
+ return t?.trim() ? t.trim() : Vn;
14
+ }
15
+ const Wn = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", rn = "eng_a7f2b9c1", bt = "eng_d4e8f3a2", Le = "eng_c9b1e6d4", Oe = Le, sn = /* @__PURE__ */ new Set([
16
+ bt,
17
+ Le
18
+ ]), on = {
19
+ [rn]: "oculus_direct",
20
+ [Le]: "oculus_direct",
21
+ [bt]: "inworld_word"
22
+ }, Ot = {
23
+ google: rn,
24
+ inworld: bt,
25
+ cartesia: Le
26
26
  };
27
- function $n(e) {
28
- return rn[e];
27
+ function Hn(e) {
28
+ return on[e];
29
29
  }
30
- function Wn(e) {
31
- return e === Oe;
30
+ function qn(e) {
31
+ return e === Le;
32
32
  }
33
- function Hn(e) {
34
- if (e.ttsEngineId && e.ttsEngineId in rn)
33
+ function Kn(e) {
34
+ if (e.ttsEngineId && e.ttsEngineId in on)
35
35
  return e.ttsEngineId;
36
36
  const t = e.tts?.toLowerCase();
37
- return t && t in Bt ? Bt[t] : Be;
37
+ return t && t in Ot ? Ot[t] : Oe;
38
38
  }
39
- class wt extends Error {
39
+ class gt extends Error {
40
40
  constructor(t = "AI twin not found") {
41
41
  super(t), this.name = "AiTwinNotFoundError";
42
42
  }
43
43
  }
44
- async function qn(e, t = Vn) {
44
+ async function jn(e, t = Wn) {
45
45
  const n = new URL(t);
46
46
  n.searchParams.set("id", e);
47
47
  const r = await fetch(n.toString());
48
48
  if (r.status === 404)
49
- throw new wt();
49
+ throw new gt();
50
50
  if (!r.ok)
51
51
  throw new Error(`getAiTwin failed (${r.status})`);
52
52
  const s = await r.json();
53
53
  if (!s.success)
54
- throw new wt(s.error ?? "AI twin not found");
54
+ throw new gt(s.error ?? "AI twin not found");
55
55
  const { tts: i, token: o, ...c } = s.data, l = String(c.authToken ?? o ?? "").trim() || void 0;
56
56
  return {
57
57
  ...c,
58
- ttsEngineId: Hn(s.data),
58
+ ttsEngineId: Kn(s.data),
59
59
  authToken: l
60
60
  };
61
61
  }
62
- const Kn = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", jn = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", zn = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", Gn = "6TNvp3SCs4Og0a1ijm9TommXLql1", Qn = "Swaraj Mali";
63
- async function ft() {
64
- const e = await fetch(Kn, {
62
+ const zn = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", Gn = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", Qn = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", Yn = "6TNvp3SCs4Og0a1ijm9TommXLql1", Jn = "Swaraj Mali";
63
+ async function dt() {
64
+ const e = await fetch(zn, {
65
65
  method: "POST",
66
66
  headers: {
67
67
  "Content-Type": "application/json",
68
- "Client-Id": jn,
69
- "Client-Secret": zn
68
+ "Client-Id": Gn,
69
+ "Client-Secret": Qn
70
70
  },
71
71
  body: JSON.stringify({
72
- userId: Gn,
73
- userName: Qn
72
+ userId: Yn,
73
+ userName: Jn
74
74
  })
75
75
  });
76
76
  if (!e.ok)
@@ -80,7 +80,7 @@ async function ft() {
80
80
  throw new Error("getAuthToken returned no token");
81
81
  return n;
82
82
  }
83
- async function Yn(e, t = Te) {
83
+ async function Xn(e, t = Ae) {
84
84
  const n = await fetch(`${t.replace(/\/$/, "")}/api/session-value`, {
85
85
  headers: { Authorization: `Bearer ${e}` }
86
86
  });
@@ -90,7 +90,7 @@ async function Yn(e, t = Te) {
90
90
  if (!r.value) throw new Error("Session value response missing value");
91
91
  return r;
92
92
  }
93
- function Jn(e) {
93
+ function Zn(e) {
94
94
  const t = e.trim();
95
95
  if (t.length % 2 !== 0) throw new Error("Invalid hex key");
96
96
  const n = new Uint8Array(t.length / 2);
@@ -98,20 +98,20 @@ function Jn(e) {
98
98
  n[r / 2] = Number.parseInt(t.slice(r, r + 2), 16);
99
99
  return n;
100
100
  }
101
- function Ge(e) {
101
+ function Qe(e) {
102
102
  return Uint8Array.from(e);
103
103
  }
104
- function Xn(e, t) {
104
+ function er(e, t) {
105
105
  const n = new Uint8Array(e.length + t.length);
106
106
  return n.set(e, 0), n.set(t, e.length), n;
107
107
  }
108
- async function Zn(e, t) {
108
+ async function tr(e, t) {
109
109
  if (!t) throw new Error("Asset key is required for encrypted assets");
110
110
  if (e.byteLength < 28)
111
111
  throw new Error("Encrypted payload too small");
112
- const n = new Uint8Array(e), r = Ge(n.subarray(0, 12)), s = Ge(n.subarray(12, 28)), i = Ge(n.subarray(28)), o = Ge(Xn(i, s)), c = await crypto.subtle.importKey(
112
+ const n = new Uint8Array(e), r = Qe(n.subarray(0, 12)), s = Qe(n.subarray(12, 28)), i = Qe(n.subarray(28)), o = Qe(er(i, s)), c = await crypto.subtle.importKey(
113
113
  "raw",
114
- Jn(t),
114
+ Zn(t),
115
115
  { name: "AES-GCM" },
116
116
  !1,
117
117
  ["decrypt"]
@@ -122,35 +122,35 @@ async function Zn(e, t) {
122
122
  o
123
123
  );
124
124
  }
125
- let gt = null;
126
- const _t = /* @__PURE__ */ new Set();
127
- function Qe(e) {
125
+ let _t = null;
126
+ const pt = /* @__PURE__ */ new Set();
127
+ function Ye(e) {
128
128
  return e.includes("/custom-faces/");
129
129
  }
130
- function Xe(e) {
130
+ function Ze(e) {
131
131
  const t = e.binBase.trim().replace(/\/$/, ""), n = e.twinBase.trim().replace(/\/$/, "");
132
- if (!(e.encrypted || Qe(t) || Qe(n)))
132
+ if (!(e.encrypted || Ye(t) || Ye(n)))
133
133
  return { twinBase: n, binBase: t, encrypted: !1 };
134
- const s = Qe(t) ? t : Qe(n) ? n : t;
134
+ const s = Ye(t) ? t : Ye(n) ? n : t;
135
135
  return { twinBase: s, binBase: s, encrypted: !0 };
136
136
  }
137
- function Fe(e) {
138
- return Xe(e).encrypted;
137
+ function Ue(e) {
138
+ return Ze(e).encrypted;
139
139
  }
140
- function Ot(e, t = St) {
140
+ function Lt(e, t = Et) {
141
141
  const n = `${t.replace(/\/$/, "")}/${e}`;
142
142
  return { twinBase: n, binBase: n, encrypted: !0 };
143
143
  }
144
- function er(e, t) {
144
+ function nr(e, t) {
145
145
  return (e ?? t)?.trim() || void 0;
146
146
  }
147
- function tr(e) {
148
- gt = Xe(e);
149
- for (const t of _t) t();
147
+ function rr(e) {
148
+ _t = Ze(e);
149
+ for (const t of pt) t();
150
150
  }
151
- function nr(e, t) {
151
+ function sr(e, t) {
152
152
  const n = typeof globalThis.location < "u" ? globalThis.location.href : void 0;
153
- if (!n) return Xe(e);
153
+ if (!n) return Ze(e);
154
154
  const r = (s) => {
155
155
  try {
156
156
  return new URL(s, n).href.replace(/\/$/, "");
@@ -158,44 +158,44 @@ function nr(e, t) {
158
158
  return s;
159
159
  }
160
160
  };
161
- return Xe({
161
+ return Ze({
162
162
  twinBase: r(e.twinBase),
163
163
  binBase: r(e.binBase),
164
164
  encrypted: e.encrypted
165
165
  });
166
166
  }
167
- function Ie() {
168
- if (!gt)
167
+ function Re() {
168
+ if (!_t)
169
169
  throw new Error("Twin assets not configured; call setActiveTwinAssets first");
170
- return gt;
170
+ return _t;
171
171
  }
172
- function rr(e) {
173
- return _t.add(e), () => _t.delete(e);
172
+ function ir(e) {
173
+ return pt.add(e), () => pt.delete(e);
174
174
  }
175
- function Ft() {
176
- const e = Ie();
177
- return Fe(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
175
+ function Ut() {
176
+ const e = Re();
177
+ return Ue(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
178
178
  }
179
- function sr() {
180
- const e = Ie();
181
- return Fe(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
179
+ function or() {
180
+ const e = Re();
181
+ return Ue(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
182
182
  }
183
- function ir() {
184
- const e = Ie();
185
- return Fe(e) ? e.binBase : e.twinBase;
183
+ function ar() {
184
+ const e = Re();
185
+ return Ue(e) ? e.binBase : e.twinBase;
186
186
  }
187
- function tt() {
188
- return Fe(Ie());
187
+ function nt() {
188
+ return Ue(Re());
189
189
  }
190
- function or() {
191
- const e = Ie();
192
- return Fe(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
190
+ function cr() {
191
+ const e = Re();
192
+ return Ue(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
193
193
  }
194
- function ar() {
195
- const e = Ie();
196
- return Fe(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
194
+ function ur() {
195
+ const e = Re();
196
+ return Ue(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
197
197
  }
198
- function sn(e) {
198
+ function an(e) {
199
199
  const t = e.split(/\r?\n/);
200
200
  let n = "", r = "";
201
201
  for (const i of t)
@@ -210,7 +210,7 @@ function sn(e) {
210
210
  }
211
211
  return { event: n, data: s };
212
212
  }
213
- const cr = [
213
+ const lr = [
214
214
  "aa",
215
215
  "CH",
216
216
  "DD",
@@ -226,14 +226,14 @@ const cr = [
226
226
  "kk",
227
227
  "nn",
228
228
  "sil"
229
- ], ur = new Map(
230
- cr.map((e) => [e.toLowerCase(), e])
229
+ ], fr = new Map(
230
+ lr.map((e) => [e.toLowerCase(), e])
231
231
  );
232
- function lr(e) {
232
+ function dr(e) {
233
233
  const t = (e ?? "").trim();
234
- return t ? ur.get(t.toLowerCase()) ?? "sil" : "sil";
234
+ return t ? fr.get(t.toLowerCase()) ?? "sil" : "sil";
235
235
  }
236
- const fr = {
236
+ const mr = {
237
237
  aei: ["aa", "E", "I"],
238
238
  o: ["O", "U"],
239
239
  ee: ["I"],
@@ -245,12 +245,12 @@ const fr = {
245
245
  qw: ["U", "O"],
246
246
  cdgknstxyz: ["DD", "SS", "kk", "CH"]
247
247
  };
248
- function dr(e) {
248
+ function hr(e) {
249
249
  if (!e) return ["sil"];
250
250
  const t = e.toLowerCase();
251
- return fr[t] ?? ["sil"];
251
+ return mr[t] ?? ["sil"];
252
252
  }
253
- function mr(e, t) {
253
+ function wr(e, t) {
254
254
  const n = e.word.length;
255
255
  if (n <= 0) return 0;
256
256
  const r = e.wduration;
@@ -258,33 +258,33 @@ function mr(e, t) {
258
258
  const s = Math.max(0, Math.min(1, (t - e.wtime) / r));
259
259
  return Math.min(n - 1, Math.floor(s * n));
260
260
  }
261
- function nt(e, t) {
261
+ function rt(e, t) {
262
262
  const n = Math.max(0, Math.min(e.length - 1, t));
263
263
  return e[n] ?? "";
264
264
  }
265
- function hr(e, t) {
266
- const n = e.toLowerCase(), r = nt(n, t), s = n.slice(Math.max(0, t - 1), t + 2);
265
+ function gr(e, t) {
266
+ const n = e.toLowerCase(), r = rt(n, t), s = n.slice(Math.max(0, t - 1), t + 2);
267
267
  return r === "i" || r === "y" ? "I" : s.includes("ee") || r === "e" || n.includes("ea") ? "E" : "aa";
268
268
  }
269
- function wr(e, t) {
269
+ function _r(e, t) {
270
270
  const n = e.toLowerCase(), r = n.slice(
271
271
  Math.max(0, t - 1),
272
272
  Math.min(n.length, t + 3)
273
273
  );
274
274
  if (/oo|ou|uw/.test(r)) return "U";
275
- const s = nt(n, t);
275
+ const s = rt(n, t);
276
276
  return s === "u" || s === "w" ? "U" : "O";
277
277
  }
278
- function gr(e, t) {
278
+ function pr(e, t) {
279
279
  const n = e.toLowerCase(), r = n.slice(Math.max(0, t - 2), t + 1);
280
280
  if (/qu/.test(r)) return "U";
281
281
  const s = n.slice(
282
282
  Math.max(0, t - 1),
283
283
  Math.min(n.length, t + 3)
284
284
  );
285
- return /wo|wh/.test(s) || nt(n, t) === "o" ? "O" : "U";
285
+ return /wo|wh/.test(s) || rt(n, t) === "o" ? "O" : "U";
286
286
  }
287
- const Ye = {
287
+ const Je = {
288
288
  d: "DD",
289
289
  t: "DD",
290
290
  n: "DD",
@@ -296,46 +296,50 @@ const Ye = {
296
296
  x: "CH",
297
297
  j: "CH"
298
298
  };
299
- function _r(e, t) {
300
- const n = e.toLowerCase(), r = nt(n, t);
301
- if (Ye[r]) return Ye[r];
299
+ function yr(e, t) {
300
+ const n = e.toLowerCase(), r = rt(n, t);
301
+ if (Je[r]) return Je[r];
302
302
  for (let s = 0; s < n.length; s++) {
303
303
  const i = n[s];
304
- if (Ye[i]) return Ye[i];
304
+ if (Je[i]) return Je[i];
305
305
  }
306
306
  return "DD";
307
307
  }
308
- function pr(e, t, n) {
309
- const r = dr(e);
308
+ function kr(e, t, n) {
309
+ const r = hr(e);
310
310
  if (r.length === 1) return r[0];
311
311
  const s = t.trim();
312
312
  if (!s) return r[0];
313
313
  const i = (e ?? "").toLowerCase(), o = Math.max(0, n);
314
314
  switch (i) {
315
315
  case "aei":
316
- return hr(s, o);
316
+ return gr(s, o);
317
317
  case "o":
318
- return wr(s, o);
318
+ return _r(s, o);
319
319
  case "qw":
320
- return gr(s, o);
320
+ return pr(s, o);
321
321
  case "cdgknstxyz":
322
- return _r(s, o);
322
+ return yr(s, o);
323
323
  default:
324
324
  return r[0];
325
325
  }
326
326
  }
327
- const yr = 24e3;
328
- function kr(e) {
327
+ const Tt = 16e3;
328
+ function cn(e) {
329
+ const t = Number(e);
330
+ return Number.isFinite(t) && t > 0 ? t : Tt;
331
+ }
332
+ function vr(e) {
329
333
  let t = e.trim();
330
334
  const n = t.indexOf(",");
331
335
  t.startsWith("data:") && n >= 0 && (t = t.slice(n + 1)), t = t.replace(/\s+/g, "").replace(/-/g, "+").replace(/_/g, "/");
332
336
  const r = t.length % 4;
333
337
  return r !== 0 && (t += "=".repeat(4 - r)), t;
334
338
  }
335
- function vr(e) {
339
+ function Sr(e) {
336
340
  return e.length >= 4 && e[0] === 82 && e[1] === 73 && e[2] === 70 && e[3] === 70;
337
341
  }
338
- function Lt(e, t, n = yr) {
342
+ function Nt(e, t, n = Tt) {
339
343
  const r = t.byteOffset % 2 === 0 ? t : t.slice(), s = new Int16Array(
340
344
  r.buffer,
341
345
  r.byteOffset,
@@ -346,46 +350,46 @@ function Lt(e, t, n = yr) {
346
350
  const o = e.createBuffer(1, i.length, n);
347
351
  return o.copyToChannel(i, 0), o;
348
352
  }
349
- function Sr(e) {
350
- const t = kr(e), n = window.atob(t), r = new Uint8Array(n.length);
353
+ function Er(e) {
354
+ const t = vr(e), n = window.atob(t), r = new Uint8Array(n.length);
351
355
  for (let s = 0; s < n.length; s++)
352
356
  r[s] = n.charCodeAt(s);
353
357
  return r;
354
358
  }
355
- async function Er(e, t) {
356
- const n = Sr(t);
357
- if (vr(n)) {
358
- const r = n.buffer.slice(
359
- n.byteOffset,
360
- n.byteOffset + n.byteLength
359
+ async function br(e, t, n = Tt) {
360
+ const r = Er(t), s = cn(n);
361
+ if (Sr(r)) {
362
+ const i = r.buffer.slice(
363
+ r.byteOffset,
364
+ r.byteOffset + r.byteLength
361
365
  );
362
- return e.decodeAudioData(r);
366
+ return e.decodeAudioData(i);
363
367
  }
364
- if (n.length >= 2 && n.length % 2 === 0)
365
- return Lt(e, n);
368
+ if (r.length >= 2 && r.length % 2 === 0)
369
+ return Nt(e, r, s);
366
370
  try {
367
- const r = n.buffer.slice(
368
- n.byteOffset,
369
- n.byteOffset + n.byteLength
371
+ const i = r.buffer.slice(
372
+ r.byteOffset,
373
+ r.byteOffset + r.byteLength
370
374
  );
371
- return await e.decodeAudioData(r);
375
+ return await e.decodeAudioData(i);
372
376
  } catch {
373
- return Lt(e, n);
377
+ return Nt(e, r, s);
374
378
  }
375
379
  }
376
- function Ut(e) {
380
+ function Vt(e) {
377
381
  let t = 0;
378
382
  for (const n of e)
379
383
  t = Math.max(t, n.vtime + n.vduration);
380
384
  return t;
381
385
  }
382
- function br(e, t) {
386
+ function Tr(e, t) {
383
387
  for (const n of e)
384
388
  if (t >= n.wtime && t < n.wtime + n.wduration)
385
389
  return n;
386
390
  return null;
387
391
  }
388
- function on(e, t) {
392
+ function un(e, t) {
389
393
  const n = [], r = [];
390
394
  let s = null, i = !1, o = !1, c = !1, l = !1, f = 0, w = 0, y = 0, m = 0, S = null, v = 1, u = t, _ = !1;
391
395
  const d = () => {
@@ -405,127 +409,133 @@ function on(e, t) {
405
409
  }, E = () => {
406
410
  for (const k of r)
407
411
  k.playbackRate.value = v;
408
- }, N = () => {
412
+ }, V = () => {
409
413
  _ || !l || i || r.length > 0 || n.length > 0 || (o = !1, d(), e.onSpeakingDone(), e.onNotify());
410
414
  }, j = (k) => {
411
- const x = Ut(k);
412
- if (x <= 0) {
415
+ const C = Vt(k);
416
+ if (C <= 0) {
413
417
  e.onSpeakingDone(), e.onNotify();
414
418
  return;
415
419
  }
416
420
  o = !0, f = performance.now(), e.onSpeakingStart(), e.onNotify(), d();
417
- const T = v > 0 ? x / v : x;
421
+ const b = v > 0 ? C / v : C;
418
422
  S = setTimeout(() => {
419
423
  _ || (o = !1, S = null, e.onSpeakingDone(), e.onNotify());
420
- }, T);
421
- }, M = (k, x, T, b) => {
422
- x.length !== 0 && (b && (y = T), x.forEach((A) => {
423
- const B = String(A.word ?? "").trim();
424
- if (!B) return;
425
- const z = Math.round((A.start ?? 0) * 1e3), Y = A.duration != null ? Math.round(A.duration * 1e3) : A.end != null ? Math.max(1, Math.round((A.end - (A.start ?? 0)) * 1e3)) : 0;
424
+ }, b);
425
+ }, M = (k, C, b, T) => {
426
+ C.length !== 0 && (T && (y = b), C.forEach((A) => {
427
+ const F = String(A.word ?? "").trim();
428
+ if (!F) return;
429
+ const J = Math.round((A.start ?? 0) * 1e3), Z = A.duration != null ? Math.round(A.duration * 1e3) : A.end != null ? Math.max(1, Math.round((A.end - (A.start ?? 0)) * 1e3)) : 0;
426
430
  k.push({
427
- word: B,
428
- wtime: y + z,
429
- wduration: Y,
431
+ word: F,
432
+ wtime: y + J,
433
+ wduration: Z,
430
434
  queueIndex: k.length,
431
435
  gesture: A.gesture ?? null,
432
436
  emphasis: A.emphasis === !0
433
437
  });
434
438
  }));
435
- }, V = (k, x, T, b, A, F) => {
436
- T.length !== 0 && (A && (y = b), T.forEach((B) => {
437
- const z = String(B.symbol ?? B.viseme ?? "").trim();
438
- if (!z) return;
439
- const Y = Math.round((B.start ?? 0) * 1e3), H = Math.max(1, Math.round((B.duration ?? 0) * 1e3)), X = y + Y;
440
- let Z;
441
- if ($n(F) === "oculus_direct")
442
- Z = lr(z);
439
+ }, $ = (k, C, b, T, A, L) => {
440
+ b.length !== 0 && (A && (y = T), b.forEach((F) => {
441
+ const J = String(F.symbol ?? F.viseme ?? "").trim();
442
+ if (!J) return;
443
+ const Z = Math.round((F.start ?? 0) * 1e3), B = Math.max(1, Math.round((F.duration ?? 0) * 1e3)), G = y + Z;
444
+ let ce;
445
+ if (Hn(L) === "oculus_direct")
446
+ ce = dr(J);
443
447
  else {
444
- const ge = br(x, X), te = ge ? mr(ge, X) : 0;
445
- Z = pr(
446
- z,
447
- ge?.word ?? "",
448
+ const le = Tr(C, G), te = le ? wr(le, G) : 0;
449
+ ce = kr(
450
+ J,
451
+ le?.word ?? "",
448
452
  te
449
453
  );
450
454
  }
451
455
  k.push({
452
- viseme: Z,
456
+ viseme: ce,
453
457
  weight: 1,
454
- vtime: X,
455
- vduration: H
458
+ vtime: G,
459
+ vduration: B
456
460
  });
457
461
  }), e.onNotify());
458
- }, U = (k, x, T, b, A, F, B) => {
459
- M(x, b, A, F), V(
462
+ }, N = (k, C, b, T, A, L, F) => {
463
+ M(C, T, A, L), $(
460
464
  k,
461
- x,
462
- T,
465
+ C,
466
+ b,
463
467
  A,
464
- F,
465
- B
468
+ L,
469
+ F
466
470
  );
467
- }, g = async (k, x, T, b, A, F, B) => {
468
- if (!(_ || !T?.trim())) {
469
- if (i) {
470
- n.push({
471
- audio: T,
472
- visemes: b,
473
- words: A,
474
- isNewSegment: F
475
- });
471
+ }, g = async (k, C, b, T, A, L, F) => {
472
+ if (_ || !b?.trim())
473
+ return;
474
+ const J = cn(F?.sampleRate), Z = F?.onFirstChunk;
475
+ if (i) {
476
+ n.push({
477
+ audio: b,
478
+ visemes: T,
479
+ words: A,
480
+ isNewSegment: L,
481
+ sampleRate: J
482
+ });
483
+ return;
484
+ }
485
+ i = !0;
486
+ try {
487
+ const B = window.AudioContext || window.webkitAudioContext;
488
+ s || (s = new B());
489
+ const G = s;
490
+ G.state === "suspended" && await G.resume();
491
+ const ce = await br(
492
+ G,
493
+ b,
494
+ J
495
+ );
496
+ c = !0;
497
+ const le = G.currentTime;
498
+ let te = m;
499
+ const ye = !o;
500
+ te < le && (te = le + 0.1), m = te + ce.duration;
501
+ const ee = G.createBufferSource();
502
+ if (ee.buffer = ce, ee.playbackRate.value = v, ee.connect(G.destination), r.push(ee), _) {
503
+ r.pop();
476
504
  return;
477
505
  }
478
- i = !0;
479
- try {
480
- const z = window.AudioContext || window.webkitAudioContext;
481
- s || (s = new z());
482
- const Y = s;
483
- Y.state === "suspended" && await Y.resume();
484
- const H = await Er(Y, T);
485
- c = !0;
486
- const X = Y.currentTime;
487
- let Z = m;
488
- const ge = !o;
489
- Z < X && (Z = X + 0.1), m = Z + H.duration;
490
- const te = Y.createBufferSource();
491
- if (te.buffer = H, te.playbackRate.value = v, te.connect(Y.destination), r.push(te), _) {
492
- r.pop();
493
- return;
494
- }
495
- if (ge) {
496
- o = !0, e.onSpeakingStart(), w = Z, y = 0, k.length = 0, x.length = 0, B?.();
497
- const oe = (Z - X) * 1e3;
498
- f = performance.now() + oe;
499
- }
500
- te.onended = () => {
501
- const oe = r.indexOf(te);
502
- oe >= 0 && r.splice(oe, 1), N(), e.onNotify();
503
- }, te.start(Z);
504
- const ye = (Z - w) * 1e3;
505
- U(
506
- k,
507
- x,
508
- b,
509
- A,
510
- ye,
511
- F,
512
- u
513
- );
514
- } catch (z) {
515
- console.error("[avatarChunkPlayback] audio chunk failed:", z);
516
- } finally {
517
- if (i = !1, _) return;
518
- const z = n.shift();
519
- z ? await g(
520
- k,
521
- x,
522
- z.audio,
523
- z.visemes,
524
- z.words,
525
- z.isNewSegment,
526
- B
527
- ) : N();
506
+ if (ye) {
507
+ o = !0, e.onSpeakingStart(), w = te, y = 0, k.length = 0, C.length = 0, Z?.();
508
+ const ke = (te - le) * 1e3;
509
+ f = performance.now() + ke;
528
510
  }
511
+ ee.onended = () => {
512
+ const ke = r.indexOf(ee);
513
+ ke >= 0 && r.splice(ke, 1), V(), e.onNotify();
514
+ }, ee.start(te);
515
+ const De = (te - w) * 1e3;
516
+ N(
517
+ k,
518
+ C,
519
+ T,
520
+ A,
521
+ De,
522
+ L,
523
+ u
524
+ );
525
+ } catch (B) {
526
+ console.error("[avatarChunkPlayback] audio chunk failed:", B);
527
+ } finally {
528
+ if (i = !1, _) return;
529
+ const B = n.shift();
530
+ B ? await g(
531
+ k,
532
+ C,
533
+ B.audio,
534
+ B.visemes,
535
+ B.words,
536
+ B.isNewSegment,
537
+ { sampleRate: B.sampleRate, onFirstChunk: Z }
538
+ ) : V();
529
539
  }
530
540
  };
531
541
  return {
@@ -552,18 +562,18 @@ function on(e, t) {
552
562
  j(k);
553
563
  return;
554
564
  }
555
- N();
565
+ V();
556
566
  },
557
567
  playAudioChunk: g,
558
- queueTimingsOnly: (k, x, T, b, A) => {
568
+ queueTimingsOnly: (k, C, b, T, A) => {
559
569
  if (_) return;
560
- let F = y;
561
- A && k.length > 0 && (F = Ut(k)), U(
570
+ let L = y;
571
+ A && k.length > 0 && (L = Vt(k)), N(
562
572
  k,
563
- x,
564
- T,
573
+ C,
565
574
  b,
566
- F,
575
+ T,
576
+ L,
567
577
  A,
568
578
  u
569
579
  );
@@ -583,14 +593,14 @@ function on(e, t) {
583
593
  }
584
594
  };
585
595
  }
586
- function rt(e, t) {
596
+ function st(e, t) {
587
597
  let n = null;
588
598
  for (const r of e)
589
599
  t < r.vtime || t >= r.vtime + r.vduration || (!n || r.vtime >= n.vtime) && (n = r);
590
600
  return n ? n.viseme : "sil";
591
601
  }
592
- function Tr(e, t, n = 120) {
593
- const r = rt(e, t);
602
+ function Ar(e, t, n = 120) {
603
+ const r = st(e, t);
594
604
  if (r !== "sil") return r;
595
605
  let s = null;
596
606
  for (const i of e) {
@@ -600,23 +610,23 @@ function Tr(e, t, n = 120) {
600
610
  }
601
611
  return s?.viseme ?? "sil";
602
612
  }
603
- function Zs(e, t) {
613
+ function ei(e, t) {
604
614
  for (const n of e)
605
615
  if (t >= n.wtime && t < n.wtime + n.wduration)
606
616
  return n;
607
617
  return null;
608
618
  }
609
- const bt = 0.5, Tt = 1.5, an = "Olivia", cn = "f786b574-daa5-4673-aa0c-cbe3e8534c02", st = 0.85;
610
- function Nt(e, t = Te) {
619
+ const At = 0.5, It = 1.5, ln = "Olivia", fn = "f786b574-daa5-4673-aa0c-cbe3e8534c02", it = 0.85;
620
+ function $t(e, t = Ae) {
611
621
  const n = `${t.replace(/\/$/, "")}/avatar_ttsWithPoses`, r = [], s = [], i = [];
612
- let o = "neutral", c = "", l = Be;
613
- const f = /* @__PURE__ */ new Set(), w = () => f.forEach((v) => v()), y = on(
622
+ let o = "neutral", c = "", l = Oe;
623
+ const f = /* @__PURE__ */ new Set(), w = () => f.forEach((v) => v()), y = un(
614
624
  {
615
625
  onSpeakingStart: () => e("speaking"),
616
626
  onSpeakingDone: () => e("done"),
617
627
  onNotify: w
618
628
  },
619
- Be
629
+ Oe
620
630
  ), m = () => {
621
631
  y.stop(), r.length = 0, s.length = 0, i.length = 0, o = "neutral", e("idle"), w();
622
632
  };
@@ -633,18 +643,18 @@ function Nt(e, t = Te) {
633
643
  const _ = c.trim();
634
644
  if (!_)
635
645
  throw new Error("Developer token required for avatar_ttsWithPoses");
636
- const d = u?.ttsEngineId ?? l ?? Be;
646
+ const d = u?.ttsEngineId ?? l ?? Oe;
637
647
  y.resetForNewStream(d), y.setStreamTtsEngineId(d);
638
- const R = u?.voiceId ?? an, E = u?.speakingRate ?? st, N = Math.max(
639
- bt,
640
- Math.min(Tt, E)
648
+ const R = u?.voiceId ?? ln, E = u?.speakingRate ?? it, V = Math.max(
649
+ At,
650
+ Math.min(It, E)
641
651
  ), j = {
642
652
  user_query: v,
643
653
  ttsEngineId: d,
644
- speakingRate: N,
654
+ speakingRate: V,
645
655
  tenant: "aiTwin"
646
656
  };
647
- nn.has(d) && (j.voice_id = R);
657
+ sn.has(d) && (j.voice_id = R);
648
658
  try {
649
659
  const M = await fetch(n, {
650
660
  method: "POST",
@@ -656,64 +666,65 @@ function Nt(e, t = Te) {
656
666
  });
657
667
  if (!M.ok)
658
668
  throw new Error(`avatar_ttsWithPoses failed (${M.status})`);
659
- const V = M.body;
660
- if (!V) throw new Error("No response body");
661
- const U = V.getReader(), g = new TextDecoder();
669
+ const $ = M.body;
670
+ if (!$) throw new Error("No response body");
671
+ const N = $.getReader(), g = new TextDecoder();
662
672
  let I = "";
663
- const k = async (x) => {
664
- const T = sn(x);
665
- if (T) {
666
- if (T.event === "audio") {
667
- const b = T.data.chunk, A = T.data.visemes ?? [], F = T.data.words ?? [], B = T.data.is_new_segment ?? !1;
668
- b ? await y.playAudioChunk(
673
+ const k = async (C) => {
674
+ const b = an(C);
675
+ if (b) {
676
+ if (b.event === "audio") {
677
+ const T = b.data.chunk, A = b.data.visemes ?? [], L = b.data.words ?? [], F = b.data.is_new_segment ?? !1, J = b.data.sample_rate;
678
+ T ? await y.playAudioChunk(
669
679
  r,
670
680
  s,
671
- b,
681
+ T,
672
682
  A,
683
+ L,
673
684
  F,
674
- B
675
- ) : (A.length > 0 || F.length > 0) && y.queueTimingsOnly(
685
+ { sampleRate: J }
686
+ ) : (A.length > 0 || L.length > 0) && y.queueTimingsOnly(
676
687
  r,
677
688
  s,
678
689
  A,
679
- F,
680
- B
690
+ L,
691
+ F
681
692
  );
682
- } else if (T.event === "metadata") {
683
- const b = T.data.mood;
684
- typeof b == "string" && b.trim() && (o = b.trim());
685
- const A = T.data.sentence_emotions;
693
+ } else if (b.event === "metadata") {
694
+ const T = b.data.mood;
695
+ typeof T == "string" && T.trim() && (o = T.trim());
696
+ const A = b.data.sentence_emotions;
686
697
  if (Array.isArray(A)) {
687
698
  i.length = 0;
688
- for (const F of A) {
689
- if (!F || typeof F != "object") continue;
690
- const B = F;
699
+ for (const L of A) {
700
+ if (!L || typeof L != "object") continue;
701
+ const F = L;
691
702
  i.push({
692
- sentence_index: Number(B.sentence_index ?? 0),
693
- text: String(B.text ?? ""),
694
- sentiment: typeof B.sentiment == "string" ? B.sentiment : void 0,
695
- emotion: String(B.emotion ?? o),
696
- start_word: Number(B.start_word ?? 0),
697
- end_word: Number(B.end_word ?? 0)
703
+ sentence_index: Number(F.sentence_index ?? 0),
704
+ text: String(F.text ?? ""),
705
+ sentiment: typeof F.sentiment == "string" ? F.sentiment : void 0,
706
+ emotion: String(F.emotion ?? o),
707
+ start_word: Number(F.start_word ?? 0),
708
+ end_word: Number(F.end_word ?? 0)
698
709
  });
699
710
  }
700
711
  }
701
712
  w();
702
- } else if (T.event === "error")
713
+ } else if (b.event === "error")
703
714
  throw new Error(
704
- String(T.data.message ?? "avatar_ttsWithPoses stream error")
715
+ String(b.data.message ?? "avatar_ttsWithPoses stream error")
705
716
  );
706
717
  }
707
718
  };
708
719
  for (; ; ) {
709
- const { done: x, value: T } = await U.read();
710
- T && (I += g.decode(T, { stream: !0 }));
711
- const b = I.split(`
720
+ const { done: C, value: b } = await N.read();
721
+ b && (I += g.decode(b, { stream: !0 }));
722
+ const T = I.split(`
712
723
 
713
724
  `);
714
- I = b.pop() ?? "";
715
- for (const A of b) await k(A);
716
- if (x) {
725
+ I = T.pop() ?? "";
726
+ for (const A of T) await k(A);
727
+ if (C) {
717
728
  I.trim() && await k(I.trim()), y.markStreamComplete(r);
718
729
  break;
719
730
  }
@@ -736,8 +747,8 @@ function Nt(e, t = Te) {
736
747
  subscribe: (v) => (f.add(v), () => f.delete(v))
737
748
  };
738
749
  }
739
- const un = 16e3, ln = 24e3;
740
- class Ar extends Pn {
750
+ const dn = 16e3, mn = 16e3;
751
+ class Ir extends Fn {
741
752
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
742
753
  async deserialize(t) {
743
754
  try {
@@ -749,7 +760,7 @@ class Ar extends Pn {
749
760
  }
750
761
  }
751
762
  }
752
- class Ir extends Mn {
763
+ class Rr extends Bn {
753
764
  constructor() {
754
765
  super(
755
766
  !0,
@@ -757,42 +768,42 @@ class Ir extends Mn {
757
768
  void 0,
758
769
  void 0,
759
770
  512,
760
- un,
761
- ln
771
+ dn,
772
+ mn
762
773
  );
763
774
  }
764
775
  /** Pipecat protobuf bot audio is unused — playback comes from avatar_audio_chunk. */
765
776
  bufferBotAudio(t, n) {
766
777
  }
767
778
  }
768
- const Rr = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
769
- function Dr(e) {
770
- return Rr.test(e.trim());
779
+ const Dr = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
780
+ function Cr(e) {
781
+ return Dr.test(e.trim());
771
782
  }
772
783
  function xr(e) {
773
784
  const t = e.replace(/\/$/, "");
774
785
  return t.startsWith("https://") ? `wss://${t.slice(8)}` : t.startsWith("http://") ? `ws://${t.slice(7)}` : t;
775
786
  }
776
- function Cr(e) {
787
+ function Mr(e) {
777
788
  if (e.wsUrl?.trim()) return e.wsUrl.trim();
778
789
  const t = e.authToken?.trim();
779
790
  if (!t)
780
791
  throw new Error(
781
792
  "Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
782
793
  );
783
- const n = e.apiBase ?? Te, r = new URL(`${xr(n)}/ws/voice`);
794
+ const n = e.apiBase ?? Ae, r = new URL(`${xr(n)}/ws/voice`);
784
795
  r.searchParams.set("authToken", t), r.searchParams.set("tenant", "aiTwin");
785
796
  const s = e.voiceId?.trim();
786
- s && Dr(s) && r.searchParams.set("voiceId", s);
797
+ s && Cr(s) && r.searchParams.set("voiceId", s);
787
798
  const i = e.personaId?.trim();
788
799
  i && r.searchParams.set("personaId", i);
789
- const o = e.speakingRate ?? st;
800
+ const o = e.speakingRate ?? it;
790
801
  return r.searchParams.set(
791
802
  "speaking_rate",
792
- String(Math.max(bt, Math.min(Tt, o)))
803
+ String(Math.max(At, Math.min(It, o)))
793
804
  ), e.ttsStream === !1 ? r.searchParams.set("tts_stream", "false") : r.searchParams.set("tts_stream", "true"), r.toString();
794
805
  }
795
- function dt(e, t) {
806
+ function mt(e, t) {
796
807
  if (!Array.isArray(e)) return [];
797
808
  const n = [];
798
809
  for (const r of e)
@@ -806,7 +817,7 @@ function dt(e, t) {
806
817
  });
807
818
  return n;
808
819
  }
809
- function Mr(e) {
820
+ function Pr(e) {
810
821
  if (!e || typeof e != "object") return null;
811
822
  const t = e, r = (t.data && typeof t.data == "object" && !Array.isArray(t.data) ? t.data : null) || t;
812
823
  return {
@@ -814,24 +825,24 @@ function Mr(e) {
814
825
  type: String(r.type ?? t.type ?? "server-message")
815
826
  };
816
827
  }
817
- function mt(e) {
828
+ function ht(e) {
818
829
  return e.is_new_segment === !0 || Number(e.audio_offset_ms ?? -1) === 0 ? !0 : Number(e.chunk_index ?? -1) === 0;
819
830
  }
820
- function Pr(e) {
831
+ function Br(e) {
821
832
  return e?.transport?._mediaManager?._wavStreamPlayer ?? null;
822
833
  }
823
- function Br(e, t = {}) {
834
+ function Fr(e, t = {}) {
824
835
  const n = [], r = [], s = [], i = [];
825
- let o = "", c = "neutral", l = Oe, f = !1, w = null, y = null, m = { ...t }, S = 0, v = null;
836
+ let o = "", c = "neutral", l = Le, f = !1, w = null, y = null, m = { ...t }, S = 0, v = null;
826
837
  const u = /* @__PURE__ */ new Set(), _ = [];
827
- let d = !1, R = null, E = !0, N = "default";
838
+ let d = !1, R = null, E = !0, V = "default";
828
839
  const j = /* @__PURE__ */ new Set();
829
- let M = null, V = 0;
830
- const U = () => u.forEach((a) => a()), g = on(
840
+ let M = null, $ = 0;
841
+ const N = () => u.forEach((a) => a()), g = un(
831
842
  {
832
843
  onSpeakingStart: () => e("speaking"),
833
844
  onSpeakingDone: () => e("done"),
834
- onNotify: U
845
+ onNotify: N
835
846
  },
836
847
  l
837
848
  ), I = () => {
@@ -839,38 +850,38 @@ function Br(e, t = {}) {
839
850
  const a = new MessageChannel();
840
851
  return a.port1.onmessage = () => {
841
852
  const p = _.shift();
842
- p !== void 0 && ot(p), _.length > 0 ? a.port2.postMessage(null) : d = !1;
853
+ p !== void 0 && ke(p), _.length > 0 ? a.port2.postMessage(null) : d = !1;
843
854
  }, R = a, a;
844
855
  }, k = (a) => {
845
856
  _.push(a), !d && (d = !0, I().port2.postMessage(null));
846
- }, x = () => g.getPlaybackElapsedMs(), T = (a, p = o) => {
857
+ }, C = () => g.getPlaybackElapsedMs(), b = (a, p = o) => {
847
858
  if (!m.onLipsyncDebug) return;
848
- const C = x(), G = n;
859
+ const x = C(), z = n;
849
860
  m.onLipsyncDebug({
850
861
  event: a,
851
862
  spokenText: p,
852
863
  mood: c,
853
864
  playbackAnchorPerf: g.getPlaybackStartPerf(),
854
- playbackElapsedMs: C,
855
- queueLength: G.length,
856
- activeViseme: rt(G, C),
857
- segments: i.map((W) => ({
858
- ...W,
859
- visemes: [...W.visemes]
865
+ playbackElapsedMs: x,
866
+ queueLength: z.length,
867
+ activeViseme: st(z, x),
868
+ segments: i.map((H) => ({
869
+ ...H,
870
+ visemes: [...H.visemes]
860
871
  }))
861
872
  });
862
- }, b = (a, p) => {
873
+ }, T = (a, p) => {
863
874
  m.onLipsyncDebug && (v = { event: a, spokenText: p }, S === 0 && (S = requestAnimationFrame(() => {
864
875
  S = 0;
865
- const C = v;
866
- v = null, C && T(C.event, C.spokenText);
876
+ const x = v;
877
+ v = null, x && b(x.event, x.spokenText);
867
878
  })));
868
879
  }, A = () => {
869
880
  E = !0, j.clear();
870
- }, F = () => {
871
- const a = Pr(w);
881
+ }, L = () => {
882
+ const a = Br(w);
872
883
  if (a) {
873
- N = `bot-${Date.now()}`, a.interruptedTrackIds = { [N]: !0 };
884
+ V = `bot-${Date.now()}`, a.interruptedTrackIds = { [V]: !0 };
874
885
  try {
875
886
  a.interrupt?.();
876
887
  } catch {
@@ -881,44 +892,44 @@ function Br(e, t = {}) {
881
892
  p?.interrupt?.();
882
893
  } catch {
883
894
  }
884
- }, B = (a) => {
895
+ }, F = (a) => {
885
896
  const p = a.context_id?.trim();
886
- return p && j.has(p) ? !0 : E ? !1 : !(a.type === "avatar_metadata" || mt(a));
887
- }, z = (a) => {
897
+ return p && j.has(p) ? !0 : E ? !1 : !(a.type === "avatar_metadata" || ht(a));
898
+ }, J = (a) => {
888
899
  E = !1;
889
900
  const p = a.context_id?.trim();
890
- p && j.add(p), _.length = 0, d = !1, M?.abort(), M = null, V += 1, F(), g.bargeIn(), Y(), e("idle"), b("interrupt"), U();
891
- }, Y = () => {
901
+ p && j.add(p), _.length = 0, d = !1, M?.abort(), M = null, $ += 1, L(), g.bargeIn(), Z(), e("idle"), T("interrupt"), N();
902
+ }, Z = () => {
892
903
  n.length = 0, r.length = 0, i.length = 0, o = "", c = "neutral", s.length = 0;
893
- }, H = () => {
894
- g.stop(), Y(), b("reset"), U();
895
- }, X = () => {
896
- H(), e("idle"), U();
897
- }, Z = (a, p) => {
904
+ }, B = () => {
905
+ g.stop(), Z(), T("reset"), N();
906
+ }, G = () => {
907
+ B(), e("idle"), N();
908
+ }, ce = (a, p) => {
898
909
  typeof a.mood == "string" && a.mood.trim() && (c = a.mood.trim()), Array.isArray(a.sentence_emotions) && a.sentence_emotions.length > 0 && (p && (s.length = 0), s.push(
899
- ...dt(a.sentence_emotions, c)
910
+ ...mt(a.sentence_emotions, c)
900
911
  ));
901
- }, ge = (a) => {
902
- if (B({ ...a, type: "avatar_metadata" }))
912
+ }, le = (a) => {
913
+ if (F({ ...a, type: "avatar_metadata" }))
903
914
  return;
904
915
  A();
905
916
  const p = String(a.spoken_text ?? a.text ?? "").trim();
906
917
  p && (o = p), g.resetForNewStream(l), typeof a.mood == "string" && a.mood.trim() && (c = a.mood.trim()), s.length = 0, s.push(
907
- ...dt(a.sentence_emotions, c)
908
- ), Array.isArray(a.gestures) && a.gestures, b("metadata", p), U();
909
- }, te = (a, p, C, G) => {
918
+ ...mt(a.sentence_emotions, c)
919
+ ), Array.isArray(a.gestures) && a.gestures, T("metadata", p), N();
920
+ }, te = (a, p, x, z) => {
910
921
  if (!m.onLipsyncDebug) return;
911
- const W = n.slice(C), Ee = G.filter(
922
+ const H = n.slice(x), be = z.filter(
912
923
  (re) => String(re.symbol ?? re.viseme ?? "").trim()
913
924
  );
914
925
  i.push({
915
926
  spokenText: p,
916
- audioOffsetMs: W[0]?.vtime ?? 0,
927
+ audioOffsetMs: H[0]?.vtime ?? 0,
917
928
  isNewSegment: !!a.is_new_segment,
918
929
  chunkDurationMs: a.chunk_duration_ms != null ? Number(a.chunk_duration_ms) : null,
919
930
  receivedAtMs: performance.now(),
920
- visemes: W.map((re, Re) => {
921
- const _e = Ee[Re];
931
+ visemes: H.map((re, Ce) => {
932
+ const _e = be[Ce];
922
933
  return {
923
934
  rawSymbol: String(_e?.symbol ?? _e?.viseme ?? re.viseme).trim(),
924
935
  viseme: re.viseme,
@@ -930,32 +941,35 @@ function Br(e, t = {}) {
930
941
  })
931
942
  });
932
943
  }, ye = (a) => {
933
- if (B(a)) return;
934
- mt(a) && A();
935
- const p = String(a.spoken_text ?? a.text ?? "").trim(), C = mt(a), G = a.visemes ?? [], W = a.words ?? [], Ee = String(a.chunk ?? "").trim();
936
- p && (o = p), Z(a, C), C && g.resetForNewStream(l);
944
+ if (F(a)) return;
945
+ ht(a) && A();
946
+ const p = String(a.spoken_text ?? a.text ?? "").trim(), x = ht(a), z = a.visemes ?? [], H = a.words ?? [], be = String(a.chunk ?? "").trim();
947
+ p && (o = p), ce(a, x), x && g.resetForNewStream(l);
937
948
  const re = n.length;
938
949
  g.playAudioChunk(
939
950
  n,
940
951
  r,
941
- Ee,
942
- G,
943
- W,
944
- C,
945
- () => {
946
- i.length = 0;
952
+ be,
953
+ z,
954
+ H,
955
+ x,
956
+ {
957
+ sampleRate: a.sample_rate,
958
+ onFirstChunk: () => {
959
+ i.length = 0;
960
+ }
947
961
  }
948
962
  ).then(() => {
949
- te(a, p, re, G), b("audio_chunk", p);
963
+ te(a, p, re, z), T("audio_chunk", p);
950
964
  });
951
- }, oe = (a) => {
952
- if (B(a)) return;
965
+ }, ee = (a) => {
966
+ if (F(a)) return;
953
967
  (a.is_new_segment || Number(a.audio_offset_ms ?? -1) === 0) && A(), console.warn(
954
968
  "[realtimeVoice] avatar_lipsync is deprecated — expect avatar_audio_chunk"
955
969
  );
956
970
  const p = String(a.spoken_text ?? a.text ?? "").trim();
957
- p && (o = p), Z(a, !!a.is_new_segment);
958
- const C = n.length;
971
+ p && (o = p), ce(a, !!a.is_new_segment);
972
+ const x = n.length;
959
973
  g.queueTimingsOnly(
960
974
  n,
961
975
  r,
@@ -965,164 +979,165 @@ function Br(e, t = {}) {
965
979
  ), te(
966
980
  a,
967
981
  p,
968
- C,
982
+ x,
969
983
  a.visemes ?? []
970
- ), b("lipsync", p), U();
971
- }, Ke = async (a) => {
984
+ ), T("lipsync", p), N();
985
+ }, De = async (a) => {
972
986
  const p = String(a.text ?? "").trim();
973
987
  if (!p) return;
974
- const C = m.authToken?.trim();
975
- if (!C) {
988
+ const x = m.authToken?.trim();
989
+ if (!x) {
976
990
  console.error("[realtimeVoice] avatar_speak requires authToken");
977
991
  return;
978
992
  }
979
993
  M?.abort();
980
- const G = new AbortController();
981
- M = G;
982
- const W = ++V;
994
+ const z = new AbortController();
995
+ M = z;
996
+ const H = ++$;
983
997
  A(), g.resetForNewStream(l), o = p;
984
- const re = `${(m.apiBase ?? Te).replace(/\/$/, "")}/avatar_ttsWithPoses`, Re = m.voiceId?.trim() || cn, _e = m.speakingRate ?? st, je = Math.max(
985
- bt,
986
- Math.min(Tt, _e)
987
- ), le = {
998
+ const re = `${(m.apiBase ?? Ae).replace(/\/$/, "")}/avatar_ttsWithPoses`, Ce = m.voiceId?.trim() || fn, _e = m.speakingRate ?? it, ze = Math.max(
999
+ At,
1000
+ Math.min(It, _e)
1001
+ ), fe = {
988
1002
  user_query: p,
989
1003
  ttsEngineId: l,
990
- speakingRate: je,
1004
+ speakingRate: ze,
991
1005
  tenant: "aiTwin"
992
1006
  };
993
- nn.has(l) && (le.voice_id = Re);
1007
+ sn.has(l) && (fe.voice_id = Ce);
994
1008
  try {
995
- const fe = await fetch(re, {
1009
+ const de = await fetch(re, {
996
1010
  method: "POST",
997
1011
  headers: {
998
1012
  "Content-Type": "application/json",
999
- Authorization: `Bearer ${C}`
1013
+ Authorization: `Bearer ${x}`
1000
1014
  },
1001
- body: JSON.stringify(le),
1002
- signal: G.signal
1015
+ body: JSON.stringify(fe),
1016
+ signal: z.signal
1003
1017
  });
1004
- if (!fe.ok)
1005
- throw new Error(`avatar_ttsWithPoses failed (${fe.status})`);
1006
- const q = fe.body;
1018
+ if (!de.ok)
1019
+ throw new Error(`avatar_ttsWithPoses failed (${de.status})`);
1020
+ const q = de.body;
1007
1021
  if (!q) throw new Error("No response body");
1008
- const Q = q.getReader(), ze = new TextDecoder();
1009
- let ee = "";
1010
- const ue = async (De) => {
1011
- if (W !== V || G.signal.aborted || !E)
1022
+ const Q = q.getReader(), Ge = new TextDecoder();
1023
+ let X = "";
1024
+ const ue = async (xe) => {
1025
+ if (H !== $ || z.signal.aborted || !E)
1012
1026
  return;
1013
- const J = sn(De);
1014
- if (J) {
1015
- if (J.event === "audio") {
1016
- const ce = J.data.chunk, se = J.data.visemes ?? [], xe = J.data.words ?? [], he = J.data.is_new_segment ?? !1;
1017
- ce ? await g.playAudioChunk(
1027
+ const Y = an(xe);
1028
+ if (Y) {
1029
+ if (Y.event === "audio") {
1030
+ const ae = Y.data.chunk, se = Y.data.visemes ?? [], Me = Y.data.words ?? [], we = Y.data.is_new_segment ?? !1, ct = Y.data.sample_rate;
1031
+ ae ? await g.playAudioChunk(
1018
1032
  n,
1019
1033
  r,
1020
- ce,
1034
+ ae,
1021
1035
  se,
1022
- xe,
1023
- he
1024
- ) : (se.length > 0 || xe.length > 0) && g.queueTimingsOnly(
1036
+ Me,
1037
+ we,
1038
+ { sampleRate: ct }
1039
+ ) : (se.length > 0 || Me.length > 0) && g.queueTimingsOnly(
1025
1040
  n,
1026
1041
  r,
1027
1042
  se,
1028
- xe,
1029
- he
1043
+ Me,
1044
+ we
1030
1045
  );
1031
- } else if (J.event === "metadata") {
1032
- const ce = J.data.mood;
1033
- typeof ce == "string" && ce.trim() && (c = ce.trim());
1034
- const se = J.data.sentence_emotions;
1046
+ } else if (Y.event === "metadata") {
1047
+ const ae = Y.data.mood;
1048
+ typeof ae == "string" && ae.trim() && (c = ae.trim());
1049
+ const se = Y.data.sentence_emotions;
1035
1050
  Array.isArray(se) && (s.length = 0, s.push(
1036
- ...dt(se, c)
1037
- )), U();
1038
- } else if (J.event === "error")
1051
+ ...mt(se, c)
1052
+ )), N();
1053
+ } else if (Y.event === "error")
1039
1054
  throw new Error(
1040
- String(J.data.message ?? "avatar_ttsWithPoses stream error")
1055
+ String(Y.data.message ?? "avatar_ttsWithPoses stream error")
1041
1056
  );
1042
1057
  }
1043
1058
  };
1044
- for (; !(W !== V || G.signal.aborted || !E); ) {
1045
- const { done: De, value: J } = await Q.read();
1046
- J && (ee += ze.decode(J, { stream: !0 }));
1047
- const ce = ee.split(`
1059
+ for (; !(H !== $ || z.signal.aborted || !E); ) {
1060
+ const { done: xe, value: Y } = await Q.read();
1061
+ Y && (X += Ge.decode(Y, { stream: !0 }));
1062
+ const ae = X.split(`
1048
1063
 
1049
1064
  `);
1050
- ee = ce.pop() ?? "";
1051
- for (const se of ce) await ue(se);
1052
- if (De) {
1053
- ee.trim() && await ue(ee.trim()), W === V && !G.signal.aborted && E && g.markStreamComplete(n);
1065
+ X = ae.pop() ?? "";
1066
+ for (const se of ae) await ue(se);
1067
+ if (xe) {
1068
+ X.trim() && await ue(X.trim()), H === $ && !z.signal.aborted && E && g.markStreamComplete(n);
1054
1069
  break;
1055
1070
  }
1056
1071
  }
1057
- } catch (fe) {
1058
- if (G.signal.aborted || !E) return;
1059
- console.error("[realtimeVoice] avatar_speak failed:", fe), e("error"), U();
1072
+ } catch (de) {
1073
+ if (z.signal.aborted || !E) return;
1074
+ console.error("[realtimeVoice] avatar_speak failed:", de), e("error"), N();
1060
1075
  } finally {
1061
- M === G && (M = null);
1076
+ M === z && (M = null);
1062
1077
  }
1063
- }, ot = (a) => {
1064
- const p = Mr(a);
1078
+ }, ke = (a) => {
1079
+ const p = Pr(a);
1065
1080
  if (!p) {
1066
1081
  console.warn("[realtimeVoice] server message with no payload", a);
1067
1082
  return;
1068
1083
  }
1069
- const C = String(p.type ?? "unknown");
1070
- switch (C !== "avatar_metadata" && C !== "avatar_audio_chunk" && C !== "avatar_lipsync" && C !== "avatar_interrupt" && C !== "error" && console.debug("[realtimeVoice] server message", C, p), C) {
1084
+ const x = String(p.type ?? "unknown");
1085
+ switch (x !== "avatar_metadata" && x !== "avatar_audio_chunk" && x !== "avatar_lipsync" && x !== "avatar_interrupt" && x !== "error" && console.debug("[realtimeVoice] server message", x, p), x) {
1071
1086
  case "avatar_metadata":
1072
- ge(p);
1087
+ le(p);
1073
1088
  break;
1074
1089
  case "avatar_audio_chunk":
1075
1090
  ye(p);
1076
1091
  break;
1077
1092
  case "avatar_lipsync":
1078
- oe(p);
1093
+ ee(p);
1079
1094
  break;
1080
1095
  case "avatar_interrupt":
1081
- z(p);
1096
+ J(p);
1082
1097
  break;
1083
1098
  case "error": {
1084
- const G = String(p.message ?? "Voice session error");
1085
- console.error("[realtimeVoice] server error:", G), e("error"), U();
1099
+ const z = String(p.message ?? "Voice session error");
1100
+ console.error("[realtimeVoice] server error:", z), e("error"), N();
1086
1101
  break;
1087
1102
  }
1088
1103
  case "avatar_speak":
1089
- Ke(p);
1104
+ De(p);
1090
1105
  break;
1091
1106
  }
1092
- }, Le = () => w || (y = new Ir(), w = new xn({
1093
- transport: new Cn({
1107
+ }, Ne = () => w || (y = new Rr(), w = new Mn({
1108
+ transport: new Pn({
1094
1109
  mediaManager: y,
1095
- serializer: new Ar(),
1096
- recorderSampleRate: un,
1097
- playerSampleRate: ln
1110
+ serializer: new Ir(),
1111
+ recorderSampleRate: dn,
1112
+ playerSampleRate: mn
1098
1113
  }),
1099
1114
  enableCam: !1,
1100
1115
  enableMic: !0,
1101
1116
  callbacks: {
1102
1117
  onBotReady: () => {
1103
- f = !0, e("idle"), U();
1118
+ f = !0, e("idle"), N();
1104
1119
  },
1105
1120
  onDisconnected: () => {
1106
- f = !1, X();
1121
+ f = !1, G();
1107
1122
  },
1108
1123
  onError: (a) => {
1109
1124
  const p = typeof a == "object" && a !== null && "data" in a ? String(a.data ?? a) : String(a);
1110
- console.error("[realtimeVoice]", p, a), e("error"), U();
1125
+ console.error("[realtimeVoice]", p, a), e("error"), N();
1111
1126
  },
1112
1127
  onTransportStateChanged: (a) => {
1113
- a === "error" && (e("error"), U());
1128
+ a === "error" && (e("error"), N());
1114
1129
  },
1115
1130
  onServerMessage: (a) => {
1116
1131
  k(a);
1117
1132
  },
1118
1133
  onUserStartedSpeaking: () => {
1119
- z({});
1134
+ J({});
1120
1135
  },
1121
1136
  onBotStartedSpeaking: () => {
1122
- b("bot_started");
1137
+ T("bot_started");
1123
1138
  },
1124
1139
  onBotStoppedSpeaking: () => {
1125
- E && (g.markStreamComplete(n), b("bot_stopped"));
1140
+ E && (g.markStreamComplete(n), T("bot_stopped"));
1126
1141
  },
1127
1142
  onUserTranscript: (a) => {
1128
1143
  m.onUserTranscript?.(a.text, !!a.final);
@@ -1140,17 +1155,17 @@ function Br(e, t = {}) {
1140
1155
  },
1141
1156
  getTtsEngineId: () => l,
1142
1157
  speak: async (a, p) => {
1143
- const C = a.trim();
1144
- if (C) {
1158
+ const x = a.trim();
1159
+ if (x) {
1145
1160
  if (!w || !f)
1146
1161
  throw new Error(
1147
1162
  "Realtime voice is not connected. Call connect() first."
1148
1163
  );
1149
- H(), await w.sendText(C);
1164
+ B(), await w.sendText(x);
1150
1165
  }
1151
1166
  },
1152
1167
  stop: () => {
1153
- M?.abort(), M = null, V += 1, A(), H(), e("idle"), U();
1168
+ M?.abort(), M = null, $ += 1, A(), B(), e("idle"), N();
1154
1169
  },
1155
1170
  connect: async (a) => {
1156
1171
  if (a && (m = { ...m, ...a }), !m.authToken?.trim())
@@ -1158,27 +1173,27 @@ function Br(e, t = {}) {
1158
1173
  "Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
1159
1174
  );
1160
1175
  e("loading");
1161
- const p = Le();
1176
+ const p = Ne();
1162
1177
  await p.initDevices();
1163
- const C = Cr(m);
1164
- console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", C);
1178
+ const x = Mr(m);
1179
+ console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", x);
1165
1180
  try {
1166
- await p.connect({ wsUrl: C });
1167
- } catch (G) {
1168
- f = !1, e("error"), U();
1169
- const W = G instanceof Error ? G.message : "Realtime voice connect failed (WebSocket 101 only means upgrade OK — check authToken/origin/RTVI handshake)";
1170
- throw new Error(`${W} — ${C}`);
1181
+ await p.connect({ wsUrl: x });
1182
+ } catch (z) {
1183
+ f = !1, e("error"), N();
1184
+ const H = z instanceof Error ? z.message : "Realtime voice connect failed (WebSocket 101 only means upgrade OK — check authToken/origin/RTVI handshake)";
1185
+ throw new Error(`${H} — ${x}`);
1171
1186
  }
1172
- f = !0, e("idle"), U();
1187
+ f = !0, e("idle"), N();
1173
1188
  },
1174
1189
  disconnect: async () => {
1175
- if (_.length = 0, d = !1, M?.abort(), M = null, V += 1, A(), w)
1190
+ if (_.length = 0, d = !1, M?.abort(), M = null, $ += 1, A(), w)
1176
1191
  try {
1177
1192
  await w.disconnect();
1178
1193
  } catch (a) {
1179
1194
  console.error("[realtimeVoice] disconnect failed:", a);
1180
1195
  }
1181
- f = !1, X();
1196
+ f = !1, G();
1182
1197
  },
1183
1198
  isConnected: () => f,
1184
1199
  unlockAudio: async () => {
@@ -1188,7 +1203,7 @@ function Br(e, t = {}) {
1188
1203
  getWordQueue: () => r,
1189
1204
  getSentenceEmotions: () => s,
1190
1205
  getStreamMood: () => c,
1191
- getPlaybackElapsedMs: x,
1206
+ getPlaybackElapsedMs: C,
1192
1207
  isSpeaking: () => g.isSpeaking(),
1193
1208
  setPlaybackSpeed: (a) => {
1194
1209
  g.setPlaybackSpeed(a);
@@ -1203,7 +1218,7 @@ function Or(e, t, n) {
1203
1218
  height: e.crop?.source_height ?? n
1204
1219
  };
1205
1220
  }
1206
- function Fr(e, t) {
1221
+ function Lr(e, t) {
1207
1222
  const n = e.crop;
1208
1223
  return {
1209
1224
  x: t?.source_x ?? n?.x ?? 0,
@@ -1212,21 +1227,21 @@ function Fr(e, t) {
1212
1227
  height: t?.source_h ?? n?.height ?? e.frame_height ?? 0
1213
1228
  };
1214
1229
  }
1215
- function Lr(e) {
1230
+ function Ur(e) {
1216
1231
  return e ? (e.w ?? 0) > 0 && (e.h ?? 0) > 0 : !1;
1217
1232
  }
1218
- async function it(e, t) {
1233
+ async function ot(e, t) {
1219
1234
  const n = await fetch(e);
1220
1235
  if (!n.ok) throw new Error(`Failed to load encrypted asset: ${e}`);
1221
1236
  const r = await n.arrayBuffer();
1222
- return Zn(r, t);
1237
+ return tr(r, t);
1223
1238
  }
1224
- async function Ur(e, t) {
1239
+ async function Nr(e, t) {
1225
1240
  if (!t) throw new Error("Missing asset key for encrypted JSON");
1226
- const n = await it(e, t), r = new TextDecoder().decode(n);
1241
+ const n = await ot(e, t), r = new TextDecoder().decode(n);
1227
1242
  return JSON.parse(r);
1228
1243
  }
1229
- async function Nr(e) {
1244
+ async function Vr(e) {
1230
1245
  const t = new Blob([e], { type: "image/webp" }), n = URL.createObjectURL(t);
1231
1246
  return new Promise((r, s) => {
1232
1247
  const i = new Image();
@@ -1237,7 +1252,7 @@ async function Nr(e) {
1237
1252
  }, i.src = n;
1238
1253
  });
1239
1254
  }
1240
- async function Vr(e) {
1255
+ async function $r(e) {
1241
1256
  const t = new Blob([e], { type: "image/png" }), n = URL.createObjectURL(t);
1242
1257
  return new Promise((r, s) => {
1243
1258
  const i = new Image();
@@ -1248,28 +1263,28 @@ async function Vr(e) {
1248
1263
  }, i.src = n;
1249
1264
  });
1250
1265
  }
1251
- function $r(e) {
1266
+ function Wr(e) {
1252
1267
  const t = new Blob([e], { type: "video/mp4" });
1253
1268
  return URL.createObjectURL(t);
1254
1269
  }
1255
- async function Wr(e) {
1256
- const t = sr();
1257
- if (!tt()) return t;
1270
+ async function Hr(e) {
1271
+ const t = or();
1272
+ if (!nt()) return t;
1258
1273
  if (!e) throw new Error("Missing asset key for encrypted idle video");
1259
- const n = await it(t, e);
1260
- return $r(n);
1274
+ const n = await ot(t, e);
1275
+ return Wr(n);
1261
1276
  }
1262
- function At(e, t) {
1277
+ function Rt(e, t) {
1263
1278
  return `${e}/${t}_minus_sil.png`;
1264
1279
  }
1265
- const fn = 5;
1266
- function dn(e) {
1280
+ const hn = 5;
1281
+ function wn(e) {
1267
1282
  const t = e?.composite_threshold;
1268
1283
  if (typeof t == "number" && t > 0) return t;
1269
1284
  const n = e?.crop?.content_threshold;
1270
- return typeof n == "number" && n > 0 ? n : fn;
1285
+ return typeof n == "number" && n > 0 ? n : hn;
1271
1286
  }
1272
- const ei = [
1287
+ const ti = [
1273
1288
  "aa",
1274
1289
  "E",
1275
1290
  "I",
@@ -1284,11 +1299,11 @@ const ei = [
1284
1299
  "RR",
1285
1300
  "kk",
1286
1301
  "nn"
1287
- ], pt = [
1302
+ ], yt = [
1288
1303
  "t01_0.25",
1289
1304
  "t02_0.50",
1290
1305
  "t03_0.75"
1291
- ], Hr = pt.length, Vt = /* @__PURE__ */ new Set([
1306
+ ], qr = yt.length, Wt = /* @__PURE__ */ new Set([
1292
1307
  "aa__kk",
1293
1308
  "aa__nn",
1294
1309
  "aa__sil",
@@ -1395,75 +1410,75 @@ const ei = [
1395
1410
  "U__nn",
1396
1411
  "U__sil"
1397
1412
  ]);
1398
- function $t(e, t) {
1413
+ function Ht(e, t) {
1399
1414
  return `${e}__${t}`;
1400
1415
  }
1401
- function Wt(e, t) {
1416
+ function qt(e, t) {
1402
1417
  return `pairs/${e}/${t}_minus_sil.png`;
1403
1418
  }
1404
- function Ze(e) {
1419
+ function et(e) {
1405
1420
  return `${e}_minus_sil.png`;
1406
1421
  }
1407
- function qr(e, t) {
1422
+ function Kr(e, t) {
1408
1423
  if (t.has(e)) return e;
1409
1424
  const n = /^pairs\/([^/]+)\//.exec(e);
1410
1425
  if (!n) return null;
1411
1426
  const r = n[1].split("__")[1];
1412
1427
  if (!r || r === "sil") return null;
1413
- const s = Ze(r);
1428
+ const s = et(r);
1414
1429
  return t.has(s) ? s : null;
1415
1430
  }
1416
- function mn(e, t) {
1431
+ function gn(e, t) {
1417
1432
  return e.filter((n) => t.has(n));
1418
1433
  }
1419
- function Kr(e, t, n) {
1420
- const r = It(e, t);
1421
- return mn(r, n).length > 0;
1434
+ function jr(e, t, n) {
1435
+ const r = Dt(e, t);
1436
+ return gn(r, n).length > 0;
1422
1437
  }
1423
- function It(e, t) {
1438
+ function Dt(e, t) {
1424
1439
  if (e === t) return [];
1425
- const n = [], r = $t(e, t);
1426
- if (Vt.has(r)) {
1427
- for (const i of pt)
1428
- n.push(Wt(r, i));
1440
+ const n = [], r = Ht(e, t);
1441
+ if (Wt.has(r)) {
1442
+ for (const i of yt)
1443
+ n.push(qt(r, i));
1429
1444
  return n;
1430
1445
  }
1431
- const s = $t(t, e);
1432
- if (Vt.has(s)) {
1433
- for (let i = Hr - 1; i >= 0; i--)
1434
- n.push(Wt(s, pt[i]));
1446
+ const s = Ht(t, e);
1447
+ if (Wt.has(s)) {
1448
+ for (let i = qr - 1; i >= 0; i--)
1449
+ n.push(qt(s, yt[i]));
1435
1450
  return n;
1436
1451
  }
1437
1452
  return [];
1438
1453
  }
1439
- function jr(e) {
1454
+ function zr(e) {
1440
1455
  return e < 16 ? [] : e < 35 ? [1] : e < 51 ? [0, 2] : [0, 1, 2];
1441
1456
  }
1442
- function zr(e, t) {
1443
- return jr(t).map((r) => e[r]).filter((r) => r != null);
1457
+ function Gr(e, t) {
1458
+ return zr(t).map((r) => e[r]).filter((r) => r != null);
1444
1459
  }
1445
- function Gr(e, t, n, r) {
1460
+ function Qr(e, t, n, r) {
1446
1461
  if (r <= 0) return 0;
1447
1462
  const i = Math.max(1, n - t) / r, o = e - t, c = Math.floor(o / i);
1448
1463
  return Math.min(r - 1, Math.max(0, c));
1449
1464
  }
1450
- function Qr(e, t, n) {
1465
+ function Yr(e, t, n) {
1451
1466
  if (!n) return `${e}/${t}`;
1452
1467
  const r = t.split("/").pop() ?? t, s = r.includes(".") ? r.slice(0, r.lastIndexOf(".")) : r;
1453
1468
  return `${e}/${s}.bin`;
1454
1469
  }
1455
- const Yr = [0.32, 0.24, 0.16, 0.08, 0], Jr = Yr.map(
1470
+ const Jr = [0.32, 0.24, 0.16, 0.08, 0], Xr = Jr.map(
1456
1471
  (e) => `eyes_${e.toFixed(2)}`
1457
- ), Xr = [
1472
+ ), Zr = [
1458
1473
  "eyes_0.32",
1459
1474
  "eyes_0.16",
1460
1475
  "eyes_0.00"
1461
- ], Zr = [
1476
+ ], es = [
1462
1477
  "eyes_0.32",
1463
1478
  "eyes_0.16",
1464
1479
  "eyes_0.08",
1465
1480
  "eyes_0.00"
1466
- ], Ht = 2, es = -30, yt = 20, ts = {
1481
+ ], Kt = 2, ts = -30, kt = 20, ns = {
1467
1482
  fear: -30,
1468
1483
  anger: -20,
1469
1484
  sad: -10,
@@ -1472,24 +1487,24 @@ const Yr = [0.32, 0.24, 0.16, 0.08, 0], Jr = Yr.map(
1472
1487
  happy: 0,
1473
1488
  disgust: 20
1474
1489
  };
1475
- function Rt(e) {
1490
+ function Ct(e) {
1476
1491
  return `brow_${e}`;
1477
1492
  }
1478
- function Dt(e) {
1479
- return ts[e];
1493
+ function xt(e) {
1494
+ return ns[e];
1480
1495
  }
1481
- function Ae(e) {
1482
- return Math.max(es, Math.min(yt, e));
1496
+ function Ie(e) {
1497
+ return Math.max(ts, Math.min(kt, e));
1483
1498
  }
1484
- function ns(e, t) {
1499
+ function rs(e, t) {
1485
1500
  if (e === t) return [];
1486
- const n = e < t ? Ht : -Ht, r = [];
1501
+ const n = e < t ? Kt : -Kt, r = [];
1487
1502
  let s = e;
1488
1503
  for (; s !== t; )
1489
1504
  s += n, r.push(s);
1490
1505
  return r;
1491
1506
  }
1492
- const rs = {
1507
+ const ss = {
1493
1508
  fear: "fear",
1494
1509
  afraid: "fear",
1495
1510
  anxiety: "fear",
@@ -1512,63 +1527,63 @@ const rs = {
1512
1527
  disgust: "disgust",
1513
1528
  disgusted: "disgust"
1514
1529
  };
1515
- function Pe(e, t = "neutral") {
1530
+ function Fe(e, t = "neutral") {
1516
1531
  const n = String(e ?? "").trim().toLowerCase();
1517
- return n ? rs[n] ?? t : t;
1532
+ return n ? ss[n] ?? t : t;
1518
1533
  }
1519
- function hn(e) {
1520
- return e === 0 ? null : At(Rt(e), "eyes_standard");
1534
+ function _n(e) {
1535
+ return e === 0 ? null : Rt(Ct(e), "eyes_standard");
1521
1536
  }
1522
- function wn(e) {
1523
- return hn(Dt(e));
1537
+ function pn(e) {
1538
+ return _n(xt(e));
1524
1539
  }
1525
- function qt(e, t) {
1526
- const n = Rt(Dt(e));
1527
- return !t || t === "eyes_standard" ? wn(e) : e === "neutral" && t === "eyes_standard" ? null : At(n, t);
1540
+ function jt(e, t) {
1541
+ const n = Ct(xt(e));
1542
+ return !t || t === "eyes_standard" ? pn(e) : e === "neutral" && t === "eyes_standard" ? null : Rt(n, t);
1528
1543
  }
1529
- function ss(e, t) {
1544
+ function is(e, t) {
1530
1545
  const n = [];
1531
1546
  for (const r of t)
1532
- n.push(qt(e, r));
1547
+ n.push(jt(e, r));
1533
1548
  for (let r = t.length - 2; r >= 0; r--)
1534
- n.push(qt(e, t[r]));
1535
- return n.push(wn(e)), n;
1549
+ n.push(jt(e, t[r]));
1550
+ return n.push(pn(e)), n;
1536
1551
  }
1537
- function is(e) {
1538
- return e === 0 ? null : At(Rt(e), "eyes_standard");
1552
+ function os(e) {
1553
+ return e === 0 ? null : Rt(Ct(e), "eyes_standard");
1539
1554
  }
1540
- function os(e, t) {
1541
- return ns(e, t).map(is).filter((n) => n != null);
1555
+ function as(e, t) {
1556
+ return rs(e, t).map(os).filter((n) => n != null);
1542
1557
  }
1543
- const as = 6;
1544
- function cs(e, t) {
1558
+ const cs = 6;
1559
+ function us(e, t) {
1545
1560
  for (const n of e)
1546
1561
  if (t >= n.wtime && t < n.wtime + n.wduration)
1547
1562
  return n;
1548
1563
  return null;
1549
1564
  }
1550
- function us(e) {
1551
- const t = Ae(e);
1552
- return t >= yt ? yt : Ae(t + as);
1565
+ function ls(e) {
1566
+ const t = Ie(e);
1567
+ return t >= kt ? kt : Ie(t + cs);
1553
1568
  }
1554
- function ls(e, t, n) {
1555
- const r = Ae(n);
1556
- return cs(t, e)?.emphasis ? us(r) : r;
1569
+ function fs(e, t, n) {
1570
+ const r = Ie(n);
1571
+ return us(t, e)?.emphasis ? ls(r) : r;
1557
1572
  }
1558
- function Kt(e) {
1573
+ function zt(e) {
1559
1574
  if (!e) return 0;
1560
1575
  const t = e.match(/^brow_(-?\d+)\//);
1561
1576
  if (!t?.[1]) return null;
1562
1577
  const n = Number.parseInt(t[1], 10);
1563
- return Number.isFinite(n) ? Ae(n) : null;
1578
+ return Number.isFinite(n) ? Ie(n) : null;
1564
1579
  }
1565
- function We(e, t) {
1580
+ function qe(e, t) {
1566
1581
  return e + Math.random() * (t - e);
1567
1582
  }
1568
- function Je() {
1569
- return We(14, 32);
1583
+ function Xe() {
1584
+ return qe(14, 32);
1570
1585
  }
1571
- function fs(e = {}) {
1586
+ function ds(e = {}) {
1572
1587
  const {
1573
1588
  initialDelayMs: t = 800 + Math.random() * 1200,
1574
1589
  intervalMinMs: n = 2200,
@@ -1589,69 +1604,69 @@ function fs(e = {}) {
1589
1604
  }
1590
1605
  function E(g, I = w) {
1591
1606
  _ = g;
1592
- const k = Kt(g);
1607
+ const k = zt(g);
1593
1608
  k != null ? S = k : g == null && (S = 0), R(I);
1594
1609
  }
1595
- function N(g) {
1596
- return hn(g);
1610
+ function V(g) {
1611
+ return _n(g);
1597
1612
  }
1598
1613
  function j(g, I, k) {
1599
- const x = Ae(I), T = Ae(k);
1600
- if (m = T, x === T) {
1601
- E(N(T));
1614
+ const C = Ie(I), b = Ie(k);
1615
+ if (m = b, C === b) {
1616
+ E(V(b));
1602
1617
  return;
1603
1618
  }
1604
- const b = [
1605
- ...os(x, T),
1606
- N(T)
1619
+ const T = [
1620
+ ...as(C, b),
1621
+ V(b)
1607
1622
  ];
1608
1623
  u = {
1609
1624
  kind: "browBlend",
1610
- paths: b,
1625
+ paths: T,
1611
1626
  index: 0,
1612
- holdUntil: g + Je(),
1613
- targetBrow: T
1614
- }, E(b[0] ?? null);
1627
+ holdUntil: g + Xe(),
1628
+ targetBrow: b
1629
+ }, E(T[0] ?? null);
1615
1630
  }
1616
1631
  function M(g, I) {
1617
1632
  u = {
1618
1633
  kind: "idle",
1619
- nextBlinkAt: g + We(n, r)
1620
- }, y = I, E(N(m), I);
1634
+ nextBlinkAt: g + qe(n, r)
1635
+ }, y = I, E(V(m), I);
1621
1636
  }
1622
- function V(g, I, k) {
1623
- const x = k ? Xr : Math.random() < c ? Jr : Zr;
1637
+ function $(g, I, k) {
1638
+ const C = k ? Zr : Math.random() < c ? Xr : es;
1624
1639
  u = {
1625
1640
  kind: "playing",
1626
- paths: ss(I, x),
1641
+ paths: is(I, C),
1627
1642
  index: 0,
1628
- holdUntil: g + Je(),
1643
+ holdUntil: g + Xe(),
1629
1644
  after: "idle",
1630
1645
  blinkEmotion: I
1631
1646
  }, y = I, E(u.paths[0] ?? null, I);
1632
1647
  }
1633
- function U(g) {
1648
+ function N(g) {
1634
1649
  if (u.kind === "browBlend") {
1635
1650
  for (; g >= u.holdUntil && u.index < u.paths.length - 1; )
1636
- u.index += 1, u.holdUntil = g + Je();
1651
+ u.index += 1, u.holdUntil = g + Xe();
1637
1652
  const I = u.paths[u.index] ?? null;
1638
- E(I), g >= u.holdUntil && u.index >= u.paths.length - 1 && (S = u.targetBrow, m = u.targetBrow, E(N(u.targetBrow)), u = {
1653
+ E(I), g >= u.holdUntil && u.index >= u.paths.length - 1 && (S = u.targetBrow, m = u.targetBrow, E(V(u.targetBrow)), u = {
1639
1654
  kind: "idle",
1640
1655
  nextBlinkAt: g + l
1641
1656
  });
1642
1657
  return;
1643
1658
  }
1644
1659
  if (u.kind === "idle") {
1645
- E(N(m), y), g >= u.nextBlinkAt && V(g, y, !1);
1660
+ E(V(m), y), g >= u.nextBlinkAt && $(g, y, !1);
1646
1661
  return;
1647
1662
  }
1648
1663
  if (u.kind === "doublePause") {
1649
- E(N(m), u.blinkEmotion), g >= u.resumeAt && V(g, u.blinkEmotion, !0);
1664
+ E(V(m), u.blinkEmotion), g >= u.resumeAt && $(g, u.blinkEmotion, !0);
1650
1665
  return;
1651
1666
  }
1652
1667
  if (u.kind === "playing") {
1653
1668
  for (; g >= u.holdUntil && u.index < u.paths.length - 1; )
1654
- u.index += 1, u.holdUntil = g + Je();
1669
+ u.index += 1, u.holdUntil = g + Xe();
1655
1670
  if (E(u.paths[u.index] ?? null, u.blinkEmotion), g >= u.holdUntil && u.index >= u.paths.length - 1) {
1656
1671
  if (u.after === "resumeIdle") {
1657
1672
  M(g + l, w);
@@ -1660,17 +1675,17 @@ function fs(e = {}) {
1660
1675
  if (u.after === "doublePause") {
1661
1676
  u = {
1662
1677
  kind: "doublePause",
1663
- resumeAt: g + We(i, o),
1678
+ resumeAt: g + qe(i, o),
1664
1679
  blinkEmotion: u.blinkEmotion
1665
- }, E(N(m), u.blinkEmotion);
1680
+ }, E(V(m), u.blinkEmotion);
1666
1681
  return;
1667
1682
  }
1668
1683
  if (u.after === "idle" && Math.random() < s) {
1669
1684
  u = {
1670
1685
  kind: "doublePause",
1671
- resumeAt: g + We(i, o),
1686
+ resumeAt: g + qe(i, o),
1672
1687
  blinkEmotion: u.blinkEmotion
1673
- }, E(N(m), u.blinkEmotion);
1688
+ }, E(V(m), u.blinkEmotion);
1674
1689
  return;
1675
1690
  }
1676
1691
  M(g, u.blinkEmotion);
@@ -1678,18 +1693,18 @@ function fs(e = {}) {
1678
1693
  }
1679
1694
  }
1680
1695
  return {
1681
- advance: U,
1696
+ advance: N,
1682
1697
  setTargetEmotion(g) {
1683
- const I = Pe(g, w);
1698
+ const I = Fe(g, w);
1684
1699
  if (I === w) return;
1685
1700
  const k = performance.now();
1686
1701
  f > 0 && I !== w && !(w === "neutral" && I !== "neutral") && k - v < f || (w = I, y = I, v = k);
1687
1702
  },
1688
1703
  setTargetEyebrow(g) {
1689
- const I = Ae(g);
1704
+ const I = Ie(g);
1690
1705
  if (I === m && u.kind !== "browBlend") return;
1691
- const k = performance.now(), x = u.kind === "browBlend" ? Kt(_) ?? S : S;
1692
- m = I, !(I === x && u.kind !== "browBlend") && (u.kind === "playing" || u.kind === "doublePause" || j(k, x, I));
1706
+ const k = performance.now(), C = u.kind === "browBlend" ? zt(_) ?? S : S;
1707
+ m = I, !(I === C && u.kind !== "browBlend") && (u.kind === "playing" || u.kind === "doublePause" || j(k, C, I));
1693
1708
  },
1694
1709
  getTargetEmotion: () => w,
1695
1710
  getTargetEyebrow: () => m,
@@ -1697,13 +1712,13 @@ function fs(e = {}) {
1697
1712
  getDrawKey: () => d,
1698
1713
  reset() {
1699
1714
  w = "neutral", y = "neutral", m = 0, S = 0, v = 0, M(
1700
- performance.now() + We(n, r),
1715
+ performance.now() + qe(n, r),
1701
1716
  "neutral"
1702
1717
  );
1703
1718
  }
1704
1719
  };
1705
1720
  }
1706
- function ds() {
1721
+ function ms() {
1707
1722
  const e = document.createElement("video");
1708
1723
  e.muted = !0, e.playsInline = !0, e.preload = "auto", e.setAttribute("playsinline", ""), e.loop = !0;
1709
1724
  let t = !1, n = null, r = "";
@@ -1746,17 +1761,17 @@ function ds() {
1746
1761
  }
1747
1762
  };
1748
1763
  }
1749
- const ms = 50, gn = 400;
1750
- function hs(e, t, n) {
1764
+ const hs = 50, yn = 400;
1765
+ function ws(e, t, n) {
1751
1766
  return e.filter((r) => {
1752
1767
  const s = r.queueIndex ?? -1;
1753
1768
  return s >= t && s <= n;
1754
1769
  });
1755
1770
  }
1756
- function ws(e, t) {
1771
+ function gs(e, t) {
1757
1772
  const n = [];
1758
1773
  for (const r of e) {
1759
- const s = hs(
1774
+ const s = ws(
1760
1775
  t,
1761
1776
  r.start_word,
1762
1777
  r.end_word
@@ -1765,30 +1780,30 @@ function ws(e, t) {
1765
1780
  const i = s[0], o = s[s.length - 1];
1766
1781
  n.push({
1767
1782
  sentence: r,
1768
- startMs: Math.max(0, i.wtime - ms),
1769
- endMs: o.wtime + o.wduration + gn
1783
+ startMs: Math.max(0, i.wtime - hs),
1784
+ endMs: o.wtime + o.wduration + yn
1770
1785
  });
1771
1786
  }
1772
1787
  return n.sort((r, s) => r.startMs - s.startMs);
1773
1788
  }
1774
- function gs(e, t, n, r = "neutral") {
1775
- const s = Pe(r);
1789
+ function _s(e, t, n, r = "neutral") {
1790
+ const s = Fe(r);
1776
1791
  if (t.length === 0) return s;
1777
1792
  if (n.length === 0 || e < n[0].wtime)
1778
- return Pe(t[0]?.emotion, s);
1779
- const i = ws(t, n);
1793
+ return Fe(t[0]?.emotion, s);
1794
+ const i = gs(t, n);
1780
1795
  let o = null;
1781
1796
  for (const f of i)
1782
1797
  e >= f.startMs && e <= f.endMs && (o = f);
1783
1798
  if (o)
1784
- return Pe(o.sentence.emotion, s);
1799
+ return Fe(o.sentence.emotion, s);
1785
1800
  const c = n[n.length - 1], l = c.wtime + c.wduration;
1786
- return e > l + gn ? Pe(
1801
+ return e > l + yn ? Fe(
1787
1802
  t[t.length - 1]?.emotion,
1788
1803
  s
1789
1804
  ) : s;
1790
1805
  }
1791
- function _n(e, t, n, r, s = fn) {
1806
+ function kn(e, t, n, r, s = hn) {
1792
1807
  const i = new OffscreenCanvas(n, r), o = i.getContext("2d", { willReadFrequently: !0 });
1793
1808
  o.drawImage(e, 0, 0, n, r);
1794
1809
  const c = o.getImageData(0, 0, n, r), l = o.createImageData(n, r);
@@ -1804,38 +1819,38 @@ function _n(e, t, n, r, s = fn) {
1804
1819
  }
1805
1820
  return o.putImageData(l, 0, 0), i;
1806
1821
  }
1807
- let be = null, He = null;
1808
- const et = /* @__PURE__ */ new Map();
1809
- function _s() {
1810
- be = null, He = null, et.clear();
1822
+ let Te = null, Ke = null;
1823
+ const tt = /* @__PURE__ */ new Map();
1824
+ function ps() {
1825
+ Te = null, Ke = null, tt.clear();
1811
1826
  }
1812
- rr(_s);
1813
- function ps(e) {
1814
- return e ?? He ?? void 0;
1827
+ ir(ps);
1828
+ function ys(e) {
1829
+ return e ?? Ke ?? void 0;
1815
1830
  }
1816
- function xt(e) {
1831
+ function Mt(e) {
1817
1832
  return new Promise((t, n) => {
1818
1833
  const r = new Image();
1819
1834
  r.decoding = "async", r.onload = () => t(r), r.onerror = () => n(new Error(`Failed to load image: ${e}`)), r.src = e;
1820
1835
  });
1821
1836
  }
1822
- async function ys(e) {
1823
- return tt() ? Vr(
1824
- await it(Ft(), e ?? "")
1825
- ) : xt(Ft());
1837
+ async function ks(e) {
1838
+ return nt() ? $r(
1839
+ await ot(Ut(), e ?? "")
1840
+ ) : Mt(Ut());
1826
1841
  }
1827
- async function jt(e, t, n, r) {
1828
- const s = n ? await Ur(e, r) : await fetch(e).then((f) => {
1842
+ async function Gt(e, t, n, r) {
1843
+ const s = n ? await Nr(e, r) : await fetch(e).then((f) => {
1829
1844
  if (!f.ok) throw new Error(`Failed to load ${e}`);
1830
1845
  return f.json();
1831
1846
  }), i = s.sheets?.[0];
1832
1847
  if (!i?.path) throw new Error(`${e} has no sheets[0].path`);
1833
- const o = n ? await Nr(
1834
- await it(
1835
- Qr(t, i.path, n),
1848
+ const o = n ? await Vr(
1849
+ await ot(
1850
+ Yr(t, i.path, n),
1836
1851
  r ?? ""
1837
1852
  )
1838
- ) : await xt(`${t}/${i.path}`), c = /* @__PURE__ */ new Map();
1853
+ ) : await Mt(`${t}/${i.path}`), c = /* @__PURE__ */ new Map();
1839
1854
  for (const f of s.cells ?? [])
1840
1855
  f.path && c.set(f.path, f);
1841
1856
  const l = /* @__PURE__ */ new Map();
@@ -1843,30 +1858,30 @@ async function jt(e, t, n, r) {
1843
1858
  l.set(f.index, f);
1844
1859
  return { atlas: o, atlasMeta: s, cellByPath: c, sheetByIndex: l, diffBase: t };
1845
1860
  }
1846
- async function kt(e) {
1847
- const t = ps(e), n = tt();
1861
+ async function vt(e) {
1862
+ const t = ys(e), n = nt();
1848
1863
  if (n && !t)
1849
1864
  throw new Error("Encrypted assets enabled but no key provided");
1850
- if (be && (!n || He === (t ?? null))) {
1851
- const i = await be;
1865
+ if (Te && (!n || Ke === (t ?? null))) {
1866
+ const i = await Te;
1852
1867
  return {
1853
- ...qe(i),
1868
+ ...je(i),
1854
1869
  visemePaths: [...i.viseme.cellByPath.keys()]
1855
1870
  };
1856
1871
  }
1857
- He = t ?? null, et.clear();
1858
- const r = ir();
1859
- be = (async () => {
1860
- const i = await ys(t), o = await jt(
1861
- or(),
1872
+ Ke = t ?? null, tt.clear();
1873
+ const r = ar();
1874
+ Te = (async () => {
1875
+ const i = await ks(t), o = await Gt(
1876
+ cr(),
1862
1877
  r,
1863
1878
  n,
1864
1879
  t
1865
1880
  );
1866
1881
  let c = null;
1867
1882
  try {
1868
- c = await jt(
1869
- ar(),
1883
+ c = await Gt(
1884
+ ur(),
1870
1885
  r,
1871
1886
  n,
1872
1887
  t
@@ -1876,45 +1891,45 @@ async function kt(e) {
1876
1891
  }
1877
1892
  return { sil: i, viseme: o, expression: c };
1878
1893
  })();
1879
- const s = await be;
1880
- return { ...qe(s), visemePaths: [...s.viseme.cellByPath.keys()] };
1894
+ const s = await Te;
1895
+ return { ...je(s), visemePaths: [...s.viseme.cellByPath.keys()] };
1881
1896
  }
1882
- async function pn(e) {
1883
- if (await kt(e), !be) throw new Error("Assets not loaded");
1884
- return be;
1897
+ async function vn(e) {
1898
+ if (await vt(e), !Te) throw new Error("Assets not loaded");
1899
+ return Te;
1885
1900
  }
1886
- function qe(e) {
1901
+ function je(e) {
1887
1902
  return Or(
1888
1903
  e.viseme.atlasMeta,
1889
1904
  e.sil.naturalWidth,
1890
1905
  e.sil.naturalHeight
1891
1906
  );
1892
1907
  }
1893
- function ks(e, t) {
1908
+ function vs(e, t) {
1894
1909
  const n = document.createElement("canvas");
1895
1910
  return n.width = t.w, n.height = t.h, n.getContext("2d", { willReadFrequently: !0 }).drawImage(e.atlas, t.x, t.y, t.w, t.h, 0, 0, t.w, t.h), n;
1896
1911
  }
1897
- async function zt(e, t, n) {
1898
- const r = `${t.diffBase}::${n}`, s = et.get(r);
1912
+ async function Qt(e, t, n) {
1913
+ const r = `${t.diffBase}::${n}`, s = tt.get(r);
1899
1914
  if (s) return s;
1900
1915
  const i = (async () => {
1901
1916
  const o = t.cellByPath.get(n);
1902
1917
  if (!o) throw new Error(`No atlas cell for path: ${n}`);
1903
- const c = Fr(t.atlasMeta, o), l = qe(e);
1904
- if (Lr(o)) {
1905
- const y = ks(t, o), m = document.createElement("canvas");
1918
+ const c = Lr(t.atlasMeta, o), l = je(e);
1919
+ if (Ur(o)) {
1920
+ const y = vs(t, o), m = document.createElement("canvas");
1906
1921
  m.width = l.width, m.height = l.height;
1907
1922
  const S = m.getContext("2d");
1908
1923
  return S.fillStyle = "#000", S.fillRect(0, 0, l.width, l.height), S.drawImage(y, c.x, c.y), m;
1909
1924
  }
1910
- const f = `${t.diffBase}/${n}`, w = await xt(f);
1925
+ const f = `${t.diffBase}/${n}`, w = await Mt(f);
1911
1926
  if (w.naturalWidth === l.width && w.naturalHeight === l.height)
1912
1927
  return w;
1913
1928
  throw new Error(`Diff PNG wrong size for ${n}`);
1914
1929
  })();
1915
- return et.set(r, i), i;
1930
+ return tt.set(r, i), i;
1916
1931
  }
1917
- async function Gt(e, t, n, r, s, i) {
1932
+ async function Yt(e, t, n, r, s, i) {
1918
1933
  if (s) {
1919
1934
  const { width: S, height: v } = s;
1920
1935
  if (i && !i() || t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
@@ -1928,7 +1943,7 @@ async function Gt(e, t, n, r, s, i) {
1928
1943
  d.clearRect(0, 0, S, v), d.drawImage(u, 0, 0);
1929
1944
  return;
1930
1945
  }
1931
- const o = await pn(), c = dn(o.viseme.atlasMeta), { width: l, height: f } = qe(o);
1946
+ const o = await vn(), c = wn(o.viseme.atlasMeta), { width: l, height: f } = je(o);
1932
1947
  (e.width !== l || e.height !== f) && (e.width = l, e.height = f);
1933
1948
  const w = [], y = e.getContext("2d");
1934
1949
  if (y.clearRect(0, 0, l, f), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
@@ -1940,26 +1955,26 @@ async function Gt(e, t, n, r, s, i) {
1940
1955
  y.drawImage(t, 0, 0, l, f);
1941
1956
  return;
1942
1957
  }
1943
- const m = _n(t, w, l, f, c);
1958
+ const m = kn(t, w, l, f, c);
1944
1959
  y.drawImage(m, 0, 0);
1945
1960
  }
1946
- async function vt(e, t, n) {
1947
- const r = await pn(He ?? void 0), s = dn(r.viseme.atlasMeta), { width: i, height: o } = qe(r);
1961
+ async function St(e, t, n) {
1962
+ const r = await vn(Ke ?? void 0), s = wn(r.viseme.atlasMeta), { width: i, height: o } = je(r);
1948
1963
  (e.width !== i || e.height !== o) && (e.width = i, e.height = o);
1949
1964
  const c = [];
1950
1965
  if (t.mouthPath) {
1951
- const w = new Set(r.viseme.cellByPath.keys()), y = qr(t.mouthPath, w) ?? (w.has(t.mouthPath) ? t.mouthPath : null);
1952
- y && c.push(await zt(r, r.viseme, y));
1966
+ const w = new Set(r.viseme.cellByPath.keys()), y = Kr(t.mouthPath, w) ?? (w.has(t.mouthPath) ? t.mouthPath : null);
1967
+ y && c.push(await Qt(r, r.viseme, y));
1953
1968
  }
1954
1969
  t.expressionPath && r.expression && c.push(
1955
- await zt(r, r.expression, t.expressionPath)
1970
+ await Qt(r, r.expression, t.expressionPath)
1956
1971
  );
1957
1972
  const l = e.getContext("2d");
1958
1973
  if (l.clearRect(0, 0, i, o), c.length === 0) {
1959
1974
  l.drawImage(r.sil, 0, 0, i, o);
1960
1975
  return;
1961
1976
  }
1962
- const f = _n(
1977
+ const f = kn(
1963
1978
  r.sil,
1964
1979
  c,
1965
1980
  i,
@@ -1968,37 +1983,37 @@ async function vt(e, t, n) {
1968
1983
  );
1969
1984
  l.drawImage(f, 0, 0);
1970
1985
  }
1971
- async function vs(e) {
1972
- await vt(e, { mouthPath: null, expressionPath: null });
1986
+ async function Ss(e) {
1987
+ await St(e, { mouthPath: null, expressionPath: null });
1973
1988
  }
1974
- function Ss(e) {
1989
+ function Es(e) {
1975
1990
  const t = /* @__PURE__ */ new Map();
1976
1991
  for (const n of e)
1977
1992
  t.has(n.vtime) || t.set(n.vtime, n);
1978
1993
  return [...t.values()].sort((n, r) => n.vtime - r.vtime);
1979
1994
  }
1980
- function Es(e) {
1981
- const t = Ss(e), n = [];
1995
+ function bs(e) {
1996
+ const t = Es(e), n = [];
1982
1997
  for (let r = 0; r < t.length - 1; r++) {
1983
1998
  const s = t[r].viseme, i = t[r + 1].viseme, o = t[r].vtime, c = t[r + 1].vtime;
1984
1999
  s === i || c <= o || n.push({ from: s, to: i, fromVtime: o, toVtime: c });
1985
2000
  }
1986
2001
  return n;
1987
2002
  }
1988
- function bs(e, t) {
2003
+ function Ts(e, t) {
1989
2004
  let n = null;
1990
2005
  for (const r of e)
1991
2006
  t >= r.fromVtime && t < r.toVtime && (n = r);
1992
2007
  return n;
1993
2008
  }
1994
- function Ts(e, t) {
2009
+ function As(e, t) {
1995
2010
  return { gapMs: Math.max(0, t - e), holdEnd: e, transStart: e };
1996
2011
  }
1997
- const yn = 400, As = 200, Is = 600, kn = "__sil__";
1998
- function Rs(e) {
1999
- return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] === kn : !1;
2012
+ const Sn = 400, Is = 200, Rs = 600, En = "__sil__";
2013
+ function Ds(e) {
2014
+ return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] === En : !1;
2000
2015
  }
2001
- function Ds() {
2016
+ function Cs() {
2002
2017
  return { lastDrawnKey: "" };
2003
2018
  }
2004
2019
  function pe(e) {
@@ -2007,42 +2022,42 @@ function pe(e) {
2007
2022
  function xs(e, t) {
2008
2023
  if (t?.transitionCache && t.transitionCache.queueLength === e.length)
2009
2024
  return t.transitionCache.transitions;
2010
- const n = Es(e);
2025
+ const n = bs(e);
2011
2026
  return t && (t.transitionCache = { queueLength: e.length, transitions: n }), n;
2012
2027
  }
2013
- function Cs(e, t) {
2028
+ function Ms(e, t) {
2014
2029
  let n = "sil";
2015
2030
  for (const r of e)
2016
2031
  r.viseme !== "sil" && (t != null && r.vtime > t || (n = r.viseme));
2017
2032
  return n;
2018
2033
  }
2019
- function Ms(e, t, n, r = 120) {
2034
+ function Ps(e, t, n, r = 120) {
2020
2035
  if (n !== "sil")
2021
2036
  return n;
2022
- const s = Tr(e, t, r);
2023
- return s !== "sil" ? s : Cs(e, t);
2037
+ const s = Ar(e, t, r);
2038
+ return s !== "sil" ? s : Ms(e, t);
2024
2039
  }
2025
- function Ps(e, t) {
2026
- return e === "sil" ? !1 : t ? Kr(e, "sil", t) : It(e, "sil").length > 0;
2040
+ function Bs(e, t) {
2041
+ return e === "sil" ? !1 : t ? jr(e, "sil", t) : Dt(e, "sil").length > 0;
2027
2042
  }
2028
- function Bs() {
2029
- return yn + Is;
2043
+ function Fs() {
2044
+ return Sn + Rs;
2030
2045
  }
2031
- function Qt(e) {
2032
- return e ?? kn;
2046
+ function Jt(e) {
2047
+ return e ?? En;
2033
2048
  }
2034
2049
  function Os(e, t, n, r) {
2035
2050
  if (e.length === 0)
2036
2051
  return { diffPath: null, label: "sil" };
2037
- const s = xs(e, r), i = bs(s, t);
2052
+ const s = xs(e, r), i = Ts(s, t);
2038
2053
  if (i) {
2039
- const c = i.toVtime - i.fromVtime, l = Ts(i.fromVtime, i.toVtime);
2054
+ const c = i.toVtime - i.fromVtime, l = As(i.fromVtime, i.toVtime);
2040
2055
  if (t >= l.transStart && t < i.toVtime) {
2041
- let f = It(i.from, i.to);
2042
- n && (f = mn(f, n));
2043
- const w = zr(f, c);
2056
+ let f = Dt(i.from, i.to);
2057
+ n && (f = gn(f, n));
2058
+ const w = Gr(f, c);
2044
2059
  if (w.length > 0) {
2045
- const y = Gr(
2060
+ const y = Qr(
2046
2061
  t,
2047
2062
  l.transStart,
2048
2063
  i.toVtime,
@@ -2050,34 +2065,34 @@ function Os(e, t, n, r) {
2050
2065
  );
2051
2066
  return { diffPath: w[y] ?? w[w.length - 1], label: `${i.from}→${i.to}` };
2052
2067
  }
2053
- return { diffPath: Ze(i.to), label: i.to };
2068
+ return { diffPath: et(i.to), label: i.to };
2054
2069
  }
2055
2070
  }
2056
- const o = rt(e, t);
2057
- return o === "sil" ? { diffPath: null, label: "sil" } : { diffPath: Ze(o), label: o };
2071
+ const o = st(e, t);
2072
+ return o === "sil" ? { diffPath: null, label: "sil" } : { diffPath: et(o), label: o };
2058
2073
  }
2059
- function vn(e, t) {
2060
- const n = t ?? Qt(e.expressionPath);
2061
- return `${Qt(e.mouthPath)}|${n}`;
2074
+ function bn(e, t) {
2075
+ const n = t ?? Jt(e.expressionPath);
2076
+ return `${Jt(e.mouthPath)}|${n}`;
2062
2077
  }
2063
- function Fs(e, t, n, r, s, i, o, c, l, f) {
2078
+ function Ls(e, t, n, r, s, i, o, c, l, f) {
2064
2079
  const w = Os(t, n, l, i), y = {
2065
2080
  mouthPath: w.diffPath,
2066
2081
  expressionPath: r
2067
- }, m = vn(y, s);
2082
+ }, m = bn(y, s);
2068
2083
  m !== i.lastDrawnKey && (c(w.label), o(e, y, m, (S) => {
2069
2084
  S === m && (i.lastDrawnKey = m);
2070
2085
  }));
2071
2086
  }
2072
- function Yt(e, t, n, r, s, i, o = null) {
2073
- const c = { mouthPath: null, expressionPath: t }, l = o != null ? `|idle@${Math.round(o * 1e3)}` : "", f = vn(c, n) + l;
2087
+ function Xt(e, t, n, r, s, i, o = null) {
2088
+ const c = { mouthPath: null, expressionPath: t }, l = o != null ? `|idle@${Math.round(o * 1e3)}` : "", f = bn(c, n) + l;
2074
2089
  !(o != null) && f === r.lastDrawnKey || (i(
2075
2090
  o != null ? "idle" : "sil"
2076
2091
  ), s(e, c, f, (y) => {
2077
2092
  y === f && (r.lastDrawnKey = f);
2078
2093
  }));
2079
2094
  }
2080
- function Sn(e) {
2095
+ function Tn(e) {
2081
2096
  let t = 0, n = null, r = !1, s = !1;
2082
2097
  const i = async () => {
2083
2098
  if (!r) {
@@ -2113,9 +2128,9 @@ function Sn(e) {
2113
2128
  }
2114
2129
  };
2115
2130
  }
2116
- const Jt = -1, Xt = /* @__PURE__ */ new Map();
2117
- async function Ls(e) {
2118
- let t = Xt.get(e);
2131
+ const Zt = -1, en = /* @__PURE__ */ new Map();
2132
+ async function Us(e) {
2133
+ let t = en.get(e);
2119
2134
  if (!t) {
2120
2135
  const n = await fetch(e);
2121
2136
  if (!n.ok)
@@ -2123,32 +2138,32 @@ async function Ls(e) {
2123
2138
  `Failed to fetch worker script (${n.status}): ${e}`
2124
2139
  );
2125
2140
  const r = await n.blob();
2126
- t = URL.createObjectURL(r), Xt.set(e, t);
2141
+ t = URL.createObjectURL(r), en.set(e, t);
2127
2142
  }
2128
2143
  return new Worker(t, { name: "visemeDiffPreview" });
2129
2144
  }
2130
- function Us() {
2145
+ function Ns() {
2131
2146
  return typeof Worker < "u" && typeof OffscreenCanvas < "u";
2132
2147
  }
2133
- function Ns(e, t) {
2148
+ function Vs(e, t) {
2134
2149
  (e.width !== t.width || e.height !== t.height) && (e.width = t.width, e.height = t.height);
2135
2150
  const n = e.getContext("2d");
2136
2151
  n && n.drawImage(t, 0, 0);
2137
2152
  }
2138
- function Zt(e, t) {
2153
+ function tn(e, t) {
2139
2154
  let n = 0, r = null;
2140
- const s = Sn(async (i, o) => (await kt(), await vt(e, i), s.isLatestSeq(o)));
2155
+ const s = Tn(async (i, o) => (await vt(), await St(e, i), s.isLatestSeq(o)));
2141
2156
  return {
2142
2157
  usesWorker: !1,
2143
2158
  async loadAssets(i) {
2144
- const o = await kt(i);
2159
+ const o = await vt(i);
2145
2160
  return r = o.visemePaths ? new Set(o.visemePaths) : null, o;
2146
2161
  },
2147
2162
  getVisemeAtlasPaths() {
2148
2163
  return r;
2149
2164
  },
2150
2165
  async renderSilOnly() {
2151
- n += 1, s.reset(), await vs(e);
2166
+ n += 1, s.reset(), await Ss(e);
2152
2167
  },
2153
2168
  drawLiveFrame(i, o, c, l) {
2154
2169
  s.enqueue(o, c, l);
@@ -2156,8 +2171,8 @@ function Zt(e, t) {
2156
2171
  async renderViseme(i, o) {
2157
2172
  n += 1;
2158
2173
  const c = n;
2159
- t.onStatus?.(o), await vt(i, {
2160
- mouthPath: Ze(o),
2174
+ t.onStatus?.(o), await St(i, {
2175
+ mouthPath: et(o),
2161
2176
  expressionPath: null
2162
2177
  });
2163
2178
  },
@@ -2166,9 +2181,9 @@ function Zt(e, t) {
2166
2181
  }
2167
2182
  };
2168
2183
  }
2169
- function Vs(e, t, n) {
2184
+ function $s(e, t, n) {
2170
2185
  let r = null, s = 1, i = 0, o = !1, c = !1, l = null;
2171
- const f = /* @__PURE__ */ new Map(), w = Sn(async (_, d, R) => (f.set(d, {
2186
+ const f = /* @__PURE__ */ new Map(), w = Tn(async (_, d, R) => (f.set(d, {
2172
2187
  drawKey: R.drawKey,
2173
2188
  onDisplayed: R.onDisplayed
2174
2189
  }), await v(
@@ -2181,11 +2196,11 @@ function Vs(e, t, n) {
2181
2196
  void 0,
2182
2197
  !0
2183
2198
  ), !1)), y = (_) => {
2184
- if (_ === Jt) {
2185
- let E = -1, N;
2199
+ if (_ === Zt) {
2200
+ let E = -1, V;
2186
2201
  for (const [j, M] of f)
2187
- j >= E && (E = j, N = M);
2188
- E >= 0 && f.delete(E), N?.onDisplayed?.(N.drawKey);
2202
+ j >= E && (E = j, V = M);
2203
+ E >= 0 && f.delete(E), V?.onDisplayed?.(V.drawKey);
2189
2204
  return;
2190
2205
  }
2191
2206
  const d = -_, R = f.get(d);
@@ -2195,16 +2210,16 @@ function Vs(e, t, n) {
2195
2210
  }, v = (_, d, R = !1) => {
2196
2211
  if (c) return Promise.resolve();
2197
2212
  const E = s++;
2198
- return new Promise((N, j) => {
2213
+ return new Promise((V, j) => {
2199
2214
  m.set(E, {
2200
- resolve: (M) => N(M),
2215
+ resolve: (M) => V(M),
2201
2216
  reject: j,
2202
2217
  generation: typeof _.generation == "number" ? _.generation : void 0,
2203
2218
  expectRenderDone: R
2204
2219
  }), S({ ..._, requestId: E });
2205
2220
  });
2206
2221
  }, u = (async () => {
2207
- r = await Ls(n), r.onmessage = (_) => {
2222
+ r = await Us(n), r.onmessage = (_) => {
2208
2223
  if (c) return;
2209
2224
  const d = _.data;
2210
2225
  if (d.type === "status") {
@@ -2217,7 +2232,7 @@ function Vs(e, t, n) {
2217
2232
  d.bitmap.close();
2218
2233
  return;
2219
2234
  }
2220
- if (E && !(d.generation === Jt)) {
2235
+ if (E && !(d.generation === Zt)) {
2221
2236
  const j = -d.generation;
2222
2237
  if (!w.isLatestSeq(j)) {
2223
2238
  d.bitmap.close();
@@ -2228,7 +2243,7 @@ function Vs(e, t, n) {
2228
2243
  d.bitmap.close();
2229
2244
  return;
2230
2245
  }
2231
- Ns(e, d.bitmap), d.bitmap.close(), E && y(d.generation);
2246
+ Vs(e, d.bitmap), d.bitmap.close(), E && y(d.generation);
2232
2247
  return;
2233
2248
  }
2234
2249
  const R = m.get(d.requestId);
@@ -2270,7 +2285,7 @@ function Vs(e, t, n) {
2270
2285
  return await v({
2271
2286
  type: "loadAssets",
2272
2287
  keyHex: _,
2273
- urls: nr(Ie())
2288
+ urls: sr(Re())
2274
2289
  }) ?? { width: 842, height: 1264 };
2275
2290
  },
2276
2291
  getVisemeAtlasPaths() {
@@ -2309,9 +2324,9 @@ function Vs(e, t, n) {
2309
2324
  void 0,
2310
2325
  !0
2311
2326
  );
2312
- } catch (N) {
2313
- if (N?.name === "AbortError") return;
2314
- throw N;
2327
+ } catch (V) {
2328
+ if (V?.name === "AbortError") return;
2329
+ throw V;
2315
2330
  }
2316
2331
  },
2317
2332
  dispose() {
@@ -2324,25 +2339,25 @@ function Vs(e, t, n) {
2324
2339
  }
2325
2340
  };
2326
2341
  }
2327
- function $s(e, t = {}) {
2328
- if (!Us())
2329
- return Zt(e, t);
2330
- const n = Nn(t.workerScriptUrl);
2342
+ function Ws(e, t = {}) {
2343
+ if (!Ns())
2344
+ return tn(e, t);
2345
+ const n = $n(t.workerScriptUrl);
2331
2346
  try {
2332
- return Vs(e, t, n);
2347
+ return $s(e, t, n);
2333
2348
  } catch {
2334
- return Zt(e, t);
2349
+ return tn(e, t);
2335
2350
  }
2336
2351
  }
2337
- class Ws extends Error {
2352
+ class Hs extends Error {
2338
2353
  constructor(t, n) {
2339
2354
  super(`${t} timed out after ${Math.round(n / 1e3)}s`), this.name = "LoadTimeoutError";
2340
2355
  }
2341
2356
  }
2342
- function ht(e, t, n) {
2357
+ function wt(e, t, n) {
2343
2358
  return new Promise((r, s) => {
2344
2359
  const i = globalThis.setTimeout(() => {
2345
- s(new Ws(n, t));
2360
+ s(new Hs(n, t));
2346
2361
  }, t);
2347
2362
  e.then(
2348
2363
  (o) => {
@@ -2354,15 +2369,15 @@ function ht(e, t, n) {
2354
2369
  );
2355
2370
  });
2356
2371
  }
2357
- const Hs = {
2372
+ const qs = {
2358
2373
  position: "relative",
2359
2374
  display: "inline-block",
2360
2375
  lineHeight: 0
2361
- }, qs = {
2376
+ }, Ks = {
2362
2377
  display: "block",
2363
2378
  maxWidth: "100%",
2364
2379
  height: "auto"
2365
- }, Ks = {
2380
+ }, js = {
2366
2381
  position: "absolute",
2367
2382
  inset: 0,
2368
2383
  display: "flex",
@@ -2374,21 +2389,21 @@ const Hs = {
2374
2389
  fontSize: "0.875rem",
2375
2390
  textAlign: "center"
2376
2391
  };
2377
- function $e(e) {
2378
- return Wn(e) ? cn : an;
2392
+ function He(e) {
2393
+ return qn(e) ? fn : ln;
2379
2394
  }
2380
- function Se(e, t) {
2395
+ function Ee(e, t) {
2381
2396
  return t?.isSpeaking() ? t : e.isSpeaking() ? e : t?.isConnected() ? t : e;
2382
2397
  }
2383
- const ti = Rn(function({
2398
+ const ni = Cn(function({
2384
2399
  id: t,
2385
2400
  avatarId: n,
2386
2401
  faceId: r,
2387
2402
  assets: s,
2388
2403
  authToken: i,
2389
- ttsEngineId: o = Be,
2404
+ ttsEngineId: o = Oe,
2390
2405
  voiceId: c,
2391
- speakingRate: l = st,
2406
+ speakingRate: l = it,
2392
2407
  className: f,
2393
2408
  style: w,
2394
2409
  canvasStyle: y,
@@ -2400,95 +2415,95 @@ const ti = Rn(function({
2400
2415
  onUserTranscript: d,
2401
2416
  onBotOutput: R,
2402
2417
  onRealtimeLipsyncDebug: E
2403
- }, N) {
2404
- const j = L(null), M = L(null), V = L(Ds()), U = L(fs()), g = L(0), I = L(0), k = L(0), x = L(null), T = L(null), b = L(!1), A = L(!1), F = L(!1), B = L("sil"), z = L(0), Y = L(!1), H = L(
2418
+ }, V) {
2419
+ const j = U(null), M = U(null), $ = U(Cs()), N = U(ds()), g = U(0), I = U(0), k = U(0), C = U(null), b = U(null), T = U(!1), A = U(!1), L = U(!1), F = U("sil"), J = U(0), Z = U(!1), B = U(
2405
2420
  null
2406
- ), X = L(!1), [Z, ge] = Ve("idle"), [te, ye] = Ve(null), [oe, Ke] = Ve(!1), [ot, Le] = Ve(!1), [at, Ct] = Ve({ width: 842, height: 1264 }), ke = L(i ?? null), Ue = L(null), ae = L(null), a = L(!1), p = L({ width: 842, height: 1264 }), C = L(null), G = L(u), W = L(S), Ee = L(v), re = L(d), Re = L(R), _e = L(E);
2407
- G.current = u, W.current = S, Ee.current = v, re.current = d, Re.current = R, _e.current = E;
2408
- const je = me(
2421
+ ), G = U(!1), [ce, le] = We("idle"), [te, ye] = We(null), [ee, De] = We(!1), [ke, Ne] = We(!1), [at, Pt] = We({ width: 842, height: 1264 }), ve = U(i ?? null), Ve = U(null), oe = U(null), a = U(!1), p = U({ width: 842, height: 1264 }), x = U(null), z = U(u), H = U(S), be = U(v), re = U(d), Ce = U(R), _e = U(E);
2422
+ z.current = u, H.current = S, be.current = v, re.current = d, Ce.current = R, _e.current = E;
2423
+ const ze = he(
2409
2424
  (h) => {
2410
- const D = h?.ttsEngineId ?? o ?? ae.current?.ttsEngineId ?? Be, P = h?.voiceId ?? c ?? ae.current?.voiceId ?? $e(D);
2425
+ const D = h?.ttsEngineId ?? o ?? oe.current?.ttsEngineId ?? Oe, P = h?.voiceId ?? c ?? oe.current?.voiceId ?? He(D);
2411
2426
  return { ttsEngineId: D, voiceId: P };
2412
2427
  },
2413
2428
  [o, c]
2414
- ), le = me((h) => {
2415
- ye(h), Ee.current?.(h);
2416
- }, []), fe = me(
2429
+ ), fe = he((h) => {
2430
+ ye(h), be.current?.(h);
2431
+ }, []), de = he(
2417
2432
  (h) => {
2418
- ge(h), m?.(h);
2433
+ le(h), m?.(h);
2419
2434
  },
2420
2435
  [m]
2421
- ), q = L(
2422
- Nt(fe, Te)
2423
- ), Q = L(null);
2424
- Me(() => (q.current = Nt(
2425
- fe,
2426
- Te
2436
+ ), q = U(
2437
+ $t(de, Ae)
2438
+ ), Q = U(null);
2439
+ Be(() => (q.current = $t(
2440
+ de,
2441
+ Ae
2427
2442
  ), i && q.current.setDeveloperToken(i), q.current.setTtsEngineId(o), () => {
2428
2443
  q.current.stop();
2429
2444
  const h = Q.current;
2430
2445
  h && (h.disconnect(), Q.current = null);
2431
- }), [fe, i, o]);
2432
- const ze = me(() => (Q.current || (Q.current = Br(
2433
- fe,
2446
+ }), [de, i, o]);
2447
+ const Ge = he(() => (Q.current || (Q.current = Fr(
2448
+ de,
2434
2449
  {
2435
2450
  speakingRate: l,
2436
2451
  onUserTranscript: (h, D) => re.current?.(h, D),
2437
- onBotOutput: (h) => Re.current?.(h),
2452
+ onBotOutput: (h) => Ce.current?.(h),
2438
2453
  onLipsyncDebug: (h) => _e.current?.(h)
2439
2454
  }
2440
- ), Q.current.setTtsEngineId(o)), Q.current), [fe, l, o]), ee = me(() => {
2441
- x.current != null && (clearTimeout(x.current), x.current = null);
2442
- }, []), ue = me(() => {
2443
- T.current != null && (clearTimeout(T.current), T.current = null), F.current = !1;
2444
- }, []), De = me(() => {
2445
- !X.current || !H.current || (ue(), F.current = !0, T.current = setTimeout(() => {
2446
- if (T.current = null, Se(
2455
+ ), Q.current.setTtsEngineId(o)), Q.current), [de, l, o]), X = he(() => {
2456
+ C.current != null && (clearTimeout(C.current), C.current = null);
2457
+ }, []), ue = he(() => {
2458
+ b.current != null && (clearTimeout(b.current), b.current = null), L.current = !1;
2459
+ }, []), xe = he(() => {
2460
+ !G.current || !B.current || (ue(), L.current = !0, b.current = setTimeout(() => {
2461
+ if (b.current = null, Ee(
2447
2462
  q.current,
2448
2463
  Q.current
2449
2464
  ).isSpeaking()) {
2450
- F.current = !1;
2465
+ L.current = !1;
2451
2466
  return;
2452
2467
  }
2453
- if (b.current) {
2454
- F.current = !1;
2468
+ if (T.current) {
2469
+ L.current = !1;
2455
2470
  return;
2456
2471
  }
2457
- const h = H.current;
2472
+ const h = B.current;
2458
2473
  if (!h) {
2459
- F.current = !1;
2474
+ L.current = !1;
2460
2475
  return;
2461
2476
  }
2462
2477
  h.restart(), h.setActive(!0);
2463
2478
  const D = h.getVideo();
2464
2479
  let P = !1;
2465
- const $ = () => {
2466
- P || (P = !0, D.removeEventListener("playing", O), F.current = !1);
2480
+ const W = () => {
2481
+ P || (P = !0, D.removeEventListener("playing", O), L.current = !1);
2467
2482
  }, O = () => {
2468
- $();
2483
+ W();
2469
2484
  };
2470
2485
  if (D.addEventListener("playing", O, { once: !0 }), D.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && !D.paused) {
2471
- $();
2486
+ W();
2472
2487
  return;
2473
2488
  }
2474
- setTimeout($, 300);
2475
- }, As));
2476
- }, [ue]), J = me(() => {
2477
- if (ee(), W.current?.("sil"), b.current = !1, !X.current || !H.current) {
2478
- F.current = !1;
2489
+ setTimeout(W, 300);
2490
+ }, Is));
2491
+ }, [ue]), Y = he(() => {
2492
+ if (X(), H.current?.("sil"), T.current = !1, !G.current || !B.current) {
2493
+ L.current = !1;
2479
2494
  return;
2480
2495
  }
2481
- De();
2482
- }, [ee, De]), ce = me(
2496
+ xe();
2497
+ }, [X, xe]), ae = he(
2483
2498
  async (h) => {
2484
- const D = I.current, P = M.current, $ = j.current, O = () => {
2485
- h?.fallbackOnly || (b.current = !1);
2499
+ const D = I.current, P = M.current, W = j.current, O = () => {
2500
+ h?.fallbackOnly || (T.current = !1);
2486
2501
  };
2487
- if (!P || !$ || !oe) {
2502
+ if (!P || !W || !ee) {
2488
2503
  O();
2489
2504
  return;
2490
2505
  }
2491
- if (Se(
2506
+ if (Ee(
2492
2507
  q.current,
2493
2508
  Q.current
2494
2509
  ).isSpeaking()) {
@@ -2496,398 +2511,398 @@ const ti = Rn(function({
2496
2511
  return;
2497
2512
  }
2498
2513
  if (h?.fallbackOnly) {
2499
- if (!b.current || (pe(V.current), await P.renderSilOnly(), D !== I.current) || Se(
2514
+ if (!T.current || (pe($.current), await P.renderSilOnly(), D !== I.current) || Ee(
2500
2515
  q.current,
2501
2516
  Q.current
2502
2517
  ).isSpeaking())
2503
2518
  return;
2504
- J();
2519
+ Y();
2505
2520
  return;
2506
2521
  }
2507
- if (Rs(V.current)) {
2508
- pe(V.current), J();
2522
+ if (Ds($.current)) {
2523
+ pe($.current), Y();
2509
2524
  return;
2510
2525
  }
2511
- const ie = Ms(
2512
- Se(
2526
+ const ie = Ps(
2527
+ Ee(
2513
2528
  q.current,
2514
2529
  Q.current
2515
2530
  ).getVisemeQueue(),
2516
- z.current,
2517
- B.current
2518
- ), we = Ps(
2531
+ J.current,
2532
+ F.current
2533
+ ), ge = Bs(
2519
2534
  ie,
2520
- C.current
2535
+ x.current
2521
2536
  );
2522
- if (pe(V.current), !we) {
2523
- if (await P.renderSilOnly(), D !== I.current || Se(
2537
+ if (pe($.current), !ge) {
2538
+ if (await P.renderSilOnly(), D !== I.current || Ee(
2524
2539
  q.current,
2525
2540
  Q.current
2526
2541
  ).isSpeaking())
2527
2542
  return;
2528
- J();
2543
+ Y();
2529
2544
  return;
2530
2545
  }
2531
2546
  try {
2532
- await P.renderViseme($, "sil", {
2547
+ await P.renderViseme(W, "sil", {
2533
2548
  from: ie,
2534
- transitionDurationMs: yn
2549
+ transitionDurationMs: Sn
2535
2550
  });
2536
- } catch (ve) {
2537
- if (ve?.name !== "AbortError")
2538
- throw ve;
2551
+ } catch (Se) {
2552
+ if (Se?.name !== "AbortError")
2553
+ throw Se;
2539
2554
  }
2540
2555
  if (D !== I.current) {
2541
2556
  O();
2542
2557
  return;
2543
2558
  }
2544
- if (Se(
2559
+ if (Ee(
2545
2560
  q.current,
2546
2561
  Q.current
2547
2562
  ).isSpeaking()) {
2548
2563
  O();
2549
2564
  return;
2550
2565
  }
2551
- J();
2566
+ Y();
2552
2567
  },
2553
- [oe, J]
2554
- ), se = me(() => {
2555
- if (A.current || b.current) return;
2556
- A.current = !0, b.current = !0, ee();
2568
+ [ee, Y]
2569
+ ), se = he(() => {
2570
+ if (A.current || T.current) return;
2571
+ A.current = !0, T.current = !0, X();
2557
2572
  const h = I.current;
2558
- ce().finally(() => {
2573
+ ae().finally(() => {
2559
2574
  A.current = !1;
2560
- }), x.current = setTimeout(() => {
2561
- x.current = null, h === I.current && ce({ fallbackOnly: !0 });
2562
- }, Bs());
2563
- }, [ee, ce]), xe = me(async () => {
2575
+ }), C.current = setTimeout(() => {
2576
+ C.current = null, h === I.current && ae({ fallbackOnly: !0 });
2577
+ }, Fs());
2578
+ }, [X, ae]), Me = he(async () => {
2564
2579
  const h = Math.floor(Date.now() / 1e3);
2565
- if (Ue.current && h < Ue.current.expiresAt - 60)
2566
- return Ue.current.key;
2567
- const D = ke.current ?? await ft();
2568
- ke.current = D, q.current.setDeveloperToken(D);
2569
- const P = await Yn(D, Te);
2570
- return Ue.current = {
2580
+ if (Ve.current && h < Ve.current.expiresAt - 60)
2581
+ return Ve.current.key;
2582
+ const D = ve.current ?? await dt();
2583
+ ve.current = D, q.current.setDeveloperToken(D);
2584
+ const P = await Xn(D, Ae);
2585
+ return Ve.current = {
2571
2586
  key: P.value,
2572
2587
  expiresAt: P.expiresAt
2573
2588
  }, P.value;
2574
2589
  }, []);
2575
- Me(() => {
2576
- i && (ke.current = i, q.current.setDeveloperToken(i));
2577
- }, [i]), Me(() => {
2578
- q.current.setTtsEngineId(o), Q.current?.setTtsEngineId(o), ae.current && (ae.current.ttsEngineId = o);
2579
- }, [o]), Me(() => {
2580
- const h = c ?? $e(o);
2581
- ae.current && (ae.current.voiceId = h);
2590
+ Be(() => {
2591
+ i && (ve.current = i, q.current.setDeveloperToken(i));
2592
+ }, [i]), Be(() => {
2593
+ q.current.setTtsEngineId(o), Q.current?.setTtsEngineId(o), oe.current && (oe.current.ttsEngineId = o);
2594
+ }, [o]), Be(() => {
2595
+ const h = c ?? He(o);
2596
+ oe.current && (oe.current.voiceId = h);
2582
2597
  }, [c, o]);
2583
- const he = Pt(
2584
- () => er(n, r),
2598
+ const we = Ft(
2599
+ () => nr(n, r),
2585
2600
  [n, r]
2586
- ), En = Pt(() => s ? JSON.stringify(s) : he ? `face:${he}` : `id:${t ?? ""}`, [s, he, t]);
2587
- return Me(() => {
2588
- if (!t && !s && !he) {
2589
- le("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
2601
+ ), ct = Ft(() => s ? JSON.stringify(s) : we ? `face:${we}` : `id:${t ?? ""}`, [s, we, t]);
2602
+ return Be(() => {
2603
+ if (!t && !s && !we) {
2604
+ fe("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
2590
2605
  return;
2591
2606
  }
2592
2607
  let h = !1;
2593
- a.current = !1, Ke(!1), Le(!1), ye(null), ae.current = null, H.current = null, X.current = !1;
2608
+ a.current = !1, De(!1), Ne(!1), ye(null), oe.current = null, B.current = null, G.current = !1;
2594
2609
  const D = j.current;
2595
2610
  if (!D) return;
2596
2611
  let P = null;
2597
2612
  return (async () => {
2598
2613
  try {
2599
- let $, O, ie, we;
2614
+ let W, O, ie, ge;
2600
2615
  if (s)
2601
- $ = s, O = o, ie = c ?? $e(O);
2602
- else if (he)
2603
- W.current?.("loadFace"), $ = Ot(he), O = o, ie = c ?? $e(O);
2616
+ W = s, O = o, ie = c ?? He(O);
2617
+ else if (we)
2618
+ H.current?.("loadFace"), W = Lt(we), O = o, ie = c ?? He(O);
2604
2619
  else {
2605
- W.current?.("getAiTwin");
2606
- const K = await ht(
2607
- qn(t),
2620
+ H.current?.("getAiTwin");
2621
+ const K = await wt(
2622
+ jn(t),
2608
2623
  3e4,
2609
2624
  "getAiTwin"
2610
2625
  );
2611
2626
  if (h) return;
2612
2627
  if (!K.faceId?.trim())
2613
2628
  throw new Error("getAiTwin returned no faceId");
2614
- O = K.ttsEngineId, ie = c ?? K.voiceId ?? $e(O), we = K.knowledgeContextId?.trim() || void 0, $ = Ot(K.faceId);
2629
+ O = K.ttsEngineId, ie = c ?? K.voiceId ?? He(O), ge = K.knowledgeContextId?.trim() || void 0, W = Lt(K.faceId);
2615
2630
  }
2616
- ae.current = { ttsEngineId: O, voiceId: ie, personaId: we }, tr($), H.current = ds(), P = $s(D, {
2631
+ oe.current = { ttsEngineId: O, voiceId: ie, personaId: ge }, rr(W), B.current = ms(), P = Ws(D, {
2617
2632
  onStatus: (K) => {
2618
- h || W.current?.(K);
2633
+ h || H.current?.(K);
2619
2634
  },
2620
2635
  onError: (K) => {
2621
- h || le(K);
2636
+ h || fe(K);
2622
2637
  },
2623
- shouldAcceptLiveFrame: () => Se(
2638
+ shouldAcceptLiveFrame: () => Ee(
2624
2639
  q.current,
2625
2640
  Q.current
2626
- ).isSpeaking() && !b.current
2627
- }), M.current = P, W.current?.("auth");
2628
- const ve = ke.current ?? i ?? await ht(ft(), 3e4, "getAuthToken");
2641
+ ).isSpeaking() && !T.current
2642
+ }), M.current = P, H.current?.("auth");
2643
+ const Se = ve.current ?? i ?? await wt(dt(), 3e4, "getAuthToken");
2629
2644
  if (h) return;
2630
- ke.current = ve, q.current.setDeveloperToken(ve), q.current.setTtsEngineId(O);
2631
- const Ne = tt() ? await xe() : void 0;
2645
+ ve.current = Se, q.current.setDeveloperToken(Se), q.current.setTtsEngineId(O);
2646
+ const $e = nt() ? await Me() : void 0;
2632
2647
  if (h) return;
2633
- W.current?.("loadAssets");
2634
- const ne = await ht(
2635
- P.loadAssets(Ne),
2648
+ H.current?.("loadAssets");
2649
+ const ne = await wt(
2650
+ P.loadAssets($e),
2636
2651
  18e4,
2637
2652
  "load face assets"
2638
2653
  );
2639
- if (!h && ne.width > 0 && ne.height > 0 && (p.current = ne, Ct(ne)), h) return;
2640
- C.current = P.getVisemeAtlasPaths(), a.current = !0, Ke(!0), G.current?.(), P.renderSilOnly().then(() => {
2641
- h || W.current?.("sil");
2654
+ if (!h && ne.width > 0 && ne.height > 0 && (p.current = ne, Pt(ne)), h) return;
2655
+ x.current = P.getVisemeAtlasPaths(), a.current = !0, De(!0), z.current?.(), P.renderSilOnly().then(() => {
2656
+ h || H.current?.("sil");
2642
2657
  }), (async () => {
2643
2658
  try {
2644
- const K = await Wr(Ne);
2645
- if (await H.current.load(K), h) return;
2646
- X.current = !0, Le(!0), pe(V.current), H.current.setActive(!0);
2647
- const de = H.current.getVideo();
2648
- await Gt(
2659
+ const K = await Hr($e);
2660
+ if (await B.current.load(K), h) return;
2661
+ G.current = !0, Ne(!0), pe($.current), B.current.setActive(!0);
2662
+ const me = B.current.getVideo();
2663
+ await Yt(
2649
2664
  D,
2650
- de,
2665
+ me,
2651
2666
  null,
2652
2667
  void 0,
2653
2668
  p.current
2654
- ), h || W.current?.("idle");
2669
+ ), h || H.current?.("idle");
2655
2670
  } catch (K) {
2656
2671
  if (h) return;
2657
- X.current = !1, Le(!1), console.warn("[AiTwin] Idle video unavailable:", K);
2672
+ G.current = !1, Ne(!1), console.warn("[AiTwin] Idle video unavailable:", K);
2658
2673
  }
2659
2674
  })();
2660
- } catch ($) {
2675
+ } catch (W) {
2661
2676
  if (h) return;
2662
- if ($ instanceof wt) {
2663
- le($.message);
2677
+ if (W instanceof gt) {
2678
+ fe(W.message);
2664
2679
  return;
2665
2680
  }
2666
- le($ instanceof Error ? $.message : "Failed to load AI twin");
2681
+ fe(W instanceof Error ? W.message : "Failed to load AI twin");
2667
2682
  }
2668
2683
  })(), () => {
2669
- h = !0, H.current?.dispose(), P?.dispose(), M.current = null;
2684
+ h = !0, B.current?.dispose(), P?.dispose(), M.current = null;
2670
2685
  };
2671
- }, [En, s, he, t, o, c, i, xe, le]), Me(() => {
2686
+ }, [ct, s, we, t, o, c, i, Me, fe]), Be(() => {
2672
2687
  const h = { current: !1 }, D = () => {
2673
- const P = j.current, $ = M.current, O = Se(
2688
+ const P = j.current, W = M.current, O = Ee(
2674
2689
  q.current,
2675
2690
  Q.current
2676
2691
  );
2677
- if (!P || !$ || !oe) {
2692
+ if (!P || !W || !ee) {
2678
2693
  g.current = requestAnimationFrame(D);
2679
2694
  return;
2680
2695
  }
2681
- const ie = O.isSpeaking(), we = ie && !Y.current, ve = Y.current && !ie;
2682
- we && (ee(), ue(), b.current = !1, A.current = !1, pe(V.current), k.current = 0, B.current = "sil", z.current = 0, H.current?.setActive(!1)), ve && (U.current.reset(), H.current?.setActive(!1), se());
2683
- const Ne = ve || b.current || F.current;
2696
+ const ie = O.isSpeaking(), ge = ie && !Z.current, Se = Z.current && !ie;
2697
+ ge && (X(), ue(), T.current = !1, A.current = !1, pe($.current), k.current = 0, F.current = "sil", J.current = 0, B.current?.setActive(!1)), Se && (N.current.reset(), B.current?.setActive(!1), se());
2698
+ const $e = Se || T.current || L.current;
2684
2699
  if (ie) {
2685
- X.current && H.current?.setActive(!1);
2700
+ G.current && B.current?.setActive(!1);
2686
2701
  const ne = O.getVisemeQueue(), K = O.getPlaybackElapsedMs();
2687
- z.current = K;
2688
- const de = ne.length > 0 ? rt(ne, K) : "sil";
2689
- de !== "sil" && (B.current = de);
2690
- const Ce = gs(
2702
+ J.current = K;
2703
+ const me = ne.length > 0 ? st(ne, K) : "sil";
2704
+ me !== "sil" && (F.current = me);
2705
+ const Pe = _s(
2691
2706
  K,
2692
2707
  O.getSentenceEmotions(),
2693
2708
  O.getWordQueue(),
2694
2709
  O.getStreamMood()
2695
2710
  );
2696
- U.current.setTargetEmotion(Ce), U.current.setTargetEyebrow(
2697
- ls(
2711
+ N.current.setTargetEmotion(Pe), N.current.setTargetEyebrow(
2712
+ fs(
2698
2713
  K,
2699
2714
  O.getWordQueue(),
2700
- Dt(Ce)
2715
+ xt(Pe)
2701
2716
  )
2702
- ), U.current.advance(performance.now());
2703
- const ct = U.current.getExpressionPath(), ut = U.current.getDrawKey();
2704
- Fs(
2717
+ ), N.current.advance(performance.now());
2718
+ const ut = N.current.getExpressionPath(), lt = N.current.getDrawKey();
2719
+ Ls(
2705
2720
  P,
2706
2721
  ne,
2707
2722
  K,
2708
- ct,
2709
2723
  ut,
2710
- V.current,
2711
- (lt, bn, Tn, An) => $.drawLiveFrame(lt, bn, Tn, An),
2712
- (lt) => W.current?.(lt),
2713
- C.current
2724
+ lt,
2725
+ $.current,
2726
+ (ft, An, In, Rn) => W.drawLiveFrame(ft, An, In, Rn),
2727
+ (ft) => H.current?.(ft),
2728
+ x.current
2714
2729
  );
2715
- } else if (!Ne && X.current && H.current) {
2716
- const ne = H.current, K = ne.getVideo();
2717
- K.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? (ne.setActive(!0), h.current || (h.current = !0, Gt(
2730
+ } else if (!$e && G.current && B.current) {
2731
+ const ne = B.current, K = ne.getVideo();
2732
+ K.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? (ne.setActive(!0), h.current || (h.current = !0, Yt(
2718
2733
  P,
2719
2734
  K,
2720
2735
  null,
2721
2736
  void 0,
2722
2737
  p.current,
2723
- () => !O.isSpeaking() && !b.current && !F.current
2724
- ).then(() => W.current?.("idle")).finally(() => {
2738
+ () => !O.isSpeaking() && !T.current && !L.current
2739
+ ).then(() => H.current?.("idle")).finally(() => {
2725
2740
  h.current = !1;
2726
- }))) : Yt(
2741
+ }))) : Xt(
2727
2742
  P,
2728
2743
  null,
2729
2744
  "__sil__",
2730
- V.current,
2731
- (de, Ce, ct, ut) => $.drawLiveFrame(de, Ce, ct, ut),
2732
- (de) => W.current?.(de)
2745
+ $.current,
2746
+ (me, Pe, ut, lt) => W.drawLiveFrame(me, Pe, ut, lt),
2747
+ (me) => H.current?.(me)
2733
2748
  );
2734
- } else Ne || Yt(
2749
+ } else $e || Xt(
2735
2750
  P,
2736
2751
  null,
2737
2752
  "__sil__",
2738
- V.current,
2739
- (ne, K, de, Ce) => $.drawLiveFrame(ne, K, de, Ce),
2740
- (ne) => W.current?.(ne)
2753
+ $.current,
2754
+ (ne, K, me, Pe) => W.drawLiveFrame(ne, K, me, Pe),
2755
+ (ne) => H.current?.(ne)
2741
2756
  );
2742
- Y.current = ie, g.current = requestAnimationFrame(D);
2757
+ Z.current = ie, g.current = requestAnimationFrame(D);
2743
2758
  };
2744
2759
  return g.current = requestAnimationFrame(D), () => {
2745
- cancelAnimationFrame(g.current), ee(), ue(), q.current.stop(), Q.current?.stop();
2760
+ cancelAnimationFrame(g.current), X(), ue(), q.current.stop(), Q.current?.stop();
2746
2761
  };
2747
2762
  }, [
2748
- oe,
2749
- ot,
2750
- se,
2751
2763
  ee,
2764
+ ke,
2765
+ se,
2766
+ X,
2752
2767
  ue
2753
- ]), Dn(
2754
- N,
2768
+ ]), xn(
2769
+ V,
2755
2770
  () => ({
2756
2771
  speakText: async (h, D) => {
2757
2772
  const P = h.trim();
2758
2773
  if (!P) return;
2759
- const $ = M.current;
2760
- if (!$ || !a.current && !oe)
2774
+ const W = M.current;
2775
+ if (!W || !a.current && !ee)
2761
2776
  throw new Error("AI twin is not ready");
2762
- const { ttsEngineId: O, voiceId: ie } = je(D);
2763
- ye(null), I.current += 1, ee(), ue(), b.current = !1, A.current = !1, B.current = "sil", z.current = 0, pe(V.current), U.current.reset(), Y.current = !1;
2777
+ const { ttsEngineId: O, voiceId: ie } = ze(D);
2778
+ ye(null), I.current += 1, X(), ue(), T.current = !1, A.current = !1, F.current = "sil", J.current = 0, pe($.current), N.current.reset(), Z.current = !1;
2764
2779
  try {
2765
- X.current ? (H.current?.setActive(!1), H.current?.restart(), pe(V.current)) : await $.renderSilOnly(), await q.current.speak(P, {
2780
+ G.current ? (B.current?.setActive(!1), B.current?.restart(), pe($.current)) : await W.renderSilOnly(), await q.current.speak(P, {
2766
2781
  voiceId: ie,
2767
2782
  speakingRate: D?.speakingRate ?? l,
2768
2783
  ttsEngineId: O
2769
2784
  });
2770
- } catch (we) {
2771
- throw le(we instanceof Error ? we.message : "TTS failed"), we;
2785
+ } catch (ge) {
2786
+ throw fe(ge instanceof Error ? ge.message : "TTS failed"), ge;
2772
2787
  }
2773
2788
  },
2774
2789
  stop: () => {
2775
- I.current += 1, ee(), ue(), b.current = !1, A.current = !1, q.current.stop(), Q.current?.stop(), pe(V.current), Y.current = !1, se();
2790
+ I.current += 1, X(), ue(), T.current = !1, A.current = !1, q.current.stop(), Q.current?.stop(), pe($.current), Z.current = !1, se();
2776
2791
  },
2777
2792
  setTtsEngineId: (h) => {
2778
- q.current.setTtsEngineId(h), Q.current?.setTtsEngineId(h), ae.current && (ae.current.ttsEngineId = h);
2793
+ q.current.setTtsEngineId(h), Q.current?.setTtsEngineId(h), oe.current && (oe.current.ttsEngineId = h);
2779
2794
  },
2780
2795
  renderViseme: async (h, D) => {
2781
- const P = M.current, $ = j.current;
2782
- if (!P || !$ || !a.current)
2796
+ const P = M.current, W = j.current;
2797
+ if (!P || !W || !a.current)
2783
2798
  throw new Error("AI twin is not ready");
2784
- await P.renderViseme($, h, {
2799
+ await P.renderViseme(W, h, {
2785
2800
  from: D?.from,
2786
2801
  transitionDurationMs: D?.transitionDurationMs,
2787
2802
  gapMs: D?.gapMs,
2788
- onStatus: (O) => W.current?.(O)
2803
+ onStatus: (O) => H.current?.(O)
2789
2804
  });
2790
2805
  },
2791
2806
  isReady: () => a.current,
2792
- getStatus: () => Z,
2807
+ getStatus: () => ce,
2793
2808
  connect: async (h = {}) => {
2794
2809
  ye(null);
2795
2810
  try {
2796
2811
  let D = h.authToken?.trim();
2797
- D || (D = ke.current ?? i ?? await ft(), ke.current = D);
2798
- const P = h.voiceId?.trim() ?? c ?? ae.current?.voiceId, $ = h.personaId?.trim() ?? ae.current?.personaId, O = ze();
2812
+ D || (D = ve.current ?? i ?? await dt(), ve.current = D);
2813
+ const P = h.voiceId?.trim() ?? c ?? oe.current?.voiceId, W = h.personaId?.trim() ?? oe.current?.personaId, O = Ge();
2799
2814
  await O.unlockAudio(), await O.connect({
2800
2815
  ...h,
2801
2816
  authToken: D,
2802
2817
  voiceId: P,
2803
- personaId: $,
2818
+ personaId: W,
2804
2819
  speakingRate: h.speakingRate ?? l
2805
2820
  });
2806
2821
  } catch (D) {
2807
- throw le(
2822
+ throw fe(
2808
2823
  D instanceof Error ? D.message : "Voice connect failed"
2809
2824
  ), D;
2810
2825
  }
2811
2826
  },
2812
2827
  disconnect: async () => {
2813
2828
  const h = Q.current;
2814
- h && (I.current += 1, ee(), ue(), b.current = !1, A.current = !1, pe(V.current), Y.current = !1, await h.disconnect(), se());
2829
+ h && (I.current += 1, X(), ue(), T.current = !1, A.current = !1, pe($.current), Z.current = !1, await h.disconnect(), se());
2815
2830
  },
2816
2831
  isConnected: () => Q.current?.isConnected() ?? !1
2817
2832
  }),
2818
2833
  [
2819
- oe,
2834
+ ee,
2820
2835
  l,
2821
2836
  i,
2822
2837
  c,
2823
- ee,
2838
+ X,
2824
2839
  ue,
2825
2840
  se,
2826
- le,
2827
- je,
2841
+ fe,
2828
2842
  ze,
2829
- Z
2843
+ Ge,
2844
+ ce
2830
2845
  ]
2831
- ), /* @__PURE__ */ In("div", { className: f, style: { ...Hs, ...w }, children: [
2832
- /* @__PURE__ */ Mt(
2846
+ ), /* @__PURE__ */ Dn("div", { className: f, style: { ...qs, ...w }, children: [
2847
+ /* @__PURE__ */ Bt(
2833
2848
  "canvas",
2834
2849
  {
2835
2850
  ref: j,
2836
2851
  width: at.width,
2837
2852
  height: at.height,
2838
- style: { ...qs, ...y },
2853
+ style: { ...Ks, ...y },
2839
2854
  "aria-label": t ? `AI twin ${t}` : "AI twin face"
2840
2855
  }
2841
2856
  ),
2842
- _ && te ? /* @__PURE__ */ Mt("div", { style: Ks, children: te }) : null
2857
+ _ && te ? /* @__PURE__ */ Bt("div", { style: js, children: te }) : null
2843
2858
  ] });
2844
- }), js = "thumbnail.webp";
2845
- function ni(e, t = St) {
2859
+ }), zs = "thumbnail.webp";
2860
+ function ri(e, t = Et) {
2846
2861
  const n = e.trim();
2847
2862
  if (!n)
2848
2863
  throw new Error("faceId is required");
2849
- return `${t.replace(/\/$/, "")}/${n}/${js}`;
2864
+ return `${t.replace(/\/$/, "")}/${n}/${zs}`;
2850
2865
  }
2851
- const zs = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]);
2852
- function Gs(e = ".png") {
2866
+ const Gs = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]);
2867
+ function Qs(e = ".png") {
2853
2868
  const t = e.toLowerCase();
2854
- return zs.has(t) ? `source${t}` : "source.png";
2869
+ return Gs.has(t) ? `source${t}` : "source.png";
2855
2870
  }
2856
- function ri(e, t = St, n = ".png") {
2871
+ function si(e, t = Et, n = ".png") {
2857
2872
  const r = e.trim();
2858
2873
  if (!r)
2859
2874
  throw new Error("faceId is required");
2860
- return `${t.replace(/\/$/, "")}/${r}/${Gs(n)}`;
2875
+ return `${t.replace(/\/$/, "")}/${r}/${Qs(n)}`;
2861
2876
  }
2862
2877
  export {
2863
- js as AI_TWIN_THUMBNAIL_FILENAME,
2864
- ti as AiTwin,
2865
- wt as AiTwinNotFoundError,
2866
- Be as DEFAULT_TTS_ENGINE_ID,
2867
- un as MIC_SAMPLE_RATE,
2868
- cr as OCULUS_VISEME_IDS,
2869
- ln as PLAYBACK_SAMPLE_RATE,
2870
- Tt as SPEAKING_RATE_MAX,
2871
- bt as SPEAKING_RATE_MIN,
2872
- Oe as TTS_ENGINE_CARTESIA,
2873
- tn as TTS_ENGINE_GOOGLE,
2874
- Et as TTS_ENGINE_INWORLD,
2875
- ei as VISEME_IDS,
2876
- cn as VISEME_TEST_CARTESIA_VOICE_ID,
2877
- st as VISEME_TEST_SPEAKING_RATE,
2878
- an as VISEME_TEST_VOICE_ID,
2879
- Gs as aiTwinSourceFilename,
2880
- Cr as buildVoiceWebSocketUrl,
2881
- Nt as createAvatarTtsLipsyncController,
2882
- Br as createRealtimeVoiceLipsyncController,
2883
- Ot as faceAssetUrls,
2884
- qn as fetchAiTwin,
2885
- ft as fetchDevAuthToken,
2886
- ri as getAiTwinSourceUrl,
2887
- ni as getAiTwinThumbnailUrl,
2888
- lr as normalizeOculusViseme,
2889
- er as resolveDirectFaceId,
2890
- rt as resolveVisemeAtTime,
2891
- Zs as resolveWordAtTime,
2892
- tr as setActiveTwinAssets
2878
+ zs as AI_TWIN_THUMBNAIL_FILENAME,
2879
+ ni as AiTwin,
2880
+ gt as AiTwinNotFoundError,
2881
+ Oe as DEFAULT_TTS_ENGINE_ID,
2882
+ dn as MIC_SAMPLE_RATE,
2883
+ lr as OCULUS_VISEME_IDS,
2884
+ mn as PLAYBACK_SAMPLE_RATE,
2885
+ It as SPEAKING_RATE_MAX,
2886
+ At as SPEAKING_RATE_MIN,
2887
+ Le as TTS_ENGINE_CARTESIA,
2888
+ rn as TTS_ENGINE_GOOGLE,
2889
+ bt as TTS_ENGINE_INWORLD,
2890
+ ti as VISEME_IDS,
2891
+ fn as VISEME_TEST_CARTESIA_VOICE_ID,
2892
+ it as VISEME_TEST_SPEAKING_RATE,
2893
+ ln as VISEME_TEST_VOICE_ID,
2894
+ Qs as aiTwinSourceFilename,
2895
+ Mr as buildVoiceWebSocketUrl,
2896
+ $t as createAvatarTtsLipsyncController,
2897
+ Fr as createRealtimeVoiceLipsyncController,
2898
+ Lt as faceAssetUrls,
2899
+ jn as fetchAiTwin,
2900
+ dt as fetchDevAuthToken,
2901
+ si as getAiTwinSourceUrl,
2902
+ ri as getAiTwinThumbnailUrl,
2903
+ dr as normalizeOculusViseme,
2904
+ nr as resolveDirectFaceId,
2905
+ st as resolveVisemeAtTime,
2906
+ ei as resolveWordAtTime,
2907
+ rr as setActiveTwinAssets
2893
2908
  };