@flowengage/react-chatbot 4.0.3 → 4.0.5

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.
@@ -2,20 +2,20 @@
2
2
  import e, { Component as t, Fragment as n, createContext as r, createElement as i, forwardRef as a, useCallback as o, useContext as s, useEffect as c, useId as l, useInsertionEffect as u, useLayoutEffect as d, useMemo as f, useRef as p, useState as m } from "react";
3
3
  import { Fragment as h, jsx as g, jsxs as _ } from "react/jsx-runtime";
4
4
  //#region \0rolldown/runtime.js
5
- var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.getOwnPropertyNames, x = Object.prototype.hasOwnProperty, S = (e, t) => () => (e && (t = e(e = 0)), t), ee = (e, t) => {
5
+ var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.getOwnPropertyNames, x = Object.prototype.hasOwnProperty, S = (e, t) => () => (e && (t = e(e = 0)), t), C = (e, t) => {
6
6
  let n = {};
7
7
  for (var r in e) v(n, r, {
8
8
  get: e[r],
9
9
  enumerable: !0
10
10
  });
11
11
  return t || v(n, Symbol.toStringTag, { value: "Module" }), n;
12
- }, C = (e, t, n, r) => {
12
+ }, w = (e, t, n, r) => {
13
13
  if (t && typeof t == "object" || typeof t == "function") for (var i = b(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !x.call(e, s) && s !== n && v(e, s, {
14
14
  get: ((e) => t[e]).bind(null, s),
15
15
  enumerable: !(r = y(t, s)) || r.enumerable
16
16
  });
17
17
  return e;
18
- }, te = (e) => x.call(e, "module.exports") ? e["module.exports"] : C(v({}, "__esModule", { value: !0 }), e), w = (e) => {
18
+ }, T = (e) => x.call(e, "module.exports") ? e["module.exports"] : w(v({}, "__esModule", { value: !0 }), e), ee = (e) => {
19
19
  if (!e || typeof e != "object") throw Error("FlowEngage config is required");
20
20
  if (!e.siteId || typeof e.siteId != "string") throw Error("[FlowEngage] config.siteId is required. Pass it as <FlowEngageProvider siteId=\"your-site-id\" /> or config={{ siteId: 'your-site-id' }}.");
21
21
  let t = (e.apiBaseUrl || "https://be-flowengage-stage.oslabs.app").replace(/\/+$/, "");
@@ -23,10 +23,10 @@ var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.g
23
23
  siteId: e.siteId.trim(),
24
24
  apiBaseUrl: t
25
25
  };
26
- }, T = (e, t) => {
26
+ }, te = (e, t) => {
27
27
  let n = Number.parseInt(String(e ?? ""), 10);
28
28
  return Number.isFinite(n) && n > 0 ? n : t;
29
- }, ne = T(void 0, 1e4), re = T(void 0, 15e3), E = {
29
+ }, ne = te(void 0, 1e4), re = te(void 0, 15e3), E = {
30
30
  chatId: "flowengage.chatId",
31
31
  isOpen: "flowengage.isOpen",
32
32
  activeScreen: "flowengage.activeScreen",
@@ -344,16 +344,6 @@ var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.g
344
344
  async getVisitorChatThread(e) {
345
345
  return a(`/api/visitors/my-chats/${e}`, { method: "GET" });
346
346
  },
347
- async submitFeedback(e, t, n = "") {
348
- return a("/api/chat/feedback", {
349
- method: "POST",
350
- body: JSON.stringify({
351
- chatId: e,
352
- rating: t,
353
- comment: n
354
- })
355
- });
356
- },
357
347
  async getSignedVoiceUrl(e) {
358
348
  return a(`/api/voice/signed-url?chatId=${encodeURIComponent(e)}`, { method: "GET" });
359
349
  },
@@ -471,7 +461,7 @@ var Qe = (e) => {
471
461
  }, $e = typeof ArrayBuffer == "function", et = (e, t) => {
472
462
  if (typeof e != "string") return {
473
463
  type: "message",
474
- data: nt(e, t)
464
+ data: O(e, t)
475
465
  };
476
466
  let n = e.charAt(0);
477
467
  return n === "b" ? {
@@ -481,30 +471,30 @@ var Qe = (e) => {
481
471
  type: Be[n],
482
472
  data: e.substring(1)
483
473
  } : { type: Be[n] } : Ve;
484
- }, tt = (e, t) => $e ? nt(Qe(e), t) : {
474
+ }, tt = (e, t) => $e ? O(Qe(e), t) : {
485
475
  base64: !0,
486
476
  data: e
487
- }, nt = (e, t) => {
477
+ }, O = (e, t) => {
488
478
  switch (t) {
489
479
  case "blob": return e instanceof Blob ? e : new Blob([e]);
490
480
  default: return e instanceof ArrayBuffer ? e : e.buffer;
491
481
  }
492
- }, rt = "", it = (e, t) => {
482
+ }, nt = "", rt = (e, t) => {
493
483
  let n = e.length, r = Array(n), i = 0;
494
484
  e.forEach((e, a) => {
495
485
  Ge(e, !1, (e) => {
496
- r[a] = e, ++i === n && t(r.join(rt));
486
+ r[a] = e, ++i === n && t(r.join(nt));
497
487
  });
498
488
  });
499
- }, at = (e, t) => {
500
- let n = e.split(rt), r = [];
489
+ }, it = (e, t) => {
490
+ let n = e.split(nt), r = [];
501
491
  for (let e = 0; e < n.length; e++) {
502
492
  let i = et(n[e], t);
503
493
  if (r.push(i), i.type === "error") break;
504
494
  }
505
495
  return r;
506
496
  };
507
- function O() {
497
+ function at() {
508
498
  return new TransformStream({ transform(e, t) {
509
499
  Ye(e, (n) => {
510
500
  let r = n.length, i;
@@ -721,7 +711,7 @@ var wt = class extends Error {
721
711
  this._polling = !0, this.doPoll(), this.emitReserved("poll");
722
712
  }
723
713
  onData(e) {
724
- at(e, this.socket.binaryType).forEach((e) => {
714
+ it(e, this.socket.binaryType).forEach((e) => {
725
715
  if (this.readyState === "opening" && e.type === "open" && this.onOpen(), e.type === "close") return this.onClose({ description: "transport closed by the server" }), !1;
726
716
  this.onPacket(e);
727
717
  }), this.readyState !== "closed" && (this._polling = !1, this.emitReserved("pollComplete"), this.readyState === "open" && this._poll());
@@ -733,7 +723,7 @@ var wt = class extends Error {
733
723
  this.readyState === "open" ? e() : this.once("open", e);
734
724
  }
735
725
  write(e) {
736
- this.writable = !1, it(e, (e) => {
726
+ this.writable = !1, rt(e, (e) => {
737
727
  this.doWrite(e, () => {
738
728
  this.writable = !0, this.emitReserved("drain");
739
729
  });
@@ -931,7 +921,7 @@ var It = typeof navigator < "u" && typeof navigator.product == "string" && navig
931
921
  this.onError("webtransport error", e);
932
922
  }), this._transport.ready.then(() => {
933
923
  this._transport.createBidirectionalStream().then((e) => {
934
- let t = lt(2 ** 53 - 1, this.socket.binaryType), n = e.readable.pipeThrough(t).getReader(), r = O();
924
+ let t = lt(2 ** 53 - 1, this.socket.binaryType), n = e.readable.pipeThrough(t).getReader(), r = at();
935
925
  r.readable.pipeTo(e.writable), this._writer = r.writable.getWriter();
936
926
  let i = () => {
937
927
  n.read().then(({ done: e, value: t }) => {
@@ -1289,7 +1279,7 @@ function cn(e, t) {
1289
1279
  }
1290
1280
  //#endregion
1291
1281
  //#region node_modules/socket.io-parser/build/esm/index.js
1292
- var ln = /* @__PURE__ */ ee({
1282
+ var ln = /* @__PURE__ */ C({
1293
1283
  Decoder: () => fn,
1294
1284
  Encoder: () => dn,
1295
1285
  PacketType: () => A,
@@ -2759,26 +2749,26 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
2759
2749
  let i = f(() => e ? {
2760
2750
  ...t || {},
2761
2751
  siteId: e
2762
- } : 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([]), [ee, C] = m(ve().isOpen), [te, T] = 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(""), [Pe, Fe] = m(!1), [ze, Be] = m(!1), [Ve, He] = m(!1), [Ue, We] = m(!1), [Ge, Ke] = 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), O = p(null), ot = p(""), st = p(!1), ct = p(null), lt = p(null), k = p(null), ut = p(null), dt = p(null), ft = p(null), pt = p([]), mt = p(null), ht = p(null), gt = p(null), _t = p(!1), vt = p(!1), yt = p(""), bt = p(null), xt = p(null), St = p([]), Ct = p(0), wt = p(E), Tt = p([]), Et = p(!1), Dt = p({
2752
+ } : 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(""), [Pe, Fe] = m(!1), [ze, Be] = m(!1), [Ve, He] = m(null), [Ue, We] = m(null), [Ge, Ke] = m("idle"), [qe, Je] = m(null), [Ye, Xe] = m(!1), [Ze, Qe] = m(""), [$e, et] = m(!1), tt = p(null), O = p(null), nt = p(""), rt = p(!1), it = p(null), at = p(null), ot = p(null), st = p(null), ct = p(null), lt = p(null), k = p([]), ut = p(null), dt = p(null), ft = p(null), pt = p(!1), mt = p(!1), ht = p(""), gt = p(null), _t = p(null), vt = p([]), yt = p(0), bt = p(E), xt = p([]), St = p(!1), Ct = p({
2763
2753
  notifyRouteChange: () => {},
2764
2754
  cleanup: () => {}
2765
- }), Ot = o((e = {}) => {
2755
+ }), wt = o((e = {}) => {
2766
2756
  let t = !!e.is_human_handled;
2767
- return re(t), t ? (T("agent"), e.agent_info?.name && D(e.agent_info.name), e.agent_info?.headshot && de(e.agent_info.headshot), t) : (T("ai"), t);
2768
- }, []), kt = f(() => {
2757
+ return re(t), t ? (te("agent"), e.agent_info?.name && D(e.agent_info.name), e.agent_info?.headshot && de(e.agent_info.headshot), t) : (te("ai"), t);
2758
+ }, []), Tt = f(() => {
2769
2759
  let e = _?.widgetSettings?.call?.maxDurationSeconds ?? i?.widgetSettings?.call?.maxDurationSeconds ?? i?.callMaxDurationSeconds, t = Number(e);
2770
2760
  return Number.isFinite(t) && t > 0 ? t : ae;
2771
2761
  }, [i, _]);
2772
2762
  c(() => {
2773
- lt.current = Ge;
2774
- }, [Ge]), c(() => {
2775
- wt.current = E;
2763
+ at.current = Ve;
2764
+ }, [Ve]), c(() => {
2765
+ bt.current = E;
2776
2766
  }, [E]);
2777
- let At = () => {
2778
- nt("");
2779
- }, jt = o(() => {
2780
- gt.current &&= (window.clearTimeout(gt.current), null);
2781
- }, []), Mt = (e) => {
2767
+ let Et = () => {
2768
+ Qe("");
2769
+ }, Dt = o(() => {
2770
+ ft.current &&= (window.clearTimeout(ft.current), null);
2771
+ }, []), Ot = (e) => {
2782
2772
  let t = typeof e == "string" ? e.trim().toLowerCase() : "";
2783
2773
  return pe(t), xe(t, i?.siteId), t;
2784
2774
  };
@@ -2786,12 +2776,12 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
2786
2776
  let e = i?.siteId;
2787
2777
  e && pe(be(e));
2788
2778
  }, [i?.siteId]);
2789
- let Nt = (e = "unspecified") => {
2790
- let t = mt.current || ft.current?.callId, n = Ct.current, r = bt.current;
2791
- if (bt.current = null, Ct.current = 0, r && r.state !== "inactive") {
2779
+ let kt = (e = "unspecified") => {
2780
+ let t = ut.current || lt.current?.callId, n = yt.current, r = gt.current;
2781
+ if (gt.current = null, yt.current = 0, r && r.state !== "inactive") {
2792
2782
  r.onstop = () => {
2793
- let e = St.current;
2794
- if (St.current = [], e.length > 0 && t && O.current) {
2783
+ let e = vt.current;
2784
+ if (vt.current = [], e.length > 0 && t && O.current) {
2795
2785
  let r = new Blob(e, { type: e[0].type }), i = n > 0 ? Math.round((Date.now() - n) / 1e3) : 0;
2796
2786
  O.current.uploadRecording(t, r, i).then((e) => console.log("[FlowEngageCall] recording upload success", e)).catch((e) => console.warn("[FlowEngageCall] recording upload failed", e));
2797
2787
  }
@@ -2799,121 +2789,121 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
2799
2789
  try {
2800
2790
  r.stop();
2801
2791
  } catch {
2802
- r.onstop = null, St.current = [];
2792
+ r.onstop = null, vt.current = [];
2803
2793
  }
2804
2794
  } else if (r && r.state === "inactive") {
2805
- let e = St.current;
2806
- if (St.current = [], e.length > 0 && t && O.current) {
2795
+ let e = vt.current;
2796
+ if (vt.current = [], e.length > 0 && t && O.current) {
2807
2797
  let r = new Blob(e, { type: e[0].type }), i = n > 0 ? Math.round((Date.now() - n) / 1e3) : 0;
2808
2798
  O.current.uploadRecording(t, r, i).then((e) => console.log("[FlowEngageCall] recording upload success", e)).catch((e) => console.warn("[FlowEngageCall] recording upload failed", e));
2809
2799
  }
2810
- } else St.current = [];
2811
- if (xt.current) {
2800
+ } else vt.current = [];
2801
+ if (_t.current) {
2812
2802
  try {
2813
- xt.current.close();
2803
+ _t.current.close();
2814
2804
  } catch {}
2815
- xt.current = null;
2805
+ _t.current = null;
2816
2806
  }
2817
- k.current &&= (k.current.close(), null), ut.current &&= (ut.current.getTracks().forEach((e) => e.stop()), null), dt.current &&= (dt.current.srcObject = null, dt.current.remove(), null), jt(), ft.current = null, pt.current = [], mt.current = null, ht.current = null, _t.current = !1, et(!1), Ke(null), Je(null), Xe("idle"), Qe(null);
2818
- }, Pt = (e = (/* @__PURE__ */ new Date()).toISOString()) => {
2819
- let t = at.current, n = mt.current || ft.current?.callId;
2820
- if (!(!t?.connected || !n || _t.current)) {
2821
- _t.current = !0, t.emit("call:connected", {
2807
+ ot.current &&= (ot.current.close(), null), st.current &&= (st.current.getTracks().forEach((e) => e.stop()), null), ct.current &&= (ct.current.srcObject = null, ct.current.remove(), null), Dt(), lt.current = null, k.current = [], ut.current = null, dt.current = null, pt.current = !1, Xe(!1), He(null), We(null), Ke("idle"), Je(null);
2808
+ }, At = (e = (/* @__PURE__ */ new Date()).toISOString()) => {
2809
+ let t = tt.current, n = ut.current || lt.current?.callId;
2810
+ if (!(!t?.connected || !n || pt.current)) {
2811
+ pt.current = !0, t.emit("call:connected", {
2822
2812
  callId: n,
2823
- chatId: ot.current,
2813
+ chatId: nt.current,
2824
2814
  connectedAt: e
2825
2815
  });
2826
2816
  try {
2827
- let e = ut.current, t = dt.current?.srcObject;
2828
- if (e && t && !bt.current) {
2829
- St.current = [];
2817
+ let e = st.current, t = ct.current?.srcObject;
2818
+ if (e && t && !gt.current) {
2819
+ vt.current = [];
2830
2820
  let n = new (window.AudioContext || window.webkitAudioContext)();
2831
- xt.current = n;
2821
+ _t.current = n;
2832
2822
  let r = n.createMediaStreamDestination();
2833
2823
  n.createMediaStreamSource(e).connect(r), n.createMediaStreamSource(t).connect(r);
2834
2824
  let i = window.MediaRecorder.isTypeSupported("audio/webm") ? "audio/webm" : "audio/mp4", a = new window.MediaRecorder(r.stream, { mimeType: i });
2835
2825
  a.ondataavailable = (e) => {
2836
- e.data && e.data.size > 0 && St.current.push(e.data);
2837
- }, bt.current = a, Ct.current = Date.now(), a.start(1e3);
2826
+ e.data && e.data.size > 0 && vt.current.push(e.data);
2827
+ }, gt.current = a, yt.current = Date.now(), a.start(1e3);
2838
2828
  }
2839
2829
  } catch {}
2840
2830
  }
2841
- }, Ft = (e = {}) => {
2831
+ }, jt = (e = {}) => {
2842
2832
  if (!e.callId) return;
2843
- let t = ht.current === e.callId, n = mt.current === e.callId, r = lt.current?.callId === e.callId;
2833
+ let t = dt.current === e.callId, n = ut.current === e.callId, r = at.current?.callId === e.callId;
2844
2834
  if (!(!t && !n && !r)) {
2845
- if (jt(), Ke(null), t || n) {
2846
- mt.current = e.callId, Je(e.callId), Xe((e) => e === "connected" ? e : "connecting"), C(!0);
2835
+ if (Dt(), He(null), t || n) {
2836
+ ut.current = e.callId, We(e.callId), Ke((e) => e === "connected" ? e : "connecting"), w(!0);
2847
2837
  return;
2848
2838
  }
2849
- Xe("idle");
2839
+ Ke("idle");
2850
2840
  }
2851
- }, It = (e = {}) => {
2841
+ }, Mt = (e = {}) => {
2852
2842
  if (!e.callId) return;
2853
- let t = ht.current === e.callId, n = mt.current === e.callId, r = lt.current?.callId === e.callId;
2843
+ let t = dt.current === e.callId, n = ut.current === e.callId, r = at.current?.callId === e.callId;
2854
2844
  if (!(!t && !n && !r)) {
2855
- if (jt(), n) {
2856
- Nt();
2845
+ if (Dt(), n) {
2846
+ kt();
2857
2847
  return;
2858
2848
  }
2859
- ht.current = null, ft.current = null, pt.current = [], Ke(null), Xe("idle");
2849
+ dt.current = null, lt.current = null, k.current = [], He(null), Ke("idle");
2860
2850
  }
2861
- }, Lt = async (e = {}) => {
2862
- let t = k.current, n = at.current, r = e.sdpOffer || e.offer?.sdp;
2851
+ }, Nt = async (e = {}) => {
2852
+ let t = ot.current, n = tt.current, r = e.sdpOffer || e.offer?.sdp;
2863
2853
  if (!t || !n?.connected || !r || !e.callId) {
2864
2854
  console.log("[FlowEngageProvider] deferring remote offer until peer/socket ready", {
2865
2855
  callId: e.callId,
2866
- chatId: ot.current,
2856
+ chatId: nt.current,
2867
2857
  hasPeerConnection: !!t,
2868
2858
  socketConnected: !!n?.connected,
2869
2859
  hasOffer: !!r
2870
- }), ft.current = e;
2860
+ }), lt.current = e;
2871
2861
  return;
2872
2862
  }
2873
2863
  if (await t.setRemoteDescription(new RTCSessionDescription({
2874
2864
  type: "offer",
2875
2865
  sdp: r
2876
- })), pt.current.length > 0) {
2866
+ })), k.current.length > 0) {
2877
2867
  console.log("[FlowEngageProvider] flushing queued agent ICE candidates after remote offer", {
2878
2868
  callId: e.callId,
2879
- chatId: ot.current,
2880
- queuedCount: pt.current.length
2869
+ chatId: nt.current,
2870
+ queuedCount: k.current.length
2881
2871
  });
2882
- for (let e of pt.current) await t.addIceCandidate(new RTCIceCandidate(e));
2883
- pt.current = [];
2872
+ for (let e of k.current) await t.addIceCandidate(new RTCIceCandidate(e));
2873
+ k.current = [];
2884
2874
  }
2885
2875
  let i = await t.createAnswer();
2886
2876
  await t.setLocalDescription(i), n.emit("call:answer", {
2887
2877
  callId: e.callId,
2888
2878
  sdpAnswer: i.sdp,
2889
- chatId: ot.current
2879
+ chatId: nt.current
2890
2880
  });
2891
2881
  };
2892
2882
  c(() => {
2893
2883
  ye({
2894
- isOpen: ee,
2895
- activeScreen: te,
2884
+ isOpen: C,
2885
+ activeScreen: T,
2896
2886
  isHumanHandled: ne,
2897
2887
  agentName: E,
2898
2888
  agentHeadshot: se
2899
2889
  });
2900
2890
  }, [
2901
- ee,
2902
- te,
2891
+ C,
2892
+ T,
2903
2893
  ne,
2904
2894
  E,
2905
2895
  se
2906
2896
  ]), c(() => {
2907
2897
  let e = !0;
2908
2898
  return (async () => {
2909
- it(!0);
2899
+ et(!0);
2910
2900
  try {
2911
- let t = w(i), n = await Le(t);
2901
+ let t = ee(i), n = await Le(t);
2912
2902
  if (!e) return;
2913
2903
  let a = t.siteId, o = he(a), s = Te(a), c = "";
2914
2904
  try {
2915
- let e = st.current, r = ct.current;
2916
- if (st.current = !1, ct.current = null, c = (await Ie({
2905
+ let e = rt.current, r = it.current;
2906
+ if (rt.current = !1, it.current = null, c = (await Ie({
2917
2907
  apiBaseUrl: t.apiBaseUrl,
2918
2908
  userId: n.userId,
2919
2909
  siteId: a,
@@ -2926,7 +2916,7 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
2926
2916
  } catch (e) {
2927
2917
  console.warn("[FlowEngageProvider] resolve-session failed, reusing persisted or ephemeral chat id", e?.message || e), c = o || ue(), _e(a, c);
2928
2918
  }
2929
- ot.current = c;
2919
+ nt.current = c;
2930
2920
  let l = Re({
2931
2921
  apiBaseUrl: t.apiBaseUrl,
2932
2922
  userId: n.userId,
@@ -2943,7 +2933,7 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
2943
2933
  chatId: c,
2944
2934
  siteId: t.siteId
2945
2935
  });
2946
- at.current = f, f.on("connect", () => {
2936
+ tt.current = f, f.on("connect", () => {
2947
2937
  De("connected");
2948
2938
  }), f.on("disconnect", () => {
2949
2939
  De("disconnected");
@@ -2986,20 +2976,20 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
2986
2976
  ...n,
2987
2977
  isPending: !1,
2988
2978
  id: n.messageId || `${n.sender}-${Date.now()}-${Math.random()}`
2989
- }]), (n.sender === "agent" || n.agent_name) && (re(!0), T("agent"), D(xr([
2979
+ }]), (n.sender === "agent" || n.agent_name) && (re(!0), te("agent"), D(xr([
2990
2980
  n.agent_name,
2991
2981
  n.agentName,
2992
2982
  n.metadata?.agentName
2993
- ], d)), n.sender_headshot && de(n.sender_headshot), C(!0));
2983
+ ], d)), n.sender_headshot && de(n.sender_headshot), w(!0));
2994
2984
  });
2995
2985
  let p = (e = {}) => {
2996
2986
  let t = xr([
2997
2987
  e.agent?.name,
2998
2988
  e.agentName,
2999
2989
  e.agent_name,
3000
- wt.current
2990
+ bt.current
3001
2991
  ], d);
3002
- re(!0), T("agent"), D(t), de(e.agent?.headshot || null), C(!0), S((e) => Sr(e, {
2992
+ re(!0), te("agent"), D(t), de(e.agent?.headshot || null), w(!0), S((e) => Sr(e, {
3003
2993
  id: `agent-joined-${Date.now()}`,
3004
2994
  sender: "system",
3005
2995
  message: `${t} has joined the chat.`,
@@ -3011,9 +3001,9 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
3011
3001
  e.agent?.name,
3012
3002
  e.agentName,
3013
3003
  e.agent_name,
3014
- wt.current
3004
+ bt.current
3015
3005
  ], d);
3016
- re(!1), T("ai"), S((e) => Sr(e, {
3006
+ re(!1), te("ai"), S((e) => Sr(e, {
3017
3007
  id: `agent-left-${Date.now()}`,
3018
3008
  sender: "system",
3019
3009
  message: `${t} has left the chat.`,
@@ -3033,11 +3023,9 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
3033
3023
  }]);
3034
3024
  }), f.on("chat:history_update", (e) => {
3035
3025
  let t = _r(e.chat_history || []);
3036
- S(t), t.length === 0 && (Be(!1), re(!1), T("ai"), we(!1), Se(!1));
3026
+ S(t), t.length === 0 && (Be(!1), re(!1), te("ai"), we(!1), Se(!1));
3037
3027
  }), f.on("conversation:reset", () => {
3038
- S([]), Be(!1), re(!1), T("ai"), we(!1), Se(!1);
3039
- }), f.on("conversation:feedback_requested", () => {
3040
- He(!0);
3028
+ S([]), Be(!1), re(!1), te("ai"), we(!1), Se(!1);
3041
3029
  }), f.on("typing:start", (e) => {
3042
3030
  e.sender === "agent" && Se(!0);
3043
3031
  }), f.on("typing:stop", (e) => {
@@ -3047,18 +3035,18 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
3047
3035
  e.agentName,
3048
3036
  e.ownerName,
3049
3037
  e.agent?.name,
3050
- wt.current
3038
+ bt.current
3051
3039
  ], "Agent");
3052
- At(), jt(), _t.current = !1, Ke({
3040
+ Et(), Dt(), pt.current = !1, He({
3053
3041
  callId: e.callId,
3054
3042
  from: e.from || "owner",
3055
3043
  agentId: e.agentId || null,
3056
3044
  agentName: t
3057
- }), D((e) => xr([t, e], "Agent")), Xe("incoming"), Qe(null), C(!0);
3045
+ }), D((e) => xr([t, e], "Agent")), Ke("incoming"), Je(null), w(!0);
3058
3046
  }), f.on("call:offer", async (e = {}) => {
3059
- ft.current = e;
3047
+ lt.current = e;
3060
3048
  try {
3061
- await Lt(e);
3049
+ await Nt(e);
3062
3050
  } catch (e) {
3063
3051
  console.error("[FlowEngageProvider] failed to apply remote offer", e);
3064
3052
  }
@@ -3069,42 +3057,42 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
3069
3057
  console.warn("[FlowEngageProvider] ignoring invalid ICE candidate payload", e);
3070
3058
  return;
3071
3059
  }
3072
- if (!k.current || !k.current.remoteDescription) {
3060
+ if (!ot.current || !ot.current.remoteDescription) {
3073
3061
  console.log("[FlowEngageProvider] queueing agent ICE candidate until peer/remote description is ready", {
3074
3062
  callId: e.callId,
3075
- chatId: e.chatId || ot.current,
3076
- queueSize: pt.current.length + 1
3077
- }), pt.current.push(t);
3063
+ chatId: e.chatId || nt.current,
3064
+ queueSize: k.current.length + 1
3065
+ }), k.current.push(t);
3078
3066
  return;
3079
3067
  }
3080
- await k.current.addIceCandidate(new RTCIceCandidate(t));
3068
+ await ot.current.addIceCandidate(new RTCIceCandidate(t));
3081
3069
  } catch (e) {
3082
3070
  console.error("[FlowEngageProvider] failed to add ICE candidate", e);
3083
3071
  }
3084
3072
  }), f.on("call:ended", () => {
3085
- At(), Nt("socket:call_ended");
3073
+ Et(), kt("socket:call_ended");
3086
3074
  }), f.on("call:accepted", (e = {}) => {
3087
- Ft(e);
3075
+ jt(e);
3088
3076
  }), f.on("call:accepted_by_other", (e = {}) => {
3089
- Ft(e);
3077
+ jt(e);
3090
3078
  }), f.on("call:rejected", (e = {}) => {
3091
- It(e);
3079
+ Mt(e);
3092
3080
  }), f.on("call:missed", (e = {}) => {
3093
- It(e);
3081
+ Mt(e);
3094
3082
  }), f.on("call:failed", (e = {}) => {
3095
- It(e);
3083
+ Mt(e);
3096
3084
  }), f.on("call:connected", (e = {}) => {
3097
3085
  if (!e.callId) return;
3098
- let t = ht.current === e.callId, n = mt.current === e.callId, r = ft.current?.callId === e.callId, i = lt.current?.callId === e.callId;
3086
+ let t = dt.current === e.callId, n = ut.current === e.callId, r = lt.current?.callId === e.callId, i = at.current?.callId === e.callId;
3099
3087
  if (!t && !n && !r) {
3100
- i && (Ke(null), Xe("idle"));
3088
+ i && (He(null), Ke("idle"));
3101
3089
  return;
3102
3090
  }
3103
- _t.current = !0, ht.current = null, mt.current = e.callId, Je(e.callId), Ke(null), Xe("connected"), Qe(e.connectedAt || (/* @__PURE__ */ new Date()).toISOString()), C(!0);
3091
+ pt.current = !0, dt.current = null, ut.current = e.callId, We(e.callId), He(null), Ke("connected"), Je(e.connectedAt || (/* @__PURE__ */ new Date()).toISOString()), w(!0);
3104
3092
  }), f.on("call:unavailable", (e = {}) => {
3105
- Nt("socket:call_unavailable"), nt(yr(e, "This visitor is not available for a call right now.")), C(!0);
3093
+ kt("socket:call_unavailable"), Qe(yr(e, "This visitor is not available for a call right now.")), w(!0);
3106
3094
  }), f.on("call:error", (e = {}) => {
3107
- Nt("socket:call_error"), nt(yr(e, "We couldn't connect the call right now.")), C(!0);
3095
+ kt("socket:call_error"), Qe(yr(e, "We couldn't connect the call right now.")), w(!0);
3108
3096
  }), f.on("visitor:navigate", async ({ url: e, section: n, highlight: r } = {}) => {
3109
3097
  e && await ur(e, {
3110
3098
  siteId: t.siteId,
@@ -3122,54 +3110,54 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
3122
3110
  n && or(n);
3123
3111
  }), f.on("visitor:clear_highlight", () => {
3124
3112
  sr();
3125
- }), Dt.current = On({
3113
+ }), Ct.current = On({
3126
3114
  socket: f,
3127
3115
  chatId: c
3128
3116
  });
3129
3117
  let h = await l.loadHistory(c, r);
3130
3118
  if (!e) return;
3131
- S(_r(h.chat_history || [])), re(!!h.is_human_handled), T(h.is_human_handled ? "agent" : te);
3119
+ S(_r(h.chat_history || [])), re(!!h.is_human_handled), te(h.is_human_handled ? "agent" : T);
3132
3120
  let g = h?.visitor_email || h?.visitorEmail;
3133
- if (g && String(g).trim() && Mt(String(g).trim()), await new Promise((e) => setTimeout(e, 500)), !e) return;
3121
+ if (g && String(g).trim() && Ot(String(g).trim()), await new Promise((e) => setTimeout(e, 500)), !e) return;
3134
3122
  u("ready");
3135
3123
  } catch (t) {
3136
3124
  if (!e) return;
3137
3125
  h(t), u("error");
3138
3126
  } finally {
3139
- e && it(!1);
3127
+ e && et(!1);
3140
3128
  }
3141
3129
  })(), () => {
3142
- e = !1, Dt.current?.cleanup?.(), Nt(), at.current?.disconnect();
3130
+ e = !1, Ct.current?.cleanup?.(), kt(), tt.current?.disconnect();
3143
3131
  };
3144
3132
  }, [
3145
3133
  i,
3146
3134
  r,
3147
3135
  a
3148
3136
  ]), c(() => () => {
3149
- if (Pe && !Et.current && Tt.current.length > 0) {
3150
- let e = ot.current, t = Tt.current, n = O.current;
3151
- n && e && t.length > 0 && (console.log("[FlowEngageProvider] safety-net: syncing voice transcript on unmount"), n.beaconSyncVoice(e, t) || n.syncVoice(e, t).catch(() => {}), Et.current = !0);
3137
+ if (Pe && !St.current && xt.current.length > 0) {
3138
+ let e = nt.current, t = xt.current, n = O.current;
3139
+ n && e && t.length > 0 && (console.log("[FlowEngageProvider] safety-net: syncing voice transcript on unmount"), n.beaconSyncVoice(e, t) || n.syncVoice(e, t).catch(() => {}), St.current = !0);
3152
3140
  }
3153
3141
  }, [Pe, _]), c(() => {
3154
3142
  if (!O.current || !y || l !== "ready") return;
3155
3143
  let e = window.setInterval(async () => {
3156
3144
  try {
3157
3145
  let e = await O.current.checkHumanHandled(y);
3158
- re(!!e.is_human_handled), e.is_human_handled && (T("agent"), e.agent_info?.name && D(xr([e.agent_info.name], "Agent")), e.agent_info?.headshot && de(e.agent_info.headshot)), Ot(e);
3146
+ re(!!e.is_human_handled), e.is_human_handled && (te("agent"), e.agent_info?.name && D(xr([e.agent_info.name], "Agent")), e.agent_info?.headshot && de(e.agent_info.headshot)), wt(e);
3159
3147
  } catch {}
3160
3148
  }, 1e4);
3161
3149
  return () => window.clearInterval(e);
3162
3150
  }, [
3163
3151
  y,
3164
3152
  l,
3165
- Ot
3153
+ wt
3166
3154
  ]);
3167
- let Rt = async () => {
3168
- if (!(!Ge?.callId || !O.current || !at.current || !y)) {
3169
- At(), ht.current = Ge.callId, jt();
3155
+ let Pt = async () => {
3156
+ if (!(!Ve?.callId || !O.current || !tt.current || !y)) {
3157
+ Et(), dt.current = Ve.callId, Dt();
3170
3158
  try {
3171
3159
  let e = await navigator.mediaDevices.getUserMedia({ audio: !0 });
3172
- ut.current = e;
3160
+ st.current = e;
3173
3161
  let t = [{ urls: "stun:stun.l.google.com:19302" }];
3174
3162
  try {
3175
3163
  let e = await O.current.getIceServersConfig();
@@ -3178,35 +3166,35 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
3178
3166
  console.warn("[FlowEngageProvider] ice-config fetch failed, using STUN default", e);
3179
3167
  }
3180
3168
  let n = new RTCPeerConnection({ iceServers: t });
3181
- k.current = n, n.onconnectionstatechange = () => {
3169
+ ot.current = n, n.onconnectionstatechange = () => {
3182
3170
  let e = n.connectionState;
3183
3171
  if (e === "connected") {
3184
3172
  let e = (/* @__PURE__ */ new Date()).toISOString();
3185
- Xe("connected"), Qe((t) => t || e), Pt(e);
3173
+ Ke("connected"), Je((t) => t || e), At(e);
3186
3174
  return;
3187
3175
  }
3188
3176
  if (e === "connecting") {
3189
- Xe((e) => e === "connected" ? e : "connecting");
3177
+ Ke((e) => e === "connected" ? e : "connecting");
3190
3178
  return;
3191
3179
  }
3192
3180
  }, n.oniceconnectionstatechange = () => {
3193
3181
  let e = n.iceConnectionState;
3194
3182
  if (e === "connected" || e === "completed") {
3195
3183
  let e = (/* @__PURE__ */ new Date()).toISOString();
3196
- Xe("connected"), Qe((t) => t || e), Pt(e);
3184
+ Ke("connected"), Je((t) => t || e), At(e);
3197
3185
  return;
3198
3186
  }
3199
3187
  if (e === "checking" || e === "new") {
3200
- Xe((e) => e === "connected" ? e : "connecting");
3188
+ Ke((e) => e === "connected" ? e : "connecting");
3201
3189
  return;
3202
3190
  }
3203
3191
  }, n.onsignalingstatechange = () => {}, n.onicegatheringstatechange = () => {}, e.getTracks().forEach((t) => {
3204
3192
  n.addTrack(t, e);
3205
3193
  }), n.onicecandidate = (e) => {
3206
- if (!e.candidate || !at.current?.connected) return;
3194
+ if (!e.candidate || !tt.current?.connected) return;
3207
3195
  let t = e.candidate;
3208
- at.current.emit("call:ice-candidate", {
3209
- callId: Ge.callId,
3196
+ tt.current.emit("call:ice-candidate", {
3197
+ callId: Ve.callId,
3210
3198
  candidate: t.candidate,
3211
3199
  sdpMid: t.sdpMid,
3212
3200
  sdpMLineIndex: t.sdpMLineIndex,
@@ -3215,98 +3203,98 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
3215
3203
  });
3216
3204
  }, n.ontrack = (e) => {
3217
3205
  let [t] = e.streams || [], [n] = t?.getAudioTracks?.() || [];
3218
- if (!dt.current) {
3206
+ if (!ct.current) {
3219
3207
  let e = document.createElement("audio");
3220
- 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);
3208
+ e.id = "flowengage-remote-audio", e.autoplay = !0, e.playsInline = !0, e.onplay = () => {}, e.onpause = () => {}, e.onended = () => {}, e.onerror = (e) => {}, ct.current = e, document.body.appendChild(e);
3221
3209
  }
3222
- dt.current.srcObject = e.streams[0];
3223
- let r = Ge?.callId, i = r && (ht.current === r || mt.current === r);
3224
- if (!_t.current && i) {
3210
+ ct.current.srcObject = e.streams[0];
3211
+ let r = Ve?.callId, i = r && (dt.current === r || ut.current === r);
3212
+ if (!pt.current && i) {
3225
3213
  let e = (/* @__PURE__ */ new Date()).toISOString();
3226
- Xe("connected"), Qe((t) => t || e), mt.current = r, Je(r), Pt(e);
3214
+ Ke("connected"), Je((t) => t || e), ut.current = r, We(r), At(e);
3227
3215
  }
3228
- dt.current.srcObject = t || null;
3229
- let a = dt.current.play?.();
3216
+ ct.current.srcObject = t || null;
3217
+ let a = ct.current.play?.();
3230
3218
  a?.catch && a.catch((e) => {});
3231
3219
  };
3232
- let r = ft.current;
3220
+ let r = lt.current;
3233
3221
  r && (console.log("[FlowEngageProvider] found pending remote offer during accept", {
3234
- callId: r.callId || Ge.callId,
3222
+ callId: r.callId || Ve.callId,
3235
3223
  chatId: y
3236
- }), await Lt({
3224
+ }), await Nt({
3237
3225
  ...r,
3238
- callId: r.callId || Ge.callId
3239
- })), await O.current.acceptCall(Ge.callId, y), mt.current = Ge.callId, Je(Ge.callId), Xe((e) => e === "connected" || _t.current ? "connected" : "connecting"), Ke(null), C(!0);
3226
+ callId: r.callId || Ve.callId
3227
+ })), await O.current.acceptCall(Ve.callId, y), ut.current = Ve.callId, We(Ve.callId), Ke((e) => e === "connected" || pt.current ? "connected" : "connecting"), He(null), w(!0);
3240
3228
  } catch (e) {
3241
- if (ht.current = null, Nt("accept_call_failed"), e?.status === 404 || e?.status === 409 || e?.status === 422) {
3242
- nt(yr(e, "This visitor call is no longer available."));
3229
+ if (dt.current = null, kt("accept_call_failed"), e?.status === 404 || e?.status === 409 || e?.status === 422) {
3230
+ Qe(yr(e, "This visitor call is no longer available."));
3243
3231
  return;
3244
3232
  }
3245
3233
  if (e?.name === "NotAllowedError" || e?.name === "PermissionDeniedError") {
3246
3234
  try {
3247
- await O.current.rejectCall(Ge.callId, y);
3235
+ await O.current.rejectCall(Ve.callId, y);
3248
3236
  } catch (e) {
3249
3237
  console.error("[FlowEngageProvider] failed to reject call after microphone denial", e);
3250
3238
  }
3251
- nt("Microphone access was denied. Please allow microphone access to accept the call.");
3239
+ Qe("Microphone access was denied. Please allow microphone access to accept the call.");
3252
3240
  return;
3253
3241
  }
3254
- nt("We couldn't connect the call right now. Please try again.");
3242
+ Qe("We couldn't connect the call right now. Please try again.");
3255
3243
  }
3256
3244
  }
3257
- }, zt = async () => {
3258
- if (!Ge?.callId || !O.current || !y) {
3259
- Nt("reject_call_without_server_context");
3245
+ }, Ft = async () => {
3246
+ if (!Ve?.callId || !O.current || !y) {
3247
+ kt("reject_call_without_server_context");
3260
3248
  return;
3261
3249
  }
3262
- jt(), At();
3250
+ Dt(), Et();
3263
3251
  try {
3264
- await O.current.rejectCall(Ge.callId, y);
3252
+ await O.current.rejectCall(Ve.callId, y);
3265
3253
  } catch (e) {
3266
- nt(yr(e, "We couldn't decline the call cleanly."));
3254
+ Qe(yr(e, "We couldn't decline the call cleanly."));
3267
3255
  } finally {
3268
- Nt("reject_call_finally");
3256
+ kt("reject_call_finally");
3269
3257
  }
3270
- }, Bt = p(zt);
3271
- Bt.current = zt, c(() => {
3272
- if (!Ge?.callId || qe) {
3273
- jt();
3258
+ }, It = p(Ft);
3259
+ It.current = Ft, c(() => {
3260
+ if (!Ve?.callId || Ue) {
3261
+ Dt();
3274
3262
  return;
3275
3263
  }
3276
- let e = Ge.callId;
3277
- return jt(), gt.current = window.setTimeout(() => {
3278
- lt.current?.callId === e && ht.current !== e && mt.current !== e && Bt.current();
3264
+ let e = Ve.callId;
3265
+ return Dt(), ft.current = window.setTimeout(() => {
3266
+ at.current?.callId === e && dt.current !== e && ut.current !== e && It.current();
3279
3267
  }, oe), () => {
3280
- gt.current &&= (window.clearTimeout(gt.current), null);
3268
+ ft.current &&= (window.clearTimeout(ft.current), null);
3281
3269
  };
3282
3270
  }, [
3283
- qe,
3284
- jt,
3285
- Ge?.callId
3271
+ Ue,
3272
+ Dt,
3273
+ Ve?.callId
3286
3274
  ]);
3287
- let Vt = async () => {
3288
- if (!qe || !O.current || !y) {
3289
- Nt("end_call_without_server_context");
3275
+ let Lt = async () => {
3276
+ if (!Ue || !O.current || !y) {
3277
+ kt("end_call_without_server_context");
3290
3278
  return;
3291
3279
  }
3292
- At();
3280
+ Et();
3293
3281
  try {
3294
- await O.current.endWebRTCCall(qe, y);
3282
+ await O.current.endWebRTCCall(Ue, y);
3295
3283
  } catch (e) {
3296
- nt(yr(e, "The call ended locally, but the server could not be updated."));
3284
+ Qe(yr(e, "The call ended locally, but the server could not be updated."));
3297
3285
  } finally {
3298
- Nt("end_call_finally");
3286
+ kt("end_call_finally");
3299
3287
  }
3300
- }, Ht = () => {
3301
- let e = ut.current?.getAudioTracks?.() || [], t = k.current?.getSenders?.().map((e) => e.track).filter((e) => e?.kind === "audio") || [], n = [...e, ...t].filter(Boolean);
3288
+ }, Rt = () => {
3289
+ let e = st.current?.getAudioTracks?.() || [], t = ot.current?.getSenders?.().map((e) => e.track).filter((e) => e?.kind === "audio") || [], n = [...e, ...t].filter(Boolean);
3302
3290
  if (n.length === 0) return;
3303
- let r = !$e;
3291
+ let r = !Ye;
3304
3292
  n.forEach((e) => {
3305
3293
  e.enabled = !r;
3306
- }), et(r);
3307
- }, Ut = async (e = {}) => {
3294
+ }), Xe(r);
3295
+ }, zt = async (e = {}) => {
3308
3296
  let t = e.notifyChatInitiated === !0;
3309
- if (C(!0), !(!t || !O.current || !y || typeof window > "u")) {
3297
+ if (w(!0), !(!t || !O.current || !y || typeof window > "u")) {
3310
3298
  try {
3311
3299
  await O.current.trackVisitor({
3312
3300
  chatId: y,
@@ -3317,12 +3305,12 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
3317
3305
  await O.current.updateChatStatus(y, "open");
3318
3306
  } catch {}
3319
3307
  }
3320
- }, Wt = async (e) => {
3321
- let t = Mt(e);
3322
- if (!t || !O.current || !ot.current) return t;
3308
+ }, Bt = async (e) => {
3309
+ let t = Ot(e);
3310
+ if (!t || !O.current || !nt.current) return t;
3323
3311
  try {
3324
3312
  await O.current.trackVisitor({
3325
- chatId: ot.current,
3313
+ chatId: nt.current,
3326
3314
  currentPagePath: typeof window < "u" && window.location.pathname || "/",
3327
3315
  email: t
3328
3316
  });
@@ -3330,26 +3318,26 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
3330
3318
  console.error("[FlowEngageProvider] failed to persist visitor email", e);
3331
3319
  }
3332
3320
  return t;
3333
- }, Gt = () => {
3334
- !y || !at.current?.connected || vt.current || (vt.current = !0, at.current.emit("typing:start", {
3321
+ }, Vt = () => {
3322
+ !y || !tt.current?.connected || mt.current || (mt.current = !0, tt.current.emit("typing:start", {
3335
3323
  chatId: y,
3336
3324
  sender: "user"
3337
3325
  }));
3338
- }, Kt = () => {
3339
- !y || !at.current?.connected || !vt.current || (vt.current = !1, at.current.emit("typing:stop", {
3326
+ }, Ht = () => {
3327
+ !y || !tt.current?.connected || !mt.current || (mt.current = !1, tt.current.emit("typing:stop", {
3340
3328
  chatId: y,
3341
3329
  sender: "user"
3342
3330
  }));
3343
- }, qt = (e = "") => {
3331
+ }, Ut = (e = "") => {
3344
3332
  let t = typeof e == "string" ? e : "";
3345
- !y || !at.current?.connected || t !== "" && yt.current === t || (yt.current = t, at.current.emit("typing:update", {
3333
+ !y || !tt.current?.connected || t !== "" && ht.current === t || (ht.current = t, tt.current.emit("typing:update", {
3346
3334
  chatId: y,
3347
3335
  sender: "user",
3348
3336
  text: t
3349
3337
  }));
3350
- }, Jt = async (e, t = "", n = null, a = {}) => {
3338
+ }, Wt = async (e, t = "", n = null, a = {}) => {
3351
3339
  if (!(typeof e == "string" && e.trim()) || !O.current || !y || l !== "ready" || ze) return;
3352
- Kt();
3340
+ Ht();
3353
3341
  let o = `pending-user-${Date.now()}`, s = {
3354
3342
  id: o,
3355
3343
  sender: "user",
@@ -3363,10 +3351,10 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
3363
3351
  S((e) => [...e, s]);
3364
3352
  let c = ne;
3365
3353
  if (c) try {
3366
- c = Ot(await O.current.checkHumanHandled(y));
3354
+ c = wt(await O.current.checkHumanHandled(y));
3367
3355
  } catch {}
3368
- if (c && at.current?.connected) {
3369
- at.current.emit("customer:message", {
3356
+ if (c && tt.current?.connected) {
3357
+ tt.current.emit("customer:message", {
3370
3358
  chatId: y,
3371
3359
  content: e,
3372
3360
  sender: "user",
@@ -3402,26 +3390,26 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
3402
3390
  });
3403
3391
  });
3404
3392
  }
3405
- S(_r(s)), re(!!o.is_human_handled), T(o.is_human_handled ? "agent" : "ai"), we(!1), ke(!1), o.feedback_requested && !Ue && He(!0), await O.current.updateChatStatus(y, "messageSent");
3393
+ S(_r(s)), re(!!o.is_human_handled), te(o.is_human_handled ? "agent" : "ai"), we(!1), ke(!1), await O.current.updateChatStatus(y, "messageSent");
3406
3394
  } catch (e) {
3407
3395
  S((e) => e.filter((e) => e.id !== o)), we(!1), ke(!1), e.status === 429 ? (je(!0), Ne(e.message), window.setTimeout(() => {
3408
3396
  je(!1), Ne("");
3409
3397
  }, ie)) : h(e);
3410
3398
  }
3411
- }, Yt = async (e) => {
3399
+ }, Gt = async (e) => {
3412
3400
  if (!O.current || !e) throw Error("Upload is unavailable right now.");
3413
3401
  return O.current.uploadChatFile(e);
3414
- }, Xt = async (e) => {
3402
+ }, Kt = async (e) => {
3415
3403
  if (!(!O.current || !y)) {
3416
3404
  try {
3417
3405
  let t = e ? "voice" : "text";
3418
3406
  await O.current.setChatMode(y, t);
3419
3407
  } catch {}
3420
- Fe(e), e && (Et.current = !1);
3408
+ Fe(e), e && (St.current = !1);
3421
3409
  }
3422
- }, Zt = async (e) => {
3423
- if (Et.current) return;
3424
- if (Et.current = !0, !O.current || !y || !e?.length) {
3410
+ }, qt = async (e) => {
3411
+ if (St.current) return;
3412
+ if (St.current = !0, !O.current || !y || !e?.length) {
3425
3413
  Fe(!1);
3426
3414
  return;
3427
3415
  }
@@ -3448,9 +3436,9 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
3448
3436
  } finally {
3449
3437
  Fe(!1);
3450
3438
  }
3451
- }, Qt = async () => {
3439
+ }, Jt = async () => {
3452
3440
  if (!(!O.current || !y)) {
3453
- Pe && !Et.current && Tt.current.length > 0 && await Zt(Tt.current);
3441
+ Pe && !St.current && xt.current.length > 0 && await qt(xt.current);
3454
3442
  try {
3455
3443
  await O.current.endConversation(y);
3456
3444
  } catch {
@@ -3468,47 +3456,47 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
3468
3456
  }
3469
3457
  };
3470
3458
  c(() => {
3471
- if (Ye !== "connected" || !qe || !y || !Ze || !kt) return;
3472
- let e = new Date(Ze).getTime(), t = Number.isFinite(e) ? Date.now() - e : 0, n = Math.max(0, kt * 1e3 - t), r = window.setTimeout(() => {
3473
- nt("The call ended because it reached the time limit."), Vt();
3459
+ if (Ge !== "connected" || !Ue || !y || !qe || !Tt) return;
3460
+ let e = new Date(qe).getTime(), t = Number.isFinite(e) ? Date.now() - e : 0, n = Math.max(0, Tt * 1e3 - t), r = window.setTimeout(() => {
3461
+ Qe("The call ended because it reached the time limit."), Lt();
3474
3462
  }, n);
3475
3463
  return () => window.clearTimeout(r);
3476
3464
  }, [
3465
+ Ue,
3477
3466
  qe,
3478
- Ze,
3479
- Ye,
3467
+ Ge,
3480
3468
  y,
3481
- Vt,
3482
- kt
3469
+ Lt,
3470
+ Tt
3483
3471
  ]), c(() => {
3484
3472
  let e = () => {
3485
- let e = ot.current, t = O.current;
3473
+ let e = nt.current, t = O.current;
3486
3474
  if (!t || !e) return;
3487
- if (!Et.current && Tt.current.length > 0 && (t.beaconSyncVoice(e, Tt.current) || t.syncVoice(e, Tt.current).catch(() => {}), Et.current = !0), mt.current) {
3488
- t.beaconEndWebRTCCall(mt.current, e);
3475
+ if (!St.current && xt.current.length > 0 && (t.beaconSyncVoice(e, xt.current) || t.syncVoice(e, xt.current).catch(() => {}), St.current = !0), ut.current) {
3476
+ t.beaconEndWebRTCCall(ut.current, e);
3489
3477
  return;
3490
3478
  }
3491
- let n = ht.current || lt.current?.callId;
3479
+ let n = dt.current || at.current?.callId;
3492
3480
  n && t.beaconCustomerUnavailable(n, e);
3493
3481
  };
3494
3482
  return window.addEventListener("pagehide", e), window.addEventListener("beforeunload", e), () => {
3495
3483
  window.removeEventListener("pagehide", e), window.removeEventListener("beforeunload", e);
3496
3484
  };
3497
3485
  }, []);
3498
- let $t = o(() => {
3486
+ let Yt = o(() => {
3499
3487
  let e = i?.siteId;
3500
- ge(e), st.current = !0, ct.current = null, at.current?.disconnect(), S([]), b(""), ot.current = "", Be(!1), re(!1), D(null), de(null), it(!0), s((e) => e + 1);
3501
- }, [i?.siteId]), en = o((e) => {
3502
- i?.siteId, st.current = !1, ct.current = e, at.current?.disconnect(), S([]), b(""), ot.current = "", Be(!1), re(!1), D(null), de(null), it(!0), s((e) => e + 1);
3503
- }, [i?.siteId]), tn = f(() => ({
3488
+ ge(e), rt.current = !0, it.current = null, tt.current?.disconnect(), S([]), b(""), nt.current = "", Be(!1), re(!1), D(null), de(null), et(!0), s((e) => e + 1);
3489
+ }, [i?.siteId]), Xt = o((e) => {
3490
+ i?.siteId, rt.current = !1, it.current = e, tt.current?.disconnect(), S([]), b(""), nt.current = "", Be(!1), re(!1), D(null), de(null), et(!0), s((e) => e + 1);
3491
+ }, [i?.siteId]), Zt = f(() => ({
3504
3492
  status: l,
3505
3493
  error: d,
3506
3494
  runtimeConfig: _,
3507
3495
  resolvedConfig: i,
3508
3496
  chatId: y,
3509
3497
  chatHistory: x,
3510
- isOpen: ee,
3511
- activeScreen: te,
3498
+ isOpen: C,
3499
+ activeScreen: T,
3512
3500
  isHumanHandled: ne,
3513
3501
  agentName: E,
3514
3502
  agentHeadshot: se,
@@ -3521,54 +3509,44 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
3521
3509
  isRateLimited: Ae,
3522
3510
  rateLimitMessage: Me,
3523
3511
  isConversationEnded: ze,
3524
- isSessionRestoring: rt,
3525
- isFeedbackPending: Ve,
3526
- feedbackSubmitted: Ue,
3527
- submitFeedback: async (e, t = "") => {
3528
- if (!(!O.current || !y)) try {
3529
- await O.current.submitFeedback(y, e, t), We(!0), He(!1);
3530
- } catch (e) {
3531
- console.error("[FlowEngage] Failed to submit feedback:", e);
3532
- }
3533
- },
3534
- dismissFeedback: () => He(!1),
3535
- incomingCall: Ge,
3536
- activeCallId: qe,
3537
- callConnectionState: Ye,
3538
- callConnectedAt: Ze,
3539
- isCallMuted: $e,
3540
- webRTCError: tt,
3512
+ isSessionRestoring: $e,
3513
+ incomingCall: Ve,
3514
+ activeCallId: Ue,
3515
+ callConnectionState: Ge,
3516
+ callConnectedAt: qe,
3517
+ isCallMuted: Ye,
3518
+ webRTCError: Ze,
3541
3519
  language: r,
3542
- historyRef: Tt,
3543
- hasSyncedRef: Et,
3544
- dismissCallError: At,
3545
- captureVisitorEmail: Wt,
3546
- startTyping: Gt,
3547
- stopTyping: Kt,
3548
- updateTypingDraft: qt,
3549
- notifyRouteChange: () => Dt.current?.notifyRouteChange?.(),
3550
- openWidget: Ut,
3551
- closeWidget: () => C(!1),
3520
+ historyRef: xt,
3521
+ hasSyncedRef: St,
3522
+ dismissCallError: Et,
3523
+ captureVisitorEmail: Bt,
3524
+ startTyping: Vt,
3525
+ stopTyping: Ht,
3526
+ updateTypingDraft: Ut,
3527
+ notifyRouteChange: () => Ct.current?.notifyRouteChange?.(),
3528
+ openWidget: zt,
3529
+ closeWidget: () => w(!1),
3552
3530
  toggleWidget: () => {
3553
- if (ee) {
3554
- C(!1);
3531
+ if (C) {
3532
+ w(!1);
3555
3533
  return;
3556
3534
  }
3557
- Ut({ notifyChatInitiated: !0 });
3535
+ zt({ notifyChatInitiated: !0 });
3558
3536
  },
3559
- sendMessage: Jt,
3560
- uploadChatFile: Yt,
3561
- setVoiceMode: Xt,
3562
- onMessageSync: Zt,
3563
- endConversation: Qt,
3564
- startNewChat: $t,
3565
- resumeChat: en,
3537
+ sendMessage: Wt,
3538
+ uploadChatFile: Gt,
3539
+ setVoiceMode: Kt,
3540
+ onMessageSync: qt,
3541
+ endConversation: Jt,
3542
+ startNewChat: Yt,
3543
+ resumeChat: Xt,
3566
3544
  getVisitorChatHistory: () => O.current?.getVisitorChatHistory?.(),
3567
3545
  getVisitorChatThread: (e) => O.current?.getVisitorChatThread?.(e),
3568
- acceptCall: Rt,
3569
- rejectCall: zt,
3570
- endWebRTCCall: Vt,
3571
- toggleCallMute: Ht
3546
+ acceptCall: Pt,
3547
+ rejectCall: Ft,
3548
+ endWebRTCCall: Lt,
3549
+ toggleCallMute: Rt
3572
3550
  }), [
3573
3551
  l,
3574
3552
  d,
@@ -3576,8 +3554,8 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
3576
3554
  i,
3577
3555
  y,
3578
3556
  x,
3579
- ee,
3580
- te,
3557
+ C,
3558
+ T,
3581
3559
  ne,
3582
3560
  E,
3583
3561
  se,
@@ -3590,35 +3568,33 @@ function Cr({ siteId: e, config: t, children: n, language: r = "en" }) {
3590
3568
  Ae,
3591
3569
  Me,
3592
3570
  ze,
3593
- rt,
3571
+ $e,
3594
3572
  Ve,
3595
3573
  Ue,
3596
3574
  Ge,
3597
3575
  qe,
3598
3576
  Ye,
3599
3577
  Ze,
3600
- $e,
3601
- tt,
3602
3578
  r,
3579
+ Bt,
3580
+ Vt,
3581
+ Ht,
3582
+ Ut,
3583
+ Pt,
3584
+ Ft,
3585
+ Lt,
3586
+ Rt,
3587
+ zt,
3603
3588
  Wt,
3604
3589
  Gt,
3605
3590
  Kt,
3606
3591
  qt,
3607
- Rt,
3608
- zt,
3609
- Vt,
3610
- Ht,
3611
- Ut,
3612
3592
  Jt,
3613
3593
  Yt,
3614
- Xt,
3615
- Zt,
3616
- Qt,
3617
- $t,
3618
- At
3594
+ Et
3619
3595
  ]);
3620
3596
  return /* @__PURE__ */ g(kn.Provider, {
3621
- value: tn,
3597
+ value: Zt,
3622
3598
  children: n
3623
3599
  });
3624
3600
  }
@@ -4202,8 +4178,8 @@ function Qa(e = Ha.visualDuration, t = Ha.bounce) {
4202
4178
  velocity: -/* @__PURE__ */ Gr(n.velocity || 0)
4203
4179
  }), m = f || 0, h = l / (2 * Math.sqrt(c * u)), g = o - a, _ = /* @__PURE__ */ Gr(Math.sqrt(c / u)), v = Math.abs(g) < 5;
4204
4180
  r ||= v ? Ha.restSpeed.granular : Ha.restSpeed.default, i ||= v ? Ha.restDelta.granular : Ha.restDelta.default;
4205
- let y, b, x, S, ee, C;
4206
- if (h < 1) x = Ua(_, h), S = (m + h * _ * g) / x, y = (e) => o - Math.exp(-h * _ * e) * (S * Math.sin(x * e) + g * Math.cos(x * e)), ee = h * _ * S + g * x, C = h * _ * g - S * x, b = (e) => Math.exp(-h * _ * e) * (ee * Math.sin(x * e) + C * Math.cos(x * e));
4181
+ let y, b, x, S, C, w;
4182
+ if (h < 1) x = Ua(_, h), S = (m + h * _ * g) / x, y = (e) => o - Math.exp(-h * _ * e) * (S * Math.sin(x * e) + g * Math.cos(x * e)), C = h * _ * S + g * x, w = h * _ * g - S * x, b = (e) => Math.exp(-h * _ * e) * (C * Math.sin(x * e) + w * Math.cos(x * e));
4207
4183
  else if (h === 1) {
4208
4184
  y = (e) => o - Math.exp(-_ * e) * (g + (m + _ * g) * e);
4209
4185
  let e = m + _ * g;
@@ -4220,12 +4196,12 @@ function Qa(e = Ha.visualDuration, t = Ha.bounce) {
4220
4196
  return i * (n * Math.sinh(a) + r * Math.cosh(a));
4221
4197
  };
4222
4198
  }
4223
- let te = {
4199
+ let T = {
4224
4200
  calculatedDuration: p && d || null,
4225
4201
  velocity: (e) => /* @__PURE__ */ Wr(b(e)),
4226
4202
  next: (e) => {
4227
4203
  if (!p && h < 1) {
4228
- let t = Math.exp(-h * _ * e), n = Math.sin(x * e), a = Math.cos(x * e), c = o - t * (S * n + g * a), l = /* @__PURE__ */ Wr(t * (ee * n + C * a));
4204
+ let t = Math.exp(-h * _ * e), n = Math.sin(x * e), a = Math.cos(x * e), c = o - t * (S * n + g * a), l = /* @__PURE__ */ Wr(t * (C * n + w * a));
4229
4205
  return s.done = Math.abs(l) <= r && Math.abs(o - c) <= i, s.value = s.done ? o : c, s;
4230
4206
  }
4231
4207
  let t = y(e);
@@ -4237,12 +4213,12 @@ function Qa(e = Ha.visualDuration, t = Ha.bounce) {
4237
4213
  return s.value = s.done ? o : t, s;
4238
4214
  },
4239
4215
  toString: () => {
4240
- let e = Math.min(Ba(te), za), t = Ra((t) => te.next(e * t).value, e, 30);
4216
+ let e = Math.min(Ba(T), za), t = Ra((t) => T.next(e * t).value, e, 30);
4241
4217
  return e + "ms " + t;
4242
4218
  },
4243
4219
  toTransition: () => {}
4244
4220
  };
4245
- return te;
4221
+ return T;
4246
4222
  }
4247
4223
  Qa.applyToOptions = (e) => {
4248
4224
  let t = Va(e, 100, Qa);
@@ -4266,7 +4242,7 @@ function to({ keyframes: e, velocity: t = 0, power: n = .8, timeConstant: r = 32
4266
4242
  let v = (e) => -h * Math.exp(-e / r), y = (e) => _ + v(e), b = (e) => {
4267
4243
  let t = v(e), n = y(e);
4268
4244
  f.done = Math.abs(t) <= l, f.value = f.done ? _ : n;
4269
- }, x, S, ee = (e) => {
4245
+ }, x, S, C = (e) => {
4270
4246
  p(f.value) && (x = e, S = Qa({
4271
4247
  keyframes: [f.value, m(f.value)],
4272
4248
  velocity: eo(y, e, f.value),
@@ -4276,11 +4252,11 @@ function to({ keyframes: e, velocity: t = 0, power: n = .8, timeConstant: r = 32
4276
4252
  restSpeed: u
4277
4253
  }));
4278
4254
  };
4279
- return ee(0), {
4255
+ return C(0), {
4280
4256
  calculatedDuration: null,
4281
4257
  next: (e) => {
4282
4258
  let t = !1;
4283
- return !S && x === void 0 && (t = !0, b(e), ee(e)), x !== void 0 && e >= x ? S.next(e - x) : (!t && b(e), f);
4259
+ return !S && x === void 0 && (t = !0, b(e), C(e)), x !== void 0 && e >= x ? S.next(e - x) : (!t && b(e), f);
4284
4260
  }
4285
4261
  };
4286
4262
  }
@@ -6507,30 +6483,30 @@ function Mu(e) {
6507
6483
  });
6508
6484
  continue;
6509
6485
  }
6510
- let y = Nu(m.prevProp, h), b = y || p === o && m.isActive && !v && g || t > f && g, x = !1, S = Array.isArray(h) ? h : [h], ee = S.reduce(a(p), {});
6511
- _ === !1 && (ee = {});
6512
- let { prevResolvedValues: C = {} } = m, te = {
6513
- ...C,
6514
- ...ee
6515
- }, w = (t) => {
6486
+ let y = Nu(m.prevProp, h), b = y || p === o && m.isActive && !v && g || t > f && g, x = !1, S = Array.isArray(h) ? h : [h], C = S.reduce(a(p), {});
6487
+ _ === !1 && (C = {});
6488
+ let { prevResolvedValues: w = {} } = m, T = {
6489
+ ...w,
6490
+ ...C
6491
+ }, ee = (t) => {
6516
6492
  b = !0, u.has(t) && (x = !0, u.delete(t)), m.needsAnimating[t] = !0;
6517
6493
  let n = e.getValue(t);
6518
6494
  n && (n.liveStyle = !1);
6519
6495
  };
6520
- for (let e in te) {
6521
- let t = ee[e], n = C[e];
6496
+ for (let e in T) {
6497
+ let t = C[e], n = w[e];
6522
6498
  if (d.hasOwnProperty(e)) continue;
6523
6499
  let r = !1;
6524
- r = Gs(t) && Gs(n) ? !Ou(t, n) : t !== n, r ? t == null ? u.add(e) : w(e) : t !== void 0 && u.has(e) ? w(e) : m.protectedKeys[e] = !0;
6500
+ r = Gs(t) && Gs(n) ? !Ou(t, n) : t !== n, r ? t == null ? u.add(e) : ee(e) : t !== void 0 && u.has(e) ? ee(e) : m.protectedKeys[e] = !0;
6525
6501
  }
6526
- m.prevProp = h, m.prevResolvedValues = ee, m.isActive && (d = {
6502
+ m.prevProp = h, m.prevResolvedValues = C, m.isActive && (d = {
6527
6503
  ...d,
6528
- ...ee
6504
+ ...C
6529
6505
  }), (r || i) && e.blockInitialAnimation && (b = !1);
6530
- let T = v && y;
6531
- b && (!T || x) && l.push(...S.map((t) => {
6506
+ let te = v && y;
6507
+ b && (!te || x) && l.push(...S.map((t) => {
6532
6508
  let n = { type: p };
6533
- if (typeof t == "string" && (r || i) && !T && e.manuallyAnimateOnMount && e.parent) {
6509
+ if (typeof t == "string" && (r || i) && !te && e.manuallyAnimateOnMount && e.parent) {
6534
6510
  let { parent: r } = e, i = Rs(r, t);
6535
6511
  if (r.enteringChildren && i) {
6536
6512
  let { delayChildren: t } = i.transition || {};
@@ -7484,14 +7460,14 @@ function wf(e) {
7484
7460
  }
7485
7461
  //#endregion
7486
7462
  //#region __vite-optional-peer-dep:@emotion/is-prop-valid:framer-motion
7487
- var Tf = /* @__PURE__ */ ee({ default: () => Ef }), Ef, Df = S((() => {
7463
+ var Tf = /* @__PURE__ */ C({ default: () => Ef }), Ef, Df = S((() => {
7488
7464
  throw Ef = {}, Error("Could not resolve \"@emotion/is-prop-valid\" imported by \"framer-motion\". Is it installed?");
7489
7465
  })), Of = (e) => !wf(e);
7490
7466
  function kf(e) {
7491
7467
  typeof e == "function" && (Of = (t) => t.startsWith("on") ? !wf(t) : e(t));
7492
7468
  }
7493
7469
  try {
7494
- kf((Df(), te(Tf)).default);
7470
+ kf((Df(), T(Tf)).default);
7495
7471
  } catch {}
7496
7472
  function Af(e, t, n) {
7497
7473
  let r = {};
@@ -27231,8 +27207,8 @@ function qD({ chatHistory: e, isAiTyping: t, isLoading: n, isAgentTyping: r, set
27231
27207
  }
27232
27208
  //#endregion
27233
27209
  //#region src/components/ChatInput.jsx
27234
- function JD({ input: e, setInput: t, onSubmit: n, isConversationEnded: r, callUiActive: i, handleToggleVoice: a, activeScreen: o, inputDisabled: s, replyContext: c, clearReplyContext: l, requiresEmail: u, emailInput: d, setEmailInput: f, emailError: m, showVoiceToggle: v = !1, voiceEnabled: y = !0, onFileSelect: b, selectedFile: x = null, onRemoveSelectedFile: S, attachmentError: ee = "", isUploadingAttachment: C = !1, inputPlaceholder: te = "Type your message" }) {
27235
- let w = p(null), T = c?.sender === "user" ? "You" : c?.sender === "agent" ? "Agent" : "AI Assistant", ne = u ? !!d?.trim() : !!e?.trim() || !!x, re = s || C || !ne, E = !u && y && v;
27210
+ function JD({ input: e, setInput: t, onSubmit: n, isConversationEnded: r, callUiActive: i, handleToggleVoice: a, activeScreen: o, inputDisabled: s, replyContext: c, clearReplyContext: l, requiresEmail: u, emailInput: d, setEmailInput: f, emailError: m, showVoiceToggle: v = !1, voiceEnabled: y = !0, onFileSelect: b, selectedFile: x = null, onRemoveSelectedFile: S, attachmentError: C = "", isUploadingAttachment: w = !1, inputPlaceholder: T = "Type your message" }) {
27211
+ let ee = p(null), te = c?.sender === "user" ? "You" : c?.sender === "agent" ? "Agent" : "AI Assistant", ne = u ? !!d?.trim() : !!e?.trim() || !!x, re = s || w || !ne, E = !u && y && v;
27236
27212
  return /* @__PURE__ */ _("div", {
27237
27213
  style: {
27238
27214
  padding: "0 16px",
@@ -27265,7 +27241,7 @@ function JD({ input: e, setInput: t, onSubmit: n, isConversationEnded: r, callUi
27265
27241
  fontWeight: 600,
27266
27242
  color: "var(--flowengage-primary)"
27267
27243
  },
27268
- children: ["Replying to ", T]
27244
+ children: ["Replying to ", te]
27269
27245
  }), /* @__PURE__ */ g("div", {
27270
27246
  style: {
27271
27247
  overflow: "hidden",
@@ -27417,7 +27393,7 @@ function JD({ input: e, setInput: t, onSubmit: n, isConversationEnded: r, callUi
27417
27393
  onSubmit: n,
27418
27394
  children: [
27419
27395
  E ? /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ g("input", {
27420
- ref: w,
27396
+ ref: ee,
27421
27397
  type: "file",
27422
27398
  accept: BD,
27423
27399
  style: { display: "none" },
@@ -27441,10 +27417,10 @@ function JD({ input: e, setInput: t, onSubmit: n, isConversationEnded: r, callUi
27441
27417
  cursor: "pointer",
27442
27418
  flexShrink: 0
27443
27419
  },
27444
- onClick: () => w.current?.click(),
27420
+ onClick: () => ee.current?.click(),
27445
27421
  title: "Attach file",
27446
27422
  "aria-label": "Attach file",
27447
- disabled: C,
27423
+ disabled: w,
27448
27424
  onMouseEnter: (e) => {
27449
27425
  e.currentTarget.style.opacity = "0.8";
27450
27426
  },
@@ -27478,7 +27454,7 @@ function JD({ input: e, setInput: t, onSubmit: n, isConversationEnded: r, callUi
27478
27454
  }
27479
27455
  t(e.target.value);
27480
27456
  },
27481
- placeholder: u ? "Enter your Email" : o === "agent" ? "Message the agent…" : te,
27457
+ placeholder: u ? "Enter your Email" : o === "agent" ? "Message the agent…" : T,
27482
27458
  disabled: s,
27483
27459
  type: u ? "email" : "text",
27484
27460
  autoComplete: u ? "email" : "off"
@@ -27511,7 +27487,7 @@ function JD({ input: e, setInput: t, onSubmit: n, isConversationEnded: r, callUi
27511
27487
  })
27512
27488
  ]
27513
27489
  }),
27514
- !u && ee && /* @__PURE__ */ _("div", {
27490
+ !u && C && /* @__PURE__ */ _("div", {
27515
27491
  style: {
27516
27492
  display: "flex",
27517
27493
  alignItems: "center",
@@ -27553,7 +27529,7 @@ function JD({ input: e, setInput: t, onSubmit: n, isConversationEnded: r, callUi
27553
27529
  color: "#dc2626",
27554
27530
  fontWeight: 500
27555
27531
  },
27556
- children: ee
27532
+ children: C
27557
27533
  })]
27558
27534
  }),
27559
27535
  u && m && /* @__PURE__ */ g("div", {
@@ -27959,9 +27935,9 @@ function uO(e) {
27959
27935
  function dO({ incomingCall: e, activeCallId: t, callConnectionState: n, callDurationSeconds: r, isCallMuted: i, agentName: a, agentHeadshot: o, fallbackAgentName: s, acceptCall: c, rejectCall: l, endWebRTCCall: u, toggleCallMute: d, formatCallDuration: f, onMinimize: p, primaryColor: m = "#3B82F6", orbColors: h, chatHistory: v = [] }) {
27960
27936
  let y = a || s || "Agent", b = e ? "incoming" : n === "connecting" ? "connecting" : "ongoing", x = uO(!!e), S = async () => {
27961
27937
  x(), await c();
27962
- }, ee = async () => {
27938
+ }, C = async () => {
27963
27939
  x(), await l();
27964
- }, C = i ? "muted" : n === "connecting" ? "idle" : "listening", te = b === "ongoing", w = {
27940
+ }, w = i ? "muted" : n === "connecting" ? "idle" : "listening", T = b === "ongoing", ee = {
27965
27941
  position: "absolute",
27966
27942
  inset: 0,
27967
27943
  zIndex: 10,
@@ -27970,12 +27946,12 @@ function dO({ incomingCall: e, activeCallId: t, callConnectionState: n, callDura
27970
27946
  borderRadius: "inherit",
27971
27947
  overflow: "hidden",
27972
27948
  background: cO(h, m),
27973
- animation: te ? "fe-call-slide-up 0.36s cubic-bezier(0.16,1,0.3,1)" : "fe-call-fade-in 0.32s ease"
27949
+ animation: T ? "fe-call-slide-up 0.36s cubic-bezier(0.16,1,0.3,1)" : "fe-call-fade-in 0.32s ease"
27974
27950
  };
27975
27951
  if (b === "incoming") {
27976
27952
  let e = Array.isArray(h) && h.length > 0 ? h : [m];
27977
27953
  return /* @__PURE__ */ _("div", {
27978
- style: w,
27954
+ style: ee,
27979
27955
  children: [/* @__PURE__ */ g("style", { children: aO }), /* @__PURE__ */ _("div", {
27980
27956
  style: {
27981
27957
  flex: 1,
@@ -28082,7 +28058,7 @@ function dO({ incomingCall: e, activeCallId: t, callConnectionState: n, callDura
28082
28058
  },
28083
28059
  children: [/* @__PURE__ */ g("button", {
28084
28060
  type: "button",
28085
- onClick: ee,
28061
+ onClick: C,
28086
28062
  style: {
28087
28063
  width: "68px",
28088
28064
  height: "68px",
@@ -28161,7 +28137,7 @@ function dO({ incomingCall: e, activeCallId: t, callConnectionState: n, callDura
28161
28137
  });
28162
28138
  }
28163
28139
  return b === "connecting" ? /* @__PURE__ */ _("div", {
28164
- style: w,
28140
+ style: ee,
28165
28141
  children: [/* @__PURE__ */ g("style", { children: aO }), /* @__PURE__ */ _("div", {
28166
28142
  style: {
28167
28143
  flex: 1,
@@ -28197,7 +28173,7 @@ function dO({ incomingCall: e, activeCallId: t, callConnectionState: n, callDura
28197
28173
  ]
28198
28174
  })]
28199
28175
  }) : /* @__PURE__ */ _("div", {
28200
- style: w,
28176
+ style: ee,
28201
28177
  children: [
28202
28178
  /* @__PURE__ */ g("style", { children: aO }),
28203
28179
  /* @__PURE__ */ _("div", {
@@ -28248,7 +28224,7 @@ function dO({ incomingCall: e, activeCallId: t, callConnectionState: n, callDura
28248
28224
  /* @__PURE__ */ g(iO, {
28249
28225
  colors: h,
28250
28226
  size: 36,
28251
- voiceState: C
28227
+ voiceState: w
28252
28228
  }),
28253
28229
  /* @__PURE__ */ g("div", {
28254
28230
  style: {
@@ -29648,27 +29624,6 @@ function Tk(e) {
29648
29624
  }
29649
29625
  },
29650
29626
  flowengage_end_session: async () => ($("flowengage_end_session ▶"), typeof e.requestEndSession == "function" && e.requestEndSession(), "Voice session is ending."),
29651
- flowengage_submit_feedback: async (r) => {
29652
- let i = _k(r), a = Number(i.rating ?? i.score ?? 0), o = (i.comment ?? i.feedback ?? "").toString().trim();
29653
- if ($("flowengage_submit_feedback ▶", {
29654
- rating: a,
29655
- comment: o
29656
- }), !a || a < 1 || a > 5) return "Invalid rating. Please provide a number between 1 and 5.";
29657
- try {
29658
- return (await fetch(`${n}/api/chat/feedback`, {
29659
- method: "POST",
29660
- headers: { "Content-Type": "application/json" },
29661
- body: JSON.stringify({
29662
- chatId: e.chatId || null,
29663
- rating: a,
29664
- comment: o,
29665
- siteId: t
29666
- })
29667
- })).ok ? ($("flowengage_submit_feedback ✓ rating:", a), `Thank you! Your rating of ${a}/5 has been recorded.`) : "Feedback could not be saved right now. Thank you anyway!";
29668
- } catch (e) {
29669
- return $("flowengage_submit_feedback ✖", e.message), "Thank you for your feedback!";
29670
- }
29671
- },
29672
29627
  flowengage_list_forms: async () => {
29673
29628
  let e = $O(), t = ek();
29674
29629
  return $("flowengage_list_forms ✓", `${e.length} field(s)`, `${t.length} button(s)`), JSON.stringify({
@@ -29758,7 +29713,6 @@ function Tk(e) {
29758
29713
  searchSiteContent: a.flowengage_search,
29759
29714
  getPageContent: a.flowengage_page_content,
29760
29715
  endVoiceSession: a.flowengage_end_session,
29761
- submitFeedback: a.flowengage_submit_feedback,
29762
29716
  listPageForms: a.flowengage_list_forms,
29763
29717
  fillFormFields: a.flowengage_fill_form,
29764
29718
  clickPageButton: a.flowengage_click_button
@@ -30158,149 +30112,133 @@ function Fk({ copy: e, orbColors: t, primaryColor: n, onVoice: r, onText: i, onC
30158
30112
  ]
30159
30113
  });
30160
30114
  }
30161
- function Ik({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i, apiBaseUrl: a, chatId: s, historyRef: l, onMessageSync: u }) {
30162
- let [d, f] = m("idle"), [h, v] = m(!1), [y, b] = m(!1), x = p(null), S = p(""), ee = p(async () => {}), C = p(!1), te = p(!1), w = p(!1), T = p(!1), ne = p("minimized"), re = p(null), E = o((e = "minimized") => {
30163
- ne.current = e, T.current = !0, queueMicrotask(() => {
30164
- C.current || (C.current = !0, ee.current?.());
30115
+ function Ik({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i, apiBaseUrl: a, historyRef: s, onMessageSync: l }) {
30116
+ let [u, d] = m("idle"), [f, h] = m(!1), [v, y] = m(!1), b = p(null), x = p(""), S = p(async () => {}), C = p(!1), w = p(!1), T = p(!1), ee = p(!1), te = p("minimized"), ne = p(null), re = o((e = "minimized") => {
30117
+ te.current = e, ee.current = !0, queueMicrotask(() => {
30118
+ C.current || (C.current = !0, S.current?.());
30165
30119
  });
30166
- }, [l]), ie = o(async (e) => {
30167
- T.current = !0;
30120
+ }, [s]), E = o(async (e) => {
30121
+ ee.current = !0;
30168
30122
  try {
30169
- await x.current?.endSession?.();
30123
+ await b.current?.endSession?.();
30170
30124
  } catch {}
30171
- if (x.current = null, f("idle"), v(!1), C.current = !1, i) try {
30125
+ if (b.current = null, d("idle"), h(!1), C.current = !1, i) try {
30172
30126
  Ae(i);
30173
30127
  } catch {}
30174
- typeof u == "function" && await u(l.current), e?.();
30128
+ typeof l == "function" && await l(s.current), e?.();
30175
30129
  }, [
30130
+ s,
30176
30131
  l,
30177
- u,
30178
30132
  i
30179
30133
  ]);
30180
- return ee.current = () => ie(ne.current === "chat" ? t : n), c(() => {
30181
- te.current = h;
30182
- }, [h]), c(() => {
30134
+ return S.current = () => E(te.current === "chat" ? t : n), c(() => {
30135
+ w.current = f;
30136
+ }, [f]), c(() => {
30183
30137
  let e = !1, n = null;
30184
30138
  return (async () => {
30185
30139
  if (!r) {
30186
- f("error");
30140
+ d("error");
30187
30141
  return;
30188
30142
  }
30189
30143
  try {
30190
30144
  if ((await navigator.mediaDevices.getUserMedia({ audio: !0 })).getTracks().forEach((e) => e.stop()), e) return;
30191
- l.current = [], S.current = "", C.current = !1, w.current = !1, T.current = !1, ne.current = "minimized";
30145
+ s.current = [], x.current = "", C.current = !1, T.current = !1, ee.current = !1, te.current = "minimized";
30192
30146
  let t = Ek(Tk({
30193
30147
  siteId: i || null,
30194
30148
  apiBaseUrl: a || null,
30195
- chatId: s || null,
30196
- getLastUserVoiceText: () => S.current,
30149
+ getLastUserVoiceText: () => x.current,
30197
30150
  requestEndSession: () => {
30198
- E();
30151
+ re();
30199
30152
  }
30200
- })), o = i ? ke(i) : null, c = !!o?.transcript, u = {
30153
+ })), o = i ? ke(i) : null, c = !!o?.transcript, l = {
30154
+ agentId: r,
30201
30155
  clientTools: t,
30202
30156
  connectionType: "websocket"
30203
30157
  };
30204
- if (s && a) try {
30205
- let e = await fetch(`${a}/api/voice/signed-url?chatId=${encodeURIComponent(s)}&siteId=${encodeURIComponent(i || "")}`, {
30206
- method: "GET",
30207
- headers: { "Content-Type": "application/json" }
30208
- });
30209
- if (e.ok) {
30210
- let t = await e.json();
30211
- t?.signedUrl && (u.signedUrl = t.signedUrl, console.log("[FlowEngage] ✅ Using signed ElevenLabs URL"));
30212
- }
30213
- } catch (e) {
30214
- console.warn("[FlowEngage] Signed URL fetch failed, falling back to agentId:", e.message);
30215
- }
30216
- if (!u.signedUrl && r && (u.agentId = r), c) u.overrides = { agent: { firstMessage: "" } };
30217
- else {
30218
- let e = typeof window < "u" ? window.location.pathname : "", t = typeof window < "u" ? document.title : "";
30219
- !e || e === "/" || e === "/home" || e === "/index" || (u.overrides = { agent: { firstMessage: `Hi! I see you've landed on the ${t || e.replace(/^\//, "").replace(/[-_]/g, " ").replace(/\//g, " › ") || "this page"} page. Are you looking for something specific here?` } }, console.log(`[FlowEngage] 🏠 Page-context voice greeting injected for path: ${e}`));
30220
- }
30221
- let d = await xD.startSession({
30222
- ...u,
30158
+ c && (l.overrides = { agent: { firstMessage: "" } });
30159
+ let u = await xD.startSession({
30160
+ ...l,
30223
30161
  onUnhandledClientToolCall: (e) => console.error("[FlowEngage] Unhandled tool:", e?.tool_name),
30224
30162
  onModeChange: ({ mode: t }) => {
30225
- e || f(t === "speaking" ? "speaking" : "listening");
30163
+ e || d(t === "speaking" ? "speaking" : "listening");
30226
30164
  },
30227
30165
  onMessage: (t) => {
30228
30166
  if (e) return;
30229
30167
  let n = t.role === "user" ? "user" : "bot", r = t.message || t.text || t.content || "";
30230
30168
  if (r) {
30231
- if (n === "user" && (S.current = r), l.current = [...l.current, {
30169
+ if (n === "user" && (x.current = r), s.current = [...s.current, {
30232
30170
  sender: n,
30233
30171
  message: r,
30234
30172
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
30235
30173
  }], i) try {
30236
- let e = pO(l.current);
30174
+ let e = pO(s.current);
30237
30175
  e && Oe(i, e);
30238
30176
  } catch {}
30239
- Mk(n, r) && E("minimized");
30177
+ Mk(n, r) && re("minimized");
30240
30178
  }
30241
30179
  },
30242
30180
  onError: (t) => {
30243
- if (!e && !T.current && !w.current) {
30244
- w.current = !0, console.error("[FlowEngageVoiceCall] session:error", {
30181
+ if (!e && !ee.current && !T.current) {
30182
+ T.current = !0, console.error("[FlowEngageVoiceCall] session:error", {
30245
30183
  message: t?.message,
30246
30184
  name: t?.name,
30247
30185
  raw: t
30248
30186
  });
30249
30187
  try {
30250
- x.current?.setMicMuted?.(!0);
30188
+ b.current?.setMicMuted?.(!0);
30251
30189
  } catch {}
30252
- v(!0), f("error"), E("chat");
30190
+ h(!0), d("error"), re("chat");
30253
30191
  }
30254
30192
  },
30255
30193
  onDisconnect: () => {
30256
- if (!e && !T.current && !w.current) {
30257
- w.current = !0, console.warn("[FlowEngageVoiceCall] session:disconnected", {
30258
- historyCount: l.current?.length || 0,
30259
- lastUserText: S.current || "",
30260
- wasMuted: te.current
30194
+ if (!e && !ee.current && !T.current) {
30195
+ T.current = !0, console.warn("[FlowEngageVoiceCall] session:disconnected", {
30196
+ historyCount: s.current?.length || 0,
30197
+ lastUserText: x.current || "",
30198
+ wasMuted: w.current
30261
30199
  });
30262
30200
  try {
30263
- x.current?.setMicMuted?.(!0);
30201
+ b.current?.setMicMuted?.(!0);
30264
30202
  } catch {}
30265
- v(!0), E("chat");
30203
+ h(!0), re("chat");
30266
30204
  }
30267
30205
  }
30268
30206
  });
30269
30207
  if (e) {
30270
- d.endSession().catch(() => {});
30208
+ u.endSession().catch(() => {});
30271
30209
  return;
30272
30210
  }
30273
- n = d, x.current = d, f("listening");
30211
+ n = u, b.current = u, d("listening");
30274
30212
  try {
30275
30213
  let e = typeof window < "u" ? window.location.href : "", n = "[]";
30276
30214
  try {
30277
30215
  n = await t.list_page_forms();
30278
30216
  } catch {}
30279
30217
  let r = c ? `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${o.transcript}\n\n` : "";
30280
- d.sendContextualUpdate(`${r}Page: ${e}. SiteId: ${i || "unknown"}. Forms: ${n}. Voice: call end_voice_session or say you are ending the session to stop.`);
30218
+ u.sendContextualUpdate(`${r}Page: ${e}. SiteId: ${i || "unknown"}. Forms: ${n}. Voice: call end_voice_session or say you are ending the session to stop.`);
30281
30219
  } catch {}
30282
30220
  } catch (n) {
30283
- e || (console.error("[FlowEngage] startSession failed", n), f("error"), ne.current = "chat", window.setTimeout(() => {
30221
+ e || (console.error("[FlowEngage] startSession failed", n), d("error"), te.current = "chat", window.setTimeout(() => {
30284
30222
  e || t?.();
30285
30223
  }, 0));
30286
30224
  }
30287
30225
  })(), () => {
30288
- e = !0, T.current = !0, (n || x.current)?.endSession?.().catch(() => {});
30226
+ e = !0, ee.current = !0, (n || b.current)?.endSession?.().catch(() => {});
30289
30227
  };
30290
30228
  }, [
30291
30229
  r,
30292
30230
  i,
30293
30231
  a,
30294
- E
30232
+ re
30295
30233
  ]), c(() => {
30296
- if (!y) return;
30234
+ if (!v) return;
30297
30235
  let e = (e) => {
30298
30236
  let t = e.composedPath?.()?.[0] || e.target;
30299
- re.current && !re.current.contains(t) && b(!1);
30237
+ ne.current && !ne.current.contains(t) && y(!1);
30300
30238
  };
30301
30239
  return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
30302
- }, [y]), /* @__PURE__ */ _("div", {
30303
- ref: re,
30240
+ }, [v]), /* @__PURE__ */ _("div", {
30241
+ ref: ne,
30304
30242
  style: {
30305
30243
  position: "relative",
30306
30244
  display: "flex",
@@ -30312,7 +30250,7 @@ function Ik({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30312
30250
  children: [
30313
30251
  /* @__PURE__ */ _("div", {
30314
30252
  style: { position: "relative" },
30315
- children: [d === "listening" && /* @__PURE__ */ g("span", {
30253
+ children: [u === "listening" && /* @__PURE__ */ g("span", {
30316
30254
  style: {
30317
30255
  position: "absolute",
30318
30256
  right: "100%",
@@ -30329,12 +30267,12 @@ function Ik({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30329
30267
  children: "Listening..."
30330
30268
  }), /* @__PURE__ */ g(Nk, {
30331
30269
  size: 72,
30332
- voiceState: d,
30333
- isMuted: h,
30270
+ voiceState: u,
30271
+ isMuted: f,
30334
30272
  orbColors: e
30335
30273
  })]
30336
30274
  }),
30337
- d === "error" && /* @__PURE__ */ g("span", {
30275
+ u === "error" && /* @__PURE__ */ g("span", {
30338
30276
  style: {
30339
30277
  color: "#f87171",
30340
30278
  fontSize: "13px",
@@ -30350,28 +30288,28 @@ function Ik({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30350
30288
  },
30351
30289
  children: [/* @__PURE__ */ g("button", {
30352
30290
  onClick: async () => {
30353
- if (x.current) try {
30354
- h ? (await x.current.setMicMuted?.(!1), v(!1)) : (await x.current.setMicMuted?.(!0), v(!0));
30291
+ if (b.current) try {
30292
+ f ? (await b.current.setMicMuted?.(!1), h(!1)) : (await b.current.setMicMuted?.(!0), h(!0));
30355
30293
  } catch {}
30356
30294
  },
30357
- title: h ? "Unmute" : "Mute",
30295
+ title: f ? "Unmute" : "Mute",
30358
30296
  style: {
30359
30297
  width: "24px",
30360
30298
  height: "24px",
30361
30299
  borderRadius: "50%",
30362
- background: h ? "#7f1d1d" : "#1f2937",
30363
- border: h ? "1.5px solid #ef4444" : "1.5px solid #4b5563",
30300
+ background: f ? "#7f1d1d" : "#1f2937",
30301
+ border: f ? "1.5px solid #ef4444" : "1.5px solid #4b5563",
30364
30302
  display: "flex",
30365
30303
  alignItems: "center",
30366
30304
  justifyContent: "center",
30367
30305
  cursor: "pointer",
30368
- color: h ? "#f87171" : "white",
30306
+ color: f ? "#f87171" : "white",
30369
30307
  transition: "all 0.2s ease",
30370
30308
  boxShadow: "0 2px 8px rgba(0,0,0,0.4)",
30371
30309
  padding: 0,
30372
30310
  flexShrink: 0
30373
30311
  },
30374
- children: h ? /* @__PURE__ */ _("svg", {
30312
+ children: f ? /* @__PURE__ */ _("svg", {
30375
30313
  width: "16",
30376
30314
  height: "16",
30377
30315
  viewBox: "0 0 24 24",
@@ -30407,7 +30345,7 @@ function Ik({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30407
30345
  color: "currentColor"
30408
30346
  })
30409
30347
  }), /* @__PURE__ */ g("button", {
30410
- onClick: () => b((e) => !e),
30348
+ onClick: () => y((e) => !e),
30411
30349
  style: {
30412
30350
  width: "24px",
30413
30351
  height: "24px",
@@ -30430,7 +30368,7 @@ function Ik({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30430
30368
  })
30431
30369
  })]
30432
30370
  }),
30433
- y && /* @__PURE__ */ _("div", {
30371
+ v && /* @__PURE__ */ _("div", {
30434
30372
  style: {
30435
30373
  position: "absolute",
30436
30374
  bottom: 0,
@@ -30448,7 +30386,7 @@ function Ik({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30448
30386
  children: [
30449
30387
  /* @__PURE__ */ _("button", {
30450
30388
  onClick: () => {
30451
- b(!1), ne.current = "chat", ie(t);
30389
+ y(!1), te.current = "chat", E(t);
30452
30390
  },
30453
30391
  style: {
30454
30392
  display: "flex",
@@ -30477,7 +30415,7 @@ function Ik({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30477
30415
  }),
30478
30416
  /* @__PURE__ */ _("button", {
30479
30417
  onClick: () => {
30480
- b(!1), ne.current = "minimized", ie(n);
30418
+ y(!1), te.current = "minimized", E(n);
30481
30419
  },
30482
30420
  style: {
30483
30421
  display: "flex",
@@ -30505,7 +30443,7 @@ function Ik({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30505
30443
  children: [/* @__PURE__ */ g(MD, {}), "End Conversation"]
30506
30444
  }),
30507
30445
  /* @__PURE__ */ g("button", {
30508
- onClick: () => b(!1),
30446
+ onClick: () => y(!1),
30509
30447
  style: {
30510
30448
  position: "absolute",
30511
30449
  bottom: "8px",
@@ -30600,8 +30538,8 @@ var Rk = () => /* @__PURE__ */ g("div", {
30600
30538
  } }, e))
30601
30539
  })
30602
30540
  });
30603
- function zk({ 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: ee, isConversationEnded: C, isLoading: te, isRateLimited: w, rateLimitMessage: T, selectedFile: ne, onFileSelect: re, onRemoveSelectedFile: E, attachmentError: ie, isUploadingAttachment: ae, requiresEmail: oe, emailInput: D, setEmailInput: se, emailError: ce, replyContext: le, setReplyContext: ue, webRTCError: de, micError: fe, setMicError: pe, dismissCallError: me, activeCallId: he, isCallMuted: ge, toggleCallMute: _e, endWebRTCCall: ve, formatCallDuration: ye, callDurationSeconds: be, isCallMinimized: xe, onExpand: Se, onCollapse: Ce, onStartVoice: we, onNewChat: Te, onEndConversation: Ee, showPoweredBy: De, getVisitorChatHistory: Oe, getVisitorChatThread: ke, resumeChat: Ae, isSessionRestoring: je, isClosing: Me }) {
30604
- let Ne = l.length > 0, Pe = te || w || C, Fe = !!he, [Ie, Le] = m(!1), [Re, ze] = m(!1), [Be, Ve] = m([]), [He, Ue] = m(!1), [We, Ge] = m(null), [Ke, qe] = m([]), Je = p(null), Ye = async () => {
30541
+ function zk({ 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, replyContext: le, setReplyContext: ue, webRTCError: de, micError: fe, setMicError: pe, dismissCallError: me, activeCallId: he, isCallMuted: ge, toggleCallMute: _e, endWebRTCCall: ve, formatCallDuration: ye, callDurationSeconds: be, isCallMinimized: xe, onExpand: Se, onCollapse: Ce, onStartVoice: we, onNewChat: Te, onEndConversation: Ee, showPoweredBy: De, getVisitorChatHistory: Oe, getVisitorChatThread: ke, resumeChat: Ae, isSessionRestoring: je, isClosing: Me }) {
30542
+ let Ne = l.length > 0, Pe = T || ee || w, Fe = !!he, [Ie, Le] = m(!1), [Re, ze] = m(!1), [Be, Ve] = m([]), [He, Ue] = m(!1), [We, Ge] = m(null), [Ke, qe] = m([]), Je = p(null), Ye = async () => {
30605
30543
  Le(!1), ze(!0), Ue(!0), Ge(null);
30606
30544
  try {
30607
30545
  let e = await Oe();
@@ -31023,8 +30961,8 @@ function zk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
31023
30961
  micError: fe,
31024
30962
  setMicError: pe,
31025
30963
  dismissCallError: me,
31026
- isRateLimited: w,
31027
- rateLimitMessage: T
30964
+ isRateLimited: ee,
30965
+ rateLimitMessage: te
31028
30966
  }),
31029
30967
  xe && /* @__PURE__ */ g(fO, {
31030
30968
  agentName: v,
@@ -31221,7 +31159,7 @@ function zk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
31221
31159
  }) : null, Ne ? /* @__PURE__ */ g(qD, {
31222
31160
  chatHistory: l,
31223
31161
  isAiTyping: u,
31224
- isLoading: te,
31162
+ isLoading: T,
31225
31163
  isAgentTyping: d,
31226
31164
  setReplyContext: ue,
31227
31165
  TypingDots: Rk,
@@ -31330,8 +31268,8 @@ function zk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
31330
31268
  children: /* @__PURE__ */ g(JD, {
31331
31269
  input: x,
31332
31270
  setInput: S,
31333
- onSubmit: ee,
31334
- isConversationEnded: C,
31271
+ onSubmit: C,
31272
+ isConversationEnded: w,
31335
31273
  callUiActive: Fe,
31336
31274
  handleToggleVoice: we,
31337
31275
  showVoiceToggle: f === "agent",
@@ -31378,275 +31316,275 @@ function zk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
31378
31316
  });
31379
31317
  }
31380
31318
  function Bk() {
31381
- let { status: e, runtimeConfig: t, resolvedConfig: n, chatId: r, chatHistory: i, isOpen: a, activeScreen: s, isHumanHandled: l, agentName: u, agentHeadshot: h, visitorEmail: v, isAgentTyping: y, isAiTyping: b, isLoading: x, isRateLimited: S, rateLimitMessage: ee, isConversationEnded: C, incomingCall: te, activeCallId: w, callConnectionState: T, callConnectedAt: ne, isCallMuted: re, webRTCError: E, language: 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, getVisitorChatThread: we, resumeChat: Te, isSessionRestoring: Ee } = An();
31319
+ 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, historyRef: ie, onMessageSync: ae, sendMessage: oe, uploadChatFile: D, openWidget: se, captureVisitorEmail: ce, setVoiceMode: le, endConversation: ue, startNewChat: de, acceptCall: me, rejectCall: he, endWebRTCCall: ge, toggleCallMute: _e, dismissCallError: ve, startTyping: ye, stopTyping: be, updateTypingDraft: xe, getVisitorChatHistory: Se, getVisitorChatThread: Ce, resumeChat: we, isSessionRestoring: Te } = An();
31382
31320
  c(() => {
31383
31321
  try {
31384
31322
  rr();
31385
31323
  } catch {}
31386
31324
  }, []);
31387
- let De = t?.widgetSettings || {}, Oe = n?.widgetSettings || {}, ke = {
31388
- ...De.branding || {},
31389
- ...Oe.branding || {}
31325
+ let Ee = t?.widgetSettings || {}, De = n?.widgetSettings || {}, Oe = {
31326
+ ...Ee.branding || {},
31327
+ ...De.branding || {}
31328
+ }, ke = {
31329
+ ...Ee.theme || {},
31330
+ ...De.theme || {}
31390
31331
  }, Ae = {
31391
- ...De.theme || {},
31392
- ...Oe.theme || {}
31393
- }, je = {
31394
- ...De.features || {},
31395
- ...Oe.features || {}
31396
- }, Me = je.voice !== !1, Pe = Array.isArray(Ae.orbColors) && Ae.orbColors.length > 0 ? Ae.orbColors : null, Fe = Ae.buttonColor || Ae.primaryColor || Pe?.[0] || "#3B82F6", Ie = Ae.position || "bottom-right", Le = ke.fallbackAgentName || "Agent", Re = Ok(Pe ?? Ae.chatBgColors), ze = ke.logo || ke.logoUrl || null, Be = ie || "en", Ve = De.recommendations?.[Be] || [], He = (Oe.recommendations?.[Be] ?? Ve).filter((e) => String(e?.label ?? "").trim()).map((e, t) => ({
31332
+ ...Ee.features || {},
31333
+ ...De.features || {}
31334
+ }, je = Ae.voice !== !1, Me = Array.isArray(ke.orbColors) && ke.orbColors.length > 0 ? ke.orbColors : null, Pe = ke.buttonColor || ke.primaryColor || Me?.[0] || "#3B82F6", Fe = ke.position || "bottom-right", Ie = Oe.fallbackAgentName || "Agent", Le = Ok(Me ?? ke.chatBgColors), Re = Oe.logo || Oe.logoUrl || null, ze = E || "en", Be = Ee.recommendations?.[ze] || [], Ve = (De.recommendations?.[ze] ?? Be).filter((e) => String(e?.label ?? "").trim()).map((e, t) => ({
31397
31335
  id: e.key || `qr-${t}`,
31398
31336
  label: e.label,
31399
31337
  message: e.label,
31400
31338
  text: e.label
31401
- })), Ue = Array.isArray(ke.quickChatOptions) && ke.quickChatOptions.length > 0 ? ke.quickChatOptions : He, We = ke.hideWatermark === !0 ? !1 : ke.showPoweredBy !== !1, Ge = ke.chatbotEnabled !== !1 && Ae.chatbotEnabled !== !1, Ke = De.greetings?.[ie] || Oe.greetings?.[ie] || ke.introGreeting || "Hello, I'm here to help you know more about OpenSense Labs.", qe = {
31402
- entryPrompt: ke.entryPrompt || "Do you want to explore in a new way?",
31403
- yesLabel: ke.yesLabel || "Yes",
31404
- laterLabel: ke.laterLabel || "Later",
31405
- connectionTitle: ke.connectionTitle || "How would you like to connect?",
31406
- voiceLabel: ke.voiceLabel || "Voice",
31407
- textLabel: ke.textLabel || "Text",
31408
- chatTitle: ke.headerName || "Chat with FlowEngage",
31409
- introGreeting: Ke,
31410
- inputPlaceholder: ke.inputPlaceholder || "Type your message",
31411
- analysingLabel: ke.analysingLabel || "analysing..."
31412
- }, Je = Oe.elevenLabsAgentId || t?.elevenLabsAgentId || null, Ye = t?.siteId || n?.siteId || null, Xe = t?.apiBaseUrl || "", Ze = f(() => u && String(u).trim() || t?.ownerName && String(t.ownerName).trim() || t?.websiteName && String(t.websiteName).trim() || "Agent", [
31413
- u,
31339
+ })), He = Array.isArray(Oe.quickChatOptions) && Oe.quickChatOptions.length > 0 ? Oe.quickChatOptions : Ve, Ue = Oe.hideWatermark === !0 ? !1 : Oe.showPoweredBy !== !1, We = Oe.chatbotEnabled !== !1 && ke.chatbotEnabled !== !1, Ge = Ee.greetings?.[E] || De.greetings?.[E] || Oe.introGreeting || "Hello, I'm here to help you know more about OpenSense Labs.", Ke = {
31340
+ entryPrompt: Oe.entryPrompt || "Do you want to explore in a new way?",
31341
+ yesLabel: Oe.yesLabel || "Yes",
31342
+ laterLabel: Oe.laterLabel || "Later",
31343
+ connectionTitle: Oe.connectionTitle || "How would you like to connect?",
31344
+ voiceLabel: Oe.voiceLabel || "Voice",
31345
+ textLabel: Oe.textLabel || "Text",
31346
+ chatTitle: Oe.headerName || "Chat with FlowEngage",
31347
+ introGreeting: Ge,
31348
+ inputPlaceholder: Oe.inputPlaceholder || "Type your message",
31349
+ analysingLabel: Oe.analysingLabel || "analysing..."
31350
+ }, qe = De.elevenLabsAgentId || t?.elevenLabsAgentId || null, Je = t?.siteId || n?.siteId || null, Ye = t?.apiBaseUrl || "", Xe = f(() => l && String(l).trim() || t?.ownerName && String(t.ownerName).trim() || t?.websiteName && String(t.websiteName).trim() || "Agent", [
31351
+ l,
31414
31352
  t?.ownerName,
31415
31353
  t?.websiteName
31416
- ]), Qe = h && String(h).trim() || t?.ownerProfileImageUrl && String(t.ownerProfileImageUrl).trim() || null, $e = i.some((e) => e.sender === "user"), et = f(() => {
31417
- let e = i.findIndex((e) => e.sender === "user");
31418
- return e === -1 ? !1 : i.slice(e + 1).some((e) => e.sender === "bot" || e.sender === "ai" || e.sender === "agent");
31419
- }, [i]), tt = !v && $e && et, nt = !!(Oe._dashboardLivePreview || De._dashboardLivePreview), [rt, it] = m(() => nt ? "text_chat" : "entry_prompt"), [at, O] = m(""), [ot, st] = m(null), [ct, lt] = m(v || ""), [k, ut] = m(""), [dt, ft] = m(0), [pt, mt] = m(null), [ht, gt] = m(null), [_t, vt] = m(""), [yt, bt] = m(!1), [xt, St] = m(!1), [Ct, wt] = m(!1), Tt = p(null), Et = p(!1);
31354
+ ]), Ze = u && String(u).trim() || t?.ownerProfileImageUrl && String(t.ownerProfileImageUrl).trim() || null, Qe = r.some((e) => e.sender === "user"), $e = f(() => {
31355
+ let e = r.findIndex((e) => e.sender === "user");
31356
+ return e === -1 ? !1 : r.slice(e + 1).some((e) => e.sender === "bot" || e.sender === "ai" || e.sender === "agent");
31357
+ }, [r]), et = !h && Qe && $e, tt = !!(De._dashboardLivePreview || Ee._dashboardLivePreview), [O, nt] = m(() => tt ? "text_chat" : "entry_prompt"), [rt, it] = m(""), [at, ot] = m(null), [st, ct] = m(h || ""), [lt, k] = m(""), [ut, dt] = m(0), [ft, pt] = m(null), [mt, ht] = m(null), [gt, _t] = m(""), [vt, yt] = m(!1), [bt, xt] = m(!1), [St, Ct] = m(!1), wt = p(null), Tt = p(!1);
31420
31358
  d(() => {
31421
- if (!(e !== "ready" || Et.current)) {
31422
- if (Et.current = !0, Me && Ne()) {
31423
- ce?.({ notifyChatInitiated: !0 }), ue?.(!0), it("voice_mode");
31359
+ if (!(e !== "ready" || Tt.current)) {
31360
+ if (Tt.current = !0, je && Ne()) {
31361
+ se?.({ notifyChatInitiated: !0 }), le?.(!0), nt("voice_mode");
31424
31362
  return;
31425
31363
  }
31426
- if (fe(Ye) || !Me) {
31427
- it("minimized_orb");
31364
+ if (fe(Je) || !je) {
31365
+ nt("minimized_orb");
31428
31366
  return;
31429
31367
  }
31430
31368
  try {
31431
31369
  let { shouldResumeVoice: e } = mr();
31432
- e && it("connection_modal");
31370
+ e && nt("connection_modal");
31433
31371
  } catch {}
31434
31372
  }
31435
- }, [e, i]);
31436
- let [Dt, Ot] = m(() => typeof window < "u" && window.matchMedia("(max-width: 640px)").matches);
31373
+ }, [e, r]);
31374
+ let [Et, Dt] = m(() => typeof window < "u" && window.matchMedia("(max-width: 640px)").matches);
31437
31375
  c(() => {
31438
- let e = window.matchMedia("(max-width: 640px)"), t = (e) => Ot(e.matches);
31376
+ let e = window.matchMedia("(max-width: 640px)"), t = (e) => Dt(e.matches);
31439
31377
  return e.addEventListener("change", t), () => e.removeEventListener("change", t);
31440
31378
  }, []), c(() => {
31441
- lt(v || ""), v && ut("");
31442
- }, [v]);
31443
- let kt = o(() => {
31444
- gt(null), vt("");
31445
- }, []), At = o((e) => {
31379
+ ct(h || ""), h && k("");
31380
+ }, [h]);
31381
+ let Ot = o(() => {
31382
+ ht(null), _t("");
31383
+ }, []), kt = o((e) => {
31446
31384
  let t = HD(e);
31447
31385
  if (t) {
31448
- gt(null), vt(t);
31386
+ ht(null), _t(t);
31449
31387
  return;
31450
31388
  }
31451
- gt(e), vt("");
31389
+ ht(e), _t("");
31452
31390
  }, []);
31453
31391
  c(() => {
31454
- if (!ne || T !== "connected") {
31455
- ft(0);
31392
+ if (!te || ee !== "connected") {
31393
+ dt(0);
31456
31394
  return;
31457
31395
  }
31458
31396
  let e = () => {
31459
- let e = new Date(ne).getTime();
31460
- isNaN(e) || ft(Math.max(0, Math.floor((Date.now() - e) / 1e3)));
31397
+ let e = new Date(te).getTime();
31398
+ isNaN(e) || dt(Math.max(0, Math.floor((Date.now() - e) / 1e3)));
31461
31399
  };
31462
31400
  e();
31463
31401
  let t = window.setInterval(e, 1e3);
31464
31402
  return () => window.clearInterval(t);
31465
- }, [ne, T]);
31466
- let jt = o(() => {
31467
- it("call_screen"), St(!1);
31468
- }, []), Mt = o(() => {
31469
- it("text_chat"), St(!0);
31403
+ }, [te, ee]);
31404
+ let At = o(() => {
31405
+ nt("call_screen"), xt(!1);
31406
+ }, []), jt = o(() => {
31407
+ nt("text_chat"), xt(!0);
31470
31408
  }, []);
31471
31409
  c(() => {
31472
- let e = te?.callId || w || null;
31410
+ let e = w?.callId || T || null;
31473
31411
  if (!e) {
31474
- Tt.current = null;
31412
+ wt.current = null;
31475
31413
  return;
31476
31414
  }
31477
- if (te?.callId || T === "connecting" || T === "connected") {
31478
- if (rt === "minimized_orb" && xt && w && !te?.callId) {
31479
- Tt.current = e;
31415
+ if (w?.callId || ee === "connecting" || ee === "connected") {
31416
+ if (O === "minimized_orb" && bt && T && !w?.callId) {
31417
+ wt.current = e;
31480
31418
  return;
31481
31419
  }
31482
- !(!a || rt === "minimized_orb" || rt === "voice_mode") && Tt.current === e || (console.log("[FlowEngageWidget] forcing call UI to front", {
31420
+ !(!i || O === "minimized_orb" || O === "voice_mode") && wt.current === e || (console.log("[FlowEngageWidget] forcing call UI to front", {
31483
31421
  forcedKey: e,
31484
- isOpen: a,
31485
- surface: rt,
31486
- hasIncomingCall: !!te?.callId,
31487
- activeCallId: w,
31488
- callConnectionState: T
31489
- }), Tt.current = e, rt === "voice_mode" && ue?.(!1), ce?.(), jt());
31422
+ isOpen: i,
31423
+ surface: O,
31424
+ hasIncomingCall: !!w?.callId,
31425
+ activeCallId: T,
31426
+ callConnectionState: ee
31427
+ }), wt.current = e, O === "voice_mode" && le?.(!1), se?.(), At());
31490
31428
  }
31491
31429
  }, [
31492
- w,
31493
31430
  T,
31494
- jt,
31495
- te?.callId,
31496
- a,
31497
- ce,
31498
- ue,
31499
- rt
31431
+ ee,
31432
+ At,
31433
+ w?.callId,
31434
+ i,
31435
+ se,
31436
+ le,
31437
+ O
31500
31438
  ]), c(() => {
31501
- !te && !w && rt === "call_screen" && it("text_chat");
31439
+ !w && !T && O === "call_screen" && nt("text_chat");
31502
31440
  }, [
31503
- te,
31504
31441
  w,
31505
- rt
31442
+ T,
31443
+ O
31506
31444
  ]), c(() => {
31507
- !w && xt && St(!1);
31508
- }, [w, xt]), c(() => {
31509
- if (!l || C) {
31510
- Se?.(""), xe?.();
31445
+ !T && bt && xt(!1);
31446
+ }, [T, bt]), c(() => {
31447
+ if (!s || C) {
31448
+ xe?.(""), be?.();
31511
31449
  return;
31512
31450
  }
31513
- if (!at.trim() || ht) {
31514
- Se?.("");
31515
- let e = window.setTimeout(() => xe?.(), 100);
31451
+ if (!rt.trim() || mt) {
31452
+ xe?.("");
31453
+ let e = window.setTimeout(() => be?.(), 100);
31516
31454
  return () => window.clearTimeout(e);
31517
31455
  }
31518
- be?.();
31519
- let e = window.setTimeout(() => Se?.(at), 120), t = window.setTimeout(() => xe?.(), 1200);
31456
+ ye?.();
31457
+ let e = window.setTimeout(() => xe?.(rt), 120), t = window.setTimeout(() => be?.(), 1200);
31520
31458
  return () => {
31521
31459
  window.clearTimeout(e), window.clearTimeout(t);
31522
31460
  };
31523
31461
  }, [
31524
- at,
31525
- ht,
31526
- l,
31462
+ rt,
31463
+ mt,
31464
+ s,
31527
31465
  C,
31466
+ ye,
31528
31467
  be,
31529
- xe,
31530
- Se
31468
+ xe
31531
31469
  ]);
31532
- let Nt = (e) => e ? {
31470
+ let Mt = (e) => e ? {
31533
31471
  replyTo: e.messageId || e.id || null,
31534
31472
  replyToContent: (e.replyToContent || e.message || "").replace(/<[^>]+>/g, "").trim().slice(0, 200),
31535
31473
  replyToSender: e.sender || null
31536
- } : null, Pt = async (e) => {
31474
+ } : null, Nt = async (e) => {
31537
31475
  if (e.preventDefault(), C) return;
31538
- if (tt) {
31539
- let e = ct.trim().toLowerCase();
31476
+ if (et) {
31477
+ let e = st.trim().toLowerCase();
31540
31478
  if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)) {
31541
- ut("Please enter a valid email so we can continue helping you.");
31479
+ k("Please enter a valid email so we can continue helping you.");
31542
31480
  return;
31543
31481
  }
31544
- await le(e), ut("");
31482
+ await ce(e), k("");
31545
31483
  return;
31546
31484
  }
31547
- let t = Nt(ot);
31548
- if (!at.trim() && !ht) return;
31549
- if (ht) {
31485
+ let t = Mt(at);
31486
+ if (!rt.trim() && !mt) return;
31487
+ if (mt) {
31550
31488
  try {
31551
- bt(!0), vt("");
31552
- let e = await se(ht), n = e?.data || e, r = at.trim() || `Shared file: ${WD(ht)}`;
31553
- O(""), st(null), kt(), await D(r, "", t, {
31489
+ yt(!0), _t("");
31490
+ let e = await D(mt), n = e?.data || e, r = rt.trim() || `Shared file: ${WD(mt)}`;
31491
+ it(""), ot(null), Ot(), await oe(r, "", t, {
31554
31492
  type: "file",
31555
31493
  metadata: {
31556
31494
  fileUrl: n?.fileUrl,
31557
- fileName: n?.fileName || ht.name,
31558
- fileType: n?.fileType || ht.type,
31559
- fileSize: n?.fileSize || ht.size
31495
+ fileName: n?.fileName || mt.name,
31496
+ fileType: n?.fileType || mt.type,
31497
+ fileSize: n?.fileSize || mt.size
31560
31498
  }
31561
31499
  });
31562
31500
  } catch (e) {
31563
- vt(e?.message || "Failed to upload the selected file.");
31501
+ _t(e?.message || "Failed to upload the selected file.");
31564
31502
  } finally {
31565
- bt(!1);
31503
+ yt(!1);
31566
31504
  }
31567
31505
  return;
31568
31506
  }
31569
- let n = at.trim();
31570
- O(""), st(null), await D(n, "", t);
31571
- }, Ft = (e) => {
31507
+ let n = rt.trim();
31508
+ it(""), ot(null), await oe(n, "", t);
31509
+ }, Pt = (e) => {
31572
31510
  let t = Math.floor(e / 60);
31573
31511
  return `${String(t).padStart(2, "0")}:${String(e % 60).padStart(2, "0")}`;
31574
- }, It = o(async (e) => {
31575
- if (C || x) return;
31512
+ }, Ft = o(async (e) => {
31513
+ if (C || b) return;
31576
31514
  let t = e.message || e.label || e.text || "";
31577
- t.trim() && await D(t.trim(), "");
31515
+ t.trim() && await oe(t.trim(), "");
31578
31516
  }, [
31579
31517
  C,
31580
- x,
31581
- D
31582
- ]), Lt = Dt && rt === "entry_prompt" ? { inset: 0 } : Dt && rt === "text_chat" ? {
31518
+ b,
31519
+ oe
31520
+ ]), It = Et && O === "entry_prompt" ? { inset: 0 } : Et && O === "text_chat" ? {
31583
31521
  left: 0,
31584
31522
  right: 0,
31585
31523
  bottom: 0
31586
- } : Dt && rt === "call_screen" ? {
31524
+ } : Et && O === "call_screen" ? {
31587
31525
  left: 0,
31588
31526
  right: 0,
31589
31527
  bottom: 0,
31590
31528
  height: "90dvh",
31591
31529
  overflow: "hidden",
31592
31530
  borderRadius: "16px 16px 0 0"
31593
- } : Dt && rt === "connection_modal" ? {
31531
+ } : Et && O === "connection_modal" ? {
31594
31532
  left: "28px",
31595
31533
  right: "12px",
31596
31534
  bottom: "12px"
31597
- } : rt === "call_screen" ? {
31535
+ } : O === "call_screen" ? {
31598
31536
  width: "min(350px, calc(100vw - 40px))",
31599
31537
  height: "min(640px, calc(100vh - 120px))",
31600
31538
  borderRadius: "22px",
31601
31539
  overflow: "hidden",
31602
- ...Ie === "bottom-left" ? {
31540
+ ...Fe === "bottom-left" ? {
31603
31541
  left: "1.5rem",
31604
31542
  bottom: "1.5rem"
31605
31543
  } : {
31606
31544
  right: "1.5rem",
31607
31545
  bottom: "1.5rem"
31608
31546
  }
31609
- } : Ie === "bottom-left" ? {
31547
+ } : Fe === "bottom-left" ? {
31610
31548
  left: "1.5rem",
31611
31549
  bottom: "1.5rem"
31612
31550
  } : {
31613
31551
  right: "1.5rem",
31614
31552
  bottom: "1.5rem"
31615
- }, Rt = o(() => {
31616
- rt !== "minimized_orb" && (wt(!0), setTimeout(() => {
31617
- it("minimized_orb"), wt(!1);
31553
+ }, Lt = o(() => {
31554
+ O !== "minimized_orb" && (Ct(!0), setTimeout(() => {
31555
+ nt("minimized_orb"), Ct(!1);
31618
31556
  }, 280));
31619
- }, [rt]), zt = () => it("connection_modal"), Bt = () => {
31620
- ce({ notifyChatInitiated: !0 }), ue?.(!0), it("voice_mode");
31557
+ }, [O]), Rt = () => nt("connection_modal"), zt = () => {
31558
+ se({ notifyChatInitiated: !0 }), le?.(!0), nt("voice_mode");
31559
+ }, Bt = () => {
31560
+ se({ notifyChatInitiated: !0 }), le?.(!1), nt("text_chat");
31621
31561
  }, Vt = () => {
31622
- ce({ notifyChatInitiated: !0 }), ue?.(!1), it("text_chat");
31623
- }, Ht = () => {
31624
- ue?.(!1), Rt();
31562
+ le?.(!1), Lt();
31625
31563
  };
31626
- return e !== "ready" || !Ge || je.chat === !1 ? null : /* @__PURE__ */ _("div", {
31564
+ return e !== "ready" || !We || Ae.chat === !1 ? null : /* @__PURE__ */ _("div", {
31627
31565
  className: "flowengage-widget-root",
31628
31566
  style: {
31629
31567
  position: "fixed",
31630
31568
  zIndex: 999999,
31631
- ...Lt
31569
+ ...It
31632
31570
  },
31633
31571
  onWheel: (e) => e.stopPropagation(),
31634
31572
  onTouchMove: (e) => e.stopPropagation(),
31635
31573
  children: [
31636
- rt === "entry_prompt" && /* @__PURE__ */ g(Pk, {
31637
- copy: qe,
31638
- orbColors: Pe,
31639
- primaryColor: Fe,
31574
+ O === "entry_prompt" && /* @__PURE__ */ g(Pk, {
31575
+ copy: Ke,
31576
+ orbColors: Me,
31577
+ primaryColor: Pe,
31640
31578
  onYes: () => {
31641
- pe(Ye), Bt();
31579
+ pe(Je), zt();
31642
31580
  },
31643
31581
  onLater: () => {
31644
- pe(Ye), Rt();
31582
+ pe(Je), Lt();
31645
31583
  },
31646
- isMobile: Dt,
31647
- isClosing: Ct
31584
+ isMobile: Et,
31585
+ isClosing: St
31648
31586
  }),
31649
- rt === "minimized_orb" && /* @__PURE__ */ _(fm.div, {
31587
+ O === "minimized_orb" && /* @__PURE__ */ _(fm.div, {
31650
31588
  layoutId: "fe-main-orb",
31651
31589
  initial: {
31652
31590
  scale: .4,
@@ -31665,14 +31603,14 @@ function Bk() {
31665
31603
  transformOrigin: "bottom right",
31666
31604
  display: "inline-flex",
31667
31605
  flexDirection: "column",
31668
- alignItems: Ie === "bottom-left" ? "flex-start" : "flex-end",
31606
+ alignItems: Fe === "bottom-left" ? "flex-start" : "flex-end",
31669
31607
  gap: "10px"
31670
31608
  },
31671
- children: [w && xt && /* @__PURE__ */ _("button", {
31609
+ children: [T && bt && /* @__PURE__ */ _("button", {
31672
31610
  type: "button",
31673
- onClick: jt,
31611
+ onClick: At,
31674
31612
  style: {
31675
- maxWidth: Dt ? "220px" : "240px",
31613
+ maxWidth: Et ? "220px" : "240px",
31676
31614
  padding: "10px 14px",
31677
31615
  borderRadius: "18px",
31678
31616
  border: "1px solid rgba(255,255,255,0.7)",
@@ -31703,7 +31641,7 @@ function Bk() {
31703
31641
  color: "#111827",
31704
31642
  lineHeight: 1.2
31705
31643
  },
31706
- children: T === "connected" ? "Call in progress" : "Call is active"
31644
+ children: ee === "connected" ? "Call in progress" : "Call is active"
31707
31645
  }), /* @__PURE__ */ g("span", {
31708
31646
  style: {
31709
31647
  display: "block",
@@ -31713,112 +31651,111 @@ function Bk() {
31713
31651
  marginTop: "2px",
31714
31652
  whiteSpace: "nowrap"
31715
31653
  },
31716
- children: T === "connected" ? `${Ft(dt)} with ${Ze}` : `Tap to return to ${Ze}`
31654
+ children: ee === "connected" ? `${Pt(ut)} with ${Xe}` : `Tap to return to ${Xe}`
31717
31655
  })]
31718
31656
  })]
31719
31657
  }), /* @__PURE__ */ g(Nk, {
31720
31658
  size: 50,
31721
- orbColors: Pe,
31722
- onClick: w && xt ? jt : Me ? zt : Vt
31659
+ orbColors: Me,
31660
+ onClick: T && bt ? At : je ? Rt : Bt
31723
31661
  })]
31724
31662
  }),
31725
- rt === "connection_modal" && /* @__PURE__ */ g(Fk, {
31726
- copy: qe,
31727
- orbColors: Pe,
31728
- primaryColor: Fe,
31729
- onVoice: Bt,
31730
- onText: Vt,
31731
- onClose: Rt,
31732
- isMobile: Dt,
31733
- isClosing: Ct
31663
+ O === "connection_modal" && /* @__PURE__ */ g(Fk, {
31664
+ copy: Ke,
31665
+ orbColors: Me,
31666
+ primaryColor: Pe,
31667
+ onVoice: zt,
31668
+ onText: Bt,
31669
+ onClose: Lt,
31670
+ isMobile: Et,
31671
+ isClosing: St
31734
31672
  }),
31735
- rt === "voice_mode" && /* @__PURE__ */ g(Ik, {
31736
- orbColors: Pe,
31737
- onEnterChat: Vt,
31738
- onEndChat: Ht,
31739
- agentId: Je,
31740
- siteId: Ye,
31741
- apiBaseUrl: Xe,
31742
- chatId: r,
31743
- historyRef: ae,
31744
- onMessageSync: oe
31673
+ O === "voice_mode" && /* @__PURE__ */ g(Ik, {
31674
+ orbColors: Me,
31675
+ onEnterChat: Bt,
31676
+ onEndChat: Vt,
31677
+ agentId: qe,
31678
+ siteId: Je,
31679
+ apiBaseUrl: Ye,
31680
+ historyRef: ie,
31681
+ onMessageSync: ae
31745
31682
  }, "voice"),
31746
- rt === "call_screen" && /* @__PURE__ */ g(dO, {
31747
- incomingCall: te,
31748
- activeCallId: w,
31749
- callConnectionState: T,
31750
- callDurationSeconds: dt,
31751
- isCallMuted: re,
31752
- agentName: Ze,
31753
- agentHeadshot: Qe,
31754
- fallbackAgentName: Le,
31755
- acceptCall: he,
31756
- rejectCall: ge,
31757
- endWebRTCCall: _e,
31758
- toggleCallMute: ve,
31759
- formatCallDuration: Ft,
31760
- onMinimize: Mt,
31761
- primaryColor: Fe,
31762
- orbColors: Pe,
31763
- chatHistory: i
31683
+ O === "call_screen" && /* @__PURE__ */ g(dO, {
31684
+ incomingCall: w,
31685
+ activeCallId: T,
31686
+ callConnectionState: ee,
31687
+ callDurationSeconds: ut,
31688
+ isCallMuted: ne,
31689
+ agentName: Xe,
31690
+ agentHeadshot: Ze,
31691
+ fallbackAgentName: Ie,
31692
+ acceptCall: me,
31693
+ rejectCall: he,
31694
+ endWebRTCCall: ge,
31695
+ toggleCallMute: _e,
31696
+ formatCallDuration: Pt,
31697
+ onMinimize: jt,
31698
+ primaryColor: Pe,
31699
+ orbColors: Me,
31700
+ chatHistory: r
31764
31701
  }),
31765
- rt === "text_chat" && /* @__PURE__ */ g(zk, {
31766
- isClosing: Ct,
31767
- copy: qe,
31768
- orbColors: Pe,
31769
- primaryColor: Fe,
31770
- chatBgGradient: Re,
31771
- logo: ze,
31772
- quickChatOptions: Ue,
31773
- onQuickChatSelect: It,
31774
- isMobile: Dt,
31775
- chatHistory: i,
31776
- isAiTyping: b,
31777
- isAgentTyping: y,
31778
- activeScreen: s,
31779
- agentName: Ze,
31780
- agentHeadshot: Qe,
31781
- fallbackAgentName: Le,
31782
- input: at,
31783
- setInput: O,
31784
- onSubmit: Pt,
31702
+ O === "text_chat" && /* @__PURE__ */ g(zk, {
31703
+ isClosing: St,
31704
+ copy: Ke,
31705
+ orbColors: Me,
31706
+ primaryColor: Pe,
31707
+ chatBgGradient: Le,
31708
+ logo: Re,
31709
+ quickChatOptions: He,
31710
+ onQuickChatSelect: Ft,
31711
+ isMobile: Et,
31712
+ chatHistory: r,
31713
+ isAiTyping: y,
31714
+ isAgentTyping: v,
31715
+ activeScreen: a,
31716
+ agentName: Xe,
31717
+ agentHeadshot: Ze,
31718
+ fallbackAgentName: Ie,
31719
+ input: rt,
31720
+ setInput: it,
31721
+ onSubmit: Nt,
31785
31722
  isConversationEnded: C,
31786
- isLoading: x,
31787
- isRateLimited: S,
31788
- rateLimitMessage: ee,
31789
- selectedFile: ht,
31790
- onFileSelect: At,
31791
- onRemoveSelectedFile: kt,
31792
- attachmentError: _t,
31793
- isUploadingAttachment: yt,
31794
- requiresEmail: tt,
31795
- emailInput: ct,
31796
- setEmailInput: lt,
31797
- emailError: k,
31798
- replyContext: ot,
31799
- setReplyContext: st,
31800
- webRTCError: E,
31801
- micError: pt,
31802
- setMicError: mt,
31803
- dismissCallError: ye,
31804
- activeCallId: w,
31805
- isCallMuted: re,
31806
- toggleCallMute: ve,
31807
- endWebRTCCall: _e,
31808
- formatCallDuration: Ft,
31809
- callDurationSeconds: dt,
31810
- onCollapse: Rt,
31811
- onStartVoice: Bt,
31812
- onNewChat: me,
31813
- onEndConversation: de,
31814
- onMinimize: Mt,
31815
- onExpand: jt,
31816
- isCallMinimized: xt && !!w,
31817
- showPoweredBy: We,
31818
- getVisitorChatHistory: Ce,
31819
- getVisitorChatThread: we,
31820
- resumeChat: Te,
31821
- isSessionRestoring: Ee
31723
+ isLoading: b,
31724
+ isRateLimited: x,
31725
+ rateLimitMessage: S,
31726
+ selectedFile: mt,
31727
+ onFileSelect: kt,
31728
+ onRemoveSelectedFile: Ot,
31729
+ attachmentError: gt,
31730
+ isUploadingAttachment: vt,
31731
+ requiresEmail: et,
31732
+ emailInput: st,
31733
+ setEmailInput: ct,
31734
+ emailError: lt,
31735
+ replyContext: at,
31736
+ setReplyContext: ot,
31737
+ webRTCError: re,
31738
+ micError: ft,
31739
+ setMicError: pt,
31740
+ dismissCallError: ve,
31741
+ activeCallId: T,
31742
+ isCallMuted: ne,
31743
+ toggleCallMute: _e,
31744
+ endWebRTCCall: ge,
31745
+ formatCallDuration: Pt,
31746
+ callDurationSeconds: ut,
31747
+ onCollapse: Lt,
31748
+ onStartVoice: zt,
31749
+ onNewChat: de,
31750
+ onEndConversation: ue,
31751
+ onMinimize: jt,
31752
+ onExpand: At,
31753
+ isCallMinimized: bt && !!T,
31754
+ showPoweredBy: Ue,
31755
+ getVisitorChatHistory: Se,
31756
+ getVisitorChatThread: Ce,
31757
+ resumeChat: we,
31758
+ isSessionRestoring: Te
31822
31759
  }),
31823
31760
  /* @__PURE__ */ g("style", { children: "\n /* Force any SVG (or img) inside LogoSlot to fill the container height\n regardless of whether the component forwards its style prop. */\n .fe-logo-slot svg,\n .fe-logo-slot img { height: 100%; width: auto; display: block; }\n\n @keyframes fe-orb-breathe { 0%,100%{transform:scale(1)} 50%{transform:scale(1.04)} }\n @keyframes fe-orb-breathe-subtle { 0%,100%{transform:scale(1)} 50%{transform:scale(1.025)} }\n @keyframes fe-orb-pulse { 0%{transform:scale(1);opacity:.65} 50%{transform:scale(1.28);opacity:.1} 100%{transform:scale(1);opacity:.65} }\n @keyframes fe-orb-glow { from{opacity:.35} to{opacity:.75} }\n @keyframes fe-orb-fade-in { from{opacity:0} to{opacity:1} }\n @keyframes fe-orb-slide-up { from{opacity:0;transform:translateY(18px)} to{opacity:1;transform:translateY(0)} }\n @keyframes fe-orb-slide-down { from{opacity:1;transform:translateY(0)} to{opacity:0;transform:translateY(24px)} }\n @keyframes fe-orb-bar-0 { from{height:6px} to{height:18px} }\n @keyframes fe-orb-bar-1 { from{height:10px} to{height:22px} }\n @keyframes fe-orb-bar-2 { from{height:14px} to{height:26px} }\n @keyframes fe-orb-bar-3 { from{height:8px} to{height:20px} }\n @keyframes fe-orb-bar-4 { from{height:6px} to{height:16px} }\n @keyframes fe-dot-bounce { 0%,80%,100%{transform:translateY(0);opacity:.5} 40%{transform:translateY(-5px);opacity:1} }\n " })
31824
31761
  ]