@flowengage/react-chatbot 6.0.35 → 6.0.41

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) {
@@ -2118,11 +2118,14 @@ function er() {
2118
2118
  if (window.ng?.getComponent || document.querySelector("[ng-version]")) return "angular";
2119
2119
  if (window.__sveltekit_data || document.querySelector("[data-sveltekit-hydrate]")) return "sveltekit";
2120
2120
  if (document.querySelector("[data-astro-transition]")) return "astro";
2121
- let e = Array.from(document.body.children).filter((e) => {
2122
- let t = e.tagName?.toUpperCase();
2123
- return !(t === "SCRIPT" || t === "NOSCRIPT" || t === "LINK" || t === "STYLE" || e.id === "flowengage-root");
2124
- });
2125
- return e.length === 1 && e[0].id && (e[0].querySelector("[data-reactroot]") || e[0]._reactRootContainer || e[0].__vue_app__) ? "generic-spa" : null;
2121
+ if (window.__vite_plugin_react_preamble_installed__) return "vite-react-spa";
2122
+ let e = Array.from(document.body.children);
2123
+ for (let t of e) {
2124
+ if (t.id === "flowengage-root") continue;
2125
+ let e = t.tagName?.toUpperCase();
2126
+ if (!(e === "SCRIPT" || e === "NOSCRIPT" || e === "LINK" || e === "STYLE") && (t.querySelector?.("[data-reactroot]") || t._reactRootContainer || t.__vue_app__ || !(Array.from(t.childNodes).filter((e) => e.nodeType === 3).map((e) => e.textContent.trim()).join("").length > 200) && Object.getOwnPropertyNames(t).some((e) => e.startsWith("__reactFiber$") || e.startsWith("__reactContainer$")))) return "generic-spa";
2127
+ }
2128
+ return null;
2126
2129
  }
2127
2130
  var tr = "data-fe-swap-css";
2128
2131
  function nr() {
@@ -2836,7 +2839,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
2836
2839
  let i = f(() => e ? {
2837
2840
  ...t || {},
2838
2841
  siteId: e
2839
- } : t || null, [e, t]), [a, s] = m(0), [l, u] = m("booting"), [d, h] = m(null), [_, v] = m(null), [y, b] = m(""), [x, S] = m([]), [C, w] = m(ve().isOpen), [T, te] = m(ve().activeScreen), [ne, re] = m(ve().isHumanHandled), [E, D] = m(ve().agentName), [se, de] = m(ve().agentHeadshot), [fe, pe] = m(() => be(i?.siteId)), [me, Se] = m(!1), [Ce, we] = m(!1), [Ee, De] = m("idle"), [Oe, ke] = m(!1), [Ae, je] = m(!1), [Me, Ne] = m(""), [Fe, Ie] = m(!1), [Le, Re] = m(0), [ze, Be] = m(0), [Ve, He] = m(!1), [O, Ue] = m(null), [qe, Je] = m(null), [Ye, Xe] = m("idle"), [Ze, Qe] = m(null), [$e, et] = m(!1), [tt, nt] = m(""), [rt, it] = m(!1), at = p(null), k = p(null), 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({
2840
2843
  notifyRouteChange: () => {},
2841
2844
  cleanup: () => {}
2842
2845
  }), kt = o((e = {}) => {
@@ -2901,7 +2904,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
2901
2904
  if (!(!t?.connected || !n || j.current)) {
2902
2905
  j.current = !0, t.emit("call:connected", {
2903
2906
  callId: n,
2904
- chatId: A.current,
2907
+ chatId: ot.current,
2905
2908
  connectedAt: e
2906
2909
  });
2907
2910
  try {
@@ -2968,7 +2971,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
2968
2971
  if (!t || !n?.connected || !r || !e.callId) {
2969
2972
  console.log("[FlowEngageProvider] deferring remote offer until peer/socket ready", {
2970
2973
  callId: e.callId,
2971
- chatId: A.current,
2974
+ chatId: ot.current,
2972
2975
  hasPeerConnection: !!t,
2973
2976
  socketConnected: !!n?.connected,
2974
2977
  hasOffer: !!r
@@ -2981,7 +2984,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
2981
2984
  })), pt.current.length > 0) {
2982
2985
  console.log("[FlowEngageProvider] flushing queued agent ICE candidates after remote offer", {
2983
2986
  callId: e.callId,
2984
- chatId: A.current,
2987
+ chatId: ot.current,
2985
2988
  queuedCount: pt.current.length
2986
2989
  });
2987
2990
  for (let e of pt.current) await t.addIceCandidate(new RTCIceCandidate(e));
@@ -2991,7 +2994,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
2991
2994
  await t.setLocalDescription(i), n.emit("call:answer", {
2992
2995
  callId: e.callId,
2993
2996
  sdpAnswer: i.sdp,
2994
- chatId: A.current
2997
+ chatId: ot.current
2995
2998
  });
2996
2999
  };
2997
3000
  c(() => {
@@ -3017,8 +3020,8 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3017
3020
  if (!e) return;
3018
3021
  let a = t.siteId, o = he(a), s = Te(a), c = "";
3019
3022
  try {
3020
- let e = ot.current, r = st.current;
3021
- 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({
3022
3025
  apiBaseUrl: t.apiBaseUrl,
3023
3026
  userId: n.userId,
3024
3027
  siteId: a,
@@ -3031,7 +3034,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3031
3034
  } catch (e) {
3032
3035
  console.warn("[FlowEngageProvider] resolve-session failed, reusing persisted or ephemeral chat id", e?.message || e), c = o || ue(), _e(a, c);
3033
3036
  }
3034
- A.current = c;
3037
+ ot.current = c;
3035
3038
  let l = Ke({
3036
3039
  apiBaseUrl: t.apiBaseUrl,
3037
3040
  userId: n.userId,
@@ -3177,7 +3180,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3177
3180
  if (!lt.current || !lt.current.remoteDescription) {
3178
3181
  console.log("[FlowEngageProvider] queueing agent ICE candidate until peer/remote description is ready", {
3179
3182
  callId: e.callId,
3180
- chatId: e.chatId || A.current,
3183
+ chatId: e.chatId || ot.current,
3181
3184
  queueSize: pt.current.length + 1
3182
3185
  }), pt.current.push(t);
3183
3186
  return;
@@ -3252,7 +3255,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3252
3255
  a
3253
3256
  ]), c(() => () => {
3254
3257
  if (Fe && !Tt.current && wt.current.length > 0) {
3255
- let e = A.current, t = wt.current, n = k.current;
3258
+ let e = ot.current, t = wt.current, n = k.current;
3256
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);
3257
3260
  }
3258
3261
  }, [Fe, _]);
@@ -3262,7 +3265,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3262
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);
3263
3266
  }, [C, y]), c(() => {
3264
3267
  let e = () => {
3265
- let e = A.current, t = k.current;
3268
+ let e = ot.current, t = k.current;
3266
3269
  !e || !t || typeof navigator > "u" || t.beaconWidgetClosed?.(e) || t.updateChatStatus(e, "widget_closed").catch(() => {});
3267
3270
  };
3268
3271
  return window.addEventListener("pagehide", e), () => window.removeEventListener("pagehide", e);
@@ -3445,10 +3448,10 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3445
3448
  }
3446
3449
  }, qt = async (e) => {
3447
3450
  let t = Nt(e);
3448
- if (!t || !k.current || !A.current) return t;
3451
+ if (!t || !k.current || !ot.current) return t;
3449
3452
  try {
3450
3453
  await k.current.trackVisitor({
3451
- chatId: A.current,
3454
+ chatId: ot.current,
3452
3455
  currentPagePath: typeof window < "u" && window.location.pathname || "/",
3453
3456
  email: t
3454
3457
  });
@@ -3608,7 +3611,7 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3608
3611
  At
3609
3612
  ]), c(() => {
3610
3613
  let e = () => {
3611
- let e = A.current, t = k.current;
3614
+ let e = ot.current, t = k.current;
3612
3615
  if (!t || !e) return;
3613
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) {
3614
3617
  t.beaconEndWebRTCCall(mt.current, e);
@@ -3623,9 +3626,9 @@ function Rr({ siteId: e, config: t, children: n, language: r = "en" }) {
3623
3626
  }, []);
3624
3627
  let nn = o(() => {
3625
3628
  let e = i?.siteId;
3626
- ge(e), 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);
3627
3630
  }, [i?.siteId]), rn = o((e) => {
3628
- 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);
3629
3632
  }, [i?.siteId]), an = f(() => ({
3630
3633
  status: l,
3631
3634
  error: d,
@@ -29265,7 +29268,12 @@ function vk(e) {
29265
29268
  let t = e.url ?? e.target_url ?? e.page_url ?? e.pageUrl ?? e.link ?? e.href ?? e.path;
29266
29269
  return t == null ? null : String(t).trim() || null;
29267
29270
  }
29268
- function yk(e, t, n) {
29271
+ function yk(e) {
29272
+ if (!e || typeof e != "object") return null;
29273
+ let t = e.query ?? e.q ?? e.search ?? e.text ?? e.keywords;
29274
+ return t == null ? null : String(t).trim() || null;
29275
+ }
29276
+ function bk(e, t, n) {
29269
29277
  if (!n?.skipScroll) try {
29270
29278
  e.scrollIntoView({
29271
29279
  block: "center",
@@ -29320,7 +29328,7 @@ function yk(e, t, n) {
29320
29328
  } catch {}
29321
29329
  return !0;
29322
29330
  }
29323
- function bk() {
29331
+ function xk() {
29324
29332
  let e = {};
29325
29333
  document.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach((t) => {
29326
29334
  if (t.id) return;
@@ -29335,11 +29343,11 @@ function bk() {
29335
29343
  e[r] = !0, t.id = r;
29336
29344
  });
29337
29345
  }
29338
- function xk() {
29346
+ function Sk() {
29339
29347
  let e = document.querySelector("main, [role='main'], article") || document.body;
29340
29348
  return Array.from(e.querySelectorAll("h1, h2, h3")).filter((e) => !e.closest("#flowengage-root, .flowengage-shell, .flowengage-widget-root")).map((e) => e.textContent.replace(/\s+/g, " ").trim()).filter((e) => e.length > 2 && e.length < 200).slice(0, 12);
29341
29349
  }
29342
- function Sk(e) {
29350
+ function Ck(e) {
29343
29351
  let t = e.siteId || null, n = (e.apiBaseUrl || "").replace(/\/$/, ""), r = typeof e.getLastUserVoiceText == "function" ? e.getLastUserVoiceText : null, i = [], a = {
29344
29352
  flowengage_navigate: async (n) => {
29345
29353
  $("flowengage_navigate ▶ raw parameters:", n);
@@ -29370,7 +29378,7 @@ function Sk(e) {
29370
29378
  siteId: t,
29371
29379
  apiBaseUrl: e.apiBaseUrl
29372
29380
  })) {
29373
- let e = `Page "${a}" could not be verified. Try a different URL from your known site pages, or ask the visitor to clarify which page they want.`;
29381
+ let e = `Page "${a}" could not be verified. Call flowengage_search with keywords from the topic to find the correct URL, then navigate to the URL from the search results.`;
29374
29382
  return $("flowengage_navigate ✖ blocked", e), e;
29375
29383
  }
29376
29384
  try {
@@ -29397,11 +29405,11 @@ function Sk(e) {
29397
29405
  for (; Date.now() < t && !(typeof window < "u" && window.location.pathname === e);) await new Promise((e) => setTimeout(e, 80));
29398
29406
  let n = typeof window < "u" ? window.location.pathname : e, r = typeof window < "u" ? window.location.href : a, i = n === e, o = (n.split("/").filter(Boolean).pop() || "").replace(/[-_]/g, " ").replace(/\b\w/g, (e) => e.toUpperCase()) || "Home";
29399
29407
  $("flowengage_navigate → SPA nav complete. target:", e, "actual:", n);
29400
- let s = [], c = Date.now() + 8e3;
29401
- for (; Date.now() < c && (await new Promise((e) => setTimeout(e, 250)), s = xk(), !(s.length >= 1)););
29402
- bk(), $("flowengage_navigate → page headings collected:", s);
29403
- let l = s.length ? s.join(" | ") : "none", u = s.length ? "These exact heading strings are available for flowengage_highlight once the visitor approves a walkthrough." : "No DOM headings collected — if the visitor approves a walkthrough, call flowengage_get_current_page first to get fresh headings.";
29404
- return i ? (wr(), `OK_NAVIGATE_SPA. Visitor is now on: ${r} (page: "${o}") | Section headings: ${l}. ${u} REQUIRED: (1) Speak 2-3 natural sentences introducing the ${o} page what it is and what the visitor will find here. (2) Ask: "Would you like me to walk you through this page in detail?" (3) Wait for their answer. ONLY call flowengage_highlight if they say yes. DO NOT highlight sections before the visitor approves.`) : (wr(), `OK_NAVIGATE_SPA. CURRENT PAGE IS: ${r} (page: "${o}") | Section headings: ${l}. ${u} REQUIRED: (1) Speak 2-3 natural sentences introducing the ${o} page. (2) Ask: "Would you like me to walk you through this page?" (3) Wait for the visitor's answer before calling flowengage_highlight.`);
29408
+ let s = [], c = Date.now() + 12e3;
29409
+ for (; Date.now() < c && (await new Promise((e) => setTimeout(e, 300)), s = Sk(), !(s.length >= 1)););
29410
+ xk(), $("flowengage_navigate → page headings collected:", s);
29411
+ let l = s.length ? s.join(" | ") : "none", u = s.length ? "Use ONLY these exact heading strings for flowengage_highlight never invent or abbreviate." : "No headings collected yet call flowengage_get_current_page immediately (no speech) to get the live headings before speaking or highlighting.";
29412
+ return i ? (wr(), `OK_NAVIGATE_SPA. Visitor is now on: ${r} (page: "${o}") | Section headings: ${l}. ${u} Speak 2-3 sentences about this page from your knowledge, then STOP. Do NOT highlight. Do NOT walk through sections. Wait for the visitor to respond. Only do a highlighted walkthrough if they explicitly ask for one.`) : (wr(), `OK_NAVIGATE_SPA. CURRENT PAGE IS: ${r} (page: "${o}") | Section headings: ${l}. ${u} Speak 2-3 sentences about this page from your knowledge, then STOP. Do NOT highlight or walk through sections. Describe THIS page only do not mention the page you tried to navigate to.`);
29405
29413
  } catch {}
29406
29414
  return "OK_NAVIGATE_RELOADING. Navigating to the page now; the voice session will resume automatically on the new page. When the session resumes, immediately introduce the new page and continue guiding the visitor — do not wait for the user to speak first.";
29407
29415
  } catch (e) {
@@ -29423,15 +29431,15 @@ function Sk(e) {
29423
29431
  if (Date.now() - e.ts >= 3e4) window.__fe_user_nav_during_speech = null;
29424
29432
  else return $("flowengage_highlight ✖ blocked — user navigated during speech", e), `NAV_CHANGED: The visitor navigated from "${e.fromPageName}" to "${e.toPageName}" (current path: ${t}) while you were speaking. STOP the current walkthrough immediately. DO NOT call flowengage_highlight again. Say out loud: "I see you've navigated to the ${e.toPageName} page — do you want me to continue what I was explaining, or shall I guide you through this page?" Wait for the visitor's answer before doing anything else.`;
29425
29433
  }
29426
- bk();
29434
+ xk();
29427
29435
  let i = hr(n || null, r || null);
29428
29436
  if (!i && r) {
29429
29437
  let e = Date.now() + 600;
29430
- for (; !i && Date.now() < e;) await new Promise((e) => setTimeout(e, 50)), bk(), i = hr(null, r);
29438
+ for (; !i && Date.now() < e;) await new Promise((e) => setTimeout(e, 50)), xk(), i = hr(null, r);
29431
29439
  }
29432
29440
  if (!i) {
29433
29441
  $("flowengage_highlight ✖ no element for:", r || n);
29434
- let e = xk(), t = e.length ? `Page headings: ${e.join(" | ")}. Use one of these exact strings for section_text.` : "No headings found — skip highlight and continue.";
29442
+ let e = Sk(), t = e.length ? `Page headings: ${e.join(" | ")}. Use one of these exact strings for section_text.` : "No headings found — skip highlight and continue.";
29435
29443
  return `HIGHLIGHT_NOT_FOUND: "${r || n}" on the current page. ${t}`;
29436
29444
  }
29437
29445
  return xD(i), $("flowengage_highlight ✓", r || n), `OK_HIGHLIGHT: "${r || n}". WALKTHROUGH: continue immediately to the next section — do NOT pause between sections.`;
@@ -29459,6 +29467,38 @@ function Sk(e) {
29459
29467
  return $("flowengage_read_content ✖", e.message), `Could not read page content: ${e.message}`;
29460
29468
  }
29461
29469
  },
29470
+ flowengage_search: async (e) => {
29471
+ $("flowengage_search ▶", e);
29472
+ let r = yk(mk(e));
29473
+ if ($("flowengage_search · query:", r, "siteId:", t, "apiBase:", n || "(empty)"), !r) return $("flowengage_search ✖ missing query"), "Missing query parameter.";
29474
+ if (!t) return $("flowengage_search ✖ no siteId"), "Site is not configured for search.";
29475
+ if (!n) return $("flowengage_search ✖ no api base"), "API base URL is missing; cannot search.";
29476
+ CO(`Searching${r ? ` for "${r}"` : ""}…`, { spinner: !0 });
29477
+ try {
29478
+ let e = `${n}/api/site-tools/search`;
29479
+ $("flowengage_search → POST", e);
29480
+ let i = await fetch(e, {
29481
+ method: "POST",
29482
+ headers: { "Content-Type": "application/json" },
29483
+ body: JSON.stringify({
29484
+ siteId: t,
29485
+ query: r,
29486
+ currentUrl: typeof window < "u" ? window.location.href : ""
29487
+ })
29488
+ }), a = await i.json();
29489
+ if ($("flowengage_search · HTTP", i.status, "success:", a.success), !a.success) {
29490
+ let e = a.error || "Search failed.";
29491
+ return $("flowengage_search ✖", e), e;
29492
+ }
29493
+ let o = a.results || [];
29494
+ return $("flowengage_search ✓", `${o.length} result(s)`, o.slice(0, 3).map((e) => e?.url || e)), o.length ? `SEARCH_RESULTS: ${JSON.stringify(o)}. MANDATORY: Do NOT call flowengage_navigate now. Speak the answer from these results in 2-3 sentences. Then ask the visitor if they want to go to a relevant page — e.g. "Would you like me to take you to that page?" Only navigate if they say yes.` : "SEARCH_RESULTS: No results found. Answer from your knowledge base.";
29495
+ } catch (e) {
29496
+ let t = `Search error: ${e.message || "network"}`;
29497
+ return $("flowengage_search ✖", t), t;
29498
+ } finally {
29499
+ wO(600);
29500
+ }
29501
+ },
29462
29502
  flowengage_page_content: async (e) => {
29463
29503
  $("flowengage_page_content ▶", e);
29464
29504
  let r = mk(e), i = r?.url || r?.page_url || "";
@@ -29494,12 +29534,12 @@ function Sk(e) {
29494
29534
  flowengage_end_session: async () => ($("flowengage_end_session ▶"), typeof e.requestEndSession == "function" && e.requestEndSession(), "Voice session is ending."),
29495
29535
  flowengage_get_current_page: async () => {
29496
29536
  if ($("flowengage_get_current_page ▶"), typeof window > "u") return "Cannot determine current page (no browser context).";
29497
- let e = window.location.href, t = window.location.pathname, n = document.title || "", r = xk(), i = r.length ? r.join(" | ") : "none";
29537
+ let e = window.location.href, t = window.location.pathname, n = document.title || "", r = Sk(), i = r.length ? r.join(" | ") : "none";
29498
29538
  return $("flowengage_get_current_page ✓", {
29499
29539
  url: e,
29500
29540
  path: t,
29501
29541
  title: n
29502
- }), $("flowengage_get_current_page → page headings collected:", r), `CURRENT_PAGE. URL: ${e} | Path: ${t} | Title: ${n} | Section headings: ${i}. 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}. These are the EXACT heading strings — use them verbatim for every flowengage_highlight call. If the visitor has already requested a walkthrough, proceed immediately with the full highlighted walkthrough using these headings. If not, give 1-2 sentences about the page and wait.`;
29503
29543
  },
29504
29544
  flowengage_list_forms: async () => {
29505
29545
  let e = XO(), t = ZO();
@@ -29525,12 +29565,12 @@ function Sk(e) {
29525
29565
  CO(`Filling ${String(t)}...`, { spinner: !0 });
29526
29566
  let a = YO(), o = ck(a, String(t), r);
29527
29567
  if (o.length) {
29528
- for (let [e, t] of o.entries()) jO(t), await LO(t), yk(t, r, { skipScroll: e > 0 }), MO(t), await HO(120);
29568
+ for (let [e, t] of o.entries()) jO(t), await LO(t), bk(t, r, { skipScroll: e > 0 }), MO(t), await HO(120);
29529
29569
  i = o, n.push(String(t));
29530
29570
  continue;
29531
29571
  }
29532
29572
  let s = dk(a, String(t));
29533
- s ||= nk(a, String(t)), s ||= rk(a, String(t), r), s && (jO(s), await LO(s), yk(s, r), MO(s), await HO(120), i = [s], n.push(String(t)));
29573
+ s ||= nk(a, String(t)), s ||= rk(a, String(t), r), s && (jO(s), await LO(s), bk(s, r), MO(s), await HO(120), i = [s], n.push(String(t)));
29534
29574
  }
29535
29575
  if (!n.length) return $("flowengage_fill_form ✖ no matches"), "Could not match any fields. Call flowengage_list_forms and use field_key values that match placeholder, label, name, or id (e.g. Enter Website URL). Ensure the form is on the page, not the chat panel.";
29536
29576
  let a = `OK_FILLED: ${n.join(", ")}`;
@@ -29587,6 +29627,7 @@ function Sk(e) {
29587
29627
  return {
29588
29628
  ...a,
29589
29629
  highlightOnPage: a.flowengage_highlight,
29630
+ searchSiteContent: a.flowengage_search,
29590
29631
  getPageContent: a.flowengage_page_content,
29591
29632
  endVoiceSession: a.flowengage_end_session,
29592
29633
  listPageForms: a.flowengage_list_forms,
@@ -29596,26 +29637,24 @@ function Sk(e) {
29596
29637
  }
29597
29638
  //#endregion
29598
29639
  //#region src/utils/wrapVoiceToolsForLogging.js
29599
- function Ck(e, { onToolStart: t, onToolEnd: n } = {}) {
29600
- return !e || typeof e != "object" ? e : Object.fromEntries(Object.entries(e).map(([e, r]) => [e, async (i) => {
29601
- let a = Rn();
29602
- a ? console.log("[FlowEngage:voice-tool] ▶", e, i) : console.info(`[FlowEngage] voice tool » ${e}`), t?.();
29603
- let o;
29640
+ function wk(e) {
29641
+ return !e || typeof e != "object" ? e : Object.fromEntries(Object.entries(e).map(([e, t]) => [e, async (n) => {
29642
+ let r = Rn();
29643
+ r ? console.log("[FlowEngage:voice-tool] ▶", e, n) : console.info(`[FlowEngage] voice tool » ${e}`);
29644
+ let i;
29604
29645
  try {
29605
- o = await r(i);
29646
+ i = await t(n);
29606
29647
  } catch (t) {
29607
29648
  let n = `Tool error: ${t?.message || String(t)}`;
29608
29649
  return console.error(`[FlowEngage] voice tool ${e} threw:`, t), n;
29609
- } finally {
29610
- n?.();
29611
29650
  }
29612
- let s = typeof o == "string" ? o.length > 220 ? `${o.slice(0, 220)}…` : o : String(o);
29613
- return a ? console.log("[FlowEngage:voice-tool] ◀", e, s) : console.info(`[FlowEngage] voice tool « ${e}:`, s), o;
29651
+ let a = typeof i == "string" ? i.length > 220 ? `${i.slice(0, 220)}…` : i : String(i);
29652
+ return r ? console.log("[FlowEngage:voice-tool] ◀", e, a) : console.info(`[FlowEngage] voice tool « ${e}:`, a), i;
29614
29653
  }]));
29615
29654
  }
29616
29655
  //#endregion
29617
29656
  //#region src/components/FlowEngageWidget.jsx
29618
- var wk = {
29657
+ var Tk = {
29619
29658
  blue: "#135bd8",
29620
29659
  red: "#ef334b",
29621
29660
  yellow: "#ffbd2e",
@@ -29623,7 +29662,7 @@ var wk = {
29623
29662
  highlight: "rgba(255,255,255,0.9)",
29624
29663
  green: "#10b981"
29625
29664
  };
29626
- function Tk(e) {
29665
+ function Ek(e) {
29627
29666
  if (!Array.isArray(e) || e.length < 2) return "linear-gradient(145deg, #dce8f022 0%, #e8dff522 45%, #f5e0e022 100%), #f7f8fa";
29628
29667
  let [t, n, r] = e;
29629
29668
  return e.length >= 3 && r ? [
@@ -29637,12 +29676,12 @@ function Tk(e) {
29637
29676
  "#f7f8fa"
29638
29677
  ].join(", ");
29639
29678
  }
29640
- function Ek(e) {
29679
+ function Dk(e) {
29641
29680
  if (!e || typeof e != "string") return "#1a1a1a";
29642
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;
29643
29682
  return .2126 * o(r) + .7152 * o(i) + .0722 * o(a) > .179 ? "#1a1a1a" : "#ffffff";
29644
29683
  }
29645
- function Dk(t) {
29684
+ function Ok(t) {
29646
29685
  let [n, r] = e.useState(null), i = typeof t == "string" ? t.trim() : "";
29647
29686
  return e.useEffect(() => {
29648
29687
  if (!i) {
@@ -29660,8 +29699,8 @@ function Dk(t) {
29660
29699
  };
29661
29700
  }, [i]), n;
29662
29701
  }
29663
- function Ok({ logo: t, style: n }) {
29664
- let r = Dk(typeof t == "string" ? t : null);
29702
+ function kk({ logo: t, style: n }) {
29703
+ let r = Ok(typeof t == "string" ? t : null);
29665
29704
  if (!t) return null;
29666
29705
  if (typeof t == "string") return r ? /* @__PURE__ */ g("img", {
29667
29706
  src: r,
@@ -29686,7 +29725,7 @@ function Ok({ logo: t, style: n }) {
29686
29725
  children: i
29687
29726
  }) : null;
29688
29727
  }
29689
- function kk({ title: e }) {
29728
+ function Ak({ title: e }) {
29690
29729
  return /* @__PURE__ */ g("div", {
29691
29730
  style: {
29692
29731
  width: "100%",
@@ -29704,18 +29743,18 @@ function kk({ title: e }) {
29704
29743
  children: String(e || "FE").split(/\s+/).filter(Boolean).slice(0, 2).map((e) => e[0]?.toUpperCase() || "").join("") || "FE"
29705
29744
  });
29706
29745
  }
29707
- function Ak(e, t) {
29746
+ function jk(e, t) {
29708
29747
  let n = (t || "").trim();
29709
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;
29710
29749
  }
29711
- function jk({ orbColors: e, ...t }) {
29750
+ function Mk({ orbColors: e, ...t }) {
29712
29751
  return /* @__PURE__ */ g(lO, {
29713
29752
  colors: e,
29714
29753
  ...t
29715
29754
  });
29716
29755
  }
29717
- function Mk({ copy: e, orbColors: t, primaryColor: n, onYes: r, onLater: i, isMobile: a, isClosing: o }) {
29718
- 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", {
29719
29758
  style: {
29720
29759
  display: "flex",
29721
29760
  alignItems: a ? "flex-end" : "center",
@@ -29836,7 +29875,7 @@ function Mk({ copy: e, orbColors: t, primaryColor: n, onYes: r, onLater: i, isMo
29836
29875
  delay: 0
29837
29876
  },
29838
29877
  style: { flexShrink: 0 },
29839
- children: /* @__PURE__ */ g(jk, {
29878
+ children: /* @__PURE__ */ g(Mk, {
29840
29879
  size: l,
29841
29880
  orbColors: t
29842
29881
  })
@@ -29868,8 +29907,8 @@ function Mk({ copy: e, orbColors: t, primaryColor: n, onYes: r, onLater: i, isMo
29868
29907
  children: u
29869
29908
  })] });
29870
29909
  }
29871
- function Nk({ copy: e, orbColors: t, primaryColor: n, onVoice: r, onText: i, onClose: a, isMobile: o, isClosing: s }) {
29872
- 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);
29873
29912
  return /* @__PURE__ */ _(Dm.div, {
29874
29913
  initial: {
29875
29914
  scale: 50 / 350,
@@ -29940,7 +29979,7 @@ function Nk({ copy: e, orbColors: t, primaryColor: n, onVoice: r, onText: i, onC
29940
29979
  children: /* @__PURE__ */ g("polyline", { points: "6 9 12 15 18 9" })
29941
29980
  })
29942
29981
  }),
29943
- /* @__PURE__ */ g(jk, {
29982
+ /* @__PURE__ */ g(Mk, {
29944
29983
  size: 72,
29945
29984
  orbColors: t
29946
29985
  }),
@@ -30009,16 +30048,12 @@ function Nk({ copy: e, orbColors: t, primaryColor: n, onVoice: r, onText: i, onC
30009
30048
  ]
30010
30049
  });
30011
30050
  }
30012
- function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i, apiBaseUrl: a, chatId: s, historyRef: l, onMessageSync: u, voiceEndCounter: d }) {
30013
- c(() => (console.log("[FlowEngage:VoiceDebug] 🔵 VoiceMode MOUNTED"), () => console.log("[FlowEngage:VoiceDebug] 🔴 VoiceMode UNMOUNTED")), []);
30014
- 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 = p(!1), pe = o((e = "minimized") => {
30015
- console.warn("[FlowEngage:VoiceDebug] 🛑 requestSessionShutdown called", {
30016
- destination: e,
30017
- stack: (/* @__PURE__ */ Error()).stack?.split("\n").slice(1, 4).join(" | ")
30018
- }), re.current = e, ne.current = !0, queueMicrotask(() => {
30051
+ function Fk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i, apiBaseUrl: a, chatId: s, historyRef: l, onMessageSync: u, voiceEndCounter: d }) {
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") => {
30053
+ re.current = e, ne.current = !0, queueMicrotask(() => {
30019
30054
  T.current || (T.current = !0, w.current?.());
30020
30055
  });
30021
- }, [l]), me = o(async (e) => {
30056
+ }, [l]), pe = o(async (e) => {
30022
30057
  ne.current = !0;
30023
30058
  try {
30024
30059
  SD();
@@ -30054,10 +30089,10 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30054
30089
  s,
30055
30090
  a
30056
30091
  ]);
30057
- return w.current = () => me(re.current === "chat" ? t : n), c(() => {
30092
+ return w.current = () => pe(re.current === "chat" ? t : n), c(() => {
30058
30093
  ee.current = v;
30059
30094
  }, [v]), c(() => {
30060
- d && pe("chat");
30095
+ d && fe("chat");
30061
30096
  }, [d]), c(() => {
30062
30097
  let e = !1, o = null, c = null, d = null;
30063
30098
  return (async () => {
@@ -30091,21 +30126,14 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30091
30126
  }
30092
30127
  Pe();
30093
30128
  } });
30094
- let t = Ck(Sk({
30129
+ let t = wk(Ck({
30095
30130
  siteId: i || null,
30096
30131
  apiBaseUrl: a || null,
30097
30132
  getLastUserVoiceText: () => C.current,
30098
30133
  requestEndSession: () => {
30099
30134
  D.current = !0;
30100
30135
  }
30101
- }), {
30102
- onToolStart: () => {
30103
- e || (de.current = !0, ue.current &&= (clearTimeout(ue.current), null), se.current = "thinking", h("thinking"));
30104
- },
30105
- onToolEnd: () => {
30106
- e || (de.current = !1, se.current = "listening", h("listening"));
30107
- }
30108
- }), n = i ? je(i) : null, u = !!n?.transcript, f = !!(i && He(i)), p = typeof window < "u" ? window.location.pathname : "/", m = typeof document < "u" ? document.title : "", g = p === "/" || p === "", _ = null;
30136
+ })), n = i ? je(i) : null, u = !!n?.transcript, f = !!(i && He(i)), p = typeof window < "u" ? window.location.pathname : "/", m = typeof document < "u" ? document.title : "", g = p === "/" || p === "", _ = null;
30109
30137
  try {
30110
30138
  let e = await fetch(`${a}/api/voice/signed-url?siteId=${encodeURIComponent(i || "")}`, {
30111
30139
  method: "GET",
@@ -30128,8 +30156,8 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30128
30156
  }, b = (p.split("/").filter(Boolean).pop() || "").replace(/[-_]/g, " ").replace(/\b\w/g, (e) => e.toUpperCase()), x = "";
30129
30157
  m && m.includes("|") && (x = m.split("|").map((e) => e.trim()).filter(Boolean).reduce((e, t) => e.length <= t.length ? e : t));
30130
30158
  let w = x || b || "this page";
30131
- _ ? f ? (v.overrides = { agent: { firstMessage: `I've navigated you to the ${w} page.` } }, console.log(`[FlowEngage] 🔄 Agent-nav resume: firstMessage set for "${w}" (${p})`)) : u ? v.overrides = { agent: { firstMessage: "I'm still here. Go ahead!" } } : g ? v.overrides = { agent: { firstMessage: "Hi there! Let me give you a quick tour of what's available here." } } : (v.overrides = { agent: { firstMessage: `Welcome! You're on the ${w} page let me walk you through the highlights.` } }, console.log(`[FlowEngage] 🏠 Page-context override: "${w}" for ${p}`)) : u && (v.overrides = { agent: { firstMessage: "" } });
30132
- let ae = !1, me = f ? `NAVIGATION RESUME: You are on the "${w}" page. Speak 2-3 natural sentences introducing this page what it is and what the visitor will find here. Then ask exactly: "Would you like me to walk you through this page in detail?" Wait for the visitor's response. ONLY if they say yes/sure/go ahead → call flowengage_highlight section by section. If they decline respond helpfully and let them explore. DO NOT call flowengage_highlight before the visitor explicitly approves. Prior conversation context:\n${n?.transcript || ""}\n\n` : null, he = !1, ge = !f && !u ? "AUTO-START — Your greeting has been spoken. NOW — without waiting for the visitor to say anything — call flowengage_get_current_page, then immediately highlight the top 3 sections and give a one-sentence summary for each. Keep it brisk — no filler, no questions until the walkthrough is done." : null, _e = await vD.startSession({
30159
+ _ ? f ? (v.overrides = { agent: { firstMessage: `I've navigated you to the ${w} page. Let me walk you through what's here.` } }, console.log(`[FlowEngage] 🔄 Agent-nav resume: firstMessage set for "${w}" (${p})`)) : u ? v.overrides = { agent: { firstMessage: "I'm still here. Go ahead!" } } : g || (v.overrides = { agent: { firstMessage: `Hi! I see you are currently on the ${w} page. Are you looking for something specific here?` } }, console.log(`[FlowEngage] 🏠 Page-context override: "${w}" for ${p}`)) : u && (v.overrides = { agent: { firstMessage: "" } });
30160
+ let ae = !1, pe = f ? `NAVIGATION RESUME Your intro has been spoken. NOWwithout waiting for the visitor to say anything call flowengage_highlight for the first content section on this page, then speak one sentence about it. Continue section by section (highlight + one sentence each) until you have covered the key content. Prior conversation context:\n${(i ? je(i) : null)?.transcript || ""}\n\n` : null, me = await vD.startSession({
30133
30161
  ...v,
30134
30162
  onConnect: ({ conversationId: e }) => {
30135
30163
  E.current = e, ie.current = Date.now(), console.log("[FlowEngage] 🎙️ AI chat session connected:", e);
@@ -30138,31 +30166,21 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30138
30166
  onModeChange: ({ mode: t }) => {
30139
30167
  if (!e) {
30140
30168
  if (t === "speaking") {
30141
- ue.current &&= (clearTimeout(ue.current), null), h("speaking"), se.current = "speaking", ce.current = !0, fe.current = !1, le.current &&= (clearTimeout(le.current), null);
30169
+ ue.current &&= (clearTimeout(ue.current), null), h("speaking"), se.current = "speaking", ce.current = !0, de.current = !1, le.current &&= (clearTimeout(le.current), null);
30142
30170
  return;
30143
30171
  }
30144
- if (de.current || (se.current = "listening", h("listening")), D.current) {
30145
- D.current = !1, pe();
30172
+ if (se.current = "listening", D.current) {
30173
+ D.current = !1, fe();
30146
30174
  return;
30147
30175
  }
30148
- if (me && !ae) {
30176
+ if (pe && !ae) {
30149
30177
  ae = !0;
30150
30178
  try {
30151
- S.current?.sendUserMessage?.(me);
30152
- } catch {}
30153
- }
30154
- if (ge && !he) {
30155
- he = !0;
30156
- try {
30157
- S.current?.sendContextualUpdate?.(ge);
30179
+ S.current?.sendUserMessage?.("continue with the tour");
30158
30180
  } catch {}
30159
30181
  }
30160
30182
  ue.current && clearTimeout(ue.current), ue.current = setTimeout(() => {
30161
- e || se.current !== "speaking" && se.current !== "thinking" && (de.current || fe.current || (ue.current = null, se.current = "listening", h("listening"), ce.current && !ee.current && (le.current && clearTimeout(le.current), le.current = setTimeout(() => {
30162
- if (!e && se.current === "listening" && !ee.current) try {
30163
- S.current?.sendContextualUpdate?.("The visitor has been silent for a while. Ask one short, natural question to re-engage — for example: 'Is there anything specific you'd like to know more about?' or 'What else can I help you with today?' Keep it to one sentence.");
30164
- } catch {}
30165
- }, 4e3))));
30183
+ e || se.current !== "speaking" && (de.current || (ue.current = null, se.current = "listening", h("listening")));
30166
30184
  }, 1200);
30167
30185
  }
30168
30186
  },
@@ -30170,7 +30188,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30170
30188
  if (e) return;
30171
30189
  let n = t.role === "user" ? "user" : "bot", r = t.message || t.text || t.content || "";
30172
30190
  if (r) {
30173
- if (n === "user" && (C.current = r, fe.current = !0, ue.current &&= (clearTimeout(ue.current), null), le.current &&= (clearTimeout(le.current), null)), l.current = [...l.current, {
30191
+ if (n === "user" && (C.current = r, de.current = !0, ue.current &&= (clearTimeout(ue.current), null), le.current &&= (clearTimeout(le.current), null)), l.current = [...l.current, {
30174
30192
  sender: n,
30175
30193
  message: r,
30176
30194
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
@@ -30178,14 +30196,14 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30178
30196
  let e = vO(l.current);
30179
30197
  e && Ae(i, e);
30180
30198
  } catch {}
30181
- if (Ak(n, r)) {
30182
- pe("minimized");
30199
+ if (jk(n, r)) {
30200
+ fe("minimized");
30183
30201
  return;
30184
30202
  }
30185
30203
  if (ee.current && n === "bot" && /are you still there|still there\??|hello\?|anyone there|checking in|you there|are you available|is anyone|did you step away/i.test(r)) if (oe.current += 1, oe.current === 2) try {
30186
30204
  S.current?.sendContextualUpdate?.("IMPORTANT: The visitor is muted and has not responded to your last 2 checks. Make exactly ONE more check. If there is still no response, say: 'I feel like you are not active, so I'm ending this session. You can connect with me anytime.' then immediately call the flowengage_end_session tool to end the voice session. Do NOT ask again after that.");
30187
30205
  } catch {}
30188
- else oe.current >= 5 && pe("minimized");
30206
+ else oe.current >= 5 && fe("minimized");
30189
30207
  }
30190
30208
  },
30191
30209
  onError: (t) => {
@@ -30198,7 +30216,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30198
30216
  try {
30199
30217
  S.current?.setMicMuted?.(!0);
30200
30218
  } catch {}
30201
- y(!0), h("error"), pe("chat");
30219
+ y(!0), h("error"), fe("chat");
30202
30220
  }
30203
30221
  },
30204
30222
  onDisconnect: (t) => {
@@ -30215,21 +30233,21 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30215
30233
  try {
30216
30234
  S.current?.setMicMuted?.(!0);
30217
30235
  } catch {}
30218
- y(!0), pe("chat");
30236
+ y(!0), fe("chat");
30219
30237
  }
30220
30238
  });
30221
30239
  if (e) {
30222
- console.warn("[FlowEngage:VoiceDebug] ❌ cancelled=true after startSession resolved — killing session immediately"), _e.endSession().catch(() => {});
30240
+ me.endSession().catch(() => {});
30223
30241
  return;
30224
30242
  }
30225
- o = _e, S.current = _e, h("listening");
30243
+ o = me, S.current = me, h("listening");
30226
30244
  try {
30227
30245
  let e = typeof window < "u" ? window.location.href : "", r = "[]";
30228
30246
  try {
30229
- r = await t.flowengage_list_forms();
30247
+ r = await t.list_page_forms();
30230
30248
  } catch {}
30231
30249
  let a = u && !f ? `RESUMING PRIOR SESSION — DO NOT GREET. The visitor is continuing the same conversation after a page reload. Do not introduce yourself or re-state your capabilities. Wait silently until the visitor speaks; if you must speak first, briefly acknowledge where you left off in one short sentence.\nPrior transcript:\n${n?.transcript || ""}\n\n` : "";
30232
- _e.sendContextualUpdate(`${a}Page: ${e}. SiteId: ${i || "unknown"}. Forms: ${r}. Voice: call end_voice_session or say you are ending the session to stop.`);
30250
+ me.sendContextualUpdate(`${a}Page: ${e}. SiteId: ${i || "unknown"}. Forms: ${r}. Voice: call end_voice_session or say you are ending the session to stop.`);
30233
30251
  } catch {}
30234
30252
  if (typeof window < "u") {
30235
30253
  let t = window.location.pathname, n = () => {
@@ -30271,27 +30289,23 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30271
30289
  }, 0)));
30272
30290
  }
30273
30291
  })(), () => {
30274
- console.warn("[FlowEngage:VoiceDebug] ⚠️ useEffect CLEANUP fired — session will be killed", {
30275
- agentId: r,
30276
- siteId: i,
30277
- apiBaseUrl: a
30278
- }), e = !0, ne.current = !0;
30292
+ e = !0, ne.current = !0;
30279
30293
  try {
30280
30294
  SD();
30281
30295
  } catch {}
30282
30296
  if (i) try {
30283
30297
  He(i);
30284
30298
  } catch {}
30285
- 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, fe.current = !1, de.current = !1, se.current = "idle", c && typeof window < "u" && (window.history.pushState = c), d && typeof window < "u" && window.removeEventListener("popstate", d);
30286
- let t = o || S.current, n = E.current, f = ie.current;
30299
+ typeof window < "u" && (window.__fe_user_nav_during_speech = null), Ar(), le.current &&= (clearTimeout(le.current), null), ue.current &&= (clearTimeout(ue.current), null), ce.current = !1, de.current = !1, se.current = "idle", c && typeof window < "u" && (window.history.pushState = c), d && typeof window < "u" && window.removeEventListener("popstate", d);
30300
+ let t = o || S.current, n = E.current, r = ie.current;
30287
30301
  if (t?.endSession?.().catch(() => {}), n && s && a) {
30288
- let e = f ? Math.round((Date.now() - f) / 1e3) : 0, t = JSON.stringify({
30302
+ let e = r ? Math.round((Date.now() - r) / 1e3) : 0, t = JSON.stringify({
30289
30303
  chatId: s,
30290
30304
  elevenLabsConversationId: n,
30291
30305
  duration: e,
30292
30306
  siteId: i
30293
- }), r = `${a}/api/voice/save-chat-recording`;
30294
- typeof navigator < "u" && navigator.sendBeacon && navigator.sendBeacon(r, new Blob([t], { type: "application/json" })) || fetch(r, {
30307
+ }), o = `${a}/api/voice/save-chat-recording`;
30308
+ typeof navigator < "u" && navigator.sendBeacon && navigator.sendBeacon(o, new Blob([t], { type: "application/json" })) || fetch(o, {
30295
30309
  method: "POST",
30296
30310
  headers: { "Content-Type": "application/json" },
30297
30311
  body: t,
@@ -30304,7 +30318,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30304
30318
  r,
30305
30319
  i,
30306
30320
  a,
30307
- pe
30321
+ fe
30308
30322
  ]), c(() => {
30309
30323
  if (!b) return;
30310
30324
  let e = (e) => {
@@ -30326,22 +30340,6 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30326
30340
  /* @__PURE__ */ _("div", {
30327
30341
  style: { position: "relative" },
30328
30342
  children: [
30329
- f === "thinking" && !v && /* @__PURE__ */ g("span", {
30330
- style: {
30331
- position: "absolute",
30332
- right: "100%",
30333
- marginRight: "18px",
30334
- top: "50%",
30335
- transform: "translateY(-50%)",
30336
- color: "#a78bfa",
30337
- fontSize: "18px",
30338
- fontWeight: 600,
30339
- letterSpacing: "0.01em",
30340
- textShadow: "0 2px 4px rgba(0,0,0,0.4)",
30341
- whiteSpace: "nowrap"
30342
- },
30343
- children: "Processing..."
30344
- }),
30345
30343
  f === "listening" && !v && /* @__PURE__ */ g("span", {
30346
30344
  style: {
30347
30345
  position: "absolute",
@@ -30374,7 +30372,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30374
30372
  },
30375
30373
  children: "Muted"
30376
30374
  }),
30377
- /* @__PURE__ */ g(jk, {
30375
+ /* @__PURE__ */ g(Mk, {
30378
30376
  size: 72,
30379
30377
  voiceState: f,
30380
30378
  isMuted: v,
@@ -30506,7 +30504,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30506
30504
  children: [
30507
30505
  /* @__PURE__ */ _("button", {
30508
30506
  onClick: () => {
30509
- x(!1), re.current = "chat", me(t);
30507
+ x(!1), re.current = "chat", pe(t);
30510
30508
  },
30511
30509
  style: {
30512
30510
  display: "flex",
@@ -30535,7 +30533,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30535
30533
  }),
30536
30534
  /* @__PURE__ */ _("button", {
30537
30535
  onClick: () => {
30538
- x(!1), re.current = "minimized", me(n);
30536
+ x(!1), re.current = "minimized", pe(n);
30539
30537
  },
30540
30538
  style: {
30541
30539
  display: "flex",
@@ -30612,7 +30610,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
30612
30610
  ]
30613
30611
  });
30614
30612
  }
30615
- function Fk({ orbColors: e }) {
30613
+ function Ik({ orbColors: e }) {
30616
30614
  return /* @__PURE__ */ g("div", {
30617
30615
  style: {
30618
30616
  flexShrink: 0,
@@ -30622,13 +30620,13 @@ function Fk({ orbColors: e }) {
30622
30620
  alignItems: "center",
30623
30621
  justifyContent: "center"
30624
30622
  },
30625
- children: /* @__PURE__ */ g(jk, {
30623
+ children: /* @__PURE__ */ g(Mk, {
30626
30624
  size: 36,
30627
30625
  orbColors: e
30628
30626
  })
30629
30627
  });
30630
30628
  }
30631
- var Ik = () => /* @__PURE__ */ g("div", {
30629
+ var Lk = () => /* @__PURE__ */ g("div", {
30632
30630
  style: {
30633
30631
  display: "flex",
30634
30632
  marginBottom: "12px",
@@ -30658,7 +30656,7 @@ var Ik = () => /* @__PURE__ */ g("div", {
30658
30656
  } }, e))
30659
30657
  })
30660
30658
  });
30661
- function Lk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i, quickChatOptions: a, onQuickChatSelect: o, isMobile: s, chatHistory: l, isAiTyping: u, isAgentTyping: d, activeScreen: f, agentName: v, agentHeadshot: y, fallbackAgentName: b, input: x, setInput: S, onSubmit: C, isConversationEnded: w, isLoading: T, isRateLimited: ee, rateLimitMessage: te, selectedFile: ne, onFileSelect: re, onRemoveSelectedFile: E, attachmentError: ie, isUploadingAttachment: ae, requiresEmail: oe, emailInput: D, setEmailInput: se, emailError: ce, emailCaptureSuccess: le, replyContext: ue, setReplyContext: de, webRTCError: fe, micError: pe, setMicError: me, dismissCallError: he, activeCallId: ge, isCallMuted: _e, toggleCallMute: ve, endWebRTCCall: ye, formatCallDuration: be, callDurationSeconds: xe, isCallMinimized: Se, onExpand: Ce, onCollapse: we, onStartVoice: Te, onNewChat: Ee, showPoweredBy: De, getVisitorChatHistory: Oe, resumeChat: ke, isSessionRestoring: Ae, isClosing: je }) {
30659
+ function Rk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i, quickChatOptions: a, onQuickChatSelect: o, isMobile: s, chatHistory: l, isAiTyping: u, isAgentTyping: d, activeScreen: f, agentName: v, agentHeadshot: y, fallbackAgentName: b, input: x, setInput: S, onSubmit: C, isConversationEnded: w, isLoading: T, isRateLimited: ee, rateLimitMessage: te, selectedFile: ne, onFileSelect: re, onRemoveSelectedFile: E, attachmentError: ie, isUploadingAttachment: ae, requiresEmail: oe, emailInput: D, setEmailInput: se, emailError: ce, emailCaptureSuccess: le, replyContext: ue, setReplyContext: de, webRTCError: fe, micError: pe, setMicError: me, dismissCallError: he, activeCallId: ge, isCallMuted: _e, toggleCallMute: ve, endWebRTCCall: ye, formatCallDuration: be, callDurationSeconds: xe, isCallMinimized: Se, onExpand: Ce, onCollapse: we, onStartVoice: Te, onNewChat: Ee, showPoweredBy: De, getVisitorChatHistory: Oe, resumeChat: ke, isSessionRestoring: Ae, isClosing: je }) {
30662
30660
  let Me = l.length > 0, Ne = T || ee || w, Pe = !!ge, [Fe, Ie] = m(!1), [Le, Re] = m(!1), [ze, Be] = m([]), [Ve, He] = m(!1), O = p(null), [Ue, We] = m(() => typeof window < "u" ? window.visualViewport?.height ?? window.innerHeight : 600), [Ge, Ke] = m(0);
30663
30661
  c(() => {
30664
30662
  if (!s) return;
@@ -30794,7 +30792,7 @@ function Lk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
30794
30792
  justifyContent: "center",
30795
30793
  height: "40px"
30796
30794
  },
30797
- children: i ? /* @__PURE__ */ g(Ok, {
30795
+ children: i ? /* @__PURE__ */ g(kk, {
30798
30796
  logo: i,
30799
30797
  style: {
30800
30798
  height: "34px",
@@ -30807,7 +30805,7 @@ function Lk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
30807
30805
  height: "40px",
30808
30806
  flexShrink: 0
30809
30807
  },
30810
- children: /* @__PURE__ */ g(kk, { title: e.chatTitle })
30808
+ children: /* @__PURE__ */ g(Ak, { title: e.chatTitle })
30811
30809
  })
30812
30810
  }), /* @__PURE__ */ g("div", {
30813
30811
  style: {
@@ -31237,11 +31235,11 @@ function Lk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
31237
31235
  isLoading: T,
31238
31236
  isAgentTyping: d,
31239
31237
  setReplyContext: de,
31240
- TypingDots: Ik,
31238
+ TypingDots: Lk,
31241
31239
  primaryColor: n,
31242
31240
  agentHeadshot: y,
31243
31241
  agentDisplayName: v || b,
31244
- botAvatarNode: /* @__PURE__ */ g(Fk, { orbColors: t })
31242
+ botAvatarNode: /* @__PURE__ */ g(Ik, { orbColors: t })
31245
31243
  }) : Ae ? /* @__PURE__ */ _("div", {
31246
31244
  style: {
31247
31245
  flex: 1,
@@ -31282,7 +31280,7 @@ function Lk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
31282
31280
  padding: "28px 24px"
31283
31281
  },
31284
31282
  children: [
31285
- /* @__PURE__ */ g(jk, {
31283
+ /* @__PURE__ */ g(Mk, {
31286
31284
  size: 94,
31287
31285
  orbColors: t
31288
31286
  }),
@@ -31424,14 +31422,14 @@ function Lk({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
31424
31422
  ]
31425
31423
  });
31426
31424
  }
31427
- function Rk() {
31425
+ function zk() {
31428
31426
  let { status: e, runtimeConfig: t, resolvedConfig: n, chatHistory: r, isOpen: i, activeScreen: a, isHumanHandled: s, agentName: l, agentHeadshot: u, visitorEmail: h, isAgentTyping: v, isAiTyping: y, isLoading: b, isRateLimited: x, rateLimitMessage: S, isConversationEnded: C, incomingCall: w, activeCallId: T, callConnectionState: ee, callConnectedAt: te, isCallMuted: ne, webRTCError: re, language: E, chatId: ie, historyRef: ae, onMessageSync: oe, sendMessage: D, uploadChatFile: se, openWidget: ce, captureVisitorEmail: le, setVoiceMode: ue, endConversation: de, startNewChat: me, acceptCall: he, rejectCall: ge, endWebRTCCall: _e, toggleCallMute: ve, dismissCallError: ye, startTyping: be, stopTyping: xe, updateTypingDraft: Se, getVisitorChatHistory: Ce, resumeChat: we, isSessionRestoring: Te, openToChatCounter: Ee, voiceEndCounter: De } = Ln();
31429
31427
  c(() => {
31430
31428
  try {
31431
31429
  pr();
31432
31430
  } catch {}
31433
31431
  }, []), c(() => {
31434
- Ee && A !== "voice_mode" && A !== "text_chat" && A !== "call_screen" && (ue?.(!1), ot("text_chat"));
31432
+ Ee && A !== "text_chat" && A !== "call_screen" && (ue?.(!1), st("text_chat"));
31435
31433
  }, [Ee]);
31436
31434
  let Oe = t?.widgetSettings || {}, ke = n?.widgetSettings || {}, Ae = {
31437
31435
  ...Oe.branding || {},
@@ -31446,7 +31444,7 @@ function Rk() {
31446
31444
  small: 50,
31447
31445
  medium: 64,
31448
31446
  large: 80
31449
- }, 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) => ({
31447
+ }, Ve = Be[Ne.orbSize] || Be.small, He = Ne.position || "bottom-right", O = Ae.fallbackAgentName || "Agent", Ue = Ek(Le ?? Ne.chatBgColors), We = Ae.logo || Ae.logoUrl || null, Ge = E || "en", Ke = Oe.recommendations?.[Ge] || [], qe = (ke.recommendations?.[Ge] ?? Ke).filter((e) => String(e?.label ?? "").trim()).map((e, t) => ({
31450
31448
  id: e.key || `qr-${t}`,
31451
31449
  label: e.label,
31452
31450
  message: e.label,
@@ -31469,11 +31467,11 @@ function Rk() {
31469
31467
  ]), rt = u && String(u).trim() || t?.ownerProfileImageUrl && String(t.ownerProfileImageUrl).trim() || null, it = r.some((e) => e.sender === "user"), at = f(() => {
31470
31468
  let e = r.findIndex((e) => e.sender === "user");
31471
31469
  return e === -1 ? !1 : r.slice(e + 1).some((e) => e.sender === "bot" || e.sender === "ai" || e.sender === "agent");
31472
- }, [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";
31470
+ }, [r]), k = !h && it && at, ot = !!(ke._dashboardLivePreview || Oe._dashboardLivePreview), [A, st] = m(() => ot ? "text_chat" : "entry_prompt"), [ct, lt] = m(""), [ut, dt] = m(null), [ft, pt] = m(h || ""), [mt, ht] = m(""), [gt, j] = m(!1), [_t, vt] = m(0), [yt, bt] = m(null), [xt, St] = m(null), [Ct, wt] = m(""), [Tt, Et] = m(!1), [Dt, Ot] = m(!1), [kt, At] = m(!1), jt = p(null), Mt = p(!1);
31473
31471
  d(() => {
31474
- if (e !== "ready" || jt.current) return;
31475
- if (jt.current = !0, !Ie) {
31476
- ot("minimized_orb");
31472
+ if (e !== "ready" || Mt.current) return;
31473
+ if (Mt.current = !0, !Ie) {
31474
+ st("minimized_orb");
31477
31475
  return;
31478
31476
  }
31479
31477
  let t = !1;
@@ -31482,22 +31480,22 @@ function Rk() {
31482
31480
  } catch {}
31483
31481
  let n = Fe(), r = et ? je(et) : null, i = n || !!r?.transcript;
31484
31482
  if (t) {
31485
- ce?.({ notifyChatInitiated: !0 }), ue?.(!0), ot("voice_mode");
31483
+ ce?.({ notifyChatInitiated: !0 }), ue?.(!0), st("voice_mode");
31486
31484
  return;
31487
31485
  }
31488
31486
  if (Re()) {
31489
- ce?.({ notifyChatInitiated: !1 }), ot("text_chat");
31490
- return;
31491
- }
31492
- if (i) {
31493
- ce?.({ notifyChatInitiated: !0 }), ue?.(!0), ot("voice_mode");
31487
+ ce?.({ notifyChatInitiated: !1 }), st("text_chat");
31494
31488
  return;
31495
31489
  }
31496
31490
  if (et) try {
31497
31491
  Me(et);
31498
31492
  } catch {}
31493
+ if (i) {
31494
+ st("minimized_orb");
31495
+ return;
31496
+ }
31499
31497
  if (fe(et)) {
31500
- ot("minimized_orb");
31498
+ st("minimized_orb");
31501
31499
  return;
31502
31500
  }
31503
31501
  }, [e, r]);
@@ -31506,55 +31504,55 @@ function Rk() {
31506
31504
  let e = window.matchMedia("(max-width: 640px)"), t = (e) => Pt(e.matches);
31507
31505
  return e.addEventListener("change", t), () => e.removeEventListener("change", t);
31508
31506
  }, []), c(() => {
31509
- ft(h || ""), h && mt("");
31507
+ pt(h || ""), h && ht("");
31510
31508
  }, [h]);
31511
31509
  let Ft = o(() => {
31512
- xt(null), Ct("");
31510
+ St(null), wt("");
31513
31511
  }, []), It = o((e) => {
31514
31512
  let t = qD(e);
31515
31513
  if (t) {
31516
- xt(null), Ct(t);
31514
+ St(null), wt(t);
31517
31515
  return;
31518
31516
  }
31519
- xt(e), Ct("");
31517
+ St(e), wt("");
31520
31518
  }, []);
31521
31519
  c(() => {
31522
31520
  if (!te || ee !== "connected") {
31523
- _t(0);
31521
+ vt(0);
31524
31522
  return;
31525
31523
  }
31526
31524
  let e = () => {
31527
31525
  let e = new Date(te).getTime();
31528
- isNaN(e) || _t(Math.max(0, Math.floor((Date.now() - e) / 1e3)));
31526
+ isNaN(e) || vt(Math.max(0, Math.floor((Date.now() - e) / 1e3)));
31529
31527
  };
31530
31528
  e();
31531
31529
  let t = window.setInterval(e, 1e3);
31532
31530
  return () => window.clearInterval(t);
31533
31531
  }, [te, ee]);
31534
31532
  let Lt = o(() => {
31535
- ot("call_screen"), Dt(!1);
31533
+ st("call_screen"), Ot(!1);
31536
31534
  }, []), Rt = o(() => {
31537
- ot("text_chat"), Dt(!0);
31535
+ st("text_chat"), Ot(!0);
31538
31536
  }, []);
31539
31537
  c(() => {
31540
31538
  let e = w?.callId || T || null;
31541
31539
  if (!e) {
31542
- At.current = null;
31540
+ jt.current = null;
31543
31541
  return;
31544
31542
  }
31545
31543
  if (w?.callId || ee === "connecting" || ee === "connected") {
31546
- if (A === "minimized_orb" && Et && T && !w?.callId) {
31547
- At.current = e;
31544
+ if (A === "minimized_orb" && Dt && T && !w?.callId) {
31545
+ jt.current = e;
31548
31546
  return;
31549
31547
  }
31550
- !(!i || A === "minimized_orb" || A === "voice_mode") && At.current === e || (console.log("[FlowEngageWidget] forcing call UI to front", {
31548
+ !(!i || A === "minimized_orb" || A === "voice_mode") && jt.current === e || (console.log("[FlowEngageWidget] forcing call UI to front", {
31551
31549
  forcedKey: e,
31552
31550
  isOpen: i,
31553
31551
  surface: A,
31554
31552
  hasIncomingCall: !!w?.callId,
31555
31553
  activeCallId: T,
31556
31554
  callConnectionState: ee
31557
- }), At.current = e, A === "voice_mode" && ue?.(!1), ce?.(), Lt());
31555
+ }), jt.current = e, A === "voice_mode" && ue?.(!1), ce?.(), Lt());
31558
31556
  }
31559
31557
  }, [
31560
31558
  T,
@@ -31566,31 +31564,31 @@ function Rk() {
31566
31564
  ue,
31567
31565
  A
31568
31566
  ]), c(() => {
31569
- !w && !T && A === "call_screen" && ot("text_chat");
31567
+ !w && !T && A === "call_screen" && st("text_chat");
31570
31568
  }, [
31571
31569
  w,
31572
31570
  T,
31573
31571
  A
31574
31572
  ]), c(() => {
31575
- !T && Et && Dt(!1);
31576
- }, [T, Et]), c(() => {
31573
+ !T && Dt && Ot(!1);
31574
+ }, [T, Dt]), c(() => {
31577
31575
  if (!s || C) {
31578
31576
  Se?.(""), xe?.();
31579
31577
  return;
31580
31578
  }
31581
- if (!st.trim() || bt) {
31579
+ if (!ct.trim() || xt) {
31582
31580
  Se?.("");
31583
31581
  let e = window.setTimeout(() => xe?.(), 100);
31584
31582
  return () => window.clearTimeout(e);
31585
31583
  }
31586
31584
  be?.();
31587
- let e = window.setTimeout(() => Se?.(st), 120), t = window.setTimeout(() => xe?.(), 1200);
31585
+ let e = window.setTimeout(() => Se?.(ct), 120), t = window.setTimeout(() => xe?.(), 1200);
31588
31586
  return () => {
31589
31587
  window.clearTimeout(e), window.clearTimeout(t);
31590
31588
  };
31591
31589
  }, [
31592
- st,
31593
- bt,
31590
+ ct,
31591
+ xt,
31594
31592
  s,
31595
31593
  C,
31596
31594
  be,
@@ -31603,39 +31601,39 @@ function Rk() {
31603
31601
  replyToSender: e.sender || null
31604
31602
  } : null, Bt = async (e) => {
31605
31603
  if (e.preventDefault(), C) return;
31606
- if (Mt) {
31607
- let e = dt.trim().toLowerCase();
31604
+ if (k) {
31605
+ let e = ft.trim().toLowerCase();
31608
31606
  if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)) {
31609
- mt("Please enter a valid email so we can continue helping you.");
31607
+ ht("Please enter a valid email so we can continue helping you.");
31610
31608
  return;
31611
31609
  }
31612
- await le(e), mt(""), gt(!0), setTimeout(() => gt(!1), 3e3);
31610
+ await le(e), ht(""), j(!0), setTimeout(() => j(!1), 3e3);
31613
31611
  return;
31614
31612
  }
31615
- let t = zt(lt);
31616
- if (!st.trim() && !bt) return;
31617
- if (bt) {
31613
+ let t = zt(ut);
31614
+ if (!ct.trim() && !xt) return;
31615
+ if (xt) {
31618
31616
  try {
31619
- Tt(!0), Ct("");
31620
- let e = await se(bt), n = e?.data || e, r = st.trim() || `Shared file: ${YD(bt)}`;
31621
- ct(""), ut(null), Ft(), await D(r, "", t, {
31617
+ Et(!0), wt("");
31618
+ let e = await se(xt), n = e?.data || e, r = ct.trim() || `Shared file: ${YD(xt)}`;
31619
+ lt(""), dt(null), Ft(), await D(r, "", t, {
31622
31620
  type: "file",
31623
31621
  metadata: {
31624
31622
  fileUrl: n?.fileUrl,
31625
- fileName: n?.fileName || bt.name,
31626
- fileType: n?.fileType || bt.type,
31627
- fileSize: n?.fileSize || bt.size
31623
+ fileName: n?.fileName || xt.name,
31624
+ fileType: n?.fileType || xt.type,
31625
+ fileSize: n?.fileSize || xt.size
31628
31626
  }
31629
31627
  });
31630
31628
  } catch (e) {
31631
- Ct(e?.message || "Failed to upload the selected file.");
31629
+ wt(e?.message || "Failed to upload the selected file.");
31632
31630
  } finally {
31633
- Tt(!1);
31631
+ Et(!1);
31634
31632
  }
31635
31633
  return;
31636
31634
  }
31637
- let n = st.trim();
31638
- ct(""), ut(null), await D(n, "", t);
31635
+ let n = ct.trim();
31636
+ lt(""), dt(null), await D(n, "", t);
31639
31637
  }, Vt = o(() => {
31640
31638
  r.length !== 0 && me?.();
31641
31639
  }, [r.length, me]), Ht = (e) => {
@@ -31683,10 +31681,10 @@ function Rk() {
31683
31681
  right: "1.5rem",
31684
31682
  bottom: "1.5rem"
31685
31683
  }, Gt = o(() => {
31686
- A !== "minimized_orb" && (kt(!0), setTimeout(() => {
31687
- ot("minimized_orb"), kt(!1), T && Dt(!0);
31684
+ A !== "minimized_orb" && (At(!0), setTimeout(() => {
31685
+ st("minimized_orb"), At(!1), T && Ot(!0);
31688
31686
  }, 280));
31689
- }, [T, A]), Kt = () => ot("connection_modal"), qt = () => {
31687
+ }, [T, A]), Kt = () => st("connection_modal"), qt = () => {
31690
31688
  try {
31691
31689
  let e = window.AudioContext || window.webkitAudioContext;
31692
31690
  if (e) {
@@ -31694,9 +31692,9 @@ function Rk() {
31694
31692
  t.resume().catch(() => {}), setTimeout(() => t.close().catch(() => {}), 3e3);
31695
31693
  }
31696
31694
  } catch {}
31697
- ce({ notifyChatInitiated: !0 }), ue?.(!0), ot("voice_mode");
31695
+ ce({ notifyChatInitiated: !0 }), ue?.(!0), st("voice_mode");
31698
31696
  }, Jt = () => {
31699
- ce({ notifyChatInitiated: !0 }), ue?.(!1), ot("text_chat");
31697
+ ce({ notifyChatInitiated: !0 }), ue?.(!1), st("text_chat");
31700
31698
  }, Yt = () => {
31701
31699
  ue?.(!1), Gt();
31702
31700
  };
@@ -31710,7 +31708,7 @@ function Rk() {
31710
31708
  onWheel: (e) => e.stopPropagation(),
31711
31709
  onTouchMove: (e) => e.stopPropagation(),
31712
31710
  children: [
31713
- A === "entry_prompt" && /* @__PURE__ */ g(Mk, {
31711
+ A === "entry_prompt" && /* @__PURE__ */ g(Nk, {
31714
31712
  copy: Qe,
31715
31713
  orbColors: Le,
31716
31714
  primaryColor: ze,
@@ -31721,7 +31719,7 @@ function Rk() {
31721
31719
  pe(et), Gt();
31722
31720
  },
31723
31721
  isMobile: Nt,
31724
- isClosing: Ot
31722
+ isClosing: kt
31725
31723
  }),
31726
31724
  A === "minimized_orb" && /* @__PURE__ */ _(Dm.div, {
31727
31725
  layoutId: "fe-main-orb",
@@ -31790,16 +31788,16 @@ function Rk() {
31790
31788
  marginTop: "2px",
31791
31789
  whiteSpace: "nowrap"
31792
31790
  },
31793
- children: ee === "connected" ? `${Ht(j)} with ${nt}` : `Tap to return to ${nt}`
31791
+ children: ee === "connected" ? `${Ht(_t)} with ${nt}` : `Tap to return to ${nt}`
31794
31792
  })]
31795
31793
  })]
31796
- }), /* @__PURE__ */ g(jk, {
31794
+ }), /* @__PURE__ */ g(Mk, {
31797
31795
  size: Ve,
31798
31796
  orbColors: Le,
31799
31797
  onClick: T ? Lt : Ie ? Kt : Jt
31800
31798
  })]
31801
31799
  }),
31802
- A === "connection_modal" && /* @__PURE__ */ g(Nk, {
31800
+ A === "connection_modal" && /* @__PURE__ */ g(Pk, {
31803
31801
  copy: Qe,
31804
31802
  orbColors: Le,
31805
31803
  primaryColor: ze,
@@ -31807,9 +31805,9 @@ function Rk() {
31807
31805
  onText: Jt,
31808
31806
  onClose: Gt,
31809
31807
  isMobile: Nt,
31810
- isClosing: Ot
31808
+ isClosing: kt
31811
31809
  }),
31812
- A === "voice_mode" && /* @__PURE__ */ g(Pk, {
31810
+ A === "voice_mode" && /* @__PURE__ */ g(Fk, {
31813
31811
  orbColors: Le,
31814
31812
  onEnterChat: Jt,
31815
31813
  onEndChat: Yt,
@@ -31825,7 +31823,7 @@ function Rk() {
31825
31823
  incomingCall: w,
31826
31824
  activeCallId: T,
31827
31825
  callConnectionState: ee,
31828
- callDurationSeconds: j,
31826
+ callDurationSeconds: _t,
31829
31827
  isCallMuted: ne,
31830
31828
  agentName: nt,
31831
31829
  agentHeadshot: rt,
@@ -31840,8 +31838,8 @@ function Rk() {
31840
31838
  orbColors: Le,
31841
31839
  chatHistory: r
31842
31840
  }),
31843
- A === "text_chat" && /* @__PURE__ */ g(Lk, {
31844
- isClosing: Ot,
31841
+ A === "text_chat" && /* @__PURE__ */ g(Rk, {
31842
+ isClosing: kt,
31845
31843
  copy: Qe,
31846
31844
  orbColors: Le,
31847
31845
  primaryColor: ze,
@@ -31857,35 +31855,35 @@ function Rk() {
31857
31855
  agentName: nt,
31858
31856
  agentHeadshot: rt,
31859
31857
  fallbackAgentName: O,
31860
- input: st,
31861
- setInput: ct,
31858
+ input: ct,
31859
+ setInput: lt,
31862
31860
  onSubmit: Bt,
31863
31861
  isConversationEnded: C,
31864
31862
  isLoading: b,
31865
31863
  isRateLimited: x,
31866
31864
  rateLimitMessage: S,
31867
- selectedFile: bt,
31865
+ selectedFile: xt,
31868
31866
  onFileSelect: It,
31869
31867
  onRemoveSelectedFile: Ft,
31870
- attachmentError: St,
31871
- isUploadingAttachment: wt,
31872
- requiresEmail: Mt,
31873
- emailInput: dt,
31874
- setEmailInput: ft,
31875
- emailError: pt,
31876
- emailCaptureSuccess: ht,
31877
- replyContext: lt,
31878
- setReplyContext: ut,
31868
+ attachmentError: Ct,
31869
+ isUploadingAttachment: Tt,
31870
+ requiresEmail: k,
31871
+ emailInput: ft,
31872
+ setEmailInput: pt,
31873
+ emailError: mt,
31874
+ emailCaptureSuccess: gt,
31875
+ replyContext: ut,
31876
+ setReplyContext: dt,
31879
31877
  webRTCError: re,
31880
- micError: vt,
31881
- setMicError: yt,
31878
+ micError: yt,
31879
+ setMicError: bt,
31882
31880
  dismissCallError: ye,
31883
31881
  activeCallId: T,
31884
31882
  isCallMuted: ne,
31885
31883
  toggleCallMute: ve,
31886
31884
  endWebRTCCall: _e,
31887
31885
  formatCallDuration: Ht,
31888
- callDurationSeconds: j,
31886
+ callDurationSeconds: _t,
31889
31887
  onCollapse: Gt,
31890
31888
  onStartVoice: qt,
31891
31889
  onNewChat: Vt,
@@ -31903,7 +31901,7 @@ function Rk() {
31903
31901
  }
31904
31902
  //#endregion
31905
31903
  //#region src/components/ErrorBoundary.jsx
31906
- var zk = class extends e.Component {
31904
+ var Bk = class extends e.Component {
31907
31905
  constructor(e) {
31908
31906
  super(e), this.state = { hasError: !1 };
31909
31907
  }
@@ -31918,4 +31916,4 @@ var zk = class extends e.Component {
31918
31916
  }
31919
31917
  };
31920
31918
  //#endregion
31921
- export { lO as AnimatedOrb, zk as ErrorBoundary, Rr as FlowEngageProvider, Rk as FlowEngageWidget, Ln as useFlowEngage };
31919
+ export { lO as AnimatedOrb, Bk as ErrorBoundary, Rr as FlowEngageProvider, zk as FlowEngageWidget, Ln as useFlowEngage };