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