vanilla-agent 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.global.js +1 -1
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/launcher.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -11,6 +11,6 @@
|
|
|
11
11
|
<span class="tvw-text-xs tvw-text-cw-muted" data-role="launcher-subtitle"></span>
|
|
12
12
|
</span>
|
|
13
13
|
<span class="tvw-ml-2 tvw-grid tvw-place-items-center tvw-rounded-full tvw-bg-cw-primary tvw-text-cw-call-to-action" data-role="launcher-call-to-action-icon">\u2197</span>
|
|
14
|
-
`,e.addEventListener("click",o);let n=l=>{var J,I,x,P,f,yt,F,T,ot,ct;let i=(J=l.launcher)!=null?J:{},W=e.querySelector("[data-role='launcher-title']");W&&(W.textContent=(I=i.title)!=null?I:"Chat Assistant");let b=e.querySelector("[data-role='launcher-subtitle']");b&&(b.textContent=(x=i.subtitle)!=null?x:"Get answers fast");let k=e.querySelector(".tvw-flex-col");k&&(i.textHidden?k.style.display="none":k.style.display="");let h=e.querySelector("[data-role='launcher-icon']");if(h)if(i.agentIconHidden)h.style.display="none";else{let dt=(P=i.agentIconSize)!=null?P:"40px";if(h.style.height=dt,h.style.width=dt,h.innerHTML="",i.agentIconName){let xt=parseFloat(dt)||24,ht=ft(i.agentIconName,xt*.6,"#ffffff",2);ht?(h.appendChild(ht),h.style.display=""):(h.textContent=(f=i.agentIconText)!=null?f:"\u{1F4AC}",h.style.display="")}else i.iconUrl?h.style.display="none":(h.textContent=(yt=i.agentIconText)!=null?yt:"\u{1F4AC}",h.style.display="")}let D=e.querySelector("[data-role='launcher-image']");if(D){let dt=(F=i.agentIconSize)!=null?F:"40px";D.style.height=dt,D.style.width=dt,i.iconUrl&&!i.agentIconName&&!i.agentIconHidden?(D.src=i.iconUrl,D.style.display="block"):D.style.display="none"}let M=e.querySelector("[data-role='launcher-call-to-action-icon']");if(M){let dt=(T=i.callToActionIconSize)!=null?T:"32px";M.style.height=dt,M.style.width=dt,i.callToActionIconBackgroundColor?(M.style.backgroundColor=i.callToActionIconBackgroundColor,M.classList.remove("tvw-bg-cw-primary")):(M.style.backgroundColor="",M.classList.add("tvw-bg-cw-primary"));let xt=0;if(i.callToActionIconPadding?(M.style.boxSizing="border-box",M.style.padding=i.callToActionIconPadding,xt=(parseFloat(i.callToActionIconPadding)||0)*2):(M.style.boxSizing="",M.style.padding=""),i.callToActionIconHidden)M.style.display="none";else if(M.style.display="",M.innerHTML="",i.callToActionIconName){let ht=parseFloat(dt)||24,v=Math.max(ht-xt,8),z=ft(i.callToActionIconName,v,"currentColor",2);z?M.appendChild(z):M.textContent=(ot=i.callToActionIconText)!=null?ot:"\u2197"}else M.textContent=(ct=i.callToActionIconText)!=null?ct:"\u2197"}let Y=i.position&&Se[i.position]?Se[i.position]:Se["bottom-right"],O="tvw-fixed tvw-flex tvw-items-center tvw-gap-3 tvw-rounded-launcher tvw-bg-cw-surface tvw-py-2.5 tvw-pl-3 tvw-pr-3 tvw-shadow-lg tvw-border tvw-border-gray-200 tvw-transition hover:tvw-translate-y-[-2px] tvw-cursor-pointer";e.className=`${O} ${Y}`},r=()=>{e.removeEventListener("click",o),e.remove()};return t&&n(t),{element:e,update:n,destroy:r}};var Zn=t=>{var b,k,h,D,M;if(!((k=(b=t==null?void 0:t.launcher)==null?void 0:b.enabled)!=null?k:!0)){let Y=p("div","tvw-relative tvw-w-full tvw-h-full"),O=p("div","tvw-relative tvw-w-full tvw-h-full tvw-min-h-[360px]");return Y.appendChild(O),{wrapper:Y,panel:O}}let e=(h=t==null?void 0:t.launcher)!=null?h:{},n=e.position&&Se[e.position]?Se[e.position]:Se["bottom-right"],r=p("div",`tvw-fixed ${n} tvw-z-50 tvw-transition`),l=p("div","tvw-relative tvw-min-h-[320px]"),i=(M=(D=t==null?void 0:t.launcher)==null?void 0:D.width)!=null?M:t==null?void 0:t.launcherWidth,W=i!=null?i:"min(400px, calc(100vw - 24px))";return l.style.width=W,l.style.maxWidth=W,r.appendChild(l),{wrapper:r,panel:l}},Qn=(t,o=!0)=>{var Et,zt,Nt,ae,ce,kt,Be,ee,de,rt,Ut,ue,pe,He,ge,me,fe,we,he,ve,ye,be,xe,s,E,a,L,g,w,m,R,B,c,y,S,u,d,H,N,Z,nt,lt,at,Q,j,U,K,Tt,V,Kt,De,qe,ze,$e,Oe,_e,Ue,je,Xe,Ye;let e=p("div","tvw-flex tvw-h-full tvw-w-full tvw-flex-col tvw-bg-cw-surface tvw-text-cw-primary tvw-rounded-2xl tvw-overflow-hidden tvw-shadow-2xl tvw-border tvw-border-cw-border"),n=p("div","tvw-flex tvw-items-center tvw-gap-3 tvw-bg-cw-surface tvw-px-6 tvw-py-5 tvw-border-b-cw-divider"),r=(Et=t==null?void 0:t.launcher)!=null?Et:{},l=(zt=r.headerIconSize)!=null?zt:"48px",i=(Nt=r.closeButtonSize)!=null?Nt:"32px",W=(ae=r.closeButtonPlacement)!=null?ae:"inline",b=(ce=r.headerIconHidden)!=null?ce:!1,k=r.headerIconName,h=p("div","tvw-flex tvw-items-center tvw-justify-center tvw-rounded-xl tvw-bg-cw-primary tvw-text-white tvw-text-xl");if(h.style.height=l,h.style.width=l,!b)if(k){let q=parseFloat(l)||24,ut=ft(k,q*.6,"#ffffff",2);ut?h.replaceChildren(ut):h.textContent=(Be=(kt=t==null?void 0:t.launcher)==null?void 0:kt.agentIconText)!=null?Be:"\u{1F4AC}"}else if((ee=t==null?void 0:t.launcher)!=null&&ee.iconUrl){let q=p("img");q.src=t.launcher.iconUrl,q.alt="",q.className="tvw-rounded-xl tvw-object-cover",q.style.height=l,q.style.width=l,h.replaceChildren(q)}else h.textContent=(rt=(de=t==null?void 0:t.launcher)==null?void 0:de.agentIconText)!=null?rt:"\u{1F4AC}";let D=p("div","tvw-flex tvw-flex-col"),M=p("span","tvw-text-base tvw-font-semibold");M.textContent=(ue=(Ut=t==null?void 0:t.launcher)==null?void 0:Ut.title)!=null?ue:"Chat Assistant";let Y=p("span","tvw-text-xs tvw-text-cw-muted");Y.textContent=(He=(pe=t==null?void 0:t.launcher)==null?void 0:pe.subtitle)!=null?He:"Here to help you get answers fast",D.append(M,Y),b?n.append(D):n.append(h,D);let O=(ge=r.clearChat)!=null?ge:{},J=(me=O.enabled)!=null?me:!0,I=null,x=null;if(J){let q=(fe=O.size)!=null?fe:"32px",ut=(we=O.iconName)!=null?we:"refresh-cw",St=(he=O.iconColor)!=null?he:"",jt=(ve=O.backgroundColor)!=null?ve:"",It=(ye=O.borderWidth)!=null?ye:"",ne=(be=O.borderColor)!=null?be:"",Ce=(xe=O.borderRadius)!=null?xe:"",oe=(s=O.paddingX)!=null?s:"",We=(E=O.paddingY)!=null?E:"",re=(a=O.tooltipText)!=null?a:"Clear chat",Ge=(L=O.showTooltip)!=null?L:!0;x=p("div","tvw-relative tvw-ml-auto tvw-clear-chat-button-wrapper"),I=p("button","tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none"),I.style.height=q,I.style.width=q,I.type="button",I.setAttribute("aria-label",re);let Ve=ft(ut,"20px",St||"",2);if(Ve&&I.appendChild(Ve),St&&(I.style.color=St,I.classList.remove("tvw-text-cw-muted")),jt&&(I.style.backgroundColor=jt,I.classList.remove("hover:tvw-bg-gray-100")),It||ne){let vt=It||"0px",se=ne||"transparent";I.style.border=`${vt} solid ${se}`,I.classList.remove("tvw-border-none")}if(Ce&&(I.style.borderRadius=Ce,I.classList.remove("tvw-rounded-full")),oe?(I.style.paddingLeft=oe,I.style.paddingRight=oe):(I.style.paddingLeft="",I.style.paddingRight=""),We?(I.style.paddingTop=We,I.style.paddingBottom=We):(I.style.paddingTop="",I.style.paddingBottom=""),x.appendChild(I),Ge&&re&&I&&x){let vt=null,se=()=>{if(vt||!I)return;vt=p("div","tvw-clear-chat-tooltip"),vt.textContent=re;let Ke=p("div");Ke.className="tvw-clear-chat-tooltip-arrow",vt.appendChild(Ke);let Re=I.getBoundingClientRect();vt.style.position="fixed",vt.style.left=`${Re.left+Re.width/2}px`,vt.style.top=`${Re.top-8}px`,vt.style.transform="translate(-50%, -100%)",document.body.appendChild(vt)},Te=()=>{vt&&vt.parentNode&&(vt.parentNode.removeChild(vt),vt=null)};x.addEventListener("mouseenter",se),x.addEventListener("mouseleave",Te),I.addEventListener("focus",se),I.addEventListener("blur",Te),x._cleanupTooltip=()=>{Te(),x&&(x.removeEventListener("mouseenter",se),x.removeEventListener("mouseleave",Te)),I&&(I.removeEventListener("focus",se),I.removeEventListener("blur",Te))}}n.appendChild(x)}let P=p("div",W==="top-right"?"tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50":J?"":"tvw-ml-auto"),f=p("button","tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none");f.style.height=i,f.style.width=i,f.type="button";let yt=(g=r.closeButtonTooltipText)!=null?g:"Close chat",F=(w=r.closeButtonShowTooltip)!=null?w:!0;f.setAttribute("aria-label",yt),f.style.display=o?"":"none";let T=(m=r.closeButtonIconName)!=null?m:"x",ot=(R=r.closeButtonIconText)!=null?R:"\xD7",ct=ft(T,"20px",r.closeButtonColor||"",2);if(ct?f.appendChild(ct):f.textContent=ot,r.closeButtonColor?(f.style.color=r.closeButtonColor,f.classList.remove("tvw-text-cw-muted")):(f.style.color="",f.classList.add("tvw-text-cw-muted")),r.closeButtonBackgroundColor?(f.style.backgroundColor=r.closeButtonBackgroundColor,f.classList.remove("hover:tvw-bg-gray-100")):(f.style.backgroundColor="",f.classList.add("hover:tvw-bg-gray-100")),r.closeButtonBorderWidth||r.closeButtonBorderColor){let q=r.closeButtonBorderWidth||"0px",ut=r.closeButtonBorderColor||"transparent";f.style.border=`${q} solid ${ut}`,f.classList.remove("tvw-border-none")}else f.style.border="",f.classList.add("tvw-border-none");if(r.closeButtonBorderRadius?(f.style.borderRadius=r.closeButtonBorderRadius,f.classList.remove("tvw-rounded-full")):(f.style.borderRadius="",f.classList.add("tvw-rounded-full")),r.closeButtonPaddingX?(f.style.paddingLeft=r.closeButtonPaddingX,f.style.paddingRight=r.closeButtonPaddingX):(f.style.paddingLeft="",f.style.paddingRight=""),r.closeButtonPaddingY?(f.style.paddingTop=r.closeButtonPaddingY,f.style.paddingBottom=r.closeButtonPaddingY):(f.style.paddingTop="",f.style.paddingBottom=""),P.appendChild(f),F&&yt){let q=null,ut=()=>{if(q)return;q=p("div","tvw-clear-chat-tooltip"),q.textContent=yt;let jt=p("div");jt.className="tvw-clear-chat-tooltip-arrow",q.appendChild(jt);let It=f.getBoundingClientRect();q.style.position="fixed",q.style.left=`${It.left+It.width/2}px`,q.style.top=`${It.top-8}px`,q.style.transform="translate(-50%, -100%)",document.body.appendChild(q)},St=()=>{q&&q.parentNode&&(q.parentNode.removeChild(q),q=null)};P.addEventListener("mouseenter",ut),P.addEventListener("mouseleave",St),f.addEventListener("focus",ut),f.addEventListener("blur",St),P._cleanupTooltip=()=>{St(),P.removeEventListener("mouseenter",ut),P.removeEventListener("mouseleave",St),f.removeEventListener("focus",ut),f.removeEventListener("blur",St)}}W==="top-right"?(e.style.position="relative",e.appendChild(P)):n.appendChild(P);let dt=p("div","tvw-flex tvw-flex-1 tvw-min-h-0 tvw-flex-col tvw-gap-6 tvw-overflow-y-auto tvw-bg-cw-container tvw-px-6 tvw-py-6");dt.id="vanilla-agent-scroll-container";let xt=p("div","tvw-rounded-2xl tvw-bg-cw-surface tvw-p-6 tvw-shadow-sm"),ht=p("h2","tvw-text-lg tvw-font-semibold tvw-text-cw-primary");ht.textContent=(c=(B=t==null?void 0:t.copy)==null?void 0:B.welcomeTitle)!=null?c:"Hello \u{1F44B}";let v=p("p","tvw-mt-2 tvw-text-sm tvw-text-cw-muted");v.textContent=(S=(y=t==null?void 0:t.copy)==null?void 0:y.welcomeSubtitle)!=null?S:"Ask anything about your account or products.",xt.append(ht,v);let z=p("div","tvw-flex tvw-flex-col tvw-gap-3");dt.append(xt,z);let C=p("div","tvw-border-t-cw-divider tvw-bg-cw-surface tvw-px-6 tvw-py-4"),bt=p("div","tvw-mb-3 tvw-flex tvw-flex-wrap tvw-gap-2"),Pt=((u=t==null?void 0:t.voiceRecognition)==null?void 0:u.enabled)===!0,Xt=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),Mt=p("form",`tvw-flex tvw-items-end ${Pt&&Xt?"tvw-gap-1":"tvw-gap-3"} tvw-rounded-2xl tvw-border tvw-border-gray-200 tvw-bg-cw-input-background tvw-px-4 tvw-py-3`);Mt.style.outline="none";let G=p("textarea");G.placeholder=(H=(d=t==null?void 0:t.copy)==null?void 0:d.inputPlaceholder)!=null?H:"Type your message\u2026",G.className="tvw-min-h-[48px] tvw-flex-1 tvw-resize-none tvw-border-none tvw-bg-transparent tvw-text-sm tvw-text-cw-primary focus:tvw-outline-none focus:tvw-border-none",G.rows=1;let Gt=(Z=(N=t==null?void 0:t.theme)==null?void 0:N.inputFontFamily)!=null?Z:"sans-serif",Ae=(lt=(nt=t==null?void 0:t.theme)==null?void 0:nt.inputFontWeight)!=null?lt:"400",Ot=q=>{switch(q){case"serif":return'Georgia, "Times New Roman", Times, serif';case"mono":return'"Courier New", Courier, "Lucida Console", Monaco, monospace';case"sans-serif":default:return'-apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif'}};G.style.fontFamily=Ot(Gt),G.style.fontWeight=Ae,G.style.border="none",G.style.outline="none",G.style.borderWidth="0",G.style.borderStyle="none",G.style.borderColor="transparent",G.addEventListener("focus",()=>{G.style.border="none",G.style.outline="none",G.style.borderWidth="0",G.style.borderStyle="none",G.style.borderColor="transparent",G.style.boxShadow="none"}),G.addEventListener("blur",()=>{G.style.border="none",G.style.outline="none"});let et=(at=t==null?void 0:t.sendButton)!=null?at:{},Zt=(Q=et.useIcon)!=null?Q:!1,Qt=(j=et.iconText)!=null?j:"\u2191",Ee=et.iconName,Le=(U=et.tooltipText)!=null?U:"Send message",Ie=(K=et.showTooltip)!=null?K:!1,qt=(Tt=et.size)!=null?Tt:"40px",_t=et.backgroundColor,gt=et.textColor,Yt=p("div","tvw-send-button-wrapper"),_=p("button",Zt?"tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer":"tvw-rounded-button tvw-bg-cw-accent tvw-px-4 tvw-py-2 tvw-text-sm tvw-font-semibold disabled:tvw-opacity-50 tvw-cursor-pointer");if(_.type="submit",Zt){if(_.style.width=qt,_.style.height=qt,_.style.minWidth=qt,_.style.minHeight=qt,_.style.fontSize="18px",_.style.lineHeight="1",_.innerHTML="",Ee){let q=parseFloat(qt)||24,ut=gt&&typeof gt=="string"&>.trim()?gt.trim():"currentColor",St=ft(Ee,q,ut,2);St?(_.appendChild(St),_.style.color=ut):(_.textContent=Qt,gt?_.style.color=gt:_.classList.add("tvw-text-white"))}else _.textContent=Qt,gt?_.style.color=gt:_.classList.add("tvw-text-white");_t?_.style.backgroundColor=_t:_.classList.add("tvw-bg-cw-primary")}else _.textContent=(Kt=(V=t==null?void 0:t.copy)==null?void 0:V.sendButtonLabel)!=null?Kt:"Send",gt?_.style.color=gt:_.classList.add("tvw-text-white");if(et.borderWidth&&(_.style.borderWidth=et.borderWidth,_.style.borderStyle="solid"),et.borderColor&&(_.style.borderColor=et.borderColor),et.paddingX?(_.style.paddingLeft=et.paddingX,_.style.paddingRight=et.paddingX):(_.style.paddingLeft="",_.style.paddingRight=""),et.paddingY?(_.style.paddingTop=et.paddingY,_.style.paddingBottom=et.paddingY):(_.style.paddingTop="",_.style.paddingBottom=""),Ie&&Le){let q=p("div","tvw-send-button-tooltip");q.textContent=Le,Yt.appendChild(q)}Yt.appendChild(_);let it=(De=t==null?void 0:t.voiceRecognition)!=null?De:{},te=it.enabled===!0,$=null,Wt=null,Me=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined");if(te&&Me){Wt=p("div","tvw-send-button-wrapper"),$=p("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer"),$.type="button",$.setAttribute("aria-label","Start voice recognition");let q=(qe=it.iconName)!=null?qe:"mic",ut=(ze=it.iconSize)!=null?ze:qt,St=parseFloat(ut)||24,jt=($e=it.backgroundColor)!=null?$e:_t,It=(Oe=it.iconColor)!=null?Oe:gt;$.style.width=ut,$.style.height=ut,$.style.minWidth=ut,$.style.minHeight=ut,$.style.fontSize="18px",$.style.lineHeight="1";let ne=It||"currentColor",Ce=ft(q,St,ne,1.5);Ce?($.appendChild(Ce),$.style.color=ne):($.textContent="\u{1F3A4}",$.style.color=ne),jt?$.style.backgroundColor=jt:$.classList.add("tvw-bg-cw-primary"),It?$.style.color=It:!It&&!gt&&$.classList.add("tvw-text-white"),it.borderWidth&&($.style.borderWidth=it.borderWidth,$.style.borderStyle="solid"),it.borderColor&&($.style.borderColor=it.borderColor),it.paddingX&&($.style.paddingLeft=it.paddingX,$.style.paddingRight=it.paddingX),it.paddingY&&($.style.paddingTop=it.paddingY,$.style.paddingBottom=it.paddingY),Wt.appendChild($);let oe=(_e=it.tooltipText)!=null?_e:"Start voice recognition";if(((Ue=it.showTooltip)!=null?Ue:!1)&&oe){let re=p("div","tvw-send-button-tooltip");re.textContent=oe,Wt.appendChild(re)}}Mt.addEventListener("click",q=>{q.target!==_&&q.target!==Yt&&q.target!==$&&q.target!==Wt&&G.focus()}),Mt.append(G),Wt&&Mt.append(Wt),Mt.append(Yt);let Vt=p("div","tvw-mt-2 tvw-text-right tvw-text-xs tvw-text-cw-muted"),le=(je=t==null?void 0:t.statusIndicator)!=null?je:{},Ct=(Xe=le.visible)!=null?Xe:!0;return Vt.style.display=Ct?"":"none",Vt.textContent=(Ye=le.idleText)!=null?Ye:"Online",C.append(bt,Mt,Vt),e.append(n,dt,C),{container:e,body:dt,messagesWrapper:z,suggestions:bt,textarea:G,sendButton:_,sendButtonWrapper:Yt,micButton:$,micButtonWrapper:Wt,composerForm:Mt,statusText:Vt,introTitle:ht,introSubtitle:v,closeButton:f,closeButtonWrapper:P,clearChatButton:I,clearChatButtonWrapper:x,iconHolder:h}};var un=()=>{let t=document.createElement("div");t.className="tvw-flex tvw-items-center tvw-space-x-1 tvw-h-5 tvw-mt-2";let o=document.createElement("div");o.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",o.style.animationDelay="0ms";let e=document.createElement("div");e.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",e.style.animationDelay="250ms";let n=document.createElement("div");n.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",n.style.animationDelay="500ms";let r=document.createElement("span");return r.className="tvw-sr-only",r.textContent="Loading",t.appendChild(o),t.appendChild(e),t.appendChild(n),t.appendChild(r),t},pn=(t,o)=>{let e=["tvw-max-w-[85%]","tvw-rounded-2xl","tvw-text-sm","tvw-leading-relaxed","tvw-shadow-sm"];t.role==="user"?e.push("tvw-ml-auto","tvw-bg-cw-accent","tvw-text-white","tvw-px-5","tvw-py-3"):e.push("tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-px-5","tvw-py-3");let n=p("div",e.join(" ")),r=document.createElement("div");if(r.innerHTML=o({text:t.content,message:t,streaming:!!t.streaming}),n.appendChild(r),t.streaming&&t.role==="assistant"&&(!t.content||!t.content.trim())){let l=un();n.appendChild(l)}return n};var gn=new Set,mn=t=>{let o=t.reasoning,e=p("div",["tvw-w-full","tvw-max-w-[85%]","tvw-rounded-2xl","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-shadow-sm","tvw-overflow-hidden","tvw-px-0","tvw-py-0"].join(" "));if(!o)return e;let n=gn.has(t.id),r=p("button","tvw-flex tvw-w-full tvw-items-center tvw-justify-between tvw-gap-3 tvw-bg-transparent tvw-px-4 tvw-py-3 tvw-text-left tvw-cursor-pointer tvw-border-none");r.type="button",r.setAttribute("aria-expanded",n?"true":"false");let l=p("div","tvw-flex tvw-flex-col tvw-text-left"),i=p("span","tvw-text-xs tvw-text-cw-primary");i.textContent="Thinking...",l.appendChild(i);let W=p("span","tvw-text-xs tvw-text-cw-primary");W.textContent=Yn(o),l.appendChild(W),o.status==="complete"?i.style.display="none":i.style.display="";let b=p("div","tvw-flex tvw-items-center"),h=ft(n?"chevron-up":"chevron-down",16,"currentColor",2);h?b.appendChild(h):b.textContent=n?"Hide":"Show";let D=p("div","tvw-flex tvw-items-center tvw-ml-auto");D.append(b),r.append(l,D);let M=p("div","tvw-border-t tvw-border-gray-200 tvw-bg-gray-50 tvw-px-4 tvw-py-3");M.style.display=n?"":"none";let Y=o.chunks.join(""),O=p("div","tvw-whitespace-pre-wrap tvw-text-xs tvw-leading-snug tvw-text-cw-muted");O.textContent=Y||(o.status==="complete"?"No additional context was shared.":"Waiting for details\u2026"),M.appendChild(O);let J=()=>{r.setAttribute("aria-expanded",n?"true":"false"),b.innerHTML="";let P=ft(n?"chevron-up":"chevron-down",16,"currentColor",2);P?b.appendChild(P):b.textContent=n?"Hide":"Show",M.style.display=n?"":"none"},I=()=>{n=!n,n?gn.add(t.id):gn.delete(t.id),J()};return r.addEventListener("pointerdown",x=>{x.preventDefault(),I()}),r.addEventListener("keydown",x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),I())}),J(),e.append(r,M),e};var fn=new Set,wn=(t,o)=>{var I;let e=t.toolCall,n=(I=o==null?void 0:o.toolCall)!=null?I:{},r=p("div",["tvw-w-full","tvw-max-w-[85%]","tvw-rounded-2xl","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-shadow-sm","tvw-overflow-hidden","tvw-px-0","tvw-py-0"].join(" "));if(n.backgroundColor&&(r.style.backgroundColor=n.backgroundColor),n.borderColor&&(r.style.borderColor=n.borderColor),n.borderWidth&&(r.style.borderWidth=n.borderWidth),n.borderRadius&&(r.style.borderRadius=n.borderRadius),!e)return r;let l=fn.has(t.id),i=p("button","tvw-flex tvw-w-full tvw-items-center tvw-justify-between tvw-gap-3 tvw-bg-transparent tvw-px-4 tvw-py-3 tvw-text-left tvw-cursor-pointer tvw-border-none");i.type="button",i.setAttribute("aria-expanded",l?"true":"false"),n.headerBackgroundColor&&(i.style.backgroundColor=n.headerBackgroundColor),n.headerPaddingX&&(i.style.paddingLeft=n.headerPaddingX,i.style.paddingRight=n.headerPaddingX),n.headerPaddingY&&(i.style.paddingTop=n.headerPaddingY,i.style.paddingBottom=n.headerPaddingY);let W=p("div","tvw-flex tvw-flex-col tvw-text-left"),b=p("span","tvw-text-xs tvw-text-cw-primary");n.headerTextColor&&(b.style.color=n.headerTextColor),b.textContent=Vn(e),W.appendChild(b);let k=p("div","tvw-flex tvw-items-center"),h=n.toggleTextColor||n.headerTextColor||"currentColor",D=ft(l?"chevron-up":"chevron-down",16,h,2);D?k.appendChild(D):k.textContent=l?"Hide":"Show";let M=p("div","tvw-flex tvw-items-center tvw-gap-2 tvw-ml-auto");M.append(k),i.append(W,M);let Y=p("div","tvw-border-t tvw-border-gray-200 tvw-bg-gray-50 tvw-space-y-3 tvw-px-4 tvw-py-3");if(Y.style.display=l?"":"none",n.contentBackgroundColor&&(Y.style.backgroundColor=n.contentBackgroundColor),n.contentTextColor&&(Y.style.color=n.contentTextColor),n.contentPaddingX&&(Y.style.paddingLeft=n.contentPaddingX,Y.style.paddingRight=n.contentPaddingX),n.contentPaddingY&&(Y.style.paddingTop=n.contentPaddingY,Y.style.paddingBottom=n.contentPaddingY),e.name){let x=p("div","tvw-text-xs tvw-text-cw-muted tvw-italic");n.contentTextColor?x.style.color=n.contentTextColor:n.headerTextColor&&(x.style.color=n.headerTextColor),x.textContent=e.name,Y.appendChild(x)}if(e.args!==void 0){let x=p("div","tvw-space-y-1"),P=p("div","tvw-text-xs tvw-text-cw-muted");n.labelTextColor&&(P.style.color=n.labelTextColor),P.textContent="Arguments";let f=p("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-text-xs tvw-text-cw-primary");f.style.fontSize="0.75rem",f.style.lineHeight="1rem",n.codeBlockBackgroundColor&&(f.style.backgroundColor=n.codeBlockBackgroundColor),n.codeBlockBorderColor&&(f.style.borderColor=n.codeBlockBorderColor),n.codeBlockTextColor&&(f.style.color=n.codeBlockTextColor),f.textContent=an(e.args),x.append(P,f),Y.appendChild(x)}if(e.chunks&&e.chunks.length){let x=p("div","tvw-space-y-1"),P=p("div","tvw-text-xs tvw-text-cw-muted");n.labelTextColor&&(P.style.color=n.labelTextColor),P.textContent="Activity";let f=p("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-text-xs tvw-text-cw-primary");f.style.fontSize="0.75rem",f.style.lineHeight="1rem",n.codeBlockBackgroundColor&&(f.style.backgroundColor=n.codeBlockBackgroundColor),n.codeBlockBorderColor&&(f.style.borderColor=n.codeBlockBorderColor),n.codeBlockTextColor&&(f.style.color=n.codeBlockTextColor),f.textContent=e.chunks.join(`
|
|
14
|
+
`,e.addEventListener("click",o);let n=l=>{var J,I,x,P,f,yt,F,T,ot,ct;let i=(J=l.launcher)!=null?J:{},W=e.querySelector("[data-role='launcher-title']");W&&(W.textContent=(I=i.title)!=null?I:"Chat Assistant");let b=e.querySelector("[data-role='launcher-subtitle']");b&&(b.textContent=(x=i.subtitle)!=null?x:"Get answers fast");let k=e.querySelector(".tvw-flex-col");k&&(i.textHidden?k.style.display="none":k.style.display="");let h=e.querySelector("[data-role='launcher-icon']");if(h)if(i.agentIconHidden)h.style.display="none";else{let dt=(P=i.agentIconSize)!=null?P:"40px";if(h.style.height=dt,h.style.width=dt,h.innerHTML="",i.agentIconName){let xt=parseFloat(dt)||24,ht=ft(i.agentIconName,xt*.6,"#ffffff",2);ht?(h.appendChild(ht),h.style.display=""):(h.textContent=(f=i.agentIconText)!=null?f:"\u{1F4AC}",h.style.display="")}else i.iconUrl?h.style.display="none":(h.textContent=(yt=i.agentIconText)!=null?yt:"\u{1F4AC}",h.style.display="")}let D=e.querySelector("[data-role='launcher-image']");if(D){let dt=(F=i.agentIconSize)!=null?F:"40px";D.style.height=dt,D.style.width=dt,i.iconUrl&&!i.agentIconName&&!i.agentIconHidden?(D.src=i.iconUrl,D.style.display="block"):D.style.display="none"}let M=e.querySelector("[data-role='launcher-call-to-action-icon']");if(M){let dt=(T=i.callToActionIconSize)!=null?T:"32px";M.style.height=dt,M.style.width=dt,i.callToActionIconBackgroundColor?(M.style.backgroundColor=i.callToActionIconBackgroundColor,M.classList.remove("tvw-bg-cw-primary")):(M.style.backgroundColor="",M.classList.add("tvw-bg-cw-primary"));let xt=0;if(i.callToActionIconPadding?(M.style.boxSizing="border-box",M.style.padding=i.callToActionIconPadding,xt=(parseFloat(i.callToActionIconPadding)||0)*2):(M.style.boxSizing="",M.style.padding=""),i.callToActionIconHidden)M.style.display="none";else if(M.style.display="",M.innerHTML="",i.callToActionIconName){let ht=parseFloat(dt)||24,v=Math.max(ht-xt,8),z=ft(i.callToActionIconName,v,"currentColor",2);z?M.appendChild(z):M.textContent=(ot=i.callToActionIconText)!=null?ot:"\u2197"}else M.textContent=(ct=i.callToActionIconText)!=null?ct:"\u2197"}let Y=i.position&&Se[i.position]?Se[i.position]:Se["bottom-right"],O="tvw-fixed tvw-flex tvw-items-center tvw-gap-3 tvw-rounded-launcher tvw-bg-cw-surface tvw-py-2.5 tvw-pl-3 tvw-pr-3 tvw-shadow-lg tvw-border tvw-border-gray-200 tvw-transition hover:tvw-translate-y-[-2px] tvw-cursor-pointer tvw-z-50";e.className=`${O} ${Y}`},r=()=>{e.removeEventListener("click",o),e.remove()};return t&&n(t),{element:e,update:n,destroy:r}};var Zn=t=>{var b,k,h,D,M;if(!((k=(b=t==null?void 0:t.launcher)==null?void 0:b.enabled)!=null?k:!0)){let Y=p("div","tvw-relative tvw-w-full tvw-h-full"),O=p("div","tvw-relative tvw-w-full tvw-h-full tvw-min-h-[360px]");return Y.appendChild(O),{wrapper:Y,panel:O}}let e=(h=t==null?void 0:t.launcher)!=null?h:{},n=e.position&&Se[e.position]?Se[e.position]:Se["bottom-right"],r=p("div",`tvw-fixed ${n} tvw-z-50 tvw-transition`),l=p("div","tvw-relative tvw-min-h-[320px]"),i=(M=(D=t==null?void 0:t.launcher)==null?void 0:D.width)!=null?M:t==null?void 0:t.launcherWidth,W=i!=null?i:"min(400px, calc(100vw - 24px))";return l.style.width=W,l.style.maxWidth=W,r.appendChild(l),{wrapper:r,panel:l}},Qn=(t,o=!0)=>{var Et,zt,Nt,ae,ce,kt,Be,ee,de,rt,Ut,ue,pe,He,ge,me,fe,we,he,ve,ye,be,xe,s,E,a,L,g,w,m,R,B,c,y,S,u,d,H,N,Z,nt,lt,at,Q,j,U,K,Tt,V,Kt,De,qe,ze,$e,Oe,_e,Ue,je,Xe,Ye;let e=p("div","tvw-flex tvw-h-full tvw-w-full tvw-flex-col tvw-bg-cw-surface tvw-text-cw-primary tvw-rounded-2xl tvw-overflow-hidden tvw-shadow-2xl tvw-border tvw-border-cw-border"),n=p("div","tvw-flex tvw-items-center tvw-gap-3 tvw-bg-cw-surface tvw-px-6 tvw-py-5 tvw-border-b-cw-divider"),r=(Et=t==null?void 0:t.launcher)!=null?Et:{},l=(zt=r.headerIconSize)!=null?zt:"48px",i=(Nt=r.closeButtonSize)!=null?Nt:"32px",W=(ae=r.closeButtonPlacement)!=null?ae:"inline",b=(ce=r.headerIconHidden)!=null?ce:!1,k=r.headerIconName,h=p("div","tvw-flex tvw-items-center tvw-justify-center tvw-rounded-xl tvw-bg-cw-primary tvw-text-white tvw-text-xl");if(h.style.height=l,h.style.width=l,!b)if(k){let q=parseFloat(l)||24,ut=ft(k,q*.6,"#ffffff",2);ut?h.replaceChildren(ut):h.textContent=(Be=(kt=t==null?void 0:t.launcher)==null?void 0:kt.agentIconText)!=null?Be:"\u{1F4AC}"}else if((ee=t==null?void 0:t.launcher)!=null&&ee.iconUrl){let q=p("img");q.src=t.launcher.iconUrl,q.alt="",q.className="tvw-rounded-xl tvw-object-cover",q.style.height=l,q.style.width=l,h.replaceChildren(q)}else h.textContent=(rt=(de=t==null?void 0:t.launcher)==null?void 0:de.agentIconText)!=null?rt:"\u{1F4AC}";let D=p("div","tvw-flex tvw-flex-col"),M=p("span","tvw-text-base tvw-font-semibold");M.textContent=(ue=(Ut=t==null?void 0:t.launcher)==null?void 0:Ut.title)!=null?ue:"Chat Assistant";let Y=p("span","tvw-text-xs tvw-text-cw-muted");Y.textContent=(He=(pe=t==null?void 0:t.launcher)==null?void 0:pe.subtitle)!=null?He:"Here to help you get answers fast",D.append(M,Y),b?n.append(D):n.append(h,D);let O=(ge=r.clearChat)!=null?ge:{},J=(me=O.enabled)!=null?me:!0,I=null,x=null;if(J){let q=(fe=O.size)!=null?fe:"32px",ut=(we=O.iconName)!=null?we:"refresh-cw",St=(he=O.iconColor)!=null?he:"",jt=(ve=O.backgroundColor)!=null?ve:"",It=(ye=O.borderWidth)!=null?ye:"",ne=(be=O.borderColor)!=null?be:"",Ce=(xe=O.borderRadius)!=null?xe:"",oe=(s=O.paddingX)!=null?s:"",We=(E=O.paddingY)!=null?E:"",re=(a=O.tooltipText)!=null?a:"Clear chat",Ge=(L=O.showTooltip)!=null?L:!0;x=p("div","tvw-relative tvw-ml-auto tvw-clear-chat-button-wrapper"),I=p("button","tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none"),I.style.height=q,I.style.width=q,I.type="button",I.setAttribute("aria-label",re);let Ve=ft(ut,"20px",St||"",2);if(Ve&&I.appendChild(Ve),St&&(I.style.color=St,I.classList.remove("tvw-text-cw-muted")),jt&&(I.style.backgroundColor=jt,I.classList.remove("hover:tvw-bg-gray-100")),It||ne){let vt=It||"0px",se=ne||"transparent";I.style.border=`${vt} solid ${se}`,I.classList.remove("tvw-border-none")}if(Ce&&(I.style.borderRadius=Ce,I.classList.remove("tvw-rounded-full")),oe?(I.style.paddingLeft=oe,I.style.paddingRight=oe):(I.style.paddingLeft="",I.style.paddingRight=""),We?(I.style.paddingTop=We,I.style.paddingBottom=We):(I.style.paddingTop="",I.style.paddingBottom=""),x.appendChild(I),Ge&&re&&I&&x){let vt=null,se=()=>{if(vt||!I)return;vt=p("div","tvw-clear-chat-tooltip"),vt.textContent=re;let Ke=p("div");Ke.className="tvw-clear-chat-tooltip-arrow",vt.appendChild(Ke);let Re=I.getBoundingClientRect();vt.style.position="fixed",vt.style.left=`${Re.left+Re.width/2}px`,vt.style.top=`${Re.top-8}px`,vt.style.transform="translate(-50%, -100%)",document.body.appendChild(vt)},Te=()=>{vt&&vt.parentNode&&(vt.parentNode.removeChild(vt),vt=null)};x.addEventListener("mouseenter",se),x.addEventListener("mouseleave",Te),I.addEventListener("focus",se),I.addEventListener("blur",Te),x._cleanupTooltip=()=>{Te(),x&&(x.removeEventListener("mouseenter",se),x.removeEventListener("mouseleave",Te)),I&&(I.removeEventListener("focus",se),I.removeEventListener("blur",Te))}}n.appendChild(x)}let P=p("div",W==="top-right"?"tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50":J?"":"tvw-ml-auto"),f=p("button","tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none");f.style.height=i,f.style.width=i,f.type="button";let yt=(g=r.closeButtonTooltipText)!=null?g:"Close chat",F=(w=r.closeButtonShowTooltip)!=null?w:!0;f.setAttribute("aria-label",yt),f.style.display=o?"":"none";let T=(m=r.closeButtonIconName)!=null?m:"x",ot=(R=r.closeButtonIconText)!=null?R:"\xD7",ct=ft(T,"20px",r.closeButtonColor||"",2);if(ct?f.appendChild(ct):f.textContent=ot,r.closeButtonColor?(f.style.color=r.closeButtonColor,f.classList.remove("tvw-text-cw-muted")):(f.style.color="",f.classList.add("tvw-text-cw-muted")),r.closeButtonBackgroundColor?(f.style.backgroundColor=r.closeButtonBackgroundColor,f.classList.remove("hover:tvw-bg-gray-100")):(f.style.backgroundColor="",f.classList.add("hover:tvw-bg-gray-100")),r.closeButtonBorderWidth||r.closeButtonBorderColor){let q=r.closeButtonBorderWidth||"0px",ut=r.closeButtonBorderColor||"transparent";f.style.border=`${q} solid ${ut}`,f.classList.remove("tvw-border-none")}else f.style.border="",f.classList.add("tvw-border-none");if(r.closeButtonBorderRadius?(f.style.borderRadius=r.closeButtonBorderRadius,f.classList.remove("tvw-rounded-full")):(f.style.borderRadius="",f.classList.add("tvw-rounded-full")),r.closeButtonPaddingX?(f.style.paddingLeft=r.closeButtonPaddingX,f.style.paddingRight=r.closeButtonPaddingX):(f.style.paddingLeft="",f.style.paddingRight=""),r.closeButtonPaddingY?(f.style.paddingTop=r.closeButtonPaddingY,f.style.paddingBottom=r.closeButtonPaddingY):(f.style.paddingTop="",f.style.paddingBottom=""),P.appendChild(f),F&&yt){let q=null,ut=()=>{if(q)return;q=p("div","tvw-clear-chat-tooltip"),q.textContent=yt;let jt=p("div");jt.className="tvw-clear-chat-tooltip-arrow",q.appendChild(jt);let It=f.getBoundingClientRect();q.style.position="fixed",q.style.left=`${It.left+It.width/2}px`,q.style.top=`${It.top-8}px`,q.style.transform="translate(-50%, -100%)",document.body.appendChild(q)},St=()=>{q&&q.parentNode&&(q.parentNode.removeChild(q),q=null)};P.addEventListener("mouseenter",ut),P.addEventListener("mouseleave",St),f.addEventListener("focus",ut),f.addEventListener("blur",St),P._cleanupTooltip=()=>{St(),P.removeEventListener("mouseenter",ut),P.removeEventListener("mouseleave",St),f.removeEventListener("focus",ut),f.removeEventListener("blur",St)}}W==="top-right"?(e.style.position="relative",e.appendChild(P)):n.appendChild(P);let dt=p("div","tvw-flex tvw-flex-1 tvw-min-h-0 tvw-flex-col tvw-gap-6 tvw-overflow-y-auto tvw-bg-cw-container tvw-px-6 tvw-py-6");dt.id="vanilla-agent-scroll-container";let xt=p("div","tvw-rounded-2xl tvw-bg-cw-surface tvw-p-6 tvw-shadow-sm"),ht=p("h2","tvw-text-lg tvw-font-semibold tvw-text-cw-primary");ht.textContent=(c=(B=t==null?void 0:t.copy)==null?void 0:B.welcomeTitle)!=null?c:"Hello \u{1F44B}";let v=p("p","tvw-mt-2 tvw-text-sm tvw-text-cw-muted");v.textContent=(S=(y=t==null?void 0:t.copy)==null?void 0:y.welcomeSubtitle)!=null?S:"Ask anything about your account or products.",xt.append(ht,v);let z=p("div","tvw-flex tvw-flex-col tvw-gap-3");dt.append(xt,z);let C=p("div","tvw-border-t-cw-divider tvw-bg-cw-surface tvw-px-6 tvw-py-4"),bt=p("div","tvw-mb-3 tvw-flex tvw-flex-wrap tvw-gap-2"),Pt=((u=t==null?void 0:t.voiceRecognition)==null?void 0:u.enabled)===!0,Xt=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),Mt=p("form",`tvw-flex tvw-items-end ${Pt&&Xt?"tvw-gap-1":"tvw-gap-3"} tvw-rounded-2xl tvw-border tvw-border-gray-200 tvw-bg-cw-input-background tvw-px-4 tvw-py-3`);Mt.style.outline="none";let G=p("textarea");G.placeholder=(H=(d=t==null?void 0:t.copy)==null?void 0:d.inputPlaceholder)!=null?H:"Type your message\u2026",G.className="tvw-min-h-[48px] tvw-flex-1 tvw-resize-none tvw-border-none tvw-bg-transparent tvw-text-sm tvw-text-cw-primary focus:tvw-outline-none focus:tvw-border-none",G.rows=1;let Gt=(Z=(N=t==null?void 0:t.theme)==null?void 0:N.inputFontFamily)!=null?Z:"sans-serif",Ae=(lt=(nt=t==null?void 0:t.theme)==null?void 0:nt.inputFontWeight)!=null?lt:"400",Ot=q=>{switch(q){case"serif":return'Georgia, "Times New Roman", Times, serif';case"mono":return'"Courier New", Courier, "Lucida Console", Monaco, monospace';case"sans-serif":default:return'-apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif'}};G.style.fontFamily=Ot(Gt),G.style.fontWeight=Ae,G.style.border="none",G.style.outline="none",G.style.borderWidth="0",G.style.borderStyle="none",G.style.borderColor="transparent",G.addEventListener("focus",()=>{G.style.border="none",G.style.outline="none",G.style.borderWidth="0",G.style.borderStyle="none",G.style.borderColor="transparent",G.style.boxShadow="none"}),G.addEventListener("blur",()=>{G.style.border="none",G.style.outline="none"});let et=(at=t==null?void 0:t.sendButton)!=null?at:{},Zt=(Q=et.useIcon)!=null?Q:!1,Qt=(j=et.iconText)!=null?j:"\u2191",Ee=et.iconName,Le=(U=et.tooltipText)!=null?U:"Send message",Ie=(K=et.showTooltip)!=null?K:!1,qt=(Tt=et.size)!=null?Tt:"40px",_t=et.backgroundColor,gt=et.textColor,Yt=p("div","tvw-send-button-wrapper"),_=p("button",Zt?"tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer":"tvw-rounded-button tvw-bg-cw-accent tvw-px-4 tvw-py-2 tvw-text-sm tvw-font-semibold disabled:tvw-opacity-50 tvw-cursor-pointer");if(_.type="submit",Zt){if(_.style.width=qt,_.style.height=qt,_.style.minWidth=qt,_.style.minHeight=qt,_.style.fontSize="18px",_.style.lineHeight="1",_.innerHTML="",Ee){let q=parseFloat(qt)||24,ut=gt&&typeof gt=="string"&>.trim()?gt.trim():"currentColor",St=ft(Ee,q,ut,2);St?(_.appendChild(St),_.style.color=ut):(_.textContent=Qt,gt?_.style.color=gt:_.classList.add("tvw-text-white"))}else _.textContent=Qt,gt?_.style.color=gt:_.classList.add("tvw-text-white");_t?_.style.backgroundColor=_t:_.classList.add("tvw-bg-cw-primary")}else _.textContent=(Kt=(V=t==null?void 0:t.copy)==null?void 0:V.sendButtonLabel)!=null?Kt:"Send",gt?_.style.color=gt:_.classList.add("tvw-text-white");if(et.borderWidth&&(_.style.borderWidth=et.borderWidth,_.style.borderStyle="solid"),et.borderColor&&(_.style.borderColor=et.borderColor),et.paddingX?(_.style.paddingLeft=et.paddingX,_.style.paddingRight=et.paddingX):(_.style.paddingLeft="",_.style.paddingRight=""),et.paddingY?(_.style.paddingTop=et.paddingY,_.style.paddingBottom=et.paddingY):(_.style.paddingTop="",_.style.paddingBottom=""),Ie&&Le){let q=p("div","tvw-send-button-tooltip");q.textContent=Le,Yt.appendChild(q)}Yt.appendChild(_);let it=(De=t==null?void 0:t.voiceRecognition)!=null?De:{},te=it.enabled===!0,$=null,Wt=null,Me=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined");if(te&&Me){Wt=p("div","tvw-send-button-wrapper"),$=p("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer"),$.type="button",$.setAttribute("aria-label","Start voice recognition");let q=(qe=it.iconName)!=null?qe:"mic",ut=(ze=it.iconSize)!=null?ze:qt,St=parseFloat(ut)||24,jt=($e=it.backgroundColor)!=null?$e:_t,It=(Oe=it.iconColor)!=null?Oe:gt;$.style.width=ut,$.style.height=ut,$.style.minWidth=ut,$.style.minHeight=ut,$.style.fontSize="18px",$.style.lineHeight="1";let ne=It||"currentColor",Ce=ft(q,St,ne,1.5);Ce?($.appendChild(Ce),$.style.color=ne):($.textContent="\u{1F3A4}",$.style.color=ne),jt?$.style.backgroundColor=jt:$.classList.add("tvw-bg-cw-primary"),It?$.style.color=It:!It&&!gt&&$.classList.add("tvw-text-white"),it.borderWidth&&($.style.borderWidth=it.borderWidth,$.style.borderStyle="solid"),it.borderColor&&($.style.borderColor=it.borderColor),it.paddingX&&($.style.paddingLeft=it.paddingX,$.style.paddingRight=it.paddingX),it.paddingY&&($.style.paddingTop=it.paddingY,$.style.paddingBottom=it.paddingY),Wt.appendChild($);let oe=(_e=it.tooltipText)!=null?_e:"Start voice recognition";if(((Ue=it.showTooltip)!=null?Ue:!1)&&oe){let re=p("div","tvw-send-button-tooltip");re.textContent=oe,Wt.appendChild(re)}}Mt.addEventListener("click",q=>{q.target!==_&&q.target!==Yt&&q.target!==$&&q.target!==Wt&&G.focus()}),Mt.append(G),Wt&&Mt.append(Wt),Mt.append(Yt);let Vt=p("div","tvw-mt-2 tvw-text-right tvw-text-xs tvw-text-cw-muted"),le=(je=t==null?void 0:t.statusIndicator)!=null?je:{},Ct=(Xe=le.visible)!=null?Xe:!0;return Vt.style.display=Ct?"":"none",Vt.textContent=(Ye=le.idleText)!=null?Ye:"Online",C.append(bt,Mt,Vt),e.append(n,dt,C),{container:e,body:dt,messagesWrapper:z,suggestions:bt,textarea:G,sendButton:_,sendButtonWrapper:Yt,micButton:$,micButtonWrapper:Wt,composerForm:Mt,statusText:Vt,introTitle:ht,introSubtitle:v,closeButton:f,closeButtonWrapper:P,clearChatButton:I,clearChatButtonWrapper:x,iconHolder:h}};var un=()=>{let t=document.createElement("div");t.className="tvw-flex tvw-items-center tvw-space-x-1 tvw-h-5 tvw-mt-2";let o=document.createElement("div");o.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",o.style.animationDelay="0ms";let e=document.createElement("div");e.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",e.style.animationDelay="250ms";let n=document.createElement("div");n.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",n.style.animationDelay="500ms";let r=document.createElement("span");return r.className="tvw-sr-only",r.textContent="Loading",t.appendChild(o),t.appendChild(e),t.appendChild(n),t.appendChild(r),t},pn=(t,o)=>{let e=["tvw-max-w-[85%]","tvw-rounded-2xl","tvw-text-sm","tvw-leading-relaxed","tvw-shadow-sm"];t.role==="user"?e.push("tvw-ml-auto","tvw-bg-cw-accent","tvw-text-white","tvw-px-5","tvw-py-3"):e.push("tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-px-5","tvw-py-3");let n=p("div",e.join(" ")),r=document.createElement("div");if(r.innerHTML=o({text:t.content,message:t,streaming:!!t.streaming}),n.appendChild(r),t.streaming&&t.role==="assistant"&&(!t.content||!t.content.trim())){let l=un();n.appendChild(l)}return n};var gn=new Set,mn=t=>{let o=t.reasoning,e=p("div",["tvw-w-full","tvw-max-w-[85%]","tvw-rounded-2xl","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-shadow-sm","tvw-overflow-hidden","tvw-px-0","tvw-py-0"].join(" "));if(!o)return e;let n=gn.has(t.id),r=p("button","tvw-flex tvw-w-full tvw-items-center tvw-justify-between tvw-gap-3 tvw-bg-transparent tvw-px-4 tvw-py-3 tvw-text-left tvw-cursor-pointer tvw-border-none");r.type="button",r.setAttribute("aria-expanded",n?"true":"false");let l=p("div","tvw-flex tvw-flex-col tvw-text-left"),i=p("span","tvw-text-xs tvw-text-cw-primary");i.textContent="Thinking...",l.appendChild(i);let W=p("span","tvw-text-xs tvw-text-cw-primary");W.textContent=Yn(o),l.appendChild(W),o.status==="complete"?i.style.display="none":i.style.display="";let b=p("div","tvw-flex tvw-items-center"),h=ft(n?"chevron-up":"chevron-down",16,"currentColor",2);h?b.appendChild(h):b.textContent=n?"Hide":"Show";let D=p("div","tvw-flex tvw-items-center tvw-ml-auto");D.append(b),r.append(l,D);let M=p("div","tvw-border-t tvw-border-gray-200 tvw-bg-gray-50 tvw-px-4 tvw-py-3");M.style.display=n?"":"none";let Y=o.chunks.join(""),O=p("div","tvw-whitespace-pre-wrap tvw-text-xs tvw-leading-snug tvw-text-cw-muted");O.textContent=Y||(o.status==="complete"?"No additional context was shared.":"Waiting for details\u2026"),M.appendChild(O);let J=()=>{r.setAttribute("aria-expanded",n?"true":"false"),b.innerHTML="";let P=ft(n?"chevron-up":"chevron-down",16,"currentColor",2);P?b.appendChild(P):b.textContent=n?"Hide":"Show",M.style.display=n?"":"none"},I=()=>{n=!n,n?gn.add(t.id):gn.delete(t.id),J()};return r.addEventListener("pointerdown",x=>{x.preventDefault(),I()}),r.addEventListener("keydown",x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),I())}),J(),e.append(r,M),e};var fn=new Set,wn=(t,o)=>{var I;let e=t.toolCall,n=(I=o==null?void 0:o.toolCall)!=null?I:{},r=p("div",["tvw-w-full","tvw-max-w-[85%]","tvw-rounded-2xl","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-shadow-sm","tvw-overflow-hidden","tvw-px-0","tvw-py-0"].join(" "));if(n.backgroundColor&&(r.style.backgroundColor=n.backgroundColor),n.borderColor&&(r.style.borderColor=n.borderColor),n.borderWidth&&(r.style.borderWidth=n.borderWidth),n.borderRadius&&(r.style.borderRadius=n.borderRadius),!e)return r;let l=fn.has(t.id),i=p("button","tvw-flex tvw-w-full tvw-items-center tvw-justify-between tvw-gap-3 tvw-bg-transparent tvw-px-4 tvw-py-3 tvw-text-left tvw-cursor-pointer tvw-border-none");i.type="button",i.setAttribute("aria-expanded",l?"true":"false"),n.headerBackgroundColor&&(i.style.backgroundColor=n.headerBackgroundColor),n.headerPaddingX&&(i.style.paddingLeft=n.headerPaddingX,i.style.paddingRight=n.headerPaddingX),n.headerPaddingY&&(i.style.paddingTop=n.headerPaddingY,i.style.paddingBottom=n.headerPaddingY);let W=p("div","tvw-flex tvw-flex-col tvw-text-left"),b=p("span","tvw-text-xs tvw-text-cw-primary");n.headerTextColor&&(b.style.color=n.headerTextColor),b.textContent=Vn(e),W.appendChild(b);let k=p("div","tvw-flex tvw-items-center"),h=n.toggleTextColor||n.headerTextColor||"currentColor",D=ft(l?"chevron-up":"chevron-down",16,h,2);D?k.appendChild(D):k.textContent=l?"Hide":"Show";let M=p("div","tvw-flex tvw-items-center tvw-gap-2 tvw-ml-auto");M.append(k),i.append(W,M);let Y=p("div","tvw-border-t tvw-border-gray-200 tvw-bg-gray-50 tvw-space-y-3 tvw-px-4 tvw-py-3");if(Y.style.display=l?"":"none",n.contentBackgroundColor&&(Y.style.backgroundColor=n.contentBackgroundColor),n.contentTextColor&&(Y.style.color=n.contentTextColor),n.contentPaddingX&&(Y.style.paddingLeft=n.contentPaddingX,Y.style.paddingRight=n.contentPaddingX),n.contentPaddingY&&(Y.style.paddingTop=n.contentPaddingY,Y.style.paddingBottom=n.contentPaddingY),e.name){let x=p("div","tvw-text-xs tvw-text-cw-muted tvw-italic");n.contentTextColor?x.style.color=n.contentTextColor:n.headerTextColor&&(x.style.color=n.headerTextColor),x.textContent=e.name,Y.appendChild(x)}if(e.args!==void 0){let x=p("div","tvw-space-y-1"),P=p("div","tvw-text-xs tvw-text-cw-muted");n.labelTextColor&&(P.style.color=n.labelTextColor),P.textContent="Arguments";let f=p("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-text-xs tvw-text-cw-primary");f.style.fontSize="0.75rem",f.style.lineHeight="1rem",n.codeBlockBackgroundColor&&(f.style.backgroundColor=n.codeBlockBackgroundColor),n.codeBlockBorderColor&&(f.style.borderColor=n.codeBlockBorderColor),n.codeBlockTextColor&&(f.style.color=n.codeBlockTextColor),f.textContent=an(e.args),x.append(P,f),Y.appendChild(x)}if(e.chunks&&e.chunks.length){let x=p("div","tvw-space-y-1"),P=p("div","tvw-text-xs tvw-text-cw-muted");n.labelTextColor&&(P.style.color=n.labelTextColor),P.textContent="Activity";let f=p("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-text-xs tvw-text-cw-primary");f.style.fontSize="0.75rem",f.style.lineHeight="1rem",n.codeBlockBackgroundColor&&(f.style.backgroundColor=n.codeBlockBackgroundColor),n.codeBlockBorderColor&&(f.style.borderColor=n.codeBlockBorderColor),n.codeBlockTextColor&&(f.style.color=n.codeBlockTextColor),f.textContent=e.chunks.join(`
|
|
15
15
|
`),x.append(P,f),Y.appendChild(x)}if(e.status==="complete"&&e.result!==void 0){let x=p("div","tvw-space-y-1"),P=p("div","tvw-text-xs tvw-text-cw-muted");n.labelTextColor&&(P.style.color=n.labelTextColor),P.textContent="Result";let f=p("pre","tvw-max-h-48 tvw-overflow-auto tvw-whitespace-pre-wrap tvw-rounded-lg tvw-border tvw-border-gray-100 tvw-bg-white tvw-px-3 tvw-py-2 tvw-text-xs tvw-text-cw-primary");f.style.fontSize="0.75rem",f.style.lineHeight="1rem",n.codeBlockBackgroundColor&&(f.style.backgroundColor=n.codeBlockBackgroundColor),n.codeBlockBorderColor&&(f.style.borderColor=n.codeBlockBorderColor),n.codeBlockTextColor&&(f.style.color=n.codeBlockTextColor),f.textContent=an(e.result),x.append(P,f),Y.appendChild(x)}if(e.status==="complete"&&typeof e.duration=="number"){let x=p("div","tvw-text-xs tvw-text-cw-muted");n.contentTextColor&&(x.style.color=n.contentTextColor),x.textContent=`Duration: ${e.duration}ms`,Y.appendChild(x)}let O=()=>{i.setAttribute("aria-expanded",l?"true":"false"),k.innerHTML="";let x=n.toggleTextColor||n.headerTextColor||"currentColor",P=ft(l?"chevron-up":"chevron-down",16,x,2);P?k.appendChild(P):k.textContent=l?"Hide":"Show",Y.style.display=l?"":"none"},J=()=>{l=!l,l?fn.add(t.id):fn.delete(t.id),O()};return i.addEventListener("pointerdown",x=>{x.preventDefault(),J()}),i.addEventListener("keydown",x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),J())}),O(),r.append(i,Y),r};var to=t=>{let o=[];return{buttons:o,render:(n,r,l,i)=>{if(t.innerHTML="",o.length=0,!n||!n.length||(i!=null?i:r?r.getMessages():[]).some(D=>D.role==="user"))return;let k=document.createDocumentFragment(),h=r?r.isStreaming():!1;n.forEach(D=>{let M=p("button","tvw-rounded-button tvw-bg-cw-surface tvw-px-3 tvw-py-1.5 tvw-text-xs tvw-font-medium tvw-text-cw-muted hover:tvw-opacity-90 tvw-cursor-pointer tvw-border tvw-border-gray-200");M.type="button",M.textContent=D,M.disabled=h,M.addEventListener("click",()=>{!r||r.isStreaming()||(l.value="",r.sendMessage(D))}),k.appendChild(M),o.push(M)}),t.appendChild(k)}}};var eo={init:{title:"Schedule a Demo",description:"Share the basics and we'll follow up with a confirmation.",fields:[{name:"name",label:"Full name",placeholder:"Jane Doe",required:!0},{name:"email",label:"Work email",placeholder:"jane@example.com",type:"email",required:!0},{name:"notes",label:"What would you like to cover?",type:"textarea"}],submitLabel:"Submit details"},followup:{title:"Additional Information",description:"Provide any extra details to tailor the next steps.",fields:[{name:"company",label:"Company",placeholder:"Acme Inc."},{name:"context",label:"Context",type:"textarea",placeholder:"Share more about your use case"}],submitLabel:"Send"}},hn=(t,o,e,n)=>{let r=t.querySelectorAll("[data-tv-form]");r.length&&r.forEach(l=>{var O,J,I;if(l.dataset.enhanced==="true")return;let i=(O=l.dataset.tvForm)!=null?O:"init";l.dataset.enhanced="true";let W=(J=eo[i])!=null?J:eo.init;l.classList.add("tvw-form-card","tvw-space-y-4");let b=p("div","tvw-space-y-1"),k=p("h3","tvw-text-base tvw-font-semibold tvw-text-cw-primary");if(k.textContent=W.title,b.appendChild(k),W.description){let x=p("p","tvw-text-sm tvw-text-cw-muted");x.textContent=W.description,b.appendChild(x)}let h=document.createElement("form");h.className="tvw-form-grid tvw-space-y-3",W.fields.forEach(x=>{var T,ot;let P=p("label","tvw-form-field tvw-flex tvw-flex-col tvw-gap-1");P.htmlFor=`${o.id}-${i}-${x.name}`;let f=p("span","tvw-text-xs tvw-font-medium tvw-text-cw-muted");f.textContent=x.label,P.appendChild(f);let yt=(T=x.type)!=null?T:"text",F;yt==="textarea"?(F=document.createElement("textarea"),F.rows=3):(F=document.createElement("input"),F.type=yt),F.className="tvw-rounded-xl tvw-border tvw-border-gray-200 tvw-bg-white tvw-px-3 tvw-py-2 tvw-text-sm tvw-text-cw-primary focus:tvw-outline-none focus:tvw-border-cw-primary",F.id=`${o.id}-${i}-${x.name}`,F.name=x.name,F.placeholder=(ot=x.placeholder)!=null?ot:"",x.required&&(F.required=!0),P.appendChild(F),h.appendChild(P)});let D=p("div","tvw-flex tvw-items-center tvw-justify-between tvw-gap-2"),M=p("div","tvw-text-xs tvw-text-cw-muted tvw-min-h-[1.5rem]"),Y=p("button","tvw-inline-flex tvw-items-center tvw-rounded-full tvw-bg-cw-primary tvw-px-4 tvw-py-2 tvw-text-sm tvw-font-semibold tvw-text-white disabled:tvw-opacity-60 tvw-cursor-pointer");Y.type="submit",Y.textContent=(I=W.submitLabel)!=null?I:"Submit",D.appendChild(M),D.appendChild(Y),h.appendChild(D),l.replaceChildren(b,h),h.addEventListener("submit",async x=>{var F,T;x.preventDefault();let P=(F=e.formEndpoint)!=null?F:"/form",f=new FormData(h),yt={};f.forEach((ot,ct)=>{yt[ct]=ot}),yt.type=i,Y.disabled=!0,M.textContent="Submitting\u2026";try{let ot=await fetch(P,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(yt)});if(!ot.ok)throw new Error(`Form submission failed (${ot.status})`);let ct=await ot.json();M.textContent=(T=ct.message)!=null?T:"Thanks! We'll be in touch soon.",ct.success&&ct.nextPrompt&&await n.sendMessage(String(ct.nextPrompt))}catch(ot){M.textContent=ot instanceof Error?ot.message:"Something went wrong. Please try again."}finally{Y.disabled=!1}})})};var vn=class{constructor(){this.plugins=new Map}register(o){var e;this.plugins.has(o.id)&&console.warn(`Plugin "${o.id}" is already registered. Overwriting.`),this.plugins.set(o.id,o),(e=o.onRegister)==null||e.call(o)}unregister(o){var n;let e=this.plugins.get(o);e&&((n=e.onUnregister)==null||n.call(e),this.plugins.delete(o))}getAll(){return Array.from(this.plugins.values()).sort((o,e)=>{var n,r;return((n=e.priority)!=null?n:0)-((r=o.priority)!=null?r:0)})}getForInstance(o){let e=this.getAll();if(!o||o.length===0)return e;let n=new Set(o.map(l=>l.id));return[...e.filter(l=>!n.has(l.id)),...o].sort((l,i)=>{var W,b;return((W=i.priority)!=null?W:0)-((b=l.priority)!=null?b:0)})}clear(){this.plugins.forEach(o=>{var e;return(e=o.onUnregister)==null?void 0:e.call(o)}),this.plugins.clear()}},Je=new vn;var Dt={apiUrl:"http://localhost:43111/api/chat/dispatch",theme:{primary:"#111827",accent:"#1d4ed8",surface:"#ffffff",muted:"#6b7280",container:"#f8fafc",border:"#f1f5f9",divider:"#f1f5f9",messageBorder:"#f1f5f9",inputBackground:"#ffffff",callToAction:"#000000",callToActionBackground:"#ffffff",sendButtonBackgroundColor:"#111827",sendButtonTextColor:"#ffffff",sendButtonBorderColor:"#60a5fa",closeButtonColor:"#6b7280",closeButtonBackgroundColor:"transparent",closeButtonBorderColor:"",clearChatIconColor:"#6b7280",clearChatBackgroundColor:"transparent",clearChatBorderColor:"transparent",micIconColor:"#111827",micBackgroundColor:"transparent",micBorderColor:"transparent",recordingIconColor:"#ffffff",recordingBackgroundColor:"#ef4444",recordingBorderColor:"transparent",inputFontFamily:"sans-serif",inputFontWeight:"400",radiusSm:"0.75rem",radiusMd:"1rem",radiusLg:"1.5rem",launcherRadius:"9999px",buttonRadius:"9999px"},launcher:{enabled:!0,title:"Chat Assistant",subtitle:"Here to help you get answers fast",agentIconText:"\u{1F4AC}",position:"bottom-right",width:"min(400px, calc(100vw - 24px))",autoExpand:!1,callToActionIconHidden:!1,agentIconSize:"40px",headerIconSize:"40px",closeButtonSize:"32px",callToActionIconName:"arrow-up-right",callToActionIconText:"",callToActionIconSize:"32px",callToActionIconPadding:"5px",callToActionIconColor:"#000000",callToActionIconBackgroundColor:"#ffffff",closeButtonColor:"#6b7280",closeButtonBackgroundColor:"transparent",clearChat:{iconColor:"#6b7280",backgroundColor:"transparent",borderColor:"transparent",enabled:!0,iconName:"refresh-cw",size:"29px",showTooltip:!0,tooltipText:"Clear chat",paddingX:"0px",paddingY:"0px"},headerIconHidden:!1},copy:{welcomeTitle:"Hello \u{1F44B}",welcomeSubtitle:"Ask anything about your account or products.",inputPlaceholder:"How can I help...",sendButtonLabel:"Send"},sendButton:{borderWidth:"0px",paddingX:"12px",paddingY:"10px",backgroundColor:"#111827",textColor:"#ffffff",borderColor:"#60a5fa",useIcon:!0,iconText:"\u2191",size:"40px",showTooltip:!0,tooltipText:"Send message",iconName:"send"},statusIndicator:{visible:!0,idleText:"Online",connectingText:"Connecting\u2026",connectedText:"Streaming\u2026",errorText:"Offline"},voiceRecognition:{enabled:!0,pauseDuration:2e3,iconName:"mic",iconSize:"39px",borderWidth:"0px",paddingX:"9px",paddingY:"14px",iconColor:"#111827",backgroundColor:"transparent",borderColor:"transparent",recordingIconColor:"#ffffff",recordingBackgroundColor:"#ef4444",recordingBorderColor:"transparent",showTooltip:!0,tooltipText:"Start voice recognition"},features:{showReasoning:!0,showToolCalls:!0},suggestionChips:["What can you help me with?","Tell me about your features","How does this work?"],debug:!1};function nn(t){var o,e,n;return t?{...Dt,...t,theme:{...Dt.theme,...t.theme},launcher:{...Dt.launcher,...t.launcher,clearChat:{...(o=Dt.launcher)==null?void 0:o.clearChat,...(e=t.launcher)==null?void 0:e.clearChat}},copy:{...Dt.copy,...t.copy},sendButton:{...Dt.sendButton,...t.sendButton},statusIndicator:{...Dt.statusIndicator,...t.statusIndicator},voiceRecognition:{...Dt.voiceRecognition,...t.voiceRecognition},features:{...Dt.features,...t.features},suggestionChips:(n=t.suggestionChips)!=null?n:Dt.suggestionChips}:Dt}var Fe="vanilla-agent-chat-history",no=t=>t!=null&&t.postprocessMessage?o=>t.postprocessMessage({text:o.text,message:o.message,streaming:o.streaming}):({text:o})=>Qe(o),on=(t,o)=>{var ge,me,fe,we,he,ve,ye,be,xe;(!t.id||t.id!=="vanilla-agent-root")&&(t.id="vanilla-agent-root");let e=nn(o);cn(t,e);let n=Je.getForInstance(e.plugins),r=(me=(ge=e.launcher)==null?void 0:ge.enabled)!=null?me:!0,l=(we=(fe=e.launcher)==null?void 0:fe.autoExpand)!=null?we:!1,i=l,W=r,b=r?l:!0,k=no(e),h=(ve=(he=e.features)==null?void 0:he.showReasoning)!=null?ve:!0,D=(be=(ye=e.features)==null?void 0:ye.showToolCalls)!=null?be:!0,M=(xe=e.statusIndicator)!=null?xe:{},Y=s=>{var E,a,L,g;return s==="idle"?(E=M.idleText)!=null?E:Lt.idle:s==="connecting"?(a=M.connectingText)!=null?a:Lt.connecting:s==="connected"?(L=M.connectedText)!=null?L:Lt.connected:s==="error"?(g=M.errorText)!=null?g:Lt.error:Lt[s]},{wrapper:O,panel:J}=Zn(e),I=Qn(e,r),{container:x,body:P,messagesWrapper:f,suggestions:yt,textarea:F,sendButton:T,sendButtonWrapper:ot,composerForm:ct,statusText:dt,introTitle:xt,introSubtitle:ht,closeButton:v,iconHolder:z}=I,C=I.micButton,bt=I.micButtonWrapper;J.appendChild(x),t.appendChild(O);let Pt=[],Xt=to(yt),$t=null,X,Mt=!1,G=!0,Gt=0,Ae=0,Ot=null,et=!1,Zt=0,Qt=!1,Ee=125,Le=2e3,Ie=5,qt=50,_t=(s=!1)=>{if(!G)return;let E=Date.now();et&&E<Zt&&!s||(et&&E>=Zt&&(et=!1),!(!s&&!Mt)&&(E-Ae<Ee||(Ae=E,Ot&&cancelAnimationFrame(Ot),Ot=requestAnimationFrame(()=>{et||!G||(Qt=!0,P.scrollTop=P.scrollHeight,Gt=P.scrollTop,requestAnimationFrame(()=>{Qt=!1}),Ot=null)}))))},gt=null,Yt=()=>O.querySelector("#vanilla-agent-scroll-container")||P,_=(s,E=500)=>{let a=s.scrollTop,L=s.clientHeight,g=s.scrollHeight,w=g-a;if(a+L>=g-2||Math.abs(w)<5)return;gt!==null&&(cancelAnimationFrame(gt),gt=null);let R=performance.now(),B=y=>1-Math.pow(1-y,3),c=y=>{let S=s.scrollHeight;S!==g&&(g=S,w=g-a);let u=y-R,d=Math.min(u/E,1),H=B(d),N=a+w*H;s.scrollTop=N,d<1?gt=requestAnimationFrame(c):(s.scrollTop=s.scrollHeight,gt=null)};gt=requestAnimationFrame(c)},it=(s,E,a)=>{s.innerHTML="";let L=document.createDocumentFragment();E.forEach(w=>{let m=null,R=n.find(c=>!!(w.variant==="reasoning"&&c.renderReasoning||w.variant==="tool"&&c.renderToolCall||!w.variant&&c.renderMessage));if(R)if(w.variant==="reasoning"&&w.reasoning&&R.renderReasoning){if(!h)return;m=R.renderReasoning({message:w,defaultRenderer:()=>mn(w),config:e})}else if(w.variant==="tool"&&w.toolCall&&R.renderToolCall){if(!D)return;m=R.renderToolCall({message:w,defaultRenderer:()=>wn(w,e),config:e})}else R.renderMessage&&(m=R.renderMessage({message:w,defaultRenderer:()=>{let c=pn(w,a);return w.role!=="user"&&hn(c,w,e,X),c},config:e}));if(!m)if(w.variant==="reasoning"&&w.reasoning){if(!h)return;m=mn(w)}else if(w.variant==="tool"&&w.toolCall){if(!D)return;m=wn(w,e)}else m=pn(w,a),w.role!=="user"&&hn(m,w,e,X);let B=document.createElement("div");B.className="tvw-flex",w.role==="user"&&B.classList.add("tvw-justify-end"),B.appendChild(m),L.appendChild(B)});let g=E.some(w=>w.role==="assistant"&&w.streaming);if(Mt&&E.some(w=>w.role==="user")&&!g){let w=un(),m=document.createElement("div");m.className=["tvw-max-w-[85%]","tvw-rounded-2xl","tvw-text-sm","tvw-leading-relaxed","tvw-shadow-sm","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-px-5","tvw-py-3"].join(" "),m.appendChild(w);let R=document.createElement("div");R.className="tvw-flex",R.appendChild(m),L.appendChild(R)}s.appendChild(L),requestAnimationFrame(()=>{requestAnimationFrame(()=>{let w=Yt();_(w)})})},te=()=>{r&&(b?(O.classList.remove("tvw-pointer-events-none","tvw-opacity-0"),J.classList.remove("tvw-scale-95","tvw-opacity-0"),J.classList.add("tvw-scale-100","tvw-opacity-100"),rt&&(rt.element.style.display="none")):(O.classList.add("tvw-pointer-events-none","tvw-opacity-0"),J.classList.remove("tvw-scale-100","tvw-opacity-100"),J.classList.add("tvw-scale-95","tvw-opacity-0"),rt&&(rt.element.style.display="")))},$=s=>{r&&b!==s&&(b=s,te(),b&&(Ut(),_t(!0)))},Wt=s=>{F.disabled=s,T.disabled=s,C&&(C.disabled=s),Xt.buttons.forEach(E=>{E.disabled=s})},Me=()=>{var g,w,m,R,B,c,y,S,u,d,H,N,Z,nt;xt.textContent=(w=(g=e.copy)==null?void 0:g.welcomeTitle)!=null?w:"Hello \u{1F44B}",ht.textContent=(R=(m=e.copy)==null?void 0:m.welcomeSubtitle)!=null?R:"Ask anything about your account or products.",F.placeholder=(c=(B=e.copy)==null?void 0:B.inputPlaceholder)!=null?c:"How can I help...",((S=(y=e.sendButton)==null?void 0:y.useIcon)!=null?S:!1)||(T.textContent=(d=(u=e.copy)==null?void 0:u.sendButtonLabel)!=null?d:"Send");let E=(N=(H=e.theme)==null?void 0:H.inputFontFamily)!=null?N:"sans-serif",a=(nt=(Z=e.theme)==null?void 0:Z.inputFontWeight)!=null?nt:"400",L=lt=>{switch(lt){case"serif":return'Georgia, "Times New Roman", Times, serif';case"mono":return'"Courier New", Courier, "Lucida Console", Monaco, monospace';case"sans-serif":default:return'-apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif'}};F.style.fontFamily=L(E),F.style.fontWeight=a};X=new Ne(e,{onMessagesChanged(s){it(f,s,k),X&&(s.some(a=>a.role==="user")?Xt.render([],X,F,s):Xt.render(e.suggestionChips,X,F,s)),_t(!Mt)},onStatusChanged(s){var L;let E=(L=e.statusIndicator)!=null?L:{},a=g=>{var w,m,R,B;return g==="idle"?(w=E.idleText)!=null?w:Lt.idle:g==="connecting"?(m=E.connectingText)!=null?m:Lt.connecting:g==="connected"?(R=E.connectedText)!=null?R:Lt.connected:g==="error"?(B=E.errorText)!=null?B:Lt.error:Lt[g]};dt.textContent=a(s)},onStreamingChanged(s){Mt=s,Wt(s),X&&it(f,X.getMessages(),k),s||_t(!0)}});let Vt=s=>{s.preventDefault();let E=F.value.trim();E&&(F.value="",X.sendMessage(E))},le=s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),T.click())},Ct=null,Et=!1,zt=null,Nt=null,ae=()=>typeof window=="undefined"?null:window.webkitSpeechRecognition||window.SpeechRecognition||null,ce=()=>{var g,w,m,R;if(Et||X.isStreaming())return;let s=ae();if(!s)return;Ct=new s;let a=(w=((g=e.voiceRecognition)!=null?g:{}).pauseDuration)!=null?w:2e3;Ct.continuous=!0,Ct.interimResults=!0,Ct.lang="en-US";let L=F.value;Ct.onresult=B=>{let c="",y="";for(let u=0;u<B.results.length;u++){let d=B.results[u],H=d[0].transcript;d.isFinal?c+=H+" ":y=H}let S=L+c+y;F.value=S,zt&&clearTimeout(zt),(c||y)&&(zt=window.setTimeout(()=>{let u=F.value.trim();u&&Ct&&Et&&(kt(),F.value="",X.sendMessage(u,{viaVoice:!0}))},a))},Ct.onerror=B=>{B.error!=="no-speech"&&kt()},Ct.onend=()=>{if(Et){let B=F.value.trim();B&&B!==L.trim()&&(F.value="",X.sendMessage(B,{viaVoice:!0})),kt()}};try{if(Ct.start(),Et=!0,C){Nt={backgroundColor:C.style.backgroundColor,color:C.style.color,borderColor:C.style.borderColor};let B=(m=e.voiceRecognition)!=null?m:{},c=(R=B.recordingBackgroundColor)!=null?R:"#ef4444",y=B.recordingIconColor,S=B.recordingBorderColor;if(C.classList.add("tvw-voice-recording"),C.style.backgroundColor=c,y){C.style.color=y;let u=C.querySelector("svg");u&&u.setAttribute("stroke",y)}S&&(C.style.borderColor=S),C.setAttribute("aria-label","Stop voice recognition")}}catch{kt()}},kt=()=>{if(Et){if(Et=!1,zt&&(clearTimeout(zt),zt=null),Ct){try{Ct.stop()}catch{}Ct=null}if(C){if(C.classList.remove("tvw-voice-recording"),Nt){C.style.backgroundColor=Nt.backgroundColor,C.style.color=Nt.color,C.style.borderColor=Nt.borderColor;let s=C.querySelector("svg");s&&s.setAttribute("stroke",Nt.color||"currentColor"),Nt=null}C.setAttribute("aria-label","Start voice recognition")}}},Be=(s,E)=>{var N,Z,nt,lt,at,Q,j;if(!(typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined")))return null;let L=p("div","tvw-send-button-wrapper"),g=p("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer");g.type="button",g.setAttribute("aria-label","Start voice recognition");let w=(N=s==null?void 0:s.iconName)!=null?N:"mic",m=(Z=E==null?void 0:E.size)!=null?Z:"40px",R=(nt=s==null?void 0:s.iconSize)!=null?nt:m,B=parseFloat(R)||24,c=(lt=s==null?void 0:s.backgroundColor)!=null?lt:E==null?void 0:E.backgroundColor,y=(at=s==null?void 0:s.iconColor)!=null?at:E==null?void 0:E.textColor;g.style.width=R,g.style.height=R,g.style.minWidth=R,g.style.minHeight=R,g.style.fontSize="18px",g.style.lineHeight="1";let S=y||"currentColor",u=ft(w,B,S,1.5);u?(g.appendChild(u),g.style.color=S):(g.textContent="\u{1F3A4}",g.style.color=S),c?g.style.backgroundColor=c:g.classList.add("tvw-bg-cw-primary"),y?g.style.color=y:!y&&!(E!=null&&E.textColor)&&g.classList.add("tvw-text-white"),s!=null&&s.borderWidth&&(g.style.borderWidth=s.borderWidth,g.style.borderStyle="solid"),s!=null&&s.borderColor&&(g.style.borderColor=s.borderColor),s!=null&&s.paddingX&&(g.style.paddingLeft=s.paddingX,g.style.paddingRight=s.paddingX),s!=null&&s.paddingY&&(g.style.paddingTop=s.paddingY,g.style.paddingBottom=s.paddingY),L.appendChild(g);let d=(Q=s==null?void 0:s.tooltipText)!=null?Q:"Start voice recognition";if(((j=s==null?void 0:s.showTooltip)!=null?j:!1)&&d){let U=p("div","tvw-send-button-tooltip");U.textContent=d,L.appendChild(U)}return{micButton:g,micButtonWrapper:L}},ee=()=>{if(Et){let s=F.value.trim();kt(),s&&(F.value="",X.sendMessage(s))}else ce()};C&&(C.addEventListener("click",ee),Pt.push(()=>{kt(),C&&C.removeEventListener("click",ee)}));let de=()=>{$(!b)},rt=r?dn(e,de):null;rt&&t.appendChild(rt.element),te(),Xt.render(e.suggestionChips,X,F),Me(),Wt(X.isStreaming()),_t(!0);let Ut=()=>{var m,R;if(!r){J.style.height="",J.style.width="";return}let s=(R=(m=e==null?void 0:e.launcher)==null?void 0:m.width)!=null?R:e==null?void 0:e.launcherWidth,E=s!=null?s:"min(400px, calc(100vw - 24px))";J.style.width=E,J.style.maxWidth=E;let a=window.innerHeight,g=Math.max(200,a-64),w=Math.min(640,g);J.style.height=`${w}px`};Ut(),window.addEventListener("resize",Ut),Pt.push(()=>window.removeEventListener("resize",Ut)),Gt=P.scrollTop;let ue=()=>{let s=P.scrollTop,E=P.scrollHeight,a=P.clientHeight,L=E-s-a,g=Math.abs(s-Gt);if(Gt=s,!Qt&&!(g<=Ie)){if(!G&&L<qt){et=!1,G=!0;return}G&&L>qt&&(et=!0,Zt=Date.now()+Le,G=!1)}};P.addEventListener("scroll",ue,{passive:!0}),Pt.push(()=>P.removeEventListener("scroll",ue)),Pt.push(()=>{Ot&&cancelAnimationFrame(Ot)});let pe=()=>{v&&($t&&(v.removeEventListener("click",$t),$t=null),r?(v.style.display="",$t=()=>{b=!1,te()},v.addEventListener("click",$t)):v.style.display="none")};return pe(),(()=>{let{clearChatButton:s}=I;s&&s.addEventListener("click",()=>{X.clearMessages();try{localStorage.removeItem(Fe),e.debug&&console.log(`[AgentWidget] Cleared default localStorage key: ${Fe}`)}catch(a){console.error("[AgentWidget] Failed to clear default localStorage:",a)}if(e.clearChatHistoryStorageKey&&e.clearChatHistoryStorageKey!==Fe)try{localStorage.removeItem(e.clearChatHistoryStorageKey),e.debug&&console.log(`[AgentWidget] Cleared custom localStorage key: ${e.clearChatHistoryStorageKey}`)}catch(a){console.error("[AgentWidget] Failed to clear custom localStorage:",a)}let E=new CustomEvent("vanilla-agent:clear-chat",{detail:{timestamp:new Date().toISOString()}});window.dispatchEvent(E)})})(),ct.addEventListener("submit",Vt),F.addEventListener("keydown",le),Pt.push(()=>{ct.removeEventListener("submit",Vt),F.removeEventListener("keydown",le)}),Pt.push(()=>{X.cancel()}),rt&&Pt.push(()=>{rt==null||rt.destroy()}),{update(s){var De,qe,ze,$e,Oe,_e,Ue,je,Xe,Ye,q,ut,St,jt,It,ne,Ce,oe,We,re,Ge,Ve,vt,se,Te,Ke,Re,xn,Cn,Tn,Sn,An,En,Ln,Mn,Bn,Wn,kn,In,Hn,Rn,Pn,Nn,Fn,Dn,qn,zn,$n,On;let E=e.toolCall;e={...e,...s},cn(t,e);let a=Je.getForInstance(e.plugins);n.length=0,n.push(...a),r=(qe=(De=e.launcher)==null?void 0:De.enabled)!=null?qe:!0,l=($e=(ze=e.launcher)==null?void 0:ze.autoExpand)!=null?$e:!1,h=(_e=(Oe=e.features)==null?void 0:Oe.showReasoning)!=null?_e:!0,D=(je=(Ue=e.features)==null?void 0:Ue.showToolCalls)!=null?je:!0,((Xe=e.launcher)==null?void 0:Xe.enabled)===!1&&rt&&(rt.destroy(),rt=null),((Ye=e.launcher)==null?void 0:Ye.enabled)!==!1&&!rt&&(rt=dn(e,de),t.appendChild(rt.element)),rt&&rt.update(e),r!==W?r?$(l):(b=!0,te()):l!==i&&$(l),i=l,W=r,Ut(),pe(),JSON.stringify(s.toolCall)!==JSON.stringify(E)&&X&&it(f,X.getMessages(),k);let m=(q=e.launcher)!=null?q:{},R=(ut=m.headerIconHidden)!=null?ut:!1,B=m.headerIconName,c=(St=m.headerIconSize)!=null?St:"48px";if(z){let A=x.querySelector(".tvw-border-b-cw-divider"),mt=A==null?void 0:A.querySelector(".tvw-flex-col");if(R)z.style.display="none",A&&mt&&!A.contains(mt)&&A.insertBefore(mt,A.firstChild);else{if(z.style.display="",z.style.height=c,z.style.width=c,A&&mt&&(A.contains(z)?z.nextSibling!==mt&&(z.remove(),A.insertBefore(z,mt)):A.insertBefore(z,mt)),B){let At=parseFloat(c)||24,st=ft(B,At*.6,"#ffffff",2);st?z.replaceChildren(st):z.textContent=(jt=m.agentIconText)!=null?jt:"\u{1F4AC}"}else if(m.iconUrl){let At=z.querySelector("img");if(At)At.src=m.iconUrl,At.style.height=c,At.style.width=c;else{let st=document.createElement("img");st.src=m.iconUrl,st.alt="",st.className="tvw-rounded-xl tvw-object-cover",st.style.height=c,st.style.width=c,z.replaceChildren(st)}}else{let At=z.querySelector("svg"),st=z.querySelector("img");(At||st)&&z.replaceChildren(),z.textContent=(It=m.agentIconText)!=null?It:"\u{1F4AC}"}let wt=z.querySelector("img");wt&&(wt.style.height=c,wt.style.width=c)}}if(v){let A=(ne=m.closeButtonSize)!=null?ne:"32px",mt=(Ce=m.closeButtonPlacement)!=null?Ce:"inline";v.style.height=A,v.style.width=A;let wt=mt==="top-right",At=v.classList.contains("tvw-absolute");if(wt!==At)if(v.remove(),wt)v.className="tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50 tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none",x.style.position="relative",x.appendChild(v);else{v.className="tvw-ml-auto tvw-inline-flex tvw-items-center tvw-justify-center tvw-rounded-full tvw-text-cw-muted hover:tvw-bg-gray-100 tvw-cursor-pointer tvw-border-none";let tt=x.querySelector(".tvw-border-b-cw-divider");tt&&tt.appendChild(v)}if(m.closeButtonColor?(v.style.color=m.closeButtonColor,v.classList.remove("tvw-text-cw-muted")):(v.style.color="",v.classList.add("tvw-text-cw-muted")),m.closeButtonBackgroundColor?(v.style.backgroundColor=m.closeButtonBackgroundColor,v.classList.remove("hover:tvw-bg-gray-100")):(v.style.backgroundColor="",v.classList.add("hover:tvw-bg-gray-100")),m.closeButtonBorderWidth||m.closeButtonBorderColor){let tt=m.closeButtonBorderWidth||"0px",Jt=m.closeButtonBorderColor||"transparent";v.style.border=`${tt} solid ${Jt}`,v.classList.remove("tvw-border-none")}else v.style.border="",v.classList.add("tvw-border-none");m.closeButtonBorderRadius?(v.style.borderRadius=m.closeButtonBorderRadius,v.classList.remove("tvw-rounded-full")):(v.style.borderRadius="",v.classList.add("tvw-rounded-full")),m.closeButtonPaddingX?(v.style.paddingLeft=m.closeButtonPaddingX,v.style.paddingRight=m.closeButtonPaddingX):(v.style.paddingLeft="",v.style.paddingRight=""),m.closeButtonPaddingY?(v.style.paddingTop=m.closeButtonPaddingY,v.style.paddingBottom=m.closeButtonPaddingY):(v.style.paddingTop="",v.style.paddingBottom="");let st=(oe=m.closeButtonIconName)!=null?oe:"x",ie=(We=m.closeButtonIconText)!=null?We:"\xD7";v.innerHTML="";let Ht=ft(st,"20px",m.closeButtonColor||"",2);Ht?v.appendChild(Ht):v.textContent=ie;let{closeButtonWrapper:Bt}=I,pt=(re=m.closeButtonTooltipText)!=null?re:"Close chat",Rt=(Ge=m.closeButtonShowTooltip)!=null?Ge:!0;if(v.setAttribute("aria-label",pt),Bt&&(Bt._cleanupTooltip&&(Bt._cleanupTooltip(),delete Bt._cleanupTooltip),Rt&&pt)){let tt=null,Jt=()=>{if(tt||!v)return;tt=p("div","tvw-clear-chat-tooltip"),tt.textContent=pt;let _n=p("div");_n.className="tvw-clear-chat-tooltip-arrow",tt.appendChild(_n);let rn=v.getBoundingClientRect();tt.style.position="fixed",tt.style.left=`${rn.left+rn.width/2}px`,tt.style.top=`${rn.top-8}px`,tt.style.transform="translate(-50%, -100%)",document.body.appendChild(tt)},Ft=()=>{tt&&tt.parentNode&&(tt.parentNode.removeChild(tt),tt=null)};Bt.addEventListener("mouseenter",Jt),Bt.addEventListener("mouseleave",Ft),v.addEventListener("focus",Jt),v.addEventListener("blur",Ft),Bt._cleanupTooltip=()=>{Ft(),Bt&&(Bt.removeEventListener("mouseenter",Jt),Bt.removeEventListener("mouseleave",Ft)),v&&(v.removeEventListener("focus",Jt),v.removeEventListener("blur",Ft))}}}let{clearChatButton:y,clearChatButtonWrapper:S}=I;if(y){let A=(Ve=m.clearChat)!=null?Ve:{},mt=(vt=A.enabled)!=null?vt:!0;if(S&&(S.style.display=mt?"":"none"),mt){let wt=(se=A.size)!=null?se:"32px";y.style.height=wt,y.style.width=wt;let At=(Te=A.iconName)!=null?Te:"refresh-cw",st=(Ke=A.iconColor)!=null?Ke:"";y.innerHTML="";let ie=ft(At,"20px",st||"",2);if(ie&&y.appendChild(ie),st?(y.style.color=st,y.classList.remove("tvw-text-cw-muted")):(y.style.color="",y.classList.add("tvw-text-cw-muted")),A.backgroundColor?(y.style.backgroundColor=A.backgroundColor,y.classList.remove("hover:tvw-bg-gray-100")):(y.style.backgroundColor="",y.classList.add("hover:tvw-bg-gray-100")),A.borderWidth||A.borderColor){let pt=A.borderWidth||"0px",Rt=A.borderColor||"transparent";y.style.border=`${pt} solid ${Rt}`,y.classList.remove("tvw-border-none")}else y.style.border="",y.classList.add("tvw-border-none");A.borderRadius?(y.style.borderRadius=A.borderRadius,y.classList.remove("tvw-rounded-full")):(y.style.borderRadius="",y.classList.add("tvw-rounded-full")),A.paddingX?(y.style.paddingLeft=A.paddingX,y.style.paddingRight=A.paddingX):(y.style.paddingLeft="",y.style.paddingRight=""),A.paddingY?(y.style.paddingTop=A.paddingY,y.style.paddingBottom=A.paddingY):(y.style.paddingTop="",y.style.paddingBottom="");let Ht=(Re=A.tooltipText)!=null?Re:"Clear chat",Bt=(xn=A.showTooltip)!=null?xn:!0;if(y.setAttribute("aria-label",Ht),S&&(S._cleanupTooltip&&(S._cleanupTooltip(),delete S._cleanupTooltip),Bt&&Ht)){let pt=null,Rt=()=>{if(pt||!y)return;pt=p("div","tvw-clear-chat-tooltip"),pt.textContent=Ht;let Jt=p("div");Jt.className="tvw-clear-chat-tooltip-arrow",pt.appendChild(Jt);let Ft=y.getBoundingClientRect();pt.style.position="fixed",pt.style.left=`${Ft.left+Ft.width/2}px`,pt.style.top=`${Ft.top-8}px`,pt.style.transform="translate(-50%, -100%)",document.body.appendChild(pt)},tt=()=>{pt&&pt.parentNode&&(pt.parentNode.removeChild(pt),pt=null)};S.addEventListener("mouseenter",Rt),S.addEventListener("mouseleave",tt),y.addEventListener("focus",Rt),y.addEventListener("blur",tt),S._cleanupTooltip=()=>{tt(),S&&(S.removeEventListener("mouseenter",Rt),S.removeEventListener("mouseleave",tt)),y&&(y.removeEventListener("focus",Rt),y.removeEventListener("blur",tt))}}}}k=no(e),X.updateConfig(e),it(f,X.getMessages(),k),Xt.render(e.suggestionChips,X,F),Me(),Wt(X.isStreaming());let u=((Cn=e.voiceRecognition)==null?void 0:Cn.enabled)===!0,d=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),H=u&&d;if(ct.classList.remove("tvw-gap-1","tvw-gap-3"),ct.classList.add(H?"tvw-gap-1":"tvw-gap-3"),u&&d)if(!C||!bt){let A=Be(e.voiceRecognition,e.sendButton);A&&(C=A.micButton,bt=A.micButtonWrapper,ct.insertBefore(bt,ot),C.addEventListener("click",ee),C.disabled=X.isStreaming())}else{let A=(Tn=e.voiceRecognition)!=null?Tn:{},mt=(Sn=e.sendButton)!=null?Sn:{},wt=(An=A.iconName)!=null?An:"mic",At=(En=mt.size)!=null?En:"40px",st=(Ln=A.iconSize)!=null?Ln:At,ie=parseFloat(st)||24;C.style.width=st,C.style.height=st,C.style.minWidth=st,C.style.minHeight=st;let Ht=(Bn=(Mn=A.iconColor)!=null?Mn:mt.textColor)!=null?Bn:"currentColor";C.innerHTML="";let Bt=ft(wt,ie,Ht,2);Bt?C.appendChild(Bt):C.textContent="\u{1F3A4}";let pt=(Wn=A.backgroundColor)!=null?Wn:mt.backgroundColor;pt?(C.style.backgroundColor=pt,C.classList.remove("tvw-bg-cw-primary")):(C.style.backgroundColor="",C.classList.add("tvw-bg-cw-primary")),Ht?(C.style.color=Ht,C.classList.remove("tvw-text-white")):!Ht&&!mt.textColor&&(C.style.color="",C.classList.add("tvw-text-white")),A.borderWidth?(C.style.borderWidth=A.borderWidth,C.style.borderStyle="solid"):(C.style.borderWidth="",C.style.borderStyle=""),A.borderColor?C.style.borderColor=A.borderColor:C.style.borderColor="",A.paddingX?(C.style.paddingLeft=A.paddingX,C.style.paddingRight=A.paddingX):(C.style.paddingLeft="",C.style.paddingRight=""),A.paddingY?(C.style.paddingTop=A.paddingY,C.style.paddingBottom=A.paddingY):(C.style.paddingTop="",C.style.paddingBottom="");let Rt=bt==null?void 0:bt.querySelector(".tvw-send-button-tooltip"),tt=(kn=A.tooltipText)!=null?kn:"Start voice recognition";if(((In=A.showTooltip)!=null?In:!1)&&tt)if(Rt)Rt.textContent=tt,Rt.style.display="";else{let Ft=document.createElement("div");Ft.className="tvw-send-button-tooltip",Ft.textContent=tt,bt==null||bt.insertBefore(Ft,C)}else Rt&&(Rt.style.display="none");bt.style.display="",C.disabled=X.isStreaming()}else C&&bt&&(bt.style.display="none",Et&&kt());let N=(Hn=e.sendButton)!=null?Hn:{},Z=(Rn=N.useIcon)!=null?Rn:!1,nt=(Pn=N.iconText)!=null?Pn:"\u2191",lt=N.iconName,at=(Nn=N.tooltipText)!=null?Nn:"Send message",Q=(Fn=N.showTooltip)!=null?Fn:!1,j=(Dn=N.size)!=null?Dn:"40px",U=N.backgroundColor,K=N.textColor;if(Z){if(T.style.width=j,T.style.height=j,T.style.minWidth=j,T.style.minHeight=j,T.style.fontSize="18px",T.style.lineHeight="1",T.innerHTML="",lt){let A=parseFloat(j)||24,mt=K&&typeof K=="string"&&K.trim()?K.trim():"currentColor",wt=ft(lt,A,mt,2);wt?(T.appendChild(wt),T.style.color=mt):(T.textContent=nt,K?T.style.color=K:T.classList.add("tvw-text-white"))}else T.textContent=nt,K?T.style.color=K:T.classList.add("tvw-text-white");T.className="tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer",U?(T.style.backgroundColor=U,T.classList.remove("tvw-bg-cw-primary")):T.classList.add("tvw-bg-cw-primary")}else T.textContent=(zn=(qn=e.copy)==null?void 0:qn.sendButtonLabel)!=null?zn:"Send",T.style.width="",T.style.height="",T.style.minWidth="",T.style.minHeight="",T.style.fontSize="",T.style.lineHeight="",T.className="tvw-rounded-button tvw-bg-cw-accent tvw-px-4 tvw-py-2 tvw-text-sm tvw-font-semibold tvw-text-white disabled:tvw-opacity-50 tvw-cursor-pointer",U?(T.style.backgroundColor=U,T.classList.remove("tvw-bg-cw-accent")):T.classList.add("tvw-bg-cw-accent"),K?T.style.color=K:T.classList.add("tvw-text-white");N.borderWidth?(T.style.borderWidth=N.borderWidth,T.style.borderStyle="solid"):(T.style.borderWidth="",T.style.borderStyle=""),N.borderColor?T.style.borderColor=N.borderColor:T.style.borderColor="",N.paddingX?(T.style.paddingLeft=N.paddingX,T.style.paddingRight=N.paddingX):(T.style.paddingLeft="",T.style.paddingRight=""),N.paddingY?(T.style.paddingTop=N.paddingY,T.style.paddingBottom=N.paddingY):(T.style.paddingTop="",T.style.paddingBottom="");let Tt=ot==null?void 0:ot.querySelector(".tvw-send-button-tooltip");if(Q&&at)if(Tt)Tt.textContent=at,Tt.style.display="";else{let A=document.createElement("div");A.className="tvw-send-button-tooltip",A.textContent=at,ot==null||ot.insertBefore(A,T)}else Tt&&(Tt.style.display="none");let V=($n=e.statusIndicator)!=null?$n:{},Kt=(On=V.visible)!=null?On:!0;if(dt.style.display=Kt?"":"none",X){let A=X.getStatus(),mt=wt=>{var At,st,ie,Ht;return wt==="idle"?(At=V.idleText)!=null?At:Lt.idle:wt==="connecting"?(st=V.connectingText)!=null?st:Lt.connecting:wt==="connected"?(ie=V.connectedText)!=null?ie:Lt.connected:wt==="error"?(Ht=V.errorText)!=null?Ht:Lt.error:Lt[wt]};dt.textContent=mt(A)}},open(){r&&$(!0)},close(){r&&$(!1)},toggle(){r&&$(!b)},clearChat(){X.clearMessages();try{localStorage.removeItem(Fe),e.debug&&console.log(`[AgentWidget] Cleared default localStorage key: ${Fe}`)}catch(E){console.error("[AgentWidget] Failed to clear default localStorage:",E)}if(e.clearChatHistoryStorageKey&&e.clearChatHistoryStorageKey!==Fe)try{localStorage.removeItem(e.clearChatHistoryStorageKey),e.debug&&console.log(`[AgentWidget] Cleared custom localStorage key: ${e.clearChatHistoryStorageKey}`)}catch(E){console.error("[AgentWidget] Failed to clear custom localStorage:",E)}let s=new CustomEvent("vanilla-agent:clear-chat",{detail:{timestamp:new Date().toISOString()}});window.dispatchEvent(s)},setMessage(s){return!F||X.isStreaming()?!1:(!b&&r&&$(!0),F.value=s,F.dispatchEvent(new Event("input",{bubbles:!0})),!0)},submitMessage(s){if(X.isStreaming())return!1;let E=(s==null?void 0:s.trim())||F.value.trim();return E?(!b&&r&&$(!0),F.value="",X.sendMessage(E),!0):!1},startVoiceRecognition(){return Et||X.isStreaming()||!ae()?!1:(!b&&r&&$(!0),ce(),!0)},stopVoiceRecognition(){return Et?(kt(),!0):!1},injectTestMessage(s){!b&&r&&$(!0),X.injectTestEvent(s)},destroy(){Pt.forEach(s=>s()),O.remove(),rt==null||rt.destroy(),$t&&v.removeEventListener("click",$t)}}};var yn={},xo=t=>{if(typeof window=="undefined"||typeof document=="undefined")throw new Error("Chat widget can only be mounted in a browser environment");if(typeof t=="string"){let o=document.querySelector(t);if(!o)throw new Error(`Chat widget target "${t}" was not found`);return o}return t},Co=()=>{try{if(typeof yn!="undefined"&&yn.url)return new URL("../widget.css",yn.url).href}catch{}return null},oo=t=>{let o=Co(),e=()=>{if(!(t instanceof ShadowRoot)||t.querySelector("link[data-vanilla-agent]"))return;let n=document.head.querySelector("link[data-vanilla-agent]");if(!n)return;let r=n.cloneNode(!0);t.insertBefore(r,t.firstChild)};if(t instanceof ShadowRoot)if(o){let n=document.createElement("link");n.rel="stylesheet",n.href=o,n.setAttribute("data-vanilla-agent","true"),t.insertBefore(n,t.firstChild)}else e();else if(!document.head.querySelector("link[data-vanilla-agent]")&&o){let r=document.createElement("link");r.rel="stylesheet",r.href=o,r.setAttribute("data-vanilla-agent","true"),document.head.appendChild(r)}},bn=t=>{var b;let o=xo(t.target),e=document.createElement("div");e.className="vanilla-agent-host",o.appendChild(e);let n=t.useShadowDom!==!1,r,l;if(n){let k=e.attachShadow({mode:"open"});l=k,r=document.createElement("div"),r.id="vanilla-agent-root",k.appendChild(r),oo(k)}else l=e,r=document.createElement("div"),r.id="vanilla-agent-root",e.appendChild(r),oo(e);let i=on(r,t.config);(b=t.onReady)==null||b.call(t);let W={host:e,update(k){i.update(k)},open(){i.open()},close(){i.close()},toggle(){i.toggle()},clearChat(){i.clearChat()},setMessage(k){return i.setMessage(k)},submitMessage(k){return i.submitMessage(k)},startVoiceRecognition(){return i.startVoiceRecognition()},stopVoiceRecognition(){return i.stopVoiceRecognition()},injectTestMessage(k){i.injectTestMessage(k)},destroy(){i.destroy(),e.remove(),t.windowKey&&typeof window!="undefined"&&delete window[t.windowKey]}};return t.windowKey&&typeof window!="undefined"&&(window[t.windowKey]=W),W};var To=bn;0&&(module.exports={AgentWidgetClient,AgentWidgetSession,DEFAULT_WIDGET_CONFIG,createAgentExperience,createJsonStreamParser,createPlainTextParser,createRegexJsonParser,createXmlParser,directivePostprocessor,escapeHtml,initAgentWidget,markdownPostprocessor,mergeWithDefaults,pluginRegistry});
|
|
16
16
|
//# sourceMappingURL=index.cjs.map
|