@streamoji/avatar-widget 0.4.1 → 0.4.2

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