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