@flowengage/react-chatbot 4.0.12 → 4.0.14

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.
@@ -481,7 +481,7 @@ var nt = (e) => {
481
481
  let l = new ArrayBuffer(t), u = new Uint8Array(l);
482
482
  for (r = 0; r < n; r += 4) a = tt[e.charCodeAt(r)], o = tt[e.charCodeAt(r + 1)], s = tt[e.charCodeAt(r + 2)], c = tt[e.charCodeAt(r + 3)], u[i++] = a << 2 | o >> 4, u[i++] = (o & 15) << 4 | s >> 2, u[i++] = (s & 3) << 6 | c & 63;
483
483
  return l;
484
- }, k = typeof ArrayBuffer == "function", A = (e, t) => {
484
+ }, k = typeof ArrayBuffer == "function", rt = (e, t) => {
485
485
  if (typeof e != "string") return {
486
486
  type: "message",
487
487
  data: it(e, t)
@@ -489,12 +489,12 @@ var nt = (e) => {
489
489
  let n = e.charAt(0);
490
490
  return n === "b" ? {
491
491
  type: "message",
492
- data: rt(e.substring(1), t)
492
+ data: A(e.substring(1), t)
493
493
  } : We[n] ? e.length > 1 ? {
494
494
  type: We[n],
495
495
  data: e.substring(1)
496
496
  } : { type: We[n] } : Ge;
497
- }, rt = (e, t) => k ? it(nt(e), t) : {
497
+ }, A = (e, t) => k ? it(nt(e), t) : {
498
498
  base64: !0,
499
499
  data: e
500
500
  }, it = (e, t) => {
@@ -512,7 +512,7 @@ var nt = (e) => {
512
512
  }, st = (e, t) => {
513
513
  let n = e.split(at), r = [];
514
514
  for (let e = 0; e < n.length; e++) {
515
- let i = A(n[e], t);
515
+ let i = rt(n[e], t);
516
516
  if (r.push(i), i.type === "error") break;
517
517
  }
518
518
  return r;
@@ -569,7 +569,7 @@ function ft(e, t) {
569
569
  } else {
570
570
  if (ut(n) < i) break;
571
571
  let e = dt(n, i);
572
- s.enqueue(A(a ? e : lt.decode(e), t)), r = 0;
572
+ s.enqueue(rt(a ? e : lt.decode(e), t)), r = 0;
573
573
  }
574
574
  if (i === 0 || i > e) {
575
575
  s.enqueue(Ge);
@@ -682,7 +682,7 @@ var Dt = class extends Error {
682
682
  this.readyState = "open", this.writable = !0, super.emitReserved("open");
683
683
  }
684
684
  onData(e) {
685
- let t = A(e, this.socket.binaryType);
685
+ let t = rt(e, this.socket.binaryType);
686
686
  this.onPacket(t);
687
687
  }
688
688
  onPacket(e) {
@@ -2813,7 +2813,7 @@ function jr({ siteId: e, config: t, children: n, language: r = "en" }) {
2813
2813
  let i = f(() => e ? {
2814
2814
  ...t || {},
2815
2815
  siteId: e
2816
- } : t || null, [e, t]), [a, s] = m(0), [l, u] = m("booting"), [d, h] = m(null), [_, v] = m(null), [y, b] = m(""), [x, S] = m([]), [C, w] = m(ve().isOpen), [T, te] = m(ve().activeScreen), [ne, re] = m(ve().isHumanHandled), [E, D] = m(ve().agentName), [se, de] = m(ve().agentHeadshot), [fe, pe] = m(() => be(i?.siteId)), [me, Se] = m(!1), [Ce, we] = m(!1), [Ee, De] = m("idle"), [Oe, ke] = m(!1), [Ae, je] = m(!1), [Me, Ne] = m(""), [Fe, Ie] = m(!1), [Le, ze] = m(!1), [O, Ue] = m(null), [We, Ge] = m(null), [Ke, qe] = m("idle"), [Je, Ye] = m(null), [Xe, Ze] = m(!1), [Qe, $e] = m(""), [et, tt] = m(!1), nt = p(null), k = p(null), A = p(""), rt = p(!1), it = p(null), at = p(null), ot = p(null), st = p(null), ct = p(null), lt = p(null), ut = p([]), dt = p(null), ft = p(null), j = 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(!1), wt = p(i), Tt = p({
2816
+ } : t || null, [e, t]), [a, s] = m(0), [l, u] = m("booting"), [d, h] = m(null), [_, v] = m(null), [y, b] = m(""), [x, S] = m([]), [C, w] = m(ve().isOpen), [T, te] = m(ve().activeScreen), [ne, re] = m(ve().isHumanHandled), [E, D] = m(ve().agentName), [se, de] = m(ve().agentHeadshot), [fe, pe] = m(() => be(i?.siteId)), [me, Se] = m(!1), [Ce, we] = m(!1), [Ee, De] = m("idle"), [Oe, ke] = m(!1), [Ae, je] = m(!1), [Me, Ne] = m(""), [Fe, Ie] = m(!1), [Le, ze] = m(!1), [O, Ue] = m(null), [We, Ge] = m(null), [Ke, qe] = m("idle"), [Je, Ye] = m(null), [Xe, Ze] = m(!1), [Qe, $e] = m(""), [et, tt] = m(!1), nt = p(null), k = p(null), rt = p(""), A = p(!1), it = p(null), at = p(null), ot = p(null), st = p(null), ct = p(null), lt = p(null), ut = p([]), dt = p(null), ft = p(null), j = 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(!1), wt = p(i), Tt = p({
2817
2817
  notifyRouteChange: () => {},
2818
2818
  cleanup: () => {}
2819
2819
  }), Et = o((e = {}) => {
@@ -2878,7 +2878,7 @@ function jr({ siteId: e, config: t, children: n, language: r = "en" }) {
2878
2878
  if (!(!t?.connected || !n || pt.current)) {
2879
2879
  pt.current = !0, t.emit("call:connected", {
2880
2880
  callId: n,
2881
- chatId: A.current,
2881
+ chatId: rt.current,
2882
2882
  connectedAt: e
2883
2883
  });
2884
2884
  try {
@@ -2921,7 +2921,7 @@ function jr({ siteId: e, config: t, children: n, language: r = "en" }) {
2921
2921
  if (!t || !n?.connected || !r || !e.callId) {
2922
2922
  console.log("[FlowEngageProvider] deferring remote offer until peer/socket ready", {
2923
2923
  callId: e.callId,
2924
- chatId: A.current,
2924
+ chatId: rt.current,
2925
2925
  hasPeerConnection: !!t,
2926
2926
  socketConnected: !!n?.connected,
2927
2927
  hasOffer: !!r
@@ -2934,7 +2934,7 @@ function jr({ siteId: e, config: t, children: n, language: r = "en" }) {
2934
2934
  })), ut.current.length > 0) {
2935
2935
  console.log("[FlowEngageProvider] flushing queued agent ICE candidates after remote offer", {
2936
2936
  callId: e.callId,
2937
- chatId: A.current,
2937
+ chatId: rt.current,
2938
2938
  queuedCount: ut.current.length
2939
2939
  });
2940
2940
  for (let e of ut.current) await t.addIceCandidate(new RTCIceCandidate(e));
@@ -2944,7 +2944,7 @@ function jr({ siteId: e, config: t, children: n, language: r = "en" }) {
2944
2944
  await t.setLocalDescription(i), n.emit("call:answer", {
2945
2945
  callId: e.callId,
2946
2946
  sdpAnswer: i.sdp,
2947
- chatId: A.current
2947
+ chatId: rt.current
2948
2948
  });
2949
2949
  };
2950
2950
  c(() => {
@@ -2970,8 +2970,8 @@ function jr({ siteId: e, config: t, children: n, language: r = "en" }) {
2970
2970
  if (!e) return;
2971
2971
  let a = t.siteId, o = he(a), s = Te(a), c = "";
2972
2972
  try {
2973
- let e = rt.current, r = it.current;
2974
- if (rt.current = !1, it.current = null, c = (await Be({
2973
+ let e = A.current, r = it.current;
2974
+ if (A.current = !1, it.current = null, c = (await Be({
2975
2975
  apiBaseUrl: t.apiBaseUrl,
2976
2976
  userId: n.userId,
2977
2977
  siteId: a,
@@ -2984,7 +2984,7 @@ function jr({ siteId: e, config: t, children: n, language: r = "en" }) {
2984
2984
  } catch (e) {
2985
2985
  console.warn("[FlowEngageProvider] resolve-session failed, reusing persisted or ephemeral chat id", e?.message || e), c = o || ue(), _e(a, c);
2986
2986
  }
2987
- A.current = c;
2987
+ rt.current = c;
2988
2988
  let l = He({
2989
2989
  apiBaseUrl: t.apiBaseUrl,
2990
2990
  userId: n.userId,
@@ -3128,7 +3128,7 @@ function jr({ siteId: e, config: t, children: n, language: r = "en" }) {
3128
3128
  if (!ot.current || !ot.current.remoteDescription) {
3129
3129
  console.log("[FlowEngageProvider] queueing agent ICE candidate until peer/remote description is ready", {
3130
3130
  callId: e.callId,
3131
- chatId: e.chatId || A.current,
3131
+ chatId: e.chatId || rt.current,
3132
3132
  queueSize: ut.current.length + 1
3133
3133
  }), ut.current.push(t);
3134
3134
  return;
@@ -3203,7 +3203,7 @@ function jr({ siteId: e, config: t, children: n, language: r = "en" }) {
3203
3203
  a
3204
3204
  ]), c(() => () => {
3205
3205
  if (Fe && !St.current && xt.current.length > 0) {
3206
- let e = A.current, t = xt.current, n = k.current;
3206
+ let e = rt.current, t = xt.current, n = k.current;
3207
3207
  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);
3208
3208
  }
3209
3209
  }, [Fe, _]), c(() => {
@@ -3375,10 +3375,10 @@ function jr({ siteId: e, config: t, children: n, language: r = "en" }) {
3375
3375
  }
3376
3376
  }, Ht = async (e) => {
3377
3377
  let t = At(e);
3378
- if (!t || !k.current || !A.current) return t;
3378
+ if (!t || !k.current || !rt.current) return t;
3379
3379
  try {
3380
3380
  await k.current.trackVisitor({
3381
- chatId: A.current,
3381
+ chatId: rt.current,
3382
3382
  currentPagePath: typeof window < "u" && window.location.pathname || "/",
3383
3383
  email: t
3384
3384
  });
@@ -3538,7 +3538,7 @@ function jr({ siteId: e, config: t, children: n, language: r = "en" }) {
3538
3538
  Dt
3539
3539
  ]), c(() => {
3540
3540
  let e = () => {
3541
- let e = A.current, t = k.current;
3541
+ let e = rt.current, t = k.current;
3542
3542
  if (!t || !e) return;
3543
3543
  if (Ct.current && xt.current.length > 0) {
3544
3544
  let e = wt.current?.siteId;
@@ -3557,9 +3557,9 @@ function jr({ siteId: e, config: t, children: n, language: r = "en" }) {
3557
3557
  }, []);
3558
3558
  let Zt = o(() => {
3559
3559
  let e = i?.siteId;
3560
- ge(e), rt.current = !0, it.current = null, nt.current?.disconnect(), S([]), b(""), A.current = "", ze(!1), re(!1), D(null), de(null), tt(!0), s((e) => e + 1);
3560
+ ge(e), A.current = !0, it.current = null, nt.current?.disconnect(), S([]), b(""), rt.current = "", ze(!1), re(!1), D(null), de(null), tt(!0), s((e) => e + 1);
3561
3561
  }, [i?.siteId]), Qt = o((e) => {
3562
- i?.siteId, rt.current = !1, it.current = e, nt.current?.disconnect(), S([]), b(""), A.current = "", ze(!1), re(!1), D(null), de(null), tt(!0), s((e) => e + 1);
3562
+ i?.siteId, A.current = !1, it.current = e, nt.current?.disconnect(), S([]), b(""), rt.current = "", ze(!1), re(!1), D(null), de(null), tt(!0), s((e) => e + 1);
3563
3563
  }, [i?.siteId]), $t = f(() => ({
3564
3564
  status: l,
3565
3565
  error: d,
@@ -30126,39 +30126,55 @@ function qk({ copy: e, orbColors: t, primaryColor: n, onVoice: r, onText: i, onC
30126
30126
  ]
30127
30127
  });
30128
30128
  }
30129
- function Jk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i, siteId: a, apiBaseUrl: s, historyRef: l, onMessageSync: u }) {
30130
- let [d, f] = m("idle"), [h, v] = m(!1), [y, b] = m(!1), x = p(null), S = p(""), C = p(async () => {}), w = p(!1), T = p(!1), ee = p(!1), te = p(!1), ne = p("minimized"), re = p(null), E = o((e = "minimized") => {
30131
- ne.current = e, te.current = !0, queueMicrotask(() => {
30132
- w.current || (w.current = !0, C.current?.());
30129
+ function Jk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i, siteId: a, apiBaseUrl: s, chatId: l, historyRef: u, onMessageSync: d }) {
30130
+ let [f, h] = m("idle"), [v, y] = m(!1), [b, x] = m(!1), S = p(null), C = p(""), w = p(async () => {}), T = p(!1), ee = p(!1), te = p(!1), ne = p(!1), re = p("minimized"), E = p(null), ie = p(null), ae = p(null), oe = o((e = "minimized") => {
30131
+ re.current = e, ne.current = !0, queueMicrotask(() => {
30132
+ T.current || (T.current = !0, w.current?.());
30133
30133
  });
30134
- }, [l]), ie = o(async (e) => {
30135
- te.current = !0;
30134
+ }, [u]), D = o(async (e) => {
30135
+ ne.current = !0;
30136
30136
  try {
30137
- await x.current?.endSession?.();
30137
+ await S.current?.endSession?.();
30138
30138
  } catch {}
30139
- if (x.current = null, f("idle"), v(!1), w.current = !1, Cr(), a) try {
30139
+ let t = E.current, n = ie.current;
30140
+ if (t && l && s) {
30141
+ let e = n ? Math.round((Date.now() - n) / 1e3) : 0;
30142
+ fetch(`${s}/api/voice/save-chat-recording`, {
30143
+ method: "POST",
30144
+ headers: { "Content-Type": "application/json" },
30145
+ body: JSON.stringify({
30146
+ chatId: l,
30147
+ elevenLabsConversationId: t,
30148
+ duration: e,
30149
+ siteId: a
30150
+ })
30151
+ }).catch((e) => console.warn("[FlowEngage] save-chat-recording failed:", e.message));
30152
+ }
30153
+ if (E.current = null, ie.current = null, S.current = null, h("idle"), y(!1), T.current = !1, Cr(), a) try {
30140
30154
  Me(a);
30141
30155
  } catch {}
30142
- typeof u == "function" && await u(l.current), e?.();
30156
+ typeof d == "function" && await d(u.current), e?.();
30143
30157
  }, [
30144
- l,
30145
30158
  u,
30146
- a
30159
+ d,
30160
+ a,
30161
+ l,
30162
+ s
30147
30163
  ]);
30148
- return C.current = () => ie(ne.current === "chat" ? t : n), c(() => {
30149
- T.current = h;
30150
- }, [h]), c(() => {
30164
+ return w.current = () => D(re.current === "chat" ? t : n), c(() => {
30165
+ ee.current = v;
30166
+ }, [v]), c(() => {
30151
30167
  let e = !1, n = null;
30152
30168
  return (async () => {
30153
30169
  if (!r) {
30154
- f("error");
30170
+ h("error");
30155
30171
  return;
30156
30172
  }
30157
30173
  try {
30158
30174
  if ((await navigator.mediaDevices.getUserMedia({ audio: !0 })).getTracks().forEach((e) => e.stop()), e) return;
30159
- l.current = [], S.current = "", w.current = !1, ee.current = !1, te.current = !1, ne.current = "minimized", Sr({ onBeforeNavigate: () => {
30160
- if (a && l.current.length > 0) try {
30161
- let e = DO(l.current);
30175
+ u.current = [], C.current = "", T.current = !1, te.current = !1, ne.current = !1, re.current = "minimized", Sr({ onBeforeNavigate: () => {
30176
+ if (a && u.current.length > 0) try {
30177
+ let e = DO(u.current);
30162
30178
  e && Ae(a, e);
30163
30179
  } catch {}
30164
30180
  if (a && typeof window < "u") try {
@@ -30169,120 +30185,123 @@ function Jk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30169
30185
  let t = Rk(Lk({
30170
30186
  siteId: a || null,
30171
30187
  apiBaseUrl: s || null,
30172
- getLastUserVoiceText: () => S.current,
30188
+ getLastUserVoiceText: () => C.current,
30173
30189
  requestEndSession: () => {
30174
- E();
30190
+ oe();
30175
30191
  }
30176
- })), i = a ? je(a) : null, o = !!i?.transcript, c = typeof window < "u" ? window.location.pathname : "/", u = typeof document < "u" ? document.title : "", d = c === "/" || c === "", p = null;
30192
+ })), i = a ? je(a) : null, o = !!i?.transcript, c = typeof window < "u" ? window.location.pathname : "/", l = typeof document < "u" ? document.title : "", d = c === "/" || c === "", f = null;
30177
30193
  try {
30178
30194
  let e = await fetch(`${s}/api/voice/signed-url?siteId=${encodeURIComponent(a || "")}`, {
30179
30195
  method: "GET",
30180
30196
  headers: { "Content-Type": "application/json" }
30181
30197
  });
30182
- e.ok ? (p = (await e.json()).signedUrl || null, p && console.log("[FlowEngage] ✅ Using signed ElevenLabs URL")) : console.warn("[FlowEngage] ⚠️ Signed URL fetch failed, falling back to agentId");
30198
+ e.ok ? (f = (await e.json()).signedUrl || null, f && console.log("[FlowEngage] ✅ Using signed ElevenLabs URL")) : console.warn("[FlowEngage] ⚠️ Signed URL fetch failed, falling back to agentId");
30183
30199
  } catch (e) {
30184
30200
  console.warn("[FlowEngage] ⚠️ Signed URL fetch error:", e.message);
30185
30201
  }
30186
- let m = {
30202
+ let p = {
30187
30203
  clientTools: t,
30188
30204
  connectionType: "websocket",
30189
- ...p ? { signedUrl: p } : { agentId: r }
30205
+ ...f ? { signedUrl: f } : { agentId: r }
30190
30206
  };
30191
- if (p) {
30192
- if (o) m.overrides = { agent: { firstMessage: "" } };
30207
+ if (f) {
30208
+ if (o) p.overrides = { agent: { firstMessage: "" } };
30193
30209
  else if (!d) {
30194
30210
  let e = (c.split("/").filter(Boolean).pop() || "").replace(/[-_]/g, " ").replace(/\b\w/g, (e) => e.toUpperCase()), t = "";
30195
- u && u.includes("|") && (t = u.split("|").map((e) => e.trim()).filter(Boolean).reduce((e, t) => e.length <= t.length ? e : t));
30211
+ l && l.includes("|") && (t = l.split("|").map((e) => e.trim()).filter(Boolean).reduce((e, t) => e.length <= t.length ? e : t));
30196
30212
  let n = t || e || "this page";
30197
- m.overrides = { agent: { firstMessage: `Hi! I see you are currently on the ${n} page. Are you looking for something specific here?` } }, console.log(`[FlowEngage] 🏠 Page-context override: "${n}" for ${c}`);
30213
+ p.overrides = { agent: { firstMessage: `Hi! I see you are currently on the ${n} page. Are you looking for something specific here?` } }, console.log(`[FlowEngage] 🏠 Page-context override: "${n}" for ${c}`);
30198
30214
  }
30199
- } else o && (m.overrides = { agent: { firstMessage: "" } });
30200
- let h = await jD.startSession({
30201
- ...m,
30215
+ } else o && (p.overrides = { agent: { firstMessage: "" } });
30216
+ let m = await jD.startSession({
30217
+ ...p,
30218
+ onConnect: ({ conversationId: e }) => {
30219
+ E.current = e, ie.current = Date.now(), console.log("[FlowEngage] 🎙️ AI chat session connected:", e);
30220
+ },
30202
30221
  onUnhandledClientToolCall: (e) => console.error("[FlowEngage] Unhandled tool:", e?.tool_name),
30203
30222
  onModeChange: ({ mode: t }) => {
30204
- e || f(t === "speaking" ? "speaking" : "listening");
30223
+ e || h(t === "speaking" ? "speaking" : "listening");
30205
30224
  },
30206
30225
  onMessage: (t) => {
30207
30226
  if (e) return;
30208
30227
  let n = t.role === "user" ? "user" : "bot", r = t.message || t.text || t.content || "";
30209
30228
  if (r) {
30210
- if (n === "user" && (S.current = r), l.current = [...l.current, {
30229
+ if (n === "user" && (C.current = r), u.current = [...u.current, {
30211
30230
  sender: n,
30212
30231
  message: r,
30213
30232
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
30214
30233
  }], a) try {
30215
- let e = DO(l.current);
30234
+ let e = DO(u.current);
30216
30235
  e && Ae(a, e);
30217
30236
  } catch {}
30218
- Wk(n, r) && E("minimized");
30237
+ Wk(n, r) && oe("minimized");
30219
30238
  }
30220
30239
  },
30221
30240
  onError: (t) => {
30222
- if (!e && !te.current && !ee.current && !Ie()) {
30223
- ee.current = !0, console.error("[FlowEngageVoiceCall] session:error", {
30241
+ if (!e && !ne.current && !te.current && !Ie()) {
30242
+ te.current = !0, console.error("[FlowEngageVoiceCall] session:error", {
30224
30243
  message: t?.message,
30225
30244
  name: t?.name,
30226
30245
  raw: t
30227
30246
  });
30228
30247
  try {
30229
- x.current?.setMicMuted?.(!0);
30248
+ S.current?.setMicMuted?.(!0);
30230
30249
  } catch {}
30231
- v(!0), f("error"), E("chat");
30250
+ y(!0), h("error"), oe("chat");
30232
30251
  }
30233
30252
  },
30234
30253
  onDisconnect: (t) => {
30235
- if (e || te.current || ee.current || Ie()) return;
30236
- let n = l.current?.length || 0;
30254
+ if (e || ne.current || te.current || Ie()) return;
30255
+ let n = u.current?.length || 0;
30237
30256
  console.warn("[FlowEngageVoiceCall] session:disconnected", {
30238
30257
  historyCount: n,
30239
30258
  reason: t?.reason,
30240
30259
  closeCode: t?.context?.code,
30241
30260
  closeReason: t?.context?.reason || t?.message,
30242
- lastUserText: S.current || "",
30243
- wasMuted: T.current
30244
- }), ee.current = !0;
30261
+ lastUserText: C.current || "",
30262
+ wasMuted: ee.current
30263
+ }), te.current = !0;
30245
30264
  try {
30246
- x.current?.setMicMuted?.(!0);
30265
+ S.current?.setMicMuted?.(!0);
30247
30266
  } catch {}
30248
- v(!0), E("chat");
30267
+ y(!0), oe("chat");
30249
30268
  }
30250
30269
  });
30251
30270
  if (e) {
30252
- h.endSession().catch(() => {});
30271
+ m.endSession().catch(() => {});
30253
30272
  return;
30254
30273
  }
30255
- n = h, x.current = h, f("listening");
30274
+ n = m, S.current = m, h("listening");
30256
30275
  try {
30257
30276
  let e = typeof window < "u" ? window.location.href : "", n = "[]";
30258
30277
  try {
30259
30278
  n = await t.list_page_forms();
30260
30279
  } catch {}
30261
30280
  let r = o ? `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${i.transcript}\n\n` : "";
30262
- h.sendContextualUpdate(`${r}Page: ${e}. SiteId: ${a || "unknown"}. Forms: ${n}. Voice: call end_voice_session or say you are ending the session to stop.`);
30281
+ m.sendContextualUpdate(`${r}Page: ${e}. SiteId: ${a || "unknown"}. Forms: ${n}. Voice: call end_voice_session or say you are ending the session to stop.`);
30263
30282
  } catch {}
30264
30283
  } catch (n) {
30265
- e || (console.error("[FlowEngage] startSession failed", n), f("error"), ne.current = "chat", window.setTimeout(() => {
30284
+ e || (console.error("[FlowEngage] startSession failed", n), h("error"), re.current = "chat", window.setTimeout(() => {
30266
30285
  e || t?.();
30267
30286
  }, 0));
30268
30287
  }
30269
30288
  })(), () => {
30270
- e = !0, te.current = !0, Cr(), (n || x.current)?.endSession?.().catch(() => {});
30289
+ e = !0, ne.current = !0, Cr(), (n || S.current)?.endSession?.().catch(() => {});
30271
30290
  };
30272
30291
  }, [
30273
30292
  r,
30274
30293
  a,
30275
30294
  s,
30276
- E
30295
+ oe
30277
30296
  ]), c(() => {
30278
- if (!y) return;
30297
+ if (!b) return;
30279
30298
  let e = (e) => {
30280
30299
  let t = e.composedPath?.()?.[0] || e.target;
30281
- re.current && !re.current.contains(t) && b(!1);
30300
+ ae.current && !ae.current.contains(t) && x(!1);
30282
30301
  };
30283
30302
  return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
30284
- }, [y]), /* @__PURE__ */ _("div", {
30285
- ref: re,
30303
+ }, [b]), /* @__PURE__ */ _("div", {
30304
+ ref: ae,
30286
30305
  style: {
30287
30306
  position: "relative",
30288
30307
  display: "flex",
@@ -30294,7 +30313,7 @@ function Jk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30294
30313
  children: [
30295
30314
  /* @__PURE__ */ _("div", {
30296
30315
  style: { position: "relative" },
30297
- children: [d === "listening" && /* @__PURE__ */ g("span", {
30316
+ children: [f === "listening" && /* @__PURE__ */ g("span", {
30298
30317
  style: {
30299
30318
  position: "absolute",
30300
30319
  right: "100%",
@@ -30311,12 +30330,12 @@ function Jk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30311
30330
  children: "Listening..."
30312
30331
  }), /* @__PURE__ */ g(Gk, {
30313
30332
  size: 72,
30314
- voiceState: d,
30315
- isMuted: h,
30333
+ voiceState: f,
30334
+ isMuted: v,
30316
30335
  orbColors: e
30317
30336
  })]
30318
30337
  }),
30319
- d === "error" && /* @__PURE__ */ g("span", {
30338
+ f === "error" && /* @__PURE__ */ g("span", {
30320
30339
  style: {
30321
30340
  color: "#f87171",
30322
30341
  fontSize: "13px",
@@ -30332,28 +30351,28 @@ function Jk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30332
30351
  },
30333
30352
  children: [/* @__PURE__ */ g("button", {
30334
30353
  onClick: async () => {
30335
- if (x.current) try {
30336
- h ? (await x.current.setMicMuted?.(!1), v(!1)) : (await x.current.setMicMuted?.(!0), v(!0));
30354
+ if (S.current) try {
30355
+ v ? (await S.current.setMicMuted?.(!1), y(!1)) : (await S.current.setMicMuted?.(!0), y(!0));
30337
30356
  } catch {}
30338
30357
  },
30339
- title: h ? "Unmute" : "Mute",
30358
+ title: v ? "Unmute" : "Mute",
30340
30359
  style: {
30341
30360
  width: "24px",
30342
30361
  height: "24px",
30343
30362
  borderRadius: "50%",
30344
- background: h ? "#7f1d1d" : "#1f2937",
30345
- border: h ? "1.5px solid #ef4444" : "1.5px solid #4b5563",
30363
+ background: v ? "#7f1d1d" : "#1f2937",
30364
+ border: v ? "1.5px solid #ef4444" : "1.5px solid #4b5563",
30346
30365
  display: "flex",
30347
30366
  alignItems: "center",
30348
30367
  justifyContent: "center",
30349
30368
  cursor: "pointer",
30350
- color: h ? "#f87171" : "white",
30369
+ color: v ? "#f87171" : "white",
30351
30370
  transition: "all 0.2s ease",
30352
30371
  boxShadow: "0 2px 8px rgba(0,0,0,0.4)",
30353
30372
  padding: 0,
30354
30373
  flexShrink: 0
30355
30374
  },
30356
- children: h ? /* @__PURE__ */ _("svg", {
30375
+ children: v ? /* @__PURE__ */ _("svg", {
30357
30376
  width: "16",
30358
30377
  height: "16",
30359
30378
  viewBox: "0 0 24 24",
@@ -30389,7 +30408,7 @@ function Jk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30389
30408
  color: "currentColor"
30390
30409
  })
30391
30410
  }), /* @__PURE__ */ g("button", {
30392
- onClick: () => b((e) => !e),
30411
+ onClick: () => x((e) => !e),
30393
30412
  style: {
30394
30413
  width: "24px",
30395
30414
  height: "24px",
@@ -30412,7 +30431,7 @@ function Jk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30412
30431
  })
30413
30432
  })]
30414
30433
  }),
30415
- y && /* @__PURE__ */ _("div", {
30434
+ b && /* @__PURE__ */ _("div", {
30416
30435
  style: {
30417
30436
  position: "absolute",
30418
30437
  bottom: 0,
@@ -30430,7 +30449,7 @@ function Jk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30430
30449
  children: [
30431
30450
  /* @__PURE__ */ _("button", {
30432
30451
  onClick: () => {
30433
- b(!1), ne.current = "chat", ie(t);
30452
+ x(!1), re.current = "chat", D(t);
30434
30453
  },
30435
30454
  style: {
30436
30455
  display: "flex",
@@ -30459,7 +30478,7 @@ function Jk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30459
30478
  }),
30460
30479
  /* @__PURE__ */ _("button", {
30461
30480
  onClick: () => {
30462
- b(!1), ne.current = "minimized", ie(n);
30481
+ x(!1), re.current = "minimized", D(n);
30463
30482
  },
30464
30483
  style: {
30465
30484
  display: "flex",
@@ -30487,7 +30506,7 @@ function Jk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30487
30506
  children: [/* @__PURE__ */ g(HD, {}), "End Conversation"]
30488
30507
  }),
30489
30508
  /* @__PURE__ */ g("button", {
30490
- onClick: () => b(!1),
30509
+ onClick: () => x(!1),
30491
30510
  style: {
30492
30511
  position: "absolute",
30493
30512
  bottom: "8px",
@@ -31360,230 +31379,230 @@ function Zk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
31360
31379
  });
31361
31380
  }
31362
31381
  function Qk() {
31363
- 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 } = Nn();
31382
+ let { status: e, runtimeConfig: t, resolvedConfig: n, chatHistory: r, isOpen: i, activeScreen: a, isHumanHandled: s, agentName: l, agentHeadshot: u, visitorEmail: h, isAgentTyping: v, isAiTyping: y, isLoading: b, isRateLimited: x, rateLimitMessage: S, isConversationEnded: C, incomingCall: w, activeCallId: T, callConnectionState: ee, callConnectedAt: te, isCallMuted: ne, webRTCError: re, language: E, chatId: ie, historyRef: ae, onMessageSync: oe, sendMessage: D, uploadChatFile: se, openWidget: ce, captureVisitorEmail: le, setVoiceMode: ue, endConversation: de, startNewChat: me, acceptCall: he, rejectCall: ge, endWebRTCCall: _e, toggleCallMute: ve, dismissCallError: ye, startTyping: be, stopTyping: xe, updateTypingDraft: Se, getVisitorChatHistory: Ce, getVisitorChatThread: we, resumeChat: Te, isSessionRestoring: Ee } = Nn();
31364
31383
  c(() => {
31365
31384
  try {
31366
31385
  or();
31367
31386
  } catch {}
31368
31387
  }, []);
31369
- let Ee = t?.widgetSettings || {}, De = n?.widgetSettings || {}, Oe = {
31370
- ...Ee.branding || {},
31371
- ...De.branding || {}
31372
- }, ke = {
31373
- ...Ee.theme || {},
31374
- ...De.theme || {}
31388
+ let De = t?.widgetSettings || {}, Oe = n?.widgetSettings || {}, ke = {
31389
+ ...De.branding || {},
31390
+ ...Oe.branding || {}
31375
31391
  }, Ae = {
31376
- ...Ee.features || {},
31377
- ...De.features || {}
31378
- }, Ne = Ae.voice !== !1, Pe = Array.isArray(ke.orbColors) && ke.orbColors.length > 0 ? ke.orbColors : null, Ie = ke.buttonColor || ke.primaryColor || Pe?.[0] || "#3B82F6", Le = ke.position || "bottom-right", Re = Oe.fallbackAgentName || "Agent", ze = Bk(Pe ?? ke.chatBgColors), O = Oe.logo || Oe.logoUrl || null, Be = E || "en", Ve = Ee.recommendations?.[Be] || [], He = (De.recommendations?.[Be] ?? Ve).filter((e) => String(e?.label ?? "").trim()).map((e, t) => ({
31392
+ ...De.theme || {},
31393
+ ...Oe.theme || {}
31394
+ }, Ne = {
31395
+ ...De.features || {},
31396
+ ...Oe.features || {}
31397
+ }, Pe = Ne.voice !== !1, Ie = Array.isArray(Ae.orbColors) && Ae.orbColors.length > 0 ? Ae.orbColors : null, Le = Ae.buttonColor || Ae.primaryColor || Ie?.[0] || "#3B82F6", Re = Ae.position || "bottom-right", ze = ke.fallbackAgentName || "Agent", O = Bk(Ie ?? Ae.chatBgColors), Be = ke.logo || ke.logoUrl || null, Ve = E || "en", He = De.recommendations?.[Ve] || [], Ue = (Oe.recommendations?.[Ve] ?? He).filter((e) => String(e?.label ?? "").trim()).map((e, t) => ({
31379
31398
  id: e.key || `qr-${t}`,
31380
31399
  label: e.label,
31381
31400
  message: e.label,
31382
31401
  text: e.label
31383
- })), Ue = Array.isArray(Oe.quickChatOptions) && Oe.quickChatOptions.length > 0 ? Oe.quickChatOptions : He, We = Oe.hideWatermark === !0 ? !1 : Oe.showPoweredBy !== !1, Ge = Oe.chatbotEnabled !== !1 && ke.chatbotEnabled !== !1, Ke = Ee.greetings?.[E] || De.greetings?.[E] || Oe.introGreeting || "Hello, I'm here to help you know more about OpenSense Labs.", qe = {
31384
- entryPrompt: Oe.entryPrompt || "Do you want to explore in a new way?",
31385
- yesLabel: Oe.yesLabel || "Yes",
31386
- laterLabel: Oe.laterLabel || "Later",
31387
- connectionTitle: Oe.connectionTitle || "How would you like to connect?",
31388
- voiceLabel: Oe.voiceLabel || "Voice",
31389
- textLabel: Oe.textLabel || "Text",
31390
- chatTitle: Oe.headerName || "Chat with FlowEngage",
31391
- introGreeting: Ke,
31392
- inputPlaceholder: Oe.inputPlaceholder || "Type your message",
31393
- analysingLabel: Oe.analysingLabel || "analysing..."
31394
- }, Je = De.elevenLabsAgentId || t?.elevenLabsAgentId || null, Ye = De.elevenLabsVoiceId || t?.elevenLabsVoiceId || null, Xe = t?.siteId || n?.siteId || null, Ze = t?.apiBaseUrl || "", Qe = f(() => l && String(l).trim() || t?.ownerName && String(t.ownerName).trim() || t?.websiteName && String(t.websiteName).trim() || "Agent", [
31402
+ })), We = Array.isArray(ke.quickChatOptions) && ke.quickChatOptions.length > 0 ? ke.quickChatOptions : Ue, Ge = ke.hideWatermark === !0 ? !1 : ke.showPoweredBy !== !1, Ke = ke.chatbotEnabled !== !1 && Ae.chatbotEnabled !== !1, qe = De.greetings?.[E] || Oe.greetings?.[E] || ke.introGreeting || "Hello, I'm here to help you know more about OpenSense Labs.", Je = {
31403
+ entryPrompt: ke.entryPrompt || "Do you want to explore in a new way?",
31404
+ yesLabel: ke.yesLabel || "Yes",
31405
+ laterLabel: ke.laterLabel || "Later",
31406
+ connectionTitle: ke.connectionTitle || "How would you like to connect?",
31407
+ voiceLabel: ke.voiceLabel || "Voice",
31408
+ textLabel: ke.textLabel || "Text",
31409
+ chatTitle: ke.headerName || "Chat with FlowEngage",
31410
+ introGreeting: qe,
31411
+ inputPlaceholder: ke.inputPlaceholder || "Type your message",
31412
+ analysingLabel: ke.analysingLabel || "analysing..."
31413
+ }, Ye = Oe.elevenLabsAgentId || t?.elevenLabsAgentId || null, Xe = Oe.elevenLabsVoiceId || t?.elevenLabsVoiceId || null, Ze = t?.siteId || n?.siteId || null, Qe = t?.apiBaseUrl || "", $e = f(() => l && String(l).trim() || t?.ownerName && String(t.ownerName).trim() || t?.websiteName && String(t.websiteName).trim() || "Agent", [
31395
31414
  l,
31396
31415
  t?.ownerName,
31397
31416
  t?.websiteName
31398
- ]), $e = u && String(u).trim() || t?.ownerProfileImageUrl && String(t.ownerProfileImageUrl).trim() || null, et = r.some((e) => e.sender === "user"), tt = f(() => {
31417
+ ]), et = u && String(u).trim() || t?.ownerProfileImageUrl && String(t.ownerProfileImageUrl).trim() || null, tt = r.some((e) => e.sender === "user"), nt = f(() => {
31399
31418
  let e = r.findIndex((e) => e.sender === "user");
31400
31419
  return e === -1 ? !1 : r.slice(e + 1).some((e) => e.sender === "bot" || e.sender === "ai" || e.sender === "agent");
31401
- }, [r]), nt = !h && et && tt, k = !!(De._dashboardLivePreview || Ee._dashboardLivePreview), [A, rt] = m(() => k ? "text_chat" : "entry_prompt"), [it, at] = m(""), [ot, st] = m(null), [ct, lt] = m(h || ""), [ut, dt] = m(""), [ft, j] = 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);
31420
+ }, [r]), k = !h && tt && nt, rt = !!(Oe._dashboardLivePreview || De._dashboardLivePreview), [A, it] = m(() => rt ? "text_chat" : "entry_prompt"), [at, ot] = m(""), [st, ct] = m(null), [lt, ut] = m(h || ""), [dt, ft] = m(""), [j, pt] = m(0), [mt, ht] = m(null), [gt, _t] = m(null), [vt, yt] = m(""), [bt, xt] = m(!1), [St, Ct] = m(!1), [wt, Tt] = m(!1), Et = p(null), Dt = p(!1);
31402
31421
  d(() => {
31403
- if (e !== "ready" || Et.current) return;
31404
- if (Et.current = !0, !Ne) {
31405
- rt("minimized_orb");
31422
+ if (e !== "ready" || Dt.current) return;
31423
+ if (Dt.current = !0, !Pe) {
31424
+ it("minimized_orb");
31406
31425
  return;
31407
31426
  }
31408
31427
  let t = !1;
31409
31428
  try {
31410
31429
  t = vr().shouldResumeVoice;
31411
31430
  } catch {}
31412
- let n = Fe(), r = Xe ? je(Xe) : null, i = n || !!r?.transcript;
31431
+ let n = Fe(), r = Ze ? je(Ze) : null, i = n || !!r?.transcript;
31413
31432
  if (t) {
31414
- se?.({ notifyChatInitiated: !0 }), le?.(!0), rt("voice_mode");
31433
+ ce?.({ notifyChatInitiated: !0 }), ue?.(!0), it("voice_mode");
31415
31434
  return;
31416
31435
  }
31417
- if (Xe) try {
31418
- Me(Xe);
31436
+ if (Ze) try {
31437
+ Me(Ze);
31419
31438
  } catch {}
31420
31439
  if (i) {
31421
- rt("minimized_orb");
31440
+ it("minimized_orb");
31422
31441
  return;
31423
31442
  }
31424
- if (fe(Xe)) {
31425
- rt("minimized_orb");
31443
+ if (fe(Ze)) {
31444
+ it("minimized_orb");
31426
31445
  return;
31427
31446
  }
31428
31447
  }, [e, r]);
31429
- let [Dt, Ot] = m(() => typeof window < "u" && window.matchMedia("(max-width: 640px)").matches);
31448
+ let [Ot, kt] = m(() => typeof window < "u" && window.matchMedia("(max-width: 640px)").matches);
31430
31449
  c(() => {
31431
- let e = window.matchMedia("(max-width: 640px)"), t = (e) => Ot(e.matches);
31450
+ let e = window.matchMedia("(max-width: 640px)"), t = (e) => kt(e.matches);
31432
31451
  return e.addEventListener("change", t), () => e.removeEventListener("change", t);
31433
31452
  }, []), c(() => {
31434
- lt(h || ""), h && dt("");
31453
+ ut(h || ""), h && ft("");
31435
31454
  }, [h]);
31436
- let kt = o(() => {
31437
- gt(null), vt("");
31438
- }, []), At = o((e) => {
31455
+ let At = o(() => {
31456
+ _t(null), yt("");
31457
+ }, []), jt = o((e) => {
31439
31458
  let t = nO(e);
31440
31459
  if (t) {
31441
- gt(null), vt(t);
31460
+ _t(null), yt(t);
31442
31461
  return;
31443
31462
  }
31444
- gt(e), vt("");
31463
+ _t(e), yt("");
31445
31464
  }, []);
31446
31465
  c(() => {
31447
31466
  if (!te || ee !== "connected") {
31448
- j(0);
31467
+ pt(0);
31449
31468
  return;
31450
31469
  }
31451
31470
  let e = () => {
31452
31471
  let e = new Date(te).getTime();
31453
- isNaN(e) || j(Math.max(0, Math.floor((Date.now() - e) / 1e3)));
31472
+ isNaN(e) || pt(Math.max(0, Math.floor((Date.now() - e) / 1e3)));
31454
31473
  };
31455
31474
  e();
31456
31475
  let t = window.setInterval(e, 1e3);
31457
31476
  return () => window.clearInterval(t);
31458
31477
  }, [te, ee]);
31459
- let jt = o(() => {
31460
- rt("call_screen"), St(!1);
31461
- }, []), Mt = o(() => {
31462
- rt("text_chat"), St(!0);
31478
+ let Mt = o(() => {
31479
+ it("call_screen"), Ct(!1);
31480
+ }, []), Nt = o(() => {
31481
+ it("text_chat"), Ct(!0);
31463
31482
  }, []);
31464
31483
  c(() => {
31465
31484
  let e = w?.callId || T || null;
31466
31485
  if (!e) {
31467
- Tt.current = null;
31486
+ Et.current = null;
31468
31487
  return;
31469
31488
  }
31470
31489
  if (w?.callId || ee === "connecting" || ee === "connected") {
31471
- if (A === "minimized_orb" && xt && T && !w?.callId) {
31472
- Tt.current = e;
31490
+ if (A === "minimized_orb" && St && T && !w?.callId) {
31491
+ Et.current = e;
31473
31492
  return;
31474
31493
  }
31475
- !(!i || A === "minimized_orb" || A === "voice_mode") && Tt.current === e || (console.log("[FlowEngageWidget] forcing call UI to front", {
31494
+ !(!i || A === "minimized_orb" || A === "voice_mode") && Et.current === e || (console.log("[FlowEngageWidget] forcing call UI to front", {
31476
31495
  forcedKey: e,
31477
31496
  isOpen: i,
31478
31497
  surface: A,
31479
31498
  hasIncomingCall: !!w?.callId,
31480
31499
  activeCallId: T,
31481
31500
  callConnectionState: ee
31482
- }), Tt.current = e, A === "voice_mode" && le?.(!1), se?.(), jt());
31501
+ }), Et.current = e, A === "voice_mode" && ue?.(!1), ce?.(), Mt());
31483
31502
  }
31484
31503
  }, [
31485
31504
  T,
31486
31505
  ee,
31487
- jt,
31506
+ Mt,
31488
31507
  w?.callId,
31489
31508
  i,
31490
- se,
31491
- le,
31509
+ ce,
31510
+ ue,
31492
31511
  A
31493
31512
  ]), c(() => {
31494
- !w && !T && A === "call_screen" && rt("text_chat");
31513
+ !w && !T && A === "call_screen" && it("text_chat");
31495
31514
  }, [
31496
31515
  w,
31497
31516
  T,
31498
31517
  A
31499
31518
  ]), c(() => {
31500
- !T && xt && St(!1);
31501
- }, [T, xt]), c(() => {
31519
+ !T && St && Ct(!1);
31520
+ }, [T, St]), c(() => {
31502
31521
  if (!s || C) {
31503
- xe?.(""), be?.();
31522
+ Se?.(""), xe?.();
31504
31523
  return;
31505
31524
  }
31506
- if (!it.trim() || ht) {
31507
- xe?.("");
31508
- let e = window.setTimeout(() => be?.(), 100);
31525
+ if (!at.trim() || gt) {
31526
+ Se?.("");
31527
+ let e = window.setTimeout(() => xe?.(), 100);
31509
31528
  return () => window.clearTimeout(e);
31510
31529
  }
31511
- ye?.();
31512
- let e = window.setTimeout(() => xe?.(it), 120), t = window.setTimeout(() => be?.(), 1200);
31530
+ be?.();
31531
+ let e = window.setTimeout(() => Se?.(at), 120), t = window.setTimeout(() => xe?.(), 1200);
31513
31532
  return () => {
31514
31533
  window.clearTimeout(e), window.clearTimeout(t);
31515
31534
  };
31516
31535
  }, [
31517
- it,
31518
- ht,
31536
+ at,
31537
+ gt,
31519
31538
  s,
31520
31539
  C,
31521
- ye,
31522
31540
  be,
31523
- xe
31541
+ xe,
31542
+ Se
31524
31543
  ]);
31525
- let Nt = (e) => e ? {
31544
+ let Pt = (e) => e ? {
31526
31545
  replyTo: e.messageId || e.id || null,
31527
31546
  replyToContent: (e.replyToContent || e.message || "").replace(/<[^>]+>/g, "").trim().slice(0, 200),
31528
31547
  replyToSender: e.sender || null
31529
- } : null, Pt = async (e) => {
31548
+ } : null, Ft = async (e) => {
31530
31549
  if (e.preventDefault(), C) return;
31531
- if (nt) {
31532
- let e = ct.trim().toLowerCase();
31550
+ if (k) {
31551
+ let e = lt.trim().toLowerCase();
31533
31552
  if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)) {
31534
- dt("Please enter a valid email so we can continue helping you.");
31553
+ ft("Please enter a valid email so we can continue helping you.");
31535
31554
  return;
31536
31555
  }
31537
- await ce(e), dt("");
31556
+ await le(e), ft("");
31538
31557
  return;
31539
31558
  }
31540
- let t = Nt(ot);
31541
- if (!it.trim() && !ht) return;
31542
- if (ht) {
31559
+ let t = Pt(st);
31560
+ if (!at.trim() && !gt) return;
31561
+ if (gt) {
31543
31562
  try {
31544
- bt(!0), vt("");
31545
- let e = await D(ht), n = e?.data || e, r = it.trim() || `Shared file: ${iO(ht)}`;
31546
- at(""), st(null), kt(), await oe(r, "", t, {
31563
+ xt(!0), yt("");
31564
+ let e = await se(gt), n = e?.data || e, r = at.trim() || `Shared file: ${iO(gt)}`;
31565
+ ot(""), ct(null), At(), await D(r, "", t, {
31547
31566
  type: "file",
31548
31567
  metadata: {
31549
31568
  fileUrl: n?.fileUrl,
31550
- fileName: n?.fileName || ht.name,
31551
- fileType: n?.fileType || ht.type,
31552
- fileSize: n?.fileSize || ht.size
31569
+ fileName: n?.fileName || gt.name,
31570
+ fileType: n?.fileType || gt.type,
31571
+ fileSize: n?.fileSize || gt.size
31553
31572
  }
31554
31573
  });
31555
31574
  } catch (e) {
31556
- vt(e?.message || "Failed to upload the selected file.");
31575
+ yt(e?.message || "Failed to upload the selected file.");
31557
31576
  } finally {
31558
- bt(!1);
31577
+ xt(!1);
31559
31578
  }
31560
31579
  return;
31561
31580
  }
31562
- let n = it.trim();
31563
- at(""), st(null), await oe(n, "", t);
31564
- }, Ft = (e) => {
31581
+ let n = at.trim();
31582
+ ot(""), ct(null), await D(n, "", t);
31583
+ }, It = (e) => {
31565
31584
  let t = Math.floor(e / 60);
31566
31585
  return `${String(t).padStart(2, "0")}:${String(e % 60).padStart(2, "0")}`;
31567
- }, It = o(async (e) => {
31586
+ }, Lt = o(async (e) => {
31568
31587
  if (C || b) return;
31569
31588
  let t = e.message || e.label || e.text || "";
31570
- t.trim() && await oe(t.trim(), "");
31589
+ t.trim() && await D(t.trim(), "");
31571
31590
  }, [
31572
31591
  C,
31573
31592
  b,
31574
- oe
31575
- ]), Lt = Dt && A === "entry_prompt" ? { inset: 0 } : Dt && A === "text_chat" ? {
31593
+ D
31594
+ ]), Rt = Ot && A === "entry_prompt" ? { inset: 0 } : Ot && A === "text_chat" ? {
31576
31595
  left: 0,
31577
31596
  right: 0,
31578
31597
  bottom: 0
31579
- } : Dt && A === "call_screen" ? {
31598
+ } : Ot && A === "call_screen" ? {
31580
31599
  left: 0,
31581
31600
  right: 0,
31582
31601
  bottom: 0,
31583
31602
  height: "90dvh",
31584
31603
  overflow: "hidden",
31585
31604
  borderRadius: "16px 16px 0 0"
31586
- } : Dt && A === "connection_modal" ? {
31605
+ } : Ot && A === "connection_modal" ? {
31587
31606
  left: "28px",
31588
31607
  right: "12px",
31589
31608
  bottom: "12px"
@@ -31592,24 +31611,24 @@ function Qk() {
31592
31611
  height: "min(640px, calc(100vh - 120px))",
31593
31612
  borderRadius: "22px",
31594
31613
  overflow: "hidden",
31595
- ...Le === "bottom-left" ? {
31614
+ ...Re === "bottom-left" ? {
31596
31615
  left: "1.5rem",
31597
31616
  bottom: "1.5rem"
31598
31617
  } : {
31599
31618
  right: "1.5rem",
31600
31619
  bottom: "1.5rem"
31601
31620
  }
31602
- } : Le === "bottom-left" ? {
31621
+ } : Re === "bottom-left" ? {
31603
31622
  left: "1.5rem",
31604
31623
  bottom: "1.5rem"
31605
31624
  } : {
31606
31625
  right: "1.5rem",
31607
31626
  bottom: "1.5rem"
31608
- }, Rt = o(() => {
31609
- A !== "minimized_orb" && (wt(!0), setTimeout(() => {
31610
- rt("minimized_orb"), wt(!1);
31627
+ }, zt = o(() => {
31628
+ A !== "minimized_orb" && (Tt(!0), setTimeout(() => {
31629
+ it("minimized_orb"), Tt(!1);
31611
31630
  }, 280));
31612
- }, [A]), zt = () => rt("connection_modal"), Bt = () => {
31631
+ }, [A]), Bt = () => it("connection_modal"), Vt = () => {
31613
31632
  try {
31614
31633
  let e = window.AudioContext || window.webkitAudioContext;
31615
31634
  if (e) {
@@ -31617,34 +31636,34 @@ function Qk() {
31617
31636
  t.resume().catch(() => {}), setTimeout(() => t.close().catch(() => {}), 3e3);
31618
31637
  }
31619
31638
  } catch {}
31620
- se({ notifyChatInitiated: !0 }), le?.(!0), rt("voice_mode");
31621
- }, Vt = () => {
31622
- se({ notifyChatInitiated: !0 }), le?.(!1), rt("text_chat");
31639
+ ce({ notifyChatInitiated: !0 }), ue?.(!0), it("voice_mode");
31623
31640
  }, Ht = () => {
31624
- le?.(!1), Rt();
31641
+ ce({ notifyChatInitiated: !0 }), ue?.(!1), it("text_chat");
31642
+ }, Ut = () => {
31643
+ ue?.(!1), zt();
31625
31644
  };
31626
- return e !== "ready" || !Ge || Ae.chat === !1 ? null : /* @__PURE__ */ _("div", {
31645
+ return e !== "ready" || !Ke || Ne.chat === !1 ? null : /* @__PURE__ */ _("div", {
31627
31646
  className: "flowengage-widget-root",
31628
31647
  style: {
31629
31648
  position: "fixed",
31630
31649
  zIndex: 999999,
31631
- ...Lt
31650
+ ...Rt
31632
31651
  },
31633
31652
  onWheel: (e) => e.stopPropagation(),
31634
31653
  onTouchMove: (e) => e.stopPropagation(),
31635
31654
  children: [
31636
31655
  A === "entry_prompt" && /* @__PURE__ */ g(Kk, {
31637
- copy: qe,
31638
- orbColors: Pe,
31639
- primaryColor: Ie,
31656
+ copy: Je,
31657
+ orbColors: Ie,
31658
+ primaryColor: Le,
31640
31659
  onYes: () => {
31641
- pe(Xe), Bt();
31660
+ pe(Ze), Vt();
31642
31661
  },
31643
31662
  onLater: () => {
31644
- pe(Xe), Rt();
31663
+ pe(Ze), zt();
31645
31664
  },
31646
- isMobile: Dt,
31647
- isClosing: Ct
31665
+ isMobile: Ot,
31666
+ isClosing: wt
31648
31667
  }),
31649
31668
  A === "minimized_orb" && /* @__PURE__ */ _(bm.div, {
31650
31669
  layoutId: "fe-main-orb",
@@ -31665,14 +31684,14 @@ function Qk() {
31665
31684
  transformOrigin: "bottom right",
31666
31685
  display: "inline-flex",
31667
31686
  flexDirection: "column",
31668
- alignItems: Le === "bottom-left" ? "flex-start" : "flex-end",
31687
+ alignItems: Re === "bottom-left" ? "flex-start" : "flex-end",
31669
31688
  gap: "10px"
31670
31689
  },
31671
- children: [T && xt && /* @__PURE__ */ _("button", {
31690
+ children: [T && St && /* @__PURE__ */ _("button", {
31672
31691
  type: "button",
31673
- onClick: jt,
31692
+ onClick: Mt,
31674
31693
  style: {
31675
- maxWidth: Dt ? "220px" : "240px",
31694
+ maxWidth: Ot ? "220px" : "240px",
31676
31695
  padding: "10px 14px",
31677
31696
  borderRadius: "18px",
31678
31697
  border: "1px solid rgba(255,255,255,0.7)",
@@ -31713,112 +31732,113 @@ function Qk() {
31713
31732
  marginTop: "2px",
31714
31733
  whiteSpace: "nowrap"
31715
31734
  },
31716
- children: ee === "connected" ? `${Ft(ft)} with ${Qe}` : `Tap to return to ${Qe}`
31735
+ children: ee === "connected" ? `${It(j)} with ${$e}` : `Tap to return to ${$e}`
31717
31736
  })]
31718
31737
  })]
31719
31738
  }), /* @__PURE__ */ g(Gk, {
31720
31739
  size: 50,
31721
- orbColors: Pe,
31722
- onClick: T && xt ? jt : Ne ? zt : Vt
31740
+ orbColors: Ie,
31741
+ onClick: T && St ? Mt : Pe ? Bt : Ht
31723
31742
  })]
31724
31743
  }),
31725
31744
  A === "connection_modal" && /* @__PURE__ */ g(qk, {
31726
- copy: qe,
31727
- orbColors: Pe,
31728
- primaryColor: Ie,
31729
- onVoice: Bt,
31730
- onText: Vt,
31731
- onClose: Rt,
31732
- isMobile: Dt,
31733
- isClosing: Ct
31745
+ copy: Je,
31746
+ orbColors: Ie,
31747
+ primaryColor: Le,
31748
+ onVoice: Vt,
31749
+ onText: Ht,
31750
+ onClose: zt,
31751
+ isMobile: Ot,
31752
+ isClosing: wt
31734
31753
  }),
31735
31754
  A === "voice_mode" && /* @__PURE__ */ g(Jk, {
31736
- orbColors: Pe,
31737
- onEnterChat: Vt,
31738
- onEndChat: Ht,
31739
- agentId: Je,
31740
- voiceId: Ye,
31741
- siteId: Xe,
31742
- apiBaseUrl: Ze,
31743
- historyRef: ie,
31744
- onMessageSync: ae
31755
+ orbColors: Ie,
31756
+ onEnterChat: Ht,
31757
+ onEndChat: Ut,
31758
+ agentId: Ye,
31759
+ voiceId: Xe,
31760
+ siteId: Ze,
31761
+ apiBaseUrl: Qe,
31762
+ chatId: ie,
31763
+ historyRef: ae,
31764
+ onMessageSync: oe
31745
31765
  }, "voice"),
31746
31766
  A === "call_screen" && /* @__PURE__ */ g(TO, {
31747
31767
  incomingCall: w,
31748
31768
  activeCallId: T,
31749
31769
  callConnectionState: ee,
31750
- callDurationSeconds: ft,
31770
+ callDurationSeconds: j,
31751
31771
  isCallMuted: ne,
31752
- agentName: Qe,
31753
- agentHeadshot: $e,
31754
- fallbackAgentName: Re,
31755
- acceptCall: me,
31756
- rejectCall: he,
31757
- endWebRTCCall: ge,
31758
- toggleCallMute: _e,
31759
- formatCallDuration: Ft,
31760
- onMinimize: Mt,
31761
- primaryColor: Ie,
31762
- orbColors: Pe,
31772
+ agentName: $e,
31773
+ agentHeadshot: et,
31774
+ fallbackAgentName: ze,
31775
+ acceptCall: he,
31776
+ rejectCall: ge,
31777
+ endWebRTCCall: _e,
31778
+ toggleCallMute: ve,
31779
+ formatCallDuration: It,
31780
+ onMinimize: Nt,
31781
+ primaryColor: Le,
31782
+ orbColors: Ie,
31763
31783
  chatHistory: r
31764
31784
  }),
31765
31785
  A === "text_chat" && /* @__PURE__ */ g(Zk, {
31766
- isClosing: Ct,
31767
- copy: qe,
31768
- orbColors: Pe,
31769
- primaryColor: Ie,
31770
- chatBgGradient: ze,
31771
- logo: O,
31772
- quickChatOptions: Ue,
31773
- onQuickChatSelect: It,
31774
- isMobile: Dt,
31786
+ isClosing: wt,
31787
+ copy: Je,
31788
+ orbColors: Ie,
31789
+ primaryColor: Le,
31790
+ chatBgGradient: O,
31791
+ logo: Be,
31792
+ quickChatOptions: We,
31793
+ onQuickChatSelect: Lt,
31794
+ isMobile: Ot,
31775
31795
  chatHistory: r,
31776
31796
  isAiTyping: y,
31777
31797
  isAgentTyping: v,
31778
31798
  activeScreen: a,
31779
- agentName: Qe,
31780
- agentHeadshot: $e,
31781
- fallbackAgentName: Re,
31782
- input: it,
31783
- setInput: at,
31784
- onSubmit: Pt,
31799
+ agentName: $e,
31800
+ agentHeadshot: et,
31801
+ fallbackAgentName: ze,
31802
+ input: at,
31803
+ setInput: ot,
31804
+ onSubmit: Ft,
31785
31805
  isConversationEnded: C,
31786
31806
  isLoading: b,
31787
31807
  isRateLimited: x,
31788
31808
  rateLimitMessage: S,
31789
- selectedFile: ht,
31790
- onFileSelect: At,
31791
- onRemoveSelectedFile: kt,
31792
- attachmentError: _t,
31793
- isUploadingAttachment: yt,
31794
- requiresEmail: nt,
31795
- emailInput: ct,
31796
- setEmailInput: lt,
31797
- emailError: ut,
31798
- replyContext: ot,
31799
- setReplyContext: st,
31809
+ selectedFile: gt,
31810
+ onFileSelect: jt,
31811
+ onRemoveSelectedFile: At,
31812
+ attachmentError: vt,
31813
+ isUploadingAttachment: bt,
31814
+ requiresEmail: k,
31815
+ emailInput: lt,
31816
+ setEmailInput: ut,
31817
+ emailError: dt,
31818
+ replyContext: st,
31819
+ setReplyContext: ct,
31800
31820
  webRTCError: re,
31801
- micError: pt,
31802
- setMicError: mt,
31803
- dismissCallError: ve,
31821
+ micError: mt,
31822
+ setMicError: ht,
31823
+ dismissCallError: ye,
31804
31824
  activeCallId: T,
31805
31825
  isCallMuted: ne,
31806
- toggleCallMute: _e,
31807
- endWebRTCCall: ge,
31808
- formatCallDuration: Ft,
31809
- callDurationSeconds: ft,
31810
- onCollapse: Rt,
31811
- onStartVoice: Bt,
31812
- onNewChat: de,
31813
- onEndConversation: ue,
31814
- onMinimize: Mt,
31815
- onExpand: jt,
31816
- isCallMinimized: xt && !!T,
31817
- showPoweredBy: We,
31818
- getVisitorChatHistory: Se,
31819
- getVisitorChatThread: Ce,
31820
- resumeChat: we,
31821
- isSessionRestoring: Te
31826
+ toggleCallMute: ve,
31827
+ endWebRTCCall: _e,
31828
+ formatCallDuration: It,
31829
+ callDurationSeconds: j,
31830
+ onCollapse: zt,
31831
+ onStartVoice: Vt,
31832
+ onNewChat: me,
31833
+ onEndConversation: de,
31834
+ onMinimize: Nt,
31835
+ onExpand: Mt,
31836
+ isCallMinimized: St && !!T,
31837
+ showPoweredBy: Ge,
31838
+ getVisitorChatHistory: Ce,
31839
+ getVisitorChatThread: we,
31840
+ resumeChat: Te,
31841
+ isSessionRestoring: Ee
31822
31842
  }),
31823
31843
  /* @__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
31844
  ]