@useago/sdk 1.7.2 → 1.12.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.
- package/CHANGELOG.md +175 -0
- package/README.md +96 -1
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +402 -5
- package/dist/angular.d.ts +402 -5
- package/dist/angular.js +11 -7
- package/dist/{createConversationSession-DP90nY71.js → createConversationSession-B1Qn-y0I.js} +3 -3
- package/dist/createConversationSession-B3v_xOU7.cjs +1 -0
- package/dist/createFormCollector-FvwDOqnV.cjs +1 -0
- package/dist/{createFormCollector-BivHRIAe.js → createFormCollector-m79zk_NA.js} +1 -1
- package/dist/createMockClient-BEOXI8yW.cjs +1 -0
- package/dist/{createMockClient-BDLW6tVc.js → createMockClient-Beao82tu.js} +31 -18
- package/dist/devtools.cjs +61 -12
- package/dist/devtools.d.cts +403 -5
- package/dist/devtools.d.ts +403 -5
- package/dist/devtools.js +225 -73
- package/dist/errors-BLfjXnLB.js +32 -0
- package/dist/errors-o1IB5fEu.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +489 -7
- package/dist/index.d.ts +489 -7
- package/dist/index.js +124 -118
- package/dist/react.cjs +4 -4
- package/dist/react.d.cts +510 -3
- package/dist/react.d.ts +510 -3
- package/dist/react.js +1036 -752
- package/dist/sheetController-BThJRtOu.cjs +1 -0
- package/dist/sheetController-aEKXIvjk.js +343 -0
- package/dist/testing.cjs +1 -1
- package/dist/testing.d.cts +393 -3
- package/dist/testing.d.ts +393 -3
- package/dist/testing.js +1 -1
- package/dist/types-Ct1hlKwg.js +2408 -0
- package/dist/types-mcW8vB1U.cjs +10 -0
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +615 -3
- package/dist/vue.d.ts +615 -3
- package/dist/vue.js +202 -154
- package/dist/widget.cjs +6 -4
- package/dist/widget.d.cts +733 -5
- package/dist/widget.d.ts +733 -5
- package/dist/widget.js +3996 -786
- package/llms-full.txt +264 -31
- package/package.json +1 -1
- package/dist/AgoClient-7yXQ6R3O.cjs +0 -9
- package/dist/AgoClient-DTkBRGFE.js +0 -1965
- package/dist/createConversationSession-Bv6a15E0.cjs +0 -1
- package/dist/createFormCollector-CwfiYn0V.cjs +0 -1
- package/dist/createMockClient-BSNuN3ys.cjs +0 -1
- package/dist/sheetController-CBUVOroo.js +0 -205
- package/dist/sheetController-DY-sC13T.cjs +0 -1
package/dist/widget.cjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
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={"&":"&","<":"<",">":">",'"':""","'":"'"};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 Ee=require("./types-mcW8vB1U.cjs"),ci=require("./errors-o1IB5fEu.cjs"),pi=require("./createConversationSession-B3v_xOU7.cjs"),no=require("./createFormCollector-FvwDOqnV.cjs"),n=require("./sheetController-BThJRtOu.cjs");var pt="http://www.w3.org/2000/svg";function ut(t,e,o){const i=document.createElementNS(pt,"svg");return i.setAttribute("xmlns",pt),i.setAttribute("viewBox",t),i.setAttribute("width",String(e)),i.setAttribute("height",String(e)),i.setAttribute("aria-hidden","true"),i.setAttribute("focusable","false"),i.style.flexShrink="0",i.style.display="block",o&&i.setAttribute("class",o),i}function Ze(t,e){const o=document.createElementNS(pt,"path");return o.setAttribute("d",t),o.setAttribute("fill","currentColor"),e&&o.setAttribute("data-ago-path",e),o}function le(t,e={}){const o=ut("0 -960 960 960",e.size??24,e.className);return o.appendChild(Ze(t)),o}function Bt(t,e={}){const o=ut("0 0 24 24",e.size??24,e.className);o.setAttribute("fill","none"),o.setAttribute("stroke","currentColor"),o.setAttribute("stroke-width",String(e.strokeWidth??2)),o.setAttribute("stroke-linecap","round"),o.setAttribute("stroke-linejoin","round");for(const i of t){const r=document.createElementNS(pt,"path");r.setAttribute("d",i),o.appendChild(r)}return o}var ui="M240-400h480v-80H240v80Zm0-120h480v-80H240v80Zm0-120h480v-80H240v80ZM880-80 720-240H160q-33 0-56.5-23.5T80-320v-480q0-33 23.5-56.5T160-880h640q33 0 56.5 23.5T880-800v720ZM160-320h594l46 45v-525H160v480Zm0 0v-480 480Z",fo="M480-344 240-584l56-56 184 184 184-184 56 56-240 240Z";function fi(){const t=ut("0 -960 960 960",48);return t.appendChild(Ze(ui,"open")),t.appendChild(Ze(fo,"close")),t}function mi(){const t=ut("0 -960 960 960",48);return t.appendChild(Ze(fo,"close")),t}function gi(t){return le("M560-240 320-480l240-240 56 56-184 184 184 184-56 56Z",t)}function hi(t){return le("M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z",t)}function mo(t){return le("m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z",t)}function bn(t){return le("M440-400h80v-120h120v-80H520v-120h-80v120H320v80h120v120ZM80-80v-720q0-33 23.5-56.5T160-880h640q33 0 56.5 23.5T880-800v480q0 33-23.5 56.5T800-240H240L80-80Zm126-240h594v-480H160v525l46-45Zm-46 0v-480 480Z",t)}function bi(t){return le("M440-160v-487L216-423l-56-57 320-320 320 320-56 57-224-224v487h-80Z",t)}function xi(t){return le("M440-800v487L216-537l-56 57 320 320 320-320-56-57-224 224v-487h-80Z",t)}function yi(t){return le("M240-240v-480h480v480H240Z",t)}function vi(t){return le("M720-120H280v-520l280-280 50 50q7 7 11.5 19t4.5 23v14l-44 174h258q32 0 56 24t24 56v80q0 7-2 15t-4 15L794-168q-9 20-30 34t-44 14Zm-360-80h360l120-280v-80H480l54-220-174 174v406Zm0-406v406-406Zm-80-34v80H160v360h120v80H80v-520h200Z",t)}function Ci(t){return le("M240-840h440v520L400-40l-50-50q-7-7-11.5-19t-4.5-23v-14l44-174H120q-32 0-56-24t-24-56v-80q0-7 2-15t4-15l120-282q9-20 30-34t44-14Zm360 80H240L120-480v80h360l-54 220 174-174v-406Zm0 406v-406 406Zm80 34v-80h120v-360H680v-80h200v520H680Z",t)}function wi(t){return le("M320-240h320v-80H320v80Zm0-160h320v-80H320v80ZM240-80q-33 0-56.5-23.5T160-160v-640q0-33 23.5-56.5T240-880h320l240 240v480q0 33-23.5 56.5T720-80H240Zm280-520v-200H240v640h480v-440H520ZM240-800v200-200 640-640Z",t)}function Ei(t){return le("M480-320 280-520l56-58 104 104v-326h80v326l104-104 56 58-200 200ZM240-160q-33 0-56.5-23.5T160-240v-120h80v120h480v-120h80v120q0 33-23.5 56.5T720-160H240Z",t)}function ki(t){return le("M720-330q0 104-73 177T470-80q-104 0-177-73t-73-177v-370q0-75 52.5-127.5T400-880q75 0 127.5 52.5T580-700v350q0 46-32 78t-78 32q-46 0-78-32t-32-78v-370h80v370q0 13 8.5 21.5T470-320q13 0 21.5-8.5T500-350v-350q-1-42-29.5-71T400-800q-42 0-71 29t-29 71v370q-1 71 49 120.5T470-160q70 0 119-49.5T640-330v-390h80v390Z",t)}function _i(t){return Bt(["M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8","M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"],{...t,strokeWidth:1.5})}function Si(t){return Bt(["M7 7h10v10","M7 17 17 7"],t)}function Ti(t){const e=Bt(["M12 8v4","M12 16h.01"],t),o=document.createElementNS(pt,"circle");return o.setAttribute("cx","12"),o.setAttribute("cy","12"),o.setAttribute("r","10"),e.insertBefore(o,e.firstChild),e}function Ri(t){return Bt(["M12 3v3m6.366-.366-2.12 2.12M21 12h-3m.366 6.366-2.12-2.12M12 21v-3m-6.366.366 2.12-2.12M3 12h3m-.366-6.366 2.12 2.12"],{size:20,...t,strokeWidth:1.5})}function go(t){const e=ut("0 0 24 24",t?.size??24,t?.className);return e.setAttribute("fill","none"),e.appendChild(Ze("M21.5166 5.68457C21.5166 5.43995 21.4185 5.20337 21.2402 5.02734C21.0616 4.85106 20.8173 4.75009 20.5605 4.75H6.90723C6.65037 4.75 6.40524 4.85098 6.22656 5.02734C6.04838 5.20336 5.9502 5.44001 5.9502 5.68457V19.0518L7.58691 17.4365C8.04823 16.9811 8.67203 16.7267 9.32031 16.7266H20.5605C20.8173 16.7265 21.0616 16.6255 21.2402 16.4492C21.4185 16.2732 21.5166 16.0366 21.5166 15.792V5.68457ZM23.0166 15.792C23.0166 16.4408 22.7556 17.0608 22.2939 17.5166C21.8326 17.972 21.2088 18.2265 20.5605 18.2266H9.32031C9.09545 18.2266 8.87996 18.3038 8.70996 18.4414L8.64062 18.5039L6.76172 20.3584C6.57148 20.5461 6.32948 20.6733 6.06836 20.7246C5.80739 20.7758 5.53645 20.7492 5.29004 20.6484C5.0436 20.5476 4.83171 20.3759 4.68164 20.1543C4.53151 19.9325 4.45027 19.671 4.4502 19.4023V5.68457C4.4502 5.03587 4.71129 4.41572 5.17285 3.95996C5.63429 3.50449 6.25881 3.25 6.90723 3.25H20.5605C21.2088 3.25009 21.8326 3.50457 22.2939 3.95996C22.7556 4.41574 23.0166 5.0358 23.0166 5.68457V15.792Z")),e.appendChild(Ze("M1.25 7.81793C1.25 7.16923 1.5111 6.54909 1.97266 6.09332C2.4341 5.63785 3.05861 5.38336 3.70703 5.38336C4.12108 5.38356 4.45703 5.71927 4.45703 6.13336C4.45703 6.54745 4.12108 6.88316 3.70703 6.88336C3.45018 6.88336 3.20505 6.98434 3.02637 7.16071C2.84819 7.33672 2.75 7.57337 2.75 7.81793V19.1304C3.02293 19.0188 3.34839 19.0755 3.56836 19.2984C3.85897 19.5932 3.85612 20.0681 3.56152 20.3589C3.37129 20.5467 3.12929 20.6729 2.86816 20.7242C2.60717 20.7754 2.33628 20.7497 2.08984 20.649C1.84341 20.5482 1.63154 20.3764 1.48145 20.1548C1.33122 19.933 1.25004 19.6707 1.25 19.4019V7.81793Z")),e}var Ai=10*1024*1024;var oo=["image/jpeg","image/png","image/gif","image/webp","image/bmp","image/tiff","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-word.document.macroenabled.12","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","text/plain","text/csv","application/json","application/xml","text/xml","text/html","application/epub+zip"];function io(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function Oi(t){const e=t.look==="embed";let o=[];const i=new Map,r=document.createElement("form");r.className=e?"ago-chat-input ago-chat-input--embed":"ago-chat-input",e?n.css(r,{width:"100%",borderRadius:"24px",border:`2px solid ${n.PRIMARY_FOREGROUND}`,backgroundColor:"#fff",boxShadow:n.SHADOW,position:"relative",boxSizing:"border-box",display:"block",fontFamily:n.FONT_VAR}):n.css(r,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${n.BORDER_COLOR}`,backgroundColor:n.PANEL_BACKGROUND});const s=n.div(e?{display:"none",flexWrap:"wrap",gap:"8px",padding:"0 0 8px"}:{display:"flex",flexWrap:"wrap",gap:"6px"});s.className="ago-chat-input__files";const d=n.div(e?{display:"flex",flexDirection:"row",gap:"8px",padding:"16px"}:{display:"flex",gap:"8px",alignItems:"flex-end"}),c=document.createElement("textarea");c.placeholder=t.placeholder,c.setAttribute("aria-label",t.placeholder),c.rows=1,c.autocapitalize="off",c.setAttribute("autocorrect","off");const b=e?208:110;e?n.css(c,{display:"block",width:"100%",minHeight:"40px",maxHeight:`${b}px`,overflowY:"auto",resize:"none",border:"none",outline:"none",boxShadow:"none",background:"transparent",padding:"8px",boxSizing:"border-box",fontSize:"16px",lineHeight:"24px",fontFamily:"inherit",color:"inherit"}):n.css(c,{flex:"1",resize:"none",boxSizing:"border-box",padding:"10px 12px",border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"12px",fontSize:"16px",fontFamily:n.FONT_VAR,lineHeight:"1.4",maxHeight:`${b}px`,overflowY:"hidden"});const f=()=>{const h=e?0:2;c.style.height="auto";const I=Math.min(c.scrollHeight+h,b);c.style.height=`${I}px`,c.style.overflowY=c.scrollHeight+h>b?"auto":"hidden"};c.addEventListener("input",()=>{f(),A()});const p='<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>',B='<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>',E=document.createElement("button");E.type="submit",E.className="ago-chat-input__send",E.setAttribute("aria-label","Send"),e?n.css(E,{flexShrink:"0",width:"40px",height:"40px",padding:"0",border:"none",borderRadius:"50%",backgroundColor:n.SEND_BACKGROUND,color:"#fafafa",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",transition:"background-color 0.15s, color 0.15s"}):(E.innerHTML=p,n.css(E,{flexShrink:"0",width:"44px",height:"44px",padding:"0",border:"none",borderRadius:"50%",backgroundColor:n.BRAND_COLOR,color:n.BRAND_TEXT_COLOR,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer"}));let u=!1;const C=()=>u&&!!t.onStop,A=()=>{const h=c.value.trim()!==""||o.length>0,I=C(),N=!I&&(u||!h);if(E.disabled=N,E.type=I?"button":"submit",E.setAttribute("aria-label",I?"Stop generating":"Send"),e){E.replaceChildren(I?yi({size:16}):bi({size:16}));const G=N&&!u;E.style.backgroundColor=G?"#f1f5f9":n.SEND_BACKGROUND,E.style.color=G?"#cbd5e1":"#fafafa",E.style.pointerEvents=N?"none":"auto",E.style.cursor=N?"default":"pointer",T.style.opacity=u?"0.5":"1";return}E.innerHTML=I?B:u?y:p,E.style.opacity=N&&!u?"0.5":"1",E.style.cursor=N?"default":"pointer"};E.addEventListener("click",()=>{C()&&t.onStop?.()});const k=n.div({display:"none",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",margin:"0 0 12px",padding:"12px 16px",borderRadius:"12px",border:"1px solid rgba(239, 68, 68, 0.5)",color:"#ef4444",backgroundColor:"#fff",fontSize:"14px",lineHeight:"20px"});k.className="ago-chat-input__error",k.setAttribute("role","alert");const F=document.createElement("span"),z=document.createElement("button");z.type="button",z.textContent=t.labels?.dismiss??"Dismiss",n.css(z,{border:"none",background:"transparent",color:"inherit",font:"inherit",fontWeight:"500",cursor:"pointer",padding:"0",minHeight:"20px"}),z.addEventListener("click",()=>{k.style.display="none"}),k.append(F,z);const w=h=>{F.textContent=h,k.style.display="flex"},D=(h,I)=>h.replace(/\{(\w+)\}/g,(N,G)=>I[G]??""),v=h=>{if(!e)return h;const I=t.labels,N=[];for(const G of h){if(o.length+N.length>=5){w(D(I?.tooManyFiles??"Too many files. Maximum allowed: {max}",{max:String(5)}));break}if(G.type&&!oo.includes(G.type)){w(D(I?.invalidFileType??"Invalid file type: {name}",{name:G.name}));continue}if(G.size>10485760){w(D(I?.fileTooLarge??"File too large: {name} (maximum {max})",{name:G.name,max:io(Ai)}));continue}N.push(G)}return N};let x=null,S=null;t.allowFiles&&(x=document.createElement("input"),x.type="file",x.multiple=!0,e&&(x.accept=oo.join(",")),n.css(x,{display:"none"}),S=document.createElement("button"),S.type="button",S.className="ago-chat-input__attach",S.setAttribute("aria-label",t.labels?.attachFiles??"Attach file"),e?(S.appendChild(ki({size:16})),n.css(S,{height:"40px",padding:"8px",display:"flex",alignItems:"center",gap:"4px",fontSize:"14px",color:n.BRAND_COLOR,background:"none",border:"none",cursor:"pointer",borderRadius:"6px"})):(S.textContent="📎",n.css(S,{flexShrink:"0",minWidth:"44px",minHeight:"44px",display:"flex",alignItems:"center",justifyContent:"center",padding:"0 12px",border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"12px",backgroundColor:n.PANEL_BACKGROUND,cursor:"pointer",fontSize:"14px"})),S.addEventListener("click",()=>x?.click()),x.addEventListener("change",()=>{const h=Array.from(x?.files??[]);o=[...o,...v(h)],x&&(x.value=""),M()}));function W(h){if(!e||!h.type.startsWith("image/")||typeof URL>"u"||typeof URL.createObjectURL!="function")return null;let I=i.get(h);return I||(I=URL.createObjectURL(h),i.set(h,I)),I}function j(h){const I=i.get(h);I&&(URL.revokeObjectURL(I),i.delete(h))}function M(){s.replaceChildren(),e&&(s.style.display=o.length>0?"flex":"none"),o.forEach((h,I)=>{const N=n.div(e?{display:"flex",alignItems:"center",gap:"8px",backgroundColor:"#f3f4f6",borderRadius:"8px",padding:"8px 12px",fontSize:"14px",lineHeight:"20px"}:{display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"8px",fontSize:"12px"});if(N.className="ago-chat-input__file",e){const K=W(h);if(K){const X=document.createElement("img");X.src=K,X.alt="",n.css(X,{width:"32px",height:"32px",objectFit:"cover",borderRadius:"4px",flexShrink:"0"}),N.appendChild(X)}else N.appendChild(wi({size:20}))}const G=document.createElement("span");if(G.textContent=h.name,G.title=h.name,e&&n.css(G,{maxWidth:"150px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),N.appendChild(G),e){const K=document.createElement("span");K.textContent=io(h.size),n.css(K,{fontSize:"12px",lineHeight:"16px",color:"#6b7280"}),N.appendChild(K)}const ee=document.createElement("button");ee.type="button",ee.setAttribute("aria-label",`Remove ${h.name}`),e?ee.appendChild(mo({size:16})):ee.textContent="×",n.css(ee,{flexShrink:"0",width:"44px",height:"44px",margin:e?"-10px -16px -10px -8px":"-14px -12px -14px -4px",display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1",color:"inherit"}),ee.addEventListener("click",()=>{j(h),o=o.filter((K,X)=>X!==I),M()}),N.appendChild(ee),s.appendChild(N)}),A()}const P=()=>{const h=c.value,I=o;c.value="",f(),o=[];for(const N of I)j(N);return M(),{content:h,files:I}},m=()=>{const{content:h,files:I}=P();(h.trim()||I.length>0)&&(t.onSend(h.trim(),I.length>0?I:void 0),e&&typeof window<"u"&&window.innerWidth<(t.blurOnSubmitBelow??600)&&c.blur())};r.addEventListener("submit",h=>{h.preventDefault(),m()}),c.addEventListener("keydown",h=>{if(h.key==="Enter"&&!h.shiftKey){if(h.isComposing||h.keyCode===229)return;h.preventDefault(),m()}});const T=n.div({flex:"1",minWidth:"0"});if(T.className="ago-chat-input__editor",e){T.append(k,s,c);const h=n.div({display:"flex",alignItems:"center"});h.className="ago-chat-input__toolbar",S&&h.appendChild(S),S&&T.appendChild(h);const I=n.div({display:"flex",alignItems:"flex-end",flexShrink:"0"});I.appendChild(E),d.append(T,I),x&&r.appendChild(x),r.appendChild(d),r.addEventListener("click",N=>{(N.target instanceof Element?N.target:null)?.closest("button,a,input,textarea")||c.focus()})}else S&&d.appendChild(S),d.append(c,E),x&&r.appendChild(x),r.append(s,d);return A(),{inputRow:r,getValueAndClear:P,setDisabled:h=>{c.disabled=h,u=h,A()},focus:()=>c.focus(),blur:()=>c.blur(),restoreDraft:(h,I)=>{h&&!c.value.trim()&&(c.value=h,f()),I?.length&&(o=[...I,...o],M()),A()},setPlaceholder:h=>{c.placeholder=h,h&&c.setAttribute("aria-label",h)}}}var sn="rgba(3, 24, 47, 0.07)";function Li(t){const e=document.createElement("footer");e.className="ago-chat-widget__footer",n.css(e,{padding:"12px",flexShrink:"0",background:"transparent"});const o=document.createElement("nav");n.css(o,{display:"flex",alignItems:"center",gap:"4px",width:"100%"});const i=new Map;let r="home";function s(c,b,f){const p=document.createElement("button");p.type="button",p.className="ago-chat-widget__tab",p.dataset.agoScreen=c,n.css(p,{flex:"1",minWidth:"0",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"4px",padding:"12px 8px",borderRadius:"32px",border:"none",background:"transparent",color:n.BRAND_COLOR,cursor:"pointer",transition:"background-color 0.15s",font:"inherit"});const y=document.createElement("span");return y.textContent=b,n.css(y,{fontSize:"12px",lineHeight:"16px",maxWidth:"100%",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"}),p.append(f,y),p.addEventListener("mouseenter",()=>{p.style.backgroundColor=sn}),p.addEventListener("mouseleave",()=>{p.style.backgroundColor=r===c?sn:"transparent"}),p.addEventListener("click",()=>t.onNavigate(c)),i.set(c,p),p}o.append(s("home",t.labels.home,_i({size:24})),s("history",t.labels.chats,go({size:24}))),e.appendChild(o);const d=c=>{r=c==="history"?"history":"home";for(const[b,f]of i){const p=b===r;f.style.color=p?n.PRIMARY_ACCENT:n.BRAND_COLOR,f.style.backgroundColor=p?sn:"transparent",p?f.setAttribute("aria-current","page"):f.removeAttribute("aria-current")}};return d("home"),{el:e,setActive:d,setVisible:c=>{e.style.display=c?"block":"none"}}}function ln(t,e,o,i){const r=document.createElement("button");return r.type="button",r.className=t,r.setAttribute("aria-label",e),r.title=e,n.css(r,{display:"flex",alignItems:"center",justifyContent:"center",width:"44px",height:"44px",margin:"-12px",padding:"0",border:"none",background:"transparent",color:"currentColor",opacity:"0.8",cursor:"pointer",transition:"opacity 0.15s",flexShrink:"0"}),r.addEventListener("mouseenter",()=>{r.style.opacity="1"}),r.addEventListener("mouseleave",()=>{r.style.opacity="0.8"}),r.addEventListener("click",i),r.appendChild(o),r}function Ni(t){const e=document.createElement("header");e.className="ago-chat-widget__header",n.css(e,{display:"flex",alignItems:"center",justifyContent:"space-between",height:"56px",padding:"0 16px",boxSizing:"border-box",background:n.HEADER_BACKGROUND,color:n.HEADER_TEXT_COLOR,borderBottom:"1px solid #e5e7eb",boxShadow:n.SHADOW_SM,flexShrink:"0"});const o=n.div({display:"flex",alignItems:"center",gap:"12px",minWidth:"0"}),i=ln("ago-chat-widget__back",t.labels.back,gi({size:20}),t.onBack);i.style.marginRight="-8px";const r=document.createElement("span");r.className="ago-chat-widget__title",n.css(r,{fontSize:"14px",lineHeight:"20px",fontWeight:"500",color:"currentColor",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"}),o.append(i,r);const s=n.div({display:"flex",alignItems:"center",gap:"8px",flexShrink:"0"}),d=ln("ago-chat-widget__new",t.labels.newChat,bn({size:20}),t.onNewChat),c=ln("ago-chat-widget__close",t.labels.close,mo({size:20}),t.onClose);return s.append(d,c),e.append(o,s),{el:e,update:({screen:b})=>{i.style.display=b==="chat"?"flex":"none",d.style.display=b==="home"?"none":"flex",r.textContent=b==="history"?t.labels.history:t.title}}}var ho={minutes:"{n}min ago",hours:"{n}h ago",days:"{n}d ago",weeks:"{n} weeks ago",months:"{n} months ago"},Fi=60*1e3;function Ii(t,e=Date.now(),o=ho){const i=t instanceof Date?t.getTime():new Date(t).getTime(),r=(p,y)=>p.replace("{n}",String(y));if(!Number.isFinite(i))return r(o.minutes,0);const s=Math.max(0,Math.floor((e-i)/Fi)),d=Math.floor(s/60),c=Math.floor(d/24),b=Math.floor(c/7),f=Math.max(1,Math.floor(c/30));return s<60?r(o.minutes,s):d<24?r(o.hours,d):c<7?r(o.days,c):b<4?r(o.weeks,b):r(o.months,f)}var dn={home:"Home",chats:"Chats",history:"History",newConversation:"New conversation",noHistory:"No chat history yet",askQuestion:"Ask a question",back:"Back",close:"Close chat",newChat:"New chat",errorTitle:"Something went wrong",errorDescription:"The answer could not be generated. Please try again.",scrollToBottom:"Scroll to bottom",dismiss:"Dismiss",attachFiles:"Attach files",tooManyFiles:"Too many files. Maximum allowed: {max}",invalidFileType:"Invalid file type: {name}",fileTooLarge:"File too large: {name} (maximum {max})",timeAgo:ho};function Di(t){return{...dn,...t,timeAgo:{...dn.timeAgo,...t?.timeAgo}}}var Bi={"&":"&","<":"<",">":">",'"':""","'":"'"};function Ve(t){return t.replace(/[&<>"']/g,e=>Bi[e])}function ro(t){const e=t.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(e)||!/^[a-z][a-z0-9+.-]*:/i.test(e)?e:null}var bo='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',Nt="";function Be(t){const e=[],o=r=>(e.push(r),`${Nt}${e.length-1}${Nt}`);let i=t;return i=i.replace(/`([^`]+)`/g,(r,s)=>o(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${bo}">${Ve(s)}</code>`)),i=i.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(r,s,d)=>{const c=ro(d);return c?o(`<img alt="${Ve(s)}" src="${Ve(c)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):r}),i=i.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(r,s,d)=>{const c=ro(d);return c?o(`<a href="${Ve(c)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${Be(s)}</a>`):r}),i=Ve(i),i=i.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>"),i=i.replace(new RegExp(`${Nt}(\\d+)${Nt}`,"g"),(r,s)=>e[Number(s)]),i}function se(t,e,o){const i=document.createElement(t);return Object.assign(i.style,e),o!==void 0&&(i.innerHTML=o),i}var xo=/^ {0,3}([-*_])( *\1){2,} *$/,yo=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,vo=/^ {0,3}(```+|~~~+)/,Ft=/^ {0,3}>\s?/,Xe=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,Hi=["20px","18px","16px","15px","14px","13px"],cn=t=>t.match(/^\s*/)?.[0].length??0;function Mi(t){return t.trim()===""||xo.test(t)||yo.test(t)||vo.test(t)||Ft.test(t)||Xe.test(t)}function Co(t){const e=t[0].match(Xe),o=e[1].length,i=/\d/.test(e[2]),r=se(i?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:i?"decimal":"disc",listStylePosition:"outside"});let s=0;for(;s<t.length;){const d=t[s].match(Xe),c=[];for(s++;s<t.length&&cn(t[s])>o;)c.push(t[s]),s++;const b=se("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),f=d[3].match(/^\[([ xX])\]\s+(.*)$/);f?(b.style.listStyleType="none",b.style.marginLeft="-20px",b.innerHTML=`<span style="margin-right:6px">${f[1].toLowerCase()==="x"?"☑":"☐"}</span>${Be(f[2])}`):b.innerHTML=Be(d[3]),c.filter(p=>Xe.test(p)).length>0&&b.appendChild(Co(c.filter(p=>p.trim()!==""))),r.appendChild(b)}return r}function zi(t){const e=c=>c.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(b=>b.trim()),o=se("div",{overflowX:"auto",margin:"0 0 8px 0"}),i=se("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),r=document.createElement("thead"),s=document.createElement("tr");for(const c of e(t[0]))s.appendChild(se("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},Be(c)));r.appendChild(s),i.appendChild(r);const d=document.createElement("tbody");for(const c of t.slice(2)){const b=document.createElement("tr");for(const f of e(c))b.appendChild(se("td",{border:"1px solid #dee3e8",padding:"6px 10px"},Be(f)));d.appendChild(b)}return i.appendChild(d),o.appendChild(i),o}var $i=t=>!!t&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(t);function He(t){const e=document.createDocumentFragment(),o=t.replace(/\r\n?/g,`
|
|
2
2
|
`).split(`
|
|
3
|
-
`);let
|
|
4
|
-
`)))),
|
|
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 i=0;for(;i<o.length;){const s=o[i];if(s.trim()===""){i++;continue}const d=s.match(vo);if(d){const f=d[1][0],p=[];for(i++;i<o.length&&!new RegExp(`^ {0,3}${f==="`"?"`{3,}":"~{3,}"}\\s*$`).test(o[i]);)p.push(o[i]),i++;i++;const y=se("pre",{margin:"0 0 8px 0"});y.appendChild(se("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:bo,whiteSpace:"pre"},Ve(p.join(`
|
|
4
|
+
`)))),e.appendChild(y);continue}if(xo.test(s)){e.appendChild(se("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),i++;continue}const c=s.match(yo);if(c){const f=c[1].length;e.appendChild(se(`h${f}`,{margin:"16px 0 8px 0",fontSize:Hi[f-1],fontWeight:"600",lineHeight:"1.3"},Be(c[2]))),i++;continue}if(Ft.test(s)){const f=[];for(;i<o.length&&Ft.test(o[i]);)f.push(o[i].replace(Ft,"")),i++;const p=se("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});p.appendChild(He(f.join(`
|
|
5
|
+
`))),e.appendChild(p);continue}if(s.includes("|")&&$i(o[i+1])){const f=[s,o[i+1]];for(i+=2;i<o.length&&o[i].includes("|")&&o[i].trim();)f.push(o[i]),i++;e.appendChild(zi(f));continue}if(Xe.test(s)){const f=[],p=cn(s);for(;i<o.length&&o[i].trim()!=="";)if(Xe.test(o[i])||cn(o[i])>p)f.push(o[i]),i++;else break;e.appendChild(Co(f));continue}const b=[s];for(i++;i<o.length&&!Mi(o[i]);)b.push(o[i]),i++;e.appendChild(se("p",{margin:"0 0 8px 0",lineHeight:"1.6"},b.map(f=>Be(f)).join("<br>")))}const r=e.lastElementChild;return r&&(r.style.marginBottom="0"),e}function Ui(t,e){const o=n.div({display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:e.isUser?"flex-end":"flex-start",maxWidth:"75%"});o.className="ago-message__attachments";for(const i of t){const r=Ee.safeAttachmentUrl(i.url);if(Ee.canInlineImage(i)&&r){const p=document.createElement("a");p.href=r,p.target="_blank",p.rel="noopener noreferrer",n.css(p,{display:"inline-block",textDecoration:"none"});const y=document.createElement("img");y.src=r,y.alt=i.name,y.loading="lazy",n.css(y,{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:`1px solid ${n.BORDER_COLOR}`,display:"block"}),p.appendChild(y),o.appendChild(p);continue}const s=r?document.createElement("a"):document.createElement("div");r&&s instanceof HTMLAnchorElement&&(s.href=r,s.target="_blank",s.rel="noopener noreferrer"),n.css(s,{display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:`1px solid ${n.BORDER_COLOR}`,backgroundColor:e.cardBackground,color:e.cardColor,fontSize:"13px",textDecoration:"none",maxWidth:"220px"});const d=document.createElement("span");d.textContent="📄",d.setAttribute("aria-hidden","true"),n.css(d,{fontSize:"16px",lineHeight:"1",flexShrink:"0"});const c=n.div({display:"flex",flexDirection:"column",minWidth:"0"}),b=n.div({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"});b.textContent=i.name,b.title=i.name,c.appendChild(b);const f=Ee.formatFileSize(i.fileSize);if(f){const p=n.div({fontSize:"11px",color:n.MUTED_TEXT_COLOR});p.textContent=f,c.appendChild(p)}s.append(d,c),o.appendChild(s)}return o}function wo(t,e){const o=e.look==="embed",i=n.div({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:o?"16px":"10px"});i.className="ago-message__followups";for(const r of t){const s=document.createElement("button");if(s.type="button",s.className="ago-message__followup-btn",s.textContent=r,s.disabled=!e.enabled,n.css(s,o?{display:"inline-flex",alignItems:"center",padding:"8px",fontSize:"14px",lineHeight:"20px",font:"inherit",color:"#525252",backgroundColor:"#fff",border:"1px solid #e5e5e5",borderRadius:"12px",boxShadow:"0 1px 2px 0 rgba(0,0,0,0.05)",cursor:e.enabled?"pointer":"default",transition:"background-color 0.15s"}:{minHeight:"44px",padding:"6px 14px",fontSize:"14px",borderRadius:n.MESSAGE_RADIUS,border:`1px solid ${n.BORDER_COLOR}`,backgroundColor:n.PANEL_BACKGROUND,color:n.TEXT_COLOR,cursor:e.enabled?"pointer":"default",transition:"border-color 0.15s"}),e.handler){const d=e.handler;s.addEventListener("click",()=>d(r))}s.addEventListener("mouseenter",()=>{o?s.style.backgroundColor="#fafafa":s.style.borderColor=n.ACCENT_COLOR}),s.addEventListener("mouseleave",()=>{o?s.style.backgroundColor="#fff":s.style.borderColor=n.BORDER_COLOR}),i.appendChild(s)}return i}function Wi(t,e){const{isLast:o,isLastOfBlock:i,bubbleStyle:r,showAgentName:s,agentBubble:d,followUpEnabled:c,followUpHandler:b,isMobile:f,feedbackRow:p}=e,y=t.role==="user",B=r==="imessage",E=n.div({display:"flex",flexDirection:"column",alignItems:y?"flex-end":"flex-start",marginBottom:B&&!i?"2px":"16px"});if(E.className=`ago-message ago-message--${t.role}`,!y&&s&&t.agent){const k=n.div({fontSize:"13px",fontWeight:"500",color:n.TEXT_COLOR,marginBottom:"6px",padding:"0 4px"});k.className="ago-message__agent",k.textContent=t.agent.displayName||t.agent.name,E.appendChild(k)}if(!y&&t.sources&&t.sources.length>0){const k=n.div({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});k.className="ago-message__sources",t.sources.forEach((F,z)=>{const w=F.url?document.createElement("a"):document.createElement("div");F.url&&w instanceof HTMLAnchorElement&&(w.href=F.url,w.target="_blank",w.rel="noopener noreferrer"),n.css(w,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"8px",backgroundColor:n.PANEL_BACKGROUND,textDecoration:"none",color:n.TEXT_COLOR,fontSize:"12px",overflow:"hidden"});const D=n.div({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${n.ACCENT_COLOR}`,color:n.ACCENT_COLOR,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});D.textContent=String(z+1);const v=n.div({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});v.textContent=F.title,v.title=F.title,w.append(D,v),k.appendChild(w)}),E.appendChild(k)}if(t.attachments&&t.attachments.length>0&&E.appendChild(Ui(t.attachments,{isUser:y,cardBackground:y?"rgba(255,255,255,0.12)":n.PANEL_BACKGROUND,cardColor:y?n.BRAND_TEXT_COLOR:n.TEXT_COLOR})),!y&&e.renderToolCall&&t.toolCalls?.length)for(const k of t.toolCalls){const F=e.renderToolCall(k,t);F&&E.appendChild(F)}const u=y||d||B,C=!!t.content||t.status==="IN_PROGRESS"||t.status==="WAITING_CLIENT",A=n.div({maxWidth:u?B||y?f?"88%":"75%":f?"92%":"85%":"100%",padding:u?"10px 14px":"2px 8px",borderRadius:B?n.MESSAGE_RADIUS_IMESSAGE:u?n.MESSAGE_RADIUS:"0",backgroundColor:y?n.BRAND_COLOR:u?n.AGENT_BUBBLE_BACKGROUND:"transparent",color:y?n.BRAND_TEXT_COLOR:n.TEXT_COLOR,overflowWrap:"break-word",textWrap:"pretty",fontSize:"16px",lineHeight:"1.6"});if(A.className="ago-message__content",B&&i){A.style.position="relative";const k=n.div({position:"absolute",zIndex:"0",bottom:"-2px",width:"20px",height:"20px",background:y?n.BRAND_COLOR:n.AGENT_BUBBLE_BACKGROUND});k.className="ago-message__tail";const F=n.div({position:"absolute",zIndex:"1",bottom:"-2px",width:"10px",height:"20px",background:n.MESSAGES_BACKGROUND});F.className="ago-message__tail-mask",y?(k.style.right="-8px",k.style.borderBottomLeftRadius="16px 14px",F.style.right="-10px",F.style.borderBottomLeftRadius="10px"):(k.style.left="-7px",k.style.borderBottomRightRadius="16px 14px",F.style.left="-10px",F.style.borderBottomRightRadius="10px"),A.append(k,F)}return t.content?A.appendChild(He(t.content)):(t.status==="IN_PROGRESS"||t.status==="WAITING_CLIENT")&&A.appendChild(ji()),C&&E.appendChild(A),!y&&p&&E.appendChild(p),o&&t.followUpReplies&&t.followUpReplies.length>0&&E.appendChild(wo(t.followUpReplies,{enabled:c,handler:b,look:"classic"})),E}function Pi(t){const e=n.div({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:n.MESSAGE_RADIUS,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});e.className="ago-form-notice",e.setAttribute("role","status");const o=document.createElement("span");o.textContent="✓",o.setAttribute("aria-hidden","true"),n.css(o,{fontWeight:"700"});const i=document.createElement("span");return i.textContent=t,e.append(o,i),e}function ji(){const t=n.div({display:"flex",gap:"4px",padding:"4px 0"});for(let e=0;e<3;e++){const o=n.div({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"currentColor",opacity:"0.55",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${e*.2}s`});t.appendChild(o)}return t}function qi(){const t="http://www.w3.org/2000/svg",e=document.createElementNS(t,"svg");e.setAttribute("width","26"),e.setAttribute("height","26"),e.setAttribute("viewBox","0 0 24 24"),e.setAttribute("fill","none");const o=document.createElementNS(t,"path");return o.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"),o.setAttribute("stroke","currentColor"),o.setAttribute("stroke-width","2"),o.setAttribute("stroke-linecap","round"),o.setAttribute("stroke-linejoin","round"),e.appendChild(o),e}function Vi(t){const e=document.createElement("button");if(e.type="button",e.className="ago-chat-widget-launcher",e.setAttribute("aria-label",`Open ${t.title}`),e.setAttribute("aria-expanded","false"),t.look==="classic"){if(n.css(e,{position:"fixed",bottom:"20px",[t.edge]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:n.BRAND_COLOR,color:n.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:n.FONT_VAR}),t.icon){const r=document.createElement("img");r.src=t.icon,r.alt="",n.css(r,{width:"26px",height:"26px",objectFit:"contain"}),e.appendChild(r)}else e.appendChild(qi());return e.addEventListener("click",t.onClick),{el:e,setOpen:r=>{e.setAttribute("aria-expanded",r?"true":"false"),e.setAttribute("aria-label",`${r?"Close":"Open"} ${t.title}`)}}}n.css(e,{position:"fixed",bottom:"20px",[t.edge]:"20px",width:"54px",height:"54px",padding:"12px",margin:"0",boxSizing:"border-box",border:"none",borderRadius:"50%",backgroundColor:n.LAUNCHER_BACKGROUND,color:n.LAUNCHER_TEXT_COLOR,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",boxShadow:"0 4px 12px rgba(123, 123, 123, 0.3)",transition:"scale 0.2s ease",zIndex:"2147483001",transform:"translateZ(0)",backfaceVisibility:"hidden",willChange:"transform",contain:"layout style paint",fontFamily:n.FONT_VAR}),e.addEventListener("mouseenter",()=>{e.style.scale="1.1",e.style.boxShadow="0 6px 16px rgba(123, 123, 123, 0.4)"}),e.addEventListener("mouseleave",()=>{e.style.scale="1",e.style.boxShadow="0 4px 12px rgba(123, 123, 123, 0.3)"});let o,i;if(t.icon){const r=document.createElement("img");r.src=t.icon,r.alt="",n.css(r,{width:"32px",height:"32px",objectFit:"contain"}),o=r,i=mi(),e.append(r,i)}else{const r=fi();o=r.querySelector('[data-ago-path="open"]'),i=r.querySelector('[data-ago-path="close"]'),e.appendChild(r)}return i.style.display="none",e.addEventListener("click",t.onClick),{el:e,setOpen:r=>{o.style.display=r?"none":"",i.style.display=r?"":"none",e.setAttribute("aria-expanded",r?"true":"false"),e.setAttribute("aria-label",`${r?"Close":"Open"} ${t.title}`)}}}function Gi(t){const e=n.div({marginBottom:"12px",display:"flex",flexWrap:"wrap",gap:"8px"});e.className="ago-message__attachments";for(const o of t.attachments??[]){const i=Ee.safeAttachmentUrl(o.url),r=n.div({display:"flex",alignItems:"center",gap:"8px",backgroundColor:"#f3f4f6",borderRadius:"8px",padding:"8px 12px",fontSize:"14px",lineHeight:"20px",maxWidth:"100%",boxSizing:"border-box"});if(Ee.canInlineImage(o)&&i){const s=document.createElement("a");s.href=i,s.target="_blank",s.rel="noopener noreferrer",n.css(s,{display:"flex",flexDirection:"column",gap:"4px",textDecoration:"none",color:"inherit"});const d=document.createElement("img");d.src=i,d.alt=o.name,d.loading="lazy",n.css(d,{height:"128px",maxWidth:"100%",objectFit:"contain",borderRadius:"4px",display:"block"});const c=n.div({fontSize:"12px",lineHeight:"16px",color:"#4b5563",maxWidth:"150px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});c.textContent=o.name,s.append(d,c),r.appendChild(s)}else{const s=i?document.createElement("a"):document.createElement("span");i&&s instanceof HTMLAnchorElement&&(s.href=i,s.target="_blank",s.rel="noopener noreferrer",s.download=o.name),n.css(s,{display:"flex",alignItems:"center",gap:"8px",textDecoration:"none",color:"inherit",minWidth:"0"});const d=document.createElement("span");d.textContent=o.name,d.title=o.name,n.css(d,{maxWidth:"150px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),s.append(Ei({size:20}),d);const c=Ee.formatFileSize(o.fileSize);if(c){const b=document.createElement("span");b.textContent=c,n.css(b,{fontSize:"12px",lineHeight:"16px",color:"#6b7280"}),s.appendChild(b)}r.appendChild(s)}e.appendChild(r)}return e}function Xi(t){const e=n.div({display:"flex",justifyContent:"flex-end"}),o=n.div({maxWidth:"70%",borderRadius:"16px",marginBottom:"16px",padding:"16px",backgroundColor:n.USER_BUBBLE_BACKGROUND_EMBED,color:n.USER_BUBBLE_TEXT_EMBED,boxSizing:"border-box",fontSize:"14px",lineHeight:"24px"});o.className="ago-message__content",t.attachments?.length&&o.appendChild(Gi(t));const i=n.div({whiteSpace:"pre-wrap",overflowWrap:"break-word"});return i.textContent=t.content,o.appendChild(i),e.appendChild(o),e}function Zi(t){const e=n.div({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px",paddingBottom:"16px"});return e.className="ago-message__sources",(t.sources??[]).forEach((o,i)=>{const r=o.url?document.createElement("a"):document.createElement("div");o.url&&r instanceof HTMLAnchorElement&&(r.href=o.url,r.target="_blank",r.rel="noopener noreferrer"),n.css(r,{display:"inline-flex",alignItems:"center",height:"48px",justifyContent:"flex-start",padding:"8px 16px",border:`1px solid ${n.NEUTRAL_BORDER}`,backgroundColor:"#fff",borderRadius:"6px",boxShadow:n.SHADOW_SM,fontSize:"14px",fontWeight:"500",color:n.TEXT_COLOR,textDecoration:"none",overflow:"hidden",boxSizing:"border-box",transition:"background-color 0.15s"}),r.addEventListener("mouseenter",()=>{r.style.backgroundColor="#f5f5f5"}),r.addEventListener("mouseleave",()=>{r.style.backgroundColor="#fff"});const s=n.div({display:"flex",alignItems:"center",gap:"8px",width:"100%",minWidth:"0"}),d=n.div({flexShrink:"0",width:"16px",height:"16px",borderRadius:"4px",border:`1px solid ${n.PRIMARY_ACCENT}`,color:n.PRIMARY_ACCENT,backgroundColor:n.PRIMARY_FOREGROUND,fontSize:"12px",lineHeight:"1",display:"flex",alignItems:"center",justifyContent:"center"});d.textContent=String(i+1);const c=n.div({fontSize:"12px",lineHeight:"16px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:"0"});c.textContent=o.title,c.title=o.title,s.append(d,c),r.appendChild(s),e.appendChild(r)}),e}function Ki(t,e){return Eo({errorTitle:t,errorDescription:e})}function Eo(t){const e=n.div({position:"relative",width:"100%",borderRadius:"12px",border:"1px solid rgba(239, 68, 68, 0.5)",padding:"12px 16px 12px 44px",fontSize:"14px",lineHeight:"20px",color:"#ef4444",backgroundColor:"#fff",boxSizing:"border-box"});e.className="ago-message__error",e.setAttribute("role","alert");const o=Ti({size:16});n.css(o,{position:"absolute",left:"16px",top:"16px"});const i=document.createElement("h5");i.textContent=t.errorTitle,n.css(i,{margin:"0 0 4px",fontSize:"14px",fontWeight:"500",lineHeight:"1",letterSpacing:"-0.025em"});const r=n.div({fontSize:"14px",lineHeight:"1.625"});return r.textContent=t.errorDescription,e.append(o,i,r),e}function Yi(){const t=n.div({marginTop:"4px",animation:"ago-skeleton-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"});t.className="ago-message__skeleton";const e=n.div({height:"16px",backgroundColor:"#f1f5f9",borderRadius:"4px",width:"75%",marginBottom:"10px"});return t.appendChild(e),t}function Qi(){const t=n.div({display:"flex",alignItems:"center",padding:"8px",gap:"8px"});t.className="ago-message__spinner";const e=Ri({size:20});return n.css(e,{color:"#a1a1aa",animation:"ago-spin 1s linear infinite"}),t.appendChild(e),t}function Ji(t,e){const o=t.status==="IN_PROGRESS"||t.status==="WAITING_CLIENT",i=n.div({position:"relative",display:"flex",alignItems:"flex-start",borderRadius:"16px",padding:"8px",marginBottom:"16px",boxSizing:"border-box"});i.className="ago-message__row",e.agentRowTinted&&(i.style.backgroundColor=n.AGENT_BUBBLE_BACKGROUND),e.agentRowTextTinted&&(i.style.color=n.AGENT_BUBBLE_TEXT);const r=n.div({flex:"1",minWidth:"0",overflow:"hidden",padding:"0 4px",fontSize:"14px",lineHeight:"24px"});if(r.className="ago-message__body",o&&r.appendChild(Qi()),t.sources?.length&&r.appendChild(Zi(t)),e.renderToolCall&&t.toolCalls?.length)for(const s of t.toolCalls){const d=e.renderToolCall(s,t);d&&r.appendChild(d)}if(t.status==="ERROR")r.appendChild(Eo(e.labels));else if(t.content){const s=n.div({});s.className="ago-message__markdown ago-message__content",s.appendChild(He(t.content)),r.appendChild(s)}else o&&r.appendChild(Yi());return e.isLast&&t.status==="DONE"&&t.followUpReplies?.length&&r.appendChild(wo(t.followUpReplies,{enabled:e.followUpEnabled,handler:e.followUpHandler,look:"embed"})),e.actionsRow&&!o&&r.appendChild(e.actionsRow),i.appendChild(r),i}function er(t,e){const o=n.div({});return o.className=`ago-message ago-message--${t.role}`,o.dataset.messageId=t.id,o.dataset.messageRole=t.role,o.appendChild(t.role==="user"?Xi(t):Ji(t,e)),o}var pn="ago-hs-form-ready";function tr(t,e){const o=t.tagName==="TEXTAREA"?Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,"value"):Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value"),i=t._valueTracker;i&&i.setValue(""),t.focus(),t.dispatchEvent(new Event("focus",{bubbles:!0})),o?.set?o.set.call(t,e):t.value=e,t.setAttribute("value",e),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})),t.dispatchEvent(new Event("blur",{bubbles:!0}))}function Dt(t,e){const o=t.querySelectorAll("input, textarea, select");let i=!1;for(const r of o){if(r.type==="hidden"||r.type==="submit"||r.type==="button")continue;const s=e[r.name]??(r.name.includes("/")?e[r.name.split("/").pop()]:void 0);s&&!r.value&&(tr(r,s),i=!0)}return i}function nr(t){return`function($f){document.dispatchEvent(new CustomEvent(${JSON.stringify(pn)},{detail:{token:${JSON.stringify(t)},form:$f}}))}`}function or(t,e,o){return!t||!e||Object.keys(e).length===0?t:/hbspt\.forms\.create\s*\(\s*\{/.test(t)&&!/onFormReady/.test(t)?t.replace(/hbspt\.forms\.create\s*\(\s*\{/g,`hbspt.forms.create({onFormReady:${nr(o)},`):t}function ir(t,e){if(!t||Object.keys(t).length===0)return()=>{};const o={};for(const[d,c]of Object.entries(t))c!=null&&c!==""&&(o[d]=c);const i=[],r=[],s=d=>{const c=d.detail;if(!c||c.token!==e)return;const b=c.form,f=b&&typeof b=="object"&&"jquery"in b&&b.jquery?b[0]:b;if(!f||typeof f.querySelectorAll!="function")return;Dt(f,o);const p=new MutationObserver(()=>{Dt(f,o)});p.observe(f,{childList:!0,subtree:!0}),i.push(p),r.push(setTimeout(()=>p.disconnect(),1e4))};return document.addEventListener(pn,s),()=>{document.removeEventListener(pn,s),i.forEach(d=>d.disconnect()),r.forEach(d=>clearTimeout(d))}}function ko(){return globalThis.HubSpotFormsV4}async function _o(t,e){let o=null;if(t.getFormFieldValues)try{const i=await t.getFormFieldValues();let r=[];Array.isArray(i)?r=i.filter(s=>typeof s=="object"&&s!==null).map(s=>s.name).filter(s=>typeof s=="string"):typeof i=="object"&&i!==null&&(r=Object.keys(i)),r.length>0&&(o=r)}catch{}for(const[i,r]of Object.entries(e)){if(!r)continue;let s;if(i.includes("/"))s=i;else if(o){const d=o.find(c=>c.endsWith("/"+i));if(!d)continue;s=d}else s=`0-1/${i}`;try{t.setFieldValue(s,r)}catch{}}}function ao(t){if(!t||Object.keys(t).length===0)return()=>{};const e=o=>{try{const i=ko()?.getFormFromEvent?.(o);if(!i?.setFieldValue)return;_o(i,t)}catch{}};return window.addEventListener("hs-form-event:on-ready",e),()=>window.removeEventListener("hs-form-event:on-ready",e)}function rr(t){const e=ko()?.getForms?.();if(!Array.isArray(e)||e.length===0)return!1;for(const o of e)o?.setFieldValue&&_o(o,t);return!0}var un="ago-hs-form-submit",fn="ago-hs-form-submitted";function It(t){if(!t||typeof t!="object")return t;let e;if(Array.isArray(t)){e={};for(const i of t)i&&typeof i=="object"&&"name"in i&&i.name&&i.value!==void 0&&(e[i.name]=i.value)}else e=t;const o={};for(const[i,r]of Object.entries(e)){const s=i.replace(/^\d+-\d+\//,"");s.startsWith("hs_")||s.startsWith("HS_")||s==="LEGAL_CONSENT"||s==="legal_consent"||s!=="goToWebinarWebinarKey"&&(r===""||r===null||r===void 0||typeof r=="string"&&r.length>2e3||(o[s]=r))}return Object.keys(o).length>0?o:null}function ar(t){try{const e=new FormData(t),o={};return e.forEach((i,r)=>{i instanceof File||(o[r]=i)}),Object.keys(o).length>0?o:null}catch{return null}}function so(t,e,o){const i=o?`{token:${JSON.stringify(e)},form:$f}`:`{token:${JSON.stringify(e)}}`;return`function(${o?"$f":""}){document.dispatchEvent(new CustomEvent(${JSON.stringify(t)},{detail:${i}}))}`}function sr(t,e){return t&&(/hbspt\.forms\.create\s*\(\s*\{/.test(t)&&!t.includes("ago-hs-form-submitted")?t.replace(/hbspt\.forms\.create\s*\(\s*\{/g,`hbspt.forms.create({onFormSubmit:${so(un,e,!0)},onFormSubmitted:${so(fn,e,!1)},`):t)}function lr(t,e,o,i){let r=!1,s=null;function d(){r||(r=!0,e(It(s)))}function c(u){if(s||(s=ar(u)),u.closest(".hs-form, .hbspt-form, [data-hs-forms]")){o?.();return}d()}const b=u=>{const C=u.target;C?.tagName==="FORM"&&c(C)};t.addEventListener("submit",b,!0);const f=new WeakSet;function p(u){f.has(u)||(f.add(u),u.addEventListener("submit",()=>c(u)))}for(const u of t.querySelectorAll("form"))p(u);const y=new MutationObserver(()=>{for(const u of t.querySelectorAll("form"))p(u)});y.observe(t,{childList:!0,subtree:!0});const B=u=>{const C=u.detail;if(!(!C||C.token!==i))try{const A=C.form,k=A&&typeof A=="object"&&"jquery"in A&&A.jquery?A[0]:A;if(k?.querySelectorAll){const F=k.querySelectorAll("input, textarea, select"),z={};for(const w of F)w.name&&w.type!=="submit"&&w.type!=="button"&&(z[w.name]=w.value||"");Object.keys(z).length>0&&(s=z)}}catch{}},E=u=>{const C=u.detail;!C||C.token!==i||d()};return document.addEventListener(un,B),document.addEventListener(fn,E),()=>{t.removeEventListener("submit",b,!0),y.disconnect(),document.removeEventListener(un,B),document.removeEventListener(fn,E)}}function oe(t){return t.externalId||t.id}function So(t){return t.conditionalFieldValues?.length?t.conditionalFieldValues:t.conditionalFieldValue?.split(",").map(e=>e.trim()).filter(Boolean)??[]}function xn(t,e){return!t.priorityTypologies?.length||!e||t.priorityTypologies.includes(e)}function To(t,e,o,i,r,s){if(!e||!o.length)return!0;const d=t.fields.find(c=>c.id===e||c.externalId===e);return d?Ht(t,d,i,r,s)&&o.includes(i[oe(d)]):!0}function Ht(t,e,o,i="",r=new Set){if(e.active===!1||r.has(e.id)||e.title==="Priority"&&!xn(t,i))return!1;const s=new Set(r).add(e.id);return To(t,e.conditionalFieldId,So(e),o,i,s)}function Ro(t,e,o,i=""){return e.options.filter(r=>To(t,r.conditionalFieldId,r.conditionalFieldValues??[],o,i,new Set)).sort((r,s)=>(r.position??0)-(s.position??0))}function Ge(t,e,o=""){let i;do{i=!1;for(const r of t.fields){const s=oe(r);if(!(s in e))continue;const d=!r.options.length||!e[s]||Ro(t,r,e,o).some(c=>(c.value??c.name??"")===e[s]);(!Ht(t,r,e,o)||!d)&&(delete e[s],i=!0)}}while(i)}function dr(t,e,o=""){const i=[...t.fields].sort((r,s)=>r.position-s.position).filter(r=>!r.hidden&&Ht(t,r,e,o));return i.filter((r,s)=>{if(s===0||r.alwaysVisible||r.conditionalFieldId&&So(r).length)return!0;const d=i[s-1];return d.type==="checkbox"||!!e[oe(d)]?.trim()})}var cr="var(--ago-send-button-background, var(--ago-accent-color, #003edf))",pr=/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z]{2,}$/;function ur(t){return t.toLowerCase().trim().replace(/[^a-z0-9_]/g,"_")}function Ao(t,e,o){const i={};if(e){for(const r of e.fields){if(r.active===!1)continue;const s=r.options.find(d=>d.default);s&&(i[oe(r)]=s.value??s.name??"")}if(t?.tag)for(const r of e.fields)r.type==="tagger"&&(i[oe(r)]=t.tag);if(t?.custom_fields)for(const[r,s]of Object.entries(t.custom_fields)){const d=e.fields.find(c=>c.externalId===r||c.id===r||(c.title?ur(c.title)===r:!1));d&&(i[oe(d)]=s)}}return e&&Ge(e,i,t?.typology??"Question"),{ticket:{subject:t?.subject??"",typology:t?.typology??"Question",priority:t?.priority??"Normal",body:t?.body??"",tag:t?.tag??""},customFields:i,files:[],email:o,errors:{},submittedOnce:!1,loading:!1,submitError:null}}function fr(t,e,o){t.customFields={...Ao(e,o,t.email).customFields,...t.customFields},Ge(o,t.customFields,t.ticket.typology)}function lo(t,e){return t.replace(/\{(\w+)\}/g,(o,i)=>e[i]??"")}function mr(t,e,o,i){const r={},s=e.ticket;t.showSubject&&!s.subject.trim()&&(r.subject=o.subjectRequired),t.showTypology&&!s.typology.trim()&&(r.typology=o.typologyRequired),t.showPriority&&xn(t,s.typology)&&!s.priority.trim()&&(r.priority=o.priorityRequired),t.showBody&&!s.body.trim()&&(r.body=o.detailedContextRequired);for(const d of t.fields){if(d.hidden||!Ht(t,d,e.customFields,s.typology))continue;const c=e.customFields[oe(d)];if(d.required&&!c?.trim())r[oe(d)]=lo(o.fieldRequired,{fieldTitle:d.title??""});else if(d.regexpForValidation&&c?.trim())try{new RegExp(d.regexpForValidation).test(c)||(r[oe(d)]=lo(o.fieldFormatInvalid,{fieldTitle:d.title??""}))}catch{}}return i&&(e.email.trim()?pr.test(e.email)||(r.userEmail=o.emailInvalid):r.userEmail=o.emailRequired),r}var gr={border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"4px",width:"100%",padding:"8px",boxSizing:"border-box",fontSize:"16px",lineHeight:"24px",fontFamily:n.FONT_VAR,color:n.TEXT_COLOR,backgroundColor:n.PANEL_BACKGROUND};function Fe(t,e){const o=document.createElement("label");return o.htmlFor=e,o.textContent=t,n.css(o,{display:"block",fontWeight:"600"}),o}function ge(t){const e=document.createElement("p");return e.className="ago-ticket-form__error",e.textContent=t,n.css(e,{color:"#ef4444",fontSize:"14px",lineHeight:"20px",margin:"0"}),e}function Ie(){const t=n.div({display:"flex",flexDirection:"column",gap:"8px"});return t.className="ago-ticket-form__field",t}function De(t,e,o){n.css(t,gr),e&&(t.style.borderColor="#ef4444"),t.disabled=o,o&&(t.style.opacity="0.5",t.style.cursor="not-allowed"),t.addEventListener("focus",()=>{t.style.outline="2px solid var(--ago-accent-color, #003edf)",t.style.outlineOffset="1px"}),t.addEventListener("blur",()=>{t.style.outline="",t.style.outlineOffset=""})}function Oo(t){const e=n.div({padding:"16px",borderRadius:"4px",backgroundColor:"#dcfce7",color:"#166534",fontSize:"16px",lineHeight:"24px"});e.className="ago-ticket-form__success",e.setAttribute("role","status");const o=document.createElement("p");if(o.textContent=t.text,n.css(o,{whiteSpace:"pre-line",margin:"0"}),e.appendChild(o),t.ticketUrl){const i=n.div({marginTop:"4px"});if(i.append(document.createTextNode(`${t.urlLabel} `)),t.ticketUrl.startsWith("http")){const r=document.createElement("a");r.href=t.ticketUrl,r.target="_blank",r.rel="noreferrer noopener",r.textContent=t.ticketUrl,n.css(r,{fontWeight:"700",textDecoration:"underline",color:"#166534"}),i.appendChild(r)}else{const r=document.createElement("span");r.textContent=t.ticketUrl,r.style.fontWeight="700",i.appendChild(r)}e.appendChild(i)}return e}function hr(t){const e=n.div({width:"100%",padding:"16px",backgroundColor:"#fefce8",border:"1px solid #fef08a",borderRadius:"6px",display:"flex",gap:"12px",alignItems:"flex-start",color:"#854d0e",boxSizing:"border-box",fontSize:"16px",lineHeight:"24px"});e.className="ago-ticket-form__denied";const o=document.createElement("span");o.textContent="i",o.setAttribute("aria-hidden","true"),n.css(o,{flexShrink:"0",width:"20px",height:"20px",marginTop:"2px",borderRadius:"50%",border:"2px solid #ca8a04",color:"#ca8a04",fontSize:"13px",fontWeight:"700",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:"1"});const i=n.div({minWidth:"0"});return i.appendChild(He(t)),e.append(o,i),e}function br(t){const{state:e,labels:o}=t;let i=t.ticketForm,r=t.configLoading,s=t.allowFiles;const d=n.div({position:"relative",width:"100%",display:"flex",flexDirection:"column",gap:"16px",paddingBottom:"16px",fontSize:"16px",lineHeight:"24px",color:n.TEXT_COLOR,boxSizing:"border-box"});d.className="ago-ticket-form";function c(){return i?(e.errors=mr(i,e,o,t.requireEmail),Object.keys(e.errors).length===0):!1}async function b(){if(!(e.loading||!i)){if(Ge(i,e.customFields,e.ticket.typology),e.submittedOnce=!0,e.submitError=null,!c()){e.submitError=`${o.validationFailed}: ${o.pleaseCheckFields}`,E();return}e.loading=!0,E();try{const u=await t.createTicket({subject:e.ticket.subject,typology:e.ticket.typology||"Question",priority:e.ticket.priority||"Normal",body:e.ticket.body,files:e.files,customFields:Object.entries(e.customFields).map(([C,A])=>({id:C,value:A})),email:t.requireEmail?e.email:void 0,ticketFormId:i.id});e.loading=!1,e.submitted={ticketId:u.id,ticketUrl:u.url},E(),t.onCreated(u,e)}catch(u){e.loading=!1;const C=u instanceof Error?u:new Error(String(u)),A=C.status;let k=o.submissionFailed,F=o.submissionFailedDescription;A===413?k=o.fileTooLarge:A===403?k=o.permissionDenied:A===422?(k=o.validationFailed,F=C.message||o.pleaseCheckFields):C.message&&(F=C.message),e.submitError=`${k}: ${F}`,E(),t.onError?.(C)}}}function f(u,C){const A=oe(u);e.customFields[A]=C,i&&Ge(i,e.customFields,e.ticket.typology),e.submittedOnce&&c(),E()}function p(){e.submittedOnce&&c()}function y(u){const C=oe(u),A=`ago-ticket-field-${C}`,k=e.customFields[C]??"",F=e.loading,z=e.errors[C];if(u.type==="checkbox"){const x=n.div({display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"});x.className="ago-ticket-form__field";const S=document.createElement("input");S.type="checkbox",S.id=A,S.checked=k==="true",S.disabled=F,n.css(S,{width:"16px",height:"16px",margin:"0"}),S.addEventListener("change",()=>f(u,S.checked?"true":"false"));const W=document.createElement("label");return W.htmlFor=A,W.textContent=u.title??"",W.style.fontWeight="600",x.append(S,W),z&&x.appendChild(ge(z)),x}const w=Ie();w.appendChild(Fe(u.title??"",A));const D=Ro(i,u,e.customFields,e.ticket.typology).filter(x=>!x.noDisplay);if(u.options.length>0){const x=document.createElement("select");x.id=A;const S=document.createElement("option");S.value="",S.textContent="----",x.appendChild(S);const W=new Map;for(const M of D){const P=document.createElement("option");if(P.value=M.value??M.name??"",P.textContent=M.name??M.value??"",M.group){let m=W.get(M.group);m||(m=document.createElement("optgroup"),m.label=M.group,W.set(M.group,m),x.appendChild(m)),m.appendChild(P)}else x.appendChild(P)}x.value=k,De(x,!!z,F),x.addEventListener("change",()=>f(u,x.value)),w.appendChild(x);const j=D.find(M=>(M.value??M.name)===k);if(z&&w.appendChild(ge(z)),j?.message){const M={info:{bg:"#eff6ff",border:"#bfdbfe",text:"#1e3a8a"},warning:{bg:"#fffbeb",border:"#fcd34d",text:"#78350f"},danger:{bg:"#fef2f2",border:"#fca5a5",text:"#7f1d1d"}}[j.messageType??"info"],P=document.createElement("p");P.className="ago-ticket-form__option-message",P.textContent=j.message,n.css(P,{fontSize:"14px",lineHeight:"20px",border:`1px solid ${M.border}`,backgroundColor:M.bg,color:M.text,borderRadius:"4px",padding:"8px",whiteSpace:"pre-line",margin:"0"}),w.appendChild(P)}return w}const v=document.createElement("input");return v.type="text",v.id=A,v.value=k,De(v,!!z,F),v.addEventListener("input",()=>{e.customFields[C]=v.value,i&&Ge(i,e.customFields,e.ticket.typology),e.submittedOnce&&(c(),B())}),v.addEventListener("change",()=>E()),w.appendChild(v),z&&w.appendChild(ge(z)),w}function B(){for(const u of d.querySelectorAll("[data-ago-error-for]")){const C=u.dataset.agoErrorFor,A=u.querySelector(".ago-ticket-form__error"),k=e.errors[C],F=u.querySelector("input, select, textarea");F&&(F.style.borderColor=k?"#ef4444":""),F&&!k&&(F.style.border=`1px solid ${n.BORDER_COLOR}`),k&&!A?u.appendChild(ge(k)):k&&A?A.textContent=k:!k&&A&&A.remove()}}function E(){if(d.replaceChildren(),t.message){const m=n.div({fontWeight:"500",color:"#1e40af",backgroundColor:"#eff6ff",padding:"12px",borderRadius:"4px"});m.className="ago-ticket-form__message",m.textContent=t.message,d.appendChild(m)}if(e.submitted){d.appendChild(Oo({text:t.successMessage||i?.successMessageText||o.ticketSubmitted,ticketUrl:e.submitted.ticketUrl,urlLabel:t.successUrlLabel||i?.successMessageUrlLabel||o.findTicketHere}));return}if(r){const m=n.div({padding:"16px",textAlign:"center",fontWeight:"700",fontSize:"20px"});m.className="ago-ticket-form__config-loading",m.setAttribute("role","status"),m.textContent=o.loading,d.appendChild(m);return}if(!i){const m=n.div({backgroundColor:"#fee2e2",color:"#991b1b",padding:"16px",borderRadius:"4px"});m.className="ago-ticket-form__missing",m.textContent=o.noTicketForm,d.appendChild(m);return}const u=i,C=e.loading;if(e.loading){const m=n.div({position:"absolute",inset:"0",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(255, 255, 255, 0.7)",zIndex:"5",borderRadius:"16px",fontSize:"20px",fontWeight:"700"});m.className="ago-ticket-form__loading",m.setAttribute("role","status"),m.textContent=o.loading,d.appendChild(m)}const A=n.div({fontWeight:"600",backgroundColor:"#bfdbfe",padding:"16px",borderRadius:"4px"});if(A.className="ago-ticket-form__intro",A.textContent=o.useFormToCreateTicket,d.appendChild(A),t.requireEmail){const m=Ie();m.dataset.agoErrorFor="userEmail",m.appendChild(Fe(`${o.yourEmail} *`,"ago-ticket-email"));const T=document.createElement("input");T.type="email",T.id="ago-ticket-email",T.placeholder=o.emailPlaceholder,T.value=e.email,De(T,!!e.errors.userEmail,C),T.addEventListener("input",()=>{e.email=T.value,e.submittedOnce&&(c(),B())}),m.appendChild(T),e.errors.userEmail&&m.appendChild(ge(e.errors.userEmail)),d.appendChild(m)}const k=u.showSubject&&!!e.ticket.subject||!u.showSubject,F=k&&(!!e.ticket.typology||!u.showTypology),z=u.showPriority&&xn(u,e.ticket.typology),w=F&&(!!e.ticket.priority||!z);if(u.showSubject){const m=Ie();m.dataset.agoErrorFor="subject",m.appendChild(Fe(o.subject,"ago-ticket-subject"));const T=document.createElement("input");T.type="text",T.id="ago-ticket-subject",T.value=e.ticket.subject,De(T,!!e.errors.subject,C),T.addEventListener("input",()=>{e.ticket.subject=T.value,p(),B()}),T.addEventListener("change",()=>E()),m.appendChild(T),e.errors.subject&&m.appendChild(ge(e.errors.subject)),d.appendChild(m)}if(k&&u.showTypology){const m=Ie();m.dataset.agoErrorFor="typology",m.appendChild(Fe(o.typology,"ago-ticket-typology"));const T=document.createElement("select");T.id="ago-ticket-typology";for(const[h,I]of[["",o.selectTypology],["Question",o.question],["Task",o.task],["Incident",o.incident]]){const N=document.createElement("option");N.value=h,N.textContent=I,T.appendChild(N)}T.value=e.ticket.typology,De(T,!!e.errors.typology,C),T.addEventListener("change",()=>{e.ticket.typology=T.value,Ge(u,e.customFields,e.ticket.typology),p(),E()}),m.appendChild(T),e.errors.typology&&m.appendChild(ge(e.errors.typology)),d.appendChild(m)}if(F&&z){const m=Ie();m.dataset.agoErrorFor="priority",m.appendChild(Fe(o.priority,"ago-ticket-priority"));const T=document.createElement("select");T.id="ago-ticket-priority";for(const[h,I]of[["",o.selectPriority],["Low",o.low],["Normal",o.normal],["High",o.high],["Urgent",o.urgent]]){const N=document.createElement("option");N.value=h,N.textContent=I,T.appendChild(N)}T.value=e.ticket.priority,De(T,!!e.errors.priority,C),T.addEventListener("change",()=>{e.ticket.priority=T.value,p(),E()}),m.appendChild(T),e.errors.priority&&m.appendChild(ge(e.errors.priority)),d.appendChild(m)}if(w){const m=new Set(dr(u,e.customFields,e.ticket.typology));for(const T of[...u.fields].sort((h,I)=>h.position-I.position)){if(!m.has(T)&&!e.errors[oe(T)])continue;const h=y(T);h.dataset.agoErrorFor=oe(T),d.appendChild(h)}}const D=Ie();D.dataset.agoErrorFor="body",D.appendChild(Fe(o.detailedContext,"ago-ticket-body"));const v=document.createElement("textarea");v.id="ago-ticket-body",v.rows=4,v.value=e.ticket.body,De(v,!!e.errors.body,C),n.css(v,{resize:"vertical",maxHeight:"240px",overflowY:"auto"});const x=n.div({fontSize:"14px",lineHeight:"20px",marginTop:"4px",textAlign:"right",display:"none"});x.className="ago-ticket-form__counter";const S=()=>{const m=e.ticket.body.length;x.style.display=m>6e4?"block":"none",x.style.color=m>65535?"#dc2626":"#d97706",x.textContent=`${m} / 65,535 · ${o.maxCharacters}`},W=()=>{v.style.height="auto",v.style.height=`${v.scrollHeight}px`};if(v.addEventListener("input",()=>{e.ticket.body=v.value,p(),B(),S(),W()}),D.append(v,x),S(),e.errors.body&&D.appendChild(ge(e.errors.body)),d.appendChild(D),s){const m=Ie();m.className="ago-ticket-form__field ago-ticket-form__attachments",m.appendChild(Fe(o.attachments,"ago-ticket-files"));const T=document.createElement("label");T.htmlFor="ago-ticket-files",T.textContent=o.selectFile,n.css(T,{display:"inline-block",alignSelf:"flex-start",backgroundColor:"#e5e7eb",padding:"8px 16px",borderRadius:"4px",cursor:"pointer",border:"1px solid #d1d5db",minHeight:"24px"});const h=document.createElement("input");h.type="file",h.id="ago-ticket-files",h.multiple=!0,h.disabled=C,n.css(h,{display:"none"}),h.addEventListener("change",()=>{e.files=[...e.files,...Array.from(h.files??[])],h.value="",E()}),m.append(T,h);const I=n.div({display:"flex",flexDirection:"column",gap:"4px"});e.files.forEach((N,G)=>{const ee=n.div({display:"flex",alignItems:"center",justifyContent:"space-between",backgroundColor:"#f3f4f6",padding:"4px 8px",borderRadius:"4px"}),K=document.createElement("span");K.textContent=`${N.name} - ${(N.size/1024).toFixed(1)} KB`;const X=document.createElement("button");X.type="button",X.textContent="×",X.setAttribute("aria-label",`Remove ${N.name}`),X.disabled=C,n.css(X,{color:"#dc2626",fontWeight:"700",background:"none",border:"none",cursor:"pointer",fontSize:"18px",lineHeight:"1",width:"44px",height:"44px",margin:"-10px -12px -10px 0"}),X.addEventListener("click",()=>{e.files=e.files.filter((Mt,ft)=>ft!==G),E()}),ee.append(K,X),I.appendChild(ee)}),m.appendChild(I),d.appendChild(m)}if(e.submitError){const m=ge(e.submitError);m.setAttribute("role","alert"),m.className="ago-ticket-form__error ago-ticket-form__submit-error",d.appendChild(m)}const j=document.createElement("button");j.type="button",j.className="ago-ticket-form__submit",j.disabled=C,n.css(j,{width:"100%",backgroundColor:cr,color:n.BRAND_TEXT_COLOR,padding:"8px 16px",borderRadius:"4px",border:"none",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",cursor:C?"default":"pointer",fontSize:"16px",lineHeight:"24px",minHeight:"44px",font:"inherit",transition:"filter 0.15s"});const M=document.createElement("span");M.textContent=o.submit;const P=document.createElement("span");P.textContent="→",P.setAttribute("aria-hidden","true"),n.css(P,{fontSize:"20px",lineHeight:"1",transition:"transform 0.15s"}),j.append(M,P),j.addEventListener("mouseenter",()=>{j.style.filter="brightness(0.9)",P.style.transform="translateX(4px)"}),j.addEventListener("mouseleave",()=>{j.style.filter="",P.style.transform=""}),j.addEventListener("click",()=>{b()}),d.appendChild(j)}return E(),{el:d,rebuild:u=>{u&&"ticketForm"in u&&(i=u.ticketForm??null),u&&"configLoading"in u&&(r=!!u.configLoading),u&&"allowFiles"in u&&(s=!!u.allowFiles),E()}}}var xr=0;async function yr(t){const e=Array.from(t.querySelectorAll("script"));for(const o of e){const i=document.createElement("script");for(const r of Array.from(o.attributes))i.setAttribute(r.name,r.value);o.src?await new Promise((r,s)=>{i.onload=()=>r(),i.onerror=()=>s(new Error(`Failed to load script: ${o.src}`)),o.parentNode?.replaceChild(i,o)}):(i.textContent=o.textContent,o.parentNode?.replaceChild(i,o))}}function vr(t,e){const o={};if(t)for(const[i,r]of Object.entries(t))if(i==="custom_fields"&&r&&typeof r=="object")for(const[s,d]of Object.entries(r))d&&(o[s]=d);else typeof r=="string"&&r&&(o[i]=r);return e&&(o.email=e),Object.keys(o).length>0?o:null}function Cr(t){const e=n.div({fontWeight:"500",color:"#1e40af",backgroundColor:"#eff6ff",padding:"12px",borderRadius:"4px",fontSize:"16px",lineHeight:"24px"});return e.className="ago-ticket-form__message",e.textContent=t,e}function wr(t){const{state:e,labels:o}=t,i=`ago-embed-${Date.now().toString(36)}-${++xr}`,r=n.div({display:"flex",flexDirection:"column",gap:"16px"});r.className="ago-embed-form",t.message&&r.appendChild(Cr(t.message));const s=n.div({display:"flex",flexDirection:"column",gap:"12px"});s.className="ago-embed-form__body",r.appendChild(s);const d=[];let c,b=!1,f=e.status==="submitted",p=null;const y=vr(t.ticket,t.email),B=v=>{f||b||(f=!0,c&&(clearTimeout(c),c=void 0),e.status="submitted",e.captured=v??null,D(),t.onSubmitted(v??null))},E=()=>{f||c||(b=!1,c=setTimeout(()=>{f||(c=void 0,e.status="timeout",D())},3e4))},u=()=>{try{const v=globalThis.HubSpotFormsV4?.getForms?.()?.[0];if(v?.getFormFieldValues){const x=new Promise((S,W)=>setTimeout(()=>W(new Error("timeout")),3e3));Promise.race([v.getFormFieldValues(),x]).then(S=>B(It(S))).catch(()=>B(p));return}}catch{}B(p)};window.addEventListener("hs-form-event:on-submission:success",u),d.push(()=>window.removeEventListener("hs-form-event:on-submission:success",u));const C=[],A=v=>{const x=v.data;if(x?.type==="hsFormCallback"&&x.eventName==="onFormSubmit"){try{const S=x.data;if(Array.isArray(S)){const W={};for(const M of S)M?.name&&M.value!==void 0&&(W[M.name]=M.value);const j=It(W);j&&(p=j)}}catch{}return}if(x?.type==="hsFormCallback"&&x.eventName==="onFormSubmitted"){B(p);return}if(x?.type==="HS_CTA_PARENT_INIT"&&v.ports?.[0]){const S=v.ports[0],W=j=>{const M=j.data;if(M?.type==="HS_SEND_FORM_FIELD_VALUES"){const P=M.payload?.formFieldValues;if(P&&typeof P=="object"){const m=It(P);m&&(p=m)}}M?.type==="HS_SEND_FORM_SUBMISSION_SUCCESS"&&B(p)};S.addEventListener("message",W),S.start(),C.push(()=>S.removeEventListener("message",W))}};window.addEventListener("message",A),d.push(()=>{window.removeEventListener("message",A),C.forEach(v=>v())});let k;function F(v){if(!t.embedHtml)return;let x=or(t.embedHtml,y,i);x=sr(x,i);const S=ir(y,i),W=ao(y);v.innerHTML=x;const j=lr(v,B,E,i);let M,P,m;yr(v).catch(()=>{}).then(()=>{e.status==="loading"&&(e.status="ready",z.style.display="none",y&&(Dt(v,y),rr(y),m=ao(y),M=new MutationObserver(()=>Dt(v,y)),M.observe(v,{childList:!0,subtree:!0}),P=setTimeout(()=>M?.disconnect(),1e4)))}),k=()=>{S(),W(),j(),M?.disconnect(),P&&clearTimeout(P),m?.(),v.innerHTML=""}}const z=n.div({position:"absolute",inset:"0",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(255, 255, 255, 0.8)",zIndex:"10"});z.className="ago-embed-form__loading";const w=n.div({width:"24px",height:"24px",borderRadius:"50%",border:`2px solid ${n.EMBED_MUTED_TEXT}`,borderTopColor:"transparent",animation:"ago-spin 1s linear infinite"});w.setAttribute("role","status"),z.appendChild(w);function D(){if(s.replaceChildren(),e.status==="timeout"){const x=n.div({borderRadius:"8px",border:"1px solid #fef08a",backgroundColor:"#fefce8",padding:"16px",display:"flex",flexDirection:"column",gap:"12px"});x.className="ago-embed-form__timeout";const S=document.createElement("p");S.textContent=o.embedSubmitTimeout,n.css(S,{fontSize:"14px",lineHeight:"20px",color:"#854d0e",margin:"0"});const W=document.createElement("button");W.type="button",W.textContent=o.tryAgain,n.css(W,{alignSelf:"flex-start",fontSize:"14px",fontWeight:"500",color:"#854d0e",textDecoration:"underline",background:"none",border:"none",padding:"0",cursor:"pointer",minHeight:"44px",font:"inherit"}),W.addEventListener("click",()=>{b=!0,f=!1,c=void 0,e.status="ready",D()}),x.append(S,W),s.appendChild(x);return}if(e.status==="submitted"){s.appendChild(Oo({text:t.successMessage||o.embeddedFormSubmitted,urlLabel:o.findTicketHere}));return}if(t.description){const x=document.createElement("p");x.textContent=t.description,n.css(x,{fontSize:"14px",lineHeight:"20px",margin:"0"}),s.appendChild(x)}const v=n.div({position:"relative",borderRadius:"8px",border:`1px solid ${n.BORDER_COLOR}`,overflow:"hidden"});if(v.className="ago-embed-form__frame",t.embedHtml){z.style.display=e.status==="loading"?"flex":"none",v.appendChild(z);const x=n.div({width:"100%",minHeight:"200px"});x.className="ago-embed-form__host",v.appendChild(x),k?.(),F(x)}else{const x=n.div({padding:"24px",textAlign:"center",color:n.EMBED_MUTED_TEXT,fontSize:"14px"});x.textContent=o.noEmbedConfigured,v.appendChild(x)}s.appendChild(v)}return D(),{el:r,destroy:()=>{c&&clearTimeout(c),k?.(),d.forEach(v=>v())}}}function Er(t){return t.type==="form"&&t.toolName==="ago_ticketing"}function kr(t){let e=null;for(const o of t)for(const i of o.toolCalls??[])i.type==="form"&&(e=i.id);return e}function _r(t){return t.some(e=>(e.toolCalls??[]).some(o=>{if(o.type!=="form")return!1;const i=o.data;return i?.success===!0&&!!i.ticket?.ticket_id}))}function co(t){const e=t.data;return e?.success!==!0||!e.ticket?.ticket_id?null:{ticketId:String(e.ticket.ticket_id),ticketUrl:typeof e.ticket.ticket_url=="string"&&e.ticket.ticket_url?e.ticket.ticket_url:void 0}}var Sr={info:{border:"#bfdbfe",bg:"#eff6ff",text:"#1e40af"},warning:{border:"#fef08a",bg:"#fefce8",text:"#854d0e"},success:{border:"#bbf7d0",bg:"#f0fdf4",text:"#166534"},error:{border:"#fecaca",bg:"#fef2f2",text:"#991b1b"}};function Tr(t,e="info",o){const i=Sr[e],r=n.div({margin:"8px 0",padding:"12px 16px",border:`1px solid ${i.border}`,backgroundColor:i.bg,color:i.text,borderRadius:"8px",display:"flex",alignItems:"flex-start",gap:"8px",fontSize:"14px",lineHeight:"20px"});if(r.className=`ago-toolcall-status ago-toolcall-status--${e}`,r.setAttribute("role","status"),o){const d=document.createElement("span");d.textContent=`${o}:`,n.css(d,{fontSize:"12px",fontWeight:"500",opacity:"0.7",flexShrink:"0"}),r.appendChild(d)}const s=document.createElement("span");return s.textContent=t,s.style.whiteSpace="pre-wrap",r.appendChild(s),r}function Rr(t,e){const o=n.div({margin:"8px 0",padding:"12px 16px",border:"1px solid #e9d5ff",backgroundColor:"#faf5ff",color:"#6b21a8",borderRadius:"8px",display:"flex",flexDirection:"column",gap:"8px",fontSize:"14px",lineHeight:"20px"});o.className="ago-toolcall-form-placeholder";const i=n.div({display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"});if(t.toolName){const s=document.createElement("span");s.textContent=`${t.toolName}:`,n.css(s,{fontSize:"12px",fontWeight:"500",opacity:"0.7"}),i.appendChild(s)}if(t.message){const s=document.createElement("span");s.textContent=t.message,i.appendChild(s)}i.childElementCount>0&&o.appendChild(i);const r=n.div({opacity:"0.8"});if(r.textContent=e.genericFormComingSoon,t.formSchema){const s=document.createElement("pre");s.textContent=JSON.stringify(t.formSchema,null,2),n.css(s,{fontSize:"12px",lineHeight:"16px",marginTop:"8px",marginBottom:"0",whiteSpace:"pre-wrap",overflowWrap:"anywhere"}),r.appendChild(s)}return o.appendChild(r),o}var Lo={useFormToCreateTicket:"You can use the following form to create a ticket",yourEmail:"Your Email",emailPlaceholder:"Enter your email address",emailRequired:"Email is required",emailInvalid:"Please enter a valid email address",subject:"Subject",subjectRequired:"Subject is required.",typology:"Typology",selectTypology:"Select a typology",typologyRequired:"Typology is required.",question:"Question",task:"Task",incident:"Incident",priority:"Priority",selectPriority:"Select a priority",priorityRequired:"Priority is required.",low:"Low",normal:"Normal",high:"High",urgent:"Urgent",detailedContext:"Detailed context",detailedContextRequired:"Detailed context is required.",fieldRequired:"{fieldTitle} is required.",fieldFormatInvalid:"{fieldTitle} has an invalid format.",attachments:"Attachments",selectFile:"Select file",submit:"Submit",loading:"Loading...",maxCharacters:"Maximum characters",ticketSubmitted:"Your ticket has been successfully submitted.",findTicketHere:"You can find it here:",noTicketForm:"No ticket form found",notAllowed:"You are not allowed to create a ticket.",submissionFailed:"Failed to submit ticket",submissionFailedDescription:"There was an error submitting your ticket. Please try again.",fileTooLarge:"File too large",permissionDenied:"Permission denied",validationFailed:"Validation error",pleaseCheckFields:"Please check your form fields and try again.",embeddedFormSubmitted:"Your form has been submitted successfully.",noEmbedConfigured:"No embed URL or HTML configured for this form.",embedSubmitTimeout:"The form submission could not be confirmed. Please try again.",tryAgain:"Try again",contactFormCreated:"A new contact form has been created, see below to fill it out.",contactFormRejected:"You are not allowed to create a ticket. See below why.",genericFormComingSoon:"Generic form rendering (Coming soon)",unknownToolCall:"Unknown tool call type: {type}",formPending:"Please complete the form above to continue the conversation",ticketCreatedBlocked:`A ticket has been created for this conversation.
|
|
6
|
+
Please create a new conversation to continue.`,newConversation:"New conversation"},mn={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 Ar(){return{detailsOpen:!1,reasons:new Set,comment:"",reported:!1}}var Or={display:"inline-flex",alignItems:"center",justifyContent:"center",width:"44px",height:"44px",margin:"-8px",padding:"0",border:"none",borderRadius:"8px",background:"transparent",color:n.MUTED_TEXT_COLOR,cursor:"pointer",lineHeight:"1"};function Lr(t){const{state:e,labels:o,askWhy:i,onRate:r,onReport:s}=t,d=t.look==="embed",c=d?{idle:"#78716c",hover:"#1c1917",active:"#1c1917"}:{idle:n.MUTED_TEXT_COLOR,hover:n.TEXT_COLOR,active:n.ACCENT_COLOR},b=n.div(d?{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px",width:"100%"}:{marginTop:"6px",width:"100%",maxWidth:"85%"});b.className="ago-feedback";const f=n.div({display:"flex",alignItems:"center",gap:d?"8px":"2px"});f.className="ago-feedback__actions";const p=po("up",o.helpful,e.rating==="positive",c,d);p.addEventListener("click",()=>{e.rating="positive",e.detailsOpen=!1,E(),u(),r("positive")});const y=po("down",o.notHelpful,e.rating==="negative",c,d);y.addEventListener("click",()=>{e.rating="negative",r("negative"),i&&!e.reported&&(e.detailsOpen=!0),E(),u()}),f.append(p,y),d&&b.appendChild(n.div({flex:"1"})),b.appendChild(f);const B=n.div();B.className="ago-feedback__panel-slot",d&&(B.style.flexBasis="100%"),b.appendChild(B);function E(){gn(p,e.rating==="positive",c),gn(y,e.rating==="negative",c)}function u(){if(B.replaceChildren(),e.reported){B.appendChild(Ir(o.thanks));return}e.detailsOpen&&B.appendChild(Fr(e,o,async C=>await s(e.rating??"negative",C)?(e.reported=!0,e.detailsOpen=!1,u(),!0):!1))}return E(),u(),b}function po(t,e,o,i,r=!1){const s=document.createElement("button");return s.type="button",s.className=`ago-feedback__thumb ago-feedback__thumb--${t}`,s.setAttribute("aria-label",e),s.title=e,n.css(s,Or),r?(s.style.margin="-14px",s.appendChild(t==="up"?vi({size:18}):Ci({size:18}))):s.appendChild(Nr(t)),gn(s,o,i),s.addEventListener("mouseenter",()=>{s.getAttribute("aria-pressed")!=="true"&&(s.style.color=i.hover)}),s.addEventListener("mouseleave",()=>{s.getAttribute("aria-pressed")!=="true"&&(s.style.color=i.idle)}),s}function gn(t,e,o){t.setAttribute("aria-pressed",e?"true":"false"),t.style.color=e?o.active:o.idle}function Nr(t){const e="http://www.w3.org/2000/svg",o=document.createElementNS(e,"svg");o.setAttribute("width","16"),o.setAttribute("height","16"),o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("fill","none"),o.setAttribute("aria-hidden","true");const i=document.createElementNS(e,"path");i.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"),i.setAttribute("stroke","currentColor"),i.setAttribute("stroke-width","1.8"),i.setAttribute("stroke-linejoin","round");const r=document.createElementNS(e,"path");return r.setAttribute("d","M7 22V12H4.5A1.5 1.5 0 0 0 3 13.5v7A1.5 1.5 0 0 0 4.5 22z"),r.setAttribute("stroke","currentColor"),r.setAttribute("stroke-width","1.8"),r.setAttribute("stroke-linejoin","round"),o.append(i,r),t==="down"&&(o.style.transform="rotate(180deg)"),o}function Fr(t,e,o){const i=n.div({marginTop:"8px",padding:"12px",border:`1px solid ${n.BORDER_COLOR}`,borderRadius:n.MESSAGE_RADIUS,backgroundColor:n.PANEL_BACKGROUND});i.className="ago-feedback__panel",i.setAttribute("role","group"),i.setAttribute("aria-label",e.whatWentWrong);const r=n.div({fontSize:"13px",fontWeight:"500",color:n.TEXT_COLOR,marginBottom:"8px"});r.textContent=e.whatWentWrong,i.appendChild(r);const s=n.div({display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"8px"});s.className="ago-feedback__reasons";for(const f of Ee.FEEDBACK_REASONS){const p=document.createElement("button");p.type="button",p.className="ago-feedback__reason",p.textContent=e.reasons[f],n.css(p,{minHeight:"44px",padding:"4px 12px",fontSize:"13px",fontFamily:"inherit",borderRadius:"999px",border:`1px solid ${n.BORDER_COLOR}`,backgroundColor:"transparent",color:n.TEXT_COLOR,cursor:"pointer"});const y=()=>{const B=t.reasons.has(f);p.setAttribute("aria-pressed",B?"true":"false"),p.style.borderColor=B?n.ACCENT_COLOR:n.BORDER_COLOR,p.style.color=B?n.ACCENT_COLOR:n.TEXT_COLOR};p.addEventListener("click",()=>{t.reasons.has(f)?t.reasons.delete(f):t.reasons.add(f),y(),b()}),y(),s.appendChild(p)}i.appendChild(s);const d=document.createElement("textarea");d.className="ago-feedback__comment",d.rows=2,d.placeholder=e.commentPlaceholder,d.value=t.comment,d.setAttribute("aria-label",e.commentPlaceholder),n.css(d,{width:"100%",boxSizing:"border-box",padding:"8px 10px",fontSize:"14px",fontFamily:"inherit",color:n.TEXT_COLOR,border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"10px",backgroundColor:"transparent",resize:"vertical"}),d.addEventListener("input",()=>{t.comment=d.value,b()}),i.appendChild(d);const c=document.createElement("button");return c.type="button",c.className="ago-feedback__send",c.textContent=e.send,n.css(c,{marginTop:"8px",minHeight:"44px",padding:"6px 16px",fontSize:"14px",fontFamily:"inherit",borderRadius:"10px",border:"none",backgroundColor:n.BRAND_COLOR,color:n.BRAND_TEXT_COLOR,cursor:"pointer"}),c.addEventListener("click",()=>{c.disabled||(c.disabled=!0,o({reasons:[...t.reasons],comment:t.comment.trim()}).then(f=>{f||b()}))}),i.appendChild(c),b(),i;function b(){const f=t.reasons.size>0||t.comment.trim().length>0;c.disabled=!f,c.style.opacity=f?"1":"0.5",c.style.cursor=f?"pointer":"default"}}function Ir(t){const e=n.div({marginTop:"6px",fontSize:"13px",color:n.MUTED_TEXT_COLOR});return e.className="ago-feedback__thanks",e.setAttribute("role","status"),e.textContent=t,e}function Dr(t){const e=n.div({display:"flex",flexDirection:"column",flex:"1",width:"100%",overflow:"auto",minHeight:"0"});e.className="ago-chat-widget__chat";const o=n.div({position:"relative",isolation:"isolate",width:"100%",maxWidth:"768px",margin:"0 auto",padding:"0 8px 8px",boxSizing:"border-box",flexShrink:"0"});o.className="ago-chat-widget__dock";const i=n.div({width:"100%"});return i.className="ago-chat-widget__chat-composer",n.css(t.jumpBtn,{position:"absolute",bottom:"100%",top:"auto",left:"auto",right:"50%",marginBottom:"16px",transform:"translateX(50%)",zIndex:"50"}),o.append(t.jumpBtn,i),e.append(t.messagesWrap,o),{el:e,composerSlot:i}}var Br=7200*1e3;function hn(t){const e=t.lastMessageDate instanceof Date?t.lastMessageDate.getTime():new Date(t.lastMessageDate).getTime();return Number.isFinite(e)?e:Number.NEGATIVE_INFINITY}function No(t){return[...t].sort((e,o)=>hn(o)-hn(e))}function Hr(t,e=Date.now(),o=Br){const i=No(t)[0];if(!i)return null;const r=hn(i);return Number.isFinite(r)&&e-r<o?i:null}function Mr(t){const e=n.div({position:"relative",display:"flex",flexDirection:"column",height:"100%",flex:"1",minHeight:"0"});e.className="ago-chat-widget__history";const o=n.div({display:"flex",flex:"1",minHeight:"0"});o.className="ago-chat-widget__history-body";const i=n.div({pointerEvents:"none",position:"absolute",left:"0",right:"0",bottom:"0",zIndex:"10",padding:"32px 16px 16px",backgroundImage:`linear-gradient(to top, ${n.EMBED_BACKGROUND} 72px, transparent 104px)`});i.className="ago-chat-widget__new-strip";const r=document.createElement("button");r.type="button",r.className="ago-chat-widget__new-conversation",n.css(r,{pointerEvents:"auto",display:"flex",height:"56px",width:"100%",alignItems:"center",justifyContent:"center",gap:"8px",borderRadius:"32px",backgroundColor:n.BRAND_COLOR,color:"#fff",padding:"0 24px",border:"none",cursor:"pointer",font:"inherit"});const s=document.createElement("span");s.textContent=t.labels.newConversation,n.css(s,{fontSize:"14px",lineHeight:"20px",fontWeight:"500"}),r.append(bn({size:16}),s),r.addEventListener("click",t.onNew),i.appendChild(r),e.append(o,i);const d=p=>{t.customFont?p.style.opacity="0.7":p.style.color=n.EMBED_MUTED_TEXT};function c(){const p=n.div({display:"flex",flex:"1",alignItems:"center",justifyContent:"center",paddingBottom:"112px"});p.className="ago-chat-widget__history-loading";const y=n.div({width:"32px",height:"32px",borderRadius:"50%",borderBottom:`2px solid ${n.BRAND_COLOR}`,animation:"ago-spin 1s linear infinite"});y.setAttribute("role","status"),p.appendChild(y),o.replaceChildren(p)}function b(){const p=n.div({display:"flex",flex:"1",flexDirection:"column",alignItems:"center",justifyContent:"center"});p.className="ago-chat-widget__history-empty",d(p);const y=go({size:36});y.style.marginBottom="8px";const B=document.createElement("p");B.textContent=t.labels.noHistory,n.css(B,{fontSize:"14px",lineHeight:"20px",margin:"0"}),p.append(y,B),o.replaceChildren(p)}function f(p){const y=n.div({flex:"1",overflowY:"auto",padding:"0 16px 112px",minHeight:"0"});y.className="ago-chat-widget__history-list";const B=No(p);B.forEach((E,u)=>{const C=document.createElement("button");if(C.type="button",C.className="ago-chat-widget__thread",C.dataset.agoConversationId=E.id,n.css(C,{display:"flex",alignItems:"center",gap:"8px",padding:"17px 0",width:"100%",textAlign:"left",backgroundColor:"transparent",border:"none",borderBottom:u===B.length-1?"none":`1px solid ${n.EMBED_BORDER}`,cursor:"pointer",font:"inherit",color:"inherit"}),t.hoverBackground){const w=t.hoverBackground;C.addEventListener("mouseenter",()=>{C.style.backgroundColor=w}),C.addEventListener("mouseleave",()=>{C.style.backgroundColor="transparent"})}const A=n.div({flex:"1",minWidth:"0",display:"flex",flexDirection:"column",gap:"4px"}),k=document.createElement("h3");k.textContent=E.title||t.labels.newConversation,n.css(k,{margin:"0",fontSize:"14px",lineHeight:"20px",fontWeight:"400",color:t.customFont?"inherit":n.BRAND_COLOR,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"});const F=document.createElement("span");F.textContent=Ii(E.lastMessageDate,Date.now(),t.labels.timeAgo),n.css(F,{fontSize:"12px",lineHeight:"16px"}),d(F),A.append(k,F);const z=hi({size:16});t.customFont?z.style.opacity="0.6":z.style.color=n.BRAND_COLOR,C.append(A,z),C.addEventListener("click",()=>t.onSelect(E)),y.appendChild(C)}),o.replaceChildren(y)}return{el:e,render:({threads:p,loading:y})=>{y?c():p.length===0?b():f(p)}}}function zr(t){const e=n.div({position:"relative",display:"flex",flex:"1",flexDirection:"column",width:"100%",maxWidth:"768px",margin:"0 auto",padding:"16px",overflow:"auto",boxSizing:"border-box",minHeight:"0"});e.className="ago-chat-widget__home";const o=n.div({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"space-between",height:"100%",width:"100%",minHeight:"0"}),i=n.div({flex:"1",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-end",gap:"32px",margin:"16px 0 32px"}),r=n.div({fontSize:"28px",lineHeight:"1.2",letterSpacing:"-0.03em",fontWeight:"700",textAlign:"center",color:n.TEXT_COLOR});r.className="ago-chat-widget__home-title",i.appendChild(r);const s=n.div({fontSize:"14px",lineHeight:"20px",textAlign:"center",maxWidth:"512px"});s.className="ago-chat-widget__home-subtitle",i.appendChild(s);const d=w=>{r.replaceChildren();for(const D of w.split(`
|
|
7
|
+
`)){const v=n.div({});v.textContent=D,r.appendChild(v)}},c=w=>{s.replaceChildren(),s.style.display=w?"":"none",w&&s.appendChild(He(w))};d(t.title),c(t.subtitle);const b=n.div({flex:"1",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",width:"100%",position:"relative"}),f=n.div({display:"grid",gridTemplateColumns:"1fr",gap:"12px",width:"100%",maxWidth:"672px",marginBottom:"32px",padding:"0 16px",boxSizing:"border-box"});f.className="ago-chat-widget__starters";const p=[];let y=null;const B=w=>{f.replaceChildren(),p.length=0;for(const D of w)E(D);w.length>0?f.parentNode||b.insertBefore(f,u):f.remove()};function E(w){const D=document.createElement("button");D.type="button",D.className="ago-chat-widget__starter",n.css(D,{textAlign:"left",borderRadius:"12px",border:"1px solid rgba(228, 228, 231, 0.6)",backgroundColor:"#fff",padding:"14px 16px",boxShadow:n.SHADOW_SM,transition:"all 0.2s",cursor:"pointer",font:"inherit",color:n.TEXT_COLOR,position:"relative"});const v=n.div({display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"}),x=n.div({minWidth:"0",flex:"1",fontSize:"14px",lineHeight:"1.375",display:"-webkit-box",overflow:"hidden"});x.style.setProperty("-webkit-line-clamp","2"),x.style.setProperty("-webkit-box-orient","vertical"),x.textContent=w.label;const S=Si({size:16});n.css(S,{marginTop:"2px",color:"rgba(113, 113, 122, 0.5)",transition:"all 0.15s"}),v.append(x,S),D.appendChild(v),D.addEventListener("mouseenter",()=>{D.disabled||(D.style.borderColor="#e4e4e7",D.style.boxShadow=n.SHADOW_MD,D.style.transform="translateY(-2px)",S.style.color=n.TEXT_COLOR,S.style.transform="translate(2px, -2px)")}),D.addEventListener("mouseleave",()=>{D.style.borderColor="rgba(228, 228, 231, 0.6)",D.style.boxShadow=n.SHADOW_SM,D.style.transform="",S.style.color="rgba(113, 113, 122, 0.5)",S.style.transform=""}),D.addEventListener("click",()=>{y||t.onStarter(w)}),p.push({starter:w,btn:D}),f.appendChild(D)}const u=n.div({width:"100%"});u.className="ago-chat-widget__home-composer",b.appendChild(u),B(t.starters);const C=n.div({flex:"1"});o.append(i,b,C),e.appendChild(o);const A=t.twoColumnsFrom??640,k=()=>{const w=typeof window<"u"&&window.innerWidth>=A;f.style.gridTemplateColumns=w?"1fr 1fr":"1fr"};k();const F=w=>{y=w;for(const{starter:D,btn:v}of p){const x=D===w;v.disabled=!!w,v.style.opacity=w?"0.6":"",v.style.cursor=w?"not-allowed":"pointer";const S=v.querySelector("svg");S&&(S.style.animation=x?"ago-skeleton-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite":"")}};return{el:e,composerSlot:u,syncColumns:k,setPending:F,setContent:w=>{w.title!==void 0&&d(w.title),w.subtitle!==void 0&&c(w.subtitle),w.starters&&(B(w.starters),k(),y&&F(y))}}}function $r(t){const e=n.div({position:"fixed",bottom:"80px",[t.edge]:"20px",textAlign:t.edge==="left"?"left":"right",cursor:"pointer",zIndex:"2147483000",animation:"ago-scale-in 800ms",fontFamily:"Arial, Helvetica, sans-serif",transform:"translateZ(0)",backfaceVisibility:"hidden",willChange:"transform"});e.className="ago-chat-widget-teaser";const o=document.createElement("button");o.type="button",o.className="ago-chat-widget-teaser__close",o.setAttribute("aria-label","Dismiss"),o.textContent="X",n.css(o,{animation:"ago-appear 1000ms ease-in",background:"#fff",border:"1px solid #efefef",borderRadius:"50%",boxShadow:n.PANEL_SHADOW,color:"#333",cursor:"pointer",display:"inline-block",fontSize:"12px",fontWeight:"600",fontFamily:"inherit",lineHeight:"normal",left:"5px",padding:"3px 5px",position:"relative",top:"15px",zIndex:"1"});const i=document.createElement("p");i.className="ago-chat-widget-teaser__text",n.css(i,{alignItems:"center",backgroundColor:"#fff",borderRadius:"16px",boxShadow:n.PANEL_SHADOW,color:"#333",display:"flex",fontFamily:"Arial, Helvetica, sans-serif",fontSize:"0.9rem",fontWeight:"600",gap:"8px",margin:"0 0 16px 0",padding:"20px",position:"relative",textAlign:"left"}),i.textContent=t.text;const r=document.createElement("span");r.setAttribute("aria-hidden","true"),n.css(r,{position:"absolute",bottom:"-7px",[t.edge]:"20px",height:"16px",width:"16px",border:"1px solid #fff",transform:"rotate(45deg)",backgroundColor:"#fff"}),i.appendChild(r);const s=()=>{e.remove()};return o.addEventListener("click",d=>{d.stopPropagation(),s(),t.onDismiss?.()},{once:!0}),e.addEventListener("click",d=>{d.target!==o&&t.onOpen()}),e.append(o,i),{el:e,remove:s}}var uo="Form submitted.";function Ur(t){if(typeof t=="string")return t||null;if(!t||typeof t!="object")return null;const e=t;if(typeof e.message=="string"&&e.message)return e.message;const o=e.result;if(typeof o=="string"&&o)return o;if(o&&typeof o=="object"){const i=o.message;if(typeof i=="string"&&i)return i}return null}var Wr=0,Pr="Hello, how can I help you today?",jr=6,qr=800,Vr=/^(?:\d+(?:\.\d+)?(?:px|rem|em|vw|vmin|vmax|%)|(?:min|max|clamp|calc)\([^;{}]+\))$/i;function Gr(t){const e=typeof t=="number"?`${t}px`:String(t).trim();return!Vr.test(e)||typeof CSS<"u"&&typeof CSS.supports=="function"&&!CSS.supports("width",`min(max(400px, ${e}), 100% - 40px)`)?null:e}function Xr(t){const e=typeof t=="string"?document.querySelector(t):t;if(!e)throw new Error(`mountChatWidget: target "${String(t)}" not found.`);return e}function Zr(t,e){const o=e.placement??"inline",i=o==="bubble",{welcomeMessage:r="Hello! How can I help you today?",allowFiles:s=!1,allowStop:d=!0,height:c=500,defaultOpen:b=!1,logoUrl:f,showAgentName:p=!1,agentBubble:y=!1,bubbleStyle:B="default",showHeader:E=!0,forms:u,formSubmittedMessage:C=uo,onFollowUpClick:A,onMessageSent:k,onMessageReceived:F,onFormSubmitted:z,onFormError:w,onOpen:D,onClose:v,icon:x,subtitle:S,conversationStarters:W=[],autoResume:j=!0,hideFooter:M=!1,loadHomeConfig:P=!1}=e,m=e.title??(i?"AGO Chatbot":"Chat"),T=e.width??(i?550:400),h=e.loadThreads??i,I=e.feedback??i,N=Di(e.labels),G=e.placeholder??(i?N.askQuestion:"Type a message..."),ee=e.prompt===void 0?Pr:e.prompt,K=i?{...n.colorsToTheme(e.colors),...e.theme}:e.theme,X=typeof r=="string"?{message:r,mode:"static"}:r,Mt=X.message,ft=X.mode??"static",Fo="speed"in X&&X.speed||45,yn="followUpReplies"in X&&X.followUpReplies||void 0;if(!e.client&&!e.config?.baseUrl)throw new ci.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const $=e.client??new Ee.AgoClient(e.config),zt=Xr(t),mt=o==="left"||o==="right",ie=mt||i,Io=ie&&(e.launcher??!0);let Q=ie?b:!0,$t=!1;const Do=e.mobile?.breakpoint??(i?450:768),Ut=e.mobile?.trigger??"tap",vn=typeof window<"u"&&!!window.matchMedia,te=vn?window.matchMedia(`(max-width: ${Do}px), (max-height: 500px) and (orientation: landscape)`):void 0,Bo=vn?window.matchMedia("(prefers-reduced-motion: reduce)"):void 0,Ho=!!te,Ke=!ie&&!!te,Ye=Symbol("ago-scroll-lock");let J=!1;const Wt=e.persistConversation??(i?!0:void 0),Me=Wt?pi.createConversationSession(Wt===!0?{}:Wt):void 0;let Z=e.conversationId??Me?.getLastActiveThread()??void 0,L=[],gt=[],re=!1,he=null,ke;const Qe=[];function Mo(a){if(typeof C=="function"){const g=C(a);if(typeof g=="string"&&g)return g}const l=Ur(a);return l||(typeof C=="string"?C:uo)}const be=[],R=n.div({display:"flex",flexDirection:"column",height:mt?"100%":typeof c=="number"?`${c}px`:c,border:`1px solid ${n.BORDER_COLOR}`,borderRadius:n.RADIUS,overflow:"hidden",backgroundColor:n.PANEL_BACKGROUND,fontFamily:n.FONT_VAR,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});R.className="ago-chat-widget",n.applyTheme(R,K),i&&(n.css(R,{height:"100%",width:"100%",border:"none",borderRadius:"0",boxShadow:"none",backgroundColor:n.EMBED_BACKGROUND,color:n.TEXT_COLOR,fontSize:"14px",lineHeight:"24px"}),K?.headerText||R.style.setProperty("--ago-header-text-color",n.readableTextColor(K?.headerBg??K?.brand??"#03182f")));let de;if(E&&!i){if(de=n.div({padding:"14px 16px",borderBottom:`1px solid ${n.BORDER_COLOR}`,backgroundColor:n.HEADER_BACKGROUND,color:n.HEADER_TEXT_COLOR,display:"flex",alignItems:"center",gap:"10px"}),de.className="ago-chat-widget__header",f){const l=document.createElement("img");l.src=f,l.alt="Logo",n.css(l,{height:"24px",width:"auto"}),de.appendChild(l)}const a=document.createElement("h3");if(a.textContent=m,n.css(a,{margin:"0",fontSize:"15px",fontWeight:"600"}),de.appendChild(a),mt){const l=document.createElement("button");l.type="button",l.className="ago-chat-widget__close",l.setAttribute("aria-label","Close"),l.textContent="×",n.css(l,{marginLeft:"auto",flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center",width:"44px",height:"44px",margin:"-10px -10px -10px auto",background:"transparent",border:"none",color:n.HEADER_TEXT_COLOR,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0"}),l.addEventListener("click",()=>qe()),de.appendChild(l)}}const Y=n.div({flex:"1",overflow:"auto",overscrollBehavior:"contain",padding:"16px",backgroundColor:n.MESSAGES_BACKGROUND});Y.className="ago-chat-widget__messages",Y.setAttribute("role","log"),Y.setAttribute("aria-live","polite"),Y.setAttribute("aria-relevant","additions text"),Y.setAttribute("aria-atomic","false");const ce=i?n.div({maxWidth:"768px",margin:"0 auto",padding:"0 8px",boxSizing:"border-box"}):Y;i&&(n.css(Y,{padding:"16px 0",backgroundColor:"transparent"}),ce.className="ago-chat-widget__list",Y.appendChild(ce));const zo=48;let xe=!0,Pt=0;function ht(a){Pt++;try{a()}finally{const l=()=>{Pt--};typeof queueMicrotask=="function"?queueMicrotask(l):l()}}function $o(){return Y.scrollHeight-Y.scrollTop-Y.clientHeight<=zo}const ne=document.createElement("button");ne.type="button",ne.className="ago-chat-widget__jump",ne.setAttribute("aria-label","Jump to latest message"),ne.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>',n.css(ne,{position:"absolute",left:"50%",bottom:"12px",transform:"translateX(-50%)",width:"44px",height:"44px",display:"none",alignItems:"center",justifyContent:"center",border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"50%",backgroundColor:n.PANEL_BACKGROUND,color:n.TEXT_COLOR,boxShadow:"rgba(15, 15, 15, 0.16) 0px 2px 10px 0px",cursor:"pointer",zIndex:"2"}),i&&(ne.setAttribute("aria-label",N.scrollToBottom),ne.replaceChildren(xi({size:20})),n.css(ne,{display:"flex",width:"36px",height:"36px",padding:"8px",boxSizing:"border-box",border:`1px solid ${n.NEUTRAL_BORDER}`,backgroundColor:"#fff",boxShadow:n.SHADOW_MD,transition:"opacity 0.3s",opacity:"0",pointerEvents:"none"})),ne.addEventListener("click",()=>{xe=!0,ht(()=>{Y.scrollTop=Y.scrollHeight}),jt()});function jt(){if(i){ne.style.opacity=xe?"0":"1",ne.style.pointerEvents=xe?"none":"auto";return}ne.style.display=xe?"none":"flex"}function bt(){xe&&ht(()=>{Y.scrollTop=Y.scrollHeight}),jt()}Y.addEventListener("scroll",()=>{Pt>0||(xe=$o(),jt())});const qt=n.div({position:"relative",flex:"1",display:"flex",minHeight:"0"});qt.append(Y,ne);const{inputRow:ye,setDisabled:Uo,focus:xt,restoreDraft:Wo,setPlaceholder:Cn,getValueAndClear:Po}=Oi({placeholder:G,allowFiles:s,onSend:(a,l)=>{je(a,l)},onStop:d?()=>{St()}:void 0,look:i?"embed":"classic",labels:i?{attachFiles:N.attachFiles,dismiss:N.dismiss,tooManyFiles:N.tooManyFiles,invalidFileType:N.invalidFileType,fileTooLarge:N.fileTooLarge}:void 0});n.ensureKeyframes(),i||R.append(...de?[de]:[],qt,ye);let Je=R,U,ae,Vt;const et=o==="left"?"left":"right";let Gt,yt,ve,ze,vt,tt,pe,Oe,$e,_e="home",Ct="home",Ue=!1,wt=h,nt=!1,ot=!1,Xt;if(i){if(U=n.div({position:"fixed",right:"20px",bottom:"80px",top:"max(40px, calc(100% - 880px))",width:`min(max(400px, ${n.PANEL_WIDTH}), var(--ago-panel-max, calc(100% - 40px)))`,height:"auto",borderRadius:"16px",boxShadow:n.PANEL_SHADOW,overflow:"hidden",transformOrigin:"right bottom",zIndex:"2147483000",backgroundColor:n.EMBED_BACKGROUND,display:"none",fontFamily:n.FONT_VAR}),U.className="ago-chat-widget-bubble",U.dataset.agoLayout="panel",n.applyTheme(U,K),!K?.panelWidth){const l=Gr(T);l?U.style.setProperty("--ago-panel-width",l):console.warn(`[AGO] mountChatWidget width "${String(T)}" is not a valid CSS length, ignoring. Expected e.g. 700 or "45rem". Falling back to 550px.`)}E&&(Gt=Ni({title:m,labels:N,onBack:()=>Ae(Ct,{byUser:!0}),onNewChat:()=>Tt(),onClose:()=>qe()}),R.appendChild(Gt.el)),tt=n.div({flex:"1",display:"flex",flexDirection:"column",minHeight:"0",overflow:"hidden"}),tt.className="ago-chat-widget__main",R.appendChild(tt),M||(yt=Li({labels:N,onNavigate:l=>Ae(l,{byUser:!0})}),R.appendChild(yt.el)),ve=zr({title:m,subtitle:S,starters:W,onStarter:l=>{ve?.setPending(l),je(l.message??l.label,void 0,{agentId:l.agentId}).finally(()=>ve?.setPending(null))}});const a=e.colors?.background;ze=Mr({labels:N,onSelect:l=>{Ue=!0,Ct="history",st(l.id)},onNew:()=>Tt(),hoverBackground:a&&n.isValidHexColor(a)?n.lightenColor(a,10):void 0,customFont:!!e.colors?.font}),vt=Dr({messagesWrap:qt,jumpBtn:ne}),U.appendChild(R),Je=U}mt&&(U=n.div({position:"fixed",top:"0",bottom:"0",[et]:"0",width:typeof T=="number"?`${T}px`:T,maxWidth:"100vw",display:"flex",zIndex:"2147483000",transition:"transform 0.3s ease",boxShadow:"rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"}),U.className="ago-chat-widget-panel",n.css(R,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[et==="left"?"borderRight":"borderLeft"]:`1px solid ${n.BORDER_COLOR}`}),U.appendChild(R),Je=U),Io&&(Vt=Vi({look:i?"bubble":"classic",edge:et,title:m,icon:i?x:f,onClick:()=>i?Zn():Ot()}),ae=Vt.el);const it=Ke?`ago-vt-${++Wr}`:"",wn=52;let Ce=!1,Se=0,We=0,ue,rt,Te;const Et={height:R.style.height,border:R.style.border,borderRadius:R.style.borderRadius,boxShadow:R.style.boxShadow};zt.appendChild(Je),ae&&zt.appendChild(ae),At(),i&&(ee!==!1&&!Q&&(Oe=setTimeout(ti,1e3)),document.addEventListener("keydown",qn),window.addEventListener("resize",Vn)),Ke&&(ue=si(),R.insertBefore(ue,R.firstChild),rt=document.createElement("style"),rt.id=it,rt.textContent=`::view-transition-group(${it}),::view-transition-group(${it}-bar){animation-duration:0.3s;animation-timing-function:cubic-bezier(0.4,0,0.2,1)}`,document.head.appendChild(rt),(Ut==="focus"||Ut==="tap")&&(R.addEventListener("pointerdown",a=>{if(Ce||!te?.matches)return;const l=ye.contains(a.target);if(Ut==="tap"){if((a.target instanceof Element?a.target:null)?.closest("button,a[href],[role='button']"))return}else if(!l)return;l&&a.preventDefault(),dt()},!0),R.addEventListener("focusin",a=>{te?.matches&&ye.contains(a.target)&&dt()}))),Ho&&document.addEventListener("keydown",Kn),te&&te.addEventListener("change",Yn);const En=A!==!1,kn=A===!1?void 0:A??(a=>{Ke&&te?.matches&&!Ce?dt().then(()=>je(a)):je(a)}),Pe=I===!0?{}:I||null,jo={...mn,...Pe?.labels,reasons:{...mn.reasons,...Pe?.labels?.reasons}},kt=new Map;function _n(a){if(!Pe||!a.id||!a.conversationId||a.status!=="DONE"||!a.content)return null;let l=kt.get(a.id);l||(l=Ar(),kt.set(a.id,l));const g=async(_,H)=>{try{return await $.submitFeedback(a.id,_,H),Pe.onSubmit?.({messageId:a.id,rating:_,reasons:H?.reasons??[],comment:H?.comment||void 0}),!0}catch(O){return Pe.onError?.(O instanceof Error?O:new Error(String(O))),!1}};return Lr({state:l,labels:jo,askWhy:Pe.askWhy??!i,onRate:_=>{g(_)},onReport:(_,H)=>g(_,H),look:i?"embed":"classic"})}const fe=e.toolCallForm??{},we={...Lo,...fe.labels},Sn=$.getUserIdentity(),Zt=fe.userEmail??Sn.email,Tn=!Zt&&!Sn.hasJwt;let Le=null,Rn=!1,An,Kt=!1;const at=new Map,_t=new Set;function qo(){An||(An=$.getConfig().then(a=>{const l=a.permissions[0];Le=l?.ticketForm??null,Kt=!!l?.fileAttachmentsEnabled}).catch(()=>{Le=null}).then(()=>{if(Rn=!0,!J)for(const a of at.values())a.kind==="ticket"&&(Le&&fr(a.state,a.call.ticket,Le),a.view.rebuild({ticketForm:Le,configLoading:!1,allowFiles:s||Kt}))}))}function Yt(){for(const a of at.values())a.kind==="embed"&&a.view.destroy();at.clear(),_t.clear()}function Vo(a){for(const l of L){const g=l.toolCalls?.find(_=>_.id===a);if(g)return g}}function Go(a){const l=at.get(a.id);if(l)return l;let g;if(a.allowedToCreateTicket===!1){const _=n.div({display:"flex",flexDirection:"column",gap:"16px"});_.className="ago-ticket-form ago-ticket-form--denied",_.appendChild(hr(we.notAllowed)),g={kind:"static",el:_}}else if(a.mode==="embed"){const _={status:co(a)?"submitted":"loading"};g={kind:"embed",state:_,view:wr({state:_,embedHtml:a.embedHtml,description:a.embedDescription,ticket:a.ticket,email:Zt,labels:we,message:a.message,successMessage:fe.successMessage,onSubmitted:H=>{_t.add(a.id),$.submitToolCallForm(a.id,{success:!0,source:"embed",thread_id:Z,captured_form_data:H}).then(O=>{const q=O.ticket??O.result?.ticket;fe.onSubmitted?.({toolCallId:a.id,toolName:a.toolName,mode:"embed",ticket:q?.ticket_id?{id:String(q.ticket_id),url:q.ticket_url}:void 0,values:H??{}})}).catch(O=>{fe.onError?.(O instanceof Error?O:new Error(String(O)))}).finally(()=>{J||V()})}})}}else{qo();const _=Ao(a.ticket,Le,Zt??""),H=co(a);H&&(_.submitted=H),g={kind:"ticket",state:_,view:br({state:_,ticketForm:Le,configLoading:!Rn,labels:we,message:a.message,requireEmail:Tn,allowFiles:s||Kt,successMessage:fe.successMessage,successUrlLabel:fe.successUrlLabel,createTicket:O=>$.createTicket({subject:O.subject,body:O.body,priority:O.priority,typology:O.typology,conversationId:Z,email:O.email,customFields:O.customFields,files:O.files,ticketFormId:O.ticketFormId}),onCreated:(O,q)=>{_t.add(a.id);const me=Object.entries(q.customFields).map(([Ne,di])=>({id:Ne,value:di}));$.submitToolCallForm(a.id,{success:!0,ticket_id:O.id,ticket_url:O.url,subject:q.ticket.subject,typology:q.ticket.typology,priority:q.ticket.priority,body:q.ticket.body,tag:q.ticket.tag,custom_fields:me,created_at:new Date().toISOString()}).catch(Ne=>{fe.onError?.(Ne instanceof Error?Ne:new Error(String(Ne)))}).finally(()=>{fe.onSubmitted?.({toolCallId:a.id,toolName:a.toolName,mode:"form",ticket:{id:O.id,url:O.url},values:{...q.ticket,custom_fields:q.customFields,email:Tn?q.email:void 0}}),J||V()})},onError:fe.onError}),call:a}}return at.set(a.id,g),g}function On(a){if(a.type!=="form"||a.displayMode==="collapsible")return null;const l=kr(L);if(l&&l!==a.id){const _=Vo(l),H=!!_?.askToTalkToHuman&&_.allowedToCreateTicket===!1;return Tr(H?we.contactFormRejected:we.contactFormCreated,H?"warning":"info")}if(!Er(a))return Rr(a,we);const g=Go(a);return g.kind==="static"?g.el:g.view.el}let Re;function Xo(){const a=L.some(_=>_.toolCalls?.some(H=>H.type==="form")),l=_t.size>0||_r(L);if(!a&&!l){ye.style.display="",Re?.remove();return}Re||(Re=n.div({margin:"12px",borderRadius:"24px",border:`1px solid ${n.BORDER_COLOR}`,boxShadow:"0 1px 2px rgba(0, 0, 0, 0.05)",backgroundColor:n.PANEL_BACKGROUND,display:"flex",flexDirection:"column",alignItems:"center",gap:"16px",padding:"28px 24px",textAlign:"center",fontFamily:n.FONT_VAR}),Re.className="ago-chat-blocked"),Re.replaceChildren();const g=document.createElement("p");if(g.textContent=l?we.ticketCreatedBlocked:we.formPending,n.css(g,{color:n.MUTED_TEXT_COLOR,lineHeight:"1.625",fontSize:"16px",margin:"0",whiteSpace:"pre-line"}),Re.appendChild(g),l){const _=document.createElement("button");_.type="button",_.className="ago-chat-blocked__new",n.css(_,{display:"inline-flex",alignItems:"center",gap:"8px",borderRadius:"9999px",padding:"0 20px",minHeight:"44px",backgroundColor:"var(--ago-brand-color, #03182f)",color:"var(--ago-brand-text-color, #fff)",border:"none",cursor:"pointer",font:"inherit",fontSize:"14px",fontWeight:"500"}),_.append(bn({size:18}));const H=document.createElement("span");H.textContent=we.newConversation,_.appendChild(H),_.addEventListener("click",()=>{Tt(),fe.onNewConversation?.()}),Re.appendChild(_)}ye.style.display="none",ye.parentElement?.insertBefore(Re,ye)}function Ln(a){const l=L[a];return i?er(l,{isLast:a===L.length-1,followUpEnabled:En,followUpHandler:kn,agentRowTinted:!!K?.agentBubbleBg,agentRowTextTinted:!!K?.agentBubbleText,labels:N,actionsRow:_n(l),renderToolCall:On}):Wi(l,{...Zo(a),renderToolCall:On})}function Zo(a){const l=L.length-1;return{isLast:a===l,isLastOfBlock:a===l||L[a+1].role!==L[a].role,bubbleStyle:B,showAgentName:p,agentBubble:y,followUpEnabled:En,followUpHandler:kn,isMobile:!!te?.matches,feedbackRow:_n(L[a])}}function Ko(){if(he||Qe.length>0)return!1;const a=L.length-1,l=L[a];if(!l||l.role!=="assistant")return!1;const g=gt[a];if(!g||g.parentNode!==ce)return!1;const _=Ln(a),H=document.activeElement,O=H instanceof HTMLElement&&g.contains(H)?H:null;return ht(()=>ce.replaceChild(_,g)),O&&_.contains(O)&&O.focus({preventScroll:!0}),gt[a]=_,bt(),!0}function V(){ht(Yo),bt();const a=L[L.length-1],l=re&&a?.role==="assistant"&&(a.status==="IN_PROGRESS"||a.status==="WAITING_CLIENT");Y.setAttribute("aria-busy",l?"true":"false"),Uo(l),Xo()}function Yo(){if(ce.replaceChildren(),gt=[],L.length===0){if(i){if(nt){const a=n.div({display:"flex",justifyContent:"center",padding:"32px 0"});a.className="ago-chat-widget__thread-loading";const l=n.div({width:"32px",height:"32px",borderRadius:"50%",borderBottom:"2px solid var(--ago-brand-color, #03182f)",animation:"ago-spin 1s linear infinite"});l.setAttribute("role","status"),a.appendChild(l),ce.appendChild(a)}}else if(ft==="static"){const a=n.div({textAlign:"center",color:n.MUTED_TEXT_COLOR,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});a.appendChild(He(Mt)),ce.appendChild(a)}}else L.forEach((a,l)=>{const g=Ln(l);gt[l]=g,ce.appendChild(g)});for(const a of Qe)ce.appendChild(Pi(a));if(he){if(i){ce.appendChild(Ki(N.errorTitle,he));return}const a=n.div({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});a.setAttribute("role","alert"),a.textContent=he,ce.appendChild(a)}}function Qt(){for(let a=L.length-1;a>=0;a--){const l=L[a];if(l.role==="assistant"&&(l.status==="IN_PROGRESS"||l.status==="WAITING_CLIENT"))return l}}const Nn=a=>{Z||(Z=a.conversationId)},Fn=a=>{const l=Qt();l&&(l.content+=a.content,Ko()||V())},In=a=>{const l=L.findIndex(g=>g.id===a.id||g.role==="assistant"&&g.status==="IN_PROGRESS");l>=0?L[l]=a:L.push(a),V(),lt()||xt()},Dn=a=>{const l=L.findIndex(g=>g.id===a.id||g.role==="assistant"&&g.status==="IN_PROGRESS");l>=0?L[l]=a:L.push(a),re=!1,V(),a.status==="DONE"&&F?.({id:a.id,content:a.content})},Bn=()=>{const a=Qt();a&&(a.content?a.status="CANCELED":L=L.filter(l=>l!==a)),re=!1,V()},Hn=a=>{he=a.error,re=!1,L=L.filter(l=>!l.id.startsWith("temp-")),V()};function Qo(a){const l={id:`ago-intro-${Date.now()}`,conversationId:"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};L.push(l),V();const g=a.match(/\S+\s*/g)??[a];let _=0;ke=setInterval(()=>{if(_>=g.length){clearInterval(ke),ke=void 0,l.status="DONE",yn&&(l.followUpReplies=yn),V();return}l.content+=g[_],_++,V()},Fo)}const Mn=a=>{const l=be.find(g=>g.id===a.conversationId);l&&(l.title=a.title),i&&_e==="history"&&ze?.render({threads:be,loading:wt})},zn=a=>{if(a.type!=="form")return;const l=Qt()??[...L].reverse().find(H=>H.role==="assistant");if(!l)return;const g=l.toolCalls??[],_=g.findIndex(H=>H.id===a.id);_>=0?g[_]=a:g.push(a),l.toolCalls=g,V()};$.on("message:start",Nn),$.on("message:chunk",Fn),$.on("message:answer-complete",In),$.on("message:complete",Dn),$.on("message:stopped",Bn),$.on("message:error",Hn),$.on("conversation:title",Mn),$.on("toolCall:received",zn);const $n=a=>z?.(a),Un=a=>w?.(a);z&&$.on("form:submitted",$n),w&&$.on("form:error",Un);const Jt=[];let Wn=!1;const Pn=a=>{if(Wn)return;Jt.push(a.install($));let l=a.store.get().submitted;const g=a.store.subscribe(_=>{_.submitted&&!l&&(Qe.push(Mo(_.submitResult)),V()),l=_.submitted});Jt.push(g)};for(const a of u??[])a.schema!=null?Pn(no.createFormCollector(a)):no.loadFormCollector($,a).then(l=>Pn(l)).catch(()=>{});async function je(a,l,g){const _=a.trim();if(!_&&!l?.length||re)return;if(i&&_e!=="chat"&&(Ct="home",Ae("chat",{byUser:!0})),k?.(_),re=!0,he=null,xe=!0,ke){clearInterval(ke),ke=void 0;const O=L.find(q=>q.id.startsWith("ago-intro-"));O&&!O.content?L=L.filter(q=>q!==O):O&&(O.status="DONE")}const H=Date.now();L.push({id:`temp-user-${H}`,conversationId:Z||"",content:_,role:"user",status:"DONE",attachments:l&&l.length>0?Ee.attachmentsFromFiles(l):void 0,createdAt:new Date}),L.push({id:`temp-assistant-${H}`,conversationId:Z||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),V();try{const O=await $.sendMessage(_,{conversationId:Z,files:l,...g?.agentId?{agentId:g.agentId}:{}});O.conversationId&&(Z||(Z=O.conversationId),Me?.setActiveThread(O.conversationId,O.createdAt));const q=L.find(me=>me.id===`temp-user-${H}`);if(q&&(q.id=`user-${H}`,q.conversationId=O.conversationId),O.id&&!L.some(me=>me.id===O.id)){const me=L.findIndex(Ne=>Ne.id===`temp-assistant-${H}`);me>=0?L[me]=O:L.push(O)}L=L.filter(me=>!me.id.startsWith("temp-")),O.status!=="WAITING_CLIENT"&&(re=!1),V(),h&&en()}catch(O){he=O instanceof Error?O.message:"Failed to send message",re=!1,L=L.filter(q=>!q.id.startsWith("temp-")),Wo(_,l),V()}}async function St(){re&&await $.stop()}async function en(){try{const{data:a}=await $.getConversations();be.splice(0,be.length,...a)}catch{}return wt=!1,i&&!J&&(_e==="history"&&ze?.render({threads:be,loading:!1}),Jo()),be}async function jn(a){try{const l=await $.getConversation(a);if(Z!==a)return;const g=l?.messages??[];nt=!1,g.length>0&&L.length===0?(L=g,V()):i&&V(),i&&Me?.setActiveThread(a,l.lastMessageDate)}catch{if(Z!==a)return;nt=!1,L.length===0&&(Me?.clear(),Z=void 0,i&&(_e==="chat"&&Ae("home"),V()))}}function Ae(a,l){if(!i||!tt||!ve||!vt||!ze)return;l?.byUser&&(Ue=!0),_e=a,a==="home"?(ve.composerSlot.appendChild(ye),Cn(G)):a==="chat"&&(vt.composerSlot.appendChild(ye),Cn(""));const g=a==="home"?ve.el:a==="chat"?vt.el:ze.el;tt.replaceChildren(g),a==="history"&&ze.render({threads:be,loading:wt}),a==="chat"&&(xe=!0,bt()),Gt?.update({screen:a}),yt?.setActive(a),yt?.setVisible(a!=="chat")}async function st(a){i&&(re&&await St(),Z=a,L=[],he=null,Qe.length=0,kt.clear(),Yt(),nt=!0,Ae("chat"),V(),await jn(a))}function Tt(){re&&St(),Z=void 0,L=[],he=null,Qe.length=0,kt.clear(),Yt(),nt=!1,Me?.clear(),Po(),ve?.setPending(null),Ct="home",i&&Ae("home",{byUser:!0}),V()}function Jo(){if(!i||ot)return;if(ot=!0,!j||Ue||_e!=="home"||L.length>0||Z){Rt();return}const a=Hr(be);a&&st(a.id),Rt()}async function ei(){let a;try{a=(await $.getConfig()).permissions[0]?.homePage}catch{return}J||!a||(ve?.setContent({title:a.title||void 0,subtitle:a.subtitle||void 0,starters:a.starters.length?a.starters.map(l=>({label:l.label,message:l.message,agentId:l.agentId})):void 0}),a.widgetStarter&&(Xt=a.widgetStarter,Rt()))}function Rt(){const a=Xt;!a||J||Q&&(wt&&!ot||(Xt=void 0,!(Ue||Z||L.length>0||re||_e!=="home")&&je(a.message,void 0,{agentId:a.agentId})))}function ti(){Oe=void 0,!(J||Q||ee===!1||pe)&&(pe=$r({text:ee,edge:et,onOpen:()=>Ot(),onDismiss:()=>{pe=void 0}}),zt.appendChild(pe.el),tn())}function tn(){if(!i||!U||!ae||lt()||!ae.offsetHeight)return;const a=getComputedStyle(ae),l=parseFloat(a.bottom),g=parseFloat(a.right);if(Number.isNaN(l)||Number.isNaN(g))return;const _=Math.round(l+ae.offsetHeight)+jr,H=Math.round(g),O=[U];pe&&O.push(pe.el);for(const q of O)q.style.setProperty("bottom",`${_}px`,"important"),q.style.setProperty("right",`${H}px`,"important");U.style.setProperty("top",`max(40px, calc(100% - ${_+qr}px))`,"important"),U.style.setProperty("--ago-panel-max",`calc(100% - ${H+20}px)`)}function qn(a){a.key!=="Escape"||!Q||a.defaultPrevented||a.target instanceof HTMLInputElement||a.target instanceof HTMLTextAreaElement||nn()||qe()}function Vn(){$e&&clearTimeout($e),$e=setTimeout(()=>{$e=void 0,!J&&(tn(),ve?.syncColumns())},150)}i?(Ae("home"),V(),P&&ei(),e.conversationId?(Ue=!0,ot=!0,st(e.conversationId)):Z&&j?(ot=!0,st(Z)):Z=void 0):(V(),Ke&&te?.matches||xt(),Z?jn(Z):ft==="streaming"&&Qo(Mt)),h&&en();const Gn={client:$,element:Je,sendMessage:je,stop:St,...ie||Ke?{open:ni,close:oi,toggle:ii}:{},newConversation:Tt,...i?{showScreen:a=>Ae(a,{byUser:!0}),openConversation:a=>(Ue=!0,st(a))}:{},session:Me,threads:be,refreshThreads:en,destroy(){J||(J=!0,ke&&clearInterval(ke),Oe&&clearTimeout(Oe),$e&&clearTimeout($e),pe?.remove(),$.off("message:start",Nn),$.off("message:chunk",Fn),$.off("message:answer-complete",In),$.off("message:complete",Dn),$.off("message:stopped",Bn),$.off("message:error",Hn),$.off("conversation:title",Mn),$.off("toolCall:received",zn),Yt(),z&&$.off("form:submitted",$n),w&&$.off("form:error",Un),Wn=!0,Jt.forEach(a=>a()),Je.remove(),ae?.remove(),ue?.remove(),document.removeEventListener("keydown",qn),window.removeEventListener("resize",Vn),rt?.remove(),Te?.remove(),te?.removeEventListener("change",Yn),document.removeEventListener("keydown",Kn),an(),$t=!1,n.unlockBackgroundScroll(Ye),e.client||$.destroy())}};return i&&Object.defineProperty(Gn,"screen",{get:()=>_e,enumerable:!0}),Gn;function At(){if(!U)return;if(i)Xn();else{const l=et==="left"?"border-right":"border-left";te?.matches?(U.style.width="100%",R.style.borderRadius="0",R.style.removeProperty(l)):(U.style.width=typeof T=="number"?`${T}px`:T,R.style.setProperty(l,`1px solid ${n.BORDER_COLOR}`));const g=o==="left"?"translateX(-100%)":"translateX(100%)";U.style.transform=Q?"translateX(0)":g,ae&&(ae.style.display=Q?"none":"flex")}U.setAttribute("aria-hidden",Q?"false":"true");const a=nn();a!==$t&&($t=a,a?(R.setAttribute("role","dialog"),R.setAttribute("aria-modal","true"),R.setAttribute("aria-label",m),R.tabIndex=-1,R.style.paddingBottom="env(safe-area-inset-bottom)",n.lockBackgroundScroll(Ye),Se=on(),rn(),Qn()):(an(),ai(),Se=0,R.removeAttribute("role"),R.removeAttribute("aria-modal"),R.removeAttribute("aria-label"),R.style.removeProperty("padding-bottom"),n.unlockBackgroundScroll(Ye)))}function Xn(){if(!U)return;U.style.display=Q?"block":"none",Vt?.setOpen(Q);const a=lt();if(ae&&(ae.style.display=a&&Q?"none":"flex"),a){for(const l of["bottom","right","top","--ago-panel-max"])U.style.removeProperty(l);n.css(U,{top:"0",left:"0",right:"0",bottom:"0",width:"100dvw",maxWidth:"100vw",height:"var(--ago-vh, 100dvh)",borderRadius:"0",paddingTop:"env(safe-area-inset-top, 0px)",paddingBottom:"env(safe-area-inset-bottom, 0px)",paddingLeft:"env(safe-area-inset-left, 0px)",paddingRight:"env(safe-area-inset-right, 0px)",boxSizing:"border-box"}),U.dataset.agoLayout="fullscreen",Q&&(pe?.remove(),pe=void 0)}else{for(const l of["left","max-width","padding-top","padding-bottom","padding-left","padding-right"])U.style.removeProperty(l);n.css(U,{right:"20px",bottom:"80px",top:"max(40px, calc(100% - 880px))",width:`min(max(400px, ${n.PANEL_WIDTH}), var(--ago-panel-max, calc(100% - 40px)))`,height:"auto",borderRadius:"16px"}),U.dataset.agoLayout="panel",tn()}}function Ot(){Q=!0,Oe&&(clearTimeout(Oe),Oe=void 0),pe?.remove(),pe=void 0,At(),lt()?R.focus({preventScroll:!0}):xt(),Rt(),D?.()}function qe(){Q=!1,At(),v?.()}function Zn(){Q?qe():Ot()}function ni(){ie?Ot():dt()}function oi(){ie?qe():ct()}function ii(){ie?Zn():Ce?ct():dt()}function lt(){return!!te?.matches}function nn(){return lt()&&(ie?Q:Ce)}function ri(){return Array.from(R.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter(a=>a.getClientRects().length>0)}function Kn(a){if(!nn())return;if(a.key==="Escape"){ie?qe():ct();return}if(a.key!=="Tab")return;const l=ri();if(l.length===0){a.preventDefault();return}const g=l[0],_=l[l.length-1],H=document.activeElement;a.shiftKey&&(H===g||!R.contains(H))?(a.preventDefault(),_.focus()):!a.shiftKey&&(H===_||!R.contains(H))&&(a.preventDefault(),g.focus())}function Yn(a){ie?At():!a.matches&&Ce&&ct(),V()}function on(){return window.visualViewport?.height??window.innerHeight}function rn(){const a=window.visualViewport,l=a?.offsetTop??0,g=a?.height??Se;if(ie){if(!U)return;const H=window.innerHeight||Se,O=Math.max(0,H-(l+g));U.style.bottom=`${O}px`,U.style.top=`${l}px`;return}const _=Math.min(0,l+g-Se);R.style.top=`${_}px`,ue&&(ue.style.top=`${l}px`)}function ai(){ie&&U&&(U.style.removeProperty("bottom"),U.style.removeProperty("top"),i&&!J&&Xn())}function Lt(){We||(We=requestAnimationFrame(()=>{We=0,!J&&rn()}))}function Qn(){window.visualViewport?.addEventListener("resize",Lt),window.visualViewport?.addEventListener("scroll",Lt)}function an(){window.visualViewport?.removeEventListener("resize",Lt),window.visualViewport?.removeEventListener("scroll",Lt),We&&(cancelAnimationFrame(We),We=0)}function Jn(){xe=!0,bt()}function si(){const a=n.div({position:"fixed",top:"0",left:"0",right:"0",height:`calc(${wn}px + env(safe-area-inset-top))`,display:"none",alignItems:"center",justifyContent:"space-between",padding:"env(safe-area-inset-top) 14px 0",backgroundColor:n.PANEL_BACKGROUND,borderBottom:`1px solid ${n.BORDER_COLOR}`,zIndex:"2147483001",fontFamily:n.FONT_VAR});if(a.className="ago-chat-widget-mobile-bar",f){const g=document.createElement("img");g.src=f,g.alt="",n.css(g,{height:"28px",width:"auto"}),a.appendChild(g)}else if(m){const g=document.createElement("span");g.textContent=m,n.css(g,{fontSize:"15px",fontWeight:"600",color:n.TEXT_COLOR,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"}),a.appendChild(g)}else a.appendChild(n.div({}));const l=document.createElement("button");return l.type="button",l.setAttribute("aria-label","Close"),l.textContent="×",n.css(l,{flexShrink:"0",width:"44px",height:"44px",marginRight:"-10px",display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",fontSize:"26px",lineHeight:"1",color:n.TEXT_COLOR,cursor:"pointer",padding:"0"}),l.addEventListener("click",()=>{ct()}),a.appendChild(l),a}function li(){return typeof document.startViewTransition=="function"&&!Bo?.matches&&!!te?.matches}function eo(a){const l=document;if(li()&&l.startViewTransition){R.style.setProperty("view-transition-name",it),ue?.style.setProperty("view-transition-name",`${it}-bar`);const g=()=>{R.style.removeProperty("view-transition-name"),ue?.style.removeProperty("view-transition-name")};return l.startViewTransition(a).finished.then(g,g)}return a(),Promise.resolve()}function to(a){if(a)Te&&R.parentElement?.insertBefore(Te,R),n.css(R,{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(${wn}px + env(safe-area-inset-top))`,paddingBottom:"env(safe-area-inset-bottom)"}),R.setAttribute("role","dialog"),R.setAttribute("aria-modal","true"),R.setAttribute("aria-label",m),de&&(de.style.display="none"),ue&&(ue.style.display="flex");else{Te?.remove(),Te=void 0;for(const l of["position","top","left","right","bottom","z-index","padding-top","padding-bottom"])R.style.removeProperty(l);R.style.height=Et.height,R.style.border=Et.border,R.style.borderRadius=Et.borderRadius,R.style.boxShadow=Et.boxShadow,R.removeAttribute("role"),R.removeAttribute("aria-modal"),R.removeAttribute("aria-label"),de&&(de.style.display="flex"),ue&&(ue.style.display="none")}}function dt(){if(J||Ce||!te?.matches)return Promise.resolve();const a=R.getBoundingClientRect();if(a.height>=on()*.8)return Promise.resolve();Ce=!0,Te=n.div({width:`${a.width}px`,height:`${a.height}px`}),Te.className="ago-chat-widget-spacer",Te.setAttribute("aria-hidden","true"),Se=on(),R.style.setProperty("--ago-vh",`${Se}px`),rn(),Qn(),n.lockBackgroundScroll(Ye);const l=eo(()=>to(!0));return l.then(()=>{J||(Jn(),xt())}),Jn(),D?.(),l}function ct(){if(!Ce)return Promise.resolve();Ce=!1,an(),n.unlockBackgroundScroll(Ye),R.querySelector("textarea")?.blur();const a=eo(()=>to(!1));return a.then(()=>{J||R.style.removeProperty("--ago-vh")}),Se=0,v?.(),a}}exports.DEFAULT_FEEDBACK_LABELS=mn;exports.DEFAULT_TOOL_CALL_FORM_LABELS=Lo;exports.DEFAULT_WIDGET_LABELS=dn;exports.colorsToTheme=n.colorsToTheme;exports.compactMediaQuery=n.compactMediaQuery;exports.createSheetController=n.createSheetController;exports.mountChatWidget=Zr;exports.readableTextColor=n.readableTextColor;exports.renderMarkdown=He;
|