@paramms/chat-widget 1.0.48 → 1.6.0

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