@prodantix/sdk 0.6.0 → 0.7.0-beta.437

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.
Files changed (39) hide show
  1. package/README.md +19 -0
  2. package/dist/chat.cjs +19 -18
  3. package/dist/chat.d.cts +125 -7
  4. package/dist/chat.d.ts +125 -7
  5. package/dist/chat.js +21 -20
  6. package/dist/chunk-D6PMLUYA.js +2 -0
  7. package/dist/{client-BO7f6q5k.d.cts → client-CL6Xvhay.d.cts} +2 -1
  8. package/dist/{client-BQlU_3Dc.d.ts → client-QyKW0LFW.d.ts} +2 -1
  9. package/dist/{config-DqC0lcr7.d.ts → config-6ulvfBFp.d.ts} +33 -1
  10. package/dist/{config-CMF9zz1a.d.cts → config-g14Jiv1t.d.cts} +33 -1
  11. package/dist/csp.cjs +2 -2
  12. package/dist/csp.d.cts +9 -10
  13. package/dist/csp.d.ts +9 -10
  14. package/dist/csp.js +2 -2
  15. package/dist/index.cjs +1 -1
  16. package/dist/index.d.cts +5 -5
  17. package/dist/index.d.ts +5 -5
  18. package/dist/index.js +1 -1
  19. package/dist/messenger-files.iife.js +2 -0
  20. package/dist/messenger-help.iife.js +3 -0
  21. package/dist/messenger.cjs +1 -1
  22. package/dist/messenger.d.cts +1 -1
  23. package/dist/messenger.d.ts +1 -1
  24. package/dist/messenger.iife.js +7 -6
  25. package/dist/messenger.js +1 -1
  26. package/dist/node.cjs +1 -1
  27. package/dist/node.d.cts +2 -2
  28. package/dist/node.d.ts +2 -2
  29. package/dist/node.js +1 -1
  30. package/dist/{transport-CqAmRbpQ.d.ts → transport-DKFvkfX4.d.ts} +1 -1
  31. package/dist/{transport-Cy42FY5A.d.cts → transport-DN9pXyrX.d.cts} +1 -1
  32. package/dist/{types-DjMXp6Wg.d.cts → types-Q2VNlJbG.d.cts} +1 -0
  33. package/dist/{types-DjMXp6Wg.d.ts → types-Q2VNlJbG.d.ts} +1 -0
  34. package/dist/web.cjs +1 -1
  35. package/dist/web.d.cts +9 -4
  36. package/dist/web.d.ts +9 -4
  37. package/dist/web.js +1 -1
  38. package/package.json +1 -1
  39. package/dist/chunk-4RLPQZ5L.js +0 -2
package/README.md CHANGED
@@ -55,6 +55,25 @@ on it or anything inside it still counts but carries no text, id, classes or lin
55
55
  textareas, selects and any `password`, `email` or `tel` field never carry content, whatever the
56
56
  options say. A selector that does not parse is skipped and reported to `onError` once.
57
57
 
58
+ A click is recorded against the button, link or control it landed on, so a press on the icon
59
+ inside a button is a click on the button. Describe what the person is trying to do with
60
+ `data-prodantix`, and the click carries it as `$el_description`:
61
+
62
+ ```html
63
+ <button data-prodantix="Upgrade to Pro" data-prodantix-action="upgrade_plan">Upgrade</button>
64
+ ```
65
+
66
+ The value is trimmed, an empty one counts as absent, and one over 300 characters is ignored
67
+ whole and reported to `onError` once, never cut short. `data-prodantix-action` is an optional
68
+ stable identifier, recorded as `$el_action`. Without an annotation the description is inferred:
69
+ the accessible label or visible text when `captureElementText` is on, then a link's destination,
70
+ then the element's role or tag, and `$el_description_source` says which. The annotation is read
71
+ from the clicked element or the interactive element around it, never from a plain container.
72
+ `data-prodantix-ignore` on an element or any of its ancestors stops its clicks from being sent at
73
+ all. A manual event reads the same two attributes when it names its element:
74
+ `client.capture('Plan upgraded', { element: event.currentTarget })`. Never put a name, an email
75
+ address, an account id or anything else personal in an annotation.
76
+
58
77
  A session id is minted per
59
78
  visit (thirty minutes idle, twenty-four hours at most) and stamped on every event; pass
60
79
  `sessionTracking: false` to stop it.
package/dist/chat.cjs CHANGED
@@ -1,30 +1,30 @@
1
- 'use strict';var V=Object.defineProperty;var X=(n,e,t)=>e in n?V(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t;var d=(n,e,t)=>X(n,typeof e!="symbol"?e+"":e,t);var L=class extends Error{constructor(t,r,a){super(r,a);d(this,"code");this.code=t,this.name="ProdantixError";}},A=class extends L{constructor(e){super("config",e),this.name="ConfigError";}};var v=class extends L{constructor(t,r,a){super("transport",t,a);d(this,"status");this.status=r,this.name="TransportError";}};function O(n){if(n)return n;let e=globalThis.fetch;if(typeof e=="function")return e.bind(globalThis)}function z(n){return n.replace(/\/+$/,"")}var U="X-Prodantix-Conversation-Token",_="prodantix.chat.handle";function Z(){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 E=class{constructor(e){this.options=e;d(this,"fetchImpl");d(this,"fileFetchImpl");d(this,"host");d(this,"storage");d(this,"handle");d(this,"identity",null);this.fetchImpl=O(e.fetchImpl),this.fileFetchImpl=e.fileFetchImpl??((t,r)=>fetch(t,r)),this.host=z(e.host),this.storage=e.storage??Z(),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(_,JSON.stringify(this.handle)),true)}async send(e,t,r){if(!await this.ensureThread())return null;let a=this.handle;return a?(await this.request("POST",`/v1/conversations/${encodeURIComponent(a.conversationId)}/turns`,{body:{attachmentIds:r,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 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(){let e=this.storage?.get(_);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(t){this.options.onError?.(t);}return this.storage?.remove(_),null}async fileRequest(e,t,r,a,o){let i={authorization:`Bearer ${this.options.apiKey}`,[U]:r};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 v(`prodantix chat ${t}: ${s.status}`,s.status));}catch(s){this.options.onError?.(s);}return null}async request(e,t,r={}){let a=this.fetchImpl;if(!a)return this.options.onError?.(new v("no fetch available for prodantix chat")),null;let o={authorization:`Bearer ${this.options.apiKey}`,"content-type":"application/json"};r.token&&(o[U]=r.token);try{let i=await a(`${this.host}${t}`,{body:r.body===void 0?void 0:JSON.stringify(r.body),headers:o,method:e}),s=await i.text();return i.ok?s?JSON.parse(s):{}:(this.options.onError?.(new v(`prodantix chat ${t}: ${i.status}`,i.status)),null)}catch(i){return this.options.onError?.(i),null}}};var Q={Fri:"fri",Mon:"mon",Sat:"sat",Sun:"sun",Thu:"thu",Tue:"tue",Wed:"wed"};function N(n,e){let t=new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:false,minute:"2-digit",timeZone:n.timezone,weekday:"short"}).formatToParts(e),r=Q[t.find(s=>s.type==="weekday")?.value??""];if(!r)return false;let a=t.find(s=>s.type==="hour")?.value??"",o=t.find(s=>s.type==="minute")?.value??"",i=`${a}:${o}`;return n.windows.some(s=>s.days.includes(r)&&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"},ee=["quiet","standard"],te=["round","square"],ne=["rounded","tailed"],re=["filled","outlined"],ae=["circle","pill","squircle"],ie=["filled","outlined"],oe=["avatar","glyph","team_faces"],se=["large","medium","small"],le=["above","hidden","inline"],ce=["beside_name","none","under_turn"],de=["time","time_and_latency"],x=(n,e,t)=>typeof n=="string"&&e.includes(n)?n:t,B=(n,e)=>typeof n=="boolean"?n:e,pe={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"]},ue={above:["above",false],avatar_only:["hidden",true],gutter:["above",true],hidden:["hidden",false],inline:["inline",false]},he={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"]},me={concierge:["standard","round"],console:["standard","square"],quiet:["quiet","square"]},ge={hairline:["rounded","outlined"],outlined:["rounded","outlined"],rounded:["rounded","filled"],tailed:["tailed","filled"]};function T(n){let e=typeof n=="object"&&n!==null?n:{},t=typeof e.launcherStyle=="string"?e.launcherStyle:void 0,r=t===void 0?void 0:pe[t],a=typeof e.namePlacement=="string"?e.namePlacement:void 0,o=a===void 0?void 0:ue[a],i=typeof e.timestampStyle=="string"?e.timestampStyle:void 0,s=i===void 0?void 0:he[i],p=typeof e.skin=="string"?e.skin:void 0,u=p===void 0?void 0:me[p],c=typeof e.bubbleStyle=="string"?e.bubbleStyle:void 0,l=c===void 0?void 0:ge[c],h={bubbleFill:x(e.bubbleFill,re,l?.[1]??g.bubbleFill),bubbleShape:x(e.bubbleShape,ne,l?.[0]??g.bubbleShape),composerShape:x(e.composerShape,te,u?.[1]??g.composerShape),dayDividers:B(e.dayDividers,s?.[0]??g.dayDividers),launcherContent:x(e.launcherContent,oe,r?.[2]??g.launcherContent),launcherFill:x(e.launcherFill,ie,r?.[1]??g.launcherFill),launcherShape:x(e.launcherShape,ae,r?.[0]??g.launcherShape),launcherSize:x(e.launcherSize,se,r?.[3]??g.launcherSize),nameAvatar:B(e.nameAvatar,o?.[1]??g.nameAvatar),namePlacement:x(e.namePlacement,le,o?.[0]??g.namePlacement),skin:x(e.skin,ee,u?.[0]??g.skin),stampContent:x(e.stampContent,de,s?.[2]??g.stampContent),stampPlacement:x(e.stampPlacement,ce,s?.[1]??g.stampPlacement)};return h.stampPlacement==="beside_name"&&h.namePlacement==="hidden"&&(h.stampPlacement="under_turn"),h}function D(n){let e=n.split(/\s+/).filter(r=>r.length>0);return (e.length>1?`${e[0]?.slice(0,1)}${e[1]?.slice(0,1)}`:e[0]?.slice(0,2)??"").toUpperCase()}var fe="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",be={large:66,medium:56,small:46},xe={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;"},ye={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);"},ve={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;}"},ke=".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}",Se={circle:"",pill:".badge{position:static;box-shadow:none}",squircle:""},Ce={filled:"",outlined:".badge{background:var(--a);top:-7px;right:-7px;min-width:19px;height:19px;font-size:11.5px}"},Ee={circle:"",pill:".launcher .label{font-size:14px;font-weight:600;white-space:nowrap;}",squircle:""},Te={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:${be[r]}px;${xe[n]}${ye[e]}}${ve[t]}${ke}${Se[n]}${Ce[e]}${Ee[n]}${Te[n]}`}function K(n,e,t,r=a=>a){let a=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="${fe}"/></svg>`,a.append(...o.childNodes,F()),a}return n==="avatar"?(a.append(q(t[0],e,r),F()),a):(a.append(I(t,e,r),F()),a)}function I(n,e,t=r=>r){let r=document.createElement("span");r.className="faces";for(let a of n.slice(0,2))r.append(q(a,e,t));return r}function q(n,e,t){let r=document.createElement("span");if(r.className="av",r.setAttribute("aria-hidden","true"),n&&(r.style.background=n.tone),n?.avatarUrl){let a=document.createElement("img");return a.alt="",a.src=t(n.avatarUrl),r.append(a),r}return r.textContent=n?n.initials:e.agentLabel.slice(0,2).toUpperCase(),r}function F(){let n=document.createElement("span");return n.className="live",n.setAttribute("aria-hidden","true"),n}var we={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`},C={accentColor:"#5b5bff",availability:{timezone:"UTC",windows:[]},awayMessage:"",greeting:"",launcherOffsetX:20,launcherOffsetY:20,launcherPosition:"bottom_right",starterPrompts:[],team:[],...g},Le={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}"},Ae={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}"},Ne={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}"},Pe={filled:"",outlined:".turn{background:none;border:1px solid var(--hairline)}.turn.end_user{background:none;border-color:var(--a);color:var(--ink)}"},_e={above:"",hidden:".turn.agent .author,.turn.ai .author:not(.ai){display:none}",inline:".body .author.below{display:block;margin:4px 0 0;font-size:11.5px;font-weight:500;color:var(--ink-2);text-transform:none;letter-spacing:0;opacity:1}"},Fe=".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}",Ie='.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)}',Re={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}"},He=".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 Me(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 R(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);
1
+ 'use strict';var J=Object.defineProperty;var V=(n,e,t)=>e in n?J(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t;var l=(n,e,t)=>V(n,typeof e!="symbol"?e+"":e,t);var A=class extends Error{constructor(t,r,i){super(r,i);l(this,"code");this.code=t,this.name="ProdantixError";}},P=class extends A{constructor(e){super("config",e),this.name="ConfigError";}};var v=class extends A{constructor(t,r,i){super("transport",t,i);l(this,"status");this.status=r,this.name="TransportError";}};function $(n){if(n)return n;let e=globalThis.fetch;if(typeof e=="function")return e.bind(globalThis)}function M(n){return n.replace(/\/+$/,"")}var O="X-Prodantix-Conversation-Token",F="prodantix.chat.handle";function X(){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 T=class{constructor(e){this.options=e;l(this,"fetchImpl");l(this,"fileFetchImpl");l(this,"host");l(this,"storage");l(this,"handle");l(this,"identity",null);this.fetchImpl=$(e.fetchImpl),this.fileFetchImpl=e.fileFetchImpl??((t,r)=>fetch(t,r)),this.host=M(e.host),this.storage=e.storage??X(),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(F,JSON.stringify(this.handle)),true)}async send(e,t,r){if(!await this.ensureThread())return null;let i=this.handle;return i?(await this.request("POST",`/v1/conversations/${encodeURIComponent(i.conversationId)}/turns`,{body:{attachmentIds:r,body:e,pageContext:t},token:i.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 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 helpCentre(e,t){let r=Object.entries({...t,...this.options.locale?{lang:this.options.locale}:{}}).map(([i,a])=>`${i}=${encodeURIComponent(a)}`).join("&");return this.request("GET",`/v1/messenger/articles${e}${r?`?${r}`:""}`)}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(F);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(t){this.options.onError?.(t);}return this.storage?.remove(F),null}async fileRequest(e,t,r,i,a){let o={authorization:`Bearer ${this.options.apiKey}`,[O]:r};a&&(o["content-type"]=a.type||"application/octet-stream");try{let s=await this.fileFetchImpl(`${this.host}${t}`,{body:a,headers:o,method:e});if(s.ok)return await i(s);this.options.onError?.(new v(`prodantix chat ${t}: ${s.status}`,s.status));}catch(s){this.options.onError?.(s);}return null}async request(e,t,r={}){let i=this.fetchImpl;if(!i)return this.options.onError?.(new v("no fetch available for prodantix chat")),null;let a={authorization:`Bearer ${this.options.apiKey}`,"content-type":"application/json"};r.token&&(a[O]=r.token);try{let o=await i(`${this.host}${t}`,{body:r.body===void 0?void 0:JSON.stringify(r.body),headers:a,method:e}),s=await o.text();return o.ok?s?JSON.parse(s):{}:(this.options.onError?.(new v(`prodantix chat ${t}: ${o.status}`,o.status)),null)}catch(o){return this.options.onError?.(o),null}}};var Z={Fri:"fri",Mon:"mon",Sat:"sat",Sun:"sun",Thu:"thu",Tue:"tue",Wed:"wed"};function N(n,e){let t=new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:false,minute:"2-digit",timeZone:n.timezone,weekday:"short"}).formatToParts(e),r=Z[t.find(s=>s.type==="weekday")?.value??""];if(!r)return false;let i=t.find(s=>s.type==="hour")?.value??"",a=t.find(s=>s.type==="minute")?.value??"",o=`${i}:${a}`;return n.windows.some(s=>s.days.includes(r)&&s.open<=o&&o<s.close)}var f={bubbleFill:"filled",bubbleShape:"tailed",composerShape:"round",dayDividers:true,launcherContent:"glyph",launcherFill:"outlined",launcherShape:"circle",launcherSize:"small",nameAvatar:true,namePlacement:"hidden",skin:"standard",stampContent:"time",stampPlacement:"none"},Q=["quiet","standard"],ee=["round","square"],te=["rounded","tailed"],ne=["filled","outlined"],re=["circle","pill","squircle"],ie=["filled","outlined"],ae=["avatar","glyph","team_faces"],oe=["large","medium","small"],se=["above","hidden","inline"],le=["beside_name","none","under_turn"],ce=["time","time_and_latency"],x=(n,e,t)=>typeof n=="string"&&e.includes(n)?n:t,U=(n,e)=>typeof n=="boolean"?n:e,de={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"]},pe={above:["above",false],avatar_only:["hidden",true],gutter:["above",true],hidden:["hidden",false],inline:["inline",false]},he={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"]},ue={concierge:["standard","round"],console:["standard","square"],quiet:["quiet","square"]},me={hairline:["rounded","outlined"],outlined:["rounded","outlined"],rounded:["rounded","filled"],tailed:["tailed","filled"]};function L(n){let e=typeof n=="object"&&n!==null?n:{},t=typeof e.launcherStyle=="string"?e.launcherStyle:void 0,r=t===void 0?void 0:de[t],i=typeof e.namePlacement=="string"?e.namePlacement:void 0,a=i===void 0?void 0:pe[i],o=typeof e.timestampStyle=="string"?e.timestampStyle:void 0,s=o===void 0?void 0:he[o],h=typeof e.skin=="string"?e.skin:void 0,u=h===void 0?void 0:ue[h],c=typeof e.bubbleStyle=="string"?e.bubbleStyle:void 0,d=c===void 0?void 0:me[c],p={bubbleFill:x(e.bubbleFill,ne,d?.[1]??f.bubbleFill),bubbleShape:x(e.bubbleShape,te,d?.[0]??f.bubbleShape),composerShape:x(e.composerShape,ee,u?.[1]??f.composerShape),dayDividers:U(e.dayDividers,s?.[0]??f.dayDividers),launcherContent:x(e.launcherContent,ae,r?.[2]??f.launcherContent),launcherFill:x(e.launcherFill,ie,r?.[1]??f.launcherFill),launcherShape:x(e.launcherShape,re,r?.[0]??f.launcherShape),launcherSize:x(e.launcherSize,oe,r?.[3]??f.launcherSize),nameAvatar:U(e.nameAvatar,a?.[1]??f.nameAvatar),namePlacement:x(e.namePlacement,se,a?.[0]??f.namePlacement),skin:x(e.skin,Q,u?.[0]??f.skin),stampContent:x(e.stampContent,ce,s?.[2]??f.stampContent),stampPlacement:x(e.stampPlacement,le,s?.[1]??f.stampPlacement)};return p.stampPlacement==="beside_name"&&p.namePlacement==="hidden"&&(p.stampPlacement="under_turn"),p}function K(n){let e=n.split(/\s+/).filter(r=>r.length>0);return (e.length>1?`${e[0]?.slice(0,1)}${e[1]?.slice(0,1)}`:e[0]?.slice(0,2)??"").toUpperCase()}var ge="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",fe={large:66,medium:56,small:46},be={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;"},ye={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);"},xe={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;}"},ve=".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}",Se={circle:"",pill:".badge{position:static;box-shadow:none}",squircle:""},ke={filled:"",outlined:".badge{background:var(--a);top:-7px;right:-7px;min-width:19px;height:19px;font-size:11.5px}"},Ce={circle:"",pill:".launcher .label{font-size:14px;font-weight:600;white-space:nowrap;}",squircle:""},Ee={circle:"",pill:"@media (max-width:480px){.launcher{width:var(--fab-size);padding:0}.launcher .label{display:none}}",squircle:""};function z(n,e,t,r){return `.launcher{--fab-size:${fe[r]}px;${be[n]}${ye[e]}}${xe[t]}${ve}${Se[n]}${ke[e]}${Ce[n]}${Ee[n]}`}function B(n,e,t,r=i=>i){let i=document.createDocumentFragment();if(n==="glyph"||t.length===0){let a=document.createElement("span");return a.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="${ge}"/></svg>`,i.append(...a.childNodes,I()),i}return n==="avatar"?(i.append(D(t[0],e,r),I()),i):(i.append(H(t,e,r),I()),i)}function H(n,e,t=r=>r){let r=document.createElement("span");r.className="faces";for(let i of n.slice(0,2))r.append(D(i,e,t));return r}function D(n,e,t){let r=document.createElement("span");if(r.className="av",r.setAttribute("aria-hidden","true"),n&&(r.style.background=n.tone),n?.avatarUrl){let 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 I(){let n=document.createElement("span");return n.className="live",n.setAttribute("aria-hidden","true"),n}var Te={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`},E={accentColor:"#5958fc",availability:{timezone:"UTC",windows:[]},awayMessage:"",greeting:"",launcherOffsetX:20,launcherOffsetY:20,launcherPosition:"bottom_right",starterPrompts:[],team:[],...f},Le={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}"},we={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}"},Ae={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}"},Pe={filled:"",outlined:".turn{background:none;border:1px solid var(--hairline)}.turn.end_user{background:none;border-color:var(--a);color:var(--ink)}"},Ne={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}"},_e=".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}",Fe='.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)}',Ie={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}"},He=".lat{font-size:11px;opacity:.7;margin-left:6px}",G=`--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 Oe(n){return n==="light"?"":n==="dark"?`:host { ${j} }`:`@media (prefers-color-scheme: dark) {
3
+ --online: oklch(72% 0.13 163.23);`;function Re(n){return n==="light"?"":n==="dark"?`:host { ${G} }`:`@media (prefers-color-scheme: dark) {
4
4
  :host {
5
- ${j}
5
+ ${G}
6
6
  }
7
- }`}var ze=/https?:\/\/[^\s<>"]+/g,Ue=/[.,;:!?)]$/,Be=n=>{let e=n;for(;Ue.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 De(n,e){let t=0;for(let r of e.matchAll(ze)){let a=r.index??0,o=Be(r[0]);a>t&&n.append(e.slice(t,a));let i=document.createElement("a");i.href=o,i.target="_blank",i.rel="noopener noreferrer",i.textContent=o,n.append(i),t=a+o.length;}t<e.length&&n.append(e.slice(t));}var Ge=["P","BR","STRONG","EM","A","UL","OL","LI"],Ke=n=>typeof n=="object"&&n!==null&&"html"in n&&typeof n.html=="string"&&"text"in n&&typeof n.text=="string",qe=(n,e)=>e.name==="class"||e.name==="data-block-type"?true:n!=="A"?false:e.name==="target"||e.name==="rel"?true:e.name==="href"&&/^https?:\/\//i.test(e.value.trim()),je=n=>[...n.querySelectorAll("*")].every(e=>Ge.includes(e.tagName)&&[...e.attributes].every(t=>qe(e.tagName,t)));function H(n,e="system"){let t=T(n),r=n.launcherPosition==="bottom_left"?"left":"right",a=n.accentColor;return `${`
7
+ }`}var $e=/https?:\/\/[^\s<>"]+/g,Me=/[.,;:!?)]$/,Oe=n=>{let e=n;for(;Me.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 Ue(n,e){let t=0;for(let r of e.matchAll($e)){let i=r.index??0,a=Oe(r[0]);i>t&&n.append(e.slice(t,i));let o=document.createElement("a");o.href=a,o.target="_blank",o.rel="noopener noreferrer",o.textContent=a,n.append(o),t=i+a.length;}t<e.length&&n.append(e.slice(t));}var Ke=["P","BR","STRONG","EM","A","UL","OL","LI"],ze=n=>typeof n=="object"&&n!==null&&"html"in n&&typeof n.html=="string"&&"text"in n&&typeof n.text=="string",Be=(n,e)=>e.name==="class"||e.name==="data-block-type"?true:n!=="A"?false:e.name==="target"||e.name==="rel"?true:e.name==="href"&&/^https?:\/\//i.test(e.value.trim()),De=n=>[...n.querySelectorAll("*")].every(e=>Ke.includes(e.tagName)&&[...e.attributes].every(t=>Be(e.tagName,t)));function q(n,e="system"){let t=L(n),r=n.launcherPosition==="bottom_left"?"left":"right",i=n.accentColor;return `${`
8
8
  :host {
9
- all: initial; z-index: 2147483000; --a: ${a};
9
+ all: initial; z-index: 2147483000; --a: ${i};
10
10
  --paper: #fff; --ink: #0f172a; --ink-3: rgba(0,0,0,.55);
11
11
  --fill: #f1f5f9; --hairline: #e2e8f0; --ink-2: rgba(0,0,0,.72);
12
12
  --online: oklch(53.8% 0.1274 163.23);
13
13
  color-scheme: ${e==="system"?"light dark":e};
14
14
  }
15
- ${Oe(e)}
15
+ ${Re(e)}
16
16
  * { box-sizing: border-box; font-family: system-ui, sans-serif; }
17
17
  .launcher {
18
18
  z-index: 2147483000; position: fixed; ${r}: ${n.launcherOffsetX}px; bottom: ${n.launcherOffsetY}px; width: 56px; height: 56px;
19
19
  border-radius: 28px; border: none; cursor: pointer;
20
20
  display: inline-flex; align-items: center; justify-content: center;
21
- background: ${a}; color: #fff; font-size: 24px;
21
+ background: ${i}; color: #fff; font-size: 24px;
22
22
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
23
23
  }
24
24
  .launcher:focus-visible { outline: 3px solid #0b0e14; outline-offset: 2px; }
25
25
  .launcher { transition: background-color 120ms ease; }
26
- .launcher:hover { background: color-mix(in srgb, #000 12%, ${a}); }
27
- .launcher:active { background: color-mix(in srgb, #000 20%, ${a}); }
26
+ .launcher:hover { background: color-mix(in srgb, #000 12%, ${i}); }
27
+ .launcher:active { background: color-mix(in srgb, #000 20%, ${i}); }
28
28
  @media (prefers-reduced-motion: reduce) {
29
29
  .launcher { transition: none; }
30
30
  }
@@ -62,14 +62,14 @@ ${Oe(e)}
62
62
  .close:focus-visible { outline: 2px solid currentColor; outline-offset: 1px; }
63
63
  .log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
64
64
  .turn { max-width: 80%; padding: 8px 12px; border-radius: 12px; font-size: 14px; }
65
- .turn.end_user { align-self: flex-end; background: ${a}; color: #fff; }
65
+ .turn.end_user { align-self: flex-end; background: ${i}; color: #fff; }
66
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; }
67
+ .turn.ai a { color: ${i}; text-decoration: underline; overflow-wrap: anywhere; }
68
68
  .author { font-size: 11px; opacity: .7; margin-bottom: 2px; }
69
69
  .turn[data-pending] { opacity: .6; }
70
70
  .turn[data-failed] { opacity: 1; box-shadow: inset 0 0 0 1px #dc2626; }
71
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; }
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; }
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; }
73
73
  .awayglyph { flex: none; width: 16px; height: 16px; margin-top: 1px; border: 1.5px solid currentColor; border-radius: 50%; }
74
74
  .empty { display: flex; flex-direction: column; gap: 8px; padding: 20px 16px; }
75
75
  .empty h3 { margin: 0; font-size: 18px; font-weight: 640; letter-spacing: -.015em; }
@@ -84,17 +84,17 @@ ${Oe(e)}
84
84
  .prompt p { margin: 0 0 16px; line-height: 1.6; }
85
85
  .prompt ul, .prompt ol { margin: 0 0 16px; padding-left: 32px; }
86
86
  .prompt li { margin: 8px 0; line-height: 1.6; }
87
- .prompt a { position: relative; z-index: 1; color: ${a}; text-decoration: underline; overflow-wrap: anywhere; }
87
+ .prompt a { position: relative; z-index: 1; color: ${i}; text-decoration: underline; overflow-wrap: anywhere; }
88
88
  .promptpress { position: absolute; inset: 0; padding: 0; background: none; border: 0; border-radius: inherit; cursor: pointer; }
89
- .promptpress:focus-visible { outline: 2px solid ${a}; outline-offset: 2px; }
89
+ .promptpress:focus-visible { outline: 2px solid ${i}; outline-offset: 2px; }
90
90
  .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); }
91
91
  .av.bot { border-radius: 9px; background: var(--fill); color: var(--ink); }
92
92
  .av img { width: 100%; height: 100%; display: block; object-fit: cover; border-radius: inherit; }
93
93
  .composer { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--hairline); }
94
94
  .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); }
95
- .composer input:focus-visible { outline: 2px solid ${a}; }
96
- .composer button { display: inline-flex; align-items: center; justify-content: center; gap: 0; min-width: 56px; height: 36px; padding: 0 14px; background: ${a}; color: #fff; border: none; border-radius: 8px; cursor: pointer; font-family: inherit; font-size: 13.5px; font-weight: 550; }
97
- .composer button:hover { background: color-mix(in srgb, #000 12%, ${a}); }
95
+ .composer input:focus-visible { outline: 2px solid ${i}; }
96
+ .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; }
97
+ .composer button:hover { background: color-mix(in srgb, #000 12%, ${i}); }
98
98
  .composer button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
99
99
  .composer button .sendglyph { display: none; width: 17px; height: 17px; }
100
100
  .composer button:focus-visible { outline: 2px solid #0b0e14; }
@@ -102,5 +102,6 @@ ${Oe(e)}
102
102
  .panel { animation: rise 180ms ease-out; }
103
103
  @keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
104
104
  }
105
- `}${Ae[t.composerShape]}${Le[t.skin]}${G(t.launcherShape,t.launcherFill,t.launcherContent,t.launcherSize)}${Ne[t.bubbleShape]}${Pe[t.bubbleFill]}${_e[t.namePlacement]}${t.nameAvatar?Fe:""}${t.dayDividers?Ie:""}${Re[t.stampPlacement]}${t.stampContent==="time_and_latency"?He:""}${$e}${n.attachments?.enabled?Me(t.composerShape):""}`}var Ye=["end_user","agent","ai"];function We(){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="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>',Ve='<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,r={},a={},o={}){this.host=e;this.client=t;d(this,"root");d(this,"strings");d(this,"settings");d(this,"appearance");d(this,"launcher");d(this,"badge");d(this,"panel",null);d(this,"lastFocused",null);d(this,"unread",0);d(this,"pendingTurns",0);d(this,"openNow");d(this,"style");d(this,"scheme");d(this,"picked",null);d(this,"objectUrls",[]);this.strings={...we,...r},this.appearance={...C,...a},this.settings=T({...C,...a}),this.root=e.attachShadow({mode:o.shadowMode??"closed"}),this.openNow=N(this.appearance.availability,new Date),this.scheme=o.scheme,this.style=document.createElement("style"),this.style.textContent=H(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(K(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={...C,...e},this.settings=T(this.appearance),t!==void 0&&(this.scheme=t),this.style.textContent=H(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 r=this.appearance.team??[];r.length>0&&t.append(I(r,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 p=document.createElement("button");p.className="close",p.type="button",p.setAttribute("aria-label",this.strings.closeLabel),p.innerHTML=Ve,p.addEventListener("click",()=>this.close()),t.append(a,p);let u=document.createElement("div");u.className="log",u.setAttribute("role","log"),u.setAttribute("aria-live","polite"),u.setAttribute("aria-label",this.strings.title);let c=document.createElement("form");c.className="composer";let l=document.createElement("input");l.type="text",l.setAttribute("aria-label",this.strings.inputPlaceholder),l.placeholder=this.strings.inputPlaceholder;let h=document.createElement("button");h.type="submit",h.setAttribute("aria-label",this.strings.sendLabel),h.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,h.append(y);let k=this.appearance.attachments;if(k?.enabled&&this.client.upload){let f=document.createElement("span");f.className="field";let m=document.createElement("input");m.type="file",m.accept=k.accept.join(","),m.hidden=true,m.addEventListener("change",()=>{let M=m.files?.[0];m.value="",M&&this.pick(u,c,k,M);});let b=document.createElement("button");b.type="button",b.className="clip",b.setAttribute("aria-label",this.strings.attachLabel),b.innerHTML=Je,b.addEventListener("click",()=>m.click()),f.append(b,l,m),c.append(f,h);}else c.append(l,h);c.addEventListener("submit",f=>{f.preventDefault(),this.submit(l,u);}),e.append(t,u,c),e.addEventListener("keydown",f=>this.onKeydown(f,e,p)),this.root.append(e),this.panel=e,l.focus();let S=await this.client.load();S&&S.turns.length>0?this.renderThread(u,S):this.renderFirstRun(u,l),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 o=document.createElement("p");o.textContent=this.strings.emptyBody,r.append(a,o),this.appearance.starterPrompts.filter(Ke).forEach((s,p)=>{let u=document.createElement("div");u.className="prompt";let c=document.createElement("div");c.className="promptwords",c.id=`prompt-${p}`;let l=document.createElement("template");l.innerHTML=s.html,je(l.content)?c.append(l.content):c.textContent=s.text;for(let y of c.querySelectorAll("a"))y.target="_blank",y.rel="noopener noreferrer";let h=document.createElement("button");h.className="promptpress",h.type="button",h.setAttribute("aria-labelledby",c.id),h.addEventListener("click",()=>{t.value=s.text,this.submit(t,e);}),u.append(c,h),r.append(u);}),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);}pick(e,t,r,a){let o=a.size>r.maxBytes||!r.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(R(a.size),`${r.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 p=document.createElement("span");p.className="name",p.textContent=a.name;let u=document.createElement("span");u.className="sz",u.textContent=`\xB7 ${R(a.size)}`;let c=document.createElement("button");c.type="button",c.className="x",c.setAttribute("aria-label",this.strings.removeFileLabel),c.textContent="\xD7",c.addEventListener("click",()=>{this.picked=null,i.remove();}),i.append(s,p,u,c),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 r=e.value.trim(),a=this.picked;if(!(!r&&!a)){e.value="",this.picked=null;for(let o of this.root.querySelectorAll(".file,.ferr"))o.remove();await this.sendBody(t,r,a);}}async sendBody(e,t,r=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}`},r);a.setAttribute("data-pending","");let o=r?await this.client.upload?.(r):void 0,i=o===null?null:await this.client.send(t,We(),o?[o.id]:void 0);if(a.removeAttribute("data-pending"),i){a.dataset.turnId=i.id;return}this.markFailed(e,a,t,r);}markFailed(e,t,r,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,a);}),(t.querySelector(".body")??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){e.querySelector(".empty")?.remove();let a=Ye.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 h=document.createElement("img");h.alt="",h.src=this.client.avatarUrl(t.authorAvatarUrl),l.append(h);}else {l.textContent=a==="ai"?this.strings.aiLabel:D(this.agentName(t));let h=a==="agent"?this.appearance.team?.find(y=>y.name===t.authorName)?.tone:void 0;h&&(l.style.background=h);}i.append(l);}let p=document.createElement("div");if(p.className="body",a==="end_user"){r&&this.drawFile(p,r.name,r.type,r.size,Promise.resolve(r));for(let l of t.attachments??[])this.drawFile(p,l.name,l.contentType,l.bytes,this.client.file?.(l.url)??Promise.resolve(null));}let u=a!=="end_user"&&o.namePlacement!=="hidden",c=document.createElement("div");if(a==="ai"?De(c,t.body):c.textContent=t.body,u||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"),p.append(c,l)):p.append(l,c);}else t.body&&p.append(c);return o.stampPlacement==="under_turn"&&p.append(this.stamp(t)),i.append(p),e.append(i),e.scrollTop=e.scrollHeight,i}drawFile(e,t,r,a,o){let i=document.createElement("a");if(r==="application/pdf"){i.className="pdfc",i.download=t;let s=document.createElement("b");s.textContent="PDF",i.append(s,`${t} \xB7 ${R(a)}`);}else {i.className="att",i.target="_blank",i.rel="noopener noreferrer";let s=document.createElement("img");s.alt=t,s.addEventListener("load",()=>{let p=i.closest(".log");p&&(p.scrollTop=p.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,r){if(e.key==="Escape"){e.preventDefault(),this.close();return}if(e.key!=="Tab")return;let a=t.querySelectorAll('button, input, [tabindex]:not([tabindex="-1"])');if(a.length===0)return;let o=a[0],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(),r.focus());}renderBadge(){this.unread>0?(this.badge.hidden=false,this.badge.textContent=String(this.unread),this.launcher.setAttribute("aria-label",`${this.strings.launcherLabel}, ${this.strings.unreadLabel(this.unread)}`)):(this.badge.hidden=true,this.badge.textContent="",this.launcher.setAttribute("aria-label",this.strings.launcherLabel));}};function Y(n){return `40${JSON.stringify(n)}`}function W(){return "3"}function J(n){let e=n.charAt(0),t=n.slice(1);if(e==="2")return {kind:"ping"};if(e==="1")return {kind:"disconnect"};if(e==="0"){let i=$(t);return {kind:"open",pingInterval:typeof i?.pingInterval=="number"?i.pingInterval:25e3,pingTimeout:typeof i?.pingTimeout=="number"?i.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 i=$(a);return {kind:"connectError",message:typeof i?.message=="string"?i.message:"refused"}}if(r!=="2")return {kind:"other"};let o=$(a);return !Array.isArray(o)||typeof o[0]!="string"?{kind:"other"}:{kind:"event",name:o[0],payload:o[1]}}function $(n){try{return JSON.parse(n)}catch{return null}}var Xe="/socket.io/?EIO=4&transport=websocket",P=class{constructor(e){this.options=e;d(this,"socket",null);d(this,"heartbeat",null);d(this,"ready",false);d(this,"closed",false);d(this,"heartbeatWindow",45e3);d(this,"factory");d(this,"setTimer");d(this,"clearTimer");this.factory=e.socketFactory??Ze,this.setTimer=e.setTimer??((t,r)=>setTimeout(t,r)),this.clearTimer=e.clearTimer??(t=>clearTimeout(t));}open(){if(this.socket||this.closed)return;let e=`${this.options.host.replace(/^http/,"ws").replace(/\/+$/,"")}${Xe}`,t;try{t=this.factory(e);}catch{this.options.onClosed(false);return}this.socket=t,t.onmessage=r=>this.receive(String(r.data)),t.onerror=()=>t.close(),t.onclose=()=>this.fell();}close(){this.closed=true,this.stopHeartbeat();let e=this.socket;this.socket=null,e?.close();}receive(e){let t=J(e);if(t.kind==="open"){this.armHeartbeat(t.pingInterval+t.pingTimeout),this.socket?.send(Y(this.options.auth));return}if(t.kind==="ping"){this.armHeartbeat(),this.socket?.send(W());return}if(t.kind==="connectError"||t.kind==="disconnect"){this.stopHeartbeat(),this.socket?.close();return}if(t.kind==="event"){if(t.name==="ready"){this.ready=true,this.options.onReady();return}if(t.name==="conversation.turn"){let r=t.payload?.turn;r&&this.options.onTurn(r);}}}fell(){this.stopHeartbeat();let e=this.ready;this.socket=null,this.ready=false,this.closed||this.options.onClosed(e);}armHeartbeat(e){e!==void 0&&(this.heartbeatWindow=e),this.stopHeartbeat(),this.heartbeat=this.setTimer(()=>this.socket?.close(),this.heartbeatWindow);}stopHeartbeat(){this.heartbeat!==null&&this.clearTimer(this.heartbeat),this.heartbeat=null;}};function Ze(n){let e=globalThis.WebSocket;if(!e)throw new v("no WebSocket");return new e(n)}var Qe=6e4;function wt(n){let e=globalThis.document;if(!e)throw new A("prodantix chat requires a document; mount it in the browser");let t=n.mountPoint??e.createElement("div");n.mountPoint||e.body.append(t);let r=new E(n),a=new w(t,r,n.strings,n.appearance),o=n.appearance?.availability??C.availability,i,s=()=>{a.setOpenNow(N(o,new Date)),i=setTimeout(s,Qe);};s();let p=new Set,u,c=null,l=n.pollIntervalMs??15e3,h=m=>{p.has(m.id)||m.authorKind==="end_user"||(p.add(m.id),a.onIncomingTurn(m));},y=async()=>{if(!r.hasThread)return;let m=await r.load();if(m){for(let b of m.turns)h(b);p=new Set(m.turns.map(b=>b.id));}},k=()=>{u||l<=0||(u=setInterval(()=>void y(),l));},S=()=>{u&&clearInterval(u),u=void 0;},f=()=>{if(c||!n.socketHost)return;let m=r.socketAuth;m&&(c=new P({auth:m,host:n.socketHost,onClosed:b=>{c=null,k(),b&&f();},onReady:S,onTurn:h,socketFactory:n.socketFactory}),c.open());};return k(),f(),{close:()=>a.close(),destroy:()=>{S(),clearTimeout(i),c?.close(),c=null,a.close(),t.remove();},identify:m=>r.identify(m),open:()=>{a.open().then(f);}}}exports.ChatClient=E;exports.ChatPanel=w;exports.DEFAULT_APPEARANCE=C;exports.DEFAULT_APPEARANCE_SETTINGS=g;exports.mountChat=wt;exports.panelStyles=H;exports.resolveAppearance=T;//# sourceMappingURL=chat.cjs.map
105
+ .scrim,.grip{display:none}@media (max-width:770px){.panel{inset:auto 0 0;width:100%;max-width:none;height:86dvh;max-height:86dvh}:host .panel{border-bottom-left-radius:0;border-bottom-right-radius:0}.scrim{display:block;position:fixed;inset:0;z-index:2147483000;background:rgb(15 23 42/.24)}.grip{display:block;position:absolute;top:7px;left:calc(50% - 17px);width:34px;height:4px;border-radius:2px;background:currentColor;opacity:.45}.panel:not([data-dragging]){transition:translate .2s}.composer{padding-bottom:max(12px,env(safe-area-inset-bottom))}}
106
+ `}${we[t.composerShape]}${Le[t.skin]}${z(t.launcherShape,t.launcherFill,t.launcherContent,t.launcherSize)}${Ae[t.bubbleShape]}${Pe[t.bubbleFill]}${Ne[t.namePlacement]}${t.nameAvatar?_e:""}${t.dayDividers?Fe:""}${Ie[t.stampPlacement]}${t.stampContent==="time_and_latency"?He:""}`}var Ge=["end_user","agent","ai"];function qe(){let n=globalThis.location;if(n)return {host:n.host,path:n.pathname,title:document.title}}var 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>',w=class{constructor(e,t,r={},i={},a={}){this.host=e;this.client=t;l(this,"root");l(this,"strings");l(this,"settings");l(this,"appearance");l(this,"launcher");l(this,"badge");l(this,"panel",null);l(this,"scrim",null);l(this,"lastFocused",null);l(this,"unread",0);l(this,"pendingTurns",0);l(this,"openNow");l(this,"styles");l(this,"scheme");l(this,"picked",null);l(this,"objectUrls",[]);l(this,"helpLoader");l(this,"kit",null);l(this,"kitLoad",null);l(this,"filesLoader");l(this,"filesKit",null);l(this,"filesLoad",null);this.strings={...Te,...r},this.appearance={...E,...i},this.settings=L({...E,...i}),this.root=e.attachShadow({mode:a.shadowMode??"closed"}),this.openNow=N(this.appearance.availability,new Date),this.scheme=a.scheme,this.helpLoader=a.help,this.filesLoader=a.files,this.styles=Je(this.root),this.paint(),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(B(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.strings.launcherLabel,this.launcher.append(e);}this.launcher.append(this.badge),this.launcher.classList.toggle("closed",!this.openNow);}update(e,t){this.appearance={...E,...e},this.settings=L(this.appearance),t!==void 0&&(this.scheme=t),this.paint(),this.drawLauncher(),this.panel&&(this.close(),this.open());}paint(){this.styles(`${q(this.appearance,this.scheme)}${this.kit&&this.appearance.help?this.kit.HELP_CSS:""}${this.filesKit?this.filesKit.filesCss(this.appearance.attachments?.enabled===true,this.settings.composerShape):""}`);}loadKit(){return !this.appearance.help||!this.helpLoader?Promise.resolve(null):(this.kitLoad??(this.kitLoad=this.helpLoader().then(e=>(this.kit=e,this.paint(),e))),this.kitLoad)}loadFiles(){return this.filesLoader?(this.filesLoad??(this.filesLoad=this.filesLoader().then(e=>(this.filesKit=e,this.paint(),e))),this.filesLoad):Promise.resolve(null)}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 r=document.createElement("span");r.className="grip",r.setAttribute("aria-hidden","true"),t.append(r);let i=this.appearance.team??[];i.length>0&&t.append(H(i,this.strings,y=>this.client.avatarUrl(y)));let a=document.createElement("div");a.className="headmain";let o=document.createElement("h2");o.textContent=this.strings.title;let s=document.createElement("p");s.className="status";let h=document.createElement("span");h.className="live",h.setAttribute("aria-hidden","true"),s.append(h,this.strings.replyTime),a.append(o,s);let u=document.createElement("button");u.className="close",u.type="button",u.setAttribute("aria-label",this.strings.closeLabel),u.innerHTML=je,u.addEventListener("click",()=>this.close()),t.append(a,u);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 d=document.createElement("form");d.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 C=document.createElement("span");C.className="sendtext",C.textContent=this.strings.sendLabel,m.append(C),d.append(p,m),d.addEventListener("submit",y=>{y.preventDefault(),this.submit(p,c);}),e.append(t,c,d),e.addEventListener("keydown",y=>this.onKeydown(y,e,u));let S=document.createElement("div");S.className="scrim",S.addEventListener("click",()=>this.close()),this.root.append(S,e),this.panel=e,this.scrim=S,We(e,()=>this.close()),p.focus();let k=this.appearance.attachments,[g]=await Promise.all([this.client.load(),this.loadKit(),k?.enabled&&this.client.upload?this.loadFiles():null]);if(g?.turns.some(y=>y.attachments?.length)&&await this.loadFiles(),this.panel!==e)return;this.filesKit&&k?.enabled&&this.client.upload&&this.filesKit.attachField({attachLabel:this.strings.attachLabel,fileRefusal:this.strings.fileRefusal,hold:y=>{this.picked=y;},objectUrl:y=>this.objectUrl(y),removeFileLabel:this.strings.removeFileLabel,root:this.root},d,p,c,k);let b=this.helpHost();b?.placement==="tab"&&b.host.source.collections&&b.host.source.collectionArticles&&b.kit.helpTab(b.host),b?.placement==="while_typing"&&b.kit.whileTyping(b.host,p,d),g&&g.turns.length>0?this.renderThread(c,g):this.renderFirstRun(c,p),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,r.append(i);let a=this.helpHost();if(a?.placement==="first_view")a.kit.firstView(a.host,r);else {let s=document.createElement("p");s.textContent=this.strings.emptyBody,r.append(s);}this.appearance.starterPrompts.filter(ze).forEach((s,h)=>{let u=document.createElement("div");u.className="prompt";let c=document.createElement("div");c.className="promptwords",c.id=`prompt-${h}`;let d=document.createElement("template");d.innerHTML=s.html,De(d.content)?c.append(d.content):c.textContent=s.text;for(let m of c.querySelectorAll("a"))m.target="_blank",m.rel="noopener noreferrer";let p=document.createElement("button");p.className="promptpress",p.type="button",p.setAttribute("aria-labelledby",c.id),p.addEventListener("click",()=>{t.value=s.text,this.submit(t,e);}),u.append(c,p),r.append(u);}),e.replaceChildren(r);}helpHost(){let e=this.appearance.help,{kit:t,panel:r}=this,i=e&&t&&r?t.hostOf(this.client,{close:()=>this.close(),closeLabel:this.strings.closeLabel,panel:r,scheme:this.scheme,words:e.words}):null;return i&&t&&e?{host:i,kit:t,placement:e.placement}:null}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);}objectUrl(e){let t=URL.createObjectURL(e);return this.objectUrls.push(t),t}close(){if(this.panel){this.panel.remove(),this.scrim?.remove(),this.panel=null,this.scrim=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&&e.attachments?.length&&!this.filesKit&&this.filesLoader){this.loadFiles().then(()=>this.takeTurn(e));return}this.takeTurn(e);}takeTurn(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 a of this.root.querySelectorAll(".file,.ferr,.hsugg"))a.remove();await this.sendBody(t,r,i);}}async sendBody(e,t,r=null){e.querySelector(".empty")?.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 a=r?await this.client.upload?.(r):void 0,o=a===null?null:await this.client.send(t,qe(),a?[a.id]:void 0);if(i.removeAttribute("data-pending"),o){i.dataset.turnId=o.id;return}this.markFailed(e,i,t,r);}markFailed(e,t,r,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")??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,r=null){e.querySelector(".empty")?.remove();let i=Ge.includes(t.authorKind)?t.authorKind:"agent",a=this.settings,o=document.createElement("div");if(o.className=`turn ${i}`,o.dataset.turnId=t.id,i!=="end_user"&&a.nameAvatar){let d=document.createElement("span");if(d.className=i==="ai"?"av bot":"av",d.setAttribute("aria-hidden","true"),i==="agent"&&t.authorAvatarUrl){let p=document.createElement("img");p.alt="",p.src=this.client.avatarUrl(t.authorAvatarUrl),d.append(p);}else {d.textContent=i==="ai"?this.strings.aiLabel:K(this.agentName(t));let p=i==="agent"?this.appearance.team?.find(m=>m.name===t.authorName)?.tone:void 0;p&&(d.style.background=p);}o.append(d);}let h=document.createElement("div");if(h.className="body",i==="end_user"){let d=this.filesKit,p=m=>this.objectUrl(m);r&&d?.drawFile(h,r.name,r.type,r.size,Promise.resolve(r),p);for(let m of t.attachments??[])d?.drawFile(h,m.name,m.contentType,m.bytes,this.client.file?.(m.url)??Promise.resolve(null),p);}let u=i!=="end_user"&&a.namePlacement!=="hidden",c=document.createElement("div");if(i==="ai"?Ue(c,t.body):c.textContent=t.body,u||i==="ai"&&a.namePlacement==="hidden"){let d=document.createElement("div");d.className=i==="ai"?"author ai":"author",d.textContent=i==="ai"?this.strings.aiLabel:this.agentName(t),a.stampPlacement==="beside_name"&&d.append(this.stamp(t)),a.namePlacement==="inline"?(d.classList.add("below"),h.append(c,d)):h.append(d,c);}else t.body&&h.append(c);return a.stampPlacement==="under_turn"&&h.append(this.stamp(t)),o.append(h),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,r){if(e.key==="Escape"){e.preventDefault(),this.close();return}if(e.key!=="Tab")return;let i=[...t.querySelectorAll('button, input, a[href], [tabindex]:not([tabindex="-1"])')].filter(h=>!h.closest("[hidden]")&&!h.hidden);if(i.length===0)return;let a=i[0],o=i[i.length-1],s=this.root.activeElement;e.shiftKey&&s===a?(e.preventDefault(),o.focus()):!e.shiftKey&&s===o?(e.preventDefault(),a.focus()):s===null&&(e.preventDefault(),r.focus());}renderBadge(){this.unread>0?(this.badge.hidden=false,this.badge.textContent=String(this.unread),this.launcher.setAttribute("aria-label",`${this.strings.launcherLabel}, ${this.strings.unreadLabel(this.unread)}`)):(this.badge.hidden=true,this.badge.textContent="",this.launcher.setAttribute("aria-label",this.strings.launcherLabel));}},Ye="(max-width: 770px)";function We(n,e){let t=null;n.addEventListener("pointerdown",i=>{if(t||i.button!==0||!globalThis.matchMedia?.(Ye).matches)return;let a=i.target;if(!a?.closest("a, button, input, textarea, iframe")){for(;a&&a!==n;a=a.parentElement)if(a.scrollTop>0)return;t={at:i.timeStamp,id:i.pointerId,offset:0,startY:i.clientY},n.setPointerCapture?.(i.pointerId),n.dataset.dragging="";}}),n.addEventListener("pointermove",i=>{if(t?.id!==i.pointerId)return;let a=i.clientY-t.startY;t.offset=a>=0?a:-16*(1-Math.exp(a/48)),n.style.translate=`0 ${t.offset}px`;});let r=i=>{let a=t;if(a?.id!==i.pointerId)return;t=null,delete n.dataset.dragging;let o=a.offset>Math.min(72,n.getBoundingClientRect().height*.4),s=a.offset/Math.max(1,i.timeStamp-a.at)>.5&&a.offset>16;o||s?e():n.style.translate="";};n.addEventListener("pointerup",r),n.addEventListener("pointercancel",r);}var Je=n=>{if(typeof CSSStyleSheet=="function"&&"adoptedStyleSheets"in n&&"replaceSync"in CSSStyleSheet.prototype){let t=new CSSStyleSheet;return n.adoptedStyleSheets=[t],r=>t.replaceSync(r)}let e=document.createElement("style");return n.append(e),t=>{e.textContent=t;}};function j(n){return `40${JSON.stringify(n)}`}function Y(){return "3"}function W(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=R(t);return {kind:"open",pingInterval:typeof o?.pingInterval=="number"?o.pingInterval:25e3,pingTimeout:typeof o?.pingTimeout=="number"?o.pingTimeout:2e4}}if(e!=="4")return {kind:"other"};let r=t.charAt(0),i=t.slice(1);if(r==="0")return {kind:"connected"};if(r==="1")return {kind:"disconnect"};if(r==="4"){let o=R(i);return {kind:"connectError",message:typeof o?.message=="string"?o.message:"refused"}}if(r!=="2")return {kind:"other"};let a=R(i);return !Array.isArray(a)||typeof a[0]!="string"?{kind:"other"}:{kind:"event",name:a[0],payload:a[1]}}function R(n){try{return JSON.parse(n)}catch{return null}}var Ve="/socket.io/?EIO=4&transport=websocket",_=class{constructor(e){this.options=e;l(this,"socket",null);l(this,"heartbeat",null);l(this,"ready",false);l(this,"closed",false);l(this,"heartbeatWindow",45e3);l(this,"factory");l(this,"setTimer");l(this,"clearTimer");this.factory=e.socketFactory??Xe,this.setTimer=e.setTimer??((t,r)=>setTimeout(t,r)),this.clearTimer=e.clearTimer??(t=>clearTimeout(t));}open(){if(this.socket||this.closed)return;let e=`${this.options.host.replace(/^http/,"ws").replace(/\/+$/,"")}${Ve}`,t;try{t=this.factory(e);}catch{this.options.onClosed(false);return}this.socket=t,t.onmessage=r=>this.receive(String(r.data)),t.onerror=()=>t.close(),t.onclose=()=>this.fell();}close(){this.closed=true,this.stopHeartbeat();let e=this.socket;this.socket=null,e?.close();}receive(e){let t=W(e);if(t.kind==="open"){this.armHeartbeat(t.pingInterval+t.pingTimeout),this.socket?.send(j(this.options.auth));return}if(t.kind==="ping"){this.armHeartbeat(),this.socket?.send(Y());return}if(t.kind==="connectError"||t.kind==="disconnect"){this.stopHeartbeat(),this.socket?.close();return}if(t.kind==="event"){if(t.name==="ready"){this.ready=true,this.options.onReady();return}if(t.name==="conversation.turn"){let r=t.payload?.turn;r&&this.options.onTurn(r);}}}fell(){this.stopHeartbeat();let e=this.ready;this.socket=null,this.ready=false,this.closed||this.options.onClosed(e);}armHeartbeat(e){e!==void 0&&(this.heartbeatWindow=e),this.stopHeartbeat(),this.heartbeat=this.setTimer(()=>this.socket?.close(),this.heartbeatWindow);}stopHeartbeat(){this.heartbeat!==null&&this.clearTimer(this.heartbeat),this.heartbeat=null;}};function Xe(n){let e=globalThis.WebSocket;if(!e)throw new v("no WebSocket");return new e(n)}var Ze=6e4;function Tt(n){let e=globalThis.document;if(!e)throw new P("prodantix chat requires a document; mount it in the browser");let t=n.mountPoint??e.createElement("div");n.mountPoint||e.body.append(t);let r=new T(n),i=new w(t,r,n.strings,n.appearance,{files:n.files,help:n.help}),a=n.appearance?.availability??E.availability,o,s=()=>{i.setOpenNow(N(a,new Date)),o=setTimeout(s,Ze);};s();let h=new Set,u,c=null,d=n.pollIntervalMs??15e3,p=g=>{h.has(g.id)||g.authorKind==="end_user"||(h.add(g.id),i.onIncomingTurn(g));},m=async()=>{if(!r.hasThread)return;let g=await r.load();if(g){for(let b of g.turns)p(b);h=new Set(g.turns.map(b=>b.id));}},C=()=>{u||d<=0||(u=setInterval(()=>void m(),d));},S=()=>{u&&clearInterval(u),u=void 0;},k=()=>{if(c||!n.socketHost)return;let g=r.socketAuth;g&&(c=new _({auth:g,host:n.socketHost,onClosed:b=>{c=null,C(),b&&k();},onReady:S,onTurn:p,socketFactory:n.socketFactory}),c.open());};return C(),k(),{close:()=>i.close(),destroy:()=>{S(),clearTimeout(o),c?.close(),c=null,i.close(),t.remove();},identify:g=>r.identify(g),open:()=>{i.open().then(k);}}}exports.ChatClient=T;exports.ChatPanel=w;exports.DEFAULT_APPEARANCE=E;exports.DEFAULT_APPEARANCE_SETTINGS=f;exports.mountChat=Tt;exports.panelStyles=q;exports.resolveAppearance=L;//# sourceMappingURL=chat.cjs.map
106
107
  //# sourceMappingURL=chat.cjs.map
package/dist/chat.d.cts CHANGED
@@ -1,8 +1,105 @@
1
- import { C as ChatThread, P as PageContext, a as ChatTurn, b as ChatUpload, M as MessengerConfig, A as AppearanceSettings, c as ChatIdentity, d as ChatClientOptions } from './config-CMF9zz1a.cjs';
2
- export { B as BubbleFill, e as BubbleShape, f as ChatAttachment, g as ChatClient, h as ChatStorage, i as ComposerShape, D as DEFAULT_APPEARANCE_SETTINGS, F as FileFetchLike, j as FileResponseLike, L as LauncherContent, k as LauncherFill, l as LauncherShape, m as LauncherSize, n as MessengerSkin, N as NamePlacement, S as StampContent, o as StampPlacement, r as resolveAppearance } from './config-CMF9zz1a.cjs';
3
- import { S as SocketFactory } from './types-DjMXp6Wg.cjs';
1
+ import { A as ArticleHit, a as ArticleCollection, H as HelpWords, M as MessengerAttachments, b as AppearanceSettings, C as ChatThread, P as PageContext, c as ChatTurn, d as ChatUpload, e as MessengerConfig, f as ChatIdentity, g as ChatClientOptions } from './config-g14Jiv1t.cjs';
2
+ export { B as BubbleFill, h as BubbleShape, i as ChatAttachment, j as ChatClient, k as ChatStorage, l as ComposerShape, D as DEFAULT_APPEARANCE_SETTINGS, F as FileFetchLike, m as FileResponseLike, L as LauncherContent, n as LauncherFill, o as LauncherShape, p as LauncherSize, q as MessengerSkin, N as NamePlacement, S as StampContent, r as StampPlacement, s as resolveAppearance } from './config-g14Jiv1t.cjs';
3
+ import { S as SocketFactory } from './types-Q2VNlJbG.cjs';
4
4
  import './http-BCh716Vs.cjs';
5
5
 
6
+ declare const SEARCH_PAUSE_MS = 300;
7
+ declare const TYPED_MINIMUM = 3;
8
+ declare const SUGGESTED = 3;
9
+ declare const HELP_CSS = "[hidden]{display:none!important}.hsearch{display:flex;align-items:center;gap:8px;height:40px;padding:0 12px;color:var(--ink-3);border:1px solid var(--hairline);border-radius:10px}.hsearch:focus-within{border-color:var(--a);box-shadow:0 0 0 3px color-mix(in srgb,var(--a) 20%,transparent)}.hsearch input{flex:1;min-width:0;height:100%;padding:0;border:0;outline:0;background:none;font:inherit;font-size:14px;color:var(--ink)}.hsearch input::placeholder{color:var(--ink-3)}.hsearch svg,.hrow svg{display:block;flex:none;width:16px;height:16px;fill:currentColor}.hlabel{margin:6px 0 0;font-size:12px;font-weight:600;color:var(--ink-3)}.hrows{display:flex;flex-direction:column}.hrow{display:flex;align-items:center;gap:10px;width:100%;padding:10px 2px;font:inherit;font-size:14px;color:var(--ink);text-align:left;background:none;border:0;border-bottom:1px solid var(--hairline);cursor:pointer}.hrow span{flex:1;min-width:0}.hrow small{font-size:12px;color:var(--ink-3)}.hrow svg{color:var(--ink-3)}.hrow:focus-visible{outline:2px solid var(--a);outline-offset:-2px}.hnone{margin:0;padding:10px 2px;font-size:13.5px;color:var(--ink-2)}.hview{flex:1;min-height:0;overflow-y:auto;display:flex;flex-direction:column;gap:10px;padding:16px}.htabs{display:grid;grid-template-columns:1fr 1fr;border-top:1px solid var(--hairline)}.htab{display:flex;flex-direction:column;align-items:center;gap:2px;padding:8px 0 10px;font:inherit;font-size:11.5px;font-weight:550;color:var(--ink-3);background:none;border:0;cursor:pointer}.htab[aria-selected=\"true\"]{color:var(--a)}.htab svg{display:block;width:22px;height:22px;fill:currentColor}.htab:focus-visible{outline:2px solid var(--a);outline-offset:-2px}.hsugg{margin:0 10px 8px;padding:10px 12px 4px;border:1px solid var(--hairline);border-radius:10px}.hsugg p{margin:0 0 4px;font-size:12px;font-weight:600;color:var(--ink-3)}.hsugg .hrow{padding:8px 0;font-size:13.5px}.hsugg .hrow:last-child{border-bottom:0}.hreader{flex:1;min-height:0;display:flex;flex-direction:column}.hbar{flex:none;display:flex;align-items:center;gap:6px;height:52px;padding:0 8px;border-bottom:1px solid var(--hairline)}.hbar b{flex:1;min-width:0;font-size:14px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.hbtn{display:grid;place-items:center;flex:none;width:32px;height:32px;padding:0;border:0;border-radius:8px;background:none;color:var(--ink);cursor:pointer}.hbtn svg{display:block;width:20px;height:20px;fill:currentColor}.hbtn:hover{background:color-mix(in srgb,currentColor 14%,transparent)}.hbtn:focus-visible{outline:2px solid var(--a)}.hreader iframe{flex:1;min-height:0;width:100%;border:0}.hblocked{flex:1;display:flex;flex-direction:column;gap:8px;padding:20px 18px}.hblocked h3{margin:0;font-size:18px;font-weight:640;letter-spacing:-.015em}.hblocked a{font-size:14px;color:var(--ink);text-decoration:underline}.hmore{flex:none;display:flex;align-items:center;justify-content:space-between;gap:10px;margin:6px 18px 16px;padding:12px 14px;font-size:13.5px;background:var(--fill);border-radius:10px}.hmore button{padding:7px 14px;font:inherit;font-size:13px;font-weight:600;color:#fff;white-space:nowrap;background:var(--a);border:0;border-radius:8px;cursor:pointer}.hmore button:focus-visible{outline:2px solid var(--ink);outline-offset:2px}.hrow,.htab,.hmore,.hlabel,.hnone,.hsugg p{line-height:1.45}";
10
+ declare function searchBox(words: HelpWords, onWords: (words: string) => void): HTMLElement;
11
+ declare function paused(run: (words: string) => void): (words: string) => void;
12
+ declare const isReadable: (hit: ArticleHit) => boolean;
13
+ declare function articleRows(rows: HTMLElement, found: readonly ArticleHit[], noMatches: string | null, onOpen: (hit: ArticleHit) => void): HTMLElement;
14
+ declare function collectionRows(rows: HTMLElement, collections: readonly ArticleCollection[], onOpen: (collection: ArticleCollection) => void): HTMLElement;
15
+ declare function emptyRows(): HTMLElement;
16
+ declare function helpTabs(words: HelpWords, onPick: (help: boolean) => void): HTMLElement;
17
+ declare function suggestions(words: HelpWords, hits: readonly ArticleHit[], onOpen: (hit: ArticleHit) => void): HTMLElement;
18
+ interface ReaderControls {
19
+ back: () => void;
20
+ close: () => void;
21
+ messageUs: () => void;
22
+ }
23
+ declare function frameAddress(embedUrl: string, scheme: 'dark' | 'light'): string;
24
+ declare function reader(hit: ArticleHit, words: HelpWords, closeLabel: string, scheme: 'dark' | 'light', controls: ReaderControls): HTMLElement;
25
+ interface HelpSource {
26
+ articles?(query: string): Promise<ArticleHit[]>;
27
+ popularArticles?(): Promise<ArticleHit[]>;
28
+ collections?(): Promise<ArticleCollection[]>;
29
+ collectionArticles?(collection: string): Promise<ArticleHit[]>;
30
+ }
31
+ type HelpRead = <T>(suffix: string, params: Record<string, string>) => Promise<T | null>;
32
+ declare function helpReads(read: HelpRead): Required<HelpSource>;
33
+ interface HelpHost {
34
+ close: () => void;
35
+ closeLabel: string;
36
+ panel: HTMLElement;
37
+ scheme: 'dark' | 'light' | 'system' | undefined;
38
+ source: HelpSource;
39
+ words: HelpWords;
40
+ }
41
+ type HelpClient = HelpSource & {
42
+ helpCentre?: HelpRead;
43
+ };
44
+ declare function hostOf(client: HelpClient, lent: Omit<HelpHost, 'source'>): HelpHost | null;
45
+ declare function setHelping(panel: HTMLElement, helping: boolean): void;
46
+ declare function showArticle(host: HelpHost, hit: ArticleHit): void;
47
+ declare function firstView(host: HelpHost, empty: HTMLElement): void;
48
+ declare function helpTab(host: HelpHost): void;
49
+ declare function whileTyping(host: HelpHost, input: HTMLInputElement, composer: HTMLElement): void;
50
+
51
+ declare const Articles_HELP_CSS: typeof HELP_CSS;
52
+ type Articles_HelpClient = HelpClient;
53
+ type Articles_HelpHost = HelpHost;
54
+ type Articles_HelpRead = HelpRead;
55
+ type Articles_HelpSource = HelpSource;
56
+ type Articles_ReaderControls = ReaderControls;
57
+ declare const Articles_SEARCH_PAUSE_MS: typeof SEARCH_PAUSE_MS;
58
+ declare const Articles_SUGGESTED: typeof SUGGESTED;
59
+ declare const Articles_TYPED_MINIMUM: typeof TYPED_MINIMUM;
60
+ declare const Articles_articleRows: typeof articleRows;
61
+ declare const Articles_collectionRows: typeof collectionRows;
62
+ declare const Articles_emptyRows: typeof emptyRows;
63
+ declare const Articles_firstView: typeof firstView;
64
+ declare const Articles_frameAddress: typeof frameAddress;
65
+ declare const Articles_helpReads: typeof helpReads;
66
+ declare const Articles_helpTab: typeof helpTab;
67
+ declare const Articles_helpTabs: typeof helpTabs;
68
+ declare const Articles_hostOf: typeof hostOf;
69
+ declare const Articles_isReadable: typeof isReadable;
70
+ declare const Articles_paused: typeof paused;
71
+ declare const Articles_reader: typeof reader;
72
+ declare const Articles_searchBox: typeof searchBox;
73
+ declare const Articles_setHelping: typeof setHelping;
74
+ declare const Articles_showArticle: typeof showArticle;
75
+ declare const Articles_suggestions: typeof suggestions;
76
+ declare const Articles_whileTyping: typeof whileTyping;
77
+ declare namespace Articles {
78
+ export { Articles_HELP_CSS as HELP_CSS, type Articles_HelpClient as HelpClient, type Articles_HelpHost as HelpHost, type Articles_HelpRead as HelpRead, type Articles_HelpSource as HelpSource, type Articles_ReaderControls as ReaderControls, Articles_SEARCH_PAUSE_MS as SEARCH_PAUSE_MS, Articles_SUGGESTED as SUGGESTED, Articles_TYPED_MINIMUM as TYPED_MINIMUM, Articles_articleRows as articleRows, Articles_collectionRows as collectionRows, Articles_emptyRows as emptyRows, Articles_firstView as firstView, Articles_frameAddress as frameAddress, Articles_helpReads as helpReads, Articles_helpTab as helpTab, Articles_helpTabs as helpTabs, Articles_hostOf as hostOf, Articles_isReadable as isReadable, Articles_paused as paused, Articles_reader as reader, Articles_searchBox as searchBox, Articles_setHelping as setHelping, Articles_showArticle as showArticle, Articles_suggestions as suggestions, Articles_whileTyping as whileTyping };
79
+ }
80
+
81
+ declare const filesCss: (taking: boolean, composerShape: AppearanceSettings["composerShape"]) => string;
82
+ declare function sizeOf(bytes: number): string;
83
+ interface FilesHost {
84
+ attachLabel: string;
85
+ removeFileLabel: string;
86
+ fileRefusal: (size: string, limit: string) => string;
87
+ objectUrl: (blob: Blob) => string;
88
+ root: ShadowRoot;
89
+ hold: (file: File | null) => void;
90
+ }
91
+ declare function attachField(host: FilesHost, composer: HTMLElement, input: HTMLInputElement, log: HTMLElement, files: MessengerAttachments): void;
92
+ declare function drawFile(parent: HTMLElement, name: string, type: string, bytes: number, blob: Promise<Blob | null>, objectUrl: (blob: Blob) => string): void;
93
+
94
+ type Files_FilesHost = FilesHost;
95
+ declare const Files_attachField: typeof attachField;
96
+ declare const Files_drawFile: typeof drawFile;
97
+ declare const Files_filesCss: typeof filesCss;
98
+ declare const Files_sizeOf: typeof sizeOf;
99
+ declare namespace Files {
100
+ export { type Files_FilesHost as FilesHost, Files_attachField as attachField, Files_drawFile as drawFile, Files_filesCss as filesCss, Files_sizeOf as sizeOf };
101
+ }
102
+
6
103
  interface ChatStrings {
7
104
  launcherLabel: string;
8
105
  title: string;
@@ -22,7 +119,7 @@ interface ChatStrings {
22
119
  removeFileLabel: string;
23
120
  fileRefusal: (size: string, limit: string) => string;
24
121
  }
25
- type MessengerAppearance = Pick<MessengerConfig, 'accentColor' | 'attachments' | 'availability' | 'awayMessage' | 'greeting' | 'launcherOffsetX' | 'launcherOffsetY' | 'launcherPosition' | 'starterPrompts' | 'team'> & AppearanceSettings;
122
+ type MessengerAppearance = Pick<MessengerConfig, 'accentColor' | 'attachments' | 'availability' | 'awayMessage' | 'greeting' | 'launcherOffsetX' | 'launcherOffsetY' | 'launcherPosition' | 'help' | 'starterPrompts' | 'team'> & AppearanceSettings;
26
123
  declare const DEFAULT_APPEARANCE: MessengerAppearance;
27
124
  interface ChatSource {
28
125
  avatarUrl(url: string): string;
@@ -30,9 +127,18 @@ interface ChatSource {
30
127
  send(body: string, pageContext?: PageContext, attachmentIds?: string[]): Promise<ChatTurn | null>;
31
128
  upload?(file: File): Promise<ChatUpload | null>;
32
129
  file?(path: string): Promise<Blob | null>;
130
+ articles?(query: string): Promise<ArticleHit[]>;
131
+ popularArticles?(): Promise<ArticleHit[]>;
132
+ collections?(): Promise<ArticleCollection[]>;
133
+ collectionArticles?(collection: string): Promise<ArticleHit[]>;
134
+ helpCentre?<T>(suffix: string, params: Record<string, string>): Promise<T | null>;
33
135
  }
34
136
  type ChatScheme = 'dark' | 'light' | 'system';
137
+ type HelpKit = typeof Articles;
138
+ type FilesKit = typeof Files;
35
139
  interface ChatPanelOptions {
140
+ help?: () => Promise<HelpKit | null>;
141
+ files?: () => Promise<FilesKit | null>;
36
142
  scheme?: ChatScheme;
37
143
  shadowMode?: 'closed' | 'open';
38
144
  }
@@ -47,26 +153,37 @@ declare class ChatPanel {
47
153
  private readonly launcher;
48
154
  private readonly badge;
49
155
  private panel;
156
+ private scrim;
50
157
  private lastFocused;
51
158
  private unread;
52
159
  private pendingTurns;
53
160
  private openNow;
54
- private readonly style;
161
+ private readonly styles;
55
162
  private scheme;
56
163
  private picked;
57
164
  private objectUrls;
165
+ private readonly helpLoader;
166
+ private kit;
167
+ private kitLoad;
168
+ private readonly filesLoader;
169
+ private filesKit;
170
+ private filesLoad;
58
171
  constructor(host: HTMLElement, client: ChatSource, strings?: Partial<ChatStrings>, appearance?: Partial<MessengerAppearance>, options?: ChatPanelOptions);
59
172
  private drawLauncher;
60
173
  update(appearance: Partial<MessengerAppearance>, scheme?: ChatScheme): void;
174
+ private paint;
175
+ private loadKit;
176
+ private loadFiles;
61
177
  private toggle;
62
178
  setOpenNow(open: boolean): void;
63
179
  open(): Promise<void>;
64
180
  private renderFirstRun;
181
+ private helpHost;
65
182
  private renderAway;
66
- private pick;
67
183
  private objectUrl;
68
184
  close(): void;
69
185
  onIncomingTurn(turn: ChatTurn): void;
186
+ private takeTurn;
70
187
  private submit;
71
188
  /**
72
189
  * Draw the visitor's words, then send them.
@@ -95,7 +212,6 @@ declare class ChatPanel {
95
212
  private hasTurn;
96
213
  private renderThread;
97
214
  private appendTurn;
98
- private drawFile;
99
215
  private agentName;
100
216
  private stamp;
101
217
  private onKeydown;
@@ -109,6 +225,8 @@ interface MountChatOptions extends ChatClientOptions {
109
225
  pollIntervalMs?: number;
110
226
  socketHost?: string;
111
227
  socketFactory?: SocketFactory;
228
+ help?: () => Promise<HelpKit | null>;
229
+ files?: () => Promise<FilesKit | null>;
112
230
  }
113
231
  interface ChatHandle {
114
232
  open(): void;