@streamoji/avatar-widget 0.3.6 → 0.3.8

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