@flowengage/react-chatbot 5.0.37 → 5.0.40

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.
@@ -29386,8 +29386,10 @@ function Ck(e) {
29386
29386
  $("flowengage_navigate → real navigation", a);
29387
29387
  let e = typeof window < "u" && !!(window.next?.router || window.__NEXT_ROUTER__ || window.__remixRouter || window.__staticRouterHydrationData || window.___gatsby || window.___navigate || window.__VUE_ROUTER__ || window.__NUXT__ || window.$nuxt || window.ng?.getComponent || typeof document < "u" && document.querySelector("[ng-version]") || window.__sveltekit_data || typeof document < "u" && document.querySelector("[data-sveltekit-hydrate]"));
29388
29388
  if (typeof window < "u" && window.__fe_triggerVoiceNavHooks && window.__fe_triggerVoiceNavHooks(), e && qn(3e3), Tr(a, { voiceActive: !0 }).catch(() => {}), e) try {
29389
- let e = (new URL(a, window.location.origin).pathname.split("/").filter(Boolean).pop() || "").replace(/[-_]/g, " ").replace(/\b\w/g, (e) => e.toUpperCase()) || "this page";
29390
- return $("flowengage_navigate → SPA async navigation, new page:", e), `OK_NAVIGATE_SPA. You are now on the ${e} page. Immediately say: "I have navigated you to the ${e} page. Let me show you what's here." Then continue guiding the visitor.`;
29389
+ let e = new URL(a, window.location.origin).pathname;
29390
+ await new Promise((e) => setTimeout(e, 350));
29391
+ let t = typeof window < "u" ? window.location.pathname : e, n = typeof window < "u" ? window.location.href : a, r = t === e, i = (t.split("/").filter(Boolean).pop() || "").replace(/[-_]/g, " ").replace(/\b\w/g, (e) => e.toUpperCase()) || "Home";
29392
+ return $("flowengage_navigate → SPA nav complete. target:", e, "actual:", t), r ? `OK_NAVIGATE_SPA. Navigation confirmed. Visitor is now at: ${n}. Page name: "${i}". Continue with your response about this page — do NOT say "I have navigated you to..." (the page is already changing visually). Just start talking about the content.` : `OK_NAVIGATE_SPA. IMPORTANT: Navigation was interrupted. The visitor is currently at ${n} (page: "${i}"), NOT the page you tried to navigate to. Adjust your response to describe the page the visitor is ACTUALLY on right now.`;
29391
29393
  } catch {}
29392
29394
  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.";
29393
29395
  } catch (e) {
@@ -29985,12 +29987,15 @@ function Nk({ copy: e, orbColors: t, primaryColor: n, onVoice: r, onText: i, onC
29985
29987
  });
29986
29988
  }
29987
29989
  function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i, siteId: a, apiBaseUrl: s, chatId: l, historyRef: u, onMessageSync: d, voiceEndCounter: f }) {
29988
- let [h, v] = m("idle"), [y, b] = m(!1), [x, S] = m(!1), C = p(null), w = p(""), T = p(async () => {}), ee = p(!1), te = p(!1), ne = p(!1), re = p(!1), E = p("minimized"), ie = p(null), ae = p(null), oe = p(null), D = p(0), se = p(!1), ce = p("idle"), le = p(!1), ue = p(null), de = p(null), fe = o((e = "minimized") => {
29990
+ let [h, v] = m("idle"), [y, b] = m(!1), [x, S] = m(!1), C = p(null), w = p(""), T = p(async () => {}), ee = p(!1), te = p(!1), ne = p(!1), re = p(!1), E = p("minimized"), ie = p(null), ae = p(null), oe = p(null), D = p(0), se = p(!1), ce = p("idle"), le = p(!1), ue = p(null), de = p(null), fe = p(!1), pe = o((e = "minimized") => {
29989
29991
  E.current = e, re.current = !0, queueMicrotask(() => {
29990
29992
  ee.current || (ee.current = !0, T.current?.());
29991
29993
  });
29992
- }, [u]), pe = o(async (e) => {
29994
+ }, [u]), me = o(async (e) => {
29993
29995
  re.current = !0;
29996
+ try {
29997
+ _r();
29998
+ } catch {}
29994
29999
  try {
29995
30000
  await C.current?.endSession?.();
29996
30001
  } catch {}
@@ -30019,10 +30024,10 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30019
30024
  l,
30020
30025
  s
30021
30026
  ]);
30022
- return T.current = () => pe(E.current === "chat" ? t : n), c(() => {
30027
+ return T.current = () => me(E.current === "chat" ? t : n), c(() => {
30023
30028
  te.current = y;
30024
30029
  }, [y]), c(() => {
30025
- f && fe("chat");
30030
+ f && pe("chat");
30026
30031
  }, [f]), c(() => {
30027
30032
  let e = !1, i = null, o = null, c = null;
30028
30033
  return (async () => {
@@ -30086,42 +30091,42 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30086
30091
  m && m.includes("|") && (x = m.split("|").map((e) => e.trim()).filter(Boolean).reduce((e, t) => e.length <= t.length ? e : t));
30087
30092
  let S = x || y || "this page";
30088
30093
  g ? f ? (_.overrides = { agent: { firstMessage: `I've navigated you to the ${S} page. Let me walk you through what's here.` } }, console.log(`[FlowEngage] 🔄 Agent-nav resume: firstMessage set for "${S}" (${p})`)) : d ? _.overrides = { agent: { firstMessage: "I'm still here. Go ahead!" } } : h || (_.overrides = { agent: { firstMessage: `Hi! I see you are currently on the ${S} page. Are you looking for something specific here?` } }, console.log(`[FlowEngage] 🏠 Page-context override: "${S}" for ${p}`)) : d && (_.overrides = { agent: { firstMessage: "" } });
30089
- let T = !1, oe = f ? `NAVIGATION RESUME — Your intro has been spoken. NOW — without 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${(a ? je(a) : null)?.transcript || ""}\n\n` : null, pe = await _D.startSession({
30094
+ let T = !1, oe = f ? `NAVIGATION RESUME — Your intro has been spoken. NOW — without 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${(a ? je(a) : null)?.transcript || ""}\n\n` : null, me = await _D.startSession({
30090
30095
  ..._,
30091
30096
  onConnect: ({ conversationId: e }) => {
30092
30097
  ie.current = e, ae.current = Date.now(), console.log("[FlowEngage] 🎙️ AI chat session connected:", e);
30093
30098
  },
30094
30099
  onUnhandledClientToolCall: (e) => console.error("[FlowEngage] Unhandled tool:", e?.tool_name),
30095
30100
  onModeChange: ({ mode: t }) => {
30096
- if (!e) {
30097
- if (t === "speaking") {
30098
- de.current &&= (clearTimeout(de.current), null), v("speaking"), ce.current = "speaking", le.current = !0, ue.current &&= (clearTimeout(ue.current), null);
30099
- return;
30100
- }
30101
- if (ce.current = "listening", se.current) {
30102
- se.current = !1, fe();
30103
- return;
30104
- }
30105
- if (oe && !T) {
30106
- T = !0;
30107
- try {
30108
- C.current?.sendUserMessage?.("continue with the tour");
30109
- } catch {}
30110
- }
30111
- de.current && clearTimeout(de.current), de.current = setTimeout(() => {
30112
- e || ce.current === "listening" && (de.current = null, v("listening"), le.current && !te.current && (ue.current && clearTimeout(ue.current), ue.current = setTimeout(() => {
30113
- if (!e && ce.current === "listening" && !te.current) try {
30114
- C.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.");
30115
- } catch {}
30116
- }, 4e3)));
30117
- }, 1200);
30101
+ if (e) return;
30102
+ if (t === "speaking") {
30103
+ de.current &&= (clearTimeout(de.current), null), v("speaking"), ce.current = "speaking", le.current = !0, fe.current = !1, ue.current &&= (clearTimeout(ue.current), null);
30104
+ return;
30105
+ }
30106
+ let n = ce.current;
30107
+ if (ce.current = "listening", se.current) {
30108
+ se.current = !1, pe();
30109
+ return;
30118
30110
  }
30111
+ if (oe && !T) {
30112
+ T = !0;
30113
+ try {
30114
+ C.current?.sendUserMessage?.("continue with the tour");
30115
+ } catch {}
30116
+ }
30117
+ n === "speaking" && le.current && !te.current && (ce.current = "thinking", v("thinking")), de.current && clearTimeout(de.current), de.current = setTimeout(() => {
30118
+ e || ce.current !== "speaking" && (fe.current || (de.current = null, ce.current = "listening", v("listening"), le.current && !te.current && (ue.current && clearTimeout(ue.current), ue.current = setTimeout(() => {
30119
+ if (!e && ce.current === "listening" && !te.current) try {
30120
+ C.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.");
30121
+ } catch {}
30122
+ }, 4e3))));
30123
+ }, 1200);
30119
30124
  },
30120
30125
  onMessage: (t) => {
30121
30126
  if (e) return;
30122
30127
  let n = t.role === "user" ? "user" : "bot", r = t.message || t.text || t.content || "";
30123
30128
  if (r) {
30124
- if (n === "user" && (w.current = r, ue.current &&= (clearTimeout(ue.current), null)), u.current = [...u.current, {
30129
+ if (n === "user" && (w.current = r, fe.current = !0, de.current &&= (clearTimeout(de.current), null), ce.current = "thinking", v("thinking"), ue.current &&= (clearTimeout(ue.current), null)), u.current = [...u.current, {
30125
30130
  sender: n,
30126
30131
  message: r,
30127
30132
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
@@ -30130,13 +30135,13 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30130
30135
  e && Ae(a, e);
30131
30136
  } catch {}
30132
30137
  if (Ak(n, r)) {
30133
- fe("minimized");
30138
+ pe("minimized");
30134
30139
  return;
30135
30140
  }
30136
30141
  if (te.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 (D.current += 1, D.current === 2) try {
30137
30142
  C.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.");
30138
30143
  } catch {}
30139
- else D.current >= 5 && fe("minimized");
30144
+ else D.current >= 5 && pe("minimized");
30140
30145
  }
30141
30146
  },
30142
30147
  onError: (t) => {
@@ -30149,7 +30154,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30149
30154
  try {
30150
30155
  C.current?.setMicMuted?.(!0);
30151
30156
  } catch {}
30152
- b(!0), v("error"), fe("chat");
30157
+ b(!0), v("error"), pe("chat");
30153
30158
  }
30154
30159
  },
30155
30160
  onDisconnect: (t) => {
@@ -30166,21 +30171,21 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30166
30171
  try {
30167
30172
  C.current?.setMicMuted?.(!0);
30168
30173
  } catch {}
30169
- b(!0), fe("chat");
30174
+ b(!0), pe("chat");
30170
30175
  }
30171
30176
  });
30172
30177
  if (e) {
30173
- pe.endSession().catch(() => {});
30178
+ me.endSession().catch(() => {});
30174
30179
  return;
30175
30180
  }
30176
- i = pe, C.current = pe, v("listening");
30181
+ i = me, C.current = me, v("listening");
30177
30182
  try {
30178
30183
  let e = typeof window < "u" ? window.location.href : "", r = "[]";
30179
30184
  try {
30180
30185
  r = await t.list_page_forms();
30181
30186
  } catch {}
30182
30187
  let i = d && !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` : "";
30183
- pe.sendContextualUpdate(`${i}Page: ${e}. SiteId: ${a || "unknown"}. Forms: ${r}. Voice: call end_voice_session or say you are ending the session to stop.`);
30188
+ me.sendContextualUpdate(`${i}Page: ${e}. SiteId: ${a || "unknown"}. Forms: ${r}. Voice: call end_voice_session or say you are ending the session to stop.`);
30184
30189
  } catch {}
30185
30190
  if (typeof window < "u") {
30186
30191
  let t = window.location.pathname, n = () => {
@@ -30210,7 +30215,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30210
30215
  }, 0)));
30211
30216
  }
30212
30217
  })(), () => {
30213
- e = !0, re.current = !0, kr(), ue.current &&= (clearTimeout(ue.current), null), de.current &&= (clearTimeout(de.current), null), le.current = !1, ce.current = "idle", o && typeof window < "u" && (window.history.pushState = o), c && typeof window < "u" && window.removeEventListener("popstate", c);
30218
+ e = !0, re.current = !0, kr(), ue.current &&= (clearTimeout(ue.current), null), de.current &&= (clearTimeout(de.current), null), le.current = !1, fe.current = !1, ce.current = "idle", o && typeof window < "u" && (window.history.pushState = o), c && typeof window < "u" && window.removeEventListener("popstate", c);
30214
30219
  let t = i || C.current, n = ie.current, r = ae.current;
30215
30220
  if (t?.endSession?.().catch(() => {}), n && l && s) {
30216
30221
  let e = r ? Math.round((Date.now() - r) / 1e3) : 0, t = JSON.stringify({
@@ -30232,7 +30237,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30232
30237
  r,
30233
30238
  a,
30234
30239
  s,
30235
- fe
30240
+ pe
30236
30241
  ]), c(() => {
30237
30242
  if (!x) return;
30238
30243
  let e = (e) => {
@@ -30418,7 +30423,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30418
30423
  children: [
30419
30424
  /* @__PURE__ */ _("button", {
30420
30425
  onClick: () => {
30421
- S(!1), E.current = "chat", pe(t);
30426
+ S(!1), E.current = "chat", me(t);
30422
30427
  },
30423
30428
  style: {
30424
30429
  display: "flex",
@@ -30447,7 +30452,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30447
30452
  }),
30448
30453
  /* @__PURE__ */ _("button", {
30449
30454
  onClick: () => {
30450
- S(!1), E.current = "minimized", pe(n);
30455
+ S(!1), E.current = "minimized", me(n);
30451
30456
  },
30452
30457
  style: {
30453
30458
  display: "flex",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowengage/react-chatbot",
3
- "version": "5.0.37",
3
+ "version": "5.0.40",
4
4
  "description": "Embeddable AI chat widget for React — powered by FlowEngage. Drop it in with a single siteId.",
5
5
  "keywords": [
6
6
  "chatbot",