@flowengage/react-chatbot 6.0.34 → 6.0.40

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.
@@ -506,43 +506,43 @@ var k = (e) => {
506
506
  let l = new ArrayBuffer(t), u = new Uint8Array(l);
507
507
  for (r = 0; r < n; r += 4) a = at[e.charCodeAt(r)], o = at[e.charCodeAt(r + 1)], s = at[e.charCodeAt(r + 2)], c = at[e.charCodeAt(r + 3)], u[i++] = a << 2 | o >> 4, u[i++] = (o & 15) << 4 | s >> 2, u[i++] = (s & 3) << 6 | c & 63;
508
508
  return l;
509
- }, ot = typeof ArrayBuffer == "function", st = (e, t) => {
509
+ }, ot = typeof ArrayBuffer == "function", A = (e, t) => {
510
510
  if (typeof e != "string") return {
511
511
  type: "message",
512
- data: lt(e, t)
512
+ data: ct(e, t)
513
513
  };
514
514
  let n = e.charAt(0);
515
515
  return n === "b" ? {
516
516
  type: "message",
517
- data: ct(e.substring(1), t)
517
+ data: st(e.substring(1), t)
518
518
  } : Je[n] ? e.length > 1 ? {
519
519
  type: Je[n],
520
520
  data: e.substring(1)
521
521
  } : { type: Je[n] } : Ye;
522
- }, ct = (e, t) => ot ? lt(k(e), t) : {
522
+ }, st = (e, t) => ot ? ct(k(e), t) : {
523
523
  base64: !0,
524
524
  data: e
525
- }, lt = (e, t) => {
525
+ }, ct = (e, t) => {
526
526
  switch (t) {
527
527
  case "blob": return e instanceof Blob ? e : new Blob([e]);
528
528
  default: return e instanceof ArrayBuffer ? e : e.buffer;
529
529
  }
530
- }, ut = "", dt = (e, t) => {
530
+ }, lt = "", ut = (e, t) => {
531
531
  let n = e.length, r = Array(n), i = 0;
532
532
  e.forEach((e, a) => {
533
533
  $e(e, !1, (e) => {
534
- r[a] = e, ++i === n && t(r.join(ut));
534
+ r[a] = e, ++i === n && t(r.join(lt));
535
535
  });
536
536
  });
537
- }, ft = (e, t) => {
538
- let n = e.split(ut), r = [];
537
+ }, dt = (e, t) => {
538
+ let n = e.split(lt), r = [];
539
539
  for (let e = 0; e < n.length; e++) {
540
- let i = st(n[e], t);
540
+ let i = A(n[e], t);
541
541
  if (r.push(i), i.type === "error") break;
542
542
  }
543
543
  return r;
544
544
  };
545
- function pt() {
545
+ function ft() {
546
546
  return new TransformStream({ transform(e, t) {
547
547
  rt(e, (n) => {
548
548
  let r = n.length, i;
@@ -560,41 +560,41 @@ function pt() {
560
560
  });
561
561
  } });
562
562
  }
563
- var mt;
564
- function ht(e) {
563
+ var pt;
564
+ function mt(e) {
565
565
  return e.reduce((e, t) => e + t.length, 0);
566
566
  }
567
- function gt(e, t) {
567
+ function ht(e, t) {
568
568
  if (e[0].length === t) return e.shift();
569
569
  let n = new Uint8Array(t), r = 0;
570
570
  for (let i = 0; i < t; i++) n[i] = e[0][r++], r === e[0].length && (e.shift(), r = 0);
571
571
  return e.length && r < e[0].length && (e[0] = e[0].slice(r)), n;
572
572
  }
573
- function _t(e, t) {
574
- mt ||= new TextDecoder();
573
+ function gt(e, t) {
574
+ pt ||= new TextDecoder();
575
575
  let n = [], r = 0, i = -1, a = !1;
576
576
  return new TransformStream({ transform(o, s) {
577
577
  for (n.push(o);;) {
578
578
  if (r === 0) {
579
- if (ht(n) < 1) break;
580
- let e = gt(n, 1);
579
+ if (mt(n) < 1) break;
580
+ let e = ht(n, 1);
581
581
  a = (e[0] & 128) == 128, i = e[0] & 127, r = i < 126 ? 3 : i === 126 ? 1 : 2;
582
582
  } else if (r === 1) {
583
- if (ht(n) < 2) break;
584
- let e = gt(n, 2);
583
+ if (mt(n) < 2) break;
584
+ let e = ht(n, 2);
585
585
  i = new DataView(e.buffer, e.byteOffset, e.length).getUint16(0), r = 3;
586
586
  } else if (r === 2) {
587
- if (ht(n) < 8) break;
588
- let e = gt(n, 8), t = new DataView(e.buffer, e.byteOffset, e.length), a = t.getUint32(0);
587
+ if (mt(n) < 8) break;
588
+ let e = ht(n, 8), t = new DataView(e.buffer, e.byteOffset, e.length), a = t.getUint32(0);
589
589
  if (a > 2 ** 21 - 1) {
590
590
  s.enqueue(Ye);
591
591
  break;
592
592
  }
593
593
  i = a * 2 ** 32 + t.getUint32(4), r = 3;
594
594
  } else {
595
- if (ht(n) < i) break;
596
- let e = gt(n, i);
597
- s.enqueue(st(a ? e : mt.decode(e), t)), r = 0;
595
+ if (mt(n) < i) break;
596
+ let e = ht(n, i);
597
+ s.enqueue(A(a ? e : pt.decode(e), t)), r = 0;
598
598
  }
599
599
  if (i === 0 || i > e) {
600
600
  s.enqueue(Ye);
@@ -605,21 +605,21 @@ function _t(e, t) {
605
605
  }
606
606
  //#endregion
607
607
  //#region node_modules/@socket.io/component-emitter/lib/esm/index.js
608
- function A(e) {
609
- if (e) return vt(e);
608
+ function j(e) {
609
+ if (e) return _t(e);
610
610
  }
611
- function vt(e) {
612
- for (var t in A.prototype) e[t] = A.prototype[t];
611
+ function _t(e) {
612
+ for (var t in j.prototype) e[t] = j.prototype[t];
613
613
  return e;
614
614
  }
615
- A.prototype.on = A.prototype.addEventListener = function(e, t) {
615
+ j.prototype.on = j.prototype.addEventListener = function(e, t) {
616
616
  return this._callbacks = this._callbacks || {}, (this._callbacks["$" + e] = this._callbacks["$" + e] || []).push(t), this;
617
- }, A.prototype.once = function(e, t) {
617
+ }, j.prototype.once = function(e, t) {
618
618
  function n() {
619
619
  this.off(e, n), t.apply(this, arguments);
620
620
  }
621
621
  return n.fn = t, this.on(e, n), this;
622
- }, A.prototype.off = A.prototype.removeListener = A.prototype.removeAllListeners = A.prototype.removeEventListener = function(e, t) {
622
+ }, j.prototype.off = j.prototype.removeListener = j.prototype.removeAllListeners = j.prototype.removeEventListener = function(e, t) {
623
623
  if (this._callbacks = this._callbacks || {}, arguments.length == 0) return this._callbacks = {}, this;
624
624
  var n = this._callbacks["$" + e];
625
625
  if (!n) return this;
@@ -629,7 +629,7 @@ A.prototype.on = A.prototype.addEventListener = function(e, t) {
629
629
  break;
630
630
  }
631
631
  return n.length === 0 && delete this._callbacks["$" + e], this;
632
- }, A.prototype.emit = function(e) {
632
+ }, j.prototype.emit = function(e) {
633
633
  this._callbacks = this._callbacks || {};
634
634
  for (var t = Array(arguments.length - 1), n = this._callbacks["$" + e], r = 1; r < arguments.length; r++) t[r - 1] = arguments[r];
635
635
  if (n) {
@@ -637,22 +637,22 @@ A.prototype.on = A.prototype.addEventListener = function(e, t) {
637
637
  for (var r = 0, i = n.length; r < i; ++r) n[r].apply(this, t);
638
638
  }
639
639
  return this;
640
- }, A.prototype.emitReserved = A.prototype.emit, A.prototype.listeners = function(e) {
640
+ }, j.prototype.emitReserved = j.prototype.emit, j.prototype.listeners = function(e) {
641
641
  return this._callbacks = this._callbacks || {}, this._callbacks["$" + e] || [];
642
- }, A.prototype.hasListeners = function(e) {
642
+ }, j.prototype.hasListeners = function(e) {
643
643
  return !!this.listeners(e).length;
644
644
  };
645
645
  //#endregion
646
646
  //#region node_modules/engine.io-client/build/esm/globals.js
647
- var yt = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0), j = typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), bt = "arraybuffer";
647
+ var vt = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0), yt = typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), bt = "arraybuffer";
648
648
  //#endregion
649
649
  //#region node_modules/engine.io-client/build/esm/util.js
650
650
  function xt(e, ...t) {
651
651
  return t.reduce((t, n) => (e.hasOwnProperty(n) && (t[n] = e[n]), t), {});
652
652
  }
653
- var St = j.setTimeout, Ct = j.clearTimeout;
653
+ var St = yt.setTimeout, Ct = yt.clearTimeout;
654
654
  function wt(e, t) {
655
- t.useNativeTimers ? (e.setTimeoutFn = St.bind(j), e.clearTimeoutFn = Ct.bind(j)) : (e.setTimeoutFn = j.setTimeout.bind(j), e.clearTimeoutFn = j.clearTimeout.bind(j));
655
+ t.useNativeTimers ? (e.setTimeoutFn = St.bind(yt), e.clearTimeoutFn = Ct.bind(yt)) : (e.setTimeoutFn = yt.setTimeout.bind(yt), e.clearTimeoutFn = yt.clearTimeout.bind(yt));
656
656
  }
657
657
  var Tt = 1.33;
658
658
  function Et(e) {
@@ -687,7 +687,7 @@ var jt = class extends Error {
687
687
  constructor(e, t, n) {
688
688
  super(e), this.description = t, this.context = n, this.type = "TransportError";
689
689
  }
690
- }, Mt = class extends A {
690
+ }, Mt = class extends j {
691
691
  constructor(e) {
692
692
  super(), this.writable = !1, wt(this, e), this.opts = e, this.query = e.query, this.socket = e.socket, this.supportsBinary = !e.forceBase64;
693
693
  }
@@ -707,7 +707,7 @@ var jt = class extends Error {
707
707
  this.readyState = "open", this.writable = !0, super.emitReserved("open");
708
708
  }
709
709
  onData(e) {
710
- let t = st(e, this.socket.binaryType);
710
+ let t = A(e, this.socket.binaryType);
711
711
  this.onPacket(t);
712
712
  }
713
713
  onPacket(e) {
@@ -759,7 +759,7 @@ var jt = class extends Error {
759
759
  this._polling = !0, this.doPoll(), this.emitReserved("poll");
760
760
  }
761
761
  onData(e) {
762
- ft(e, this.socket.binaryType).forEach((e) => {
762
+ dt(e, this.socket.binaryType).forEach((e) => {
763
763
  if (this.readyState === "opening" && e.type === "open" && this.onOpen(), e.type === "close") return this.onClose({ description: "transport closed by the server" }), !1;
764
764
  this.onPacket(e);
765
765
  }), this.readyState !== "closed" && (this._polling = !1, this.emitReserved("pollComplete"), this.readyState === "open" && this._poll());
@@ -771,7 +771,7 @@ var jt = class extends Error {
771
771
  this.readyState === "open" ? e() : this.once("open", e);
772
772
  }
773
773
  write(e) {
774
- this.writable = !1, dt(e, (e) => {
774
+ this.writable = !1, ut(e, (e) => {
775
775
  this.doWrite(e, () => {
776
776
  this.writable = !0, this.emitReserved("drain");
777
777
  });
@@ -811,7 +811,7 @@ var Lt = class extends Nt {
811
811
  this.onError("xhr poll error", e, t);
812
812
  }), this.pollXhr = e;
813
813
  }
814
- }, Rt = class e extends A {
814
+ }, Rt = class e extends j {
815
815
  constructor(e, t, n) {
816
816
  super(), this.createRequest = e, wt(this, n), this._opts = n, this._method = n.method || "GET", this._uri = t, this._data = n.data === void 0 ? null : n.data, this._create();
817
817
  }
@@ -870,7 +870,7 @@ var Lt = class extends Nt {
870
870
  if (Rt.requestsCount = 0, Rt.requests = {}, typeof document < "u") {
871
871
  if (typeof attachEvent == "function") attachEvent("onunload", zt);
872
872
  else if (typeof addEventListener == "function") {
873
- let e = "onpagehide" in j ? "pagehide" : "unload";
873
+ let e = "onpagehide" in yt ? "pagehide" : "unload";
874
874
  addEventListener(e, zt, !1);
875
875
  }
876
876
  }
@@ -896,7 +896,7 @@ function Ht(e) {
896
896
  if (typeof XMLHttpRequest < "u" && (!t || Ft)) return new XMLHttpRequest();
897
897
  } catch {}
898
898
  if (!t) try {
899
- return new j[["Active", "Object"].join("X")]("Microsoft.XMLHTTP");
899
+ return new yt[["Active", "Object"].join("X")]("Microsoft.XMLHTTP");
900
900
  } catch {}
901
901
  }
902
902
  //#endregion
@@ -931,7 +931,7 @@ var Ut = typeof navigator < "u" && typeof navigator.product == "string" && navig
931
931
  try {
932
932
  this.doWrite(n, e);
933
933
  } catch {}
934
- r && yt(() => {
934
+ r && vt(() => {
935
935
  this.writable = !0, this.emitReserved("drain");
936
936
  }, this.setTimeoutFn);
937
937
  });
@@ -944,7 +944,7 @@ var Ut = typeof navigator < "u" && typeof navigator.product == "string" && navig
944
944
  let e = this.opts.secure ? "wss" : "ws", t = this.query || {};
945
945
  return this.opts.timestampRequests && (t[this.opts.timestampParam] = Ot()), this.supportsBinary || (t.b64 = 1), this.createUri(e, t);
946
946
  }
947
- }, Gt = j.WebSocket || j.MozWebSocket, Kt = {
947
+ }, Gt = yt.WebSocket || yt.MozWebSocket, Kt = {
948
948
  websocket: class extends Wt {
949
949
  createSocket(e, t, n) {
950
950
  return Ut ? new Gt(e, t, n) : t ? new Gt(e, t) : new Gt(e);
@@ -969,7 +969,7 @@ var Ut = typeof navigator < "u" && typeof navigator.product == "string" && navig
969
969
  this.onError("webtransport error", e);
970
970
  }), this._transport.ready.then(() => {
971
971
  this._transport.createBidirectionalStream().then((e) => {
972
- let t = _t(2 ** 53 - 1, this.socket.binaryType), n = e.readable.pipeThrough(t).getReader(), r = pt();
972
+ let t = gt(2 ** 53 - 1, this.socket.binaryType), n = e.readable.pipeThrough(t).getReader(), r = ft();
973
973
  r.readable.pipeTo(e.writable), this._writer = r.writable.getWriter();
974
974
  let i = () => {
975
975
  n.read().then(({ done: e, value: t }) => {
@@ -987,7 +987,7 @@ var Ut = typeof navigator < "u" && typeof navigator.product == "string" && navig
987
987
  for (let t = 0; t < e.length; t++) {
988
988
  let n = e[t], r = t === e.length - 1;
989
989
  this._writer.write(n).then(() => {
990
- r && yt(() => {
990
+ r && vt(() => {
991
991
  this.writable = !0, this.emitReserved("drain");
992
992
  }, this.setTimeoutFn);
993
993
  });
@@ -1039,7 +1039,7 @@ var Qt = typeof addEventListener == "function" && typeof removeEventListener ==
1039
1039
  Qt && addEventListener("offline", () => {
1040
1040
  $t.forEach((e) => e());
1041
1041
  }, !1);
1042
- var en = class e extends A {
1042
+ var en = class e extends j {
1043
1043
  constructor(e, t) {
1044
1044
  if (super(), this.binaryType = bt, this.writeBuffer = [], this._prevBufferLen = 0, this._pingInterval = -1, this._pingTimeout = -1, this._maxPayload = -1, this._pingTimeoutTime = Infinity, e && typeof e == "object" && (t = e, e = null), e) {
1045
1045
  let n = Yt(e);
@@ -1145,7 +1145,7 @@ var en = class e extends A {
1145
1145
  _hasPingExpired() {
1146
1146
  if (!this._pingTimeoutTime) return !0;
1147
1147
  let e = Date.now() > this._pingTimeoutTime;
1148
- return e && (this._pingTimeoutTime = 0, yt(() => {
1148
+ return e && (this._pingTimeoutTime = 0, vt(() => {
1149
1149
  this._onClose("ping timeout");
1150
1150
  }, this.setTimeoutFn)), e;
1151
1151
  }
@@ -1364,7 +1364,7 @@ var vn = class {
1364
1364
  let t = fn(e), n = this.encodeAsString(t.packet), r = t.buffers;
1365
1365
  return r.unshift(n), r;
1366
1366
  }
1367
- }, yn = class e extends A {
1367
+ }, yn = class e extends j {
1368
1368
  constructor(e) {
1369
1369
  super(), this.opts = Object.assign({
1370
1370
  reviver: void 0,
@@ -1497,7 +1497,7 @@ var On = Object.freeze({
1497
1497
  disconnecting: 1,
1498
1498
  newListener: 1,
1499
1499
  removeListener: 1
1500
- }), kn = class extends A {
1500
+ }), kn = class extends j {
1501
1501
  constructor(e, t, n) {
1502
1502
  super(), this.connected = !1, this.recovered = !1, this.receiveBuffer = [], this.sendBuffer = [], this._queue = [], this._queueSeq = 0, this.ids = 0, this.acks = {}, this.flags = {}, this.io = e, this.nsp = t, n && n.auth && (this.auth = n.auth), this._opts = Object.assign({}, n), this.io._autoConnect && this.open();
1503
1503
  }
@@ -1750,7 +1750,7 @@ An.prototype.duration = function() {
1750
1750
  };
1751
1751
  //#endregion
1752
1752
  //#region node_modules/socket.io-client/build/esm/manager.js
1753
- var jn = class extends A {
1753
+ var jn = class extends j {
1754
1754
  constructor(e, t) {
1755
1755
  super(), this.nsps = {}, this.subs = [], e && typeof e == "object" && (t = e, e = void 0), t ||= {}, t.path = t.path || "/socket.io", this.opts = t, wt(this, t), this.reconnection(t.reconnection !== !1), this.reconnectionAttempts(t.reconnectionAttempts || Infinity), this.reconnectionDelay(t.reconnectionDelay || 1e3), this.reconnectionDelayMax(t.reconnectionDelayMax || 5e3), this.randomizationFactor(t.randomizationFactor ?? .5), this.backoff = new An({
1756
1756
  min: this.reconnectionDelay(),
@@ -1823,7 +1823,7 @@ var jn = class extends A {
1823
1823
  }
1824
1824
  }
1825
1825
  ondecoded(e) {
1826
- yt(() => {
1826
+ vt(() => {
1827
1827
  this.emitReserved("packet", e);
1828
1828
  }, this.setTimeoutFn);
1829
1829
  }
@@ -2118,11 +2118,14 @@ function er() {
2118
2118
  if (window.ng?.getComponent || document.querySelector("[ng-version]")) return "angular";
2119
2119
  if (window.__sveltekit_data || document.querySelector("[data-sveltekit-hydrate]")) return "sveltekit";
2120
2120
  if (document.querySelector("[data-astro-transition]")) return "astro";
2121
- let e = Array.from(document.body.children).filter((e) => {
2122
- let t = e.tagName?.toUpperCase();
2123
- return !(t === "SCRIPT" || t === "NOSCRIPT" || t === "LINK" || t === "STYLE" || e.id === "flowengage-root");
2124
- });
2125
- return e.length === 1 && e[0].id && (e[0].querySelector("[data-reactroot]") || e[0]._reactRootContainer || e[0].__vue_app__) ? "generic-spa" : null;
2121
+ if (window.__vite_plugin_react_preamble_installed__) return "vite-react-spa";
2122
+ let e = Array.from(document.body.children);
2123
+ for (let t of e) {
2124
+ if (t.id === "flowengage-root") continue;
2125
+ let e = t.tagName?.toUpperCase();
2126
+ if (!(e === "SCRIPT" || e === "NOSCRIPT" || e === "LINK" || e === "STYLE") && (t.querySelector?.("[data-reactroot]") || t._reactRootContainer || t.__vue_app__ || !(Array.from(t.childNodes).filter((e) => e.nodeType === 3).map((e) => e.textContent.trim()).join("").length > 200) && Object.getOwnPropertyNames(t).some((e) => e.startsWith("__reactFiber$") || e.startsWith("__reactContainer$")))) return "generic-spa";
2127
+ }
2128
+ return null;
2126
2129
  }
2127
2130
  var tr = "data-fe-swap-css";
2128
2131
  function nr() {
@@ -2836,7 +2839,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
2836
2839
  let i = f(() => e ? {
2837
2840
  ...t || {},
2838
2841
  siteId: e
2839
- } : t || null, [e, t]), [a, s] = m(0), [l, u] = m("booting"), [d, h] = m(null), [_, v] = m(null), [y, b] = m(""), [x, S] = m([]), [C, w] = m(ve().isOpen), [T, te] = m(ve().activeScreen), [ne, re] = m(ve().isHumanHandled), [E, D] = m(ve().agentName), [se, de] = m(ve().agentHeadshot), [fe, pe] = m(() => be(i?.siteId)), [me, Se] = m(!1), [Ce, we] = m(!1), [Ee, De] = m("idle"), [Oe, ke] = m(!1), [Ae, je] = m(!1), [Me, Ne] = m(""), [Fe, Ie] = m(!1), [Le, Re] = m(0), [ze, Be] = m(0), [Ve, He] = m(!1), [O, Ue] = m(null), [qe, Je] = m(null), [Ye, Xe] = m("idle"), [Ze, Qe] = m(null), [$e, et] = m(!1), [tt, nt] = m(""), [rt, it] = m(!1), at = p(null), k = p(null), ot = p(""), st = p(!1), ct = p(null), lt = p(null), ut = p(null), dt = p(null), ft = p(null), pt = p(null), mt = p([]), ht = p(null), gt = p(null), _t = p(null), A = p(!1), vt = p(!1), yt = p(""), j = p(null), bt = p(null), xt = p([]), St = p(0), Ct = p(E), wt = p([]), Tt = p(!1), Et = p(!1), Dt = p(i), Ot = p({
2842
+ } : t || null, [e, t]), [a, s] = m(0), [l, u] = m("booting"), [d, h] = m(null), [_, v] = m(null), [y, b] = m(""), [x, S] = m([]), [C, w] = m(ve().isOpen), [T, te] = m(ve().activeScreen), [ne, re] = m(ve().isHumanHandled), [E, D] = m(ve().agentName), [se, de] = m(ve().agentHeadshot), [fe, pe] = m(() => be(i?.siteId)), [me, Se] = m(!1), [Ce, we] = m(!1), [Ee, De] = m("idle"), [Oe, ke] = m(!1), [Ae, je] = m(!1), [Me, Ne] = m(""), [Fe, Ie] = m(!1), [Le, Re] = m(0), [ze, Be] = m(0), [Ve, He] = m(!1), [O, Ue] = m(null), [qe, Je] = m(null), [Ye, Xe] = m("idle"), [Ze, Qe] = m(null), [$e, et] = m(!1), [tt, nt] = m(""), [rt, it] = m(!1), at = p(null), k = p(null), ot = p(""), A = p(!1), st = p(null), ct = p(null), lt = p(null), ut = p(null), dt = p(null), ft = p(null), pt = p([]), mt = p(null), ht = p(null), gt = p(null), j = p(!1), _t = p(!1), vt = p(""), yt = p(null), bt = p(null), xt = p([]), St = p(0), Ct = p(E), wt = p([]), Tt = p(!1), Et = p(!1), Dt = p(i), Ot = p({
2840
2843
  notifyRouteChange: () => {},
2841
2844
  cleanup: () => {}
2842
2845
  }), kt = o((e = {}) => {
@@ -2847,7 +2850,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
2847
2850
  return Number.isFinite(t) && t > 0 ? t : ae;
2848
2851
  }, [i, _]);
2849
2852
  c(() => {
2850
- lt.current = O;
2853
+ ct.current = O;
2851
2854
  }, [O]), c(() => {
2852
2855
  Ct.current = E;
2853
2856
  }, [E]), c(() => {
@@ -2858,7 +2861,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
2858
2861
  let jt = () => {
2859
2862
  nt("");
2860
2863
  }, Mt = o(() => {
2861
- _t.current &&= (window.clearTimeout(_t.current), null);
2864
+ gt.current &&= (window.clearTimeout(gt.current), null);
2862
2865
  }, []), Nt = (e) => {
2863
2866
  let t = typeof e == "string" ? e.trim().toLowerCase() : "";
2864
2867
  return pe(t), xe(t, i?.siteId), t;
@@ -2868,8 +2871,8 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
2868
2871
  e && pe(be(e));
2869
2872
  }, [i?.siteId]);
2870
2873
  let Pt = (e = "unspecified") => {
2871
- let t = ht.current || pt.current?.callId, n = St.current, r = j.current;
2872
- if (j.current = null, St.current = 0, r && r.state !== "inactive") {
2874
+ let t = mt.current || ft.current?.callId, n = St.current, r = yt.current;
2875
+ if (yt.current = null, St.current = 0, r && r.state !== "inactive") {
2873
2876
  r.onstop = () => {
2874
2877
  let e = xt.current;
2875
2878
  if (xt.current = [], e.length > 0 && t && k.current) {
@@ -2895,18 +2898,18 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
2895
2898
  } catch {}
2896
2899
  bt.current = null;
2897
2900
  }
2898
- ut.current &&= (ut.current.close(), null), dt.current &&= (dt.current.getTracks().forEach((e) => e.stop()), null), ft.current &&= (ft.current.srcObject = null, ft.current.remove(), null), Mt(), pt.current = null, mt.current = [], ht.current = null, gt.current = null, A.current = !1, et(!1), Ue(null), Je(null), Xe("idle"), Qe(null);
2901
+ lt.current &&= (lt.current.close(), null), ut.current &&= (ut.current.getTracks().forEach((e) => e.stop()), null), dt.current &&= (dt.current.srcObject = null, dt.current.remove(), null), Mt(), ft.current = null, pt.current = [], mt.current = null, ht.current = null, j.current = !1, et(!1), Ue(null), Je(null), Xe("idle"), Qe(null);
2899
2902
  }, Ft = (e = (/* @__PURE__ */ new Date()).toISOString()) => {
2900
- let t = at.current, n = ht.current || pt.current?.callId;
2901
- if (!(!t?.connected || !n || A.current)) {
2902
- A.current = !0, t.emit("call:connected", {
2903
+ let t = at.current, n = mt.current || ft.current?.callId;
2904
+ if (!(!t?.connected || !n || j.current)) {
2905
+ j.current = !0, t.emit("call:connected", {
2903
2906
  callId: n,
2904
2907
  chatId: ot.current,
2905
2908
  connectedAt: e
2906
2909
  });
2907
2910
  try {
2908
- let e = dt.current, t = ft.current?.srcObject;
2909
- if (e && t && !j.current) {
2911
+ let e = ut.current, t = dt.current?.srcObject;
2912
+ if (e && t && !yt.current) {
2910
2913
  xt.current = [];
2911
2914
  let n = new (window.AudioContext || window.webkitAudioContext)();
2912
2915
  bt.current = n;
@@ -2915,7 +2918,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
2915
2918
  let i = window.MediaRecorder.isTypeSupported("audio/webm") ? "audio/webm" : "audio/mp4", a = new window.MediaRecorder(r.stream, { mimeType: i });
2916
2919
  a.ondataavailable = (e) => {
2917
2920
  e.data && e.data.size > 0 && xt.current.push(e.data);
2918
- }, j.current = a, St.current = Date.now(), a.start(1e3), setTimeout(() => {
2921
+ }, yt.current = a, St.current = Date.now(), a.start(1e3), setTimeout(() => {
2919
2922
  try {
2920
2923
  if (!window.speechSynthesis) return;
2921
2924
  let e = new SpeechSynthesisUtterance("This call is being recorded for quality and training purposes.");
@@ -2945,26 +2948,26 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
2945
2948
  }
2946
2949
  }, It = (e = {}) => {
2947
2950
  if (!e.callId) return;
2948
- let t = gt.current === e.callId, n = ht.current === e.callId, r = lt.current?.callId === e.callId;
2951
+ let t = ht.current === e.callId, n = mt.current === e.callId, r = ct.current?.callId === e.callId;
2949
2952
  if (!(!t && !n && !r)) {
2950
2953
  if (Mt(), Ue(null), t || n) {
2951
- ht.current = e.callId, Je(e.callId), Xe((e) => e === "connected" ? e : "connecting"), w(!0);
2954
+ mt.current = e.callId, Je(e.callId), Xe((e) => e === "connected" ? e : "connecting"), w(!0);
2952
2955
  return;
2953
2956
  }
2954
2957
  Xe("idle");
2955
2958
  }
2956
2959
  }, Lt = (e = {}) => {
2957
2960
  if (!e.callId) return;
2958
- let t = gt.current === e.callId, n = ht.current === e.callId, r = lt.current?.callId === e.callId;
2961
+ let t = ht.current === e.callId, n = mt.current === e.callId, r = ct.current?.callId === e.callId;
2959
2962
  if (!(!t && !n && !r)) {
2960
2963
  if (Mt(), n) {
2961
2964
  Pt();
2962
2965
  return;
2963
2966
  }
2964
- gt.current = null, pt.current = null, mt.current = [], Ue(null), Xe("idle");
2967
+ ht.current = null, ft.current = null, pt.current = [], Ue(null), Xe("idle");
2965
2968
  }
2966
2969
  }, Rt = async (e = {}) => {
2967
- let t = ut.current, n = at.current, r = e.sdpOffer || e.offer?.sdp;
2970
+ let t = lt.current, n = at.current, r = e.sdpOffer || e.offer?.sdp;
2968
2971
  if (!t || !n?.connected || !r || !e.callId) {
2969
2972
  console.log("[FlowEngageProvider] deferring remote offer until peer/socket ready", {
2970
2973
  callId: e.callId,
@@ -2972,20 +2975,20 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
2972
2975
  hasPeerConnection: !!t,
2973
2976
  socketConnected: !!n?.connected,
2974
2977
  hasOffer: !!r
2975
- }), pt.current = e;
2978
+ }), ft.current = e;
2976
2979
  return;
2977
2980
  }
2978
2981
  if (await t.setRemoteDescription(new RTCSessionDescription({
2979
2982
  type: "offer",
2980
2983
  sdp: r
2981
- })), mt.current.length > 0) {
2984
+ })), pt.current.length > 0) {
2982
2985
  console.log("[FlowEngageProvider] flushing queued agent ICE candidates after remote offer", {
2983
2986
  callId: e.callId,
2984
2987
  chatId: ot.current,
2985
- queuedCount: mt.current.length
2988
+ queuedCount: pt.current.length
2986
2989
  });
2987
- for (let e of mt.current) await t.addIceCandidate(new RTCIceCandidate(e));
2988
- mt.current = [];
2990
+ for (let e of pt.current) await t.addIceCandidate(new RTCIceCandidate(e));
2991
+ pt.current = [];
2989
2992
  }
2990
2993
  let i = await t.createAnswer();
2991
2994
  await t.setLocalDescription(i), n.emit("call:answer", {
@@ -3017,8 +3020,8 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3017
3020
  if (!e) return;
3018
3021
  let a = t.siteId, o = he(a), s = Te(a), c = "";
3019
3022
  try {
3020
- let e = st.current, r = ct.current;
3021
- if (st.current = !1, ct.current = null, c = (await We({
3023
+ let e = A.current, r = st.current;
3024
+ if (A.current = !1, st.current = null, c = (await We({
3022
3025
  apiBaseUrl: t.apiBaseUrl,
3023
3026
  userId: n.userId,
3024
3027
  siteId: a,
@@ -3154,14 +3157,14 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3154
3157
  e.agent?.name,
3155
3158
  Ct.current
3156
3159
  ], "Agent");
3157
- jt(), Mt(), A.current = !1, Ue({
3160
+ jt(), Mt(), j.current = !1, Ue({
3158
3161
  callId: e.callId,
3159
3162
  from: e.from || "owner",
3160
3163
  agentId: e.agentId || null,
3161
3164
  agentName: t
3162
3165
  }), D((e) => Ir([t, e], "Agent")), Xe("incoming"), Qe(null), w(!0);
3163
3166
  }), f.on("call:offer", async (e = {}) => {
3164
- pt.current = e;
3167
+ ft.current = e;
3165
3168
  try {
3166
3169
  await Rt(e);
3167
3170
  } catch (e) {
@@ -3174,15 +3177,15 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3174
3177
  console.warn("[FlowEngageProvider] ignoring invalid ICE candidate payload", e);
3175
3178
  return;
3176
3179
  }
3177
- if (!ut.current || !ut.current.remoteDescription) {
3180
+ if (!lt.current || !lt.current.remoteDescription) {
3178
3181
  console.log("[FlowEngageProvider] queueing agent ICE candidate until peer/remote description is ready", {
3179
3182
  callId: e.callId,
3180
3183
  chatId: e.chatId || ot.current,
3181
- queueSize: mt.current.length + 1
3182
- }), mt.current.push(t);
3184
+ queueSize: pt.current.length + 1
3185
+ }), pt.current.push(t);
3183
3186
  return;
3184
3187
  }
3185
- await ut.current.addIceCandidate(new RTCIceCandidate(t));
3188
+ await lt.current.addIceCandidate(new RTCIceCandidate(t));
3186
3189
  } catch (e) {
3187
3190
  console.error("[FlowEngageProvider] failed to add ICE candidate", e);
3188
3191
  }
@@ -3200,12 +3203,12 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3200
3203
  Lt(e);
3201
3204
  }), f.on("call:connected", (e = {}) => {
3202
3205
  if (!e.callId) return;
3203
- let t = gt.current === e.callId, n = ht.current === e.callId, r = pt.current?.callId === e.callId, i = lt.current?.callId === e.callId;
3206
+ let t = ht.current === e.callId, n = mt.current === e.callId, r = ft.current?.callId === e.callId, i = ct.current?.callId === e.callId;
3204
3207
  if (!t && !n && !r) {
3205
3208
  i && (Ue(null), Xe("idle"));
3206
3209
  return;
3207
3210
  }
3208
- A.current = !0, gt.current = null, ht.current = e.callId, Je(e.callId), Ue(null), Xe("connected"), Qe(e.connectedAt || (/* @__PURE__ */ new Date()).toISOString()), w(!0);
3211
+ j.current = !0, ht.current = null, mt.current = e.callId, Je(e.callId), Ue(null), Xe("connected"), Qe(e.connectedAt || (/* @__PURE__ */ new Date()).toISOString()), w(!0);
3209
3212
  }), f.on("call:unavailable", (e = {}) => {
3210
3213
  Pt("socket:call_unavailable"), nt(Pr(e, "This visitor is not available for a call right now.")), w(!0);
3211
3214
  }), f.on("call:error", (e = {}) => {
@@ -3282,10 +3285,10 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3282
3285
  ]);
3283
3286
  let Vt = async () => {
3284
3287
  if (!(!O?.callId || !k.current || !at.current || !y)) {
3285
- jt(), gt.current = O.callId, Mt();
3288
+ jt(), ht.current = O.callId, Mt();
3286
3289
  try {
3287
3290
  let e = await navigator.mediaDevices.getUserMedia({ audio: !0 });
3288
- dt.current = e;
3291
+ ut.current = e;
3289
3292
  let t = [{ urls: "stun:stun.l.google.com:19302" }];
3290
3293
  try {
3291
3294
  let e = await k.current.getIceServersConfig();
@@ -3294,7 +3297,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3294
3297
  console.warn("[FlowEngageProvider] ice-config fetch failed, using STUN default", e);
3295
3298
  }
3296
3299
  let n = new RTCPeerConnection({ iceServers: t });
3297
- ut.current = n, n.onconnectionstatechange = () => {
3300
+ lt.current = n, n.onconnectionstatechange = () => {
3298
3301
  let e = n.connectionState;
3299
3302
  if (e === "connected") {
3300
3303
  let e = (/* @__PURE__ */ new Date()).toISOString();
@@ -3333,21 +3336,21 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3333
3336
  });
3334
3337
  }, n.ontrack = (e) => {
3335
3338
  let [t] = e.streams || [], [n] = t?.getAudioTracks?.() || [];
3336
- if (!ft.current) {
3339
+ if (!dt.current) {
3337
3340
  let e = document.createElement("audio");
3338
- e.id = "flowengage-remote-audio", e.autoplay = !0, e.playsInline = !0, e.onplay = () => {}, e.onpause = () => {}, e.onended = () => {}, e.onerror = (e) => {}, ft.current = e, document.body.appendChild(e);
3341
+ e.id = "flowengage-remote-audio", e.autoplay = !0, e.playsInline = !0, e.onplay = () => {}, e.onpause = () => {}, e.onended = () => {}, e.onerror = (e) => {}, dt.current = e, document.body.appendChild(e);
3339
3342
  }
3340
- ft.current.srcObject = e.streams[0];
3341
- let r = O?.callId, i = r && (gt.current === r || ht.current === r);
3342
- if (!A.current && i) {
3343
+ dt.current.srcObject = e.streams[0];
3344
+ let r = O?.callId, i = r && (ht.current === r || mt.current === r);
3345
+ if (!j.current && i) {
3343
3346
  let e = (/* @__PURE__ */ new Date()).toISOString();
3344
- Xe("connected"), Qe((t) => t || e), ht.current = r, Je(r), Ft(e);
3347
+ Xe("connected"), Qe((t) => t || e), mt.current = r, Je(r), Ft(e);
3345
3348
  }
3346
- ft.current.srcObject = t || null;
3347
- let a = ft.current.play?.();
3349
+ dt.current.srcObject = t || null;
3350
+ let a = dt.current.play?.();
3348
3351
  a?.catch && a.catch((e) => {});
3349
3352
  };
3350
- let r = pt.current;
3353
+ let r = ft.current;
3351
3354
  r && (console.log("[FlowEngageProvider] found pending remote offer during accept", {
3352
3355
  callId: r.callId || O.callId,
3353
3356
  chatId: y
@@ -3357,9 +3360,9 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3357
3360
  })), await k.current.acceptCall(O.callId, y), at.current?.emit("call:accepted", {
3358
3361
  callId: O.callId,
3359
3362
  chatId: y
3360
- }), ht.current = O.callId, Je(O.callId), Xe((e) => e === "connected" || A.current ? "connected" : "connecting"), Ue(null), w(!0);
3363
+ }), mt.current = O.callId, Je(O.callId), Xe((e) => e === "connected" || j.current ? "connected" : "connecting"), Ue(null), w(!0);
3361
3364
  } catch (e) {
3362
- if (gt.current = null, Pt("accept_call_failed"), e?.status === 404 || e?.status === 409 || e?.status === 422) {
3365
+ if (ht.current = null, Pt("accept_call_failed"), e?.status === 404 || e?.status === 409 || e?.status === 422) {
3363
3366
  nt(Pr(e, "This visitor call is no longer available."));
3364
3367
  return;
3365
3368
  }
@@ -3400,10 +3403,10 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3400
3403
  return;
3401
3404
  }
3402
3405
  let e = O.callId;
3403
- return Mt(), _t.current = window.setTimeout(() => {
3404
- lt.current?.callId === e && gt.current !== e && ht.current !== e && Ut.current();
3406
+ return Mt(), gt.current = window.setTimeout(() => {
3407
+ ct.current?.callId === e && ht.current !== e && mt.current !== e && Ut.current();
3405
3408
  }, oe), () => {
3406
- _t.current &&= (window.clearTimeout(_t.current), null);
3409
+ gt.current &&= (window.clearTimeout(gt.current), null);
3407
3410
  };
3408
3411
  }, [
3409
3412
  qe,
@@ -3424,7 +3427,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3424
3427
  Pt("end_call_finally");
3425
3428
  }
3426
3429
  }, Gt = () => {
3427
- let e = dt.current?.getAudioTracks?.() || [], t = ut.current?.getSenders?.().map((e) => e.track).filter((e) => e?.kind === "audio") || [], n = [...e, ...t].filter(Boolean);
3430
+ let e = ut.current?.getAudioTracks?.() || [], t = lt.current?.getSenders?.().map((e) => e.track).filter((e) => e?.kind === "audio") || [], n = [...e, ...t].filter(Boolean);
3428
3431
  if (n.length === 0) return;
3429
3432
  let r = !$e;
3430
3433
  n.forEach((e) => {
@@ -3457,18 +3460,18 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3457
3460
  }
3458
3461
  return t;
3459
3462
  }, Jt = () => {
3460
- !y || !at.current?.connected || vt.current || (vt.current = !0, at.current.emit("typing:start", {
3463
+ !y || !at.current?.connected || _t.current || (_t.current = !0, at.current.emit("typing:start", {
3461
3464
  chatId: y,
3462
3465
  sender: "user"
3463
3466
  }));
3464
3467
  }, Yt = () => {
3465
- !y || !at.current?.connected || !vt.current || (vt.current = !1, at.current.emit("typing:stop", {
3468
+ !y || !at.current?.connected || !_t.current || (_t.current = !1, at.current.emit("typing:stop", {
3466
3469
  chatId: y,
3467
3470
  sender: "user"
3468
3471
  }));
3469
3472
  }, Xt = (e = "") => {
3470
3473
  let t = typeof e == "string" ? e : "";
3471
- !y || !at.current?.connected || t !== "" && yt.current === t || (yt.current = t, at.current.emit("typing:update", {
3474
+ !y || !at.current?.connected || t !== "" && vt.current === t || (vt.current = t, at.current.emit("typing:update", {
3472
3475
  chatId: y,
3473
3476
  sender: "user",
3474
3477
  text: t
@@ -3610,11 +3613,11 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3610
3613
  let e = () => {
3611
3614
  let e = ot.current, t = k.current;
3612
3615
  if (!t || !e) return;
3613
- if (Et.current && wt.current.length > 0 && Pe(), !Tt.current && wt.current.length > 0 && (t.beaconSyncVoice(e, wt.current) || t.syncVoice(e, wt.current).catch(() => {}), Tt.current = !0), ht.current) {
3614
- t.beaconEndWebRTCCall(ht.current, e);
3616
+ if (Et.current && wt.current.length > 0 && Pe(), !Tt.current && wt.current.length > 0 && (t.beaconSyncVoice(e, wt.current) || t.syncVoice(e, wt.current).catch(() => {}), Tt.current = !0), mt.current) {
3617
+ t.beaconEndWebRTCCall(mt.current, e);
3615
3618
  return;
3616
3619
  }
3617
- let n = gt.current || lt.current?.callId;
3620
+ let n = ht.current || ct.current?.callId;
3618
3621
  n && t.beaconCustomerUnavailable(n, e);
3619
3622
  };
3620
3623
  return window.addEventListener("pagehide", e), window.addEventListener("beforeunload", e), () => {
@@ -3623,9 +3626,9 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3623
3626
  }, []);
3624
3627
  let nn = o(() => {
3625
3628
  let e = i?.siteId;
3626
- ge(e), st.current = !0, ct.current = null, at.current?.disconnect(), S([]), b(""), ot.current = "", He(!1), re(!1), D(null), de(null), it(!0), s((e) => e + 1);
3629
+ ge(e), A.current = !0, st.current = null, at.current?.disconnect(), S([]), b(""), ot.current = "", He(!1), re(!1), D(null), de(null), it(!0), s((e) => e + 1);
3627
3630
  }, [i?.siteId]), rn = o((e) => {
3628
- i?.siteId, st.current = !1, ct.current = e, at.current?.disconnect(), S([]), b(""), ot.current = "", He(!1), re(!1), D(null), de(null), it(!0), s((e) => e + 1);
3631
+ i?.siteId, A.current = !1, st.current = e, at.current?.disconnect(), S([]), b(""), ot.current = "", He(!1), re(!1), D(null), de(null), it(!0), s((e) => e + 1);
3629
3632
  }, [i?.siteId]), an = f(() => ({
3630
3633
  status: l,
3631
3634
  error: d,
@@ -29265,7 +29268,12 @@ function vk(e) {
29265
29268
  let t = e.url ?? e.target_url ?? e.page_url ?? e.pageUrl ?? e.link ?? e.href ?? e.path;
29266
29269
  return t == null ? null : String(t).trim() || null;
29267
29270
  }
29268
- function yk(e, t, n) {
29271
+ function yk(e) {
29272
+ if (!e || typeof e != "object") return null;
29273
+ let t = e.query ?? e.q ?? e.search ?? e.text ?? e.keywords;
29274
+ return t == null ? null : String(t).trim() || null;
29275
+ }
29276
+ function bk(e, t, n) {
29269
29277
  if (!n?.skipScroll) try {
29270
29278
  e.scrollIntoView({
29271
29279
  block: "center",
@@ -29320,7 +29328,7 @@ function yk(e, t, n) {
29320
29328
  } catch {}
29321
29329
  return !0;
29322
29330
  }
29323
- function bk() {
29331
+ function xk() {
29324
29332
  let e = {};
29325
29333
  document.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach((t) => {
29326
29334
  if (t.id) return;
@@ -29335,11 +29343,11 @@ function bk() {
29335
29343
  e[r] = !0, t.id = r;
29336
29344
  });
29337
29345
  }
29338
- function xk() {
29346
+ function Sk() {
29339
29347
  let e = document.querySelector("main, [role='main'], article") || document.body;
29340
29348
  return Array.from(e.querySelectorAll("h1, h2, h3")).filter((e) => !e.closest("#flowengage-root, .flowengage-shell, .flowengage-widget-root")).map((e) => e.textContent.replace(/\s+/g, " ").trim()).filter((e) => e.length > 2 && e.length < 200).slice(0, 12);
29341
29349
  }
29342
- function Sk(e) {
29350
+ function Ck(e) {
29343
29351
  let t = e.siteId || null, n = (e.apiBaseUrl || "").replace(/\/$/, ""), r = typeof e.getLastUserVoiceText == "function" ? e.getLastUserVoiceText : null, i = [], a = {
29344
29352
  flowengage_navigate: async (n) => {
29345
29353
  $("flowengage_navigate ▶ raw parameters:", n);
@@ -29370,7 +29378,7 @@ function Sk(e) {
29370
29378
  siteId: t,
29371
29379
  apiBaseUrl: e.apiBaseUrl
29372
29380
  })) {
29373
- let e = `Page "${a}" could not be verified. Try a different URL from your known site pages, or ask the visitor to clarify which page they want.`;
29381
+ let e = `Page "${a}" could not be verified. Call flowengage_search with keywords from the topic to find the correct URL, then navigate to the URL from the search results.`;
29374
29382
  return $("flowengage_navigate ✖ blocked", e), e;
29375
29383
  }
29376
29384
  try {
@@ -29398,10 +29406,10 @@ function Sk(e) {
29398
29406
  let n = typeof window < "u" ? window.location.pathname : e, r = typeof window < "u" ? window.location.href : a, i = n === e, o = (n.split("/").filter(Boolean).pop() || "").replace(/[-_]/g, " ").replace(/\b\w/g, (e) => e.toUpperCase()) || "Home";
29399
29407
  $("flowengage_navigate → SPA nav complete. target:", e, "actual:", n);
29400
29408
  let s = [], c = Date.now() + 8e3;
29401
- for (; Date.now() < c && (await new Promise((e) => setTimeout(e, 250)), s = xk(), !(s.length >= 1)););
29402
- bk(), $("flowengage_navigate → page headings collected:", s);
29403
- let l = s.length ? s.join(" | ") : "none", u = s.length ? "Use ONLY these exact heading strings for flowengage_highlight." : "No headings were collected from the live DOM — use your knowledge base heading strings for this page to call flowengage_highlight. Follow RULE 1: call each highlight BEFORE describing its section (transition → highlight → content).";
29404
- return i ? (wr(), `OK_NAVIGATE_SPA. Visitor is now on: ${r} (page: "${o}") | Section headings: ${l}. ${u} Speak 2-3 sentences about this page from your knowledge, then IMMEDIATELY ask: "Is there a specific section or topic you'd like to know more about?" Do NOT highlight or walkthrough unless the visitor explicitly requests it. Do NOT say "I have navigated you" or "I've taken you to".`) : (wr(), `OK_NAVIGATE_SPA. CURRENT PAGE IS: ${r} (page: "${o}") | Section headings: ${l}. ${u} Speak 2-3 sentences about this page from your knowledge, then IMMEDIATELY ask: "Is there a specific section or topic you'd like to know more about?" Describe THIS page only — do not mention the page you tried to navigate to.`);
29409
+ for (; Date.now() < c && (await new Promise((e) => setTimeout(e, 250)), s = Sk(), !(s.length >= 1)););
29410
+ xk(), $("flowengage_navigate → page headings collected:", s);
29411
+ let l = s.length ? s.join(" | ") : "none", u = s.length ? "Section headings are provided for reference only." : "No headings collected from live DOM — use knowledge base heading strings if a walkthrough is later requested.";
29412
+ return i ? (wr(), `OK_NAVIGATE_SPA. Visitor is now on: ${r} (page: "${o}") | Section headings: ${l}. ${u} Speak 2-3 sentences about this page from your knowledge, then STOP. Do NOT highlight. Do NOT walk through sections. Wait for the visitor to respond. Only do a highlighted walkthrough if they explicitly ask for one.`) : (wr(), `OK_NAVIGATE_SPA. CURRENT PAGE IS: ${r} (page: "${o}") | Section headings: ${l}. ${u} Speak 2-3 sentences about this page from your knowledge, then STOP. Do NOT highlight or walk through sections. Describe THIS page only — do not mention the page you tried to navigate to.`);
29405
29413
  } catch {}
29406
29414
  return "OK_NAVIGATE_RELOADING. Navigating to the page now; the voice session will resume automatically on the new page. When the session resumes, immediately introduce the new page and continue guiding the visitor — do not wait for the user to speak first.";
29407
29415
  } catch (e) {
@@ -29423,15 +29431,15 @@ function Sk(e) {
29423
29431
  if (Date.now() - e.ts >= 3e4) window.__fe_user_nav_during_speech = null;
29424
29432
  else return $("flowengage_highlight ✖ blocked — user navigated during speech", e), `NAV_CHANGED: The visitor navigated from "${e.fromPageName}" to "${e.toPageName}" (current path: ${t}) while you were speaking. STOP the current walkthrough immediately. DO NOT call flowengage_highlight again. Say out loud: "I see you've navigated to the ${e.toPageName} page — do you want me to continue what I was explaining, or shall I guide you through this page?" Wait for the visitor's answer before doing anything else.`;
29425
29433
  }
29426
- bk();
29434
+ xk();
29427
29435
  let i = hr(n || null, r || null);
29428
29436
  if (!i && r) {
29429
29437
  let e = Date.now() + 600;
29430
- for (; !i && Date.now() < e;) await new Promise((e) => setTimeout(e, 50)), bk(), i = hr(null, r);
29438
+ for (; !i && Date.now() < e;) await new Promise((e) => setTimeout(e, 50)), xk(), i = hr(null, r);
29431
29439
  }
29432
29440
  if (!i) {
29433
29441
  $("flowengage_highlight ✖ no element for:", r || n);
29434
- let e = xk(), t = e.length ? `Page headings: ${e.join(" | ")}. Use one of these exact strings for section_text.` : "No headings found — skip highlight and continue.";
29442
+ let e = Sk(), t = e.length ? `Page headings: ${e.join(" | ")}. Use one of these exact strings for section_text.` : "No headings found — skip highlight and continue.";
29435
29443
  return `HIGHLIGHT_NOT_FOUND: "${r || n}" on the current page. ${t}`;
29436
29444
  }
29437
29445
  return xD(i), $("flowengage_highlight ✓", r || n), `OK_HIGHLIGHT: "${r || n}". WALKTHROUGH: continue immediately to the next section — do NOT pause between sections.`;
@@ -29459,6 +29467,38 @@ function Sk(e) {
29459
29467
  return $("flowengage_read_content ✖", e.message), `Could not read page content: ${e.message}`;
29460
29468
  }
29461
29469
  },
29470
+ flowengage_search: async (e) => {
29471
+ $("flowengage_search ▶", e);
29472
+ let r = yk(mk(e));
29473
+ if ($("flowengage_search · query:", r, "siteId:", t, "apiBase:", n || "(empty)"), !r) return $("flowengage_search ✖ missing query"), "Missing query parameter.";
29474
+ if (!t) return $("flowengage_search ✖ no siteId"), "Site is not configured for search.";
29475
+ if (!n) return $("flowengage_search ✖ no api base"), "API base URL is missing; cannot search.";
29476
+ CO(`Searching${r ? ` for "${r}"` : ""}…`, { spinner: !0 });
29477
+ try {
29478
+ let e = `${n}/api/site-tools/search`;
29479
+ $("flowengage_search → POST", e);
29480
+ let i = await fetch(e, {
29481
+ method: "POST",
29482
+ headers: { "Content-Type": "application/json" },
29483
+ body: JSON.stringify({
29484
+ siteId: t,
29485
+ query: r,
29486
+ currentUrl: typeof window < "u" ? window.location.href : ""
29487
+ })
29488
+ }), a = await i.json();
29489
+ if ($("flowengage_search · HTTP", i.status, "success:", a.success), !a.success) {
29490
+ let e = a.error || "Search failed.";
29491
+ return $("flowengage_search ✖", e), e;
29492
+ }
29493
+ let o = a.results || [];
29494
+ return $("flowengage_search ✓", `${o.length} result(s)`, o.slice(0, 3).map((e) => e?.url || e)), o.length ? `SEARCH_RESULTS: ${JSON.stringify(o)}. MANDATORY: Do NOT call flowengage_navigate now. Speak the answer from these results in 2-3 sentences. Then ask the visitor if they want to go to a relevant page — e.g. "Would you like me to take you to that page?" Only navigate if they say yes.` : "SEARCH_RESULTS: No results found. Answer from your knowledge base.";
29495
+ } catch (e) {
29496
+ let t = `Search error: ${e.message || "network"}`;
29497
+ return $("flowengage_search ✖", t), t;
29498
+ } finally {
29499
+ wO(600);
29500
+ }
29501
+ },
29462
29502
  flowengage_page_content: async (e) => {
29463
29503
  $("flowengage_page_content ▶", e);
29464
29504
  let r = mk(e), i = r?.url || r?.page_url || "";
@@ -29494,12 +29534,12 @@ function Sk(e) {
29494
29534
  flowengage_end_session: async () => ($("flowengage_end_session ▶"), typeof e.requestEndSession == "function" && e.requestEndSession(), "Voice session is ending."),
29495
29535
  flowengage_get_current_page: async () => {
29496
29536
  if ($("flowengage_get_current_page ▶"), typeof window > "u") return "Cannot determine current page (no browser context).";
29497
- let e = window.location.href, t = window.location.pathname, n = document.title || "", r = xk(), i = r.length ? r.join(" | ") : "none";
29537
+ let e = window.location.href, t = window.location.pathname, n = document.title || "", r = Sk(), i = r.length ? r.join(" | ") : "none";
29498
29538
  return $("flowengage_get_current_page ✓", {
29499
29539
  url: e,
29500
29540
  path: t,
29501
29541
  title: n
29502
- }), $("flowengage_get_current_page → page headings collected:", r), `CURRENT_PAGE. URL: ${e} | Path: ${t} | Title: ${n} | Section headings: ${i}. Give 1-2 sentences about this page, then ask: "Is there a specific section or topic you'd like to know more about?" Use ONLY these exact heading strings for flowengage_highlight — never invent or abbreviate section names.`;
29542
+ }), $("flowengage_get_current_page → page headings collected:", r), `CURRENT_PAGE. URL: ${e} | Path: ${t} | Title: ${n} | Section headings: ${i}. Section headings are for reference. Speak 1-2 sentences about this page, then STOP. Do NOT highlight or walkthrough unless the visitor explicitly requests it. If doing a walkthrough, use ONLY these exact heading strings for flowengage_highlight — never invent or abbreviate.`;
29503
29543
  },
29504
29544
  flowengage_list_forms: async () => {
29505
29545
  let e = XO(), t = ZO();
@@ -29525,12 +29565,12 @@ function Sk(e) {
29525
29565
  CO(`Filling ${String(t)}...`, { spinner: !0 });
29526
29566
  let a = YO(), o = ck(a, String(t), r);
29527
29567
  if (o.length) {
29528
- for (let [e, t] of o.entries()) jO(t), await LO(t), yk(t, r, { skipScroll: e > 0 }), MO(t), await HO(120);
29568
+ for (let [e, t] of o.entries()) jO(t), await LO(t), bk(t, r, { skipScroll: e > 0 }), MO(t), await HO(120);
29529
29569
  i = o, n.push(String(t));
29530
29570
  continue;
29531
29571
  }
29532
29572
  let s = dk(a, String(t));
29533
- s ||= nk(a, String(t)), s ||= rk(a, String(t), r), s && (jO(s), await LO(s), yk(s, r), MO(s), await HO(120), i = [s], n.push(String(t)));
29573
+ s ||= nk(a, String(t)), s ||= rk(a, String(t), r), s && (jO(s), await LO(s), bk(s, r), MO(s), await HO(120), i = [s], n.push(String(t)));
29534
29574
  }
29535
29575
  if (!n.length) return $("flowengage_fill_form ✖ no matches"), "Could not match any fields. Call flowengage_list_forms and use field_key values that match placeholder, label, name, or id (e.g. Enter Website URL). Ensure the form is on the page, not the chat panel.";
29536
29576
  let a = `OK_FILLED: ${n.join(", ")}`;
@@ -29587,6 +29627,7 @@ function Sk(e) {
29587
29627
  return {
29588
29628
  ...a,
29589
29629
  highlightOnPage: a.flowengage_highlight,
29630
+ searchSiteContent: a.flowengage_search,
29590
29631
  getPageContent: a.flowengage_page_content,
29591
29632
  endVoiceSession: a.flowengage_end_session,
29592
29633
  listPageForms: a.flowengage_list_forms,
@@ -29596,7 +29637,7 @@ function Sk(e) {
29596
29637
  }
29597
29638
  //#endregion
29598
29639
  //#region src/utils/wrapVoiceToolsForLogging.js
29599
- function Ck(e) {
29640
+ function wk(e) {
29600
29641
  return !e || typeof e != "object" ? e : Object.fromEntries(Object.entries(e).map(([e, t]) => [e, async (n) => {
29601
29642
  let r = Rn();
29602
29643
  r ? console.log("[FlowEngage:voice-tool] ▶", e, n) : console.info(`[FlowEngage] voice tool » ${e}`);
@@ -29613,7 +29654,7 @@ function Ck(e) {
29613
29654
  }
29614
29655
  //#endregion
29615
29656
  //#region src/components/FlowEngageWidget.jsx
29616
- var wk = {
29657
+ var Tk = {
29617
29658
  blue: "#135bd8",
29618
29659
  red: "#ef334b",
29619
29660
  yellow: "#ffbd2e",
@@ -29621,7 +29662,7 @@ var wk = {
29621
29662
  highlight: "rgba(255,255,255,0.9)",
29622
29663
  green: "#10b981"
29623
29664
  };
29624
- function Tk(e) {
29665
+ function Ek(e) {
29625
29666
  if (!Array.isArray(e) || e.length < 2) return "linear-gradient(145deg, #dce8f022 0%, #e8dff522 45%, #f5e0e022 100%), #f7f8fa";
29626
29667
  let [t, n, r] = e;
29627
29668
  return e.length >= 3 && r ? [
@@ -29635,12 +29676,12 @@ function Tk(e) {
29635
29676
  "#f7f8fa"
29636
29677
  ].join(", ");
29637
29678
  }
29638
- function Ek(e) {
29679
+ function Dk(e) {
29639
29680
  if (!e || typeof e != "string") return "#1a1a1a";
29640
29681
  let t = e.replace("#", ""), n = t.length === 3 ? t.split("").map((e) => e + e).join("") : t, r = parseInt(n.slice(0, 2), 16) / 255, i = parseInt(n.slice(2, 4), 16) / 255, a = parseInt(n.slice(4, 6), 16) / 255, o = (e) => e <= .04045 ? e / 12.92 : ((e + .055) / 1.055) ** 2.4;
29641
29682
  return .2126 * o(r) + .7152 * o(i) + .0722 * o(a) > .179 ? "#1a1a1a" : "#ffffff";
29642
29683
  }
29643
- function Dk(t) {
29684
+ function Ok(t) {
29644
29685
  let [n, r] = e.useState(null), i = typeof t == "string" ? t.trim() : "";
29645
29686
  return e.useEffect(() => {
29646
29687
  if (!i) {
@@ -29658,8 +29699,8 @@ function Dk(t) {
29658
29699
  };
29659
29700
  }, [i]), n;
29660
29701
  }
29661
- function Ok({ logo: t, style: n }) {
29662
- let r = Dk(typeof t == "string" ? t : null);
29702
+ function kk({ logo: t, style: n }) {
29703
+ let r = Ok(typeof t == "string" ? t : null);
29663
29704
  if (!t) return null;
29664
29705
  if (typeof t == "string") return r ? /* @__PURE__ */ g("img", {
29665
29706
  src: r,
@@ -29684,7 +29725,7 @@ function Ok({ logo: t, style: n }) {
29684
29725
  children: i
29685
29726
  }) : null;
29686
29727
  }
29687
- function kk({ title: e }) {
29728
+ function Ak({ title: e }) {
29688
29729
  return /* @__PURE__ */ g("div", {
29689
29730
  style: {
29690
29731
  width: "100%",
@@ -29702,18 +29743,18 @@ function kk({ title: e }) {
29702
29743
  children: String(e || "FE").split(/\s+/).filter(Boolean).slice(0, 2).map((e) => e[0]?.toUpperCase() || "").join("") || "FE"
29703
29744
  });
29704
29745
  }
29705
- function Ak(e, t) {
29746
+ function jk(e, t) {
29706
29747
  let n = (t || "").trim();
29707
29748
  return n ? !!(/\b(let'?s|let us)\s+(end|stop|finish|wrap up|close)\s+(the\s+)?(voice\s+)?(session|call|chat)\b/i.test(n) || /\bend\s+(this\s+)?(the\s+)?(voice\s+)?(session|call|chat)\b/i.test(n) || /\b(hang\s+up|disconnect)\b/i.test(n) || /\b(that'?s all|we'?re done)\b/i.test(n) || e === "bot" && (/\b(I'?ll|I will|Let me|I can|I'?m going to)\s+(end|close)\s+(the\s+)?(voice\s+)?(session|call)\b/i.test(n) || /\b(ending|closing)\s+(the\s+)?(voice\s+)?session\b|\bvoice\s+session\s+(is\s+)?(now\s+)?(ended|over|closing)\b/i.test(n) || /\b(session|call)\s+(is\s+)?(now\s+)?(ended|over)\b/i.test(n) || /\bwe\s+can\s+end\s+(the\s+)?(session|call)?\s*(here|now)\b/i.test(n) || /\b(wrapping\s+up|signing\s+off)\b/i.test(n)) || /^(goodbye|bye|that'?s all|we'?re done|hang up|disconnect)\b/i.test(n)) : !1;
29708
29749
  }
29709
- function jk({ orbColors: e, ...t }) {
29750
+ function Mk({ orbColors: e, ...t }) {
29710
29751
  return /* @__PURE__ */ g(lO, {
29711
29752
  colors: e,
29712
29753
  ...t
29713
29754
  });
29714
29755
  }
29715
- function Mk({ copy: e, orbColors: t, primaryColor: n, onYes: r, onLater: i, isMobile: a, isClosing: o }) {
29716
- let s = n || wk.green, c = Ek(s), l = a ? 72 : 94, u = /* @__PURE__ */ _("div", {
29756
+ function Nk({ copy: e, orbColors: t, primaryColor: n, onYes: r, onLater: i, isMobile: a, isClosing: o }) {
29757
+ let s = n || Tk.green, c = Dk(s), l = a ? 72 : 94, u = /* @__PURE__ */ _("div", {
29717
29758
  style: {
29718
29759
  display: "flex",
29719
29760
  alignItems: a ? "flex-end" : "center",
@@ -29834,7 +29875,7 @@ function Mk({ copy: e, orbColors: t, primaryColor: n, onYes: r, onLater: i, isMo
29834
29875
  delay: 0
29835
29876
  },
29836
29877
  style: { flexShrink: 0 },
29837
- children: /* @__PURE__ */ g(jk, {
29878
+ children: /* @__PURE__ */ g(Mk, {
29838
29879
  size: l,
29839
29880
  orbColors: t
29840
29881
  })
@@ -29866,8 +29907,8 @@ function Mk({ copy: e, orbColors: t, primaryColor: n, onYes: r, onLater: i, isMo
29866
29907
  children: u
29867
29908
  })] });
29868
29909
  }
29869
- function Nk({ copy: e, orbColors: t, primaryColor: n, onVoice: r, onText: i, onClose: a, isMobile: o, isClosing: s }) {
29870
- let c = n || wk.green, l = Ek(c);
29910
+ function Pk({ copy: e, orbColors: t, primaryColor: n, onVoice: r, onText: i, onClose: a, isMobile: o, isClosing: s }) {
29911
+ let c = n || Tk.green, l = Dk(c);
29871
29912
  return /* @__PURE__ */ _(Dm.div, {
29872
29913
  initial: {
29873
29914
  scale: 50 / 350,
@@ -29938,7 +29979,7 @@ function Nk({ copy: e, orbColors: t, primaryColor: n, onVoice: r, onText: i, onC
29938
29979
  children: /* @__PURE__ */ g("polyline", { points: "6 9 12 15 18 9" })
29939
29980
  })
29940
29981
  }),
29941
- /* @__PURE__ */ g(jk, {
29982
+ /* @__PURE__ */ g(Mk, {
29942
29983
  size: 72,
29943
29984
  orbColors: t
29944
29985
  }),
@@ -30007,13 +30048,9 @@ function Nk({ copy: e, orbColors: t, primaryColor: n, onVoice: r, onText: i, onC
30007
30048
  ]
30008
30049
  });
30009
30050
  }
30010
- function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i, apiBaseUrl: a, chatId: s, historyRef: l, onMessageSync: u, voiceEndCounter: d }) {
30011
- c(() => (console.log("[FlowEngage:VoiceDebug] 🔵 VoiceMode MOUNTED"), () => console.log("[FlowEngage:VoiceDebug] 🔴 VoiceMode UNMOUNTED")), []);
30051
+ function Fk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i, apiBaseUrl: a, chatId: s, historyRef: l, onMessageSync: u, voiceEndCounter: d }) {
30012
30052
  let [f, h] = m("idle"), [v, y] = m(!1), [b, x] = m(!1), S = p(null), C = p(""), w = p(async () => {}), T = p(!1), ee = p(!1), te = p(!1), ne = p(!1), re = p("minimized"), E = p(null), ie = p(null), ae = p(null), oe = p(0), D = p(!1), se = p("idle"), ce = p(!1), le = p(null), ue = p(null), de = p(!1), fe = o((e = "minimized") => {
30013
- console.warn("[FlowEngage:VoiceDebug] 🛑 requestSessionShutdown called", {
30014
- destination: e,
30015
- stack: (/* @__PURE__ */ Error()).stack?.split("\n").slice(1, 4).join(" | ")
30016
- }), re.current = e, ne.current = !0, queueMicrotask(() => {
30053
+ re.current = e, ne.current = !0, queueMicrotask(() => {
30017
30054
  T.current || (T.current = !0, w.current?.());
30018
30055
  });
30019
30056
  }, [l]), pe = o(async (e) => {
@@ -30089,7 +30126,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30089
30126
  }
30090
30127
  Pe();
30091
30128
  } });
30092
- let t = Ck(Sk({
30129
+ let t = wk(Ck({
30093
30130
  siteId: i || null,
30094
30131
  apiBaseUrl: a || null,
30095
30132
  getLastUserVoiceText: () => C.current,
@@ -30120,7 +30157,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30120
30157
  m && m.includes("|") && (x = m.split("|").map((e) => e.trim()).filter(Boolean).reduce((e, t) => e.length <= t.length ? e : t));
30121
30158
  let w = x || b || "this page";
30122
30159
  _ ? f ? (v.overrides = { agent: { firstMessage: `I've navigated you to the ${w} page. Let me walk you through what's here.` } }, console.log(`[FlowEngage] 🔄 Agent-nav resume: firstMessage set for "${w}" (${p})`)) : u ? v.overrides = { agent: { firstMessage: "I'm still here. Go ahead!" } } : g || (v.overrides = { agent: { firstMessage: `Hi! I see you are currently on the ${w} page. Are you looking for something specific here?` } }, console.log(`[FlowEngage] 🏠 Page-context override: "${w}" for ${p}`)) : u && (v.overrides = { agent: { firstMessage: "" } });
30123
- let ae = !1, pe = f ? `NAVIGATION RESUME — You have just navigated to a new page. Speak 2-3 sentences about this page from your knowledge, then STOP and wait for the visitor to respond. Do NOT auto-highlight or walkthrough. Prior conversation context:\n${(i ? je(i) : null)?.transcript || ""}\n\n` : null, me = await vD.startSession({
30160
+ let ae = !1, pe = f ? `NAVIGATION RESUME — Your intro has been spoken. NOW — without waiting for the visitor to say anything call flowengage_highlight for the first content section on this page, then speak one sentence about it. Continue section by section (highlight + one sentence each) until you have covered the key content. Prior conversation context:\n${(i ? je(i) : null)?.transcript || ""}\n\n` : null, me = await vD.startSession({
30124
30161
  ...v,
30125
30162
  onConnect: ({ conversationId: e }) => {
30126
30163
  E.current = e, ie.current = Date.now(), console.log("[FlowEngage] 🎙️ AI chat session connected:", e);
@@ -30143,11 +30180,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30143
30180
  } catch {}
30144
30181
  }
30145
30182
  ue.current && clearTimeout(ue.current), ue.current = setTimeout(() => {
30146
- e || se.current !== "speaking" && (de.current || (ue.current = null, se.current = "listening", h("listening"), ce.current && !ee.current && (le.current && clearTimeout(le.current), le.current = setTimeout(() => {
30147
- if (!e && se.current === "listening" && !ee.current) try {
30148
- S.current?.sendContextualUpdate?.("The visitor has been silent for a while. Ask one short, natural question to re-engage — for example: 'Is there anything specific you'd like to know more about?' or 'What else can I help you with today?' Keep it to one sentence.");
30149
- } catch {}
30150
- }, 4e3))));
30183
+ e || se.current !== "speaking" && (de.current || (ue.current = null, se.current = "listening", h("listening")));
30151
30184
  }, 1200);
30152
30185
  }
30153
30186
  },
@@ -30163,8 +30196,8 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30163
30196
  let e = vO(l.current);
30164
30197
  e && Ae(i, e);
30165
30198
  } catch {}
30166
- if (Ak(n, r)) {
30167
- D.current = !0;
30199
+ if (jk(n, r)) {
30200
+ fe("minimized");
30168
30201
  return;
30169
30202
  }
30170
30203
  if (ee.current && n === "bot" && /are you still there|still there\??|hello\?|anyone there|checking in|you there|are you available|is anyone|did you step away/i.test(r)) if (oe.current += 1, oe.current === 2) try {
@@ -30204,14 +30237,14 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30204
30237
  }
30205
30238
  });
30206
30239
  if (e) {
30207
- console.warn("[FlowEngage:VoiceDebug] ❌ cancelled=true after startSession resolved — killing session immediately"), me.endSession().catch(() => {});
30240
+ me.endSession().catch(() => {});
30208
30241
  return;
30209
30242
  }
30210
30243
  o = me, S.current = me, h("listening");
30211
30244
  try {
30212
30245
  let e = typeof window < "u" ? window.location.href : "", r = "[]";
30213
30246
  try {
30214
- r = await t.flowengage_list_forms();
30247
+ r = await t.list_page_forms();
30215
30248
  } catch {}
30216
30249
  let a = u && !f ? `RESUMING PRIOR SESSION — DO NOT GREET. The visitor is continuing the same conversation after a page reload. Do not introduce yourself or re-state your capabilities. Wait silently until the visitor speaks; if you must speak first, briefly acknowledge where you left off in one short sentence.\nPrior transcript:\n${n?.transcript || ""}\n\n` : "";
30217
30250
  me.sendContextualUpdate(`${a}Page: ${e}. SiteId: ${i || "unknown"}. Forms: ${r}. Voice: call end_voice_session or say you are ending the session to stop.`);
@@ -30256,11 +30289,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30256
30289
  }, 0)));
30257
30290
  }
30258
30291
  })(), () => {
30259
- console.warn("[FlowEngage:VoiceDebug] ⚠️ useEffect CLEANUP fired — session will be killed", {
30260
- agentId: r,
30261
- siteId: i,
30262
- apiBaseUrl: a
30263
- }), e = !0, ne.current = !0;
30292
+ e = !0, ne.current = !0;
30264
30293
  try {
30265
30294
  SD();
30266
30295
  } catch {}
@@ -30268,15 +30297,15 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30268
30297
  He(i);
30269
30298
  } catch {}
30270
30299
  typeof window < "u" && (window.__fe_user_nav_during_speech = null), Ar(), le.current &&= (clearTimeout(le.current), null), ue.current &&= (clearTimeout(ue.current), null), ce.current = !1, de.current = !1, se.current = "idle", c && typeof window < "u" && (window.history.pushState = c), d && typeof window < "u" && window.removeEventListener("popstate", d);
30271
- let t = o || S.current, n = E.current, f = ie.current;
30300
+ let t = o || S.current, n = E.current, r = ie.current;
30272
30301
  if (t?.endSession?.().catch(() => {}), n && s && a) {
30273
- let e = f ? Math.round((Date.now() - f) / 1e3) : 0, t = JSON.stringify({
30302
+ let e = r ? Math.round((Date.now() - r) / 1e3) : 0, t = JSON.stringify({
30274
30303
  chatId: s,
30275
30304
  elevenLabsConversationId: n,
30276
30305
  duration: e,
30277
30306
  siteId: i
30278
- }), r = `${a}/api/voice/save-chat-recording`;
30279
- typeof navigator < "u" && navigator.sendBeacon && navigator.sendBeacon(r, new Blob([t], { type: "application/json" })) || fetch(r, {
30307
+ }), o = `${a}/api/voice/save-chat-recording`;
30308
+ typeof navigator < "u" && navigator.sendBeacon && navigator.sendBeacon(o, new Blob([t], { type: "application/json" })) || fetch(o, {
30280
30309
  method: "POST",
30281
30310
  headers: { "Content-Type": "application/json" },
30282
30311
  body: t,
@@ -30343,7 +30372,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30343
30372
  },
30344
30373
  children: "Muted"
30345
30374
  }),
30346
- /* @__PURE__ */ g(jk, {
30375
+ /* @__PURE__ */ g(Mk, {
30347
30376
  size: 72,
30348
30377
  voiceState: f,
30349
30378
  isMuted: v,
@@ -30581,7 +30610,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30581
30610
  ]
30582
30611
  });
30583
30612
  }
30584
- function Fk({ orbColors: e }) {
30613
+ function Ik({ orbColors: e }) {
30585
30614
  return /* @__PURE__ */ g("div", {
30586
30615
  style: {
30587
30616
  flexShrink: 0,
@@ -30591,13 +30620,13 @@ function Fk({ orbColors: e }) {
30591
30620
  alignItems: "center",
30592
30621
  justifyContent: "center"
30593
30622
  },
30594
- children: /* @__PURE__ */ g(jk, {
30623
+ children: /* @__PURE__ */ g(Mk, {
30595
30624
  size: 36,
30596
30625
  orbColors: e
30597
30626
  })
30598
30627
  });
30599
30628
  }
30600
- var Ik = () => /* @__PURE__ */ g("div", {
30629
+ var Lk = () => /* @__PURE__ */ g("div", {
30601
30630
  style: {
30602
30631
  display: "flex",
30603
30632
  marginBottom: "12px",
@@ -30627,7 +30656,7 @@ var Ik = () => /* @__PURE__ */ g("div", {
30627
30656
  } }, e))
30628
30657
  })
30629
30658
  });
30630
- function Lk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i, quickChatOptions: a, onQuickChatSelect: o, isMobile: s, chatHistory: l, isAiTyping: u, isAgentTyping: d, activeScreen: f, agentName: v, agentHeadshot: y, fallbackAgentName: b, input: x, setInput: S, onSubmit: C, isConversationEnded: w, isLoading: T, isRateLimited: ee, rateLimitMessage: te, selectedFile: ne, onFileSelect: re, onRemoveSelectedFile: E, attachmentError: ie, isUploadingAttachment: ae, requiresEmail: oe, emailInput: D, setEmailInput: se, emailError: ce, emailCaptureSuccess: le, replyContext: ue, setReplyContext: de, webRTCError: fe, micError: pe, setMicError: me, dismissCallError: he, activeCallId: ge, isCallMuted: _e, toggleCallMute: ve, endWebRTCCall: ye, formatCallDuration: be, callDurationSeconds: xe, isCallMinimized: Se, onExpand: Ce, onCollapse: we, onStartVoice: Te, onNewChat: Ee, showPoweredBy: De, getVisitorChatHistory: Oe, resumeChat: ke, isSessionRestoring: Ae, isClosing: je }) {
30659
+ function Rk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i, quickChatOptions: a, onQuickChatSelect: o, isMobile: s, chatHistory: l, isAiTyping: u, isAgentTyping: d, activeScreen: f, agentName: v, agentHeadshot: y, fallbackAgentName: b, input: x, setInput: S, onSubmit: C, isConversationEnded: w, isLoading: T, isRateLimited: ee, rateLimitMessage: te, selectedFile: ne, onFileSelect: re, onRemoveSelectedFile: E, attachmentError: ie, isUploadingAttachment: ae, requiresEmail: oe, emailInput: D, setEmailInput: se, emailError: ce, emailCaptureSuccess: le, replyContext: ue, setReplyContext: de, webRTCError: fe, micError: pe, setMicError: me, dismissCallError: he, activeCallId: ge, isCallMuted: _e, toggleCallMute: ve, endWebRTCCall: ye, formatCallDuration: be, callDurationSeconds: xe, isCallMinimized: Se, onExpand: Ce, onCollapse: we, onStartVoice: Te, onNewChat: Ee, showPoweredBy: De, getVisitorChatHistory: Oe, resumeChat: ke, isSessionRestoring: Ae, isClosing: je }) {
30631
30660
  let Me = l.length > 0, Ne = T || ee || w, Pe = !!ge, [Fe, Ie] = m(!1), [Le, Re] = m(!1), [ze, Be] = m([]), [Ve, He] = m(!1), O = p(null), [Ue, We] = m(() => typeof window < "u" ? window.visualViewport?.height ?? window.innerHeight : 600), [Ge, Ke] = m(0);
30632
30661
  c(() => {
30633
30662
  if (!s) return;
@@ -30763,7 +30792,7 @@ function Lk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
30763
30792
  justifyContent: "center",
30764
30793
  height: "40px"
30765
30794
  },
30766
- children: i ? /* @__PURE__ */ g(Ok, {
30795
+ children: i ? /* @__PURE__ */ g(kk, {
30767
30796
  logo: i,
30768
30797
  style: {
30769
30798
  height: "34px",
@@ -30776,7 +30805,7 @@ function Lk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
30776
30805
  height: "40px",
30777
30806
  flexShrink: 0
30778
30807
  },
30779
- children: /* @__PURE__ */ g(kk, { title: e.chatTitle })
30808
+ children: /* @__PURE__ */ g(Ak, { title: e.chatTitle })
30780
30809
  })
30781
30810
  }), /* @__PURE__ */ g("div", {
30782
30811
  style: {
@@ -31206,11 +31235,11 @@ function Lk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
31206
31235
  isLoading: T,
31207
31236
  isAgentTyping: d,
31208
31237
  setReplyContext: de,
31209
- TypingDots: Ik,
31238
+ TypingDots: Lk,
31210
31239
  primaryColor: n,
31211
31240
  agentHeadshot: y,
31212
31241
  agentDisplayName: v || b,
31213
- botAvatarNode: /* @__PURE__ */ g(Fk, { orbColors: t })
31242
+ botAvatarNode: /* @__PURE__ */ g(Ik, { orbColors: t })
31214
31243
  }) : Ae ? /* @__PURE__ */ _("div", {
31215
31244
  style: {
31216
31245
  flex: 1,
@@ -31251,7 +31280,7 @@ function Lk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
31251
31280
  padding: "28px 24px"
31252
31281
  },
31253
31282
  children: [
31254
- /* @__PURE__ */ g(jk, {
31283
+ /* @__PURE__ */ g(Mk, {
31255
31284
  size: 94,
31256
31285
  orbColors: t
31257
31286
  }),
@@ -31393,34 +31422,34 @@ function Lk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
31393
31422
  ]
31394
31423
  });
31395
31424
  }
31396
- function Rk() {
31425
+ function zk() {
31397
31426
  let { status: e, runtimeConfig: t, resolvedConfig: n, chatHistory: r, isOpen: i, activeScreen: a, isHumanHandled: s, agentName: l, agentHeadshot: u, visitorEmail: h, isAgentTyping: v, isAiTyping: y, isLoading: b, isRateLimited: x, rateLimitMessage: S, isConversationEnded: C, incomingCall: w, activeCallId: T, callConnectionState: ee, callConnectedAt: te, isCallMuted: ne, webRTCError: re, language: E, chatId: ie, historyRef: ae, onMessageSync: oe, sendMessage: D, uploadChatFile: se, openWidget: ce, captureVisitorEmail: le, setVoiceMode: ue, endConversation: de, startNewChat: me, acceptCall: he, rejectCall: ge, endWebRTCCall: _e, toggleCallMute: ve, dismissCallError: ye, startTyping: be, stopTyping: xe, updateTypingDraft: Se, getVisitorChatHistory: Ce, resumeChat: we, isSessionRestoring: Te, openToChatCounter: Ee, voiceEndCounter: De } = Ln();
31398
31427
  c(() => {
31399
31428
  try {
31400
31429
  pr();
31401
31430
  } catch {}
31402
31431
  }, []), c(() => {
31403
- Ee && k !== "voice_mode" && k !== "text_chat" && k !== "call_screen" && (ue?.(!1), ot("text_chat"));
31432
+ Ee && A !== "text_chat" && A !== "call_screen" && (ue?.(!1), st("text_chat"));
31404
31433
  }, [Ee]);
31405
31434
  let Oe = t?.widgetSettings || {}, ke = n?.widgetSettings || {}, Ae = {
31406
31435
  ...Oe.branding || {},
31407
31436
  ...ke.branding || {}
31408
- }, je = {
31437
+ }, Ne = {
31409
31438
  ...Oe.theme || {},
31410
31439
  ...ke.theme || {}
31411
- }, Ne = {
31440
+ }, Pe = {
31412
31441
  ...Oe.features || {},
31413
31442
  ...ke.features || {}
31414
- }, Pe = Ne.voice !== !1, Ie = Array.isArray(je.orbColors) && je.orbColors.length > 0 ? je.orbColors : null, Le = je.buttonColor || je.primaryColor || Ie?.[0] || "#3B82F6", ze = {
31443
+ }, Ie = Pe.voice !== !1, Le = Array.isArray(Ne.orbColors) && Ne.orbColors.length > 0 ? Ne.orbColors : null, ze = Ne.buttonColor || Ne.primaryColor || Le?.[0] || "#3B82F6", Be = {
31415
31444
  small: 50,
31416
31445
  medium: 64,
31417
31446
  large: 80
31418
- }, Be = ze[je.orbSize] || ze.small, Ve = je.position || "bottom-right", He = Ae.fallbackAgentName || "Agent", O = Tk(Ie ?? je.chatBgColors), Ue = Ae.logo || Ae.logoUrl || null, We = E || "en", Ge = Oe.recommendations?.[We] || [], Ke = (ke.recommendations?.[We] ?? Ge).filter((e) => String(e?.label ?? "").trim()).map((e, t) => ({
31447
+ }, Ve = Be[Ne.orbSize] || Be.small, He = Ne.position || "bottom-right", O = Ae.fallbackAgentName || "Agent", Ue = Ek(Le ?? Ne.chatBgColors), We = Ae.logo || Ae.logoUrl || null, Ge = E || "en", Ke = Oe.recommendations?.[Ge] || [], qe = (ke.recommendations?.[Ge] ?? Ke).filter((e) => String(e?.label ?? "").trim()).map((e, t) => ({
31419
31448
  id: e.key || `qr-${t}`,
31420
31449
  label: e.label,
31421
31450
  message: e.label,
31422
31451
  text: e.label
31423
- })), qe = Array.isArray(Ae.quickChatOptions) && Ae.quickChatOptions.length > 0 ? Ae.quickChatOptions : Ke, Je = Ae.hideWatermark === !0 ? !1 : Ae.showPoweredBy !== !1, Ye = Ae.chatbotEnabled !== !1 && je.chatbotEnabled !== !1, Xe = Oe.greetings?.[E] || ke.greetings?.[E] || Ae.introGreeting || "Hello, I'm here to help you know more about OpenSense Labs.", Ze = {
31452
+ })), Je = Array.isArray(Ae.quickChatOptions) && Ae.quickChatOptions.length > 0 ? Ae.quickChatOptions : qe, Ye = Ae.hideWatermark === !0 ? !1 : Ae.showPoweredBy !== !1, Xe = Ae.chatbotEnabled !== !1 && Ne.chatbotEnabled !== !1, Ze = Oe.greetings?.[E] || ke.greetings?.[E] || Ae.introGreeting || "Hello, I'm here to help you know more about OpenSense Labs.", Qe = {
31424
31453
  entryPrompt: Ae.entryPrompt || "Do you want to explore in a new way?",
31425
31454
  yesLabel: Ae.yesLabel || "Yes",
31426
31455
  laterLabel: Ae.laterLabel || "Later",
@@ -31428,184 +31457,189 @@ function Rk() {
31428
31457
  voiceLabel: Ae.voiceLabel || "Voice",
31429
31458
  textLabel: Ae.textLabel || "Text",
31430
31459
  chatTitle: Ae.headerName || "Chat with FlowEngage",
31431
- introGreeting: Xe,
31460
+ introGreeting: Ze,
31432
31461
  inputPlaceholder: Ae.inputPlaceholder || "Type your message",
31433
31462
  analysingLabel: Ae.analysingLabel || "analysing..."
31434
- }, Qe = ke.elevenLabsAgentId || t?.elevenLabsAgentId || null, $e = t?.siteId || n?.siteId || null, et = t?.apiBaseUrl || "", tt = f(() => l && String(l).trim() || t?.ownerName && String(t.ownerName).trim() || t?.websiteName && String(t.websiteName).trim() || "Agent", [
31463
+ }, $e = ke.elevenLabsAgentId || t?.elevenLabsAgentId || null, et = t?.siteId || n?.siteId || null, tt = t?.apiBaseUrl || "", nt = f(() => l && String(l).trim() || t?.ownerName && String(t.ownerName).trim() || t?.websiteName && String(t.websiteName).trim() || "Agent", [
31435
31464
  l,
31436
31465
  t?.ownerName,
31437
31466
  t?.websiteName
31438
- ]), nt = u && String(u).trim() || t?.ownerProfileImageUrl && String(t.ownerProfileImageUrl).trim() || null, rt = r.some((e) => e.sender === "user"), it = f(() => {
31467
+ ]), rt = u && String(u).trim() || t?.ownerProfileImageUrl && String(t.ownerProfileImageUrl).trim() || null, it = r.some((e) => e.sender === "user"), at = f(() => {
31439
31468
  let e = r.findIndex((e) => e.sender === "user");
31440
31469
  return e === -1 ? !1 : r.slice(e + 1).some((e) => e.sender === "bot" || e.sender === "ai" || e.sender === "agent");
31441
- }, [r]), at = !!(ke._dashboardLivePreview || Oe._dashboardLivePreview), [k, ot] = m(() => at ? "text_chat" : "entry_prompt"), [st, ct] = m(""), [lt, ut] = m(null), [dt, ft] = m(h || ""), [pt, mt] = m(""), [ht, gt] = m(!1), [_t, A] = m(0), [vt, yt] = m(null), [j, bt] = m(null), [xt, St] = m(""), [Ct, wt] = m(!1), [Tt, Et] = m(!1), [Dt, Ot] = m(!1), kt = p(null), At = p(!1), jt = !h && rt && it && k !== "voice_mode";
31470
+ }, [r]), k = !h && it && at, ot = !!(ke._dashboardLivePreview || Oe._dashboardLivePreview), [A, st] = m(() => ot ? "text_chat" : "entry_prompt"), [ct, lt] = m(""), [ut, dt] = m(null), [ft, pt] = m(h || ""), [mt, ht] = m(""), [gt, j] = m(!1), [_t, vt] = m(0), [yt, bt] = m(null), [xt, St] = m(null), [Ct, wt] = m(""), [Tt, Et] = m(!1), [Dt, Ot] = m(!1), [kt, At] = m(!1), jt = p(null), Mt = p(!1);
31442
31471
  d(() => {
31443
- if (e !== "ready" || At.current) return;
31444
- if (At.current = !0, !Pe) {
31445
- ot("minimized_orb");
31472
+ if (e !== "ready" || Mt.current) return;
31473
+ if (Mt.current = !0, !Ie) {
31474
+ st("minimized_orb");
31446
31475
  return;
31447
31476
  }
31448
31477
  let t = !1;
31449
31478
  try {
31450
31479
  t = Tr().shouldResumeVoice;
31451
31480
  } catch {}
31452
- if (Fe(), t) {
31453
- ce?.({ notifyChatInitiated: !0 }), ue?.(!0), ot("voice_mode");
31481
+ let n = Fe(), r = et ? je(et) : null, i = n || !!r?.transcript;
31482
+ if (t) {
31483
+ ce?.({ notifyChatInitiated: !0 }), ue?.(!0), st("voice_mode");
31454
31484
  return;
31455
31485
  }
31456
31486
  if (Re()) {
31457
- ce?.({ notifyChatInitiated: !1 }), ot("text_chat");
31487
+ ce?.({ notifyChatInitiated: !1 }), st("text_chat");
31458
31488
  return;
31459
31489
  }
31460
- if ($e) try {
31461
- Me($e);
31490
+ if (et) try {
31491
+ Me(et);
31462
31492
  } catch {}
31463
- if (fe($e)) {
31464
- ot("minimized_orb");
31493
+ if (i) {
31494
+ st("minimized_orb");
31495
+ return;
31496
+ }
31497
+ if (fe(et)) {
31498
+ st("minimized_orb");
31465
31499
  return;
31466
31500
  }
31467
31501
  }, [e, r]);
31468
- let [Mt, Nt] = m(() => typeof window < "u" && window.matchMedia("(max-width: 640px)").matches);
31502
+ let [Nt, Pt] = m(() => typeof window < "u" && window.matchMedia("(max-width: 640px)").matches);
31469
31503
  c(() => {
31470
- let e = window.matchMedia("(max-width: 640px)"), t = (e) => Nt(e.matches);
31504
+ let e = window.matchMedia("(max-width: 640px)"), t = (e) => Pt(e.matches);
31471
31505
  return e.addEventListener("change", t), () => e.removeEventListener("change", t);
31472
31506
  }, []), c(() => {
31473
- ft(h || ""), h && mt("");
31507
+ pt(h || ""), h && ht("");
31474
31508
  }, [h]);
31475
- let Pt = o(() => {
31476
- bt(null), St("");
31477
- }, []), Ft = o((e) => {
31509
+ let Ft = o(() => {
31510
+ St(null), wt("");
31511
+ }, []), It = o((e) => {
31478
31512
  let t = qD(e);
31479
31513
  if (t) {
31480
- bt(null), St(t);
31514
+ St(null), wt(t);
31481
31515
  return;
31482
31516
  }
31483
- bt(e), St("");
31517
+ St(e), wt("");
31484
31518
  }, []);
31485
31519
  c(() => {
31486
31520
  if (!te || ee !== "connected") {
31487
- A(0);
31521
+ vt(0);
31488
31522
  return;
31489
31523
  }
31490
31524
  let e = () => {
31491
31525
  let e = new Date(te).getTime();
31492
- isNaN(e) || A(Math.max(0, Math.floor((Date.now() - e) / 1e3)));
31526
+ isNaN(e) || vt(Math.max(0, Math.floor((Date.now() - e) / 1e3)));
31493
31527
  };
31494
31528
  e();
31495
31529
  let t = window.setInterval(e, 1e3);
31496
31530
  return () => window.clearInterval(t);
31497
31531
  }, [te, ee]);
31498
- let It = o(() => {
31499
- ot("call_screen"), Et(!1);
31500
- }, []), Lt = o(() => {
31501
- ot("text_chat"), Et(!0);
31532
+ let Lt = o(() => {
31533
+ st("call_screen"), Ot(!1);
31534
+ }, []), Rt = o(() => {
31535
+ st("text_chat"), Ot(!0);
31502
31536
  }, []);
31503
31537
  c(() => {
31504
31538
  let e = w?.callId || T || null;
31505
31539
  if (!e) {
31506
- kt.current = null;
31540
+ jt.current = null;
31507
31541
  return;
31508
31542
  }
31509
31543
  if (w?.callId || ee === "connecting" || ee === "connected") {
31510
- if (k === "minimized_orb" && Tt && T && !w?.callId) {
31511
- kt.current = e;
31544
+ if (A === "minimized_orb" && Dt && T && !w?.callId) {
31545
+ jt.current = e;
31512
31546
  return;
31513
31547
  }
31514
- !(!i || k === "minimized_orb" || k === "voice_mode") && kt.current === e || (console.log("[FlowEngageWidget] forcing call UI to front", {
31548
+ !(!i || A === "minimized_orb" || A === "voice_mode") && jt.current === e || (console.log("[FlowEngageWidget] forcing call UI to front", {
31515
31549
  forcedKey: e,
31516
31550
  isOpen: i,
31517
- surface: k,
31551
+ surface: A,
31518
31552
  hasIncomingCall: !!w?.callId,
31519
31553
  activeCallId: T,
31520
31554
  callConnectionState: ee
31521
- }), kt.current = e, k === "voice_mode" && ue?.(!1), ce?.(), It());
31555
+ }), jt.current = e, A === "voice_mode" && ue?.(!1), ce?.(), Lt());
31522
31556
  }
31523
31557
  }, [
31524
31558
  T,
31525
31559
  ee,
31526
- It,
31560
+ Lt,
31527
31561
  w?.callId,
31528
31562
  i,
31529
31563
  ce,
31530
31564
  ue,
31531
- k
31565
+ A
31532
31566
  ]), c(() => {
31533
- !w && !T && k === "call_screen" && ot("text_chat");
31567
+ !w && !T && A === "call_screen" && st("text_chat");
31534
31568
  }, [
31535
31569
  w,
31536
31570
  T,
31537
- k
31571
+ A
31538
31572
  ]), c(() => {
31539
- !T && Tt && Et(!1);
31540
- }, [T, Tt]), c(() => {
31573
+ !T && Dt && Ot(!1);
31574
+ }, [T, Dt]), c(() => {
31541
31575
  if (!s || C) {
31542
31576
  Se?.(""), xe?.();
31543
31577
  return;
31544
31578
  }
31545
- if (!st.trim() || j) {
31579
+ if (!ct.trim() || xt) {
31546
31580
  Se?.("");
31547
31581
  let e = window.setTimeout(() => xe?.(), 100);
31548
31582
  return () => window.clearTimeout(e);
31549
31583
  }
31550
31584
  be?.();
31551
- let e = window.setTimeout(() => Se?.(st), 120), t = window.setTimeout(() => xe?.(), 1200);
31585
+ let e = window.setTimeout(() => Se?.(ct), 120), t = window.setTimeout(() => xe?.(), 1200);
31552
31586
  return () => {
31553
31587
  window.clearTimeout(e), window.clearTimeout(t);
31554
31588
  };
31555
31589
  }, [
31556
- st,
31557
- j,
31590
+ ct,
31591
+ xt,
31558
31592
  s,
31559
31593
  C,
31560
31594
  be,
31561
31595
  xe,
31562
31596
  Se
31563
31597
  ]);
31564
- let Rt = (e) => e ? {
31598
+ let zt = (e) => e ? {
31565
31599
  replyTo: e.messageId || e.id || null,
31566
31600
  replyToContent: (e.replyToContent || e.message || "").replace(/<[^>]+>/g, "").trim().slice(0, 200),
31567
31601
  replyToSender: e.sender || null
31568
- } : null, zt = async (e) => {
31602
+ } : null, Bt = async (e) => {
31569
31603
  if (e.preventDefault(), C) return;
31570
- if (jt) {
31571
- let e = dt.trim().toLowerCase();
31604
+ if (k) {
31605
+ let e = ft.trim().toLowerCase();
31572
31606
  if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)) {
31573
- mt("Please enter a valid email so we can continue helping you.");
31607
+ ht("Please enter a valid email so we can continue helping you.");
31574
31608
  return;
31575
31609
  }
31576
- await le(e), mt(""), gt(!0), setTimeout(() => gt(!1), 3e3);
31610
+ await le(e), ht(""), j(!0), setTimeout(() => j(!1), 3e3);
31577
31611
  return;
31578
31612
  }
31579
- let t = Rt(lt);
31580
- if (!st.trim() && !j) return;
31581
- if (j) {
31613
+ let t = zt(ut);
31614
+ if (!ct.trim() && !xt) return;
31615
+ if (xt) {
31582
31616
  try {
31583
- wt(!0), St("");
31584
- let e = await se(j), n = e?.data || e, r = st.trim() || `Shared file: ${YD(j)}`;
31585
- ct(""), ut(null), Pt(), await D(r, "", t, {
31617
+ Et(!0), wt("");
31618
+ let e = await se(xt), n = e?.data || e, r = ct.trim() || `Shared file: ${YD(xt)}`;
31619
+ lt(""), dt(null), Ft(), await D(r, "", t, {
31586
31620
  type: "file",
31587
31621
  metadata: {
31588
31622
  fileUrl: n?.fileUrl,
31589
- fileName: n?.fileName || j.name,
31590
- fileType: n?.fileType || j.type,
31591
- fileSize: n?.fileSize || j.size
31623
+ fileName: n?.fileName || xt.name,
31624
+ fileType: n?.fileType || xt.type,
31625
+ fileSize: n?.fileSize || xt.size
31592
31626
  }
31593
31627
  });
31594
31628
  } catch (e) {
31595
- St(e?.message || "Failed to upload the selected file.");
31629
+ wt(e?.message || "Failed to upload the selected file.");
31596
31630
  } finally {
31597
- wt(!1);
31631
+ Et(!1);
31598
31632
  }
31599
31633
  return;
31600
31634
  }
31601
- let n = st.trim();
31602
- ct(""), ut(null), await D(n, "", t);
31603
- }, Bt = o(() => {
31635
+ let n = ct.trim();
31636
+ lt(""), dt(null), await D(n, "", t);
31637
+ }, Vt = o(() => {
31604
31638
  r.length !== 0 && me?.();
31605
- }, [r.length, me]), Vt = (e) => {
31639
+ }, [r.length, me]), Ht = (e) => {
31606
31640
  let t = Math.floor(e / 60);
31607
31641
  return `${String(t).padStart(2, "0")}:${String(e % 60).padStart(2, "0")}`;
31608
- }, Ht = o(async (e) => {
31642
+ }, Ut = o(async (e) => {
31609
31643
  if (C || b) return;
31610
31644
  let t = e.message || e.label || e.text || "";
31611
31645
  t.trim() && await D(t.trim(), "");
@@ -31613,44 +31647,44 @@ function Rk() {
31613
31647
  C,
31614
31648
  b,
31615
31649
  D
31616
- ]), Ut = Mt && k === "entry_prompt" ? { inset: 0 } : Mt && k === "text_chat" ? {
31650
+ ]), Wt = Nt && A === "entry_prompt" ? { inset: 0 } : Nt && A === "text_chat" ? {
31617
31651
  left: 0,
31618
31652
  right: 0,
31619
31653
  bottom: 0
31620
- } : Mt && k === "call_screen" ? {
31654
+ } : Nt && A === "call_screen" ? {
31621
31655
  left: 0,
31622
31656
  right: 0,
31623
31657
  bottom: 0,
31624
31658
  height: "90dvh",
31625
31659
  overflow: "hidden",
31626
31660
  borderRadius: "16px 16px 0 0"
31627
- } : Mt && k === "connection_modal" ? {
31661
+ } : Nt && A === "connection_modal" ? {
31628
31662
  left: "12px",
31629
31663
  right: "12px",
31630
31664
  bottom: "12px"
31631
- } : k === "call_screen" ? {
31665
+ } : A === "call_screen" ? {
31632
31666
  width: "min(350px, calc(100vw - 40px))",
31633
31667
  height: "min(640px, calc(100vh - 120px))",
31634
31668
  borderRadius: "22px",
31635
31669
  overflow: "hidden",
31636
- ...Ve === "bottom-left" ? {
31670
+ ...He === "bottom-left" ? {
31637
31671
  left: "1.5rem",
31638
31672
  bottom: "1.5rem"
31639
31673
  } : {
31640
31674
  right: "1.5rem",
31641
31675
  bottom: "1.5rem"
31642
31676
  }
31643
- } : Ve === "bottom-left" ? {
31677
+ } : He === "bottom-left" ? {
31644
31678
  left: "1.5rem",
31645
31679
  bottom: "1.5rem"
31646
31680
  } : {
31647
31681
  right: "1.5rem",
31648
31682
  bottom: "1.5rem"
31649
- }, Wt = o(() => {
31650
- k !== "minimized_orb" && (Ot(!0), setTimeout(() => {
31651
- ot("minimized_orb"), Ot(!1), T && Et(!0);
31683
+ }, Gt = o(() => {
31684
+ A !== "minimized_orb" && (At(!0), setTimeout(() => {
31685
+ st("minimized_orb"), At(!1), T && Ot(!0);
31652
31686
  }, 280));
31653
- }, [T, k]), Gt = () => ot("connection_modal"), Kt = () => {
31687
+ }, [T, A]), Kt = () => st("connection_modal"), qt = () => {
31654
31688
  try {
31655
31689
  let e = window.AudioContext || window.webkitAudioContext;
31656
31690
  if (e) {
@@ -31658,36 +31692,36 @@ function Rk() {
31658
31692
  t.resume().catch(() => {}), setTimeout(() => t.close().catch(() => {}), 3e3);
31659
31693
  }
31660
31694
  } catch {}
31661
- ce({ notifyChatInitiated: !0 }), ue?.(!0), ot("voice_mode");
31662
- }, qt = () => {
31663
- ce({ notifyChatInitiated: !0 }), ue?.(!1), ot("text_chat");
31695
+ ce({ notifyChatInitiated: !0 }), ue?.(!0), st("voice_mode");
31664
31696
  }, Jt = () => {
31665
- ue?.(!1), Wt();
31697
+ ce({ notifyChatInitiated: !0 }), ue?.(!1), st("text_chat");
31698
+ }, Yt = () => {
31699
+ ue?.(!1), Gt();
31666
31700
  };
31667
- return e !== "ready" || !Ye || Ne.chat === !1 ? null : /* @__PURE__ */ _("div", {
31701
+ return e !== "ready" || !Xe || Pe.chat === !1 ? null : /* @__PURE__ */ _("div", {
31668
31702
  className: "flowengage-widget-root",
31669
31703
  style: {
31670
31704
  position: "fixed",
31671
31705
  zIndex: 999999,
31672
- ...Ut
31706
+ ...Wt
31673
31707
  },
31674
31708
  onWheel: (e) => e.stopPropagation(),
31675
31709
  onTouchMove: (e) => e.stopPropagation(),
31676
31710
  children: [
31677
- k === "entry_prompt" && /* @__PURE__ */ g(Mk, {
31678
- copy: Ze,
31679
- orbColors: Ie,
31680
- primaryColor: Le,
31711
+ A === "entry_prompt" && /* @__PURE__ */ g(Nk, {
31712
+ copy: Qe,
31713
+ orbColors: Le,
31714
+ primaryColor: ze,
31681
31715
  onYes: () => {
31682
- pe($e), Kt();
31716
+ pe(et), qt();
31683
31717
  },
31684
31718
  onLater: () => {
31685
- pe($e), Wt();
31719
+ pe(et), Gt();
31686
31720
  },
31687
- isMobile: Mt,
31688
- isClosing: Dt
31721
+ isMobile: Nt,
31722
+ isClosing: kt
31689
31723
  }),
31690
- k === "minimized_orb" && /* @__PURE__ */ _(Dm.div, {
31724
+ A === "minimized_orb" && /* @__PURE__ */ _(Dm.div, {
31691
31725
  layoutId: "fe-main-orb",
31692
31726
  initial: {
31693
31727
  scale: .4,
@@ -31706,14 +31740,14 @@ function Rk() {
31706
31740
  transformOrigin: "bottom right",
31707
31741
  display: "inline-flex",
31708
31742
  flexDirection: "column",
31709
- alignItems: Ve === "bottom-left" ? "flex-start" : "flex-end",
31743
+ alignItems: He === "bottom-left" ? "flex-start" : "flex-end",
31710
31744
  gap: "10px"
31711
31745
  },
31712
31746
  children: [T && /* @__PURE__ */ _("button", {
31713
31747
  type: "button",
31714
- onClick: It,
31748
+ onClick: Lt,
31715
31749
  style: {
31716
- maxWidth: Mt ? "220px" : "240px",
31750
+ maxWidth: Nt ? "220px" : "240px",
31717
31751
  padding: "10px 14px",
31718
31752
  borderRadius: "18px",
31719
31753
  border: "1px solid rgba(255,255,255,0.7)",
@@ -31754,109 +31788,109 @@ function Rk() {
31754
31788
  marginTop: "2px",
31755
31789
  whiteSpace: "nowrap"
31756
31790
  },
31757
- children: ee === "connected" ? `${Vt(_t)} with ${tt}` : `Tap to return to ${tt}`
31791
+ children: ee === "connected" ? `${Ht(_t)} with ${nt}` : `Tap to return to ${nt}`
31758
31792
  })]
31759
31793
  })]
31760
- }), /* @__PURE__ */ g(jk, {
31761
- size: Be,
31762
- orbColors: Ie,
31763
- onClick: T ? It : Pe ? Gt : qt
31794
+ }), /* @__PURE__ */ g(Mk, {
31795
+ size: Ve,
31796
+ orbColors: Le,
31797
+ onClick: T ? Lt : Ie ? Kt : Jt
31764
31798
  })]
31765
31799
  }),
31766
- k === "connection_modal" && /* @__PURE__ */ g(Nk, {
31767
- copy: Ze,
31768
- orbColors: Ie,
31769
- primaryColor: Le,
31770
- onVoice: Kt,
31771
- onText: qt,
31772
- onClose: Wt,
31773
- isMobile: Mt,
31774
- isClosing: Dt
31800
+ A === "connection_modal" && /* @__PURE__ */ g(Pk, {
31801
+ copy: Qe,
31802
+ orbColors: Le,
31803
+ primaryColor: ze,
31804
+ onVoice: qt,
31805
+ onText: Jt,
31806
+ onClose: Gt,
31807
+ isMobile: Nt,
31808
+ isClosing: kt
31775
31809
  }),
31776
- k === "voice_mode" && /* @__PURE__ */ g(Pk, {
31777
- orbColors: Ie,
31778
- onEnterChat: qt,
31779
- onEndChat: Jt,
31780
- agentId: Qe,
31781
- siteId: $e,
31782
- apiBaseUrl: et,
31810
+ A === "voice_mode" && /* @__PURE__ */ g(Fk, {
31811
+ orbColors: Le,
31812
+ onEnterChat: Jt,
31813
+ onEndChat: Yt,
31814
+ agentId: $e,
31815
+ siteId: et,
31816
+ apiBaseUrl: tt,
31783
31817
  chatId: ie,
31784
31818
  historyRef: ae,
31785
31819
  onMessageSync: oe,
31786
31820
  voiceEndCounter: De
31787
31821
  }, "voice"),
31788
- k === "call_screen" && /* @__PURE__ */ g(gO, {
31822
+ A === "call_screen" && /* @__PURE__ */ g(gO, {
31789
31823
  incomingCall: w,
31790
31824
  activeCallId: T,
31791
31825
  callConnectionState: ee,
31792
31826
  callDurationSeconds: _t,
31793
31827
  isCallMuted: ne,
31794
- agentName: tt,
31795
- agentHeadshot: nt,
31796
- fallbackAgentName: He,
31828
+ agentName: nt,
31829
+ agentHeadshot: rt,
31830
+ fallbackAgentName: O,
31797
31831
  acceptCall: he,
31798
31832
  rejectCall: ge,
31799
31833
  endWebRTCCall: _e,
31800
31834
  toggleCallMute: ve,
31801
- formatCallDuration: Vt,
31802
- onMinimize: Lt,
31803
- primaryColor: Le,
31804
- orbColors: Ie,
31835
+ formatCallDuration: Ht,
31836
+ onMinimize: Rt,
31837
+ primaryColor: ze,
31838
+ orbColors: Le,
31805
31839
  chatHistory: r
31806
31840
  }),
31807
- k === "text_chat" && /* @__PURE__ */ g(Lk, {
31808
- isClosing: Dt,
31809
- copy: Ze,
31810
- orbColors: Ie,
31811
- primaryColor: Le,
31812
- chatBgGradient: O,
31813
- logo: Ue,
31814
- quickChatOptions: qe,
31815
- onQuickChatSelect: Ht,
31816
- isMobile: Mt,
31841
+ A === "text_chat" && /* @__PURE__ */ g(Rk, {
31842
+ isClosing: kt,
31843
+ copy: Qe,
31844
+ orbColors: Le,
31845
+ primaryColor: ze,
31846
+ chatBgGradient: Ue,
31847
+ logo: We,
31848
+ quickChatOptions: Je,
31849
+ onQuickChatSelect: Ut,
31850
+ isMobile: Nt,
31817
31851
  chatHistory: r,
31818
31852
  isAiTyping: y,
31819
31853
  isAgentTyping: v,
31820
31854
  activeScreen: a,
31821
- agentName: tt,
31822
- agentHeadshot: nt,
31823
- fallbackAgentName: He,
31824
- input: st,
31825
- setInput: ct,
31826
- onSubmit: zt,
31855
+ agentName: nt,
31856
+ agentHeadshot: rt,
31857
+ fallbackAgentName: O,
31858
+ input: ct,
31859
+ setInput: lt,
31860
+ onSubmit: Bt,
31827
31861
  isConversationEnded: C,
31828
31862
  isLoading: b,
31829
31863
  isRateLimited: x,
31830
31864
  rateLimitMessage: S,
31831
- selectedFile: j,
31832
- onFileSelect: Ft,
31833
- onRemoveSelectedFile: Pt,
31834
- attachmentError: xt,
31835
- isUploadingAttachment: Ct,
31836
- requiresEmail: jt,
31837
- emailInput: dt,
31838
- setEmailInput: ft,
31839
- emailError: pt,
31840
- emailCaptureSuccess: ht,
31841
- replyContext: lt,
31842
- setReplyContext: ut,
31865
+ selectedFile: xt,
31866
+ onFileSelect: It,
31867
+ onRemoveSelectedFile: Ft,
31868
+ attachmentError: Ct,
31869
+ isUploadingAttachment: Tt,
31870
+ requiresEmail: k,
31871
+ emailInput: ft,
31872
+ setEmailInput: pt,
31873
+ emailError: mt,
31874
+ emailCaptureSuccess: gt,
31875
+ replyContext: ut,
31876
+ setReplyContext: dt,
31843
31877
  webRTCError: re,
31844
- micError: vt,
31845
- setMicError: yt,
31878
+ micError: yt,
31879
+ setMicError: bt,
31846
31880
  dismissCallError: ye,
31847
31881
  activeCallId: T,
31848
31882
  isCallMuted: ne,
31849
31883
  toggleCallMute: ve,
31850
31884
  endWebRTCCall: _e,
31851
- formatCallDuration: Vt,
31885
+ formatCallDuration: Ht,
31852
31886
  callDurationSeconds: _t,
31853
- onCollapse: Wt,
31854
- onStartVoice: Kt,
31855
- onNewChat: Bt,
31856
- onMinimize: Lt,
31857
- onExpand: It,
31887
+ onCollapse: Gt,
31888
+ onStartVoice: qt,
31889
+ onNewChat: Vt,
31890
+ onMinimize: Rt,
31891
+ onExpand: Lt,
31858
31892
  isCallMinimized: !!T,
31859
- showPoweredBy: Je,
31893
+ showPoweredBy: Ye,
31860
31894
  getVisitorChatHistory: Ce,
31861
31895
  resumeChat: we,
31862
31896
  isSessionRestoring: Te
@@ -31867,7 +31901,7 @@ function Rk() {
31867
31901
  }
31868
31902
  //#endregion
31869
31903
  //#region src/components/ErrorBoundary.jsx
31870
- var zk = class extends e.Component {
31904
+ var Bk = class extends e.Component {
31871
31905
  constructor(e) {
31872
31906
  super(e), this.state = { hasError: !1 };
31873
31907
  }
@@ -31882,4 +31916,4 @@ var zk = class extends e.Component {
31882
31916
  }
31883
31917
  };
31884
31918
  //#endregion
31885
- export { lO as AnimatedOrb, zk as ErrorBoundary, Rr as FlowEngageProvider, Rk as FlowEngageWidget, Ln as useFlowEngage };
31919
+ export { lO as AnimatedOrb, Bk as ErrorBoundary, Rr as FlowEngageProvider, zk as FlowEngageWidget, Ln as useFlowEngage };