@streamoji/aitwin 0.2.6 → 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,75 +1,75 @@
1
- import { jsxs as kn, jsx as It } from "react/jsx-runtime";
2
- import { forwardRef as vn, useRef as F, useState as Le, useCallback as oe, useEffect as ke, useMemo as Rt, 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", Jt = {
6
- publicBase: Rn
7
- }, Dn = "0.2.6", Mn = {
8
- version: Dn
9
- }, Cn = {}, be = "https://ai.streamoji.com", ut = `${Jt.publicBase}/custom-faces`, xn = `${Jt.publicBase}/aitwin-workers/v${Mn.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
- const t = typeof import.meta < "u" ? Cn?.VITE_AITWIN_WORKER_URL : void 0;
13
- return t?.trim() ? t.trim() : xn;
14
- }
15
- const Bn = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", Qt = "eng_a7f2b9c1", lt = "eng_d4e8f3a2", Ae = "eng_c9b1e6d4", Te = Ae, Ln = /* @__PURE__ */ new Set([
16
- lt,
17
- Ae
18
- ]), Xt = {
19
- [Qt]: "oculus_direct",
20
- [Ae]: "oculus_direct",
21
- [lt]: "inworld_word"
22
- }, Dt = {
23
- google: Qt,
24
- inworld: lt,
25
- cartesia: Ae
12
+ const t = typeof import.meta < "u" ? Mn?.VITE_AITWIN_WORKER_URL : void 0;
13
+ return t?.trim() ? t.trim() : Pn;
14
+ }
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
+ dt,
17
+ Ie
18
+ ]), Zt = {
19
+ [Xt]: "oculus_direct",
20
+ [Ie]: "oculus_direct",
21
+ [dt]: "inworld_word"
22
+ }, Ct = {
23
+ google: Xt,
24
+ inworld: dt,
25
+ cartesia: Ie
26
26
  };
27
- function On(e) {
28
- return Xt[e];
29
- }
30
27
  function Fn(e) {
31
- return e === Ae;
28
+ return Zt[e];
32
29
  }
33
30
  function Un(e) {
34
- if (e.ttsEngineId && e.ttsEngineId in Xt)
31
+ return e === Ie;
32
+ }
33
+ function Nn(e) {
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 Dt ? Dt[t] : Te;
37
+ return t && t in Ct ? Ct[t] : Ae;
38
38
  }
39
- class nt extends Error {
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());
48
48
  if (r.status === 404)
49
- throw new nt();
49
+ throw new st();
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 nt(s.error ?? "AI twin not found");
54
+ throw new st(s.error ?? "AI twin not found");
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";
62
- async function et() {
63
- const e = await fetch(Vn, {
61
+ const $n = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", Wn = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", Hn = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", qn = "6TNvp3SCs4Og0a1ijm9TommXLql1", Kn = "Swaraj Mali";
62
+ async function nt() {
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 et() {
79
79
  throw new Error("getAuthToken returned no token");
80
80
  return n;
81
81
  }
82
- async function Kn(e, t = be) {
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 = be) {
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);
@@ -97,20 +97,20 @@ function jn(e) {
97
97
  n[r / 2] = Number.parseInt(t.slice(r, r + 2), 16);
98
98
  return n;
99
99
  }
100
- function Ve(e) {
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 = Ve(n.subarray(0, 12)), s = Ve(n.subarray(12, 28)), i = Ve(n.subarray(28)), o = Ve(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"]
@@ -121,35 +121,35 @@ async function zn(e, t) {
121
121
  o
122
122
  );
123
123
  }
124
- let rt = null;
125
- const st = /* @__PURE__ */ new Set();
126
- function $e(e) {
124
+ let it = null;
125
+ const ot = /* @__PURE__ */ new Set();
126
+ function Ve(e) {
127
127
  return e.includes("/custom-faces/");
128
128
  }
129
- function qe(e) {
129
+ function He(e) {
130
130
  const t = e.binBase.trim().replace(/\/$/, ""), n = e.twinBase.trim().replace(/\/$/, "");
131
- if (!(e.encrypted || $e(t) || $e(n)))
131
+ if (!(e.encrypted || Ve(t) || Ve(n)))
132
132
  return { twinBase: n, binBase: t, encrypted: !1 };
133
- const s = $e(t) ? t : $e(n) ? n : t;
133
+ const s = Ve(t) ? t : Ve(n) ? n : t;
134
134
  return { twinBase: s, binBase: s, encrypted: !0 };
135
135
  }
136
- function Ie(e) {
137
- return qe(e).encrypted;
136
+ function Re(e) {
137
+ return He(e).encrypted;
138
138
  }
139
- function Mt(e, t = ut) {
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) {
147
- rt = qe(e);
148
- for (const t of st) t();
146
+ function Qn(e) {
147
+ it = He(e);
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
- if (!n) return qe(e);
152
+ if (!n) return He(e);
153
153
  const r = (s) => {
154
154
  try {
155
155
  return new URL(s, n).href.replace(/\/$/, "");
@@ -157,44 +157,44 @@ function Qn(e, t) {
157
157
  return s;
158
158
  }
159
159
  };
160
- return qe({
160
+ return He({
161
161
  twinBase: r(e.twinBase),
162
162
  binBase: r(e.binBase),
163
163
  encrypted: e.encrypted
164
164
  });
165
165
  }
166
166
  function Ee() {
167
- if (!rt)
167
+ if (!it)
168
168
  throw new Error("Twin assets not configured; call setActiveTwinAssets first");
169
- return rt;
169
+ return it;
170
170
  }
171
- function Xn(e) {
172
- return st.add(e), () => st.delete(e);
171
+ function Zn(e) {
172
+ return ot.add(e), () => ot.delete(e);
173
173
  }
174
- function Ct() {
174
+ function Mt() {
175
175
  const e = Ee();
176
- return Ie(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
177
- }
178
- function Zn() {
179
- const e = Ee();
180
- return Ie(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
176
+ return Re(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
181
177
  }
182
178
  function er() {
183
179
  const e = Ee();
184
- return Ie(e) ? e.binBase : e.twinBase;
185
- }
186
- function Ge() {
187
- return Ie(Ee());
180
+ return Re(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
188
181
  }
189
182
  function tr() {
190
183
  const e = Ee();
191
- return Ie(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
184
+ return Re(e) ? e.binBase : e.twinBase;
185
+ }
186
+ function je() {
187
+ return Re(Ee());
192
188
  }
193
189
  function nr() {
194
190
  const e = Ee();
195
- return Ie(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
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;
@@ -257,33 +257,33 @@ function ur(e, t) {
257
257
  const s = Math.max(0, Math.min(1, (t - e.wtime) / r));
258
258
  return Math.min(n - 1, Math.floor(s * n));
259
259
  }
260
- function ze(e, t) {
260
+ 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) {
265
- const n = e.toLowerCase(), r = ze(n, t), s = n.slice(Math.max(0, t - 1), t + 2);
264
+ function fr(e, t) {
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)
272
272
  );
273
273
  if (/oo|ou|uw/.test(r)) return "U";
274
- const s = ze(n, t);
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(
281
281
  Math.max(0, t - 1),
282
282
  Math.min(n.length, t + 3)
283
283
  );
284
- return /wo|wh/.test(s) || ze(n, t) === "o" ? "O" : "U";
284
+ return /wo|wh/.test(s) || Ge(n, t) === "o" ? "O" : "U";
285
285
  }
286
- const We = {
286
+ const $e = {
287
287
  d: "DD",
288
288
  t: "DD",
289
289
  n: "DD",
@@ -295,46 +295,46 @@ const We = {
295
295
  x: "CH",
296
296
  j: "CH"
297
297
  };
298
- function hr(e, t) {
299
- const n = e.toLowerCase(), r = ze(n, t);
300
- if (We[r]) return We[r];
298
+ function mr(e, t) {
299
+ const n = e.toLowerCase(), r = Ge(n, t);
300
+ if ($e[r]) return $e[r];
301
301
  for (let s = 0; s < n.length; s++) {
302
302
  const i = n[s];
303
- if (We[i]) return We[i];
303
+ if ($e[i]) return $e[i];
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 xt(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 xt(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
@@ -361,7 +361,7 @@ async function yr(e, t) {
361
361
  return e.decodeAudioData(r);
362
362
  }
363
363
  if (n.length >= 2 && n.length % 2 === 0)
364
- return xt(e, n);
364
+ return Pt(e, n);
365
365
  try {
366
366
  const r = n.buffer.slice(
367
367
  n.byteOffset,
@@ -369,26 +369,26 @@ async function yr(e, t) {
369
369
  );
370
370
  return await e.decodeAudioData(r);
371
371
  } catch {
372
- return xt(e, n);
372
+ return Pt(e, n);
373
373
  }
374
374
  }
375
- function Pt(e) {
375
+ function Bt(e) {
376
376
  let t = 0;
377
377
  for (const n of 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;
385
385
  return null;
386
386
  }
387
- function Zt(e, t) {
387
+ function en(e, t) {
388
388
  const n = [], r = [];
389
- let s = null, i = !1, o = !1, a = !1, f = !1, l = 0, w = 0, _ = 0, m = 0, k = null, S = 1, u = t, p = !1;
389
+ let s = null, i = !1, o = !1, a = !1, f = !1, l = 0, w = 0, _ = 0, m = 0, v = null, k = 1, u = t, p = !1;
390
390
  const d = () => {
391
- k != null && (clearTimeout(k), k = null);
391
+ v != null && (clearTimeout(v), v = null);
392
392
  }, I = () => {
393
393
  for (const g of r)
394
394
  try {
@@ -396,73 +396,73 @@ function Zt(e, t) {
396
396
  } catch {
397
397
  }
398
398
  r.length = 0;
399
- }, E = () => {
399
+ }, S = () => {
400
400
  for (const g of r)
401
- g.playbackRate.value = S;
401
+ g.playbackRate.value = k;
402
402
  }, R = () => {
403
403
  !f || i || r.length > 0 || n.length > 0 || (o = !1, d(), e.onSpeakingDone(), e.onNotify());
404
- }, H = (g) => {
405
- const C = Pt(g);
406
- if (C <= 0) {
404
+ }, q = (g) => {
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 = S > 0 ? C / S : C;
412
- k = setTimeout(() => {
413
- p || (o = !1, k = null, e.onSpeakingDone(), e.onNotify());
411
+ const b = k > 0 ? x / k : x;
412
+ v = setTimeout(() => {
413
+ p || (o = !1, v = null, e.onSpeakingDone(), e.onNotify());
414
414
  }, b);
415
- }, V = (g, C, b, D) => {
416
- C.length !== 0 && (D && (_ = b), C.forEach((A) => {
417
- const B = String(A.word ?? "").trim();
418
- if (!B) return;
419
- const W = Math.round((A.start ?? 0) * 1e3), U = A.duration != null ? Math.round(A.duration * 1e3) : A.end != null ? Math.max(1, Math.round((A.end - (A.start ?? 0)) * 1e3)) : 0;
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
+ 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: B,
421
+ word: F,
422
422
  wtime: _ + W,
423
- wduration: U,
423
+ wduration: G,
424
424
  queueIndex: g.length,
425
425
  gesture: A.gesture ?? null,
426
426
  emphasis: A.emphasis === !0
427
427
  });
428
428
  }));
429
- }, $ = (g, C, b, D, A, P) => {
430
- b.length !== 0 && (A && (_ = D), b.forEach((B) => {
431
- const W = String(B.symbol ?? B.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 U = Math.round((B.start ?? 0) * 1e3), X = Math.max(1, Math.round((B.duration ?? 0) * 1e3)), se = _ + U;
434
- let Z;
435
- if (On(P) === "oculus_direct")
436
- Z = or(W);
433
+ const G = Math.round((F.start ?? 0) * 1e3), H = Math.max(1, Math.round((F.duration ?? 0) * 1e3)), Y = _ + G;
434
+ let J;
435
+ if (Fn(P) === "oculus_direct")
436
+ J = ar(W);
437
437
  else {
438
- const ce = Er(C, se), J = ce ? ur(ce, se) : 0;
439
- Z = mr(
438
+ const he = Sr(x, Y), te = he ? lr(he, Y) : 0;
439
+ J = wr(
440
440
  W,
441
- ce?.word ?? "",
442
- J
441
+ he?.word ?? "",
442
+ te
443
443
  );
444
444
  }
445
445
  g.push({
446
- viseme: Z,
446
+ viseme: J,
447
447
  weight: 1,
448
- vtime: se,
449
- vduration: X
448
+ vtime: Y,
449
+ vduration: H
450
450
  });
451
451
  }), e.onNotify());
452
- }, j = (g, C, b, D, A, P, B) => {
453
- V(C, D, A, P), $(
452
+ }, z = (g, x, b, D, A, P, F) => {
453
+ N(x, D, A, P), V(
454
454
  g,
455
- C,
455
+ x,
456
456
  b,
457
457
  A,
458
458
  P,
459
- B
459
+ F
460
460
  );
461
- }, y = async (g, C, b, D, A, P, B) => {
461
+ }, y = async (g, x, b, D, A, P, F) => {
462
462
  if (p || !b?.trim()) {
463
- (D.length > 0 || A.length > 0) && !a && j(
463
+ (D.length > 0 || A.length > 0) && !a && z(
464
464
  g,
465
- C,
465
+ x,
466
466
  D,
467
467
  A,
468
468
  _,
@@ -484,32 +484,32 @@ function Zt(e, t) {
484
484
  try {
485
485
  const W = window.AudioContext || window.webkitAudioContext;
486
486
  s || (s = new W());
487
- const U = s;
488
- U.state === "suspended" && await U.resume();
489
- const X = await yr(U, b);
487
+ const G = s;
488
+ G.state === "suspended" && await G.resume();
489
+ const H = await Er(G, b);
490
490
  a = !0;
491
- const se = U.currentTime;
492
- let Z = m;
493
- const ce = !o;
494
- Z < se && (Z = se + 0.1), m = Z + X.duration;
495
- const J = U.createBufferSource();
496
- if (J.buffer = X, J.playbackRate.value = S, J.connect(U.destination), r.push(J), p) {
491
+ const Y = G.currentTime;
492
+ let J = m;
493
+ const he = !o;
494
+ J < Y && (J = Y + 0.1), m = J + H.duration;
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 (ce) {
501
- o = !0, e.onSpeakingStart(), w = Z, _ = 0, g.length = 0, C.length = 0, B?.();
502
- const v = (Z - se) * 1e3;
503
- l = performance.now() + v;
500
+ if (he) {
501
+ o = !0, e.onSpeakingStart(), w = J, _ = 0, g.length = 0, x.length = 0, F?.();
502
+ const E = (J - Y) * 1e3;
503
+ l = performance.now() + E;
504
504
  }
505
- J.onended = () => {
506
- const v = r.indexOf(J);
507
- v >= 0 && r.splice(v, 1), R(), e.onNotify();
508
- }, J.start(Z);
509
- const c = (Z - w) * 1e3;
510
- j(
505
+ te.onended = () => {
506
+ const E = r.indexOf(te);
507
+ E >= 0 && r.splice(E, 1), R(), e.onNotify();
508
+ }, te.start(J);
509
+ const c = (J - w) * 1e3;
510
+ z(
511
511
  g,
512
- C,
512
+ x,
513
513
  D,
514
514
  A,
515
515
  c,
@@ -523,12 +523,12 @@ function Zt(e, t) {
523
523
  const W = n.shift();
524
524
  W ? await y(
525
525
  g,
526
- C,
526
+ x,
527
527
  W.audio,
528
528
  W.visemes,
529
529
  W.words,
530
530
  W.isNewSegment,
531
- B
531
+ F
532
532
  ) : R();
533
533
  }
534
534
  };
@@ -537,9 +537,9 @@ function Zt(e, t) {
537
537
  u = g;
538
538
  },
539
539
  setPlaybackSpeed: (g) => {
540
- S = Math.max(0.1, Math.min(1, g)), E();
540
+ k = Math.max(0.1, Math.min(1, g)), S();
541
541
  },
542
- getPlaybackSpeed: () => S,
542
+ getPlaybackSpeed: () => k,
543
543
  resetForNewStream: (g) => {
544
544
  p = !1, f = !1, u = g;
545
545
  },
@@ -553,17 +553,17 @@ function Zt(e, t) {
553
553
  },
554
554
  markStreamComplete: (g) => {
555
555
  if (f = !0, !a && g.length > 0) {
556
- H(g);
556
+ q(g);
557
557
  return;
558
558
  }
559
559
  R();
560
560
  },
561
561
  playAudioChunk: y,
562
- queueTimingsOnly: (g, C, b, D, A) => {
562
+ queueTimingsOnly: (g, x, b, D, A) => {
563
563
  let P = _;
564
- A && g.length > 0 && (P = Pt(g)), j(
564
+ A && g.length > 0 && (P = Bt(g)), z(
565
565
  g,
566
- C,
566
+ x,
567
567
  b,
568
568
  D,
569
569
  P,
@@ -574,7 +574,7 @@ function Zt(e, t) {
574
574
  getPlaybackElapsedMs: () => o ? a && s && w > 0 ? Math.max(
575
575
  0,
576
576
  (s.currentTime - w) * 1e3
577
- ) : Math.max(0, (performance.now() - l) * S) : 0,
577
+ ) : Math.max(0, (performance.now() - l) * k) : 0,
578
578
  isSpeaking: () => o,
579
579
  getPlaybackStartPerf: () => l,
580
580
  /** User spoke over the bot — drop in-flight chunks until the next utterance. */
@@ -586,90 +586,101 @@ function Zt(e, t) {
586
586
  }
587
587
  };
588
588
  }
589
- function ft(e, t) {
589
+ function ze(e, t) {
590
590
  let n = null;
591
591
  for (const r of e)
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 js(e, t) {
595
+ function kr(e, t, n = 120) {
596
+ const r = ze(e, t);
597
+ if (r !== "sil") return r;
598
+ let s = null;
599
+ for (const i of e) {
600
+ if (i.vtime > t) break;
601
+ const o = i.vtime + i.vduration;
602
+ o <= t && t - o <= n && (s = i);
603
+ }
604
+ return s?.viseme ?? "sil";
605
+ }
606
+ function Ys(e, t) {
596
607
  for (const n of e)
597
608
  if (t >= n.wtime && t < n.wtime + n.wduration)
598
609
  return n;
599
610
  return null;
600
611
  }
601
- const en = 0.5, tn = 1.5, nn = "Olivia", Sr = "f786b574-daa5-4673-aa0c-cbe3e8534c02", dt = 0.85;
602
- function Bt(e, t = be) {
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) {
603
614
  const n = `${t.replace(/\/$/, "")}/avatar_ttsWithPoses`, r = [], s = [], i = [];
604
- let o = "neutral", a = "", f = Te;
605
- const l = /* @__PURE__ */ new Set(), w = () => l.forEach((S) => S()), _ = Zt(
615
+ let o = "neutral", a = "", f = Ae;
616
+ const l = /* @__PURE__ */ new Set(), w = () => l.forEach((k) => k()), _ = en(
606
617
  {
607
618
  onSpeakingStart: () => e("speaking"),
608
619
  onSpeakingDone: () => e("done"),
609
620
  onNotify: w
610
621
  },
611
- Te
622
+ Ae
612
623
  ), m = () => {
613
624
  _.stop(), r.length = 0, s.length = 0, i.length = 0, o = "neutral", e("idle"), w();
614
625
  };
615
626
  return {
616
- setDeveloperToken: (S) => {
617
- a = S;
627
+ setDeveloperToken: (k) => {
628
+ a = k;
618
629
  },
619
- setTtsEngineId: (S) => {
620
- f = S;
630
+ setTtsEngineId: (k) => {
631
+ f = k;
621
632
  },
622
633
  getTtsEngineId: () => f,
623
- speak: async (S, u) => {
634
+ speak: async (k, u) => {
624
635
  m(), e("loading");
625
636
  const p = a.trim();
626
637
  if (!p)
627
638
  throw new Error("Developer token required for avatar_ttsWithPoses");
628
- const d = u?.ttsEngineId ?? f ?? Te;
639
+ const d = u?.ttsEngineId ?? f ?? Ae;
629
640
  _.resetForNewStream(d), _.setStreamTtsEngineId(d);
630
- const I = u?.voiceId ?? nn, E = u?.speakingRate ?? dt, R = Math.max(
631
- en,
632
- Math.min(tn, E)
633
- ), H = {
634
- user_query: S,
641
+ const I = u?.voiceId ?? rn, S = u?.speakingRate ?? ht, R = Math.max(
642
+ tn,
643
+ Math.min(nn, S)
644
+ ), q = {
645
+ user_query: k,
635
646
  ttsEngineId: d,
636
647
  speakingRate: R,
637
648
  tenant: "aiTwin"
638
649
  };
639
- Ln.has(d) && (H.voice_id = I);
650
+ On.has(d) && (q.voice_id = I);
640
651
  try {
641
- const V = await fetch(n, {
652
+ const N = await fetch(n, {
642
653
  method: "POST",
643
654
  headers: {
644
655
  "Content-Type": "application/json",
645
656
  Authorization: `Bearer ${p}`
646
657
  },
647
- body: JSON.stringify(H)
658
+ body: JSON.stringify(q)
648
659
  });
649
- if (!V.ok)
650
- throw new Error(`avatar_ttsWithPoses failed (${V.status})`);
651
- const $ = V.body;
652
- if (!$) throw new Error("No response body");
653
- const j = $.getReader(), y = new TextDecoder();
660
+ if (!N.ok)
661
+ throw new Error(`avatar_ttsWithPoses failed (${N.status})`);
662
+ const V = N.body;
663
+ if (!V) throw new Error("No response body");
664
+ const z = V.getReader(), y = new TextDecoder();
654
665
  let T = "";
655
- const g = async (C) => {
656
- const b = rr(C);
666
+ const g = async (x) => {
667
+ const b = sr(x);
657
668
  if (b) {
658
669
  if (b.event === "audio") {
659
- const D = b.data.chunk, A = b.data.visemes ?? [], P = b.data.words ?? [], B = 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;
660
671
  D ? await _.playAudioChunk(
661
672
  r,
662
673
  s,
663
674
  D,
664
675
  A,
665
676
  P,
666
- B
677
+ F
667
678
  ) : (A.length > 0 || P.length > 0) && _.queueTimingsOnly(
668
679
  r,
669
680
  s,
670
681
  A,
671
682
  P,
672
- B
683
+ F
673
684
  );
674
685
  } else if (b.event === "metadata") {
675
686
  const D = b.data.mood;
@@ -679,14 +690,14 @@ function Bt(e, t = be) {
679
690
  i.length = 0;
680
691
  for (const P of A) {
681
692
  if (!P || typeof P != "object") continue;
682
- const B = P;
693
+ const F = P;
683
694
  i.push({
684
- sentence_index: Number(B.sentence_index ?? 0),
685
- text: String(B.text ?? ""),
686
- sentiment: typeof B.sentiment == "string" ? B.sentiment : void 0,
687
- emotion: String(B.emotion ?? o),
688
- start_word: Number(B.start_word ?? 0),
689
- end_word: Number(B.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)
690
701
  });
691
702
  }
692
703
  }
@@ -698,20 +709,20 @@ function Bt(e, t = be) {
698
709
  }
699
710
  };
700
711
  for (; ; ) {
701
- const { done: C, value: b } = await j.read();
712
+ const { done: x, value: b } = await z.read();
702
713
  b && (T += y.decode(b, { stream: !0 }));
703
714
  const D = T.split(`
704
715
 
705
716
  `);
706
717
  T = D.pop() ?? "";
707
718
  for (const A of D) await g(A);
708
- if (C) {
719
+ if (x) {
709
720
  T.trim() && await g(T.trim()), _.markStreamComplete(r);
710
721
  break;
711
722
  }
712
723
  }
713
- } catch (V) {
714
- throw console.error("[avatarTtsLipsync]", V), m(), e("error"), V;
724
+ } catch (N) {
725
+ throw console.error("[avatarTtsLipsync]", N), m(), e("error"), N;
715
726
  }
716
727
  },
717
728
  stop: m,
@@ -721,15 +732,15 @@ function Bt(e, t = be) {
721
732
  getStreamMood: () => o,
722
733
  getPlaybackElapsedMs: () => _.getPlaybackElapsedMs(),
723
734
  isSpeaking: () => _.isSpeaking(),
724
- setPlaybackSpeed: (S) => {
725
- _.setPlaybackSpeed(S);
735
+ setPlaybackSpeed: (k) => {
736
+ _.setPlaybackSpeed(k);
726
737
  },
727
738
  getPlaybackSpeed: () => _.getPlaybackSpeed(),
728
- subscribe: (S) => (l.add(S), () => l.delete(S))
739
+ subscribe: (k) => (l.add(k), () => l.delete(k))
729
740
  };
730
741
  }
731
- const rn = 16e3, sn = 24e3;
732
- class kr extends In {
742
+ const sn = 16e3, on = 24e3;
743
+ class br extends Rn {
733
744
  constructor() {
734
745
  super(
735
746
  !0,
@@ -737,40 +748,42 @@ class kr extends In {
737
748
  void 0,
738
749
  void 0,
739
750
  512,
740
- rn,
741
- sn
751
+ sn,
752
+ on
742
753
  );
743
754
  }
744
755
  /** Pipecat protobuf bot audio is unused — playback comes from avatar_audio_chunk. */
745
756
  bufferBotAudio(t, n) {
746
757
  }
747
758
  }
748
- const vr = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
749
- function br(e) {
750
- return vr.test(e.trim());
759
+ const Tr = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
760
+ function Ar(e) {
761
+ return Tr.test(e.trim());
751
762
  }
752
- function Tr(e) {
763
+ function Ir(e) {
753
764
  const t = e.replace(/\/$/, "");
754
765
  return t.startsWith("https://") ? `wss://${t.slice(8)}` : t.startsWith("http://") ? `ws://${t.slice(7)}` : t;
755
766
  }
756
- function Ar(e) {
767
+ function Rr(e) {
757
768
  if (e.wsUrl?.trim()) return e.wsUrl.trim();
758
769
  const t = e.authToken?.trim();
759
770
  if (!t)
760
771
  throw new Error(
761
772
  "Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
762
773
  );
763
- const n = e.apiBase ?? be, r = new URL(`${Tr(n)}/ws/voice`);
764
- 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");
765
776
  const s = e.voiceId?.trim();
766
- s && br(s) && r.searchParams.set("voiceId", s);
767
- const i = e.speakingRate ?? dt;
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;
768
781
  return r.searchParams.set(
769
782
  "speaking_rate",
770
- String(Math.max(en, Math.min(tn, i)))
783
+ String(Math.max(tn, Math.min(nn, o)))
771
784
  ), e.ttsStream === !1 ? r.searchParams.set("tts_stream", "false") : r.searchParams.set("tts_stream", "true"), r.toString();
772
785
  }
773
- function Lt(e, t) {
786
+ function Ot(e, t) {
774
787
  if (!Array.isArray(e)) return [];
775
788
  const n = [];
776
789
  for (const r of e)
@@ -784,115 +797,115 @@ function Lt(e, t) {
784
797
  });
785
798
  return n;
786
799
  }
787
- function Ir(e) {
800
+ function Dr(e) {
788
801
  if (!e || typeof e != "object") return null;
789
802
  const t = e, n = t.data;
790
803
  return n && typeof n == "object" ? n : t;
791
804
  }
792
- function Rr(e, t = {}) {
805
+ function Cr(e, t = {}) {
793
806
  const n = [], r = [], s = [], i = [];
794
- let o = "", a = "neutral", f = Ae, l = !1, w = null, _ = null, m = { ...t }, k = 0, S = null;
807
+ let o = "", a = "neutral", f = Ie, l = !1, w = null, _ = null, m = { ...t }, v = 0, k = null;
795
808
  const u = /* @__PURE__ */ new Set(), p = [];
796
809
  let d = !1, I = null;
797
- const E = () => u.forEach((c) => c()), R = Zt(
810
+ const S = () => u.forEach((c) => c()), R = en(
798
811
  {
799
812
  onSpeakingStart: () => e("speaking"),
800
813
  onSpeakingDone: () => e("done"),
801
- onNotify: E
814
+ onNotify: S
802
815
  },
803
816
  f
804
- ), H = () => {
817
+ ), q = () => {
805
818
  if (I) return I;
806
819
  const c = new MessageChannel();
807
820
  return c.port1.onmessage = () => {
808
- const v = p.shift();
809
- v !== void 0 && W(v), p.length > 0 ? c.port2.postMessage(null) : d = !1;
821
+ const E = p.shift();
822
+ E !== void 0 && W(E), p.length > 0 ? c.port2.postMessage(null) : d = !1;
810
823
  }, I = c, c;
811
- }, V = (c) => {
812
- p.push(c), !d && (d = !0, H().port2.postMessage(null));
813
- }, $ = () => R.getPlaybackElapsedMs(), j = (c, v = o) => {
824
+ }, N = (c) => {
825
+ p.push(c), !d && (d = !0, q().port2.postMessage(null));
826
+ }, V = () => R.getPlaybackElapsedMs(), z = (c, E = o) => {
814
827
  if (!m.onLipsyncDebug) return;
815
- const L = $(), z = n;
828
+ const L = V(), X = n;
816
829
  m.onLipsyncDebug({
817
830
  event: c,
818
- spokenText: v,
831
+ spokenText: E,
819
832
  mood: a,
820
833
  playbackAnchorPerf: R.getPlaybackStartPerf(),
821
834
  playbackElapsedMs: L,
822
- queueLength: z.length,
823
- activeViseme: ft(z, L),
835
+ queueLength: X.length,
836
+ activeViseme: ze(X, L),
824
837
  segments: i.map((ne) => ({
825
838
  ...ne,
826
839
  visemes: [...ne.visemes]
827
840
  }))
828
841
  });
829
- }, y = (c, v) => {
830
- m.onLipsyncDebug && (S = { event: c, spokenText: v }, k === 0 && (k = requestAnimationFrame(() => {
831
- k = 0;
832
- const L = S;
833
- S = null, L && j(L.event, L.spokenText);
842
+ }, y = (c, E) => {
843
+ m.onLipsyncDebug && (k = { event: c, spokenText: E }, v === 0 && (v = requestAnimationFrame(() => {
844
+ v = 0;
845
+ const L = k;
846
+ k = null, L && z(L.event, L.spokenText);
834
847
  })));
835
848
  }, T = () => {
836
849
  n.length = 0, r.length = 0, i.length = 0, o = "", a = "neutral", s.length = 0;
837
850
  }, g = () => {
838
- R.stop(), T(), y("reset"), E();
839
- }, C = () => {
840
- g(), e("idle"), E();
841
- }, b = (c, v) => {
842
- typeof c.mood == "string" && c.mood.trim() && (a = c.mood.trim()), Array.isArray(c.sentence_emotions) && c.sentence_emotions.length > 0 && (v && (s.length = 0), s.push(
843
- ...Lt(c.sentence_emotions, a)
851
+ R.stop(), T(), y("reset"), S();
852
+ }, x = () => {
853
+ g(), e("idle"), S();
854
+ }, b = (c, E) => {
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(
856
+ ...Ot(c.sentence_emotions, a)
844
857
  ));
845
858
  }, D = (c) => {
846
- const v = String(c.spoken_text ?? c.text ?? "").trim();
847
- v && (o = v), R.resetForNewStream(f), typeof c.mood == "string" && c.mood.trim() && (a = c.mood.trim()), s.length = 0, s.push(
848
- ...Lt(c.sentence_emotions, a)
849
- ), Array.isArray(c.gestures) && c.gestures, y("metadata", v), E();
850
- }, A = (c, v, L, z) => {
859
+ const E = String(c.spoken_text ?? c.text ?? "").trim();
860
+ E && (o = E), R.resetForNewStream(f), typeof c.mood == "string" && c.mood.trim() && (a = c.mood.trim()), s.length = 0, s.push(
861
+ ...Ot(c.sentence_emotions, a)
862
+ ), Array.isArray(c.gestures) && c.gestures, y("metadata", E), S();
863
+ }, A = (c, E, L, X) => {
851
864
  if (!m.onLipsyncDebug) return;
852
- const ne = n.slice(L), Re = z.filter(
853
- (G) => String(G.symbol ?? G.viseme ?? "").trim()
865
+ const ne = n.slice(L), Se = X.filter(
866
+ (se) => String(se.symbol ?? se.viseme ?? "").trim()
854
867
  );
855
868
  i.push({
856
- spokenText: v,
869
+ spokenText: E,
857
870
  audioOffsetMs: ne[0]?.vtime ?? 0,
858
871
  isNewSegment: !!c.is_new_segment,
859
872
  chunkDurationMs: c.chunk_duration_ms != null ? Number(c.chunk_duration_ms) : null,
860
873
  receivedAtMs: performance.now(),
861
- visemes: ne.map((G, Se) => {
862
- const Y = Re[Se];
874
+ visemes: ne.map((se, ue) => {
875
+ const le = Se[ue];
863
876
  return {
864
- rawSymbol: String(Y?.symbol ?? Y?.viseme ?? G.viseme).trim(),
865
- viseme: G.viseme,
866
- startSec: Number(Y?.start ?? 0),
867
- durationSec: Number(Y?.duration ?? 0),
868
- vtimeMs: G.vtime,
869
- vdurationMs: G.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
870
883
  };
871
884
  })
872
885
  });
873
886
  }, P = (c) => {
874
- const v = String(c.spoken_text ?? c.text ?? "").trim(), L = !!c.is_new_segment || Number(c.chunk_index ?? -1) === 0, z = c.visemes ?? [], ne = c.words ?? [], Re = String(c.chunk ?? "").trim();
875
- v && (o = v), b(c, L), L && R.resetForNewStream(f);
876
- const G = 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;
877
890
  R.playAudioChunk(
878
891
  n,
879
892
  r,
880
- Re,
881
- z,
893
+ Se,
894
+ X,
882
895
  ne,
883
896
  L,
884
897
  () => {
885
898
  i.length = 0;
886
899
  }
887
900
  ).then(() => {
888
- A(c, v, G, z), y("audio_chunk", v);
901
+ A(c, E, se, X), y("audio_chunk", E);
889
902
  });
890
- }, B = (c) => {
903
+ }, F = (c) => {
891
904
  console.warn(
892
905
  "[realtimeVoice] avatar_lipsync is deprecated — expect avatar_audio_chunk"
893
906
  );
894
- const v = String(c.spoken_text ?? c.text ?? "").trim();
895
- v && (o = v), b(c, !!c.is_new_segment);
907
+ const E = String(c.spoken_text ?? c.text ?? "").trim();
908
+ E && (o = E), b(c, !!c.is_new_segment);
896
909
  const L = n.length;
897
910
  R.queueTimingsOnly(
898
911
  n,
@@ -902,66 +915,66 @@ function Rr(e, t = {}) {
902
915
  !!c.is_new_segment
903
916
  ), A(
904
917
  c,
905
- v,
918
+ E,
906
919
  L,
907
920
  c.visemes ?? []
908
- ), y("lipsync", v), E();
921
+ ), y("lipsync", E), S();
909
922
  }, W = (c) => {
910
- const v = Ir(c);
911
- if (!v) {
923
+ const E = Dr(c);
924
+ if (!E) {
912
925
  console.warn("[realtimeVoice] server message with no payload", c);
913
926
  return;
914
927
  }
915
- const L = String(v.type ?? "unknown");
916
- switch (L !== "avatar_metadata" && L !== "avatar_audio_chunk" && L !== "avatar_lipsync" && L !== "error" && console.debug("[realtimeVoice] server message", L, v), L) {
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) {
917
930
  case "avatar_metadata":
918
- D(v);
931
+ D(E);
919
932
  break;
920
933
  case "avatar_audio_chunk":
921
- P(v);
934
+ P(E);
922
935
  break;
923
936
  case "avatar_lipsync":
924
- B(v);
937
+ F(E);
925
938
  break;
926
939
  case "error": {
927
- const z = String(v.message ?? "Voice session error");
928
- console.error("[realtimeVoice] server error:", z), e("error"), E();
940
+ const X = String(E.message ?? "Voice session error");
941
+ console.error("[realtimeVoice] server error:", X), e("error"), S();
929
942
  break;
930
943
  }
931
944
  case "avatar_speak":
932
945
  console.warn(
933
946
  "[realtimeVoice] avatar_speak received; tts_stream=false Mode B is not wired yet:",
934
- v.text
947
+ E.text
935
948
  );
936
949
  break;
937
950
  }
938
- }, U = () => w || (_ = new kr(), w = new Tn({
939
- transport: new An({
951
+ }, G = () => w || (_ = new br(), w = new An({
952
+ transport: new In({
940
953
  mediaManager: _,
941
- recorderSampleRate: rn,
942
- playerSampleRate: sn
954
+ recorderSampleRate: sn,
955
+ playerSampleRate: on
943
956
  }),
944
957
  enableCam: !1,
945
958
  enableMic: !0,
946
959
  callbacks: {
947
960
  onBotReady: () => {
948
- l = !0, e("idle"), E();
961
+ l = !0, e("idle"), S();
949
962
  },
950
963
  onDisconnected: () => {
951
- l = !1, C();
964
+ l = !1, x();
952
965
  },
953
966
  onError: (c) => {
954
- const v = typeof c == "object" && c !== null && "data" in c ? String(c.data ?? c) : String(c);
955
- console.error("[realtimeVoice]", v, c), e("error"), E();
967
+ const E = typeof c == "object" && c !== null && "data" in c ? String(c.data ?? c) : String(c);
968
+ console.error("[realtimeVoice]", E, c), e("error"), S();
956
969
  },
957
970
  onTransportStateChanged: (c) => {
958
- c === "error" && (e("error"), E());
971
+ c === "error" && (e("error"), S());
959
972
  },
960
973
  onServerMessage: (c) => {
961
- V(c);
974
+ N(c);
962
975
  },
963
976
  onUserStartedSpeaking: () => {
964
- R.bargeIn(), T(), e("idle"), y("user_started"), E();
977
+ R.bargeIn(), T(), e("idle"), y("user_started"), S();
965
978
  },
966
979
  onBotStartedSpeaking: () => {
967
980
  y("bot_started");
@@ -984,7 +997,7 @@ function Rr(e, t = {}) {
984
997
  f = c, R.setStreamTtsEngineId(c);
985
998
  },
986
999
  getTtsEngineId: () => f,
987
- speak: async (c, v) => {
1000
+ speak: async (c, E) => {
988
1001
  const L = c.trim();
989
1002
  if (L) {
990
1003
  if (!w || !l)
@@ -995,7 +1008,7 @@ function Rr(e, t = {}) {
995
1008
  }
996
1009
  },
997
1010
  stop: () => {
998
- g(), e("idle"), E();
1011
+ g(), e("idle"), S();
999
1012
  },
1000
1013
  connect: async (c) => {
1001
1014
  if (c && (m = { ...m, ...c }), !m.authToken?.trim())
@@ -1003,18 +1016,18 @@ function Rr(e, t = {}) {
1003
1016
  "Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
1004
1017
  );
1005
1018
  e("loading");
1006
- const v = U();
1007
- await v.initDevices();
1008
- const L = Ar(m);
1019
+ const E = G();
1020
+ await E.initDevices();
1021
+ const L = Rr(m);
1009
1022
  console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", L);
1010
1023
  try {
1011
- await v.connect({ wsUrl: L });
1012
- } catch (z) {
1013
- l = !1, e("error"), E();
1014
- const ne = z instanceof Error ? z.message : "Realtime voice connect failed (WebSocket 101 only means upgrade OK — check authToken/origin/RTVI handshake)";
1024
+ await E.connect({ wsUrl: L });
1025
+ } catch (X) {
1026
+ l = !1, e("error"), S();
1027
+ const ne = X instanceof Error ? X.message : "Realtime voice connect failed (WebSocket 101 only means upgrade OK — check authToken/origin/RTVI handshake)";
1015
1028
  throw new Error(`${ne} — ${L}`);
1016
1029
  }
1017
- l = !0, e("idle"), E();
1030
+ l = !0, e("idle"), S();
1018
1031
  },
1019
1032
  disconnect: async () => {
1020
1033
  if (p.length = 0, d = !1, w)
@@ -1023,7 +1036,7 @@ function Rr(e, t = {}) {
1023
1036
  } catch (c) {
1024
1037
  console.error("[realtimeVoice] disconnect failed:", c);
1025
1038
  }
1026
- l = !1, C();
1039
+ l = !1, x();
1027
1040
  },
1028
1041
  isConnected: () => l,
1029
1042
  unlockAudio: async () => {
@@ -1033,7 +1046,7 @@ function Rr(e, t = {}) {
1033
1046
  getWordQueue: () => r,
1034
1047
  getSentenceEmotions: () => s,
1035
1048
  getStreamMood: () => a,
1036
- getPlaybackElapsedMs: $,
1049
+ getPlaybackElapsedMs: V,
1037
1050
  isSpeaking: () => R.isSpeaking(),
1038
1051
  setPlaybackSpeed: (c) => {
1039
1052
  R.setPlaybackSpeed(c);
@@ -1042,7 +1055,7 @@ function Rr(e, t = {}) {
1042
1055
  subscribe: (c) => (u.add(c), () => u.delete(c))
1043
1056
  };
1044
1057
  }
1045
- function Dr(e, t, n) {
1058
+ function xr(e, t, n) {
1046
1059
  return {
1047
1060
  width: e.crop?.source_width ?? t,
1048
1061
  height: e.crop?.source_height ?? n
@@ -1057,21 +1070,21 @@ function Mr(e, t) {
1057
1070
  height: t?.source_h ?? n?.height ?? e.frame_height ?? 0
1058
1071
  };
1059
1072
  }
1060
- function Cr(e) {
1073
+ function Pr(e) {
1061
1074
  return e ? (e.w ?? 0) > 0 && (e.h ?? 0) > 0 : !1;
1062
1075
  }
1063
1076
  async function Ye(e, t) {
1064
1077
  const n = await fetch(e);
1065
1078
  if (!n.ok) throw new Error(`Failed to load encrypted asset: ${e}`);
1066
1079
  const r = await n.arrayBuffer();
1067
- return zn(r, t);
1080
+ return Yn(r, t);
1068
1081
  }
1069
- async function xr(e, t) {
1082
+ async function Br(e, t) {
1070
1083
  if (!t) throw new Error("Missing asset key for encrypted JSON");
1071
1084
  const n = await Ye(e, t), r = new TextDecoder().decode(n);
1072
1085
  return JSON.parse(r);
1073
1086
  }
1074
- async function Pr(e) {
1087
+ async function Lr(e) {
1075
1088
  const t = new Blob([e], { type: "image/webp" }), n = URL.createObjectURL(t);
1076
1089
  return new Promise((r, s) => {
1077
1090
  const i = new Image();
@@ -1082,7 +1095,7 @@ async function Pr(e) {
1082
1095
  }, i.src = n;
1083
1096
  });
1084
1097
  }
1085
- async function Br(e) {
1098
+ async function Or(e) {
1086
1099
  const t = new Blob([e], { type: "image/png" }), n = URL.createObjectURL(t);
1087
1100
  return new Promise((r, s) => {
1088
1101
  const i = new Image();
@@ -1093,28 +1106,28 @@ async function Br(e) {
1093
1106
  }, i.src = n;
1094
1107
  });
1095
1108
  }
1096
- function Lr(e) {
1109
+ function Fr(e) {
1097
1110
  const t = new Blob([e], { type: "video/mp4" });
1098
1111
  return URL.createObjectURL(t);
1099
1112
  }
1100
- async function Or(e) {
1101
- const t = Zn();
1102
- if (!Ge()) return t;
1113
+ async function Ur(e) {
1114
+ const t = er();
1115
+ if (!je()) return t;
1103
1116
  if (!e) throw new Error("Missing asset key for encrypted idle video");
1104
1117
  const n = await Ye(t, e);
1105
- return Lr(n);
1118
+ return Fr(n);
1106
1119
  }
1107
- function ht(e, t) {
1120
+ function mt(e, t) {
1108
1121
  return `${e}/${t}_minus_sil.png`;
1109
1122
  }
1110
- const on = 5;
1111
- function an(e) {
1123
+ const an = 5;
1124
+ function cn(e) {
1112
1125
  const t = e?.composite_threshold;
1113
1126
  if (typeof t == "number" && t > 0) return t;
1114
1127
  const n = e?.crop?.content_threshold;
1115
- return typeof n == "number" && n > 0 ? n : on;
1128
+ return typeof n == "number" && n > 0 ? n : an;
1116
1129
  }
1117
- const Gs = [
1130
+ const Js = [
1118
1131
  "aa",
1119
1132
  "E",
1120
1133
  "I",
@@ -1129,11 +1142,11 @@ const Gs = [
1129
1142
  "RR",
1130
1143
  "kk",
1131
1144
  "nn"
1132
- ], it = [
1145
+ ], at = [
1133
1146
  "t01_0.25",
1134
1147
  "t02_0.50",
1135
1148
  "t03_0.75"
1136
- ], Fr = it.length, Ot = /* @__PURE__ */ new Set([
1149
+ ], Nr = at.length, Ft = /* @__PURE__ */ new Set([
1137
1150
  "aa__kk",
1138
1151
  "aa__nn",
1139
1152
  "aa__sil",
@@ -1240,75 +1253,75 @@ const Gs = [
1240
1253
  "U__nn",
1241
1254
  "U__sil"
1242
1255
  ]);
1243
- function Ft(e, t) {
1256
+ function Ut(e, t) {
1244
1257
  return `${e}__${t}`;
1245
1258
  }
1246
- function Ut(e, t) {
1259
+ function Nt(e, t) {
1247
1260
  return `pairs/${e}/${t}_minus_sil.png`;
1248
1261
  }
1249
- function Ke(e) {
1262
+ function qe(e) {
1250
1263
  return `${e}_minus_sil.png`;
1251
1264
  }
1252
- function Ur(e, t) {
1265
+ function Vr(e, t) {
1253
1266
  if (t.has(e)) return e;
1254
1267
  const n = /^pairs\/([^/]+)\//.exec(e);
1255
1268
  if (!n) return null;
1256
1269
  const r = n[1].split("__")[1];
1257
1270
  if (!r || r === "sil") return null;
1258
- const s = Ke(r);
1271
+ const s = qe(r);
1259
1272
  return t.has(s) ? s : null;
1260
1273
  }
1261
- function cn(e, t) {
1274
+ function un(e, t) {
1262
1275
  return e.filter((n) => t.has(n));
1263
1276
  }
1264
- function Nr(e, t, n) {
1265
- const r = mt(e, t);
1266
- return cn(r, n).length > 0;
1277
+ function $r(e, t, n) {
1278
+ const r = wt(e, t);
1279
+ return un(r, n).length > 0;
1267
1280
  }
1268
- function mt(e, t) {
1281
+ function wt(e, t) {
1269
1282
  if (e === t) return [];
1270
- const n = [], r = Ft(e, t);
1271
- if (Ot.has(r)) {
1272
- for (const i of it)
1273
- n.push(Ut(r, i));
1283
+ const n = [], r = Ut(e, t);
1284
+ if (Ft.has(r)) {
1285
+ for (const i of at)
1286
+ n.push(Nt(r, i));
1274
1287
  return n;
1275
1288
  }
1276
- const s = Ft(t, e);
1277
- if (Ot.has(s)) {
1278
- for (let i = Fr - 1; i >= 0; i--)
1279
- n.push(Ut(s, it[i]));
1289
+ const s = Ut(t, e);
1290
+ if (Ft.has(s)) {
1291
+ for (let i = Nr - 1; i >= 0; i--)
1292
+ n.push(Nt(s, at[i]));
1280
1293
  return n;
1281
1294
  }
1282
1295
  return [];
1283
1296
  }
1284
- function Vr(e) {
1297
+ function Wr(e) {
1285
1298
  return e < 16 ? [] : e < 35 ? [1] : e < 51 ? [0, 2] : [0, 1, 2];
1286
1299
  }
1287
- function $r(e, t) {
1288
- return Vr(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);
1289
1302
  }
1290
- function Wr(e, t, n, r) {
1303
+ function qr(e, t, n, r) {
1291
1304
  if (r <= 0) return 0;
1292
1305
  const i = Math.max(1, n - t) / r, o = e - t, a = Math.floor(o / i);
1293
1306
  return Math.min(r - 1, Math.max(0, a));
1294
1307
  }
1295
- function Hr(e, t, n) {
1308
+ function Kr(e, t, n) {
1296
1309
  if (!n) return `${e}/${t}`;
1297
1310
  const r = t.split("/").pop() ?? t, s = r.includes(".") ? r.slice(0, r.lastIndexOf(".")) : r;
1298
1311
  return `${e}/${s}.bin`;
1299
1312
  }
1300
- const qr = [0.32, 0.24, 0.16, 0.08, 0], Kr = qr.map(
1313
+ const jr = [0.32, 0.24, 0.16, 0.08, 0], Gr = jr.map(
1301
1314
  (e) => `eyes_${e.toFixed(2)}`
1302
- ), jr = [
1315
+ ), zr = [
1303
1316
  "eyes_0.32",
1304
1317
  "eyes_0.16",
1305
1318
  "eyes_0.00"
1306
- ], Gr = [
1319
+ ], Yr = [
1307
1320
  "eyes_0.32",
1308
1321
  "eyes_0.16",
1309
1322
  "eyes_0.08",
1310
1323
  "eyes_0.00"
1311
- ], Nt = 2, zr = -30, ot = 20, Yr = {
1324
+ ], Vt = 2, Jr = -30, ct = 20, Qr = {
1312
1325
  fear: -30,
1313
1326
  anger: -20,
1314
1327
  sad: -10,
@@ -1317,24 +1330,24 @@ const qr = [0.32, 0.24, 0.16, 0.08, 0], Kr = qr.map(
1317
1330
  happy: 0,
1318
1331
  disgust: 20
1319
1332
  };
1320
- function wt(e) {
1333
+ function gt(e) {
1321
1334
  return `brow_${e}`;
1322
1335
  }
1323
- function gt(e) {
1324
- return Yr[e];
1336
+ function _t(e) {
1337
+ return Qr[e];
1325
1338
  }
1326
1339
  function ye(e) {
1327
- return Math.max(zr, Math.min(ot, e));
1340
+ return Math.max(Jr, Math.min(ct, e));
1328
1341
  }
1329
- function Jr(e, t) {
1342
+ function Xr(e, t) {
1330
1343
  if (e === t) return [];
1331
- const n = e < t ? Nt : -Nt, r = [];
1344
+ const n = e < t ? Vt : -Vt, r = [];
1332
1345
  let s = e;
1333
1346
  for (; s !== t; )
1334
1347
  s += n, r.push(s);
1335
1348
  return r;
1336
1349
  }
1337
- const Qr = {
1350
+ const Zr = {
1338
1351
  fear: "fear",
1339
1352
  afraid: "fear",
1340
1353
  anxiety: "fear",
@@ -1357,63 +1370,63 @@ const Qr = {
1357
1370
  disgust: "disgust",
1358
1371
  disgusted: "disgust"
1359
1372
  };
1360
- function ve(e, t = "neutral") {
1373
+ function be(e, t = "neutral") {
1361
1374
  const n = String(e ?? "").trim().toLowerCase();
1362
- return n ? Qr[n] ?? t : t;
1363
- }
1364
- function un(e) {
1365
- return e === 0 ? null : ht(wt(e), "eyes_standard");
1375
+ return n ? Zr[n] ?? t : t;
1366
1376
  }
1367
1377
  function ln(e) {
1368
- return un(gt(e));
1378
+ return e === 0 ? null : mt(gt(e), "eyes_standard");
1369
1379
  }
1370
- function Vt(e, t) {
1371
- const n = wt(gt(e));
1372
- return !t || t === "eyes_standard" ? ln(e) : e === "neutral" && t === "eyes_standard" ? null : ht(n, t);
1380
+ function fn(e) {
1381
+ return ln(_t(e));
1373
1382
  }
1374
- function Xr(e, t) {
1383
+ function $t(e, t) {
1384
+ const n = gt(_t(e));
1385
+ return !t || t === "eyes_standard" ? fn(e) : e === "neutral" && t === "eyes_standard" ? null : mt(n, t);
1386
+ }
1387
+ function es(e, t) {
1375
1388
  const n = [];
1376
1389
  for (const r of t)
1377
- n.push(Vt(e, r));
1390
+ n.push($t(e, r));
1378
1391
  for (let r = t.length - 2; r >= 0; r--)
1379
- n.push(Vt(e, t[r]));
1380
- return n.push(ln(e)), n;
1392
+ n.push($t(e, t[r]));
1393
+ return n.push(fn(e)), n;
1381
1394
  }
1382
- function Zr(e) {
1383
- return e === 0 ? null : ht(wt(e), "eyes_standard");
1395
+ function ts(e) {
1396
+ return e === 0 ? null : mt(gt(e), "eyes_standard");
1384
1397
  }
1385
- function es(e, t) {
1386
- return Jr(e, t).map(Zr).filter((n) => n != null);
1387
- }
1388
- const ts = 6;
1389
1398
  function ns(e, t) {
1399
+ return Xr(e, t).map(ts).filter((n) => n != null);
1400
+ }
1401
+ const rs = 6;
1402
+ function ss(e, t) {
1390
1403
  for (const n of e)
1391
1404
  if (t >= n.wtime && t < n.wtime + n.wduration)
1392
1405
  return n;
1393
1406
  return null;
1394
1407
  }
1395
- function rs(e) {
1408
+ function is(e) {
1396
1409
  const t = ye(e);
1397
- return t >= ot ? ot : ye(t + ts);
1410
+ return t >= ct ? ct : ye(t + rs);
1398
1411
  }
1399
- function ss(e, t, n) {
1412
+ function os(e, t, n) {
1400
1413
  const r = ye(n);
1401
- return ns(t, e)?.emphasis ? rs(r) : r;
1414
+ return ss(t, e)?.emphasis ? is(r) : r;
1402
1415
  }
1403
- function $t(e) {
1416
+ function Wt(e) {
1404
1417
  if (!e) return 0;
1405
1418
  const t = e.match(/^brow_(-?\d+)\//);
1406
1419
  if (!t?.[1]) return null;
1407
1420
  const n = Number.parseInt(t[1], 10);
1408
1421
  return Number.isFinite(n) ? ye(n) : null;
1409
1422
  }
1410
- function Fe(e, t) {
1423
+ function Oe(e, t) {
1411
1424
  return e + Math.random() * (t - e);
1412
1425
  }
1413
- function He() {
1414
- return Fe(14, 32);
1426
+ function We() {
1427
+ return Oe(14, 32);
1415
1428
  }
1416
- function is(e = {}) {
1429
+ function as(e = {}) {
1417
1430
  const {
1418
1431
  initialDelayMs: t = 800 + Math.random() * 1200,
1419
1432
  intervalMinMs: n = 2200,
@@ -1425,130 +1438,130 @@ function is(e = {}) {
1425
1438
  postEmotionChangeDelayMs: f = 380,
1426
1439
  minDwellMs: l = 550
1427
1440
  } = e;
1428
- let w = "neutral", _ = "neutral", m = 0, k = 0, S = 0, u = {
1441
+ let w = "neutral", _ = "neutral", m = 0, v = 0, k = 0, u = {
1429
1442
  kind: "idle",
1430
1443
  nextBlinkAt: performance.now() + t
1431
1444
  }, p = null, d = "__eyes_open__|neutral|brow:0";
1432
1445
  function I(y = w) {
1433
- d = `${p ?? "__eyes_open__"}|${y}|brow:${k}`;
1446
+ d = `${p ?? "__eyes_open__"}|${y}|brow:${v}`;
1434
1447
  }
1435
- function E(y, T = w) {
1448
+ function S(y, T = w) {
1436
1449
  p = y;
1437
- const g = $t(y);
1438
- g != null ? k = g : y == null && (k = 0), I(T);
1450
+ const g = Wt(y);
1451
+ g != null ? v = g : y == null && (v = 0), I(T);
1439
1452
  }
1440
1453
  function R(y) {
1441
- return un(y);
1454
+ return ln(y);
1442
1455
  }
1443
- function H(y, T, g) {
1444
- const C = ye(T), b = ye(g);
1445
- if (m = b, C === b) {
1446
- E(R(b));
1456
+ function q(y, T, g) {
1457
+ const x = ye(T), b = ye(g);
1458
+ if (m = b, x === b) {
1459
+ S(R(b));
1447
1460
  return;
1448
1461
  }
1449
1462
  const D = [
1450
- ...es(C, b),
1463
+ ...ns(x, b),
1451
1464
  R(b)
1452
1465
  ];
1453
1466
  u = {
1454
1467
  kind: "browBlend",
1455
1468
  paths: D,
1456
1469
  index: 0,
1457
- holdUntil: y + He(),
1470
+ holdUntil: y + We(),
1458
1471
  targetBrow: b
1459
- }, E(D[0] ?? null);
1472
+ }, S(D[0] ?? null);
1460
1473
  }
1461
- function V(y, T) {
1474
+ function N(y, T) {
1462
1475
  u = {
1463
1476
  kind: "idle",
1464
- nextBlinkAt: y + Fe(n, r)
1465
- }, _ = T, E(R(m), T);
1477
+ nextBlinkAt: y + Oe(n, r)
1478
+ }, _ = T, S(R(m), T);
1466
1479
  }
1467
- function $(y, T, g) {
1468
- const C = g ? jr : Math.random() < a ? Kr : Gr;
1480
+ function V(y, T, g) {
1481
+ const x = g ? zr : Math.random() < a ? Gr : Yr;
1469
1482
  u = {
1470
1483
  kind: "playing",
1471
- paths: Xr(T, C),
1484
+ paths: es(T, x),
1472
1485
  index: 0,
1473
- holdUntil: y + He(),
1486
+ holdUntil: y + We(),
1474
1487
  after: "idle",
1475
1488
  blinkEmotion: T
1476
- }, _ = T, E(u.paths[0] ?? null, T);
1489
+ }, _ = T, S(u.paths[0] ?? null, T);
1477
1490
  }
1478
- function j(y) {
1491
+ function z(y) {
1479
1492
  if (u.kind === "browBlend") {
1480
1493
  for (; y >= u.holdUntil && u.index < u.paths.length - 1; )
1481
- u.index += 1, u.holdUntil = y + He();
1494
+ u.index += 1, u.holdUntil = y + We();
1482
1495
  const T = u.paths[u.index] ?? null;
1483
- E(T), y >= u.holdUntil && u.index >= u.paths.length - 1 && (k = u.targetBrow, m = u.targetBrow, E(R(u.targetBrow)), u = {
1496
+ S(T), y >= u.holdUntil && u.index >= u.paths.length - 1 && (v = u.targetBrow, m = u.targetBrow, S(R(u.targetBrow)), u = {
1484
1497
  kind: "idle",
1485
1498
  nextBlinkAt: y + f
1486
1499
  });
1487
1500
  return;
1488
1501
  }
1489
1502
  if (u.kind === "idle") {
1490
- E(R(m), _), y >= u.nextBlinkAt && $(y, _, !1);
1503
+ S(R(m), _), y >= u.nextBlinkAt && V(y, _, !1);
1491
1504
  return;
1492
1505
  }
1493
1506
  if (u.kind === "doublePause") {
1494
- E(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);
1495
1508
  return;
1496
1509
  }
1497
1510
  if (u.kind === "playing") {
1498
1511
  for (; y >= u.holdUntil && u.index < u.paths.length - 1; )
1499
- u.index += 1, u.holdUntil = y + He();
1500
- if (E(u.paths[u.index] ?? null, u.blinkEmotion), y >= u.holdUntil && u.index >= u.paths.length - 1) {
1512
+ u.index += 1, u.holdUntil = y + We();
1513
+ if (S(u.paths[u.index] ?? null, u.blinkEmotion), y >= u.holdUntil && u.index >= u.paths.length - 1) {
1501
1514
  if (u.after === "resumeIdle") {
1502
- V(y + f, w);
1515
+ N(y + f, w);
1503
1516
  return;
1504
1517
  }
1505
1518
  if (u.after === "doublePause") {
1506
1519
  u = {
1507
1520
  kind: "doublePause",
1508
- resumeAt: y + Fe(i, o),
1521
+ resumeAt: y + Oe(i, o),
1509
1522
  blinkEmotion: u.blinkEmotion
1510
- }, E(R(m), u.blinkEmotion);
1523
+ }, S(R(m), u.blinkEmotion);
1511
1524
  return;
1512
1525
  }
1513
1526
  if (u.after === "idle" && Math.random() < s) {
1514
1527
  u = {
1515
1528
  kind: "doublePause",
1516
- resumeAt: y + Fe(i, o),
1529
+ resumeAt: y + Oe(i, o),
1517
1530
  blinkEmotion: u.blinkEmotion
1518
- }, E(R(m), u.blinkEmotion);
1531
+ }, S(R(m), u.blinkEmotion);
1519
1532
  return;
1520
1533
  }
1521
- V(y, u.blinkEmotion);
1534
+ N(y, u.blinkEmotion);
1522
1535
  }
1523
1536
  }
1524
1537
  }
1525
1538
  return {
1526
- advance: j,
1539
+ advance: z,
1527
1540
  setTargetEmotion(y) {
1528
- const T = ve(y, w);
1541
+ const T = be(y, w);
1529
1542
  if (T === w) return;
1530
1543
  const g = performance.now();
1531
- l > 0 && T !== w && !(w === "neutral" && T !== "neutral") && g - S < l || (w = T, _ = T, S = g);
1544
+ l > 0 && T !== w && !(w === "neutral" && T !== "neutral") && g - k < l || (w = T, _ = T, k = g);
1532
1545
  },
1533
1546
  setTargetEyebrow(y) {
1534
1547
  const T = ye(y);
1535
1548
  if (T === m && u.kind !== "browBlend") return;
1536
- const g = performance.now(), C = u.kind === "browBlend" ? $t(p) ?? k : k;
1537
- m = T, !(T === C && u.kind !== "browBlend") && (u.kind === "playing" || u.kind === "doublePause" || H(g, C, 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));
1538
1551
  },
1539
1552
  getTargetEmotion: () => w,
1540
1553
  getTargetEyebrow: () => m,
1541
1554
  getExpressionPath: () => p,
1542
1555
  getDrawKey: () => d,
1543
1556
  reset() {
1544
- w = "neutral", _ = "neutral", m = 0, k = 0, S = 0, V(
1545
- performance.now() + Fe(n, r),
1557
+ w = "neutral", _ = "neutral", m = 0, v = 0, k = 0, N(
1558
+ performance.now() + Oe(n, r),
1546
1559
  "neutral"
1547
1560
  );
1548
1561
  }
1549
1562
  };
1550
1563
  }
1551
- function os() {
1564
+ function cs() {
1552
1565
  const e = document.createElement("video");
1553
1566
  e.muted = !0, e.playsInline = !0, e.preload = "auto", e.setAttribute("playsinline", ""), e.loop = !0;
1554
1567
  let t = !1, n = null, r = "";
@@ -1591,17 +1604,17 @@ function os() {
1591
1604
  }
1592
1605
  };
1593
1606
  }
1594
- const as = 50, fn = 400;
1595
- function cs(e, t, n) {
1607
+ const us = 50, dn = 400;
1608
+ function ls(e, t, n) {
1596
1609
  return e.filter((r) => {
1597
1610
  const s = r.queueIndex ?? -1;
1598
1611
  return s >= t && s <= n;
1599
1612
  });
1600
1613
  }
1601
- function us(e, t) {
1614
+ function fs(e, t) {
1602
1615
  const n = [];
1603
1616
  for (const r of e) {
1604
- const s = cs(
1617
+ const s = ls(
1605
1618
  t,
1606
1619
  r.start_word,
1607
1620
  r.end_word
@@ -1610,30 +1623,30 @@ function us(e, t) {
1610
1623
  const i = s[0], o = s[s.length - 1];
1611
1624
  n.push({
1612
1625
  sentence: r,
1613
- startMs: Math.max(0, i.wtime - as),
1614
- endMs: o.wtime + o.wduration + fn
1626
+ startMs: Math.max(0, i.wtime - us),
1627
+ endMs: o.wtime + o.wduration + dn
1615
1628
  });
1616
1629
  }
1617
1630
  return n.sort((r, s) => r.startMs - s.startMs);
1618
1631
  }
1619
- function ls(e, t, n, r = "neutral") {
1620
- const s = ve(r);
1632
+ function ds(e, t, n, r = "neutral") {
1633
+ const s = be(r);
1621
1634
  if (t.length === 0) return s;
1622
1635
  if (n.length === 0 || e < n[0].wtime)
1623
- return ve(t[0]?.emotion, s);
1624
- const i = us(t, n);
1636
+ return be(t[0]?.emotion, s);
1637
+ const i = fs(t, n);
1625
1638
  let o = null;
1626
1639
  for (const l of i)
1627
1640
  e >= l.startMs && e <= l.endMs && (o = l);
1628
1641
  if (o)
1629
- return ve(o.sentence.emotion, s);
1642
+ return be(o.sentence.emotion, s);
1630
1643
  const a = n[n.length - 1], f = a.wtime + a.wduration;
1631
- return e > f + fn ? ve(
1644
+ return e > f + dn ? be(
1632
1645
  t[t.length - 1]?.emotion,
1633
1646
  s
1634
1647
  ) : s;
1635
1648
  }
1636
- function dn(e, t, n, r, s = on) {
1649
+ function hn(e, t, n, r, s = an) {
1637
1650
  const i = new OffscreenCanvas(n, r), o = i.getContext("2d", { willReadFrequently: !0 });
1638
1651
  o.drawImage(e, 0, 0, n, r);
1639
1652
  const a = o.getImageData(0, 0, n, r), f = o.createImageData(n, r);
@@ -1642,45 +1655,45 @@ function dn(e, t, n, r, s = on) {
1642
1655
  for (const _ of t) {
1643
1656
  w.clearRect(0, 0, n, r), w.drawImage(_, 0, 0, n, r);
1644
1657
  const m = w.getImageData(0, 0, n, r);
1645
- for (let k = 0; k < f.data.length; k += 4) {
1646
- const S = m.data[k], u = m.data[k + 1], p = m.data[k + 2];
1647
- Math.max(S, u, p) > s && (f.data[k] = S, f.data[k + 1] = u, f.data[k + 2] = p, f.data[k + 3] = 255);
1658
+ for (let v = 0; v < f.data.length; v += 4) {
1659
+ const k = m.data[v], u = m.data[v + 1], p = m.data[v + 2];
1660
+ Math.max(k, u, p) > s && (f.data[v] = k, f.data[v + 1] = u, f.data[v + 2] = p, f.data[v + 3] = 255);
1648
1661
  }
1649
1662
  }
1650
1663
  return o.putImageData(f, 0, 0), i;
1651
1664
  }
1652
- let pe = null, Ue = null;
1653
- const je = /* @__PURE__ */ new Map();
1654
- function fs() {
1655
- pe = null, Ue = null, je.clear();
1665
+ let pe = null, Fe = null;
1666
+ const Ke = /* @__PURE__ */ new Map();
1667
+ function hs() {
1668
+ pe = null, Fe = null, Ke.clear();
1656
1669
  }
1657
- Xn(fs);
1658
- function ds(e) {
1659
- return e ?? Ue ?? void 0;
1670
+ Zn(hs);
1671
+ function ms(e) {
1672
+ return e ?? Fe ?? void 0;
1660
1673
  }
1661
- function _t(e) {
1674
+ function pt(e) {
1662
1675
  return new Promise((t, n) => {
1663
1676
  const r = new Image();
1664
1677
  r.decoding = "async", r.onload = () => t(r), r.onerror = () => n(new Error(`Failed to load image: ${e}`)), r.src = e;
1665
1678
  });
1666
1679
  }
1667
- async function hs(e) {
1668
- return Ge() ? Br(
1669
- await Ye(Ct(), e ?? "")
1670
- ) : _t(Ct());
1680
+ async function ws(e) {
1681
+ return je() ? Or(
1682
+ await Ye(Mt(), e ?? "")
1683
+ ) : pt(Mt());
1671
1684
  }
1672
- async function Wt(e, t, n, r) {
1673
- const s = n ? await xr(e, r) : await fetch(e).then((l) => {
1685
+ async function Ht(e, t, n, r) {
1686
+ const s = n ? await Br(e, r) : await fetch(e).then((l) => {
1674
1687
  if (!l.ok) throw new Error(`Failed to load ${e}`);
1675
1688
  return l.json();
1676
1689
  }), i = s.sheets?.[0];
1677
1690
  if (!i?.path) throw new Error(`${e} has no sheets[0].path`);
1678
- const o = n ? await Pr(
1691
+ const o = n ? await Lr(
1679
1692
  await Ye(
1680
- Hr(t, i.path, n),
1693
+ Kr(t, i.path, n),
1681
1694
  r ?? ""
1682
1695
  )
1683
- ) : await _t(`${t}/${i.path}`), a = /* @__PURE__ */ new Map();
1696
+ ) : await pt(`${t}/${i.path}`), a = /* @__PURE__ */ new Map();
1684
1697
  for (const l of s.cells ?? [])
1685
1698
  l.path && a.set(l.path, l);
1686
1699
  const f = /* @__PURE__ */ new Map();
@@ -1688,30 +1701,30 @@ async function Wt(e, t, n, r) {
1688
1701
  f.set(l.index, l);
1689
1702
  return { atlas: o, atlasMeta: s, cellByPath: a, sheetByIndex: f, diffBase: t };
1690
1703
  }
1691
- async function at(e) {
1692
- const t = ds(e), n = Ge();
1704
+ async function ut(e) {
1705
+ const t = ms(e), n = je();
1693
1706
  if (n && !t)
1694
1707
  throw new Error("Encrypted assets enabled but no key provided");
1695
- if (pe && (!n || Ue === (t ?? null))) {
1708
+ if (pe && (!n || Fe === (t ?? null))) {
1696
1709
  const i = await pe;
1697
1710
  return {
1698
- ...Ne(i),
1711
+ ...Ue(i),
1699
1712
  visemePaths: [...i.viseme.cellByPath.keys()]
1700
1713
  };
1701
1714
  }
1702
- Ue = t ?? null, je.clear();
1703
- const r = er();
1715
+ Fe = t ?? null, Ke.clear();
1716
+ const r = tr();
1704
1717
  pe = (async () => {
1705
- const i = await hs(t), o = await Wt(
1706
- tr(),
1718
+ const i = await ws(t), o = await Ht(
1719
+ nr(),
1707
1720
  r,
1708
1721
  n,
1709
1722
  t
1710
1723
  );
1711
1724
  let a = null;
1712
1725
  try {
1713
- a = await Wt(
1714
- nr(),
1726
+ a = await Ht(
1727
+ rr(),
1715
1728
  r,
1716
1729
  n,
1717
1730
  t
@@ -1722,89 +1735,89 @@ async function at(e) {
1722
1735
  return { sil: i, viseme: o, expression: a };
1723
1736
  })();
1724
1737
  const s = await pe;
1725
- return { ...Ne(s), visemePaths: [...s.viseme.cellByPath.keys()] };
1738
+ return { ...Ue(s), visemePaths: [...s.viseme.cellByPath.keys()] };
1726
1739
  }
1727
- async function hn(e) {
1728
- if (await at(e), !pe) throw new Error("Assets not loaded");
1740
+ async function mn(e) {
1741
+ if (await ut(e), !pe) throw new Error("Assets not loaded");
1729
1742
  return pe;
1730
1743
  }
1731
- function Ne(e) {
1732
- return Dr(
1744
+ function Ue(e) {
1745
+ return xr(
1733
1746
  e.viseme.atlasMeta,
1734
1747
  e.sil.naturalWidth,
1735
1748
  e.sil.naturalHeight
1736
1749
  );
1737
1750
  }
1738
- function ms(e, t) {
1751
+ function gs(e, t) {
1739
1752
  const n = document.createElement("canvas");
1740
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;
1741
1754
  }
1742
- async function Ht(e, t, n) {
1743
- const r = `${t.diffBase}::${n}`, s = je.get(r);
1755
+ async function qt(e, t, n) {
1756
+ const r = `${t.diffBase}::${n}`, s = Ke.get(r);
1744
1757
  if (s) return s;
1745
1758
  const i = (async () => {
1746
1759
  const o = t.cellByPath.get(n);
1747
1760
  if (!o) throw new Error(`No atlas cell for path: ${n}`);
1748
- const a = Mr(t.atlasMeta, o), f = Ne(e);
1749
- if (Cr(o)) {
1750
- const _ = ms(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");
1751
1764
  m.width = f.width, m.height = f.height;
1752
- const k = m.getContext("2d");
1753
- return k.fillStyle = "#000", k.fillRect(0, 0, f.width, f.height), k.drawImage(_, a.x, a.y), m;
1765
+ const v = m.getContext("2d");
1766
+ return v.fillStyle = "#000", v.fillRect(0, 0, f.width, f.height), v.drawImage(_, a.x, a.y), m;
1754
1767
  }
1755
- const l = `${t.diffBase}/${n}`, w = await _t(l);
1768
+ const l = `${t.diffBase}/${n}`, w = await pt(l);
1756
1769
  if (w.naturalWidth === f.width && w.naturalHeight === f.height)
1757
1770
  return w;
1758
1771
  throw new Error(`Diff PNG wrong size for ${n}`);
1759
1772
  })();
1760
- return je.set(r, i), i;
1773
+ return Ke.set(r, i), i;
1761
1774
  }
1762
- async function qt(e, t, n, r, s, i) {
1775
+ async function Kt(e, t, n, r, s, i) {
1763
1776
  if (s) {
1764
- const { width: k, height: S } = s;
1777
+ const { width: v, height: k } = s;
1765
1778
  if (i && !i() || t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
1766
1779
  return;
1767
1780
  const u = document.createElement("canvas");
1768
- u.width = k, u.height = S;
1781
+ u.width = v, u.height = k;
1769
1782
  const p = u.getContext("2d");
1770
- if (p.clearRect(0, 0, k, S), p.drawImage(t, 0, 0, k, S), i && !i()) return;
1771
- (e.width !== k || e.height !== S) && (e.width = k, e.height = S);
1783
+ if (p.clearRect(0, 0, v, k), p.drawImage(t, 0, 0, v, k), i && !i()) return;
1784
+ (e.width !== v || e.height !== k) && (e.width = v, e.height = k);
1772
1785
  const d = e.getContext("2d");
1773
- d.clearRect(0, 0, k, S), d.drawImage(u, 0, 0);
1786
+ d.clearRect(0, 0, v, k), d.drawImage(u, 0, 0);
1774
1787
  return;
1775
1788
  }
1776
- const o = await hn(), a = an(o.viseme.atlasMeta), { width: f, height: l } = Ne(o);
1789
+ const o = await mn(), a = cn(o.viseme.atlasMeta), { width: f, height: l } = Ue(o);
1777
1790
  (e.width !== f || e.height !== l) && (e.width = f, e.height = l);
1778
1791
  const w = [], _ = e.getContext("2d");
1779
1792
  if (_.clearRect(0, 0, f, l), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
1780
- const k = o.sil;
1781
- _.drawImage(k, 0, 0, f, l);
1793
+ const v = o.sil;
1794
+ _.drawImage(v, 0, 0, f, l);
1782
1795
  return;
1783
1796
  }
1784
1797
  if (w.length === 0) {
1785
1798
  _.drawImage(t, 0, 0, f, l);
1786
1799
  return;
1787
1800
  }
1788
- const m = dn(t, w, f, l, a);
1801
+ const m = hn(t, w, f, l, a);
1789
1802
  _.drawImage(m, 0, 0);
1790
1803
  }
1791
- async function ct(e, t, n) {
1792
- const r = await hn(Ue ?? void 0), s = an(r.viseme.atlasMeta), { width: i, height: o } = Ne(r);
1804
+ async function lt(e, t, n) {
1805
+ const r = await mn(Fe ?? void 0), s = cn(r.viseme.atlasMeta), { width: i, height: o } = Ue(r);
1793
1806
  (e.width !== i || e.height !== o) && (e.width = i, e.height = o);
1794
1807
  const a = [];
1795
1808
  if (t.mouthPath) {
1796
- const w = new Set(r.viseme.cellByPath.keys()), _ = Ur(t.mouthPath, w) ?? (w.has(t.mouthPath) ? t.mouthPath : null);
1797
- _ && a.push(await Ht(r, r.viseme, _));
1809
+ const w = new Set(r.viseme.cellByPath.keys()), _ = Vr(t.mouthPath, w) ?? (w.has(t.mouthPath) ? t.mouthPath : null);
1810
+ _ && a.push(await qt(r, r.viseme, _));
1798
1811
  }
1799
1812
  t.expressionPath && r.expression && a.push(
1800
- await Ht(r, r.expression, t.expressionPath)
1813
+ await qt(r, r.expression, t.expressionPath)
1801
1814
  );
1802
1815
  const f = e.getContext("2d");
1803
1816
  if (f.clearRect(0, 0, i, o), a.length === 0) {
1804
1817
  f.drawImage(r.sil, 0, 0, i, o);
1805
1818
  return;
1806
1819
  }
1807
- const l = dn(
1820
+ const l = hn(
1808
1821
  r.sil,
1809
1822
  a,
1810
1823
  i,
@@ -1813,75 +1826,81 @@ async function ct(e, t, n) {
1813
1826
  );
1814
1827
  f.drawImage(l, 0, 0);
1815
1828
  }
1816
- async function ws(e) {
1817
- await ct(e, { mouthPath: null, expressionPath: null });
1829
+ async function _s(e) {
1830
+ await lt(e, { mouthPath: null, expressionPath: null });
1818
1831
  }
1819
- function gs(e) {
1832
+ function ps(e) {
1820
1833
  const t = /* @__PURE__ */ new Map();
1821
1834
  for (const n of e)
1822
1835
  t.has(n.vtime) || t.set(n.vtime, n);
1823
1836
  return [...t.values()].sort((n, r) => n.vtime - r.vtime);
1824
1837
  }
1825
- function _s(e) {
1826
- const t = gs(e), n = [];
1838
+ function ys(e) {
1839
+ const t = ps(e), n = [];
1827
1840
  for (let r = 0; r < t.length - 1; r++) {
1828
1841
  const s = t[r].viseme, i = t[r + 1].viseme, o = t[r].vtime, a = t[r + 1].vtime;
1829
1842
  s === i || a <= o || n.push({ from: s, to: i, fromVtime: o, toVtime: a });
1830
1843
  }
1831
1844
  return n;
1832
1845
  }
1833
- function ps(e, t) {
1846
+ function Es(e, t) {
1834
1847
  let n = null;
1835
1848
  for (const r of e)
1836
1849
  t >= r.fromVtime && t < r.toVtime && (n = r);
1837
1850
  return n;
1838
1851
  }
1839
- function ys(e, t) {
1852
+ function Ss(e, t) {
1840
1853
  return { gapMs: Math.max(0, t - e), holdEnd: e, transStart: e };
1841
1854
  }
1842
- const mn = 400, Es = 200, Ss = 600, wn = "__sil__";
1843
- function ks(e) {
1844
- return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] === wn : !1;
1855
+ const wn = 400, ks = 200, vs = 600, gn = "__sil__";
1856
+ function bs(e) {
1857
+ return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] === gn : !1;
1845
1858
  }
1846
- function vs() {
1859
+ function Ts() {
1847
1860
  return { lastDrawnKey: "" };
1848
1861
  }
1849
- function fe(e) {
1862
+ function de(e) {
1850
1863
  e.lastDrawnKey = "", e.transitionCache = void 0;
1851
1864
  }
1852
- function bs(e, t) {
1865
+ function As(e, t) {
1853
1866
  if (t?.transitionCache && t.transitionCache.queueLength === e.length)
1854
1867
  return t.transitionCache.transitions;
1855
- const n = _s(e);
1868
+ const n = ys(e);
1856
1869
  return t && (t.transitionCache = { queueLength: e.length, transitions: n }), n;
1857
1870
  }
1858
- function Ts(e) {
1859
- let t = "sil";
1860
- for (const n of e)
1861
- n.viseme !== "sil" && (t = n.viseme);
1862
- return t;
1871
+ function Is(e, t) {
1872
+ let n = "sil";
1873
+ for (const r of e)
1874
+ r.viseme !== "sil" && (t != null && r.vtime > t || (n = r.viseme));
1875
+ return n;
1863
1876
  }
1864
- function As(e, t) {
1865
- return e === "sil" ? !1 : t ? Nr(e, "sil", t) : mt(e, "sil").length > 0;
1877
+ function Rs(e, t, n, r = 120) {
1878
+ if (n !== "sil")
1879
+ return n;
1880
+ const s = kr(e, t, r);
1881
+ return s !== "sil" ? s : Is(e, t);
1882
+ }
1883
+ function Ds(e, t) {
1884
+ return e === "sil" ? !1 : t ? $r(e, "sil", t) : wt(e, "sil").length > 0;
1866
1885
  }
1867
- function Is() {
1868
- return mn + Ss;
1886
+ function Cs() {
1887
+ return wn + vs;
1869
1888
  }
1870
- function Kt(e) {
1871
- return e ?? wn;
1889
+ function jt(e) {
1890
+ return e ?? gn;
1872
1891
  }
1873
- function Rs(e, t, n, r) {
1892
+ function xs(e, t, n, r) {
1874
1893
  if (e.length === 0)
1875
1894
  return { diffPath: null, label: "sil" };
1876
- const s = bs(e, r), i = ps(s, t);
1895
+ const s = As(e, r), i = Es(s, t);
1877
1896
  if (i) {
1878
- const a = i.toVtime - i.fromVtime, f = ys(i.fromVtime, i.toVtime);
1897
+ const a = i.toVtime - i.fromVtime, f = Ss(i.fromVtime, i.toVtime);
1879
1898
  if (t >= f.transStart && t < i.toVtime) {
1880
- let l = mt(i.from, i.to);
1881
- n && (l = cn(l, n));
1882
- const w = $r(l, a);
1899
+ let l = wt(i.from, i.to);
1900
+ n && (l = un(l, n));
1901
+ const w = Hr(l, a);
1883
1902
  if (w.length > 0) {
1884
- const _ = Wr(
1903
+ const _ = qr(
1885
1904
  t,
1886
1905
  f.transStart,
1887
1906
  i.toVtime,
@@ -1889,34 +1908,34 @@ function Rs(e, t, n, r) {
1889
1908
  );
1890
1909
  return { diffPath: w[_] ?? w[w.length - 1], label: `${i.from}→${i.to}` };
1891
1910
  }
1892
- return { diffPath: Ke(i.to), label: i.to };
1911
+ return { diffPath: qe(i.to), label: i.to };
1893
1912
  }
1894
1913
  }
1895
- const o = ft(e, t);
1896
- return o === "sil" ? { diffPath: null, label: "sil" } : { diffPath: Ke(o), label: o };
1914
+ const o = ze(e, t);
1915
+ return o === "sil" ? { diffPath: null, label: "sil" } : { diffPath: qe(o), label: o };
1897
1916
  }
1898
- function gn(e, t) {
1899
- const n = t ?? Kt(e.expressionPath);
1900
- return `${Kt(e.mouthPath)}|${n}`;
1917
+ function _n(e, t) {
1918
+ const n = t ?? jt(e.expressionPath);
1919
+ return `${jt(e.mouthPath)}|${n}`;
1901
1920
  }
1902
- function Ds(e, t, n, r, s, i, o, a, f, l) {
1903
- const w = Rs(t, n, f, i), _ = {
1921
+ function Ms(e, t, n, r, s, i, o, a, f, l) {
1922
+ const w = xs(t, n, f, i), _ = {
1904
1923
  mouthPath: w.diffPath,
1905
1924
  expressionPath: r
1906
- }, m = gn(_, s);
1907
- m !== i.lastDrawnKey && (a(w.label), o(e, _, m, (k) => {
1908
- k === m && (i.lastDrawnKey = m);
1925
+ }, m = _n(_, s);
1926
+ m !== i.lastDrawnKey && (a(w.label), o(e, _, m, (v) => {
1927
+ v === m && (i.lastDrawnKey = m);
1909
1928
  }));
1910
1929
  }
1911
- function jt(e, t, n, r, s, i, o = null) {
1912
- const a = { mouthPath: null, expressionPath: t }, f = o != null ? `|idle@${Math.round(o * 1e3)}` : "", l = gn(a, n) + f;
1930
+ function Gt(e, t, n, r, s, i, o = null) {
1931
+ const a = { mouthPath: null, expressionPath: t }, f = o != null ? `|idle@${Math.round(o * 1e3)}` : "", l = _n(a, n) + f;
1913
1932
  !(o != null) && l === r.lastDrawnKey || (i(
1914
1933
  o != null ? "idle" : "sil"
1915
1934
  ), s(e, a, l, (_) => {
1916
1935
  _ === l && (r.lastDrawnKey = l);
1917
1936
  }));
1918
1937
  }
1919
- function _n(e) {
1938
+ function pn(e) {
1920
1939
  let t = 0, n = null, r = !1, s = !1;
1921
1940
  const i = async () => {
1922
1941
  if (!r) {
@@ -1952,9 +1971,9 @@ function _n(e) {
1952
1971
  }
1953
1972
  };
1954
1973
  }
1955
- const Gt = -1, zt = /* @__PURE__ */ new Map();
1956
- async function Ms(e) {
1957
- let t = zt.get(e);
1974
+ const zt = -1, Yt = /* @__PURE__ */ new Map();
1975
+ async function Ps(e) {
1976
+ let t = Yt.get(e);
1958
1977
  if (!t) {
1959
1978
  const n = await fetch(e);
1960
1979
  if (!n.ok)
@@ -1962,32 +1981,32 @@ async function Ms(e) {
1962
1981
  `Failed to fetch worker script (${n.status}): ${e}`
1963
1982
  );
1964
1983
  const r = await n.blob();
1965
- t = URL.createObjectURL(r), zt.set(e, t);
1984
+ t = URL.createObjectURL(r), Yt.set(e, t);
1966
1985
  }
1967
1986
  return new Worker(t, { name: "visemeDiffPreview" });
1968
1987
  }
1969
- function Cs() {
1988
+ function Bs() {
1970
1989
  return typeof Worker < "u" && typeof OffscreenCanvas < "u";
1971
1990
  }
1972
- function xs(e, t) {
1991
+ function Ls(e, t) {
1973
1992
  (e.width !== t.width || e.height !== t.height) && (e.width = t.width, e.height = t.height);
1974
1993
  const n = e.getContext("2d");
1975
1994
  n && n.drawImage(t, 0, 0);
1976
1995
  }
1977
- function Yt(e, t) {
1996
+ function Jt(e, t) {
1978
1997
  let n = 0, r = null;
1979
- const s = _n(async (i, o) => (await at(), await ct(e, i), s.isLatestSeq(o)));
1998
+ const s = pn(async (i, o) => (await ut(), await lt(e, i), s.isLatestSeq(o)));
1980
1999
  return {
1981
2000
  usesWorker: !1,
1982
2001
  async loadAssets(i) {
1983
- const o = await at(i);
2002
+ const o = await ut(i);
1984
2003
  return r = o.visemePaths ? new Set(o.visemePaths) : null, o;
1985
2004
  },
1986
2005
  getVisemeAtlasPaths() {
1987
2006
  return r;
1988
2007
  },
1989
2008
  async renderSilOnly() {
1990
- n += 1, s.reset(), await ws(e);
2009
+ n += 1, s.reset(), await _s(e);
1991
2010
  },
1992
2011
  drawLiveFrame(i, o, a, f) {
1993
2012
  s.enqueue(o, a, f);
@@ -1995,8 +2014,8 @@ function Yt(e, t) {
1995
2014
  async renderViseme(i, o) {
1996
2015
  n += 1;
1997
2016
  const a = n;
1998
- t.onStatus?.(o), await ct(i, {
1999
- mouthPath: Ke(o),
2017
+ t.onStatus?.(o), await lt(i, {
2018
+ mouthPath: qe(o),
2000
2019
  expressionPath: null
2001
2020
  });
2002
2021
  },
@@ -2005,12 +2024,12 @@ function Yt(e, t) {
2005
2024
  }
2006
2025
  };
2007
2026
  }
2008
- function Ps(e, t, n) {
2027
+ function Os(e, t, n) {
2009
2028
  let r = null, s = 1, i = 0, o = !1, a = !1, f = null;
2010
- 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, {
2011
2030
  drawKey: I.drawKey,
2012
2031
  onDisplayed: I.onDisplayed
2013
- }), await S(
2032
+ }), await k(
2014
2033
  {
2015
2034
  type: "drawFrame",
2016
2035
  diffPath: p.mouthPath,
@@ -2020,30 +2039,30 @@ function Ps(e, t, n) {
2020
2039
  void 0,
2021
2040
  !0
2022
2041
  ), !1)), _ = (p) => {
2023
- if (p === Gt) {
2024
- let E = -1, R;
2025
- for (const [H, V] of l)
2026
- H >= E && (E = H, R = V);
2027
- E >= 0 && l.delete(E), R?.onDisplayed?.(R.drawKey);
2042
+ if (p === zt) {
2043
+ let S = -1, R;
2044
+ for (const [q, N] of l)
2045
+ q >= S && (S = q, R = N);
2046
+ S >= 0 && l.delete(S), R?.onDisplayed?.(R.drawKey);
2028
2047
  return;
2029
2048
  }
2030
2049
  const d = -p, I = l.get(d);
2031
2050
  l.delete(d), I?.onDisplayed?.(I.drawKey);
2032
- }, m = /* @__PURE__ */ new Map(), k = (p, d) => {
2051
+ }, m = /* @__PURE__ */ new Map(), v = (p, d) => {
2033
2052
  a || !r || r.postMessage(p, []);
2034
- }, S = (p, d, I = !1) => {
2053
+ }, k = (p, d, I = !1) => {
2035
2054
  if (a) return Promise.resolve();
2036
- const E = s++;
2037
- return new Promise((R, H) => {
2038
- m.set(E, {
2039
- resolve: (V) => R(V),
2040
- reject: H,
2055
+ const S = s++;
2056
+ return new Promise((R, q) => {
2057
+ m.set(S, {
2058
+ resolve: (N) => R(N),
2059
+ reject: q,
2041
2060
  generation: typeof p.generation == "number" ? p.generation : void 0,
2042
2061
  expectRenderDone: I
2043
- }), k({ ...p, requestId: E });
2062
+ }), v({ ...p, requestId: S });
2044
2063
  });
2045
2064
  }, u = (async () => {
2046
- r = await Ms(n), r.onmessage = (p) => {
2065
+ r = await Ps(n), r.onmessage = (p) => {
2047
2066
  if (a) return;
2048
2067
  const d = p.data;
2049
2068
  if (d.type === "status") {
@@ -2051,23 +2070,23 @@ function Ps(e, t, n) {
2051
2070
  return;
2052
2071
  }
2053
2072
  if (d.type === "frame") {
2054
- const E = d.generation < 0;
2055
- if (!E && d.generation !== i) {
2073
+ const S = d.generation < 0;
2074
+ if (!S && d.generation !== i) {
2056
2075
  d.bitmap.close();
2057
2076
  return;
2058
2077
  }
2059
- if (E && !(d.generation === Gt)) {
2060
- const H = -d.generation;
2061
- if (!w.isLatestSeq(H)) {
2078
+ if (S && !(d.generation === zt)) {
2079
+ const q = -d.generation;
2080
+ if (!w.isLatestSeq(q)) {
2062
2081
  d.bitmap.close();
2063
2082
  return;
2064
2083
  }
2065
2084
  }
2066
- if (E && t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame()) {
2085
+ if (S && t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame()) {
2067
2086
  d.bitmap.close();
2068
2087
  return;
2069
2088
  }
2070
- xs(e, d.bitmap), d.bitmap.close(), E && _(d.generation);
2089
+ Ls(e, d.bitmap), d.bitmap.close(), S && _(d.generation);
2071
2090
  return;
2072
2091
  }
2073
2092
  const I = m.get(d.requestId);
@@ -2098,7 +2117,7 @@ function Ps(e, t, n) {
2098
2117
  for (const [, I] of m)
2099
2118
  I.reject(new Error(d));
2100
2119
  m.clear();
2101
- }, await S({ type: "init" }), o = !0;
2120
+ }, await k({ type: "init" }), o = !0;
2102
2121
  })();
2103
2122
  return {
2104
2123
  usesWorker: !0,
@@ -2106,10 +2125,10 @@ function Ps(e, t, n) {
2106
2125
  if (a) return { width: 842, height: 1264 };
2107
2126
  if (await u, a) return { width: 842, height: 1264 };
2108
2127
  if (!o) throw new Error("Worker init failed");
2109
- return await S({
2128
+ return await k({
2110
2129
  type: "loadAssets",
2111
2130
  keyHex: p,
2112
- urls: Qn(Ee())
2131
+ urls: Xn(Ee())
2113
2132
  }) ?? { width: 842, height: 1264 };
2114
2133
  },
2115
2134
  getVisemeAtlasPaths() {
@@ -2119,26 +2138,26 @@ function Ps(e, t, n) {
2119
2138
  if (a || (await u, a)) return;
2120
2139
  i += 1, w.reset(), l.clear();
2121
2140
  const p = i;
2122
- await S({ type: "cancelLiveDraws" }), await S(
2141
+ await k({ type: "cancelLiveDraws" }), await k(
2123
2142
  { type: "renderSil", generation: p },
2124
2143
  void 0,
2125
2144
  !0
2126
2145
  );
2127
2146
  },
2128
- drawLiveFrame(p, d, I, E) {
2147
+ drawLiveFrame(p, d, I, S) {
2129
2148
  a || u.then(() => {
2130
- a || w.enqueue(d, I, E);
2149
+ a || w.enqueue(d, I, S);
2131
2150
  });
2132
2151
  },
2133
2152
  async renderViseme(p, d, I = {}) {
2134
2153
  if (a || (await u, a)) return;
2135
2154
  i += 1, w.reset(), l.clear();
2136
- const E = i;
2155
+ const S = i;
2137
2156
  try {
2138
- await S({ type: "cancelLiveDraws" }), await S(
2157
+ await k({ type: "cancelLiveDraws" }), await k(
2139
2158
  {
2140
2159
  type: "renderViseme",
2141
- generation: E,
2160
+ generation: S,
2142
2161
  to: d,
2143
2162
  from: I.from,
2144
2163
  transitionDurationMs: I.transitionDurationMs,
@@ -2163,25 +2182,25 @@ function Ps(e, t, n) {
2163
2182
  }
2164
2183
  };
2165
2184
  }
2166
- function Bs(e, t = {}) {
2167
- if (!Cs())
2168
- return Yt(e, t);
2169
- const n = Pn(t.workerScriptUrl);
2185
+ function Fs(e, t = {}) {
2186
+ if (!Bs())
2187
+ return Jt(e, t);
2188
+ const n = Bn(t.workerScriptUrl);
2170
2189
  try {
2171
- return Ps(e, t, n);
2190
+ return Os(e, t, n);
2172
2191
  } catch {
2173
- return Yt(e, t);
2192
+ return Jt(e, t);
2174
2193
  }
2175
2194
  }
2176
- class Ls extends Error {
2195
+ class Us extends Error {
2177
2196
  constructor(t, n) {
2178
2197
  super(`${t} timed out after ${Math.round(n / 1e3)}s`), this.name = "LoadTimeoutError";
2179
2198
  }
2180
2199
  }
2181
- function tt(e, t, n) {
2200
+ function rt(e, t, n) {
2182
2201
  return new Promise((r, s) => {
2183
2202
  const i = globalThis.setTimeout(() => {
2184
- s(new Ls(n, t));
2203
+ s(new Us(n, t));
2185
2204
  }, t);
2186
2205
  e.then(
2187
2206
  (o) => {
@@ -2193,15 +2212,15 @@ function tt(e, t, n) {
2193
2212
  );
2194
2213
  });
2195
2214
  }
2196
- const Os = {
2215
+ const Ns = {
2197
2216
  position: "relative",
2198
2217
  display: "inline-block",
2199
2218
  lineHeight: 0
2200
- }, Fs = {
2219
+ }, Vs = {
2201
2220
  display: "block",
2202
2221
  maxWidth: "100%",
2203
2222
  height: "auto"
2204
- }, Us = {
2223
+ }, $s = {
2205
2224
  position: "absolute",
2206
2225
  inset: 0,
2207
2226
  display: "flex",
@@ -2213,78 +2232,78 @@ const Os = {
2213
2232
  fontSize: "0.875rem",
2214
2233
  textAlign: "center"
2215
2234
  };
2216
- function Oe(e) {
2217
- return Fn(e) ? Sr : nn;
2235
+ function Le(e) {
2236
+ return Un(e) ? vr : rn;
2218
2237
  }
2219
- function we(e, t) {
2238
+ function ge(e, t) {
2220
2239
  return t?.isSpeaking() ? t : e.isSpeaking() ? e : t?.isConnected() ? t : e;
2221
2240
  }
2222
- const zs = vn(function({
2241
+ const Qs = bn(function({
2223
2242
  id: t,
2224
2243
  avatarId: n,
2225
2244
  faceId: r,
2226
2245
  assets: s,
2227
2246
  authToken: i,
2228
- ttsEngineId: o = Te,
2247
+ ttsEngineId: o = Ae,
2229
2248
  voiceId: a,
2230
- speakingRate: f = dt,
2249
+ speakingRate: f = ht,
2231
2250
  className: l,
2232
2251
  style: w,
2233
2252
  canvasStyle: _,
2234
2253
  onStatusChange: m,
2235
- onDisplayStatus: k,
2236
- onError: S,
2254
+ onDisplayStatus: v,
2255
+ onError: k,
2237
2256
  onReady: u,
2238
2257
  showErrorOverlay: p = !0,
2239
2258
  onUserTranscript: d,
2240
2259
  onBotOutput: I,
2241
- onRealtimeLipsyncDebug: E
2260
+ onRealtimeLipsyncDebug: S
2242
2261
  }, R) {
2243
- const H = F(null), V = F(null), $ = F(vs()), j = F(is()), y = F(0), T = F(0), g = F(0), C = F(null), b = F(null), D = F(!1), A = F(!1), P = F(!1), B = F("sil"), W = F(!1), U = F(
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(
2244
2263
  null
2245
- ), X = F(!1), [se, Z] = Le("idle"), [ce, J] = Le(null), [c, v] = Le(!1), [L, z] = Le(!1), [ne, Re] = Le({ width: 842, height: 1264 }), G = F(i ?? null), Se = F(null), Y = F(null), De = F(!1), Je = F({ width: 842, height: 1264 }), Qe = F(null), pt = F(u), ee = F(k), yt = F(S), Et = F(d), St = F(I), kt = F(E);
2246
- pt.current = u, ee.current = k, yt.current = S, Et.current = d, St.current = I, kt.current = E;
2247
- const vt = 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(
2248
2267
  (h) => {
2249
- const M = h?.ttsEngineId ?? o ?? Y.current?.ttsEngineId ?? Te, x = h?.voiceId ?? a ?? Y.current?.voiceId ?? Oe(M);
2250
- return { ttsEngineId: M, 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 };
2251
2270
  },
2252
2271
  [o, a]
2253
- ), de = oe((h) => {
2254
- J(h), yt.current?.(h);
2255
- }, []), Me = oe(
2272
+ ), me = ae((h) => {
2273
+ c(h), Et.current?.(h);
2274
+ }, []), Ce = ae(
2256
2275
  (h) => {
2257
- Z(h), m?.(h);
2276
+ he(h), m?.(h);
2258
2277
  },
2259
2278
  [m]
2260
- ), q = F(
2261
- Bt(Me, be)
2262
- ), K = F(null);
2263
- ke(() => (q.current = Bt(
2264
- Me,
2265
- be
2266
- ), i && q.current.setDeveloperToken(i), q.current.setTtsEngineId(o), () => {
2267
- q.current.stop();
2268
- const h = K.current;
2269
- h && (h.disconnect(), K.current = null);
2270
- }), [Me, i, o]);
2271
- const bt = oe(() => (K.current || (K.current = Rr(
2272
- Me,
2279
+ ), K = O(
2280
+ Lt(Ce, Te)
2281
+ ), j = O(null);
2282
+ ve(() => (K.current = Lt(
2283
+ Ce,
2284
+ Te
2285
+ ), i && K.current.setDeveloperToken(i), K.current.setTtsEngineId(o), () => {
2286
+ K.current.stop();
2287
+ const h = j.current;
2288
+ h && (h.disconnect(), j.current = null);
2289
+ }), [Ce, i, o]);
2290
+ const Tt = ae(() => (j.current || (j.current = Cr(
2291
+ Ce,
2273
2292
  {
2274
2293
  speakingRate: f,
2275
- onUserTranscript: (h, M) => Et.current?.(h, M),
2276
- onBotOutput: (h) => St.current?.(h),
2277
- onLipsyncDebug: (h) => kt.current?.(h)
2294
+ onUserTranscript: (h, C) => St.current?.(h, C),
2295
+ onBotOutput: (h) => kt.current?.(h),
2296
+ onLipsyncDebug: (h) => vt.current?.(h)
2278
2297
  }
2279
- ), K.current.setTtsEngineId(o)), K.current), [Me, f, o]), ie = oe(() => {
2280
- C.current != null && (clearTimeout(C.current), C.current = null);
2281
- }, []), ue = 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(() => {
2282
2301
  b.current != null && (clearTimeout(b.current), b.current = null), P.current = !1;
2283
- }, []), Tt = oe(() => {
2284
- !X.current || !U.current || (ue(), P.current = !0, b.current = setTimeout(() => {
2285
- if (b.current = null, we(
2286
- q.current,
2287
- K.current
2302
+ }, []), At = ae(() => {
2303
+ !Y.current || !H.current || (fe(), P.current = !0, b.current = setTimeout(() => {
2304
+ if (b.current = null, ge(
2305
+ K.current,
2306
+ j.current
2288
2307
  ).isSpeaking()) {
2289
2308
  P.current = !1;
2290
2309
  return;
@@ -2293,435 +2312,440 @@ const zs = vn(function({
2293
2312
  P.current = !1;
2294
2313
  return;
2295
2314
  }
2296
- const h = U.current;
2315
+ const h = H.current;
2297
2316
  if (!h) {
2298
2317
  P.current = !1;
2299
2318
  return;
2300
2319
  }
2301
2320
  h.restart(), h.setActive(!0);
2302
- const M = h.getVideo();
2303
- let x = !1;
2304
- const O = () => {
2305
- x || (x = !0, M.removeEventListener("playing", N), P.current = !1);
2306
- }, N = () => {
2307
- O();
2321
+ const C = h.getVideo();
2322
+ let M = !1;
2323
+ const U = () => {
2324
+ M || (M = !0, C.removeEventListener("playing", B), P.current = !1);
2325
+ }, B = () => {
2326
+ U();
2308
2327
  };
2309
- if (M.addEventListener("playing", N, { once: !0 }), M.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && !M.paused) {
2310
- O();
2328
+ if (C.addEventListener("playing", B, { once: !0 }), C.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && !C.paused) {
2329
+ U();
2311
2330
  return;
2312
2331
  }
2313
- setTimeout(O, 300);
2314
- }, Es));
2315
- }, [ue]), Ce = oe(() => {
2316
- if (ie(), ee.current?.("sil"), D.current = !1, !X.current || !U.current) {
2332
+ setTimeout(U, 300);
2333
+ }, ks));
2334
+ }, [fe]), xe = ae(() => {
2335
+ if (ie(), Z.current?.("sil"), D.current = !1, !Y.current || !H.current) {
2317
2336
  P.current = !1;
2318
2337
  return;
2319
2338
  }
2320
- Tt();
2321
- }, [ie, Tt]), Xe = oe(
2339
+ At();
2340
+ }, [ie, At]), Xe = ae(
2322
2341
  async (h) => {
2323
- const M = T.current, x = V.current, O = H.current, N = () => {
2342
+ const C = T.current, M = N.current, U = q.current, B = () => {
2324
2343
  h?.fallbackOnly || (D.current = !1);
2325
2344
  };
2326
- if (!x || !O || !c) {
2327
- N();
2345
+ if (!M || !U || !E) {
2346
+ B();
2328
2347
  return;
2329
2348
  }
2330
- if (we(
2331
- q.current,
2332
- K.current
2349
+ if (ge(
2350
+ K.current,
2351
+ j.current
2333
2352
  ).isSpeaking()) {
2334
- N();
2353
+ B();
2335
2354
  return;
2336
2355
  }
2337
2356
  if (h?.fallbackOnly) {
2338
- if (!D.current || (fe($.current), await x.renderSilOnly(), M !== T.current) || we(
2339
- q.current,
2340
- K.current
2357
+ if (!D.current || (de(V.current), await M.renderSilOnly(), C !== T.current) || ge(
2358
+ K.current,
2359
+ j.current
2341
2360
  ).isSpeaking())
2342
2361
  return;
2343
- Ce();
2362
+ xe();
2344
2363
  return;
2345
2364
  }
2346
- if (ks($.current)) {
2347
- fe($.current), Ce();
2365
+ if (bs(V.current)) {
2366
+ de(V.current), xe();
2348
2367
  return;
2349
2368
  }
2350
- const te = B.current !== "sil" ? B.current : Ts(
2351
- we(
2352
- q.current,
2353
- K.current
2354
- ).getVisemeQueue()
2355
- ), ae = As(
2356
- te,
2369
+ const ee = Rs(
2370
+ ge(
2371
+ K.current,
2372
+ j.current
2373
+ ).getVisemeQueue(),
2374
+ W.current,
2375
+ F.current
2376
+ ), ce = Ds(
2377
+ ee,
2357
2378
  Qe.current
2358
2379
  );
2359
- if (fe($.current), !ae) {
2360
- if (await x.renderSilOnly(), M !== T.current || we(
2361
- q.current,
2362
- K.current
2380
+ if (de(V.current), !ce) {
2381
+ if (await M.renderSilOnly(), C !== T.current || ge(
2382
+ K.current,
2383
+ j.current
2363
2384
  ).isSpeaking())
2364
2385
  return;
2365
- Ce();
2386
+ xe();
2366
2387
  return;
2367
2388
  }
2368
2389
  try {
2369
- await x.renderViseme(O, "sil", {
2370
- from: te,
2371
- transitionDurationMs: mn
2390
+ await M.renderViseme(U, "sil", {
2391
+ from: ee,
2392
+ transitionDurationMs: wn
2372
2393
  });
2373
- } catch (he) {
2374
- if (he?.name !== "AbortError")
2375
- throw he;
2394
+ } catch (we) {
2395
+ if (we?.name !== "AbortError")
2396
+ throw we;
2376
2397
  }
2377
- if (M !== T.current) {
2378
- N();
2398
+ if (C !== T.current) {
2399
+ B();
2379
2400
  return;
2380
2401
  }
2381
- if (we(
2382
- q.current,
2383
- K.current
2402
+ if (ge(
2403
+ K.current,
2404
+ j.current
2384
2405
  ).isSpeaking()) {
2385
- N();
2406
+ B();
2386
2407
  return;
2387
2408
  }
2388
- Ce();
2409
+ xe();
2389
2410
  },
2390
- [c, Ce]
2391
- ), xe = oe(() => {
2411
+ [E, xe]
2412
+ ), Me = ae(() => {
2392
2413
  if (A.current || D.current) return;
2393
2414
  A.current = !0, D.current = !0, ie();
2394
2415
  const h = T.current;
2395
2416
  Xe().finally(() => {
2396
2417
  A.current = !1;
2397
- }), C.current = setTimeout(() => {
2398
- C.current = null, h === T.current && Xe({ fallbackOnly: !0 });
2399
- }, Is());
2400
- }, [ie, Xe]), At = oe(async () => {
2418
+ }), x.current = setTimeout(() => {
2419
+ x.current = null, h === T.current && Xe({ fallbackOnly: !0 });
2420
+ }, Cs());
2421
+ }, [ie, Xe]), It = ae(async () => {
2401
2422
  const h = Math.floor(Date.now() / 1e3);
2402
- if (Se.current && h < Se.current.expiresAt - 60)
2403
- return Se.current.key;
2404
- const M = G.current ?? await et();
2405
- G.current = M, q.current.setDeveloperToken(M);
2406
- const x = await Kn(M, be);
2407
- return Se.current = {
2408
- key: x.value,
2409
- expiresAt: x.expiresAt
2410
- }, 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;
2411
2432
  }, []);
2412
- ke(() => {
2413
- i && (G.current = i, q.current.setDeveloperToken(i));
2414
- }, [i]), ke(() => {
2415
- q.current.setTtsEngineId(o), K.current?.setTtsEngineId(o), Y.current && (Y.current.ttsEngineId = o);
2416
- }, [o]), ke(() => {
2417
- const h = a ?? Oe(o);
2418
- Y.current && (Y.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);
2419
2440
  }, [a, o]);
2420
- const ge = Rt(
2421
- () => Yn(n, r),
2441
+ const _e = Dt(
2442
+ () => Jn(n, r),
2422
2443
  [n, r]
2423
- ), pn = Rt(() => s ? JSON.stringify(s) : ge ? `face:${ge}` : `id:${t ?? ""}`, [s, ge, t]);
2424
- return ke(() => {
2425
- if (!t && !s && !ge) {
2426
- de("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
2444
+ ), yn = Dt(() => s ? JSON.stringify(s) : _e ? `face:${_e}` : `id:${t ?? ""}`, [s, _e, t]);
2445
+ return ve(() => {
2446
+ if (!t && !s && !_e) {
2447
+ me("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
2427
2448
  return;
2428
2449
  }
2429
2450
  let h = !1;
2430
- De.current = !1, v(!1), z(!1), J(null), Y.current = null, U.current = null, X.current = !1;
2431
- const M = H.current;
2432
- if (!M) return;
2433
- let x = null;
2451
+ De.current = !1, L(!1), ne(!1), c(null), re.current = null, H.current = null, Y.current = !1;
2452
+ const C = q.current;
2453
+ if (!C) return;
2454
+ let M = null;
2434
2455
  return (async () => {
2435
2456
  try {
2436
- let O, N, te;
2457
+ let U, B, ee, ce;
2437
2458
  if (s)
2438
- O = s, N = o, te = a ?? Oe(N);
2439
- else if (ge)
2440
- ee.current?.("loadFace"), O = Mt(ge), N = o, te = a ?? Oe(N);
2459
+ U = s, B = o, ee = a ?? Le(B);
2460
+ else if (_e)
2461
+ Z.current?.("loadFace"), U = xt(_e), B = o, ee = a ?? Le(B);
2441
2462
  else {
2442
- ee.current?.("getAiTwin");
2443
- const Q = await tt(
2444
- Nn(t),
2463
+ Z.current?.("getAiTwin");
2464
+ const $ = await rt(
2465
+ Vn(t),
2445
2466
  3e4,
2446
2467
  "getAiTwin"
2447
2468
  );
2448
2469
  if (h) return;
2449
- if (!Q.faceId?.trim())
2470
+ if (!$.faceId?.trim())
2450
2471
  throw new Error("getAiTwin returned no faceId");
2451
- N = Q.ttsEngineId, te = a ?? Q.voiceId ?? Oe(N), O = Mt(Q.faceId);
2472
+ B = $.ttsEngineId, ee = a ?? $.voiceId ?? Le(B), ce = $.knowledgeContextId?.trim() || void 0, U = xt($.faceId);
2452
2473
  }
2453
- Y.current = { ttsEngineId: N, voiceId: te }, Jn(O), U.current = os(), x = Bs(M, {
2454
- onStatus: (Q) => {
2455
- h || ee.current?.(Q);
2474
+ re.current = { ttsEngineId: B, voiceId: ee, personaId: ce }, Qn(U), H.current = cs(), M = Fs(C, {
2475
+ onStatus: ($) => {
2476
+ h || Z.current?.($);
2456
2477
  },
2457
- onError: (Q) => {
2458
- h || de(Q);
2478
+ onError: ($) => {
2479
+ h || me($);
2459
2480
  },
2460
- shouldAcceptLiveFrame: () => we(
2461
- q.current,
2462
- K.current
2481
+ shouldAcceptLiveFrame: () => ge(
2482
+ K.current,
2483
+ j.current
2463
2484
  ).isSpeaking() && !D.current
2464
- }), V.current = x, ee.current?.("auth");
2465
- const ae = G.current ?? i ?? await tt(et(), 3e4, "getAuthToken");
2485
+ }), N.current = M, Z.current?.("auth");
2486
+ const we = ue.current ?? i ?? await rt(nt(), 3e4, "getAuthToken");
2466
2487
  if (h) return;
2467
- G.current = ae, q.current.setDeveloperToken(ae), q.current.setTtsEngineId(N);
2468
- const he = Ge() ? await At() : void 0;
2488
+ ue.current = we, K.current.setDeveloperToken(we), K.current.setTtsEngineId(B);
2489
+ const Pe = je() ? await It() : void 0;
2469
2490
  if (h) return;
2470
- ee.current?.("loadAssets");
2471
- const le = await tt(
2472
- x.loadAssets(he),
2491
+ Z.current?.("loadAssets");
2492
+ const Q = await rt(
2493
+ M.loadAssets(Pe),
2473
2494
  18e4,
2474
2495
  "load face assets"
2475
2496
  );
2476
- if (!h && le.width > 0 && le.height > 0 && (Je.current = le, Re(le)), h) return;
2477
- Qe.current = x.getVisemeAtlasPaths(), De.current = !0, v(!0), pt.current?.(), x.renderSilOnly().then(() => {
2478
- h || ee.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");
2479
2500
  }), (async () => {
2480
2501
  try {
2481
- const Q = await Or(he);
2482
- if (await U.current.load(Q), h) return;
2483
- X.current = !0, z(!0), fe($.current), U.current.setActive(!0);
2484
- const re = U.current.getVideo();
2485
- await qt(
2486
- M,
2487
- re,
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();
2506
+ await Kt(
2507
+ C,
2508
+ oe,
2488
2509
  null,
2489
2510
  void 0,
2490
2511
  Je.current
2491
- ), h || ee.current?.("idle");
2492
- } catch (Q) {
2512
+ ), h || Z.current?.("idle");
2513
+ } catch ($) {
2493
2514
  if (h) return;
2494
- X.current = !1, z(!1), console.warn("[AiTwin] Idle video unavailable:", Q);
2515
+ Y.current = !1, ne(!1), console.warn("[AiTwin] Idle video unavailable:", $);
2495
2516
  }
2496
2517
  })();
2497
- } catch (O) {
2518
+ } catch (U) {
2498
2519
  if (h) return;
2499
- if (O instanceof nt) {
2500
- de(O.message);
2520
+ if (U instanceof st) {
2521
+ me(U.message);
2501
2522
  return;
2502
2523
  }
2503
- de(O instanceof Error ? O.message : "Failed to load AI twin");
2524
+ me(U instanceof Error ? U.message : "Failed to load AI twin");
2504
2525
  }
2505
2526
  })(), () => {
2506
- h = !0, U.current?.dispose(), x?.dispose(), V.current = null;
2527
+ h = !0, H.current?.dispose(), M?.dispose(), N.current = null;
2507
2528
  };
2508
- }, [pn, s, ge, t, o, a, i, At, de]), ke(() => {
2509
- const h = { current: !1 }, M = () => {
2510
- const x = H.current, O = V.current, N = we(
2511
- q.current,
2512
- K.current
2529
+ }, [yn, s, _e, t, o, a, i, It, me]), ve(() => {
2530
+ const h = { current: !1 }, C = () => {
2531
+ const M = q.current, U = N.current, B = ge(
2532
+ K.current,
2533
+ j.current
2513
2534
  );
2514
- if (!x || !O || !c) {
2515
- y.current = requestAnimationFrame(M);
2535
+ if (!M || !U || !E) {
2536
+ y.current = requestAnimationFrame(C);
2516
2537
  return;
2517
2538
  }
2518
- const te = N.isSpeaking(), ae = te && !W.current, he = W.current && !te;
2519
- ae && (ie(), ue(), D.current = !1, A.current = !1, fe($.current), g.current = 0, B.current = "sil", U.current?.setActive(!1)), he && (j.current.reset(), U.current?.setActive(!1), xe());
2520
- const le = N.getPlaybackElapsedMs(), Q = he || D.current || P.current;
2521
- if (te) {
2522
- X.current && U.current?.setActive(!1);
2523
- const re = N.getVisemeQueue(), _e = re.length > 0 ? ft(re, le) : "sil";
2524
- _e !== "sil" && (B.current = _e);
2525
- const me = ls(
2526
- le,
2527
- N.getSentenceEmotions(),
2528
- N.getWordQueue(),
2529
- N.getStreamMood()
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) {
2543
+ Y.current && H.current?.setActive(!1);
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()
2530
2553
  );
2531
- j.current.setTargetEmotion(me), j.current.setTargetEyebrow(
2532
- ss(
2533
- le,
2534
- N.getWordQueue(),
2535
- gt(me)
2554
+ z.current.setTargetEmotion(ke), z.current.setTargetEyebrow(
2555
+ os(
2556
+ $,
2557
+ B.getWordQueue(),
2558
+ _t(ke)
2536
2559
  )
2537
- ), j.current.advance(performance.now());
2538
- const Pe = j.current.getExpressionPath(), Ze = j.current.getDrawKey();
2539
- Ds(
2540
- x,
2541
- re,
2542
- le,
2543
- Pe,
2560
+ ), z.current.advance(performance.now());
2561
+ const Ze = z.current.getExpressionPath(), et = z.current.getDrawKey();
2562
+ Ms(
2563
+ M,
2564
+ Q,
2565
+ $,
2544
2566
  Ze,
2545
- $.current,
2546
- (Be, yn, En, Sn) => O.drawLiveFrame(Be, yn, En, Sn),
2547
- (Be) => ee.current?.(Be),
2567
+ et,
2568
+ V.current,
2569
+ (tt, En, Sn, kn) => U.drawLiveFrame(tt, En, Sn, kn),
2570
+ (tt) => Z.current?.(tt),
2548
2571
  Qe.current
2549
2572
  );
2550
- } else if (!Q && X.current && U.current) {
2551
- const re = U.current, _e = re.getVideo();
2552
- _e.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? (re.setActive(!0), h.current || (h.current = !0, qt(
2553
- x,
2554
- _e,
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
+ $,
2555
2578
  null,
2556
2579
  void 0,
2557
2580
  Je.current,
2558
- () => !N.isSpeaking() && !D.current && !P.current
2559
- ).then(() => ee.current?.("idle")).finally(() => {
2581
+ () => !B.isSpeaking() && !D.current && !P.current
2582
+ ).then(() => Z.current?.("idle")).finally(() => {
2560
2583
  h.current = !1;
2561
- }))) : jt(
2562
- x,
2584
+ }))) : Gt(
2585
+ M,
2563
2586
  null,
2564
2587
  "__sil__",
2565
- $.current,
2566
- (me, Pe, Ze, Be) => O.drawLiveFrame(me, Pe, Ze, Be),
2567
- (me) => ee.current?.(me)
2588
+ V.current,
2589
+ (oe, ke, Ze, et) => U.drawLiveFrame(oe, ke, Ze, et),
2590
+ (oe) => Z.current?.(oe)
2568
2591
  );
2569
- } else Q || jt(
2570
- x,
2592
+ } else Pe || Gt(
2593
+ M,
2571
2594
  null,
2572
2595
  "__sil__",
2573
- $.current,
2574
- (re, _e, me, Pe) => O.drawLiveFrame(re, _e, me, Pe),
2575
- (re) => ee.current?.(re)
2596
+ V.current,
2597
+ (Q, $, oe, ke) => U.drawLiveFrame(Q, $, oe, ke),
2598
+ (Q) => Z.current?.(Q)
2576
2599
  );
2577
- W.current = te, y.current = requestAnimationFrame(M);
2600
+ G.current = ee, y.current = requestAnimationFrame(C);
2578
2601
  };
2579
- return y.current = requestAnimationFrame(M), () => {
2580
- cancelAnimationFrame(y.current), ie(), ue(), q.current.stop(), K.current?.stop();
2602
+ return y.current = requestAnimationFrame(C), () => {
2603
+ cancelAnimationFrame(y.current), ie(), fe(), K.current.stop(), j.current?.stop();
2581
2604
  };
2582
2605
  }, [
2583
- c,
2584
- L,
2585
- xe,
2606
+ E,
2607
+ X,
2608
+ Me,
2586
2609
  ie,
2587
- ue
2588
- ]), bn(
2610
+ fe
2611
+ ]), Tn(
2589
2612
  R,
2590
2613
  () => ({
2591
- speakText: async (h, M) => {
2592
- const x = h.trim();
2593
- if (!x) return;
2594
- const O = V.current;
2595
- if (!O || !De.current && !c)
2614
+ speakText: async (h, C) => {
2615
+ const M = h.trim();
2616
+ if (!M) return;
2617
+ const U = N.current;
2618
+ if (!U || !De.current && !E)
2596
2619
  throw new Error("AI twin is not ready");
2597
- const { ttsEngineId: N, voiceId: te } = vt(M);
2598
- J(null), T.current += 1, ie(), ue(), D.current = !1, A.current = !1, B.current = "sil", fe($.current), j.current.reset(), W.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;
2599
2622
  try {
2600
- X.current ? (U.current?.setActive(!1), U.current?.restart(), fe($.current)) : await O.renderSilOnly(), await q.current.speak(x, {
2601
- voiceId: te,
2602
- speakingRate: M?.speakingRate ?? f,
2603
- ttsEngineId: N
2623
+ Y.current ? (H.current?.setActive(!1), H.current?.restart(), de(V.current)) : await U.renderSilOnly(), await K.current.speak(M, {
2624
+ voiceId: ee,
2625
+ speakingRate: C?.speakingRate ?? f,
2626
+ ttsEngineId: B
2604
2627
  });
2605
- } catch (ae) {
2606
- throw de(ae instanceof Error ? ae.message : "TTS failed"), ae;
2628
+ } catch (ce) {
2629
+ throw me(ce instanceof Error ? ce.message : "TTS failed"), ce;
2607
2630
  }
2608
2631
  },
2609
2632
  stop: () => {
2610
- T.current += 1, ie(), ue(), D.current = !1, A.current = !1, q.current.stop(), K.current?.stop(), fe($.current), W.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();
2611
2634
  },
2612
2635
  setTtsEngineId: (h) => {
2613
- q.current.setTtsEngineId(h), K.current?.setTtsEngineId(h), Y.current && (Y.current.ttsEngineId = h);
2636
+ K.current.setTtsEngineId(h), j.current?.setTtsEngineId(h), re.current && (re.current.ttsEngineId = h);
2614
2637
  },
2615
- renderViseme: async (h, M) => {
2616
- const x = V.current, O = H.current;
2617
- if (!x || !O || !De.current)
2638
+ renderViseme: async (h, C) => {
2639
+ const M = N.current, U = q.current;
2640
+ if (!M || !U || !De.current)
2618
2641
  throw new Error("AI twin is not ready");
2619
- await x.renderViseme(O, h, {
2620
- from: M?.from,
2621
- transitionDurationMs: M?.transitionDurationMs,
2622
- gapMs: M?.gapMs,
2623
- onStatus: (N) => ee.current?.(N)
2642
+ await M.renderViseme(U, h, {
2643
+ from: C?.from,
2644
+ transitionDurationMs: C?.transitionDurationMs,
2645
+ gapMs: C?.gapMs,
2646
+ onStatus: (B) => Z.current?.(B)
2624
2647
  });
2625
2648
  },
2626
2649
  isReady: () => De.current,
2627
- getStatus: () => se,
2650
+ getStatus: () => J,
2628
2651
  connect: async (h = {}) => {
2629
- J(null);
2652
+ c(null);
2630
2653
  try {
2631
- let M = h.authToken?.trim();
2632
- M || (M = G.current ?? i ?? await et(), G.current = M);
2633
- const x = h.voiceId?.trim() ?? a ?? Y.current?.voiceId, O = bt();
2634
- await O.unlockAudio(), await O.connect({
2654
+ let C = h.authToken?.trim();
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({
2635
2658
  ...h,
2636
- authToken: M,
2637
- voiceId: x,
2659
+ authToken: C,
2660
+ voiceId: M,
2661
+ personaId: U,
2638
2662
  speakingRate: h.speakingRate ?? f
2639
2663
  });
2640
- } catch (M) {
2641
- throw de(
2642
- M instanceof Error ? M.message : "Voice connect failed"
2643
- ), M;
2664
+ } catch (C) {
2665
+ throw me(
2666
+ C instanceof Error ? C.message : "Voice connect failed"
2667
+ ), C;
2644
2668
  }
2645
2669
  },
2646
2670
  disconnect: async () => {
2647
- const h = K.current;
2648
- h && (T.current += 1, ie(), ue(), D.current = !1, A.current = !1, fe($.current), W.current = !1, await h.disconnect(), xe());
2671
+ const h = j.current;
2672
+ h && (T.current += 1, ie(), fe(), D.current = !1, A.current = !1, de(V.current), G.current = !1, await h.disconnect(), Me());
2649
2673
  },
2650
- isConnected: () => K.current?.isConnected() ?? !1
2674
+ isConnected: () => j.current?.isConnected() ?? !1
2651
2675
  }),
2652
2676
  [
2653
- c,
2677
+ E,
2654
2678
  f,
2655
2679
  i,
2656
2680
  a,
2657
2681
  ie,
2658
- ue,
2659
- xe,
2660
- de,
2661
- vt,
2682
+ fe,
2683
+ Me,
2684
+ me,
2662
2685
  bt,
2663
- se
2686
+ Tt,
2687
+ J
2664
2688
  ]
2665
- ), /* @__PURE__ */ kn("div", { className: l, style: { ...Os, ...w }, children: [
2666
- /* @__PURE__ */ It(
2689
+ ), /* @__PURE__ */ vn("div", { className: l, style: { ...Ns, ...w }, children: [
2690
+ /* @__PURE__ */ Rt(
2667
2691
  "canvas",
2668
2692
  {
2669
- ref: H,
2670
- width: ne.width,
2671
- height: ne.height,
2672
- style: { ...Fs, ..._ },
2693
+ ref: q,
2694
+ width: Se.width,
2695
+ height: Se.height,
2696
+ style: { ...Vs, ..._ },
2673
2697
  "aria-label": t ? `AI twin ${t}` : "AI twin face"
2674
2698
  }
2675
2699
  ),
2676
- p && ce ? /* @__PURE__ */ It("div", { style: Us, children: ce }) : null
2700
+ p && te ? /* @__PURE__ */ Rt("div", { style: $s, children: te }) : null
2677
2701
  ] });
2678
- }), Ns = "thumbnail.webp";
2679
- function Ys(e, t = ut) {
2702
+ }), Ws = "thumbnail.webp";
2703
+ function Xs(e, t = ft) {
2680
2704
  const n = e.trim();
2681
2705
  if (!n)
2682
2706
  throw new Error("faceId is required");
2683
- return `${t.replace(/\/$/, "")}/${n}/${Ns}`;
2707
+ return `${t.replace(/\/$/, "")}/${n}/${Ws}`;
2684
2708
  }
2685
- const Vs = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]);
2686
- function $s(e = ".png") {
2709
+ const Hs = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]);
2710
+ function qs(e = ".png") {
2687
2711
  const t = e.toLowerCase();
2688
- return Vs.has(t) ? `source${t}` : "source.png";
2712
+ return Hs.has(t) ? `source${t}` : "source.png";
2689
2713
  }
2690
- function Js(e, t = ut, n = ".png") {
2714
+ function Zs(e, t = ft, n = ".png") {
2691
2715
  const r = e.trim();
2692
2716
  if (!r)
2693
2717
  throw new Error("faceId is required");
2694
- return `${t.replace(/\/$/, "")}/${r}/${$s(n)}`;
2718
+ return `${t.replace(/\/$/, "")}/${r}/${qs(n)}`;
2695
2719
  }
2696
2720
  export {
2697
- Ns as AI_TWIN_THUMBNAIL_FILENAME,
2698
- zs as AiTwin,
2699
- nt as AiTwinNotFoundError,
2700
- Te as DEFAULT_TTS_ENGINE_ID,
2701
- rn as MIC_SAMPLE_RATE,
2702
- sr as OCULUS_VISEME_IDS,
2703
- sn as PLAYBACK_SAMPLE_RATE,
2704
- tn as SPEAKING_RATE_MAX,
2705
- en as SPEAKING_RATE_MIN,
2706
- Ae as TTS_ENGINE_CARTESIA,
2707
- Qt as TTS_ENGINE_GOOGLE,
2708
- lt as TTS_ENGINE_INWORLD,
2709
- Gs as VISEME_IDS,
2710
- Sr as VISEME_TEST_CARTESIA_VOICE_ID,
2711
- dt as VISEME_TEST_SPEAKING_RATE,
2712
- nn as VISEME_TEST_VOICE_ID,
2713
- $s as aiTwinSourceFilename,
2714
- Ar as buildVoiceWebSocketUrl,
2715
- Bt as createAvatarTtsLipsyncController,
2716
- Rr as createRealtimeVoiceLipsyncController,
2717
- Mt as faceAssetUrls,
2718
- Nn as fetchAiTwin,
2719
- et as fetchDevAuthToken,
2720
- Js as getAiTwinSourceUrl,
2721
- Ys as getAiTwinThumbnailUrl,
2722
- or as normalizeOculusViseme,
2723
- Yn as resolveDirectFaceId,
2724
- ft as resolveVisemeAtTime,
2725
- js as resolveWordAtTime,
2726
- Jn as setActiveTwinAssets
2721
+ Ws as AI_TWIN_THUMBNAIL_FILENAME,
2722
+ Qs as AiTwin,
2723
+ st as AiTwinNotFoundError,
2724
+ Ae as DEFAULT_TTS_ENGINE_ID,
2725
+ sn as MIC_SAMPLE_RATE,
2726
+ ir as OCULUS_VISEME_IDS,
2727
+ on as PLAYBACK_SAMPLE_RATE,
2728
+ nn as SPEAKING_RATE_MAX,
2729
+ tn as SPEAKING_RATE_MIN,
2730
+ Ie as TTS_ENGINE_CARTESIA,
2731
+ Xt as TTS_ENGINE_GOOGLE,
2732
+ dt as TTS_ENGINE_INWORLD,
2733
+ Js as VISEME_IDS,
2734
+ vr as VISEME_TEST_CARTESIA_VOICE_ID,
2735
+ ht as VISEME_TEST_SPEAKING_RATE,
2736
+ rn as VISEME_TEST_VOICE_ID,
2737
+ qs as aiTwinSourceFilename,
2738
+ Rr as buildVoiceWebSocketUrl,
2739
+ Lt as createAvatarTtsLipsyncController,
2740
+ Cr as createRealtimeVoiceLipsyncController,
2741
+ xt as faceAssetUrls,
2742
+ Vn as fetchAiTwin,
2743
+ nt as fetchDevAuthToken,
2744
+ Zs as getAiTwinSourceUrl,
2745
+ Xs as getAiTwinThumbnailUrl,
2746
+ ar as normalizeOculusViseme,
2747
+ Jn as resolveDirectFaceId,
2748
+ ze as resolveVisemeAtTime,
2749
+ Ys as resolveWordAtTime,
2750
+ Qn as setActiveTwinAssets
2727
2751
  };