@streamoji/avatar-widget 0.3.3 → 0.3.4

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