@useago/sdk 1.12.0 → 1.13.1
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 +111 -4
- package/README.md +73 -0
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +140 -38
- package/dist/angular.d.ts +140 -38
- package/dist/angular.js +7 -4
- package/dist/autoContinue-C3UsCvT5.cjs +1 -0
- package/dist/{autoContinue-CC8K9mBU.js → autoContinue-Cb4_iEbO.js} +1 -1
- package/dist/{createConversationSession-B1Qn-y0I.js → createConversationSession-D0vks-8C.js} +1 -1
- package/dist/{createConversationSession-B3v_xOU7.cjs → createConversationSession-Ri3EKIJU.cjs} +1 -1
- package/dist/{createFormCollector-m79zk_NA.js → createFormCollector-BMN-blXs.js} +1 -1
- package/dist/{createFormCollector-FvwDOqnV.cjs → createFormCollector-BNCMIUw2.cjs} +1 -1
- package/dist/createMockClient-BPt1gSve.cjs +1 -0
- package/dist/{createMockClient-Beao82tu.js → createMockClient-YoYr3pQr.js} +1 -0
- package/dist/devtools.cjs +4 -4
- package/dist/devtools.d.cts +129 -33
- package/dist/devtools.d.ts +129 -33
- package/dist/devtools.js +87 -84
- package/dist/helpers.d.cts +42 -12
- package/dist/helpers.d.ts +42 -12
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +135 -40
- package/dist/index.d.ts +135 -40
- package/dist/index.js +44 -43
- package/dist/react.cjs +4 -4
- package/dist/react.d.cts +187 -34
- package/dist/react.d.ts +187 -34
- package/dist/react.js +822 -729
- package/dist/speechToText-BV7qxqPF.js +704 -0
- package/dist/speechToText-ZciRyyJE.cjs +1 -0
- package/dist/testing.cjs +1 -1
- package/dist/testing.d.cts +129 -33
- package/dist/testing.d.ts +129 -33
- package/dist/testing.js +1 -1
- package/dist/types-Ck3iZG0K.cjs +10 -0
- package/dist/{types-Ct1hlKwg.js → types-fX-VoHfa.js} +1042 -759
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +143 -35
- package/dist/vue.d.ts +143 -35
- package/dist/vue.js +133 -131
- package/dist/widget.cjs +6 -6
- package/dist/widget.d.cts +161 -33
- package/dist/widget.d.ts +161 -33
- package/dist/widget.js +1702 -1757
- package/llms-full.txt +166 -1
- package/package.json +1 -1
- package/dist/autoContinue-CP9pJR-V.cjs +0 -1
- package/dist/createMockClient-BEOXI8yW.cjs +0 -1
- package/dist/sheetController-BThJRtOu.cjs +0 -1
- package/dist/sheetController-aEKXIvjk.js +0 -343
- package/dist/types-mcW8vB1U.cjs +0 -10
package/dist/widget.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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,`
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _e=require("./types-Ck3iZG0K.cjs"),si=require("./errors-o1IB5fEu.cjs"),li=require("./createConversationSession-Ri3EKIJU.cjs"),to=require("./createFormCollector-BNCMIUw2.cjs"),n=require("./speechToText-ZciRyyJE.cjs");var di=10*1024*1024;var no=["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 oo(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function ci(t){const e=t.look==="embed";let i=[];const o=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 c=n.div(e?{display:"flex",flexDirection:"row",gap:"8px",padding:"16px"}:{display:"flex",gap:"8px",alignItems:"flex-end"}),d=document.createElement("textarea");d.placeholder=t.placeholder,d.setAttribute("aria-label",t.placeholder),d.rows=1,d.autocapitalize="off",d.setAttribute("autocorrect","off");const h=e?208:110;e?n.css(d,{display:"block",width:"100%",minHeight:"40px",maxHeight:`${h}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(d,{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:`${h}px`,overflowY:"hidden"});const f=()=>{const m=e?0:2;d.style.height="auto";const B=Math.min(d.scrollHeight+m,h);d.style.height=`${B}px`,d.style.overflowY=d.scrollHeight+m>h?"auto":"hidden"};d.addEventListener("input",()=>{f(),E()});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>',x='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true" style="animation: ago-spin 0.8s linear infinite"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>',I='<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>',w=document.createElement("button");w.type="submit",w.className="ago-chat-input__send",w.setAttribute("aria-label","Send"),e?n.css(w,{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"}):(w.innerHTML=p,n.css(w,{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,v=!1;const A=()=>u&&!!t.onStop,E=()=>{const m=d.value.trim()!=="",B=A(),G=!B&&(u||v||!m);if(w.disabled=G,w.type=B?"button":"submit",w.setAttribute("aria-label",B?"Stop generating":"Send"),e){w.replaceChildren(B?n.stopIcon({size:16}):n.arrowUpwardIcon({size:16}));const P=G&&!u;w.style.backgroundColor=P?"#f1f5f9":n.SEND_BACKGROUND,w.style.color=P?"#cbd5e1":"#fafafa",w.style.pointerEvents=G?"none":"auto",w.style.cursor=G?"default":"pointer",J.style.opacity=u?"0.5":"1";return}w.innerHTML=B?I:u?x:p,w.style.opacity=G&&!u?"0.5":"1",w.style.cursor=G?"default":"pointer"};w.addEventListener("click",()=>{A()&&t.onStop?.()});const O=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"});O.className="ago-chat-input__error",O.setAttribute("role","alert");const W=document.createElement("span"),C=document.createElement("button");C.type="button",C.textContent=t.labels?.dismiss??"Dismiss",n.css(C,{border:"none",background:"transparent",color:"inherit",font:"inherit",fontWeight:"500",cursor:"pointer",padding:"0",minHeight:"20px"}),C.addEventListener("click",()=>{O.style.display="none"}),O.append(W,C);const F=m=>{W.textContent=m,O.style.display="flex"},y=(m,B)=>m.replace(/\{(\w+)\}/g,(G,P)=>B[P]??""),k=m=>{if(!e)return m;const B=t.labels,G=[];for(const P of m){if(i.length+G.length>=5){F(y(B?.tooManyFiles??"Too many files. Maximum allowed: {max}",{max:String(5)}));break}if(P.type&&!no.includes(P.type)){F(y(B?.invalidFileType??"Invalid file type: {name}",{name:P.name}));continue}if(P.size>10485760){F(y(B?.fileTooLarge??"File too large: {name} (maximum {max})",{name:P.name,max:oo(di)}));continue}G.push(P)}return G};let S=null,D=null;t.allowFiles&&(S=document.createElement("input"),S.type="file",S.multiple=!0,e&&(S.accept=no.join(",")),n.css(S,{display:"none"}),D=document.createElement("button"),D.type="button",D.className="ago-chat-input__attach",D.setAttribute("aria-label",t.labels?.attachFiles??"Attach file"),e?(D.appendChild(n.attachFileIcon({size:16})),n.css(D,{height:"40px",padding:"8px",display:"flex",alignItems:"center",gap:"4px",fontSize:"14px",color:n.BRAND_COLOR,background:"none",border:"none",cursor:"pointer",borderRadius:"6px"})):(D.textContent="📎",n.css(D,{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"})),D.addEventListener("click",()=>S?.click()),S.addEventListener("change",()=>{const m=Array.from(S?.files??[]);i=[...i,...k(m)],S&&(S.value=""),j()}));function V(m){if(!e||!m.type.startsWith("image/")||typeof URL>"u"||typeof URL.createObjectURL!="function")return null;let B=o.get(m);return B||(B=URL.createObjectURL(m),o.set(m,B)),B}function M(m){const B=o.get(m);B&&(URL.revokeObjectURL(B),o.delete(m))}function j(){s.replaceChildren(),e&&(s.style.display=i.length>0?"flex":"none"),i.forEach((m,B)=>{const G=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(G.className="ago-chat-input__file",e){const re=V(m);if(re){const be=document.createElement("img");be.src=re,be.alt="",n.css(be,{width:"32px",height:"32px",objectFit:"cover",borderRadius:"4px",flexShrink:"0"}),G.appendChild(be)}else G.appendChild(n.descriptionIcon({size:20}))}const P=document.createElement("span");if(P.textContent=m.name,P.title=m.name,e&&n.css(P,{maxWidth:"150px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),G.appendChild(P),e){const re=document.createElement("span");re.textContent=oo(m.size),n.css(re,{fontSize:"12px",lineHeight:"16px",color:"#6b7280"}),G.appendChild(re)}const ee=document.createElement("button");ee.type="button",ee.setAttribute("aria-label",`Remove ${m.name}`),e?ee.appendChild(n.closeIcon({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",()=>{M(m),i=i.filter((re,be)=>be!==B),j()}),G.appendChild(ee),s.appendChild(G)}),E()}const b=()=>{z?.cancel();const m=d.value,B=i;d.value="",f(),i=[];for(const G of B)M(G);return j(),{content:m,files:B}},R=()=>{if(u||v||!d.value.trim())return;const{content:m,files:B}=b();t.onSend(m.trim(),B.length>0?B:void 0),e&&typeof window<"u"&&window.innerWidth<(t.blurOnSubmitBelow??600)&&d.blur()};r.addEventListener("submit",m=>{m.preventDefault(),R()}),d.addEventListener("keydown",m=>{if(m.key==="Enter"&&!m.shiftKey){if(m.isComposing||m.keyCode===229)return;m.preventDefault(),R()}});const z=t.transcribeAudio?n.createSpeechToText({transcribe:t.transcribeAudio,labels:t.speechToTextLabels,onBusy:m=>{const B=v&&!m&&!u&&r.contains(document.activeElement);v=m,d.disabled=u||m,e?(J.style.display=m?"none":"",Y.style.display=m?"none":"flex",c.style.padding=m?"8px":"16px",z&&(m?c.append(z.el):Y.prepend(z.el))):(d.style.display=m?"none":"",w.style.display=m?"none":"flex",D&&(D.style.display=m?"none":"flex")),E(),B&&d.focus()},onText:m=>{d.value+=`${d.value&&!/\s$/.test(d.value)?" ":""}${m}`,f(),E(),d.focus()},onError:F}):void 0,J=n.div({flex:"1",minWidth:"0"});J.className="ago-chat-input__editor";const Y=n.div({display:"flex",alignItems:"flex-end",flexShrink:"0",gap:"4px"});if(e){J.append(O,s,d);const m=n.div({display:"flex",alignItems:"center"});m.className="ago-chat-input__toolbar",D&&m.appendChild(D),D&&J.appendChild(m),z&&Y.appendChild(z.el),Y.appendChild(w),c.append(J,Y),S&&r.appendChild(S),r.appendChild(c),r.addEventListener("click",B=>{(B.target instanceof Element?B.target:null)?.closest("button,a,input,textarea")||d.focus()})}else D&&c.appendChild(D),c.append(d),z&&c.appendChild(z.el),c.append(w),S&&r.appendChild(S),r.append(O,s,c);return E(),{inputRow:r,getValueAndClear:b,setDisabled:m=>{u=m,z?.setDisabled(m),d.disabled=m||v,E()},focus:()=>d.focus(),blur:()=>d.blur(),restoreDraft:(m,B)=>{m&&!d.value.trim()&&(d.value=m,f()),B?.length&&(i=[...B,...i],j()),E()},setPlaceholder:m=>{d.placeholder=m,m&&d.setAttribute("aria-label",m)},setSpeechToTextEnabled:m=>z?.setEnabled(m),cancelRecording:()=>z?.cancel(),destroy:()=>{z?.destroy();for(const m of o.keys())M(m)}}}var on="rgba(3, 24, 47, 0.07)";function pi(t){const e=document.createElement("footer");e.className="ago-chat-widget__footer",n.css(e,{padding:"12px",flexShrink:"0",background:"transparent"});const i=document.createElement("nav");n.css(i,{display:"flex",alignItems:"center",gap:"4px",width:"100%"});const o=new Map;let r="home";function s(d,h,f){const p=document.createElement("button");p.type="button",p.className="ago-chat-widget__tab",p.dataset.agoScreen=d,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 x=document.createElement("span");return x.textContent=h,n.css(x,{fontSize:"12px",lineHeight:"16px",maxWidth:"100%",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"}),p.append(f,x),p.addEventListener("mouseenter",()=>{p.style.backgroundColor=on}),p.addEventListener("mouseleave",()=>{p.style.backgroundColor=r===d?on:"transparent"}),p.addEventListener("click",()=>t.onNavigate(d)),o.set(d,p),p}i.append(s("home",t.labels.home,n.houseIcon({size:24})),s("history",t.labels.chats,n.conversationsIcon({size:24}))),e.appendChild(i);const c=d=>{r=d==="history"?"history":"home";for(const[h,f]of o){const p=h===r;f.style.color=p?n.PRIMARY_ACCENT:n.BRAND_COLOR,f.style.backgroundColor=p?on:"transparent",p?f.setAttribute("aria-current","page"):f.removeAttribute("aria-current")}};return c("home"),{el:e,setActive:c,setVisible:d=>{e.style.display=d?"block":"none"}}}function rn(t,e,i,o){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",o),r.appendChild(i),r}function ui(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 i=n.div({display:"flex",alignItems:"center",gap:"12px",minWidth:"0"}),o=rn("ago-chat-widget__back",t.labels.back,n.chevronLeftIcon({size:20}),t.onBack);o.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"}),i.append(o,r);const s=n.div({display:"flex",alignItems:"center",gap:"8px",flexShrink:"0"}),c=rn("ago-chat-widget__new",t.labels.newChat,n.addCommentIcon({size:20}),t.onNewChat),d=rn("ago-chat-widget__close",t.labels.close,n.closeIcon({size:20}),t.onClose);return s.append(c,d),e.append(i,s),{el:e,update:({screen:h})=>{o.style.display=h==="chat"?"flex":"none",c.style.display=h==="home"?"none":"flex",r.textContent=h==="history"?t.labels.history:t.title}}}var uo={minutes:"{n}min ago",hours:"{n}h ago",days:"{n}d ago",weeks:"{n} weeks ago",months:"{n} months ago"},fi=60*1e3;function mi(t,e=Date.now(),i=uo){const o=t instanceof Date?t.getTime():new Date(t).getTime(),r=(p,x)=>p.replace("{n}",String(x));if(!Number.isFinite(o))return r(i.minutes,0);const s=Math.max(0,Math.floor((e-o)/fi)),c=Math.floor(s/60),d=Math.floor(c/24),h=Math.floor(d/7),f=Math.max(1,Math.floor(d/30));return s<60?r(i.minutes,s):c<24?r(i.hours,c):d<7?r(i.days,d):h<4?r(i.weeks,h):r(i.months,f)}var an={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:uo};function gi(t){return{...an,...t,timeAgo:{...an.timeAgo,...t?.timeAgo}}}var hi={"&":"&","<":"<",">":">",'"':""","'":"'"};function Xe(t){return t.replace(/[&<>"']/g,e=>hi[e])}function io(t){const e=t.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(e)||!/^[a-z][a-z0-9+.-]*:/i.test(e)?e:null}var fo='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',At="";function ze(t){const e=[],i=r=>(e.push(r),`${At}${e.length-1}${At}`);let o=t;return o=o.replace(/`([^`]+)`/g,(r,s)=>i(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${fo}">${Xe(s)}</code>`)),o=o.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(r,s,c)=>{const d=io(c);return d?i(`<img alt="${Xe(s)}" src="${Xe(d)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):r}),o=o.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(r,s,c)=>{const d=io(c);return d?i(`<a href="${Xe(d)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${ze(s)}</a>`):r}),o=Xe(o),o=o.replace(/\*\*([^*]+?)\*\*/g,"<strong>$1</strong>").replace(/__([^_]+?)__/g,"<strong>$1</strong>").replace(/~~([^~]+?)~~/g,"<del>$1</del>").replace(/(^|[^*])\*(?!\s)([^*]+?)\*/g,"$1<em>$2</em>").replace(/(^|[^\w_])_(?!\s)([^_]+?)_/g,"$1<em>$2</em>"),o=o.replace(new RegExp(`${At}(\\d+)${At}`,"g"),(r,s)=>e[Number(s)]),o}function de(t,e,i){const o=document.createElement(t);return Object.assign(o.style,e),i!==void 0&&(o.innerHTML=i),o}var mo=/^ {0,3}([-*_])( *\1){2,} *$/,go=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,ho=/^ {0,3}(```+|~~~+)/,Ot=/^ {0,3}>\s?/,Ye=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,bi=["20px","18px","16px","15px","14px","13px"],sn=t=>t.match(/^\s*/)?.[0].length??0;function xi(t){return t.trim()===""||mo.test(t)||go.test(t)||ho.test(t)||Ot.test(t)||Ye.test(t)}function bo(t){const e=t[0].match(Ye),i=e[1].length,o=/\d/.test(e[2]),r=de(o?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:o?"decimal":"disc",listStylePosition:"outside"});let s=0;for(;s<t.length;){const c=t[s].match(Ye),d=[];for(s++;s<t.length&&sn(t[s])>i;)d.push(t[s]),s++;const h=de("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),f=c[3].match(/^\[([ xX])\]\s+(.*)$/);f?(h.style.listStyleType="none",h.style.marginLeft="-20px",h.innerHTML=`<span style="margin-right:6px">${f[1].toLowerCase()==="x"?"☑":"☐"}</span>${ze(f[2])}`):h.innerHTML=ze(c[3]),d.filter(p=>Ye.test(p)).length>0&&h.appendChild(bo(d.filter(p=>p.trim()!==""))),r.appendChild(h)}return r}function yi(t){const e=d=>d.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(h=>h.trim()),i=de("div",{overflowX:"auto",margin:"0 0 8px 0"}),o=de("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),r=document.createElement("thead"),s=document.createElement("tr");for(const d of e(t[0]))s.appendChild(de("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},ze(d)));r.appendChild(s),o.appendChild(r);const c=document.createElement("tbody");for(const d of t.slice(2)){const h=document.createElement("tr");for(const f of e(d))h.appendChild(de("td",{border:"1px solid #dee3e8",padding:"6px 10px"},ze(f)));c.appendChild(h)}return o.appendChild(c),i.appendChild(o),i}var Ci=t=>!!t&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(t);function Me(t){const e=document.createDocumentFragment(),i=t.replace(/\r\n?/g,`
|
|
2
2
|
`).split(`
|
|
3
|
-
`);let
|
|
4
|
-
`)))),e.appendChild(
|
|
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;
|
|
3
|
+
`);let o=0;for(;o<i.length;){const s=i[o];if(s.trim()===""){o++;continue}const c=s.match(ho);if(c){const f=c[1][0],p=[];for(o++;o<i.length&&!new RegExp(`^ {0,3}${f==="`"?"`{3,}":"~{3,}"}\\s*$`).test(i[o]);)p.push(i[o]),o++;o++;const x=de("pre",{margin:"0 0 8px 0"});x.appendChild(de("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:fo,whiteSpace:"pre"},Xe(p.join(`
|
|
4
|
+
`)))),e.appendChild(x);continue}if(mo.test(s)){e.appendChild(de("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),o++;continue}const d=s.match(go);if(d){const f=d[1].length;e.appendChild(de(`h${f}`,{margin:"16px 0 8px 0",fontSize:bi[f-1],fontWeight:"600",lineHeight:"1.3"},ze(d[2]))),o++;continue}if(Ot.test(s)){const f=[];for(;o<i.length&&Ot.test(i[o]);)f.push(i[o].replace(Ot,"")),o++;const p=de("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});p.appendChild(Me(f.join(`
|
|
5
|
+
`))),e.appendChild(p);continue}if(s.includes("|")&&Ci(i[o+1])){const f=[s,i[o+1]];for(o+=2;o<i.length&&i[o].includes("|")&&i[o].trim();)f.push(i[o]),o++;e.appendChild(yi(f));continue}if(Ye.test(s)){const f=[],p=sn(s);for(;o<i.length&&i[o].trim()!=="";)if(Ye.test(i[o])||sn(i[o])>p)f.push(i[o]),o++;else break;e.appendChild(bo(f));continue}const h=[s];for(o++;o<i.length&&!xi(i[o]);)h.push(i[o]),o++;e.appendChild(de("p",{margin:"0 0 8px 0",lineHeight:"1.6"},h.map(f=>ze(f)).join("<br>")))}const r=e.lastElementChild;return r&&(r.style.marginBottom="0"),e}function vi(t,e){const i=n.div({display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:e.isUser?"flex-end":"flex-start",maxWidth:"75%"});i.className="ago-message__attachments";for(const o of t){const r=_e.safeAttachmentUrl(o.url);if(_e.canInlineImage(o)&&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 x=document.createElement("img");x.src=r,x.alt=o.name,x.loading="lazy",n.css(x,{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:`1px solid ${n.BORDER_COLOR}`,display:"block"}),p.appendChild(x),i.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 c=document.createElement("span");c.textContent="📄",c.setAttribute("aria-hidden","true"),n.css(c,{fontSize:"16px",lineHeight:"1",flexShrink:"0"});const d=n.div({display:"flex",flexDirection:"column",minWidth:"0"}),h=n.div({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"});h.textContent=o.name,h.title=o.name,d.appendChild(h);const f=_e.formatFileSize(o.fileSize);if(f){const p=n.div({fontSize:"11px",color:n.MUTED_TEXT_COLOR});p.textContent=f,d.appendChild(p)}s.append(c,d),i.appendChild(s)}return i}function xo(t,e){const i=e.look==="embed",o=n.div({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:i?"16px":"10px"});o.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,i?{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 c=e.handler;s.addEventListener("click",()=>c(r))}s.addEventListener("mouseenter",()=>{i?s.style.backgroundColor="#fafafa":s.style.borderColor=n.ACCENT_COLOR}),s.addEventListener("mouseleave",()=>{i?s.style.backgroundColor="#fff":s.style.borderColor=n.BORDER_COLOR}),o.appendChild(s)}return o}function Ei(t,e){const{isLast:i,isLastOfBlock:o,bubbleStyle:r,showAgentName:s,agentBubble:c,followUpEnabled:d,followUpHandler:h,isMobile:f,feedbackRow:p}=e,x=t.role==="user",I=r==="imessage",w=n.div({display:"flex",flexDirection:"column",alignItems:x?"flex-end":"flex-start",marginBottom:I&&!o?"2px":"16px"});if(w.className=`ago-message ago-message--${t.role}`,!x&&s&&t.agent){const E=n.div({fontSize:"13px",fontWeight:"500",color:n.TEXT_COLOR,marginBottom:"6px",padding:"0 4px"});E.className="ago-message__agent",E.textContent=t.agent.displayName||t.agent.name,w.appendChild(E)}if(!x&&t.sources&&t.sources.length>0){const E=n.div({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});E.className="ago-message__sources",t.sources.forEach((O,W)=>{const C=O.url?document.createElement("a"):document.createElement("div");O.url&&C instanceof HTMLAnchorElement&&(C.href=O.url,C.target="_blank",C.rel="noopener noreferrer"),n.css(C,{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 F=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"});F.textContent=String(W+1);const y=n.div({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});y.textContent=O.title,y.title=O.title,C.append(F,y),E.appendChild(C)}),w.appendChild(E)}if(t.attachments&&t.attachments.length>0&&w.appendChild(vi(t.attachments,{isUser:x,cardBackground:x?"rgba(255,255,255,0.12)":n.PANEL_BACKGROUND,cardColor:x?n.BRAND_TEXT_COLOR:n.TEXT_COLOR})),!x&&e.renderToolCall&&t.toolCalls?.length)for(const E of t.toolCalls){const O=e.renderToolCall(E,t);O&&w.appendChild(O)}const u=x||c||I,v=!!t.content||t.status==="IN_PROGRESS"||t.status==="WAITING_CLIENT",A=n.div({maxWidth:u?I||x?f?"88%":"75%":f?"92%":"85%":"100%",padding:u?"10px 14px":"2px 8px",borderRadius:I?n.MESSAGE_RADIUS_IMESSAGE:u?n.MESSAGE_RADIUS:"0",backgroundColor:x?n.BRAND_COLOR:u?n.AGENT_BUBBLE_BACKGROUND:"transparent",color:x?n.BRAND_TEXT_COLOR:n.TEXT_COLOR,overflowWrap:"break-word",textWrap:"pretty",fontSize:"16px",lineHeight:"1.6"});if(A.className="ago-message__content",I&&o){A.style.position="relative";const E=n.div({position:"absolute",zIndex:"0",bottom:"-2px",width:"20px",height:"20px",background:x?n.BRAND_COLOR:n.AGENT_BUBBLE_BACKGROUND});E.className="ago-message__tail";const O=n.div({position:"absolute",zIndex:"1",bottom:"-2px",width:"10px",height:"20px",background:n.MESSAGES_BACKGROUND});O.className="ago-message__tail-mask",x?(E.style.right="-8px",E.style.borderBottomLeftRadius="16px 14px",O.style.right="-10px",O.style.borderBottomLeftRadius="10px"):(E.style.left="-7px",E.style.borderBottomRightRadius="16px 14px",O.style.left="-10px",O.style.borderBottomRightRadius="10px"),A.append(E,O)}return t.content?A.appendChild(Me(t.content)):(t.status==="IN_PROGRESS"||t.status==="WAITING_CLIENT")&&A.appendChild(ki()),v&&w.appendChild(A),!x&&p&&w.appendChild(p),i&&t.followUpReplies&&t.followUpReplies.length>0&&w.appendChild(xo(t.followUpReplies,{enabled:d,handler:h,look:"classic"})),w}function wi(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 i=document.createElement("span");i.textContent="✓",i.setAttribute("aria-hidden","true"),n.css(i,{fontWeight:"700"});const o=document.createElement("span");return o.textContent=t,e.append(i,o),e}function ki(){const t=n.div({display:"flex",gap:"4px",padding:"4px 0"});for(let e=0;e<3;e++){const i=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(i)}return t}function _i(){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 i=document.createElementNS(t,"path");return i.setAttribute("d","M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"),i.setAttribute("stroke","currentColor"),i.setAttribute("stroke-width","2"),i.setAttribute("stroke-linecap","round"),i.setAttribute("stroke-linejoin","round"),e.appendChild(i),e}function Si(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(_i());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 i,o;if(t.icon){const r=document.createElement("img");r.src=t.icon,r.alt="",n.css(r,{width:"32px",height:"32px",objectFit:"contain"}),i=r,o=n.launcherCloseIcon(),e.append(r,o)}else{const r=n.launcherIcon();i=r.querySelector('[data-ago-path="open"]'),o=r.querySelector('[data-ago-path="close"]'),e.appendChild(r)}return o.style.display="none",e.addEventListener("click",t.onClick),{el:e,setOpen:r=>{i.style.display=r?"none":"",o.style.display=r?"":"none",e.setAttribute("aria-expanded",r?"true":"false"),e.setAttribute("aria-label",`${r?"Close":"Open"} ${t.title}`)}}}function Ti(t){const e=n.div({marginBottom:"12px",display:"flex",flexWrap:"wrap",gap:"8px"});e.className="ago-message__attachments";for(const i of t.attachments??[]){const o=_e.safeAttachmentUrl(i.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(_e.canInlineImage(i)&&o){const s=document.createElement("a");s.href=o,s.target="_blank",s.rel="noopener noreferrer",n.css(s,{display:"flex",flexDirection:"column",gap:"4px",textDecoration:"none",color:"inherit"});const c=document.createElement("img");c.src=o,c.alt=i.name,c.loading="lazy",n.css(c,{height:"128px",maxWidth:"100%",objectFit:"contain",borderRadius:"4px",display:"block"});const d=n.div({fontSize:"12px",lineHeight:"16px",color:"#4b5563",maxWidth:"150px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});d.textContent=i.name,s.append(c,d),r.appendChild(s)}else{const s=o?document.createElement("a"):document.createElement("span");o&&s instanceof HTMLAnchorElement&&(s.href=o,s.target="_blank",s.rel="noopener noreferrer",s.download=i.name),n.css(s,{display:"flex",alignItems:"center",gap:"8px",textDecoration:"none",color:"inherit",minWidth:"0"});const c=document.createElement("span");c.textContent=i.name,c.title=i.name,n.css(c,{maxWidth:"150px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),s.append(n.downloadIcon({size:20}),c);const d=_e.formatFileSize(i.fileSize);if(d){const h=document.createElement("span");h.textContent=d,n.css(h,{fontSize:"12px",lineHeight:"16px",color:"#6b7280"}),s.appendChild(h)}r.appendChild(s)}e.appendChild(r)}return e}function Ri(t){const e=n.div({display:"flex",justifyContent:"flex-end"}),i=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"});i.className="ago-message__content",t.attachments?.length&&i.appendChild(Ti(t));const o=n.div({whiteSpace:"pre-wrap",overflowWrap:"break-word"});return o.textContent=t.content,i.appendChild(o),e.appendChild(i),e}function Ai(t){const e=n.div({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px",paddingBottom:"16px"});return e.className="ago-message__sources",(t.sources??[]).forEach((i,o)=>{const r=i.url?document.createElement("a"):document.createElement("div");i.url&&r instanceof HTMLAnchorElement&&(r.href=i.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"}),c=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"});c.textContent=String(o+1);const d=n.div({fontSize:"12px",lineHeight:"16px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:"0"});d.textContent=i.title,d.title=i.title,s.append(c,d),r.appendChild(s),e.appendChild(r)}),e}function Oi(t,e){return yo({errorTitle:t,errorDescription:e})}function yo(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 i=n.alertCircleIcon({size:16});n.css(i,{position:"absolute",left:"16px",top:"16px"});const o=document.createElement("h5");o.textContent=t.errorTitle,n.css(o,{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(i,o,r),e}function Li(){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 Ni(){const t=n.div({display:"flex",alignItems:"center",padding:"8px",gap:"8px"});t.className="ago-message__spinner";const e=n.spokeSpinnerIcon({size:20});return n.css(e,{color:"#a1a1aa",animation:"ago-spin 1s linear infinite"}),t.appendChild(e),t}function Fi(t,e){const i=t.status==="IN_PROGRESS"||t.status==="WAITING_CLIENT",o=n.div({position:"relative",display:"flex",alignItems:"flex-start",borderRadius:"16px",padding:"8px",marginBottom:"16px",boxSizing:"border-box"});o.className="ago-message__row",e.agentRowTinted&&(o.style.backgroundColor=n.AGENT_BUBBLE_BACKGROUND),e.agentRowTextTinted&&(o.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",i&&r.appendChild(Ni()),t.sources?.length&&r.appendChild(Ai(t)),e.renderToolCall&&t.toolCalls?.length)for(const s of t.toolCalls){const c=e.renderToolCall(s,t);c&&r.appendChild(c)}if(t.status==="ERROR")r.appendChild(yo(e.labels));else if(t.content){const s=n.div({});s.className="ago-message__markdown ago-message__content",s.appendChild(Me(t.content)),r.appendChild(s)}else i&&r.appendChild(Li());return e.isLast&&t.status==="DONE"&&t.followUpReplies?.length&&r.appendChild(xo(t.followUpReplies,{enabled:e.followUpEnabled,handler:e.followUpHandler,look:"embed"})),e.actionsRow&&!i&&r.appendChild(e.actionsRow),o.appendChild(r),o}function Ii(t,e){const i=n.div({});return i.className=`ago-message ago-message--${t.role}`,i.dataset.messageId=t.id,i.dataset.messageRole=t.role,i.appendChild(t.role==="user"?Ri(t):Fi(t,e)),i}var ln="ago-hs-form-ready";function Di(t,e){const i=t.tagName==="TEXTAREA"?Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,"value"):Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value"),o=t._valueTracker;o&&o.setValue(""),t.focus(),t.dispatchEvent(new Event("focus",{bubbles:!0})),i?.set?i.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 Nt(t,e){const i=t.querySelectorAll("input, textarea, select");let o=!1;for(const r of i){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&&(Di(r,s),o=!0)}return o}function Bi(t){return`function($f){document.dispatchEvent(new CustomEvent(${JSON.stringify(ln)},{detail:{token:${JSON.stringify(t)},form:$f}}))}`}function Hi(t,e,i){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:${Bi(i)},`):t}function zi(t,e){if(!t||Object.keys(t).length===0)return()=>{};const i={};for(const[c,d]of Object.entries(t))d!=null&&d!==""&&(i[c]=d);const o=[],r=[],s=c=>{const d=c.detail;if(!d||d.token!==e)return;const h=d.form,f=h&&typeof h=="object"&&"jquery"in h&&h.jquery?h[0]:h;if(!f||typeof f.querySelectorAll!="function")return;Nt(f,i);const p=new MutationObserver(()=>{Nt(f,i)});p.observe(f,{childList:!0,subtree:!0}),o.push(p),r.push(setTimeout(()=>p.disconnect(),1e4))};return document.addEventListener(ln,s),()=>{document.removeEventListener(ln,s),o.forEach(c=>c.disconnect()),r.forEach(c=>clearTimeout(c))}}function Co(){return globalThis.HubSpotFormsV4}async function vo(t,e){let i=null;if(t.getFormFieldValues)try{const o=await t.getFormFieldValues();let r=[];Array.isArray(o)?r=o.filter(s=>typeof s=="object"&&s!==null).map(s=>s.name).filter(s=>typeof s=="string"):typeof o=="object"&&o!==null&&(r=Object.keys(o)),r.length>0&&(i=r)}catch{}for(const[o,r]of Object.entries(e)){if(!r)continue;let s;if(o.includes("/"))s=o;else if(i){const c=i.find(d=>d.endsWith("/"+o));if(!c)continue;s=c}else s=`0-1/${o}`;try{t.setFieldValue(s,r)}catch{}}}function ro(t){if(!t||Object.keys(t).length===0)return()=>{};const e=i=>{try{const o=Co()?.getFormFromEvent?.(i);if(!o?.setFieldValue)return;vo(o,t)}catch{}};return window.addEventListener("hs-form-event:on-ready",e),()=>window.removeEventListener("hs-form-event:on-ready",e)}function Mi(t){const e=Co()?.getForms?.();if(!Array.isArray(e)||e.length===0)return!1;for(const i of e)i?.setFieldValue&&vo(i,t);return!0}var dn="ago-hs-form-submit",cn="ago-hs-form-submitted";function Lt(t){if(!t||typeof t!="object")return t;let e;if(Array.isArray(t)){e={};for(const o of t)o&&typeof o=="object"&&"name"in o&&o.name&&o.value!==void 0&&(e[o.name]=o.value)}else e=t;const i={};for(const[o,r]of Object.entries(e)){const s=o.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||(i[s]=r))}return Object.keys(i).length>0?i:null}function $i(t){try{const e=new FormData(t),i={};return e.forEach((o,r)=>{o instanceof File||(i[r]=o)}),Object.keys(i).length>0?i:null}catch{return null}}function ao(t,e,i){const o=i?`{token:${JSON.stringify(e)},form:$f}`:`{token:${JSON.stringify(e)}}`;return`function(${i?"$f":""}){document.dispatchEvent(new CustomEvent(${JSON.stringify(t)},{detail:${o}}))}`}function Ui(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:${ao(dn,e,!0)},onFormSubmitted:${ao(cn,e,!1)},`):t)}function Wi(t,e,i,o){let r=!1,s=null;function c(){r||(r=!0,e(Lt(s)))}function d(u){if(s||(s=$i(u)),u.closest(".hs-form, .hbspt-form, [data-hs-forms]")){i?.();return}c()}const h=u=>{const v=u.target;v?.tagName==="FORM"&&d(v)};t.addEventListener("submit",h,!0);const f=new WeakSet;function p(u){f.has(u)||(f.add(u),u.addEventListener("submit",()=>d(u)))}for(const u of t.querySelectorAll("form"))p(u);const x=new MutationObserver(()=>{for(const u of t.querySelectorAll("form"))p(u)});x.observe(t,{childList:!0,subtree:!0});const I=u=>{const v=u.detail;if(!(!v||v.token!==o))try{const A=v.form,E=A&&typeof A=="object"&&"jquery"in A&&A.jquery?A[0]:A;if(E?.querySelectorAll){const O=E.querySelectorAll("input, textarea, select"),W={};for(const C of O)C.name&&C.type!=="submit"&&C.type!=="button"&&(W[C.name]=C.value||"");Object.keys(W).length>0&&(s=W)}}catch{}},w=u=>{const v=u.detail;!v||v.token!==o||c()};return document.addEventListener(dn,I),document.addEventListener(cn,w),()=>{t.removeEventListener("submit",h,!0),x.disconnect(),document.removeEventListener(dn,I),document.removeEventListener(cn,w)}}function ie(t){return t.externalId||t.id}function Eo(t){return t.conditionalFieldValues?.length?t.conditionalFieldValues:t.conditionalFieldValue?.split(",").map(e=>e.trim()).filter(Boolean)??[]}function mn(t,e){return!t.priorityTypologies?.length||!e||t.priorityTypologies.includes(e)}function wo(t,e,i,o,r,s){if(!e||!i.length)return!0;const c=t.fields.find(d=>d.id===e||d.externalId===e);return c?Ft(t,c,o,r,s)&&i.includes(o[ie(c)]):!0}function Ft(t,e,i,o="",r=new Set){if(e.active===!1||r.has(e.id)||e.title==="Priority"&&!mn(t,o))return!1;const s=new Set(r).add(e.id);return wo(t,e.conditionalFieldId,Eo(e),i,o,s)}function ko(t,e,i,o=""){return e.options.filter(r=>wo(t,r.conditionalFieldId,r.conditionalFieldValues??[],i,o,new Set)).sort((r,s)=>(r.position??0)-(s.position??0))}function Ke(t,e,i=""){let o;do{o=!1;for(const r of t.fields){const s=ie(r);if(!(s in e))continue;const c=!r.options.length||!e[s]||ko(t,r,e,i).some(d=>(d.value??d.name??"")===e[s]);(!Ft(t,r,e,i)||!c)&&(delete e[s],o=!0)}}while(o)}function Pi(t,e,i=""){const o=[...t.fields].sort((r,s)=>r.position-s.position).filter(r=>!r.hidden&&Ft(t,r,e,i));return o.filter((r,s)=>{if(s===0||r.alwaysVisible||r.conditionalFieldId&&Eo(r).length)return!0;const c=o[s-1];return c.type==="checkbox"||!!e[ie(c)]?.trim()})}var ji="var(--ago-send-button-background, var(--ago-accent-color, #003edf))",Gi=/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z]{2,}$/;function Vi(t){return t.toLowerCase().trim().replace(/[^a-z0-9_]/g,"_")}function _o(t,e,i){const o={};if(e){for(const r of e.fields){if(r.active===!1)continue;const s=r.options.find(c=>c.default);s&&(o[ie(r)]=s.value??s.name??"")}if(t?.tag)for(const r of e.fields)r.type==="tagger"&&(o[ie(r)]=t.tag);if(t?.custom_fields)for(const[r,s]of Object.entries(t.custom_fields)){const c=e.fields.find(d=>d.externalId===r||d.id===r||(d.title?Vi(d.title)===r:!1));c&&(o[ie(c)]=s)}}return e&&Ke(e,o,t?.typology??"Question"),{ticket:{subject:t?.subject??"",typology:t?.typology??"Question",priority:t?.priority??"Normal",body:t?.body??"",tag:t?.tag??""},customFields:o,files:[],email:i,errors:{},submittedOnce:!1,loading:!1,submitError:null}}function qi(t,e,i){t.customFields={..._o(e,i,t.email).customFields,...t.customFields},Ke(i,t.customFields,t.ticket.typology)}function so(t,e){return t.replace(/\{(\w+)\}/g,(i,o)=>e[o]??"")}function Xi(t,e,i,o){const r={},s=e.ticket;t.showSubject&&!s.subject.trim()&&(r.subject=i.subjectRequired),t.showTypology&&!s.typology.trim()&&(r.typology=i.typologyRequired),t.showPriority&&mn(t,s.typology)&&!s.priority.trim()&&(r.priority=i.priorityRequired),t.showBody&&!s.body.trim()&&(r.body=i.detailedContextRequired);for(const c of t.fields){if(c.hidden||!Ft(t,c,e.customFields,s.typology))continue;const d=e.customFields[ie(c)];if(c.required&&!d?.trim())r[ie(c)]=so(i.fieldRequired,{fieldTitle:c.title??""});else if(c.regexpForValidation&&d?.trim())try{new RegExp(c.regexpForValidation).test(d)||(r[ie(c)]=so(i.fieldFormatInvalid,{fieldTitle:c.title??""}))}catch{}}return o&&(e.email.trim()?Gi.test(e.email)||(r.userEmail=i.emailInvalid):r.userEmail=i.emailRequired),r}var Ki={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 De(t,e){const i=document.createElement("label");return i.htmlFor=e,i.textContent=t,n.css(i,{display:"block",fontWeight:"600"}),i}function he(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 Be(){const t=n.div({display:"flex",flexDirection:"column",gap:"8px"});return t.className="ago-ticket-form__field",t}function He(t,e,i){n.css(t,Ki),e&&(t.style.borderColor="#ef4444"),t.disabled=i,i&&(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 So(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 i=document.createElement("p");if(i.textContent=t.text,n.css(i,{whiteSpace:"pre-line",margin:"0"}),e.appendChild(i),t.ticketUrl){const o=n.div({marginTop:"4px"});if(o.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"}),o.appendChild(r)}else{const r=document.createElement("span");r.textContent=t.ticketUrl,r.style.fontWeight="700",o.appendChild(r)}e.appendChild(o)}return e}function Yi(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 i=document.createElement("span");i.textContent="i",i.setAttribute("aria-hidden","true"),n.css(i,{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 o=n.div({minWidth:"0"});return o.appendChild(Me(t)),e.append(i,o),e}function Qi(t){const{state:e,labels:i}=t;let o=t.ticketForm,r=t.configLoading,s=t.allowFiles;const c=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"});c.className="ago-ticket-form";function d(){return o?(e.errors=Xi(o,e,i,t.requireEmail),Object.keys(e.errors).length===0):!1}async function h(){if(!(e.loading||!o)){if(Ke(o,e.customFields,e.ticket.typology),e.submittedOnce=!0,e.submitError=null,!d()){e.submitError=`${i.validationFailed}: ${i.pleaseCheckFields}`,w();return}e.loading=!0,w();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(([v,A])=>({id:v,value:A})),email:t.requireEmail?e.email:void 0,ticketFormId:o.id});e.loading=!1,e.submitted={ticketId:u.id,ticketUrl:u.url},w(),t.onCreated(u,e)}catch(u){e.loading=!1;const v=u instanceof Error?u:new Error(String(u)),A=v.status;let E=i.submissionFailed,O=i.submissionFailedDescription;A===413?E=i.fileTooLarge:A===403?E=i.permissionDenied:A===422?(E=i.validationFailed,O=v.message||i.pleaseCheckFields):v.message&&(O=v.message),e.submitError=`${E}: ${O}`,w(),t.onError?.(v)}}}function f(u,v){const A=ie(u);e.customFields[A]=v,o&&Ke(o,e.customFields,e.ticket.typology),e.submittedOnce&&d(),w()}function p(){e.submittedOnce&&d()}function x(u){const v=ie(u),A=`ago-ticket-field-${v}`,E=e.customFields[v]??"",O=e.loading,W=e.errors[v];if(u.type==="checkbox"){const k=n.div({display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"});k.className="ago-ticket-form__field";const S=document.createElement("input");S.type="checkbox",S.id=A,S.checked=E==="true",S.disabled=O,n.css(S,{width:"16px",height:"16px",margin:"0"}),S.addEventListener("change",()=>f(u,S.checked?"true":"false"));const D=document.createElement("label");return D.htmlFor=A,D.textContent=u.title??"",D.style.fontWeight="600",k.append(S,D),W&&k.appendChild(he(W)),k}const C=Be();C.appendChild(De(u.title??"",A));const F=ko(o,u,e.customFields,e.ticket.typology).filter(k=>!k.noDisplay);if(u.options.length>0){const k=document.createElement("select");k.id=A;const S=document.createElement("option");S.value="",S.textContent="----",k.appendChild(S);const D=new Map;for(const M of F){const j=document.createElement("option");if(j.value=M.value??M.name??"",j.textContent=M.name??M.value??"",M.group){let b=D.get(M.group);b||(b=document.createElement("optgroup"),b.label=M.group,D.set(M.group,b),k.appendChild(b)),b.appendChild(j)}else k.appendChild(j)}k.value=E,He(k,!!W,O),k.addEventListener("change",()=>f(u,k.value)),C.appendChild(k);const V=F.find(M=>(M.value??M.name)===E);if(W&&C.appendChild(he(W)),V?.message){const M={info:{bg:"#eff6ff",border:"#bfdbfe",text:"#1e3a8a"},warning:{bg:"#fffbeb",border:"#fcd34d",text:"#78350f"},danger:{bg:"#fef2f2",border:"#fca5a5",text:"#7f1d1d"}}[V.messageType??"info"],j=document.createElement("p");j.className="ago-ticket-form__option-message",j.textContent=V.message,n.css(j,{fontSize:"14px",lineHeight:"20px",border:`1px solid ${M.border}`,backgroundColor:M.bg,color:M.text,borderRadius:"4px",padding:"8px",whiteSpace:"pre-line",margin:"0"}),C.appendChild(j)}return C}const y=document.createElement("input");return y.type="text",y.id=A,y.value=E,He(y,!!W,O),y.addEventListener("input",()=>{e.customFields[v]=y.value,o&&Ke(o,e.customFields,e.ticket.typology),e.submittedOnce&&(d(),I())}),y.addEventListener("change",()=>w()),C.appendChild(y),W&&C.appendChild(he(W)),C}function I(){for(const u of c.querySelectorAll("[data-ago-error-for]")){const v=u.dataset.agoErrorFor,A=u.querySelector(".ago-ticket-form__error"),E=e.errors[v],O=u.querySelector("input, select, textarea");O&&(O.style.borderColor=E?"#ef4444":""),O&&!E&&(O.style.border=`1px solid ${n.BORDER_COLOR}`),E&&!A?u.appendChild(he(E)):E&&A?A.textContent=E:!E&&A&&A.remove()}}function w(){if(c.replaceChildren(),t.message){const b=n.div({fontWeight:"500",color:"#1e40af",backgroundColor:"#eff6ff",padding:"12px",borderRadius:"4px"});b.className="ago-ticket-form__message",b.textContent=t.message,c.appendChild(b)}if(e.submitted){c.appendChild(So({text:t.successMessage||o?.successMessageText||i.ticketSubmitted,ticketUrl:e.submitted.ticketUrl,urlLabel:t.successUrlLabel||o?.successMessageUrlLabel||i.findTicketHere}));return}if(r){const b=n.div({padding:"16px",textAlign:"center",fontWeight:"700",fontSize:"20px"});b.className="ago-ticket-form__config-loading",b.setAttribute("role","status"),b.textContent=i.loading,c.appendChild(b);return}if(!o){const b=n.div({backgroundColor:"#fee2e2",color:"#991b1b",padding:"16px",borderRadius:"4px"});b.className="ago-ticket-form__missing",b.textContent=i.noTicketForm,c.appendChild(b);return}const u=o,v=e.loading;if(e.loading){const b=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"});b.className="ago-ticket-form__loading",b.setAttribute("role","status"),b.textContent=i.loading,c.appendChild(b)}const A=n.div({fontWeight:"600",backgroundColor:"#bfdbfe",padding:"16px",borderRadius:"4px"});if(A.className="ago-ticket-form__intro",A.textContent=i.useFormToCreateTicket,c.appendChild(A),t.requireEmail){const b=Be();b.dataset.agoErrorFor="userEmail",b.appendChild(De(`${i.yourEmail} *`,"ago-ticket-email"));const R=document.createElement("input");R.type="email",R.id="ago-ticket-email",R.placeholder=i.emailPlaceholder,R.value=e.email,He(R,!!e.errors.userEmail,v),R.addEventListener("input",()=>{e.email=R.value,e.submittedOnce&&(d(),I())}),b.appendChild(R),e.errors.userEmail&&b.appendChild(he(e.errors.userEmail)),c.appendChild(b)}const E=u.showSubject&&!!e.ticket.subject||!u.showSubject,O=E&&(!!e.ticket.typology||!u.showTypology),W=u.showPriority&&mn(u,e.ticket.typology),C=O&&(!!e.ticket.priority||!W);if(u.showSubject){const b=Be();b.dataset.agoErrorFor="subject",b.appendChild(De(i.subject,"ago-ticket-subject"));const R=document.createElement("input");R.type="text",R.id="ago-ticket-subject",R.value=e.ticket.subject,He(R,!!e.errors.subject,v),R.addEventListener("input",()=>{e.ticket.subject=R.value,p(),I()}),R.addEventListener("change",()=>w()),b.appendChild(R),e.errors.subject&&b.appendChild(he(e.errors.subject)),c.appendChild(b)}if(E&&u.showTypology){const b=Be();b.dataset.agoErrorFor="typology",b.appendChild(De(i.typology,"ago-ticket-typology"));const R=document.createElement("select");R.id="ago-ticket-typology";for(const[z,J]of[["",i.selectTypology],["Question",i.question],["Task",i.task],["Incident",i.incident]]){const Y=document.createElement("option");Y.value=z,Y.textContent=J,R.appendChild(Y)}R.value=e.ticket.typology,He(R,!!e.errors.typology,v),R.addEventListener("change",()=>{e.ticket.typology=R.value,Ke(u,e.customFields,e.ticket.typology),p(),w()}),b.appendChild(R),e.errors.typology&&b.appendChild(he(e.errors.typology)),c.appendChild(b)}if(O&&W){const b=Be();b.dataset.agoErrorFor="priority",b.appendChild(De(i.priority,"ago-ticket-priority"));const R=document.createElement("select");R.id="ago-ticket-priority";for(const[z,J]of[["",i.selectPriority],["Low",i.low],["Normal",i.normal],["High",i.high],["Urgent",i.urgent]]){const Y=document.createElement("option");Y.value=z,Y.textContent=J,R.appendChild(Y)}R.value=e.ticket.priority,He(R,!!e.errors.priority,v),R.addEventListener("change",()=>{e.ticket.priority=R.value,p(),w()}),b.appendChild(R),e.errors.priority&&b.appendChild(he(e.errors.priority)),c.appendChild(b)}if(C){const b=new Set(Pi(u,e.customFields,e.ticket.typology));for(const R of[...u.fields].sort((z,J)=>z.position-J.position)){if(!b.has(R)&&!e.errors[ie(R)])continue;const z=x(R);z.dataset.agoErrorFor=ie(R),c.appendChild(z)}}const F=Be();F.dataset.agoErrorFor="body",F.appendChild(De(i.detailedContext,"ago-ticket-body"));const y=document.createElement("textarea");y.id="ago-ticket-body",y.rows=4,y.value=e.ticket.body,He(y,!!e.errors.body,v),n.css(y,{resize:"vertical",maxHeight:"240px",overflowY:"auto"});const k=n.div({fontSize:"14px",lineHeight:"20px",marginTop:"4px",textAlign:"right",display:"none"});k.className="ago-ticket-form__counter";const S=()=>{const b=e.ticket.body.length;k.style.display=b>6e4?"block":"none",k.style.color=b>65535?"#dc2626":"#d97706",k.textContent=`${b} / 65,535 · ${i.maxCharacters}`},D=()=>{y.style.height="auto",y.style.height=`${y.scrollHeight}px`};if(y.addEventListener("input",()=>{e.ticket.body=y.value,p(),I(),S(),D()}),F.append(y,k),S(),e.errors.body&&F.appendChild(he(e.errors.body)),c.appendChild(F),s){const b=Be();b.className="ago-ticket-form__field ago-ticket-form__attachments",b.appendChild(De(i.attachments,"ago-ticket-files"));const R=document.createElement("label");R.htmlFor="ago-ticket-files",R.textContent=i.selectFile,n.css(R,{display:"inline-block",alignSelf:"flex-start",backgroundColor:"#e5e7eb",padding:"8px 16px",borderRadius:"4px",cursor:"pointer",border:"1px solid #d1d5db",minHeight:"24px"});const z=document.createElement("input");z.type="file",z.id="ago-ticket-files",z.multiple=!0,z.disabled=v,n.css(z,{display:"none"}),z.addEventListener("change",()=>{e.files=[...e.files,...Array.from(z.files??[])],z.value="",w()}),b.append(R,z);const J=n.div({display:"flex",flexDirection:"column",gap:"4px"});e.files.forEach((Y,m)=>{const B=n.div({display:"flex",alignItems:"center",justifyContent:"space-between",backgroundColor:"#f3f4f6",padding:"4px 8px",borderRadius:"4px"}),G=document.createElement("span");G.textContent=`${Y.name} - ${(Y.size/1024).toFixed(1)} KB`;const P=document.createElement("button");P.type="button",P.textContent="×",P.setAttribute("aria-label",`Remove ${Y.name}`),P.disabled=v,n.css(P,{color:"#dc2626",fontWeight:"700",background:"none",border:"none",cursor:"pointer",fontSize:"18px",lineHeight:"1",width:"44px",height:"44px",margin:"-10px -12px -10px 0"}),P.addEventListener("click",()=>{e.files=e.files.filter((ee,re)=>re!==m),w()}),B.append(G,P),J.appendChild(B)}),b.appendChild(J),c.appendChild(b)}if(e.submitError){const b=he(e.submitError);b.setAttribute("role","alert"),b.className="ago-ticket-form__error ago-ticket-form__submit-error",c.appendChild(b)}const V=document.createElement("button");V.type="button",V.className="ago-ticket-form__submit",V.disabled=v,n.css(V,{width:"100%",backgroundColor:ji,color:n.BRAND_TEXT_COLOR,padding:"8px 16px",borderRadius:"4px",border:"none",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",cursor:v?"default":"pointer",fontSize:"16px",lineHeight:"24px",minHeight:"44px",font:"inherit",transition:"filter 0.15s"});const M=document.createElement("span");M.textContent=i.submit;const j=document.createElement("span");j.textContent="→",j.setAttribute("aria-hidden","true"),n.css(j,{fontSize:"20px",lineHeight:"1",transition:"transform 0.15s"}),V.append(M,j),V.addEventListener("mouseenter",()=>{V.style.filter="brightness(0.9)",j.style.transform="translateX(4px)"}),V.addEventListener("mouseleave",()=>{V.style.filter="",j.style.transform=""}),V.addEventListener("click",()=>{h()}),c.appendChild(V)}return w(),{el:c,rebuild:u=>{u&&"ticketForm"in u&&(o=u.ticketForm??null),u&&"configLoading"in u&&(r=!!u.configLoading),u&&"allowFiles"in u&&(s=!!u.allowFiles),w()}}}var Ji=0;async function Zi(t){const e=Array.from(t.querySelectorAll("script"));for(const i of e){const o=document.createElement("script");for(const r of Array.from(i.attributes))o.setAttribute(r.name,r.value);i.src?await new Promise((r,s)=>{o.onload=()=>r(),o.onerror=()=>s(new Error(`Failed to load script: ${i.src}`)),i.parentNode?.replaceChild(o,i)}):(o.textContent=i.textContent,i.parentNode?.replaceChild(o,i))}}function er(t,e){const i={};if(t)for(const[o,r]of Object.entries(t))if(o==="custom_fields"&&r&&typeof r=="object")for(const[s,c]of Object.entries(r))c&&(i[s]=c);else typeof r=="string"&&r&&(i[o]=r);return e&&(i.email=e),Object.keys(i).length>0?i:null}function tr(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 nr(t){const{state:e,labels:i}=t,o=`ago-embed-${Date.now().toString(36)}-${++Ji}`,r=n.div({display:"flex",flexDirection:"column",gap:"16px"});r.className="ago-embed-form",t.message&&r.appendChild(tr(t.message));const s=n.div({display:"flex",flexDirection:"column",gap:"12px"});s.className="ago-embed-form__body",r.appendChild(s);const c=[];let d,h=!1,f=e.status==="submitted",p=null;const x=er(t.ticket,t.email),I=y=>{f||h||(f=!0,d&&(clearTimeout(d),d=void 0),e.status="submitted",e.captured=y??null,F(),t.onSubmitted(y??null))},w=()=>{f||d||(h=!1,d=setTimeout(()=>{f||(d=void 0,e.status="timeout",F())},3e4))},u=()=>{try{const y=globalThis.HubSpotFormsV4?.getForms?.()?.[0];if(y?.getFormFieldValues){const k=new Promise((S,D)=>setTimeout(()=>D(new Error("timeout")),3e3));Promise.race([y.getFormFieldValues(),k]).then(S=>I(Lt(S))).catch(()=>I(p));return}}catch{}I(p)};window.addEventListener("hs-form-event:on-submission:success",u),c.push(()=>window.removeEventListener("hs-form-event:on-submission:success",u));const v=[],A=y=>{const k=y.data;if(k?.type==="hsFormCallback"&&k.eventName==="onFormSubmit"){try{const S=k.data;if(Array.isArray(S)){const D={};for(const M of S)M?.name&&M.value!==void 0&&(D[M.name]=M.value);const V=Lt(D);V&&(p=V)}}catch{}return}if(k?.type==="hsFormCallback"&&k.eventName==="onFormSubmitted"){I(p);return}if(k?.type==="HS_CTA_PARENT_INIT"&&y.ports?.[0]){const S=y.ports[0],D=V=>{const M=V.data;if(M?.type==="HS_SEND_FORM_FIELD_VALUES"){const j=M.payload?.formFieldValues;if(j&&typeof j=="object"){const b=Lt(j);b&&(p=b)}}M?.type==="HS_SEND_FORM_SUBMISSION_SUCCESS"&&I(p)};S.addEventListener("message",D),S.start(),v.push(()=>S.removeEventListener("message",D))}};window.addEventListener("message",A),c.push(()=>{window.removeEventListener("message",A),v.forEach(y=>y())});let E;function O(y){if(!t.embedHtml)return;let k=Hi(t.embedHtml,x,o);k=Ui(k,o);const S=zi(x,o),D=ro(x);y.innerHTML=k;const V=Wi(y,I,w,o);let M,j,b;Zi(y).catch(()=>{}).then(()=>{e.status==="loading"&&(e.status="ready",W.style.display="none",x&&(Nt(y,x),Mi(x),b=ro(x),M=new MutationObserver(()=>Nt(y,x)),M.observe(y,{childList:!0,subtree:!0}),j=setTimeout(()=>M?.disconnect(),1e4)))}),E=()=>{S(),D(),V(),M?.disconnect(),j&&clearTimeout(j),b?.(),y.innerHTML=""}}const W=n.div({position:"absolute",inset:"0",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(255, 255, 255, 0.8)",zIndex:"10"});W.className="ago-embed-form__loading";const C=n.div({width:"24px",height:"24px",borderRadius:"50%",border:`2px solid ${n.EMBED_MUTED_TEXT}`,borderTopColor:"transparent",animation:"ago-spin 1s linear infinite"});C.setAttribute("role","status"),W.appendChild(C);function F(){if(s.replaceChildren(),e.status==="timeout"){const k=n.div({borderRadius:"8px",border:"1px solid #fef08a",backgroundColor:"#fefce8",padding:"16px",display:"flex",flexDirection:"column",gap:"12px"});k.className="ago-embed-form__timeout";const S=document.createElement("p");S.textContent=i.embedSubmitTimeout,n.css(S,{fontSize:"14px",lineHeight:"20px",color:"#854d0e",margin:"0"});const D=document.createElement("button");D.type="button",D.textContent=i.tryAgain,n.css(D,{alignSelf:"flex-start",fontSize:"14px",fontWeight:"500",color:"#854d0e",textDecoration:"underline",background:"none",border:"none",padding:"0",cursor:"pointer",minHeight:"44px",font:"inherit"}),D.addEventListener("click",()=>{h=!0,f=!1,d=void 0,e.status="ready",F()}),k.append(S,D),s.appendChild(k);return}if(e.status==="submitted"){s.appendChild(So({text:t.successMessage||i.embeddedFormSubmitted,urlLabel:i.findTicketHere}));return}if(t.description){const k=document.createElement("p");k.textContent=t.description,n.css(k,{fontSize:"14px",lineHeight:"20px",margin:"0"}),s.appendChild(k)}const y=n.div({position:"relative",borderRadius:"8px",border:`1px solid ${n.BORDER_COLOR}`,overflow:"hidden"});if(y.className="ago-embed-form__frame",t.embedHtml){W.style.display=e.status==="loading"?"flex":"none",y.appendChild(W);const k=n.div({width:"100%",minHeight:"200px"});k.className="ago-embed-form__host",y.appendChild(k),E?.(),O(k)}else{const k=n.div({padding:"24px",textAlign:"center",color:n.EMBED_MUTED_TEXT,fontSize:"14px"});k.textContent=i.noEmbedConfigured,y.appendChild(k)}s.appendChild(y)}return F(),{el:r,destroy:()=>{d&&clearTimeout(d),E?.(),c.forEach(y=>y())}}}function or(t){return t.type==="form"&&t.toolName==="ago_ticketing"}function ir(t){let e=null;for(const i of t)for(const o of i.toolCalls??[])o.type==="form"&&(e=o.id);return e}function rr(t){return t.some(e=>(e.toolCalls??[]).some(i=>{if(i.type!=="form")return!1;const o=i.data;return o?.success===!0&&!!o.ticket?.ticket_id}))}function lo(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 ar={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 sr(t,e="info",i){const o=ar[e],r=n.div({margin:"8px 0",padding:"12px 16px",border:`1px solid ${o.border}`,backgroundColor:o.bg,color:o.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"),i){const c=document.createElement("span");c.textContent=`${i}:`,n.css(c,{fontSize:"12px",fontWeight:"500",opacity:"0.7",flexShrink:"0"}),r.appendChild(c)}const s=document.createElement("span");return s.textContent=t,s.style.whiteSpace="pre-wrap",r.appendChild(s),r}function lr(t,e){const i=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"});i.className="ago-toolcall-form-placeholder";const o=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"}),o.appendChild(s)}if(t.message){const s=document.createElement("span");s.textContent=t.message,o.appendChild(s)}o.childElementCount>0&&i.appendChild(o);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 i.appendChild(r),i}var To={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"},pn={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 dr(){return{detailsOpen:!1,reasons:new Set,comment:"",reported:!1}}var cr={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 pr(t){const{state:e,labels:i,askWhy:o,onRate:r,onReport:s}=t,c=t.look==="embed",d=c?{idle:"#78716c",hover:"#1c1917",active:"#1c1917"}:{idle:n.MUTED_TEXT_COLOR,hover:n.TEXT_COLOR,active:n.ACCENT_COLOR},h=n.div(c?{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px",width:"100%"}:{marginTop:"6px",width:"100%",maxWidth:"85%"});h.className="ago-feedback";const f=n.div({display:"flex",alignItems:"center",gap:c?"8px":"2px"});f.className="ago-feedback__actions";const p=co("up",i.helpful,e.rating==="positive",d,c);p.addEventListener("click",()=>{e.rating="positive",e.detailsOpen=!1,w(),u(),r("positive")});const x=co("down",i.notHelpful,e.rating==="negative",d,c);x.addEventListener("click",()=>{e.rating="negative",r("negative"),o&&!e.reported&&(e.detailsOpen=!0),w(),u()}),f.append(p,x),c&&h.appendChild(n.div({flex:"1"})),h.appendChild(f);const I=n.div();I.className="ago-feedback__panel-slot",c&&(I.style.flexBasis="100%"),h.appendChild(I);function w(){un(p,e.rating==="positive",d),un(x,e.rating==="negative",d)}function u(){if(I.replaceChildren(),e.reported){I.appendChild(mr(i.thanks));return}e.detailsOpen&&I.appendChild(fr(e,i,async v=>await s(e.rating??"negative",v)?(e.reported=!0,e.detailsOpen=!1,u(),!0):!1))}return w(),u(),h}function co(t,e,i,o,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,cr),r?(s.style.margin="-14px",s.appendChild(t==="up"?n.thumbUpIcon({size:18}):n.thumbDownIcon({size:18}))):s.appendChild(ur(t)),un(s,i,o),s.addEventListener("mouseenter",()=>{s.getAttribute("aria-pressed")!=="true"&&(s.style.color=o.hover)}),s.addEventListener("mouseleave",()=>{s.getAttribute("aria-pressed")!=="true"&&(s.style.color=o.idle)}),s}function un(t,e,i){t.setAttribute("aria-pressed",e?"true":"false"),t.style.color=e?i.active:i.idle}function ur(t){const e="http://www.w3.org/2000/svg",i=document.createElementNS(e,"svg");i.setAttribute("width","16"),i.setAttribute("height","16"),i.setAttribute("viewBox","0 0 24 24"),i.setAttribute("fill","none"),i.setAttribute("aria-hidden","true");const o=document.createElementNS(e,"path");o.setAttribute("d","M7 22h9.3a2 2 0 0 0 2-1.7l1.4-9A2 2 0 0 0 17.7 9H14V5a3 3 0 0 0-3-3l-4 10z"),o.setAttribute("stroke","currentColor"),o.setAttribute("stroke-width","1.8"),o.setAttribute("stroke-linejoin","round");const 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"),i.append(o,r),t==="down"&&(i.style.transform="rotate(180deg)"),i}function fr(t,e,i){const o=n.div({marginTop:"8px",padding:"12px",border:`1px solid ${n.BORDER_COLOR}`,borderRadius:n.MESSAGE_RADIUS,backgroundColor:n.PANEL_BACKGROUND});o.className="ago-feedback__panel",o.setAttribute("role","group"),o.setAttribute("aria-label",e.whatWentWrong);const r=n.div({fontSize:"13px",fontWeight:"500",color:n.TEXT_COLOR,marginBottom:"8px"});r.textContent=e.whatWentWrong,o.appendChild(r);const s=n.div({display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"8px"});s.className="ago-feedback__reasons";for(const f of _e.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 x=()=>{const I=t.reasons.has(f);p.setAttribute("aria-pressed",I?"true":"false"),p.style.borderColor=I?n.ACCENT_COLOR:n.BORDER_COLOR,p.style.color=I?n.ACCENT_COLOR:n.TEXT_COLOR};p.addEventListener("click",()=>{t.reasons.has(f)?t.reasons.delete(f):t.reasons.add(f),x(),h()}),x(),s.appendChild(p)}o.appendChild(s);const c=document.createElement("textarea");c.className="ago-feedback__comment",c.rows=2,c.placeholder=e.commentPlaceholder,c.value=t.comment,c.setAttribute("aria-label",e.commentPlaceholder),n.css(c,{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"}),c.addEventListener("input",()=>{t.comment=c.value,h()}),o.appendChild(c);const d=document.createElement("button");return d.type="button",d.className="ago-feedback__send",d.textContent=e.send,n.css(d,{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"}),d.addEventListener("click",()=>{d.disabled||(d.disabled=!0,i({reasons:[...t.reasons],comment:t.comment.trim()}).then(f=>{f||h()}))}),o.appendChild(d),h(),o;function h(){const f=t.reasons.size>0||t.comment.trim().length>0;d.disabled=!f,d.style.opacity=f?"1":"0.5",d.style.cursor=f?"pointer":"default"}}function mr(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 gr(t){const e=n.div({display:"flex",flexDirection:"column",flex:"1",width:"100%",overflow:"auto",minHeight:"0"});e.className="ago-chat-widget__chat";const i=n.div({position:"relative",isolation:"isolate",width:"100%",maxWidth:"768px",margin:"0 auto",padding:"0 8px 8px",boxSizing:"border-box",flexShrink:"0"});i.className="ago-chat-widget__dock";const o=n.div({width:"100%"});return o.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"}),i.append(t.jumpBtn,o),e.append(t.messagesWrap,i),{el:e,composerSlot:o}}var hr=7200*1e3;function fn(t){const e=t.lastMessageDate instanceof Date?t.lastMessageDate.getTime():new Date(t.lastMessageDate).getTime();return Number.isFinite(e)?e:Number.NEGATIVE_INFINITY}function Ro(t){return[...t].sort((e,i)=>fn(i)-fn(e))}function br(t,e=Date.now(),i=hr){const o=Ro(t)[0];if(!o)return null;const r=fn(o);return Number.isFinite(r)&&e-r<i?o:null}function xr(t){const e=n.div({position:"relative",display:"flex",flexDirection:"column",height:"100%",flex:"1",minHeight:"0"});e.className="ago-chat-widget__history";const i=n.div({display:"flex",flex:"1",minHeight:"0"});i.className="ago-chat-widget__history-body";const o=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)`});o.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(n.addCommentIcon({size:16}),s),r.addEventListener("click",t.onNew),o.appendChild(r),e.append(i,o);const c=p=>{t.customFont?p.style.opacity="0.7":p.style.color=n.EMBED_MUTED_TEXT};function d(){const p=n.div({display:"flex",flex:"1",alignItems:"center",justifyContent:"center",paddingBottom:"112px"});p.className="ago-chat-widget__history-loading";const x=n.div({width:"32px",height:"32px",borderRadius:"50%",borderBottom:`2px solid ${n.BRAND_COLOR}`,animation:"ago-spin 1s linear infinite"});x.setAttribute("role","status"),p.appendChild(x),i.replaceChildren(p)}function h(){const p=n.div({display:"flex",flex:"1",flexDirection:"column",alignItems:"center",justifyContent:"center"});p.className="ago-chat-widget__history-empty",c(p);const x=n.conversationsIcon({size:36});x.style.marginBottom="8px";const I=document.createElement("p");I.textContent=t.labels.noHistory,n.css(I,{fontSize:"14px",lineHeight:"20px",margin:"0"}),p.append(x,I),i.replaceChildren(p)}function f(p){const x=n.div({flex:"1",overflowY:"auto",padding:"0 16px 112px",minHeight:"0"});x.className="ago-chat-widget__history-list";const I=Ro(p);I.forEach((w,u)=>{const v=document.createElement("button");if(v.type="button",v.className="ago-chat-widget__thread",v.dataset.agoConversationId=w.id,n.css(v,{display:"flex",alignItems:"center",gap:"8px",padding:"17px 0",width:"100%",textAlign:"left",backgroundColor:"transparent",border:"none",borderBottom:u===I.length-1?"none":`1px solid ${n.EMBED_BORDER}`,cursor:"pointer",font:"inherit",color:"inherit"}),t.hoverBackground){const C=t.hoverBackground;v.addEventListener("mouseenter",()=>{v.style.backgroundColor=C}),v.addEventListener("mouseleave",()=>{v.style.backgroundColor="transparent"})}const A=n.div({flex:"1",minWidth:"0",display:"flex",flexDirection:"column",gap:"4px"}),E=document.createElement("h3");E.textContent=w.title||t.labels.newConversation,n.css(E,{margin:"0",fontSize:"14px",lineHeight:"20px",fontWeight:"400",color:t.customFont?"inherit":n.BRAND_COLOR,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"});const O=document.createElement("span");O.textContent=mi(w.lastMessageDate,Date.now(),t.labels.timeAgo),n.css(O,{fontSize:"12px",lineHeight:"16px"}),c(O),A.append(E,O);const W=n.chevronRightIcon({size:16});t.customFont?W.style.opacity="0.6":W.style.color=n.BRAND_COLOR,v.append(A,W),v.addEventListener("click",()=>t.onSelect(w)),x.appendChild(v)}),i.replaceChildren(x)}return{el:e,render:({threads:p,loading:x})=>{x?d():p.length===0?h():f(p)}}}function yr(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 i=n.div({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"space-between",height:"100%",width:"100%",minHeight:"0"}),o=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",o.appendChild(r);const s=n.div({fontSize:"14px",lineHeight:"20px",textAlign:"center",maxWidth:"512px"});s.className="ago-chat-widget__home-subtitle",o.appendChild(s);const c=C=>{r.replaceChildren();for(const F of C.split(`
|
|
7
|
+
`)){const y=n.div({});y.textContent=F,r.appendChild(y)}},d=C=>{s.replaceChildren(),s.style.display=C?"":"none",C&&s.appendChild(Me(C))};c(t.title),d(t.subtitle);const h=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 x=null;const I=C=>{f.replaceChildren(),p.length=0;for(const F of C)w(F);C.length>0?f.parentNode||h.insertBefore(f,u):f.remove()};function w(C){const F=document.createElement("button");F.type="button",F.className="ago-chat-widget__starter",n.css(F,{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 y=n.div({display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"}),k=n.div({minWidth:"0",flex:"1",fontSize:"14px",lineHeight:"1.375",display:"-webkit-box",overflow:"hidden"});k.style.setProperty("-webkit-line-clamp","2"),k.style.setProperty("-webkit-box-orient","vertical"),k.textContent=C.label;const S=n.arrowUpRightIcon({size:16});n.css(S,{marginTop:"2px",color:"rgba(113, 113, 122, 0.5)",transition:"all 0.15s"}),y.append(k,S),F.appendChild(y),F.addEventListener("mouseenter",()=>{F.disabled||(F.style.borderColor="#e4e4e7",F.style.boxShadow=n.SHADOW_MD,F.style.transform="translateY(-2px)",S.style.color=n.TEXT_COLOR,S.style.transform="translate(2px, -2px)")}),F.addEventListener("mouseleave",()=>{F.style.borderColor="rgba(228, 228, 231, 0.6)",F.style.boxShadow=n.SHADOW_SM,F.style.transform="",S.style.color="rgba(113, 113, 122, 0.5)",S.style.transform=""}),F.addEventListener("click",()=>{x||t.onStarter(C)}),p.push({starter:C,btn:F}),f.appendChild(F)}const u=n.div({width:"100%"});u.className="ago-chat-widget__home-composer",h.appendChild(u),I(t.starters);const v=n.div({flex:"1"});i.append(o,h,v),e.appendChild(i);const A=t.twoColumnsFrom??640,E=()=>{const C=typeof window<"u"&&window.innerWidth>=A;f.style.gridTemplateColumns=C?"1fr 1fr":"1fr"};E();const O=C=>{x=C;for(const{starter:F,btn:y}of p){const k=F===C;y.disabled=!!C,y.style.opacity=C?"0.6":"",y.style.cursor=C?"not-allowed":"pointer";const S=y.querySelector("svg");S&&(S.style.animation=k?"ago-skeleton-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite":"")}};return{el:e,composerSlot:u,syncColumns:E,setPending:O,setContent:C=>{C.title!==void 0&&c(C.title),C.subtitle!==void 0&&d(C.subtitle),C.starters&&(I(C.starters),E(),x&&O(x))}}}function Cr(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 i=document.createElement("button");i.type="button",i.className="ago-chat-widget-teaser__close",i.setAttribute("aria-label","Dismiss"),i.textContent="X",n.css(i,{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 o=document.createElement("p");o.className="ago-chat-widget-teaser__text",n.css(o,{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"}),o.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"}),o.appendChild(r);const s=()=>{e.remove()};return i.addEventListener("click",c=>{c.stopPropagation(),s(),t.onDismiss?.()},{once:!0}),e.addEventListener("click",c=>{c.target!==i&&t.onOpen()}),e.append(i,o),{el:e,remove:s}}var po="Form submitted.";function vr(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 i=e.result;if(typeof i=="string"&&i)return i;if(i&&typeof i=="object"){const o=i.message;if(typeof o=="string"&&o)return o}return null}var Er=0,wr="Hello, how can I help you today?",kr=6,_r=800,Sr=/^(?:\d+(?:\.\d+)?(?:px|rem|em|vw|vmin|vmax|%)|(?:min|max|clamp|calc)\([^;{}]+\))$/i;function Tr(t){const e=typeof t=="number"?`${t}px`:String(t).trim();return!Sr.test(e)||typeof CSS<"u"&&typeof CSS.supports=="function"&&!CSS.supports("width",`min(max(400px, ${e}), 100% - 40px)`)?null:e}function Rr(t){const e=typeof t=="string"?document.querySelector(t):t;if(!e)throw new Error(`mountChatWidget: target "${String(t)}" not found.`);return e}function Ar(t,e){const i=e.placement??"inline",o=i==="bubble",{welcomeMessage:r="Hello! How can I help you today?",allowFiles:s=!1,allowStop:c=!0,autoScroll:d=!0,height:h=500,defaultOpen:f=!1,logoUrl:p,showAgentName:x=!1,agentBubble:I=!1,bubbleStyle:w="default",showHeader:u=!0,forms:v,formSubmittedMessage:A=po,onFollowUpClick:E,onMessageSent:O,onMessageReceived:W,onFormSubmitted:C,onFormError:F,onOpen:y,onClose:k,icon:S,subtitle:D,conversationStarters:V=[],autoResume:M=!0,hideFooter:j=!1,loadHomeConfig:b=!1}=e,R=e.title??(o?"AGO Chatbot":"Chat"),z=e.width??(o?550:400),J=e.loadThreads??o,Y=e.feedback??o,m=gi(e.labels),B=e.placeholder??(o?m.askQuestion:"Type a message..."),G=e.prompt===void 0?wr:e.prompt,P=o?{...n.colorsToTheme(e.colors),...e.theme}:e.theme,ee=typeof r=="string"?{message:r,mode:"static"}:r,re=ee.message,be=ee.mode??"static",Ao="speed"in ee&&ee.speed||45,gn="followUpReplies"in ee&&ee.followUpReplies||void 0;if(!e.client&&!e.config?.baseUrl)throw new si.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const $=e.client??new _e.AgoClient(e.config),It=Rr(t),ft=i==="left"||i==="right",ae=ft||o,Oo=ae&&(e.launcher??!0);let te=ae?f:!0,Dt=!1;const Lo=e.mobile?.breakpoint??(o?450:768),Bt=e.mobile?.trigger??"tap",hn=typeof window<"u"&&!!window.matchMedia,ne=hn?window.matchMedia(`(max-width: ${Lo}px), (max-height: 500px) and (orientation: landscape)`):void 0,No=hn?window.matchMedia("(prefers-reduced-motion: reduce)"):void 0,Fo=!!ne,Qe=!ae&&!!ne,Je=Symbol("ago-scroll-lock");let Z=!1;const Ht=e.persistConversation??(o?!0:void 0),$e=Ht?li.createConversationSession(Ht===!0?{}:Ht):void 0;let K=e.conversationId??$e?.getLastActiveThread()??void 0,N=[],mt=[],se=!1,xe=null,Se;const Ze=[];function Io(a){if(typeof A=="function"){const g=A(a);if(typeof g=="string"&&g)return g}const l=vr(a);return l||(typeof A=="string"?A:po)}const ye=[],T=n.div({display:"flex",flexDirection:"column",height:ft?"100%":typeof h=="number"?`${h}px`:h,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"});T.className="ago-chat-widget",n.applyTheme(T,P),o&&(n.css(T,{height:"100%",width:"100%",border:"none",borderRadius:"0",boxShadow:"none",backgroundColor:n.EMBED_BACKGROUND,color:n.TEXT_COLOR,fontSize:"14px",lineHeight:"24px"}),P?.headerText||T.style.setProperty("--ago-header-text-color",n.readableTextColor(P?.headerBg??P?.brand??"#03182f")));let ce;if(u&&!o){if(ce=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"}),ce.className="ago-chat-widget__header",p){const l=document.createElement("img");l.src=p,l.alt="Logo",n.css(l,{height:"24px",width:"auto"}),ce.appendChild(l)}const a=document.createElement("h3");if(a.textContent=R,n.css(a,{margin:"0",fontSize:"15px",fontWeight:"600"}),ce.appendChild(a),ft){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()),ce.appendChild(l)}}const Q=n.div({flex:"1",overflow:"auto",overflowAnchor:d?"auto":"none",overscrollBehavior:"contain",padding:"16px",backgroundColor:n.MESSAGES_BACKGROUND});Q.className="ago-chat-widget__messages",Q.setAttribute("role","log"),Q.setAttribute("aria-live","polite"),Q.setAttribute("aria-relevant","additions text"),Q.setAttribute("aria-atomic","false");const pe=o?n.div({maxWidth:"768px",margin:"0 auto",padding:"0 8px",boxSizing:"border-box"}):Q;o&&(n.css(Q,{padding:"16px 0",backgroundColor:"transparent"}),pe.className="ago-chat-widget__list",Q.appendChild(pe));const Do=48;let Te=!0,zt=0;function Mt(a){zt++;try{a()}finally{const l=()=>{zt--};typeof queueMicrotask=="function"?queueMicrotask(l):l()}}function bn(){return Q.scrollHeight-Q.scrollTop-Q.clientHeight<=Do}const oe=document.createElement("button");oe.type="button",oe.className="ago-chat-widget__jump",oe.setAttribute("aria-label","Jump to latest message"),oe.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(oe,{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"}),o&&(oe.setAttribute("aria-label",m.scrollToBottom),oe.replaceChildren(n.arrowDownwardIcon({size:20})),n.css(oe,{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"}));function xn(){Te=!0,Mt(()=>{Q.scrollTop=Q.scrollHeight}),$t()}oe.addEventListener("click",xn);function $t(){const a=d?Te:bn();if(o){oe.style.opacity=a?"0":"1",oe.style.pointerEvents=a?"none":"auto";return}oe.style.display=a?"none":"flex"}function Ut(){d&&Te&&Mt(()=>{Q.scrollTop=Q.scrollHeight}),$t()}function yn(a){Mt(()=>{const l=Q.scrollTop;a(),(!d||!Te)&&(Q.scrollTop=l)}),Ut()}Q.addEventListener("scroll",()=>{zt>0||(Te=bn(),$t())});const Wt=n.div({position:"relative",flex:"1",display:"flex",minHeight:"0"});Wt.append(Q,oe);const{inputRow:Ce,setDisabled:Bo,focus:gt,restoreDraft:Ho,setPlaceholder:Cn,getValueAndClear:zo,setSpeechToTextEnabled:Mo,cancelRecording:et,destroy:$o}=ci({placeholder:B,allowFiles:s,transcribeAudio:e.speechToText?(a,l)=>$.transcribeAudio(a,l):void 0,speechToTextLabels:typeof e.speechToText=="object"?e.speechToText.labels:void 0,onSend:(a,l)=>{Ve(a,l)},onStop:c?()=>{wt()}:void 0,look:o?"embed":"classic",labels:o?{attachFiles:m.attachFiles,dismiss:m.dismiss,tooManyFiles:m.tooManyFiles,invalidFileType:m.invalidFileType,fileTooLarge:m.fileTooLarge}:void 0});n.ensureKeyframes(),e.speechToText&&$.getConfig().then(a=>{Z||Mo(a.permissions.some(l=>l.speechToTextEnabled))}).catch(()=>{}),o||T.append(...ce?[ce]:[],Wt,Ce);let tt=T,U,le,Pt;const nt=i==="left"?"left":"right";let jt,ht,ve,Ue,bt,ot,ue,Ne,We,Ee="home",xt="home",Pe=!1,yt=J,it=!1,rt=!1,Gt;if(o){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,P),!P?.panelWidth){const l=Tr(z);l?U.style.setProperty("--ago-panel-width",l):console.warn(`[AGO] mountChatWidget width "${String(z)}" is not a valid CSS length, ignoring. Expected e.g. 700 or "45rem". Falling back to 550px.`)}u&&(jt=ui({title:R,labels:m,onBack:()=>Le(xt,{byUser:!0}),onNewChat:()=>kt(),onClose:()=>qe()}),T.appendChild(jt.el)),ot=n.div({flex:"1",display:"flex",flexDirection:"column",minHeight:"0",overflow:"hidden"}),ot.className="ago-chat-widget__main",T.appendChild(ot),j||(ht=pi({labels:m,onNavigate:l=>Le(l,{byUser:!0})}),T.appendChild(ht.el)),ve=yr({title:R,subtitle:D,starters:V,onStarter:l=>{ve?.setPending(l),Ve(l.message??l.label,void 0,{agentId:l.agentId}).finally(()=>ve?.setPending(null))}});const a=e.colors?.background;Ue=xr({labels:m,onSelect:l=>{Pe=!0,xt="history",dt(l.id)},onNew:()=>kt(),hoverBackground:a&&n.isValidHexColor(a)?n.lightenColor(a,10):void 0,customFont:!!e.colors?.font}),bt=gr({messagesWrap:Wt,jumpBtn:oe}),U.appendChild(T),tt=U}ft&&(U=n.div({position:"fixed",top:"0",bottom:"0",[nt]:"0",width:typeof z=="number"?`${z}px`:z,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(T,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[nt==="left"?"borderRight":"borderLeft"]:`1px solid ${n.BORDER_COLOR}`}),U.appendChild(T),tt=U),Oo&&(Pt=Si({look:o?"bubble":"classic",edge:nt,title:R,icon:o?S:p,onClick:()=>o?Xn():Tt()}),le=Pt.el);const at=Qe?`ago-vt-${++Er}`:"",vn=52;let we=!1,Re=0,je=0,fe,st,Ae;const Ct={height:T.style.height,border:T.style.border,borderRadius:T.style.borderRadius,boxShadow:T.style.boxShadow};It.appendChild(tt),le&&It.appendChild(le),St(),o&&(G!==!1&&!te&&(Ne=setTimeout(Jo,1e3)),document.addEventListener("keydown",jn),window.addEventListener("resize",Gn)),Qe&&(fe=ii(),T.insertBefore(fe,T.firstChild),st=document.createElement("style"),st.id=at,st.textContent=`::view-transition-group(${at}),::view-transition-group(${at}-bar){animation-duration:0.3s;animation-timing-function:cubic-bezier(0.4,0,0.2,1)}`,document.head.appendChild(st),(Bt==="focus"||Bt==="tap")&&(T.addEventListener("pointerdown",a=>{if(we||!ne?.matches)return;const l=Ce.contains(a.target);if(Bt==="tap"){if((a.target instanceof Element?a.target:null)?.closest("button,a[href],[role='button']"))return}else if(!l)return;l&&a.preventDefault(),pt()},!0),T.addEventListener("focusin",a=>{ne?.matches&&Ce.contains(a.target)&&pt()}))),Fo&&document.addEventListener("keydown",Kn),ne&&ne.addEventListener("change",Yn);const En=E!==!1,wn=E===!1?void 0:E??(a=>{Qe&&ne?.matches&&!we?pt().then(()=>Ve(a)):Ve(a)}),Ge=Y===!0?{}:Y||null,Uo={...pn,...Ge?.labels,reasons:{...pn.reasons,...Ge?.labels?.reasons}},vt=new Map;function kn(a){if(!Ge||!a.id||!a.conversationId||a.status!=="DONE"||!a.content)return null;let l=vt.get(a.id);l||(l=dr(),vt.set(a.id,l));const g=async(_,H)=>{try{return await $.submitFeedback(a.id,_,H),Ge.onSubmit?.({messageId:a.id,rating:_,reasons:H?.reasons??[],comment:H?.comment||void 0}),!0}catch(L){return Ge.onError?.(L instanceof Error?L:new Error(String(L))),!1}};return pr({state:l,labels:Uo,askWhy:Ge.askWhy??!o,onRate:_=>{g(_)},onReport:(_,H)=>g(_,H),look:o?"embed":"classic"})}const me=e.toolCallForm??{},ke={...To,...me.labels},_n=$.getUserIdentity(),Vt=me.userEmail??_n.email,Sn=!Vt&&!_n.hasJwt;let Fe=null,Tn=!1,Rn,qt=!1;const lt=new Map,Et=new Set;function Wo(){Rn||(Rn=$.getConfig().then(a=>{const l=a.permissions[0];Fe=l?.ticketForm??null,qt=!!l?.fileAttachmentsEnabled}).catch(()=>{Fe=null}).then(()=>{if(Tn=!0,!Z)for(const a of lt.values())a.kind==="ticket"&&(Fe&&qi(a.state,a.call.ticket,Fe),a.view.rebuild({ticketForm:Fe,configLoading:!1,allowFiles:s||qt}))}))}function Xt(){for(const a of lt.values())a.kind==="embed"&&a.view.destroy();lt.clear(),Et.clear()}function Po(a){for(const l of N){const g=l.toolCalls?.find(_=>_.id===a);if(g)return g}}function jo(a){const l=lt.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(Yi(ke.notAllowed)),g={kind:"static",el:_}}else if(a.mode==="embed"){const _={status:lo(a)?"submitted":"loading"};g={kind:"embed",state:_,view:nr({state:_,embedHtml:a.embedHtml,description:a.embedDescription,ticket:a.ticket,email:Vt,labels:ke,message:a.message,successMessage:me.successMessage,onSubmitted:H=>{Et.add(a.id),$.submitToolCallForm(a.id,{success:!0,source:"embed",thread_id:K,captured_form_data:H}).then(L=>{const q=L.ticket??L.result?.ticket;me.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(L=>{me.onError?.(L instanceof Error?L:new Error(String(L)))}).finally(()=>{Z||X()})}})}}else{Wo();const _=_o(a.ticket,Fe,Vt??""),H=lo(a);H&&(_.submitted=H),g={kind:"ticket",state:_,view:Qi({state:_,ticketForm:Fe,configLoading:!Tn,labels:ke,message:a.message,requireEmail:Sn,allowFiles:s||qt,successMessage:me.successMessage,successUrlLabel:me.successUrlLabel,createTicket:L=>$.createTicket({subject:L.subject,body:L.body,priority:L.priority,typology:L.typology,conversationId:K,email:L.email,customFields:L.customFields,files:L.files,ticketFormId:L.ticketFormId}),onCreated:(L,q)=>{Et.add(a.id);const ge=Object.entries(q.customFields).map(([Ie,ai])=>({id:Ie,value:ai}));$.submitToolCallForm(a.id,{success:!0,ticket_id:L.id,ticket_url:L.url,subject:q.ticket.subject,typology:q.ticket.typology,priority:q.ticket.priority,body:q.ticket.body,tag:q.ticket.tag,custom_fields:ge,created_at:new Date().toISOString()}).catch(Ie=>{me.onError?.(Ie instanceof Error?Ie:new Error(String(Ie)))}).finally(()=>{me.onSubmitted?.({toolCallId:a.id,toolName:a.toolName,mode:"form",ticket:{id:L.id,url:L.url},values:{...q.ticket,custom_fields:q.customFields,email:Sn?q.email:void 0}}),Z||X()})},onError:me.onError}),call:a}}return lt.set(a.id,g),g}function An(a){if(a.type!=="form"||a.displayMode==="collapsible")return null;const l=ir(N);if(l&&l!==a.id){const _=Po(l),H=!!_?.askToTalkToHuman&&_.allowedToCreateTicket===!1;return sr(H?ke.contactFormRejected:ke.contactFormCreated,H?"warning":"info")}if(!or(a))return lr(a,ke);const g=jo(a);return g.kind==="static"?g.el:g.view.el}let Oe;function Go(){const a=N.some(_=>_.toolCalls?.some(H=>H.type==="form")),l=Et.size>0||rr(N);if(!a&&!l){Ce.style.display="",Oe?.remove();return}Oe||(Oe=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}),Oe.className="ago-chat-blocked"),Oe.replaceChildren();const g=document.createElement("p");if(g.textContent=l?ke.ticketCreatedBlocked:ke.formPending,n.css(g,{color:n.MUTED_TEXT_COLOR,lineHeight:"1.625",fontSize:"16px",margin:"0",whiteSpace:"pre-line"}),Oe.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(n.addCommentIcon({size:18}));const H=document.createElement("span");H.textContent=ke.newConversation,_.appendChild(H),_.addEventListener("click",()=>{kt(),me.onNewConversation?.()}),Oe.appendChild(_)}Ce.style.display="none",Ce.parentElement?.insertBefore(Oe,Ce)}function On(a){const l=N[a];return o?Ii(l,{isLast:a===N.length-1,followUpEnabled:En,followUpHandler:wn,agentRowTinted:!!P?.agentBubbleBg,agentRowTextTinted:!!P?.agentBubbleText,labels:m,actionsRow:kn(l),renderToolCall:An}):Ei(l,{...Vo(a),renderToolCall:An})}function Vo(a){const l=N.length-1;return{isLast:a===l,isLastOfBlock:a===l||N[a+1].role!==N[a].role,bubbleStyle:w,showAgentName:x,agentBubble:I,followUpEnabled:En,followUpHandler:wn,isMobile:!!ne?.matches,feedbackRow:kn(N[a])}}function qo(){if(xe||Ze.length>0)return!1;const a=N.length-1,l=N[a];if(!l||l.role!=="assistant")return!1;const g=mt[a];if(!g||g.parentNode!==pe)return!1;const _=On(a),H=document.activeElement,L=H instanceof HTMLElement&&g.contains(H)?H:null;return yn(()=>pe.replaceChild(_,g)),L&&_.contains(L)&&L.focus({preventScroll:!0}),mt[a]=_,!0}function X(){yn(Xo);const a=N[N.length-1],l=se&&a?.role==="assistant"&&(a.status==="IN_PROGRESS"||a.status==="WAITING_CLIENT");Q.setAttribute("aria-busy",l?"true":"false"),Bo(l),Go()}function Xo(){if(pe.replaceChildren(),mt=[],N.length===0){if(o){if(it){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),pe.appendChild(a)}}else if(be==="static"){const a=n.div({textAlign:"center",color:n.MUTED_TEXT_COLOR,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});a.appendChild(Me(re)),pe.appendChild(a)}}else N.forEach((a,l)=>{const g=On(l);mt[l]=g,pe.appendChild(g)});for(const a of Ze)pe.appendChild(wi(a));if(xe){if(o){pe.appendChild(Oi(m.errorTitle,xe));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=xe,pe.appendChild(a)}}function Kt(){for(let a=N.length-1;a>=0;a--){const l=N[a];if(l.role==="assistant"&&(l.status==="IN_PROGRESS"||l.status==="WAITING_CLIENT"))return l}}const Ln=a=>{K||(K=a.conversationId)},Nn=a=>{const l=Kt();l&&(l.content+=a.content,qo()||X())},Fn=a=>{const l=N.findIndex(g=>g.id===a.id||g.role==="assistant"&&g.status==="IN_PROGRESS");l>=0?N[l]=a:N.push(a),X(),ct()||gt()},In=a=>{const l=N.findIndex(g=>g.id===a.id||g.role==="assistant"&&g.status==="IN_PROGRESS");l>=0?N[l]=a:N.push(a),se=!1,X(),a.status==="DONE"&&W?.({id:a.id,content:a.content})},Dn=()=>{const a=Kt();a&&(a.content?a.status="CANCELED":N=N.filter(l=>l!==a)),se=!1,X()},Bn=a=>{xe=a.error,se=!1,N=N.filter(l=>!l.id.startsWith("temp-")),X()};function Ko(a){const l={id:`ago-intro-${Date.now()}`,conversationId:"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};N.push(l),X();const g=a.match(/\S+\s*/g)??[a];let _=0;Se=setInterval(()=>{if(_>=g.length){clearInterval(Se),Se=void 0,l.status="DONE",gn&&(l.followUpReplies=gn),X();return}l.content+=g[_],_++,X()},Ao)}const Hn=a=>{const l=ye.find(g=>g.id===a.conversationId);l&&(l.title=a.title),o&&Ee==="history"&&Ue?.render({threads:ye,loading:yt})},zn=a=>{if(a.type!=="form")return;const l=Kt()??[...N].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,X()};$.on("message:start",Ln),$.on("message:chunk",Nn),$.on("message:answer-complete",Fn),$.on("message:complete",In),$.on("message:stopped",Dn),$.on("message:error",Bn),$.on("conversation:title",Hn),$.on("toolCall:received",zn);const Mn=a=>C?.(a),$n=a=>F?.(a);C&&$.on("form:submitted",Mn),F&&$.on("form:error",$n);const Yt=[];let Un=!1;const Wn=a=>{if(Un)return;Yt.push(a.install($));let l=a.store.get().submitted;const g=a.store.subscribe(_=>{_.submitted&&!l&&(Ze.push(Io(_.submitResult)),X()),l=_.submitted});Yt.push(g)};for(const a of v??[])a.schema!=null?Wn(to.createFormCollector(a)):to.loadFormCollector($,a).then(l=>Wn(l)).catch(()=>{});async function Ve(a,l,g){const _=a.trim();if(!_||se)return;if(o&&Ee!=="chat"&&(xt="home",Le("chat",{byUser:!0})),O?.(_),se=!0,xe=null,Te=!0,Se){clearInterval(Se),Se=void 0;const L=N.find(q=>q.id.startsWith("ago-intro-"));L&&!L.content?N=N.filter(q=>q!==L):L&&(L.status="DONE")}const H=Date.now();N.push({id:`temp-user-${H}`,conversationId:K||"",content:_,role:"user",status:"DONE",attachments:l&&l.length>0?_e.attachmentsFromFiles(l):void 0,createdAt:new Date}),N.push({id:`temp-assistant-${H}`,conversationId:K||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),X(),d||xn();try{const L=await $.sendMessage(_,{conversationId:K,files:l,...g?.agentId?{agentId:g.agentId}:{}});L.conversationId&&(K||(K=L.conversationId),$e?.setActiveThread(L.conversationId,L.createdAt));const q=N.find(ge=>ge.id===`temp-user-${H}`);if(q&&(q.id=`user-${H}`,q.conversationId=L.conversationId),L.id&&!N.some(ge=>ge.id===L.id)){const ge=N.findIndex(Ie=>Ie.id===`temp-assistant-${H}`);ge>=0?N[ge]=L:N.push(L)}N=N.filter(ge=>!ge.id.startsWith("temp-")),L.status!=="WAITING_CLIENT"&&(se=!1),X(),J&&Qt()}catch(L){xe=L instanceof Error?L.message:"Failed to send message",se=!1,N=N.filter(q=>!q.id.startsWith("temp-")),Ho(_,l),X()}}async function wt(){se&&await $.stop()}async function Qt(){try{const{data:a}=await $.getConversations();ye.splice(0,ye.length,...a)}catch{}return yt=!1,o&&!Z&&(Ee==="history"&&Ue?.render({threads:ye,loading:!1}),Yo()),ye}async function Pn(a){try{const l=await $.getConversation(a);if(K!==a)return;const g=l?.messages??[];it=!1,g.length>0&&N.length===0?(N=g,X()):o&&X(),o&&$e?.setActiveThread(a,l.lastMessageDate)}catch{if(K!==a)return;it=!1,N.length===0&&($e?.clear(),K=void 0,o&&(Ee==="chat"&&Le("home"),X()))}}function Le(a,l){if(!o||!ot||!ve||!bt||!Ue)return;l?.byUser&&(Pe=!0),Ee!==a&&et(),Ee=a,a==="home"?(ve.composerSlot.appendChild(Ce),Cn(B)):a==="chat"&&(bt.composerSlot.appendChild(Ce),Cn(""));const g=a==="home"?ve.el:a==="chat"?bt.el:Ue.el;ot.replaceChildren(g),a==="history"&&Ue.render({threads:ye,loading:yt}),a==="chat"&&(Te=!0,Ut()),jt?.update({screen:a}),ht?.setActive(a),ht?.setVisible(a!=="chat")}async function dt(a){o&&(et(),se&&await wt(),K=a,N=[],xe=null,Ze.length=0,vt.clear(),Xt(),it=!0,Le("chat"),X(),await Pn(a))}function kt(){se&&wt(),K=void 0,N=[],xe=null,Ze.length=0,vt.clear(),Xt(),it=!1,$e?.clear(),zo(),ve?.setPending(null),xt="home",o&&Le("home",{byUser:!0}),X()}function Yo(){if(!o||rt)return;if(rt=!0,!M||Pe||Ee!=="home"||N.length>0||K){_t();return}const a=br(ye);a&&dt(a.id),_t()}async function Qo(){let a;try{a=(await $.getConfig()).permissions[0]?.homePage}catch{return}Z||!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&&(Gt=a.widgetStarter,_t()))}function _t(){const a=Gt;!a||Z||te&&(yt&&!rt||(Gt=void 0,!(Pe||K||N.length>0||se||Ee!=="home")&&Ve(a.message,void 0,{agentId:a.agentId})))}function Jo(){Ne=void 0,!(Z||te||G===!1||ue)&&(ue=Cr({text:G,edge:nt,onOpen:()=>Tt(),onDismiss:()=>{ue=void 0}}),It.appendChild(ue.el),Jt())}function Jt(){if(!o||!U||!le||ct()||!le.offsetHeight)return;const a=getComputedStyle(le),l=parseFloat(a.bottom),g=parseFloat(a.right);if(Number.isNaN(l)||Number.isNaN(g))return;const _=Math.round(l+le.offsetHeight)+kr,H=Math.round(g),L=[U];ue&&L.push(ue.el);for(const q of L)q.style.setProperty("bottom",`${_}px`,"important"),q.style.setProperty("right",`${H}px`,"important");U.style.setProperty("top",`max(40px, calc(100% - ${_+_r}px))`,"important"),U.style.setProperty("--ago-panel-max",`calc(100% - ${H+20}px)`)}function jn(a){a.key!=="Escape"||!te||a.defaultPrevented||a.target instanceof HTMLInputElement||a.target instanceof HTMLTextAreaElement||Zt()||qe()}function Gn(){We&&clearTimeout(We),We=setTimeout(()=>{We=void 0,!Z&&(Jt(),ve?.syncColumns())},150)}o?(Le("home"),X(),b&&Qo(),e.conversationId?(Pe=!0,rt=!0,dt(e.conversationId)):K&&M?(rt=!0,dt(K)):K=void 0):(X(),Qe&&ne?.matches||gt(),K?Pn(K):be==="streaming"&&Ko(re)),J&&Qt();const Vn={client:$,element:tt,sendMessage:Ve,stop:wt,...ae||Qe?{open:Zo,close:ei,toggle:ti}:{},newConversation:kt,...o?{showScreen:a=>Le(a,{byUser:!0}),openConversation:a=>(Pe=!0,dt(a))}:{},session:$e,threads:ye,refreshThreads:Qt,destroy(){Z||(Z=!0,$o(),Se&&clearInterval(Se),Ne&&clearTimeout(Ne),We&&clearTimeout(We),ue?.remove(),$.off("message:start",Ln),$.off("message:chunk",Nn),$.off("message:answer-complete",Fn),$.off("message:complete",In),$.off("message:stopped",Dn),$.off("message:error",Bn),$.off("conversation:title",Hn),$.off("toolCall:received",zn),Xt(),C&&$.off("form:submitted",Mn),F&&$.off("form:error",$n),Un=!0,Yt.forEach(a=>a()),tt.remove(),le?.remove(),fe?.remove(),document.removeEventListener("keydown",jn),window.removeEventListener("resize",Gn),st?.remove(),Ae?.remove(),ne?.removeEventListener("change",Yn),document.removeEventListener("keydown",Kn),nn(),Dt=!1,n.unlockBackgroundScroll(Je),e.client||$.destroy())}};return o&&Object.defineProperty(Vn,"screen",{get:()=>Ee,enumerable:!0}),Vn;function St(){if(!U)return;if(o)qn();else{const l=nt==="left"?"border-right":"border-left";ne?.matches?(U.style.width="100%",T.style.borderRadius="0",T.style.removeProperty(l)):(U.style.width=typeof z=="number"?`${z}px`:z,T.style.setProperty(l,`1px solid ${n.BORDER_COLOR}`));const g=i==="left"?"translateX(-100%)":"translateX(100%)";U.style.transform=te?"translateX(0)":g,le&&(le.style.display=te?"none":"flex")}U.setAttribute("aria-hidden",te?"false":"true");const a=Zt();a!==Dt&&(Dt=a,a?(T.setAttribute("role","dialog"),T.setAttribute("aria-modal","true"),T.setAttribute("aria-label",R),T.tabIndex=-1,T.style.paddingBottom="env(safe-area-inset-bottom)",n.lockBackgroundScroll(Je),Re=en(),tn(),Qn()):(nn(),oi(),Re=0,T.removeAttribute("role"),T.removeAttribute("aria-modal"),T.removeAttribute("aria-label"),T.style.removeProperty("padding-bottom"),n.unlockBackgroundScroll(Je)))}function qn(){if(!U)return;U.style.display=te?"block":"none",Pt?.setOpen(te);const a=ct();if(le&&(le.style.display=a&&te?"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",te&&(ue?.remove(),ue=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",Jt()}}function Tt(){te=!0,Ne&&(clearTimeout(Ne),Ne=void 0),ue?.remove(),ue=void 0,St(),ct()?T.focus({preventScroll:!0}):gt(),_t(),y?.()}function qe(){et(),te=!1,St(),k?.()}function Xn(){te?qe():Tt()}function Zo(){ae?Tt():pt()}function ei(){et(),ae?qe():ut()}function ti(){ae?Xn():we?ut():pt()}function ct(){return!!ne?.matches}function Zt(){return ct()&&(ae?te:we)}function ni(){return Array.from(T.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(!Zt())return;if(a.key==="Escape"){ae?qe():ut();return}if(a.key!=="Tab")return;const l=ni();if(l.length===0){a.preventDefault();return}const g=l[0],_=l[l.length-1],H=document.activeElement;a.shiftKey&&(H===g||!T.contains(H))?(a.preventDefault(),_.focus()):!a.shiftKey&&(H===_||!T.contains(H))&&(a.preventDefault(),g.focus())}function Yn(a){ae?St():!a.matches&&we&&ut(),X()}function en(){return window.visualViewport?.height??window.innerHeight}function tn(){const a=window.visualViewport,l=a?.offsetTop??0,g=a?.height??Re;if(ae){if(!U)return;const H=window.innerHeight||Re,L=Math.max(0,H-(l+g));U.style.bottom=`${L}px`,U.style.top=`${l}px`;return}const _=Math.min(0,l+g-Re);T.style.top=`${_}px`,fe&&(fe.style.top=`${l}px`)}function oi(){ae&&U&&(U.style.removeProperty("bottom"),U.style.removeProperty("top"),o&&!Z&&qn())}function Rt(){je||(je=requestAnimationFrame(()=>{je=0,!Z&&tn()}))}function Qn(){window.visualViewport?.addEventListener("resize",Rt),window.visualViewport?.addEventListener("scroll",Rt)}function nn(){window.visualViewport?.removeEventListener("resize",Rt),window.visualViewport?.removeEventListener("scroll",Rt),je&&(cancelAnimationFrame(je),je=0)}function Jn(){Te=!0,Ut()}function ii(){const a=n.div({position:"fixed",top:"0",left:"0",right:"0",height:`calc(${vn}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",p){const g=document.createElement("img");g.src=p,g.alt="",n.css(g,{height:"28px",width:"auto"}),a.appendChild(g)}else if(R){const g=document.createElement("span");g.textContent=R,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",()=>{ut()}),a.appendChild(l),a}function ri(){return typeof document.startViewTransition=="function"&&!No?.matches&&!!ne?.matches}function Zn(a){const l=document;if(ri()&&l.startViewTransition){T.style.setProperty("view-transition-name",at),fe?.style.setProperty("view-transition-name",`${at}-bar`);const g=()=>{T.style.removeProperty("view-transition-name"),fe?.style.removeProperty("view-transition-name")};return l.startViewTransition(a).finished.then(g,g)}return a(),Promise.resolve()}function eo(a){if(a)Ae&&T.parentElement?.insertBefore(Ae,T),n.css(T,{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(${vn}px + env(safe-area-inset-top))`,paddingBottom:"env(safe-area-inset-bottom)"}),T.setAttribute("role","dialog"),T.setAttribute("aria-modal","true"),T.setAttribute("aria-label",R),ce&&(ce.style.display="none"),fe&&(fe.style.display="flex");else{Ae?.remove(),Ae=void 0;for(const l of["position","top","left","right","bottom","z-index","padding-top","padding-bottom"])T.style.removeProperty(l);T.style.height=Ct.height,T.style.border=Ct.border,T.style.borderRadius=Ct.borderRadius,T.style.boxShadow=Ct.boxShadow,T.removeAttribute("role"),T.removeAttribute("aria-modal"),T.removeAttribute("aria-label"),ce&&(ce.style.display="flex"),fe&&(fe.style.display="none")}}function pt(){if(Z||we||!ne?.matches)return Promise.resolve();const a=T.getBoundingClientRect();if(a.height>=en()*.8)return Promise.resolve();we=!0,Ae=n.div({width:`${a.width}px`,height:`${a.height}px`}),Ae.className="ago-chat-widget-spacer",Ae.setAttribute("aria-hidden","true"),Re=en(),T.style.setProperty("--ago-vh",`${Re}px`),tn(),Qn(),n.lockBackgroundScroll(Je);const l=Zn(()=>eo(!0));return l.then(()=>{Z||(Jn(),gt())}),Jn(),y?.(),l}function ut(){if(!we)return Promise.resolve();et(),we=!1,nn(),n.unlockBackgroundScroll(Je),T.querySelector("textarea")?.blur();const a=Zn(()=>eo(!1));return a.then(()=>{Z||T.style.removeProperty("--ago-vh")}),Re=0,k?.(),a}}exports.DEFAULT_FEEDBACK_LABELS=pn;exports.DEFAULT_SPEECH_TO_TEXT_LABELS=n.DEFAULT_SPEECH_TO_TEXT_LABELS;exports.DEFAULT_TOOL_CALL_FORM_LABELS=To;exports.DEFAULT_WIDGET_LABELS=an;exports.colorsToTheme=n.colorsToTheme;exports.compactMediaQuery=n.compactMediaQuery;exports.createSheetController=n.createSheetController;exports.mountChatWidget=Ar;exports.readableTextColor=n.readableTextColor;exports.renderMarkdown=Me;
|