@streamoji/avatar-widget 0.3.4 → 0.3.5

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.
@@ -1,38 +1,38 @@
1
1
  import { jsx as l, jsxs as ae } from "react/jsx-runtime";
2
- import { useGLTF as lt, Environment as Yt } from "@react-three/drei";
3
- import { useFrame as Qt, Canvas as Kt, useThree as Xt } from "@react-three/fiber";
4
- import { memo as Zt, useMemo as ft, useRef as a, useState as g, useEffect as H, useCallback as Ke, useLayoutEffect as en, Suspense as tn } from "react";
2
+ import { useGLTF as lt, Environment as Kt } from "@react-three/drei";
3
+ import { useFrame as Xt, Canvas as Zt, useThree as en } from "@react-three/fiber";
4
+ import { memo as tn, useMemo as ft, useRef as a, useState as b, useEffect as H, useCallback as Ke, useLayoutEffect as nn, Suspense as rn } from "react";
5
5
  import * as He from "three";
6
- import { GLTFLoader as nn } from "three/examples/jsm/loaders/GLTFLoader.js";
7
- const ut = "https://ai.streamoji.com", $ = (...f) => {
8
- }, rn = (...f) => {
9
- }, Et = ({ analyser: f }) => {
10
- const L = a(null), b = a(null);
6
+ import { GLTFLoader as sn } from "three/examples/jsm/loaders/GLTFLoader.js";
7
+ const ut = "https://ai.streamoji.com", $ = (...d) => {
8
+ }, on = (...d) => {
9
+ }, Et = ({ analyser: d }) => {
10
+ const L = a(null), _ = a(null);
11
11
  return H(() => {
12
12
  const p = L.current;
13
13
  if (!p) return;
14
- const _ = p.getContext("2d", { alpha: !0 });
15
- if (!_) return;
14
+ const w = p.getContext("2d", { alpha: !0 });
15
+ if (!w) return;
16
16
  let D, j = null;
17
- f && (f.fftSize = 128, j = new Uint8Array(f.frequencyBinCount));
17
+ d && (d.fftSize = 128, j = new Uint8Array(d.frequencyBinCount));
18
18
  const fe = () => {
19
19
  D = requestAnimationFrame(fe), (p.width !== p.offsetWidth || p.height !== p.offsetHeight) && (p.width = p.offsetWidth, p.height = p.offsetHeight);
20
20
  const K = p.width, N = p.height;
21
21
  if (K === 0 || N === 0) return;
22
22
  const he = N / 2;
23
- _.clearRect(0, 0, K, N), _.fillStyle = "#1e293b";
24
- const E = 2, S = E + 2, R = K * 0.95, U = Math.floor(R / S);
25
- (!b.current || b.current.length !== U) && (b.current = new Float32Array(U).fill(2));
26
- const me = U * S, y = (K - me) / 2;
27
- f && j && f.getByteFrequencyData(j);
23
+ w.clearRect(0, 0, K, N), w.fillStyle = "#1e293b";
24
+ const E = 2, x = E + 2, R = K * 0.95, U = Math.floor(R / x);
25
+ (!_.current || _.current.length !== U) && (_.current = new Float32Array(U).fill(2));
26
+ const me = U * x, S = (K - me) / 2;
27
+ d && j && d.getByteFrequencyData(j);
28
28
  const Ie = j ? j.length : 0, Y = Math.floor(Ie * 0.7) / U, be = new Float32Array(U);
29
29
  for (let B = 0; B < U; B++) {
30
30
  let J = 0;
31
31
  if (j && Y > 0) {
32
32
  const P = Math.floor(B * Y), _e = Math.floor((B + 1) * Y);
33
33
  for (let M = P; M < _e; M++) {
34
- const x = j[M] || 0;
35
- x > J && (J = x);
34
+ const k = j[M] || 0;
35
+ k > J && (J = k);
36
36
  }
37
37
  }
38
38
  J < 10 && (J = 0);
@@ -40,61 +40,61 @@ const ut = "https://ai.streamoji.com", $ = (...f) => {
40
40
  be[B] = I;
41
41
  }
42
42
  for (let B = 0; B < U; B++) {
43
- const J = U - 1 - B, z = Math.max(be[B], be[J]), I = b.current[B] + (z - b.current[B]) * 0.3;
44
- b.current[B] = I;
45
- const P = y + B * S, _e = he - I / 2;
46
- _.beginPath(), _.roundRect ? _.roundRect(P, _e, E, I, 4) : _.fillRect(P, _e, E, I), _.fill();
43
+ const J = U - 1 - B, z = Math.max(be[B], be[J]), I = _.current[B] + (z - _.current[B]) * 0.3;
44
+ _.current[B] = I;
45
+ const P = S + B * x, _e = he - I / 2;
46
+ w.beginPath(), w.roundRect ? w.roundRect(P, _e, E, I, 4) : w.fillRect(P, _e, E, I), w.fill();
47
47
  }
48
48
  };
49
49
  return fe(), () => {
50
50
  cancelAnimationFrame(D);
51
51
  };
52
- }, [f]), /* @__PURE__ */ l(
52
+ }, [d]), /* @__PURE__ */ l(
53
53
  "canvas",
54
54
  {
55
55
  ref: L,
56
56
  style: { width: "100%", height: "100%", display: "block" }
57
57
  }
58
58
  );
59
- }, sn = "https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev", It = "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/avatar-blue-suit.glb";
60
- async function on(f) {
59
+ }, an = "https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev", It = "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/avatar-blue-suit.glb";
60
+ async function cn(d) {
61
61
  const L = await crypto.subtle.digest(
62
62
  "SHA-256",
63
- new TextEncoder().encode(f)
63
+ new TextEncoder().encode(d)
64
64
  );
65
- return Array.from(new Uint8Array(L)).map((b) => b.toString(16).padStart(2, "0")).join("");
65
+ return Array.from(new Uint8Array(L)).map((_) => _.toString(16).padStart(2, "0")).join("");
66
66
  }
67
- function an(f) {
68
- const [L, b] = g(null);
67
+ function ln(d) {
68
+ const [L, _] = b(null);
69
69
  return H(() => {
70
- if (!f) {
71
- b(null);
70
+ if (!d) {
71
+ _(null);
72
72
  return;
73
73
  }
74
74
  let p = !1;
75
- return on(f).then((_) => {
75
+ return cn(d).then((w) => {
76
76
  if (p) return;
77
- const D = `${sn}/${_}.glb`;
77
+ const D = `${an}/${w}.glb`;
78
78
  fetch(D, { method: "HEAD" }).then((j) => {
79
- p || b(j.ok ? D : It);
79
+ p || _(j.ok ? D : It);
80
80
  }).catch(() => {
81
- p || b(It);
81
+ p || _(It);
82
82
  });
83
83
  }), () => {
84
84
  p = !0;
85
85
  };
86
- }, [f]), L;
86
+ }, [d]), L;
87
87
  }
88
- const cn = [
88
+ const un = [
89
89
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_001.glb",
90
90
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_002.glb",
91
91
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_002.glb",
92
92
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_005.glb"
93
- ], ln = [
93
+ ], dn = [
94
94
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_001.glb",
95
95
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_003.glb",
96
96
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_003.glb"
97
- ], un = [
97
+ ], fn = [
98
98
  {
99
99
  id: "m_expr_01",
100
100
  name: "Friendly Wave",
@@ -260,23 +260,23 @@ const cn = [
260
260
  name: "Take It Easy",
261
261
  url: "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_006.glb"
262
262
  }
263
- ], dn = [
263
+ ], hn = [
264
264
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_005.glb",
265
265
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_007.glb",
266
266
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_006.glb"
267
- ], fn = [
268
- "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_005.glb",
269
- "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_007.glb",
270
- "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_006.glb",
267
+ ], mn = [
268
+ "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_004.glb",
269
+ "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_005.glb",
270
+ "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_006.glb",
271
271
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_002.glb"
272
- ], hn = {
272
+ ], pn = {
273
273
  zoom: 0.85,
274
274
  position: [0.15, -0.8, 0],
275
275
  scale: 1.5,
276
276
  rotation: [0.15, 0.02, 0]
277
- }, mn = [-0.45, 1.9, 0.1], pn = {
277
+ }, gn = [-0.45, 1.9, 0.1], bn = {
278
278
  browInnerUp: 0.2
279
- }, dt = 0.18, gn = 1, Mt = "__branding__", Xe = {
279
+ }, dt = 0.18, _n = 1, Mt = "__branding__", Xe = {
280
280
  neutral: { eyeLookDownLeft: 0.1, eyeLookDownRight: 0.1 },
281
281
  happy: {
282
282
  mouthSmileLeft: 0.2,
@@ -358,7 +358,7 @@ const cn = [
358
358
  mouthUpperUpLeft: 0.1,
359
359
  mouthUpperUpRight: 0.1
360
360
  }
361
- }, bn = [
361
+ }, wn = [
362
362
  { key: "viseme_aa", mix: { jawOpen: 0.6 } },
363
363
  {
364
364
  key: "viseme_E",
@@ -454,7 +454,7 @@ const cn = [
454
454
  }
455
455
  },
456
456
  { key: "viseme_sil", mix: {} }
457
- ], _n = {
457
+ ], vn = {
458
458
  aei: [
459
459
  { v: "E", w: 0.8 },
460
460
  { v: "I", w: 0.2 }
@@ -483,39 +483,39 @@ const cn = [
483
483
  ],
484
484
  sil: [{ v: "sil", w: 1 }]
485
485
  };
486
- function wn(f) {
487
- if (!f) return [{ v: "sil", w: 1 }];
488
- const L = f.toLowerCase();
489
- return _n[L] ?? [{ v: "sil", w: 1 }];
486
+ function yn(d) {
487
+ if (!d) return [{ v: "sil", w: 1 }];
488
+ const L = d.toLowerCase();
489
+ return vn[L] ?? [{ v: "sil", w: 1 }];
490
490
  }
491
- function vn({ target: f }) {
492
- const { camera: L } = Xt();
491
+ function Sn({ target: d }) {
492
+ const { camera: L } = en();
493
493
  return H(() => {
494
- L.lookAt(...f);
495
- }, [L, f]), null;
494
+ L.lookAt(...d);
495
+ }, [L, d]), null;
496
496
  }
497
- function Q(f, L, b) {
498
- if (!f || !f.morphTargetDictionary)
497
+ function Q(d, L, _) {
498
+ if (!d || !d.morphTargetDictionary)
499
499
  return;
500
- const p = f, _ = p.morphTargetDictionary, D = p.morphTargetInfluences;
500
+ const p = d, w = p.morphTargetDictionary, D = p.morphTargetInfluences;
501
501
  if (D)
502
- for (const j in _)
503
- j.toLowerCase() === L.toLowerCase() && (D[_[j]] = b);
502
+ for (const j in w)
503
+ j.toLowerCase() === L.toLowerCase() && (D[w[j]] = _);
504
504
  }
505
- function Ct(f, L = 0.97) {
506
- if (!f) return;
507
- const b = f;
508
- if (b.morphTargetInfluences)
509
- for (let p = 0; p < b.morphTargetInfluences.length; p++)
510
- b.morphTargetInfluences[p] *= L;
505
+ function Ct(d, L = 0.97) {
506
+ if (!d) return;
507
+ const _ = d;
508
+ if (_.morphTargetInfluences)
509
+ for (let p = 0; p < _.morphTargetInfluences.length; p++)
510
+ _.morphTargetInfluences[p] *= L;
511
511
  }
512
- const yn = Zt(
512
+ const xn = tn(
513
513
  ({
514
- avatarUrl: f,
514
+ avatarUrl: d,
515
515
  isPlayingRef: L,
516
- visemeQueueRef: b,
516
+ visemeQueueRef: _,
517
517
  audioContextRef: p,
518
- responseAudioStartTimeRef: _,
518
+ responseAudioStartTimeRef: w,
519
519
  adjustments: D,
520
520
  mood: j,
521
521
  expression: fe,
@@ -523,51 +523,51 @@ const yn = Zt(
523
523
  isSpeaking: N,
524
524
  nextStartTimeRef: he,
525
525
  stopPlayback: E,
526
- setIsSpeaking: v,
527
- expressionUrl: S,
526
+ setIsSpeaking: y,
527
+ expressionUrl: x,
528
528
  onExpressionFinished: R,
529
529
  isNudgeResponse: U,
530
530
  avatarGender: me
531
531
  }) => {
532
- const { scene: y } = lt(f), Ue = lt(me === "female" ? ln : cn), Y = ft(
533
- () => Ue.flatMap((d) => d.animations),
532
+ const { scene: S } = lt(d), Ue = lt(me === "female" ? dn : un), Y = ft(
533
+ () => Ue.flatMap((f) => f.animations),
534
534
  [Ue]
535
- ), B = lt(me === "female" ? fn : dn), J = ft(
536
- () => B.flatMap((d) => d.animations),
535
+ ), B = lt(me === "female" ? mn : hn), J = ft(
536
+ () => B.flatMap((f) => f.animations),
537
537
  [B]
538
- ), z = a(null), I = a(null), P = a(null), _e = a([]), [M] = g(() => new He.AnimationMixer(y)), x = a({}), C = a(null), we = a(0), Me = a(!1), ve = a(0), ce = a(null);
538
+ ), z = a(null), I = a(null), P = a(null), _e = a([]), [M] = b(() => new He.AnimationMixer(S)), k = a({}), C = a(null), we = a(0), Me = a(!1), ve = a(0), ce = a(null);
539
539
  H(() => {
540
- if (!(!Y || !y)) {
541
- if (Y.forEach((d, u) => {
540
+ if (!(!Y || !S)) {
541
+ if (Y.forEach((f, u) => {
542
542
  const i = `idle_${u}`;
543
- if (!x.current[i]) {
544
- const s = M.clipAction(d, y);
545
- s.name = i, s.setLoop(He.LoopOnce, 1), s.clampWhenFinished = !0, x.current[i] = s;
543
+ if (!k.current[i]) {
544
+ const s = M.clipAction(f, S);
545
+ s.name = i, s.setLoop(He.LoopOnce, 1), s.clampWhenFinished = !0, k.current[i] = s;
546
546
  }
547
- }), J.forEach((d, u) => {
547
+ }), J.forEach((f, u) => {
548
548
  const i = `talk_${u}`;
549
- if (!x.current[i]) {
550
- const s = M.clipAction(d, y);
551
- s.name = i, s.setLoop(He.LoopOnce, 1), s.clampWhenFinished = !0, x.current[i] = s;
549
+ if (!k.current[i]) {
550
+ const s = M.clipAction(f, S);
551
+ s.name = i, s.setLoop(He.LoopOnce, 1), s.clampWhenFinished = !0, k.current[i] = s;
552
552
  }
553
553
  }), Y.length > 0) {
554
- const d = x.current.idle_0, u = C.current && M.existingAction(C.current.getClip());
555
- d && !u && (d.reset().fadeIn(0.5).play(), C.current = d);
554
+ const f = k.current.idle_0, u = C.current && M.existingAction(C.current.getClip());
555
+ f && !u && (f.reset().fadeIn(0.5).play(), C.current = f);
556
556
  }
557
557
  return () => {
558
- M.stopAllAction(), x.current = {}, C.current = null;
558
+ M.stopAllAction(), k.current = {}, C.current = null;
559
559
  };
560
560
  }
561
- }, [Y, J, y, M]);
561
+ }, [Y, J, S, M]);
562
562
  const ye = a("");
563
563
  H(() => {
564
- if (!S || !y || S === ye.current) return;
565
- ye.current = S, ce.current = S, new nn().load(
566
- S,
564
+ if (!x || !S || x === ye.current) return;
565
+ ye.current = x, ce.current = x, new sn().load(
566
+ x,
567
567
  (u) => {
568
568
  if (u.animations && u.animations.length > 0) {
569
- const i = u.animations[0], s = M.clipAction(i, y);
570
- if (s.name = `EXPR_${S}`, s.setLoop(He.LoopOnce, 1), s.clampWhenFinished = !0, x.current[`EXPR_${S}`] = s, N && ce.current === S) {
569
+ const i = u.animations[0], s = M.clipAction(i, S);
570
+ if (s.name = `EXPR_${x}`, s.setLoop(He.LoopOnce, 1), s.clampWhenFinished = !0, k.current[`EXPR_${x}`] = s, N && ce.current === x) {
571
571
  const h = C.current;
572
572
  s.reset().fadeIn(0.3).play(), h && h !== s && h.crossFadeTo(s, 0.3, !0), C.current = s, ce.current = null;
573
573
  }
@@ -575,36 +575,36 @@ const yn = Zt(
575
575
  },
576
576
  void 0,
577
577
  (u) => {
578
- console.error(`[ANIMATION] Failed to load ${S}`, u);
578
+ console.error(`[ANIMATION] Failed to load ${x}`, u);
579
579
  }
580
580
  );
581
- }, [S, y, M, N]), H(() => {
582
- const d = (u) => {
581
+ }, [x, S, M, N]), H(() => {
582
+ const f = (u) => {
583
583
  const i = u.action, s = i.name || "";
584
584
  if (s.startsWith("idle_")) {
585
- const W = (parseInt(s.split("_")[1]) + 1) % Y.length, X = x.current[`idle_${W}`];
585
+ const W = (parseInt(s.split("_")[1]) + 1) % Y.length, X = k.current[`idle_${W}`];
586
586
  X && (X.reset().fadeIn(0.5).play(), i.crossFadeTo(X, 0.5, !0), C.current = X);
587
587
  } else if (s.startsWith("EXPR_")) {
588
588
  if (N) {
589
589
  const h = Math.floor(
590
590
  Math.random() * J.length
591
- ), W = x.current[`talk_${h}`];
591
+ ), W = k.current[`talk_${h}`];
592
592
  W && (W.reset().fadeIn(0.5).play(), i.crossFadeTo(W, 0.5, !0), C.current = W);
593
593
  } else {
594
- const h = x.current.idle_0;
594
+ const h = k.current.idle_0;
595
595
  h && (h.reset().fadeIn(0.5).play(), i.crossFadeTo(h, 0.5, !0), C.current = h);
596
596
  }
597
597
  R && R();
598
598
  } else if (s.startsWith("talk_"))
599
599
  if (N && !U) {
600
- const W = (parseInt(s.split("_")[1]) + 1) % J.length, X = x.current[`talk_${W}`];
600
+ const W = (parseInt(s.split("_")[1]) + 1) % J.length, X = k.current[`talk_${W}`];
601
601
  X && (X.reset().fadeIn(0.3).play(), i.crossFadeTo(X, 0.3, !0), C.current = X);
602
602
  } else {
603
- const h = x.current.idle_0;
603
+ const h = k.current.idle_0;
604
604
  h && (h.reset().fadeIn(0.5).play(), i.crossFadeTo(h, 0.5, !0), C.current = h);
605
605
  }
606
606
  };
607
- return M.addEventListener("finished", d), () => M.removeEventListener("finished", d);
607
+ return M.addEventListener("finished", f), () => M.removeEventListener("finished", f);
608
608
  }, [
609
609
  M,
610
610
  Y,
@@ -613,71 +613,71 @@ const yn = Zt(
613
613
  U,
614
614
  R
615
615
  ]), H(() => {
616
- if (N && y) {
617
- const d = C.current, u = d?.name || "";
616
+ if (N && S) {
617
+ const f = C.current, u = f?.name || "";
618
618
  if (u.startsWith("idle_") || u.startsWith("talk_") || u === "") {
619
619
  const i = ce.current;
620
620
  if (i) {
621
- const s = x.current[`EXPR_${i}`];
621
+ const s = k.current[`EXPR_${i}`];
622
622
  if (s) {
623
- s.reset().fadeIn(0.3).play(), d && d !== s && d.crossFadeTo(s, 0.3, !0), C.current = s, ce.current = null;
623
+ s.reset().fadeIn(0.3).play(), f && f !== s && f.crossFadeTo(s, 0.3, !0), C.current = s, ce.current = null;
624
624
  return;
625
625
  }
626
626
  }
627
627
  if (u.startsWith("idle_") || u === "") {
628
628
  const s = Math.floor(
629
629
  Math.random() * J.length
630
- ), h = x.current[`talk_${s}`];
631
- h && (h.reset().fadeIn(0.5).play(), d && d.crossFadeTo(h, 0.5, !0), C.current = h);
630
+ ), h = k.current[`talk_${s}`];
631
+ h && (h.reset().fadeIn(0.5).play(), f && f.crossFadeTo(h, 0.5, !0), C.current = h);
632
632
  }
633
633
  }
634
- } else if (!N && y) {
635
- const d = C.current, u = d?.name || "";
634
+ } else if (!N && S) {
635
+ const f = C.current, u = f?.name || "";
636
636
  if (u.startsWith("talk_") || u.startsWith("EXPR_")) {
637
- const i = x.current.idle_0;
638
- i && (i.reset().fadeIn(0.5).play(), d && d.crossFadeTo(i, 0.5, !0), C.current = i);
637
+ const i = k.current.idle_0;
638
+ i && (i.reset().fadeIn(0.5).play(), f && f.crossFadeTo(i, 0.5, !0), C.current = i);
639
639
  }
640
640
  }
641
- }, [N, y, S]), H(() => {
642
- if (!y) return;
643
- y.traverse((i) => {
641
+ }, [N, S, x]), H(() => {
642
+ if (!S) return;
643
+ S.traverse((i) => {
644
644
  if (i.isMesh && i.morphTargetDictionary) {
645
645
  const s = i.name.toLowerCase();
646
646
  (s.includes("head") || s.includes("avatar")) && (I.current = i, $(`[ANIMATION] Found head mesh: ${i.name}`)), s.includes("teeth") && (P.current = i, $(`[ANIMATION] Found teeth mesh: ${i.name}`));
647
647
  }
648
648
  });
649
- const d = I.current?.morphTargetDictionary;
650
- d && Object.keys(d).filter(
649
+ const f = I.current?.morphTargetDictionary;
650
+ f && Object.keys(f).filter(
651
651
  (i) => i.toLowerCase().includes("brow")
652
652
  );
653
653
  const u = [];
654
- y.traverse((i) => {
654
+ S.traverse((i) => {
655
655
  if (i.isMesh) {
656
656
  const h = i.morphTargetDictionary;
657
657
  h && Object.keys(h).some((W) => W.toLowerCase().includes("brow")) && u.push(i);
658
658
  }
659
659
  }), _e.current = u, u.length > 0 && $("[ANIMATION] Meshes with brow morphs:", u.length);
660
- }, [y]);
661
- const Be = (d, u = 1) => {
662
- const i = `viseme_${d}`.toLowerCase(), s = bn.find((h) => h.key.toLowerCase() === i);
660
+ }, [S]);
661
+ const Be = (f, u = 1) => {
662
+ const i = `viseme_${f}`.toLowerCase(), s = wn.find((h) => h.key.toLowerCase() === i);
663
663
  if (s)
664
664
  for (const h in s.mix) {
665
665
  const W = s.mix[h] * u;
666
666
  Q(I.current, h, W), Q(P.current, h, W);
667
667
  }
668
- }, ke = (d) => {
669
- const u = Xe[d] ?? Xe.neutral;
668
+ }, ke = (f) => {
669
+ const u = Xe[f] ?? Xe.neutral;
670
670
  for (const i in u)
671
671
  Q(I.current, i, u[i]), Q(P.current, i, u[i]);
672
672
  };
673
- return Qt((d, u) => {
673
+ return Xt((f, u) => {
674
674
  const i = Math.pow(0.88, 60 * u);
675
675
  Ct(I.current, i), Ct(P.current, i), ke(j);
676
- const s = d.clock.elapsedTime;
676
+ const s = f.clock.elapsedTime;
677
677
  let h = 0;
678
678
  if (Math.floor(s) % 5 === 0 && Math.floor((s - u) % 5) !== 0) {
679
679
  let q = null;
680
- y.traverse((Z) => {
680
+ S.traverse((Z) => {
681
681
  Z.name.toLowerCase().includes("hips") && (q = Z);
682
682
  });
683
683
  const Se = q ? `Hips Y: ${q.position.y.toFixed(4)}` : "Hips not found";
@@ -691,10 +691,10 @@ const yn = Zt(
691
691
  we.current = s + Z;
692
692
  } else {
693
693
  const Z = Se < 0.5 ? Se * 2 : (1 - Se) * 2;
694
- Q(I.current, "eyeBlinkLeft", Z), Q(I.current, "eyeBlinkRight", Z), Q(P.current, "eyeBlinkLeft", Z), Q(P.current, "eyeBlinkRight", Z), h = Z * pn.browInnerUp;
694
+ Q(I.current, "eyeBlinkLeft", Z), Q(I.current, "eyeBlinkRight", Z), Q(P.current, "eyeBlinkLeft", Z), Q(P.current, "eyeBlinkRight", Z), h = Z * bn.browInnerUp;
695
695
  }
696
696
  }
697
- const W = Xe[j] ?? Xe.neutral, X = W.browInnerUp ?? 0, Ze = W.browOuterUpLeft ?? 0, je = W.browOuterUpRight ?? 0, Pe = s * gn, Ae = dt * Math.sin(Pe), te = dt * 0.7 * Math.sin(Pe + 0.7), Je = dt * 0.7 * Math.sin(Pe + 1.3), re = (q) => Math.max(0, Math.min(1, q)), Te = re(X + Ae), Le = re(Ze + te), We = re(je + Je), Ce = re(Te + h);
697
+ const W = Xe[j] ?? Xe.neutral, X = W.browInnerUp ?? 0, Ze = W.browOuterUpLeft ?? 0, je = W.browOuterUpRight ?? 0, Pe = s * _n, Ae = dt * Math.sin(Pe), te = dt * 0.7 * Math.sin(Pe + 0.7), Je = dt * 0.7 * Math.sin(Pe + 1.3), re = (q) => Math.max(0, Math.min(1, q)), Te = re(X + Ae), Le = re(Ze + te), We = re(je + Je), Ce = re(Te + h);
698
698
  if (Q(I.current, "browInnerUp", Ce), Q(P.current, "browInnerUp", Ce), Q(I.current, "browOuterUpLeft", Le), Q(P.current, "browOuterUpLeft", Le), Q(I.current, "browOuterUpRight", We), Q(P.current, "browOuterUpRight", We), z.current) {
699
699
  const q = L.current ? 0 : D.rotation[1];
700
700
  z.current.rotation.y = He.MathUtils.lerp(
@@ -704,44 +704,47 @@ const yn = Zt(
704
704
  ), z.current.position.set(...D.position), z.current.scale.setScalar(D.scale), z.current.rotation.x = D.rotation[0], z.current.rotation.z = D.rotation[2];
705
705
  }
706
706
  if (L.current && p.current) {
707
- const q = p.current.currentTime, Oe = (q - _.current) * 1e3 - -150;
708
- for (let ne = 0; ne < b.current.length; ne++) {
709
- const ie = b.current[ne];
707
+ const q = p.current.currentTime, Oe = (q - w.current) * 1e3 - -150;
708
+ for (let ne = 0; ne < _.current.length; ne++) {
709
+ const ie = _.current[ne];
710
710
  Oe >= ie.vtime && Oe < ie.vtime + ie.vduration && Be(ie.viseme, ie.weight ?? 1);
711
711
  }
712
- q > he.current + 0.5 && (E(), v(!1));
712
+ q > he.current + 0.5 && (E(), y(!1));
713
713
  }
714
- }), /* @__PURE__ */ l("group", { ref: z, children: /* @__PURE__ */ l("primitive", { object: y }) });
714
+ }), /* @__PURE__ */ l("group", { ref: z, children: /* @__PURE__ */ l("primitive", { object: S }) });
715
715
  }
716
716
  );
717
- function Sn(f) {
718
- return f ? f.charAt(0).toUpperCase() + f.slice(1).toLowerCase() : "";
717
+ function kn(d) {
718
+ return d ? d.charAt(0).toUpperCase() + d.slice(1).toLowerCase() : "";
719
719
  }
720
- const xn = ({
721
- token: f,
720
+ function Ot(d) {
721
+ return d.replace(/\*(.*?)\*/g, " $1 ").replace(/\[.*?\]/g, " ").replace(/<.*?\/>/g, " ").replace(/<.*?>.*?<\/.*?>/g, " ").replace(/\s+/g, " ").trim();
722
+ }
723
+ const An = ({
724
+ token: d,
722
725
  agentToken: L,
723
- onNavigationRequested: b,
726
+ onNavigationRequested: _,
724
727
  avatarGender: p,
725
- presetUserDetails: _
728
+ presetUserDetails: w
726
729
  } = {}) => {
727
- const D = f ?? L ?? "", j = an(D || void 0), [fe, K] = g(""), [N, he] = g(""), [E, v] = g("Ready"), [S, R] = g(!1), [U, me] = g(!1), [y, Ie] = g([]), [Ue, Y] = g(""), be = a(null), [B, J] = g(
730
+ const D = d ?? L ?? "", j = ln(D || void 0), [fe, K] = b(""), [N, he] = b(""), [E, y] = b("Ready"), [x, R] = b(!1), [U, me] = b(!1), [S, Ie] = b([]), [Ue, Y] = b(""), be = a(null), [B, J] = b(
728
731
  () => typeof window < "u" ? window.matchMedia("(max-width: 480px)").matches : !1
729
732
  );
730
733
  H(() => {
731
734
  const e = window.matchMedia("(max-width: 480px)"), t = () => J(e.matches);
732
735
  return e.addEventListener("change", t), () => e.removeEventListener("change", t);
733
736
  }, []);
734
- const z = B ? 80 : 600, I = a(!1), P = a([]), _e = a(0), M = a(!1), x = a([]), C = a(null), we = a([]);
737
+ const z = B ? 80 : 600, I = a(!1), P = a([]), _e = a(0), M = a(!1), k = a([]), C = a(null), we = a([]);
735
738
  a([]);
736
- const Me = a([]), ve = a(0), ce = a(0), ye = a(0), Be = a(0), ke = a(!1), [d, u] = g(
739
+ const Me = a([]), ve = a(0), ce = a(0), ye = a(0), Be = a(0), ke = a(!1), [f, u] = b(
737
740
  null
738
- ), i = a(null), [s, h] = g("neutral"), [W, X] = g(""), [Ze, je] = g(""), [Pe, Ae] = g("Chat with us"), [te, Je] = g(
741
+ ), i = a(null), [s, h] = b("neutral"), [W, X] = b(""), [Ze, je] = b(""), [Pe, Ae] = b("Chat with us"), [te, Je] = b(
739
742
  null
740
- ), [re, Te] = g("hidden"), [Le, We] = g(""), Ce = a(null), q = a(re);
743
+ ), [re, Te] = b("hidden"), [Le, We] = b(""), Ce = a(null), q = a(re);
741
744
  q.current = re;
742
- const [Se, Z] = g(null), Oe = a(null), ne = a(null), [ie, ht] = g(!1), mt = a(null), [le, qe] = g("hidden"), [pt, Ot] = g(""), et = a(le);
745
+ const [Se, Z] = b(null), Oe = a(null), ne = a(null), [ie, ht] = b(!1), mt = a(null), [le, qe] = b("hidden"), [pt, Dt] = b(""), et = a(le);
743
746
  et.current = le;
744
- const pe = a(""), De = a(!1), Ne = a(""), gt = a(Date.now()), tt = a([]), Ve = a(!1), [nt, $e] = g(!1), [bt, _t] = g(!1), xe = a(null), Fe = ft(() => ie ? "Try again" : E === "Busy" ? "Busy" : E === "Thinking..." || E === "Processing Voice..." ? E : te != null && te !== "" && te !== "none" && te !== "<none>" ? `Enter ${Sn(te)}` : le !== "hidden" || !bt ? null : Mt, [E, te, ie, le, bt]), wt = !ie && E !== "Busy" && E !== "Thinking..." && E !== "Processing Voice..." && (te == null || te === "" || te === "none" || te === "<none>");
747
+ const pe = a(""), De = a(!1), Ne = a(""), gt = a(Date.now()), tt = a([]), Ve = a(!1), [nt, $e] = b(!1), [bt, _t] = b(!1), xe = a(null), Fe = ft(() => ie ? "Try again" : E === "Busy" ? "Busy" : E === "Thinking..." || E === "Processing Voice..." ? E : te != null && te !== "" && te !== "none" && te !== "<none>" ? `Enter ${kn(te)}` : le !== "hidden" || !bt ? null : Mt, [E, te, ie, le, bt]), wt = !ie && E !== "Busy" && E !== "Thinking..." && E !== "Processing Voice..." && (te == null || te === "" || te === "none" || te === "<none>");
745
748
  H(() => {
746
749
  if (le !== "hidden" || !wt) {
747
750
  _t(!1), xe.current != null && (clearTimeout(xe.current), xe.current = null);
@@ -774,7 +777,7 @@ const xn = ({
774
777
  return;
775
778
  }
776
779
  return ne.current = setTimeout(() => {
777
- ne.current = null, v("Ready"), ht(!0);
780
+ ne.current = null, y("Ready"), ht(!0);
778
781
  }, 12e3), () => {
779
782
  ne.current != null && (clearTimeout(ne.current), ne.current = null);
780
783
  };
@@ -783,14 +786,14 @@ const xn = ({
783
786
  const e = setTimeout(() => ht(!1), 2500);
784
787
  return () => clearTimeout(e);
785
788
  }, [ie]);
786
- const Dt = Ke(() => {
789
+ const Nt = Ke(() => {
787
790
  const e = q.current;
788
791
  if (e === "exiting") {
789
792
  Te("hidden");
790
793
  const t = Ce.current;
791
794
  Ce.current = null, t != null && t !== "" && (We(t), Te("entering"));
792
795
  } else e === "entering" && Te("visible");
793
- }, []), Nt = (e) => {
796
+ }, []), Ft = (e) => {
794
797
  if (!e) return;
795
798
  if (e.mood != null) {
796
799
  const n = String(e.mood).toLowerCase();
@@ -799,7 +802,7 @@ const xn = ({
799
802
  if (e.expression != null) {
800
803
  const n = String(e.expression).trim();
801
804
  X(n);
802
- const c = un.find(
805
+ const c = fn.find(
803
806
  (m) => m.name.toLowerCase() === n.toLowerCase()
804
807
  );
805
808
  $(
@@ -808,17 +811,17 @@ const xn = ({
808
811
  }
809
812
  if (e.navigation != null) {
810
813
  const n = String(e.navigation).trim();
811
- n !== "" && (b ? b(n) : window.open(n, "_blank"));
814
+ n !== "" && (_ ? _(n) : window.open(n, "_blank"));
812
815
  }
813
816
  const t = e.ask_for || e.lead_capture?.ask_for, r = t ? String(t).trim().toLowerCase() : "", o = r === "none" || r === "<none>";
814
817
  if (t && !o) {
815
818
  const n = r;
816
- if (_ && (n === "email" && _.email || n === "name" && _.name || n === "phone" && _.phone))
819
+ if (w && (n === "email" && w.email || n === "name" && w.name || n === "phone" && w.phone))
817
820
  return;
818
821
  Je(n || null), Ae(n === "email" ? "Enter your email" : n === "name" ? "Enter your name" : n === "phone" ? "Enter your phone number" : "Chat with us");
819
822
  } else (o || e.ask_for === null || e.lead_capture && e.lead_capture.ask_for === null || e.ask_for === "none") && (Je(null), Pe !== "Chat with us" && Ae("Chat with us"));
820
823
  e.collected, e.valid;
821
- }, Ft = (e) => {
824
+ }, Ut = (e) => {
822
825
  const t = e.trim();
823
826
  if (!t) return null;
824
827
  if (t.startsWith("{"))
@@ -832,7 +835,7 @@ const xn = ({
832
835
  return { [o]: n };
833
836
  }
834
837
  return null;
835
- }, Ut = Ke(() => {
838
+ }, Bt = Ke(() => {
836
839
  }, []), vt = (e) => {
837
840
  if (De.current)
838
841
  e === "§" ? De.current = !1 : (Ne.current += e, he((t) => t + e));
@@ -845,8 +848,8 @@ const xn = ({
845
848
  const t = pe.current.indexOf(`
846
849
  `), r = pe.current.slice(0, t).trim();
847
850
  pe.current = pe.current.slice(t + 1);
848
- const o = Ft(r);
849
- o && Nt(o);
851
+ const o = Ut(r);
852
+ o && Ft(o);
850
853
  }
851
854
  };
852
855
  H(() => {
@@ -856,22 +859,22 @@ const xn = ({
856
859
  )) {
857
860
  const n = "secret", c = Math.floor(Date.now() / 1e3).toString();
858
861
  try {
859
- const m = new TextEncoder(), w = await crypto.subtle.importKey(
862
+ const m = new TextEncoder(), g = await crypto.subtle.importKey(
860
863
  "raw",
861
864
  m.encode(n),
862
865
  { name: "HMAC", hash: "SHA-256" },
863
866
  !1,
864
867
  ["sign"]
865
- ), k = await crypto.subtle.sign(
868
+ ), v = await crypto.subtle.sign(
866
869
  "HMAC",
867
- w,
870
+ g,
868
871
  m.encode(c)
869
- ), T = Array.from(new Uint8Array(k)).map((V) => V.toString(16).padStart(2, "0")).join("");
872
+ ), T = Array.from(new Uint8Array(v)).map((V) => V.toString(16).padStart(2, "0")).join("");
870
873
  sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", T), $("[SESSION] New HMAC UID generated and saved:", T);
871
874
  } catch (m) {
872
875
  console.error("[SESSION] HMAC generation failed:", m);
873
- const w = Math.random().toString(36) + Date.now().toString();
874
- sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", w);
876
+ const g = Math.random().toString(36) + Date.now().toString();
877
+ sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", g);
875
878
  }
876
879
  }
877
880
  const r = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES");
@@ -882,7 +885,7 @@ const xn = ({
882
885
  } catch {
883
886
  o = [];
884
887
  }
885
- o.length === 0 && _ && (_.name || _.email) ? (o = [{ role: "user", content: `PRESET_USER_DETAILS: Name is "${_.name || ""}" , Email is "${_.email || ""}"` }], sessionStorage.setItem(
888
+ o.length === 0 && w && (w.name || w.email) ? (o = [{ role: "user", content: `PRESET_USER_DETAILS: Name is "${w.name || ""}" , Email is "${w.email || ""}"` }], sessionStorage.setItem(
886
889
  "STREAMOJI_LEADS_SESSION_MESSAGES",
887
890
  JSON.stringify(o)
888
891
  )) : r || sessionStorage.setItem(
@@ -890,13 +893,13 @@ const xn = ({
890
893
  JSON.stringify([])
891
894
  );
892
895
  })();
893
- }, [_]), H(() => {
896
+ }, [w]), H(() => {
894
897
  const e = () => {
895
898
  gt.current = Date.now(), Ve.current && (Ve.current = !1, $e(!1), Ie([]), Y(""), he(""), me(!1));
896
899
  };
897
900
  window.addEventListener("mousemove", e), window.addEventListener("keydown", e), window.addEventListener("mousedown", e), window.addEventListener("touchstart", e);
898
901
  const t = setInterval(async () => {
899
- if (Date.now() - gt.current >= 3e4 && !U && !S && E === "Ready" && !Ve.current)
902
+ if (Date.now() - gt.current >= 3e4 && !U && !x && E === "Ready" && !Ve.current)
900
903
  if (Ve.current = !0, tt.current.length > 0)
901
904
  $e(!0), Ie(tt.current);
902
905
  else
@@ -912,8 +915,8 @@ const xn = ({
912
915
  body: JSON.stringify(c)
913
916
  });
914
917
  if (m.ok) {
915
- const k = (await m.json()).nudge_questions;
916
- k && k.length > 0 && ($("[NUDGE] Received nudge questions from API:", k), tt.current = k, $e(!0), Ie(k));
918
+ const v = (await m.json()).nudge_questions;
919
+ v && v.length > 0 && ($("[NUDGE] Received nudge questions from API:", v), tt.current = v, $e(!0), Ie(v));
917
920
  }
918
921
  } catch (n) {
919
922
  console.error("[NUDGE] Error calling /nudgeUser:", n), Ve.current = !1;
@@ -922,11 +925,11 @@ const xn = ({
922
925
  return () => {
923
926
  window.removeEventListener("mousemove", e), window.removeEventListener("keydown", e), window.removeEventListener("mousedown", e), window.removeEventListener("touchstart", e), clearInterval(t);
924
927
  };
925
- }, [D, U, S, E]), H(() => {
926
- if (y.length === 0) return;
928
+ }, [D, U, x, E]), H(() => {
929
+ if (S.length === 0) return;
927
930
  let e = 0, t = 0, r = !1, o = 100;
928
931
  const n = () => {
929
- const c = y[e];
932
+ const c = S[e];
930
933
  if (r) {
931
934
  const m = c.substring(0, t - 1);
932
935
  Y(m), t--, o = 50;
@@ -934,12 +937,12 @@ const xn = ({
934
937
  const m = c.substring(0, t + 1);
935
938
  Y(m), t++, o = 100;
936
939
  }
937
- !r && t === c.length ? (r = !0, o = 3e3) : r && t === 0 && (r = !1, e = (e + 1) % y.length, o = 500), be.current = setTimeout(n, o);
940
+ !r && t === c.length ? (r = !0, o = 3e3) : r && t === 0 && (r = !1, e = (e + 1) % S.length, o = 500), be.current = setTimeout(n, o);
938
941
  };
939
942
  return n(), () => {
940
943
  be.current && clearTimeout(be.current);
941
944
  };
942
- }, [y]);
945
+ }, [S]);
943
946
  const yt = () => {
944
947
  try {
945
948
  return JSON.parse(
@@ -948,25 +951,25 @@ const xn = ({
948
951
  } catch {
949
952
  return [];
950
953
  }
951
- }, Bt = (e) => {
954
+ }, Pt = (e) => {
952
955
  sessionStorage.setItem(
953
956
  "STREAMOJI_LEADS_SESSION_MESSAGES",
954
957
  JSON.stringify(e)
955
958
  );
956
- }, [rt, it] = g(!1), [St, st] = g(0), ue = a(null), ze = a([]), xt = a(0), [kt, Pt] = g(
959
+ }, [rt, it] = b(!1), [St, st] = b(0), ue = a(null), ze = a([]), xt = a(0), [kt, Wt] = b(
957
960
  null
958
- ), [Wt, ot] = g(
961
+ ), [Vt, ot] = b(
959
962
  null
960
963
  ), ge = a(null), Re = a(
961
964
  null
962
965
  ), Ye = Ke((e = !1) => {
963
- e && (ke.current = !0, R(!1), v("Ready")), x.current = [], P.current = [], M.current = !1, me(!1), ve.current = 0, ce.current = 0, ye.current = 0, we.current.forEach((t) => {
966
+ e && (ke.current = !0, R(!1), y("Ready")), k.current = [], P.current = [], M.current = !1, me(!1), ve.current = 0, ce.current = 0, ye.current = 0, we.current.forEach((t) => {
964
967
  try {
965
968
  t.stop();
966
969
  } catch {
967
970
  }
968
971
  }), Oe.current && (clearTimeout(Oe.current), Oe.current = null), Z(null), je(""), we.current = [];
969
- }, []), Vt = async () => {
972
+ }, []), $t = async () => {
970
973
  try {
971
974
  const e = await navigator.mediaDevices.getUserMedia({ audio: !0 }), t = window.AudioContext || window.webkitAudioContext, r = new t(), o = r.createMediaStreamSource(e), n = r.createAnalyser();
972
975
  n.fftSize = 64, o.connect(n), ge.current = r, Re.current = o, ot(n);
@@ -976,21 +979,21 @@ const xn = ({
976
979
  }, c.onstop = async () => {
977
980
  const m = Date.now() - xt.current;
978
981
  if (ot(null), Re.current && (Re.current.disconnect(), Re.current = null), ge.current && ge.current.state !== "closed" && (ge.current.close(), ge.current = null), m < 1e3) {
979
- v("Recording too short. Hold or click longer."), R(!1);
982
+ y("Recording too short. Hold or click longer."), R(!1);
980
983
  return;
981
984
  }
982
- const w = new Blob(ze.current, {
985
+ const g = new Blob(ze.current, {
983
986
  type: "audio/wav"
984
987
  });
985
- await Jt(w);
986
- }, xt.current = Date.now(), c.start(100), it(!0), v("Listening...");
988
+ await qt(g);
989
+ }, xt.current = Date.now(), c.start(100), it(!0), y("Listening...");
987
990
  } catch (e) {
988
- console.error("Error accessing microphone:", e), v("Mic Access Error");
991
+ console.error("Error accessing microphone:", e), y("Mic Access Error");
989
992
  }
990
- }, $t = () => {
991
- ue.current && ue.current.state !== "inactive" && (ue.current.stop(), ue.current.stream.getTracks().forEach((e) => e.stop()), it(!1));
992
993
  }, Ht = () => {
993
- ue.current && ue.current.state !== "inactive" && (ue.current.onstop = null, ue.current.stop(), ue.current.stream.getTracks().forEach((e) => e.stop()), ot(null), Re.current && (Re.current.disconnect(), Re.current = null), ge.current && ge.current.state !== "closed" && (ge.current.close(), ge.current = null), it(!1), ze.current = [], v("Ready"));
994
+ ue.current && ue.current.state !== "inactive" && (ue.current.stop(), ue.current.stream.getTracks().forEach((e) => e.stop()), it(!1));
995
+ }, jt = () => {
996
+ ue.current && ue.current.state !== "inactive" && (ue.current.onstop = null, ue.current.stop(), ue.current.stream.getTracks().forEach((e) => e.stop()), ot(null), Re.current && (Re.current.disconnect(), Re.current = null), ge.current && ge.current.state !== "closed" && (ge.current.close(), ge.current = null), it(!1), ze.current = [], y("Ready"));
994
997
  };
995
998
  H(() => {
996
999
  if (!U) return;
@@ -999,13 +1002,13 @@ const xn = ({
999
1002
  if (t <= 0) return;
1000
1003
  const r = C.current, o = ve.current;
1001
1004
  if (!r) return;
1002
- const n = r.currentTime - o, c = Math.min(Math.max(0, n), t), m = N.trim().length;
1003
- if (m <= 0) return;
1004
- const w = Math.min(
1005
- Math.round(c / t * m),
1006
- m
1005
+ const n = r.currentTime - o, c = Math.min(Math.max(0, n), t), g = Ot(N).trim().length;
1006
+ if (g <= 0) return;
1007
+ const v = Math.min(
1008
+ Math.round(c / t * g),
1009
+ g
1007
1010
  );
1008
- u(w);
1011
+ u(v);
1009
1012
  };
1010
1013
  return clearInterval(i.current ?? void 0), i.current = setInterval(e, 90), () => clearInterval(i.current ?? void 0);
1011
1014
  }, [U, N, ye.current]), H(() => {
@@ -1014,21 +1017,21 @@ const xn = ({
1014
1017
  st((t) => t + 1);
1015
1018
  }, 1e3)) : st(0), () => clearInterval(e);
1016
1019
  }, [rt]);
1017
- const jt = (e) => {
1020
+ const Jt = (e) => {
1018
1021
  const t = e.numberOfChannels, r = e.length * t * 2 + 44, o = new ArrayBuffer(r), n = new DataView(o);
1019
1022
  let c = 0;
1020
1023
  const m = (T) => {
1021
1024
  n.setUint16(c, T, !0), c += 2;
1022
- }, w = (T) => {
1025
+ }, g = (T) => {
1023
1026
  n.setUint32(c, T, !0), c += 4;
1024
1027
  };
1025
- w(1179011410), w(r - 8), w(1163280727), w(544501094), w(16), m(1), m(t), w(e.sampleRate), w(e.sampleRate * 2 * t), m(t * 2), m(16), w(1635017060), w(r - c - 4);
1026
- const k = [];
1027
- for (let T = 0; T < t; T++) k.push(e.getChannelData(T));
1028
+ g(1179011410), g(r - 8), g(1163280727), g(544501094), g(16), m(1), m(t), g(e.sampleRate), g(e.sampleRate * 2 * t), m(t * 2), m(16), g(1635017060), g(r - c - 4);
1029
+ const v = [];
1030
+ for (let T = 0; T < t; T++) v.push(e.getChannelData(T));
1028
1031
  let A = 0;
1029
1032
  for (; c < r; ) {
1030
1033
  for (let T = 0; T < t; T++) {
1031
- let V = Math.max(-1, Math.min(1, k[T][A]));
1034
+ let V = Math.max(-1, Math.min(1, v[T][A]));
1032
1035
  V = V < 0 ? V * 32768 : V * 32767, n.setInt16(c, V, !0), c += 2;
1033
1036
  }
1034
1037
  A++;
@@ -1051,16 +1054,16 @@ const xn = ({
1051
1054
  const c = window.atob(e), m = new Uint8Array(c.length);
1052
1055
  for (let F = 0; F < c.length; F++)
1053
1056
  m[F] = c.charCodeAt(F);
1054
- const w = await n.decodeAudioData(m.buffer.slice(0));
1055
- ye.current += w.duration;
1056
- const k = n.currentTime;
1057
+ const g = await n.decodeAudioData(m.buffer.slice(0));
1058
+ ye.current += g.duration;
1059
+ const v = n.currentTime;
1057
1060
  let A = ce.current;
1058
1061
  const T = !M.current;
1059
- A < k && (A = k + 0.1), ce.current = A + w.duration;
1062
+ A < v && (A = v + 0.1), ce.current = A + g.duration;
1060
1063
  const V = n.createBufferSource();
1061
- V.buffer = w;
1064
+ V.buffer = g;
1062
1065
  let G = kt;
1063
- if ((!G || G.context !== n) && (G = n.createAnalyser(), G.fftSize = 64, G.connect(n.destination), Pt(G)), V.connect(G), we.current.push(V), ke.current) {
1066
+ if ((!G || G.context !== n) && (G = n.createAnalyser(), G.fftSize = 64, G.connect(n.destination), Wt(G)), V.connect(G), we.current.push(V), ke.current) {
1064
1067
  we.current = we.current.filter((F) => F !== V);
1065
1068
  return;
1066
1069
  }
@@ -1070,11 +1073,11 @@ const xn = ({
1070
1073
  3
1071
1074
  )}`
1072
1075
  ), ve.current = A;
1073
- const F = (A - k) * 1e3;
1076
+ const F = (A - v) * 1e3;
1074
1077
  _e.current = performance.now() + F, $(
1075
1078
  `[AUDIO] Response started. Initial startTime: ${A.toFixed(
1076
1079
  3
1077
- )}, CT: ${k.toFixed(3)}`
1080
+ )}, CT: ${v.toFixed(3)}`
1078
1081
  );
1079
1082
  }
1080
1083
  V.start(A);
@@ -1086,13 +1089,13 @@ const xn = ({
1086
1089
  )), t.forEach((F, se) => {
1087
1090
  const O = F.symbol ?? "";
1088
1091
  if (O) {
1089
- const oe = wn(O), de = Math.round(F.start * 1e3), Ee = Math.round((F.duration ?? 0) * 1e3), Lt = Be.current + de;
1092
+ const oe = yn(O), de = Math.round(F.start * 1e3), Ee = Math.round((F.duration ?? 0) * 1e3), Lt = Be.current + de;
1090
1093
  se < 3 && $(
1091
1094
  `[AUDIO] Viseme "${O}": segment_relative=${de}ms, segment_offset=${Be.current.toFixed(
1092
1095
  0
1093
1096
  )}ms => vtime=${Lt}ms`
1094
1097
  ), oe.forEach((Rt) => {
1095
- x.current.push({
1098
+ k.current.push({
1096
1099
  viseme: Rt.v,
1097
1100
  weight: Rt.w,
1098
1101
  vtime: Lt,
@@ -1100,7 +1103,7 @@ const xn = ({
1100
1103
  });
1101
1104
  });
1102
1105
  }
1103
- }), v("Speaking...");
1106
+ }), y("Speaking...");
1104
1107
  } finally {
1105
1108
  if (I.current = !1, P.current.length > 0) {
1106
1109
  const o = P.current.shift();
@@ -1108,16 +1111,16 @@ const xn = ({
1108
1111
  }
1109
1112
  }
1110
1113
  }
1111
- }, Jt = async (e) => {
1114
+ }, qt = async (e) => {
1112
1115
  try {
1113
- R(!0), $e(!1), Ne.current = "", he(""), v("Processing Voice...");
1114
- const t = await e.arrayBuffer(), o = await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(t), n = jt(o), c = new FileReader();
1116
+ R(!0), $e(!1), Ne.current = "", he(""), y("Processing Voice...");
1117
+ const t = await e.arrayBuffer(), o = await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(t), n = Jt(o), c = new FileReader();
1115
1118
  c.readAsDataURL(n), c.onloadend = async () => {
1116
1119
  const m = c.result.split(",")[1];
1117
1120
  Ye(), K(""), pe.current = "", De.current = !1;
1118
- const w = `${ut}/stt?token=${encodeURIComponent(
1121
+ const g = `${ut}/stt?token=${encodeURIComponent(
1119
1122
  D
1120
- )}`, k = await fetch(w, {
1123
+ )}`, v = await fetch(g, {
1121
1124
  method: "POST",
1122
1125
  headers: { "Content-Type": "application/json" },
1123
1126
  body: JSON.stringify({
@@ -1125,17 +1128,17 @@ const xn = ({
1125
1128
  audio_format: "wav"
1126
1129
  })
1127
1130
  });
1128
- if (k.status === 429) {
1131
+ if (v.status === 429) {
1129
1132
  try {
1130
- const se = await k.text(), O = JSON.parse(se);
1133
+ const se = await v.text(), O = JSON.parse(se);
1131
1134
  $("[STT] 429 agent at capacity:", O?.detail);
1132
1135
  } catch {
1133
1136
  }
1134
- K(""), v("Busy"), R(!1);
1137
+ K(""), y("Busy"), R(!1);
1135
1138
  return;
1136
1139
  }
1137
- if (!k.ok) {
1138
- const se = await k.text();
1140
+ if (!v.ok) {
1141
+ const se = await v.text();
1139
1142
  let O = "STT Failed";
1140
1143
  try {
1141
1144
  O = JSON.parse(se).error || O;
@@ -1144,9 +1147,9 @@ const xn = ({
1144
1147
  }
1145
1148
  throw new Error(O);
1146
1149
  }
1147
- const A = k.body;
1150
+ const A = v.body;
1148
1151
  if ($("this is body" + A), !A) {
1149
- v("STT Failed"), R(!1);
1152
+ y("STT Failed"), R(!1);
1150
1153
  return;
1151
1154
  }
1152
1155
  const T = A.getReader();
@@ -1169,11 +1172,11 @@ const xn = ({
1169
1172
  break;
1170
1173
  }
1171
1174
  case "done": {
1172
- ee = !0, v("Ready"), R(!1);
1175
+ ee = !0, y("Ready"), R(!1);
1173
1176
  break;
1174
1177
  }
1175
1178
  case "error": {
1176
- ee = !0, v("STT Failed"), R(!1);
1179
+ ee = !0, y("STT Failed"), R(!1);
1177
1180
  break;
1178
1181
  }
1179
1182
  default:
@@ -1196,16 +1199,16 @@ const xn = ({
1196
1199
  const de = Qe(G.trim());
1197
1200
  de && await F(de.event, de.data);
1198
1201
  }
1199
- ee || (v("Ready"), R(!1));
1202
+ ee || (y("Ready"), R(!1));
1200
1203
  break;
1201
1204
  }
1202
1205
  }
1203
1206
  };
1204
1207
  } catch (t) {
1205
- console.error("Audio Submission Error:", t), v("STT Failed"), R(!1);
1208
+ console.error("Audio Submission Error:", t), y("STT Failed"), R(!1);
1206
1209
  }
1207
- }, qt = async (e) => {
1208
- e && e.preventDefault(), $e(!1), Ne.current = "", he(""), !(!fe || S) && await Gt(fe);
1210
+ }, Gt = async (e) => {
1211
+ e && e.preventDefault(), $e(!1), Ne.current = "", he(""), !(!fe || x) && await zt(fe);
1209
1212
  }, Qe = (e) => {
1210
1213
  const t = e.split(/\r?\n/);
1211
1214
  let r = "", o = "";
@@ -1241,24 +1244,24 @@ const xn = ({
1241
1244
  { role: "user", content: fe || "..." },
1242
1245
  { role: "assistant", content: o }
1243
1246
  ];
1244
- Bt(n), Me.current = [...x.current], v("Ready"), R(!1), K("");
1247
+ Pt(n), Me.current = [...k.current], y("Ready"), R(!1), K("");
1245
1248
  break;
1246
1249
  }
1247
1250
  case "error": {
1248
1251
  const r = t.message ?? "Unknown error";
1249
- Ne.current = r, he(r), v("Agent Failed"), R(!1);
1252
+ Ne.current = r, he(r), y("Agent Failed"), R(!1);
1250
1253
  break;
1251
1254
  }
1252
1255
  }
1253
- }, Gt = async (e) => {
1254
- R(!0), v("Thinking..."), Ne.current = "", pe.current = "", De.current = !1, Ye(), ye.current = 0, u(0);
1256
+ }, zt = async (e) => {
1257
+ R(!0), y("Thinking..."), Ne.current = "", pe.current = "", De.current = !1, Ye(), ye.current = 0, u(0);
1255
1258
  const t = `${ut}/agent/chat?token=${encodeURIComponent(
1256
1259
  D
1257
1260
  )}`;
1258
1261
  try {
1259
1262
  const r = yt();
1260
1263
  let o = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID");
1261
- o || (rn(
1264
+ o || (on(
1262
1265
  "[CHAT] Session UID missing at send time! Generating emergency backup."
1263
1266
  ), o = "emergency-" + Math.random().toString(36).substring(7), sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", o));
1264
1267
  const n = {
@@ -1281,25 +1284,25 @@ const xn = ({
1281
1284
  $("[CHAT] 429 agent at capacity:", T?.detail);
1282
1285
  } catch {
1283
1286
  }
1284
- K(""), v("Busy"), R(!1);
1287
+ K(""), y("Busy"), R(!1);
1285
1288
  return;
1286
1289
  }
1287
1290
  if (!c.ok)
1288
1291
  throw new Error("Agent request failed");
1289
1292
  const m = c.body;
1290
1293
  if (!m) {
1291
- v("Agent Failed"), R(!1);
1294
+ y("Agent Failed"), R(!1);
1292
1295
  return;
1293
1296
  }
1294
- const w = m.getReader();
1297
+ const g = m.getReader();
1295
1298
  ke.current = !1;
1296
- const k = new TextDecoder();
1299
+ const v = new TextDecoder();
1297
1300
  let A = "";
1298
1301
  for (; ; ) {
1299
- const { done: T, value: V } = await w.read();
1302
+ const { done: T, value: V } = await g.read();
1300
1303
  $(
1301
1304
  `[SSE] Chunk received. done=${T}, length=${V?.length || 0}`
1302
- ), V && (A += k.decode(V, { stream: !0 }));
1305
+ ), V && (A += v.decode(V, { stream: !0 }));
1303
1306
  const G = A.split(`
1304
1307
 
1305
1308
  `);
@@ -1314,26 +1317,26 @@ const xn = ({
1314
1317
  const ee = Qe(A.trim());
1315
1318
  ee && At(ee.event, ee.data);
1316
1319
  }
1317
- v("Ready"), R(!1), K("");
1320
+ y("Ready"), R(!1), K("");
1318
1321
  break;
1319
1322
  }
1320
1323
  }
1321
1324
  } catch (r) {
1322
- console.error("Chat Error:", r), v("Agent Failed"), R(!1);
1325
+ console.error("Chat Error:", r), y("Agent Failed"), R(!1);
1323
1326
  }
1324
- }, Tt = N.trim(), ct = Tt && U ? Tt.slice(
1327
+ }, Yt = N.trim(), Tt = Ot(Yt), ct = Tt && U ? Tt.slice(
1325
1328
  0,
1326
- d != null && d > 0 ? d : 0
1329
+ f != null && f > 0 ? f : 0
1327
1330
  ) : "";
1328
1331
  H(() => {
1329
1332
  const e = et.current;
1330
- e !== "exiting" && (ct ? (Ot(ct), e === "hidden" && qe("entering")) : (e === "visible" || e === "entering") && qe("exiting"));
1333
+ e !== "exiting" && (ct ? (Dt(ct), e === "hidden" && qe("entering")) : (e === "visible" || e === "entering") && qe("exiting"));
1331
1334
  }, [ct, le]);
1332
- const zt = Ke(() => {
1335
+ const Qt = Ke(() => {
1333
1336
  const e = et.current;
1334
1337
  e === "entering" ? qe("visible") : e === "exiting" && qe("hidden");
1335
1338
  }, []);
1336
- return en(() => {
1339
+ return nn(() => {
1337
1340
  const e = mt.current;
1338
1341
  e && (e.scrollTop = e.scrollHeight);
1339
1342
  }, [pt]), /* @__PURE__ */ ae("div", { className: "avatar-widget-container", children: [
@@ -1342,7 +1345,7 @@ const xn = ({
1342
1345
  "div",
1343
1346
  {
1344
1347
  className: `avatar-thinking-tab${re === "exiting" ? " avatar-thinking-tab--exiting" : re === "entering" ? " avatar-thinking-tab--entering" : ""}`,
1345
- onAnimationEnd: Dt,
1348
+ onAnimationEnd: Nt,
1346
1349
  children: Le === Mt ? /* @__PURE__ */ l(
1347
1350
  "a",
1348
1351
  {
@@ -1369,7 +1372,7 @@ const xn = ({
1369
1372
  {
1370
1373
  type: "button",
1371
1374
  className: "avatar-recording-cancel",
1372
- onClick: Ht,
1375
+ onClick: jt,
1373
1376
  title: "Cancel",
1374
1377
  children: /* @__PURE__ */ ae(
1375
1378
  "svg",
@@ -1403,7 +1406,7 @@ const xn = ({
1403
1406
  minWidth: 0
1404
1407
  },
1405
1408
  children: [
1406
- /* @__PURE__ */ l("div", { style: { flex: 1, height: "100%" }, children: /* @__PURE__ */ l(Et, { analyser: Wt }) }),
1409
+ /* @__PURE__ */ l("div", { style: { flex: 1, height: "100%" }, children: /* @__PURE__ */ l(Et, { analyser: Vt }) }),
1407
1410
  /* @__PURE__ */ ae(
1408
1411
  "span",
1409
1412
  {
@@ -1431,7 +1434,7 @@ const xn = ({
1431
1434
  {
1432
1435
  type: "button",
1433
1436
  className: "avatar-recording-confirm",
1434
- onClick: $t,
1437
+ onClick: Ht,
1435
1438
  title: "Send",
1436
1439
  children: /* @__PURE__ */ l(
1437
1440
  "svg",
@@ -1474,7 +1477,7 @@ const xn = ({
1474
1477
  children: /* @__PURE__ */ l("span", { className: "avatar-speaking-stop__icon", "aria-hidden": !0 })
1475
1478
  }
1476
1479
  )
1477
- ] }) : S ? /* @__PURE__ */ l(
1480
+ ] }) : x ? /* @__PURE__ */ l(
1478
1481
  "div",
1479
1482
  {
1480
1483
  style: {
@@ -1489,7 +1492,7 @@ const xn = ({
1489
1492
  ) : /* @__PURE__ */ ae(
1490
1493
  "form",
1491
1494
  {
1492
- onSubmit: qt,
1495
+ onSubmit: Gt,
1493
1496
  style: {
1494
1497
  flex: 1,
1495
1498
  display: "flex",
@@ -1505,7 +1508,7 @@ const xn = ({
1505
1508
  value: fe,
1506
1509
  onChange: (e) => K(e.target.value),
1507
1510
  placeholder: E === "Busy" ? "Assisting another user" : Ue || "Ask me anything",
1508
- disabled: S || E === "Busy",
1511
+ disabled: x || E === "Busy",
1509
1512
  autoComplete: "off",
1510
1513
  style: { width: "100%", height: "100%" }
1511
1514
  }
@@ -1542,8 +1545,8 @@ const xn = ({
1542
1545
  {
1543
1546
  type: "button",
1544
1547
  className: "mic-button",
1545
- onClick: Vt,
1546
- disabled: S,
1548
+ onClick: $t,
1549
+ disabled: x,
1547
1550
  style: { backgroundColor: "#1e4a5e" },
1548
1551
  children: /* @__PURE__ */ ae(
1549
1552
  "svg",
@@ -1577,7 +1580,7 @@ const xn = ({
1577
1580
  {
1578
1581
  type: "submit",
1579
1582
  className: "mic-button",
1580
- disabled: S,
1583
+ disabled: x,
1581
1584
  style: { backgroundColor: "#1e4a5e" },
1582
1585
  title: "Send",
1583
1586
  children: /* @__PURE__ */ l(
@@ -1613,7 +1616,7 @@ const xn = ({
1613
1616
  "div",
1614
1617
  {
1615
1618
  className: `avatar-bubble${le === "entering" ? " avatar-bubble--entering" : le === "exiting" ? " avatar-bubble--exiting" : ""}`,
1616
- onAnimationEnd: zt,
1619
+ onAnimationEnd: Qt,
1617
1620
  children: /* @__PURE__ */ l("div", { ref: mt, className: `avatar-bubble__content${nt ? " avatar-bubble__content--nudge" : ""}`, children: pt })
1618
1621
  }
1619
1622
  ),
@@ -1623,7 +1626,7 @@ const xn = ({
1623
1626
  className: "avatar-canvas-layer",
1624
1627
  style: { width: z, height: z },
1625
1628
  children: /* @__PURE__ */ ae(
1626
- Kt,
1629
+ Zt,
1627
1630
  {
1628
1631
  shadows: !0,
1629
1632
  camera: { position: [0.2, 1.4, 3], fov: 42 },
@@ -1631,19 +1634,19 @@ const xn = ({
1631
1634
  dpr: 1.8,
1632
1635
  style: { pointerEvents: "none", width: "100%", height: "100%" },
1633
1636
  children: [
1634
- /* @__PURE__ */ l(vn, { target: mn }),
1637
+ /* @__PURE__ */ l(Sn, { target: gn }),
1635
1638
  /* @__PURE__ */ l("ambientLight", { intensity: 0.7 }),
1636
1639
  /* @__PURE__ */ l("directionalLight", { position: [0, 2, 2], intensity: 1 }),
1637
- /* @__PURE__ */ l(Yt, { preset: "city" }),
1638
- /* @__PURE__ */ l(tn, { fallback: null, children: j !== null && /* @__PURE__ */ l(
1639
- yn,
1640
+ /* @__PURE__ */ l(Kt, { preset: "city" }),
1641
+ /* @__PURE__ */ l(rn, { fallback: null, children: j !== null && /* @__PURE__ */ l(
1642
+ xn,
1640
1643
  {
1641
1644
  avatarUrl: j,
1642
1645
  isPlayingRef: M,
1643
- visemeQueueRef: x,
1646
+ visemeQueueRef: k,
1644
1647
  audioContextRef: C,
1645
1648
  responseAudioStartTimeRef: ve,
1646
- adjustments: hn,
1649
+ adjustments: pn,
1647
1650
  mood: s,
1648
1651
  expression: W,
1649
1652
  agentResponse: N,
@@ -1652,7 +1655,7 @@ const xn = ({
1652
1655
  stopPlayback: Ye,
1653
1656
  setIsSpeaking: me,
1654
1657
  expressionUrl: Ze,
1655
- onExpressionFinished: Ut,
1658
+ onExpressionFinished: Bt,
1656
1659
  isNudgeResponse: nt,
1657
1660
  avatarGender: p
1658
1661
  }
@@ -1664,20 +1667,20 @@ const xn = ({
1664
1667
  )
1665
1668
  ] }) })
1666
1669
  ] });
1667
- }, En = ({
1668
- token: f,
1670
+ }, Mn = ({
1671
+ token: d,
1669
1672
  avatarGender: L,
1670
- onNavigationRequested: b,
1673
+ onNavigationRequested: _,
1671
1674
  presetUserDetails: p
1672
1675
  }) => /* @__PURE__ */ l(
1673
- xn,
1676
+ An,
1674
1677
  {
1675
- token: f,
1676
- onNavigationRequested: b,
1678
+ token: d,
1679
+ onNavigationRequested: _,
1677
1680
  avatarGender: L,
1678
1681
  presetUserDetails: p
1679
1682
  }
1680
1683
  );
1681
1684
  export {
1682
- En as AvatarWidget
1685
+ Mn as AvatarWidget
1683
1686
  };