@flowengage/react-chatbot 0.2.11 → 0.2.12

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.
@@ -21924,16 +21924,45 @@ function Mh(e) {
21924
21924
  return e;
21925
21925
  }
21926
21926
  function Nh(e) {
21927
+ let t = Mh(e);
21928
+ if (Array.isArray(t) && t.length > 0) {
21929
+ let e = t[0];
21930
+ if (e?.field_key != null || e?.fieldKey != null) return t.map((e) => ({
21931
+ field_key: e.field_key ?? e.fieldKey,
21932
+ value: e.value
21933
+ }));
21934
+ }
21935
+ if (!t || typeof t != "object") return [];
21936
+ let n = t.fields ?? t.Fields ?? t.field_list ?? t.fieldList ?? t.data?.fields;
21937
+ if (typeof n == "string") try {
21938
+ n = JSON.parse(n);
21939
+ } catch {
21940
+ n = null;
21941
+ }
21942
+ n && !Array.isArray(n) && typeof n == "object" && (n = Object.values(n)), (!n || n.length === 0) && (t.field_key != null || t.fieldKey != null) && t.value != null && (n = [{
21943
+ field_key: t.field_key ?? t.fieldKey,
21944
+ value: t.value
21945
+ }]);
21946
+ let r = t.website_url ?? t.websiteUrl ?? t.url ?? t.website ?? t.domain ?? t.site_url ?? t.siteUrl;
21947
+ return (!n || n.length === 0) && r != null && String(r).trim() && (n = [{
21948
+ field_key: t.field_key ?? t.fieldKey ?? "url",
21949
+ value: String(r).trim()
21950
+ }]), Array.isArray(n) ? n.map((e) => ({
21951
+ field_key: e?.field_key ?? e?.fieldKey,
21952
+ value: e?.value ?? e?.Value
21953
+ })) : [];
21954
+ }
21955
+ function Ph(e) {
21927
21956
  if (!e || typeof e != "object") return null;
21928
21957
  let t = e.url ?? e.target_url ?? e.page_url ?? e.pageUrl ?? e.link ?? e.href ?? e.path;
21929
21958
  return t == null ? null : String(t).trim() || null;
21930
21959
  }
21931
- function Ph(e) {
21960
+ function Fh(e) {
21932
21961
  if (!e || typeof e != "object") return null;
21933
21962
  let t = e.query ?? e.q ?? e.search ?? e.text ?? e.keywords;
21934
21963
  return t == null ? null : String(t).trim() || null;
21935
21964
  }
21936
- function Fh(e, t) {
21965
+ function Ih(e, t) {
21937
21966
  try {
21938
21967
  e.scrollIntoView({
21939
21968
  block: "center",
@@ -21964,23 +21993,35 @@ function Fh(e, t) {
21964
21993
  let t = e.ownerDocument?.defaultView || window, r = n === "TEXTAREA" ? t.HTMLTextAreaElement.prototype : t.HTMLInputElement.prototype, a = Object.getOwnPropertyDescriptor(r, "value");
21965
21994
  a?.set ? a.set.call(e, i) : e.value = i;
21966
21995
  } else e.value = i;
21996
+ let a = {
21997
+ bubbles: !0,
21998
+ cancelable: !0,
21999
+ composed: !0
22000
+ };
21967
22001
  try {
21968
22002
  e.dispatchEvent(new InputEvent("input", {
21969
- bubbles: !0,
21970
- cancelable: !0,
22003
+ ...a,
21971
22004
  inputType: "insertText",
21972
22005
  data: i
21973
22006
  }));
21974
22007
  } catch {
21975
- e.dispatchEvent(new Event("input", { bubbles: !0 }));
22008
+ e.dispatchEvent(new Event("input", a));
21976
22009
  }
21977
- return e.dispatchEvent(new Event("change", { bubbles: !0 })), !0;
22010
+ e.dispatchEvent(new Event("change", a));
22011
+ try {
22012
+ queueMicrotask(() => {
22013
+ try {
22014
+ e.dispatchEvent(new Event("input", a)), e.dispatchEvent(new Event("change", a));
22015
+ } catch {}
22016
+ });
22017
+ } catch {}
22018
+ return !0;
21978
22019
  }
21979
- function Ih(e) {
22020
+ function Lh(e) {
21980
22021
  let t = e.siteId || null, n = (e.apiBaseUrl || "").replace(/\/$/, ""), r = {
21981
22022
  navigate_to_page: async (e) => {
21982
22023
  $("navigate_to_page ▶ raw parameters:", e);
21983
- let t = Mh(e), n = Nh(t), r = t.section_text ?? t.sectionText ?? t.section;
22024
+ let t = Mh(e), n = Ph(t), r = t.section_text ?? t.sectionText ?? t.section;
21984
22025
  if ($("navigate_to_page · coerced:", {
21985
22026
  url: n,
21986
22027
  sectionText: r
@@ -22010,7 +22051,7 @@ function Ih(e) {
22010
22051
  },
22011
22052
  search_site_content: async (e) => {
22012
22053
  $("search_site_content ▶", e);
22013
- let r = Ph(Mh(e));
22054
+ let r = Fh(Mh(e));
22014
22055
  if ($("search_site_content · query:", r, "siteId:", t, "apiBase:", n || "(empty)"), !r) return $("search_site_content ✖ missing query"), "Missing query parameter.";
22015
22056
  if (!t) return $("search_site_content ✖ no siteId"), "Site is not configured for search.";
22016
22057
  if (!n) return $("search_site_content ✖ no api base"), "API base URL is missing; cannot search.";
@@ -22047,29 +22088,19 @@ function Ih(e) {
22047
22088
  },
22048
22089
  fill_form_fields: async (e) => {
22049
22090
  try {
22050
- let t = Mh(e), n = t?.fields;
22051
- if (typeof n == "string") try {
22052
- n = JSON.parse(n);
22053
- } catch {
22054
- n = null;
22055
- }
22056
- if (!n && Array.isArray(t) && t.length > 0 && t[0]?.field_key != null && (n = t), !n && Array.isArray(t) && t.length > 0 && t[0]?.fieldKey != null && (n = t.map((e) => ({
22057
- field_key: e.field_key ?? e.fieldKey,
22058
- value: e.value
22059
- }))), !n && (t.field_key != null || t.fieldKey != null) && t.value != null && (n = [{
22060
- field_key: t.field_key ?? t.fieldKey,
22061
- value: t.value
22062
- }]), $("fill_form_fields ▶", { fieldCount: Array.isArray(n) ? n.length : 0 }), !Array.isArray(n) || n.length === 0) return "No fields provided. Use list_page_forms first.";
22063
- let r = [];
22064
- for (let e of n) {
22065
- let t = e?.field_key ?? e?.fieldKey, n = e?.value;
22066
- if (t == null || n == null) continue;
22091
+ $("fill_form_fields ▶ raw:", e);
22092
+ let t = Nh(e);
22093
+ if ($("fill_form_fields · normalized fields:", t), !t.length) return "No fields provided. Call list_page_forms, then fill_form_fields with { \"fields\": [ { \"field_key\": \"url or Enter Website URL\", \"value\": \"https://...\" } ] }.";
22094
+ let n = [];
22095
+ for (let e of t) {
22096
+ let t = e?.field_key ?? e?.fieldKey, r = e?.value;
22097
+ if (t == null || r == null) continue;
22067
22098
  let i = xh(), a = kh(i, String(t));
22068
- a ||= Eh(i, String(t)), a ||= Dh(i, String(t), n), a && (Fh(a, n), r.push(String(t)));
22099
+ a ||= Eh(i, String(t)), a ||= Dh(i, String(t), r), a && (Ih(a, r), n.push(String(t)));
22069
22100
  }
22070
- if (!r.length) return $("fill_form_fields ✖ no matches"), "Could not match any fields. Call list_page_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.";
22071
- let i = `OK_FILLED: ${r.join(", ")}`;
22072
- return $("fill_form_fields ✓", i), i;
22101
+ if (!n.length) return $("fill_form_fields ✖ no matches"), "Could not match any fields. Call list_page_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.";
22102
+ let r = `OK_FILLED: ${n.join(", ")}`;
22103
+ return $("fill_form_fields ✓", r), r;
22073
22104
  } catch (e) {
22074
22105
  let t = `fill_form_fields error: ${e?.message || String(e)}`;
22075
22106
  return $("fill_form_fields ✖", t), t;
@@ -22109,19 +22140,29 @@ function Ih(e) {
22109
22140
  };
22110
22141
  }
22111
22142
  //#endregion
22143
+ //#region src/utils/wrapVoiceToolsForLogging.js
22144
+ function Rh(e) {
22145
+ return !e || typeof e != "object" ? e : Object.fromEntries(Object.entries(e).map(([e, t]) => [e, async (n) => {
22146
+ let r = Yt();
22147
+ r ? console.log("[FlowEngage:voice-tool] ▶", e, n) : console.info(`[FlowEngage] voice tool » ${e}`);
22148
+ let i = await t(n), a = typeof i == "string" ? i.length > 220 ? `${i.slice(0, 220)}…` : i : String(i);
22149
+ return r ? console.log("[FlowEngage:voice-tool] ◀", e, a) : console.info(`[FlowEngage] voice tool « ${e}:`, a), i;
22150
+ }]));
22151
+ }
22152
+ //#endregion
22112
22153
  //#region src/components/VoiceInterface.jsx
22113
- var Lh = {
22154
+ var zh = {
22114
22155
  idle: "rgba(99,102,241,0.18)",
22115
22156
  listening: "rgba(16,185,129,0.25)",
22116
22157
  speaking: "rgba(245,158,11,0.25)",
22117
22158
  error: "rgba(239,68,68,0.2)"
22118
- }, Rh = {
22159
+ }, Bh = {
22119
22160
  idle: "#6366f1",
22120
22161
  listening: "#10b981",
22121
22162
  speaking: "#f59e0b",
22122
22163
  error: "#ef4444"
22123
22164
  };
22124
- function zh({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, historyRef: d, hasSyncedRef: f, onMessageSync: p, onStartSync: m }) {
22165
+ function Vh({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, historyRef: d, hasSyncedRef: f, onMessageSync: p, onStartSync: m }) {
22125
22166
  let [ee, te] = s("idle"), [h, ne] = s(null), [re, ie] = s(!1), [ae, oe] = s([]), se = o(null), g = o(null);
22126
22167
  i(() => {
22127
22168
  let t = !1, n = null;
@@ -22129,10 +22170,10 @@ function zh({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, history
22129
22170
  try {
22130
22171
  if (await navigator.mediaDevices.getUserMedia({ audio: !0 }), t) return;
22131
22172
  oe([]);
22132
- let i = Ih({
22173
+ let i = Rh(Lh({
22133
22174
  siteId: r || null,
22134
22175
  apiBaseUrl: a || null
22135
- }), o = await hh.startSession({
22176
+ })), o = await hh.startSession({
22136
22177
  agentId: e,
22137
22178
  clientTools: i,
22138
22179
  onUnhandledClientToolCall: (e) => {
@@ -22196,7 +22237,7 @@ function zh({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, history
22196
22237
  d,
22197
22238
  p,
22198
22239
  c
22199
- ]), le = ee === "listening" || ee === "speaking", _ = Rh[ee] || Rh.idle, ue = Lh[ee] || Lh.idle;
22240
+ ]), le = ee === "listening" || ee === "speaking", _ = Bh[ee] || Bh.idle, ue = zh[ee] || zh.idle;
22200
22241
  return /* @__PURE__ */ u("div", {
22201
22242
  ref: g,
22202
22243
  style: {
@@ -22331,7 +22372,7 @@ function zh({ agentId: e, chatId: t, siteId: r, apiBaseUrl: a, onEnd: c, history
22331
22372
  }
22332
22373
  //#endregion
22333
22374
  //#region src/components/FlowEngageWidget.jsx
22334
- var Bh = [
22375
+ var Hh = [
22335
22376
  {
22336
22377
  key: "become_client",
22337
22378
  label: "Become a Client"
@@ -22352,7 +22393,7 @@ var Bh = [
22352
22393
  key: "looking_for_job",
22353
22394
  label: "Looking for a Job"
22354
22395
  }
22355
- ], Vh = () => /* @__PURE__ */ l("div", {
22396
+ ], Uh = () => /* @__PURE__ */ l("div", {
22356
22397
  style: {
22357
22398
  display: "flex",
22358
22399
  marginBottom: "12px",
@@ -22383,7 +22424,7 @@ var Bh = [
22383
22424
  } }, e)), /* @__PURE__ */ l("style", { children: "\n @keyframes fe-dot-bounce {\n 0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }\n 40% { transform: translateY(-5px); opacity: 1; }\n }\n " })]
22384
22425
  })
22385
22426
  });
22386
- function Hh() {
22427
+ function Wh() {
22387
22428
  let { status: e, runtimeConfig: t, resolvedConfig: n, chatId: r, chatHistory: a, isOpen: o, activeScreen: c, isHumanHandled: d, agentName: f, visitorEmail: p, isAgentTyping: m, isAiTyping: ee, isLoading: te, isVoiceMode: h, isRateLimited: ne, rateLimitMessage: re, isConversationEnded: ie, incomingCall: ae, activeCallId: oe, callConnectionState: se, callConnectedAt: g, isCallMuted: ce, webRTCError: le, language: _, historyRef: ue, onMessageSync: v, endConversation: y, acceptCall: de, rejectCall: fe, endWebRTCCall: pe, toggleCallMute: me, dismissCallError: he, captureVisitorEmail: ge, openWidget: _e, closeWidget: ve, sendMessage: ye, setVoiceMode: be, startTyping: xe, stopTyping: Se, updateTypingDraft: Ce } = Jt(), [we, Te] = s(""), [Ee, De] = s(null), [Oe, ke] = s(null), [Ae, je] = s(null), [Me, b] = s(0), [Ne, Pe] = s(p || ""), [Fe, Ie] = s(""), x = t?.widgetSettings || {}, Le = n?.widgetSettings || {}, Re = {
22388
22429
  ...x.branding || {},
22389
22430
  ...Le.branding || {}
@@ -22405,7 +22446,7 @@ function Hh() {
22405
22446
  outline: "none",
22406
22447
  fontFamily: "ui-sans-serif, system-ui, sans-serif",
22407
22448
  ...o ? {} : He
22408
- }, We = Le.recommendations?.[_] || x.recommendations?.[_] || Bh, Ge = Le.greetings?.[_] || x.greetings?.[_], Ke = Re.chatButtonText || "Chat with us", qe = Re.headerName || t?.websiteName || "OpenSense Labs", S = Re.logoUrl || null, C = Re.hideWatermark || !1, w = Le.elevenLabsAgentId || t?.elevenLabsAgentId || null, Je = t?.siteId || n?.siteId || null, Ye = t?.apiBaseUrl || "", Xe = Re.fallbackAgentName || "Agent", Ze = Re.botLabel || "AI", Qe = ae?.agentName || f || Xe, $e = !p && a.length === 0;
22449
+ }, We = Le.recommendations?.[_] || x.recommendations?.[_] || Hh, Ge = Le.greetings?.[_] || x.greetings?.[_], Ke = Re.chatButtonText || "Chat with us", qe = Re.headerName || t?.websiteName || "OpenSense Labs", S = Re.logoUrl || null, C = Re.hideWatermark || !1, w = Le.elevenLabsAgentId || t?.elevenLabsAgentId || null, Je = t?.siteId || n?.siteId || null, Ye = t?.apiBaseUrl || "", Xe = Re.fallbackAgentName || "Agent", Ze = Re.botLabel || "AI", Qe = ae?.agentName || f || Xe, $e = !p && a.length === 0;
22409
22450
  i(() => {
22410
22451
  Pe(p || ""), p && Ie("");
22411
22452
  }, [p]), i(() => {
@@ -22528,7 +22569,7 @@ function Hh() {
22528
22569
  flexDirection: "column"
22529
22570
  },
22530
22571
  className: "fe-screen-fade-in",
22531
- children: /* @__PURE__ */ l(zh, {
22572
+ children: /* @__PURE__ */ l(Vh, {
22532
22573
  agentId: w,
22533
22574
  chatId: r,
22534
22575
  siteId: Je,
@@ -22568,7 +22609,7 @@ function Hh() {
22568
22609
  isAiTyping: ee,
22569
22610
  isAgentTyping: m,
22570
22611
  setReplyContext: je,
22571
- TypingDots: Vh
22612
+ TypingDots: Uh
22572
22613
  })
22573
22614
  }, "history")
22574
22615
  }),
@@ -22644,4 +22685,4 @@ function Hh() {
22644
22685
  }) : null;
22645
22686
  }
22646
22687
  //#endregion
22647
- export { un as FlowEngageProvider, Hh as FlowEngageWidget, Jt as useFlowEngage };
22688
+ export { un as FlowEngageProvider, Wh as FlowEngageWidget, Jt as useFlowEngage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowengage/react-chatbot",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
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",