@streamoji/aitwin 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/aitwin.js CHANGED
@@ -1,47 +1,47 @@
1
- import { jsxs as Hn, jsx as Gt } from "react/jsx-runtime";
2
- import { forwardRef as Kn, useRef as P, useState as ze, useEffect as Me, useCallback as he, useMemo as zt, useImperativeHandle as jn } from "react";
3
- import { PipecatClient as Gn } from "@pipecat-ai/client-js";
4
- import { WebSocketTransport as zn, DailyMediaManager as Qn, ProtobufFrameSerializer as Yn } from "@pipecat-ai/websocket-transport";
5
- const Jn = "https://pub-607ad1fc22e2400eb57d17240aab857c.r2.dev", pn = {
6
- publicBase: Jn
7
- }, Xn = "0.3.1", Zn = {
8
- version: Xn
9
- }, er = {}, et = "https://ai.aitwin.me", Ct = `${pn.publicBase}/custom-faces`, tr = `${pn.publicBase}/aitwin-workers/v${Zn.version}/visemeDiffPreview.worker.js`;
10
- function nr(e) {
1
+ import { jsxs as Kn, jsx as zt } from "react/jsx-runtime";
2
+ import { forwardRef as jn, useRef as P, useState as Qe, useEffect as Me, useCallback as he, useMemo as Qt, useImperativeHandle as Gn } from "react";
3
+ import { PipecatClient as zn } from "@pipecat-ai/client-js";
4
+ import { WebSocketTransport as Qn, DailyMediaManager as Yn, ProtobufFrameSerializer as Jn } from "@pipecat-ai/websocket-transport";
5
+ const Xn = "https://pub-607ad1fc22e2400eb57d17240aab857c.r2.dev", _n = {
6
+ publicBase: Xn
7
+ }, Zn = "0.3.3", er = {
8
+ version: Zn
9
+ }, tr = {}, tt = "https://ai.aitwin.me", xt = `${_n.publicBase}/custom-faces`, nr = `${_n.publicBase}/aitwin-workers/v${er.version}/visemeDiffPreview.worker.js`;
10
+ function rr(e) {
11
11
  if (e) return e;
12
- const t = typeof import.meta < "u" ? er?.VITE_AITWIN_WORKER_URL : void 0;
13
- return t?.trim() ? t.trim() : tr;
12
+ const t = typeof import.meta < "u" ? tr?.VITE_AITWIN_WORKER_URL : void 0;
13
+ return t?.trim() ? t.trim() : nr;
14
14
  }
15
- const rr = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", _n = "eng_a7f2b9c1", Pt = "eng_d4e8f3a2", Ue = "eng_c9b1e6d4", Le = Ue, yn = /* @__PURE__ */ new Set([
15
+ const sr = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", yn = "eng_a7f2b9c1", Pt = "eng_d4e8f3a2", Ne = "eng_c9b1e6d4", Le = Ne, Sn = /* @__PURE__ */ new Set([
16
16
  Pt,
17
- Ue
18
- ]), Sn = {
19
- [_n]: "oculus_direct",
20
- [Ue]: "oculus_direct",
17
+ Ne
18
+ ]), kn = {
19
+ [yn]: "oculus_direct",
20
+ [Ne]: "oculus_direct",
21
21
  [Pt]: "inworld_word"
22
- }, Qt = {
23
- google: _n,
22
+ }, Yt = {
23
+ google: yn,
24
24
  inworld: Pt,
25
- cartesia: Ue
25
+ cartesia: Ne
26
26
  };
27
- function sr(e) {
28
- return Sn[e];
29
- }
30
27
  function ir(e) {
31
- return e === Ue;
28
+ return kn[e];
32
29
  }
33
30
  function ar(e) {
34
- if (e.ttsEngineId && e.ttsEngineId in Sn)
31
+ return e === Ne;
32
+ }
33
+ function or(e) {
34
+ if (e.ttsEngineId && e.ttsEngineId in kn)
35
35
  return e.ttsEngineId;
36
36
  const t = e.tts?.toLowerCase();
37
- return t && t in Qt ? Qt[t] : Le;
37
+ return t && t in Yt ? Yt[t] : Le;
38
38
  }
39
39
  class Tt extends Error {
40
40
  constructor(t = "AI twin not found") {
41
41
  super(t), this.name = "AiTwinNotFoundError";
42
42
  }
43
43
  }
44
- async function or(e, t = rr) {
44
+ async function cr(e, t = sr) {
45
45
  const n = new URL(t);
46
46
  n.searchParams.set("id", e);
47
47
  const r = await fetch(n.toString());
@@ -55,22 +55,22 @@ async function or(e, t = rr) {
55
55
  const { tts: i, token: o, ...a } = s.data, l = String(a.authToken ?? o ?? "").trim() || void 0;
56
56
  return {
57
57
  ...a,
58
- ttsEngineId: ar(s.data),
58
+ ttsEngineId: or(s.data),
59
59
  authToken: l
60
60
  };
61
61
  }
62
- const cr = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", ur = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", lr = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", fr = "6TNvp3SCs4Og0a1ijm9TommXLql1", dr = "Swaraj Mali";
62
+ const ur = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", lr = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", fr = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", dr = "6TNvp3SCs4Og0a1ijm9TommXLql1", mr = "Swaraj Mali";
63
63
  async function kt() {
64
- const e = await fetch(cr, {
64
+ const e = await fetch(ur, {
65
65
  method: "POST",
66
66
  headers: {
67
67
  "Content-Type": "application/json",
68
- "Client-Id": ur,
69
- "Client-Secret": lr
68
+ "Client-Id": lr,
69
+ "Client-Secret": fr
70
70
  },
71
71
  body: JSON.stringify({
72
- userId: fr,
73
- userName: dr
72
+ userId: dr,
73
+ userName: mr
74
74
  })
75
75
  });
76
76
  if (!e.ok)
@@ -80,7 +80,7 @@ async function kt() {
80
80
  throw new Error("getAuthToken returned no token");
81
81
  return n;
82
82
  }
83
- async function mr(e, t = et) {
83
+ async function hr(e, t = tt) {
84
84
  const n = await fetch(`${t.replace(/\/$/, "")}/api/session-value`, {
85
85
  headers: { Authorization: `Bearer ${e}` }
86
86
  });
@@ -90,7 +90,7 @@ async function mr(e, t = et) {
90
90
  if (!r.value) throw new Error("Session value response missing value");
91
91
  return r;
92
92
  }
93
- function hr(e) {
93
+ function wr(e) {
94
94
  const t = e.trim();
95
95
  if (t.length % 2 !== 0) throw new Error("Invalid hex key");
96
96
  const n = new Uint8Array(t.length / 2);
@@ -98,20 +98,20 @@ function hr(e) {
98
98
  n[r / 2] = Number.parseInt(t.slice(r, r + 2), 16);
99
99
  return n;
100
100
  }
101
- function st(e) {
101
+ function it(e) {
102
102
  return Uint8Array.from(e);
103
103
  }
104
- function wr(e, t) {
104
+ function gr(e, t) {
105
105
  const n = new Uint8Array(e.length + t.length);
106
106
  return n.set(e, 0), n.set(t, e.length), n;
107
107
  }
108
- async function gr(e, t) {
108
+ async function pr(e, t) {
109
109
  if (!t) throw new Error("Asset key is required for encrypted assets");
110
110
  if (e.byteLength < 28)
111
111
  throw new Error("Encrypted payload too small");
112
- const n = new Uint8Array(e), r = st(n.subarray(0, 12)), s = st(n.subarray(12, 28)), i = st(n.subarray(28)), o = st(wr(i, s)), a = await crypto.subtle.importKey(
112
+ const n = new Uint8Array(e), r = it(n.subarray(0, 12)), s = it(n.subarray(12, 28)), i = it(n.subarray(28)), o = it(gr(i, s)), a = await crypto.subtle.importKey(
113
113
  "raw",
114
- hr(t),
114
+ wr(t),
115
115
  { name: "AES-GCM" },
116
116
  !1,
117
117
  ["decrypt"]
@@ -124,33 +124,33 @@ async function gr(e, t) {
124
124
  }
125
125
  let At = null;
126
126
  const It = /* @__PURE__ */ new Set();
127
- function it(e) {
127
+ function at(e) {
128
128
  return e.includes("/custom-faces/");
129
129
  }
130
- function ct(e) {
130
+ function ut(e) {
131
131
  const t = e.binBase.trim().replace(/\/$/, ""), n = e.twinBase.trim().replace(/\/$/, "");
132
- if (!(e.encrypted || it(t) || it(n)))
132
+ if (!(e.encrypted || at(t) || at(n)))
133
133
  return { twinBase: n, binBase: t, encrypted: !1 };
134
- const s = it(t) ? t : it(n) ? n : t;
134
+ const s = at(t) ? t : at(n) ? n : t;
135
135
  return { twinBase: s, binBase: s, encrypted: !0 };
136
136
  }
137
- function Ne(e) {
138
- return ct(e).encrypted;
137
+ function Ve(e) {
138
+ return ut(e).encrypted;
139
139
  }
140
- function Yt(e, t = Ct) {
140
+ function Jt(e, t = xt) {
141
141
  const n = `${t.replace(/\/$/, "")}/${e}`;
142
142
  return { twinBase: n, binBase: n, encrypted: !0 };
143
143
  }
144
- function pr(e, t) {
144
+ function _r(e, t) {
145
145
  return (e ?? t)?.trim() || void 0;
146
146
  }
147
- function _r(e) {
148
- At = ct(e);
147
+ function yr(e) {
148
+ At = ut(e);
149
149
  for (const t of It) t();
150
150
  }
151
- function yr(e, t) {
151
+ function Sr(e, t) {
152
152
  const n = typeof globalThis.location < "u" ? globalThis.location.href : void 0;
153
- if (!n) return ct(e);
153
+ if (!n) return ut(e);
154
154
  const r = (s) => {
155
155
  try {
156
156
  return new URL(s, n).href.replace(/\/$/, "");
@@ -158,7 +158,7 @@ function yr(e, t) {
158
158
  return s;
159
159
  }
160
160
  };
161
- return ct({
161
+ return ut({
162
162
  twinBase: r(e.twinBase),
163
163
  binBase: r(e.binBase),
164
164
  encrypted: e.encrypted
@@ -169,33 +169,33 @@ function Pe() {
169
169
  throw new Error("Twin assets not configured; call setActiveTwinAssets first");
170
170
  return At;
171
171
  }
172
- function Sr(e) {
172
+ function kr(e) {
173
173
  return It.add(e), () => It.delete(e);
174
174
  }
175
- function Jt() {
175
+ function Xt() {
176
176
  const e = Pe();
177
- return Ne(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
178
- }
179
- function kr() {
180
- const e = Pe();
181
- return Ne(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
177
+ return Ve(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
182
178
  }
183
179
  function vr() {
184
180
  const e = Pe();
185
- return Ne(e) ? e.binBase : e.twinBase;
186
- }
187
- function dt() {
188
- return Ne(Pe());
181
+ return Ve(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
189
182
  }
190
183
  function Er() {
191
184
  const e = Pe();
192
- return Ne(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
185
+ return Ve(e) ? e.binBase : e.twinBase;
186
+ }
187
+ function mt() {
188
+ return Ve(Pe());
193
189
  }
194
190
  function br() {
195
191
  const e = Pe();
196
- return Ne(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
192
+ return Ve(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
197
193
  }
198
- function kn(e) {
194
+ function Tr() {
195
+ const e = Pe();
196
+ return Ve(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
197
+ }
198
+ function vn(e) {
199
199
  const t = e.split(/\r?\n/);
200
200
  let n = "", r = "";
201
201
  for (const i of t)
@@ -210,7 +210,7 @@ function kn(e) {
210
210
  }
211
211
  return { event: n, data: s };
212
212
  }
213
- const Tr = [
213
+ const Ar = [
214
214
  "aa",
215
215
  "CH",
216
216
  "DD",
@@ -226,14 +226,14 @@ const Tr = [
226
226
  "kk",
227
227
  "nn",
228
228
  "sil"
229
- ], Ar = new Map(
230
- Tr.map((e) => [e.toLowerCase(), e])
229
+ ], Ir = new Map(
230
+ Ar.map((e) => [e.toLowerCase(), e])
231
231
  );
232
- function Ir(e) {
232
+ function Rr(e) {
233
233
  const t = (e ?? "").trim();
234
- return t ? Ar.get(t.toLowerCase()) ?? "sil" : "sil";
234
+ return t ? Ir.get(t.toLowerCase()) ?? "sil" : "sil";
235
235
  }
236
- const Rr = {
236
+ const Dr = {
237
237
  aei: ["aa", "E", "I"],
238
238
  o: ["O", "U"],
239
239
  ee: ["I"],
@@ -245,12 +245,12 @@ const Rr = {
245
245
  qw: ["U", "O"],
246
246
  cdgknstxyz: ["DD", "SS", "kk", "CH"]
247
247
  };
248
- function Dr(e) {
248
+ function Mr(e) {
249
249
  if (!e) return ["sil"];
250
250
  const t = e.toLowerCase();
251
- return Rr[t] ?? ["sil"];
251
+ return Dr[t] ?? ["sil"];
252
252
  }
253
- function Mr(e, t) {
253
+ function Cr(e, t) {
254
254
  const n = e.word.length;
255
255
  if (n <= 0) return 0;
256
256
  const r = e.wduration;
@@ -258,33 +258,40 @@ function Mr(e, t) {
258
258
  const s = Math.max(0, Math.min(1, (t - e.wtime) / r));
259
259
  return Math.min(n - 1, Math.floor(s * n));
260
260
  }
261
- function mt(e, t) {
261
+ function Ue(e, t) {
262
262
  const n = Math.max(0, Math.min(e.length - 1, t));
263
263
  return e[n] ?? "";
264
264
  }
265
+ function Ft(e, t) {
266
+ const n = e.toLowerCase().replace(/[^a-z']/g, "");
267
+ return !n || Ue(n, t) !== "w" || t > 0 && Ue(n, t - 1) === "q" ? !1 : t === 0 && /^w[aeiouy]/.test(n);
268
+ }
265
269
  function xr(e, t) {
266
- const n = e.toLowerCase(), r = mt(n, t), s = n.slice(Math.max(0, t - 1), t + 2);
270
+ const n = e.toLowerCase(), r = Ue(n, t), s = n.slice(Math.max(0, t - 1), t + 2);
267
271
  return r === "i" || r === "y" ? "I" : s.includes("ee") || r === "e" || n.includes("ea") ? "E" : "aa";
268
272
  }
269
- function Cr(e, t) {
273
+ function Pr(e, t) {
270
274
  const n = e.toLowerCase(), r = n.slice(
271
275
  Math.max(0, t - 1),
272
276
  Math.min(n.length, t + 3)
273
277
  );
274
278
  if (/oo|ou|uw/.test(r)) return "U";
275
- const s = mt(n, t);
279
+ if (Ft(n, t)) return "FF";
280
+ const s = Ue(n, t);
276
281
  return s === "u" || s === "w" ? "U" : "O";
277
282
  }
278
- function Pr(e, t) {
279
- const n = e.toLowerCase(), r = n.slice(Math.max(0, t - 2), t + 1);
283
+ function Fr(e, t) {
284
+ const n = e.toLowerCase();
285
+ if (Ft(n, t)) return "FF";
286
+ const r = n.slice(Math.max(0, t - 2), t + 1);
280
287
  if (/qu/.test(r)) return "U";
281
288
  const s = n.slice(
282
289
  Math.max(0, t - 1),
283
290
  Math.min(n.length, t + 3)
284
291
  );
285
- return /wo|wh/.test(s) || mt(n, t) === "o" ? "O" : "U";
292
+ return /wo|wh/.test(s) || Ue(n, t) === "o" ? "O" : "U";
286
293
  }
287
- const at = {
294
+ const ot = {
288
295
  d: "DD",
289
296
  t: "DD",
290
297
  n: "DD",
@@ -296,17 +303,17 @@ const at = {
296
303
  x: "CH",
297
304
  j: "CH"
298
305
  };
299
- function Fr(e, t) {
300
- const n = e.toLowerCase(), r = mt(n, t);
301
- if (at[r]) return at[r];
306
+ function Br(e, t) {
307
+ const n = e.toLowerCase(), r = Ue(n, t);
308
+ if (ot[r]) return ot[r];
302
309
  for (let s = 0; s < n.length; s++) {
303
310
  const i = n[s];
304
- if (at[i]) return at[i];
311
+ if (ot[i]) return ot[i];
305
312
  }
306
313
  return "DD";
307
314
  }
308
- function Br(e, t, n) {
309
- const r = Dr(e);
315
+ function Or(e, t, n) {
316
+ const r = Mr(e);
310
317
  if (r.length === 1) return r[0];
311
318
  const s = t.trim();
312
319
  if (!s) return r[0];
@@ -315,31 +322,31 @@ function Br(e, t, n) {
315
322
  case "aei":
316
323
  return xr(s, o);
317
324
  case "o":
318
- return Cr(s, o);
319
- case "qw":
320
325
  return Pr(s, o);
321
- case "cdgknstxyz":
326
+ case "qw":
322
327
  return Fr(s, o);
328
+ case "cdgknstxyz":
329
+ return Br(s, o);
323
330
  default:
324
331
  return r[0];
325
332
  }
326
333
  }
327
- const Ft = 16e3;
328
- function vn(e) {
334
+ const Bt = 16e3;
335
+ function En(e) {
329
336
  const t = Number(e);
330
- return Number.isFinite(t) && t > 0 ? t : Ft;
337
+ return Number.isFinite(t) && t > 0 ? t : Bt;
331
338
  }
332
- function Or(e) {
339
+ function Lr(e) {
333
340
  let t = e.trim();
334
341
  const n = t.indexOf(",");
335
342
  t.startsWith("data:") && n >= 0 && (t = t.slice(n + 1)), t = t.replace(/\s+/g, "").replace(/-/g, "+").replace(/_/g, "/");
336
343
  const r = t.length % 4;
337
344
  return r !== 0 && (t += "=".repeat(4 - r)), t;
338
345
  }
339
- function Lr(e) {
346
+ function Ur(e) {
340
347
  return e.length >= 4 && e[0] === 82 && e[1] === 73 && e[2] === 70 && e[3] === 70;
341
348
  }
342
- function Xt(e, t, n = Ft) {
349
+ function Zt(e, t, n = Bt) {
343
350
  const r = t.byteOffset % 2 === 0 ? t : t.slice(), s = new Int16Array(
344
351
  r.buffer,
345
352
  r.byteOffset,
@@ -350,15 +357,15 @@ function Xt(e, t, n = Ft) {
350
357
  const o = e.createBuffer(1, i.length, n);
351
358
  return o.copyToChannel(i, 0), o;
352
359
  }
353
- function Ur(e) {
354
- const t = Or(e), n = window.atob(t), r = new Uint8Array(n.length);
360
+ function Nr(e) {
361
+ const t = Lr(e), n = window.atob(t), r = new Uint8Array(n.length);
355
362
  for (let s = 0; s < n.length; s++)
356
363
  r[s] = n.charCodeAt(s);
357
364
  return r;
358
365
  }
359
- async function Nr(e, t, n = Ft) {
360
- const r = Ur(t), s = vn(n);
361
- if (Lr(r)) {
366
+ async function Vr(e, t, n = Bt) {
367
+ const r = Nr(t), s = En(n);
368
+ if (Ur(r)) {
362
369
  const i = r.buffer.slice(
363
370
  r.byteOffset,
364
371
  r.byteOffset + r.byteLength
@@ -366,7 +373,7 @@ async function Nr(e, t, n = Ft) {
366
373
  return e.decodeAudioData(i);
367
374
  }
368
375
  if (r.length >= 2 && r.length % 2 === 0)
369
- return Xt(e, r, s);
376
+ return Zt(e, r, s);
370
377
  try {
371
378
  const i = r.buffer.slice(
372
379
  r.byteOffset,
@@ -374,22 +381,22 @@ async function Nr(e, t, n = Ft) {
374
381
  );
375
382
  return await e.decodeAudioData(i);
376
383
  } catch {
377
- return Xt(e, r, s);
384
+ return Zt(e, r, s);
378
385
  }
379
386
  }
380
- function Qe(e) {
387
+ function Ye(e) {
381
388
  let t = 0;
382
389
  for (const n of e)
383
390
  t = Math.max(t, n.vtime + n.vduration);
384
391
  return t;
385
392
  }
386
- function Vr(e, t) {
393
+ function $r(e, t) {
387
394
  for (const n of e)
388
395
  if (t >= n.wtime && t < n.wtime + n.wduration)
389
396
  return n;
390
397
  return null;
391
398
  }
392
- function En(e, t) {
399
+ function bn(e, t) {
393
400
  const n = [], r = [];
394
401
  let s = null, i = !1, o = !1, a = !1, l = !1, f = 0, u = 0, _ = 0, m = 0, p = null, v = 1, d = t, y = !1, h = null, E = 0;
395
402
  const b = () => {
@@ -425,7 +432,7 @@ function En(e, t) {
425
432
  o = !1, b(), e.onSpeakingDone(), e.onNotify();
426
433
  }
427
434
  }, G = (g) => {
428
- const D = Qe(g);
435
+ const D = Ye(g);
429
436
  if (D <= 0) {
430
437
  e.onSpeakingDone(), e.onNotify();
431
438
  return;
@@ -435,15 +442,15 @@ function En(e, t) {
435
442
  p = setTimeout(() => {
436
443
  y || (o = !1, p = null, e.onSpeakingDone(), e.onNotify());
437
444
  }, L);
438
- }, X = (g, D, L, F) => {
445
+ }, Z = (g, D, L, F) => {
439
446
  D.length !== 0 && (F && (_ = L), D.forEach((T) => {
440
447
  const z = String(T.word ?? "").trim();
441
448
  if (!z) return;
442
- const Z = Math.round((T.start ?? 0) * 1e3), re = T.duration != null ? Math.round(T.duration * 1e3) : T.end != null ? Math.max(1, Math.round((T.end - (T.start ?? 0)) * 1e3)) : 0;
449
+ const ee = Math.round((T.start ?? 0) * 1e3), se = T.duration != null ? Math.round(T.duration * 1e3) : T.end != null ? Math.max(1, Math.round((T.end - (T.start ?? 0)) * 1e3)) : 0;
443
450
  g.push({
444
451
  word: z,
445
- wtime: _ + Z,
446
- wduration: re,
452
+ wtime: _ + ee,
453
+ wduration: se,
447
454
  queueIndex: g.length,
448
455
  gesture: T.gesture ?? null,
449
456
  emphasis: T.emphasis === !0
@@ -451,29 +458,23 @@ function En(e, t) {
451
458
  }));
452
459
  }, S = (g, D, L, F, T, $) => {
453
460
  L.length !== 0 && (T && (_ = F), L.forEach((z) => {
454
- const Z = String(z.symbol ?? z.viseme ?? "").trim();
455
- if (!Z) return;
456
- const re = Math.round((z.start ?? 0) * 1e3), O = Math.max(1, Math.round((z.duration ?? 0) * 1e3)), K = _ + re;
457
- let le;
458
- if (sr($) === "oculus_direct")
459
- le = Ir(Z);
460
- else {
461
- const fe = Vr(D, K), ie = fe ? Mr(fe, K) : 0;
462
- le = Br(
463
- Z,
464
- fe?.word ?? "",
465
- ie
466
- );
467
- }
468
- g.push({
469
- viseme: le,
461
+ const ee = String(z.symbol ?? z.viseme ?? "").trim();
462
+ if (!ee) return;
463
+ const se = Math.round((z.start ?? 0) * 1e3), O = Math.max(1, Math.round((z.duration ?? 0) * 1e3)), K = _ + se, ae = $r(D, K), de = ae ? Cr(ae, K) : 0;
464
+ let X;
465
+ ir($) === "oculus_direct" ? (X = Rr(ee), X === "U" && ae && Ft(ae.word, de) && (X = "FF")) : X = Or(
466
+ ee,
467
+ ae?.word ?? "",
468
+ de
469
+ ), g.push({
470
+ viseme: X,
470
471
  weight: 1,
471
472
  vtime: K,
472
473
  vduration: O
473
474
  });
474
475
  }), e.onNotify());
475
476
  }, A = (g, D, L, F, T, $, z) => {
476
- X(D, F, T, $), S(
477
+ Z(D, F, T, $), S(
477
478
  g,
478
479
  D,
479
480
  L,
@@ -484,15 +485,15 @@ function En(e, t) {
484
485
  }, M = async (g, D, L, F, T, $, z) => {
485
486
  if (y || !L?.trim())
486
487
  return;
487
- const Z = vn(z?.sampleRate), re = z?.newStream === !0;
488
+ const ee = En(z?.sampleRate), se = z?.newStream === !0;
488
489
  if (i) {
489
490
  n.push({
490
491
  audio: L,
491
492
  visemes: F,
492
493
  words: T,
493
494
  isNewSegment: $,
494
- sampleRate: Z,
495
- newStream: re
495
+ sampleRate: ee,
496
+ newStream: se
496
497
  });
497
498
  return;
498
499
  }
@@ -502,31 +503,31 @@ function En(e, t) {
502
503
  s || (s = new O());
503
504
  const K = s;
504
505
  K.state === "suspended" && await K.resume(), h || (h = K.createMediaStreamDestination());
505
- const le = await Nr(
506
+ const ae = await Vr(
506
507
  K,
507
508
  L,
508
- Z
509
+ ee
509
510
  );
510
511
  a = !0;
511
- const fe = K.currentTime;
512
- let ie = m;
512
+ const de = K.currentTime;
513
+ let X = m;
513
514
  const ge = !o;
514
- ie < fe && (ie = fe + 0.1), m = ie + le.duration;
515
- const ee = K.createBufferSource();
516
- if (ee.buffer = le, ee.playbackRate.value = v, ee.connect(K.destination), h && ee.connect(h), r.push(ee), y) {
515
+ X < de && (X = de + 0.1), m = X + ae.duration;
516
+ const te = K.createBufferSource();
517
+ if (te.buffer = ae, te.playbackRate.value = v, te.connect(K.destination), h && te.connect(h), r.push(te), y) {
517
518
  r.pop();
518
519
  return;
519
520
  }
520
521
  if (ge) {
521
- o = !0, e.onSpeakingStart(), re ? (u = ie, _ = 0, E = 0, g.length = 0, D.length = 0, z?.onNewStream?.()) : u <= 0 && (u = ie);
522
- const ye = (ie - fe) * 1e3;
522
+ o = !0, e.onSpeakingStart(), se ? (u = X, _ = 0, E = 0, g.length = 0, D.length = 0, z?.onNewStream?.()) : u <= 0 && (u = X);
523
+ const ye = (X - de) * 1e3;
523
524
  f = performance.now() + ye;
524
525
  }
525
- ee.onended = () => {
526
- const ye = r.indexOf(ee);
526
+ te.onended = () => {
527
+ const ye = r.indexOf(te);
527
528
  ye >= 0 && r.splice(ye, 1), N(), e.onNotify();
528
- }, ee.start(ie);
529
- const Fe = (ie - u) * 1e3;
529
+ }, te.start(X);
530
+ const Fe = (X - u) * 1e3;
530
531
  A(
531
532
  g,
532
533
  D,
@@ -535,7 +536,7 @@ function En(e, t) {
535
536
  Fe,
536
537
  $,
537
538
  d
538
- ), E = Math.max(E, Qe(g));
539
+ ), E = Math.max(E, Ye(g));
539
540
  } catch (O) {
540
541
  console.error("[avatarChunkPlayback] audio chunk failed:", O);
541
542
  } finally {
@@ -580,7 +581,7 @@ function En(e, t) {
580
581
  y = !0, b(), V(), n.length = 0, i = !1, o = !1, a = !1, l = !1, _ = 0, m = 0, u = 0, f = 0, E = 0;
581
582
  },
582
583
  markStreamComplete: (g) => {
583
- if (E = Math.max(E, Qe(g)), l = !0, !a && g.length > 0) {
584
+ if (E = Math.max(E, Ye(g)), l = !0, !a && g.length > 0) {
584
585
  G(g);
585
586
  return;
586
587
  }
@@ -590,7 +591,7 @@ function En(e, t) {
590
591
  queueTimingsOnly: (g, D, L, F, T) => {
591
592
  if (y) return;
592
593
  let $ = _;
593
- T && g.length > 0 && ($ = Qe(g)), A(
594
+ T && g.length > 0 && ($ = Ye(g)), A(
594
595
  g,
595
596
  D,
596
597
  L,
@@ -598,7 +599,7 @@ function En(e, t) {
598
599
  $,
599
600
  T,
600
601
  d
601
- ), E = Math.max(E, Qe(g));
602
+ ), E = Math.max(E, Ye(g));
602
603
  },
603
604
  getPlaybackElapsedMs: () => a && s && u > 0 ? Math.max(
604
605
  0,
@@ -622,7 +623,7 @@ function ht(e, t) {
622
623
  t < r.vtime || t >= r.vtime + r.vduration || (!n || r.vtime >= n.vtime) && (n = r);
623
624
  return n ? n.viseme : "sil";
624
625
  }
625
- function $r(e, t, n = 120) {
626
+ function Wr(e, t, n = 120) {
626
627
  const r = ht(e, t);
627
628
  if (r !== "sil") return r;
628
629
  let s = null;
@@ -633,17 +634,17 @@ function $r(e, t, n = 120) {
633
634
  }
634
635
  return s?.viseme ?? "sil";
635
636
  }
636
- function _i(e, t) {
637
+ function yi(e, t) {
637
638
  for (const n of e)
638
639
  if (t >= n.wtime && t < n.wtime + n.wduration)
639
640
  return n;
640
641
  return null;
641
642
  }
642
- const Bt = 0.5, Ot = 1.5, bn = "Olivia", Tn = "f786b574-daa5-4673-aa0c-cbe3e8534c02", wt = 0.85;
643
- function Zt(e, t = et) {
643
+ const Ot = 0.5, Lt = 1.5, Tn = "Olivia", An = "f786b574-daa5-4673-aa0c-cbe3e8534c02", wt = 0.85;
644
+ function en(e, t = tt) {
644
645
  const n = `${t.replace(/\/$/, "")}/avatar_ttsWithPoses`, r = [], s = [], i = [];
645
646
  let o = "neutral", a = "", l = Le;
646
- const f = /* @__PURE__ */ new Set(), u = () => f.forEach((v) => v()), _ = En(
647
+ const f = /* @__PURE__ */ new Set(), u = () => f.forEach((v) => v()), _ = bn(
647
648
  {
648
649
  onSpeakingStart: () => e("speaking"),
649
650
  onSpeakingDone: () => e("done"),
@@ -668,16 +669,16 @@ function Zt(e, t = et) {
668
669
  throw new Error("Developer token required for avatar_ttsWithPoses");
669
670
  const h = d?.ttsEngineId ?? l ?? Le;
670
671
  _.resetForNewStream(h), _.setStreamTtsEngineId(h);
671
- const E = d?.voiceId ?? bn, b = d?.speakingRate ?? wt, V = Math.max(
672
- Bt,
673
- Math.min(Ot, b)
672
+ const E = d?.voiceId ?? Tn, b = d?.speakingRate ?? wt, V = Math.max(
673
+ Ot,
674
+ Math.min(Lt, b)
674
675
  ), Q = {
675
676
  user_query: v,
676
677
  ttsEngineId: h,
677
678
  speakingRate: V,
678
679
  tenant: "aiTwin"
679
680
  };
680
- yn.has(h) && (Q.voice_id = E);
681
+ Sn.has(h) && (Q.voice_id = E);
681
682
  try {
682
683
  const N = await fetch(n, {
683
684
  method: "POST",
@@ -691,10 +692,10 @@ function Zt(e, t = et) {
691
692
  throw new Error(`avatar_ttsWithPoses failed (${N.status})`);
692
693
  const G = N.body;
693
694
  if (!G) throw new Error("No response body");
694
- const X = G.getReader(), S = new TextDecoder();
695
+ const Z = G.getReader(), S = new TextDecoder();
695
696
  let A = "";
696
697
  const M = async (I) => {
697
- const g = kn(I);
698
+ const g = vn(I);
698
699
  if (g) {
699
700
  if (g.event === "audio") {
700
701
  const D = g.data.chunk, L = g.data.visemes ?? [], F = g.data.words ?? [], T = g.data.is_new_segment ?? !1, $ = g.data.sample_rate;
@@ -740,7 +741,7 @@ function Zt(e, t = et) {
740
741
  }
741
742
  };
742
743
  for (; ; ) {
743
- const { done: I, value: g } = await X.read();
744
+ const { done: I, value: g } = await Z.read();
744
745
  g && (A += S.decode(g, { stream: !0 }));
745
746
  const D = A.split(`
746
747
 
@@ -771,8 +772,8 @@ function Zt(e, t = et) {
771
772
  subscribe: (v) => (f.add(v), () => f.delete(v))
772
773
  };
773
774
  }
774
- const An = 16e3, In = 16e3;
775
- class Wr extends Yn {
775
+ const In = 16e3, Rn = 16e3;
776
+ class qr extends Jn {
776
777
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
777
778
  async deserialize(t) {
778
779
  try {
@@ -784,7 +785,7 @@ class Wr extends Yn {
784
785
  }
785
786
  }
786
787
  }
787
- class qr extends Qn {
788
+ class Hr extends Yn {
788
789
  constructor() {
789
790
  super(
790
791
  !0,
@@ -792,39 +793,39 @@ class qr extends Qn {
792
793
  void 0,
793
794
  void 0,
794
795
  512,
795
- An,
796
- In
796
+ In,
797
+ Rn
797
798
  );
798
799
  }
799
800
  /** Pipecat protobuf bot audio is unused — playback comes from avatar_audio_chunk. */
800
801
  bufferBotAudio(t, n) {
801
802
  }
802
803
  }
803
- const Hr = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
804
- function Kr(e) {
805
- return Hr.test(e.trim());
806
- }
804
+ const Kr = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
807
805
  function jr(e) {
806
+ return Kr.test(e.trim());
807
+ }
808
+ function Gr(e) {
808
809
  const t = e.replace(/\/$/, "");
809
810
  return t.startsWith("https://") ? `wss://${t.slice(8)}` : t.startsWith("http://") ? `ws://${t.slice(7)}` : t;
810
811
  }
811
- function Gr(e) {
812
+ function zr(e) {
812
813
  if (e.wsUrl?.trim()) return e.wsUrl.trim();
813
814
  const t = e.authToken?.trim();
814
815
  if (!t)
815
816
  throw new Error(
816
817
  "Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
817
818
  );
818
- const n = e.apiBase ?? et, r = new URL(`${jr(n)}/ws/voice`);
819
+ const n = e.apiBase ?? tt, r = new URL(`${Gr(n)}/ws/voice`);
819
820
  r.searchParams.set("authToken", t), r.searchParams.set("tenant", "aiTwin");
820
821
  const s = e.voiceId?.trim();
821
- s && Kr(s) && r.searchParams.set("voiceId", s);
822
+ s && jr(s) && r.searchParams.set("voiceId", s);
822
823
  const i = e.personaId?.trim();
823
824
  i && r.searchParams.set("personaId", i);
824
825
  const o = e.speakingRate ?? wt;
825
826
  return r.searchParams.set(
826
827
  "speaking_rate",
827
- String(Math.max(Bt, Math.min(Ot, o)))
828
+ String(Math.max(Ot, Math.min(Lt, o)))
828
829
  ), e.ttsStream === !1 ? r.searchParams.set("tts_stream", "false") : r.searchParams.set("tts_stream", "true"), r.toString();
829
830
  }
830
831
  function vt(e, t) {
@@ -841,7 +842,7 @@ function vt(e, t) {
841
842
  });
842
843
  return n;
843
844
  }
844
- function zr(e) {
845
+ function Qr(e) {
845
846
  if (!e || typeof e != "object") return null;
846
847
  const t = e, r = (t.data && typeof t.data == "object" && !Array.isArray(t.data) ? t.data : null) || t;
847
848
  return {
@@ -852,19 +853,19 @@ function zr(e) {
852
853
  function Et(e) {
853
854
  return e.is_new_segment === !0 || Number(e.audio_offset_ms ?? -1) === 0 ? !0 : Number(e.chunk_index ?? -1) === 0;
854
855
  }
855
- function Qr(e) {
856
+ function Yr(e) {
856
857
  return e?.transport?._mediaManager?._wavStreamPlayer ?? null;
857
858
  }
858
- function Yr(e, t = {}) {
859
+ function Jr(e, t = {}) {
859
860
  const n = [], r = [], s = [], i = [];
860
- let o = "", a = "neutral", l = Ue, f = !1, u = null, _ = null, m = { ...t }, p = 0, v = null;
861
+ let o = "", a = "neutral", l = Ne, f = !1, u = null, _ = null, m = { ...t }, p = 0, v = null;
861
862
  const d = /* @__PURE__ */ new Set(), y = [];
862
863
  let h = !1, E = null, b = !0, V = "default";
863
864
  const Q = /* @__PURE__ */ new Set();
864
- let N = null, G = 0, X = !1, S = null;
865
+ let N = null, G = 0, Z = !1, S = null;
865
866
  const A = () => {
866
867
  S != null && (clearTimeout(S), S = null);
867
- }, M = () => d.forEach((c) => c()), I = En(
868
+ }, M = () => d.forEach((c) => c()), I = bn(
868
869
  {
869
870
  onSpeakingStart: () => e("speaking"),
870
871
  onSpeakingDone: () => e("done"),
@@ -876,36 +877,36 @@ function Yr(e, t = {}) {
876
877
  const c = new MessageChannel();
877
878
  return c.port1.onmessage = () => {
878
879
  const k = y.shift();
879
- k !== void 0 && Ve(k), y.length > 0 ? c.port2.postMessage(null) : h = !1;
880
+ k !== void 0 && $e(k), y.length > 0 ? c.port2.postMessage(null) : h = !1;
880
881
  }, E = c, c;
881
882
  }, D = (c) => {
882
883
  y.push(c), !h && (h = !0, g().port2.postMessage(null));
883
884
  }, L = () => I.getPlaybackElapsedMs(), F = (c, k = o) => {
884
885
  if (!m.onLipsyncDebug) return;
885
- const C = L(), j = n;
886
+ const x = L(), j = n;
886
887
  m.onLipsyncDebug({
887
888
  event: c,
888
889
  spokenText: k,
889
890
  mood: a,
890
891
  playbackAnchorPerf: I.getPlaybackStartPerf(),
891
- playbackElapsedMs: C,
892
+ playbackElapsedMs: x,
892
893
  queueLength: j.length,
893
- activeViseme: ht(j, C),
894
- segments: i.map((te) => ({
895
- ...te,
896
- visemes: [...te.visemes]
894
+ activeViseme: ht(j, x),
895
+ segments: i.map((ne) => ({
896
+ ...ne,
897
+ visemes: [...ne.visemes]
897
898
  }))
898
899
  });
899
900
  }, T = (c, k) => {
900
901
  m.onLipsyncDebug && (v = { event: c, spokenText: k }, p === 0 && (p = requestAnimationFrame(() => {
901
902
  p = 0;
902
- const C = v;
903
- v = null, C && F(C.event, C.spokenText);
903
+ const x = v;
904
+ v = null, x && F(x.event, x.spokenText);
904
905
  })));
905
906
  }, $ = () => {
906
907
  b = !0, Q.clear();
907
908
  }, z = () => {
908
- const c = Qr(u);
909
+ const c = Yr(u);
909
910
  if (c) {
910
911
  V = `bot-${Date.now()}`, c.interruptedTrackIds = { [V]: !0 };
911
912
  try {
@@ -918,70 +919,70 @@ function Yr(e, t = {}) {
918
919
  k?.interrupt?.();
919
920
  } catch {
920
921
  }
921
- }, Z = (c) => {
922
+ }, ee = (c) => {
922
923
  const k = c.context_id?.trim();
923
924
  return k && Q.has(k) ? !0 : b ? !1 : !(c.type === "avatar_metadata" || Et(c));
924
- }, re = (c) => {
925
+ }, se = (c) => {
925
926
  b = !1;
926
927
  const k = c.context_id?.trim();
927
- k && Q.add(k), A(), X = !1, y.length = 0, h = !1, N?.abort(), N = null, G += 1, z(), I.bargeIn(), O(), e("idle"), T("interrupt"), M();
928
+ k && Q.add(k), A(), Z = !1, y.length = 0, h = !1, N?.abort(), N = null, G += 1, z(), I.bargeIn(), O(), e("idle"), T("interrupt"), M();
928
929
  }, O = () => {
929
930
  n.length = 0, r.length = 0, i.length = 0, o = "", a = "neutral", s.length = 0;
930
931
  }, K = () => {
931
932
  I.stop(), O(), T("reset"), M();
932
- }, le = () => {
933
+ }, ae = () => {
933
934
  K(), e("idle"), M();
934
- }, fe = (c, k) => {
935
+ }, de = (c, k) => {
935
936
  typeof c.mood == "string" && c.mood.trim() && (a = c.mood.trim()), Array.isArray(c.sentence_emotions) && c.sentence_emotions.length > 0 && (k && (s.length = 0), s.push(
936
937
  ...vt(c.sentence_emotions, a)
937
938
  ));
938
- }, ie = (c) => {
939
- if (Z({ ...c, type: "avatar_metadata" }))
939
+ }, X = (c) => {
940
+ if (ee({ ...c, type: "avatar_metadata" }))
940
941
  return;
941
- $(), X = !0;
942
+ $(), Z = !0;
942
943
  const k = String(c.spoken_text ?? c.text ?? "").trim();
943
944
  k && (o = k), I.resetForNewStream(l), typeof c.mood == "string" && c.mood.trim() && (a = c.mood.trim()), s.length = 0, s.push(
944
945
  ...vt(c.sentence_emotions, a)
945
946
  ), Array.isArray(c.gestures) && c.gestures, T("metadata", k), M();
946
- }, ge = (c, k, C, j) => {
947
+ }, ge = (c, k, x, j) => {
947
948
  if (!m.onLipsyncDebug) return;
948
- const te = n.slice(C), ke = j.filter(
949
- (se) => String(se.symbol ?? se.viseme ?? "").trim()
949
+ const ne = n.slice(x), ke = j.filter(
950
+ (ie) => String(ie.symbol ?? ie.viseme ?? "").trim()
950
951
  );
951
952
  i.push({
952
953
  spokenText: k,
953
- audioOffsetMs: te[0]?.vtime ?? 0,
954
+ audioOffsetMs: ne[0]?.vtime ?? 0,
954
955
  isNewSegment: !!c.is_new_segment,
955
956
  chunkDurationMs: c.chunk_duration_ms != null ? Number(c.chunk_duration_ms) : null,
956
957
  receivedAtMs: performance.now(),
957
- visemes: te.map((se, Y) => {
958
+ visemes: ne.map((ie, Y) => {
958
959
  const pe = ke[Y];
959
960
  return {
960
- rawSymbol: String(pe?.symbol ?? pe?.viseme ?? se.viseme).trim(),
961
- viseme: se.viseme,
961
+ rawSymbol: String(pe?.symbol ?? pe?.viseme ?? ie.viseme).trim(),
962
+ viseme: ie.viseme,
962
963
  startSec: Number(pe?.start ?? 0),
963
964
  durationSec: Number(pe?.duration ?? 0),
964
- vtimeMs: se.vtime,
965
- vdurationMs: se.vduration
965
+ vtimeMs: ie.vtime,
966
+ vdurationMs: ie.vduration
966
967
  };
967
968
  })
968
969
  });
969
- }, ee = (c) => {
970
- if (Z(c)) return;
970
+ }, te = (c) => {
971
+ if (ee(c)) return;
971
972
  A(), Et(c) && $();
972
- const k = String(c.spoken_text ?? c.text ?? "").trim(), C = Et(c), j = c.visemes ?? [], te = c.words ?? [], ke = String(c.chunk ?? "").trim(), se = X;
973
- se && (X = !1), k && (o = k), fe(c, C), se ? I.resetForNewStream(l) : C && I.resumeBotStream();
973
+ const k = String(c.spoken_text ?? c.text ?? "").trim(), x = Et(c), j = c.visemes ?? [], ne = c.words ?? [], ke = String(c.chunk ?? "").trim(), ie = Z;
974
+ ie && (Z = !1), k && (o = k), de(c, x), ie ? I.resetForNewStream(l) : x && I.resumeBotStream();
974
975
  const Y = n.length;
975
976
  I.playAudioChunk(
976
977
  n,
977
978
  r,
978
979
  ke,
979
980
  j,
980
- te,
981
- C,
981
+ ne,
982
+ x,
982
983
  {
983
984
  sampleRate: c.sample_rate,
984
- newStream: se,
985
+ newStream: ie,
985
986
  onNewStream: () => {
986
987
  i.length = 0;
987
988
  }
@@ -990,13 +991,13 @@ function Yr(e, t = {}) {
990
991
  ge(c, k, Y, j), T("audio_chunk", k);
991
992
  });
992
993
  }, Fe = (c) => {
993
- if (Z(c)) return;
994
+ if (ee(c)) return;
994
995
  (c.is_new_segment || Number(c.audio_offset_ms ?? -1) === 0) && $(), console.warn(
995
996
  "[realtimeVoice] avatar_lipsync is deprecated — expect avatar_audio_chunk"
996
997
  );
997
998
  const k = String(c.spoken_text ?? c.text ?? "").trim();
998
- k && (o = k), fe(c, !!c.is_new_segment);
999
- const C = n.length;
999
+ k && (o = k), de(c, !!c.is_new_segment);
1000
+ const x = n.length;
1000
1001
  I.queueTimingsOnly(
1001
1002
  n,
1002
1003
  r,
@@ -1006,93 +1007,93 @@ function Yr(e, t = {}) {
1006
1007
  ), ge(
1007
1008
  c,
1008
1009
  k,
1009
- C,
1010
+ x,
1010
1011
  c.visemes ?? []
1011
1012
  ), T("lipsync", k), M();
1012
1013
  }, ye = async (c) => {
1013
1014
  const k = String(c.text ?? "").trim();
1014
1015
  if (!k) return;
1015
- const C = m.authToken?.trim();
1016
- if (!C) {
1016
+ const x = m.authToken?.trim();
1017
+ if (!x) {
1017
1018
  console.error("[realtimeVoice] avatar_speak requires authToken");
1018
1019
  return;
1019
1020
  }
1020
1021
  N?.abort();
1021
1022
  const j = new AbortController();
1022
1023
  N = j;
1023
- const te = ++G;
1024
+ const ne = ++G;
1024
1025
  $(), I.resetForNewStream(l), o = k;
1025
- const se = `${(m.apiBase ?? et).replace(/\/$/, "")}/avatar_ttsWithPoses`, Y = m.voiceId?.trim() || Tn, pe = m.speakingRate ?? wt, nt = Math.max(
1026
- Bt,
1027
- Math.min(Ot, pe)
1028
- ), We = {
1026
+ const ie = `${(m.apiBase ?? tt).replace(/\/$/, "")}/avatar_ttsWithPoses`, Y = m.voiceId?.trim() || An, pe = m.speakingRate ?? wt, rt = Math.max(
1027
+ Ot,
1028
+ Math.min(Lt, pe)
1029
+ ), qe = {
1029
1030
  user_query: k,
1030
1031
  ttsEngineId: l,
1031
- speakingRate: nt,
1032
+ speakingRate: rt,
1032
1033
  tenant: "aiTwin"
1033
1034
  };
1034
- yn.has(l) && (We.voice_id = Y);
1035
+ Sn.has(l) && (qe.voice_id = Y);
1035
1036
  try {
1036
- const ve = await fetch(se, {
1037
+ const ve = await fetch(ie, {
1037
1038
  method: "POST",
1038
1039
  headers: {
1039
1040
  "Content-Type": "application/json",
1040
- Authorization: `Bearer ${C}`
1041
+ Authorization: `Bearer ${x}`
1041
1042
  },
1042
- body: JSON.stringify(We),
1043
+ body: JSON.stringify(qe),
1043
1044
  signal: j.signal
1044
1045
  });
1045
1046
  if (!ve.ok)
1046
1047
  throw new Error(`avatar_ttsWithPoses failed (${ve.status})`);
1047
- const qe = ve.body;
1048
- if (!qe) throw new Error("No response body");
1049
- const Ie = qe.getReader(), rt = new TextDecoder();
1050
- let ae = "";
1048
+ const He = ve.body;
1049
+ if (!He) throw new Error("No response body");
1050
+ const Ie = He.getReader(), st = new TextDecoder();
1051
+ let oe = "";
1051
1052
  const Ee = async (q) => {
1052
- if (te !== G || j.signal.aborted || !b)
1053
+ if (ne !== G || j.signal.aborted || !b)
1053
1054
  return;
1054
- const x = kn(q);
1055
- if (x) {
1056
- if (x.event === "audio") {
1057
- const de = x.data.chunk, J = x.data.visemes ?? [], ue = x.data.words ?? [], He = x.data.is_new_segment ?? !1, Re = x.data.sample_rate;
1058
- de ? await I.playAudioChunk(
1055
+ const C = vn(q);
1056
+ if (C) {
1057
+ if (C.event === "audio") {
1058
+ const fe = C.data.chunk, J = C.data.visemes ?? [], le = C.data.words ?? [], Ke = C.data.is_new_segment ?? !1, Re = C.data.sample_rate;
1059
+ fe ? await I.playAudioChunk(
1059
1060
  n,
1060
1061
  r,
1061
- de,
1062
+ fe,
1062
1063
  J,
1063
- ue,
1064
- He,
1064
+ le,
1065
+ Ke,
1065
1066
  { sampleRate: Re }
1066
- ) : (J.length > 0 || ue.length > 0) && I.queueTimingsOnly(
1067
+ ) : (J.length > 0 || le.length > 0) && I.queueTimingsOnly(
1067
1068
  n,
1068
1069
  r,
1069
1070
  J,
1070
- ue,
1071
- He
1071
+ le,
1072
+ Ke
1072
1073
  );
1073
- } else if (x.event === "metadata") {
1074
- const de = x.data.mood;
1075
- typeof de == "string" && de.trim() && (a = de.trim());
1076
- const J = x.data.sentence_emotions;
1074
+ } else if (C.event === "metadata") {
1075
+ const fe = C.data.mood;
1076
+ typeof fe == "string" && fe.trim() && (a = fe.trim());
1077
+ const J = C.data.sentence_emotions;
1077
1078
  Array.isArray(J) && (s.length = 0, s.push(
1078
1079
  ...vt(J, a)
1079
1080
  )), M();
1080
- } else if (x.event === "error")
1081
+ } else if (C.event === "error")
1081
1082
  throw new Error(
1082
- String(x.data.message ?? "avatar_ttsWithPoses stream error")
1083
+ String(C.data.message ?? "avatar_ttsWithPoses stream error")
1083
1084
  );
1084
1085
  }
1085
1086
  };
1086
- for (; !(te !== G || j.signal.aborted || !b); ) {
1087
- const { done: q, value: x } = await Ie.read();
1088
- x && (ae += rt.decode(x, { stream: !0 }));
1089
- const de = ae.split(`
1087
+ for (; !(ne !== G || j.signal.aborted || !b); ) {
1088
+ const { done: q, value: C } = await Ie.read();
1089
+ C && (oe += st.decode(C, { stream: !0 }));
1090
+ const fe = oe.split(`
1090
1091
 
1091
1092
  `);
1092
- ae = de.pop() ?? "";
1093
- for (const J of de) await Ee(J);
1093
+ oe = fe.pop() ?? "";
1094
+ for (const J of fe) await Ee(J);
1094
1095
  if (q) {
1095
- ae.trim() && await Ee(ae.trim()), te === G && !j.signal.aborted && b && I.markStreamComplete(n);
1096
+ oe.trim() && await Ee(oe.trim()), ne === G && !j.signal.aborted && b && I.markStreamComplete(n);
1096
1097
  break;
1097
1098
  }
1098
1099
  }
@@ -1102,25 +1103,25 @@ function Yr(e, t = {}) {
1102
1103
  } finally {
1103
1104
  N === j && (N = null);
1104
1105
  }
1105
- }, Ve = (c) => {
1106
- const k = zr(c);
1106
+ }, $e = (c) => {
1107
+ const k = Qr(c);
1107
1108
  if (!k) {
1108
1109
  console.warn("[realtimeVoice] server message with no payload", c);
1109
1110
  return;
1110
1111
  }
1111
- const C = String(k.type ?? "unknown");
1112
- switch (C !== "avatar_metadata" && C !== "avatar_audio_chunk" && C !== "avatar_lipsync" && C !== "avatar_interrupt" && C !== "error" && console.debug("[realtimeVoice] server message", C, k), C) {
1112
+ const x = String(k.type ?? "unknown");
1113
+ switch (x !== "avatar_metadata" && x !== "avatar_audio_chunk" && x !== "avatar_lipsync" && x !== "avatar_interrupt" && x !== "error" && console.debug("[realtimeVoice] server message", x, k), x) {
1113
1114
  case "avatar_metadata":
1114
- ie(k);
1115
+ X(k);
1115
1116
  break;
1116
1117
  case "avatar_audio_chunk":
1117
- ee(k);
1118
+ te(k);
1118
1119
  break;
1119
1120
  case "avatar_lipsync":
1120
1121
  Fe(k);
1121
1122
  break;
1122
1123
  case "avatar_interrupt":
1123
- re(k);
1124
+ se(k);
1124
1125
  break;
1125
1126
  case "error": {
1126
1127
  const j = String(k.message ?? "Voice session error");
@@ -1131,12 +1132,12 @@ function Yr(e, t = {}) {
1131
1132
  ye(k);
1132
1133
  break;
1133
1134
  }
1134
- }, tt = () => u || (_ = new qr(), u = new Gn({
1135
- transport: new zn({
1135
+ }, nt = () => u || (_ = new Hr(), u = new zn({
1136
+ transport: new Qn({
1136
1137
  mediaManager: _,
1137
- serializer: new Wr(),
1138
- recorderSampleRate: An,
1139
- playerSampleRate: In
1138
+ serializer: new qr(),
1139
+ recorderSampleRate: In,
1140
+ playerSampleRate: Rn
1140
1141
  }),
1141
1142
  enableCam: !1,
1142
1143
  enableMic: !0,
@@ -1145,7 +1146,7 @@ function Yr(e, t = {}) {
1145
1146
  f = !0, e("idle"), M();
1146
1147
  },
1147
1148
  onDisconnected: () => {
1148
- f = !1, le();
1149
+ f = !1, ae();
1149
1150
  },
1150
1151
  onError: (c) => {
1151
1152
  const k = typeof c == "object" && c !== null && "data" in c ? String(c.data ?? c) : String(c);
@@ -1158,7 +1159,7 @@ function Yr(e, t = {}) {
1158
1159
  D(c);
1159
1160
  },
1160
1161
  onUserStartedSpeaking: () => {
1161
- re({});
1162
+ se({});
1162
1163
  },
1163
1164
  onBotStartedSpeaking: () => {
1164
1165
  T("bot_started");
@@ -1184,13 +1185,13 @@ function Yr(e, t = {}) {
1184
1185
  },
1185
1186
  getTtsEngineId: () => l,
1186
1187
  speak: async (c, k) => {
1187
- const C = c.trim();
1188
- if (C) {
1188
+ const x = c.trim();
1189
+ if (x) {
1189
1190
  if (!u || !f)
1190
1191
  throw new Error(
1191
1192
  "Realtime voice is not connected. Call connect() first."
1192
1193
  );
1193
- K(), await u.sendText(C);
1194
+ K(), await u.sendText(x);
1194
1195
  }
1195
1196
  },
1196
1197
  stop: () => {
@@ -1202,27 +1203,27 @@ function Yr(e, t = {}) {
1202
1203
  "Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
1203
1204
  );
1204
1205
  e("loading");
1205
- const k = tt();
1206
+ const k = nt();
1206
1207
  await k.initDevices();
1207
- const C = Gr(m);
1208
- console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", C);
1208
+ const x = zr(m);
1209
+ console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", x);
1209
1210
  try {
1210
- await k.connect({ wsUrl: C });
1211
+ await k.connect({ wsUrl: x });
1211
1212
  } catch (j) {
1212
1213
  f = !1, e("error"), M();
1213
- const te = j instanceof Error ? j.message : "Realtime voice connect failed (WebSocket 101 only means upgrade OK — check authToken/origin/RTVI handshake)";
1214
- throw new Error(`${te} — ${C}`);
1214
+ const ne = j instanceof Error ? j.message : "Realtime voice connect failed (WebSocket 101 only means upgrade OK — check authToken/origin/RTVI handshake)";
1215
+ throw new Error(`${ne} — ${x}`);
1215
1216
  }
1216
1217
  f = !0, e("idle"), M();
1217
1218
  },
1218
1219
  disconnect: async () => {
1219
- if (A(), X = !1, y.length = 0, h = !1, N?.abort(), N = null, G += 1, $(), u)
1220
+ if (A(), Z = !1, y.length = 0, h = !1, N?.abort(), N = null, G += 1, $(), u)
1220
1221
  try {
1221
1222
  await u.disconnect();
1222
1223
  } catch (c) {
1223
1224
  console.error("[realtimeVoice] disconnect failed:", c);
1224
1225
  }
1225
- f = !1, le();
1226
+ f = !1, ae();
1226
1227
  },
1227
1228
  isConnected: () => f,
1228
1229
  unlockAudio: async () => {
@@ -1242,13 +1243,13 @@ function Yr(e, t = {}) {
1242
1243
  subscribe: (c) => (d.add(c), () => d.delete(c))
1243
1244
  };
1244
1245
  }
1245
- function Jr(e, t, n) {
1246
+ function Xr(e, t, n) {
1246
1247
  return {
1247
1248
  width: e.crop?.source_width ?? t,
1248
1249
  height: e.crop?.source_height ?? n
1249
1250
  };
1250
1251
  }
1251
- function Xr(e, t) {
1252
+ function Zr(e, t) {
1252
1253
  const n = e.crop;
1253
1254
  return {
1254
1255
  x: t?.source_x ?? n?.x ?? 0,
@@ -1257,21 +1258,21 @@ function Xr(e, t) {
1257
1258
  height: t?.source_h ?? n?.height ?? e.frame_height ?? 0
1258
1259
  };
1259
1260
  }
1260
- function Zr(e) {
1261
+ function es(e) {
1261
1262
  return e ? (e.w ?? 0) > 0 && (e.h ?? 0) > 0 : !1;
1262
1263
  }
1263
1264
  async function gt(e, t) {
1264
1265
  const n = await fetch(e);
1265
1266
  if (!n.ok) throw new Error(`Failed to load encrypted asset: ${e}`);
1266
1267
  const r = await n.arrayBuffer();
1267
- return gr(r, t);
1268
+ return pr(r, t);
1268
1269
  }
1269
- async function es(e, t) {
1270
+ async function ts(e, t) {
1270
1271
  if (!t) throw new Error("Missing asset key for encrypted JSON");
1271
1272
  const n = await gt(e, t), r = new TextDecoder().decode(n);
1272
1273
  return JSON.parse(r);
1273
1274
  }
1274
- async function ts(e) {
1275
+ async function ns(e) {
1275
1276
  const t = new Blob([e], { type: "image/webp" }), n = URL.createObjectURL(t);
1276
1277
  return new Promise((r, s) => {
1277
1278
  const i = new Image();
@@ -1282,7 +1283,7 @@ async function ts(e) {
1282
1283
  }, i.src = n;
1283
1284
  });
1284
1285
  }
1285
- async function ns(e) {
1286
+ async function rs(e) {
1286
1287
  const t = new Blob([e], { type: "image/png" }), n = URL.createObjectURL(t);
1287
1288
  return new Promise((r, s) => {
1288
1289
  const i = new Image();
@@ -1293,28 +1294,28 @@ async function ns(e) {
1293
1294
  }, i.src = n;
1294
1295
  });
1295
1296
  }
1296
- function rs(e) {
1297
+ function ss(e) {
1297
1298
  const t = new Blob([e], { type: "video/mp4" });
1298
1299
  return URL.createObjectURL(t);
1299
1300
  }
1300
- async function ss(e) {
1301
- const t = kr();
1302
- if (!dt()) return t;
1301
+ async function is(e) {
1302
+ const t = vr();
1303
+ if (!mt()) return t;
1303
1304
  if (!e) throw new Error("Missing asset key for encrypted idle video");
1304
1305
  const n = await gt(t, e);
1305
- return rs(n);
1306
+ return ss(n);
1306
1307
  }
1307
- function Lt(e, t) {
1308
+ function Ut(e, t) {
1308
1309
  return `${e}/${t}_minus_sil.png`;
1309
1310
  }
1310
- const Rn = 5;
1311
- function Dn(e) {
1311
+ const Dn = 5;
1312
+ function Mn(e) {
1312
1313
  const t = e?.composite_threshold;
1313
1314
  if (typeof t == "number" && t > 0) return t;
1314
1315
  const n = e?.crop?.content_threshold;
1315
- return typeof n == "number" && n > 0 ? n : Rn;
1316
+ return typeof n == "number" && n > 0 ? n : Dn;
1316
1317
  }
1317
- const yi = [
1318
+ const Si = [
1318
1319
  "aa",
1319
1320
  "E",
1320
1321
  "I",
@@ -1333,7 +1334,7 @@ const yi = [
1333
1334
  "t01_0.25",
1334
1335
  "t02_0.50",
1335
1336
  "t03_0.75"
1336
- ], is = Rt.length, en = /* @__PURE__ */ new Set([
1337
+ ], as = Rt.length, tn = /* @__PURE__ */ new Set([
1337
1338
  "aa__kk",
1338
1339
  "aa__nn",
1339
1340
  "aa__sil",
@@ -1440,75 +1441,75 @@ const yi = [
1440
1441
  "U__nn",
1441
1442
  "U__sil"
1442
1443
  ]);
1443
- function tn(e, t) {
1444
+ function nn(e, t) {
1444
1445
  return `${e}__${t}`;
1445
1446
  }
1446
- function nn(e, t) {
1447
+ function rn(e, t) {
1447
1448
  return `pairs/${e}/${t}_minus_sil.png`;
1448
1449
  }
1449
- function ut(e) {
1450
+ function lt(e) {
1450
1451
  return `${e}_minus_sil.png`;
1451
1452
  }
1452
- function as(e, t) {
1453
+ function os(e, t) {
1453
1454
  if (t.has(e)) return e;
1454
1455
  const n = /^pairs\/([^/]+)\//.exec(e);
1455
1456
  if (!n) return null;
1456
1457
  const r = n[1].split("__")[1];
1457
1458
  if (!r || r === "sil") return null;
1458
- const s = ut(r);
1459
+ const s = lt(r);
1459
1460
  return t.has(s) ? s : null;
1460
1461
  }
1461
- function Mn(e, t) {
1462
+ function Cn(e, t) {
1462
1463
  return e.filter((n) => t.has(n));
1463
1464
  }
1464
- function os(e, t, n) {
1465
- const r = Ut(e, t);
1466
- return Mn(r, n).length > 0;
1465
+ function cs(e, t, n) {
1466
+ const r = Nt(e, t);
1467
+ return Cn(r, n).length > 0;
1467
1468
  }
1468
- function Ut(e, t) {
1469
+ function Nt(e, t) {
1469
1470
  if (e === t) return [];
1470
- const n = [], r = tn(e, t);
1471
- if (en.has(r)) {
1471
+ const n = [], r = nn(e, t);
1472
+ if (tn.has(r)) {
1472
1473
  for (const i of Rt)
1473
- n.push(nn(r, i));
1474
+ n.push(rn(r, i));
1474
1475
  return n;
1475
1476
  }
1476
- const s = tn(t, e);
1477
- if (en.has(s)) {
1478
- for (let i = is - 1; i >= 0; i--)
1479
- n.push(nn(s, Rt[i]));
1477
+ const s = nn(t, e);
1478
+ if (tn.has(s)) {
1479
+ for (let i = as - 1; i >= 0; i--)
1480
+ n.push(rn(s, Rt[i]));
1480
1481
  return n;
1481
1482
  }
1482
1483
  return [];
1483
1484
  }
1484
- function cs(e) {
1485
+ function us(e) {
1485
1486
  return e < 16 ? [] : e < 35 ? [1] : e < 51 ? [0, 2] : [0, 1, 2];
1486
1487
  }
1487
- function us(e, t) {
1488
- return cs(t).map((r) => e[r]).filter((r) => r != null);
1488
+ function ls(e, t) {
1489
+ return us(t).map((r) => e[r]).filter((r) => r != null);
1489
1490
  }
1490
- function ls(e, t, n, r) {
1491
+ function fs(e, t, n, r) {
1491
1492
  if (r <= 0) return 0;
1492
1493
  const i = Math.max(1, n - t) / r, o = e - t, a = Math.floor(o / i);
1493
1494
  return Math.min(r - 1, Math.max(0, a));
1494
1495
  }
1495
- function fs(e, t, n) {
1496
+ function ds(e, t, n) {
1496
1497
  if (!n) return `${e}/${t}`;
1497
1498
  const r = t.split("/").pop() ?? t, s = r.includes(".") ? r.slice(0, r.lastIndexOf(".")) : r;
1498
1499
  return `${e}/${s}.bin`;
1499
1500
  }
1500
- const ds = [0.32, 0.24, 0.16, 0.08, 0], ms = ds.map(
1501
+ const ms = [0.32, 0.24, 0.16, 0.08, 0], hs = ms.map(
1501
1502
  (e) => `eyes_${e.toFixed(2)}`
1502
- ), hs = [
1503
+ ), ws = [
1503
1504
  "eyes_0.32",
1504
1505
  "eyes_0.16",
1505
1506
  "eyes_0.00"
1506
- ], ws = [
1507
+ ], gs = [
1507
1508
  "eyes_0.32",
1508
1509
  "eyes_0.16",
1509
1510
  "eyes_0.08",
1510
1511
  "eyes_0.00"
1511
- ], rn = 2, gs = -30, Dt = 20, ps = {
1512
+ ], sn = 2, ps = -30, Dt = 20, _s = {
1512
1513
  fear: -30,
1513
1514
  anger: -20,
1514
1515
  sad: -10,
@@ -1517,24 +1518,24 @@ const ds = [0.32, 0.24, 0.16, 0.08, 0], ms = ds.map(
1517
1518
  happy: 0,
1518
1519
  disgust: 20
1519
1520
  };
1520
- function Nt(e) {
1521
+ function Vt(e) {
1521
1522
  return `brow_${e}`;
1522
1523
  }
1523
- function Vt(e) {
1524
- return ps[e];
1524
+ function $t(e) {
1525
+ return _s[e];
1525
1526
  }
1526
- function Ce(e) {
1527
- return Math.max(gs, Math.min(Dt, e));
1527
+ function xe(e) {
1528
+ return Math.max(ps, Math.min(Dt, e));
1528
1529
  }
1529
- function _s(e, t) {
1530
+ function ys(e, t) {
1530
1531
  if (e === t) return [];
1531
- const n = e < t ? rn : -rn, r = [];
1532
+ const n = e < t ? sn : -sn, r = [];
1532
1533
  let s = e;
1533
1534
  for (; s !== t; )
1534
1535
  s += n, r.push(s);
1535
1536
  return r;
1536
1537
  }
1537
- const ys = {
1538
+ const Ss = {
1538
1539
  fear: "fear",
1539
1540
  afraid: "fear",
1540
1541
  anxiety: "fear",
@@ -1559,61 +1560,61 @@ const ys = {
1559
1560
  };
1560
1561
  function Oe(e, t = "neutral") {
1561
1562
  const n = String(e ?? "").trim().toLowerCase();
1562
- return n ? ys[n] ?? t : t;
1563
+ return n ? Ss[n] ?? t : t;
1563
1564
  }
1564
1565
  function xn(e) {
1565
- return e === 0 ? null : Lt(Nt(e), "eyes_standard");
1566
+ return e === 0 ? null : Ut(Vt(e), "eyes_standard");
1566
1567
  }
1567
- function Cn(e) {
1568
- return xn(Vt(e));
1568
+ function Pn(e) {
1569
+ return xn($t(e));
1569
1570
  }
1570
- function sn(e, t) {
1571
- const n = Nt(Vt(e));
1572
- return !t || t === "eyes_standard" ? Cn(e) : e === "neutral" && t === "eyes_standard" ? null : Lt(n, t);
1571
+ function an(e, t) {
1572
+ const n = Vt($t(e));
1573
+ return !t || t === "eyes_standard" ? Pn(e) : e === "neutral" && t === "eyes_standard" ? null : Ut(n, t);
1573
1574
  }
1574
- function Ss(e, t) {
1575
+ function ks(e, t) {
1575
1576
  const n = [];
1576
1577
  for (const r of t)
1577
- n.push(sn(e, r));
1578
+ n.push(an(e, r));
1578
1579
  for (let r = t.length - 2; r >= 0; r--)
1579
- n.push(sn(e, t[r]));
1580
- return n.push(Cn(e)), n;
1580
+ n.push(an(e, t[r]));
1581
+ return n.push(Pn(e)), n;
1581
1582
  }
1582
- function ks(e) {
1583
- return e === 0 ? null : Lt(Nt(e), "eyes_standard");
1583
+ function vs(e) {
1584
+ return e === 0 ? null : Ut(Vt(e), "eyes_standard");
1584
1585
  }
1585
- function vs(e, t) {
1586
- return _s(e, t).map(ks).filter((n) => n != null);
1586
+ function Es(e, t) {
1587
+ return ys(e, t).map(vs).filter((n) => n != null);
1587
1588
  }
1588
- const Es = 6;
1589
- function bs(e, t) {
1589
+ const bs = 6;
1590
+ function Ts(e, t) {
1590
1591
  for (const n of e)
1591
1592
  if (t >= n.wtime && t < n.wtime + n.wduration)
1592
1593
  return n;
1593
1594
  return null;
1594
1595
  }
1595
- function Ts(e) {
1596
- const t = Ce(e);
1597
- return t >= Dt ? Dt : Ce(t + Es);
1596
+ function As(e) {
1597
+ const t = xe(e);
1598
+ return t >= Dt ? Dt : xe(t + bs);
1598
1599
  }
1599
- function As(e, t, n) {
1600
- const r = Ce(n);
1601
- return bs(t, e)?.emphasis ? Ts(r) : r;
1600
+ function Is(e, t, n) {
1601
+ const r = xe(n);
1602
+ return Ts(t, e)?.emphasis ? As(r) : r;
1602
1603
  }
1603
- function an(e) {
1604
+ function on(e) {
1604
1605
  if (!e) return 0;
1605
1606
  const t = e.match(/^brow_(-?\d+)\//);
1606
1607
  if (!t?.[1]) return null;
1607
1608
  const n = Number.parseInt(t[1], 10);
1608
- return Number.isFinite(n) ? Ce(n) : null;
1609
+ return Number.isFinite(n) ? xe(n) : null;
1609
1610
  }
1610
- function Je(e, t) {
1611
+ function Xe(e, t) {
1611
1612
  return e + Math.random() * (t - e);
1612
1613
  }
1613
- function ot() {
1614
- return Je(14, 32);
1614
+ function ct() {
1615
+ return Xe(14, 32);
1615
1616
  }
1616
- function Is(e = {}) {
1617
+ function Rs(e = {}) {
1617
1618
  const {
1618
1619
  initialDelayMs: t = 800 + Math.random() * 1200,
1619
1620
  intervalMinMs: n = 2200,
@@ -1634,51 +1635,51 @@ function Is(e = {}) {
1634
1635
  }
1635
1636
  function b(S, A = u) {
1636
1637
  y = S;
1637
- const M = an(S);
1638
+ const M = on(S);
1638
1639
  M != null ? p = M : S == null && (p = 0), E(A);
1639
1640
  }
1640
1641
  function V(S) {
1641
1642
  return xn(S);
1642
1643
  }
1643
1644
  function Q(S, A, M) {
1644
- const I = Ce(A), g = Ce(M);
1645
+ const I = xe(A), g = xe(M);
1645
1646
  if (m = g, I === g) {
1646
1647
  b(V(g));
1647
1648
  return;
1648
1649
  }
1649
1650
  const D = [
1650
- ...vs(I, g),
1651
+ ...Es(I, g),
1651
1652
  V(g)
1652
1653
  ];
1653
1654
  d = {
1654
1655
  kind: "browBlend",
1655
1656
  paths: D,
1656
1657
  index: 0,
1657
- holdUntil: S + ot(),
1658
+ holdUntil: S + ct(),
1658
1659
  targetBrow: g
1659
1660
  }, b(D[0] ?? null);
1660
1661
  }
1661
1662
  function N(S, A) {
1662
1663
  d = {
1663
1664
  kind: "idle",
1664
- nextBlinkAt: S + Je(n, r)
1665
+ nextBlinkAt: S + Xe(n, r)
1665
1666
  }, _ = A, b(V(m), A);
1666
1667
  }
1667
1668
  function G(S, A, M) {
1668
- const I = M ? hs : Math.random() < a ? ms : ws;
1669
+ const I = M ? ws : Math.random() < a ? hs : gs;
1669
1670
  d = {
1670
1671
  kind: "playing",
1671
- paths: Ss(A, I),
1672
+ paths: ks(A, I),
1672
1673
  index: 0,
1673
- holdUntil: S + ot(),
1674
+ holdUntil: S + ct(),
1674
1675
  after: "idle",
1675
1676
  blinkEmotion: A
1676
1677
  }, _ = A, b(d.paths[0] ?? null, A);
1677
1678
  }
1678
- function X(S) {
1679
+ function Z(S) {
1679
1680
  if (d.kind === "browBlend") {
1680
1681
  for (; S >= d.holdUntil && d.index < d.paths.length - 1; )
1681
- d.index += 1, d.holdUntil = S + ot();
1682
+ d.index += 1, d.holdUntil = S + ct();
1682
1683
  const A = d.paths[d.index] ?? null;
1683
1684
  b(A), S >= d.holdUntil && d.index >= d.paths.length - 1 && (p = d.targetBrow, m = d.targetBrow, b(V(d.targetBrow)), d = {
1684
1685
  kind: "idle",
@@ -1696,7 +1697,7 @@ function Is(e = {}) {
1696
1697
  }
1697
1698
  if (d.kind === "playing") {
1698
1699
  for (; S >= d.holdUntil && d.index < d.paths.length - 1; )
1699
- d.index += 1, d.holdUntil = S + ot();
1700
+ d.index += 1, d.holdUntil = S + ct();
1700
1701
  if (b(d.paths[d.index] ?? null, d.blinkEmotion), S >= d.holdUntil && d.index >= d.paths.length - 1) {
1701
1702
  if (d.after === "resumeIdle") {
1702
1703
  N(S + l, u);
@@ -1705,7 +1706,7 @@ function Is(e = {}) {
1705
1706
  if (d.after === "doublePause") {
1706
1707
  d = {
1707
1708
  kind: "doublePause",
1708
- resumeAt: S + Je(i, o),
1709
+ resumeAt: S + Xe(i, o),
1709
1710
  blinkEmotion: d.blinkEmotion
1710
1711
  }, b(V(m), d.blinkEmotion);
1711
1712
  return;
@@ -1713,7 +1714,7 @@ function Is(e = {}) {
1713
1714
  if (d.after === "idle" && Math.random() < s) {
1714
1715
  d = {
1715
1716
  kind: "doublePause",
1716
- resumeAt: S + Je(i, o),
1717
+ resumeAt: S + Xe(i, o),
1717
1718
  blinkEmotion: d.blinkEmotion
1718
1719
  }, b(V(m), d.blinkEmotion);
1719
1720
  return;
@@ -1723,7 +1724,7 @@ function Is(e = {}) {
1723
1724
  }
1724
1725
  }
1725
1726
  return {
1726
- advance: X,
1727
+ advance: Z,
1727
1728
  setTargetEmotion(S) {
1728
1729
  const A = Oe(S, u);
1729
1730
  if (A === u) return;
@@ -1731,9 +1732,9 @@ function Is(e = {}) {
1731
1732
  f > 0 && A !== u && !(u === "neutral" && A !== "neutral") && M - v < f || (u = A, _ = A, v = M);
1732
1733
  },
1733
1734
  setTargetEyebrow(S) {
1734
- const A = Ce(S);
1735
+ const A = xe(S);
1735
1736
  if (A === m && d.kind !== "browBlend") return;
1736
- const M = performance.now(), I = d.kind === "browBlend" ? an(y) ?? p : p;
1737
+ const M = performance.now(), I = d.kind === "browBlend" ? on(y) ?? p : p;
1737
1738
  m = A, !(A === I && d.kind !== "browBlend") && (d.kind === "playing" || d.kind === "doublePause" || Q(M, I, A));
1738
1739
  },
1739
1740
  getTargetEmotion: () => u,
@@ -1742,13 +1743,13 @@ function Is(e = {}) {
1742
1743
  getDrawKey: () => h,
1743
1744
  reset() {
1744
1745
  u = "neutral", _ = "neutral", m = 0, p = 0, v = 0, N(
1745
- performance.now() + Je(n, r),
1746
+ performance.now() + Xe(n, r),
1746
1747
  "neutral"
1747
1748
  );
1748
1749
  }
1749
1750
  };
1750
1751
  }
1751
- function Rs() {
1752
+ function Ds() {
1752
1753
  const e = document.createElement("video");
1753
1754
  e.muted = !0, e.playsInline = !0, e.preload = "auto", e.setAttribute("playsinline", ""), e.loop = !0;
1754
1755
  let t = !1, n = null, r = "";
@@ -1791,8 +1792,8 @@ function Rs() {
1791
1792
  }
1792
1793
  };
1793
1794
  }
1794
- const Ds = 50, Pn = 400;
1795
- function Ms(e, t, n) {
1795
+ const Ms = 50, Fn = 400;
1796
+ function Cs(e, t, n) {
1796
1797
  return e.filter((r) => {
1797
1798
  const s = r.queueIndex ?? -1;
1798
1799
  return s >= t && s <= n;
@@ -1801,7 +1802,7 @@ function Ms(e, t, n) {
1801
1802
  function xs(e, t) {
1802
1803
  const n = [];
1803
1804
  for (const r of e) {
1804
- const s = Ms(
1805
+ const s = Cs(
1805
1806
  t,
1806
1807
  r.start_word,
1807
1808
  r.end_word
@@ -1810,13 +1811,13 @@ function xs(e, t) {
1810
1811
  const i = s[0], o = s[s.length - 1];
1811
1812
  n.push({
1812
1813
  sentence: r,
1813
- startMs: Math.max(0, i.wtime - Ds),
1814
- endMs: o.wtime + o.wduration + Pn
1814
+ startMs: Math.max(0, i.wtime - Ms),
1815
+ endMs: o.wtime + o.wduration + Fn
1815
1816
  });
1816
1817
  }
1817
1818
  return n.sort((r, s) => r.startMs - s.startMs);
1818
1819
  }
1819
- function Cs(e, t, n, r = "neutral") {
1820
+ function Ps(e, t, n, r = "neutral") {
1820
1821
  const s = Oe(r);
1821
1822
  if (t.length === 0) return s;
1822
1823
  if (n.length === 0 || e < n[0].wtime)
@@ -1828,12 +1829,12 @@ function Cs(e, t, n, r = "neutral") {
1828
1829
  if (o)
1829
1830
  return Oe(o.sentence.emotion, s);
1830
1831
  const a = n[n.length - 1], l = a.wtime + a.wduration;
1831
- return e > l + Pn ? Oe(
1832
+ return e > l + Fn ? Oe(
1832
1833
  t[t.length - 1]?.emotion,
1833
1834
  s
1834
1835
  ) : s;
1835
1836
  }
1836
- function Fn(e, t, n, r, s = Rn) {
1837
+ function Bn(e, t, n, r, s = Dn) {
1837
1838
  const i = new OffscreenCanvas(n, r), o = i.getContext("2d", { willReadFrequently: !0 });
1838
1839
  o.drawImage(e, 0, 0, n, r);
1839
1840
  const a = o.getImageData(0, 0, n, r), l = o.createImageData(n, r);
@@ -1849,38 +1850,38 @@ function Fn(e, t, n, r, s = Rn) {
1849
1850
  }
1850
1851
  return o.putImageData(l, 0, 0), i;
1851
1852
  }
1852
- let xe = null, Xe = null;
1853
- const lt = /* @__PURE__ */ new Map();
1854
- function Ps() {
1855
- xe = null, Xe = null, lt.clear();
1853
+ let Ce = null, Ze = null;
1854
+ const ft = /* @__PURE__ */ new Map();
1855
+ function Fs() {
1856
+ Ce = null, Ze = null, ft.clear();
1856
1857
  }
1857
- Sr(Ps);
1858
- function Fs(e) {
1859
- return e ?? Xe ?? void 0;
1858
+ kr(Fs);
1859
+ function Bs(e) {
1860
+ return e ?? Ze ?? void 0;
1860
1861
  }
1861
- function $t(e) {
1862
+ function Wt(e) {
1862
1863
  return new Promise((t, n) => {
1863
1864
  const r = new Image();
1864
1865
  r.decoding = "async", r.onload = () => t(r), r.onerror = () => n(new Error(`Failed to load image: ${e}`)), r.src = e;
1865
1866
  });
1866
1867
  }
1867
- async function Bs(e) {
1868
- return dt() ? ns(
1869
- await gt(Jt(), e ?? "")
1870
- ) : $t(Jt());
1868
+ async function Os(e) {
1869
+ return mt() ? rs(
1870
+ await gt(Xt(), e ?? "")
1871
+ ) : Wt(Xt());
1871
1872
  }
1872
- async function on(e, t, n, r) {
1873
- const s = n ? await es(e, r) : await fetch(e).then((f) => {
1873
+ async function cn(e, t, n, r) {
1874
+ const s = n ? await ts(e, r) : await fetch(e).then((f) => {
1874
1875
  if (!f.ok) throw new Error(`Failed to load ${e}`);
1875
1876
  return f.json();
1876
1877
  }), i = s.sheets?.[0];
1877
1878
  if (!i?.path) throw new Error(`${e} has no sheets[0].path`);
1878
- const o = n ? await ts(
1879
+ const o = n ? await ns(
1879
1880
  await gt(
1880
- fs(t, i.path, n),
1881
+ ds(t, i.path, n),
1881
1882
  r ?? ""
1882
1883
  )
1883
- ) : await $t(`${t}/${i.path}`), a = /* @__PURE__ */ new Map();
1884
+ ) : await Wt(`${t}/${i.path}`), a = /* @__PURE__ */ new Map();
1884
1885
  for (const f of s.cells ?? [])
1885
1886
  f.path && a.set(f.path, f);
1886
1887
  const l = /* @__PURE__ */ new Map();
@@ -1889,29 +1890,29 @@ async function on(e, t, n, r) {
1889
1890
  return { atlas: o, atlasMeta: s, cellByPath: a, sheetByIndex: l, diffBase: t };
1890
1891
  }
1891
1892
  async function Mt(e) {
1892
- const t = Fs(e), n = dt();
1893
+ const t = Bs(e), n = mt();
1893
1894
  if (n && !t)
1894
1895
  throw new Error("Encrypted assets enabled but no key provided");
1895
- if (xe && (!n || Xe === (t ?? null))) {
1896
- const i = await xe;
1896
+ if (Ce && (!n || Ze === (t ?? null))) {
1897
+ const i = await Ce;
1897
1898
  return {
1898
- ...Ze(i),
1899
+ ...et(i),
1899
1900
  visemePaths: [...i.viseme.cellByPath.keys()]
1900
1901
  };
1901
1902
  }
1902
- Xe = t ?? null, lt.clear();
1903
- const r = vr();
1904
- xe = (async () => {
1905
- const i = await Bs(t), o = await on(
1906
- Er(),
1903
+ Ze = t ?? null, ft.clear();
1904
+ const r = Er();
1905
+ Ce = (async () => {
1906
+ const i = await Os(t), o = await cn(
1907
+ br(),
1907
1908
  r,
1908
1909
  n,
1909
1910
  t
1910
1911
  );
1911
1912
  let a = null;
1912
1913
  try {
1913
- a = await on(
1914
- br(),
1914
+ a = await cn(
1915
+ Tr(),
1915
1916
  r,
1916
1917
  n,
1917
1918
  t
@@ -1921,45 +1922,45 @@ async function Mt(e) {
1921
1922
  }
1922
1923
  return { sil: i, viseme: o, expression: a };
1923
1924
  })();
1924
- const s = await xe;
1925
- return { ...Ze(s), visemePaths: [...s.viseme.cellByPath.keys()] };
1925
+ const s = await Ce;
1926
+ return { ...et(s), visemePaths: [...s.viseme.cellByPath.keys()] };
1926
1927
  }
1927
- async function Bn(e) {
1928
- if (await Mt(e), !xe) throw new Error("Assets not loaded");
1929
- return xe;
1928
+ async function On(e) {
1929
+ if (await Mt(e), !Ce) throw new Error("Assets not loaded");
1930
+ return Ce;
1930
1931
  }
1931
- function Ze(e) {
1932
- return Jr(
1932
+ function et(e) {
1933
+ return Xr(
1933
1934
  e.viseme.atlasMeta,
1934
1935
  e.sil.naturalWidth,
1935
1936
  e.sil.naturalHeight
1936
1937
  );
1937
1938
  }
1938
- function Os(e, t) {
1939
+ function Ls(e, t) {
1939
1940
  const n = document.createElement("canvas");
1940
1941
  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;
1941
1942
  }
1942
- async function cn(e, t, n) {
1943
- const r = `${t.diffBase}::${n}`, s = lt.get(r);
1943
+ async function un(e, t, n) {
1944
+ const r = `${t.diffBase}::${n}`, s = ft.get(r);
1944
1945
  if (s) return s;
1945
1946
  const i = (async () => {
1946
1947
  const o = t.cellByPath.get(n);
1947
1948
  if (!o) throw new Error(`No atlas cell for path: ${n}`);
1948
- const a = Xr(t.atlasMeta, o), l = Ze(e);
1949
- if (Zr(o)) {
1950
- const _ = Os(t, o), m = document.createElement("canvas");
1949
+ const a = Zr(t.atlasMeta, o), l = et(e);
1950
+ if (es(o)) {
1951
+ const _ = Ls(t, o), m = document.createElement("canvas");
1951
1952
  m.width = l.width, m.height = l.height;
1952
1953
  const p = m.getContext("2d");
1953
1954
  return p.fillStyle = "#000", p.fillRect(0, 0, l.width, l.height), p.drawImage(_, a.x, a.y), m;
1954
1955
  }
1955
- const f = `${t.diffBase}/${n}`, u = await $t(f);
1956
+ const f = `${t.diffBase}/${n}`, u = await Wt(f);
1956
1957
  if (u.naturalWidth === l.width && u.naturalHeight === l.height)
1957
1958
  return u;
1958
1959
  throw new Error(`Diff PNG wrong size for ${n}`);
1959
1960
  })();
1960
- return lt.set(r, i), i;
1961
+ return ft.set(r, i), i;
1961
1962
  }
1962
- async function un(e, t, n, r, s, i) {
1963
+ async function ln(e, t, n, r, s, i) {
1963
1964
  if (s) {
1964
1965
  const { width: p, height: v } = s;
1965
1966
  if (i && !i() || t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
@@ -1973,7 +1974,7 @@ async function un(e, t, n, r, s, i) {
1973
1974
  h.clearRect(0, 0, p, v), h.drawImage(d, 0, 0);
1974
1975
  return;
1975
1976
  }
1976
- const o = await Bn(), a = Dn(o.viseme.atlasMeta), { width: l, height: f } = Ze(o);
1977
+ const o = await On(), a = Mn(o.viseme.atlasMeta), { width: l, height: f } = et(o);
1977
1978
  (e.width !== l || e.height !== f) && (e.width = l, e.height = f);
1978
1979
  const u = [], _ = e.getContext("2d");
1979
1980
  if (_.clearRect(0, 0, l, f), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
@@ -1985,26 +1986,26 @@ async function un(e, t, n, r, s, i) {
1985
1986
  _.drawImage(t, 0, 0, l, f);
1986
1987
  return;
1987
1988
  }
1988
- const m = Fn(t, u, l, f, a);
1989
+ const m = Bn(t, u, l, f, a);
1989
1990
  _.drawImage(m, 0, 0);
1990
1991
  }
1991
- async function xt(e, t, n) {
1992
- const r = await Bn(Xe ?? void 0), s = Dn(r.viseme.atlasMeta), { width: i, height: o } = Ze(r);
1992
+ async function Ct(e, t, n) {
1993
+ const r = await On(Ze ?? void 0), s = Mn(r.viseme.atlasMeta), { width: i, height: o } = et(r);
1993
1994
  (e.width !== i || e.height !== o) && (e.width = i, e.height = o);
1994
1995
  const a = [];
1995
1996
  if (t.mouthPath) {
1996
- const u = new Set(r.viseme.cellByPath.keys()), _ = as(t.mouthPath, u) ?? (u.has(t.mouthPath) ? t.mouthPath : null);
1997
- _ && a.push(await cn(r, r.viseme, _));
1997
+ const u = new Set(r.viseme.cellByPath.keys()), _ = os(t.mouthPath, u) ?? (u.has(t.mouthPath) ? t.mouthPath : null);
1998
+ _ && a.push(await un(r, r.viseme, _));
1998
1999
  }
1999
2000
  t.expressionPath && r.expression && a.push(
2000
- await cn(r, r.expression, t.expressionPath)
2001
+ await un(r, r.expression, t.expressionPath)
2001
2002
  );
2002
2003
  const l = e.getContext("2d");
2003
2004
  if (l.clearRect(0, 0, i, o), a.length === 0) {
2004
2005
  l.drawImage(r.sil, 0, 0, i, o);
2005
2006
  return;
2006
2007
  }
2007
- const f = Fn(
2008
+ const f = Bn(
2008
2009
  r.sil,
2009
2010
  a,
2010
2011
  i,
@@ -2013,43 +2014,43 @@ async function xt(e, t, n) {
2013
2014
  );
2014
2015
  l.drawImage(f, 0, 0);
2015
2016
  }
2016
- async function Ls(e) {
2017
- await xt(e, { mouthPath: null, expressionPath: null });
2017
+ async function Us(e) {
2018
+ await Ct(e, { mouthPath: null, expressionPath: null });
2018
2019
  }
2019
- function Us(e) {
2020
+ function Ns(e) {
2020
2021
  const t = /* @__PURE__ */ new Map();
2021
2022
  for (const n of e)
2022
2023
  t.has(n.vtime) || t.set(n.vtime, n);
2023
2024
  return [...t.values()].sort((n, r) => n.vtime - r.vtime);
2024
2025
  }
2025
- function Ns(e) {
2026
- const t = Us(e), n = [];
2026
+ function Vs(e) {
2027
+ const t = Ns(e), n = [];
2027
2028
  for (let r = 0; r < t.length - 1; r++) {
2028
2029
  const s = t[r].viseme, i = t[r + 1].viseme, o = t[r].vtime, a = t[r + 1].vtime;
2029
2030
  s === i || a <= o || n.push({ from: s, to: i, fromVtime: o, toVtime: a });
2030
2031
  }
2031
2032
  return n;
2032
2033
  }
2033
- function Vs(e, t) {
2034
+ function $s(e, t) {
2034
2035
  let n = null;
2035
2036
  for (const r of e)
2036
2037
  t >= r.fromVtime && t < r.toVtime && (n = r);
2037
2038
  return n;
2038
2039
  }
2039
- function $s(e, t) {
2040
+ function Ws(e, t) {
2040
2041
  return { gapMs: Math.max(0, t - e), holdEnd: e, transStart: e };
2041
2042
  }
2042
- let On = null;
2043
- function ln(e) {
2044
- On = e;
2043
+ let Ln = null;
2044
+ function fn(e) {
2045
+ Ln = e;
2045
2046
  }
2046
- function ft() {
2047
- return On;
2047
+ function dt() {
2048
+ return Ln;
2048
2049
  }
2049
- function Ws(e) {
2050
+ function qs(e) {
2050
2051
  return `${e.from}→${e.to}@${e.fromVtime}`;
2051
2052
  }
2052
- function fn() {
2053
+ function dn() {
2053
2054
  return {
2054
2055
  rafTicksSpeaking: 0,
2055
2056
  rafTicksDeduped: 0,
@@ -2063,12 +2064,12 @@ function fn() {
2063
2064
  transitionFramesMissed: 0
2064
2065
  };
2065
2066
  }
2066
- function qs() {
2067
- let e = fn();
2067
+ function Hs() {
2068
+ let e = dn();
2068
2069
  const t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set();
2069
2070
  let s = "", i = -1, o = "";
2070
2071
  const a = () => {
2071
- e = fn(), t.clear(), n.clear(), r.clear(), s = "", i = -1, o = "";
2072
+ e = dn(), t.clear(), n.clear(), r.clear(), s = "", i = -1, o = "";
2072
2073
  }, l = (u) => {
2073
2074
  t.add(u);
2074
2075
  }, f = (u) => {
@@ -2092,7 +2093,7 @@ function qs() {
2092
2093
  e.workerStale += 1;
2093
2094
  },
2094
2095
  onTransitionSample(u, _) {
2095
- const m = Ws(u);
2096
+ const m = qs(u);
2096
2097
  e.transitionFramesSampled += 1, m !== s && (s = m, i = -1, o !== m && (o = m, e.rifeFramesOmittedByGap += u.omittedByGap)), _ && n.add(_), i >= 0 && u.frameIdx > i + 1 && (e.transitionFramesMissed += u.frameIdx - i - 1), i = u.frameIdx;
2097
2098
  },
2098
2099
  onDrawDisplayed(u, _) {
@@ -2140,55 +2141,55 @@ function qs() {
2140
2141
  }
2141
2142
  };
2142
2143
  }
2143
- const Ln = 400, Hs = 200, Ks = 600, Un = "__sil__";
2144
- function js(e) {
2145
- return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] === Un : !1;
2144
+ const Un = 400, Ks = 200, js = 600, Nn = "__sil__";
2145
+ function Gs(e) {
2146
+ return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] === Nn : !1;
2146
2147
  }
2147
- function Gs() {
2148
+ function zs() {
2148
2149
  return { lastDrawnKey: "" };
2149
2150
  }
2150
2151
  function _e(e) {
2151
2152
  e.lastDrawnKey = "", e.transitionCache = void 0;
2152
2153
  }
2153
- function zs(e, t) {
2154
+ function Qs(e, t) {
2154
2155
  if (t?.transitionCache && t.transitionCache.queueLength === e.length)
2155
2156
  return t.transitionCache.transitions;
2156
- const n = Ns(e);
2157
+ const n = Vs(e);
2157
2158
  return t && (t.transitionCache = { queueLength: e.length, transitions: n }), n;
2158
2159
  }
2159
- function Qs(e, t) {
2160
+ function Ys(e, t) {
2160
2161
  let n = "sil";
2161
2162
  for (const r of e)
2162
2163
  r.viseme !== "sil" && (t != null && r.vtime > t || (n = r.viseme));
2163
2164
  return n;
2164
2165
  }
2165
- function Ys(e, t, n, r = 120) {
2166
+ function Js(e, t, n, r = 120) {
2166
2167
  if (n !== "sil")
2167
2168
  return n;
2168
- const s = $r(e, t, r);
2169
- return s !== "sil" ? s : Qs(e, t);
2169
+ const s = Wr(e, t, r);
2170
+ return s !== "sil" ? s : Ys(e, t);
2170
2171
  }
2171
- function Js(e, t) {
2172
- return e === "sil" ? !1 : t ? os(e, "sil", t) : Ut(e, "sil").length > 0;
2172
+ function Xs(e, t) {
2173
+ return e === "sil" ? !1 : t ? cs(e, "sil", t) : Nt(e, "sil").length > 0;
2173
2174
  }
2174
- function Xs() {
2175
- return Ln + Ks;
2175
+ function Zs() {
2176
+ return Un + js;
2176
2177
  }
2177
- function dn(e) {
2178
- return e ?? Un;
2178
+ function mn(e) {
2179
+ return e ?? Nn;
2179
2180
  }
2180
- function Zs(e, t, n, r) {
2181
+ function ei(e, t, n, r) {
2181
2182
  if (e.length === 0)
2182
2183
  return { diffPath: null, label: "sil" };
2183
- const s = zs(e, r), i = Vs(s, t);
2184
+ const s = Qs(e, r), i = $s(s, t);
2184
2185
  if (i) {
2185
- const a = i.toVtime - i.fromVtime, l = $s(i.fromVtime, i.toVtime);
2186
+ const a = i.toVtime - i.fromVtime, l = Ws(i.fromVtime, i.toVtime);
2186
2187
  if (t >= l.transStart && t < i.toVtime) {
2187
- let f = Ut(i.from, i.to);
2188
- n && (f = Mn(f, n));
2189
- const u = us(f, a);
2188
+ let f = Nt(i.from, i.to);
2189
+ n && (f = Cn(f, n));
2190
+ const u = ls(f, a);
2190
2191
  if (u.length > 0) {
2191
- const _ = ls(
2192
+ const _ = fs(
2192
2193
  t,
2193
2194
  l.transStart,
2194
2195
  i.toVtime,
@@ -2209,21 +2210,21 @@ function Zs(e, t, n, r) {
2209
2210
  }
2210
2211
  };
2211
2212
  }
2212
- return { diffPath: ut(i.to), label: i.to };
2213
+ return { diffPath: lt(i.to), label: i.to };
2213
2214
  }
2214
2215
  }
2215
2216
  const o = ht(e, t);
2216
- return o === "sil" ? { diffPath: null, label: "sil" } : { diffPath: ut(o), label: o };
2217
+ return o === "sil" ? { diffPath: null, label: "sil" } : { diffPath: lt(o), label: o };
2217
2218
  }
2218
- function Nn(e, t) {
2219
- const n = t ?? dn(e.expressionPath);
2220
- return `${dn(e.mouthPath)}|${n}`;
2219
+ function Vn(e, t) {
2220
+ const n = t ?? mn(e.expressionPath);
2221
+ return `${mn(e.mouthPath)}|${n}`;
2221
2222
  }
2222
- function ei(e, t, n, r, s, i, o, a, l, f) {
2223
- const u = Zs(t, n, l, i), _ = {
2223
+ function ti(e, t, n, r, s, i, o, a, l, f) {
2224
+ const u = ei(t, n, l, i), _ = {
2224
2225
  mouthPath: u.diffPath,
2225
2226
  expressionPath: r
2226
- }, m = Nn(_, s), p = ft();
2227
+ }, m = Vn(_, s), p = dt();
2227
2228
  if (u.transitionMeta && p?.onTransitionSample(u.transitionMeta, u.diffPath), m === i.lastDrawnKey) {
2228
2229
  p?.onDrawDeduped();
2229
2230
  return;
@@ -2232,16 +2233,16 @@ function ei(e, t, n, r, s, i, o, a, l, f) {
2232
2233
  v === m && (i.lastDrawnKey = m);
2233
2234
  });
2234
2235
  }
2235
- function mn(e, t, n, r, s, i, o = null) {
2236
- const a = { mouthPath: null, expressionPath: t }, l = o != null ? `|idle@${Math.round(o * 1e3)}` : "", f = Nn(a, n) + l;
2236
+ function hn(e, t, n, r, s, i, o = null) {
2237
+ const a = { mouthPath: null, expressionPath: t }, l = o != null ? `|idle@${Math.round(o * 1e3)}` : "", f = Vn(a, n) + l;
2237
2238
  !(o != null) && f === r.lastDrawnKey || (i(
2238
2239
  o != null ? "idle" : "sil"
2239
2240
  ), s(e, a, f, (_) => {
2240
2241
  _ === f && (r.lastDrawnKey = f);
2241
2242
  }));
2242
2243
  }
2243
- const ti = 3;
2244
- function Vn(e) {
2244
+ const ni = 3;
2245
+ function $n(e) {
2245
2246
  let t = 0;
2246
2247
  const n = [];
2247
2248
  let r = !1, s = !1;
@@ -2265,7 +2266,7 @@ function Vn(e) {
2265
2266
  return {
2266
2267
  enqueue(a, l, f) {
2267
2268
  const u = n.findIndex((_) => _.drawKey === l);
2268
- u >= 0 ? n[u] = { diffs: a, drawKey: l, onDisplayed: f } : (n.length >= ti && (n.shift(), ft()?.onQueueSuperseded()), n.push({ diffs: a, drawKey: l, onDisplayed: f })), o();
2269
+ u >= 0 ? n[u] = { diffs: a, drawKey: l, onDisplayed: f } : (n.length >= ni && (n.shift(), dt()?.onQueueSuperseded()), n.push({ diffs: a, drawKey: l, onDisplayed: f })), o();
2269
2270
  },
2270
2271
  reset() {
2271
2272
  t += 1, n.length = 0;
@@ -2278,9 +2279,9 @@ function Vn(e) {
2278
2279
  }
2279
2280
  };
2280
2281
  }
2281
- const hn = -1, wn = /* @__PURE__ */ new Map();
2282
- async function ni(e) {
2283
- let t = wn.get(e);
2282
+ const wn = -1, gn = /* @__PURE__ */ new Map();
2283
+ async function ri(e) {
2284
+ let t = gn.get(e);
2284
2285
  if (!t) {
2285
2286
  const n = await fetch(e);
2286
2287
  if (!n.ok)
@@ -2288,21 +2289,21 @@ async function ni(e) {
2288
2289
  `Failed to fetch worker script (${n.status}): ${e}`
2289
2290
  );
2290
2291
  const r = await n.blob();
2291
- t = URL.createObjectURL(r), wn.set(e, t);
2292
+ t = URL.createObjectURL(r), gn.set(e, t);
2292
2293
  }
2293
2294
  return new Worker(t, { name: "visemeDiffPreview" });
2294
2295
  }
2295
- function ri() {
2296
+ function si() {
2296
2297
  return typeof Worker < "u" && typeof OffscreenCanvas < "u";
2297
2298
  }
2298
- function si(e, t) {
2299
+ function ii(e, t) {
2299
2300
  (e.width !== t.width || e.height !== t.height) && (e.width = t.width, e.height = t.height);
2300
2301
  const n = e.getContext("2d");
2301
2302
  n && n.drawImage(t, 0, 0);
2302
2303
  }
2303
- function gn(e, t) {
2304
+ function pn(e, t) {
2304
2305
  let n = 0, r = null;
2305
- const s = Vn(async (i, o) => (await Mt(), await xt(e, i), s.isLatestSeq(o)));
2306
+ const s = $n(async (i, o) => (await Mt(), await Ct(e, i), s.isLatestSeq(o)));
2306
2307
  return {
2307
2308
  usesWorker: !1,
2308
2309
  async loadAssets(i) {
@@ -2313,7 +2314,7 @@ function gn(e, t) {
2313
2314
  return r;
2314
2315
  },
2315
2316
  async renderSilOnly() {
2316
- n += 1, s.reset(), await Ls(e);
2317
+ n += 1, s.reset(), await Us(e);
2317
2318
  },
2318
2319
  drawLiveFrame(i, o, a, l) {
2319
2320
  s.enqueue(o, a, l);
@@ -2321,8 +2322,8 @@ function gn(e, t) {
2321
2322
  async renderViseme(i, o) {
2322
2323
  n += 1;
2323
2324
  const a = n;
2324
- t.onStatus?.(o), await xt(i, {
2325
- mouthPath: ut(o),
2325
+ t.onStatus?.(o), await Ct(i, {
2326
+ mouthPath: lt(o),
2326
2327
  expressionPath: null
2327
2328
  });
2328
2329
  },
@@ -2331,9 +2332,9 @@ function gn(e, t) {
2331
2332
  }
2332
2333
  };
2333
2334
  }
2334
- function ii(e, t, n) {
2335
+ function ai(e, t, n) {
2335
2336
  let r = null, s = 1, i = 0, o = !1, a = !1, l = null;
2336
- const f = /* @__PURE__ */ new Map(), u = Vn(async (y, h, E) => (f.set(h, {
2337
+ const f = /* @__PURE__ */ new Map(), u = $n(async (y, h, E) => (f.set(h, {
2337
2338
  drawKey: E.drawKey,
2338
2339
  onDisplayed: E.onDisplayed
2339
2340
  }), await v(
@@ -2346,7 +2347,7 @@ function ii(e, t, n) {
2346
2347
  void 0,
2347
2348
  !0
2348
2349
  ), !1)), _ = (y) => {
2349
- if (y === hn) {
2350
+ if (y === wn) {
2350
2351
  let b = -1, V;
2351
2352
  for (const [Q, N] of f)
2352
2353
  Q >= b && (b = Q, V = N);
@@ -2369,7 +2370,7 @@ function ii(e, t, n) {
2369
2370
  }), p({ ...y, requestId: b });
2370
2371
  });
2371
2372
  }, d = (async () => {
2372
- r = await ni(n), r.onmessage = (y) => {
2373
+ r = await ri(n), r.onmessage = (y) => {
2373
2374
  if (a) return;
2374
2375
  const h = y.data;
2375
2376
  if (h.type === "status") {
@@ -2382,18 +2383,18 @@ function ii(e, t, n) {
2382
2383
  h.bitmap.close();
2383
2384
  return;
2384
2385
  }
2385
- if (b && !(h.generation === hn)) {
2386
+ if (b && !(h.generation === wn)) {
2386
2387
  const Q = -h.generation;
2387
2388
  if (!u.isLatestSeq(Q)) {
2388
- ft()?.onWorkerStale(), h.bitmap.close();
2389
+ dt()?.onWorkerStale(), h.bitmap.close();
2389
2390
  return;
2390
2391
  }
2391
2392
  }
2392
2393
  if (b && t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame()) {
2393
- ft()?.onWorkerStale(), h.bitmap.close();
2394
+ dt()?.onWorkerStale(), h.bitmap.close();
2394
2395
  return;
2395
2396
  }
2396
- si(e, h.bitmap), h.bitmap.close(), b && _(h.generation);
2397
+ ii(e, h.bitmap), h.bitmap.close(), b && _(h.generation);
2397
2398
  return;
2398
2399
  }
2399
2400
  const E = m.get(h.requestId);
@@ -2435,7 +2436,7 @@ function ii(e, t, n) {
2435
2436
  return await v({
2436
2437
  type: "loadAssets",
2437
2438
  keyHex: y,
2438
- urls: yr(Pe())
2439
+ urls: Sr(Pe())
2439
2440
  }) ?? { width: 842, height: 1264 };
2440
2441
  },
2441
2442
  getVisemeAtlasPaths() {
@@ -2489,17 +2490,17 @@ function ii(e, t, n) {
2489
2490
  }
2490
2491
  };
2491
2492
  }
2492
- function ai(e, t = {}) {
2493
- if (!ri())
2494
- return gn(e, t);
2495
- const n = nr(t.workerScriptUrl);
2493
+ function oi(e, t = {}) {
2494
+ if (!si())
2495
+ return pn(e, t);
2496
+ const n = rr(t.workerScriptUrl);
2496
2497
  try {
2497
- return ii(e, t, n);
2498
+ return ai(e, t, n);
2498
2499
  } catch {
2499
- return gn(e, t);
2500
+ return pn(e, t);
2500
2501
  }
2501
2502
  }
2502
- class oi extends Error {
2503
+ class ci extends Error {
2503
2504
  constructor(t, n) {
2504
2505
  super(`${t} timed out after ${Math.round(n / 1e3)}s`), this.name = "LoadTimeoutError";
2505
2506
  }
@@ -2507,7 +2508,7 @@ class oi extends Error {
2507
2508
  function bt(e, t, n) {
2508
2509
  return new Promise((r, s) => {
2509
2510
  const i = globalThis.setTimeout(() => {
2510
- s(new oi(n, t));
2511
+ s(new ci(n, t));
2511
2512
  }, t);
2512
2513
  e.then(
2513
2514
  (o) => {
@@ -2519,15 +2520,15 @@ function bt(e, t, n) {
2519
2520
  );
2520
2521
  });
2521
2522
  }
2522
- const ci = {
2523
+ const ui = {
2523
2524
  position: "relative",
2524
2525
  display: "inline-block",
2525
2526
  lineHeight: 0
2526
- }, ui = {
2527
+ }, li = {
2527
2528
  display: "block",
2528
2529
  maxWidth: "100%",
2529
2530
  height: "auto"
2530
- }, li = {
2531
+ }, fi = {
2531
2532
  position: "absolute",
2532
2533
  inset: 0,
2533
2534
  display: "flex",
@@ -2539,13 +2540,13 @@ const ci = {
2539
2540
  fontSize: "0.875rem",
2540
2541
  textAlign: "center"
2541
2542
  };
2542
- function Ye(e) {
2543
- return ir(e) ? Tn : bn;
2543
+ function Je(e) {
2544
+ return ar(e) ? An : Tn;
2544
2545
  }
2545
2546
  function Te(e, t) {
2546
2547
  return t?.isSpeaking() ? t : e.isSpeaking() ? e : t?.isConnected() ? t : e;
2547
2548
  }
2548
- const Si = Kn(function({
2549
+ const ki = jn(function({
2549
2550
  id: t,
2550
2551
  avatarId: n,
2551
2552
  faceId: r,
@@ -2568,54 +2569,54 @@ const Si = Kn(function({
2568
2569
  onRealtimeLipsyncDebug: V,
2569
2570
  onFrameRenderStats: Q
2570
2571
  }, N) {
2571
- const G = P(null), X = P(null), S = P(Gs()), A = P(Is()), M = P(0), I = P(0), g = P(0), D = P(null), L = P(null), F = P(!1), T = P(!1), $ = P(!1), z = P("sil"), Z = P(0), re = P(!1), O = P(
2572
+ const G = P(null), Z = P(null), S = P(zs()), A = P(Rs()), M = P(0), I = P(0), g = P(0), D = P(null), L = P(null), F = P(!1), T = P(!1), $ = P(!1), z = P("sil"), ee = P(0), se = P(!1), O = P(
2572
2573
  null
2573
- ), K = P(!1), [le, fe] = ze("idle"), [ie, ge] = ze(null), [ee, Fe] = ze(!1), [ye, Ve] = ze(!1), [tt, Wt] = ze({ width: 842, height: 1264 }), Se = P(i ?? null), Ae = o?.trim() || et, $e = P(null), ce = P(null), c = P(!1), k = P({ width: 842, height: 1264 }), C = P(null), j = P("sil"), te = P(void 0), ke = P(/* @__PURE__ */ new Map()), se = P(y), Y = P(v), pe = P(d), nt = P(E), We = P(b), ve = P(V), qe = P(Q), Ie = P(qs());
2574
- se.current = y, Y.current = v, pe.current = d, nt.current = E, We.current = b, ve.current = V, qe.current = Q, Me(() => {
2574
+ ), K = P(!1), [ae, de] = Qe("idle"), [X, ge] = Qe(null), [te, Fe] = Qe(!1), [ye, $e] = Qe(!1), [nt, qt] = Qe({ width: 842, height: 1264 }), Se = P(i ?? null), Ae = o?.trim() || tt, We = P(null), ue = P(null), c = P(!1), k = P({ width: 842, height: 1264 }), x = P(null), j = P("sil"), ne = P(void 0), ke = P(/* @__PURE__ */ new Map()), ie = P(y), Y = P(v), pe = P(d), rt = P(E), qe = P(b), ve = P(V), He = P(Q), Ie = P(Hs());
2575
+ ie.current = y, Y.current = v, pe.current = d, rt.current = E, qe.current = b, ve.current = V, He.current = Q, Me(() => {
2575
2576
  const w = Ie.current;
2576
- return ln(w), () => ln(null);
2577
+ return fn(w), () => fn(null);
2577
2578
  }, []);
2578
- const rt = he(
2579
+ const st = he(
2579
2580
  (w) => {
2580
- const R = w?.ttsEngineId ?? a ?? ce.current?.ttsEngineId ?? Le, B = w?.voiceId ?? l ?? ce.current?.voiceId ?? Ye(R);
2581
+ const R = w?.ttsEngineId ?? a ?? ue.current?.ttsEngineId ?? Le, B = w?.voiceId ?? l ?? ue.current?.voiceId ?? Je(R);
2581
2582
  return { ttsEngineId: R, voiceId: B };
2582
2583
  },
2583
2584
  [a, l]
2584
- ), ae = he((w) => {
2585
+ ), oe = he((w) => {
2585
2586
  ge(w), pe.current?.(w);
2586
2587
  }, []), Ee = he(
2587
2588
  (w) => {
2588
- fe(w), p?.(w);
2589
+ de(w), p?.(w);
2589
2590
  },
2590
2591
  [p]
2591
2592
  ), q = P(
2592
- Zt(Ee, Ae)
2593
- ), x = P(null);
2594
- Me(() => (q.current = Zt(
2593
+ en(Ee, Ae)
2594
+ ), C = P(null);
2595
+ Me(() => (q.current = en(
2595
2596
  Ee,
2596
2597
  Ae
2597
2598
  ), i && q.current.setDeveloperToken(i), q.current.setTtsEngineId(a), () => {
2598
2599
  q.current.stop();
2599
- const w = x.current;
2600
- w && (w.disconnect(), x.current = null);
2600
+ const w = C.current;
2601
+ w && (w.disconnect(), C.current = null);
2601
2602
  }), [Ee, i, a, Ae]);
2602
- const de = he(() => (x.current || (x.current = Yr(
2603
+ const fe = he(() => (C.current || (C.current = Jr(
2603
2604
  Ee,
2604
2605
  {
2605
2606
  speakingRate: f,
2606
- onUserTranscript: (w, R) => nt.current?.(w, R),
2607
- onBotOutput: (w) => We.current?.(w),
2607
+ onUserTranscript: (w, R) => rt.current?.(w, R),
2608
+ onBotOutput: (w) => qe.current?.(w),
2608
2609
  onLipsyncDebug: (w) => ve.current?.(w)
2609
2610
  }
2610
- ), x.current.setTtsEngineId(a)), x.current), [Ee, f, a]), J = he(() => {
2611
+ ), C.current.setTtsEngineId(a)), C.current), [Ee, f, a]), J = he(() => {
2611
2612
  D.current != null && (clearTimeout(D.current), D.current = null);
2612
- }, []), ue = he(() => {
2613
+ }, []), le = he(() => {
2613
2614
  L.current != null && (clearTimeout(L.current), L.current = null), $.current = !1;
2614
- }, []), He = he(() => {
2615
- !K.current || !O.current || (ue(), $.current = !0, L.current = setTimeout(() => {
2615
+ }, []), Ke = he(() => {
2616
+ !K.current || !O.current || (le(), $.current = !0, L.current = setTimeout(() => {
2616
2617
  if (L.current = null, Te(
2617
2618
  q.current,
2618
- x.current
2619
+ C.current
2619
2620
  ).isSpeaking()) {
2620
2621
  $.current = !1;
2621
2622
  return;
@@ -2642,25 +2643,25 @@ const Si = Kn(function({
2642
2643
  return;
2643
2644
  }
2644
2645
  setTimeout(W, 300);
2645
- }, Hs));
2646
- }, [ue]), Re = he(() => {
2646
+ }, Ks));
2647
+ }, [le]), Re = he(() => {
2647
2648
  if (J(), Y.current?.("sil"), F.current = !1, !K.current || !O.current) {
2648
2649
  $.current = !1;
2649
2650
  return;
2650
2651
  }
2651
- He();
2652
- }, [J, He]), pt = he(
2652
+ Ke();
2653
+ }, [J, Ke]), pt = he(
2653
2654
  async (w) => {
2654
- const R = I.current, B = X.current, W = G.current, U = () => {
2655
+ const R = I.current, B = Z.current, W = G.current, U = () => {
2655
2656
  w?.fallbackOnly || (F.current = !1);
2656
2657
  };
2657
- if (!B || !W || !ee) {
2658
+ if (!B || !W || !te) {
2658
2659
  U();
2659
2660
  return;
2660
2661
  }
2661
2662
  if (Te(
2662
2663
  q.current,
2663
- x.current
2664
+ C.current
2664
2665
  ).isSpeaking()) {
2665
2666
  U();
2666
2667
  return;
@@ -2668,31 +2669,31 @@ const Si = Kn(function({
2668
2669
  if (w?.fallbackOnly) {
2669
2670
  if (!F.current || (_e(S.current), await B.renderSilOnly(), R !== I.current) || Te(
2670
2671
  q.current,
2671
- x.current
2672
+ C.current
2672
2673
  ).isSpeaking())
2673
2674
  return;
2674
2675
  Re();
2675
2676
  return;
2676
2677
  }
2677
- if (js(S.current)) {
2678
+ if (Gs(S.current)) {
2678
2679
  _e(S.current), Re();
2679
2680
  return;
2680
2681
  }
2681
- const oe = Ys(
2682
+ const ce = Js(
2682
2683
  Te(
2683
2684
  q.current,
2684
- x.current
2685
+ C.current
2685
2686
  ).getVisemeQueue(),
2686
- Z.current,
2687
+ ee.current,
2687
2688
  z.current
2688
- ), we = Js(
2689
- oe,
2690
- C.current
2689
+ ), we = Xs(
2690
+ ce,
2691
+ x.current
2691
2692
  );
2692
2693
  if (_e(S.current), !we) {
2693
2694
  if (await B.renderSilOnly(), R !== I.current || Te(
2694
2695
  q.current,
2695
- x.current
2696
+ C.current
2696
2697
  ).isSpeaking())
2697
2698
  return;
2698
2699
  Re();
@@ -2700,8 +2701,8 @@ const Si = Kn(function({
2700
2701
  }
2701
2702
  try {
2702
2703
  await B.renderViseme(W, "sil", {
2703
- from: oe,
2704
- transitionDurationMs: Ln
2704
+ from: ce,
2705
+ transitionDurationMs: Un
2705
2706
  });
2706
2707
  } catch (be) {
2707
2708
  if (be?.name !== "AbortError")
@@ -2713,15 +2714,15 @@ const Si = Kn(function({
2713
2714
  }
2714
2715
  if (Te(
2715
2716
  q.current,
2716
- x.current
2717
+ C.current
2717
2718
  ).isSpeaking()) {
2718
2719
  U();
2719
2720
  return;
2720
2721
  }
2721
2722
  Re();
2722
2723
  },
2723
- [ee, Re]
2724
- ), Ke = he(() => {
2724
+ [te, Re]
2725
+ ), je = he(() => {
2725
2726
  if (T.current || F.current) return;
2726
2727
  T.current = !0, F.current = !0, J();
2727
2728
  const w = I.current;
@@ -2729,15 +2730,15 @@ const Si = Kn(function({
2729
2730
  T.current = !1;
2730
2731
  }), D.current = setTimeout(() => {
2731
2732
  D.current = null, w === I.current && pt({ fallbackOnly: !0 });
2732
- }, Xs());
2733
- }, [J, pt]), qt = he(async () => {
2733
+ }, Zs());
2734
+ }, [J, pt]), Ht = he(async () => {
2734
2735
  const w = Math.floor(Date.now() / 1e3);
2735
- if ($e.current && w < $e.current.expiresAt - 60)
2736
- return $e.current.key;
2736
+ if (We.current && w < We.current.expiresAt - 60)
2737
+ return We.current.key;
2737
2738
  const R = Se.current ?? await kt();
2738
2739
  Se.current = R, q.current.setDeveloperToken(R);
2739
- const B = await mr(R, Ae);
2740
- return $e.current = {
2740
+ const B = await hr(R, Ae);
2741
+ return We.current = {
2741
2742
  key: B.value,
2742
2743
  expiresAt: B.expiresAt
2743
2744
  }, B.value;
@@ -2745,77 +2746,77 @@ const Si = Kn(function({
2745
2746
  Me(() => {
2746
2747
  i && (Se.current = i, q.current.setDeveloperToken(i));
2747
2748
  }, [i]), Me(() => {
2748
- q.current.setTtsEngineId(a), x.current?.setTtsEngineId(a), ce.current && (ce.current.ttsEngineId = a);
2749
+ q.current.setTtsEngineId(a), C.current?.setTtsEngineId(a), ue.current && (ue.current.ttsEngineId = a);
2749
2750
  }, [a]), Me(() => {
2750
- const w = l ?? Ye(a);
2751
- ce.current && (ce.current.voiceId = w);
2751
+ const w = l ?? Je(a);
2752
+ ue.current && (ue.current.voiceId = w);
2752
2753
  }, [l, a]);
2753
- const De = zt(
2754
- () => pr(n, r),
2754
+ const De = Qt(
2755
+ () => _r(n, r),
2755
2756
  [n, r]
2756
- ), $n = zt(() => s ? JSON.stringify(s) : De ? `face:${De}` : `id:${t ?? ""}`, [s, De, t]);
2757
+ ), Wn = Qt(() => s ? JSON.stringify(s) : De ? `face:${De}` : `id:${t ?? ""}`, [s, De, t]);
2757
2758
  return Me(() => {
2758
2759
  if (!t && !s && !De) {
2759
- ae("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
2760
+ oe("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
2760
2761
  return;
2761
2762
  }
2762
2763
  let w = !1;
2763
- c.current = !1, Fe(!1), Ve(!1), ge(null), ce.current = null, O.current = null, K.current = !1;
2764
+ c.current = !1, Fe(!1), $e(!1), ge(null), ue.current = null, O.current = null, K.current = !1;
2764
2765
  const R = G.current;
2765
2766
  if (!R) return;
2766
2767
  let B = null;
2767
2768
  return (async () => {
2768
2769
  try {
2769
- let W, U, oe, we;
2770
+ let W, U, ce, we;
2770
2771
  if (s)
2771
- W = s, U = a, oe = l ?? Ye(U);
2772
+ W = s, U = a, ce = l ?? Je(U);
2772
2773
  else if (De)
2773
- Y.current?.("loadFace"), W = Yt(De), U = a, oe = l ?? Ye(U);
2774
+ Y.current?.("loadFace"), W = Jt(De), U = a, ce = l ?? Je(U);
2774
2775
  else {
2775
2776
  Y.current?.("getAiTwin");
2776
2777
  const H = await bt(
2777
- or(t),
2778
+ cr(t),
2778
2779
  3e4,
2779
2780
  "getAiTwin"
2780
2781
  );
2781
2782
  if (w) return;
2782
2783
  if (!H.faceId?.trim())
2783
2784
  throw new Error("getAiTwin returned no faceId");
2784
- U = H.ttsEngineId, oe = l ?? H.voiceId ?? Ye(U), we = H.knowledgeContextId?.trim() || void 0, W = Yt(H.faceId);
2785
+ U = H.ttsEngineId, ce = l ?? H.voiceId ?? Je(U), we = H.knowledgeContextId?.trim() || void 0, W = Jt(H.faceId);
2785
2786
  }
2786
- ce.current = { ttsEngineId: U, voiceId: oe, personaId: we }, _r(W), O.current = Rs(), B = ai(R, {
2787
+ ue.current = { ttsEngineId: U, voiceId: ce, personaId: we }, yr(W), O.current = Ds(), B = oi(R, {
2787
2788
  onStatus: (H) => {
2788
2789
  w || Y.current?.(H);
2789
2790
  },
2790
2791
  onError: (H) => {
2791
- w || ae(H);
2792
+ w || oe(H);
2792
2793
  },
2793
2794
  shouldAcceptLiveFrame: () => Te(
2794
2795
  q.current,
2795
- x.current
2796
+ C.current
2796
2797
  ).isSpeaking() && !F.current
2797
- }), X.current = B, Y.current?.("auth");
2798
+ }), Z.current = B, Y.current?.("auth");
2798
2799
  const be = Se.current ?? i ?? await bt(kt(), 3e4, "getAuthToken");
2799
2800
  if (w) return;
2800
2801
  Se.current = be, q.current.setDeveloperToken(be), q.current.setTtsEngineId(U);
2801
- const je = dt() ? await qt() : void 0;
2802
+ const Ge = mt() ? await Ht() : void 0;
2802
2803
  if (w) return;
2803
2804
  Y.current?.("loadAssets");
2804
- const ne = await bt(
2805
- B.loadAssets(je),
2805
+ const re = await bt(
2806
+ B.loadAssets(Ge),
2806
2807
  18e4,
2807
2808
  "load face assets"
2808
2809
  );
2809
- if (!w && ne.width > 0 && ne.height > 0 && (k.current = ne, Wt(ne)), w) return;
2810
- C.current = B.getVisemeAtlasPaths(), c.current = !0, Fe(!0), se.current?.(), B.renderSilOnly().then(() => {
2810
+ if (!w && re.width > 0 && re.height > 0 && (k.current = re, qt(re)), w) return;
2811
+ x.current = B.getVisemeAtlasPaths(), c.current = !0, Fe(!0), ie.current?.(), B.renderSilOnly().then(() => {
2811
2812
  w || Y.current?.("sil");
2812
2813
  }), (async () => {
2813
2814
  try {
2814
- const H = await ss(je);
2815
+ const H = await is(Ge);
2815
2816
  if (await O.current.load(H), w) return;
2816
- K.current = !0, Ve(!0), _e(S.current), O.current.setActive(!0);
2817
+ K.current = !0, $e(!0), _e(S.current), O.current.setActive(!0);
2817
2818
  const me = O.current.getVideo();
2818
- await un(
2819
+ await ln(
2819
2820
  R,
2820
2821
  me,
2821
2822
  null,
@@ -2824,85 +2825,85 @@ const Si = Kn(function({
2824
2825
  ), w || Y.current?.("idle");
2825
2826
  } catch (H) {
2826
2827
  if (w) return;
2827
- K.current = !1, Ve(!1), console.warn("[AiTwin] Idle video unavailable:", H);
2828
+ K.current = !1, $e(!1), console.warn("[AiTwin] Idle video unavailable:", H);
2828
2829
  }
2829
2830
  })();
2830
2831
  } catch (W) {
2831
2832
  if (w) return;
2832
2833
  if (W instanceof Tt) {
2833
- ae(W.message);
2834
+ oe(W.message);
2834
2835
  return;
2835
2836
  }
2836
- ae(W instanceof Error ? W.message : "Failed to load AI twin");
2837
+ oe(W instanceof Error ? W.message : "Failed to load AI twin");
2837
2838
  }
2838
2839
  })(), () => {
2839
- w = !0, O.current?.dispose(), B?.dispose(), X.current = null;
2840
+ w = !0, O.current?.dispose(), B?.dispose(), Z.current = null;
2840
2841
  };
2841
- }, [$n, s, De, t, a, l, i, qt, ae]), Me(() => {
2842
+ }, [Wn, s, De, t, a, l, i, Ht, oe]), Me(() => {
2842
2843
  const w = { current: !1 }, R = () => {
2843
- const B = G.current, W = X.current, U = Te(
2844
+ const B = G.current, W = Z.current, U = Te(
2844
2845
  q.current,
2845
- x.current
2846
+ C.current
2846
2847
  );
2847
- if (!B || !W || !ee) {
2848
+ if (!B || !W || !te) {
2848
2849
  M.current = requestAnimationFrame(R);
2849
2850
  return;
2850
2851
  }
2851
- const oe = U.isSpeaking(), we = oe && !re.current, be = re.current && !oe;
2852
- we && (J(), ue(), F.current = !1, T.current = !1, _e(S.current), Ie.current.reset(), te.current = void 0, g.current = 0, z.current = "sil", Z.current = 0, O.current?.setActive(!1)), be && (A.current.reset(), O.current?.setActive(!1), Ke());
2853
- const je = be || F.current || $.current;
2854
- if (oe) {
2852
+ const ce = U.isSpeaking(), we = ce && !se.current, be = se.current && !ce;
2853
+ we && (J(), le(), F.current = !1, T.current = !1, _e(S.current), Ie.current.reset(), ne.current = void 0, g.current = 0, z.current = "sil", ee.current = 0, O.current?.setActive(!1)), be && (A.current.reset(), O.current?.setActive(!1), je());
2854
+ const Ge = be || F.current || $.current;
2855
+ if (ce) {
2855
2856
  K.current && O.current?.setActive(!1);
2856
- const ne = U.getVisemeQueue(), H = U.getPlaybackElapsedMs();
2857
- Z.current = H;
2858
- const me = ne.length > 0 ? ht(ne, H) : "sil";
2857
+ const re = U.getVisemeQueue(), H = U.getPlaybackElapsedMs();
2858
+ ee.current = H;
2859
+ const me = re.length > 0 ? ht(re, H) : "sil";
2859
2860
  me !== "sil" && (z.current = me);
2860
- const Be = Cs(
2861
+ const Be = Ps(
2861
2862
  H,
2862
2863
  U.getSentenceEmotions(),
2863
2864
  U.getWordQueue(),
2864
2865
  U.getStreamMood()
2865
2866
  );
2866
2867
  A.current.setTargetEmotion(Be), A.current.setTargetEyebrow(
2867
- As(
2868
+ Is(
2868
2869
  H,
2869
2870
  U.getWordQueue(),
2870
- Vt(Be)
2871
+ $t(Be)
2871
2872
  )
2872
2873
  ), A.current.advance(performance.now());
2873
2874
  const _t = A.current.getExpressionPath(), yt = A.current.getDrawKey();
2874
- ei(
2875
+ ti(
2875
2876
  B,
2876
- ne,
2877
+ re,
2877
2878
  H,
2878
2879
  _t,
2879
2880
  yt,
2880
2881
  S.current,
2881
- (Ge, Ht, Kt, Wn) => {
2882
- const jt = {
2882
+ (ze, Kt, jt, qn) => {
2883
+ const Gt = {
2883
2884
  label: j.current,
2884
2885
  elapsedMs: H,
2885
- mouthPath: Ht.mouthPath,
2886
- transitionMeta: te.current
2886
+ mouthPath: Kt.mouthPath,
2887
+ transitionMeta: ne.current
2887
2888
  };
2888
- ke.current.set(Kt, jt), W.drawLiveFrame(Ge, Ht, Kt, (St) => {
2889
- const qn = ke.current.get(St) ?? jt;
2889
+ ke.current.set(jt, Gt), W.drawLiveFrame(ze, Kt, jt, (St) => {
2890
+ const Hn = ke.current.get(St) ?? Gt;
2890
2891
  ke.current.delete(St), Ie.current.onDrawDisplayed(
2891
- qn,
2892
- ne
2893
- ), Wn?.(St);
2892
+ Hn,
2893
+ re
2894
+ ), qn?.(St);
2894
2895
  });
2895
2896
  },
2896
- (Ge) => {
2897
- j.current = Ge.label, te.current = Ge.transitionMeta, Y.current?.(Ge.label);
2897
+ (ze) => {
2898
+ j.current = ze.label, ne.current = ze.transitionMeta, Y.current?.(ze.label);
2898
2899
  },
2899
- C.current
2900
- ), Ie.current.onRafTickSpeaking(), qe.current?.(
2901
- Ie.current.snapshot(ne, H)
2900
+ x.current
2901
+ ), Ie.current.onRafTickSpeaking(), He.current?.(
2902
+ Ie.current.snapshot(re, H)
2902
2903
  );
2903
- } else if (!je && K.current && O.current) {
2904
- const ne = O.current, H = ne.getVideo();
2905
- H.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? (ne.setActive(!0), w.current || (w.current = !0, un(
2904
+ } else if (!Ge && K.current && O.current) {
2905
+ const re = O.current, H = re.getVideo();
2906
+ H.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? (re.setActive(!0), w.current || (w.current = !0, ln(
2906
2907
  B,
2907
2908
  H,
2908
2909
  null,
@@ -2911,7 +2912,7 @@ const Si = Kn(function({
2911
2912
  () => !U.isSpeaking() && !F.current && !$.current
2912
2913
  ).then(() => Y.current?.("idle")).finally(() => {
2913
2914
  w.current = !1;
2914
- }))) : mn(
2915
+ }))) : hn(
2915
2916
  B,
2916
2917
  null,
2917
2918
  "__sil__",
@@ -2919,54 +2920,54 @@ const Si = Kn(function({
2919
2920
  (me, Be, _t, yt) => W.drawLiveFrame(me, Be, _t, yt),
2920
2921
  (me) => Y.current?.(me)
2921
2922
  );
2922
- } else je || mn(
2923
+ } else Ge || hn(
2923
2924
  B,
2924
2925
  null,
2925
2926
  "__sil__",
2926
2927
  S.current,
2927
- (ne, H, me, Be) => W.drawLiveFrame(ne, H, me, Be),
2928
- (ne) => Y.current?.(ne)
2928
+ (re, H, me, Be) => W.drawLiveFrame(re, H, me, Be),
2929
+ (re) => Y.current?.(re)
2929
2930
  );
2930
- re.current = oe, M.current = requestAnimationFrame(R);
2931
+ se.current = ce, M.current = requestAnimationFrame(R);
2931
2932
  };
2932
2933
  return M.current = requestAnimationFrame(R), () => {
2933
- cancelAnimationFrame(M.current), J(), ue(), q.current.stop(), x.current?.stop();
2934
+ cancelAnimationFrame(M.current), J(), le(), q.current.stop(), C.current?.stop();
2934
2935
  };
2935
2936
  }, [
2936
- ee,
2937
+ te,
2937
2938
  ye,
2938
- Ke,
2939
+ je,
2939
2940
  J,
2940
- ue
2941
- ]), jn(
2941
+ le
2942
+ ]), Gn(
2942
2943
  N,
2943
2944
  () => ({
2944
2945
  speakText: async (w, R) => {
2945
2946
  const B = w.trim();
2946
2947
  if (!B) return;
2947
- const W = X.current;
2948
- if (!W || !c.current && !ee)
2948
+ const W = Z.current;
2949
+ if (!W || !c.current && !te)
2949
2950
  throw new Error("AI twin is not ready");
2950
- const { ttsEngineId: U, voiceId: oe } = rt(R);
2951
- ge(null), I.current += 1, J(), ue(), F.current = !1, T.current = !1, z.current = "sil", Z.current = 0, _e(S.current), A.current.reset(), re.current = !1;
2951
+ const { ttsEngineId: U, voiceId: ce } = st(R);
2952
+ ge(null), I.current += 1, J(), le(), F.current = !1, T.current = !1, z.current = "sil", ee.current = 0, _e(S.current), A.current.reset(), se.current = !1;
2952
2953
  try {
2953
2954
  K.current ? (O.current?.setActive(!1), O.current?.restart(), _e(S.current)) : await W.renderSilOnly(), await q.current.speak(B, {
2954
- voiceId: oe,
2955
+ voiceId: ce,
2955
2956
  speakingRate: R?.speakingRate ?? f,
2956
2957
  ttsEngineId: U
2957
2958
  });
2958
2959
  } catch (we) {
2959
- throw ae(we instanceof Error ? we.message : "TTS failed"), we;
2960
+ throw oe(we instanceof Error ? we.message : "TTS failed"), we;
2960
2961
  }
2961
2962
  },
2962
2963
  stop: () => {
2963
- I.current += 1, J(), ue(), F.current = !1, T.current = !1, q.current.stop(), x.current?.stop(), _e(S.current), re.current = !1, Ke();
2964
+ I.current += 1, J(), le(), F.current = !1, T.current = !1, q.current.stop(), C.current?.stop(), _e(S.current), se.current = !1, je();
2964
2965
  },
2965
2966
  setTtsEngineId: (w) => {
2966
- q.current.setTtsEngineId(w), x.current?.setTtsEngineId(w), ce.current && (ce.current.ttsEngineId = w);
2967
+ q.current.setTtsEngineId(w), C.current?.setTtsEngineId(w), ue.current && (ue.current.ttsEngineId = w);
2967
2968
  },
2968
2969
  renderViseme: async (w, R) => {
2969
- const B = X.current, W = G.current;
2970
+ const B = Z.current, W = G.current;
2970
2971
  if (!B || !W || !c.current)
2971
2972
  throw new Error("AI twin is not ready");
2972
2973
  await B.renderViseme(W, w, {
@@ -2977,13 +2978,13 @@ const Si = Kn(function({
2977
2978
  });
2978
2979
  },
2979
2980
  isReady: () => c.current,
2980
- getStatus: () => le,
2981
+ getStatus: () => ae,
2981
2982
  connect: async (w = {}) => {
2982
2983
  ge(null);
2983
2984
  try {
2984
2985
  let R = w.authToken?.trim();
2985
2986
  R || (R = Se.current ?? i ?? await kt(), Se.current = R);
2986
- const B = w.voiceId?.trim() ?? l ?? ce.current?.voiceId, W = w.personaId?.trim() ?? ce.current?.personaId, U = de();
2987
+ const B = w.voiceId?.trim() ?? l ?? ue.current?.voiceId, W = w.personaId?.trim() ?? ue.current?.personaId, U = fe();
2987
2988
  await U.unlockAudio(), await U.connect({
2988
2989
  ...w,
2989
2990
  apiBase: w.apiBase?.trim() || Ae,
@@ -2993,91 +2994,91 @@ const Si = Kn(function({
2993
2994
  speakingRate: w.speakingRate ?? f
2994
2995
  });
2995
2996
  } catch (R) {
2996
- throw ae(
2997
+ throw oe(
2997
2998
  R instanceof Error ? R.message : "Voice connect failed"
2998
2999
  ), R;
2999
3000
  }
3000
3001
  },
3001
3002
  disconnect: async () => {
3002
- const w = x.current;
3003
- w && (I.current += 1, J(), ue(), F.current = !1, T.current = !1, _e(S.current), re.current = !1, await w.disconnect(), Ke());
3003
+ const w = C.current;
3004
+ w && (I.current += 1, J(), le(), F.current = !1, T.current = !1, _e(S.current), se.current = !1, await w.disconnect(), je());
3004
3005
  },
3005
- isConnected: () => x.current?.isConnected() ?? !1,
3006
- getVoiceStream: () => x.current?.getVoiceStream() ?? q.current?.getVoiceStream() ?? null
3006
+ isConnected: () => C.current?.isConnected() ?? !1,
3007
+ getVoiceStream: () => C.current?.getVoiceStream() ?? q.current?.getVoiceStream() ?? null
3007
3008
  }),
3008
3009
  [
3009
- ee,
3010
+ te,
3010
3011
  f,
3011
3012
  i,
3012
3013
  l,
3013
3014
  J,
3014
- ue,
3015
- Ke,
3016
- ae,
3017
- rt,
3018
- de,
3019
- le
3015
+ le,
3016
+ je,
3017
+ oe,
3018
+ st,
3019
+ fe,
3020
+ ae
3020
3021
  ]
3021
- ), /* @__PURE__ */ Hn("div", { className: u, style: { ...ci, ..._ }, children: [
3022
- /* @__PURE__ */ Gt(
3022
+ ), /* @__PURE__ */ Kn("div", { className: u, style: { ...ui, ..._ }, children: [
3023
+ /* @__PURE__ */ zt(
3023
3024
  "canvas",
3024
3025
  {
3025
3026
  ref: G,
3026
- width: tt.width,
3027
- height: tt.height,
3028
- style: { ...ui, ...m },
3027
+ width: nt.width,
3028
+ height: nt.height,
3029
+ style: { ...li, ...m },
3029
3030
  "aria-label": t ? `AI twin ${t}` : "AI twin face"
3030
3031
  }
3031
3032
  ),
3032
- h && ie ? /* @__PURE__ */ Gt("div", { style: li, children: ie }) : null
3033
+ h && X ? /* @__PURE__ */ zt("div", { style: fi, children: X }) : null
3033
3034
  ] });
3034
- }), fi = "thumbnail.webp";
3035
- function ki(e, t = Ct) {
3035
+ }), di = "thumbnail.webp";
3036
+ function vi(e, t = xt) {
3036
3037
  const n = e.trim();
3037
3038
  if (!n)
3038
3039
  throw new Error("faceId is required");
3039
- return `${t.replace(/\/$/, "")}/${n}/${fi}`;
3040
+ return `${t.replace(/\/$/, "")}/${n}/${di}`;
3040
3041
  }
3041
- const di = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]);
3042
- function mi(e = ".png") {
3042
+ const mi = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]);
3043
+ function hi(e = ".png") {
3043
3044
  const t = e.toLowerCase();
3044
- return di.has(t) ? `source${t}` : "source.png";
3045
+ return mi.has(t) ? `source${t}` : "source.png";
3045
3046
  }
3046
- function vi(e, t = Ct, n = ".png") {
3047
+ function Ei(e, t = xt, n = ".png") {
3047
3048
  const r = e.trim();
3048
3049
  if (!r)
3049
3050
  throw new Error("faceId is required");
3050
- return `${t.replace(/\/$/, "")}/${r}/${mi(n)}`;
3051
+ return `${t.replace(/\/$/, "")}/${r}/${hi(n)}`;
3051
3052
  }
3052
3053
  export {
3053
- fi as AI_TWIN_THUMBNAIL_FILENAME,
3054
- Si as AiTwin,
3054
+ di as AI_TWIN_THUMBNAIL_FILENAME,
3055
+ ki as AiTwin,
3055
3056
  Tt as AiTwinNotFoundError,
3056
3057
  Le as DEFAULT_TTS_ENGINE_ID,
3057
- An as MIC_SAMPLE_RATE,
3058
- Tr as OCULUS_VISEME_IDS,
3059
- In as PLAYBACK_SAMPLE_RATE,
3060
- Ot as SPEAKING_RATE_MAX,
3061
- Bt as SPEAKING_RATE_MIN,
3062
- Ue as TTS_ENGINE_CARTESIA,
3063
- _n as TTS_ENGINE_GOOGLE,
3058
+ In as MIC_SAMPLE_RATE,
3059
+ Ar as OCULUS_VISEME_IDS,
3060
+ Rn as PLAYBACK_SAMPLE_RATE,
3061
+ Lt as SPEAKING_RATE_MAX,
3062
+ Ot as SPEAKING_RATE_MIN,
3063
+ Ne as TTS_ENGINE_CARTESIA,
3064
+ yn as TTS_ENGINE_GOOGLE,
3064
3065
  Pt as TTS_ENGINE_INWORLD,
3065
- yi as VISEME_IDS,
3066
- Tn as VISEME_TEST_CARTESIA_VOICE_ID,
3066
+ Si as VISEME_IDS,
3067
+ An as VISEME_TEST_CARTESIA_VOICE_ID,
3067
3068
  wt as VISEME_TEST_SPEAKING_RATE,
3068
- bn as VISEME_TEST_VOICE_ID,
3069
- mi as aiTwinSourceFilename,
3070
- Gr as buildVoiceWebSocketUrl,
3071
- Zt as createAvatarTtsLipsyncController,
3072
- Yr as createRealtimeVoiceLipsyncController,
3073
- Yt as faceAssetUrls,
3074
- or as fetchAiTwin,
3069
+ Tn as VISEME_TEST_VOICE_ID,
3070
+ hi as aiTwinSourceFilename,
3071
+ zr as buildVoiceWebSocketUrl,
3072
+ en as createAvatarTtsLipsyncController,
3073
+ Jr as createRealtimeVoiceLipsyncController,
3074
+ Jt as faceAssetUrls,
3075
+ cr as fetchAiTwin,
3075
3076
  kt as fetchDevAuthToken,
3076
- vi as getAiTwinSourceUrl,
3077
- ki as getAiTwinThumbnailUrl,
3078
- Ir as normalizeOculusViseme,
3079
- pr as resolveDirectFaceId,
3077
+ Ei as getAiTwinSourceUrl,
3078
+ vi as getAiTwinThumbnailUrl,
3079
+ Rr as normalizeOculusViseme,
3080
+ _r as resolveDirectFaceId,
3080
3081
  ht as resolveVisemeAtTime,
3081
- _i as resolveWordAtTime,
3082
- _r as setActiveTwinAssets
3082
+ yi as resolveWordAtTime,
3083
+ yr as setActiveTwinAssets
3083
3084
  };