@prodantix/sdk 0.4.2 → 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 +25 -81
- package/dist/chat.d.cts +15 -5
- package/dist/chat.d.ts +15 -5
- package/dist/chat.js +14 -70
- package/dist/{config-D8-uiWM8.d.cts → config-CM4nTGof.d.cts} +37 -3
- package/dist/{config-DGUsxWOL.d.ts → config-DJX2zFaa.d.ts} +37 -3
- 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 +23 -79
- package/dist/messenger.js +1 -1
- package/package.json +3 -3
package/dist/chat.js
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
import {c,a as a$2,b}from'./chunk-V77KYPOF.js';import {a as a$1,d}from'./chunk-VG77TYVX.js';import {a}from'./chunk-5XGN7UAV.js';var q="X-Prodantix-Conversation-Token",L="prodantix.chat.handle";function K(){let r=globalThis.localStorage;if(r)return {get:e=>r.getItem(e),remove:e=>r.removeItem(e),set:(e,t)=>r.setItem(e,t)}}var k=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??K(),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(L,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(L);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(L),null}async request(e,t,n={}){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"};n.token&&(o[q]=n.token);try{let d=await a(`${this.host}${t}`,{body:n.body===void 0?void 0:JSON.stringify(n.body),headers:o,method:e}),i=await d.text();return d.ok?i?JSON.parse(i):{}:(this.options.onError?.(new Error(`prodantix chat ${t}: ${d.status}`)),null)}catch(d){return this.options.onError?.(d),null}}};var j={Fri:"fri",Mon:"mon",Sat:"sat",Sun:"sun",Thu:"thu",Tue:"tue",Wed:"wed"};function T(r,e){let t=new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:false,minute:"2-digit",timeZone:r.timezone,weekday:"short"}).formatToParts(e),n=j[t.find(i=>i.type==="weekday")?.value??""];if(!n)return false;let a=t.find(i=>i.type==="hour")?.value??"",o=t.find(i=>i.type==="minute")?.value??"",d=`${a}:${o}`;return r.windows.some(i=>i.days.includes(n)&&i.open<=d&&d<i.close)}var u={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"},W=["quiet","standard"],Y=["round","square"],G=["rounded","tailed"],X=["filled","outlined"],V=["circle","pill","squircle"],Z=["filled","outlined"],J=["avatar","glyph","team_faces"],Q=["large","medium","small"],ee=["above","hidden","inline"],te=["beside_name","none","under_turn"],ne=["time","time_and_latency"],f=(r,e,t)=>typeof r=="string"&&e.includes(r)?r:t,$=(r,e)=>typeof r=="boolean"?r: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"]},re={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 C(r){let e=typeof r=="object"&&r!==null?r:{},t=typeof e.launcherStyle=="string"?e.launcherStyle:void 0,n=t===void 0?void 0:ae[t],a=typeof e.namePlacement=="string"?e.namePlacement:void 0,o=a===void 0?void 0:re[a],d=typeof e.timestampStyle=="string"?e.timestampStyle:void 0,i=d===void 0?void 0:ie[d],h=typeof e.skin=="string"?e.skin:void 0,c=h===void 0?void 0:oe[h],l=typeof e.bubbleStyle=="string"?e.bubbleStyle:void 0,p=l===void 0?void 0:se[l],m={bubbleFill:f(e.bubbleFill,X,p?.[1]??u.bubbleFill),bubbleShape:f(e.bubbleShape,G,p?.[0]??u.bubbleShape),composerShape:f(e.composerShape,Y,c?.[1]??u.composerShape),dayDividers:$(e.dayDividers,i?.[0]??u.dayDividers),launcherContent:f(e.launcherContent,J,n?.[2]??u.launcherContent),launcherFill:f(e.launcherFill,Z,n?.[1]??u.launcherFill),launcherShape:f(e.launcherShape,V,n?.[0]??u.launcherShape),launcherSize:f(e.launcherSize,Q,n?.[3]??u.launcherSize),nameAvatar:$(e.nameAvatar,o?.[1]??u.nameAvatar),namePlacement:f(e.namePlacement,ee,o?.[0]??u.namePlacement),skin:f(e.skin,W,c?.[0]??u.skin),stampContent:f(e.stampContent,ne,i?.[2]??u.stampContent),stampPlacement:f(e.stampPlacement,te,i?.[1]??u.stampPlacement)};return m.stampPlacement==="beside_name"&&m.namePlacement==="hidden"&&(m.stampPlacement="under_turn"),m}function z(r){let e=r.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 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",de={large:66,medium:56,small:46},ce={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);"},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;}"},ue=".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 B(r,e,t,n){return `.launcher{--fab-size:${de[n]}px;${ce[r]}${pe[e]}}${he[t]}${ue}${me[r]}${ge[e]}${fe[r]}${be[r]}`}function O(r,e,t,n=a=>a){let a=document.createDocumentFragment();if(r==="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="${le}"/></svg>`,a.append(...o.childNodes,P()),a}return r==="avatar"?(a.append(U(t[0],e,n),P()),a):(a.append(_(t,e,n),P()),a)}function _(r,e,t=a=>a,n=true){let a=document.createElement("span");a.className="faces";for(let o of r.slice(0,2))a.append(U(o,e,t,n));return a}function U(r,e,t,n=true){let a=document.createElement("span");if(a.className="av",a.setAttribute("aria-hidden","true"),r&&n&&(a.style.background=r.tone),r?.avatarUrl){let o=document.createElement("img");return o.alt="",o.src=t(r.avatarUrl),a.append(o),a}return a.textContent=r?r.initials:e.agentLabel.slice(0,2).toUpperCase(),a}function P(){let r=document.createElement("span");return r.className="live",r.setAttribute("aria-hidden","true"),r}var ye={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:r=>{let e=new Date(r);return Number.isNaN(e.getTime())?"":`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`},title:"Support",unreadLabel:r=>`${r} unread`},x={accentColor:"#5b5bff",availability:{timezone:"UTC",windows:[]},awayMessage:"",greeting:"",launcherOffsetX:20,launcherOffsetY:20,launcherPosition:"bottom_right",starterPrompts:[],team:[],...u},xe={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}"},ve={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}"},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}"},we=".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}",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)}',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}"},Ae=".lat{font-size:11px;opacity:.7;margin-left:6px}",D=`--paper: oklch(24.6% 0.015 257); --ink: #fff; --ink-3: rgba(255,255,255,.55);
|
|
1
|
+
import {c,a as a$2,b}from'./chunk-V77KYPOF.js';import {a as a$1,d}from'./chunk-VG77TYVX.js';import {a}from'./chunk-5XGN7UAV.js';var U="X-Prodantix-Conversation-Token",A="prodantix.chat.handle";function G(){let r=globalThis.localStorage;if(r)return {get:e=>r.getItem(e),remove:e=>r.removeItem(e),set:(e,t)=>r.setItem(e,t)}}var C=class{constructor(e){this.options=e;a(this,"fetchImpl");a(this,"fileFetchImpl");a(this,"host");a(this,"storage");a(this,"handle");a(this,"identity",null);this.fetchImpl=a$1(e.fetchImpl),this.fileFetchImpl=e.fileFetchImpl??((t,n)=>fetch(t,n)),this.host=d(e.host),this.storage=e.storage??G(),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(A,JSON.stringify(this.handle)),true)}async send(e,t,n){if(!await this.ensureThread())return null;let a=this.handle;return a?(await this.request("POST",`/v1/conversations/${encodeURIComponent(a.conversationId)}/turns`,{body:{attachmentIds:n,body:e,pageContext:t},token:a.token}))?.turn??null: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 n=>JSON.parse(await n.text()),e):null}async file(e){let t=this.handle;return t?this.fileRequest("GET",e,t.token,n=>n.blob()):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 fileRequest(e,t,n,a,o){let i={authorization:`Bearer ${this.options.apiKey}`,[U]:n};o&&(i["content-type"]=o.type||"application/octet-stream");try{let s=await this.fileFetchImpl(`${this.host}${t}`,{body:o,headers:i,method:e});if(s.ok)return await a(s);this.options.onError?.(new Error(`prodantix chat ${t}: ${s.status}`));}catch(s){this.options.onError?.(s);}return null}async request(e,t,n={}){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"};n.token&&(o[U]=n.token);try{let i=await a(`${this.host}${t}`,{body:n.body===void 0?void 0:JSON.stringify(n.body),headers:o,method:e}),s=await i.text();return i.ok?s?JSON.parse(s):{}:(this.options.onError?.(new Error(`prodantix chat ${t}: ${i.status}`)),null)}catch(i){return this.options.onError?.(i),null}}};var Y={Fri:"fri",Mon:"mon",Sat:"sat",Sun:"sun",Thu:"thu",Tue:"tue",Wed:"wed"};function L(r,e){let t=new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:false,minute:"2-digit",timeZone:r.timezone,weekday:"short"}).formatToParts(e),n=Y[t.find(s=>s.type==="weekday")?.value??""];if(!n)return false;let a=t.find(s=>s.type==="hour")?.value??"",o=t.find(s=>s.type==="minute")?.value??"",i=`${a}:${o}`;return r.windows.some(s=>s.days.includes(n)&&s.open<=i&&i<s.close)}var g={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"},W=["quiet","standard"],J=["round","square"],X=["rounded","tailed"],Z=["filled","outlined"],V=["circle","pill","squircle"],Q=["filled","outlined"],ee=["avatar","glyph","team_faces"],te=["large","medium","small"],ne=["above","hidden","inline"],ae=["beside_name","none","under_turn"],re=["time","time_and_latency"],x=(r,e,t)=>typeof r=="string"&&e.includes(r)?r:t,B=(r,e)=>typeof r=="boolean"?r:e,ie={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"]},oe={above:["above",false],avatar_only:["hidden",true],gutter:["above",true],hidden:["hidden",false],inline:["inline",false]},se={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"]},le={concierge:["standard","round"],console:["standard","square"],quiet:["quiet","square"]},ce={hairline:["rounded","outlined"],outlined:["rounded","outlined"],rounded:["rounded","filled"],tailed:["tailed","filled"]};function E(r){let e=typeof r=="object"&&r!==null?r:{},t=typeof e.launcherStyle=="string"?e.launcherStyle:void 0,n=t===void 0?void 0:ie[t],a=typeof e.namePlacement=="string"?e.namePlacement:void 0,o=a===void 0?void 0:oe[a],i=typeof e.timestampStyle=="string"?e.timestampStyle:void 0,s=i===void 0?void 0:se[i],d=typeof e.skin=="string"?e.skin:void 0,h=d===void 0?void 0:le[d],p=typeof e.bubbleStyle=="string"?e.bubbleStyle:void 0,l=p===void 0?void 0:ce[p],m={bubbleFill:x(e.bubbleFill,Z,l?.[1]??g.bubbleFill),bubbleShape:x(e.bubbleShape,X,l?.[0]??g.bubbleShape),composerShape:x(e.composerShape,J,h?.[1]??g.composerShape),dayDividers:B(e.dayDividers,s?.[0]??g.dayDividers),launcherContent:x(e.launcherContent,ee,n?.[2]??g.launcherContent),launcherFill:x(e.launcherFill,Q,n?.[1]??g.launcherFill),launcherShape:x(e.launcherShape,V,n?.[0]??g.launcherShape),launcherSize:x(e.launcherSize,te,n?.[3]??g.launcherSize),nameAvatar:B(e.nameAvatar,o?.[1]??g.nameAvatar),namePlacement:x(e.namePlacement,ne,o?.[0]??g.namePlacement),skin:x(e.skin,W,h?.[0]??g.skin),stampContent:x(e.stampContent,re,s?.[2]??g.stampContent),stampPlacement:x(e.stampPlacement,ae,s?.[1]??g.stampPlacement)};return m.stampPlacement==="beside_name"&&m.namePlacement==="hidden"&&(m.stampPlacement="under_turn"),m}function O(r){let e=r.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 de="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",pe={large:66,medium:56,small:46},he={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);"},me={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;}"},ge=".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}",fe={circle:"",pill:".badge{position:static;box-shadow:none}",squircle:""},be={filled:"",outlined:".badge{background:var(--a);top:-7px;right:-7px;min-width:19px;height:19px;font-size:11.5px}"},xe={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 D(r,e,t,n){return `.launcher{--fab-size:${pe[n]}px;${he[r]}${ue[e]}}${me[t]}${ge}${fe[r]}${be[e]}${xe[r]}${ye[r]}`}function q(r,e,t,n=a=>a){let a=document.createDocumentFragment();if(r==="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="${de}"/></svg>`,a.append(...o.childNodes,P()),a}return r==="avatar"?(a.append(K(t[0],e,n),P()),a):(a.append(_(t,e,n),P()),a)}function _(r,e,t=n=>n){let n=document.createElement("span");n.className="faces";for(let a of r.slice(0,2))n.append(K(a,e,t));return n}function K(r,e,t){let n=document.createElement("span");if(n.className="av",n.setAttribute("aria-hidden","true"),r&&(n.style.background=r.tone),r?.avatarUrl){let a=document.createElement("img");return a.alt="",a.src=t(r.avatarUrl),n.append(a),n}return n.textContent=r?r.initials:e.agentLabel.slice(0,2).toUpperCase(),n}function P(){let r=document.createElement("span");return r.className="live",r.setAttribute("aria-hidden","true"),r}var ve={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:(r,e)=>`That file is ${r}. 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:r=>{let e=new Date(r);return Number.isNaN(e.getTime())?"":`${String(e.getHours()).padStart(2,"0")}:${String(e.getMinutes()).padStart(2,"0")}`},title:"Support",unreadLabel:r=>`${r} unread`},k={accentColor:"#5b5bff",availability:{timezone:"UTC",windows:[]},awayMessage:"",greeting:"",launcherOffsetX:20,launcherOffsetY:20,launcherPosition:"bottom_right",starterPrompts:[],team:[],...g},Se={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}"},ke={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}"},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)}"},we={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}"},Le=".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}",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}"},Pe=".lat{font-size:11px;opacity:.7;margin-left:6px}",_e=".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 Ne(r){let e=r==="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 N(r){return r<999500?`${Math.max(1,Math.round(r/1e3))} KB`:`${(r/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 Fe(r){return r==="light"?"":r==="dark"?`:host { ${j} }`:`@media (prefers-color-scheme: dark) {
|
|
4
4
|
:host {
|
|
5
|
-
${
|
|
5
|
+
${j}
|
|
6
6
|
}
|
|
7
|
-
}`}function
|
|
7
|
+
}`}var He=/https?:\/\/[^\s<>"]+/g,Ie=/[.,;:!?)]$/,Re=r=>{let e=r;for(;Ie.test(e);){let t=e.split("(").length-1,n=e.split(")").length-1;if(e.endsWith(")")&&t>=n)break;e=e.slice(0,-1);}return e};function $e(r,e){let t=0;for(let n of e.matchAll(He)){let a=n.index??0,o=Re(n[0]);a>t&&r.append(e.slice(t,a));let i=document.createElement("a");i.href=o,i.target="_blank",i.rel="noopener noreferrer",i.textContent=o,r.append(i),t=a+o.length;}t<e.length&&r.append(e.slice(t));}function F(r,e="system"){let t=E(r),n=r.launcherPosition==="bottom_left"?"left":"right",a=r.accentColor;return `${`
|
|
8
8
|
:host {
|
|
9
|
-
/* The widget sits above the host page's own furniture. The reset above sends
|
|
10
|
-
z-index back to auto, so without this the launcher and panel stack at the
|
|
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
9
|
all: initial; z-index: 2147483000; --a: ${a};
|
|
16
|
-
--paper: #fff; --ink: #0f172a; --ink-3:
|
|
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
|
+
${Fe(e)}
|
|
22
16
|
* { box-sizing: border-box; font-family: system-ui, sans-serif; }
|
|
23
17
|
.launcher {
|
|
24
18
|
z-index: 2147483000; position: fixed; ${n}: ${r.launcherOffsetX}px; bottom: ${r.launcherOffsetY}px; width: 56px; height: 56px;
|
|
@@ -28,11 +22,6 @@ ${Le(e)}
|
|
|
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
26
|
.launcher:hover { background: color-mix(in srgb, #000 12%, ${a}); }
|
|
38
27
|
.launcher:active { background: color-mix(in srgb, #000 20%, ${a}); }
|
|
@@ -44,12 +33,6 @@ ${Le(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; ${n}: ${r.launcherOffsetX}px; bottom: ${r.launcherOffsetY+68}px; width: 360px; max-width: calc(100vw - 40px);
|
|
@@ -59,64 +42,35 @@ ${Le(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
|
-
|
|
67
|
-
arrives as the project accent and would be this header's own colour. Mixed
|
|
68
|
-
down from the accent rather than a fixed colour so it still belongs to the
|
|
69
|
-
project's palette, and the ring stays the accent because its job is to part
|
|
70
|
-
two OVERLAPPING discs from each other and from the header behind them. */
|
|
71
|
-
.header .av { width: 36px; height: 36px; background: color-mix(in srgb, #000 30%, var(--a)); box-shadow: 0 0 0 2px var(--a); }
|
|
46
|
+
.header .av { width: 36px; height: 36px; box-shadow: 0 0 0 2px var(--a); }
|
|
72
47
|
.header .av + .av { margin-left: -12px; }
|
|
73
48
|
.headmain { display: flex; flex-direction: column; }
|
|
74
49
|
.header .status { display: flex; align-items: center; gap: 6px; margin: 5px 0 0; font-size: 12.5px; color: rgb(255 255 255 / 80%); }
|
|
75
|
-
/* The dot's ring is the PAPER, not the accent. An accent ring on the standard
|
|
76
|
-
skin is the header's own background and draws nothing, which is how this
|
|
77
|
-
shipped looking ringless beside a preview that had one. The faces above keep
|
|
78
|
-
the accent ring, which is a different job: separating two overlapping discs
|
|
79
|
-
from each other and from the header. */
|
|
80
50
|
.header .status .live { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--online); box-shadow: 0 0 0 2px var(--paper); }
|
|
81
|
-
/* Hours, the same fact the launcher's dot carries. A green dot and a sentence
|
|
82
|
-
promising a reply in minutes are both claims about somebody being there, so
|
|
83
|
-
outside the project's hours neither is drawn: the away message in the thread
|
|
84
|
-
is what speaks then. */
|
|
85
51
|
.panel.closed .status { display: none; }
|
|
86
|
-
/* Pinned rather than laid out: the standard skin turns this header into a
|
|
87
|
-
column so the title can carry a line under it, and a close button that is
|
|
88
|
-
merely a flex sibling then stacks BELOW the title on the left, which is where
|
|
89
|
-
clepit's landing showed it. */
|
|
90
52
|
.header .close { position: absolute; top: 8px; right: 8px; }
|
|
91
|
-
/* The fleet's icon button: a padded square, a radius, and a hover that tints
|
|
92
|
-
the background. This carried none of them, so the messenger's close was the
|
|
93
|
-
one icon button in the product with no radius and no hover at all. The tint
|
|
94
|
-
is mixed from currentColor rather than a fixed white because the header is
|
|
95
|
-
the accent on some skins and the paper on others. */
|
|
96
53
|
.close {
|
|
97
54
|
display: inline-flex; align-items: center; justify-content: center;
|
|
98
55
|
width: 32px; height: 32px; padding: 0;
|
|
99
56
|
background: none; border: none; border-radius: 8px;
|
|
100
|
-
color: inherit; cursor: pointer;
|
|
57
|
+
color: inherit; cursor: pointer;
|
|
101
58
|
transition: background-color 120ms ease;
|
|
102
59
|
}
|
|
60
|
+
.close svg { display: block; width: 22px; height: 22px; }
|
|
103
61
|
.close:hover { background: color-mix(in srgb, currentColor 14%, transparent); }
|
|
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
65
|
.turn.end_user { align-self: flex-end; background: ${a}; color: #fff; }
|
|
108
66
|
.turn.agent, .turn.ai { align-self: flex-start; background: var(--fill); color: var(--ink); }
|
|
67
|
+
.turn.ai a { color: ${a}; 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 {
|
|
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: ${a}; background: color-mix(in srgb, ${a} 12%, transparent); border-radius: 4px; }
|
|
73
|
+
.awayglyph { flex: none; width: 16px; height: 16px; margin-top: 1px; border: 1.5px solid currentColor; border-radius: 50%; }
|
|
120
74
|
.empty { display: flex; flex-direction: column; gap: 8px; padding: 20px 16px; }
|
|
121
75
|
.empty h3 { margin: 0; font-size: 18px; font-weight: 640; letter-spacing: -.015em; }
|
|
122
76
|
.empty p { margin: 0 0 8px; font-size: 13.5px; color: var(--ink-2); }
|
|
@@ -126,19 +80,9 @@ ${Le(e)}
|
|
|
126
80
|
background: none; border: 1px solid var(--hairline); border-radius: 8px; cursor: pointer;
|
|
127
81
|
}
|
|
128
82
|
.prompt:focus-visible { outline: 2px solid ${a}; outline-offset: 2px; }
|
|
129
|
-
.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:
|
|
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); }
|
|
130
84
|
.av.bot { border-radius: 9px; background: var(--fill); color: var(--ink); }
|
|
131
85
|
.av img { width: 100%; height: 100%; display: block; object-fit: cover; border-radius: inherit; }
|
|
132
|
-
/* 36px, against a message bubble measured at 33px in the panel (14px type,
|
|
133
|
-
8px of padding, rendered). The field was 46px round and 44px square, half
|
|
134
|
-
again the height of anything it produced, which is what read as too much air
|
|
135
|
-
inside it; 36 sits a hair above a bubble, which is the room a field wants for
|
|
136
|
-
a caret and a placeholder and a bubble does not. The type stays at 14px, the
|
|
137
|
-
same size the messages are set in: the box came down, not the words.
|
|
138
|
-
|
|
139
|
-
No backtick in this comment, or in any other inside this sheet. It is a
|
|
140
|
-
template literal, so one ends the string and the rest of the CSS becomes a
|
|
141
|
-
tagged-template call. Writing a selector as code here cost 124 tests. */
|
|
142
86
|
.composer { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--hairline); }
|
|
143
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); }
|
|
144
88
|
.composer input:focus-visible { outline: 2px solid ${a}; }
|
|
@@ -151,5 +95,5 @@ ${Le(e)}
|
|
|
151
95
|
.panel { animation: rise 180ms ease-out; }
|
|
152
96
|
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
|
|
153
97
|
}
|
|
154
|
-
`}${ve[t.composerShape]}${xe[t.skin]}${B(t.launcherShape,t.launcherFill,t.launcherContent,t.launcherSize)}${Se[t.bubbleShape]}${ke[t.bubbleFill]}${Ce[t.namePlacement]}${t.nameAvatar?we:""}${t.dayDividers?Te:""}${Ee[t.stampPlacement]}${t.stampContent==="time_and_latency"?Ae:""}`}var Pe=["end_user","agent","ai"];function _e(){let r=globalThis.location;if(r)return {host:r.host,path:r.pathname,title:document.title}}var w=class{constructor(e,t,n={},a$1={},o={}){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);a(this,"pendingTurns",0);a(this,"openNow");a(this,"style");a(this,"scheme");this.strings={...ye,...n},this.appearance={...x,...a$1},this.settings=C({...x,...a$1}),this.root=e.attachShadow({mode:o.shadowMode??"closed"}),this.openNow=T(this.appearance.availability,new Date),this.scheme=o.scheme,this.style=document.createElement("style"),this.style.textContent=N(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(O(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={...x,...e},this.settings=C(this.appearance),t!==void 0&&(this.scheme=t),this.style.textContent=N(this.appearance,this.scheme),this.drawLauncher(),this.panel&&(this.close(),this.open());}toggle(){this.panel?this.close():this.open();}setOpenNow(e){this.openNow=e,this.launcher.classList.toggle("closed",!e),this.panel?.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=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 n=this.appearance.team??[];n.length>0&&t.append(_(n,this.strings,b=>this.client.avatarUrl(b),false));let a=document.createElement("div");a.className="headmain";let o=document.createElement("h2");o.textContent=this.strings.title;let d=document.createElement("p");d.className="status";let i=document.createElement("span");i.className="live",i.setAttribute("aria-hidden","true"),d.append(i,this.strings.replyTime),a.append(o,d);let h=document.createElement("button");h.className="close",h.type="button",h.setAttribute("aria-label",this.strings.closeLabel),h.textContent="\xD7",h.addEventListener("click",()=>this.close()),t.append(a,h);let c=document.createElement("div");c.className="log",c.setAttribute("role","log"),c.setAttribute("aria-live","polite"),c.setAttribute("aria-label",this.strings.title);let l=document.createElement("form");l.className="composer";let p=document.createElement("input");p.type="text",p.setAttribute("aria-label",this.strings.inputPlaceholder),p.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 v=document.createElement("span");v.className="sendtext",v.textContent=this.strings.sendLabel,m.append(v),l.append(p,m),l.addEventListener("submit",b=>{b.preventDefault(),this.submit(p,c);}),e.append(t,c,l),e.addEventListener("keydown",b=>this.onKeydown(b,e,h)),this.root.append(e),this.panel=e,p.focus();let y=await this.client.load();y&&y.turns.length>0?this.renderThread(c,y):this.renderFirstRun(c,p),this.openNow||this.renderAway(c);}renderFirstRun(e,t){let n=document.createElement("div");n.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,n.append(a,o);for(let d of this.appearance.starterPrompts){let i=document.createElement("button");i.className="prompt",i.type="button",i.textContent=d,i.addEventListener("click",()=>{t.value=d,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.trim()||this.strings.awayBody,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.hasTurn(t,e.id)&&this.appendTurn(t,e);return}e.authorKind!=="end_user"&&(this.unread+=1,this.renderBadge());}async submit(e,t){let n=e.value.trim();n&&(e.value="",await this.sendBody(t,n));}async sendBody(e,t){e.querySelector(".empty")?.remove(),this.pendingTurns+=1;let n=this.appendTurn(e,{authorId:null,authorKind:"end_user",body:t,createdAt:new Date().toISOString(),id:`pending-${this.pendingTurns}`});n.setAttribute("data-pending","");let a=await this.client.send(t,_e());if(n.removeAttribute("data-pending"),a){n.dataset.turnId=a.id;return}this.markFailed(e,n,t);}markFailed(e,t,n){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,n);}),(t.querySelector(".body")??t).append(a);}hasTurn(e,t){for(let n of e.children)if(n instanceof HTMLElement&&n.dataset.turnId===t)return true;return false}renderThread(e,t){e.replaceChildren();for(let n of t.turns)this.appendTurn(e,n);}appendTurn(e,t){e.querySelector(".empty")?.remove();let n=Pe.includes(t.authorKind)?t.authorKind:"agent",a=this.settings,o=document.createElement("div");if(o.className=`turn ${n}`,o.dataset.turnId=t.id,n!=="end_user"&&a.nameAvatar){let l=document.createElement("span");if(l.className=n==="ai"?"av bot":"av",l.setAttribute("aria-hidden","true"),n==="agent"&&t.authorAvatarUrl){let p=document.createElement("img");p.alt="",p.src=this.client.avatarUrl(t.authorAvatarUrl),l.append(p);}else l.textContent=n==="ai"?this.strings.aiLabel:z(this.agentName(t));o.append(l);}let i=document.createElement("div");i.className="body";let h=n!=="end_user"&&a.namePlacement!=="hidden",c=document.createElement("div");if(c.textContent=t.body,h||n==="ai"&&a.namePlacement==="hidden"){let l=document.createElement("div");l.className=n==="ai"?"author ai":"author",l.textContent=n==="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(c,l)):i.append(l,c);}else i.append(c);return a.stampPlacement==="under_turn"&&i.append(this.stamp(t)),o.append(i),e.append(o),e.scrollTop=e.scrollHeight,o}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 a=t.querySelectorAll('button, input, [tabindex]:not([tabindex="-1"])');if(a.length===0)return;let o=a[0],d=a[a.length-1],i=this.root.activeElement;e.shiftKey&&i===o?(e.preventDefault(),d.focus()):!e.shiftKey&&i===d?(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 Ne="/socket.io/?EIO=4&transport=websocket",E=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??He,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(/\/+$/,"")}${Ne}`,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());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 He(r){let e=globalThis.WebSocket;if(!e)throw new Error("no WebSocket");return new e(r)}var Ie=6e4;function Je(r){let e=globalThis.document;if(!e)throw new Error("prodantix chat requires a document; mount it in the browser");let t=r.mountPoint??e.createElement("div");r.mountPoint||e.body.append(t);let n=new k(r),a=new w(t,n,r.strings,r.appearance),o=r.appearance?.availability??x.availability,d,i=()=>{a.setOpenNow(T(o,new Date)),d=setTimeout(i,Ie);};i();let h=new Set,c,l=null,p=r.pollIntervalMs??15e3,m=g=>{h.has(g.id)||g.authorKind==="end_user"||(h.add(g.id),a.onIncomingTurn(g));},v=async()=>{if(!n.hasThread)return;let g=await n.load();if(g){for(let S of g.turns)m(S);h=new Set(g.turns.map(S=>S.id));}},y=()=>{c||p<=0||(c=setInterval(()=>void v(),p));},b=()=>{c&&clearInterval(c),c=void 0;},A=()=>{if(l||!r.socketHost)return;let g=n.socketAuth;g&&(l=new E({auth:g,host:r.socketHost,onClosed:S=>{l=null,y(),S&&A();},onReady:b,onTurn:m,socketFactory:r.socketFactory}),l.open());};return y(),A(),{close:()=>a.close(),destroy:()=>{b(),clearTimeout(d),l?.close(),l=null,a.close(),t.remove();},identify:g=>n.identify(g),open:()=>{a.open().then(A);}}}export{k as ChatClient,w as ChatPanel,x as DEFAULT_APPEARANCE,u as DEFAULT_APPEARANCE_SETTINGS,Je as mountChat,N as panelStyles,C as resolveAppearance};//# sourceMappingURL=chat.js.map
|
|
98
|
+
`}${ke[t.composerShape]}${Se[t.skin]}${D(t.launcherShape,t.launcherFill,t.launcherContent,t.launcherSize)}${Ce[t.bubbleShape]}${Ee[t.bubbleFill]}${we[t.namePlacement]}${t.nameAvatar?Le:""}${t.dayDividers?Te:""}${Ae[t.stampPlacement]}${t.stampContent==="time_and_latency"?Pe:""}${_e}${r.attachments?.enabled?Ne(t.composerShape):""}`}var Me=["end_user","agent","ai"];function ze(){let r=globalThis.location;if(r)return {host:r.host,path:r.pathname,title:document.title}}var Ue='<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>',Be='<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>',w=class{constructor(e,t,n={},a$1={},o={}){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);a(this,"pendingTurns",0);a(this,"openNow");a(this,"style");a(this,"scheme");a(this,"picked",null);a(this,"objectUrls",[]);this.strings={...ve,...n},this.appearance={...k,...a$1},this.settings=E({...k,...a$1}),this.root=e.attachShadow({mode:o.shadowMode??"closed"}),this.openNow=L(this.appearance.availability,new Date),this.scheme=o.scheme,this.style=document.createElement("style"),this.style.textContent=F(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={...k,...e},this.settings=E(this.appearance),t!==void 0&&(this.scheme=t),this.style.textContent=F(this.appearance,this.scheme),this.drawLauncher(),this.panel&&(this.close(),this.open());}toggle(){this.panel?this.close():this.open();}setOpenNow(e){this.openNow=e,this.launcher.classList.toggle("closed",!e),this.panel?.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=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 n=this.appearance.team??[];n.length>0&&t.append(_(n,this.strings,f=>this.client.avatarUrl(f)));let a=document.createElement("div");a.className="headmain";let o=document.createElement("h2");o.textContent=this.strings.title;let i=document.createElement("p");i.className="status";let s=document.createElement("span");s.className="live",s.setAttribute("aria-hidden","true"),i.append(s,this.strings.replyTime),a.append(o,i);let d=document.createElement("button");d.className="close",d.type="button",d.setAttribute("aria-label",this.strings.closeLabel),d.innerHTML=Be,d.addEventListener("click",()=>this.close()),t.append(a,d);let h=document.createElement("div");h.className="log",h.setAttribute("role","log"),h.setAttribute("aria-live","polite"),h.setAttribute("aria-label",this.strings.title);let p=document.createElement("form");p.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 y=document.createElement("span");y.className="sendtext",y.textContent=this.strings.sendLabel,m.append(y);let v=this.appearance.attachments;if(v?.enabled&&this.client.upload){let f=document.createElement("span");f.className="field";let u=document.createElement("input");u.type="file",u.accept=v.accept.join(","),u.hidden=true,u.addEventListener("change",()=>{let H=u.files?.[0];u.value="",H&&this.pick(h,p,v,H);});let b=document.createElement("button");b.type="button",b.className="clip",b.setAttribute("aria-label",this.strings.attachLabel),b.innerHTML=Ue,b.addEventListener("click",()=>u.click()),f.append(b,l,u),p.append(f,m);}else p.append(l,m);p.addEventListener("submit",f=>{f.preventDefault(),this.submit(l,h);}),e.append(t,h,p),e.addEventListener("keydown",f=>this.onKeydown(f,e,d)),this.root.append(e),this.panel=e,l.focus();let S=await this.client.load();S&&S.turns.length>0?this.renderThread(h,S):this.renderFirstRun(h,l),this.openNow||this.renderAway(t);}renderFirstRun(e,t){let n=document.createElement("div");n.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,n.append(a,o);for(let i of this.appearance.starterPrompts){let s=document.createElement("button");s.className="prompt",s.type="button",s.textContent=i,s.addEventListener("click",()=>{t.value=i,this.submit(t,e);}),n.append(s);}e.replaceChildren(n);}renderAway(e){let t=document.createElement("div");t.className="away";let n=document.createElement("span");n.className="awayglyph",n.setAttribute("aria-hidden","true");let a=document.createElement("span");a.textContent=this.appearance.awayMessage.trim()||this.strings.awayBody,t.append(n,a),e.after(t);}pick(e,t,n,a){let o=a.size>n.maxBytes||!n.accept.includes(a.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(N(a.size),`${n.maxBytes/1e6} MB`),t.before(l),e.scrollTop=e.scrollHeight;return}this.picked=a;let i=document.createElement("span");i.className="file";let s;if(a.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(a),s=l;}let d=document.createElement("span");d.className="name",d.textContent=a.name;let h=document.createElement("span");h.className="sz",h.textContent=`\xB7 ${N(a.size)}`;let p=document.createElement("button");p.type="button",p.className="x",p.setAttribute("aria-label",this.strings.removeFileLabel),p.textContent="\xD7",p.addEventListener("click",()=>{this.picked=null,i.remove();}),i.append(s,d,h,p),t.before(i),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 n=e.value.trim(),a=this.picked;if(!(!n&&!a)){e.value="",this.picked=null;for(let o of this.root.querySelectorAll(".file,.ferr"))o.remove();await this.sendBody(t,n,a);}}async sendBody(e,t,n=null){e.querySelector(".empty")?.remove(),this.pendingTurns+=1;let a=this.appendTurn(e,{authorId:null,authorKind:"end_user",body:t,createdAt:new Date().toISOString(),id:`pending-${this.pendingTurns}`},n);a.setAttribute("data-pending","");let o=n?await this.client.upload?.(n):void 0,i=o===null?null:await this.client.send(t,ze(),o?[o.id]:void 0);if(a.removeAttribute("data-pending"),i){a.dataset.turnId=i.id;return}this.markFailed(e,a,t,n);}markFailed(e,t,n,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,n,a);}),(t.querySelector(".body")??t).append(o);}hasTurn(e,t){for(let n of e.children)if(n instanceof HTMLElement&&n.dataset.turnId===t)return true;return false}renderThread(e,t){e.replaceChildren();for(let n of t.turns)this.appendTurn(e,n);}appendTurn(e,t,n=null){e.querySelector(".empty")?.remove();let a=Me.includes(t.authorKind)?t.authorKind:"agent",o=this.settings,i=document.createElement("div");if(i.className=`turn ${a}`,i.dataset.turnId=t.id,a!=="end_user"&&o.nameAvatar){let l=document.createElement("span");if(l.className=a==="ai"?"av bot":"av",l.setAttribute("aria-hidden","true"),a==="agent"&&t.authorAvatarUrl){let m=document.createElement("img");m.alt="",m.src=this.client.avatarUrl(t.authorAvatarUrl),l.append(m);}else {l.textContent=a==="ai"?this.strings.aiLabel:O(this.agentName(t));let m=a==="agent"?this.appearance.team?.find(y=>y.name===t.authorName)?.tone:void 0;m&&(l.style.background=m);}i.append(l);}let d=document.createElement("div");if(d.className="body",a==="end_user"){n&&this.drawFile(d,n.name,n.type,n.size,Promise.resolve(n));for(let l of t.attachments??[])this.drawFile(d,l.name,l.contentType,l.bytes,this.client.file?.(l.url)??Promise.resolve(null));}let h=a!=="end_user"&&o.namePlacement!=="hidden",p=document.createElement("div");if(a==="ai"?$e(p,t.body):p.textContent=t.body,h||a==="ai"&&o.namePlacement==="hidden"){let l=document.createElement("div");l.className=a==="ai"?"author ai":"author",l.textContent=a==="ai"?this.strings.aiLabel:this.agentName(t),o.stampPlacement==="beside_name"&&l.append(this.stamp(t)),o.namePlacement==="inline"?(l.classList.add("below"),d.append(p,l)):d.append(l,p);}else t.body&&d.append(p);return o.stampPlacement==="under_turn"&&d.append(this.stamp(t)),i.append(d),e.append(i),e.scrollTop=e.scrollHeight,i}drawFile(e,t,n,a,o){let i=document.createElement("a");if(n==="application/pdf"){i.className="pdfc",i.download=t;let s=document.createElement("b");s.textContent="PDF",i.append(s,`${t} \xB7 ${N(a)}`);}else {i.className="att",i.target="_blank",i.rel="noopener noreferrer";let s=document.createElement("img");s.alt=t,s.addEventListener("load",()=>{let d=i.closest(".log");d&&(d.scrollTop=d.scrollHeight);}),i.append(s);}e.append(i),o.then(s=>{s&&(i.href=this.objectUrl(s),i.querySelector("img")?.setAttribute("src",i.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,n){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],i=a[a.length-1],s=this.root.activeElement;e.shiftKey&&s===o?(e.preventDefault(),i.focus()):!e.shiftKey&&s===i?(e.preventDefault(),o.focus()):s===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 Oe="/socket.io/?EIO=4&transport=websocket",T=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??De,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(/\/+$/,"")}${Oe}`,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());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 De(r){let e=globalThis.WebSocket;if(!e)throw new Error("no WebSocket");return new e(r)}var qe=6e4;function lt(r){let e=globalThis.document;if(!e)throw new Error("prodantix chat requires a document; mount it in the browser");let t=r.mountPoint??e.createElement("div");r.mountPoint||e.body.append(t);let n=new C(r),a=new w(t,n,r.strings,r.appearance),o=r.appearance?.availability??k.availability,i,s=()=>{a.setOpenNow(L(o,new Date)),i=setTimeout(s,qe);};s();let d=new Set,h,p=null,l=r.pollIntervalMs??15e3,m=u=>{d.has(u.id)||u.authorKind==="end_user"||(d.add(u.id),a.onIncomingTurn(u));},y=async()=>{if(!n.hasThread)return;let u=await n.load();if(u){for(let b of u.turns)m(b);d=new Set(u.turns.map(b=>b.id));}},v=()=>{h||l<=0||(h=setInterval(()=>void y(),l));},S=()=>{h&&clearInterval(h),h=void 0;},f=()=>{if(p||!r.socketHost)return;let u=n.socketAuth;u&&(p=new T({auth:u,host:r.socketHost,onClosed:b=>{p=null,v(),b&&f();},onReady:S,onTurn:m,socketFactory:r.socketFactory}),p.open());};return v(),f(),{close:()=>a.close(),destroy:()=>{S(),clearTimeout(i),p?.close(),p=null,a.close(),t.remove();},identify:u=>n.identify(u),open:()=>{a.open().then(f);}}}export{C as ChatClient,w as ChatPanel,k as DEFAULT_APPEARANCE,g as DEFAULT_APPEARANCE_SETTINGS,lt as mountChat,F as panelStyles,E as resolveAppearance};//# sourceMappingURL=chat.js.map
|
|
155
99
|
//# sourceMappingURL=chat.js.map
|
|
@@ -8,7 +8,28 @@ interface ChatTurn {
|
|
|
8
8
|
createdAt: string;
|
|
9
9
|
authorName?: string | null;
|
|
10
10
|
authorAvatarUrl?: string | null;
|
|
11
|
+
attachments?: ChatAttachment[];
|
|
11
12
|
}
|
|
13
|
+
interface ChatUpload {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
contentType: string;
|
|
17
|
+
bytes: number;
|
|
18
|
+
}
|
|
19
|
+
interface ChatAttachment extends ChatUpload {
|
|
20
|
+
url: string;
|
|
21
|
+
}
|
|
22
|
+
interface FileResponseLike {
|
|
23
|
+
ok: boolean;
|
|
24
|
+
status: number;
|
|
25
|
+
blob(): Promise<Blob>;
|
|
26
|
+
text(): Promise<string>;
|
|
27
|
+
}
|
|
28
|
+
type FileFetchLike = (url: string, init: {
|
|
29
|
+
body?: Blob;
|
|
30
|
+
headers: Record<string, string>;
|
|
31
|
+
method: string;
|
|
32
|
+
}) => Promise<FileResponseLike>;
|
|
12
33
|
interface ChatThread {
|
|
13
34
|
id: string;
|
|
14
35
|
status: string;
|
|
@@ -20,6 +41,7 @@ interface ChatClientOptions {
|
|
|
20
41
|
distinctId: string;
|
|
21
42
|
storage?: ChatStorage;
|
|
22
43
|
fetchImpl?: FetchLike;
|
|
44
|
+
fileFetchImpl?: FileFetchLike;
|
|
23
45
|
onError?: (error: unknown) => void;
|
|
24
46
|
}
|
|
25
47
|
interface ChatIdentity {
|
|
@@ -39,6 +61,7 @@ interface PageContext {
|
|
|
39
61
|
declare class ChatClient {
|
|
40
62
|
private readonly options;
|
|
41
63
|
private readonly fetchImpl?;
|
|
64
|
+
private readonly fileFetchImpl;
|
|
42
65
|
private readonly host;
|
|
43
66
|
private readonly storage?;
|
|
44
67
|
private handle;
|
|
@@ -53,9 +76,12 @@ declare class ChatClient {
|
|
|
53
76
|
} | null;
|
|
54
77
|
identify(identity: ChatIdentity): void;
|
|
55
78
|
ensureThread(subject?: string): Promise<boolean>;
|
|
56
|
-
send(body: string, pageContext?: PageContext): Promise<ChatTurn | null>;
|
|
79
|
+
send(body: string, pageContext?: PageContext, attachmentIds?: string[]): Promise<ChatTurn | null>;
|
|
80
|
+
upload(file: File): Promise<ChatUpload | null>;
|
|
81
|
+
file(path: string): Promise<Blob | null>;
|
|
57
82
|
load(): Promise<ChatThread | null>;
|
|
58
83
|
private readHandle;
|
|
84
|
+
private fileRequest;
|
|
59
85
|
private request;
|
|
60
86
|
}
|
|
61
87
|
|
|
@@ -118,6 +144,12 @@ interface MessengerConfig extends AppearanceSettings {
|
|
|
118
144
|
starterPrompts: string[];
|
|
119
145
|
team: TeamFace[];
|
|
120
146
|
socketUrl: string;
|
|
147
|
+
attachments?: MessengerAttachments;
|
|
148
|
+
}
|
|
149
|
+
interface MessengerAttachments {
|
|
150
|
+
enabled: boolean;
|
|
151
|
+
maxBytes: number;
|
|
152
|
+
accept: string[];
|
|
121
153
|
}
|
|
122
154
|
interface MessengerConfigOptions {
|
|
123
155
|
apiKey: string;
|
|
@@ -128,7 +160,9 @@ interface MessengerConfigOptions {
|
|
|
128
160
|
onError?: (error: unknown) => void;
|
|
129
161
|
}
|
|
130
162
|
declare const MESSENGER_CACHE_KEY = "prodantix.messenger.config";
|
|
131
|
-
declare
|
|
163
|
+
declare const localeCandidates: (win: Window) => string | undefined;
|
|
164
|
+
declare const cacheKeyFor: (apiKey: string, locale: string | undefined) => string;
|
|
165
|
+
declare function cachedMessengerConfig(storage: ChatStorage | undefined, apiKey: string, locale?: string): MessengerConfig | null;
|
|
132
166
|
declare function fetchMessengerConfig(options: MessengerConfigOptions): Promise<MessengerConfig | null>;
|
|
133
167
|
|
|
134
|
-
export { type AppearanceSettings as A, type BubbleFill as B, type ChatThread as C, DEFAULT_APPEARANCE_SETTINGS as D, type LauncherContent as L, type MessengerConfig as M, type NamePlacement as N, type PageContext as P, type StampContent as S, type ChatTurn as a, type
|
|
168
|
+
export { type AppearanceSettings as A, type BubbleFill as B, type ChatThread as C, DEFAULT_APPEARANCE_SETTINGS as D, type FileFetchLike as F, type LauncherContent as L, type MessengerConfig as M, type NamePlacement as N, type PageContext as P, type StampContent as S, type ChatTurn as a, type ChatUpload as b, type ChatIdentity as c, type ChatClientOptions as d, type BubbleShape as e, type ChatAttachment as f, ChatClient as g, type ChatStorage as h, type ComposerShape as i, type FileResponseLike as j, type LauncherFill as k, type LauncherShape as l, type LauncherSize as m, type MessengerSkin as n, type StampPlacement as o, MESSENGER_CACHE_KEY as p, type MessengerAttachments as q, resolveAppearance as r, type MessengerConfigOptions as s, cacheKeyFor as t, cachedMessengerConfig as u, fetchMessengerConfig as v, localeCandidates as w };
|
|
@@ -8,7 +8,28 @@ interface ChatTurn {
|
|
|
8
8
|
createdAt: string;
|
|
9
9
|
authorName?: string | null;
|
|
10
10
|
authorAvatarUrl?: string | null;
|
|
11
|
+
attachments?: ChatAttachment[];
|
|
11
12
|
}
|
|
13
|
+
interface ChatUpload {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
contentType: string;
|
|
17
|
+
bytes: number;
|
|
18
|
+
}
|
|
19
|
+
interface ChatAttachment extends ChatUpload {
|
|
20
|
+
url: string;
|
|
21
|
+
}
|
|
22
|
+
interface FileResponseLike {
|
|
23
|
+
ok: boolean;
|
|
24
|
+
status: number;
|
|
25
|
+
blob(): Promise<Blob>;
|
|
26
|
+
text(): Promise<string>;
|
|
27
|
+
}
|
|
28
|
+
type FileFetchLike = (url: string, init: {
|
|
29
|
+
body?: Blob;
|
|
30
|
+
headers: Record<string, string>;
|
|
31
|
+
method: string;
|
|
32
|
+
}) => Promise<FileResponseLike>;
|
|
12
33
|
interface ChatThread {
|
|
13
34
|
id: string;
|
|
14
35
|
status: string;
|
|
@@ -20,6 +41,7 @@ interface ChatClientOptions {
|
|
|
20
41
|
distinctId: string;
|
|
21
42
|
storage?: ChatStorage;
|
|
22
43
|
fetchImpl?: FetchLike;
|
|
44
|
+
fileFetchImpl?: FileFetchLike;
|
|
23
45
|
onError?: (error: unknown) => void;
|
|
24
46
|
}
|
|
25
47
|
interface ChatIdentity {
|
|
@@ -39,6 +61,7 @@ interface PageContext {
|
|
|
39
61
|
declare class ChatClient {
|
|
40
62
|
private readonly options;
|
|
41
63
|
private readonly fetchImpl?;
|
|
64
|
+
private readonly fileFetchImpl;
|
|
42
65
|
private readonly host;
|
|
43
66
|
private readonly storage?;
|
|
44
67
|
private handle;
|
|
@@ -53,9 +76,12 @@ declare class ChatClient {
|
|
|
53
76
|
} | null;
|
|
54
77
|
identify(identity: ChatIdentity): void;
|
|
55
78
|
ensureThread(subject?: string): Promise<boolean>;
|
|
56
|
-
send(body: string, pageContext?: PageContext): Promise<ChatTurn | null>;
|
|
79
|
+
send(body: string, pageContext?: PageContext, attachmentIds?: string[]): Promise<ChatTurn | null>;
|
|
80
|
+
upload(file: File): Promise<ChatUpload | null>;
|
|
81
|
+
file(path: string): Promise<Blob | null>;
|
|
57
82
|
load(): Promise<ChatThread | null>;
|
|
58
83
|
private readHandle;
|
|
84
|
+
private fileRequest;
|
|
59
85
|
private request;
|
|
60
86
|
}
|
|
61
87
|
|
|
@@ -118,6 +144,12 @@ interface MessengerConfig extends AppearanceSettings {
|
|
|
118
144
|
starterPrompts: string[];
|
|
119
145
|
team: TeamFace[];
|
|
120
146
|
socketUrl: string;
|
|
147
|
+
attachments?: MessengerAttachments;
|
|
148
|
+
}
|
|
149
|
+
interface MessengerAttachments {
|
|
150
|
+
enabled: boolean;
|
|
151
|
+
maxBytes: number;
|
|
152
|
+
accept: string[];
|
|
121
153
|
}
|
|
122
154
|
interface MessengerConfigOptions {
|
|
123
155
|
apiKey: string;
|
|
@@ -128,7 +160,9 @@ interface MessengerConfigOptions {
|
|
|
128
160
|
onError?: (error: unknown) => void;
|
|
129
161
|
}
|
|
130
162
|
declare const MESSENGER_CACHE_KEY = "prodantix.messenger.config";
|
|
131
|
-
declare
|
|
163
|
+
declare const localeCandidates: (win: Window) => string | undefined;
|
|
164
|
+
declare const cacheKeyFor: (apiKey: string, locale: string | undefined) => string;
|
|
165
|
+
declare function cachedMessengerConfig(storage: ChatStorage | undefined, apiKey: string, locale?: string): MessengerConfig | null;
|
|
132
166
|
declare function fetchMessengerConfig(options: MessengerConfigOptions): Promise<MessengerConfig | null>;
|
|
133
167
|
|
|
134
|
-
export { type AppearanceSettings as A, type BubbleFill as B, type ChatThread as C, DEFAULT_APPEARANCE_SETTINGS as D, type LauncherContent as L, type MessengerConfig as M, type NamePlacement as N, type PageContext as P, type StampContent as S, type ChatTurn as a, type
|
|
168
|
+
export { type AppearanceSettings as A, type BubbleFill as B, type ChatThread as C, DEFAULT_APPEARANCE_SETTINGS as D, type FileFetchLike as F, type LauncherContent as L, type MessengerConfig as M, type NamePlacement as N, type PageContext as P, type StampContent as S, type ChatTurn as a, type ChatUpload as b, type ChatIdentity as c, type ChatClientOptions as d, type BubbleShape as e, type ChatAttachment as f, ChatClient as g, type ChatStorage as h, type ComposerShape as i, type FileResponseLike as j, type LauncherFill as k, type LauncherShape as l, type LauncherSize as m, type MessengerSkin as n, type StampPlacement as o, MESSENGER_CACHE_KEY as p, type MessengerAttachments as q, resolveAppearance as r, type MessengerConfigOptions as s, cacheKeyFor as t, cachedMessengerConfig as u, fetchMessengerConfig as v, localeCandidates as w };
|
package/dist/csp.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';function r(n){let t=n?.trim()??"";if(t==="")return null;try{return new URL(t).origin}catch{return null}}function s(n){return n.startsWith("https://")?`wss://${n.slice(8)}`:n.startsWith("http://")?`ws://${n.slice(7)}`:null}function i(n){return [...new Set(["'self'",...n.filter(t=>t!==null)])].join(" ")}function
|
|
2
|
-
exports.prodantixConnectSrc=
|
|
1
|
+
'use strict';function r(n){let t=n?.trim()??"";if(t==="")return null;try{return new URL(t).origin}catch{return null}}function s(n){return n.startsWith("https://")?`wss://${n.slice(8)}`:n.startsWith("http://")?`ws://${n.slice(7)}`:null}function i(n){return [...new Set(["'self'",...n.filter(t=>t!==null)])].join(" ")}function o(n,t=[]){let e=r(n.edge);return i([...t,r(n.ingest),e,e===null?null:s(e),r(n.replay)])}function l(n,t=[]){return i([...t,r(n.edge)])}function u(n,t=[]){return i([...t,"blob:",r(n.edge)])}
|
|
2
|
+
exports.prodantixConnectSrc=o;exports.prodantixImgSrc=u;exports.prodantixScriptSrc=l;//# sourceMappingURL=csp.cjs.map
|
|
3
3
|
//# sourceMappingURL=csp.cjs.map
|
package/dist/csp.d.cts
CHANGED
|
@@ -33,5 +33,6 @@ declare function prodantixConnectSrc(hosts: ProdantixHosts, extra?: readonly str
|
|
|
33
33
|
* here would widen the policy for nothing, and a needlessly wide script-src is
|
|
34
34
|
* the one direction of CSP error that never announces itself. */
|
|
35
35
|
declare function prodantixScriptSrc(hosts: ProdantixHosts, extra?: readonly string[]): string;
|
|
36
|
+
declare function prodantixImgSrc(hosts: ProdantixHosts, extra?: readonly string[]): string;
|
|
36
37
|
|
|
37
|
-
export { type ProdantixHosts, prodantixConnectSrc, prodantixScriptSrc };
|
|
38
|
+
export { type ProdantixHosts, prodantixConnectSrc, prodantixImgSrc, prodantixScriptSrc };
|
package/dist/csp.d.ts
CHANGED
|
@@ -33,5 +33,6 @@ declare function prodantixConnectSrc(hosts: ProdantixHosts, extra?: readonly str
|
|
|
33
33
|
* here would widen the policy for nothing, and a needlessly wide script-src is
|
|
34
34
|
* the one direction of CSP error that never announces itself. */
|
|
35
35
|
declare function prodantixScriptSrc(hosts: ProdantixHosts, extra?: readonly string[]): string;
|
|
36
|
+
declare function prodantixImgSrc(hosts: ProdantixHosts, extra?: readonly string[]): string;
|
|
36
37
|
|
|
37
|
-
export { type ProdantixHosts, prodantixConnectSrc, prodantixScriptSrc };
|
|
38
|
+
export { type ProdantixHosts, prodantixConnectSrc, prodantixImgSrc, prodantixScriptSrc };
|
package/dist/csp.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import'./chunk-5XGN7UAV.js';function r(n){let t=n?.trim()??"";if(t==="")return null;try{return new URL(t).origin}catch{return null}}function s(n){return n.startsWith("https://")?`wss://${n.slice(8)}`:n.startsWith("http://")?`ws://${n.slice(7)}`:null}function i(n){return [...new Set(["'self'",...n.filter(t=>t!==null)])].join(" ")}function
|
|
2
|
-
export{
|
|
1
|
+
import'./chunk-5XGN7UAV.js';function r(n){let t=n?.trim()??"";if(t==="")return null;try{return new URL(t).origin}catch{return null}}function s(n){return n.startsWith("https://")?`wss://${n.slice(8)}`:n.startsWith("http://")?`ws://${n.slice(7)}`:null}function i(n){return [...new Set(["'self'",...n.filter(t=>t!==null)])].join(" ")}function o(n,t=[]){let e=r(n.edge);return i([...t,r(n.ingest),e,e===null?null:s(e),r(n.replay)])}function l(n,t=[]){return i([...t,r(n.edge)])}function u(n,t=[]){return i([...t,"blob:",r(n.edge)])}
|
|
2
|
+
export{o as prodantixConnectSrc,u as prodantixImgSrc,l as prodantixScriptSrc};//# sourceMappingURL=csp.js.map
|
|
3
3
|
//# sourceMappingURL=csp.js.map
|
package/dist/messenger.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';function s(e){if(e)return e;let
|
|
1
|
+
'use strict';function s(e){if(e)return e;let t=globalThis.fetch;if(typeof t=="function")return t.bind(globalThis)}function c(e){return e.replace(/\/+$/,"")}var g="prodantix.messenger.config",h=e=>{let t=e.navigator?.languages;return Array.isArray(t)&&t.length>0?t.join(","):e.navigator?.language||e.document?.documentElement?.lang||void 0},l=(e,t)=>`${g}:${e}:${t??""}`;function d(e,t,a){let r=e?.get(l(t,a));if(!r)return null;try{let o=JSON.parse(r);return o?.apiKey===t?o.config:null}catch{return null}}async function m(e){let t=s(e.fetchImpl);if(!t)return e.onError?.(new Error("no fetch available for the prodantix messenger")),null;let a=c(e.host),r=l(e.apiKey,e.locale),o=e.locale?`?locale=${encodeURIComponent(e.locale)}`:"";try{let n=await t(`${a}/v1/messenger/config${o}`,{headers:{authorization:`Bearer ${e.apiKey}`},method:"GET"});if(!n.ok)return e.onError?.(new Error(`prodantix messenger config: ${n.status}`)),null;let i=JSON.parse(await n.text());return i.enabled?(e.storage?.set(r,JSON.stringify({apiKey:e.apiKey,config:i})),i):(e.storage?.remove(r),i)}catch(n){return e.onError?.(n),null}}exports.MESSENGER_CACHE_KEY=g;exports.cacheKeyFor=l;exports.cachedMessengerConfig=d;exports.fetchMessengerConfig=m;exports.localeCandidates=h;//# sourceMappingURL=messenger.cjs.map
|
|
2
2
|
//# sourceMappingURL=messenger.cjs.map
|
package/dist/messenger.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { p as MESSENGER_CACHE_KEY, q as MessengerAttachments, M as MessengerConfig, s as MessengerConfigOptions, t as cacheKeyFor, u as cachedMessengerConfig, v as fetchMessengerConfig, w as localeCandidates } from './config-CM4nTGof.cjs';
|
|
2
2
|
import './http-BCh716Vs.cjs';
|
package/dist/messenger.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { p as MESSENGER_CACHE_KEY, q as MessengerAttachments, M as MessengerConfig, s as MessengerConfigOptions, t as cacheKeyFor, u as cachedMessengerConfig, v as fetchMessengerConfig, w as localeCandidates } from './config-DJX2zFaa.js';
|
|
2
2
|
import './http-BCh716Vs.js';
|