@flowengage/react-chatbot 8.0.51 → 8.0.54

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.
@@ -18,7 +18,7 @@ var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.g
18
18
  }, T = (e) => x.call(e, "module.exports") ? e["module.exports"] : w(v({}, "__esModule", { value: !0 }), e), E = (e) => {
19
19
  if (!e || typeof e != "object") throw Error("FlowEngage config is required");
20
20
  if (!e.siteId || typeof e.siteId != "string") throw Error("[FlowEngage] config.siteId is required. Pass it as <FlowEngageProvider siteId=\"your-site-id\" /> or config={{ siteId: 'your-site-id' }}.");
21
- let t = (e.apiBaseUrl || "http://localhost:5008").replace(/\/+$/, "");
21
+ let t = (e.apiBaseUrl || "https://be-flowengage-dev.oslabs.app").replace(/\/+$/, "");
22
22
  return {
23
23
  siteId: e.siteId.trim(),
24
24
  apiBaseUrl: t
@@ -8876,76 +8876,78 @@ async function Em(e, t, n) {
8876
8876
  }
8877
8877
  if (!i.ok) throw Error("Could not start a voice session.");
8878
8878
  let a = await i.json();
8879
- if (!a?.success || !a.token) throw Error(a?.error || "Voice session was refused.");
8879
+ if (!a?.success || !a.wsUrl) throw Error(a?.error || "Voice session was refused.");
8880
8880
  return a;
8881
8881
  }
8882
8882
  async function Dm(e) {
8883
8883
  let { apiBaseUrl: t, siteId: n, chatId: r, clientTools: i = {}, onConnect: a, onDisconnect: o, onMessage: s, onModeChange: c, onError: l, onUnhandledClientToolCall: u, onAgentTurnEnd: d, onSessionInfo: f } = e, p = await Em(t, n, r);
8884
- f?.({ emailOnFile: !!p.emailOnFile }), e.greeting !== void 0 && (e.greeting ? p.settings.agent.greeting = e.greeting : delete p.settings.agent.greeting);
8885
- let m = await navigator.mediaDevices.getUserMedia({ audio: {
8884
+ f?.({ emailOnFile: !!p.emailOnFile });
8885
+ let m = { type: "Start" };
8886
+ e.greeting !== void 0 && (m.greeting = e.greeting || null);
8887
+ let h = await navigator.mediaDevices.getUserMedia({ audio: {
8886
8888
  channelCount: 1,
8887
8889
  echoCancellation: !0,
8888
8890
  noiseSuppression: !0,
8889
8891
  autoGainControl: !0
8890
- } }), h = new (window.AudioContext || window.webkitAudioContext)({ sampleRate: bm });
8891
- h.state === "suspended" && await h.resume();
8892
- let g = new WebSocket(p.wsUrl, ["token", p.token]);
8893
- g.binaryType = "arraybuffer";
8894
- let _ = /* @__PURE__ */ new Set(), v = {
8892
+ } }), g = new (window.AudioContext || window.webkitAudioContext)({ sampleRate: bm });
8893
+ g.state === "suspended" && await g.resume();
8894
+ let _ = new WebSocket(p.wsUrl);
8895
+ _.binaryType = "arraybuffer";
8896
+ let v = /* @__PURE__ */ new Set(), y = {
8895
8897
  role: null,
8896
8898
  text: "",
8897
8899
  timer: null
8898
- }, y = "", b = () => {
8899
- v.timer &&= (clearTimeout(v.timer), null);
8900
- let e = v.text.trim(), t = v.role;
8901
- if (v.text = "", v.role = null, !(!e || !t)) {
8900
+ }, b = "", x = () => {
8901
+ y.timer &&= (clearTimeout(y.timer), null);
8902
+ let e = y.text.trim(), t = y.role;
8903
+ if (y.text = "", y.role = null, !(!e || !t)) {
8902
8904
  if (t === "agent") {
8903
- if (e === y) {
8905
+ if (e === b) {
8904
8906
  console.debug("[FlowEngage] duplicate agent turn suppressed");
8905
8907
  return;
8906
8908
  }
8907
- y = e;
8909
+ b = e;
8908
8910
  }
8909
8911
  s?.({
8910
8912
  role: t,
8911
8913
  message: e
8912
8914
  });
8913
8915
  }
8914
- }, x = (e, t) => {
8915
- t && (v.role && v.role !== e && b(), v.role = e, v.text = v.text ? `${v.text} ${t}`.replace(/\s+/g, " ") : t, v.timer && clearTimeout(v.timer), v.timer = setTimeout(b, Sm));
8916
- }, S = !1, C = !1, w = !1, T = !1, E = null, D = () => {
8917
- E && clearTimeout(E);
8916
+ }, S = (e, t) => {
8917
+ t && (y.role && y.role !== e && x(), y.role = e, y.text = y.text ? `${y.text} ${t}`.replace(/\s+/g, " ") : t, y.timer && clearTimeout(y.timer), y.timer = setTimeout(x, Sm));
8918
+ }, C = !1, w = !1, T = !1, E = !1, D = !0, O = null, k = () => {
8919
+ O && clearTimeout(O);
8918
8920
  let e = () => {
8919
- if (!S) {
8920
- if (O.isPlaying()) {
8921
- E = setTimeout(e, 150);
8921
+ if (!C) {
8922
+ if (A.isPlaying()) {
8923
+ O = setTimeout(e, 150);
8922
8924
  return;
8923
8925
  }
8924
- E = null, d?.();
8926
+ O = null, d?.();
8925
8927
  }
8926
8928
  };
8927
- E = setTimeout(e, 150);
8928
- }, O = Tm(h, () => {
8929
- T && (T = !1, c?.({ mode: "listening" }));
8930
- }), k = h.createMediaStreamSource(m), A = h.createScriptProcessor(xm, 1, 1);
8931
- A.onaudioprocess = (e) => {
8932
- if (S || g.readyState !== WebSocket.OPEN) return;
8929
+ O = setTimeout(e, 150);
8930
+ }, A = Tm(g, () => {
8931
+ E && (E = !1, c?.({ mode: "listening" }));
8932
+ }), ee = g.createMediaStreamSource(h), te = g.createScriptProcessor(xm, 1, 1);
8933
+ te.onaudioprocess = (e) => {
8934
+ if (C || _.readyState !== WebSocket.OPEN) return;
8933
8935
  let t = e.inputBuffer.getChannelData(0);
8934
- if (C) {
8935
- w || (w = !0, console.debug("[FlowEngage] mic held — streaming silence to keep socket alive")), g.send(new Int16Array(t.length).buffer);
8936
+ if (w) {
8937
+ T || (T = !0, console.debug("[FlowEngage] mic held — streaming silence to keep socket alive")), _.send(new Int16Array(t.length).buffer);
8936
8938
  return;
8937
8939
  }
8938
- g.send(Cm(t).buffer);
8939
- }, k.connect(A), A.connect(h.destination);
8940
- let ee = () => {
8941
- if (!S) {
8942
- S = !0, E &&= (clearTimeout(E), null), b(), O.stop();
8940
+ _.send(Cm(t).buffer);
8941
+ }, ee.connect(te), te.connect(g.destination);
8942
+ let ne = () => {
8943
+ if (!C) {
8944
+ C = !0, O &&= (clearTimeout(O), null), x(), A.stop();
8943
8945
  try {
8944
- A.disconnect(), k.disconnect();
8946
+ te.disconnect(), ee.disconnect();
8945
8947
  } catch {}
8946
- m.getTracks().forEach((e) => e.stop()), h.close().catch(() => {}), (g.readyState === WebSocket.OPEN || g.readyState === WebSocket.CONNECTING) && g.close();
8948
+ h.getTracks().forEach((e) => e.stop()), g.close().catch(() => {}), (_.readyState === WebSocket.OPEN || _.readyState === WebSocket.CONNECTING) && _.close();
8947
8949
  }
8948
- }, te = async (e) => {
8950
+ }, j = async (e) => {
8949
8951
  let t = i[e.name];
8950
8952
  if (!t) return u?.({ tool_name: e.name }), { error: `Unknown tool ${e.name}` };
8951
8953
  let n = {};
@@ -8957,29 +8959,29 @@ async function Dm(e) {
8957
8959
  } catch (e) {
8958
8960
  return { error: e?.message || "Tool execution failed" };
8959
8961
  }
8960
- }, ne = async (e) => {
8962
+ }, re = async (e) => {
8961
8963
  for (let t of e.functions || []) {
8962
8964
  if (!t.client_side) continue;
8963
- let e = await te(t);
8964
- if (S || g.readyState !== WebSocket.OPEN) return;
8965
- g.send(JSON.stringify({
8965
+ let e = await j(t);
8966
+ if (C || _.readyState !== WebSocket.OPEN) return;
8967
+ _.send(JSON.stringify({
8966
8968
  type: "FunctionCallResponse",
8967
8969
  id: t.id,
8968
8970
  name: t.name,
8969
8971
  content: typeof e == "string" ? e : JSON.stringify(e ?? {})
8970
8972
  }));
8971
8973
  }
8972
- }, j = (e) => {
8974
+ }, ie = (e) => {
8973
8975
  switch (e.type) {
8974
8976
  case "Welcome":
8975
- a?.({ conversationId: e.request_id || p.token.slice(0, 12) });
8977
+ a?.({ conversationId: e.session_id || r || n });
8976
8978
  break;
8977
8979
  case "ConversationText": {
8978
8980
  let t = String(e.content || "");
8979
8981
  if (e.role === "user") {
8980
8982
  let e = t.trim();
8981
- if (_.has(e)) {
8982
- _.delete(e);
8983
+ if (v.has(e)) {
8984
+ v.delete(e);
8983
8985
  break;
8984
8986
  }
8985
8987
  if (/^\[SYSTEM:/i.test(e) || /^Continue (now )?to the next section/i.test(e) || /^That was the last section/i.test(e)) {
@@ -8987,68 +8989,68 @@ async function Dm(e) {
8987
8989
  break;
8988
8990
  }
8989
8991
  }
8990
- x(e.role === "user" ? "user" : "agent", t);
8992
+ S(e.role === "user" ? "user" : "agent", t);
8991
8993
  break;
8992
8994
  }
8993
8995
  case "UserStartedSpeaking":
8994
- b(), O.stop(), T = !1, c?.({ mode: "listening" });
8996
+ x(), A.stop(), D = !1, E = !1, c?.({ mode: "listening" });
8995
8997
  break;
8996
8998
  case "AgentStartedSpeaking":
8997
- T = !0, c?.({ mode: "speaking" });
8999
+ D = !0, E = !0, c?.({ mode: "speaking" });
8998
9000
  break;
8999
9001
  case "AgentAudioDone":
9000
- b(), D(), O.isPlaying() || (T = !1, c?.({ mode: "listening" }));
9002
+ x(), k(), A.isPlaying() || (E = !1, c?.({ mode: "listening" }));
9001
9003
  break;
9002
9004
  case "FunctionCallRequest":
9003
- ne(e);
9005
+ re(e);
9004
9006
  break;
9005
9007
  case "PromptUpdated":
9006
9008
  case "AgentThinking": break;
9007
9009
  case "Error":
9008
- console.error("[FlowEngage:Deepgram]", e.code || "", e.description || e), l?.(Error(e.description || "Voice service error"));
9010
+ console.error("[FlowEngage:Voice]", e.code || "", e.description || e), l?.(Error(e.description || "Voice service error"));
9009
9011
  break;
9010
9012
  case "Warning":
9011
- console.warn("[FlowEngage:Deepgram]", e.code || "", e.description || "");
9013
+ console.warn("[FlowEngage:Voice]", e.code || "", e.description || "");
9012
9014
  break;
9013
9015
  default: break;
9014
9016
  }
9015
9017
  };
9016
- return g.onopen = () => g.send(JSON.stringify(p.settings)), g.onmessage = (e) => {
9018
+ return _.onopen = () => _.send(JSON.stringify(m)), _.onmessage = (e) => {
9017
9019
  if (e.data instanceof ArrayBuffer) {
9018
- O.enqueue(new Int16Array(e.data));
9020
+ D && A.enqueue(new Int16Array(e.data));
9019
9021
  return;
9020
9022
  }
9021
9023
  try {
9022
- j(JSON.parse(e.data));
9024
+ ie(JSON.parse(e.data));
9023
9025
  } catch {}
9024
- }, g.onerror = () => l?.(/* @__PURE__ */ Error("Voice connection failed")), g.onclose = () => {
9025
- ee(), o?.();
9026
+ }, _.onerror = () => l?.(/* @__PURE__ */ Error("Voice connection failed")), _.onclose = () => {
9027
+ ne(), o?.();
9026
9028
  }, {
9027
- endSession: async () => ee(),
9029
+ endSession: async () => ne(),
9028
9030
  sendContextualUpdate: (e) => {
9029
- S || g.readyState !== WebSocket.OPEN || !e || g.send(JSON.stringify({
9031
+ C || _.readyState !== WebSocket.OPEN || !e || _.send(JSON.stringify({
9030
9032
  type: "UpdatePrompt",
9031
9033
  prompt: e
9032
9034
  }));
9033
9035
  },
9034
9036
  sendUserMessage: (e, { silent: t = !0 } = {}) => {
9035
- S || g.readyState !== WebSocket.OPEN || !e || (t && _.add(e.trim()), g.send(JSON.stringify({
9037
+ C || _.readyState !== WebSocket.OPEN || !e || (t && v.add(e.trim()), _.send(JSON.stringify({
9036
9038
  type: "InjectUserMessage",
9037
9039
  content: e
9038
9040
  })));
9039
9041
  },
9040
9042
  injectAgentSpeech: (e, t = "interrupt") => {
9041
- S || g.readyState !== WebSocket.OPEN || !e || g.send(JSON.stringify({
9043
+ C || _.readyState !== WebSocket.OPEN || !e || _.send(JSON.stringify({
9042
9044
  type: "InjectAgentMessage",
9043
9045
  message: e,
9044
9046
  behavior: t
9045
9047
  }));
9046
9048
  },
9047
9049
  setMicMuted: (e) => {
9048
- C = !!e;
9050
+ w = !!e;
9049
9051
  },
9050
9052
  get status() {
9051
- return S ? "disconnected" : "connected";
9053
+ return C ? "disconnected" : "connected";
9052
9054
  }
9053
9055
  };
9054
9056
  }
@@ -12817,7 +12819,7 @@ function Tg({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
12817
12819
  headers: { "Content-Type": "application/json" },
12818
12820
  body: JSON.stringify({
12819
12821
  chatId: s,
12820
- elevenLabsConversationId: t,
12822
+ voiceSessionId: t,
12821
12823
  duration: e,
12822
12824
  siteId: i
12823
12825
  })
@@ -12857,7 +12859,7 @@ function Tg({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
12857
12859
  if (e && s && a) try {
12858
12860
  let n = t ? Math.round((Date.now() - t) / 1e3) : 0, r = JSON.stringify({
12859
12861
  chatId: s,
12860
- elevenLabsConversationId: e,
12862
+ voiceSessionId: e,
12861
12863
  duration: n,
12862
12864
  siteId: i
12863
12865
  }), o = `${a}/api/voice/save-chat-recording`;
@@ -13095,7 +13097,7 @@ function Tg({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
13095
13097
  if (t?.endSession?.().catch(() => {}), n && s && a) {
13096
13098
  let e = f ? Math.round((Date.now() - f) / 1e3) : 0, t = JSON.stringify({
13097
13099
  chatId: s,
13098
- elevenLabsConversationId: n,
13100
+ voiceSessionId: n,
13099
13101
  duration: e,
13100
13102
  siteId: i
13101
13103
  }), r = `${a}/api/voice/save-chat-recording`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@flowengage/react-chatbot",
3
- "version": "8.0.51",
4
- "description": "Embeddable AI chat widget for React \u2014 powered by FlowEngage. Drop it in with a single siteId.",
3
+ "version": "8.0.54",
4
+ "description": "Embeddable AI chat widget for React powered by FlowEngage. Drop it in with a single siteId.",
5
5
  "keywords": [
6
6
  "chatbot",
7
7
  "customer-support",
@@ -63,4 +63,4 @@
63
63
  "vite": "^8.0.1",
64
64
  "vite-plugin-css-injected-by-js": "^4.0.1"
65
65
  }
66
- }
66
+ }