@aikaara/chat-sdk 0.3.0 → 0.4.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/MountTenant-5CL6i2El.mjs +13712 -0
- package/dist/MountTenant-dM6HzlAl.cjs +792 -0
- package/dist/headless.cjs +1 -1
- package/dist/headless.d.ts +766 -1
- package/dist/headless.mjs +24 -51
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +377 -1
- package/dist/index.mjs +40 -35
- package/dist/ui.cjs +1 -621
- package/dist/ui.d.ts +334 -7
- package/dist/ui.mjs +17 -1232
- package/package.json +1 -1
- package/dist/AikaaraChatClient-Cqbcd1jb.mjs +0 -11538
- package/dist/AikaaraChatClient-kAu65hX-.cjs +0 -8
- package/dist/cdn/aikaara-chat.iife.js +0 -628
package/dist/ui.mjs
CHANGED
|
@@ -1,1234 +1,19 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
class E {
|
|
3
|
-
client;
|
|
4
|
-
panel;
|
|
5
|
-
bubble;
|
|
6
|
-
header;
|
|
7
|
-
messageList;
|
|
8
|
-
input;
|
|
9
|
-
errorBanner;
|
|
10
|
-
isOpen = !1;
|
|
11
|
-
constructor(e, t, a) {
|
|
12
|
-
this.client = new k(e, { uploadAdapter: a?.uploadAdapter }), 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();
|
|
13
|
-
}
|
|
14
|
-
async connect() {
|
|
15
|
-
try {
|
|
16
|
-
await this.client.connect(), this.messageList.renderMessages(this.client.messages);
|
|
17
|
-
} catch {
|
|
18
|
-
this.errorBanner.show("Failed to connect. Retrying...", 5e3);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
async disconnect() {
|
|
22
|
-
await this.client.disconnect();
|
|
23
|
-
}
|
|
24
|
-
wireEvents() {
|
|
25
|
-
this.bubble.addEventListener("toggle", () => {
|
|
26
|
-
this.togglePanel();
|
|
27
|
-
}), this.header.addEventListener("header-close", () => {
|
|
28
|
-
this.togglePanel(!1);
|
|
29
|
-
}), this.input.addEventListener("send", ((e) => {
|
|
30
|
-
this.handleSend(e.detail.content);
|
|
31
|
-
})), this.client.on("message:sent", (e) => {
|
|
32
|
-
this.messageList.addMessage(e);
|
|
33
|
-
}), this.client.on("stream:start", () => {
|
|
34
|
-
this.messageList.removeTypingIndicator();
|
|
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);
|
|
39
|
-
}), this.client.on("stream:end", () => {
|
|
40
|
-
this.messageList.finalizeStreaming();
|
|
41
|
-
}), this.client.on("typing:start", () => {
|
|
42
|
-
const e = this.client.messages, t = e[e.length - 1];
|
|
43
|
-
(!t || t.status !== "streaming") && this.messageList.showTypingIndicator();
|
|
44
|
-
}), this.client.on("typing:stop", () => {
|
|
45
|
-
this.messageList.removeTypingIndicator();
|
|
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);
|
|
50
|
-
}), this.client.on("message:received", (e) => {
|
|
51
|
-
this.messageList.upsertMessage(e);
|
|
52
|
-
}), this.client.on("message:updated", (e) => {
|
|
53
|
-
this.messageList.upsertMessage(e);
|
|
54
|
-
}), this.messageList.addEventListener("message-action", (e) => {
|
|
55
|
-
const t = e.detail;
|
|
56
|
-
t?.text && this.handleSend(t.text);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
async handleSend(e) {
|
|
60
|
-
try {
|
|
61
|
-
await this.client.sendMessage(e);
|
|
62
|
-
} catch {
|
|
63
|
-
this.errorBanner.show("Failed to send message", 3e3);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
sendUserEvent(e, t, a) {
|
|
67
|
-
this.client.sendUserEvent(e, t, a);
|
|
68
|
-
}
|
|
69
|
-
getClient() {
|
|
70
|
-
return this.client;
|
|
71
|
-
}
|
|
72
|
-
togglePanel(e) {
|
|
73
|
-
this.isOpen = e !== void 0 ? e : !this.isOpen, this.isOpen ? (this.panel.removeAttribute("hidden"), requestAnimationFrame(() => {
|
|
74
|
-
this.panel.classList.remove("entering"), this.panel.classList.add("visible"), this.input.focus();
|
|
75
|
-
})) : (this.panel.classList.remove("visible"), this.panel.classList.add("entering"), setTimeout(() => {
|
|
76
|
-
this.panel.setAttribute("hidden", "");
|
|
77
|
-
}, 200));
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
class S extends HTMLElement {
|
|
81
|
-
shadow;
|
|
82
|
-
controller = null;
|
|
83
|
-
_config = {};
|
|
84
|
-
static get observedAttributes() {
|
|
85
|
-
return [
|
|
86
|
-
"base-url",
|
|
87
|
-
"ws-url",
|
|
88
|
-
"user-token",
|
|
89
|
-
"api-key",
|
|
90
|
-
"title",
|
|
91
|
-
"subtitle",
|
|
92
|
-
"theme",
|
|
93
|
-
"primary-color",
|
|
94
|
-
"position",
|
|
95
|
-
"width",
|
|
96
|
-
"height",
|
|
97
|
-
"placeholder",
|
|
98
|
-
"welcome-message",
|
|
99
|
-
"avatar-url"
|
|
100
|
-
];
|
|
101
|
-
}
|
|
102
|
-
constructor() {
|
|
103
|
-
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
104
|
-
}
|
|
105
|
-
connectedCallback() {
|
|
106
|
-
this.render(), this.initController();
|
|
107
|
-
}
|
|
108
|
-
disconnectedCallback() {
|
|
109
|
-
this.controller?.disconnect();
|
|
110
|
-
}
|
|
111
|
-
attributeChangedCallback(e, t, a) {
|
|
112
|
-
t !== a && this.controller && (this.render(), this.initController());
|
|
113
|
-
}
|
|
114
|
-
configure(e) {
|
|
115
|
-
this._config = { ...this._config, ...e };
|
|
116
|
-
}
|
|
117
|
-
getConfig() {
|
|
118
|
-
return {
|
|
119
|
-
baseUrl: this.getAttribute("base-url") || this._config.baseUrl || "",
|
|
120
|
-
wsUrl: this.getAttribute("ws-url") || this._config.wsUrl,
|
|
121
|
-
userToken: this.getAttribute("user-token") || this._config.userToken || "",
|
|
122
|
-
apiKey: this.getAttribute("api-key") || this._config.apiKey,
|
|
123
|
-
title: this.getAttribute("title") || this._config.title || "Chat",
|
|
124
|
-
subtitle: this.getAttribute("subtitle") || this._config.subtitle,
|
|
125
|
-
theme: this.getAttribute("theme") || this._config.theme || A,
|
|
126
|
-
primaryColor: this.getAttribute("primary-color") || this._config.primaryColor || b,
|
|
127
|
-
position: this.getAttribute("position") || this._config.position || L,
|
|
128
|
-
width: Number(this.getAttribute("width")) || this._config.width || C,
|
|
129
|
-
height: Number(this.getAttribute("height")) || this._config.height || T,
|
|
130
|
-
fontFamily: this._config.fontFamily || w,
|
|
131
|
-
borderRadius: this._config.borderRadius ?? v,
|
|
132
|
-
placeholder: this.getAttribute("placeholder") || this._config.placeholder || u,
|
|
133
|
-
welcomeMessage: this.getAttribute("welcome-message") || this._config.welcomeMessage,
|
|
134
|
-
avatarUrl: this.getAttribute("avatar-url") || this._config.avatarUrl,
|
|
135
|
-
showTimestamps: this._config.showTimestamps ?? !0,
|
|
136
|
-
persistConversation: this._config.persistConversation ?? !0,
|
|
137
|
-
showBubble: this._config.showBubble ?? !0,
|
|
138
|
-
offset: this._config.offset || y,
|
|
139
|
-
conversationId: this._config.conversationId,
|
|
140
|
-
systemPromptId: this._config.systemPromptId,
|
|
141
|
-
channel: this._config.channel,
|
|
142
|
-
extUid: this._config.extUid,
|
|
143
|
-
transport: this._config.transport,
|
|
144
|
-
tiledesk: this._config.tiledesk,
|
|
145
|
-
tiledeskIdentity: this._config.tiledeskIdentity,
|
|
146
|
-
onMessage: this._config.onMessage,
|
|
147
|
-
onStatusChange: this._config.onStatusChange,
|
|
148
|
-
onError: this._config.onError,
|
|
149
|
-
onStreamUpdate: this._config.onStreamUpdate,
|
|
150
|
-
onConnectionStateChange: this._config.onConnectionStateChange,
|
|
151
|
-
onTemplateMessage: this._config.onTemplateMessage
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
setUploadAdapter(e) {
|
|
155
|
-
this._config.uploadAdapter = e, this.controller?.getClient().setUploadAdapter(e);
|
|
156
|
-
}
|
|
157
|
-
render() {
|
|
158
|
-
const e = this.getConfig();
|
|
159
|
-
this.shadow.innerHTML = `
|
|
160
|
-
<style>
|
|
161
|
-
:host {
|
|
162
|
-
--aikaara-primary: ${e.primaryColor};
|
|
163
|
-
--aikaara-primary-hover: ${this.darkenColor(e.primaryColor || b)};
|
|
164
|
-
--aikaara-bg: #ffffff;
|
|
165
|
-
--aikaara-bg-secondary: #f9fafb;
|
|
166
|
-
--aikaara-text: #1f2937;
|
|
167
|
-
--aikaara-text-secondary: #6b7280;
|
|
168
|
-
--aikaara-border: #e5e7eb;
|
|
169
|
-
--aikaara-radius: ${e.borderRadius}px;
|
|
170
|
-
--aikaara-font: ${e.fontFamily};
|
|
171
|
-
--aikaara-panel-width: ${e.width}px;
|
|
172
|
-
--aikaara-panel-height: ${e.height}px;
|
|
173
|
-
--aikaara-bubble-size: 60px;
|
|
174
|
-
--aikaara-offset-x: ${e.offset?.x ?? 20}px;
|
|
175
|
-
--aikaara-offset-y: ${e.offset?.y ?? 20}px;
|
|
176
|
-
font-family: var(--aikaara-font);
|
|
177
|
-
position: fixed;
|
|
178
|
-
z-index: 9999;
|
|
179
|
-
bottom: var(--aikaara-offset-y);
|
|
180
|
-
${e.position === "bottom-left" ? "left" : "right"}: var(--aikaara-offset-x);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
.aikaara-panel {
|
|
184
|
-
width: var(--aikaara-panel-width);
|
|
185
|
-
height: var(--aikaara-panel-height);
|
|
186
|
-
max-height: calc(100vh - 100px);
|
|
187
|
-
background: var(--aikaara-bg);
|
|
188
|
-
border-radius: var(--aikaara-radius);
|
|
189
|
-
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
|
|
190
|
-
border: 1px solid var(--aikaara-border);
|
|
191
|
-
display: flex;
|
|
192
|
-
flex-direction: column;
|
|
193
|
-
overflow: hidden;
|
|
194
|
-
position: absolute;
|
|
195
|
-
bottom: calc(var(--aikaara-bubble-size) + 16px);
|
|
196
|
-
${e.position === "bottom-left" ? "left" : "right"}: 0;
|
|
197
|
-
transition: opacity 200ms ease, transform 200ms ease;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
.aikaara-panel[hidden] {
|
|
201
|
-
display: none;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
.aikaara-panel.entering {
|
|
205
|
-
opacity: 0;
|
|
206
|
-
transform: translateY(8px) scale(0.98);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
.aikaara-panel.visible {
|
|
210
|
-
opacity: 1;
|
|
211
|
-
transform: translateY(0) scale(1);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
aikaara-chat-header,
|
|
215
|
-
aikaara-message-list,
|
|
216
|
-
aikaara-chat-input,
|
|
217
|
-
aikaara-error-banner {
|
|
218
|
-
display: block;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
aikaara-message-list {
|
|
222
|
-
flex: 1;
|
|
223
|
-
overflow: scroll;
|
|
224
|
-
min-height: 0;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
aikaara-chat-input {
|
|
228
|
-
flex-shrink: 0;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
aikaara-chat-header {
|
|
232
|
-
flex-shrink: 0;
|
|
233
|
-
}
|
|
234
|
-
</style>
|
|
235
|
-
|
|
236
|
-
<aikaara-chat-bubble></aikaara-chat-bubble>
|
|
237
|
-
|
|
238
|
-
<div class="aikaara-panel entering" hidden role="dialog" aria-label="Chat">
|
|
239
|
-
<aikaara-chat-header
|
|
240
|
-
title="${e.title || "Chat"}"
|
|
241
|
-
${e.subtitle ? `subtitle="${e.subtitle}"` : ""}
|
|
242
|
-
${e.avatarUrl ? `avatar-url="${e.avatarUrl}"` : ""}
|
|
243
|
-
></aikaara-chat-header>
|
|
244
|
-
<aikaara-message-list></aikaara-message-list>
|
|
245
|
-
<aikaara-chat-input placeholder="${e.placeholder || u}"></aikaara-chat-input>
|
|
246
|
-
<aikaara-error-banner></aikaara-error-banner>
|
|
247
|
-
</div>
|
|
248
|
-
`;
|
|
249
|
-
}
|
|
250
|
-
async initController() {
|
|
251
|
-
const e = this.getConfig();
|
|
252
|
-
!e.baseUrl || !e.userToken || (this.controller?.disconnect(), this.controller = new E(e, this.shadow, {
|
|
253
|
-
uploadAdapter: this._config.uploadAdapter
|
|
254
|
-
}), await this.controller.connect());
|
|
255
|
-
}
|
|
256
|
-
sendUserEvent(e, t, a) {
|
|
257
|
-
this.controller?.sendUserEvent(e, t, a);
|
|
258
|
-
}
|
|
259
|
-
getClient() {
|
|
260
|
-
return this.controller?.getClient() ?? null;
|
|
261
|
-
}
|
|
262
|
-
darkenColor(e) {
|
|
263
|
-
try {
|
|
264
|
-
const t = parseInt(e.replace("#", ""), 16), a = Math.max(0, (t >> 16) - 20), i = Math.max(0, (t >> 8 & 255) - 20), r = Math.max(0, (t & 255) - 20);
|
|
265
|
-
return `#${(a << 16 | i << 8 | r).toString(16).padStart(6, "0")}`;
|
|
266
|
-
} catch {
|
|
267
|
-
return e;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
class M extends HTMLElement {
|
|
272
|
-
shadow;
|
|
273
|
-
constructor() {
|
|
274
|
-
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
275
|
-
}
|
|
276
|
-
connectedCallback() {
|
|
277
|
-
this.render(), this.shadow.querySelector(".bubble")?.addEventListener("click", () => {
|
|
278
|
-
this.dispatchEvent(new CustomEvent("toggle", { bubbles: !0, composed: !0 }));
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
render() {
|
|
282
|
-
this.shadow.innerHTML = `
|
|
283
|
-
<style>
|
|
284
|
-
.bubble {
|
|
285
|
-
width: var(--aikaara-bubble-size, 60px);
|
|
286
|
-
height: var(--aikaara-bubble-size, 60px);
|
|
287
|
-
border-radius: 50%;
|
|
288
|
-
background: var(--aikaara-primary, #6366f1);
|
|
289
|
-
color: #ffffff;
|
|
290
|
-
border: none;
|
|
291
|
-
cursor: pointer;
|
|
292
|
-
display: flex;
|
|
293
|
-
align-items: center;
|
|
294
|
-
justify-content: center;
|
|
295
|
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
296
|
-
transition: transform 200ms ease, box-shadow 200ms ease;
|
|
297
|
-
}
|
|
298
|
-
.bubble:hover {
|
|
299
|
-
transform: scale(1.05);
|
|
300
|
-
box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
|
|
301
|
-
}
|
|
302
|
-
.bubble svg {
|
|
303
|
-
width: 28px;
|
|
304
|
-
height: 28px;
|
|
305
|
-
}
|
|
306
|
-
.bubble-text {
|
|
307
|
-
font-family: var(--aikaara-font, system-ui, sans-serif);
|
|
308
|
-
font-size: 12px;
|
|
309
|
-
font-weight: 500;
|
|
310
|
-
}
|
|
311
|
-
</style>
|
|
312
|
-
<button class="bubble" aria-label="Open chat">
|
|
313
|
-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
314
|
-
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>
|
|
315
|
-
</svg>
|
|
316
|
-
</button>
|
|
317
|
-
`;
|
|
318
|
-
}
|
|
319
|
-
setIcon(e) {
|
|
320
|
-
const t = this.shadow.querySelector(".bubble");
|
|
321
|
-
t && (t.innerHTML = e);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
class _ extends HTMLElement {
|
|
325
|
-
shadow;
|
|
326
|
-
static get observedAttributes() {
|
|
327
|
-
return ["title", "subtitle", "avatar-url", "status"];
|
|
328
|
-
}
|
|
329
|
-
constructor() {
|
|
330
|
-
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
331
|
-
}
|
|
332
|
-
connectedCallback() {
|
|
333
|
-
this.render(), this.bindClose();
|
|
334
|
-
}
|
|
335
|
-
attributeChangedCallback() {
|
|
336
|
-
this.render(), this.bindClose();
|
|
337
|
-
}
|
|
338
|
-
bindClose() {
|
|
339
|
-
this.shadow.querySelector(".close-btn")?.addEventListener("click", () => {
|
|
340
|
-
this.dispatchEvent(new CustomEvent("header-close", { bubbles: !0, composed: !0 }));
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
render() {
|
|
344
|
-
const e = this.getAttribute("title") || "Chat", t = this.getAttribute("subtitle") || "", a = this.getAttribute("avatar-url"), i = this.getAttribute("status") || "connected", r = i === "connected" ? "#10b981" : i === "connecting" || i === "reconnecting" ? "#f59e0b" : "#ef4444";
|
|
345
|
-
this.shadow.innerHTML = `
|
|
346
|
-
<style>
|
|
347
|
-
.header {
|
|
348
|
-
display: flex;
|
|
349
|
-
align-items: center;
|
|
350
|
-
gap: 12px;
|
|
351
|
-
padding: 14px 16px;
|
|
352
|
-
background: var(--aikaara-primary, #6366f1);
|
|
353
|
-
color: #ffffff;
|
|
354
|
-
flex-shrink: 0;
|
|
355
|
-
}
|
|
356
|
-
.avatar {
|
|
357
|
-
width: 36px;
|
|
358
|
-
height: 36px;
|
|
359
|
-
border-radius: 50%;
|
|
360
|
-
background: rgba(255,255,255,0.2);
|
|
361
|
-
display: flex;
|
|
362
|
-
align-items: center;
|
|
363
|
-
justify-content: center;
|
|
364
|
-
flex-shrink: 0;
|
|
365
|
-
overflow: hidden;
|
|
366
|
-
}
|
|
367
|
-
.avatar img {
|
|
368
|
-
width: 100%;
|
|
369
|
-
height: 100%;
|
|
370
|
-
object-fit: cover;
|
|
371
|
-
}
|
|
372
|
-
.avatar svg {
|
|
373
|
-
width: 20px;
|
|
374
|
-
height: 20px;
|
|
375
|
-
}
|
|
376
|
-
.info {
|
|
377
|
-
flex: 1;
|
|
378
|
-
min-width: 0;
|
|
379
|
-
}
|
|
380
|
-
.title {
|
|
381
|
-
font-size: 15px;
|
|
382
|
-
font-weight: 600;
|
|
383
|
-
line-height: 1.2;
|
|
384
|
-
display: flex;
|
|
385
|
-
align-items: center;
|
|
386
|
-
gap: 6px;
|
|
387
|
-
}
|
|
388
|
-
.status-dot {
|
|
389
|
-
width: 8px;
|
|
390
|
-
height: 8px;
|
|
391
|
-
border-radius: 50%;
|
|
392
|
-
flex-shrink: 0;
|
|
393
|
-
}
|
|
394
|
-
.subtitle {
|
|
395
|
-
font-size: 12px;
|
|
396
|
-
opacity: 0.85;
|
|
397
|
-
white-space: nowrap;
|
|
398
|
-
overflow: hidden;
|
|
399
|
-
text-overflow: ellipsis;
|
|
400
|
-
}
|
|
401
|
-
.close-btn {
|
|
402
|
-
background: none;
|
|
403
|
-
border: none;
|
|
404
|
-
color: #ffffff;
|
|
405
|
-
cursor: pointer;
|
|
406
|
-
padding: 4px;
|
|
407
|
-
border-radius: 4px;
|
|
408
|
-
display: flex;
|
|
409
|
-
align-items: center;
|
|
410
|
-
justify-content: center;
|
|
411
|
-
opacity: 0.8;
|
|
412
|
-
transition: opacity 200ms;
|
|
413
|
-
}
|
|
414
|
-
.close-btn:hover {
|
|
415
|
-
opacity: 1;
|
|
416
|
-
}
|
|
417
|
-
.close-btn svg {
|
|
418
|
-
width: 20px;
|
|
419
|
-
height: 20px;
|
|
420
|
-
}
|
|
421
|
-
</style>
|
|
422
|
-
<div class="header">
|
|
423
|
-
<div class="avatar">
|
|
424
|
-
${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>'}
|
|
425
|
-
</div>
|
|
426
|
-
<div class="info">
|
|
427
|
-
<div class="title">
|
|
428
|
-
${e}
|
|
429
|
-
<span class="status-dot" style="background:${r}"></span>
|
|
430
|
-
</div>
|
|
431
|
-
${t ? `<div class="subtitle">${t}</div>` : ""}
|
|
432
|
-
</div>
|
|
433
|
-
<button class="close-btn" aria-label="Close chat">
|
|
434
|
-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
435
|
-
<line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/>
|
|
436
|
-
</svg>
|
|
437
|
-
</button>
|
|
438
|
-
</div>
|
|
439
|
-
`;
|
|
440
|
-
}
|
|
441
|
-
setStatus(e) {
|
|
442
|
-
this.setAttribute("status", e);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
function l(s) {
|
|
446
|
-
let e = $(s);
|
|
447
|
-
return e = e.replace(/```(\w*)\n([\s\S]*?)```/g, (t, a, i) => `<pre><code>${i.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(
|
|
448
|
-
/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g,
|
|
449
|
-
'<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'
|
|
450
|
-
), e = e.replace(/\n/g, "<br>"), e;
|
|
451
|
-
}
|
|
452
|
-
function $(s) {
|
|
453
|
-
const e = {
|
|
454
|
-
"&": "&",
|
|
455
|
-
"<": "<",
|
|
456
|
-
">": ">",
|
|
457
|
-
'"': """,
|
|
458
|
-
"'": "'"
|
|
459
|
-
};
|
|
460
|
-
return s.replace(/[&<>"']/g, (t) => e[t]);
|
|
461
|
-
}
|
|
462
|
-
const H = /* @__PURE__ */ new Set([
|
|
463
|
-
"p",
|
|
464
|
-
"br",
|
|
465
|
-
"strong",
|
|
466
|
-
"em",
|
|
467
|
-
"code",
|
|
468
|
-
"pre",
|
|
469
|
-
"a",
|
|
470
|
-
"ul",
|
|
471
|
-
"ol",
|
|
472
|
-
"li",
|
|
473
|
-
"blockquote",
|
|
474
|
-
"h1",
|
|
475
|
-
"h2",
|
|
476
|
-
"h3",
|
|
477
|
-
"h4",
|
|
478
|
-
"h5",
|
|
479
|
-
"h6",
|
|
480
|
-
"span",
|
|
481
|
-
"div"
|
|
482
|
-
]), z = {
|
|
483
|
-
a: /* @__PURE__ */ new Set(["href", "target", "rel"]),
|
|
484
|
-
code: /* @__PURE__ */ new Set(["class"]),
|
|
485
|
-
pre: /* @__PURE__ */ new Set(["class"]),
|
|
486
|
-
span: /* @__PURE__ */ new Set(["class"]),
|
|
487
|
-
div: /* @__PURE__ */ new Set(["class"])
|
|
488
|
-
};
|
|
489
|
-
function d(s) {
|
|
490
|
-
const e = document.createElement("template");
|
|
491
|
-
return e.innerHTML = s, g(e.content), e.innerHTML;
|
|
492
|
-
}
|
|
493
|
-
function g(s) {
|
|
494
|
-
const e = Array.from(s.childNodes);
|
|
495
|
-
for (const t of e)
|
|
496
|
-
if (t.nodeType === Node.ELEMENT_NODE) {
|
|
497
|
-
const a = t, i = a.tagName.toLowerCase();
|
|
498
|
-
if (!H.has(i)) {
|
|
499
|
-
const n = document.createTextNode(a.textContent || "");
|
|
500
|
-
s.replaceChild(n, t);
|
|
501
|
-
continue;
|
|
502
|
-
}
|
|
503
|
-
const r = z[i] || /* @__PURE__ */ new Set(), o = Array.from(a.attributes);
|
|
504
|
-
for (const n of o)
|
|
505
|
-
r.has(n.name) || a.removeAttribute(n.name);
|
|
506
|
-
if (a.hasAttribute("href")) {
|
|
507
|
-
const n = a.getAttribute("href") || "";
|
|
508
|
-
!n.startsWith("http://") && !n.startsWith("https://") && !n.startsWith("/") && a.removeAttribute("href");
|
|
509
|
-
}
|
|
510
|
-
g(t);
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
class I extends HTMLElement {
|
|
514
|
-
shadow;
|
|
515
|
-
container;
|
|
516
|
-
welcomeMessage = "";
|
|
517
|
-
showTimestamps = !0;
|
|
518
|
-
constructor() {
|
|
519
|
-
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
520
|
-
}
|
|
521
|
-
connectedCallback() {
|
|
522
|
-
this.shadow.innerHTML = `
|
|
523
|
-
<style>
|
|
524
|
-
:host {
|
|
525
|
-
display: flex;
|
|
526
|
-
flex-direction: column;
|
|
527
|
-
min-height: 0;
|
|
528
|
-
}
|
|
529
|
-
.message-list {
|
|
530
|
-
flex: 1;
|
|
531
|
-
overflow-y: auto;
|
|
532
|
-
padding: 16px;
|
|
533
|
-
display: flex;
|
|
534
|
-
flex-direction: column;
|
|
535
|
-
gap: 8px;
|
|
536
|
-
scroll-behavior: smooth;
|
|
537
|
-
}
|
|
538
|
-
.message-list::-webkit-scrollbar { width: 6px; }
|
|
539
|
-
.message-list::-webkit-scrollbar-track { background: transparent; }
|
|
540
|
-
.message-list::-webkit-scrollbar-thumb { background: var(--aikaara-border, #e5e7eb); border-radius: 3px; }
|
|
541
|
-
.message-wrap { display: flex; flex-direction: column; }
|
|
542
|
-
.message-wrap.user { align-items: flex-end; }
|
|
543
|
-
.message-wrap.assistant,
|
|
544
|
-
.message-wrap.agent,
|
|
545
|
-
.message-wrap.system { align-items: flex-start; }
|
|
546
|
-
.message-wrap.system .bubble {
|
|
547
|
-
background: transparent;
|
|
548
|
-
color: var(--aikaara-text-secondary, #6b7280);
|
|
549
|
-
font-size: 12px;
|
|
550
|
-
font-style: italic;
|
|
551
|
-
padding: 4px 0;
|
|
552
|
-
}
|
|
553
|
-
.attachments {
|
|
554
|
-
display: flex;
|
|
555
|
-
flex-direction: column;
|
|
556
|
-
gap: 4px;
|
|
557
|
-
margin-top: 6px;
|
|
558
|
-
}
|
|
559
|
-
.attachment {
|
|
560
|
-
display: inline-flex;
|
|
561
|
-
align-items: center;
|
|
562
|
-
gap: 6px;
|
|
563
|
-
padding: 6px 10px;
|
|
564
|
-
background: rgba(0,0,0,0.05);
|
|
565
|
-
border-radius: 8px;
|
|
566
|
-
font-size: 12px;
|
|
567
|
-
color: inherit;
|
|
568
|
-
text-decoration: none;
|
|
569
|
-
}
|
|
570
|
-
.attachment:hover { background: rgba(0,0,0,0.08); }
|
|
571
|
-
.status-tick {
|
|
572
|
-
font-size: 10px;
|
|
573
|
-
margin-left: 4px;
|
|
574
|
-
color: var(--aikaara-text-secondary, #6b7280);
|
|
575
|
-
}
|
|
576
|
-
.status-tick.read { color: var(--aikaara-primary, #6366f1); }
|
|
577
|
-
aikaara-template-renderer { display: block; margin-top: 6px; }
|
|
578
|
-
.bubble {
|
|
579
|
-
max-width: 85%;
|
|
580
|
-
padding: 10px 14px;
|
|
581
|
-
border-radius: var(--aikaara-radius, 12px);
|
|
582
|
-
font-size: 14px;
|
|
583
|
-
line-height: 1.5;
|
|
584
|
-
word-wrap: break-word;
|
|
585
|
-
overflow-wrap: break-word;
|
|
586
|
-
}
|
|
587
|
-
.bubble.user {
|
|
588
|
-
background: var(--aikaara-primary, #6366f1);
|
|
589
|
-
color: #ffffff;
|
|
590
|
-
border-bottom-right-radius: 4px;
|
|
591
|
-
}
|
|
592
|
-
.bubble.assistant {
|
|
593
|
-
background: var(--aikaara-bg-secondary, #f9fafb);
|
|
594
|
-
color: var(--aikaara-text, #1f2937);
|
|
595
|
-
border-bottom-left-radius: 4px;
|
|
596
|
-
}
|
|
597
|
-
.bubble pre {
|
|
598
|
-
background: rgba(0,0,0,0.06);
|
|
599
|
-
padding: 8px 12px;
|
|
600
|
-
border-radius: 6px;
|
|
601
|
-
overflow-x: auto;
|
|
602
|
-
font-size: 13px;
|
|
603
|
-
margin: 8px 0;
|
|
604
|
-
}
|
|
605
|
-
.bubble code {
|
|
606
|
-
font-family: 'SF Mono', 'Fira Code', monospace;
|
|
607
|
-
font-size: 13px;
|
|
608
|
-
}
|
|
609
|
-
.bubble.assistant code:not(pre code) {
|
|
610
|
-
background: rgba(0,0,0,0.06);
|
|
611
|
-
padding: 2px 4px;
|
|
612
|
-
border-radius: 3px;
|
|
613
|
-
}
|
|
614
|
-
.bubble a { color: inherit; text-decoration: underline; }
|
|
615
|
-
.timestamp {
|
|
616
|
-
font-size: 11px;
|
|
617
|
-
color: var(--aikaara-text-secondary, #6b7280);
|
|
618
|
-
margin-top: 2px;
|
|
619
|
-
padding: 0 4px;
|
|
620
|
-
}
|
|
621
|
-
.welcome {
|
|
622
|
-
text-align: center;
|
|
623
|
-
color: var(--aikaara-text-secondary, #6b7280);
|
|
624
|
-
font-size: 14px;
|
|
625
|
-
padding: 24px 16px;
|
|
626
|
-
}
|
|
627
|
-
.streaming-cursor::after {
|
|
628
|
-
content: '\\25CF';
|
|
629
|
-
animation: blink 1s infinite;
|
|
630
|
-
margin-left: 2px;
|
|
631
|
-
font-size: 10px;
|
|
632
|
-
vertical-align: middle;
|
|
633
|
-
}
|
|
634
|
-
@keyframes blink {
|
|
635
|
-
0%, 100% { opacity: 1; }
|
|
636
|
-
50% { opacity: 0; }
|
|
637
|
-
}
|
|
638
|
-
.typing-indicator {
|
|
639
|
-
display: flex;
|
|
640
|
-
align-items: center;
|
|
641
|
-
gap: 4px;
|
|
642
|
-
padding: 10px 14px;
|
|
643
|
-
align-self: flex-start;
|
|
644
|
-
background: var(--aikaara-bg-secondary, #f9fafb);
|
|
645
|
-
border-radius: var(--aikaara-radius, 12px);
|
|
646
|
-
border-bottom-left-radius: 4px;
|
|
647
|
-
}
|
|
648
|
-
.typing-indicator .dot {
|
|
649
|
-
width: 6px;
|
|
650
|
-
height: 6px;
|
|
651
|
-
border-radius: 50%;
|
|
652
|
-
background: var(--aikaara-text-secondary, #6b7280);
|
|
653
|
-
animation: typing-bounce 1.4s infinite ease-in-out;
|
|
654
|
-
}
|
|
655
|
-
.typing-indicator .dot:nth-child(1) { animation-delay: 0ms; }
|
|
656
|
-
.typing-indicator .dot:nth-child(2) { animation-delay: 200ms; }
|
|
657
|
-
.typing-indicator .dot:nth-child(3) { animation-delay: 400ms; }
|
|
658
|
-
@keyframes typing-bounce {
|
|
659
|
-
0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
|
|
660
|
-
30% { transform: translateY(-4px); opacity: 1; }
|
|
661
|
-
}
|
|
662
|
-
</style>
|
|
663
|
-
<div class="message-list"></div>
|
|
664
|
-
`, this.container = this.shadow.querySelector(".message-list"), this.welcomeMessage && this.renderMessages([]);
|
|
665
|
-
}
|
|
666
|
-
setWelcomeMessage(e) {
|
|
667
|
-
this.welcomeMessage = e;
|
|
668
|
-
}
|
|
669
|
-
setShowTimestamps(e) {
|
|
670
|
-
this.showTimestamps = e;
|
|
671
|
-
}
|
|
672
|
-
renderMessages(e) {
|
|
673
|
-
if (this.container) {
|
|
674
|
-
if (this.container.innerHTML = "", e.length === 0 && this.welcomeMessage) {
|
|
675
|
-
this.container.innerHTML = `<div class="welcome">${d(l(this.welcomeMessage))}</div>`;
|
|
676
|
-
return;
|
|
677
|
-
}
|
|
678
|
-
for (const t of e)
|
|
679
|
-
this.appendMessageElement(t);
|
|
680
|
-
this.scrollToBottom();
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
addMessage(e) {
|
|
684
|
-
const t = this.container.querySelector(".welcome");
|
|
685
|
-
t && t.remove(), this.appendMessageElement(e), this.scrollToBottom();
|
|
686
|
-
}
|
|
687
|
-
updateStreamingContent(e) {
|
|
688
|
-
const t = this.container.querySelector('[data-streaming="true"] .bubble');
|
|
689
|
-
t && (t.innerHTML = d(l(e)), t.classList.add("streaming-cursor"), this.scrollToBottom());
|
|
690
|
-
}
|
|
691
|
-
finalizeStreaming() {
|
|
692
|
-
const e = this.container.querySelector('[data-streaming="true"]');
|
|
693
|
-
e && (e.removeAttribute("data-streaming"), e.querySelector(".bubble")?.classList.remove("streaming-cursor"));
|
|
694
|
-
}
|
|
695
|
-
showTypingIndicator() {
|
|
696
|
-
this.removeTypingIndicator();
|
|
697
|
-
const e = document.createElement("div");
|
|
698
|
-
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();
|
|
699
|
-
}
|
|
700
|
-
removeTypingIndicator() {
|
|
701
|
-
this.container.querySelector('[data-typing="true"]')?.remove();
|
|
702
|
-
}
|
|
703
|
-
appendMessageElement(e) {
|
|
704
|
-
const t = document.createElement("div");
|
|
705
|
-
t.classList.add("message-wrap", e.role), e.status === "streaming" && t.setAttribute("data-streaming", "true"), e.externalId && (t.dataset.externalId = e.externalId), t.dataset.messageId = e.id;
|
|
706
|
-
const a = document.createElement("div");
|
|
707
|
-
if (a.classList.add("bubble", e.role), e.role === "user" ? a.textContent = e.content : (a.innerHTML = d(l(e.content || "")), e.status === "streaming" && a.classList.add("streaming-cursor")), e.template?.contentType) {
|
|
708
|
-
const i = document.createElement("aikaara-template-renderer");
|
|
709
|
-
i.setAttribute("content-type", e.template.contentType), e.template.templateId && i.setAttribute("template-id", e.template.templateId), i.setPayload(e.template.payload, e.role !== "user" ? e.content : void 0), a.appendChild(i);
|
|
710
|
-
}
|
|
711
|
-
if (e.attachments?.length) {
|
|
712
|
-
const i = document.createElement("div");
|
|
713
|
-
i.classList.add("attachments");
|
|
714
|
-
for (const r of e.attachments) {
|
|
715
|
-
const o = document.createElement("a");
|
|
716
|
-
o.classList.add("attachment"), o.href = r.fileUrl, o.target = "_blank", o.rel = "noopener noreferrer", o.textContent = `📎 ${r.fileName}`, i.appendChild(o);
|
|
717
|
-
}
|
|
718
|
-
a.appendChild(i);
|
|
719
|
-
}
|
|
720
|
-
if (t.appendChild(a), this.showTimestamps && e.createdAt || e.role === "user" && e.status) {
|
|
721
|
-
const i = document.createElement("div");
|
|
722
|
-
if (i.classList.add("timestamp"), this.showTimestamps && e.createdAt && (i.textContent = this.formatTime(e.createdAt)), e.role === "user" && e.status) {
|
|
723
|
-
const r = document.createElement("span");
|
|
724
|
-
r.classList.add("status-tick"), e.status === "read" && r.classList.add("read"), r.textContent = {
|
|
725
|
-
sending: " ○",
|
|
726
|
-
sent: " ✓",
|
|
727
|
-
delivered: " ✓✓",
|
|
728
|
-
read: " ✓✓"
|
|
729
|
-
}[e.status] ?? "", i.appendChild(r);
|
|
730
|
-
}
|
|
731
|
-
t.appendChild(i);
|
|
732
|
-
}
|
|
733
|
-
this.container.appendChild(t);
|
|
734
|
-
}
|
|
735
|
-
/**
|
|
736
|
-
* Replace an existing rendered message (matched by id or externalId) in place.
|
|
737
|
-
* Used when a Tiledesk self-echo reconciles with an optimistic bubble or when
|
|
738
|
-
* a status update flips delivered → read.
|
|
739
|
-
*/
|
|
740
|
-
upsertMessage(e) {
|
|
741
|
-
const t = this.findRenderedMessage(e);
|
|
742
|
-
t && t.remove(), this.appendMessageElement(e), this.scrollToBottom();
|
|
743
|
-
}
|
|
744
|
-
findRenderedMessage(e) {
|
|
745
|
-
if (e.externalId) {
|
|
746
|
-
const t = this.container.querySelector(`[data-external-id="${CSS.escape(e.externalId)}"]`);
|
|
747
|
-
if (t) return t;
|
|
748
|
-
}
|
|
749
|
-
return this.container.querySelector(`[data-message-id="${CSS.escape(e.id)}"]`);
|
|
750
|
-
}
|
|
751
|
-
scrollToBottom() {
|
|
752
|
-
requestAnimationFrame(() => {
|
|
753
|
-
this.container.scrollTop = this.container.scrollHeight;
|
|
754
|
-
});
|
|
755
|
-
}
|
|
756
|
-
formatTime(e) {
|
|
757
|
-
try {
|
|
758
|
-
return new Date(e).toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit" });
|
|
759
|
-
} catch {
|
|
760
|
-
return "";
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
class U extends HTMLElement {
|
|
765
|
-
shadow;
|
|
766
|
-
templatePayload = null;
|
|
767
|
-
attachments = [];
|
|
768
|
-
static get observedAttributes() {
|
|
769
|
-
return ["role", "content", "timestamp", "content-type", "template-id", "inner-message", "message-id", "status"];
|
|
770
|
-
}
|
|
771
|
-
constructor() {
|
|
772
|
-
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
773
|
-
}
|
|
774
|
-
connectedCallback() {
|
|
775
|
-
this.render();
|
|
776
|
-
}
|
|
777
|
-
attributeChangedCallback() {
|
|
778
|
-
this.render();
|
|
779
|
-
}
|
|
780
|
-
setTemplatePayload(e) {
|
|
781
|
-
this.templatePayload = e, this.render();
|
|
782
|
-
}
|
|
783
|
-
setAttachments(e) {
|
|
784
|
-
this.attachments = e, this.render();
|
|
785
|
-
}
|
|
786
|
-
render() {
|
|
787
|
-
const e = this.getAttribute("role") || "user", t = this.getAttribute("content") || "", a = this.getAttribute("timestamp") || "", i = this.getAttribute("status") || "", r = this.getAttribute("content-type") || "", o = this.getAttribute("template-id") || "", n = this.getAttribute("inner-message") || "", h = e === "user" ? document.createTextNode(t).textContent || "" : d(l(t)), p = e === "user" && i, f = i === "sending" ? "○" : i === "sent" ? "✓" : i === "delivered" || i === "read" ? "✓✓" : "";
|
|
788
|
-
this.shadow.innerHTML = `
|
|
789
|
-
<style>
|
|
790
|
-
:host { display: flex; flex-direction: column; }
|
|
791
|
-
:host([role="user"]) { align-items: flex-end; }
|
|
792
|
-
:host([role="assistant"]),
|
|
793
|
-
:host([role="agent"]),
|
|
794
|
-
:host([role="system"]) { align-items: flex-start; }
|
|
795
|
-
.bubble {
|
|
796
|
-
max-width: 85%;
|
|
797
|
-
padding: 10px 14px;
|
|
798
|
-
border-radius: var(--aikaara-radius, 12px);
|
|
799
|
-
font-size: 14px;
|
|
800
|
-
line-height: 1.5;
|
|
801
|
-
word-wrap: break-word;
|
|
802
|
-
}
|
|
803
|
-
.bubble.user {
|
|
804
|
-
background: var(--aikaara-primary, #6366f1);
|
|
805
|
-
color: #fff;
|
|
806
|
-
border-bottom-right-radius: 4px;
|
|
807
|
-
}
|
|
808
|
-
.bubble.assistant, .bubble.agent {
|
|
809
|
-
background: var(--aikaara-bg-secondary, #f9fafb);
|
|
810
|
-
color: var(--aikaara-text, #1f2937);
|
|
811
|
-
border-bottom-left-radius: 4px;
|
|
812
|
-
}
|
|
813
|
-
.bubble.system {
|
|
814
|
-
background: transparent;
|
|
815
|
-
color: var(--aikaara-text-secondary, #6b7280);
|
|
816
|
-
font-size: 12px;
|
|
817
|
-
font-style: italic;
|
|
818
|
-
}
|
|
819
|
-
.timestamp {
|
|
820
|
-
font-size: 11px;
|
|
821
|
-
color: var(--aikaara-text-secondary, #6b7280);
|
|
822
|
-
margin-top: 2px;
|
|
823
|
-
padding: 0 4px;
|
|
824
|
-
}
|
|
825
|
-
.status {
|
|
826
|
-
font-size: 10px;
|
|
827
|
-
color: ${i === "read" ? "var(--aikaara-primary, #6366f1)" : "var(--aikaara-text-secondary, #6b7280)"};
|
|
828
|
-
margin-left: 4px;
|
|
829
|
-
}
|
|
830
|
-
.attachments {
|
|
831
|
-
display: flex;
|
|
832
|
-
flex-direction: column;
|
|
833
|
-
gap: 6px;
|
|
834
|
-
margin-top: 8px;
|
|
835
|
-
}
|
|
836
|
-
.attachment {
|
|
837
|
-
display: inline-flex;
|
|
838
|
-
align-items: center;
|
|
839
|
-
gap: 6px;
|
|
840
|
-
padding: 6px 10px;
|
|
841
|
-
background: rgba(0,0,0,0.05);
|
|
842
|
-
border-radius: 8px;
|
|
843
|
-
font-size: 12px;
|
|
844
|
-
color: inherit;
|
|
845
|
-
text-decoration: none;
|
|
846
|
-
max-width: 100%;
|
|
847
|
-
}
|
|
848
|
-
.attachment:hover { background: rgba(0,0,0,0.08); }
|
|
849
|
-
aikaara-template-renderer { display: block; margin-top: 6px; }
|
|
850
|
-
</style>
|
|
851
|
-
<div class="bubble ${e}">
|
|
852
|
-
<div class="content">${h}</div>
|
|
853
|
-
${r ? `<aikaara-template-renderer
|
|
854
|
-
content-type="${r}"
|
|
855
|
-
template-id="${o}"
|
|
856
|
-
inner-message="${m(n)}"
|
|
857
|
-
></aikaara-template-renderer>` : ""}
|
|
858
|
-
${this.renderAttachments()}
|
|
859
|
-
</div>
|
|
860
|
-
${a || p ? `
|
|
861
|
-
<div class="timestamp">
|
|
862
|
-
${a}${p ? `<span class="status">${f}</span>` : ""}
|
|
863
|
-
</div>
|
|
864
|
-
` : ""}
|
|
865
|
-
`;
|
|
866
|
-
const c = this.shadow.querySelector("aikaara-template-renderer");
|
|
867
|
-
c && this.templatePayload !== null && c.setPayload(this.templatePayload, n), c && c.addEventListener("template-action", (x) => {
|
|
868
|
-
this.dispatchEvent(
|
|
869
|
-
new CustomEvent("message-action", {
|
|
870
|
-
detail: x.detail,
|
|
871
|
-
bubbles: !0,
|
|
872
|
-
composed: !0
|
|
873
|
-
})
|
|
874
|
-
);
|
|
875
|
-
});
|
|
876
|
-
}
|
|
877
|
-
renderAttachments() {
|
|
878
|
-
return this.attachments.length ? `<div class="attachments">${this.attachments.map(
|
|
879
|
-
(t) => `<a class="attachment" href="${m(t.fileUrl)}" target="_blank" rel="noopener noreferrer">
|
|
880
|
-
📎 ${q(t.fileName)}
|
|
881
|
-
</a>`
|
|
882
|
-
).join("")}</div>` : "";
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
function m(s) {
|
|
886
|
-
return String(s).replace(/[&<>"']/g, (e) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[e]);
|
|
887
|
-
}
|
|
888
|
-
function q(s) {
|
|
889
|
-
return String(s).replace(/[&<>]/g, (e) => ({ "&": "&", "<": "<", ">": ">" })[e]);
|
|
890
|
-
}
|
|
891
|
-
class B extends HTMLElement {
|
|
892
|
-
shadow;
|
|
893
|
-
textarea;
|
|
894
|
-
sendBtn;
|
|
895
|
-
_disabled = !1;
|
|
896
|
-
constructor() {
|
|
897
|
-
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
898
|
-
}
|
|
899
|
-
connectedCallback() {
|
|
900
|
-
const e = this.getAttribute("placeholder") || "Type a message...";
|
|
901
|
-
this.shadow.innerHTML = `
|
|
902
|
-
<style>
|
|
903
|
-
.input-container {
|
|
904
|
-
display: flex;
|
|
905
|
-
align-items: flex-end;
|
|
906
|
-
gap: 8px;
|
|
907
|
-
padding: 12px 16px;
|
|
908
|
-
border-top: 1px solid var(--aikaara-border, #e5e7eb);
|
|
909
|
-
background: var(--aikaara-bg, #ffffff);
|
|
910
|
-
}
|
|
911
|
-
textarea {
|
|
912
|
-
flex: 1;
|
|
913
|
-
resize: none;
|
|
914
|
-
border: 1px solid var(--aikaara-border, #e5e7eb);
|
|
915
|
-
border-radius: 8px;
|
|
916
|
-
padding: 10px 12px;
|
|
917
|
-
font-family: var(--aikaara-font, system-ui, sans-serif);
|
|
918
|
-
font-size: 14px;
|
|
919
|
-
color: var(--aikaara-text, #1f2937);
|
|
920
|
-
background: var(--aikaara-bg, #ffffff);
|
|
921
|
-
outline: none;
|
|
922
|
-
min-height: 40px;
|
|
923
|
-
max-height: 120px;
|
|
924
|
-
line-height: 1.4;
|
|
925
|
-
transition: border-color 200ms ease;
|
|
926
|
-
}
|
|
927
|
-
textarea:focus {
|
|
928
|
-
border-color: var(--aikaara-primary, #6366f1);
|
|
929
|
-
}
|
|
930
|
-
textarea::placeholder {
|
|
931
|
-
color: var(--aikaara-text-secondary, #6b7280);
|
|
932
|
-
}
|
|
933
|
-
.send-btn {
|
|
934
|
-
width: 40px;
|
|
935
|
-
height: 40px;
|
|
936
|
-
border: none;
|
|
937
|
-
border-radius: 50%;
|
|
938
|
-
background: var(--aikaara-primary, #6366f1);
|
|
939
|
-
color: #ffffff;
|
|
940
|
-
cursor: pointer;
|
|
941
|
-
display: flex;
|
|
942
|
-
align-items: center;
|
|
943
|
-
justify-content: center;
|
|
944
|
-
flex-shrink: 0;
|
|
945
|
-
transition: background 200ms, opacity 200ms;
|
|
946
|
-
}
|
|
947
|
-
.send-btn:hover { background: var(--aikaara-primary-hover, #4f46e5); }
|
|
948
|
-
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
949
|
-
.send-btn svg { width: 18px; height: 18px; }
|
|
950
|
-
</style>
|
|
951
|
-
<div class="input-container">
|
|
952
|
-
<textarea rows="1" placeholder="${e}"></textarea>
|
|
953
|
-
<button class="send-btn" aria-label="Send message" disabled>
|
|
954
|
-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
955
|
-
<line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/>
|
|
956
|
-
</svg>
|
|
957
|
-
</button>
|
|
958
|
-
</div>
|
|
959
|
-
`, this.textarea = this.shadow.querySelector("textarea"), this.sendBtn = this.shadow.querySelector(".send-btn"), this.textarea.addEventListener("input", () => {
|
|
960
|
-
this.autoGrow(), this.sendBtn.disabled = this._disabled || !this.textarea.value.trim();
|
|
961
|
-
}), this.textarea.addEventListener("keydown", (t) => {
|
|
962
|
-
t.key === "Enter" && !t.shiftKey && (t.preventDefault(), this.handleSend());
|
|
963
|
-
}), this.sendBtn.addEventListener("click", () => this.handleSend());
|
|
964
|
-
}
|
|
965
|
-
set disabled(e) {
|
|
966
|
-
this._disabled = e, this.textarea && (this.textarea.disabled = e), this.sendBtn && (this.sendBtn.disabled = e || !this.textarea?.value.trim());
|
|
967
|
-
}
|
|
968
|
-
get disabled() {
|
|
969
|
-
return this._disabled;
|
|
970
|
-
}
|
|
971
|
-
focus() {
|
|
972
|
-
this.textarea?.focus();
|
|
973
|
-
}
|
|
974
|
-
clear() {
|
|
975
|
-
this.textarea && (this.textarea.value = "", this.textarea.style.height = "auto", this.sendBtn.disabled = !0);
|
|
976
|
-
}
|
|
977
|
-
handleSend() {
|
|
978
|
-
const e = this.textarea.value.trim();
|
|
979
|
-
!e || this._disabled || (this.dispatchEvent(new CustomEvent("send", {
|
|
980
|
-
detail: { content: e },
|
|
981
|
-
bubbles: !0,
|
|
982
|
-
composed: !0
|
|
983
|
-
})), this.clear(), this.textarea.focus());
|
|
984
|
-
}
|
|
985
|
-
autoGrow() {
|
|
986
|
-
this.textarea.style.height = "auto", this.textarea.style.height = Math.min(this.textarea.scrollHeight, 120) + "px";
|
|
987
|
-
}
|
|
988
|
-
}
|
|
989
|
-
class D extends HTMLElement {
|
|
990
|
-
shadow;
|
|
991
|
-
constructor() {
|
|
992
|
-
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
993
|
-
}
|
|
994
|
-
connectedCallback() {
|
|
995
|
-
this.shadow.innerHTML = `
|
|
996
|
-
<style>
|
|
997
|
-
:host { display: none; }
|
|
998
|
-
:host([visible]) { display: block; }
|
|
999
|
-
.typing {
|
|
1000
|
-
display: flex;
|
|
1001
|
-
align-items: center;
|
|
1002
|
-
gap: 4px;
|
|
1003
|
-
padding: 10px 14px;
|
|
1004
|
-
background: var(--aikaara-bg-secondary, #f9fafb);
|
|
1005
|
-
border-radius: var(--aikaara-radius, 12px);
|
|
1006
|
-
border-bottom-left-radius: 4px;
|
|
1007
|
-
width: fit-content;
|
|
1008
|
-
}
|
|
1009
|
-
.dot {
|
|
1010
|
-
width: 6px;
|
|
1011
|
-
height: 6px;
|
|
1012
|
-
border-radius: 50%;
|
|
1013
|
-
background: var(--aikaara-text-secondary, #6b7280);
|
|
1014
|
-
animation: bounce 1.4s infinite ease-in-out;
|
|
1015
|
-
}
|
|
1016
|
-
.dot:nth-child(1) { animation-delay: 0ms; }
|
|
1017
|
-
.dot:nth-child(2) { animation-delay: 200ms; }
|
|
1018
|
-
.dot:nth-child(3) { animation-delay: 400ms; }
|
|
1019
|
-
@keyframes bounce {
|
|
1020
|
-
0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
|
|
1021
|
-
30% { transform: translateY(-4px); opacity: 1; }
|
|
1022
|
-
}
|
|
1023
|
-
</style>
|
|
1024
|
-
<div class="typing">
|
|
1025
|
-
<span class="dot"></span>
|
|
1026
|
-
<span class="dot"></span>
|
|
1027
|
-
<span class="dot"></span>
|
|
1028
|
-
</div>
|
|
1029
|
-
`;
|
|
1030
|
-
}
|
|
1031
|
-
show() {
|
|
1032
|
-
this.setAttribute("visible", "");
|
|
1033
|
-
}
|
|
1034
|
-
hide() {
|
|
1035
|
-
this.removeAttribute("visible");
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
class F extends HTMLElement {
|
|
1039
|
-
shadow;
|
|
1040
|
-
bubble;
|
|
1041
|
-
constructor() {
|
|
1042
|
-
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
1043
|
-
}
|
|
1044
|
-
connectedCallback() {
|
|
1045
|
-
this.shadow.innerHTML = `
|
|
1046
|
-
<style>
|
|
1047
|
-
:host {
|
|
1048
|
-
display: flex;
|
|
1049
|
-
flex-direction: column;
|
|
1050
|
-
align-items: flex-start;
|
|
1051
|
-
}
|
|
1052
|
-
.bubble {
|
|
1053
|
-
max-width: 85%;
|
|
1054
|
-
padding: 10px 14px;
|
|
1055
|
-
border-radius: var(--aikaara-radius, 12px);
|
|
1056
|
-
border-bottom-left-radius: 4px;
|
|
1057
|
-
background: var(--aikaara-bg-secondary, #f9fafb);
|
|
1058
|
-
color: var(--aikaara-text, #1f2937);
|
|
1059
|
-
font-size: 14px;
|
|
1060
|
-
line-height: 1.5;
|
|
1061
|
-
word-wrap: break-word;
|
|
1062
|
-
min-height: 20px;
|
|
1063
|
-
}
|
|
1064
|
-
.bubble pre {
|
|
1065
|
-
background: rgba(0,0,0,0.06);
|
|
1066
|
-
padding: 8px 12px;
|
|
1067
|
-
border-radius: 6px;
|
|
1068
|
-
overflow-x: auto;
|
|
1069
|
-
font-size: 13px;
|
|
1070
|
-
margin: 8px 0;
|
|
1071
|
-
}
|
|
1072
|
-
.bubble code {
|
|
1073
|
-
font-family: 'SF Mono', 'Fira Code', monospace;
|
|
1074
|
-
font-size: 13px;
|
|
1075
|
-
}
|
|
1076
|
-
.bubble code:not(pre code) {
|
|
1077
|
-
background: rgba(0,0,0,0.06);
|
|
1078
|
-
padding: 2px 4px;
|
|
1079
|
-
border-radius: 3px;
|
|
1080
|
-
}
|
|
1081
|
-
.cursor::after {
|
|
1082
|
-
content: '\\25CF';
|
|
1083
|
-
animation: blink 1s infinite;
|
|
1084
|
-
margin-left: 2px;
|
|
1085
|
-
font-size: 10px;
|
|
1086
|
-
vertical-align: middle;
|
|
1087
|
-
}
|
|
1088
|
-
@keyframes blink {
|
|
1089
|
-
0%, 100% { opacity: 1; }
|
|
1090
|
-
50% { opacity: 0; }
|
|
1091
|
-
}
|
|
1092
|
-
</style>
|
|
1093
|
-
<div class="bubble cursor"></div>
|
|
1094
|
-
`, this.bubble = this.shadow.querySelector(".bubble");
|
|
1095
|
-
}
|
|
1096
|
-
updateContent(e) {
|
|
1097
|
-
this.bubble && (this.bubble.innerHTML = d(l(e)), this.bubble.classList.add("cursor"));
|
|
1098
|
-
}
|
|
1099
|
-
finalize() {
|
|
1100
|
-
this.bubble?.classList.remove("cursor");
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
class P extends HTMLElement {
|
|
1104
|
-
shadow;
|
|
1105
|
-
container;
|
|
1106
|
-
dismissTimer = null;
|
|
1107
|
-
constructor() {
|
|
1108
|
-
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
1109
|
-
}
|
|
1110
|
-
connectedCallback() {
|
|
1111
|
-
this.shadow.innerHTML = `
|
|
1112
|
-
<style>
|
|
1113
|
-
.banner {
|
|
1114
|
-
display: none;
|
|
1115
|
-
padding: 8px 16px;
|
|
1116
|
-
background: #fef2f2;
|
|
1117
|
-
color: #dc2626;
|
|
1118
|
-
font-size: 13px;
|
|
1119
|
-
text-align: center;
|
|
1120
|
-
border-top: 1px solid #fecaca;
|
|
1121
|
-
}
|
|
1122
|
-
.banner.visible {
|
|
1123
|
-
display: block;
|
|
1124
|
-
}
|
|
1125
|
-
.dismiss {
|
|
1126
|
-
background: none;
|
|
1127
|
-
border: none;
|
|
1128
|
-
color: #dc2626;
|
|
1129
|
-
cursor: pointer;
|
|
1130
|
-
font-size: 12px;
|
|
1131
|
-
text-decoration: underline;
|
|
1132
|
-
margin-left: 8px;
|
|
1133
|
-
}
|
|
1134
|
-
</style>
|
|
1135
|
-
<div class="banner">
|
|
1136
|
-
<span class="message"></span>
|
|
1137
|
-
<button class="dismiss">Dismiss</button>
|
|
1138
|
-
</div>
|
|
1139
|
-
`, this.container = this.shadow.querySelector(".banner"), this.shadow.querySelector(".dismiss")?.addEventListener("click", () => this.hide());
|
|
1140
|
-
}
|
|
1141
|
-
show(e, t) {
|
|
1142
|
-
const a = this.container.querySelector(".message");
|
|
1143
|
-
a && (a.textContent = e), this.container.classList.add("visible"), this.dismissTimer && clearTimeout(this.dismissTimer), t && (this.dismissTimer = setTimeout(() => this.hide(), t));
|
|
1144
|
-
}
|
|
1145
|
-
hide() {
|
|
1146
|
-
this.container.classList.remove("visible"), this.dismissTimer && (clearTimeout(this.dismissTimer), this.dismissTimer = null);
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
class O extends HTMLElement {
|
|
1150
|
-
shadow;
|
|
1151
|
-
payloadData = null;
|
|
1152
|
-
innerMessage = "";
|
|
1153
|
-
static get observedAttributes() {
|
|
1154
|
-
return ["content-type", "template-id", "inner-message"];
|
|
1155
|
-
}
|
|
1156
|
-
constructor() {
|
|
1157
|
-
super(), this.shadow = this.attachShadow({ mode: "open" });
|
|
1158
|
-
}
|
|
1159
|
-
connectedCallback() {
|
|
1160
|
-
this.render();
|
|
1161
|
-
}
|
|
1162
|
-
attributeChangedCallback() {
|
|
1163
|
-
this.render();
|
|
1164
|
-
}
|
|
1165
|
-
setPayload(e, t) {
|
|
1166
|
-
this.payloadData = e, t !== void 0 && (this.innerMessage = t), this.render();
|
|
1167
|
-
}
|
|
1168
|
-
render() {
|
|
1169
|
-
const e = this.getAttribute("content-type") ?? "", t = this.getAttribute("template-id") ?? "", a = this.getAttribute("inner-message") ?? this.innerMessage;
|
|
1170
|
-
this.shadow.innerHTML = `
|
|
1171
|
-
<style>
|
|
1172
|
-
:host { display: block; }
|
|
1173
|
-
.inner { font-size: 14px; line-height: 1.5; color: var(--aikaara-text, #1f2937); }
|
|
1174
|
-
.placeholder {
|
|
1175
|
-
font-size: 12px;
|
|
1176
|
-
color: var(--aikaara-text-secondary, #6b7280);
|
|
1177
|
-
padding: 6px 0;
|
|
1178
|
-
}
|
|
1179
|
-
</style>
|
|
1180
|
-
${a ? '<div class="inner"></div>' : ""}
|
|
1181
|
-
<slot></slot>
|
|
1182
|
-
`;
|
|
1183
|
-
const i = this.shadow.querySelector(".inner");
|
|
1184
|
-
if (i && a && (i.textContent = a), !e) return;
|
|
1185
|
-
const r = t ? `aikaara-template-${t}` : `aikaara-template-${e}`;
|
|
1186
|
-
if (customElements.get(r)) {
|
|
1187
|
-
const o = this.querySelector(r);
|
|
1188
|
-
if (o) {
|
|
1189
|
-
o.setPayload?.(this.payloadData);
|
|
1190
|
-
return;
|
|
1191
|
-
}
|
|
1192
|
-
const n = document.createElement(r);
|
|
1193
|
-
n.setPayload?.(this.payloadData), n.addEventListener("template-action", (h) => {
|
|
1194
|
-
this.dispatchEvent(
|
|
1195
|
-
new CustomEvent("template-action", {
|
|
1196
|
-
detail: h.detail,
|
|
1197
|
-
bubbles: !0,
|
|
1198
|
-
composed: !0
|
|
1199
|
-
})
|
|
1200
|
-
);
|
|
1201
|
-
}), this.appendChild(n);
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
function N() {
|
|
1206
|
-
const s = [
|
|
1207
|
-
["aikaara-chat-widget", S],
|
|
1208
|
-
["aikaara-chat-bubble", M],
|
|
1209
|
-
["aikaara-chat-header", _],
|
|
1210
|
-
["aikaara-message-list", I],
|
|
1211
|
-
["aikaara-message-bubble", U],
|
|
1212
|
-
["aikaara-chat-input", B],
|
|
1213
|
-
["aikaara-typing-indicator", D],
|
|
1214
|
-
["aikaara-streaming-message", F],
|
|
1215
|
-
["aikaara-error-banner", P],
|
|
1216
|
-
["aikaara-template-renderer", O]
|
|
1217
|
-
];
|
|
1218
|
-
for (const [e, t] of s)
|
|
1219
|
-
customElements.get(e) || customElements.define(e, t);
|
|
1220
|
-
}
|
|
1221
|
-
N();
|
|
1
|
+
import { y as i, a as s, c as e, d as t, e as A, f as k, g as n, h as o, z as g, B as d, i as h, D as l, F as m, G as p, j as C, r as b } from "./MountTenant-5CL6i2El.mjs";
|
|
1222
2
|
export {
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
3
|
+
i as AikaaraChat,
|
|
4
|
+
s as AikaaraChatBubble,
|
|
5
|
+
e as AikaaraChatHeader,
|
|
6
|
+
t as AikaaraChatInput,
|
|
7
|
+
A as AikaaraChatWidget,
|
|
8
|
+
k as AikaaraErrorBanner,
|
|
9
|
+
n as AikaaraMessageBubble,
|
|
10
|
+
o as AikaaraMessageList,
|
|
11
|
+
g as AikaaraModalAction,
|
|
12
|
+
d as AikaaraOptionList,
|
|
13
|
+
h as AikaaraStreamingMessage,
|
|
14
|
+
l as AikaaraSubmitAction,
|
|
15
|
+
m as AikaaraSystemPill,
|
|
16
|
+
p as AikaaraTemplateRenderer,
|
|
17
|
+
C as AikaaraTypingIndicator,
|
|
18
|
+
b as registerComponents
|
|
1234
19
|
};
|