@useago/sdk 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/widget.cjs CHANGED
@@ -1,5 +1,5 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ae=require("./AgoClient-CzSmJQxl.cjs"),dt=require("./createFormCollector-BB3Uscuo.cjs"),Gt=require("./createConversationSession-DV0Xp_3O.cjs");var jt='"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',Se=`var(--ago-font, ${jt})`,ct={font:"--ago-font",radius:"--ago-radius",messageRadius:"--ago-message-radius",brand:"--ago-brand-color",brandText:"--ago-brand-text-color",headerBg:"--ago-header-background",headerText:"--ago-header-text-color",panelBg:"--ago-panel-background",messagesBg:"--ago-messages-background",text:"--ago-text-color",mutedText:"--ago-muted-text-color",border:"--ago-border-color",accent:"--ago-accent-color",agentBubbleBg:"--ago-agent-bubble-background"},ke="var(--ago-brand-color, #03182f)",Ae="var(--ago-brand-text-color, #fff)",Vt="var(--ago-header-background, var(--ago-brand-color, #03182f))",pt="var(--ago-header-text-color, #e8f0fe)",ee="var(--ago-panel-background, #fff)",ht="var(--ago-messages-background, #fbfbfb)",J="var(--ago-text-color, #30373e)",xt="var(--ago-muted-text-color, #6b6d6f)",L="var(--ago-border-color, #dee3e8)",Be="var(--ago-accent-color, #1b5fc4)",ft="var(--ago-agent-bubble-background, #f1f3f5)",qt="var(--ago-radius, 16px)",De="var(--ago-message-radius, 16px)",Kt="var(--ago-message-radius, 20px)";function Xt(n,o){if(o)for(const i of Object.keys(ct)){const r=o[i];r!=null&&n.style.setProperty(ct[i],r)}}function v(n,o){Object.assign(n.style,o)}function h(n={}){const o=document.createElement("div");return v(o,n),o}var ut="ago-chat-widget-keyframes";function Qt(){if(typeof document>"u"||document.getElementById(ut))return;const n=document.createElement("style");n.id=ut,n.textContent="@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }@keyframes ago-spin { to { transform: rotate(360deg); } }",document.head.appendChild(n)}function Yt(n){let o=[];const i=document.createElement("form");v(i,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${L}`,backgroundColor:ee}),i.className="ago-chat-input";const r=h({display:"flex",flexWrap:"wrap",gap:"6px"}),b=h({display:"flex",gap:"8px",alignItems:"flex-end"}),a=document.createElement("textarea");a.placeholder=n.placeholder,a.setAttribute("aria-label",n.placeholder),a.rows=1,v(a,{flex:"1",resize:"none",boxSizing:"border-box",padding:"10px 12px",border:`1px solid ${L}`,borderRadius:"12px",fontSize:"16px",fontFamily:Se,lineHeight:"1.4",maxHeight:"110px",overflowY:"hidden"});const C=()=>{a.style.height="auto";const c=Math.min(a.scrollHeight+2,110);a.style.height=`${c}px`,a.style.overflowY=a.scrollHeight+2>110?"auto":"hidden"};a.addEventListener("input",()=>{C(),A()});const m='<svg width="18" height="18" viewBox="0 -960 960 960" fill="currentColor" aria-hidden="true"><path d="M440-160v-487L216-423l-56-57 320-320 320 320-56 57-224-224v487h-80Z"/></svg>',x='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true" style="animation: ago-spin 0.8s linear infinite"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>',p=document.createElement("button");p.type="submit",p.setAttribute("aria-label","Send"),p.innerHTML=m,v(p,{flexShrink:"0",width:"40px",height:"40px",padding:"0",border:"none",borderRadius:"50%",backgroundColor:ke,color:Ae,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer"});let f=!1;const A=()=>{const s=a.value.trim()!==""||o.length>0,c=f||!s;p.disabled=c,p.innerHTML=f?x:m,p.style.opacity=c&&!f?"0.5":"1",p.style.cursor=c?"default":"pointer"};let R=null,_=null;n.allowFiles&&(R=document.createElement("input"),R.type="file",R.multiple=!0,v(R,{display:"none"}),_=document.createElement("button"),_.type="button",_.setAttribute("aria-label","Attach file"),_.textContent="📎",v(_,{padding:"10px 12px",border:`1px solid ${L}`,borderRadius:"12px",backgroundColor:ee,cursor:"pointer",fontSize:"14px"}),_.addEventListener("click",()=>R?.click()),R.addEventListener("change",()=>{o=[...o,...Array.from(R?.files??[])],Y()}));function Y(){r.replaceChildren(),o.forEach((s,c)=>{const y=h({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${L}`,borderRadius:"8px",fontSize:"12px"}),T=document.createElement("span");T.textContent=s.name;const k=document.createElement("button");k.type="button",k.setAttribute("aria-label",`Remove ${s.name}`),k.textContent="×",v(k,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),k.addEventListener("click",()=>{o=o.filter((G,j)=>j!==c),Y()}),y.append(T,k),r.appendChild(y)}),A()}const B=()=>{const s=a.value,c=o;return a.value="",C(),o=[],Y(),{content:s,files:c}},g=()=>{const{content:s,files:c}=B();(s.trim()||c.length>0)&&n.onSend(s.trim(),c.length>0?c:void 0)};return i.addEventListener("submit",s=>{s.preventDefault(),g()}),a.addEventListener("keydown",s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),g())}),_&&b.appendChild(_),b.append(a,p),R&&i.appendChild(R),i.append(r,b),A(),{inputRow:i,getValueAndClear:B,setDisabled:s=>{a.disabled=s,f=s,A()},focus:()=>a.focus()}}var Zt={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function ie(n){return n.replace(/[&<>"']/g,o=>Zt[o])}function mt(n){const o=n.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(o)||!/^[a-z][a-z0-9+.-]*:/i.test(o)?o:null}var bt='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',Ee="";function te(n){const o=[],i=b=>(o.push(b),`${Ee}${o.length-1}${Ee}`);let r=n;return r=r.replace(/`([^`]+)`/g,(b,a)=>i(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${bt}">${ie(a)}</code>`)),r=r.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(b,a,C)=>{const m=mt(C);return m?i(`<img alt="${ie(a)}" src="${ie(m)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):b}),r=r.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(b,a,C)=>{const m=mt(C);return m?i(`<a href="${ie(m)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${te(a)}</a>`):b}),r=ie(r),r=r.replace(/\*\*([^*]+?)\*\*/g,"<strong>$1</strong>").replace(/__([^_]+?)__/g,"<strong>$1</strong>").replace(/~~([^~]+?)~~/g,"<del>$1</del>").replace(/(^|[^*])\*(?!\s)([^*]+?)\*/g,"$1<em>$2</em>").replace(/(^|[^\w_])_(?!\s)([^_]+?)_/g,"$1<em>$2</em>"),r=r.replace(new RegExp(`${Ee}(\\d+)${Ee}`,"g"),(b,a)=>o[Number(a)]),r}function O(n,o,i){const r=document.createElement(n);return Object.assign(r.style,o),i!==void 0&&(r.innerHTML=i),r}var vt=/^ {0,3}([-*_])( *\1){2,} *$/,yt=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,wt=/^ {0,3}(```+|~~~+)/,Re=/^ {0,3}>\s?/,se=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,Jt=["20px","18px","16px","15px","14px","13px"],ze=n=>n.match(/^\s*/)?.[0].length??0;function en(n){return n.trim()===""||vt.test(n)||yt.test(n)||wt.test(n)||Re.test(n)||se.test(n)}function Ct(n){const o=n[0].match(se),i=o[1].length,r=/\d/.test(o[2]),b=O(r?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:r?"decimal":"disc",listStylePosition:"outside"});let a=0;for(;a<n.length;){const C=n[a].match(se),m=[];for(a++;a<n.length&&ze(n[a])>i;)m.push(n[a]),a++;const x=O("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),p=C[3].match(/^\[([ xX])\]\s+(.*)$/);p?(x.style.listStyleType="none",x.style.marginLeft="-20px",x.innerHTML=`<span style="margin-right:6px">${p[1].toLowerCase()==="x"?"☑":"☐"}</span>${te(p[2])}`):x.innerHTML=te(C[3]),m.filter(f=>se.test(f)).length>0&&x.appendChild(Ct(m.filter(f=>f.trim()!==""))),b.appendChild(x)}return b}function tn(n){const o=m=>m.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(x=>x.trim()),i=O("div",{overflowX:"auto",margin:"0 0 8px 0"}),r=O("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),b=document.createElement("thead"),a=document.createElement("tr");for(const m of o(n[0]))a.appendChild(O("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},te(m)));b.appendChild(a),r.appendChild(b);const C=document.createElement("tbody");for(const m of n.slice(2)){const x=document.createElement("tr");for(const p of o(m))x.appendChild(O("td",{border:"1px solid #dee3e8",padding:"6px 10px"},te(p)));C.appendChild(x)}return r.appendChild(C),i.appendChild(r),i}var nn=n=>!!n&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(n);function _e(n){const o=document.createDocumentFragment(),i=n.replace(/\r\n?/g,`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const se=require("./AgoClient-CzSmJQxl.cjs"),ct=require("./createFormCollector-BB3Uscuo.cjs"),Gt=require("./createConversationSession-DV0Xp_3O.cjs");var jt='"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',Re=`var(--ago-font, ${jt})`,pt={font:"--ago-font",radius:"--ago-radius",messageRadius:"--ago-message-radius",brand:"--ago-brand-color",brandText:"--ago-brand-text-color",headerBg:"--ago-header-background",headerText:"--ago-header-text-color",panelBg:"--ago-panel-background",messagesBg:"--ago-messages-background",text:"--ago-text-color",mutedText:"--ago-muted-text-color",border:"--ago-border-color",accent:"--ago-accent-color",agentBubbleBg:"--ago-agent-bubble-background"},Ae="var(--ago-brand-color, #03182f)",_e="var(--ago-brand-text-color, #fff)",Vt="var(--ago-header-background, var(--ago-brand-color, #03182f))",ft="var(--ago-header-text-color, #e8f0fe)",ee="var(--ago-panel-background, #fff)",xt="var(--ago-messages-background, #fbfbfb)",J="var(--ago-text-color, #30373e)",bt="var(--ago-muted-text-color, #6b6d6f)",L="var(--ago-border-color, #dee3e8)",De="var(--ago-accent-color, #1b5fc4)",ut="var(--ago-agent-bubble-background, #f1f3f5)",qt="var(--ago-radius, 16px)",ze="var(--ago-message-radius, 16px)",Kt="var(--ago-message-radius, 20px)";function Xt(n,o){if(o)for(const i of Object.keys(pt)){const r=o[i];r!=null&&n.style.setProperty(pt[i],r)}}function v(n,o){Object.assign(n.style,o)}function h(n={}){const o=document.createElement("div");return v(o,n),o}var mt="ago-chat-widget-keyframes";function Qt(){if(typeof document>"u"||document.getElementById(mt))return;const n=document.createElement("style");n.id=mt,n.textContent="@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }@keyframes ago-spin { to { transform: rotate(360deg); } }",document.head.appendChild(n)}function Yt(n){let o=[];const i=document.createElement("form");v(i,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${L}`,backgroundColor:ee}),i.className="ago-chat-input";const r=h({display:"flex",flexWrap:"wrap",gap:"6px"}),b=h({display:"flex",gap:"8px",alignItems:"flex-end"}),a=document.createElement("textarea");a.placeholder=n.placeholder,a.setAttribute("aria-label",n.placeholder),a.rows=1,v(a,{flex:"1",resize:"none",boxSizing:"border-box",padding:"10px 12px",border:`1px solid ${L}`,borderRadius:"12px",fontSize:"16px",fontFamily:Re,lineHeight:"1.4",maxHeight:"110px",overflowY:"hidden"});const C=()=>{a.style.height="auto";const c=Math.min(a.scrollHeight+2,110);a.style.height=`${c}px`,a.style.overflowY=a.scrollHeight+2>110?"auto":"hidden"};a.addEventListener("input",()=>{C(),A()});const m='<svg width="18" height="18" viewBox="0 -960 960 960" fill="currentColor" aria-hidden="true"><path d="M440-160v-487L216-423l-56-57 320-320 320 320-56 57-224-224v487h-80Z"/></svg>',x='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true" style="animation: ago-spin 0.8s linear infinite"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>',p=document.createElement("button");p.type="submit",p.setAttribute("aria-label","Send"),p.innerHTML=m,v(p,{flexShrink:"0",width:"40px",height:"40px",padding:"0",border:"none",borderRadius:"50%",backgroundColor:Ae,color:_e,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer"});let f=!1;const A=()=>{const s=a.value.trim()!==""||o.length>0,c=f||!s;p.disabled=c,p.innerHTML=f?x:m,p.style.opacity=c&&!f?"0.5":"1",p.style.cursor=c?"default":"pointer"};let R=null,_=null;n.allowFiles&&(R=document.createElement("input"),R.type="file",R.multiple=!0,v(R,{display:"none"}),_=document.createElement("button"),_.type="button",_.setAttribute("aria-label","Attach file"),_.textContent="📎",v(_,{padding:"10px 12px",border:`1px solid ${L}`,borderRadius:"12px",backgroundColor:ee,cursor:"pointer",fontSize:"14px"}),_.addEventListener("click",()=>R?.click()),R.addEventListener("change",()=>{o=[...o,...Array.from(R?.files??[])],Y()}));function Y(){r.replaceChildren(),o.forEach((s,c)=>{const y=h({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${L}`,borderRadius:"8px",fontSize:"12px"}),T=document.createElement("span");T.textContent=s.name;const k=document.createElement("button");k.type="button",k.setAttribute("aria-label",`Remove ${s.name}`),k.textContent="×",v(k,{border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),k.addEventListener("click",()=>{o=o.filter((j,V)=>V!==c),Y()}),y.append(T,k),r.appendChild(y)}),A()}const D=()=>{const s=a.value,c=o;return a.value="",C(),o=[],Y(),{content:s,files:c}},g=()=>{const{content:s,files:c}=D();(s.trim()||c.length>0)&&n.onSend(s.trim(),c.length>0?c:void 0)};return i.addEventListener("submit",s=>{s.preventDefault(),g()}),a.addEventListener("keydown",s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),g())}),_&&b.appendChild(_),b.append(a,p),R&&i.appendChild(R),i.append(r,b),A(),{inputRow:i,getValueAndClear:D,setDisabled:s=>{a.disabled=s,f=s,A()},focus:()=>a.focus()}}var Zt={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function ae(n){return n.replace(/[&<>"']/g,o=>Zt[o])}function gt(n){const o=n.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(o)||!/^[a-z][a-z0-9+.-]*:/i.test(o)?o:null}var vt='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',Se="";function te(n){const o=[],i=b=>(o.push(b),`${Se}${o.length-1}${Se}`);let r=n;return r=r.replace(/`([^`]+)`/g,(b,a)=>i(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${vt}">${ae(a)}</code>`)),r=r.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(b,a,C)=>{const m=gt(C);return m?i(`<img alt="${ae(a)}" src="${ae(m)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):b}),r=r.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(b,a,C)=>{const m=gt(C);return m?i(`<a href="${ae(m)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${te(a)}</a>`):b}),r=ae(r),r=r.replace(/\*\*([^*]+?)\*\*/g,"<strong>$1</strong>").replace(/__([^_]+?)__/g,"<strong>$1</strong>").replace(/~~([^~]+?)~~/g,"<del>$1</del>").replace(/(^|[^*])\*(?!\s)([^*]+?)\*/g,"$1<em>$2</em>").replace(/(^|[^\w_])_(?!\s)([^_]+?)_/g,"$1<em>$2</em>"),r=r.replace(new RegExp(`${Se}(\\d+)${Se}`,"g"),(b,a)=>o[Number(a)]),r}function B(n,o,i){const r=document.createElement(n);return Object.assign(r.style,o),i!==void 0&&(r.innerHTML=i),r}var yt=/^ {0,3}([-*_])( *\1){2,} *$/,wt=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,Ct=/^ {0,3}(```+|~~~+)/,ke=/^ {0,3}>\s?/,le=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,Jt=["20px","18px","16px","15px","14px","13px"],Fe=n=>n.match(/^\s*/)?.[0].length??0;function en(n){return n.trim()===""||yt.test(n)||wt.test(n)||Ct.test(n)||ke.test(n)||le.test(n)}function Et(n){const o=n[0].match(le),i=o[1].length,r=/\d/.test(o[2]),b=B(r?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:r?"decimal":"disc",listStylePosition:"outside"});let a=0;for(;a<n.length;){const C=n[a].match(le),m=[];for(a++;a<n.length&&Fe(n[a])>i;)m.push(n[a]),a++;const x=B("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),p=C[3].match(/^\[([ xX])\]\s+(.*)$/);p?(x.style.listStyleType="none",x.style.marginLeft="-20px",x.innerHTML=`<span style="margin-right:6px">${p[1].toLowerCase()==="x"?"☑":"☐"}</span>${te(p[2])}`):x.innerHTML=te(C[3]),m.filter(f=>le.test(f)).length>0&&x.appendChild(Et(m.filter(f=>f.trim()!==""))),b.appendChild(x)}return b}function tn(n){const o=m=>m.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(x=>x.trim()),i=B("div",{overflowX:"auto",margin:"0 0 8px 0"}),r=B("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),b=document.createElement("thead"),a=document.createElement("tr");for(const m of o(n[0]))a.appendChild(B("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},te(m)));b.appendChild(a),r.appendChild(b);const C=document.createElement("tbody");for(const m of n.slice(2)){const x=document.createElement("tr");for(const p of o(m))x.appendChild(B("td",{border:"1px solid #dee3e8",padding:"6px 10px"},te(p)));C.appendChild(x)}return r.appendChild(C),i.appendChild(r),i}var nn=n=>!!n&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(n);function Ie(n){const o=document.createDocumentFragment(),i=n.replace(/\r\n?/g,`
2
2
  `).split(`
3
- `);let r=0;for(;r<i.length;){const a=i[r];if(a.trim()===""){r++;continue}const C=a.match(wt);if(C){const p=C[1][0],f=[];for(r++;r<i.length&&!new RegExp(`^ {0,3}${p==="`"?"`{3,}":"~{3,}"}\\s*$`).test(i[r]);)f.push(i[r]),r++;r++;const A=O("pre",{margin:"0 0 8px 0"});A.appendChild(O("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:bt,whiteSpace:"pre"},ie(f.join(`
4
- `)))),o.appendChild(A);continue}if(vt.test(a)){o.appendChild(O("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),r++;continue}const m=a.match(yt);if(m){const p=m[1].length;o.appendChild(O(`h${p}`,{margin:"16px 0 8px 0",fontSize:Jt[p-1],fontWeight:"600",lineHeight:"1.3"},te(m[2]))),r++;continue}if(Re.test(a)){const p=[];for(;r<i.length&&Re.test(i[r]);)p.push(i[r].replace(Re,"")),r++;const f=O("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});f.appendChild(_e(p.join(`
5
- `))),o.appendChild(f);continue}if(a.includes("|")&&nn(i[r+1])){const p=[a,i[r+1]];for(r+=2;r<i.length&&i[r].includes("|")&&i[r].trim();)p.push(i[r]),r++;o.appendChild(tn(p));continue}if(se.test(a)){const p=[],f=ze(a);for(;r<i.length&&i[r].trim()!=="";)if(se.test(i[r])||ze(i[r])>f)p.push(i[r]),r++;else break;o.appendChild(Ct(p));continue}const x=[a];for(r++;r<i.length&&!en(i[r]);)x.push(i[r]),r++;o.appendChild(O("p",{margin:"0 0 8px 0",lineHeight:"1.6"},x.map(p=>te(p)).join("<br>")))}const b=o.lastElementChild;return b&&(b.style.marginBottom="0"),o}function on(n,o){const{isLast:i,isLastOfBlock:r,bubbleStyle:b,showAgentName:a,agentBubble:C,followUpEnabled:m,followUpHandler:x,isMobile:p}=o,f=n.role==="user",A=b==="imessage",R=h({display:"flex",flexDirection:"column",alignItems:f?"flex-end":"flex-start",marginBottom:A&&!r?"2px":"16px"});if(R.className=`ago-message ago-message--${n.role}`,!f&&a&&n.agent){const g=h({fontSize:"13px",fontWeight:"500",color:J,marginBottom:"6px",padding:"0 4px"});g.className="ago-message__agent",g.textContent=n.agent.displayName||n.agent.name,R.appendChild(g)}if(!f&&n.sources&&n.sources.length>0){const g=h({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});g.className="ago-message__sources",n.sources.forEach((s,c)=>{const y=s.url?document.createElement("a"):document.createElement("div");s.url&&y instanceof HTMLAnchorElement&&(y.href=s.url,y.target="_blank",y.rel="noopener noreferrer"),v(y,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${L}`,borderRadius:"8px",backgroundColor:ee,textDecoration:"none",color:J,fontSize:"12px",overflow:"hidden"});const T=h({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${Be}`,color:Be,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});T.textContent=String(c+1);const k=h({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});k.textContent=s.title,k.title=s.title,y.append(T,k),g.appendChild(y)}),R.appendChild(g)}if(n.attachments&&n.attachments.length>0){const g=h({display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:f?"flex-end":"flex-start",maxWidth:"75%"});g.className="ago-message__attachments";for(const s of n.attachments){const c=ae.safeAttachmentUrl(s.url);if(ae.canInlineImage(s)&&c){const M=document.createElement("a");M.href=c,M.target="_blank",M.rel="noopener noreferrer",v(M,{display:"inline-block",textDecoration:"none"});const V=document.createElement("img");V.src=c,V.alt=s.name,V.loading="lazy",v(V,{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:`1px solid ${L}`,display:"block"}),M.appendChild(V),g.appendChild(M);continue}const y=c?document.createElement("a"):document.createElement("div");c&&y instanceof HTMLAnchorElement&&(y.href=c,y.target="_blank",y.rel="noopener noreferrer"),v(y,{display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:`1px solid ${L}`,backgroundColor:f?"rgba(255,255,255,0.12)":ee,color:f?Ae:J,fontSize:"13px",textDecoration:"none",maxWidth:"220px"});const T=document.createElement("span");T.textContent="📄",T.setAttribute("aria-hidden","true"),v(T,{fontSize:"16px",lineHeight:"1",flexShrink:"0"});const k=h({display:"flex",flexDirection:"column",minWidth:"0"}),G=h({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"});G.textContent=s.name,G.title=s.name,k.appendChild(G);const j=ae.formatFileSize(s.fileSize);if(j){const M=h({fontSize:"11px",color:xt});M.textContent=j,k.appendChild(M)}y.append(T,k),g.appendChild(y)}R.appendChild(g)}const _=f||C||A,Y=!!n.content||n.status==="IN_PROGRESS",B=h({maxWidth:_?A||f?p?"88%":"75%":p?"92%":"85%":"100%",padding:_?"10px 14px":"2px 8px",borderRadius:A?Kt:_?De:"0",backgroundColor:f?ke:_?ft:"transparent",color:f?Ae:J,overflowWrap:"break-word",textWrap:"pretty",fontSize:"16px",lineHeight:"1.6"});if(B.className="ago-message__content",A&&r){B.style.position="relative";const g=h({position:"absolute",zIndex:"0",bottom:"-2px",width:"20px",height:"20px",background:f?ke:ft});g.className="ago-message__tail";const s=h({position:"absolute",zIndex:"1",bottom:"-2px",width:"10px",height:"20px",background:ht});s.className="ago-message__tail-mask",f?(g.style.right="-8px",g.style.borderBottomLeftRadius="16px 14px",s.style.right="-10px",s.style.borderBottomLeftRadius="10px"):(g.style.left="-7px",g.style.borderBottomRightRadius="16px 14px",s.style.left="-10px",s.style.borderBottomRightRadius="10px"),B.append(g,s)}if(n.content?B.appendChild(_e(n.content)):n.status==="IN_PROGRESS"&&B.appendChild(an()),Y&&R.appendChild(B),i&&n.followUpReplies&&n.followUpReplies.length>0){const g=h({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});g.className="ago-message__followups";for(const s of n.followUpReplies){const c=document.createElement("button");c.type="button",c.className="ago-message__followup-btn",c.textContent=s,c.disabled=!m,v(c,{minHeight:"36px",padding:"6px 14px",fontSize:"14px",borderRadius:De,border:`1px solid ${L}`,backgroundColor:ee,color:J,cursor:m?"pointer":"default",transition:"border-color 0.15s"}),x&&c.addEventListener("click",()=>x(s)),c.addEventListener("mouseenter",()=>{c.style.borderColor=Be}),c.addEventListener("mouseleave",()=>{c.style.borderColor=L}),g.appendChild(c)}R.appendChild(g)}return R}function rn(n){const o=h({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:De,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});o.className="ago-form-notice",o.setAttribute("role","status");const i=document.createElement("span");i.textContent="✓",i.setAttribute("aria-hidden","true"),v(i,{fontWeight:"700"});const r=document.createElement("span");return r.textContent=n,o.append(i,r),o}function an(){const n=h({display:"flex",gap:"4px",padding:"4px 0"});for(let o=0;o<3;o++){const i=h({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${o*.2}s`});n.appendChild(i)}return n}function sn(){const n="http://www.w3.org/2000/svg",o=document.createElementNS(n,"svg");o.setAttribute("width","26"),o.setAttribute("height","26"),o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("fill","none");const i=document.createElementNS(n,"path");return i.setAttribute("d","M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"),i.setAttribute("stroke","currentColor"),i.setAttribute("stroke-width","2"),i.setAttribute("stroke-linecap","round"),i.setAttribute("stroke-linejoin","round"),o.appendChild(i),o}var gt="Form submitted.";function ln(n){if(typeof n=="string")return n||null;if(!n||typeof n!="object")return null;const o=n;if(typeof o.message=="string"&&o.message)return o.message;const i=o.result;if(typeof i=="string"&&i)return i;if(i&&typeof i=="object"){const r=i.message;if(typeof r=="string"&&r)return r}return null}var dn=0;function cn(n){const o=typeof n=="string"?document.querySelector(n):n;if(!o)throw new Error(`mountChatWidget: target "${String(n)}" not found.`);return o}function pn(n,o){const{title:i="Chat",welcomeMessage:r="Hello! How can I help you today?",placeholder:b="Type a message...",allowFiles:a=!1,height:C=500,placement:m="inline",width:x=400,defaultOpen:p=!1,logoUrl:f,showAgentName:A=!1,agentBubble:R=!1,bubbleStyle:_="default",showHeader:Y=!0,theme:B,loadThreads:g=!1,forms:s,formSubmittedMessage:c=gt,onFollowUpClick:y,onMessageSent:T,onMessageReceived:k,onFormSubmitted:G,onFormError:j,onOpen:M,onClose:V}=o,ne=typeof r=="string"?{message:r,mode:"static"}:r,Fe=ne.message,He=ne.mode??"static",Et="speed"in ne&&ne.speed||45,Pe="followUpReplies"in ne&&ne.followUpReplies||void 0;if(!o.client&&!o.config?.baseUrl)throw new ae.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const E=o.client??new ae.AgoClient(o.config),Ue=cn(n),D=m==="left"||m==="right",St=D&&(o.launcher??!0);let oe=D?p:!0;const Rt=o.mobile?.breakpoint??768,kt=o.mobile?.trigger??"focus",We=typeof window<"u"&&!!window.matchMedia,z=We?window.matchMedia(`(max-width: ${Rt}px)`):void 0,At=We?window.matchMedia("(prefers-reduced-motion: reduce)"):void 0,le=!D&&!!z,Ie=o.persistConversation,me=Ie?Gt.createConversationSession(Ie===!0?{}:Ie):void 0;let P=o.conversationId??me?.getLastActiveThread()??void 0,u=[],Z=!1,de=null,q;const Ge=[];function _t(e){if(typeof c=="function"){const l=c(e);if(typeof l=="string"&&l)return l}const t=ln(e);return t||(typeof c=="string"?c:gt)}const ge=[],d=h({display:"flex",flexDirection:"column",height:D?"100%":typeof C=="number"?`${C}px`:C,border:`1px solid ${L}`,borderRadius:qt,overflow:"hidden",backgroundColor:ee,fontFamily:Se,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});d.className="ago-chat-widget",Xt(d,B);let F;if(Y){if(F=h({padding:"14px 16px",borderBottom:`1px solid ${L}`,backgroundColor:Vt,color:pt,display:"flex",alignItems:"center",gap:"10px"}),F.className="ago-chat-widget__header",f){const t=document.createElement("img");t.src=f,t.alt="Logo",v(t,{height:"24px",width:"auto"}),F.appendChild(t)}const e=document.createElement("h3");if(e.textContent=i,v(e,{margin:"0",fontSize:"15px",fontWeight:"600"}),F.appendChild(e),D){const t=document.createElement("button");t.type="button",t.className="ago-chat-widget__close",t.setAttribute("aria-label","Close"),t.textContent="×",v(t,{marginLeft:"auto",background:"transparent",border:"none",color:pt,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),t.addEventListener("click",()=>Oe()),F.appendChild(t)}}const I=h({flex:"1",overflow:"auto",padding:"16px",backgroundColor:ht});I.className="ago-chat-widget__messages",I.setAttribute("role","log"),I.setAttribute("aria-live","polite"),I.setAttribute("aria-relevant","additions text"),I.setAttribute("aria-atomic","false");const{inputRow:$e,setDisabled:It,focus:he}=Yt({placeholder:b,allowFiles:a,onSend:(e,t)=>{Ne(e,t)}});Qt(),d.append(...F?[F]:[],I,$e);let xe=d,U,N;const be=m==="left"?"left":"right";if(D&&(U=h({position:"fixed",top:"0",bottom:"0",[be]:"0",width:typeof x=="number"?`${x}px`:x,maxWidth:"100vw",display:"flex",zIndex:"2147483000",transition:"transform 0.3s ease",boxShadow:"rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"}),U.className="ago-chat-widget-panel",v(d,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[be==="left"?"borderRight":"borderLeft"]:`1px solid ${L}`}),U.appendChild(d),xe=U),St){if(N=document.createElement("button"),N.type="button",N.className="ago-chat-widget-launcher",N.setAttribute("aria-label",`Open ${i}`),v(N,{position:"fixed",bottom:"20px",[be]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:ke,color:Ae,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:Se}),f){const e=document.createElement("img");e.src=f,e.alt="",v(e,{width:"26px",height:"26px",objectFit:"contain"}),N.appendChild(e)}else N.appendChild(sn());N.addEventListener("click",()=>Me())}const ce=le?`ago-vt-${++dn}`:"",je=52;let K=!1,pe=0,re=0,H,fe,X;const ve={height:d.style.height,border:d.style.border,borderRadius:d.style.borderRadius,boxShadow:d.style.boxShadow};Ue.appendChild(xe),N&&Ue.appendChild(N),ye(),le&&(H=Pt(),d.insertBefore(H,d.firstChild),fe=document.createElement("style"),fe.id=ce,fe.textContent=`::view-transition-group(${ce}),::view-transition-group(${ce}-bar){animation-duration:0.3s;animation-timing-function:cubic-bezier(0.4,0,0.2,1)}`,document.head.appendChild(fe),kt==="focus"&&(d.addEventListener("pointerdown",e=>{K||!z?.matches||$e.contains(e.target)&&(e.preventDefault(),Ce())},!0),d.addEventListener("focusin",e=>{z?.matches&&$e.contains(e.target)&&Ce()})),document.addEventListener("keydown",tt)),z&&z.addEventListener("change",nt);const $t=y!==!1,Lt=y===!1?void 0:y??(e=>{Ne(e)});function $(){if(I.replaceChildren(),u.length===0){if(He==="static"){const t=h({textAlign:"center",color:xt,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});t.appendChild(_e(Fe)),I.appendChild(t)}}else u.forEach((t,l)=>{const S=l===u.length-1||u[l+1].role!==t.role;I.appendChild(on(t,{isLast:l===u.length-1,isLastOfBlock:S,bubbleStyle:_,showAgentName:A,agentBubble:R,followUpEnabled:$t,followUpHandler:Lt,isMobile:!!z?.matches}))});for(const t of Ge)I.appendChild(rn(t));if(de){const t=h({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});t.setAttribute("role","alert"),t.textContent=de,I.appendChild(t)}I.scrollTop=I.scrollHeight;const e=u[u.length-1];It(Z&&e?.role==="assistant"&&e.status==="IN_PROGRESS")}function Nt(){for(let e=u.length-1;e>=0;e--){const t=u[e];if(t.role==="assistant"&&t.status==="IN_PROGRESS")return t}}const Ve=e=>{P||(P=e.conversationId)},qe=e=>{const t=Nt();t&&(t.content+=e.content,$())},Ke=e=>{const t=u.findIndex(l=>l.id===e.id||l.role==="assistant"&&l.status==="IN_PROGRESS");t>=0?u[t]=e:u.push(e),$(),he()},Xe=e=>{const t=u.findIndex(l=>l.id===e.id||l.role==="assistant"&&l.status==="IN_PROGRESS");t>=0?u[t]=e:u.push(e),Z=!1,$(),e.status==="DONE"&&k?.({id:e.id,content:e.content})},Qe=e=>{de=e.error,Z=!1,u=u.filter(t=>!t.id.startsWith("temp-")),$()};function Tt(e){const t={id:`ago-intro-${Date.now()}`,conversationId:"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};u.push(t),$();const l=e.match(/\S+\s*/g)??[e];let S=0;q=setInterval(()=>{if(S>=l.length){clearInterval(q),q=void 0,t.status="DONE",Pe&&(t.followUpReplies=Pe),$();return}t.content+=l[S],S++,$()},Et)}E.on("message:start",Ve),E.on("message:chunk",qe),E.on("message:answer-complete",Ke),E.on("message:complete",Xe),E.on("message:error",Qe);const Ye=e=>G?.(e),Ze=e=>j?.(e);G&&E.on("form:submitted",Ye),j&&E.on("form:error",Ze);const Le=[];let Je=!1;const et=e=>{if(Je)return;Le.push(e.install(E));let t=e.store.get().submitted;const l=e.store.subscribe(S=>{S.submitted&&!t&&(Ge.push(_t(S.submitResult)),$()),t=S.submitted});Le.push(l)};for(const e of s??[])e.schema!=null?et(dt.createFormCollector(e)):dt.loadFormCollector(E,e).then(t=>et(t)).catch(()=>{});async function Ne(e,t){const l=e.trim();if(!l&&!t?.length||Z)return;if(T?.(l),Z=!0,de=null,q){clearInterval(q),q=void 0;const w=u.find(W=>W.id.startsWith("ago-intro-"));w&&!w.content?u=u.filter(W=>W!==w):w&&(w.status="DONE")}const S=Date.now();u.push({id:`temp-user-${S}`,conversationId:P||"",content:l,role:"user",status:"DONE",attachments:t&&t.length>0?ae.attachmentsFromFiles(t):void 0,createdAt:new Date}),u.push({id:`temp-assistant-${S}`,conversationId:P||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),$();try{const w=await E.sendMessage(l,{conversationId:P,files:t});w.conversationId&&(P||(P=w.conversationId),me?.setActiveThread(w.conversationId,w.createdAt));const W=u.find(Q=>Q.id===`temp-user-${S}`);if(W&&(W.id=`user-${S}`,W.conversationId=w.conversationId),!u.some(Q=>Q.id===w.id)){const Q=u.findIndex(Wt=>Wt.id===`temp-assistant-${S}`);Q>=0?u[Q]=w:u.push(w)}u=u.filter(Q=>!Q.id.startsWith("temp-")),Z=!1,$(),g&&Te()}catch(w){de=w instanceof Error?w.message:"Failed to send message",Z=!1,u=u.filter(W=>!W.id.startsWith("temp-")),$()}}async function Te(){try{const e=await E.getConversations();ge.splice(0,ge.length,...e)}catch{}return ge}async function Mt(e){try{const t=(await E.getConversation(e))?.messages??[];t.length>0&&u.length===0&&(u=t,$())}catch{u.length===0&&(me?.clear(),P=void 0)}}return $(),le&&z?.matches||he(),P?Mt(P):He==="streaming"&&Tt(Fe),g&&Te(),{client:E,element:xe,sendMessage:Ne,...D||le?{open:Bt,close:Dt,toggle:zt}:{},session:me,threads:ge,refreshThreads:Te,destroy(){q&&clearInterval(q),E.off("message:start",Ve),E.off("message:chunk",qe),E.off("message:answer-complete",Ke),E.off("message:complete",Xe),E.off("message:error",Qe),G&&E.off("form:submitted",Ye),j&&E.off("form:error",Ze),Je=!0,Le.forEach(e=>e()),xe.remove(),N?.remove(),H?.remove(),fe?.remove(),X?.remove(),z?.removeEventListener("change",nt),le&&(document.removeEventListener("keydown",tt),it(),document.documentElement.style.removeProperty("overflow")),o.client||E.destroy()}};function ye(){if(!U)return;{const t=be==="left"?"border-right":"border-left";z?.matches?(U.style.width="100%",d.style.borderRadius="0",d.style.removeProperty(t)):(U.style.width=typeof x=="number"?`${x}px`:x,d.style.setProperty(t,`1px solid ${L}`))}const e=m==="left"?"translateX(-100%)":"translateX(100%)";U.style.transform=oe?"translateX(0)":e,U.setAttribute("aria-hidden",oe?"false":"true"),N&&(N.style.display=oe?"none":"flex")}function Me(){oe=!0,ye(),he(),M?.()}function Oe(){oe=!1,ye(),V?.()}function Ot(){oe?Oe():Me()}function Bt(){D?Me():Ce()}function Dt(){D?Oe():ue()}function zt(){D?Ot():K?ue():Ce()}function Ft(){return Array.from(d.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter(e=>e.getClientRects().length>0)}function tt(e){if(!K)return;if(e.key==="Escape"){ue();return}if(e.key!=="Tab")return;const t=Ft();if(t.length===0){e.preventDefault();return}const l=t[0],S=t[t.length-1],w=document.activeElement;e.shiftKey&&(w===l||!d.contains(w))?(e.preventDefault(),S.focus()):!e.shiftKey&&(w===S||!d.contains(w))&&(e.preventDefault(),l.focus())}function nt(e){D?ye():!e.matches&&K&&ue(),$()}function ot(){return window.visualViewport?.height??window.innerHeight}function rt(){const e=window.visualViewport,t=e?.offsetTop??0,l=e?.height??pe,S=Math.min(0,t+l-pe);d.style.top=`${S}px`,H&&(H.style.top=`${t}px`)}function we(){re||(re=requestAnimationFrame(()=>{re=0,rt()}))}function Ht(){window.visualViewport?.addEventListener("resize",we),window.visualViewport?.addEventListener("scroll",we)}function it(){window.visualViewport?.removeEventListener("resize",we),window.visualViewport?.removeEventListener("scroll",we),re&&(cancelAnimationFrame(re),re=0)}function at(){I.scrollTop=I.scrollHeight}function Pt(){const e=h({position:"fixed",top:"0",left:"0",right:"0",height:`calc(${je}px + env(safe-area-inset-top))`,display:"none",alignItems:"center",justifyContent:"space-between",padding:"env(safe-area-inset-top) 14px 0",backgroundColor:ee,borderBottom:`1px solid ${L}`,zIndex:"2147483001",fontFamily:Se});if(e.className="ago-chat-widget-mobile-bar",f){const l=document.createElement("img");l.src=f,l.alt="",v(l,{height:"28px",width:"auto"}),e.appendChild(l)}else if(i){const l=document.createElement("span");l.textContent=i,v(l,{fontSize:"15px",fontWeight:"600",color:J,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"}),e.appendChild(l)}else e.appendChild(h({}));const t=document.createElement("button");return t.type="button",t.setAttribute("aria-label","Close"),t.textContent="×",v(t,{border:"none",background:"transparent",fontSize:"26px",lineHeight:"1",color:J,cursor:"pointer",padding:"4px 8px"}),t.addEventListener("click",()=>{ue()}),e.appendChild(t),e}function Ut(){return typeof document.startViewTransition=="function"&&!At?.matches&&!!z?.matches}function st(e){const t=document;if(Ut()&&t.startViewTransition){d.style.setProperty("view-transition-name",ce),H?.style.setProperty("view-transition-name",`${ce}-bar`);const l=()=>{d.style.removeProperty("view-transition-name"),H?.style.removeProperty("view-transition-name")};return t.startViewTransition(e).finished.then(l,l)}return e(),Promise.resolve()}function lt(e){if(e)X&&d.parentElement?.insertBefore(X,d),v(d,{position:"fixed",top:"0",left:"0",right:"0",bottom:"0",height:"var(--ago-vh, 100dvh)",zIndex:"2147483000",border:"none",borderRadius:"0",boxShadow:"none",paddingTop:`calc(${je}px + env(safe-area-inset-top))`,paddingBottom:"env(safe-area-inset-bottom)"}),d.setAttribute("role","dialog"),d.setAttribute("aria-modal","true"),d.setAttribute("aria-label",i),document.documentElement.style.overflow="hidden",F&&(F.style.display="none"),H&&(H.style.display="flex");else{X?.remove(),X=void 0;for(const t of["position","top","left","right","bottom","z-index","padding-top","padding-bottom"])d.style.removeProperty(t);d.style.height=ve.height,d.style.border=ve.border,d.style.borderRadius=ve.borderRadius,d.style.boxShadow=ve.boxShadow,d.removeAttribute("role"),d.removeAttribute("aria-modal"),d.removeAttribute("aria-label"),document.documentElement.style.removeProperty("overflow"),F&&(F.style.display="flex"),H&&(H.style.display="none")}}function Ce(){if(K||!z?.matches)return Promise.resolve();const e=d.getBoundingClientRect();if(e.height>=ot()*.8)return Promise.resolve();K=!0,X=h({width:`${e.width}px`,height:`${e.height}px`}),X.className="ago-chat-widget-spacer",X.setAttribute("aria-hidden","true"),pe=ot(),d.style.setProperty("--ago-vh",`${pe}px`),rt(),Ht();const t=st(()=>lt(!0));return t.then(()=>{at(),he()}),at(),M?.(),t}function ue(){if(!K)return Promise.resolve();K=!1,it(),d.querySelector("textarea")?.blur();const e=st(()=>lt(!1));return e.then(()=>d.style.removeProperty("--ago-vh")),pe=0,V?.(),e}}exports.mountChatWidget=pn;exports.renderMarkdown=_e;
3
+ `);let r=0;for(;r<i.length;){const a=i[r];if(a.trim()===""){r++;continue}const C=a.match(Ct);if(C){const p=C[1][0],f=[];for(r++;r<i.length&&!new RegExp(`^ {0,3}${p==="`"?"`{3,}":"~{3,}"}\\s*$`).test(i[r]);)f.push(i[r]),r++;r++;const A=B("pre",{margin:"0 0 8px 0"});A.appendChild(B("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:vt,whiteSpace:"pre"},ae(f.join(`
4
+ `)))),o.appendChild(A);continue}if(yt.test(a)){o.appendChild(B("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),r++;continue}const m=a.match(wt);if(m){const p=m[1].length;o.appendChild(B(`h${p}`,{margin:"16px 0 8px 0",fontSize:Jt[p-1],fontWeight:"600",lineHeight:"1.3"},te(m[2]))),r++;continue}if(ke.test(a)){const p=[];for(;r<i.length&&ke.test(i[r]);)p.push(i[r].replace(ke,"")),r++;const f=B("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});f.appendChild(Ie(p.join(`
5
+ `))),o.appendChild(f);continue}if(a.includes("|")&&nn(i[r+1])){const p=[a,i[r+1]];for(r+=2;r<i.length&&i[r].includes("|")&&i[r].trim();)p.push(i[r]),r++;o.appendChild(tn(p));continue}if(le.test(a)){const p=[],f=Fe(a);for(;r<i.length&&i[r].trim()!=="";)if(le.test(i[r])||Fe(i[r])>f)p.push(i[r]),r++;else break;o.appendChild(Et(p));continue}const x=[a];for(r++;r<i.length&&!en(i[r]);)x.push(i[r]),r++;o.appendChild(B("p",{margin:"0 0 8px 0",lineHeight:"1.6"},x.map(p=>te(p)).join("<br>")))}const b=o.lastElementChild;return b&&(b.style.marginBottom="0"),o}function on(n,o){const{isLast:i,isLastOfBlock:r,bubbleStyle:b,showAgentName:a,agentBubble:C,followUpEnabled:m,followUpHandler:x,isMobile:p}=o,f=n.role==="user",A=b==="imessage",R=h({display:"flex",flexDirection:"column",alignItems:f?"flex-end":"flex-start",marginBottom:A&&!r?"2px":"16px"});if(R.className=`ago-message ago-message--${n.role}`,!f&&a&&n.agent){const g=h({fontSize:"13px",fontWeight:"500",color:J,marginBottom:"6px",padding:"0 4px"});g.className="ago-message__agent",g.textContent=n.agent.displayName||n.agent.name,R.appendChild(g)}if(!f&&n.sources&&n.sources.length>0){const g=h({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});g.className="ago-message__sources",n.sources.forEach((s,c)=>{const y=s.url?document.createElement("a"):document.createElement("div");s.url&&y instanceof HTMLAnchorElement&&(y.href=s.url,y.target="_blank",y.rel="noopener noreferrer"),v(y,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${L}`,borderRadius:"8px",backgroundColor:ee,textDecoration:"none",color:J,fontSize:"12px",overflow:"hidden"});const T=h({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${De}`,color:De,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});T.textContent=String(c+1);const k=h({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});k.textContent=s.title,k.title=s.title,y.append(T,k),g.appendChild(y)}),R.appendChild(g)}if(n.attachments&&n.attachments.length>0){const g=h({display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:f?"flex-end":"flex-start",maxWidth:"75%"});g.className="ago-message__attachments";for(const s of n.attachments){const c=se.safeAttachmentUrl(s.url);if(se.canInlineImage(s)&&c){const M=document.createElement("a");M.href=c,M.target="_blank",M.rel="noopener noreferrer",v(M,{display:"inline-block",textDecoration:"none"});const q=document.createElement("img");q.src=c,q.alt=s.name,q.loading="lazy",v(q,{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:`1px solid ${L}`,display:"block"}),M.appendChild(q),g.appendChild(M);continue}const y=c?document.createElement("a"):document.createElement("div");c&&y instanceof HTMLAnchorElement&&(y.href=c,y.target="_blank",y.rel="noopener noreferrer"),v(y,{display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:`1px solid ${L}`,backgroundColor:f?"rgba(255,255,255,0.12)":ee,color:f?_e:J,fontSize:"13px",textDecoration:"none",maxWidth:"220px"});const T=document.createElement("span");T.textContent="📄",T.setAttribute("aria-hidden","true"),v(T,{fontSize:"16px",lineHeight:"1",flexShrink:"0"});const k=h({display:"flex",flexDirection:"column",minWidth:"0"}),j=h({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"});j.textContent=s.name,j.title=s.name,k.appendChild(j);const V=se.formatFileSize(s.fileSize);if(V){const M=h({fontSize:"11px",color:bt});M.textContent=V,k.appendChild(M)}y.append(T,k),g.appendChild(y)}R.appendChild(g)}const _=f||C||A,Y=!!n.content||n.status==="IN_PROGRESS",D=h({maxWidth:_?A||f?p?"88%":"75%":p?"92%":"85%":"100%",padding:_?"10px 14px":"2px 8px",borderRadius:A?Kt:_?ze:"0",backgroundColor:f?Ae:_?ut:"transparent",color:f?_e:J,overflowWrap:"break-word",textWrap:"pretty",fontSize:"16px",lineHeight:"1.6"});if(D.className="ago-message__content",A&&r){D.style.position="relative";const g=h({position:"absolute",zIndex:"0",bottom:"-2px",width:"20px",height:"20px",background:f?Ae:ut});g.className="ago-message__tail";const s=h({position:"absolute",zIndex:"1",bottom:"-2px",width:"10px",height:"20px",background:xt});s.className="ago-message__tail-mask",f?(g.style.right="-8px",g.style.borderBottomLeftRadius="16px 14px",s.style.right="-10px",s.style.borderBottomLeftRadius="10px"):(g.style.left="-7px",g.style.borderBottomRightRadius="16px 14px",s.style.left="-10px",s.style.borderBottomRightRadius="10px"),D.append(g,s)}if(n.content?D.appendChild(Ie(n.content)):n.status==="IN_PROGRESS"&&D.appendChild(an()),Y&&R.appendChild(D),i&&n.followUpReplies&&n.followUpReplies.length>0){const g=h({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});g.className="ago-message__followups";for(const s of n.followUpReplies){const c=document.createElement("button");c.type="button",c.className="ago-message__followup-btn",c.textContent=s,c.disabled=!m,v(c,{minHeight:"36px",padding:"6px 14px",fontSize:"14px",borderRadius:ze,border:`1px solid ${L}`,backgroundColor:ee,color:J,cursor:m?"pointer":"default",transition:"border-color 0.15s"}),x&&c.addEventListener("click",()=>x(s)),c.addEventListener("mouseenter",()=>{c.style.borderColor=De}),c.addEventListener("mouseleave",()=>{c.style.borderColor=L}),g.appendChild(c)}R.appendChild(g)}return R}function rn(n){const o=h({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:ze,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});o.className="ago-form-notice",o.setAttribute("role","status");const i=document.createElement("span");i.textContent="✓",i.setAttribute("aria-hidden","true"),v(i,{fontWeight:"700"});const r=document.createElement("span");return r.textContent=n,o.append(i,r),o}function an(){const n=h({display:"flex",gap:"4px",padding:"4px 0"});for(let o=0;o<3;o++){const i=h({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"#b5bfc8",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${o*.2}s`});n.appendChild(i)}return n}function sn(){const n="http://www.w3.org/2000/svg",o=document.createElementNS(n,"svg");o.setAttribute("width","26"),o.setAttribute("height","26"),o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("fill","none");const i=document.createElementNS(n,"path");return i.setAttribute("d","M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"),i.setAttribute("stroke","currentColor"),i.setAttribute("stroke-width","2"),i.setAttribute("stroke-linecap","round"),i.setAttribute("stroke-linejoin","round"),o.appendChild(i),o}var ht="Form submitted.";function ln(n){if(typeof n=="string")return n||null;if(!n||typeof n!="object")return null;const o=n;if(typeof o.message=="string"&&o.message)return o.message;const i=o.result;if(typeof i=="string"&&i)return i;if(i&&typeof i=="object"){const r=i.message;if(typeof r=="string"&&r)return r}return null}var dn=0;function cn(n){const o=typeof n=="string"?document.querySelector(n):n;if(!o)throw new Error(`mountChatWidget: target "${String(n)}" not found.`);return o}function pn(n,o){const{title:i="Chat",welcomeMessage:r="Hello! How can I help you today?",placeholder:b="Type a message...",allowFiles:a=!1,height:C=500,placement:m="inline",width:x=400,defaultOpen:p=!1,logoUrl:f,showAgentName:A=!1,agentBubble:R=!1,bubbleStyle:_="default",showHeader:Y=!0,theme:D,loadThreads:g=!1,forms:s,formSubmittedMessage:c=ht,onFollowUpClick:y,onMessageSent:T,onMessageReceived:k,onFormSubmitted:j,onFormError:V,onOpen:M,onClose:q}=o,ne=typeof r=="string"?{message:r,mode:"static"}:r,He=ne.message,Pe=ne.mode??"static",St="speed"in ne&&ne.speed||45,Ue="followUpReplies"in ne&&ne.followUpReplies||void 0;if(!o.client&&!o.config?.baseUrl)throw new se.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const E=o.client??new se.AgoClient(o.config),We=cn(n),z=m==="left"||m==="right",Rt=z&&(o.launcher??!0);let oe=z?p:!0;const kt=o.mobile?.breakpoint??768,$e=o.mobile?.trigger??"tap",Ge=typeof window<"u"&&!!window.matchMedia,O=Ge?window.matchMedia(`(max-width: ${kt}px)`):void 0,At=Ge?window.matchMedia("(prefers-reduced-motion: reduce)"):void 0,re=!z&&!!O,Le=o.persistConversation,ge=Le?Gt.createConversationSession(Le===!0?{}:Le):void 0;let P=o.conversationId??ge?.getLastActiveThread()??void 0,u=[],Z=!1,de=null,K;const je=[];function _t(e){if(typeof c=="function"){const l=c(e);if(typeof l=="string"&&l)return l}const t=ln(e);return t||(typeof c=="string"?c:ht)}const he=[],d=h({display:"flex",flexDirection:"column",height:z?"100%":typeof C=="number"?`${C}px`:C,border:`1px solid ${L}`,borderRadius:qt,overflow:"hidden",backgroundColor:ee,fontFamily:Re,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});d.className="ago-chat-widget",Xt(d,D);let F;if(Y){if(F=h({padding:"14px 16px",borderBottom:`1px solid ${L}`,backgroundColor:Vt,color:ft,display:"flex",alignItems:"center",gap:"10px"}),F.className="ago-chat-widget__header",f){const t=document.createElement("img");t.src=f,t.alt="Logo",v(t,{height:"24px",width:"auto"}),F.appendChild(t)}const e=document.createElement("h3");if(e.textContent=i,v(e,{margin:"0",fontSize:"15px",fontWeight:"600"}),F.appendChild(e),z){const t=document.createElement("button");t.type="button",t.className="ago-chat-widget__close",t.setAttribute("aria-label","Close"),t.textContent="×",v(t,{marginLeft:"auto",background:"transparent",border:"none",color:ft,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0 2px"}),t.addEventListener("click",()=>Be()),F.appendChild(t)}}const I=h({flex:"1",overflow:"auto",padding:"16px",backgroundColor:xt});I.className="ago-chat-widget__messages",I.setAttribute("role","log"),I.setAttribute("aria-live","polite"),I.setAttribute("aria-relevant","additions text"),I.setAttribute("aria-atomic","false");const{inputRow:Ne,setDisabled:It,focus:xe}=Yt({placeholder:b,allowFiles:a,onSend:(e,t)=>{we(e,t)}});Qt(),d.append(...F?[F]:[],I,Ne);let be=d,U,N;const ve=m==="left"?"left":"right";if(z&&(U=h({position:"fixed",top:"0",bottom:"0",[ve]:"0",width:typeof x=="number"?`${x}px`:x,maxWidth:"100vw",display:"flex",zIndex:"2147483000",transition:"transform 0.3s ease",boxShadow:"rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"}),U.className="ago-chat-widget-panel",v(d,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[ve==="left"?"borderRight":"borderLeft"]:`1px solid ${L}`}),U.appendChild(d),be=U),Rt){if(N=document.createElement("button"),N.type="button",N.className="ago-chat-widget-launcher",N.setAttribute("aria-label",`Open ${i}`),v(N,{position:"fixed",bottom:"20px",[ve]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:Ae,color:_e,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:Re}),f){const e=document.createElement("img");e.src=f,e.alt="",v(e,{width:"26px",height:"26px",objectFit:"contain"}),N.appendChild(e)}else N.appendChild(sn());N.addEventListener("click",()=>Oe())}const ce=re?`ago-vt-${++dn}`:"",Ve=52;let W=!1,pe=0,ie=0,H,fe,X;const ye={height:d.style.height,border:d.style.border,borderRadius:d.style.borderRadius,boxShadow:d.style.boxShadow};We.appendChild(be),N&&We.appendChild(N),Ce(),re&&(H=Pt(),d.insertBefore(H,d.firstChild),fe=document.createElement("style"),fe.id=ce,fe.textContent=`::view-transition-group(${ce}),::view-transition-group(${ce}-bar){animation-duration:0.3s;animation-timing-function:cubic-bezier(0.4,0,0.2,1)}`,document.head.appendChild(fe),($e==="focus"||$e==="tap")&&(d.addEventListener("pointerdown",e=>{if(W||!O?.matches)return;const t=Ne.contains(e.target);if($e==="tap"){if((e.target instanceof Element?e.target:null)?.closest("button,a[href],[role='button']"))return}else if(!t)return;t&&e.preventDefault(),ue()},!0),d.addEventListener("focusin",e=>{O?.matches&&Ne.contains(e.target)&&ue()})),document.addEventListener("keydown",nt)),O&&O.addEventListener("change",ot);const $t=y!==!1,Lt=y===!1?void 0:y??(e=>{re&&O?.matches&&!W?ue().then(()=>we(e)):we(e)});function $(){if(I.replaceChildren(),u.length===0){if(Pe==="static"){const t=h({textAlign:"center",color:bt,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});t.appendChild(Ie(He)),I.appendChild(t)}}else u.forEach((t,l)=>{const S=l===u.length-1||u[l+1].role!==t.role;I.appendChild(on(t,{isLast:l===u.length-1,isLastOfBlock:S,bubbleStyle:_,showAgentName:A,agentBubble:R,followUpEnabled:$t,followUpHandler:Lt,isMobile:!!O?.matches}))});for(const t of je)I.appendChild(rn(t));if(de){const t=h({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});t.setAttribute("role","alert"),t.textContent=de,I.appendChild(t)}I.scrollTop=I.scrollHeight;const e=u[u.length-1];It(Z&&e?.role==="assistant"&&e.status==="IN_PROGRESS")}function Nt(){for(let e=u.length-1;e>=0;e--){const t=u[e];if(t.role==="assistant"&&t.status==="IN_PROGRESS")return t}}const qe=e=>{P||(P=e.conversationId)},Ke=e=>{const t=Nt();t&&(t.content+=e.content,$())},Xe=e=>{const t=u.findIndex(l=>l.id===e.id||l.role==="assistant"&&l.status==="IN_PROGRESS");t>=0?u[t]=e:u.push(e),$(),xe()},Qe=e=>{const t=u.findIndex(l=>l.id===e.id||l.role==="assistant"&&l.status==="IN_PROGRESS");t>=0?u[t]=e:u.push(e),Z=!1,$(),e.status==="DONE"&&k?.({id:e.id,content:e.content})},Ye=e=>{de=e.error,Z=!1,u=u.filter(t=>!t.id.startsWith("temp-")),$()};function Tt(e){const t={id:`ago-intro-${Date.now()}`,conversationId:"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};u.push(t),$();const l=e.match(/\S+\s*/g)??[e];let S=0;K=setInterval(()=>{if(S>=l.length){clearInterval(K),K=void 0,t.status="DONE",Ue&&(t.followUpReplies=Ue),$();return}t.content+=l[S],S++,$()},St)}E.on("message:start",qe),E.on("message:chunk",Ke),E.on("message:answer-complete",Xe),E.on("message:complete",Qe),E.on("message:error",Ye);const Ze=e=>j?.(e),Je=e=>V?.(e);j&&E.on("form:submitted",Ze),V&&E.on("form:error",Je);const Te=[];let et=!1;const tt=e=>{if(et)return;Te.push(e.install(E));let t=e.store.get().submitted;const l=e.store.subscribe(S=>{S.submitted&&!t&&(je.push(_t(S.submitResult)),$()),t=S.submitted});Te.push(l)};for(const e of s??[])e.schema!=null?tt(ct.createFormCollector(e)):ct.loadFormCollector(E,e).then(t=>tt(t)).catch(()=>{});async function we(e,t){const l=e.trim();if(!l&&!t?.length||Z)return;if(T?.(l),Z=!0,de=null,K){clearInterval(K),K=void 0;const w=u.find(G=>G.id.startsWith("ago-intro-"));w&&!w.content?u=u.filter(G=>G!==w):w&&(w.status="DONE")}const S=Date.now();u.push({id:`temp-user-${S}`,conversationId:P||"",content:l,role:"user",status:"DONE",attachments:t&&t.length>0?se.attachmentsFromFiles(t):void 0,createdAt:new Date}),u.push({id:`temp-assistant-${S}`,conversationId:P||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),$();try{const w=await E.sendMessage(l,{conversationId:P,files:t});w.conversationId&&(P||(P=w.conversationId),ge?.setActiveThread(w.conversationId,w.createdAt));const G=u.find(Q=>Q.id===`temp-user-${S}`);if(G&&(G.id=`user-${S}`,G.conversationId=w.conversationId),!u.some(Q=>Q.id===w.id)){const Q=u.findIndex(Wt=>Wt.id===`temp-assistant-${S}`);Q>=0?u[Q]=w:u.push(w)}u=u.filter(Q=>!Q.id.startsWith("temp-")),Z=!1,$(),g&&Me()}catch(w){de=w instanceof Error?w.message:"Failed to send message",Z=!1,u=u.filter(G=>!G.id.startsWith("temp-")),$()}}async function Me(){try{const e=await E.getConversations();he.splice(0,he.length,...e)}catch{}return he}async function Mt(e){try{const t=(await E.getConversation(e))?.messages??[];t.length>0&&u.length===0&&(u=t,$())}catch{u.length===0&&(ge?.clear(),P=void 0)}}return $(),re&&O?.matches||xe(),P?Mt(P):Pe==="streaming"&&Tt(He),g&&Me(),{client:E,element:be,sendMessage:we,...z||re?{open:Bt,close:Dt,toggle:zt}:{},session:ge,threads:he,refreshThreads:Me,destroy(){K&&clearInterval(K),E.off("message:start",qe),E.off("message:chunk",Ke),E.off("message:answer-complete",Xe),E.off("message:complete",Qe),E.off("message:error",Ye),j&&E.off("form:submitted",Ze),V&&E.off("form:error",Je),et=!0,Te.forEach(e=>e()),be.remove(),N?.remove(),H?.remove(),fe?.remove(),X?.remove(),O?.removeEventListener("change",ot),re&&(document.removeEventListener("keydown",nt),at(),document.documentElement.style.removeProperty("overflow")),o.client||E.destroy()}};function Ce(){if(!U)return;{const t=ve==="left"?"border-right":"border-left";O?.matches?(U.style.width="100%",d.style.borderRadius="0",d.style.removeProperty(t)):(U.style.width=typeof x=="number"?`${x}px`:x,d.style.setProperty(t,`1px solid ${L}`))}const e=m==="left"?"translateX(-100%)":"translateX(100%)";U.style.transform=oe?"translateX(0)":e,U.setAttribute("aria-hidden",oe?"false":"true"),N&&(N.style.display=oe?"none":"flex")}function Oe(){oe=!0,Ce(),xe(),M?.()}function Be(){oe=!1,Ce(),q?.()}function Ot(){oe?Be():Oe()}function Bt(){z?Oe():ue()}function Dt(){z?Be():me()}function zt(){z?Ot():W?me():ue()}function Ft(){return Array.from(d.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter(e=>e.getClientRects().length>0)}function nt(e){if(!W)return;if(e.key==="Escape"){me();return}if(e.key!=="Tab")return;const t=Ft();if(t.length===0){e.preventDefault();return}const l=t[0],S=t[t.length-1],w=document.activeElement;e.shiftKey&&(w===l||!d.contains(w))?(e.preventDefault(),S.focus()):!e.shiftKey&&(w===S||!d.contains(w))&&(e.preventDefault(),l.focus())}function ot(e){z?Ce():!e.matches&&W&&me(),$()}function rt(){return window.visualViewport?.height??window.innerHeight}function it(){const e=window.visualViewport,t=e?.offsetTop??0,l=e?.height??pe,S=Math.min(0,t+l-pe);d.style.top=`${S}px`,H&&(H.style.top=`${t}px`)}function Ee(){ie||(ie=requestAnimationFrame(()=>{ie=0,it()}))}function Ht(){window.visualViewport?.addEventListener("resize",Ee),window.visualViewport?.addEventListener("scroll",Ee)}function at(){window.visualViewport?.removeEventListener("resize",Ee),window.visualViewport?.removeEventListener("scroll",Ee),ie&&(cancelAnimationFrame(ie),ie=0)}function st(){I.scrollTop=I.scrollHeight}function Pt(){const e=h({position:"fixed",top:"0",left:"0",right:"0",height:`calc(${Ve}px + env(safe-area-inset-top))`,display:"none",alignItems:"center",justifyContent:"space-between",padding:"env(safe-area-inset-top) 14px 0",backgroundColor:ee,borderBottom:`1px solid ${L}`,zIndex:"2147483001",fontFamily:Re});if(e.className="ago-chat-widget-mobile-bar",f){const l=document.createElement("img");l.src=f,l.alt="",v(l,{height:"28px",width:"auto"}),e.appendChild(l)}else if(i){const l=document.createElement("span");l.textContent=i,v(l,{fontSize:"15px",fontWeight:"600",color:J,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"}),e.appendChild(l)}else e.appendChild(h({}));const t=document.createElement("button");return t.type="button",t.setAttribute("aria-label","Close"),t.textContent="×",v(t,{border:"none",background:"transparent",fontSize:"26px",lineHeight:"1",color:J,cursor:"pointer",padding:"4px 8px"}),t.addEventListener("click",()=>{me()}),e.appendChild(t),e}function Ut(){return typeof document.startViewTransition=="function"&&!At?.matches&&!!O?.matches}function lt(e){const t=document;if(Ut()&&t.startViewTransition){d.style.setProperty("view-transition-name",ce),H?.style.setProperty("view-transition-name",`${ce}-bar`);const l=()=>{d.style.removeProperty("view-transition-name"),H?.style.removeProperty("view-transition-name")};return t.startViewTransition(e).finished.then(l,l)}return e(),Promise.resolve()}function dt(e){if(e)X&&d.parentElement?.insertBefore(X,d),v(d,{position:"fixed",top:"0",left:"0",right:"0",bottom:"0",height:"var(--ago-vh, 100dvh)",zIndex:"2147483000",border:"none",borderRadius:"0",boxShadow:"none",paddingTop:`calc(${Ve}px + env(safe-area-inset-top))`,paddingBottom:"env(safe-area-inset-bottom)"}),d.setAttribute("role","dialog"),d.setAttribute("aria-modal","true"),d.setAttribute("aria-label",i),document.documentElement.style.overflow="hidden",F&&(F.style.display="none"),H&&(H.style.display="flex");else{X?.remove(),X=void 0;for(const t of["position","top","left","right","bottom","z-index","padding-top","padding-bottom"])d.style.removeProperty(t);d.style.height=ye.height,d.style.border=ye.border,d.style.borderRadius=ye.borderRadius,d.style.boxShadow=ye.boxShadow,d.removeAttribute("role"),d.removeAttribute("aria-modal"),d.removeAttribute("aria-label"),document.documentElement.style.removeProperty("overflow"),F&&(F.style.display="flex"),H&&(H.style.display="none")}}function ue(){if(W||!O?.matches)return Promise.resolve();const e=d.getBoundingClientRect();if(e.height>=rt()*.8)return Promise.resolve();W=!0,X=h({width:`${e.width}px`,height:`${e.height}px`}),X.className="ago-chat-widget-spacer",X.setAttribute("aria-hidden","true"),pe=rt(),d.style.setProperty("--ago-vh",`${pe}px`),it(),Ht();const t=lt(()=>dt(!0));return t.then(()=>{st(),xe()}),st(),M?.(),t}function me(){if(!W)return Promise.resolve();W=!1,at(),d.querySelector("textarea")?.blur();const e=lt(()=>dt(!1));return e.then(()=>d.style.removeProperty("--ago-vh")),pe=0,q?.(),e}}exports.mountChatWidget=pn;exports.renderMarkdown=Ie;
package/dist/widget.d.cts CHANGED
@@ -876,11 +876,13 @@ export declare interface MountChatWidgetOptions {
876
876
  /** Max viewport width (px) treated as "mobile". Defaults to `768`. */
877
877
  breakpoint?: number;
878
878
  /**
879
- * Inline placement only: how the card enters full screen. `"focus"` (default)
880
- * expands when the input is tapped/focused; `"manual"` expands only via
881
- * `widget.open()`. Ignored for side placements (driven by the launcher).
879
+ * Inline placement only: how the card enters full screen.
880
+ * - `"tap"` (default): expands when anywhere on the compact card is tapped
881
+ * - `"focus"`: expands only when the input is tapped/focused.
882
+ * - `"manual"`: expands only via `widget.open()`.
883
+ * Ignored for side placements (driven by the launcher).
882
884
  */
883
- trigger?: "focus" | "manual";
885
+ trigger?: "tap" | "focus" | "manual";
884
886
  };
885
887
  /**
886
888
  * Load the visitor's conversation list into `widget.threads` on mount and refresh
package/dist/widget.d.ts CHANGED
@@ -876,11 +876,13 @@ export declare interface MountChatWidgetOptions {
876
876
  /** Max viewport width (px) treated as "mobile". Defaults to `768`. */
877
877
  breakpoint?: number;
878
878
  /**
879
- * Inline placement only: how the card enters full screen. `"focus"` (default)
880
- * expands when the input is tapped/focused; `"manual"` expands only via
881
- * `widget.open()`. Ignored for side placements (driven by the launcher).
879
+ * Inline placement only: how the card enters full screen.
880
+ * - `"tap"` (default): expands when anywhere on the compact card is tapped
881
+ * - `"focus"`: expands only when the input is tapped/focused.
882
+ * - `"manual"`: expands only via `widget.open()`.
883
+ * Ignored for side placements (driven by the launcher).
882
884
  */
883
- trigger?: "focus" | "manual";
885
+ trigger?: "tap" | "focus" | "manual";
884
886
  };
885
887
  /**
886
888
  * Load the visitor's conversation list into `widget.threads` on mount and refresh
package/dist/widget.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { a as Ut, i as Wt, m as Gt, o as Vt, s as jt, t as qt } from "./AgoClient-Cwx_eYSu.js";
2
2
  import { r as Kt, t as Xt } from "./createFormCollector-CyWisAkI.js";
3
3
  import { t as Qt } from "./createConversationSession-B3h567tt.js";
4
- var Yt = '"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif', Ee = `var(--ago-font, ${Yt})`, lt = {
4
+ var Yt = '"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif', Se = `var(--ago-font, ${Yt})`, dt = {
5
5
  font: "--ago-font",
6
6
  radius: "--ago-radius",
7
7
  messageRadius: "--ago-message-radius",
@@ -16,12 +16,12 @@ var Yt = '"IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto
16
16
  border: "--ago-border-color",
17
17
  accent: "--ago-accent-color",
18
18
  agentBubbleBg: "--ago-agent-bubble-background"
19
- }, Re = "var(--ago-brand-color, #03182f)", ke = "var(--ago-brand-text-color, #fff)", Zt = "var(--ago-header-background, var(--ago-brand-color, #03182f))", dt = "var(--ago-header-text-color, #e8f0fe)", ee = "var(--ago-panel-background, #fff)", mt = "var(--ago-messages-background, #fbfbfb)", J = "var(--ago-text-color, #30373e)", gt = "var(--ago-muted-text-color, #6b6d6f)", L = "var(--ago-border-color, #dee3e8)", Be = "var(--ago-accent-color, #1b5fc4)", ct = "var(--ago-agent-bubble-background, #f1f3f5)", Jt = "var(--ago-radius, 16px)", Me = "var(--ago-message-radius, 16px)", en = "var(--ago-message-radius, 20px)";
19
+ }, ke = "var(--ago-brand-color, #03182f)", Ae = "var(--ago-brand-text-color, #fff)", Zt = "var(--ago-header-background, var(--ago-brand-color, #03182f))", ct = "var(--ago-header-text-color, #e8f0fe)", ee = "var(--ago-panel-background, #fff)", gt = "var(--ago-messages-background, #fbfbfb)", J = "var(--ago-text-color, #30373e)", ht = "var(--ago-muted-text-color, #6b6d6f)", L = "var(--ago-border-color, #dee3e8)", Me = "var(--ago-accent-color, #1b5fc4)", pt = "var(--ago-agent-bubble-background, #f1f3f5)", Jt = "var(--ago-radius, 16px)", Oe = "var(--ago-message-radius, 16px)", en = "var(--ago-message-radius, 20px)";
20
20
  function tn(n, o) {
21
21
  if (o)
22
- for (const i of Object.keys(lt)) {
22
+ for (const i of Object.keys(dt)) {
23
23
  const r = o[i];
24
- r != null && n.style.setProperty(lt[i], r);
24
+ r != null && n.style.setProperty(dt[i], r);
25
25
  }
26
26
  }
27
27
  function v(n, o) {
@@ -31,11 +31,11 @@ function h(n = {}) {
31
31
  const o = document.createElement("div");
32
32
  return v(o, n), o;
33
33
  }
34
- var pt = "ago-chat-widget-keyframes";
34
+ var ft = "ago-chat-widget-keyframes";
35
35
  function nn() {
36
- if (typeof document > "u" || document.getElementById(pt)) return;
36
+ if (typeof document > "u" || document.getElementById(ft)) return;
37
37
  const n = document.createElement("style");
38
- n.id = pt, n.textContent = "@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }@keyframes ago-spin { to { transform: rotate(360deg); } }", document.head.appendChild(n);
38
+ n.id = ft, n.textContent = "@keyframes ago-pulse { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }@keyframes ago-spin { to { transform: rotate(360deg); } }", document.head.appendChild(n);
39
39
  }
40
40
  function on(n) {
41
41
  let o = [];
@@ -65,7 +65,7 @@ function on(n) {
65
65
  border: `1px solid ${L}`,
66
66
  borderRadius: "12px",
67
67
  fontSize: "16px",
68
- fontFamily: Ee,
68
+ fontFamily: Se,
69
69
  lineHeight: "1.4",
70
70
  maxHeight: "110px",
71
71
  overflowY: "hidden"
@@ -86,8 +86,8 @@ function on(n) {
86
86
  padding: "0",
87
87
  border: "none",
88
88
  borderRadius: "50%",
89
- backgroundColor: Re,
90
- color: ke,
89
+ backgroundColor: ke,
90
+ color: Ae,
91
91
  display: "flex",
92
92
  alignItems: "center",
93
93
  justifyContent: "center",
@@ -130,18 +130,18 @@ function on(n) {
130
130
  fontSize: "14px",
131
131
  lineHeight: "1"
132
132
  }), k.addEventListener("click", () => {
133
- o = o.filter((G, V) => V !== c), Y();
133
+ o = o.filter((V, j) => j !== c), Y();
134
134
  }), y.append(T, k), r.appendChild(y);
135
135
  }), A();
136
136
  }
137
- const O = () => {
137
+ const D = () => {
138
138
  const s = a.value, c = o;
139
139
  return a.value = "", C(), o = [], Y(), {
140
140
  content: s,
141
141
  files: c
142
142
  };
143
143
  }, g = () => {
144
- const { content: s, files: c } = O();
144
+ const { content: s, files: c } = D();
145
145
  (s.trim() || c.length > 0) && n.onSend(s.trim(), c.length > 0 ? c : void 0);
146
146
  };
147
147
  return i.addEventListener("submit", (s) => {
@@ -150,7 +150,7 @@ function on(n) {
150
150
  s.key === "Enter" && !s.shiftKey && (s.preventDefault(), g());
151
151
  }), _ && b.appendChild(_), b.append(a, p), R && i.appendChild(R), i.append(r, b), A(), {
152
152
  inputRow: i,
153
- getValueAndClear: O,
153
+ getValueAndClear: D,
154
154
  setDisabled: (s) => {
155
155
  a.disabled = s, f = s, A();
156
156
  },
@@ -164,42 +164,42 @@ var rn = {
164
164
  '"': "&quot;",
165
165
  "'": "&#39;"
166
166
  };
167
- function ie(n) {
167
+ function ae(n) {
168
168
  return n.replace(/[&<>"']/g, (o) => rn[o]);
169
169
  }
170
- function ft(n) {
170
+ function ut(n) {
171
171
  const o = n.trim();
172
172
  return /^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(o) || !/^[a-z][a-z0-9+.-]*:/i.test(o) ? o : null;
173
173
  }
174
- var ht = '"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace', Ce = "";
174
+ var xt = '"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace', Ee = "";
175
175
  function te(n) {
176
- const o = [], i = (b) => (o.push(b), `${Ce}${o.length - 1}${Ce}`);
176
+ const o = [], i = (b) => (o.push(b), `${Ee}${o.length - 1}${Ee}`);
177
177
  let r = n;
178
- return r = r.replace(/`([^`]+)`/g, (b, a) => i(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${ht}">${ie(a)}</code>`)), r = r.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (b, a, C) => {
179
- const m = ft(C);
180
- return m ? i(`<img alt="${ie(a)}" src="${ie(m)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`) : b;
178
+ return r = r.replace(/`([^`]+)`/g, (b, a) => i(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${xt}">${ae(a)}</code>`)), r = r.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (b, a, C) => {
179
+ const m = ut(C);
180
+ return m ? i(`<img alt="${ae(a)}" src="${ae(m)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`) : b;
181
181
  }), r = r.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (b, a, C) => {
182
- const m = ft(C);
183
- return m ? i(`<a href="${ie(m)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${te(a)}</a>`) : b;
184
- }), r = ie(r), r = r.replace(/\*\*([^*]+?)\*\*/g, "<strong>$1</strong>").replace(/__([^_]+?)__/g, "<strong>$1</strong>").replace(/~~([^~]+?)~~/g, "<del>$1</del>").replace(/(^|[^*])\*(?!\s)([^*]+?)\*/g, "$1<em>$2</em>").replace(/(^|[^\w_])_(?!\s)([^_]+?)_/g, "$1<em>$2</em>"), r = r.replace(new RegExp(`${Ce}(\\d+)${Ce}`, "g"), (b, a) => o[Number(a)]), r;
182
+ const m = ut(C);
183
+ return m ? i(`<a href="${ae(m)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${te(a)}</a>`) : b;
184
+ }), r = ae(r), r = r.replace(/\*\*([^*]+?)\*\*/g, "<strong>$1</strong>").replace(/__([^_]+?)__/g, "<strong>$1</strong>").replace(/~~([^~]+?)~~/g, "<del>$1</del>").replace(/(^|[^*])\*(?!\s)([^*]+?)\*/g, "$1<em>$2</em>").replace(/(^|[^\w_])_(?!\s)([^_]+?)_/g, "$1<em>$2</em>"), r = r.replace(new RegExp(`${Ee}(\\d+)${Ee}`, "g"), (b, a) => o[Number(a)]), r;
185
185
  }
186
- function M(n, o, i) {
186
+ function O(n, o, i) {
187
187
  const r = document.createElement(n);
188
188
  return Object.assign(r.style, o), i !== void 0 && (r.innerHTML = i), r;
189
189
  }
190
- var xt = /^ {0,3}([-*_])( *\1){2,} *$/, bt = /^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/, vt = /^ {0,3}(```+|~~~+)/, Se = /^ {0,3}>\s?/, ae = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/, an = [
190
+ var bt = /^ {0,3}([-*_])( *\1){2,} *$/, vt = /^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/, yt = /^ {0,3}(```+|~~~+)/, Re = /^ {0,3}>\s?/, se = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/, an = [
191
191
  "20px",
192
192
  "18px",
193
193
  "16px",
194
194
  "15px",
195
195
  "14px",
196
196
  "13px"
197
- ], Oe = (n) => n.match(/^\s*/)?.[0].length ?? 0;
197
+ ], De = (n) => n.match(/^\s*/)?.[0].length ?? 0;
198
198
  function sn(n) {
199
- return n.trim() === "" || xt.test(n) || bt.test(n) || vt.test(n) || Se.test(n) || ae.test(n);
199
+ return n.trim() === "" || bt.test(n) || vt.test(n) || yt.test(n) || Re.test(n) || se.test(n);
200
200
  }
201
- function yt(n) {
202
- const o = n[0].match(ae), i = o[1].length, r = /\d/.test(o[2]), b = M(r ? "ol" : "ul", {
201
+ function wt(n) {
202
+ const o = n[0].match(se), i = o[1].length, r = /\d/.test(o[2]), b = O(r ? "ol" : "ul", {
203
203
  margin: "0 0 8px 0",
204
204
  paddingLeft: "20px",
205
205
  listStyleType: r ? "decimal" : "disc",
@@ -207,28 +207,28 @@ function yt(n) {
207
207
  });
208
208
  let a = 0;
209
209
  for (; a < n.length; ) {
210
- const C = n[a].match(ae), m = [];
211
- for (a++; a < n.length && Oe(n[a]) > i; )
210
+ const C = n[a].match(se), m = [];
211
+ for (a++; a < n.length && De(n[a]) > i; )
212
212
  m.push(n[a]), a++;
213
- const x = M("li", {
213
+ const x = O("li", {
214
214
  display: "list-item",
215
215
  margin: "2px 0",
216
216
  lineHeight: "1.6"
217
217
  }), p = C[3].match(/^\[([ xX])\]\s+(.*)$/);
218
- p ? (x.style.listStyleType = "none", x.style.marginLeft = "-20px", x.innerHTML = `<span style="margin-right:6px">${p[1].toLowerCase() === "x" ? "☑" : "☐"}</span>${te(p[2])}`) : x.innerHTML = te(C[3]), m.filter((f) => ae.test(f)).length > 0 && x.appendChild(yt(m.filter((f) => f.trim() !== ""))), b.appendChild(x);
218
+ p ? (x.style.listStyleType = "none", x.style.marginLeft = "-20px", x.innerHTML = `<span style="margin-right:6px">${p[1].toLowerCase() === "x" ? "☑" : "☐"}</span>${te(p[2])}`) : x.innerHTML = te(C[3]), m.filter((f) => se.test(f)).length > 0 && x.appendChild(wt(m.filter((f) => f.trim() !== ""))), b.appendChild(x);
219
219
  }
220
220
  return b;
221
221
  }
222
222
  function ln(n) {
223
- const o = (m) => m.replace(/^\s*\|?/, "").replace(/\|?\s*$/, "").split("|").map((x) => x.trim()), i = M("div", {
223
+ const o = (m) => m.replace(/^\s*\|?/, "").replace(/\|?\s*$/, "").split("|").map((x) => x.trim()), i = O("div", {
224
224
  overflowX: "auto",
225
225
  margin: "0 0 8px 0"
226
- }), r = M("table", {
226
+ }), r = O("table", {
227
227
  borderCollapse: "collapse",
228
228
  width: "100%",
229
229
  fontSize: "13px"
230
230
  }), b = document.createElement("thead"), a = document.createElement("tr");
231
- for (const m of o(n[0])) a.appendChild(M("th", {
231
+ for (const m of o(n[0])) a.appendChild(O("th", {
232
232
  border: "1px solid #dee3e8",
233
233
  padding: "6px 10px",
234
234
  textAlign: "left",
@@ -239,7 +239,7 @@ function ln(n) {
239
239
  const C = document.createElement("tbody");
240
240
  for (const m of n.slice(2)) {
241
241
  const x = document.createElement("tr");
242
- for (const p of o(m)) x.appendChild(M("td", {
242
+ for (const p of o(m)) x.appendChild(O("td", {
243
243
  border: "1px solid #dee3e8",
244
244
  padding: "6px 10px"
245
245
  }, te(p)));
@@ -248,7 +248,7 @@ function ln(n) {
248
248
  return r.appendChild(C), i.appendChild(r), i;
249
249
  }
250
250
  var dn = (n) => !!n && /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(n);
251
- function De(n) {
251
+ function ze(n) {
252
252
  const o = document.createDocumentFragment(), i = n.replace(/\r\n?/g, `
253
253
  `).split(`
254
254
  `);
@@ -259,38 +259,38 @@ function De(n) {
259
259
  r++;
260
260
  continue;
261
261
  }
262
- const C = a.match(vt);
262
+ const C = a.match(yt);
263
263
  if (C) {
264
264
  const p = C[1][0], f = [];
265
265
  for (r++; r < i.length && !new RegExp(`^ {0,3}${p === "`" ? "`{3,}" : "~{3,}"}\\s*$`).test(i[r]); )
266
266
  f.push(i[r]), r++;
267
267
  r++;
268
- const A = M("pre", { margin: "0 0 8px 0" });
269
- A.appendChild(M("code", {
268
+ const A = O("pre", { margin: "0 0 8px 0" });
269
+ A.appendChild(O("code", {
270
270
  display: "block",
271
271
  background: "#f5f5f5",
272
272
  padding: "8px 12px",
273
273
  borderRadius: "6px",
274
274
  fontSize: "13px",
275
275
  overflowX: "auto",
276
- fontFamily: ht,
276
+ fontFamily: xt,
277
277
  whiteSpace: "pre"
278
- }, ie(f.join(`
278
+ }, ae(f.join(`
279
279
  `)))), o.appendChild(A);
280
280
  continue;
281
281
  }
282
- if (xt.test(a)) {
283
- o.appendChild(M("hr", {
282
+ if (bt.test(a)) {
283
+ o.appendChild(O("hr", {
284
284
  border: "none",
285
285
  borderTop: "1px solid #dee3e8",
286
286
  margin: "12px 0"
287
287
  })), r++;
288
288
  continue;
289
289
  }
290
- const m = a.match(bt);
290
+ const m = a.match(vt);
291
291
  if (m) {
292
292
  const p = m[1].length;
293
- o.appendChild(M(`h${p}`, {
293
+ o.appendChild(O(`h${p}`, {
294
294
  margin: "16px 0 8px 0",
295
295
  fontSize: an[p - 1],
296
296
  fontWeight: "600",
@@ -298,18 +298,18 @@ function De(n) {
298
298
  }, te(m[2]))), r++;
299
299
  continue;
300
300
  }
301
- if (Se.test(a)) {
301
+ if (Re.test(a)) {
302
302
  const p = [];
303
- for (; r < i.length && Se.test(i[r]); )
304
- p.push(i[r].replace(Se, "")), r++;
305
- const f = M("blockquote", {
303
+ for (; r < i.length && Re.test(i[r]); )
304
+ p.push(i[r].replace(Re, "")), r++;
305
+ const f = O("blockquote", {
306
306
  borderLeft: "4px solid #dee3e8",
307
307
  paddingLeft: "12px",
308
308
  margin: "0 0 8px 0",
309
309
  fontStyle: "italic",
310
310
  color: "#6b6d6f"
311
311
  });
312
- f.appendChild(De(p.join(`
312
+ f.appendChild(ze(p.join(`
313
313
  `))), o.appendChild(f);
314
314
  continue;
315
315
  }
@@ -320,19 +320,19 @@ function De(n) {
320
320
  o.appendChild(ln(p));
321
321
  continue;
322
322
  }
323
- if (ae.test(a)) {
324
- const p = [], f = Oe(a);
323
+ if (se.test(a)) {
324
+ const p = [], f = De(a);
325
325
  for (; r < i.length && i[r].trim() !== ""; )
326
- if (ae.test(i[r]) || Oe(i[r]) > f)
326
+ if (se.test(i[r]) || De(i[r]) > f)
327
327
  p.push(i[r]), r++;
328
328
  else break;
329
- o.appendChild(yt(p));
329
+ o.appendChild(wt(p));
330
330
  continue;
331
331
  }
332
332
  const x = [a];
333
333
  for (r++; r < i.length && !sn(i[r]); )
334
334
  x.push(i[r]), r++;
335
- o.appendChild(M("p", {
335
+ o.appendChild(O("p", {
336
336
  margin: "0 0 8px 0",
337
337
  lineHeight: "1.6"
338
338
  }, x.map((p) => te(p)).join("<br>")));
@@ -386,8 +386,8 @@ function cn(n, o) {
386
386
  width: "18px",
387
387
  height: "18px",
388
388
  borderRadius: "3px",
389
- border: `1px solid ${Be}`,
390
- color: Be,
389
+ border: `1px solid ${Me}`,
390
+ color: Me,
391
391
  fontSize: "11px",
392
392
  fontWeight: "500",
393
393
  display: "flex",
@@ -422,15 +422,15 @@ function cn(n, o) {
422
422
  display: "inline-block",
423
423
  textDecoration: "none"
424
424
  });
425
- const j = document.createElement("img");
426
- j.src = c, j.alt = s.name, j.loading = "lazy", v(j, {
425
+ const q = document.createElement("img");
426
+ q.src = c, q.alt = s.name, q.loading = "lazy", v(q, {
427
427
  maxWidth: "180px",
428
428
  maxHeight: "160px",
429
429
  objectFit: "cover",
430
430
  borderRadius: "10px",
431
431
  border: `1px solid ${L}`,
432
432
  display: "block"
433
- }), B.appendChild(j), g.appendChild(B);
433
+ }), B.appendChild(q), g.appendChild(B);
434
434
  continue;
435
435
  }
436
436
  const y = c ? document.createElement("a") : document.createElement("div");
@@ -442,7 +442,7 @@ function cn(n, o) {
442
442
  borderRadius: "10px",
443
443
  border: `1px solid ${L}`,
444
444
  backgroundColor: f ? "rgba(255,255,255,0.12)" : ee,
445
- color: f ? ke : J,
445
+ color: f ? Ae : J,
446
446
  fontSize: "13px",
447
447
  textDecoration: "none",
448
448
  maxWidth: "220px"
@@ -457,45 +457,45 @@ function cn(n, o) {
457
457
  display: "flex",
458
458
  flexDirection: "column",
459
459
  minWidth: "0"
460
- }), G = h({
460
+ }), V = h({
461
461
  overflow: "hidden",
462
462
  textOverflow: "ellipsis",
463
463
  whiteSpace: "nowrap",
464
464
  maxWidth: "160px"
465
465
  });
466
- G.textContent = s.name, G.title = s.name, k.appendChild(G);
467
- const V = Vt(s.fileSize);
468
- if (V) {
466
+ V.textContent = s.name, V.title = s.name, k.appendChild(V);
467
+ const j = Vt(s.fileSize);
468
+ if (j) {
469
469
  const B = h({
470
470
  fontSize: "11px",
471
- color: gt
471
+ color: ht
472
472
  });
473
- B.textContent = V, k.appendChild(B);
473
+ B.textContent = j, k.appendChild(B);
474
474
  }
475
475
  y.append(T, k), g.appendChild(y);
476
476
  }
477
477
  R.appendChild(g);
478
478
  }
479
- const _ = f || C || A, Y = !!n.content || n.status === "IN_PROGRESS", O = h({
479
+ const _ = f || C || A, Y = !!n.content || n.status === "IN_PROGRESS", D = h({
480
480
  maxWidth: _ ? A || f ? p ? "88%" : "75%" : p ? "92%" : "85%" : "100%",
481
481
  padding: _ ? "10px 14px" : "2px 8px",
482
- borderRadius: A ? en : _ ? Me : "0",
483
- backgroundColor: f ? Re : _ ? ct : "transparent",
484
- color: f ? ke : J,
482
+ borderRadius: A ? en : _ ? Oe : "0",
483
+ backgroundColor: f ? ke : _ ? pt : "transparent",
484
+ color: f ? Ae : J,
485
485
  overflowWrap: "break-word",
486
486
  textWrap: "pretty",
487
487
  fontSize: "16px",
488
488
  lineHeight: "1.6"
489
489
  });
490
- if (O.className = "ago-message__content", A && r) {
491
- O.style.position = "relative";
490
+ if (D.className = "ago-message__content", A && r) {
491
+ D.style.position = "relative";
492
492
  const g = h({
493
493
  position: "absolute",
494
494
  zIndex: "0",
495
495
  bottom: "-2px",
496
496
  width: "20px",
497
497
  height: "20px",
498
- background: f ? Re : ct
498
+ background: f ? ke : pt
499
499
  });
500
500
  g.className = "ago-message__tail";
501
501
  const s = h({
@@ -504,11 +504,11 @@ function cn(n, o) {
504
504
  bottom: "-2px",
505
505
  width: "10px",
506
506
  height: "20px",
507
- background: mt
507
+ background: gt
508
508
  });
509
- s.className = "ago-message__tail-mask", f ? (g.style.right = "-8px", g.style.borderBottomLeftRadius = "16px 14px", s.style.right = "-10px", s.style.borderBottomLeftRadius = "10px") : (g.style.left = "-7px", g.style.borderBottomRightRadius = "16px 14px", s.style.left = "-10px", s.style.borderBottomRightRadius = "10px"), O.append(g, s);
509
+ s.className = "ago-message__tail-mask", f ? (g.style.right = "-8px", g.style.borderBottomLeftRadius = "16px 14px", s.style.right = "-10px", s.style.borderBottomLeftRadius = "10px") : (g.style.left = "-7px", g.style.borderBottomRightRadius = "16px 14px", s.style.left = "-10px", s.style.borderBottomRightRadius = "10px"), D.append(g, s);
510
510
  }
511
- if (n.content ? O.appendChild(De(n.content)) : n.status === "IN_PROGRESS" && O.appendChild(fn()), Y && R.appendChild(O), i && n.followUpReplies && n.followUpReplies.length > 0) {
511
+ if (n.content ? D.appendChild(ze(n.content)) : n.status === "IN_PROGRESS" && D.appendChild(fn()), Y && R.appendChild(D), i && n.followUpReplies && n.followUpReplies.length > 0) {
512
512
  const g = h({
513
513
  display: "flex",
514
514
  flexWrap: "wrap",
@@ -522,14 +522,14 @@ function cn(n, o) {
522
522
  minHeight: "36px",
523
523
  padding: "6px 14px",
524
524
  fontSize: "14px",
525
- borderRadius: Me,
525
+ borderRadius: Oe,
526
526
  border: `1px solid ${L}`,
527
527
  backgroundColor: ee,
528
528
  color: J,
529
529
  cursor: m ? "pointer" : "default",
530
530
  transition: "border-color 0.15s"
531
531
  }), x && c.addEventListener("click", () => x(s)), c.addEventListener("mouseenter", () => {
532
- c.style.borderColor = Be;
532
+ c.style.borderColor = Me;
533
533
  }), c.addEventListener("mouseleave", () => {
534
534
  c.style.borderColor = L;
535
535
  }), g.appendChild(c);
@@ -546,7 +546,7 @@ function pn(n) {
546
546
  padding: "10px 14px",
547
547
  backgroundColor: "#f0fdf4",
548
548
  color: "#15803d",
549
- borderRadius: Me,
549
+ borderRadius: Oe,
550
550
  marginTop: "8px",
551
551
  fontSize: "13px",
552
552
  border: "1px solid #bbf7d0"
@@ -582,7 +582,7 @@ function un() {
582
582
  const i = document.createElementNS(n, "path");
583
583
  return i.setAttribute("d", "M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"), i.setAttribute("stroke", "currentColor"), i.setAttribute("stroke-width", "2"), i.setAttribute("stroke-linecap", "round"), i.setAttribute("stroke-linejoin", "round"), o.appendChild(i), o;
584
584
  }
585
- var ut = "Form submitted.";
585
+ var mt = "Form submitted.";
586
586
  function mn(n) {
587
587
  if (typeof n == "string") return n || null;
588
588
  if (!n || typeof n != "object") return null;
@@ -602,45 +602,45 @@ function hn(n) {
602
602
  if (!o) throw new Error(`mountChatWidget: target "${String(n)}" not found.`);
603
603
  return o;
604
604
  }
605
- function yn(n, o) {
606
- const { title: i = "Chat", welcomeMessage: r = "Hello! How can I help you today?", placeholder: b = "Type a message...", allowFiles: a = !1, height: C = 500, placement: m = "inline", width: x = 400, defaultOpen: p = !1, logoUrl: f, showAgentName: A = !1, agentBubble: R = !1, bubbleStyle: _ = "default", showHeader: Y = !0, theme: O, loadThreads: g = !1, forms: s, formSubmittedMessage: c = ut, onFollowUpClick: y, onMessageSent: T, onMessageReceived: k, onFormSubmitted: G, onFormError: V, onOpen: B, onClose: j } = o, ne = typeof r == "string" ? {
605
+ function wn(n, o) {
606
+ const { title: i = "Chat", welcomeMessage: r = "Hello! How can I help you today?", placeholder: b = "Type a message...", allowFiles: a = !1, height: C = 500, placement: m = "inline", width: x = 400, defaultOpen: p = !1, logoUrl: f, showAgentName: A = !1, agentBubble: R = !1, bubbleStyle: _ = "default", showHeader: Y = !0, theme: D, loadThreads: g = !1, forms: s, formSubmittedMessage: c = mt, onFollowUpClick: y, onMessageSent: T, onMessageReceived: k, onFormSubmitted: V, onFormError: j, onOpen: B, onClose: q } = o, ne = typeof r == "string" ? {
607
607
  message: r,
608
608
  mode: "static"
609
- } : r, ze = ne.message, Fe = ne.mode ?? "static", wt = "speed" in ne && ne.speed || 45, He = "followUpReplies" in ne && ne.followUpReplies || void 0;
609
+ } : r, Fe = ne.message, He = ne.mode ?? "static", Ct = "speed" in ne && ne.speed || 45, Pe = "followUpReplies" in ne && ne.followUpReplies || void 0;
610
610
  if (!o.client && !o.config?.baseUrl) throw new Gt("mountChatWidget requires either `client` or `config` (with a baseUrl).", "config_missing_base_url");
611
- const E = o.client ?? new qt(o.config), Pe = hn(n), D = m === "left" || m === "right", Ct = D && (o.launcher ?? !0);
612
- let oe = D ? p : !0;
613
- const Et = o.mobile?.breakpoint ?? 768, St = o.mobile?.trigger ?? "focus", Ue = typeof window < "u" && !!window.matchMedia, z = Ue ? window.matchMedia(`(max-width: ${Et}px)`) : void 0, Rt = Ue ? window.matchMedia("(prefers-reduced-motion: reduce)") : void 0, se = !D && !!z, Ae = o.persistConversation, ue = Ae ? Qt(Ae === !0 ? {} : Ae) : void 0;
614
- let P = o.conversationId ?? ue?.getLastActiveThread() ?? void 0, u = [], Z = !1, le = null, q;
615
- const We = [];
611
+ const E = o.client ?? new qt(o.config), Ue = hn(n), z = m === "left" || m === "right", Et = z && (o.launcher ?? !0);
612
+ let oe = z ? p : !0;
613
+ const St = o.mobile?.breakpoint ?? 768, _e = o.mobile?.trigger ?? "tap", We = typeof window < "u" && !!window.matchMedia, M = We ? window.matchMedia(`(max-width: ${St}px)`) : void 0, Rt = We ? window.matchMedia("(prefers-reduced-motion: reduce)") : void 0, re = !z && !!M, Ie = o.persistConversation, me = Ie ? Qt(Ie === !0 ? {} : Ie) : void 0;
614
+ let P = o.conversationId ?? me?.getLastActiveThread() ?? void 0, u = [], Z = !1, le = null, K;
615
+ const Ge = [];
616
616
  function kt(e) {
617
617
  if (typeof c == "function") {
618
618
  const l = c(e);
619
619
  if (typeof l == "string" && l) return l;
620
620
  }
621
621
  const t = mn(e);
622
- return t || (typeof c == "string" ? c : ut);
622
+ return t || (typeof c == "string" ? c : mt);
623
623
  }
624
- const me = [], d = h({
624
+ const ge = [], d = h({
625
625
  display: "flex",
626
626
  flexDirection: "column",
627
- height: D ? "100%" : typeof C == "number" ? `${C}px` : C,
627
+ height: z ? "100%" : typeof C == "number" ? `${C}px` : C,
628
628
  border: `1px solid ${L}`,
629
629
  borderRadius: Jt,
630
630
  overflow: "hidden",
631
631
  backgroundColor: ee,
632
- fontFamily: Ee,
632
+ fontFamily: Se,
633
633
  textAlign: "left",
634
634
  boxShadow: "rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"
635
635
  });
636
- d.className = "ago-chat-widget", tn(d, O);
636
+ d.className = "ago-chat-widget", tn(d, D);
637
637
  let F;
638
638
  if (Y) {
639
639
  if (F = h({
640
640
  padding: "14px 16px",
641
641
  borderBottom: `1px solid ${L}`,
642
642
  backgroundColor: Zt,
643
- color: dt,
643
+ color: ct,
644
644
  display: "flex",
645
645
  alignItems: "center",
646
646
  gap: "10px"
@@ -656,42 +656,42 @@ function yn(n, o) {
656
656
  margin: "0",
657
657
  fontSize: "15px",
658
658
  fontWeight: "600"
659
- }), F.appendChild(e), D) {
659
+ }), F.appendChild(e), z) {
660
660
  const t = document.createElement("button");
661
661
  t.type = "button", t.className = "ago-chat-widget__close", t.setAttribute("aria-label", "Close"), t.textContent = "×", v(t, {
662
662
  marginLeft: "auto",
663
663
  background: "transparent",
664
664
  border: "none",
665
- color: dt,
665
+ color: ct,
666
666
  fontSize: "22px",
667
667
  lineHeight: "1",
668
668
  cursor: "pointer",
669
669
  padding: "0 2px"
670
- }), t.addEventListener("click", () => Te()), F.appendChild(t);
670
+ }), t.addEventListener("click", () => Be()), F.appendChild(t);
671
671
  }
672
672
  }
673
673
  const I = h({
674
674
  flex: "1",
675
675
  overflow: "auto",
676
676
  padding: "16px",
677
- backgroundColor: mt
677
+ backgroundColor: gt
678
678
  });
679
679
  I.className = "ago-chat-widget__messages", I.setAttribute("role", "log"), I.setAttribute("aria-live", "polite"), I.setAttribute("aria-relevant", "additions text"), I.setAttribute("aria-atomic", "false");
680
- const { inputRow: _e, setDisabled: At, focus: ge } = on({
680
+ const { inputRow: $e, setDisabled: At, focus: he } = on({
681
681
  placeholder: b,
682
682
  allowFiles: a,
683
683
  onSend: (e, t) => {
684
- $e(e, t);
684
+ ye(e, t);
685
685
  }
686
686
  });
687
- nn(), d.append(...F ? [F] : [], I, _e);
688
- let he = d, U, N;
689
- const xe = m === "left" ? "left" : "right";
690
- if (D && (U = h({
687
+ nn(), d.append(...F ? [F] : [], I, $e);
688
+ let xe = d, U, N;
689
+ const be = m === "left" ? "left" : "right";
690
+ if (z && (U = h({
691
691
  position: "fixed",
692
692
  top: "0",
693
693
  bottom: "0",
694
- [xe]: "0",
694
+ [be]: "0",
695
695
  width: typeof x == "number" ? `${x}px` : x,
696
696
  maxWidth: "100vw",
697
697
  display: "flex",
@@ -704,25 +704,25 @@ function yn(n, o) {
704
704
  borderRadius: "0",
705
705
  border: "none",
706
706
  boxShadow: "none",
707
- [xe === "left" ? "borderRight" : "borderLeft"]: `1px solid ${L}`
708
- }), U.appendChild(d), he = U), Ct) {
707
+ [be === "left" ? "borderRight" : "borderLeft"]: `1px solid ${L}`
708
+ }), U.appendChild(d), xe = U), Et) {
709
709
  if (N = document.createElement("button"), N.type = "button", N.className = "ago-chat-widget-launcher", N.setAttribute("aria-label", `Open ${i}`), v(N, {
710
710
  position: "fixed",
711
711
  bottom: "20px",
712
- [xe]: "20px",
712
+ [be]: "20px",
713
713
  width: "56px",
714
714
  height: "56px",
715
715
  borderRadius: "50%",
716
716
  border: "none",
717
- backgroundColor: Re,
718
- color: ke,
717
+ backgroundColor: ke,
718
+ color: Ae,
719
719
  cursor: "pointer",
720
720
  display: "flex",
721
721
  alignItems: "center",
722
722
  justifyContent: "center",
723
723
  zIndex: "2147483000",
724
724
  boxShadow: "rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",
725
- fontFamily: Ee
725
+ fontFamily: Se
726
726
  }), f) {
727
727
  const e = document.createElement("img");
728
728
  e.src = f, e.alt = "", v(e, {
@@ -731,35 +731,40 @@ function yn(n, o) {
731
731
  objectFit: "contain"
732
732
  }), N.appendChild(e);
733
733
  } else N.appendChild(un());
734
- N.addEventListener("click", () => Ne());
734
+ N.addEventListener("click", () => Te());
735
735
  }
736
- const de = se ? `ago-vt-${++gn}` : "", Ge = 52;
737
- let K = !1, ce = 0, re = 0, H, pe, X;
738
- const be = {
736
+ const de = re ? `ago-vt-${++gn}` : "", Ve = 52;
737
+ let W = !1, ce = 0, ie = 0, H, pe, X;
738
+ const ve = {
739
739
  height: d.style.height,
740
740
  border: d.style.border,
741
741
  borderRadius: d.style.borderRadius,
742
742
  boxShadow: d.style.boxShadow
743
743
  };
744
- Pe.appendChild(he), N && Pe.appendChild(N), ve(), se && (H = Ft(), d.insertBefore(H, d.firstChild), pe = document.createElement("style"), pe.id = de, pe.textContent = `::view-transition-group(${de}),::view-transition-group(${de}-bar){animation-duration:0.3s;animation-timing-function:cubic-bezier(0.4,0,0.2,1)}`, document.head.appendChild(pe), St === "focus" && (d.addEventListener("pointerdown", (e) => {
745
- K || !z?.matches || _e.contains(e.target) && (e.preventDefault(), we());
744
+ Ue.appendChild(xe), N && Ue.appendChild(N), we(), re && (H = Ft(), d.insertBefore(H, d.firstChild), pe = document.createElement("style"), pe.id = de, pe.textContent = `::view-transition-group(${de}),::view-transition-group(${de}-bar){animation-duration:0.3s;animation-timing-function:cubic-bezier(0.4,0,0.2,1)}`, document.head.appendChild(pe), (_e === "focus" || _e === "tap") && (d.addEventListener("pointerdown", (e) => {
745
+ if (W || !M?.matches) return;
746
+ const t = $e.contains(e.target);
747
+ if (_e === "tap") {
748
+ if ((e.target instanceof Element ? e.target : null)?.closest("button,a[href],[role='button']")) return;
749
+ } else if (!t) return;
750
+ t && e.preventDefault(), fe();
746
751
  }, !0), d.addEventListener("focusin", (e) => {
747
- z?.matches && _e.contains(e.target) && we();
748
- })), document.addEventListener("keydown", et)), z && z.addEventListener("change", tt);
752
+ M?.matches && $e.contains(e.target) && fe();
753
+ })), document.addEventListener("keydown", tt)), M && M.addEventListener("change", nt);
749
754
  const _t = y !== !1, It = y === !1 ? void 0 : y ?? ((e) => {
750
- $e(e);
755
+ re && M?.matches && !W ? fe().then(() => ye(e)) : ye(e);
751
756
  });
752
757
  function $() {
753
758
  if (I.replaceChildren(), u.length === 0) {
754
- if (Fe === "static") {
759
+ if (He === "static") {
755
760
  const t = h({
756
761
  textAlign: "center",
757
- color: gt,
762
+ color: ht,
758
763
  padding: "24px 16px",
759
764
  fontSize: "16px",
760
765
  lineHeight: "1.5"
761
766
  });
762
- t.appendChild(De(ze)), I.appendChild(t);
767
+ t.appendChild(ze(Fe)), I.appendChild(t);
763
768
  }
764
769
  } else u.forEach((t, l) => {
765
770
  const S = l === u.length - 1 || u[l + 1].role !== t.role;
@@ -771,10 +776,10 @@ function yn(n, o) {
771
776
  agentBubble: R,
772
777
  followUpEnabled: _t,
773
778
  followUpHandler: It,
774
- isMobile: !!z?.matches
779
+ isMobile: !!M?.matches
775
780
  }));
776
781
  });
777
- for (const t of We) I.appendChild(pn(t));
782
+ for (const t of Ge) I.appendChild(pn(t));
778
783
  if (le) {
779
784
  const t = h({
780
785
  padding: "10px 14px",
@@ -797,21 +802,21 @@ function yn(n, o) {
797
802
  if (t.role === "assistant" && t.status === "IN_PROGRESS") return t;
798
803
  }
799
804
  }
800
- const Ve = (e) => {
805
+ const je = (e) => {
801
806
  P || (P = e.conversationId);
802
- }, je = (e) => {
807
+ }, qe = (e) => {
803
808
  const t = $t();
804
809
  t && (t.content += e.content, $());
805
- }, qe = (e) => {
806
- const t = u.findIndex((l) => l.id === e.id || l.role === "assistant" && l.status === "IN_PROGRESS");
807
- t >= 0 ? u[t] = e : u.push(e), $(), ge();
808
810
  }, Ke = (e) => {
811
+ const t = u.findIndex((l) => l.id === e.id || l.role === "assistant" && l.status === "IN_PROGRESS");
812
+ t >= 0 ? u[t] = e : u.push(e), $(), he();
813
+ }, Xe = (e) => {
809
814
  const t = u.findIndex((l) => l.id === e.id || l.role === "assistant" && l.status === "IN_PROGRESS");
810
815
  t >= 0 ? u[t] = e : u.push(e), Z = !1, $(), e.status === "DONE" && k?.({
811
816
  id: e.id,
812
817
  content: e.content
813
818
  });
814
- }, Xe = (e) => {
819
+ }, Qe = (e) => {
815
820
  le = e.error, Z = !1, u = u.filter((t) => !t.id.startsWith("temp-")), $();
816
821
  };
817
822
  function Lt(e) {
@@ -826,37 +831,37 @@ function yn(n, o) {
826
831
  u.push(t), $();
827
832
  const l = e.match(/\S+\s*/g) ?? [e];
828
833
  let S = 0;
829
- q = setInterval(() => {
834
+ K = setInterval(() => {
830
835
  if (S >= l.length) {
831
- clearInterval(q), q = void 0, t.status = "DONE", He && (t.followUpReplies = He), $();
836
+ clearInterval(K), K = void 0, t.status = "DONE", Pe && (t.followUpReplies = Pe), $();
832
837
  return;
833
838
  }
834
839
  t.content += l[S], S++, $();
835
- }, wt);
840
+ }, Ct);
836
841
  }
837
- E.on("message:start", Ve), E.on("message:chunk", je), E.on("message:answer-complete", qe), E.on("message:complete", Ke), E.on("message:error", Xe);
838
- const Qe = (e) => G?.(e), Ye = (e) => V?.(e);
839
- G && E.on("form:submitted", Qe), V && E.on("form:error", Ye);
840
- const Ie = [];
841
- let Ze = !1;
842
- const Je = (e) => {
843
- if (Ze) return;
844
- Ie.push(e.install(E));
842
+ E.on("message:start", je), E.on("message:chunk", qe), E.on("message:answer-complete", Ke), E.on("message:complete", Xe), E.on("message:error", Qe);
843
+ const Ye = (e) => V?.(e), Ze = (e) => j?.(e);
844
+ V && E.on("form:submitted", Ye), j && E.on("form:error", Ze);
845
+ const Le = [];
846
+ let Je = !1;
847
+ const et = (e) => {
848
+ if (Je) return;
849
+ Le.push(e.install(E));
845
850
  let t = e.store.get().submitted;
846
851
  const l = e.store.subscribe((S) => {
847
- S.submitted && !t && (We.push(kt(S.submitResult)), $()), t = S.submitted;
852
+ S.submitted && !t && (Ge.push(kt(S.submitResult)), $()), t = S.submitted;
848
853
  });
849
- Ie.push(l);
854
+ Le.push(l);
850
855
  };
851
- for (const e of s ?? []) e.schema != null ? Je(Xt(e)) : Kt(E, e).then((t) => Je(t)).catch(() => {
856
+ for (const e of s ?? []) e.schema != null ? et(Xt(e)) : Kt(E, e).then((t) => et(t)).catch(() => {
852
857
  });
853
- async function $e(e, t) {
858
+ async function ye(e, t) {
854
859
  const l = e.trim();
855
860
  if (!l && !t?.length || Z) return;
856
- if (T?.(l), Z = !0, le = null, q) {
857
- clearInterval(q), q = void 0;
858
- const w = u.find((W) => W.id.startsWith("ago-intro-"));
859
- w && !w.content ? u = u.filter((W) => W !== w) : w && (w.status = "DONE");
861
+ if (T?.(l), Z = !0, le = null, K) {
862
+ clearInterval(K), K = void 0;
863
+ const w = u.find((G) => G.id.startsWith("ago-intro-"));
864
+ w && !w.content ? u = u.filter((G) => G !== w) : w && (w.status = "DONE");
860
865
  }
861
866
  const S = Date.now();
862
867
  u.push({
@@ -880,83 +885,83 @@ function yn(n, o) {
880
885
  conversationId: P,
881
886
  files: t
882
887
  });
883
- w.conversationId && (P || (P = w.conversationId), ue?.setActiveThread(w.conversationId, w.createdAt));
884
- const W = u.find((Q) => Q.id === `temp-user-${S}`);
885
- if (W && (W.id = `user-${S}`, W.conversationId = w.conversationId), !u.some((Q) => Q.id === w.id)) {
888
+ w.conversationId && (P || (P = w.conversationId), me?.setActiveThread(w.conversationId, w.createdAt));
889
+ const G = u.find((Q) => Q.id === `temp-user-${S}`);
890
+ if (G && (G.id = `user-${S}`, G.conversationId = w.conversationId), !u.some((Q) => Q.id === w.id)) {
886
891
  const Q = u.findIndex((Pt) => Pt.id === `temp-assistant-${S}`);
887
892
  Q >= 0 ? u[Q] = w : u.push(w);
888
893
  }
889
- u = u.filter((Q) => !Q.id.startsWith("temp-")), Z = !1, $(), g && Le();
894
+ u = u.filter((Q) => !Q.id.startsWith("temp-")), Z = !1, $(), g && Ne();
890
895
  } catch (w) {
891
- le = w instanceof Error ? w.message : "Failed to send message", Z = !1, u = u.filter((W) => !W.id.startsWith("temp-")), $();
896
+ le = w instanceof Error ? w.message : "Failed to send message", Z = !1, u = u.filter((G) => !G.id.startsWith("temp-")), $();
892
897
  }
893
898
  }
894
- async function Le() {
899
+ async function Ne() {
895
900
  try {
896
901
  const e = await E.getConversations();
897
- me.splice(0, me.length, ...e);
902
+ ge.splice(0, ge.length, ...e);
898
903
  } catch {
899
904
  }
900
- return me;
905
+ return ge;
901
906
  }
902
907
  async function Nt(e) {
903
908
  try {
904
909
  const t = (await E.getConversation(e))?.messages ?? [];
905
910
  t.length > 0 && u.length === 0 && (u = t, $());
906
911
  } catch {
907
- u.length === 0 && (ue?.clear(), P = void 0);
912
+ u.length === 0 && (me?.clear(), P = void 0);
908
913
  }
909
914
  }
910
- return $(), se && z?.matches || ge(), P ? Nt(P) : Fe === "streaming" && Lt(ze), g && Le(), {
915
+ return $(), re && M?.matches || he(), P ? Nt(P) : He === "streaming" && Lt(Fe), g && Ne(), {
911
916
  client: E,
912
- element: he,
913
- sendMessage: $e,
914
- ...D || se ? {
917
+ element: xe,
918
+ sendMessage: ye,
919
+ ...z || re ? {
915
920
  open: Bt,
916
921
  close: Mt,
917
922
  toggle: Ot
918
923
  } : {},
919
- session: ue,
920
- threads: me,
921
- refreshThreads: Le,
924
+ session: me,
925
+ threads: ge,
926
+ refreshThreads: Ne,
922
927
  destroy() {
923
- q && clearInterval(q), E.off("message:start", Ve), E.off("message:chunk", je), E.off("message:answer-complete", qe), E.off("message:complete", Ke), E.off("message:error", Xe), G && E.off("form:submitted", Qe), V && E.off("form:error", Ye), Ze = !0, Ie.forEach((e) => e()), he.remove(), N?.remove(), H?.remove(), pe?.remove(), X?.remove(), z?.removeEventListener("change", tt), se && (document.removeEventListener("keydown", et), rt(), document.documentElement.style.removeProperty("overflow")), o.client || E.destroy();
928
+ K && clearInterval(K), E.off("message:start", je), E.off("message:chunk", qe), E.off("message:answer-complete", Ke), E.off("message:complete", Xe), E.off("message:error", Qe), V && E.off("form:submitted", Ye), j && E.off("form:error", Ze), Je = !0, Le.forEach((e) => e()), xe.remove(), N?.remove(), H?.remove(), pe?.remove(), X?.remove(), M?.removeEventListener("change", nt), re && (document.removeEventListener("keydown", tt), it(), document.documentElement.style.removeProperty("overflow")), o.client || E.destroy();
924
929
  }
925
930
  };
926
- function ve() {
931
+ function we() {
927
932
  if (!U) return;
928
933
  {
929
- const t = xe === "left" ? "border-right" : "border-left";
930
- z?.matches ? (U.style.width = "100%", d.style.borderRadius = "0", d.style.removeProperty(t)) : (U.style.width = typeof x == "number" ? `${x}px` : x, d.style.setProperty(t, `1px solid ${L}`));
934
+ const t = be === "left" ? "border-right" : "border-left";
935
+ M?.matches ? (U.style.width = "100%", d.style.borderRadius = "0", d.style.removeProperty(t)) : (U.style.width = typeof x == "number" ? `${x}px` : x, d.style.setProperty(t, `1px solid ${L}`));
931
936
  }
932
937
  const e = m === "left" ? "translateX(-100%)" : "translateX(100%)";
933
938
  U.style.transform = oe ? "translateX(0)" : e, U.setAttribute("aria-hidden", oe ? "false" : "true"), N && (N.style.display = oe ? "none" : "flex");
934
939
  }
935
- function Ne() {
936
- oe = !0, ve(), ge(), B?.();
937
- }
938
940
  function Te() {
939
- oe = !1, ve(), j?.();
941
+ oe = !0, we(), he(), B?.();
942
+ }
943
+ function Be() {
944
+ oe = !1, we(), q?.();
940
945
  }
941
946
  function Tt() {
942
- oe ? Te() : Ne();
947
+ oe ? Be() : Te();
943
948
  }
944
949
  function Bt() {
945
- D ? Ne() : we();
950
+ z ? Te() : fe();
946
951
  }
947
952
  function Mt() {
948
- D ? Te() : fe();
953
+ z ? Be() : ue();
949
954
  }
950
955
  function Ot() {
951
- D ? Tt() : K ? fe() : we();
956
+ z ? Tt() : W ? ue() : fe();
952
957
  }
953
958
  function Dt() {
954
959
  return Array.from(d.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter((e) => e.getClientRects().length > 0);
955
960
  }
956
- function et(e) {
957
- if (!K) return;
961
+ function tt(e) {
962
+ if (!W) return;
958
963
  if (e.key === "Escape") {
959
- fe();
964
+ ue();
960
965
  return;
961
966
  }
962
967
  if (e.key !== "Tab") return;
@@ -968,28 +973,28 @@ function yn(n, o) {
968
973
  const l = t[0], S = t[t.length - 1], w = document.activeElement;
969
974
  e.shiftKey && (w === l || !d.contains(w)) ? (e.preventDefault(), S.focus()) : !e.shiftKey && (w === S || !d.contains(w)) && (e.preventDefault(), l.focus());
970
975
  }
971
- function tt(e) {
972
- D ? ve() : !e.matches && K && fe(), $();
976
+ function nt(e) {
977
+ z ? we() : !e.matches && W && ue(), $();
973
978
  }
974
- function nt() {
979
+ function ot() {
975
980
  return window.visualViewport?.height ?? window.innerHeight;
976
981
  }
977
- function ot() {
982
+ function rt() {
978
983
  const e = window.visualViewport, t = e?.offsetTop ?? 0, l = e?.height ?? ce, S = Math.min(0, t + l - ce);
979
984
  d.style.top = `${S}px`, H && (H.style.top = `${t}px`);
980
985
  }
981
- function ye() {
982
- re || (re = requestAnimationFrame(() => {
983
- re = 0, ot();
986
+ function Ce() {
987
+ ie || (ie = requestAnimationFrame(() => {
988
+ ie = 0, rt();
984
989
  }));
985
990
  }
986
991
  function zt() {
987
- window.visualViewport?.addEventListener("resize", ye), window.visualViewport?.addEventListener("scroll", ye);
988
- }
989
- function rt() {
990
- window.visualViewport?.removeEventListener("resize", ye), window.visualViewport?.removeEventListener("scroll", ye), re && (cancelAnimationFrame(re), re = 0);
992
+ window.visualViewport?.addEventListener("resize", Ce), window.visualViewport?.addEventListener("scroll", Ce);
991
993
  }
992
994
  function it() {
995
+ window.visualViewport?.removeEventListener("resize", Ce), window.visualViewport?.removeEventListener("scroll", Ce), ie && (cancelAnimationFrame(ie), ie = 0);
996
+ }
997
+ function at() {
993
998
  I.scrollTop = I.scrollHeight;
994
999
  }
995
1000
  function Ft() {
@@ -998,7 +1003,7 @@ function yn(n, o) {
998
1003
  top: "0",
999
1004
  left: "0",
1000
1005
  right: "0",
1001
- height: `calc(${Ge}px + env(safe-area-inset-top))`,
1006
+ height: `calc(${Ve}px + env(safe-area-inset-top))`,
1002
1007
  display: "none",
1003
1008
  alignItems: "center",
1004
1009
  justifyContent: "space-between",
@@ -1006,7 +1011,7 @@ function yn(n, o) {
1006
1011
  backgroundColor: ee,
1007
1012
  borderBottom: `1px solid ${L}`,
1008
1013
  zIndex: "2147483001",
1009
- fontFamily: Ee
1014
+ fontFamily: Se
1010
1015
  });
1011
1016
  if (e.className = "ago-chat-widget-mobile-bar", f) {
1012
1017
  const l = document.createElement("img");
@@ -1035,13 +1040,13 @@ function yn(n, o) {
1035
1040
  cursor: "pointer",
1036
1041
  padding: "4px 8px"
1037
1042
  }), t.addEventListener("click", () => {
1038
- fe();
1043
+ ue();
1039
1044
  }), e.appendChild(t), e;
1040
1045
  }
1041
1046
  function Ht() {
1042
- return typeof document.startViewTransition == "function" && !Rt?.matches && !!z?.matches;
1047
+ return typeof document.startViewTransition == "function" && !Rt?.matches && !!M?.matches;
1043
1048
  }
1044
- function at(e) {
1049
+ function st(e) {
1045
1050
  const t = document;
1046
1051
  if (Ht() && t.startViewTransition) {
1047
1052
  d.style.setProperty("view-transition-name", de), H?.style.setProperty("view-transition-name", `${de}-bar`);
@@ -1052,7 +1057,7 @@ function yn(n, o) {
1052
1057
  }
1053
1058
  return e(), Promise.resolve();
1054
1059
  }
1055
- function st(e) {
1060
+ function lt(e) {
1056
1061
  if (e)
1057
1062
  X && d.parentElement?.insertBefore(X, d), v(d, {
1058
1063
  position: "fixed",
@@ -1065,7 +1070,7 @@ function yn(n, o) {
1065
1070
  border: "none",
1066
1071
  borderRadius: "0",
1067
1072
  boxShadow: "none",
1068
- paddingTop: `calc(${Ge}px + env(safe-area-inset-top))`,
1073
+ paddingTop: `calc(${Ve}px + env(safe-area-inset-top))`,
1069
1074
  paddingBottom: "env(safe-area-inset-bottom)"
1070
1075
  }), d.setAttribute("role", "dialog"), d.setAttribute("aria-modal", "true"), d.setAttribute("aria-label", i), document.documentElement.style.overflow = "hidden", F && (F.style.display = "none"), H && (H.style.display = "flex");
1071
1076
  else {
@@ -1080,30 +1085,30 @@ function yn(n, o) {
1080
1085
  "padding-top",
1081
1086
  "padding-bottom"
1082
1087
  ]) d.style.removeProperty(t);
1083
- d.style.height = be.height, d.style.border = be.border, d.style.borderRadius = be.borderRadius, d.style.boxShadow = be.boxShadow, d.removeAttribute("role"), d.removeAttribute("aria-modal"), d.removeAttribute("aria-label"), document.documentElement.style.removeProperty("overflow"), F && (F.style.display = "flex"), H && (H.style.display = "none");
1088
+ d.style.height = ve.height, d.style.border = ve.border, d.style.borderRadius = ve.borderRadius, d.style.boxShadow = ve.boxShadow, d.removeAttribute("role"), d.removeAttribute("aria-modal"), d.removeAttribute("aria-label"), document.documentElement.style.removeProperty("overflow"), F && (F.style.display = "flex"), H && (H.style.display = "none");
1084
1089
  }
1085
1090
  }
1086
- function we() {
1087
- if (K || !z?.matches) return Promise.resolve();
1091
+ function fe() {
1092
+ if (W || !M?.matches) return Promise.resolve();
1088
1093
  const e = d.getBoundingClientRect();
1089
- if (e.height >= nt() * 0.8) return Promise.resolve();
1090
- K = !0, X = h({
1094
+ if (e.height >= ot() * 0.8) return Promise.resolve();
1095
+ W = !0, X = h({
1091
1096
  width: `${e.width}px`,
1092
1097
  height: `${e.height}px`
1093
- }), X.className = "ago-chat-widget-spacer", X.setAttribute("aria-hidden", "true"), ce = nt(), d.style.setProperty("--ago-vh", `${ce}px`), ot(), zt();
1094
- const t = at(() => st(!0));
1098
+ }), X.className = "ago-chat-widget-spacer", X.setAttribute("aria-hidden", "true"), ce = ot(), d.style.setProperty("--ago-vh", `${ce}px`), rt(), zt();
1099
+ const t = st(() => lt(!0));
1095
1100
  return t.then(() => {
1096
- it(), ge();
1097
- }), it(), B?.(), t;
1101
+ at(), he();
1102
+ }), at(), B?.(), t;
1098
1103
  }
1099
- function fe() {
1100
- if (!K) return Promise.resolve();
1101
- K = !1, rt(), d.querySelector("textarea")?.blur();
1102
- const e = at(() => st(!1));
1103
- return e.then(() => d.style.removeProperty("--ago-vh")), ce = 0, j?.(), e;
1104
+ function ue() {
1105
+ if (!W) return Promise.resolve();
1106
+ W = !1, it(), d.querySelector("textarea")?.blur();
1107
+ const e = st(() => lt(!1));
1108
+ return e.then(() => d.style.removeProperty("--ago-vh")), ce = 0, q?.(), e;
1104
1109
  }
1105
1110
  }
1106
1111
  export {
1107
- yn as mountChatWidget,
1108
- De as renderMarkdown
1112
+ wn as mountChatWidget,
1113
+ ze as renderMarkdown
1109
1114
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useago/sdk",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Create In-APP AI agents that answers question and performs actions. Works with React, Vue, Angular and vanilla JS/TS.",
5
5
  "type": "module",
6
6
  "sideEffects": false,