@aikaara/chat-sdk 0.1.3 → 0.2.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/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 v } from "./AikaaraChatClient-C4lWcRsS.mjs";
2
+ class y {
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 {
@@ -29,55 +26,58 @@ class L {
29
26
  this.togglePanel();
30
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
+ sendUserEvent(e, t, a) {
60
+ this.client.sendUserEvent(e, t, a);
61
+ }
62
+ getClient() {
63
+ return this.client;
64
+ }
65
+ togglePanel(e) {
66
+ this.isOpen = e !== void 0 ? e : !this.isOpen, this.isOpen ? (this.panel.removeAttribute("hidden"), requestAnimationFrame(() => {
64
67
  this.panel.classList.remove("entering"), this.panel.classList.add("visible"), this.input.focus();
65
68
  })) : (this.panel.classList.remove("visible"), this.panel.classList.add("entering"), setTimeout(() => {
66
69
  this.panel.setAttribute("hidden", "");
67
70
  }, 200));
68
71
  }
69
72
  }
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
- }
73
+ class w extends HTMLElement {
74
+ shadow;
75
+ controller = null;
76
+ _config = {};
78
77
  static get observedAttributes() {
79
78
  return [
80
79
  "base-url",
80
+ "ws-url",
81
81
  "user-token",
82
82
  "api-key",
83
83
  "title",
@@ -92,15 +92,17 @@ class C extends HTMLElement {
92
92
  "avatar-url"
93
93
  ];
94
94
  }
95
+ constructor() {
96
+ super(), this.shadow = this.attachShadow({ mode: "open" });
97
+ }
95
98
  connectedCallback() {
96
99
  this.render(), this.initController();
97
100
  }
98
101
  disconnectedCallback() {
99
- var e;
100
- (e = this.controller) == null || e.disconnect();
102
+ this.controller?.disconnect();
101
103
  }
102
- attributeChangedCallback(e, a, r) {
103
- a !== r && this.controller && (this.render(), this.initController());
104
+ attributeChangedCallback(e, t, a) {
105
+ t !== a && this.controller && (this.render(), this.initController());
104
106
  }
105
107
  configure(e) {
106
108
  this._config = { ...this._config, ...e };
@@ -108,27 +110,29 @@ class C extends HTMLElement {
108
110
  getConfig() {
109
111
  return {
110
112
  baseUrl: this.getAttribute("base-url") || this._config.baseUrl || "",
113
+ wsUrl: this.getAttribute("ws-url") || this._config.wsUrl,
111
114
  userToken: this.getAttribute("user-token") || this._config.userToken || "",
112
115
  apiKey: this.getAttribute("api-key") || this._config.apiKey,
113
116
  title: this.getAttribute("title") || this._config.title || "Chat",
114
117
  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,
118
+ theme: this.getAttribute("theme") || this._config.theme || v,
119
+ primaryColor: this.getAttribute("primary-color") || this._config.primaryColor || c,
120
+ position: this.getAttribute("position") || this._config.position || k,
121
+ width: Number(this.getAttribute("width")) || this._config.width || x,
122
+ height: Number(this.getAttribute("height")) || this._config.height || f,
123
+ fontFamily: this._config.fontFamily || m,
124
+ borderRadius: this._config.borderRadius ?? g,
125
+ placeholder: this.getAttribute("placeholder") || this._config.placeholder || d,
123
126
  welcomeMessage: this.getAttribute("welcome-message") || this._config.welcomeMessage,
124
127
  avatarUrl: this.getAttribute("avatar-url") || this._config.avatarUrl,
125
128
  showTimestamps: this._config.showTimestamps ?? !0,
126
129
  persistConversation: this._config.persistConversation ?? !0,
127
130
  showBubble: this._config.showBubble ?? !0,
128
- offset: this._config.offset || f,
131
+ offset: this._config.offset || u,
129
132
  conversationId: this._config.conversationId,
130
133
  systemPromptId: this._config.systemPromptId,
131
134
  channel: this._config.channel,
135
+ extUid: this._config.extUid,
132
136
  onMessage: this._config.onMessage,
133
137
  onStatusChange: this._config.onStatusChange,
134
138
  onError: this._config.onError,
@@ -137,13 +141,12 @@ class C extends HTMLElement {
137
141
  };
138
142
  }
139
143
  render() {
140
- var a, r;
141
144
  const e = this.getConfig();
142
145
  this.shadow.innerHTML = `
143
146
  <style>
144
147
  :host {
145
148
  --aikaara-primary: ${e.primaryColor};
146
- --aikaara-primary-hover: ${this.darkenColor(e.primaryColor || b)};
149
+ --aikaara-primary-hover: ${this.darkenColor(e.primaryColor || c)};
147
150
  --aikaara-bg: #ffffff;
148
151
  --aikaara-bg-secondary: #f9fafb;
149
152
  --aikaara-text: #1f2937;
@@ -154,8 +157,8 @@ class C extends HTMLElement {
154
157
  --aikaara-panel-width: ${e.width}px;
155
158
  --aikaara-panel-height: ${e.height}px;
156
159
  --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;
160
+ --aikaara-offset-x: ${e.offset?.x ?? 20}px;
161
+ --aikaara-offset-y: ${e.offset?.y ?? 20}px;
159
162
  font-family: var(--aikaara-font);
160
163
  position: fixed;
161
164
  z-index: 9999;
@@ -193,6 +196,27 @@ class C extends HTMLElement {
193
196
  opacity: 1;
194
197
  transform: translateY(0) scale(1);
195
198
  }
199
+
200
+ aikaara-chat-header,
201
+ aikaara-message-list,
202
+ aikaara-chat-input,
203
+ aikaara-error-banner {
204
+ display: block;
205
+ }
206
+
207
+ aikaara-message-list {
208
+ flex: 1;
209
+ overflow: scroll;
210
+ min-height: 0;
211
+ }
212
+
213
+ aikaara-chat-input {
214
+ flex-shrink: 0;
215
+ }
216
+
217
+ aikaara-chat-header {
218
+ flex-shrink: 0;
219
+ }
196
220
  </style>
197
221
 
198
222
  <aikaara-chat-bubble></aikaara-chat-bubble>
@@ -204,34 +228,37 @@ class C extends HTMLElement {
204
228
  ${e.avatarUrl ? `avatar-url="${e.avatarUrl}"` : ""}
205
229
  ></aikaara-chat-header>
206
230
  <aikaara-message-list></aikaara-message-list>
207
- <aikaara-chat-input placeholder="${e.placeholder || h}"></aikaara-chat-input>
231
+ <aikaara-chat-input placeholder="${e.placeholder || d}"></aikaara-chat-input>
208
232
  <aikaara-error-banner></aikaara-error-banner>
209
233
  </div>
210
234
  `;
211
235
  }
212
236
  async initController() {
213
- var a;
214
237
  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());
238
+ !e.baseUrl || !e.userToken || (this.controller?.disconnect(), this.controller = new y(e, this.shadow), await this.controller.connect());
239
+ }
240
+ sendUserEvent(e, t, a) {
241
+ this.controller?.sendUserEvent(e, t, a);
242
+ }
243
+ getClient() {
244
+ return this.controller?.getClient() ?? null;
216
245
  }
217
246
  darkenColor(e) {
218
247
  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")}`;
248
+ 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);
249
+ return `#${(a << 16 | s << 8 | n).toString(16).padStart(6, "0")}`;
221
250
  } catch {
222
251
  return e;
223
252
  }
224
253
  }
225
254
  }
226
- class A extends HTMLElement {
255
+ class T extends HTMLElement {
256
+ shadow;
227
257
  constructor() {
228
- super();
229
- i(this, "shadow");
230
- this.shadow = this.attachShadow({ mode: "open" });
258
+ super(), this.shadow = this.attachShadow({ mode: "open" });
231
259
  }
232
260
  connectedCallback() {
233
- var e;
234
- this.render(), (e = this.shadow.querySelector(".bubble")) == null || e.addEventListener("click", () => {
261
+ this.render(), this.shadow.querySelector(".bubble")?.addEventListener("click", () => {
235
262
  this.dispatchEvent(new CustomEvent("toggle", { bubbles: !0, composed: !0 }));
236
263
  });
237
264
  }
@@ -274,19 +301,18 @@ class A extends HTMLElement {
274
301
  `;
275
302
  }
276
303
  setIcon(e) {
277
- const a = this.shadow.querySelector(".bubble");
278
- a && (a.innerHTML = e);
304
+ const t = this.shadow.querySelector(".bubble");
305
+ t && (t.innerHTML = e);
279
306
  }
280
307
  }
281
- class S extends HTMLElement {
282
- constructor() {
283
- super();
284
- i(this, "shadow");
285
- this.shadow = this.attachShadow({ mode: "open" });
286
- }
308
+ class C extends HTMLElement {
309
+ shadow;
287
310
  static get observedAttributes() {
288
311
  return ["title", "subtitle", "avatar-url", "status"];
289
312
  }
313
+ constructor() {
314
+ super(), this.shadow = this.attachShadow({ mode: "open" });
315
+ }
290
316
  connectedCallback() {
291
317
  this.render(), this.bindClose();
292
318
  }
@@ -294,13 +320,12 @@ class S extends HTMLElement {
294
320
  this.render(), this.bindClose();
295
321
  }
296
322
  bindClose() {
297
- var e;
298
- (e = this.shadow.querySelector(".close-btn")) == null || e.addEventListener("click", () => {
323
+ this.shadow.querySelector(".close-btn")?.addEventListener("click", () => {
299
324
  this.dispatchEvent(new CustomEvent("header-close", { bubbles: !0, composed: !0 }));
300
325
  });
301
326
  }
302
327
  render() {
303
- 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";
328
+ 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";
304
329
  this.shadow.innerHTML = `
305
330
  <style>
306
331
  .header {
@@ -380,14 +405,14 @@ class S extends HTMLElement {
380
405
  </style>
381
406
  <div class="header">
382
407
  <div class="avatar">
383
- ${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>'}
408
+ ${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>'}
384
409
  </div>
385
410
  <div class="info">
386
411
  <div class="title">
387
412
  ${e}
388
- <span class="status-dot" style="background:${l}"></span>
413
+ <span class="status-dot" style="background:${n}"></span>
389
414
  </div>
390
- ${a ? `<div class="subtitle">${a}</div>` : ""}
415
+ ${t ? `<div class="subtitle">${t}</div>` : ""}
391
416
  </div>
392
417
  <button class="close-btn" aria-label="Close chat">
393
418
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
@@ -401,24 +426,24 @@ class S extends HTMLElement {
401
426
  this.setAttribute("status", e);
402
427
  }
403
428
  }
404
- function d(s) {
405
- let t = E(s);
406
- 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(
429
+ function o(i) {
430
+ let e = L(i);
431
+ 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(
407
432
  /\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g,
408
433
  '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'
409
- ), t = t.replace(/\n/g, "<br>"), t;
434
+ ), e = e.replace(/\n/g, "<br>"), e;
410
435
  }
411
- function E(s) {
412
- const t = {
436
+ function L(i) {
437
+ const e = {
413
438
  "&": "&amp;",
414
439
  "<": "&lt;",
415
440
  ">": "&gt;",
416
441
  '"': "&quot;",
417
442
  "'": "&#039;"
418
443
  };
419
- return s.replace(/[&<>"']/g, (e) => t[e]);
444
+ return i.replace(/[&<>"']/g, (t) => e[t]);
420
445
  }
421
- const M = /* @__PURE__ */ new Set([
446
+ const A = /* @__PURE__ */ new Set([
422
447
  "p",
423
448
  "br",
424
449
  "strong",
@@ -438,49 +463,53 @@ const M = /* @__PURE__ */ new Set([
438
463
  "h6",
439
464
  "span",
440
465
  "div"
441
- ]), _ = {
466
+ ]), E = {
442
467
  a: /* @__PURE__ */ new Set(["href", "target", "rel"]),
443
468
  code: /* @__PURE__ */ new Set(["class"]),
444
469
  pre: /* @__PURE__ */ new Set(["class"]),
445
470
  span: /* @__PURE__ */ new Set(["class"]),
446
471
  div: /* @__PURE__ */ new Set(["class"])
447
472
  };
448
- function c(s) {
449
- const t = document.createElement("template");
450
- return t.innerHTML = s, p(t.content), t.innerHTML;
473
+ function l(i) {
474
+ const e = document.createElement("template");
475
+ return e.innerHTML = i, h(e.content), e.innerHTML;
451
476
  }
452
- function p(s) {
453
- const t = Array.from(s.childNodes);
454
- for (const e of t)
455
- if (e.nodeType === Node.ELEMENT_NODE) {
456
- const a = e, r = a.tagName.toLowerCase();
457
- if (!M.has(r)) {
458
- const o = document.createTextNode(a.textContent || "");
459
- s.replaceChild(o, e);
477
+ function h(i) {
478
+ const e = Array.from(i.childNodes);
479
+ for (const t of e)
480
+ if (t.nodeType === Node.ELEMENT_NODE) {
481
+ const a = t, s = a.tagName.toLowerCase();
482
+ if (!A.has(s)) {
483
+ const r = document.createTextNode(a.textContent || "");
484
+ i.replaceChild(r, t);
460
485
  continue;
461
486
  }
462
- const n = _[r] || /* @__PURE__ */ new Set(), l = Array.from(a.attributes);
463
- for (const o of l)
464
- n.has(o.name) || a.removeAttribute(o.name);
487
+ const n = E[s] || /* @__PURE__ */ new Set(), b = Array.from(a.attributes);
488
+ for (const r of b)
489
+ n.has(r.name) || a.removeAttribute(r.name);
465
490
  if (a.hasAttribute("href")) {
466
- const o = a.getAttribute("href") || "";
467
- !o.startsWith("http://") && !o.startsWith("https://") && !o.startsWith("/") && a.removeAttribute("href");
491
+ const r = a.getAttribute("href") || "";
492
+ !r.startsWith("http://") && !r.startsWith("https://") && !r.startsWith("/") && a.removeAttribute("href");
468
493
  }
469
- p(e);
494
+ h(t);
470
495
  }
471
496
  }
472
- class H extends HTMLElement {
497
+ class S extends HTMLElement {
498
+ shadow;
499
+ container;
500
+ welcomeMessage = "";
501
+ showTimestamps = !0;
473
502
  constructor() {
474
- super();
475
- i(this, "shadow");
476
- i(this, "container");
477
- i(this, "welcomeMessage", "");
478
- i(this, "showTimestamps", !0);
479
- this.shadow = this.attachShadow({ mode: "open" });
503
+ super(), this.shadow = this.attachShadow({ mode: "open" });
480
504
  }
481
505
  connectedCallback() {
482
506
  this.shadow.innerHTML = `
483
507
  <style>
508
+ :host {
509
+ display: flex;
510
+ flex-direction: column;
511
+ min-height: 0;
512
+ }
484
513
  .message-list {
485
514
  flex: 1;
486
515
  overflow-y: auto;
@@ -582,7 +611,7 @@ class H extends HTMLElement {
582
611
  }
583
612
  </style>
584
613
  <div class="message-list"></div>
585
- `, this.container = this.shadow.querySelector(".message-list");
614
+ `, this.container = this.shadow.querySelector(".message-list"), this.welcomeMessage && this.renderMessages([]);
586
615
  }
587
616
  setWelcomeMessage(e) {
588
617
  this.welcomeMessage = e;
@@ -593,29 +622,25 @@ class H extends HTMLElement {
593
622
  renderMessages(e) {
594
623
  if (this.container) {
595
624
  if (this.container.innerHTML = "", e.length === 0 && this.welcomeMessage) {
596
- this.container.innerHTML = `<div class="welcome">${c(d(this.welcomeMessage))}</div>`;
625
+ this.container.innerHTML = `<div class="welcome">${l(o(this.welcomeMessage))}</div>`;
597
626
  return;
598
627
  }
599
- for (const a of e)
600
- this.appendMessageElement(a);
628
+ for (const t of e)
629
+ this.appendMessageElement(t);
601
630
  this.scrollToBottom();
602
631
  }
603
632
  }
604
633
  addMessage(e) {
605
- const a = this.container.querySelector(".welcome");
606
- a && a.remove(), this.appendMessageElement(e), this.scrollToBottom();
634
+ const t = this.container.querySelector(".welcome");
635
+ t && t.remove(), this.appendMessageElement(e), this.scrollToBottom();
607
636
  }
608
637
  updateStreamingContent(e) {
609
- const a = this.container.querySelector('[data-streaming="true"] .bubble');
610
- a && (a.innerHTML = c(d(e)), a.classList.add("streaming-cursor"), this.scrollToBottom());
638
+ const t = this.container.querySelector('[data-streaming="true"] .bubble');
639
+ t && (t.innerHTML = l(o(e)), t.classList.add("streaming-cursor"), this.scrollToBottom());
611
640
  }
612
641
  finalizeStreaming() {
613
642
  const e = this.container.querySelector('[data-streaming="true"]');
614
- if (e) {
615
- e.removeAttribute("data-streaming");
616
- const a = e.querySelector(".bubble");
617
- a == null || a.classList.remove("streaming-cursor");
618
- }
643
+ e && (e.removeAttribute("data-streaming"), e.querySelector(".bubble")?.classList.remove("streaming-cursor"));
619
644
  }
620
645
  showTypingIndicator() {
621
646
  this.removeTypingIndicator();
@@ -623,18 +648,17 @@ class H extends HTMLElement {
623
648
  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();
624
649
  }
625
650
  removeTypingIndicator() {
626
- var e;
627
- (e = this.container.querySelector('[data-typing="true"]')) == null || e.remove();
651
+ this.container.querySelector('[data-typing="true"]')?.remove();
628
652
  }
629
653
  appendMessageElement(e) {
654
+ const t = document.createElement("div");
655
+ t.classList.add("message-wrap", e.role), e.status === "streaming" && t.setAttribute("data-streaming", "true");
630
656
  const a = document.createElement("div");
631
- a.classList.add("message-wrap", e.role), e.status === "streaming" && a.setAttribute("data-streaming", "true");
632
- const r = document.createElement("div");
633
- 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) {
634
- const n = document.createElement("div");
635
- n.classList.add("timestamp"), n.textContent = this.formatTime(e.createdAt), a.appendChild(n);
657
+ 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) {
658
+ const s = document.createElement("div");
659
+ s.classList.add("timestamp"), s.textContent = this.formatTime(e.createdAt), t.appendChild(s);
636
660
  }
637
- this.container.appendChild(a);
661
+ this.container.appendChild(t);
638
662
  }
639
663
  scrollToBottom() {
640
664
  requestAnimationFrame(() => {
@@ -649,15 +673,14 @@ class H extends HTMLElement {
649
673
  }
650
674
  }
651
675
  }
652
- class $ extends HTMLElement {
653
- constructor() {
654
- super();
655
- i(this, "shadow");
656
- this.shadow = this.attachShadow({ mode: "open" });
657
- }
676
+ class M extends HTMLElement {
677
+ shadow;
658
678
  static get observedAttributes() {
659
679
  return ["role", "content", "timestamp"];
660
680
  }
681
+ constructor() {
682
+ super(), this.shadow = this.attachShadow({ mode: "open" });
683
+ }
661
684
  connectedCallback() {
662
685
  this.render();
663
686
  }
@@ -665,7 +688,7 @@ class $ extends HTMLElement {
665
688
  this.render();
666
689
  }
667
690
  render() {
668
- const e = this.getAttribute("role") || "user", a = this.getAttribute("content") || "", r = this.getAttribute("timestamp") || "", n = e === "user" ? document.createTextNode(a).textContent || "" : c(d(a));
691
+ const e = this.getAttribute("role") || "user", t = this.getAttribute("content") || "", a = this.getAttribute("timestamp") || "", s = e === "user" ? document.createTextNode(t).textContent || "" : l(o(t));
669
692
  this.shadow.innerHTML = `
670
693
  <style>
671
694
  :host { display: flex; flex-direction: column; }
@@ -696,19 +719,18 @@ class $ extends HTMLElement {
696
719
  padding: 0 4px;
697
720
  }
698
721
  </style>
699
- <div class="bubble ${e}">${n}</div>
700
- ${r ? `<div class="timestamp">${r}</div>` : ""}
722
+ <div class="bubble ${e}">${s}</div>
723
+ ${a ? `<div class="timestamp">${a}</div>` : ""}
701
724
  `;
702
725
  }
703
726
  }
704
- class z extends HTMLElement {
727
+ class _ extends HTMLElement {
728
+ shadow;
729
+ textarea;
730
+ sendBtn;
731
+ _disabled = !1;
705
732
  constructor() {
706
- super();
707
- i(this, "shadow");
708
- i(this, "textarea");
709
- i(this, "sendBtn");
710
- i(this, "_disabled", !1);
711
- this.shadow = this.attachShadow({ mode: "open" });
733
+ super(), this.shadow = this.attachShadow({ mode: "open" });
712
734
  }
713
735
  connectedCallback() {
714
736
  const e = this.getAttribute("placeholder") || "Type a message...";
@@ -772,20 +794,18 @@ class z extends HTMLElement {
772
794
  </div>
773
795
  `, this.textarea = this.shadow.querySelector("textarea"), this.sendBtn = this.shadow.querySelector(".send-btn"), this.textarea.addEventListener("input", () => {
774
796
  this.autoGrow(), this.sendBtn.disabled = this._disabled || !this.textarea.value.trim();
775
- }), this.textarea.addEventListener("keydown", (a) => {
776
- a.key === "Enter" && !a.shiftKey && (a.preventDefault(), this.handleSend());
797
+ }), this.textarea.addEventListener("keydown", (t) => {
798
+ t.key === "Enter" && !t.shiftKey && (t.preventDefault(), this.handleSend());
777
799
  }), this.sendBtn.addEventListener("click", () => this.handleSend());
778
800
  }
779
801
  set disabled(e) {
780
- var a;
781
- this._disabled = e, this.textarea && (this.textarea.disabled = e), this.sendBtn && (this.sendBtn.disabled = e || !((a = this.textarea) != null && a.value.trim()));
802
+ this._disabled = e, this.textarea && (this.textarea.disabled = e), this.sendBtn && (this.sendBtn.disabled = e || !this.textarea?.value.trim());
782
803
  }
783
804
  get disabled() {
784
805
  return this._disabled;
785
806
  }
786
807
  focus() {
787
- var e;
788
- (e = this.textarea) == null || e.focus();
808
+ this.textarea?.focus();
789
809
  }
790
810
  clear() {
791
811
  this.textarea && (this.textarea.value = "", this.textarea.style.height = "auto", this.sendBtn.disabled = !0);
@@ -802,11 +822,10 @@ class z extends HTMLElement {
802
822
  this.textarea.style.height = "auto", this.textarea.style.height = Math.min(this.textarea.scrollHeight, 120) + "px";
803
823
  }
804
824
  }
805
- class B extends HTMLElement {
825
+ class H extends HTMLElement {
826
+ shadow;
806
827
  constructor() {
807
- super();
808
- i(this, "shadow");
809
- this.shadow = this.attachShadow({ mode: "open" });
828
+ super(), this.shadow = this.attachShadow({ mode: "open" });
810
829
  }
811
830
  connectedCallback() {
812
831
  this.shadow.innerHTML = `
@@ -852,12 +871,11 @@ class B extends HTMLElement {
852
871
  this.removeAttribute("visible");
853
872
  }
854
873
  }
855
- class F extends HTMLElement {
874
+ class $ extends HTMLElement {
875
+ shadow;
876
+ bubble;
856
877
  constructor() {
857
- super();
858
- i(this, "shadow");
859
- i(this, "bubble");
860
- this.shadow = this.attachShadow({ mode: "open" });
878
+ super(), this.shadow = this.attachShadow({ mode: "open" });
861
879
  }
862
880
  connectedCallback() {
863
881
  this.shadow.innerHTML = `
@@ -912,23 +930,20 @@ class F extends HTMLElement {
912
930
  `, this.bubble = this.shadow.querySelector(".bubble");
913
931
  }
914
932
  updateContent(e) {
915
- this.bubble && (this.bubble.innerHTML = c(d(e)), this.bubble.classList.add("cursor"));
933
+ this.bubble && (this.bubble.innerHTML = l(o(e)), this.bubble.classList.add("cursor"));
916
934
  }
917
935
  finalize() {
918
- var e;
919
- (e = this.bubble) == null || e.classList.remove("cursor");
936
+ this.bubble?.classList.remove("cursor");
920
937
  }
921
938
  }
922
- class q extends HTMLElement {
939
+ class z extends HTMLElement {
940
+ shadow;
941
+ container;
942
+ dismissTimer = null;
923
943
  constructor() {
924
- super();
925
- i(this, "shadow");
926
- i(this, "container");
927
- i(this, "dismissTimer", null);
928
- this.shadow = this.attachShadow({ mode: "open" });
944
+ super(), this.shadow = this.attachShadow({ mode: "open" });
929
945
  }
930
946
  connectedCallback() {
931
- var e;
932
947
  this.shadow.innerHTML = `
933
948
  <style>
934
949
  .banner {
@@ -957,41 +972,41 @@ class q extends HTMLElement {
957
972
  <span class="message"></span>
958
973
  <button class="dismiss">Dismiss</button>
959
974
  </div>
960
- `, this.container = this.shadow.querySelector(".banner"), (e = this.shadow.querySelector(".dismiss")) == null || e.addEventListener("click", () => this.hide());
975
+ `, this.container = this.shadow.querySelector(".banner"), this.shadow.querySelector(".dismiss")?.addEventListener("click", () => this.hide());
961
976
  }
962
- show(e, a) {
963
- const r = this.container.querySelector(".message");
964
- r && (r.textContent = e), this.container.classList.add("visible"), this.dismissTimer && clearTimeout(this.dismissTimer), a && (this.dismissTimer = setTimeout(() => this.hide(), a));
977
+ show(e, t) {
978
+ const a = this.container.querySelector(".message");
979
+ a && (a.textContent = e), this.container.classList.add("visible"), this.dismissTimer && clearTimeout(this.dismissTimer), t && (this.dismissTimer = setTimeout(() => this.hide(), t));
965
980
  }
966
981
  hide() {
967
982
  this.container.classList.remove("visible"), this.dismissTimer && (clearTimeout(this.dismissTimer), this.dismissTimer = null);
968
983
  }
969
984
  }
970
- function I() {
971
- const s = [
972
- ["aikaara-chat-widget", C],
973
- ["aikaara-chat-bubble", A],
974
- ["aikaara-chat-header", S],
975
- ["aikaara-message-list", H],
976
- ["aikaara-message-bubble", $],
977
- ["aikaara-chat-input", z],
978
- ["aikaara-typing-indicator", B],
979
- ["aikaara-streaming-message", F],
980
- ["aikaara-error-banner", q]
985
+ function B() {
986
+ const i = [
987
+ ["aikaara-chat-widget", w],
988
+ ["aikaara-chat-bubble", T],
989
+ ["aikaara-chat-header", C],
990
+ ["aikaara-message-list", S],
991
+ ["aikaara-message-bubble", M],
992
+ ["aikaara-chat-input", _],
993
+ ["aikaara-typing-indicator", H],
994
+ ["aikaara-streaming-message", $],
995
+ ["aikaara-error-banner", z]
981
996
  ];
982
- for (const [t, e] of s)
983
- customElements.get(t) || customElements.define(t, e);
997
+ for (const [e, t] of i)
998
+ customElements.get(e) || customElements.define(e, t);
984
999
  }
985
- I();
1000
+ B();
986
1001
  export {
987
- A as AikaaraChatBubble,
988
- S as AikaaraChatHeader,
989
- z as AikaaraChatInput,
990
- C as AikaaraChatWidget,
991
- q as AikaaraErrorBanner,
992
- $ as AikaaraMessageBubble,
993
- H as AikaaraMessageList,
994
- F as AikaaraStreamingMessage,
995
- B as AikaaraTypingIndicator,
996
- I as registerComponents
1002
+ T as AikaaraChatBubble,
1003
+ C as AikaaraChatHeader,
1004
+ _ as AikaaraChatInput,
1005
+ w as AikaaraChatWidget,
1006
+ z as AikaaraErrorBanner,
1007
+ M as AikaaraMessageBubble,
1008
+ S as AikaaraMessageList,
1009
+ $ as AikaaraStreamingMessage,
1010
+ H as AikaaraTypingIndicator,
1011
+ B as registerComponents
997
1012
  };