@prodantix/sdk 0.2.0-beta.370 → 0.2.0-beta.371
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/chat.cjs +3 -2
- package/dist/chat.d.cts +4 -3
- package/dist/chat.d.ts +4 -3
- package/dist/chat.js +3 -2
- package/dist/{config-VQeYKesW.d.cts → config-BD9kg-c4.d.cts} +11 -1
- package/dist/{config-CvAQ_wmX.d.ts → config-BR_iYD-k.d.ts} +11 -1
- package/dist/messenger.d.cts +1 -1
- package/dist/messenger.d.ts +1 -1
- package/dist/messenger.iife.js +3 -2
- package/package.json +1 -1
package/dist/chat.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var D=Object.defineProperty;var K=(n,e,t)=>e in n?D(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t;var c=(n,e,t)=>K(n,typeof e!="symbol"?e+"":e,t);function N(n){if(n)return n;let e=globalThis.fetch;if(typeof e=="function")return e.bind(globalThis)}function P(n){return n.replace(/\/+$/,"")}var G="X-Prodantix-Conversation-Token",T="prodantix.chat.handle";function U(){let n=globalThis.localStorage;if(n)return {get:e=>n.getItem(e),remove:e=>n.removeItem(e),set:(e,t)=>n.setItem(e,t)}}var x=class{constructor(e){this.options=e;c(this,"fetchImpl");c(this,"host");c(this,"storage");c(this,"handle");c(this,"identity",null);this.fetchImpl=N(e.fetchImpl),this.host=P(e.host),this.storage=e.storage??U(),this.handle=this.readHandle();}get hasThread(){return this.handle!==null}get socketAuth(){return this.handle?{conversationId:this.handle.conversationId,conversationToken:this.handle.token,projectKey:this.options.apiKey}:null}identify(e){this.identity=e;}async ensureThread(e){if(this.handle)return true;let t=await this.request("POST","/v1/conversations",{body:{distinctId:this.options.distinctId,subject:e,userHash:this.identity?.userHash,userId:this.identity?.userId}});return !t?.conversationId||!t.token?false:(this.handle={conversationId:t.conversationId,token:t.token},this.storage?.set(T,JSON.stringify(this.handle)),true)}async send(e,t){if(!await this.ensureThread())return null;let r=this.handle;return r?(await this.request("POST",`/v1/conversations/${encodeURIComponent(r.conversationId)}/turns`,{body:{body:e,pageContext:t},token:r.token}))?.turn??null:null}async load(){let e=this.handle;return e?this.request("GET",`/v1/conversations/${encodeURIComponent(e.conversationId)}`,{token:e.token}):null}readHandle(){let e=this.storage?.get(T);if(!e)return null;try{let t=JSON.parse(e);if(typeof t.conversationId=="string"&&typeof t.token=="string")return {conversationId:t.conversationId,token:t.token}}catch{}return this.storage?.remove(T),null}async request(e,t,r={}){let a=this.fetchImpl;if(!a)return this.options.onError?.(new Error("no fetch available for prodantix chat")),null;let s={authorization:`Bearer ${this.options.apiKey}`,"content-type":"application/json"};r.token&&(s[G]=r.token);try{let o=await a(`${this.host}${t}`,{body:r.body===void 0?void 0:JSON.stringify(r.body),headers:s,method:e}),i=await o.text();return o.ok?i?JSON.parse(i):{}:(this.options.onError?.(new Error(`prodantix chat ${t}: ${o.status}`)),null)}catch(o){return this.options.onError?.(o),null}}};var q={Fri:"fri",Mon:"mon",Sat:"sat",Sun:"sun",Thu:"thu",Tue:"tue",Wed:"wed"};function S(n,e){let t=new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:false,minute:"2-digit",timeZone:n.timezone,weekday:"short"}).formatToParts(e),r=q[t.find(i=>i.type==="weekday")?.value??""];if(!r)return false;let a=t.find(i=>i.type==="hour")?.value??"",s=t.find(i=>i.type==="minute")?.value??"",o=`${a}:${s}`;return n.windows.some(i=>i.days.includes(r)&&i.open<=o&&o<i.close)}var p={bubbleFill:"filled",bubbleShape:"tailed",composerShape:"round",dayDividers:true,launcherContent:"glyph",launcherFill:"outlined",launcherShape:"circle",launcherSize:"small",nameAvatar:true,namePlacement:"hidden",skin:"standard",stampContent:"time",stampPlacement:"none"},Y=["quiet","standard"],j=["round","square"],W=["rounded","tailed"],J=["filled","outlined"],V=["circle","pill","squircle"],X=["filled","outlined"],Z=["avatar","glyph","team_faces"],Q=["large","medium","small"],ee=["above","hidden","inline"],te=["beside_name","none","under_turn"],ne=["time","time_and_latency"],m=(n,e,t)=>typeof n=="string"&&e.includes(n)?n:t,I=(n,e)=>typeof n=="boolean"?n:e,re={avatar_circle:["circle","outlined","avatar","large"],circle_filled:["circle","filled","glyph","medium"],circle_outlined:["circle","outlined","glyph","small"],pill_labelled:["pill","filled","glyph","medium"],pill_team:["pill","outlined","team_faces","medium"],squircle_filled:["squircle","filled","glyph","medium"]},ae={above:["above",false],avatar_only:["hidden",true],gutter:["above",true],hidden:["hidden",false],inline:["inline",false]},ie={cluster:[true,"none","time"],latency:[false,"beside_name","time_and_latency"],none:[false,"none","time"],trailing:[false,"under_turn","time"],with_name:[false,"beside_name","time"]},oe={concierge:["standard","round"],console:["standard","square"],quiet:["quiet","square"]},se={hairline:["rounded","outlined"],outlined:["rounded","outlined"],rounded:["rounded","filled"],tailed:["tailed","filled"]};function k(n){let e=typeof n=="object"&&n!==null?n:{},t=typeof e.launcherStyle=="string"?e.launcherStyle:void 0,r=t===void 0?void 0:re[t],a=typeof e.namePlacement=="string"?e.namePlacement:void 0,s=a===void 0?void 0:ae[a],o=typeof e.timestampStyle=="string"?e.timestampStyle:void 0,i=o===void 0?void 0:ie[o],u=typeof e.skin=="string"?e.skin:void 0,d=u===void 0?void 0:oe[u],l=typeof e.bubbleStyle=="string"?e.bubbleStyle:void 0,g=l===void 0?void 0:se[l],f={bubbleFill:m(e.bubbleFill,J,g?.[1]??p.bubbleFill),bubbleShape:m(e.bubbleShape,W,g?.[0]??p.bubbleShape),composerShape:m(e.composerShape,j,d?.[1]??p.composerShape),dayDividers:I(e.dayDividers,i?.[0]??p.dayDividers),launcherContent:m(e.launcherContent,Z,r?.[2]??p.launcherContent),launcherFill:m(e.launcherFill,X,r?.[1]??p.launcherFill),launcherShape:m(e.launcherShape,V,r?.[0]??p.launcherShape),launcherSize:m(e.launcherSize,Q,r?.[3]??p.launcherSize),nameAvatar:I(e.nameAvatar,s?.[1]??p.nameAvatar),namePlacement:m(e.namePlacement,ee,s?.[0]??p.namePlacement),skin:m(e.skin,Y,d?.[0]??p.skin),stampContent:m(e.stampContent,ne,i?.[2]??p.stampContent),stampPlacement:m(e.stampPlacement,te,i?.[1]??p.stampPlacement)};return f.stampPlacement==="beside_name"&&f.namePlacement==="hidden"&&(f.stampPlacement="under_turn"),f}var le="M20 11.6a7.4 7.4 0 0 1-7.4 7.4H8.2L4 21.8l1-4.1A7.4 7.4 0 1 1 20 11.6Z",ce={large:66,medium:56,small:46},de={circle:"width:var(--fab-size);height:var(--fab-size);border-radius:calc(var(--fab-size) / 2);",pill:"width:auto;height:var(--fab-size);border-radius:calc(var(--fab-size) / 2);padding:0 22px;gap:10px;",squircle:"width:var(--fab-size);height:var(--fab-size);border-radius:16px;"},pe={filled:"background:var(--a);color:#fff;",outlined:"background:var(--paper);border:1px solid var(--hairline);color:var(--ink-2);box-shadow:0 1px 2px rgba(0,0,0,.08);"},ue={avatar:"",glyph:".launcher svg{width:calc(var(--fab-size) * 0.375);height:calc(var(--fab-size) * 0.375);}",team_faces:".launcher .faces{display:flex;}.launcher .faces .av{box-shadow:0 0 0 2px var(--paper);}.launcher .faces .av+.av{margin-left:-10px;}"},he=".launcher .live{width:10px;height:10px;position:absolute;right:3px;bottom:3px;border-radius:50%;background:var(--online);box-shadow:0 0 0 2px var(--paper);}.launcher.closed .live{display:none}",me={circle:"",pill:".badge{position:static;box-shadow:none}",squircle:""},ge={filled:"",outlined:".badge{background:var(--a);top:-7px;right:-7px;min-width:19px;height:19px;font-size:11.5px}"},fe={circle:"",pill:".launcher .label{font-size:14px;font-weight:600;white-space:nowrap;}",squircle:""},be={circle:"",pill:"@media (max-width:480px){.launcher{width:var(--fab-size);padding:0}.launcher .label{display:none}}",squircle:""};function H(n,e,t,r){return `.launcher{--fab-size:${ce[r]}px;${de[n]}${pe[e]}}${ue[t]}${he}${me[n]}${ge[e]}${fe[n]}${be[n]}`}function R(n,e,t){let r=document.createDocumentFragment();if(n==="glyph"){let o=document.createElement("span");return o.innerHTML=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${le}"/></svg>`,r.append(...o.childNodes,A()),r}if(n==="avatar")return r.append(F(t[0],e),A()),r;let a=document.createElement("span");a.className="faces";let s=t.length>0?t.slice(0,2):[void 0];for(let o of s)a.append(F(o,e));return r.append(a,A()),r}function F(n,e){let t=document.createElement("span");return t.className="av",t.setAttribute("aria-hidden","true"),t.textContent=n?n.initials:e.agentLabel.slice(0,2).toUpperCase(),n&&(t.style.background=n.tone),t}function A(){let n=document.createElement("span");return n.className="live",n.setAttribute("aria-hidden","true"),n}var ye={agentLabel:"Agent",aiLabel:"AI",closeLabel:"Close chat",emptyBody:"We usually reply within a few minutes.",emptyTitle:"Ask us anything.",inputPlaceholder:"Type a message",launcherLabel:"Open support chat",sendLabel:"Send",timeLabel:n=>{let e=new Date(n);return Number.isNaN(e.getTime())?"":`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`},title:"Support",unreadLabel:n=>`${n} unread`},b={accentColor:"#5b5bff",availability:{timezone:"UTC",windows:[]},awayMessage:"",greeting:"",launcherOffsetX:20,launcherOffsetY:20,launcherPosition:"bottom_right",starterPrompts:[],teamFaces:[],...p},xe={quiet:".composer{position:relative;padding:10px 12px 12px}.composer input{padding-right:42px}.composer button{position:absolute;top:50%;right:16px;width:34px;min-width:34px;height:34px;padding:0;background:transparent;color:var(--ink);border-radius:7px;transform:translateY(-50%)}.composer button .sendglyph{display:block;width:18px;height:18px}.composer button .sendtext{display:none}.panel{border-radius:8px;box-shadow:0 2px 8px rgba(0,0,0,.12)}.header{background:var(--paper);color:var(--ink);height:44px;padding:0 8px 0 16px;border-bottom:1px solid var(--hairline)}.header h2{font-size:11px;letter-spacing:.11em;text-transform:uppercase;color:var(--ink-3)}.close{color:var(--ink-2)}",standard:".panel{border-radius:16px;box-shadow:0 16px 40px rgba(0,0,0,.2)}.header{background:var(--a);color:#fff;flex-direction:column;align-items:flex-start;gap:14px;padding:18px 14px 20px 20px}.header h2{font-size:19px;font-weight:640}"},ve={round:".composer{padding:12px 12px 14px;gap:8px}.composer input{height:46px;border-radius:23px;padding:0 16px}.composer button{width:46px;min-width:46px;height:46px;padding:0;border-radius:23px}.composer button .sendglyph{display:block}.composer button .sendtext{display:none}",square:".composer input{height:44px;border-radius:8px;padding:0 12px}"},Se={rounded:".turn{border-radius:18px;padding:10px 15px}",tailed:".turn.agent,.turn.ai{border-radius:12px 12px 12px 4px}.turn.end_user{border-radius:12px 12px 4px 12px}"},ke={filled:"",outlined:".turn{background:none;border:1px solid var(--hairline)}.turn.end_user{background:none;border-color:var(--a);color:var(--ink)}"},Ce={above:"",hidden:".turn.agent .author,.turn.ai .author:not(.ai){display:none}",inline:".body .author.below{display:block;margin:4px 0 0;font-size:11.5px;font-weight:500;color:var(--ink-2);text-transform:none;letter-spacing:0;opacity:1}"},Ee=".turn.agent,.turn.ai{display:flex;gap:10px;max-width:100%;background:none;padding:0}.turn .body{background:var(--fill);padding:9px 13px;border-radius:inherit}.author{text-transform:none;letter-spacing:0;font-size:12.5px;font-weight:600;opacity:1}",Te='.divider{display:flex;align-items:center;gap:10px;margin:0;font-size:11px;opacity:.6}.divider:before,.divider:after{content:"";flex:1;height:1px;background:var(--hairline)}',Ae={beside_name:".stamp{font-size:11px;opacity:.7;margin-left:6px}",none:"",under_turn:".stamp{display:block;font-size:11px;opacity:.7;margin-top:4px}.turn.end_user .stamp{text-align:right}"},Le=".lat{font-size:11px;opacity:.7;margin-left:6px}";function O(n){let e=k(n),t=n.launcherPosition==="bottom_left"?"left":"right",r=n.accentColor;return `${`
|
|
1
|
+
'use strict';var D=Object.defineProperty;var K=(n,e,t)=>e in n?D(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t;var c=(n,e,t)=>K(n,typeof e!="symbol"?e+"":e,t);function N(n){if(n)return n;let e=globalThis.fetch;if(typeof e=="function")return e.bind(globalThis)}function P(n){return n.replace(/\/+$/,"")}var G="X-Prodantix-Conversation-Token",T="prodantix.chat.handle";function q(){let n=globalThis.localStorage;if(n)return {get:e=>n.getItem(e),remove:e=>n.removeItem(e),set:(e,t)=>n.setItem(e,t)}}var x=class{constructor(e){this.options=e;c(this,"fetchImpl");c(this,"host");c(this,"storage");c(this,"handle");c(this,"identity",null);this.fetchImpl=N(e.fetchImpl),this.host=P(e.host),this.storage=e.storage??q(),this.handle=this.readHandle();}get hasThread(){return this.handle!==null}avatarUrl(e){return e.startsWith("/")?`${this.host}${e}?api_key=${encodeURIComponent(this.options.apiKey)}`:e}get socketAuth(){return this.handle?{conversationId:this.handle.conversationId,conversationToken:this.handle.token,projectKey:this.options.apiKey}:null}identify(e){this.identity=e;}async ensureThread(e){if(this.handle)return true;let t=await this.request("POST","/v1/conversations",{body:{distinctId:this.options.distinctId,subject:e,userHash:this.identity?.userHash,userId:this.identity?.userId}});return !t?.conversationId||!t.token?false:(this.handle={conversationId:t.conversationId,token:t.token},this.storage?.set(T,JSON.stringify(this.handle)),true)}async send(e,t){if(!await this.ensureThread())return null;let r=this.handle;return r?(await this.request("POST",`/v1/conversations/${encodeURIComponent(r.conversationId)}/turns`,{body:{body:e,pageContext:t},token:r.token}))?.turn??null:null}async load(){let e=this.handle;return e?this.request("GET",`/v1/conversations/${encodeURIComponent(e.conversationId)}`,{token:e.token}):null}readHandle(){let e=this.storage?.get(T);if(!e)return null;try{let t=JSON.parse(e);if(typeof t.conversationId=="string"&&typeof t.token=="string")return {conversationId:t.conversationId,token:t.token}}catch{}return this.storage?.remove(T),null}async request(e,t,r={}){let a=this.fetchImpl;if(!a)return this.options.onError?.(new Error("no fetch available for prodantix chat")),null;let o={authorization:`Bearer ${this.options.apiKey}`,"content-type":"application/json"};r.token&&(o[G]=r.token);try{let s=await a(`${this.host}${t}`,{body:r.body===void 0?void 0:JSON.stringify(r.body),headers:o,method:e}),i=await s.text();return s.ok?i?JSON.parse(i):{}:(this.options.onError?.(new Error(`prodantix chat ${t}: ${s.status}`)),null)}catch(s){return this.options.onError?.(s),null}}};var Y={Fri:"fri",Mon:"mon",Sat:"sat",Sun:"sun",Thu:"thu",Tue:"tue",Wed:"wed"};function S(n,e){let t=new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:false,minute:"2-digit",timeZone:n.timezone,weekday:"short"}).formatToParts(e),r=Y[t.find(i=>i.type==="weekday")?.value??""];if(!r)return false;let a=t.find(i=>i.type==="hour")?.value??"",o=t.find(i=>i.type==="minute")?.value??"",s=`${a}:${o}`;return n.windows.some(i=>i.days.includes(r)&&i.open<=s&&s<i.close)}var p={bubbleFill:"filled",bubbleShape:"tailed",composerShape:"round",dayDividers:true,launcherContent:"glyph",launcherFill:"outlined",launcherShape:"circle",launcherSize:"small",nameAvatar:true,namePlacement:"hidden",skin:"standard",stampContent:"time",stampPlacement:"none"},j=["quiet","standard"],W=["round","square"],J=["rounded","tailed"],V=["filled","outlined"],X=["circle","pill","squircle"],Z=["filled","outlined"],Q=["avatar","glyph","team_faces"],ee=["large","medium","small"],te=["above","hidden","inline"],ne=["beside_name","none","under_turn"],re=["time","time_and_latency"],g=(n,e,t)=>typeof n=="string"&&e.includes(n)?n:t,I=(n,e)=>typeof n=="boolean"?n:e,ae={avatar_circle:["circle","outlined","avatar","large"],circle_filled:["circle","filled","glyph","medium"],circle_outlined:["circle","outlined","glyph","small"],pill_labelled:["pill","filled","glyph","medium"],pill_team:["pill","outlined","team_faces","medium"],squircle_filled:["squircle","filled","glyph","medium"]},ie={above:["above",false],avatar_only:["hidden",true],gutter:["above",true],hidden:["hidden",false],inline:["inline",false]},oe={cluster:[true,"none","time"],latency:[false,"beside_name","time_and_latency"],none:[false,"none","time"],trailing:[false,"under_turn","time"],with_name:[false,"beside_name","time"]},se={concierge:["standard","round"],console:["standard","square"],quiet:["quiet","square"]},le={hairline:["rounded","outlined"],outlined:["rounded","outlined"],rounded:["rounded","filled"],tailed:["tailed","filled"]};function k(n){let e=typeof n=="object"&&n!==null?n:{},t=typeof e.launcherStyle=="string"?e.launcherStyle:void 0,r=t===void 0?void 0:ae[t],a=typeof e.namePlacement=="string"?e.namePlacement:void 0,o=a===void 0?void 0:ie[a],s=typeof e.timestampStyle=="string"?e.timestampStyle:void 0,i=s===void 0?void 0:oe[s],u=typeof e.skin=="string"?e.skin:void 0,d=u===void 0?void 0:se[u],l=typeof e.bubbleStyle=="string"?e.bubbleStyle:void 0,h=l===void 0?void 0:le[l],f={bubbleFill:g(e.bubbleFill,V,h?.[1]??p.bubbleFill),bubbleShape:g(e.bubbleShape,J,h?.[0]??p.bubbleShape),composerShape:g(e.composerShape,W,d?.[1]??p.composerShape),dayDividers:I(e.dayDividers,i?.[0]??p.dayDividers),launcherContent:g(e.launcherContent,Q,r?.[2]??p.launcherContent),launcherFill:g(e.launcherFill,Z,r?.[1]??p.launcherFill),launcherShape:g(e.launcherShape,X,r?.[0]??p.launcherShape),launcherSize:g(e.launcherSize,ee,r?.[3]??p.launcherSize),nameAvatar:I(e.nameAvatar,o?.[1]??p.nameAvatar),namePlacement:g(e.namePlacement,te,o?.[0]??p.namePlacement),skin:g(e.skin,j,d?.[0]??p.skin),stampContent:g(e.stampContent,re,i?.[2]??p.stampContent),stampPlacement:g(e.stampPlacement,ne,i?.[1]??p.stampPlacement)};return f.stampPlacement==="beside_name"&&f.namePlacement==="hidden"&&(f.stampPlacement="under_turn"),f}function H(n){let e=n.split(/\s+/).filter(r=>r.length>0);return (e.length>1?`${e[0]?.slice(0,1)}${e[1]?.slice(0,1)}`:e[0]?.slice(0,2)??"").toUpperCase()}var ce="M20 11.6a7.4 7.4 0 0 1-7.4 7.4H8.2L4 21.8l1-4.1A7.4 7.4 0 1 1 20 11.6Z",de={large:66,medium:56,small:46},pe={circle:"width:var(--fab-size);height:var(--fab-size);border-radius:calc(var(--fab-size) / 2);",pill:"width:auto;height:var(--fab-size);border-radius:calc(var(--fab-size) / 2);padding:0 22px;gap:10px;",squircle:"width:var(--fab-size);height:var(--fab-size);border-radius:16px;"},ue={filled:"background:var(--a);color:#fff;",outlined:"background:var(--paper);border:1px solid var(--hairline);color:var(--ink-2);box-shadow:0 1px 2px rgba(0,0,0,.08);"},he={avatar:"",glyph:".launcher svg{width:calc(var(--fab-size) * 0.375);height:calc(var(--fab-size) * 0.375);}",team_faces:".launcher .faces{display:flex;}.launcher .faces .av{box-shadow:0 0 0 2px var(--paper);}.launcher .faces .av+.av{margin-left:-10px;}"},me=".launcher .live{width:10px;height:10px;position:absolute;right:3px;bottom:3px;border-radius:50%;background:var(--online);box-shadow:0 0 0 2px var(--paper);}.launcher.closed .live{display:none}",ge={circle:"",pill:".badge{position:static;box-shadow:none}",squircle:""},fe={filled:"",outlined:".badge{background:var(--a);top:-7px;right:-7px;min-width:19px;height:19px;font-size:11.5px}"},be={circle:"",pill:".launcher .label{font-size:14px;font-weight:600;white-space:nowrap;}",squircle:""},ye={circle:"",pill:"@media (max-width:480px){.launcher{width:var(--fab-size);padding:0}.launcher .label{display:none}}",squircle:""};function R(n,e,t,r){return `.launcher{--fab-size:${de[r]}px;${pe[n]}${ue[e]}}${he[t]}${me}${ge[n]}${fe[e]}${be[n]}${ye[n]}`}function O(n,e,t,r=a=>a){let a=document.createDocumentFragment();if(n==="glyph"){let i=document.createElement("span");return i.innerHTML=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${ce}"/></svg>`,a.append(...i.childNodes,A()),a}if(n==="avatar")return a.append(F(t[0],e,r),A()),a;let o=document.createElement("span");o.className="faces";let s=t.length>0?t.slice(0,2):[void 0];for(let i of s)o.append(F(i,e,r));return a.append(o,A()),a}function F(n,e,t){let r=document.createElement("span");if(r.className="av",r.setAttribute("aria-hidden","true"),n&&(r.style.background=n.tone),n?.avatarUrl){let a=document.createElement("img");return a.alt="",a.src=t(n.avatarUrl),r.append(a),r}return r.textContent=n?n.initials:e.agentLabel.slice(0,2).toUpperCase(),r}function A(){let n=document.createElement("span");return n.className="live",n.setAttribute("aria-hidden","true"),n}var xe={agentLabel:"Agent",aiLabel:"AI",closeLabel:"Close chat",emptyBody:"We usually reply within a few minutes.",emptyTitle:"Ask us anything.",inputPlaceholder:"Type a message",launcherLabel:"Open support chat",sendLabel:"Send",timeLabel:n=>{let e=new Date(n);return Number.isNaN(e.getTime())?"":`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`},title:"Support",unreadLabel:n=>`${n} unread`},b={accentColor:"#5b5bff",availability:{timezone:"UTC",windows:[]},awayMessage:"",greeting:"",launcherOffsetX:20,launcherOffsetY:20,launcherPosition:"bottom_right",starterPrompts:[],team:[],teamFaces:[],...p};function ve(n){return n.team.length>0?n.team:n.teamFaces}var Se={quiet:".composer{position:relative;padding:10px 12px 12px}.composer input{padding-right:42px}.composer button{position:absolute;top:50%;right:16px;width:34px;min-width:34px;height:34px;padding:0;background:transparent;color:var(--ink);border-radius:7px;transform:translateY(-50%)}.composer button .sendglyph{display:block;width:18px;height:18px}.composer button .sendtext{display:none}.panel{border-radius:8px;box-shadow:0 2px 8px rgba(0,0,0,.12)}.header{background:var(--paper);color:var(--ink);height:44px;padding:0 8px 0 16px;border-bottom:1px solid var(--hairline)}.header h2{font-size:11px;letter-spacing:.11em;text-transform:uppercase;color:var(--ink-3)}.close{color:var(--ink-2)}",standard:".panel{border-radius:16px;box-shadow:0 16px 40px rgba(0,0,0,.2)}.header{background:var(--a);color:#fff;flex-direction:column;align-items:flex-start;gap:14px;padding:18px 14px 20px 20px}.header h2{font-size:19px;font-weight:640}"},ke={round:".composer{padding:12px 12px 14px;gap:8px}.composer input{height:46px;border-radius:23px;padding:0 16px}.composer button{width:46px;min-width:46px;height:46px;padding:0;border-radius:23px}.composer button .sendglyph{display:block}.composer button .sendtext{display:none}",square:".composer input{height:44px;border-radius:8px;padding:0 12px}"},Ce={rounded:".turn{border-radius:18px;padding:10px 15px}",tailed:".turn.agent,.turn.ai{border-radius:12px 12px 12px 4px}.turn.end_user{border-radius:12px 12px 4px 12px}"},Ee={filled:"",outlined:".turn{background:none;border:1px solid var(--hairline)}.turn.end_user{background:none;border-color:var(--a);color:var(--ink)}"},Te={above:"",hidden:".turn.agent .author,.turn.ai .author:not(.ai){display:none}",inline:".body .author.below{display:block;margin:4px 0 0;font-size:11.5px;font-weight:500;color:var(--ink-2);text-transform:none;letter-spacing:0;opacity:1}"},Ae=".turn.agent,.turn.ai{display:flex;gap:10px;max-width:100%;background:none;padding:0}.turn .body{background:var(--fill);padding:9px 13px;border-radius:inherit}.author{text-transform:none;letter-spacing:0;font-size:12.5px;font-weight:600;opacity:1}",Le='.divider{display:flex;align-items:center;gap:10px;margin:0;font-size:11px;opacity:.6}.divider:before,.divider:after{content:"";flex:1;height:1px;background:var(--hairline)}',we={beside_name:".stamp{font-size:11px;opacity:.7;margin-left:6px}",none:"",under_turn:".stamp{display:block;font-size:11px;opacity:.7;margin-top:4px}.turn.end_user .stamp{text-align:right}"},_e=".lat{font-size:11px;opacity:.7;margin-left:6px}";function M(n){let e=k(n),t=n.launcherPosition==="bottom_left"?"left":"right",r=n.accentColor;return `${`
|
|
2
2
|
:host {
|
|
3
3
|
all: initial; --a: ${r};
|
|
4
4
|
--paper: #fff; --ink: #0f172a; --ink-3: var(--ink-3);
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
.prompt:focus-visible { outline: 2px solid ${r}; outline-offset: 2px; }
|
|
55
55
|
.av { width: 30px; height: 30px; border-radius: 50%; flex: none; display: inline-flex; align-items: center; justify-content: center; font-size: 11.5px; font-weight: 650; color: #fff; background: #7c3f3f; }
|
|
56
56
|
.av.bot { border-radius: 9px; background: var(--fill); color: var(--ink); }
|
|
57
|
+
.av img { width: 100%; height: 100%; display: block; object-fit: cover; border-radius: inherit; }
|
|
57
58
|
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--hairline); }
|
|
58
59
|
.composer input { flex: 1; min-width: 0; height: 44px; padding: 0 12px; border: 0; border-radius: 8px; font-size: 14px; background: var(--fill); color: var(--ink); }
|
|
59
60
|
.composer input:focus-visible { outline: 2px solid ${r}; }
|
|
@@ -64,5 +65,5 @@
|
|
|
64
65
|
.panel { animation: rise 180ms ease-out; }
|
|
65
66
|
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
|
|
66
67
|
}
|
|
67
|
-
`}${ve[e.composerShape]}${xe[e.skin]}${H(e.launcherShape,e.launcherFill,e.launcherContent,e.launcherSize)}${Se[e.bubbleShape]}${ke[e.bubbleFill]}${Ce[e.namePlacement]}${e.nameAvatar?Ee:""}${e.dayDividers?Te:""}${Ae[e.stampPlacement]}${e.stampContent==="time_and_latency"?Le:""}`}var we=["end_user","agent","ai"];function _e(){let n=globalThis.location;if(n)return {host:n.host,path:n.pathname,title:document.title}}var v=class{constructor(e,t,r={},a={}){this.host=e;this.client=t;c(this,"root");c(this,"strings");c(this,"settings");c(this,"appearance");c(this,"launcher");c(this,"badge");c(this,"panel",null);c(this,"lastFocused",null);c(this,"unread",0);this.strings={...ye,...r},this.appearance={...b,...a},this.settings=k({...b,...a}),this.root=e.attachShadow({mode:"closed"});let s=document.createElement("style");if(s.textContent=O({...b,...a}),this.root.append(s),this.launcher=document.createElement("button"),this.launcher.className="launcher",this.launcher.type="button",this.launcher.setAttribute("aria-haspopup","dialog"),this.launcher.setAttribute("aria-label",this.strings.launcherLabel),this.launcher.append(R(this.settings.launcherContent,this.strings,this.appearance.teamFaces)),this.settings.launcherShape==="pill"){let o=document.createElement("span");o.className="label",o.textContent=this.settings.launcherContent==="team_faces"?this.strings.agentLabel:this.strings.launcherLabel,this.launcher.append(o);}this.launcher.addEventListener("click",()=>this.toggle()),this.badge=document.createElement("span"),this.badge.className="badge",this.badge.hidden=true,this.launcher.append(this.badge),this.root.append(this.launcher);}toggle(){this.panel?this.close():this.open();}setOpenNow(e){this.launcher.classList.toggle("closed",!e);}async open(){if(this.panel)return;this.lastFocused=this.host.ownerDocument.activeElement,this.unread=0,this.renderBadge();let e=document.createElement("section");e.className="panel",e.setAttribute("role","dialog"),e.setAttribute("aria-modal","true"),e.setAttribute("aria-label",this.strings.title);let t=document.createElement("div");t.className="header";let r=document.createElement("h2");r.textContent=this.strings.title;let a=document.createElement("button");a.className="close",a.type="button",a.setAttribute("aria-label",this.strings.closeLabel),a.textContent="\xD7",a.addEventListener("click",()=>this.close()),t.append(r,a);let s=document.createElement("div");s.className="log",s.setAttribute("role","log"),s.setAttribute("aria-live","polite"),s.setAttribute("aria-label",this.strings.title);let o=document.createElement("form");o.className="composer";let i=document.createElement("input");i.type="text",i.setAttribute("aria-label",this.strings.inputPlaceholder),i.placeholder=this.strings.inputPlaceholder;let u=document.createElement("button");u.type="submit",u.setAttribute("aria-label",this.strings.sendLabel),u.innerHTML='<svg class="sendglyph" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4.5 12 20 4.5 15 20l-3.6-5.4L4.5 12Z"/></svg>';let d=document.createElement("span");d.className="sendtext",d.textContent=this.strings.sendLabel,u.append(d),o.append(i,u),o.addEventListener("submit",g=>{g.preventDefault(),this.submit(i,s);}),e.append(t,s,o),e.addEventListener("keydown",g=>this.onKeydown(g,e,a)),this.root.append(e),this.panel=e,i.focus();let l=await this.client.load();l&&l.turns.length>0?this.renderThread(s,l):this.renderFirstRun(s,i),!S(this.appearance.availability,new Date)&&this.appearance.awayMessage.trim()&&this.renderAway(s);}renderFirstRun(e,t){let r=document.createElement("div");r.className="empty";let a=document.createElement("h3");a.textContent=this.appearance.greeting.trim()||this.strings.emptyTitle;let s=document.createElement("p");s.textContent=this.strings.emptyBody,r.append(a,s);for(let o of this.appearance.starterPrompts){let i=document.createElement("button");i.className="prompt",i.type="button",i.textContent=o,i.addEventListener("click",()=>{t.value=o,this.submit(t,e);}),r.append(i);}e.replaceChildren(r);}renderAway(e){let t=document.createElement("div");t.className="away",t.textContent=this.appearance.awayMessage,e.prepend(t);}close(){this.panel&&(this.panel.remove(),this.panel=null,this.lastFocused instanceof HTMLElement?this.lastFocused.focus():this.launcher.focus());}onIncomingTurn(e){if(this.panel){let t=this.panel.querySelector(".log");t instanceof HTMLElement&&this.appendTurn(t,e);return}e.authorKind!=="end_user"&&(this.unread+=1,this.renderBadge());}async submit(e,t){let r=e.value.trim();if(!r)return;e.value="",t.querySelector(".empty")?.remove();let a=await this.client.send(r,_e());a&&this.appendTurn(t,a);}renderThread(e,t){e.replaceChildren();for(let r of t.turns)this.appendTurn(e,r);}appendTurn(e,t){e.querySelector(".empty")?.remove();let r=we.includes(t.authorKind)?t.authorKind:"agent",a=this.settings,s=document.createElement("div");if(s.className=`turn ${r}`,r!=="end_user"&&a.nameAvatar){let l=document.createElement("span");l.className=r==="ai"?"av bot":"av",l.textContent=r==="ai"?this.strings.aiLabel:this.strings.agentLabel.slice(0,2).toUpperCase(),l.setAttribute("aria-hidden","true"),s.append(l);}let i=document.createElement("div");i.className="body";let u=r!=="end_user"&&a.namePlacement!=="hidden",d=document.createElement("div");if(d.textContent=t.body,u||r==="ai"&&a.namePlacement==="hidden"){let l=document.createElement("div");l.className=r==="ai"?"author ai":"author",l.textContent=r==="ai"?this.strings.aiLabel:this.strings.agentLabel,a.stampPlacement==="beside_name"&&l.append(this.stamp(t)),a.namePlacement==="inline"?(l.classList.add("below"),i.append(d,l)):i.append(l,d);}else i.append(d);a.stampPlacement==="under_turn"&&i.append(this.stamp(t)),s.append(i),e.append(s),e.scrollTop=e.scrollHeight;}stamp(e){let t=document.createElement("span");return t.className="stamp",t.textContent=this.strings.timeLabel(e.createdAt),t}onKeydown(e,t,r){if(e.key==="Escape"){e.preventDefault(),this.close();return}if(e.key!=="Tab")return;let a=t.querySelectorAll('button, input, [tabindex]:not([tabindex="-1"])');if(a.length===0)return;let s=a[0],o=a[a.length-1],i=this.root.activeElement;e.shiftKey&&i===s?(e.preventDefault(),o.focus()):!e.shiftKey&&i===o?(e.preventDefault(),s.focus()):i===null&&(e.preventDefault(),r.focus());}renderBadge(){this.unread>0?(this.badge.hidden=false,this.badge.textContent=String(this.unread),this.launcher.setAttribute("aria-label",`${this.strings.launcherLabel}, ${this.strings.unreadLabel(this.unread)}`)):(this.badge.hidden=true,this.badge.textContent="",this.launcher.setAttribute("aria-label",this.strings.launcherLabel));}};function M(n){return `40${JSON.stringify(n)}`}function $(){return "3"}function z(n){let e=n.charAt(0),t=n.slice(1);if(e==="2")return {kind:"ping"};if(e==="1")return {kind:"disconnect"};if(e==="0"){let o=L(t);return {kind:"open",pingInterval:typeof o?.pingInterval=="number"?o.pingInterval:25e3,pingTimeout:typeof o?.pingTimeout=="number"?o.pingTimeout:2e4}}if(e!=="4")return {kind:"other"};let r=t.charAt(0),a=t.slice(1);if(r==="0")return {kind:"connected"};if(r==="1")return {kind:"disconnect"};if(r==="4"){let o=L(a);return {kind:"connectError",message:typeof o?.message=="string"?o.message:"refused"}}if(r!=="2")return {kind:"other"};let s=L(a);return !Array.isArray(s)||typeof s[0]!="string"?{kind:"other"}:{kind:"event",name:s[0],payload:s[1]}}function L(n){try{return JSON.parse(n)}catch{return null}}var Ne="/socket.io/?EIO=4&transport=websocket",C=class{constructor(e){this.options=e;c(this,"socket",null);c(this,"heartbeat",null);c(this,"ready",false);c(this,"closed",false);c(this,"heartbeatWindow",45e3);c(this,"factory");c(this,"setTimer");c(this,"clearTimer");this.factory=e.socketFactory??Pe,this.setTimer=e.setTimer??((t,r)=>setTimeout(t,r)),this.clearTimer=e.clearTimer??(t=>clearTimeout(t));}open(){if(this.socket||this.closed)return;let e=`${this.options.host.replace(/^http/,"ws").replace(/\/+$/,"")}${Ne}`,t;try{t=this.factory(e);}catch{this.options.onClosed(false);return}this.socket=t,t.onmessage=r=>this.receive(String(r.data)),t.onerror=()=>t.close(),t.onclose=()=>this.fell();}close(){this.closed=true,this.stopHeartbeat();let e=this.socket;this.socket=null,e?.close();}receive(e){let t=z(e);if(t.kind==="open"){this.armHeartbeat(t.pingInterval+t.pingTimeout),this.socket?.send(M(this.options.auth));return}if(t.kind==="ping"){this.armHeartbeat(),this.socket?.send($());return}if(t.kind==="connectError"||t.kind==="disconnect"){this.stopHeartbeat(),this.socket?.close();return}if(t.kind==="event"){if(t.name==="ready"){this.ready=true,this.options.onReady();return}if(t.name==="conversation.turn"){let r=t.payload?.turn;r&&this.options.onTurn(r);}}}fell(){this.stopHeartbeat();let e=this.ready;this.socket=null,this.ready=false,this.closed||this.options.onClosed(e);}armHeartbeat(e){e!==void 0&&(this.heartbeatWindow=e),this.stopHeartbeat(),this.heartbeat=this.setTimer(()=>this.socket?.close(),this.heartbeatWindow);}stopHeartbeat(){this.heartbeat!==null&&this.clearTimer(this.heartbeat),this.heartbeat=null;}};function Pe(n){let e=globalThis.WebSocket;if(!e)throw new Error("no WebSocket");return new e(n)}var Ie=6e4;function et(n){let e=globalThis.document;if(!e)throw new Error("prodantix chat requires a document; mount it in the browser");let t=n.mountPoint??e.createElement("div");n.mountPoint||e.body.append(t);let r=new x(n),a=new v(t,r,n.strings,n.appearance),s=n.appearance?.availability??b.availability,o,i=()=>{a.setOpenNow(S(s,new Date)),o=setTimeout(i,Ie);};i();let u=new Set,d,l=null,g=n.pollIntervalMs??15e3,f=h=>{u.has(h.id)||h.authorKind==="end_user"||(u.add(h.id),a.onIncomingTurn(h));},B=async()=>{if(!r.hasThread)return;let h=await r.load();if(h){for(let y of h.turns)f(y);u=new Set(h.turns.map(y=>y.id));}},w=()=>{d||g<=0||(d=setInterval(()=>void B(),g));},_=()=>{d&&clearInterval(d),d=void 0;},E=()=>{if(l||!n.socketHost)return;let h=r.socketAuth;h&&(l=new C({auth:h,host:n.socketHost,onClosed:y=>{l=null,w(),y&&E();},onReady:_,onTurn:f,socketFactory:n.socketFactory}),l.open());};return w(),E(),{close:()=>a.close(),destroy:()=>{_(),clearTimeout(o),l?.close(),l=null,a.close(),t.remove();},identify:h=>r.identify(h),open:()=>{a.open().then(E);}}}exports.ChatClient=x;exports.ChatPanel=v;exports.DEFAULT_APPEARANCE=b;exports.DEFAULT_APPEARANCE_SETTINGS=p;exports.mountChat=et;exports.panelStyles=O;exports.resolveAppearance=k;//# sourceMappingURL=chat.cjs.map
|
|
68
|
+
`}${ke[e.composerShape]}${Se[e.skin]}${R(e.launcherShape,e.launcherFill,e.launcherContent,e.launcherSize)}${Ce[e.bubbleShape]}${Ee[e.bubbleFill]}${Te[e.namePlacement]}${e.nameAvatar?Ae:""}${e.dayDividers?Le:""}${we[e.stampPlacement]}${e.stampContent==="time_and_latency"?_e:""}`}var Ne=["end_user","agent","ai"];function Pe(){let n=globalThis.location;if(n)return {host:n.host,path:n.pathname,title:document.title}}var v=class{constructor(e,t,r={},a={}){this.host=e;this.client=t;c(this,"root");c(this,"strings");c(this,"settings");c(this,"appearance");c(this,"launcher");c(this,"badge");c(this,"panel",null);c(this,"lastFocused",null);c(this,"unread",0);this.strings={...xe,...r},this.appearance={...b,...a},this.settings=k({...b,...a}),this.root=e.attachShadow({mode:"closed"});let o=document.createElement("style");if(o.textContent=M({...b,...a}),this.root.append(o),this.launcher=document.createElement("button"),this.launcher.className="launcher",this.launcher.type="button",this.launcher.setAttribute("aria-haspopup","dialog"),this.launcher.setAttribute("aria-label",this.strings.launcherLabel),this.launcher.append(O(this.settings.launcherContent,this.strings,ve(this.appearance),s=>this.client.avatarUrl(s))),this.settings.launcherShape==="pill"){let s=document.createElement("span");s.className="label",s.textContent=this.settings.launcherContent==="team_faces"?this.strings.agentLabel:this.strings.launcherLabel,this.launcher.append(s);}this.launcher.addEventListener("click",()=>this.toggle()),this.badge=document.createElement("span"),this.badge.className="badge",this.badge.hidden=true,this.launcher.append(this.badge),this.root.append(this.launcher);}toggle(){this.panel?this.close():this.open();}setOpenNow(e){this.launcher.classList.toggle("closed",!e);}async open(){if(this.panel)return;this.lastFocused=this.host.ownerDocument.activeElement,this.unread=0,this.renderBadge();let e=document.createElement("section");e.className="panel",e.setAttribute("role","dialog"),e.setAttribute("aria-modal","true"),e.setAttribute("aria-label",this.strings.title);let t=document.createElement("div");t.className="header";let r=document.createElement("h2");r.textContent=this.strings.title;let a=document.createElement("button");a.className="close",a.type="button",a.setAttribute("aria-label",this.strings.closeLabel),a.textContent="\xD7",a.addEventListener("click",()=>this.close()),t.append(r,a);let o=document.createElement("div");o.className="log",o.setAttribute("role","log"),o.setAttribute("aria-live","polite"),o.setAttribute("aria-label",this.strings.title);let s=document.createElement("form");s.className="composer";let i=document.createElement("input");i.type="text",i.setAttribute("aria-label",this.strings.inputPlaceholder),i.placeholder=this.strings.inputPlaceholder;let u=document.createElement("button");u.type="submit",u.setAttribute("aria-label",this.strings.sendLabel),u.innerHTML='<svg class="sendglyph" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4.5 12 20 4.5 15 20l-3.6-5.4L4.5 12Z"/></svg>';let d=document.createElement("span");d.className="sendtext",d.textContent=this.strings.sendLabel,u.append(d),s.append(i,u),s.addEventListener("submit",h=>{h.preventDefault(),this.submit(i,o);}),e.append(t,o,s),e.addEventListener("keydown",h=>this.onKeydown(h,e,a)),this.root.append(e),this.panel=e,i.focus();let l=await this.client.load();l&&l.turns.length>0?this.renderThread(o,l):this.renderFirstRun(o,i),!S(this.appearance.availability,new Date)&&this.appearance.awayMessage.trim()&&this.renderAway(o);}renderFirstRun(e,t){let r=document.createElement("div");r.className="empty";let a=document.createElement("h3");a.textContent=this.appearance.greeting.trim()||this.strings.emptyTitle;let o=document.createElement("p");o.textContent=this.strings.emptyBody,r.append(a,o);for(let s of this.appearance.starterPrompts){let i=document.createElement("button");i.className="prompt",i.type="button",i.textContent=s,i.addEventListener("click",()=>{t.value=s,this.submit(t,e);}),r.append(i);}e.replaceChildren(r);}renderAway(e){let t=document.createElement("div");t.className="away",t.textContent=this.appearance.awayMessage,e.prepend(t);}close(){this.panel&&(this.panel.remove(),this.panel=null,this.lastFocused instanceof HTMLElement?this.lastFocused.focus():this.launcher.focus());}onIncomingTurn(e){if(this.panel){let t=this.panel.querySelector(".log");t instanceof HTMLElement&&this.appendTurn(t,e);return}e.authorKind!=="end_user"&&(this.unread+=1,this.renderBadge());}async submit(e,t){let r=e.value.trim();if(!r)return;e.value="",t.querySelector(".empty")?.remove();let a=await this.client.send(r,Pe());a&&this.appendTurn(t,a);}renderThread(e,t){e.replaceChildren();for(let r of t.turns)this.appendTurn(e,r);}appendTurn(e,t){e.querySelector(".empty")?.remove();let r=Ne.includes(t.authorKind)?t.authorKind:"agent",a=this.settings,o=document.createElement("div");if(o.className=`turn ${r}`,r!=="end_user"&&a.nameAvatar){let l=document.createElement("span");if(l.className=r==="ai"?"av bot":"av",l.setAttribute("aria-hidden","true"),r==="agent"&&t.authorAvatarUrl){let h=document.createElement("img");h.alt="",h.src=this.client.avatarUrl(t.authorAvatarUrl),l.append(h);}else l.textContent=r==="ai"?this.strings.aiLabel:H(this.agentName(t));o.append(l);}let i=document.createElement("div");i.className="body";let u=r!=="end_user"&&a.namePlacement!=="hidden",d=document.createElement("div");if(d.textContent=t.body,u||r==="ai"&&a.namePlacement==="hidden"){let l=document.createElement("div");l.className=r==="ai"?"author ai":"author",l.textContent=r==="ai"?this.strings.aiLabel:this.agentName(t),a.stampPlacement==="beside_name"&&l.append(this.stamp(t)),a.namePlacement==="inline"?(l.classList.add("below"),i.append(d,l)):i.append(l,d);}else i.append(d);a.stampPlacement==="under_turn"&&i.append(this.stamp(t)),o.append(i),e.append(o),e.scrollTop=e.scrollHeight;}agentName(e){return e.authorName||this.strings.agentLabel}stamp(e){let t=document.createElement("span");return t.className="stamp",t.textContent=this.strings.timeLabel(e.createdAt),t}onKeydown(e,t,r){if(e.key==="Escape"){e.preventDefault(),this.close();return}if(e.key!=="Tab")return;let a=t.querySelectorAll('button, input, [tabindex]:not([tabindex="-1"])');if(a.length===0)return;let o=a[0],s=a[a.length-1],i=this.root.activeElement;e.shiftKey&&i===o?(e.preventDefault(),s.focus()):!e.shiftKey&&i===s?(e.preventDefault(),o.focus()):i===null&&(e.preventDefault(),r.focus());}renderBadge(){this.unread>0?(this.badge.hidden=false,this.badge.textContent=String(this.unread),this.launcher.setAttribute("aria-label",`${this.strings.launcherLabel}, ${this.strings.unreadLabel(this.unread)}`)):(this.badge.hidden=true,this.badge.textContent="",this.launcher.setAttribute("aria-label",this.strings.launcherLabel));}};function $(n){return `40${JSON.stringify(n)}`}function z(){return "3"}function U(n){let e=n.charAt(0),t=n.slice(1);if(e==="2")return {kind:"ping"};if(e==="1")return {kind:"disconnect"};if(e==="0"){let s=L(t);return {kind:"open",pingInterval:typeof s?.pingInterval=="number"?s.pingInterval:25e3,pingTimeout:typeof s?.pingTimeout=="number"?s.pingTimeout:2e4}}if(e!=="4")return {kind:"other"};let r=t.charAt(0),a=t.slice(1);if(r==="0")return {kind:"connected"};if(r==="1")return {kind:"disconnect"};if(r==="4"){let s=L(a);return {kind:"connectError",message:typeof s?.message=="string"?s.message:"refused"}}if(r!=="2")return {kind:"other"};let o=L(a);return !Array.isArray(o)||typeof o[0]!="string"?{kind:"other"}:{kind:"event",name:o[0],payload:o[1]}}function L(n){try{return JSON.parse(n)}catch{return null}}var Ie="/socket.io/?EIO=4&transport=websocket",C=class{constructor(e){this.options=e;c(this,"socket",null);c(this,"heartbeat",null);c(this,"ready",false);c(this,"closed",false);c(this,"heartbeatWindow",45e3);c(this,"factory");c(this,"setTimer");c(this,"clearTimer");this.factory=e.socketFactory??Fe,this.setTimer=e.setTimer??((t,r)=>setTimeout(t,r)),this.clearTimer=e.clearTimer??(t=>clearTimeout(t));}open(){if(this.socket||this.closed)return;let e=`${this.options.host.replace(/^http/,"ws").replace(/\/+$/,"")}${Ie}`,t;try{t=this.factory(e);}catch{this.options.onClosed(false);return}this.socket=t,t.onmessage=r=>this.receive(String(r.data)),t.onerror=()=>t.close(),t.onclose=()=>this.fell();}close(){this.closed=true,this.stopHeartbeat();let e=this.socket;this.socket=null,e?.close();}receive(e){let t=U(e);if(t.kind==="open"){this.armHeartbeat(t.pingInterval+t.pingTimeout),this.socket?.send($(this.options.auth));return}if(t.kind==="ping"){this.armHeartbeat(),this.socket?.send(z());return}if(t.kind==="connectError"||t.kind==="disconnect"){this.stopHeartbeat(),this.socket?.close();return}if(t.kind==="event"){if(t.name==="ready"){this.ready=true,this.options.onReady();return}if(t.name==="conversation.turn"){let r=t.payload?.turn;r&&this.options.onTurn(r);}}}fell(){this.stopHeartbeat();let e=this.ready;this.socket=null,this.ready=false,this.closed||this.options.onClosed(e);}armHeartbeat(e){e!==void 0&&(this.heartbeatWindow=e),this.stopHeartbeat(),this.heartbeat=this.setTimer(()=>this.socket?.close(),this.heartbeatWindow);}stopHeartbeat(){this.heartbeat!==null&&this.clearTimer(this.heartbeat),this.heartbeat=null;}};function Fe(n){let e=globalThis.WebSocket;if(!e)throw new Error("no WebSocket");return new e(n)}var He=6e4;function nt(n){let e=globalThis.document;if(!e)throw new Error("prodantix chat requires a document; mount it in the browser");let t=n.mountPoint??e.createElement("div");n.mountPoint||e.body.append(t);let r=new x(n),a=new v(t,r,n.strings,n.appearance),o=n.appearance?.availability??b.availability,s,i=()=>{a.setOpenNow(S(o,new Date)),s=setTimeout(i,He);};i();let u=new Set,d,l=null,h=n.pollIntervalMs??15e3,f=m=>{u.has(m.id)||m.authorKind==="end_user"||(u.add(m.id),a.onIncomingTurn(m));},B=async()=>{if(!r.hasThread)return;let m=await r.load();if(m){for(let y of m.turns)f(y);u=new Set(m.turns.map(y=>y.id));}},w=()=>{d||h<=0||(d=setInterval(()=>void B(),h));},_=()=>{d&&clearInterval(d),d=void 0;},E=()=>{if(l||!n.socketHost)return;let m=r.socketAuth;m&&(l=new C({auth:m,host:n.socketHost,onClosed:y=>{l=null,w(),y&&E();},onReady:_,onTurn:f,socketFactory:n.socketFactory}),l.open());};return w(),E(),{close:()=>a.close(),destroy:()=>{_(),clearTimeout(s),l?.close(),l=null,a.close(),t.remove();},identify:m=>r.identify(m),open:()=>{a.open().then(E);}}}exports.ChatClient=x;exports.ChatPanel=v;exports.DEFAULT_APPEARANCE=b;exports.DEFAULT_APPEARANCE_SETTINGS=p;exports.mountChat=nt;exports.panelStyles=M;exports.resolveAppearance=k;//# sourceMappingURL=chat.cjs.map
|
|
68
69
|
//# sourceMappingURL=chat.cjs.map
|
package/dist/chat.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ChatClient, M as MessengerConfig, A as AppearanceSettings, a as ChatTurn, b as ChatIdentity, c as ChatClientOptions } from './config-
|
|
2
|
-
export { B as BubbleFill, d as BubbleShape, e as ChatStorage, f as ChatThread, g as ComposerShape, D as DEFAULT_APPEARANCE_SETTINGS, L as LauncherContent, h as LauncherFill, i as LauncherShape, j as LauncherSize, k as MessengerSkin, N as NamePlacement, S as StampContent, l as StampPlacement, r as resolveAppearance } from './config-
|
|
1
|
+
import { C as ChatClient, M as MessengerConfig, A as AppearanceSettings, a as ChatTurn, b as ChatIdentity, c as ChatClientOptions } from './config-BD9kg-c4.cjs';
|
|
2
|
+
export { B as BubbleFill, d as BubbleShape, e as ChatStorage, f as ChatThread, g as ComposerShape, D as DEFAULT_APPEARANCE_SETTINGS, L as LauncherContent, h as LauncherFill, i as LauncherShape, j as LauncherSize, k as MessengerSkin, N as NamePlacement, S as StampContent, l as StampPlacement, r as resolveAppearance } from './config-BD9kg-c4.cjs';
|
|
3
3
|
import { S as SocketFactory } from './types-DjMXp6Wg.cjs';
|
|
4
4
|
import './http-BCh716Vs.cjs';
|
|
5
5
|
|
|
@@ -16,7 +16,7 @@ interface ChatStrings {
|
|
|
16
16
|
emptyTitle: string;
|
|
17
17
|
emptyBody: string;
|
|
18
18
|
}
|
|
19
|
-
type MessengerAppearance = Pick<MessengerConfig, 'accentColor' | 'availability' | 'awayMessage' | 'greeting' | 'launcherOffsetX' | 'launcherOffsetY' | 'launcherPosition' | 'starterPrompts' | 'teamFaces'> & AppearanceSettings;
|
|
19
|
+
type MessengerAppearance = Pick<MessengerConfig, 'accentColor' | 'availability' | 'awayMessage' | 'greeting' | 'launcherOffsetX' | 'launcherOffsetY' | 'launcherPosition' | 'starterPrompts' | 'team' | 'teamFaces'> & AppearanceSettings;
|
|
20
20
|
declare const DEFAULT_APPEARANCE: MessengerAppearance;
|
|
21
21
|
declare function panelStyles(appearance: MessengerAppearance): string;
|
|
22
22
|
declare class ChatPanel {
|
|
@@ -42,6 +42,7 @@ declare class ChatPanel {
|
|
|
42
42
|
private submit;
|
|
43
43
|
private renderThread;
|
|
44
44
|
private appendTurn;
|
|
45
|
+
private agentName;
|
|
45
46
|
private stamp;
|
|
46
47
|
private onKeydown;
|
|
47
48
|
private renderBadge;
|
package/dist/chat.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ChatClient, M as MessengerConfig, A as AppearanceSettings, a as ChatTurn, b as ChatIdentity, c as ChatClientOptions } from './config-
|
|
2
|
-
export { B as BubbleFill, d as BubbleShape, e as ChatStorage, f as ChatThread, g as ComposerShape, D as DEFAULT_APPEARANCE_SETTINGS, L as LauncherContent, h as LauncherFill, i as LauncherShape, j as LauncherSize, k as MessengerSkin, N as NamePlacement, S as StampContent, l as StampPlacement, r as resolveAppearance } from './config-
|
|
1
|
+
import { C as ChatClient, M as MessengerConfig, A as AppearanceSettings, a as ChatTurn, b as ChatIdentity, c as ChatClientOptions } from './config-BR_iYD-k.js';
|
|
2
|
+
export { B as BubbleFill, d as BubbleShape, e as ChatStorage, f as ChatThread, g as ComposerShape, D as DEFAULT_APPEARANCE_SETTINGS, L as LauncherContent, h as LauncherFill, i as LauncherShape, j as LauncherSize, k as MessengerSkin, N as NamePlacement, S as StampContent, l as StampPlacement, r as resolveAppearance } from './config-BR_iYD-k.js';
|
|
3
3
|
import { S as SocketFactory } from './types-DjMXp6Wg.js';
|
|
4
4
|
import './http-BCh716Vs.js';
|
|
5
5
|
|
|
@@ -16,7 +16,7 @@ interface ChatStrings {
|
|
|
16
16
|
emptyTitle: string;
|
|
17
17
|
emptyBody: string;
|
|
18
18
|
}
|
|
19
|
-
type MessengerAppearance = Pick<MessengerConfig, 'accentColor' | 'availability' | 'awayMessage' | 'greeting' | 'launcherOffsetX' | 'launcherOffsetY' | 'launcherPosition' | 'starterPrompts' | 'teamFaces'> & AppearanceSettings;
|
|
19
|
+
type MessengerAppearance = Pick<MessengerConfig, 'accentColor' | 'availability' | 'awayMessage' | 'greeting' | 'launcherOffsetX' | 'launcherOffsetY' | 'launcherPosition' | 'starterPrompts' | 'team' | 'teamFaces'> & AppearanceSettings;
|
|
20
20
|
declare const DEFAULT_APPEARANCE: MessengerAppearance;
|
|
21
21
|
declare function panelStyles(appearance: MessengerAppearance): string;
|
|
22
22
|
declare class ChatPanel {
|
|
@@ -42,6 +42,7 @@ declare class ChatPanel {
|
|
|
42
42
|
private submit;
|
|
43
43
|
private renderThread;
|
|
44
44
|
private appendTurn;
|
|
45
|
+
private agentName;
|
|
45
46
|
private stamp;
|
|
46
47
|
private onKeydown;
|
|
47
48
|
private renderBadge;
|
package/dist/chat.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {c,a as a$2,b as b$1}from'./chunk-V77KYPOF.js';import {a as a$1,d}from'./chunk-VG77TYVX.js';import {a}from'./chunk-5XGN7UAV.js';var B="X-Prodantix-Conversation-Token",A="prodantix.chat.handle";function D(){let a=globalThis.localStorage;if(a)return {get:e=>a.getItem(e),remove:e=>a.removeItem(e),set:(e,t)=>a.setItem(e,t)}}var x=class{constructor(e){this.options=e;a(this,"fetchImpl");a(this,"host");a(this,"storage");a(this,"handle");a(this,"identity",null);this.fetchImpl=a$1(e.fetchImpl),this.host=d(e.host),this.storage=e.storage??D(),this.handle=this.readHandle();}get hasThread(){return this.handle!==null}get socketAuth(){return this.handle?{conversationId:this.handle.conversationId,conversationToken:this.handle.token,projectKey:this.options.apiKey}:null}identify(e){this.identity=e;}async ensureThread(e){if(this.handle)return true;let t=await this.request("POST","/v1/conversations",{body:{distinctId:this.options.distinctId,subject:e,userHash:this.identity?.userHash,userId:this.identity?.userId}});return !t?.conversationId||!t.token?false:(this.handle={conversationId:t.conversationId,token:t.token},this.storage?.set(A,JSON.stringify(this.handle)),true)}async send(e,t){if(!await this.ensureThread())return null;let n=this.handle;return n?(await this.request("POST",`/v1/conversations/${encodeURIComponent(n.conversationId)}/turns`,{body:{body:e,pageContext:t},token:n.token}))?.turn??null:null}async load(){let e=this.handle;return e?this.request("GET",`/v1/conversations/${encodeURIComponent(e.conversationId)}`,{token:e.token}):null}readHandle(){let e=this.storage?.get(A);if(!e)return null;try{let t=JSON.parse(e);if(typeof t.conversationId=="string"&&typeof t.token=="string")return {conversationId:t.conversationId,token:t.token}}catch{}return this.storage?.remove(A),null}async request(e,t,n={}){let r=this.fetchImpl;if(!r)return this.options.onError?.(new Error("no fetch available for prodantix chat")),null;let o={authorization:`Bearer ${this.options.apiKey}`,"content-type":"application/json"};n.token&&(o[B]=n.token);try{let s=await r(`${this.host}${t}`,{body:n.body===void 0?void 0:JSON.stringify(n.body),headers:o,method:e}),i=await s.text();return s.ok?i?JSON.parse(i):{}:(this.options.onError?.(new Error(`prodantix chat ${t}: ${s.status}`)),null)}catch(s){return this.options.onError?.(s),null}}};var U={Fri:"fri",Mon:"mon",Sat:"sat",Sun:"sun",Thu:"thu",Tue:"tue",Wed:"wed"};function S(a,e){let t=new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:false,minute:"2-digit",timeZone:a.timezone,weekday:"short"}).formatToParts(e),n=U[t.find(i=>i.type==="weekday")?.value??""];if(!n)return false;let r=t.find(i=>i.type==="hour")?.value??"",o=t.find(i=>i.type==="minute")?.value??"",s=`${r}:${o}`;return a.windows.some(i=>i.days.includes(n)&&i.open<=s&&s<i.close)}var p={bubbleFill:"filled",bubbleShape:"tailed",composerShape:"round",dayDividers:true,launcherContent:"glyph",launcherFill:"outlined",launcherShape:"circle",launcherSize:"small",nameAvatar:true,namePlacement:"hidden",skin:"standard",stampContent:"time",stampPlacement:"none"},q=["quiet","standard"],K=["round","square"],Y=["rounded","tailed"],G=["filled","outlined"],W=["circle","pill","squircle"],j=["filled","outlined"],X=["avatar","glyph","team_faces"],Z=["large","medium","small"],J=["above","hidden","inline"],V=["beside_name","none","under_turn"],Q=["time","time_and_latency"],m=(a,e,t)=>typeof a=="string"&&e.includes(a)?a:t,I=(a,e)=>typeof a=="boolean"?a:e,ee={avatar_circle:["circle","outlined","avatar","large"],circle_filled:["circle","filled","glyph","medium"],circle_outlined:["circle","outlined","glyph","small"],pill_labelled:["pill","filled","glyph","medium"],pill_team:["pill","outlined","team_faces","medium"],squircle_filled:["squircle","filled","glyph","medium"]},te={above:["above",false],avatar_only:["hidden",true],gutter:["above",true],hidden:["hidden",false],inline:["inline",false]},ne={cluster:[true,"none","time"],latency:[false,"beside_name","time_and_latency"],none:[false,"none","time"],trailing:[false,"under_turn","time"],with_name:[false,"beside_name","time"]},ae={concierge:["standard","round"],console:["standard","square"],quiet:["quiet","square"]},re={hairline:["rounded","outlined"],outlined:["rounded","outlined"],rounded:["rounded","filled"],tailed:["tailed","filled"]};function k(a){let e=typeof a=="object"&&a!==null?a:{},t=typeof e.launcherStyle=="string"?e.launcherStyle:void 0,n=t===void 0?void 0:ee[t],r=typeof e.namePlacement=="string"?e.namePlacement:void 0,o=r===void 0?void 0:te[r],s=typeof e.timestampStyle=="string"?e.timestampStyle:void 0,i=s===void 0?void 0:ne[s],u=typeof e.skin=="string"?e.skin:void 0,d=u===void 0?void 0:ae[u],l=typeof e.bubbleStyle=="string"?e.bubbleStyle:void 0,g=l===void 0?void 0:re[l],f={bubbleFill:m(e.bubbleFill,G,g?.[1]??p.bubbleFill),bubbleShape:m(e.bubbleShape,Y,g?.[0]??p.bubbleShape),composerShape:m(e.composerShape,K,d?.[1]??p.composerShape),dayDividers:I(e.dayDividers,i?.[0]??p.dayDividers),launcherContent:m(e.launcherContent,X,n?.[2]??p.launcherContent),launcherFill:m(e.launcherFill,j,n?.[1]??p.launcherFill),launcherShape:m(e.launcherShape,W,n?.[0]??p.launcherShape),launcherSize:m(e.launcherSize,Z,n?.[3]??p.launcherSize),nameAvatar:I(e.nameAvatar,o?.[1]??p.nameAvatar),namePlacement:m(e.namePlacement,J,o?.[0]??p.namePlacement),skin:m(e.skin,q,d?.[0]??p.skin),stampContent:m(e.stampContent,Q,i?.[2]??p.stampContent),stampPlacement:m(e.stampPlacement,V,i?.[1]??p.stampPlacement)};return f.stampPlacement==="beside_name"&&f.namePlacement==="hidden"&&(f.stampPlacement="under_turn"),f}var ie="M20 11.6a7.4 7.4 0 0 1-7.4 7.4H8.2L4 21.8l1-4.1A7.4 7.4 0 1 1 20 11.6Z",oe={large:66,medium:56,small:46},se={circle:"width:var(--fab-size);height:var(--fab-size);border-radius:calc(var(--fab-size) / 2);",pill:"width:auto;height:var(--fab-size);border-radius:calc(var(--fab-size) / 2);padding:0 22px;gap:10px;",squircle:"width:var(--fab-size);height:var(--fab-size);border-radius:16px;"},le={filled:"background:var(--a);color:#fff;",outlined:"background:var(--paper);border:1px solid var(--hairline);color:var(--ink-2);box-shadow:0 1px 2px rgba(0,0,0,.08);"},ce={avatar:"",glyph:".launcher svg{width:calc(var(--fab-size) * 0.375);height:calc(var(--fab-size) * 0.375);}",team_faces:".launcher .faces{display:flex;}.launcher .faces .av{box-shadow:0 0 0 2px var(--paper);}.launcher .faces .av+.av{margin-left:-10px;}"},de=".launcher .live{width:10px;height:10px;position:absolute;right:3px;bottom:3px;border-radius:50%;background:var(--online);box-shadow:0 0 0 2px var(--paper);}.launcher.closed .live{display:none}",pe={circle:"",pill:".badge{position:static;box-shadow:none}",squircle:""},ue={filled:"",outlined:".badge{background:var(--a);top:-7px;right:-7px;min-width:19px;height:19px;font-size:11.5px}"},he={circle:"",pill:".launcher .label{font-size:14px;font-weight:600;white-space:nowrap;}",squircle:""},me={circle:"",pill:"@media (max-width:480px){.launcher{width:var(--fab-size);padding:0}.launcher .label{display:none}}",squircle:""};function M(a,e,t,n){return `.launcher{--fab-size:${oe[n]}px;${se[a]}${le[e]}}${ce[t]}${de}${pe[a]}${ue[e]}${he[a]}${me[a]}`}function z(a,e,t){let n=document.createDocumentFragment();if(a==="glyph"){let s=document.createElement("span");return s.innerHTML=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${ie}"/></svg>`,n.append(...s.childNodes,T()),n}if(a==="avatar")return n.append(R(t[0],e),T()),n;let r=document.createElement("span");r.className="faces";let o=t.length>0?t.slice(0,2):[void 0];for(let s of o)r.append(R(s,e));return n.append(r,T()),n}function R(a,e){let t=document.createElement("span");return t.className="av",t.setAttribute("aria-hidden","true"),t.textContent=a?a.initials:e.agentLabel.slice(0,2).toUpperCase(),a&&(t.style.background=a.tone),t}function T(){let a=document.createElement("span");return a.className="live",a.setAttribute("aria-hidden","true"),a}var ge={agentLabel:"Agent",aiLabel:"AI",closeLabel:"Close chat",emptyBody:"We usually reply within a few minutes.",emptyTitle:"Ask us anything.",inputPlaceholder:"Type a message",launcherLabel:"Open support chat",sendLabel:"Send",timeLabel:a=>{let e=new Date(a);return Number.isNaN(e.getTime())?"":`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`},title:"Support",unreadLabel:a=>`${a} unread`},b={accentColor:"#5b5bff",availability:{timezone:"UTC",windows:[]},awayMessage:"",greeting:"",launcherOffsetX:20,launcherOffsetY:20,launcherPosition:"bottom_right",starterPrompts:[],teamFaces:[],...p},fe={quiet:".composer{position:relative;padding:10px 12px 12px}.composer input{padding-right:42px}.composer button{position:absolute;top:50%;right:16px;width:34px;min-width:34px;height:34px;padding:0;background:transparent;color:var(--ink);border-radius:7px;transform:translateY(-50%)}.composer button .sendglyph{display:block;width:18px;height:18px}.composer button .sendtext{display:none}.panel{border-radius:8px;box-shadow:0 2px 8px rgba(0,0,0,.12)}.header{background:var(--paper);color:var(--ink);height:44px;padding:0 8px 0 16px;border-bottom:1px solid var(--hairline)}.header h2{font-size:11px;letter-spacing:.11em;text-transform:uppercase;color:var(--ink-3)}.close{color:var(--ink-2)}",standard:".panel{border-radius:16px;box-shadow:0 16px 40px rgba(0,0,0,.2)}.header{background:var(--a);color:#fff;flex-direction:column;align-items:flex-start;gap:14px;padding:18px 14px 20px 20px}.header h2{font-size:19px;font-weight:640}"},be={round:".composer{padding:12px 12px 14px;gap:8px}.composer input{height:46px;border-radius:23px;padding:0 16px}.composer button{width:46px;min-width:46px;height:46px;padding:0;border-radius:23px}.composer button .sendglyph{display:block}.composer button .sendtext{display:none}",square:".composer input{height:44px;border-radius:8px;padding:0 12px}"},ye={rounded:".turn{border-radius:18px;padding:10px 15px}",tailed:".turn.agent,.turn.ai{border-radius:12px 12px 12px 4px}.turn.end_user{border-radius:12px 12px 4px 12px}"},xe={filled:"",outlined:".turn{background:none;border:1px solid var(--hairline)}.turn.end_user{background:none;border-color:var(--a);color:var(--ink)}"},ve={above:"",hidden:".turn.agent .author,.turn.ai .author:not(.ai){display:none}",inline:".body .author.below{display:block;margin:4px 0 0;font-size:11.5px;font-weight:500;color:var(--ink-2);text-transform:none;letter-spacing:0;opacity:1}"},Se=".turn.agent,.turn.ai{display:flex;gap:10px;max-width:100%;background:none;padding:0}.turn .body{background:var(--fill);padding:9px 13px;border-radius:inherit}.author{text-transform:none;letter-spacing:0;font-size:12.5px;font-weight:600;opacity:1}",ke='.divider{display:flex;align-items:center;gap:10px;margin:0;font-size:11px;opacity:.6}.divider:before,.divider:after{content:"";flex:1;height:1px;background:var(--hairline)}',Ce={beside_name:".stamp{font-size:11px;opacity:.7;margin-left:6px}",none:"",under_turn:".stamp{display:block;font-size:11px;opacity:.7;margin-top:4px}.turn.end_user .stamp{text-align:right}"},Ee=".lat{font-size:11px;opacity:.7;margin-left:6px}";function $(a){let e=k(a),t=a.launcherPosition==="bottom_left"?"left":"right",n=a.accentColor;return `${`
|
|
1
|
+
import {c,a as a$2,b as b$1}from'./chunk-V77KYPOF.js';import {a as a$1,d}from'./chunk-VG77TYVX.js';import {a}from'./chunk-5XGN7UAV.js';var B="X-Prodantix-Conversation-Token",E="prodantix.chat.handle";function D(){let a=globalThis.localStorage;if(a)return {get:e=>a.getItem(e),remove:e=>a.removeItem(e),set:(e,t)=>a.setItem(e,t)}}var x=class{constructor(e){this.options=e;a(this,"fetchImpl");a(this,"host");a(this,"storage");a(this,"handle");a(this,"identity",null);this.fetchImpl=a$1(e.fetchImpl),this.host=d(e.host),this.storage=e.storage??D(),this.handle=this.readHandle();}get hasThread(){return this.handle!==null}avatarUrl(e){return e.startsWith("/")?`${this.host}${e}?api_key=${encodeURIComponent(this.options.apiKey)}`:e}get socketAuth(){return this.handle?{conversationId:this.handle.conversationId,conversationToken:this.handle.token,projectKey:this.options.apiKey}:null}identify(e){this.identity=e;}async ensureThread(e){if(this.handle)return true;let t=await this.request("POST","/v1/conversations",{body:{distinctId:this.options.distinctId,subject:e,userHash:this.identity?.userHash,userId:this.identity?.userId}});return !t?.conversationId||!t.token?false:(this.handle={conversationId:t.conversationId,token:t.token},this.storage?.set(E,JSON.stringify(this.handle)),true)}async send(e,t){if(!await this.ensureThread())return null;let n=this.handle;return n?(await this.request("POST",`/v1/conversations/${encodeURIComponent(n.conversationId)}/turns`,{body:{body:e,pageContext:t},token:n.token}))?.turn??null:null}async load(){let e=this.handle;return e?this.request("GET",`/v1/conversations/${encodeURIComponent(e.conversationId)}`,{token:e.token}):null}readHandle(){let e=this.storage?.get(E);if(!e)return null;try{let t=JSON.parse(e);if(typeof t.conversationId=="string"&&typeof t.token=="string")return {conversationId:t.conversationId,token:t.token}}catch{}return this.storage?.remove(E),null}async request(e,t,n={}){let r=this.fetchImpl;if(!r)return this.options.onError?.(new Error("no fetch available for prodantix chat")),null;let o={authorization:`Bearer ${this.options.apiKey}`,"content-type":"application/json"};n.token&&(o[B]=n.token);try{let s=await r(`${this.host}${t}`,{body:n.body===void 0?void 0:JSON.stringify(n.body),headers:o,method:e}),i=await s.text();return s.ok?i?JSON.parse(i):{}:(this.options.onError?.(new Error(`prodantix chat ${t}: ${s.status}`)),null)}catch(s){return this.options.onError?.(s),null}}};var q={Fri:"fri",Mon:"mon",Sat:"sat",Sun:"sun",Thu:"thu",Tue:"tue",Wed:"wed"};function S(a,e){let t=new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:false,minute:"2-digit",timeZone:a.timezone,weekday:"short"}).formatToParts(e),n=q[t.find(i=>i.type==="weekday")?.value??""];if(!n)return false;let r=t.find(i=>i.type==="hour")?.value??"",o=t.find(i=>i.type==="minute")?.value??"",s=`${r}:${o}`;return a.windows.some(i=>i.days.includes(n)&&i.open<=s&&s<i.close)}var p={bubbleFill:"filled",bubbleShape:"tailed",composerShape:"round",dayDividers:true,launcherContent:"glyph",launcherFill:"outlined",launcherShape:"circle",launcherSize:"small",nameAvatar:true,namePlacement:"hidden",skin:"standard",stampContent:"time",stampPlacement:"none"},K=["quiet","standard"],Y=["round","square"],G=["rounded","tailed"],W=["filled","outlined"],j=["circle","pill","squircle"],X=["filled","outlined"],Z=["avatar","glyph","team_faces"],J=["large","medium","small"],V=["above","hidden","inline"],Q=["beside_name","none","under_turn"],ee=["time","time_and_latency"],g=(a,e,t)=>typeof a=="string"&&e.includes(a)?a:t,I=(a,e)=>typeof a=="boolean"?a:e,te={avatar_circle:["circle","outlined","avatar","large"],circle_filled:["circle","filled","glyph","medium"],circle_outlined:["circle","outlined","glyph","small"],pill_labelled:["pill","filled","glyph","medium"],pill_team:["pill","outlined","team_faces","medium"],squircle_filled:["squircle","filled","glyph","medium"]},ne={above:["above",false],avatar_only:["hidden",true],gutter:["above",true],hidden:["hidden",false],inline:["inline",false]},ae={cluster:[true,"none","time"],latency:[false,"beside_name","time_and_latency"],none:[false,"none","time"],trailing:[false,"under_turn","time"],with_name:[false,"beside_name","time"]},re={concierge:["standard","round"],console:["standard","square"],quiet:["quiet","square"]},ie={hairline:["rounded","outlined"],outlined:["rounded","outlined"],rounded:["rounded","filled"],tailed:["tailed","filled"]};function k(a){let e=typeof a=="object"&&a!==null?a:{},t=typeof e.launcherStyle=="string"?e.launcherStyle:void 0,n=t===void 0?void 0:te[t],r=typeof e.namePlacement=="string"?e.namePlacement:void 0,o=r===void 0?void 0:ne[r],s=typeof e.timestampStyle=="string"?e.timestampStyle:void 0,i=s===void 0?void 0:ae[s],u=typeof e.skin=="string"?e.skin:void 0,d=u===void 0?void 0:re[u],l=typeof e.bubbleStyle=="string"?e.bubbleStyle:void 0,h=l===void 0?void 0:ie[l],f={bubbleFill:g(e.bubbleFill,W,h?.[1]??p.bubbleFill),bubbleShape:g(e.bubbleShape,G,h?.[0]??p.bubbleShape),composerShape:g(e.composerShape,Y,d?.[1]??p.composerShape),dayDividers:I(e.dayDividers,i?.[0]??p.dayDividers),launcherContent:g(e.launcherContent,Z,n?.[2]??p.launcherContent),launcherFill:g(e.launcherFill,X,n?.[1]??p.launcherFill),launcherShape:g(e.launcherShape,j,n?.[0]??p.launcherShape),launcherSize:g(e.launcherSize,J,n?.[3]??p.launcherSize),nameAvatar:I(e.nameAvatar,o?.[1]??p.nameAvatar),namePlacement:g(e.namePlacement,V,o?.[0]??p.namePlacement),skin:g(e.skin,K,d?.[0]??p.skin),stampContent:g(e.stampContent,ee,i?.[2]??p.stampContent),stampPlacement:g(e.stampPlacement,Q,i?.[1]??p.stampPlacement)};return f.stampPlacement==="beside_name"&&f.namePlacement==="hidden"&&(f.stampPlacement="under_turn"),f}function M(a){let e=a.split(/\s+/).filter(n=>n.length>0);return (e.length>1?`${e[0]?.slice(0,1)}${e[1]?.slice(0,1)}`:e[0]?.slice(0,2)??"").toUpperCase()}var oe="M20 11.6a7.4 7.4 0 0 1-7.4 7.4H8.2L4 21.8l1-4.1A7.4 7.4 0 1 1 20 11.6Z",se={large:66,medium:56,small:46},le={circle:"width:var(--fab-size);height:var(--fab-size);border-radius:calc(var(--fab-size) / 2);",pill:"width:auto;height:var(--fab-size);border-radius:calc(var(--fab-size) / 2);padding:0 22px;gap:10px;",squircle:"width:var(--fab-size);height:var(--fab-size);border-radius:16px;"},ce={filled:"background:var(--a);color:#fff;",outlined:"background:var(--paper);border:1px solid var(--hairline);color:var(--ink-2);box-shadow:0 1px 2px rgba(0,0,0,.08);"},de={avatar:"",glyph:".launcher svg{width:calc(var(--fab-size) * 0.375);height:calc(var(--fab-size) * 0.375);}",team_faces:".launcher .faces{display:flex;}.launcher .faces .av{box-shadow:0 0 0 2px var(--paper);}.launcher .faces .av+.av{margin-left:-10px;}"},pe=".launcher .live{width:10px;height:10px;position:absolute;right:3px;bottom:3px;border-radius:50%;background:var(--online);box-shadow:0 0 0 2px var(--paper);}.launcher.closed .live{display:none}",ue={circle:"",pill:".badge{position:static;box-shadow:none}",squircle:""},he={filled:"",outlined:".badge{background:var(--a);top:-7px;right:-7px;min-width:19px;height:19px;font-size:11.5px}"},me={circle:"",pill:".launcher .label{font-size:14px;font-weight:600;white-space:nowrap;}",squircle:""},ge={circle:"",pill:"@media (max-width:480px){.launcher{width:var(--fab-size);padding:0}.launcher .label{display:none}}",squircle:""};function $(a,e,t,n){return `.launcher{--fab-size:${se[n]}px;${le[a]}${ce[e]}}${de[t]}${pe}${ue[a]}${he[e]}${me[a]}${ge[a]}`}function z(a,e,t,n=r=>r){let r=document.createDocumentFragment();if(a==="glyph"){let i=document.createElement("span");return i.innerHTML=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${oe}"/></svg>`,r.append(...i.childNodes,T()),r}if(a==="avatar")return r.append(R(t[0],e,n),T()),r;let o=document.createElement("span");o.className="faces";let s=t.length>0?t.slice(0,2):[void 0];for(let i of s)o.append(R(i,e,n));return r.append(o,T()),r}function R(a,e,t){let n=document.createElement("span");if(n.className="av",n.setAttribute("aria-hidden","true"),a&&(n.style.background=a.tone),a?.avatarUrl){let r=document.createElement("img");return r.alt="",r.src=t(a.avatarUrl),n.append(r),n}return n.textContent=a?a.initials:e.agentLabel.slice(0,2).toUpperCase(),n}function T(){let a=document.createElement("span");return a.className="live",a.setAttribute("aria-hidden","true"),a}var fe={agentLabel:"Agent",aiLabel:"AI",closeLabel:"Close chat",emptyBody:"We usually reply within a few minutes.",emptyTitle:"Ask us anything.",inputPlaceholder:"Type a message",launcherLabel:"Open support chat",sendLabel:"Send",timeLabel:a=>{let e=new Date(a);return Number.isNaN(e.getTime())?"":`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`},title:"Support",unreadLabel:a=>`${a} unread`},b={accentColor:"#5b5bff",availability:{timezone:"UTC",windows:[]},awayMessage:"",greeting:"",launcherOffsetX:20,launcherOffsetY:20,launcherPosition:"bottom_right",starterPrompts:[],team:[],teamFaces:[],...p};function be(a){return a.team.length>0?a.team:a.teamFaces}var ye={quiet:".composer{position:relative;padding:10px 12px 12px}.composer input{padding-right:42px}.composer button{position:absolute;top:50%;right:16px;width:34px;min-width:34px;height:34px;padding:0;background:transparent;color:var(--ink);border-radius:7px;transform:translateY(-50%)}.composer button .sendglyph{display:block;width:18px;height:18px}.composer button .sendtext{display:none}.panel{border-radius:8px;box-shadow:0 2px 8px rgba(0,0,0,.12)}.header{background:var(--paper);color:var(--ink);height:44px;padding:0 8px 0 16px;border-bottom:1px solid var(--hairline)}.header h2{font-size:11px;letter-spacing:.11em;text-transform:uppercase;color:var(--ink-3)}.close{color:var(--ink-2)}",standard:".panel{border-radius:16px;box-shadow:0 16px 40px rgba(0,0,0,.2)}.header{background:var(--a);color:#fff;flex-direction:column;align-items:flex-start;gap:14px;padding:18px 14px 20px 20px}.header h2{font-size:19px;font-weight:640}"},xe={round:".composer{padding:12px 12px 14px;gap:8px}.composer input{height:46px;border-radius:23px;padding:0 16px}.composer button{width:46px;min-width:46px;height:46px;padding:0;border-radius:23px}.composer button .sendglyph{display:block}.composer button .sendtext{display:none}",square:".composer input{height:44px;border-radius:8px;padding:0 12px}"},ve={rounded:".turn{border-radius:18px;padding:10px 15px}",tailed:".turn.agent,.turn.ai{border-radius:12px 12px 12px 4px}.turn.end_user{border-radius:12px 12px 4px 12px}"},Se={filled:"",outlined:".turn{background:none;border:1px solid var(--hairline)}.turn.end_user{background:none;border-color:var(--a);color:var(--ink)}"},ke={above:"",hidden:".turn.agent .author,.turn.ai .author:not(.ai){display:none}",inline:".body .author.below{display:block;margin:4px 0 0;font-size:11.5px;font-weight:500;color:var(--ink-2);text-transform:none;letter-spacing:0;opacity:1}"},Ce=".turn.agent,.turn.ai{display:flex;gap:10px;max-width:100%;background:none;padding:0}.turn .body{background:var(--fill);padding:9px 13px;border-radius:inherit}.author{text-transform:none;letter-spacing:0;font-size:12.5px;font-weight:600;opacity:1}",Ae='.divider{display:flex;align-items:center;gap:10px;margin:0;font-size:11px;opacity:.6}.divider:before,.divider:after{content:"";flex:1;height:1px;background:var(--hairline)}',Ee={beside_name:".stamp{font-size:11px;opacity:.7;margin-left:6px}",none:"",under_turn:".stamp{display:block;font-size:11px;opacity:.7;margin-top:4px}.turn.end_user .stamp{text-align:right}"},Te=".lat{font-size:11px;opacity:.7;margin-left:6px}";function O(a){let e=k(a),t=a.launcherPosition==="bottom_left"?"left":"right",n=a.accentColor;return `${`
|
|
2
2
|
:host {
|
|
3
3
|
all: initial; --a: ${n};
|
|
4
4
|
--paper: #fff; --ink: #0f172a; --ink-3: var(--ink-3);
|
|
@@ -54,6 +54,7 @@ import {c,a as a$2,b as b$1}from'./chunk-V77KYPOF.js';import {a as a$1,d}from'./
|
|
|
54
54
|
.prompt:focus-visible { outline: 2px solid ${n}; outline-offset: 2px; }
|
|
55
55
|
.av { width: 30px; height: 30px; border-radius: 50%; flex: none; display: inline-flex; align-items: center; justify-content: center; font-size: 11.5px; font-weight: 650; color: #fff; background: #7c3f3f; }
|
|
56
56
|
.av.bot { border-radius: 9px; background: var(--fill); color: var(--ink); }
|
|
57
|
+
.av img { width: 100%; height: 100%; display: block; object-fit: cover; border-radius: inherit; }
|
|
57
58
|
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--hairline); }
|
|
58
59
|
.composer input { flex: 1; min-width: 0; height: 44px; padding: 0 12px; border: 0; border-radius: 8px; font-size: 14px; background: var(--fill); color: var(--ink); }
|
|
59
60
|
.composer input:focus-visible { outline: 2px solid ${n}; }
|
|
@@ -64,5 +65,5 @@ import {c,a as a$2,b as b$1}from'./chunk-V77KYPOF.js';import {a as a$1,d}from'./
|
|
|
64
65
|
.panel { animation: rise 180ms ease-out; }
|
|
65
66
|
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
|
|
66
67
|
}
|
|
67
|
-
`}${
|
|
68
|
+
`}${xe[e.composerShape]}${ye[e.skin]}${$(e.launcherShape,e.launcherFill,e.launcherContent,e.launcherSize)}${ve[e.bubbleShape]}${Se[e.bubbleFill]}${ke[e.namePlacement]}${e.nameAvatar?Ce:""}${e.dayDividers?Ae:""}${Ee[e.stampPlacement]}${e.stampContent==="time_and_latency"?Te:""}`}var Le=["end_user","agent","ai"];function we(){let a=globalThis.location;if(a)return {host:a.host,path:a.pathname,title:document.title}}var v=class{constructor(e,t,n={},r={}){this.host=e;this.client=t;a(this,"root");a(this,"strings");a(this,"settings");a(this,"appearance");a(this,"launcher");a(this,"badge");a(this,"panel",null);a(this,"lastFocused",null);a(this,"unread",0);this.strings={...fe,...n},this.appearance={...b,...r},this.settings=k({...b,...r}),this.root=e.attachShadow({mode:"closed"});let o=document.createElement("style");if(o.textContent=O({...b,...r}),this.root.append(o),this.launcher=document.createElement("button"),this.launcher.className="launcher",this.launcher.type="button",this.launcher.setAttribute("aria-haspopup","dialog"),this.launcher.setAttribute("aria-label",this.strings.launcherLabel),this.launcher.append(z(this.settings.launcherContent,this.strings,be(this.appearance),s=>this.client.avatarUrl(s))),this.settings.launcherShape==="pill"){let s=document.createElement("span");s.className="label",s.textContent=this.settings.launcherContent==="team_faces"?this.strings.agentLabel:this.strings.launcherLabel,this.launcher.append(s);}this.launcher.addEventListener("click",()=>this.toggle()),this.badge=document.createElement("span"),this.badge.className="badge",this.badge.hidden=true,this.launcher.append(this.badge),this.root.append(this.launcher);}toggle(){this.panel?this.close():this.open();}setOpenNow(e){this.launcher.classList.toggle("closed",!e);}async open(){if(this.panel)return;this.lastFocused=this.host.ownerDocument.activeElement,this.unread=0,this.renderBadge();let e=document.createElement("section");e.className="panel",e.setAttribute("role","dialog"),e.setAttribute("aria-modal","true"),e.setAttribute("aria-label",this.strings.title);let t=document.createElement("div");t.className="header";let n=document.createElement("h2");n.textContent=this.strings.title;let r=document.createElement("button");r.className="close",r.type="button",r.setAttribute("aria-label",this.strings.closeLabel),r.textContent="\xD7",r.addEventListener("click",()=>this.close()),t.append(n,r);let o=document.createElement("div");o.className="log",o.setAttribute("role","log"),o.setAttribute("aria-live","polite"),o.setAttribute("aria-label",this.strings.title);let s=document.createElement("form");s.className="composer";let i=document.createElement("input");i.type="text",i.setAttribute("aria-label",this.strings.inputPlaceholder),i.placeholder=this.strings.inputPlaceholder;let u=document.createElement("button");u.type="submit",u.setAttribute("aria-label",this.strings.sendLabel),u.innerHTML='<svg class="sendglyph" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4.5 12 20 4.5 15 20l-3.6-5.4L4.5 12Z"/></svg>';let d=document.createElement("span");d.className="sendtext",d.textContent=this.strings.sendLabel,u.append(d),s.append(i,u),s.addEventListener("submit",h=>{h.preventDefault(),this.submit(i,o);}),e.append(t,o,s),e.addEventListener("keydown",h=>this.onKeydown(h,e,r)),this.root.append(e),this.panel=e,i.focus();let l=await this.client.load();l&&l.turns.length>0?this.renderThread(o,l):this.renderFirstRun(o,i),!S(this.appearance.availability,new Date)&&this.appearance.awayMessage.trim()&&this.renderAway(o);}renderFirstRun(e,t){let n=document.createElement("div");n.className="empty";let r=document.createElement("h3");r.textContent=this.appearance.greeting.trim()||this.strings.emptyTitle;let o=document.createElement("p");o.textContent=this.strings.emptyBody,n.append(r,o);for(let s of this.appearance.starterPrompts){let i=document.createElement("button");i.className="prompt",i.type="button",i.textContent=s,i.addEventListener("click",()=>{t.value=s,this.submit(t,e);}),n.append(i);}e.replaceChildren(n);}renderAway(e){let t=document.createElement("div");t.className="away",t.textContent=this.appearance.awayMessage,e.prepend(t);}close(){this.panel&&(this.panel.remove(),this.panel=null,this.lastFocused instanceof HTMLElement?this.lastFocused.focus():this.launcher.focus());}onIncomingTurn(e){if(this.panel){let t=this.panel.querySelector(".log");t instanceof HTMLElement&&this.appendTurn(t,e);return}e.authorKind!=="end_user"&&(this.unread+=1,this.renderBadge());}async submit(e,t){let n=e.value.trim();if(!n)return;e.value="",t.querySelector(".empty")?.remove();let r=await this.client.send(n,we());r&&this.appendTurn(t,r);}renderThread(e,t){e.replaceChildren();for(let n of t.turns)this.appendTurn(e,n);}appendTurn(e,t){e.querySelector(".empty")?.remove();let n=Le.includes(t.authorKind)?t.authorKind:"agent",r=this.settings,o=document.createElement("div");if(o.className=`turn ${n}`,n!=="end_user"&&r.nameAvatar){let l=document.createElement("span");if(l.className=n==="ai"?"av bot":"av",l.setAttribute("aria-hidden","true"),n==="agent"&&t.authorAvatarUrl){let h=document.createElement("img");h.alt="",h.src=this.client.avatarUrl(t.authorAvatarUrl),l.append(h);}else l.textContent=n==="ai"?this.strings.aiLabel:M(this.agentName(t));o.append(l);}let i=document.createElement("div");i.className="body";let u=n!=="end_user"&&r.namePlacement!=="hidden",d=document.createElement("div");if(d.textContent=t.body,u||n==="ai"&&r.namePlacement==="hidden"){let l=document.createElement("div");l.className=n==="ai"?"author ai":"author",l.textContent=n==="ai"?this.strings.aiLabel:this.agentName(t),r.stampPlacement==="beside_name"&&l.append(this.stamp(t)),r.namePlacement==="inline"?(l.classList.add("below"),i.append(d,l)):i.append(l,d);}else i.append(d);r.stampPlacement==="under_turn"&&i.append(this.stamp(t)),o.append(i),e.append(o),e.scrollTop=e.scrollHeight;}agentName(e){return e.authorName||this.strings.agentLabel}stamp(e){let t=document.createElement("span");return t.className="stamp",t.textContent=this.strings.timeLabel(e.createdAt),t}onKeydown(e,t,n){if(e.key==="Escape"){e.preventDefault(),this.close();return}if(e.key!=="Tab")return;let r=t.querySelectorAll('button, input, [tabindex]:not([tabindex="-1"])');if(r.length===0)return;let o=r[0],s=r[r.length-1],i=this.root.activeElement;e.shiftKey&&i===o?(e.preventDefault(),s.focus()):!e.shiftKey&&i===s?(e.preventDefault(),o.focus()):i===null&&(e.preventDefault(),n.focus());}renderBadge(){this.unread>0?(this.badge.hidden=false,this.badge.textContent=String(this.unread),this.launcher.setAttribute("aria-label",`${this.strings.launcherLabel}, ${this.strings.unreadLabel(this.unread)}`)):(this.badge.hidden=true,this.badge.textContent="",this.launcher.setAttribute("aria-label",this.strings.launcherLabel));}};var Pe="/socket.io/?EIO=4&transport=websocket",C=class{constructor(e){this.options=e;a(this,"socket",null);a(this,"heartbeat",null);a(this,"ready",false);a(this,"closed",false);a(this,"heartbeatWindow",45e3);a(this,"factory");a(this,"setTimer");a(this,"clearTimer");this.factory=e.socketFactory??_e,this.setTimer=e.setTimer??((t,n)=>setTimeout(t,n)),this.clearTimer=e.clearTimer??(t=>clearTimeout(t));}open(){if(this.socket||this.closed)return;let e=`${this.options.host.replace(/^http/,"ws").replace(/\/+$/,"")}${Pe}`,t;try{t=this.factory(e);}catch{this.options.onClosed(false);return}this.socket=t,t.onmessage=n=>this.receive(String(n.data)),t.onerror=()=>t.close(),t.onclose=()=>this.fell();}close(){this.closed=true,this.stopHeartbeat();let e=this.socket;this.socket=null,e?.close();}receive(e){let t=c(e);if(t.kind==="open"){this.armHeartbeat(t.pingInterval+t.pingTimeout),this.socket?.send(a$2(this.options.auth));return}if(t.kind==="ping"){this.armHeartbeat(),this.socket?.send(b$1());return}if(t.kind==="connectError"||t.kind==="disconnect"){this.stopHeartbeat(),this.socket?.close();return}if(t.kind==="event"){if(t.name==="ready"){this.ready=true,this.options.onReady();return}if(t.name==="conversation.turn"){let n=t.payload?.turn;n&&this.options.onTurn(n);}}}fell(){this.stopHeartbeat();let e=this.ready;this.socket=null,this.ready=false,this.closed||this.options.onClosed(e);}armHeartbeat(e){e!==void 0&&(this.heartbeatWindow=e),this.stopHeartbeat(),this.heartbeat=this.setTimer(()=>this.socket?.close(),this.heartbeatWindow);}stopHeartbeat(){this.heartbeat!==null&&this.clearTimer(this.heartbeat),this.heartbeat=null;}};function _e(a){let e=globalThis.WebSocket;if(!e)throw new Error("no WebSocket");return new e(a)}var Ne=6e4;function Ze(a){let e=globalThis.document;if(!e)throw new Error("prodantix chat requires a document; mount it in the browser");let t=a.mountPoint??e.createElement("div");a.mountPoint||e.body.append(t);let n=new x(a),r=new v(t,n,a.strings,a.appearance),o=a.appearance?.availability??b.availability,s,i=()=>{r.setOpenNow(S(o,new Date)),s=setTimeout(i,Ne);};i();let u=new Set,d,l=null,h=a.pollIntervalMs??15e3,f=m=>{u.has(m.id)||m.authorKind==="end_user"||(u.add(m.id),r.onIncomingTurn(m));},U=async()=>{if(!n.hasThread)return;let m=await n.load();if(m){for(let y of m.turns)f(y);u=new Set(m.turns.map(y=>y.id));}},L=()=>{d||h<=0||(d=setInterval(()=>void U(),h));},w=()=>{d&&clearInterval(d),d=void 0;},A=()=>{if(l||!a.socketHost)return;let m=n.socketAuth;m&&(l=new C({auth:m,host:a.socketHost,onClosed:y=>{l=null,L(),y&&A();},onReady:w,onTurn:f,socketFactory:a.socketFactory}),l.open());};return L(),A(),{close:()=>r.close(),destroy:()=>{w(),clearTimeout(s),l?.close(),l=null,r.close(),t.remove();},identify:m=>n.identify(m),open:()=>{r.open().then(A);}}}export{x as ChatClient,v as ChatPanel,b as DEFAULT_APPEARANCE,p as DEFAULT_APPEARANCE_SETTINGS,Ze as mountChat,O as panelStyles,k as resolveAppearance};//# sourceMappingURL=chat.js.map
|
|
68
69
|
//# sourceMappingURL=chat.js.map
|
|
@@ -6,6 +6,8 @@ interface ChatTurn {
|
|
|
6
6
|
authorId: string | null;
|
|
7
7
|
body: string;
|
|
8
8
|
createdAt: string;
|
|
9
|
+
authorName?: string | null;
|
|
10
|
+
authorAvatarUrl?: string | null;
|
|
9
11
|
}
|
|
10
12
|
interface ChatThread {
|
|
11
13
|
id: string;
|
|
@@ -43,6 +45,7 @@ declare class ChatClient {
|
|
|
43
45
|
private identity;
|
|
44
46
|
constructor(options: ChatClientOptions);
|
|
45
47
|
get hasThread(): boolean;
|
|
48
|
+
avatarUrl(url: string): string;
|
|
46
49
|
get socketAuth(): {
|
|
47
50
|
conversationId: string;
|
|
48
51
|
conversationToken: string;
|
|
@@ -96,6 +99,12 @@ type Availability = {
|
|
|
96
99
|
};
|
|
97
100
|
|
|
98
101
|
interface TeamFace {
|
|
102
|
+
name: string;
|
|
103
|
+
initials: string;
|
|
104
|
+
tone: string;
|
|
105
|
+
avatarUrl: string | null;
|
|
106
|
+
}
|
|
107
|
+
interface TypedFace {
|
|
99
108
|
initials: string;
|
|
100
109
|
tone: string;
|
|
101
110
|
}
|
|
@@ -111,7 +120,8 @@ interface MessengerConfig extends AppearanceSettings {
|
|
|
111
120
|
availability: Availability;
|
|
112
121
|
version: string;
|
|
113
122
|
starterPrompts: string[];
|
|
114
|
-
teamFaces:
|
|
123
|
+
teamFaces: TypedFace[];
|
|
124
|
+
team: TeamFace[];
|
|
115
125
|
socketUrl: string;
|
|
116
126
|
}
|
|
117
127
|
interface MessengerConfigOptions {
|
|
@@ -6,6 +6,8 @@ interface ChatTurn {
|
|
|
6
6
|
authorId: string | null;
|
|
7
7
|
body: string;
|
|
8
8
|
createdAt: string;
|
|
9
|
+
authorName?: string | null;
|
|
10
|
+
authorAvatarUrl?: string | null;
|
|
9
11
|
}
|
|
10
12
|
interface ChatThread {
|
|
11
13
|
id: string;
|
|
@@ -43,6 +45,7 @@ declare class ChatClient {
|
|
|
43
45
|
private identity;
|
|
44
46
|
constructor(options: ChatClientOptions);
|
|
45
47
|
get hasThread(): boolean;
|
|
48
|
+
avatarUrl(url: string): string;
|
|
46
49
|
get socketAuth(): {
|
|
47
50
|
conversationId: string;
|
|
48
51
|
conversationToken: string;
|
|
@@ -96,6 +99,12 @@ type Availability = {
|
|
|
96
99
|
};
|
|
97
100
|
|
|
98
101
|
interface TeamFace {
|
|
102
|
+
name: string;
|
|
103
|
+
initials: string;
|
|
104
|
+
tone: string;
|
|
105
|
+
avatarUrl: string | null;
|
|
106
|
+
}
|
|
107
|
+
interface TypedFace {
|
|
99
108
|
initials: string;
|
|
100
109
|
tone: string;
|
|
101
110
|
}
|
|
@@ -111,7 +120,8 @@ interface MessengerConfig extends AppearanceSettings {
|
|
|
111
120
|
availability: Availability;
|
|
112
121
|
version: string;
|
|
113
122
|
starterPrompts: string[];
|
|
114
|
-
teamFaces:
|
|
123
|
+
teamFaces: TypedFace[];
|
|
124
|
+
team: TeamFace[];
|
|
115
125
|
socketUrl: string;
|
|
116
126
|
}
|
|
117
127
|
interface MessengerConfigOptions {
|
package/dist/messenger.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { m as MESSENGER_CACHE_KEY, M as MessengerConfig, n as MessengerConfigOptions, o as cachedMessengerConfig, p as fetchMessengerConfig } from './config-
|
|
1
|
+
export { m as MESSENGER_CACHE_KEY, M as MessengerConfig, n as MessengerConfigOptions, o as cachedMessengerConfig, p as fetchMessengerConfig } from './config-BD9kg-c4.cjs';
|
|
2
2
|
import './http-BCh716Vs.cjs';
|
package/dist/messenger.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { m as MESSENGER_CACHE_KEY, M as MessengerConfig, n as MessengerConfigOptions, o as cachedMessengerConfig, p as fetchMessengerConfig } from './config-
|
|
1
|
+
export { m as MESSENGER_CACHE_KEY, M as MessengerConfig, n as MessengerConfigOptions, o as cachedMessengerConfig, p as fetchMessengerConfig } from './config-BR_iYD-k.js';
|
|
2
2
|
import './http-BCh716Vs.js';
|
package/dist/messenger.iife.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(){'use strict';var ee=Object.defineProperty;var te=(n,e,t)=>e in n?ee(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t;var u=(n,e,t)=>te(n,typeof e!="symbol"?e+"":e,t);function L(n){if(n)return n;let e=globalThis.fetch;if(typeof e=="function")return e.bind(globalThis)}function _(n){return n.replace(/\/+$/,"")}var ne="X-Prodantix-Conversation-Token",M="prodantix.chat.handle";function re(){let n=globalThis.localStorage;if(n)return {get:e=>n.getItem(e),remove:e=>n.removeItem(e),set:(e,t)=>n.setItem(e,t)}}var P=class{constructor(e){this.options=e;u(this,"fetchImpl");u(this,"host");u(this,"storage");u(this,"handle");u(this,"identity",null);var t;this.fetchImpl=L(e.fetchImpl),this.host=_(e.host),this.storage=(t=e.storage)!=null?t:re(),this.handle=this.readHandle();}get hasThread(){return this.handle!==null}get socketAuth(){return this.handle?{conversationId:this.handle.conversationId,conversationToken:this.handle.token,projectKey:this.options.apiKey}:null}identify(e){this.identity=e;}async ensureThread(e){var r,i,a;if(this.handle)return true;let t=await this.request("POST","/v1/conversations",{body:{distinctId:this.options.distinctId,subject:e,userHash:(r=this.identity)==null?void 0:r.userHash,userId:(i=this.identity)==null?void 0:i.userId}});return !(t!=null&&t.conversationId)||!t.token?false:(this.handle={conversationId:t.conversationId,token:t.token},(a=this.storage)==null||a.set(M,JSON.stringify(this.handle)),true)}async send(e,t){var a;if(!await this.ensureThread())return null;let r=this.handle;if(!r)return null;let i=await this.request("POST",`/v1/conversations/${encodeURIComponent(r.conversationId)}/turns`,{body:{body:e,pageContext:t},token:r.token});return (a=i==null?void 0:i.turn)!=null?a:null}async load(){let e=this.handle;return e?this.request("GET",`/v1/conversations/${encodeURIComponent(e.conversationId)}`,{token:e.token}):null}readHandle(){var t,r;let e=(t=this.storage)==null?void 0:t.get(M);if(!e)return null;try{let i=JSON.parse(e);if(typeof i.conversationId=="string"&&typeof i.token=="string")return {conversationId:i.conversationId,token:i.token}}catch(i){}return (r=this.storage)==null||r.remove(M),null}async request(e,t,r={}){var o,s,p,l,c,d;let i=this.fetchImpl;if(!i)return (s=(o=this.options).onError)==null||s.call(o,new Error("no fetch available for prodantix chat")),null;let a={authorization:`Bearer ${this.options.apiKey}`,"content-type":"application/json"};r.token&&(a[ne]=r.token);try{let g=await i(`${this.host}${t}`,{body:r.body===void 0?void 0:JSON.stringify(r.body),headers:a,method:e}),h=await g.text();return g.ok?h?JSON.parse(h):{}:((l=(p=this.options).onError)==null||l.call(p,new Error(`prodantix chat ${t}: ${g.status}`)),null)}catch(g){return (d=(c=this.options).onError)==null||d.call(c,g),null}}};var ie={Fri:"fri",Mon:"mon",Sat:"sat",Sun:"sun",Thu:"thu",Tue:"tue",Wed:"wed"};function N(n,e){var s,p,l,c,d,g;let t=new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:false,minute:"2-digit",timeZone:n.timezone,weekday:"short"}).formatToParts(e),r=ie[(p=(s=t.find(h=>h.type==="weekday"))==null?void 0:s.value)!=null?p:""];if(!r)return false;let i=(c=(l=t.find(h=>h.type==="hour"))==null?void 0:l.value)!=null?c:"",a=(g=(d=t.find(h=>h.type==="minute"))==null?void 0:d.value)!=null?g:"",o=`${i}:${a}`;return n.windows.some(h=>h.days.includes(r)&&h.open<=o&&o<h.close)}var b={bubbleFill:"filled",bubbleShape:"tailed",composerShape:"round",dayDividers:true,launcherContent:"glyph",launcherFill:"outlined",launcherShape:"circle",launcherSize:"small",nameAvatar:true,namePlacement:"hidden",skin:"standard",stampContent:"time",stampPlacement:"none"},ae=["quiet","standard"],oe=["round","square"],se=["rounded","tailed"],le=["filled","outlined"],ce=["circle","pill","squircle"],de=["filled","outlined"],pe=["avatar","glyph","team_faces"],ue=["large","medium","small"],he=["above","hidden","inline"],ge=["beside_name","none","under_turn"],me=["time","time_and_latency"],y=(n,e,t)=>typeof n=="string"&&e.includes(n)?n:t,B=(n,e)=>typeof n=="boolean"?n:e,fe={avatar_circle:["circle","outlined","avatar","large"],circle_filled:["circle","filled","glyph","medium"],circle_outlined:["circle","outlined","glyph","small"],pill_labelled:["pill","filled","glyph","medium"],pill_team:["pill","outlined","team_faces","medium"],squircle_filled:["squircle","filled","glyph","medium"]},be={above:["above",false],avatar_only:["hidden",true],gutter:["above",true],hidden:["hidden",false],inline:["inline",false]},ye={cluster:[true,"none","time"],latency:[false,"beside_name","time_and_latency"],none:[false,"none","time"],trailing:[false,"under_turn","time"],with_name:[false,"beside_name","time"]},xe={concierge:["standard","round"],console:["standard","square"],quiet:["quiet","square"]},Se={hairline:["rounded","outlined"],outlined:["rounded","outlined"],rounded:["rounded","filled"],tailed:["tailed","filled"]};function H(n){var h,v,C,x,m,S,k,T,f,E,z,K,D;let e=typeof n=="object"&&n!==null?n:{},t=typeof e.launcherStyle=="string"?e.launcherStyle:void 0,r=t===void 0?void 0:fe[t],i=typeof e.namePlacement=="string"?e.namePlacement:void 0,a=i===void 0?void 0:be[i],o=typeof e.timestampStyle=="string"?e.timestampStyle:void 0,s=o===void 0?void 0:ye[o],p=typeof e.skin=="string"?e.skin:void 0,l=p===void 0?void 0:xe[p],c=typeof e.bubbleStyle=="string"?e.bubbleStyle:void 0,d=c===void 0?void 0:Se[c],g={bubbleFill:y(e.bubbleFill,le,(h=d==null?void 0:d[1])!=null?h:b.bubbleFill),bubbleShape:y(e.bubbleShape,se,(v=d==null?void 0:d[0])!=null?v:b.bubbleShape),composerShape:y(e.composerShape,oe,(C=l==null?void 0:l[1])!=null?C:b.composerShape),dayDividers:B(e.dayDividers,(x=s==null?void 0:s[0])!=null?x:b.dayDividers),launcherContent:y(e.launcherContent,pe,(m=r==null?void 0:r[2])!=null?m:b.launcherContent),launcherFill:y(e.launcherFill,de,(S=r==null?void 0:r[1])!=null?S:b.launcherFill),launcherShape:y(e.launcherShape,ce,(k=r==null?void 0:r[0])!=null?k:b.launcherShape),launcherSize:y(e.launcherSize,ue,(T=r==null?void 0:r[3])!=null?T:b.launcherSize),nameAvatar:B(e.nameAvatar,(f=a==null?void 0:a[1])!=null?f:b.nameAvatar),namePlacement:y(e.namePlacement,he,(E=a==null?void 0:a[0])!=null?E:b.namePlacement),skin:y(e.skin,ae,(z=l==null?void 0:l[0])!=null?z:b.skin),stampContent:y(e.stampContent,me,(K=s==null?void 0:s[2])!=null?K:b.stampContent),stampPlacement:y(e.stampPlacement,ge,(D=s==null?void 0:s[1])!=null?D:b.stampPlacement)};return g.stampPlacement==="beside_name"&&g.namePlacement==="hidden"&&(g.stampPlacement="under_turn"),g}var ve="M20 11.6a7.4 7.4 0 0 1-7.4 7.4H8.2L4 21.8l1-4.1A7.4 7.4 0 1 1 20 11.6Z",Ce={large:66,medium:56,small:46},ke={circle:"width:var(--fab-size);height:var(--fab-size);border-radius:calc(var(--fab-size) / 2);",pill:"width:auto;height:var(--fab-size);border-radius:calc(var(--fab-size) / 2);padding:0 22px;gap:10px;",squircle:"width:var(--fab-size);height:var(--fab-size);border-radius:16px;"},Ee={filled:"background:var(--a);color:#fff;",outlined:"background:var(--paper);border:1px solid var(--hairline);color:var(--ink-2);box-shadow:0 1px 2px rgba(0,0,0,.08);"},Te={avatar:"",glyph:".launcher svg{width:calc(var(--fab-size) * 0.375);height:calc(var(--fab-size) * 0.375);}",team_faces:".launcher .faces{display:flex;}.launcher .faces .av{box-shadow:0 0 0 2px var(--paper);}.launcher .faces .av+.av{margin-left:-10px;}"},Ae=".launcher .live{width:10px;height:10px;position:absolute;right:3px;bottom:3px;border-radius:50%;background:var(--online);box-shadow:0 0 0 2px var(--paper);}.launcher.closed .live{display:none}",we={circle:"",pill:".badge{position:static;box-shadow:none}",squircle:""},Le={filled:"",outlined:".badge{background:var(--a);top:-7px;right:-7px;min-width:19px;height:19px;font-size:11.5px}"},_e={circle:"",pill:".launcher .label{font-size:14px;font-weight:600;white-space:nowrap;}",squircle:""},Pe={circle:"",pill:"@media (max-width:480px){.launcher{width:var(--fab-size);padding:0}.launcher .label{display:none}}",squircle:""};function G(n,e,t,r){return `.launcher{--fab-size:${Ce[r]}px;${ke[n]}${Ee[e]}}${Te[t]}${Ae}${we[n]}${Le[e]}${_e[n]}${Pe[n]}`}function q(n,e,t){let r=document.createDocumentFragment();if(n==="glyph"){let o=document.createElement("span");return o.innerHTML=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${ve}"/></svg>`,r.append(...o.childNodes,R()),r}if(n==="avatar")return r.append(U(t[0],e),R()),r;let i=document.createElement("span");i.className="faces";let a=t.length>0?t.slice(0,2):[void 0];for(let o of a)i.append(U(o,e));return r.append(i,R()),r}function U(n,e){let t=document.createElement("span");return t.className="av",t.setAttribute("aria-hidden","true"),t.textContent=n?n.initials:e.agentLabel.slice(0,2).toUpperCase(),n&&(t.style.background=n.tone),t}function R(){let n=document.createElement("span");return n.className="live",n.setAttribute("aria-hidden","true"),n}var Ne={agentLabel:"Agent",aiLabel:"AI",closeLabel:"Close chat",emptyBody:"We usually reply within a few minutes.",emptyTitle:"Ask us anything.",inputPlaceholder:"Type a message",launcherLabel:"Open support chat",sendLabel:"Send",timeLabel:n=>{let e=new Date(n);return Number.isNaN(e.getTime())?"":`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`},title:"Support",unreadLabel:n=>`${n} unread`},A={accentColor:"#5b5bff",availability:{timezone:"UTC",windows:[]},awayMessage:"",greeting:"",launcherOffsetX:20,launcherOffsetY:20,launcherPosition:"bottom_right",starterPrompts:[],teamFaces:[],...b},Ie={quiet:".composer{position:relative;padding:10px 12px 12px}.composer input{padding-right:42px}.composer button{position:absolute;top:50%;right:16px;width:34px;min-width:34px;height:34px;padding:0;background:transparent;color:var(--ink);border-radius:7px;transform:translateY(-50%)}.composer button .sendglyph{display:block;width:18px;height:18px}.composer button .sendtext{display:none}.panel{border-radius:8px;box-shadow:0 2px 8px rgba(0,0,0,.12)}.header{background:var(--paper);color:var(--ink);height:44px;padding:0 8px 0 16px;border-bottom:1px solid var(--hairline)}.header h2{font-size:11px;letter-spacing:.11em;text-transform:uppercase;color:var(--ink-3)}.close{color:var(--ink-2)}",standard:".panel{border-radius:16px;box-shadow:0 16px 40px rgba(0,0,0,.2)}.header{background:var(--a);color:#fff;flex-direction:column;align-items:flex-start;gap:14px;padding:18px 14px 20px 20px}.header h2{font-size:19px;font-weight:640}"},Fe={round:".composer{padding:12px 12px 14px;gap:8px}.composer input{height:46px;border-radius:23px;padding:0 16px}.composer button{width:46px;min-width:46px;height:46px;padding:0;border-radius:23px}.composer button .sendglyph{display:block}.composer button .sendtext{display:none}",square:".composer input{height:44px;border-radius:8px;padding:0 12px}"},Me={rounded:".turn{border-radius:18px;padding:10px 15px}",tailed:".turn.agent,.turn.ai{border-radius:12px 12px 12px 4px}.turn.end_user{border-radius:12px 12px 4px 12px}"},He={filled:"",outlined:".turn{background:none;border:1px solid var(--hairline)}.turn.end_user{background:none;border-color:var(--a);color:var(--ink)}"},Re={above:"",hidden:".turn.agent .author,.turn.ai .author:not(.ai){display:none}",inline:".body .author.below{display:block;margin:4px 0 0;font-size:11.5px;font-weight:500;color:var(--ink-2);text-transform:none;letter-spacing:0;opacity:1}"},Oe=".turn.agent,.turn.ai{display:flex;gap:10px;max-width:100%;background:none;padding:0}.turn .body{background:var(--fill);padding:9px 13px;border-radius:inherit}.author{text-transform:none;letter-spacing:0;font-size:12.5px;font-weight:600;opacity:1}",$e='.divider{display:flex;align-items:center;gap:10px;margin:0;font-size:11px;opacity:.6}.divider:before,.divider:after{content:"";flex:1;height:1px;background:var(--hairline)}',ze={beside_name:".stamp{font-size:11px;opacity:.7;margin-left:6px}",none:"",under_turn:".stamp{display:block;font-size:11px;opacity:.7;margin-top:4px}.turn.end_user .stamp{text-align:right}"},Ke=".lat{font-size:11px;opacity:.7;margin-left:6px}";function De(n){let e=H(n),t=n.launcherPosition==="bottom_left"?"left":"right",r=n.accentColor;return `${`
|
|
1
|
+
(function(){'use strict';var te=Object.defineProperty;var ne=(n,e,t)=>e in n?te(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t;var u=(n,e,t)=>ne(n,typeof e!="symbol"?e+"":e,t);function L(n){if(n)return n;let e=globalThis.fetch;if(typeof e=="function")return e.bind(globalThis)}function _(n){return n.replace(/\/+$/,"")}var re="X-Prodantix-Conversation-Token",M="prodantix.chat.handle";function ie(){let n=globalThis.localStorage;if(n)return {get:e=>n.getItem(e),remove:e=>n.removeItem(e),set:(e,t)=>n.setItem(e,t)}}var N=class{constructor(e){this.options=e;u(this,"fetchImpl");u(this,"host");u(this,"storage");u(this,"handle");u(this,"identity",null);var t;this.fetchImpl=L(e.fetchImpl),this.host=_(e.host),this.storage=(t=e.storage)!=null?t:ie(),this.handle=this.readHandle();}get hasThread(){return this.handle!==null}avatarUrl(e){return e.startsWith("/")?`${this.host}${e}?api_key=${encodeURIComponent(this.options.apiKey)}`:e}get socketAuth(){return this.handle?{conversationId:this.handle.conversationId,conversationToken:this.handle.token,projectKey:this.options.apiKey}:null}identify(e){this.identity=e;}async ensureThread(e){var r,i,a;if(this.handle)return true;let t=await this.request("POST","/v1/conversations",{body:{distinctId:this.options.distinctId,subject:e,userHash:(r=this.identity)==null?void 0:r.userHash,userId:(i=this.identity)==null?void 0:i.userId}});return !(t!=null&&t.conversationId)||!t.token?false:(this.handle={conversationId:t.conversationId,token:t.token},(a=this.storage)==null||a.set(M,JSON.stringify(this.handle)),true)}async send(e,t){var a;if(!await this.ensureThread())return null;let r=this.handle;if(!r)return null;let i=await this.request("POST",`/v1/conversations/${encodeURIComponent(r.conversationId)}/turns`,{body:{body:e,pageContext:t},token:r.token});return (a=i==null?void 0:i.turn)!=null?a:null}async load(){let e=this.handle;return e?this.request("GET",`/v1/conversations/${encodeURIComponent(e.conversationId)}`,{token:e.token}):null}readHandle(){var t,r;let e=(t=this.storage)==null?void 0:t.get(M);if(!e)return null;try{let i=JSON.parse(e);if(typeof i.conversationId=="string"&&typeof i.token=="string")return {conversationId:i.conversationId,token:i.token}}catch(i){}return (r=this.storage)==null||r.remove(M),null}async request(e,t,r={}){var o,s,p,l,c,d;let i=this.fetchImpl;if(!i)return (s=(o=this.options).onError)==null||s.call(o,new Error("no fetch available for prodantix chat")),null;let a={authorization:`Bearer ${this.options.apiKey}`,"content-type":"application/json"};r.token&&(a[re]=r.token);try{let h=await i(`${this.host}${t}`,{body:r.body===void 0?void 0:JSON.stringify(r.body),headers:a,method:e}),g=await h.text();return h.ok?g?JSON.parse(g):{}:((l=(p=this.options).onError)==null||l.call(p,new Error(`prodantix chat ${t}: ${h.status}`)),null)}catch(h){return (d=(c=this.options).onError)==null||d.call(c,h),null}}};var ae={Fri:"fri",Mon:"mon",Sat:"sat",Sun:"sun",Thu:"thu",Tue:"tue",Wed:"wed"};function P(n,e){var s,p,l,c,d,h;let t=new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:false,minute:"2-digit",timeZone:n.timezone,weekday:"short"}).formatToParts(e),r=ae[(p=(s=t.find(g=>g.type==="weekday"))==null?void 0:s.value)!=null?p:""];if(!r)return false;let i=(c=(l=t.find(g=>g.type==="hour"))==null?void 0:l.value)!=null?c:"",a=(h=(d=t.find(g=>g.type==="minute"))==null?void 0:d.value)!=null?h:"",o=`${i}:${a}`;return n.windows.some(g=>g.days.includes(r)&&g.open<=o&&o<g.close)}var b={bubbleFill:"filled",bubbleShape:"tailed",composerShape:"round",dayDividers:true,launcherContent:"glyph",launcherFill:"outlined",launcherShape:"circle",launcherSize:"small",nameAvatar:true,namePlacement:"hidden",skin:"standard",stampContent:"time",stampPlacement:"none"},oe=["quiet","standard"],se=["round","square"],le=["rounded","tailed"],ce=["filled","outlined"],de=["circle","pill","squircle"],pe=["filled","outlined"],ue=["avatar","glyph","team_faces"],he=["large","medium","small"],ge=["above","hidden","inline"],me=["beside_name","none","under_turn"],fe=["time","time_and_latency"],y=(n,e,t)=>typeof n=="string"&&e.includes(n)?n:t,D=(n,e)=>typeof n=="boolean"?n:e,be={avatar_circle:["circle","outlined","avatar","large"],circle_filled:["circle","filled","glyph","medium"],circle_outlined:["circle","outlined","glyph","small"],pill_labelled:["pill","filled","glyph","medium"],pill_team:["pill","outlined","team_faces","medium"],squircle_filled:["squircle","filled","glyph","medium"]},ye={above:["above",false],avatar_only:["hidden",true],gutter:["above",true],hidden:["hidden",false],inline:["inline",false]},xe={cluster:[true,"none","time"],latency:[false,"beside_name","time_and_latency"],none:[false,"none","time"],trailing:[false,"under_turn","time"],with_name:[false,"beside_name","time"]},ve={concierge:["standard","round"],console:["standard","square"],quiet:["quiet","square"]},Se={hairline:["rounded","outlined"],outlined:["rounded","outlined"],rounded:["rounded","filled"],tailed:["tailed","filled"]};function H(n){var g,S,C,x,m,v,k,T,f,E,z,U,K;let e=typeof n=="object"&&n!==null?n:{},t=typeof e.launcherStyle=="string"?e.launcherStyle:void 0,r=t===void 0?void 0:be[t],i=typeof e.namePlacement=="string"?e.namePlacement:void 0,a=i===void 0?void 0:ye[i],o=typeof e.timestampStyle=="string"?e.timestampStyle:void 0,s=o===void 0?void 0:xe[o],p=typeof e.skin=="string"?e.skin:void 0,l=p===void 0?void 0:ve[p],c=typeof e.bubbleStyle=="string"?e.bubbleStyle:void 0,d=c===void 0?void 0:Se[c],h={bubbleFill:y(e.bubbleFill,ce,(g=d==null?void 0:d[1])!=null?g:b.bubbleFill),bubbleShape:y(e.bubbleShape,le,(S=d==null?void 0:d[0])!=null?S:b.bubbleShape),composerShape:y(e.composerShape,se,(C=l==null?void 0:l[1])!=null?C:b.composerShape),dayDividers:D(e.dayDividers,(x=s==null?void 0:s[0])!=null?x:b.dayDividers),launcherContent:y(e.launcherContent,ue,(m=r==null?void 0:r[2])!=null?m:b.launcherContent),launcherFill:y(e.launcherFill,pe,(v=r==null?void 0:r[1])!=null?v:b.launcherFill),launcherShape:y(e.launcherShape,de,(k=r==null?void 0:r[0])!=null?k:b.launcherShape),launcherSize:y(e.launcherSize,he,(T=r==null?void 0:r[3])!=null?T:b.launcherSize),nameAvatar:D(e.nameAvatar,(f=a==null?void 0:a[1])!=null?f:b.nameAvatar),namePlacement:y(e.namePlacement,ge,(E=a==null?void 0:a[0])!=null?E:b.namePlacement),skin:y(e.skin,oe,(z=l==null?void 0:l[0])!=null?z:b.skin),stampContent:y(e.stampContent,fe,(U=s==null?void 0:s[2])!=null?U:b.stampContent),stampPlacement:y(e.stampPlacement,me,(K=s==null?void 0:s[1])!=null?K:b.stampPlacement)};return h.stampPlacement==="beside_name"&&h.namePlacement==="hidden"&&(h.stampPlacement="under_turn"),h}function G(n){var r,i,a,o;let e=n.split(/\s+/).filter(s=>s.length>0);return (e.length>1?`${(r=e[0])==null?void 0:r.slice(0,1)}${(i=e[1])==null?void 0:i.slice(0,1)}`:(o=(a=e[0])==null?void 0:a.slice(0,2))!=null?o:"").toUpperCase()}var Ce="M20 11.6a7.4 7.4 0 0 1-7.4 7.4H8.2L4 21.8l1-4.1A7.4 7.4 0 1 1 20 11.6Z",ke={large:66,medium:56,small:46},Ee={circle:"width:var(--fab-size);height:var(--fab-size);border-radius:calc(var(--fab-size) / 2);",pill:"width:auto;height:var(--fab-size);border-radius:calc(var(--fab-size) / 2);padding:0 22px;gap:10px;",squircle:"width:var(--fab-size);height:var(--fab-size);border-radius:16px;"},Te={filled:"background:var(--a);color:#fff;",outlined:"background:var(--paper);border:1px solid var(--hairline);color:var(--ink-2);box-shadow:0 1px 2px rgba(0,0,0,.08);"},Ae={avatar:"",glyph:".launcher svg{width:calc(var(--fab-size) * 0.375);height:calc(var(--fab-size) * 0.375);}",team_faces:".launcher .faces{display:flex;}.launcher .faces .av{box-shadow:0 0 0 2px var(--paper);}.launcher .faces .av+.av{margin-left:-10px;}"},we=".launcher .live{width:10px;height:10px;position:absolute;right:3px;bottom:3px;border-radius:50%;background:var(--online);box-shadow:0 0 0 2px var(--paper);}.launcher.closed .live{display:none}",Le={circle:"",pill:".badge{position:static;box-shadow:none}",squircle:""},_e={filled:"",outlined:".badge{background:var(--a);top:-7px;right:-7px;min-width:19px;height:19px;font-size:11.5px}"},Ne={circle:"",pill:".launcher .label{font-size:14px;font-weight:600;white-space:nowrap;}",squircle:""},Pe={circle:"",pill:"@media (max-width:480px){.launcher{width:var(--fab-size);padding:0}.launcher .label{display:none}}",squircle:""};function q(n,e,t,r){return `.launcher{--fab-size:${ke[r]}px;${Ee[n]}${Te[e]}}${Ae[t]}${we}${Le[n]}${_e[e]}${Ne[n]}${Pe[n]}`}function W(n,e,t,r=i=>i){let i=document.createDocumentFragment();if(n==="glyph"){let s=document.createElement("span");return s.innerHTML=`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${Ce}"/></svg>`,i.append(...s.childNodes,R()),i}if(n==="avatar")return i.append(B(t[0],e,r),R()),i;let a=document.createElement("span");a.className="faces";let o=t.length>0?t.slice(0,2):[void 0];for(let s of o)a.append(B(s,e,r));return i.append(a,R()),i}function B(n,e,t){let r=document.createElement("span");if(r.className="av",r.setAttribute("aria-hidden","true"),n&&(r.style.background=n.tone),n!=null&&n.avatarUrl){let i=document.createElement("img");return i.alt="",i.src=t(n.avatarUrl),r.append(i),r}return r.textContent=n?n.initials:e.agentLabel.slice(0,2).toUpperCase(),r}function R(){let n=document.createElement("span");return n.className="live",n.setAttribute("aria-hidden","true"),n}var Ie={agentLabel:"Agent",aiLabel:"AI",closeLabel:"Close chat",emptyBody:"We usually reply within a few minutes.",emptyTitle:"Ask us anything.",inputPlaceholder:"Type a message",launcherLabel:"Open support chat",sendLabel:"Send",timeLabel:n=>{let e=new Date(n);return Number.isNaN(e.getTime())?"":`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`},title:"Support",unreadLabel:n=>`${n} unread`},A={accentColor:"#5b5bff",availability:{timezone:"UTC",windows:[]},awayMessage:"",greeting:"",launcherOffsetX:20,launcherOffsetY:20,launcherPosition:"bottom_right",starterPrompts:[],team:[],teamFaces:[],...b};function Fe(n){return n.team.length>0?n.team:n.teamFaces}var Me={quiet:".composer{position:relative;padding:10px 12px 12px}.composer input{padding-right:42px}.composer button{position:absolute;top:50%;right:16px;width:34px;min-width:34px;height:34px;padding:0;background:transparent;color:var(--ink);border-radius:7px;transform:translateY(-50%)}.composer button .sendglyph{display:block;width:18px;height:18px}.composer button .sendtext{display:none}.panel{border-radius:8px;box-shadow:0 2px 8px rgba(0,0,0,.12)}.header{background:var(--paper);color:var(--ink);height:44px;padding:0 8px 0 16px;border-bottom:1px solid var(--hairline)}.header h2{font-size:11px;letter-spacing:.11em;text-transform:uppercase;color:var(--ink-3)}.close{color:var(--ink-2)}",standard:".panel{border-radius:16px;box-shadow:0 16px 40px rgba(0,0,0,.2)}.header{background:var(--a);color:#fff;flex-direction:column;align-items:flex-start;gap:14px;padding:18px 14px 20px 20px}.header h2{font-size:19px;font-weight:640}"},He={round:".composer{padding:12px 12px 14px;gap:8px}.composer input{height:46px;border-radius:23px;padding:0 16px}.composer button{width:46px;min-width:46px;height:46px;padding:0;border-radius:23px}.composer button .sendglyph{display:block}.composer button .sendtext{display:none}",square:".composer input{height:44px;border-radius:8px;padding:0 12px}"},Re={rounded:".turn{border-radius:18px;padding:10px 15px}",tailed:".turn.agent,.turn.ai{border-radius:12px 12px 12px 4px}.turn.end_user{border-radius:12px 12px 4px 12px}"},Oe={filled:"",outlined:".turn{background:none;border:1px solid var(--hairline)}.turn.end_user{background:none;border-color:var(--a);color:var(--ink)}"},$e={above:"",hidden:".turn.agent .author,.turn.ai .author:not(.ai){display:none}",inline:".body .author.below{display:block;margin:4px 0 0;font-size:11.5px;font-weight:500;color:var(--ink-2);text-transform:none;letter-spacing:0;opacity:1}"},ze=".turn.agent,.turn.ai{display:flex;gap:10px;max-width:100%;background:none;padding:0}.turn .body{background:var(--fill);padding:9px 13px;border-radius:inherit}.author{text-transform:none;letter-spacing:0;font-size:12.5px;font-weight:600;opacity:1}",Ue='.divider{display:flex;align-items:center;gap:10px;margin:0;font-size:11px;opacity:.6}.divider:before,.divider:after{content:"";flex:1;height:1px;background:var(--hairline)}',Ke={beside_name:".stamp{font-size:11px;opacity:.7;margin-left:6px}",none:"",under_turn:".stamp{display:block;font-size:11px;opacity:.7;margin-top:4px}.turn.end_user .stamp{text-align:right}"},De=".lat{font-size:11px;opacity:.7;margin-left:6px}";function Be(n){let e=H(n),t=n.launcherPosition==="bottom_left"?"left":"right",r=n.accentColor;return `${`
|
|
2
2
|
:host {
|
|
3
3
|
all: initial; --a: ${r};
|
|
4
4
|
--paper: #fff; --ink: #0f172a; --ink-3: var(--ink-3);
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
.prompt:focus-visible { outline: 2px solid ${r}; outline-offset: 2px; }
|
|
55
55
|
.av { width: 30px; height: 30px; border-radius: 50%; flex: none; display: inline-flex; align-items: center; justify-content: center; font-size: 11.5px; font-weight: 650; color: #fff; background: #7c3f3f; }
|
|
56
56
|
.av.bot { border-radius: 9px; background: var(--fill); color: var(--ink); }
|
|
57
|
+
.av img { width: 100%; height: 100%; display: block; object-fit: cover; border-radius: inherit; }
|
|
57
58
|
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--hairline); }
|
|
58
59
|
.composer input { flex: 1; min-width: 0; height: 44px; padding: 0 12px; border: 0; border-radius: 8px; font-size: 14px; background: var(--fill); color: var(--ink); }
|
|
59
60
|
.composer input:focus-visible { outline: 2px solid ${r}; }
|
|
@@ -64,5 +65,5 @@
|
|
|
64
65
|
.panel { animation: rise 180ms ease-out; }
|
|
65
66
|
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
|
|
66
67
|
}
|
|
67
|
-
`}${Fe[e.composerShape]}${Ie[e.skin]}${G(e.launcherShape,e.launcherFill,e.launcherContent,e.launcherSize)}${Me[e.bubbleShape]}${He[e.bubbleFill]}${Re[e.namePlacement]}${e.nameAvatar?Oe:""}${e.dayDividers?$e:""}${ze[e.stampPlacement]}${e.stampContent==="time_and_latency"?Ke:""}`}var Be=["end_user","agent","ai"];function Ue(){let n=globalThis.location;if(n)return {host:n.host,path:n.pathname,title:document.title}}var I=class{constructor(e,t,r={},i={}){this.host=e;this.client=t;u(this,"root");u(this,"strings");u(this,"settings");u(this,"appearance");u(this,"launcher");u(this,"badge");u(this,"panel",null);u(this,"lastFocused",null);u(this,"unread",0);this.strings={...Ne,...r},this.appearance={...A,...i},this.settings=H({...A,...i}),this.root=e.attachShadow({mode:"closed"});let a=document.createElement("style");if(a.textContent=De({...A,...i}),this.root.append(a),this.launcher=document.createElement("button"),this.launcher.className="launcher",this.launcher.type="button",this.launcher.setAttribute("aria-haspopup","dialog"),this.launcher.setAttribute("aria-label",this.strings.launcherLabel),this.launcher.append(q(this.settings.launcherContent,this.strings,this.appearance.teamFaces)),this.settings.launcherShape==="pill"){let o=document.createElement("span");o.className="label",o.textContent=this.settings.launcherContent==="team_faces"?this.strings.agentLabel:this.strings.launcherLabel,this.launcher.append(o);}this.launcher.addEventListener("click",()=>this.toggle()),this.badge=document.createElement("span"),this.badge.className="badge",this.badge.hidden=true,this.launcher.append(this.badge),this.root.append(this.launcher);}toggle(){this.panel?this.close():this.open();}setOpenNow(e){this.launcher.classList.toggle("closed",!e);}async open(){if(this.panel)return;this.lastFocused=this.host.ownerDocument.activeElement,this.unread=0,this.renderBadge();let e=document.createElement("section");e.className="panel",e.setAttribute("role","dialog"),e.setAttribute("aria-modal","true"),e.setAttribute("aria-label",this.strings.title);let t=document.createElement("div");t.className="header";let r=document.createElement("h2");r.textContent=this.strings.title;let i=document.createElement("button");i.className="close",i.type="button",i.setAttribute("aria-label",this.strings.closeLabel),i.textContent="\xD7",i.addEventListener("click",()=>this.close()),t.append(r,i);let a=document.createElement("div");a.className="log",a.setAttribute("role","log"),a.setAttribute("aria-live","polite"),a.setAttribute("aria-label",this.strings.title);let o=document.createElement("form");o.className="composer";let s=document.createElement("input");s.type="text",s.setAttribute("aria-label",this.strings.inputPlaceholder),s.placeholder=this.strings.inputPlaceholder;let p=document.createElement("button");p.type="submit",p.setAttribute("aria-label",this.strings.sendLabel),p.innerHTML='<svg class="sendglyph" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4.5 12 20 4.5 15 20l-3.6-5.4L4.5 12Z"/></svg>';let l=document.createElement("span");l.className="sendtext",l.textContent=this.strings.sendLabel,p.append(l),o.append(s,p),o.addEventListener("submit",d=>{d.preventDefault(),this.submit(s,a);}),e.append(t,a,o),e.addEventListener("keydown",d=>this.onKeydown(d,e,i)),this.root.append(e),this.panel=e,s.focus();let c=await this.client.load();c&&c.turns.length>0?this.renderThread(a,c):this.renderFirstRun(a,s),!N(this.appearance.availability,new Date)&&this.appearance.awayMessage.trim()&&this.renderAway(a);}renderFirstRun(e,t){let r=document.createElement("div");r.className="empty";let i=document.createElement("h3");i.textContent=this.appearance.greeting.trim()||this.strings.emptyTitle;let a=document.createElement("p");a.textContent=this.strings.emptyBody,r.append(i,a);for(let o of this.appearance.starterPrompts){let s=document.createElement("button");s.className="prompt",s.type="button",s.textContent=o,s.addEventListener("click",()=>{t.value=o,this.submit(t,e);}),r.append(s);}e.replaceChildren(r);}renderAway(e){let t=document.createElement("div");t.className="away",t.textContent=this.appearance.awayMessage,e.prepend(t);}close(){this.panel&&(this.panel.remove(),this.panel=null,this.lastFocused instanceof HTMLElement?this.lastFocused.focus():this.launcher.focus());}onIncomingTurn(e){if(this.panel){let t=this.panel.querySelector(".log");t instanceof HTMLElement&&this.appendTurn(t,e);return}e.authorKind!=="end_user"&&(this.unread+=1,this.renderBadge());}async submit(e,t){var a;let r=e.value.trim();if(!r)return;e.value="",(a=t.querySelector(".empty"))==null||a.remove();let i=await this.client.send(r,Ue());i&&this.appendTurn(t,i);}renderThread(e,t){e.replaceChildren();for(let r of t.turns)this.appendTurn(e,r);}appendTurn(e,t){var c;(c=e.querySelector(".empty"))==null||c.remove();let r=Be.includes(t.authorKind)?t.authorKind:"agent",i=this.settings,a=document.createElement("div");if(a.className=`turn ${r}`,r!=="end_user"&&i.nameAvatar){let d=document.createElement("span");d.className=r==="ai"?"av bot":"av",d.textContent=r==="ai"?this.strings.aiLabel:this.strings.agentLabel.slice(0,2).toUpperCase(),d.setAttribute("aria-hidden","true"),a.append(d);}let s=document.createElement("div");s.className="body";let p=r!=="end_user"&&i.namePlacement!=="hidden",l=document.createElement("div");if(l.textContent=t.body,p||r==="ai"&&i.namePlacement==="hidden"){let d=document.createElement("div");d.className=r==="ai"?"author ai":"author",d.textContent=r==="ai"?this.strings.aiLabel:this.strings.agentLabel,i.stampPlacement==="beside_name"&&d.append(this.stamp(t)),i.namePlacement==="inline"?(d.classList.add("below"),s.append(l,d)):s.append(d,l);}else s.append(l);i.stampPlacement==="under_turn"&&s.append(this.stamp(t)),a.append(s),e.append(a),e.scrollTop=e.scrollHeight;}stamp(e){let t=document.createElement("span");return t.className="stamp",t.textContent=this.strings.timeLabel(e.createdAt),t}onKeydown(e,t,r){if(e.key==="Escape"){e.preventDefault(),this.close();return}if(e.key!=="Tab")return;let i=t.querySelectorAll('button, input, [tabindex]:not([tabindex="-1"])');if(i.length===0)return;let a=i[0],o=i[i.length-1],s=this.root.activeElement;e.shiftKey&&s===a?(e.preventDefault(),o.focus()):!e.shiftKey&&s===o?(e.preventDefault(),a.focus()):s===null&&(e.preventDefault(),r.focus());}renderBadge(){this.unread>0?(this.badge.hidden=false,this.badge.textContent=String(this.unread),this.launcher.setAttribute("aria-label",`${this.strings.launcherLabel}, ${this.strings.unreadLabel(this.unread)}`)):(this.badge.hidden=true,this.badge.textContent="",this.launcher.setAttribute("aria-label",this.strings.launcherLabel));}};function W(n){return `40${JSON.stringify(n)}`}function Y(){return "3"}function j(n){let e=n.charAt(0),t=n.slice(1);if(e==="2")return {kind:"ping"};if(e==="1")return {kind:"disconnect"};if(e==="0"){let o=O(t);return {kind:"open",pingInterval:typeof(o==null?void 0:o.pingInterval)=="number"?o.pingInterval:25e3,pingTimeout:typeof(o==null?void 0:o.pingTimeout)=="number"?o.pingTimeout:2e4}}if(e!=="4")return {kind:"other"};let r=t.charAt(0),i=t.slice(1);if(r==="0")return {kind:"connected"};if(r==="1")return {kind:"disconnect"};if(r==="4"){let o=O(i);return {kind:"connectError",message:typeof(o==null?void 0:o.message)=="string"?o.message:"refused"}}if(r!=="2")return {kind:"other"};let a=O(i);return !Array.isArray(a)||typeof a[0]!="string"?{kind:"other"}:{kind:"event",name:a[0],payload:a[1]}}function O(n){try{return JSON.parse(n)}catch(e){return null}}var Ge="/socket.io/?EIO=4&transport=websocket",F=class{constructor(e){this.options=e;u(this,"socket",null);u(this,"heartbeat",null);u(this,"ready",false);u(this,"closed",false);u(this,"heartbeatWindow",45e3);u(this,"factory");u(this,"setTimer");u(this,"clearTimer");var t,r,i;this.factory=(t=e.socketFactory)!=null?t:qe,this.setTimer=(r=e.setTimer)!=null?r:((a,o)=>setTimeout(a,o)),this.clearTimer=(i=e.clearTimer)!=null?i:(a=>clearTimeout(a));}open(){if(this.socket||this.closed)return;let e=`${this.options.host.replace(/^http/,"ws").replace(/\/+$/,"")}${Ge}`,t;try{t=this.factory(e);}catch(r){this.options.onClosed(false);return}this.socket=t,t.onmessage=r=>this.receive(String(r.data)),t.onerror=()=>t.close(),t.onclose=()=>this.fell();}close(){this.closed=true,this.stopHeartbeat();let e=this.socket;this.socket=null,e==null||e.close();}receive(e){var r,i,a,o;let t=j(e);if(t.kind==="open"){this.armHeartbeat(t.pingInterval+t.pingTimeout),(r=this.socket)==null||r.send(W(this.options.auth));return}if(t.kind==="ping"){this.armHeartbeat(),(i=this.socket)==null||i.send(Y());return}if(t.kind==="connectError"||t.kind==="disconnect"){this.stopHeartbeat(),(a=this.socket)==null||a.close();return}if(t.kind==="event"){if(t.name==="ready"){this.ready=true,this.options.onReady();return}if(t.name==="conversation.turn"){let s=(o=t.payload)==null?void 0:o.turn;s&&this.options.onTurn(s);}}}fell(){this.stopHeartbeat();let e=this.ready;this.socket=null,this.ready=false,this.closed||this.options.onClosed(e);}armHeartbeat(e){e!==void 0&&(this.heartbeatWindow=e),this.stopHeartbeat(),this.heartbeat=this.setTimer(()=>{var t;return (t=this.socket)==null?void 0:t.close()},this.heartbeatWindow);}stopHeartbeat(){this.heartbeat!==null&&this.clearTimer(this.heartbeat),this.heartbeat=null;}};function qe(n){let e=globalThis.WebSocket;if(!e)throw new Error("no WebSocket");return new e(n)}var We=6e4;function J(n){var m,S,k,T;let e=globalThis.document;if(!e)throw new Error("prodantix chat requires a document; mount it in the browser");let t=(m=n.mountPoint)!=null?m:e.createElement("div");n.mountPoint||e.body.append(t);let r=new P(n),i=new I(t,r,n.strings,n.appearance),a=(k=(S=n.appearance)==null?void 0:S.availability)!=null?k:A.availability,o,s=()=>{i.setOpenNow(N(a,new Date)),o=setTimeout(s,We);};s();let p=new Set,l,c=null,d=(T=n.pollIntervalMs)!=null?T:15e3,g=f=>{p.has(f.id)||f.authorKind==="end_user"||(p.add(f.id),i.onIncomingTurn(f));},h=async()=>{if(!r.hasThread)return;let f=await r.load();if(f){for(let E of f.turns)g(E);p=new Set(f.turns.map(E=>E.id));}},v=()=>{l||d<=0||(l=setInterval(()=>void h(),d));},C=()=>{l&&clearInterval(l),l=void 0;},x=()=>{if(c||!n.socketHost)return;let f=r.socketAuth;f&&(c=new F({auth:f,host:n.socketHost,onClosed:E=>{c=null,v(),E&&x();},onReady:C,onTurn:g,socketFactory:n.socketFactory}),c.open());};return v(),x(),{close:()=>i.close(),destroy:()=>{C(),clearTimeout(o),c==null||c.close(),c=null,i.close(),t.remove();},identify:f=>r.identify(f),open:()=>{i.open().then(x);}}}var $="prodantix.messenger.config";function X(n,e){let t=n==null?void 0:n.get($);if(!t)return null;try{let r=JSON.parse(t);return (r==null?void 0:r.apiKey)===e?r.config:null}catch(r){return null}}async function V(n){var i,a,o,s,p;let e=L(n.fetchImpl);if(!e)return (i=n.onError)==null||i.call(n,new Error("no fetch available for the prodantix messenger")),null;let t=_(n.host),r=n.locale?`?locale=${encodeURIComponent(n.locale)}`:"";try{let l=await e(`${t}/v1/messenger/config${r}`,{headers:{authorization:`Bearer ${n.apiKey}`},method:"GET"});if(!l.ok)return (a=n.onError)==null||a.call(n,new Error(`prodantix messenger config: ${l.status}`)),null;let c=JSON.parse(await l.text());return c.enabled?((s=n.storage)==null||s.set($,JSON.stringify({apiKey:n.apiKey,config:c})),c):((o=n.storage)==null||o.remove($),c)}catch(l){return (p=n.onError)==null||p.call(n,l),null}}var Ye=["close","identify","open","shutdown","toggle"],w="[prodantix/messenger]";function je(n,e){for(let t of n){let[r,...i]=t!=null?t:[];typeof r!="string"||!Ye.includes(r)||e(r,...i);}}function Je(n){if(!n)return null;try{return new URL(n).origin}catch(e){return null}}async function Z(n,e={}){var g,h,v,C,x;let t=(g=e.warn)!=null?g:(m=>console.warn(m)),r=n.prodantix,i=r==null?void 0:r.k;if(!i)return t(`${w} no project key on the install snippet; nothing will load.`),null;let a=Je((h=e.scriptSrc)!=null?h:Xe(n));if(!a)return t(`${w} could not tell which host served this script; nothing will load.`),null;let o=Ve(n),s=X(o,i),p=await V({apiKey:i,host:a,locale:((C=(v=n.document)==null?void 0:v.documentElement)==null?void 0:C.lang)||void 0,onError:m=>t(`${w} settings could not be read: ${String(m)}`),storage:o}),l=p!=null?p:s;if(!l)return t(`${w} no settings available; the messenger will not render.`),null;if(!l.enabled)return null;let c=J({apiKey:i,appearance:l,distinctId:Ze(n,o),host:a,socketHost:l.socketUrl||void 0}),d=(m,...S)=>{if((m==="open"||m==="toggle")&&c.open(),m==="close"&&c.close(),m==="shutdown"&&c.destroy(),m==="identify"){let k=Qe(S[0]);if(!k){console.error(`${w} identify needs { userId, userHash }: the hash is HMAC-SHA256 of the user id under the project signing secret, computed on your server. Without it the visitor stays anonymous.`);return}c.identify(k);}};return je((x=r==null?void 0:r.q)!=null?x:[],d),n.prodantix=Object.assign((m,...S)=>d(m,...S),{k:i,q:[]}),c}function Xe(n){var t;let e=(t=n.document)==null?void 0:t.currentScript;return e==null?void 0:e.src}function Ve(n){let e=n.localStorage;if(e)return {get:t=>e.getItem(t),remove:t=>e.removeItem(t),set:(t,r)=>e.setItem(t,r)}}function Qe(n){if(typeof n!="object"||n===null)return null;let{userHash:e,userId:t}=n;return typeof t!="string"||typeof e!="string"||t.trim()===""||e.trim()===""?null:{userHash:e,userId:t}}var Q="prodantix.messenger.anon";function Ze(n,e){var i,a,o;let t=e==null?void 0:e.get(Q);if(t)return t;let r=`anon_${(o=(a=(i=n.crypto)==null?void 0:i.randomUUID)==null?void 0:a.call(i))!=null?o:Math.random().toString(36).slice(2)}`;return e==null||e.set(Q,r),r}Z(globalThis);})();//# sourceMappingURL=messenger.iife.js.map
|
|
68
|
+
`}${He[e.composerShape]}${Me[e.skin]}${q(e.launcherShape,e.launcherFill,e.launcherContent,e.launcherSize)}${Re[e.bubbleShape]}${Oe[e.bubbleFill]}${$e[e.namePlacement]}${e.nameAvatar?ze:""}${e.dayDividers?Ue:""}${Ke[e.stampPlacement]}${e.stampContent==="time_and_latency"?De:""}`}var Ge=["end_user","agent","ai"];function qe(){let n=globalThis.location;if(n)return {host:n.host,path:n.pathname,title:document.title}}var I=class{constructor(e,t,r={},i={}){this.host=e;this.client=t;u(this,"root");u(this,"strings");u(this,"settings");u(this,"appearance");u(this,"launcher");u(this,"badge");u(this,"panel",null);u(this,"lastFocused",null);u(this,"unread",0);this.strings={...Ie,...r},this.appearance={...A,...i},this.settings=H({...A,...i}),this.root=e.attachShadow({mode:"closed"});let a=document.createElement("style");if(a.textContent=Be({...A,...i}),this.root.append(a),this.launcher=document.createElement("button"),this.launcher.className="launcher",this.launcher.type="button",this.launcher.setAttribute("aria-haspopup","dialog"),this.launcher.setAttribute("aria-label",this.strings.launcherLabel),this.launcher.append(W(this.settings.launcherContent,this.strings,Fe(this.appearance),o=>this.client.avatarUrl(o))),this.settings.launcherShape==="pill"){let o=document.createElement("span");o.className="label",o.textContent=this.settings.launcherContent==="team_faces"?this.strings.agentLabel:this.strings.launcherLabel,this.launcher.append(o);}this.launcher.addEventListener("click",()=>this.toggle()),this.badge=document.createElement("span"),this.badge.className="badge",this.badge.hidden=true,this.launcher.append(this.badge),this.root.append(this.launcher);}toggle(){this.panel?this.close():this.open();}setOpenNow(e){this.launcher.classList.toggle("closed",!e);}async open(){if(this.panel)return;this.lastFocused=this.host.ownerDocument.activeElement,this.unread=0,this.renderBadge();let e=document.createElement("section");e.className="panel",e.setAttribute("role","dialog"),e.setAttribute("aria-modal","true"),e.setAttribute("aria-label",this.strings.title);let t=document.createElement("div");t.className="header";let r=document.createElement("h2");r.textContent=this.strings.title;let i=document.createElement("button");i.className="close",i.type="button",i.setAttribute("aria-label",this.strings.closeLabel),i.textContent="\xD7",i.addEventListener("click",()=>this.close()),t.append(r,i);let a=document.createElement("div");a.className="log",a.setAttribute("role","log"),a.setAttribute("aria-live","polite"),a.setAttribute("aria-label",this.strings.title);let o=document.createElement("form");o.className="composer";let s=document.createElement("input");s.type="text",s.setAttribute("aria-label",this.strings.inputPlaceholder),s.placeholder=this.strings.inputPlaceholder;let p=document.createElement("button");p.type="submit",p.setAttribute("aria-label",this.strings.sendLabel),p.innerHTML='<svg class="sendglyph" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4.5 12 20 4.5 15 20l-3.6-5.4L4.5 12Z"/></svg>';let l=document.createElement("span");l.className="sendtext",l.textContent=this.strings.sendLabel,p.append(l),o.append(s,p),o.addEventListener("submit",d=>{d.preventDefault(),this.submit(s,a);}),e.append(t,a,o),e.addEventListener("keydown",d=>this.onKeydown(d,e,i)),this.root.append(e),this.panel=e,s.focus();let c=await this.client.load();c&&c.turns.length>0?this.renderThread(a,c):this.renderFirstRun(a,s),!P(this.appearance.availability,new Date)&&this.appearance.awayMessage.trim()&&this.renderAway(a);}renderFirstRun(e,t){let r=document.createElement("div");r.className="empty";let i=document.createElement("h3");i.textContent=this.appearance.greeting.trim()||this.strings.emptyTitle;let a=document.createElement("p");a.textContent=this.strings.emptyBody,r.append(i,a);for(let o of this.appearance.starterPrompts){let s=document.createElement("button");s.className="prompt",s.type="button",s.textContent=o,s.addEventListener("click",()=>{t.value=o,this.submit(t,e);}),r.append(s);}e.replaceChildren(r);}renderAway(e){let t=document.createElement("div");t.className="away",t.textContent=this.appearance.awayMessage,e.prepend(t);}close(){this.panel&&(this.panel.remove(),this.panel=null,this.lastFocused instanceof HTMLElement?this.lastFocused.focus():this.launcher.focus());}onIncomingTurn(e){if(this.panel){let t=this.panel.querySelector(".log");t instanceof HTMLElement&&this.appendTurn(t,e);return}e.authorKind!=="end_user"&&(this.unread+=1,this.renderBadge());}async submit(e,t){var a;let r=e.value.trim();if(!r)return;e.value="",(a=t.querySelector(".empty"))==null||a.remove();let i=await this.client.send(r,qe());i&&this.appendTurn(t,i);}renderThread(e,t){e.replaceChildren();for(let r of t.turns)this.appendTurn(e,r);}appendTurn(e,t){var c;(c=e.querySelector(".empty"))==null||c.remove();let r=Ge.includes(t.authorKind)?t.authorKind:"agent",i=this.settings,a=document.createElement("div");if(a.className=`turn ${r}`,r!=="end_user"&&i.nameAvatar){let d=document.createElement("span");if(d.className=r==="ai"?"av bot":"av",d.setAttribute("aria-hidden","true"),r==="agent"&&t.authorAvatarUrl){let h=document.createElement("img");h.alt="",h.src=this.client.avatarUrl(t.authorAvatarUrl),d.append(h);}else d.textContent=r==="ai"?this.strings.aiLabel:G(this.agentName(t));a.append(d);}let s=document.createElement("div");s.className="body";let p=r!=="end_user"&&i.namePlacement!=="hidden",l=document.createElement("div");if(l.textContent=t.body,p||r==="ai"&&i.namePlacement==="hidden"){let d=document.createElement("div");d.className=r==="ai"?"author ai":"author",d.textContent=r==="ai"?this.strings.aiLabel:this.agentName(t),i.stampPlacement==="beside_name"&&d.append(this.stamp(t)),i.namePlacement==="inline"?(d.classList.add("below"),s.append(l,d)):s.append(d,l);}else s.append(l);i.stampPlacement==="under_turn"&&s.append(this.stamp(t)),a.append(s),e.append(a),e.scrollTop=e.scrollHeight;}agentName(e){return e.authorName||this.strings.agentLabel}stamp(e){let t=document.createElement("span");return t.className="stamp",t.textContent=this.strings.timeLabel(e.createdAt),t}onKeydown(e,t,r){if(e.key==="Escape"){e.preventDefault(),this.close();return}if(e.key!=="Tab")return;let i=t.querySelectorAll('button, input, [tabindex]:not([tabindex="-1"])');if(i.length===0)return;let a=i[0],o=i[i.length-1],s=this.root.activeElement;e.shiftKey&&s===a?(e.preventDefault(),o.focus()):!e.shiftKey&&s===o?(e.preventDefault(),a.focus()):s===null&&(e.preventDefault(),r.focus());}renderBadge(){this.unread>0?(this.badge.hidden=false,this.badge.textContent=String(this.unread),this.launcher.setAttribute("aria-label",`${this.strings.launcherLabel}, ${this.strings.unreadLabel(this.unread)}`)):(this.badge.hidden=true,this.badge.textContent="",this.launcher.setAttribute("aria-label",this.strings.launcherLabel));}};function Y(n){return `40${JSON.stringify(n)}`}function j(){return "3"}function J(n){let e=n.charAt(0),t=n.slice(1);if(e==="2")return {kind:"ping"};if(e==="1")return {kind:"disconnect"};if(e==="0"){let o=O(t);return {kind:"open",pingInterval:typeof(o==null?void 0:o.pingInterval)=="number"?o.pingInterval:25e3,pingTimeout:typeof(o==null?void 0:o.pingTimeout)=="number"?o.pingTimeout:2e4}}if(e!=="4")return {kind:"other"};let r=t.charAt(0),i=t.slice(1);if(r==="0")return {kind:"connected"};if(r==="1")return {kind:"disconnect"};if(r==="4"){let o=O(i);return {kind:"connectError",message:typeof(o==null?void 0:o.message)=="string"?o.message:"refused"}}if(r!=="2")return {kind:"other"};let a=O(i);return !Array.isArray(a)||typeof a[0]!="string"?{kind:"other"}:{kind:"event",name:a[0],payload:a[1]}}function O(n){try{return JSON.parse(n)}catch(e){return null}}var We="/socket.io/?EIO=4&transport=websocket",F=class{constructor(e){this.options=e;u(this,"socket",null);u(this,"heartbeat",null);u(this,"ready",false);u(this,"closed",false);u(this,"heartbeatWindow",45e3);u(this,"factory");u(this,"setTimer");u(this,"clearTimer");var t,r,i;this.factory=(t=e.socketFactory)!=null?t:Ye,this.setTimer=(r=e.setTimer)!=null?r:((a,o)=>setTimeout(a,o)),this.clearTimer=(i=e.clearTimer)!=null?i:(a=>clearTimeout(a));}open(){if(this.socket||this.closed)return;let e=`${this.options.host.replace(/^http/,"ws").replace(/\/+$/,"")}${We}`,t;try{t=this.factory(e);}catch(r){this.options.onClosed(false);return}this.socket=t,t.onmessage=r=>this.receive(String(r.data)),t.onerror=()=>t.close(),t.onclose=()=>this.fell();}close(){this.closed=true,this.stopHeartbeat();let e=this.socket;this.socket=null,e==null||e.close();}receive(e){var r,i,a,o;let t=J(e);if(t.kind==="open"){this.armHeartbeat(t.pingInterval+t.pingTimeout),(r=this.socket)==null||r.send(Y(this.options.auth));return}if(t.kind==="ping"){this.armHeartbeat(),(i=this.socket)==null||i.send(j());return}if(t.kind==="connectError"||t.kind==="disconnect"){this.stopHeartbeat(),(a=this.socket)==null||a.close();return}if(t.kind==="event"){if(t.name==="ready"){this.ready=true,this.options.onReady();return}if(t.name==="conversation.turn"){let s=(o=t.payload)==null?void 0:o.turn;s&&this.options.onTurn(s);}}}fell(){this.stopHeartbeat();let e=this.ready;this.socket=null,this.ready=false,this.closed||this.options.onClosed(e);}armHeartbeat(e){e!==void 0&&(this.heartbeatWindow=e),this.stopHeartbeat(),this.heartbeat=this.setTimer(()=>{var t;return (t=this.socket)==null?void 0:t.close()},this.heartbeatWindow);}stopHeartbeat(){this.heartbeat!==null&&this.clearTimer(this.heartbeat),this.heartbeat=null;}};function Ye(n){let e=globalThis.WebSocket;if(!e)throw new Error("no WebSocket");return new e(n)}var je=6e4;function X(n){var m,v,k,T;let e=globalThis.document;if(!e)throw new Error("prodantix chat requires a document; mount it in the browser");let t=(m=n.mountPoint)!=null?m:e.createElement("div");n.mountPoint||e.body.append(t);let r=new N(n),i=new I(t,r,n.strings,n.appearance),a=(k=(v=n.appearance)==null?void 0:v.availability)!=null?k:A.availability,o,s=()=>{i.setOpenNow(P(a,new Date)),o=setTimeout(s,je);};s();let p=new Set,l,c=null,d=(T=n.pollIntervalMs)!=null?T:15e3,h=f=>{p.has(f.id)||f.authorKind==="end_user"||(p.add(f.id),i.onIncomingTurn(f));},g=async()=>{if(!r.hasThread)return;let f=await r.load();if(f){for(let E of f.turns)h(E);p=new Set(f.turns.map(E=>E.id));}},S=()=>{l||d<=0||(l=setInterval(()=>void g(),d));},C=()=>{l&&clearInterval(l),l=void 0;},x=()=>{if(c||!n.socketHost)return;let f=r.socketAuth;f&&(c=new F({auth:f,host:n.socketHost,onClosed:E=>{c=null,S(),E&&x();},onReady:C,onTurn:h,socketFactory:n.socketFactory}),c.open());};return S(),x(),{close:()=>i.close(),destroy:()=>{C(),clearTimeout(o),c==null||c.close(),c=null,i.close(),t.remove();},identify:f=>r.identify(f),open:()=>{i.open().then(x);}}}var $="prodantix.messenger.config";function V(n,e){let t=n==null?void 0:n.get($);if(!t)return null;try{let r=JSON.parse(t);return (r==null?void 0:r.apiKey)===e?r.config:null}catch(r){return null}}async function Q(n){var i,a,o,s,p;let e=L(n.fetchImpl);if(!e)return (i=n.onError)==null||i.call(n,new Error("no fetch available for the prodantix messenger")),null;let t=_(n.host),r=n.locale?`?locale=${encodeURIComponent(n.locale)}`:"";try{let l=await e(`${t}/v1/messenger/config${r}`,{headers:{authorization:`Bearer ${n.apiKey}`},method:"GET"});if(!l.ok)return (a=n.onError)==null||a.call(n,new Error(`prodantix messenger config: ${l.status}`)),null;let c=JSON.parse(await l.text());return c.enabled?((s=n.storage)==null||s.set($,JSON.stringify({apiKey:n.apiKey,config:c})),c):((o=n.storage)==null||o.remove($),c)}catch(l){return (p=n.onError)==null||p.call(n,l),null}}var Je=["close","identify","open","shutdown","toggle"],w="[prodantix/messenger]";function Xe(n,e){for(let t of n){let[r,...i]=t!=null?t:[];typeof r!="string"||!Je.includes(r)||e(r,...i);}}function Ve(n){if(!n)return null;try{return new URL(n).origin}catch(e){return null}}async function ee(n,e={}){var h,g,S,C,x;let t=(h=e.warn)!=null?h:(m=>console.warn(m)),r=n.prodantix,i=r==null?void 0:r.k;if(!i)return t(`${w} no project key on the install snippet; nothing will load.`),null;let a=Ve((g=e.scriptSrc)!=null?g:Qe(n));if(!a)return t(`${w} could not tell which host served this script; nothing will load.`),null;let o=Ze(n),s=V(o,i),p=await Q({apiKey:i,host:a,locale:((C=(S=n.document)==null?void 0:S.documentElement)==null?void 0:C.lang)||void 0,onError:m=>t(`${w} settings could not be read: ${String(m)}`),storage:o}),l=p!=null?p:s;if(!l)return t(`${w} no settings available; the messenger will not render.`),null;if(!l.enabled)return null;let c=X({apiKey:i,appearance:l,distinctId:tt(n,o),host:a,socketHost:l.socketUrl||void 0}),d=(m,...v)=>{if((m==="open"||m==="toggle")&&c.open(),m==="close"&&c.close(),m==="shutdown"&&c.destroy(),m==="identify"){let k=et(v[0]);if(!k){console.error(`${w} identify needs { userId, userHash }: the hash is HMAC-SHA256 of the user id under the project signing secret, computed on your server. Without it the visitor stays anonymous.`);return}c.identify(k);}};return Xe((x=r==null?void 0:r.q)!=null?x:[],d),n.prodantix=Object.assign((m,...v)=>d(m,...v),{k:i,q:[]}),c}function Qe(n){var t;let e=(t=n.document)==null?void 0:t.currentScript;return e==null?void 0:e.src}function Ze(n){let e=n.localStorage;if(e)return {get:t=>e.getItem(t),remove:t=>e.removeItem(t),set:(t,r)=>e.setItem(t,r)}}function et(n){if(typeof n!="object"||n===null)return null;let{userHash:e,userId:t}=n;return typeof t!="string"||typeof e!="string"||t.trim()===""||e.trim()===""?null:{userHash:e,userId:t}}var Z="prodantix.messenger.anon";function tt(n,e){var i,a,o;let t=e==null?void 0:e.get(Z);if(t)return t;let r=`anon_${(o=(a=(i=n.crypto)==null?void 0:i.randomUUID)==null?void 0:a.call(i))!=null?o:Math.random().toString(36).slice(2)}`;return e==null||e.set(Z,r),r}ee(globalThis);})();//# sourceMappingURL=messenger.iife.js.map
|
|
68
69
|
//# sourceMappingURL=messenger.iife.js.map
|
package/package.json
CHANGED