@spilki/widget 1.0.34 → 1.0.35

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.
@@ -137,27 +137,27 @@ function z(r) {
137
137
  function _(r = "msg") {
138
138
  return typeof crypto != "undefined" && crypto.randomUUID ? crypto.randomUUID() : `${r}-${Math.random().toString(16).slice(2)}`;
139
139
  }
140
- function G() {
140
+ function q() {
141
141
  var r, e;
142
142
  return (e = (r = window.matchMedia) == null ? void 0 : r.call(window, "(prefers-color-scheme: dark)").matches) != null ? e : !1;
143
143
  }
144
144
  function P(r) {
145
- return r === "light" || r === "dark" ? r : G() ? "dark" : "light";
145
+ return r === "light" || r === "dark" ? r : q() ? "dark" : "light";
146
146
  }
147
147
  function S(r, e = 30) {
148
148
  return r.slice(-e);
149
149
  }
150
- function q(r) {
150
+ function G(r) {
151
151
  if (!r || r.length === 0) return;
152
152
  const e = window.location.origin;
153
153
  r.includes(e) || console.warn(
154
154
  `SpilkiWidget: current origin ${e} not in allowedOriginsHint: ${r.join(", ")}`
155
155
  );
156
156
  }
157
- const Y = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
158
- function V(r) {
157
+ const V = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
158
+ function Y(r) {
159
159
  const e = new Date(r), t = /* @__PURE__ */ new Date(), s = (a) => String(a).padStart(2, "0"), i = `${s(e.getHours())}:${s(e.getMinutes())}`, o = new Date(t.getFullYear(), t.getMonth(), t.getDate()).getTime(), l = o - 864e5, n = new Date(e.getFullYear(), e.getMonth(), e.getDate()).getTime();
160
- return n === o ? `Today at ${i}` : n === l ? `Yesterday at ${i}` : `${Y[e.getMonth()]} ${e.getDate()}, ${i}`;
160
+ return n === o ? `Today at ${i}` : n === l ? `Yesterday at ${i}` : `${V[e.getMonth()]} ${e.getDate()}, ${i}`;
161
161
  }
162
162
  const J = ':host{--spilki-bg-light: #ffffff;--spilki-bg-dark: #0f172a;--spilki-text-light: #0f172a;--spilki-text-dark: #f8fafc;--spilki-border-light: rgba(15, 23, 42, .1);--spilki-border-dark: rgba(148, 163, 184, .25);--spilki-muted-light: #64748b;--spilki-muted-dark: #94a3b8;--spilki-shadow: 0 10px 40px rgba(15, 23, 42, .2);--spilki-radius: 16px;--spilki-font: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;color:inherit;font-family:var(--spilki-font)}.wrapper{position:relative;width:100%;height:100%;display:flex;flex-direction:column;background:var(--spilki-surface);color:var(--spilki-text);border-radius:var(--spilki-radius);box-shadow:var(--spilki-shadow);border:1px solid var(--spilki-border);overflow:hidden}header{display:flex;align-items:center;justify-content:space-between;padding:.75rem 1rem;background:var(--spilki-surface);border-bottom:1px solid var(--spilki-border)}header h1{font-size:1rem;margin:0;display:flex;align-items:center;gap:.5rem}header button.close{border:none;background:transparent;color:inherit;font-size:1.25rem;cursor:pointer}header button.close:focus-visible{outline:2px solid var(--spilki-accent);outline-offset:2px;border-radius:4px}header .status-dot{width:10px;height:10px;border-radius:999px;background:var(--spilki-accent)}.messages{flex:1;overflow-y:auto;padding:1rem;display:flex;flex-direction:column;gap:.75rem;scrollbar-width:thin;scrollbar-color:rgba(148,163,184,.3) transparent;scroll-behavior:smooth}.message{display:flex;flex-direction:column;gap:.15rem;max-width:85%;width:fit-content;line-height:1.4;word-wrap:break-word;overflow-wrap:anywhere;white-space:pre-wrap}.message.user{align-self:flex-end;align-items:flex-end}.message .bubble{padding:.6rem .8rem;border-radius:1rem;background:#6366f126}.message.user .bubble{background:var(--spilki-accent);color:#fff}.message.bot .bubble{background:#94a3b826}.msg-time{font-size:.7rem;color:var(--spilki-muted);margin-top:2px}.date-separator{display:flex;align-items:center;gap:.5rem;padding:.4rem 0;font-size:.72rem;color:var(--spilki-muted);white-space:nowrap}.date-separator:before,.date-separator:after{content:"";flex:1;height:1px;background:var(--spilki-border)}.scroll-bottom{position:absolute;right:1rem;bottom:88px;width:38px;height:38px;border:none;border-radius:999px;background:var(--spilki-accent);color:#fff;box-shadow:0 8px 20px #0f172a40;cursor:pointer;opacity:0;pointer-events:none;transform:translateY(4px);transition:opacity .18s ease,transform .18s ease;z-index:3}.scroll-bottom.visible{opacity:1;pointer-events:auto;transform:translateY(0)}.scroll-arrow{font-size:.8rem;line-height:1}.scroll-count{position:absolute;top:-5px;right:-5px;min-width:16px;height:16px;border-radius:999px;background:#ef4444;color:#fff;font-size:10px;line-height:16px;text-align:center;padding:0 4px}.suggested-replies{display:flex;flex-wrap:wrap;gap:.4rem;padding:.5rem 1rem;border-top:1px solid var(--spilki-border)}.suggested-chip{border:1px solid var(--spilki-accent);background:transparent;color:var(--spilki-accent);border-radius:999px;padding:.35rem .75rem;font-size:.8rem;font-family:inherit;cursor:pointer;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;transition:background .15s,color .15s}.suggested-chip:hover{background:var(--spilki-accent);color:#fff}.suggested-chip:focus-visible{outline:2px solid var(--spilki-accent);outline-offset:2px}.input-area{padding:.5rem .75rem}.input-wrap{display:flex;align-items:center;border:1px solid var(--spilki-border);border-radius:1.5rem;background:transparent;padding-left:0}.input-area textarea{flex:1;resize:none;min-height:2.4rem;max-height:6rem;border:0;border-radius:0;outline:0;background:transparent;box-shadow:none;-webkit-box-shadow:none;-webkit-appearance:none;appearance:none;padding:.55rem 0 .55rem 1rem;font-family:inherit;font-size:.95rem;color:var(--spilki-text);scrollbar-width:thin;scrollbar-color:rgba(148,163,184,.3) transparent}.input-actions{display:flex;align-items:center;gap:.25rem;padding:.25rem .35rem;flex-shrink:0}.input-actions button{width:32px;height:32px;display:grid;place-items:center;border:none;border-radius:50%;cursor:pointer;padding:0;transition:opacity .15s}.emoji-btn{background:#6366f126;color:var(--spilki-accent)}.emoji-btn:hover{background:#6366f140}.emoji-btn:focus-visible{outline:2px solid var(--spilki-accent);outline-offset:1px}.send-btn{background:var(--spilki-accent);color:#fff}.send-btn:hover{opacity:.85}.send-btn:focus-visible{outline:2px solid var(--spilki-accent);outline-offset:2px}.emoji-picker{position:absolute;right:1rem;bottom:80px;width:240px;max-height:180px;overflow-y:auto;display:none;grid-template-columns:repeat(10,minmax(0,1fr));gap:.25rem;padding:.5rem;background:var(--spilki-surface);border:1px solid var(--spilki-border);border-radius:12px;box-shadow:0 14px 30px #0f172a40;z-index:4}.emoji-option{width:100%;aspect-ratio:1;border:none;border-radius:8px;background:transparent;font-size:1rem;cursor:pointer}.emoji-option:hover,.emoji-option:focus-visible{background:#94a3b833}.typing{font-size:.75rem;color:var(--spilki-muted);padding:0 1rem .75rem}.typing:after{content:"";animation:dots 1.2s steps(4,end) infinite}@keyframes dots{0%{content:""}25%{content:"."}50%{content:".."}75%{content:"..."}}.offline{font-size:.8rem;padding:0 1rem;color:#f97316}:host([data-theme="dark"]){--spilki-surface: var(--spilki-bg-dark);--spilki-text: var(--spilki-text-dark);--spilki-border: var(--spilki-border-dark);--spilki-muted: var(--spilki-muted-dark)}:host([data-theme="dark"]) .messages,:host([data-theme="dark"]) .input-area textarea,:host([data-theme="dark"]) .emoji-picker{scrollbar-color:rgba(255,255,255,.2) transparent}:host([data-theme="light"]){--spilki-surface: var(--spilki-bg-light);--spilki-text: var(--spilki-text-light);--spilki-border: var(--spilki-border-light);--spilki-muted: var(--spilki-muted-light)}:host([data-theme="dark"]) .message .bubble{background:#94a3b81f}:host([data-theme="dark"]) .message.bot .bubble{background:#6366f126}:host([data-theme="dark"]) .input-area textarea{background:transparent}.messages::-webkit-scrollbar,.input-area textarea::-webkit-scrollbar,.emoji-picker::-webkit-scrollbar{width:6px}.messages::-webkit-scrollbar-track,.input-area textarea::-webkit-scrollbar-track,.emoji-picker::-webkit-scrollbar-track{background:transparent}.messages::-webkit-scrollbar-thumb,.input-area textarea::-webkit-scrollbar-thumb,.emoji-picker::-webkit-scrollbar-thumb{background:#94a3b84d;border-radius:999px}.messages::-webkit-scrollbar-thumb:hover,.input-area textarea::-webkit-scrollbar-thumb:hover,.emoji-picker::-webkit-scrollbar-thumb:hover{background:#94a3b880}:host([data-theme="dark"]) .messages::-webkit-scrollbar-thumb,:host([data-theme="dark"]) .input-area textarea::-webkit-scrollbar-thumb,:host([data-theme="dark"]) .emoji-picker::-webkit-scrollbar-thumb{background:#fff3}:host([data-theme="dark"]) .messages::-webkit-scrollbar-thumb:hover,:host([data-theme="dark"]) .input-area textarea::-webkit-scrollbar-thumb:hover,:host([data-theme="dark"]) .emoji-picker::-webkit-scrollbar-thumb:hover{background:#ffffff59}.conversation-separator{display:flex;align-items:center;gap:.5rem;padding:.5rem 0;cursor:pointer;user-select:none;font-size:.7rem;color:var(--spilki-muted);white-space:nowrap}.conversation-separator:before,.conversation-separator:after{content:"";flex:1;height:1px;background:var(--spilki-border)}.conversation-separator:hover{color:var(--spilki-text)}.conversation-separator:focus-visible{outline:2px solid var(--spilki-accent);outline-offset:2px;border-radius:4px}.conversation-history{display:none;flex-direction:column;gap:.5rem}.conversation-history.expanded{display:flex}', D = 24 * 60 * 60 * 1e3, X = 2 * 60 * 1e3, Z = 200, Q = [
163
163
  "😀",
@@ -211,7 +211,7 @@ const J = ':host{--spilki-bg-light: #ffffff;--spilki-bg-dark: #0f172a;--spilki-t
211
211
  "☕",
212
212
  "🍕"
213
213
  ];
214
- function x(r) {
214
+ function E(r) {
215
215
  return r.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
216
216
  }
217
217
  class ee {
@@ -229,7 +229,7 @@ class ee {
229
229
  day: "numeric",
230
230
  year: "numeric"
231
231
  }), this.renderedMessages = [], this.focusable = [], this.seenIds = /* @__PURE__ */ new Set(), this.lastTimelineMessage = null, this.scrollUnreadCount = 0, this.emojiPickerOpen = !1, this.open = !1, this.host = document.createElement("div"), this.host.setAttribute("part", "panel-root"), this.host.style.position = "fixed", this.host.style.bottom = "96px", this.host.style[e.position === "bottom-right" ? "right" : "left"] = "24px", this.host.style.width = "360px", this.host.style.maxWidth = "calc(100vw - 32px)", this.host.style.height = "520px", this.host.style.display = "none", this.host.style.zIndex = "2147483001", this.shadow = this.host.attachShadow({ mode: "open" });
232
- const t = x(e.i18n.title), s = x(e.i18n.typing), i = x(e.i18n.offline), o = x(e.i18n.placeholder), l = x(e.i18n.sendLabel);
232
+ const t = E(e.i18n.title), s = E(e.i18n.typing), i = E(e.i18n.offline), o = E(e.i18n.placeholder), l = E(e.i18n.sendLabel);
233
233
  this.shadow.innerHTML = `
234
234
  <style>${J}</style>
235
235
  <div class="wrapper" role="dialog" aria-modal="true" aria-label="${t}">
@@ -395,7 +395,7 @@ class ee {
395
395
  }
396
396
  createSeparatorElement(e, t) {
397
397
  const s = document.createElement("div");
398
- s.className = "conversation-separator", s.setAttribute("role", "button"), s.setAttribute("tabindex", "0"), s.setAttribute("aria-expanded", "false"), s.setAttribute("aria-label", "Show previous conversation"), s.textContent = V(e);
398
+ s.className = "conversation-separator", s.setAttribute("role", "button"), s.setAttribute("tabindex", "0"), s.setAttribute("aria-expanded", "false"), s.setAttribute("aria-label", "Show previous conversation"), s.textContent = Y(e);
399
399
  const i = () => {
400
400
  const o = t.classList.toggle("expanded");
401
401
  s.setAttribute("aria-expanded", String(o)), s.setAttribute(
@@ -693,18 +693,18 @@ class te {
693
693
  const l = o.body.getReader(), n = new TextDecoder();
694
694
  let a = "";
695
695
  const g = () => {
696
- l.read().then(({ done: u, value: d }) => {
696
+ l.read().then(({ done: u, value: h }) => {
697
697
  var m;
698
698
  if (u || this.stopped) {
699
699
  this.stopped || (this.handlers.onError(new Error("SpilkiWidget: SSE stream ended")), this.retryFallback("sse"));
700
700
  return;
701
701
  }
702
- a += n.decode(d, { stream: !0 });
703
- const h = a.split(`
702
+ a += n.decode(h, { stream: !0 });
703
+ const d = a.split(`
704
704
 
705
705
  `);
706
- a = (m = h.pop()) != null ? m : "";
707
- for (const f of h)
706
+ a = (m = d.pop()) != null ? m : "";
707
+ for (const f of d)
708
708
  for (const p of f.split(`
709
709
  `))
710
710
  p.startsWith("data:") && this.handleIncoming(p.slice(5).trim());
@@ -773,12 +773,12 @@ const se = /* @__PURE__ */ new Set(["TYPING", "THINKING", "SEARCHING", "EXECUTIN
773
773
  function ie(r) {
774
774
  if (typeof r != "object" || r === null) return !1;
775
775
  const e = r;
776
- return se.has(e.eventType) && typeof e.active == "boolean";
776
+ return se.has(e.eventType);
777
777
  }
778
778
  const U = 30 * 60 * 1e3, re = 3e4, A = 30;
779
779
  class oe {
780
780
  constructor(e, t) {
781
- this.org = e, this.listeners = /* @__PURE__ */ new Set(), this.activityTimer = null, this.activeEvents = /* @__PURE__ */ new Set(), this.state = {
781
+ this.org = e, this.listeners = /* @__PURE__ */ new Set(), this.activityTimer = null, this.state = {
782
782
  isOpen: !1,
783
783
  agentActivity: null,
784
784
  isConnected: !1,
@@ -802,27 +802,16 @@ class oe {
802
802
  close() {
803
803
  this.state.isOpen && (this.state.isOpen = !1, this.emit());
804
804
  }
805
- handleAgentEvent(e, t) {
806
- t ? this.activeEvents.add(e) : this.activeEvents.delete(e), this.updateDisplayedActivity();
805
+ handleAgentEvent(e) {
806
+ this.activityTimer && (clearTimeout(this.activityTimer), this.activityTimer = null), this.activityTimer = setTimeout(() => {
807
+ this.state.agentActivity = null, this.activityTimer = null, this.emit();
808
+ }, re), this.state.agentActivity !== e && (this.state.agentActivity = e, this.emit());
807
809
  }
808
- setTyping(e) {
809
- this.handleAgentEvent("TYPING", e);
810
- }
811
- updateDisplayedActivity() {
812
- this.activityTimer && (clearTimeout(this.activityTimer), this.activityTimer = null), this.activeEvents.size > 0 && (this.activityTimer = setTimeout(() => {
813
- this.activeEvents.clear(), this.state.agentActivity = null, this.activityTimer = null, this.emit();
814
- }, re));
815
- const e = this.resolveTopActivity();
816
- this.state.agentActivity !== e && (this.state.agentActivity = e, this.emit());
810
+ clearAgentActivity() {
811
+ this.resetAgentActivity() && this.emit();
817
812
  }
818
- resolveTopActivity() {
819
- var t;
820
- return this.activeEvents.size === 0 ? null : (t = [
821
- "EXECUTING_TOOL",
822
- "SEARCHING",
823
- "THINKING",
824
- "TYPING"
825
- ].find((s) => this.activeEvents.has(s))) != null ? t : null;
813
+ resetAgentActivity() {
814
+ return this.activityTimer && (clearTimeout(this.activityTimer), this.activityTimer = null), this.state.agentActivity === null ? !1 : (this.state.agentActivity = null, !0);
826
815
  }
827
816
  setConnected(e) {
828
817
  this.state.isConnected !== e && (this.state.isConnected = e, this.emit());
@@ -835,7 +824,7 @@ class oe {
835
824
  author: e.author,
836
825
  text: e.text
837
826
  };
838
- return this.state.messages.some((o) => o.id === t.id) ? null : (this.state.messages = S([...this.state.messages, t], A), this.persistMessages(), this.touchActivity(), this.emit(), t);
827
+ return this.state.messages.some((o) => o.id === t.id) ? null : (this.state.messages = S([...this.state.messages, t], A), this.resetAgentActivity(), this.persistMessages(), this.touchActivity(), this.emit(), t);
839
828
  }
840
829
  setMessages(e) {
841
830
  this.state.messages = S(e, A), this.persistMessages(), this.emit();
@@ -1004,7 +993,7 @@ const ce = {
1004
993
  onTransportChange() {
1005
994
  }
1006
995
  };
1007
- async function de(r, e, t) {
996
+ async function he(r, e, t) {
1008
997
  const s = `${r.replace(/\/$/, "")}/widget/install`, i = await fetch(s, {
1009
998
  method: "POST",
1010
999
  headers: { "Content-Type": "application/json", Origin: window.location.origin },
@@ -1013,7 +1002,7 @@ async function de(r, e, t) {
1013
1002
  if (!i.ok) throw new Error(`SpilkiWidget: install failed (${i.status})`);
1014
1003
  return (await i.json()).accessToken;
1015
1004
  }
1016
- async function he(r, e) {
1005
+ async function de(r, e) {
1017
1006
  const t = `${r.replace(/\/$/, "")}/widget/refresh`, s = await fetch(t, {
1018
1007
  method: "POST",
1019
1008
  headers: { "X-Authorization": `Bearer ${e}`, Origin: window.location.origin }
@@ -1057,9 +1046,9 @@ function pe(r) {
1057
1046
  if (!n || n.state !== "running") return;
1058
1047
  const a = n.createGain();
1059
1048
  a.gain.value = 0.15, a.connect(n.destination);
1060
- const g = (d, h, m) => {
1049
+ const g = (h, d, m) => {
1061
1050
  const f = n.createOscillator(), p = n.createGain();
1062
- f.type = "sine", f.frequency.setValueAtTime(d, h), p.gain.setValueAtTime(1e-4, h), p.gain.exponentialRampToValueAtTime(1, h + 0.012), p.gain.exponentialRampToValueAtTime(1e-4, h + m), f.connect(p), p.connect(a), f.start(h), f.stop(h + m + 0.02);
1051
+ f.type = "sine", f.frequency.setValueAtTime(h, d), p.gain.setValueAtTime(1e-4, d), p.gain.exponentialRampToValueAtTime(1, d + 0.012), p.gain.exponentialRampToValueAtTime(1e-4, d + m), f.connect(p), p.connect(a), f.start(d), f.stop(d + m + 0.02);
1063
1052
  }, u = n.currentTime;
1064
1053
  g(880, u, 0.08), g(1175, u + 0.09, 0.08);
1065
1054
  },
@@ -1076,7 +1065,7 @@ function $(r) {
1076
1065
  if (!r.org)
1077
1066
  throw new Error("SpilkiWidget: org is required");
1078
1067
  const e = z(r);
1079
- q(e.allowedOriginsHint);
1068
+ G(e.allowedOriginsHint);
1080
1069
  const t = { ...ce, ...(O = e.hooks) != null ? O : {} }, s = new oe(e.org, { persist: e.persist }), i = pe(e.sound);
1081
1070
  let o = (M = s.accessToken) != null ? M : void 0, l = null;
1082
1071
  const n = () => {
@@ -1087,7 +1076,7 @@ function $(r) {
1087
1076
  try {
1088
1077
  if (o && le(o))
1089
1078
  try {
1090
- o = await he(e.apiBase, o), s.persistAccessToken(o), h.setAccessToken(o);
1079
+ o = await de(e.apiBase, o), s.persistAccessToken(o), d.setAccessToken(o);
1091
1080
  return;
1092
1081
  } catch {
1093
1082
  o = void 0, s.clearAccessToken();
@@ -1095,7 +1084,7 @@ function $(r) {
1095
1084
  if (!o) {
1096
1085
  if (!r.installationToken) throw new Error("SpilkiWidget: missing installationToken");
1097
1086
  if (!r.org) throw new Error("SpilkiWidget: missing org");
1098
- o = await de(e.apiBase, r.installationToken, r.org), s.persistAccessToken(o), h.setAccessToken(o);
1087
+ o = await he(e.apiBase, r.installationToken, r.org), s.persistAccessToken(o), d.setAccessToken(o);
1099
1088
  }
1100
1089
  } finally {
1101
1090
  l = null;
@@ -1106,7 +1095,7 @@ function $(r) {
1106
1095
  onClick: () => {
1107
1096
  s.snapshot.isOpen ? (s.close(), t.onClose()) : (i.markUserInteraction(), s.open(), a(), t.onOpen());
1108
1097
  }
1109
- }), d = new ee({
1098
+ }), h = new ee({
1110
1099
  color: e.color,
1111
1100
  theme: P(e.theme),
1112
1101
  position: (j = e.position) != null ? j : "bottom-right",
@@ -1116,11 +1105,11 @@ function $(r) {
1116
1105
  },
1117
1106
  onSend: (c) => {
1118
1107
  const k = s.addMessage({ author: "user", text: c });
1119
- k && (d.appendMessage(k), g().then(() => h.send(c, k.id)).catch((b) => {
1120
- t.onError(b), s.setConnected(!1), d.setOffline(!0);
1108
+ k && (h.appendMessage(k), g().then(() => d.send(c, k.id)).catch((b) => {
1109
+ t.onError(b), s.setConnected(!1), h.setOffline(!0);
1121
1110
  }));
1122
1111
  }
1123
- }), h = new te(
1112
+ }), d = new te(
1124
1113
  {
1125
1114
  apiBase: e.apiBase,
1126
1115
  accessToken: o,
@@ -1129,24 +1118,24 @@ function $(r) {
1129
1118
  },
1130
1119
  {
1131
1120
  onOpen(c) {
1132
- C.transport = c, t.onTransportChange(c), s.setConnected(!0), d.setOffline(!1);
1121
+ C.transport = c, t.onTransportChange(c), s.setConnected(!0), h.setOffline(!1);
1133
1122
  },
1134
1123
  onMessage(c) {
1135
1124
  const b = c.suggestedReplies, y = s.addMessage(c);
1136
- y && (d.appendMessage(y), y.author === "bot" && b && b.length > 0 && d.setSuggestedReplies(b), !s.snapshot.isOpen && y.author === "bot" && (n(), i.play()), t.onMessage(y));
1125
+ y && (h.appendMessage(y), y.author === "bot" && b && b.length > 0 && h.setSuggestedReplies(b), !s.snapshot.isOpen && y.author === "bot" && (n(), i.play()), t.onMessage(y));
1137
1126
  },
1138
- onTyping(c) {
1139
- s.setTyping(c);
1127
+ onTyping() {
1128
+ s.handleAgentEvent("TYPING");
1140
1129
  },
1141
1130
  onAgentEvent(c) {
1142
- s.handleAgentEvent(c.eventType, c.active);
1131
+ s.handleAgentEvent(c.eventType);
1143
1132
  },
1144
1133
  onError(c) {
1145
- t.onError(c), s.setConnected(!1), s.snapshot.isOpen && d.setOffline(!0);
1134
+ t.onError(c), s.setConnected(!1), s.snapshot.isOpen && h.setOffline(!0);
1146
1135
  }
1147
1136
  }
1148
1137
  );
1149
- u.mount(), d.mount();
1138
+ u.mount(), h.mount();
1150
1139
  const m = s.snapshot.messages, f = s.isSessionExpired(), p = s.getConversationGroups();
1151
1140
  if (m.length === 0 && e.welcome) {
1152
1141
  const c = {
@@ -1155,29 +1144,29 @@ function $(r) {
1155
1144
  text: e.welcome,
1156
1145
  ts: Date.now()
1157
1146
  };
1158
- s.addMessage(c), d.appendMessage(c);
1159
- } else f && m.length > 0 ? d.renderWithConversations(p, []) : p.length > 1 ? d.renderWithConversations(p.slice(0, -1), p[p.length - 1].messages) : d.updateMessages(m);
1147
+ s.addMessage(c), h.appendMessage(c);
1148
+ } else f && m.length > 0 ? h.renderWithConversations(p, []) : p.length > 1 ? h.renderWithConversations(p.slice(0, -1), p[p.length - 1].messages) : h.updateMessages(m);
1160
1149
  let T = !1;
1161
1150
  const W = s.subscribe(() => {
1162
1151
  const c = s.snapshot;
1163
- if (u.setOpen(c.isOpen), d.setAgentActivity(c.agentActivity, e.i18n), d.setOffline(!c.isConnected), d.updateTheme(P(e.theme)), c.isOpen) {
1152
+ if (u.setOpen(c.isOpen), h.setAgentActivity(c.agentActivity, e.i18n), h.setOffline(!c.isConnected), h.updateTheme(P(e.theme)), c.isOpen) {
1164
1153
  if (!T) {
1165
1154
  const k = s.countUnread() > 0, b = s.lastReadTs;
1166
- a(), k && d.scrollToFirstUnread(b);
1155
+ a(), k && h.scrollToFirstUnread(b);
1167
1156
  }
1168
- T = !0, d.show();
1157
+ T = !0, h.show();
1169
1158
  } else
1170
- T = !1, d.hide();
1159
+ T = !1, h.hide();
1171
1160
  }), F = m.length === 0 || f;
1172
1161
  n(), g().then(
1173
- () => h.connect().then((c) => {
1162
+ () => d.connect().then((c) => {
1174
1163
  var b, y;
1175
- e.persist && s.persistSession(c.sessionId), s.setConnected(!0), t.onTransportChange((b = h.kind) != null ? b : "ws");
1164
+ e.persist && s.persistSession(c.sessionId), s.setConnected(!0), t.onTransportChange((b = d.kind) != null ? b : "ws");
1176
1165
  const k = (y = c.suggestedReplies) != null ? y : [];
1177
- k.length > 0 && F && d.setSuggestedReplies(k);
1166
+ k.length > 0 && F && h.setSuggestedReplies(k);
1178
1167
  })
1179
1168
  ).catch((c) => {
1180
- t.onError(c), s.setConnected(!1), d.setOffline(!0);
1169
+ t.onError(c), s.setConnected(!1), h.setOffline(!0);
1181
1170
  });
1182
1171
  const C = {
1183
1172
  transport: null,
@@ -1188,10 +1177,10 @@ function $(r) {
1188
1177
  s.close(), t.onClose();
1189
1178
  },
1190
1179
  identify(c) {
1191
- h.setUser(c);
1180
+ d.setUser(c);
1192
1181
  },
1193
1182
  destroy() {
1194
- W(), h.stop(), i.destroy(), u.destroy(), d.destroy(), E === C && (E = null);
1183
+ W(), d.stop(), i.destroy(), u.destroy(), h.destroy(), x === C && (x = null);
1195
1184
  }
1196
1185
  };
1197
1186
  return C;
@@ -1208,7 +1197,7 @@ function N() {
1208
1197
  console.error("SpilkiWidget: data-org and is required for auto init");
1209
1198
  return;
1210
1199
  }
1211
- E = $({
1200
+ x = $({
1212
1201
  org: t,
1213
1202
  installationToken: e.installationToken,
1214
1203
  apiBase: e.apiBase,
@@ -1216,9 +1205,9 @@ function N() {
1216
1205
  theme: (i = e.theme) != null ? i : void 0
1217
1206
  });
1218
1207
  }
1219
- let E = null;
1220
- typeof window != "undefined" && (window.SpilkiWidget = window.SpilkiWidget || {}, window.SpilkiWidget.init = (r) => (E = $(r), E), window.SpilkiWidget.identify = (r) => {
1221
- E ? E.identify(r) : console.warn("SpilkiWidget: call init() before identify()");
1208
+ let x = null;
1209
+ typeof window != "undefined" && (window.SpilkiWidget = window.SpilkiWidget || {}, window.SpilkiWidget.init = (r) => (x = $(r), x), window.SpilkiWidget.identify = (r) => {
1210
+ x ? x.identify(r) : console.warn("SpilkiWidget: call init() before identify()");
1222
1211
  });
1223
1212
  N();
1224
1213
  N();