@paramms/chat-widget 1.5.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,18 +1,18 @@
1
1
  var Be = Object.defineProperty;
2
- var $e = (t, e, l) => e in t ? Be(t, e, { enumerable: !0, configurable: !0, writable: !0, value: l }) : t[e] = l;
3
- var T = (t, e, l) => $e(t, typeof e != "symbol" ? e + "" : e, l);
4
- import { l as Me, b as ge, p as Re, r as qe, a as Ae } from "./codec.js";
5
- import { h as st } from "./codec.js";
2
+ var $e = (t, e, d) => e in t ? Be(t, e, { enumerable: !0, configurable: !0, writable: !0, value: d }) : t[e] = d;
3
+ var C = (t, e, d) => $e(t, typeof e != "symbol" ? e + "" : e, d);
4
+ import { l as Re, b as ve, p as Me, r as Ae, a as qe } from "./codec.js";
5
+ import { h as rt } from "./codec.js";
6
6
  import { P as Ne, C as Oe, b as De } from "./outbox.js";
7
7
  import { e as dt } from "./outbox.js";
8
8
  import { E2ESession as He, extractX3DHInit as _e } from "./e2e.js";
9
9
  const Ue = `
10
- .ocw { ${Me("ocw")}
10
+ .ocw { ${Re("ocw")}
11
11
  position:relative;
12
12
  display:flex; flex-direction:column; height:100%; min-height:320px; background:var(--ocw-bg);
13
13
  font-family:var(--ocw-fb); color:var(--ocw-ink); overflow:hidden; }
14
- @media (prefers-color-scheme: dark) { .ocw[data-theme="auto"] { ${ge("ocw")} } }
15
- .ocw[data-theme="dark"] { ${ge("ocw")} }
14
+ @media (prefers-color-scheme: dark) { .ocw[data-theme="auto"] { ${ve("ocw")} } }
15
+ .ocw[data-theme="dark"] { ${ve("ocw")} }
16
16
  /* ── Responsive sizing ──────────────────────────────────────────────────────
17
17
  * Sizing is driven by the WIDGET'S OWN width (ResizeObserver toggles
18
18
  * .ocw-compact below 400px), not the viewport — so a widget embedded in a
@@ -67,7 +67,7 @@ const Ue = `
67
67
  .ocw-row { display:flex; align-items:flex-end; gap:8px; max-width:86%; }
68
68
  .ocw-row.mine { align-self:flex-end; flex-direction:row-reverse; }
69
69
  .ocw-row.theirs { align-self:flex-start; }
70
- .ocw-bubble { padding:10px 14px; border-radius:18px; font-size:13.5px; line-height:1.45; word-wrap:break-word; max-width:80%; }
70
+ .ocw-bubble { padding:10px 14px; border-radius:18px; font-size:13.5px; line-height:1.45; word-wrap:break-word; max-width:100%; width:fit-content; }
71
71
  .theirs .ocw-bubble { background:var(--ocw-tint); border-bottom-left-radius:4px; }
72
72
  .mine .ocw-bubble { background:var(--ocw-accent2); color:#fff; border-bottom-right-radius:4px; }
73
73
  .ocw-sys { align-self:center; color:var(--ocw-mut); font-size:12.5px; font-style:italic; text-align:center; max-width:90%; }
@@ -197,21 +197,21 @@ const Ue = `
197
197
  .ocw-bubble-wrap:hover .ocw-translate-btn { opacity:1; }
198
198
  .ocw-translation { margin-top:6px; padding-top:6px; border-top:1px solid var(--ocw-line); font-size:13px; line-height:1.45; }
199
199
  .ocw-translation::before { content:'🌐 '; opacity:.75; }
200
- `, ye = "objectchat-widget-styles", Fe = ["👍", "❤️", "😂", "😮", "😢", "🙏"], We = 400, Ge = '<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M22 2 11 13M22 2l-7 20-4-9-9-4 20-7z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
200
+ `, ke = "objectchat-widget-styles", Fe = ["👍", "❤️", "😂", "😮", "😢", "🙏"], We = 400, Ge = '<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M22 2 11 13M22 2l-7 20-4-9-9-4 20-7z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
201
201
  function Ke() {
202
- if (typeof document > "u" || document.getElementById(ye)) return;
202
+ if (typeof document > "u" || document.getElementById(ke)) return;
203
203
  const t = document.createElement("style");
204
- t.id = ye, t.textContent = Ue, document.head.appendChild(t);
204
+ t.id = ke, t.textContent = Ue, document.head.appendChild(t);
205
205
  }
206
- const ve = "ocw-webfont";
206
+ const Ce = "ocw-webfont";
207
207
  function Ve() {
208
- if (typeof document > "u" || document.getElementById(ve)) return;
208
+ if (typeof document > "u" || document.getElementById(Ce)) return;
209
209
  const t = document.createElement("link");
210
- t.id = ve, t.rel = "stylesheet", t.href = "https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700&family=Nunito:wght@400;500;600;700&display=swap", document.head.appendChild(t);
210
+ t.id = Ce, t.rel = "stylesheet", t.href = "https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700&family=Nunito:wght@400;500;600;700&display=swap", document.head.appendChild(t);
211
211
  }
212
- function n(t, e, l) {
213
- const c = document.createElement(t);
214
- return e && (c.className = e), l !== void 0 && (c.textContent = l), c;
212
+ function n(t, e, d) {
213
+ const l = document.createElement(t);
214
+ return e && (l.className = e), d !== void 0 && (l.textContent = d), l;
215
215
  }
216
216
  function Ye(t) {
217
217
  try {
@@ -220,7 +220,7 @@ function Ye(t) {
220
220
  return "";
221
221
  }
222
222
  }
223
- function ae(t) {
223
+ function ce(t) {
224
224
  var e;
225
225
  switch (t.kind) {
226
226
  case "text":
@@ -239,94 +239,94 @@ function ae(t) {
239
239
  }
240
240
  class Xe {
241
241
  /** Last seq the guest has seen per conversationId — used to compute unread badges. */
242
- constructor(e, l, c, a = {}) {
243
- T(this, "scroll");
244
- T(this, "chips");
245
- T(this, "typing");
246
- T(this, "quick");
247
- T(this, "formHost");
248
- T(this, "csatPanel");
249
- T(this, "awayNotice");
250
- T(this, "headStatus");
251
- T(this, "reopenBtn");
252
- T(this, "preChatPanel");
253
- T(this, "deflectPanel");
254
- T(this, "preChatBuilt", !1);
255
- T(this, "preChatDone", !1);
256
- T(this, "footer");
257
- T(this, "input");
258
- T(this, "subjectCard");
259
- T(this, "e2eBadge");
260
- T(this, "statusBadge");
261
- T(this, "headerName");
262
- T(this, "connStatus");
263
- T(this, "typingTimer", null);
264
- T(this, "csatSubmitted", !1);
265
- T(this, "sendBtn");
242
+ constructor(e, d, l, c = {}) {
243
+ C(this, "scroll");
244
+ C(this, "chips");
245
+ C(this, "typing");
246
+ C(this, "quick");
247
+ C(this, "formHost");
248
+ C(this, "csatPanel");
249
+ C(this, "awayNotice");
250
+ C(this, "headStatus");
251
+ C(this, "reopenBtn");
252
+ C(this, "preChatPanel");
253
+ C(this, "deflectPanel");
254
+ C(this, "preChatBuilt", !1);
255
+ C(this, "preChatDone", !1);
256
+ C(this, "footer");
257
+ C(this, "input");
258
+ C(this, "subjectCard");
259
+ C(this, "e2eBadge");
260
+ C(this, "statusBadge");
261
+ C(this, "headerName");
262
+ C(this, "connStatus");
263
+ C(this, "typingTimer", null);
264
+ C(this, "csatSubmitted", !1);
265
+ C(this, "sendBtn");
266
266
  /** Container-driven responsive sizing — toggles .ocw-compact (see CSS note). */
267
- T(this, "compactObserver", null);
268
- T(this, "storeRef", null);
269
- T(this, "cfgAccent2");
270
- T(this, "scrollCleanup", null);
267
+ C(this, "compactObserver", null);
268
+ C(this, "storeRef", null);
269
+ C(this, "cfgAccent2");
270
+ C(this, "scrollCleanup", null);
271
271
  // ── Live translation ──────────────────────────────────────────────────-
272
- T(this, "translationCache", /* @__PURE__ */ new Map());
273
- T(this, "showingTranslation", /* @__PURE__ */ new Set());
272
+ C(this, "translationCache", /* @__PURE__ */ new Map());
273
+ C(this, "showingTranslation", /* @__PURE__ */ new Set());
274
274
  /** Whether the subject card (server Subject entity, mount config fallback)
275
275
  * has been built — built once when data first arrives. */
276
- T(this, "subjectBuilt", !1);
277
- var r, d, b, k, u, g, $, y, S, N, M;
278
- this.root = e, this.me = l, this.h = c, this.cfg = a, Ke(), a.webfont !== !1 && Ve(), e.replaceChildren(), e.classList.add("ocw"), a.accent && e.style.setProperty("--ocw-accent", a.accent);
279
- const f = a.accent2 ?? a.accent;
280
- f && e.style.setProperty("--ocw-accent2", f), this.cfgAccent2 = a.accent2, e.dataset.theme = a.theme ?? "light";
281
- const w = n("div", "ocw-head");
276
+ C(this, "subjectBuilt", !1);
277
+ var z, O, S, _, a, i, y, h, x, k, E;
278
+ this.root = e, this.me = d, this.h = l, this.cfg = c, Ke(), c.webfont !== !1 && Ve(), e.replaceChildren(), e.classList.add("ocw"), c.accent && e.style.setProperty("--ocw-accent", c.accent);
279
+ const w = c.accent2 ?? c.accent;
280
+ w && e.style.setProperty("--ocw-accent2", w), this.cfgAccent2 = c.accent2, e.dataset.theme = c.theme ?? "light";
281
+ const b = n("div", "ocw-head");
282
282
  if (this.h.onBack) {
283
- const v = n("button", "ocw-back", "‹");
284
- v.type = "button", v.setAttribute("aria-label", "Back"), v.addEventListener("click", () => this.h.onBack()), w.append(v);
283
+ const f = n("button", "ocw-back", "‹");
284
+ f.type = "button", f.setAttribute("aria-label", "Back"), f.addEventListener("click", () => this.h.onBack()), b.append(f);
285
285
  }
286
- const C = ((r = a.subject) == null ? void 0 : r.ownerLabel) ?? ((d = a.subject) == null ? void 0 : d.title) ?? "", p = n("div", "ocw-avatar");
287
- C.trim() && (p.textContent = C.trim()[0].toUpperCase(), w.append(p));
288
- const h = n("div", "ocw-head-main");
289
- this.headerName = n("div", "ocw-head-name", ((b = a.subject) == null ? void 0 : b.ownerLabel) ?? ((k = a.subject) == null ? void 0 : k.title) ?? ""), h.append(this.headerName), this.headStatus = n("div", "ocw-head-status"), this.headStatus.style.display = "none", h.append(this.headStatus), (u = a.subject) != null && u.subtitle && h.append(n("div", "ocw-head-meta", a.subject.subtitle)), w.append(h), this.statusBadge = n("span", "ocw-badge", ((g = a.subject) == null ? void 0 : g.status) ?? ""), ($ = a.subject) != null && $.status || (this.statusBadge.style.display = "none"), w.append(this.statusBadge), this.e2eBadge = n("span", "ocw-e2e", "🔒 E2E"), this.e2eBadge.style.display = "none", w.append(this.e2eBadge), this.connStatus = n("span", "ocw-conn-status"), this.connStatus.style.display = "none", w.append(this.connStatus), w.append(n("button", "ocw-menu", "⋯")), this.chips = n("div", "ocw-chiprow"), this.scroll = n("div", "ocw-scroll"), this.subjectCard = n("div", "ocw-subject"), this.typing = n("div", "ocw-typing");
290
- const m = n("div", "ocw-typing-bubble");
291
- m.append(n("div", "ocw-typing-dot"), n("div", "ocw-typing-dot"), n("div", "ocw-typing-dot")), this.typing.append(m), this.quick = n("div", "ocw-quick");
292
- for (const v of a.quickReplies ?? []) {
293
- const D = n("button", void 0, v);
294
- D.addEventListener("click", () => {
295
- this.h.onSend(v), this.quick.style.display = "none";
296
- }), this.quick.append(D);
286
+ const v = ((z = c.subject) == null ? void 0 : z.ownerLabel) ?? ((O = c.subject) == null ? void 0 : O.title) ?? "", p = n("div", "ocw-avatar");
287
+ v.trim() && (p.textContent = v.trim()[0].toUpperCase(), b.append(p));
288
+ const u = n("div", "ocw-head-main");
289
+ this.headerName = n("div", "ocw-head-name", ((S = c.subject) == null ? void 0 : S.ownerLabel) ?? ((_ = c.subject) == null ? void 0 : _.title) ?? ""), u.append(this.headerName), this.headStatus = n("div", "ocw-head-status"), this.headStatus.style.display = "none", u.append(this.headStatus), (a = c.subject) != null && a.subtitle && u.append(n("div", "ocw-head-meta", c.subject.subtitle)), b.append(u), this.statusBadge = n("span", "ocw-badge", ((i = c.subject) == null ? void 0 : i.status) ?? ""), (y = c.subject) != null && y.status || (this.statusBadge.style.display = "none"), b.append(this.statusBadge), this.e2eBadge = n("span", "ocw-e2e", "🔒 E2E"), this.e2eBadge.style.display = "none", b.append(this.e2eBadge), this.connStatus = n("span", "ocw-conn-status"), this.connStatus.style.display = "none", b.append(this.connStatus), b.append(n("button", "ocw-menu", "⋯")), this.chips = n("div", "ocw-chiprow"), this.scroll = n("div", "ocw-scroll"), this.subjectCard = n("div", "ocw-subject"), this.typing = n("div", "ocw-typing");
290
+ const g = n("div", "ocw-typing-bubble");
291
+ g.append(n("div", "ocw-typing-dot"), n("div", "ocw-typing-dot"), n("div", "ocw-typing-dot")), this.typing.append(g), this.quick = n("div", "ocw-quick");
292
+ for (const f of c.quickReplies ?? []) {
293
+ const T = n("button", void 0, f);
294
+ T.addEventListener("click", () => {
295
+ this.h.onSend(f), this.quick.style.display = "none";
296
+ }), this.quick.append(T);
297
297
  }
298
- this.formHost = n("div", "ocw-form-host"), this.csatPanel = n("div", "ocw-csat"), this.csatPanel.style.display = "none", this.awayNotice = n("div", "ocw-away"), this.awayNotice.style.display = "none", this.preChatPanel = n("div", "ocw-prechat"), this.preChatPanel.style.display = "none", this.deflectPanel = n("div", "ocw-deflect"), this.deflectPanel.style.display = "none", this.input = n("textarea", void 0), this.input.rows = 1, this.input.placeholder = ((y = a.i18n) == null ? void 0 : y.placeholder) ?? "Message…";
299
- const i = n("button", "ocw-sendbtn");
300
- i.type = "button";
301
- const P = (S = a.i18n) == null ? void 0 : S.send;
302
- P ? (i.textContent = P, i.classList.add("ocw-sendbtn-label"), i.setAttribute("aria-label", P)) : (i.innerHTML = Ge, i.setAttribute("aria-label", "Send message")), i.disabled = !0, this.sendBtn = i, i.addEventListener("click", () => this.flushSend()), this.input.addEventListener("input", () => {
303
- var v, D;
304
- this.sendBtn.disabled = this.input.value.trim().length === 0, this.autoGrowInput(), this.storeRef && !this.storeRef.messages().some((_) => _.senderRole === "guest") ? (D = (v = this.h).onDeflectQuery) == null || D.call(v, this.input.value) : this.hideDeflection();
305
- }), this.input.addEventListener("keydown", (v) => {
306
- v.isComposing || v.keyCode === 229 || (v.key === "Enter" && !v.shiftKey ? (v.preventDefault(), this.flushSend()) : this.signalTyping());
298
+ this.formHost = n("div", "ocw-form-host"), this.csatPanel = n("div", "ocw-csat"), this.csatPanel.style.display = "none", this.awayNotice = n("div", "ocw-away"), this.awayNotice.style.display = "none", this.preChatPanel = n("div", "ocw-prechat"), this.preChatPanel.style.display = "none", this.deflectPanel = n("div", "ocw-deflect"), this.deflectPanel.style.display = "none", this.input = n("textarea", void 0), this.input.rows = 1, this.input.placeholder = ((h = c.i18n) == null ? void 0 : h.placeholder) ?? "Message…";
299
+ const s = n("button", "ocw-sendbtn");
300
+ s.type = "button";
301
+ const $ = (x = c.i18n) == null ? void 0 : x.send;
302
+ $ ? (s.textContent = $, s.classList.add("ocw-sendbtn-label"), s.setAttribute("aria-label", $)) : (s.innerHTML = Ge, s.setAttribute("aria-label", "Send message")), s.disabled = !0, this.sendBtn = s, s.addEventListener("click", () => this.flushSend()), this.input.addEventListener("input", () => {
303
+ var f, T;
304
+ this.sendBtn.disabled = this.input.value.trim().length === 0, this.autoGrowInput(), this.storeRef && !this.storeRef.messages().some((N) => N.senderRole === "guest") ? (T = (f = this.h).onDeflectQuery) == null || T.call(f, this.input.value) : this.hideDeflection();
305
+ }), this.input.addEventListener("keydown", (f) => {
306
+ f.isComposing || f.keyCode === 229 || (f.key === "Enter" && !f.shiftKey ? (f.preventDefault(), this.flushSend()) : this.signalTyping());
307
307
  });
308
- const B = n("button", "ocw-attach", "📎");
309
- B.title = "Attach image or file";
308
+ const R = n("button", "ocw-attach", "📎");
309
+ R.title = "Attach image or file";
310
310
  const I = document.createElement("input");
311
- I.type = "file", I.accept = "image/*,.pdf,.txt,.doc,.docx", I.style.display = "none", B.addEventListener("click", () => I.click()), I.addEventListener("change", () => {
312
- var v;
313
- (v = I.files) != null && v[0] && this.h.onAttach && this.h.onAttach(I.files[0]), I.value = "";
311
+ I.type = "file", I.accept = "image/*,.pdf,.txt,.doc,.docx", I.style.display = "none", R.addEventListener("click", () => I.click()), I.addEventListener("change", () => {
312
+ var f;
313
+ (f = I.files) != null && f[0] && this.h.onAttach && this.h.onAttach(I.files[0]), I.value = "";
314
314
  });
315
- const q = n("div", "ocw-input");
316
- q.append(B, I, this.input, i);
317
- const z = n("div", "ocw-footer");
318
- ((N = a.i18n) == null ? void 0 : N.poweredBy) !== void 0 ? z.textContent = a.i18n.poweredBy : z.innerHTML = 'Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>', this.footer = z, this.reopenBtn = n("button", "ocw-reopen", ((M = this.cfg.i18n) == null ? void 0 : M.reopen) ?? "Reopen conversation"), this.reopenBtn.type = "button", this.reopenBtn.addEventListener("click", () => {
315
+ const A = n("div", "ocw-input");
316
+ A.append(R, I, this.input, s);
317
+ const j = n("div", "ocw-footer");
318
+ ((k = c.i18n) == null ? void 0 : k.poweredBy) !== void 0 ? j.textContent = c.i18n.poweredBy : j.innerHTML = 'Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>', this.footer = j, this.reopenBtn = n("button", "ocw-reopen", ((E = this.cfg.i18n) == null ? void 0 : E.reopen) ?? "Reopen conversation"), this.reopenBtn.type = "button", this.reopenBtn.addEventListener("click", () => {
319
319
  this.reopenBtn.style.display = "none";
320
- const v = this.root.querySelector(".ocw-input textarea");
321
- v == null || v.focus();
322
- }), e.append(w, this.chips, this.scroll, this.typing, this.quick, this.formHost, this.csatPanel, this.preChatPanel, this.deflectPanel, this.awayNotice, q, this.reopenBtn, this.footer);
323
- const j = (v) => {
324
- e.classList.toggle("ocw-compact", v > 0 && v < We);
320
+ const f = this.root.querySelector(".ocw-input textarea");
321
+ f == null || f.focus();
322
+ }), e.append(b, this.chips, this.scroll, this.typing, this.quick, this.formHost, this.csatPanel, this.preChatPanel, this.deflectPanel, this.awayNotice, A, this.reopenBtn, this.footer);
323
+ const P = (f) => {
324
+ e.classList.toggle("ocw-compact", f > 0 && f < We);
325
325
  };
326
- j(e.clientWidth), typeof ResizeObserver < "u" && (this.compactObserver = new ResizeObserver((v) => {
327
- var _;
328
- const D = ((_ = v[0]) == null ? void 0 : _.contentRect.width) ?? e.clientWidth;
329
- j(D);
326
+ P(e.clientWidth), typeof ResizeObserver < "u" && (this.compactObserver = new ResizeObserver((f) => {
327
+ var N;
328
+ const T = ((N = f[0]) == null ? void 0 : N.contentRect.width) ?? e.clientWidth;
329
+ P(T);
330
330
  }), this.compactObserver.observe(e));
331
331
  }
332
332
  /** Returns the scroll container so history.ts can attach scroll listeners. */
@@ -335,13 +335,13 @@ class Xe {
335
335
  }
336
336
  /** Registers a cleanup fn removed on destroy() to prevent listener leaks. */
337
337
  setScrollCleanup(e) {
338
- var l;
339
- (l = this.scrollCleanup) == null || l.call(this), this.scrollCleanup = e;
338
+ var d;
339
+ (d = this.scrollCleanup) == null || d.call(this), this.scrollCleanup = e;
340
340
  }
341
341
  /** Call when the widget is unmounted. Disconnects scroll listeners and clears timers. */
342
342
  destroy() {
343
- var e, l;
344
- (e = this.scrollCleanup) == null || e.call(this), this.scrollCleanup = null, this.typingTimer && (clearTimeout(this.typingTimer), this.typingTimer = null), (l = this.compactObserver) == null || l.disconnect(), this.compactObserver = null;
343
+ var e, d;
344
+ (e = this.scrollCleanup) == null || e.call(this), this.scrollCleanup = null, this.typingTimer && (clearTimeout(this.typingTimer), this.typingTimer = null), (d = this.compactObserver) == null || d.disconnect(), this.compactObserver = null;
345
345
  }
346
346
  flushSend() {
347
347
  this.hideDeflection();
@@ -360,111 +360,115 @@ class Xe {
360
360
  const e = this.input.value.trim().slice(0, 100) || void 0;
361
361
  this.h.onTyping(!0, e), this.typingTimer && clearTimeout(this.typingTimer), this.typingTimer = setTimeout(() => this.h.onTyping(!1), 2e3);
362
362
  }
363
+ /** A3.3 — per-chatroom bot identity from the manifest; relabels bot bubbles. */
364
+ setBotName(e) {
365
+ this.cfg.i18n = { ...this.cfg.i18n ?? {}, aiAssistant: e };
366
+ }
363
367
  render(e) {
364
- var I, q, z, j, r, d, b, k;
368
+ var I, A, j, P, z, O, S, _;
365
369
  if (this.storeRef = e, e.accent && (this.root.style.setProperty("--ocw-accent", e.accent), this.root.style.setProperty("--ocw-accent2", this.cfgAccent2 ?? e.accent)), this.e2eBadge.style.display = e.e2e ? "inline-flex" : "none", this.buildSubjectCard(e), e.subject) {
366
- const u = (I = this.cfg.subject) == null ? void 0 : I.ownerLabel;
367
- u && (this.headerName.textContent = u);
370
+ const a = (I = this.cfg.subject) == null ? void 0 : I.ownerLabel;
371
+ a && (this.headerName.textContent = a);
368
372
  }
369
373
  this.quick.style.display = e.messages().length === 0 ? "flex" : "none", this.chips.replaceChildren();
370
- const l = e.visibleActions();
371
- this.chips.style.display = l.length ? "flex" : "none";
372
- for (const u of l) this.chips.append(this.chipEl(u));
373
- const c = this.scroll.scrollHeight, a = this.scroll.scrollTop;
374
+ const d = e.visibleActions();
375
+ this.chips.style.display = d.length ? "flex" : "none";
376
+ for (const a of d) this.chips.append(this.chipEl(a));
377
+ const l = this.scroll.scrollHeight, c = this.scroll.scrollTop;
374
378
  if (this.scroll.replaceChildren(), this.subjectCard.childNodes.length && this.scroll.append(this.subjectCard), e.hasMoreHistory) {
375
- const u = n("div", "ocw-load-more");
376
- u.textContent = "↑ Loading earlier messages…", u.style.pointerEvents = "none", this.scroll.append(u);
379
+ const a = n("div", "ocw-load-more");
380
+ a.textContent = "↑ Loading earlier messages…", a.style.pointerEvents = "none", this.scroll.append(a);
377
381
  }
378
- let f = 0, w = null;
379
- const C = [...e.messages()];
380
- for (let u = 0; u < C.length; u++) {
381
- const g = C[u], $ = g.senderRole !== "system" && g.senderId !== this.me && !g.internal && g.senderId !== w;
382
- this.scroll.append(this.messageEl(g, e, $, u === C.length - 1)), g.senderRole !== "system" && (w = g.senderId), g.senderId !== this.me && g.seq > f && (f = g.seq);
382
+ let w = 0, b = null;
383
+ const v = [...e.messages()];
384
+ for (let a = 0; a < v.length; a++) {
385
+ const i = v[a], y = i.senderRole !== "system" && i.senderId !== this.me && !i.internal && i.senderId !== b;
386
+ this.scroll.append(this.messageEl(i, e, y, a === v.length - 1)), i.senderRole !== "system" && (b = i.senderId), i.senderId !== this.me && i.seq > w && (w = i.seq);
383
387
  }
384
- a > 20 ? this.scroll.scrollTop = this.scroll.scrollHeight - c + a : this.scroll.scrollTop = this.scroll.scrollHeight, f > 0 && this.h.onReadUpTo(f);
388
+ c > 20 ? this.scroll.scrollTop = this.scroll.scrollHeight - l + c : this.scroll.scrollTop = this.scroll.scrollHeight, w > 0 && this.h.onReadUpTo(w);
385
389
  const p = [...e.typing];
386
390
  this.typing.classList.toggle("active", p.length > 0);
387
- const h = this.typing.querySelector(".ocw-typing-bubble");
388
- h && h.setAttribute("aria-label", p.length ? "typing" : ""), this.footer.style.display = e.whiteLabel ? "none" : "block";
389
- const m = e.messages().some((u) => u.senderRole === "guest");
390
- if (!!((q = e.preChat) != null && q.enabled) && !this.preChatDone && !m && (e.preChat.showWhen !== "offline" || e.offline))
391
- this.preChatBuilt || this.buildPreChatPanel(e.preChat), this.preChatPanel.style.display = "block", this.awayNotice.style.display = "none", (z = this.root.querySelector(".ocw-input")) == null || z.style.setProperty("display", "none");
391
+ const u = this.typing.querySelector(".ocw-typing-bubble");
392
+ u && u.setAttribute("aria-label", p.length ? "typing" : ""), this.footer.style.display = e.whiteLabel ? "none" : "block";
393
+ const g = e.messages().some((a) => a.senderRole === "guest");
394
+ if (!!((A = e.preChat) != null && A.enabled) && !this.preChatDone && !g && (e.preChat.showWhen !== "offline" || e.offline))
395
+ this.preChatBuilt || this.buildPreChatPanel(e.preChat), this.preChatPanel.style.display = "block", this.awayNotice.style.display = "none", (j = this.root.querySelector(".ocw-input")) == null || j.style.setProperty("display", "none");
392
396
  else {
393
397
  if (this.preChatPanel.style.display = "none", e.offline) {
394
398
  this.awayNotice.firstChild || this.awayNotice.append(n("span", "ocw-away-icon", "🌙"), n("span", "", ""));
395
- const u = this.awayNotice.lastChild;
396
- u.textContent = e.offlineMessage || ((j = this.cfg.i18n) == null ? void 0 : j.offline) || "We're away right now — send your message and we'll reply as soon as we're back.", this.awayNotice.style.display = "flex";
399
+ const a = this.awayNotice.lastChild;
400
+ a.textContent = e.offlineMessage || ((P = this.cfg.i18n) == null ? void 0 : P.offline) || "We're away right now — send your message and we'll reply as soon as we're back.", this.awayNotice.style.display = "flex";
397
401
  } else
398
402
  this.awayNotice.style.display = "none";
399
- (r = this.root.querySelector(".ocw-input")) == null || r.style.removeProperty("display");
403
+ (z = this.root.querySelector(".ocw-input")) == null || z.style.removeProperty("display");
400
404
  }
401
- const P = ["resolved", "closed", "sold", "issued", "checked_out"];
402
- this.h.onCsat && !this.csatSubmitted && P.includes(e.state) && e.messages().length > 0 && (this.csatPanel.style.display === "none" && this.buildCsatPanel(), this.csatPanel.style.display = "block");
403
- const B = P.includes(e.state);
404
- if (e.offline ? (this.headStatus.textContent = `● ${e.offlineMessage || ((d = this.cfg.i18n) == null ? void 0 : d.away) || "Away"}`, this.headStatus.className = "ocw-head-status away", this.headStatus.style.display = "") : e.conversationId ? (this.headStatus.textContent = `● ${((b = this.cfg.i18n) == null ? void 0 : b.online) ?? "Online"}`, this.headStatus.className = "ocw-head-status online", this.headStatus.style.display = "") : this.headStatus.style.display = "none", B && e.messages().length > 0) {
405
- const u = n("div", "ocw-resolved-note", `— ${((k = this.cfg.i18n) == null ? void 0 : k.resolved) ?? "Marked as resolved"} —`);
406
- this.scroll.append(u), this.reopenBtn.style.display = "block";
405
+ const $ = ["resolved", "closed", "sold", "issued", "checked_out"];
406
+ this.h.onCsat && !this.csatSubmitted && $.includes(e.state) && e.messages().length > 0 && (this.csatPanel.style.display === "none" && this.buildCsatPanel(), this.csatPanel.style.display = "block");
407
+ const R = $.includes(e.state);
408
+ if (e.offline ? (this.headStatus.textContent = `● ${e.offlineMessage || ((O = this.cfg.i18n) == null ? void 0 : O.away) || "Away"}`, this.headStatus.className = "ocw-head-status away", this.headStatus.style.display = "") : e.conversationId ? (this.headStatus.textContent = `● ${((S = this.cfg.i18n) == null ? void 0 : S.online) ?? "Online"}`, this.headStatus.className = "ocw-head-status online", this.headStatus.style.display = "") : this.headStatus.style.display = "none", R && e.messages().length > 0) {
409
+ const a = n("div", "ocw-resolved-note", `— ${((_ = this.cfg.i18n) == null ? void 0 : _.resolved) ?? "Marked as resolved"} —`);
410
+ this.scroll.append(a), this.reopenBtn.style.display = "block";
407
411
  } else
408
412
  this.reopenBtn.style.display = "none";
409
413
  }
410
- setConnStatus(e, l) {
414
+ setConnStatus(e, d) {
411
415
  if (e === "open") {
412
416
  this.connStatus.style.display = "none";
413
417
  return;
414
418
  }
415
419
  this.connStatus.style.display = "";
416
- const c = e === "error";
417
- this.connStatus.className = `ocw-conn-status${c ? " err" : e === "reconnecting" ? " warn" : ""}`, this.connStatus.textContent = c ? `⚠ ${l ?? "Chat unavailable"}` : e === "reconnecting" ? l ?? "↻ reconnecting…" : "● connecting…";
420
+ const l = e === "error";
421
+ this.connStatus.className = `ocw-conn-status${l ? " err" : e === "reconnecting" ? " warn" : ""}`, this.connStatus.textContent = l ? `⚠ ${d ?? "Chat unavailable"}` : e === "reconnecting" ? d ?? "↻ reconnecting…" : "● connecting…";
418
422
  }
419
423
  buildPreChatPanel(e) {
420
424
  var p;
421
425
  this.preChatBuilt = !0, this.preChatPanel.replaceChildren(), this.preChatPanel.append(n("div", "ocw-prechat-title", e.title ?? "Before we start…"));
422
- const l = n("div", "ocw-offline-form"), c = {};
423
- for (const h of e.fields ?? ["name", "email"]) {
424
- const m = n("input", "ocw-offline-input");
425
- m.type = h === "email" ? "email" : h === "phone" ? "tel" : "text", m.placeholder = h === "name" ? "Your name" : h === "email" ? "Your email" : "Your phone number", c[h] = m, l.append(m);
426
+ const d = n("div", "ocw-offline-form"), l = {};
427
+ for (const u of e.fields ?? ["name", "email"]) {
428
+ const g = n("input", "ocw-offline-input");
429
+ g.type = u === "email" ? "email" : u === "phone" ? "tel" : "text", g.placeholder = u === "name" ? "Your name" : u === "email" ? "Your email" : "Your phone number", l[u] = g, d.append(g);
426
430
  }
427
- let a = null;
431
+ let c = null;
428
432
  if ((p = e.topics) != null && p.length) {
429
- a = n("select", void 0);
430
- const h = document.createElement("option");
431
- h.value = "", h.textContent = "What is this about?", a.append(h);
432
- for (const m of e.topics) {
433
- const i = document.createElement("option");
434
- i.value = m, i.textContent = m, a.append(i);
433
+ c = n("select", void 0);
434
+ const u = document.createElement("option");
435
+ u.value = "", u.textContent = "What is this about?", c.append(u);
436
+ for (const g of e.topics) {
437
+ const s = document.createElement("option");
438
+ s.value = g, s.textContent = g, c.append(s);
435
439
  }
436
- l.append(a);
440
+ d.append(c);
437
441
  }
438
- let f = null, w = null;
442
+ let w = null, b = null;
439
443
  if (e.callbackOption) {
440
- const h = n("label", "ocw-prechat-cb");
441
- f = document.createElement("input"), f.type = "checkbox", h.append(f, document.createTextNode("📞 Request a call back")), l.append(h), c.phone || (w = n("input", "ocw-offline-input"), w.type = "tel", w.placeholder = "Phone number for the call", w.style.display = "none", f.addEventListener("change", () => w.style.setProperty("display", f.checked ? "block" : "none")), l.append(w));
444
+ const u = n("label", "ocw-prechat-cb");
445
+ w = document.createElement("input"), w.type = "checkbox", u.append(w, document.createTextNode("📞 Request a call back")), d.append(u), l.phone || (b = n("input", "ocw-offline-input"), b.type = "tel", b.placeholder = "Phone number for the call", b.style.display = "none", w.addEventListener("change", () => b.style.setProperty("display", w.checked ? "block" : "none")), d.append(b));
442
446
  }
443
- const C = n("button", "ocw-offline-submit", "Start chat");
444
- C.type = "button", C.addEventListener("click", () => {
445
- var P, B, I, q, z, j, r;
446
- const h = (P = c.email) == null ? void 0 : P.value.trim();
447
- if (c.email && (!h || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(h))) {
448
- c.email.focus();
447
+ const v = n("button", "ocw-offline-submit", "Start chat");
448
+ v.type = "button", v.addEventListener("click", () => {
449
+ var $, R, I, A, j, P, z;
450
+ const u = ($ = l.email) == null ? void 0 : $.value.trim();
451
+ if (l.email && (!u || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(u))) {
452
+ l.email.focus();
449
453
  return;
450
454
  }
451
- const m = !!(f != null && f.checked), i = (((B = c.phone) == null ? void 0 : B.value) ?? (w == null ? void 0 : w.value) ?? "").trim();
452
- if (m && !i) {
453
- (I = c.phone ?? w) == null || I.focus();
455
+ const g = !!(w != null && w.checked), s = (((R = l.phone) == null ? void 0 : R.value) ?? (b == null ? void 0 : b.value) ?? "").trim();
456
+ if (g && !s) {
457
+ (I = l.phone ?? b) == null || I.focus();
454
458
  return;
455
459
  }
456
- if (a && ((q = e.topics) != null && q.length) && !a.value) {
457
- a.focus();
460
+ if (c && ((A = e.topics) != null && A.length) && !c.value) {
461
+ c.focus();
458
462
  return;
459
463
  }
460
- C.disabled = !0, this.completePreChat(), (r = (j = this.h).onPreChat) == null || r.call(j, {
461
- ...(z = c.name) != null && z.value.trim() ? { name: c.name.value.trim() } : {},
462
- ...h ? { email: h } : {},
463
- ...i ? { phone: i } : {},
464
- ...a != null && a.value ? { topic: a.value } : {},
465
- ...m ? { callback: !0 } : {}
464
+ v.disabled = !0, this.completePreChat(), (z = (P = this.h).onPreChat) == null || z.call(P, {
465
+ ...(j = l.name) != null && j.value.trim() ? { name: l.name.value.trim() } : {},
466
+ ...u ? { email: u } : {},
467
+ ...s ? { phone: s } : {},
468
+ ...c != null && c.value ? { topic: c.value } : {},
469
+ ...g ? { callback: !0 } : {}
466
470
  });
467
- }), l.append(C), this.preChatPanel.append(l);
471
+ }), d.append(v), this.preChatPanel.append(d);
468
472
  }
469
473
  /** Mark pre-chat complete (submitted now or in a previous session). */
470
474
  completePreChat() {
@@ -474,9 +478,9 @@ class Xe {
474
478
  showDeflection(e) {
475
479
  if (!e.length) return this.hideDeflection();
476
480
  this.deflectPanel.replaceChildren(), this.deflectPanel.append(n("div", "ocw-deflect-hint", "Instant answers — tap to expand"));
477
- for (const l of e.slice(0, 3)) {
478
- const c = n("button", "ocw-deflect-card");
479
- c.append(n("div", "ocw-deflect-q", l.title), n("div", "ocw-deflect-a", l.answer)), c.addEventListener("click", () => c.classList.toggle("open")), this.deflectPanel.append(c);
481
+ for (const d of e.slice(0, 3)) {
482
+ const l = n("button", "ocw-deflect-card");
483
+ l.append(n("div", "ocw-deflect-q", d.title), n("div", "ocw-deflect-a", d.answer)), l.addEventListener("click", () => l.classList.toggle("open")), this.deflectPanel.append(l);
480
484
  }
481
485
  this.deflectPanel.style.display = "flex";
482
486
  }
@@ -485,236 +489,263 @@ class Xe {
485
489
  }
486
490
  buildCsatPanel() {
487
491
  this.csatPanel.replaceChildren(), this.csatPanel.append(n("div", "ocw-csat-title", "How did we do?"));
488
- const e = n("div", "ocw-csat-stars"), l = [];
489
- for (let c = 1; c <= 5; c++) {
490
- const a = n("button", "ocw-csat-star", "★");
491
- a.dataset.score = String(c), a.addEventListener("mouseenter", () => l.forEach((f, w) => f.classList.toggle("lit", w < c))), a.addEventListener("mouseleave", () => l.forEach((f) => f.classList.remove("lit"))), a.addEventListener("click", () => {
492
- var f, w;
493
- this.csatSubmitted = !0, this.csatPanel.replaceChildren(n("div", "ocw-csat-done", `Thanks for your ${c}★ rating!`)), (w = (f = this.h).onCsat) == null || w.call(f, c);
494
- }), l.push(a), e.append(a);
492
+ const e = n("div", "ocw-csat-stars"), d = [];
493
+ for (let l = 1; l <= 5; l++) {
494
+ const c = n("button", "ocw-csat-star", "★");
495
+ c.dataset.score = String(l), c.addEventListener("mouseenter", () => d.forEach((w, b) => w.classList.toggle("lit", b < l))), c.addEventListener("mouseleave", () => d.forEach((w) => w.classList.remove("lit"))), c.addEventListener("click", () => {
496
+ var w, b;
497
+ this.csatSubmitted = !0, this.csatPanel.replaceChildren(n("div", "ocw-csat-done", `Thanks for your ${l}★ rating!`)), (b = (w = this.h).onCsat) == null || b.call(w, l);
498
+ }), d.push(c), e.append(c);
495
499
  }
496
500
  this.csatPanel.append(e);
497
501
  }
498
502
  buildSubjectCard(e) {
499
503
  if (this.subjectBuilt) return;
500
- const l = e.subject, c = this.cfg.subject, a = (l == null ? void 0 : l.title) ?? (c == null ? void 0 : c.title);
501
- if (!a) return;
502
- this.subjectBuilt = !0, this.subjectCard.replaceChildren(), this.subjectCard.append(n("div", "ocw-subject-title", a)), c != null && c.subtitle && this.subjectCard.append(n("div", "ocw-subject-sub", c.subtitle));
503
- const f = n("div", "ocw-tags");
504
- if (l) for (const [C, p] of Object.entries(l.fields)) f.append(n("span", "ocw-tag", `${C}: ${p}`));
505
- else for (const C of (c == null ? void 0 : c.tags) ?? []) f.append(n("span", "ocw-tag", C));
506
- f.childNodes.length && this.subjectCard.append(f);
507
- const w = (l == null ? void 0 : l.state) ?? (c == null ? void 0 : c.status);
508
- w && (this.statusBadge.textContent = w, this.statusBadge.style.display = "inline-flex");
504
+ const d = e.subject, l = this.cfg.subject, c = (d == null ? void 0 : d.title) ?? (l == null ? void 0 : l.title);
505
+ if (!c) return;
506
+ this.subjectBuilt = !0, this.subjectCard.replaceChildren(), this.subjectCard.append(n("div", "ocw-subject-title", c)), l != null && l.subtitle && this.subjectCard.append(n("div", "ocw-subject-sub", l.subtitle));
507
+ const w = n("div", "ocw-tags");
508
+ if (d) for (const [v, p] of Object.entries(d.fields)) w.append(n("span", "ocw-tag", `${v}: ${p}`));
509
+ else for (const v of (l == null ? void 0 : l.tags) ?? []) w.append(n("span", "ocw-tag", v));
510
+ w.childNodes.length && this.subjectCard.append(w);
511
+ const b = (d == null ? void 0 : d.state) ?? (l == null ? void 0 : l.status);
512
+ b && (this.statusBadge.textContent = b, this.statusBadge.style.display = "inline-flex");
509
513
  }
510
514
  chipEl(e) {
511
- const l = n("button", "ocw-chip", e.icon ? `${e.icon} ${e.label}` : e.label);
512
- return l.dataset.actionId = e.id, l.addEventListener("click", async () => {
513
- var c;
514
- e.confirm && !await this.confirm(e.label) || ((c = e.input) != null && c.length ? this.openForm(e) : this.h.onInvoke(e.id));
515
- }), l;
515
+ const d = n("button", "ocw-chip", e.icon ? `${e.icon} ${e.label}` : e.label);
516
+ return d.dataset.actionId = e.id, d.addEventListener("click", async () => {
517
+ var l;
518
+ e.confirm && !await this.confirm(e.label) || ((l = e.input) != null && l.length ? this.openForm(e) : this.h.onInvoke(e.id));
519
+ }), d;
516
520
  }
517
521
  /** In-widget confirmation modal (replaces window.confirm). */
518
522
  confirm(e) {
519
- return new Promise((l) => {
520
- const c = n("div", "ocw-modal"), a = n("div", "ocw-modal-card");
521
- a.append(n("div", "ocw-modal-title", e)), a.append(n("div", "ocw-modal-body", `Confirm “${e}”?`));
522
- const f = n("div", "ocw-modal-actions"), w = n("button", "ocw-modal-cancel", "Cancel"), C = n("button", "ocw-modal-ok", "Confirm"), p = (h) => {
523
- c.remove(), l(h);
523
+ return new Promise((d) => {
524
+ const l = n("div", "ocw-modal"), c = n("div", "ocw-modal-card");
525
+ c.append(n("div", "ocw-modal-title", e)), c.append(n("div", "ocw-modal-body", `Confirm “${e}”?`));
526
+ const w = n("div", "ocw-modal-actions"), b = n("button", "ocw-modal-cancel", "Cancel"), v = n("button", "ocw-modal-ok", "Confirm"), p = (u) => {
527
+ l.remove(), d(u);
524
528
  };
525
- w.addEventListener("click", () => p(!1)), C.addEventListener("click", () => p(!0)), c.addEventListener("click", (h) => {
526
- h.target === c && p(!1);
527
- }), f.append(w, C), a.append(f), c.append(a), this.root.append(c), C.focus();
529
+ b.addEventListener("click", () => p(!1)), v.addEventListener("click", () => p(!0)), l.addEventListener("click", (u) => {
530
+ u.target === l && p(!1);
531
+ }), w.append(b, v), c.append(w), l.append(c), this.root.append(l), v.focus();
528
532
  });
529
533
  }
530
534
  /** Inline form for a form-effect action: typed inputs (date picker, number,
531
535
  * text) rendered above the composer — no browser prompts. */
532
536
  openForm(e) {
533
- var C, p;
537
+ var v, p;
534
538
  this.formHost.replaceChildren();
535
- const l = n("div", "ocw-form");
536
- l.append(n("div", "ocw-form-title", e.icon ? `${e.icon} ${e.label}` : e.label));
537
- const c = /* @__PURE__ */ new Map();
538
- for (const h of e.input ?? []) {
539
- const m = n("label", "ocw-form-row");
540
- if (m.append(n("span", "ocw-form-lbl", h.label)), h.type === "select" && ((C = h.options) != null && C.length)) {
541
- const i = n("select", "ocw-form-input");
542
- h.required || i.append(n("option", void 0, "— select —"));
543
- for (const P of h.options) {
544
- const B = n("option");
545
- B.value = P, B.textContent = P, i.append(B);
539
+ const d = n("div", "ocw-form");
540
+ d.append(n("div", "ocw-form-title", e.icon ? `${e.icon} ${e.label}` : e.label));
541
+ const l = /* @__PURE__ */ new Map();
542
+ for (const u of e.input ?? []) {
543
+ const g = n("label", "ocw-form-row");
544
+ if (g.append(n("span", "ocw-form-lbl", u.label)), u.type === "select" && ((v = u.options) != null && v.length)) {
545
+ const s = n("select", "ocw-form-input");
546
+ u.required || s.append(n("option", void 0, "— select —"));
547
+ for (const $ of u.options) {
548
+ const R = n("option");
549
+ R.value = $, R.textContent = $, s.append(R);
546
550
  }
547
- h.required && (i.required = !0), m.append(i), c.set(h.name, i);
551
+ u.required && (s.required = !0), g.append(s), l.set(u.name, s);
548
552
  } else {
549
- const i = n("input", "ocw-form-input");
550
- i.type = h.type === "number" ? "number" : h.type === "date" ? "datetime-local" : "text", h.required && (i.required = !0), m.append(i), c.set(h.name, i);
553
+ const s = n("input", "ocw-form-input");
554
+ s.type = u.type === "number" ? "number" : u.type === "date" ? "datetime-local" : "text", u.required && (s.required = !0), g.append(s), l.set(u.name, s);
551
555
  }
552
- l.append(m);
556
+ d.append(g);
553
557
  }
554
- const a = n("div", "ocw-form-actions"), f = n("button", "ocw-form-cancel", "Cancel"), w = n("button", "ocw-form-submit", "Send");
555
- f.addEventListener("click", () => this.formHost.replaceChildren()), w.addEventListener("click", () => {
556
- const h = {};
557
- for (const [m, i] of c) {
558
- if (i.required && !i.value) {
559
- i.style.borderColor = "#e5484d";
558
+ const c = n("div", "ocw-form-actions"), w = n("button", "ocw-form-cancel", "Cancel"), b = n("button", "ocw-form-submit", "Send");
559
+ w.addEventListener("click", () => this.formHost.replaceChildren()), b.addEventListener("click", () => {
560
+ const u = {};
561
+ for (const [g, s] of l) {
562
+ if (s.required && !s.value) {
563
+ s.style.borderColor = "#e5484d";
560
564
  return;
561
565
  }
562
- h[m] = i.type === "number" ? Number(i.value) : i.value;
566
+ u[g] = s.type === "number" ? Number(s.value) : s.value;
563
567
  }
564
- this.formHost.replaceChildren(), this.h.onInvoke(e.id, h);
565
- }), a.append(f, w), l.append(a), this.formHost.append(l), (p = c.values().next().value) == null || p.focus();
568
+ this.formHost.replaceChildren(), this.h.onInvoke(e.id, u);
569
+ }), c.append(w, b), d.append(c), this.formHost.append(d), (p = l.values().next().value) == null || p.focus();
566
570
  }
567
- messageEl(e, l, c = !1, a = !1) {
568
- var B, I, q, z, j;
571
+ messageEl(e, d, l = !1, c = !1) {
572
+ var R, I, A, j, P, z, O, S, _;
569
573
  if (e.senderRole === "system") {
570
- const r = n("div", "ocw-sys");
571
- return r.textContent = e.deletedAt ? "message deleted" : ae(e.content), r;
574
+ const a = n("div", "ocw-sys");
575
+ return a.textContent = e.deletedAt ? "message deleted" : ce(e.content), a;
572
576
  }
573
- const f = e.senderId === this.me, w = !!e.internal, C = n("div", `ocw-row ${w ? "ocw-note mine" : f ? "mine" : "theirs"} ${e.senderRole === "bot" ? "ocw-bot" : ""}`), p = n("div");
574
- if (c) {
575
- const r = e.senderRole === "bot" ? ((B = this.cfg.i18n) == null ? void 0 : B.aiAssistant) ?? "AI Assistant" : ((I = this.cfg.subject) == null ? void 0 : I.ownerLabel) ?? ((q = this.cfg.subject) == null ? void 0 : q.title) ?? "Support";
576
- p.append(n("div", "ocw-msg-sender", r));
577
+ const w = e.senderId === this.me, b = !!e.internal, v = n("div", `ocw-row ${b ? "ocw-note mine" : w ? "mine" : "theirs"} ${e.senderRole === "bot" ? "ocw-bot" : ""}`), p = n("div");
578
+ if (l) {
579
+ const a = e.senderRole === "bot" ? ((R = this.cfg.i18n) == null ? void 0 : R.aiAssistant) ?? "AI Assistant" : ((I = this.cfg.subject) == null ? void 0 : I.ownerLabel) ?? ((A = this.cfg.subject) == null ? void 0 : A.title) ?? "Support";
580
+ p.append(n("div", "ocw-msg-sender", a));
577
581
  }
578
- const h = n("div", "ocw-bubble-wrap");
582
+ const u = n("div", "ocw-bubble-wrap");
579
583
  if (e.replyToId) {
580
- const r = n("div", "ocw-reply-to", "↩ replying to a message");
581
- r.style.cssText = "font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic", p.append(r);
584
+ const a = n("div", "ocw-reply-to", "↩ replying to a message");
585
+ a.style.cssText = "font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic", p.append(a);
582
586
  }
583
- const m = n("div", "ocw-bubble");
584
- let i = null;
585
- if (e.deletedAt) m.append(n("span", "ocw-deleted", "message deleted"));
587
+ const g = n("div", "ocw-bubble");
588
+ let s = null;
589
+ if (e.deletedAt) g.append(n("span", "ocw-deleted", "message deleted"));
586
590
  else if (e.content.kind === "attachment") {
587
- const r = e.content;
588
- if ((z = r.mime) != null && z.startsWith("image/")) {
589
- const d = document.createElement("img");
590
- d.src = r.url, d.alt = r.name ?? "image", d.style.cssText = "max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer", d.addEventListener("click", () => window.open(r.url, "_blank")), m.append(d);
591
+ const a = e.content;
592
+ if ((j = a.mime) != null && j.startsWith("image/")) {
593
+ const i = document.createElement("img");
594
+ i.src = a.url, i.alt = a.name ?? "image", i.style.cssText = "max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer", i.addEventListener("click", () => window.open(a.url, "_blank")), g.append(i);
595
+ } else if ((P = a.mime) != null && P.startsWith("video/")) {
596
+ const i = document.createElement("video");
597
+ i.src = a.url, i.controls = !0, i.style.cssText = "max-width:240px;max-height:180px;border-radius:10px;display:block", g.append(i);
591
598
  } else {
592
- const d = document.createElement("a");
593
- d.href = r.url, d.target = "_blank", d.rel = "noopener", d.style.cssText = "display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none", d.append(n("span", void 0, "📄"), n("span", void 0, r.name ?? "file")), m.append(d);
599
+ const i = document.createElement("a");
600
+ i.href = a.url, i.target = "_blank", i.rel = "noopener", i.style.cssText = "display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none", i.append(n("span", void 0, "📄"), n("span", void 0, a.name ?? "file")), g.append(i);
594
601
  }
595
602
  } else if (e.content.kind === "appointment") {
596
- const r = e.content, d = n("div", "ocw-appt");
597
- d.append(n("div", "ocw-appt-title", `📅 ${r.title}`)), d.append(n("div", "ocw-appt-time", new Date(r.startIso).toLocaleString() + " – " + new Date(r.endIso).toLocaleTimeString())), r.location && d.append(n("div", "ocw-appt-loc", `📍 ${r.location}`)), r.description && d.append(n("div", "ocw-appt-desc", r.description));
598
- const b = n("div", "ocw-appt-links"), k = document.createElement("a");
599
- k.href = r.googleUrl, k.target = "_blank", k.rel = "noopener", k.className = "ocw-appt-btn", k.textContent = "📅 Add to Google Calendar";
600
- const u = document.createElement("a");
601
- u.href = r.icalUrl, u.download = `${r.title}.ics`, u.className = "ocw-appt-btn ocw-appt-btn-sec", u.textContent = "🍎 Apple / iCal", b.append(k, u), d.append(b), m.append(d);
603
+ const a = e.content, i = n("div", "ocw-appt");
604
+ i.append(n("div", "ocw-appt-title", `📅 ${a.title}`)), i.append(n("div", "ocw-appt-time", new Date(a.startIso).toLocaleString() + " – " + new Date(a.endIso).toLocaleTimeString())), a.location && i.append(n("div", "ocw-appt-loc", `📍 ${a.location}`)), a.description && i.append(n("div", "ocw-appt-desc", a.description));
605
+ const y = n("div", "ocw-appt-links"), h = document.createElement("a");
606
+ h.href = a.googleUrl, h.target = "_blank", h.rel = "noopener", h.className = "ocw-appt-btn", h.textContent = "📅 Add to Google Calendar";
607
+ const x = document.createElement("a");
608
+ x.href = a.icalUrl, x.download = `${a.title}.ics`, x.className = "ocw-appt-btn ocw-appt-btn-sec", x.textContent = "🍎 Apple / iCal", y.append(h, x), i.append(y), g.append(i);
602
609
  } else
603
- i = document.createTextNode(ae(e.content)), m.append(i), e.editedAt && m.append(n("span", "ocw-edited", "(edited)"));
604
- if (h.append(m), a && !e.deletedAt && e.content.kind === "text" && ((j = e.content.quickReplies) != null && j.length)) {
605
- const r = n("div", "ocw-flow-choices");
606
- r.style.cssText = "display:flex;flex-wrap:wrap;gap:6px;margin-top:6px";
607
- for (const d of e.content.quickReplies) {
608
- const b = n("button", "ocw-flow-choice", d);
609
- b.type = "button", b.style.cssText = "border:1px solid var(--ocw-bd,rgba(0,0,0,.12));background:var(--ocw-bg,#fff);color:inherit;border-radius:14px;padding:5px 12px;font:inherit;font-size:13px;cursor:pointer", b.addEventListener("click", () => {
610
- r.querySelectorAll("button").forEach((k) => k.disabled = !0), r.style.opacity = "0.5", this.h.onSend(d);
611
- }), r.append(b);
610
+ s = document.createTextNode(ce(e.content)), g.append(s), e.editedAt && g.append(n("span", "ocw-edited", "(edited)"));
611
+ if (u.append(g), c && !e.deletedAt && e.content.kind === "text" && ((z = e.content.quickReplies) != null && z.length)) {
612
+ const a = n("div", "ocw-flow-choices");
613
+ a.style.cssText = "display:flex;flex-wrap:wrap;gap:6px;margin-top:6px";
614
+ for (const i of e.content.quickReplies) {
615
+ const y = n("button", "ocw-flow-choice", i);
616
+ y.type = "button", y.style.cssText = "border:1px solid var(--ocw-bd,rgba(0,0,0,.12));background:var(--ocw-bg,#fff);color:inherit;border-radius:14px;padding:5px 12px;font:inherit;font-size:13px;cursor:pointer", y.addEventListener("click", () => {
617
+ a.querySelectorAll("button").forEach((h) => h.disabled = !0), a.style.opacity = "0.5", this.h.onSend(i);
618
+ }), a.append(y);
612
619
  }
613
- h.append(r);
620
+ u.append(a);
614
621
  }
615
- if (!f && !w && this.h.onTranslate && e.content.kind === "text" && !e.deletedAt && e.seq > 0 && i) {
616
- const r = e.content.text;
617
- if (r.trim()) {
618
- const d = n("button", "ocw-translate-btn", "🌐");
619
- d.type = "button", d.title = "Translate";
620
- const b = n("div", "ocw-translation");
621
- b.style.display = "none", m.append(b);
622
- const k = ($) => {
623
- b.textContent = $, b.style.display = "", this.showingTranslation.add(e.id), d.textContent = "↩", d.title = "Show original";
624
- }, u = () => {
625
- b.style.display = "none", this.showingTranslation.delete(e.id), d.textContent = "🌐", d.title = "Translate";
622
+ if (!w && !b && this.h.onTranslate && e.content.kind === "text" && !e.deletedAt && e.seq > 0 && s) {
623
+ const a = e.content.text;
624
+ if (a.trim()) {
625
+ const i = n("button", "ocw-translate-btn", "🌐");
626
+ i.type = "button", i.title = "Translate";
627
+ const y = n("div", "ocw-translation");
628
+ y.style.display = "none", g.append(y);
629
+ const h = (E) => {
630
+ y.textContent = E, y.style.display = "", this.showingTranslation.add(e.id), i.textContent = "↩", i.title = "Show original";
631
+ }, x = () => {
632
+ y.style.display = "none", this.showingTranslation.delete(e.id), i.textContent = "🌐", i.title = "Translate";
626
633
  };
627
- d.addEventListener("click", ($) => {
628
- if ($.stopPropagation(), this.showingTranslation.has(e.id)) {
629
- u();
634
+ i.addEventListener("click", (E) => {
635
+ if (E.stopPropagation(), this.showingTranslation.has(e.id)) {
636
+ x();
630
637
  return;
631
638
  }
632
- const y = this.translationCache.get(e.id);
633
- if (y !== void 0) {
634
- k(y);
639
+ const f = this.translationCache.get(e.id);
640
+ if (f !== void 0) {
641
+ h(f);
635
642
  return;
636
643
  }
637
- d.textContent = "⏳", this.h.onTranslate(r).then((S) => {
638
- if (S === null) {
639
- d.textContent = "⚠️", d.title = "Translation unavailable", setTimeout(() => {
640
- d.textContent = "🌐", d.title = "Translate";
644
+ i.textContent = "⏳", this.h.onTranslate(a).then((T) => {
645
+ if (T === null) {
646
+ i.textContent = "⚠️", i.title = "Translation unavailable", setTimeout(() => {
647
+ i.textContent = "🌐", i.title = "Translate";
641
648
  }, 1500);
642
649
  return;
643
650
  }
644
- this.translationCache.set(e.id, S), k(S);
651
+ this.translationCache.set(e.id, T), h(T);
645
652
  });
646
- }), h.append(d);
647
- const g = this.translationCache.get(e.id);
648
- this.showingTranslation.has(e.id) && g !== void 0 && k(g);
653
+ }), u.append(i);
654
+ const k = this.translationCache.get(e.id);
655
+ this.showingTranslation.has(e.id) && k !== void 0 && h(k);
649
656
  }
650
657
  }
651
- if (f && !e.deletedAt && e.seq > 0 && (this.h.onEdit ?? this.h.onDelete)) {
652
- const r = n("div", "ocw-msg-menu");
658
+ if (w && !e.deletedAt && e.seq > 0 && (this.h.onEdit ?? this.h.onDelete)) {
659
+ const a = n("div", "ocw-msg-menu");
653
660
  if (this.h.onEdit) {
654
- const d = n("button", void 0, "✏️");
655
- d.title = "Edit", d.addEventListener("click", (b) => {
656
- b.stopPropagation();
657
- const k = ae(e.content), u = document.createElement("textarea");
658
- u.value = k, u.rows = Math.min(4, Math.ceil(k.length / 40) + 1), u.style.cssText = "width:100%;resize:vertical;border:1px solid var(--ocw-accent);border-radius:8px;padding:6px 10px;font:inherit;font-size:14px;background:var(--ocw-card);color:#1c1b1a;box-sizing:border-box";
659
- const g = n("button", "ocw-form-submit", "Save");
660
- g.style.cssText = "margin-top:6px;padding:5px 14px;font-size:13px";
661
- const $ = n("button", "ocw-form-cancel", "Cancel");
662
- $.style.cssText = "margin-top:6px;padding:5px 10px;font-size:13px";
663
- const y = n("div");
664
- y.style.cssText = "display:flex;gap:6px;justify-content:flex-end", y.append($, g);
665
- const S = n("div");
666
- S.append(u, y), m.replaceChildren(S), u.focus(), u.select();
667
- const N = () => m.replaceChildren(i ?? document.createTextNode(k));
668
- $.addEventListener("click", N), g.addEventListener("click", () => {
669
- const M = u.value.trim();
670
- M && M !== k && this.h.onEdit(e.id, M), N();
671
- }), u.addEventListener("keydown", (M) => {
672
- M.key === "Enter" && !M.shiftKey && (M.preventDefault(), g.click()), M.key === "Escape" && N();
661
+ const i = n("button", void 0, "✏️");
662
+ i.title = "Edit", i.addEventListener("click", (y) => {
663
+ y.stopPropagation();
664
+ const h = ce(e.content), x = document.createElement("textarea");
665
+ x.value = h, x.rows = Math.min(4, Math.ceil(h.length / 40) + 1), x.style.cssText = "width:100%;resize:vertical;border:1px solid var(--ocw-accent);border-radius:8px;padding:6px 10px;font:inherit;font-size:14px;background:var(--ocw-card);color:#1c1b1a;box-sizing:border-box";
666
+ const k = n("button", "ocw-form-submit", "Save");
667
+ k.style.cssText = "margin-top:6px;padding:5px 14px;font-size:13px";
668
+ const E = n("button", "ocw-form-cancel", "Cancel");
669
+ E.style.cssText = "margin-top:6px;padding:5px 10px;font-size:13px";
670
+ const f = n("div");
671
+ f.style.cssText = "display:flex;gap:6px;justify-content:flex-end", f.append(E, k);
672
+ const T = n("div");
673
+ T.append(x, f), g.replaceChildren(T), x.focus(), x.select();
674
+ const N = () => g.replaceChildren(s ?? document.createTextNode(h));
675
+ E.addEventListener("click", N), k.addEventListener("click", () => {
676
+ const D = x.value.trim();
677
+ D && D !== h && this.h.onEdit(e.id, D), N();
678
+ }), x.addEventListener("keydown", (D) => {
679
+ D.key === "Enter" && !D.shiftKey && (D.preventDefault(), k.click()), D.key === "Escape" && N();
673
680
  });
674
- }), r.append(d);
681
+ }), a.append(i);
675
682
  }
676
683
  if (this.h.onDelete) {
677
- const d = n("button", "del", "🗑");
678
- d.title = "Delete", d.addEventListener("click", (b) => {
679
- b.stopPropagation(), this.h.onDelete(e.id);
680
- }), r.append(d);
684
+ const i = n("button", "del", "🗑");
685
+ i.title = "Delete", i.addEventListener("click", (y) => {
686
+ y.stopPropagation(), this.h.onDelete(e.id);
687
+ }), a.append(i);
688
+ }
689
+ u.append(a);
690
+ }
691
+ if (p.append(u), e.senderRole === "bot" && !e.deletedAt && e.seq > 0 && e.content.kind === "text") {
692
+ const a = e.content.citations;
693
+ if (a != null && a.length) {
694
+ const i = n("div", "ocw-cites");
695
+ i.style.cssText = "margin-top:4px;font-size:11px;color:var(--ocw-mut,#667)", i.textContent = `${((O = this.cfg.i18n) == null ? void 0 : O.sources) ?? "Sources"}: ${a.map((y) => y.source).join(", ")}`, p.append(i);
696
+ }
697
+ if (this.h.onReact) {
698
+ const i = n("div", "ocw-bot-feedback");
699
+ i.style.cssText = "display:flex;gap:6px;margin-top:4px";
700
+ const y = (h, x) => {
701
+ const k = n("button", "ocw-fb-btn", h);
702
+ k.type = "button", k.title = x, k.style.cssText = "border:1px solid var(--ocw-bd,rgba(0,0,0,.12));background:transparent;border-radius:12px;padding:1px 8px;font-size:12px;cursor:pointer;opacity:.7";
703
+ const E = () => {
704
+ var f, T;
705
+ return !!((T = (f = e.reactions) == null ? void 0 : f[h]) != null && T.includes(this.me));
706
+ };
707
+ return E() && (k.style.opacity = "1"), k.addEventListener("click", () => {
708
+ var f, T;
709
+ (T = (f = this.h).onReact) == null || T.call(f, e.id, h, E()), k.style.opacity = "1";
710
+ }), k;
711
+ };
712
+ i.append(y("👍", ((S = this.cfg.i18n) == null ? void 0 : S.helpful) ?? "Helpful"), y("👎", ((_ = this.cfg.i18n) == null ? void 0 : _.notHelpful) ?? "Not helpful")), p.append(i);
681
713
  }
682
- h.append(r);
683
714
  }
684
- if (p.append(h), this.h.onReact && !e.deletedAt && e.seq > 0) {
685
- const r = n("div", "ocw-react-wrap"), d = n("div", "ocw-react");
715
+ if (this.h.onReact && !e.deletedAt && e.seq > 0) {
716
+ const a = n("div", "ocw-react-wrap"), i = n("div", "ocw-react");
686
717
  if (e.reactions && Object.keys(e.reactions).length)
687
- for (const [u, g] of Object.entries(e.reactions)) {
688
- const $ = n("button", `ocw-react-pill${g.includes(this.me) ? " mine" : ""}`, `${u} ${g.length}`);
689
- $.addEventListener("click", () => {
690
- var y, S;
691
- return (S = (y = this.h).onReact) == null ? void 0 : S.call(y, e.id, u, g.includes(this.me));
692
- }), d.append($);
718
+ for (const [x, k] of Object.entries(e.reactions)) {
719
+ const E = n("button", `ocw-react-pill${k.includes(this.me) ? " mine" : ""}`, `${x} ${k.length}`);
720
+ E.addEventListener("click", () => {
721
+ var f, T;
722
+ return (T = (f = this.h).onReact) == null ? void 0 : T.call(f, e.id, x, k.includes(this.me));
723
+ }), i.append(E);
693
724
  }
694
- const b = n("button", "ocw-react-btn", "+"), k = n("div", "ocw-react-picker");
695
- for (const u of Fe) {
696
- const g = n("button", void 0, u);
697
- g.addEventListener("click", ($) => {
698
- var S, N, M, v;
699
- $.stopPropagation();
700
- const y = (N = (S = e.reactions) == null ? void 0 : S[u]) == null ? void 0 : N.includes(this.me);
701
- (v = (M = this.h).onReact) == null || v.call(M, e.id, u, !!y), k.style.display = "none";
702
- }), k.append(g);
725
+ const y = n("button", "ocw-react-btn", "+"), h = n("div", "ocw-react-picker");
726
+ for (const x of Fe) {
727
+ const k = n("button", void 0, x);
728
+ k.addEventListener("click", (E) => {
729
+ var T, N, D, X;
730
+ E.stopPropagation();
731
+ const f = (N = (T = e.reactions) == null ? void 0 : T[x]) == null ? void 0 : N.includes(this.me);
732
+ (X = (D = this.h).onReact) == null || X.call(D, e.id, x, !!f), h.style.display = "none";
733
+ }), h.append(k);
703
734
  }
704
- k.style.display = "none", b.addEventListener("click", (u) => {
705
- u.stopPropagation();
706
- const g = k.style.display === "none";
707
- k.style.display = g ? "flex" : "none", g && document.addEventListener("click", () => {
708
- k.style.display = "none";
735
+ h.style.display = "none", y.addEventListener("click", (x) => {
736
+ x.stopPropagation();
737
+ const k = h.style.display === "none";
738
+ h.style.display = k ? "flex" : "none", k && document.addEventListener("click", () => {
739
+ h.style.display = "none";
709
740
  }, { once: !0 });
710
- }), d.append(b), r.append(d, k), p.append(r);
711
- } else e.reactions && Object.keys(e.reactions).length && p.append(n("div", "ocw-react", Object.entries(e.reactions).map(([r, d]) => `${r}${d.length}`).join(" ")));
712
- const P = n("div", "ocw-time ocw-meta", Ye(e.ts));
713
- if (f && e.status) {
714
- const r = n("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`, Qe(e.status));
715
- P.append(r);
741
+ }), i.append(y), a.append(i, h), p.append(a);
742
+ } else e.reactions && Object.keys(e.reactions).length && p.append(n("div", "ocw-react", Object.entries(e.reactions).map(([a, i]) => `${a}${i.length}`).join(" ")));
743
+ const $ = n("div", "ocw-time ocw-meta", Ye(e.ts));
744
+ if (w && e.status) {
745
+ const a = n("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`, Qe(e.status));
746
+ $.append(a);
716
747
  }
717
- return f && e.seq > 0 && l.lastReadByOthers >= e.seq && P.append(n("span", "ocw-seen", " · Seen")), p.append(P), C.append(p), C;
748
+ return w && e.seq > 0 && d.lastReadByOthers >= e.seq && $.append(n("span", "ocw-seen", " · Seen")), p.append($), v.append(p), v;
718
749
  }
719
750
  }
720
751
  function Qe(t) {
@@ -729,40 +760,40 @@ function Qe(t) {
729
760
  return "🕓";
730
761
  }
731
762
  }
732
- const U = /* @__PURE__ */ new WeakMap(), ee = /* @__PURE__ */ new Map();
733
- function ke(t) {
763
+ const F = /* @__PURE__ */ new WeakMap(), ne = /* @__PURE__ */ new Map();
764
+ function Te(t) {
734
765
  return `relay-launcher::${t.profileId}::${t.subjectId ?? ""}`;
735
766
  }
736
- let V = null;
767
+ let Y = null;
737
768
  function Je() {
738
- if (V && V.state !== "closed") return V;
769
+ if (Y && Y.state !== "closed") return Y;
739
770
  try {
740
- return V = new AudioContext(), V;
771
+ return Y = new AudioContext(), Y;
741
772
  } catch {
742
773
  return null;
743
774
  }
744
775
  }
745
776
  function it(t) {
746
777
  var e;
747
- (e = U.get(t)) == null || e.close(), U.delete(t);
778
+ (e = F.get(t)) == null || e.close(), F.delete(t);
748
779
  }
749
780
  function at(t) {
750
- var se, le, de, pe, he, ue, fe, we;
751
- U.has(t.el) && (U.get(t.el).close(), U.delete(t.el)), t.launcher && ((se = ee.get(ke(t))) == null || se.close());
752
- const e = Re();
753
- let l, c = !1;
754
- const a = t.token ?? t.userId ?? e, f = a !== e ? e : void 0, { wsUrl: w, httpBase: C } = qe(t.url, t.apiUrl);
755
- let p = new Oe(a);
756
- const h = t.subjectId ? `${a}::${t.subjectId}` : a, m = new Ne(h);
757
- let i, P = !1, B = null, I = null, q = null, z = null;
781
+ var de, pe, he, ue, fe, we, be, xe;
782
+ F.has(t.el) && (F.get(t.el).close(), F.delete(t.el)), t.launcher && ((de = ne.get(Te(t))) == null || de.close());
783
+ const e = Me();
784
+ let d, l = !1;
785
+ const c = t.token ?? t.userId ?? e, w = c !== e ? e : void 0, { wsUrl: b, httpBase: v } = Ae(t.url, t.apiUrl);
786
+ let p = new Oe(c);
787
+ const u = t.subjectId ? `${c}::${t.subjectId}` : c, g = new Ne(u);
788
+ let s, $ = !1, R = null, I = null, A = null, j = null;
758
789
  !t.launcher && !t.el.style.height && t.el.clientHeight === 0 && (t.el.style.width = t.el.style.width || "100%", t.el.style.height = "600px");
759
- for (const o of m.load()) p.addOptimistic(o.clientMsgId, o.content);
760
- let j = null, r = null, d = 0, b = !t.launcher;
790
+ for (const o of g.load()) p.addOptimistic(o.clientMsgId, o.content);
791
+ let P = null, z = null, O = 0, S = !t.launcher;
761
792
  if (t.launcher) {
762
- const s = (t.position ?? "bottom-right").includes("right");
763
- j = document.createElement("div"), j.style.cssText = `position:fixed;${s ? "right:20px" : "left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${s ? "flex-end" : "flex-start"};gap:12px`;
764
- const x = document.createElement("div"), R = typeof window < "u" && typeof window.matchMedia == "function" ? window.matchMedia("(max-width: 479px)") : null, G = (L) => {
765
- t.el.classList.toggle("ocw-fs", L), x.style.cssText = L ? [
793
+ const r = (t.position ?? "bottom-right").includes("right");
794
+ P = document.createElement("div"), P.style.cssText = `position:fixed;${r ? "right:20px" : "left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${r ? "flex-end" : "flex-start"};gap:12px`;
795
+ const m = document.createElement("div"), M = typeof window < "u" && typeof window.matchMedia == "function" ? window.matchMedia("(max-width: 479px)") : null, K = (B) => {
796
+ t.el.classList.toggle("ocw-fs", B), m.style.cssText = B ? [
766
797
  "position:fixed",
767
798
  "inset:0",
768
799
  "width:100%",
@@ -785,17 +816,17 @@ function at(t) {
785
816
  "display:none",
786
817
  "flex-direction:column",
787
818
  "background:#fff",
788
- "transform-origin:bottom " + (s ? "right" : "left"),
819
+ "transform-origin:bottom " + (r ? "right" : "left"),
789
820
  "transition:opacity .18s,transform .18s",
790
821
  "opacity:0",
791
822
  "transform:scale(.95)"
792
823
  ].join(";");
793
824
  };
794
- G((R == null ? void 0 : R.matches) ?? !1);
795
- const K = (L) => G(L.matches);
796
- R == null || R.addEventListener("change", K), B = R, I = K, t.el.style.cssText = "width:100%;height:100%;overflow:hidden", x.append(t.el);
797
- const X = '<svg viewBox="0 0 24 24" width="26" height="26" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>', Q = '<svg viewBox="0 0 24 24" width="22" height="22" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg>', O = document.createElement("button");
798
- O.type = "button", O.style.cssText = [
825
+ K((M == null ? void 0 : M.matches) ?? !1);
826
+ const V = (B) => K(B.matches);
827
+ M == null || M.addEventListener("change", V), R = M, I = V, t.el.style.cssText = "width:100%;height:100%;overflow:hidden", m.append(t.el);
828
+ const J = '<svg viewBox="0 0 24 24" width="26" height="26" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>', Z = '<svg viewBox="0 0 24 24" width="22" height="22" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg>', H = document.createElement("button");
829
+ H.type = "button", H.style.cssText = [
799
830
  "width:56px;height:56px;border-radius:50%",
800
831
  `background:${t.accent ?? "#6c5ce7"}`,
801
832
  "color:#fff;border:none;cursor:pointer",
@@ -803,31 +834,31 @@ function at(t) {
803
834
  "position:relative;flex:none",
804
835
  "display:flex;align-items:center;justify-content:center",
805
836
  "transition:transform .15s"
806
- ].join(";"), O.onmouseenter = () => {
807
- O.style.transform = "scale(1.08)";
808
- }, O.onmouseleave = () => {
809
- O.style.transform = "scale(1)";
810
- }, r = document.createElement("span"), r.style.cssText = "position:absolute;top:-4px;right:-4px;background:#4c6fff;color:#fff;border-radius:50%;width:20px;height:20px;font-size:11px;font-weight:700;display:none;align-items:center;justify-content:center";
811
- const J = () => {
812
- O.innerHTML = b ? Q : X, O.setAttribute("aria-label", b ? "Close chat" : "Open chat"), O.setAttribute("aria-expanded", String(b)), O.append(r);
837
+ ].join(";"), H.onmouseenter = () => {
838
+ H.style.transform = "scale(1.08)";
839
+ }, H.onmouseleave = () => {
840
+ H.style.transform = "scale(1)";
841
+ }, z = document.createElement("span"), z.style.cssText = "position:absolute;top:-4px;right:-4px;background:#4c6fff;color:#fff;border-radius:50%;width:20px;height:20px;font-size:11px;font-weight:700;display:none;align-items:center;justify-content:center";
842
+ const ee = () => {
843
+ H.innerHTML = S ? Z : J, H.setAttribute("aria-label", S ? "Close chat" : "Open chat"), H.setAttribute("aria-expanded", String(S)), H.append(z);
813
844
  };
814
- J(), j.append(x, O), document.body.append(j);
815
- const te = `ocw-teaser-dismissed::${t.profileId}`, Z = typeof t.launcherMessage == "string" ? { title: t.launcherMessage } : t.launcherMessage;
816
- let E = null;
817
- const Le = () => {
845
+ ee(), P.append(m, H), document.body.append(P);
846
+ const oe = `ocw-teaser-dismissed::${t.profileId}`, te = typeof t.launcherMessage == "string" ? { title: t.launcherMessage } : t.launcherMessage;
847
+ let L = null;
848
+ const je = () => {
818
849
  try {
819
- return sessionStorage.getItem(te) === "1";
850
+ return sessionStorage.getItem(oe) === "1";
820
851
  } catch {
821
852
  return !1;
822
853
  }
823
- }, Pe = '<svg viewBox="0 0 24 24" width="15" height="15" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>', be = () => {
824
- const L = Z != null && Z.title ? Z : p.launcherMessage ?? void 0;
825
- if (!(!!(L != null && L.title) && !b && !Le())) {
826
- E && (E.remove(), E = null);
854
+ }, Pe = '<svg viewBox="0 0 24 24" width="15" height="15" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>', me = () => {
855
+ const B = te != null && te.title ? te : p.launcherMessage ?? void 0;
856
+ if (!(!!(B != null && B.title) && !S && !je())) {
857
+ L && (L.remove(), L = null);
827
858
  return;
828
859
  }
829
- if (E) return;
830
- E = document.createElement("div"), E.setAttribute("role", "button"), E.setAttribute("tabindex", "0"), E.setAttribute("aria-label", L.title), E.style.cssText = [
860
+ if (L) return;
861
+ L = document.createElement("div"), L.setAttribute("role", "button"), L.setAttribute("tabindex", "0"), L.setAttribute("aria-label", B.title), L.style.cssText = [
831
862
  "max-width:280px",
832
863
  "background:#fff",
833
864
  "border-radius:16px",
@@ -836,142 +867,142 @@ function at(t) {
836
867
  "position:relative",
837
868
  "cursor:pointer",
838
869
  "font-family:inherit",
839
- `align-self:${s ? "flex-end" : "flex-start"}`,
870
+ `align-self:${r ? "flex-end" : "flex-start"}`,
840
871
  "animation:ocw-teaser-in .22s ease-out"
841
872
  ].join(";");
842
- const oe = document.createElement("div");
843
- if (oe.textContent = L.title, oe.style.cssText = "font-size:15px;font-weight:600;color:#111;line-height:1.35", E.append(oe), L.subtitle) {
844
- const H = document.createElement("div");
845
- H.style.cssText = "display:flex;align-items:center;gap:6px;margin-top:6px;font-size:13px;color:#6b7280";
846
- const ie = document.createElement("span");
847
- ie.innerHTML = Pe, ie.style.cssText = `color:${t.accent ?? "#6c5ce7"};display:inline-flex`;
848
- const me = document.createElement("span");
849
- me.textContent = L.subtitle, H.append(ie, me), E.append(H);
873
+ const ae = document.createElement("div");
874
+ if (ae.textContent = B.title, ae.style.cssText = "font-size:15px;font-weight:600;color:#111;line-height:1.35", L.append(ae), B.subtitle) {
875
+ const U = document.createElement("div");
876
+ U.style.cssText = "display:flex;align-items:center;gap:6px;margin-top:6px;font-size:13px;color:#6b7280";
877
+ const se = document.createElement("span");
878
+ se.innerHTML = Pe, se.style.cssText = `color:${t.accent ?? "#6c5ce7"};display:inline-flex`;
879
+ const ye = document.createElement("span");
880
+ ye.textContent = B.subtitle, U.append(se, ye), L.append(U);
850
881
  }
851
- const F = document.createElement("button");
852
- F.type = "button", F.setAttribute("aria-label", "Dismiss"), F.innerHTML = '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M18 6 6 18M6 6l12 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg>', F.style.cssText = "position:absolute;top:8px;right:8px;width:24px;height:24px;border:none;border-radius:50%;background:#f3f4f6;color:#6b7280;cursor:pointer;display:flex;align-items:center;justify-content:center;padding:0", F.addEventListener("click", (H) => {
853
- H.stopPropagation();
882
+ const W = document.createElement("button");
883
+ W.type = "button", W.setAttribute("aria-label", "Dismiss"), W.innerHTML = '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M18 6 6 18M6 6l12 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg>', W.style.cssText = "position:absolute;top:8px;right:8px;width:24px;height:24px;border:none;border-radius:50%;background:#f3f4f6;color:#6b7280;cursor:pointer;display:flex;align-items:center;justify-content:center;padding:0", W.addEventListener("click", (U) => {
884
+ U.stopPropagation();
854
885
  try {
855
- sessionStorage.setItem(te, "1");
886
+ sessionStorage.setItem(oe, "1");
856
887
  } catch {
857
888
  }
858
- E && (E.remove(), E = null);
859
- }), E.append(F);
860
- const xe = () => {
861
- b || (b = !0, ne(!0), J(), d = 0, r && (r.style.display = "none"), E && (E.remove(), E = null));
889
+ L && (L.remove(), L = null);
890
+ }), L.append(W);
891
+ const ge = () => {
892
+ S || (S = !0, ie(!0), ee(), O = 0, z && (z.style.display = "none"), L && (L.remove(), L = null));
862
893
  };
863
- E.addEventListener("click", xe), E.addEventListener("keydown", (H) => {
864
- (H.key === "Enter" || H.key === " ") && (H.preventDefault(), xe());
865
- }), j.insertBefore(E, O);
894
+ L.addEventListener("click", ge), L.addEventListener("keydown", (U) => {
895
+ (U.key === "Enter" || U.key === " ") && (U.preventDefault(), ge());
896
+ }), P.insertBefore(L, H);
866
897
  };
867
898
  if (!document.getElementById("ocw-teaser-style")) {
868
- const L = document.createElement("style");
869
- L.id = "ocw-teaser-style", L.textContent = "@keyframes ocw-teaser-in{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}", document.head.append(L);
899
+ const B = document.createElement("style");
900
+ B.id = "ocw-teaser-style", B.textContent = "@keyframes ocw-teaser-in{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}", document.head.append(B);
870
901
  }
871
- z = be, be();
872
- const ne = (L) => {
873
- L ? (x.style.display = "flex", requestAnimationFrame(() => {
874
- x.style.opacity = "1", x.style.transform = "scale(1)";
875
- })) : (x.style.opacity = "0", x.style.transform = "scale(.95)", setTimeout(() => {
876
- b || (x.style.display = "none");
902
+ j = me, me();
903
+ const ie = (B) => {
904
+ B ? (m.style.display = "flex", requestAnimationFrame(() => {
905
+ m.style.opacity = "1", m.style.transform = "scale(1)";
906
+ })) : (m.style.opacity = "0", m.style.transform = "scale(.95)", setTimeout(() => {
907
+ S || (m.style.display = "none");
877
908
  }, 180));
878
909
  };
879
- O.addEventListener("click", () => {
880
- if (b = !b, ne(b), J(), b) {
881
- d = 0, r && (r.style.display = "none");
910
+ H.addEventListener("click", () => {
911
+ if (S = !S, ie(S), ee(), S) {
912
+ O = 0, z && (z.style.display = "none");
882
913
  try {
883
- sessionStorage.setItem(te, "1");
914
+ sessionStorage.setItem(oe, "1");
884
915
  } catch {
885
916
  }
886
917
  }
887
- z == null || z();
888
- }), q = (L) => {
889
- L.key === "Escape" && b && (b = !1, ne(!1), J());
890
- }, document.addEventListener("keydown", q);
918
+ j == null || j();
919
+ }), A = (B) => {
920
+ B.key === "Escape" && S && (S = !1, ie(!1), ee());
921
+ }, document.addEventListener("keydown", A);
891
922
  }
892
- const k = () => {
893
- b || (d++, r && (r.textContent = String(d), r.style.display = "flex"));
894
- }, u = () => {
923
+ const _ = () => {
924
+ S || (O++, z && (z.textContent = String(O), z.style.display = "flex"));
925
+ }, a = () => {
895
926
  try {
896
927
  const o = Je();
897
928
  if (!o) return;
898
929
  o.state === "suspended" && o.resume().catch(() => {
899
930
  });
900
- const s = o.createOscillator(), x = o.createGain();
901
- s.connect(x), x.connect(o.destination), s.frequency.setValueAtTime(880, o.currentTime), s.frequency.exponentialRampToValueAtTime(440, o.currentTime + 0.15), x.gain.setValueAtTime(0.3, o.currentTime), x.gain.exponentialRampToValueAtTime(1e-3, o.currentTime + 0.3), s.start(), s.stop(o.currentTime + 0.3);
931
+ const r = o.createOscillator(), m = o.createGain();
932
+ r.connect(m), m.connect(o.destination), r.frequency.setValueAtTime(880, o.currentTime), r.frequency.exponentialRampToValueAtTime(440, o.currentTime + 0.15), m.gain.setValueAtTime(0.3, o.currentTime), m.gain.exponentialRampToValueAtTime(1e-3, o.currentTime + 0.3), r.start(), r.stop(o.currentTime + 0.3);
902
933
  } catch {
903
934
  }
904
- }, g = [], $ = (o) => {
905
- for (; g.length; ) {
906
- const s = g.shift();
907
- m.add({ clientMsgId: s.clientMsgId, content: s.content, ts: Date.now() }), y.send({ type: "send", conversationId: o, clientMsgId: s.clientMsgId, content: s.content });
935
+ }, i = [], y = (o) => {
936
+ for (; i.length; ) {
937
+ const r = i.shift();
938
+ g.add({ clientMsgId: r.clientMsgId, content: r.content, ts: Date.now() }), h.send({ type: "send", conversationId: o, clientMsgId: r.clientMsgId, content: r.content });
908
939
  }
909
940
  };
910
- let y;
911
- const S = new He(`ocw-e2e-${t.profileId}`);
912
- let N = !1;
913
- const M = [], v = [];
914
- let D = !1;
915
- const _ = (o, s) => {
916
- S.sealText(s).then((x) => {
917
- i && y.send({ type: "send", conversationId: i, clientMsgId: o, content: x });
941
+ let h;
942
+ const x = new He(`ocw-e2e-${t.profileId}`);
943
+ let k = !1;
944
+ const E = [], f = [];
945
+ let T = !1;
946
+ const N = (o, r) => {
947
+ x.sealText(r).then((m) => {
948
+ s && h.send({ type: "send", conversationId: s, clientMsgId: o, content: m });
918
949
  });
919
- }, Ce = (o, s, x) => {
920
- S.sealText(s, x).then((R) => {
921
- i && y.send({ type: "send", conversationId: i, clientMsgId: o, content: R });
950
+ }, D = (o, r, m) => {
951
+ x.sealText(r, m).then((M) => {
952
+ s && h.send({ type: "send", conversationId: s, clientMsgId: o, content: M });
922
953
  });
923
- }, Te = () => {
924
- for (; M.length; ) {
925
- const o = M.shift();
926
- _(o.clientMsgId, o.text);
954
+ }, X = () => {
955
+ for (; E.length; ) {
956
+ const o = E.shift();
957
+ N(o.clientMsgId, o.text);
927
958
  }
928
- for (; v.length; ) {
929
- const o = v.shift();
930
- _(o.clientMsgId, o.text);
959
+ for (; f.length; ) {
960
+ const o = f.shift();
961
+ N(o.clientMsgId, o.text);
931
962
  }
932
963
  }, Se = (o) => {
933
- y.send({ type: "fetchPrekey", targetUserId: o });
934
- }, Ie = t.i18n ?? {}, Ee = ["ar", "he", "fa", "ur"], ze = typeof navigator < "u" ? (navigator.language ?? "").slice(0, 2).toLowerCase() : "";
935
- Ee.includes(ze) && !t.el.dir && (t.el.dir = "rtl", t.el.style.fontFamily = t.el.style.fontFamily || "Tahoma,Arial,system-ui,sans-serif");
936
- const ce = `oc_prechat_${t.profileId}_${a.slice(-8)}`, A = new Xe(t.el, a, {
964
+ h.send({ type: "fetchPrekey", targetUserId: o });
965
+ }, Ee = t.i18n ?? {}, Ie = ["ar", "he", "fa", "ur"], ze = typeof navigator < "u" ? (navigator.language ?? "").slice(0, 2).toLowerCase() : "";
966
+ Ie.includes(ze) && !t.el.dir && (t.el.dir = "rtl", t.el.style.fontFamily = t.el.style.fontFamily || "Tahoma,Arial,system-ui,sans-serif");
967
+ const re = `oc_prechat_${t.profileId}_${c.slice(-8)}`, q = new Xe(t.el, c, {
937
968
  onSend(o) {
938
- const s = `cm_${Math.random().toString(36).slice(2)}`, x = { kind: "text", text: o };
939
- p.addOptimistic(s, x), A.render(p), p.e2e ? S.ready ? _(s, o) : D ? v.push({ clientMsgId: s, text: o }) : (M.push({ clientMsgId: s, text: o }), p.assignedAgentId && Se(p.assignedAgentId)) : i ? (m.add({ clientMsgId: s, content: x, ts: Date.now() }), y.send({ type: "send", conversationId: i, clientMsgId: s, content: x })) : g.push({ clientMsgId: s, content: x });
969
+ const r = `cm_${Math.random().toString(36).slice(2)}`, m = { kind: "text", text: o };
970
+ p.addOptimistic(r, m), q.render(p), p.e2e ? x.ready ? N(r, o) : T ? f.push({ clientMsgId: r, text: o }) : (E.push({ clientMsgId: r, text: o }), p.assignedAgentId && Se(p.assignedAgentId)) : s ? (g.add({ clientMsgId: r, content: m, ts: Date.now() }), h.send({ type: "send", conversationId: s, clientMsgId: r, content: m })) : i.push({ clientMsgId: r, content: m });
940
971
  },
941
972
  async onAttach(o) {
942
- if (!i) return;
943
- const s = `${C}/upload?name=${encodeURIComponent(o.name)}`, x = `cm_${Math.random().toString(36).slice(2)}`;
944
- p.addOptimistic(x, { kind: "text", text: `📎 Uploading ${o.name}…` }), A.render(p);
973
+ if (!s) return;
974
+ const r = `${v}/upload?name=${encodeURIComponent(o.name)}`, m = `cm_${Math.random().toString(36).slice(2)}`;
975
+ p.addOptimistic(m, { kind: "text", text: `📎 Uploading ${o.name}…` }), q.render(p);
945
976
  try {
946
- const R = await fetch(s, {
977
+ const M = await fetch(r, {
947
978
  method: "POST",
948
979
  // Use the resolved connection token (a signed JWT, an explicit userId,
949
980
  // or the anonymous persistent uid) — NOT just opts.token. The server
950
981
  // requires an Authorization header, and the verifier accepts an
951
982
  // anonymous id as a guest; keying off opts.token alone meant anonymous
952
983
  // visitors (the common case) sent no auth and every upload 401'd.
953
- headers: { "content-type": o.type, authorization: `Bearer ${a}` },
984
+ headers: { "content-type": o.type, authorization: `Bearer ${c}` },
954
985
  body: o
955
986
  });
956
- if (!R.ok) throw new Error(`Upload failed: ${R.status}`);
957
- const { url: G, name: K, mime: X, size: Q } = await R.json();
958
- p.addOptimistic(x, { kind: "attachment", url: G, name: K, mime: X, size: Q }), A.render(p), y.send({ type: "send", conversationId: i, clientMsgId: x, content: { kind: "attachment", url: G, name: K, mime: X, size: Q } });
959
- } catch (R) {
960
- p.addOptimistic(x, { kind: "text", text: `⚠️ Upload failed: ${R.message}` }), A.render(p);
987
+ if (!M.ok) throw new Error(`Upload failed: ${M.status}`);
988
+ const { url: K, name: V, mime: J, size: Z } = await M.json();
989
+ p.addOptimistic(m, { kind: "attachment", url: K, name: V, mime: J, size: Z }), q.render(p), h.send({ type: "send", conversationId: s, clientMsgId: m, content: { kind: "attachment", url: K, name: V, mime: J, size: Z } });
990
+ } catch (M) {
991
+ p.addOptimistic(m, { kind: "text", text: `⚠️ Upload failed: ${M.message}` }), q.render(p);
961
992
  }
962
993
  },
963
- onInvoke(o, s) {
964
- i && y.send({ type: "invoke", conversationId: i, actionId: o, clientInvokeId: `iv_${Math.random().toString(36).slice(2)}`, ...s ? { inputs: s } : {} });
994
+ onInvoke(o, r) {
995
+ s && h.send({ type: "invoke", conversationId: s, actionId: o, clientInvokeId: `iv_${Math.random().toString(36).slice(2)}`, ...r ? { inputs: r } : {} });
965
996
  },
966
- onTyping(o, s) {
967
- i && y.send({ type: "typing", conversationId: i, isTyping: o, ...s ? { preview: s } : {} });
997
+ onTyping(o, r) {
998
+ s && h.send({ type: "typing", conversationId: s, isTyping: o, ...r ? { preview: r } : {} });
968
999
  },
969
1000
  onPreChat(o) {
970
1001
  try {
971
- localStorage.setItem(ce, "1");
1002
+ localStorage.setItem(re, "1");
972
1003
  } catch {
973
1004
  }
974
- y.send({
1005
+ h.send({
975
1006
  type: "open",
976
1007
  profileId: t.profileId,
977
1008
  ...t.subjectId ? { subjectId: t.subjectId } : {},
@@ -984,47 +1015,47 @@ function at(t) {
984
1015
  } } : {}
985
1016
  }
986
1017
  });
987
- const s = o.callback ? `📞 Call-back requested${o.phone ? `: ${o.phone}` : ""}${o.topic ? ` — ${o.topic}` : ""}` : o.topic ? `Topic: ${o.topic}` : "";
988
- s && i && !p.e2e && y.send({ type: "send", conversationId: i, clientMsgId: `pc_${Math.random().toString(36).slice(2, 12)}`, content: { kind: "text", text: s } });
1018
+ const r = o.callback ? `📞 Call-back requested${o.phone ? `: ${o.phone}` : ""}${o.topic ? ` — ${o.topic}` : ""}` : o.topic ? `Topic: ${o.topic}` : "";
1019
+ r && s && !p.e2e && h.send({ type: "send", conversationId: s, clientMsgId: `pc_${Math.random().toString(36).slice(2, 12)}`, content: { kind: "text", text: r } });
989
1020
  },
990
- ...((le = t.features) == null ? void 0 : le.deflection) !== !1 ? {
1021
+ ...((pe = t.features) == null ? void 0 : pe.deflection) !== !1 ? {
991
1022
  onDeflectQuery(o) {
992
- if (c) return;
993
- clearTimeout(l);
994
- const s = o.trim();
995
- if (s.length < 3) {
996
- A.hideDeflection();
1023
+ if (l) return;
1024
+ clearTimeout(d);
1025
+ const r = o.trim();
1026
+ if (r.length < 3) {
1027
+ q.hideDeflection();
997
1028
  return;
998
1029
  }
999
- l = setTimeout(() => {
1000
- fetch(`${C}/kb/search?profileId=${encodeURIComponent(t.profileId)}&q=${encodeURIComponent(s.slice(0, 200))}`).then((x) => x.ok ? x.json() : { articles: [] }).then((x) => A.showDeflection(x.articles ?? [])).catch(() => A.hideDeflection());
1030
+ d = setTimeout(() => {
1031
+ fetch(`${v}/kb/search?profileId=${encodeURIComponent(t.profileId)}&q=${encodeURIComponent(r.slice(0, 200))}`).then((m) => m.ok ? m.json() : { articles: [] }).then((m) => q.showDeflection(m.articles ?? [])).catch(() => q.hideDeflection());
1001
1032
  }, 350);
1002
1033
  }
1003
1034
  } : {},
1004
1035
  onReadUpTo(o) {
1005
- i && y.send({ type: "read", conversationId: i, seq: o });
1036
+ s && h.send({ type: "read", conversationId: s, seq: o });
1006
1037
  },
1007
1038
  onLoadMore() {
1008
- if (!i || !p.e2e) return;
1039
+ if (!s || !p.e2e) return;
1009
1040
  const o = p.messages()[0];
1010
- o && y.send({ type: "history", conversationId: i, beforeSeq: o.seq, limit: 20 });
1041
+ o && h.send({ type: "history", conversationId: s, beforeSeq: o.seq, limit: 20 });
1011
1042
  },
1012
- onEdit(o, s) {
1013
- i && y.send({ type: "edit", conversationId: i, messageId: o, content: { kind: "text", text: s } });
1043
+ onEdit(o, r) {
1044
+ s && h.send({ type: "edit", conversationId: s, messageId: o, content: { kind: "text", text: r } });
1014
1045
  },
1015
1046
  onDelete(o) {
1016
- i && y.send({ type: "delete", conversationId: i, messageId: o });
1047
+ s && h.send({ type: "delete", conversationId: s, messageId: o });
1017
1048
  },
1018
- ...((de = t.features) == null ? void 0 : de.reactions) !== !1 ? {
1019
- onReact(o, s, x) {
1020
- i && y.send({ type: "react", conversationId: i, messageId: o, emoji: s, remove: x });
1049
+ ...((he = t.features) == null ? void 0 : he.reactions) !== !1 ? {
1050
+ onReact(o, r, m) {
1051
+ s && h.send({ type: "react", conversationId: s, messageId: o, emoji: r, remove: m });
1021
1052
  }
1022
1053
  } : {},
1023
- ...((pe = t.features) == null ? void 0 : pe.csat) !== !1 ? {
1054
+ ...((ue = t.features) == null ? void 0 : ue.csat) !== !1 ? {
1024
1055
  onCsat(o) {
1025
- i && fetch(`${C}/conversations/${i}/csat`, {
1056
+ s && fetch(`${v}/conversations/${s}/csat`, {
1026
1057
  method: "POST",
1027
- headers: { "Content-Type": "application/json", Authorization: `Bearer ${a}` },
1058
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${c}` },
1028
1059
  body: JSON.stringify({ score: o })
1029
1060
  }).catch(() => {
1030
1061
  });
@@ -1033,14 +1064,14 @@ function at(t) {
1033
1064
  ...t.translateLang ? {
1034
1065
  async onTranslate(o) {
1035
1066
  try {
1036
- const s = await fetch(`${C}/translate`, {
1067
+ const r = await fetch(`${v}/translate`, {
1037
1068
  method: "POST",
1038
- headers: { "content-type": "application/json", authorization: `Bearer ${a}` },
1069
+ headers: { "content-type": "application/json", authorization: `Bearer ${c}` },
1039
1070
  body: JSON.stringify({ text: o, targetLang: t.translateLang })
1040
1071
  });
1041
- if (!s.ok) return null;
1042
- const { translated: x } = await s.json();
1043
- return x;
1072
+ if (!r.ok) return null;
1073
+ const { translated: m } = await r.json();
1074
+ return m;
1044
1075
  } catch {
1045
1076
  return null;
1046
1077
  }
@@ -1054,89 +1085,94 @@ function at(t) {
1054
1085
  ...t.accent2 ? { accent2: t.accent2 } : {},
1055
1086
  ...t.theme ? { theme: t.theme } : {},
1056
1087
  ...t.webfont === !1 ? { webfont: !1 } : {},
1057
- ...(he = t.user) != null && he.name || (ue = t.user) != null && ue.avatar ? { userInfo: { ...t.user.name ? { name: t.user.name } : {}, ...t.user.avatar ? { avatar: t.user.avatar } : {} } } : {},
1058
- i18n: Ie
1088
+ ...(fe = t.user) != null && fe.name || (we = t.user) != null && we.avatar ? { userInfo: { ...t.user.name ? { name: t.user.name } : {}, ...t.user.avatar ? { avatar: t.user.avatar } : {} } } : {},
1089
+ i18n: Ee
1059
1090
  });
1060
1091
  try {
1061
- localStorage.getItem(ce) && A.completePreChat();
1092
+ localStorage.getItem(re) && q.completePreChat();
1062
1093
  } catch {
1063
1094
  }
1064
- const re = t.user && (t.user.name || t.user.email || t.user.avatar || t.user.meta) ? {
1095
+ const le = t.user && (t.user.name || t.user.email || t.user.avatar || t.user.meta) ? {
1065
1096
  ...t.user.name ? { name: t.user.name } : {},
1066
1097
  ...t.user.email ? { email: t.user.email } : {},
1067
1098
  ...t.user.avatar ? { avatar: t.user.avatar } : {},
1068
1099
  ...t.user.meta ? { meta: t.user.meta } : {}
1069
- } : void 0, je = {
1100
+ } : void 0, Le = {
1070
1101
  type: "open",
1071
1102
  profileId: t.profileId,
1072
1103
  // Direct conversations use the kind/peerId pair; the dm:… subject key is
1073
1104
  // server-derived and owner-keyed, so passing it as subjectId from the
1074
1105
  // NON-owner side would find-or-create a junk duplicate thread.
1075
1106
  ...t.kind === "direct" && t.peerId ? { kind: "direct", peerId: t.peerId } : t.subjectId ? { subjectId: t.subjectId } : {},
1076
- ...f ? { linkFrom: f } : {},
1077
- ...re ? { userInfo: re } : {},
1107
+ ...w ? { linkFrom: w } : {},
1108
+ ...le ? { userInfo: le } : {},
1078
1109
  ...typeof location < "u" ? { pageUrl: location.href } : {},
1079
1110
  ...typeof document < "u" && document.title ? { pageTitle: document.title } : {},
1080
1111
  // Pass subject display info so the server can persist it to the Subject record.
1081
1112
  // This is how listingTitle and listingMeta get saved without a separate API call.
1082
- ...(fe = t.subject) != null && fe.title ? { subjectTitle: t.subject.title } : {},
1083
- ...(we = t.subject) != null && we.subtitle ? { subjectMeta: t.subject.subtitle } : {}
1113
+ ...(be = t.subject) != null && be.title ? { subjectTitle: t.subject.title } : {},
1114
+ ...(xe = t.subject) != null && xe.subtitle ? { subjectMeta: t.subject.subtitle } : {}
1084
1115
  };
1085
- y = new De({
1116
+ h = new De({
1086
1117
  ...t.refreshToken ? { refreshToken: t.refreshToken } : {},
1087
- url: w,
1088
- token: a,
1089
- open: je,
1118
+ url: b,
1119
+ token: c,
1120
+ open: Le,
1090
1121
  getCursor: () => p.highestSeq(),
1091
- onStatusChange: (o, s) => A.setConnStatus(o, s),
1122
+ onStatusChange: (o, r) => q.setConnStatus(o, r),
1092
1123
  onFrame(o) {
1093
1124
  if (o.type === "opened") {
1094
- if (i = o.conversation.id, !P) {
1095
- P = !0;
1096
- for (const s of m.load())
1097
- y.send({ type: "send", conversationId: i, clientMsgId: s.clientMsgId, content: s.content });
1125
+ if (s = o.conversation.id, !$) {
1126
+ $ = !0;
1127
+ for (const r of g.load())
1128
+ h.send({ type: "send", conversationId: s, clientMsgId: r.clientMsgId, content: r.content });
1098
1129
  }
1099
- Ae(w, a, i, p, A, C), g.length && $(i);
1130
+ qe(b, c, s, p, q, v), i.length && y(s);
1100
1131
  }
1101
- if (o.type === "ack" && m.remove(o.clientMsgId), o.type === "prekeyBundle") {
1102
- o.bundle && (D = !0, S.x3dhSendTo(o.bundle).then((s) => {
1103
- const x = [...M.splice(0), ...v.splice(0)];
1104
- for (const R of x) Ce(R.clientMsgId, R.text, s);
1105
- A.render(p);
1132
+ if (o.type === "ack" && g.remove(o.clientMsgId), o.type === "prekeyBundle") {
1133
+ o.bundle && (T = !0, x.x3dhSendTo(o.bundle).then((r) => {
1134
+ const m = [...E.splice(0), ...f.splice(0)];
1135
+ for (const M of m) D(M.clientMsgId, M.text, r);
1136
+ q.render(p);
1106
1137
  }));
1107
1138
  return;
1108
1139
  }
1109
1140
  if (o.type === "message" && p.e2e) {
1110
- const s = _e(o.message.content);
1111
- if (s && !S.ready) {
1112
- S.x3dhReceiveFrom(s.x3dhIK, s.x3dhEK, s.x3dhSPK, s.x3dhOTP).then(async () => {
1113
- await S.openFrame(o), p.apply(o), A.render(p);
1141
+ const r = _e(o.message.content);
1142
+ if (r && !x.ready) {
1143
+ x.x3dhReceiveFrom(r.x3dhIK, r.x3dhEK, r.x3dhSPK, r.x3dhOTP).then(async () => {
1144
+ await x.openFrame(o), p.apply(o), q.render(p);
1114
1145
  });
1115
1146
  return;
1116
1147
  }
1117
1148
  }
1118
1149
  if (o.type === "peerkey") {
1119
- S.onPeerKey(o.key).then(() => {
1120
- Te(), A.render(p);
1150
+ x.onPeerKey(o.key).then(() => {
1151
+ X(), q.render(p);
1121
1152
  });
1122
1153
  return;
1123
1154
  }
1124
1155
  (async () => {
1125
- if (p.e2e && await S.openFrame(o), p.apply(o), o.type === "manifest" && (z == null || z()), o.type === "message" && o.message.senderId !== a && !o.message.internal && (k(), u()), p.e2e && i && !N) {
1126
- N = !0;
1127
- const s = await S.initX3DH();
1128
- y.send({ type: "uploadPrekeys", ...s });
1129
- const x = await S.begin();
1130
- y.send({ type: "pubkey", conversationId: i, key: x });
1156
+ if (p.e2e && await x.openFrame(o), p.apply(o), o.type === "manifest") {
1157
+ j == null || j();
1158
+ const r = o.botName;
1159
+ r && q.setBotName(r);
1160
+ }
1161
+ if (o.type === "message" && o.message.senderId !== c && !o.message.internal && (_(), a()), p.e2e && s && !k) {
1162
+ k = !0;
1163
+ const r = await x.initX3DH();
1164
+ h.send({ type: "uploadPrekeys", ...r });
1165
+ const m = await x.begin();
1166
+ h.send({ type: "pubkey", conversationId: s, key: m });
1131
1167
  }
1132
- A.render(p);
1168
+ q.render(p);
1133
1169
  })();
1134
1170
  }
1135
- }), y.connect(), A.render(p);
1136
- const W = t.launcher ? ke(t) : null, Y = { close: () => {
1137
- c = !0, clearTimeout(l), y.close(), j == null || j.remove(), A.destroy(), B && I && B.removeEventListener("change", I), q && (document.removeEventListener("keydown", q), q = null), U.delete(t.el), W && ee.get(W) === Y && ee.delete(W);
1171
+ }), h.connect(), q.render(p);
1172
+ const G = t.launcher ? Te(t) : null, Q = { close: () => {
1173
+ l = !0, clearTimeout(d), h.close(), P == null || P.remove(), q.destroy(), R && I && R.removeEventListener("change", I), A && (document.removeEventListener("keydown", A), A = null), F.delete(t.el), G && ne.get(G) === Q && ne.delete(G);
1138
1174
  } };
1139
- return U.set(t.el, Y), W && ee.set(W, Y), Y;
1175
+ return F.set(t.el, Q), G && ne.set(G, Q), Q;
1140
1176
  }
1141
1177
  export {
1142
1178
  Oe as ChatStore,
@@ -1146,10 +1182,10 @@ export {
1146
1182
  Xe as Renderer,
1147
1183
  dt as asConversationId,
1148
1184
  _e as extractX3DHInit,
1149
- st as httpBaseFromWsUrl,
1185
+ rt as httpBaseFromWsUrl,
1150
1186
  at as mount,
1151
- qe as resolveRelayUrls,
1152
- Ae as restoreHistory,
1187
+ Ae as resolveRelayUrls,
1188
+ qe as restoreHistory,
1153
1189
  it as unmount
1154
1190
  };
1155
1191
  //# sourceMappingURL=index.js.map