@aikaara/chat-sdk 0.1.4 → 0.3.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/README.md +435 -0
- package/dist/AikaaraChatClient-Cqbcd1jb.mjs +11538 -0
- package/dist/AikaaraChatClient-kAu65hX-.cjs +8 -0
- package/dist/cdn/aikaara-chat.iife.js +118 -18
- package/dist/headless.cjs +1 -1
- package/dist/headless.d.ts +523 -5
- package/dist/headless.mjs +142 -9
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +541 -5
- package/dist/index.mjs +36 -28
- package/dist/ui.cjs +111 -18
- package/dist/ui.d.ts +498 -3
- package/dist/ui.mjs +322 -88
- package/package.json +4 -1
- package/dist/headless-BhsiNVQj.mjs +0 -551
- package/dist/headless-CrgIWcf7.cjs +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { A as m, a as u, b as h, C as k, c as g, d as C, E as A, M as b, T as f, e as T, i as M, f as v, p as w } from "./AikaaraChatClient-Cqbcd1jb.mjs";
|
|
2
|
+
import { FormBridge as E, createFetchUploadAdapter as S } from "./headless.mjs";
|
|
3
|
+
import { registerComponents as s } from "./ui.mjs";
|
|
4
|
+
import { AikaaraChatBubble as B, AikaaraChatHeader as F, AikaaraChatInput as U, AikaaraChatWidget as I, AikaaraErrorBanner as j, AikaaraMessageBubble as q, AikaaraMessageList as H, AikaaraStreamingMessage as K, AikaaraTypingIndicator as L } from "./ui.mjs";
|
|
5
|
+
function l(e) {
|
|
6
|
+
s();
|
|
7
|
+
const a = document.createElement("aikaara-chat-widget"), r = {
|
|
7
8
|
baseUrl: "base-url",
|
|
8
9
|
userToken: "user-token",
|
|
9
10
|
apiKey: "api-key",
|
|
@@ -19,34 +20,41 @@ function l(a) {
|
|
|
19
20
|
avatarUrl: "avatar-url"
|
|
20
21
|
};
|
|
21
22
|
for (const [i, o] of Object.entries(r)) {
|
|
22
|
-
const t =
|
|
23
|
-
t != null &&
|
|
23
|
+
const t = e[i];
|
|
24
|
+
t != null && a.setAttribute(o, String(t));
|
|
24
25
|
}
|
|
25
|
-
return
|
|
26
|
+
return a.configure(e), document.body.appendChild(a), a;
|
|
26
27
|
}
|
|
27
28
|
function c() {
|
|
28
|
-
const
|
|
29
|
-
|
|
29
|
+
const e = document.querySelector("aikaara-chat-widget");
|
|
30
|
+
e && e.remove();
|
|
30
31
|
}
|
|
31
32
|
export {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
m as ActionCableClient,
|
|
34
|
+
B as AikaaraChatBubble,
|
|
35
|
+
u as AikaaraChatClient,
|
|
36
|
+
F as AikaaraChatHeader,
|
|
37
|
+
U as AikaaraChatInput,
|
|
38
|
+
I as AikaaraChatWidget,
|
|
39
|
+
j as AikaaraErrorBanner,
|
|
40
|
+
q as AikaaraMessageBubble,
|
|
41
|
+
H as AikaaraMessageList,
|
|
42
|
+
K as AikaaraStreamingMessage,
|
|
43
|
+
L as AikaaraTypingIndicator,
|
|
44
|
+
h as ApiClient,
|
|
45
|
+
k as ChannelSubscription,
|
|
46
|
+
g as ConnectionManager,
|
|
46
47
|
C as ConversationManager,
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
A as EventEmitter,
|
|
49
|
+
E as FormBridge,
|
|
50
|
+
b as MessageStore,
|
|
51
|
+
f as TiledeskTransport,
|
|
52
|
+
S as createFetchUploadAdapter,
|
|
53
|
+
T as extractTiledeskFileEnvelope,
|
|
54
|
+
M as inferTiledeskRole,
|
|
55
|
+
v as isTiledeskSelfEcho,
|
|
49
56
|
l as mount,
|
|
50
|
-
|
|
57
|
+
w as parseTiledeskTemplate,
|
|
58
|
+
s as registerComponents,
|
|
51
59
|
c as unmount
|
|
52
60
|
};
|
package/dist/ui.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./AikaaraChatClient-kAu65hX-.cjs");class S{client;panel;bubble;header;messageList;input;errorBanner;isOpen=!1;constructor(e,t,a){this.client=new l.AikaaraChatClient(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()}async connect(){try{await this.client.connect(),this.messageList.renderMessages(this.client.messages)}catch{this.errorBanner.show("Failed to connect. Retrying...",5e3)}}async disconnect(){await this.client.disconnect()}wireEvents(){this.bubble.addEventListener("toggle",()=>{this.togglePanel()}),this.header.addEventListener("header-close",()=>{this.togglePanel(!1)}),this.input.addEventListener("send",(e=>{this.handleSend(e.detail.content)})),this.client.on("message:sent",e=>{this.messageList.addMessage(e)}),this.client.on("stream:start",()=>{this.messageList.removeTypingIndicator();const e=this.client.messages[this.client.messages.length-1];e&&this.messageList.addMessage(e)}),this.client.on("stream:update",({content:e})=>{this.messageList.updateStreamingContent(e)}),this.client.on("stream:end",()=>{this.messageList.finalizeStreaming()}),this.client.on("typing:start",()=>{const e=this.client.messages,t=e[e.length-1];(!t||t.status!=="streaming")&&this.messageList.showTypingIndicator()}),this.client.on("typing:stop",()=>{this.messageList.removeTypingIndicator()}),this.client.on("connection:state",e=>{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)}),this.client.on("error",e=>{this.errorBanner.show(e.message,5e3)}),this.client.on("message:received",e=>{this.messageList.upsertMessage(e)}),this.client.on("message:updated",e=>{this.messageList.upsertMessage(e)}),this.messageList.addEventListener("message-action",e=>{const t=e.detail;t?.text&&this.handleSend(t.text)})}async handleSend(e){try{await this.client.sendMessage(e)}catch{this.errorBanner.show("Failed to send message",3e3)}}sendUserEvent(e,t,a){this.client.sendUserEvent(e,t,a)}getClient(){return this.client}togglePanel(e){this.isOpen=e!==void 0?e:!this.isOpen,this.isOpen?(this.panel.removeAttribute("hidden"),requestAnimationFrame(()=>{this.panel.classList.remove("entering"),this.panel.classList.add("visible"),this.input.focus()})):(this.panel.classList.remove("visible"),this.panel.classList.add("entering"),setTimeout(()=>{this.panel.setAttribute("hidden","")},200))}}class m extends HTMLElement{shadow;controller=null;_config={};static get observedAttributes(){return["base-url","ws-url","user-token","api-key","title","subtitle","theme","primary-color","position","width","height","placeholder","welcome-message","avatar-url"]}constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render(),this.initController()}disconnectedCallback(){this.controller?.disconnect()}attributeChangedCallback(e,t,a){t!==a&&this.controller&&(this.render(),this.initController())}configure(e){this._config={...this._config,...e}}getConfig(){return{baseUrl:this.getAttribute("base-url")||this._config.baseUrl||"",wsUrl:this.getAttribute("ws-url")||this._config.wsUrl,userToken:this.getAttribute("user-token")||this._config.userToken||"",apiKey:this.getAttribute("api-key")||this._config.apiKey,title:this.getAttribute("title")||this._config.title||"Chat",subtitle:this.getAttribute("subtitle")||this._config.subtitle,theme:this.getAttribute("theme")||this._config.theme||l.DEFAULT_THEME,primaryColor:this.getAttribute("primary-color")||this._config.primaryColor||l.DEFAULT_PRIMARY_COLOR,position:this.getAttribute("position")||this._config.position||l.DEFAULT_POSITION,width:Number(this.getAttribute("width"))||this._config.width||l.DEFAULT_WIDGET_WIDTH,height:Number(this.getAttribute("height"))||this._config.height||l.DEFAULT_WIDGET_HEIGHT,fontFamily:this._config.fontFamily||l.DEFAULT_FONT_FAMILY,borderRadius:this._config.borderRadius??l.DEFAULT_BORDER_RADIUS,placeholder:this.getAttribute("placeholder")||this._config.placeholder||l.DEFAULT_PLACEHOLDER,welcomeMessage:this.getAttribute("welcome-message")||this._config.welcomeMessage,avatarUrl:this.getAttribute("avatar-url")||this._config.avatarUrl,showTimestamps:this._config.showTimestamps??!0,persistConversation:this._config.persistConversation??!0,showBubble:this._config.showBubble??!0,offset:this._config.offset||l.DEFAULT_OFFSET,conversationId:this._config.conversationId,systemPromptId:this._config.systemPromptId,channel:this._config.channel,extUid:this._config.extUid,transport:this._config.transport,tiledesk:this._config.tiledesk,tiledeskIdentity:this._config.tiledeskIdentity,onMessage:this._config.onMessage,onStatusChange:this._config.onStatusChange,onError:this._config.onError,onStreamUpdate:this._config.onStreamUpdate,onConnectionStateChange:this._config.onConnectionStateChange,onTemplateMessage:this._config.onTemplateMessage}}setUploadAdapter(e){this._config.uploadAdapter=e,this.controller?.getClient().setUploadAdapter(e)}render(){const e=this.getConfig();this.shadow.innerHTML=`
|
|
2
2
|
<style>
|
|
3
3
|
:host {
|
|
4
4
|
--aikaara-primary: ${e.primaryColor};
|
|
5
|
-
--aikaara-primary-hover: ${this.darkenColor(e.primaryColor||
|
|
5
|
+
--aikaara-primary-hover: ${this.darkenColor(e.primaryColor||l.DEFAULT_PRIMARY_COLOR)};
|
|
6
6
|
--aikaara-bg: #ffffff;
|
|
7
7
|
--aikaara-bg-secondary: #f9fafb;
|
|
8
8
|
--aikaara-text: #1f2937;
|
|
@@ -84,10 +84,10 @@
|
|
|
84
84
|
${e.avatarUrl?`avatar-url="${e.avatarUrl}"`:""}
|
|
85
85
|
></aikaara-chat-header>
|
|
86
86
|
<aikaara-message-list></aikaara-message-list>
|
|
87
|
-
<aikaara-chat-input placeholder="${e.placeholder||
|
|
87
|
+
<aikaara-chat-input placeholder="${e.placeholder||l.DEFAULT_PLACEHOLDER}"></aikaara-chat-input>
|
|
88
88
|
<aikaara-error-banner></aikaara-error-banner>
|
|
89
89
|
</div>
|
|
90
|
-
`}async initController(){const e=this.getConfig();!e.baseUrl||!e.userToken||(this.controller?.disconnect(),this.controller=new
|
|
90
|
+
`}async initController(){const e=this.getConfig();!e.baseUrl||!e.userToken||(this.controller?.disconnect(),this.controller=new S(e,this.shadow,{uploadAdapter:this._config.uploadAdapter}),await this.controller.connect())}sendUserEvent(e,t,a){this.controller?.sendUserEvent(e,t,a)}getClient(){return this.controller?.getClient()??null}darkenColor(e){try{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);return`#${(a<<16|i<<8|r).toString(16).padStart(6,"0")}`}catch{return e}}}class g extends HTMLElement{shadow;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render(),this.shadow.querySelector(".bubble")?.addEventListener("click",()=>{this.dispatchEvent(new CustomEvent("toggle",{bubbles:!0,composed:!0}))})}render(){this.shadow.innerHTML=`
|
|
91
91
|
<style>
|
|
92
92
|
.bubble {
|
|
93
93
|
width: var(--aikaara-bubble-size, 60px);
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>
|
|
123
123
|
</svg>
|
|
124
124
|
</button>
|
|
125
|
-
`}setIcon(e){const t=this.shadow.querySelector(".bubble");t&&(t.innerHTML=e)}}class
|
|
125
|
+
`}setIcon(e){const t=this.shadow.querySelector(".bubble");t&&(t.innerHTML=e)}}class f extends HTMLElement{shadow;static get observedAttributes(){return["title","subtitle","avatar-url","status"]}constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render(),this.bindClose()}attributeChangedCallback(){this.render(),this.bindClose()}bindClose(){this.shadow.querySelector(".close-btn")?.addEventListener("click",()=>{this.dispatchEvent(new CustomEvent("header-close",{bubbles:!0,composed:!0}))})}render(){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";this.shadow.innerHTML=`
|
|
126
126
|
<style>
|
|
127
127
|
.header {
|
|
128
128
|
display: flex;
|
|
@@ -206,7 +206,7 @@
|
|
|
206
206
|
<div class="info">
|
|
207
207
|
<div class="title">
|
|
208
208
|
${e}
|
|
209
|
-
<span class="status-dot" style="background:${
|
|
209
|
+
<span class="status-dot" style="background:${r}"></span>
|
|
210
210
|
</div>
|
|
211
211
|
${t?`<div class="subtitle">${t}</div>`:""}
|
|
212
212
|
</div>
|
|
@@ -216,7 +216,7 @@
|
|
|
216
216
|
</svg>
|
|
217
217
|
</button>
|
|
218
218
|
</div>
|
|
219
|
-
`}setStatus(e){this.setAttribute("status",e)}}function
|
|
219
|
+
`}setStatus(e){this.setAttribute("status",e)}}function d(s){let e=_(s);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(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g,'<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'),e=e.replace(/\n/g,"<br>"),e}function _(s){const e={"&":"&","<":"<",">":">",'"':""","'":"'"};return s.replace(/[&<>"']/g,t=>e[t])}const $=new Set(["p","br","strong","em","code","pre","a","ul","ol","li","blockquote","h1","h2","h3","h4","h5","h6","span","div"]),H={a:new Set(["href","target","rel"]),code:new Set(["class"]),pre:new Set(["class"]),span:new Set(["class"]),div:new Set(["class"])};function c(s){const e=document.createElement("template");return e.innerHTML=s,x(e.content),e.innerHTML}function x(s){const e=Array.from(s.childNodes);for(const t of e)if(t.nodeType===Node.ELEMENT_NODE){const a=t,i=a.tagName.toLowerCase();if(!$.has(i)){const n=document.createTextNode(a.textContent||"");s.replaceChild(n,t);continue}const r=H[i]||new Set,o=Array.from(a.attributes);for(const n of o)r.has(n.name)||a.removeAttribute(n.name);if(a.hasAttribute("href")){const n=a.getAttribute("href")||"";!n.startsWith("http://")&&!n.startsWith("https://")&&!n.startsWith("/")&&a.removeAttribute("href")}x(t)}}class k extends HTMLElement{shadow;container;welcomeMessage="";showTimestamps=!0;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.shadow.innerHTML=`
|
|
220
220
|
<style>
|
|
221
221
|
:host {
|
|
222
222
|
display: flex;
|
|
@@ -237,7 +237,41 @@
|
|
|
237
237
|
.message-list::-webkit-scrollbar-thumb { background: var(--aikaara-border, #e5e7eb); border-radius: 3px; }
|
|
238
238
|
.message-wrap { display: flex; flex-direction: column; }
|
|
239
239
|
.message-wrap.user { align-items: flex-end; }
|
|
240
|
-
.message-wrap.assistant
|
|
240
|
+
.message-wrap.assistant,
|
|
241
|
+
.message-wrap.agent,
|
|
242
|
+
.message-wrap.system { align-items: flex-start; }
|
|
243
|
+
.message-wrap.system .bubble {
|
|
244
|
+
background: transparent;
|
|
245
|
+
color: var(--aikaara-text-secondary, #6b7280);
|
|
246
|
+
font-size: 12px;
|
|
247
|
+
font-style: italic;
|
|
248
|
+
padding: 4px 0;
|
|
249
|
+
}
|
|
250
|
+
.attachments {
|
|
251
|
+
display: flex;
|
|
252
|
+
flex-direction: column;
|
|
253
|
+
gap: 4px;
|
|
254
|
+
margin-top: 6px;
|
|
255
|
+
}
|
|
256
|
+
.attachment {
|
|
257
|
+
display: inline-flex;
|
|
258
|
+
align-items: center;
|
|
259
|
+
gap: 6px;
|
|
260
|
+
padding: 6px 10px;
|
|
261
|
+
background: rgba(0,0,0,0.05);
|
|
262
|
+
border-radius: 8px;
|
|
263
|
+
font-size: 12px;
|
|
264
|
+
color: inherit;
|
|
265
|
+
text-decoration: none;
|
|
266
|
+
}
|
|
267
|
+
.attachment:hover { background: rgba(0,0,0,0.08); }
|
|
268
|
+
.status-tick {
|
|
269
|
+
font-size: 10px;
|
|
270
|
+
margin-left: 4px;
|
|
271
|
+
color: var(--aikaara-text-secondary, #6b7280);
|
|
272
|
+
}
|
|
273
|
+
.status-tick.read { color: var(--aikaara-primary, #6366f1); }
|
|
274
|
+
aikaara-template-renderer { display: block; margin-top: 6px; }
|
|
241
275
|
.bubble {
|
|
242
276
|
max-width: 85%;
|
|
243
277
|
padding: 10px 14px;
|
|
@@ -324,11 +358,13 @@
|
|
|
324
358
|
}
|
|
325
359
|
</style>
|
|
326
360
|
<div class="message-list"></div>
|
|
327
|
-
`,this.container=this.shadow.querySelector(".message-list"),this.welcomeMessage&&this.renderMessages([])}setWelcomeMessage(e){this.welcomeMessage=e}setShowTimestamps(e){this.showTimestamps=e}renderMessages(e){if(this.container){if(this.container.innerHTML="",e.length===0&&this.welcomeMessage){this.container.innerHTML=`<div class="welcome">${d(
|
|
361
|
+
`,this.container=this.shadow.querySelector(".message-list"),this.welcomeMessage&&this.renderMessages([])}setWelcomeMessage(e){this.welcomeMessage=e}setShowTimestamps(e){this.showTimestamps=e}renderMessages(e){if(this.container){if(this.container.innerHTML="",e.length===0&&this.welcomeMessage){this.container.innerHTML=`<div class="welcome">${c(d(this.welcomeMessage))}</div>`;return}for(const t of e)this.appendMessageElement(t);this.scrollToBottom()}}addMessage(e){const t=this.container.querySelector(".welcome");t&&t.remove(),this.appendMessageElement(e),this.scrollToBottom()}updateStreamingContent(e){const t=this.container.querySelector('[data-streaming="true"] .bubble');t&&(t.innerHTML=c(d(e)),t.classList.add("streaming-cursor"),this.scrollToBottom())}finalizeStreaming(){const e=this.container.querySelector('[data-streaming="true"]');e&&(e.removeAttribute("data-streaming"),e.querySelector(".bubble")?.classList.remove("streaming-cursor"))}showTypingIndicator(){this.removeTypingIndicator();const e=document.createElement("div");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()}removeTypingIndicator(){this.container.querySelector('[data-typing="true"]')?.remove()}appendMessageElement(e){const t=document.createElement("div");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;const a=document.createElement("div");if(a.classList.add("bubble",e.role),e.role==="user"?a.textContent=e.content:(a.innerHTML=c(d(e.content||"")),e.status==="streaming"&&a.classList.add("streaming-cursor")),e.template?.contentType){const i=document.createElement("aikaara-template-renderer");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)}if(e.attachments?.length){const i=document.createElement("div");i.classList.add("attachments");for(const r of e.attachments){const o=document.createElement("a");o.classList.add("attachment"),o.href=r.fileUrl,o.target="_blank",o.rel="noopener noreferrer",o.textContent=`📎 ${r.fileName}`,i.appendChild(o)}a.appendChild(i)}if(t.appendChild(a),this.showTimestamps&&e.createdAt||e.role==="user"&&e.status){const i=document.createElement("div");if(i.classList.add("timestamp"),this.showTimestamps&&e.createdAt&&(i.textContent=this.formatTime(e.createdAt)),e.role==="user"&&e.status){const r=document.createElement("span");r.classList.add("status-tick"),e.status==="read"&&r.classList.add("read"),r.textContent={sending:" ○",sent:" ✓",delivered:" ✓✓",read:" ✓✓"}[e.status]??"",i.appendChild(r)}t.appendChild(i)}this.container.appendChild(t)}upsertMessage(e){const t=this.findRenderedMessage(e);t&&t.remove(),this.appendMessageElement(e),this.scrollToBottom()}findRenderedMessage(e){if(e.externalId){const t=this.container.querySelector(`[data-external-id="${CSS.escape(e.externalId)}"]`);if(t)return t}return this.container.querySelector(`[data-message-id="${CSS.escape(e.id)}"]`)}scrollToBottom(){requestAnimationFrame(()=>{this.container.scrollTop=this.container.scrollHeight})}formatTime(e){try{return new Date(e).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})}catch{return""}}}class y extends HTMLElement{shadow;templatePayload=null;attachments=[];static get observedAttributes(){return["role","content","timestamp","content-type","template-id","inner-message","message-id","status"]}constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render()}attributeChangedCallback(){this.render()}setTemplatePayload(e){this.templatePayload=e,this.render()}setAttachments(e){this.attachments=e,this.render()}render(){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")||"",p=e==="user"?document.createTextNode(t).textContent||"":c(d(t)),u=e==="user"&&i,E=i==="sending"?"○":i==="sent"?"✓":i==="delivered"||i==="read"?"✓✓":"";this.shadow.innerHTML=`
|
|
328
362
|
<style>
|
|
329
363
|
:host { display: flex; flex-direction: column; }
|
|
330
364
|
:host([role="user"]) { align-items: flex-end; }
|
|
331
|
-
:host([role="assistant"])
|
|
365
|
+
:host([role="assistant"]),
|
|
366
|
+
:host([role="agent"]),
|
|
367
|
+
:host([role="system"]) { align-items: flex-start; }
|
|
332
368
|
.bubble {
|
|
333
369
|
max-width: 85%;
|
|
334
370
|
padding: 10px 14px;
|
|
@@ -342,21 +378,66 @@
|
|
|
342
378
|
color: #fff;
|
|
343
379
|
border-bottom-right-radius: 4px;
|
|
344
380
|
}
|
|
345
|
-
.bubble.assistant {
|
|
381
|
+
.bubble.assistant, .bubble.agent {
|
|
346
382
|
background: var(--aikaara-bg-secondary, #f9fafb);
|
|
347
383
|
color: var(--aikaara-text, #1f2937);
|
|
348
384
|
border-bottom-left-radius: 4px;
|
|
349
385
|
}
|
|
386
|
+
.bubble.system {
|
|
387
|
+
background: transparent;
|
|
388
|
+
color: var(--aikaara-text-secondary, #6b7280);
|
|
389
|
+
font-size: 12px;
|
|
390
|
+
font-style: italic;
|
|
391
|
+
}
|
|
350
392
|
.timestamp {
|
|
351
393
|
font-size: 11px;
|
|
352
394
|
color: var(--aikaara-text-secondary, #6b7280);
|
|
353
395
|
margin-top: 2px;
|
|
354
396
|
padding: 0 4px;
|
|
355
397
|
}
|
|
398
|
+
.status {
|
|
399
|
+
font-size: 10px;
|
|
400
|
+
color: ${i==="read"?"var(--aikaara-primary, #6366f1)":"var(--aikaara-text-secondary, #6b7280)"};
|
|
401
|
+
margin-left: 4px;
|
|
402
|
+
}
|
|
403
|
+
.attachments {
|
|
404
|
+
display: flex;
|
|
405
|
+
flex-direction: column;
|
|
406
|
+
gap: 6px;
|
|
407
|
+
margin-top: 8px;
|
|
408
|
+
}
|
|
409
|
+
.attachment {
|
|
410
|
+
display: inline-flex;
|
|
411
|
+
align-items: center;
|
|
412
|
+
gap: 6px;
|
|
413
|
+
padding: 6px 10px;
|
|
414
|
+
background: rgba(0,0,0,0.05);
|
|
415
|
+
border-radius: 8px;
|
|
416
|
+
font-size: 12px;
|
|
417
|
+
color: inherit;
|
|
418
|
+
text-decoration: none;
|
|
419
|
+
max-width: 100%;
|
|
420
|
+
}
|
|
421
|
+
.attachment:hover { background: rgba(0,0,0,0.08); }
|
|
422
|
+
aikaara-template-renderer { display: block; margin-top: 6px; }
|
|
356
423
|
</style>
|
|
357
|
-
<div class="bubble ${e}"
|
|
358
|
-
|
|
359
|
-
|
|
424
|
+
<div class="bubble ${e}">
|
|
425
|
+
<div class="content">${p}</div>
|
|
426
|
+
${r?`<aikaara-template-renderer
|
|
427
|
+
content-type="${r}"
|
|
428
|
+
template-id="${o}"
|
|
429
|
+
inner-message="${b(n)}"
|
|
430
|
+
></aikaara-template-renderer>`:""}
|
|
431
|
+
${this.renderAttachments()}
|
|
432
|
+
</div>
|
|
433
|
+
${a||u?`
|
|
434
|
+
<div class="timestamp">
|
|
435
|
+
${a}${u?`<span class="status">${E}</span>`:""}
|
|
436
|
+
</div>
|
|
437
|
+
`:""}
|
|
438
|
+
`;const h=this.shadow.querySelector("aikaara-template-renderer");h&&this.templatePayload!==null&&h.setPayload(this.templatePayload,n),h&&h.addEventListener("template-action",M=>{this.dispatchEvent(new CustomEvent("message-action",{detail:M.detail,bubbles:!0,composed:!0}))})}renderAttachments(){return this.attachments.length?`<div class="attachments">${this.attachments.map(t=>`<a class="attachment" href="${b(t.fileUrl)}" target="_blank" rel="noopener noreferrer">
|
|
439
|
+
📎 ${z(t.fileName)}
|
|
440
|
+
</a>`).join("")}</div>`:""}}function b(s){return String(s).replace(/[&<>"']/g,e=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[e])}function z(s){return String(s).replace(/[&<>]/g,e=>({"&":"&","<":"<",">":">"})[e])}class v extends HTMLElement{shadow;textarea;sendBtn;_disabled=!1;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){const e=this.getAttribute("placeholder")||"Type a message...";this.shadow.innerHTML=`
|
|
360
441
|
<style>
|
|
361
442
|
.input-container {
|
|
362
443
|
display: flex;
|
|
@@ -414,7 +495,7 @@
|
|
|
414
495
|
</svg>
|
|
415
496
|
</button>
|
|
416
497
|
</div>
|
|
417
|
-
`,this.textarea=this.shadow.querySelector("textarea"),this.sendBtn=this.shadow.querySelector(".send-btn"),this.textarea.addEventListener("input",()=>{this.autoGrow(),this.sendBtn.disabled=this._disabled||!this.textarea.value.trim()}),this.textarea.addEventListener("keydown",t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),this.handleSend())}),this.sendBtn.addEventListener("click",()=>this.handleSend())}set disabled(e){this._disabled=e,this.textarea&&(this.textarea.disabled=e),this.sendBtn&&(this.sendBtn.disabled=e||!this.textarea?.value.trim())}get disabled(){return this._disabled}focus(){this.textarea?.focus()}clear(){this.textarea&&(this.textarea.value="",this.textarea.style.height="auto",this.sendBtn.disabled=!0)}handleSend(){const e=this.textarea.value.trim();!e||this._disabled||(this.dispatchEvent(new CustomEvent("send",{detail:{content:e},bubbles:!0,composed:!0})),this.clear(),this.textarea.focus())}autoGrow(){this.textarea.style.height="auto",this.textarea.style.height=Math.min(this.textarea.scrollHeight,120)+"px"}}class
|
|
498
|
+
`,this.textarea=this.shadow.querySelector("textarea"),this.sendBtn=this.shadow.querySelector(".send-btn"),this.textarea.addEventListener("input",()=>{this.autoGrow(),this.sendBtn.disabled=this._disabled||!this.textarea.value.trim()}),this.textarea.addEventListener("keydown",t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),this.handleSend())}),this.sendBtn.addEventListener("click",()=>this.handleSend())}set disabled(e){this._disabled=e,this.textarea&&(this.textarea.disabled=e),this.sendBtn&&(this.sendBtn.disabled=e||!this.textarea?.value.trim())}get disabled(){return this._disabled}focus(){this.textarea?.focus()}clear(){this.textarea&&(this.textarea.value="",this.textarea.style.height="auto",this.sendBtn.disabled=!0)}handleSend(){const e=this.textarea.value.trim();!e||this._disabled||(this.dispatchEvent(new CustomEvent("send",{detail:{content:e},bubbles:!0,composed:!0})),this.clear(),this.textarea.focus())}autoGrow(){this.textarea.style.height="auto",this.textarea.style.height=Math.min(this.textarea.scrollHeight,120)+"px"}}class w extends HTMLElement{shadow;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.shadow.innerHTML=`
|
|
418
499
|
<style>
|
|
419
500
|
:host { display: none; }
|
|
420
501
|
:host([visible]) { display: block; }
|
|
@@ -448,7 +529,7 @@
|
|
|
448
529
|
<span class="dot"></span>
|
|
449
530
|
<span class="dot"></span>
|
|
450
531
|
</div>
|
|
451
|
-
`}show(){this.setAttribute("visible","")}hide(){this.removeAttribute("visible")}}class
|
|
532
|
+
`}show(){this.setAttribute("visible","")}hide(){this.removeAttribute("visible")}}class C extends HTMLElement{shadow;bubble;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.shadow.innerHTML=`
|
|
452
533
|
<style>
|
|
453
534
|
:host {
|
|
454
535
|
display: flex;
|
|
@@ -497,7 +578,7 @@
|
|
|
497
578
|
}
|
|
498
579
|
</style>
|
|
499
580
|
<div class="bubble cursor"></div>
|
|
500
|
-
`,this.bubble=this.shadow.querySelector(".bubble")}updateContent(e){this.bubble&&(this.bubble.innerHTML=d(
|
|
581
|
+
`,this.bubble=this.shadow.querySelector(".bubble")}updateContent(e){this.bubble&&(this.bubble.innerHTML=c(d(e)),this.bubble.classList.add("cursor"))}finalize(){this.bubble?.classList.remove("cursor")}}class A extends HTMLElement{shadow;container;dismissTimer=null;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.shadow.innerHTML=`
|
|
501
582
|
<style>
|
|
502
583
|
.banner {
|
|
503
584
|
display: none;
|
|
@@ -525,4 +606,16 @@
|
|
|
525
606
|
<span class="message"></span>
|
|
526
607
|
<button class="dismiss">Dismiss</button>
|
|
527
608
|
</div>
|
|
528
|
-
`,this.container=this.shadow.querySelector(".banner"),this.shadow.querySelector(".dismiss")?.addEventListener("click",()=>this.hide())}show(e,t){const a=this.container.querySelector(".message");a&&(a.textContent=e),this.container.classList.add("visible"),this.dismissTimer&&clearTimeout(this.dismissTimer),t&&(this.dismissTimer=setTimeout(()=>this.hide(),t))}hide(){this.container.classList.remove("visible"),this.dismissTimer&&(clearTimeout(this.dismissTimer),this.dismissTimer=null)}}
|
|
609
|
+
`,this.container=this.shadow.querySelector(".banner"),this.shadow.querySelector(".dismiss")?.addEventListener("click",()=>this.hide())}show(e,t){const a=this.container.querySelector(".message");a&&(a.textContent=e),this.container.classList.add("visible"),this.dismissTimer&&clearTimeout(this.dismissTimer),t&&(this.dismissTimer=setTimeout(()=>this.hide(),t))}hide(){this.container.classList.remove("visible"),this.dismissTimer&&(clearTimeout(this.dismissTimer),this.dismissTimer=null)}}class T extends HTMLElement{shadow;payloadData=null;innerMessage="";static get observedAttributes(){return["content-type","template-id","inner-message"]}constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render()}attributeChangedCallback(){this.render()}setPayload(e,t){this.payloadData=e,t!==void 0&&(this.innerMessage=t),this.render()}render(){const e=this.getAttribute("content-type")??"",t=this.getAttribute("template-id")??"",a=this.getAttribute("inner-message")??this.innerMessage;this.shadow.innerHTML=`
|
|
610
|
+
<style>
|
|
611
|
+
:host { display: block; }
|
|
612
|
+
.inner { font-size: 14px; line-height: 1.5; color: var(--aikaara-text, #1f2937); }
|
|
613
|
+
.placeholder {
|
|
614
|
+
font-size: 12px;
|
|
615
|
+
color: var(--aikaara-text-secondary, #6b7280);
|
|
616
|
+
padding: 6px 0;
|
|
617
|
+
}
|
|
618
|
+
</style>
|
|
619
|
+
${a?'<div class="inner"></div>':""}
|
|
620
|
+
<slot></slot>
|
|
621
|
+
`;const i=this.shadow.querySelector(".inner");if(i&&a&&(i.textContent=a),!e)return;const r=t?`aikaara-template-${t}`:`aikaara-template-${e}`;if(customElements.get(r)){const o=this.querySelector(r);if(o){o.setPayload?.(this.payloadData);return}const n=document.createElement(r);n.setPayload?.(this.payloadData),n.addEventListener("template-action",p=>{this.dispatchEvent(new CustomEvent("template-action",{detail:p.detail,bubbles:!0,composed:!0}))}),this.appendChild(n)}}}function L(){const s=[["aikaara-chat-widget",m],["aikaara-chat-bubble",g],["aikaara-chat-header",f],["aikaara-message-list",k],["aikaara-message-bubble",y],["aikaara-chat-input",v],["aikaara-typing-indicator",w],["aikaara-streaming-message",C],["aikaara-error-banner",A],["aikaara-template-renderer",T]];for(const[e,t]of s)customElements.get(e)||customElements.define(e,t)}L();exports.AikaaraChatBubble=g;exports.AikaaraChatHeader=f;exports.AikaaraChatInput=v;exports.AikaaraChatWidget=m;exports.AikaaraErrorBanner=A;exports.AikaaraMessageBubble=y;exports.AikaaraMessageList=k;exports.AikaaraStreamingMessage=C;exports.AikaaraTemplateRenderer=T;exports.AikaaraTypingIndicator=w;exports.registerComponents=L;
|