@flowengage/react-chatbot 6.0.25 → 6.0.26

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