@flowengage/react-chatbot 8.0.133 → 8.0.134

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.
@@ -55,51 +55,51 @@ var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.g
55
55
  let t = P(e);
56
56
  t && window.localStorage.setItem(t, "1");
57
57
  } catch {}
58
- }, F = (e) => e ? `flowengage.navPreference.${e}` : null, I = (e) => e ? `flowengage.navPreferencePromptShown.${e}` : null, se = (e) => {
58
+ }, se = (e) => e ? `flowengage.navPreference.${e}` : null, F = (e) => e ? `flowengage.navPreferencePromptShown.${e}` : null, ce = (e) => {
59
59
  if (!j || !e) return null;
60
60
  try {
61
- let t = F(e), n = t ? window.localStorage.getItem(t) : null;
61
+ let t = se(e), n = t ? window.localStorage.getItem(t) : null;
62
62
  return n === "auto" || n === "ask" ? n : null;
63
63
  } catch {
64
64
  return null;
65
65
  }
66
- }, ce = (e, t) => {
66
+ }, le = (e, t) => {
67
67
  if (!(!j || !e || t !== "auto" && t !== "ask")) try {
68
- let n = F(e);
69
- n && window.localStorage.setItem(n, t), ue(e);
68
+ let n = se(e);
69
+ n && window.localStorage.setItem(n, t), de(e);
70
70
  } catch {}
71
- }, le = (e) => {
71
+ }, ue = (e) => {
72
72
  if (!j || !e) return !1;
73
73
  try {
74
- let t = I(e);
74
+ let t = F(e);
75
75
  return t ? window.localStorage.getItem(t) === "1" : !1;
76
76
  } catch {
77
77
  return !1;
78
78
  }
79
- }, ue = (e) => {
79
+ }, de = (e) => {
80
80
  if (!(!j || !e)) try {
81
- let t = I(e);
81
+ let t = F(e);
82
82
  t && window.localStorage.setItem(t, "1");
83
83
  } catch {}
84
- }, de = (e) => e ? `flowengage.persistedChatId.${e}` : null, fe = (e) => {
84
+ }, fe = (e) => e ? `flowengage.persistedChatId.${e}` : null, pe = (e) => {
85
85
  if (!j || !e) return null;
86
86
  try {
87
- let t = de(e), n = t ? window.localStorage.getItem(t) : null;
87
+ let t = fe(e), n = t ? window.localStorage.getItem(t) : null;
88
88
  return n && String(n).trim() ? String(n).trim() : null;
89
89
  } catch {
90
90
  return null;
91
91
  }
92
- }, pe = (e) => {
92
+ }, me = (e) => {
93
93
  if (!(!j || !e)) try {
94
- let t = de(e);
94
+ let t = fe(e);
95
95
  t && window.localStorage.removeItem(t);
96
96
  } catch {}
97
- }, me = (e, t) => {
97
+ }, he = (e, t) => {
98
98
  if (!(!j || !e || !t)) try {
99
- let n = de(e);
99
+ let n = fe(e);
100
100
  n && window.localStorage.setItem(n, String(t).trim());
101
101
  } catch {}
102
- }, he = () => j ? {
102
+ }, ge = () => j ? {
103
103
  isOpen: !1,
104
104
  activeScreen: window.sessionStorage.getItem(A.activeScreen) || "ai",
105
105
  isHumanHandled: window.sessionStorage.getItem(A.isHumanHandled) === "true",
@@ -113,7 +113,7 @@ var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.g
113
113
  agentName: null,
114
114
  agentHeadshot: null,
115
115
  visitorEmail: ""
116
- }, ge = (e) => {
116
+ }, _e = (e) => {
117
117
  j && Object.entries(e).forEach(([e, t]) => {
118
118
  let n = A[e];
119
119
  if (n) {
@@ -124,7 +124,7 @@ var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.g
124
124
  window.sessionStorage.setItem(n, String(t));
125
125
  }
126
126
  });
127
- }, _e = (e) => {
127
+ }, ve = (e) => {
128
128
  if (!j || !e) return "";
129
129
  let t = M(e), n = window.localStorage.getItem(t);
130
130
  if (!n) {
@@ -132,7 +132,7 @@ var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.g
132
132
  e && (window.localStorage.setItem(t, e), window.sessionStorage.removeItem(A.visitorEmail), n = e);
133
133
  }
134
134
  return n || "";
135
- }, ve = (e, t) => {
135
+ }, ye = (e, t) => {
136
136
  if (!j) return;
137
137
  let n = M(t);
138
138
  if (!n) return;
@@ -142,91 +142,91 @@ var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.g
142
142
  return;
143
143
  }
144
144
  window.localStorage.setItem(n, r), window.sessionStorage.removeItem(A.visitorEmail);
145
- }, ye = (e) => e ? `flowengage.visitorId.${e}` : null, be = () => `v_${Date.now().toString(36)}_${typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID().replace(/-/g, "").slice(0, 16) : Math.random().toString(36).slice(2, 18)}`, L = (e) => {
145
+ }, be = (e) => e ? `flowengage.visitorId.${e}` : null, xe = () => `v_${Date.now().toString(36)}_${typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID().replace(/-/g, "").slice(0, 16) : Math.random().toString(36).slice(2, 18)}`, I = (e) => {
146
146
  if (!j || !e) return null;
147
147
  try {
148
- let t = ye(e), n = t ? window.localStorage.getItem(t) : null;
148
+ let t = be(e), n = t ? window.localStorage.getItem(t) : null;
149
149
  return n && String(n).trim() ? String(n).trim() : null;
150
150
  } catch {
151
151
  return null;
152
152
  }
153
- }, R = (e) => {
153
+ }, L = (e) => {
154
154
  if (!j || !e) return null;
155
155
  try {
156
- let t = L(e);
156
+ let t = I(e);
157
157
  if (t) return t;
158
- let n = be(), r = ye(e);
158
+ let n = xe(), r = be(e);
159
159
  return r && window.localStorage.setItem(r, n), n;
160
160
  } catch {
161
- return be();
161
+ return xe();
162
162
  }
163
- }, z = "flowengage.tabId", xe = () => {
163
+ }, R = "flowengage.tabId", Se = () => {
164
164
  if (!j) return "default";
165
165
  try {
166
- let e = window.sessionStorage.getItem(z);
167
- return e || (e = typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID().replace(/-/g, "").slice(0, 12) : Math.random().toString(36).slice(2, 14), window.sessionStorage.setItem(z, e)), e;
166
+ let e = window.sessionStorage.getItem(R);
167
+ return e || (e = typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID().replace(/-/g, "").slice(0, 12) : Math.random().toString(36).slice(2, 14), window.sessionStorage.setItem(R, e)), e;
168
168
  } catch {
169
169
  return "default";
170
170
  }
171
- }, Se = (e) => e ? `flowengage.voice.transcript.${e}.${xe()}` : null, Ce = 600 * 1e3, we = (e, t, n = {}) => {
171
+ }, Ce = (e) => e ? `flowengage.voice.transcript.${e}.${Se()}` : null, we = 600 * 1e3, Te = (e, t, n = {}) => {
172
172
  if (!j || !e) return;
173
173
  let r = typeof t == "string" ? t.trim() : "";
174
174
  if (!r) return;
175
- let i = Number.isFinite(n.ttlMs) ? n.ttlMs : Ce, a = {
175
+ let i = Number.isFinite(n.ttlMs) ? n.ttlMs : we, a = {
176
176
  transcript: r,
177
177
  expiresAt: Date.now() + i
178
178
  };
179
179
  try {
180
- let t = Se(e);
180
+ let t = Ce(e);
181
181
  t && window.localStorage.setItem(t, JSON.stringify(a));
182
182
  } catch {}
183
- }, Te = (e) => {
183
+ }, Ee = (e) => {
184
184
  if (!j || !e) return null;
185
185
  try {
186
- let t = Se(e), n = t ? window.localStorage.getItem(t) : null;
186
+ let t = Ce(e), n = t ? window.localStorage.getItem(t) : null;
187
187
  if (!n) return null;
188
188
  let r = JSON.parse(n);
189
189
  return !r || typeof r.transcript != "string" ? null : Number.isFinite(r.expiresAt) && Date.now() > r.expiresAt ? (window.localStorage.removeItem(t), null) : r;
190
190
  } catch {
191
191
  return null;
192
192
  }
193
- }, Ee = (e) => {
193
+ }, De = (e) => {
194
194
  if (!(!j || !e)) try {
195
- let t = Se(e);
195
+ let t = Ce(e);
196
196
  t && window.localStorage.removeItem(t);
197
197
  } catch {}
198
- }, De = "flowengage.voice.pendingResume", Oe = () => {
198
+ }, Oe = "flowengage.voice.pendingResume", ke = () => {
199
199
  if (j) try {
200
- window.sessionStorage.setItem(De, "1");
200
+ window.sessionStorage.setItem(Oe, "1");
201
201
  } catch {}
202
- }, ke = () => {
202
+ }, Ae = () => {
203
203
  if (!j) return !1;
204
204
  try {
205
- return window.sessionStorage.getItem(De) === "1" ? (window.sessionStorage.removeItem(De), !0) : !1;
205
+ return window.sessionStorage.getItem(Oe) === "1" ? (window.sessionStorage.removeItem(Oe), !0) : !1;
206
206
  } catch {
207
207
  return !1;
208
208
  }
209
- }, Ae = "flowengage.chat.pendingReopen", je = () => {
209
+ }, je = "flowengage.chat.pendingReopen", Me = () => {
210
210
  if (j) try {
211
- window.sessionStorage.setItem(Ae, "1");
211
+ window.sessionStorage.setItem(je, "1");
212
212
  } catch {}
213
- }, Me = () => {
213
+ }, Ne = () => {
214
214
  if (!j) return !1;
215
215
  try {
216
- return window.sessionStorage.getItem(Ae) === "1" ? (window.sessionStorage.removeItem(Ae), !0) : !1;
216
+ return window.sessionStorage.getItem(je) === "1" ? (window.sessionStorage.removeItem(je), !0) : !1;
217
217
  } catch {
218
218
  return !1;
219
219
  }
220
- }, Ne = () => {
220
+ }, Pe = () => {
221
221
  if (!j) return !1;
222
222
  try {
223
- return window.sessionStorage.getItem(De) === "1";
223
+ return window.sessionStorage.getItem(Oe) === "1";
224
224
  } catch {
225
225
  return !1;
226
226
  }
227
- }, Pe = (e) => e ? `flowengage.voice.navState.${e}.${xe()}` : null, Fe = (e, t, n, r) => {
227
+ }, Fe = (e) => e ? `flowengage.voice.navState.${e}.${Se()}` : null, Ie = (e, t, n, r) => {
228
228
  if (!(!j || !e || !t)) try {
229
- let i = Pe(e);
229
+ let i = Fe(e);
230
230
  i && window.sessionStorage.setItem(i, JSON.stringify({
231
231
  previousPage: String(t),
232
232
  targetPath: n ? new URL(String(n), window.location.href).pathname : null,
@@ -234,10 +234,10 @@ var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.g
234
234
  ts: Date.now()
235
235
  }));
236
236
  } catch {}
237
- }, Ie = (e) => {
237
+ }, Le = (e) => {
238
238
  if (!j || !e) return null;
239
239
  try {
240
- let t = Pe(e);
240
+ let t = Fe(e);
241
241
  if (!t) return null;
242
242
  let n = window.sessionStorage.getItem(t);
243
243
  if (!n) return null;
@@ -250,14 +250,14 @@ var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.g
250
250
  } catch {
251
251
  return null;
252
252
  }
253
- }, B = async (e) => {
253
+ }, z = async (e) => {
254
254
  let t = await e.json().catch(() => ({}));
255
255
  if (!e.ok) {
256
256
  let n = Error(t.message || t.error || `Request failed with status ${e.status}`);
257
257
  throw n.status = e.status, n;
258
258
  }
259
259
  return t;
260
- }, Le = async (e, t = {}) => {
260
+ }, Re = async (e, t = {}) => {
261
261
  try {
262
262
  return await fetch(e, {
263
263
  mode: "cors",
@@ -267,9 +267,9 @@ var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.g
267
267
  let n = /* @__PURE__ */ Error(`Network error reaching ${e}. Check: (1) backend is running, (2) CORS allows this origin, (3) siteId is correct. Original: ${t.message}`);
268
268
  throw n.status = 0, n.cause = t, n;
269
269
  }
270
- }, Re = async ({ apiBaseUrl: e, userId: t, siteId: n, priorChatId: r = null, forceNew: i = !1, resumeChatId: a = null, visitorId: o = null }) => {
270
+ }, ze = async ({ apiBaseUrl: e, userId: t, siteId: n, priorChatId: r = null, forceNew: i = !1, resumeChatId: a = null, visitorId: o = null }) => {
271
271
  let s = `${e}/api/visitors/resolve-session`, c = { siteId: n };
272
- return r && String(r).trim() && (c.priorChatId = String(r).trim()), i && (c.forceNew = !0), a && (c.resumeChatId = a), o && (c.visitorId = o), B(await Le(s, {
272
+ return r && String(r).trim() && (c.priorChatId = String(r).trim()), i && (c.forceNew = !0), a && (c.resumeChatId = a), o && (c.visitorId = o), z(await Re(s, {
273
273
  method: "POST",
274
274
  mode: "cors",
275
275
  headers: {
@@ -280,13 +280,13 @@ var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.g
280
280
  },
281
281
  body: JSON.stringify(c)
282
282
  }));
283
- }, ze = async ({ apiBaseUrl: e, siteId: t }) => {
283
+ }, Be = async ({ apiBaseUrl: e, siteId: t }) => {
284
284
  let n = typeof window < "u" ? window.location.origin : "http://localhost";
285
- return (await B(await Le(`${e}/api/widget/chatbot-loader?${new URLSearchParams({
285
+ return (await z(await Re(`${e}/api/widget/chatbot-loader?${new URLSearchParams({
286
286
  siteId: t,
287
287
  origin: n
288
288
  }).toString()}`, { method: "GET" }))).data;
289
- }, Be = ({ apiBaseUrl: e, userId: t, siteId: n, visitorId: r = null }) => {
289
+ }, Ve = ({ apiBaseUrl: e, userId: t, siteId: n, visitorId: r = null }) => {
290
290
  let i = (t, n) => {
291
291
  let r = `${e}${t}`, i = JSON.stringify(n);
292
292
  if (typeof navigator < "u" && navigator.sendBeacon) try {
@@ -300,7 +300,7 @@ var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.g
300
300
  headers: { "Content-Type": "application/json" },
301
301
  body: i
302
302
  }).catch(() => {}), !0) : !1;
303
- }, a = async (i, a = {}) => B(await Le(`${e}${i}`, {
303
+ }, a = async (i, a = {}) => z(await Re(`${e}${i}`, {
304
304
  ...a,
305
305
  headers: {
306
306
  "Content-Type": "application/json",
@@ -315,7 +315,7 @@ var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.g
315
315
  ...n ? { "x-site-id": n } : {},
316
316
  ...a.headers || {}
317
317
  };
318
- return B(await Le(`${e}${r}`, {
318
+ return z(await Re(`${e}${r}`, {
319
319
  ...a,
320
320
  body: i,
321
321
  headers: o
@@ -346,7 +346,7 @@ var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.g
346
346
  method: "POST",
347
347
  body: JSON.stringify(f)
348
348
  });
349
- let p = await Le(`${e}/api/ai/chat`, {
349
+ let p = await Re(`${e}/api/ai/chat`, {
350
350
  method: "POST",
351
351
  headers: {
352
352
  "Content-Type": "application/json",
@@ -359,7 +359,7 @@ var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.g
359
359
  stream: !0
360
360
  })
361
361
  });
362
- if (!(p.headers.get("content-type") || "").includes("text/event-stream")) return B(p);
362
+ if (!(p.headers.get("content-type") || "").includes("text/event-stream")) return z(p);
363
363
  let m = p.body.getReader(), h = new TextDecoder(), g = "", _ = null, v = (e) => {
364
364
  let t = e.split("\n").find((e) => e.startsWith("data: "));
365
365
  if (t) try {
@@ -475,7 +475,7 @@ var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.g
475
475
  });
476
476
  },
477
477
  async getIceServersConfig() {
478
- return B(await Le(`${e}/api/calls/ice-config`, {
478
+ return z(await Re(`${e}/api/calls/ice-config`, {
479
479
  method: "GET",
480
480
  headers: {
481
481
  "x-user-id": t,
@@ -530,31 +530,31 @@ var v = Object.defineProperty, y = Object.getOwnPropertyDescriptor, b = Object.g
530
530
  return i.append("chatId", r), i.append("type", "widget_closed"), t && i.append("userId", String(t)), n && i.append("siteId", String(n)), navigator.sendBeacon(`${e}/api/chat/status`, i);
531
531
  }
532
532
  };
533
- }, V = Object.create(null);
534
- V.open = "0", V.close = "1", V.ping = "2", V.pong = "3", V.message = "4", V.upgrade = "5", V.noop = "6";
535
- var Ve = Object.create(null);
536
- Object.keys(V).forEach((e) => {
537
- Ve[V[e]] = e;
533
+ }, B = Object.create(null);
534
+ B.open = "0", B.close = "1", B.ping = "2", B.pong = "3", B.message = "4", B.upgrade = "5", B.noop = "6";
535
+ var He = Object.create(null);
536
+ Object.keys(B).forEach((e) => {
537
+ He[B[e]] = e;
538
538
  });
539
- var He = {
539
+ var Ue = {
540
540
  type: "error",
541
541
  data: "parser error"
542
- }, H = typeof Blob == "function" || typeof Blob < "u" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", Ue = typeof ArrayBuffer == "function", We = (e) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(e) : e && e.buffer instanceof ArrayBuffer, Ge = ({ type: e, data: t }, n, r) => H && t instanceof Blob ? n ? r(t) : Ke(t, r) : Ue && (t instanceof ArrayBuffer || We(t)) ? n ? r(t) : Ke(new Blob([t]), r) : r(V[e] + (t || "")), Ke = (e, t) => {
542
+ }, V = typeof Blob == "function" || typeof Blob < "u" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", We = typeof ArrayBuffer == "function", Ge = (e) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(e) : e && e.buffer instanceof ArrayBuffer, Ke = ({ type: e, data: t }, n, r) => V && t instanceof Blob ? n ? r(t) : qe(t, r) : We && (t instanceof ArrayBuffer || Ge(t)) ? n ? r(t) : qe(new Blob([t]), r) : r(B[e] + (t || "")), qe = (e, t) => {
543
543
  let n = new FileReader();
544
544
  return n.onload = function() {
545
545
  let e = n.result.split(",")[1];
546
546
  t("b" + (e || ""));
547
547
  }, n.readAsDataURL(e);
548
548
  };
549
- function qe(e) {
549
+ function Je(e) {
550
550
  return e instanceof Uint8Array ? e : e instanceof ArrayBuffer ? new Uint8Array(e) : new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
551
551
  }
552
- var Je;
552
+ var H;
553
553
  function Ye(e, t) {
554
- if (H && e.data instanceof Blob) return e.data.arrayBuffer().then(qe).then(t);
555
- if (Ue && (e.data instanceof ArrayBuffer || We(e.data))) return t(qe(e.data));
556
- Ge(e, !1, (e) => {
557
- Je ||= new TextEncoder(), t(Je.encode(e));
554
+ if (V && e.data instanceof Blob) return e.data.arrayBuffer().then(Je).then(t);
555
+ if (We && (e.data instanceof ArrayBuffer || Ge(e.data))) return t(Je(e.data));
556
+ Ke(e, !1, (e) => {
557
+ H ||= new TextEncoder(), t(H.encode(e));
558
558
  });
559
559
  }
560
560
  //#endregion
@@ -576,10 +576,10 @@ var W = (e) => {
576
576
  return n === "b" ? {
577
577
  type: "message",
578
578
  data: G(e.substring(1), t)
579
- } : Ve[n] ? e.length > 1 ? {
580
- type: Ve[n],
579
+ } : He[n] ? e.length > 1 ? {
580
+ type: He[n],
581
581
  data: e.substring(1)
582
- } : { type: Ve[n] } : He;
582
+ } : { type: He[n] } : Ue;
583
583
  }, G = (e, t) => Ze ? $e(W(e), t) : {
584
584
  base64: !0,
585
585
  data: e
@@ -591,7 +591,7 @@ var W = (e) => {
591
591
  }, et = "", tt = (e, t) => {
592
592
  let n = e.length, r = Array(n), i = 0;
593
593
  e.forEach((e, a) => {
594
- Ge(e, !1, (e) => {
594
+ Ke(e, !1, (e) => {
595
595
  r[a] = e, ++i === n && t(r.join(et));
596
596
  });
597
597
  });
@@ -648,7 +648,7 @@ function st(e, t) {
648
648
  if (at(n) < 8) break;
649
649
  let e = ot(n, 8), t = new DataView(e.buffer, e.byteOffset, e.length), a = t.getUint32(0);
650
650
  if (a > 2 ** 21 - 1) {
651
- s.enqueue(He);
651
+ s.enqueue(Ue);
652
652
  break;
653
653
  }
654
654
  i = a * 2 ** 32 + t.getUint32(4), r = 3;
@@ -658,7 +658,7 @@ function st(e, t) {
658
658
  s.enqueue(Qe(a ? e : it.decode(e), t)), r = 0;
659
659
  }
660
660
  if (i === 0 || i > e) {
661
- s.enqueue(He);
661
+ s.enqueue(Ue);
662
662
  break;
663
663
  }
664
664
  }
@@ -988,7 +988,7 @@ var Pt = typeof navigator < "u" && typeof navigator.product == "string" && navig
988
988
  this.writable = !1;
989
989
  for (let t = 0; t < e.length; t++) {
990
990
  let n = e[t], r = t === e.length - 1;
991
- Ge(n, this.supportsBinary, (e) => {
991
+ Ke(n, this.supportsBinary, (e) => {
992
992
  try {
993
993
  this.doWrite(n, e);
994
994
  } catch {}
@@ -2881,7 +2881,7 @@ async function kr(e, t = {}) {
2881
2881
  reason: "already-on-page"
2882
2882
  };
2883
2883
  let a = i.pathname + i.search + i.hash;
2884
- if (window.Shopify) return n && yr(n), r || je(), r ? Or().then(() => window.location.assign(i.href)) : window.location.assign(i.href), { navigated: !0 };
2884
+ if (window.Shopify) return n && yr(n), r || Me(), r ? Or().then(() => window.location.assign(i.href)) : window.location.assign(i.href), { navigated: !0 };
2885
2885
  let o = window.next?.router;
2886
2886
  if (o?.push) return new Promise((e) => {
2887
2887
  let t = () => {
@@ -2900,11 +2900,11 @@ async function kr(e, t = {}) {
2900
2900
  try {
2901
2901
  window.history.pushState({}, "", e), window.dispatchEvent(new PopStateEvent("popstate", { state: {} }));
2902
2902
  } catch {}
2903
- return n && yr(n), r || je(), window.location.assign(i.href), { navigated: !0 };
2903
+ return n && yr(n), r || Me(), window.location.assign(i.href), { navigated: !0 };
2904
2904
  }
2905
2905
  return { navigated: !0 };
2906
2906
  }
2907
- return n && yr(n), r || je(), window.location.assign(i.href), { navigated: !0 };
2907
+ return n && yr(n), r || Me(), window.location.assign(i.href), { navigated: !0 };
2908
2908
  } catch (t) {
2909
2909
  console.warn("[FlowEngage] shadowNavigate error:", t), n && yr(n);
2910
2910
  try {
@@ -3325,7 +3325,7 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3325
3325
  message: "Looks like you're already on this page!",
3326
3326
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
3327
3327
  }]);
3328
- }, []), [D, O] = m(he().isOpen), [k, A] = m(he().activeScreen), [j, M] = m(he().isHumanHandled), [P, ae] = m(he().agentName), [oe, F] = m(he().agentHeadshot), [I, ce] = m(() => _e(i?.siteId)), [de, ye] = m(!1), [be, L] = m(!1), [z, xe] = m("idle"), [Se, Ce] = m(!1), [we, Te] = m(!1), [Ee, De] = m(""), [ke, Ae] = m(!1), [je, Me] = m(0), [Ne, Pe] = m(0), [Fe, Ie] = m(!1), [B, Le] = m(null), [V, Ve] = m(null), [He, H] = m("idle"), [Ue, We] = m(null), [Ge, Ke] = m(!1), [qe, Je] = m(""), [Ye, Xe] = m(!1), U = p(null), W = p(null), Ze = p(""), Qe = p(!1), G = p(null), $e = p(null), et = p(null), tt = p(null), nt = p(null), rt = p(null), it = p(null), at = p(!1), ot = p({
3328
+ }, []), [D, O] = m(ge().isOpen), [k, A] = m(ge().activeScreen), [j, M] = m(ge().isHumanHandled), [P, ae] = m(ge().agentName), [oe, se] = m(ge().agentHeadshot), [F, le] = m(() => ve(i?.siteId)), [fe, be] = m(!1), [xe, I] = m(!1), [R, Se] = m("idle"), [Ce, we] = m(!1), [Te, Ee] = m(!1), [De, Oe] = m(""), [Ae, je] = m(!1), [Me, Ne] = m(0), [Pe, Fe] = m(0), [Ie, Le] = m(!1), [z, Re] = m(null), [B, He] = m(null), [Ue, V] = m("idle"), [We, Ge] = m(null), [Ke, qe] = m(!1), [Je, H] = m(""), [Ye, Xe] = m(!1), U = p(null), W = p(null), Ze = p(""), Qe = p(!1), G = p(null), $e = p(null), et = p(null), tt = p(null), nt = p(null), rt = p(null), it = p(null), at = p(!1), ot = p({
3329
3329
  url: null,
3330
3330
  at: 0
3331
3331
  }), st = o((e, t) => {
@@ -3347,37 +3347,37 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3347
3347
  cleanup: () => {}
3348
3348
  }), wt = o((e = {}) => {
3349
3349
  let t = !!e.is_human_handled;
3350
- return M(t), t ? (A("agent"), e.agent_info?.name && ae(e.agent_info.name), e.agent_info?.headshot && F(e.agent_info.headshot), t) : (A("ai"), t);
3350
+ return M(t), t ? (A("agent"), e.agent_info?.name && ae(e.agent_info.name), e.agent_info?.headshot && se(e.agent_info.headshot), t) : (A("ai"), t);
3351
3351
  }, []), Tt = f(() => {
3352
3352
  let e = _?.widgetSettings?.call?.maxDurationSeconds ?? i?.widgetSettings?.call?.maxDurationSeconds ?? i?.callMaxDurationSeconds, t = Number(e);
3353
3353
  return Number.isFinite(t) && t > 0 ? t : te;
3354
3354
  }, [i, _]);
3355
3355
  c(() => {
3356
- $e.current = B;
3357
- }, [B]), c(() => {
3356
+ $e.current = z;
3357
+ }, [z]), c(() => {
3358
3358
  vt.current = P;
3359
3359
  }, [P]), c(() => {
3360
- xt.current = ke;
3361
- }, [ke]), c(() => {
3360
+ xt.current = Ae;
3361
+ }, [Ae]), c(() => {
3362
3362
  St.current = i;
3363
3363
  }, [i]);
3364
3364
  let Et = () => {
3365
- Je("");
3365
+ H("");
3366
3366
  }, Dt = o(() => {
3367
3367
  ut.current &&= (window.clearTimeout(ut.current), null);
3368
3368
  }, []), Ot = (e) => {
3369
3369
  let t = typeof e == "string" ? e.trim().toLowerCase() : "";
3370
- return ce(t), ve(t, i?.siteId), t;
3370
+ return le(t), ye(t, i?.siteId), t;
3371
3371
  };
3372
3372
  c(() => {
3373
3373
  let e = i?.siteId;
3374
3374
  if (!e) return;
3375
- let t = _e(e);
3375
+ let t = ve(e);
3376
3376
  if (t) {
3377
- ce(t);
3377
+ le(t);
3378
3378
  return;
3379
3379
  }
3380
- ce((t) => (t && ve(t, e), t));
3380
+ le((t) => (t && ye(t, e), t));
3381
3381
  }, [i?.siteId]);
3382
3382
  let kt = (e = "unspecified") => {
3383
3383
  let t = ct.current || rt.current?.callId, n = _t.current, r = mt.current;
@@ -3407,7 +3407,7 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3407
3407
  } catch {}
3408
3408
  ht.current = null;
3409
3409
  }
3410
- et.current &&= (et.current.close(), null), tt.current &&= (tt.current.getTracks().forEach((e) => e.stop()), null), nt.current &&= (nt.current.srcObject = null, nt.current.remove(), null), Dt(), rt.current = null, K.current = [], ct.current = null, lt.current = null, dt.current = !1, Ke(!1), Le(null), Ve(null), H("idle"), We(null);
3410
+ et.current &&= (et.current.close(), null), tt.current &&= (tt.current.getTracks().forEach((e) => e.stop()), null), nt.current &&= (nt.current.srcObject = null, nt.current.remove(), null), Dt(), rt.current = null, K.current = [], ct.current = null, lt.current = null, dt.current = !1, qe(!1), Re(null), He(null), V("idle"), Ge(null);
3411
3411
  }, At = (e = (/* @__PURE__ */ new Date()).toISOString()) => {
3412
3412
  let t = U.current, n = ct.current || rt.current?.callId;
3413
3413
  if (!(!t?.connected || !n || dt.current)) {
@@ -3459,11 +3459,11 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3459
3459
  if (!e.callId) return;
3460
3460
  let t = lt.current === e.callId, n = ct.current === e.callId, r = $e.current?.callId === e.callId;
3461
3461
  if (!(!t && !n && !r)) {
3462
- if (Dt(), Le(null), t || n) {
3463
- ct.current = e.callId, Ve(e.callId), H((e) => e === "connected" ? e : "connecting"), O(!0);
3462
+ if (Dt(), Re(null), t || n) {
3463
+ ct.current = e.callId, He(e.callId), V((e) => e === "connected" ? e : "connecting"), O(!0);
3464
3464
  return;
3465
3465
  }
3466
- H("idle");
3466
+ V("idle");
3467
3467
  }
3468
3468
  }, Mt = (e = {}) => {
3469
3469
  if (!e.callId) return;
@@ -3473,7 +3473,7 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3473
3473
  kt();
3474
3474
  return;
3475
3475
  }
3476
- lt.current = null, rt.current = null, K.current = [], Le(null), H("idle");
3476
+ lt.current = null, rt.current = null, K.current = [], Re(null), V("idle");
3477
3477
  }
3478
3478
  }, Nt = async (e = {}) => {
3479
3479
  let t = et.current, n = U.current, r = e.sdpOffer || e.offer?.sdp;
@@ -3507,7 +3507,7 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3507
3507
  });
3508
3508
  };
3509
3509
  c(() => {
3510
- ge({
3510
+ _e({
3511
3511
  isOpen: D,
3512
3512
  activeScreen: k,
3513
3513
  isHumanHandled: j,
@@ -3525,12 +3525,12 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3525
3525
  return (async () => {
3526
3526
  Xe(!0);
3527
3527
  try {
3528
- let t = E(i), n = await ze(t);
3528
+ let t = E(i), n = await Be(t);
3529
3529
  if (!e) return;
3530
- let a = t.siteId, o = fe(a), s = R(a), c = "";
3530
+ let a = t.siteId, o = pe(a), s = L(a), c = "";
3531
3531
  try {
3532
3532
  let e = Qe.current, r = G.current;
3533
- if (Qe.current = !1, G.current = null, c = (await Re({
3533
+ if (Qe.current = !1, G.current = null, c = (await ze({
3534
3534
  apiBaseUrl: t.apiBaseUrl,
3535
3535
  userId: n.userId,
3536
3536
  siteId: a,
@@ -3539,12 +3539,12 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3539
3539
  resumeChatId: r,
3540
3540
  visitorId: s
3541
3541
  }))?.data?.chatId, !c) throw Error("resolve-session returned no chatId");
3542
- N(), me(a, c);
3542
+ N(), he(a, c);
3543
3543
  } catch (e) {
3544
- console.warn("[FlowEngageProvider] resolve-session failed, reusing persisted or ephemeral chat id", e?.message || e), c = o || ie(), me(a, c);
3544
+ console.warn("[FlowEngageProvider] resolve-session failed, reusing persisted or ephemeral chat id", e?.message || e), c = o || ie(), he(a, c);
3545
3545
  }
3546
3546
  Ze.current = c;
3547
- let l = Be({
3547
+ let l = Ve({
3548
3548
  apiBaseUrl: t.apiBaseUrl,
3549
3549
  userId: n.userId,
3550
3550
  siteId: t.siteId,
@@ -3561,23 +3561,23 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3561
3561
  siteId: t.siteId
3562
3562
  });
3563
3563
  U.current = f, f.on("connect", async () => {
3564
- xe("connected");
3564
+ Se("connected");
3565
3565
  let e = Ze.current;
3566
3566
  if (e && W.current) try {
3567
3567
  wt(await W.current.checkHumanHandled(e));
3568
3568
  } catch {}
3569
3569
  }), f.on("disconnect", () => {
3570
- xe("disconnected");
3570
+ Se("disconnected");
3571
3571
  }), f.on("aiTyping", () => {
3572
- L(!0);
3572
+ I(!0);
3573
3573
  }), f.on("ai:typing", () => {
3574
- L(!0);
3574
+ I(!0);
3575
3575
  }), f.on("messageReceived", (e) => {
3576
3576
  let t = e.message || e, n = {
3577
3577
  ...t,
3578
3578
  message: di(t.message)
3579
3579
  };
3580
- L(!1), ye(!1), !(n.type === "call_recording" || typeof n.message == "string" && n.message.includes("AI chat recording")) && S((e) => [...e.filter((e) => !e.isPending), {
3580
+ I(!1), be(!1), !(n.type === "call_recording" || typeof n.message == "string" && n.message.includes("AI chat recording")) && S((e) => [...e.filter((e) => !e.isPending), {
3581
3581
  ...n,
3582
3582
  isPending: !1,
3583
3583
  id: n.messageId || `${n.sender}-${Date.now()}-${Math.random()}`
@@ -3595,7 +3595,7 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3595
3595
  ...t,
3596
3596
  message: di(t.message)
3597
3597
  };
3598
- L(!1), !(n.type === "call_recording" || typeof n.message == "string" && n.message.includes("AI chat recording")) && ((n.sender === "agent" || n.agent_name || n.sender === "ai" || n.sender === "bot") && ye(!1), S((e) => n.sender === "bot" || n.sender === "ai" ? [...e, {
3598
+ I(!1), !(n.type === "call_recording" || typeof n.message == "string" && n.message.includes("AI chat recording")) && ((n.sender === "agent" || n.agent_name || n.sender === "ai" || n.sender === "bot") && be(!1), S((e) => n.sender === "bot" || n.sender === "ai" ? [...e, {
3599
3599
  ...n,
3600
3600
  isPending: !1,
3601
3601
  id: n.messageId || `${n.sender}-${Date.now()}-${Math.random()}`
@@ -3611,7 +3611,7 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3611
3611
  n.agent_name,
3612
3612
  n.agentName,
3613
3613
  n.metadata?.agentName
3614
- ], d)), n.sender_headshot && F(n.sender_headshot), O(!0), Me((e) => e + 1)));
3614
+ ], d)), n.sender_headshot && se(n.sender_headshot), O(!0), Ne((e) => e + 1)));
3615
3615
  });
3616
3616
  let p = (e = {}) => {
3617
3617
  let t = gi([
@@ -3620,7 +3620,7 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3620
3620
  e.agent_name,
3621
3621
  vt.current
3622
3622
  ], d);
3623
- M(!0), A("agent"), ae(t), F(e.agent?.headshot || null), O(!0), Me((e) => e + 1), S((e) => _i(e, {
3623
+ M(!0), A("agent"), ae(t), se(e.agent?.headshot || null), O(!0), Ne((e) => e + 1), S((e) => _i(e, {
3624
3624
  id: `agent-joined-${Date.now()}`,
3625
3625
  sender: "system",
3626
3626
  message: `${t} has joined the chat.`,
@@ -3643,7 +3643,7 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3643
3643
  }));
3644
3644
  };
3645
3645
  f.on("agent:joined", p), f.on("agentJoined", p), f.on("agent:left", m), f.on("agentLeft", m), f.on("conversationEnded", (e) => {
3646
- Ie(!0);
3646
+ Le(!0);
3647
3647
  let t = e?.message || "This conversation has ended. Thank you for reaching out!";
3648
3648
  S((e) => [...e, {
3649
3649
  id: `conversation-ended-${Date.now()}`,
@@ -3654,15 +3654,15 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3654
3654
  }]);
3655
3655
  }), f.on("chat:history_update", (e) => {
3656
3656
  let t = fi(e.chat_history || []);
3657
- S(t), t.length === 0 && (Ie(!1), M(!1), A("ai"), L(!1), ye(!1));
3657
+ S(t), t.length === 0 && (Le(!1), M(!1), A("ai"), I(!1), be(!1));
3658
3658
  }), f.on("conversation:reset", () => {
3659
- S([]), Ie(!1), M(!1), A("ai"), L(!1), ye(!1);
3659
+ S([]), Le(!1), M(!1), A("ai"), I(!1), be(!1);
3660
3660
  }), f.on("voice:end_session", (e = {}) => {
3661
- console.log("[FlowEngageProvider] voice:end_session received — ending voice session"), Pe((e) => e + 1), O(!0), Me((e) => e + 1);
3661
+ console.log("[FlowEngageProvider] voice:end_session received — ending voice session"), Fe((e) => e + 1), O(!0), Ne((e) => e + 1);
3662
3662
  }), f.on("typing:start", (e) => {
3663
- e.sender === "agent" && ye(!0);
3663
+ e.sender === "agent" && be(!0);
3664
3664
  }), f.on("typing:stop", (e) => {
3665
- e.sender === "agent" && ye(!1);
3665
+ e.sender === "agent" && be(!1);
3666
3666
  }), f.on("call:incoming", (e = {}) => {
3667
3667
  let t = gi([
3668
3668
  e.agentName,
@@ -3670,12 +3670,12 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3670
3670
  e.agent?.name,
3671
3671
  vt.current
3672
3672
  ], "Agent");
3673
- Et(), Dt(), dt.current = !1, Le({
3673
+ Et(), Dt(), dt.current = !1, Re({
3674
3674
  callId: e.callId,
3675
3675
  from: e.from || "owner",
3676
3676
  agentId: e.agentId || null,
3677
3677
  agentName: t
3678
- }), ae((e) => gi([t, e], "Agent")), H("incoming"), We(null), O(!0);
3678
+ }), ae((e) => gi([t, e], "Agent")), V("incoming"), Ge(null), O(!0);
3679
3679
  }), f.on("call:offer", async (e = {}) => {
3680
3680
  rt.current = e;
3681
3681
  try {
@@ -3718,14 +3718,14 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3718
3718
  if (!e.callId) return;
3719
3719
  let t = lt.current === e.callId, n = ct.current === e.callId, r = rt.current?.callId === e.callId, i = $e.current?.callId === e.callId;
3720
3720
  if (!t && !n && !r) {
3721
- i && (Le(null), H("idle"));
3721
+ i && (Re(null), V("idle"));
3722
3722
  return;
3723
3723
  }
3724
- dt.current = !0, lt.current = null, ct.current = e.callId, Ve(e.callId), Le(null), H("connected"), We(e.connectedAt || (/* @__PURE__ */ new Date()).toISOString()), O(!0);
3724
+ dt.current = !0, lt.current = null, ct.current = e.callId, He(e.callId), Re(null), V("connected"), Ge(e.connectedAt || (/* @__PURE__ */ new Date()).toISOString()), O(!0);
3725
3725
  }), f.on("call:unavailable", (e = {}) => {
3726
- kt("socket:call_unavailable"), Je(mi(e, "This visitor is not available for a call right now.")), O(!0);
3726
+ kt("socket:call_unavailable"), H(mi(e, "This visitor is not available for a call right now.")), O(!0);
3727
3727
  }), f.on("call:error", (e = {}) => {
3728
- kt("socket:call_error"), Je(mi(e, "We couldn't connect the call right now.")), O(!0);
3728
+ kt("socket:call_error"), H(mi(e, "We couldn't connect the call right now.")), O(!0);
3729
3729
  }), f.on("visitor:navigate", async ({ url: e, section: t, highlight: n } = {}) => {
3730
3730
  e && st(e, { voiceActive: xt.current }).then(({ navigated: e, reason: r }) => {
3731
3731
  if (!e) {
@@ -3768,11 +3768,11 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3768
3768
  r,
3769
3769
  a
3770
3770
  ]), c(() => () => {
3771
- if (ke && !bt.current && yt.current.length > 0) {
3771
+ if (Ae && !bt.current && yt.current.length > 0) {
3772
3772
  let e = Ze.current, t = yt.current, n = W.current;
3773
3773
  n && e && t.length > 0 && (console.log("[FlowEngageProvider] safety-net: syncing voice transcript on unmount"), n.beaconSyncVoice(e, t) || n.syncVoice(e, t).catch(() => {}), bt.current = !0);
3774
3774
  }
3775
- }, [ke, _]);
3775
+ }, [Ae, _]);
3776
3776
  let Pt = p(null);
3777
3777
  c(() => {
3778
3778
  let e = W.current;
@@ -3785,8 +3785,8 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3785
3785
  return window.addEventListener("pagehide", e), () => window.removeEventListener("pagehide", e);
3786
3786
  }, []);
3787
3787
  let Ft = async () => {
3788
- if (!(!B?.callId || !W.current || !U.current || !y)) {
3789
- Et(), lt.current = B.callId, Dt();
3788
+ if (!(!z?.callId || !W.current || !U.current || !y)) {
3789
+ Et(), lt.current = z.callId, Dt();
3790
3790
  try {
3791
3791
  let e = await navigator.mediaDevices.getUserMedia({ audio: !0 });
3792
3792
  tt.current = e;
@@ -3802,11 +3802,11 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3802
3802
  let e = n.connectionState;
3803
3803
  if (e === "connected") {
3804
3804
  let e = (/* @__PURE__ */ new Date()).toISOString();
3805
- H("connected"), We((t) => t || e), At(e);
3805
+ V("connected"), Ge((t) => t || e), At(e);
3806
3806
  return;
3807
3807
  }
3808
3808
  if (e === "connecting") {
3809
- H((e) => e === "connected" ? e : "connecting");
3809
+ V((e) => e === "connected" ? e : "connecting");
3810
3810
  return;
3811
3811
  }
3812
3812
  (e === "failed" || e === "closed") && kt(`peer:connection_${e}`);
@@ -3814,11 +3814,11 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3814
3814
  let e = n.iceConnectionState;
3815
3815
  if (e === "connected" || e === "completed") {
3816
3816
  let e = (/* @__PURE__ */ new Date()).toISOString();
3817
- H("connected"), We((t) => t || e), At(e);
3817
+ V("connected"), Ge((t) => t || e), At(e);
3818
3818
  return;
3819
3819
  }
3820
3820
  if (e === "checking" || e === "new") {
3821
- H((e) => e === "connected" ? e : "connecting");
3821
+ V((e) => e === "connected" ? e : "connecting");
3822
3822
  return;
3823
3823
  }
3824
3824
  (e === "failed" || e === "closed") && kt(`peer:ice_${e}`);
@@ -3828,7 +3828,7 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3828
3828
  if (!e.candidate || !U.current?.connected) return;
3829
3829
  let t = e.candidate;
3830
3830
  U.current.emit("call:ice-candidate", {
3831
- callId: B.callId,
3831
+ callId: z.callId,
3832
3832
  candidate: t.candidate,
3833
3833
  sdpMid: t.sdpMid,
3834
3834
  sdpMLineIndex: t.sdpMLineIndex,
@@ -3842,10 +3842,10 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3842
3842
  e.id = "flowengage-remote-audio", e.autoplay = !0, e.playsInline = !0, e.onplay = () => {}, e.onpause = () => {}, e.onended = () => {}, e.onerror = (e) => {}, nt.current = e, document.body.appendChild(e);
3843
3843
  }
3844
3844
  nt.current.srcObject = e.streams[0];
3845
- let r = B?.callId, i = r && (lt.current === r || ct.current === r);
3845
+ let r = z?.callId, i = r && (lt.current === r || ct.current === r);
3846
3846
  if (!dt.current && i) {
3847
3847
  let e = (/* @__PURE__ */ new Date()).toISOString();
3848
- H("connected"), We((t) => t || e), ct.current = r, Ve(r), At(e);
3848
+ V("connected"), Ge((t) => t || e), ct.current = r, He(r), At(e);
3849
3849
  }
3850
3850
  nt.current.srcObject = t || null;
3851
3851
  let a = nt.current.play?.();
@@ -3853,38 +3853,38 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3853
3853
  };
3854
3854
  let r = rt.current;
3855
3855
  r && (console.log("[FlowEngageProvider] found pending remote offer during accept", {
3856
- callId: r.callId || B.callId,
3856
+ callId: r.callId || z.callId,
3857
3857
  chatId: y
3858
3858
  }), await Nt({
3859
3859
  ...r,
3860
- callId: r.callId || B.callId
3861
- })), await W.current.acceptCall(B.callId, y), U.current?.emit("call:accepted", {
3862
- callId: B.callId,
3860
+ callId: r.callId || z.callId
3861
+ })), await W.current.acceptCall(z.callId, y), U.current?.emit("call:accepted", {
3862
+ callId: z.callId,
3863
3863
  chatId: y
3864
- }), ct.current = B.callId, Ve(B.callId), H((e) => e === "connected" || dt.current ? "connected" : "connecting"), Le(null), O(!0);
3864
+ }), ct.current = z.callId, He(z.callId), V((e) => e === "connected" || dt.current ? "connected" : "connecting"), Re(null), O(!0);
3865
3865
  } catch (e) {
3866
3866
  if (lt.current = null, kt("accept_call_failed"), e?.status === 404 || e?.status === 409 || e?.status === 422) {
3867
- Je(mi(e, "This visitor call is no longer available."));
3867
+ H(mi(e, "This visitor call is no longer available."));
3868
3868
  return;
3869
3869
  }
3870
3870
  if (e?.name === "NotAllowedError" || e?.name === "PermissionDeniedError") {
3871
3871
  try {
3872
- await W.current.rejectCall(B.callId, y);
3872
+ await W.current.rejectCall(z.callId, y);
3873
3873
  } catch (e) {
3874
3874
  console.error("[FlowEngageProvider] failed to reject call after microphone denial", e);
3875
3875
  }
3876
- Je("Microphone access was denied. Please allow microphone access to accept the call.");
3876
+ H("Microphone access was denied. Please allow microphone access to accept the call.");
3877
3877
  return;
3878
3878
  }
3879
- Je("We couldn't connect the call right now. Please try again.");
3879
+ H("We couldn't connect the call right now. Please try again.");
3880
3880
  }
3881
3881
  }
3882
3882
  }, It = async () => {
3883
- if (!B?.callId || !W.current || !y) {
3883
+ if (!z?.callId || !W.current || !y) {
3884
3884
  kt("reject_call_without_server_context");
3885
3885
  return;
3886
3886
  }
3887
- let e = B.callId;
3887
+ let e = z.callId;
3888
3888
  Dt(), Et(), U.current?.emit("call:rejected", {
3889
3889
  callId: e,
3890
3890
  chatId: y,
@@ -3893,47 +3893,47 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3893
3893
  try {
3894
3894
  await W.current.rejectCall(e, y);
3895
3895
  } catch (e) {
3896
- Je(mi(e, "We couldn't decline the call cleanly."));
3896
+ H(mi(e, "We couldn't decline the call cleanly."));
3897
3897
  } finally {
3898
3898
  kt("reject_call_finally");
3899
3899
  }
3900
3900
  }, Lt = p(It);
3901
3901
  Lt.current = It, c(() => {
3902
- if (!B?.callId || V) {
3902
+ if (!z?.callId || B) {
3903
3903
  Dt();
3904
3904
  return;
3905
3905
  }
3906
- let e = B.callId;
3906
+ let e = z.callId;
3907
3907
  return Dt(), ut.current = window.setTimeout(() => {
3908
3908
  $e.current?.callId === e && lt.current !== e && ct.current !== e && Lt.current();
3909
3909
  }, ne), () => {
3910
3910
  ut.current &&= (window.clearTimeout(ut.current), null);
3911
3911
  };
3912
3912
  }, [
3913
- V,
3913
+ B,
3914
3914
  Dt,
3915
- B?.callId
3915
+ z?.callId
3916
3916
  ]);
3917
3917
  let Rt = async () => {
3918
- if (!V || !W.current || !y) {
3918
+ if (!B || !W.current || !y) {
3919
3919
  kt("end_call_without_server_context");
3920
3920
  return;
3921
3921
  }
3922
3922
  Et();
3923
3923
  try {
3924
- await W.current.endWebRTCCall(V, y);
3924
+ await W.current.endWebRTCCall(B, y);
3925
3925
  } catch (e) {
3926
- Je(mi(e, "The call ended locally, but the server could not be updated."));
3926
+ H(mi(e, "The call ended locally, but the server could not be updated."));
3927
3927
  } finally {
3928
3928
  kt("end_call_finally");
3929
3929
  }
3930
3930
  }, zt = () => {
3931
3931
  let e = tt.current?.getAudioTracks?.() || [], t = et.current?.getSenders?.().map((e) => e.track).filter((e) => e?.kind === "audio") || [], n = [...e, ...t].filter(Boolean);
3932
3932
  if (n.length === 0) return;
3933
- let r = !Ge;
3933
+ let r = !Ke;
3934
3934
  n.forEach((e) => {
3935
3935
  e.enabled = !r;
3936
- }), Ke(r);
3936
+ }), qe(r);
3937
3937
  }, Bt = async (e = {}) => {
3938
3938
  let t = e.notifyChatInitiated === !0;
3939
3939
  if (O(!0), !(!t || !W.current || !y || typeof window > "u")) {
@@ -3991,7 +3991,7 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
3991
3991
  }
3992
3992
  let Kt = async (e, t = "", n = null, a = {}) => {
3993
3993
  let o = typeof e == "string" ? e.trim() : "";
3994
- if (!o || !W.current || !y || l !== "ready" || Fe) return;
3994
+ if (!o || !W.current || !y || l !== "ready" || Ie) return;
3995
3995
  Ut(), at.current = !1;
3996
3996
  let s = /^\s*(yes|yeah|sure|ok|okay|go ahead|take me(?: there)?(?!\s+\w)|navigate(?!\s+(?:me\s+)?to\s+\w)|yep|absolutely|please do|do it|let'?s go|go there|show me(?!\s+(?:the|a|an)\s+\w)|go to it|bring me there|navigate me there)\b/i, c = /^\s*(?:yes|yeah|sure|ok|okay|yep|absolutely)\s+(?!(?:please|do\s+it|let'?s|that|this|there|it|thanks|go|cool|great|perfect|sounds|alright|proceed)\b)\w/i, u = /\b(take me|navigate|go to|show me|bring me|open|go there|navigate to|take me to|let'?s go to)\b/i;
3997
3997
  if (it.current && s.test(o) && !c.test(o)) {
@@ -4027,17 +4027,17 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
4027
4027
  chatId: y,
4028
4028
  content: e,
4029
4029
  sender: "user",
4030
- email: I || void 0,
4030
+ email: F || void 0,
4031
4031
  type: a?.type || "text",
4032
4032
  metadata: a?.metadata || {},
4033
4033
  ...n || {}
4034
4034
  });
4035
4035
  return;
4036
4036
  }
4037
- Ce(!0);
4037
+ we(!0);
4038
4038
  try {
4039
4039
  let s = await Hr(), c = Br(), l = `stream-preview-${Date.now().toString(36)}`, d = (e) => {
4040
- L(!1), S((t) => {
4040
+ I(!1), S((t) => {
4041
4041
  let n = t.findIndex((e) => e.id === l);
4042
4042
  if (n === -1) return [...t, {
4043
4043
  id: l,
@@ -4054,14 +4054,14 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
4054
4054
  });
4055
4055
  }, f = await W.current.sendAiMessage(y, e, r, t, {
4056
4056
  ...n || {},
4057
- ...I ? { email: I } : {}
4057
+ ...F ? { email: F } : {}
4058
4058
  }, {
4059
4059
  ...a,
4060
4060
  currentPageUrl: typeof window < "u" ? window.location.href : void 0,
4061
4061
  currentPageTitle: typeof window < "u" ? document.title : void 0,
4062
4062
  currentPagePath: typeof window < "u" ? window.location.pathname : void 0,
4063
4063
  currentPageContent: Gt() || void 0,
4064
- navPreference: se(i?.siteId) || void 0,
4064
+ navPreference: ce(i?.siteId) || void 0,
4065
4065
  ...s ? { shopifyCart: s } : {},
4066
4066
  ...c ? { shopifyCustomerId: c } : {}
4067
4067
  }, d), p = f.chat_history || [];
@@ -4087,7 +4087,7 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
4087
4087
  }, 300);
4088
4088
  })) : (it.current = e, console.log("[FWH Nav] Stored pending nav →", it.current));
4089
4089
  let t = i?.siteId;
4090
- t && !le(t) && (ue(t), S((e) => [...e, {
4090
+ t && !ue(t) && (de(t), S((e) => [...e, {
4091
4091
  id: `nav-pref-${Date.now()}`,
4092
4092
  type: "nav_pref_choice",
4093
4093
  sender: "system",
@@ -4140,14 +4140,14 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
4140
4140
  });
4141
4141
  }
4142
4142
  }
4143
- S(fi(p)), Array.isArray(f.cart_actions) && f.cart_actions.length && w(f.cart_actions), M(!!f.is_human_handled), A(f.is_human_handled ? "agent" : "ai"), L(!1), Ce(!1), await W.current.updateChatStatus(y, "messageSent");
4143
+ S(fi(p)), Array.isArray(f.cart_actions) && f.cart_actions.length && w(f.cart_actions), M(!!f.is_human_handled), A(f.is_human_handled ? "agent" : "ai"), I(!1), we(!1), await W.current.updateChatStatus(y, "messageSent");
4144
4144
  } catch (e) {
4145
4145
  S((e) => e.filter((e) => !e.isStreaming).map((e) => e.id === d ? {
4146
4146
  ...e,
4147
4147
  isPending: !1,
4148
4148
  failed: !0
4149
- } : e)), L(!1), Ce(!1), e.status === 429 ? (Te(!0), De(e.message), window.setTimeout(() => {
4150
- Te(!1), De("");
4149
+ } : e)), I(!1), we(!1), e.status === 429 ? (Ee(!0), Oe(e.message), window.setTimeout(() => {
4150
+ Ee(!1), Oe("");
4151
4151
  }, ee)) : h(e);
4152
4152
  }
4153
4153
  }, qt = async (e) => {
@@ -4159,12 +4159,12 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
4159
4159
  let t = e ? "voice" : "text";
4160
4160
  await W.current.setChatMode(y, t);
4161
4161
  } catch {}
4162
- Ae(e), e && (bt.current = !1);
4162
+ je(e), e && (bt.current = !1);
4163
4163
  }
4164
4164
  }, Yt = async (e) => {
4165
4165
  if (bt.current) return;
4166
4166
  if (bt.current = !0, !W.current || !y || !e?.length) {
4167
- Ae(!1);
4167
+ je(!1);
4168
4168
  return;
4169
4169
  }
4170
4170
  let t = () => {
@@ -4188,11 +4188,11 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
4188
4188
  } catch {
4189
4189
  t();
4190
4190
  } finally {
4191
- Ae(!1);
4191
+ je(!1);
4192
4192
  }
4193
4193
  }, Xt = async () => {
4194
4194
  if (!(!W.current || !y)) {
4195
- ke && !bt.current && yt.current.length > 0 && await Yt(yt.current);
4195
+ Ae && !bt.current && yt.current.length > 0 && await Yt(yt.current);
4196
4196
  try {
4197
4197
  await W.current.endConversation(y);
4198
4198
  } catch {
@@ -4200,7 +4200,7 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
4200
4200
  await W.current.updateChatStatus(y, "ended");
4201
4201
  } catch {}
4202
4202
  }
4203
- Ie(!0), S((e) => [...e, {
4203
+ Le(!0), S((e) => [...e, {
4204
4204
  id: `conversation-ended-${Date.now()}`,
4205
4205
  sender: "system",
4206
4206
  message: "This conversation has ended. Thank you for reaching out!",
@@ -4210,15 +4210,15 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
4210
4210
  }
4211
4211
  };
4212
4212
  c(() => {
4213
- if (He !== "connected" || !V || !y || !Ue || !Tt) return;
4214
- let e = new Date(Ue).getTime(), t = Number.isFinite(e) ? Date.now() - e : 0, n = Math.max(0, Tt * 1e3 - t), r = window.setTimeout(() => {
4215
- Je("The call ended because it reached the time limit."), Rt();
4213
+ if (Ue !== "connected" || !B || !y || !We || !Tt) return;
4214
+ let e = new Date(We).getTime(), t = Number.isFinite(e) ? Date.now() - e : 0, n = Math.max(0, Tt * 1e3 - t), r = window.setTimeout(() => {
4215
+ H("The call ended because it reached the time limit."), Rt();
4216
4216
  }, n);
4217
4217
  return () => window.clearTimeout(r);
4218
4218
  }, [
4219
- V,
4219
+ B,
4220
+ We,
4220
4221
  Ue,
4221
- He,
4222
4222
  y,
4223
4223
  Rt,
4224
4224
  Tt
@@ -4226,7 +4226,7 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
4226
4226
  let e = () => {
4227
4227
  let e = Ze.current, t = W.current;
4228
4228
  if (!t || !e) return;
4229
- if (xt.current && yt.current.length > 0 && Oe(), !bt.current && yt.current.length > 0 && (t.beaconSyncVoice(e, yt.current) || t.syncVoice(e, yt.current).catch(() => {}), bt.current = !0), ct.current) {
4229
+ if (xt.current && yt.current.length > 0 && ke(), !bt.current && yt.current.length > 0 && (t.beaconSyncVoice(e, yt.current) || t.syncVoice(e, yt.current).catch(() => {}), bt.current = !0), ct.current) {
4230
4230
  t.beaconEndWebRTCCall(ct.current, e);
4231
4231
  return;
4232
4232
  }
@@ -4239,9 +4239,9 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
4239
4239
  }, []);
4240
4240
  let Zt = o(() => {
4241
4241
  let e = i?.siteId;
4242
- pe(e), Qe.current = !0, G.current = null, U.current?.disconnect(), S([]), b(""), Ze.current = "", Ie(!1), M(!1), ae(null), F(null), Xe(!0), s((e) => e + 1);
4242
+ me(e), Qe.current = !0, G.current = null, U.current?.disconnect(), S([]), b(""), Ze.current = "", Le(!1), M(!1), ae(null), se(null), Xe(!0), s((e) => e + 1);
4243
4243
  }, [i?.siteId]), Qt = o((e) => {
4244
- i?.siteId, Qe.current = !1, G.current = e, U.current?.disconnect(), S([]), b(""), Ze.current = "", Ie(!1), M(!1), ae(null), F(null), Xe(!0), s((e) => e + 1);
4244
+ i?.siteId, Qe.current = !1, G.current = e, U.current?.disconnect(), S([]), b(""), Ze.current = "", Le(!1), M(!1), ae(null), se(null), Xe(!0), s((e) => e + 1);
4245
4245
  }, [i?.siteId]), $t = f(() => ({
4246
4246
  status: l,
4247
4247
  error: d,
@@ -4254,24 +4254,24 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
4254
4254
  isHumanHandled: j,
4255
4255
  agentName: P,
4256
4256
  agentHeadshot: oe,
4257
- visitorEmail: I,
4258
- isAgentTyping: de,
4259
- isAiTyping: be,
4260
- connectionStatus: z,
4261
- isLoading: Se,
4262
- isVoiceMode: ke,
4263
- isRateLimited: we,
4264
- rateLimitMessage: Ee,
4265
- isConversationEnded: Fe,
4257
+ visitorEmail: F,
4258
+ isAgentTyping: fe,
4259
+ isAiTyping: xe,
4260
+ connectionStatus: R,
4261
+ isLoading: Ce,
4262
+ isVoiceMode: Ae,
4263
+ isRateLimited: Te,
4264
+ rateLimitMessage: De,
4265
+ isConversationEnded: Ie,
4266
4266
  isSessionRestoring: Ye,
4267
- openToChatCounter: je,
4268
- voiceEndCounter: Ne,
4269
- incomingCall: B,
4270
- activeCallId: V,
4271
- callConnectionState: He,
4272
- callConnectedAt: Ue,
4273
- isCallMuted: Ge,
4274
- webRTCError: qe,
4267
+ openToChatCounter: Me,
4268
+ voiceEndCounter: Pe,
4269
+ incomingCall: z,
4270
+ activeCallId: B,
4271
+ callConnectionState: Ue,
4272
+ callConnectedAt: We,
4273
+ isCallMuted: Ke,
4274
+ webRTCError: Je,
4275
4275
  language: r,
4276
4276
  historyRef: yt,
4277
4277
  hasSyncedRef: bt,
@@ -4319,24 +4319,24 @@ function vi({ siteId: e, config: t, children: n, language: r = "en" }) {
4319
4319
  j,
4320
4320
  P,
4321
4321
  oe,
4322
- I,
4323
- de,
4324
- be,
4325
- z,
4326
- Se,
4327
- ke,
4328
- we,
4329
- Ee,
4330
- Fe,
4322
+ F,
4323
+ fe,
4324
+ xe,
4325
+ R,
4326
+ Ce,
4327
+ Ae,
4328
+ Te,
4329
+ De,
4330
+ Ie,
4331
4331
  Ye,
4332
- je,
4333
- Ne,
4332
+ Me,
4333
+ Pe,
4334
+ z,
4334
4335
  B,
4335
- V,
4336
- He,
4337
4336
  Ue,
4338
- Ge,
4339
- qe,
4337
+ We,
4338
+ Ke,
4339
+ Je,
4340
4340
  r,
4341
4341
  Vt,
4342
4342
  Ht,
@@ -9417,7 +9417,7 @@ async function Rh(e, t, n) {
9417
9417
  let r = new URLSearchParams({ siteId: t || "" });
9418
9418
  n && r.set("chatId", n);
9419
9419
  let i = Br();
9420
- i && r.set("shopifyCustomerId", String(i)), se(t) === "auto" && r.set("navPreference", "auto");
9420
+ i && r.set("shopifyCustomerId", String(i)), ce(t) === "auto" && r.set("navPreference", "auto");
9421
9421
  let a = await fetch(`${e}/api/voice/session?${r.toString()}`, {
9422
9422
  method: "GET",
9423
9423
  headers: { "Content-Type": "application/json" }
@@ -9473,63 +9473,63 @@ async function zh(e) {
9473
9473
  }
9474
9474
  }, A = (e, t, n) => {
9475
9475
  t && (D.role && D.role !== e && k(), D.role = e, D.text = D.text ? `${D.text} ${t}`.replace(/\s+/g, " ") : t, n && (D.debug = n), D.timer && clearTimeout(D.timer), D.timer = setTimeout(k, yh));
9476
- }, ee = !1, te = !1, ne = !1, j = !1, M = !1, re = !0, N = 0, ie = 0, P = !1, ae = !1, oe = bh, F = null, I = !1, se = !1, ce = () => {
9477
- F && clearTimeout(F);
9476
+ }, ee = !1, te = !1, ne = !1, j = !1, M = !1, re = !0, N = 0, ie = 0, P = !1, ae = !1, oe = bh, se = 0, F = 0, ce = null, le = !1, ue = !1, de = () => {
9477
+ ce && clearTimeout(ce);
9478
9478
  let e = () => {
9479
9479
  if (!ee) {
9480
- if (le.isPlaying()) {
9481
- F = setTimeout(e, 150);
9480
+ if (fe.isPlaying()) {
9481
+ ce = setTimeout(e, 150);
9482
9482
  return;
9483
9483
  }
9484
- if (F = null, I) {
9484
+ if (ce = null, le) {
9485
9485
  p?.();
9486
9486
  return;
9487
9487
  }
9488
- !ee && T.readyState === WebSocket.OPEN && T.send(JSON.stringify({ type: "PlaybackDrained" })), se && (se = !1, d?.());
9488
+ !ee && T.readyState === WebSocket.OPEN && T.send(JSON.stringify({ type: "PlaybackDrained" })), ue && (ue = !1, d?.());
9489
9489
  }
9490
9490
  };
9491
- F = setTimeout(e, 150);
9492
- }, le = Lh(y, () => {
9491
+ ce = setTimeout(e, 150);
9492
+ }, fe = Lh(y, () => {
9493
9493
  j && (j = !1, c?.({ mode: M ? "thinking" : "listening" }));
9494
9494
  }, b);
9495
- typeof window < "u" && (window.__fe_agentAudioPlaying = () => le.isPlaying());
9496
- let ue = y.createMediaStreamSource(v);
9497
- ue.connect(b);
9498
- let de = y.createScriptProcessor(vh, 1, 1), fe = !1, pe = null, me = !1;
9495
+ typeof window < "u" && (window.__fe_agentAudioPlaying = () => fe.isPlaying());
9496
+ let pe = y.createMediaStreamSource(v);
9497
+ pe.connect(b);
9498
+ let me = y.createScriptProcessor(vh, 1, 1), he = !1, ge = null, _e = !1;
9499
9499
  gh({
9500
9500
  assetBase: `${t}/vad`,
9501
9501
  inputRate: _h
9502
9502
  }).then((e) => {
9503
9503
  if (ee) return e.close();
9504
- pe = e, console.debug("[FlowEngage] speech model ready");
9505
- }).catch((e) => console.warn("[FlowEngage] speech model unavailable, using the basic speech check:", e?.message)), de.onaudioprocess = (e) => {
9504
+ ge = e, console.log("[FlowEngage] speech model ready");
9505
+ }).catch((e) => console.warn("[FlowEngage] speech model unavailable, using the basic speech check:", e?.message)), me.onaudioprocess = (e) => {
9506
9506
  if (ee || T.readyState !== WebSocket.OPEN) return;
9507
9507
  let t = e.inputBuffer.getChannelData(0), n = () => T.send(new Int16Array(t.length).buffer);
9508
9508
  if (te) {
9509
- ne || (ne = !0, console.debug("[FlowEngage] mic held — streaming silence to keep socket alive")), fe = !1, N = 0, ie = 0, n();
9509
+ ne || (ne = !0, console.debug("[FlowEngage] mic held — streaming silence to keep socket alive")), he = !1, N = 0, ie = 0, n();
9510
9510
  return;
9511
9511
  }
9512
- let r = kh(t), i = Oh(t), a = le.isPlaying() || ae, o = a ? oe * Eh : oe, s = a ? Th : Ch;
9513
- pe?.push(t), (pe ? r >= o && pe.speechProbability >= Dh : r >= o && i >= xh && i <= Sh) ? (ie = 0, N += 1) : ++ie >= wh && (N = 0);
9512
+ let r = kh(t), i = Oh(t), a = fe.isPlaying() || ae, o = a && !ge ? oe * Eh : oe, s = a ? Th : Ch;
9513
+ ge?.push(t), (ge ? r >= o && ge.speechProbability >= Dh : r >= o && i >= xh && i <= Sh) ? (ie = 0, N += 1) : ++ie >= wh && (N = 0), a && ge?.speechProbability >= Dh && (se = Math.max(se, r)), a && (F = Math.max(F, N));
9514
9514
  let l = N >= Ch;
9515
- if (pe && l !== me && (me = l, T.send(JSON.stringify({
9515
+ if (ge && l !== _e && (_e = l, T.send(JSON.stringify({
9516
9516
  type: "VisitorSpeech",
9517
9517
  active: l
9518
- }))), a ? fe = !1 : !fe && N >= Ch ? (fe = !0, c?.({ mode: "user-speaking" })) : fe && N === 0 && (fe = !1), a && !P && N >= s) {
9518
+ }))), a ? he = !1 : !he && N >= Ch ? (he = !0, c?.({ mode: "user-speaking" })) : he && N === 0 && (he = !1), a && !P && N >= s) {
9519
9519
  P = !0, M = !1, N = 0;
9520
- let e = le.playedMs();
9521
- le.stop(), re = !1, ae = !1, F && !I && (clearTimeout(F), F = null), se = !1, T.send(JSON.stringify({
9520
+ let e = fe.playedMs();
9521
+ fe.stop(), re = !1, ae = !1, ce && !le && (clearTimeout(ce), ce = null), ue = !1, T.send(JSON.stringify({
9522
9522
  type: "VisitorInterrupted",
9523
9523
  played_ms: Math.round(e)
9524
9524
  })), console.debug("[FlowEngage] barge-in — visitor spoke over the agent");
9525
9525
  }
9526
9526
  T.send(Ah(t).buffer);
9527
- }, ue.connect(de), de.connect(y.destination);
9528
- let he = () => {
9527
+ }, pe.connect(me), me.connect(y.destination);
9528
+ let ve = () => {
9529
9529
  if (!ee) {
9530
- ee = !0, pe?.close(), F &&= (clearTimeout(F), null), k(), le.stop(), typeof window < "u" && delete window.__fe_agentAudioPlaying;
9530
+ ee = !0, ge?.close(), ce &&= (clearTimeout(ce), null), k(), fe.stop(), typeof window < "u" && delete window.__fe_agentAudioPlaying;
9531
9531
  try {
9532
- de.disconnect(), ue.disconnect();
9532
+ me.disconnect(), pe.disconnect();
9533
9533
  } catch {}
9534
9534
  if (v.getTracks().forEach((e) => e.stop()), C && C.state !== "inactive") {
9535
9535
  C.onstop = () => Fh(t, n, w, S, x);
@@ -9541,7 +9541,7 @@ async function zh(e) {
9541
9541
  } else S.length && Fh(t, n, w, S, x);
9542
9542
  y.close().catch(() => {}), (T.readyState === WebSocket.OPEN || T.readyState === WebSocket.CONNECTING) && T.close();
9543
9543
  }
9544
- }, ge = async (e) => {
9544
+ }, ye = async (e) => {
9545
9545
  let t = i[e.name];
9546
9546
  if (!t) return u?.({ tool_name: e.name }), { error: `Unknown tool ${e.name}` };
9547
9547
  let n = {};
@@ -9553,10 +9553,10 @@ async function zh(e) {
9553
9553
  } catch (e) {
9554
9554
  return { error: e?.message || "Tool execution failed" };
9555
9555
  }
9556
- }, _e = async (e) => {
9556
+ }, be = async (e) => {
9557
9557
  for (let t of e.functions || []) {
9558
9558
  if (!t.client_side) continue;
9559
- let e = await ge(t);
9559
+ let e = await ye(t);
9560
9560
  if (ee || T.readyState !== WebSocket.OPEN) return;
9561
9561
  T.send(JSON.stringify({
9562
9562
  type: "FunctionCallResponse",
@@ -9565,7 +9565,7 @@ async function zh(e) {
9565
9565
  content: typeof e == "string" ? e : JSON.stringify(e ?? {})
9566
9566
  }));
9567
9567
  }
9568
- }, ve = (e) => {
9568
+ }, xe = (e) => {
9569
9569
  switch (e.type) {
9570
9570
  case "Welcome":
9571
9571
  Number.isFinite(e.barge_in_rms) && e.barge_in_rms > 0 && (oe = e.barge_in_rms), Number.isFinite(e.barge_in_frames) && e.barge_in_frames > 0 && e.barge_in_frames, w = e.session_id || r || n || null, a?.({ conversationId: w });
@@ -9587,25 +9587,25 @@ async function zh(e) {
9587
9587
  break;
9588
9588
  }
9589
9589
  case "UserStartedSpeaking":
9590
- k(), le.stop(), ae = !1, re = !1, j = !1, M = !1, F && !I && (clearTimeout(F), F = null), se = !1, c?.({ mode: "listening" });
9590
+ j && !P && console.log(`[FlowEngage] interrupted by the server, not the widget: loudest speech ${se.toFixed(3)} (needs ${oe}), longest run ${F}/${Th} frames, speech model ${ge ? "on" : "off"}`), k(), fe.stop(), ae = !1, re = !1, j = !1, M = !1, ce && !le && (clearTimeout(ce), ce = null), ue = !1, c?.({ mode: "listening" });
9591
9591
  break;
9592
9592
  case "AgentStartedSpeaking":
9593
- re = !0, j = !0, P = !1, N = 0, c?.({ mode: "speaking" });
9593
+ re = !0, j = !0, P = !1, N = 0, se = 0, F = 0, c?.({ mode: "speaking" });
9594
9594
  break;
9595
9595
  case "AgentAudioDone":
9596
- ae = !1, k(), ce(), le.isPlaying() || (j = !1, c?.({ mode: M ? "thinking" : "listening" }));
9596
+ ae = !1, k(), de(), fe.isPlaying() || (j = !1, c?.({ mode: M ? "thinking" : "listening" }));
9597
9597
  break;
9598
9598
  case "FunctionCallRequest":
9599
- _e(e);
9599
+ be(e);
9600
9600
  break;
9601
9601
  case "AgentPreparing":
9602
9602
  ae = !0;
9603
9603
  break;
9604
9604
  case "AgentTurnComplete":
9605
- M = !1, se = !0, ce();
9605
+ M = !1, ue = !0, de();
9606
9606
  break;
9607
9607
  case "SessionEnding":
9608
- console.debug("[FlowEngage] server is ending the session:", e.reason || "unspecified"), I = !0;
9608
+ console.debug("[FlowEngage] server is ending the session:", e.reason || "unspecified"), le = !0;
9609
9609
  break;
9610
9610
  case "StartWalkthrough":
9611
9611
  h?.();
@@ -9632,7 +9632,7 @@ async function zh(e) {
9632
9632
  };
9633
9633
  return T.onopen = () => T.send(JSON.stringify(_)), T.onmessage = (e) => {
9634
9634
  if (e.data instanceof ArrayBuffer) {
9635
- re && le.enqueue(new Int16Array(e.data));
9635
+ re && fe.enqueue(new Int16Array(e.data));
9636
9636
  return;
9637
9637
  }
9638
9638
  let t;
@@ -9642,14 +9642,14 @@ async function zh(e) {
9642
9642
  return;
9643
9643
  }
9644
9644
  try {
9645
- ve(t);
9645
+ xe(t);
9646
9646
  } catch (e) {
9647
9647
  console.error("[FlowEngage] voice event handler failed:", t?.type, e);
9648
9648
  }
9649
9649
  }, T.onerror = () => l?.(/* @__PURE__ */ Error("Voice connection failed")), T.onclose = () => {
9650
- he(), o?.();
9650
+ ve(), o?.();
9651
9651
  }, {
9652
- endSession: async () => he(),
9652
+ endSession: async () => ve(),
9653
9653
  sendContextualUpdate: (e) => {
9654
9654
  ee || T.readyState !== WebSocket.OPEN || !e || T.send(JSON.stringify({
9655
9655
  type: "UpdatePrompt",
@@ -10489,7 +10489,7 @@ function Jg({ src: e, name: t, imgStyle: n, initialsSpanStyle: r }) {
10489
10489
  //#region src/components/MessageList.jsx
10490
10490
  function Yg({ siteId: e, onChoose: t }) {
10491
10491
  let [n, r] = m(null), i = (n) => {
10492
- ce(e, n), r(n), t?.(n);
10492
+ le(e, n), r(n), t?.(n);
10493
10493
  };
10494
10494
  return /* @__PURE__ */ g("div", {
10495
10495
  style: {
@@ -12961,10 +12961,10 @@ function L_(e) {
12961
12961
  sender: "user",
12962
12962
  message: e
12963
12963
  }]);
12964
- n && we(t, n);
12964
+ n && Te(t, n);
12965
12965
  }
12966
12966
  } catch {}
12967
- Oe();
12967
+ ke();
12968
12968
  let e = o;
12969
12969
  try {
12970
12970
  e = new URL(o, typeof window < "u" ? window.location.href : "").href;
@@ -12974,7 +12974,7 @@ function L_(e) {
12974
12974
  let e = new URL(o, window.location.href).pathname.split("/").filter(Boolean).pop() || "";
12975
12975
  n = e ? e.replace(/[-_]/g, " ").replace(/\b\w/g, (e) => e.toUpperCase()) : "Home";
12976
12976
  } catch {}
12977
- t && typeof window < "u" && Fe(t, window.location.href, e, n), xr(e);
12977
+ t && typeof window < "u" && Ie(t, window.location.href, e, n), xr(e);
12978
12978
  try {
12979
12979
  window.__fe_agent_nav = {
12980
12980
  path: new URL(e, window.location.href).pathname,
@@ -13339,7 +13339,7 @@ function L_(e) {
13339
13339
  try {
13340
13340
  r = new URL(e, window.location.href).href;
13341
13341
  } catch {}
13342
- return t && Fe(t, window.location.href, r, n), xr(r), Or().then(() => {
13342
+ return t && Ie(t, window.location.href, r, n), xr(r), Or().then(() => {
13343
13343
  window.location.assign(r);
13344
13344
  }), `OK_NAVIGATING to ${n}. The page is loading.`;
13345
13345
  }
@@ -13803,86 +13803,86 @@ function $_({ copy: e, orbColors: t, primaryColor: n, onVoice: r, onText: i, onC
13803
13803
  }
13804
13804
  function ev({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i, apiBaseUrl: a, chatId: s, historyRef: l, onMessageSync: u, beaconSyncVoiceTranscript: d, widgetPosition: f = "bottom-right", voiceEndCounter: h, websiteName: v, voiceFirstMessage: y, captureVisitorEmail: b, emailRequired: x, emailCaptureEnabled: S = !0, listeningLabel: C = "Listening...", thinkingLabel: w = "Thinking...", enterChatModeLabel: T = "Enter Chat Mode", endConversationLabel: E = "End Conversation" }) {
13805
13805
  c(() => (console.log("[FlowEngage:VoiceDebug] 🔵 VoiceMode MOUNTED"), () => console.log("[FlowEngage:VoiceDebug] 🔴 VoiceMode UNMOUNTED")), []);
13806
- let [D, O] = m("idle"), [k, A] = m(!1), [ee, te] = m(!1), [ne, j] = m(() => se(i) === "auto"), M = () => {
13806
+ let [D, O] = m("idle"), [k, A] = m(!1), [ee, te] = m(!1), [ne, j] = m(() => ce(i) === "auto"), M = () => {
13807
13807
  let e = ne ? "ask" : "auto";
13808
- ce(i, e), j(e === "auto");
13809
- }, [re, N] = m(!1), [ie, P] = m(""), [ae, oe] = m(""), F = p(!1), I = p(!1), le = p(null), ue = p(0), de = p(""), fe = p(!1), pe = p(0), me = p(!1), he = p(!1), ge = p(!1), _e = p([]), ve = p(null), ye = p(""), be = p(null), L = (e) => {
13810
- me.current = e, e || (he.current = !1), z.current?.setWalkthroughActive?.(e);
13808
+ le(i, e), j(e === "auto");
13809
+ }, [re, N] = m(!1), [ie, P] = m(""), [ae, oe] = m(""), se = p(!1), F = p(!1), ue = p(null), de = p(0), fe = p(""), pe = p(!1), me = p(0), he = p(!1), ge = p(!1), _e = p(!1), ve = p([]), ye = p(null), be = p(""), xe = p(null), I = (e) => {
13810
+ he.current = e, e || (ge.current = !1), R.current?.setWalkthroughActive?.(e);
13811
13811
  };
13812
- be.current = async () => {
13813
- if (he.current) return;
13812
+ xe.current = async () => {
13813
+ if (ge.current) return;
13814
13814
  let e = typeof window < "u" ? window.location.pathname : null;
13815
- if (e && ve.current && e !== ve.current) {
13816
- console.log("[FlowEngage] walkthrough ended — visitor left " + ve.current), ve.current = null, _e.current = [], L(!1);
13815
+ if (e && ye.current && e !== ye.current) {
13816
+ console.log("[FlowEngage] walkthrough ended — visitor left " + ye.current), ye.current = null, ve.current = [], I(!1);
13817
13817
  return;
13818
13818
  }
13819
- let t = _e.current;
13820
- R.current += 1;
13821
- let n = R.current, r = t[n];
13819
+ let t = ve.current;
13820
+ L.current += 1;
13821
+ let n = L.current, r = t[n];
13822
13822
  if (!r) {
13823
- if (L(!1), t.length) z.current?.sendUserMessage?.("That was the last section. Say so in one short sentence and ask if they want to explore any section further.");
13823
+ if (I(!1), t.length) R.current?.sendUserMessage?.("That was the last section. Say so in one short sentence and ask if they want to explore any section further.");
13824
13824
  else if (n === 0) {
13825
13825
  let e = "";
13826
13826
  try {
13827
- let t = await xe.current?.["fwh-read-content-mvp"]?.({});
13827
+ let t = await Se.current?.["fwh-read-content-mvp"]?.({});
13828
13828
  typeof t == "string" && t && !/^Could not/i.test(t) && (e = t.slice(0, 2800));
13829
13829
  } catch {}
13830
- z.current?.sendUserMessage?.(e ? `Give the visitor a complete spoken overview of this page in 4-6 sentences, based ONLY on this page content:\n"""${e}"""\nThen ask which part they'd like to hear more about. Do not call any tool.` : "Give the visitor a complete spoken overview of this page in 4-6 sentences based on what you know about it, then ask which part they'd like to hear more about. Do not call any tool.", { suppressQuestion: !0 });
13830
+ R.current?.sendUserMessage?.(e ? `Give the visitor a complete spoken overview of this page in 4-6 sentences, based ONLY on this page content:\n"""${e}"""\nThen ask which part they'd like to hear more about. Do not call any tool.` : "Give the visitor a complete spoken overview of this page in 4-6 sentences based on what you know about it, then ask which part they'd like to hear more about. Do not call any tool.", { suppressQuestion: !0 });
13831
13831
  }
13832
13832
  return;
13833
13833
  }
13834
13834
  try {
13835
- await xe.current?.highlightOnPage?.({ section_text: r });
13835
+ await Se.current?.highlightOnPage?.({ section_text: r });
13836
13836
  } catch (e) {
13837
13837
  console.warn("[FlowEngage] walkthrough highlight failed:", e?.message || e);
13838
13838
  }
13839
13839
  console.debug(`[FlowEngage] walkthrough step ${n + 1}/${t.length}: ${r}`);
13840
13840
  let i = "";
13841
13841
  try {
13842
- let e = await xe.current?.["fwh-read-content-mvp"]?.({ section_text: r });
13842
+ let e = await Se.current?.["fwh-read-content-mvp"]?.({ section_text: r });
13843
13843
  typeof e == "string" && e && !/^Could not/i.test(e) && (i = e.slice(0, 2500));
13844
13844
  } catch {}
13845
- z.current?.sendUserMessage?.(`Describe the section titled "${r}".` + (i ? ` Its content:\n"""${i}"""` : ""), { suppressQuestion: !0 });
13845
+ R.current?.sendUserMessage?.(`Describe the section titled "${r}".` + (i ? ` Its content:\n"""${i}"""` : ""), { suppressQuestion: !0 });
13846
13846
  };
13847
- let R = p(0), z = p(null), xe = p(null), Se = p(""), Ce = p(async () => {}), De = p(!1), ke = p(!1), Ae = p(!1), je = p(!1), Me = p("minimized"), Pe = p(null), Fe = p(null), B = p(null), Le = p(0), Re = p(!1), ze = p("idle"), Be = p(null), V = p(!1), Ve = p(null), He = o((e = "minimized") => {
13847
+ let L = p(0), R = p(null), Se = p(null), Ce = p(""), we = p(async () => {}), Oe = p(!1), Ae = p(!1), je = p(!1), Me = p(!1), Ne = p("minimized"), Fe = p(null), Ie = p(null), z = p(null), Re = p(0), ze = p(!1), Be = p("idle"), Ve = p(null), B = p(!1), He = p(null), Ue = o((e = "minimized") => {
13848
13848
  console.warn("[FlowEngage:VoiceDebug] 🛑 requestSessionShutdown called", {
13849
13849
  destination: e,
13850
13850
  stack: (/* @__PURE__ */ Error()).stack?.split("\n").slice(1, 4).join(" | ")
13851
- }), Me.current = e, je.current = !0, queueMicrotask(() => {
13852
- De.current || (De.current = !0, Ce.current?.());
13851
+ }), Ne.current = e, Me.current = !0, queueMicrotask(() => {
13852
+ Oe.current || (Oe.current = !0, we.current?.());
13853
13853
  });
13854
- }, [l]), H = o(() => {
13855
- le.current &&= (clearTimeout(le.current), null);
13854
+ }, [l]), V = o(() => {
13855
+ ue.current &&= (clearTimeout(ue.current), null);
13856
13856
  }, []);
13857
13857
  c(() => {
13858
13858
  if (x) {
13859
- F.current = !1;
13859
+ se.current = !1;
13860
13860
  return;
13861
13861
  }
13862
- if (F.current = !0, I.current = !1, N(!1), H(), fe.current) {
13863
- fe.current = !1, z.current?.setMicMuted?.(!1);
13864
- let e = de.current;
13865
- de.current = "", z.current?.injectAgentSpeech?.("Thanks — I already have your email on file.", "interrupt"), e && z.current?.sendUserMessage?.(`The visitor's email is already on file — do not ask for it. Answer their question now: "${e}"`);
13866
- }
13867
- z.current?.sendContextualUpdate?.("EMAIL REQUIREMENT SATISFIED — the visitor's email is already on file. All earlier instructions about requiring or asking for an email are VOID. Never ask for it again.");
13868
- }, [x, H]);
13869
- let Ue = /(that covers everything|that was all|covered everything|that(?:'|’)?s everything)/i, We = /^((uh+|um+|so|well|okay|ok|yeah)[,.\s]+)*(yes|yeah|yep|yup|sure|ok(ay)?|please|continue|go on|next|keep going|carry on|go ahead|resume|back to the tour)[\s.!,]*$/i, Ge = /(would you like (me )?to take you|shall i take you|want me to take you|would you like to (go|explore|visit|see)|take you there)/i, Ke = /^((uh+|um+|oh|ah|so|well)[,.\s]+)*(cool|nice|great|awesome|wow|lovely|perfect|got it|gotcha|i see|understood|makes sense|interesting|right|alright|sounds good|mm+-?hmm+|hmm+|k)[\s.!,]*$/i, qe = (e) => String(e || "").replace(/[\s.,!?]*((uh+|um+|er+|hmm+|mm+)[\s.,!?]*)+$/i, "").trim(), Je = o(() => {
13870
- H(), le.current = setTimeout(() => {
13871
- if (!(!I.current || F.current)) if (ue.current < 3) {
13872
- ue.current += 1;
13862
+ if (se.current = !0, F.current = !1, N(!1), V(), pe.current) {
13863
+ pe.current = !1, R.current?.setMicMuted?.(!1);
13864
+ let e = fe.current;
13865
+ fe.current = "", R.current?.injectAgentSpeech?.("Thanks — I already have your email on file.", "interrupt"), e && R.current?.sendUserMessage?.(`The visitor's email is already on file — do not ask for it. Answer their question now: "${e}"`);
13866
+ }
13867
+ R.current?.sendContextualUpdate?.("EMAIL REQUIREMENT SATISFIED — the visitor's email is already on file. All earlier instructions about requiring or asking for an email are VOID. Never ask for it again.");
13868
+ }, [x, V]);
13869
+ let We = /(that covers everything|that was all|covered everything|that(?:'|’)?s everything)/i, Ge = /^((uh+|um+|so|well|okay|ok|yeah)[,.\s]+)*(yes|yeah|yep|yup|sure|ok(ay)?|please|continue|go on|next|keep going|carry on|go ahead|resume|back to the tour)[\s.!,]*$/i, Ke = /(would you like (me )?to take you|shall i take you|want me to take you|would you like to (go|explore|visit|see)|take you there)/i, qe = /^((uh+|um+|oh|ah|so|well)[,.\s]+)*(cool|nice|great|awesome|wow|lovely|perfect|got it|gotcha|i see|understood|makes sense|interesting|right|alright|sounds good|mm+-?hmm+|hmm+|k)[\s.!,]*$/i, Je = (e) => String(e || "").replace(/[\s.,!?]*((uh+|um+|er+|hmm+|mm+)[\s.,!?]*)+$/i, "").trim(), H = o(() => {
13870
+ V(), ue.current = setTimeout(() => {
13871
+ if (!(!F.current || se.current)) if (de.current < 3) {
13872
+ de.current += 1;
13873
13873
  try {
13874
- z.current?.injectAgentSpeech?.("I still need your email in the box below to continue — could you enter it, please?", "queue");
13874
+ R.current?.injectAgentSpeech?.("I still need your email in the box below to continue — could you enter it, please?", "queue");
13875
13875
  } catch {}
13876
- Je();
13876
+ H();
13877
13877
  } else {
13878
13878
  try {
13879
- z.current?.injectAgentSpeech?.("Since I haven't received your email, I'll close this session for now. Feel free to come back anytime — take care!", "queue");
13879
+ R.current?.injectAgentSpeech?.("Since I haven't received your email, I'll close this session for now. Feel free to come back anytime — take care!", "queue");
13880
13880
  } catch {}
13881
- I.current = !1, N(!1), H(), Re.current = !0;
13881
+ F.current = !1, N(!1), V(), ze.current = !0;
13882
13882
  }
13883
13883
  }, 1e4);
13884
- }, [H]), Ye = o(async (e) => {
13885
- je.current = !0;
13884
+ }, [V]), Ye = o(async (e) => {
13885
+ Me.current = !0;
13886
13886
  try {
13887
13887
  Nn();
13888
13888
  } catch {}
@@ -13890,12 +13890,12 @@ function ev({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
13890
13890
  ag();
13891
13891
  } catch {}
13892
13892
  if (i) try {
13893
- Ie(i);
13893
+ Le(i);
13894
13894
  } catch {}
13895
13895
  try {
13896
- await z.current?.endSession?.();
13896
+ await R.current?.endSession?.();
13897
13897
  } catch {}
13898
- let t = Pe.current, n = Fe.current;
13898
+ let t = Fe.current, n = Ie.current;
13899
13899
  if (t && s && a) {
13900
13900
  let e = n ? Math.round((Date.now() - n) / 1e3) : 0;
13901
13901
  fetch(`${a}/api/voice/save-chat-recording`, {
@@ -13909,8 +13909,8 @@ function ev({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
13909
13909
  })
13910
13910
  }).catch((e) => console.warn("[FlowEngage] save-chat-recording failed:", e.message));
13911
13911
  }
13912
- if (Pe.current = null, Fe.current = null, z.current = null, O("idle"), A(!1), De.current = !1, Nr(), i) try {
13913
- Ee(i);
13912
+ if (Fe.current = null, Ie.current = null, R.current = null, O("idle"), A(!1), Oe.current = !1, Nr(), i) try {
13913
+ De(i);
13914
13914
  } catch {}
13915
13915
  typeof u == "function" && await u(l.current), e?.();
13916
13916
  }, [
@@ -13920,10 +13920,10 @@ function ev({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
13920
13920
  s,
13921
13921
  a
13922
13922
  ]);
13923
- Ce.current = () => Ye(Me.current === "chat" ? t : n), c(() => {
13924
- ke.current = k;
13923
+ we.current = () => Ye(Ne.current === "chat" ? t : n), c(() => {
13924
+ Ae.current = k;
13925
13925
  }, [k]), c(() => {
13926
- h && He("chat");
13926
+ h && Ue("chat");
13927
13927
  }, [h]), c(() => {
13928
13928
  let e = !1, o = null, c = null, p = null;
13929
13929
  return (async () => {
@@ -13933,13 +13933,13 @@ function ev({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
13933
13933
  }
13934
13934
  try {
13935
13935
  if ((await navigator.mediaDevices.getUserMedia({ audio: !0 })).getTracks().forEach((e) => e.stop()), e) return;
13936
- l.current = [], Se.current = "", De.current = !1, Ae.current = !1, je.current = !1, Me.current = "minimized", Mr({ onBeforeNavigate: () => {
13936
+ l.current = [], Ce.current = "", Oe.current = !1, je.current = !1, Me.current = !1, Ne.current = "minimized", Mr({ onBeforeNavigate: () => {
13937
13937
  if (i && l.current.length > 0) try {
13938
13938
  let e = __(l.current);
13939
- e && we(i, e);
13939
+ e && Te(i, e);
13940
13940
  } catch {}
13941
13941
  if (!Qn()) {
13942
- let e = Pe.current, t = Fe.current;
13942
+ let e = Fe.current, t = Ie.current;
13943
13943
  if (e && s && a) try {
13944
13944
  let n = t ? Math.round((Date.now() - t) / 1e3) : 0, r = JSON.stringify({
13945
13945
  chatId: s,
@@ -13952,31 +13952,31 @@ function ev({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
13952
13952
  headers: { "Content-Type": "application/json" },
13953
13953
  body: r,
13954
13954
  keepalive: !0
13955
- }).catch(() => {}), Pe.current = null, Fe.current = null;
13955
+ }).catch(() => {}), Fe.current = null, Ie.current = null;
13956
13956
  } catch {}
13957
13957
  }
13958
- Oe();
13958
+ ke();
13959
13959
  } });
13960
13960
  let t = B_(L_({
13961
13961
  siteId: i || null,
13962
13962
  apiBaseUrl: a || null,
13963
13963
  chatId: s || null,
13964
- getLastUserVoiceText: () => Se.current,
13964
+ getLastUserVoiceText: () => Ce.current,
13965
13965
  beaconSyncFullVoiceHistory: () => d?.(l.current),
13966
- isWalkthroughActive: () => me.current && !he.current,
13966
+ isWalkthroughActive: () => he.current && !ge.current,
13967
13967
  requestEndSession: () => {
13968
- Re.current = !0;
13968
+ ze.current = !0;
13969
13969
  },
13970
13970
  requestEmailCollection: () => {
13971
- S && (F.current || I.current || (I.current = !0, ue.current = 0, N(!0), Je()));
13971
+ S && (se.current || F.current || (F.current = !0, de.current = 0, N(!0), H()));
13972
13972
  }
13973
- })), n = !!(i ? Te(i) : null)?.transcript, r = i ? Ie(i) : null, u = !!r, m = typeof window < "u" ? window.location.pathname : "/", h = typeof document < "u" ? document.title : "", g = m.replace(/^\/[a-z]{2}(?:-[a-z]{2})?(?=\/|$)/i, "") || "/", _ = g === "/" || g === "", b = {
13973
+ })), n = !!(i ? Ee(i) : null)?.transcript, r = i ? Le(i) : null, u = !!r, m = typeof window < "u" ? window.location.pathname : "/", h = typeof document < "u" ? document.title : "", g = m.replace(/^\/[a-z]{2}(?:-[a-z]{2})?(?=\/|$)/i, "") || "/", _ = g === "/" || g === "", b = {
13974
13974
  apiBaseUrl: a,
13975
13975
  siteId: i,
13976
13976
  chatId: s,
13977
13977
  clientTools: t
13978
13978
  };
13979
- xe.current = t;
13979
+ Se.current = t;
13980
13980
  let C = (m.split("/").filter(Boolean).pop() || "").replace(/[-_]/g, " ").replace(/\b\w/g, (e) => e.toUpperCase()), w = "";
13981
13981
  h && h.includes("|") && (w = h.split("|").map((e) => e.trim()).filter(Boolean).reduce((e, t) => e.length <= t.length ? e : t));
13982
13982
  let T = w || C || "", E = T ? `the ${T} page` : "this page", D = (() => {
@@ -13992,23 +13992,23 @@ function ev({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
13992
13992
  let e = v || "";
13993
13993
  b.greeting = y || (_ ? e ? `Hi, welcome to ${e}! How may I help you?` : "Hi, welcome! How may I help you?" : `Welcome to ${E}! How may I help you?`), _ || console.log(`[FlowEngage] 🏠 Page-context greeting: "${T}" for ${m}`);
13994
13994
  }
13995
- let k = !1, ee = !1, te = S && !!x && !ge.current, ne = await Bh.startSession({
13995
+ let k = !1, ee = !1, te = S && !!x && !_e.current, ne = await Bh.startSession({
13996
13996
  ...b,
13997
13997
  onConnect: ({ conversationId: e }) => {
13998
- Pe.current = e, Fe.current = Date.now(), console.log("[FlowEngage] 🎙️ AI chat session connected:", e);
13998
+ Fe.current = e, Ie.current = Date.now(), console.log("[FlowEngage] 🎙️ AI chat session connected:", e);
13999
13999
  },
14000
14000
  onUnhandledClientToolCall: (e) => console.error("[FlowEngage] Unhandled tool:", e?.tool_name),
14001
14001
  onSessionInfo: ({ emailOnFile: e }) => {
14002
- ge.current = !!e, e && (F.current = !0, I.current = !1, N(!1), H(), console.log("[FlowEngage] email already on file per server — gate disabled"));
14002
+ _e.current = !!e, e && (se.current = !0, F.current = !1, N(!1), V(), console.log("[FlowEngage] email already on file per server — gate disabled"));
14003
14003
  },
14004
14004
  onAgentTurnEnd: () => {
14005
- e || me.current && (he.current || fe.current || setTimeout(() => be.current?.(), 250));
14005
+ e || he.current && (ge.current || pe.current || setTimeout(() => xe.current?.(), 250));
14006
14006
  },
14007
14007
  onSessionEnding: () => {
14008
- e || He("minimized");
14008
+ e || Ue("minimized");
14009
14009
  },
14010
14010
  onStartWalkthrough: () => {
14011
- e || (typeof window < "u" && (window.__fe_user_nav_during_speech = null), L(!0), he.current = !1, pe.current = 0, R.current = -1, _e.current = z_(), ve.current = typeof window < "u" ? window.location.pathname : null, console.log(`[FlowEngage] walkthrough started — ${_e.current.length} sections on this page`), be.current?.());
14011
+ e || (typeof window < "u" && (window.__fe_user_nav_during_speech = null), I(!0), ge.current = !1, me.current = 0, L.current = -1, ve.current = z_(), ye.current = typeof window < "u" ? window.location.pathname : null, console.log(`[FlowEngage] walkthrough started — ${ve.current.length} sections on this page`), xe.current?.());
14012
14012
  },
14013
14013
  onPanel: ({ title: t, items: n }) => {
14014
14014
  e || rg(n, {
@@ -14020,106 +14020,106 @@ function ev({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
14020
14020
  onModeChange: ({ mode: t, tentative: n }) => {
14021
14021
  if (!e) {
14022
14022
  if (t === "speaking") {
14023
- Be.current &&= (clearTimeout(Be.current), null), Ve.current &&= (clearTimeout(Ve.current), null), O("speaking"), ze.current = "speaking", V.current = !1;
14023
+ Ve.current &&= (clearTimeout(Ve.current), null), He.current &&= (clearTimeout(He.current), null), O("speaking"), Be.current = "speaking", B.current = !1;
14024
14024
  return;
14025
14025
  }
14026
14026
  if (t === "user-speaking") {
14027
- if (I.current && !F.current && Je(), Ve.current &&= (clearTimeout(Ve.current), null), ze.current === "speaking") return;
14027
+ if (F.current && !se.current && H(), He.current &&= (clearTimeout(He.current), null), Be.current === "speaking") return;
14028
14028
  try {
14029
14029
  Nn();
14030
14030
  } catch {}
14031
- Be.current &&= (clearTimeout(Be.current), null), ze.current !== "listening" && (O("listening"), ze.current = "listening");
14031
+ Ve.current &&= (clearTimeout(Ve.current), null), Be.current !== "listening" && (O("listening"), Be.current = "listening");
14032
14032
  return;
14033
14033
  }
14034
14034
  if (t === "thinking") {
14035
- if (Be.current &&= (clearTimeout(Be.current), null), Ve.current &&= (clearTimeout(Ve.current), null), ze.current === "speaking") return;
14036
- O("thinking"), ze.current = "thinking", n && (Ve.current = setTimeout(() => {
14037
- Ve.current = null, !(e || ze.current !== "thinking") && (ze.current = "listening", O("listening"));
14035
+ if (Ve.current &&= (clearTimeout(Ve.current), null), He.current &&= (clearTimeout(He.current), null), Be.current === "speaking") return;
14036
+ O("thinking"), Be.current = "thinking", n && (He.current = setTimeout(() => {
14037
+ He.current = null, !(e || Be.current !== "thinking") && (Be.current = "listening", O("listening"));
14038
14038
  }, 4e3));
14039
14039
  return;
14040
14040
  }
14041
- if (ze.current = "listening", Re.current) {
14042
- Re.current = !1, He();
14041
+ if (Be.current = "listening", ze.current) {
14042
+ ze.current = !1, Ue();
14043
14043
  return;
14044
14044
  }
14045
- if (te && !ee && !F.current && !ge.current) {
14045
+ if (te && !ee && !se.current && !_e.current) {
14046
14046
  ee = !0;
14047
14047
  try {
14048
- z.current?.sendContextualUpdate?.("The visitor hasn't given their email yet; the app will ask for it when they first speak.");
14048
+ R.current?.sendContextualUpdate?.("The visitor hasn't given their email yet; the app will ask for it when they first speak.");
14049
14049
  } catch {}
14050
14050
  }
14051
- Be.current && clearTimeout(Be.current), Be.current = setTimeout(() => {
14052
- e || ze.current !== "speaking" && (V.current || (Be.current = null, ze.current = "listening", O("listening")));
14051
+ Ve.current && clearTimeout(Ve.current), Ve.current = setTimeout(() => {
14052
+ e || Be.current !== "speaking" && (B.current || (Ve.current = null, Be.current = "listening", O("listening")));
14053
14053
  }, 1200);
14054
14054
  }
14055
14055
  },
14056
14056
  onMessage: (t) => {
14057
- if (e || fe.current && t.role !== "user" && !/email/i.test(String(t.message || ""))) return;
14057
+ if (e || pe.current && t.role !== "user" && !/email/i.test(String(t.message || ""))) return;
14058
14058
  let n = t.role === "user" && /^(Describe the section titled "|\[SYSTEM:|Give the visitor a complete spoken overview|That was the last section)/.test(String(t.message || "").trim());
14059
14059
  if (t.role === "user" && !n) try {
14060
14060
  ag();
14061
14061
  } catch {}
14062
- if (!n && t.role === "user" && me.current) {
14063
- let e = String(t.message || "").trim(), n = qe(e), r = (e) => !!e && (We.test(e) || Ke.test(e));
14064
- Ge.test(ye.current || "") ? (console.log("[FlowEngage] walkthrough ended — visitor accepted a navigation offer"), ve.current = null, _e.current = [], L(!1)) : !n || r(e) || r(n) ? he.current && (he.current = !1, console.debug("[FlowEngage] walkthrough resumed by visitor"), setTimeout(() => be.current?.(), 300)) : (console.log("[FlowEngage] walkthrough ended — visitor moved to a new topic"), ve.current = null, _e.current = [], L(!1));
14062
+ if (!n && t.role === "user" && he.current) {
14063
+ let e = String(t.message || "").trim(), n = Je(e), r = (e) => !!e && (Ge.test(e) || qe.test(e));
14064
+ Ke.test(be.current || "") ? (console.log("[FlowEngage] walkthrough ended — visitor accepted a navigation offer"), ye.current = null, ve.current = [], I(!1)) : !n || r(e) || r(n) ? ge.current && (ge.current = !1, console.debug("[FlowEngage] walkthrough resumed by visitor"), setTimeout(() => xe.current?.(), 300)) : (console.log("[FlowEngage] walkthrough ended — visitor moved to a new topic"), ye.current = null, ve.current = [], I(!1));
14065
14065
  }
14066
- if (t.role !== "user" && !n && (ye.current = String(t.message || "")), t.role !== "user" && Ue.test(String(t.message || ""))) {
14067
- let e = _e.current.length;
14068
- !e || R.current >= e - 1 ? L(!1) : console.debug(`[FlowEngage] agent claimed completion at step ${R.current + 1}/${e} — ignoring, tour continues`);
14066
+ if (t.role !== "user" && !n && (be.current = String(t.message || "")), t.role !== "user" && We.test(String(t.message || ""))) {
14067
+ let e = ve.current.length;
14068
+ !e || L.current >= e - 1 ? I(!1) : console.debug(`[FlowEngage] agent claimed completion at step ${L.current + 1}/${e} — ignoring, tour continues`);
14069
14069
  }
14070
14070
  let r = t.role === "user" ? "user" : "bot", a = t.message || t.text || t.content || "";
14071
14071
  if (a) {
14072
- if (r === "user" && (Se.current = a, typeof window < "u" && (window.__fe_user_nav_during_speech = null), V.current = !0, Be.current &&= (clearTimeout(Be.current), null), ze.current !== "speaking" && (O("thinking"), ze.current = "thinking"), te && !k && !F.current && !ge.current && (k = !0, de.current = a, fe.current = !0, z.current?.injectAgentSpeech?.("Before I answer that, could you please enter your email in the text box below?", "interrupt"), z.current?.setMicMuted?.(!0), I.current || (I.current = !0, ue.current = 0, N(!0), Je()))), l.current = [...l.current, {
14072
+ if (r === "user" && (Ce.current = a, typeof window < "u" && (window.__fe_user_nav_during_speech = null), B.current = !0, Ve.current &&= (clearTimeout(Ve.current), null), Be.current !== "speaking" && (O("thinking"), Be.current = "thinking"), te && !k && !se.current && !_e.current && (k = !0, fe.current = a, pe.current = !0, R.current?.injectAgentSpeech?.("Before I answer that, could you please enter your email in the text box below?", "interrupt"), R.current?.setMicMuted?.(!0), F.current || (F.current = !0, de.current = 0, N(!0), H()))), l.current = [...l.current, {
14073
14073
  sender: r,
14074
14074
  message: a,
14075
14075
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
14076
14076
  debug: t.debug
14077
14077
  }], i) try {
14078
14078
  let e = __(l.current);
14079
- e && we(i, e);
14079
+ e && Te(i, e);
14080
14080
  } catch {}
14081
14081
  if (X_(r, a)) {
14082
- Re.current = !0;
14082
+ ze.current = !0;
14083
14083
  return;
14084
14084
  }
14085
- ke.current && r === "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(a) && (Le.current += 1, Le.current >= 5 && He("minimized"));
14085
+ Ae.current && r === "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(a) && (Re.current += 1, Re.current >= 5 && Ue("minimized"));
14086
14086
  }
14087
14087
  },
14088
14088
  onError: (t) => {
14089
- if (!e && !je.current && !Ae.current && !Ne()) {
14090
- Ae.current = !0, console.error("[FlowEngageVoiceCall] session:error", {
14089
+ if (!e && !Me.current && !je.current && !Pe()) {
14090
+ je.current = !0, console.error("[FlowEngageVoiceCall] session:error", {
14091
14091
  message: t?.message,
14092
14092
  name: t?.name,
14093
14093
  raw: t
14094
14094
  });
14095
14095
  try {
14096
- z.current?.setMicMuted?.(!0);
14096
+ R.current?.setMicMuted?.(!0);
14097
14097
  } catch {}
14098
- A(!0), O("error"), He("chat");
14098
+ A(!0), O("error"), Ue("chat");
14099
14099
  }
14100
14100
  },
14101
14101
  onDisconnect: (t) => {
14102
- if (e || je.current || Ae.current || Ne()) return;
14102
+ if (e || Me.current || je.current || Pe()) return;
14103
14103
  let n = l.current?.length || 0;
14104
14104
  console.warn("[FlowEngageVoiceCall] session:disconnected", {
14105
14105
  historyCount: n,
14106
14106
  reason: t?.reason,
14107
14107
  closeCode: t?.context?.code,
14108
14108
  closeReason: t?.context?.reason || t?.message,
14109
- lastUserText: Se.current || "",
14110
- wasMuted: ke.current
14111
- }), Ae.current = !0;
14109
+ lastUserText: Ce.current || "",
14110
+ wasMuted: Ae.current
14111
+ }), je.current = !0;
14112
14112
  try {
14113
- z.current?.setMicMuted?.(!0);
14113
+ R.current?.setMicMuted?.(!0);
14114
14114
  } catch {}
14115
- A(!0), He("chat");
14115
+ A(!0), Ue("chat");
14116
14116
  }
14117
14117
  });
14118
14118
  if (e) {
14119
14119
  console.warn("[FlowEngage:VoiceDebug] ❌ cancelled=true after startSession resolved — killing session immediately"), ne.endSession().catch(() => {});
14120
14120
  return;
14121
14121
  }
14122
- o = ne, z.current = ne, O("listening");
14122
+ o = ne, R.current = ne, O("listening");
14123
14123
  try {
14124
14124
  sessionStorage.setItem(`el_conv_${i}`, ne.getId());
14125
14125
  } catch {}
@@ -14167,7 +14167,7 @@ function ev({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
14167
14167
  if (o) {
14168
14168
  typeof window < "u" && (window.__fe_agent_nav = null), console.log(`[FlowEngage] agent-driven navigation settled: "${s}" → "${i}"`);
14169
14169
  try {
14170
- U_(z.current, c, u);
14170
+ U_(R.current, c, u);
14171
14171
  } catch {}
14172
14172
  return;
14173
14173
  }
@@ -14179,7 +14179,7 @@ function ev({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
14179
14179
  ts: Date.now()
14180
14180
  }), console.log(`[FlowEngage] visitor navigation detected: "${s}" → "${i}" (agent target: ${D || "none"})`);
14181
14181
  try {
14182
- U_(z.current, c, u, null, f);
14182
+ U_(R.current, c, u, null, f);
14183
14183
  } catch {}
14184
14184
  };
14185
14185
  c = window.history.pushState.bind(window.history), window.history.pushState = (...e) => {
@@ -14187,7 +14187,7 @@ function ev({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
14187
14187
  }, p = () => setTimeout(i, 50), window.addEventListener("popstate", p);
14188
14188
  }
14189
14189
  } catch (r) {
14190
- e || (console.error("[FlowEngage] startSession failed", r), r.message && r.message.includes("Too many voice sessions") ? (alert(r.message), n && n("minimized")) : (O("error"), Me.current = "chat", window.setTimeout(() => {
14190
+ e || (console.error("[FlowEngage] startSession failed", r), r.message && r.message.includes("Too many voice sessions") ? (alert(r.message), n && n("minimized")) : (O("error"), Ne.current = "chat", window.setTimeout(() => {
14191
14191
  e || t?.();
14192
14192
  }, 0)));
14193
14193
  }
@@ -14196,15 +14196,15 @@ function ev({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
14196
14196
  agentId: r,
14197
14197
  siteId: i,
14198
14198
  apiBaseUrl: a
14199
- }), e = !0, je.current = !0;
14199
+ }), e = !0, Me.current = !0;
14200
14200
  try {
14201
14201
  Nn();
14202
14202
  } catch {}
14203
14203
  if (i) try {
14204
- Ie(i);
14204
+ Le(i);
14205
14205
  } catch {}
14206
- typeof window < "u" && (window.__fe_user_nav_during_speech = null), Nr(), Be.current &&= (clearTimeout(Be.current), null), Ve.current &&= (clearTimeout(Ve.current), null), le.current &&= (clearTimeout(le.current), null), V.current = !1, ze.current = "idle", c && typeof window < "u" && (window.history.pushState = c), p && typeof window < "u" && window.removeEventListener("popstate", p);
14207
- let t = o || z.current, n = Pe.current, d = Fe.current;
14206
+ typeof window < "u" && (window.__fe_user_nav_during_speech = null), Nr(), Ve.current &&= (clearTimeout(Ve.current), null), He.current &&= (clearTimeout(He.current), null), ue.current &&= (clearTimeout(ue.current), null), B.current = !1, Be.current = "idle", c && typeof window < "u" && (window.history.pushState = c), p && typeof window < "u" && window.removeEventListener("popstate", p);
14207
+ let t = o || R.current, n = Fe.current, d = Ie.current;
14208
14208
  if (t?.endSession?.().catch(() => {}), n && s && a) {
14209
14209
  let e = d ? Math.round((Date.now() - d) / 1e3) : 0, t = JSON.stringify({
14210
14210
  chatId: s,
@@ -14217,7 +14217,7 @@ function ev({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
14217
14217
  headers: { "Content-Type": "application/json" },
14218
14218
  body: t,
14219
14219
  keepalive: !0
14220
- }).catch(() => {}), Pe.current = null, Fe.current = null;
14220
+ }).catch(() => {}), Fe.current = null, Ie.current = null;
14221
14221
  }
14222
14222
  typeof u == "function" && l.current.length > 0 && u(l.current).catch?.(() => {});
14223
14223
  };
@@ -14225,26 +14225,26 @@ function ev({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
14225
14225
  r,
14226
14226
  i,
14227
14227
  a,
14228
- He
14228
+ Ue
14229
14229
  ]), c(() => {
14230
14230
  if (!ee) return;
14231
14231
  let e = (e) => {
14232
14232
  let t = e.composedPath?.()?.[0] || e.target;
14233
- B.current && !B.current.contains(t) && te(!1);
14233
+ z.current && !z.current.contains(t) && te(!1);
14234
14234
  };
14235
14235
  return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
14236
14236
  }, [ee]);
14237
14237
  let Xe = async () => {
14238
- if (z.current) try {
14238
+ if (R.current) try {
14239
14239
  if (k) {
14240
- Le.current = 0, await z.current.setMicMuted?.(!1), A(!1);
14240
+ Re.current = 0, await R.current.setMicMuted?.(!1), A(!1);
14241
14241
  try {
14242
- z.current.sendContextualUpdate?.("[MIC] The visitor unmuted their microphone.");
14242
+ R.current.sendContextualUpdate?.("[MIC] The visitor unmuted their microphone.");
14243
14243
  } catch {}
14244
14244
  } else {
14245
- Le.current = 0, await z.current.setMicMuted?.(!0), A(!0);
14245
+ Re.current = 0, await R.current.setMicMuted?.(!0), A(!0);
14246
14246
  try {
14247
- z.current.sendContextualUpdate?.("[MIC] The visitor muted their microphone.");
14247
+ R.current.sendContextualUpdate?.("[MIC] The visitor muted their microphone.");
14248
14248
  } catch {}
14249
14249
  }
14250
14250
  } catch {}
@@ -14255,23 +14255,23 @@ function ev({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
14255
14255
  oe("Please enter a valid email address.");
14256
14256
  return;
14257
14257
  }
14258
- oe(""), F.current = !0, I.current = !1, H(), N(!1), P(""), fe.current = !1;
14258
+ oe(""), se.current = !0, F.current = !1, V(), N(!1), P(""), pe.current = !1;
14259
14259
  try {
14260
14260
  typeof b == "function" && await b(t);
14261
14261
  } catch {}
14262
- z.current?.setMicMuted?.(!1);
14263
- let n = de.current;
14264
- de.current = "";
14262
+ R.current?.setMicMuted?.(!1);
14263
+ let n = fe.current;
14264
+ fe.current = "";
14265
14265
  try {
14266
- z.current?.injectAgentSpeech?.("Thank you for submitting your email."), z.current?.sendUserMessage?.(n || "The visitor's email is on file. Carry on helping them and never ask for it again.");
14266
+ R.current?.injectAgentSpeech?.("Thank you for submitting your email."), R.current?.sendUserMessage?.(n || "The visitor's email is on file. Carry on helping them and never ask for it again.");
14267
14267
  } catch {}
14268
14268
  }, [
14269
14269
  ie,
14270
14270
  b,
14271
- H
14271
+ V
14272
14272
  ]), W = Array.isArray(e) && e[0] || "#3B82F6";
14273
14273
  return /* @__PURE__ */ _("div", {
14274
- ref: B,
14274
+ ref: z,
14275
14275
  style: {
14276
14276
  position: "relative",
14277
14277
  display: "flex",
@@ -14509,7 +14509,7 @@ function ev({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
14509
14509
  children: [
14510
14510
  /* @__PURE__ */ _("button", {
14511
14511
  onClick: () => {
14512
- te(!1), Me.current = "chat", Ye(t);
14512
+ te(!1), Ne.current = "chat", Ye(t);
14513
14513
  },
14514
14514
  style: {
14515
14515
  display: "flex",
@@ -14613,7 +14613,7 @@ function ev({ orbColors: e, onEnterChat: t, onEndChat: n, agentId: r, siteId: i,
14613
14613
  }),
14614
14614
  /* @__PURE__ */ _("button", {
14615
14615
  onClick: () => {
14616
- te(!1), Me.current = "minimized", Ye(n);
14616
+ te(!1), Ne.current = "minimized", Ye(n);
14617
14617
  },
14618
14618
  style: {
14619
14619
  display: "flex",
@@ -14739,57 +14739,57 @@ var nv = () => /* @__PURE__ */ g("div", {
14739
14739
  } }, e))
14740
14740
  })
14741
14741
  });
14742
- function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i, quickChatOptions: a, onQuickChatSelect: o, isMobile: s, chatHistory: l, isAiTyping: u, isAgentTyping: d, activeScreen: f, agentName: v, agentHeadshot: y, fallbackAgentName: b, input: x, setInput: S, onSubmit: C, isConversationEnded: w, isLoading: T, isRateLimited: E, rateLimitMessage: D, selectedFile: O, onFileSelect: k, onRemoveSelectedFile: A, attachmentError: ee, isUploadingAttachment: te, requiresEmail: ne, emailInput: j, setEmailInput: M, emailError: re, emailCaptureSuccess: N, replyContext: ie, setReplyContext: P, webRTCError: ae, micError: oe, setMicError: F, dismissCallError: I, activeCallId: le, isCallMuted: ue, toggleCallMute: de, endWebRTCCall: fe, formatCallDuration: pe, callDurationSeconds: me, isCallMinimized: he, onExpand: ge, onCollapse: _e, onStartVoice: ve, voiceEnabled: ye, headerBgColor: be, onNewChat: L, showPoweredBy: R, privacyPolicyUrl: z, getVisitorChatHistory: xe, resumeChat: Se, isSessionRestoring: Ce, isClosing: we }) {
14743
- let Te = l.length > 0, Ee = T || E || w, De = !!le, [Oe, ke] = m(!1), { resolvedConfig: Ae } = On(), je = Ae?.siteId || null, [Me, Ne] = m(() => se(je) === "auto"), Pe = () => {
14744
- let e = Me ? "ask" : "auto";
14745
- ce(je, e), Ne(e === "auto");
14746
- }, [Fe, Ie] = m(!1), [B, Le] = m([]), [Re, ze] = m(!1), Be = p(null), [V, Ve] = m(() => typeof window < "u" ? window.visualViewport?.height ?? window.innerHeight : 600), [He, H] = m(0);
14742
+ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i, quickChatOptions: a, onQuickChatSelect: o, isMobile: s, chatHistory: l, isAiTyping: u, isAgentTyping: d, activeScreen: f, agentName: v, agentHeadshot: y, fallbackAgentName: b, input: x, setInput: S, onSubmit: C, isConversationEnded: w, isLoading: T, isRateLimited: E, rateLimitMessage: D, selectedFile: O, onFileSelect: k, onRemoveSelectedFile: A, attachmentError: ee, isUploadingAttachment: te, requiresEmail: ne, emailInput: j, setEmailInput: M, emailError: re, emailCaptureSuccess: N, replyContext: ie, setReplyContext: P, webRTCError: ae, micError: oe, setMicError: se, dismissCallError: F, activeCallId: ue, isCallMuted: de, toggleCallMute: fe, endWebRTCCall: pe, formatCallDuration: me, callDurationSeconds: he, isCallMinimized: ge, onExpand: _e, onCollapse: ve, onStartVoice: ye, voiceEnabled: be, headerBgColor: xe, onNewChat: I, showPoweredBy: L, privacyPolicyUrl: R, getVisitorChatHistory: Se, resumeChat: Ce, isSessionRestoring: we, isClosing: Te }) {
14743
+ let Ee = l.length > 0, De = T || E || w, Oe = !!ue, [ke, Ae] = m(!1), { resolvedConfig: je } = On(), Me = je?.siteId || null, [Ne, Pe] = m(() => ce(Me) === "auto"), Fe = () => {
14744
+ let e = Ne ? "ask" : "auto";
14745
+ le(Me, e), Pe(e === "auto");
14746
+ }, [Ie, Le] = m(!1), [z, Re] = m([]), [ze, Be] = m(!1), Ve = p(null), [B, He] = m(() => typeof window < "u" ? window.visualViewport?.height ?? window.innerHeight : 600), [Ue, V] = m(0);
14747
14747
  c(() => {
14748
14748
  if (!s) return;
14749
14749
  let e = window.visualViewport;
14750
14750
  if (!e) return;
14751
14751
  let t = () => {
14752
- Ve(e.height), H(Math.max(0, window.innerHeight - e.offsetTop - e.height));
14752
+ He(e.height), V(Math.max(0, window.innerHeight - e.offsetTop - e.height));
14753
14753
  };
14754
14754
  return e.addEventListener("resize", t), e.addEventListener("scroll", t), t(), () => {
14755
14755
  e.removeEventListener("resize", t), e.removeEventListener("scroll", t);
14756
14756
  };
14757
14757
  }, [s]);
14758
- let Ue = s && window.innerHeight - V > 150, We = async () => {
14759
- ke(!1), Ie(!0), ze(!0);
14758
+ let We = s && window.innerHeight - B > 150, Ge = async () => {
14759
+ Ae(!1), Le(!0), Be(!0);
14760
14760
  try {
14761
- let e = await xe();
14762
- e?.data && Le(e.data);
14761
+ let e = await Se();
14762
+ e?.data && Re(e.data);
14763
14763
  } catch (e) {
14764
14764
  console.error(e);
14765
14765
  } finally {
14766
- ze(!1);
14766
+ Be(!1);
14767
14767
  }
14768
- }, Ge = async (e) => {
14769
- Ie(!1), Se?.(e.chatId);
14768
+ }, Ke = async (e) => {
14769
+ Le(!1), Ce?.(e.chatId);
14770
14770
  };
14771
14771
  return c(() => {
14772
- if (!Oe) return;
14772
+ if (!ke) return;
14773
14773
  let e = (e) => {
14774
14774
  let t = e.composedPath?.()?.[0] || e.target;
14775
- Be.current && !Be.current.contains(t) && ke(!1);
14775
+ Ve.current && !Ve.current.contains(t) && Ae(!1);
14776
14776
  };
14777
14777
  return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
14778
- }, [Oe]), /* @__PURE__ */ _("div", {
14778
+ }, [ke]), /* @__PURE__ */ _("div", {
14779
14779
  style: s ? {
14780
14780
  "--flowengage-primary": n,
14781
14781
  "--flowengage-accent": n,
14782
14782
  position: "fixed",
14783
14783
  left: "0",
14784
14784
  right: "0",
14785
- bottom: `${He}px`,
14786
- height: V > 0 ? `${Math.round(V * (Ue ? 1 : .92))}px` : "90dvh",
14785
+ bottom: `${Ue}px`,
14786
+ height: B > 0 ? `${Math.round(B * (We ? 1 : .92))}px` : "90dvh",
14787
14787
  background: r,
14788
14788
  borderRadius: "16px 16px 0 0",
14789
14789
  display: "flex",
14790
14790
  flexDirection: "column",
14791
14791
  overflow: "hidden",
14792
- animation: we ? "fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards" : "fe-orb-slide-up 0.28s cubic-bezier(0.16,1,0.3,1)"
14792
+ animation: Te ? "fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards" : "fe-orb-slide-up 0.28s cubic-bezier(0.16,1,0.3,1)"
14793
14793
  } : {
14794
14794
  "--flowengage-primary": n,
14795
14795
  "--flowengage-accent": n,
@@ -14802,7 +14802,7 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
14802
14802
  flexDirection: "column",
14803
14803
  overflow: "hidden",
14804
14804
  position: "relative",
14805
- animation: we ? "fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards" : "fe-orb-slide-up 0.36s cubic-bezier(0.16,1,0.3,1)"
14805
+ animation: Te ? "fe-orb-slide-down 0.28s cubic-bezier(0.16,1,0.3,1) forwards" : "fe-orb-slide-up 0.36s cubic-bezier(0.16,1,0.3,1)"
14806
14806
  },
14807
14807
  children: [
14808
14808
  /* @__PURE__ */ _("div", {
@@ -14812,7 +14812,7 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
14812
14812
  alignItems: "center",
14813
14813
  columnGap: "14px",
14814
14814
  padding: "16px 10px 14px",
14815
- background: be || "transparent",
14815
+ background: xe || "transparent",
14816
14816
  flexShrink: 0,
14817
14817
  position: "relative",
14818
14818
  zIndex: 30
@@ -14825,7 +14825,7 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
14825
14825
  alignItems: "center"
14826
14826
  },
14827
14827
  children: /* @__PURE__ */ g("button", {
14828
- onClick: _e,
14828
+ onClick: ve,
14829
14829
  style: {
14830
14830
  width: "40px",
14831
14831
  height: "40px",
@@ -14927,10 +14927,10 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
14927
14927
  isolation: "isolate",
14928
14928
  zIndex: 10
14929
14929
  },
14930
- ref: Be,
14930
+ ref: Ve,
14931
14931
  children: [/* @__PURE__ */ g("button", {
14932
14932
  type: "button",
14933
- onClick: () => ke((e) => !e),
14933
+ onClick: () => Ae((e) => !e),
14934
14934
  style: {
14935
14935
  width: "40px",
14936
14936
  height: "40px",
@@ -14976,7 +14976,7 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
14976
14976
  })
14977
14977
  ]
14978
14978
  })
14979
- }), Oe && /* @__PURE__ */ _("div", {
14979
+ }), ke && /* @__PURE__ */ _("div", {
14980
14980
  style: {
14981
14981
  position: "absolute",
14982
14982
  top: "34px",
@@ -14992,10 +14992,10 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
14992
14992
  animation: "fe-orb-fade-in 0.18s ease"
14993
14993
  },
14994
14994
  children: [
14995
- ye && /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ _("button", {
14995
+ be && /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ _("button", {
14996
14996
  type: "button",
14997
14997
  onClick: () => {
14998
- ke(!1), ve?.();
14998
+ Ae(!1), ye?.();
14999
14999
  },
15000
15000
  style: {
15001
15001
  display: "flex",
@@ -15037,7 +15037,7 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
15037
15037
  /* @__PURE__ */ _("button", {
15038
15038
  type: "button",
15039
15039
  onClick: () => {
15040
- ke(!1), L?.();
15040
+ Ae(!1), I?.();
15041
15041
  },
15042
15042
  style: {
15043
15043
  display: "flex",
@@ -15072,13 +15072,13 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
15072
15072
  children: [/* @__PURE__ */ g("path", { d: "M12 5H5a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-7" }), /* @__PURE__ */ g("path", { d: "M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z" })]
15073
15073
  }), "Start new chat"]
15074
15074
  }),
15075
- xe && /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ g("div", { style: {
15075
+ Se && /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ g("div", { style: {
15076
15076
  height: "1px",
15077
15077
  background: "rgba(255,255,255,0.07)",
15078
15078
  margin: "0 14px"
15079
15079
  } }), /* @__PURE__ */ _("button", {
15080
15080
  type: "button",
15081
- onClick: We,
15081
+ onClick: Ge,
15082
15082
  style: {
15083
15083
  display: "flex",
15084
15084
  alignItems: "center",
@@ -15112,14 +15112,14 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
15112
15112
  children: /* @__PURE__ */ g("path", { d: "M12 8v4l3 3M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0z" })
15113
15113
  }), "Chat history"]
15114
15114
  })] }),
15115
- je && /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ g("div", { style: {
15115
+ Me && /* @__PURE__ */ _(h, { children: [/* @__PURE__ */ g("div", { style: {
15116
15116
  height: "1px",
15117
15117
  background: "rgba(255,255,255,0.07)",
15118
15118
  margin: "0 14px"
15119
15119
  } }), /* @__PURE__ */ _("button", {
15120
15120
  type: "button",
15121
15121
  onClick: () => {
15122
- Pe(), ke(!1);
15122
+ Fe(), Ae(!1);
15123
15123
  },
15124
15124
  style: {
15125
15125
  display: "flex",
@@ -15176,7 +15176,7 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
15176
15176
  width: "34px",
15177
15177
  height: "19px",
15178
15178
  borderRadius: "999px",
15179
- background: Me ? "#22c55e" : "rgba(255,255,255,0.2)",
15179
+ background: Ne ? "#22c55e" : "rgba(255,255,255,0.2)",
15180
15180
  position: "relative",
15181
15181
  flexShrink: 0,
15182
15182
  transition: "background 0.15s ease"
@@ -15184,7 +15184,7 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
15184
15184
  children: /* @__PURE__ */ g("span", { style: {
15185
15185
  position: "absolute",
15186
15186
  top: "2px",
15187
- left: Me ? "17px" : "2px",
15187
+ left: Ne ? "17px" : "2px",
15188
15188
  width: "15px",
15189
15189
  height: "15px",
15190
15190
  borderRadius: "50%",
@@ -15201,7 +15201,7 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
15201
15201
  /* @__PURE__ */ _("button", {
15202
15202
  type: "button",
15203
15203
  onClick: () => {
15204
- ke(!1), _e?.();
15204
+ Ae(!1), ve?.();
15205
15205
  },
15206
15206
  style: {
15207
15207
  display: "flex",
@@ -15262,21 +15262,21 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
15262
15262
  /* @__PURE__ */ g($g, {
15263
15263
  webRTCError: ae,
15264
15264
  micError: oe,
15265
- setMicError: F,
15266
- dismissCallError: I,
15265
+ setMicError: se,
15266
+ dismissCallError: F,
15267
15267
  isRateLimited: E,
15268
15268
  rateLimitMessage: D
15269
15269
  }),
15270
- he && /* @__PURE__ */ g(g_, {
15270
+ ge && /* @__PURE__ */ g(g_, {
15271
15271
  agentName: v,
15272
15272
  agentHeadshot: y,
15273
15273
  fallbackAgentName: b,
15274
- callDurationSeconds: me,
15275
- isCallMuted: ue,
15276
- formatCallDuration: pe,
15277
- toggleCallMute: de,
15278
- endWebRTCCall: fe,
15279
- onExpand: ge,
15274
+ callDurationSeconds: he,
15275
+ isCallMuted: de,
15276
+ formatCallDuration: me,
15277
+ toggleCallMute: fe,
15278
+ endWebRTCCall: pe,
15279
+ onExpand: _e,
15280
15280
  primaryColor: n
15281
15281
  }),
15282
15282
  /* @__PURE__ */ _("div", {
@@ -15288,7 +15288,7 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
15288
15288
  background: "transparent",
15289
15289
  position: "relative"
15290
15290
  },
15291
- children: [Fe ? /* @__PURE__ */ _("div", {
15291
+ children: [Ie ? /* @__PURE__ */ _("div", {
15292
15292
  style: {
15293
15293
  position: "absolute",
15294
15294
  inset: 0,
@@ -15307,7 +15307,7 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
15307
15307
  flexShrink: 0
15308
15308
  },
15309
15309
  children: /* @__PURE__ */ _("button", {
15310
- onClick: () => Ie(!1),
15310
+ onClick: () => Le(!1),
15311
15311
  style: {
15312
15312
  background: "none",
15313
15313
  border: "none",
@@ -15341,7 +15341,7 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
15341
15341
  overflowY: "auto",
15342
15342
  position: "relative"
15343
15343
  },
15344
- children: Re ? /* @__PURE__ */ g("div", {
15344
+ children: ze ? /* @__PURE__ */ g("div", {
15345
15345
  style: {
15346
15346
  padding: "40px 20px",
15347
15347
  textAlign: "center",
@@ -15349,8 +15349,8 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
15349
15349
  fontSize: "14px"
15350
15350
  },
15351
15351
  children: "Loading past conversations..."
15352
- }) : B.length > 0 ? /* @__PURE__ */ g("div", { children: B.map((e) => /* @__PURE__ */ _("div", {
15353
- onClick: () => Ge(e),
15352
+ }) : z.length > 0 ? /* @__PURE__ */ g("div", { children: z.map((e) => /* @__PURE__ */ _("div", {
15353
+ onClick: () => Ke(e),
15354
15354
  style: {
15355
15355
  padding: "16px 20px",
15356
15356
  borderBottom: "1px solid #f3f4f6",
@@ -15401,7 +15401,7 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
15401
15401
  children: "No previous chats found."
15402
15402
  })
15403
15403
  })]
15404
- }) : null, Te ? /* @__PURE__ */ g(Xg, {
15404
+ }) : null, Ee ? /* @__PURE__ */ g(Xg, {
15405
15405
  chatHistory: l,
15406
15406
  isAiTyping: u,
15407
15407
  isLoading: T,
@@ -15412,7 +15412,7 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
15412
15412
  agentHeadshot: y,
15413
15413
  agentDisplayName: v || b,
15414
15414
  botAvatarNode: /* @__PURE__ */ g(tv, { orbColors: t })
15415
- }) : Ce ? /* @__PURE__ */ _("div", {
15415
+ }) : we ? /* @__PURE__ */ _("div", {
15416
15416
  style: {
15417
15417
  flex: 1,
15418
15418
  display: "flex",
@@ -15548,11 +15548,11 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
15548
15548
  setInput: S,
15549
15549
  onSubmit: C,
15550
15550
  isConversationEnded: w,
15551
- callUiActive: De,
15552
- handleToggleVoice: ve,
15551
+ callUiActive: Oe,
15552
+ handleToggleVoice: ye,
15553
15553
  showVoiceToggle: f === "agent",
15554
15554
  activeScreen: f,
15555
- inputDisabled: Ee,
15555
+ inputDisabled: De,
15556
15556
  replyContext: ie,
15557
15557
  clearReplyContext: () => P(null),
15558
15558
  onFileSelect: k,
@@ -15567,7 +15567,7 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
15567
15567
  inputPlaceholder: e.inputPlaceholder
15568
15568
  })
15569
15569
  }),
15570
- !Ue && /* @__PURE__ */ _("div", {
15570
+ !We && /* @__PURE__ */ _("div", {
15571
15571
  style: {
15572
15572
  flexShrink: 0,
15573
15573
  textAlign: "center",
@@ -15575,7 +15575,7 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
15575
15575
  paddingBottom: "max(12px, env(safe-area-inset-bottom, 12px))",
15576
15576
  pointerEvents: "none"
15577
15577
  },
15578
- children: [z && /* @__PURE__ */ _("p", {
15578
+ children: [R && /* @__PURE__ */ _("p", {
15579
15579
  style: {
15580
15580
  margin: "0 0 4px",
15581
15581
  fontSize: "10px",
@@ -15588,7 +15588,7 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
15588
15588
  "This conversation is recorded for quality assurance purposes.",
15589
15589
  " ",
15590
15590
  /* @__PURE__ */ g("a", {
15591
- href: z,
15591
+ href: R,
15592
15592
  target: "_blank",
15593
15593
  rel: "noopener noreferrer",
15594
15594
  style: {
@@ -15598,7 +15598,7 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
15598
15598
  children: "See our privacy policy"
15599
15599
  })
15600
15600
  ]
15601
- }), R && /* @__PURE__ */ _("span", {
15601
+ }), L && /* @__PURE__ */ _("span", {
15602
15602
  style: {
15603
15603
  fontSize: "11px",
15604
15604
  color: "#9ca3af",
@@ -15618,62 +15618,62 @@ function rv({ copy: e, orbColors: t, primaryColor: n, chatBgGradient: r, logo: i
15618
15618
  });
15619
15619
  }
15620
15620
  function iv() {
15621
- let { status: e, runtimeConfig: t, resolvedConfig: n, chatHistory: r, isOpen: i, activeScreen: a, isHumanHandled: s, agentName: l, agentHeadshot: u, visitorEmail: h, isAgentTyping: v, isAiTyping: y, isLoading: b, isRateLimited: x, rateLimitMessage: S, isConversationEnded: C, incomingCall: w, activeCallId: T, callConnectionState: E, callConnectedAt: D, isCallMuted: O, webRTCError: k, language: A, chatId: ee, historyRef: te, onMessageSync: ne, beaconSyncVoiceTranscript: j, sendMessage: M, uploadChatFile: re, openWidget: N, captureVisitorEmail: ie, setVoiceMode: P, endConversation: F, startNewChat: I, acceptCall: se, rejectCall: ce, endWebRTCCall: le, toggleCallMute: ue, dismissCallError: de, startTyping: fe, stopTyping: pe, updateTypingDraft: me, getVisitorChatHistory: he, resumeChat: ge, isSessionRestoring: _e, openToChatCounter: ve, voiceEndCounter: ye } = On();
15621
+ let { status: e, runtimeConfig: t, resolvedConfig: n, chatHistory: r, isOpen: i, activeScreen: a, isHumanHandled: s, agentName: l, agentHeadshot: u, visitorEmail: h, isAgentTyping: v, isAiTyping: y, isLoading: b, isRateLimited: x, rateLimitMessage: S, isConversationEnded: C, incomingCall: w, activeCallId: T, callConnectionState: E, callConnectedAt: D, isCallMuted: O, webRTCError: k, language: A, chatId: ee, historyRef: te, onMessageSync: ne, beaconSyncVoiceTranscript: j, sendMessage: M, uploadChatFile: re, openWidget: N, captureVisitorEmail: ie, setVoiceMode: P, endConversation: se, startNewChat: F, acceptCall: ce, rejectCall: le, endWebRTCCall: ue, toggleCallMute: de, dismissCallError: fe, startTyping: pe, stopTyping: me, updateTypingDraft: he, getVisitorChatHistory: ge, resumeChat: _e, isSessionRestoring: ve, openToChatCounter: ye, voiceEndCounter: be } = On();
15622
15622
  c(() => {
15623
15623
  try {
15624
15624
  dr();
15625
15625
  } catch {}
15626
15626
  }, []), c(() => {
15627
- ve && G !== "voice_mode" && G !== "text_chat" && G !== "call_screen" && (P?.(!1), $e("text_chat"));
15628
- }, [ve]);
15629
- let be = t?.widgetSettings || {}, L = n?.widgetSettings || {}, R = {
15630
- ...be.branding || {},
15631
- ...L.branding || {}
15632
- }, z = {
15633
- ...be.theme || {},
15634
- ...L.theme || {}
15635
- }, xe = {
15636
- ...be.features || {},
15637
- ...L.features || {}
15638
- }, Se = xe.voice !== !1, Ce = Array.isArray(z.orbColors) && z.orbColors.length > 0 ? z.orbColors : null, we = z.buttonColor || z.primaryColor || Ce?.[0] || "#3B82F6", De = {
15627
+ ye && G !== "voice_mode" && G !== "text_chat" && G !== "call_screen" && (P?.(!1), $e("text_chat"));
15628
+ }, [ye]);
15629
+ let xe = t?.widgetSettings || {}, I = n?.widgetSettings || {}, L = {
15630
+ ...xe.branding || {},
15631
+ ...I.branding || {}
15632
+ }, R = {
15633
+ ...xe.theme || {},
15634
+ ...I.theme || {}
15635
+ }, Se = {
15636
+ ...xe.features || {},
15637
+ ...I.features || {}
15638
+ }, Ce = Se.voice !== !1, we = Array.isArray(R.orbColors) && R.orbColors.length > 0 ? R.orbColors : null, Te = R.buttonColor || R.primaryColor || we?.[0] || "#3B82F6", Oe = {
15639
15639
  small: 50,
15640
15640
  medium: 64,
15641
15641
  large: 80
15642
- }, Oe = De[z.orbSize] || De.small, Ae = z.position || "bottom-right", je = R.fallbackAgentName || "Agent", Ne = G_(Ce ?? z.chatBgColors), Pe = R.logo || R.logoUrl || null, Fe = A || "en", Ie = be.recommendations?.[Fe] || [], B = (L.recommendations?.[Fe] ?? Ie).filter((e) => String(e?.label ?? "").trim()).map((e, t) => ({
15642
+ }, ke = Oe[R.orbSize] || Oe.small, je = R.position || "bottom-right", Me = L.fallbackAgentName || "Agent", Pe = G_(we ?? R.chatBgColors), Fe = L.logo || L.logoUrl || null, Ie = A || "en", Le = xe.recommendations?.[Ie] || [], z = (I.recommendations?.[Ie] ?? Le).filter((e) => String(e?.label ?? "").trim()).map((e, t) => ({
15643
15643
  id: e.key || `qr-${t}`,
15644
15644
  label: e.label,
15645
15645
  message: e.label,
15646
15646
  text: e.label
15647
- })), Le = Array.isArray(R.quickChatOptions) && R.quickChatOptions.length > 0 ? R.quickChatOptions : B, Re = R.hideWatermark === !0 ? !1 : R.showPoweredBy !== !1, ze = R.headerBgColor || null, Be = z.bottomPosition == null ? "1.5rem" : `${z.bottomPosition}px`, V = R.privacyPolicyUrl || null, Ve = R.chatbotEnabled !== !1 && z.chatbotEnabled !== !1, [He, H] = m(() => typeof window < "u" ? window.location.pathname : "/");
15647
+ })), Re = Array.isArray(L.quickChatOptions) && L.quickChatOptions.length > 0 ? L.quickChatOptions : z, ze = L.hideWatermark === !0 ? !1 : L.showPoweredBy !== !1, Be = L.headerBgColor || null, Ve = R.bottomPosition == null ? "1.5rem" : `${R.bottomPosition}px`, B = L.privacyPolicyUrl || null, He = L.chatbotEnabled !== !1 && R.chatbotEnabled !== !1, [Ue, V] = m(() => typeof window < "u" ? window.location.pathname : "/");
15648
15648
  c(() => {
15649
15649
  if (typeof window > "u") return;
15650
- let e = () => H(window.location.pathname), t = window.history.pushState.bind(window.history);
15650
+ let e = () => V(window.location.pathname), t = window.history.pushState.bind(window.history);
15651
15651
  return window.history.pushState = (...n) => {
15652
15652
  t(...n), setTimeout(e, 50);
15653
15653
  }, window.addEventListener("popstate", e), () => {
15654
15654
  window.history.pushState = t, window.removeEventListener("popstate", e);
15655
15655
  };
15656
15656
  }, []);
15657
- let Ue = (() => {
15657
+ let We = (() => {
15658
15658
  let e = {
15659
- ...be.pageVisibility || {},
15660
- ...L.pageVisibility || {}
15659
+ ...xe.pageVisibility || {},
15660
+ ...I.pageVisibility || {}
15661
15661
  };
15662
15662
  return Array.isArray(e.allowedPaths) ? e.allowedPaths.filter(Boolean) : [];
15663
- })(), We = Ue.length === 0 || Ue.some((e) => e === "*" || e === "/*" ? !0 : e.endsWith("/*") ? He.startsWith(e.slice(0, -1)) : He.replace(/\/$/, "") === e.replace(/\/$/, "")), Ge = be.greetings?.[A] || L.greetings?.[A] || R.introGreeting || (t?.websiteName && String(t.websiteName).trim() ? `Hello, I'm here to help you know more about ${String(t.websiteName).trim()}.` : "Hello, I'm here to help — what would you like to know?"), Ke = {
15664
- entryPrompt: R.entryPrompt || "Do you want to explore in a new way?",
15665
- yesLabel: R.yesLabel || "Yes",
15666
- laterLabel: R.laterLabel || "Later",
15667
- connectionTitle: R.connectionTitle || "How would you like to connect?",
15668
- connectionSubtitle: R.connectionSubtitle || "",
15669
- voiceLabel: R.voiceLabel || "Voice",
15670
- textLabel: R.textLabel || "Text",
15671
- chatTitle: R.headerName || "Chat with FlowEngage",
15672
- hasCustomTitle: !!(R.headerName && String(R.headerName).trim()),
15673
- introGreeting: Ge,
15674
- inputPlaceholder: R.inputPlaceholder || "Type your message",
15675
- analysingLabel: R.analysingLabel || "analysing..."
15676
- }, qe = L.elevenLabsAgentId || t?.elevenLabsAgentId || null, Je = t?.siteId || n?.siteId || null, Ye = t?.apiBaseUrl || "";
15663
+ })(), Ge = We.length === 0 || We.some((e) => e === "*" || e === "/*" ? !0 : e.endsWith("/*") ? Ue.startsWith(e.slice(0, -1)) : Ue.replace(/\/$/, "") === e.replace(/\/$/, "")), Ke = xe.greetings?.[A] || I.greetings?.[A] || L.introGreeting || (t?.websiteName && String(t.websiteName).trim() ? `Hello, I'm here to help you know more about ${String(t.websiteName).trim()}.` : "Hello, I'm here to help — what would you like to know?"), qe = {
15664
+ entryPrompt: L.entryPrompt || "Do you want to explore in a new way?",
15665
+ yesLabel: L.yesLabel || "Yes",
15666
+ laterLabel: L.laterLabel || "Later",
15667
+ connectionTitle: L.connectionTitle || "How would you like to connect?",
15668
+ connectionSubtitle: L.connectionSubtitle || "",
15669
+ voiceLabel: L.voiceLabel || "Voice",
15670
+ textLabel: L.textLabel || "Text",
15671
+ chatTitle: L.headerName || "Chat with FlowEngage",
15672
+ hasCustomTitle: !!(L.headerName && String(L.headerName).trim()),
15673
+ introGreeting: Ke,
15674
+ inputPlaceholder: L.inputPlaceholder || "Type your message",
15675
+ analysingLabel: L.analysingLabel || "analysing..."
15676
+ }, Je = I.elevenLabsAgentId || t?.elevenLabsAgentId || null, H = t?.siteId || n?.siteId || null, Ye = t?.apiBaseUrl || "";
15677
15677
  c(() => {
15678
15678
  Zn(t?.siteType || null);
15679
15679
  }, [t?.siteType]);
@@ -15684,10 +15684,10 @@ function iv() {
15684
15684
  ]), U = u && String(u).trim() || t?.ownerProfileImageUrl && String(t.ownerProfileImageUrl).trim() || null, W = r.some((e) => e.sender === "user"), Ze = f(() => {
15685
15685
  let e = r.findIndex((e) => e.sender === "user");
15686
15686
  return e === -1 ? !1 : r.slice(e + 1).some((e) => e.sender === "bot" || e.sender === "ai" || e.sender === "agent");
15687
- }, [r]), Qe = !!(L._dashboardLivePreview || be._dashboardLivePreview), [G, $e] = m(() => Qe ? "text_chat" : "entry_prompt"), [et, tt] = m(""), [nt, rt] = m(null), [it, at] = m(h || ""), [ot, st] = m(""), [K, ct] = m(!1), [lt, ut] = m(0), [dt, ft] = m(null), [pt, mt] = m(null), [ht, gt] = m(""), [_t, vt] = m(!1), [yt, bt] = m(!1), [xt, St] = m(!1), Ct = p(null), wt = p(!1), Tt = !h && W && Ze && G !== "voice_mode";
15687
+ }, [r]), Qe = !!(I._dashboardLivePreview || xe._dashboardLivePreview), [G, $e] = m(() => Qe ? "text_chat" : "entry_prompt"), [et, tt] = m(""), [nt, rt] = m(null), [it, at] = m(h || ""), [ot, st] = m(""), [K, ct] = m(!1), [lt, ut] = m(0), [dt, ft] = m(null), [pt, mt] = m(null), [ht, gt] = m(""), [_t, vt] = m(!1), [yt, bt] = m(!1), [xt, St] = m(!1), Ct = p(null), wt = p(!1), Tt = !h && W && Ze && G !== "voice_mode";
15688
15688
  d(() => {
15689
15689
  if (e !== "ready" || wt.current) return;
15690
- if (wt.current = !0, !Se) {
15690
+ if (wt.current = !0, !Ce) {
15691
15691
  $e("minimized_orb");
15692
15692
  return;
15693
15693
  }
@@ -15695,12 +15695,12 @@ function iv() {
15695
15695
  try {
15696
15696
  t = Cr().shouldResumeVoice;
15697
15697
  } catch {}
15698
- let n = ke(), r = Je ? Te(Je) : null, i = n || !!r?.transcript;
15698
+ let n = Ae(), r = H ? Ee(H) : null, i = n || !!r?.transcript;
15699
15699
  if (t) {
15700
15700
  N?.({ notifyChatInitiated: !0 }), P?.(!0), $e("voice_mode");
15701
15701
  return;
15702
15702
  }
15703
- if (Me()) {
15703
+ if (Ne()) {
15704
15704
  N?.({ notifyChatInitiated: !1 }), $e("text_chat");
15705
15705
  return;
15706
15706
  }
@@ -15712,10 +15712,10 @@ function iv() {
15712
15712
  N?.({ notifyChatInitiated: !0 }), P?.(!0), $e("voice_mode");
15713
15713
  return;
15714
15714
  }
15715
- if (Je) try {
15716
- Ee(Je);
15715
+ if (H) try {
15716
+ De(H);
15717
15717
  } catch {}
15718
- if (ae(Je)) {
15718
+ if (ae(H)) {
15719
15719
  $e("minimized_orb");
15720
15720
  return;
15721
15721
  }
@@ -15794,16 +15794,16 @@ function iv() {
15794
15794
  !T && yt && bt(!1);
15795
15795
  }, [T, yt]), c(() => {
15796
15796
  if (!s || C) {
15797
- me?.(""), pe?.();
15797
+ he?.(""), me?.();
15798
15798
  return;
15799
15799
  }
15800
15800
  if (!et.trim() || pt) {
15801
- me?.("");
15802
- let e = window.setTimeout(() => pe?.(), 100);
15801
+ he?.("");
15802
+ let e = window.setTimeout(() => me?.(), 100);
15803
15803
  return () => window.clearTimeout(e);
15804
15804
  }
15805
- fe?.();
15806
- let e = window.setTimeout(() => me?.(et), 120), t = window.setTimeout(() => pe?.(), 1200);
15805
+ pe?.();
15806
+ let e = window.setTimeout(() => he?.(et), 120), t = window.setTimeout(() => me?.(), 1200);
15807
15807
  return () => {
15808
15808
  window.clearTimeout(e), window.clearTimeout(t);
15809
15809
  };
@@ -15812,9 +15812,9 @@ function iv() {
15812
15812
  pt,
15813
15813
  s,
15814
15814
  C,
15815
- fe,
15816
15815
  pe,
15817
- me
15816
+ me,
15817
+ he
15818
15818
  ]);
15819
15819
  let Mt = (e) => e ? {
15820
15820
  replyTo: e.messageId || e.id || null,
@@ -15856,8 +15856,8 @@ function iv() {
15856
15856
  let n = et.trim();
15857
15857
  tt(""), rt(null), await M(n, "", t);
15858
15858
  }, Pt = o(() => {
15859
- r.length !== 0 && I?.();
15860
- }, [r.length, I]), Ft = (e) => {
15859
+ r.length !== 0 && F?.();
15860
+ }, [r.length, F]), Ft = (e) => {
15861
15861
  let t = Math.floor(e / 60);
15862
15862
  return `${String(t).padStart(2, "0")}:${String(e % 60).padStart(2, "0")}`;
15863
15863
  }, It = o(async (e) => {
@@ -15888,19 +15888,19 @@ function iv() {
15888
15888
  height: "min(640px, calc(100vh - 120px))",
15889
15889
  borderRadius: "22px",
15890
15890
  overflow: "hidden",
15891
- ...Ae === "bottom-left" ? {
15891
+ ...je === "bottom-left" ? {
15892
15892
  left: "1.5rem",
15893
- bottom: Be
15893
+ bottom: Ve
15894
15894
  } : {
15895
15895
  right: "1.5rem",
15896
- bottom: Be
15896
+ bottom: Ve
15897
15897
  }
15898
- } : Ae === "bottom-left" ? {
15898
+ } : je === "bottom-left" ? {
15899
15899
  left: "1.5rem",
15900
- bottom: Be
15900
+ bottom: Ve
15901
15901
  } : {
15902
15902
  right: "1.5rem",
15903
- bottom: Be
15903
+ bottom: Ve
15904
15904
  }, Rt = o(() => {
15905
15905
  G !== "minimized_orb" && (St(!0), setTimeout(() => {
15906
15906
  $e("minimized_orb"), St(!1), T && bt(!0);
@@ -15919,7 +15919,7 @@ function iv() {
15919
15919
  }, Ht = () => {
15920
15920
  P?.(!1), Rt();
15921
15921
  };
15922
- return e !== "ready" || !Ve || xe.chat === !1 || !We ? null : /* @__PURE__ */ _("div", {
15922
+ return e !== "ready" || !He || Se.chat === !1 || !Ge ? null : /* @__PURE__ */ _("div", {
15923
15923
  className: "flowengage-widget-root",
15924
15924
  style: {
15925
15925
  position: "fixed",
@@ -15930,14 +15930,14 @@ function iv() {
15930
15930
  onTouchMove: (e) => e.stopPropagation(),
15931
15931
  children: [
15932
15932
  G === "entry_prompt" && /* @__PURE__ */ g(Q_, {
15933
- copy: Ke,
15934
- orbColors: Ce,
15935
- primaryColor: we,
15933
+ copy: qe,
15934
+ orbColors: we,
15935
+ primaryColor: Te,
15936
15936
  onYes: () => {
15937
- oe(Je), Bt();
15937
+ oe(H), Bt();
15938
15938
  },
15939
15939
  onLater: () => {
15940
- oe(Je), Rt();
15940
+ oe(H), Rt();
15941
15941
  },
15942
15942
  isMobile: Et,
15943
15943
  isClosing: xt
@@ -15961,7 +15961,7 @@ function iv() {
15961
15961
  transformOrigin: "bottom right",
15962
15962
  display: "inline-flex",
15963
15963
  flexDirection: "column",
15964
- alignItems: Ae === "bottom-left" ? "flex-start" : "flex-end",
15964
+ alignItems: je === "bottom-left" ? "flex-start" : "flex-end",
15965
15965
  gap: "10px"
15966
15966
  },
15967
15967
  children: [T && /* @__PURE__ */ _("button", {
@@ -16013,15 +16013,15 @@ function iv() {
16013
16013
  })]
16014
16014
  })]
16015
16015
  }), /* @__PURE__ */ g(Z_, {
16016
- size: Oe,
16017
- orbColors: Ce,
16018
- onClick: T ? At : Se ? zt : Vt
16016
+ size: ke,
16017
+ orbColors: we,
16018
+ onClick: T ? At : Ce ? zt : Vt
16019
16019
  })]
16020
16020
  }),
16021
16021
  G === "connection_modal" && /* @__PURE__ */ g($_, {
16022
- copy: Ke,
16023
- orbColors: Ce,
16024
- primaryColor: we,
16022
+ copy: qe,
16023
+ orbColors: we,
16024
+ primaryColor: Te,
16025
16025
  onVoice: Bt,
16026
16026
  onText: Vt,
16027
16027
  onClose: Rt,
@@ -16029,27 +16029,27 @@ function iv() {
16029
16029
  isClosing: xt
16030
16030
  }),
16031
16031
  G === "voice_mode" && /* @__PURE__ */ g(ev, {
16032
- orbColors: Ce,
16032
+ orbColors: we,
16033
16033
  onEnterChat: Vt,
16034
16034
  onEndChat: Ht,
16035
- agentId: qe,
16036
- siteId: Je,
16035
+ agentId: Je,
16036
+ siteId: H,
16037
16037
  apiBaseUrl: Ye,
16038
16038
  chatId: ee,
16039
16039
  historyRef: te,
16040
16040
  onMessageSync: ne,
16041
16041
  beaconSyncVoiceTranscript: j,
16042
- widgetPosition: Ae,
16043
- voiceEndCounter: ye,
16042
+ widgetPosition: je,
16043
+ voiceEndCounter: be,
16044
16044
  websiteName: t?.websiteName,
16045
- voiceFirstMessage: be.voiceFirstMessage || null,
16045
+ voiceFirstMessage: xe.voiceFirstMessage || null,
16046
16046
  captureVisitorEmail: ie,
16047
16047
  emailRequired: !h,
16048
- emailCaptureEnabled: xe.emailCapture !== !1 && R.disableEmailCapture !== !0,
16049
- listeningLabel: R.voiceListeningLabel || "Listening...",
16050
- thinkingLabel: R.voiceThinkingLabel || "Thinking...",
16051
- enterChatModeLabel: R.voiceEnterChatLabel || "Enter Chat Mode",
16052
- endConversationLabel: R.voiceEndConversationLabel || "End Conversation"
16048
+ emailCaptureEnabled: Se.emailCapture !== !1 && L.disableEmailCapture !== !0,
16049
+ listeningLabel: L.voiceListeningLabel || "Listening...",
16050
+ thinkingLabel: L.voiceThinkingLabel || "Thinking...",
16051
+ enterChatModeLabel: L.voiceEnterChatLabel || "Enter Chat Mode",
16052
+ endConversationLabel: L.voiceEndConversationLabel || "End Conversation"
16053
16053
  }, "voice"),
16054
16054
  G === "call_screen" && /* @__PURE__ */ g(h_, {
16055
16055
  incomingCall: w,
@@ -16059,25 +16059,25 @@ function iv() {
16059
16059
  isCallMuted: O,
16060
16060
  agentName: Xe,
16061
16061
  agentHeadshot: U,
16062
- fallbackAgentName: je,
16063
- acceptCall: se,
16064
- rejectCall: ce,
16065
- endWebRTCCall: le,
16066
- toggleCallMute: ue,
16062
+ fallbackAgentName: Me,
16063
+ acceptCall: ce,
16064
+ rejectCall: le,
16065
+ endWebRTCCall: ue,
16066
+ toggleCallMute: de,
16067
16067
  formatCallDuration: Ft,
16068
16068
  onMinimize: jt,
16069
- primaryColor: we,
16070
- orbColors: Ce,
16069
+ primaryColor: Te,
16070
+ orbColors: we,
16071
16071
  chatHistory: r
16072
16072
  }),
16073
16073
  G === "text_chat" && /* @__PURE__ */ g(rv, {
16074
16074
  isClosing: xt,
16075
- copy: Ke,
16076
- orbColors: Ce,
16077
- primaryColor: we,
16078
- chatBgGradient: Ne,
16079
- logo: Pe,
16080
- quickChatOptions: Le,
16075
+ copy: qe,
16076
+ orbColors: we,
16077
+ primaryColor: Te,
16078
+ chatBgGradient: Pe,
16079
+ logo: Fe,
16080
+ quickChatOptions: Re,
16081
16081
  onQuickChatSelect: It,
16082
16082
  isMobile: Et,
16083
16083
  chatHistory: r,
@@ -16086,7 +16086,7 @@ function iv() {
16086
16086
  activeScreen: a,
16087
16087
  agentName: Xe,
16088
16088
  agentHeadshot: U,
16089
- fallbackAgentName: je,
16089
+ fallbackAgentName: Me,
16090
16090
  input: et,
16091
16091
  setInput: tt,
16092
16092
  onSubmit: Nt,
@@ -16109,26 +16109,26 @@ function iv() {
16109
16109
  webRTCError: k,
16110
16110
  micError: dt,
16111
16111
  setMicError: ft,
16112
- dismissCallError: de,
16112
+ dismissCallError: fe,
16113
16113
  activeCallId: T,
16114
16114
  isCallMuted: O,
16115
- toggleCallMute: ue,
16116
- endWebRTCCall: le,
16115
+ toggleCallMute: de,
16116
+ endWebRTCCall: ue,
16117
16117
  formatCallDuration: Ft,
16118
16118
  callDurationSeconds: lt,
16119
16119
  onCollapse: Rt,
16120
16120
  onStartVoice: Bt,
16121
- voiceEnabled: Se,
16121
+ voiceEnabled: Ce,
16122
16122
  onNewChat: Pt,
16123
16123
  onMinimize: jt,
16124
16124
  onExpand: At,
16125
16125
  isCallMinimized: !!T,
16126
- showPoweredBy: Re,
16127
- privacyPolicyUrl: V,
16128
- headerBgColor: ze,
16129
- getVisitorChatHistory: he,
16130
- resumeChat: ge,
16131
- isSessionRestoring: _e
16126
+ showPoweredBy: ze,
16127
+ privacyPolicyUrl: B,
16128
+ headerBgColor: Be,
16129
+ getVisitorChatHistory: ge,
16130
+ resumeChat: _e,
16131
+ isSessionRestoring: ve
16132
16132
  }),
16133
16133
  /* @__PURE__ */ g("style", { children: "\n /* Force any SVG (or img) inside LogoSlot to fill the container height\n regardless of whether the component forwards its style prop. */\n .fe-logo-slot svg,\n .fe-logo-slot img { height: 100%; width: auto; display: block; }\n\n @keyframes fe-orb-breathe { 0%,100%{transform:scale(1)} 50%{transform:scale(1.04)} }\n @keyframes fe-orb-breathe-subtle { 0%,100%{transform:scale(1)} 50%{transform:scale(1.025)} }\n @keyframes fe-orb-pulse { 0%{transform:scale(1);opacity:.65} 50%{transform:scale(1.28);opacity:.1} 100%{transform:scale(1);opacity:.65} }\n @keyframes fe-orb-glow { from{opacity:.35} to{opacity:.75} }\n @keyframes fe-orb-fade-in { from{opacity:0} to{opacity:1} }\n @keyframes fe-orb-slide-up { from{opacity:0;transform:translateY(18px)} to{opacity:1;transform:translateY(0)} }\n @keyframes fe-orb-slide-down { from{opacity:1;transform:translateY(0)} to{opacity:0;transform:translateY(24px)} }\n @keyframes fe-orb-bar-0 { from{height:6px} to{height:18px} }\n @keyframes fe-orb-bar-1 { from{height:10px} to{height:22px} }\n @keyframes fe-orb-bar-2 { from{height:14px} to{height:26px} }\n @keyframes fe-orb-bar-3 { from{height:8px} to{height:20px} }\n @keyframes fe-orb-bar-4 { from{height:6px} to{height:16px} }\n @keyframes fe-dot-bounce { 0%,80%,100%{transform:translateY(0);opacity:.5} 40%{transform:translateY(-5px);opacity:1} }\n " })
16134
16134
  ]