@useago/sdk 1.7.2 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/README.md +43 -1
  3. package/dist/angular.cjs +1 -1
  4. package/dist/angular.d.cts +89 -5
  5. package/dist/angular.d.ts +89 -5
  6. package/dist/angular.js +11 -7
  7. package/dist/{createConversationSession-DP90nY71.js → createConversationSession-BaaXBQ5b.js} +3 -3
  8. package/dist/createConversationSession-CU0b-t1W.cjs +1 -0
  9. package/dist/{createFormCollector-BivHRIAe.js → createFormCollector-Cf7kGhCB.js} +1 -1
  10. package/dist/createFormCollector-DfN1xZBy.cjs +1 -0
  11. package/dist/{createMockClient-BDLW6tVc.js → createMockClient-5YF-ZbVu.js} +22 -21
  12. package/dist/createMockClient-BZbOe-23.cjs +1 -0
  13. package/dist/devtools.cjs +61 -12
  14. package/dist/devtools.d.cts +90 -5
  15. package/dist/devtools.d.ts +90 -5
  16. package/dist/devtools.js +225 -73
  17. package/dist/errors-BLfjXnLB.js +32 -0
  18. package/dist/errors-o1IB5fEu.cjs +1 -0
  19. package/dist/index.cjs +1 -1
  20. package/dist/index.d.cts +100 -3
  21. package/dist/index.d.ts +100 -3
  22. package/dist/index.js +77 -75
  23. package/dist/react.cjs +4 -4
  24. package/dist/react.d.cts +197 -3
  25. package/dist/react.d.ts +197 -3
  26. package/dist/react.js +1034 -752
  27. package/dist/testing.cjs +1 -1
  28. package/dist/testing.d.cts +80 -3
  29. package/dist/testing.d.ts +80 -3
  30. package/dist/testing.js +1 -1
  31. package/dist/{AgoClient-DTkBRGFE.js → types-CPga11Of.js} +489 -386
  32. package/dist/types-D3YQl1jx.cjs +9 -0
  33. package/dist/vue.cjs +1 -1
  34. package/dist/vue.d.cts +110 -3
  35. package/dist/vue.d.ts +110 -3
  36. package/dist/vue.js +202 -154
  37. package/dist/widget.cjs +4 -4
  38. package/dist/widget.d.cts +148 -3
  39. package/dist/widget.d.ts +148 -3
  40. package/dist/widget.js +871 -651
  41. package/llms-full.txt +139 -25
  42. package/package.json +1 -1
  43. package/dist/AgoClient-7yXQ6R3O.cjs +0 -9
  44. package/dist/createConversationSession-Bv6a15E0.cjs +0 -1
  45. package/dist/createFormCollector-CwfiYn0V.cjs +0 -1
  46. package/dist/createMockClient-BSNuN3ys.cjs +0 -1
package/dist/widget.cjs CHANGED
@@ -1,5 +1,5 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ae=require("./AgoClient-7yXQ6R3O.cjs"),en=require("./createConversationSession-Bv6a15E0.cjs"),Ct=require("./createFormCollector-CwfiYn0V.cjs"),t=require("./sheetController-DY-sC13T.cjs");function tn(o){let i=[];const s=document.createElement("form");t.css(s,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${t.BORDER_COLOR}`,backgroundColor:t.PANEL_BACKGROUND}),s.className="ago-chat-input";const r=t.div({display:"flex",flexWrap:"wrap",gap:"6px"}),C=t.div({display:"flex",gap:"8px",alignItems:"flex-end"}),a=document.createElement("textarea");a.placeholder=o.placeholder,a.setAttribute("aria-label",o.placeholder),a.rows=1,t.css(a,{flex:"1",resize:"none",boxSizing:"border-box",padding:"10px 12px",border:`1px solid ${t.BORDER_COLOR}`,borderRadius:"12px",fontSize:"16px",fontFamily:t.FONT_VAR,lineHeight:"1.4",maxHeight:"110px",overflowY:"hidden"});const _=()=>{a.style.height="auto";const g=Math.min(a.scrollHeight+2,110);a.style.height=`${g}px`,a.style.overflowY=a.scrollHeight+2>110?"auto":"hidden"};a.addEventListener("input",()=>{_(),H()});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>',y='<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>',u='<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><rect x="5" y="5" width="14" height="14" rx="2"/></svg>',p=document.createElement("button");p.type="submit",p.setAttribute("aria-label","Send"),p.innerHTML=m,t.css(p,{flexShrink:"0",width:"44px",height:"44px",padding:"0",border:"none",borderRadius:"50%",backgroundColor:t.BRAND_COLOR,color:t.BRAND_TEXT_COLOR,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer"});let R=!1;const M=()=>R&&!!o.onStop,H=()=>{const c=a.value.trim()!==""||i.length>0,g=M(),A=!g&&(R||!c);p.disabled=A,p.type=g?"button":"submit",p.setAttribute("aria-label",g?"Stop generating":"Send"),p.innerHTML=g?u:R?y:m,p.style.opacity=A&&!R?"0.5":"1",p.style.cursor=A?"default":"pointer"};p.addEventListener("click",()=>{M()&&o.onStop?.()});let B=null,O=null;o.allowFiles&&(B=document.createElement("input"),B.type="file",B.multiple=!0,t.css(B,{display:"none"}),O=document.createElement("button"),O.type="button",O.setAttribute("aria-label","Attach file"),O.textContent="📎",t.css(O,{flexShrink:"0",minWidth:"44px",minHeight:"44px",display:"flex",alignItems:"center",justifyContent:"center",padding:"0 12px",border:`1px solid ${t.BORDER_COLOR}`,borderRadius:"12px",backgroundColor:t.PANEL_BACKGROUND,cursor:"pointer",fontSize:"14px"}),O.addEventListener("click",()=>B?.click()),B.addEventListener("change",()=>{i=[...i,...Array.from(B?.files??[])],h()}));function h(){r.replaceChildren(),i.forEach((c,g)=>{const A=t.div({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${t.BORDER_COLOR}`,borderRadius:"8px",fontSize:"12px"}),q=document.createElement("span");q.textContent=c.name;const D=document.createElement("button");D.type="button",D.setAttribute("aria-label",`Remove ${c.name}`),D.textContent="×",t.css(D,{flexShrink:"0",width:"44px",height:"44px",margin:"-14px -12px -14px -4px",display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),D.addEventListener("click",()=>{i=i.filter((N,G)=>G!==g),h()}),A.append(q,D),r.appendChild(A)}),H()}const x=()=>{const c=a.value,g=i;return a.value="",_(),i=[],h(),{content:c,files:g}},v=()=>{const{content:c,files:g}=x();(c.trim()||g.length>0)&&o.onSend(c.trim(),g.length>0?g:void 0)};return s.addEventListener("submit",c=>{c.preventDefault(),v()}),a.addEventListener("keydown",c=>{c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),v())}),O&&C.appendChild(O),C.append(a,p),B&&s.appendChild(B),s.append(r,C),H(),{inputRow:s,getValueAndClear:x,setDisabled:c=>{a.disabled=c,R=c,H()},focus:()=>a.focus(),restoreDraft:(c,g)=>{c&&!a.value.trim()&&(a.value=c,_()),g?.length&&(i=[...g,...i],h()),H()}}}var nn={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function se(o){return o.replace(/[&<>"']/g,i=>nn[i])}function yt(o){const i=o.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(i)||!/^[a-z][a-z0-9+.-]*:/i.test(i)?i:null}var Rt='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',Oe="";function ee(o){const i=[],s=C=>(i.push(C),`${Oe}${i.length-1}${Oe}`);let r=o;return r=r.replace(/`([^`]+)`/g,(C,a)=>s(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${Rt}">${se(a)}</code>`)),r=r.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(C,a,_)=>{const m=yt(_);return m?s(`<img alt="${se(a)}" src="${se(m)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):C}),r=r.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(C,a,_)=>{const m=yt(_);return m?s(`<a href="${se(m)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${ee(a)}</a>`):C}),r=se(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(`${Oe}(\\d+)${Oe}`,"g"),(C,a)=>i[Number(a)]),r}function U(o,i,s){const r=document.createElement(o);return Object.assign(r.style,i),s!==void 0&&(r.innerHTML=s),r}var St=/^ {0,3}([-*_])( *\1){2,} *$/,_t=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,Ot=/^ {0,3}(```+|~~~+)/,Ae=/^ {0,3}>\s?/,le=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,on=["20px","18px","16px","15px","14px","13px"],Xe=o=>o.match(/^\s*/)?.[0].length??0;function rn(o){return o.trim()===""||St.test(o)||_t.test(o)||Ot.test(o)||Ae.test(o)||le.test(o)}function At(o){const i=o[0].match(le),s=i[1].length,r=/\d/.test(i[2]),C=U(r?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:r?"decimal":"disc",listStylePosition:"outside"});let a=0;for(;a<o.length;){const _=o[a].match(le),m=[];for(a++;a<o.length&&Xe(o[a])>s;)m.push(o[a]),a++;const y=U("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),u=_[3].match(/^\[([ xX])\]\s+(.*)$/);u?(y.style.listStyleType="none",y.style.marginLeft="-20px",y.innerHTML=`<span style="margin-right:6px">${u[1].toLowerCase()==="x"?"☑":"☐"}</span>${ee(u[2])}`):y.innerHTML=ee(_[3]),m.filter(p=>le.test(p)).length>0&&y.appendChild(At(m.filter(p=>p.trim()!==""))),C.appendChild(y)}return C}function sn(o){const i=m=>m.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(y=>y.trim()),s=U("div",{overflowX:"auto",margin:"0 0 8px 0"}),r=U("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),C=document.createElement("thead"),a=document.createElement("tr");for(const m of i(o[0]))a.appendChild(U("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},ee(m)));C.appendChild(a),r.appendChild(C);const _=document.createElement("tbody");for(const m of o.slice(2)){const y=document.createElement("tr");for(const u of i(m))y.appendChild(U("td",{border:"1px solid #dee3e8",padding:"6px 10px"},ee(u)));_.appendChild(y)}return r.appendChild(_),s.appendChild(r),s}var an=o=>!!o&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(o);function Le(o){const i=document.createDocumentFragment(),s=o.replace(/\r\n?/g,`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const de=require("./types-D3YQl1jx.cjs"),dn=require("./errors-o1IB5fEu.cjs"),cn=require("./createConversationSession-CU0b-t1W.cjs"),_t=require("./createFormCollector-DfN1xZBy.cjs"),e=require("./sheetController-DY-sC13T.cjs");function pn(i){let n=[];const s=document.createElement("form");e.css(s,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${e.BORDER_COLOR}`,backgroundColor:e.PANEL_BACKGROUND}),s.className="ago-chat-input";const o=e.div({display:"flex",flexWrap:"wrap",gap:"6px"}),h=e.div({display:"flex",gap:"8px",alignItems:"flex-end"}),a=document.createElement("textarea");a.placeholder=i.placeholder,a.setAttribute("aria-label",i.placeholder),a.rows=1,e.css(a,{flex:"1",resize:"none",boxSizing:"border-box",padding:"10px 12px",border:`1px solid ${e.BORDER_COLOR}`,borderRadius:"12px",fontSize:"16px",fontFamily:e.FONT_VAR,lineHeight:"1.4",maxHeight:"110px",overflowY:"hidden"});const x=()=>{a.style.height="auto";const b=Math.min(a.scrollHeight+2,110);a.style.height=`${b}px`,a.style.overflowY=a.scrollHeight+2>110?"auto":"hidden"};a.addEventListener("input",()=>{x(),S()});const u='<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>',C='<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>',c='<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><rect x="5" y="5" width="14" height="14" rx="2"/></svg>',f=document.createElement("button");f.type="submit",f.setAttribute("aria-label","Send"),f.innerHTML=u,e.css(f,{flexShrink:"0",width:"44px",height:"44px",padding:"0",border:"none",borderRadius:"50%",backgroundColor:e.BRAND_COLOR,color:e.BRAND_TEXT_COLOR,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer"});let g=!1;const O=()=>g&&!!i.onStop,S=()=>{const p=a.value.trim()!==""||n.length>0,b=O(),A=!b&&(g||!p);f.disabled=A,f.type=b?"button":"submit",f.setAttribute("aria-label",b?"Stop generating":"Send"),f.innerHTML=b?c:g?C:u,f.style.opacity=A&&!g?"0.5":"1",f.style.cursor=A?"default":"pointer"};f.addEventListener("click",()=>{O()&&i.onStop?.()});let L=null,H=null;i.allowFiles&&(L=document.createElement("input"),L.type="file",L.multiple=!0,e.css(L,{display:"none"}),H=document.createElement("button"),H.type="button",H.setAttribute("aria-label","Attach file"),H.textContent="📎",e.css(H,{flexShrink:"0",minWidth:"44px",minHeight:"44px",display:"flex",alignItems:"center",justifyContent:"center",padding:"0 12px",border:`1px solid ${e.BORDER_COLOR}`,borderRadius:"12px",backgroundColor:e.PANEL_BACKGROUND,cursor:"pointer",fontSize:"14px"}),H.addEventListener("click",()=>L?.click()),L.addEventListener("change",()=>{n=[...n,...Array.from(L?.files??[])],$()}));function $(){o.replaceChildren(),n.forEach((p,b)=>{const A=e.div({display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${e.BORDER_COLOR}`,borderRadius:"8px",fontSize:"12px"}),z=document.createElement("span");z.textContent=p.name;const F=document.createElement("button");F.type="button",F.setAttribute("aria-label",`Remove ${p.name}`),F.textContent="×",e.css(F,{flexShrink:"0",width:"44px",height:"44px",margin:"-14px -12px -14px -4px",display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1"}),F.addEventListener("click",()=>{n=n.filter((Z,k)=>k!==b),$()}),A.append(z,F),o.appendChild(A)}),S()}const E=()=>{const p=a.value,b=n;return a.value="",x(),n=[],$(),{content:p,files:b}},y=()=>{const{content:p,files:b}=E();(p.trim()||b.length>0)&&i.onSend(p.trim(),b.length>0?b:void 0)};return s.addEventListener("submit",p=>{p.preventDefault(),y()}),a.addEventListener("keydown",p=>{p.key==="Enter"&&!p.shiftKey&&(p.preventDefault(),y())}),H&&h.appendChild(H),h.append(a,f),L&&s.appendChild(L),s.append(o,h),S(),{inputRow:s,getValueAndClear:E,setDisabled:p=>{a.disabled=p,g=p,S()},focus:()=>a.focus(),restoreDraft:(p,b)=>{p&&!a.value.trim()&&(a.value=p,x()),b?.length&&(n=[...b,...n],$()),S()}}}var un={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function le(i){return i.replace(/[&<>"']/g,n=>un[n])}function Ot(i){const n=i.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(n)||!/^[a-z][a-z0-9+.-]*:/i.test(n)?n:null}var kt='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',Le="";function te(i){const n=[],s=h=>(n.push(h),`${Le}${n.length-1}${Le}`);let o=i;return o=o.replace(/`([^`]+)`/g,(h,a)=>s(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${kt}">${le(a)}</code>`)),o=o.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(h,a,x)=>{const u=Ot(x);return u?s(`<img alt="${le(a)}" src="${le(u)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):h}),o=o.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(h,a,x)=>{const u=Ot(x);return u?s(`<a href="${le(u)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${te(a)}</a>`):h}),o=le(o),o=o.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>"),o=o.replace(new RegExp(`${Le}(\\d+)${Le}`,"g"),(h,a)=>n[Number(a)]),o}function U(i,n,s){const o=document.createElement(i);return Object.assign(o.style,n),s!==void 0&&(o.innerHTML=s),o}var Tt=/^ {0,3}([-*_])( *\1){2,} *$/,Nt=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,It=/^ {0,3}(```+|~~~+)/,ke=/^ {0,3}>\s?/,ce=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,fn=["20px","18px","16px","15px","14px","13px"],Ke=i=>i.match(/^\s*/)?.[0].length??0;function mn(i){return i.trim()===""||Tt.test(i)||Nt.test(i)||It.test(i)||ke.test(i)||ce.test(i)}function Bt(i){const n=i[0].match(ce),s=n[1].length,o=/\d/.test(n[2]),h=U(o?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:o?"decimal":"disc",listStylePosition:"outside"});let a=0;for(;a<i.length;){const x=i[a].match(ce),u=[];for(a++;a<i.length&&Ke(i[a])>s;)u.push(i[a]),a++;const C=U("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),c=x[3].match(/^\[([ xX])\]\s+(.*)$/);c?(C.style.listStyleType="none",C.style.marginLeft="-20px",C.innerHTML=`<span style="margin-right:6px">${c[1].toLowerCase()==="x"?"☑":"☐"}</span>${te(c[2])}`):C.innerHTML=te(x[3]),u.filter(f=>ce.test(f)).length>0&&C.appendChild(Bt(u.filter(f=>f.trim()!==""))),h.appendChild(C)}return h}function hn(i){const n=u=>u.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(C=>C.trim()),s=U("div",{overflowX:"auto",margin:"0 0 8px 0"}),o=U("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),h=document.createElement("thead"),a=document.createElement("tr");for(const u of n(i[0]))a.appendChild(U("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},te(u)));h.appendChild(a),o.appendChild(h);const x=document.createElement("tbody");for(const u of i.slice(2)){const C=document.createElement("tr");for(const c of n(u))C.appendChild(U("td",{border:"1px solid #dee3e8",padding:"6px 10px"},te(c)));x.appendChild(C)}return o.appendChild(x),s.appendChild(o),s}var gn=i=>!!i&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(i);function Te(i){const n=document.createDocumentFragment(),s=i.replace(/\r\n?/g,`
2
2
  `).split(`
3
- `);let r=0;for(;r<s.length;){const a=s[r];if(a.trim()===""){r++;continue}const _=a.match(Ot);if(_){const u=_[1][0],p=[];for(r++;r<s.length&&!new RegExp(`^ {0,3}${u==="`"?"`{3,}":"~{3,}"}\\s*$`).test(s[r]);)p.push(s[r]),r++;r++;const R=U("pre",{margin:"0 0 8px 0"});R.appendChild(U("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:Rt,whiteSpace:"pre"},se(p.join(`
4
- `)))),i.appendChild(R);continue}if(St.test(a)){i.appendChild(U("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),r++;continue}const m=a.match(_t);if(m){const u=m[1].length;i.appendChild(U(`h${u}`,{margin:"16px 0 8px 0",fontSize:on[u-1],fontWeight:"600",lineHeight:"1.3"},ee(m[2]))),r++;continue}if(Ae.test(a)){const u=[];for(;r<s.length&&Ae.test(s[r]);)u.push(s[r].replace(Ae,"")),r++;const p=U("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});p.appendChild(Le(u.join(`
5
- `))),i.appendChild(p);continue}if(a.includes("|")&&an(s[r+1])){const u=[a,s[r+1]];for(r+=2;r<s.length&&s[r].includes("|")&&s[r].trim();)u.push(s[r]),r++;i.appendChild(sn(u));continue}if(le.test(a)){const u=[],p=Xe(a);for(;r<s.length&&s[r].trim()!=="";)if(le.test(s[r])||Xe(s[r])>p)u.push(s[r]),r++;else break;i.appendChild(At(u));continue}const y=[a];for(r++;r<s.length&&!rn(s[r]);)y.push(s[r]),r++;i.appendChild(U("p",{margin:"0 0 8px 0",lineHeight:"1.6"},y.map(u=>ee(u)).join("<br>")))}const C=i.lastElementChild;return C&&(C.style.marginBottom="0"),i}function wt(o,i){const{isLast:s,isLastOfBlock:r,bubbleStyle:C,showAgentName:a,agentBubble:_,followUpEnabled:m,followUpHandler:y,isMobile:u}=i,p=o.role==="user",R=C==="imessage",M=t.div({display:"flex",flexDirection:"column",alignItems:p?"flex-end":"flex-start",marginBottom:R&&!r?"2px":"16px"});if(M.className=`ago-message ago-message--${o.role}`,!p&&a&&o.agent){const h=t.div({fontSize:"13px",fontWeight:"500",color:t.TEXT_COLOR,marginBottom:"6px",padding:"0 4px"});h.className="ago-message__agent",h.textContent=o.agent.displayName||o.agent.name,M.appendChild(h)}if(!p&&o.sources&&o.sources.length>0){const h=t.div({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});h.className="ago-message__sources",o.sources.forEach((x,v)=>{const c=x.url?document.createElement("a"):document.createElement("div");x.url&&c instanceof HTMLAnchorElement&&(c.href=x.url,c.target="_blank",c.rel="noopener noreferrer"),t.css(c,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${t.BORDER_COLOR}`,borderRadius:"8px",backgroundColor:t.PANEL_BACKGROUND,textDecoration:"none",color:t.TEXT_COLOR,fontSize:"12px",overflow:"hidden"});const g=t.div({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${t.ACCENT_COLOR}`,color:t.ACCENT_COLOR,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});g.textContent=String(v+1);const A=t.div({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});A.textContent=x.title,A.title=x.title,c.append(g,A),h.appendChild(c)}),M.appendChild(h)}if(o.attachments&&o.attachments.length>0){const h=t.div({display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:p?"flex-end":"flex-start",maxWidth:"75%"});h.className="ago-message__attachments";for(const x of o.attachments){const v=ae.safeAttachmentUrl(x.url);if(ae.canInlineImage(x)&&v){const N=document.createElement("a");N.href=v,N.target="_blank",N.rel="noopener noreferrer",t.css(N,{display:"inline-block",textDecoration:"none"});const G=document.createElement("img");G.src=v,G.alt=x.name,G.loading="lazy",t.css(G,{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:`1px solid ${t.BORDER_COLOR}`,display:"block"}),N.appendChild(G),h.appendChild(N);continue}const c=v?document.createElement("a"):document.createElement("div");v&&c instanceof HTMLAnchorElement&&(c.href=v,c.target="_blank",c.rel="noopener noreferrer"),t.css(c,{display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:`1px solid ${t.BORDER_COLOR}`,backgroundColor:p?"rgba(255,255,255,0.12)":t.PANEL_BACKGROUND,color:p?t.BRAND_TEXT_COLOR:t.TEXT_COLOR,fontSize:"13px",textDecoration:"none",maxWidth:"220px"});const g=document.createElement("span");g.textContent="📄",g.setAttribute("aria-hidden","true"),t.css(g,{fontSize:"16px",lineHeight:"1",flexShrink:"0"});const A=t.div({display:"flex",flexDirection:"column",minWidth:"0"}),q=t.div({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"});q.textContent=x.name,q.title=x.name,A.appendChild(q);const D=ae.formatFileSize(x.fileSize);if(D){const N=t.div({fontSize:"11px",color:t.MUTED_TEXT_COLOR});N.textContent=D,A.appendChild(N)}c.append(g,A),h.appendChild(c)}M.appendChild(h)}const H=p||_||R,B=!!o.content||o.status==="IN_PROGRESS"||o.status==="WAITING_CLIENT",O=t.div({maxWidth:H?R||p?u?"88%":"75%":u?"92%":"85%":"100%",padding:H?"10px 14px":"2px 8px",borderRadius:R?t.MESSAGE_RADIUS_IMESSAGE:H?t.MESSAGE_RADIUS:"0",backgroundColor:p?t.BRAND_COLOR:H?t.AGENT_BUBBLE_BACKGROUND:"transparent",color:p?t.BRAND_TEXT_COLOR:t.TEXT_COLOR,overflowWrap:"break-word",textWrap:"pretty",fontSize:"16px",lineHeight:"1.6"});if(O.className="ago-message__content",R&&r){O.style.position="relative";const h=t.div({position:"absolute",zIndex:"0",bottom:"-2px",width:"20px",height:"20px",background:p?t.BRAND_COLOR:t.AGENT_BUBBLE_BACKGROUND});h.className="ago-message__tail";const x=t.div({position:"absolute",zIndex:"1",bottom:"-2px",width:"10px",height:"20px",background:t.MESSAGES_BACKGROUND});x.className="ago-message__tail-mask",p?(h.style.right="-8px",h.style.borderBottomLeftRadius="16px 14px",x.style.right="-10px",x.style.borderBottomLeftRadius="10px"):(h.style.left="-7px",h.style.borderBottomRightRadius="16px 14px",x.style.left="-10px",x.style.borderBottomRightRadius="10px"),O.append(h,x)}if(o.content?O.appendChild(Le(o.content)):(o.status==="IN_PROGRESS"||o.status==="WAITING_CLIENT")&&O.appendChild(dn()),B&&M.appendChild(O),s&&o.followUpReplies&&o.followUpReplies.length>0){const h=t.div({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});h.className="ago-message__followups";for(const x of o.followUpReplies){const v=document.createElement("button");v.type="button",v.className="ago-message__followup-btn",v.textContent=x,v.disabled=!m,t.css(v,{minHeight:"44px",padding:"6px 14px",fontSize:"14px",borderRadius:t.MESSAGE_RADIUS,border:`1px solid ${t.BORDER_COLOR}`,backgroundColor:t.PANEL_BACKGROUND,color:t.TEXT_COLOR,cursor:m?"pointer":"default",transition:"border-color 0.15s"}),y&&v.addEventListener("click",()=>y(x)),v.addEventListener("mouseenter",()=>{v.style.borderColor=t.ACCENT_COLOR}),v.addEventListener("mouseleave",()=>{v.style.borderColor=t.BORDER_COLOR}),h.appendChild(v)}M.appendChild(h)}return M}function ln(o){const i=t.div({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:t.MESSAGE_RADIUS,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});i.className="ago-form-notice",i.setAttribute("role","status");const s=document.createElement("span");s.textContent="✓",s.setAttribute("aria-hidden","true"),t.css(s,{fontWeight:"700"});const r=document.createElement("span");return r.textContent=o,i.append(s,r),i}function dn(){const o=t.div({display:"flex",gap:"4px",padding:"4px 0"});for(let i=0;i<3;i++){const s=t.div({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"currentColor",opacity:"0.55",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${i*.2}s`});o.appendChild(s)}return o}function cn(){const o="http://www.w3.org/2000/svg",i=document.createElementNS(o,"svg");i.setAttribute("width","26"),i.setAttribute("height","26"),i.setAttribute("viewBox","0 0 24 24"),i.setAttribute("fill","none");const s=document.createElementNS(o,"path");return s.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"),s.setAttribute("stroke","currentColor"),s.setAttribute("stroke-width","2"),s.setAttribute("stroke-linecap","round"),s.setAttribute("stroke-linejoin","round"),i.appendChild(s),i}var Et="Form submitted.";function pn(o){if(typeof o=="string")return o||null;if(!o||typeof o!="object")return null;const i=o;if(typeof i.message=="string"&&i.message)return i.message;const s=i.result;if(typeof s=="string"&&s)return s;if(s&&typeof s=="object"){const r=s.message;if(typeof r=="string"&&r)return r}return null}var fn=0;function un(o){const i=typeof o=="string"?document.querySelector(o):o;if(!i)throw new Error(`mountChatWidget: target "${String(o)}" not found.`);return i}function hn(o,i){const{title:s="Chat",welcomeMessage:r="Hello! How can I help you today?",placeholder:C="Type a message...",allowFiles:a=!1,allowStop:_=!0,height:m=500,placement:y="inline",width:u=400,defaultOpen:p=!1,logoUrl:R,showAgentName:M=!1,agentBubble:H=!1,bubbleStyle:B="default",showHeader:O=!0,theme:h,loadThreads:x=!1,forms:v,formSubmittedMessage:c=Et,onFollowUpClick:g,onMessageSent:A,onMessageReceived:q,onFormSubmitted:D,onFormError:N,onOpen:G,onClose:je}=i,te=typeof r=="string"?{message:r,mode:"static"}:r,qe=te.message,Ve=te.mode??"static",Lt="speed"in te&&te.speed||45,Ke="followUpReplies"in te&&te.followUpReplies||void 0;if(!i.client&&!i.config?.baseUrl)throw new ae.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const w=i.client??new ae.AgoClient(i.config),Qe=un(o),L=y==="left"||y==="right",Tt=L&&(i.launcher??!0);let Z=L?p:!0,Te=!1;const kt=i.mobile?.breakpoint??768,ke=i.mobile?.trigger??"tap",Je=typeof window<"u"&&!!window.matchMedia,I=Je?window.matchMedia(`(max-width: ${kt}px), (max-height: 500px) and (orientation: landscape)`):void 0,Nt=Je?window.matchMedia("(prefers-reduced-motion: reduce)"):void 0,It=!!I,de=!L&&!!I,ce=Symbol("ago-scroll-lock");let ne=!1;const Ne=i.persistConversation,me=Ne?en.createConversationSession(Ne===!0?{}:Ne):void 0;let W=i.conversationId??me?.getLastActiveThread()??void 0,f=[],ge=[],X=!1,oe=null,V;const Ie=[];function Bt(e){if(typeof c=="function"){const d=c(e);if(typeof d=="string"&&d)return d}const n=pn(e);return n||(typeof c=="string"?c:Et)}const xe=[],l=t.div({display:"flex",flexDirection:"column",height:L?"100%":typeof m=="number"?`${m}px`:m,border:`1px solid ${t.BORDER_COLOR}`,borderRadius:t.RADIUS,overflow:"hidden",backgroundColor:t.PANEL_BACKGROUND,fontFamily:t.FONT_VAR,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});l.className="ago-chat-widget",t.applyTheme(l,h);let z;if(O){if(z=t.div({padding:"14px 16px",borderBottom:`1px solid ${t.BORDER_COLOR}`,backgroundColor:t.HEADER_BACKGROUND,color:t.HEADER_TEXT_COLOR,display:"flex",alignItems:"center",gap:"10px"}),z.className="ago-chat-widget__header",R){const n=document.createElement("img");n.src=R,n.alt="Logo",t.css(n,{height:"24px",width:"auto"}),z.appendChild(n)}const e=document.createElement("h3");if(e.textContent=s,t.css(e,{margin:"0",fontSize:"15px",fontWeight:"600"}),z.appendChild(e),L){const n=document.createElement("button");n.type="button",n.className="ago-chat-widget__close",n.setAttribute("aria-label","Close"),n.textContent="×",t.css(n,{marginLeft:"auto",flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center",width:"44px",height:"44px",margin:"-10px -10px -10px auto",background:"transparent",border:"none",color:t.HEADER_TEXT_COLOR,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0"}),n.addEventListener("click",()=>Se()),z.appendChild(n)}}const E=t.div({flex:"1",overflow:"auto",overscrollBehavior:"contain",padding:"16px",backgroundColor:t.MESSAGES_BACKGROUND});E.className="ago-chat-widget__messages",E.setAttribute("role","log"),E.setAttribute("aria-live","polite"),E.setAttribute("aria-relevant","additions text"),E.setAttribute("aria-atomic","false");const Dt=48;let ie=!0,Be=0;function be(e){Be++;try{e()}finally{const n=()=>{Be--};typeof queueMicrotask=="function"?queueMicrotask(n):n()}}function $t(){return E.scrollHeight-E.scrollTop-E.clientHeight<=Dt}const K=document.createElement("button");K.type="button",K.className="ago-chat-widget__jump",K.setAttribute("aria-label","Jump to latest message"),K.innerHTML='<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 5v14M19 12l-7 7-7-7"/></svg>',t.css(K,{position:"absolute",left:"50%",bottom:"12px",transform:"translateX(-50%)",width:"44px",height:"44px",display:"none",alignItems:"center",justifyContent:"center",border:`1px solid ${t.BORDER_COLOR}`,borderRadius:"50%",backgroundColor:t.PANEL_BACKGROUND,color:t.TEXT_COLOR,boxShadow:"rgba(15, 15, 15, 0.16) 0px 2px 10px 0px",cursor:"pointer",zIndex:"2"}),K.addEventListener("click",()=>{ie=!0,be(()=>{E.scrollTop=E.scrollHeight}),De()});function De(){K.style.display=ie?"none":"flex"}function $e(){ie&&be(()=>{E.scrollTop=E.scrollHeight}),De()}E.addEventListener("scroll",()=>{Be>0||(ie=$t(),De())});const Ye=t.div({position:"relative",flex:"1",display:"flex",minHeight:"0"});Ye.append(E,K);const{inputRow:Me,setDisabled:Mt,focus:ve,restoreDraft:Ht}=tn({placeholder:C,allowFiles:a,onSend:(e,n)=>{Ee(e,n)},onStop:_?()=>{ft()}:void 0});t.ensureKeyframes(),l.append(...z?[z]:[],Ye,Me);let Ce=l,T,$;const ye=y==="left"?"left":"right";if(L&&(T=t.div({position:"fixed",top:"0",bottom:"0",[ye]:"0",width:typeof u=="number"?`${u}px`:u,maxWidth:"100vw",display:"flex",zIndex:"2147483000",transition:"transform 0.3s ease",boxShadow:"rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"}),T.className="ago-chat-widget-panel",t.css(l,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[ye==="left"?"borderRight":"borderLeft"]:`1px solid ${t.BORDER_COLOR}`}),T.appendChild(l),Ce=T),Tt){if($=document.createElement("button"),$.type="button",$.className="ago-chat-widget-launcher",$.setAttribute("aria-label",`Open ${s}`),t.css($,{position:"fixed",bottom:"20px",[ye]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:t.BRAND_COLOR,color:t.BRAND_TEXT_COLOR,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:t.FONT_VAR}),R){const e=document.createElement("img");e.src=R,e.alt="",t.css(e,{width:"26px",height:"26px",objectFit:"contain"}),$.appendChild(e)}else $.appendChild(cn());$.addEventListener("click",()=>ze())}const pe=de?`ago-vt-${++fn}`:"",Ze=52;let j=!1,Q=0,re=0,P,fe,J;const we={height:l.style.height,border:l.style.border,borderRadius:l.style.borderRadius,boxShadow:l.style.boxShadow};Qe.appendChild(Ce),$&&Qe.appendChild($),Re(),de&&(P=Jt(),l.insertBefore(P,l.firstChild),fe=document.createElement("style"),fe.id=pe,fe.textContent=`::view-transition-group(${pe}),::view-transition-group(${pe}-bar){animation-duration:0.3s;animation-timing-function:cubic-bezier(0.4,0,0.2,1)}`,document.head.appendChild(fe),(ke==="focus"||ke==="tap")&&(l.addEventListener("pointerdown",e=>{if(j||!I?.matches)return;const n=Me.contains(e.target);if(ke==="tap"){if((e.target instanceof Element?e.target:null)?.closest("button,a[href],[role='button']"))return}else if(!n)return;n&&e.preventDefault(),ue()},!0),l.addEventListener("focusin",e=>{I?.matches&&Me.contains(e.target)&&ue()}))),It&&document.addEventListener("keydown",ht),I&&I.addEventListener("change",mt);const Ut=g!==!1,zt=g===!1?void 0:g??(e=>{de&&I?.matches&&!j?ue().then(()=>Ee(e)):Ee(e)});function et(e){const n=f.length-1;return{isLast:e===n,isLastOfBlock:e===n||f[e+1].role!==f[e].role,bubbleStyle:B,showAgentName:M,agentBubble:H,followUpEnabled:Ut,followUpHandler:zt,isMobile:!!I?.matches}}function Pt(){if(oe||Ie.length>0)return!1;const e=f.length-1,n=f[e];if(!n||n.role!=="assistant")return!1;const d=ge[e];if(!d||d.parentNode!==E)return!1;const S=wt(n,et(e));return be(()=>E.replaceChild(S,d)),ge[e]=S,$e(),!0}function k(){be(Ft),$e();const e=f[f.length-1],n=X&&e?.role==="assistant"&&(e.status==="IN_PROGRESS"||e.status==="WAITING_CLIENT");E.setAttribute("aria-busy",n?"true":"false"),Mt(n)}function Ft(){if(E.replaceChildren(),ge=[],f.length===0){if(Ve==="static"){const e=t.div({textAlign:"center",color:t.MUTED_TEXT_COLOR,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});e.appendChild(Le(qe)),E.appendChild(e)}}else f.forEach((e,n)=>{const d=wt(e,et(n));ge[n]=d,E.appendChild(d)});for(const e of Ie)E.appendChild(ln(e));if(oe){const e=t.div({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});e.setAttribute("role","alert"),e.textContent=oe,E.appendChild(e)}}function tt(){for(let e=f.length-1;e>=0;e--){const n=f[e];if(n.role==="assistant"&&(n.status==="IN_PROGRESS"||n.status==="WAITING_CLIENT"))return n}}const nt=e=>{W||(W=e.conversationId)},ot=e=>{const n=tt();n&&(n.content+=e.content,Pt()||k())},it=e=>{const n=f.findIndex(d=>d.id===e.id||d.role==="assistant"&&d.status==="IN_PROGRESS");n>=0?f[n]=e:f.push(e),k(),Pe()||ve()},rt=e=>{const n=f.findIndex(d=>d.id===e.id||d.role==="assistant"&&d.status==="IN_PROGRESS");n>=0?f[n]=e:f.push(e),X=!1,k(),e.status==="DONE"&&q?.({id:e.id,content:e.content})},st=()=>{const e=tt();e&&(e.content?e.status="CANCELED":f=f.filter(n=>n!==e)),X=!1,k()},at=e=>{oe=e.error,X=!1,f=f.filter(n=>!n.id.startsWith("temp-")),k()};function Gt(e){const n={id:`ago-intro-${Date.now()}`,conversationId:"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};f.push(n),k();const d=e.match(/\S+\s*/g)??[e];let S=0;V=setInterval(()=>{if(S>=d.length){clearInterval(V),V=void 0,n.status="DONE",Ke&&(n.followUpReplies=Ke),k();return}n.content+=d[S],S++,k()},Lt)}w.on("message:start",nt),w.on("message:chunk",ot),w.on("message:answer-complete",it),w.on("message:complete",rt),w.on("message:stopped",st),w.on("message:error",at);const lt=e=>D?.(e),dt=e=>N?.(e);D&&w.on("form:submitted",lt),N&&w.on("form:error",dt);const He=[];let ct=!1;const pt=e=>{if(ct)return;He.push(e.install(w));let n=e.store.get().submitted;const d=e.store.subscribe(S=>{S.submitted&&!n&&(Ie.push(Bt(S.submitResult)),k()),n=S.submitted});He.push(d)};for(const e of v??[])e.schema!=null?pt(Ct.createFormCollector(e)):Ct.loadFormCollector(w,e).then(n=>pt(n)).catch(()=>{});async function Ee(e,n){const d=e.trim();if(!d&&!n?.length||X)return;if(A?.(d),X=!0,oe=null,ie=!0,V){clearInterval(V),V=void 0;const b=f.find(F=>F.id.startsWith("ago-intro-"));b&&!b.content?f=f.filter(F=>F!==b):b&&(b.status="DONE")}const S=Date.now();f.push({id:`temp-user-${S}`,conversationId:W||"",content:d,role:"user",status:"DONE",attachments:n&&n.length>0?ae.attachmentsFromFiles(n):void 0,createdAt:new Date}),f.push({id:`temp-assistant-${S}`,conversationId:W||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),k();try{const b=await w.sendMessage(d,{conversationId:W,files:n});b.conversationId&&(W||(W=b.conversationId),me?.setActiveThread(b.conversationId,b.createdAt));const F=f.find(Y=>Y.id===`temp-user-${S}`);if(F&&(F.id=`user-${S}`,F.conversationId=b.conversationId),b.id&&!f.some(Y=>Y.id===b.id)){const Y=f.findIndex(Zt=>Zt.id===`temp-assistant-${S}`);Y>=0?f[Y]=b:f.push(b)}f=f.filter(Y=>!Y.id.startsWith("temp-")),b.status!=="WAITING_CLIENT"&&(X=!1),k(),x&&Ue()}catch(b){oe=b instanceof Error?b.message:"Failed to send message",X=!1,f=f.filter(F=>!F.id.startsWith("temp-")),Ht(d,n),k()}}async function ft(){X&&await w.stop()}async function Ue(){try{const{data:e}=await w.getConversations();xe.splice(0,xe.length,...e)}catch{}return xe}async function Wt(e){try{const n=(await w.getConversation(e))?.messages??[];n.length>0&&f.length===0&&(f=n,k())}catch{f.length===0&&(me?.clear(),W=void 0)}}return k(),de&&I?.matches||ve(),W?Wt(W):Ve==="streaming"&&Gt(qe),x&&Ue(),{client:w,element:Ce,sendMessage:Ee,stop:ft,...L||de?{open:jt,close:qt,toggle:Vt}:{},session:me,threads:xe,refreshThreads:Ue,destroy(){ne||(ne=!0,V&&clearInterval(V),w.off("message:start",nt),w.off("message:chunk",ot),w.off("message:answer-complete",it),w.off("message:complete",rt),w.off("message:stopped",st),w.off("message:error",at),D&&w.off("form:submitted",lt),N&&w.off("form:error",dt),ct=!0,He.forEach(e=>e()),Ce.remove(),$?.remove(),P?.remove(),fe?.remove(),J?.remove(),I?.removeEventListener("change",mt),document.removeEventListener("keydown",ht),We(),Te=!1,t.unlockBackgroundScroll(ce),i.client||w.destroy())}};function Re(){if(!T)return;{const d=ye==="left"?"border-right":"border-left";I?.matches?(T.style.width="100%",l.style.borderRadius="0",l.style.removeProperty(d)):(T.style.width=typeof u=="number"?`${u}px`:u,l.style.setProperty(d,`1px solid ${t.BORDER_COLOR}`))}const e=y==="left"?"translateX(-100%)":"translateX(100%)";T.style.transform=Z?"translateX(0)":e,T.setAttribute("aria-hidden",Z?"false":"true"),$&&($.style.display=Z?"none":"flex");const n=ut();n!==Te&&(Te=n,n?(l.setAttribute("role","dialog"),l.setAttribute("aria-modal","true"),l.setAttribute("aria-label",s),l.tabIndex=-1,l.style.paddingBottom="env(safe-area-inset-bottom)",t.lockBackgroundScroll(ce),Q=Fe(),Ge(),gt()):(We(),Qt(),Q=0,l.removeAttribute("role"),l.removeAttribute("aria-modal"),l.removeAttribute("aria-label"),l.style.removeProperty("padding-bottom"),t.unlockBackgroundScroll(ce)))}function ze(){Z=!0,Re(),Pe()?l.focus({preventScroll:!0}):ve(),G?.()}function Se(){Z=!1,Re(),je?.()}function Xt(){Z?Se():ze()}function jt(){L?ze():ue()}function qt(){L?Se():he()}function Vt(){L?Xt():j?he():ue()}function Pe(){return!!I?.matches}function ut(){return Pe()&&(L?Z:j)}function Kt(){return Array.from(l.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 ht(e){if(!ut())return;if(e.key==="Escape"){L?Se():he();return}if(e.key!=="Tab")return;const n=Kt();if(n.length===0){e.preventDefault();return}const d=n[0],S=n[n.length-1],b=document.activeElement;e.shiftKey&&(b===d||!l.contains(b))?(e.preventDefault(),S.focus()):!e.shiftKey&&(b===S||!l.contains(b))&&(e.preventDefault(),d.focus())}function mt(e){L?Re():!e.matches&&j&&he(),k()}function Fe(){return window.visualViewport?.height??window.innerHeight}function Ge(){const e=window.visualViewport,n=e?.offsetTop??0,d=e?.height??Q;if(L){if(!T)return;const b=window.innerHeight||Q,F=Math.max(0,b-(n+d));T.style.bottom=`${F}px`,T.style.top=`${n}px`;return}const S=Math.min(0,n+d-Q);l.style.top=`${S}px`,P&&(P.style.top=`${n}px`)}function Qt(){L&&T&&(T.style.removeProperty("bottom"),T.style.removeProperty("top"))}function _e(){re||(re=requestAnimationFrame(()=>{re=0,!ne&&Ge()}))}function gt(){window.visualViewport?.addEventListener("resize",_e),window.visualViewport?.addEventListener("scroll",_e)}function We(){window.visualViewport?.removeEventListener("resize",_e),window.visualViewport?.removeEventListener("scroll",_e),re&&(cancelAnimationFrame(re),re=0)}function xt(){ie=!0,$e()}function Jt(){const e=t.div({position:"fixed",top:"0",left:"0",right:"0",height:`calc(${Ze}px + env(safe-area-inset-top))`,display:"none",alignItems:"center",justifyContent:"space-between",padding:"env(safe-area-inset-top) 14px 0",backgroundColor:t.PANEL_BACKGROUND,borderBottom:`1px solid ${t.BORDER_COLOR}`,zIndex:"2147483001",fontFamily:t.FONT_VAR});if(e.className="ago-chat-widget-mobile-bar",R){const d=document.createElement("img");d.src=R,d.alt="",t.css(d,{height:"28px",width:"auto"}),e.appendChild(d)}else if(s){const d=document.createElement("span");d.textContent=s,t.css(d,{fontSize:"15px",fontWeight:"600",color:t.TEXT_COLOR,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"}),e.appendChild(d)}else e.appendChild(t.div({}));const n=document.createElement("button");return n.type="button",n.setAttribute("aria-label","Close"),n.textContent="×",t.css(n,{flexShrink:"0",width:"44px",height:"44px",marginRight:"-10px",display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",fontSize:"26px",lineHeight:"1",color:t.TEXT_COLOR,cursor:"pointer",padding:"0"}),n.addEventListener("click",()=>{he()}),e.appendChild(n),e}function Yt(){return typeof document.startViewTransition=="function"&&!Nt?.matches&&!!I?.matches}function bt(e){const n=document;if(Yt()&&n.startViewTransition){l.style.setProperty("view-transition-name",pe),P?.style.setProperty("view-transition-name",`${pe}-bar`);const d=()=>{l.style.removeProperty("view-transition-name"),P?.style.removeProperty("view-transition-name")};return n.startViewTransition(e).finished.then(d,d)}return e(),Promise.resolve()}function vt(e){if(e)J&&l.parentElement?.insertBefore(J,l),t.css(l,{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(${Ze}px + env(safe-area-inset-top))`,paddingBottom:"env(safe-area-inset-bottom)"}),l.setAttribute("role","dialog"),l.setAttribute("aria-modal","true"),l.setAttribute("aria-label",s),z&&(z.style.display="none"),P&&(P.style.display="flex");else{J?.remove(),J=void 0;for(const n of["position","top","left","right","bottom","z-index","padding-top","padding-bottom"])l.style.removeProperty(n);l.style.height=we.height,l.style.border=we.border,l.style.borderRadius=we.borderRadius,l.style.boxShadow=we.boxShadow,l.removeAttribute("role"),l.removeAttribute("aria-modal"),l.removeAttribute("aria-label"),z&&(z.style.display="flex"),P&&(P.style.display="none")}}function ue(){if(ne||j||!I?.matches)return Promise.resolve();const e=l.getBoundingClientRect();if(e.height>=Fe()*.8)return Promise.resolve();j=!0,J=t.div({width:`${e.width}px`,height:`${e.height}px`}),J.className="ago-chat-widget-spacer",J.setAttribute("aria-hidden","true"),Q=Fe(),l.style.setProperty("--ago-vh",`${Q}px`),Ge(),gt(),t.lockBackgroundScroll(ce);const n=bt(()=>vt(!0));return n.then(()=>{ne||(xt(),ve())}),xt(),G?.(),n}function he(){if(!j)return Promise.resolve();j=!1,We(),t.unlockBackgroundScroll(ce),l.querySelector("textarea")?.blur();const e=bt(()=>vt(!1));return e.then(()=>{ne||l.style.removeProperty("--ago-vh")}),Q=0,je?.(),e}}exports.compactMediaQuery=t.compactMediaQuery;exports.createSheetController=t.createSheetController;exports.mountChatWidget=hn;exports.renderMarkdown=Le;
3
+ `);let o=0;for(;o<s.length;){const a=s[o];if(a.trim()===""){o++;continue}const x=a.match(It);if(x){const c=x[1][0],f=[];for(o++;o<s.length&&!new RegExp(`^ {0,3}${c==="`"?"`{3,}":"~{3,}"}\\s*$`).test(s[o]);)f.push(s[o]),o++;o++;const g=U("pre",{margin:"0 0 8px 0"});g.appendChild(U("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:kt,whiteSpace:"pre"},le(f.join(`
4
+ `)))),n.appendChild(g);continue}if(Tt.test(a)){n.appendChild(U("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),o++;continue}const u=a.match(Nt);if(u){const c=u[1].length;n.appendChild(U(`h${c}`,{margin:"16px 0 8px 0",fontSize:fn[c-1],fontWeight:"600",lineHeight:"1.3"},te(u[2]))),o++;continue}if(ke.test(a)){const c=[];for(;o<s.length&&ke.test(s[o]);)c.push(s[o].replace(ke,"")),o++;const f=U("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});f.appendChild(Te(c.join(`
5
+ `))),n.appendChild(f);continue}if(a.includes("|")&&gn(s[o+1])){const c=[a,s[o+1]];for(o+=2;o<s.length&&s[o].includes("|")&&s[o].trim();)c.push(s[o]),o++;n.appendChild(hn(c));continue}if(ce.test(a)){const c=[],f=Ke(a);for(;o<s.length&&s[o].trim()!=="";)if(ce.test(s[o])||Ke(s[o])>f)c.push(s[o]),o++;else break;n.appendChild(Bt(c));continue}const C=[a];for(o++;o<s.length&&!mn(s[o]);)C.push(s[o]),o++;n.appendChild(U("p",{margin:"0 0 8px 0",lineHeight:"1.6"},C.map(c=>te(c)).join("<br>")))}const h=n.lastElementChild;return h&&(h.style.marginBottom="0"),n}var qe={helpful:"Helpful",notHelpful:"Not helpful",whatWentWrong:"What went wrong?",reasons:{inaccurate:"Inaccurate",incomplete:"Incomplete",information_not_found:"Information not found",technical_issue:"Technical issue"},commentPlaceholder:"Anything else? (optional)",send:"Send",thanks:"Thanks, this was reported."};function bn(){return{detailsOpen:!1,reasons:new Set,comment:"",reported:!1}}var xn={display:"inline-flex",alignItems:"center",justifyContent:"center",width:"44px",height:"44px",margin:"-8px",padding:"0",border:"none",borderRadius:"8px",background:"transparent",color:e.MUTED_TEXT_COLOR,cursor:"pointer",lineHeight:"1"};function Cn(i){const{state:n,labels:s,askWhy:o,onRate:h,onReport:a}=i,x=e.div({marginTop:"6px",width:"100%",maxWidth:"85%"});x.className="ago-feedback";const u=e.div({display:"flex",alignItems:"center",gap:"2px"});u.className="ago-feedback__actions";const C=St("up",s.helpful,n.rating==="positive");C.addEventListener("click",()=>{n.rating="positive",n.detailsOpen=!1,g(),O(),h("positive")});const c=St("down",s.notHelpful,n.rating==="negative");c.addEventListener("click",()=>{n.rating="negative",h("negative"),o&&!n.reported&&(n.detailsOpen=!0),g(),O()}),u.append(C,c),x.appendChild(u);const f=e.div();f.className="ago-feedback__panel-slot",x.appendChild(f);function g(){Ve(C,n.rating==="positive"),Ve(c,n.rating==="negative")}function O(){if(f.replaceChildren(),n.reported){f.appendChild(wn(s.thanks));return}n.detailsOpen&&f.appendChild(En(n,s,async S=>await a(n.rating??"negative",S)?(n.reported=!0,n.detailsOpen=!1,O(),!0):!1))}return g(),O(),x}function St(i,n,s){const o=document.createElement("button");return o.type="button",o.className=`ago-feedback__thumb ago-feedback__thumb--${i}`,o.setAttribute("aria-label",n),o.title=n,e.css(o,xn),o.appendChild(vn(i)),Ve(o,s),o.addEventListener("mouseenter",()=>{o.getAttribute("aria-pressed")!=="true"&&(o.style.color=e.TEXT_COLOR)}),o.addEventListener("mouseleave",()=>{o.getAttribute("aria-pressed")!=="true"&&(o.style.color=e.MUTED_TEXT_COLOR)}),o}function Ve(i,n){i.setAttribute("aria-pressed",n?"true":"false"),i.style.color=n?e.ACCENT_COLOR:e.MUTED_TEXT_COLOR}function vn(i){const n="http://www.w3.org/2000/svg",s=document.createElementNS(n,"svg");s.setAttribute("width","16"),s.setAttribute("height","16"),s.setAttribute("viewBox","0 0 24 24"),s.setAttribute("fill","none"),s.setAttribute("aria-hidden","true");const o=document.createElementNS(n,"path");o.setAttribute("d","M7 22h9.3a2 2 0 0 0 2-1.7l1.4-9A2 2 0 0 0 17.7 9H14V5a3 3 0 0 0-3-3l-4 10z"),o.setAttribute("stroke","currentColor"),o.setAttribute("stroke-width","1.8"),o.setAttribute("stroke-linejoin","round");const h=document.createElementNS(n,"path");return h.setAttribute("d","M7 22V12H4.5A1.5 1.5 0 0 0 3 13.5v7A1.5 1.5 0 0 0 4.5 22z"),h.setAttribute("stroke","currentColor"),h.setAttribute("stroke-width","1.8"),h.setAttribute("stroke-linejoin","round"),s.append(o,h),i==="down"&&(s.style.transform="rotate(180deg)"),s}function En(i,n,s){const o=e.div({marginTop:"8px",padding:"12px",border:`1px solid ${e.BORDER_COLOR}`,borderRadius:e.MESSAGE_RADIUS,backgroundColor:e.PANEL_BACKGROUND});o.className="ago-feedback__panel",o.setAttribute("role","group"),o.setAttribute("aria-label",n.whatWentWrong);const h=e.div({fontSize:"13px",fontWeight:"500",color:e.TEXT_COLOR,marginBottom:"8px"});h.textContent=n.whatWentWrong,o.appendChild(h);const a=e.div({display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"8px"});a.className="ago-feedback__reasons";for(const c of de.FEEDBACK_REASONS){const f=document.createElement("button");f.type="button",f.className="ago-feedback__reason",f.textContent=n.reasons[c],e.css(f,{minHeight:"44px",padding:"4px 12px",fontSize:"13px",fontFamily:"inherit",borderRadius:"999px",border:`1px solid ${e.BORDER_COLOR}`,backgroundColor:"transparent",color:e.TEXT_COLOR,cursor:"pointer"});const g=()=>{const O=i.reasons.has(c);f.setAttribute("aria-pressed",O?"true":"false"),f.style.borderColor=O?e.ACCENT_COLOR:e.BORDER_COLOR,f.style.color=O?e.ACCENT_COLOR:e.TEXT_COLOR};f.addEventListener("click",()=>{i.reasons.has(c)?i.reasons.delete(c):i.reasons.add(c),g(),C()}),g(),a.appendChild(f)}o.appendChild(a);const x=document.createElement("textarea");x.className="ago-feedback__comment",x.rows=2,x.placeholder=n.commentPlaceholder,x.value=i.comment,x.setAttribute("aria-label",n.commentPlaceholder),e.css(x,{width:"100%",boxSizing:"border-box",padding:"8px 10px",fontSize:"14px",fontFamily:"inherit",color:e.TEXT_COLOR,border:`1px solid ${e.BORDER_COLOR}`,borderRadius:"10px",backgroundColor:"transparent",resize:"vertical"}),x.addEventListener("input",()=>{i.comment=x.value,C()}),o.appendChild(x);const u=document.createElement("button");return u.type="button",u.className="ago-feedback__send",u.textContent=n.send,e.css(u,{marginTop:"8px",minHeight:"44px",padding:"6px 16px",fontSize:"14px",fontFamily:"inherit",borderRadius:"10px",border:"none",backgroundColor:e.BRAND_COLOR,color:e.BRAND_TEXT_COLOR,cursor:"pointer"}),u.addEventListener("click",()=>{u.disabled||(u.disabled=!0,s({reasons:[...i.reasons],comment:i.comment.trim()}).then(c=>{c||C()}))}),o.appendChild(u),C(),o;function C(){const c=i.reasons.size>0||i.comment.trim().length>0;u.disabled=!c,u.style.opacity=c?"1":"0.5",u.style.cursor=c?"pointer":"default"}}function wn(i){const n=e.div({marginTop:"6px",fontSize:"13px",color:e.MUTED_TEXT_COLOR});return n.className="ago-feedback__thanks",n.setAttribute("role","status"),n.textContent=i,n}function At(i,n){const{isLast:s,isLastOfBlock:o,bubbleStyle:h,showAgentName:a,agentBubble:x,followUpEnabled:u,followUpHandler:C,isMobile:c,feedbackRow:f}=n,g=i.role==="user",O=h==="imessage",S=e.div({display:"flex",flexDirection:"column",alignItems:g?"flex-end":"flex-start",marginBottom:O&&!o?"2px":"16px"});if(S.className=`ago-message ago-message--${i.role}`,!g&&a&&i.agent){const E=e.div({fontSize:"13px",fontWeight:"500",color:e.TEXT_COLOR,marginBottom:"6px",padding:"0 4px"});E.className="ago-message__agent",E.textContent=i.agent.displayName||i.agent.name,S.appendChild(E)}if(!g&&i.sources&&i.sources.length>0){const E=e.div({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});E.className="ago-message__sources",i.sources.forEach((y,p)=>{const b=y.url?document.createElement("a"):document.createElement("div");y.url&&b instanceof HTMLAnchorElement&&(b.href=y.url,b.target="_blank",b.rel="noopener noreferrer"),e.css(b,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${e.BORDER_COLOR}`,borderRadius:"8px",backgroundColor:e.PANEL_BACKGROUND,textDecoration:"none",color:e.TEXT_COLOR,fontSize:"12px",overflow:"hidden"});const A=e.div({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${e.ACCENT_COLOR}`,color:e.ACCENT_COLOR,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});A.textContent=String(p+1);const z=e.div({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});z.textContent=y.title,z.title=y.title,b.append(A,z),E.appendChild(b)}),S.appendChild(E)}if(i.attachments&&i.attachments.length>0){const E=e.div({display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:g?"flex-end":"flex-start",maxWidth:"75%"});E.className="ago-message__attachments";for(const y of i.attachments){const p=de.safeAttachmentUrl(y.url);if(de.canInlineImage(y)&&p){const k=document.createElement("a");k.href=p,k.target="_blank",k.rel="noopener noreferrer",e.css(k,{display:"inline-block",textDecoration:"none"});const K=document.createElement("img");K.src=p,K.alt=y.name,K.loading="lazy",e.css(K,{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:`1px solid ${e.BORDER_COLOR}`,display:"block"}),k.appendChild(K),E.appendChild(k);continue}const b=p?document.createElement("a"):document.createElement("div");p&&b instanceof HTMLAnchorElement&&(b.href=p,b.target="_blank",b.rel="noopener noreferrer"),e.css(b,{display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:`1px solid ${e.BORDER_COLOR}`,backgroundColor:g?"rgba(255,255,255,0.12)":e.PANEL_BACKGROUND,color:g?e.BRAND_TEXT_COLOR:e.TEXT_COLOR,fontSize:"13px",textDecoration:"none",maxWidth:"220px"});const A=document.createElement("span");A.textContent="📄",A.setAttribute("aria-hidden","true"),e.css(A,{fontSize:"16px",lineHeight:"1",flexShrink:"0"});const z=e.div({display:"flex",flexDirection:"column",minWidth:"0"}),F=e.div({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"});F.textContent=y.name,F.title=y.name,z.appendChild(F);const Z=de.formatFileSize(y.fileSize);if(Z){const k=e.div({fontSize:"11px",color:e.MUTED_TEXT_COLOR});k.textContent=Z,z.appendChild(k)}b.append(A,z),E.appendChild(b)}S.appendChild(E)}const L=g||x||O,H=!!i.content||i.status==="IN_PROGRESS"||i.status==="WAITING_CLIENT",$=e.div({maxWidth:L?O||g?c?"88%":"75%":c?"92%":"85%":"100%",padding:L?"10px 14px":"2px 8px",borderRadius:O?e.MESSAGE_RADIUS_IMESSAGE:L?e.MESSAGE_RADIUS:"0",backgroundColor:g?e.BRAND_COLOR:L?e.AGENT_BUBBLE_BACKGROUND:"transparent",color:g?e.BRAND_TEXT_COLOR:e.TEXT_COLOR,overflowWrap:"break-word",textWrap:"pretty",fontSize:"16px",lineHeight:"1.6"});if($.className="ago-message__content",O&&o){$.style.position="relative";const E=e.div({position:"absolute",zIndex:"0",bottom:"-2px",width:"20px",height:"20px",background:g?e.BRAND_COLOR:e.AGENT_BUBBLE_BACKGROUND});E.className="ago-message__tail";const y=e.div({position:"absolute",zIndex:"1",bottom:"-2px",width:"10px",height:"20px",background:e.MESSAGES_BACKGROUND});y.className="ago-message__tail-mask",g?(E.style.right="-8px",E.style.borderBottomLeftRadius="16px 14px",y.style.right="-10px",y.style.borderBottomLeftRadius="10px"):(E.style.left="-7px",E.style.borderBottomRightRadius="16px 14px",y.style.left="-10px",y.style.borderBottomRightRadius="10px"),$.append(E,y)}if(i.content?$.appendChild(Te(i.content)):(i.status==="IN_PROGRESS"||i.status==="WAITING_CLIENT")&&$.appendChild(Rn()),H&&S.appendChild($),!g&&f&&S.appendChild(f),s&&i.followUpReplies&&i.followUpReplies.length>0){const E=e.div({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:"10px"});E.className="ago-message__followups";for(const y of i.followUpReplies){const p=document.createElement("button");p.type="button",p.className="ago-message__followup-btn",p.textContent=y,p.disabled=!u,e.css(p,{minHeight:"44px",padding:"6px 14px",fontSize:"14px",borderRadius:e.MESSAGE_RADIUS,border:`1px solid ${e.BORDER_COLOR}`,backgroundColor:e.PANEL_BACKGROUND,color:e.TEXT_COLOR,cursor:u?"pointer":"default",transition:"border-color 0.15s"}),C&&p.addEventListener("click",()=>C(y)),p.addEventListener("mouseenter",()=>{p.style.borderColor=e.ACCENT_COLOR}),p.addEventListener("mouseleave",()=>{p.style.borderColor=e.BORDER_COLOR}),E.appendChild(p)}S.appendChild(E)}return S}function yn(i){const n=e.div({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:e.MESSAGE_RADIUS,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});n.className="ago-form-notice",n.setAttribute("role","status");const s=document.createElement("span");s.textContent="✓",s.setAttribute("aria-hidden","true"),e.css(s,{fontWeight:"700"});const o=document.createElement("span");return o.textContent=i,n.append(s,o),n}function Rn(){const i=e.div({display:"flex",gap:"4px",padding:"4px 0"});for(let n=0;n<3;n++){const s=e.div({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"currentColor",opacity:"0.55",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${n*.2}s`});i.appendChild(s)}return i}function _n(){const i="http://www.w3.org/2000/svg",n=document.createElementNS(i,"svg");n.setAttribute("width","26"),n.setAttribute("height","26"),n.setAttribute("viewBox","0 0 24 24"),n.setAttribute("fill","none");const s=document.createElementNS(i,"path");return s.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"),s.setAttribute("stroke","currentColor"),s.setAttribute("stroke-width","2"),s.setAttribute("stroke-linecap","round"),s.setAttribute("stroke-linejoin","round"),n.appendChild(s),n}var Lt="Form submitted.";function On(i){if(typeof i=="string")return i||null;if(!i||typeof i!="object")return null;const n=i;if(typeof n.message=="string"&&n.message)return n.message;const s=n.result;if(typeof s=="string"&&s)return s;if(s&&typeof s=="object"){const o=s.message;if(typeof o=="string"&&o)return o}return null}var Sn=0;function An(i){const n=typeof i=="string"?document.querySelector(i):i;if(!n)throw new Error(`mountChatWidget: target "${String(i)}" not found.`);return n}function Ln(i,n){const{title:s="Chat",welcomeMessage:o="Hello! How can I help you today?",placeholder:h="Type a message...",allowFiles:a=!1,allowStop:x=!0,height:u=500,placement:C="inline",width:c=400,defaultOpen:f=!1,logoUrl:g,showAgentName:O=!1,agentBubble:S=!1,bubbleStyle:L="default",showHeader:H=!0,theme:$,loadThreads:E=!1,forms:y,formSubmittedMessage:p=Lt,feedback:b=!1,onFollowUpClick:A,onMessageSent:z,onMessageReceived:F,onFormSubmitted:Z,onFormError:k,onOpen:K,onClose:Qe}=n,ne=typeof o=="string"?{message:o,mode:"static"}:o,Je=ne.message,Ye=ne.mode??"static",Dt="speed"in ne&&ne.speed||45,Ze="followUpReplies"in ne&&ne.followUpReplies||void 0;if(!n.client&&!n.config?.baseUrl)throw new dn.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const R=n.client??new de.AgoClient(n.config),et=An(i),T=C==="left"||C==="right",$t=T&&(n.launcher??!0);let ee=T?f:!0,Ne=!1;const Mt=n.mobile?.breakpoint??768,Ie=n.mobile?.trigger??"tap",tt=typeof window<"u"&&!!window.matchMedia,D=tt?window.matchMedia(`(max-width: ${Mt}px), (max-height: 500px) and (orientation: landscape)`):void 0,Ht=tt?window.matchMedia("(prefers-reduced-motion: reduce)"):void 0,zt=!!D,pe=!T&&!!D,ue=Symbol("ago-scroll-lock");let oe=!1;const Be=n.persistConversation,be=Be?cn.createConversationSession(Be===!0?{}:Be):void 0;let G=n.conversationId??be?.getLastActiveThread()??void 0,m=[],xe=[],X=!1,re=null,q;const De=[];function Ft(t){if(typeof p=="function"){const l=p(t);if(typeof l=="string"&&l)return l}const r=On(t);return r||(typeof p=="string"?p:Lt)}const Ce=[],d=e.div({display:"flex",flexDirection:"column",height:T?"100%":typeof u=="number"?`${u}px`:u,border:`1px solid ${e.BORDER_COLOR}`,borderRadius:e.RADIUS,overflow:"hidden",backgroundColor:e.PANEL_BACKGROUND,fontFamily:e.FONT_VAR,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});d.className="ago-chat-widget",e.applyTheme(d,$);let P;if(H){if(P=e.div({padding:"14px 16px",borderBottom:`1px solid ${e.BORDER_COLOR}`,backgroundColor:e.HEADER_BACKGROUND,color:e.HEADER_TEXT_COLOR,display:"flex",alignItems:"center",gap:"10px"}),P.className="ago-chat-widget__header",g){const r=document.createElement("img");r.src=g,r.alt="Logo",e.css(r,{height:"24px",width:"auto"}),P.appendChild(r)}const t=document.createElement("h3");if(t.textContent=s,e.css(t,{margin:"0",fontSize:"15px",fontWeight:"600"}),P.appendChild(t),T){const r=document.createElement("button");r.type="button",r.className="ago-chat-widget__close",r.setAttribute("aria-label","Close"),r.textContent="×",e.css(r,{marginLeft:"auto",flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center",width:"44px",height:"44px",margin:"-10px -10px -10px auto",background:"transparent",border:"none",color:e.HEADER_TEXT_COLOR,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0"}),r.addEventListener("click",()=>Se()),P.appendChild(r)}}const _=e.div({flex:"1",overflow:"auto",overscrollBehavior:"contain",padding:"16px",backgroundColor:e.MESSAGES_BACKGROUND});_.className="ago-chat-widget__messages",_.setAttribute("role","log"),_.setAttribute("aria-live","polite"),_.setAttribute("aria-relevant","additions text"),_.setAttribute("aria-atomic","false");const Ut=48;let ie=!0,$e=0;function ve(t){$e++;try{t()}finally{const r=()=>{$e--};typeof queueMicrotask=="function"?queueMicrotask(r):r()}}function Pt(){return _.scrollHeight-_.scrollTop-_.clientHeight<=Ut}const V=document.createElement("button");V.type="button",V.className="ago-chat-widget__jump",V.setAttribute("aria-label","Jump to latest message"),V.innerHTML='<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 5v14M19 12l-7 7-7-7"/></svg>',e.css(V,{position:"absolute",left:"50%",bottom:"12px",transform:"translateX(-50%)",width:"44px",height:"44px",display:"none",alignItems:"center",justifyContent:"center",border:`1px solid ${e.BORDER_COLOR}`,borderRadius:"50%",backgroundColor:e.PANEL_BACKGROUND,color:e.TEXT_COLOR,boxShadow:"rgba(15, 15, 15, 0.16) 0px 2px 10px 0px",cursor:"pointer",zIndex:"2"}),V.addEventListener("click",()=>{ie=!0,ve(()=>{_.scrollTop=_.scrollHeight}),Me()});function Me(){V.style.display=ie?"none":"flex"}function He(){ie&&ve(()=>{_.scrollTop=_.scrollHeight}),Me()}_.addEventListener("scroll",()=>{$e>0||(ie=Pt(),Me())});const nt=e.div({position:"relative",flex:"1",display:"flex",minHeight:"0"});nt.append(_,V);const{inputRow:ze,setDisabled:Wt,focus:Ee,restoreDraft:Gt}=pn({placeholder:h,allowFiles:a,onSend:(t,r)=>{_e(t,r)},onStop:x?()=>{bt()}:void 0});e.ensureKeyframes(),d.append(...P?[P]:[],nt,ze);let we=d,N,M;const ye=C==="left"?"left":"right";if(T&&(N=e.div({position:"fixed",top:"0",bottom:"0",[ye]:"0",width:typeof c=="number"?`${c}px`:c,maxWidth:"100vw",display:"flex",zIndex:"2147483000",transition:"transform 0.3s ease",boxShadow:"rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"}),N.className="ago-chat-widget-panel",e.css(d,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[ye==="left"?"borderRight":"borderLeft"]:`1px solid ${e.BORDER_COLOR}`}),N.appendChild(d),we=N),$t){if(M=document.createElement("button"),M.type="button",M.className="ago-chat-widget-launcher",M.setAttribute("aria-label",`Open ${s}`),e.css(M,{position:"fixed",bottom:"20px",[ye]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:e.BRAND_COLOR,color:e.BRAND_TEXT_COLOR,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:e.FONT_VAR}),g){const t=document.createElement("img");t.src=g,t.alt="",e.css(t,{width:"26px",height:"26px",objectFit:"contain"}),M.appendChild(t)}else M.appendChild(_n());M.addEventListener("click",()=>Pe())}const fe=pe?`ago-vt-${++Sn}`:"",ot=52;let j=!1,Q=0,se=0,W,me,J;const Re={height:d.style.height,border:d.style.border,borderRadius:d.style.borderRadius,boxShadow:d.style.boxShadow};et.appendChild(we),M&&et.appendChild(M),Oe(),pe&&(W=sn(),d.insertBefore(W,d.firstChild),me=document.createElement("style"),me.id=fe,me.textContent=`::view-transition-group(${fe}),::view-transition-group(${fe}-bar){animation-duration:0.3s;animation-timing-function:cubic-bezier(0.4,0,0.2,1)}`,document.head.appendChild(me),(Ie==="focus"||Ie==="tap")&&(d.addEventListener("pointerdown",t=>{if(j||!D?.matches)return;const r=ze.contains(t.target);if(Ie==="tap"){if((t.target instanceof Element?t.target:null)?.closest("button,a[href],[role='button']"))return}else if(!r)return;r&&t.preventDefault(),he()},!0),d.addEventListener("focusin",t=>{D?.matches&&ze.contains(t.target)&&he()}))),zt&&document.addEventListener("keydown",Ct),D&&D.addEventListener("change",vt);const Xt=A!==!1,jt=A===!1?void 0:A??(t=>{pe&&D?.matches&&!j?he().then(()=>_e(t)):_e(t)}),ae=b===!0?{}:b||null,Kt={...qe,...ae?.labels,reasons:{...qe.reasons,...ae?.labels?.reasons}},rt=new Map;function qt(t){if(!ae||!t.id||!t.conversationId||t.status!=="DONE"||!t.content)return null;let r=rt.get(t.id);r||(r=bn(),rt.set(t.id,r));const l=async(w,v)=>{try{return await R.submitFeedback(t.id,w,v),ae.onSubmit?.({messageId:t.id,rating:w,reasons:v?.reasons??[],comment:v?.comment||void 0}),!0}catch(B){return ae.onError?.(B instanceof Error?B:new Error(String(B))),!1}};return Cn({state:r,labels:Kt,askWhy:ae.askWhy??!0,onRate:w=>{l(w)},onReport:(w,v)=>l(w,v)})}function it(t){const r=m.length-1;return{isLast:t===r,isLastOfBlock:t===r||m[t+1].role!==m[t].role,bubbleStyle:L,showAgentName:O,agentBubble:S,followUpEnabled:Xt,followUpHandler:jt,isMobile:!!D?.matches,feedbackRow:qt(m[t])}}function Vt(){if(re||De.length>0)return!1;const t=m.length-1,r=m[t];if(!r||r.role!=="assistant")return!1;const l=xe[t];if(!l||l.parentNode!==_)return!1;const w=At(r,it(t));return ve(()=>_.replaceChild(w,l)),xe[t]=w,He(),!0}function I(){ve(Qt),He();const t=m[m.length-1],r=X&&t?.role==="assistant"&&(t.status==="IN_PROGRESS"||t.status==="WAITING_CLIENT");_.setAttribute("aria-busy",r?"true":"false"),Wt(r)}function Qt(){if(_.replaceChildren(),xe=[],m.length===0){if(Ye==="static"){const t=e.div({textAlign:"center",color:e.MUTED_TEXT_COLOR,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});t.appendChild(Te(Je)),_.appendChild(t)}}else m.forEach((t,r)=>{const l=At(t,it(r));xe[r]=l,_.appendChild(l)});for(const t of De)_.appendChild(yn(t));if(re){const t=e.div({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});t.setAttribute("role","alert"),t.textContent=re,_.appendChild(t)}}function st(){for(let t=m.length-1;t>=0;t--){const r=m[t];if(r.role==="assistant"&&(r.status==="IN_PROGRESS"||r.status==="WAITING_CLIENT"))return r}}const at=t=>{G||(G=t.conversationId)},lt=t=>{const r=st();r&&(r.content+=t.content,Vt()||I())},dt=t=>{const r=m.findIndex(l=>l.id===t.id||l.role==="assistant"&&l.status==="IN_PROGRESS");r>=0?m[r]=t:m.push(t),I(),We()||Ee()},ct=t=>{const r=m.findIndex(l=>l.id===t.id||l.role==="assistant"&&l.status==="IN_PROGRESS");r>=0?m[r]=t:m.push(t),X=!1,I(),t.status==="DONE"&&F?.({id:t.id,content:t.content})},pt=()=>{const t=st();t&&(t.content?t.status="CANCELED":m=m.filter(r=>r!==t)),X=!1,I()},ut=t=>{re=t.error,X=!1,m=m.filter(r=>!r.id.startsWith("temp-")),I()};function Jt(t){const r={id:`ago-intro-${Date.now()}`,conversationId:"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};m.push(r),I();const l=t.match(/\S+\s*/g)??[t];let w=0;q=setInterval(()=>{if(w>=l.length){clearInterval(q),q=void 0,r.status="DONE",Ze&&(r.followUpReplies=Ze),I();return}r.content+=l[w],w++,I()},Dt)}R.on("message:start",at),R.on("message:chunk",lt),R.on("message:answer-complete",dt),R.on("message:complete",ct),R.on("message:stopped",pt),R.on("message:error",ut);const ft=t=>Z?.(t),mt=t=>k?.(t);Z&&R.on("form:submitted",ft),k&&R.on("form:error",mt);const Fe=[];let ht=!1;const gt=t=>{if(ht)return;Fe.push(t.install(R));let r=t.store.get().submitted;const l=t.store.subscribe(w=>{w.submitted&&!r&&(De.push(Ft(w.submitResult)),I()),r=w.submitted});Fe.push(l)};for(const t of y??[])t.schema!=null?gt(_t.createFormCollector(t)):_t.loadFormCollector(R,t).then(r=>gt(r)).catch(()=>{});async function _e(t,r){const l=t.trim();if(!l&&!r?.length||X)return;if(z?.(l),X=!0,re=null,ie=!0,q){clearInterval(q),q=void 0;const v=m.find(B=>B.id.startsWith("ago-intro-"));v&&!v.content?m=m.filter(B=>B!==v):v&&(v.status="DONE")}const w=Date.now();m.push({id:`temp-user-${w}`,conversationId:G||"",content:l,role:"user",status:"DONE",attachments:r&&r.length>0?de.attachmentsFromFiles(r):void 0,createdAt:new Date}),m.push({id:`temp-assistant-${w}`,conversationId:G||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),I();try{const v=await R.sendMessage(l,{conversationId:G,files:r});v.conversationId&&(G||(G=v.conversationId),be?.setActiveThread(v.conversationId,v.createdAt));const B=m.find(Y=>Y.id===`temp-user-${w}`);if(B&&(B.id=`user-${w}`,B.conversationId=v.conversationId),v.id&&!m.some(Y=>Y.id===v.id)){const Y=m.findIndex(ln=>ln.id===`temp-assistant-${w}`);Y>=0?m[Y]=v:m.push(v)}m=m.filter(Y=>!Y.id.startsWith("temp-")),v.status!=="WAITING_CLIENT"&&(X=!1),I(),E&&Ue()}catch(v){re=v instanceof Error?v.message:"Failed to send message",X=!1,m=m.filter(B=>!B.id.startsWith("temp-")),Gt(l,r),I()}}async function bt(){X&&await R.stop()}async function Ue(){try{const{data:t}=await R.getConversations();Ce.splice(0,Ce.length,...t)}catch{}return Ce}async function Yt(t){try{const r=(await R.getConversation(t))?.messages??[];r.length>0&&m.length===0&&(m=r,I())}catch{m.length===0&&(be?.clear(),G=void 0)}}return I(),pe&&D?.matches||Ee(),G?Yt(G):Ye==="streaming"&&Jt(Je),E&&Ue(),{client:R,element:we,sendMessage:_e,stop:bt,...T||pe?{open:en,close:tn,toggle:nn}:{},session:be,threads:Ce,refreshThreads:Ue,destroy(){oe||(oe=!0,q&&clearInterval(q),R.off("message:start",at),R.off("message:chunk",lt),R.off("message:answer-complete",dt),R.off("message:complete",ct),R.off("message:stopped",pt),R.off("message:error",ut),Z&&R.off("form:submitted",ft),k&&R.off("form:error",mt),ht=!0,Fe.forEach(t=>t()),we.remove(),M?.remove(),W?.remove(),me?.remove(),J?.remove(),D?.removeEventListener("change",vt),document.removeEventListener("keydown",Ct),je(),Ne=!1,e.unlockBackgroundScroll(ue),n.client||R.destroy())}};function Oe(){if(!N)return;{const l=ye==="left"?"border-right":"border-left";D?.matches?(N.style.width="100%",d.style.borderRadius="0",d.style.removeProperty(l)):(N.style.width=typeof c=="number"?`${c}px`:c,d.style.setProperty(l,`1px solid ${e.BORDER_COLOR}`))}const t=C==="left"?"translateX(-100%)":"translateX(100%)";N.style.transform=ee?"translateX(0)":t,N.setAttribute("aria-hidden",ee?"false":"true"),M&&(M.style.display=ee?"none":"flex");const r=xt();r!==Ne&&(Ne=r,r?(d.setAttribute("role","dialog"),d.setAttribute("aria-modal","true"),d.setAttribute("aria-label",s),d.tabIndex=-1,d.style.paddingBottom="env(safe-area-inset-bottom)",e.lockBackgroundScroll(ue),Q=Ge(),Xe(),Et()):(je(),rn(),Q=0,d.removeAttribute("role"),d.removeAttribute("aria-modal"),d.removeAttribute("aria-label"),d.style.removeProperty("padding-bottom"),e.unlockBackgroundScroll(ue)))}function Pe(){ee=!0,Oe(),We()?d.focus({preventScroll:!0}):Ee(),K?.()}function Se(){ee=!1,Oe(),Qe?.()}function Zt(){ee?Se():Pe()}function en(){T?Pe():he()}function tn(){T?Se():ge()}function nn(){T?Zt():j?ge():he()}function We(){return!!D?.matches}function xt(){return We()&&(T?ee:j)}function on(){return Array.from(d.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter(t=>t.getClientRects().length>0)}function Ct(t){if(!xt())return;if(t.key==="Escape"){T?Se():ge();return}if(t.key!=="Tab")return;const r=on();if(r.length===0){t.preventDefault();return}const l=r[0],w=r[r.length-1],v=document.activeElement;t.shiftKey&&(v===l||!d.contains(v))?(t.preventDefault(),w.focus()):!t.shiftKey&&(v===w||!d.contains(v))&&(t.preventDefault(),l.focus())}function vt(t){T?Oe():!t.matches&&j&&ge(),I()}function Ge(){return window.visualViewport?.height??window.innerHeight}function Xe(){const t=window.visualViewport,r=t?.offsetTop??0,l=t?.height??Q;if(T){if(!N)return;const v=window.innerHeight||Q,B=Math.max(0,v-(r+l));N.style.bottom=`${B}px`,N.style.top=`${r}px`;return}const w=Math.min(0,r+l-Q);d.style.top=`${w}px`,W&&(W.style.top=`${r}px`)}function rn(){T&&N&&(N.style.removeProperty("bottom"),N.style.removeProperty("top"))}function Ae(){se||(se=requestAnimationFrame(()=>{se=0,!oe&&Xe()}))}function Et(){window.visualViewport?.addEventListener("resize",Ae),window.visualViewport?.addEventListener("scroll",Ae)}function je(){window.visualViewport?.removeEventListener("resize",Ae),window.visualViewport?.removeEventListener("scroll",Ae),se&&(cancelAnimationFrame(se),se=0)}function wt(){ie=!0,He()}function sn(){const t=e.div({position:"fixed",top:"0",left:"0",right:"0",height:`calc(${ot}px + env(safe-area-inset-top))`,display:"none",alignItems:"center",justifyContent:"space-between",padding:"env(safe-area-inset-top) 14px 0",backgroundColor:e.PANEL_BACKGROUND,borderBottom:`1px solid ${e.BORDER_COLOR}`,zIndex:"2147483001",fontFamily:e.FONT_VAR});if(t.className="ago-chat-widget-mobile-bar",g){const l=document.createElement("img");l.src=g,l.alt="",e.css(l,{height:"28px",width:"auto"}),t.appendChild(l)}else if(s){const l=document.createElement("span");l.textContent=s,e.css(l,{fontSize:"15px",fontWeight:"600",color:e.TEXT_COLOR,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"}),t.appendChild(l)}else t.appendChild(e.div({}));const r=document.createElement("button");return r.type="button",r.setAttribute("aria-label","Close"),r.textContent="×",e.css(r,{flexShrink:"0",width:"44px",height:"44px",marginRight:"-10px",display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",fontSize:"26px",lineHeight:"1",color:e.TEXT_COLOR,cursor:"pointer",padding:"0"}),r.addEventListener("click",()=>{ge()}),t.appendChild(r),t}function an(){return typeof document.startViewTransition=="function"&&!Ht?.matches&&!!D?.matches}function yt(t){const r=document;if(an()&&r.startViewTransition){d.style.setProperty("view-transition-name",fe),W?.style.setProperty("view-transition-name",`${fe}-bar`);const l=()=>{d.style.removeProperty("view-transition-name"),W?.style.removeProperty("view-transition-name")};return r.startViewTransition(t).finished.then(l,l)}return t(),Promise.resolve()}function Rt(t){if(t)J&&d.parentElement?.insertBefore(J,d),e.css(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(${ot}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",s),P&&(P.style.display="none"),W&&(W.style.display="flex");else{J?.remove(),J=void 0;for(const r of["position","top","left","right","bottom","z-index","padding-top","padding-bottom"])d.style.removeProperty(r);d.style.height=Re.height,d.style.border=Re.border,d.style.borderRadius=Re.borderRadius,d.style.boxShadow=Re.boxShadow,d.removeAttribute("role"),d.removeAttribute("aria-modal"),d.removeAttribute("aria-label"),P&&(P.style.display="flex"),W&&(W.style.display="none")}}function he(){if(oe||j||!D?.matches)return Promise.resolve();const t=d.getBoundingClientRect();if(t.height>=Ge()*.8)return Promise.resolve();j=!0,J=e.div({width:`${t.width}px`,height:`${t.height}px`}),J.className="ago-chat-widget-spacer",J.setAttribute("aria-hidden","true"),Q=Ge(),d.style.setProperty("--ago-vh",`${Q}px`),Xe(),Et(),e.lockBackgroundScroll(ue);const r=yt(()=>Rt(!0));return r.then(()=>{oe||(wt(),Ee())}),wt(),K?.(),r}function ge(){if(!j)return Promise.resolve();j=!1,je(),e.unlockBackgroundScroll(ue),d.querySelector("textarea")?.blur();const t=yt(()=>Rt(!1));return t.then(()=>{oe||d.style.removeProperty("--ago-vh")}),Q=0,Qe?.(),t}}exports.DEFAULT_FEEDBACK_LABELS=qe;exports.compactMediaQuery=e.compactMediaQuery;exports.createSheetController=e.createSheetController;exports.mountChatWidget=Ln;exports.renderMarkdown=Te;
package/dist/widget.d.cts CHANGED
@@ -273,9 +273,40 @@ declare class AgoClient {
273
273
  */
274
274
  submitFormCollector(name: string, values: Record<string, unknown>): Promise<unknown>;
275
275
  /**
276
- * Submit feedback for a message
276
+ * Report an answer: thumbs up/down, optionally with what went wrong.
277
+ *
278
+ * ```ts
279
+ * await client.submitFeedback(message.id, "negative", {
280
+ * reasons: ["inaccurate"],
281
+ * comment: "The price it quoted is from last year.",
282
+ * });
283
+ * ```
284
+ *
285
+ * A bare rating is a reaction (the thumbs counted in the dashboard). Adding a
286
+ * reason or a comment also files it in the feedback list, the analytics and
287
+ * the CSV export, so someone can act on it.
288
+ */
289
+ submitFeedback(messageId: string, rating: FeedbackRating, details?: FeedbackDetails): Promise<void>;
290
+ /**
291
+ * Report a whole conversation ("this chat is not working").
292
+ *
293
+ * ```ts
294
+ * await client.submitConversationFeedback(conversationId, "negative", {
295
+ * reasons: ["information_not_found"],
296
+ * comment: "It never answered my question.",
297
+ * });
298
+ * ```
299
+ *
300
+ * Feedback is stored per message, so this attaches the report to the last
301
+ * answer of the conversation, which is the one the user is reacting to.
302
+ * Returns the message id it landed on.
303
+ *
304
+ * Pass `lastMessageId` when you already have it (the widget does) to skip the
305
+ * lookup round-trip.
277
306
  */
278
- submitFeedback(messageId: string, rating: "positive" | "negative"): Promise<void>;
307
+ submitConversationFeedback(conversationId: string, rating: FeedbackRating, details?: FeedbackDetails & {
308
+ lastMessageId?: string;
309
+ }): Promise<string>;
279
310
  /**
280
311
  * Register a client-side function that AGO can call.
281
312
  * Accepts either a definition object or (name, handler, schema) args.
@@ -907,12 +938,27 @@ declare interface AgoStateControl<T = unknown> {
907
938
  enum?: (string | number)[];
908
939
  };
909
940
  };
941
+ /** String-only: `""` means "clear" instead of being dropped as filler. */
942
+ clearable?: boolean;
910
943
  /** Current value → pushed as dynamic context so the agent knows what to change. */
911
944
  get?: () => T;
912
945
  /** Apply the state change on the page. May be async. */
913
- set: (value: T) => void | Promise<void>;
946
+ set: (value: T) => void | AgoStateSetResult | Promise<void | AgoStateSetResult>;
914
947
  }
915
948
 
949
+ /**
950
+ * Tagged outcome a page setter may return to reject or mark unchanged.
951
+ *
952
+ * Returning nothing (void) means APPLY. Returning an unrecognized JS value
953
+ * (e.g. a string from an assignment expression) is also treated as APPLY.
954
+ */
955
+ declare type AgoStateSetResult = {
956
+ result: "rejected";
957
+ reason: string;
958
+ } | {
959
+ result: "unchanged";
960
+ };
961
+
916
962
  export declare interface AgoWidgetColors {
917
963
  button?: string;
918
964
  header?: string;
@@ -1199,6 +1245,8 @@ export declare interface CreateFormCollectorOptions<V = Record<string, unknown>>
1199
1245
 
1200
1246
  export declare function createSheetController(options?: SheetOptions): SheetController;
1201
1247
 
1248
+ export declare const DEFAULT_FEEDBACK_LABELS: FeedbackLabels;
1249
+
1202
1250
  /**
1203
1251
  * A function that returns a fresh context entry on demand.
1204
1252
  * Evaluated every time a message is sent — use it to pull data from stores,
@@ -1213,6 +1261,55 @@ export declare interface ElementProps {
1213
1261
  attrs: Record<string, string | null>;
1214
1262
  }
1215
1263
 
1264
+ /**
1265
+ * Why the user is reporting a message (see `AgoClient.submitFeedback`).
1266
+ *
1267
+ * A rating on its own is a reaction (the thumbs count). Add a reason or a
1268
+ * comment and the report also lands in the feedback dashboard, the analytics
1269
+ * and the CSV export, where someone can act on it.
1270
+ */
1271
+ declare interface FeedbackDetails {
1272
+ /** What went wrong. Several can apply at once. */
1273
+ reasons?: FeedbackReason[];
1274
+ /** The user's own words. Trimmed server-side; 5000 characters max. */
1275
+ comment?: string;
1276
+ }
1277
+
1278
+ /** Every string the feedback row shows, so a non-English app can translate it. */
1279
+ export declare interface FeedbackLabels {
1280
+ /** Accessible name of the thumbs-up button. */
1281
+ helpful: string;
1282
+ /** Accessible name of the thumbs-down button. */
1283
+ notHelpful: string;
1284
+ /** Title of the panel opened by a thumbs-down. */
1285
+ whatWentWrong: string;
1286
+ /** Label of each reason chip. */
1287
+ reasons: Record<FeedbackReason, string>;
1288
+ /** Placeholder of the free-text field. */
1289
+ commentPlaceholder: string;
1290
+ /** Label of the panel's submit button. */
1291
+ send: string;
1292
+ /** Confirmation shown once a report is sent. */
1293
+ thanks: string;
1294
+ }
1295
+
1296
+ /** Thumbs up / thumbs down on an answer. */
1297
+ declare type FeedbackRating = "positive" | "negative";
1298
+
1299
+ /**
1300
+ * What went wrong with an answer. These are the four buckets the AGO feedback
1301
+ * dashboard filters and charts on.
1302
+ */
1303
+ declare type FeedbackReason =
1304
+ /** The answer states something false. */
1305
+ "inaccurate"
1306
+ /** The answer is right but stops short. */
1307
+ | "incomplete"
1308
+ /** The agent could not find the information. */
1309
+ | "information_not_found"
1310
+ /** Something broke: the widget, a tool call, the stream. */
1311
+ | "technical_issue";
1312
+
1216
1313
  /**
1217
1314
  * The backend-stored shape returned by `GET /api/sdk/v1/forms/{name}` (see
1218
1315
  * {@link AgoClient.getFormCollector}). Mirrors the persistable subset of
@@ -1552,6 +1649,25 @@ export declare interface MountChatWidgetOptions {
1552
1649
  * nullish value to fall back to the default text.
1553
1650
  */
1554
1651
  formSubmittedMessage?: string | ((result: unknown) => string | null | undefined);
1652
+ /**
1653
+ * Let the visitor report an answer that did not work: a thumbs up/down row
1654
+ * under each finished answer, and after a thumbs-down a small panel to say
1655
+ * what went wrong (reason chips plus a free-text comment).
1656
+ *
1657
+ * `true` turns it on with English labels. Pass an object to translate the
1658
+ * strings, skip the "why" panel, or observe what was sent. Off by default.
1659
+ *
1660
+ * ```ts
1661
+ * mountChatWidget("#chat", {
1662
+ * config: { baseUrl: "https://playground.api.useago.com", agent: "generic-guide" },
1663
+ * feedback: true,
1664
+ * });
1665
+ * ```
1666
+ *
1667
+ * The thumb is sent as soon as it is clicked, so the signal is never lost if
1668
+ * the visitor ignores the panel; the panel then files the detailed report.
1669
+ */
1670
+ feedback?: boolean | WidgetFeedbackOptions;
1555
1671
  /**
1556
1672
  * How clicking a suggested follow-up reply behaves. Defaults to sending the
1557
1673
  * reply as a new user message. Pass a handler to override, or `false` to
@@ -2117,6 +2233,35 @@ export declare type WelcomeMessage = string | {
2117
2233
  followUpReplies?: string[];
2118
2234
  };
2119
2235
 
2236
+ /** Fine-tuning for {@link MountChatWidgetOptions.feedback}. */
2237
+ export declare interface WidgetFeedbackOptions {
2238
+ /**
2239
+ * After a thumbs-down, open the panel asking what went wrong. Default `true`;
2240
+ * set `false` to collect thumbs only.
2241
+ */
2242
+ askWhy?: boolean;
2243
+ /**
2244
+ * Override any of the row's strings (all English by default). Reason labels
2245
+ * can be overridden one by one.
2246
+ */
2247
+ labels?: Partial<Omit<FeedbackLabels, "reasons">> & {
2248
+ reasons?: Partial<Record<FeedbackReason, string>>;
2249
+ };
2250
+ /**
2251
+ * Called after a report was accepted by the API. Fires once per accepted
2252
+ * report, so a thumbs-down followed by the panel calls it twice: first for
2253
+ * the bare thumb, then for the detailed report.
2254
+ */
2255
+ onSubmit?: (report: {
2256
+ messageId: string;
2257
+ rating: FeedbackRating;
2258
+ reasons: FeedbackReason[];
2259
+ comment?: string;
2260
+ }) => void;
2261
+ /** Called when a report could not be sent. The row keeps its state. */
2262
+ onError?: (error: Error) => void;
2263
+ }
2264
+
2120
2265
  /**
2121
2266
  * Theme overrides for `mountChatWidget`. The keys map to `--ago-*` custom
2122
2267
  * properties (see `THEME_VARS` in `./styles`).
package/dist/widget.d.ts CHANGED
@@ -273,9 +273,40 @@ declare class AgoClient {
273
273
  */
274
274
  submitFormCollector(name: string, values: Record<string, unknown>): Promise<unknown>;
275
275
  /**
276
- * Submit feedback for a message
276
+ * Report an answer: thumbs up/down, optionally with what went wrong.
277
+ *
278
+ * ```ts
279
+ * await client.submitFeedback(message.id, "negative", {
280
+ * reasons: ["inaccurate"],
281
+ * comment: "The price it quoted is from last year.",
282
+ * });
283
+ * ```
284
+ *
285
+ * A bare rating is a reaction (the thumbs counted in the dashboard). Adding a
286
+ * reason or a comment also files it in the feedback list, the analytics and
287
+ * the CSV export, so someone can act on it.
288
+ */
289
+ submitFeedback(messageId: string, rating: FeedbackRating, details?: FeedbackDetails): Promise<void>;
290
+ /**
291
+ * Report a whole conversation ("this chat is not working").
292
+ *
293
+ * ```ts
294
+ * await client.submitConversationFeedback(conversationId, "negative", {
295
+ * reasons: ["information_not_found"],
296
+ * comment: "It never answered my question.",
297
+ * });
298
+ * ```
299
+ *
300
+ * Feedback is stored per message, so this attaches the report to the last
301
+ * answer of the conversation, which is the one the user is reacting to.
302
+ * Returns the message id it landed on.
303
+ *
304
+ * Pass `lastMessageId` when you already have it (the widget does) to skip the
305
+ * lookup round-trip.
277
306
  */
278
- submitFeedback(messageId: string, rating: "positive" | "negative"): Promise<void>;
307
+ submitConversationFeedback(conversationId: string, rating: FeedbackRating, details?: FeedbackDetails & {
308
+ lastMessageId?: string;
309
+ }): Promise<string>;
279
310
  /**
280
311
  * Register a client-side function that AGO can call.
281
312
  * Accepts either a definition object or (name, handler, schema) args.
@@ -907,12 +938,27 @@ declare interface AgoStateControl<T = unknown> {
907
938
  enum?: (string | number)[];
908
939
  };
909
940
  };
941
+ /** String-only: `""` means "clear" instead of being dropped as filler. */
942
+ clearable?: boolean;
910
943
  /** Current value → pushed as dynamic context so the agent knows what to change. */
911
944
  get?: () => T;
912
945
  /** Apply the state change on the page. May be async. */
913
- set: (value: T) => void | Promise<void>;
946
+ set: (value: T) => void | AgoStateSetResult | Promise<void | AgoStateSetResult>;
914
947
  }
915
948
 
949
+ /**
950
+ * Tagged outcome a page setter may return to reject or mark unchanged.
951
+ *
952
+ * Returning nothing (void) means APPLY. Returning an unrecognized JS value
953
+ * (e.g. a string from an assignment expression) is also treated as APPLY.
954
+ */
955
+ declare type AgoStateSetResult = {
956
+ result: "rejected";
957
+ reason: string;
958
+ } | {
959
+ result: "unchanged";
960
+ };
961
+
916
962
  export declare interface AgoWidgetColors {
917
963
  button?: string;
918
964
  header?: string;
@@ -1199,6 +1245,8 @@ export declare interface CreateFormCollectorOptions<V = Record<string, unknown>>
1199
1245
 
1200
1246
  export declare function createSheetController(options?: SheetOptions): SheetController;
1201
1247
 
1248
+ export declare const DEFAULT_FEEDBACK_LABELS: FeedbackLabels;
1249
+
1202
1250
  /**
1203
1251
  * A function that returns a fresh context entry on demand.
1204
1252
  * Evaluated every time a message is sent — use it to pull data from stores,
@@ -1213,6 +1261,55 @@ export declare interface ElementProps {
1213
1261
  attrs: Record<string, string | null>;
1214
1262
  }
1215
1263
 
1264
+ /**
1265
+ * Why the user is reporting a message (see `AgoClient.submitFeedback`).
1266
+ *
1267
+ * A rating on its own is a reaction (the thumbs count). Add a reason or a
1268
+ * comment and the report also lands in the feedback dashboard, the analytics
1269
+ * and the CSV export, where someone can act on it.
1270
+ */
1271
+ declare interface FeedbackDetails {
1272
+ /** What went wrong. Several can apply at once. */
1273
+ reasons?: FeedbackReason[];
1274
+ /** The user's own words. Trimmed server-side; 5000 characters max. */
1275
+ comment?: string;
1276
+ }
1277
+
1278
+ /** Every string the feedback row shows, so a non-English app can translate it. */
1279
+ export declare interface FeedbackLabels {
1280
+ /** Accessible name of the thumbs-up button. */
1281
+ helpful: string;
1282
+ /** Accessible name of the thumbs-down button. */
1283
+ notHelpful: string;
1284
+ /** Title of the panel opened by a thumbs-down. */
1285
+ whatWentWrong: string;
1286
+ /** Label of each reason chip. */
1287
+ reasons: Record<FeedbackReason, string>;
1288
+ /** Placeholder of the free-text field. */
1289
+ commentPlaceholder: string;
1290
+ /** Label of the panel's submit button. */
1291
+ send: string;
1292
+ /** Confirmation shown once a report is sent. */
1293
+ thanks: string;
1294
+ }
1295
+
1296
+ /** Thumbs up / thumbs down on an answer. */
1297
+ declare type FeedbackRating = "positive" | "negative";
1298
+
1299
+ /**
1300
+ * What went wrong with an answer. These are the four buckets the AGO feedback
1301
+ * dashboard filters and charts on.
1302
+ */
1303
+ declare type FeedbackReason =
1304
+ /** The answer states something false. */
1305
+ "inaccurate"
1306
+ /** The answer is right but stops short. */
1307
+ | "incomplete"
1308
+ /** The agent could not find the information. */
1309
+ | "information_not_found"
1310
+ /** Something broke: the widget, a tool call, the stream. */
1311
+ | "technical_issue";
1312
+
1216
1313
  /**
1217
1314
  * The backend-stored shape returned by `GET /api/sdk/v1/forms/{name}` (see
1218
1315
  * {@link AgoClient.getFormCollector}). Mirrors the persistable subset of
@@ -1552,6 +1649,25 @@ export declare interface MountChatWidgetOptions {
1552
1649
  * nullish value to fall back to the default text.
1553
1650
  */
1554
1651
  formSubmittedMessage?: string | ((result: unknown) => string | null | undefined);
1652
+ /**
1653
+ * Let the visitor report an answer that did not work: a thumbs up/down row
1654
+ * under each finished answer, and after a thumbs-down a small panel to say
1655
+ * what went wrong (reason chips plus a free-text comment).
1656
+ *
1657
+ * `true` turns it on with English labels. Pass an object to translate the
1658
+ * strings, skip the "why" panel, or observe what was sent. Off by default.
1659
+ *
1660
+ * ```ts
1661
+ * mountChatWidget("#chat", {
1662
+ * config: { baseUrl: "https://playground.api.useago.com", agent: "generic-guide" },
1663
+ * feedback: true,
1664
+ * });
1665
+ * ```
1666
+ *
1667
+ * The thumb is sent as soon as it is clicked, so the signal is never lost if
1668
+ * the visitor ignores the panel; the panel then files the detailed report.
1669
+ */
1670
+ feedback?: boolean | WidgetFeedbackOptions;
1555
1671
  /**
1556
1672
  * How clicking a suggested follow-up reply behaves. Defaults to sending the
1557
1673
  * reply as a new user message. Pass a handler to override, or `false` to
@@ -2117,6 +2233,35 @@ export declare type WelcomeMessage = string | {
2117
2233
  followUpReplies?: string[];
2118
2234
  };
2119
2235
 
2236
+ /** Fine-tuning for {@link MountChatWidgetOptions.feedback}. */
2237
+ export declare interface WidgetFeedbackOptions {
2238
+ /**
2239
+ * After a thumbs-down, open the panel asking what went wrong. Default `true`;
2240
+ * set `false` to collect thumbs only.
2241
+ */
2242
+ askWhy?: boolean;
2243
+ /**
2244
+ * Override any of the row's strings (all English by default). Reason labels
2245
+ * can be overridden one by one.
2246
+ */
2247
+ labels?: Partial<Omit<FeedbackLabels, "reasons">> & {
2248
+ reasons?: Partial<Record<FeedbackReason, string>>;
2249
+ };
2250
+ /**
2251
+ * Called after a report was accepted by the API. Fires once per accepted
2252
+ * report, so a thumbs-down followed by the panel calls it twice: first for
2253
+ * the bare thumb, then for the detailed report.
2254
+ */
2255
+ onSubmit?: (report: {
2256
+ messageId: string;
2257
+ rating: FeedbackRating;
2258
+ reasons: FeedbackReason[];
2259
+ comment?: string;
2260
+ }) => void;
2261
+ /** Called when a report could not be sent. The row keeps its state. */
2262
+ onError?: (error: Error) => void;
2263
+ }
2264
+
2120
2265
  /**
2121
2266
  * Theme overrides for `mountChatWidget`. The keys map to `--ago-*` custom
2122
2267
  * properties (see `THEME_VARS` in `./styles`).