@aikaara/chat-sdk 0.1.3 → 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/cdn/aikaara-chat.iife.js +45 -19
- package/dist/{headless-CXRux2Q-.mjs → headless-BhsiNVQj.mjs} +185 -199
- package/dist/headless-CrgIWcf7.cjs +1 -0
- package/dist/headless.cjs +1 -1
- package/dist/headless.d.ts +3 -0
- package/dist/headless.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +1 -1
- package/dist/ui.cjs +45 -19
- package/dist/ui.d.ts +1 -0
- package/dist/ui.mjs +209 -206
- package/package.json +2 -2
- package/dist/headless-DDmLD-ag.cjs +0 -1
package/dist/ui.mjs
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 {
|
|
@@ -29,55 +26,52 @@ class L {
|
|
|
29
26
|
this.togglePanel();
|
|
30
27
|
}), this.header.addEventListener("header-close", () => {
|
|
31
28
|
this.togglePanel(!1);
|
|
32
|
-
}), this.input.addEventListener("send", ((
|
|
33
|
-
this.handleSend(
|
|
34
|
-
})), this.client.on("message:sent", (
|
|
35
|
-
this.messageList.addMessage(
|
|
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
|
|
39
|
-
|
|
40
|
-
}), this.client.on("stream:update", ({ content:
|
|
41
|
-
this.messageList.updateStreamingContent(
|
|
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
|
|
46
|
-
(!
|
|
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", (
|
|
50
|
-
this.header.setStatus(
|
|
51
|
-
}), this.client.on("error", (
|
|
52
|
-
this.errorBanner.show(
|
|
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(
|
|
52
|
+
async handleSend(e) {
|
|
56
53
|
try {
|
|
57
|
-
await this.client.sendMessage(
|
|
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(
|
|
63
|
-
this.isOpen =
|
|
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
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
100
|
-
(e = this.controller) == null || e.disconnect();
|
|
96
|
+
this.controller?.disconnect();
|
|
101
97
|
}
|
|
102
|
-
attributeChangedCallback(e,
|
|
103
|
-
|
|
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 ||
|
|
116
|
-
primaryColor: this.getAttribute("primary-color") || this._config.primaryColor ||
|
|
117
|
-
position: this.getAttribute("position") || this._config.position ||
|
|
118
|
-
width: Number(this.getAttribute("width")) || this._config.width ||
|
|
119
|
-
height: Number(this.getAttribute("height")) || this._config.height ||
|
|
120
|
-
fontFamily: this._config.fontFamily ||
|
|
121
|
-
borderRadius: this._config.borderRadius ??
|
|
122
|
-
placeholder: this.getAttribute("placeholder") || this._config.placeholder ||
|
|
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 ||
|
|
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 ||
|
|
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: ${
|
|
158
|
-
--aikaara-offset-y: ${
|
|
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 ||
|
|
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 || (
|
|
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
|
|
220
|
-
return `#${(
|
|
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
|
|
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
|
-
|
|
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,19 +289,18 @@ class A extends HTMLElement {
|
|
|
274
289
|
`;
|
|
275
290
|
}
|
|
276
291
|
setIcon(e) {
|
|
277
|
-
const
|
|
278
|
-
|
|
292
|
+
const t = this.shadow.querySelector(".bubble");
|
|
293
|
+
t && (t.innerHTML = e);
|
|
279
294
|
}
|
|
280
295
|
}
|
|
281
|
-
class
|
|
282
|
-
|
|
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
305
|
this.render(), this.bindClose();
|
|
292
306
|
}
|
|
@@ -294,13 +308,12 @@ class S extends HTMLElement {
|
|
|
294
308
|
this.render(), this.bindClose();
|
|
295
309
|
}
|
|
296
310
|
bindClose() {
|
|
297
|
-
|
|
298
|
-
(e = this.shadow.querySelector(".close-btn")) == null || e.addEventListener("click", () => {
|
|
311
|
+
this.shadow.querySelector(".close-btn")?.addEventListener("click", () => {
|
|
299
312
|
this.dispatchEvent(new CustomEvent("header-close", { bubbles: !0, composed: !0 }));
|
|
300
313
|
});
|
|
301
314
|
}
|
|
302
315
|
render() {
|
|
303
|
-
const e = this.getAttribute("title") || "Chat",
|
|
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";
|
|
304
317
|
this.shadow.innerHTML = `
|
|
305
318
|
<style>
|
|
306
319
|
.header {
|
|
@@ -380,14 +393,14 @@ class S extends HTMLElement {
|
|
|
380
393
|
</style>
|
|
381
394
|
<div class="header">
|
|
382
395
|
<div class="avatar">
|
|
383
|
-
${
|
|
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>'}
|
|
384
397
|
</div>
|
|
385
398
|
<div class="info">
|
|
386
399
|
<div class="title">
|
|
387
400
|
${e}
|
|
388
|
-
<span class="status-dot" style="background:${
|
|
401
|
+
<span class="status-dot" style="background:${n}"></span>
|
|
389
402
|
</div>
|
|
390
|
-
${
|
|
403
|
+
${t ? `<div class="subtitle">${t}</div>` : ""}
|
|
391
404
|
</div>
|
|
392
405
|
<button class="close-btn" aria-label="Close chat">
|
|
393
406
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
@@ -401,24 +414,24 @@ class S extends HTMLElement {
|
|
|
401
414
|
this.setAttribute("status", e);
|
|
402
415
|
}
|
|
403
416
|
}
|
|
404
|
-
function
|
|
405
|
-
let
|
|
406
|
-
return
|
|
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(
|
|
407
420
|
/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g,
|
|
408
421
|
'<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'
|
|
409
|
-
),
|
|
422
|
+
), e = e.replace(/\n/g, "<br>"), e;
|
|
410
423
|
}
|
|
411
|
-
function
|
|
412
|
-
const
|
|
424
|
+
function C(i) {
|
|
425
|
+
const e = {
|
|
413
426
|
"&": "&",
|
|
414
427
|
"<": "<",
|
|
415
428
|
">": ">",
|
|
416
429
|
'"': """,
|
|
417
430
|
"'": "'"
|
|
418
431
|
};
|
|
419
|
-
return
|
|
432
|
+
return i.replace(/[&<>"']/g, (t) => e[t]);
|
|
420
433
|
}
|
|
421
|
-
const
|
|
434
|
+
const A = /* @__PURE__ */ new Set([
|
|
422
435
|
"p",
|
|
423
436
|
"br",
|
|
424
437
|
"strong",
|
|
@@ -438,49 +451,53 @@ const M = /* @__PURE__ */ new Set([
|
|
|
438
451
|
"h6",
|
|
439
452
|
"span",
|
|
440
453
|
"div"
|
|
441
|
-
]),
|
|
454
|
+
]), S = {
|
|
442
455
|
a: /* @__PURE__ */ new Set(["href", "target", "rel"]),
|
|
443
456
|
code: /* @__PURE__ */ new Set(["class"]),
|
|
444
457
|
pre: /* @__PURE__ */ new Set(["class"]),
|
|
445
458
|
span: /* @__PURE__ */ new Set(["class"]),
|
|
446
459
|
div: /* @__PURE__ */ new Set(["class"])
|
|
447
460
|
};
|
|
448
|
-
function
|
|
449
|
-
const
|
|
450
|
-
return
|
|
461
|
+
function l(i) {
|
|
462
|
+
const e = document.createElement("template");
|
|
463
|
+
return e.innerHTML = i, h(e.content), e.innerHTML;
|
|
451
464
|
}
|
|
452
|
-
function
|
|
453
|
-
const
|
|
454
|
-
for (const
|
|
455
|
-
if (
|
|
456
|
-
const a =
|
|
457
|
-
if (!
|
|
458
|
-
const
|
|
459
|
-
|
|
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);
|
|
460
473
|
continue;
|
|
461
474
|
}
|
|
462
|
-
const n =
|
|
463
|
-
for (const
|
|
464
|
-
n.has(
|
|
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);
|
|
465
478
|
if (a.hasAttribute("href")) {
|
|
466
|
-
const
|
|
467
|
-
!
|
|
479
|
+
const r = a.getAttribute("href") || "";
|
|
480
|
+
!r.startsWith("http://") && !r.startsWith("https://") && !r.startsWith("/") && a.removeAttribute("href");
|
|
468
481
|
}
|
|
469
|
-
|
|
482
|
+
h(t);
|
|
470
483
|
}
|
|
471
484
|
}
|
|
472
|
-
class
|
|
485
|
+
class E extends HTMLElement {
|
|
486
|
+
shadow;
|
|
487
|
+
container;
|
|
488
|
+
welcomeMessage = "";
|
|
489
|
+
showTimestamps = !0;
|
|
473
490
|
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" });
|
|
491
|
+
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
480
492
|
}
|
|
481
493
|
connectedCallback() {
|
|
482
494
|
this.shadow.innerHTML = `
|
|
483
495
|
<style>
|
|
496
|
+
:host {
|
|
497
|
+
display: flex;
|
|
498
|
+
flex-direction: column;
|
|
499
|
+
min-height: 0;
|
|
500
|
+
}
|
|
484
501
|
.message-list {
|
|
485
502
|
flex: 1;
|
|
486
503
|
overflow-y: auto;
|
|
@@ -582,7 +599,7 @@ class H extends HTMLElement {
|
|
|
582
599
|
}
|
|
583
600
|
</style>
|
|
584
601
|
<div class="message-list"></div>
|
|
585
|
-
`, this.container = this.shadow.querySelector(".message-list");
|
|
602
|
+
`, this.container = this.shadow.querySelector(".message-list"), this.welcomeMessage && this.renderMessages([]);
|
|
586
603
|
}
|
|
587
604
|
setWelcomeMessage(e) {
|
|
588
605
|
this.welcomeMessage = e;
|
|
@@ -593,29 +610,25 @@ class H extends HTMLElement {
|
|
|
593
610
|
renderMessages(e) {
|
|
594
611
|
if (this.container) {
|
|
595
612
|
if (this.container.innerHTML = "", e.length === 0 && this.welcomeMessage) {
|
|
596
|
-
this.container.innerHTML = `<div class="welcome">${
|
|
613
|
+
this.container.innerHTML = `<div class="welcome">${l(o(this.welcomeMessage))}</div>`;
|
|
597
614
|
return;
|
|
598
615
|
}
|
|
599
|
-
for (const
|
|
600
|
-
this.appendMessageElement(
|
|
616
|
+
for (const t of e)
|
|
617
|
+
this.appendMessageElement(t);
|
|
601
618
|
this.scrollToBottom();
|
|
602
619
|
}
|
|
603
620
|
}
|
|
604
621
|
addMessage(e) {
|
|
605
|
-
const
|
|
606
|
-
|
|
622
|
+
const t = this.container.querySelector(".welcome");
|
|
623
|
+
t && t.remove(), this.appendMessageElement(e), this.scrollToBottom();
|
|
607
624
|
}
|
|
608
625
|
updateStreamingContent(e) {
|
|
609
|
-
const
|
|
610
|
-
|
|
626
|
+
const t = this.container.querySelector('[data-streaming="true"] .bubble');
|
|
627
|
+
t && (t.innerHTML = l(o(e)), t.classList.add("streaming-cursor"), this.scrollToBottom());
|
|
611
628
|
}
|
|
612
629
|
finalizeStreaming() {
|
|
613
630
|
const e = this.container.querySelector('[data-streaming="true"]');
|
|
614
|
-
|
|
615
|
-
e.removeAttribute("data-streaming");
|
|
616
|
-
const a = e.querySelector(".bubble");
|
|
617
|
-
a == null || a.classList.remove("streaming-cursor");
|
|
618
|
-
}
|
|
631
|
+
e && (e.removeAttribute("data-streaming"), e.querySelector(".bubble")?.classList.remove("streaming-cursor"));
|
|
619
632
|
}
|
|
620
633
|
showTypingIndicator() {
|
|
621
634
|
this.removeTypingIndicator();
|
|
@@ -623,18 +636,17 @@ class H extends HTMLElement {
|
|
|
623
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();
|
|
624
637
|
}
|
|
625
638
|
removeTypingIndicator() {
|
|
626
|
-
|
|
627
|
-
(e = this.container.querySelector('[data-typing="true"]')) == null || e.remove();
|
|
639
|
+
this.container.querySelector('[data-typing="true"]')?.remove();
|
|
628
640
|
}
|
|
629
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");
|
|
630
644
|
const a = document.createElement("div");
|
|
631
|
-
a.classList.add("
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
const n = document.createElement("div");
|
|
635
|
-
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);
|
|
636
648
|
}
|
|
637
|
-
this.container.appendChild(
|
|
649
|
+
this.container.appendChild(t);
|
|
638
650
|
}
|
|
639
651
|
scrollToBottom() {
|
|
640
652
|
requestAnimationFrame(() => {
|
|
@@ -649,15 +661,14 @@ class H extends HTMLElement {
|
|
|
649
661
|
}
|
|
650
662
|
}
|
|
651
663
|
}
|
|
652
|
-
class
|
|
653
|
-
|
|
654
|
-
super();
|
|
655
|
-
i(this, "shadow");
|
|
656
|
-
this.shadow = this.attachShadow({ mode: "open" });
|
|
657
|
-
}
|
|
664
|
+
class M extends HTMLElement {
|
|
665
|
+
shadow;
|
|
658
666
|
static get observedAttributes() {
|
|
659
667
|
return ["role", "content", "timestamp"];
|
|
660
668
|
}
|
|
669
|
+
constructor() {
|
|
670
|
+
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
671
|
+
}
|
|
661
672
|
connectedCallback() {
|
|
662
673
|
this.render();
|
|
663
674
|
}
|
|
@@ -665,7 +676,7 @@ class $ extends HTMLElement {
|
|
|
665
676
|
this.render();
|
|
666
677
|
}
|
|
667
678
|
render() {
|
|
668
|
-
const e = this.getAttribute("role") || "user",
|
|
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));
|
|
669
680
|
this.shadow.innerHTML = `
|
|
670
681
|
<style>
|
|
671
682
|
:host { display: flex; flex-direction: column; }
|
|
@@ -696,19 +707,18 @@ class $ extends HTMLElement {
|
|
|
696
707
|
padding: 0 4px;
|
|
697
708
|
}
|
|
698
709
|
</style>
|
|
699
|
-
<div class="bubble ${e}">${
|
|
700
|
-
${
|
|
710
|
+
<div class="bubble ${e}">${s}</div>
|
|
711
|
+
${a ? `<div class="timestamp">${a}</div>` : ""}
|
|
701
712
|
`;
|
|
702
713
|
}
|
|
703
714
|
}
|
|
704
|
-
class
|
|
715
|
+
class _ extends HTMLElement {
|
|
716
|
+
shadow;
|
|
717
|
+
textarea;
|
|
718
|
+
sendBtn;
|
|
719
|
+
_disabled = !1;
|
|
705
720
|
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" });
|
|
721
|
+
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
712
722
|
}
|
|
713
723
|
connectedCallback() {
|
|
714
724
|
const e = this.getAttribute("placeholder") || "Type a message...";
|
|
@@ -772,20 +782,18 @@ class z extends HTMLElement {
|
|
|
772
782
|
</div>
|
|
773
783
|
`, this.textarea = this.shadow.querySelector("textarea"), this.sendBtn = this.shadow.querySelector(".send-btn"), this.textarea.addEventListener("input", () => {
|
|
774
784
|
this.autoGrow(), this.sendBtn.disabled = this._disabled || !this.textarea.value.trim();
|
|
775
|
-
}), this.textarea.addEventListener("keydown", (
|
|
776
|
-
|
|
785
|
+
}), this.textarea.addEventListener("keydown", (t) => {
|
|
786
|
+
t.key === "Enter" && !t.shiftKey && (t.preventDefault(), this.handleSend());
|
|
777
787
|
}), this.sendBtn.addEventListener("click", () => this.handleSend());
|
|
778
788
|
}
|
|
779
789
|
set disabled(e) {
|
|
780
|
-
|
|
781
|
-
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());
|
|
782
791
|
}
|
|
783
792
|
get disabled() {
|
|
784
793
|
return this._disabled;
|
|
785
794
|
}
|
|
786
795
|
focus() {
|
|
787
|
-
|
|
788
|
-
(e = this.textarea) == null || e.focus();
|
|
796
|
+
this.textarea?.focus();
|
|
789
797
|
}
|
|
790
798
|
clear() {
|
|
791
799
|
this.textarea && (this.textarea.value = "", this.textarea.style.height = "auto", this.sendBtn.disabled = !0);
|
|
@@ -802,11 +810,10 @@ class z extends HTMLElement {
|
|
|
802
810
|
this.textarea.style.height = "auto", this.textarea.style.height = Math.min(this.textarea.scrollHeight, 120) + "px";
|
|
803
811
|
}
|
|
804
812
|
}
|
|
805
|
-
class
|
|
813
|
+
class H extends HTMLElement {
|
|
814
|
+
shadow;
|
|
806
815
|
constructor() {
|
|
807
|
-
super();
|
|
808
|
-
i(this, "shadow");
|
|
809
|
-
this.shadow = this.attachShadow({ mode: "open" });
|
|
816
|
+
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
810
817
|
}
|
|
811
818
|
connectedCallback() {
|
|
812
819
|
this.shadow.innerHTML = `
|
|
@@ -852,12 +859,11 @@ class B extends HTMLElement {
|
|
|
852
859
|
this.removeAttribute("visible");
|
|
853
860
|
}
|
|
854
861
|
}
|
|
855
|
-
class
|
|
862
|
+
class $ extends HTMLElement {
|
|
863
|
+
shadow;
|
|
864
|
+
bubble;
|
|
856
865
|
constructor() {
|
|
857
|
-
super();
|
|
858
|
-
i(this, "shadow");
|
|
859
|
-
i(this, "bubble");
|
|
860
|
-
this.shadow = this.attachShadow({ mode: "open" });
|
|
866
|
+
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
861
867
|
}
|
|
862
868
|
connectedCallback() {
|
|
863
869
|
this.shadow.innerHTML = `
|
|
@@ -912,23 +918,20 @@ class F extends HTMLElement {
|
|
|
912
918
|
`, this.bubble = this.shadow.querySelector(".bubble");
|
|
913
919
|
}
|
|
914
920
|
updateContent(e) {
|
|
915
|
-
this.bubble && (this.bubble.innerHTML =
|
|
921
|
+
this.bubble && (this.bubble.innerHTML = l(o(e)), this.bubble.classList.add("cursor"));
|
|
916
922
|
}
|
|
917
923
|
finalize() {
|
|
918
|
-
|
|
919
|
-
(e = this.bubble) == null || e.classList.remove("cursor");
|
|
924
|
+
this.bubble?.classList.remove("cursor");
|
|
920
925
|
}
|
|
921
926
|
}
|
|
922
|
-
class
|
|
927
|
+
class z extends HTMLElement {
|
|
928
|
+
shadow;
|
|
929
|
+
container;
|
|
930
|
+
dismissTimer = null;
|
|
923
931
|
constructor() {
|
|
924
|
-
super();
|
|
925
|
-
i(this, "shadow");
|
|
926
|
-
i(this, "container");
|
|
927
|
-
i(this, "dismissTimer", null);
|
|
928
|
-
this.shadow = this.attachShadow({ mode: "open" });
|
|
932
|
+
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
929
933
|
}
|
|
930
934
|
connectedCallback() {
|
|
931
|
-
var e;
|
|
932
935
|
this.shadow.innerHTML = `
|
|
933
936
|
<style>
|
|
934
937
|
.banner {
|
|
@@ -957,41 +960,41 @@ class q extends HTMLElement {
|
|
|
957
960
|
<span class="message"></span>
|
|
958
961
|
<button class="dismiss">Dismiss</button>
|
|
959
962
|
</div>
|
|
960
|
-
`, this.container = this.shadow.querySelector(".banner"),
|
|
963
|
+
`, this.container = this.shadow.querySelector(".banner"), this.shadow.querySelector(".dismiss")?.addEventListener("click", () => this.hide());
|
|
961
964
|
}
|
|
962
|
-
show(e,
|
|
963
|
-
const
|
|
964
|
-
|
|
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));
|
|
965
968
|
}
|
|
966
969
|
hide() {
|
|
967
970
|
this.container.classList.remove("visible"), this.dismissTimer && (clearTimeout(this.dismissTimer), this.dismissTimer = null);
|
|
968
971
|
}
|
|
969
972
|
}
|
|
970
|
-
function
|
|
971
|
-
const
|
|
972
|
-
["aikaara-chat-widget",
|
|
973
|
-
["aikaara-chat-bubble",
|
|
974
|
-
["aikaara-chat-header",
|
|
975
|
-
["aikaara-message-list",
|
|
976
|
-
["aikaara-message-bubble",
|
|
977
|
-
["aikaara-chat-input",
|
|
978
|
-
["aikaara-typing-indicator",
|
|
979
|
-
["aikaara-streaming-message",
|
|
980
|
-
["aikaara-error-banner",
|
|
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]
|
|
981
984
|
];
|
|
982
|
-
for (const [
|
|
983
|
-
customElements.get(
|
|
985
|
+
for (const [e, t] of i)
|
|
986
|
+
customElements.get(e) || customElements.define(e, t);
|
|
984
987
|
}
|
|
985
|
-
|
|
988
|
+
B();
|
|
986
989
|
export {
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
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
|
|
997
1000
|
};
|