@flowengage/react-chatbot 6.0.24 → 6.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -506,7 +506,7 @@ var k = (e) => {
506
506
  let l = new ArrayBuffer(t), u = new Uint8Array(l);
507
507
  for (r = 0; r < n; r += 4) a = at[e.charCodeAt(r)], o = at[e.charCodeAt(r + 1)], s = at[e.charCodeAt(r + 2)], c = at[e.charCodeAt(r + 3)], u[i++] = a << 2 | o >> 4, u[i++] = (o & 15) << 4 | s >> 2, u[i++] = (s & 3) << 6 | c & 63;
508
508
  return l;
509
- }, ot = typeof ArrayBuffer == "function", A = (e, t) => {
509
+ }, A = typeof ArrayBuffer == "function", ot = (e, t) => {
510
510
  if (typeof e != "string") return {
511
511
  type: "message",
512
512
  data: ct(e, t)
@@ -519,7 +519,7 @@ var k = (e) => {
519
519
  type: Je[n],
520
520
  data: e.substring(1)
521
521
  } : { type: Je[n] } : Ye;
522
- }, st = (e, t) => ot ? ct(k(e), t) : {
522
+ }, st = (e, t) => A ? ct(k(e), t) : {
523
523
  base64: !0,
524
524
  data: e
525
525
  }, ct = (e, t) => {
@@ -537,7 +537,7 @@ var k = (e) => {
537
537
  }, dt = (e, t) => {
538
538
  let n = e.split(lt), r = [];
539
539
  for (let e = 0; e < n.length; e++) {
540
- let i = A(n[e], t);
540
+ let i = ot(n[e], t);
541
541
  if (r.push(i), i.type === "error") break;
542
542
  }
543
543
  return r;
@@ -594,7 +594,7 @@ function gt(e, t) {
594
594
  } else {
595
595
  if (mt(n) < i) break;
596
596
  let e = ht(n, i);
597
- s.enqueue(A(a ? e : pt.decode(e), t)), r = 0;
597
+ s.enqueue(ot(a ? e : pt.decode(e), t)), r = 0;
598
598
  }
599
599
  if (i === 0 || i > e) {
600
600
  s.enqueue(Ye);
@@ -707,7 +707,7 @@ var jt = class extends Error {
707
707
  this.readyState = "open", this.writable = !0, super.emitReserved("open");
708
708
  }
709
709
  onData(e) {
710
- let t = A(e, this.socket.binaryType);
710
+ let t = ot(e, this.socket.binaryType);
711
711
  this.onPacket(t);
712
712
  }
713
713
  onPacket(e) {
@@ -2839,7 +2839,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
2839
2839
  let i = f(() => e ? {
2840
2840
  ...t || {},
2841
2841
  siteId: e
2842
- } : t || null, [e, t]), [a, s] = m(0), [l, u] = m("booting"), [d, h] = m(null), [_, v] = m(null), [y, b] = m(""), [x, S] = m([]), [C, w] = m(ve().isOpen), [T, te] = m(ve().activeScreen), [ne, re] = m(ve().isHumanHandled), [E, D] = m(ve().agentName), [se, de] = m(ve().agentHeadshot), [fe, pe] = m(() => be(i?.siteId)), [me, Se] = m(!1), [Ce, we] = m(!1), [Ee, De] = m("idle"), [Oe, ke] = m(!1), [Ae, je] = m(!1), [Me, Ne] = m(""), [Fe, Ie] = m(!1), [Le, Re] = m(0), [ze, Be] = m(0), [Ve, He] = m(!1), [O, Ue] = m(null), [qe, Je] = m(null), [Ye, Xe] = m("idle"), [Ze, Qe] = m(null), [$e, et] = m(!1), [tt, nt] = m(""), [rt, it] = m(!1), at = p(null), k = p(null), ot = p(""), A = p(!1), st = p(null), ct = p(null), lt = p(null), ut = p(null), dt = p(null), ft = p(null), pt = p([]), mt = p(null), ht = p(null), gt = p(null), j = p(!1), _t = p(!1), vt = p(""), yt = p(null), bt = p(null), xt = p([]), St = p(0), Ct = p(E), wt = p([]), Tt = p(!1), Et = p(!1), Dt = p(i), Ot = p({
2842
+ } : t || null, [e, t]), [a, s] = m(0), [l, u] = m("booting"), [d, h] = m(null), [_, v] = m(null), [y, b] = m(""), [x, S] = m([]), [C, w] = m(ve().isOpen), [T, te] = m(ve().activeScreen), [ne, re] = m(ve().isHumanHandled), [E, D] = m(ve().agentName), [se, de] = m(ve().agentHeadshot), [fe, pe] = m(() => be(i?.siteId)), [me, Se] = m(!1), [Ce, we] = m(!1), [Ee, De] = m("idle"), [Oe, ke] = m(!1), [Ae, je] = m(!1), [Me, Ne] = m(""), [Fe, Ie] = m(!1), [Le, Re] = m(0), [ze, Be] = m(0), [Ve, He] = m(!1), [O, Ue] = m(null), [qe, Je] = m(null), [Ye, Xe] = m("idle"), [Ze, Qe] = m(null), [$e, et] = m(!1), [tt, nt] = m(""), [rt, it] = m(!1), at = p(null), k = p(null), A = p(""), ot = p(!1), st = p(null), ct = p(null), lt = p(null), ut = p(null), dt = p(null), ft = p(null), pt = p([]), mt = p(null), ht = p(null), gt = p(null), j = p(!1), _t = p(!1), vt = p(""), yt = p(null), bt = p(null), xt = p([]), St = p(0), Ct = p(E), wt = p([]), Tt = p(!1), Et = p(!1), Dt = p(i), Ot = p({
2843
2843
  notifyRouteChange: () => {},
2844
2844
  cleanup: () => {}
2845
2845
  }), kt = o((e = {}) => {
@@ -2904,7 +2904,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
2904
2904
  if (!(!t?.connected || !n || j.current)) {
2905
2905
  j.current = !0, t.emit("call:connected", {
2906
2906
  callId: n,
2907
- chatId: ot.current,
2907
+ chatId: A.current,
2908
2908
  connectedAt: e
2909
2909
  });
2910
2910
  try {
@@ -2971,7 +2971,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
2971
2971
  if (!t || !n?.connected || !r || !e.callId) {
2972
2972
  console.log("[FlowEngageProvider] deferring remote offer until peer/socket ready", {
2973
2973
  callId: e.callId,
2974
- chatId: ot.current,
2974
+ chatId: A.current,
2975
2975
  hasPeerConnection: !!t,
2976
2976
  socketConnected: !!n?.connected,
2977
2977
  hasOffer: !!r
@@ -2984,7 +2984,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
2984
2984
  })), pt.current.length > 0) {
2985
2985
  console.log("[FlowEngageProvider] flushing queued agent ICE candidates after remote offer", {
2986
2986
  callId: e.callId,
2987
- chatId: ot.current,
2987
+ chatId: A.current,
2988
2988
  queuedCount: pt.current.length
2989
2989
  });
2990
2990
  for (let e of pt.current) await t.addIceCandidate(new RTCIceCandidate(e));
@@ -2994,7 +2994,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
2994
2994
  await t.setLocalDescription(i), n.emit("call:answer", {
2995
2995
  callId: e.callId,
2996
2996
  sdpAnswer: i.sdp,
2997
- chatId: ot.current
2997
+ chatId: A.current
2998
2998
  });
2999
2999
  };
3000
3000
  c(() => {
@@ -3020,8 +3020,8 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3020
3020
  if (!e) return;
3021
3021
  let a = t.siteId, o = he(a), s = Te(a), c = "";
3022
3022
  try {
3023
- let e = A.current, r = st.current;
3024
- if (A.current = !1, st.current = null, c = (await We({
3023
+ let e = ot.current, r = st.current;
3024
+ if (ot.current = !1, st.current = null, c = (await We({
3025
3025
  apiBaseUrl: t.apiBaseUrl,
3026
3026
  userId: n.userId,
3027
3027
  siteId: a,
@@ -3034,7 +3034,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3034
3034
  } catch (e) {
3035
3035
  console.warn("[FlowEngageProvider] resolve-session failed, reusing persisted or ephemeral chat id", e?.message || e), c = o || ue(), _e(a, c);
3036
3036
  }
3037
- ot.current = c;
3037
+ A.current = c;
3038
3038
  let l = Ke({
3039
3039
  apiBaseUrl: t.apiBaseUrl,
3040
3040
  userId: n.userId,
@@ -3180,7 +3180,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3180
3180
  if (!lt.current || !lt.current.remoteDescription) {
3181
3181
  console.log("[FlowEngageProvider] queueing agent ICE candidate until peer/remote description is ready", {
3182
3182
  callId: e.callId,
3183
- chatId: e.chatId || ot.current,
3183
+ chatId: e.chatId || A.current,
3184
3184
  queueSize: pt.current.length + 1
3185
3185
  }), pt.current.push(t);
3186
3186
  return;
@@ -3255,7 +3255,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3255
3255
  a
3256
3256
  ]), c(() => () => {
3257
3257
  if (Fe && !Tt.current && wt.current.length > 0) {
3258
- let e = ot.current, t = wt.current, n = k.current;
3258
+ let e = A.current, t = wt.current, n = k.current;
3259
3259
  n && e && t.length > 0 && (console.log("[FlowEngageProvider] safety-net: syncing voice transcript on unmount"), n.beaconSyncVoice(e, t) || n.syncVoice(e, t).catch(() => {}), Tt.current = !0);
3260
3260
  }
3261
3261
  }, [Fe, _]);
@@ -3265,7 +3265,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3265
3265
  !e || !y || zt.current !== C && (C && zt.current !== null ? (e.updateChatStatus(y, "open").catch(() => {}), Bt.current = !0) : zt.current === !0 && e.updateChatStatus(y, "widget_closed").catch(() => {}), zt.current = C);
3266
3266
  }, [C, y]), c(() => {
3267
3267
  let e = () => {
3268
- let e = ot.current, t = k.current;
3268
+ let e = A.current, t = k.current;
3269
3269
  !e || !t || typeof navigator > "u" || t.beaconWidgetClosed?.(e) || t.updateChatStatus(e, "widget_closed").catch(() => {});
3270
3270
  };
3271
3271
  return window.addEventListener("pagehide", e), () => window.removeEventListener("pagehide", e);
@@ -3448,10 +3448,10 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3448
3448
  }
3449
3449
  }, qt = async (e) => {
3450
3450
  let t = Nt(e);
3451
- if (!t || !k.current || !ot.current) return t;
3451
+ if (!t || !k.current || !A.current) return t;
3452
3452
  try {
3453
3453
  await k.current.trackVisitor({
3454
- chatId: ot.current,
3454
+ chatId: A.current,
3455
3455
  currentPagePath: typeof window < "u" && window.location.pathname || "/",
3456
3456
  email: t
3457
3457
  });
@@ -3611,7 +3611,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3611
3611
  At
3612
3612
  ]), c(() => {
3613
3613
  let e = () => {
3614
- let e = ot.current, t = k.current;
3614
+ let e = A.current, t = k.current;
3615
3615
  if (!t || !e) return;
3616
3616
  if (Et.current && wt.current.length > 0 && Pe(), !Tt.current && wt.current.length > 0 && (t.beaconSyncVoice(e, wt.current) || t.syncVoice(e, wt.current).catch(() => {}), Tt.current = !0), mt.current) {
3617
3617
  t.beaconEndWebRTCCall(mt.current, e);
@@ -3626,9 +3626,9 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3626
3626
  }, []);
3627
3627
  let nn = o(() => {
3628
3628
  let e = i?.siteId;
3629
- ge(e), A.current = !0, st.current = null, at.current?.disconnect(), S([]), b(""), ot.current = "", He(!1), re(!1), D(null), de(null), it(!0), s((e) => e + 1);
3629
+ ge(e), ot.current = !0, st.current = null, at.current?.disconnect(), S([]), b(""), A.current = "", He(!1), re(!1), D(null), de(null), it(!0), s((e) => e + 1);
3630
3630
  }, [i?.siteId]), rn = o((e) => {
3631
- i?.siteId, A.current = !1, st.current = e, at.current?.disconnect(), S([]), b(""), ot.current = "", He(!1), re(!1), D(null), de(null), it(!0), s((e) => e + 1);
3631
+ i?.siteId, ot.current = !1, st.current = e, at.current?.disconnect(), S([]), b(""), A.current = "", He(!1), re(!1), D(null), de(null), it(!0), s((e) => e + 1);
3632
3632
  }, [i?.siteId]), an = f(() => ({
3633
3633
  status: l,
3634
3634
  error: d,
@@ -29268,12 +29268,7 @@ function vk(e) {
29268
29268
  let t = e.url ?? e.target_url ?? e.page_url ?? e.pageUrl ?? e.link ?? e.href ?? e.path;
29269
29269
  return t == null ? null : String(t).trim() || null;
29270
29270
  }
29271
- function yk(e) {
29272
- if (!e || typeof e != "object") return null;
29273
- let t = e.query ?? e.q ?? e.search ?? e.text ?? e.keywords;
29274
- return t == null ? null : String(t).trim() || null;
29275
- }
29276
- function bk(e, t, n) {
29271
+ function yk(e, t, n) {
29277
29272
  if (!n?.skipScroll) try {
29278
29273
  e.scrollIntoView({
29279
29274
  block: "center",
@@ -29328,7 +29323,7 @@ function bk(e, t, n) {
29328
29323
  } catch {}
29329
29324
  return !0;
29330
29325
  }
29331
- function xk() {
29326
+ function bk() {
29332
29327
  let e = {};
29333
29328
  document.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach((t) => {
29334
29329
  if (t.id) return;
@@ -29343,11 +29338,11 @@ function xk() {
29343
29338
  e[r] = !0, t.id = r;
29344
29339
  });
29345
29340
  }
29346
- function Sk() {
29341
+ function xk() {
29347
29342
  let e = document.querySelector("main, [role='main'], article") || document.body;
29348
29343
  return Array.from(e.querySelectorAll("h1, h2, h3")).filter((e) => !e.closest("#flowengage-root, .flowengage-shell, .flowengage-widget-root")).map((e) => e.textContent.replace(/\s+/g, " ").trim()).filter((e) => e.length > 2 && e.length < 200).slice(0, 12);
29349
29344
  }
29350
- function Ck(e) {
29345
+ function Sk(e) {
29351
29346
  let t = e.siteId || null, n = (e.apiBaseUrl || "").replace(/\/$/, ""), r = typeof e.getLastUserVoiceText == "function" ? e.getLastUserVoiceText : null, i = [], a = {
29352
29347
  flowengage_navigate: async (n) => {
29353
29348
  $("flowengage_navigate ▶ raw parameters:", n);
@@ -29378,7 +29373,7 @@ function Ck(e) {
29378
29373
  siteId: t,
29379
29374
  apiBaseUrl: e.apiBaseUrl
29380
29375
  })) {
29381
- let e = `Page "${a}" could not be verified. Call flowengage_search with keywords from the topic to find the correct URL, then navigate to the URL from the search results.`;
29376
+ let e = `Page "${a}" could not be verified. Try a different URL from your known site pages, or ask the visitor to clarify which page they want.`;
29382
29377
  return $("flowengage_navigate ✖ blocked", e), e;
29383
29378
  }
29384
29379
  try {
@@ -29406,8 +29401,8 @@ function Ck(e) {
29406
29401
  let n = typeof window < "u" ? window.location.pathname : e, r = typeof window < "u" ? window.location.href : a, i = n === e, o = (n.split("/").filter(Boolean).pop() || "").replace(/[-_]/g, " ").replace(/\b\w/g, (e) => e.toUpperCase()) || "Home";
29407
29402
  $("flowengage_navigate → SPA nav complete. target:", e, "actual:", n);
29408
29403
  let s = [], c = Date.now() + 8e3;
29409
- for (; Date.now() < c && (await new Promise((e) => setTimeout(e, 250)), s = Sk(), !(s.length >= 1)););
29410
- xk(), $("flowengage_navigate → page headings collected:", s);
29404
+ for (; Date.now() < c && (await new Promise((e) => setTimeout(e, 250)), s = xk(), !(s.length >= 1)););
29405
+ bk(), $("flowengage_navigate → page headings collected:", s);
29411
29406
  let l = s.length ? s.join(" | ") : "none", u = s.length ? "Use ONLY these exact heading strings for flowengage_highlight." : "No headings were collected from the live DOM — use your knowledge base heading strings for this page to call flowengage_highlight. Follow RULE 1: call each highlight BEFORE describing its section (transition → highlight → content).";
29412
29407
  return i ? (wr(), `OK_NAVIGATE_SPA. Visitor is now on: ${r} (page: "${o}") | Section headings: ${l}. ${u} MANDATORY: call flowengage_highlight for EVERY section before describing it — never give a plain summary. Do NOT say "I have navigated you" or "I've taken you to" — start the highlighted walkthrough immediately.`) : (wr(), `OK_NAVIGATE_SPA. CURRENT PAGE IS: ${r} (page: "${o}") | Section headings: ${l}. ${u} MANDATORY: call flowengage_highlight for EVERY section before describing it — never give a plain summary. Describe THIS page only — do not mention the page you tried to navigate to.`);
29413
29408
  } catch {}
@@ -29431,15 +29426,15 @@ function Ck(e) {
29431
29426
  if (Date.now() - e.ts >= 3e4) window.__fe_user_nav_during_speech = null;
29432
29427
  else return $("flowengage_highlight ✖ blocked — user navigated during speech", e), `NAV_CHANGED: The visitor navigated from "${e.fromPageName}" to "${e.toPageName}" (current path: ${t}) while you were speaking. STOP the current walkthrough immediately. DO NOT call flowengage_highlight again. Say out loud: "I see you've navigated to the ${e.toPageName} page — do you want me to continue what I was explaining, or shall I guide you through this page?" Wait for the visitor's answer before doing anything else.`;
29433
29428
  }
29434
- xk();
29429
+ bk();
29435
29430
  let i = hr(n || null, r || null);
29436
29431
  if (!i && r) {
29437
29432
  let e = Date.now() + 600;
29438
- for (; !i && Date.now() < e;) await new Promise((e) => setTimeout(e, 50)), xk(), i = hr(null, r);
29433
+ for (; !i && Date.now() < e;) await new Promise((e) => setTimeout(e, 50)), bk(), i = hr(null, r);
29439
29434
  }
29440
29435
  if (!i) {
29441
29436
  $("flowengage_highlight ✖ no element for:", r || n);
29442
- let e = Sk(), t = e.length ? `Page headings: ${e.join(" | ")}. Use one of these exact strings for section_text.` : "No headings found — skip highlight and continue.";
29437
+ let e = xk(), t = e.length ? `Page headings: ${e.join(" | ")}. Use one of these exact strings for section_text.` : "No headings found — skip highlight and continue.";
29443
29438
  return `HIGHLIGHT_NOT_FOUND: "${r || n}" on the current page. ${t}`;
29444
29439
  }
29445
29440
  return xD(i), $("flowengage_highlight ✓", r || n), `OK_HIGHLIGHT: "${r || n}". WALKTHROUGH: continue immediately to the next section — do NOT pause between sections.`;
@@ -29467,38 +29462,6 @@ function Ck(e) {
29467
29462
  return $("flowengage_read_content ✖", e.message), `Could not read page content: ${e.message}`;
29468
29463
  }
29469
29464
  },
29470
- flowengage_search: async (e) => {
29471
- $("flowengage_search ▶", e);
29472
- let r = yk(mk(e));
29473
- if ($("flowengage_search · query:", r, "siteId:", t, "apiBase:", n || "(empty)"), !r) return $("flowengage_search ✖ missing query"), "Missing query parameter.";
29474
- if (!t) return $("flowengage_search ✖ no siteId"), "Site is not configured for search.";
29475
- if (!n) return $("flowengage_search ✖ no api base"), "API base URL is missing; cannot search.";
29476
- CO(`Searching${r ? ` for "${r}"` : ""}…`, { spinner: !0 });
29477
- try {
29478
- let e = `${n}/api/site-tools/search`;
29479
- $("flowengage_search → POST", e);
29480
- let i = await fetch(e, {
29481
- method: "POST",
29482
- headers: { "Content-Type": "application/json" },
29483
- body: JSON.stringify({
29484
- siteId: t,
29485
- query: r,
29486
- currentUrl: typeof window < "u" ? window.location.href : ""
29487
- })
29488
- }), a = await i.json();
29489
- if ($("flowengage_search · HTTP", i.status, "success:", a.success), !a.success) {
29490
- let e = a.error || "Search failed.";
29491
- return $("flowengage_search ✖", e), e;
29492
- }
29493
- let o = a.results || [];
29494
- return $("flowengage_search ✓", `${o.length} result(s)`, o.slice(0, 3).map((e) => e?.url || e)), JSON.stringify(o);
29495
- } catch (e) {
29496
- let t = `Search error: ${e.message || "network"}`;
29497
- return $("flowengage_search ✖", t), t;
29498
- } finally {
29499
- wO(600);
29500
- }
29501
- },
29502
29465
  flowengage_page_content: async (e) => {
29503
29466
  $("flowengage_page_content ▶", e);
29504
29467
  let r = mk(e), i = r?.url || r?.page_url || "";
@@ -29534,7 +29497,7 @@ function Ck(e) {
29534
29497
  flowengage_end_session: async () => ($("flowengage_end_session ▶"), typeof e.requestEndSession == "function" && e.requestEndSession(), "Voice session is ending."),
29535
29498
  flowengage_get_current_page: async () => {
29536
29499
  if ($("flowengage_get_current_page ▶"), typeof window > "u") return "Cannot determine current page (no browser context).";
29537
- let e = window.location.href, t = window.location.pathname, n = document.title || "", r = Sk(), i = r.length ? r.join(" | ") : "none";
29500
+ let e = window.location.href, t = window.location.pathname, n = document.title || "", r = xk(), i = r.length ? r.join(" | ") : "none";
29538
29501
  return $("flowengage_get_current_page ✓", {
29539
29502
  url: e,
29540
29503
  path: t,
@@ -29565,12 +29528,12 @@ function Ck(e) {
29565
29528
  CO(`Filling ${String(t)}...`, { spinner: !0 });
29566
29529
  let a = YO(), o = ck(a, String(t), r);
29567
29530
  if (o.length) {
29568
- for (let [e, t] of o.entries()) jO(t), await LO(t), bk(t, r, { skipScroll: e > 0 }), MO(t), await HO(120);
29531
+ for (let [e, t] of o.entries()) jO(t), await LO(t), yk(t, r, { skipScroll: e > 0 }), MO(t), await HO(120);
29569
29532
  i = o, n.push(String(t));
29570
29533
  continue;
29571
29534
  }
29572
29535
  let s = dk(a, String(t));
29573
- s ||= nk(a, String(t)), s ||= rk(a, String(t), r), s && (jO(s), await LO(s), bk(s, r), MO(s), await HO(120), i = [s], n.push(String(t)));
29536
+ s ||= nk(a, String(t)), s ||= rk(a, String(t), r), s && (jO(s), await LO(s), yk(s, r), MO(s), await HO(120), i = [s], n.push(String(t)));
29574
29537
  }
29575
29538
  if (!n.length) return $("flowengage_fill_form ✖ no matches"), "Could not match any fields. Call flowengage_list_forms and use field_key values that match placeholder, label, name, or id (e.g. Enter Website URL). Ensure the form is on the page, not the chat panel.";
29576
29539
  let a = `OK_FILLED: ${n.join(", ")}`;
@@ -29627,7 +29590,6 @@ function Ck(e) {
29627
29590
  return {
29628
29591
  ...a,
29629
29592
  highlightOnPage: a.flowengage_highlight,
29630
- searchSiteContent: a.flowengage_search,
29631
29593
  getPageContent: a.flowengage_page_content,
29632
29594
  endVoiceSession: a.flowengage_end_session,
29633
29595
  listPageForms: a.flowengage_list_forms,
@@ -29637,7 +29599,7 @@ function Ck(e) {
29637
29599
  }
29638
29600
  //#endregion
29639
29601
  //#region src/utils/wrapVoiceToolsForLogging.js
29640
- function wk(e) {
29602
+ function Ck(e) {
29641
29603
  return !e || typeof e != "object" ? e : Object.fromEntries(Object.entries(e).map(([e, t]) => [e, async (n) => {
29642
29604
  let r = Rn();
29643
29605
  r ? console.log("[FlowEngage:voice-tool] ▶", e, n) : console.info(`[FlowEngage] voice tool » ${e}`);
@@ -29654,7 +29616,7 @@ function wk(e) {
29654
29616
  }
29655
29617
  //#endregion
29656
29618
  //#region src/components/FlowEngageWidget.jsx
29657
- var Tk = {
29619
+ var wk = {
29658
29620
  blue: "#135bd8",
29659
29621
  red: "#ef334b",
29660
29622
  yellow: "#ffbd2e",
@@ -29662,7 +29624,7 @@ var Tk = {
29662
29624
  highlight: "rgba(255,255,255,0.9)",
29663
29625
  green: "#10b981"
29664
29626
  };
29665
- function Ek(e) {
29627
+ function Tk(e) {
29666
29628
  if (!Array.isArray(e) || e.length < 2) return "linear-gradient(145deg, #dce8f022 0%, #e8dff522 45%, #f5e0e022 100%), #f7f8fa";
29667
29629
  let [t, n, r] = e;
29668
29630
  return e.length >= 3 && r ? [
@@ -29676,12 +29638,12 @@ function Ek(e) {
29676
29638
  "#f7f8fa"
29677
29639
  ].join(", ");
29678
29640
  }
29679
- function Dk(e) {
29641
+ function Ek(e) {
29680
29642
  if (!e || typeof e != "string") return "#1a1a1a";
29681
29643
  let t = e.replace("#", ""), n = t.length === 3 ? t.split("").map((e) => e + e).join("") : t, r = parseInt(n.slice(0, 2), 16) / 255, i = parseInt(n.slice(2, 4), 16) / 255, a = parseInt(n.slice(4, 6), 16) / 255, o = (e) => e <= .04045 ? e / 12.92 : ((e + .055) / 1.055) ** 2.4;
29682
29644
  return .2126 * o(r) + .7152 * o(i) + .0722 * o(a) > .179 ? "#1a1a1a" : "#ffffff";
29683
29645
  }
29684
- function Ok(t) {
29646
+ function Dk(t) {
29685
29647
  let [n, r] = e.useState(null), i = typeof t == "string" ? t.trim() : "";
29686
29648
  return e.useEffect(() => {
29687
29649
  if (!i) {
@@ -29699,8 +29661,8 @@ function Ok(t) {
29699
29661
  };
29700
29662
  }, [i]), n;
29701
29663
  }
29702
- function kk({ logo: t, style: n }) {
29703
- let r = Ok(typeof t == "string" ? t : null);
29664
+ function Ok({ logo: t, style: n }) {
29665
+ let r = Dk(typeof t == "string" ? t : null);
29704
29666
  if (!t) return null;
29705
29667
  if (typeof t == "string") return r ? /* @__PURE__ */ g("img", {
29706
29668
  src: r,
@@ -29725,7 +29687,7 @@ function kk({ logo: t, style: n }) {
29725
29687
  children: i
29726
29688
  }) : null;
29727
29689
  }
29728
- function Ak({ title: e }) {
29690
+ function kk({ title: e }) {
29729
29691
  return /* @__PURE__ */ g("div", {
29730
29692
  style: {
29731
29693
  width: "100%",
@@ -29743,18 +29705,18 @@ function Ak({ title: e }) {
29743
29705
  children: String(e || "FE").split(/\s+/).filter(Boolean).slice(0, 2).map((e) => e[0]?.toUpperCase() || "").join("") || "FE"
29744
29706
  });
29745
29707
  }
29746
- function jk(e, t) {
29708
+ function Ak(e, t) {
29747
29709
  let n = (t || "").trim();
29748
29710
  return n ? !!(/\b(let'?s|let us)\s+(end|stop|finish|wrap up|close)\s+(the\s+)?(voice\s+)?(session|call|chat)\b/i.test(n) || /\bend\s+(this\s+)?(the\s+)?(voice\s+)?(session|call|chat)\b/i.test(n) || /\b(hang\s+up|disconnect)\b/i.test(n) || /\b(that'?s all|we'?re done)\b/i.test(n) || e === "bot" && (/\b(I'?ll|I will|Let me|I can|I'?m going to)\s+(end|close)\s+(the\s+)?(voice\s+)?(session|call)\b/i.test(n) || /\b(ending|closing)\s+(the\s+)?(voice\s+)?session\b|\bvoice\s+session\s+(is\s+)?(now\s+)?(ended|over|closing)\b/i.test(n) || /\b(session|call)\s+(is\s+)?(now\s+)?(ended|over)\b/i.test(n) || /\bwe\s+can\s+end\s+(the\s+)?(session|call)?\s*(here|now)\b/i.test(n) || /\b(wrapping\s+up|signing\s+off)\b/i.test(n)) || /^(goodbye|bye|that'?s all|we'?re done|hang up|disconnect)\b/i.test(n)) : !1;
29749
29711
  }
29750
- function Mk({ orbColors: e, ...t }) {
29712
+ function jk({ orbColors: e, ...t }) {
29751
29713
  return /* @__PURE__ */ g(lO, {
29752
29714
  colors: e,
29753
29715
  ...t
29754
29716
  });
29755
29717
  }
29756
- function Nk({ copy: e, orbColors: t, primaryColor: n, onYes: r, onLater: i, isMobile: a, isClosing: o }) {
29757
- let s = n || Tk.green, c = Dk(s), l = a ? 72 : 94, u = /* @__PURE__ */ _("div", {
29718
+ function Mk({ copy: e, orbColors: t, primaryColor: n, onYes: r, onLater: i, isMobile: a, isClosing: o }) {
29719
+ let s = n || wk.green, c = Ek(s), l = a ? 72 : 94, u = /* @__PURE__ */ _("div", {
29758
29720
  style: {
29759
29721
  display: "flex",
29760
29722
  alignItems: a ? "flex-end" : "center",
@@ -29875,7 +29837,7 @@ function Nk({ copy: e, orbColors: t, primaryColor: n, onYes: r, onLater: i, isMo
29875
29837
  delay: 0
29876
29838
  },
29877
29839
  style: { flexShrink: 0 },
29878
- children: /* @__PURE__ */ g(Mk, {
29840
+ children: /* @__PURE__ */ g(jk, {
29879
29841
  size: l,
29880
29842
  orbColors: t
29881
29843
  })
@@ -29907,8 +29869,8 @@ function Nk({ copy: e, orbColors: t, primaryColor: n, onYes: r, onLater: i, isMo
29907
29869
  children: u
29908
29870
  })] });
29909
29871
  }
29910
- function Pk({ copy: e, orbColors: t, primaryColor: n, onVoice: r, onText: i, onClose: a, isMobile: o, isClosing: s }) {
29911
- let c = n || Tk.green, l = Dk(c);
29872
+ function Nk({ copy: e, orbColors: t, primaryColor: n, onVoice: r, onText: i, onClose: a, isMobile: o, isClosing: s }) {
29873
+ let c = n || wk.green, l = Ek(c);
29912
29874
  return /* @__PURE__ */ _(Dm.div, {
29913
29875
  initial: {
29914
29876
  scale: 50 / 350,
@@ -29979,7 +29941,7 @@ function Pk({ copy: e, orbColors: t, primaryColor: n, onVoice: r, onText: i, onC
29979
29941
  children: /* @__PURE__ */ g("polyline", { points: "6 9 12 15 18 9" })
29980
29942
  })
29981
29943
  }),
29982
- /* @__PURE__ */ g(Mk, {
29944
+ /* @__PURE__ */ g(jk, {
29983
29945
  size: 72,
29984
29946
  orbColors: t
29985
29947
  }),
@@ -30048,9 +30010,13 @@ function Pk({ copy: e, orbColors: t, primaryColor: n, onVoice: r, onText: i, onC
30048
30010
  ]
30049
30011
  });
30050
30012
  }
30051
- function Fk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i, apiBaseUrl: a, chatId: s, historyRef: l, onMessageSync: u, voiceEndCounter: d }) {
30013
+ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i, apiBaseUrl: a, chatId: s, historyRef: l, onMessageSync: u, voiceEndCounter: d }) {
30014
+ c(() => (console.log("[FlowEngage:VoiceDebug] 🔵 VoiceMode MOUNTED"), () => console.log("[FlowEngage:VoiceDebug] 🔴 VoiceMode UNMOUNTED")), []);
30052
30015
  let [f, h] = m("idle"), [v, y] = m(!1), [b, x] = m(!1), S = p(null), C = p(""), w = p(async () => {}), T = p(!1), ee = p(!1), te = p(!1), ne = p(!1), re = p("minimized"), E = p(null), ie = p(null), ae = p(null), oe = p(0), D = p(!1), se = p("idle"), ce = p(!1), le = p(null), ue = p(null), de = p(!1), fe = o((e = "minimized") => {
30053
- re.current = e, ne.current = !0, queueMicrotask(() => {
30016
+ console.warn("[FlowEngage:VoiceDebug] 🛑 requestSessionShutdown called", {
30017
+ destination: e,
30018
+ stack: (/* @__PURE__ */ Error()).stack?.split("\n").slice(1, 4).join(" | ")
30019
+ }), re.current = e, ne.current = !0, queueMicrotask(() => {
30054
30020
  T.current || (T.current = !0, w.current?.());
30055
30021
  });
30056
30022
  }, [l]), pe = o(async (e) => {
@@ -30126,7 +30092,7 @@ function Fk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30126
30092
  }
30127
30093
  Pe();
30128
30094
  } });
30129
- let t = wk(Ck({
30095
+ let t = Ck(Sk({
30130
30096
  siteId: i || null,
30131
30097
  apiBaseUrl: a || null,
30132
30098
  getLastUserVoiceText: () => C.current,
@@ -30200,7 +30166,7 @@ function Fk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30200
30166
  let e = vO(l.current);
30201
30167
  e && Ae(i, e);
30202
30168
  } catch {}
30203
- if (jk(n, r)) {
30169
+ if (Ak(n, r)) {
30204
30170
  fe("minimized");
30205
30171
  return;
30206
30172
  }
@@ -30241,14 +30207,14 @@ function Fk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30241
30207
  }
30242
30208
  });
30243
30209
  if (e) {
30244
- me.endSession().catch(() => {});
30210
+ console.warn("[FlowEngage:VoiceDebug] ❌ cancelled=true after startSession resolved — killing session immediately"), me.endSession().catch(() => {});
30245
30211
  return;
30246
30212
  }
30247
30213
  o = me, S.current = me, h("listening");
30248
30214
  try {
30249
30215
  let e = typeof window < "u" ? window.location.href : "", r = "[]";
30250
30216
  try {
30251
- r = await t.list_page_forms();
30217
+ r = await t.flowengage_list_forms();
30252
30218
  } catch {}
30253
30219
  let a = u && !f ? `RESUMING PRIOR SESSION — DO NOT GREET. The visitor is continuing the same conversation after a page reload. Do not introduce yourself or re-state your capabilities. Wait silently until the visitor speaks; if you must speak first, briefly acknowledge where you left off in one short sentence.\nPrior transcript:\n${n?.transcript || ""}\n\n` : "";
30254
30220
  me.sendContextualUpdate(`${a}Page: ${e}. SiteId: ${i || "unknown"}. Forms: ${r}. Voice: call end_voice_session or say you are ending the session to stop.`);
@@ -30293,7 +30259,11 @@ function Fk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30293
30259
  }, 0)));
30294
30260
  }
30295
30261
  })(), () => {
30296
- e = !0, ne.current = !0;
30262
+ console.warn("[FlowEngage:VoiceDebug] ⚠️ useEffect CLEANUP fired — session will be killed", {
30263
+ agentId: r,
30264
+ siteId: i,
30265
+ apiBaseUrl: a
30266
+ }), e = !0, ne.current = !0;
30297
30267
  try {
30298
30268
  SD();
30299
30269
  } catch {}
@@ -30301,15 +30271,15 @@ function Fk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30301
30271
  He(i);
30302
30272
  } catch {}
30303
30273
  typeof window < "u" && (window.__fe_user_nav_during_speech = null), Ar(), le.current &&= (clearTimeout(le.current), null), ue.current &&= (clearTimeout(ue.current), null), ce.current = !1, de.current = !1, se.current = "idle", c && typeof window < "u" && (window.history.pushState = c), d && typeof window < "u" && window.removeEventListener("popstate", d);
30304
- let t = o || S.current, n = E.current, r = ie.current;
30274
+ let t = o || S.current, n = E.current, f = ie.current;
30305
30275
  if (t?.endSession?.().catch(() => {}), n && s && a) {
30306
- let e = r ? Math.round((Date.now() - r) / 1e3) : 0, t = JSON.stringify({
30276
+ let e = f ? Math.round((Date.now() - f) / 1e3) : 0, t = JSON.stringify({
30307
30277
  chatId: s,
30308
30278
  elevenLabsConversationId: n,
30309
30279
  duration: e,
30310
30280
  siteId: i
30311
- }), o = `${a}/api/voice/save-chat-recording`;
30312
- typeof navigator < "u" && navigator.sendBeacon && navigator.sendBeacon(o, new Blob([t], { type: "application/json" })) || fetch(o, {
30281
+ }), r = `${a}/api/voice/save-chat-recording`;
30282
+ typeof navigator < "u" && navigator.sendBeacon && navigator.sendBeacon(r, new Blob([t], { type: "application/json" })) || fetch(r, {
30313
30283
  method: "POST",
30314
30284
  headers: { "Content-Type": "application/json" },
30315
30285
  body: t,
@@ -30376,7 +30346,7 @@ function Fk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30376
30346
  },
30377
30347
  children: "Muted"
30378
30348
  }),
30379
- /* @__PURE__ */ g(Mk, {
30349
+ /* @__PURE__ */ g(jk, {
30380
30350
  size: 72,
30381
30351
  voiceState: f,
30382
30352
  isMuted: v,
@@ -30614,7 +30584,7 @@ function Fk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30614
30584
  ]
30615
30585
  });
30616
30586
  }
30617
- function Ik({ orbColors: e }) {
30587
+ function Fk({ orbColors: e }) {
30618
30588
  return /* @__PURE__ */ g("div", {
30619
30589
  style: {
30620
30590
  flexShrink: 0,
@@ -30624,13 +30594,13 @@ function Ik({ orbColors: e }) {
30624
30594
  alignItems: "center",
30625
30595
  justifyContent: "center"
30626
30596
  },
30627
- children: /* @__PURE__ */ g(Mk, {
30597
+ children: /* @__PURE__ */ g(jk, {
30628
30598
  size: 36,
30629
30599
  orbColors: e
30630
30600
  })
30631
30601
  });
30632
30602
  }
30633
- var Lk = () => /* @__PURE__ */ g("div", {
30603
+ var Ik = () => /* @__PURE__ */ g("div", {
30634
30604
  style: {
30635
30605
  display: "flex",
30636
30606
  marginBottom: "12px",
@@ -30660,7 +30630,7 @@ var Lk = () => /* @__PURE__ */ g("div", {
30660
30630
  } }, e))
30661
30631
  })
30662
30632
  });
30663
- function Rk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i, quickChatOptions: a, onQuickChatSelect: o, isMobile: s, chatHistory: l, isAiTyping: u, isAgentTyping: d, activeScreen: f, agentName: v, agentHeadshot: y, fallbackAgentName: b, input: x, setInput: S, onSubmit: C, isConversationEnded: w, isLoading: T, isRateLimited: ee, rateLimitMessage: te, selectedFile: ne, onFileSelect: re, onRemoveSelectedFile: E, attachmentError: ie, isUploadingAttachment: ae, requiresEmail: oe, emailInput: D, setEmailInput: se, emailError: ce, emailCaptureSuccess: le, replyContext: ue, setReplyContext: de, webRTCError: fe, micError: pe, setMicError: me, dismissCallError: he, activeCallId: ge, isCallMuted: _e, toggleCallMute: ve, endWebRTCCall: ye, formatCallDuration: be, callDurationSeconds: xe, isCallMinimized: Se, onExpand: Ce, onCollapse: we, onStartVoice: Te, onNewChat: Ee, showPoweredBy: De, getVisitorChatHistory: Oe, resumeChat: ke, isSessionRestoring: Ae, isClosing: je }) {
30633
+ function Lk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i, quickChatOptions: a, onQuickChatSelect: o, isMobile: s, chatHistory: l, isAiTyping: u, isAgentTyping: d, activeScreen: f, agentName: v, agentHeadshot: y, fallbackAgentName: b, input: x, setInput: S, onSubmit: C, isConversationEnded: w, isLoading: T, isRateLimited: ee, rateLimitMessage: te, selectedFile: ne, onFileSelect: re, onRemoveSelectedFile: E, attachmentError: ie, isUploadingAttachment: ae, requiresEmail: oe, emailInput: D, setEmailInput: se, emailError: ce, emailCaptureSuccess: le, replyContext: ue, setReplyContext: de, webRTCError: fe, micError: pe, setMicError: me, dismissCallError: he, activeCallId: ge, isCallMuted: _e, toggleCallMute: ve, endWebRTCCall: ye, formatCallDuration: be, callDurationSeconds: xe, isCallMinimized: Se, onExpand: Ce, onCollapse: we, onStartVoice: Te, onNewChat: Ee, showPoweredBy: De, getVisitorChatHistory: Oe, resumeChat: ke, isSessionRestoring: Ae, isClosing: je }) {
30664
30634
  let Me = l.length > 0, Ne = T || ee || w, Pe = !!ge, [Fe, Ie] = m(!1), [Le, Re] = m(!1), [ze, Be] = m([]), [Ve, He] = m(!1), O = p(null), [Ue, We] = m(() => typeof window < "u" ? window.visualViewport?.height ?? window.innerHeight : 600), [Ge, Ke] = m(0);
30665
30635
  c(() => {
30666
30636
  if (!s) return;
@@ -30796,7 +30766,7 @@ function Rk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
30796
30766
  justifyContent: "center",
30797
30767
  height: "40px"
30798
30768
  },
30799
- children: i ? /* @__PURE__ */ g(kk, {
30769
+ children: i ? /* @__PURE__ */ g(Ok, {
30800
30770
  logo: i,
30801
30771
  style: {
30802
30772
  height: "34px",
@@ -30809,7 +30779,7 @@ function Rk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
30809
30779
  height: "40px",
30810
30780
  flexShrink: 0
30811
30781
  },
30812
- children: /* @__PURE__ */ g(Ak, { title: e.chatTitle })
30782
+ children: /* @__PURE__ */ g(kk, { title: e.chatTitle })
30813
30783
  })
30814
30784
  }), /* @__PURE__ */ g("div", {
30815
30785
  style: {
@@ -31239,11 +31209,11 @@ function Rk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
31239
31209
  isLoading: T,
31240
31210
  isAgentTyping: d,
31241
31211
  setReplyContext: de,
31242
- TypingDots: Lk,
31212
+ TypingDots: Ik,
31243
31213
  primaryColor: n,
31244
31214
  agentHeadshot: y,
31245
31215
  agentDisplayName: v || b,
31246
- botAvatarNode: /* @__PURE__ */ g(Ik, { orbColors: t })
31216
+ botAvatarNode: /* @__PURE__ */ g(Fk, { orbColors: t })
31247
31217
  }) : Ae ? /* @__PURE__ */ _("div", {
31248
31218
  style: {
31249
31219
  flex: 1,
@@ -31284,7 +31254,7 @@ function Rk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
31284
31254
  padding: "28px 24px"
31285
31255
  },
31286
31256
  children: [
31287
- /* @__PURE__ */ g(Mk, {
31257
+ /* @__PURE__ */ g(jk, {
31288
31258
  size: 94,
31289
31259
  orbColors: t
31290
31260
  }),
@@ -31426,14 +31396,14 @@ function Rk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
31426
31396
  ]
31427
31397
  });
31428
31398
  }
31429
- function zk() {
31399
+ function Rk() {
31430
31400
  let { status: e, runtimeConfig: t, resolvedConfig: n, chatHistory: r, isOpen: i, activeScreen: a, isHumanHandled: s, agentName: l, agentHeadshot: u, visitorEmail: h, isAgentTyping: v, isAiTyping: y, isLoading: b, isRateLimited: x, rateLimitMessage: S, isConversationEnded: C, incomingCall: w, activeCallId: T, callConnectionState: ee, callConnectedAt: te, isCallMuted: ne, webRTCError: re, language: E, chatId: ie, historyRef: ae, onMessageSync: oe, sendMessage: D, uploadChatFile: se, openWidget: ce, captureVisitorEmail: le, setVoiceMode: ue, endConversation: de, startNewChat: me, acceptCall: he, rejectCall: ge, endWebRTCCall: _e, toggleCallMute: ve, dismissCallError: ye, startTyping: be, stopTyping: xe, updateTypingDraft: Se, getVisitorChatHistory: Ce, resumeChat: we, isSessionRestoring: Te, openToChatCounter: Ee, voiceEndCounter: De } = Ln();
31431
31401
  c(() => {
31432
31402
  try {
31433
31403
  pr();
31434
31404
  } catch {}
31435
31405
  }, []), c(() => {
31436
- Ee && A !== "text_chat" && A !== "call_screen" && (ue?.(!1), st("text_chat"));
31406
+ Ee && A !== "voice_mode" && A !== "text_chat" && A !== "call_screen" && (ue?.(!1), ot("text_chat"));
31437
31407
  }, [Ee]);
31438
31408
  let Oe = t?.widgetSettings || {}, ke = n?.widgetSettings || {}, Ae = {
31439
31409
  ...Oe.branding || {},
@@ -31448,7 +31418,7 @@ function zk() {
31448
31418
  small: 50,
31449
31419
  medium: 64,
31450
31420
  large: 80
31451
- }, Ve = Be[Ne.orbSize] || Be.small, He = Ne.position || "bottom-right", O = Ae.fallbackAgentName || "Agent", Ue = Ek(Le ?? Ne.chatBgColors), We = Ae.logo || Ae.logoUrl || null, Ge = E || "en", Ke = Oe.recommendations?.[Ge] || [], qe = (ke.recommendations?.[Ge] ?? Ke).filter((e) => String(e?.label ?? "").trim()).map((e, t) => ({
31421
+ }, Ve = Be[Ne.orbSize] || Be.small, He = Ne.position || "bottom-right", O = Ae.fallbackAgentName || "Agent", Ue = Tk(Le ?? Ne.chatBgColors), We = Ae.logo || Ae.logoUrl || null, Ge = E || "en", Ke = Oe.recommendations?.[Ge] || [], qe = (ke.recommendations?.[Ge] ?? Ke).filter((e) => String(e?.label ?? "").trim()).map((e, t) => ({
31452
31422
  id: e.key || `qr-${t}`,
31453
31423
  label: e.label,
31454
31424
  message: e.label,
@@ -31471,11 +31441,11 @@ function zk() {
31471
31441
  ]), rt = u && String(u).trim() || t?.ownerProfileImageUrl && String(t.ownerProfileImageUrl).trim() || null, it = r.some((e) => e.sender === "user"), at = f(() => {
31472
31442
  let e = r.findIndex((e) => e.sender === "user");
31473
31443
  return e === -1 ? !1 : r.slice(e + 1).some((e) => e.sender === "bot" || e.sender === "ai" || e.sender === "agent");
31474
- }, [r]), k = !h && it && at, ot = !!(ke._dashboardLivePreview || Oe._dashboardLivePreview), [A, st] = m(() => ot ? "text_chat" : "entry_prompt"), [ct, lt] = m(""), [ut, dt] = m(null), [ft, pt] = m(h || ""), [mt, ht] = m(""), [gt, j] = m(!1), [_t, vt] = m(0), [yt, bt] = m(null), [xt, St] = m(null), [Ct, wt] = m(""), [Tt, Et] = m(!1), [Dt, Ot] = m(!1), [kt, At] = m(!1), jt = p(null), Mt = p(!1);
31444
+ }, [r]), k = !!(ke._dashboardLivePreview || Oe._dashboardLivePreview), [A, ot] = m(() => k ? "text_chat" : "entry_prompt"), [st, ct] = m(""), [lt, ut] = m(null), [dt, ft] = m(h || ""), [pt, mt] = m(""), [ht, gt] = m(!1), [j, _t] = m(0), [vt, yt] = m(null), [bt, xt] = m(null), [St, Ct] = m(""), [wt, Tt] = m(!1), [Et, Dt] = m(!1), [Ot, kt] = m(!1), At = p(null), jt = p(!1), Mt = !h && it && at && A !== "voice_mode";
31475
31445
  d(() => {
31476
- if (e !== "ready" || Mt.current) return;
31477
- if (Mt.current = !0, !Ie) {
31478
- st("minimized_orb");
31446
+ if (e !== "ready" || jt.current) return;
31447
+ if (jt.current = !0, !Ie) {
31448
+ ot("minimized_orb");
31479
31449
  return;
31480
31450
  }
31481
31451
  let t = !1;
@@ -31484,22 +31454,22 @@ function zk() {
31484
31454
  } catch {}
31485
31455
  let n = Fe(), r = et ? je(et) : null, i = n || !!r?.transcript;
31486
31456
  if (t) {
31487
- ce?.({ notifyChatInitiated: !0 }), ue?.(!0), st("voice_mode");
31457
+ ce?.({ notifyChatInitiated: !0 }), ue?.(!0), ot("voice_mode");
31488
31458
  return;
31489
31459
  }
31490
31460
  if (Re()) {
31491
- ce?.({ notifyChatInitiated: !1 }), st("text_chat");
31461
+ ce?.({ notifyChatInitiated: !1 }), ot("text_chat");
31492
31462
  return;
31493
31463
  }
31494
- if (et) try {
31495
- Me(et);
31496
- } catch {}
31497
31464
  if (i) {
31498
- st("minimized_orb");
31465
+ ce?.({ notifyChatInitiated: !0 }), ue?.(!0), ot("voice_mode");
31499
31466
  return;
31500
31467
  }
31468
+ if (et) try {
31469
+ Me(et);
31470
+ } catch {}
31501
31471
  if (fe(et)) {
31502
- st("minimized_orb");
31472
+ ot("minimized_orb");
31503
31473
  return;
31504
31474
  }
31505
31475
  }, [e, r]);
@@ -31508,55 +31478,55 @@ function zk() {
31508
31478
  let e = window.matchMedia("(max-width: 640px)"), t = (e) => Pt(e.matches);
31509
31479
  return e.addEventListener("change", t), () => e.removeEventListener("change", t);
31510
31480
  }, []), c(() => {
31511
- pt(h || ""), h && ht("");
31481
+ ft(h || ""), h && mt("");
31512
31482
  }, [h]);
31513
31483
  let Ft = o(() => {
31514
- St(null), wt("");
31484
+ xt(null), Ct("");
31515
31485
  }, []), It = o((e) => {
31516
31486
  let t = qD(e);
31517
31487
  if (t) {
31518
- St(null), wt(t);
31488
+ xt(null), Ct(t);
31519
31489
  return;
31520
31490
  }
31521
- St(e), wt("");
31491
+ xt(e), Ct("");
31522
31492
  }, []);
31523
31493
  c(() => {
31524
31494
  if (!te || ee !== "connected") {
31525
- vt(0);
31495
+ _t(0);
31526
31496
  return;
31527
31497
  }
31528
31498
  let e = () => {
31529
31499
  let e = new Date(te).getTime();
31530
- isNaN(e) || vt(Math.max(0, Math.floor((Date.now() - e) / 1e3)));
31500
+ isNaN(e) || _t(Math.max(0, Math.floor((Date.now() - e) / 1e3)));
31531
31501
  };
31532
31502
  e();
31533
31503
  let t = window.setInterval(e, 1e3);
31534
31504
  return () => window.clearInterval(t);
31535
31505
  }, [te, ee]);
31536
31506
  let Lt = o(() => {
31537
- st("call_screen"), Ot(!1);
31507
+ ot("call_screen"), Dt(!1);
31538
31508
  }, []), Rt = o(() => {
31539
- st("text_chat"), Ot(!0);
31509
+ ot("text_chat"), Dt(!0);
31540
31510
  }, []);
31541
31511
  c(() => {
31542
31512
  let e = w?.callId || T || null;
31543
31513
  if (!e) {
31544
- jt.current = null;
31514
+ At.current = null;
31545
31515
  return;
31546
31516
  }
31547
31517
  if (w?.callId || ee === "connecting" || ee === "connected") {
31548
- if (A === "minimized_orb" && Dt && T && !w?.callId) {
31549
- jt.current = e;
31518
+ if (A === "minimized_orb" && Et && T && !w?.callId) {
31519
+ At.current = e;
31550
31520
  return;
31551
31521
  }
31552
- !(!i || A === "minimized_orb" || A === "voice_mode") && jt.current === e || (console.log("[FlowEngageWidget] forcing call UI to front", {
31522
+ !(!i || A === "minimized_orb" || A === "voice_mode") && At.current === e || (console.log("[FlowEngageWidget] forcing call UI to front", {
31553
31523
  forcedKey: e,
31554
31524
  isOpen: i,
31555
31525
  surface: A,
31556
31526
  hasIncomingCall: !!w?.callId,
31557
31527
  activeCallId: T,
31558
31528
  callConnectionState: ee
31559
- }), jt.current = e, A === "voice_mode" && ue?.(!1), ce?.(), Lt());
31529
+ }), At.current = e, A === "voice_mode" && ue?.(!1), ce?.(), Lt());
31560
31530
  }
31561
31531
  }, [
31562
31532
  T,
@@ -31568,31 +31538,31 @@ function zk() {
31568
31538
  ue,
31569
31539
  A
31570
31540
  ]), c(() => {
31571
- !w && !T && A === "call_screen" && st("text_chat");
31541
+ !w && !T && A === "call_screen" && ot("text_chat");
31572
31542
  }, [
31573
31543
  w,
31574
31544
  T,
31575
31545
  A
31576
31546
  ]), c(() => {
31577
- !T && Dt && Ot(!1);
31578
- }, [T, Dt]), c(() => {
31547
+ !T && Et && Dt(!1);
31548
+ }, [T, Et]), c(() => {
31579
31549
  if (!s || C) {
31580
31550
  Se?.(""), xe?.();
31581
31551
  return;
31582
31552
  }
31583
- if (!ct.trim() || xt) {
31553
+ if (!st.trim() || bt) {
31584
31554
  Se?.("");
31585
31555
  let e = window.setTimeout(() => xe?.(), 100);
31586
31556
  return () => window.clearTimeout(e);
31587
31557
  }
31588
31558
  be?.();
31589
- let e = window.setTimeout(() => Se?.(ct), 120), t = window.setTimeout(() => xe?.(), 1200);
31559
+ let e = window.setTimeout(() => Se?.(st), 120), t = window.setTimeout(() => xe?.(), 1200);
31590
31560
  return () => {
31591
31561
  window.clearTimeout(e), window.clearTimeout(t);
31592
31562
  };
31593
31563
  }, [
31594
- ct,
31595
- xt,
31564
+ st,
31565
+ bt,
31596
31566
  s,
31597
31567
  C,
31598
31568
  be,
@@ -31605,39 +31575,39 @@ function zk() {
31605
31575
  replyToSender: e.sender || null
31606
31576
  } : null, Bt = async (e) => {
31607
31577
  if (e.preventDefault(), C) return;
31608
- if (k) {
31609
- let e = ft.trim().toLowerCase();
31578
+ if (Mt) {
31579
+ let e = dt.trim().toLowerCase();
31610
31580
  if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)) {
31611
- ht("Please enter a valid email so we can continue helping you.");
31581
+ mt("Please enter a valid email so we can continue helping you.");
31612
31582
  return;
31613
31583
  }
31614
- await le(e), ht(""), j(!0), setTimeout(() => j(!1), 3e3);
31584
+ await le(e), mt(""), gt(!0), setTimeout(() => gt(!1), 3e3);
31615
31585
  return;
31616
31586
  }
31617
- let t = zt(ut);
31618
- if (!ct.trim() && !xt) return;
31619
- if (xt) {
31587
+ let t = zt(lt);
31588
+ if (!st.trim() && !bt) return;
31589
+ if (bt) {
31620
31590
  try {
31621
- Et(!0), wt("");
31622
- let e = await se(xt), n = e?.data || e, r = ct.trim() || `Shared file: ${YD(xt)}`;
31623
- lt(""), dt(null), Ft(), await D(r, "", t, {
31591
+ Tt(!0), Ct("");
31592
+ let e = await se(bt), n = e?.data || e, r = st.trim() || `Shared file: ${YD(bt)}`;
31593
+ ct(""), ut(null), Ft(), await D(r, "", t, {
31624
31594
  type: "file",
31625
31595
  metadata: {
31626
31596
  fileUrl: n?.fileUrl,
31627
- fileName: n?.fileName || xt.name,
31628
- fileType: n?.fileType || xt.type,
31629
- fileSize: n?.fileSize || xt.size
31597
+ fileName: n?.fileName || bt.name,
31598
+ fileType: n?.fileType || bt.type,
31599
+ fileSize: n?.fileSize || bt.size
31630
31600
  }
31631
31601
  });
31632
31602
  } catch (e) {
31633
- wt(e?.message || "Failed to upload the selected file.");
31603
+ Ct(e?.message || "Failed to upload the selected file.");
31634
31604
  } finally {
31635
- Et(!1);
31605
+ Tt(!1);
31636
31606
  }
31637
31607
  return;
31638
31608
  }
31639
- let n = ct.trim();
31640
- lt(""), dt(null), await D(n, "", t);
31609
+ let n = st.trim();
31610
+ ct(""), ut(null), await D(n, "", t);
31641
31611
  }, Vt = o(() => {
31642
31612
  r.length !== 0 && me?.();
31643
31613
  }, [r.length, me]), Ht = (e) => {
@@ -31685,10 +31655,10 @@ function zk() {
31685
31655
  right: "1.5rem",
31686
31656
  bottom: "1.5rem"
31687
31657
  }, Gt = o(() => {
31688
- A !== "minimized_orb" && (At(!0), setTimeout(() => {
31689
- st("minimized_orb"), At(!1), T && Ot(!0);
31658
+ A !== "minimized_orb" && (kt(!0), setTimeout(() => {
31659
+ ot("minimized_orb"), kt(!1), T && Dt(!0);
31690
31660
  }, 280));
31691
- }, [T, A]), Kt = () => st("connection_modal"), qt = () => {
31661
+ }, [T, A]), Kt = () => ot("connection_modal"), qt = () => {
31692
31662
  try {
31693
31663
  let e = window.AudioContext || window.webkitAudioContext;
31694
31664
  if (e) {
@@ -31696,9 +31666,9 @@ function zk() {
31696
31666
  t.resume().catch(() => {}), setTimeout(() => t.close().catch(() => {}), 3e3);
31697
31667
  }
31698
31668
  } catch {}
31699
- ce({ notifyChatInitiated: !0 }), ue?.(!0), st("voice_mode");
31669
+ ce({ notifyChatInitiated: !0 }), ue?.(!0), ot("voice_mode");
31700
31670
  }, Jt = () => {
31701
- ce({ notifyChatInitiated: !0 }), ue?.(!1), st("text_chat");
31671
+ ce({ notifyChatInitiated: !0 }), ue?.(!1), ot("text_chat");
31702
31672
  }, Yt = () => {
31703
31673
  ue?.(!1), Gt();
31704
31674
  };
@@ -31712,7 +31682,7 @@ function zk() {
31712
31682
  onWheel: (e) => e.stopPropagation(),
31713
31683
  onTouchMove: (e) => e.stopPropagation(),
31714
31684
  children: [
31715
- A === "entry_prompt" && /* @__PURE__ */ g(Nk, {
31685
+ A === "entry_prompt" && /* @__PURE__ */ g(Mk, {
31716
31686
  copy: Qe,
31717
31687
  orbColors: Le,
31718
31688
  primaryColor: ze,
@@ -31723,7 +31693,7 @@ function zk() {
31723
31693
  pe(et), Gt();
31724
31694
  },
31725
31695
  isMobile: Nt,
31726
- isClosing: kt
31696
+ isClosing: Ot
31727
31697
  }),
31728
31698
  A === "minimized_orb" && /* @__PURE__ */ _(Dm.div, {
31729
31699
  layoutId: "fe-main-orb",
@@ -31792,16 +31762,16 @@ function zk() {
31792
31762
  marginTop: "2px",
31793
31763
  whiteSpace: "nowrap"
31794
31764
  },
31795
- children: ee === "connected" ? `${Ht(_t)} with ${nt}` : `Tap to return to ${nt}`
31765
+ children: ee === "connected" ? `${Ht(j)} with ${nt}` : `Tap to return to ${nt}`
31796
31766
  })]
31797
31767
  })]
31798
- }), /* @__PURE__ */ g(Mk, {
31768
+ }), /* @__PURE__ */ g(jk, {
31799
31769
  size: Ve,
31800
31770
  orbColors: Le,
31801
31771
  onClick: T ? Lt : Ie ? Kt : Jt
31802
31772
  })]
31803
31773
  }),
31804
- A === "connection_modal" && /* @__PURE__ */ g(Pk, {
31774
+ A === "connection_modal" && /* @__PURE__ */ g(Nk, {
31805
31775
  copy: Qe,
31806
31776
  orbColors: Le,
31807
31777
  primaryColor: ze,
@@ -31809,9 +31779,9 @@ function zk() {
31809
31779
  onText: Jt,
31810
31780
  onClose: Gt,
31811
31781
  isMobile: Nt,
31812
- isClosing: kt
31782
+ isClosing: Ot
31813
31783
  }),
31814
- A === "voice_mode" && /* @__PURE__ */ g(Fk, {
31784
+ A === "voice_mode" && /* @__PURE__ */ g(Pk, {
31815
31785
  orbColors: Le,
31816
31786
  onEnterChat: Jt,
31817
31787
  onEndChat: Yt,
@@ -31827,7 +31797,7 @@ function zk() {
31827
31797
  incomingCall: w,
31828
31798
  activeCallId: T,
31829
31799
  callConnectionState: ee,
31830
- callDurationSeconds: _t,
31800
+ callDurationSeconds: j,
31831
31801
  isCallMuted: ne,
31832
31802
  agentName: nt,
31833
31803
  agentHeadshot: rt,
@@ -31842,8 +31812,8 @@ function zk() {
31842
31812
  orbColors: Le,
31843
31813
  chatHistory: r
31844
31814
  }),
31845
- A === "text_chat" && /* @__PURE__ */ g(Rk, {
31846
- isClosing: kt,
31815
+ A === "text_chat" && /* @__PURE__ */ g(Lk, {
31816
+ isClosing: Ot,
31847
31817
  copy: Qe,
31848
31818
  orbColors: Le,
31849
31819
  primaryColor: ze,
@@ -31859,35 +31829,35 @@ function zk() {
31859
31829
  agentName: nt,
31860
31830
  agentHeadshot: rt,
31861
31831
  fallbackAgentName: O,
31862
- input: ct,
31863
- setInput: lt,
31832
+ input: st,
31833
+ setInput: ct,
31864
31834
  onSubmit: Bt,
31865
31835
  isConversationEnded: C,
31866
31836
  isLoading: b,
31867
31837
  isRateLimited: x,
31868
31838
  rateLimitMessage: S,
31869
- selectedFile: xt,
31839
+ selectedFile: bt,
31870
31840
  onFileSelect: It,
31871
31841
  onRemoveSelectedFile: Ft,
31872
- attachmentError: Ct,
31873
- isUploadingAttachment: Tt,
31874
- requiresEmail: k,
31875
- emailInput: ft,
31876
- setEmailInput: pt,
31877
- emailError: mt,
31878
- emailCaptureSuccess: gt,
31879
- replyContext: ut,
31880
- setReplyContext: dt,
31842
+ attachmentError: St,
31843
+ isUploadingAttachment: wt,
31844
+ requiresEmail: Mt,
31845
+ emailInput: dt,
31846
+ setEmailInput: ft,
31847
+ emailError: pt,
31848
+ emailCaptureSuccess: ht,
31849
+ replyContext: lt,
31850
+ setReplyContext: ut,
31881
31851
  webRTCError: re,
31882
- micError: yt,
31883
- setMicError: bt,
31852
+ micError: vt,
31853
+ setMicError: yt,
31884
31854
  dismissCallError: ye,
31885
31855
  activeCallId: T,
31886
31856
  isCallMuted: ne,
31887
31857
  toggleCallMute: ve,
31888
31858
  endWebRTCCall: _e,
31889
31859
  formatCallDuration: Ht,
31890
- callDurationSeconds: _t,
31860
+ callDurationSeconds: j,
31891
31861
  onCollapse: Gt,
31892
31862
  onStartVoice: qt,
31893
31863
  onNewChat: Vt,
@@ -31905,7 +31875,7 @@ function zk() {
31905
31875
  }
31906
31876
  //#endregion
31907
31877
  //#region src/components/ErrorBoundary.jsx
31908
- var Bk = class extends e.Component {
31878
+ var zk = class extends e.Component {
31909
31879
  constructor(e) {
31910
31880
  super(e), this.state = { hasError: !1 };
31911
31881
  }
@@ -31920,4 +31890,4 @@ var Bk = class extends e.Component {
31920
31890
  }
31921
31891
  };
31922
31892
  //#endregion
31923
- export { lO as AnimatedOrb, Bk as ErrorBoundary, Rr as FlowEngageProvider, zk as FlowEngageWidget, Ln as useFlowEngage };
31893
+ export { lO as AnimatedOrb, zk as ErrorBoundary, Rr as FlowEngageProvider, Rk as FlowEngageWidget, Ln as useFlowEngage };