@flowengage/react-chatbot 1.2.0 → 1.2.1
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.
|
@@ -1945,109 +1945,108 @@ function ln(e, t) {
|
|
|
1945
1945
|
let n = cn(e).slice(-Math.min(t, 28)), r = n.filter((e) => e.length > 2 && !sn.has(e));
|
|
1946
1946
|
return r.length >= 2 ? r : n.filter((e) => e.length > 2).slice(-12);
|
|
1947
1947
|
}
|
|
1948
|
-
function un(e, t) {
|
|
1948
|
+
function un(e, t, { strict: n = !1 } = {}) {
|
|
1949
1949
|
if (!e || !t?.length) return null;
|
|
1950
|
-
let
|
|
1951
|
-
for (let e of
|
|
1950
|
+
let r = e.querySelectorAll("h1, h2, h3, h4, h5, h6, p, li, blockquote, [data-plan], [class*='pricing'] h2, [class*='pricing'] h3, section h2, section h3"), i = null, a = 0;
|
|
1951
|
+
for (let e of r) {
|
|
1952
1952
|
if (Qt(e)) continue;
|
|
1953
1953
|
try {
|
|
1954
1954
|
if (e.closest("aside, nav, [role='navigation'], [role='banner'], footer")) continue;
|
|
1955
1955
|
} catch {}
|
|
1956
1956
|
let n = e.textContent.replace(/\s+/g, " ").toLowerCase();
|
|
1957
1957
|
if (n.length < 3 || n.length > 6e3) continue;
|
|
1958
|
-
let
|
|
1959
|
-
for (let e of t) n.includes(e) &&
|
|
1960
|
-
let o =
|
|
1958
|
+
let r = 0;
|
|
1959
|
+
for (let e of t) n.includes(e) && r++;
|
|
1960
|
+
let o = r / t.length;
|
|
1961
1961
|
if (o < .2) continue;
|
|
1962
1962
|
let s = o, c = e.tagName;
|
|
1963
|
-
(c === "H2" || c === "H3" || c === "H4") && (s *= 1.35), (c === "P" || c === "BLOCKQUOTE") && (s *= 1.15), c?.startsWith("H") && n.length < 80 && (s *= 1.2), n.length > 400 && (s *= .65), s >
|
|
1963
|
+
(c === "H2" || c === "H3" || c === "H4") && (s *= 1.35), (c === "P" || c === "BLOCKQUOTE") && (s *= 1.15), c?.startsWith("H") && n.length < 80 && (s *= 1.2), n.length > 400 && (s *= .65), s > a && (a = s, i = e);
|
|
1964
1964
|
}
|
|
1965
|
-
let
|
|
1966
|
-
return
|
|
1965
|
+
let o = n ? t.length <= 1 ? .62 : .5 : t.length <= 1 ? .55 : .35;
|
|
1966
|
+
return a >= o ? i : null;
|
|
1967
1967
|
}
|
|
1968
1968
|
function dn(e) {
|
|
1969
1969
|
return /^H[1-6]$/i.test(e?.tagName || "");
|
|
1970
1970
|
}
|
|
1971
|
-
function fn(e, t) {
|
|
1971
|
+
function fn(e, t, n = !1) {
|
|
1972
1972
|
if (!e || !t) return null;
|
|
1973
|
-
let
|
|
1974
|
-
if (
|
|
1975
|
-
let
|
|
1976
|
-
if (
|
|
1977
|
-
let
|
|
1978
|
-
for (let e of
|
|
1973
|
+
let r = t.replace(/\s+/g, " ").trim();
|
|
1974
|
+
if (r.length < 14) return null;
|
|
1975
|
+
let i = n ? .34 : .24, a = r.toLowerCase(), o = ln(r, 24);
|
|
1976
|
+
if (o.length < 3 && (o = a.replace(/[^\w\s'-]/g, " ").split(/\s+/).filter((e) => e.length > 2).slice(-18)), o.length < 3) return null;
|
|
1977
|
+
let s = e.querySelectorAll("p, blockquote"), c = null, l = 0;
|
|
1978
|
+
for (let e of s) {
|
|
1979
1979
|
if (Qt(e)) continue;
|
|
1980
1980
|
let t = e.textContent.replace(/\s+/g, " ").toLowerCase();
|
|
1981
1981
|
if (t.length < 24) continue;
|
|
1982
1982
|
let n = 0;
|
|
1983
|
-
for (let e of
|
|
1984
|
-
let
|
|
1985
|
-
for (let e = Math.min(90,
|
|
1986
|
-
let n =
|
|
1983
|
+
for (let e of o) t.includes(e) && n++;
|
|
1984
|
+
let r = n / o.length, s = 0;
|
|
1985
|
+
for (let e = Math.min(90, a.length); e >= 22; e -= 6) {
|
|
1986
|
+
let n = a.slice(-e).trim();
|
|
1987
1987
|
if (n.length >= 22 && t.includes(n)) {
|
|
1988
|
-
|
|
1988
|
+
s = .28;
|
|
1989
1989
|
break;
|
|
1990
1990
|
}
|
|
1991
1991
|
}
|
|
1992
|
-
let
|
|
1993
|
-
|
|
1992
|
+
let u = r + s;
|
|
1993
|
+
u > l && r >= i && (l = u, c = e);
|
|
1994
1994
|
}
|
|
1995
|
-
return
|
|
1995
|
+
return c;
|
|
1996
1996
|
}
|
|
1997
|
-
function pn(e) {
|
|
1997
|
+
function pn(e, t = {}) {
|
|
1998
1998
|
if (typeof document > "u" || !e || !String(e).trim()) return null;
|
|
1999
|
-
let t = String(e).trim(),
|
|
2000
|
-
if (
|
|
2001
|
-
let e = fn(
|
|
1999
|
+
let n = t.strict === !0, r = String(e).trim(), i = r.length > 450 ? r.slice(-450).trim() : r, a = on(), o = ln(r, 26);
|
|
2000
|
+
if (r.length >= (n ? 55 : 42)) {
|
|
2001
|
+
let e = fn(a, i, n);
|
|
2002
2002
|
if (e) return e;
|
|
2003
2003
|
}
|
|
2004
|
-
if (
|
|
2005
|
-
let e = un(
|
|
2004
|
+
if ((!n || o.length >= 3 || o.length === 2 && o.every((e) => e.length >= 5)) && (o.length >= 2 || o.length === 1 && o[0].length >= 5)) {
|
|
2005
|
+
let e = un(a, o, { strict: n });
|
|
2006
2006
|
if (e) return e;
|
|
2007
2007
|
}
|
|
2008
|
-
let
|
|
2009
|
-
|
|
2010
|
-
for (let e = 4; e <= Math.min(10,
|
|
2011
|
-
for (let e = Math.min(14,
|
|
2012
|
-
for (let e = Math.min(8,
|
|
2013
|
-
let
|
|
2014
|
-
for (let e of
|
|
2015
|
-
let
|
|
2016
|
-
if (
|
|
2017
|
-
|
|
2018
|
-
let
|
|
2019
|
-
if (
|
|
2020
|
-
if (dn(
|
|
2021
|
-
let e = (
|
|
2022
|
-
for (let
|
|
2008
|
+
let s = i.split(/(?<=[.!?])\s+/).filter((e) => e.trim().length > 0), c = s[s.length - 1] || i, l = c.toLowerCase().replace(/[^\w\s'-]/g, " ").split(/\s+/).filter((e) => e.length > 2), u = [];
|
|
2009
|
+
c.length >= 10 && (u.push(c.slice(-220).trim()), c.length > 220 && u.push(c.slice(0, 120).trim()));
|
|
2010
|
+
for (let e = 4; e <= Math.min(10, l.length); e++) u.push(l.slice(-e).join(" "));
|
|
2011
|
+
for (let e = Math.min(14, l.length); e >= 11; e--) u.push(l.slice(-e).join(" "));
|
|
2012
|
+
for (let e = Math.min(8, l.length); e >= 3; e--) u.push(l.slice(-e).join(" "));
|
|
2013
|
+
let d = n ? 14 : 6, f = /* @__PURE__ */ new Set();
|
|
2014
|
+
for (let e of u) {
|
|
2015
|
+
let t = e.trim();
|
|
2016
|
+
if (t.length < d || f.has(t)) continue;
|
|
2017
|
+
f.add(t);
|
|
2018
|
+
let n = an(null, t);
|
|
2019
|
+
if (n && !Qt(n)) {
|
|
2020
|
+
if (dn(n) && r.length > 140) {
|
|
2021
|
+
let e = (a.querySelector?.("[itemprop='articleBody'], .article-body, .post-content, .entry-content") || a).querySelectorAll?.("p, blockquote") || [];
|
|
2022
|
+
for (let n of e) if (!Qt(n) && n.textContent.toLowerCase().includes(t.toLowerCase().slice(0, Math.min(48, t.length)))) return n;
|
|
2023
2023
|
}
|
|
2024
|
-
return
|
|
2024
|
+
return n;
|
|
2025
2025
|
}
|
|
2026
2026
|
}
|
|
2027
|
-
let
|
|
2028
|
-
if (
|
|
2029
|
-
let
|
|
2030
|
-
for (let e of
|
|
2027
|
+
let p = o.length >= 3 ? o : l.slice(-22);
|
|
2028
|
+
if (p.length === 0) return null;
|
|
2029
|
+
let m = null, h = -1, g = a.querySelectorAll("h1, h2, h3, h4, h5, h6, p, li, blockquote, article");
|
|
2030
|
+
for (let e of g) {
|
|
2031
2031
|
if (Qt(e)) continue;
|
|
2032
2032
|
try {
|
|
2033
2033
|
if (e.closest("aside, nav, [role='navigation'], footer")) continue;
|
|
2034
2034
|
} catch {}
|
|
2035
|
-
let
|
|
2036
|
-
if (
|
|
2037
|
-
let
|
|
2038
|
-
for (let e of
|
|
2039
|
-
let
|
|
2040
|
-
(
|
|
2035
|
+
let t = e.textContent.toLowerCase();
|
|
2036
|
+
if (t.length < 12) continue;
|
|
2037
|
+
let i = 0;
|
|
2038
|
+
for (let e of p) e.length > 2 && t.includes(e) && i++;
|
|
2039
|
+
let a = i / p.length, o = e.tagName;
|
|
2040
|
+
(o === "P" || o === "BLOCKQUOTE" || o === "LI") && (a *= 1.22), dn(e) && (r.length > 110 ? a *= .48 : a *= .92), o === "ARTICLE" && r.length > 80 && (a *= .55), a > h && a >= (n ? .42 : .28) && (h = a, m = e);
|
|
2041
2041
|
}
|
|
2042
|
-
return
|
|
2042
|
+
return m;
|
|
2043
2043
|
}
|
|
2044
|
-
function mn(e, { speaking: t = !1 } = {}) {
|
|
2044
|
+
function mn(e, { speaking: t = !1, scroll: n = !0 } = {}) {
|
|
2045
2045
|
if (!e || typeof document > "u") return;
|
|
2046
2046
|
rn();
|
|
2047
|
-
let
|
|
2048
|
-
for (let t of
|
|
2049
|
-
e.classList.remove("fe-highlight-exiting"), e.classList.add("fe-highlight-section"), t ? e.classList.add("fe-highlight-speaking") : e.classList.remove("fe-highlight-speaking")
|
|
2050
|
-
try {
|
|
2047
|
+
let r = document.querySelectorAll(".fe-highlight-section");
|
|
2048
|
+
for (let t of r) t !== e && (t.classList.remove("fe-highlight-section", "fe-highlight-speaking"), t.classList.add("fe-highlight-exiting"), setTimeout(() => t.classList.remove("fe-highlight-exiting"), 300));
|
|
2049
|
+
if (e.classList.remove("fe-highlight-exiting"), e.classList.add("fe-highlight-section"), t ? e.classList.add("fe-highlight-speaking") : e.classList.remove("fe-highlight-speaking"), n) try {
|
|
2051
2050
|
e.scrollIntoView({
|
|
2052
2051
|
behavior: "smooth",
|
|
2053
2052
|
block: "center"
|
|
@@ -23020,19 +23019,19 @@ async function f_(e, t, n) {
|
|
|
23020
23019
|
return _g(e), !0;
|
|
23021
23020
|
}
|
|
23022
23021
|
function p_(e) {
|
|
23023
|
-
let t = e.siteId || null, n = (e.apiBaseUrl || "").replace(/\/$/, ""), r =
|
|
23022
|
+
let t = e.siteId || null, n = (e.apiBaseUrl || "").replace(/\/$/, ""), r = e.voicePageHighlightMode || "tool", i = typeof e.getLastUserVoiceText == "function" ? e.getLastUserVoiceText : null, a = [], o = null, s = {
|
|
23024
23023
|
navigate_to_page: async (n) => {
|
|
23025
23024
|
$("navigate_to_page ▶ raw parameters:", n);
|
|
23026
|
-
let
|
|
23025
|
+
let i = r_(n), a = l_(i), o = i.section_text ?? i.sectionText ?? i.section;
|
|
23027
23026
|
if ($("navigate_to_page · coerced:", {
|
|
23028
|
-
url:
|
|
23029
|
-
sectionText:
|
|
23030
|
-
}), !
|
|
23027
|
+
url: a,
|
|
23028
|
+
sectionText: o
|
|
23029
|
+
}), !a) {
|
|
23031
23030
|
let e = "Missing url: pass a string url, path like /pricing, or JSON with a url field.";
|
|
23032
23031
|
return $("navigate_to_page ✖", e), e;
|
|
23033
23032
|
}
|
|
23034
|
-
let
|
|
23035
|
-
if (fg(`Navigating to ${String(
|
|
23033
|
+
let s = typeof window < "u" ? gn(a) : a;
|
|
23034
|
+
if (fg(`Navigating to ${String(s).replace(/^https?:\/\/[^/]+/, "") || "/"}…`), mg(), !await vn(s, {
|
|
23036
23035
|
siteId: t,
|
|
23037
23036
|
apiBaseUrl: e.apiBaseUrl
|
|
23038
23037
|
})) {
|
|
@@ -23041,10 +23040,13 @@ function p_(e) {
|
|
|
23041
23040
|
return $("navigate_to_page ✖ blocked", e), e;
|
|
23042
23041
|
}
|
|
23043
23042
|
try {
|
|
23044
|
-
if ($("navigate_to_page → shadowNavigate",
|
|
23045
|
-
let e = an(null,
|
|
23046
|
-
e && mn(e
|
|
23047
|
-
|
|
23043
|
+
if ($("navigate_to_page → shadowNavigate", s), await bn(s, { sectionText: o || void 0 }), await new Promise((e) => setTimeout(e, 600)), hg(), pg(300), o && typeof o == "string" && r !== "off") {
|
|
23044
|
+
let e = an(null, o);
|
|
23045
|
+
e && mn(e, {
|
|
23046
|
+
speaking: !0,
|
|
23047
|
+
scroll: !0
|
|
23048
|
+
}), $("navigate_to_page · highlight", {
|
|
23049
|
+
sectionText: o,
|
|
23048
23050
|
found: !!e
|
|
23049
23051
|
});
|
|
23050
23052
|
}
|
|
@@ -23056,7 +23058,7 @@ function p_(e) {
|
|
|
23056
23058
|
e = ` This page has a form with fields: [${r}]` + (i ? ` and buttons: [${i}].` : ".") + " Call list_page_forms then start filling.";
|
|
23057
23059
|
}
|
|
23058
23060
|
} catch {}
|
|
23059
|
-
let t = `OK_NAVIGATION ${
|
|
23061
|
+
let t = `OK_NAVIGATION ${s}${e}`;
|
|
23060
23062
|
return $("navigate_to_page ✓", t), t;
|
|
23061
23063
|
} catch (e) {
|
|
23062
23064
|
hg(), pg(200);
|
|
@@ -23065,9 +23067,13 @@ function p_(e) {
|
|
|
23065
23067
|
}
|
|
23066
23068
|
},
|
|
23067
23069
|
highlight_on_page: async (e) => {
|
|
23068
|
-
if ($("highlight_on_page ▶", e), r) return $("highlight_on_page · skipped (
|
|
23070
|
+
if ($("highlight_on_page ▶", e), r === "off") return $("highlight_on_page · skipped (voicePageHighlightMode=off)"), "OK_HIGHLIGHT page highlighting is disabled.";
|
|
23071
|
+
if (r === "transcript") return $("highlight_on_page · skipped (transcript mode owns highlights)"), "OK_HIGHLIGHT Page highlight follows speech in this mode; skip redundant highlight_on_page calls.";
|
|
23069
23072
|
let t = r_(e), n = t?.section_id || t?.sectionId, i = t?.section_text || t?.sectionText, a = an(n || null, i || null);
|
|
23070
|
-
return a ? (mn(a, {
|
|
23073
|
+
return a ? (mn(a, {
|
|
23074
|
+
speaking: !0,
|
|
23075
|
+
scroll: !0
|
|
23076
|
+
}), $("highlight_on_page ✓ (speaking)"), "OK_HIGHLIGHT section is now highlighted and scrolled into view.") : ($("highlight_on_page ✖ no element"), "Could not find that section on the page.");
|
|
23071
23077
|
},
|
|
23072
23078
|
search_site_content: async (e) => {
|
|
23073
23079
|
$("search_site_content ▶", e);
|
|
@@ -23101,7 +23107,7 @@ function p_(e) {
|
|
|
23101
23107
|
},
|
|
23102
23108
|
read_page_content: async (e) => {
|
|
23103
23109
|
$("read_page_content ▶", e);
|
|
23104
|
-
let t = r_(e), n = t?.section_text || t?.sectionText,
|
|
23110
|
+
let t = r_(e), n = t?.section_text || t?.sectionText, i = 3e3;
|
|
23105
23111
|
try {
|
|
23106
23112
|
if (n) {
|
|
23107
23113
|
let e = an(null, n);
|
|
@@ -23110,13 +23116,16 @@ function p_(e) {
|
|
|
23110
23116
|
for (let n = Math.min(t.length, 5); n >= 2 && !e; n--) e = an(null, t.slice(0, n).join(" "));
|
|
23111
23117
|
}
|
|
23112
23118
|
if (!e) return `Could not find a section matching "${n}" on this page. Try navigate_to_page or click_page_button with the article title, then read_page_content again.`;
|
|
23113
|
-
mn(e, {
|
|
23114
|
-
|
|
23119
|
+
r !== "off" && mn(e, {
|
|
23120
|
+
speaking: !0,
|
|
23121
|
+
scroll: !0
|
|
23122
|
+
});
|
|
23123
|
+
let t = Eg(e, i);
|
|
23115
23124
|
return t ? ($("read_page_content ✓ section:", t.length, "chars"), `OK_READ: ${t}`) : "Found the section but it appears to be empty.";
|
|
23116
23125
|
}
|
|
23117
23126
|
let e = Og(Dg());
|
|
23118
23127
|
if (!e) return "Could not determine the main content area of this page.";
|
|
23119
|
-
let t = Eg(e,
|
|
23128
|
+
let t = Eg(e, i);
|
|
23120
23129
|
return t ? ($("read_page_content ✓ page:", t.length, "chars"), `OK_READ: ${t}`) : "The page appears to have no readable text content.";
|
|
23121
23130
|
} catch (e) {
|
|
23122
23131
|
return $("read_page_content ✖", e?.message), `Error reading page content: ${e?.message || "unknown error"}`;
|
|
@@ -23297,141 +23306,145 @@ function y_(e, t) {
|
|
|
23297
23306
|
let n = (t || "").trim();
|
|
23298
23307
|
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;
|
|
23299
23308
|
}
|
|
23300
|
-
function b_({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, historyRef: d, hasSyncedRef: f, onMessageSync: p, onStartSync: m }) {
|
|
23301
|
-
let [
|
|
23302
|
-
|
|
23309
|
+
function b_({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, historyRef: d, hasSyncedRef: f, onMessageSync: p, onStartSync: m, voicePageHighlightMode: h = "tool" }) {
|
|
23310
|
+
let [g, ee] = s("idle"), [te, _] = s(null), [ne, re] = s(!1), ie = o(null), ae = o(null), oe = o(""), se = o(async () => {}), v = o(!1), ce = o(""), le = o(null), ue = o(null), y = o(null), b = o(null), de = o(null), fe = o(!1), pe = n(() => {
|
|
23311
|
+
y.current &&= (clearTimeout(y.current), null), b.current &&= (clearInterval(b.current), null), ce.current = "", le.current = null, ue.current = null, fe.current = !1, de.current != null && (cancelAnimationFrame(de.current), de.current = null);
|
|
23303
23312
|
try {
|
|
23304
23313
|
hn();
|
|
23305
23314
|
} catch {}
|
|
23306
|
-
}, []),
|
|
23307
|
-
|
|
23315
|
+
}, []), me = n(async () => {
|
|
23316
|
+
pe();
|
|
23308
23317
|
try {
|
|
23309
|
-
await
|
|
23318
|
+
await ie.current?.endSession?.();
|
|
23310
23319
|
} catch {}
|
|
23311
|
-
|
|
23320
|
+
ie.current = null, re(!1), ee("idle"), v.current = !1, typeof p == "function" && await p(d.current), typeof c == "function" && c();
|
|
23312
23321
|
}, [
|
|
23313
|
-
|
|
23322
|
+
pe,
|
|
23314
23323
|
d,
|
|
23315
23324
|
p,
|
|
23316
23325
|
c
|
|
23317
23326
|
]);
|
|
23318
|
-
|
|
23327
|
+
se.current = me, i(() => {
|
|
23319
23328
|
let t = !1, n = null;
|
|
23320
23329
|
return (async () => {
|
|
23321
23330
|
try {
|
|
23322
23331
|
if (await navigator.mediaDevices.getUserMedia({ audio: !0 }), t) return;
|
|
23323
|
-
d.current = [],
|
|
23324
|
-
let i = m_(p_({
|
|
23332
|
+
d.current = [], oe.current = "", v.current = !1, fe.current = !1;
|
|
23333
|
+
let i = h === "transcript", o = m_(p_({
|
|
23325
23334
|
siteId: r || null,
|
|
23326
23335
|
apiBaseUrl: a || null,
|
|
23327
|
-
getLastUserVoiceText: () =>
|
|
23328
|
-
|
|
23336
|
+
getLastUserVoiceText: () => oe.current,
|
|
23337
|
+
voicePageHighlightMode: h,
|
|
23329
23338
|
requestEndSession: () => {
|
|
23330
23339
|
queueMicrotask(() => {
|
|
23331
|
-
|
|
23340
|
+
v.current || (v.current = !0, se.current?.());
|
|
23332
23341
|
});
|
|
23333
23342
|
}
|
|
23334
|
-
})),
|
|
23343
|
+
})), s = () => {
|
|
23335
23344
|
try {
|
|
23336
|
-
|
|
23345
|
+
if (!i || !fe.current) return;
|
|
23346
|
+
let e = ce.current, t = le.current;
|
|
23337
23347
|
if (!e?.trim() || t == null) return;
|
|
23338
|
-
let n =
|
|
23348
|
+
let n = ue.current, r = Date.now(), a;
|
|
23339
23349
|
if (n != null) {
|
|
23340
|
-
let t = Math.max(0, (r - n) / 1e3)
|
|
23341
|
-
|
|
23350
|
+
let t = Math.max(0, (r - n) / 1e3);
|
|
23351
|
+
a = Math.min(e.length, Math.floor(t * __));
|
|
23342
23352
|
} else {
|
|
23343
23353
|
let n = Math.max(0, (r - t) / 1e3);
|
|
23344
|
-
if (n > 2.1 && e.length > 36)
|
|
23354
|
+
if (n > 2.1 && e.length > 36) a = Math.min(e.length, Math.floor(Math.max(0, n - .4) * __));
|
|
23345
23355
|
else {
|
|
23346
23356
|
let t = Math.min(96, Math.floor(n * v_));
|
|
23347
|
-
|
|
23357
|
+
a = Math.min(e.length, t);
|
|
23348
23358
|
}
|
|
23349
23359
|
}
|
|
23350
|
-
let
|
|
23351
|
-
if (
|
|
23360
|
+
let o = e.slice(0, a);
|
|
23361
|
+
if (o.trim().length < 6) return;
|
|
23352
23362
|
rn();
|
|
23353
|
-
let
|
|
23354
|
-
|
|
23363
|
+
let s = pn(o, { strict: !0 });
|
|
23364
|
+
s && mn(s, {
|
|
23365
|
+
speaking: !0,
|
|
23366
|
+
scroll: !1
|
|
23367
|
+
});
|
|
23355
23368
|
} catch (e) {
|
|
23356
23369
|
console.warn("[VoiceInterface] speech highlight failed", e?.message);
|
|
23357
23370
|
}
|
|
23358
|
-
}, s = () => {
|
|
23359
|
-
b.current ??= requestAnimationFrame(() => {
|
|
23360
|
-
b.current = null, o();
|
|
23361
|
-
});
|
|
23362
23371
|
}, c = () => {
|
|
23363
|
-
|
|
23364
|
-
|
|
23365
|
-
}
|
|
23372
|
+
de.current ??= requestAnimationFrame(() => {
|
|
23373
|
+
de.current = null, s();
|
|
23374
|
+
});
|
|
23366
23375
|
}, l = () => {
|
|
23367
|
-
y.current
|
|
23368
|
-
|
|
23376
|
+
y.current && clearTimeout(y.current), y.current = setTimeout(() => {
|
|
23377
|
+
y.current = null, s();
|
|
23378
|
+
}, 120);
|
|
23379
|
+
}, u = () => {
|
|
23380
|
+
b.current ||= setInterval(() => {
|
|
23381
|
+
s();
|
|
23369
23382
|
}, 160);
|
|
23370
|
-
},
|
|
23383
|
+
}, f = await Bh.startSession({
|
|
23371
23384
|
agentId: e,
|
|
23372
|
-
clientTools:
|
|
23385
|
+
clientTools: o,
|
|
23373
23386
|
onUnhandledClientToolCall: (e) => {
|
|
23374
23387
|
console.error("[VoiceInterface] ElevenLabs requested a client tool that is not registered in the widget:", e?.tool_name, e?.parameters, "Add a matching handler in voiceClientTools (snake_case and camelCase are both supported).");
|
|
23375
23388
|
},
|
|
23376
23389
|
onModeChange: ({ mode: e }) => {
|
|
23377
|
-
t ||
|
|
23390
|
+
t || ee(e === "speaking" ? "speaking" : "listening");
|
|
23378
23391
|
},
|
|
23379
23392
|
onAudio: () => {
|
|
23380
|
-
t || (
|
|
23393
|
+
t || !i || (ue.current ??= Date.now(), u(), c());
|
|
23381
23394
|
},
|
|
23382
23395
|
onAgentChatResponsePart: (e) => {
|
|
23383
23396
|
if (t) return;
|
|
23384
|
-
let n = e?.text_response_part ?? e, r = n?.type,
|
|
23385
|
-
r === "start" ? (
|
|
23397
|
+
let n = e?.text_response_part ?? e, r = n?.type, a = n?.text ?? "";
|
|
23398
|
+
r === "start" ? (y.current &&= (clearTimeout(y.current), null), b.current &&= (clearInterval(b.current), null), de.current != null && (cancelAnimationFrame(de.current), de.current = null), ue.current = null, ce.current = a, le.current = Date.now(), i && u()) : r === "delta" ? (ce.current += a, le.current ??= Date.now(), i && u()) : r === "stop" ? (ce.current += a, i && u()) : (ce.current += a, le.current == null && a && (le.current = Date.now()), i && u()), i && ce.current.trim().length >= 10 && (l(), c());
|
|
23386
23399
|
},
|
|
23387
23400
|
onInterruption: () => {
|
|
23388
|
-
|
|
23401
|
+
pe();
|
|
23389
23402
|
},
|
|
23390
23403
|
onMessage: (e) => {
|
|
23391
23404
|
if (t) return;
|
|
23392
23405
|
let n = e.role === "user" ? "user" : "bot", r = e.message || e.text || e.content || "";
|
|
23393
23406
|
if (!r) return;
|
|
23394
|
-
let
|
|
23407
|
+
let a = {
|
|
23395
23408
|
sender: n,
|
|
23396
23409
|
message: r,
|
|
23397
23410
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
23398
23411
|
};
|
|
23399
|
-
if (n === "user")
|
|
23400
|
-
else if (n === "bot" && r.trim()) {
|
|
23412
|
+
if (n === "user") oe.current = r, r.trim().length >= 1 && (fe.current = !0);
|
|
23413
|
+
else if (n === "bot" && r.trim() && i && fe.current) {
|
|
23401
23414
|
let e = r.trim();
|
|
23402
|
-
e.length > (
|
|
23415
|
+
e.length > (ce.current?.length || 0) && (ce.current = e, le.current ??= Date.now(), u(), e.length >= 10 && (l(), c()));
|
|
23403
23416
|
}
|
|
23404
|
-
d.current = [...d.current,
|
|
23405
|
-
|
|
23417
|
+
d.current = [...d.current, a], y_(n, r) && queueMicrotask(() => {
|
|
23418
|
+
v.current || (v.current = !0, se.current?.());
|
|
23406
23419
|
});
|
|
23407
23420
|
},
|
|
23408
23421
|
onError: (e) => {
|
|
23409
|
-
t || (console.error("[VoiceInterface] ElevenLabs error", e),
|
|
23422
|
+
t || (console.error("[VoiceInterface] ElevenLabs error", e), pe(), ee("error"), _("Voice session encountered an error."));
|
|
23410
23423
|
},
|
|
23411
23424
|
onDisconnect: () => {
|
|
23412
|
-
t || (console.log("[VoiceInterface] session disconnected"),
|
|
23425
|
+
t || (console.log("[VoiceInterface] session disconnected"), pe(), re(!1), ee("idle"));
|
|
23413
23426
|
}
|
|
23414
23427
|
});
|
|
23415
23428
|
if (t) {
|
|
23416
|
-
|
|
23429
|
+
f.endSession().catch(() => {});
|
|
23417
23430
|
return;
|
|
23418
23431
|
}
|
|
23419
|
-
n =
|
|
23432
|
+
n = f, ie.current = f, re(!0), ee("listening");
|
|
23420
23433
|
try {
|
|
23421
23434
|
let e = typeof window < "u" ? window.location.href : "", t = "";
|
|
23422
23435
|
try {
|
|
23423
|
-
t = await
|
|
23436
|
+
t = await o.list_page_forms();
|
|
23424
23437
|
} catch {
|
|
23425
23438
|
t = "[]";
|
|
23426
23439
|
}
|
|
23427
|
-
|
|
23440
|
+
f.sendContextualUpdate(`Current page URL: ${e}. Site ID: ${r || "unknown"}. Page fields/buttons JSON: ${t}. Navigation: when the user wants to go to any page (contact, pricing, about, services, etc.), call search_site_content then navigate_to_page immediately — never ask permission. After navigating to a page with a form, call list_page_forms and proactively start helping the user fill it. Contact / lead forms: use only the main contact form (Full Name, Email, Message). Ignore footer or secondary marketing URL fields unless the user explicitly asks to use them. Fill in order: name → email → message. Message must be a short visitor note (what they want from the team), not a transcript of the conversation. Forms: use fill_form_fields then click_page_button (e.g. Send Message) when appropriate. Fill each field right after the user gives that value — do not click submit until required fields are filled. On-page reading: highlight the correct section by calling highlight_on_page({ section_text: "..." }) with visible heading/plan text, or read_page_content({ section_text: "..." }) when reading a specific section — the UI follows tool targets, not loose speech. Voice: if the user wants to end the voice session, call end_voice_session or confirm and end.`);
|
|
23428
23441
|
} catch {}
|
|
23429
23442
|
typeof m == "function" && m();
|
|
23430
23443
|
} catch (e) {
|
|
23431
|
-
t || (console.error("[VoiceInterface] startSession failed", e),
|
|
23444
|
+
t || (console.error("[VoiceInterface] startSession failed", e), ee("error"), _("Could not start voice session. Please try again."));
|
|
23432
23445
|
}
|
|
23433
23446
|
})(), () => {
|
|
23434
|
-
t = !0,
|
|
23447
|
+
t = !0, pe(), n ? n.endSession().catch(() => {}) : ie.current && ie.current.endSession().catch(() => {});
|
|
23435
23448
|
};
|
|
23436
23449
|
}, [
|
|
23437
23450
|
e,
|
|
@@ -23439,11 +23452,12 @@ function b_({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, history
|
|
|
23439
23452
|
a,
|
|
23440
23453
|
d,
|
|
23441
23454
|
m,
|
|
23442
|
-
|
|
23455
|
+
pe,
|
|
23456
|
+
h
|
|
23443
23457
|
]);
|
|
23444
|
-
let
|
|
23458
|
+
let he = g === "listening" || g === "speaking", ge = g_[g] || g_.idle, _e = h_[g] || h_.idle;
|
|
23445
23459
|
return /* @__PURE__ */ u("div", {
|
|
23446
|
-
ref:
|
|
23460
|
+
ref: ae,
|
|
23447
23461
|
style: {
|
|
23448
23462
|
display: "flex",
|
|
23449
23463
|
flexDirection: "column",
|
|
@@ -23465,19 +23479,19 @@ function b_({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, history
|
|
|
23465
23479
|
justifyContent: "center"
|
|
23466
23480
|
},
|
|
23467
23481
|
children: [
|
|
23468
|
-
|
|
23482
|
+
he && /* @__PURE__ */ l("div", { style: {
|
|
23469
23483
|
position: "absolute",
|
|
23470
23484
|
inset: "-16px",
|
|
23471
23485
|
borderRadius: "50%",
|
|
23472
|
-
border: `2px solid ${
|
|
23486
|
+
border: `2px solid ${ge}`,
|
|
23473
23487
|
animation: "fe-orb-pulse 1.4s ease-in-out infinite",
|
|
23474
23488
|
opacity: .6
|
|
23475
23489
|
} }),
|
|
23476
|
-
|
|
23490
|
+
he && /* @__PURE__ */ l("div", { style: {
|
|
23477
23491
|
position: "absolute",
|
|
23478
23492
|
inset: "-8px",
|
|
23479
23493
|
borderRadius: "50%",
|
|
23480
|
-
border: `2px solid ${
|
|
23494
|
+
border: `2px solid ${ge}`,
|
|
23481
23495
|
animation: "fe-orb-pulse 1.4s ease-in-out 0.35s infinite",
|
|
23482
23496
|
opacity: .4
|
|
23483
23497
|
} }),
|
|
@@ -23486,18 +23500,18 @@ function b_({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, history
|
|
|
23486
23500
|
width: "140px",
|
|
23487
23501
|
height: "140px",
|
|
23488
23502
|
borderRadius: "50%",
|
|
23489
|
-
background:
|
|
23490
|
-
border: `3px solid ${
|
|
23503
|
+
background: _e,
|
|
23504
|
+
border: `3px solid ${ge}`,
|
|
23491
23505
|
display: "flex",
|
|
23492
23506
|
alignItems: "center",
|
|
23493
23507
|
justifyContent: "center",
|
|
23494
23508
|
transition: "all 0.35s ease",
|
|
23495
|
-
transform:
|
|
23496
|
-
boxShadow: `0 0 40px ${
|
|
23509
|
+
transform: g === "speaking" ? "scale(1.08)" : "scale(1)",
|
|
23510
|
+
boxShadow: `0 0 40px ${_e}, 0 8px 32px rgba(0,0,0,0.08)`
|
|
23497
23511
|
},
|
|
23498
23512
|
children: /* @__PURE__ */ l(An, {
|
|
23499
23513
|
size: 44,
|
|
23500
|
-
color:
|
|
23514
|
+
color: ge
|
|
23501
23515
|
})
|
|
23502
23516
|
})
|
|
23503
23517
|
]
|
|
@@ -23506,19 +23520,19 @@ function b_({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, history
|
|
|
23506
23520
|
style: {
|
|
23507
23521
|
fontSize: "15px",
|
|
23508
23522
|
fontWeight: 600,
|
|
23509
|
-
color:
|
|
23523
|
+
color: g === "error" ? "#ef4444" : "#374151",
|
|
23510
23524
|
letterSpacing: "0.01em",
|
|
23511
23525
|
textAlign: "center"
|
|
23512
23526
|
},
|
|
23513
23527
|
children: [
|
|
23514
|
-
|
|
23515
|
-
|
|
23516
|
-
|
|
23517
|
-
|
|
23528
|
+
g === "idle" && "Starting voice session…",
|
|
23529
|
+
g === "listening" && "Listening…",
|
|
23530
|
+
g === "speaking" && "AI is speaking…",
|
|
23531
|
+
g === "error" && (te || "Error")
|
|
23518
23532
|
]
|
|
23519
23533
|
}),
|
|
23520
23534
|
/* @__PURE__ */ u("button", {
|
|
23521
|
-
onClick:
|
|
23535
|
+
onClick: me,
|
|
23522
23536
|
style: {
|
|
23523
23537
|
display: "flex",
|
|
23524
23538
|
alignItems: "center",
|