@prodantix/sdk 0.4.2-beta.389 → 0.5.0-beta.395
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 +20 -77
- package/dist/chat.d.cts +15 -5
- package/dist/chat.d.ts +15 -5
- package/dist/chat.js +20 -77
- package/dist/{config-BGZ6cbgG.d.cts → config-CM4nTGof.d.cts} +34 -2
- package/dist/{config-R3BY9rvi.d.ts → config-DJX2zFaa.d.ts} +34 -2
- package/dist/csp.cjs +2 -2
- package/dist/csp.d.cts +2 -1
- package/dist/csp.d.ts +2 -1
- package/dist/csp.js +2 -2
- package/dist/messenger.cjs +1 -1
- package/dist/messenger.d.cts +1 -1
- package/dist/messenger.d.ts +1 -1
- package/dist/messenger.iife.js +18 -75
- package/dist/messenger.js +1 -1
- package/package.json +1 -1
package/dist/messenger.iife.js
CHANGED
|
@@ -1,41 +1,30 @@
|
|
|
1
|
-
(function(){'use strict';var ie=Object.defineProperty;var oe=(n,e,t)=>e in n?ie(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t;var h=(n,e,t)=>oe(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(n){return n.replace(/\/+$/,"")}var se="X-Prodantix-Conversation-Token",F="prodantix.chat.handle";function le(){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;h(this,"fetchImpl");h(this,"host");h(this,"storage");h(this,"handle");h(this,"identity",null);var t;this.fetchImpl=L(e.fetchImpl),this.host=N(e.host),this.storage=(t=e.storage)!=null?t:le(),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,a,i;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:(a=this.identity)==null?void 0:a.userId}});return !(t!=null&&t.conversationId)||!t.token?false:(this.handle={conversationId:t.conversationId,token:t.token},(i=this.storage)==null||i.set(F,JSON.stringify(this.handle)),true)}async send(e,t){var i;if(!await this.ensureThread())return null;let r=this.handle;if(!r)return null;let a=await this.request("POST",`/v1/conversations/${encodeURIComponent(r.conversationId)}/turns`,{body:{body:e,pageContext:t},token:r.token});return (i=a==null?void 0:a.turn)!=null?i: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(F);if(!e)return null;try{let a=JSON.parse(e);if(typeof a.conversationId=="string"&&typeof a.token=="string")return {conversationId:a.conversationId,token:a.token}}catch(a){}return (r=this.storage)==null||r.remove(F),null}async request(e,t,r={}){var o,s,g,l,p,d;let a=this.fetchImpl;if(!a)return (s=(o=this.options).onError)==null||s.call(o,new Error("no fetch available for prodantix chat")),null;let i={authorization:`Bearer ${this.options.apiKey}`,"content-type":"application/json"};r.token&&(i[se]=r.token);try{let u=await a(`${this.host}${t}`,{body:r.body===void 0?void 0:JSON.stringify(r.body),headers:i,method:e}),c=await u.text();return u.ok?c?JSON.parse(c):{}:((l=(g=this.options).onError)==null||l.call(g,new Error(`prodantix chat ${t}: ${u.status}`)),null)}catch(u){return (d=(p=this.options).onError)==null||d.call(p,u),null}}};var ce={Fri:"fri",Mon:"mon",Sat:"sat",Sun:"sun",Thu:"thu",Tue:"tue",Wed:"wed"};function _(n,e){var s,g,l,p,d,u;let t=new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:false,minute:"2-digit",timeZone:n.timezone,weekday:"short"}).formatToParts(e),r=ce[(g=(s=t.find(c=>c.type==="weekday"))==null?void 0:s.value)!=null?g:""];if(!r)return false;let a=(p=(l=t.find(c=>c.type==="hour"))==null?void 0:l.value)!=null?p:"",i=(u=(d=t.find(c=>c.type==="minute"))==null?void 0:d.value)!=null?u:"",o=`${a}:${i}`;return n.windows.some(c=>c.days.includes(r)&&c.open<=o&&o<c.close)}var y={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"},de=["quiet","standard"],pe=["round","square"],he=["rounded","tailed"],ue=["filled","outlined"],ge=["circle","pill","squircle"],me=["filled","outlined"],fe=["avatar","glyph","team_faces"],be=["large","medium","small"],ye=["above","hidden","inline"],xe=["beside_name","none","under_turn"],ve=["time","time_and_latency"],v=(n,e,t)=>typeof n=="string"&&e.includes(n)?n:t,K=(n,e)=>typeof n=="boolean"?n:e,Se={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"]},Ce={above:["above",false],avatar_only:["hidden",true],gutter:["above",true],hidden:["hidden",false],inline:["inline",false]},ke={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"]},Ee={concierge:["standard","round"],console:["standard","square"],quiet:["quiet","square"]},we={hairline:["rounded","outlined"],outlined:["rounded","outlined"],rounded:["rounded","filled"],tailed:["tailed","filled"]};function I(n){var c,f,x,m,S,C,E,w,b,k,z,U,B;let e=typeof n=="object"&&n!==null?n:{},t=typeof e.launcherStyle=="string"?e.launcherStyle:void 0,r=t===void 0?void 0:Se[t],a=typeof e.namePlacement=="string"?e.namePlacement:void 0,i=a===void 0?void 0:Ce[a],o=typeof e.timestampStyle=="string"?e.timestampStyle:void 0,s=o===void 0?void 0:ke[o],g=typeof e.skin=="string"?e.skin:void 0,l=g===void 0?void 0:Ee[g],p=typeof e.bubbleStyle=="string"?e.bubbleStyle:void 0,d=p===void 0?void 0:we[p],u={bubbleFill:v(e.bubbleFill,ue,(c=d==null?void 0:d[1])!=null?c:y.bubbleFill),bubbleShape:v(e.bubbleShape,he,(f=d==null?void 0:d[0])!=null?f:y.bubbleShape),composerShape:v(e.composerShape,pe,(x=l==null?void 0:l[1])!=null?x:y.composerShape),dayDividers:K(e.dayDividers,(m=s==null?void 0:s[0])!=null?m:y.dayDividers),launcherContent:v(e.launcherContent,fe,(S=r==null?void 0:r[2])!=null?S:y.launcherContent),launcherFill:v(e.launcherFill,me,(C=r==null?void 0:r[1])!=null?C:y.launcherFill),launcherShape:v(e.launcherShape,ge,(E=r==null?void 0:r[0])!=null?E:y.launcherShape),launcherSize:v(e.launcherSize,be,(w=r==null?void 0:r[3])!=null?w:y.launcherSize),nameAvatar:K(e.nameAvatar,(b=i==null?void 0:i[1])!=null?b:y.nameAvatar),namePlacement:v(e.namePlacement,ye,(k=i==null?void 0:i[0])!=null?k:y.namePlacement),skin:v(e.skin,de,(z=l==null?void 0:l[0])!=null?z:y.skin),stampContent:v(e.stampContent,ve,(U=s==null?void 0:s[2])!=null?U:y.stampContent),stampPlacement:v(e.stampPlacement,xe,(B=s==null?void 0:s[1])!=null?B:y.stampPlacement)};return u.stampPlacement==="beside_name"&&u.namePlacement==="hidden"&&(u.stampPlacement="under_turn"),u}function D(n){var r,a,i,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)}${(a=e[1])==null?void 0:a.slice(0,1)}`:(o=(i=e[0])==null?void 0:i.slice(0,2))!=null?o:"").toUpperCase()}var Te="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",Ae={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;"},Ne={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);"},Pe={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;}"},_e=".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}",Ie={circle:"",pill:".badge{position:static;box-shadow:none}",squircle:""},Me={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:""},Fe={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:${Ae[r]}px;${Le[n]}${Ne[e]}}${Pe[t]}${_e}${Ie[n]}${Me[e]}${He[n]}${Fe[n]}`}function q(n,e,t,r=a=>a){let a=document.createDocumentFragment();if(n==="glyph"||t.length===0){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="${Te}"/></svg>`,a.append(...i.childNodes,O()),a}return n==="avatar"?(a.append(W(t[0],e,r),O()),a):(a.append(R(t,e,r),O()),a)}function R(n,e,t=r=>r){let r=document.createElement("span");r.className="faces";for(let a of n.slice(0,2))r.append(W(a,e,t));return r}function W(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 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 O(){let n=document.createElement("span");return n.className="live",n.setAttribute("aria-hidden","true"),n}var Oe={agentLabel:"Agent",aiLabel:"AI",awayBody:"We are away right now, but we will reply as soon as we are back.",closeLabel:"Close chat",emptyBody:"We usually reply within a few minutes.",emptyTitle:"Ask us anything.",inputPlaceholder:"Type a message",launcherLabel:"Chat with us",replyTime:"Usually replying in a few minutes",retryLabel:"Not delivered. Retry",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`},T={accentColor:"#5b5bff",availability:{timezone:"UTC",windows:[]},awayMessage:"",greeting:"",launcherOffsetX:20,launcherOffsetY:20,launcherPosition:"bottom_right",starterPrompts:[],team:[],...y},Re={quiet:".composer{position:relative;padding:8px 10px 10px}.composer input{padding-right:36px}.composer button{position:absolute;top:50%;right:14px;width:28px;min-width:28px;height:28px;padding:0;background:transparent;color:var(--ink);border-radius:7px;transform:translateY(-50%)}.composer button .sendglyph{display:block;width:16px;height:16px}.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)}.header .status{color:var(--ink-3)}.header .av,.header .status .live{box-shadow:0 0 0 2px var(--paper)}.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}"},$e={round:".composer{padding:10px 10px 12px;gap:6px}.composer input{height:36px;border-radius:18px;padding:0 14px}.composer button{width:36px;min-width:36px;height:36px;padding:0;border-radius:18px}.composer button .sendglyph{display:block}.composer button .sendtext{display:none}",square:".composer input{height:36px;border-radius:8px;padding:0 12px}"},ze={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}"},Ue={filled:"",outlined:".turn{background:none;border:1px solid var(--hairline)}.turn.end_user{background:none;border-color:var(--a);color:var(--ink)}"},Be={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}"},Ke=".turn.agent,.turn.ai{display:flex;gap:10px;max-width:100%;background:none;padding:0}.turn.agent .body,.turn.ai .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}",De='.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)}',Ge={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}"},qe=".lat{font-size:11px;opacity:.7;margin-left:6px}",j=`--paper: oklch(24.6% 0.015 257); --ink: #fff; --ink-3: rgba(255,255,255,.55);
|
|
1
|
+
(function(){'use strict';var se=Object.defineProperty;var le=(n,e,t)=>e in n?se(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t;var h=(n,e,t)=>le(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 P(n){return n.replace(/\/+$/,"")}var D="X-Prodantix-Conversation-Token",H="prodantix.chat.handle";function ce(){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;h(this,"fetchImpl");h(this,"fileFetchImpl");h(this,"host");h(this,"storage");h(this,"handle");h(this,"identity",null);var t,r;this.fetchImpl=L(e.fetchImpl),this.fileFetchImpl=(t=e.fileFetchImpl)!=null?t:((i,o)=>fetch(i,o)),this.host=P(e.host),this.storage=(r=e.storage)!=null?r:ce(),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,o;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},(o=this.storage)==null||o.set(H,JSON.stringify(this.handle)),true)}async send(e,t,r){var a;if(!await this.ensureThread())return null;let i=this.handle;if(!i)return null;let o=await this.request("POST",`/v1/conversations/${encodeURIComponent(i.conversationId)}/turns`,{body:{attachmentIds:r,body:e,pageContext:t},token:i.token});return (a=o==null?void 0:o.turn)!=null?a:null}async upload(e){if(!await this.ensureThread())return null;let t=this.handle;return t?this.fileRequest("POST",`/v1/conversations/${encodeURIComponent(t.conversationId)}/attachments?name=${encodeURIComponent(e.name)}`,t.token,async r=>JSON.parse(await r.text()),e):null}async file(e){let t=this.handle;return t?this.fileRequest("GET",e,t.token,r=>r.blob()):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(H);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(H),null}async fileRequest(e,t,r,i,o){var s,c,p,d;let a={authorization:`Bearer ${this.options.apiKey}`,[D]:r};o&&(a["content-type"]=o.type||"application/octet-stream");try{let l=await this.fileFetchImpl(`${this.host}${t}`,{body:o,headers:a,method:e});if(l.ok)return await i(l);(c=(s=this.options).onError)==null||c.call(s,new Error(`prodantix chat ${t}: ${l.status}`));}catch(l){(d=(p=this.options).onError)==null||d.call(p,l);}return null}async request(e,t,r={}){var a,s,c,p,d,l;let i=this.fetchImpl;if(!i)return (s=(a=this.options).onError)==null||s.call(a,new Error("no fetch available for prodantix chat")),null;let o={authorization:`Bearer ${this.options.apiKey}`,"content-type":"application/json"};r.token&&(o[D]=r.token);try{let m=await i(`${this.host}${t}`,{body:r.body===void 0?void 0:JSON.stringify(r.body),headers:o,method:e}),g=await m.text();return m.ok?g?JSON.parse(g):{}:((p=(c=this.options).onError)==null||p.call(c,new Error(`prodantix chat ${t}: ${m.status}`)),null)}catch(m){return (l=(d=this.options).onError)==null||l.call(d,m),null}}};var de={Fri:"fri",Mon:"mon",Sat:"sat",Sun:"sun",Thu:"thu",Tue:"tue",Wed:"wed"};function _(n,e){var s,c,p,d,l,m;let t=new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:false,minute:"2-digit",timeZone:n.timezone,weekday:"short"}).formatToParts(e),r=de[(c=(s=t.find(g=>g.type==="weekday"))==null?void 0:s.value)!=null?c:""];if(!r)return false;let i=(d=(p=t.find(g=>g.type==="hour"))==null?void 0:p.value)!=null?d:"",o=(m=(l=t.find(g=>g.type==="minute"))==null?void 0:l.value)!=null?m:"",a=`${i}:${o}`;return n.windows.some(g=>g.days.includes(r)&&g.open<=a&&a<g.close)}var k={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"},pe=["quiet","standard"],ue=["round","square"],he=["rounded","tailed"],me=["filled","outlined"],ge=["circle","pill","squircle"],fe=["filled","outlined"],be=["avatar","glyph","team_faces"],xe=["large","medium","small"],ye=["above","hidden","inline"],ve=["beside_name","none","under_turn"],Se=["time","time_and_latency"],C=(n,e,t)=>typeof n=="string"&&e.includes(n)?n:t,G=(n,e)=>typeof n=="boolean"?n:e,ke={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"]},Ce={above:["above",false],avatar_only:["hidden",true],gutter:["above",true],hidden:["hidden",false],inline:["inline",false]},Ee={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"]},we={concierge:["standard","round"],console:["standard","square"],quiet:["quiet","square"]},Te={hairline:["rounded","outlined"],outlined:["rounded","outlined"],rounded:["rounded","filled"],tailed:["tailed","filled"]};function F(n){var g,v,S,f,b,u,x,E,y,w,z,B,K;let e=typeof n=="object"&&n!==null?n:{},t=typeof e.launcherStyle=="string"?e.launcherStyle:void 0,r=t===void 0?void 0:ke[t],i=typeof e.namePlacement=="string"?e.namePlacement:void 0,o=i===void 0?void 0:Ce[i],a=typeof e.timestampStyle=="string"?e.timestampStyle:void 0,s=a===void 0?void 0:Ee[a],c=typeof e.skin=="string"?e.skin:void 0,p=c===void 0?void 0:we[c],d=typeof e.bubbleStyle=="string"?e.bubbleStyle:void 0,l=d===void 0?void 0:Te[d],m={bubbleFill:C(e.bubbleFill,me,(g=l==null?void 0:l[1])!=null?g:k.bubbleFill),bubbleShape:C(e.bubbleShape,he,(v=l==null?void 0:l[0])!=null?v:k.bubbleShape),composerShape:C(e.composerShape,ue,(S=p==null?void 0:p[1])!=null?S:k.composerShape),dayDividers:G(e.dayDividers,(f=s==null?void 0:s[0])!=null?f:k.dayDividers),launcherContent:C(e.launcherContent,be,(b=r==null?void 0:r[2])!=null?b:k.launcherContent),launcherFill:C(e.launcherFill,fe,(u=r==null?void 0:r[1])!=null?u:k.launcherFill),launcherShape:C(e.launcherShape,ge,(x=r==null?void 0:r[0])!=null?x:k.launcherShape),launcherSize:C(e.launcherSize,xe,(E=r==null?void 0:r[3])!=null?E:k.launcherSize),nameAvatar:G(e.nameAvatar,(y=o==null?void 0:o[1])!=null?y:k.nameAvatar),namePlacement:C(e.namePlacement,ye,(w=o==null?void 0:o[0])!=null?w:k.namePlacement),skin:C(e.skin,pe,(z=p==null?void 0:p[0])!=null?z:k.skin),stampContent:C(e.stampContent,Se,(B=s==null?void 0:s[2])!=null?B:k.stampContent),stampPlacement:C(e.stampPlacement,ve,(K=s==null?void 0:s[1])!=null?K:k.stampPlacement)};return m.stampPlacement==="beside_name"&&m.namePlacement==="hidden"&&(m.stampPlacement="under_turn"),m}function q(n){var r,i,o,a;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)}`:(a=(o=e[0])==null?void 0:o.slice(0,2))!=null?a:"").toUpperCase()}var Ae="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",Le={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;"},Ne={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);"},_e={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;}"},Fe=".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}",Ie={circle:"",pill:".badge{position:static;box-shadow:none}",squircle:""},Me={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:""},$e={circle:"",pill:"@media (max-width:480px){.launcher{width:var(--fab-size);padding:0}.launcher .label{display:none}}",squircle:""};function j(n,e,t,r){return `.launcher{--fab-size:${Le[r]}px;${Pe[n]}${Ne[e]}}${_e[t]}${Fe}${Ie[n]}${Me[e]}${He[n]}${$e[n]}`}function W(n,e,t,r=i=>i){let i=document.createDocumentFragment();if(n==="glyph"||t.length===0){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="${Ae}"/></svg>`,i.append(...o.childNodes,$()),i}return n==="avatar"?(i.append(Y(t[0],e,r),$()),i):(i.append(R(t,e,r),$()),i)}function R(n,e,t=r=>r){let r=document.createElement("span");r.className="faces";for(let i of n.slice(0,2))r.append(Y(i,e,t));return r}function Y(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 $(){let n=document.createElement("span");return n.className="live",n.setAttribute("aria-hidden","true"),n}var Re={agentLabel:"Agent",aiLabel:"AI",attachLabel:"Attach a file",awayBody:"We are away right now, but we will reply as soon as we are back.",closeLabel:"Close chat",emptyBody:"We usually reply within a few minutes.",emptyTitle:"Ask us anything.",fileRefusal:(n,e)=>`That file is ${n}. Send a PNG, JPEG, WebP, GIF or PDF up to ${e}.`,inputPlaceholder:"Type a message",launcherLabel:"Chat with us",removeFileLabel:"Remove file",replyTime:"Usually replying in a few minutes",retryLabel:"Not delivered. Retry",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`},T={accentColor:"#5b5bff",availability:{timezone:"UTC",windows:[]},awayMessage:"",greeting:"",launcherOffsetX:20,launcherOffsetY:20,launcherPosition:"bottom_right",starterPrompts:[],team:[],...k},Oe={quiet:".composer{position:relative;padding:8px 10px 10px}.composer input{padding-right:36px}.composer button{position:absolute;top:50%;right:14px;width:28px;min-width:28px;height:28px;padding:0;background:transparent;color:var(--ink);border-radius:7px;transform:translateY(-50%)}.composer button .sendglyph{display:block;width:16px;height:16px}.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)}.header .faces,.header .status{display:none}.header .close{top:6px}.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}"},Ue={round:".composer{padding:10px 10px 12px;gap:6px}.composer input{height:36px;border-radius:18px;padding:0 14px}.composer button{width:36px;min-width:36px;height:36px;padding:0;border-radius:18px}.composer button .sendglyph{display:block}.composer button .sendtext{display:none}",square:".composer input{height:36px;border-radius:8px;padding:0 12px}"},ze={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}"},Be={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}"},De=".turn.agent,.turn.ai{display:flex;gap:10px;max-width:100%;background:none;padding:0}.turn.agent .body,.turn.ai .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}",Ge='.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)}',qe={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}"},je=".lat{font-size:11px;opacity:.7;margin-left:6px}",We=".att{display:block;width:180px;margin-bottom:6px;border-radius:8px;overflow:hidden}.att img{display:block;width:100%}.pdfc{display:inline-flex;gap:8px;align-items:center;margin-bottom:6px;padding:6px 8px;border-radius:8px;background:color-mix(in srgb,currentColor 16%,transparent);color:inherit;font-size:12.5px;text-decoration:none;overflow-wrap:anywhere}.pdfc b,.file b{flex:none;display:inline-flex;align-items:center;justify-content:center;width:26px;height:26px;border-radius:4px;font-size:9px;letter-spacing:.04em;background:color-mix(in srgb,currentColor 22%,transparent)}.att:last-child,.pdfc:last-child{margin-bottom:0}";function Ye(n){let e=n==="round"?14:12;return `.field{position:relative;flex:1;min-width:0;display:flex}.composer .field input{padding-left:${e+26}px}.composer button.clip{position:absolute;top:50%;left:${e-5}px;right:auto;width:28px;min-width:28px;height:28px;padding:0;border-radius:7px;background:none;color:var(--ink-2);transform:translateY(-50%)}.composer button.clip:hover{background:color-mix(in srgb,currentColor 14%,transparent)}.clip svg{display:block;width:18px;height:18px}.file{display:inline-flex;gap:8px;align-items:center;align-self:flex-start;max-width:calc(100% - 20px);margin:0 10px 8px;padding:6px 10px 6px 6px;font-size:12.5px;color:var(--ink);border:1px solid var(--hairline);border-radius:8px}.file .th{flex:none;width:28px;height:28px;border-radius:4px;object-fit:cover}.file .name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.file .sz,.file .x{flex:none;color:var(--ink-3)}.file .x{margin-left:4px;padding:0;border:0;background:none;font:inherit;font-size:16px;line-height:1;cursor:pointer}.ferr{margin:0 10px 6px;font-size:12px;color:oklch(60% 0.2 27)}`}function O(n){return n<999500?`${Math.max(1,Math.round(n/1e3))} KB`:`${(n/1e6).toFixed(1)} MB`}var J=`--paper: oklch(24.6% 0.015 257); --ink: #fff; --ink-3: rgba(255,255,255,.55);
|
|
2
2
|
--fill: rgba(255,255,255,.06); --hairline: rgba(255,255,255,.13); --ink-2: rgba(255,255,255,.70);
|
|
3
|
-
--online: oklch(72% 0.13 163.23);`;function
|
|
3
|
+
--online: oklch(72% 0.13 163.23);`;function Je(n){return n==="light"?"":n==="dark"?`:host { ${J} }`:`@media (prefers-color-scheme: dark) {
|
|
4
4
|
:host {
|
|
5
|
-
${
|
|
5
|
+
${J}
|
|
6
6
|
}
|
|
7
|
-
}`}function
|
|
7
|
+
}`}var Xe=/https?:\/\/[^\s<>"]+/g,Ve=/[.,;:!?)]$/,Qe=n=>{let e=n;for(;Ve.test(e);){let t=e.split("(").length-1,r=e.split(")").length-1;if(e.endsWith(")")&&t>=r)break;e=e.slice(0,-1);}return e};function Ze(n,e){var r;let t=0;for(let i of e.matchAll(Xe)){let o=(r=i.index)!=null?r:0,a=Qe(i[0]);o>t&&n.append(e.slice(t,o));let s=document.createElement("a");s.href=a,s.target="_blank",s.rel="noopener noreferrer",s.textContent=a,n.append(s),t=o+a.length;}t<e.length&&n.append(e.slice(t));}function X(n,e="system"){var a;let t=F(n),r=n.launcherPosition==="bottom_left"?"left":"right",i=n.accentColor;return `${`
|
|
8
8
|
:host {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
document floor and anything the page raises (a cookie bar, a dev chip)
|
|
12
|
-
draws over them: the WebMCP chip covered the launcher on clepit's landing.
|
|
13
|
-
Below the 32-bit ceiling so a host can still put something over us
|
|
14
|
-
deliberately. */
|
|
15
|
-
all: initial; z-index: 2147483000; --a: ${a};
|
|
16
|
-
--paper: #fff; --ink: #0f172a; --ink-3: var(--ink-3);
|
|
9
|
+
all: initial; z-index: 2147483000; --a: ${i};
|
|
10
|
+
--paper: #fff; --ink: #0f172a; --ink-3: rgba(0,0,0,.55);
|
|
17
11
|
--fill: #f1f5f9; --hairline: #e2e8f0; --ink-2: rgba(0,0,0,.72);
|
|
18
12
|
--online: oklch(53.8% 0.1274 163.23);
|
|
19
13
|
color-scheme: ${e==="system"?"light dark":e};
|
|
20
14
|
}
|
|
21
|
-
${
|
|
15
|
+
${Je(e)}
|
|
22
16
|
* { box-sizing: border-box; font-family: system-ui, sans-serif; }
|
|
23
17
|
.launcher {
|
|
24
18
|
z-index: 2147483000; position: fixed; ${r}: ${n.launcherOffsetX}px; bottom: ${n.launcherOffsetY}px; width: 56px; height: 56px;
|
|
25
19
|
border-radius: 28px; border: none; cursor: pointer;
|
|
26
20
|
display: inline-flex; align-items: center; justify-content: center;
|
|
27
|
-
background: ${
|
|
21
|
+
background: ${i}; color: #fff; font-size: 24px;
|
|
28
22
|
box-shadow: 0 4px 12px rgba(0,0,0,.2);
|
|
29
23
|
}
|
|
30
24
|
.launcher:focus-visible { outline: 3px solid #0b0e14; outline-offset: 2px; }
|
|
31
|
-
/* A BACKGROUND change, never a position change. Nothing else in the fleet
|
|
32
|
-
moves under the pointer: .button[data-variant] and .iconButton all hover by
|
|
33
|
-
background alone. This used to lift by translateY(-1px), which made the one
|
|
34
|
-
control a visitor is meant to click the only element in the product that
|
|
35
|
-
shifted when pointed at. */
|
|
36
25
|
.launcher { transition: background-color 120ms ease; }
|
|
37
|
-
.launcher:hover { background: color-mix(in srgb, #000 12%, ${
|
|
38
|
-
.launcher:active { background: color-mix(in srgb, #000 20%, ${
|
|
26
|
+
.launcher:hover { background: color-mix(in srgb, #000 12%, ${i}); }
|
|
27
|
+
.launcher:active { background: color-mix(in srgb, #000 20%, ${i}); }
|
|
39
28
|
@media (prefers-reduced-motion: reduce) {
|
|
40
29
|
.launcher { transition: none; }
|
|
41
30
|
}
|
|
@@ -44,12 +33,6 @@ ${We(e)}
|
|
|
44
33
|
border-radius: 10px; background: #dc2626; color: #fff; font-size: 12px;
|
|
45
34
|
display: flex; align-items: center; justify-content: center; padding: 0 4px;
|
|
46
35
|
}
|
|
47
|
-
/* renderBadge hides this with the hidden attribute, which is UA display:none
|
|
48
|
-
and is beaten by ANY author display. The rule above is one, so the badge
|
|
49
|
-
rendered for every visitor with no unread messages: an empty red circle on
|
|
50
|
-
the launcher, in production, for as long as it has shipped. The hiding code
|
|
51
|
-
read as if it worked, which is why nothing caught it. Keep this rule beside
|
|
52
|
-
the one that needs it. */
|
|
53
36
|
.badge[hidden] { display: none; }
|
|
54
37
|
.panel {
|
|
55
38
|
z-index: 2147483001; position: fixed; ${r}: ${n.launcherOffsetX}px; bottom: ${n.launcherOffsetY+68}px; width: 360px; max-width: calc(100vw - 40px);
|
|
@@ -59,39 +42,14 @@ ${We(e)}
|
|
|
59
42
|
}
|
|
60
43
|
.header { position: relative; padding: 14px 16px; background: #0b0e14; color: #fff; display: flex; align-items: center; justify-content: space-between; }
|
|
61
44
|
.header h2 { margin: 0; font-size: 15px; }
|
|
62
|
-
/* Sized from the Configure tab's own head: 36px faces overlapping by 12, the
|
|
63
|
-
status line 12.5px at 80% under the title. The ring is the header's own
|
|
64
|
-
ground so overlapping faces separate from it and from each other. */
|
|
65
45
|
.header .faces { display: flex; }
|
|
66
|
-
/* The fill is the face's own tone, set inline from the served config: one of
|
|
67
|
-
the record's two face tones, never the accent this header is painted in. The
|
|
68
|
-
ring is the accent because its job is to part two OVERLAPPING discs from each
|
|
69
|
-
other and from the header behind them. */
|
|
70
46
|
.header .av { width: 36px; height: 36px; box-shadow: 0 0 0 2px var(--a); }
|
|
71
47
|
.header .av + .av { margin-left: -12px; }
|
|
72
48
|
.headmain { display: flex; flex-direction: column; }
|
|
73
49
|
.header .status { display: flex; align-items: center; gap: 6px; margin: 5px 0 0; font-size: 12.5px; color: rgb(255 255 255 / 80%); }
|
|
74
|
-
/* The dot's ring is the PAPER, not the accent. An accent ring on the standard
|
|
75
|
-
skin is the header's own background and draws nothing, which is how this
|
|
76
|
-
shipped looking ringless beside a preview that had one. The faces above keep
|
|
77
|
-
the accent ring, which is a different job: separating two overlapping discs
|
|
78
|
-
from each other and from the header. */
|
|
79
50
|
.header .status .live { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--online); box-shadow: 0 0 0 2px var(--paper); }
|
|
80
|
-
/* Hours, the same fact the launcher's dot carries. A green dot and a sentence
|
|
81
|
-
promising a reply in minutes are both claims about somebody being there, so
|
|
82
|
-
outside the project's hours neither is drawn: the away message in the thread
|
|
83
|
-
is what speaks then. */
|
|
84
51
|
.panel.closed .status { display: none; }
|
|
85
|
-
/* Pinned rather than laid out: the standard skin turns this header into a
|
|
86
|
-
column so the title can carry a line under it, and a close button that is
|
|
87
|
-
merely a flex sibling then stacks BELOW the title on the left, which is where
|
|
88
|
-
clepit's landing showed it. */
|
|
89
52
|
.header .close { position: absolute; top: 8px; right: 8px; }
|
|
90
|
-
/* The fleet's icon button: a padded square, a radius, and a hover that tints
|
|
91
|
-
the background. This carried none of them, so the messenger's close was the
|
|
92
|
-
one icon button in the product with no radius and no hover at all. The tint
|
|
93
|
-
is mixed from currentColor rather than a fixed white because the header is
|
|
94
|
-
the accent on some skins and the paper on others. */
|
|
95
53
|
.close {
|
|
96
54
|
display: inline-flex; align-items: center; justify-content: center;
|
|
97
55
|
width: 32px; height: 32px; padding: 0;
|
|
@@ -104,19 +62,14 @@ ${We(e)}
|
|
|
104
62
|
.close:focus-visible { outline: 2px solid currentColor; outline-offset: 1px; }
|
|
105
63
|
.log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
|
|
106
64
|
.turn { max-width: 80%; padding: 8px 12px; border-radius: 12px; font-size: 14px; }
|
|
107
|
-
.turn.end_user { align-self: flex-end; background: ${
|
|
65
|
+
.turn.end_user { align-self: flex-end; background: ${i}; color: #fff; }
|
|
108
66
|
.turn.agent, .turn.ai { align-self: flex-start; background: var(--fill); color: var(--ink); }
|
|
67
|
+
.turn.ai a { color: ${i}; text-decoration: underline; overflow-wrap: anywhere; }
|
|
109
68
|
.author { font-size: 11px; opacity: .7; margin-bottom: 2px; }
|
|
110
|
-
/* In flight. Dimmed rather than spinner'd or greyed out: the words are already
|
|
111
|
-
readable and the only thing not yet true is that anyone else has them. No
|
|
112
|
-
transition, because a fade running as the bubble appears reads as the lag
|
|
113
|
-
this change exists to remove. */
|
|
114
69
|
.turn[data-pending] { opacity: .6; }
|
|
115
70
|
.turn[data-failed] { opacity: 1; box-shadow: inset 0 0 0 1px #dc2626; }
|
|
116
|
-
/* Inside the bubble, under the words it belongs to. A failure notice parked
|
|
117
|
-
somewhere else in the panel does not say WHICH message went nowhere. */
|
|
118
71
|
.retry { display: block; margin: 5px 0 0; padding: 0; background: none; border: 0; color: inherit; font: inherit; font-size: 11.5px; text-decoration: underline; cursor: pointer; opacity: .85; }
|
|
119
|
-
.away { display: flex; gap: 10px; align-items: flex-start; margin: 12px 12px 0; padding: 10px 14px; font-size: 13px; line-height: 1.43; color: ${
|
|
72
|
+
.away { display: flex; gap: 10px; align-items: flex-start; margin: 12px 12px 0; padding: 10px 14px; font-size: 13px; line-height: 1.43; color: ${i}; background: color-mix(in srgb, ${i} 12%, transparent); border-radius: 4px; }
|
|
120
73
|
.awayglyph { flex: none; width: 16px; height: 16px; margin-top: 1px; border: 1.5px solid currentColor; border-radius: 50%; }
|
|
121
74
|
.empty { display: flex; flex-direction: column; gap: 8px; padding: 20px 16px; }
|
|
122
75
|
.empty h3 { margin: 0; font-size: 18px; font-weight: 640; letter-spacing: -.015em; }
|
|
@@ -126,25 +79,15 @@ ${We(e)}
|
|
|
126
79
|
font-family: inherit; font-size: 13.5px; font-weight: 500; color: var(--ink);
|
|
127
80
|
background: none; border: 1px solid var(--hairline); border-radius: 8px; cursor: pointer;
|
|
128
81
|
}
|
|
129
|
-
.prompt:focus-visible { outline: 2px solid ${
|
|
82
|
+
.prompt:focus-visible { outline: 2px solid ${i}; outline-offset: 2px; }
|
|
130
83
|
.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: oklch(52% 0.17 22); }
|
|
131
84
|
.av.bot { border-radius: 9px; background: var(--fill); color: var(--ink); }
|
|
132
85
|
.av img { width: 100%; height: 100%; display: block; object-fit: cover; border-radius: inherit; }
|
|
133
|
-
/* 36px, against a message bubble measured at 33px in the panel (14px type,
|
|
134
|
-
8px of padding, rendered). The field was 46px round and 44px square, half
|
|
135
|
-
again the height of anything it produced, which is what read as too much air
|
|
136
|
-
inside it; 36 sits a hair above a bubble, which is the room a field wants for
|
|
137
|
-
a caret and a placeholder and a bubble does not. The type stays at 14px, the
|
|
138
|
-
same size the messages are set in: the box came down, not the words.
|
|
139
|
-
|
|
140
|
-
No backtick in this comment, or in any other inside this sheet. It is a
|
|
141
|
-
template literal, so one ends the string and the rest of the CSS becomes a
|
|
142
|
-
tagged-template call. Writing a selector as code here cost 124 tests. */
|
|
143
86
|
.composer { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--hairline); }
|
|
144
87
|
.composer input { flex: 1; min-width: 0; height: 36px; padding: 0 12px; border: 0; border-radius: 8px; font-size: 14px; background: var(--fill); color: var(--ink); }
|
|
145
|
-
.composer input:focus-visible { outline: 2px solid ${
|
|
146
|
-
.composer button { display: inline-flex; align-items: center; justify-content: center; gap: 0; min-width: 56px; height: 36px; padding: 0 14px; background: ${
|
|
147
|
-
.composer button:hover { background: color-mix(in srgb, #000 12%, ${
|
|
88
|
+
.composer input:focus-visible { outline: 2px solid ${i}; }
|
|
89
|
+
.composer button { display: inline-flex; align-items: center; justify-content: center; gap: 0; min-width: 56px; height: 36px; padding: 0 14px; background: ${i}; color: #fff; border: none; border-radius: 8px; cursor: pointer; font-family: inherit; font-size: 13.5px; font-weight: 550; }
|
|
90
|
+
.composer button:hover { background: color-mix(in srgb, #000 12%, ${i}); }
|
|
148
91
|
.composer button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
|
|
149
92
|
.composer button .sendglyph { display: none; width: 17px; height: 17px; }
|
|
150
93
|
.composer button:focus-visible { outline: 2px solid #0b0e14; }
|
|
@@ -152,5 +95,5 @@ ${We(e)}
|
|
|
152
95
|
.panel { animation: rise 180ms ease-out; }
|
|
153
96
|
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
|
|
154
97
|
}
|
|
155
|
-
`}${$e[t.composerShape]}${Re[t.skin]}${G(t.launcherShape,t.launcherFill,t.launcherContent,t.launcherSize)}${ze[t.bubbleShape]}${Ue[t.bubbleFill]}${Be[t.namePlacement]}${t.nameAvatar?Ke:""}${t.dayDividers?De:""}${Ge[t.stampPlacement]}${t.stampContent==="time_and_latency"?qe:""}`}var je=["end_user","agent","ai"];function Ye(){let n=globalThis.location;if(n)return {host:n.host,path:n.pathname,title:document.title}}var Je='<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M15.88 9.29 12 13.17 8.12 9.29a.996.996 0 0 0-1.41 0c-.39.39-.39 1.02 0 1.41l4.59 4.59c.39.39 1.02.39 1.41 0l4.59-4.59c.39-.39.39-1.02 0-1.41-.39-.38-1.03-.39-1.42 0"/></svg>',M=class{constructor(e,t,r={},a={},i={}){this.host=e;this.client=t;h(this,"root");h(this,"strings");h(this,"settings");h(this,"appearance");h(this,"launcher");h(this,"badge");h(this,"panel",null);h(this,"lastFocused",null);h(this,"unread",0);h(this,"pendingTurns",0);h(this,"openNow");h(this,"style");h(this,"scheme");var o;this.strings={...Oe,...r},this.appearance={...T,...a},this.settings=I({...T,...a}),this.root=e.attachShadow({mode:(o=i.shadowMode)!=null?o:"closed"}),this.openNow=_(this.appearance.availability,new Date),this.scheme=i.scheme,this.style=document.createElement("style"),this.style.textContent=Y(this.appearance,this.scheme),this.root.append(this.style),this.launcher=document.createElement("button"),this.launcher.className="launcher",this.launcher.type="button",this.launcher.setAttribute("aria-haspopup","dialog"),this.launcher.addEventListener("click",()=>this.toggle()),this.badge=document.createElement("span"),this.badge.className="badge",this.badge.hidden=true,this.drawLauncher(),this.root.append(this.launcher);}drawLauncher(){if(this.launcher.setAttribute("aria-label",this.strings.launcherLabel),this.launcher.replaceChildren(),this.launcher.append(q(this.settings.launcherContent,this.strings,this.appearance.team,e=>this.client.avatarUrl(e))),this.settings.launcherShape==="pill"){let e=document.createElement("span");e.className="label",e.textContent=this.settings.launcherContent==="team_faces"?this.strings.agentLabel:this.strings.launcherLabel,this.launcher.append(e);}this.launcher.append(this.badge),this.launcher.classList.toggle("closed",!this.openNow);}update(e,t){this.appearance={...T,...e},this.settings=I(this.appearance),t!==void 0&&(this.scheme=t),this.style.textContent=Y(this.appearance,this.scheme),this.drawLauncher(),this.panel&&(this.close(),this.open());}toggle(){this.panel?this.close():this.open();}setOpenNow(e){var t;this.openNow=e,this.launcher.classList.toggle("closed",!e),(t=this.panel)==null||t.classList.toggle("closed",!e);}async open(){var x;if(this.panel)return;this.lastFocused=this.host.ownerDocument.activeElement,this.unread=0,this.renderBadge();let e=document.createElement("section");e.className=this.openNow?"panel":"panel closed",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=(x=this.appearance.team)!=null?x:[];r.length>0&&t.append(R(r,this.strings,m=>this.client.avatarUrl(m)));let a=document.createElement("div");a.className="headmain";let i=document.createElement("h2");i.textContent=this.strings.title;let o=document.createElement("p");o.className="status";let s=document.createElement("span");s.className="live",s.setAttribute("aria-hidden","true"),o.append(s,this.strings.replyTime),a.append(i,o);let g=document.createElement("button");g.className="close",g.type="button",g.setAttribute("aria-label",this.strings.closeLabel),g.innerHTML=Je,g.addEventListener("click",()=>this.close()),t.append(a,g);let l=document.createElement("div");l.className="log",l.setAttribute("role","log"),l.setAttribute("aria-live","polite"),l.setAttribute("aria-label",this.strings.title);let p=document.createElement("form");p.className="composer";let d=document.createElement("input");d.type="text",d.setAttribute("aria-label",this.strings.inputPlaceholder),d.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 c=document.createElement("span");c.className="sendtext",c.textContent=this.strings.sendLabel,u.append(c),p.append(d,u),p.addEventListener("submit",m=>{m.preventDefault(),this.submit(d,l);}),e.append(t,l,p),e.addEventListener("keydown",m=>this.onKeydown(m,e,g)),this.root.append(e),this.panel=e,d.focus();let f=await this.client.load();f&&f.turns.length>0?this.renderThread(l,f):this.renderFirstRun(l,d),this.openNow||this.renderAway(t);}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 i=document.createElement("p");i.textContent=this.strings.emptyBody,r.append(a,i);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";let r=document.createElement("span");r.className="awayglyph",r.setAttribute("aria-hidden","true");let a=document.createElement("span");a.textContent=this.appearance.awayMessage.trim()||this.strings.awayBody,t.append(r,a),e.after(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.hasTurn(t,e.id)&&this.appendTurn(t,e);return}e.authorKind!=="end_user"&&(this.unread+=1,this.renderBadge());}async submit(e,t){let r=e.value.trim();r&&(e.value="",await this.sendBody(t,r));}async sendBody(e,t){var i;(i=e.querySelector(".empty"))==null||i.remove(),this.pendingTurns+=1;let r=this.appendTurn(e,{authorId:null,authorKind:"end_user",body:t,createdAt:new Date().toISOString(),id:`pending-${this.pendingTurns}`});r.setAttribute("data-pending","");let a=await this.client.send(t,Ye());if(r.removeAttribute("data-pending"),a){r.dataset.turnId=a.id;return}this.markFailed(e,r,t);}markFailed(e,t,r){var i;t.setAttribute("data-failed","");let a=document.createElement("button");a.type="button",a.className="retry",a.textContent=this.strings.retryLabel,a.addEventListener("click",()=>{t.remove(),this.sendBody(e,r);}),((i=t.querySelector(".body"))!=null?i:t).append(a);}hasTurn(e,t){for(let r of e.children)if(r instanceof HTMLElement&&r.dataset.turnId===t)return true;return false}renderThread(e,t){e.replaceChildren();for(let r of t.turns)this.appendTurn(e,r);}appendTurn(e,t){var p,d,u;(p=e.querySelector(".empty"))==null||p.remove();let r=je.includes(t.authorKind)?t.authorKind:"agent",a=this.settings,i=document.createElement("div");if(i.className=`turn ${r}`,i.dataset.turnId=t.id,r!=="end_user"&&a.nameAvatar){let c=document.createElement("span");if(c.className=r==="ai"?"av bot":"av",c.setAttribute("aria-hidden","true"),r==="agent"&&t.authorAvatarUrl){let f=document.createElement("img");f.alt="",f.src=this.client.avatarUrl(t.authorAvatarUrl),c.append(f);}else {c.textContent=r==="ai"?this.strings.aiLabel:D(this.agentName(t));let f=r==="agent"?(u=(d=this.appearance.team)==null?void 0:d.find(x=>x.name===t.authorName))==null?void 0:u.tone:void 0;f&&(c.style.background=f);}i.append(c);}let s=document.createElement("div");s.className="body";let g=r!=="end_user"&&a.namePlacement!=="hidden",l=document.createElement("div");if(l.textContent=t.body,g||r==="ai"&&a.namePlacement==="hidden"){let c=document.createElement("div");c.className=r==="ai"?"author ai":"author",c.textContent=r==="ai"?this.strings.aiLabel:this.agentName(t),a.stampPlacement==="beside_name"&&c.append(this.stamp(t)),a.namePlacement==="inline"?(c.classList.add("below"),s.append(l,c)):s.append(c,l);}else s.append(l);return a.stampPlacement==="under_turn"&&s.append(this.stamp(t)),i.append(s),e.append(i),e.scrollTop=e.scrollHeight,i}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 i=a[0],o=a[a.length-1],s=this.root.activeElement;e.shiftKey&&s===i?(e.preventDefault(),o.focus()):!e.shiftKey&&s===o?(e.preventDefault(),i.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 J(n){return `40${JSON.stringify(n)}`}function X(){return "3"}function V(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=$(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),a=t.slice(1);if(r==="0")return {kind:"connected"};if(r==="1")return {kind:"disconnect"};if(r==="4"){let o=$(a);return {kind:"connectError",message:typeof(o==null?void 0:o.message)=="string"?o.message:"refused"}}if(r!=="2")return {kind:"other"};let i=$(a);return !Array.isArray(i)||typeof i[0]!="string"?{kind:"other"}:{kind:"event",name:i[0],payload:i[1]}}function $(n){try{return JSON.parse(n)}catch(e){return null}}var Xe="/socket.io/?EIO=4&transport=websocket",H=class{constructor(e){this.options=e;h(this,"socket",null);h(this,"heartbeat",null);h(this,"ready",false);h(this,"closed",false);h(this,"heartbeatWindow",45e3);h(this,"factory");h(this,"setTimer");h(this,"clearTimer");var t,r,a;this.factory=(t=e.socketFactory)!=null?t:Ve,this.setTimer=(r=e.setTimer)!=null?r:((i,o)=>setTimeout(i,o)),this.clearTimer=(a=e.clearTimer)!=null?a:(i=>clearTimeout(i));}open(){if(this.socket||this.closed)return;let e=`${this.options.host.replace(/^http/,"ws").replace(/\/+$/,"")}${Xe}`,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,a,i,o;let t=V(e);if(t.kind==="open"){this.armHeartbeat(t.pingInterval+t.pingTimeout),(r=this.socket)==null||r.send(J(this.options.auth));return}if(t.kind==="ping"){this.armHeartbeat(),(a=this.socket)==null||a.send(X());return}if(t.kind==="connectError"||t.kind==="disconnect"){this.stopHeartbeat(),(i=this.socket)==null||i.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 Ve(n){let e=globalThis.WebSocket;if(!e)throw new Error("no WebSocket");return new e(n)}var Qe=6e4;function Q(n){var S,C,E,w;let e=globalThis.document;if(!e)throw new Error("prodantix chat requires a document; mount it in the browser");let t=(S=n.mountPoint)!=null?S:e.createElement("div");n.mountPoint||e.body.append(t);let r=new P(n),a=new M(t,r,n.strings,n.appearance),i=(E=(C=n.appearance)==null?void 0:C.availability)!=null?E:T.availability,o,s=()=>{a.setOpenNow(_(i,new Date)),o=setTimeout(s,Qe);};s();let g=new Set,l,p=null,d=(w=n.pollIntervalMs)!=null?w:15e3,u=b=>{g.has(b.id)||b.authorKind==="end_user"||(g.add(b.id),a.onIncomingTurn(b));},c=async()=>{if(!r.hasThread)return;let b=await r.load();if(b){for(let k of b.turns)u(k);g=new Set(b.turns.map(k=>k.id));}},f=()=>{l||d<=0||(l=setInterval(()=>void c(),d));},x=()=>{l&&clearInterval(l),l=void 0;},m=()=>{if(p||!n.socketHost)return;let b=r.socketAuth;b&&(p=new H({auth:b,host:n.socketHost,onClosed:k=>{p=null,f(),k&&m();},onReady:x,onTurn:u,socketFactory:n.socketFactory}),p.open());};return f(),m(),{close:()=>a.close(),destroy:()=>{x(),clearTimeout(o),p==null||p.close(),p=null,a.close(),t.remove();},identify:b=>r.identify(b),open:()=>{a.open().then(m);}}}var Ze="prodantix.messenger.config",Z=n=>{var t,r,a,i;let e=(t=n.navigator)==null?void 0:t.languages;return Array.isArray(e)&&e.length>0?e.join(","):((r=n.navigator)==null?void 0:r.language)||((i=(a=n.document)==null?void 0:a.documentElement)==null?void 0:i.lang)||void 0},ee=(n,e)=>`${Ze}:${n}:${e!=null?e:""}`;function te(n,e,t){let r=n==null?void 0:n.get(ee(e,t));if(!r)return null;try{let a=JSON.parse(r);return (a==null?void 0:a.apiKey)===e?a.config:null}catch(a){return null}}async function ne(n){var i,o,s,g,l;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(n.host),r=ee(n.apiKey,n.locale),a=n.locale?`?locale=${encodeURIComponent(n.locale)}`:"";try{let p=await e(`${t}/v1/messenger/config${a}`,{headers:{authorization:`Bearer ${n.apiKey}`},method:"GET"});if(!p.ok)return (o=n.onError)==null||o.call(n,new Error(`prodantix messenger config: ${p.status}`)),null;let d=JSON.parse(await p.text());return d.enabled?((g=n.storage)==null||g.set(r,JSON.stringify({apiKey:n.apiKey,config:d})),d):((s=n.storage)==null||s.remove(r),d)}catch(p){return (l=n.onError)==null||l.call(n,p),null}}var et=["close","identify","open","shutdown","toggle"],A="[prodantix/messenger]";function tt(n,e){for(let t of n){let[r,...a]=t!=null?t:[];typeof r!="string"||!et.includes(r)||e(r,...a);}}function nt(n){if(!n)return null;try{return new URL(n).origin}catch(e){return null}}async function ae(n,e={}){var c,f,x;let t=(c=e.warn)!=null?c:(m=>console.warn(m)),r=n.prodantix,a=r==null?void 0:r.k;if(!a)return t(`${A} no project key on the install snippet; nothing will load.`),null;let i=nt((f=e.scriptSrc)!=null?f:rt(n));if(!i)return t(`${A} could not tell which host served this script; nothing will load.`),null;let o=at(n),s=Z(n),g=te(o,a,s),l=await ne({apiKey:a,host:i,locale:s,onError:m=>t(`${A} settings could not be read: ${String(m)}`),storage:o}),p=l!=null?l:g;if(!p)return t(`${A} no settings available; the messenger will not render.`),null;if(!p.enabled)return null;let d=Q({apiKey:a,appearance:p,distinctId:ot(n,o),host:i,socketHost:p.socketUrl||void 0}),u=(m,...S)=>{if((m==="open"||m==="toggle")&&d.open(),m==="close"&&d.close(),m==="shutdown"&&d.destroy(),m==="identify"){let C=it(S[0]);if(!C){console.error(`${A} 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}d.identify(C);}};return tt((x=r==null?void 0:r.q)!=null?x:[],u),n.prodantix=Object.assign((m,...S)=>u(m,...S),{k:a,q:[]}),d}function rt(n){var t;let e=(t=n.document)==null?void 0:t.currentScript;return e==null?void 0:e.src}function at(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 it(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 re="prodantix.messenger.anon";function ot(n,e){var a,i,o;let t=e==null?void 0:e.get(re);if(t)return t;let r=`anon_${(o=(i=(a=n.crypto)==null?void 0:a.randomUUID)==null?void 0:i.call(a))!=null?o:Math.random().toString(36).slice(2)}`;return e==null||e.set(re,r),r}ae(globalThis);})();//# sourceMappingURL=messenger.iife.js.map
|
|
98
|
+
`}${Ue[t.composerShape]}${Oe[t.skin]}${j(t.launcherShape,t.launcherFill,t.launcherContent,t.launcherSize)}${ze[t.bubbleShape]}${Be[t.bubbleFill]}${Ke[t.namePlacement]}${t.nameAvatar?De:""}${t.dayDividers?Ge:""}${qe[t.stampPlacement]}${t.stampContent==="time_and_latency"?je:""}${We}${(a=n.attachments)!=null&&a.enabled?Ye(t.composerShape):""}`}var et=["end_user","agent","ai"];function tt(){let n=globalThis.location;if(n)return {host:n.host,path:n.pathname,title:document.title}}var nt='<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="m16.5 6.5-7.8 7.8a2.1 2.1 0 0 0 3 3l8.1-8.1a4.2 4.2 0 0 0-6-6L5.7 11.3a6.3 6.3 0 0 0 8.9 8.9l6.6-6.6"/></svg>',rt='<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M15.88 9.29 12 13.17 8.12 9.29a.996.996 0 0 0-1.41 0c-.39.39-.39 1.02 0 1.41l4.59 4.59c.39.39 1.02.39 1.41 0l4.59-4.59c.39-.39.39-1.02 0-1.41-.39-.38-1.03-.39-1.42 0"/></svg>',I=class{constructor(e,t,r={},i={},o={}){this.host=e;this.client=t;h(this,"root");h(this,"strings");h(this,"settings");h(this,"appearance");h(this,"launcher");h(this,"badge");h(this,"panel",null);h(this,"lastFocused",null);h(this,"unread",0);h(this,"pendingTurns",0);h(this,"openNow");h(this,"style");h(this,"scheme");h(this,"picked",null);h(this,"objectUrls",[]);var a;this.strings={...Re,...r},this.appearance={...T,...i},this.settings=F({...T,...i}),this.root=e.attachShadow({mode:(a=o.shadowMode)!=null?a:"closed"}),this.openNow=_(this.appearance.availability,new Date),this.scheme=o.scheme,this.style=document.createElement("style"),this.style.textContent=X(this.appearance,this.scheme),this.root.append(this.style),this.launcher=document.createElement("button"),this.launcher.className="launcher",this.launcher.type="button",this.launcher.setAttribute("aria-haspopup","dialog"),this.launcher.addEventListener("click",()=>this.toggle()),this.badge=document.createElement("span"),this.badge.className="badge",this.badge.hidden=true,this.drawLauncher(),this.root.append(this.launcher);}drawLauncher(){if(this.launcher.setAttribute("aria-label",this.strings.launcherLabel),this.launcher.replaceChildren(),this.launcher.append(W(this.settings.launcherContent,this.strings,this.appearance.team,e=>this.client.avatarUrl(e))),this.settings.launcherShape==="pill"){let e=document.createElement("span");e.className="label",e.textContent=this.settings.launcherContent==="team_faces"?this.strings.agentLabel:this.strings.launcherLabel,this.launcher.append(e);}this.launcher.append(this.badge),this.launcher.classList.toggle("closed",!this.openNow);}update(e,t){this.appearance={...T,...e},this.settings=F(this.appearance),t!==void 0&&(this.scheme=t),this.style.textContent=X(this.appearance,this.scheme),this.drawLauncher(),this.panel&&(this.close(),this.open());}toggle(){this.panel?this.close():this.open();}setOpenNow(e){var t;this.openNow=e,this.launcher.classList.toggle("closed",!e),(t=this.panel)==null||t.classList.toggle("closed",!e);}async open(){var f;if(this.panel)return;this.lastFocused=this.host.ownerDocument.activeElement,this.unread=0,this.renderBadge();let e=document.createElement("section");e.className=this.openNow?"panel":"panel closed",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=(f=this.appearance.team)!=null?f:[];r.length>0&&t.append(R(r,this.strings,b=>this.client.avatarUrl(b)));let i=document.createElement("div");i.className="headmain";let o=document.createElement("h2");o.textContent=this.strings.title;let a=document.createElement("p");a.className="status";let s=document.createElement("span");s.className="live",s.setAttribute("aria-hidden","true"),a.append(s,this.strings.replyTime),i.append(o,a);let c=document.createElement("button");c.className="close",c.type="button",c.setAttribute("aria-label",this.strings.closeLabel),c.innerHTML=rt,c.addEventListener("click",()=>this.close()),t.append(i,c);let p=document.createElement("div");p.className="log",p.setAttribute("role","log"),p.setAttribute("aria-live","polite"),p.setAttribute("aria-label",this.strings.title);let d=document.createElement("form");d.className="composer";let l=document.createElement("input");l.type="text",l.setAttribute("aria-label",this.strings.inputPlaceholder),l.placeholder=this.strings.inputPlaceholder;let m=document.createElement("button");m.type="submit",m.setAttribute("aria-label",this.strings.sendLabel),m.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 g=document.createElement("span");g.className="sendtext",g.textContent=this.strings.sendLabel,m.append(g);let v=this.appearance.attachments;if(v!=null&&v.enabled&&this.client.upload){let b=document.createElement("span");b.className="field";let u=document.createElement("input");u.type="file",u.accept=v.accept.join(","),u.hidden=true,u.addEventListener("change",()=>{var y;let E=(y=u.files)==null?void 0:y[0];u.value="",E&&this.pick(p,d,v,E);});let x=document.createElement("button");x.type="button",x.className="clip",x.setAttribute("aria-label",this.strings.attachLabel),x.innerHTML=nt,x.addEventListener("click",()=>u.click()),b.append(x,l,u),d.append(b,m);}else d.append(l,m);d.addEventListener("submit",b=>{b.preventDefault(),this.submit(l,p);}),e.append(t,p,d),e.addEventListener("keydown",b=>this.onKeydown(b,e,c)),this.root.append(e),this.panel=e,l.focus();let S=await this.client.load();S&&S.turns.length>0?this.renderThread(p,S):this.renderFirstRun(p,l),this.openNow||this.renderAway(t);}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 o=document.createElement("p");o.textContent=this.strings.emptyBody,r.append(i,o);for(let a of this.appearance.starterPrompts){let s=document.createElement("button");s.className="prompt",s.type="button",s.textContent=a,s.addEventListener("click",()=>{t.value=a,this.submit(t,e);}),r.append(s);}e.replaceChildren(r);}renderAway(e){let t=document.createElement("div");t.className="away";let r=document.createElement("span");r.className="awayglyph",r.setAttribute("aria-hidden","true");let i=document.createElement("span");i.textContent=this.appearance.awayMessage.trim()||this.strings.awayBody,t.append(r,i),e.after(t);}pick(e,t,r,i){let o=i.size>r.maxBytes||!r.accept.includes(i.type);for(let l of this.root.querySelectorAll(o?".ferr":".file,.ferr"))l.remove();if(o){let l=document.createElement("p");l.className="ferr",l.setAttribute("role","alert"),l.textContent=this.strings.fileRefusal(O(i.size),`${r.maxBytes/1e6} MB`),t.before(l),e.scrollTop=e.scrollHeight;return}this.picked=i;let a=document.createElement("span");a.className="file";let s;if(i.type==="application/pdf")s=document.createElement("b"),s.textContent="PDF";else {let l=document.createElement("img");l.className="th",l.alt="",l.src=this.objectUrl(i),s=l;}let c=document.createElement("span");c.className="name",c.textContent=i.name;let p=document.createElement("span");p.className="sz",p.textContent=`\xB7 ${O(i.size)}`;let d=document.createElement("button");d.type="button",d.className="x",d.setAttribute("aria-label",this.strings.removeFileLabel),d.textContent="\xD7",d.addEventListener("click",()=>{this.picked=null,a.remove();}),a.append(s,c,p,d),t.before(a),e.scrollTop=e.scrollHeight;}objectUrl(e){let t=URL.createObjectURL(e);return this.objectUrls.push(t),t}close(){if(this.panel){this.panel.remove(),this.panel=null,this.picked=null;for(let e of this.objectUrls)URL.revokeObjectURL(e);this.objectUrls=[],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.hasTurn(t,e.id)&&this.appendTurn(t,e);return}e.authorKind!=="end_user"&&(this.unread+=1,this.renderBadge());}async submit(e,t){let r=e.value.trim(),i=this.picked;if(!(!r&&!i)){e.value="",this.picked=null;for(let o of this.root.querySelectorAll(".file,.ferr"))o.remove();await this.sendBody(t,r,i);}}async sendBody(e,t,r=null){var s,c,p;(s=e.querySelector(".empty"))==null||s.remove(),this.pendingTurns+=1;let i=this.appendTurn(e,{authorId:null,authorKind:"end_user",body:t,createdAt:new Date().toISOString(),id:`pending-${this.pendingTurns}`},r);i.setAttribute("data-pending","");let o=r?await((p=(c=this.client).upload)==null?void 0:p.call(c,r)):void 0,a=o===null?null:await this.client.send(t,tt(),o?[o.id]:void 0);if(i.removeAttribute("data-pending"),a){i.dataset.turnId=a.id;return}this.markFailed(e,i,t,r);}markFailed(e,t,r,i){var a;t.setAttribute("data-failed","");let o=document.createElement("button");o.type="button",o.className="retry",o.textContent=this.strings.retryLabel,o.addEventListener("click",()=>{t.remove(),this.sendBody(e,r,i);}),((a=t.querySelector(".body"))!=null?a:t).append(o);}hasTurn(e,t){for(let r of e.children)if(r instanceof HTMLElement&&r.dataset.turnId===t)return true;return false}renderThread(e,t){e.replaceChildren();for(let r of t.turns)this.appendTurn(e,r);}appendTurn(e,t,r=null){var l,m,g,v,S,f,b;(l=e.querySelector(".empty"))==null||l.remove();let i=et.includes(t.authorKind)?t.authorKind:"agent",o=this.settings,a=document.createElement("div");if(a.className=`turn ${i}`,a.dataset.turnId=t.id,i!=="end_user"&&o.nameAvatar){let u=document.createElement("span");if(u.className=i==="ai"?"av bot":"av",u.setAttribute("aria-hidden","true"),i==="agent"&&t.authorAvatarUrl){let x=document.createElement("img");x.alt="",x.src=this.client.avatarUrl(t.authorAvatarUrl),u.append(x);}else {u.textContent=i==="ai"?this.strings.aiLabel:q(this.agentName(t));let x=i==="agent"?(g=(m=this.appearance.team)==null?void 0:m.find(E=>E.name===t.authorName))==null?void 0:g.tone:void 0;x&&(u.style.background=x);}a.append(u);}let c=document.createElement("div");if(c.className="body",i==="end_user"){r&&this.drawFile(c,r.name,r.type,r.size,Promise.resolve(r));for(let u of (v=t.attachments)!=null?v:[])this.drawFile(c,u.name,u.contentType,u.bytes,(b=(f=(S=this.client).file)==null?void 0:f.call(S,u.url))!=null?b:Promise.resolve(null));}let p=i!=="end_user"&&o.namePlacement!=="hidden",d=document.createElement("div");if(i==="ai"?Ze(d,t.body):d.textContent=t.body,p||i==="ai"&&o.namePlacement==="hidden"){let u=document.createElement("div");u.className=i==="ai"?"author ai":"author",u.textContent=i==="ai"?this.strings.aiLabel:this.agentName(t),o.stampPlacement==="beside_name"&&u.append(this.stamp(t)),o.namePlacement==="inline"?(u.classList.add("below"),c.append(d,u)):c.append(u,d);}else t.body&&c.append(d);return o.stampPlacement==="under_turn"&&c.append(this.stamp(t)),a.append(c),e.append(a),e.scrollTop=e.scrollHeight,a}drawFile(e,t,r,i,o){let a=document.createElement("a");if(r==="application/pdf"){a.className="pdfc",a.download=t;let s=document.createElement("b");s.textContent="PDF",a.append(s,`${t} \xB7 ${O(i)}`);}else {a.className="att",a.target="_blank",a.rel="noopener noreferrer";let s=document.createElement("img");s.alt=t,s.addEventListener("load",()=>{let c=a.closest(".log");c&&(c.scrollTop=c.scrollHeight);}),a.append(s);}e.append(a),o.then(s=>{var c;s&&(a.href=this.objectUrl(s),(c=a.querySelector("img"))==null||c.setAttribute("src",a.href));});}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 o=i[0],a=i[i.length-1],s=this.root.activeElement;e.shiftKey&&s===o?(e.preventDefault(),a.focus()):!e.shiftKey&&s===a?(e.preventDefault(),o.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 V(n){return `40${JSON.stringify(n)}`}function Q(){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 a=U(t);return {kind:"open",pingInterval:typeof(a==null?void 0:a.pingInterval)=="number"?a.pingInterval:25e3,pingTimeout:typeof(a==null?void 0:a.pingTimeout)=="number"?a.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 a=U(i);return {kind:"connectError",message:typeof(a==null?void 0:a.message)=="string"?a.message:"refused"}}if(r!=="2")return {kind:"other"};let o=U(i);return !Array.isArray(o)||typeof o[0]!="string"?{kind:"other"}:{kind:"event",name:o[0],payload:o[1]}}function U(n){try{return JSON.parse(n)}catch(e){return null}}var it="/socket.io/?EIO=4&transport=websocket",M=class{constructor(e){this.options=e;h(this,"socket",null);h(this,"heartbeat",null);h(this,"ready",false);h(this,"closed",false);h(this,"heartbeatWindow",45e3);h(this,"factory");h(this,"setTimer");h(this,"clearTimer");var t,r,i;this.factory=(t=e.socketFactory)!=null?t:at,this.setTimer=(r=e.setTimer)!=null?r:((o,a)=>setTimeout(o,a)),this.clearTimer=(i=e.clearTimer)!=null?i:(o=>clearTimeout(o));}open(){if(this.socket||this.closed)return;let e=`${this.options.host.replace(/^http/,"ws").replace(/\/+$/,"")}${it}`,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,o,a;let t=Z(e);if(t.kind==="open"){this.armHeartbeat(t.pingInterval+t.pingTimeout),(r=this.socket)==null||r.send(V(this.options.auth));return}if(t.kind==="ping"){this.armHeartbeat(),(i=this.socket)==null||i.send(Q());return}if(t.kind==="connectError"||t.kind==="disconnect"){this.stopHeartbeat(),(o=this.socket)==null||o.close();return}if(t.kind==="event"){if(t.name==="ready"){this.ready=true,this.options.onReady();return}if(t.name==="conversation.turn"){let s=(a=t.payload)==null?void 0:a.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 at(n){let e=globalThis.WebSocket;if(!e)throw new Error("no WebSocket");return new e(n)}var ot=6e4;function ee(n){var b,u,x,E;let e=globalThis.document;if(!e)throw new Error("prodantix chat requires a document; mount it in the browser");let t=(b=n.mountPoint)!=null?b:e.createElement("div");n.mountPoint||e.body.append(t);let r=new N(n),i=new I(t,r,n.strings,n.appearance),o=(x=(u=n.appearance)==null?void 0:u.availability)!=null?x:T.availability,a,s=()=>{i.setOpenNow(_(o,new Date)),a=setTimeout(s,ot);};s();let c=new Set,p,d=null,l=(E=n.pollIntervalMs)!=null?E:15e3,m=y=>{c.has(y.id)||y.authorKind==="end_user"||(c.add(y.id),i.onIncomingTurn(y));},g=async()=>{if(!r.hasThread)return;let y=await r.load();if(y){for(let w of y.turns)m(w);c=new Set(y.turns.map(w=>w.id));}},v=()=>{p||l<=0||(p=setInterval(()=>void g(),l));},S=()=>{p&&clearInterval(p),p=void 0;},f=()=>{if(d||!n.socketHost)return;let y=r.socketAuth;y&&(d=new M({auth:y,host:n.socketHost,onClosed:w=>{d=null,v(),w&&f();},onReady:S,onTurn:m,socketFactory:n.socketFactory}),d.open());};return v(),f(),{close:()=>i.close(),destroy:()=>{S(),clearTimeout(a),d==null||d.close(),d=null,i.close(),t.remove();},identify:y=>r.identify(y),open:()=>{i.open().then(f);}}}var st="prodantix.messenger.config",te=n=>{var t,r,i,o;let e=(t=n.navigator)==null?void 0:t.languages;return Array.isArray(e)&&e.length>0?e.join(","):((r=n.navigator)==null?void 0:r.language)||((o=(i=n.document)==null?void 0:i.documentElement)==null?void 0:o.lang)||void 0},ne=(n,e)=>`${st}:${n}:${e!=null?e:""}`;function re(n,e,t){let r=n==null?void 0:n.get(ne(e,t));if(!r)return null;try{let i=JSON.parse(r);return (i==null?void 0:i.apiKey)===e?i.config:null}catch(i){return null}}async function ie(n){var o,a,s,c,p;let e=L(n.fetchImpl);if(!e)return (o=n.onError)==null||o.call(n,new Error("no fetch available for the prodantix messenger")),null;let t=P(n.host),r=ne(n.apiKey,n.locale),i=n.locale?`?locale=${encodeURIComponent(n.locale)}`:"";try{let d=await e(`${t}/v1/messenger/config${i}`,{headers:{authorization:`Bearer ${n.apiKey}`},method:"GET"});if(!d.ok)return (a=n.onError)==null||a.call(n,new Error(`prodantix messenger config: ${d.status}`)),null;let l=JSON.parse(await d.text());return l.enabled?((c=n.storage)==null||c.set(r,JSON.stringify({apiKey:n.apiKey,config:l})),l):((s=n.storage)==null||s.remove(r),l)}catch(d){return (p=n.onError)==null||p.call(n,d),null}}var lt=["close","identify","open","shutdown","toggle"],A="[prodantix/messenger]";function ct(n,e){for(let t of n){let[r,...i]=t!=null?t:[];typeof r!="string"||!lt.includes(r)||e(r,...i);}}function dt(n){if(!n)return null;try{return new URL(n).origin}catch(e){return null}}async function oe(n,e={}){var g,v,S;let t=(g=e.warn)!=null?g:(f=>console.warn(f)),r=n.prodantix,i=r==null?void 0:r.k;if(!i)return t(`${A} no project key on the install snippet; nothing will load.`),null;let o=dt((v=e.scriptSrc)!=null?v:pt(n));if(!o)return t(`${A} could not tell which host served this script; nothing will load.`),null;let a=ut(n),s=te(n),c=re(a,i,s),p=await ie({apiKey:i,host:o,locale:s,onError:f=>t(`${A} settings could not be read: ${String(f)}`),storage:a}),d=p!=null?p:c;if(!d)return t(`${A} no settings available; the messenger will not render.`),null;if(!d.enabled)return null;let l=ee({apiKey:i,appearance:d,distinctId:mt(n,a),host:o,socketHost:d.socketUrl||void 0}),m=(f,...b)=>{if((f==="open"||f==="toggle")&&l.open(),f==="close"&&l.close(),f==="shutdown"&&l.destroy(),f==="identify"){let u=ht(b[0]);if(!u){console.error(`${A} 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}l.identify(u);}};return ct((S=r==null?void 0:r.q)!=null?S:[],m),n.prodantix=Object.assign((f,...b)=>m(f,...b),{k:i,q:[]}),l}function pt(n){var t;let e=(t=n.document)==null?void 0:t.currentScript;return e==null?void 0:e.src}function ut(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 ht(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 ae="prodantix.messenger.anon";function mt(n,e){var i,o,a;let t=e==null?void 0:e.get(ae);if(t)return t;let r=`anon_${(a=(o=(i=n.crypto)==null?void 0:i.randomUUID)==null?void 0:o.call(i))!=null?a:Math.random().toString(36).slice(2)}`;return e==null||e.set(ae,r),r}oe(globalThis);})();//# sourceMappingURL=messenger.iife.js.map
|
|
156
99
|
//# sourceMappingURL=messenger.iife.js.map
|
package/dist/messenger.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a,d
|
|
1
|
+
import {a,d}from'./chunk-VG77TYVX.js';import'./chunk-5XGN7UAV.js';var l="prodantix.messenger.config",h=e=>{let r=e.navigator?.languages;return Array.isArray(r)&&r.length>0?r.join(","):e.navigator?.language||e.document?.documentElement?.lang||void 0},g=(e,r)=>`${l}:${e}:${r??""}`;function u(e,r,s){let t=e?.get(g(r,s));if(!t)return null;try{let a=JSON.parse(t);return a?.apiKey===r?a.config:null}catch{return null}}async function m(e){let r=a(e.fetchImpl);if(!r)return e.onError?.(new Error("no fetch available for the prodantix messenger")),null;let s=d(e.host),t=g(e.apiKey,e.locale),a$1=e.locale?`?locale=${encodeURIComponent(e.locale)}`:"";try{let n=await r(`${s}/v1/messenger/config${a$1}`,{headers:{authorization:`Bearer ${e.apiKey}`},method:"GET"});if(!n.ok)return e.onError?.(new Error(`prodantix messenger config: ${n.status}`)),null;let o=JSON.parse(await n.text());return o.enabled?(e.storage?.set(t,JSON.stringify({apiKey:e.apiKey,config:o})),o):(e.storage?.remove(t),o)}catch(n){return e.onError?.(n),null}}export{l as MESSENGER_CACHE_KEY,g as cacheKeyFor,u as cachedMessengerConfig,m as fetchMessengerConfig,h as localeCandidates};//# sourceMappingURL=messenger.js.map
|
|
2
2
|
//# sourceMappingURL=messenger.js.map
|
package/package.json
CHANGED