@useago/sdk 1.13.0 → 1.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/dist/angular.cjs +1 -1
- package/dist/angular.d.cts +43 -10
- package/dist/angular.d.ts +43 -10
- package/dist/angular.js +4 -4
- package/dist/autoContinue-C3UsCvT5.cjs +1 -0
- package/dist/{autoContinue-CC8K9mBU.js → autoContinue-Cb4_iEbO.js} +1 -1
- package/dist/{createConversationSession-CiOXKWl0.cjs → createConversationSession-Digvn0GQ.cjs} +1 -1
- package/dist/{createConversationSession-BfJg0WyA.js → createConversationSession-DrmOaZdO.js} +1 -1
- package/dist/{createFormCollector-DnQl77Ko.cjs → createFormCollector-Cq7HWjtU.cjs} +1 -1
- package/dist/{createFormCollector-DN1xjAv5.js → createFormCollector-ki_GTlp9.js} +1 -1
- package/dist/devtools.d.cts +34 -5
- package/dist/devtools.d.ts +34 -5
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +34 -5
- package/dist/index.d.ts +34 -5
- package/dist/index.js +4 -4
- package/dist/react.cjs +3 -3
- package/dist/react.d.cts +40 -6
- package/dist/react.d.ts +40 -6
- package/dist/react.js +290 -284
- package/dist/testing.d.cts +34 -5
- package/dist/testing.d.ts +34 -5
- package/dist/{types-Q7t1peH-.js → types-D1ZrqVhr.js} +884 -776
- package/dist/types-DNr6XEwI.cjs +10 -0
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.cts +38 -7
- package/dist/vue.d.ts +38 -7
- package/dist/vue.js +57 -57
- package/dist/widget.cjs +6 -6
- package/dist/widget.d.cts +34 -5
- package/dist/widget.d.ts +34 -5
- package/dist/widget.js +136 -136
- package/llms-full.txt +56 -3
- package/package.json +1 -1
- package/dist/autoContinue-CP9pJR-V.cjs +0 -1
- package/dist/types-a7teDBnC.cjs +0 -10
package/dist/widget.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _e=require("./types-a7teDBnC.cjs"),si=require("./errors-o1IB5fEu.cjs"),li=require("./createConversationSession-CiOXKWl0.cjs"),to=require("./createFormCollector-DnQl77Ko.cjs"),n=require("./speechToText-ZciRyyJE.cjs");var di=10*1024*1024;var no=["image/jpeg","image/png","image/gif","image/webp","image/bmp","image/tiff","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-word.document.macroenabled.12","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","text/plain","text/csv","application/json","application/xml","text/xml","text/html","application/epub+zip"];function oo(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function ci(t){const e=t.look==="embed";let i=[];const o=new Map,r=document.createElement("form");r.className=e?"ago-chat-input ago-chat-input--embed":"ago-chat-input",e?n.css(r,{width:"100%",borderRadius:"24px",border:`2px solid ${n.PRIMARY_FOREGROUND}`,backgroundColor:"#fff",boxShadow:n.SHADOW,position:"relative",boxSizing:"border-box",display:"block",fontFamily:n.FONT_VAR}):n.css(r,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${n.BORDER_COLOR}`,backgroundColor:n.PANEL_BACKGROUND});const s=n.div(e?{display:"none",flexWrap:"wrap",gap:"8px",padding:"0 0 8px"}:{display:"flex",flexWrap:"wrap",gap:"6px"});s.className="ago-chat-input__files";const c=n.div(e?{display:"flex",flexDirection:"row",gap:"8px",padding:"16px"}:{display:"flex",gap:"8px",alignItems:"flex-end"}),d=document.createElement("textarea");d.placeholder=t.placeholder,d.setAttribute("aria-label",t.placeholder),d.rows=1,d.autocapitalize="off",d.setAttribute("autocorrect","off");const h=e?208:110;e?n.css(d,{display:"block",width:"100%",minHeight:"40px",maxHeight:`${h}px`,overflowY:"auto",resize:"none",border:"none",outline:"none",boxShadow:"none",background:"transparent",padding:"8px",boxSizing:"border-box",fontSize:"16px",lineHeight:"24px",fontFamily:"inherit",color:"inherit"}):n.css(d,{flex:"1",resize:"none",boxSizing:"border-box",padding:"10px 12px",border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"12px",fontSize:"16px",fontFamily:n.FONT_VAR,lineHeight:"1.4",maxHeight:`${h}px`,overflowY:"hidden"});const m=()=>{const f=e?0:2;d.style.height="auto";const B=Math.min(d.scrollHeight+f,h);d.style.height=`${B}px`,d.style.overflowY=d.scrollHeight+f>h?"auto":"hidden"};d.addEventListener("input",()=>{m(),E()});const p='<svg width="18" height="18" viewBox="0 -960 960 960" fill="currentColor" aria-hidden="true"><path d="M440-160v-487L216-423l-56-57 320-320 320 320-56 57-224-224v487h-80Z"/></svg>',x='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true" style="animation: ago-spin 0.8s linear infinite"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>',I='<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><rect x="5" y="5" width="14" height="14" rx="2"/></svg>',w=document.createElement("button");w.type="submit",w.className="ago-chat-input__send",w.setAttribute("aria-label","Send"),e?n.css(w,{flexShrink:"0",width:"40px",height:"40px",padding:"0",border:"none",borderRadius:"50%",backgroundColor:n.SEND_BACKGROUND,color:"#fafafa",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",transition:"background-color 0.15s, color 0.15s"}):(w.innerHTML=p,n.css(w,{flexShrink:"0",width:"44px",height:"44px",padding:"0",border:"none",borderRadius:"50%",backgroundColor:n.BRAND_COLOR,color:n.BRAND_TEXT_COLOR,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer"}));let u=!1,v=!1;const A=()=>u&&!!t.onStop,E=()=>{const f=d.value.trim()!==""||i.length>0,B=A(),G=!B&&(u||v||!f);if(w.disabled=G,w.type=B?"button":"submit",w.setAttribute("aria-label",B?"Stop generating":"Send"),e){w.replaceChildren(B?n.stopIcon({size:16}):n.arrowUpwardIcon({size:16}));const P=G&&!u;w.style.backgroundColor=P?"#f1f5f9":n.SEND_BACKGROUND,w.style.color=P?"#cbd5e1":"#fafafa",w.style.pointerEvents=G?"none":"auto",w.style.cursor=G?"default":"pointer",J.style.opacity=u?"0.5":"1";return}w.innerHTML=B?I:u?x:p,w.style.opacity=G&&!u?"0.5":"1",w.style.cursor=G?"default":"pointer"};w.addEventListener("click",()=>{A()&&t.onStop?.()});const O=n.div({display:"none",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",margin:"0 0 12px",padding:"12px 16px",borderRadius:"12px",border:"1px solid rgba(239, 68, 68, 0.5)",color:"#ef4444",backgroundColor:"#fff",fontSize:"14px",lineHeight:"20px"});O.className="ago-chat-input__error",O.setAttribute("role","alert");const W=document.createElement("span"),C=document.createElement("button");C.type="button",C.textContent=t.labels?.dismiss??"Dismiss",n.css(C,{border:"none",background:"transparent",color:"inherit",font:"inherit",fontWeight:"500",cursor:"pointer",padding:"0",minHeight:"20px"}),C.addEventListener("click",()=>{O.style.display="none"}),O.append(W,C);const F=f=>{W.textContent=f,O.style.display="flex"},y=(f,B)=>f.replace(/\{(\w+)\}/g,(G,P)=>B[P]??""),k=f=>{if(!e)return f;const B=t.labels,G=[];for(const P of f){if(i.length+G.length>=5){F(y(B?.tooManyFiles??"Too many files. Maximum allowed: {max}",{max:String(5)}));break}if(P.type&&!no.includes(P.type)){F(y(B?.invalidFileType??"Invalid file type: {name}",{name:P.name}));continue}if(P.size>10485760){F(y(B?.fileTooLarge??"File too large: {name} (maximum {max})",{name:P.name,max:oo(di)}));continue}G.push(P)}return G};let S=null,D=null;t.allowFiles&&(S=document.createElement("input"),S.type="file",S.multiple=!0,e&&(S.accept=no.join(",")),n.css(S,{display:"none"}),D=document.createElement("button"),D.type="button",D.className="ago-chat-input__attach",D.setAttribute("aria-label",t.labels?.attachFiles??"Attach file"),e?(D.appendChild(n.attachFileIcon({size:16})),n.css(D,{height:"40px",padding:"8px",display:"flex",alignItems:"center",gap:"4px",fontSize:"14px",color:n.BRAND_COLOR,background:"none",border:"none",cursor:"pointer",borderRadius:"6px"})):(D.textContent="📎",n.css(D,{flexShrink:"0",minWidth:"44px",minHeight:"44px",display:"flex",alignItems:"center",justifyContent:"center",padding:"0 12px",border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"12px",backgroundColor:n.PANEL_BACKGROUND,cursor:"pointer",fontSize:"14px"})),D.addEventListener("click",()=>S?.click()),S.addEventListener("change",()=>{const f=Array.from(S?.files??[]);i=[...i,...k(f)],S&&(S.value=""),j()}));function V(f){if(!e||!f.type.startsWith("image/")||typeof URL>"u"||typeof URL.createObjectURL!="function")return null;let B=o.get(f);return B||(B=URL.createObjectURL(f),o.set(f,B)),B}function M(f){const B=o.get(f);B&&(URL.revokeObjectURL(B),o.delete(f))}function j(){s.replaceChildren(),e&&(s.style.display=i.length>0?"flex":"none"),i.forEach((f,B)=>{const G=n.div(e?{display:"flex",alignItems:"center",gap:"8px",backgroundColor:"#f3f4f6",borderRadius:"8px",padding:"8px 12px",fontSize:"14px",lineHeight:"20px"}:{display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"8px",fontSize:"12px"});if(G.className="ago-chat-input__file",e){const re=V(f);if(re){const be=document.createElement("img");be.src=re,be.alt="",n.css(be,{width:"32px",height:"32px",objectFit:"cover",borderRadius:"4px",flexShrink:"0"}),G.appendChild(be)}else G.appendChild(n.descriptionIcon({size:20}))}const P=document.createElement("span");if(P.textContent=f.name,P.title=f.name,e&&n.css(P,{maxWidth:"150px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),G.appendChild(P),e){const re=document.createElement("span");re.textContent=oo(f.size),n.css(re,{fontSize:"12px",lineHeight:"16px",color:"#6b7280"}),G.appendChild(re)}const ee=document.createElement("button");ee.type="button",ee.setAttribute("aria-label",`Remove ${f.name}`),e?ee.appendChild(n.closeIcon({size:16})):ee.textContent="×",n.css(ee,{flexShrink:"0",width:"44px",height:"44px",margin:e?"-10px -16px -10px -8px":"-14px -12px -14px -4px",display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1",color:"inherit"}),ee.addEventListener("click",()=>{M(f),i=i.filter((re,be)=>be!==B),j()}),G.appendChild(ee),s.appendChild(G)}),E()}const b=()=>{z?.cancel();const f=d.value,B=i;d.value="",m(),i=[];for(const G of B)M(G);return j(),{content:f,files:B}},R=()=>{if(u||v)return;const{content:f,files:B}=b();(f.trim()||B.length>0)&&(t.onSend(f.trim(),B.length>0?B:void 0),e&&typeof window<"u"&&window.innerWidth<(t.blurOnSubmitBelow??600)&&d.blur())};r.addEventListener("submit",f=>{f.preventDefault(),R()}),d.addEventListener("keydown",f=>{if(f.key==="Enter"&&!f.shiftKey){if(f.isComposing||f.keyCode===229)return;f.preventDefault(),R()}});const z=t.transcribeAudio?n.createSpeechToText({transcribe:t.transcribeAudio,labels:t.speechToTextLabels,onBusy:f=>{const B=v&&!f&&!u&&r.contains(document.activeElement);v=f,d.disabled=u||f,e?(J.style.display=f?"none":"",Y.style.display=f?"none":"flex",c.style.padding=f?"8px":"16px",z&&(f?c.append(z.el):Y.prepend(z.el))):(d.style.display=f?"none":"",w.style.display=f?"none":"flex",D&&(D.style.display=f?"none":"flex")),E(),B&&d.focus()},onText:f=>{d.value+=`${d.value&&!/\s$/.test(d.value)?" ":""}${f}`,m(),E(),d.focus()},onError:F}):void 0,J=n.div({flex:"1",minWidth:"0"});J.className="ago-chat-input__editor";const Y=n.div({display:"flex",alignItems:"flex-end",flexShrink:"0",gap:"4px"});if(e){J.append(O,s,d);const f=n.div({display:"flex",alignItems:"center"});f.className="ago-chat-input__toolbar",D&&f.appendChild(D),D&&J.appendChild(f),z&&Y.appendChild(z.el),Y.appendChild(w),c.append(J,Y),S&&r.appendChild(S),r.appendChild(c),r.addEventListener("click",B=>{(B.target instanceof Element?B.target:null)?.closest("button,a,input,textarea")||d.focus()})}else D&&c.appendChild(D),c.append(d),z&&c.appendChild(z.el),c.append(w),S&&r.appendChild(S),r.append(O,s,c);return E(),{inputRow:r,getValueAndClear:b,setDisabled:f=>{u=f,z?.setDisabled(f),d.disabled=f||v,E()},focus:()=>d.focus(),blur:()=>d.blur(),restoreDraft:(f,B)=>{f&&!d.value.trim()&&(d.value=f,m()),B?.length&&(i=[...B,...i],j()),E()},setPlaceholder:f=>{d.placeholder=f,f&&d.setAttribute("aria-label",f)},setSpeechToTextEnabled:f=>z?.setEnabled(f),cancelRecording:()=>z?.cancel(),destroy:()=>{z?.destroy();for(const f of o.keys())M(f)}}}var on="rgba(3, 24, 47, 0.07)";function pi(t){const e=document.createElement("footer");e.className="ago-chat-widget__footer",n.css(e,{padding:"12px",flexShrink:"0",background:"transparent"});const i=document.createElement("nav");n.css(i,{display:"flex",alignItems:"center",gap:"4px",width:"100%"});const o=new Map;let r="home";function s(d,h,m){const p=document.createElement("button");p.type="button",p.className="ago-chat-widget__tab",p.dataset.agoScreen=d,n.css(p,{flex:"1",minWidth:"0",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"4px",padding:"12px 8px",borderRadius:"32px",border:"none",background:"transparent",color:n.BRAND_COLOR,cursor:"pointer",transition:"background-color 0.15s",font:"inherit"});const x=document.createElement("span");return x.textContent=h,n.css(x,{fontSize:"12px",lineHeight:"16px",maxWidth:"100%",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"}),p.append(m,x),p.addEventListener("mouseenter",()=>{p.style.backgroundColor=on}),p.addEventListener("mouseleave",()=>{p.style.backgroundColor=r===d?on:"transparent"}),p.addEventListener("click",()=>t.onNavigate(d)),o.set(d,p),p}i.append(s("home",t.labels.home,n.houseIcon({size:24})),s("history",t.labels.chats,n.conversationsIcon({size:24}))),e.appendChild(i);const c=d=>{r=d==="history"?"history":"home";for(const[h,m]of o){const p=h===r;m.style.color=p?n.PRIMARY_ACCENT:n.BRAND_COLOR,m.style.backgroundColor=p?on:"transparent",p?m.setAttribute("aria-current","page"):m.removeAttribute("aria-current")}};return c("home"),{el:e,setActive:c,setVisible:d=>{e.style.display=d?"block":"none"}}}function rn(t,e,i,o){const r=document.createElement("button");return r.type="button",r.className=t,r.setAttribute("aria-label",e),r.title=e,n.css(r,{display:"flex",alignItems:"center",justifyContent:"center",width:"44px",height:"44px",margin:"-12px",padding:"0",border:"none",background:"transparent",color:"currentColor",opacity:"0.8",cursor:"pointer",transition:"opacity 0.15s",flexShrink:"0"}),r.addEventListener("mouseenter",()=>{r.style.opacity="1"}),r.addEventListener("mouseleave",()=>{r.style.opacity="0.8"}),r.addEventListener("click",o),r.appendChild(i),r}function ui(t){const e=document.createElement("header");e.className="ago-chat-widget__header",n.css(e,{display:"flex",alignItems:"center",justifyContent:"space-between",height:"56px",padding:"0 16px",boxSizing:"border-box",background:n.HEADER_BACKGROUND,color:n.HEADER_TEXT_COLOR,borderBottom:"1px solid #e5e7eb",boxShadow:n.SHADOW_SM,flexShrink:"0"});const i=n.div({display:"flex",alignItems:"center",gap:"12px",minWidth:"0"}),o=rn("ago-chat-widget__back",t.labels.back,n.chevronLeftIcon({size:20}),t.onBack);o.style.marginRight="-8px";const r=document.createElement("span");r.className="ago-chat-widget__title",n.css(r,{fontSize:"14px",lineHeight:"20px",fontWeight:"500",color:"currentColor",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"}),i.append(o,r);const s=n.div({display:"flex",alignItems:"center",gap:"8px",flexShrink:"0"}),c=rn("ago-chat-widget__new",t.labels.newChat,n.addCommentIcon({size:20}),t.onNewChat),d=rn("ago-chat-widget__close",t.labels.close,n.closeIcon({size:20}),t.onClose);return s.append(c,d),e.append(i,s),{el:e,update:({screen:h})=>{o.style.display=h==="chat"?"flex":"none",c.style.display=h==="home"?"none":"flex",r.textContent=h==="history"?t.labels.history:t.title}}}var uo={minutes:"{n}min ago",hours:"{n}h ago",days:"{n}d ago",weeks:"{n} weeks ago",months:"{n} months ago"},fi=60*1e3;function mi(t,e=Date.now(),i=uo){const o=t instanceof Date?t.getTime():new Date(t).getTime(),r=(p,x)=>p.replace("{n}",String(x));if(!Number.isFinite(o))return r(i.minutes,0);const s=Math.max(0,Math.floor((e-o)/fi)),c=Math.floor(s/60),d=Math.floor(c/24),h=Math.floor(d/7),m=Math.max(1,Math.floor(d/30));return s<60?r(i.minutes,s):c<24?r(i.hours,c):d<7?r(i.days,d):h<4?r(i.weeks,h):r(i.months,m)}var an={home:"Home",chats:"Chats",history:"History",newConversation:"New conversation",noHistory:"No chat history yet",askQuestion:"Ask a question",back:"Back",close:"Close chat",newChat:"New chat",errorTitle:"Something went wrong",errorDescription:"The answer could not be generated. Please try again.",scrollToBottom:"Scroll to bottom",dismiss:"Dismiss",attachFiles:"Attach files",tooManyFiles:"Too many files. Maximum allowed: {max}",invalidFileType:"Invalid file type: {name}",fileTooLarge:"File too large: {name} (maximum {max})",timeAgo:uo};function gi(t){return{...an,...t,timeAgo:{...an.timeAgo,...t?.timeAgo}}}var hi={"&":"&","<":"<",">":">",'"':""","'":"'"};function Xe(t){return t.replace(/[&<>"']/g,e=>hi[e])}function io(t){const e=t.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(e)||!/^[a-z][a-z0-9+.-]*:/i.test(e)?e:null}var fo='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',At="";function ze(t){const e=[],i=r=>(e.push(r),`${At}${e.length-1}${At}`);let o=t;return o=o.replace(/`([^`]+)`/g,(r,s)=>i(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${fo}">${Xe(s)}</code>`)),o=o.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(r,s,c)=>{const d=io(c);return d?i(`<img alt="${Xe(s)}" src="${Xe(d)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):r}),o=o.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(r,s,c)=>{const d=io(c);return d?i(`<a href="${Xe(d)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${ze(s)}</a>`):r}),o=Xe(o),o=o.replace(/\*\*([^*]+?)\*\*/g,"<strong>$1</strong>").replace(/__([^_]+?)__/g,"<strong>$1</strong>").replace(/~~([^~]+?)~~/g,"<del>$1</del>").replace(/(^|[^*])\*(?!\s)([^*]+?)\*/g,"$1<em>$2</em>").replace(/(^|[^\w_])_(?!\s)([^_]+?)_/g,"$1<em>$2</em>"),o=o.replace(new RegExp(`${At}(\\d+)${At}`,"g"),(r,s)=>e[Number(s)]),o}function de(t,e,i){const o=document.createElement(t);return Object.assign(o.style,e),i!==void 0&&(o.innerHTML=i),o}var mo=/^ {0,3}([-*_])( *\1){2,} *$/,go=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,ho=/^ {0,3}(```+|~~~+)/,Ot=/^ {0,3}>\s?/,Ye=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,bi=["20px","18px","16px","15px","14px","13px"],sn=t=>t.match(/^\s*/)?.[0].length??0;function xi(t){return t.trim()===""||mo.test(t)||go.test(t)||ho.test(t)||Ot.test(t)||Ye.test(t)}function bo(t){const e=t[0].match(Ye),i=e[1].length,o=/\d/.test(e[2]),r=de(o?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:o?"decimal":"disc",listStylePosition:"outside"});let s=0;for(;s<t.length;){const c=t[s].match(Ye),d=[];for(s++;s<t.length&&sn(t[s])>i;)d.push(t[s]),s++;const h=de("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),m=c[3].match(/^\[([ xX])\]\s+(.*)$/);m?(h.style.listStyleType="none",h.style.marginLeft="-20px",h.innerHTML=`<span style="margin-right:6px">${m[1].toLowerCase()==="x"?"☑":"☐"}</span>${ze(m[2])}`):h.innerHTML=ze(c[3]),d.filter(p=>Ye.test(p)).length>0&&h.appendChild(bo(d.filter(p=>p.trim()!==""))),r.appendChild(h)}return r}function yi(t){const e=d=>d.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(h=>h.trim()),i=de("div",{overflowX:"auto",margin:"0 0 8px 0"}),o=de("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),r=document.createElement("thead"),s=document.createElement("tr");for(const d of e(t[0]))s.appendChild(de("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},ze(d)));r.appendChild(s),o.appendChild(r);const c=document.createElement("tbody");for(const d of t.slice(2)){const h=document.createElement("tr");for(const m of e(d))h.appendChild(de("td",{border:"1px solid #dee3e8",padding:"6px 10px"},ze(m)));c.appendChild(h)}return o.appendChild(c),i.appendChild(o),i}var Ci=t=>!!t&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(t);function Me(t){const e=document.createDocumentFragment(),i=t.replace(/\r\n?/g,`
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _e=require("./types-DNr6XEwI.cjs"),si=require("./errors-o1IB5fEu.cjs"),li=require("./createConversationSession-Digvn0GQ.cjs"),to=require("./createFormCollector-Cq7HWjtU.cjs"),n=require("./speechToText-ZciRyyJE.cjs");var di=10*1024*1024;var no=["image/jpeg","image/png","image/gif","image/webp","image/bmp","image/tiff","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-word.document.macroenabled.12","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","text/plain","text/csv","application/json","application/xml","text/xml","text/html","application/epub+zip"];function oo(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function ci(t){const e=t.look==="embed";let i=[];const o=new Map,r=document.createElement("form");r.className=e?"ago-chat-input ago-chat-input--embed":"ago-chat-input",e?n.css(r,{width:"100%",borderRadius:"24px",border:`2px solid ${n.PRIMARY_FOREGROUND}`,backgroundColor:"#fff",boxShadow:n.SHADOW,position:"relative",boxSizing:"border-box",display:"block",fontFamily:n.FONT_VAR}):n.css(r,{display:"flex",flexDirection:"column",gap:"8px",padding:"12px",borderTop:`1px solid ${n.BORDER_COLOR}`,backgroundColor:n.PANEL_BACKGROUND});const s=n.div(e?{display:"none",flexWrap:"wrap",gap:"8px",padding:"0 0 8px"}:{display:"flex",flexWrap:"wrap",gap:"6px"});s.className="ago-chat-input__files";const c=n.div(e?{display:"flex",flexDirection:"row",gap:"8px",padding:"16px"}:{display:"flex",gap:"8px",alignItems:"flex-end"}),d=document.createElement("textarea");d.placeholder=t.placeholder,d.setAttribute("aria-label",t.placeholder),d.rows=1,d.autocapitalize="off",d.setAttribute("autocorrect","off");const h=e?208:110;e?n.css(d,{display:"block",width:"100%",minHeight:"40px",maxHeight:`${h}px`,overflowY:"auto",resize:"none",border:"none",outline:"none",boxShadow:"none",background:"transparent",padding:"8px",boxSizing:"border-box",fontSize:"16px",lineHeight:"24px",fontFamily:"inherit",color:"inherit"}):n.css(d,{flex:"1",resize:"none",boxSizing:"border-box",padding:"10px 12px",border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"12px",fontSize:"16px",fontFamily:n.FONT_VAR,lineHeight:"1.4",maxHeight:`${h}px`,overflowY:"hidden"});const f=()=>{const m=e?0:2;d.style.height="auto";const B=Math.min(d.scrollHeight+m,h);d.style.height=`${B}px`,d.style.overflowY=d.scrollHeight+m>h?"auto":"hidden"};d.addEventListener("input",()=>{f(),E()});const p='<svg width="18" height="18" viewBox="0 -960 960 960" fill="currentColor" aria-hidden="true"><path d="M440-160v-487L216-423l-56-57 320-320 320 320-56 57-224-224v487h-80Z"/></svg>',x='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true" style="animation: ago-spin 0.8s linear infinite"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>',I='<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><rect x="5" y="5" width="14" height="14" rx="2"/></svg>',w=document.createElement("button");w.type="submit",w.className="ago-chat-input__send",w.setAttribute("aria-label","Send"),e?n.css(w,{flexShrink:"0",width:"40px",height:"40px",padding:"0",border:"none",borderRadius:"50%",backgroundColor:n.SEND_BACKGROUND,color:"#fafafa",display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",transition:"background-color 0.15s, color 0.15s"}):(w.innerHTML=p,n.css(w,{flexShrink:"0",width:"44px",height:"44px",padding:"0",border:"none",borderRadius:"50%",backgroundColor:n.BRAND_COLOR,color:n.BRAND_TEXT_COLOR,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer"}));let u=!1,v=!1;const A=()=>u&&!!t.onStop,E=()=>{const m=d.value.trim()!=="",B=A(),G=!B&&(u||v||!m);if(w.disabled=G,w.type=B?"button":"submit",w.setAttribute("aria-label",B?"Stop generating":"Send"),e){w.replaceChildren(B?n.stopIcon({size:16}):n.arrowUpwardIcon({size:16}));const P=G&&!u;w.style.backgroundColor=P?"#f1f5f9":n.SEND_BACKGROUND,w.style.color=P?"#cbd5e1":"#fafafa",w.style.pointerEvents=G?"none":"auto",w.style.cursor=G?"default":"pointer",J.style.opacity=u?"0.5":"1";return}w.innerHTML=B?I:u?x:p,w.style.opacity=G&&!u?"0.5":"1",w.style.cursor=G?"default":"pointer"};w.addEventListener("click",()=>{A()&&t.onStop?.()});const O=n.div({display:"none",alignItems:"flex-start",justifyContent:"space-between",gap:"8px",margin:"0 0 12px",padding:"12px 16px",borderRadius:"12px",border:"1px solid rgba(239, 68, 68, 0.5)",color:"#ef4444",backgroundColor:"#fff",fontSize:"14px",lineHeight:"20px"});O.className="ago-chat-input__error",O.setAttribute("role","alert");const W=document.createElement("span"),C=document.createElement("button");C.type="button",C.textContent=t.labels?.dismiss??"Dismiss",n.css(C,{border:"none",background:"transparent",color:"inherit",font:"inherit",fontWeight:"500",cursor:"pointer",padding:"0",minHeight:"20px"}),C.addEventListener("click",()=>{O.style.display="none"}),O.append(W,C);const F=m=>{W.textContent=m,O.style.display="flex"},y=(m,B)=>m.replace(/\{(\w+)\}/g,(G,P)=>B[P]??""),k=m=>{if(!e)return m;const B=t.labels,G=[];for(const P of m){if(i.length+G.length>=5){F(y(B?.tooManyFiles??"Too many files. Maximum allowed: {max}",{max:String(5)}));break}if(P.type&&!no.includes(P.type)){F(y(B?.invalidFileType??"Invalid file type: {name}",{name:P.name}));continue}if(P.size>10485760){F(y(B?.fileTooLarge??"File too large: {name} (maximum {max})",{name:P.name,max:oo(di)}));continue}G.push(P)}return G};let S=null,D=null;t.allowFiles&&(S=document.createElement("input"),S.type="file",S.multiple=!0,e&&(S.accept=no.join(",")),n.css(S,{display:"none"}),D=document.createElement("button"),D.type="button",D.className="ago-chat-input__attach",D.setAttribute("aria-label",t.labels?.attachFiles??"Attach file"),e?(D.appendChild(n.attachFileIcon({size:16})),n.css(D,{height:"40px",padding:"8px",display:"flex",alignItems:"center",gap:"4px",fontSize:"14px",color:n.BRAND_COLOR,background:"none",border:"none",cursor:"pointer",borderRadius:"6px"})):(D.textContent="📎",n.css(D,{flexShrink:"0",minWidth:"44px",minHeight:"44px",display:"flex",alignItems:"center",justifyContent:"center",padding:"0 12px",border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"12px",backgroundColor:n.PANEL_BACKGROUND,cursor:"pointer",fontSize:"14px"})),D.addEventListener("click",()=>S?.click()),S.addEventListener("change",()=>{const m=Array.from(S?.files??[]);i=[...i,...k(m)],S&&(S.value=""),j()}));function V(m){if(!e||!m.type.startsWith("image/")||typeof URL>"u"||typeof URL.createObjectURL!="function")return null;let B=o.get(m);return B||(B=URL.createObjectURL(m),o.set(m,B)),B}function M(m){const B=o.get(m);B&&(URL.revokeObjectURL(B),o.delete(m))}function j(){s.replaceChildren(),e&&(s.style.display=i.length>0?"flex":"none"),i.forEach((m,B)=>{const G=n.div(e?{display:"flex",alignItems:"center",gap:"8px",backgroundColor:"#f3f4f6",borderRadius:"8px",padding:"8px 12px",fontSize:"14px",lineHeight:"20px"}:{display:"flex",alignItems:"center",gap:"4px",padding:"4px 8px",backgroundColor:"#f0f4ff",border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"8px",fontSize:"12px"});if(G.className="ago-chat-input__file",e){const re=V(m);if(re){const be=document.createElement("img");be.src=re,be.alt="",n.css(be,{width:"32px",height:"32px",objectFit:"cover",borderRadius:"4px",flexShrink:"0"}),G.appendChild(be)}else G.appendChild(n.descriptionIcon({size:20}))}const P=document.createElement("span");if(P.textContent=m.name,P.title=m.name,e&&n.css(P,{maxWidth:"150px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),G.appendChild(P),e){const re=document.createElement("span");re.textContent=oo(m.size),n.css(re,{fontSize:"12px",lineHeight:"16px",color:"#6b7280"}),G.appendChild(re)}const ee=document.createElement("button");ee.type="button",ee.setAttribute("aria-label",`Remove ${m.name}`),e?ee.appendChild(n.closeIcon({size:16})):ee.textContent="×",n.css(ee,{flexShrink:"0",width:"44px",height:"44px",margin:e?"-10px -16px -10px -8px":"-14px -12px -14px -4px",display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",cursor:"pointer",fontSize:"14px",lineHeight:"1",color:"inherit"}),ee.addEventListener("click",()=>{M(m),i=i.filter((re,be)=>be!==B),j()}),G.appendChild(ee),s.appendChild(G)}),E()}const b=()=>{z?.cancel();const m=d.value,B=i;d.value="",f(),i=[];for(const G of B)M(G);return j(),{content:m,files:B}},R=()=>{if(u||v||!d.value.trim())return;const{content:m,files:B}=b();t.onSend(m.trim(),B.length>0?B:void 0),e&&typeof window<"u"&&window.innerWidth<(t.blurOnSubmitBelow??600)&&d.blur()};r.addEventListener("submit",m=>{m.preventDefault(),R()}),d.addEventListener("keydown",m=>{if(m.key==="Enter"&&!m.shiftKey){if(m.isComposing||m.keyCode===229)return;m.preventDefault(),R()}});const z=t.transcribeAudio?n.createSpeechToText({transcribe:t.transcribeAudio,labels:t.speechToTextLabels,onBusy:m=>{const B=v&&!m&&!u&&r.contains(document.activeElement);v=m,d.disabled=u||m,e?(J.style.display=m?"none":"",Y.style.display=m?"none":"flex",c.style.padding=m?"8px":"16px",z&&(m?c.append(z.el):Y.prepend(z.el))):(d.style.display=m?"none":"",w.style.display=m?"none":"flex",D&&(D.style.display=m?"none":"flex")),E(),B&&d.focus()},onText:m=>{d.value+=`${d.value&&!/\s$/.test(d.value)?" ":""}${m}`,f(),E(),d.focus()},onError:F}):void 0,J=n.div({flex:"1",minWidth:"0"});J.className="ago-chat-input__editor";const Y=n.div({display:"flex",alignItems:"flex-end",flexShrink:"0",gap:"4px"});if(e){J.append(O,s,d);const m=n.div({display:"flex",alignItems:"center"});m.className="ago-chat-input__toolbar",D&&m.appendChild(D),D&&J.appendChild(m),z&&Y.appendChild(z.el),Y.appendChild(w),c.append(J,Y),S&&r.appendChild(S),r.appendChild(c),r.addEventListener("click",B=>{(B.target instanceof Element?B.target:null)?.closest("button,a,input,textarea")||d.focus()})}else D&&c.appendChild(D),c.append(d),z&&c.appendChild(z.el),c.append(w),S&&r.appendChild(S),r.append(O,s,c);return E(),{inputRow:r,getValueAndClear:b,setDisabled:m=>{u=m,z?.setDisabled(m),d.disabled=m||v,E()},focus:()=>d.focus(),blur:()=>d.blur(),restoreDraft:(m,B)=>{m&&!d.value.trim()&&(d.value=m,f()),B?.length&&(i=[...B,...i],j()),E()},setPlaceholder:m=>{d.placeholder=m,m&&d.setAttribute("aria-label",m)},setSpeechToTextEnabled:m=>z?.setEnabled(m),cancelRecording:()=>z?.cancel(),destroy:()=>{z?.destroy();for(const m of o.keys())M(m)}}}var on="rgba(3, 24, 47, 0.07)";function pi(t){const e=document.createElement("footer");e.className="ago-chat-widget__footer",n.css(e,{padding:"12px",flexShrink:"0",background:"transparent"});const i=document.createElement("nav");n.css(i,{display:"flex",alignItems:"center",gap:"4px",width:"100%"});const o=new Map;let r="home";function s(d,h,f){const p=document.createElement("button");p.type="button",p.className="ago-chat-widget__tab",p.dataset.agoScreen=d,n.css(p,{flex:"1",minWidth:"0",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"4px",padding:"12px 8px",borderRadius:"32px",border:"none",background:"transparent",color:n.BRAND_COLOR,cursor:"pointer",transition:"background-color 0.15s",font:"inherit"});const x=document.createElement("span");return x.textContent=h,n.css(x,{fontSize:"12px",lineHeight:"16px",maxWidth:"100%",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"}),p.append(f,x),p.addEventListener("mouseenter",()=>{p.style.backgroundColor=on}),p.addEventListener("mouseleave",()=>{p.style.backgroundColor=r===d?on:"transparent"}),p.addEventListener("click",()=>t.onNavigate(d)),o.set(d,p),p}i.append(s("home",t.labels.home,n.houseIcon({size:24})),s("history",t.labels.chats,n.conversationsIcon({size:24}))),e.appendChild(i);const c=d=>{r=d==="history"?"history":"home";for(const[h,f]of o){const p=h===r;f.style.color=p?n.PRIMARY_ACCENT:n.BRAND_COLOR,f.style.backgroundColor=p?on:"transparent",p?f.setAttribute("aria-current","page"):f.removeAttribute("aria-current")}};return c("home"),{el:e,setActive:c,setVisible:d=>{e.style.display=d?"block":"none"}}}function rn(t,e,i,o){const r=document.createElement("button");return r.type="button",r.className=t,r.setAttribute("aria-label",e),r.title=e,n.css(r,{display:"flex",alignItems:"center",justifyContent:"center",width:"44px",height:"44px",margin:"-12px",padding:"0",border:"none",background:"transparent",color:"currentColor",opacity:"0.8",cursor:"pointer",transition:"opacity 0.15s",flexShrink:"0"}),r.addEventListener("mouseenter",()=>{r.style.opacity="1"}),r.addEventListener("mouseleave",()=>{r.style.opacity="0.8"}),r.addEventListener("click",o),r.appendChild(i),r}function ui(t){const e=document.createElement("header");e.className="ago-chat-widget__header",n.css(e,{display:"flex",alignItems:"center",justifyContent:"space-between",height:"56px",padding:"0 16px",boxSizing:"border-box",background:n.HEADER_BACKGROUND,color:n.HEADER_TEXT_COLOR,borderBottom:"1px solid #e5e7eb",boxShadow:n.SHADOW_SM,flexShrink:"0"});const i=n.div({display:"flex",alignItems:"center",gap:"12px",minWidth:"0"}),o=rn("ago-chat-widget__back",t.labels.back,n.chevronLeftIcon({size:20}),t.onBack);o.style.marginRight="-8px";const r=document.createElement("span");r.className="ago-chat-widget__title",n.css(r,{fontSize:"14px",lineHeight:"20px",fontWeight:"500",color:"currentColor",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"}),i.append(o,r);const s=n.div({display:"flex",alignItems:"center",gap:"8px",flexShrink:"0"}),c=rn("ago-chat-widget__new",t.labels.newChat,n.addCommentIcon({size:20}),t.onNewChat),d=rn("ago-chat-widget__close",t.labels.close,n.closeIcon({size:20}),t.onClose);return s.append(c,d),e.append(i,s),{el:e,update:({screen:h})=>{o.style.display=h==="chat"?"flex":"none",c.style.display=h==="home"?"none":"flex",r.textContent=h==="history"?t.labels.history:t.title}}}var uo={minutes:"{n}min ago",hours:"{n}h ago",days:"{n}d ago",weeks:"{n} weeks ago",months:"{n} months ago"},fi=60*1e3;function mi(t,e=Date.now(),i=uo){const o=t instanceof Date?t.getTime():new Date(t).getTime(),r=(p,x)=>p.replace("{n}",String(x));if(!Number.isFinite(o))return r(i.minutes,0);const s=Math.max(0,Math.floor((e-o)/fi)),c=Math.floor(s/60),d=Math.floor(c/24),h=Math.floor(d/7),f=Math.max(1,Math.floor(d/30));return s<60?r(i.minutes,s):c<24?r(i.hours,c):d<7?r(i.days,d):h<4?r(i.weeks,h):r(i.months,f)}var an={home:"Home",chats:"Chats",history:"History",newConversation:"New conversation",noHistory:"No chat history yet",askQuestion:"Ask a question",back:"Back",close:"Close chat",newChat:"New chat",errorTitle:"Something went wrong",errorDescription:"The answer could not be generated. Please try again.",scrollToBottom:"Scroll to bottom",dismiss:"Dismiss",attachFiles:"Attach files",tooManyFiles:"Too many files. Maximum allowed: {max}",invalidFileType:"Invalid file type: {name}",fileTooLarge:"File too large: {name} (maximum {max})",timeAgo:uo};function gi(t){return{...an,...t,timeAgo:{...an.timeAgo,...t?.timeAgo}}}var hi={"&":"&","<":"<",">":">",'"':""","'":"'"};function Xe(t){return t.replace(/[&<>"']/g,e=>hi[e])}function io(t){const e=t.trim();return/^(https?:|mailto:|tel:|#|\/|\.\/|\.\.\/)/i.test(e)||!/^[a-z][a-z0-9+.-]*:/i.test(e)?e:null}var fo='"IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace',At="";function ze(t){const e=[],i=r=>(e.push(r),`${At}${e.length-1}${At}`);let o=t;return o=o.replace(/`([^`]+)`/g,(r,s)=>i(`<code style="background:#f0f2f5;padding:2px 5px;border-radius:4px;font-size:13px;font-family:${fo}">${Xe(s)}</code>`)),o=o.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(r,s,c)=>{const d=io(c);return d?i(`<img alt="${Xe(s)}" src="${Xe(d)}" style="max-width:100%;border-radius:8px;margin:4px 0" />`):r}),o=o.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(r,s,c)=>{const d=io(c);return d?i(`<a href="${Xe(d)}" target="_blank" rel="noopener noreferrer" style="color:#1b5fc4;text-decoration:underline">${ze(s)}</a>`):r}),o=Xe(o),o=o.replace(/\*\*([^*]+?)\*\*/g,"<strong>$1</strong>").replace(/__([^_]+?)__/g,"<strong>$1</strong>").replace(/~~([^~]+?)~~/g,"<del>$1</del>").replace(/(^|[^*])\*(?!\s)([^*]+?)\*/g,"$1<em>$2</em>").replace(/(^|[^\w_])_(?!\s)([^_]+?)_/g,"$1<em>$2</em>"),o=o.replace(new RegExp(`${At}(\\d+)${At}`,"g"),(r,s)=>e[Number(s)]),o}function de(t,e,i){const o=document.createElement(t);return Object.assign(o.style,e),i!==void 0&&(o.innerHTML=i),o}var mo=/^ {0,3}([-*_])( *\1){2,} *$/,go=/^ {0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,ho=/^ {0,3}(```+|~~~+)/,Ot=/^ {0,3}>\s?/,Ye=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,bi=["20px","18px","16px","15px","14px","13px"],sn=t=>t.match(/^\s*/)?.[0].length??0;function xi(t){return t.trim()===""||mo.test(t)||go.test(t)||ho.test(t)||Ot.test(t)||Ye.test(t)}function bo(t){const e=t[0].match(Ye),i=e[1].length,o=/\d/.test(e[2]),r=de(o?"ol":"ul",{margin:"0 0 8px 0",paddingLeft:"20px",listStyleType:o?"decimal":"disc",listStylePosition:"outside"});let s=0;for(;s<t.length;){const c=t[s].match(Ye),d=[];for(s++;s<t.length&&sn(t[s])>i;)d.push(t[s]),s++;const h=de("li",{display:"list-item",margin:"2px 0",lineHeight:"1.6"}),f=c[3].match(/^\[([ xX])\]\s+(.*)$/);f?(h.style.listStyleType="none",h.style.marginLeft="-20px",h.innerHTML=`<span style="margin-right:6px">${f[1].toLowerCase()==="x"?"☑":"☐"}</span>${ze(f[2])}`):h.innerHTML=ze(c[3]),d.filter(p=>Ye.test(p)).length>0&&h.appendChild(bo(d.filter(p=>p.trim()!==""))),r.appendChild(h)}return r}function yi(t){const e=d=>d.replace(/^\s*\|?/,"").replace(/\|?\s*$/,"").split("|").map(h=>h.trim()),i=de("div",{overflowX:"auto",margin:"0 0 8px 0"}),o=de("table",{borderCollapse:"collapse",width:"100%",fontSize:"13px"}),r=document.createElement("thead"),s=document.createElement("tr");for(const d of e(t[0]))s.appendChild(de("th",{border:"1px solid #dee3e8",padding:"6px 10px",textAlign:"left",backgroundColor:"#f5f7fa",fontWeight:"600"},ze(d)));r.appendChild(s),o.appendChild(r);const c=document.createElement("tbody");for(const d of t.slice(2)){const h=document.createElement("tr");for(const f of e(d))h.appendChild(de("td",{border:"1px solid #dee3e8",padding:"6px 10px"},ze(f)));c.appendChild(h)}return o.appendChild(c),i.appendChild(o),i}var Ci=t=>!!t&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(t);function Me(t){const e=document.createDocumentFragment(),i=t.replace(/\r\n?/g,`
|
|
2
2
|
`).split(`
|
|
3
|
-
`);let o=0;for(;o<i.length;){const s=i[o];if(s.trim()===""){o++;continue}const c=s.match(ho);if(c){const
|
|
4
|
-
`)))),e.appendChild(x);continue}if(mo.test(s)){e.appendChild(de("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),o++;continue}const d=s.match(go);if(d){const
|
|
5
|
-
`))),e.appendChild(p);continue}if(s.includes("|")&&Ci(i[o+1])){const m=[s,i[o+1]];for(o+=2;o<i.length&&i[o].includes("|")&&i[o].trim();)m.push(i[o]),o++;e.appendChild(yi(m));continue}if(Ye.test(s)){const m=[],p=sn(s);for(;o<i.length&&i[o].trim()!=="";)if(Ye.test(i[o])||sn(i[o])>p)m.push(i[o]),o++;else break;e.appendChild(bo(m));continue}const h=[s];for(o++;o<i.length&&!xi(i[o]);)h.push(i[o]),o++;e.appendChild(de("p",{margin:"0 0 8px 0",lineHeight:"1.6"},h.map(m=>ze(m)).join("<br>")))}const r=e.lastElementChild;return r&&(r.style.marginBottom="0"),e}function vi(t,e){const i=n.div({display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:e.isUser?"flex-end":"flex-start",maxWidth:"75%"});i.className="ago-message__attachments";for(const o of t){const r=_e.safeAttachmentUrl(o.url);if(_e.canInlineImage(o)&&r){const p=document.createElement("a");p.href=r,p.target="_blank",p.rel="noopener noreferrer",n.css(p,{display:"inline-block",textDecoration:"none"});const x=document.createElement("img");x.src=r,x.alt=o.name,x.loading="lazy",n.css(x,{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:`1px solid ${n.BORDER_COLOR}`,display:"block"}),p.appendChild(x),i.appendChild(p);continue}const s=r?document.createElement("a"):document.createElement("div");r&&s instanceof HTMLAnchorElement&&(s.href=r,s.target="_blank",s.rel="noopener noreferrer"),n.css(s,{display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:`1px solid ${n.BORDER_COLOR}`,backgroundColor:e.cardBackground,color:e.cardColor,fontSize:"13px",textDecoration:"none",maxWidth:"220px"});const c=document.createElement("span");c.textContent="📄",c.setAttribute("aria-hidden","true"),n.css(c,{fontSize:"16px",lineHeight:"1",flexShrink:"0"});const d=n.div({display:"flex",flexDirection:"column",minWidth:"0"}),h=n.div({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"});h.textContent=o.name,h.title=o.name,d.appendChild(h);const m=_e.formatFileSize(o.fileSize);if(m){const p=n.div({fontSize:"11px",color:n.MUTED_TEXT_COLOR});p.textContent=m,d.appendChild(p)}s.append(c,d),i.appendChild(s)}return i}function xo(t,e){const i=e.look==="embed",o=n.div({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:i?"16px":"10px"});o.className="ago-message__followups";for(const r of t){const s=document.createElement("button");if(s.type="button",s.className="ago-message__followup-btn",s.textContent=r,s.disabled=!e.enabled,n.css(s,i?{display:"inline-flex",alignItems:"center",padding:"8px",fontSize:"14px",lineHeight:"20px",font:"inherit",color:"#525252",backgroundColor:"#fff",border:"1px solid #e5e5e5",borderRadius:"12px",boxShadow:"0 1px 2px 0 rgba(0,0,0,0.05)",cursor:e.enabled?"pointer":"default",transition:"background-color 0.15s"}:{minHeight:"44px",padding:"6px 14px",fontSize:"14px",borderRadius:n.MESSAGE_RADIUS,border:`1px solid ${n.BORDER_COLOR}`,backgroundColor:n.PANEL_BACKGROUND,color:n.TEXT_COLOR,cursor:e.enabled?"pointer":"default",transition:"border-color 0.15s"}),e.handler){const c=e.handler;s.addEventListener("click",()=>c(r))}s.addEventListener("mouseenter",()=>{i?s.style.backgroundColor="#fafafa":s.style.borderColor=n.ACCENT_COLOR}),s.addEventListener("mouseleave",()=>{i?s.style.backgroundColor="#fff":s.style.borderColor=n.BORDER_COLOR}),o.appendChild(s)}return o}function Ei(t,e){const{isLast:i,isLastOfBlock:o,bubbleStyle:r,showAgentName:s,agentBubble:c,followUpEnabled:d,followUpHandler:h,isMobile:m,feedbackRow:p}=e,x=t.role==="user",I=r==="imessage",w=n.div({display:"flex",flexDirection:"column",alignItems:x?"flex-end":"flex-start",marginBottom:I&&!o?"2px":"16px"});if(w.className=`ago-message ago-message--${t.role}`,!x&&s&&t.agent){const E=n.div({fontSize:"13px",fontWeight:"500",color:n.TEXT_COLOR,marginBottom:"6px",padding:"0 4px"});E.className="ago-message__agent",E.textContent=t.agent.displayName||t.agent.name,w.appendChild(E)}if(!x&&t.sources&&t.sources.length>0){const E=n.div({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});E.className="ago-message__sources",t.sources.forEach((O,W)=>{const C=O.url?document.createElement("a"):document.createElement("div");O.url&&C instanceof HTMLAnchorElement&&(C.href=O.url,C.target="_blank",C.rel="noopener noreferrer"),n.css(C,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"8px",backgroundColor:n.PANEL_BACKGROUND,textDecoration:"none",color:n.TEXT_COLOR,fontSize:"12px",overflow:"hidden"});const F=n.div({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${n.ACCENT_COLOR}`,color:n.ACCENT_COLOR,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});F.textContent=String(W+1);const y=n.div({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});y.textContent=O.title,y.title=O.title,C.append(F,y),E.appendChild(C)}),w.appendChild(E)}if(t.attachments&&t.attachments.length>0&&w.appendChild(vi(t.attachments,{isUser:x,cardBackground:x?"rgba(255,255,255,0.12)":n.PANEL_BACKGROUND,cardColor:x?n.BRAND_TEXT_COLOR:n.TEXT_COLOR})),!x&&e.renderToolCall&&t.toolCalls?.length)for(const E of t.toolCalls){const O=e.renderToolCall(E,t);O&&w.appendChild(O)}const u=x||c||I,v=!!t.content||t.status==="IN_PROGRESS"||t.status==="WAITING_CLIENT",A=n.div({maxWidth:u?I||x?m?"88%":"75%":m?"92%":"85%":"100%",padding:u?"10px 14px":"2px 8px",borderRadius:I?n.MESSAGE_RADIUS_IMESSAGE:u?n.MESSAGE_RADIUS:"0",backgroundColor:x?n.BRAND_COLOR:u?n.AGENT_BUBBLE_BACKGROUND:"transparent",color:x?n.BRAND_TEXT_COLOR:n.TEXT_COLOR,overflowWrap:"break-word",textWrap:"pretty",fontSize:"16px",lineHeight:"1.6"});if(A.className="ago-message__content",I&&o){A.style.position="relative";const E=n.div({position:"absolute",zIndex:"0",bottom:"-2px",width:"20px",height:"20px",background:x?n.BRAND_COLOR:n.AGENT_BUBBLE_BACKGROUND});E.className="ago-message__tail";const O=n.div({position:"absolute",zIndex:"1",bottom:"-2px",width:"10px",height:"20px",background:n.MESSAGES_BACKGROUND});O.className="ago-message__tail-mask",x?(E.style.right="-8px",E.style.borderBottomLeftRadius="16px 14px",O.style.right="-10px",O.style.borderBottomLeftRadius="10px"):(E.style.left="-7px",E.style.borderBottomRightRadius="16px 14px",O.style.left="-10px",O.style.borderBottomRightRadius="10px"),A.append(E,O)}return t.content?A.appendChild(Me(t.content)):(t.status==="IN_PROGRESS"||t.status==="WAITING_CLIENT")&&A.appendChild(ki()),v&&w.appendChild(A),!x&&p&&w.appendChild(p),i&&t.followUpReplies&&t.followUpReplies.length>0&&w.appendChild(xo(t.followUpReplies,{enabled:d,handler:h,look:"classic"})),w}function wi(t){const e=n.div({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:n.MESSAGE_RADIUS,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});e.className="ago-form-notice",e.setAttribute("role","status");const i=document.createElement("span");i.textContent="✓",i.setAttribute("aria-hidden","true"),n.css(i,{fontWeight:"700"});const o=document.createElement("span");return o.textContent=t,e.append(i,o),e}function ki(){const t=n.div({display:"flex",gap:"4px",padding:"4px 0"});for(let e=0;e<3;e++){const i=n.div({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"currentColor",opacity:"0.55",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${e*.2}s`});t.appendChild(i)}return t}function _i(){const t="http://www.w3.org/2000/svg",e=document.createElementNS(t,"svg");e.setAttribute("width","26"),e.setAttribute("height","26"),e.setAttribute("viewBox","0 0 24 24"),e.setAttribute("fill","none");const i=document.createElementNS(t,"path");return i.setAttribute("d","M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"),i.setAttribute("stroke","currentColor"),i.setAttribute("stroke-width","2"),i.setAttribute("stroke-linecap","round"),i.setAttribute("stroke-linejoin","round"),e.appendChild(i),e}function Si(t){const e=document.createElement("button");if(e.type="button",e.className="ago-chat-widget-launcher",e.setAttribute("aria-label",`Open ${t.title}`),e.setAttribute("aria-expanded","false"),t.look==="classic"){if(n.css(e,{position:"fixed",bottom:"20px",[t.edge]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:n.BRAND_COLOR,color:n.BRAND_TEXT_COLOR,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:n.FONT_VAR}),t.icon){const r=document.createElement("img");r.src=t.icon,r.alt="",n.css(r,{width:"26px",height:"26px",objectFit:"contain"}),e.appendChild(r)}else e.appendChild(_i());return e.addEventListener("click",t.onClick),{el:e,setOpen:r=>{e.setAttribute("aria-expanded",r?"true":"false"),e.setAttribute("aria-label",`${r?"Close":"Open"} ${t.title}`)}}}n.css(e,{position:"fixed",bottom:"20px",[t.edge]:"20px",width:"54px",height:"54px",padding:"12px",margin:"0",boxSizing:"border-box",border:"none",borderRadius:"50%",backgroundColor:n.LAUNCHER_BACKGROUND,color:n.LAUNCHER_TEXT_COLOR,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",boxShadow:"0 4px 12px rgba(123, 123, 123, 0.3)",transition:"scale 0.2s ease",zIndex:"2147483001",transform:"translateZ(0)",backfaceVisibility:"hidden",willChange:"transform",contain:"layout style paint",fontFamily:n.FONT_VAR}),e.addEventListener("mouseenter",()=>{e.style.scale="1.1",e.style.boxShadow="0 6px 16px rgba(123, 123, 123, 0.4)"}),e.addEventListener("mouseleave",()=>{e.style.scale="1",e.style.boxShadow="0 4px 12px rgba(123, 123, 123, 0.3)"});let i,o;if(t.icon){const r=document.createElement("img");r.src=t.icon,r.alt="",n.css(r,{width:"32px",height:"32px",objectFit:"contain"}),i=r,o=n.launcherCloseIcon(),e.append(r,o)}else{const r=n.launcherIcon();i=r.querySelector('[data-ago-path="open"]'),o=r.querySelector('[data-ago-path="close"]'),e.appendChild(r)}return o.style.display="none",e.addEventListener("click",t.onClick),{el:e,setOpen:r=>{i.style.display=r?"none":"",o.style.display=r?"":"none",e.setAttribute("aria-expanded",r?"true":"false"),e.setAttribute("aria-label",`${r?"Close":"Open"} ${t.title}`)}}}function Ti(t){const e=n.div({marginBottom:"12px",display:"flex",flexWrap:"wrap",gap:"8px"});e.className="ago-message__attachments";for(const i of t.attachments??[]){const o=_e.safeAttachmentUrl(i.url),r=n.div({display:"flex",alignItems:"center",gap:"8px",backgroundColor:"#f3f4f6",borderRadius:"8px",padding:"8px 12px",fontSize:"14px",lineHeight:"20px",maxWidth:"100%",boxSizing:"border-box"});if(_e.canInlineImage(i)&&o){const s=document.createElement("a");s.href=o,s.target="_blank",s.rel="noopener noreferrer",n.css(s,{display:"flex",flexDirection:"column",gap:"4px",textDecoration:"none",color:"inherit"});const c=document.createElement("img");c.src=o,c.alt=i.name,c.loading="lazy",n.css(c,{height:"128px",maxWidth:"100%",objectFit:"contain",borderRadius:"4px",display:"block"});const d=n.div({fontSize:"12px",lineHeight:"16px",color:"#4b5563",maxWidth:"150px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});d.textContent=i.name,s.append(c,d),r.appendChild(s)}else{const s=o?document.createElement("a"):document.createElement("span");o&&s instanceof HTMLAnchorElement&&(s.href=o,s.target="_blank",s.rel="noopener noreferrer",s.download=i.name),n.css(s,{display:"flex",alignItems:"center",gap:"8px",textDecoration:"none",color:"inherit",minWidth:"0"});const c=document.createElement("span");c.textContent=i.name,c.title=i.name,n.css(c,{maxWidth:"150px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),s.append(n.downloadIcon({size:20}),c);const d=_e.formatFileSize(i.fileSize);if(d){const h=document.createElement("span");h.textContent=d,n.css(h,{fontSize:"12px",lineHeight:"16px",color:"#6b7280"}),s.appendChild(h)}r.appendChild(s)}e.appendChild(r)}return e}function Ri(t){const e=n.div({display:"flex",justifyContent:"flex-end"}),i=n.div({maxWidth:"70%",borderRadius:"16px",marginBottom:"16px",padding:"16px",backgroundColor:n.USER_BUBBLE_BACKGROUND_EMBED,color:n.USER_BUBBLE_TEXT_EMBED,boxSizing:"border-box",fontSize:"14px",lineHeight:"24px"});i.className="ago-message__content",t.attachments?.length&&i.appendChild(Ti(t));const o=n.div({whiteSpace:"pre-wrap",overflowWrap:"break-word"});return o.textContent=t.content,i.appendChild(o),e.appendChild(i),e}function Ai(t){const e=n.div({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px",paddingBottom:"16px"});return e.className="ago-message__sources",(t.sources??[]).forEach((i,o)=>{const r=i.url?document.createElement("a"):document.createElement("div");i.url&&r instanceof HTMLAnchorElement&&(r.href=i.url,r.target="_blank",r.rel="noopener noreferrer"),n.css(r,{display:"inline-flex",alignItems:"center",height:"48px",justifyContent:"flex-start",padding:"8px 16px",border:`1px solid ${n.NEUTRAL_BORDER}`,backgroundColor:"#fff",borderRadius:"6px",boxShadow:n.SHADOW_SM,fontSize:"14px",fontWeight:"500",color:n.TEXT_COLOR,textDecoration:"none",overflow:"hidden",boxSizing:"border-box",transition:"background-color 0.15s"}),r.addEventListener("mouseenter",()=>{r.style.backgroundColor="#f5f5f5"}),r.addEventListener("mouseleave",()=>{r.style.backgroundColor="#fff"});const s=n.div({display:"flex",alignItems:"center",gap:"8px",width:"100%",minWidth:"0"}),c=n.div({flexShrink:"0",width:"16px",height:"16px",borderRadius:"4px",border:`1px solid ${n.PRIMARY_ACCENT}`,color:n.PRIMARY_ACCENT,backgroundColor:n.PRIMARY_FOREGROUND,fontSize:"12px",lineHeight:"1",display:"flex",alignItems:"center",justifyContent:"center"});c.textContent=String(o+1);const d=n.div({fontSize:"12px",lineHeight:"16px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:"0"});d.textContent=i.title,d.title=i.title,s.append(c,d),r.appendChild(s),e.appendChild(r)}),e}function Oi(t,e){return yo({errorTitle:t,errorDescription:e})}function yo(t){const e=n.div({position:"relative",width:"100%",borderRadius:"12px",border:"1px solid rgba(239, 68, 68, 0.5)",padding:"12px 16px 12px 44px",fontSize:"14px",lineHeight:"20px",color:"#ef4444",backgroundColor:"#fff",boxSizing:"border-box"});e.className="ago-message__error",e.setAttribute("role","alert");const i=n.alertCircleIcon({size:16});n.css(i,{position:"absolute",left:"16px",top:"16px"});const o=document.createElement("h5");o.textContent=t.errorTitle,n.css(o,{margin:"0 0 4px",fontSize:"14px",fontWeight:"500",lineHeight:"1",letterSpacing:"-0.025em"});const r=n.div({fontSize:"14px",lineHeight:"1.625"});return r.textContent=t.errorDescription,e.append(i,o,r),e}function Li(){const t=n.div({marginTop:"4px",animation:"ago-skeleton-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"});t.className="ago-message__skeleton";const e=n.div({height:"16px",backgroundColor:"#f1f5f9",borderRadius:"4px",width:"75%",marginBottom:"10px"});return t.appendChild(e),t}function Ni(){const t=n.div({display:"flex",alignItems:"center",padding:"8px",gap:"8px"});t.className="ago-message__spinner";const e=n.spokeSpinnerIcon({size:20});return n.css(e,{color:"#a1a1aa",animation:"ago-spin 1s linear infinite"}),t.appendChild(e),t}function Fi(t,e){const i=t.status==="IN_PROGRESS"||t.status==="WAITING_CLIENT",o=n.div({position:"relative",display:"flex",alignItems:"flex-start",borderRadius:"16px",padding:"8px",marginBottom:"16px",boxSizing:"border-box"});o.className="ago-message__row",e.agentRowTinted&&(o.style.backgroundColor=n.AGENT_BUBBLE_BACKGROUND),e.agentRowTextTinted&&(o.style.color=n.AGENT_BUBBLE_TEXT);const r=n.div({flex:"1",minWidth:"0",overflow:"hidden",padding:"0 4px",fontSize:"14px",lineHeight:"24px"});if(r.className="ago-message__body",i&&r.appendChild(Ni()),t.sources?.length&&r.appendChild(Ai(t)),e.renderToolCall&&t.toolCalls?.length)for(const s of t.toolCalls){const c=e.renderToolCall(s,t);c&&r.appendChild(c)}if(t.status==="ERROR")r.appendChild(yo(e.labels));else if(t.content){const s=n.div({});s.className="ago-message__markdown ago-message__content",s.appendChild(Me(t.content)),r.appendChild(s)}else i&&r.appendChild(Li());return e.isLast&&t.status==="DONE"&&t.followUpReplies?.length&&r.appendChild(xo(t.followUpReplies,{enabled:e.followUpEnabled,handler:e.followUpHandler,look:"embed"})),e.actionsRow&&!i&&r.appendChild(e.actionsRow),o.appendChild(r),o}function Ii(t,e){const i=n.div({});return i.className=`ago-message ago-message--${t.role}`,i.dataset.messageId=t.id,i.dataset.messageRole=t.role,i.appendChild(t.role==="user"?Ri(t):Fi(t,e)),i}var ln="ago-hs-form-ready";function Di(t,e){const i=t.tagName==="TEXTAREA"?Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,"value"):Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value"),o=t._valueTracker;o&&o.setValue(""),t.focus(),t.dispatchEvent(new Event("focus",{bubbles:!0})),i?.set?i.set.call(t,e):t.value=e,t.setAttribute("value",e),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})),t.dispatchEvent(new Event("blur",{bubbles:!0}))}function Nt(t,e){const i=t.querySelectorAll("input, textarea, select");let o=!1;for(const r of i){if(r.type==="hidden"||r.type==="submit"||r.type==="button")continue;const s=e[r.name]??(r.name.includes("/")?e[r.name.split("/").pop()]:void 0);s&&!r.value&&(Di(r,s),o=!0)}return o}function Bi(t){return`function($f){document.dispatchEvent(new CustomEvent(${JSON.stringify(ln)},{detail:{token:${JSON.stringify(t)},form:$f}}))}`}function Hi(t,e,i){return!t||!e||Object.keys(e).length===0?t:/hbspt\.forms\.create\s*\(\s*\{/.test(t)&&!/onFormReady/.test(t)?t.replace(/hbspt\.forms\.create\s*\(\s*\{/g,`hbspt.forms.create({onFormReady:${Bi(i)},`):t}function zi(t,e){if(!t||Object.keys(t).length===0)return()=>{};const i={};for(const[c,d]of Object.entries(t))d!=null&&d!==""&&(i[c]=d);const o=[],r=[],s=c=>{const d=c.detail;if(!d||d.token!==e)return;const h=d.form,m=h&&typeof h=="object"&&"jquery"in h&&h.jquery?h[0]:h;if(!m||typeof m.querySelectorAll!="function")return;Nt(m,i);const p=new MutationObserver(()=>{Nt(m,i)});p.observe(m,{childList:!0,subtree:!0}),o.push(p),r.push(setTimeout(()=>p.disconnect(),1e4))};return document.addEventListener(ln,s),()=>{document.removeEventListener(ln,s),o.forEach(c=>c.disconnect()),r.forEach(c=>clearTimeout(c))}}function Co(){return globalThis.HubSpotFormsV4}async function vo(t,e){let i=null;if(t.getFormFieldValues)try{const o=await t.getFormFieldValues();let r=[];Array.isArray(o)?r=o.filter(s=>typeof s=="object"&&s!==null).map(s=>s.name).filter(s=>typeof s=="string"):typeof o=="object"&&o!==null&&(r=Object.keys(o)),r.length>0&&(i=r)}catch{}for(const[o,r]of Object.entries(e)){if(!r)continue;let s;if(o.includes("/"))s=o;else if(i){const c=i.find(d=>d.endsWith("/"+o));if(!c)continue;s=c}else s=`0-1/${o}`;try{t.setFieldValue(s,r)}catch{}}}function ro(t){if(!t||Object.keys(t).length===0)return()=>{};const e=i=>{try{const o=Co()?.getFormFromEvent?.(i);if(!o?.setFieldValue)return;vo(o,t)}catch{}};return window.addEventListener("hs-form-event:on-ready",e),()=>window.removeEventListener("hs-form-event:on-ready",e)}function Mi(t){const e=Co()?.getForms?.();if(!Array.isArray(e)||e.length===0)return!1;for(const i of e)i?.setFieldValue&&vo(i,t);return!0}var dn="ago-hs-form-submit",cn="ago-hs-form-submitted";function Lt(t){if(!t||typeof t!="object")return t;let e;if(Array.isArray(t)){e={};for(const o of t)o&&typeof o=="object"&&"name"in o&&o.name&&o.value!==void 0&&(e[o.name]=o.value)}else e=t;const i={};for(const[o,r]of Object.entries(e)){const s=o.replace(/^\d+-\d+\//,"");s.startsWith("hs_")||s.startsWith("HS_")||s==="LEGAL_CONSENT"||s==="legal_consent"||s!=="goToWebinarWebinarKey"&&(r===""||r===null||r===void 0||typeof r=="string"&&r.length>2e3||(i[s]=r))}return Object.keys(i).length>0?i:null}function $i(t){try{const e=new FormData(t),i={};return e.forEach((o,r)=>{o instanceof File||(i[r]=o)}),Object.keys(i).length>0?i:null}catch{return null}}function ao(t,e,i){const o=i?`{token:${JSON.stringify(e)},form:$f}`:`{token:${JSON.stringify(e)}}`;return`function(${i?"$f":""}){document.dispatchEvent(new CustomEvent(${JSON.stringify(t)},{detail:${o}}))}`}function Ui(t,e){return t&&(/hbspt\.forms\.create\s*\(\s*\{/.test(t)&&!t.includes("ago-hs-form-submitted")?t.replace(/hbspt\.forms\.create\s*\(\s*\{/g,`hbspt.forms.create({onFormSubmit:${ao(dn,e,!0)},onFormSubmitted:${ao(cn,e,!1)},`):t)}function Wi(t,e,i,o){let r=!1,s=null;function c(){r||(r=!0,e(Lt(s)))}function d(u){if(s||(s=$i(u)),u.closest(".hs-form, .hbspt-form, [data-hs-forms]")){i?.();return}c()}const h=u=>{const v=u.target;v?.tagName==="FORM"&&d(v)};t.addEventListener("submit",h,!0);const m=new WeakSet;function p(u){m.has(u)||(m.add(u),u.addEventListener("submit",()=>d(u)))}for(const u of t.querySelectorAll("form"))p(u);const x=new MutationObserver(()=>{for(const u of t.querySelectorAll("form"))p(u)});x.observe(t,{childList:!0,subtree:!0});const I=u=>{const v=u.detail;if(!(!v||v.token!==o))try{const A=v.form,E=A&&typeof A=="object"&&"jquery"in A&&A.jquery?A[0]:A;if(E?.querySelectorAll){const O=E.querySelectorAll("input, textarea, select"),W={};for(const C of O)C.name&&C.type!=="submit"&&C.type!=="button"&&(W[C.name]=C.value||"");Object.keys(W).length>0&&(s=W)}}catch{}},w=u=>{const v=u.detail;!v||v.token!==o||c()};return document.addEventListener(dn,I),document.addEventListener(cn,w),()=>{t.removeEventListener("submit",h,!0),x.disconnect(),document.removeEventListener(dn,I),document.removeEventListener(cn,w)}}function ie(t){return t.externalId||t.id}function Eo(t){return t.conditionalFieldValues?.length?t.conditionalFieldValues:t.conditionalFieldValue?.split(",").map(e=>e.trim()).filter(Boolean)??[]}function mn(t,e){return!t.priorityTypologies?.length||!e||t.priorityTypologies.includes(e)}function wo(t,e,i,o,r,s){if(!e||!i.length)return!0;const c=t.fields.find(d=>d.id===e||d.externalId===e);return c?Ft(t,c,o,r,s)&&i.includes(o[ie(c)]):!0}function Ft(t,e,i,o="",r=new Set){if(e.active===!1||r.has(e.id)||e.title==="Priority"&&!mn(t,o))return!1;const s=new Set(r).add(e.id);return wo(t,e.conditionalFieldId,Eo(e),i,o,s)}function ko(t,e,i,o=""){return e.options.filter(r=>wo(t,r.conditionalFieldId,r.conditionalFieldValues??[],i,o,new Set)).sort((r,s)=>(r.position??0)-(s.position??0))}function Ke(t,e,i=""){let o;do{o=!1;for(const r of t.fields){const s=ie(r);if(!(s in e))continue;const c=!r.options.length||!e[s]||ko(t,r,e,i).some(d=>(d.value??d.name??"")===e[s]);(!Ft(t,r,e,i)||!c)&&(delete e[s],o=!0)}}while(o)}function Pi(t,e,i=""){const o=[...t.fields].sort((r,s)=>r.position-s.position).filter(r=>!r.hidden&&Ft(t,r,e,i));return o.filter((r,s)=>{if(s===0||r.alwaysVisible||r.conditionalFieldId&&Eo(r).length)return!0;const c=o[s-1];return c.type==="checkbox"||!!e[ie(c)]?.trim()})}var ji="var(--ago-send-button-background, var(--ago-accent-color, #003edf))",Gi=/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z]{2,}$/;function Vi(t){return t.toLowerCase().trim().replace(/[^a-z0-9_]/g,"_")}function _o(t,e,i){const o={};if(e){for(const r of e.fields){if(r.active===!1)continue;const s=r.options.find(c=>c.default);s&&(o[ie(r)]=s.value??s.name??"")}if(t?.tag)for(const r of e.fields)r.type==="tagger"&&(o[ie(r)]=t.tag);if(t?.custom_fields)for(const[r,s]of Object.entries(t.custom_fields)){const c=e.fields.find(d=>d.externalId===r||d.id===r||(d.title?Vi(d.title)===r:!1));c&&(o[ie(c)]=s)}}return e&&Ke(e,o,t?.typology??"Question"),{ticket:{subject:t?.subject??"",typology:t?.typology??"Question",priority:t?.priority??"Normal",body:t?.body??"",tag:t?.tag??""},customFields:o,files:[],email:i,errors:{},submittedOnce:!1,loading:!1,submitError:null}}function qi(t,e,i){t.customFields={..._o(e,i,t.email).customFields,...t.customFields},Ke(i,t.customFields,t.ticket.typology)}function so(t,e){return t.replace(/\{(\w+)\}/g,(i,o)=>e[o]??"")}function Xi(t,e,i,o){const r={},s=e.ticket;t.showSubject&&!s.subject.trim()&&(r.subject=i.subjectRequired),t.showTypology&&!s.typology.trim()&&(r.typology=i.typologyRequired),t.showPriority&&mn(t,s.typology)&&!s.priority.trim()&&(r.priority=i.priorityRequired),t.showBody&&!s.body.trim()&&(r.body=i.detailedContextRequired);for(const c of t.fields){if(c.hidden||!Ft(t,c,e.customFields,s.typology))continue;const d=e.customFields[ie(c)];if(c.required&&!d?.trim())r[ie(c)]=so(i.fieldRequired,{fieldTitle:c.title??""});else if(c.regexpForValidation&&d?.trim())try{new RegExp(c.regexpForValidation).test(d)||(r[ie(c)]=so(i.fieldFormatInvalid,{fieldTitle:c.title??""}))}catch{}}return o&&(e.email.trim()?Gi.test(e.email)||(r.userEmail=i.emailInvalid):r.userEmail=i.emailRequired),r}var Ki={border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"4px",width:"100%",padding:"8px",boxSizing:"border-box",fontSize:"16px",lineHeight:"24px",fontFamily:n.FONT_VAR,color:n.TEXT_COLOR,backgroundColor:n.PANEL_BACKGROUND};function De(t,e){const i=document.createElement("label");return i.htmlFor=e,i.textContent=t,n.css(i,{display:"block",fontWeight:"600"}),i}function he(t){const e=document.createElement("p");return e.className="ago-ticket-form__error",e.textContent=t,n.css(e,{color:"#ef4444",fontSize:"14px",lineHeight:"20px",margin:"0"}),e}function Be(){const t=n.div({display:"flex",flexDirection:"column",gap:"8px"});return t.className="ago-ticket-form__field",t}function He(t,e,i){n.css(t,Ki),e&&(t.style.borderColor="#ef4444"),t.disabled=i,i&&(t.style.opacity="0.5",t.style.cursor="not-allowed"),t.addEventListener("focus",()=>{t.style.outline="2px solid var(--ago-accent-color, #003edf)",t.style.outlineOffset="1px"}),t.addEventListener("blur",()=>{t.style.outline="",t.style.outlineOffset=""})}function So(t){const e=n.div({padding:"16px",borderRadius:"4px",backgroundColor:"#dcfce7",color:"#166534",fontSize:"16px",lineHeight:"24px"});e.className="ago-ticket-form__success",e.setAttribute("role","status");const i=document.createElement("p");if(i.textContent=t.text,n.css(i,{whiteSpace:"pre-line",margin:"0"}),e.appendChild(i),t.ticketUrl){const o=n.div({marginTop:"4px"});if(o.append(document.createTextNode(`${t.urlLabel} `)),t.ticketUrl.startsWith("http")){const r=document.createElement("a");r.href=t.ticketUrl,r.target="_blank",r.rel="noreferrer noopener",r.textContent=t.ticketUrl,n.css(r,{fontWeight:"700",textDecoration:"underline",color:"#166534"}),o.appendChild(r)}else{const r=document.createElement("span");r.textContent=t.ticketUrl,r.style.fontWeight="700",o.appendChild(r)}e.appendChild(o)}return e}function Yi(t){const e=n.div({width:"100%",padding:"16px",backgroundColor:"#fefce8",border:"1px solid #fef08a",borderRadius:"6px",display:"flex",gap:"12px",alignItems:"flex-start",color:"#854d0e",boxSizing:"border-box",fontSize:"16px",lineHeight:"24px"});e.className="ago-ticket-form__denied";const i=document.createElement("span");i.textContent="i",i.setAttribute("aria-hidden","true"),n.css(i,{flexShrink:"0",width:"20px",height:"20px",marginTop:"2px",borderRadius:"50%",border:"2px solid #ca8a04",color:"#ca8a04",fontSize:"13px",fontWeight:"700",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:"1"});const o=n.div({minWidth:"0"});return o.appendChild(Me(t)),e.append(i,o),e}function Qi(t){const{state:e,labels:i}=t;let o=t.ticketForm,r=t.configLoading,s=t.allowFiles;const c=n.div({position:"relative",width:"100%",display:"flex",flexDirection:"column",gap:"16px",paddingBottom:"16px",fontSize:"16px",lineHeight:"24px",color:n.TEXT_COLOR,boxSizing:"border-box"});c.className="ago-ticket-form";function d(){return o?(e.errors=Xi(o,e,i,t.requireEmail),Object.keys(e.errors).length===0):!1}async function h(){if(!(e.loading||!o)){if(Ke(o,e.customFields,e.ticket.typology),e.submittedOnce=!0,e.submitError=null,!d()){e.submitError=`${i.validationFailed}: ${i.pleaseCheckFields}`,w();return}e.loading=!0,w();try{const u=await t.createTicket({subject:e.ticket.subject,typology:e.ticket.typology||"Question",priority:e.ticket.priority||"Normal",body:e.ticket.body,files:e.files,customFields:Object.entries(e.customFields).map(([v,A])=>({id:v,value:A})),email:t.requireEmail?e.email:void 0,ticketFormId:o.id});e.loading=!1,e.submitted={ticketId:u.id,ticketUrl:u.url},w(),t.onCreated(u,e)}catch(u){e.loading=!1;const v=u instanceof Error?u:new Error(String(u)),A=v.status;let E=i.submissionFailed,O=i.submissionFailedDescription;A===413?E=i.fileTooLarge:A===403?E=i.permissionDenied:A===422?(E=i.validationFailed,O=v.message||i.pleaseCheckFields):v.message&&(O=v.message),e.submitError=`${E}: ${O}`,w(),t.onError?.(v)}}}function m(u,v){const A=ie(u);e.customFields[A]=v,o&&Ke(o,e.customFields,e.ticket.typology),e.submittedOnce&&d(),w()}function p(){e.submittedOnce&&d()}function x(u){const v=ie(u),A=`ago-ticket-field-${v}`,E=e.customFields[v]??"",O=e.loading,W=e.errors[v];if(u.type==="checkbox"){const k=n.div({display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"});k.className="ago-ticket-form__field";const S=document.createElement("input");S.type="checkbox",S.id=A,S.checked=E==="true",S.disabled=O,n.css(S,{width:"16px",height:"16px",margin:"0"}),S.addEventListener("change",()=>m(u,S.checked?"true":"false"));const D=document.createElement("label");return D.htmlFor=A,D.textContent=u.title??"",D.style.fontWeight="600",k.append(S,D),W&&k.appendChild(he(W)),k}const C=Be();C.appendChild(De(u.title??"",A));const F=ko(o,u,e.customFields,e.ticket.typology).filter(k=>!k.noDisplay);if(u.options.length>0){const k=document.createElement("select");k.id=A;const S=document.createElement("option");S.value="",S.textContent="----",k.appendChild(S);const D=new Map;for(const M of F){const j=document.createElement("option");if(j.value=M.value??M.name??"",j.textContent=M.name??M.value??"",M.group){let b=D.get(M.group);b||(b=document.createElement("optgroup"),b.label=M.group,D.set(M.group,b),k.appendChild(b)),b.appendChild(j)}else k.appendChild(j)}k.value=E,He(k,!!W,O),k.addEventListener("change",()=>m(u,k.value)),C.appendChild(k);const V=F.find(M=>(M.value??M.name)===E);if(W&&C.appendChild(he(W)),V?.message){const M={info:{bg:"#eff6ff",border:"#bfdbfe",text:"#1e3a8a"},warning:{bg:"#fffbeb",border:"#fcd34d",text:"#78350f"},danger:{bg:"#fef2f2",border:"#fca5a5",text:"#7f1d1d"}}[V.messageType??"info"],j=document.createElement("p");j.className="ago-ticket-form__option-message",j.textContent=V.message,n.css(j,{fontSize:"14px",lineHeight:"20px",border:`1px solid ${M.border}`,backgroundColor:M.bg,color:M.text,borderRadius:"4px",padding:"8px",whiteSpace:"pre-line",margin:"0"}),C.appendChild(j)}return C}const y=document.createElement("input");return y.type="text",y.id=A,y.value=E,He(y,!!W,O),y.addEventListener("input",()=>{e.customFields[v]=y.value,o&&Ke(o,e.customFields,e.ticket.typology),e.submittedOnce&&(d(),I())}),y.addEventListener("change",()=>w()),C.appendChild(y),W&&C.appendChild(he(W)),C}function I(){for(const u of c.querySelectorAll("[data-ago-error-for]")){const v=u.dataset.agoErrorFor,A=u.querySelector(".ago-ticket-form__error"),E=e.errors[v],O=u.querySelector("input, select, textarea");O&&(O.style.borderColor=E?"#ef4444":""),O&&!E&&(O.style.border=`1px solid ${n.BORDER_COLOR}`),E&&!A?u.appendChild(he(E)):E&&A?A.textContent=E:!E&&A&&A.remove()}}function w(){if(c.replaceChildren(),t.message){const b=n.div({fontWeight:"500",color:"#1e40af",backgroundColor:"#eff6ff",padding:"12px",borderRadius:"4px"});b.className="ago-ticket-form__message",b.textContent=t.message,c.appendChild(b)}if(e.submitted){c.appendChild(So({text:t.successMessage||o?.successMessageText||i.ticketSubmitted,ticketUrl:e.submitted.ticketUrl,urlLabel:t.successUrlLabel||o?.successMessageUrlLabel||i.findTicketHere}));return}if(r){const b=n.div({padding:"16px",textAlign:"center",fontWeight:"700",fontSize:"20px"});b.className="ago-ticket-form__config-loading",b.setAttribute("role","status"),b.textContent=i.loading,c.appendChild(b);return}if(!o){const b=n.div({backgroundColor:"#fee2e2",color:"#991b1b",padding:"16px",borderRadius:"4px"});b.className="ago-ticket-form__missing",b.textContent=i.noTicketForm,c.appendChild(b);return}const u=o,v=e.loading;if(e.loading){const b=n.div({position:"absolute",inset:"0",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(255, 255, 255, 0.7)",zIndex:"5",borderRadius:"16px",fontSize:"20px",fontWeight:"700"});b.className="ago-ticket-form__loading",b.setAttribute("role","status"),b.textContent=i.loading,c.appendChild(b)}const A=n.div({fontWeight:"600",backgroundColor:"#bfdbfe",padding:"16px",borderRadius:"4px"});if(A.className="ago-ticket-form__intro",A.textContent=i.useFormToCreateTicket,c.appendChild(A),t.requireEmail){const b=Be();b.dataset.agoErrorFor="userEmail",b.appendChild(De(`${i.yourEmail} *`,"ago-ticket-email"));const R=document.createElement("input");R.type="email",R.id="ago-ticket-email",R.placeholder=i.emailPlaceholder,R.value=e.email,He(R,!!e.errors.userEmail,v),R.addEventListener("input",()=>{e.email=R.value,e.submittedOnce&&(d(),I())}),b.appendChild(R),e.errors.userEmail&&b.appendChild(he(e.errors.userEmail)),c.appendChild(b)}const E=u.showSubject&&!!e.ticket.subject||!u.showSubject,O=E&&(!!e.ticket.typology||!u.showTypology),W=u.showPriority&&mn(u,e.ticket.typology),C=O&&(!!e.ticket.priority||!W);if(u.showSubject){const b=Be();b.dataset.agoErrorFor="subject",b.appendChild(De(i.subject,"ago-ticket-subject"));const R=document.createElement("input");R.type="text",R.id="ago-ticket-subject",R.value=e.ticket.subject,He(R,!!e.errors.subject,v),R.addEventListener("input",()=>{e.ticket.subject=R.value,p(),I()}),R.addEventListener("change",()=>w()),b.appendChild(R),e.errors.subject&&b.appendChild(he(e.errors.subject)),c.appendChild(b)}if(E&&u.showTypology){const b=Be();b.dataset.agoErrorFor="typology",b.appendChild(De(i.typology,"ago-ticket-typology"));const R=document.createElement("select");R.id="ago-ticket-typology";for(const[z,J]of[["",i.selectTypology],["Question",i.question],["Task",i.task],["Incident",i.incident]]){const Y=document.createElement("option");Y.value=z,Y.textContent=J,R.appendChild(Y)}R.value=e.ticket.typology,He(R,!!e.errors.typology,v),R.addEventListener("change",()=>{e.ticket.typology=R.value,Ke(u,e.customFields,e.ticket.typology),p(),w()}),b.appendChild(R),e.errors.typology&&b.appendChild(he(e.errors.typology)),c.appendChild(b)}if(O&&W){const b=Be();b.dataset.agoErrorFor="priority",b.appendChild(De(i.priority,"ago-ticket-priority"));const R=document.createElement("select");R.id="ago-ticket-priority";for(const[z,J]of[["",i.selectPriority],["Low",i.low],["Normal",i.normal],["High",i.high],["Urgent",i.urgent]]){const Y=document.createElement("option");Y.value=z,Y.textContent=J,R.appendChild(Y)}R.value=e.ticket.priority,He(R,!!e.errors.priority,v),R.addEventListener("change",()=>{e.ticket.priority=R.value,p(),w()}),b.appendChild(R),e.errors.priority&&b.appendChild(he(e.errors.priority)),c.appendChild(b)}if(C){const b=new Set(Pi(u,e.customFields,e.ticket.typology));for(const R of[...u.fields].sort((z,J)=>z.position-J.position)){if(!b.has(R)&&!e.errors[ie(R)])continue;const z=x(R);z.dataset.agoErrorFor=ie(R),c.appendChild(z)}}const F=Be();F.dataset.agoErrorFor="body",F.appendChild(De(i.detailedContext,"ago-ticket-body"));const y=document.createElement("textarea");y.id="ago-ticket-body",y.rows=4,y.value=e.ticket.body,He(y,!!e.errors.body,v),n.css(y,{resize:"vertical",maxHeight:"240px",overflowY:"auto"});const k=n.div({fontSize:"14px",lineHeight:"20px",marginTop:"4px",textAlign:"right",display:"none"});k.className="ago-ticket-form__counter";const S=()=>{const b=e.ticket.body.length;k.style.display=b>6e4?"block":"none",k.style.color=b>65535?"#dc2626":"#d97706",k.textContent=`${b} / 65,535 · ${i.maxCharacters}`},D=()=>{y.style.height="auto",y.style.height=`${y.scrollHeight}px`};if(y.addEventListener("input",()=>{e.ticket.body=y.value,p(),I(),S(),D()}),F.append(y,k),S(),e.errors.body&&F.appendChild(he(e.errors.body)),c.appendChild(F),s){const b=Be();b.className="ago-ticket-form__field ago-ticket-form__attachments",b.appendChild(De(i.attachments,"ago-ticket-files"));const R=document.createElement("label");R.htmlFor="ago-ticket-files",R.textContent=i.selectFile,n.css(R,{display:"inline-block",alignSelf:"flex-start",backgroundColor:"#e5e7eb",padding:"8px 16px",borderRadius:"4px",cursor:"pointer",border:"1px solid #d1d5db",minHeight:"24px"});const z=document.createElement("input");z.type="file",z.id="ago-ticket-files",z.multiple=!0,z.disabled=v,n.css(z,{display:"none"}),z.addEventListener("change",()=>{e.files=[...e.files,...Array.from(z.files??[])],z.value="",w()}),b.append(R,z);const J=n.div({display:"flex",flexDirection:"column",gap:"4px"});e.files.forEach((Y,f)=>{const B=n.div({display:"flex",alignItems:"center",justifyContent:"space-between",backgroundColor:"#f3f4f6",padding:"4px 8px",borderRadius:"4px"}),G=document.createElement("span");G.textContent=`${Y.name} - ${(Y.size/1024).toFixed(1)} KB`;const P=document.createElement("button");P.type="button",P.textContent="×",P.setAttribute("aria-label",`Remove ${Y.name}`),P.disabled=v,n.css(P,{color:"#dc2626",fontWeight:"700",background:"none",border:"none",cursor:"pointer",fontSize:"18px",lineHeight:"1",width:"44px",height:"44px",margin:"-10px -12px -10px 0"}),P.addEventListener("click",()=>{e.files=e.files.filter((ee,re)=>re!==f),w()}),B.append(G,P),J.appendChild(B)}),b.appendChild(J),c.appendChild(b)}if(e.submitError){const b=he(e.submitError);b.setAttribute("role","alert"),b.className="ago-ticket-form__error ago-ticket-form__submit-error",c.appendChild(b)}const V=document.createElement("button");V.type="button",V.className="ago-ticket-form__submit",V.disabled=v,n.css(V,{width:"100%",backgroundColor:ji,color:n.BRAND_TEXT_COLOR,padding:"8px 16px",borderRadius:"4px",border:"none",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",cursor:v?"default":"pointer",fontSize:"16px",lineHeight:"24px",minHeight:"44px",font:"inherit",transition:"filter 0.15s"});const M=document.createElement("span");M.textContent=i.submit;const j=document.createElement("span");j.textContent="→",j.setAttribute("aria-hidden","true"),n.css(j,{fontSize:"20px",lineHeight:"1",transition:"transform 0.15s"}),V.append(M,j),V.addEventListener("mouseenter",()=>{V.style.filter="brightness(0.9)",j.style.transform="translateX(4px)"}),V.addEventListener("mouseleave",()=>{V.style.filter="",j.style.transform=""}),V.addEventListener("click",()=>{h()}),c.appendChild(V)}return w(),{el:c,rebuild:u=>{u&&"ticketForm"in u&&(o=u.ticketForm??null),u&&"configLoading"in u&&(r=!!u.configLoading),u&&"allowFiles"in u&&(s=!!u.allowFiles),w()}}}var Ji=0;async function Zi(t){const e=Array.from(t.querySelectorAll("script"));for(const i of e){const o=document.createElement("script");for(const r of Array.from(i.attributes))o.setAttribute(r.name,r.value);i.src?await new Promise((r,s)=>{o.onload=()=>r(),o.onerror=()=>s(new Error(`Failed to load script: ${i.src}`)),i.parentNode?.replaceChild(o,i)}):(o.textContent=i.textContent,i.parentNode?.replaceChild(o,i))}}function er(t,e){const i={};if(t)for(const[o,r]of Object.entries(t))if(o==="custom_fields"&&r&&typeof r=="object")for(const[s,c]of Object.entries(r))c&&(i[s]=c);else typeof r=="string"&&r&&(i[o]=r);return e&&(i.email=e),Object.keys(i).length>0?i:null}function tr(t){const e=n.div({fontWeight:"500",color:"#1e40af",backgroundColor:"#eff6ff",padding:"12px",borderRadius:"4px",fontSize:"16px",lineHeight:"24px"});return e.className="ago-ticket-form__message",e.textContent=t,e}function nr(t){const{state:e,labels:i}=t,o=`ago-embed-${Date.now().toString(36)}-${++Ji}`,r=n.div({display:"flex",flexDirection:"column",gap:"16px"});r.className="ago-embed-form",t.message&&r.appendChild(tr(t.message));const s=n.div({display:"flex",flexDirection:"column",gap:"12px"});s.className="ago-embed-form__body",r.appendChild(s);const c=[];let d,h=!1,m=e.status==="submitted",p=null;const x=er(t.ticket,t.email),I=y=>{m||h||(m=!0,d&&(clearTimeout(d),d=void 0),e.status="submitted",e.captured=y??null,F(),t.onSubmitted(y??null))},w=()=>{m||d||(h=!1,d=setTimeout(()=>{m||(d=void 0,e.status="timeout",F())},3e4))},u=()=>{try{const y=globalThis.HubSpotFormsV4?.getForms?.()?.[0];if(y?.getFormFieldValues){const k=new Promise((S,D)=>setTimeout(()=>D(new Error("timeout")),3e3));Promise.race([y.getFormFieldValues(),k]).then(S=>I(Lt(S))).catch(()=>I(p));return}}catch{}I(p)};window.addEventListener("hs-form-event:on-submission:success",u),c.push(()=>window.removeEventListener("hs-form-event:on-submission:success",u));const v=[],A=y=>{const k=y.data;if(k?.type==="hsFormCallback"&&k.eventName==="onFormSubmit"){try{const S=k.data;if(Array.isArray(S)){const D={};for(const M of S)M?.name&&M.value!==void 0&&(D[M.name]=M.value);const V=Lt(D);V&&(p=V)}}catch{}return}if(k?.type==="hsFormCallback"&&k.eventName==="onFormSubmitted"){I(p);return}if(k?.type==="HS_CTA_PARENT_INIT"&&y.ports?.[0]){const S=y.ports[0],D=V=>{const M=V.data;if(M?.type==="HS_SEND_FORM_FIELD_VALUES"){const j=M.payload?.formFieldValues;if(j&&typeof j=="object"){const b=Lt(j);b&&(p=b)}}M?.type==="HS_SEND_FORM_SUBMISSION_SUCCESS"&&I(p)};S.addEventListener("message",D),S.start(),v.push(()=>S.removeEventListener("message",D))}};window.addEventListener("message",A),c.push(()=>{window.removeEventListener("message",A),v.forEach(y=>y())});let E;function O(y){if(!t.embedHtml)return;let k=Hi(t.embedHtml,x,o);k=Ui(k,o);const S=zi(x,o),D=ro(x);y.innerHTML=k;const V=Wi(y,I,w,o);let M,j,b;Zi(y).catch(()=>{}).then(()=>{e.status==="loading"&&(e.status="ready",W.style.display="none",x&&(Nt(y,x),Mi(x),b=ro(x),M=new MutationObserver(()=>Nt(y,x)),M.observe(y,{childList:!0,subtree:!0}),j=setTimeout(()=>M?.disconnect(),1e4)))}),E=()=>{S(),D(),V(),M?.disconnect(),j&&clearTimeout(j),b?.(),y.innerHTML=""}}const W=n.div({position:"absolute",inset:"0",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(255, 255, 255, 0.8)",zIndex:"10"});W.className="ago-embed-form__loading";const C=n.div({width:"24px",height:"24px",borderRadius:"50%",border:`2px solid ${n.EMBED_MUTED_TEXT}`,borderTopColor:"transparent",animation:"ago-spin 1s linear infinite"});C.setAttribute("role","status"),W.appendChild(C);function F(){if(s.replaceChildren(),e.status==="timeout"){const k=n.div({borderRadius:"8px",border:"1px solid #fef08a",backgroundColor:"#fefce8",padding:"16px",display:"flex",flexDirection:"column",gap:"12px"});k.className="ago-embed-form__timeout";const S=document.createElement("p");S.textContent=i.embedSubmitTimeout,n.css(S,{fontSize:"14px",lineHeight:"20px",color:"#854d0e",margin:"0"});const D=document.createElement("button");D.type="button",D.textContent=i.tryAgain,n.css(D,{alignSelf:"flex-start",fontSize:"14px",fontWeight:"500",color:"#854d0e",textDecoration:"underline",background:"none",border:"none",padding:"0",cursor:"pointer",minHeight:"44px",font:"inherit"}),D.addEventListener("click",()=>{h=!0,m=!1,d=void 0,e.status="ready",F()}),k.append(S,D),s.appendChild(k);return}if(e.status==="submitted"){s.appendChild(So({text:t.successMessage||i.embeddedFormSubmitted,urlLabel:i.findTicketHere}));return}if(t.description){const k=document.createElement("p");k.textContent=t.description,n.css(k,{fontSize:"14px",lineHeight:"20px",margin:"0"}),s.appendChild(k)}const y=n.div({position:"relative",borderRadius:"8px",border:`1px solid ${n.BORDER_COLOR}`,overflow:"hidden"});if(y.className="ago-embed-form__frame",t.embedHtml){W.style.display=e.status==="loading"?"flex":"none",y.appendChild(W);const k=n.div({width:"100%",minHeight:"200px"});k.className="ago-embed-form__host",y.appendChild(k),E?.(),O(k)}else{const k=n.div({padding:"24px",textAlign:"center",color:n.EMBED_MUTED_TEXT,fontSize:"14px"});k.textContent=i.noEmbedConfigured,y.appendChild(k)}s.appendChild(y)}return F(),{el:r,destroy:()=>{d&&clearTimeout(d),E?.(),c.forEach(y=>y())}}}function or(t){return t.type==="form"&&t.toolName==="ago_ticketing"}function ir(t){let e=null;for(const i of t)for(const o of i.toolCalls??[])o.type==="form"&&(e=o.id);return e}function rr(t){return t.some(e=>(e.toolCalls??[]).some(i=>{if(i.type!=="form")return!1;const o=i.data;return o?.success===!0&&!!o.ticket?.ticket_id}))}function lo(t){const e=t.data;return e?.success!==!0||!e.ticket?.ticket_id?null:{ticketId:String(e.ticket.ticket_id),ticketUrl:typeof e.ticket.ticket_url=="string"&&e.ticket.ticket_url?e.ticket.ticket_url:void 0}}var ar={info:{border:"#bfdbfe",bg:"#eff6ff",text:"#1e40af"},warning:{border:"#fef08a",bg:"#fefce8",text:"#854d0e"},success:{border:"#bbf7d0",bg:"#f0fdf4",text:"#166534"},error:{border:"#fecaca",bg:"#fef2f2",text:"#991b1b"}};function sr(t,e="info",i){const o=ar[e],r=n.div({margin:"8px 0",padding:"12px 16px",border:`1px solid ${o.border}`,backgroundColor:o.bg,color:o.text,borderRadius:"8px",display:"flex",alignItems:"flex-start",gap:"8px",fontSize:"14px",lineHeight:"20px"});if(r.className=`ago-toolcall-status ago-toolcall-status--${e}`,r.setAttribute("role","status"),i){const c=document.createElement("span");c.textContent=`${i}:`,n.css(c,{fontSize:"12px",fontWeight:"500",opacity:"0.7",flexShrink:"0"}),r.appendChild(c)}const s=document.createElement("span");return s.textContent=t,s.style.whiteSpace="pre-wrap",r.appendChild(s),r}function lr(t,e){const i=n.div({margin:"8px 0",padding:"12px 16px",border:"1px solid #e9d5ff",backgroundColor:"#faf5ff",color:"#6b21a8",borderRadius:"8px",display:"flex",flexDirection:"column",gap:"8px",fontSize:"14px",lineHeight:"20px"});i.className="ago-toolcall-form-placeholder";const o=n.div({display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"});if(t.toolName){const s=document.createElement("span");s.textContent=`${t.toolName}:`,n.css(s,{fontSize:"12px",fontWeight:"500",opacity:"0.7"}),o.appendChild(s)}if(t.message){const s=document.createElement("span");s.textContent=t.message,o.appendChild(s)}o.childElementCount>0&&i.appendChild(o);const r=n.div({opacity:"0.8"});if(r.textContent=e.genericFormComingSoon,t.formSchema){const s=document.createElement("pre");s.textContent=JSON.stringify(t.formSchema,null,2),n.css(s,{fontSize:"12px",lineHeight:"16px",marginTop:"8px",marginBottom:"0",whiteSpace:"pre-wrap",overflowWrap:"anywhere"}),r.appendChild(s)}return i.appendChild(r),i}var To={useFormToCreateTicket:"You can use the following form to create a ticket",yourEmail:"Your Email",emailPlaceholder:"Enter your email address",emailRequired:"Email is required",emailInvalid:"Please enter a valid email address",subject:"Subject",subjectRequired:"Subject is required.",typology:"Typology",selectTypology:"Select a typology",typologyRequired:"Typology is required.",question:"Question",task:"Task",incident:"Incident",priority:"Priority",selectPriority:"Select a priority",priorityRequired:"Priority is required.",low:"Low",normal:"Normal",high:"High",urgent:"Urgent",detailedContext:"Detailed context",detailedContextRequired:"Detailed context is required.",fieldRequired:"{fieldTitle} is required.",fieldFormatInvalid:"{fieldTitle} has an invalid format.",attachments:"Attachments",selectFile:"Select file",submit:"Submit",loading:"Loading...",maxCharacters:"Maximum characters",ticketSubmitted:"Your ticket has been successfully submitted.",findTicketHere:"You can find it here:",noTicketForm:"No ticket form found",notAllowed:"You are not allowed to create a ticket.",submissionFailed:"Failed to submit ticket",submissionFailedDescription:"There was an error submitting your ticket. Please try again.",fileTooLarge:"File too large",permissionDenied:"Permission denied",validationFailed:"Validation error",pleaseCheckFields:"Please check your form fields and try again.",embeddedFormSubmitted:"Your form has been submitted successfully.",noEmbedConfigured:"No embed URL or HTML configured for this form.",embedSubmitTimeout:"The form submission could not be confirmed. Please try again.",tryAgain:"Try again",contactFormCreated:"A new contact form has been created, see below to fill it out.",contactFormRejected:"You are not allowed to create a ticket. See below why.",genericFormComingSoon:"Generic form rendering (Coming soon)",unknownToolCall:"Unknown tool call type: {type}",formPending:"Please complete the form above to continue the conversation",ticketCreatedBlocked:`A ticket has been created for this conversation.
|
|
6
|
-
Please create a new conversation to continue.`,newConversation:"New conversation"},pn={helpful:"Helpful",notHelpful:"Not helpful",whatWentWrong:"What went wrong?",reasons:{inaccurate:"Inaccurate",incomplete:"Incomplete",information_not_found:"Information not found",technical_issue:"Technical issue"},commentPlaceholder:"Anything else? (optional)",send:"Send",thanks:"Thanks, this was reported."};function dr(){return{detailsOpen:!1,reasons:new Set,comment:"",reported:!1}}var cr={display:"inline-flex",alignItems:"center",justifyContent:"center",width:"44px",height:"44px",margin:"-8px",padding:"0",border:"none",borderRadius:"8px",background:"transparent",color:n.MUTED_TEXT_COLOR,cursor:"pointer",lineHeight:"1"};function pr(t){const{state:e,labels:i,askWhy:o,onRate:r,onReport:s}=t,c=t.look==="embed",d=c?{idle:"#78716c",hover:"#1c1917",active:"#1c1917"}:{idle:n.MUTED_TEXT_COLOR,hover:n.TEXT_COLOR,active:n.ACCENT_COLOR},h=n.div(c?{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px",width:"100%"}:{marginTop:"6px",width:"100%",maxWidth:"85%"});h.className="ago-feedback";const m=n.div({display:"flex",alignItems:"center",gap:c?"8px":"2px"});m.className="ago-feedback__actions";const p=co("up",i.helpful,e.rating==="positive",d,c);p.addEventListener("click",()=>{e.rating="positive",e.detailsOpen=!1,w(),u(),r("positive")});const x=co("down",i.notHelpful,e.rating==="negative",d,c);x.addEventListener("click",()=>{e.rating="negative",r("negative"),o&&!e.reported&&(e.detailsOpen=!0),w(),u()}),m.append(p,x),c&&h.appendChild(n.div({flex:"1"})),h.appendChild(m);const I=n.div();I.className="ago-feedback__panel-slot",c&&(I.style.flexBasis="100%"),h.appendChild(I);function w(){un(p,e.rating==="positive",d),un(x,e.rating==="negative",d)}function u(){if(I.replaceChildren(),e.reported){I.appendChild(mr(i.thanks));return}e.detailsOpen&&I.appendChild(fr(e,i,async v=>await s(e.rating??"negative",v)?(e.reported=!0,e.detailsOpen=!1,u(),!0):!1))}return w(),u(),h}function co(t,e,i,o,r=!1){const s=document.createElement("button");return s.type="button",s.className=`ago-feedback__thumb ago-feedback__thumb--${t}`,s.setAttribute("aria-label",e),s.title=e,n.css(s,cr),r?(s.style.margin="-14px",s.appendChild(t==="up"?n.thumbUpIcon({size:18}):n.thumbDownIcon({size:18}))):s.appendChild(ur(t)),un(s,i,o),s.addEventListener("mouseenter",()=>{s.getAttribute("aria-pressed")!=="true"&&(s.style.color=o.hover)}),s.addEventListener("mouseleave",()=>{s.getAttribute("aria-pressed")!=="true"&&(s.style.color=o.idle)}),s}function un(t,e,i){t.setAttribute("aria-pressed",e?"true":"false"),t.style.color=e?i.active:i.idle}function ur(t){const e="http://www.w3.org/2000/svg",i=document.createElementNS(e,"svg");i.setAttribute("width","16"),i.setAttribute("height","16"),i.setAttribute("viewBox","0 0 24 24"),i.setAttribute("fill","none"),i.setAttribute("aria-hidden","true");const o=document.createElementNS(e,"path");o.setAttribute("d","M7 22h9.3a2 2 0 0 0 2-1.7l1.4-9A2 2 0 0 0 17.7 9H14V5a3 3 0 0 0-3-3l-4 10z"),o.setAttribute("stroke","currentColor"),o.setAttribute("stroke-width","1.8"),o.setAttribute("stroke-linejoin","round");const r=document.createElementNS(e,"path");return r.setAttribute("d","M7 22V12H4.5A1.5 1.5 0 0 0 3 13.5v7A1.5 1.5 0 0 0 4.5 22z"),r.setAttribute("stroke","currentColor"),r.setAttribute("stroke-width","1.8"),r.setAttribute("stroke-linejoin","round"),i.append(o,r),t==="down"&&(i.style.transform="rotate(180deg)"),i}function fr(t,e,i){const o=n.div({marginTop:"8px",padding:"12px",border:`1px solid ${n.BORDER_COLOR}`,borderRadius:n.MESSAGE_RADIUS,backgroundColor:n.PANEL_BACKGROUND});o.className="ago-feedback__panel",o.setAttribute("role","group"),o.setAttribute("aria-label",e.whatWentWrong);const r=n.div({fontSize:"13px",fontWeight:"500",color:n.TEXT_COLOR,marginBottom:"8px"});r.textContent=e.whatWentWrong,o.appendChild(r);const s=n.div({display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"8px"});s.className="ago-feedback__reasons";for(const m of _e.FEEDBACK_REASONS){const p=document.createElement("button");p.type="button",p.className="ago-feedback__reason",p.textContent=e.reasons[m],n.css(p,{minHeight:"44px",padding:"4px 12px",fontSize:"13px",fontFamily:"inherit",borderRadius:"999px",border:`1px solid ${n.BORDER_COLOR}`,backgroundColor:"transparent",color:n.TEXT_COLOR,cursor:"pointer"});const x=()=>{const I=t.reasons.has(m);p.setAttribute("aria-pressed",I?"true":"false"),p.style.borderColor=I?n.ACCENT_COLOR:n.BORDER_COLOR,p.style.color=I?n.ACCENT_COLOR:n.TEXT_COLOR};p.addEventListener("click",()=>{t.reasons.has(m)?t.reasons.delete(m):t.reasons.add(m),x(),h()}),x(),s.appendChild(p)}o.appendChild(s);const c=document.createElement("textarea");c.className="ago-feedback__comment",c.rows=2,c.placeholder=e.commentPlaceholder,c.value=t.comment,c.setAttribute("aria-label",e.commentPlaceholder),n.css(c,{width:"100%",boxSizing:"border-box",padding:"8px 10px",fontSize:"14px",fontFamily:"inherit",color:n.TEXT_COLOR,border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"10px",backgroundColor:"transparent",resize:"vertical"}),c.addEventListener("input",()=>{t.comment=c.value,h()}),o.appendChild(c);const d=document.createElement("button");return d.type="button",d.className="ago-feedback__send",d.textContent=e.send,n.css(d,{marginTop:"8px",minHeight:"44px",padding:"6px 16px",fontSize:"14px",fontFamily:"inherit",borderRadius:"10px",border:"none",backgroundColor:n.BRAND_COLOR,color:n.BRAND_TEXT_COLOR,cursor:"pointer"}),d.addEventListener("click",()=>{d.disabled||(d.disabled=!0,i({reasons:[...t.reasons],comment:t.comment.trim()}).then(m=>{m||h()}))}),o.appendChild(d),h(),o;function h(){const m=t.reasons.size>0||t.comment.trim().length>0;d.disabled=!m,d.style.opacity=m?"1":"0.5",d.style.cursor=m?"pointer":"default"}}function mr(t){const e=n.div({marginTop:"6px",fontSize:"13px",color:n.MUTED_TEXT_COLOR});return e.className="ago-feedback__thanks",e.setAttribute("role","status"),e.textContent=t,e}function gr(t){const e=n.div({display:"flex",flexDirection:"column",flex:"1",width:"100%",overflow:"auto",minHeight:"0"});e.className="ago-chat-widget__chat";const i=n.div({position:"relative",isolation:"isolate",width:"100%",maxWidth:"768px",margin:"0 auto",padding:"0 8px 8px",boxSizing:"border-box",flexShrink:"0"});i.className="ago-chat-widget__dock";const o=n.div({width:"100%"});return o.className="ago-chat-widget__chat-composer",n.css(t.jumpBtn,{position:"absolute",bottom:"100%",top:"auto",left:"auto",right:"50%",marginBottom:"16px",transform:"translateX(50%)",zIndex:"50"}),i.append(t.jumpBtn,o),e.append(t.messagesWrap,i),{el:e,composerSlot:o}}var hr=7200*1e3;function fn(t){const e=t.lastMessageDate instanceof Date?t.lastMessageDate.getTime():new Date(t.lastMessageDate).getTime();return Number.isFinite(e)?e:Number.NEGATIVE_INFINITY}function Ro(t){return[...t].sort((e,i)=>fn(i)-fn(e))}function br(t,e=Date.now(),i=hr){const o=Ro(t)[0];if(!o)return null;const r=fn(o);return Number.isFinite(r)&&e-r<i?o:null}function xr(t){const e=n.div({position:"relative",display:"flex",flexDirection:"column",height:"100%",flex:"1",minHeight:"0"});e.className="ago-chat-widget__history";const i=n.div({display:"flex",flex:"1",minHeight:"0"});i.className="ago-chat-widget__history-body";const o=n.div({pointerEvents:"none",position:"absolute",left:"0",right:"0",bottom:"0",zIndex:"10",padding:"32px 16px 16px",backgroundImage:`linear-gradient(to top, ${n.EMBED_BACKGROUND} 72px, transparent 104px)`});o.className="ago-chat-widget__new-strip";const r=document.createElement("button");r.type="button",r.className="ago-chat-widget__new-conversation",n.css(r,{pointerEvents:"auto",display:"flex",height:"56px",width:"100%",alignItems:"center",justifyContent:"center",gap:"8px",borderRadius:"32px",backgroundColor:n.BRAND_COLOR,color:"#fff",padding:"0 24px",border:"none",cursor:"pointer",font:"inherit"});const s=document.createElement("span");s.textContent=t.labels.newConversation,n.css(s,{fontSize:"14px",lineHeight:"20px",fontWeight:"500"}),r.append(n.addCommentIcon({size:16}),s),r.addEventListener("click",t.onNew),o.appendChild(r),e.append(i,o);const c=p=>{t.customFont?p.style.opacity="0.7":p.style.color=n.EMBED_MUTED_TEXT};function d(){const p=n.div({display:"flex",flex:"1",alignItems:"center",justifyContent:"center",paddingBottom:"112px"});p.className="ago-chat-widget__history-loading";const x=n.div({width:"32px",height:"32px",borderRadius:"50%",borderBottom:`2px solid ${n.BRAND_COLOR}`,animation:"ago-spin 1s linear infinite"});x.setAttribute("role","status"),p.appendChild(x),i.replaceChildren(p)}function h(){const p=n.div({display:"flex",flex:"1",flexDirection:"column",alignItems:"center",justifyContent:"center"});p.className="ago-chat-widget__history-empty",c(p);const x=n.conversationsIcon({size:36});x.style.marginBottom="8px";const I=document.createElement("p");I.textContent=t.labels.noHistory,n.css(I,{fontSize:"14px",lineHeight:"20px",margin:"0"}),p.append(x,I),i.replaceChildren(p)}function m(p){const x=n.div({flex:"1",overflowY:"auto",padding:"0 16px 112px",minHeight:"0"});x.className="ago-chat-widget__history-list";const I=Ro(p);I.forEach((w,u)=>{const v=document.createElement("button");if(v.type="button",v.className="ago-chat-widget__thread",v.dataset.agoConversationId=w.id,n.css(v,{display:"flex",alignItems:"center",gap:"8px",padding:"17px 0",width:"100%",textAlign:"left",backgroundColor:"transparent",border:"none",borderBottom:u===I.length-1?"none":`1px solid ${n.EMBED_BORDER}`,cursor:"pointer",font:"inherit",color:"inherit"}),t.hoverBackground){const C=t.hoverBackground;v.addEventListener("mouseenter",()=>{v.style.backgroundColor=C}),v.addEventListener("mouseleave",()=>{v.style.backgroundColor="transparent"})}const A=n.div({flex:"1",minWidth:"0",display:"flex",flexDirection:"column",gap:"4px"}),E=document.createElement("h3");E.textContent=w.title||t.labels.newConversation,n.css(E,{margin:"0",fontSize:"14px",lineHeight:"20px",fontWeight:"400",color:t.customFont?"inherit":n.BRAND_COLOR,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"});const O=document.createElement("span");O.textContent=mi(w.lastMessageDate,Date.now(),t.labels.timeAgo),n.css(O,{fontSize:"12px",lineHeight:"16px"}),c(O),A.append(E,O);const W=n.chevronRightIcon({size:16});t.customFont?W.style.opacity="0.6":W.style.color=n.BRAND_COLOR,v.append(A,W),v.addEventListener("click",()=>t.onSelect(w)),x.appendChild(v)}),i.replaceChildren(x)}return{el:e,render:({threads:p,loading:x})=>{x?d():p.length===0?h():m(p)}}}function yr(t){const e=n.div({position:"relative",display:"flex",flex:"1",flexDirection:"column",width:"100%",maxWidth:"768px",margin:"0 auto",padding:"16px",overflow:"auto",boxSizing:"border-box",minHeight:"0"});e.className="ago-chat-widget__home";const i=n.div({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"space-between",height:"100%",width:"100%",minHeight:"0"}),o=n.div({flex:"1",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-end",gap:"32px",margin:"16px 0 32px"}),r=n.div({fontSize:"28px",lineHeight:"1.2",letterSpacing:"-0.03em",fontWeight:"700",textAlign:"center",color:n.TEXT_COLOR});r.className="ago-chat-widget__home-title",o.appendChild(r);const s=n.div({fontSize:"14px",lineHeight:"20px",textAlign:"center",maxWidth:"512px"});s.className="ago-chat-widget__home-subtitle",o.appendChild(s);const c=C=>{r.replaceChildren();for(const F of C.split(`
|
|
7
|
-
`)){const y=n.div({});y.textContent=F,r.appendChild(y)}},d=C=>{s.replaceChildren(),s.style.display=C?"":"none",C&&s.appendChild(Me(C))};c(t.title),d(t.subtitle);const h=n.div({flex:"1",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",width:"100%",position:"relative"}),m=n.div({display:"grid",gridTemplateColumns:"1fr",gap:"12px",width:"100%",maxWidth:"672px",marginBottom:"32px",padding:"0 16px",boxSizing:"border-box"});m.className="ago-chat-widget__starters";const p=[];let x=null;const I=C=>{m.replaceChildren(),p.length=0;for(const F of C)w(F);C.length>0?m.parentNode||h.insertBefore(m,u):m.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}),m.appendChild(F)}const u=n.div({width:"100%"});u.className="ago-chat-widget__home-composer",h.appendChild(u),I(t.starters);const v=n.div({flex:"1"});i.append(o,h,v),e.appendChild(i);const A=t.twoColumnsFrom??640,E=()=>{const C=typeof window<"u"&&window.innerWidth>=A;m.style.gridTemplateColumns=C?"1fr 1fr":"1fr"};E();const O=C=>{x=C;for(const{starter:F,btn:y}of p){const k=F===C;y.disabled=!!C,y.style.opacity=C?"0.6":"",y.style.cursor=C?"not-allowed":"pointer";const S=y.querySelector("svg");S&&(S.style.animation=k?"ago-skeleton-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite":"")}};return{el:e,composerSlot:u,syncColumns:E,setPending:O,setContent:C=>{C.title!==void 0&&c(C.title),C.subtitle!==void 0&&d(C.subtitle),C.starters&&(I(C.starters),E(),x&&O(x))}}}function Cr(t){const e=n.div({position:"fixed",bottom:"80px",[t.edge]:"20px",textAlign:t.edge==="left"?"left":"right",cursor:"pointer",zIndex:"2147483000",animation:"ago-scale-in 800ms",fontFamily:"Arial, Helvetica, sans-serif",transform:"translateZ(0)",backfaceVisibility:"hidden",willChange:"transform"});e.className="ago-chat-widget-teaser";const i=document.createElement("button");i.type="button",i.className="ago-chat-widget-teaser__close",i.setAttribute("aria-label","Dismiss"),i.textContent="X",n.css(i,{animation:"ago-appear 1000ms ease-in",background:"#fff",border:"1px solid #efefef",borderRadius:"50%",boxShadow:n.PANEL_SHADOW,color:"#333",cursor:"pointer",display:"inline-block",fontSize:"12px",fontWeight:"600",fontFamily:"inherit",lineHeight:"normal",left:"5px",padding:"3px 5px",position:"relative",top:"15px",zIndex:"1"});const o=document.createElement("p");o.className="ago-chat-widget-teaser__text",n.css(o,{alignItems:"center",backgroundColor:"#fff",borderRadius:"16px",boxShadow:n.PANEL_SHADOW,color:"#333",display:"flex",fontFamily:"Arial, Helvetica, sans-serif",fontSize:"0.9rem",fontWeight:"600",gap:"8px",margin:"0 0 16px 0",padding:"20px",position:"relative",textAlign:"left"}),o.textContent=t.text;const r=document.createElement("span");r.setAttribute("aria-hidden","true"),n.css(r,{position:"absolute",bottom:"-7px",[t.edge]:"20px",height:"16px",width:"16px",border:"1px solid #fff",transform:"rotate(45deg)",backgroundColor:"#fff"}),o.appendChild(r);const s=()=>{e.remove()};return i.addEventListener("click",c=>{c.stopPropagation(),s(),t.onDismiss?.()},{once:!0}),e.addEventListener("click",c=>{c.target!==i&&t.onOpen()}),e.append(i,o),{el:e,remove:s}}var po="Form submitted.";function vr(t){if(typeof t=="string")return t||null;if(!t||typeof t!="object")return null;const e=t;if(typeof e.message=="string"&&e.message)return e.message;const i=e.result;if(typeof i=="string"&&i)return i;if(i&&typeof i=="object"){const o=i.message;if(typeof o=="string"&&o)return o}return null}var Er=0,wr="Hello, how can I help you today?",kr=6,_r=800,Sr=/^(?:\d+(?:\.\d+)?(?:px|rem|em|vw|vmin|vmax|%)|(?:min|max|clamp|calc)\([^;{}]+\))$/i;function Tr(t){const e=typeof t=="number"?`${t}px`:String(t).trim();return!Sr.test(e)||typeof CSS<"u"&&typeof CSS.supports=="function"&&!CSS.supports("width",`min(max(400px, ${e}), 100% - 40px)`)?null:e}function Rr(t){const e=typeof t=="string"?document.querySelector(t):t;if(!e)throw new Error(`mountChatWidget: target "${String(t)}" not found.`);return e}function Ar(t,e){const i=e.placement??"inline",o=i==="bubble",{welcomeMessage:r="Hello! How can I help you today?",allowFiles:s=!1,allowStop:c=!0,autoScroll:d=!0,height:h=500,defaultOpen:m=!1,logoUrl:p,showAgentName:x=!1,agentBubble:I=!1,bubbleStyle:w="default",showHeader:u=!0,forms:v,formSubmittedMessage:A=po,onFollowUpClick:E,onMessageSent:O,onMessageReceived:W,onFormSubmitted:C,onFormError:F,onOpen:y,onClose:k,icon:S,subtitle:D,conversationStarters:V=[],autoResume:M=!0,hideFooter:j=!1,loadHomeConfig:b=!1}=e,R=e.title??(o?"AGO Chatbot":"Chat"),z=e.width??(o?550:400),J=e.loadThreads??o,Y=e.feedback??o,f=gi(e.labels),B=e.placeholder??(o?f.askQuestion:"Type a message..."),G=e.prompt===void 0?wr:e.prompt,P=o?{...n.colorsToTheme(e.colors),...e.theme}:e.theme,ee=typeof r=="string"?{message:r,mode:"static"}:r,re=ee.message,be=ee.mode??"static",Ao="speed"in ee&&ee.speed||45,gn="followUpReplies"in ee&&ee.followUpReplies||void 0;if(!e.client&&!e.config?.baseUrl)throw new si.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const $=e.client??new _e.AgoClient(e.config),It=Rr(t),ft=i==="left"||i==="right",ae=ft||o,Oo=ae&&(e.launcher??!0);let te=ae?m:!0,Dt=!1;const Lo=e.mobile?.breakpoint??(o?450:768),Bt=e.mobile?.trigger??"tap",hn=typeof window<"u"&&!!window.matchMedia,ne=hn?window.matchMedia(`(max-width: ${Lo}px), (max-height: 500px) and (orientation: landscape)`):void 0,No=hn?window.matchMedia("(prefers-reduced-motion: reduce)"):void 0,Fo=!!ne,Qe=!ae&&!!ne,Je=Symbol("ago-scroll-lock");let Z=!1;const Ht=e.persistConversation??(o?!0:void 0),$e=Ht?li.createConversationSession(Ht===!0?{}:Ht):void 0;let K=e.conversationId??$e?.getLastActiveThread()??void 0,N=[],mt=[],se=!1,xe=null,Se;const Ze=[];function Io(a){if(typeof A=="function"){const g=A(a);if(typeof g=="string"&&g)return g}const l=vr(a);return l||(typeof A=="string"?A:po)}const ye=[],T=n.div({display:"flex",flexDirection:"column",height:ft?"100%":typeof h=="number"?`${h}px`:h,border:`1px solid ${n.BORDER_COLOR}`,borderRadius:n.RADIUS,overflow:"hidden",backgroundColor:n.PANEL_BACKGROUND,fontFamily:n.FONT_VAR,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});T.className="ago-chat-widget",n.applyTheme(T,P),o&&(n.css(T,{height:"100%",width:"100%",border:"none",borderRadius:"0",boxShadow:"none",backgroundColor:n.EMBED_BACKGROUND,color:n.TEXT_COLOR,fontSize:"14px",lineHeight:"24px"}),P?.headerText||T.style.setProperty("--ago-header-text-color",n.readableTextColor(P?.headerBg??P?.brand??"#03182f")));let ce;if(u&&!o){if(ce=n.div({padding:"14px 16px",borderBottom:`1px solid ${n.BORDER_COLOR}`,backgroundColor:n.HEADER_BACKGROUND,color:n.HEADER_TEXT_COLOR,display:"flex",alignItems:"center",gap:"10px"}),ce.className="ago-chat-widget__header",p){const l=document.createElement("img");l.src=p,l.alt="Logo",n.css(l,{height:"24px",width:"auto"}),ce.appendChild(l)}const a=document.createElement("h3");if(a.textContent=R,n.css(a,{margin:"0",fontSize:"15px",fontWeight:"600"}),ce.appendChild(a),ft){const l=document.createElement("button");l.type="button",l.className="ago-chat-widget__close",l.setAttribute("aria-label","Close"),l.textContent="×",n.css(l,{marginLeft:"auto",flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center",width:"44px",height:"44px",margin:"-10px -10px -10px auto",background:"transparent",border:"none",color:n.HEADER_TEXT_COLOR,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0"}),l.addEventListener("click",()=>qe()),ce.appendChild(l)}}const Q=n.div({flex:"1",overflow:"auto",overflowAnchor:d?"auto":"none",overscrollBehavior:"contain",padding:"16px",backgroundColor:n.MESSAGES_BACKGROUND});Q.className="ago-chat-widget__messages",Q.setAttribute("role","log"),Q.setAttribute("aria-live","polite"),Q.setAttribute("aria-relevant","additions text"),Q.setAttribute("aria-atomic","false");const pe=o?n.div({maxWidth:"768px",margin:"0 auto",padding:"0 8px",boxSizing:"border-box"}):Q;o&&(n.css(Q,{padding:"16px 0",backgroundColor:"transparent"}),pe.className="ago-chat-widget__list",Q.appendChild(pe));const Do=48;let Te=!0,zt=0;function Mt(a){zt++;try{a()}finally{const l=()=>{zt--};typeof queueMicrotask=="function"?queueMicrotask(l):l()}}function bn(){return Q.scrollHeight-Q.scrollTop-Q.clientHeight<=Do}const oe=document.createElement("button");oe.type="button",oe.className="ago-chat-widget__jump",oe.setAttribute("aria-label","Jump to latest message"),oe.innerHTML='<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 5v14M19 12l-7 7-7-7"/></svg>',n.css(oe,{position:"absolute",left:"50%",bottom:"12px",transform:"translateX(-50%)",width:"44px",height:"44px",display:"none",alignItems:"center",justifyContent:"center",border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"50%",backgroundColor:n.PANEL_BACKGROUND,color:n.TEXT_COLOR,boxShadow:"rgba(15, 15, 15, 0.16) 0px 2px 10px 0px",cursor:"pointer",zIndex:"2"}),o&&(oe.setAttribute("aria-label",f.scrollToBottom),oe.replaceChildren(n.arrowDownwardIcon({size:20})),n.css(oe,{display:"flex",width:"36px",height:"36px",padding:"8px",boxSizing:"border-box",border:`1px solid ${n.NEUTRAL_BORDER}`,backgroundColor:"#fff",boxShadow:n.SHADOW_MD,transition:"opacity 0.3s",opacity:"0",pointerEvents:"none"}));function xn(){Te=!0,Mt(()=>{Q.scrollTop=Q.scrollHeight}),$t()}oe.addEventListener("click",xn);function $t(){const a=d?Te:bn();if(o){oe.style.opacity=a?"0":"1",oe.style.pointerEvents=a?"none":"auto";return}oe.style.display=a?"none":"flex"}function Ut(){d&&Te&&Mt(()=>{Q.scrollTop=Q.scrollHeight}),$t()}function yn(a){Mt(()=>{const l=Q.scrollTop;a(),(!d||!Te)&&(Q.scrollTop=l)}),Ut()}Q.addEventListener("scroll",()=>{zt>0||(Te=bn(),$t())});const Wt=n.div({position:"relative",flex:"1",display:"flex",minHeight:"0"});Wt.append(Q,oe);const{inputRow:Ce,setDisabled:Bo,focus:gt,restoreDraft:Ho,setPlaceholder:Cn,getValueAndClear:zo,setSpeechToTextEnabled:Mo,cancelRecording:et,destroy:$o}=ci({placeholder:B,allowFiles:s,transcribeAudio:e.speechToText?(a,l)=>$.transcribeAudio(a,l):void 0,speechToTextLabels:typeof e.speechToText=="object"?e.speechToText.labels:void 0,onSend:(a,l)=>{Ve(a,l)},onStop:c?()=>{wt()}:void 0,look:o?"embed":"classic",labels:o?{attachFiles:f.attachFiles,dismiss:f.dismiss,tooManyFiles:f.tooManyFiles,invalidFileType:f.invalidFileType,fileTooLarge:f.fileTooLarge}:void 0});n.ensureKeyframes(),e.speechToText&&$.getConfig().then(a=>{Z||Mo(a.permissions.some(l=>l.speechToTextEnabled))}).catch(()=>{}),o||T.append(...ce?[ce]:[],Wt,Ce);let tt=T,U,le,Pt;const nt=i==="left"?"left":"right";let jt,ht,ve,Ue,bt,ot,ue,Ne,We,Ee="home",xt="home",Pe=!1,yt=J,it=!1,rt=!1,Gt;if(o){if(U=n.div({position:"fixed",right:"20px",bottom:"80px",top:"max(40px, calc(100% - 880px))",width:`min(max(400px, ${n.PANEL_WIDTH}), var(--ago-panel-max, calc(100% - 40px)))`,height:"auto",borderRadius:"16px",boxShadow:n.PANEL_SHADOW,overflow:"hidden",transformOrigin:"right bottom",zIndex:"2147483000",backgroundColor:n.EMBED_BACKGROUND,display:"none",fontFamily:n.FONT_VAR}),U.className="ago-chat-widget-bubble",U.dataset.agoLayout="panel",n.applyTheme(U,P),!P?.panelWidth){const l=Tr(z);l?U.style.setProperty("--ago-panel-width",l):console.warn(`[AGO] mountChatWidget width "${String(z)}" is not a valid CSS length, ignoring. Expected e.g. 700 or "45rem". Falling back to 550px.`)}u&&(jt=ui({title:R,labels:f,onBack:()=>Le(xt,{byUser:!0}),onNewChat:()=>kt(),onClose:()=>qe()}),T.appendChild(jt.el)),ot=n.div({flex:"1",display:"flex",flexDirection:"column",minHeight:"0",overflow:"hidden"}),ot.className="ago-chat-widget__main",T.appendChild(ot),j||(ht=pi({labels:f,onNavigate:l=>Le(l,{byUser:!0})}),T.appendChild(ht.el)),ve=yr({title:R,subtitle:D,starters:V,onStarter:l=>{ve?.setPending(l),Ve(l.message??l.label,void 0,{agentId:l.agentId}).finally(()=>ve?.setPending(null))}});const a=e.colors?.background;Ue=xr({labels:f,onSelect:l=>{Pe=!0,xt="history",dt(l.id)},onNew:()=>kt(),hoverBackground:a&&n.isValidHexColor(a)?n.lightenColor(a,10):void 0,customFont:!!e.colors?.font}),bt=gr({messagesWrap:Wt,jumpBtn:oe}),U.appendChild(T),tt=U}ft&&(U=n.div({position:"fixed",top:"0",bottom:"0",[nt]:"0",width:typeof z=="number"?`${z}px`:z,maxWidth:"100vw",display:"flex",zIndex:"2147483000",transition:"transform 0.3s ease",boxShadow:"rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"}),U.className="ago-chat-widget-panel",n.css(T,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[nt==="left"?"borderRight":"borderLeft"]:`1px solid ${n.BORDER_COLOR}`}),U.appendChild(T),tt=U),Oo&&(Pt=Si({look:o?"bubble":"classic",edge:nt,title:R,icon:o?S:p,onClick:()=>o?Xn():Tt()}),le=Pt.el);const at=Qe?`ago-vt-${++Er}`:"",vn=52;let we=!1,Re=0,je=0,fe,st,Ae;const Ct={height:T.style.height,border:T.style.border,borderRadius:T.style.borderRadius,boxShadow:T.style.boxShadow};It.appendChild(tt),le&&It.appendChild(le),St(),o&&(G!==!1&&!te&&(Ne=setTimeout(Jo,1e3)),document.addEventListener("keydown",jn),window.addEventListener("resize",Gn)),Qe&&(fe=ii(),T.insertBefore(fe,T.firstChild),st=document.createElement("style"),st.id=at,st.textContent=`::view-transition-group(${at}),::view-transition-group(${at}-bar){animation-duration:0.3s;animation-timing-function:cubic-bezier(0.4,0,0.2,1)}`,document.head.appendChild(st),(Bt==="focus"||Bt==="tap")&&(T.addEventListener("pointerdown",a=>{if(we||!ne?.matches)return;const l=Ce.contains(a.target);if(Bt==="tap"){if((a.target instanceof Element?a.target:null)?.closest("button,a[href],[role='button']"))return}else if(!l)return;l&&a.preventDefault(),pt()},!0),T.addEventListener("focusin",a=>{ne?.matches&&Ce.contains(a.target)&&pt()}))),Fo&&document.addEventListener("keydown",Kn),ne&&ne.addEventListener("change",Yn);const En=E!==!1,wn=E===!1?void 0:E??(a=>{Qe&&ne?.matches&&!we?pt().then(()=>Ve(a)):Ve(a)}),Ge=Y===!0?{}:Y||null,Uo={...pn,...Ge?.labels,reasons:{...pn.reasons,...Ge?.labels?.reasons}},vt=new Map;function kn(a){if(!Ge||!a.id||!a.conversationId||a.status!=="DONE"||!a.content)return null;let l=vt.get(a.id);l||(l=dr(),vt.set(a.id,l));const g=async(_,H)=>{try{return await $.submitFeedback(a.id,_,H),Ge.onSubmit?.({messageId:a.id,rating:_,reasons:H?.reasons??[],comment:H?.comment||void 0}),!0}catch(L){return Ge.onError?.(L instanceof Error?L:new Error(String(L))),!1}};return pr({state:l,labels:Uo,askWhy:Ge.askWhy??!o,onRate:_=>{g(_)},onReport:(_,H)=>g(_,H),look:o?"embed":"classic"})}const me=e.toolCallForm??{},ke={...To,...me.labels},_n=$.getUserIdentity(),Vt=me.userEmail??_n.email,Sn=!Vt&&!_n.hasJwt;let Fe=null,Tn=!1,Rn,qt=!1;const lt=new Map,Et=new Set;function Wo(){Rn||(Rn=$.getConfig().then(a=>{const l=a.permissions[0];Fe=l?.ticketForm??null,qt=!!l?.fileAttachmentsEnabled}).catch(()=>{Fe=null}).then(()=>{if(Tn=!0,!Z)for(const a of lt.values())a.kind==="ticket"&&(Fe&&qi(a.state,a.call.ticket,Fe),a.view.rebuild({ticketForm:Fe,configLoading:!1,allowFiles:s||qt}))}))}function Xt(){for(const a of lt.values())a.kind==="embed"&&a.view.destroy();lt.clear(),Et.clear()}function Po(a){for(const l of N){const g=l.toolCalls?.find(_=>_.id===a);if(g)return g}}function jo(a){const l=lt.get(a.id);if(l)return l;let g;if(a.allowedToCreateTicket===!1){const _=n.div({display:"flex",flexDirection:"column",gap:"16px"});_.className="ago-ticket-form ago-ticket-form--denied",_.appendChild(Yi(ke.notAllowed)),g={kind:"static",el:_}}else if(a.mode==="embed"){const _={status:lo(a)?"submitted":"loading"};g={kind:"embed",state:_,view:nr({state:_,embedHtml:a.embedHtml,description:a.embedDescription,ticket:a.ticket,email:Vt,labels:ke,message:a.message,successMessage:me.successMessage,onSubmitted:H=>{Et.add(a.id),$.submitToolCallForm(a.id,{success:!0,source:"embed",thread_id:K,captured_form_data:H}).then(L=>{const q=L.ticket??L.result?.ticket;me.onSubmitted?.({toolCallId:a.id,toolName:a.toolName,mode:"embed",ticket:q?.ticket_id?{id:String(q.ticket_id),url:q.ticket_url}:void 0,values:H??{}})}).catch(L=>{me.onError?.(L instanceof Error?L:new Error(String(L)))}).finally(()=>{Z||X()})}})}}else{Wo();const _=_o(a.ticket,Fe,Vt??""),H=lo(a);H&&(_.submitted=H),g={kind:"ticket",state:_,view:Qi({state:_,ticketForm:Fe,configLoading:!Tn,labels:ke,message:a.message,requireEmail:Sn,allowFiles:s||qt,successMessage:me.successMessage,successUrlLabel:me.successUrlLabel,createTicket:L=>$.createTicket({subject:L.subject,body:L.body,priority:L.priority,typology:L.typology,conversationId:K,email:L.email,customFields:L.customFields,files:L.files,ticketFormId:L.ticketFormId}),onCreated:(L,q)=>{Et.add(a.id);const ge=Object.entries(q.customFields).map(([Ie,ai])=>({id:Ie,value:ai}));$.submitToolCallForm(a.id,{success:!0,ticket_id:L.id,ticket_url:L.url,subject:q.ticket.subject,typology:q.ticket.typology,priority:q.ticket.priority,body:q.ticket.body,tag:q.ticket.tag,custom_fields:ge,created_at:new Date().toISOString()}).catch(Ie=>{me.onError?.(Ie instanceof Error?Ie:new Error(String(Ie)))}).finally(()=>{me.onSubmitted?.({toolCallId:a.id,toolName:a.toolName,mode:"form",ticket:{id:L.id,url:L.url},values:{...q.ticket,custom_fields:q.customFields,email:Sn?q.email:void 0}}),Z||X()})},onError:me.onError}),call:a}}return lt.set(a.id,g),g}function An(a){if(a.type!=="form"||a.displayMode==="collapsible")return null;const l=ir(N);if(l&&l!==a.id){const _=Po(l),H=!!_?.askToTalkToHuman&&_.allowedToCreateTicket===!1;return sr(H?ke.contactFormRejected:ke.contactFormCreated,H?"warning":"info")}if(!or(a))return lr(a,ke);const g=jo(a);return g.kind==="static"?g.el:g.view.el}let Oe;function Go(){const a=N.some(_=>_.toolCalls?.some(H=>H.type==="form")),l=Et.size>0||rr(N);if(!a&&!l){Ce.style.display="",Oe?.remove();return}Oe||(Oe=n.div({margin:"12px",borderRadius:"24px",border:`1px solid ${n.BORDER_COLOR}`,boxShadow:"0 1px 2px rgba(0, 0, 0, 0.05)",backgroundColor:n.PANEL_BACKGROUND,display:"flex",flexDirection:"column",alignItems:"center",gap:"16px",padding:"28px 24px",textAlign:"center",fontFamily:n.FONT_VAR}),Oe.className="ago-chat-blocked"),Oe.replaceChildren();const g=document.createElement("p");if(g.textContent=l?ke.ticketCreatedBlocked:ke.formPending,n.css(g,{color:n.MUTED_TEXT_COLOR,lineHeight:"1.625",fontSize:"16px",margin:"0",whiteSpace:"pre-line"}),Oe.appendChild(g),l){const _=document.createElement("button");_.type="button",_.className="ago-chat-blocked__new",n.css(_,{display:"inline-flex",alignItems:"center",gap:"8px",borderRadius:"9999px",padding:"0 20px",minHeight:"44px",backgroundColor:"var(--ago-brand-color, #03182f)",color:"var(--ago-brand-text-color, #fff)",border:"none",cursor:"pointer",font:"inherit",fontSize:"14px",fontWeight:"500"}),_.append(n.addCommentIcon({size:18}));const H=document.createElement("span");H.textContent=ke.newConversation,_.appendChild(H),_.addEventListener("click",()=>{kt(),me.onNewConversation?.()}),Oe.appendChild(_)}Ce.style.display="none",Ce.parentElement?.insertBefore(Oe,Ce)}function On(a){const l=N[a];return o?Ii(l,{isLast:a===N.length-1,followUpEnabled:En,followUpHandler:wn,agentRowTinted:!!P?.agentBubbleBg,agentRowTextTinted:!!P?.agentBubbleText,labels:f,actionsRow:kn(l),renderToolCall:An}):Ei(l,{...Vo(a),renderToolCall:An})}function Vo(a){const l=N.length-1;return{isLast:a===l,isLastOfBlock:a===l||N[a+1].role!==N[a].role,bubbleStyle:w,showAgentName:x,agentBubble:I,followUpEnabled:En,followUpHandler:wn,isMobile:!!ne?.matches,feedbackRow:kn(N[a])}}function qo(){if(xe||Ze.length>0)return!1;const a=N.length-1,l=N[a];if(!l||l.role!=="assistant")return!1;const g=mt[a];if(!g||g.parentNode!==pe)return!1;const _=On(a),H=document.activeElement,L=H instanceof HTMLElement&&g.contains(H)?H:null;return yn(()=>pe.replaceChild(_,g)),L&&_.contains(L)&&L.focus({preventScroll:!0}),mt[a]=_,!0}function X(){yn(Xo);const a=N[N.length-1],l=se&&a?.role==="assistant"&&(a.status==="IN_PROGRESS"||a.status==="WAITING_CLIENT");Q.setAttribute("aria-busy",l?"true":"false"),Bo(l),Go()}function Xo(){if(pe.replaceChildren(),mt=[],N.length===0){if(o){if(it){const a=n.div({display:"flex",justifyContent:"center",padding:"32px 0"});a.className="ago-chat-widget__thread-loading";const l=n.div({width:"32px",height:"32px",borderRadius:"50%",borderBottom:"2px solid var(--ago-brand-color, #03182f)",animation:"ago-spin 1s linear infinite"});l.setAttribute("role","status"),a.appendChild(l),pe.appendChild(a)}}else if(be==="static"){const a=n.div({textAlign:"center",color:n.MUTED_TEXT_COLOR,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});a.appendChild(Me(re)),pe.appendChild(a)}}else N.forEach((a,l)=>{const g=On(l);mt[l]=g,pe.appendChild(g)});for(const a of Ze)pe.appendChild(wi(a));if(xe){if(o){pe.appendChild(Oi(f.errorTitle,xe));return}const a=n.div({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});a.setAttribute("role","alert"),a.textContent=xe,pe.appendChild(a)}}function Kt(){for(let a=N.length-1;a>=0;a--){const l=N[a];if(l.role==="assistant"&&(l.status==="IN_PROGRESS"||l.status==="WAITING_CLIENT"))return l}}const Ln=a=>{K||(K=a.conversationId)},Nn=a=>{const l=Kt();l&&(l.content+=a.content,qo()||X())},Fn=a=>{const l=N.findIndex(g=>g.id===a.id||g.role==="assistant"&&g.status==="IN_PROGRESS");l>=0?N[l]=a:N.push(a),X(),ct()||gt()},In=a=>{const l=N.findIndex(g=>g.id===a.id||g.role==="assistant"&&g.status==="IN_PROGRESS");l>=0?N[l]=a:N.push(a),se=!1,X(),a.status==="DONE"&&W?.({id:a.id,content:a.content})},Dn=()=>{const a=Kt();a&&(a.content?a.status="CANCELED":N=N.filter(l=>l!==a)),se=!1,X()},Bn=a=>{xe=a.error,se=!1,N=N.filter(l=>!l.id.startsWith("temp-")),X()};function Ko(a){const l={id:`ago-intro-${Date.now()}`,conversationId:"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};N.push(l),X();const g=a.match(/\S+\s*/g)??[a];let _=0;Se=setInterval(()=>{if(_>=g.length){clearInterval(Se),Se=void 0,l.status="DONE",gn&&(l.followUpReplies=gn),X();return}l.content+=g[_],_++,X()},Ao)}const Hn=a=>{const l=ye.find(g=>g.id===a.conversationId);l&&(l.title=a.title),o&&Ee==="history"&&Ue?.render({threads:ye,loading:yt})},zn=a=>{if(a.type!=="form")return;const l=Kt()??[...N].reverse().find(H=>H.role==="assistant");if(!l)return;const g=l.toolCalls??[],_=g.findIndex(H=>H.id===a.id);_>=0?g[_]=a:g.push(a),l.toolCalls=g,X()};$.on("message:start",Ln),$.on("message:chunk",Nn),$.on("message:answer-complete",Fn),$.on("message:complete",In),$.on("message:stopped",Dn),$.on("message:error",Bn),$.on("conversation:title",Hn),$.on("toolCall:received",zn);const Mn=a=>C?.(a),$n=a=>F?.(a);C&&$.on("form:submitted",Mn),F&&$.on("form:error",$n);const Yt=[];let Un=!1;const Wn=a=>{if(Un)return;Yt.push(a.install($));let l=a.store.get().submitted;const g=a.store.subscribe(_=>{_.submitted&&!l&&(Ze.push(Io(_.submitResult)),X()),l=_.submitted});Yt.push(g)};for(const a of v??[])a.schema!=null?Wn(to.createFormCollector(a)):to.loadFormCollector($,a).then(l=>Wn(l)).catch(()=>{});async function Ve(a,l,g){const _=a.trim();if(!_&&!l?.length||se)return;if(o&&Ee!=="chat"&&(xt="home",Le("chat",{byUser:!0})),O?.(_),se=!0,xe=null,Te=!0,Se){clearInterval(Se),Se=void 0;const L=N.find(q=>q.id.startsWith("ago-intro-"));L&&!L.content?N=N.filter(q=>q!==L):L&&(L.status="DONE")}const H=Date.now();N.push({id:`temp-user-${H}`,conversationId:K||"",content:_,role:"user",status:"DONE",attachments:l&&l.length>0?_e.attachmentsFromFiles(l):void 0,createdAt:new Date}),N.push({id:`temp-assistant-${H}`,conversationId:K||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),X(),d||xn();try{const L=await $.sendMessage(_,{conversationId:K,files:l,...g?.agentId?{agentId:g.agentId}:{}});L.conversationId&&(K||(K=L.conversationId),$e?.setActiveThread(L.conversationId,L.createdAt));const q=N.find(ge=>ge.id===`temp-user-${H}`);if(q&&(q.id=`user-${H}`,q.conversationId=L.conversationId),L.id&&!N.some(ge=>ge.id===L.id)){const ge=N.findIndex(Ie=>Ie.id===`temp-assistant-${H}`);ge>=0?N[ge]=L:N.push(L)}N=N.filter(ge=>!ge.id.startsWith("temp-")),L.status!=="WAITING_CLIENT"&&(se=!1),X(),J&&Qt()}catch(L){xe=L instanceof Error?L.message:"Failed to send message",se=!1,N=N.filter(q=>!q.id.startsWith("temp-")),Ho(_,l),X()}}async function wt(){se&&await $.stop()}async function Qt(){try{const{data:a}=await $.getConversations();ye.splice(0,ye.length,...a)}catch{}return yt=!1,o&&!Z&&(Ee==="history"&&Ue?.render({threads:ye,loading:!1}),Yo()),ye}async function Pn(a){try{const l=await $.getConversation(a);if(K!==a)return;const g=l?.messages??[];it=!1,g.length>0&&N.length===0?(N=g,X()):o&&X(),o&&$e?.setActiveThread(a,l.lastMessageDate)}catch{if(K!==a)return;it=!1,N.length===0&&($e?.clear(),K=void 0,o&&(Ee==="chat"&&Le("home"),X()))}}function Le(a,l){if(!o||!ot||!ve||!bt||!Ue)return;l?.byUser&&(Pe=!0),Ee!==a&&et(),Ee=a,a==="home"?(ve.composerSlot.appendChild(Ce),Cn(B)):a==="chat"&&(bt.composerSlot.appendChild(Ce),Cn(""));const g=a==="home"?ve.el:a==="chat"?bt.el:Ue.el;ot.replaceChildren(g),a==="history"&&Ue.render({threads:ye,loading:yt}),a==="chat"&&(Te=!0,Ut()),jt?.update({screen:a}),ht?.setActive(a),ht?.setVisible(a!=="chat")}async function dt(a){o&&(et(),se&&await wt(),K=a,N=[],xe=null,Ze.length=0,vt.clear(),Xt(),it=!0,Le("chat"),X(),await Pn(a))}function kt(){se&&wt(),K=void 0,N=[],xe=null,Ze.length=0,vt.clear(),Xt(),it=!1,$e?.clear(),zo(),ve?.setPending(null),xt="home",o&&Le("home",{byUser:!0}),X()}function Yo(){if(!o||rt)return;if(rt=!0,!M||Pe||Ee!=="home"||N.length>0||K){_t();return}const a=br(ye);a&&dt(a.id),_t()}async function Qo(){let a;try{a=(await $.getConfig()).permissions[0]?.homePage}catch{return}Z||!a||(ve?.setContent({title:a.title||void 0,subtitle:a.subtitle||void 0,starters:a.starters.length?a.starters.map(l=>({label:l.label,message:l.message,agentId:l.agentId})):void 0}),a.widgetStarter&&(Gt=a.widgetStarter,_t()))}function _t(){const a=Gt;!a||Z||te&&(yt&&!rt||(Gt=void 0,!(Pe||K||N.length>0||se||Ee!=="home")&&Ve(a.message,void 0,{agentId:a.agentId})))}function Jo(){Ne=void 0,!(Z||te||G===!1||ue)&&(ue=Cr({text:G,edge:nt,onOpen:()=>Tt(),onDismiss:()=>{ue=void 0}}),It.appendChild(ue.el),Jt())}function Jt(){if(!o||!U||!le||ct()||!le.offsetHeight)return;const a=getComputedStyle(le),l=parseFloat(a.bottom),g=parseFloat(a.right);if(Number.isNaN(l)||Number.isNaN(g))return;const _=Math.round(l+le.offsetHeight)+kr,H=Math.round(g),L=[U];ue&&L.push(ue.el);for(const q of L)q.style.setProperty("bottom",`${_}px`,"important"),q.style.setProperty("right",`${H}px`,"important");U.style.setProperty("top",`max(40px, calc(100% - ${_+_r}px))`,"important"),U.style.setProperty("--ago-panel-max",`calc(100% - ${H+20}px)`)}function jn(a){a.key!=="Escape"||!te||a.defaultPrevented||a.target instanceof HTMLInputElement||a.target instanceof HTMLTextAreaElement||Zt()||qe()}function Gn(){We&&clearTimeout(We),We=setTimeout(()=>{We=void 0,!Z&&(Jt(),ve?.syncColumns())},150)}o?(Le("home"),X(),b&&Qo(),e.conversationId?(Pe=!0,rt=!0,dt(e.conversationId)):K&&M?(rt=!0,dt(K)):K=void 0):(X(),Qe&&ne?.matches||gt(),K?Pn(K):be==="streaming"&&Ko(re)),J&&Qt();const Vn={client:$,element:tt,sendMessage:Ve,stop:wt,...ae||Qe?{open:Zo,close:ei,toggle:ti}:{},newConversation:kt,...o?{showScreen:a=>Le(a,{byUser:!0}),openConversation:a=>(Pe=!0,dt(a))}:{},session:$e,threads:ye,refreshThreads:Qt,destroy(){Z||(Z=!0,$o(),Se&&clearInterval(Se),Ne&&clearTimeout(Ne),We&&clearTimeout(We),ue?.remove(),$.off("message:start",Ln),$.off("message:chunk",Nn),$.off("message:answer-complete",Fn),$.off("message:complete",In),$.off("message:stopped",Dn),$.off("message:error",Bn),$.off("conversation:title",Hn),$.off("toolCall:received",zn),Xt(),C&&$.off("form:submitted",Mn),F&&$.off("form:error",$n),Un=!0,Yt.forEach(a=>a()),tt.remove(),le?.remove(),fe?.remove(),document.removeEventListener("keydown",jn),window.removeEventListener("resize",Gn),st?.remove(),Ae?.remove(),ne?.removeEventListener("change",Yn),document.removeEventListener("keydown",Kn),nn(),Dt=!1,n.unlockBackgroundScroll(Je),e.client||$.destroy())}};return o&&Object.defineProperty(Vn,"screen",{get:()=>Ee,enumerable:!0}),Vn;function St(){if(!U)return;if(o)qn();else{const l=nt==="left"?"border-right":"border-left";ne?.matches?(U.style.width="100%",T.style.borderRadius="0",T.style.removeProperty(l)):(U.style.width=typeof z=="number"?`${z}px`:z,T.style.setProperty(l,`1px solid ${n.BORDER_COLOR}`));const g=i==="left"?"translateX(-100%)":"translateX(100%)";U.style.transform=te?"translateX(0)":g,le&&(le.style.display=te?"none":"flex")}U.setAttribute("aria-hidden",te?"false":"true");const a=Zt();a!==Dt&&(Dt=a,a?(T.setAttribute("role","dialog"),T.setAttribute("aria-modal","true"),T.setAttribute("aria-label",R),T.tabIndex=-1,T.style.paddingBottom="env(safe-area-inset-bottom)",n.lockBackgroundScroll(Je),Re=en(),tn(),Qn()):(nn(),oi(),Re=0,T.removeAttribute("role"),T.removeAttribute("aria-modal"),T.removeAttribute("aria-label"),T.style.removeProperty("padding-bottom"),n.unlockBackgroundScroll(Je)))}function qn(){if(!U)return;U.style.display=te?"block":"none",Pt?.setOpen(te);const a=ct();if(le&&(le.style.display=a&&te?"none":"flex"),a){for(const l of["bottom","right","top","--ago-panel-max"])U.style.removeProperty(l);n.css(U,{top:"0",left:"0",right:"0",bottom:"0",width:"100dvw",maxWidth:"100vw",height:"var(--ago-vh, 100dvh)",borderRadius:"0",paddingTop:"env(safe-area-inset-top, 0px)",paddingBottom:"env(safe-area-inset-bottom, 0px)",paddingLeft:"env(safe-area-inset-left, 0px)",paddingRight:"env(safe-area-inset-right, 0px)",boxSizing:"border-box"}),U.dataset.agoLayout="fullscreen",te&&(ue?.remove(),ue=void 0)}else{for(const l of["left","max-width","padding-top","padding-bottom","padding-left","padding-right"])U.style.removeProperty(l);n.css(U,{right:"20px",bottom:"80px",top:"max(40px, calc(100% - 880px))",width:`min(max(400px, ${n.PANEL_WIDTH}), var(--ago-panel-max, calc(100% - 40px)))`,height:"auto",borderRadius:"16px"}),U.dataset.agoLayout="panel",Jt()}}function Tt(){te=!0,Ne&&(clearTimeout(Ne),Ne=void 0),ue?.remove(),ue=void 0,St(),ct()?T.focus({preventScroll:!0}):gt(),_t(),y?.()}function qe(){et(),te=!1,St(),k?.()}function Xn(){te?qe():Tt()}function Zo(){ae?Tt():pt()}function ei(){et(),ae?qe():ut()}function ti(){ae?Xn():we?ut():pt()}function ct(){return!!ne?.matches}function Zt(){return ct()&&(ae?te:we)}function ni(){return Array.from(T.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter(a=>a.getClientRects().length>0)}function Kn(a){if(!Zt())return;if(a.key==="Escape"){ae?qe():ut();return}if(a.key!=="Tab")return;const l=ni();if(l.length===0){a.preventDefault();return}const g=l[0],_=l[l.length-1],H=document.activeElement;a.shiftKey&&(H===g||!T.contains(H))?(a.preventDefault(),_.focus()):!a.shiftKey&&(H===_||!T.contains(H))&&(a.preventDefault(),g.focus())}function Yn(a){ae?St():!a.matches&&we&&ut(),X()}function en(){return window.visualViewport?.height??window.innerHeight}function tn(){const a=window.visualViewport,l=a?.offsetTop??0,g=a?.height??Re;if(ae){if(!U)return;const H=window.innerHeight||Re,L=Math.max(0,H-(l+g));U.style.bottom=`${L}px`,U.style.top=`${l}px`;return}const _=Math.min(0,l+g-Re);T.style.top=`${_}px`,fe&&(fe.style.top=`${l}px`)}function oi(){ae&&U&&(U.style.removeProperty("bottom"),U.style.removeProperty("top"),o&&!Z&&qn())}function Rt(){je||(je=requestAnimationFrame(()=>{je=0,!Z&&tn()}))}function Qn(){window.visualViewport?.addEventListener("resize",Rt),window.visualViewport?.addEventListener("scroll",Rt)}function nn(){window.visualViewport?.removeEventListener("resize",Rt),window.visualViewport?.removeEventListener("scroll",Rt),je&&(cancelAnimationFrame(je),je=0)}function Jn(){Te=!0,Ut()}function ii(){const a=n.div({position:"fixed",top:"0",left:"0",right:"0",height:`calc(${vn}px + env(safe-area-inset-top))`,display:"none",alignItems:"center",justifyContent:"space-between",padding:"env(safe-area-inset-top) 14px 0",backgroundColor:n.PANEL_BACKGROUND,borderBottom:`1px solid ${n.BORDER_COLOR}`,zIndex:"2147483001",fontFamily:n.FONT_VAR});if(a.className="ago-chat-widget-mobile-bar",p){const g=document.createElement("img");g.src=p,g.alt="",n.css(g,{height:"28px",width:"auto"}),a.appendChild(g)}else if(R){const g=document.createElement("span");g.textContent=R,n.css(g,{fontSize:"15px",fontWeight:"600",color:n.TEXT_COLOR,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"}),a.appendChild(g)}else a.appendChild(n.div({}));const l=document.createElement("button");return l.type="button",l.setAttribute("aria-label","Close"),l.textContent="×",n.css(l,{flexShrink:"0",width:"44px",height:"44px",marginRight:"-10px",display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",fontSize:"26px",lineHeight:"1",color:n.TEXT_COLOR,cursor:"pointer",padding:"0"}),l.addEventListener("click",()=>{ut()}),a.appendChild(l),a}function ri(){return typeof document.startViewTransition=="function"&&!No?.matches&&!!ne?.matches}function Zn(a){const l=document;if(ri()&&l.startViewTransition){T.style.setProperty("view-transition-name",at),fe?.style.setProperty("view-transition-name",`${at}-bar`);const g=()=>{T.style.removeProperty("view-transition-name"),fe?.style.removeProperty("view-transition-name")};return l.startViewTransition(a).finished.then(g,g)}return a(),Promise.resolve()}function eo(a){if(a)Ae&&T.parentElement?.insertBefore(Ae,T),n.css(T,{position:"fixed",top:"0",left:"0",right:"0",bottom:"0",height:"var(--ago-vh, 100dvh)",zIndex:"2147483000",border:"none",borderRadius:"0",boxShadow:"none",paddingTop:`calc(${vn}px + env(safe-area-inset-top))`,paddingBottom:"env(safe-area-inset-bottom)"}),T.setAttribute("role","dialog"),T.setAttribute("aria-modal","true"),T.setAttribute("aria-label",R),ce&&(ce.style.display="none"),fe&&(fe.style.display="flex");else{Ae?.remove(),Ae=void 0;for(const l of["position","top","left","right","bottom","z-index","padding-top","padding-bottom"])T.style.removeProperty(l);T.style.height=Ct.height,T.style.border=Ct.border,T.style.borderRadius=Ct.borderRadius,T.style.boxShadow=Ct.boxShadow,T.removeAttribute("role"),T.removeAttribute("aria-modal"),T.removeAttribute("aria-label"),ce&&(ce.style.display="flex"),fe&&(fe.style.display="none")}}function pt(){if(Z||we||!ne?.matches)return Promise.resolve();const a=T.getBoundingClientRect();if(a.height>=en()*.8)return Promise.resolve();we=!0,Ae=n.div({width:`${a.width}px`,height:`${a.height}px`}),Ae.className="ago-chat-widget-spacer",Ae.setAttribute("aria-hidden","true"),Re=en(),T.style.setProperty("--ago-vh",`${Re}px`),tn(),Qn(),n.lockBackgroundScroll(Je);const l=Zn(()=>eo(!0));return l.then(()=>{Z||(Jn(),gt())}),Jn(),y?.(),l}function ut(){if(!we)return Promise.resolve();et(),we=!1,nn(),n.unlockBackgroundScroll(Je),T.querySelector("textarea")?.blur();const a=Zn(()=>eo(!1));return a.then(()=>{Z||T.style.removeProperty("--ago-vh")}),Re=0,k?.(),a}}exports.DEFAULT_FEEDBACK_LABELS=pn;exports.DEFAULT_SPEECH_TO_TEXT_LABELS=n.DEFAULT_SPEECH_TO_TEXT_LABELS;exports.DEFAULT_TOOL_CALL_FORM_LABELS=To;exports.DEFAULT_WIDGET_LABELS=an;exports.colorsToTheme=n.colorsToTheme;exports.compactMediaQuery=n.compactMediaQuery;exports.createSheetController=n.createSheetController;exports.mountChatWidget=Ar;exports.readableTextColor=n.readableTextColor;exports.renderMarkdown=Me;
|
|
3
|
+
`);let o=0;for(;o<i.length;){const s=i[o];if(s.trim()===""){o++;continue}const c=s.match(ho);if(c){const f=c[1][0],p=[];for(o++;o<i.length&&!new RegExp(`^ {0,3}${f==="`"?"`{3,}":"~{3,}"}\\s*$`).test(i[o]);)p.push(i[o]),o++;o++;const x=de("pre",{margin:"0 0 8px 0"});x.appendChild(de("code",{display:"block",background:"#f5f5f5",padding:"8px 12px",borderRadius:"6px",fontSize:"13px",overflowX:"auto",fontFamily:fo,whiteSpace:"pre"},Xe(p.join(`
|
|
4
|
+
`)))),e.appendChild(x);continue}if(mo.test(s)){e.appendChild(de("hr",{border:"none",borderTop:"1px solid #dee3e8",margin:"12px 0"})),o++;continue}const d=s.match(go);if(d){const f=d[1].length;e.appendChild(de(`h${f}`,{margin:"16px 0 8px 0",fontSize:bi[f-1],fontWeight:"600",lineHeight:"1.3"},ze(d[2]))),o++;continue}if(Ot.test(s)){const f=[];for(;o<i.length&&Ot.test(i[o]);)f.push(i[o].replace(Ot,"")),o++;const p=de("blockquote",{borderLeft:"4px solid #dee3e8",paddingLeft:"12px",margin:"0 0 8px 0",fontStyle:"italic",color:"#6b6d6f"});p.appendChild(Me(f.join(`
|
|
5
|
+
`))),e.appendChild(p);continue}if(s.includes("|")&&Ci(i[o+1])){const f=[s,i[o+1]];for(o+=2;o<i.length&&i[o].includes("|")&&i[o].trim();)f.push(i[o]),o++;e.appendChild(yi(f));continue}if(Ye.test(s)){const f=[],p=sn(s);for(;o<i.length&&i[o].trim()!=="";)if(Ye.test(i[o])||sn(i[o])>p)f.push(i[o]),o++;else break;e.appendChild(bo(f));continue}const h=[s];for(o++;o<i.length&&!xi(i[o]);)h.push(i[o]),o++;e.appendChild(de("p",{margin:"0 0 8px 0",lineHeight:"1.6"},h.map(f=>ze(f)).join("<br>")))}const r=e.lastElementChild;return r&&(r.style.marginBottom="0"),e}function vi(t,e){const i=n.div({display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"6px",justifyContent:e.isUser?"flex-end":"flex-start",maxWidth:"75%"});i.className="ago-message__attachments";for(const o of t){const r=_e.safeAttachmentUrl(o.url);if(_e.canInlineImage(o)&&r){const p=document.createElement("a");p.href=r,p.target="_blank",p.rel="noopener noreferrer",n.css(p,{display:"inline-block",textDecoration:"none"});const x=document.createElement("img");x.src=r,x.alt=o.name,x.loading="lazy",n.css(x,{maxWidth:"180px",maxHeight:"160px",objectFit:"cover",borderRadius:"10px",border:`1px solid ${n.BORDER_COLOR}`,display:"block"}),p.appendChild(x),i.appendChild(p);continue}const s=r?document.createElement("a"):document.createElement("div");r&&s instanceof HTMLAnchorElement&&(s.href=r,s.target="_blank",s.rel="noopener noreferrer"),n.css(s,{display:"inline-flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"10px",border:`1px solid ${n.BORDER_COLOR}`,backgroundColor:e.cardBackground,color:e.cardColor,fontSize:"13px",textDecoration:"none",maxWidth:"220px"});const c=document.createElement("span");c.textContent="📄",c.setAttribute("aria-hidden","true"),n.css(c,{fontSize:"16px",lineHeight:"1",flexShrink:"0"});const d=n.div({display:"flex",flexDirection:"column",minWidth:"0"}),h=n.div({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",maxWidth:"160px"});h.textContent=o.name,h.title=o.name,d.appendChild(h);const f=_e.formatFileSize(o.fileSize);if(f){const p=n.div({fontSize:"11px",color:n.MUTED_TEXT_COLOR});p.textContent=f,d.appendChild(p)}s.append(c,d),i.appendChild(s)}return i}function xo(t,e){const i=e.look==="embed",o=n.div({display:"flex",flexWrap:"wrap",gap:"8px",marginTop:i?"16px":"10px"});o.className="ago-message__followups";for(const r of t){const s=document.createElement("button");if(s.type="button",s.className="ago-message__followup-btn",s.textContent=r,s.disabled=!e.enabled,n.css(s,i?{display:"inline-flex",alignItems:"center",padding:"8px",fontSize:"14px",lineHeight:"20px",font:"inherit",color:"#525252",backgroundColor:"#fff",border:"1px solid #e5e5e5",borderRadius:"12px",boxShadow:"0 1px 2px 0 rgba(0,0,0,0.05)",cursor:e.enabled?"pointer":"default",transition:"background-color 0.15s"}:{minHeight:"44px",padding:"6px 14px",fontSize:"14px",borderRadius:n.MESSAGE_RADIUS,border:`1px solid ${n.BORDER_COLOR}`,backgroundColor:n.PANEL_BACKGROUND,color:n.TEXT_COLOR,cursor:e.enabled?"pointer":"default",transition:"border-color 0.15s"}),e.handler){const c=e.handler;s.addEventListener("click",()=>c(r))}s.addEventListener("mouseenter",()=>{i?s.style.backgroundColor="#fafafa":s.style.borderColor=n.ACCENT_COLOR}),s.addEventListener("mouseleave",()=>{i?s.style.backgroundColor="#fff":s.style.borderColor=n.BORDER_COLOR}),o.appendChild(s)}return o}function Ei(t,e){const{isLast:i,isLastOfBlock:o,bubbleStyle:r,showAgentName:s,agentBubble:c,followUpEnabled:d,followUpHandler:h,isMobile:f,feedbackRow:p}=e,x=t.role==="user",I=r==="imessage",w=n.div({display:"flex",flexDirection:"column",alignItems:x?"flex-end":"flex-start",marginBottom:I&&!o?"2px":"16px"});if(w.className=`ago-message ago-message--${t.role}`,!x&&s&&t.agent){const E=n.div({fontSize:"13px",fontWeight:"500",color:n.TEXT_COLOR,marginBottom:"6px",padding:"0 4px"});E.className="ago-message__agent",E.textContent=t.agent.displayName||t.agent.name,w.appendChild(E)}if(!x&&t.sources&&t.sources.length>0){const E=n.div({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"6px",marginBottom:"10px",width:"100%",maxWidth:"85%"});E.className="ago-message__sources",t.sources.forEach((O,W)=>{const C=O.url?document.createElement("a"):document.createElement("div");O.url&&C instanceof HTMLAnchorElement&&(C.href=O.url,C.target="_blank",C.rel="noopener noreferrer"),n.css(C,{display:"flex",alignItems:"center",gap:"8px",padding:"8px 10px",border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"8px",backgroundColor:n.PANEL_BACKGROUND,textDecoration:"none",color:n.TEXT_COLOR,fontSize:"12px",overflow:"hidden"});const F=n.div({flexShrink:"0",width:"18px",height:"18px",borderRadius:"3px",border:`1px solid ${n.ACCENT_COLOR}`,color:n.ACCENT_COLOR,fontSize:"11px",fontWeight:"500",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"#f0f4ff"});F.textContent=String(W+1);const y=n.div({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});y.textContent=O.title,y.title=O.title,C.append(F,y),E.appendChild(C)}),w.appendChild(E)}if(t.attachments&&t.attachments.length>0&&w.appendChild(vi(t.attachments,{isUser:x,cardBackground:x?"rgba(255,255,255,0.12)":n.PANEL_BACKGROUND,cardColor:x?n.BRAND_TEXT_COLOR:n.TEXT_COLOR})),!x&&e.renderToolCall&&t.toolCalls?.length)for(const E of t.toolCalls){const O=e.renderToolCall(E,t);O&&w.appendChild(O)}const u=x||c||I,v=!!t.content||t.status==="IN_PROGRESS"||t.status==="WAITING_CLIENT",A=n.div({maxWidth:u?I||x?f?"88%":"75%":f?"92%":"85%":"100%",padding:u?"10px 14px":"2px 8px",borderRadius:I?n.MESSAGE_RADIUS_IMESSAGE:u?n.MESSAGE_RADIUS:"0",backgroundColor:x?n.BRAND_COLOR:u?n.AGENT_BUBBLE_BACKGROUND:"transparent",color:x?n.BRAND_TEXT_COLOR:n.TEXT_COLOR,overflowWrap:"break-word",textWrap:"pretty",fontSize:"16px",lineHeight:"1.6"});if(A.className="ago-message__content",I&&o){A.style.position="relative";const E=n.div({position:"absolute",zIndex:"0",bottom:"-2px",width:"20px",height:"20px",background:x?n.BRAND_COLOR:n.AGENT_BUBBLE_BACKGROUND});E.className="ago-message__tail";const O=n.div({position:"absolute",zIndex:"1",bottom:"-2px",width:"10px",height:"20px",background:n.MESSAGES_BACKGROUND});O.className="ago-message__tail-mask",x?(E.style.right="-8px",E.style.borderBottomLeftRadius="16px 14px",O.style.right="-10px",O.style.borderBottomLeftRadius="10px"):(E.style.left="-7px",E.style.borderBottomRightRadius="16px 14px",O.style.left="-10px",O.style.borderBottomRightRadius="10px"),A.append(E,O)}return t.content?A.appendChild(Me(t.content)):(t.status==="IN_PROGRESS"||t.status==="WAITING_CLIENT")&&A.appendChild(ki()),v&&w.appendChild(A),!x&&p&&w.appendChild(p),i&&t.followUpReplies&&t.followUpReplies.length>0&&w.appendChild(xo(t.followUpReplies,{enabled:d,handler:h,look:"classic"})),w}function wi(t){const e=n.div({display:"flex",alignItems:"center",gap:"8px",padding:"10px 14px",backgroundColor:"#f0fdf4",color:"#15803d",borderRadius:n.MESSAGE_RADIUS,marginTop:"8px",fontSize:"13px",border:"1px solid #bbf7d0"});e.className="ago-form-notice",e.setAttribute("role","status");const i=document.createElement("span");i.textContent="✓",i.setAttribute("aria-hidden","true"),n.css(i,{fontWeight:"700"});const o=document.createElement("span");return o.textContent=t,e.append(i,o),e}function ki(){const t=n.div({display:"flex",gap:"4px",padding:"4px 0"});for(let e=0;e<3;e++){const i=n.div({width:"6px",height:"6px",borderRadius:"50%",backgroundColor:"currentColor",opacity:"0.55",animation:"ago-pulse 1.2s ease-in-out infinite",animationDelay:`${e*.2}s`});t.appendChild(i)}return t}function _i(){const t="http://www.w3.org/2000/svg",e=document.createElementNS(t,"svg");e.setAttribute("width","26"),e.setAttribute("height","26"),e.setAttribute("viewBox","0 0 24 24"),e.setAttribute("fill","none");const i=document.createElementNS(t,"path");return i.setAttribute("d","M21 11.5a8.38 8.38 0 0 1-8.5 8.5 8.5 8.5 0 0 1-3.8-.9L3 21l1.9-5.7a8.5 8.5 0 0 1-.9-3.8 8.38 8.38 0 0 1 8.5-8.5 8.38 8.38 0 0 1 8.5 8.5z"),i.setAttribute("stroke","currentColor"),i.setAttribute("stroke-width","2"),i.setAttribute("stroke-linecap","round"),i.setAttribute("stroke-linejoin","round"),e.appendChild(i),e}function Si(t){const e=document.createElement("button");if(e.type="button",e.className="ago-chat-widget-launcher",e.setAttribute("aria-label",`Open ${t.title}`),e.setAttribute("aria-expanded","false"),t.look==="classic"){if(n.css(e,{position:"fixed",bottom:"20px",[t.edge]:"20px",width:"56px",height:"56px",borderRadius:"50%",border:"none",backgroundColor:n.BRAND_COLOR,color:n.BRAND_TEXT_COLOR,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",zIndex:"2147483000",boxShadow:"rgba(15, 15, 15, 0.2) 0px 4px 14px 0px",fontFamily:n.FONT_VAR}),t.icon){const r=document.createElement("img");r.src=t.icon,r.alt="",n.css(r,{width:"26px",height:"26px",objectFit:"contain"}),e.appendChild(r)}else e.appendChild(_i());return e.addEventListener("click",t.onClick),{el:e,setOpen:r=>{e.setAttribute("aria-expanded",r?"true":"false"),e.setAttribute("aria-label",`${r?"Close":"Open"} ${t.title}`)}}}n.css(e,{position:"fixed",bottom:"20px",[t.edge]:"20px",width:"54px",height:"54px",padding:"12px",margin:"0",boxSizing:"border-box",border:"none",borderRadius:"50%",backgroundColor:n.LAUNCHER_BACKGROUND,color:n.LAUNCHER_TEXT_COLOR,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",boxShadow:"0 4px 12px rgba(123, 123, 123, 0.3)",transition:"scale 0.2s ease",zIndex:"2147483001",transform:"translateZ(0)",backfaceVisibility:"hidden",willChange:"transform",contain:"layout style paint",fontFamily:n.FONT_VAR}),e.addEventListener("mouseenter",()=>{e.style.scale="1.1",e.style.boxShadow="0 6px 16px rgba(123, 123, 123, 0.4)"}),e.addEventListener("mouseleave",()=>{e.style.scale="1",e.style.boxShadow="0 4px 12px rgba(123, 123, 123, 0.3)"});let i,o;if(t.icon){const r=document.createElement("img");r.src=t.icon,r.alt="",n.css(r,{width:"32px",height:"32px",objectFit:"contain"}),i=r,o=n.launcherCloseIcon(),e.append(r,o)}else{const r=n.launcherIcon();i=r.querySelector('[data-ago-path="open"]'),o=r.querySelector('[data-ago-path="close"]'),e.appendChild(r)}return o.style.display="none",e.addEventListener("click",t.onClick),{el:e,setOpen:r=>{i.style.display=r?"none":"",o.style.display=r?"":"none",e.setAttribute("aria-expanded",r?"true":"false"),e.setAttribute("aria-label",`${r?"Close":"Open"} ${t.title}`)}}}function Ti(t){const e=n.div({marginBottom:"12px",display:"flex",flexWrap:"wrap",gap:"8px"});e.className="ago-message__attachments";for(const i of t.attachments??[]){const o=_e.safeAttachmentUrl(i.url),r=n.div({display:"flex",alignItems:"center",gap:"8px",backgroundColor:"#f3f4f6",borderRadius:"8px",padding:"8px 12px",fontSize:"14px",lineHeight:"20px",maxWidth:"100%",boxSizing:"border-box"});if(_e.canInlineImage(i)&&o){const s=document.createElement("a");s.href=o,s.target="_blank",s.rel="noopener noreferrer",n.css(s,{display:"flex",flexDirection:"column",gap:"4px",textDecoration:"none",color:"inherit"});const c=document.createElement("img");c.src=o,c.alt=i.name,c.loading="lazy",n.css(c,{height:"128px",maxWidth:"100%",objectFit:"contain",borderRadius:"4px",display:"block"});const d=n.div({fontSize:"12px",lineHeight:"16px",color:"#4b5563",maxWidth:"150px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});d.textContent=i.name,s.append(c,d),r.appendChild(s)}else{const s=o?document.createElement("a"):document.createElement("span");o&&s instanceof HTMLAnchorElement&&(s.href=o,s.target="_blank",s.rel="noopener noreferrer",s.download=i.name),n.css(s,{display:"flex",alignItems:"center",gap:"8px",textDecoration:"none",color:"inherit",minWidth:"0"});const c=document.createElement("span");c.textContent=i.name,c.title=i.name,n.css(c,{maxWidth:"150px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),s.append(n.downloadIcon({size:20}),c);const d=_e.formatFileSize(i.fileSize);if(d){const h=document.createElement("span");h.textContent=d,n.css(h,{fontSize:"12px",lineHeight:"16px",color:"#6b7280"}),s.appendChild(h)}r.appendChild(s)}e.appendChild(r)}return e}function Ri(t){const e=n.div({display:"flex",justifyContent:"flex-end"}),i=n.div({maxWidth:"70%",borderRadius:"16px",marginBottom:"16px",padding:"16px",backgroundColor:n.USER_BUBBLE_BACKGROUND_EMBED,color:n.USER_BUBBLE_TEXT_EMBED,boxSizing:"border-box",fontSize:"14px",lineHeight:"24px"});i.className="ago-message__content",t.attachments?.length&&i.appendChild(Ti(t));const o=n.div({whiteSpace:"pre-wrap",overflowWrap:"break-word"});return o.textContent=t.content,i.appendChild(o),e.appendChild(i),e}function Ai(t){const e=n.div({display:"grid",gridTemplateColumns:"1fr 1fr",gap:"8px",paddingBottom:"16px"});return e.className="ago-message__sources",(t.sources??[]).forEach((i,o)=>{const r=i.url?document.createElement("a"):document.createElement("div");i.url&&r instanceof HTMLAnchorElement&&(r.href=i.url,r.target="_blank",r.rel="noopener noreferrer"),n.css(r,{display:"inline-flex",alignItems:"center",height:"48px",justifyContent:"flex-start",padding:"8px 16px",border:`1px solid ${n.NEUTRAL_BORDER}`,backgroundColor:"#fff",borderRadius:"6px",boxShadow:n.SHADOW_SM,fontSize:"14px",fontWeight:"500",color:n.TEXT_COLOR,textDecoration:"none",overflow:"hidden",boxSizing:"border-box",transition:"background-color 0.15s"}),r.addEventListener("mouseenter",()=>{r.style.backgroundColor="#f5f5f5"}),r.addEventListener("mouseleave",()=>{r.style.backgroundColor="#fff"});const s=n.div({display:"flex",alignItems:"center",gap:"8px",width:"100%",minWidth:"0"}),c=n.div({flexShrink:"0",width:"16px",height:"16px",borderRadius:"4px",border:`1px solid ${n.PRIMARY_ACCENT}`,color:n.PRIMARY_ACCENT,backgroundColor:n.PRIMARY_FOREGROUND,fontSize:"12px",lineHeight:"1",display:"flex",alignItems:"center",justifyContent:"center"});c.textContent=String(o+1);const d=n.div({fontSize:"12px",lineHeight:"16px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:"0"});d.textContent=i.title,d.title=i.title,s.append(c,d),r.appendChild(s),e.appendChild(r)}),e}function Oi(t,e){return yo({errorTitle:t,errorDescription:e})}function yo(t){const e=n.div({position:"relative",width:"100%",borderRadius:"12px",border:"1px solid rgba(239, 68, 68, 0.5)",padding:"12px 16px 12px 44px",fontSize:"14px",lineHeight:"20px",color:"#ef4444",backgroundColor:"#fff",boxSizing:"border-box"});e.className="ago-message__error",e.setAttribute("role","alert");const i=n.alertCircleIcon({size:16});n.css(i,{position:"absolute",left:"16px",top:"16px"});const o=document.createElement("h5");o.textContent=t.errorTitle,n.css(o,{margin:"0 0 4px",fontSize:"14px",fontWeight:"500",lineHeight:"1",letterSpacing:"-0.025em"});const r=n.div({fontSize:"14px",lineHeight:"1.625"});return r.textContent=t.errorDescription,e.append(i,o,r),e}function Li(){const t=n.div({marginTop:"4px",animation:"ago-skeleton-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"});t.className="ago-message__skeleton";const e=n.div({height:"16px",backgroundColor:"#f1f5f9",borderRadius:"4px",width:"75%",marginBottom:"10px"});return t.appendChild(e),t}function Ni(){const t=n.div({display:"flex",alignItems:"center",padding:"8px",gap:"8px"});t.className="ago-message__spinner";const e=n.spokeSpinnerIcon({size:20});return n.css(e,{color:"#a1a1aa",animation:"ago-spin 1s linear infinite"}),t.appendChild(e),t}function Fi(t,e){const i=t.status==="IN_PROGRESS"||t.status==="WAITING_CLIENT",o=n.div({position:"relative",display:"flex",alignItems:"flex-start",borderRadius:"16px",padding:"8px",marginBottom:"16px",boxSizing:"border-box"});o.className="ago-message__row",e.agentRowTinted&&(o.style.backgroundColor=n.AGENT_BUBBLE_BACKGROUND),e.agentRowTextTinted&&(o.style.color=n.AGENT_BUBBLE_TEXT);const r=n.div({flex:"1",minWidth:"0",overflow:"hidden",padding:"0 4px",fontSize:"14px",lineHeight:"24px"});if(r.className="ago-message__body",i&&r.appendChild(Ni()),t.sources?.length&&r.appendChild(Ai(t)),e.renderToolCall&&t.toolCalls?.length)for(const s of t.toolCalls){const c=e.renderToolCall(s,t);c&&r.appendChild(c)}if(t.status==="ERROR")r.appendChild(yo(e.labels));else if(t.content){const s=n.div({});s.className="ago-message__markdown ago-message__content",s.appendChild(Me(t.content)),r.appendChild(s)}else i&&r.appendChild(Li());return e.isLast&&t.status==="DONE"&&t.followUpReplies?.length&&r.appendChild(xo(t.followUpReplies,{enabled:e.followUpEnabled,handler:e.followUpHandler,look:"embed"})),e.actionsRow&&!i&&r.appendChild(e.actionsRow),o.appendChild(r),o}function Ii(t,e){const i=n.div({});return i.className=`ago-message ago-message--${t.role}`,i.dataset.messageId=t.id,i.dataset.messageRole=t.role,i.appendChild(t.role==="user"?Ri(t):Fi(t,e)),i}var ln="ago-hs-form-ready";function Di(t,e){const i=t.tagName==="TEXTAREA"?Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,"value"):Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"value"),o=t._valueTracker;o&&o.setValue(""),t.focus(),t.dispatchEvent(new Event("focus",{bubbles:!0})),i?.set?i.set.call(t,e):t.value=e,t.setAttribute("value",e),t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})),t.dispatchEvent(new Event("blur",{bubbles:!0}))}function Nt(t,e){const i=t.querySelectorAll("input, textarea, select");let o=!1;for(const r of i){if(r.type==="hidden"||r.type==="submit"||r.type==="button")continue;const s=e[r.name]??(r.name.includes("/")?e[r.name.split("/").pop()]:void 0);s&&!r.value&&(Di(r,s),o=!0)}return o}function Bi(t){return`function($f){document.dispatchEvent(new CustomEvent(${JSON.stringify(ln)},{detail:{token:${JSON.stringify(t)},form:$f}}))}`}function Hi(t,e,i){return!t||!e||Object.keys(e).length===0?t:/hbspt\.forms\.create\s*\(\s*\{/.test(t)&&!/onFormReady/.test(t)?t.replace(/hbspt\.forms\.create\s*\(\s*\{/g,`hbspt.forms.create({onFormReady:${Bi(i)},`):t}function zi(t,e){if(!t||Object.keys(t).length===0)return()=>{};const i={};for(const[c,d]of Object.entries(t))d!=null&&d!==""&&(i[c]=d);const o=[],r=[],s=c=>{const d=c.detail;if(!d||d.token!==e)return;const h=d.form,f=h&&typeof h=="object"&&"jquery"in h&&h.jquery?h[0]:h;if(!f||typeof f.querySelectorAll!="function")return;Nt(f,i);const p=new MutationObserver(()=>{Nt(f,i)});p.observe(f,{childList:!0,subtree:!0}),o.push(p),r.push(setTimeout(()=>p.disconnect(),1e4))};return document.addEventListener(ln,s),()=>{document.removeEventListener(ln,s),o.forEach(c=>c.disconnect()),r.forEach(c=>clearTimeout(c))}}function Co(){return globalThis.HubSpotFormsV4}async function vo(t,e){let i=null;if(t.getFormFieldValues)try{const o=await t.getFormFieldValues();let r=[];Array.isArray(o)?r=o.filter(s=>typeof s=="object"&&s!==null).map(s=>s.name).filter(s=>typeof s=="string"):typeof o=="object"&&o!==null&&(r=Object.keys(o)),r.length>0&&(i=r)}catch{}for(const[o,r]of Object.entries(e)){if(!r)continue;let s;if(o.includes("/"))s=o;else if(i){const c=i.find(d=>d.endsWith("/"+o));if(!c)continue;s=c}else s=`0-1/${o}`;try{t.setFieldValue(s,r)}catch{}}}function ro(t){if(!t||Object.keys(t).length===0)return()=>{};const e=i=>{try{const o=Co()?.getFormFromEvent?.(i);if(!o?.setFieldValue)return;vo(o,t)}catch{}};return window.addEventListener("hs-form-event:on-ready",e),()=>window.removeEventListener("hs-form-event:on-ready",e)}function Mi(t){const e=Co()?.getForms?.();if(!Array.isArray(e)||e.length===0)return!1;for(const i of e)i?.setFieldValue&&vo(i,t);return!0}var dn="ago-hs-form-submit",cn="ago-hs-form-submitted";function Lt(t){if(!t||typeof t!="object")return t;let e;if(Array.isArray(t)){e={};for(const o of t)o&&typeof o=="object"&&"name"in o&&o.name&&o.value!==void 0&&(e[o.name]=o.value)}else e=t;const i={};for(const[o,r]of Object.entries(e)){const s=o.replace(/^\d+-\d+\//,"");s.startsWith("hs_")||s.startsWith("HS_")||s==="LEGAL_CONSENT"||s==="legal_consent"||s!=="goToWebinarWebinarKey"&&(r===""||r===null||r===void 0||typeof r=="string"&&r.length>2e3||(i[s]=r))}return Object.keys(i).length>0?i:null}function $i(t){try{const e=new FormData(t),i={};return e.forEach((o,r)=>{o instanceof File||(i[r]=o)}),Object.keys(i).length>0?i:null}catch{return null}}function ao(t,e,i){const o=i?`{token:${JSON.stringify(e)},form:$f}`:`{token:${JSON.stringify(e)}}`;return`function(${i?"$f":""}){document.dispatchEvent(new CustomEvent(${JSON.stringify(t)},{detail:${o}}))}`}function Ui(t,e){return t&&(/hbspt\.forms\.create\s*\(\s*\{/.test(t)&&!t.includes("ago-hs-form-submitted")?t.replace(/hbspt\.forms\.create\s*\(\s*\{/g,`hbspt.forms.create({onFormSubmit:${ao(dn,e,!0)},onFormSubmitted:${ao(cn,e,!1)},`):t)}function Wi(t,e,i,o){let r=!1,s=null;function c(){r||(r=!0,e(Lt(s)))}function d(u){if(s||(s=$i(u)),u.closest(".hs-form, .hbspt-form, [data-hs-forms]")){i?.();return}c()}const h=u=>{const v=u.target;v?.tagName==="FORM"&&d(v)};t.addEventListener("submit",h,!0);const f=new WeakSet;function p(u){f.has(u)||(f.add(u),u.addEventListener("submit",()=>d(u)))}for(const u of t.querySelectorAll("form"))p(u);const x=new MutationObserver(()=>{for(const u of t.querySelectorAll("form"))p(u)});x.observe(t,{childList:!0,subtree:!0});const I=u=>{const v=u.detail;if(!(!v||v.token!==o))try{const A=v.form,E=A&&typeof A=="object"&&"jquery"in A&&A.jquery?A[0]:A;if(E?.querySelectorAll){const O=E.querySelectorAll("input, textarea, select"),W={};for(const C of O)C.name&&C.type!=="submit"&&C.type!=="button"&&(W[C.name]=C.value||"");Object.keys(W).length>0&&(s=W)}}catch{}},w=u=>{const v=u.detail;!v||v.token!==o||c()};return document.addEventListener(dn,I),document.addEventListener(cn,w),()=>{t.removeEventListener("submit",h,!0),x.disconnect(),document.removeEventListener(dn,I),document.removeEventListener(cn,w)}}function ie(t){return t.externalId||t.id}function Eo(t){return t.conditionalFieldValues?.length?t.conditionalFieldValues:t.conditionalFieldValue?.split(",").map(e=>e.trim()).filter(Boolean)??[]}function mn(t,e){return!t.priorityTypologies?.length||!e||t.priorityTypologies.includes(e)}function wo(t,e,i,o,r,s){if(!e||!i.length)return!0;const c=t.fields.find(d=>d.id===e||d.externalId===e);return c?Ft(t,c,o,r,s)&&i.includes(o[ie(c)]):!0}function Ft(t,e,i,o="",r=new Set){if(e.active===!1||r.has(e.id)||e.title==="Priority"&&!mn(t,o))return!1;const s=new Set(r).add(e.id);return wo(t,e.conditionalFieldId,Eo(e),i,o,s)}function ko(t,e,i,o=""){return e.options.filter(r=>wo(t,r.conditionalFieldId,r.conditionalFieldValues??[],i,o,new Set)).sort((r,s)=>(r.position??0)-(s.position??0))}function Ke(t,e,i=""){let o;do{o=!1;for(const r of t.fields){const s=ie(r);if(!(s in e))continue;const c=!r.options.length||!e[s]||ko(t,r,e,i).some(d=>(d.value??d.name??"")===e[s]);(!Ft(t,r,e,i)||!c)&&(delete e[s],o=!0)}}while(o)}function Pi(t,e,i=""){const o=[...t.fields].sort((r,s)=>r.position-s.position).filter(r=>!r.hidden&&Ft(t,r,e,i));return o.filter((r,s)=>{if(s===0||r.alwaysVisible||r.conditionalFieldId&&Eo(r).length)return!0;const c=o[s-1];return c.type==="checkbox"||!!e[ie(c)]?.trim()})}var ji="var(--ago-send-button-background, var(--ago-accent-color, #003edf))",Gi=/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z]{2,}$/;function Vi(t){return t.toLowerCase().trim().replace(/[^a-z0-9_]/g,"_")}function _o(t,e,i){const o={};if(e){for(const r of e.fields){if(r.active===!1)continue;const s=r.options.find(c=>c.default);s&&(o[ie(r)]=s.value??s.name??"")}if(t?.tag)for(const r of e.fields)r.type==="tagger"&&(o[ie(r)]=t.tag);if(t?.custom_fields)for(const[r,s]of Object.entries(t.custom_fields)){const c=e.fields.find(d=>d.externalId===r||d.id===r||(d.title?Vi(d.title)===r:!1));c&&(o[ie(c)]=s)}}return e&&Ke(e,o,t?.typology??"Question"),{ticket:{subject:t?.subject??"",typology:t?.typology??"Question",priority:t?.priority??"Normal",body:t?.body??"",tag:t?.tag??""},customFields:o,files:[],email:i,errors:{},submittedOnce:!1,loading:!1,submitError:null}}function qi(t,e,i){t.customFields={..._o(e,i,t.email).customFields,...t.customFields},Ke(i,t.customFields,t.ticket.typology)}function so(t,e){return t.replace(/\{(\w+)\}/g,(i,o)=>e[o]??"")}function Xi(t,e,i,o){const r={},s=e.ticket;t.showSubject&&!s.subject.trim()&&(r.subject=i.subjectRequired),t.showTypology&&!s.typology.trim()&&(r.typology=i.typologyRequired),t.showPriority&&mn(t,s.typology)&&!s.priority.trim()&&(r.priority=i.priorityRequired),t.showBody&&!s.body.trim()&&(r.body=i.detailedContextRequired);for(const c of t.fields){if(c.hidden||!Ft(t,c,e.customFields,s.typology))continue;const d=e.customFields[ie(c)];if(c.required&&!d?.trim())r[ie(c)]=so(i.fieldRequired,{fieldTitle:c.title??""});else if(c.regexpForValidation&&d?.trim())try{new RegExp(c.regexpForValidation).test(d)||(r[ie(c)]=so(i.fieldFormatInvalid,{fieldTitle:c.title??""}))}catch{}}return o&&(e.email.trim()?Gi.test(e.email)||(r.userEmail=i.emailInvalid):r.userEmail=i.emailRequired),r}var Ki={border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"4px",width:"100%",padding:"8px",boxSizing:"border-box",fontSize:"16px",lineHeight:"24px",fontFamily:n.FONT_VAR,color:n.TEXT_COLOR,backgroundColor:n.PANEL_BACKGROUND};function De(t,e){const i=document.createElement("label");return i.htmlFor=e,i.textContent=t,n.css(i,{display:"block",fontWeight:"600"}),i}function he(t){const e=document.createElement("p");return e.className="ago-ticket-form__error",e.textContent=t,n.css(e,{color:"#ef4444",fontSize:"14px",lineHeight:"20px",margin:"0"}),e}function Be(){const t=n.div({display:"flex",flexDirection:"column",gap:"8px"});return t.className="ago-ticket-form__field",t}function He(t,e,i){n.css(t,Ki),e&&(t.style.borderColor="#ef4444"),t.disabled=i,i&&(t.style.opacity="0.5",t.style.cursor="not-allowed"),t.addEventListener("focus",()=>{t.style.outline="2px solid var(--ago-accent-color, #003edf)",t.style.outlineOffset="1px"}),t.addEventListener("blur",()=>{t.style.outline="",t.style.outlineOffset=""})}function So(t){const e=n.div({padding:"16px",borderRadius:"4px",backgroundColor:"#dcfce7",color:"#166534",fontSize:"16px",lineHeight:"24px"});e.className="ago-ticket-form__success",e.setAttribute("role","status");const i=document.createElement("p");if(i.textContent=t.text,n.css(i,{whiteSpace:"pre-line",margin:"0"}),e.appendChild(i),t.ticketUrl){const o=n.div({marginTop:"4px"});if(o.append(document.createTextNode(`${t.urlLabel} `)),t.ticketUrl.startsWith("http")){const r=document.createElement("a");r.href=t.ticketUrl,r.target="_blank",r.rel="noreferrer noopener",r.textContent=t.ticketUrl,n.css(r,{fontWeight:"700",textDecoration:"underline",color:"#166534"}),o.appendChild(r)}else{const r=document.createElement("span");r.textContent=t.ticketUrl,r.style.fontWeight="700",o.appendChild(r)}e.appendChild(o)}return e}function Yi(t){const e=n.div({width:"100%",padding:"16px",backgroundColor:"#fefce8",border:"1px solid #fef08a",borderRadius:"6px",display:"flex",gap:"12px",alignItems:"flex-start",color:"#854d0e",boxSizing:"border-box",fontSize:"16px",lineHeight:"24px"});e.className="ago-ticket-form__denied";const i=document.createElement("span");i.textContent="i",i.setAttribute("aria-hidden","true"),n.css(i,{flexShrink:"0",width:"20px",height:"20px",marginTop:"2px",borderRadius:"50%",border:"2px solid #ca8a04",color:"#ca8a04",fontSize:"13px",fontWeight:"700",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:"1"});const o=n.div({minWidth:"0"});return o.appendChild(Me(t)),e.append(i,o),e}function Qi(t){const{state:e,labels:i}=t;let o=t.ticketForm,r=t.configLoading,s=t.allowFiles;const c=n.div({position:"relative",width:"100%",display:"flex",flexDirection:"column",gap:"16px",paddingBottom:"16px",fontSize:"16px",lineHeight:"24px",color:n.TEXT_COLOR,boxSizing:"border-box"});c.className="ago-ticket-form";function d(){return o?(e.errors=Xi(o,e,i,t.requireEmail),Object.keys(e.errors).length===0):!1}async function h(){if(!(e.loading||!o)){if(Ke(o,e.customFields,e.ticket.typology),e.submittedOnce=!0,e.submitError=null,!d()){e.submitError=`${i.validationFailed}: ${i.pleaseCheckFields}`,w();return}e.loading=!0,w();try{const u=await t.createTicket({subject:e.ticket.subject,typology:e.ticket.typology||"Question",priority:e.ticket.priority||"Normal",body:e.ticket.body,files:e.files,customFields:Object.entries(e.customFields).map(([v,A])=>({id:v,value:A})),email:t.requireEmail?e.email:void 0,ticketFormId:o.id});e.loading=!1,e.submitted={ticketId:u.id,ticketUrl:u.url},w(),t.onCreated(u,e)}catch(u){e.loading=!1;const v=u instanceof Error?u:new Error(String(u)),A=v.status;let E=i.submissionFailed,O=i.submissionFailedDescription;A===413?E=i.fileTooLarge:A===403?E=i.permissionDenied:A===422?(E=i.validationFailed,O=v.message||i.pleaseCheckFields):v.message&&(O=v.message),e.submitError=`${E}: ${O}`,w(),t.onError?.(v)}}}function f(u,v){const A=ie(u);e.customFields[A]=v,o&&Ke(o,e.customFields,e.ticket.typology),e.submittedOnce&&d(),w()}function p(){e.submittedOnce&&d()}function x(u){const v=ie(u),A=`ago-ticket-field-${v}`,E=e.customFields[v]??"",O=e.loading,W=e.errors[v];if(u.type==="checkbox"){const k=n.div({display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"});k.className="ago-ticket-form__field";const S=document.createElement("input");S.type="checkbox",S.id=A,S.checked=E==="true",S.disabled=O,n.css(S,{width:"16px",height:"16px",margin:"0"}),S.addEventListener("change",()=>f(u,S.checked?"true":"false"));const D=document.createElement("label");return D.htmlFor=A,D.textContent=u.title??"",D.style.fontWeight="600",k.append(S,D),W&&k.appendChild(he(W)),k}const C=Be();C.appendChild(De(u.title??"",A));const F=ko(o,u,e.customFields,e.ticket.typology).filter(k=>!k.noDisplay);if(u.options.length>0){const k=document.createElement("select");k.id=A;const S=document.createElement("option");S.value="",S.textContent="----",k.appendChild(S);const D=new Map;for(const M of F){const j=document.createElement("option");if(j.value=M.value??M.name??"",j.textContent=M.name??M.value??"",M.group){let b=D.get(M.group);b||(b=document.createElement("optgroup"),b.label=M.group,D.set(M.group,b),k.appendChild(b)),b.appendChild(j)}else k.appendChild(j)}k.value=E,He(k,!!W,O),k.addEventListener("change",()=>f(u,k.value)),C.appendChild(k);const V=F.find(M=>(M.value??M.name)===E);if(W&&C.appendChild(he(W)),V?.message){const M={info:{bg:"#eff6ff",border:"#bfdbfe",text:"#1e3a8a"},warning:{bg:"#fffbeb",border:"#fcd34d",text:"#78350f"},danger:{bg:"#fef2f2",border:"#fca5a5",text:"#7f1d1d"}}[V.messageType??"info"],j=document.createElement("p");j.className="ago-ticket-form__option-message",j.textContent=V.message,n.css(j,{fontSize:"14px",lineHeight:"20px",border:`1px solid ${M.border}`,backgroundColor:M.bg,color:M.text,borderRadius:"4px",padding:"8px",whiteSpace:"pre-line",margin:"0"}),C.appendChild(j)}return C}const y=document.createElement("input");return y.type="text",y.id=A,y.value=E,He(y,!!W,O),y.addEventListener("input",()=>{e.customFields[v]=y.value,o&&Ke(o,e.customFields,e.ticket.typology),e.submittedOnce&&(d(),I())}),y.addEventListener("change",()=>w()),C.appendChild(y),W&&C.appendChild(he(W)),C}function I(){for(const u of c.querySelectorAll("[data-ago-error-for]")){const v=u.dataset.agoErrorFor,A=u.querySelector(".ago-ticket-form__error"),E=e.errors[v],O=u.querySelector("input, select, textarea");O&&(O.style.borderColor=E?"#ef4444":""),O&&!E&&(O.style.border=`1px solid ${n.BORDER_COLOR}`),E&&!A?u.appendChild(he(E)):E&&A?A.textContent=E:!E&&A&&A.remove()}}function w(){if(c.replaceChildren(),t.message){const b=n.div({fontWeight:"500",color:"#1e40af",backgroundColor:"#eff6ff",padding:"12px",borderRadius:"4px"});b.className="ago-ticket-form__message",b.textContent=t.message,c.appendChild(b)}if(e.submitted){c.appendChild(So({text:t.successMessage||o?.successMessageText||i.ticketSubmitted,ticketUrl:e.submitted.ticketUrl,urlLabel:t.successUrlLabel||o?.successMessageUrlLabel||i.findTicketHere}));return}if(r){const b=n.div({padding:"16px",textAlign:"center",fontWeight:"700",fontSize:"20px"});b.className="ago-ticket-form__config-loading",b.setAttribute("role","status"),b.textContent=i.loading,c.appendChild(b);return}if(!o){const b=n.div({backgroundColor:"#fee2e2",color:"#991b1b",padding:"16px",borderRadius:"4px"});b.className="ago-ticket-form__missing",b.textContent=i.noTicketForm,c.appendChild(b);return}const u=o,v=e.loading;if(e.loading){const b=n.div({position:"absolute",inset:"0",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(255, 255, 255, 0.7)",zIndex:"5",borderRadius:"16px",fontSize:"20px",fontWeight:"700"});b.className="ago-ticket-form__loading",b.setAttribute("role","status"),b.textContent=i.loading,c.appendChild(b)}const A=n.div({fontWeight:"600",backgroundColor:"#bfdbfe",padding:"16px",borderRadius:"4px"});if(A.className="ago-ticket-form__intro",A.textContent=i.useFormToCreateTicket,c.appendChild(A),t.requireEmail){const b=Be();b.dataset.agoErrorFor="userEmail",b.appendChild(De(`${i.yourEmail} *`,"ago-ticket-email"));const R=document.createElement("input");R.type="email",R.id="ago-ticket-email",R.placeholder=i.emailPlaceholder,R.value=e.email,He(R,!!e.errors.userEmail,v),R.addEventListener("input",()=>{e.email=R.value,e.submittedOnce&&(d(),I())}),b.appendChild(R),e.errors.userEmail&&b.appendChild(he(e.errors.userEmail)),c.appendChild(b)}const E=u.showSubject&&!!e.ticket.subject||!u.showSubject,O=E&&(!!e.ticket.typology||!u.showTypology),W=u.showPriority&&mn(u,e.ticket.typology),C=O&&(!!e.ticket.priority||!W);if(u.showSubject){const b=Be();b.dataset.agoErrorFor="subject",b.appendChild(De(i.subject,"ago-ticket-subject"));const R=document.createElement("input");R.type="text",R.id="ago-ticket-subject",R.value=e.ticket.subject,He(R,!!e.errors.subject,v),R.addEventListener("input",()=>{e.ticket.subject=R.value,p(),I()}),R.addEventListener("change",()=>w()),b.appendChild(R),e.errors.subject&&b.appendChild(he(e.errors.subject)),c.appendChild(b)}if(E&&u.showTypology){const b=Be();b.dataset.agoErrorFor="typology",b.appendChild(De(i.typology,"ago-ticket-typology"));const R=document.createElement("select");R.id="ago-ticket-typology";for(const[z,J]of[["",i.selectTypology],["Question",i.question],["Task",i.task],["Incident",i.incident]]){const Y=document.createElement("option");Y.value=z,Y.textContent=J,R.appendChild(Y)}R.value=e.ticket.typology,He(R,!!e.errors.typology,v),R.addEventListener("change",()=>{e.ticket.typology=R.value,Ke(u,e.customFields,e.ticket.typology),p(),w()}),b.appendChild(R),e.errors.typology&&b.appendChild(he(e.errors.typology)),c.appendChild(b)}if(O&&W){const b=Be();b.dataset.agoErrorFor="priority",b.appendChild(De(i.priority,"ago-ticket-priority"));const R=document.createElement("select");R.id="ago-ticket-priority";for(const[z,J]of[["",i.selectPriority],["Low",i.low],["Normal",i.normal],["High",i.high],["Urgent",i.urgent]]){const Y=document.createElement("option");Y.value=z,Y.textContent=J,R.appendChild(Y)}R.value=e.ticket.priority,He(R,!!e.errors.priority,v),R.addEventListener("change",()=>{e.ticket.priority=R.value,p(),w()}),b.appendChild(R),e.errors.priority&&b.appendChild(he(e.errors.priority)),c.appendChild(b)}if(C){const b=new Set(Pi(u,e.customFields,e.ticket.typology));for(const R of[...u.fields].sort((z,J)=>z.position-J.position)){if(!b.has(R)&&!e.errors[ie(R)])continue;const z=x(R);z.dataset.agoErrorFor=ie(R),c.appendChild(z)}}const F=Be();F.dataset.agoErrorFor="body",F.appendChild(De(i.detailedContext,"ago-ticket-body"));const y=document.createElement("textarea");y.id="ago-ticket-body",y.rows=4,y.value=e.ticket.body,He(y,!!e.errors.body,v),n.css(y,{resize:"vertical",maxHeight:"240px",overflowY:"auto"});const k=n.div({fontSize:"14px",lineHeight:"20px",marginTop:"4px",textAlign:"right",display:"none"});k.className="ago-ticket-form__counter";const S=()=>{const b=e.ticket.body.length;k.style.display=b>6e4?"block":"none",k.style.color=b>65535?"#dc2626":"#d97706",k.textContent=`${b} / 65,535 · ${i.maxCharacters}`},D=()=>{y.style.height="auto",y.style.height=`${y.scrollHeight}px`};if(y.addEventListener("input",()=>{e.ticket.body=y.value,p(),I(),S(),D()}),F.append(y,k),S(),e.errors.body&&F.appendChild(he(e.errors.body)),c.appendChild(F),s){const b=Be();b.className="ago-ticket-form__field ago-ticket-form__attachments",b.appendChild(De(i.attachments,"ago-ticket-files"));const R=document.createElement("label");R.htmlFor="ago-ticket-files",R.textContent=i.selectFile,n.css(R,{display:"inline-block",alignSelf:"flex-start",backgroundColor:"#e5e7eb",padding:"8px 16px",borderRadius:"4px",cursor:"pointer",border:"1px solid #d1d5db",minHeight:"24px"});const z=document.createElement("input");z.type="file",z.id="ago-ticket-files",z.multiple=!0,z.disabled=v,n.css(z,{display:"none"}),z.addEventListener("change",()=>{e.files=[...e.files,...Array.from(z.files??[])],z.value="",w()}),b.append(R,z);const J=n.div({display:"flex",flexDirection:"column",gap:"4px"});e.files.forEach((Y,m)=>{const B=n.div({display:"flex",alignItems:"center",justifyContent:"space-between",backgroundColor:"#f3f4f6",padding:"4px 8px",borderRadius:"4px"}),G=document.createElement("span");G.textContent=`${Y.name} - ${(Y.size/1024).toFixed(1)} KB`;const P=document.createElement("button");P.type="button",P.textContent="×",P.setAttribute("aria-label",`Remove ${Y.name}`),P.disabled=v,n.css(P,{color:"#dc2626",fontWeight:"700",background:"none",border:"none",cursor:"pointer",fontSize:"18px",lineHeight:"1",width:"44px",height:"44px",margin:"-10px -12px -10px 0"}),P.addEventListener("click",()=>{e.files=e.files.filter((ee,re)=>re!==m),w()}),B.append(G,P),J.appendChild(B)}),b.appendChild(J),c.appendChild(b)}if(e.submitError){const b=he(e.submitError);b.setAttribute("role","alert"),b.className="ago-ticket-form__error ago-ticket-form__submit-error",c.appendChild(b)}const V=document.createElement("button");V.type="button",V.className="ago-ticket-form__submit",V.disabled=v,n.css(V,{width:"100%",backgroundColor:ji,color:n.BRAND_TEXT_COLOR,padding:"8px 16px",borderRadius:"4px",border:"none",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",cursor:v?"default":"pointer",fontSize:"16px",lineHeight:"24px",minHeight:"44px",font:"inherit",transition:"filter 0.15s"});const M=document.createElement("span");M.textContent=i.submit;const j=document.createElement("span");j.textContent="→",j.setAttribute("aria-hidden","true"),n.css(j,{fontSize:"20px",lineHeight:"1",transition:"transform 0.15s"}),V.append(M,j),V.addEventListener("mouseenter",()=>{V.style.filter="brightness(0.9)",j.style.transform="translateX(4px)"}),V.addEventListener("mouseleave",()=>{V.style.filter="",j.style.transform=""}),V.addEventListener("click",()=>{h()}),c.appendChild(V)}return w(),{el:c,rebuild:u=>{u&&"ticketForm"in u&&(o=u.ticketForm??null),u&&"configLoading"in u&&(r=!!u.configLoading),u&&"allowFiles"in u&&(s=!!u.allowFiles),w()}}}var Ji=0;async function Zi(t){const e=Array.from(t.querySelectorAll("script"));for(const i of e){const o=document.createElement("script");for(const r of Array.from(i.attributes))o.setAttribute(r.name,r.value);i.src?await new Promise((r,s)=>{o.onload=()=>r(),o.onerror=()=>s(new Error(`Failed to load script: ${i.src}`)),i.parentNode?.replaceChild(o,i)}):(o.textContent=i.textContent,i.parentNode?.replaceChild(o,i))}}function er(t,e){const i={};if(t)for(const[o,r]of Object.entries(t))if(o==="custom_fields"&&r&&typeof r=="object")for(const[s,c]of Object.entries(r))c&&(i[s]=c);else typeof r=="string"&&r&&(i[o]=r);return e&&(i.email=e),Object.keys(i).length>0?i:null}function tr(t){const e=n.div({fontWeight:"500",color:"#1e40af",backgroundColor:"#eff6ff",padding:"12px",borderRadius:"4px",fontSize:"16px",lineHeight:"24px"});return e.className="ago-ticket-form__message",e.textContent=t,e}function nr(t){const{state:e,labels:i}=t,o=`ago-embed-${Date.now().toString(36)}-${++Ji}`,r=n.div({display:"flex",flexDirection:"column",gap:"16px"});r.className="ago-embed-form",t.message&&r.appendChild(tr(t.message));const s=n.div({display:"flex",flexDirection:"column",gap:"12px"});s.className="ago-embed-form__body",r.appendChild(s);const c=[];let d,h=!1,f=e.status==="submitted",p=null;const x=er(t.ticket,t.email),I=y=>{f||h||(f=!0,d&&(clearTimeout(d),d=void 0),e.status="submitted",e.captured=y??null,F(),t.onSubmitted(y??null))},w=()=>{f||d||(h=!1,d=setTimeout(()=>{f||(d=void 0,e.status="timeout",F())},3e4))},u=()=>{try{const y=globalThis.HubSpotFormsV4?.getForms?.()?.[0];if(y?.getFormFieldValues){const k=new Promise((S,D)=>setTimeout(()=>D(new Error("timeout")),3e3));Promise.race([y.getFormFieldValues(),k]).then(S=>I(Lt(S))).catch(()=>I(p));return}}catch{}I(p)};window.addEventListener("hs-form-event:on-submission:success",u),c.push(()=>window.removeEventListener("hs-form-event:on-submission:success",u));const v=[],A=y=>{const k=y.data;if(k?.type==="hsFormCallback"&&k.eventName==="onFormSubmit"){try{const S=k.data;if(Array.isArray(S)){const D={};for(const M of S)M?.name&&M.value!==void 0&&(D[M.name]=M.value);const V=Lt(D);V&&(p=V)}}catch{}return}if(k?.type==="hsFormCallback"&&k.eventName==="onFormSubmitted"){I(p);return}if(k?.type==="HS_CTA_PARENT_INIT"&&y.ports?.[0]){const S=y.ports[0],D=V=>{const M=V.data;if(M?.type==="HS_SEND_FORM_FIELD_VALUES"){const j=M.payload?.formFieldValues;if(j&&typeof j=="object"){const b=Lt(j);b&&(p=b)}}M?.type==="HS_SEND_FORM_SUBMISSION_SUCCESS"&&I(p)};S.addEventListener("message",D),S.start(),v.push(()=>S.removeEventListener("message",D))}};window.addEventListener("message",A),c.push(()=>{window.removeEventListener("message",A),v.forEach(y=>y())});let E;function O(y){if(!t.embedHtml)return;let k=Hi(t.embedHtml,x,o);k=Ui(k,o);const S=zi(x,o),D=ro(x);y.innerHTML=k;const V=Wi(y,I,w,o);let M,j,b;Zi(y).catch(()=>{}).then(()=>{e.status==="loading"&&(e.status="ready",W.style.display="none",x&&(Nt(y,x),Mi(x),b=ro(x),M=new MutationObserver(()=>Nt(y,x)),M.observe(y,{childList:!0,subtree:!0}),j=setTimeout(()=>M?.disconnect(),1e4)))}),E=()=>{S(),D(),V(),M?.disconnect(),j&&clearTimeout(j),b?.(),y.innerHTML=""}}const W=n.div({position:"absolute",inset:"0",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(255, 255, 255, 0.8)",zIndex:"10"});W.className="ago-embed-form__loading";const C=n.div({width:"24px",height:"24px",borderRadius:"50%",border:`2px solid ${n.EMBED_MUTED_TEXT}`,borderTopColor:"transparent",animation:"ago-spin 1s linear infinite"});C.setAttribute("role","status"),W.appendChild(C);function F(){if(s.replaceChildren(),e.status==="timeout"){const k=n.div({borderRadius:"8px",border:"1px solid #fef08a",backgroundColor:"#fefce8",padding:"16px",display:"flex",flexDirection:"column",gap:"12px"});k.className="ago-embed-form__timeout";const S=document.createElement("p");S.textContent=i.embedSubmitTimeout,n.css(S,{fontSize:"14px",lineHeight:"20px",color:"#854d0e",margin:"0"});const D=document.createElement("button");D.type="button",D.textContent=i.tryAgain,n.css(D,{alignSelf:"flex-start",fontSize:"14px",fontWeight:"500",color:"#854d0e",textDecoration:"underline",background:"none",border:"none",padding:"0",cursor:"pointer",minHeight:"44px",font:"inherit"}),D.addEventListener("click",()=>{h=!0,f=!1,d=void 0,e.status="ready",F()}),k.append(S,D),s.appendChild(k);return}if(e.status==="submitted"){s.appendChild(So({text:t.successMessage||i.embeddedFormSubmitted,urlLabel:i.findTicketHere}));return}if(t.description){const k=document.createElement("p");k.textContent=t.description,n.css(k,{fontSize:"14px",lineHeight:"20px",margin:"0"}),s.appendChild(k)}const y=n.div({position:"relative",borderRadius:"8px",border:`1px solid ${n.BORDER_COLOR}`,overflow:"hidden"});if(y.className="ago-embed-form__frame",t.embedHtml){W.style.display=e.status==="loading"?"flex":"none",y.appendChild(W);const k=n.div({width:"100%",minHeight:"200px"});k.className="ago-embed-form__host",y.appendChild(k),E?.(),O(k)}else{const k=n.div({padding:"24px",textAlign:"center",color:n.EMBED_MUTED_TEXT,fontSize:"14px"});k.textContent=i.noEmbedConfigured,y.appendChild(k)}s.appendChild(y)}return F(),{el:r,destroy:()=>{d&&clearTimeout(d),E?.(),c.forEach(y=>y())}}}function or(t){return t.type==="form"&&t.toolName==="ago_ticketing"}function ir(t){let e=null;for(const i of t)for(const o of i.toolCalls??[])o.type==="form"&&(e=o.id);return e}function rr(t){return t.some(e=>(e.toolCalls??[]).some(i=>{if(i.type!=="form")return!1;const o=i.data;return o?.success===!0&&!!o.ticket?.ticket_id}))}function lo(t){const e=t.data;return e?.success!==!0||!e.ticket?.ticket_id?null:{ticketId:String(e.ticket.ticket_id),ticketUrl:typeof e.ticket.ticket_url=="string"&&e.ticket.ticket_url?e.ticket.ticket_url:void 0}}var ar={info:{border:"#bfdbfe",bg:"#eff6ff",text:"#1e40af"},warning:{border:"#fef08a",bg:"#fefce8",text:"#854d0e"},success:{border:"#bbf7d0",bg:"#f0fdf4",text:"#166534"},error:{border:"#fecaca",bg:"#fef2f2",text:"#991b1b"}};function sr(t,e="info",i){const o=ar[e],r=n.div({margin:"8px 0",padding:"12px 16px",border:`1px solid ${o.border}`,backgroundColor:o.bg,color:o.text,borderRadius:"8px",display:"flex",alignItems:"flex-start",gap:"8px",fontSize:"14px",lineHeight:"20px"});if(r.className=`ago-toolcall-status ago-toolcall-status--${e}`,r.setAttribute("role","status"),i){const c=document.createElement("span");c.textContent=`${i}:`,n.css(c,{fontSize:"12px",fontWeight:"500",opacity:"0.7",flexShrink:"0"}),r.appendChild(c)}const s=document.createElement("span");return s.textContent=t,s.style.whiteSpace="pre-wrap",r.appendChild(s),r}function lr(t,e){const i=n.div({margin:"8px 0",padding:"12px 16px",border:"1px solid #e9d5ff",backgroundColor:"#faf5ff",color:"#6b21a8",borderRadius:"8px",display:"flex",flexDirection:"column",gap:"8px",fontSize:"14px",lineHeight:"20px"});i.className="ago-toolcall-form-placeholder";const o=n.div({display:"flex",alignItems:"center",gap:"8px",flexWrap:"wrap"});if(t.toolName){const s=document.createElement("span");s.textContent=`${t.toolName}:`,n.css(s,{fontSize:"12px",fontWeight:"500",opacity:"0.7"}),o.appendChild(s)}if(t.message){const s=document.createElement("span");s.textContent=t.message,o.appendChild(s)}o.childElementCount>0&&i.appendChild(o);const r=n.div({opacity:"0.8"});if(r.textContent=e.genericFormComingSoon,t.formSchema){const s=document.createElement("pre");s.textContent=JSON.stringify(t.formSchema,null,2),n.css(s,{fontSize:"12px",lineHeight:"16px",marginTop:"8px",marginBottom:"0",whiteSpace:"pre-wrap",overflowWrap:"anywhere"}),r.appendChild(s)}return i.appendChild(r),i}var To={useFormToCreateTicket:"You can use the following form to create a ticket",yourEmail:"Your Email",emailPlaceholder:"Enter your email address",emailRequired:"Email is required",emailInvalid:"Please enter a valid email address",subject:"Subject",subjectRequired:"Subject is required.",typology:"Typology",selectTypology:"Select a typology",typologyRequired:"Typology is required.",question:"Question",task:"Task",incident:"Incident",priority:"Priority",selectPriority:"Select a priority",priorityRequired:"Priority is required.",low:"Low",normal:"Normal",high:"High",urgent:"Urgent",detailedContext:"Detailed context",detailedContextRequired:"Detailed context is required.",fieldRequired:"{fieldTitle} is required.",fieldFormatInvalid:"{fieldTitle} has an invalid format.",attachments:"Attachments",selectFile:"Select file",submit:"Submit",loading:"Loading...",maxCharacters:"Maximum characters",ticketSubmitted:"Your ticket has been successfully submitted.",findTicketHere:"You can find it here:",noTicketForm:"No ticket form found",notAllowed:"You are not allowed to create a ticket.",submissionFailed:"Failed to submit ticket",submissionFailedDescription:"There was an error submitting your ticket. Please try again.",fileTooLarge:"File too large",permissionDenied:"Permission denied",validationFailed:"Validation error",pleaseCheckFields:"Please check your form fields and try again.",embeddedFormSubmitted:"Your form has been submitted successfully.",noEmbedConfigured:"No embed URL or HTML configured for this form.",embedSubmitTimeout:"The form submission could not be confirmed. Please try again.",tryAgain:"Try again",contactFormCreated:"A new contact form has been created, see below to fill it out.",contactFormRejected:"You are not allowed to create a ticket. See below why.",genericFormComingSoon:"Generic form rendering (Coming soon)",unknownToolCall:"Unknown tool call type: {type}",formPending:"Please complete the form above to continue the conversation",ticketCreatedBlocked:`A ticket has been created for this conversation.
|
|
6
|
+
Please create a new conversation to continue.`,newConversation:"New conversation"},pn={helpful:"Helpful",notHelpful:"Not helpful",whatWentWrong:"What went wrong?",reasons:{inaccurate:"Inaccurate",incomplete:"Incomplete",information_not_found:"Information not found",technical_issue:"Technical issue"},commentPlaceholder:"Anything else? (optional)",send:"Send",thanks:"Thanks, this was reported."};function dr(){return{detailsOpen:!1,reasons:new Set,comment:"",reported:!1}}var cr={display:"inline-flex",alignItems:"center",justifyContent:"center",width:"44px",height:"44px",margin:"-8px",padding:"0",border:"none",borderRadius:"8px",background:"transparent",color:n.MUTED_TEXT_COLOR,cursor:"pointer",lineHeight:"1"};function pr(t){const{state:e,labels:i,askWhy:o,onRate:r,onReport:s}=t,c=t.look==="embed",d=c?{idle:"#78716c",hover:"#1c1917",active:"#1c1917"}:{idle:n.MUTED_TEXT_COLOR,hover:n.TEXT_COLOR,active:n.ACCENT_COLOR},h=n.div(c?{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"8px",width:"100%"}:{marginTop:"6px",width:"100%",maxWidth:"85%"});h.className="ago-feedback";const f=n.div({display:"flex",alignItems:"center",gap:c?"8px":"2px"});f.className="ago-feedback__actions";const p=co("up",i.helpful,e.rating==="positive",d,c);p.addEventListener("click",()=>{e.rating="positive",e.detailsOpen=!1,w(),u(),r("positive")});const x=co("down",i.notHelpful,e.rating==="negative",d,c);x.addEventListener("click",()=>{e.rating="negative",r("negative"),o&&!e.reported&&(e.detailsOpen=!0),w(),u()}),f.append(p,x),c&&h.appendChild(n.div({flex:"1"})),h.appendChild(f);const I=n.div();I.className="ago-feedback__panel-slot",c&&(I.style.flexBasis="100%"),h.appendChild(I);function w(){un(p,e.rating==="positive",d),un(x,e.rating==="negative",d)}function u(){if(I.replaceChildren(),e.reported){I.appendChild(mr(i.thanks));return}e.detailsOpen&&I.appendChild(fr(e,i,async v=>await s(e.rating??"negative",v)?(e.reported=!0,e.detailsOpen=!1,u(),!0):!1))}return w(),u(),h}function co(t,e,i,o,r=!1){const s=document.createElement("button");return s.type="button",s.className=`ago-feedback__thumb ago-feedback__thumb--${t}`,s.setAttribute("aria-label",e),s.title=e,n.css(s,cr),r?(s.style.margin="-14px",s.appendChild(t==="up"?n.thumbUpIcon({size:18}):n.thumbDownIcon({size:18}))):s.appendChild(ur(t)),un(s,i,o),s.addEventListener("mouseenter",()=>{s.getAttribute("aria-pressed")!=="true"&&(s.style.color=o.hover)}),s.addEventListener("mouseleave",()=>{s.getAttribute("aria-pressed")!=="true"&&(s.style.color=o.idle)}),s}function un(t,e,i){t.setAttribute("aria-pressed",e?"true":"false"),t.style.color=e?i.active:i.idle}function ur(t){const e="http://www.w3.org/2000/svg",i=document.createElementNS(e,"svg");i.setAttribute("width","16"),i.setAttribute("height","16"),i.setAttribute("viewBox","0 0 24 24"),i.setAttribute("fill","none"),i.setAttribute("aria-hidden","true");const o=document.createElementNS(e,"path");o.setAttribute("d","M7 22h9.3a2 2 0 0 0 2-1.7l1.4-9A2 2 0 0 0 17.7 9H14V5a3 3 0 0 0-3-3l-4 10z"),o.setAttribute("stroke","currentColor"),o.setAttribute("stroke-width","1.8"),o.setAttribute("stroke-linejoin","round");const r=document.createElementNS(e,"path");return r.setAttribute("d","M7 22V12H4.5A1.5 1.5 0 0 0 3 13.5v7A1.5 1.5 0 0 0 4.5 22z"),r.setAttribute("stroke","currentColor"),r.setAttribute("stroke-width","1.8"),r.setAttribute("stroke-linejoin","round"),i.append(o,r),t==="down"&&(i.style.transform="rotate(180deg)"),i}function fr(t,e,i){const o=n.div({marginTop:"8px",padding:"12px",border:`1px solid ${n.BORDER_COLOR}`,borderRadius:n.MESSAGE_RADIUS,backgroundColor:n.PANEL_BACKGROUND});o.className="ago-feedback__panel",o.setAttribute("role","group"),o.setAttribute("aria-label",e.whatWentWrong);const r=n.div({fontSize:"13px",fontWeight:"500",color:n.TEXT_COLOR,marginBottom:"8px"});r.textContent=e.whatWentWrong,o.appendChild(r);const s=n.div({display:"flex",flexWrap:"wrap",gap:"6px",marginBottom:"8px"});s.className="ago-feedback__reasons";for(const f of _e.FEEDBACK_REASONS){const p=document.createElement("button");p.type="button",p.className="ago-feedback__reason",p.textContent=e.reasons[f],n.css(p,{minHeight:"44px",padding:"4px 12px",fontSize:"13px",fontFamily:"inherit",borderRadius:"999px",border:`1px solid ${n.BORDER_COLOR}`,backgroundColor:"transparent",color:n.TEXT_COLOR,cursor:"pointer"});const x=()=>{const I=t.reasons.has(f);p.setAttribute("aria-pressed",I?"true":"false"),p.style.borderColor=I?n.ACCENT_COLOR:n.BORDER_COLOR,p.style.color=I?n.ACCENT_COLOR:n.TEXT_COLOR};p.addEventListener("click",()=>{t.reasons.has(f)?t.reasons.delete(f):t.reasons.add(f),x(),h()}),x(),s.appendChild(p)}o.appendChild(s);const c=document.createElement("textarea");c.className="ago-feedback__comment",c.rows=2,c.placeholder=e.commentPlaceholder,c.value=t.comment,c.setAttribute("aria-label",e.commentPlaceholder),n.css(c,{width:"100%",boxSizing:"border-box",padding:"8px 10px",fontSize:"14px",fontFamily:"inherit",color:n.TEXT_COLOR,border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"10px",backgroundColor:"transparent",resize:"vertical"}),c.addEventListener("input",()=>{t.comment=c.value,h()}),o.appendChild(c);const d=document.createElement("button");return d.type="button",d.className="ago-feedback__send",d.textContent=e.send,n.css(d,{marginTop:"8px",minHeight:"44px",padding:"6px 16px",fontSize:"14px",fontFamily:"inherit",borderRadius:"10px",border:"none",backgroundColor:n.BRAND_COLOR,color:n.BRAND_TEXT_COLOR,cursor:"pointer"}),d.addEventListener("click",()=>{d.disabled||(d.disabled=!0,i({reasons:[...t.reasons],comment:t.comment.trim()}).then(f=>{f||h()}))}),o.appendChild(d),h(),o;function h(){const f=t.reasons.size>0||t.comment.trim().length>0;d.disabled=!f,d.style.opacity=f?"1":"0.5",d.style.cursor=f?"pointer":"default"}}function mr(t){const e=n.div({marginTop:"6px",fontSize:"13px",color:n.MUTED_TEXT_COLOR});return e.className="ago-feedback__thanks",e.setAttribute("role","status"),e.textContent=t,e}function gr(t){const e=n.div({display:"flex",flexDirection:"column",flex:"1",width:"100%",overflow:"auto",minHeight:"0"});e.className="ago-chat-widget__chat";const i=n.div({position:"relative",isolation:"isolate",width:"100%",maxWidth:"768px",margin:"0 auto",padding:"0 8px 8px",boxSizing:"border-box",flexShrink:"0"});i.className="ago-chat-widget__dock";const o=n.div({width:"100%"});return o.className="ago-chat-widget__chat-composer",n.css(t.jumpBtn,{position:"absolute",bottom:"100%",top:"auto",left:"auto",right:"50%",marginBottom:"16px",transform:"translateX(50%)",zIndex:"50"}),i.append(t.jumpBtn,o),e.append(t.messagesWrap,i),{el:e,composerSlot:o}}var hr=7200*1e3;function fn(t){const e=t.lastMessageDate instanceof Date?t.lastMessageDate.getTime():new Date(t.lastMessageDate).getTime();return Number.isFinite(e)?e:Number.NEGATIVE_INFINITY}function Ro(t){return[...t].sort((e,i)=>fn(i)-fn(e))}function br(t,e=Date.now(),i=hr){const o=Ro(t)[0];if(!o)return null;const r=fn(o);return Number.isFinite(r)&&e-r<i?o:null}function xr(t){const e=n.div({position:"relative",display:"flex",flexDirection:"column",height:"100%",flex:"1",minHeight:"0"});e.className="ago-chat-widget__history";const i=n.div({display:"flex",flex:"1",minHeight:"0"});i.className="ago-chat-widget__history-body";const o=n.div({pointerEvents:"none",position:"absolute",left:"0",right:"0",bottom:"0",zIndex:"10",padding:"32px 16px 16px",backgroundImage:`linear-gradient(to top, ${n.EMBED_BACKGROUND} 72px, transparent 104px)`});o.className="ago-chat-widget__new-strip";const r=document.createElement("button");r.type="button",r.className="ago-chat-widget__new-conversation",n.css(r,{pointerEvents:"auto",display:"flex",height:"56px",width:"100%",alignItems:"center",justifyContent:"center",gap:"8px",borderRadius:"32px",backgroundColor:n.BRAND_COLOR,color:"#fff",padding:"0 24px",border:"none",cursor:"pointer",font:"inherit"});const s=document.createElement("span");s.textContent=t.labels.newConversation,n.css(s,{fontSize:"14px",lineHeight:"20px",fontWeight:"500"}),r.append(n.addCommentIcon({size:16}),s),r.addEventListener("click",t.onNew),o.appendChild(r),e.append(i,o);const c=p=>{t.customFont?p.style.opacity="0.7":p.style.color=n.EMBED_MUTED_TEXT};function d(){const p=n.div({display:"flex",flex:"1",alignItems:"center",justifyContent:"center",paddingBottom:"112px"});p.className="ago-chat-widget__history-loading";const x=n.div({width:"32px",height:"32px",borderRadius:"50%",borderBottom:`2px solid ${n.BRAND_COLOR}`,animation:"ago-spin 1s linear infinite"});x.setAttribute("role","status"),p.appendChild(x),i.replaceChildren(p)}function h(){const p=n.div({display:"flex",flex:"1",flexDirection:"column",alignItems:"center",justifyContent:"center"});p.className="ago-chat-widget__history-empty",c(p);const x=n.conversationsIcon({size:36});x.style.marginBottom="8px";const I=document.createElement("p");I.textContent=t.labels.noHistory,n.css(I,{fontSize:"14px",lineHeight:"20px",margin:"0"}),p.append(x,I),i.replaceChildren(p)}function f(p){const x=n.div({flex:"1",overflowY:"auto",padding:"0 16px 112px",minHeight:"0"});x.className="ago-chat-widget__history-list";const I=Ro(p);I.forEach((w,u)=>{const v=document.createElement("button");if(v.type="button",v.className="ago-chat-widget__thread",v.dataset.agoConversationId=w.id,n.css(v,{display:"flex",alignItems:"center",gap:"8px",padding:"17px 0",width:"100%",textAlign:"left",backgroundColor:"transparent",border:"none",borderBottom:u===I.length-1?"none":`1px solid ${n.EMBED_BORDER}`,cursor:"pointer",font:"inherit",color:"inherit"}),t.hoverBackground){const C=t.hoverBackground;v.addEventListener("mouseenter",()=>{v.style.backgroundColor=C}),v.addEventListener("mouseleave",()=>{v.style.backgroundColor="transparent"})}const A=n.div({flex:"1",minWidth:"0",display:"flex",flexDirection:"column",gap:"4px"}),E=document.createElement("h3");E.textContent=w.title||t.labels.newConversation,n.css(E,{margin:"0",fontSize:"14px",lineHeight:"20px",fontWeight:"400",color:t.customFont?"inherit":n.BRAND_COLOR,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"});const O=document.createElement("span");O.textContent=mi(w.lastMessageDate,Date.now(),t.labels.timeAgo),n.css(O,{fontSize:"12px",lineHeight:"16px"}),c(O),A.append(E,O);const W=n.chevronRightIcon({size:16});t.customFont?W.style.opacity="0.6":W.style.color=n.BRAND_COLOR,v.append(A,W),v.addEventListener("click",()=>t.onSelect(w)),x.appendChild(v)}),i.replaceChildren(x)}return{el:e,render:({threads:p,loading:x})=>{x?d():p.length===0?h():f(p)}}}function yr(t){const e=n.div({position:"relative",display:"flex",flex:"1",flexDirection:"column",width:"100%",maxWidth:"768px",margin:"0 auto",padding:"16px",overflow:"auto",boxSizing:"border-box",minHeight:"0"});e.className="ago-chat-widget__home";const i=n.div({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"space-between",height:"100%",width:"100%",minHeight:"0"}),o=n.div({flex:"1",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"flex-end",gap:"32px",margin:"16px 0 32px"}),r=n.div({fontSize:"28px",lineHeight:"1.2",letterSpacing:"-0.03em",fontWeight:"700",textAlign:"center",color:n.TEXT_COLOR});r.className="ago-chat-widget__home-title",o.appendChild(r);const s=n.div({fontSize:"14px",lineHeight:"20px",textAlign:"center",maxWidth:"512px"});s.className="ago-chat-widget__home-subtitle",o.appendChild(s);const c=C=>{r.replaceChildren();for(const F of C.split(`
|
|
7
|
+
`)){const y=n.div({});y.textContent=F,r.appendChild(y)}},d=C=>{s.replaceChildren(),s.style.display=C?"":"none",C&&s.appendChild(Me(C))};c(t.title),d(t.subtitle);const h=n.div({flex:"1",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",width:"100%",position:"relative"}),f=n.div({display:"grid",gridTemplateColumns:"1fr",gap:"12px",width:"100%",maxWidth:"672px",marginBottom:"32px",padding:"0 16px",boxSizing:"border-box"});f.className="ago-chat-widget__starters";const p=[];let x=null;const I=C=>{f.replaceChildren(),p.length=0;for(const F of C)w(F);C.length>0?f.parentNode||h.insertBefore(f,u):f.remove()};function w(C){const F=document.createElement("button");F.type="button",F.className="ago-chat-widget__starter",n.css(F,{textAlign:"left",borderRadius:"12px",border:"1px solid rgba(228, 228, 231, 0.6)",backgroundColor:"#fff",padding:"14px 16px",boxShadow:n.SHADOW_SM,transition:"all 0.2s",cursor:"pointer",font:"inherit",color:n.TEXT_COLOR,position:"relative"});const y=n.div({display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:"8px"}),k=n.div({minWidth:"0",flex:"1",fontSize:"14px",lineHeight:"1.375",display:"-webkit-box",overflow:"hidden"});k.style.setProperty("-webkit-line-clamp","2"),k.style.setProperty("-webkit-box-orient","vertical"),k.textContent=C.label;const S=n.arrowUpRightIcon({size:16});n.css(S,{marginTop:"2px",color:"rgba(113, 113, 122, 0.5)",transition:"all 0.15s"}),y.append(k,S),F.appendChild(y),F.addEventListener("mouseenter",()=>{F.disabled||(F.style.borderColor="#e4e4e7",F.style.boxShadow=n.SHADOW_MD,F.style.transform="translateY(-2px)",S.style.color=n.TEXT_COLOR,S.style.transform="translate(2px, -2px)")}),F.addEventListener("mouseleave",()=>{F.style.borderColor="rgba(228, 228, 231, 0.6)",F.style.boxShadow=n.SHADOW_SM,F.style.transform="",S.style.color="rgba(113, 113, 122, 0.5)",S.style.transform=""}),F.addEventListener("click",()=>{x||t.onStarter(C)}),p.push({starter:C,btn:F}),f.appendChild(F)}const u=n.div({width:"100%"});u.className="ago-chat-widget__home-composer",h.appendChild(u),I(t.starters);const v=n.div({flex:"1"});i.append(o,h,v),e.appendChild(i);const A=t.twoColumnsFrom??640,E=()=>{const C=typeof window<"u"&&window.innerWidth>=A;f.style.gridTemplateColumns=C?"1fr 1fr":"1fr"};E();const O=C=>{x=C;for(const{starter:F,btn:y}of p){const k=F===C;y.disabled=!!C,y.style.opacity=C?"0.6":"",y.style.cursor=C?"not-allowed":"pointer";const S=y.querySelector("svg");S&&(S.style.animation=k?"ago-skeleton-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite":"")}};return{el:e,composerSlot:u,syncColumns:E,setPending:O,setContent:C=>{C.title!==void 0&&c(C.title),C.subtitle!==void 0&&d(C.subtitle),C.starters&&(I(C.starters),E(),x&&O(x))}}}function Cr(t){const e=n.div({position:"fixed",bottom:"80px",[t.edge]:"20px",textAlign:t.edge==="left"?"left":"right",cursor:"pointer",zIndex:"2147483000",animation:"ago-scale-in 800ms",fontFamily:"Arial, Helvetica, sans-serif",transform:"translateZ(0)",backfaceVisibility:"hidden",willChange:"transform"});e.className="ago-chat-widget-teaser";const i=document.createElement("button");i.type="button",i.className="ago-chat-widget-teaser__close",i.setAttribute("aria-label","Dismiss"),i.textContent="X",n.css(i,{animation:"ago-appear 1000ms ease-in",background:"#fff",border:"1px solid #efefef",borderRadius:"50%",boxShadow:n.PANEL_SHADOW,color:"#333",cursor:"pointer",display:"inline-block",fontSize:"12px",fontWeight:"600",fontFamily:"inherit",lineHeight:"normal",left:"5px",padding:"3px 5px",position:"relative",top:"15px",zIndex:"1"});const o=document.createElement("p");o.className="ago-chat-widget-teaser__text",n.css(o,{alignItems:"center",backgroundColor:"#fff",borderRadius:"16px",boxShadow:n.PANEL_SHADOW,color:"#333",display:"flex",fontFamily:"Arial, Helvetica, sans-serif",fontSize:"0.9rem",fontWeight:"600",gap:"8px",margin:"0 0 16px 0",padding:"20px",position:"relative",textAlign:"left"}),o.textContent=t.text;const r=document.createElement("span");r.setAttribute("aria-hidden","true"),n.css(r,{position:"absolute",bottom:"-7px",[t.edge]:"20px",height:"16px",width:"16px",border:"1px solid #fff",transform:"rotate(45deg)",backgroundColor:"#fff"}),o.appendChild(r);const s=()=>{e.remove()};return i.addEventListener("click",c=>{c.stopPropagation(),s(),t.onDismiss?.()},{once:!0}),e.addEventListener("click",c=>{c.target!==i&&t.onOpen()}),e.append(i,o),{el:e,remove:s}}var po="Form submitted.";function vr(t){if(typeof t=="string")return t||null;if(!t||typeof t!="object")return null;const e=t;if(typeof e.message=="string"&&e.message)return e.message;const i=e.result;if(typeof i=="string"&&i)return i;if(i&&typeof i=="object"){const o=i.message;if(typeof o=="string"&&o)return o}return null}var Er=0,wr="Hello, how can I help you today?",kr=6,_r=800,Sr=/^(?:\d+(?:\.\d+)?(?:px|rem|em|vw|vmin|vmax|%)|(?:min|max|clamp|calc)\([^;{}]+\))$/i;function Tr(t){const e=typeof t=="number"?`${t}px`:String(t).trim();return!Sr.test(e)||typeof CSS<"u"&&typeof CSS.supports=="function"&&!CSS.supports("width",`min(max(400px, ${e}), 100% - 40px)`)?null:e}function Rr(t){const e=typeof t=="string"?document.querySelector(t):t;if(!e)throw new Error(`mountChatWidget: target "${String(t)}" not found.`);return e}function Ar(t,e){const i=e.placement??"inline",o=i==="bubble",{welcomeMessage:r="Hello! How can I help you today?",allowFiles:s=!1,allowStop:c=!0,autoScroll:d=!0,height:h=500,defaultOpen:f=!1,logoUrl:p,showAgentName:x=!1,agentBubble:I=!1,bubbleStyle:w="default",showHeader:u=!0,forms:v,formSubmittedMessage:A=po,onFollowUpClick:E,onMessageSent:O,onMessageReceived:W,onFormSubmitted:C,onFormError:F,onOpen:y,onClose:k,icon:S,subtitle:D,conversationStarters:V=[],autoResume:M=!0,hideFooter:j=!1,loadHomeConfig:b=!1}=e,R=e.title??(o?"AGO Chatbot":"Chat"),z=e.width??(o?550:400),J=e.loadThreads??o,Y=e.feedback??o,m=gi(e.labels),B=e.placeholder??(o?m.askQuestion:"Type a message..."),G=e.prompt===void 0?wr:e.prompt,P=o?{...n.colorsToTheme(e.colors),...e.theme}:e.theme,ee=typeof r=="string"?{message:r,mode:"static"}:r,re=ee.message,be=ee.mode??"static",Ao="speed"in ee&&ee.speed||45,gn="followUpReplies"in ee&&ee.followUpReplies||void 0;if(!e.client&&!e.config?.baseUrl)throw new si.AgoError("mountChatWidget requires either `client` or `config` (with a baseUrl).","config_missing_base_url");const $=e.client??new _e.AgoClient(e.config),It=Rr(t),ft=i==="left"||i==="right",ae=ft||o,Oo=ae&&(e.launcher??!0);let te=ae?f:!0,Dt=!1;const Lo=e.mobile?.breakpoint??(o?450:768),Bt=e.mobile?.trigger??"tap",hn=typeof window<"u"&&!!window.matchMedia,ne=hn?window.matchMedia(`(max-width: ${Lo}px), (max-height: 500px) and (orientation: landscape)`):void 0,No=hn?window.matchMedia("(prefers-reduced-motion: reduce)"):void 0,Fo=!!ne,Qe=!ae&&!!ne,Je=Symbol("ago-scroll-lock");let Z=!1;const Ht=e.persistConversation??(o?!0:void 0),$e=Ht?li.createConversationSession(Ht===!0?{}:Ht):void 0;let K=e.conversationId??$e?.getLastActiveThread()??void 0,N=[],mt=[],se=!1,xe=null,Se;const Ze=[];function Io(a){if(typeof A=="function"){const g=A(a);if(typeof g=="string"&&g)return g}const l=vr(a);return l||(typeof A=="string"?A:po)}const ye=[],T=n.div({display:"flex",flexDirection:"column",height:ft?"100%":typeof h=="number"?`${h}px`:h,border:`1px solid ${n.BORDER_COLOR}`,borderRadius:n.RADIUS,overflow:"hidden",backgroundColor:n.PANEL_BACKGROUND,fontFamily:n.FONT_VAR,textAlign:"left",boxShadow:"rgba(15, 15, 15, 0.08) 0px 2px 16px 0px"});T.className="ago-chat-widget",n.applyTheme(T,P),o&&(n.css(T,{height:"100%",width:"100%",border:"none",borderRadius:"0",boxShadow:"none",backgroundColor:n.EMBED_BACKGROUND,color:n.TEXT_COLOR,fontSize:"14px",lineHeight:"24px"}),P?.headerText||T.style.setProperty("--ago-header-text-color",n.readableTextColor(P?.headerBg??P?.brand??"#03182f")));let ce;if(u&&!o){if(ce=n.div({padding:"14px 16px",borderBottom:`1px solid ${n.BORDER_COLOR}`,backgroundColor:n.HEADER_BACKGROUND,color:n.HEADER_TEXT_COLOR,display:"flex",alignItems:"center",gap:"10px"}),ce.className="ago-chat-widget__header",p){const l=document.createElement("img");l.src=p,l.alt="Logo",n.css(l,{height:"24px",width:"auto"}),ce.appendChild(l)}const a=document.createElement("h3");if(a.textContent=R,n.css(a,{margin:"0",fontSize:"15px",fontWeight:"600"}),ce.appendChild(a),ft){const l=document.createElement("button");l.type="button",l.className="ago-chat-widget__close",l.setAttribute("aria-label","Close"),l.textContent="×",n.css(l,{marginLeft:"auto",flexShrink:"0",display:"flex",alignItems:"center",justifyContent:"center",width:"44px",height:"44px",margin:"-10px -10px -10px auto",background:"transparent",border:"none",color:n.HEADER_TEXT_COLOR,fontSize:"22px",lineHeight:"1",cursor:"pointer",padding:"0"}),l.addEventListener("click",()=>qe()),ce.appendChild(l)}}const Q=n.div({flex:"1",overflow:"auto",overflowAnchor:d?"auto":"none",overscrollBehavior:"contain",padding:"16px",backgroundColor:n.MESSAGES_BACKGROUND});Q.className="ago-chat-widget__messages",Q.setAttribute("role","log"),Q.setAttribute("aria-live","polite"),Q.setAttribute("aria-relevant","additions text"),Q.setAttribute("aria-atomic","false");const pe=o?n.div({maxWidth:"768px",margin:"0 auto",padding:"0 8px",boxSizing:"border-box"}):Q;o&&(n.css(Q,{padding:"16px 0",backgroundColor:"transparent"}),pe.className="ago-chat-widget__list",Q.appendChild(pe));const Do=48;let Te=!0,zt=0;function Mt(a){zt++;try{a()}finally{const l=()=>{zt--};typeof queueMicrotask=="function"?queueMicrotask(l):l()}}function bn(){return Q.scrollHeight-Q.scrollTop-Q.clientHeight<=Do}const oe=document.createElement("button");oe.type="button",oe.className="ago-chat-widget__jump",oe.setAttribute("aria-label","Jump to latest message"),oe.innerHTML='<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 5v14M19 12l-7 7-7-7"/></svg>',n.css(oe,{position:"absolute",left:"50%",bottom:"12px",transform:"translateX(-50%)",width:"44px",height:"44px",display:"none",alignItems:"center",justifyContent:"center",border:`1px solid ${n.BORDER_COLOR}`,borderRadius:"50%",backgroundColor:n.PANEL_BACKGROUND,color:n.TEXT_COLOR,boxShadow:"rgba(15, 15, 15, 0.16) 0px 2px 10px 0px",cursor:"pointer",zIndex:"2"}),o&&(oe.setAttribute("aria-label",m.scrollToBottom),oe.replaceChildren(n.arrowDownwardIcon({size:20})),n.css(oe,{display:"flex",width:"36px",height:"36px",padding:"8px",boxSizing:"border-box",border:`1px solid ${n.NEUTRAL_BORDER}`,backgroundColor:"#fff",boxShadow:n.SHADOW_MD,transition:"opacity 0.3s",opacity:"0",pointerEvents:"none"}));function xn(){Te=!0,Mt(()=>{Q.scrollTop=Q.scrollHeight}),$t()}oe.addEventListener("click",xn);function $t(){const a=d?Te:bn();if(o){oe.style.opacity=a?"0":"1",oe.style.pointerEvents=a?"none":"auto";return}oe.style.display=a?"none":"flex"}function Ut(){d&&Te&&Mt(()=>{Q.scrollTop=Q.scrollHeight}),$t()}function yn(a){Mt(()=>{const l=Q.scrollTop;a(),(!d||!Te)&&(Q.scrollTop=l)}),Ut()}Q.addEventListener("scroll",()=>{zt>0||(Te=bn(),$t())});const Wt=n.div({position:"relative",flex:"1",display:"flex",minHeight:"0"});Wt.append(Q,oe);const{inputRow:Ce,setDisabled:Bo,focus:gt,restoreDraft:Ho,setPlaceholder:Cn,getValueAndClear:zo,setSpeechToTextEnabled:Mo,cancelRecording:et,destroy:$o}=ci({placeholder:B,allowFiles:s,transcribeAudio:e.speechToText?(a,l)=>$.transcribeAudio(a,l):void 0,speechToTextLabels:typeof e.speechToText=="object"?e.speechToText.labels:void 0,onSend:(a,l)=>{Ve(a,l)},onStop:c?()=>{wt()}:void 0,look:o?"embed":"classic",labels:o?{attachFiles:m.attachFiles,dismiss:m.dismiss,tooManyFiles:m.tooManyFiles,invalidFileType:m.invalidFileType,fileTooLarge:m.fileTooLarge}:void 0});n.ensureKeyframes(),e.speechToText&&$.getConfig().then(a=>{Z||Mo(a.permissions.some(l=>l.speechToTextEnabled))}).catch(()=>{}),o||T.append(...ce?[ce]:[],Wt,Ce);let tt=T,U,le,Pt;const nt=i==="left"?"left":"right";let jt,ht,ve,Ue,bt,ot,ue,Ne,We,Ee="home",xt="home",Pe=!1,yt=J,it=!1,rt=!1,Gt;if(o){if(U=n.div({position:"fixed",right:"20px",bottom:"80px",top:"max(40px, calc(100% - 880px))",width:`min(max(400px, ${n.PANEL_WIDTH}), var(--ago-panel-max, calc(100% - 40px)))`,height:"auto",borderRadius:"16px",boxShadow:n.PANEL_SHADOW,overflow:"hidden",transformOrigin:"right bottom",zIndex:"2147483000",backgroundColor:n.EMBED_BACKGROUND,display:"none",fontFamily:n.FONT_VAR}),U.className="ago-chat-widget-bubble",U.dataset.agoLayout="panel",n.applyTheme(U,P),!P?.panelWidth){const l=Tr(z);l?U.style.setProperty("--ago-panel-width",l):console.warn(`[AGO] mountChatWidget width "${String(z)}" is not a valid CSS length, ignoring. Expected e.g. 700 or "45rem". Falling back to 550px.`)}u&&(jt=ui({title:R,labels:m,onBack:()=>Le(xt,{byUser:!0}),onNewChat:()=>kt(),onClose:()=>qe()}),T.appendChild(jt.el)),ot=n.div({flex:"1",display:"flex",flexDirection:"column",minHeight:"0",overflow:"hidden"}),ot.className="ago-chat-widget__main",T.appendChild(ot),j||(ht=pi({labels:m,onNavigate:l=>Le(l,{byUser:!0})}),T.appendChild(ht.el)),ve=yr({title:R,subtitle:D,starters:V,onStarter:l=>{ve?.setPending(l),Ve(l.message??l.label,void 0,{agentId:l.agentId}).finally(()=>ve?.setPending(null))}});const a=e.colors?.background;Ue=xr({labels:m,onSelect:l=>{Pe=!0,xt="history",dt(l.id)},onNew:()=>kt(),hoverBackground:a&&n.isValidHexColor(a)?n.lightenColor(a,10):void 0,customFont:!!e.colors?.font}),bt=gr({messagesWrap:Wt,jumpBtn:oe}),U.appendChild(T),tt=U}ft&&(U=n.div({position:"fixed",top:"0",bottom:"0",[nt]:"0",width:typeof z=="number"?`${z}px`:z,maxWidth:"100vw",display:"flex",zIndex:"2147483000",transition:"transform 0.3s ease",boxShadow:"rgba(15, 15, 15, 0.18) 0px 0px 24px 0px"}),U.className="ago-chat-widget-panel",n.css(T,{height:"100%",width:"100%",borderRadius:"0",border:"none",boxShadow:"none",[nt==="left"?"borderRight":"borderLeft"]:`1px solid ${n.BORDER_COLOR}`}),U.appendChild(T),tt=U),Oo&&(Pt=Si({look:o?"bubble":"classic",edge:nt,title:R,icon:o?S:p,onClick:()=>o?Xn():Tt()}),le=Pt.el);const at=Qe?`ago-vt-${++Er}`:"",vn=52;let we=!1,Re=0,je=0,fe,st,Ae;const Ct={height:T.style.height,border:T.style.border,borderRadius:T.style.borderRadius,boxShadow:T.style.boxShadow};It.appendChild(tt),le&&It.appendChild(le),St(),o&&(G!==!1&&!te&&(Ne=setTimeout(Jo,1e3)),document.addEventListener("keydown",jn),window.addEventListener("resize",Gn)),Qe&&(fe=ii(),T.insertBefore(fe,T.firstChild),st=document.createElement("style"),st.id=at,st.textContent=`::view-transition-group(${at}),::view-transition-group(${at}-bar){animation-duration:0.3s;animation-timing-function:cubic-bezier(0.4,0,0.2,1)}`,document.head.appendChild(st),(Bt==="focus"||Bt==="tap")&&(T.addEventListener("pointerdown",a=>{if(we||!ne?.matches)return;const l=Ce.contains(a.target);if(Bt==="tap"){if((a.target instanceof Element?a.target:null)?.closest("button,a[href],[role='button']"))return}else if(!l)return;l&&a.preventDefault(),pt()},!0),T.addEventListener("focusin",a=>{ne?.matches&&Ce.contains(a.target)&&pt()}))),Fo&&document.addEventListener("keydown",Kn),ne&&ne.addEventListener("change",Yn);const En=E!==!1,wn=E===!1?void 0:E??(a=>{Qe&&ne?.matches&&!we?pt().then(()=>Ve(a)):Ve(a)}),Ge=Y===!0?{}:Y||null,Uo={...pn,...Ge?.labels,reasons:{...pn.reasons,...Ge?.labels?.reasons}},vt=new Map;function kn(a){if(!Ge||!a.id||!a.conversationId||a.status!=="DONE"||!a.content)return null;let l=vt.get(a.id);l||(l=dr(),vt.set(a.id,l));const g=async(_,H)=>{try{return await $.submitFeedback(a.id,_,H),Ge.onSubmit?.({messageId:a.id,rating:_,reasons:H?.reasons??[],comment:H?.comment||void 0}),!0}catch(L){return Ge.onError?.(L instanceof Error?L:new Error(String(L))),!1}};return pr({state:l,labels:Uo,askWhy:Ge.askWhy??!o,onRate:_=>{g(_)},onReport:(_,H)=>g(_,H),look:o?"embed":"classic"})}const me=e.toolCallForm??{},ke={...To,...me.labels},_n=$.getUserIdentity(),Vt=me.userEmail??_n.email,Sn=!Vt&&!_n.hasJwt;let Fe=null,Tn=!1,Rn,qt=!1;const lt=new Map,Et=new Set;function Wo(){Rn||(Rn=$.getConfig().then(a=>{const l=a.permissions[0];Fe=l?.ticketForm??null,qt=!!l?.fileAttachmentsEnabled}).catch(()=>{Fe=null}).then(()=>{if(Tn=!0,!Z)for(const a of lt.values())a.kind==="ticket"&&(Fe&&qi(a.state,a.call.ticket,Fe),a.view.rebuild({ticketForm:Fe,configLoading:!1,allowFiles:s||qt}))}))}function Xt(){for(const a of lt.values())a.kind==="embed"&&a.view.destroy();lt.clear(),Et.clear()}function Po(a){for(const l of N){const g=l.toolCalls?.find(_=>_.id===a);if(g)return g}}function jo(a){const l=lt.get(a.id);if(l)return l;let g;if(a.allowedToCreateTicket===!1){const _=n.div({display:"flex",flexDirection:"column",gap:"16px"});_.className="ago-ticket-form ago-ticket-form--denied",_.appendChild(Yi(ke.notAllowed)),g={kind:"static",el:_}}else if(a.mode==="embed"){const _={status:lo(a)?"submitted":"loading"};g={kind:"embed",state:_,view:nr({state:_,embedHtml:a.embedHtml,description:a.embedDescription,ticket:a.ticket,email:Vt,labels:ke,message:a.message,successMessage:me.successMessage,onSubmitted:H=>{Et.add(a.id),$.submitToolCallForm(a.id,{success:!0,source:"embed",thread_id:K,captured_form_data:H}).then(L=>{const q=L.ticket??L.result?.ticket;me.onSubmitted?.({toolCallId:a.id,toolName:a.toolName,mode:"embed",ticket:q?.ticket_id?{id:String(q.ticket_id),url:q.ticket_url}:void 0,values:H??{}})}).catch(L=>{me.onError?.(L instanceof Error?L:new Error(String(L)))}).finally(()=>{Z||X()})}})}}else{Wo();const _=_o(a.ticket,Fe,Vt??""),H=lo(a);H&&(_.submitted=H),g={kind:"ticket",state:_,view:Qi({state:_,ticketForm:Fe,configLoading:!Tn,labels:ke,message:a.message,requireEmail:Sn,allowFiles:s||qt,successMessage:me.successMessage,successUrlLabel:me.successUrlLabel,createTicket:L=>$.createTicket({subject:L.subject,body:L.body,priority:L.priority,typology:L.typology,conversationId:K,email:L.email,customFields:L.customFields,files:L.files,ticketFormId:L.ticketFormId}),onCreated:(L,q)=>{Et.add(a.id);const ge=Object.entries(q.customFields).map(([Ie,ai])=>({id:Ie,value:ai}));$.submitToolCallForm(a.id,{success:!0,ticket_id:L.id,ticket_url:L.url,subject:q.ticket.subject,typology:q.ticket.typology,priority:q.ticket.priority,body:q.ticket.body,tag:q.ticket.tag,custom_fields:ge,created_at:new Date().toISOString()}).catch(Ie=>{me.onError?.(Ie instanceof Error?Ie:new Error(String(Ie)))}).finally(()=>{me.onSubmitted?.({toolCallId:a.id,toolName:a.toolName,mode:"form",ticket:{id:L.id,url:L.url},values:{...q.ticket,custom_fields:q.customFields,email:Sn?q.email:void 0}}),Z||X()})},onError:me.onError}),call:a}}return lt.set(a.id,g),g}function An(a){if(a.type!=="form"||a.displayMode==="collapsible")return null;const l=ir(N);if(l&&l!==a.id){const _=Po(l),H=!!_?.askToTalkToHuman&&_.allowedToCreateTicket===!1;return sr(H?ke.contactFormRejected:ke.contactFormCreated,H?"warning":"info")}if(!or(a))return lr(a,ke);const g=jo(a);return g.kind==="static"?g.el:g.view.el}let Oe;function Go(){const a=N.some(_=>_.toolCalls?.some(H=>H.type==="form")),l=Et.size>0||rr(N);if(!a&&!l){Ce.style.display="",Oe?.remove();return}Oe||(Oe=n.div({margin:"12px",borderRadius:"24px",border:`1px solid ${n.BORDER_COLOR}`,boxShadow:"0 1px 2px rgba(0, 0, 0, 0.05)",backgroundColor:n.PANEL_BACKGROUND,display:"flex",flexDirection:"column",alignItems:"center",gap:"16px",padding:"28px 24px",textAlign:"center",fontFamily:n.FONT_VAR}),Oe.className="ago-chat-blocked"),Oe.replaceChildren();const g=document.createElement("p");if(g.textContent=l?ke.ticketCreatedBlocked:ke.formPending,n.css(g,{color:n.MUTED_TEXT_COLOR,lineHeight:"1.625",fontSize:"16px",margin:"0",whiteSpace:"pre-line"}),Oe.appendChild(g),l){const _=document.createElement("button");_.type="button",_.className="ago-chat-blocked__new",n.css(_,{display:"inline-flex",alignItems:"center",gap:"8px",borderRadius:"9999px",padding:"0 20px",minHeight:"44px",backgroundColor:"var(--ago-brand-color, #03182f)",color:"var(--ago-brand-text-color, #fff)",border:"none",cursor:"pointer",font:"inherit",fontSize:"14px",fontWeight:"500"}),_.append(n.addCommentIcon({size:18}));const H=document.createElement("span");H.textContent=ke.newConversation,_.appendChild(H),_.addEventListener("click",()=>{kt(),me.onNewConversation?.()}),Oe.appendChild(_)}Ce.style.display="none",Ce.parentElement?.insertBefore(Oe,Ce)}function On(a){const l=N[a];return o?Ii(l,{isLast:a===N.length-1,followUpEnabled:En,followUpHandler:wn,agentRowTinted:!!P?.agentBubbleBg,agentRowTextTinted:!!P?.agentBubbleText,labels:m,actionsRow:kn(l),renderToolCall:An}):Ei(l,{...Vo(a),renderToolCall:An})}function Vo(a){const l=N.length-1;return{isLast:a===l,isLastOfBlock:a===l||N[a+1].role!==N[a].role,bubbleStyle:w,showAgentName:x,agentBubble:I,followUpEnabled:En,followUpHandler:wn,isMobile:!!ne?.matches,feedbackRow:kn(N[a])}}function qo(){if(xe||Ze.length>0)return!1;const a=N.length-1,l=N[a];if(!l||l.role!=="assistant")return!1;const g=mt[a];if(!g||g.parentNode!==pe)return!1;const _=On(a),H=document.activeElement,L=H instanceof HTMLElement&&g.contains(H)?H:null;return yn(()=>pe.replaceChild(_,g)),L&&_.contains(L)&&L.focus({preventScroll:!0}),mt[a]=_,!0}function X(){yn(Xo);const a=N[N.length-1],l=se&&a?.role==="assistant"&&(a.status==="IN_PROGRESS"||a.status==="WAITING_CLIENT");Q.setAttribute("aria-busy",l?"true":"false"),Bo(l),Go()}function Xo(){if(pe.replaceChildren(),mt=[],N.length===0){if(o){if(it){const a=n.div({display:"flex",justifyContent:"center",padding:"32px 0"});a.className="ago-chat-widget__thread-loading";const l=n.div({width:"32px",height:"32px",borderRadius:"50%",borderBottom:"2px solid var(--ago-brand-color, #03182f)",animation:"ago-spin 1s linear infinite"});l.setAttribute("role","status"),a.appendChild(l),pe.appendChild(a)}}else if(be==="static"){const a=n.div({textAlign:"center",color:n.MUTED_TEXT_COLOR,padding:"24px 16px",fontSize:"16px",lineHeight:"1.5"});a.appendChild(Me(re)),pe.appendChild(a)}}else N.forEach((a,l)=>{const g=On(l);mt[l]=g,pe.appendChild(g)});for(const a of Ze)pe.appendChild(wi(a));if(xe){if(o){pe.appendChild(Oi(m.errorTitle,xe));return}const a=n.div({padding:"10px 14px",backgroundColor:"#fef2f2",color:"#dc2626",borderRadius:"12px",marginTop:"8px",fontSize:"13px",border:"1px solid #fecaca"});a.setAttribute("role","alert"),a.textContent=xe,pe.appendChild(a)}}function Kt(){for(let a=N.length-1;a>=0;a--){const l=N[a];if(l.role==="assistant"&&(l.status==="IN_PROGRESS"||l.status==="WAITING_CLIENT"))return l}}const Ln=a=>{K||(K=a.conversationId)},Nn=a=>{const l=Kt();l&&(l.content+=a.content,qo()||X())},Fn=a=>{const l=N.findIndex(g=>g.id===a.id||g.role==="assistant"&&g.status==="IN_PROGRESS");l>=0?N[l]=a:N.push(a),X(),ct()||gt()},In=a=>{const l=N.findIndex(g=>g.id===a.id||g.role==="assistant"&&g.status==="IN_PROGRESS");l>=0?N[l]=a:N.push(a),se=!1,X(),a.status==="DONE"&&W?.({id:a.id,content:a.content})},Dn=()=>{const a=Kt();a&&(a.content?a.status="CANCELED":N=N.filter(l=>l!==a)),se=!1,X()},Bn=a=>{xe=a.error,se=!1,N=N.filter(l=>!l.id.startsWith("temp-")),X()};function Ko(a){const l={id:`ago-intro-${Date.now()}`,conversationId:"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date};N.push(l),X();const g=a.match(/\S+\s*/g)??[a];let _=0;Se=setInterval(()=>{if(_>=g.length){clearInterval(Se),Se=void 0,l.status="DONE",gn&&(l.followUpReplies=gn),X();return}l.content+=g[_],_++,X()},Ao)}const Hn=a=>{const l=ye.find(g=>g.id===a.conversationId);l&&(l.title=a.title),o&&Ee==="history"&&Ue?.render({threads:ye,loading:yt})},zn=a=>{if(a.type!=="form")return;const l=Kt()??[...N].reverse().find(H=>H.role==="assistant");if(!l)return;const g=l.toolCalls??[],_=g.findIndex(H=>H.id===a.id);_>=0?g[_]=a:g.push(a),l.toolCalls=g,X()};$.on("message:start",Ln),$.on("message:chunk",Nn),$.on("message:answer-complete",Fn),$.on("message:complete",In),$.on("message:stopped",Dn),$.on("message:error",Bn),$.on("conversation:title",Hn),$.on("toolCall:received",zn);const Mn=a=>C?.(a),$n=a=>F?.(a);C&&$.on("form:submitted",Mn),F&&$.on("form:error",$n);const Yt=[];let Un=!1;const Wn=a=>{if(Un)return;Yt.push(a.install($));let l=a.store.get().submitted;const g=a.store.subscribe(_=>{_.submitted&&!l&&(Ze.push(Io(_.submitResult)),X()),l=_.submitted});Yt.push(g)};for(const a of v??[])a.schema!=null?Wn(to.createFormCollector(a)):to.loadFormCollector($,a).then(l=>Wn(l)).catch(()=>{});async function Ve(a,l,g){const _=a.trim();if(!_||se)return;if(o&&Ee!=="chat"&&(xt="home",Le("chat",{byUser:!0})),O?.(_),se=!0,xe=null,Te=!0,Se){clearInterval(Se),Se=void 0;const L=N.find(q=>q.id.startsWith("ago-intro-"));L&&!L.content?N=N.filter(q=>q!==L):L&&(L.status="DONE")}const H=Date.now();N.push({id:`temp-user-${H}`,conversationId:K||"",content:_,role:"user",status:"DONE",attachments:l&&l.length>0?_e.attachmentsFromFiles(l):void 0,createdAt:new Date}),N.push({id:`temp-assistant-${H}`,conversationId:K||"",content:"",role:"assistant",status:"IN_PROGRESS",createdAt:new Date}),X(),d||xn();try{const L=await $.sendMessage(_,{conversationId:K,files:l,...g?.agentId?{agentId:g.agentId}:{}});L.conversationId&&(K||(K=L.conversationId),$e?.setActiveThread(L.conversationId,L.createdAt));const q=N.find(ge=>ge.id===`temp-user-${H}`);if(q&&(q.id=`user-${H}`,q.conversationId=L.conversationId),L.id&&!N.some(ge=>ge.id===L.id)){const ge=N.findIndex(Ie=>Ie.id===`temp-assistant-${H}`);ge>=0?N[ge]=L:N.push(L)}N=N.filter(ge=>!ge.id.startsWith("temp-")),L.status!=="WAITING_CLIENT"&&(se=!1),X(),J&&Qt()}catch(L){xe=L instanceof Error?L.message:"Failed to send message",se=!1,N=N.filter(q=>!q.id.startsWith("temp-")),Ho(_,l),X()}}async function wt(){se&&await $.stop()}async function Qt(){try{const{data:a}=await $.getConversations();ye.splice(0,ye.length,...a)}catch{}return yt=!1,o&&!Z&&(Ee==="history"&&Ue?.render({threads:ye,loading:!1}),Yo()),ye}async function Pn(a){try{const l=await $.getConversation(a);if(K!==a)return;const g=l?.messages??[];it=!1,g.length>0&&N.length===0?(N=g,X()):o&&X(),o&&$e?.setActiveThread(a,l.lastMessageDate)}catch{if(K!==a)return;it=!1,N.length===0&&($e?.clear(),K=void 0,o&&(Ee==="chat"&&Le("home"),X()))}}function Le(a,l){if(!o||!ot||!ve||!bt||!Ue)return;l?.byUser&&(Pe=!0),Ee!==a&&et(),Ee=a,a==="home"?(ve.composerSlot.appendChild(Ce),Cn(B)):a==="chat"&&(bt.composerSlot.appendChild(Ce),Cn(""));const g=a==="home"?ve.el:a==="chat"?bt.el:Ue.el;ot.replaceChildren(g),a==="history"&&Ue.render({threads:ye,loading:yt}),a==="chat"&&(Te=!0,Ut()),jt?.update({screen:a}),ht?.setActive(a),ht?.setVisible(a!=="chat")}async function dt(a){o&&(et(),se&&await wt(),K=a,N=[],xe=null,Ze.length=0,vt.clear(),Xt(),it=!0,Le("chat"),X(),await Pn(a))}function kt(){se&&wt(),K=void 0,N=[],xe=null,Ze.length=0,vt.clear(),Xt(),it=!1,$e?.clear(),zo(),ve?.setPending(null),xt="home",o&&Le("home",{byUser:!0}),X()}function Yo(){if(!o||rt)return;if(rt=!0,!M||Pe||Ee!=="home"||N.length>0||K){_t();return}const a=br(ye);a&&dt(a.id),_t()}async function Qo(){let a;try{a=(await $.getConfig()).permissions[0]?.homePage}catch{return}Z||!a||(ve?.setContent({title:a.title||void 0,subtitle:a.subtitle||void 0,starters:a.starters.length?a.starters.map(l=>({label:l.label,message:l.message,agentId:l.agentId})):void 0}),a.widgetStarter&&(Gt=a.widgetStarter,_t()))}function _t(){const a=Gt;!a||Z||te&&(yt&&!rt||(Gt=void 0,!(Pe||K||N.length>0||se||Ee!=="home")&&Ve(a.message,void 0,{agentId:a.agentId})))}function Jo(){Ne=void 0,!(Z||te||G===!1||ue)&&(ue=Cr({text:G,edge:nt,onOpen:()=>Tt(),onDismiss:()=>{ue=void 0}}),It.appendChild(ue.el),Jt())}function Jt(){if(!o||!U||!le||ct()||!le.offsetHeight)return;const a=getComputedStyle(le),l=parseFloat(a.bottom),g=parseFloat(a.right);if(Number.isNaN(l)||Number.isNaN(g))return;const _=Math.round(l+le.offsetHeight)+kr,H=Math.round(g),L=[U];ue&&L.push(ue.el);for(const q of L)q.style.setProperty("bottom",`${_}px`,"important"),q.style.setProperty("right",`${H}px`,"important");U.style.setProperty("top",`max(40px, calc(100% - ${_+_r}px))`,"important"),U.style.setProperty("--ago-panel-max",`calc(100% - ${H+20}px)`)}function jn(a){a.key!=="Escape"||!te||a.defaultPrevented||a.target instanceof HTMLInputElement||a.target instanceof HTMLTextAreaElement||Zt()||qe()}function Gn(){We&&clearTimeout(We),We=setTimeout(()=>{We=void 0,!Z&&(Jt(),ve?.syncColumns())},150)}o?(Le("home"),X(),b&&Qo(),e.conversationId?(Pe=!0,rt=!0,dt(e.conversationId)):K&&M?(rt=!0,dt(K)):K=void 0):(X(),Qe&&ne?.matches||gt(),K?Pn(K):be==="streaming"&&Ko(re)),J&&Qt();const Vn={client:$,element:tt,sendMessage:Ve,stop:wt,...ae||Qe?{open:Zo,close:ei,toggle:ti}:{},newConversation:kt,...o?{showScreen:a=>Le(a,{byUser:!0}),openConversation:a=>(Pe=!0,dt(a))}:{},session:$e,threads:ye,refreshThreads:Qt,destroy(){Z||(Z=!0,$o(),Se&&clearInterval(Se),Ne&&clearTimeout(Ne),We&&clearTimeout(We),ue?.remove(),$.off("message:start",Ln),$.off("message:chunk",Nn),$.off("message:answer-complete",Fn),$.off("message:complete",In),$.off("message:stopped",Dn),$.off("message:error",Bn),$.off("conversation:title",Hn),$.off("toolCall:received",zn),Xt(),C&&$.off("form:submitted",Mn),F&&$.off("form:error",$n),Un=!0,Yt.forEach(a=>a()),tt.remove(),le?.remove(),fe?.remove(),document.removeEventListener("keydown",jn),window.removeEventListener("resize",Gn),st?.remove(),Ae?.remove(),ne?.removeEventListener("change",Yn),document.removeEventListener("keydown",Kn),nn(),Dt=!1,n.unlockBackgroundScroll(Je),e.client||$.destroy())}};return o&&Object.defineProperty(Vn,"screen",{get:()=>Ee,enumerable:!0}),Vn;function St(){if(!U)return;if(o)qn();else{const l=nt==="left"?"border-right":"border-left";ne?.matches?(U.style.width="100%",T.style.borderRadius="0",T.style.removeProperty(l)):(U.style.width=typeof z=="number"?`${z}px`:z,T.style.setProperty(l,`1px solid ${n.BORDER_COLOR}`));const g=i==="left"?"translateX(-100%)":"translateX(100%)";U.style.transform=te?"translateX(0)":g,le&&(le.style.display=te?"none":"flex")}U.setAttribute("aria-hidden",te?"false":"true");const a=Zt();a!==Dt&&(Dt=a,a?(T.setAttribute("role","dialog"),T.setAttribute("aria-modal","true"),T.setAttribute("aria-label",R),T.tabIndex=-1,T.style.paddingBottom="env(safe-area-inset-bottom)",n.lockBackgroundScroll(Je),Re=en(),tn(),Qn()):(nn(),oi(),Re=0,T.removeAttribute("role"),T.removeAttribute("aria-modal"),T.removeAttribute("aria-label"),T.style.removeProperty("padding-bottom"),n.unlockBackgroundScroll(Je)))}function qn(){if(!U)return;U.style.display=te?"block":"none",Pt?.setOpen(te);const a=ct();if(le&&(le.style.display=a&&te?"none":"flex"),a){for(const l of["bottom","right","top","--ago-panel-max"])U.style.removeProperty(l);n.css(U,{top:"0",left:"0",right:"0",bottom:"0",width:"100dvw",maxWidth:"100vw",height:"var(--ago-vh, 100dvh)",borderRadius:"0",paddingTop:"env(safe-area-inset-top, 0px)",paddingBottom:"env(safe-area-inset-bottom, 0px)",paddingLeft:"env(safe-area-inset-left, 0px)",paddingRight:"env(safe-area-inset-right, 0px)",boxSizing:"border-box"}),U.dataset.agoLayout="fullscreen",te&&(ue?.remove(),ue=void 0)}else{for(const l of["left","max-width","padding-top","padding-bottom","padding-left","padding-right"])U.style.removeProperty(l);n.css(U,{right:"20px",bottom:"80px",top:"max(40px, calc(100% - 880px))",width:`min(max(400px, ${n.PANEL_WIDTH}), var(--ago-panel-max, calc(100% - 40px)))`,height:"auto",borderRadius:"16px"}),U.dataset.agoLayout="panel",Jt()}}function Tt(){te=!0,Ne&&(clearTimeout(Ne),Ne=void 0),ue?.remove(),ue=void 0,St(),ct()?T.focus({preventScroll:!0}):gt(),_t(),y?.()}function qe(){et(),te=!1,St(),k?.()}function Xn(){te?qe():Tt()}function Zo(){ae?Tt():pt()}function ei(){et(),ae?qe():ut()}function ti(){ae?Xn():we?ut():pt()}function ct(){return!!ne?.matches}function Zt(){return ct()&&(ae?te:we)}function ni(){return Array.from(T.querySelectorAll('a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex="-1"])')).filter(a=>a.getClientRects().length>0)}function Kn(a){if(!Zt())return;if(a.key==="Escape"){ae?qe():ut();return}if(a.key!=="Tab")return;const l=ni();if(l.length===0){a.preventDefault();return}const g=l[0],_=l[l.length-1],H=document.activeElement;a.shiftKey&&(H===g||!T.contains(H))?(a.preventDefault(),_.focus()):!a.shiftKey&&(H===_||!T.contains(H))&&(a.preventDefault(),g.focus())}function Yn(a){ae?St():!a.matches&&we&&ut(),X()}function en(){return window.visualViewport?.height??window.innerHeight}function tn(){const a=window.visualViewport,l=a?.offsetTop??0,g=a?.height??Re;if(ae){if(!U)return;const H=window.innerHeight||Re,L=Math.max(0,H-(l+g));U.style.bottom=`${L}px`,U.style.top=`${l}px`;return}const _=Math.min(0,l+g-Re);T.style.top=`${_}px`,fe&&(fe.style.top=`${l}px`)}function oi(){ae&&U&&(U.style.removeProperty("bottom"),U.style.removeProperty("top"),o&&!Z&&qn())}function Rt(){je||(je=requestAnimationFrame(()=>{je=0,!Z&&tn()}))}function Qn(){window.visualViewport?.addEventListener("resize",Rt),window.visualViewport?.addEventListener("scroll",Rt)}function nn(){window.visualViewport?.removeEventListener("resize",Rt),window.visualViewport?.removeEventListener("scroll",Rt),je&&(cancelAnimationFrame(je),je=0)}function Jn(){Te=!0,Ut()}function ii(){const a=n.div({position:"fixed",top:"0",left:"0",right:"0",height:`calc(${vn}px + env(safe-area-inset-top))`,display:"none",alignItems:"center",justifyContent:"space-between",padding:"env(safe-area-inset-top) 14px 0",backgroundColor:n.PANEL_BACKGROUND,borderBottom:`1px solid ${n.BORDER_COLOR}`,zIndex:"2147483001",fontFamily:n.FONT_VAR});if(a.className="ago-chat-widget-mobile-bar",p){const g=document.createElement("img");g.src=p,g.alt="",n.css(g,{height:"28px",width:"auto"}),a.appendChild(g)}else if(R){const g=document.createElement("span");g.textContent=R,n.css(g,{fontSize:"15px",fontWeight:"600",color:n.TEXT_COLOR,overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis"}),a.appendChild(g)}else a.appendChild(n.div({}));const l=document.createElement("button");return l.type="button",l.setAttribute("aria-label","Close"),l.textContent="×",n.css(l,{flexShrink:"0",width:"44px",height:"44px",marginRight:"-10px",display:"flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",fontSize:"26px",lineHeight:"1",color:n.TEXT_COLOR,cursor:"pointer",padding:"0"}),l.addEventListener("click",()=>{ut()}),a.appendChild(l),a}function ri(){return typeof document.startViewTransition=="function"&&!No?.matches&&!!ne?.matches}function Zn(a){const l=document;if(ri()&&l.startViewTransition){T.style.setProperty("view-transition-name",at),fe?.style.setProperty("view-transition-name",`${at}-bar`);const g=()=>{T.style.removeProperty("view-transition-name"),fe?.style.removeProperty("view-transition-name")};return l.startViewTransition(a).finished.then(g,g)}return a(),Promise.resolve()}function eo(a){if(a)Ae&&T.parentElement?.insertBefore(Ae,T),n.css(T,{position:"fixed",top:"0",left:"0",right:"0",bottom:"0",height:"var(--ago-vh, 100dvh)",zIndex:"2147483000",border:"none",borderRadius:"0",boxShadow:"none",paddingTop:`calc(${vn}px + env(safe-area-inset-top))`,paddingBottom:"env(safe-area-inset-bottom)"}),T.setAttribute("role","dialog"),T.setAttribute("aria-modal","true"),T.setAttribute("aria-label",R),ce&&(ce.style.display="none"),fe&&(fe.style.display="flex");else{Ae?.remove(),Ae=void 0;for(const l of["position","top","left","right","bottom","z-index","padding-top","padding-bottom"])T.style.removeProperty(l);T.style.height=Ct.height,T.style.border=Ct.border,T.style.borderRadius=Ct.borderRadius,T.style.boxShadow=Ct.boxShadow,T.removeAttribute("role"),T.removeAttribute("aria-modal"),T.removeAttribute("aria-label"),ce&&(ce.style.display="flex"),fe&&(fe.style.display="none")}}function pt(){if(Z||we||!ne?.matches)return Promise.resolve();const a=T.getBoundingClientRect();if(a.height>=en()*.8)return Promise.resolve();we=!0,Ae=n.div({width:`${a.width}px`,height:`${a.height}px`}),Ae.className="ago-chat-widget-spacer",Ae.setAttribute("aria-hidden","true"),Re=en(),T.style.setProperty("--ago-vh",`${Re}px`),tn(),Qn(),n.lockBackgroundScroll(Je);const l=Zn(()=>eo(!0));return l.then(()=>{Z||(Jn(),gt())}),Jn(),y?.(),l}function ut(){if(!we)return Promise.resolve();et(),we=!1,nn(),n.unlockBackgroundScroll(Je),T.querySelector("textarea")?.blur();const a=Zn(()=>eo(!1));return a.then(()=>{Z||T.style.removeProperty("--ago-vh")}),Re=0,k?.(),a}}exports.DEFAULT_FEEDBACK_LABELS=pn;exports.DEFAULT_SPEECH_TO_TEXT_LABELS=n.DEFAULT_SPEECH_TO_TEXT_LABELS;exports.DEFAULT_TOOL_CALL_FORM_LABELS=To;exports.DEFAULT_WIDGET_LABELS=an;exports.colorsToTheme=n.colorsToTheme;exports.compactMediaQuery=n.compactMediaQuery;exports.createSheetController=n.createSheetController;exports.mountChatWidget=Ar;exports.readableTextColor=n.readableTextColor;exports.renderMarkdown=Me;
|