@aikaara/chat-sdk 0.1.2 → 0.1.4

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/ui.mjs CHANGED
@@ -1,18 +1,15 @@
1
- var u = Object.defineProperty;
2
- var g = (s, t, e) => t in s ? u(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var i = (s, t, e) => g(s, typeof t != "symbol" ? t + "" : t, e);
4
- import { a as m, D as f, e as h, f as x, g as k, h as y, i as v, j as w, k as b, l as T } from "./headless-CXRux2Q-.mjs";
5
- class L {
6
- constructor(t, e) {
7
- i(this, "client");
8
- i(this, "panel");
9
- i(this, "bubble");
10
- i(this, "header");
11
- i(this, "messageList");
12
- i(this, "input");
13
- i(this, "errorBanner");
14
- i(this, "isOpen", !1);
15
- this.client = new m(t), this.bubble = e.querySelector("aikaara-chat-bubble"), this.panel = e.querySelector(".aikaara-panel"), this.header = e.querySelector("aikaara-chat-header"), this.messageList = e.querySelector("aikaara-message-list"), this.input = e.querySelector("aikaara-chat-input"), this.errorBanner = e.querySelector("aikaara-error-banner"), t.welcomeMessage && this.messageList.setWelcomeMessage(t.welcomeMessage), t.showTimestamps !== void 0 && this.messageList.setShowTimestamps(t.showTimestamps), this.wireEvents();
1
+ import { a as p, D as u, e as d, f as g, g as m, h as f, i as x, j as k, k as c, l as y } from "./headless-BhsiNVQj.mjs";
2
+ class v {
3
+ client;
4
+ panel;
5
+ bubble;
6
+ header;
7
+ messageList;
8
+ input;
9
+ errorBanner;
10
+ isOpen = !1;
11
+ constructor(e, t) {
12
+ this.client = new p(e), this.bubble = t.querySelector("aikaara-chat-bubble"), this.panel = t.querySelector(".aikaara-panel"), this.header = t.querySelector("aikaara-chat-header"), this.messageList = t.querySelector("aikaara-message-list"), this.input = t.querySelector("aikaara-chat-input"), this.errorBanner = t.querySelector("aikaara-error-banner"), e.welcomeMessage && this.messageList.setWelcomeMessage(e.welcomeMessage), e.showTimestamps !== void 0 && this.messageList.setShowTimestamps(e.showTimestamps), this.wireEvents();
16
13
  }
17
14
  async connect() {
18
15
  try {
@@ -27,57 +24,54 @@ class L {
27
24
  wireEvents() {
28
25
  this.bubble.addEventListener("toggle", () => {
29
26
  this.togglePanel();
30
- }), this.header.addEventListener("close", () => {
27
+ }), this.header.addEventListener("header-close", () => {
31
28
  this.togglePanel(!1);
32
- }), this.input.addEventListener("send", ((t) => {
33
- this.handleSend(t.detail.content);
34
- })), this.client.on("message:sent", (t) => {
35
- this.messageList.addMessage(t);
29
+ }), this.input.addEventListener("send", ((e) => {
30
+ this.handleSend(e.detail.content);
31
+ })), this.client.on("message:sent", (e) => {
32
+ this.messageList.addMessage(e);
36
33
  }), this.client.on("stream:start", () => {
37
34
  this.messageList.removeTypingIndicator();
38
- const t = this.client.messages[this.client.messages.length - 1];
39
- t && this.messageList.addMessage(t);
40
- }), this.client.on("stream:update", ({ content: t }) => {
41
- this.messageList.updateStreamingContent(t);
35
+ const e = this.client.messages[this.client.messages.length - 1];
36
+ e && this.messageList.addMessage(e);
37
+ }), this.client.on("stream:update", ({ content: e }) => {
38
+ this.messageList.updateStreamingContent(e);
42
39
  }), this.client.on("stream:end", () => {
43
40
  this.messageList.finalizeStreaming();
44
41
  }), this.client.on("typing:start", () => {
45
- const t = this.client.messages, e = t[t.length - 1];
46
- (!e || e.status !== "streaming") && this.messageList.showTypingIndicator();
42
+ const e = this.client.messages, t = e[e.length - 1];
43
+ (!t || t.status !== "streaming") && this.messageList.showTypingIndicator();
47
44
  }), this.client.on("typing:stop", () => {
48
45
  this.messageList.removeTypingIndicator();
49
- }), this.client.on("connection:state", (t) => {
50
- this.header.setStatus(t), t === "connected" ? (this.errorBanner.hide(), this.input.disabled = !1) : t === "reconnecting" ? (this.errorBanner.show("Connection lost. Reconnecting..."), this.input.disabled = !0) : t === "disconnected" && (this.input.disabled = !0);
51
- }), this.client.on("error", (t) => {
52
- this.errorBanner.show(t.message, 5e3);
46
+ }), this.client.on("connection:state", (e) => {
47
+ this.header.setStatus(e), e === "connected" ? (this.errorBanner.hide(), this.input.disabled = !1) : e === "reconnecting" ? (this.errorBanner.show("Connection lost. Reconnecting..."), this.input.disabled = !0) : e === "disconnected" && (this.input.disabled = !0);
48
+ }), this.client.on("error", (e) => {
49
+ this.errorBanner.show(e.message, 5e3);
53
50
  });
54
51
  }
55
- async handleSend(t) {
52
+ async handleSend(e) {
56
53
  try {
57
- await this.client.sendMessage(t);
54
+ await this.client.sendMessage(e);
58
55
  } catch {
59
56
  this.errorBanner.show("Failed to send message", 3e3);
60
57
  }
61
58
  }
62
- togglePanel(t) {
63
- this.isOpen = t !== void 0 ? t : !this.isOpen, this.isOpen ? (this.panel.removeAttribute("hidden"), requestAnimationFrame(() => {
59
+ togglePanel(e) {
60
+ this.isOpen = e !== void 0 ? e : !this.isOpen, this.isOpen ? (this.panel.removeAttribute("hidden"), requestAnimationFrame(() => {
64
61
  this.panel.classList.remove("entering"), this.panel.classList.add("visible"), this.input.focus();
65
62
  })) : (this.panel.classList.remove("visible"), this.panel.classList.add("entering"), setTimeout(() => {
66
63
  this.panel.setAttribute("hidden", "");
67
64
  }, 200));
68
65
  }
69
66
  }
70
- class C extends HTMLElement {
71
- constructor() {
72
- super();
73
- i(this, "shadow");
74
- i(this, "controller", null);
75
- i(this, "_config", {});
76
- this.shadow = this.attachShadow({ mode: "open" });
77
- }
67
+ class w extends HTMLElement {
68
+ shadow;
69
+ controller = null;
70
+ _config = {};
78
71
  static get observedAttributes() {
79
72
  return [
80
73
  "base-url",
74
+ "ws-url",
81
75
  "user-token",
82
76
  "api-key",
83
77
  "title",
@@ -92,15 +86,17 @@ class C extends HTMLElement {
92
86
  "avatar-url"
93
87
  ];
94
88
  }
89
+ constructor() {
90
+ super(), this.shadow = this.attachShadow({ mode: "open" });
91
+ }
95
92
  connectedCallback() {
96
93
  this.render(), this.initController();
97
94
  }
98
95
  disconnectedCallback() {
99
- var e;
100
- (e = this.controller) == null || e.disconnect();
96
+ this.controller?.disconnect();
101
97
  }
102
- attributeChangedCallback(e, a, r) {
103
- a !== r && this.controller && (this.render(), this.initController());
98
+ attributeChangedCallback(e, t, a) {
99
+ t !== a && this.controller && (this.render(), this.initController());
104
100
  }
105
101
  configure(e) {
106
102
  this._config = { ...this._config, ...e };
@@ -108,27 +104,29 @@ class C extends HTMLElement {
108
104
  getConfig() {
109
105
  return {
110
106
  baseUrl: this.getAttribute("base-url") || this._config.baseUrl || "",
107
+ wsUrl: this.getAttribute("ws-url") || this._config.wsUrl,
111
108
  userToken: this.getAttribute("user-token") || this._config.userToken || "",
112
109
  apiKey: this.getAttribute("api-key") || this._config.apiKey,
113
110
  title: this.getAttribute("title") || this._config.title || "Chat",
114
111
  subtitle: this.getAttribute("subtitle") || this._config.subtitle,
115
- theme: this.getAttribute("theme") || this._config.theme || T,
116
- primaryColor: this.getAttribute("primary-color") || this._config.primaryColor || b,
117
- position: this.getAttribute("position") || this._config.position || w,
118
- width: Number(this.getAttribute("width")) || this._config.width || v,
119
- height: Number(this.getAttribute("height")) || this._config.height || y,
120
- fontFamily: this._config.fontFamily || k,
121
- borderRadius: this._config.borderRadius ?? x,
122
- placeholder: this.getAttribute("placeholder") || this._config.placeholder || h,
112
+ theme: this.getAttribute("theme") || this._config.theme || y,
113
+ primaryColor: this.getAttribute("primary-color") || this._config.primaryColor || c,
114
+ position: this.getAttribute("position") || this._config.position || k,
115
+ width: Number(this.getAttribute("width")) || this._config.width || x,
116
+ height: Number(this.getAttribute("height")) || this._config.height || f,
117
+ fontFamily: this._config.fontFamily || m,
118
+ borderRadius: this._config.borderRadius ?? g,
119
+ placeholder: this.getAttribute("placeholder") || this._config.placeholder || d,
123
120
  welcomeMessage: this.getAttribute("welcome-message") || this._config.welcomeMessage,
124
121
  avatarUrl: this.getAttribute("avatar-url") || this._config.avatarUrl,
125
122
  showTimestamps: this._config.showTimestamps ?? !0,
126
123
  persistConversation: this._config.persistConversation ?? !0,
127
124
  showBubble: this._config.showBubble ?? !0,
128
- offset: this._config.offset || f,
125
+ offset: this._config.offset || u,
129
126
  conversationId: this._config.conversationId,
130
127
  systemPromptId: this._config.systemPromptId,
131
128
  channel: this._config.channel,
129
+ extUid: this._config.extUid,
132
130
  onMessage: this._config.onMessage,
133
131
  onStatusChange: this._config.onStatusChange,
134
132
  onError: this._config.onError,
@@ -137,13 +135,12 @@ class C extends HTMLElement {
137
135
  };
138
136
  }
139
137
  render() {
140
- var a, r;
141
138
  const e = this.getConfig();
142
139
  this.shadow.innerHTML = `
143
140
  <style>
144
141
  :host {
145
142
  --aikaara-primary: ${e.primaryColor};
146
- --aikaara-primary-hover: ${this.darkenColor(e.primaryColor || b)};
143
+ --aikaara-primary-hover: ${this.darkenColor(e.primaryColor || c)};
147
144
  --aikaara-bg: #ffffff;
148
145
  --aikaara-bg-secondary: #f9fafb;
149
146
  --aikaara-text: #1f2937;
@@ -154,8 +151,8 @@ class C extends HTMLElement {
154
151
  --aikaara-panel-width: ${e.width}px;
155
152
  --aikaara-panel-height: ${e.height}px;
156
153
  --aikaara-bubble-size: 60px;
157
- --aikaara-offset-x: ${((a = e.offset) == null ? void 0 : a.x) ?? 20}px;
158
- --aikaara-offset-y: ${((r = e.offset) == null ? void 0 : r.y) ?? 20}px;
154
+ --aikaara-offset-x: ${e.offset?.x ?? 20}px;
155
+ --aikaara-offset-y: ${e.offset?.y ?? 20}px;
159
156
  font-family: var(--aikaara-font);
160
157
  position: fixed;
161
158
  z-index: 9999;
@@ -193,6 +190,27 @@ class C extends HTMLElement {
193
190
  opacity: 1;
194
191
  transform: translateY(0) scale(1);
195
192
  }
193
+
194
+ aikaara-chat-header,
195
+ aikaara-message-list,
196
+ aikaara-chat-input,
197
+ aikaara-error-banner {
198
+ display: block;
199
+ }
200
+
201
+ aikaara-message-list {
202
+ flex: 1;
203
+ overflow: scroll;
204
+ min-height: 0;
205
+ }
206
+
207
+ aikaara-chat-input {
208
+ flex-shrink: 0;
209
+ }
210
+
211
+ aikaara-chat-header {
212
+ flex-shrink: 0;
213
+ }
196
214
  </style>
197
215
 
198
216
  <aikaara-chat-bubble></aikaara-chat-bubble>
@@ -204,34 +222,31 @@ class C extends HTMLElement {
204
222
  ${e.avatarUrl ? `avatar-url="${e.avatarUrl}"` : ""}
205
223
  ></aikaara-chat-header>
206
224
  <aikaara-message-list></aikaara-message-list>
207
- <aikaara-chat-input placeholder="${e.placeholder || h}"></aikaara-chat-input>
225
+ <aikaara-chat-input placeholder="${e.placeholder || d}"></aikaara-chat-input>
208
226
  <aikaara-error-banner></aikaara-error-banner>
209
227
  </div>
210
228
  `;
211
229
  }
212
230
  async initController() {
213
- var a;
214
231
  const e = this.getConfig();
215
- !e.baseUrl || !e.userToken || ((a = this.controller) == null || a.disconnect(), this.controller = new L(e, this.shadow), await this.controller.connect());
232
+ !e.baseUrl || !e.userToken || (this.controller?.disconnect(), this.controller = new v(e, this.shadow), await this.controller.connect());
216
233
  }
217
234
  darkenColor(e) {
218
235
  try {
219
- const a = parseInt(e.replace("#", ""), 16), r = Math.max(0, (a >> 16) - 20), n = Math.max(0, (a >> 8 & 255) - 20), l = Math.max(0, (a & 255) - 20);
220
- return `#${(r << 16 | n << 8 | l).toString(16).padStart(6, "0")}`;
236
+ const t = parseInt(e.replace("#", ""), 16), a = Math.max(0, (t >> 16) - 20), s = Math.max(0, (t >> 8 & 255) - 20), n = Math.max(0, (t & 255) - 20);
237
+ return `#${(a << 16 | s << 8 | n).toString(16).padStart(6, "0")}`;
221
238
  } catch {
222
239
  return e;
223
240
  }
224
241
  }
225
242
  }
226
- class A extends HTMLElement {
243
+ class T extends HTMLElement {
244
+ shadow;
227
245
  constructor() {
228
- super();
229
- i(this, "shadow");
230
- this.shadow = this.attachShadow({ mode: "open" });
246
+ super(), this.shadow = this.attachShadow({ mode: "open" });
231
247
  }
232
248
  connectedCallback() {
233
- var e;
234
- this.render(), (e = this.shadow.querySelector(".bubble")) == null || e.addEventListener("click", () => {
249
+ this.render(), this.shadow.querySelector(".bubble")?.addEventListener("click", () => {
235
250
  this.dispatchEvent(new CustomEvent("toggle", { bubbles: !0, composed: !0 }));
236
251
  });
237
252
  }
@@ -274,30 +289,31 @@ class A extends HTMLElement {
274
289
  `;
275
290
  }
276
291
  setIcon(e) {
277
- const a = this.shadow.querySelector(".bubble");
278
- a && (a.innerHTML = e);
292
+ const t = this.shadow.querySelector(".bubble");
293
+ t && (t.innerHTML = e);
279
294
  }
280
295
  }
281
- class S extends HTMLElement {
282
- constructor() {
283
- super();
284
- i(this, "shadow");
285
- this.shadow = this.attachShadow({ mode: "open" });
286
- }
296
+ class L extends HTMLElement {
297
+ shadow;
287
298
  static get observedAttributes() {
288
299
  return ["title", "subtitle", "avatar-url", "status"];
289
300
  }
301
+ constructor() {
302
+ super(), this.shadow = this.attachShadow({ mode: "open" });
303
+ }
290
304
  connectedCallback() {
291
- var e;
292
- this.render(), (e = this.shadow.querySelector(".close-btn")) == null || e.addEventListener("click", () => {
293
- this.dispatchEvent(new CustomEvent("close", { bubbles: !0, composed: !0 }));
294
- });
305
+ this.render(), this.bindClose();
295
306
  }
296
307
  attributeChangedCallback() {
297
- this.render();
308
+ this.render(), this.bindClose();
309
+ }
310
+ bindClose() {
311
+ this.shadow.querySelector(".close-btn")?.addEventListener("click", () => {
312
+ this.dispatchEvent(new CustomEvent("header-close", { bubbles: !0, composed: !0 }));
313
+ });
298
314
  }
299
315
  render() {
300
- const e = this.getAttribute("title") || "Chat", a = this.getAttribute("subtitle") || "", r = this.getAttribute("avatar-url"), n = this.getAttribute("status") || "connected", l = n === "connected" ? "#10b981" : n === "connecting" || n === "reconnecting" ? "#f59e0b" : "#ef4444";
316
+ const e = this.getAttribute("title") || "Chat", t = this.getAttribute("subtitle") || "", a = this.getAttribute("avatar-url"), s = this.getAttribute("status") || "connected", n = s === "connected" ? "#10b981" : s === "connecting" || s === "reconnecting" ? "#f59e0b" : "#ef4444";
301
317
  this.shadow.innerHTML = `
302
318
  <style>
303
319
  .header {
@@ -377,14 +393,14 @@ class S extends HTMLElement {
377
393
  </style>
378
394
  <div class="header">
379
395
  <div class="avatar">
380
- ${r ? `<img src="${r}" alt="Avatar" />` : '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>'}
396
+ ${a ? `<img src="${a}" alt="Avatar" />` : '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>'}
381
397
  </div>
382
398
  <div class="info">
383
399
  <div class="title">
384
400
  ${e}
385
- <span class="status-dot" style="background:${l}"></span>
401
+ <span class="status-dot" style="background:${n}"></span>
386
402
  </div>
387
- ${a ? `<div class="subtitle">${a}</div>` : ""}
403
+ ${t ? `<div class="subtitle">${t}</div>` : ""}
388
404
  </div>
389
405
  <button class="close-btn" aria-label="Close chat">
390
406
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
@@ -398,24 +414,24 @@ class S extends HTMLElement {
398
414
  this.setAttribute("status", e);
399
415
  }
400
416
  }
401
- function d(s) {
402
- let t = E(s);
403
- return t = t.replace(/```(\w*)\n([\s\S]*?)```/g, (e, a, r) => `<pre><code>${r.trim()}</code></pre>`), t = t.replace(/`([^`]+)`/g, "<code>$1</code>"), t = t.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>"), t = t.replace(/\*(.+?)\*/g, "<em>$1</em>"), t = t.replace(
417
+ function o(i) {
418
+ let e = C(i);
419
+ return e = e.replace(/```(\w*)\n([\s\S]*?)```/g, (t, a, s) => `<pre><code>${s.trim()}</code></pre>`), e = e.replace(/`([^`]+)`/g, "<code>$1</code>"), e = e.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>"), e = e.replace(/\*(.+?)\*/g, "<em>$1</em>"), e = e.replace(
404
420
  /\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g,
405
421
  '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'
406
- ), t = t.replace(/\n/g, "<br>"), t;
422
+ ), e = e.replace(/\n/g, "<br>"), e;
407
423
  }
408
- function E(s) {
409
- const t = {
424
+ function C(i) {
425
+ const e = {
410
426
  "&": "&amp;",
411
427
  "<": "&lt;",
412
428
  ">": "&gt;",
413
429
  '"': "&quot;",
414
430
  "'": "&#039;"
415
431
  };
416
- return s.replace(/[&<>"']/g, (e) => t[e]);
432
+ return i.replace(/[&<>"']/g, (t) => e[t]);
417
433
  }
418
- const M = /* @__PURE__ */ new Set([
434
+ const A = /* @__PURE__ */ new Set([
419
435
  "p",
420
436
  "br",
421
437
  "strong",
@@ -435,49 +451,53 @@ const M = /* @__PURE__ */ new Set([
435
451
  "h6",
436
452
  "span",
437
453
  "div"
438
- ]), _ = {
454
+ ]), S = {
439
455
  a: /* @__PURE__ */ new Set(["href", "target", "rel"]),
440
456
  code: /* @__PURE__ */ new Set(["class"]),
441
457
  pre: /* @__PURE__ */ new Set(["class"]),
442
458
  span: /* @__PURE__ */ new Set(["class"]),
443
459
  div: /* @__PURE__ */ new Set(["class"])
444
460
  };
445
- function c(s) {
446
- const t = document.createElement("template");
447
- return t.innerHTML = s, p(t.content), t.innerHTML;
461
+ function l(i) {
462
+ const e = document.createElement("template");
463
+ return e.innerHTML = i, h(e.content), e.innerHTML;
448
464
  }
449
- function p(s) {
450
- const t = Array.from(s.childNodes);
451
- for (const e of t)
452
- if (e.nodeType === Node.ELEMENT_NODE) {
453
- const a = e, r = a.tagName.toLowerCase();
454
- if (!M.has(r)) {
455
- const o = document.createTextNode(a.textContent || "");
456
- s.replaceChild(o, e);
465
+ function h(i) {
466
+ const e = Array.from(i.childNodes);
467
+ for (const t of e)
468
+ if (t.nodeType === Node.ELEMENT_NODE) {
469
+ const a = t, s = a.tagName.toLowerCase();
470
+ if (!A.has(s)) {
471
+ const r = document.createTextNode(a.textContent || "");
472
+ i.replaceChild(r, t);
457
473
  continue;
458
474
  }
459
- const n = _[r] || /* @__PURE__ */ new Set(), l = Array.from(a.attributes);
460
- for (const o of l)
461
- n.has(o.name) || a.removeAttribute(o.name);
475
+ const n = S[s] || /* @__PURE__ */ new Set(), b = Array.from(a.attributes);
476
+ for (const r of b)
477
+ n.has(r.name) || a.removeAttribute(r.name);
462
478
  if (a.hasAttribute("href")) {
463
- const o = a.getAttribute("href") || "";
464
- !o.startsWith("http://") && !o.startsWith("https://") && !o.startsWith("/") && a.removeAttribute("href");
479
+ const r = a.getAttribute("href") || "";
480
+ !r.startsWith("http://") && !r.startsWith("https://") && !r.startsWith("/") && a.removeAttribute("href");
465
481
  }
466
- p(e);
482
+ h(t);
467
483
  }
468
484
  }
469
- class H extends HTMLElement {
485
+ class E extends HTMLElement {
486
+ shadow;
487
+ container;
488
+ welcomeMessage = "";
489
+ showTimestamps = !0;
470
490
  constructor() {
471
- super();
472
- i(this, "shadow");
473
- i(this, "container");
474
- i(this, "welcomeMessage", "");
475
- i(this, "showTimestamps", !0);
476
- this.shadow = this.attachShadow({ mode: "open" });
491
+ super(), this.shadow = this.attachShadow({ mode: "open" });
477
492
  }
478
493
  connectedCallback() {
479
494
  this.shadow.innerHTML = `
480
495
  <style>
496
+ :host {
497
+ display: flex;
498
+ flex-direction: column;
499
+ min-height: 0;
500
+ }
481
501
  .message-list {
482
502
  flex: 1;
483
503
  overflow-y: auto;
@@ -579,7 +599,7 @@ class H extends HTMLElement {
579
599
  }
580
600
  </style>
581
601
  <div class="message-list"></div>
582
- `, this.container = this.shadow.querySelector(".message-list");
602
+ `, this.container = this.shadow.querySelector(".message-list"), this.welcomeMessage && this.renderMessages([]);
583
603
  }
584
604
  setWelcomeMessage(e) {
585
605
  this.welcomeMessage = e;
@@ -590,29 +610,25 @@ class H extends HTMLElement {
590
610
  renderMessages(e) {
591
611
  if (this.container) {
592
612
  if (this.container.innerHTML = "", e.length === 0 && this.welcomeMessage) {
593
- this.container.innerHTML = `<div class="welcome">${c(d(this.welcomeMessage))}</div>`;
613
+ this.container.innerHTML = `<div class="welcome">${l(o(this.welcomeMessage))}</div>`;
594
614
  return;
595
615
  }
596
- for (const a of e)
597
- this.appendMessageElement(a);
616
+ for (const t of e)
617
+ this.appendMessageElement(t);
598
618
  this.scrollToBottom();
599
619
  }
600
620
  }
601
621
  addMessage(e) {
602
- const a = this.container.querySelector(".welcome");
603
- a && a.remove(), this.appendMessageElement(e), this.scrollToBottom();
622
+ const t = this.container.querySelector(".welcome");
623
+ t && t.remove(), this.appendMessageElement(e), this.scrollToBottom();
604
624
  }
605
625
  updateStreamingContent(e) {
606
- const a = this.container.querySelector('[data-streaming="true"] .bubble');
607
- a && (a.innerHTML = c(d(e)), a.classList.add("streaming-cursor"), this.scrollToBottom());
626
+ const t = this.container.querySelector('[data-streaming="true"] .bubble');
627
+ t && (t.innerHTML = l(o(e)), t.classList.add("streaming-cursor"), this.scrollToBottom());
608
628
  }
609
629
  finalizeStreaming() {
610
630
  const e = this.container.querySelector('[data-streaming="true"]');
611
- if (e) {
612
- e.removeAttribute("data-streaming");
613
- const a = e.querySelector(".bubble");
614
- a == null || a.classList.remove("streaming-cursor");
615
- }
631
+ e && (e.removeAttribute("data-streaming"), e.querySelector(".bubble")?.classList.remove("streaming-cursor"));
616
632
  }
617
633
  showTypingIndicator() {
618
634
  this.removeTypingIndicator();
@@ -620,18 +636,17 @@ class H extends HTMLElement {
620
636
  e.classList.add("typing-indicator"), e.setAttribute("data-typing", "true"), e.innerHTML = '<span class="dot"></span><span class="dot"></span><span class="dot"></span>', this.container.appendChild(e), this.scrollToBottom();
621
637
  }
622
638
  removeTypingIndicator() {
623
- var e;
624
- (e = this.container.querySelector('[data-typing="true"]')) == null || e.remove();
639
+ this.container.querySelector('[data-typing="true"]')?.remove();
625
640
  }
626
641
  appendMessageElement(e) {
642
+ const t = document.createElement("div");
643
+ t.classList.add("message-wrap", e.role), e.status === "streaming" && t.setAttribute("data-streaming", "true");
627
644
  const a = document.createElement("div");
628
- a.classList.add("message-wrap", e.role), e.status === "streaming" && a.setAttribute("data-streaming", "true");
629
- const r = document.createElement("div");
630
- if (r.classList.add("bubble", e.role), e.role === "user" ? r.textContent = e.content : (r.innerHTML = c(d(e.content || "")), e.status === "streaming" && r.classList.add("streaming-cursor")), a.appendChild(r), this.showTimestamps && e.createdAt) {
631
- const n = document.createElement("div");
632
- n.classList.add("timestamp"), n.textContent = this.formatTime(e.createdAt), a.appendChild(n);
645
+ if (a.classList.add("bubble", e.role), e.role === "user" ? a.textContent = e.content : (a.innerHTML = l(o(e.content || "")), e.status === "streaming" && a.classList.add("streaming-cursor")), t.appendChild(a), this.showTimestamps && e.createdAt) {
646
+ const s = document.createElement("div");
647
+ s.classList.add("timestamp"), s.textContent = this.formatTime(e.createdAt), t.appendChild(s);
633
648
  }
634
- this.container.appendChild(a);
649
+ this.container.appendChild(t);
635
650
  }
636
651
  scrollToBottom() {
637
652
  requestAnimationFrame(() => {
@@ -646,15 +661,14 @@ class H extends HTMLElement {
646
661
  }
647
662
  }
648
663
  }
649
- class $ extends HTMLElement {
650
- constructor() {
651
- super();
652
- i(this, "shadow");
653
- this.shadow = this.attachShadow({ mode: "open" });
654
- }
664
+ class M extends HTMLElement {
665
+ shadow;
655
666
  static get observedAttributes() {
656
667
  return ["role", "content", "timestamp"];
657
668
  }
669
+ constructor() {
670
+ super(), this.shadow = this.attachShadow({ mode: "open" });
671
+ }
658
672
  connectedCallback() {
659
673
  this.render();
660
674
  }
@@ -662,7 +676,7 @@ class $ extends HTMLElement {
662
676
  this.render();
663
677
  }
664
678
  render() {
665
- const e = this.getAttribute("role") || "user", a = this.getAttribute("content") || "", r = this.getAttribute("timestamp") || "", n = e === "user" ? document.createTextNode(a).textContent || "" : c(d(a));
679
+ const e = this.getAttribute("role") || "user", t = this.getAttribute("content") || "", a = this.getAttribute("timestamp") || "", s = e === "user" ? document.createTextNode(t).textContent || "" : l(o(t));
666
680
  this.shadow.innerHTML = `
667
681
  <style>
668
682
  :host { display: flex; flex-direction: column; }
@@ -693,19 +707,18 @@ class $ extends HTMLElement {
693
707
  padding: 0 4px;
694
708
  }
695
709
  </style>
696
- <div class="bubble ${e}">${n}</div>
697
- ${r ? `<div class="timestamp">${r}</div>` : ""}
710
+ <div class="bubble ${e}">${s}</div>
711
+ ${a ? `<div class="timestamp">${a}</div>` : ""}
698
712
  `;
699
713
  }
700
714
  }
701
- class z extends HTMLElement {
715
+ class _ extends HTMLElement {
716
+ shadow;
717
+ textarea;
718
+ sendBtn;
719
+ _disabled = !1;
702
720
  constructor() {
703
- super();
704
- i(this, "shadow");
705
- i(this, "textarea");
706
- i(this, "sendBtn");
707
- i(this, "_disabled", !1);
708
- this.shadow = this.attachShadow({ mode: "open" });
721
+ super(), this.shadow = this.attachShadow({ mode: "open" });
709
722
  }
710
723
  connectedCallback() {
711
724
  const e = this.getAttribute("placeholder") || "Type a message...";
@@ -769,20 +782,18 @@ class z extends HTMLElement {
769
782
  </div>
770
783
  `, this.textarea = this.shadow.querySelector("textarea"), this.sendBtn = this.shadow.querySelector(".send-btn"), this.textarea.addEventListener("input", () => {
771
784
  this.autoGrow(), this.sendBtn.disabled = this._disabled || !this.textarea.value.trim();
772
- }), this.textarea.addEventListener("keydown", (a) => {
773
- a.key === "Enter" && !a.shiftKey && (a.preventDefault(), this.handleSend());
785
+ }), this.textarea.addEventListener("keydown", (t) => {
786
+ t.key === "Enter" && !t.shiftKey && (t.preventDefault(), this.handleSend());
774
787
  }), this.sendBtn.addEventListener("click", () => this.handleSend());
775
788
  }
776
789
  set disabled(e) {
777
- var a;
778
- this._disabled = e, this.textarea && (this.textarea.disabled = e), this.sendBtn && (this.sendBtn.disabled = e || !((a = this.textarea) != null && a.value.trim()));
790
+ this._disabled = e, this.textarea && (this.textarea.disabled = e), this.sendBtn && (this.sendBtn.disabled = e || !this.textarea?.value.trim());
779
791
  }
780
792
  get disabled() {
781
793
  return this._disabled;
782
794
  }
783
795
  focus() {
784
- var e;
785
- (e = this.textarea) == null || e.focus();
796
+ this.textarea?.focus();
786
797
  }
787
798
  clear() {
788
799
  this.textarea && (this.textarea.value = "", this.textarea.style.height = "auto", this.sendBtn.disabled = !0);
@@ -799,11 +810,10 @@ class z extends HTMLElement {
799
810
  this.textarea.style.height = "auto", this.textarea.style.height = Math.min(this.textarea.scrollHeight, 120) + "px";
800
811
  }
801
812
  }
802
- class B extends HTMLElement {
813
+ class H extends HTMLElement {
814
+ shadow;
803
815
  constructor() {
804
- super();
805
- i(this, "shadow");
806
- this.shadow = this.attachShadow({ mode: "open" });
816
+ super(), this.shadow = this.attachShadow({ mode: "open" });
807
817
  }
808
818
  connectedCallback() {
809
819
  this.shadow.innerHTML = `
@@ -849,12 +859,11 @@ class B extends HTMLElement {
849
859
  this.removeAttribute("visible");
850
860
  }
851
861
  }
852
- class F extends HTMLElement {
862
+ class $ extends HTMLElement {
863
+ shadow;
864
+ bubble;
853
865
  constructor() {
854
- super();
855
- i(this, "shadow");
856
- i(this, "bubble");
857
- this.shadow = this.attachShadow({ mode: "open" });
866
+ super(), this.shadow = this.attachShadow({ mode: "open" });
858
867
  }
859
868
  connectedCallback() {
860
869
  this.shadow.innerHTML = `
@@ -909,23 +918,20 @@ class F extends HTMLElement {
909
918
  `, this.bubble = this.shadow.querySelector(".bubble");
910
919
  }
911
920
  updateContent(e) {
912
- this.bubble && (this.bubble.innerHTML = c(d(e)), this.bubble.classList.add("cursor"));
921
+ this.bubble && (this.bubble.innerHTML = l(o(e)), this.bubble.classList.add("cursor"));
913
922
  }
914
923
  finalize() {
915
- var e;
916
- (e = this.bubble) == null || e.classList.remove("cursor");
924
+ this.bubble?.classList.remove("cursor");
917
925
  }
918
926
  }
919
- class q extends HTMLElement {
927
+ class z extends HTMLElement {
928
+ shadow;
929
+ container;
930
+ dismissTimer = null;
920
931
  constructor() {
921
- super();
922
- i(this, "shadow");
923
- i(this, "container");
924
- i(this, "dismissTimer", null);
925
- this.shadow = this.attachShadow({ mode: "open" });
932
+ super(), this.shadow = this.attachShadow({ mode: "open" });
926
933
  }
927
934
  connectedCallback() {
928
- var e;
929
935
  this.shadow.innerHTML = `
930
936
  <style>
931
937
  .banner {
@@ -954,41 +960,41 @@ class q extends HTMLElement {
954
960
  <span class="message"></span>
955
961
  <button class="dismiss">Dismiss</button>
956
962
  </div>
957
- `, this.container = this.shadow.querySelector(".banner"), (e = this.shadow.querySelector(".dismiss")) == null || e.addEventListener("click", () => this.hide());
963
+ `, this.container = this.shadow.querySelector(".banner"), this.shadow.querySelector(".dismiss")?.addEventListener("click", () => this.hide());
958
964
  }
959
- show(e, a) {
960
- const r = this.container.querySelector(".message");
961
- r && (r.textContent = e), this.container.classList.add("visible"), this.dismissTimer && clearTimeout(this.dismissTimer), a && (this.dismissTimer = setTimeout(() => this.hide(), a));
965
+ show(e, t) {
966
+ const a = this.container.querySelector(".message");
967
+ a && (a.textContent = e), this.container.classList.add("visible"), this.dismissTimer && clearTimeout(this.dismissTimer), t && (this.dismissTimer = setTimeout(() => this.hide(), t));
962
968
  }
963
969
  hide() {
964
970
  this.container.classList.remove("visible"), this.dismissTimer && (clearTimeout(this.dismissTimer), this.dismissTimer = null);
965
971
  }
966
972
  }
967
- function I() {
968
- const s = [
969
- ["aikaara-chat-widget", C],
970
- ["aikaara-chat-bubble", A],
971
- ["aikaara-chat-header", S],
972
- ["aikaara-message-list", H],
973
- ["aikaara-message-bubble", $],
974
- ["aikaara-chat-input", z],
975
- ["aikaara-typing-indicator", B],
976
- ["aikaara-streaming-message", F],
977
- ["aikaara-error-banner", q]
973
+ function B() {
974
+ const i = [
975
+ ["aikaara-chat-widget", w],
976
+ ["aikaara-chat-bubble", T],
977
+ ["aikaara-chat-header", L],
978
+ ["aikaara-message-list", E],
979
+ ["aikaara-message-bubble", M],
980
+ ["aikaara-chat-input", _],
981
+ ["aikaara-typing-indicator", H],
982
+ ["aikaara-streaming-message", $],
983
+ ["aikaara-error-banner", z]
978
984
  ];
979
- for (const [t, e] of s)
980
- customElements.get(t) || customElements.define(t, e);
985
+ for (const [e, t] of i)
986
+ customElements.get(e) || customElements.define(e, t);
981
987
  }
982
- I();
988
+ B();
983
989
  export {
984
- A as AikaaraChatBubble,
985
- S as AikaaraChatHeader,
986
- z as AikaaraChatInput,
987
- C as AikaaraChatWidget,
988
- q as AikaaraErrorBanner,
989
- $ as AikaaraMessageBubble,
990
- H as AikaaraMessageList,
991
- F as AikaaraStreamingMessage,
992
- B as AikaaraTypingIndicator,
993
- I as registerComponents
990
+ T as AikaaraChatBubble,
991
+ L as AikaaraChatHeader,
992
+ _ as AikaaraChatInput,
993
+ w as AikaaraChatWidget,
994
+ z as AikaaraErrorBanner,
995
+ M as AikaaraMessageBubble,
996
+ E as AikaaraMessageList,
997
+ $ as AikaaraStreamingMessage,
998
+ H as AikaaraTypingIndicator,
999
+ B as registerComponents
994
1000
  };