@flowengage/react-chatbot 5.0.44 → 5.0.46
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.
|
@@ -29387,10 +29387,10 @@ function Ck(e) {
|
|
|
29387
29387
|
$("flowengage_navigate → real navigation", a);
|
|
29388
29388
|
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]"));
|
|
29389
29389
|
if (typeof window < "u" && window.__fe_triggerVoiceNavHooks && window.__fe_triggerVoiceNavHooks(), e && qn(3e3), Tr(a, { voiceActive: !0 }).catch(() => {}), e) try {
|
|
29390
|
-
let e = new URL(a, window.location.origin).pathname;
|
|
29391
|
-
await new Promise((e) => setTimeout(e,
|
|
29392
|
-
let
|
|
29393
|
-
return $("flowengage_navigate → SPA nav complete. target:", e, "actual:",
|
|
29390
|
+
let e = new URL(a, window.location.origin).pathname, t = Date.now() + 2e3;
|
|
29391
|
+
for (; Date.now() < t && !(typeof window < "u" && window.location.pathname === e);) await new Promise((e) => setTimeout(e, 80));
|
|
29392
|
+
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";
|
|
29393
|
+
return $("flowengage_navigate → SPA nav complete. target:", e, "actual:", n), i ? `OK_NAVIGATE_SPA. Visitor is now on: ${r} (page: "${o}"). Do NOT say "I have navigated you" or "I've taken you to" — the page is already loaded visually. Start immediately with highlights and content about THIS page.` : `OK_NAVIGATE_SPA. CURRENT PAGE IS: ${r} (page: "${o}"). The visitor manually navigated here. Describe THIS page only — do not mention the page you tried to navigate to.`;
|
|
29394
29394
|
} catch {}
|
|
29395
29395
|
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.";
|
|
29396
29396
|
} catch (e) {
|
|
@@ -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 = 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 = p([]), me = p(null), he = p(null), ge = p(null), _e = 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]),
|
|
29995
|
+
}, [u]), ve = o(async (e) => {
|
|
29996
29996
|
re.current = !0;
|
|
29997
29997
|
try {
|
|
29998
29998
|
CD();
|
|
@@ -30025,12 +30025,44 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
|
|
|
30025
30025
|
l,
|
|
30026
30026
|
s
|
|
30027
30027
|
]);
|
|
30028
|
-
|
|
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(() => {
|
|
30029
30061
|
te.current = y;
|
|
30030
30062
|
}, [y]), c(() => {
|
|
30031
|
-
f &&
|
|
30063
|
+
f && _e("chat");
|
|
30032
30064
|
}, [f]), c(() => {
|
|
30033
|
-
let e = !1,
|
|
30065
|
+
let e = !1, o = null, c = null, f = null;
|
|
30034
30066
|
return (async () => {
|
|
30035
30067
|
if (!r) {
|
|
30036
30068
|
v("error");
|
|
@@ -30069,13 +30101,13 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
|
|
|
30069
30101
|
requestEndSession: () => {
|
|
30070
30102
|
se.current = !0;
|
|
30071
30103
|
}
|
|
30072
|
-
})), n = a ? je(a) : null, d = !!n?.transcript,
|
|
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;
|
|
30073
30105
|
try {
|
|
30074
30106
|
let e = await fetch(`${s}/api/voice/signed-url?siteId=${encodeURIComponent(a || "")}`, {
|
|
30075
30107
|
method: "GET",
|
|
30076
30108
|
headers: { "Content-Type": "application/json" }
|
|
30077
30109
|
});
|
|
30078
|
-
if (e.ok)
|
|
30110
|
+
if (e.ok) _ = (await e.json()).signedUrl || null, _ && console.log("[FlowEngage] ✅ Using signed ElevenLabs URL");
|
|
30079
30111
|
else if (e.status === 429) {
|
|
30080
30112
|
let t = await e.json().catch(() => ({}));
|
|
30081
30113
|
throw Error(t.message || "Too many voice sessions started. Please wait a minute before trying again.");
|
|
@@ -30084,16 +30116,38 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
|
|
|
30084
30116
|
if (e.message && e.message.includes("Too many voice sessions")) throw e;
|
|
30085
30117
|
console.warn("[FlowEngage] ⚠️ Signed URL fetch error:", e.message);
|
|
30086
30118
|
}
|
|
30087
|
-
|
|
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 = {
|
|
30088
30142
|
clientTools: t,
|
|
30089
30143
|
connectionType: "websocket",
|
|
30090
|
-
...
|
|
30091
|
-
},
|
|
30092
|
-
|
|
30093
|
-
let
|
|
30094
|
-
|
|
30095
|
-
let
|
|
30096
|
-
...
|
|
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,
|
|
30097
30151
|
onConnect: ({ conversationId: e }) => {
|
|
30098
30152
|
ie.current = e, ae.current = Date.now(), console.log("[FlowEngage] 🎙️ AI chat session connected:", e);
|
|
30099
30153
|
},
|
|
@@ -30101,15 +30155,15 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
|
|
|
30101
30155
|
onModeChange: ({ mode: t }) => {
|
|
30102
30156
|
if (!e) {
|
|
30103
30157
|
if (t === "speaking") {
|
|
30104
|
-
de.current &&= (clearTimeout(de.current), null), v("speaking"), ce.current = "speaking", le.current = !0, fe.current = !1, ue.current &&= (clearTimeout(ue.current), null);
|
|
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);
|
|
30105
30159
|
return;
|
|
30106
30160
|
}
|
|
30107
30161
|
if (ce.current = "listening", se.current) {
|
|
30108
|
-
se.current = !1,
|
|
30162
|
+
se.current = !1, _e();
|
|
30109
30163
|
return;
|
|
30110
30164
|
}
|
|
30111
|
-
if (
|
|
30112
|
-
|
|
30165
|
+
if (he && !oe) {
|
|
30166
|
+
oe = !0;
|
|
30113
30167
|
try {
|
|
30114
30168
|
C.current?.sendUserMessage?.("continue with the tour");
|
|
30115
30169
|
} catch {}
|
|
@@ -30127,7 +30181,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
|
|
|
30127
30181
|
if (e) return;
|
|
30128
30182
|
let n = t.role === "user" ? "user" : "bot", r = t.message || t.text || t.content || "";
|
|
30129
30183
|
if (r) {
|
|
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, {
|
|
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, {
|
|
30131
30185
|
sender: n,
|
|
30132
30186
|
message: r,
|
|
30133
30187
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -30136,13 +30190,13 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
|
|
|
30136
30190
|
e && Ae(a, e);
|
|
30137
30191
|
} catch {}
|
|
30138
30192
|
if (Ak(n, r)) {
|
|
30139
|
-
|
|
30193
|
+
_e("minimized");
|
|
30140
30194
|
return;
|
|
30141
30195
|
}
|
|
30142
30196
|
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 {
|
|
30143
30197
|
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.");
|
|
30144
30198
|
} catch {}
|
|
30145
|
-
else D.current >= 5 &&
|
|
30199
|
+
else D.current >= 5 && _e("minimized");
|
|
30146
30200
|
}
|
|
30147
30201
|
},
|
|
30148
30202
|
onError: (t) => {
|
|
@@ -30155,7 +30209,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
|
|
|
30155
30209
|
try {
|
|
30156
30210
|
C.current?.setMicMuted?.(!0);
|
|
30157
30211
|
} catch {}
|
|
30158
|
-
b(!0), v("error"),
|
|
30212
|
+
b(!0), v("error"), _e("chat");
|
|
30159
30213
|
}
|
|
30160
30214
|
},
|
|
30161
30215
|
onDisconnect: (t) => {
|
|
@@ -30172,21 +30226,21 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
|
|
|
30172
30226
|
try {
|
|
30173
30227
|
C.current?.setMicMuted?.(!0);
|
|
30174
30228
|
} catch {}
|
|
30175
|
-
b(!0),
|
|
30229
|
+
b(!0), _e("chat");
|
|
30176
30230
|
}
|
|
30177
30231
|
});
|
|
30178
30232
|
if (e) {
|
|
30179
|
-
|
|
30233
|
+
ge.endSession().catch(() => {});
|
|
30180
30234
|
return;
|
|
30181
30235
|
}
|
|
30182
|
-
|
|
30236
|
+
o = ge, C.current = ge, v("listening");
|
|
30183
30237
|
try {
|
|
30184
30238
|
let e = typeof window < "u" ? window.location.href : "", r = "[]";
|
|
30185
30239
|
try {
|
|
30186
30240
|
r = await t.list_page_forms();
|
|
30187
30241
|
} catch {}
|
|
30188
|
-
let i = d && !
|
|
30189
|
-
|
|
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.`);
|
|
30190
30244
|
} catch {}
|
|
30191
30245
|
if (typeof window < "u") {
|
|
30192
30246
|
let t = window.location.pathname, n = () => {
|
|
@@ -30206,9 +30260,9 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
|
|
|
30206
30260
|
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.`);
|
|
30207
30261
|
} catch {}
|
|
30208
30262
|
};
|
|
30209
|
-
|
|
30210
|
-
|
|
30211
|
-
},
|
|
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);
|
|
30212
30266
|
}
|
|
30213
30267
|
} catch (r) {
|
|
30214
30268
|
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(() => {
|
|
@@ -30216,8 +30270,14 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
|
|
|
30216
30270
|
}, 0)));
|
|
30217
30271
|
}
|
|
30218
30272
|
})(), () => {
|
|
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",
|
|
30220
|
-
|
|
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;
|
|
30221
30281
|
if (t?.endSession?.().catch(() => {}), n && l && s) {
|
|
30222
30282
|
let e = r ? Math.round((Date.now() - r) / 1e3) : 0, t = JSON.stringify({
|
|
30223
30283
|
chatId: l,
|
|
@@ -30238,7 +30298,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
|
|
|
30238
30298
|
r,
|
|
30239
30299
|
a,
|
|
30240
30300
|
s,
|
|
30241
|
-
|
|
30301
|
+
_e
|
|
30242
30302
|
]), c(() => {
|
|
30243
30303
|
if (!x) return;
|
|
30244
30304
|
let e = (e) => {
|
|
@@ -30424,7 +30484,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
|
|
|
30424
30484
|
children: [
|
|
30425
30485
|
/* @__PURE__ */ _("button", {
|
|
30426
30486
|
onClick: () => {
|
|
30427
|
-
S(!1), E.current = "chat",
|
|
30487
|
+
S(!1), E.current = "chat", ve(t);
|
|
30428
30488
|
},
|
|
30429
30489
|
style: {
|
|
30430
30490
|
display: "flex",
|
|
@@ -30453,7 +30513,7 @@ function Pk({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, voiceId: i
|
|
|
30453
30513
|
}),
|
|
30454
30514
|
/* @__PURE__ */ _("button", {
|
|
30455
30515
|
onClick: () => {
|
|
30456
|
-
S(!1), E.current = "minimized",
|
|
30516
|
+
S(!1), E.current = "minimized", ve(n);
|
|
30457
30517
|
},
|
|
30458
30518
|
style: {
|
|
30459
30519
|
display: "flex",
|