@flowengage/react-chatbot 5.0.46 → 5.0.47

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.
@@ -29988,11 +29988,11 @@ function Nk({ copy: e, orbColors: t, primaryColor: n, onVoice: r, onText: i, onC
29988
29988
  });
29989
29989
  }
29990
29990
  function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i, siteId: a, apiBaseUrl: s, chatId: l, historyRef: u, onMessageSync: d, voiceEndCounter: f }) {
29991
- 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 = p([]), me = p(null), he = p(null), ge = p(null), _e = o((e = "minimized") => {
29991
+ 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") => {
29992
29992
  E.current = e, re.current = !0, queueMicrotask(() => {
29993
29993
  ee.current || (ee.current = !0, T.current?.());
29994
29994
  });
29995
- }, [u]), ve = o(async (e) => {
29995
+ }, [u]), me = o(async (e) => {
29996
29996
  re.current = !0;
29997
29997
  try {
29998
29998
  CD();
@@ -30025,44 +30025,12 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30025
30025
  l,
30026
30026
  s
30027
30027
  ]);
30028
- T.current = () => ve(E.current === "chat" ? t : n);
30029
- let ye = o(() => {
30030
- let e = he.current, t = me.current;
30031
- if (e) {
30032
- he.current = null;
30033
- try {
30034
- t && ge.current && (ge.current.gain.setValueAtTime(ge.current.gain.value, t.currentTime), ge.current.gain.linearRampToValueAtTime(0, t.currentTime + .12), ge.current = null), setTimeout(() => {
30035
- try {
30036
- e.stop();
30037
- } catch {}
30038
- }, 130);
30039
- } catch {
30040
- try {
30041
- e.stop();
30042
- } catch {}
30043
- }
30044
- }
30045
- }, []), be = o(() => {
30046
- let e = pe.current, t = me.current;
30047
- if (!(!e.length || !t)) {
30048
- ye();
30049
- try {
30050
- t.state === "suspended" && t.resume().catch(() => {});
30051
- let n = e[Math.floor(Math.random() * e.length)], r = t.createBufferSource();
30052
- r.buffer = n;
30053
- let i = t.createGain();
30054
- i.gain.setValueAtTime(1, t.currentTime), r.connect(i), i.connect(t.destination), r.onended = () => {
30055
- he.current === r && (he.current = null);
30056
- }, r.start(0), he.current = r, ge.current = i;
30057
- } catch {}
30058
- }
30059
- }, [ye]);
30060
- return c(() => {
30028
+ return T.current = () => me(E.current === "chat" ? t : n), c(() => {
30061
30029
  te.current = y;
30062
30030
  }, [y]), c(() => {
30063
- f && _e("chat");
30031
+ f && pe("chat");
30064
30032
  }, [f]), c(() => {
30065
- let e = !1, o = null, c = null, f = null;
30033
+ let e = !1, i = null, o = null, c = null;
30066
30034
  return (async () => {
30067
30035
  if (!r) {
30068
30036
  v("error");
@@ -30101,13 +30069,13 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30101
30069
  requestEndSession: () => {
30102
30070
  se.current = !0;
30103
30071
  }
30104
- })), n = a ? je(a) : null, d = !!n?.transcript, p = !!(a && Ve(a)), m = typeof window < "u" ? window.location.pathname : "/", h = typeof document < "u" ? document.title : "", g = m === "/" || m === "", _ = null;
30072
+ })), n = a ? je(a) : null, d = !!n?.transcript, f = !!(a && Ve(a)), p = typeof window < "u" ? window.location.pathname : "/", m = typeof document < "u" ? document.title : "", h = p === "/" || p === "", g = null;
30105
30073
  try {
30106
30074
  let e = await fetch(`${s}/api/voice/signed-url?siteId=${encodeURIComponent(a || "")}`, {
30107
30075
  method: "GET",
30108
30076
  headers: { "Content-Type": "application/json" }
30109
30077
  });
30110
- if (e.ok) _ = (await e.json()).signedUrl || null, _ && console.log("[FlowEngage] ✅ Using signed ElevenLabs URL");
30078
+ if (e.ok) g = (await e.json()).signedUrl || null, g && console.log("[FlowEngage] ✅ Using signed ElevenLabs URL");
30111
30079
  else if (e.status === 429) {
30112
30080
  let t = await e.json().catch(() => ({}));
30113
30081
  throw Error(t.message || "Too many voice sessions started. Please wait a minute before trying again.");
@@ -30116,38 +30084,16 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30116
30084
  if (e.message && e.message.includes("Too many voice sessions")) throw e;
30117
30085
  console.warn("[FlowEngage] ⚠️ Signed URL fetch error:", e.message);
30118
30086
  }
30119
- if (typeof window < "u" && (window.AudioContext || window.webkitAudioContext)) try {
30120
- let e = new (window.AudioContext || window.webkitAudioContext)();
30121
- me.current = e, (async () => {
30122
- try {
30123
- let t = new URLSearchParams({ siteId: a || "" });
30124
- i && t.set("voiceId", i);
30125
- let n = await fetch(`${s}/api/voice/fillers?${t}`);
30126
- if (!n.ok) return;
30127
- let r = await n.json();
30128
- if (!r.success || !Array.isArray(r.fillers) || !r.fillers.length) return;
30129
- let o = (await Promise.all(r.fillers.map(async (t) => {
30130
- try {
30131
- let n = Uint8Array.from(atob(t), (e) => e.charCodeAt(0));
30132
- return await e.decodeAudioData(n.buffer);
30133
- } catch {
30134
- return null;
30135
- }
30136
- }))).filter(Boolean);
30137
- o.length && (pe.current = o, console.log(`[FlowEngage] 🔊 ${o.length} filler clips ready`));
30138
- } catch {}
30139
- })();
30140
- } catch {}
30141
- let y = {
30087
+ let _ = {
30142
30088
  clientTools: t,
30143
30089
  connectionType: "websocket",
30144
- ..._ ? { signedUrl: _ } : { agentId: r }
30145
- }, x = (m.split("/").filter(Boolean).pop() || "").replace(/[-_]/g, " ").replace(/\b\w/g, (e) => e.toUpperCase()), S = "";
30146
- h && h.includes("|") && (S = h.split("|").map((e) => e.trim()).filter(Boolean).reduce((e, t) => e.length <= t.length ? e : t));
30147
- let T = S || x || "this page";
30148
- _ ? p ? (y.overrides = { agent: { firstMessage: `I've navigated you to the ${T} page. Let me walk you through what's here.` } }, console.log(`[FlowEngage] 🔄 Agent-nav resume: firstMessage set for "${T}" (${m})`)) : d ? y.overrides = { agent: { firstMessage: "I'm still here. Go ahead!" } } : g || (y.overrides = { agent: { firstMessage: `Hi! I see you are currently on the ${T} page. Are you looking for something specific here?` } }, console.log(`[FlowEngage] 🏠 Page-context override: "${T}" for ${m}`)) : d && (y.overrides = { agent: { firstMessage: "" } });
30149
- let oe = !1, he = p ? `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, ge = await _D.startSession({
30150
- ...y,
30090
+ ...g ? { signedUrl: g } : { agentId: r }
30091
+ }, y = (p.split("/").filter(Boolean).pop() || "").replace(/[-_]/g, " ").replace(/\b\w/g, (e) => e.toUpperCase()), x = "";
30092
+ m && m.includes("|") && (x = m.split("|").map((e) => e.trim()).filter(Boolean).reduce((e, t) => e.length <= t.length ? e : t));
30093
+ let S = x || y || "this page";
30094
+ 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: "" } });
30095
+ 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({
30096
+ ..._,
30151
30097
  onConnect: ({ conversationId: e }) => {
30152
30098
  ie.current = e, ae.current = Date.now(), console.log("[FlowEngage] 🎙️ AI chat session connected:", e);
30153
30099
  },
@@ -30155,15 +30101,15 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30155
30101
  onModeChange: ({ mode: t }) => {
30156
30102
  if (!e) {
30157
30103
  if (t === "speaking") {
30158
- ye(), de.current &&= (clearTimeout(de.current), null), v("speaking"), ce.current = "speaking", le.current = !0, fe.current = !1, ue.current &&= (clearTimeout(ue.current), null);
30104
+ de.current &&= (clearTimeout(de.current), null), v("speaking"), ce.current = "speaking", le.current = !0, fe.current = !1, ue.current &&= (clearTimeout(ue.current), null);
30159
30105
  return;
30160
30106
  }
30161
30107
  if (ce.current = "listening", se.current) {
30162
- se.current = !1, _e();
30108
+ se.current = !1, pe();
30163
30109
  return;
30164
30110
  }
30165
- if (he && !oe) {
30166
- oe = !0;
30111
+ if (oe && !T) {
30112
+ T = !0;
30167
30113
  try {
30168
30114
  C.current?.sendUserMessage?.("continue with the tour");
30169
30115
  } catch {}
@@ -30181,7 +30127,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30181
30127
  if (e) return;
30182
30128
  let n = t.role === "user" ? "user" : "bot", r = t.message || t.text || t.content || "";
30183
30129
  if (r) {
30184
- if (n === "user" && (w.current = r, fe.current = !0, de.current &&= (clearTimeout(de.current), null), ce.current = "thinking", ue.current &&= (clearTimeout(ue.current), null), be()), u.current = [...u.current, {
30130
+ if (n === "user" && (w.current = r, fe.current = !0, de.current &&= (clearTimeout(de.current), null), ce.current = "thinking", ue.current &&= (clearTimeout(ue.current), null)), u.current = [...u.current, {
30185
30131
  sender: n,
30186
30132
  message: r,
30187
30133
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
@@ -30190,13 +30136,13 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30190
30136
  e && Ae(a, e);
30191
30137
  } catch {}
30192
30138
  if (Ak(n, r)) {
30193
- _e("minimized");
30139
+ pe("minimized");
30194
30140
  return;
30195
30141
  }
30196
30142
  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 {
30197
30143
  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.");
30198
30144
  } catch {}
30199
- else D.current >= 5 && _e("minimized");
30145
+ else D.current >= 5 && pe("minimized");
30200
30146
  }
30201
30147
  },
30202
30148
  onError: (t) => {
@@ -30209,7 +30155,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30209
30155
  try {
30210
30156
  C.current?.setMicMuted?.(!0);
30211
30157
  } catch {}
30212
- b(!0), v("error"), _e("chat");
30158
+ b(!0), v("error"), pe("chat");
30213
30159
  }
30214
30160
  },
30215
30161
  onDisconnect: (t) => {
@@ -30226,21 +30172,21 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30226
30172
  try {
30227
30173
  C.current?.setMicMuted?.(!0);
30228
30174
  } catch {}
30229
- b(!0), _e("chat");
30175
+ b(!0), pe("chat");
30230
30176
  }
30231
30177
  });
30232
30178
  if (e) {
30233
- ge.endSession().catch(() => {});
30179
+ me.endSession().catch(() => {});
30234
30180
  return;
30235
30181
  }
30236
- o = ge, C.current = ge, v("listening");
30182
+ i = me, C.current = me, v("listening");
30237
30183
  try {
30238
30184
  let e = typeof window < "u" ? window.location.href : "", r = "[]";
30239
30185
  try {
30240
30186
  r = await t.list_page_forms();
30241
30187
  } catch {}
30242
- let i = d && !p ? `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` : "";
30243
- ge.sendContextualUpdate(`${i}Page: ${e}. SiteId: ${a || "unknown"}. Forms: ${r}. Voice: call end_voice_session or say you are ending the session to stop.`);
30188
+ 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` : "";
30189
+ me.sendContextualUpdate(`${i}Page: ${e}. SiteId: ${a || "unknown"}. Forms: ${r}. Voice: call end_voice_session or say you are ending the session to stop.`);
30244
30190
  } catch {}
30245
30191
  if (typeof window < "u") {
30246
30192
  let t = window.location.pathname, n = () => {
@@ -30260,9 +30206,9 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30260
30206
  C.current?.sendContextualUpdate?.(`PAGE CHANGED — visitor navigated manually. Current URL is now: ${r}. Page title: "${i}". Sections on this page: ${JSON.stringify(a)}. When the visitor asks about "this page", "current page", or "what page am I on", refer to this new URL — not any previously mentioned page.`);
30261
30207
  } catch {}
30262
30208
  };
30263
- c = window.history.pushState.bind(window.history), window.history.pushState = (...e) => {
30264
- c(...e), setTimeout(n, 50);
30265
- }, f = () => setTimeout(n, 50), window.addEventListener("popstate", f);
30209
+ o = window.history.pushState.bind(window.history), window.history.pushState = (...e) => {
30210
+ o(...e), setTimeout(n, 50);
30211
+ }, c = () => setTimeout(n, 50), window.addEventListener("popstate", c);
30266
30212
  }
30267
30213
  } catch (r) {
30268
30214
  e || (console.error("[FlowEngage] startSession failed", r), r.message && r.message.includes("Too many voice sessions") ? (alert(r.message), n && n("minimized")) : (v("error"), E.current = "chat", window.setTimeout(() => {
@@ -30270,14 +30216,8 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30270
30216
  }, 0)));
30271
30217
  }
30272
30218
  })(), () => {
30273
- if (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", he.current) {
30274
- try {
30275
- he.current.stop();
30276
- } catch {}
30277
- he.current = null;
30278
- }
30279
- me.current && (me.current.close().catch(() => {}), me.current = null, pe.current = [], ge.current = null), c && typeof window < "u" && (window.history.pushState = c), f && typeof window < "u" && window.removeEventListener("popstate", f);
30280
- let t = o || C.current, n = ie.current, r = ae.current;
30219
+ 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);
30220
+ let t = i || C.current, n = ie.current, r = ae.current;
30281
30221
  if (t?.endSession?.().catch(() => {}), n && l && s) {
30282
30222
  let e = r ? Math.round((Date.now() - r) / 1e3) : 0, t = JSON.stringify({
30283
30223
  chatId: l,
@@ -30298,7 +30238,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30298
30238
  r,
30299
30239
  a,
30300
30240
  s,
30301
- _e
30241
+ pe
30302
30242
  ]), c(() => {
30303
30243
  if (!x) return;
30304
30244
  let e = (e) => {
@@ -30484,7 +30424,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30484
30424
  children: [
30485
30425
  /* @__PURE__ */ _("button", {
30486
30426
  onClick: () => {
30487
- S(!1), E.current = "chat", ve(t);
30427
+ S(!1), E.current = "chat", me(t);
30488
30428
  },
30489
30429
  style: {
30490
30430
  display: "flex",
@@ -30513,7 +30453,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
30513
30453
  }),
30514
30454
  /* @__PURE__ */ _("button", {
30515
30455
  onClick: () => {
30516
- S(!1), E.current = "minimized", ve(n);
30456
+ S(!1), E.current = "minimized", me(n);
30517
30457
  },
30518
30458
  style: {
30519
30459
  display: "flex",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowengage/react-chatbot",
3
- "version": "5.0.46",
3
+ "version": "5.0.47",
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",