@streamoji/aitwin 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/aitwin.js CHANGED
@@ -1,47 +1,47 @@
1
- import { jsxs as kn, jsx as Rt } from "react/jsx-runtime";
2
- import { forwardRef as vn, useRef as L, useState as Pe, useCallback as oe, useEffect as be, useMemo as Dt, useImperativeHandle as bn } from "react";
3
- import { PipecatClient as Tn } from "@pipecat-ai/client-js";
4
- import { WebSocketTransport as An, DailyMediaManager as In } from "@pipecat-ai/websocket-transport";
5
- const Rn = "https://pub-607ad1fc22e2400eb57d17240aab857c.r2.dev", Qt = {
6
- publicBase: Rn
7
- }, Dn = "0.2.5", Cn = {
8
- version: Dn
9
- }, Mn = {}, Ae = "https://ai.streamoji.com", ft = `${Qt.publicBase}/custom-faces`, xn = `${Qt.publicBase}/aitwin-workers/v${Cn.version}/visemeDiffPreview.worker.js`;
10
- function Pn(e) {
1
+ import { jsxs as vn, jsx as Rt } from "react/jsx-runtime";
2
+ import { forwardRef as bn, useRef as O, useState as Be, useCallback as ae, useEffect as ve, useMemo as Dt, useImperativeHandle as Tn } from "react";
3
+ import { PipecatClient as An } from "@pipecat-ai/client-js";
4
+ import { WebSocketTransport as In, DailyMediaManager as Rn } from "@pipecat-ai/websocket-transport";
5
+ const Dn = "https://pub-607ad1fc22e2400eb57d17240aab857c.r2.dev", Qt = {
6
+ publicBase: Dn
7
+ }, Cn = "0.2.7", xn = {
8
+ version: Cn
9
+ }, Mn = {}, Te = "https://ai.streamoji.com", ft = `${Qt.publicBase}/custom-faces`, Pn = `${Qt.publicBase}/aitwin-workers/v${xn.version}/visemeDiffPreview.worker.js`;
10
+ function Bn(e) {
11
11
  if (e) return e;
12
12
  const t = typeof import.meta < "u" ? Mn?.VITE_AITWIN_WORKER_URL : void 0;
13
- return t?.trim() ? t.trim() : xn;
13
+ return t?.trim() ? t.trim() : Pn;
14
14
  }
15
- const Bn = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", Xt = "eng_a7f2b9c1", dt = "eng_d4e8f3a2", Re = "eng_c9b1e6d4", Ie = Re, Ln = /* @__PURE__ */ new Set([
15
+ const Ln = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", Xt = "eng_a7f2b9c1", dt = "eng_d4e8f3a2", Ie = "eng_c9b1e6d4", Ae = Ie, On = /* @__PURE__ */ new Set([
16
16
  dt,
17
- Re
17
+ Ie
18
18
  ]), Zt = {
19
19
  [Xt]: "oculus_direct",
20
- [Re]: "oculus_direct",
20
+ [Ie]: "oculus_direct",
21
21
  [dt]: "inworld_word"
22
22
  }, Ct = {
23
23
  google: Xt,
24
24
  inworld: dt,
25
- cartesia: Re
25
+ cartesia: Ie
26
26
  };
27
- function On(e) {
28
- return Zt[e];
29
- }
30
27
  function Fn(e) {
31
- return e === Re;
28
+ return Zt[e];
32
29
  }
33
30
  function Un(e) {
31
+ return e === Ie;
32
+ }
33
+ function Nn(e) {
34
34
  if (e.ttsEngineId && e.ttsEngineId in Zt)
35
35
  return e.ttsEngineId;
36
36
  const t = e.tts?.toLowerCase();
37
- return t && t in Ct ? Ct[t] : Ie;
37
+ return t && t in Ct ? Ct[t] : Ae;
38
38
  }
39
39
  class st extends Error {
40
40
  constructor(t = "AI twin not found") {
41
41
  super(t), this.name = "AiTwinNotFoundError";
42
42
  }
43
43
  }
44
- async function Nn(e, t = Bn) {
44
+ async function Vn(e, t = Ln) {
45
45
  const n = new URL(t);
46
46
  n.searchParams.set("id", e);
47
47
  const r = await fetch(n.toString());
@@ -55,21 +55,21 @@ async function Nn(e, t = Bn) {
55
55
  const { tts: i, ...o } = s.data;
56
56
  return {
57
57
  ...o,
58
- ttsEngineId: Un(s.data)
58
+ ttsEngineId: Nn(s.data)
59
59
  };
60
60
  }
61
- const Vn = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", $n = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", Wn = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", Hn = "6TNvp3SCs4Og0a1ijm9TommXLql1", qn = "Swaraj Mali";
61
+ const $n = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", Wn = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", Hn = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", qn = "6TNvp3SCs4Og0a1ijm9TommXLql1", Kn = "Swaraj Mali";
62
62
  async function nt() {
63
- const e = await fetch(Vn, {
63
+ const e = await fetch($n, {
64
64
  method: "POST",
65
65
  headers: {
66
66
  "Content-Type": "application/json",
67
- "Client-Id": $n,
68
- "Client-Secret": Wn
67
+ "Client-Id": Wn,
68
+ "Client-Secret": Hn
69
69
  },
70
70
  body: JSON.stringify({
71
- userId: Hn,
72
- userName: qn
71
+ userId: qn,
72
+ userName: Kn
73
73
  })
74
74
  });
75
75
  if (!e.ok)
@@ -79,7 +79,7 @@ async function nt() {
79
79
  throw new Error("getAuthToken returned no token");
80
80
  return n;
81
81
  }
82
- async function Kn(e, t = Ae) {
82
+ async function jn(e, t = Te) {
83
83
  const n = await fetch(`${t.replace(/\/$/, "")}/api/session-value`, {
84
84
  headers: { Authorization: `Bearer ${e}` }
85
85
  });
@@ -89,7 +89,7 @@ async function Kn(e, t = Ae) {
89
89
  if (!r.value) throw new Error("Session value response missing value");
90
90
  return r;
91
91
  }
92
- function jn(e) {
92
+ function Gn(e) {
93
93
  const t = e.trim();
94
94
  if (t.length % 2 !== 0) throw new Error("Invalid hex key");
95
95
  const n = new Uint8Array(t.length / 2);
@@ -100,17 +100,17 @@ function jn(e) {
100
100
  function Ne(e) {
101
101
  return Uint8Array.from(e);
102
102
  }
103
- function Gn(e, t) {
103
+ function zn(e, t) {
104
104
  const n = new Uint8Array(e.length + t.length);
105
105
  return n.set(e, 0), n.set(t, e.length), n;
106
106
  }
107
- async function zn(e, t) {
107
+ async function Yn(e, t) {
108
108
  if (!t) throw new Error("Asset key is required for encrypted assets");
109
109
  if (e.byteLength < 28)
110
110
  throw new Error("Encrypted payload too small");
111
- const n = new Uint8Array(e), r = Ne(n.subarray(0, 12)), s = Ne(n.subarray(12, 28)), i = Ne(n.subarray(28)), o = Ne(Gn(i, s)), a = await crypto.subtle.importKey(
111
+ const n = new Uint8Array(e), r = Ne(n.subarray(0, 12)), s = Ne(n.subarray(12, 28)), i = Ne(n.subarray(28)), o = Ne(zn(i, s)), a = await crypto.subtle.importKey(
112
112
  "raw",
113
- jn(t),
113
+ Gn(t),
114
114
  { name: "AES-GCM" },
115
115
  !1,
116
116
  ["decrypt"]
@@ -133,21 +133,21 @@ function He(e) {
133
133
  const s = Ve(t) ? t : Ve(n) ? n : t;
134
134
  return { twinBase: s, binBase: s, encrypted: !0 };
135
135
  }
136
- function De(e) {
136
+ function Re(e) {
137
137
  return He(e).encrypted;
138
138
  }
139
- function Mt(e, t = ft) {
139
+ function xt(e, t = ft) {
140
140
  const n = `${t.replace(/\/$/, "")}/${e}`;
141
141
  return { twinBase: n, binBase: n, encrypted: !0 };
142
142
  }
143
- function Yn(e, t) {
143
+ function Jn(e, t) {
144
144
  return (e ?? t)?.trim() || void 0;
145
145
  }
146
- function Jn(e) {
146
+ function Qn(e) {
147
147
  it = He(e);
148
148
  for (const t of ot) t();
149
149
  }
150
- function Qn(e, t) {
150
+ function Xn(e, t) {
151
151
  const n = typeof globalThis.location < "u" ? globalThis.location.href : void 0;
152
152
  if (!n) return He(e);
153
153
  const r = (s) => {
@@ -163,38 +163,38 @@ function Qn(e, t) {
163
163
  encrypted: e.encrypted
164
164
  });
165
165
  }
166
- function Se() {
166
+ function Ee() {
167
167
  if (!it)
168
168
  throw new Error("Twin assets not configured; call setActiveTwinAssets first");
169
169
  return it;
170
170
  }
171
- function Xn(e) {
171
+ function Zn(e) {
172
172
  return ot.add(e), () => ot.delete(e);
173
173
  }
174
- function xt() {
175
- const e = Se();
176
- return De(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
177
- }
178
- function Zn() {
179
- const e = Se();
180
- return De(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
174
+ function Mt() {
175
+ const e = Ee();
176
+ return Re(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
181
177
  }
182
178
  function er() {
183
- const e = Se();
184
- return De(e) ? e.binBase : e.twinBase;
185
- }
186
- function je() {
187
- return De(Se());
179
+ const e = Ee();
180
+ return Re(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
188
181
  }
189
182
  function tr() {
190
- const e = Se();
191
- return De(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
183
+ const e = Ee();
184
+ return Re(e) ? e.binBase : e.twinBase;
185
+ }
186
+ function je() {
187
+ return Re(Ee());
192
188
  }
193
189
  function nr() {
194
- const e = Se();
195
- return De(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
190
+ const e = Ee();
191
+ return Re(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
196
192
  }
197
- function rr(e) {
193
+ function rr() {
194
+ const e = Ee();
195
+ return Re(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
196
+ }
197
+ function sr(e) {
198
198
  const t = e.split(/\r?\n/);
199
199
  let n = "", r = "";
200
200
  for (const i of t)
@@ -209,7 +209,7 @@ function rr(e) {
209
209
  }
210
210
  return { event: n, data: s };
211
211
  }
212
- const sr = [
212
+ const ir = [
213
213
  "aa",
214
214
  "CH",
215
215
  "DD",
@@ -225,14 +225,14 @@ const sr = [
225
225
  "kk",
226
226
  "nn",
227
227
  "sil"
228
- ], ir = new Map(
229
- sr.map((e) => [e.toLowerCase(), e])
228
+ ], or = new Map(
229
+ ir.map((e) => [e.toLowerCase(), e])
230
230
  );
231
- function or(e) {
231
+ function ar(e) {
232
232
  const t = (e ?? "").trim();
233
- return t ? ir.get(t.toLowerCase()) ?? "sil" : "sil";
233
+ return t ? or.get(t.toLowerCase()) ?? "sil" : "sil";
234
234
  }
235
- const ar = {
235
+ const cr = {
236
236
  aei: ["aa", "E", "I"],
237
237
  o: ["O", "U"],
238
238
  ee: ["I"],
@@ -244,12 +244,12 @@ const ar = {
244
244
  qw: ["U", "O"],
245
245
  cdgknstxyz: ["DD", "SS", "kk", "CH"]
246
246
  };
247
- function cr(e) {
247
+ function ur(e) {
248
248
  if (!e) return ["sil"];
249
249
  const t = e.toLowerCase();
250
- return ar[t] ?? ["sil"];
250
+ return cr[t] ?? ["sil"];
251
251
  }
252
- function ur(e, t) {
252
+ function lr(e, t) {
253
253
  const n = e.word.length;
254
254
  if (n <= 0) return 0;
255
255
  const r = e.wduration;
@@ -261,11 +261,11 @@ function Ge(e, t) {
261
261
  const n = Math.max(0, Math.min(e.length - 1, t));
262
262
  return e[n] ?? "";
263
263
  }
264
- function lr(e, t) {
264
+ function fr(e, t) {
265
265
  const n = e.toLowerCase(), r = Ge(n, t), s = n.slice(Math.max(0, t - 1), t + 2);
266
266
  return r === "i" || r === "y" ? "I" : s.includes("ee") || r === "e" || n.includes("ea") ? "E" : "aa";
267
267
  }
268
- function fr(e, t) {
268
+ function dr(e, t) {
269
269
  const n = e.toLowerCase(), r = n.slice(
270
270
  Math.max(0, t - 1),
271
271
  Math.min(n.length, t + 3)
@@ -274,7 +274,7 @@ function fr(e, t) {
274
274
  const s = Ge(n, t);
275
275
  return s === "u" || s === "w" ? "U" : "O";
276
276
  }
277
- function dr(e, t) {
277
+ function hr(e, t) {
278
278
  const n = e.toLowerCase(), r = n.slice(Math.max(0, t - 2), t + 1);
279
279
  if (/qu/.test(r)) return "U";
280
280
  const s = n.slice(
@@ -295,7 +295,7 @@ const $e = {
295
295
  x: "CH",
296
296
  j: "CH"
297
297
  };
298
- function hr(e, t) {
298
+ function mr(e, t) {
299
299
  const n = e.toLowerCase(), r = Ge(n, t);
300
300
  if ($e[r]) return $e[r];
301
301
  for (let s = 0; s < n.length; s++) {
@@ -304,37 +304,37 @@ function hr(e, t) {
304
304
  }
305
305
  return "DD";
306
306
  }
307
- function mr(e, t, n) {
308
- const r = cr(e);
307
+ function wr(e, t, n) {
308
+ const r = ur(e);
309
309
  if (r.length === 1) return r[0];
310
310
  const s = t.trim();
311
311
  if (!s) return r[0];
312
312
  const i = (e ?? "").toLowerCase(), o = Math.max(0, n);
313
313
  switch (i) {
314
314
  case "aei":
315
- return lr(s, o);
316
- case "o":
317
315
  return fr(s, o);
318
- case "qw":
316
+ case "o":
319
317
  return dr(s, o);
320
- case "cdgknstxyz":
318
+ case "qw":
321
319
  return hr(s, o);
320
+ case "cdgknstxyz":
321
+ return mr(s, o);
322
322
  default:
323
323
  return r[0];
324
324
  }
325
325
  }
326
- const wr = 24e3;
327
- function gr(e) {
326
+ const gr = 24e3;
327
+ function _r(e) {
328
328
  let t = e.trim();
329
329
  const n = t.indexOf(",");
330
330
  t.startsWith("data:") && n >= 0 && (t = t.slice(n + 1)), t = t.replace(/\s+/g, "").replace(/-/g, "+").replace(/_/g, "/");
331
331
  const r = t.length % 4;
332
332
  return r !== 0 && (t += "=".repeat(4 - r)), t;
333
333
  }
334
- function _r(e) {
334
+ function pr(e) {
335
335
  return e.length >= 4 && e[0] === 82 && e[1] === 73 && e[2] === 70 && e[3] === 70;
336
336
  }
337
- function Pt(e, t, n = wr) {
337
+ function Pt(e, t, n = gr) {
338
338
  const r = t.byteOffset % 2 === 0 ? t : t.slice(), s = new Int16Array(
339
339
  r.buffer,
340
340
  r.byteOffset,
@@ -345,15 +345,15 @@ function Pt(e, t, n = wr) {
345
345
  const o = e.createBuffer(1, i.length, n);
346
346
  return o.copyToChannel(i, 0), o;
347
347
  }
348
- function pr(e) {
349
- const t = gr(e), n = window.atob(t), r = new Uint8Array(n.length);
348
+ function yr(e) {
349
+ const t = _r(e), n = window.atob(t), r = new Uint8Array(n.length);
350
350
  for (let s = 0; s < n.length; s++)
351
351
  r[s] = n.charCodeAt(s);
352
352
  return r;
353
353
  }
354
- async function yr(e, t) {
355
- const n = pr(t);
356
- if (_r(n)) {
354
+ async function Er(e, t) {
355
+ const n = yr(t);
356
+ if (pr(n)) {
357
357
  const r = n.buffer.slice(
358
358
  n.byteOffset,
359
359
  n.byteOffset + n.byteLength
@@ -378,7 +378,7 @@ function Bt(e) {
378
378
  t = Math.max(t, n.vtime + n.vduration);
379
379
  return t;
380
380
  }
381
- function Er(e, t) {
381
+ function Sr(e, t) {
382
382
  for (const n of e)
383
383
  if (t >= n.wtime && t < n.wtime + n.wduration)
384
384
  return n;
@@ -402,23 +402,23 @@ function en(e, t) {
402
402
  }, R = () => {
403
403
  !f || i || r.length > 0 || n.length > 0 || (o = !1, d(), e.onSpeakingDone(), e.onNotify());
404
404
  }, q = (g) => {
405
- const M = Bt(g);
406
- if (M <= 0) {
405
+ const x = Bt(g);
406
+ if (x <= 0) {
407
407
  e.onSpeakingDone(), e.onNotify();
408
408
  return;
409
409
  }
410
410
  o = !0, l = performance.now(), e.onSpeakingStart(), e.onNotify(), d();
411
- const b = k > 0 ? M / k : M;
411
+ const b = k > 0 ? x / k : x;
412
412
  v = setTimeout(() => {
413
413
  p || (o = !1, v = null, e.onSpeakingDone(), e.onNotify());
414
414
  }, b);
415
- }, N = (g, M, b, D) => {
416
- M.length !== 0 && (D && (_ = b), M.forEach((A) => {
417
- const O = String(A.word ?? "").trim();
418
- if (!O) return;
415
+ }, N = (g, x, b, D) => {
416
+ x.length !== 0 && (D && (_ = b), x.forEach((A) => {
417
+ const F = String(A.word ?? "").trim();
418
+ if (!F) return;
419
419
  const W = Math.round((A.start ?? 0) * 1e3), G = A.duration != null ? Math.round(A.duration * 1e3) : A.end != null ? Math.max(1, Math.round((A.end - (A.start ?? 0)) * 1e3)) : 0;
420
420
  g.push({
421
- word: O,
421
+ word: F,
422
422
  wtime: _ + W,
423
423
  wduration: G,
424
424
  queueIndex: g.length,
@@ -426,20 +426,20 @@ function en(e, t) {
426
426
  emphasis: A.emphasis === !0
427
427
  });
428
428
  }));
429
- }, $ = (g, M, b, D, A, P) => {
430
- b.length !== 0 && (A && (_ = D), b.forEach((O) => {
431
- const W = String(O.symbol ?? O.viseme ?? "").trim();
429
+ }, V = (g, x, b, D, A, P) => {
430
+ b.length !== 0 && (A && (_ = D), b.forEach((F) => {
431
+ const W = String(F.symbol ?? F.viseme ?? "").trim();
432
432
  if (!W) return;
433
- const G = Math.round((O.start ?? 0) * 1e3), H = Math.max(1, Math.round((O.duration ?? 0) * 1e3)), Y = _ + G;
433
+ const G = Math.round((F.start ?? 0) * 1e3), H = Math.max(1, Math.round((F.duration ?? 0) * 1e3)), Y = _ + G;
434
434
  let J;
435
- if (On(P) === "oculus_direct")
436
- J = or(W);
435
+ if (Fn(P) === "oculus_direct")
436
+ J = ar(W);
437
437
  else {
438
- const fe = Er(M, Y), ee = fe ? ur(fe, Y) : 0;
439
- J = mr(
438
+ const he = Sr(x, Y), te = he ? lr(he, Y) : 0;
439
+ J = wr(
440
440
  W,
441
- fe?.word ?? "",
442
- ee
441
+ he?.word ?? "",
442
+ te
443
443
  );
444
444
  }
445
445
  g.push({
@@ -449,20 +449,20 @@ function en(e, t) {
449
449
  vduration: H
450
450
  });
451
451
  }), e.onNotify());
452
- }, z = (g, M, b, D, A, P, O) => {
453
- N(M, D, A, P), $(
452
+ }, z = (g, x, b, D, A, P, F) => {
453
+ N(x, D, A, P), V(
454
454
  g,
455
- M,
455
+ x,
456
456
  b,
457
457
  A,
458
458
  P,
459
- O
459
+ F
460
460
  );
461
- }, y = async (g, M, b, D, A, P, O) => {
461
+ }, y = async (g, x, b, D, A, P, F) => {
462
462
  if (p || !b?.trim()) {
463
463
  (D.length > 0 || A.length > 0) && !a && z(
464
464
  g,
465
- M,
465
+ x,
466
466
  D,
467
467
  A,
468
468
  _,
@@ -486,30 +486,30 @@ function en(e, t) {
486
486
  s || (s = new W());
487
487
  const G = s;
488
488
  G.state === "suspended" && await G.resume();
489
- const H = await yr(G, b);
489
+ const H = await Er(G, b);
490
490
  a = !0;
491
491
  const Y = G.currentTime;
492
492
  let J = m;
493
- const fe = !o;
493
+ const he = !o;
494
494
  J < Y && (J = Y + 0.1), m = J + H.duration;
495
- const ee = G.createBufferSource();
496
- if (ee.buffer = H, ee.playbackRate.value = k, ee.connect(G.destination), r.push(ee), p) {
495
+ const te = G.createBufferSource();
496
+ if (te.buffer = H, te.playbackRate.value = k, te.connect(G.destination), r.push(te), p) {
497
497
  r.pop();
498
498
  return;
499
499
  }
500
- if (fe) {
501
- o = !0, e.onSpeakingStart(), w = J, _ = 0, g.length = 0, M.length = 0, O?.();
500
+ if (he) {
501
+ o = !0, e.onSpeakingStart(), w = J, _ = 0, g.length = 0, x.length = 0, F?.();
502
502
  const E = (J - Y) * 1e3;
503
503
  l = performance.now() + E;
504
504
  }
505
- ee.onended = () => {
506
- const E = r.indexOf(ee);
505
+ te.onended = () => {
506
+ const E = r.indexOf(te);
507
507
  E >= 0 && r.splice(E, 1), R(), e.onNotify();
508
- }, ee.start(J);
508
+ }, te.start(J);
509
509
  const c = (J - w) * 1e3;
510
510
  z(
511
511
  g,
512
- M,
512
+ x,
513
513
  D,
514
514
  A,
515
515
  c,
@@ -523,12 +523,12 @@ function en(e, t) {
523
523
  const W = n.shift();
524
524
  W ? await y(
525
525
  g,
526
- M,
526
+ x,
527
527
  W.audio,
528
528
  W.visemes,
529
529
  W.words,
530
530
  W.isNewSegment,
531
- O
531
+ F
532
532
  ) : R();
533
533
  }
534
534
  };
@@ -559,11 +559,11 @@ function en(e, t) {
559
559
  R();
560
560
  },
561
561
  playAudioChunk: y,
562
- queueTimingsOnly: (g, M, b, D, A) => {
562
+ queueTimingsOnly: (g, x, b, D, A) => {
563
563
  let P = _;
564
564
  A && g.length > 0 && (P = Bt(g)), z(
565
565
  g,
566
- M,
566
+ x,
567
567
  b,
568
568
  D,
569
569
  P,
@@ -592,7 +592,7 @@ function ze(e, t) {
592
592
  t < r.vtime || t >= r.vtime + r.vduration || (!n || r.vtime >= n.vtime) && (n = r);
593
593
  return n ? n.viseme : "sil";
594
594
  }
595
- function Sr(e, t, n = 120) {
595
+ function kr(e, t, n = 120) {
596
596
  const r = ze(e, t);
597
597
  if (r !== "sil") return r;
598
598
  let s = null;
@@ -603,23 +603,23 @@ function Sr(e, t, n = 120) {
603
603
  }
604
604
  return s?.viseme ?? "sil";
605
605
  }
606
- function zs(e, t) {
606
+ function Ys(e, t) {
607
607
  for (const n of e)
608
608
  if (t >= n.wtime && t < n.wtime + n.wduration)
609
609
  return n;
610
610
  return null;
611
611
  }
612
- const tn = 0.5, nn = 1.5, rn = "Olivia", kr = "f786b574-daa5-4673-aa0c-cbe3e8534c02", ht = 0.85;
613
- function Lt(e, t = Ae) {
612
+ const tn = 0.5, nn = 1.5, rn = "Olivia", vr = "f786b574-daa5-4673-aa0c-cbe3e8534c02", ht = 0.85;
613
+ function Lt(e, t = Te) {
614
614
  const n = `${t.replace(/\/$/, "")}/avatar_ttsWithPoses`, r = [], s = [], i = [];
615
- let o = "neutral", a = "", f = Ie;
615
+ let o = "neutral", a = "", f = Ae;
616
616
  const l = /* @__PURE__ */ new Set(), w = () => l.forEach((k) => k()), _ = en(
617
617
  {
618
618
  onSpeakingStart: () => e("speaking"),
619
619
  onSpeakingDone: () => e("done"),
620
620
  onNotify: w
621
621
  },
622
- Ie
622
+ Ae
623
623
  ), m = () => {
624
624
  _.stop(), r.length = 0, s.length = 0, i.length = 0, o = "neutral", e("idle"), w();
625
625
  };
@@ -636,7 +636,7 @@ function Lt(e, t = Ae) {
636
636
  const p = a.trim();
637
637
  if (!p)
638
638
  throw new Error("Developer token required for avatar_ttsWithPoses");
639
- const d = u?.ttsEngineId ?? f ?? Ie;
639
+ const d = u?.ttsEngineId ?? f ?? Ae;
640
640
  _.resetForNewStream(d), _.setStreamTtsEngineId(d);
641
641
  const I = u?.voiceId ?? rn, S = u?.speakingRate ?? ht, R = Math.max(
642
642
  tn,
@@ -647,7 +647,7 @@ function Lt(e, t = Ae) {
647
647
  speakingRate: R,
648
648
  tenant: "aiTwin"
649
649
  };
650
- Ln.has(d) && (q.voice_id = I);
650
+ On.has(d) && (q.voice_id = I);
651
651
  try {
652
652
  const N = await fetch(n, {
653
653
  method: "POST",
@@ -659,28 +659,28 @@ function Lt(e, t = Ae) {
659
659
  });
660
660
  if (!N.ok)
661
661
  throw new Error(`avatar_ttsWithPoses failed (${N.status})`);
662
- const $ = N.body;
663
- if (!$) throw new Error("No response body");
664
- const z = $.getReader(), y = new TextDecoder();
662
+ const V = N.body;
663
+ if (!V) throw new Error("No response body");
664
+ const z = V.getReader(), y = new TextDecoder();
665
665
  let T = "";
666
- const g = async (M) => {
667
- const b = rr(M);
666
+ const g = async (x) => {
667
+ const b = sr(x);
668
668
  if (b) {
669
669
  if (b.event === "audio") {
670
- const D = b.data.chunk, A = b.data.visemes ?? [], P = b.data.words ?? [], O = b.data.is_new_segment ?? !1;
670
+ const D = b.data.chunk, A = b.data.visemes ?? [], P = b.data.words ?? [], F = b.data.is_new_segment ?? !1;
671
671
  D ? await _.playAudioChunk(
672
672
  r,
673
673
  s,
674
674
  D,
675
675
  A,
676
676
  P,
677
- O
677
+ F
678
678
  ) : (A.length > 0 || P.length > 0) && _.queueTimingsOnly(
679
679
  r,
680
680
  s,
681
681
  A,
682
682
  P,
683
- O
683
+ F
684
684
  );
685
685
  } else if (b.event === "metadata") {
686
686
  const D = b.data.mood;
@@ -690,14 +690,14 @@ function Lt(e, t = Ae) {
690
690
  i.length = 0;
691
691
  for (const P of A) {
692
692
  if (!P || typeof P != "object") continue;
693
- const O = P;
693
+ const F = P;
694
694
  i.push({
695
- sentence_index: Number(O.sentence_index ?? 0),
696
- text: String(O.text ?? ""),
697
- sentiment: typeof O.sentiment == "string" ? O.sentiment : void 0,
698
- emotion: String(O.emotion ?? o),
699
- start_word: Number(O.start_word ?? 0),
700
- end_word: Number(O.end_word ?? 0)
695
+ sentence_index: Number(F.sentence_index ?? 0),
696
+ text: String(F.text ?? ""),
697
+ sentiment: typeof F.sentiment == "string" ? F.sentiment : void 0,
698
+ emotion: String(F.emotion ?? o),
699
+ start_word: Number(F.start_word ?? 0),
700
+ end_word: Number(F.end_word ?? 0)
701
701
  });
702
702
  }
703
703
  }
@@ -709,14 +709,14 @@ function Lt(e, t = Ae) {
709
709
  }
710
710
  };
711
711
  for (; ; ) {
712
- const { done: M, value: b } = await z.read();
712
+ const { done: x, value: b } = await z.read();
713
713
  b && (T += y.decode(b, { stream: !0 }));
714
714
  const D = T.split(`
715
715
 
716
716
  `);
717
717
  T = D.pop() ?? "";
718
718
  for (const A of D) await g(A);
719
- if (M) {
719
+ if (x) {
720
720
  T.trim() && await g(T.trim()), _.markStreamComplete(r);
721
721
  break;
722
722
  }
@@ -740,7 +740,7 @@ function Lt(e, t = Ae) {
740
740
  };
741
741
  }
742
742
  const sn = 16e3, on = 24e3;
743
- class vr extends In {
743
+ class br extends Rn {
744
744
  constructor() {
745
745
  super(
746
746
  !0,
@@ -756,29 +756,31 @@ class vr extends In {
756
756
  bufferBotAudio(t, n) {
757
757
  }
758
758
  }
759
- const br = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
760
- function Tr(e) {
761
- return br.test(e.trim());
762
- }
759
+ const Tr = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
763
760
  function Ar(e) {
761
+ return Tr.test(e.trim());
762
+ }
763
+ function Ir(e) {
764
764
  const t = e.replace(/\/$/, "");
765
765
  return t.startsWith("https://") ? `wss://${t.slice(8)}` : t.startsWith("http://") ? `ws://${t.slice(7)}` : t;
766
766
  }
767
- function Ir(e) {
767
+ function Rr(e) {
768
768
  if (e.wsUrl?.trim()) return e.wsUrl.trim();
769
769
  const t = e.authToken?.trim();
770
770
  if (!t)
771
771
  throw new Error(
772
772
  "Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
773
773
  );
774
- const n = e.apiBase ?? Ae, r = new URL(`${Ar(n)}/ws/voice`);
775
- r.searchParams.set("authToken", t);
774
+ const n = e.apiBase ?? Te, r = new URL(`${Ir(n)}/ws/voice`);
775
+ r.searchParams.set("authToken", t), r.searchParams.set("tenant", "aiTwin");
776
776
  const s = e.voiceId?.trim();
777
- s && Tr(s) && r.searchParams.set("voiceId", s);
778
- const i = e.speakingRate ?? ht;
777
+ s && Ar(s) && r.searchParams.set("voiceId", s);
778
+ const i = e.personaId?.trim();
779
+ i && r.searchParams.set("personaId", i);
780
+ const o = e.speakingRate ?? ht;
779
781
  return r.searchParams.set(
780
782
  "speaking_rate",
781
- String(Math.max(tn, Math.min(nn, i)))
783
+ String(Math.max(tn, Math.min(nn, o)))
782
784
  ), e.ttsStream === !1 ? r.searchParams.set("tts_stream", "false") : r.searchParams.set("tts_stream", "true"), r.toString();
783
785
  }
784
786
  function Ot(e, t) {
@@ -795,14 +797,14 @@ function Ot(e, t) {
795
797
  });
796
798
  return n;
797
799
  }
798
- function Rr(e) {
800
+ function Dr(e) {
799
801
  if (!e || typeof e != "object") return null;
800
802
  const t = e, n = t.data;
801
803
  return n && typeof n == "object" ? n : t;
802
804
  }
803
- function Dr(e, t = {}) {
805
+ function Cr(e, t = {}) {
804
806
  const n = [], r = [], s = [], i = [];
805
- let o = "", a = "neutral", f = Re, l = !1, w = null, _ = null, m = { ...t }, v = 0, k = null;
807
+ let o = "", a = "neutral", f = Ie, l = !1, w = null, _ = null, m = { ...t }, v = 0, k = null;
806
808
  const u = /* @__PURE__ */ new Set(), p = [];
807
809
  let d = !1, I = null;
808
810
  const S = () => u.forEach((c) => c()), R = en(
@@ -821,33 +823,33 @@ function Dr(e, t = {}) {
821
823
  }, I = c, c;
822
824
  }, N = (c) => {
823
825
  p.push(c), !d && (d = !0, q().port2.postMessage(null));
824
- }, $ = () => R.getPlaybackElapsedMs(), z = (c, E = o) => {
826
+ }, V = () => R.getPlaybackElapsedMs(), z = (c, E = o) => {
825
827
  if (!m.onLipsyncDebug) return;
826
- const B = $(), Q = n;
828
+ const L = V(), X = n;
827
829
  m.onLipsyncDebug({
828
830
  event: c,
829
831
  spokenText: E,
830
832
  mood: a,
831
833
  playbackAnchorPerf: R.getPlaybackStartPerf(),
832
- playbackElapsedMs: B,
833
- queueLength: Q.length,
834
- activeViseme: ze(Q, B),
835
- segments: i.map((te) => ({
836
- ...te,
837
- visemes: [...te.visemes]
834
+ playbackElapsedMs: L,
835
+ queueLength: X.length,
836
+ activeViseme: ze(X, L),
837
+ segments: i.map((ne) => ({
838
+ ...ne,
839
+ visemes: [...ne.visemes]
838
840
  }))
839
841
  });
840
842
  }, y = (c, E) => {
841
843
  m.onLipsyncDebug && (k = { event: c, spokenText: E }, v === 0 && (v = requestAnimationFrame(() => {
842
844
  v = 0;
843
- const B = k;
844
- k = null, B && z(B.event, B.spokenText);
845
+ const L = k;
846
+ k = null, L && z(L.event, L.spokenText);
845
847
  })));
846
848
  }, T = () => {
847
849
  n.length = 0, r.length = 0, i.length = 0, o = "", a = "neutral", s.length = 0;
848
850
  }, g = () => {
849
851
  R.stop(), T(), y("reset"), S();
850
- }, M = () => {
852
+ }, x = () => {
851
853
  g(), e("idle"), S();
852
854
  }, b = (c, E) => {
853
855
  typeof c.mood == "string" && c.mood.trim() && (a = c.mood.trim()), Array.isArray(c.sentence_emotions) && c.sentence_emotions.length > 0 && (E && (s.length = 0), s.push(
@@ -858,53 +860,53 @@ function Dr(e, t = {}) {
858
860
  E && (o = E), R.resetForNewStream(f), typeof c.mood == "string" && c.mood.trim() && (a = c.mood.trim()), s.length = 0, s.push(
859
861
  ...Ot(c.sentence_emotions, a)
860
862
  ), Array.isArray(c.gestures) && c.gestures, y("metadata", E), S();
861
- }, A = (c, E, B, Q) => {
863
+ }, A = (c, E, L, X) => {
862
864
  if (!m.onLipsyncDebug) return;
863
- const te = n.slice(B), ke = Q.filter(
864
- (re) => String(re.symbol ?? re.viseme ?? "").trim()
865
+ const ne = n.slice(L), Se = X.filter(
866
+ (se) => String(se.symbol ?? se.viseme ?? "").trim()
865
867
  );
866
868
  i.push({
867
869
  spokenText: E,
868
- audioOffsetMs: te[0]?.vtime ?? 0,
870
+ audioOffsetMs: ne[0]?.vtime ?? 0,
869
871
  isNewSegment: !!c.is_new_segment,
870
872
  chunkDurationMs: c.chunk_duration_ms != null ? Number(c.chunk_duration_ms) : null,
871
873
  receivedAtMs: performance.now(),
872
- visemes: te.map((re, ce) => {
873
- const ue = ke[ce];
874
+ visemes: ne.map((se, ue) => {
875
+ const le = Se[ue];
874
876
  return {
875
- rawSymbol: String(ue?.symbol ?? ue?.viseme ?? re.viseme).trim(),
876
- viseme: re.viseme,
877
- startSec: Number(ue?.start ?? 0),
878
- durationSec: Number(ue?.duration ?? 0),
879
- vtimeMs: re.vtime,
880
- vdurationMs: re.vduration
877
+ rawSymbol: String(le?.symbol ?? le?.viseme ?? se.viseme).trim(),
878
+ viseme: se.viseme,
879
+ startSec: Number(le?.start ?? 0),
880
+ durationSec: Number(le?.duration ?? 0),
881
+ vtimeMs: se.vtime,
882
+ vdurationMs: se.vduration
881
883
  };
882
884
  })
883
885
  });
884
886
  }, P = (c) => {
885
- const E = String(c.spoken_text ?? c.text ?? "").trim(), B = !!c.is_new_segment || Number(c.chunk_index ?? -1) === 0, Q = c.visemes ?? [], te = c.words ?? [], ke = String(c.chunk ?? "").trim();
886
- E && (o = E), b(c, B), B && R.resetForNewStream(f);
887
- const re = n.length;
887
+ const E = String(c.spoken_text ?? c.text ?? "").trim(), L = !!c.is_new_segment || Number(c.chunk_index ?? -1) === 0, X = c.visemes ?? [], ne = c.words ?? [], Se = String(c.chunk ?? "").trim();
888
+ E && (o = E), b(c, L), L && R.resetForNewStream(f);
889
+ const se = n.length;
888
890
  R.playAudioChunk(
889
891
  n,
890
892
  r,
891
- ke,
892
- Q,
893
- te,
894
- B,
893
+ Se,
894
+ X,
895
+ ne,
896
+ L,
895
897
  () => {
896
898
  i.length = 0;
897
899
  }
898
900
  ).then(() => {
899
- A(c, E, re, Q), y("audio_chunk", E);
901
+ A(c, E, se, X), y("audio_chunk", E);
900
902
  });
901
- }, O = (c) => {
903
+ }, F = (c) => {
902
904
  console.warn(
903
905
  "[realtimeVoice] avatar_lipsync is deprecated — expect avatar_audio_chunk"
904
906
  );
905
907
  const E = String(c.spoken_text ?? c.text ?? "").trim();
906
908
  E && (o = E), b(c, !!c.is_new_segment);
907
- const B = n.length;
909
+ const L = n.length;
908
910
  R.queueTimingsOnly(
909
911
  n,
910
912
  r,
@@ -914,17 +916,17 @@ function Dr(e, t = {}) {
914
916
  ), A(
915
917
  c,
916
918
  E,
917
- B,
919
+ L,
918
920
  c.visemes ?? []
919
921
  ), y("lipsync", E), S();
920
922
  }, W = (c) => {
921
- const E = Rr(c);
923
+ const E = Dr(c);
922
924
  if (!E) {
923
925
  console.warn("[realtimeVoice] server message with no payload", c);
924
926
  return;
925
927
  }
926
- const B = String(E.type ?? "unknown");
927
- switch (B !== "avatar_metadata" && B !== "avatar_audio_chunk" && B !== "avatar_lipsync" && B !== "error" && console.debug("[realtimeVoice] server message", B, E), B) {
928
+ const L = String(E.type ?? "unknown");
929
+ switch (L !== "avatar_metadata" && L !== "avatar_audio_chunk" && L !== "avatar_lipsync" && L !== "error" && console.debug("[realtimeVoice] server message", L, E), L) {
928
930
  case "avatar_metadata":
929
931
  D(E);
930
932
  break;
@@ -932,11 +934,11 @@ function Dr(e, t = {}) {
932
934
  P(E);
933
935
  break;
934
936
  case "avatar_lipsync":
935
- O(E);
937
+ F(E);
936
938
  break;
937
939
  case "error": {
938
- const Q = String(E.message ?? "Voice session error");
939
- console.error("[realtimeVoice] server error:", Q), e("error"), S();
940
+ const X = String(E.message ?? "Voice session error");
941
+ console.error("[realtimeVoice] server error:", X), e("error"), S();
940
942
  break;
941
943
  }
942
944
  case "avatar_speak":
@@ -946,8 +948,8 @@ function Dr(e, t = {}) {
946
948
  );
947
949
  break;
948
950
  }
949
- }, G = () => w || (_ = new vr(), w = new Tn({
950
- transport: new An({
951
+ }, G = () => w || (_ = new br(), w = new An({
952
+ transport: new In({
951
953
  mediaManager: _,
952
954
  recorderSampleRate: sn,
953
955
  playerSampleRate: on
@@ -959,7 +961,7 @@ function Dr(e, t = {}) {
959
961
  l = !0, e("idle"), S();
960
962
  },
961
963
  onDisconnected: () => {
962
- l = !1, M();
964
+ l = !1, x();
963
965
  },
964
966
  onError: (c) => {
965
967
  const E = typeof c == "object" && c !== null && "data" in c ? String(c.data ?? c) : String(c);
@@ -996,13 +998,13 @@ function Dr(e, t = {}) {
996
998
  },
997
999
  getTtsEngineId: () => f,
998
1000
  speak: async (c, E) => {
999
- const B = c.trim();
1000
- if (B) {
1001
+ const L = c.trim();
1002
+ if (L) {
1001
1003
  if (!w || !l)
1002
1004
  throw new Error(
1003
1005
  "Realtime voice is not connected. Call connect() first."
1004
1006
  );
1005
- g(), await w.sendText(B);
1007
+ g(), await w.sendText(L);
1006
1008
  }
1007
1009
  },
1008
1010
  stop: () => {
@@ -1016,14 +1018,14 @@ function Dr(e, t = {}) {
1016
1018
  e("loading");
1017
1019
  const E = G();
1018
1020
  await E.initDevices();
1019
- const B = Ir(m);
1020
- console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", B);
1021
+ const L = Rr(m);
1022
+ console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", L);
1021
1023
  try {
1022
- await E.connect({ wsUrl: B });
1023
- } catch (Q) {
1024
+ await E.connect({ wsUrl: L });
1025
+ } catch (X) {
1024
1026
  l = !1, e("error"), S();
1025
- const te = Q instanceof Error ? Q.message : "Realtime voice connect failed (WebSocket 101 only means upgrade OK — check authToken/origin/RTVI handshake)";
1026
- throw new Error(`${te} — ${B}`);
1027
+ const ne = X instanceof Error ? X.message : "Realtime voice connect failed (WebSocket 101 only means upgrade OK — check authToken/origin/RTVI handshake)";
1028
+ throw new Error(`${ne} — ${L}`);
1027
1029
  }
1028
1030
  l = !0, e("idle"), S();
1029
1031
  },
@@ -1034,7 +1036,7 @@ function Dr(e, t = {}) {
1034
1036
  } catch (c) {
1035
1037
  console.error("[realtimeVoice] disconnect failed:", c);
1036
1038
  }
1037
- l = !1, M();
1039
+ l = !1, x();
1038
1040
  },
1039
1041
  isConnected: () => l,
1040
1042
  unlockAudio: async () => {
@@ -1044,7 +1046,7 @@ function Dr(e, t = {}) {
1044
1046
  getWordQueue: () => r,
1045
1047
  getSentenceEmotions: () => s,
1046
1048
  getStreamMood: () => a,
1047
- getPlaybackElapsedMs: $,
1049
+ getPlaybackElapsedMs: V,
1048
1050
  isSpeaking: () => R.isSpeaking(),
1049
1051
  setPlaybackSpeed: (c) => {
1050
1052
  R.setPlaybackSpeed(c);
@@ -1053,7 +1055,7 @@ function Dr(e, t = {}) {
1053
1055
  subscribe: (c) => (u.add(c), () => u.delete(c))
1054
1056
  };
1055
1057
  }
1056
- function Cr(e, t, n) {
1058
+ function xr(e, t, n) {
1057
1059
  return {
1058
1060
  width: e.crop?.source_width ?? t,
1059
1061
  height: e.crop?.source_height ?? n
@@ -1068,21 +1070,21 @@ function Mr(e, t) {
1068
1070
  height: t?.source_h ?? n?.height ?? e.frame_height ?? 0
1069
1071
  };
1070
1072
  }
1071
- function xr(e) {
1073
+ function Pr(e) {
1072
1074
  return e ? (e.w ?? 0) > 0 && (e.h ?? 0) > 0 : !1;
1073
1075
  }
1074
1076
  async function Ye(e, t) {
1075
1077
  const n = await fetch(e);
1076
1078
  if (!n.ok) throw new Error(`Failed to load encrypted asset: ${e}`);
1077
1079
  const r = await n.arrayBuffer();
1078
- return zn(r, t);
1080
+ return Yn(r, t);
1079
1081
  }
1080
- async function Pr(e, t) {
1082
+ async function Br(e, t) {
1081
1083
  if (!t) throw new Error("Missing asset key for encrypted JSON");
1082
1084
  const n = await Ye(e, t), r = new TextDecoder().decode(n);
1083
1085
  return JSON.parse(r);
1084
1086
  }
1085
- async function Br(e) {
1087
+ async function Lr(e) {
1086
1088
  const t = new Blob([e], { type: "image/webp" }), n = URL.createObjectURL(t);
1087
1089
  return new Promise((r, s) => {
1088
1090
  const i = new Image();
@@ -1093,7 +1095,7 @@ async function Br(e) {
1093
1095
  }, i.src = n;
1094
1096
  });
1095
1097
  }
1096
- async function Lr(e) {
1098
+ async function Or(e) {
1097
1099
  const t = new Blob([e], { type: "image/png" }), n = URL.createObjectURL(t);
1098
1100
  return new Promise((r, s) => {
1099
1101
  const i = new Image();
@@ -1104,16 +1106,16 @@ async function Lr(e) {
1104
1106
  }, i.src = n;
1105
1107
  });
1106
1108
  }
1107
- function Or(e) {
1109
+ function Fr(e) {
1108
1110
  const t = new Blob([e], { type: "video/mp4" });
1109
1111
  return URL.createObjectURL(t);
1110
1112
  }
1111
- async function Fr(e) {
1112
- const t = Zn();
1113
+ async function Ur(e) {
1114
+ const t = er();
1113
1115
  if (!je()) return t;
1114
1116
  if (!e) throw new Error("Missing asset key for encrypted idle video");
1115
1117
  const n = await Ye(t, e);
1116
- return Or(n);
1118
+ return Fr(n);
1117
1119
  }
1118
1120
  function mt(e, t) {
1119
1121
  return `${e}/${t}_minus_sil.png`;
@@ -1125,7 +1127,7 @@ function cn(e) {
1125
1127
  const n = e?.crop?.content_threshold;
1126
1128
  return typeof n == "number" && n > 0 ? n : an;
1127
1129
  }
1128
- const Ys = [
1130
+ const Js = [
1129
1131
  "aa",
1130
1132
  "E",
1131
1133
  "I",
@@ -1144,7 +1146,7 @@ const Ys = [
1144
1146
  "t01_0.25",
1145
1147
  "t02_0.50",
1146
1148
  "t03_0.75"
1147
- ], Ur = at.length, Ft = /* @__PURE__ */ new Set([
1149
+ ], Nr = at.length, Ft = /* @__PURE__ */ new Set([
1148
1150
  "aa__kk",
1149
1151
  "aa__nn",
1150
1152
  "aa__sil",
@@ -1260,7 +1262,7 @@ function Nt(e, t) {
1260
1262
  function qe(e) {
1261
1263
  return `${e}_minus_sil.png`;
1262
1264
  }
1263
- function Nr(e, t) {
1265
+ function Vr(e, t) {
1264
1266
  if (t.has(e)) return e;
1265
1267
  const n = /^pairs\/([^/]+)\//.exec(e);
1266
1268
  if (!n) return null;
@@ -1272,7 +1274,7 @@ function Nr(e, t) {
1272
1274
  function un(e, t) {
1273
1275
  return e.filter((n) => t.has(n));
1274
1276
  }
1275
- function Vr(e, t, n) {
1277
+ function $r(e, t, n) {
1276
1278
  const r = wt(e, t);
1277
1279
  return un(r, n).length > 0;
1278
1280
  }
@@ -1286,40 +1288,40 @@ function wt(e, t) {
1286
1288
  }
1287
1289
  const s = Ut(t, e);
1288
1290
  if (Ft.has(s)) {
1289
- for (let i = Ur - 1; i >= 0; i--)
1291
+ for (let i = Nr - 1; i >= 0; i--)
1290
1292
  n.push(Nt(s, at[i]));
1291
1293
  return n;
1292
1294
  }
1293
1295
  return [];
1294
1296
  }
1295
- function $r(e) {
1297
+ function Wr(e) {
1296
1298
  return e < 16 ? [] : e < 35 ? [1] : e < 51 ? [0, 2] : [0, 1, 2];
1297
1299
  }
1298
- function Wr(e, t) {
1299
- return $r(t).map((r) => e[r]).filter((r) => r != null);
1300
+ function Hr(e, t) {
1301
+ return Wr(t).map((r) => e[r]).filter((r) => r != null);
1300
1302
  }
1301
- function Hr(e, t, n, r) {
1303
+ function qr(e, t, n, r) {
1302
1304
  if (r <= 0) return 0;
1303
1305
  const i = Math.max(1, n - t) / r, o = e - t, a = Math.floor(o / i);
1304
1306
  return Math.min(r - 1, Math.max(0, a));
1305
1307
  }
1306
- function qr(e, t, n) {
1308
+ function Kr(e, t, n) {
1307
1309
  if (!n) return `${e}/${t}`;
1308
1310
  const r = t.split("/").pop() ?? t, s = r.includes(".") ? r.slice(0, r.lastIndexOf(".")) : r;
1309
1311
  return `${e}/${s}.bin`;
1310
1312
  }
1311
- const Kr = [0.32, 0.24, 0.16, 0.08, 0], jr = Kr.map(
1313
+ const jr = [0.32, 0.24, 0.16, 0.08, 0], Gr = jr.map(
1312
1314
  (e) => `eyes_${e.toFixed(2)}`
1313
- ), Gr = [
1315
+ ), zr = [
1314
1316
  "eyes_0.32",
1315
1317
  "eyes_0.16",
1316
1318
  "eyes_0.00"
1317
- ], zr = [
1319
+ ], Yr = [
1318
1320
  "eyes_0.32",
1319
1321
  "eyes_0.16",
1320
1322
  "eyes_0.08",
1321
1323
  "eyes_0.00"
1322
- ], Vt = 2, Yr = -30, ct = 20, Jr = {
1324
+ ], Vt = 2, Jr = -30, ct = 20, Qr = {
1323
1325
  fear: -30,
1324
1326
  anger: -20,
1325
1327
  sad: -10,
@@ -1332,12 +1334,12 @@ function gt(e) {
1332
1334
  return `brow_${e}`;
1333
1335
  }
1334
1336
  function _t(e) {
1335
- return Jr[e];
1337
+ return Qr[e];
1336
1338
  }
1337
- function Ee(e) {
1338
- return Math.max(Yr, Math.min(ct, e));
1339
+ function ye(e) {
1340
+ return Math.max(Jr, Math.min(ct, e));
1339
1341
  }
1340
- function Qr(e, t) {
1342
+ function Xr(e, t) {
1341
1343
  if (e === t) return [];
1342
1344
  const n = e < t ? Vt : -Vt, r = [];
1343
1345
  let s = e;
@@ -1345,7 +1347,7 @@ function Qr(e, t) {
1345
1347
  s += n, r.push(s);
1346
1348
  return r;
1347
1349
  }
1348
- const Xr = {
1350
+ const Zr = {
1349
1351
  fear: "fear",
1350
1352
  afraid: "fear",
1351
1353
  anxiety: "fear",
@@ -1368,9 +1370,9 @@ const Xr = {
1368
1370
  disgust: "disgust",
1369
1371
  disgusted: "disgust"
1370
1372
  };
1371
- function Te(e, t = "neutral") {
1373
+ function be(e, t = "neutral") {
1372
1374
  const n = String(e ?? "").trim().toLowerCase();
1373
- return n ? Xr[n] ?? t : t;
1375
+ return n ? Zr[n] ?? t : t;
1374
1376
  }
1375
1377
  function ln(e) {
1376
1378
  return e === 0 ? null : mt(gt(e), "eyes_standard");
@@ -1382,7 +1384,7 @@ function $t(e, t) {
1382
1384
  const n = gt(_t(e));
1383
1385
  return !t || t === "eyes_standard" ? fn(e) : e === "neutral" && t === "eyes_standard" ? null : mt(n, t);
1384
1386
  }
1385
- function Zr(e, t) {
1387
+ function es(e, t) {
1386
1388
  const n = [];
1387
1389
  for (const r of t)
1388
1390
  n.push($t(e, r));
@@ -1390,41 +1392,41 @@ function Zr(e, t) {
1390
1392
  n.push($t(e, t[r]));
1391
1393
  return n.push(fn(e)), n;
1392
1394
  }
1393
- function es(e) {
1395
+ function ts(e) {
1394
1396
  return e === 0 ? null : mt(gt(e), "eyes_standard");
1395
1397
  }
1396
- function ts(e, t) {
1397
- return Qr(e, t).map(es).filter((n) => n != null);
1398
+ function ns(e, t) {
1399
+ return Xr(e, t).map(ts).filter((n) => n != null);
1398
1400
  }
1399
- const ns = 6;
1400
- function rs(e, t) {
1401
+ const rs = 6;
1402
+ function ss(e, t) {
1401
1403
  for (const n of e)
1402
1404
  if (t >= n.wtime && t < n.wtime + n.wduration)
1403
1405
  return n;
1404
1406
  return null;
1405
1407
  }
1406
- function ss(e) {
1407
- const t = Ee(e);
1408
- return t >= ct ? ct : Ee(t + ns);
1408
+ function is(e) {
1409
+ const t = ye(e);
1410
+ return t >= ct ? ct : ye(t + rs);
1409
1411
  }
1410
- function is(e, t, n) {
1411
- const r = Ee(n);
1412
- return rs(t, e)?.emphasis ? ss(r) : r;
1412
+ function os(e, t, n) {
1413
+ const r = ye(n);
1414
+ return ss(t, e)?.emphasis ? is(r) : r;
1413
1415
  }
1414
1416
  function Wt(e) {
1415
1417
  if (!e) return 0;
1416
1418
  const t = e.match(/^brow_(-?\d+)\//);
1417
1419
  if (!t?.[1]) return null;
1418
1420
  const n = Number.parseInt(t[1], 10);
1419
- return Number.isFinite(n) ? Ee(n) : null;
1421
+ return Number.isFinite(n) ? ye(n) : null;
1420
1422
  }
1421
- function Le(e, t) {
1423
+ function Oe(e, t) {
1422
1424
  return e + Math.random() * (t - e);
1423
1425
  }
1424
1426
  function We() {
1425
- return Le(14, 32);
1427
+ return Oe(14, 32);
1426
1428
  }
1427
- function os(e = {}) {
1429
+ function as(e = {}) {
1428
1430
  const {
1429
1431
  initialDelayMs: t = 800 + Math.random() * 1200,
1430
1432
  intervalMinMs: n = 2200,
@@ -1452,13 +1454,13 @@ function os(e = {}) {
1452
1454
  return ln(y);
1453
1455
  }
1454
1456
  function q(y, T, g) {
1455
- const M = Ee(T), b = Ee(g);
1456
- if (m = b, M === b) {
1457
+ const x = ye(T), b = ye(g);
1458
+ if (m = b, x === b) {
1457
1459
  S(R(b));
1458
1460
  return;
1459
1461
  }
1460
1462
  const D = [
1461
- ...ts(M, b),
1463
+ ...ns(x, b),
1462
1464
  R(b)
1463
1465
  ];
1464
1466
  u = {
@@ -1472,14 +1474,14 @@ function os(e = {}) {
1472
1474
  function N(y, T) {
1473
1475
  u = {
1474
1476
  kind: "idle",
1475
- nextBlinkAt: y + Le(n, r)
1477
+ nextBlinkAt: y + Oe(n, r)
1476
1478
  }, _ = T, S(R(m), T);
1477
1479
  }
1478
- function $(y, T, g) {
1479
- const M = g ? Gr : Math.random() < a ? jr : zr;
1480
+ function V(y, T, g) {
1481
+ const x = g ? zr : Math.random() < a ? Gr : Yr;
1480
1482
  u = {
1481
1483
  kind: "playing",
1482
- paths: Zr(T, M),
1484
+ paths: es(T, x),
1483
1485
  index: 0,
1484
1486
  holdUntil: y + We(),
1485
1487
  after: "idle",
@@ -1498,11 +1500,11 @@ function os(e = {}) {
1498
1500
  return;
1499
1501
  }
1500
1502
  if (u.kind === "idle") {
1501
- S(R(m), _), y >= u.nextBlinkAt && $(y, _, !1);
1503
+ S(R(m), _), y >= u.nextBlinkAt && V(y, _, !1);
1502
1504
  return;
1503
1505
  }
1504
1506
  if (u.kind === "doublePause") {
1505
- S(R(m), u.blinkEmotion), y >= u.resumeAt && $(y, u.blinkEmotion, !0);
1507
+ S(R(m), u.blinkEmotion), y >= u.resumeAt && V(y, u.blinkEmotion, !0);
1506
1508
  return;
1507
1509
  }
1508
1510
  if (u.kind === "playing") {
@@ -1516,7 +1518,7 @@ function os(e = {}) {
1516
1518
  if (u.after === "doublePause") {
1517
1519
  u = {
1518
1520
  kind: "doublePause",
1519
- resumeAt: y + Le(i, o),
1521
+ resumeAt: y + Oe(i, o),
1520
1522
  blinkEmotion: u.blinkEmotion
1521
1523
  }, S(R(m), u.blinkEmotion);
1522
1524
  return;
@@ -1524,7 +1526,7 @@ function os(e = {}) {
1524
1526
  if (u.after === "idle" && Math.random() < s) {
1525
1527
  u = {
1526
1528
  kind: "doublePause",
1527
- resumeAt: y + Le(i, o),
1529
+ resumeAt: y + Oe(i, o),
1528
1530
  blinkEmotion: u.blinkEmotion
1529
1531
  }, S(R(m), u.blinkEmotion);
1530
1532
  return;
@@ -1536,16 +1538,16 @@ function os(e = {}) {
1536
1538
  return {
1537
1539
  advance: z,
1538
1540
  setTargetEmotion(y) {
1539
- const T = Te(y, w);
1541
+ const T = be(y, w);
1540
1542
  if (T === w) return;
1541
1543
  const g = performance.now();
1542
1544
  l > 0 && T !== w && !(w === "neutral" && T !== "neutral") && g - k < l || (w = T, _ = T, k = g);
1543
1545
  },
1544
1546
  setTargetEyebrow(y) {
1545
- const T = Ee(y);
1547
+ const T = ye(y);
1546
1548
  if (T === m && u.kind !== "browBlend") return;
1547
- const g = performance.now(), M = u.kind === "browBlend" ? Wt(p) ?? v : v;
1548
- m = T, !(T === M && u.kind !== "browBlend") && (u.kind === "playing" || u.kind === "doublePause" || q(g, M, T));
1549
+ const g = performance.now(), x = u.kind === "browBlend" ? Wt(p) ?? v : v;
1550
+ m = T, !(T === x && u.kind !== "browBlend") && (u.kind === "playing" || u.kind === "doublePause" || q(g, x, T));
1549
1551
  },
1550
1552
  getTargetEmotion: () => w,
1551
1553
  getTargetEyebrow: () => m,
@@ -1553,13 +1555,13 @@ function os(e = {}) {
1553
1555
  getDrawKey: () => d,
1554
1556
  reset() {
1555
1557
  w = "neutral", _ = "neutral", m = 0, v = 0, k = 0, N(
1556
- performance.now() + Le(n, r),
1558
+ performance.now() + Oe(n, r),
1557
1559
  "neutral"
1558
1560
  );
1559
1561
  }
1560
1562
  };
1561
1563
  }
1562
- function as() {
1564
+ function cs() {
1563
1565
  const e = document.createElement("video");
1564
1566
  e.muted = !0, e.playsInline = !0, e.preload = "auto", e.setAttribute("playsinline", ""), e.loop = !0;
1565
1567
  let t = !1, n = null, r = "";
@@ -1602,17 +1604,17 @@ function as() {
1602
1604
  }
1603
1605
  };
1604
1606
  }
1605
- const cs = 50, dn = 400;
1606
- function us(e, t, n) {
1607
+ const us = 50, dn = 400;
1608
+ function ls(e, t, n) {
1607
1609
  return e.filter((r) => {
1608
1610
  const s = r.queueIndex ?? -1;
1609
1611
  return s >= t && s <= n;
1610
1612
  });
1611
1613
  }
1612
- function ls(e, t) {
1614
+ function fs(e, t) {
1613
1615
  const n = [];
1614
1616
  for (const r of e) {
1615
- const s = us(
1617
+ const s = ls(
1616
1618
  t,
1617
1619
  r.start_word,
1618
1620
  r.end_word
@@ -1621,25 +1623,25 @@ function ls(e, t) {
1621
1623
  const i = s[0], o = s[s.length - 1];
1622
1624
  n.push({
1623
1625
  sentence: r,
1624
- startMs: Math.max(0, i.wtime - cs),
1626
+ startMs: Math.max(0, i.wtime - us),
1625
1627
  endMs: o.wtime + o.wduration + dn
1626
1628
  });
1627
1629
  }
1628
1630
  return n.sort((r, s) => r.startMs - s.startMs);
1629
1631
  }
1630
- function fs(e, t, n, r = "neutral") {
1631
- const s = Te(r);
1632
+ function ds(e, t, n, r = "neutral") {
1633
+ const s = be(r);
1632
1634
  if (t.length === 0) return s;
1633
1635
  if (n.length === 0 || e < n[0].wtime)
1634
- return Te(t[0]?.emotion, s);
1635
- const i = ls(t, n);
1636
+ return be(t[0]?.emotion, s);
1637
+ const i = fs(t, n);
1636
1638
  let o = null;
1637
1639
  for (const l of i)
1638
1640
  e >= l.startMs && e <= l.endMs && (o = l);
1639
1641
  if (o)
1640
- return Te(o.sentence.emotion, s);
1642
+ return be(o.sentence.emotion, s);
1641
1643
  const a = n[n.length - 1], f = a.wtime + a.wduration;
1642
- return e > f + dn ? Te(
1644
+ return e > f + dn ? be(
1643
1645
  t[t.length - 1]?.emotion,
1644
1646
  s
1645
1647
  ) : s;
@@ -1660,14 +1662,14 @@ function hn(e, t, n, r, s = an) {
1660
1662
  }
1661
1663
  return o.putImageData(f, 0, 0), i;
1662
1664
  }
1663
- let ye = null, Oe = null;
1665
+ let pe = null, Fe = null;
1664
1666
  const Ke = /* @__PURE__ */ new Map();
1665
- function ds() {
1666
- ye = null, Oe = null, Ke.clear();
1667
+ function hs() {
1668
+ pe = null, Fe = null, Ke.clear();
1667
1669
  }
1668
- Xn(ds);
1669
- function hs(e) {
1670
- return e ?? Oe ?? void 0;
1670
+ Zn(hs);
1671
+ function ms(e) {
1672
+ return e ?? Fe ?? void 0;
1671
1673
  }
1672
1674
  function pt(e) {
1673
1675
  return new Promise((t, n) => {
@@ -1675,20 +1677,20 @@ function pt(e) {
1675
1677
  r.decoding = "async", r.onload = () => t(r), r.onerror = () => n(new Error(`Failed to load image: ${e}`)), r.src = e;
1676
1678
  });
1677
1679
  }
1678
- async function ms(e) {
1679
- return je() ? Lr(
1680
- await Ye(xt(), e ?? "")
1681
- ) : pt(xt());
1680
+ async function ws(e) {
1681
+ return je() ? Or(
1682
+ await Ye(Mt(), e ?? "")
1683
+ ) : pt(Mt());
1682
1684
  }
1683
1685
  async function Ht(e, t, n, r) {
1684
- const s = n ? await Pr(e, r) : await fetch(e).then((l) => {
1686
+ const s = n ? await Br(e, r) : await fetch(e).then((l) => {
1685
1687
  if (!l.ok) throw new Error(`Failed to load ${e}`);
1686
1688
  return l.json();
1687
1689
  }), i = s.sheets?.[0];
1688
1690
  if (!i?.path) throw new Error(`${e} has no sheets[0].path`);
1689
- const o = n ? await Br(
1691
+ const o = n ? await Lr(
1690
1692
  await Ye(
1691
- qr(t, i.path, n),
1693
+ Kr(t, i.path, n),
1692
1694
  r ?? ""
1693
1695
  )
1694
1696
  ) : await pt(`${t}/${i.path}`), a = /* @__PURE__ */ new Map();
@@ -1700,21 +1702,21 @@ async function Ht(e, t, n, r) {
1700
1702
  return { atlas: o, atlasMeta: s, cellByPath: a, sheetByIndex: f, diffBase: t };
1701
1703
  }
1702
1704
  async function ut(e) {
1703
- const t = hs(e), n = je();
1705
+ const t = ms(e), n = je();
1704
1706
  if (n && !t)
1705
1707
  throw new Error("Encrypted assets enabled but no key provided");
1706
- if (ye && (!n || Oe === (t ?? null))) {
1707
- const i = await ye;
1708
+ if (pe && (!n || Fe === (t ?? null))) {
1709
+ const i = await pe;
1708
1710
  return {
1709
- ...Fe(i),
1711
+ ...Ue(i),
1710
1712
  visemePaths: [...i.viseme.cellByPath.keys()]
1711
1713
  };
1712
1714
  }
1713
- Oe = t ?? null, Ke.clear();
1714
- const r = er();
1715
- ye = (async () => {
1716
- const i = await ms(t), o = await Ht(
1717
- tr(),
1715
+ Fe = t ?? null, Ke.clear();
1716
+ const r = tr();
1717
+ pe = (async () => {
1718
+ const i = await ws(t), o = await Ht(
1719
+ nr(),
1718
1720
  r,
1719
1721
  n,
1720
1722
  t
@@ -1722,7 +1724,7 @@ async function ut(e) {
1722
1724
  let a = null;
1723
1725
  try {
1724
1726
  a = await Ht(
1725
- nr(),
1727
+ rr(),
1726
1728
  r,
1727
1729
  n,
1728
1730
  t
@@ -1732,21 +1734,21 @@ async function ut(e) {
1732
1734
  }
1733
1735
  return { sil: i, viseme: o, expression: a };
1734
1736
  })();
1735
- const s = await ye;
1736
- return { ...Fe(s), visemePaths: [...s.viseme.cellByPath.keys()] };
1737
+ const s = await pe;
1738
+ return { ...Ue(s), visemePaths: [...s.viseme.cellByPath.keys()] };
1737
1739
  }
1738
1740
  async function mn(e) {
1739
- if (await ut(e), !ye) throw new Error("Assets not loaded");
1740
- return ye;
1741
+ if (await ut(e), !pe) throw new Error("Assets not loaded");
1742
+ return pe;
1741
1743
  }
1742
- function Fe(e) {
1743
- return Cr(
1744
+ function Ue(e) {
1745
+ return xr(
1744
1746
  e.viseme.atlasMeta,
1745
1747
  e.sil.naturalWidth,
1746
1748
  e.sil.naturalHeight
1747
1749
  );
1748
1750
  }
1749
- function ws(e, t) {
1751
+ function gs(e, t) {
1750
1752
  const n = document.createElement("canvas");
1751
1753
  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;
1752
1754
  }
@@ -1756,9 +1758,9 @@ async function qt(e, t, n) {
1756
1758
  const i = (async () => {
1757
1759
  const o = t.cellByPath.get(n);
1758
1760
  if (!o) throw new Error(`No atlas cell for path: ${n}`);
1759
- const a = Mr(t.atlasMeta, o), f = Fe(e);
1760
- if (xr(o)) {
1761
- const _ = ws(t, o), m = document.createElement("canvas");
1761
+ const a = Mr(t.atlasMeta, o), f = Ue(e);
1762
+ if (Pr(o)) {
1763
+ const _ = gs(t, o), m = document.createElement("canvas");
1762
1764
  m.width = f.width, m.height = f.height;
1763
1765
  const v = m.getContext("2d");
1764
1766
  return v.fillStyle = "#000", v.fillRect(0, 0, f.width, f.height), v.drawImage(_, a.x, a.y), m;
@@ -1784,7 +1786,7 @@ async function Kt(e, t, n, r, s, i) {
1784
1786
  d.clearRect(0, 0, v, k), d.drawImage(u, 0, 0);
1785
1787
  return;
1786
1788
  }
1787
- const o = await mn(), a = cn(o.viseme.atlasMeta), { width: f, height: l } = Fe(o);
1789
+ const o = await mn(), a = cn(o.viseme.atlasMeta), { width: f, height: l } = Ue(o);
1788
1790
  (e.width !== f || e.height !== l) && (e.width = f, e.height = l);
1789
1791
  const w = [], _ = e.getContext("2d");
1790
1792
  if (_.clearRect(0, 0, f, l), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
@@ -1800,11 +1802,11 @@ async function Kt(e, t, n, r, s, i) {
1800
1802
  _.drawImage(m, 0, 0);
1801
1803
  }
1802
1804
  async function lt(e, t, n) {
1803
- const r = await mn(Oe ?? void 0), s = cn(r.viseme.atlasMeta), { width: i, height: o } = Fe(r);
1805
+ const r = await mn(Fe ?? void 0), s = cn(r.viseme.atlasMeta), { width: i, height: o } = Ue(r);
1804
1806
  (e.width !== i || e.height !== o) && (e.width = i, e.height = o);
1805
1807
  const a = [];
1806
1808
  if (t.mouthPath) {
1807
- const w = new Set(r.viseme.cellByPath.keys()), _ = Nr(t.mouthPath, w) ?? (w.has(t.mouthPath) ? t.mouthPath : null);
1809
+ const w = new Set(r.viseme.cellByPath.keys()), _ = Vr(t.mouthPath, w) ?? (w.has(t.mouthPath) ? t.mouthPath : null);
1808
1810
  _ && a.push(await qt(r, r.viseme, _));
1809
1811
  }
1810
1812
  t.expressionPath && r.expression && a.push(
@@ -1824,78 +1826,81 @@ async function lt(e, t, n) {
1824
1826
  );
1825
1827
  f.drawImage(l, 0, 0);
1826
1828
  }
1827
- async function gs(e) {
1829
+ async function _s(e) {
1828
1830
  await lt(e, { mouthPath: null, expressionPath: null });
1829
1831
  }
1830
- function _s(e) {
1832
+ function ps(e) {
1831
1833
  const t = /* @__PURE__ */ new Map();
1832
1834
  for (const n of e)
1833
1835
  t.has(n.vtime) || t.set(n.vtime, n);
1834
1836
  return [...t.values()].sort((n, r) => n.vtime - r.vtime);
1835
1837
  }
1836
- function ps(e) {
1837
- const t = _s(e), n = [];
1838
+ function ys(e) {
1839
+ const t = ps(e), n = [];
1838
1840
  for (let r = 0; r < t.length - 1; r++) {
1839
1841
  const s = t[r].viseme, i = t[r + 1].viseme, o = t[r].vtime, a = t[r + 1].vtime;
1840
1842
  s === i || a <= o || n.push({ from: s, to: i, fromVtime: o, toVtime: a });
1841
1843
  }
1842
1844
  return n;
1843
1845
  }
1844
- function ys(e, t) {
1846
+ function Es(e, t) {
1845
1847
  let n = null;
1846
1848
  for (const r of e)
1847
1849
  t >= r.fromVtime && t < r.toVtime && (n = r);
1848
1850
  return n;
1849
1851
  }
1850
- function Es(e, t) {
1852
+ function Ss(e, t) {
1851
1853
  return { gapMs: Math.max(0, t - e), holdEnd: e, transStart: e };
1852
1854
  }
1853
- const wn = 400, Ss = 200, ks = 600, vs = "__sil__";
1854
- function bs() {
1855
+ const wn = 400, ks = 200, vs = 600, gn = "__sil__";
1856
+ function bs(e) {
1857
+ return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] === gn : !1;
1858
+ }
1859
+ function Ts() {
1855
1860
  return { lastDrawnKey: "" };
1856
1861
  }
1857
- function we(e) {
1862
+ function de(e) {
1858
1863
  e.lastDrawnKey = "", e.transitionCache = void 0;
1859
1864
  }
1860
- function Ts(e, t) {
1865
+ function As(e, t) {
1861
1866
  if (t?.transitionCache && t.transitionCache.queueLength === e.length)
1862
1867
  return t.transitionCache.transitions;
1863
- const n = ps(e);
1868
+ const n = ys(e);
1864
1869
  return t && (t.transitionCache = { queueLength: e.length, transitions: n }), n;
1865
1870
  }
1866
- function As(e, t) {
1871
+ function Is(e, t) {
1867
1872
  let n = "sil";
1868
1873
  for (const r of e)
1869
1874
  r.viseme !== "sil" && (t != null && r.vtime > t || (n = r.viseme));
1870
1875
  return n;
1871
1876
  }
1872
- function Is(e, t, n, r = 120) {
1877
+ function Rs(e, t, n, r = 120) {
1873
1878
  if (n !== "sil")
1874
1879
  return n;
1875
- const s = Sr(e, t, r);
1876
- return s !== "sil" ? s : As(e, t);
1880
+ const s = kr(e, t, r);
1881
+ return s !== "sil" ? s : Is(e, t);
1877
1882
  }
1878
- function Rs(e, t) {
1879
- return e === "sil" ? !1 : t ? Vr(e, "sil", t) : wt(e, "sil").length > 0;
1883
+ function Ds(e, t) {
1884
+ return e === "sil" ? !1 : t ? $r(e, "sil", t) : wt(e, "sil").length > 0;
1880
1885
  }
1881
- function Ds() {
1882
- return wn + ks;
1886
+ function Cs() {
1887
+ return wn + vs;
1883
1888
  }
1884
1889
  function jt(e) {
1885
- return e ?? vs;
1890
+ return e ?? gn;
1886
1891
  }
1887
- function Cs(e, t, n, r) {
1892
+ function xs(e, t, n, r) {
1888
1893
  if (e.length === 0)
1889
1894
  return { diffPath: null, label: "sil" };
1890
- const s = Ts(e, r), i = ys(s, t);
1895
+ const s = As(e, r), i = Es(s, t);
1891
1896
  if (i) {
1892
- const a = i.toVtime - i.fromVtime, f = Es(i.fromVtime, i.toVtime);
1897
+ const a = i.toVtime - i.fromVtime, f = Ss(i.fromVtime, i.toVtime);
1893
1898
  if (t >= f.transStart && t < i.toVtime) {
1894
1899
  let l = wt(i.from, i.to);
1895
1900
  n && (l = un(l, n));
1896
- const w = Wr(l, a);
1901
+ const w = Hr(l, a);
1897
1902
  if (w.length > 0) {
1898
- const _ = Hr(
1903
+ const _ = qr(
1899
1904
  t,
1900
1905
  f.transStart,
1901
1906
  i.toVtime,
@@ -1909,28 +1914,28 @@ function Cs(e, t, n, r) {
1909
1914
  const o = ze(e, t);
1910
1915
  return o === "sil" ? { diffPath: null, label: "sil" } : { diffPath: qe(o), label: o };
1911
1916
  }
1912
- function gn(e, t) {
1917
+ function _n(e, t) {
1913
1918
  const n = t ?? jt(e.expressionPath);
1914
1919
  return `${jt(e.mouthPath)}|${n}`;
1915
1920
  }
1916
1921
  function Ms(e, t, n, r, s, i, o, a, f, l) {
1917
- const w = Cs(t, n, f, i), _ = {
1922
+ const w = xs(t, n, f, i), _ = {
1918
1923
  mouthPath: w.diffPath,
1919
1924
  expressionPath: r
1920
- }, m = gn(_, s);
1925
+ }, m = _n(_, s);
1921
1926
  m !== i.lastDrawnKey && (a(w.label), o(e, _, m, (v) => {
1922
1927
  v === m && (i.lastDrawnKey = m);
1923
1928
  }));
1924
1929
  }
1925
1930
  function Gt(e, t, n, r, s, i, o = null) {
1926
- const a = { mouthPath: null, expressionPath: t }, f = o != null ? `|idle@${Math.round(o * 1e3)}` : "", l = gn(a, n) + f;
1931
+ const a = { mouthPath: null, expressionPath: t }, f = o != null ? `|idle@${Math.round(o * 1e3)}` : "", l = _n(a, n) + f;
1927
1932
  !(o != null) && l === r.lastDrawnKey || (i(
1928
1933
  o != null ? "idle" : "sil"
1929
1934
  ), s(e, a, l, (_) => {
1930
1935
  _ === l && (r.lastDrawnKey = l);
1931
1936
  }));
1932
1937
  }
1933
- function _n(e) {
1938
+ function pn(e) {
1934
1939
  let t = 0, n = null, r = !1, s = !1;
1935
1940
  const i = async () => {
1936
1941
  if (!r) {
@@ -1967,7 +1972,7 @@ function _n(e) {
1967
1972
  };
1968
1973
  }
1969
1974
  const zt = -1, Yt = /* @__PURE__ */ new Map();
1970
- async function xs(e) {
1975
+ async function Ps(e) {
1971
1976
  let t = Yt.get(e);
1972
1977
  if (!t) {
1973
1978
  const n = await fetch(e);
@@ -1980,17 +1985,17 @@ async function xs(e) {
1980
1985
  }
1981
1986
  return new Worker(t, { name: "visemeDiffPreview" });
1982
1987
  }
1983
- function Ps() {
1988
+ function Bs() {
1984
1989
  return typeof Worker < "u" && typeof OffscreenCanvas < "u";
1985
1990
  }
1986
- function Bs(e, t) {
1991
+ function Ls(e, t) {
1987
1992
  (e.width !== t.width || e.height !== t.height) && (e.width = t.width, e.height = t.height);
1988
1993
  const n = e.getContext("2d");
1989
1994
  n && n.drawImage(t, 0, 0);
1990
1995
  }
1991
1996
  function Jt(e, t) {
1992
1997
  let n = 0, r = null;
1993
- const s = _n(async (i, o) => (await ut(), await lt(e, i), s.isLatestSeq(o)));
1998
+ const s = pn(async (i, o) => (await ut(), await lt(e, i), s.isLatestSeq(o)));
1994
1999
  return {
1995
2000
  usesWorker: !1,
1996
2001
  async loadAssets(i) {
@@ -2001,7 +2006,7 @@ function Jt(e, t) {
2001
2006
  return r;
2002
2007
  },
2003
2008
  async renderSilOnly() {
2004
- n += 1, s.reset(), await gs(e);
2009
+ n += 1, s.reset(), await _s(e);
2005
2010
  },
2006
2011
  drawLiveFrame(i, o, a, f) {
2007
2012
  s.enqueue(o, a, f);
@@ -2019,9 +2024,9 @@ function Jt(e, t) {
2019
2024
  }
2020
2025
  };
2021
2026
  }
2022
- function Ls(e, t, n) {
2027
+ function Os(e, t, n) {
2023
2028
  let r = null, s = 1, i = 0, o = !1, a = !1, f = null;
2024
- const l = /* @__PURE__ */ new Map(), w = _n(async (p, d, I) => (l.set(d, {
2029
+ const l = /* @__PURE__ */ new Map(), w = pn(async (p, d, I) => (l.set(d, {
2025
2030
  drawKey: I.drawKey,
2026
2031
  onDisplayed: I.onDisplayed
2027
2032
  }), await k(
@@ -2057,7 +2062,7 @@ function Ls(e, t, n) {
2057
2062
  }), v({ ...p, requestId: S });
2058
2063
  });
2059
2064
  }, u = (async () => {
2060
- r = await xs(n), r.onmessage = (p) => {
2065
+ r = await Ps(n), r.onmessage = (p) => {
2061
2066
  if (a) return;
2062
2067
  const d = p.data;
2063
2068
  if (d.type === "status") {
@@ -2081,7 +2086,7 @@ function Ls(e, t, n) {
2081
2086
  d.bitmap.close();
2082
2087
  return;
2083
2088
  }
2084
- Bs(e, d.bitmap), d.bitmap.close(), S && _(d.generation);
2089
+ Ls(e, d.bitmap), d.bitmap.close(), S && _(d.generation);
2085
2090
  return;
2086
2091
  }
2087
2092
  const I = m.get(d.requestId);
@@ -2123,7 +2128,7 @@ function Ls(e, t, n) {
2123
2128
  return await k({
2124
2129
  type: "loadAssets",
2125
2130
  keyHex: p,
2126
- urls: Qn(Se())
2131
+ urls: Xn(Ee())
2127
2132
  }) ?? { width: 842, height: 1264 };
2128
2133
  },
2129
2134
  getVisemeAtlasPaths() {
@@ -2177,17 +2182,17 @@ function Ls(e, t, n) {
2177
2182
  }
2178
2183
  };
2179
2184
  }
2180
- function Os(e, t = {}) {
2181
- if (!Ps())
2185
+ function Fs(e, t = {}) {
2186
+ if (!Bs())
2182
2187
  return Jt(e, t);
2183
- const n = Pn(t.workerScriptUrl);
2188
+ const n = Bn(t.workerScriptUrl);
2184
2189
  try {
2185
- return Ls(e, t, n);
2190
+ return Os(e, t, n);
2186
2191
  } catch {
2187
2192
  return Jt(e, t);
2188
2193
  }
2189
2194
  }
2190
- class Fs extends Error {
2195
+ class Us extends Error {
2191
2196
  constructor(t, n) {
2192
2197
  super(`${t} timed out after ${Math.round(n / 1e3)}s`), this.name = "LoadTimeoutError";
2193
2198
  }
@@ -2195,7 +2200,7 @@ class Fs extends Error {
2195
2200
  function rt(e, t, n) {
2196
2201
  return new Promise((r, s) => {
2197
2202
  const i = globalThis.setTimeout(() => {
2198
- s(new Fs(n, t));
2203
+ s(new Us(n, t));
2199
2204
  }, t);
2200
2205
  e.then(
2201
2206
  (o) => {
@@ -2207,15 +2212,15 @@ function rt(e, t, n) {
2207
2212
  );
2208
2213
  });
2209
2214
  }
2210
- const Us = {
2215
+ const Ns = {
2211
2216
  position: "relative",
2212
2217
  display: "inline-block",
2213
2218
  lineHeight: 0
2214
- }, Ns = {
2219
+ }, Vs = {
2215
2220
  display: "block",
2216
2221
  maxWidth: "100%",
2217
2222
  height: "auto"
2218
- }, Vs = {
2223
+ }, $s = {
2219
2224
  position: "absolute",
2220
2225
  inset: 0,
2221
2226
  display: "flex",
@@ -2227,19 +2232,19 @@ const Us = {
2227
2232
  fontSize: "0.875rem",
2228
2233
  textAlign: "center"
2229
2234
  };
2230
- function Be(e) {
2231
- return Fn(e) ? kr : rn;
2235
+ function Le(e) {
2236
+ return Un(e) ? vr : rn;
2232
2237
  }
2233
2238
  function ge(e, t) {
2234
2239
  return t?.isSpeaking() ? t : e.isSpeaking() ? e : t?.isConnected() ? t : e;
2235
2240
  }
2236
- const Js = vn(function({
2241
+ const Qs = bn(function({
2237
2242
  id: t,
2238
2243
  avatarId: n,
2239
2244
  faceId: r,
2240
2245
  assets: s,
2241
2246
  authToken: i,
2242
- ttsEngineId: o = Ie,
2247
+ ttsEngineId: o = Ae,
2243
2248
  voiceId: a,
2244
2249
  speakingRate: f = ht,
2245
2250
  className: l,
@@ -2254,48 +2259,48 @@ const Js = vn(function({
2254
2259
  onBotOutput: I,
2255
2260
  onRealtimeLipsyncDebug: S
2256
2261
  }, R) {
2257
- const q = L(null), N = L(null), $ = L(bs()), z = L(os()), y = L(0), T = L(0), g = L(0), M = L(null), b = L(null), D = L(!1), A = L(!1), P = L(!1), O = L("sil"), W = L(0), G = L(!1), H = L(
2262
+ const q = O(null), N = O(null), V = O(Ts()), z = O(as()), y = O(0), T = O(0), g = O(0), x = O(null), b = O(null), D = O(!1), A = O(!1), P = O(!1), F = O("sil"), W = O(0), G = O(!1), H = O(
2258
2263
  null
2259
- ), Y = L(!1), [J, fe] = Pe("idle"), [ee, c] = Pe(null), [E, B] = Pe(!1), [Q, te] = Pe(!1), [ke, re] = Pe({ width: 842, height: 1264 }), ce = L(i ?? null), ue = L(null), se = L(null), Ce = L(!1), Je = L({ width: 842, height: 1264 }), Qe = L(null), yt = L(u), X = L(v), Et = L(k), St = L(d), kt = L(I), vt = L(S);
2260
- yt.current = u, X.current = v, Et.current = k, St.current = d, kt.current = I, vt.current = S;
2261
- const bt = oe(
2264
+ ), Y = O(!1), [J, he] = Be("idle"), [te, c] = Be(null), [E, L] = Be(!1), [X, ne] = Be(!1), [Se, se] = Be({ width: 842, height: 1264 }), ue = O(i ?? null), le = O(null), re = O(null), De = O(!1), Je = O({ width: 842, height: 1264 }), Qe = O(null), yt = O(u), Z = O(v), Et = O(k), St = O(d), kt = O(I), vt = O(S);
2265
+ yt.current = u, Z.current = v, Et.current = k, St.current = d, kt.current = I, vt.current = S;
2266
+ const bt = ae(
2262
2267
  (h) => {
2263
- const C = h?.ttsEngineId ?? o ?? se.current?.ttsEngineId ?? Ie, x = h?.voiceId ?? a ?? se.current?.voiceId ?? Be(C);
2264
- return { ttsEngineId: C, voiceId: x };
2268
+ const C = h?.ttsEngineId ?? o ?? re.current?.ttsEngineId ?? Ae, M = h?.voiceId ?? a ?? re.current?.voiceId ?? Le(C);
2269
+ return { ttsEngineId: C, voiceId: M };
2265
2270
  },
2266
2271
  [o, a]
2267
- ), de = oe((h) => {
2272
+ ), me = ae((h) => {
2268
2273
  c(h), Et.current?.(h);
2269
- }, []), Me = oe(
2274
+ }, []), Ce = ae(
2270
2275
  (h) => {
2271
- fe(h), m?.(h);
2276
+ he(h), m?.(h);
2272
2277
  },
2273
2278
  [m]
2274
- ), K = L(
2275
- Lt(Me, Ae)
2276
- ), j = L(null);
2277
- be(() => (K.current = Lt(
2278
- Me,
2279
- Ae
2279
+ ), K = O(
2280
+ Lt(Ce, Te)
2281
+ ), j = O(null);
2282
+ ve(() => (K.current = Lt(
2283
+ Ce,
2284
+ Te
2280
2285
  ), i && K.current.setDeveloperToken(i), K.current.setTtsEngineId(o), () => {
2281
2286
  K.current.stop();
2282
2287
  const h = j.current;
2283
2288
  h && (h.disconnect(), j.current = null);
2284
- }), [Me, i, o]);
2285
- const Tt = oe(() => (j.current || (j.current = Dr(
2286
- Me,
2289
+ }), [Ce, i, o]);
2290
+ const Tt = ae(() => (j.current || (j.current = Cr(
2291
+ Ce,
2287
2292
  {
2288
2293
  speakingRate: f,
2289
2294
  onUserTranscript: (h, C) => St.current?.(h, C),
2290
2295
  onBotOutput: (h) => kt.current?.(h),
2291
2296
  onLipsyncDebug: (h) => vt.current?.(h)
2292
2297
  }
2293
- ), j.current.setTtsEngineId(o)), j.current), [Me, f, o]), ie = oe(() => {
2294
- M.current != null && (clearTimeout(M.current), M.current = null);
2295
- }, []), le = oe(() => {
2298
+ ), j.current.setTtsEngineId(o)), j.current), [Ce, f, o]), ie = ae(() => {
2299
+ x.current != null && (clearTimeout(x.current), x.current = null);
2300
+ }, []), fe = ae(() => {
2296
2301
  b.current != null && (clearTimeout(b.current), b.current = null), P.current = !1;
2297
- }, []), At = oe(() => {
2298
- !Y.current || !H.current || (le(), P.current = !0, b.current = setTimeout(() => {
2302
+ }, []), At = ae(() => {
2303
+ !Y.current || !H.current || (fe(), P.current = !0, b.current = setTimeout(() => {
2299
2304
  if (b.current = null, ge(
2300
2305
  K.current,
2301
2306
  j.current
@@ -2314,352 +2319,357 @@ const Js = vn(function({
2314
2319
  }
2315
2320
  h.restart(), h.setActive(!0);
2316
2321
  const C = h.getVideo();
2317
- let x = !1;
2318
- const F = () => {
2319
- x || (x = !0, C.removeEventListener("playing", U), P.current = !1);
2320
- }, U = () => {
2321
- F();
2322
+ let M = !1;
2323
+ const U = () => {
2324
+ M || (M = !0, C.removeEventListener("playing", B), P.current = !1);
2325
+ }, B = () => {
2326
+ U();
2322
2327
  };
2323
- if (C.addEventListener("playing", U, { once: !0 }), C.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && !C.paused) {
2324
- F();
2328
+ if (C.addEventListener("playing", B, { once: !0 }), C.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && !C.paused) {
2329
+ U();
2325
2330
  return;
2326
2331
  }
2327
- setTimeout(F, 300);
2328
- }, Ss));
2329
- }, [le]), Ue = oe(() => {
2330
- if (ie(), X.current?.("sil"), D.current = !1, !Y.current || !H.current) {
2332
+ setTimeout(U, 300);
2333
+ }, ks));
2334
+ }, [fe]), xe = ae(() => {
2335
+ if (ie(), Z.current?.("sil"), D.current = !1, !Y.current || !H.current) {
2331
2336
  P.current = !1;
2332
2337
  return;
2333
2338
  }
2334
2339
  At();
2335
- }, [ie, At]), Xe = oe(
2340
+ }, [ie, At]), Xe = ae(
2336
2341
  async (h) => {
2337
- const C = T.current, x = N.current, F = q.current, U = () => {
2342
+ const C = T.current, M = N.current, U = q.current, B = () => {
2338
2343
  h?.fallbackOnly || (D.current = !1);
2339
2344
  };
2340
- if (!x || !F || !E) {
2341
- U();
2345
+ if (!M || !U || !E) {
2346
+ B();
2342
2347
  return;
2343
2348
  }
2344
2349
  if (ge(
2345
2350
  K.current,
2346
2351
  j.current
2347
2352
  ).isSpeaking()) {
2348
- U();
2353
+ B();
2349
2354
  return;
2350
2355
  }
2351
2356
  if (h?.fallbackOnly) {
2352
- if (!D.current || (we($.current), await x.renderSilOnly(), C !== T.current) || ge(
2357
+ if (!D.current || (de(V.current), await M.renderSilOnly(), C !== T.current) || ge(
2353
2358
  K.current,
2354
2359
  j.current
2355
2360
  ).isSpeaking())
2356
2361
  return;
2357
- Ue();
2362
+ xe();
2363
+ return;
2364
+ }
2365
+ if (bs(V.current)) {
2366
+ de(V.current), xe();
2358
2367
  return;
2359
2368
  }
2360
- const Z = Is(
2369
+ const ee = Rs(
2361
2370
  ge(
2362
2371
  K.current,
2363
2372
  j.current
2364
2373
  ).getVisemeQueue(),
2365
2374
  W.current,
2366
- O.current
2367
- ), ae = Rs(
2368
- Z,
2375
+ F.current
2376
+ ), ce = Ds(
2377
+ ee,
2369
2378
  Qe.current
2370
2379
  );
2371
- if (we($.current), !ae) {
2372
- if (await x.renderSilOnly(), C !== T.current || ge(
2380
+ if (de(V.current), !ce) {
2381
+ if (await M.renderSilOnly(), C !== T.current || ge(
2373
2382
  K.current,
2374
2383
  j.current
2375
2384
  ).isSpeaking())
2376
2385
  return;
2377
- Ue();
2386
+ xe();
2378
2387
  return;
2379
2388
  }
2380
2389
  try {
2381
- await x.renderViseme(F, "sil", {
2382
- from: Z,
2390
+ await M.renderViseme(U, "sil", {
2391
+ from: ee,
2383
2392
  transitionDurationMs: wn
2384
2393
  });
2385
- } catch (he) {
2386
- if (he?.name !== "AbortError")
2387
- throw he;
2394
+ } catch (we) {
2395
+ if (we?.name !== "AbortError")
2396
+ throw we;
2388
2397
  }
2389
2398
  if (C !== T.current) {
2390
- U();
2399
+ B();
2391
2400
  return;
2392
2401
  }
2393
2402
  if (ge(
2394
2403
  K.current,
2395
2404
  j.current
2396
2405
  ).isSpeaking()) {
2397
- U();
2406
+ B();
2398
2407
  return;
2399
2408
  }
2400
- Ue();
2409
+ xe();
2401
2410
  },
2402
- [E, Ue]
2403
- ), xe = oe(() => {
2411
+ [E, xe]
2412
+ ), Me = ae(() => {
2404
2413
  if (A.current || D.current) return;
2405
2414
  A.current = !0, D.current = !0, ie();
2406
2415
  const h = T.current;
2407
2416
  Xe().finally(() => {
2408
2417
  A.current = !1;
2409
- }), M.current = setTimeout(() => {
2410
- M.current = null, h === T.current && Xe({ fallbackOnly: !0 });
2411
- }, Ds());
2412
- }, [ie, Xe]), It = oe(async () => {
2418
+ }), x.current = setTimeout(() => {
2419
+ x.current = null, h === T.current && Xe({ fallbackOnly: !0 });
2420
+ }, Cs());
2421
+ }, [ie, Xe]), It = ae(async () => {
2413
2422
  const h = Math.floor(Date.now() / 1e3);
2414
- if (ue.current && h < ue.current.expiresAt - 60)
2415
- return ue.current.key;
2416
- const C = ce.current ?? await nt();
2417
- ce.current = C, K.current.setDeveloperToken(C);
2418
- const x = await Kn(C, Ae);
2419
- return ue.current = {
2420
- key: x.value,
2421
- expiresAt: x.expiresAt
2422
- }, x.value;
2423
+ if (le.current && h < le.current.expiresAt - 60)
2424
+ return le.current.key;
2425
+ const C = ue.current ?? await nt();
2426
+ ue.current = C, K.current.setDeveloperToken(C);
2427
+ const M = await jn(C, Te);
2428
+ return le.current = {
2429
+ key: M.value,
2430
+ expiresAt: M.expiresAt
2431
+ }, M.value;
2423
2432
  }, []);
2424
- be(() => {
2425
- i && (ce.current = i, K.current.setDeveloperToken(i));
2426
- }, [i]), be(() => {
2427
- K.current.setTtsEngineId(o), j.current?.setTtsEngineId(o), se.current && (se.current.ttsEngineId = o);
2428
- }, [o]), be(() => {
2429
- const h = a ?? Be(o);
2430
- se.current && (se.current.voiceId = h);
2433
+ ve(() => {
2434
+ i && (ue.current = i, K.current.setDeveloperToken(i));
2435
+ }, [i]), ve(() => {
2436
+ K.current.setTtsEngineId(o), j.current?.setTtsEngineId(o), re.current && (re.current.ttsEngineId = o);
2437
+ }, [o]), ve(() => {
2438
+ const h = a ?? Le(o);
2439
+ re.current && (re.current.voiceId = h);
2431
2440
  }, [a, o]);
2432
2441
  const _e = Dt(
2433
- () => Yn(n, r),
2442
+ () => Jn(n, r),
2434
2443
  [n, r]
2435
- ), pn = Dt(() => s ? JSON.stringify(s) : _e ? `face:${_e}` : `id:${t ?? ""}`, [s, _e, t]);
2436
- return be(() => {
2444
+ ), yn = Dt(() => s ? JSON.stringify(s) : _e ? `face:${_e}` : `id:${t ?? ""}`, [s, _e, t]);
2445
+ return ve(() => {
2437
2446
  if (!t && !s && !_e) {
2438
- de("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
2447
+ me("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
2439
2448
  return;
2440
2449
  }
2441
2450
  let h = !1;
2442
- Ce.current = !1, B(!1), te(!1), c(null), se.current = null, H.current = null, Y.current = !1;
2451
+ De.current = !1, L(!1), ne(!1), c(null), re.current = null, H.current = null, Y.current = !1;
2443
2452
  const C = q.current;
2444
2453
  if (!C) return;
2445
- let x = null;
2454
+ let M = null;
2446
2455
  return (async () => {
2447
2456
  try {
2448
- let F, U, Z;
2457
+ let U, B, ee, ce;
2449
2458
  if (s)
2450
- F = s, U = o, Z = a ?? Be(U);
2459
+ U = s, B = o, ee = a ?? Le(B);
2451
2460
  else if (_e)
2452
- X.current?.("loadFace"), F = Mt(_e), U = o, Z = a ?? Be(U);
2461
+ Z.current?.("loadFace"), U = xt(_e), B = o, ee = a ?? Le(B);
2453
2462
  else {
2454
- X.current?.("getAiTwin");
2455
- const V = await rt(
2456
- Nn(t),
2463
+ Z.current?.("getAiTwin");
2464
+ const $ = await rt(
2465
+ Vn(t),
2457
2466
  3e4,
2458
2467
  "getAiTwin"
2459
2468
  );
2460
2469
  if (h) return;
2461
- if (!V.faceId?.trim())
2470
+ if (!$.faceId?.trim())
2462
2471
  throw new Error("getAiTwin returned no faceId");
2463
- U = V.ttsEngineId, Z = a ?? V.voiceId ?? Be(U), F = Mt(V.faceId);
2472
+ B = $.ttsEngineId, ee = a ?? $.voiceId ?? Le(B), ce = $.knowledgeContextId?.trim() || void 0, U = xt($.faceId);
2464
2473
  }
2465
- se.current = { ttsEngineId: U, voiceId: Z }, Jn(F), H.current = as(), x = Os(C, {
2466
- onStatus: (V) => {
2467
- h || X.current?.(V);
2474
+ re.current = { ttsEngineId: B, voiceId: ee, personaId: ce }, Qn(U), H.current = cs(), M = Fs(C, {
2475
+ onStatus: ($) => {
2476
+ h || Z.current?.($);
2468
2477
  },
2469
- onError: (V) => {
2470
- h || de(V);
2478
+ onError: ($) => {
2479
+ h || me($);
2471
2480
  },
2472
2481
  shouldAcceptLiveFrame: () => ge(
2473
2482
  K.current,
2474
2483
  j.current
2475
2484
  ).isSpeaking() && !D.current
2476
- }), N.current = x, X.current?.("auth");
2477
- const ae = ce.current ?? i ?? await rt(nt(), 3e4, "getAuthToken");
2485
+ }), N.current = M, Z.current?.("auth");
2486
+ const we = ue.current ?? i ?? await rt(nt(), 3e4, "getAuthToken");
2478
2487
  if (h) return;
2479
- ce.current = ae, K.current.setDeveloperToken(ae), K.current.setTtsEngineId(U);
2480
- const he = je() ? await It() : void 0;
2488
+ ue.current = we, K.current.setDeveloperToken(we), K.current.setTtsEngineId(B);
2489
+ const Pe = je() ? await It() : void 0;
2481
2490
  if (h) return;
2482
- X.current?.("loadAssets");
2483
- const pe = await rt(
2484
- x.loadAssets(he),
2491
+ Z.current?.("loadAssets");
2492
+ const Q = await rt(
2493
+ M.loadAssets(Pe),
2485
2494
  18e4,
2486
2495
  "load face assets"
2487
2496
  );
2488
- if (!h && pe.width > 0 && pe.height > 0 && (Je.current = pe, re(pe)), h) return;
2489
- Qe.current = x.getVisemeAtlasPaths(), Ce.current = !0, B(!0), yt.current?.(), x.renderSilOnly().then(() => {
2490
- h || X.current?.("sil");
2497
+ if (!h && Q.width > 0 && Q.height > 0 && (Je.current = Q, se(Q)), h) return;
2498
+ Qe.current = M.getVisemeAtlasPaths(), De.current = !0, L(!0), yt.current?.(), M.renderSilOnly().then(() => {
2499
+ h || Z.current?.("sil");
2491
2500
  }), (async () => {
2492
2501
  try {
2493
- const V = await Fr(he);
2494
- if (await H.current.load(V), h) return;
2495
- Y.current = !0, te(!0), we($.current), H.current.setActive(!0);
2496
- const ne = H.current.getVideo();
2502
+ const $ = await Ur(Pe);
2503
+ if (await H.current.load($), h) return;
2504
+ Y.current = !0, ne(!0), de(V.current), H.current.setActive(!0);
2505
+ const oe = H.current.getVideo();
2497
2506
  await Kt(
2498
2507
  C,
2499
- ne,
2508
+ oe,
2500
2509
  null,
2501
2510
  void 0,
2502
2511
  Je.current
2503
- ), h || X.current?.("idle");
2504
- } catch (V) {
2512
+ ), h || Z.current?.("idle");
2513
+ } catch ($) {
2505
2514
  if (h) return;
2506
- Y.current = !1, te(!1), console.warn("[AiTwin] Idle video unavailable:", V);
2515
+ Y.current = !1, ne(!1), console.warn("[AiTwin] Idle video unavailable:", $);
2507
2516
  }
2508
2517
  })();
2509
- } catch (F) {
2518
+ } catch (U) {
2510
2519
  if (h) return;
2511
- if (F instanceof st) {
2512
- de(F.message);
2520
+ if (U instanceof st) {
2521
+ me(U.message);
2513
2522
  return;
2514
2523
  }
2515
- de(F instanceof Error ? F.message : "Failed to load AI twin");
2524
+ me(U instanceof Error ? U.message : "Failed to load AI twin");
2516
2525
  }
2517
2526
  })(), () => {
2518
- h = !0, H.current?.dispose(), x?.dispose(), N.current = null;
2527
+ h = !0, H.current?.dispose(), M?.dispose(), N.current = null;
2519
2528
  };
2520
- }, [pn, s, _e, t, o, a, i, It, de]), be(() => {
2529
+ }, [yn, s, _e, t, o, a, i, It, me]), ve(() => {
2521
2530
  const h = { current: !1 }, C = () => {
2522
- const x = q.current, F = N.current, U = ge(
2531
+ const M = q.current, U = N.current, B = ge(
2523
2532
  K.current,
2524
2533
  j.current
2525
2534
  );
2526
- if (!x || !F || !E) {
2535
+ if (!M || !U || !E) {
2527
2536
  y.current = requestAnimationFrame(C);
2528
2537
  return;
2529
2538
  }
2530
- const Z = U.isSpeaking(), ae = Z && !G.current, he = G.current && !Z;
2531
- ae && (ie(), le(), D.current = !1, A.current = !1, we($.current), g.current = 0, O.current = "sil", W.current = 0, H.current?.setActive(!1)), he && (z.current.reset(), H.current?.setActive(!1), xe());
2532
- const pe = he || D.current || P.current;
2533
- if (Z) {
2539
+ const ee = B.isSpeaking(), ce = ee && !G.current, we = G.current && !ee;
2540
+ ce && (ie(), fe(), D.current = !1, A.current = !1, de(V.current), g.current = 0, F.current = "sil", W.current = 0, H.current?.setActive(!1)), we && (z.current.reset(), H.current?.setActive(!1), Me());
2541
+ const Pe = we || D.current || P.current;
2542
+ if (ee) {
2534
2543
  Y.current && H.current?.setActive(!1);
2535
- const V = U.getVisemeQueue(), ne = U.getPlaybackElapsedMs();
2536
- W.current = ne;
2537
- const me = V.length > 0 ? ze(V, ne) : "sil";
2538
- me !== "sil" && (O.current = me);
2539
- const ve = fs(
2540
- ne,
2541
- U.getSentenceEmotions(),
2542
- U.getWordQueue(),
2543
- U.getStreamMood()
2544
+ const Q = B.getVisemeQueue(), $ = B.getPlaybackElapsedMs();
2545
+ W.current = $;
2546
+ const oe = Q.length > 0 ? ze(Q, $) : "sil";
2547
+ oe !== "sil" && (F.current = oe);
2548
+ const ke = ds(
2549
+ $,
2550
+ B.getSentenceEmotions(),
2551
+ B.getWordQueue(),
2552
+ B.getStreamMood()
2544
2553
  );
2545
- z.current.setTargetEmotion(ve), z.current.setTargetEyebrow(
2546
- is(
2547
- ne,
2548
- U.getWordQueue(),
2549
- _t(ve)
2554
+ z.current.setTargetEmotion(ke), z.current.setTargetEyebrow(
2555
+ os(
2556
+ $,
2557
+ B.getWordQueue(),
2558
+ _t(ke)
2550
2559
  )
2551
2560
  ), z.current.advance(performance.now());
2552
2561
  const Ze = z.current.getExpressionPath(), et = z.current.getDrawKey();
2553
2562
  Ms(
2554
- x,
2555
- V,
2556
- ne,
2563
+ M,
2564
+ Q,
2565
+ $,
2557
2566
  Ze,
2558
2567
  et,
2559
- $.current,
2560
- (tt, yn, En, Sn) => F.drawLiveFrame(tt, yn, En, Sn),
2561
- (tt) => X.current?.(tt),
2568
+ V.current,
2569
+ (tt, En, Sn, kn) => U.drawLiveFrame(tt, En, Sn, kn),
2570
+ (tt) => Z.current?.(tt),
2562
2571
  Qe.current
2563
2572
  );
2564
- } else if (!pe && Y.current && H.current) {
2565
- const V = H.current, ne = V.getVideo();
2566
- ne.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? (V.setActive(!0), h.current || (h.current = !0, Kt(
2567
- x,
2568
- ne,
2573
+ } else if (!Pe && Y.current && H.current) {
2574
+ const Q = H.current, $ = Q.getVideo();
2575
+ $.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? (Q.setActive(!0), h.current || (h.current = !0, Kt(
2576
+ M,
2577
+ $,
2569
2578
  null,
2570
2579
  void 0,
2571
2580
  Je.current,
2572
- () => !U.isSpeaking() && !D.current && !P.current
2573
- ).then(() => X.current?.("idle")).finally(() => {
2581
+ () => !B.isSpeaking() && !D.current && !P.current
2582
+ ).then(() => Z.current?.("idle")).finally(() => {
2574
2583
  h.current = !1;
2575
2584
  }))) : Gt(
2576
- x,
2585
+ M,
2577
2586
  null,
2578
2587
  "__sil__",
2579
- $.current,
2580
- (me, ve, Ze, et) => F.drawLiveFrame(me, ve, Ze, et),
2581
- (me) => X.current?.(me)
2588
+ V.current,
2589
+ (oe, ke, Ze, et) => U.drawLiveFrame(oe, ke, Ze, et),
2590
+ (oe) => Z.current?.(oe)
2582
2591
  );
2583
- } else pe || Gt(
2584
- x,
2592
+ } else Pe || Gt(
2593
+ M,
2585
2594
  null,
2586
2595
  "__sil__",
2587
- $.current,
2588
- (V, ne, me, ve) => F.drawLiveFrame(V, ne, me, ve),
2589
- (V) => X.current?.(V)
2596
+ V.current,
2597
+ (Q, $, oe, ke) => U.drawLiveFrame(Q, $, oe, ke),
2598
+ (Q) => Z.current?.(Q)
2590
2599
  );
2591
- G.current = Z, y.current = requestAnimationFrame(C);
2600
+ G.current = ee, y.current = requestAnimationFrame(C);
2592
2601
  };
2593
2602
  return y.current = requestAnimationFrame(C), () => {
2594
- cancelAnimationFrame(y.current), ie(), le(), K.current.stop(), j.current?.stop();
2603
+ cancelAnimationFrame(y.current), ie(), fe(), K.current.stop(), j.current?.stop();
2595
2604
  };
2596
2605
  }, [
2597
2606
  E,
2598
- Q,
2599
- xe,
2607
+ X,
2608
+ Me,
2600
2609
  ie,
2601
- le
2602
- ]), bn(
2610
+ fe
2611
+ ]), Tn(
2603
2612
  R,
2604
2613
  () => ({
2605
2614
  speakText: async (h, C) => {
2606
- const x = h.trim();
2607
- if (!x) return;
2608
- const F = N.current;
2609
- if (!F || !Ce.current && !E)
2615
+ const M = h.trim();
2616
+ if (!M) return;
2617
+ const U = N.current;
2618
+ if (!U || !De.current && !E)
2610
2619
  throw new Error("AI twin is not ready");
2611
- const { ttsEngineId: U, voiceId: Z } = bt(C);
2612
- c(null), T.current += 1, ie(), le(), D.current = !1, A.current = !1, O.current = "sil", W.current = 0, we($.current), z.current.reset(), G.current = !1;
2620
+ const { ttsEngineId: B, voiceId: ee } = bt(C);
2621
+ c(null), T.current += 1, ie(), fe(), D.current = !1, A.current = !1, F.current = "sil", W.current = 0, de(V.current), z.current.reset(), G.current = !1;
2613
2622
  try {
2614
- Y.current ? (H.current?.setActive(!1), H.current?.restart(), we($.current)) : await F.renderSilOnly(), await K.current.speak(x, {
2615
- voiceId: Z,
2623
+ Y.current ? (H.current?.setActive(!1), H.current?.restart(), de(V.current)) : await U.renderSilOnly(), await K.current.speak(M, {
2624
+ voiceId: ee,
2616
2625
  speakingRate: C?.speakingRate ?? f,
2617
- ttsEngineId: U
2626
+ ttsEngineId: B
2618
2627
  });
2619
- } catch (ae) {
2620
- throw de(ae instanceof Error ? ae.message : "TTS failed"), ae;
2628
+ } catch (ce) {
2629
+ throw me(ce instanceof Error ? ce.message : "TTS failed"), ce;
2621
2630
  }
2622
2631
  },
2623
2632
  stop: () => {
2624
- T.current += 1, ie(), le(), D.current = !1, A.current = !1, K.current.stop(), j.current?.stop(), we($.current), G.current = !1, xe();
2633
+ T.current += 1, ie(), fe(), D.current = !1, A.current = !1, K.current.stop(), j.current?.stop(), de(V.current), G.current = !1, Me();
2625
2634
  },
2626
2635
  setTtsEngineId: (h) => {
2627
- K.current.setTtsEngineId(h), j.current?.setTtsEngineId(h), se.current && (se.current.ttsEngineId = h);
2636
+ K.current.setTtsEngineId(h), j.current?.setTtsEngineId(h), re.current && (re.current.ttsEngineId = h);
2628
2637
  },
2629
2638
  renderViseme: async (h, C) => {
2630
- const x = N.current, F = q.current;
2631
- if (!x || !F || !Ce.current)
2639
+ const M = N.current, U = q.current;
2640
+ if (!M || !U || !De.current)
2632
2641
  throw new Error("AI twin is not ready");
2633
- await x.renderViseme(F, h, {
2642
+ await M.renderViseme(U, h, {
2634
2643
  from: C?.from,
2635
2644
  transitionDurationMs: C?.transitionDurationMs,
2636
2645
  gapMs: C?.gapMs,
2637
- onStatus: (U) => X.current?.(U)
2646
+ onStatus: (B) => Z.current?.(B)
2638
2647
  });
2639
2648
  },
2640
- isReady: () => Ce.current,
2649
+ isReady: () => De.current,
2641
2650
  getStatus: () => J,
2642
2651
  connect: async (h = {}) => {
2643
2652
  c(null);
2644
2653
  try {
2645
2654
  let C = h.authToken?.trim();
2646
- C || (C = ce.current ?? i ?? await nt(), ce.current = C);
2647
- const x = h.voiceId?.trim() ?? a ?? se.current?.voiceId, F = Tt();
2648
- await F.unlockAudio(), await F.connect({
2655
+ C || (C = ue.current ?? i ?? await nt(), ue.current = C);
2656
+ const M = h.voiceId?.trim() ?? a ?? re.current?.voiceId, U = h.personaId?.trim() ?? re.current?.personaId, B = Tt();
2657
+ await B.unlockAudio(), await B.connect({
2649
2658
  ...h,
2650
2659
  authToken: C,
2651
- voiceId: x,
2660
+ voiceId: M,
2661
+ personaId: U,
2652
2662
  speakingRate: h.speakingRate ?? f
2653
2663
  });
2654
2664
  } catch (C) {
2655
- throw de(
2665
+ throw me(
2656
2666
  C instanceof Error ? C.message : "Voice connect failed"
2657
2667
  ), C;
2658
2668
  }
2659
2669
  },
2660
2670
  disconnect: async () => {
2661
2671
  const h = j.current;
2662
- h && (T.current += 1, ie(), le(), D.current = !1, A.current = !1, we($.current), G.current = !1, await h.disconnect(), xe());
2672
+ h && (T.current += 1, ie(), fe(), D.current = !1, A.current = !1, de(V.current), G.current = !1, await h.disconnect(), Me());
2663
2673
  },
2664
2674
  isConnected: () => j.current?.isConnected() ?? !1
2665
2675
  }),
@@ -2669,73 +2679,73 @@ const Js = vn(function({
2669
2679
  i,
2670
2680
  a,
2671
2681
  ie,
2672
- le,
2673
- xe,
2674
- de,
2682
+ fe,
2683
+ Me,
2684
+ me,
2675
2685
  bt,
2676
2686
  Tt,
2677
2687
  J
2678
2688
  ]
2679
- ), /* @__PURE__ */ kn("div", { className: l, style: { ...Us, ...w }, children: [
2689
+ ), /* @__PURE__ */ vn("div", { className: l, style: { ...Ns, ...w }, children: [
2680
2690
  /* @__PURE__ */ Rt(
2681
2691
  "canvas",
2682
2692
  {
2683
2693
  ref: q,
2684
- width: ke.width,
2685
- height: ke.height,
2686
- style: { ...Ns, ..._ },
2694
+ width: Se.width,
2695
+ height: Se.height,
2696
+ style: { ...Vs, ..._ },
2687
2697
  "aria-label": t ? `AI twin ${t}` : "AI twin face"
2688
2698
  }
2689
2699
  ),
2690
- p && ee ? /* @__PURE__ */ Rt("div", { style: Vs, children: ee }) : null
2700
+ p && te ? /* @__PURE__ */ Rt("div", { style: $s, children: te }) : null
2691
2701
  ] });
2692
- }), $s = "thumbnail.webp";
2693
- function Qs(e, t = ft) {
2702
+ }), Ws = "thumbnail.webp";
2703
+ function Xs(e, t = ft) {
2694
2704
  const n = e.trim();
2695
2705
  if (!n)
2696
2706
  throw new Error("faceId is required");
2697
- return `${t.replace(/\/$/, "")}/${n}/${$s}`;
2707
+ return `${t.replace(/\/$/, "")}/${n}/${Ws}`;
2698
2708
  }
2699
- const Ws = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]);
2700
- function Hs(e = ".png") {
2709
+ const Hs = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]);
2710
+ function qs(e = ".png") {
2701
2711
  const t = e.toLowerCase();
2702
- return Ws.has(t) ? `source${t}` : "source.png";
2712
+ return Hs.has(t) ? `source${t}` : "source.png";
2703
2713
  }
2704
- function Xs(e, t = ft, n = ".png") {
2714
+ function Zs(e, t = ft, n = ".png") {
2705
2715
  const r = e.trim();
2706
2716
  if (!r)
2707
2717
  throw new Error("faceId is required");
2708
- return `${t.replace(/\/$/, "")}/${r}/${Hs(n)}`;
2718
+ return `${t.replace(/\/$/, "")}/${r}/${qs(n)}`;
2709
2719
  }
2710
2720
  export {
2711
- $s as AI_TWIN_THUMBNAIL_FILENAME,
2712
- Js as AiTwin,
2721
+ Ws as AI_TWIN_THUMBNAIL_FILENAME,
2722
+ Qs as AiTwin,
2713
2723
  st as AiTwinNotFoundError,
2714
- Ie as DEFAULT_TTS_ENGINE_ID,
2724
+ Ae as DEFAULT_TTS_ENGINE_ID,
2715
2725
  sn as MIC_SAMPLE_RATE,
2716
- sr as OCULUS_VISEME_IDS,
2726
+ ir as OCULUS_VISEME_IDS,
2717
2727
  on as PLAYBACK_SAMPLE_RATE,
2718
2728
  nn as SPEAKING_RATE_MAX,
2719
2729
  tn as SPEAKING_RATE_MIN,
2720
- Re as TTS_ENGINE_CARTESIA,
2730
+ Ie as TTS_ENGINE_CARTESIA,
2721
2731
  Xt as TTS_ENGINE_GOOGLE,
2722
2732
  dt as TTS_ENGINE_INWORLD,
2723
- Ys as VISEME_IDS,
2724
- kr as VISEME_TEST_CARTESIA_VOICE_ID,
2733
+ Js as VISEME_IDS,
2734
+ vr as VISEME_TEST_CARTESIA_VOICE_ID,
2725
2735
  ht as VISEME_TEST_SPEAKING_RATE,
2726
2736
  rn as VISEME_TEST_VOICE_ID,
2727
- Hs as aiTwinSourceFilename,
2728
- Ir as buildVoiceWebSocketUrl,
2737
+ qs as aiTwinSourceFilename,
2738
+ Rr as buildVoiceWebSocketUrl,
2729
2739
  Lt as createAvatarTtsLipsyncController,
2730
- Dr as createRealtimeVoiceLipsyncController,
2731
- Mt as faceAssetUrls,
2732
- Nn as fetchAiTwin,
2740
+ Cr as createRealtimeVoiceLipsyncController,
2741
+ xt as faceAssetUrls,
2742
+ Vn as fetchAiTwin,
2733
2743
  nt as fetchDevAuthToken,
2734
- Xs as getAiTwinSourceUrl,
2735
- Qs as getAiTwinThumbnailUrl,
2736
- or as normalizeOculusViseme,
2737
- Yn as resolveDirectFaceId,
2744
+ Zs as getAiTwinSourceUrl,
2745
+ Xs as getAiTwinThumbnailUrl,
2746
+ ar as normalizeOculusViseme,
2747
+ Jn as resolveDirectFaceId,
2738
2748
  ze as resolveVisemeAtTime,
2739
- zs as resolveWordAtTime,
2740
- Jn as setActiveTwinAssets
2749
+ Ys as resolveWordAtTime,
2750
+ Qn as setActiveTwinAssets
2741
2751
  };