@streamoji/avatar-widget 0.4.3 → 0.4.4

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,90 +1,90 @@
1
1
  import { jsx as l, jsxs as be } from "react/jsx-runtime";
2
- import { useGLTF as Mt, Environment as Ln } from "@react-three/drei";
3
- import { useFrame as vn, Canvas as kn, useThree as Rn } from "@react-three/fiber";
4
- import { memo as xn, useMemo as Ct, useRef as a, useState as S, useEffect as W, useCallback as et, useLayoutEffect as Tn, Suspense as An } from "react";
2
+ import { useGLTF as Mt, Environment as vn } from "@react-three/drei";
3
+ import { useFrame as kn, Canvas as Rn, useThree as xn } from "@react-three/fiber";
4
+ import { memo as Tn, useMemo as Ut, useRef as c, useState as v, useEffect as W, useCallback as tt, useLayoutEffect as An, Suspense as En } from "react";
5
5
  import * as at from "three";
6
- import { GLTFLoader as En } from "three/examples/jsm/loaders/GLTFLoader.js";
7
- const tt = "https://ai.streamoji.com", U = (...p) => {
8
- }, Mn = (...p) => {
9
- }, zt = ({ analyser: p }) => {
10
- const E = a(null), w = a(null);
6
+ import { GLTFLoader as Mn } from "three/examples/jsm/loaders/GLTFLoader.js";
7
+ const nt = "https://ai.streamoji.com", N = (...g) => {
8
+ }, In = (...g) => {
9
+ }, Yt = ({ analyser: g }) => {
10
+ const y = c(null), S = c(null);
11
11
  return W(() => {
12
- const y = E.current;
13
- if (!y) return;
14
- const j = y.getContext("2d", { alpha: !0 });
12
+ const L = y.current;
13
+ if (!L) return;
14
+ const j = L.getContext("2d", { alpha: !0 });
15
15
  if (!j) return;
16
- let Z, ee = null;
17
- p && (p.fftSize = 128, ee = new Uint8Array(p.frequencyBinCount));
18
- const nt = () => {
19
- Z = requestAnimationFrame(nt), (y.width !== y.offsetWidth || y.height !== y.offsetHeight) && (y.width = y.offsetWidth, y.height = y.offsetHeight);
20
- const Be = y.width, F = y.height;
21
- if (Be === 0 || F === 0) return;
22
- const rt = F / 2;
23
- j.clearRect(0, 0, Be, F), j.fillStyle = "#1e293b";
24
- const Te = 2, J = Te + 2, Ae = Be * 0.95, q = Math.floor(Ae / J);
25
- (!w.current || w.current.length !== q) && (w.current = new Float32Array(q).fill(2));
26
- const se = q * J, M = (Be - se) / 2;
27
- p && ee && p.getByteFrequencyData(ee);
16
+ let Q, ee = null;
17
+ g && (g.fftSize = 128, ee = new Uint8Array(g.frequencyBinCount));
18
+ const Xe = () => {
19
+ Q = requestAnimationFrame(Xe), (L.width !== L.offsetWidth || L.height !== L.offsetHeight) && (L.width = L.offsetWidth, L.height = L.offsetHeight);
20
+ const Be = L.width, U = L.height;
21
+ if (Be === 0 || U === 0) return;
22
+ const rt = U / 2;
23
+ j.clearRect(0, 0, Be, U), j.fillStyle = "#1e293b";
24
+ const ve = 2, G = ve + 2, Ae = Be * 0.95, q = Math.floor(Ae / G);
25
+ (!S.current || S.current.length !== q) && (S.current = new Float32Array(q).fill(2));
26
+ const se = q * G, M = (Be - se) / 2;
27
+ g && ee && g.getByteFrequencyData(ee);
28
28
  const _e = ee ? ee.length : 0, b = Math.floor(_e * 0.7) / q, ae = new Float32Array(q);
29
- for (let f = 0; f < q; f++) {
29
+ for (let m = 0; m < q; m++) {
30
30
  let O = 0;
31
31
  if (ee && b > 0) {
32
- const I = Math.floor(f * b), N = Math.floor((f + 1) * b);
33
- for (let Y = I; Y < N; Y++) {
34
- const Q = ee[Y] || 0;
35
- Q > O && (O = Q);
32
+ const I = Math.floor(m * b), F = Math.floor((m + 1) * b);
33
+ for (let Y = I; Y < F; Y++) {
34
+ const X = ee[Y] || 0;
35
+ X > O && (O = X);
36
36
  }
37
37
  }
38
38
  O < 10 && (O = 0);
39
- const z = O / 255, T = O > 0 ? Math.max(2, Math.pow(z, 1.4) * F * 0.25) : 2;
40
- ae[f] = T;
39
+ const z = O / 255, A = O > 0 ? Math.max(2, Math.pow(z, 1.4) * U * 0.25) : 2;
40
+ ae[m] = A;
41
41
  }
42
- for (let f = 0; f < q; f++) {
43
- const O = q - 1 - f, z = Math.max(ae[f], ae[O]), T = w.current[f] + (z - w.current[f]) * 0.3;
44
- w.current[f] = T;
45
- const I = M + f * J, N = rt - T / 2;
46
- j.beginPath(), j.roundRect ? j.roundRect(I, N, Te, T, 4) : j.fillRect(I, N, Te, T), j.fill();
42
+ for (let m = 0; m < q; m++) {
43
+ const O = q - 1 - m, z = Math.max(ae[m], ae[O]), A = S.current[m] + (z - S.current[m]) * 0.3;
44
+ S.current[m] = A;
45
+ const I = M + m * G, F = rt - A / 2;
46
+ j.beginPath(), j.roundRect ? j.roundRect(I, F, ve, A, 4) : j.fillRect(I, F, ve, A), j.fill();
47
47
  }
48
48
  };
49
- return nt(), () => {
50
- cancelAnimationFrame(Z);
49
+ return Xe(), () => {
50
+ cancelAnimationFrame(Q);
51
51
  };
52
- }, [p]), /* @__PURE__ */ l(
52
+ }, [g]), /* @__PURE__ */ l(
53
53
  "canvas",
54
54
  {
55
- ref: E,
55
+ ref: y,
56
56
  style: { width: "100%", height: "100%", display: "block" }
57
57
  }
58
58
  );
59
- }, In = "https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev", Yt = "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/avatar-blue-suit.glb";
60
- function Dn(p) {
61
- const [E, w] = S(null);
59
+ }, Dn = "https://pub-48df6f7d60d6440bbd01676ea5d90e55.r2.dev", Kt = "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/default-models/avatar-blue-suit.glb";
60
+ function On(g) {
61
+ const [y, S] = v(null);
62
62
  return W(() => {
63
- if (!p) {
64
- w(null);
63
+ if (!g) {
64
+ S(null);
65
65
  return;
66
66
  }
67
- let y = !1;
68
- const j = `${In}/${p}.glb`;
69
- return fetch(j, { method: "HEAD" }).then((Z) => {
70
- y || w(Z.ok ? j : Yt);
67
+ let L = !1;
68
+ const j = `${Dn}/${g}.glb`;
69
+ return fetch(j, { method: "HEAD" }).then((Q) => {
70
+ L || S(Q.ok ? j : Kt);
71
71
  }).catch(() => {
72
- y || w(Yt);
72
+ L || S(Kt);
73
73
  }), () => {
74
- y = !0;
74
+ L = !0;
75
75
  };
76
- }, [p]), E;
76
+ }, [g]), y;
77
77
  }
78
- const On = [
78
+ const Cn = [
79
79
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_001.glb",
80
80
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_002.glb",
81
81
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_002.glb",
82
82
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/M_Standing_Idle_Variations_005.glb"
83
- ], Cn = [
83
+ ], Un = [
84
84
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_001.glb",
85
85
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_003.glb",
86
86
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/idle/F_Standing_Idle_Variations_003.glb"
87
- ], Un = [
87
+ ], Nn = [
88
88
  {
89
89
  id: "m_expr_01",
90
90
  name: "Friendly Wave",
@@ -254,19 +254,19 @@ const On = [
254
254
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_005.glb",
255
255
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_007.glb",
256
256
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/M_Talking_Variations_006.glb"
257
- ], Nn = [
257
+ ], Pn = [
258
258
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_004.glb",
259
259
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_005.glb",
260
260
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_006.glb",
261
261
  "https://pub-be53cae7bd99457a8c1f11b4d38f1672.r2.dev/masculine/expression/F_Talking_Variations_002.glb"
262
- ], Pn = {
262
+ ], Bn = {
263
263
  zoom: 0.85,
264
264
  position: [0.15, -0.8, 0],
265
265
  scale: 1.5,
266
266
  rotation: [0.15, 0.02, 0]
267
- }, Bn = [-0.45, 1.9, 0.1], Wn = [-0.45, 1.75, 0.1], Vn = {
267
+ }, Wn = [-0.45, 1.9, 0.1], Vn = [-0.45, 1.75, 0.1], $n = {
268
268
  browInnerUp: 0.2
269
- }, It = 0.18, $n = 1, Hn = 0.5, Kt = 3, bt = 0.55, Dt = 0.12, Qt = 2, Xt = 2, _t = 4, Zt = 8, jn = 1, en = 0.38, tn = 0.32, nn = "__branding__", wt = {
269
+ }, It = 0.18, Hn = 1, jn = 0.5, Qt = 3, bt = 0.55, Dt = 0.12, Xt = 2, Zt = 2, _t = 4, en = 8, Gn = 1, tn = 0.38, nn = 0.32, rn = "__branding__", wt = {
270
270
  neutral: { eyeLookDownLeft: 0.1, eyeLookDownRight: 0.1 },
271
271
  happy: {
272
272
  mouthSmileLeft: 0.2,
@@ -583,7 +583,7 @@ const On = [
583
583
  }
584
584
  },
585
585
  { key: "viseme_sil", mix: {} }
586
- ], Gn = {
586
+ ], qn = {
587
587
  aei: [
588
588
  { v: "E", w: 0.8 },
589
589
  { v: "I", w: 0.2 }
@@ -612,91 +612,91 @@ const On = [
612
612
  ],
613
613
  sil: [{ v: "sil", w: 1 }]
614
614
  };
615
- function qn(p) {
616
- if (!p) return [{ v: "sil", w: 1 }];
617
- const E = p.toLowerCase();
618
- return Gn[E] ?? [{ v: "sil", w: 1 }];
615
+ function zn(g) {
616
+ if (!g) return [{ v: "sil", w: 1 }];
617
+ const y = g.toLowerCase();
618
+ return qn[y] ?? [{ v: "sil", w: 1 }];
619
619
  }
620
- function zn({ target: p }) {
621
- const { camera: E } = Rn();
620
+ function Yn({ target: g }) {
621
+ const { camera: y } = xn();
622
622
  return W(() => {
623
- E.lookAt(...p);
624
- }, [E, p]), null;
623
+ y.lookAt(...g);
624
+ }, [y, g]), null;
625
625
  }
626
- function c(p, E, w) {
627
- if (!p || !p.morphTargetDictionary)
626
+ function u(g, y, S) {
627
+ if (!g || !g.morphTargetDictionary)
628
628
  return;
629
- const y = p, j = y.morphTargetDictionary, Z = y.morphTargetInfluences;
630
- if (Z)
629
+ const L = g, j = L.morphTargetDictionary, Q = L.morphTargetInfluences;
630
+ if (Q)
631
631
  for (const ee in j)
632
- ee.toLowerCase() === E.toLowerCase() && (Z[j[ee]] = w);
632
+ ee.toLowerCase() === y.toLowerCase() && (Q[j[ee]] = S);
633
633
  }
634
- function Ot(p, E = 0.97) {
635
- if (!p) return;
636
- const w = p;
637
- if (w.morphTargetInfluences)
638
- for (let y = 0; y < w.morphTargetInfluences.length; y++)
639
- w.morphTargetInfluences[y] *= E;
634
+ function Ot(g, y = 0.97) {
635
+ if (!g) return;
636
+ const S = g;
637
+ if (S.morphTargetInfluences)
638
+ for (let L = 0; L < S.morphTargetInfluences.length; L++)
639
+ S.morphTargetInfluences[L] *= y;
640
640
  }
641
- const Yn = xn(
641
+ const Kn = Tn(
642
642
  ({
643
- avatarUrl: p,
644
- isPlayingRef: E,
645
- visemeQueueRef: w,
646
- audioContextRef: y,
643
+ avatarUrl: g,
644
+ isPlayingRef: y,
645
+ visemeQueueRef: S,
646
+ audioContextRef: L,
647
647
  responseAudioStartTimeRef: j,
648
- adjustments: Z,
648
+ adjustments: Q,
649
649
  mood: ee,
650
- expression: nt,
650
+ expression: Xe,
651
651
  agentResponse: Be,
652
- isSpeaking: F,
652
+ isSpeaking: U,
653
653
  nextStartTimeRef: rt,
654
- stopPlayback: Te,
654
+ stopPlayback: ve,
655
655
  setIsSpeaking: We,
656
- expressionUrl: J,
656
+ expressionUrl: G,
657
657
  onExpressionFinished: Ae,
658
658
  isNudgeResponse: q,
659
659
  avatarGender: se
660
660
  }) => {
661
- const { scene: M } = Mt(p), H = Mt(se === "female" ? Cn : On), b = Ct(
662
- () => H.flatMap((m) => m.animations),
661
+ const { scene: M } = Mt(g), H = Mt(se === "female" ? Un : Cn), b = Ut(
662
+ () => H.flatMap((p) => p.animations),
663
663
  [H]
664
- ), f = Mt(se === "female" ? Nn : Fn), O = Ct(
665
- () => f.flatMap((m) => m.animations),
666
- [f]
667
- ), z = a(null), T = a(null), I = a(null), N = a(null), Y = a(null), Q = a(null), yt = a([]), [te] = S(() => new at.AnimationMixer(M)), G = a({}), V = a(null), Ee = a(0), Xe = a(!1), Ve = a(0), Me = a(!1), we = a(null), Ie = a(Kt), ct = a(-1), De = a("left"), $e = a(_t + Math.random() * (Zt - _t)), de = a(0), Oe = a("smile");
664
+ ), m = Mt(se === "female" ? Pn : Fn), O = Ut(
665
+ () => m.flatMap((p) => p.animations),
666
+ [m]
667
+ ), z = c(null), A = c(null), I = c(null), F = c(null), Y = c(null), X = c(null), yt = c([]), [te] = v(() => new at.AnimationMixer(M)), J = c({}), V = c(null), Ee = c(0), Ze = c(!1), Ve = c(0), Me = c(!1), we = c(null), Ie = c(Qt), ct = c(-1), De = c("left"), $e = c(_t + Math.random() * (en - _t)), de = c(0), Oe = c("smile");
668
668
  W(() => {
669
669
  if (!(!b || !M)) {
670
- if (b.forEach((m, h) => {
671
- const s = `idle_${h}`;
672
- if (!G.current[s]) {
673
- const o = te.clipAction(m, M);
674
- o.name = s, o.setLoop(at.LoopOnce, 1), o.clampWhenFinished = !0, G.current[s] = o;
670
+ if (b.forEach((p, h) => {
671
+ const a = `idle_${h}`;
672
+ if (!J.current[a]) {
673
+ const o = te.clipAction(p, M);
674
+ o.name = a, o.setLoop(at.LoopOnce, 1), o.clampWhenFinished = !0, J.current[a] = o;
675
675
  }
676
- }), O.forEach((m, h) => {
677
- const s = `talk_${h}`;
678
- if (!G.current[s]) {
679
- const o = te.clipAction(m, M);
680
- o.name = s, o.setLoop(at.LoopOnce, 1), o.clampWhenFinished = !0, G.current[s] = o;
676
+ }), O.forEach((p, h) => {
677
+ const a = `talk_${h}`;
678
+ if (!J.current[a]) {
679
+ const o = te.clipAction(p, M);
680
+ o.name = a, o.setLoop(at.LoopOnce, 1), o.clampWhenFinished = !0, J.current[a] = o;
681
681
  }
682
682
  }), b.length > 0) {
683
- const m = G.current.idle_0, h = V.current && te.existingAction(V.current.getClip());
684
- m && !h && (m.reset().fadeIn(0.5).play(), V.current = m);
683
+ const p = J.current.idle_0, h = V.current && te.existingAction(V.current.getClip());
684
+ p && !h && (p.reset().fadeIn(0.5).play(), V.current = p);
685
685
  }
686
686
  return () => {
687
- te.stopAllAction(), G.current = {}, V.current = null;
687
+ te.stopAllAction(), J.current = {}, V.current = null;
688
688
  };
689
689
  }
690
690
  }, [b, O, M, te]);
691
- const ve = a("");
691
+ const ke = c("");
692
692
  W(() => {
693
- if (!J || !M || J === ve.current) return;
694
- ve.current = J, we.current = J, new En().load(
695
- J,
693
+ if (!G || !M || G === ke.current) return;
694
+ ke.current = G, we.current = G, new Mn().load(
695
+ G,
696
696
  (h) => {
697
697
  if (h.animations && h.animations.length > 0) {
698
- const s = h.animations[0], o = te.clipAction(s, M);
699
- if (o.name = `EXPR_${J}`, o.setLoop(at.LoopOnce, 1), o.clampWhenFinished = !0, G.current[`EXPR_${J}`] = o, F && we.current === J) {
698
+ const a = h.animations[0], o = te.clipAction(a, M);
699
+ if (o.name = `EXPR_${G}`, o.setLoop(at.LoopOnce, 1), o.clampWhenFinished = !0, J.current[`EXPR_${G}`] = o, U && we.current === G) {
700
700
  const d = V.current;
701
701
  o.reset().fadeIn(0.3).play(), d && d !== o && d.crossFadeTo(o, 0.3, !0), V.current = o, we.current = null;
702
702
  }
@@ -704,111 +704,111 @@ const Yn = xn(
704
704
  },
705
705
  void 0,
706
706
  (h) => {
707
- console.error(`[ANIMATION] Failed to load ${J}`, h);
707
+ console.error(`[ANIMATION] Failed to load ${G}`, h);
708
708
  }
709
709
  );
710
- }, [J, M, te, F]), W(() => {
711
- const m = (h) => {
712
- const s = h.action, o = s.name || "";
710
+ }, [G, M, te, U]), W(() => {
711
+ const p = (h) => {
712
+ const a = h.action, o = a.name || "";
713
713
  if (o.startsWith("idle_")) {
714
- const D = (parseInt(o.split("_")[1]) + 1) % b.length, ne = G.current[`idle_${D}`];
715
- ne && (ne.reset().fadeIn(0.5).play(), s.crossFadeTo(ne, 0.5, !0), V.current = ne);
714
+ const D = (parseInt(o.split("_")[1]) + 1) % b.length, ne = J.current[`idle_${D}`];
715
+ ne && (ne.reset().fadeIn(0.5).play(), a.crossFadeTo(ne, 0.5, !0), V.current = ne);
716
716
  } else if (o.startsWith("EXPR_")) {
717
- if (F) {
717
+ if (U) {
718
718
  const d = Math.floor(
719
719
  Math.random() * O.length
720
- ), D = G.current[`talk_${d}`];
721
- D && (D.reset().fadeIn(0.5).play(), s.crossFadeTo(D, 0.5, !0), V.current = D);
720
+ ), D = J.current[`talk_${d}`];
721
+ D && (D.reset().fadeIn(0.5).play(), a.crossFadeTo(D, 0.5, !0), V.current = D);
722
722
  } else {
723
- const d = G.current.idle_0;
724
- d && (d.reset().fadeIn(0.5).play(), s.crossFadeTo(d, 0.5, !0), V.current = d);
723
+ const d = J.current.idle_0;
724
+ d && (d.reset().fadeIn(0.5).play(), a.crossFadeTo(d, 0.5, !0), V.current = d);
725
725
  }
726
726
  Ae && Ae();
727
727
  } else if (o.startsWith("talk_"))
728
- if (F && !q) {
729
- const D = (parseInt(o.split("_")[1]) + 1) % O.length, ne = G.current[`talk_${D}`];
730
- ne && (ne.reset().fadeIn(0.3).play(), s.crossFadeTo(ne, 0.3, !0), V.current = ne);
728
+ if (U && !q) {
729
+ const D = (parseInt(o.split("_")[1]) + 1) % O.length, ne = J.current[`talk_${D}`];
730
+ ne && (ne.reset().fadeIn(0.3).play(), a.crossFadeTo(ne, 0.3, !0), V.current = ne);
731
731
  } else {
732
- const d = G.current.idle_0;
733
- d && (d.reset().fadeIn(0.5).play(), s.crossFadeTo(d, 0.5, !0), V.current = d);
732
+ const d = J.current.idle_0;
733
+ d && (d.reset().fadeIn(0.5).play(), a.crossFadeTo(d, 0.5, !0), V.current = d);
734
734
  }
735
735
  };
736
- return te.addEventListener("finished", m), () => te.removeEventListener("finished", m);
736
+ return te.addEventListener("finished", p), () => te.removeEventListener("finished", p);
737
737
  }, [
738
738
  te,
739
739
  b,
740
740
  O,
741
- F,
741
+ U,
742
742
  q,
743
743
  Ae
744
744
  ]), W(() => {
745
- if (F && M) {
746
- const m = V.current, h = m?.name || "";
745
+ if (U && M) {
746
+ const p = V.current, h = p?.name || "";
747
747
  if (h.startsWith("idle_") || h.startsWith("talk_") || h === "") {
748
- const s = we.current;
749
- if (s) {
750
- const o = G.current[`EXPR_${s}`];
748
+ const a = we.current;
749
+ if (a) {
750
+ const o = J.current[`EXPR_${a}`];
751
751
  if (o) {
752
- o.reset().fadeIn(0.3).play(), m && m !== o && m.crossFadeTo(o, 0.3, !0), V.current = o, we.current = null;
752
+ o.reset().fadeIn(0.3).play(), p && p !== o && p.crossFadeTo(o, 0.3, !0), V.current = o, we.current = null;
753
753
  return;
754
754
  }
755
755
  }
756
756
  if (h.startsWith("idle_") || h === "") {
757
757
  const o = Math.floor(
758
758
  Math.random() * O.length
759
- ), d = G.current[`talk_${o}`];
760
- d && (d.reset().fadeIn(0.5).play(), m && m.crossFadeTo(d, 0.5, !0), V.current = d);
759
+ ), d = J.current[`talk_${o}`];
760
+ d && (d.reset().fadeIn(0.5).play(), p && p.crossFadeTo(d, 0.5, !0), V.current = d);
761
761
  }
762
762
  }
763
- } else if (!F && M) {
764
- const m = V.current, h = m?.name || "";
763
+ } else if (!U && M) {
764
+ const p = V.current, h = p?.name || "";
765
765
  if (h.startsWith("talk_") || h.startsWith("EXPR_")) {
766
- const s = G.current.idle_0;
767
- s && (s.reset().fadeIn(0.5).play(), m && m.crossFadeTo(s, 0.5, !0), V.current = s);
766
+ const a = J.current.idle_0;
767
+ a && (a.reset().fadeIn(0.5).play(), p && p.crossFadeTo(a, 0.5, !0), V.current = a);
768
768
  }
769
769
  }
770
- }, [F, M, J]), W(() => {
770
+ }, [U, M, G]), W(() => {
771
771
  if (!M) return;
772
- M.traverse((s) => {
773
- if (s.isMesh && s.morphTargetDictionary) {
774
- const o = s.name.toLowerCase();
775
- (o.includes("head") || o.includes("avatar")) && (T.current = s, U(`[ANIMATION] Found head mesh: ${s.name}`)), o.includes("teeth") && (I.current = s, U(`[ANIMATION] Found teeth mesh: ${s.name}`)), o.includes("beard") && (N.current = s, U(`[ANIMATION] Found beard mesh: ${s.name}`)), o.includes("eyeleft") && (Y.current = s, U(`[ANIMATION] Found eye left mesh: ${s.name}`)), o.includes("eyeright") && (Q.current = s, U(`[ANIMATION] Found eye right mesh: ${s.name}`));
772
+ M.traverse((a) => {
773
+ if (a.isMesh && a.morphTargetDictionary) {
774
+ const o = a.name.toLowerCase();
775
+ (o.includes("head") || o.includes("avatar")) && (A.current = a, N(`[ANIMATION] Found head mesh: ${a.name}`)), o.includes("teeth") && (I.current = a, N(`[ANIMATION] Found teeth mesh: ${a.name}`)), o.includes("beard") && (F.current = a, N(`[ANIMATION] Found beard mesh: ${a.name}`)), o.includes("eyeleft") && (Y.current = a, N(`[ANIMATION] Found eye left mesh: ${a.name}`)), o.includes("eyeright") && (X.current = a, N(`[ANIMATION] Found eye right mesh: ${a.name}`));
776
776
  }
777
777
  });
778
- const m = T.current?.morphTargetDictionary;
779
- m && Object.keys(m).filter(
780
- (s) => s.toLowerCase().includes("brow")
778
+ const p = A.current?.morphTargetDictionary;
779
+ p && Object.keys(p).filter(
780
+ (a) => a.toLowerCase().includes("brow")
781
781
  );
782
782
  const h = [];
783
- M.traverse((s) => {
784
- if (s.isMesh) {
785
- const d = s.morphTargetDictionary;
786
- d && Object.keys(d).some((D) => D.toLowerCase().includes("brow")) && h.push(s);
783
+ M.traverse((a) => {
784
+ if (a.isMesh) {
785
+ const d = a.morphTargetDictionary;
786
+ d && Object.keys(d).some((D) => D.toLowerCase().includes("brow")) && h.push(a);
787
787
  }
788
- }), yt.current = h, h.length > 0 && U("[ANIMATION] Meshes with brow morphs:", h.length);
788
+ }), yt.current = h, h.length > 0 && N("[ANIMATION] Meshes with brow morphs:", h.length);
789
789
  }, [M]);
790
- const ot = (m, h = 1) => {
791
- const s = `viseme_${m}`.toLowerCase(), o = Jn.find((d) => d.key.toLowerCase() === s);
790
+ const ot = (p, h = 1) => {
791
+ const a = `viseme_${p}`.toLowerCase(), o = Jn.find((d) => d.key.toLowerCase() === a);
792
792
  if (o) {
793
793
  for (const d in o.mix) {
794
794
  const D = o.mix[d] * h;
795
- c(T.current, d, D), c(N.current, d, D), (!o.teethMix || !(d in o.teethMix)) && c(I.current, d, D);
795
+ u(A.current, d, D), u(F.current, d, D), (!o.teethMix || !(d in o.teethMix)) && u(I.current, d, D);
796
796
  }
797
797
  if (o.teethMix)
798
798
  for (const d in o.teethMix) {
799
799
  const D = o.teethMix[d] * h;
800
- c(I.current, d, D);
800
+ u(I.current, d, D);
801
801
  }
802
802
  }
803
- }, it = (m) => {
804
- const h = wt[m] ?? wt.neutral;
805
- for (const s in h)
806
- c(T.current, s, h[s]), c(I.current, s, h[s]), c(N.current, s, h[s]);
803
+ }, it = (p) => {
804
+ const h = wt[p] ?? wt.neutral;
805
+ for (const a in h)
806
+ u(A.current, a, h[a]), u(I.current, a, h[a]), u(F.current, a, h[a]);
807
807
  };
808
- return vn((m, h) => {
809
- const s = Math.pow(0.88, 60 * h);
810
- Ot(T.current, s), Ot(I.current, s), Ot(N.current, s), it(ee);
811
- const o = m.clock.elapsedTime;
808
+ return kn((p, h) => {
809
+ const a = Math.pow(0.88, 60 * h);
810
+ Ot(A.current, a), Ot(I.current, a), Ot(F.current, a), it(ee);
811
+ const o = p.clock.elapsedTime;
812
812
  let d = 0;
813
813
  if (Math.floor(o) % 5 === 0 && Math.floor((o - h) % 5) !== 0) {
814
814
  let _ = null;
@@ -816,329 +816,348 @@ const Yn = xn(
816
816
  P.name.toLowerCase().includes("hips") && (_ = P);
817
817
  });
818
818
  const K = _ ? `Hips Y: ${_.position.y.toFixed(4)}` : "Hips not found";
819
- U(`[ANIMATION] Mixer Time: ${te.time.toFixed(2)}, ${K}`);
819
+ N(`[ANIMATION] Mixer Time: ${te.time.toFixed(2)}, ${K}`);
820
820
  }
821
- if (te.update(h), o > Ee.current && !Xe.current && (Xe.current = !0, Ve.current = o), Xe.current) {
822
- const _ = F ? 0.2 : 0.3, K = (o - Ve.current) / _;
821
+ if (te.update(h), o > Ee.current && !Ze.current && (Ze.current = !0, Ve.current = o), Ze.current) {
822
+ const _ = U ? 0.2 : 0.3, K = (o - Ve.current) / _;
823
823
  if (K >= 1)
824
- if (Xe.current = !1, Me.current) {
825
- const P = F ? 1 : 2.5;
824
+ if (Ze.current = !1, Me.current) {
825
+ const P = U ? 1 : 2.5;
826
826
  Ee.current = o + P, Me.current = !1;
827
827
  } else
828
828
  Ee.current = o + 0.12, Me.current = !0;
829
829
  else {
830
830
  const P = K < 0.5 ? K * 2 : (1 - K) * 2;
831
- c(T.current, "eyeBlinkLeft", P), c(T.current, "eyeBlinkRight", P), c(I.current, "eyeBlinkLeft", P), c(I.current, "eyeBlinkRight", P), c(N.current, "eyeBlinkLeft", P), c(N.current, "eyeBlinkRight", P), d = P * Vn.browInnerUp;
831
+ u(A.current, "eyeBlinkLeft", P), u(A.current, "eyeBlinkRight", P), u(I.current, "eyeBlinkLeft", P), u(I.current, "eyeBlinkRight", P), u(F.current, "eyeBlinkLeft", P), u(F.current, "eyeBlinkRight", P), d = P * $n.browInnerUp;
832
832
  }
833
833
  }
834
- const D = wt[ee] ?? wt.neutral, ne = D.browInnerUp ?? 0, St = D.browOuterUpLeft ?? 0, He = D.browOuterUpRight ?? 0, re = o * $n, ut = It * Math.sin(re), Ce = It * 0.7 * Math.sin(re + 0.7), je = It * 0.7 * Math.sin(re + 1.3), L = (_) => Math.max(0, Math.min(1, _)), lt = L(ne + ut), Je = L(St + Ce), Ge = L(He + je), ht = L(lt + d);
835
- c(T.current, "browInnerUp", ht), c(I.current, "browInnerUp", ht), c(N.current, "browInnerUp", ht), c(T.current, "browOuterUpLeft", Je), c(I.current, "browOuterUpLeft", Je), c(N.current, "browOuterUpLeft", Je), c(T.current, "browOuterUpRight", Ge), c(I.current, "browOuterUpRight", Ge), c(N.current, "browOuterUpRight", Ge);
834
+ const D = wt[ee] ?? wt.neutral, ne = D.browInnerUp ?? 0, St = D.browOuterUpLeft ?? 0, He = D.browOuterUpRight ?? 0, re = o * Hn, ut = It * Math.sin(re), Ce = It * 0.7 * Math.sin(re + 0.7), je = It * 0.7 * Math.sin(re + 1.3), R = (_) => Math.max(0, Math.min(1, _)), lt = R(ne + ut), Ge = R(St + Ce), Je = R(He + je), ht = R(lt + d);
835
+ u(A.current, "browInnerUp", ht), u(I.current, "browInnerUp", ht), u(F.current, "browInnerUp", ht), u(A.current, "browOuterUpLeft", Ge), u(I.current, "browOuterUpLeft", Ge), u(F.current, "browOuterUpLeft", Ge), u(A.current, "browOuterUpRight", Je), u(I.current, "browOuterUpRight", Je), u(F.current, "browOuterUpRight", Je);
836
836
  const qe = Ie.current, Ue = qe + bt, fe = Ue + Dt;
837
- o > fe && (Ie.current += bt + Dt + Kt);
838
- const ye = !F && o >= qe && o < Ue, Fe = !F && o >= Ue && o < fe;
839
- (ye || Fe) && ct.current !== qe && (ct.current = qe, De.current = Math.random() < 0.7 ? "left" : "up");
840
- const dt = ye ? o - qe : Fe ? bt : 0, oe = ye || Fe ? Math.min(1, dt / bt) : 0, ze = oe <= 0 ? 0 : Math.sin(oe * Math.PI), ft = Fe ? 1 - (o - Ue) / Dt : 1, Lt = ye ? ze : Fe ? ze * ft : 0, Ne = Hn * Lt, k = (_) => D[_] ?? 0;
841
- if (De.current === "up" ? (c(Y.current, "eyeLookUpLeft", L(k("eyeLookUpLeft") + Ne)), c(Y.current, "eyeLookDownLeft", L(k("eyeLookDownLeft"))), c(Y.current, "eyeLookOutLeft", L(k("eyeLookOutLeft"))), c(Y.current, "eyeLookInLeft", L(k("eyeLookInLeft"))), c(Q.current, "eyeLookUpRight", L(k("eyeLookUpRight") + Ne)), c(Q.current, "eyeLookDownRight", L(k("eyeLookDownRight"))), c(Q.current, "eyeLookOutRight", L(k("eyeLookOutRight"))), c(Q.current, "eyeLookInRight", L(k("eyeLookInRight")))) : (c(Y.current, "eyeLookUpLeft", L(k("eyeLookUpLeft"))), c(Y.current, "eyeLookDownLeft", L(k("eyeLookDownLeft"))), c(Y.current, "eyeLookOutLeft", L(k("eyeLookOutLeft"))), c(Y.current, "eyeLookInLeft", L(k("eyeLookInLeft") + Ne)), c(Q.current, "eyeLookUpRight", L(k("eyeLookUpRight"))), c(Q.current, "eyeLookDownRight", L(k("eyeLookDownRight"))), c(Q.current, "eyeLookOutRight", L(k("eyeLookOutRight") + Ne)), c(Q.current, "eyeLookInRight", L(k("eyeLookInRight")))), !F && o >= $e.current) {
837
+ o > fe && (Ie.current += bt + Dt + Qt);
838
+ const ye = !U && o >= qe && o < Ue, Ne = !U && o >= Ue && o < fe;
839
+ (ye || Ne) && ct.current !== qe && (ct.current = qe, De.current = Math.random() < 0.7 ? "left" : "up");
840
+ const dt = ye ? o - qe : Ne ? bt : 0, oe = ye || Ne ? Math.min(1, dt / bt) : 0, ze = oe <= 0 ? 0 : Math.sin(oe * Math.PI), ft = Ne ? 1 - (o - Ue) / Dt : 1, Lt = ye ? ze : Ne ? ze * ft : 0, Fe = jn * Lt, x = (_) => D[_] ?? 0;
841
+ if (De.current === "up" ? (u(Y.current, "eyeLookUpLeft", R(x("eyeLookUpLeft") + Fe)), u(Y.current, "eyeLookDownLeft", R(x("eyeLookDownLeft"))), u(Y.current, "eyeLookOutLeft", R(x("eyeLookOutLeft"))), u(Y.current, "eyeLookInLeft", R(x("eyeLookInLeft"))), u(X.current, "eyeLookUpRight", R(x("eyeLookUpRight") + Fe)), u(X.current, "eyeLookDownRight", R(x("eyeLookDownRight"))), u(X.current, "eyeLookOutRight", R(x("eyeLookOutRight"))), u(X.current, "eyeLookInRight", R(x("eyeLookInRight")))) : (u(Y.current, "eyeLookUpLeft", R(x("eyeLookUpLeft"))), u(Y.current, "eyeLookDownLeft", R(x("eyeLookDownLeft"))), u(Y.current, "eyeLookOutLeft", R(x("eyeLookOutLeft"))), u(Y.current, "eyeLookInLeft", R(x("eyeLookInLeft") + Fe)), u(X.current, "eyeLookUpRight", R(x("eyeLookUpRight"))), u(X.current, "eyeLookDownRight", R(x("eyeLookDownRight"))), u(X.current, "eyeLookOutRight", R(x("eyeLookOutRight") + Fe)), u(X.current, "eyeLookInRight", R(x("eyeLookInRight")))), !U && o >= $e.current) {
842
842
  de.current = o, Oe.current = Math.random() < 0.5 ? "pucker" : "smile";
843
- const _ = Oe.current === "pucker" ? Xt : Qt;
844
- $e.current = o + _ + _t + Math.random() * (Zt - _t);
843
+ const _ = Oe.current === "pucker" ? Zt : Xt;
844
+ $e.current = o + _ + _t + Math.random() * (en - _t);
845
845
  }
846
- const ce = Oe.current === "pucker" ? Xt : Qt, ue = !F && o >= de.current && o < de.current + ce, Ye = ue ? (o - de.current) / ce : 0, ke = Ye <= 0 ? 0 : Ye < 0.5 ? Ye * 2 : (() => {
846
+ const ce = Oe.current === "pucker" ? Zt : Xt, ue = !U && o >= de.current && o < de.current + ce, Ye = ue ? (o - de.current) / ce : 0, Re = Ye <= 0 ? 0 : Ye < 0.5 ? Ye * 2 : (() => {
847
847
  const _ = (Ye - 0.5) * 2;
848
848
  return 1 - _ * _ * (3 - 2 * _);
849
849
  })(), me = (_) => D[_] ?? 0;
850
850
  if (ue)
851
851
  if (Oe.current === "pucker") {
852
- const _ = L(me("mouthPucker") + jn * ke);
853
- c(T.current, "mouthPucker", _), c(I.current, "mouthPucker", _), c(N.current, "mouthPucker", _);
852
+ const _ = R(me("mouthPucker") + Gn * Re);
853
+ u(A.current, "mouthPucker", _), u(I.current, "mouthPucker", _), u(F.current, "mouthPucker", _);
854
854
  } else {
855
- const _ = L(me("mouthSmileLeft") + en * ke), K = L(me("mouthSmileRight") + en * ke), P = L(me("mouthDimpleLeft") + tn * ke), Re = L(me("mouthDimpleRight") + tn * ke);
856
- c(T.current, "mouthSmileLeft", _), c(T.current, "mouthSmileRight", K), c(T.current, "mouthDimpleLeft", P), c(T.current, "mouthDimpleRight", Re), c(I.current, "mouthSmileLeft", _), c(I.current, "mouthSmileRight", K), c(I.current, "mouthDimpleLeft", P), c(I.current, "mouthDimpleRight", Re), c(N.current, "mouthSmileLeft", _), c(N.current, "mouthSmileRight", K), c(N.current, "mouthDimpleLeft", P), c(N.current, "mouthDimpleRight", Re);
855
+ const _ = R(me("mouthSmileLeft") + tn * Re), K = R(me("mouthSmileRight") + tn * Re), P = R(me("mouthDimpleLeft") + nn * Re), xe = R(me("mouthDimpleRight") + nn * Re);
856
+ u(A.current, "mouthSmileLeft", _), u(A.current, "mouthSmileRight", K), u(A.current, "mouthDimpleLeft", P), u(A.current, "mouthDimpleRight", xe), u(I.current, "mouthSmileLeft", _), u(I.current, "mouthSmileRight", K), u(I.current, "mouthDimpleLeft", P), u(I.current, "mouthDimpleRight", xe), u(F.current, "mouthSmileLeft", _), u(F.current, "mouthSmileRight", K), u(F.current, "mouthDimpleLeft", P), u(F.current, "mouthDimpleRight", xe);
857
857
  }
858
858
  if (z.current) {
859
- const _ = E.current ? 0 : Z.rotation[1];
859
+ const _ = y.current ? 0 : Q.rotation[1];
860
860
  z.current.rotation.y = at.MathUtils.lerp(
861
861
  z.current.rotation.y,
862
862
  _,
863
863
  0.1
864
- ), z.current.position.set(...Z.position), z.current.scale.setScalar(Z.scale), z.current.rotation.x = Z.rotation[0], z.current.rotation.z = Z.rotation[2];
864
+ ), z.current.position.set(...Q.position), z.current.scale.setScalar(Q.scale), z.current.rotation.x = Q.rotation[0], z.current.rotation.z = Q.rotation[2];
865
865
  }
866
- if (E.current && y.current) {
867
- const _ = y.current.currentTime, Re = (_ - j.current) * 1e3 - -150;
868
- for (let le = 0; le < w.current.length; le++) {
869
- const he = w.current[le];
870
- Re >= he.vtime && Re < he.vtime + he.vduration && ot(he.viseme, he.weight ?? 1);
866
+ if (y.current && L.current) {
867
+ const _ = L.current.currentTime, xe = (_ - j.current) * 1e3 - -150;
868
+ for (let le = 0; le < S.current.length; le++) {
869
+ const he = S.current[le];
870
+ xe >= he.vtime && xe < he.vtime + he.vduration && ot(he.viseme, he.weight ?? 1);
871
871
  }
872
- _ > rt.current + 0.5 && (Te(), We(!1));
872
+ _ > rt.current + 0.5 && (ve(), We(!1));
873
873
  }
874
874
  }), /* @__PURE__ */ l("group", { ref: z, children: /* @__PURE__ */ l("primitive", { object: M }) });
875
875
  }
876
876
  );
877
- function Kn(p) {
878
- return p ? p.charAt(0).toUpperCase() + p.slice(1).toLowerCase() : "";
877
+ function Qn(g) {
878
+ return g ? g.charAt(0).toUpperCase() + g.slice(1).toLowerCase() : "";
879
879
  }
880
- function rn(p) {
881
- return p.replace(/\*(.*?)\*/g, " $1 ").replace(/\[.*?\]/g, " ").replace(/<.*?\/>/g, " ").replace(/<.*?>.*?<\/.*?>/g, " ").replace(/\s+/g, " ").trim();
880
+ function on(g) {
881
+ return g.replace(/\*(.*?)\*/g, " $1 ").replace(/\[.*?\]/g, " ").replace(/<.*?\/>/g, " ").replace(/<.*?>.*?<\/.*?>/g, " ").replace(/\s+/g, " ").trim();
882
882
  }
883
- const Qn = ({
884
- onNavigationRequested: p,
885
- agentId: E,
886
- presetUserDetails: w,
887
- onAvatarReady: y
883
+ const Ct = /* @__PURE__ */ new Map(), Xn = ({
884
+ onNavigationRequested: g,
885
+ agentId: y,
886
+ presetUserDetails: S,
887
+ onAvatarReady: L
888
888
  }) => {
889
- const [j, Z] = S(""), [ee, nt] = S("male"), [Be, F] = S(""), [rt, Te] = S(!1), We = j, J = ee;
889
+ const [j, Q] = v(""), [ee, Xe] = v("male"), [Be, U] = v(""), [rt, ve] = v(!1), We = j, G = ee;
890
890
  W(() => {
891
- if (!E) {
892
- Te(!0);
891
+ if (!y) {
892
+ ve(!0);
893
893
  return;
894
894
  }
895
895
  let e = !1;
896
896
  return (async () => {
897
+ console.log(">> fetchConfig RUNNING for", y);
897
898
  try {
898
- const r = { agentId: E }, i = await fetch(`${tt}/visitedWebsite`, {
899
- method: "POST",
900
- headers: { "Content-Type": "application/json" },
901
- body: JSON.stringify(r)
902
- });
903
- if (i.ok) {
904
- const t = await i.json();
905
- if (e) return;
906
- t.encryptedAgentToken && Z(t.encryptedAgentToken), t.avatarGender && nt(t.avatarGender), t.agent_id && F(t.agent_id);
899
+ const n = `agent_config_${y}`, i = sessionStorage.getItem(n);
900
+ if (i)
901
+ try {
902
+ const s = JSON.parse(i);
903
+ e || (s.encryptedAgentToken && Q(s.encryptedAgentToken), s.avatarGender && Xe(s.avatarGender), s.agent_id && U(s.agent_id), ve(!0));
904
+ return;
905
+ } catch (s) {
906
+ console.error("Failed to parse cached avatar config:", s), sessionStorage.removeItem(n);
907
+ }
908
+ let t;
909
+ if (Ct.has(y))
910
+ console.log(">> REUSING in-flight fetch for", y), t = await Ct.get(y);
911
+ else {
912
+ const s = (async () => {
913
+ console.log(">> INITIATING visitedWebsite fetch for", y);
914
+ const f = { agentId: y }, w = await fetch(`${nt}/visitedWebsite`, {
915
+ method: "POST",
916
+ headers: { "Content-Type": "application/json" },
917
+ body: JSON.stringify(f)
918
+ });
919
+ if (!w.ok) throw new Error(`Fetch failed: ${w.status}`);
920
+ const k = await w.json();
921
+ return sessionStorage.setItem(n, JSON.stringify(k)), k;
922
+ })();
923
+ Ct.set(y, s), t = await s;
907
924
  }
908
- } catch (r) {
909
- console.error("Failed to fetch avatar config:", r);
925
+ if (e) return;
926
+ t && (t.encryptedAgentToken && Q(t.encryptedAgentToken), t.avatarGender && Xe(t.avatarGender), t.agent_id && U(t.agent_id));
927
+ } catch (n) {
928
+ console.error("Failed to fetch avatar config:", n);
910
929
  } finally {
911
- e || Te(!0);
930
+ e || ve(!0);
912
931
  }
913
932
  })(), () => {
914
933
  e = !0;
915
934
  };
916
- }, [E]);
917
- const Ae = Dn(E ?? Be), [q, se] = S(""), [M, _e] = S(""), [H, b] = S("Ready"), [ae, f] = S(!1), [O, z] = S(!1), [T, I] = S([]), [N, Y] = S(""), Q = a(null), [yt, te] = S(
935
+ }, [y]);
936
+ const Ae = On(y ?? Be), [q, se] = v(""), [M, _e] = v(""), [H, b] = v("Ready"), [ae, m] = v(!1), [O, z] = v(!1), [A, I] = v([]), [F, Y] = v(""), X = c(null), [yt, te] = v(
918
937
  () => typeof window < "u" ? window.matchMedia("(max-width: 480px)").matches : !1
919
938
  );
920
939
  W(() => {
921
- const e = window.matchMedia("(max-width: 480px)"), n = () => te(e.matches);
922
- return e.addEventListener("change", n), () => e.removeEventListener("change", n);
940
+ const e = window.matchMedia("(max-width: 480px)"), r = () => te(e.matches);
941
+ return e.addEventListener("change", r), () => e.removeEventListener("change", r);
923
942
  }, []);
924
- const G = yt ? 80 : 600, V = a(!1), Ee = a([]), Xe = a(0), Ve = a(!1), Me = a([]), we = a(null), Ie = a([]);
925
- a([]);
926
- const ct = a([]), De = a(0), $e = a(0), de = a(0), Oe = a(0), ve = a(!1), [ot, it] = S(
943
+ const J = yt ? 80 : 600, V = c(!1), Ee = c([]), Ze = c(0), Ve = c(!1), Me = c([]), we = c(null), Ie = c([]);
944
+ c([]);
945
+ const ct = c([]), De = c(0), $e = c(0), de = c(0), Oe = c(0), ke = c(!1), [ot, it] = v(
927
946
  null
928
- ), m = a(null), [h, s] = S("neutral"), [o, d] = S(""), [D, ne] = S(""), [St, He] = S("Chat with us"), [re, ut] = S(
947
+ ), p = c(null), [h, a] = v("neutral"), [o, d] = v(""), [D, ne] = v(""), [St, He] = v("Chat with us"), [re, ut] = v(
929
948
  null
930
- ), [Ce, je] = S("hidden"), [L, lt] = S(""), Je = a(null), Ge = a(Ce);
931
- Ge.current = Ce;
932
- const [ht, qe] = S(null), Ue = a(null), fe = a(null), [ye, Fe] = S(!1), dt = a(null), [oe, ze] = S("hidden"), [ft, Lt] = S(""), Ne = a(oe);
933
- Ne.current = oe;
934
- const k = a(""), ce = a(!1), ue = a(""), Ye = a(Date.now()), ke = a([]), me = a(!1), [_, K] = S(!1), [P, Re] = S(!1), le = a(null), he = Ct(() => ye ? "Try again" : H === "Busy" ? "Busy" : H === "Thinking..." || H === "Processing Voice..." ? H : re != null && re !== "" && re !== "none" && re !== "<none>" ? `Enter ${Kn(re)}` : oe !== "hidden" || !P ? null : nn, [H, re, ye, oe, P]), Ut = !ye && H !== "Busy" && H !== "Thinking..." && H !== "Processing Voice..." && (re == null || re === "" || re === "none" || re === "<none>");
949
+ ), [Ce, je] = v("hidden"), [R, lt] = v(""), Ge = c(null), Je = c(Ce);
950
+ Je.current = Ce;
951
+ const [ht, qe] = v(null), Ue = c(null), fe = c(null), [ye, Ne] = v(!1), dt = c(null), [oe, ze] = v("hidden"), [ft, Lt] = v(""), Fe = c(oe);
952
+ Fe.current = oe;
953
+ const x = c(""), ce = c(!1), ue = c(""), Ye = c(Date.now()), Re = c([]), me = c(!1), [_, K] = v(!1), [P, xe] = v(!1), le = c(null), he = Ut(() => ye ? "Try again" : H === "Busy" ? "Busy" : H === "Thinking..." || H === "Processing Voice..." ? H : re != null && re !== "" && re !== "none" && re !== "<none>" ? `Enter ${Qn(re)}` : oe !== "hidden" || !P ? null : rn, [H, re, ye, oe, P]), Nt = !ye && H !== "Busy" && H !== "Thinking..." && H !== "Processing Voice..." && (re == null || re === "" || re === "none" || re === "<none>");
935
954
  W(() => {
936
- if (oe !== "hidden" || !Ut) {
937
- Re(!1), le.current != null && (clearTimeout(le.current), le.current = null);
955
+ if (oe !== "hidden" || !Nt) {
956
+ xe(!1), le.current != null && (clearTimeout(le.current), le.current = null);
938
957
  return;
939
958
  }
940
959
  return le.current = setTimeout(() => {
941
- le.current = null, Re(!0);
960
+ le.current = null, xe(!0);
942
961
  }, 400), () => {
943
962
  le.current != null && (clearTimeout(le.current), le.current = null);
944
963
  };
945
- }, [oe, Ut]);
964
+ }, [oe, Nt]);
946
965
  const mt = he != null && he !== "";
947
966
  W(() => {
948
- const e = Ge.current;
967
+ const e = Je.current;
949
968
  if (!(e === "exiting" || e === "entering")) {
950
969
  if (e === "hidden") {
951
970
  mt && (lt(he ?? ""), je("entering"));
952
971
  return;
953
972
  }
954
- e === "visible" && (!mt || he !== L) && (Je.current = mt ? he : null, je("exiting"));
973
+ e === "visible" && (!mt || he !== R) && (Ge.current = mt ? he : null, je("exiting"));
955
974
  }
956
975
  }, [
957
976
  mt,
958
977
  he,
959
978
  Ce,
960
- L
979
+ R
961
980
  ]), W(() => {
962
981
  if (H !== "Busy") {
963
982
  fe.current != null && (clearTimeout(fe.current), fe.current = null);
964
983
  return;
965
984
  }
966
985
  return fe.current = setTimeout(() => {
967
- fe.current = null, b("Ready"), Fe(!0);
986
+ fe.current = null, b("Ready"), Ne(!0);
968
987
  }, 12e3), () => {
969
988
  fe.current != null && (clearTimeout(fe.current), fe.current = null);
970
989
  };
971
990
  }, [H]), W(() => {
972
991
  if (!ye) return;
973
- const e = setTimeout(() => Fe(!1), 2500);
992
+ const e = setTimeout(() => Ne(!1), 2500);
974
993
  return () => clearTimeout(e);
975
994
  }, [ye]);
976
- const on = et(() => {
977
- const e = Ge.current;
995
+ const sn = tt(() => {
996
+ const e = Je.current;
978
997
  if (e === "exiting") {
979
998
  je("hidden");
980
- const n = Je.current;
981
- Je.current = null, n != null && n !== "" && (lt(n), je("entering"));
999
+ const r = Ge.current;
1000
+ Ge.current = null, r != null && r !== "" && (lt(r), je("entering"));
982
1001
  } else e === "entering" && je("visible");
983
- }, []), sn = (e) => {
1002
+ }, []), an = (e) => {
984
1003
  if (!e) return;
985
1004
  if (e.mood != null) {
986
1005
  const t = String(e.mood).toLowerCase();
987
- s(t);
1006
+ a(t);
988
1007
  }
989
1008
  if (e.expression != null) {
990
1009
  const t = String(e.expression).trim();
991
1010
  d(t);
992
- const u = Un.find(
993
- (g) => g.name.toLowerCase() === t.toLowerCase()
1011
+ const s = Nn.find(
1012
+ (f) => f.name.toLowerCase() === t.toLowerCase()
994
1013
  );
995
- U(
996
- `[STREAM] Animation match for "${t}": ${u ? u.name : "NONE"}`
997
- ), ne(u?.url ?? "");
1014
+ N(
1015
+ `[STREAM] Animation match for "${t}": ${s ? s.name : "NONE"}`
1016
+ ), ne(s?.url ?? "");
998
1017
  }
999
1018
  if (e.navigation != null) {
1000
1019
  const t = String(e.navigation).trim();
1001
- t !== "" && (p ? p(t) : window.open(t, "_blank"));
1020
+ t !== "" && (g ? g(t) : window.open(t, "_blank"));
1002
1021
  }
1003
- const n = e.ask_for || e.lead_capture?.ask_for, r = n ? String(n).trim().toLowerCase() : "", i = r === "none" || r === "<none>";
1004
- if (n && !i) {
1005
- const t = r;
1006
- if (w && (t === "email" && w.email || t === "name" && w.name || t === "phone" && w.phone))
1022
+ const r = e.ask_for || e.lead_capture?.ask_for, n = r ? String(r).trim().toLowerCase() : "", i = n === "none" || n === "<none>";
1023
+ if (r && !i) {
1024
+ const t = n;
1025
+ if (S && (t === "email" && S.email || t === "name" && S.name || t === "phone" && S.phone))
1007
1026
  return;
1008
1027
  ut(t || null), He(t === "email" ? "Enter your email" : t === "name" ? "Enter your name" : t === "phone" ? "Enter your phone number" : "Chat with us");
1009
1028
  } else (i || e.ask_for === null || e.lead_capture && e.lead_capture.ask_for === null || e.ask_for === "none") && (ut(null), St !== "Chat with us" && He("Chat with us"));
1010
1029
  e.collected, e.valid;
1011
- }, an = (e) => {
1012
- const n = e.trim();
1013
- if (!n) return null;
1014
- if (n.startsWith("{"))
1030
+ }, cn = (e) => {
1031
+ const r = e.trim();
1032
+ if (!r) return null;
1033
+ if (r.startsWith("{"))
1015
1034
  try {
1016
- return JSON.parse(n);
1035
+ return JSON.parse(r);
1017
1036
  } catch {
1018
1037
  return null;
1019
1038
  }
1020
- if (n.includes(":")) {
1021
- const r = n.split(":"), i = r[0].trim().toLowerCase(), t = r.slice(1).join(":").trim();
1039
+ if (r.includes(":")) {
1040
+ const n = r.split(":"), i = n[0].trim().toLowerCase(), t = n.slice(1).join(":").trim();
1022
1041
  return { [i]: t };
1023
1042
  }
1024
1043
  return null;
1025
- }, cn = et(() => {
1044
+ }, un = tt(() => {
1026
1045
  }, []), Pe = "§", vt = () => {
1027
- for (; k.current.includes(`
1046
+ for (; x.current.includes(`
1028
1047
  `); ) {
1029
- const e = k.current.indexOf(`
1030
- `), n = k.current.slice(0, e).trim();
1031
- k.current = k.current.slice(e + 1);
1032
- const r = an(n);
1033
- r && sn(r);
1048
+ const e = x.current.indexOf(`
1049
+ `), r = x.current.slice(0, e).trim();
1050
+ x.current = x.current.slice(e + 1);
1051
+ const n = cn(r);
1052
+ n && an(n);
1034
1053
  }
1035
1054
  }, Ft = (e) => {
1036
1055
  if (ce.current)
1037
1056
  if (e.includes(Pe)) {
1038
- const n = e.indexOf(Pe), r = e.slice(0, n), i = e.slice(n + Pe.length);
1039
- r && (ue.current += r, _e((t) => t + r)), ce.current = !1, i && (k.current += i, vt());
1040
- } else e === Pe ? ce.current = !1 : (ue.current += e, _e((n) => n + e));
1057
+ const r = e.indexOf(Pe), n = e.slice(0, r), i = e.slice(r + Pe.length);
1058
+ n && (ue.current += n, _e((t) => t + n)), ce.current = !1, i && (x.current += i, vt());
1059
+ } else e === Pe ? ce.current = !1 : (ue.current += e, _e((r) => r + e));
1041
1060
  else if (e.includes(Pe)) {
1042
- const n = e.indexOf(Pe), r = e.slice(0, n), i = e.slice(n + Pe.length);
1043
- k.current += r, vt(), ce.current = !0, i && (ue.current += i, _e((t) => t + i));
1061
+ const r = e.indexOf(Pe), n = e.slice(0, r), i = e.slice(r + Pe.length);
1062
+ x.current += n, vt(), ce.current = !0, i && (ue.current += i, _e((t) => t + i));
1044
1063
  } else if (e === Pe) {
1045
1064
  ce.current = !0;
1046
1065
  return;
1047
1066
  } else
1048
- k.current += e, vt();
1067
+ x.current += e, vt();
1049
1068
  };
1050
1069
  W(() => {
1051
1070
  (async () => {
1052
1071
  if (!sessionStorage.getItem(
1053
1072
  "STREAMOJI_LEADS_SESSION_LEAD_ID"
1054
1073
  )) {
1055
- const t = "secret", u = Math.floor(Date.now() / 1e3).toString();
1074
+ const t = "secret", s = Math.floor(Date.now() / 1e3).toString();
1056
1075
  try {
1057
- const g = new TextEncoder(), v = await crypto.subtle.importKey(
1076
+ const f = new TextEncoder(), w = await crypto.subtle.importKey(
1058
1077
  "raw",
1059
- g.encode(t),
1078
+ f.encode(t),
1060
1079
  { name: "HMAC", hash: "SHA-256" },
1061
1080
  !1,
1062
1081
  ["sign"]
1063
- ), x = await crypto.subtle.sign(
1082
+ ), k = await crypto.subtle.sign(
1064
1083
  "HMAC",
1065
- v,
1066
- g.encode(u)
1067
- ), R = Array.from(new Uint8Array(x)).map((C) => C.toString(16).padStart(2, "0")).join("");
1068
- sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", R), U("[SESSION] New HMAC UID generated and saved:", R);
1069
- } catch (g) {
1070
- console.error("[SESSION] HMAC generation failed:", g);
1071
- const v = Math.random().toString(36) + Date.now().toString();
1072
- sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", v);
1084
+ w,
1085
+ f.encode(s)
1086
+ ), T = Array.from(new Uint8Array(k)).map((C) => C.toString(16).padStart(2, "0")).join("");
1087
+ sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", T), N("[SESSION] New HMAC UID generated and saved:", T);
1088
+ } catch (f) {
1089
+ console.error("[SESSION] HMAC generation failed:", f);
1090
+ const w = Math.random().toString(36) + Date.now().toString();
1091
+ sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", w);
1073
1092
  }
1074
1093
  }
1075
- const r = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES");
1094
+ const n = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES");
1076
1095
  let i = [];
1077
- if (r)
1096
+ if (n)
1078
1097
  try {
1079
- i = JSON.parse(r);
1098
+ i = JSON.parse(n);
1080
1099
  } catch {
1081
1100
  i = [];
1082
1101
  }
1083
- i.length === 0 && w && (w.name || w.email) ? (i = [{ role: "user", content: `PRESET_USER_DETAILS: Name is "${w.name || ""}" , Email is "${w.email || ""}"` }], sessionStorage.setItem(
1102
+ i.length === 0 && S && (S.name || S.email) ? (i = [{ role: "user", content: `PRESET_USER_DETAILS: Name is "${S.name || ""}" , Email is "${S.email || ""}"` }], sessionStorage.setItem(
1084
1103
  "STREAMOJI_LEADS_SESSION_MESSAGES",
1085
1104
  JSON.stringify(i)
1086
- )) : r || sessionStorage.setItem(
1105
+ )) : n || sessionStorage.setItem(
1087
1106
  "STREAMOJI_LEADS_SESSION_MESSAGES",
1088
1107
  JSON.stringify([])
1089
1108
  );
1090
1109
  })();
1091
- }, [w]), W(() => {
1110
+ }, [S]), W(() => {
1092
1111
  const e = () => {
1093
1112
  Ye.current = Date.now(), me.current && (me.current = !1, K(!1), I([]), Y(""), _e(""), z(!1));
1094
1113
  };
1095
1114
  window.addEventListener("mousemove", e), window.addEventListener("keydown", e), window.addEventListener("mousedown", e), window.addEventListener("touchstart", e);
1096
- const n = setInterval(async () => {
1115
+ const r = setInterval(async () => {
1097
1116
  if (Date.now() - Ye.current >= 3e4 && !O && !ae && H === "Ready" && !me.current)
1098
- if (me.current = !0, ke.current.length > 0)
1099
- K(!0), I(ke.current);
1117
+ if (me.current = !0, Re.current.length > 0)
1118
+ K(!0), I(Re.current);
1100
1119
  else
1101
1120
  try {
1102
- const t = `${tt}/nudgeUser`, u = {
1121
+ const t = `${nt}/nudgeUser`, s = {
1103
1122
  navigationUrl: window.location.href,
1104
1123
  token: We
1105
- }, g = await fetch(t, {
1124
+ }, f = await fetch(t, {
1106
1125
  method: "POST",
1107
1126
  headers: {
1108
1127
  "Content-Type": "application/json"
1109
1128
  },
1110
- body: JSON.stringify(u)
1129
+ body: JSON.stringify(s)
1111
1130
  });
1112
- if (g.ok) {
1113
- const x = (await g.json()).nudge_questions;
1114
- x && x.length > 0 && (U("[NUDGE] Received nudge questions from API:", x), ke.current = x, K(!0), I(x));
1131
+ if (f.ok) {
1132
+ const k = (await f.json()).nudge_questions;
1133
+ k && k.length > 0 && (N("[NUDGE] Received nudge questions from API:", k), Re.current = k, K(!0), I(k));
1115
1134
  }
1116
1135
  } catch (t) {
1117
1136
  console.error("[NUDGE] Error calling /nudgeUser:", t), me.current = !1;
1118
1137
  }
1119
1138
  }, 1e3);
1120
1139
  return () => {
1121
- window.removeEventListener("mousemove", e), window.removeEventListener("keydown", e), window.removeEventListener("mousedown", e), window.removeEventListener("touchstart", e), clearInterval(n);
1140
+ window.removeEventListener("mousemove", e), window.removeEventListener("keydown", e), window.removeEventListener("mousedown", e), window.removeEventListener("touchstart", e), clearInterval(r);
1122
1141
  };
1123
1142
  }, [We, O, ae, H]), W(() => {
1124
- if (T.length === 0) return;
1125
- let e = 0, n = 0, r = !1, i = 100;
1143
+ if (A.length === 0) return;
1144
+ let e = 0, r = 0, n = !1, i = 100;
1126
1145
  const t = () => {
1127
- const u = T[e];
1128
- if (r) {
1129
- const g = u.substring(0, n - 1);
1130
- Y(g), n--, i = 50;
1146
+ const s = A[e];
1147
+ if (n) {
1148
+ const f = s.substring(0, r - 1);
1149
+ Y(f), r--, i = 50;
1131
1150
  } else {
1132
- const g = u.substring(0, n + 1);
1133
- Y(g), n++, i = 100;
1151
+ const f = s.substring(0, r + 1);
1152
+ Y(f), r++, i = 100;
1134
1153
  }
1135
- !r && n === u.length ? (r = !0, i = 3e3) : r && n === 0 && (r = !1, e = (e + 1) % T.length, i = 500), Q.current = setTimeout(t, i);
1154
+ !n && r === s.length ? (n = !0, i = 3e3) : n && r === 0 && (n = !1, e = (e + 1) % A.length, i = 500), X.current = setTimeout(t, i);
1136
1155
  };
1137
1156
  return t(), () => {
1138
- Q.current && clearTimeout(Q.current);
1157
+ X.current && clearTimeout(X.current);
1139
1158
  };
1140
- }, [T]);
1141
- const Nt = () => {
1159
+ }, [A]);
1160
+ const Pt = () => {
1142
1161
  try {
1143
1162
  return JSON.parse(
1144
1163
  sessionStorage.getItem("STREAMOJI_LEADS_SESSION_MESSAGES") || "[]"
@@ -1146,99 +1165,99 @@ const Qn = ({
1146
1165
  } catch {
1147
1166
  return [];
1148
1167
  }
1149
- }, un = (e) => {
1168
+ }, ln = (e) => {
1150
1169
  sessionStorage.setItem(
1151
1170
  "STREAMOJI_LEADS_SESSION_MESSAGES",
1152
1171
  JSON.stringify(e)
1153
1172
  );
1154
- }, [kt, Rt] = S(!1), [Pt, xt] = S(0), Se = a(null), pt = a([]), Bt = a(0), [Wt, ln] = S(
1173
+ }, [kt, Rt] = v(!1), [Bt, xt] = v(0), Se = c(null), pt = c([]), Wt = c(0), [Vt, hn] = v(
1155
1174
  null
1156
- ), [hn, Tt] = S(
1175
+ ), [dn, Tt] = v(
1157
1176
  null
1158
- ), xe = a(null), Ke = a(
1177
+ ), Te = c(null), Ke = c(
1159
1178
  null
1160
- ), st = et((e = !1) => {
1161
- e && (ve.current = !0, f(!1), b("Ready")), Me.current = [], Ee.current = [], Ve.current = !1, z(!1), De.current = 0, $e.current = 0, de.current = 0, Ie.current.forEach((n) => {
1179
+ ), st = tt((e = !1) => {
1180
+ e && (ke.current = !0, m(!1), b("Ready")), Me.current = [], Ee.current = [], Ve.current = !1, z(!1), De.current = 0, $e.current = 0, de.current = 0, Ie.current.forEach((r) => {
1162
1181
  try {
1163
- n.stop();
1182
+ r.stop();
1164
1183
  } catch {
1165
1184
  }
1166
1185
  }), Ue.current && (clearTimeout(Ue.current), Ue.current = null), qe(null), ne(""), Ie.current = [];
1167
- }, []), dn = async () => {
1186
+ }, []), fn = async () => {
1168
1187
  try {
1169
- const e = await navigator.mediaDevices.getUserMedia({ audio: !0 }), n = window.AudioContext || window.webkitAudioContext, r = new n(), i = r.createMediaStreamSource(e), t = r.createAnalyser();
1170
- t.fftSize = 64, i.connect(t), xe.current = r, Ke.current = i, Tt(t);
1171
- const u = new MediaRecorder(e);
1172
- Se.current = u, pt.current = [], u.ondataavailable = (g) => {
1173
- g.data.size > 0 && pt.current.push(g.data);
1174
- }, u.onstop = async () => {
1175
- const g = Date.now() - Bt.current;
1176
- if (Tt(null), Ke.current && (Ke.current.disconnect(), Ke.current = null), xe.current && xe.current.state !== "closed" && (xe.current.close(), xe.current = null), g < 1e3) {
1177
- b("Recording too short. Hold or click longer."), f(!1);
1188
+ const e = await navigator.mediaDevices.getUserMedia({ audio: !0 }), r = window.AudioContext || window.webkitAudioContext, n = new r(), i = n.createMediaStreamSource(e), t = n.createAnalyser();
1189
+ t.fftSize = 64, i.connect(t), Te.current = n, Ke.current = i, Tt(t);
1190
+ const s = new MediaRecorder(e);
1191
+ Se.current = s, pt.current = [], s.ondataavailable = (f) => {
1192
+ f.data.size > 0 && pt.current.push(f.data);
1193
+ }, s.onstop = async () => {
1194
+ const f = Date.now() - Wt.current;
1195
+ if (Tt(null), Ke.current && (Ke.current.disconnect(), Ke.current = null), Te.current && Te.current.state !== "closed" && (Te.current.close(), Te.current = null), f < 1e3) {
1196
+ b("Recording too short. Hold or click longer."), m(!1);
1178
1197
  return;
1179
1198
  }
1180
- const v = new Blob(pt.current, {
1199
+ const w = new Blob(pt.current, {
1181
1200
  type: "audio/wav"
1182
1201
  });
1183
- await gn(v);
1184
- }, Bt.current = Date.now(), u.start(100), Rt(!0), b("Listening...");
1202
+ await bn(w);
1203
+ }, Wt.current = Date.now(), s.start(100), Rt(!0), b("Listening...");
1185
1204
  } catch (e) {
1186
1205
  console.error("Error accessing microphone:", e), b("Mic Access Error");
1187
1206
  }
1188
- }, fn = () => {
1189
- Se.current && Se.current.state !== "inactive" && (Se.current.stop(), Se.current.stream.getTracks().forEach((e) => e.stop()), Rt(!1));
1190
1207
  }, mn = () => {
1191
- Se.current && Se.current.state !== "inactive" && (Se.current.onstop = null, Se.current.stop(), Se.current.stream.getTracks().forEach((e) => e.stop()), Tt(null), Ke.current && (Ke.current.disconnect(), Ke.current = null), xe.current && xe.current.state !== "closed" && (xe.current.close(), xe.current = null), Rt(!1), pt.current = [], b("Ready"));
1208
+ Se.current && Se.current.state !== "inactive" && (Se.current.stop(), Se.current.stream.getTracks().forEach((e) => e.stop()), Rt(!1));
1209
+ }, pn = () => {
1210
+ Se.current && Se.current.state !== "inactive" && (Se.current.onstop = null, Se.current.stop(), Se.current.stream.getTracks().forEach((e) => e.stop()), Tt(null), Ke.current && (Ke.current.disconnect(), Ke.current = null), Te.current && Te.current.state !== "closed" && (Te.current.close(), Te.current = null), Rt(!1), pt.current = [], b("Ready"));
1192
1211
  };
1193
1212
  W(() => {
1194
1213
  if (!O) return;
1195
1214
  const e = () => {
1196
- const n = de.current;
1197
- if (n <= 0) return;
1198
- const r = we.current, i = De.current;
1199
- if (!r) return;
1200
- const t = r.currentTime - i, u = Math.min(Math.max(0, t), n), v = rn(M).trim().length;
1201
- if (v <= 0) return;
1202
- const x = Math.min(
1203
- Math.round(u / n * v),
1204
- v
1215
+ const r = de.current;
1216
+ if (r <= 0) return;
1217
+ const n = we.current, i = De.current;
1218
+ if (!n) return;
1219
+ const t = n.currentTime - i, s = Math.min(Math.max(0, t), r), w = on(M).trim().length;
1220
+ if (w <= 0) return;
1221
+ const k = Math.min(
1222
+ Math.round(s / r * w),
1223
+ w
1205
1224
  );
1206
- it(x);
1225
+ it(k);
1207
1226
  };
1208
- return clearInterval(m.current ?? void 0), m.current = setInterval(e, 90), () => clearInterval(m.current ?? void 0);
1227
+ return clearInterval(p.current ?? void 0), p.current = setInterval(e, 90), () => clearInterval(p.current ?? void 0);
1209
1228
  }, [O, M, de.current]), W(() => {
1210
1229
  let e;
1211
1230
  return kt ? (xt(0), e = window.setInterval(() => {
1212
- xt((n) => n + 1);
1231
+ xt((r) => r + 1);
1213
1232
  }, 1e3)) : xt(0), () => clearInterval(e);
1214
1233
  }, [kt]);
1215
- const pn = (e) => {
1216
- const n = e.numberOfChannels, r = e.length * n * 2 + 44, i = new ArrayBuffer(r), t = new DataView(i);
1217
- let u = 0;
1218
- const g = (R) => {
1219
- t.setUint16(u, R, !0), u += 2;
1220
- }, v = (R) => {
1221
- t.setUint32(u, R, !0), u += 4;
1234
+ const gn = (e) => {
1235
+ const r = e.numberOfChannels, n = e.length * r * 2 + 44, i = new ArrayBuffer(n), t = new DataView(i);
1236
+ let s = 0;
1237
+ const f = (T) => {
1238
+ t.setUint16(s, T, !0), s += 2;
1239
+ }, w = (T) => {
1240
+ t.setUint32(s, T, !0), s += 4;
1222
1241
  };
1223
- v(1179011410), v(r - 8), v(1163280727), v(544501094), v(16), g(1), g(n), v(e.sampleRate), v(e.sampleRate * 2 * n), g(n * 2), g(16), v(1635017060), v(r - u - 4);
1224
- const x = [];
1225
- for (let R = 0; R < n; R++) x.push(e.getChannelData(R));
1226
- let A = 0;
1227
- for (; u < r; ) {
1228
- for (let R = 0; R < n; R++) {
1229
- let C = Math.max(-1, Math.min(1, x[R][A]));
1230
- C = C < 0 ? C * 32768 : C * 32767, t.setInt16(u, C, !0), u += 2;
1242
+ w(1179011410), w(n - 8), w(1163280727), w(544501094), w(16), f(1), f(r), w(e.sampleRate), w(e.sampleRate * 2 * r), f(r * 2), f(16), w(1635017060), w(n - s - 4);
1243
+ const k = [];
1244
+ for (let T = 0; T < r; T++) k.push(e.getChannelData(T));
1245
+ let E = 0;
1246
+ for (; s < n; ) {
1247
+ for (let T = 0; T < r; T++) {
1248
+ let C = Math.max(-1, Math.min(1, k[T][E]));
1249
+ C = C < 0 ? C * 32768 : C * 32767, t.setInt16(s, C, !0), s += 2;
1231
1250
  }
1232
- A++;
1251
+ E++;
1233
1252
  }
1234
1253
  return new Blob([i], { type: "audio/wav" });
1235
- }, At = async (e, n, r = !1) => {
1236
- if (!ve.current) {
1254
+ }, At = async (e, r, n = !1) => {
1255
+ if (!ke.current) {
1237
1256
  if (V.current) {
1238
1257
  Ee.current.push({
1239
1258
  audio: e,
1240
- visemes: n,
1241
- isNewSegment: r
1259
+ visemes: r,
1260
+ isNewSegment: n
1242
1261
  });
1243
1262
  return;
1244
1263
  }
@@ -1246,54 +1265,54 @@ const Qn = ({
1246
1265
  try {
1247
1266
  const i = window.AudioContext || window.webkitAudioContext, t = we.current ?? new i();
1248
1267
  t.state === "suspended" && await t.resume(), we.current = t;
1249
- const u = window.atob(e), g = new Uint8Array(u.length);
1250
- for (let $ = 0; $ < u.length; $++)
1251
- g[$] = u.charCodeAt($);
1252
- const v = await t.decodeAudioData(g.buffer.slice(0));
1253
- de.current += v.duration;
1254
- const x = t.currentTime;
1255
- let A = $e.current;
1256
- const R = !Ve.current;
1257
- A < x && (A = x + 0.1), $e.current = A + v.duration;
1268
+ const s = window.atob(e), f = new Uint8Array(s.length);
1269
+ for (let $ = 0; $ < s.length; $++)
1270
+ f[$] = s.charCodeAt($);
1271
+ const w = await t.decodeAudioData(f.buffer.slice(0));
1272
+ de.current += w.duration;
1273
+ const k = t.currentTime;
1274
+ let E = $e.current;
1275
+ const T = !Ve.current;
1276
+ E < k && (E = k + 0.1), $e.current = E + w.duration;
1258
1277
  const C = t.createBufferSource();
1259
- C.buffer = v;
1260
- let X = Wt;
1261
- if ((!X || X.context !== t) && (X = t.createAnalyser(), X.fftSize = 64, X.connect(t.destination), ln(X)), C.connect(X), Ie.current.push(C), ve.current) {
1278
+ C.buffer = w;
1279
+ let Z = Vt;
1280
+ if ((!Z || Z.context !== t) && (Z = t.createAnalyser(), Z.fftSize = 64, Z.connect(t.destination), hn(Z)), C.connect(Z), Ie.current.push(C), ke.current) {
1262
1281
  Ie.current = Ie.current.filter(($) => $ !== C);
1263
1282
  return;
1264
1283
  }
1265
- if (R) {
1266
- Ve.current = !0, z(!0), U(
1267
- `[AUDIO] setIsSpeaking(true) - First chunk starting at ${A.toFixed(
1284
+ if (T) {
1285
+ Ve.current = !0, z(!0), N(
1286
+ `[AUDIO] setIsSpeaking(true) - First chunk starting at ${E.toFixed(
1268
1287
  3
1269
1288
  )}`
1270
- ), De.current = A;
1271
- const $ = (A - x) * 1e3;
1272
- Xe.current = performance.now() + $, U(
1273
- `[AUDIO] Response started. Initial startTime: ${A.toFixed(
1289
+ ), De.current = E;
1290
+ const $ = (E - k) * 1e3;
1291
+ Ze.current = performance.now() + $, N(
1292
+ `[AUDIO] Response started. Initial startTime: ${E.toFixed(
1274
1293
  3
1275
- )}, CT: ${x.toFixed(3)}`
1294
+ )}, CT: ${k.toFixed(3)}`
1276
1295
  );
1277
1296
  }
1278
- C.start(A);
1279
- const ie = (A - De.current) * 1e3;
1280
- r && (Oe.current = ie, U(
1297
+ C.start(E);
1298
+ const ie = (E - De.current) * 1e3;
1299
+ n && (Oe.current = ie, N(
1281
1300
  `[AUDIO] New segment detected at +${ie.toFixed(
1282
1301
  0
1283
1302
  )}ms. Resetting segment offset.`
1284
- )), n.forEach(($, pe) => {
1303
+ )), r.forEach(($, pe) => {
1285
1304
  const B = $.symbol ?? "";
1286
1305
  if (B) {
1287
- const ge = qn(B), Le = Math.round($.start * 1e3), Qe = Math.round(($.duration ?? 0) * 1e3), Gt = Oe.current + Le;
1288
- pe < 3 && U(
1306
+ const ge = zn(B), Le = Math.round($.start * 1e3), Qe = Math.round(($.duration ?? 0) * 1e3), qt = Oe.current + Le;
1307
+ pe < 3 && N(
1289
1308
  `[AUDIO] Viseme "${B}": segment_relative=${Le}ms, segment_offset=${Oe.current.toFixed(
1290
1309
  0
1291
- )}ms => vtime=${Gt}ms`
1292
- ), ge.forEach((qt) => {
1310
+ )}ms => vtime=${qt}ms`
1311
+ ), ge.forEach((zt) => {
1293
1312
  Me.current.push({
1294
- viseme: qt.v,
1295
- weight: qt.w,
1296
- vtime: Gt,
1313
+ viseme: zt.v,
1314
+ weight: zt.w,
1315
+ vtime: qt,
1297
1316
  vduration: Qe
1298
1317
  });
1299
1318
  });
@@ -1306,35 +1325,35 @@ const Qn = ({
1306
1325
  }
1307
1326
  }
1308
1327
  }
1309
- }, gn = async (e) => {
1328
+ }, bn = async (e) => {
1310
1329
  try {
1311
- f(!0), K(!1), ue.current = "", _e(""), b("Processing Voice...");
1312
- const n = await e.arrayBuffer(), i = await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(n), t = pn(i), u = new FileReader();
1313
- u.readAsDataURL(t), u.onloadend = async () => {
1314
- const g = u.result.split(",")[1];
1315
- st(), se(""), k.current = "", ce.current = !1;
1316
- const v = `${tt}/stt?token=${encodeURIComponent(
1330
+ m(!0), K(!1), ue.current = "", _e(""), b("Processing Voice...");
1331
+ const r = await e.arrayBuffer(), i = await new (window.AudioContext || window.webkitAudioContext)().decodeAudioData(r), t = gn(i), s = new FileReader();
1332
+ s.readAsDataURL(t), s.onloadend = async () => {
1333
+ const f = s.result.split(",")[1];
1334
+ st(), se(""), x.current = "", ce.current = !1;
1335
+ const w = `${nt}/stt?token=${encodeURIComponent(
1317
1336
  We
1318
- )}`, x = await fetch(v, {
1337
+ )}`, k = await fetch(w, {
1319
1338
  method: "POST",
1320
1339
  headers: { "Content-Type": "application/json" },
1321
1340
  body: JSON.stringify({
1322
- audio_base64: g,
1341
+ audio_base64: f,
1323
1342
  audio_format: "wav",
1324
- agentId: E
1343
+ agentId: y
1325
1344
  })
1326
1345
  });
1327
- if (x.status === 429) {
1346
+ if (k.status === 429) {
1328
1347
  try {
1329
- const pe = await x.text(), B = JSON.parse(pe);
1330
- U("[STT] 429 agent at capacity:", B?.detail);
1348
+ const pe = await k.text(), B = JSON.parse(pe);
1349
+ N("[STT] 429 agent at capacity:", B?.detail);
1331
1350
  } catch {
1332
1351
  }
1333
- se(""), b("Busy"), f(!1);
1352
+ se(""), b("Busy"), m(!1);
1334
1353
  return;
1335
1354
  }
1336
- if (!x.ok) {
1337
- const pe = await x.text();
1355
+ if (!k.ok) {
1356
+ const pe = await k.text();
1338
1357
  let B = "STT Failed";
1339
1358
  try {
1340
1359
  B = JSON.parse(pe).error || B;
@@ -1343,15 +1362,15 @@ const Qn = ({
1343
1362
  }
1344
1363
  throw new Error(B);
1345
1364
  }
1346
- const A = x.body;
1347
- if (U("this is body" + A), !A) {
1348
- b("STT Failed"), f(!1);
1365
+ const E = k.body;
1366
+ if (N("this is body" + E), !E) {
1367
+ b("STT Failed"), m(!1);
1349
1368
  return;
1350
1369
  }
1351
- const R = A.getReader();
1352
- ve.current = !1;
1370
+ const T = E.getReader();
1371
+ ke.current = !1;
1353
1372
  const C = new TextDecoder();
1354
- let X = "", ie = !1;
1373
+ let Z = "", ie = !1;
1355
1374
  const $ = async (pe, B) => {
1356
1375
  switch (pe) {
1357
1376
  case "transcript":
@@ -1368,11 +1387,11 @@ const Qn = ({
1368
1387
  break;
1369
1388
  }
1370
1389
  case "done": {
1371
- ie = !0, b("Ready"), f(!1);
1390
+ ie = !0, b("Ready"), m(!1);
1372
1391
  break;
1373
1392
  }
1374
1393
  case "error": {
1375
- ie = !0, b("STT Failed"), f(!1);
1394
+ ie = !0, b("STT Failed"), m(!1);
1376
1395
  break;
1377
1396
  }
1378
1397
  default:
@@ -1380,37 +1399,37 @@ const Qn = ({
1380
1399
  }
1381
1400
  };
1382
1401
  for (; ; ) {
1383
- const { done: pe, value: B } = await R.read();
1384
- B && (X += C.decode(B, { stream: !0 }));
1385
- const ge = X.split(`
1402
+ const { done: pe, value: B } = await T.read();
1403
+ B && (Z += C.decode(B, { stream: !0 }));
1404
+ const ge = Z.split(`
1386
1405
 
1387
1406
  `);
1388
- X = ge.pop() ?? "";
1407
+ Z = ge.pop() ?? "";
1389
1408
  for (const Le of ge) {
1390
- const Qe = Ze(Le);
1409
+ const Qe = et(Le);
1391
1410
  Qe && await $(Qe.event, Qe.data);
1392
1411
  }
1393
1412
  if (pe) {
1394
- if (X.trim()) {
1395
- const Le = Ze(X.trim());
1413
+ if (Z.trim()) {
1414
+ const Le = et(Z.trim());
1396
1415
  Le && await $(Le.event, Le.data);
1397
1416
  }
1398
- ie || (b("Ready"), f(!1));
1417
+ ie || (b("Ready"), m(!1));
1399
1418
  break;
1400
1419
  }
1401
1420
  }
1402
1421
  };
1403
- } catch (n) {
1404
- console.error("Audio Submission Error:", n), b("STT Failed"), f(!1);
1422
+ } catch (r) {
1423
+ console.error("Audio Submission Error:", r), b("STT Failed"), m(!1);
1405
1424
  }
1406
- }, bn = async (e) => {
1407
- e && e.preventDefault(), K(!1), ue.current = "", _e(""), !(!q || ae) && await _n(q);
1408
- }, Ze = (e) => {
1409
- const n = e.split(/\r?\n/);
1410
- let r = "", i = "";
1411
- for (const u of n)
1412
- u.startsWith("event:") ? r = u.slice(6).trim() : u.startsWith("data:") && (i = u.slice(5).trim());
1413
- if (!r) return null;
1425
+ }, _n = async (e) => {
1426
+ e && e.preventDefault(), K(!1), ue.current = "", _e(""), !(!q || ae) && await wn(q);
1427
+ }, et = (e) => {
1428
+ const r = e.split(/\r?\n/);
1429
+ let n = "", i = "";
1430
+ for (const s of r)
1431
+ s.startsWith("event:") ? n = s.slice(6).trim() : s.startsWith("data:") && (i = s.slice(5).trim());
1432
+ if (!n) return null;
1414
1433
  let t = {};
1415
1434
  if (i)
1416
1435
  try {
@@ -1418,111 +1437,111 @@ const Qn = ({
1418
1437
  } catch {
1419
1438
  t = { raw: i };
1420
1439
  }
1421
- return { event: r, data: t };
1422
- }, gt = (e, n) => {
1440
+ return { event: n, data: t };
1441
+ }, gt = (e, r) => {
1423
1442
  switch (e) {
1424
1443
  case "connected":
1425
- k.current = "", ce.current = !1;
1444
+ x.current = "", ce.current = !1;
1426
1445
  break;
1427
1446
  case "text": {
1428
- const r = n.delta ?? "";
1429
- r && Ft(r);
1447
+ const n = r.delta ?? "";
1448
+ n && Ft(n);
1430
1449
  break;
1431
1450
  }
1432
1451
  case "audio": {
1433
- const r = n.chunk, i = n.visemes ?? [];
1434
- r && At(r, i);
1452
+ const n = r.chunk, i = r.visemes ?? [];
1453
+ n && At(n, i);
1435
1454
  break;
1436
1455
  }
1437
1456
  case "done": {
1438
- const r = Nt(), i = ue.current.trim(), t = [
1439
- ...r,
1457
+ const n = Pt(), i = ue.current.trim(), t = [
1458
+ ...n,
1440
1459
  { role: "user", content: q || "..." },
1441
1460
  { role: "assistant", content: i }
1442
1461
  ];
1443
- un(t), ct.current = [...Me.current], b("Ready"), f(!1), se("");
1462
+ ln(t), ct.current = [...Me.current], b("Ready"), m(!1), se("");
1444
1463
  break;
1445
1464
  }
1446
1465
  case "error": {
1447
- const r = n.message ?? "Unknown error";
1448
- ue.current = r, _e(r), b("Agent Failed"), f(!1);
1466
+ const n = r.message ?? "Unknown error";
1467
+ ue.current = n, _e(n), b("Agent Failed"), m(!1);
1449
1468
  break;
1450
1469
  }
1451
1470
  }
1452
- }, Vt = async (e, n) => {
1453
- f(!0), b("Thinking..."), ue.current = "", k.current = "", ce.current = !1, st(), de.current = 0, it(0);
1471
+ }, $t = async (e, r) => {
1472
+ m(!0), b("Thinking..."), ue.current = "", x.current = "", ce.current = !1, st(), de.current = 0, it(0);
1454
1473
  try {
1455
- const r = await fetch(e, {
1474
+ const n = await fetch(e, {
1456
1475
  method: "POST",
1457
1476
  headers: { "Content-Type": "application/json" },
1458
- body: JSON.stringify(n)
1477
+ body: JSON.stringify(r)
1459
1478
  });
1460
- if (r.status === 429) {
1461
- b("Busy"), f(!1);
1479
+ if (n.status === 429) {
1480
+ b("Busy"), m(!1);
1462
1481
  return;
1463
1482
  }
1464
- if (!r.ok) throw new Error("Request failed");
1465
- const i = r.body;
1483
+ if (!n.ok) throw new Error("Request failed");
1484
+ const i = n.body;
1466
1485
  if (!i) {
1467
- b("Failed"), f(!1);
1486
+ b("Failed"), m(!1);
1468
1487
  return;
1469
1488
  }
1470
1489
  const t = i.getReader();
1471
- ve.current = !1;
1472
- const u = new TextDecoder();
1473
- let g = "";
1490
+ ke.current = !1;
1491
+ const s = new TextDecoder();
1492
+ let f = "";
1474
1493
  for (; ; ) {
1475
- const { done: v, value: x } = await t.read();
1476
- x && (g += u.decode(x, { stream: !0 }));
1477
- const A = g.split(`
1494
+ const { done: w, value: k } = await t.read();
1495
+ k && (f += s.decode(k, { stream: !0 }));
1496
+ const E = f.split(`
1478
1497
 
1479
1498
  `);
1480
- g = A.pop() ?? "";
1481
- for (const R of A) {
1482
- const C = Ze(R);
1499
+ f = E.pop() ?? "";
1500
+ for (const T of E) {
1501
+ const C = et(T);
1483
1502
  C && gt(C.event, C.data);
1484
1503
  }
1485
- if (v) {
1486
- if (g.trim()) {
1487
- const R = Ze(g.trim());
1488
- R && gt(R.event, R.data);
1504
+ if (w) {
1505
+ if (f.trim()) {
1506
+ const T = et(f.trim());
1507
+ T && gt(T.event, T.data);
1489
1508
  }
1490
- b("Ready"), f(!1);
1509
+ b("Ready"), m(!1);
1491
1510
  break;
1492
1511
  }
1493
1512
  }
1494
- } catch (r) {
1495
- console.error("Streaming Error:", r), b("Failed"), f(!1);
1513
+ } catch (n) {
1514
+ console.error("Streaming Error:", n), b("Failed"), m(!1);
1496
1515
  }
1497
- }, $t = et(async (e, n, r) => {
1498
- const i = `${tt}/avatar_tts`;
1499
- await Vt(i, { text: e, userQuery: n, llmPrompt: r });
1500
- }, []), Ht = et(async (e, n, r, i) => {
1501
- const t = `${tt}/avatar_ttsWithKnowledge`;
1502
- await Vt(t, { userQuery: e, llmPrompt: n, knowledge: r, history: i });
1503
- }, []), jt = a(!1);
1516
+ }, Ht = tt(async (e, r, n) => {
1517
+ const i = `${nt}/avatar_tts`;
1518
+ await $t(i, { text: e, userQuery: r, llmPrompt: n });
1519
+ }, []), jt = tt(async (e, r, n, i) => {
1520
+ const t = `${nt}/avatar_ttsWithKnowledge`;
1521
+ await $t(t, { userQuery: e, llmPrompt: r, knowledge: n, history: i });
1522
+ }, []), Gt = c(!1);
1504
1523
  W(() => {
1505
- y && !jt.current && (y({ avatarSpeak: $t, avatarRespond: Ht }), jt.current = !0);
1506
- }, [y, $t, Ht]);
1507
- const _n = async (e) => {
1508
- f(!0), b("Thinking..."), ue.current = "", k.current = "", ce.current = !1, st(), de.current = 0, it(0);
1509
- const n = `${tt}/agent/chat?token=${encodeURIComponent(
1524
+ L && !Gt.current && (L({ avatarSpeak: Ht, avatarRespond: jt }), Gt.current = !0);
1525
+ }, [L, Ht, jt]);
1526
+ const wn = async (e) => {
1527
+ m(!0), b("Thinking..."), ue.current = "", x.current = "", ce.current = !1, st(), de.current = 0, it(0);
1528
+ const r = `${nt}/agent/chat?token=${encodeURIComponent(
1510
1529
  We
1511
1530
  )}`;
1512
1531
  try {
1513
- const r = Nt();
1532
+ const n = Pt();
1514
1533
  let i = sessionStorage.getItem("STREAMOJI_LEADS_SESSION_LEAD_ID");
1515
- i || (Mn(
1534
+ i || (In(
1516
1535
  "[CHAT] Session UID missing at send time! Generating emergency backup."
1517
1536
  ), i = "emergency-" + Math.random().toString(36).substring(7), sessionStorage.setItem("STREAMOJI_LEADS_SESSION_LEAD_ID", i));
1518
1537
  const t = {
1519
- history: r,
1538
+ history: n,
1520
1539
  question: e,
1521
1540
  lead_id: i,
1522
- agentId: E
1541
+ agentId: y
1523
1542
  };
1524
- U("[CHAT] Sending payload:", t);
1525
- const u = await fetch(n, {
1543
+ N("[CHAT] Sending payload:", t);
1544
+ const s = await fetch(r, {
1526
1545
  method: "POST",
1527
1546
  headers: {
1528
1547
  "Content-Type": "application/json"
@@ -1530,77 +1549,77 @@ const Qn = ({
1530
1549
  body: JSON.stringify(t),
1531
1550
  cache: "default"
1532
1551
  });
1533
- if (u.status === 429) {
1552
+ if (s.status === 429) {
1534
1553
  try {
1535
- const R = await u.json();
1536
- U("[CHAT] 429 agent at capacity:", R?.detail);
1554
+ const T = await s.json();
1555
+ N("[CHAT] 429 agent at capacity:", T?.detail);
1537
1556
  } catch {
1538
1557
  }
1539
- se(""), b("Busy"), f(!1);
1558
+ se(""), b("Busy"), m(!1);
1540
1559
  return;
1541
1560
  }
1542
- if (!u.ok)
1561
+ if (!s.ok)
1543
1562
  throw new Error("Agent request failed");
1544
- const g = u.body;
1545
- if (!g) {
1546
- b("Agent Failed"), f(!1);
1563
+ const f = s.body;
1564
+ if (!f) {
1565
+ b("Agent Failed"), m(!1);
1547
1566
  return;
1548
1567
  }
1549
- const v = g.getReader();
1550
- ve.current = !1;
1551
- const x = new TextDecoder();
1552
- let A = "";
1568
+ const w = f.getReader();
1569
+ ke.current = !1;
1570
+ const k = new TextDecoder();
1571
+ let E = "";
1553
1572
  for (; ; ) {
1554
- const { done: R, value: C } = await v.read();
1555
- U(
1556
- `[SSE] Chunk received. done=${R}, length=${C?.length || 0}`
1557
- ), C && (A += x.decode(C, { stream: !0 }));
1558
- const X = A.split(`
1573
+ const { done: T, value: C } = await w.read();
1574
+ N(
1575
+ `[SSE] Chunk received. done=${T}, length=${C?.length || 0}`
1576
+ ), C && (E += k.decode(C, { stream: !0 }));
1577
+ const Z = E.split(`
1559
1578
 
1560
1579
  `);
1561
- A = X.pop() ?? "";
1562
- for (const ie of X) {
1563
- U(`[SSE] Processing block: ${ie.slice(0, 50)}...`);
1564
- const $ = Ze(ie);
1565
- $ && (U(`[SSE] Event: ${$.event}`), gt($.event, $.data));
1580
+ E = Z.pop() ?? "";
1581
+ for (const ie of Z) {
1582
+ N(`[SSE] Processing block: ${ie.slice(0, 50)}...`);
1583
+ const $ = et(ie);
1584
+ $ && (N(`[SSE] Event: ${$.event}`), gt($.event, $.data));
1566
1585
  }
1567
- if (R) {
1568
- if (U("[SSE] Stream finished"), A.trim()) {
1569
- const ie = Ze(A.trim());
1586
+ if (T) {
1587
+ if (N("[SSE] Stream finished"), E.trim()) {
1588
+ const ie = et(E.trim());
1570
1589
  ie && gt(ie.event, ie.data);
1571
1590
  }
1572
- b("Ready"), f(!1), se("");
1591
+ b("Ready"), m(!1), se("");
1573
1592
  break;
1574
1593
  }
1575
1594
  }
1576
- } catch (r) {
1577
- console.error("Chat Error:", r), b("Agent Failed"), f(!1);
1595
+ } catch (n) {
1596
+ console.error("Chat Error:", n), b("Agent Failed"), m(!1);
1578
1597
  }
1579
- }, wn = M.trim(), Jt = rn(wn), Et = Jt && O ? Jt.slice(
1598
+ }, yn = M.trim(), Jt = on(yn), Et = Jt && O ? Jt.slice(
1580
1599
  0,
1581
1600
  ot != null && ot > 0 ? ot : 0
1582
1601
  ) : "";
1583
1602
  W(() => {
1584
- const e = Ne.current;
1603
+ const e = Fe.current;
1585
1604
  e !== "exiting" && (Et ? (Lt(Et), e === "hidden" && ze("entering")) : (e === "visible" || e === "entering") && ze("exiting"));
1586
1605
  }, [Et, oe]);
1587
- const yn = et(() => {
1588
- const e = Ne.current;
1606
+ const Sn = tt(() => {
1607
+ const e = Fe.current;
1589
1608
  e === "entering" ? ze("visible") : e === "exiting" && ze("hidden");
1590
1609
  }, []);
1591
- Tn(() => {
1610
+ An(() => {
1592
1611
  const e = dt.current;
1593
1612
  e && (e.scrollTop = e.scrollHeight);
1594
1613
  }, [ft]);
1595
- const Sn = J === "female" ? Wn : Bn;
1614
+ const Ln = G === "female" ? Vn : Wn;
1596
1615
  return rt ? /* @__PURE__ */ be("div", { className: "avatar-widget-container", children: [
1597
1616
  /* @__PURE__ */ be("div", { className: "avatar-input-area", children: [
1598
1617
  Ce !== "hidden" ? /* @__PURE__ */ l(
1599
1618
  "div",
1600
1619
  {
1601
1620
  className: `avatar-thinking-tab${Ce === "exiting" ? " avatar-thinking-tab--exiting" : Ce === "entering" ? " avatar-thinking-tab--entering" : ""}`,
1602
- onAnimationEnd: on,
1603
- children: L === nn ? /* @__PURE__ */ l(
1621
+ onAnimationEnd: sn,
1622
+ children: R === rn ? /* @__PURE__ */ l(
1604
1623
  "a",
1605
1624
  {
1606
1625
  href: "https://leads.streamoji.com",
@@ -1608,7 +1627,7 @@ const Qn = ({
1608
1627
  rel: "noopener noreferrer",
1609
1628
  children: "Made by Streamoji Leads"
1610
1629
  }
1611
- ) : L
1630
+ ) : R
1612
1631
  }
1613
1632
  ) : null,
1614
1633
  /* @__PURE__ */ l("div", { className: "avatar-input-container", children: /* @__PURE__ */ l(
@@ -1626,7 +1645,7 @@ const Qn = ({
1626
1645
  {
1627
1646
  type: "button",
1628
1647
  className: "avatar-recording-cancel",
1629
- onClick: mn,
1648
+ onClick: pn,
1630
1649
  title: "Cancel",
1631
1650
  children: /* @__PURE__ */ be(
1632
1651
  "svg",
@@ -1660,7 +1679,7 @@ const Qn = ({
1660
1679
  minWidth: 0
1661
1680
  },
1662
1681
  children: [
1663
- /* @__PURE__ */ l("div", { style: { flex: 1, height: "100%" }, children: /* @__PURE__ */ l(zt, { analyser: hn }) }),
1682
+ /* @__PURE__ */ l("div", { style: { flex: 1, height: "100%" }, children: /* @__PURE__ */ l(Yt, { analyser: dn }) }),
1664
1683
  /* @__PURE__ */ be(
1665
1684
  "span",
1666
1685
  {
@@ -1674,9 +1693,9 @@ const Qn = ({
1674
1693
  fontVariantNumeric: "tabular-nums"
1675
1694
  },
1676
1695
  children: [
1677
- Math.floor(Pt / 60),
1696
+ Math.floor(Bt / 60),
1678
1697
  ":",
1679
- String(Pt % 60).padStart(2, "0")
1698
+ String(Bt % 60).padStart(2, "0")
1680
1699
  ]
1681
1700
  }
1682
1701
  )
@@ -1688,7 +1707,7 @@ const Qn = ({
1688
1707
  {
1689
1708
  type: "button",
1690
1709
  className: "avatar-recording-confirm",
1691
- onClick: fn,
1710
+ onClick: mn,
1692
1711
  title: "Send",
1693
1712
  children: /* @__PURE__ */ l(
1694
1713
  "svg",
@@ -1718,7 +1737,7 @@ const Qn = ({
1718
1737
  alignItems: "center",
1719
1738
  paddingRight: "8px"
1720
1739
  },
1721
- children: /* @__PURE__ */ l(zt, { analyser: Wt })
1740
+ children: /* @__PURE__ */ l(Yt, { analyser: Vt })
1722
1741
  }
1723
1742
  ),
1724
1743
  /* @__PURE__ */ l(
@@ -1746,7 +1765,7 @@ const Qn = ({
1746
1765
  ) : /* @__PURE__ */ be(
1747
1766
  "form",
1748
1767
  {
1749
- onSubmit: bn,
1768
+ onSubmit: _n,
1750
1769
  style: {
1751
1770
  flex: 1,
1752
1771
  display: "flex",
@@ -1761,7 +1780,7 @@ const Qn = ({
1761
1780
  type: "text",
1762
1781
  value: q,
1763
1782
  onChange: (e) => se(e.target.value),
1764
- placeholder: H === "Busy" ? "Assisting another user" : N || "Ask me anything",
1783
+ placeholder: H === "Busy" ? "Assisting another user" : F || "Ask me anything",
1765
1784
  disabled: ae || H === "Busy",
1766
1785
  autoComplete: "off",
1767
1786
  style: { width: "100%", height: "100%" }
@@ -1799,7 +1818,7 @@ const Qn = ({
1799
1818
  {
1800
1819
  type: "button",
1801
1820
  className: "mic-button",
1802
- onClick: dn,
1821
+ onClick: fn,
1803
1822
  disabled: ae,
1804
1823
  style: { backgroundColor: "#1e4a5e" },
1805
1824
  children: /* @__PURE__ */ be(
@@ -1870,7 +1889,7 @@ const Qn = ({
1870
1889
  "div",
1871
1890
  {
1872
1891
  className: `avatar-bubble${oe === "entering" ? " avatar-bubble--entering" : oe === "exiting" ? " avatar-bubble--exiting" : ""}`,
1873
- onAnimationEnd: yn,
1892
+ onAnimationEnd: Sn,
1874
1893
  children: /* @__PURE__ */ l("div", { ref: dt, className: `avatar-bubble__content${_ ? " avatar-bubble__content--nudge" : ""}`, children: ft })
1875
1894
  }
1876
1895
  ),
@@ -1878,9 +1897,9 @@ const Qn = ({
1878
1897
  "div",
1879
1898
  {
1880
1899
  className: "avatar-canvas-layer",
1881
- style: { width: G, height: G },
1900
+ style: { width: J, height: J },
1882
1901
  children: /* @__PURE__ */ be(
1883
- kn,
1902
+ Rn,
1884
1903
  {
1885
1904
  shadows: !0,
1886
1905
  camera: { position: [0.2, 1.4, 3], fov: 42 },
@@ -1888,19 +1907,19 @@ const Qn = ({
1888
1907
  dpr: 1.8,
1889
1908
  style: { pointerEvents: "none", width: "100%", height: "100%" },
1890
1909
  children: [
1891
- /* @__PURE__ */ l(zn, { target: Sn }),
1910
+ /* @__PURE__ */ l(Yn, { target: Ln }),
1892
1911
  /* @__PURE__ */ l("ambientLight", { intensity: 0.7 }),
1893
1912
  /* @__PURE__ */ l("directionalLight", { position: [0, 2, 2], intensity: 1 }),
1894
- /* @__PURE__ */ l(Ln, { preset: "city" }),
1895
- /* @__PURE__ */ l(An, { fallback: null, children: Ae !== null && /* @__PURE__ */ l(
1896
- Yn,
1913
+ /* @__PURE__ */ l(vn, { preset: "city" }),
1914
+ /* @__PURE__ */ l(En, { fallback: null, children: Ae !== null && /* @__PURE__ */ l(
1915
+ Kn,
1897
1916
  {
1898
1917
  avatarUrl: Ae,
1899
1918
  isPlayingRef: Ve,
1900
1919
  visemeQueueRef: Me,
1901
1920
  audioContextRef: we,
1902
1921
  responseAudioStartTimeRef: De,
1903
- adjustments: Pn,
1922
+ adjustments: Bn,
1904
1923
  mood: h,
1905
1924
  expression: o,
1906
1925
  agentResponse: M,
@@ -1909,9 +1928,9 @@ const Qn = ({
1909
1928
  stopPlayback: st,
1910
1929
  setIsSpeaking: z,
1911
1930
  expressionUrl: D,
1912
- onExpressionFinished: cn,
1931
+ onExpressionFinished: un,
1913
1932
  isNudgeResponse: _,
1914
- avatarGender: J
1933
+ avatarGender: G
1915
1934
  }
1916
1935
  ) })
1917
1936
  ]
@@ -1921,20 +1940,20 @@ const Qn = ({
1921
1940
  )
1922
1941
  ] }) })
1923
1942
  ] }) : null;
1924
- }, rr = ({
1925
- agentId: p,
1926
- onNavigationRequested: E,
1927
- presetUserDetails: w,
1928
- onAvatarReady: y
1943
+ }, or = ({
1944
+ agentId: g,
1945
+ onNavigationRequested: y,
1946
+ presetUserDetails: S,
1947
+ onAvatarReady: L
1929
1948
  }) => /* @__PURE__ */ l(
1930
- Qn,
1949
+ Xn,
1931
1950
  {
1932
- agentId: p,
1933
- onNavigationRequested: E,
1934
- presetUserDetails: w,
1935
- onAvatarReady: y
1951
+ agentId: g,
1952
+ onNavigationRequested: y,
1953
+ presetUserDetails: S,
1954
+ onAvatarReady: L
1936
1955
  }
1937
1956
  );
1938
1957
  export {
1939
- rr as AvatarWidget
1958
+ or as AvatarWidget
1940
1959
  };