@streamoji/avatar-widget 0.5.5 → 0.5.7

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