@aikaara/chat-sdk 0.4.0 → 0.4.2
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 → MountTenant-BIFRI4Kz.mjs} +35 -23
- package/dist/{MountTenant-dM6HzlAl.cjs → MountTenant-DrJJvB4L.cjs} +1 -1
- package/dist/headless.cjs +1 -1
- package/dist/headless.d.ts +7 -0
- package/dist/headless.mjs +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.mjs +2 -2
- package/dist/ui.cjs +1 -1
- package/dist/ui.mjs +1 -1
- package/package.json +1 -1
|
@@ -13632,43 +13632,55 @@ function ph(u) {
|
|
|
13632
13632
|
return e;
|
|
13633
13633
|
}
|
|
13634
13634
|
async function gh(u) {
|
|
13635
|
-
const t = `${(u.configBase ?? "https://api.aikaara.com").replace(/\/$/, "")}/widget_configs/${encodeURIComponent(u.slug)}
|
|
13636
|
-
|
|
13635
|
+
const t = `${(u.configBase ?? "https://api.aikaara.com").replace(/\/$/, "")}/widget_configs/${encodeURIComponent(u.slug)}`;
|
|
13636
|
+
let i = null;
|
|
13637
|
+
try {
|
|
13638
|
+
i = await Xa(t, u.configHeaders);
|
|
13639
|
+
} catch (d) {
|
|
13640
|
+
if (!u.fallbackConfig) throw d;
|
|
13641
|
+
console.warn(
|
|
13642
|
+
`[aikaara-chat-sdk] Widget config fetch failed for slug "${u.slug}" — using fallbackConfig.`,
|
|
13643
|
+
d
|
|
13644
|
+
);
|
|
13645
|
+
}
|
|
13646
|
+
const l = {
|
|
13647
|
+
...u.fallbackConfig ?? {},
|
|
13648
|
+
...i ?? {},
|
|
13637
13649
|
...u.overrides ?? {}
|
|
13638
13650
|
};
|
|
13639
|
-
if (!
|
|
13651
|
+
if (!l.auth)
|
|
13640
13652
|
throw new Error(
|
|
13641
13653
|
`mountFromSlug: widget_configs/${u.slug} descriptor must include "auth" block`
|
|
13642
13654
|
);
|
|
13643
|
-
const
|
|
13644
|
-
...
|
|
13645
|
-
authHeader: async () => `Bearer ${(await
|
|
13646
|
-
}) :
|
|
13647
|
-
endpoint:
|
|
13648
|
-
fieldName:
|
|
13649
|
-
extraFields:
|
|
13650
|
-
headers: async () => ({ authorization: `Bearer ${(await
|
|
13651
|
-
}) : void 0),
|
|
13655
|
+
const r = new ah(l.auth, u.user.token), n = await r.get(), o = n.fullName || u.user.name || u.user.id, s = l.upload, a = u.hooks?.upload ?? (s && s.mode === "presigned-3step" ? Rc({
|
|
13656
|
+
...s,
|
|
13657
|
+
authHeader: async () => `Bearer ${(await r.get()).token}`
|
|
13658
|
+
}) : s && s.mode === "direct" ? Ya({
|
|
13659
|
+
endpoint: s.endpoint,
|
|
13660
|
+
fieldName: s.fieldName,
|
|
13661
|
+
extraFields: s.extraFields,
|
|
13662
|
+
headers: async () => ({ authorization: `Bearer ${(await r.get()).token}` })
|
|
13663
|
+
}) : void 0), c = await dh({
|
|
13652
13664
|
container: ph(u.container),
|
|
13653
|
-
config:
|
|
13665
|
+
config: l,
|
|
13654
13666
|
identity: {
|
|
13655
13667
|
userId: u.user.id,
|
|
13656
|
-
userName:
|
|
13668
|
+
userName: o,
|
|
13657
13669
|
departmentId: u.user.departmentId,
|
|
13658
|
-
senderFullname:
|
|
13670
|
+
senderFullname: o
|
|
13659
13671
|
},
|
|
13660
|
-
tokenProvider: async () => (await
|
|
13661
|
-
historyTokenProvider: async () => (await
|
|
13662
|
-
uploadAdapter:
|
|
13672
|
+
tokenProvider: async () => (await r.get()).token,
|
|
13673
|
+
historyTokenProvider: async () => (await r.get()).token,
|
|
13674
|
+
uploadAdapter: a,
|
|
13663
13675
|
historyAdapter: u.hooks?.history,
|
|
13664
|
-
conversationId:
|
|
13676
|
+
conversationId: n.requestId,
|
|
13665
13677
|
onError: u.hooks?.onError
|
|
13666
13678
|
});
|
|
13667
|
-
return Object.assign(
|
|
13668
|
-
fullName:
|
|
13669
|
-
requestId:
|
|
13679
|
+
return Object.assign(c, {
|
|
13680
|
+
fullName: o,
|
|
13681
|
+
requestId: n.requestId,
|
|
13670
13682
|
async refreshAuth() {
|
|
13671
|
-
|
|
13683
|
+
r.reset(), await r.get();
|
|
13672
13684
|
}
|
|
13673
13685
|
});
|
|
13674
13686
|
}
|
|
@@ -789,4 +789,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
789
789
|
</div>
|
|
790
790
|
</div>
|
|
791
791
|
</div>
|
|
792
|
-
`,this.shadow.querySelector("button.ok").addEventListener("click",()=>this.handleOk()),this.shadow.querySelector("button.cancel")?.addEventListener("click",()=>this.dismiss())}}function Fr(u){return String(u).replace(/[&<>]/g,e=>({"&":"&","<":"<",">":">"})[e])}class kl extends HTMLElement{static get observedAttributes(){return["slug","user-id","user-name","user-token","department-id","config-base"]}tokenGetter;mounted=null;mountInflight=null;connectedCallback(){this.style.display||(this.style.display="flex"),this.style.flexDirection||(this.style.flexDirection="column"),this.style.minHeight||(this.style.minHeight="0"),this.tryMount()}disconnectedCallback(){this.mounted?.destroy(),this.mounted=null}attributeChangedCallback(){this.isConnected&&(this.mounted?.destroy(),this.mounted=null,this.tryMount())}async refreshAuth(){await this.mounted?.refreshAuth()}async tryMount(){if(this.mountInflight)return this.mountInflight;const e=this.getAttribute("slug"),t=this.getAttribute("user-id");if(!e||!t)return;const i=this.getAttribute("user-token"),l=this.tokenGetter??i;if(!l){this.dispatchEvent(new CustomEvent("error",{detail:new Error("aikaara-chat: user-token attribute or tokenGetter property required")}));return}return this.mountInflight=(async()=>{try{this.mounted=await Ol({container:this,slug:e,configBase:this.getAttribute("config-base")??void 0,user:{id:t,name:this.getAttribute("user-name")??void 0,departmentId:this.getAttribute("department-id")??void 0,token:l},hooks:{onError:r=>this.dispatchEvent(new CustomEvent("error",{detail:r}))}}),this.dispatchEvent(new CustomEvent("ready",{detail:{requestId:this.mounted.requestId,fullName:this.mounted.fullName}}))}catch(r){this.dispatchEvent(new CustomEvent("error",{detail:r}))}finally{this.mountInflight=null}})(),this.mountInflight}}function xl(){const u=[["aikaara-chat-widget",ul],["aikaara-chat-bubble",cl],["aikaara-chat-header",hl],["aikaara-message-list",dl],["aikaara-message-bubble",pl],["aikaara-chat-input",gl],["aikaara-typing-indicator",ml],["aikaara-streaming-message",bl],["aikaara-error-banner",yl],["aikaara-template-renderer",vl],["aikaara-system-pill",wl],["aikaara-option-list",_l],["aikaara-submit-action",Sl],["aikaara-modal-action",El],["aikaara-chat",kl]];for(const[e,t]of u)customElements.get(e)||customElements.define(e,t)}xl();function Wr(u,e,t=""){if(!e)return t;const i=e.split(".");let l=u;for(const r of i)if(l&&typeof l=="object"&&r in l)l=l[r];else return t;return typeof l=="string"?l:t}function lh(u){try{const e=u.split(".")[1];if(!e)return 0;const t=JSON.parse(atob(e.replace(/-/g,"+").replace(/_/g,"/")));return typeof t.exp=="number"?t.exp*1e3:0}catch{return 0}}async function uh(u){return typeof u=="function"?await u():u}class Al{constructor(e,t){this.descriptor=e,this.sessionToken=t}cache=null;inflight=null;reset(){this.cache=null,this.inflight=null}async get(){const e=this.descriptor.expiryBufferMs??6e4,t=Date.now();return this.cache&&this.cache.expiresAt>t+e?this.cache:this.inflight?this.inflight:(this.inflight=this.fetchOnce().finally(()=>{this.inflight=null}),this.inflight)}async fetchOnce(){const e=await uh(this.sessionToken),t=this.descriptor.authHeader??"Authorization",i=this.descriptor.authHeaderTemplate??"Bearer {token}",l={accept:"application/json",...this.descriptor.headers??{},[t]:i.replace("{token}",e)},r=this.descriptor.method??"POST",n={method:r,headers:l};r==="POST"&&(l["content-type"]="application/json",n.body=JSON.stringify(this.descriptor.body??{}));const o=await fetch(this.descriptor.endpoint,n);if(!o.ok){const b=await o.text().catch(()=>"");throw new Error(`Session auth failed: ${o.status} ${b.slice(0,200)}`)}const s=await o.json().catch(()=>({})),a=Wr(s,this.descriptor.tokenPath??"data.token"),c=this.descriptor.tokenStripPrefix,d=c?a.replace(new RegExp(`^${c}`,"i"),"").trim():a;if(!d)throw new Error("Session auth response missing token");const p=Wr(s,this.descriptor.requestIdPath??"data.requestId"),y=this.cache?.requestId||p;if(!y)throw new Error("Session auth response missing requestId");const f=Wr(s,this.descriptor.fullNamePath??"data.fullName"),m=lh(d)||Date.now()+3600*1e3;return this.cache={token:d,requestId:y,fullName:f,expiresAt:m},this.cache}}function ch(){const u=typeof crypto<"u"?crypto:null;if(u?.randomUUID)return u.randomUUID();if(u?.getRandomValues){const e=new Uint8Array(16);u.getRandomValues(e),e[6]=e[6]&15|64,e[8]=e[8]&63|128;const t=[...e].map(i=>i.toString(16).padStart(2,"0")).join("");return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}const hh="aikaara_chat:requestId";function is(u,e){return`${hh}:${u}:${e}`}function fh(u,e){try{return localStorage.getItem(is(u,e))}catch{return null}}function dh(u,e,t){try{localStorage.setItem(is(u,e),t)}catch{}}function ph(u,e){try{localStorage.removeItem(is(u,e))}catch{}}async function Il(u,e){const t=await fetch(u,{method:"GET",headers:{accept:"application/json",...e??{}}});if(!t.ok){const l=await t.text().catch(()=>"");throw new Error(`Widget config fetch failed: ${t.status} ${t.statusText} ${l.slice(0,200)}`)}const i=await t.json();if(i&&typeof i=="object"){if("config"in i)return i.config;if("data"in i)return i.data}return i}function gh(u,e){return u.replace("{projectId}",e).replace("{uuid}",ch().replace(/-/g,""))}async function Tl(u){const e={...u.config??(u.configUrl?await Il(u.configUrl,u.configHeaders):{}),...u.overrides??{}},t=e.transport??"tiledesk",i=e.tiledesk;if((t==="tiledesk"||t==="dual")&&!i)throw new Error("mount: descriptor.tiledesk is required for tiledesk/dual transport");const l=i?.projectId??"",r=u.identity.userId,n=u.forceNewConversation?null:fh(r,l),o=i?.requestIdTemplate??"support-group-{projectId}-{uuid}",s=u.conversationId??n??gh(o,l);(!n||u.forceNewConversation)&&l&&dh(r,l,s);const a=await u.tokenProvider(),c=u.tokenProvider,d=u.historyTokenProvider??c,p=i?{mqttEndpoint:i.mqttEndpoint,jwtToken:a,userId:r,userName:u.identity.userName,projectId:i.projectId,appId:i.appId,mqttUsername:i.mqttUsername,protocolId:i.protocolId,protocolVersion:i.protocolVersion,keepAliveSec:i.keepAliveSec,connectTimeoutMs:i.connectTimeoutMs,maxReconnectAttempts:i.maxReconnectAttempts,reconnectMaxDelayMs:i.reconnectMaxDelayMs,wildcardSubscribe:i.wildcardSubscribe,enablePresence:i.enablePresence,autoInitiateOnEmpty:i.autoInitiateOnEmpty,chatInitiatedAttributes:i.chatInitiatedAttributes,messageDefaults:{...i.messageDefaults,...u.identity.departmentId?{departmentId:u.identity.departmentId}:i.messageDefaults?.departmentId?{departmentId:i.messageDefaults.departmentId}:{}},fileTemplate:i.fileTemplate,topicTemplates:i.topicTemplates,debug:i.debug,senderFullname:u.identity.senderFullname??u.identity.userName,tokenProvider:c}:void 0,y=u.uploadAdapter??(e.uploadEndpoint?ns({endpoint:e.uploadEndpoint,fieldName:e.uploadFieldName,extraFields:e.uploadExtraFields}):void 0),f=u.historyAdapter??(e.historyApiBase?ll({apiBase:e.historyApiBase,pageSize:e.historyPageSize??200,pathTemplate:e.historyPathTemplate,getToken:d}):void 0),m={transport:t,baseUrl:"",userToken:r,conversationId:s,display:e.display??"embed",position:e.position,primaryColor:e.primaryColor,title:e.title,subtitle:e.subtitle,avatarUrl:e.avatarUrl,width:e.width,height:e.height,borderRadius:e.borderRadius,fontFamily:e.fontFamily,welcomeMessage:e.welcomeMessage,placeholder:e.placeholder,showTimestamps:e.showTimestamps,persistConversation:e.persistConversation,tiledesk:p,tiledeskIdentity:{userId:r,userName:u.identity.userName,departmentId:u.identity.departmentId,senderFullname:u.identity.senderFullname??u.identity.userName},templateActionAttributes:e.templateActionAttributes,uploadAdapter:y,historyAdapter:f,onError:u.onError},b=document.createElement("aikaara-chat-widget");return b.configure(m),m.title&&b.setAttribute("title",m.title),m.primaryColor&&b.setAttribute("primary-color",m.primaryColor),m.display&&b.setAttribute("display",m.display),m.display==="embed"&&(b.style.cssText="display:flex;flex-direction:column;width:100%;height:100%;min-height:0;"),u.container.appendChild(b),{widget:b,requestId:s,config:m,destroy(){b.remove()}}}function mh(u){if(typeof u!="string")return u;const e=document.querySelector(u);if(!e)throw new Error(`mountFromSlug: container "${u}" not found`);return e}async function Ol(u){const t=`${(u.configBase??"https://api.aikaara.com").replace(/\/$/,"")}/widget_configs/${encodeURIComponent(u.slug)}`,i={...await Il(t,u.configHeaders),...u.overrides??{}};if(!i.auth)throw new Error(`mountFromSlug: widget_configs/${u.slug} descriptor must include "auth" block`);const l=new Al(i.auth,u.user.token),r=await l.get(),n=r.fullName||u.user.name||u.user.id,o=i.upload,s=u.hooks?.upload??(o&&o.mode==="presigned-3step"?al({...o,authHeader:async()=>`Bearer ${(await l.get()).token}`}):o&&o.mode==="direct"?ns({endpoint:o.endpoint,fieldName:o.fieldName,extraFields:o.extraFields,headers:async()=>({authorization:`Bearer ${(await l.get()).token}`})}):void 0),a=await Tl({container:mh(u.container),config:i,identity:{userId:u.user.id,userName:n,departmentId:u.user.departmentId,senderFullname:n},tokenProvider:async()=>(await l.get()).token,historyTokenProvider:async()=>(await l.get()).token,uploadAdapter:s,historyAdapter:u.hooks?.history,conversationId:r.requestId,onError:u.hooks?.onError});return Object.assign(a,{fullName:n,requestId:r.requestId,async refreshAuth(){l.reset(),await l.get()}})}exports.ActionCableClient=$r;exports.AikaaraChat=kl;exports.AikaaraChatBubble=cl;exports.AikaaraChatClient=ol;exports.AikaaraChatHeader=hl;exports.AikaaraChatInput=gl;exports.AikaaraChatWidget=ul;exports.AikaaraErrorBanner=yl;exports.AikaaraMessageBubble=pl;exports.AikaaraMessageList=dl;exports.AikaaraModalAction=El;exports.AikaaraOptionList=_l;exports.AikaaraStreamingMessage=bl;exports.AikaaraSubmitAction=Sl;exports.AikaaraSystemPill=wl;exports.AikaaraTemplateRenderer=vl;exports.AikaaraTypingIndicator=ml;exports.ApiClient=So;exports.ChannelSubscription=wo;exports.ConnectionManager=_o;exports.ConversationManager=ko;exports.EventEmitter=Wi;exports.MessageStore=Eo;exports.SessionAuthAdapter=Al;exports.TiledeskTransport=rl;exports.clearPersistedConversationId=ph;exports.createFetchUploadAdapter=ns;exports.createPresigned3StepUploadAdapter=al;exports.createTiledeskHistoryAdapter=ll;exports.extractTiledeskFileEnvelope=sl;exports.inferTiledeskRole=il;exports.isTiledeskSelfEcho=nl;exports.mount=Tl;exports.mountFromSlug=Ol;exports.parseTiledeskTemplate=rs;exports.registerComponents=xl;
|
|
792
|
+
`,this.shadow.querySelector("button.ok").addEventListener("click",()=>this.handleOk()),this.shadow.querySelector("button.cancel")?.addEventListener("click",()=>this.dismiss())}}function Fr(u){return String(u).replace(/[&<>]/g,e=>({"&":"&","<":"<",">":">"})[e])}class kl extends HTMLElement{static get observedAttributes(){return["slug","user-id","user-name","user-token","department-id","config-base"]}tokenGetter;mounted=null;mountInflight=null;connectedCallback(){this.style.display||(this.style.display="flex"),this.style.flexDirection||(this.style.flexDirection="column"),this.style.minHeight||(this.style.minHeight="0"),this.tryMount()}disconnectedCallback(){this.mounted?.destroy(),this.mounted=null}attributeChangedCallback(){this.isConnected&&(this.mounted?.destroy(),this.mounted=null,this.tryMount())}async refreshAuth(){await this.mounted?.refreshAuth()}async tryMount(){if(this.mountInflight)return this.mountInflight;const e=this.getAttribute("slug"),t=this.getAttribute("user-id");if(!e||!t)return;const i=this.getAttribute("user-token"),l=this.tokenGetter??i;if(!l){this.dispatchEvent(new CustomEvent("error",{detail:new Error("aikaara-chat: user-token attribute or tokenGetter property required")}));return}return this.mountInflight=(async()=>{try{this.mounted=await Ol({container:this,slug:e,configBase:this.getAttribute("config-base")??void 0,user:{id:t,name:this.getAttribute("user-name")??void 0,departmentId:this.getAttribute("department-id")??void 0,token:l},hooks:{onError:r=>this.dispatchEvent(new CustomEvent("error",{detail:r}))}}),this.dispatchEvent(new CustomEvent("ready",{detail:{requestId:this.mounted.requestId,fullName:this.mounted.fullName}}))}catch(r){this.dispatchEvent(new CustomEvent("error",{detail:r}))}finally{this.mountInflight=null}})(),this.mountInflight}}function xl(){const u=[["aikaara-chat-widget",ul],["aikaara-chat-bubble",cl],["aikaara-chat-header",hl],["aikaara-message-list",dl],["aikaara-message-bubble",pl],["aikaara-chat-input",gl],["aikaara-typing-indicator",ml],["aikaara-streaming-message",bl],["aikaara-error-banner",yl],["aikaara-template-renderer",vl],["aikaara-system-pill",wl],["aikaara-option-list",_l],["aikaara-submit-action",Sl],["aikaara-modal-action",El],["aikaara-chat",kl]];for(const[e,t]of u)customElements.get(e)||customElements.define(e,t)}xl();function Wr(u,e,t=""){if(!e)return t;const i=e.split(".");let l=u;for(const r of i)if(l&&typeof l=="object"&&r in l)l=l[r];else return t;return typeof l=="string"?l:t}function lh(u){try{const e=u.split(".")[1];if(!e)return 0;const t=JSON.parse(atob(e.replace(/-/g,"+").replace(/_/g,"/")));return typeof t.exp=="number"?t.exp*1e3:0}catch{return 0}}async function uh(u){return typeof u=="function"?await u():u}class Al{constructor(e,t){this.descriptor=e,this.sessionToken=t}cache=null;inflight=null;reset(){this.cache=null,this.inflight=null}async get(){const e=this.descriptor.expiryBufferMs??6e4,t=Date.now();return this.cache&&this.cache.expiresAt>t+e?this.cache:this.inflight?this.inflight:(this.inflight=this.fetchOnce().finally(()=>{this.inflight=null}),this.inflight)}async fetchOnce(){const e=await uh(this.sessionToken),t=this.descriptor.authHeader??"Authorization",i=this.descriptor.authHeaderTemplate??"Bearer {token}",l={accept:"application/json",...this.descriptor.headers??{},[t]:i.replace("{token}",e)},r=this.descriptor.method??"POST",n={method:r,headers:l};r==="POST"&&(l["content-type"]="application/json",n.body=JSON.stringify(this.descriptor.body??{}));const o=await fetch(this.descriptor.endpoint,n);if(!o.ok){const b=await o.text().catch(()=>"");throw new Error(`Session auth failed: ${o.status} ${b.slice(0,200)}`)}const s=await o.json().catch(()=>({})),a=Wr(s,this.descriptor.tokenPath??"data.token"),c=this.descriptor.tokenStripPrefix,d=c?a.replace(new RegExp(`^${c}`,"i"),"").trim():a;if(!d)throw new Error("Session auth response missing token");const p=Wr(s,this.descriptor.requestIdPath??"data.requestId"),y=this.cache?.requestId||p;if(!y)throw new Error("Session auth response missing requestId");const f=Wr(s,this.descriptor.fullNamePath??"data.fullName"),m=lh(d)||Date.now()+3600*1e3;return this.cache={token:d,requestId:y,fullName:f,expiresAt:m},this.cache}}function ch(){const u=typeof crypto<"u"?crypto:null;if(u?.randomUUID)return u.randomUUID();if(u?.getRandomValues){const e=new Uint8Array(16);u.getRandomValues(e),e[6]=e[6]&15|64,e[8]=e[8]&63|128;const t=[...e].map(i=>i.toString(16).padStart(2,"0")).join("");return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}const hh="aikaara_chat:requestId";function is(u,e){return`${hh}:${u}:${e}`}function fh(u,e){try{return localStorage.getItem(is(u,e))}catch{return null}}function dh(u,e,t){try{localStorage.setItem(is(u,e),t)}catch{}}function ph(u,e){try{localStorage.removeItem(is(u,e))}catch{}}async function Il(u,e){const t=await fetch(u,{method:"GET",headers:{accept:"application/json",...e??{}}});if(!t.ok){const l=await t.text().catch(()=>"");throw new Error(`Widget config fetch failed: ${t.status} ${t.statusText} ${l.slice(0,200)}`)}const i=await t.json();if(i&&typeof i=="object"){if("config"in i)return i.config;if("data"in i)return i.data}return i}function gh(u,e){return u.replace("{projectId}",e).replace("{uuid}",ch().replace(/-/g,""))}async function Tl(u){const e={...u.config??(u.configUrl?await Il(u.configUrl,u.configHeaders):{}),...u.overrides??{}},t=e.transport??"tiledesk",i=e.tiledesk;if((t==="tiledesk"||t==="dual")&&!i)throw new Error("mount: descriptor.tiledesk is required for tiledesk/dual transport");const l=i?.projectId??"",r=u.identity.userId,n=u.forceNewConversation?null:fh(r,l),o=i?.requestIdTemplate??"support-group-{projectId}-{uuid}",s=u.conversationId??n??gh(o,l);(!n||u.forceNewConversation)&&l&&dh(r,l,s);const a=await u.tokenProvider(),c=u.tokenProvider,d=u.historyTokenProvider??c,p=i?{mqttEndpoint:i.mqttEndpoint,jwtToken:a,userId:r,userName:u.identity.userName,projectId:i.projectId,appId:i.appId,mqttUsername:i.mqttUsername,protocolId:i.protocolId,protocolVersion:i.protocolVersion,keepAliveSec:i.keepAliveSec,connectTimeoutMs:i.connectTimeoutMs,maxReconnectAttempts:i.maxReconnectAttempts,reconnectMaxDelayMs:i.reconnectMaxDelayMs,wildcardSubscribe:i.wildcardSubscribe,enablePresence:i.enablePresence,autoInitiateOnEmpty:i.autoInitiateOnEmpty,chatInitiatedAttributes:i.chatInitiatedAttributes,messageDefaults:{...i.messageDefaults,...u.identity.departmentId?{departmentId:u.identity.departmentId}:i.messageDefaults?.departmentId?{departmentId:i.messageDefaults.departmentId}:{}},fileTemplate:i.fileTemplate,topicTemplates:i.topicTemplates,debug:i.debug,senderFullname:u.identity.senderFullname??u.identity.userName,tokenProvider:c}:void 0,y=u.uploadAdapter??(e.uploadEndpoint?ns({endpoint:e.uploadEndpoint,fieldName:e.uploadFieldName,extraFields:e.uploadExtraFields}):void 0),f=u.historyAdapter??(e.historyApiBase?ll({apiBase:e.historyApiBase,pageSize:e.historyPageSize??200,pathTemplate:e.historyPathTemplate,getToken:d}):void 0),m={transport:t,baseUrl:"",userToken:r,conversationId:s,display:e.display??"embed",position:e.position,primaryColor:e.primaryColor,title:e.title,subtitle:e.subtitle,avatarUrl:e.avatarUrl,width:e.width,height:e.height,borderRadius:e.borderRadius,fontFamily:e.fontFamily,welcomeMessage:e.welcomeMessage,placeholder:e.placeholder,showTimestamps:e.showTimestamps,persistConversation:e.persistConversation,tiledesk:p,tiledeskIdentity:{userId:r,userName:u.identity.userName,departmentId:u.identity.departmentId,senderFullname:u.identity.senderFullname??u.identity.userName},templateActionAttributes:e.templateActionAttributes,uploadAdapter:y,historyAdapter:f,onError:u.onError},b=document.createElement("aikaara-chat-widget");return b.configure(m),m.title&&b.setAttribute("title",m.title),m.primaryColor&&b.setAttribute("primary-color",m.primaryColor),m.display&&b.setAttribute("display",m.display),m.display==="embed"&&(b.style.cssText="display:flex;flex-direction:column;width:100%;height:100%;min-height:0;"),u.container.appendChild(b),{widget:b,requestId:s,config:m,destroy(){b.remove()}}}function mh(u){if(typeof u!="string")return u;const e=document.querySelector(u);if(!e)throw new Error(`mountFromSlug: container "${u}" not found`);return e}async function Ol(u){const t=`${(u.configBase??"https://api.aikaara.com").replace(/\/$/,"")}/widget_configs/${encodeURIComponent(u.slug)}`;let i=null;try{i=await Il(t,u.configHeaders)}catch(d){if(!u.fallbackConfig)throw d;console.warn(`[aikaara-chat-sdk] Widget config fetch failed for slug "${u.slug}" — using fallbackConfig.`,d)}const l={...u.fallbackConfig??{},...i??{},...u.overrides??{}};if(!l.auth)throw new Error(`mountFromSlug: widget_configs/${u.slug} descriptor must include "auth" block`);const r=new Al(l.auth,u.user.token),n=await r.get(),o=n.fullName||u.user.name||u.user.id,s=l.upload,a=u.hooks?.upload??(s&&s.mode==="presigned-3step"?al({...s,authHeader:async()=>`Bearer ${(await r.get()).token}`}):s&&s.mode==="direct"?ns({endpoint:s.endpoint,fieldName:s.fieldName,extraFields:s.extraFields,headers:async()=>({authorization:`Bearer ${(await r.get()).token}`})}):void 0),c=await Tl({container:mh(u.container),config:l,identity:{userId:u.user.id,userName:o,departmentId:u.user.departmentId,senderFullname:o},tokenProvider:async()=>(await r.get()).token,historyTokenProvider:async()=>(await r.get()).token,uploadAdapter:a,historyAdapter:u.hooks?.history,conversationId:n.requestId,onError:u.hooks?.onError});return Object.assign(c,{fullName:o,requestId:n.requestId,async refreshAuth(){r.reset(),await r.get()}})}exports.ActionCableClient=$r;exports.AikaaraChat=kl;exports.AikaaraChatBubble=cl;exports.AikaaraChatClient=ol;exports.AikaaraChatHeader=hl;exports.AikaaraChatInput=gl;exports.AikaaraChatWidget=ul;exports.AikaaraErrorBanner=yl;exports.AikaaraMessageBubble=pl;exports.AikaaraMessageList=dl;exports.AikaaraModalAction=El;exports.AikaaraOptionList=_l;exports.AikaaraStreamingMessage=bl;exports.AikaaraSubmitAction=Sl;exports.AikaaraSystemPill=wl;exports.AikaaraTemplateRenderer=vl;exports.AikaaraTypingIndicator=ml;exports.ApiClient=So;exports.ChannelSubscription=wo;exports.ConnectionManager=_o;exports.ConversationManager=ko;exports.EventEmitter=Wi;exports.MessageStore=Eo;exports.SessionAuthAdapter=Al;exports.TiledeskTransport=rl;exports.clearPersistedConversationId=ph;exports.createFetchUploadAdapter=ns;exports.createPresigned3StepUploadAdapter=al;exports.createTiledeskHistoryAdapter=ll;exports.extractTiledeskFileEnvelope=sl;exports.inferTiledeskRole=il;exports.isTiledeskSelfEcho=nl;exports.mount=Tl;exports.mountFromSlug=Ol;exports.parseTiledeskTemplate=rs;exports.registerComponents=xl;
|
package/dist/headless.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./MountTenant-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./MountTenant-DrJJvB4L.cjs");class s extends i.EventEmitter{registration=null;pendingEdits=[];constructor(e){super(),this.setupListeners(e)}registerForm(e){this.registration=e;const t=this.pendingEdits.filter(r=>r.entity_type===e.entityType&&String(r.entity_id)===String(e.entityId));if(t.length>0){for(const r of t)e.onFieldUpdate(r.fields),this.emit("edit:applied",{entityType:r.entity_type,entityId:r.entity_id,fields:r.fields});this.pendingEdits=this.pendingEdits.filter(r=>!(r.entity_type===e.entityType&&String(r.entity_id)===String(e.entityId)))}}unregisterForm(e,t){this.registration?.entityType===e&&String(this.registration?.entityId)===String(t)&&(this.registration=null)}get currentForm(){return this.registration}pushFieldUpdates(e,t,r){this.registration&&this.registration.entityType===e&&String(this.registration.entityId)===String(t)?(this.registration.onFieldUpdate(r),this.emit("edit:applied",{entityType:e,entityId:t,fields:r})):(this.pendingEdits.push({action:"edit_entity",entity_type:e,entity_id:t,fields:r}),this.emit("edit:pending",{entityType:e,entityId:t,fields:r}))}async requestSave(){if(!this.registration)return{success:!1,error:"No form registered"};try{return await this.registration.onSave(),this.emit("save:success",{entityType:this.registration.entityType,entityId:this.registration.entityId}),{success:!0}}catch(e){const t=e instanceof Error?e.message:"Save failed";return this.emit("save:error",{entityType:this.registration.entityType,entityId:this.registration.entityId,error:t}),{success:!1,error:t}}}async requestTest(e){if(!this.registration?.onTest)return{success:!1,error:"Current form does not support testing"};try{return await this.registration.onTest(e),{success:!0}}catch(t){return{success:!1,error:t instanceof Error?t.message:"Test failed"}}}setupListeners(e){e.on("action:edit_entity",t=>{this.pushFieldUpdates(t.entity_type,t.entity_id,t.fields)}),e.on("action:save_entity",t=>{this.requestSave()}),e.on("action:test_tool",t=>{this.emit("test:triggered",{toolId:t.tool_id,parameters:t.parameters}),this.requestTest(t.parameters)})}}exports.ActionCableClient=i.ActionCableClient;exports.AikaaraChatClient=i.AikaaraChatClient;exports.ApiClient=i.ApiClient;exports.ChannelSubscription=i.ChannelSubscription;exports.ConnectionManager=i.ConnectionManager;exports.ConversationManager=i.ConversationManager;exports.EventEmitter=i.EventEmitter;exports.MessageStore=i.MessageStore;exports.SessionAuthAdapter=i.SessionAuthAdapter;exports.TiledeskTransport=i.TiledeskTransport;exports.clearPersistedConversationId=i.clearPersistedConversationId;exports.createFetchUploadAdapter=i.createFetchUploadAdapter;exports.createPresigned3StepUploadAdapter=i.createPresigned3StepUploadAdapter;exports.createTiledeskHistoryAdapter=i.createTiledeskHistoryAdapter;exports.extractTiledeskFileEnvelope=i.extractTiledeskFileEnvelope;exports.inferTiledeskRole=i.inferTiledeskRole;exports.isTiledeskSelfEcho=i.isTiledeskSelfEcho;exports.mountFromSlug=i.mountFromSlug;exports.mountTenantWidget=i.mount;exports.parseTiledeskTemplate=i.parseTiledeskTemplate;exports.FormBridge=s;
|
package/dist/headless.d.ts
CHANGED
|
@@ -958,6 +958,13 @@ export declare interface SlugMountOptions {
|
|
|
958
958
|
};
|
|
959
959
|
/** Per-mount visual overrides. */
|
|
960
960
|
overrides?: Partial<WidgetConfigDescriptor>;
|
|
961
|
+
/**
|
|
962
|
+
* Inline descriptor used when the slug fetch fails (e.g. 404, network
|
|
963
|
+
* error). Lets host apps ship without requiring the aikaara backend to be
|
|
964
|
+
* seeded — useful for demos / first-run / offline dev. When the fetch
|
|
965
|
+
* succeeds the response wins; this is purely a safety net.
|
|
966
|
+
*/
|
|
967
|
+
fallbackConfig?: WidgetConfigDescriptor;
|
|
961
968
|
}
|
|
962
969
|
|
|
963
970
|
declare type SubscriptionCallback = (data: unknown) => void;
|
package/dist/headless.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as s } from "./MountTenant-
|
|
2
|
-
import { A as p, b as g, k as l, C as h, l as y, m as c, M as u, S as m, T as f, n as T, o as S, p as _, q as v, s as E, t as C, u as F, v as A, w as k, x as I } from "./MountTenant-
|
|
1
|
+
import { E as s } from "./MountTenant-BIFRI4Kz.mjs";
|
|
2
|
+
import { A as p, b as g, k as l, C as h, l as y, m as c, M as u, S as m, T as f, n as T, o as S, p as _, q as v, s as E, t as C, u as F, v as A, w as k, x as I } from "./MountTenant-BIFRI4Kz.mjs";
|
|
3
3
|
class a extends s {
|
|
4
4
|
registration = null;
|
|
5
5
|
pendingEdits = [];
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./MountTenant-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./MountTenant-DrJJvB4L.cjs"),s=require("./headless.cjs");function l(a){e.registerComponents();const t=document.createElement("aikaara-chat-widget"),i={baseUrl:"base-url",userToken:"user-token",apiKey:"api-key",title:"title",subtitle:"subtitle",theme:"theme",primaryColor:"primary-color",position:"position",width:"width",height:"height",placeholder:"placeholder",welcomeMessage:"welcome-message",avatarUrl:"avatar-url"};for(const[n,o]of Object.entries(i)){const r=a[n];r!=null&&t.setAttribute(o,String(r))}return t.configure(a),document.body.appendChild(t),t}function d(){const a=document.querySelector("aikaara-chat-widget");a&&a.remove()}exports.ActionCableClient=e.ActionCableClient;exports.AikaaraChatBubble=e.AikaaraChatBubble;exports.AikaaraChatClient=e.AikaaraChatClient;exports.AikaaraChatHeader=e.AikaaraChatHeader;exports.AikaaraChatInput=e.AikaaraChatInput;exports.AikaaraChatWidget=e.AikaaraChatWidget;exports.AikaaraErrorBanner=e.AikaaraErrorBanner;exports.AikaaraMessageBubble=e.AikaaraMessageBubble;exports.AikaaraMessageList=e.AikaaraMessageList;exports.AikaaraStreamingMessage=e.AikaaraStreamingMessage;exports.AikaaraTypingIndicator=e.AikaaraTypingIndicator;exports.ApiClient=e.ApiClient;exports.ChannelSubscription=e.ChannelSubscription;exports.ConnectionManager=e.ConnectionManager;exports.ConversationManager=e.ConversationManager;exports.EventEmitter=e.EventEmitter;exports.MessageStore=e.MessageStore;exports.SessionAuthAdapter=e.SessionAuthAdapter;exports.TiledeskTransport=e.TiledeskTransport;exports.clearPersistedConversationId=e.clearPersistedConversationId;exports.createFetchUploadAdapter=e.createFetchUploadAdapter;exports.createPresigned3StepUploadAdapter=e.createPresigned3StepUploadAdapter;exports.createTiledeskHistoryAdapter=e.createTiledeskHistoryAdapter;exports.extractTiledeskFileEnvelope=e.extractTiledeskFileEnvelope;exports.inferTiledeskRole=e.inferTiledeskRole;exports.isTiledeskSelfEcho=e.isTiledeskSelfEcho;exports.mountFromSlug=e.mountFromSlug;exports.mountTenantWidget=e.mount;exports.parseTiledeskTemplate=e.parseTiledeskTemplate;exports.registerComponents=e.registerComponents;exports.FormBridge=s.FormBridge;exports.mount=l;exports.unmount=d;
|
package/dist/index.d.ts
CHANGED
|
@@ -838,6 +838,13 @@ export declare interface SlugMountOptions {
|
|
|
838
838
|
};
|
|
839
839
|
/** Per-mount visual overrides. */
|
|
840
840
|
overrides?: Partial<WidgetConfigDescriptor>;
|
|
841
|
+
/**
|
|
842
|
+
* Inline descriptor used when the slug fetch fails (e.g. 404, network
|
|
843
|
+
* error). Lets host apps ship without requiring the aikaara backend to be
|
|
844
|
+
* seeded — useful for demos / first-run / offline dev. When the fetch
|
|
845
|
+
* succeeds the response wins; this is purely a safety net.
|
|
846
|
+
*/
|
|
847
|
+
fallbackConfig?: WidgetConfigDescriptor;
|
|
841
848
|
}
|
|
842
849
|
|
|
843
850
|
declare type SubscriptionCallback = (data: unknown) => void;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as o } from "./MountTenant-
|
|
2
|
-
import { A as u, a as m, b as g, c as h, d as k, e as A, f as C, g as b, h as f, i as T, j as v, k as S, C as w, l as y, m as M, E, M as x, S as B, T as F, n as U, o as I, p as j, q, s as H, t as P, u as W, v as K, w as L, x as O } from "./MountTenant-
|
|
1
|
+
import { r as o } from "./MountTenant-BIFRI4Kz.mjs";
|
|
2
|
+
import { A as u, a as m, b as g, c as h, d as k, e as A, f as C, g as b, h as f, i as T, j as v, k as S, C as w, l as y, m as M, E, M as x, S as B, T as F, n as U, o as I, p as j, q, s as H, t as P, u as W, v as K, w as L, x as O } from "./MountTenant-BIFRI4Kz.mjs";
|
|
3
3
|
import { FormBridge as z } from "./headless.mjs";
|
|
4
4
|
function l(e) {
|
|
5
5
|
o();
|
package/dist/ui.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./MountTenant-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./MountTenant-DrJJvB4L.cjs");exports.AikaaraChat=a.AikaaraChat;exports.AikaaraChatBubble=a.AikaaraChatBubble;exports.AikaaraChatHeader=a.AikaaraChatHeader;exports.AikaaraChatInput=a.AikaaraChatInput;exports.AikaaraChatWidget=a.AikaaraChatWidget;exports.AikaaraErrorBanner=a.AikaaraErrorBanner;exports.AikaaraMessageBubble=a.AikaaraMessageBubble;exports.AikaaraMessageList=a.AikaaraMessageList;exports.AikaaraModalAction=a.AikaaraModalAction;exports.AikaaraOptionList=a.AikaaraOptionList;exports.AikaaraStreamingMessage=a.AikaaraStreamingMessage;exports.AikaaraSubmitAction=a.AikaaraSubmitAction;exports.AikaaraSystemPill=a.AikaaraSystemPill;exports.AikaaraTemplateRenderer=a.AikaaraTemplateRenderer;exports.AikaaraTypingIndicator=a.AikaaraTypingIndicator;exports.registerComponents=a.registerComponents;
|
package/dist/ui.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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-
|
|
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-BIFRI4Kz.mjs";
|
|
2
2
|
export {
|
|
3
3
|
i as AikaaraChat,
|
|
4
4
|
s as AikaaraChatBubble,
|