vanilla-agent 1.16.0 → 1.17.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 +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.global.js +2 -2
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/ui.ts +6 -2
package/dist/index.global.js
CHANGED
|
@@ -62,7 +62,7 @@ lucide.createIcons({icons});\``);if(typeof e=="undefined")throw new Error("`crea
|
|
|
62
62
|
</span>
|
|
63
63
|
<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>
|
|
64
64
|
`,r.addEventListener("click",t);let e=o=>{var F,O,v,C,E,S,G,W,j,Y;let d=(F=o.launcher)!=null?F:{},l=r.querySelector("[data-role='launcher-title']");l&&(l.textContent=(O=d.title)!=null?O:"Chat Assistant");let p=r.querySelector("[data-role='launcher-subtitle']");p&&(p.textContent=(v=d.subtitle)!=null?v:"Get answers fast");let f=r.querySelector(".tvw-flex-col");f&&(d.textHidden?f.style.display="none":f.style.display="");let h=r.querySelector("[data-role='launcher-icon']");if(h)if(d.agentIconHidden)h.style.display="none";else{let b=(C=d.agentIconSize)!=null?C:"40px";if(h.style.height=b,h.style.width=b,h.innerHTML="",d.agentIconName){let dt=parseFloat(b)||24,X=wt(d.agentIconName,dt*.6,"#ffffff",2);X?(h.appendChild(X),h.style.display=""):(h.textContent=(E=d.agentIconText)!=null?E:"\u{1F4AC}",h.style.display="")}else d.iconUrl?h.style.display="none":(h.textContent=(S=d.agentIconText)!=null?S:"\u{1F4AC}",h.style.display="")}let c=r.querySelector("[data-role='launcher-image']");if(c){let b=(G=d.agentIconSize)!=null?G:"40px";c.style.height=b,c.style.width=b,d.iconUrl&&!d.agentIconName&&!d.agentIconHidden?(c.src=d.iconUrl,c.style.display="block"):c.style.display="none"}let i=r.querySelector("[data-role='launcher-call-to-action-icon']");if(i){let b=(W=d.callToActionIconSize)!=null?W:"32px";i.style.height=b,i.style.width=b,d.callToActionIconBackgroundColor?(i.style.backgroundColor=d.callToActionIconBackgroundColor,i.classList.remove("tvw-bg-cw-primary")):(i.style.backgroundColor="",i.classList.add("tvw-bg-cw-primary"));let dt=0;if(d.callToActionIconPadding?(i.style.boxSizing="border-box",i.style.padding=d.callToActionIconPadding,dt=(parseFloat(d.callToActionIconPadding)||0)*2):(i.style.boxSizing="",i.style.padding=""),d.callToActionIconHidden)i.style.display="none";else if(i.style.display="",i.innerHTML="",d.callToActionIconName){let X=parseFloat(b)||24,Z=Math.max(X-dt,8),Q=wt(d.callToActionIconName,Z,"currentColor",2);Q?i.appendChild(Q):i.textContent=(j=d.callToActionIconText)!=null?j:"\u2197"}else i.textContent=(Y=d.callToActionIconText)!=null?Y:"\u2197"}let u=d.position&&ke[d.position]?ke[d.position]:ke["bottom-right"],M="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";r.className=`${M} ${u}`},s=()=>{r.removeEventListener("click",t),r.remove()};return a&&e(a),{element:r,update:e,destroy:s}};var ra=a=>{var dt,X,Z,Q,ht,ot,z,_t,jt,se,Le,Te,U,mt,Ce,Se,Yt,de,L,Vt,fe,ue,Ee,Ae,Dt,le,Xt,$,ce,Qt,Pt,Gt;let{config:t,showClose:r=!0}=a,e=x("div","tvw-widget-header tvw-flex tvw-items-center tvw-gap-3 tvw-bg-cw-surface tvw-px-6 tvw-py-5 tvw-border-b-cw-divider"),s=(dt=t==null?void 0:t.launcher)!=null?dt:{},o=(X=s.headerIconSize)!=null?X:"48px",d=(Z=s.closeButtonSize)!=null?Z:"32px",l=(Q=s.closeButtonPlacement)!=null?Q:"inline",p=(ht=s.headerIconHidden)!=null?ht:!1,f=s.headerIconName,h=x("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=o,h.style.width=o,!p)if(f){let J=parseFloat(o)||24,kt=wt(f,J*.6,"#ffffff",2);kt?h.replaceChildren(kt):h.textContent=(z=(ot=t==null?void 0:t.launcher)==null?void 0:ot.agentIconText)!=null?z:"\u{1F4AC}"}else if((_t=t==null?void 0:t.launcher)!=null&&_t.iconUrl){let J=x("img");J.src=t.launcher.iconUrl,J.alt="",J.className="tvw-rounded-xl tvw-object-cover",J.style.height=o,J.style.width=o,h.replaceChildren(J)}else h.textContent=(se=(jt=t==null?void 0:t.launcher)==null?void 0:jt.agentIconText)!=null?se:"\u{1F4AC}";let c=x("div","tvw-flex tvw-flex-col"),i=x("span","tvw-text-base tvw-font-semibold");i.textContent=(Te=(Le=t==null?void 0:t.launcher)==null?void 0:Le.title)!=null?Te:"Chat Assistant";let u=x("span","tvw-text-xs tvw-text-cw-muted");u.textContent=(mt=(U=t==null?void 0:t.launcher)==null?void 0:U.subtitle)!=null?mt:"Here to help you get answers fast",c.append(i,u),p?e.append(c):e.append(h,c);let M=(Ce=s.clearChat)!=null?Ce:{},F=(Se=M.enabled)!=null?Se:!0,O=(Yt=M.placement)!=null?Yt:"inline",v=null,C=null;if(F){let J=(de=M.size)!=null?de:"32px",kt=(L=M.iconName)!=null?L:"refresh-cw",Rt=(Vt=M.iconColor)!=null?Vt:"",Jt=(fe=M.backgroundColor)!=null?fe:"",pe=(ue=M.borderWidth)!=null?ue:"",Be=(Ee=M.borderColor)!=null?Ee:"",Ie=(Ae=M.borderRadius)!=null?Ae:"",ye=(Dt=M.paddingX)!=null?Dt:"",Pe=(le=M.paddingY)!=null?le:"",it=(Xt=M.tooltipText)!=null?Xt:"Clear chat",oa=($=M.showTooltip)!=null?$:!0;C=x("div",O==="top-right"?"tvw-absolute tvw-top-4 tvw-z-50":"tvw-relative tvw-ml-auto tvw-clear-chat-button-wrapper"),O==="top-right"&&(C.style.right="48px"),v=x("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"),v.style.height=J,v.style.width=J,v.type="button",v.setAttribute("aria-label",it);let qe=wt(kt,"20px",Rt||"",2);if(qe&&v.appendChild(qe),Rt&&(v.style.color=Rt,v.classList.remove("tvw-text-cw-muted")),Jt&&(v.style.backgroundColor=Jt,v.classList.remove("hover:tvw-bg-gray-100")),pe||Be){let Ct=pe||"0px",be=Be||"transparent";v.style.border=`${Ct} solid ${be}`,v.classList.remove("tvw-border-none")}if(Ie&&(v.style.borderRadius=Ie,v.classList.remove("tvw-rounded-full")),ye?(v.style.paddingLeft=ye,v.style.paddingRight=ye):(v.style.paddingLeft="",v.style.paddingRight=""),Pe?(v.style.paddingTop=Pe,v.style.paddingBottom=Pe):(v.style.paddingTop="",v.style.paddingBottom=""),C.appendChild(v),oa&&it&&v&&C){let Ct=null,be=()=>{if(Ct||!v)return;Ct=x("div","tvw-clear-chat-tooltip"),Ct.textContent=it;let Ue=x("div");Ue.className="tvw-clear-chat-tooltip-arrow",Ct.appendChild(Ue);let He=v.getBoundingClientRect();Ct.style.position="fixed",Ct.style.left=`${He.left+He.width/2}px`,Ct.style.top=`${He.top-8}px`,Ct.style.transform="translate(-50%, -100%)",document.body.appendChild(Ct)},Ve=()=>{Ct&&Ct.parentNode&&(Ct.parentNode.removeChild(Ct),Ct=null)};C.addEventListener("mouseenter",be),C.addEventListener("mouseleave",Ve),v.addEventListener("focus",be),v.addEventListener("blur",Ve),C._cleanupTooltip=()=>{Ve(),C&&(C.removeEventListener("mouseenter",be),C.removeEventListener("mouseleave",Ve)),v&&(v.removeEventListener("focus",be),v.removeEventListener("blur",Ve))}}O==="inline"&&e.appendChild(C)}let E=x("div",l==="top-right"?"tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50":F&&O==="inline"?"":"tvw-ml-auto"),S=x("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");S.style.height=d,S.style.width=d,S.type="button";let G=(ce=s.closeButtonTooltipText)!=null?ce:"Close chat",W=(Qt=s.closeButtonShowTooltip)!=null?Qt:!0;S.setAttribute("aria-label",G),S.style.display=r?"":"none";let j=(Pt=s.closeButtonIconName)!=null?Pt:"x",Y=(Gt=s.closeButtonIconText)!=null?Gt:"\xD7",b=wt(j,"20px",s.closeButtonColor||"",2);if(b?S.appendChild(b):S.textContent=Y,s.closeButtonColor?(S.style.color=s.closeButtonColor,S.classList.remove("tvw-text-cw-muted")):(S.style.color="",S.classList.add("tvw-text-cw-muted")),s.closeButtonBackgroundColor?(S.style.backgroundColor=s.closeButtonBackgroundColor,S.classList.remove("hover:tvw-bg-gray-100")):(S.style.backgroundColor="",S.classList.add("hover:tvw-bg-gray-100")),s.closeButtonBorderWidth||s.closeButtonBorderColor){let J=s.closeButtonBorderWidth||"0px",kt=s.closeButtonBorderColor||"transparent";S.style.border=`${J} solid ${kt}`,S.classList.remove("tvw-border-none")}else S.style.border="",S.classList.add("tvw-border-none");if(s.closeButtonBorderRadius?(S.style.borderRadius=s.closeButtonBorderRadius,S.classList.remove("tvw-rounded-full")):(S.style.borderRadius="",S.classList.add("tvw-rounded-full")),s.closeButtonPaddingX?(S.style.paddingLeft=s.closeButtonPaddingX,S.style.paddingRight=s.closeButtonPaddingX):(S.style.paddingLeft="",S.style.paddingRight=""),s.closeButtonPaddingY?(S.style.paddingTop=s.closeButtonPaddingY,S.style.paddingBottom=s.closeButtonPaddingY):(S.style.paddingTop="",S.style.paddingBottom=""),E.appendChild(S),W&&G){let J=null,kt=()=>{if(J)return;J=x("div","tvw-clear-chat-tooltip"),J.textContent=G;let Jt=x("div");Jt.className="tvw-clear-chat-tooltip-arrow",J.appendChild(Jt);let pe=S.getBoundingClientRect();J.style.position="fixed",J.style.left=`${pe.left+pe.width/2}px`,J.style.top=`${pe.top-8}px`,J.style.transform="translate(-50%, -100%)",document.body.appendChild(J)},Rt=()=>{J&&J.parentNode&&(J.parentNode.removeChild(J),J=null)};E.addEventListener("mouseenter",kt),E.addEventListener("mouseleave",Rt),S.addEventListener("focus",kt),S.addEventListener("blur",Rt),E._cleanupTooltip=()=>{Rt(),E.removeEventListener("mouseenter",kt),E.removeEventListener("mouseleave",Rt),S.removeEventListener("focus",kt),S.removeEventListener("blur",Rt)}}return l!=="top-right"&&e.appendChild(E),{header:e,iconHolder:h,headerTitle:i,headerSubtitle:u,closeButton:S,closeButtonWrapper:E,clearChatButton:v,clearChatButtonWrapper:C}},L2=(a,t,r)=>{var d,l,p,f;let e=(d=r==null?void 0:r.launcher)!=null?d:{},s=(l=e.closeButtonPlacement)!=null?l:"inline",o=(f=(p=e.clearChat)==null?void 0:p.placement)!=null?f:"inline";a.appendChild(t.header),s==="top-right"&&(a.style.position="relative",a.appendChild(t.closeButtonWrapper)),t.clearChatButtonWrapper&&o==="top-right"&&(a.style.position="relative",a.appendChild(t.clearChatButtonWrapper))};var tA=a=>ra({config:a.config,showClose:a.showClose,onClose:a.onClose,onClearChat:a.onClearChat}),eA=a=>{var M,F,O,v;let{config:t,showClose:r=!0,onClose:e}=a,s=(M=t==null?void 0:t.launcher)!=null?M:{},o=x("div","tvw-flex tvw-items-center tvw-justify-between tvw-bg-cw-surface tvw-px-6 tvw-py-4 tvw-border-b-cw-divider"),d=x("span","tvw-text-base tvw-font-semibold");d.textContent=(F=s.title)!=null?F:"Chat Assistant",o.appendChild(d);let l=(O=s.closeButtonSize)!=null?O:"32px",p=x("div",""),f=x("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=l,f.style.width=l,f.type="button",f.setAttribute("aria-label","Close chat"),f.style.display=r?"":"none";let h=(v=s.closeButtonIconName)!=null?v:"x",c=wt(h,"20px",s.closeButtonColor||"",2);c?f.appendChild(c):f.textContent="\xD7",e&&f.addEventListener("click",e),p.appendChild(f),o.appendChild(p);let i=x("div");i.style.display="none";let u=x("span");return u.style.display="none",{header:o,iconHolder:i,headerTitle:d,headerSubtitle:u,closeButton:f,closeButtonWrapper:p,clearChatButton:null,clearChatButtonWrapper:null}},aA=a=>{var S,G,W,j,Y,b,dt,X;let{config:t,showClose:r=!0,onClose:e,onClearChat:s}=a,o=(S=t==null?void 0:t.launcher)!=null?S:{},d=x("div","tvw-flex tvw-flex-col tvw-bg-cw-surface tvw-px-6 tvw-py-5 tvw-border-b-cw-divider"),l=x("div","tvw-flex tvw-items-center tvw-gap-3"),p=(G=o.headerIconSize)!=null?G:"56px",f=x("div","tvw-flex tvw-items-center tvw-justify-center tvw-rounded-xl tvw-bg-cw-primary tvw-text-white tvw-text-2xl");f.style.height=p,f.style.width=p;let h=o.headerIconName;if(h){let Z=parseFloat(p)||24,Q=wt(h,Z*.5,"#ffffff",2);Q?f.replaceChildren(Q):f.textContent=(W=o.agentIconText)!=null?W:"\u{1F4AC}"}else if(o.iconUrl){let Z=x("img");Z.src=o.iconUrl,Z.alt="",Z.className="tvw-rounded-xl tvw-object-cover",Z.style.height=p,Z.style.width=p,f.replaceChildren(Z)}else f.textContent=(j=o.agentIconText)!=null?j:"\u{1F4AC}";let c=x("div","tvw-flex tvw-flex-col tvw-flex-1"),i=x("span","tvw-text-lg tvw-font-semibold");i.textContent=(Y=o.title)!=null?Y:"Chat Assistant";let u=x("span","tvw-text-sm tvw-text-cw-muted");u.textContent=(b=o.subtitle)!=null?b:"Here to help you get answers fast",c.append(i,u),l.append(f,c);let M=(dt=o.closeButtonSize)!=null?dt:"32px",F=x("div",""),O=x("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");O.style.height=M,O.style.width=M,O.type="button",O.setAttribute("aria-label","Close chat"),O.style.display=r?"":"none";let v=(X=o.closeButtonIconName)!=null?X:"x",C=wt(v,"20px",o.closeButtonColor||"",2);C?O.appendChild(C):O.textContent="\xD7",e&&O.addEventListener("click",e),F.appendChild(O),l.appendChild(F),d.appendChild(l);let E=x("div","tvw-mt-3 tvw-pt-3 tvw-border-t tvw-border-gray-100 tvw-text-xs tvw-text-cw-muted");return E.textContent="Online and ready to help",d.appendChild(E),{header:d,iconHolder:f,headerTitle:i,headerSubtitle:u,closeButton:O,closeButtonWrapper:F,clearChatButton:null,clearChatButtonWrapper:null}},AS={default:tA,minimal:eA,expanded:aA},rA=a=>{var t;return(t=AS[a])!=null?t:AS.default},bS=(a,t,r)=>{var d,l,p;if(t!=null&&t.render){let f=t.render({config:a,onClose:r==null?void 0:r.onClose,onClearChat:r==null?void 0:r.onClearChat}),h=x("div");h.style.display="none";let c=x("span"),i=x("span"),u=x("button");u.style.display="none";let M=x("div");return M.style.display="none",{header:f,iconHolder:h,headerTitle:c,headerSubtitle:i,closeButton:u,closeButtonWrapper:M,clearChatButton:null,clearChatButtonWrapper:null}}let e=(d=t==null?void 0:t.layout)!=null?d:"default",o=rA(e)({config:a,showClose:(p=(l=t==null?void 0:t.showCloseButton)!=null?l:r==null?void 0:r.showClose)!=null?p:!0,onClose:r==null?void 0:r.onClose,onClearChat:r==null?void 0:r.onClearChat});return t&&(t.showIcon===!1&&(o.iconHolder.style.display="none"),t.showTitle===!1&&(o.headerTitle.style.display="none"),t.showSubtitle===!1&&(o.headerSubtitle.style.display="none"),t.showCloseButton===!1&&(o.closeButton.style.display="none"),t.showClearChat===!1&&o.clearChatButtonWrapper&&(o.clearChatButtonWrapper.style.display="none")),o};var ck=a=>{switch(a){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'}},T2=a=>{var ot,z,_t,jt,se,Le,Te,U,mt,Ce,Se,Yt,de,L,Vt,fe,ue,Ee,Ae,Dt,le,Xt,$,ce,Qt;let{config:t}=a,r=x("div","tvw-widget-footer tvw-border-t-cw-divider tvw-bg-cw-surface tvw-px-6 tvw-py-4"),e=x("div","tvw-mb-3 tvw-flex tvw-flex-wrap tvw-gap-2"),s=((ot=t==null?void 0:t.voiceRecognition)==null?void 0:ot.enabled)===!0,o=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),p=x("form",`tvw-widget-composer tvw-flex tvw-items-end ${s&&o?"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`);p.style.outline="none";let f=x("textarea");f.placeholder=(_t=(z=t==null?void 0:t.copy)==null?void 0:z.inputPlaceholder)!=null?_t:"Type your message\u2026",f.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",f.rows=1;let h=(se=(jt=t==null?void 0:t.theme)==null?void 0:jt.inputFontFamily)!=null?se:"sans-serif",c=(Te=(Le=t==null?void 0:t.theme)==null?void 0:Le.inputFontWeight)!=null?Te:"400";f.style.fontFamily=ck(h),f.style.fontWeight=c,f.style.border="none",f.style.outline="none",f.style.borderWidth="0",f.style.borderStyle="none",f.style.borderColor="transparent",f.addEventListener("focus",()=>{f.style.border="none",f.style.outline="none",f.style.borderWidth="0",f.style.borderStyle="none",f.style.borderColor="transparent",f.style.boxShadow="none"}),f.addEventListener("blur",()=>{f.style.border="none",f.style.outline="none"});let i=(U=t==null?void 0:t.sendButton)!=null?U:{},u=(mt=i.useIcon)!=null?mt:!1,M=(Ce=i.iconText)!=null?Ce:"\u2191",F=i.iconName,O=(Se=i.tooltipText)!=null?Se:"Send message",v=(Yt=i.showTooltip)!=null?Yt:!1,C=(de=i.size)!=null?de:"40px",E=i.backgroundColor,S=i.textColor,G=x("div","tvw-send-button-wrapper"),W=x("button",u?"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(W.type="submit",u){if(W.style.width=C,W.style.height=C,W.style.minWidth=C,W.style.minHeight=C,W.style.fontSize="18px",W.style.lineHeight="1",W.innerHTML="",F){let Pt=parseFloat(C)||24,Gt=S&&typeof S=="string"&&S.trim()?S.trim():"currentColor",J=wt(F,Pt,Gt,2);J?(W.appendChild(J),W.style.color=Gt):(W.textContent=M,S?W.style.color=S:W.classList.add("tvw-text-white"))}else W.textContent=M,S?W.style.color=S:W.classList.add("tvw-text-white");E?W.style.backgroundColor=E:W.classList.add("tvw-bg-cw-primary")}else W.textContent=(Vt=(L=t==null?void 0:t.copy)==null?void 0:L.sendButtonLabel)!=null?Vt:"Send",S?W.style.color=S:W.classList.add("tvw-text-white");if(i.borderWidth&&(W.style.borderWidth=i.borderWidth,W.style.borderStyle="solid"),i.borderColor&&(W.style.borderColor=i.borderColor),i.paddingX?(W.style.paddingLeft=i.paddingX,W.style.paddingRight=i.paddingX):(W.style.paddingLeft="",W.style.paddingRight=""),i.paddingY?(W.style.paddingTop=i.paddingY,W.style.paddingBottom=i.paddingY):(W.style.paddingTop="",W.style.paddingBottom=""),v&&O){let Pt=x("div","tvw-send-button-tooltip");Pt.textContent=O,G.appendChild(Pt)}G.appendChild(W);let j=(fe=t==null?void 0:t.voiceRecognition)!=null?fe:{},Y=j.enabled===!0,b=null,dt=null,X=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined");if(Y&&X){dt=x("div","tvw-send-button-wrapper"),b=x("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer"),b.type="button",b.setAttribute("aria-label","Start voice recognition");let Pt=(ue=j.iconName)!=null?ue:"mic",Gt=(Ee=j.iconSize)!=null?Ee:C,J=parseFloat(Gt)||24,kt=(Ae=j.backgroundColor)!=null?Ae:E,Rt=(Dt=j.iconColor)!=null?Dt:S;b.style.width=Gt,b.style.height=Gt,b.style.minWidth=Gt,b.style.minHeight=Gt,b.style.fontSize="18px",b.style.lineHeight="1";let Jt=Rt||"currentColor",pe=wt(Pt,J,Jt,1.5);pe?(b.appendChild(pe),b.style.color=Jt):(b.textContent="\u{1F3A4}",b.style.color=Jt),kt?b.style.backgroundColor=kt:b.classList.add("tvw-bg-cw-primary"),Rt?b.style.color=Rt:!Rt&&!S&&b.classList.add("tvw-text-white"),j.borderWidth&&(b.style.borderWidth=j.borderWidth,b.style.borderStyle="solid"),j.borderColor&&(b.style.borderColor=j.borderColor),j.paddingX&&(b.style.paddingLeft=j.paddingX,b.style.paddingRight=j.paddingX),j.paddingY&&(b.style.paddingTop=j.paddingY,b.style.paddingBottom=j.paddingY),dt.appendChild(b);let Be=(le=j.tooltipText)!=null?le:"Start voice recognition";if(((Xt=j.showTooltip)!=null?Xt:!1)&&Be){let ye=x("div","tvw-send-button-tooltip");ye.textContent=Be,dt.appendChild(ye)}}p.addEventListener("click",Pt=>{Pt.target!==W&&Pt.target!==G&&Pt.target!==b&&Pt.target!==dt&&f.focus()}),p.append(f),dt&&p.append(dt),p.append(G);let Z=x("div","tvw-mt-2 tvw-text-right tvw-text-xs tvw-text-cw-muted"),Q=($=t==null?void 0:t.statusIndicator)!=null?$:{},ht=(ce=Q.visible)!=null?ce:!0;return Z.style.display=ht?"":"none",Z.textContent=(Qt=Q.idleText)!=null?Qt:"Online",r.append(e,p,Z),{footer:r,suggestions:e,composerForm:p,textarea:f,sendButton:W,sendButtonWrapper:G,micButton:b,micButtonWrapper:dt,statusText:Z}};var Kb=a=>{var p,f,h,c,i;if(!((f=(p=a==null?void 0:a.launcher)==null?void 0:p.enabled)!=null?f:!0)){let u=x("div","tvw-relative tvw-w-full tvw-h-full tvw-flex tvw-flex-col tvw-flex-1 tvw-min-h-0"),M=x("div","tvw-relative tvw-w-full tvw-flex-1 tvw-flex tvw-flex-col tvw-min-h-0");return u.appendChild(M),{wrapper:u,panel:M}}let r=(h=a==null?void 0:a.launcher)!=null?h:{},e=r.position&&ke[r.position]?ke[r.position]:ke["bottom-right"],s=x("div",`tvw-widget-wrapper tvw-fixed ${e} tvw-z-50 tvw-transition`),o=x("div","tvw-widget-panel tvw-relative tvw-min-h-[320px]"),d=(i=(c=a==null?void 0:a.launcher)==null?void 0:c.width)!=null?i:a==null?void 0:a.launcherWidth,l=d!=null?d:"min(400px, calc(100vw - 24px))";return o.style.width=l,o.style.maxWidth=l,s.appendChild(o),{wrapper:s,panel:o}},jb=(a,t=!0)=>{var c,i,u,M,F;let r=x("div","tvw-widget-container tvw-flex tvw-h-full tvw-w-full tvw-flex-1 tvw-min-h-0 tvw-flex-col tvw-bg-cw-surface tvw-text-cw-primary tvw-rounded-2xl tvw-overflow-hidden tvw-border tvw-border-cw-border"),e=(c=a==null?void 0:a.layout)==null?void 0:c.header,s=e?bS(a,e,{showClose:t}):ra({config:a,showClose:t}),o=x("div","tvw-widget-body 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");o.id="vanilla-agent-scroll-container";let d=x("div","tvw-rounded-2xl tvw-bg-cw-surface tvw-p-6 tvw-shadow-sm"),l=x("h2","tvw-text-lg tvw-font-semibold tvw-text-cw-primary");l.textContent=(u=(i=a==null?void 0:a.copy)==null?void 0:i.welcomeTitle)!=null?u:"Hello \u{1F44B}";let p=x("p","tvw-mt-2 tvw-text-sm tvw-text-cw-muted");p.textContent=(F=(M=a==null?void 0:a.copy)==null?void 0:M.welcomeSubtitle)!=null?F:"Ask anything about your account or products.",d.append(l,p);let f=x("div","tvw-flex tvw-flex-col tvw-gap-3");o.append(d,f);let h=T2({config:a});return L2(r,s,a),r.append(o,h.footer),{container:r,body:o,messagesWrapper:f,suggestions:h.suggestions,textarea:h.textarea,sendButton:h.sendButton,sendButtonWrapper:h.sendButtonWrapper,micButton:h.micButton,micButtonWrapper:h.micButtonWrapper,composerForm:h.composerForm,statusText:h.statusText,introTitle:l,introSubtitle:p,closeButton:s.closeButton,closeButtonWrapper:s.closeButtonWrapper,clearChatButton:s.clearChatButton,clearChatButtonWrapper:s.clearChatButtonWrapper,iconHolder:s.iconHolder,headerTitle:s.headerTitle,headerSubtitle:s.headerSubtitle,header:s.header,footer:h.footer}};var Z2=()=>{let a=document.createElement("div");a.className="tvw-flex tvw-items-center tvw-space-x-1 tvw-h-5 tvw-mt-2";let t=document.createElement("div");t.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",t.style.animationDelay="0ms";let r=document.createElement("div");r.className="tvw-bg-cw-primary tvw-animate-typing tvw-rounded-full tvw-h-1.5 tvw-w-1.5",r.style.animationDelay="250ms";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="500ms";let s=document.createElement("span");return s.className="tvw-sr-only",s.textContent="Loading",a.appendChild(t),a.appendChild(r),a.appendChild(e),a.appendChild(s),a},xk=(a,t)=>{let r=x("div","tvw-flex-shrink-0 tvw-w-8 tvw-h-8 tvw-rounded-full tvw-flex tvw-items-center tvw-justify-center tvw-text-sm"),e=t==="user"?a.userAvatar:a.assistantAvatar;if(e)if(e.startsWith("http")||e.startsWith("/")||e.startsWith("data:")){let s=x("img");s.src=e,s.alt=t==="user"?"User":"Assistant",s.className="tvw-w-full tvw-h-full tvw-rounded-full tvw-object-cover",r.appendChild(s)}else r.textContent=e,r.classList.add(t==="user"?"tvw-bg-cw-accent":"tvw-bg-cw-primary","tvw-text-white");else r.textContent=t==="user"?"U":"A",r.classList.add(t==="user"?"tvw-bg-cw-accent":"tvw-bg-cw-primary","tvw-text-white");return r},Yb=(a,t)=>{let r=x("div","tvw-text-xs tvw-text-cw-muted"),e=new Date(a.createdAt);return t.format?r.textContent=t.format(e):r.textContent=e.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}),r},mk=(a,t="bubble")=>{let r=["vanilla-message-bubble","tvw-max-w-[85%]"];switch(t){case"flat":a==="user"?r.push("vanilla-message-user-bubble","tvw-ml-auto","tvw-text-cw-primary","tvw-py-2"):r.push("vanilla-message-assistant-bubble","tvw-text-cw-primary","tvw-py-2");break;case"minimal":r.push("tvw-text-sm","tvw-leading-relaxed"),a==="user"?r.push("vanilla-message-user-bubble","tvw-ml-auto","tvw-bg-cw-accent","tvw-text-white","tvw-px-3","tvw-py-2","tvw-rounded-lg"):r.push("vanilla-message-assistant-bubble","tvw-bg-cw-surface","tvw-text-cw-primary","tvw-px-3","tvw-py-2","tvw-rounded-lg");break;case"bubble":default:r.push("tvw-rounded-2xl","tvw-text-sm","tvw-leading-relaxed","tvw-shadow-sm"),a==="user"?r.push("vanilla-message-user-bubble","tvw-ml-auto","tvw-bg-cw-accent","tvw-text-white","tvw-px-5","tvw-py-3"):r.push("vanilla-message-assistant-bubble","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-text-cw-primary","tvw-px-5","tvw-py-3");break}return r},B2=(a,t,r)=>{var O,v,C,E,S;let e=r!=null?r:{},s=(O=e.layout)!=null?O:"bubble",o=e.avatar,d=e.timestamp,l=(v=o==null?void 0:o.show)!=null?v:!1,p=(C=d==null?void 0:d.show)!=null?C:!1,f=(E=o==null?void 0:o.position)!=null?E:"left",h=(S=d==null?void 0:d.position)!=null?S:"below",c=mk(a.role,s),i=x("div",c.join(" ")),u=document.createElement("div");if(u.innerHTML=t({text:a.content,message:a,streaming:!!a.streaming,raw:a.rawContent}),p&&h==="inline"&&a.createdAt){let G=Yb(a,d);G.classList.add("tvw-ml-2","tvw-inline"),u.appendChild(G)}if(i.appendChild(u),p&&h==="below"&&a.createdAt){let G=Yb(a,d);G.classList.add("tvw-mt-1"),i.appendChild(G)}if(a.streaming&&a.role==="assistant"&&(!a.content||!a.content.trim())){let G=Z2();i.appendChild(G)}if(!l||a.role==="system")return i;let M=x("div",`tvw-flex tvw-gap-2 ${a.role==="user"?"tvw-flex-row-reverse":""}`),F=xk(o,a.role);return f==="right"||f==="left"&&a.role==="user"?M.append(i,F):M.append(F,i),i.classList.remove("tvw-max-w-[85%]"),i.classList.add("tvw-max-w-[calc(85%-2.5rem)]"),M},Qb=(a,t,r)=>{let e=r!=null?r:{};return a.role==="user"&&e.renderUserMessage?e.renderUserMessage({message:a,config:{},streaming:!!a.streaming}):a.role==="assistant"&&e.renderAssistantMessage?e.renderAssistantMessage({message:a,config:{},streaming:!!a.streaming}):B2(a,t,r)};var oA=new Set,sA=a=>{let t=a.reasoning,r=x("div",["vanilla-message-bubble","vanilla-reasoning-bubble","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(!t)return r;let e=oA.has(a.id),s=x("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");s.type="button",s.setAttribute("aria-expanded",e?"true":"false");let o=x("div","tvw-flex tvw-flex-col tvw-text-left"),d=x("span","tvw-text-xs tvw-text-cw-primary");d.textContent="Thinking...",o.appendChild(d);let l=x("span","tvw-text-xs tvw-text-cw-primary");l.textContent=Gb(t),o.appendChild(l),t.status==="complete"?d.style.display="none":d.style.display="";let p=x("div","tvw-flex tvw-items-center"),h=wt(e?"chevron-up":"chevron-down",16,"currentColor",2);h?p.appendChild(h):p.textContent=e?"Hide":"Show";let c=x("div","tvw-flex tvw-items-center tvw-ml-auto");c.append(p),s.append(o,c);let i=x("div","tvw-border-t tvw-border-gray-200 tvw-bg-gray-50 tvw-px-4 tvw-py-3");i.style.display=e?"":"none";let u=t.chunks.join(""),M=x("div","tvw-whitespace-pre-wrap tvw-text-xs tvw-leading-snug tvw-text-cw-muted");M.textContent=u||(t.status==="complete"?"No additional context was shared.":"Waiting for details\u2026"),i.appendChild(M);let F=()=>{s.setAttribute("aria-expanded",e?"true":"false"),p.innerHTML="";let C=wt(e?"chevron-up":"chevron-down",16,"currentColor",2);C?p.appendChild(C):p.textContent=e?"Hide":"Show",i.style.display=e?"":"none"},O=()=>{e=!e,e?oA.add(a.id):oA.delete(a.id),F()};return s.addEventListener("pointerdown",v=>{v.preventDefault(),O()}),s.addEventListener("keydown",v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),O())}),F(),r.append(s,i),r};var dA=new Set,lA=(a,t)=>{var O;let r=a.toolCall,e=(O=t==null?void 0:t.toolCall)!=null?O:{},s=x("div",["vanilla-message-bubble","vanilla-tool-bubble","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(e.backgroundColor&&(s.style.backgroundColor=e.backgroundColor),e.borderColor&&(s.style.borderColor=e.borderColor),e.borderWidth&&(s.style.borderWidth=e.borderWidth),e.borderRadius&&(s.style.borderRadius=e.borderRadius),!r)return s;let o=dA.has(a.id),d=x("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");d.type="button",d.setAttribute("aria-expanded",o?"true":"false"),e.headerBackgroundColor&&(d.style.backgroundColor=e.headerBackgroundColor),e.headerPaddingX&&(d.style.paddingLeft=e.headerPaddingX,d.style.paddingRight=e.headerPaddingX),e.headerPaddingY&&(d.style.paddingTop=e.headerPaddingY,d.style.paddingBottom=e.headerPaddingY);let l=x("div","tvw-flex tvw-flex-col tvw-text-left"),p=x("span","tvw-text-xs tvw-text-cw-primary");e.headerTextColor&&(p.style.color=e.headerTextColor),p.textContent=Zb(r),l.appendChild(p);let f=x("div","tvw-flex tvw-items-center"),h=e.toggleTextColor||e.headerTextColor||"currentColor",c=wt(o?"chevron-up":"chevron-down",16,h,2);c?f.appendChild(c):f.textContent=o?"Hide":"Show";let i=x("div","tvw-flex tvw-items-center tvw-gap-2 tvw-ml-auto");i.append(f),d.append(l,i);let u=x("div","tvw-border-t tvw-border-gray-200 tvw-bg-gray-50 tvw-space-y-3 tvw-px-4 tvw-py-3");if(u.style.display=o?"":"none",e.contentBackgroundColor&&(u.style.backgroundColor=e.contentBackgroundColor),e.contentTextColor&&(u.style.color=e.contentTextColor),e.contentPaddingX&&(u.style.paddingLeft=e.contentPaddingX,u.style.paddingRight=e.contentPaddingX),e.contentPaddingY&&(u.style.paddingTop=e.contentPaddingY,u.style.paddingBottom=e.contentPaddingY),r.name){let v=x("div","tvw-text-xs tvw-text-cw-muted tvw-italic");e.contentTextColor?v.style.color=e.contentTextColor:e.headerTextColor&&(v.style.color=e.headerTextColor),v.textContent=r.name,u.appendChild(v)}if(r.args!==void 0){let v=x("div","tvw-space-y-1"),C=x("div","tvw-text-xs tvw-text-cw-muted");e.labelTextColor&&(C.style.color=e.labelTextColor),C.textContent="Arguments";let E=x("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");E.style.fontSize="0.75rem",E.style.lineHeight="1rem",e.codeBlockBackgroundColor&&(E.style.backgroundColor=e.codeBlockBackgroundColor),e.codeBlockBorderColor&&(E.style.borderColor=e.codeBlockBorderColor),e.codeBlockTextColor&&(E.style.color=e.codeBlockTextColor),E.textContent=JS(r.args),v.append(C,E),u.appendChild(v)}if(r.chunks&&r.chunks.length){let v=x("div","tvw-space-y-1"),C=x("div","tvw-text-xs tvw-text-cw-muted");e.labelTextColor&&(C.style.color=e.labelTextColor),C.textContent="Activity";let E=x("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");E.style.fontSize="0.75rem",E.style.lineHeight="1rem",e.codeBlockBackgroundColor&&(E.style.backgroundColor=e.codeBlockBackgroundColor),e.codeBlockBorderColor&&(E.style.borderColor=e.codeBlockBorderColor),e.codeBlockTextColor&&(E.style.color=e.codeBlockTextColor),E.textContent=r.chunks.join(`
|
|
65
|
-
`),v.append(C,E),u.appendChild(v)}if(r.status==="complete"&&r.result!==void 0){let v=x("div","tvw-space-y-1"),C=x("div","tvw-text-xs tvw-text-cw-muted");e.labelTextColor&&(C.style.color=e.labelTextColor),C.textContent="Result";let E=x("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");E.style.fontSize="0.75rem",E.style.lineHeight="1rem",e.codeBlockBackgroundColor&&(E.style.backgroundColor=e.codeBlockBackgroundColor),e.codeBlockBorderColor&&(E.style.borderColor=e.codeBlockBorderColor),e.codeBlockTextColor&&(E.style.color=e.codeBlockTextColor),E.textContent=JS(r.result),v.append(C,E),u.appendChild(v)}if(r.status==="complete"&&typeof r.duration=="number"){let v=x("div","tvw-text-xs tvw-text-cw-muted");e.contentTextColor&&(v.style.color=e.contentTextColor),v.textContent=`Duration: ${r.duration}ms`,u.appendChild(v)}let M=()=>{d.setAttribute("aria-expanded",o?"true":"false"),f.innerHTML="";let v=e.toggleTextColor||e.headerTextColor||"currentColor",C=wt(o?"chevron-up":"chevron-down",16,v,2);C?f.appendChild(C):f.textContent=o?"Hide":"Show",u.style.display=o?"":"none"},F=()=>{o=!o,o?dA.add(a.id):dA.delete(a.id),M()};return d.addEventListener("pointerdown",v=>{v.preventDefault(),F()}),d.addEventListener("keydown",v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),F())}),M(),s.append(d,u),s};var tH=a=>{let t=[];return{buttons:t,render:(e,s,o,d,l)=>{if(a.innerHTML="",t.length=0,!e||!e.length||(d!=null?d:s?s.getMessages():[]).some(u=>u.role==="user"))return;let h=document.createDocumentFragment(),c=s?s.isStreaming():!1,i=u=>{switch(u){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'}};e.forEach(u=>{let M=x("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=u,M.disabled=c,l!=null&&l.fontFamily&&(M.style.fontFamily=i(l.fontFamily)),l!=null&&l.fontWeight&&(M.style.fontWeight=l.fontWeight),l!=null&&l.paddingX&&(M.style.paddingLeft=l.paddingX,M.style.paddingRight=l.paddingX),l!=null&&l.paddingY&&(M.style.paddingTop=l.paddingY,M.style.paddingBottom=l.paddingY),M.addEventListener("click",()=>{!s||s.isStreaming()||(o.value="",s.sendMessage(u))}),h.appendChild(M),t.push(M)}),a.appendChild(h)}}};var eH={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"}},pA=(a,t,r,e)=>{let s=a.querySelectorAll("[data-tv-form]");s.length&&s.forEach(o=>{var M,F,O;if(o.dataset.enhanced==="true")return;let d=(M=o.dataset.tvForm)!=null?M:"init";o.dataset.enhanced="true";let l=(F=eH[d])!=null?F:eH.init;o.classList.add("tvw-form-card","tvw-space-y-4");let p=x("div","tvw-space-y-1"),f=x("h3","tvw-text-base tvw-font-semibold tvw-text-cw-primary");if(f.textContent=l.title,p.appendChild(f),l.description){let v=x("p","tvw-text-sm tvw-text-cw-muted");v.textContent=l.description,p.appendChild(v)}let h=document.createElement("form");h.className="tvw-form-grid tvw-space-y-3",l.fields.forEach(v=>{var W,j;let C=x("label","tvw-form-field tvw-flex tvw-flex-col tvw-gap-1");C.htmlFor=`${t.id}-${d}-${v.name}`;let E=x("span","tvw-text-xs tvw-font-medium tvw-text-cw-muted");E.textContent=v.label,C.appendChild(E);let S=(W=v.type)!=null?W:"text",G;S==="textarea"?(G=document.createElement("textarea"),G.rows=3):(G=document.createElement("input"),G.type=S),G.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",G.id=`${t.id}-${d}-${v.name}`,G.name=v.name,G.placeholder=(j=v.placeholder)!=null?j:"",v.required&&(G.required=!0),C.appendChild(G),h.appendChild(C)});let c=x("div","tvw-flex tvw-items-center tvw-justify-between tvw-gap-2"),i=x("div","tvw-text-xs tvw-text-cw-muted tvw-min-h-[1.5rem]"),u=x("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");u.type="submit",u.textContent=(O=l.submitLabel)!=null?O:"Submit",c.appendChild(i),c.appendChild(u),h.appendChild(c),o.replaceChildren(p,h),h.addEventListener("submit",async v=>{var G,W;v.preventDefault();let C=(G=r.formEndpoint)!=null?G:"/form",E=new FormData(h),S={};E.forEach((j,Y)=>{S[Y]=j}),S.type=d,u.disabled=!0,i.textContent="Submitting\u2026";try{let j=await fetch(C,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(S)});if(!j.ok)throw new Error(`Form submission failed (${j.status})`);let Y=await j.json();i.textContent=(W=Y.message)!=null?W:"Thanks! We'll be in touch soon.",Y.success&&Y.nextPrompt&&await e.sendMessage(String(Y.nextPrompt))}catch(j){i.textContent=j instanceof Error?j.message:"Something went wrong. Please try again."}finally{u.disabled=!1}})})};var nA=class{constructor(){this.plugins=new Map}register(t){var r;this.plugins.has(t.id)&&console.warn(`Plugin "${t.id}" is already registered. Overwriting.`),this.plugins.set(t.id,t),(r=t.onRegister)==null||r.call(t)}unregister(t){var e;let r=this.plugins.get(t);r&&((e=r.onUnregister)==null||e.call(r),this.plugins.delete(t))}getAll(){return Array.from(this.plugins.values()).sort((t,r)=>{var e,s;return((e=r.priority)!=null?e:0)-((s=t.priority)!=null?s:0)})}getForInstance(t){let r=this.getAll();if(!t||t.length===0)return r;let e=new Set(t.map(o=>o.id));return[...r.filter(o=>!e.has(o.id)),...t].sort((o,d)=>{var l,p;return((l=d.priority)!=null?l:0)-((p=o.priority)!=null?p:0)})}clear(){this.plugins.forEach(t=>{var r;return(r=t.onUnregister)==null?void 0:r.call(t)}),this.plugins.clear()}},_2=new nA;var It={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,placement:"inline",iconName:"refresh-cw",size:"32px",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?"],suggestionChipsConfig:{fontFamily:"sans-serif",fontWeight:"500",paddingX:"12px",paddingY:"6px"},layout:{header:{layout:"default",showIcon:!0,showTitle:!0,showSubtitle:!0,showCloseButton:!0,showClearChat:!0},messages:{layout:"bubble",avatar:{show:!1,position:"left"},timestamp:{show:!1,position:"below"},groupConsecutive:!1},slots:{}},debug:!1};function HS(a){var t,r,e,s,o,d,l,p,f,h,c,i,u,M,F,O,v;return a?{...It,...a,theme:{...It.theme,...a.theme},launcher:{...It.launcher,...a.launcher,clearChat:{...(t=It.launcher)==null?void 0:t.clearChat,...(r=a.launcher)==null?void 0:r.clearChat}},copy:{...It.copy,...a.copy},sendButton:{...It.sendButton,...a.sendButton},statusIndicator:{...It.statusIndicator,...a.statusIndicator},voiceRecognition:{...It.voiceRecognition,...a.voiceRecognition},features:{...It.features,...a.features},suggestionChips:(e=a.suggestionChips)!=null?e:It.suggestionChips,suggestionChipsConfig:{...It.suggestionChipsConfig,...a.suggestionChipsConfig},layout:{...It.layout,...a.layout,header:{...(s=It.layout)==null?void 0:s.header,...(o=a.layout)==null?void 0:o.header},messages:{...(d=It.layout)==null?void 0:d.messages,...(l=a.layout)==null?void 0:l.messages,avatar:{...(f=(p=It.layout)==null?void 0:p.messages)==null?void 0:f.avatar,...(c=(h=a.layout)==null?void 0:h.messages)==null?void 0:c.avatar},timestamp:{...(u=(i=It.layout)==null?void 0:i.messages)==null?void 0:u.timestamp,...(F=(M=a.layout)==null?void 0:M.messages)==null?void 0:F.timestamp}},slots:{...(O=It.layout)==null?void 0:O.slots,...(v=a.layout)==null?void 0:v.slots}}}:It}var aH=()=>{let a=new Map,t=(s,o)=>(a.has(s)||a.set(s,new Set),a.get(s).add(o),()=>r(s,o)),r=(s,o)=>{var d;(d=a.get(s))==null||d.delete(o)};return{on:t,off:r,emit:(s,o)=>{var d;(d=a.get(s))==null||d.forEach(l=>{try{l(o)}catch(p){typeof console!="undefined"&&console.error("[AgentWidget] Event handler error:",p)}})}}};var Mk=a=>{let t=a.match(/```(?:json)?\s*([\s\S]*?)```/i);return t?t[1]:a},gk=a=>{let t=a.trim(),r=t.indexOf("{");if(r===-1)return null;let e=0;for(let s=r;s<t.length;s+=1){let o=t[s];if(o==="{"&&(e+=1),o==="}"&&(e-=1,e===0))return t.slice(r,s+1)}return null},X2=({text:a})=>{if(!a||!a.includes("{"))return null;try{let t=Mk(a),r=gk(t);if(!r)return null;let e=JSON.parse(r);if(!e||typeof e!="object"||!e.action)return null;let{action:s,...o}=e;return{type:String(s),payload:o,raw:e}}catch{return null}},hA=a=>typeof a=="string"?a:a==null?"":String(a),xa={message:a=>a.type!=="message"?void 0:{handled:!0,displayText:hA(a.payload.text)},messageAndClick:(a,t)=>{var s;if(a.type!=="message_and_click")return;let r=a.payload,e=hA(r.element);if(e&&((s=t.document)!=null&&s.querySelector)){let o=t.document.querySelector(e);o?setTimeout(()=>{o.click()},400):typeof console!="undefined"&&console.warn("[AgentWidget] Element not found for selector:",e)}return{handled:!0,displayText:hA(r.text)}}},rH=a=>Array.isArray(a)?a.map(t=>String(t)):[],J2=a=>{let t=new Set(rH(a.getMetadata().processedActionMessageIds)),r=()=>{t=new Set(rH(a.getMetadata().processedActionMessageIds))},e=()=>{let o=Array.from(t);a.updateMetadata(d=>({...d,processedActionMessageIds:o}))};return{process:o=>{if(o.streaming||o.message.role!=="assistant"||!o.text||t.has(o.message.id))return null;let d=typeof o.raw=="string"&&o.raw||typeof o.message.rawContent=="string"&&o.message.rawContent||typeof o.text=="string"&&o.text||null;!d&&typeof o.text=="string"&&o.text.trim().startsWith("{")&&typeof console!="undefined"&&console.warn("[AgentWidget] Structured response detected but no raw payload was provided. Ensure your stream parser returns { text, raw }.");let l=d?a.parsers.reduce((f,h)=>f||(h==null?void 0:h({text:d,message:o.message}))||null,null):null;if(!l)return null;t.add(o.message.id),e();let p={action:l,message:o.message};a.emit("action:detected",p);for(let f of a.handlers)if(f)try{let h=f(l,{message:o.message,metadata:a.getMetadata(),updateMetadata:a.updateMetadata,document:a.documentRef});if(!h)continue;if(h.handled){let c=h.persistMessage!==!1;return{text:h.displayText!==void 0?h.displayText:"",persist:c}}}catch(h){typeof console!="undefined"&&console.error("[AgentWidget] Action handler error:",h)}return{text:"",persist:!0}},syncFromMetadata:r}};var vk=a=>{if(!a)return null;try{return JSON.parse(a)}catch(t){return typeof console!="undefined"&&console.error("[AgentWidget] Failed to parse stored state:",t),null}},yk=a=>a.map(t=>({...t,streaming:!1})),kS=(a="vanilla-agent-state")=>{let t=()=>typeof window=="undefined"||!window.localStorage?null:window.localStorage;return{load:()=>{let r=t();return r?vk(r.getItem(a)):null},save:r=>{let e=t();if(e)try{let s={...r,messages:r.messages?yk(r.messages):void 0};e.setItem(a,JSON.stringify(s))}catch(s){typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",s)}},clear:()=>{let r=t();if(r)try{r.removeItem(a)}catch(e){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear stored state:",e)}}}};var iA=class{constructor(){this.components=new Map}register(t,r){this.components.has(t)&&console.warn(`[ComponentRegistry] Component "${t}" is already registered. Overwriting.`),this.components.set(t,r)}unregister(t){this.components.delete(t)}get(t){return this.components.get(t)}has(t){return this.components.has(t)}getAllNames(){return Array.from(this.components.keys())}clear(){this.components.clear()}registerAll(t){Object.entries(t).forEach(([r,e])=>{this.register(r,e)})}},P2=new iA;var V2=Ab(XS(),1);function wk(a){if(!a||typeof a!="object"||!("component"in a))return!1;let t=a.component;return typeof t=="string"&&t.length>0}function Ck(a,t){if(!wk(a))return null;let r=a.props&&typeof a.props=="object"&&a.props!==null?a.props:{};return{component:a.component,props:r,raw:t}}function LS(){let a=null,t=0;return{getExtractedDirective:()=>a,processChunk:r=>{let e=r.trim();if(!e.startsWith("{")&&!e.startsWith("["))return null;if(r.length<=t)return a;try{let s=(0,V2.parse)(r,V2.STR|V2.OBJ),o=Ck(s,r);o&&(a=o)}catch{}return t=r.length,a},reset:()=>{a=null,t=0}}}function oH(a){return typeof a=="object"&&a!==null&&"component"in a&&typeof a.component=="string"&&"props"in a&&typeof a.props=="object"}function TS(a,t){let{config:r,message:e,onPropsUpdate:s}=t,o=P2.get(a.component);if(!o)return console.warn(`[ComponentMiddleware] Component "${a.component}" not found in registry. Falling back to default rendering.`),null;let d={message:e,config:r,updateProps:l=>{s&&s(l)}};try{return o(a.props,d)}catch(l){return console.error(`[ComponentMiddleware] Error rendering component "${a.component}":`,l),null}}function sH(){let a=LS();return{processChunk:t=>a.processChunk(t),getDirective:()=>a.getExtractedDirective(),reset:()=>{a.reset()}}}function BS(a){if(!a.rawContent)return!1;try{let t=JSON.parse(a.rawContent);return typeof t=="object"&&t!==null&&"component"in t&&typeof t.component=="string"}catch{return!1}}function PS(a){if(!a.rawContent)return null;try{let t=JSON.parse(a.rawContent);if(typeof t=="object"&&t!==null&&"component"in t&&typeof t.component=="string")return{component:t.component,props:t.props&&typeof t.props=="object"&&t.props!==null?t.props:{},raw:a.rawContent}}catch{}return null}var R2="vanilla-agent-chat-history",Sk=30*1e3,fA=a=>!a||typeof a!="object"?{}:{...a},dH=a=>a.map(t=>({...t,streaming:!1})),lH=(a,t)=>r=>{var o,d,l;let e=(o=r.text)!=null?o:"",s=(d=r.message.rawContent)!=null?d:null;if(t){let p=t.process({text:e,raw:s!=null?s:e,message:r.message,streaming:r.streaming});p!==null&&(e=p.text,p.persist||(r.message.__skipPersist=!0))}return a!=null&&a.postprocessMessage?a.postprocessMessage({...r,text:e,raw:(l=s!=null?s:r.text)!=null?l:""}):ds(e)},VS=(a,t,r)=>{var lt,ut,Ft,ct,qt,ie,we,xA,mA,MA,gA,vA,yA,wA;(!a.id||a.id!=="vanilla-agent-root")&&(a.id="vanilla-agent-root");let e=HS(t);KS(a,e);let s=_2.getForInstance(e.plugins);e.components&&P2.registerAll(e.components);let o=aH(),d=(lt=e.storageAdapter)!=null?lt:kS(),l={},p=null;if(d!=null&&d.load)try{let n=d.load();if(n&&typeof n.then=="function")p=n;else if(n){let m=n;m.metadata&&(l=fA(m.metadata)),(ut=m.messages)!=null&&ut.length&&(e={...e,initialMessages:m.messages})}}catch(n){typeof console!="undefined"&&console.error("[AgentWidget] Failed to load stored state:",n)}let f=()=>l,h=n=>{var H;l=(H=n({...l}))!=null?H:{},Ue()},c=e.actionParsers&&e.actionParsers.length?e.actionParsers:[X2],i=e.actionHandlers&&e.actionHandlers.length?e.actionHandlers:[xa.message,xa.messageAndClick],u=J2({parsers:c,handlers:i,getMetadata:f,updateMetadata:h,emit:o.emit,documentRef:typeof document!="undefined"?document:null});u.syncFromMetadata();let M=(ct=(Ft=e.launcher)==null?void 0:Ft.enabled)!=null?ct:!0,F=(ie=(qt=e.launcher)==null?void 0:qt.autoExpand)!=null?ie:!1,O=F,v=M,C=M?F:!0,E=lH(e,u),S=(xA=(we=e.features)==null?void 0:we.showReasoning)!=null?xA:!0,G=(MA=(mA=e.features)==null?void 0:mA.showToolCalls)!=null?MA:!0,W=(gA=e.statusIndicator)!=null?gA:{},j=n=>{var m,H,I,V;return n==="idle"?(m=W.idleText)!=null?m:Kt.idle:n==="connecting"?(H=W.connectingText)!=null?H:Kt.connecting:n==="connected"?(I=W.connectedText)!=null?I:Kt.connected:n==="error"?(V=W.errorText)!=null?V:Kt.error:Kt[n]},{wrapper:Y,panel:b}=Kb(e),dt=jb(e,M),{container:X,body:Z,messagesWrapper:Q,suggestions:ht,textarea:ot,sendButton:z,sendButtonWrapper:_t,composerForm:jt,statusText:se,introTitle:Le,introSubtitle:Te,closeButton:U,iconHolder:mt,headerTitle:Ce,headerSubtitle:Se,header:Yt,footer:de}=dt,L=dt.micButton,Vt=dt.micButtonWrapper,fe=s.find(n=>n.renderHeader);if(fe!=null&&fe.renderHeader){let n=fe.renderHeader({config:e,defaultRenderer:()=>{let m=ra({config:e,showClose:M});return L2(X,m,e),m.header},onClose:()=>ne(!1,"user")});if(n){let m=X.querySelector(".tvw-border-b-cw-divider");m&&(m.replaceWith(n),Yt=n)}}let ue=s.find(n=>n.renderComposer);if(ue!=null&&ue.renderComposer){let n=ue.renderComposer({config:e,defaultRenderer:()=>T2({config:e}).footer,onSubmit:m=>{$&&!$.isStreaming()&&$.sendMessage(m)},disabled:!1});n&&(de.replaceWith(n),de=n)}(()=>{var I,V;let n=(V=(I=e.layout)==null?void 0:I.slots)!=null?V:{},m=at=>{switch(at){case"body-top":return X.querySelector(".tvw-rounded-2xl.tvw-bg-cw-surface.tvw-p-6")||null;case"messages":return Q;case"footer-top":return ht;case"composer":return jt;case"footer-bottom":return se;default:return null}},H=(at,P)=>{var w;switch(at){case"header-left":case"header-center":case"header-right":if(at==="header-left")Yt.insertBefore(P,Yt.firstChild);else if(at==="header-right")Yt.appendChild(P);else{let q=Yt.querySelector(".tvw-flex-col");q?(w=q.parentNode)==null||w.insertBefore(P,q.nextSibling):Yt.appendChild(P)}break;case"body-top":let _=Z.querySelector(".tvw-rounded-2xl.tvw-bg-cw-surface.tvw-p-6");_?_.replaceWith(P):Z.insertBefore(P,Z.firstChild);break;case"body-bottom":Z.appendChild(P);break;case"footer-top":ht.replaceWith(P);break;case"footer-bottom":se.replaceWith(P);break;default:break}};for(let[at,P]of Object.entries(n))if(P)try{let w=P({config:e,defaultContent:()=>m(at)});w&&H(at,w)}catch(w){typeof console!="undefined"&&console.error(`[AgentWidget] Error rendering slot "${at}":`,w)}})(),b.appendChild(X),a.appendChild(Y);let Ae=()=>{var Ut,xe,st,me,$e,Ne,De,la,Ge,pa,Me,Ze,_e,Q2,W2,z2;let n=(xe=(Ut=e.launcher)==null?void 0:Ut.sidebarMode)!=null?xe:!1,m=n||((me=(st=e.launcher)==null?void 0:st.fullHeight)!=null?me:!1),H=($e=e.theme)!=null?$e:{},I=(De=(Ne=e.launcher)==null?void 0:Ne.position)!=null?De:"bottom-left",V=I==="bottom-left"||I==="top-left",at=n?"none":"1px solid var(--tvw-cw-border)",P=n?V?"2px 0 12px rgba(0, 0, 0, 0.08)":"-2px 0 12px rgba(0, 0, 0, 0.08)":"0 25px 50px -12px rgba(0, 0, 0, 0.25)",w=n?"0":"16px",_=(la=H.panelBorder)!=null?la:at,q=(Ge=H.panelShadow)!=null?Ge:P,R=(pa=H.panelBorderRadius)!=null?pa:w;a.style.cssText="",Y.style.cssText="",b.style.cssText="",X.style.cssText="",Z.style.cssText="",de.style.cssText="";let N=(Ze=(Me=e==null?void 0:e.launcher)==null?void 0:Me.width)!=null?Ze:e==null?void 0:e.launcherWidth,Ot=N!=null?N:"min(400px, calc(100vw - 24px))";if(n||(b.style.width=Ot,b.style.maxWidth=Ot),b.style.boxShadow=q,b.style.borderRadius=R,X.style.border=_,X.style.borderRadius=R,m){let na=((_e=e.launcher)==null?void 0:_e.enabled)===!1;a.style.display="flex",a.style.flexDirection="column",a.style.height="100%",a.style.minHeight="0",Y.style.display="flex",Y.style.flexDirection="column",Y.style.flex="1 1 0%",Y.style.minHeight="0",Y.style.maxHeight="100%",Y.style.height="100%",na&&(Y.style.overflow="hidden"),b.style.display="flex",b.style.flexDirection="column",b.style.flex="1 1 0%",b.style.minHeight="0",b.style.maxHeight="100%",b.style.height="100%",b.style.overflow="hidden",X.style.display="flex",X.style.flexDirection="column",X.style.flex="1 1 0%",X.style.minHeight="0",X.style.maxHeight="100%",X.style.overflow="hidden",Z.style.flex="1 1 0%",Z.style.minHeight="0",Z.style.overflowY="auto",de.style.flexShrink="0"}if(Y.classList.remove("tvw-bottom-6","tvw-right-6","tvw-left-6","tvw-top-6","tvw-bottom-4","tvw-right-4","tvw-left-4","tvw-top-4"),n||((Q2=ke[I])!=null?Q2:ke["bottom-right"]).split(" ").forEach(ts=>Y.classList.add(ts)),n){let na=(z2=(W2=e.launcher)==null?void 0:W2.sidebarWidth)!=null?z2:"420px";Y.style.cssText=`
|
|
65
|
+
`),v.append(C,E),u.appendChild(v)}if(r.status==="complete"&&r.result!==void 0){let v=x("div","tvw-space-y-1"),C=x("div","tvw-text-xs tvw-text-cw-muted");e.labelTextColor&&(C.style.color=e.labelTextColor),C.textContent="Result";let E=x("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");E.style.fontSize="0.75rem",E.style.lineHeight="1rem",e.codeBlockBackgroundColor&&(E.style.backgroundColor=e.codeBlockBackgroundColor),e.codeBlockBorderColor&&(E.style.borderColor=e.codeBlockBorderColor),e.codeBlockTextColor&&(E.style.color=e.codeBlockTextColor),E.textContent=JS(r.result),v.append(C,E),u.appendChild(v)}if(r.status==="complete"&&typeof r.duration=="number"){let v=x("div","tvw-text-xs tvw-text-cw-muted");e.contentTextColor&&(v.style.color=e.contentTextColor),v.textContent=`Duration: ${r.duration}ms`,u.appendChild(v)}let M=()=>{d.setAttribute("aria-expanded",o?"true":"false"),f.innerHTML="";let v=e.toggleTextColor||e.headerTextColor||"currentColor",C=wt(o?"chevron-up":"chevron-down",16,v,2);C?f.appendChild(C):f.textContent=o?"Hide":"Show",u.style.display=o?"":"none"},F=()=>{o=!o,o?dA.add(a.id):dA.delete(a.id),M()};return d.addEventListener("pointerdown",v=>{v.preventDefault(),F()}),d.addEventListener("keydown",v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),F())}),M(),s.append(d,u),s};var tH=a=>{let t=[];return{buttons:t,render:(e,s,o,d,l)=>{if(a.innerHTML="",t.length=0,!e||!e.length||(d!=null?d:s?s.getMessages():[]).some(u=>u.role==="user"))return;let h=document.createDocumentFragment(),c=s?s.isStreaming():!1,i=u=>{switch(u){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'}};e.forEach(u=>{let M=x("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=u,M.disabled=c,l!=null&&l.fontFamily&&(M.style.fontFamily=i(l.fontFamily)),l!=null&&l.fontWeight&&(M.style.fontWeight=l.fontWeight),l!=null&&l.paddingX&&(M.style.paddingLeft=l.paddingX,M.style.paddingRight=l.paddingX),l!=null&&l.paddingY&&(M.style.paddingTop=l.paddingY,M.style.paddingBottom=l.paddingY),M.addEventListener("click",()=>{!s||s.isStreaming()||(o.value="",s.sendMessage(u))}),h.appendChild(M),t.push(M)}),a.appendChild(h)}}};var eH={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"}},pA=(a,t,r,e)=>{let s=a.querySelectorAll("[data-tv-form]");s.length&&s.forEach(o=>{var M,F,O;if(o.dataset.enhanced==="true")return;let d=(M=o.dataset.tvForm)!=null?M:"init";o.dataset.enhanced="true";let l=(F=eH[d])!=null?F:eH.init;o.classList.add("tvw-form-card","tvw-space-y-4");let p=x("div","tvw-space-y-1"),f=x("h3","tvw-text-base tvw-font-semibold tvw-text-cw-primary");if(f.textContent=l.title,p.appendChild(f),l.description){let v=x("p","tvw-text-sm tvw-text-cw-muted");v.textContent=l.description,p.appendChild(v)}let h=document.createElement("form");h.className="tvw-form-grid tvw-space-y-3",l.fields.forEach(v=>{var W,j;let C=x("label","tvw-form-field tvw-flex tvw-flex-col tvw-gap-1");C.htmlFor=`${t.id}-${d}-${v.name}`;let E=x("span","tvw-text-xs tvw-font-medium tvw-text-cw-muted");E.textContent=v.label,C.appendChild(E);let S=(W=v.type)!=null?W:"text",G;S==="textarea"?(G=document.createElement("textarea"),G.rows=3):(G=document.createElement("input"),G.type=S),G.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",G.id=`${t.id}-${d}-${v.name}`,G.name=v.name,G.placeholder=(j=v.placeholder)!=null?j:"",v.required&&(G.required=!0),C.appendChild(G),h.appendChild(C)});let c=x("div","tvw-flex tvw-items-center tvw-justify-between tvw-gap-2"),i=x("div","tvw-text-xs tvw-text-cw-muted tvw-min-h-[1.5rem]"),u=x("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");u.type="submit",u.textContent=(O=l.submitLabel)!=null?O:"Submit",c.appendChild(i),c.appendChild(u),h.appendChild(c),o.replaceChildren(p,h),h.addEventListener("submit",async v=>{var G,W;v.preventDefault();let C=(G=r.formEndpoint)!=null?G:"/form",E=new FormData(h),S={};E.forEach((j,Y)=>{S[Y]=j}),S.type=d,u.disabled=!0,i.textContent="Submitting\u2026";try{let j=await fetch(C,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(S)});if(!j.ok)throw new Error(`Form submission failed (${j.status})`);let Y=await j.json();i.textContent=(W=Y.message)!=null?W:"Thanks! We'll be in touch soon.",Y.success&&Y.nextPrompt&&await e.sendMessage(String(Y.nextPrompt))}catch(j){i.textContent=j instanceof Error?j.message:"Something went wrong. Please try again."}finally{u.disabled=!1}})})};var nA=class{constructor(){this.plugins=new Map}register(t){var r;this.plugins.has(t.id)&&console.warn(`Plugin "${t.id}" is already registered. Overwriting.`),this.plugins.set(t.id,t),(r=t.onRegister)==null||r.call(t)}unregister(t){var e;let r=this.plugins.get(t);r&&((e=r.onUnregister)==null||e.call(r),this.plugins.delete(t))}getAll(){return Array.from(this.plugins.values()).sort((t,r)=>{var e,s;return((e=r.priority)!=null?e:0)-((s=t.priority)!=null?s:0)})}getForInstance(t){let r=this.getAll();if(!t||t.length===0)return r;let e=new Set(t.map(o=>o.id));return[...r.filter(o=>!e.has(o.id)),...t].sort((o,d)=>{var l,p;return((l=d.priority)!=null?l:0)-((p=o.priority)!=null?p:0)})}clear(){this.plugins.forEach(t=>{var r;return(r=t.onUnregister)==null?void 0:r.call(t)}),this.plugins.clear()}},_2=new nA;var It={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,placement:"inline",iconName:"refresh-cw",size:"32px",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?"],suggestionChipsConfig:{fontFamily:"sans-serif",fontWeight:"500",paddingX:"12px",paddingY:"6px"},layout:{header:{layout:"default",showIcon:!0,showTitle:!0,showSubtitle:!0,showCloseButton:!0,showClearChat:!0},messages:{layout:"bubble",avatar:{show:!1,position:"left"},timestamp:{show:!1,position:"below"},groupConsecutive:!1},slots:{}},debug:!1};function HS(a){var t,r,e,s,o,d,l,p,f,h,c,i,u,M,F,O,v;return a?{...It,...a,theme:{...It.theme,...a.theme},launcher:{...It.launcher,...a.launcher,clearChat:{...(t=It.launcher)==null?void 0:t.clearChat,...(r=a.launcher)==null?void 0:r.clearChat}},copy:{...It.copy,...a.copy},sendButton:{...It.sendButton,...a.sendButton},statusIndicator:{...It.statusIndicator,...a.statusIndicator},voiceRecognition:{...It.voiceRecognition,...a.voiceRecognition},features:{...It.features,...a.features},suggestionChips:(e=a.suggestionChips)!=null?e:It.suggestionChips,suggestionChipsConfig:{...It.suggestionChipsConfig,...a.suggestionChipsConfig},layout:{...It.layout,...a.layout,header:{...(s=It.layout)==null?void 0:s.header,...(o=a.layout)==null?void 0:o.header},messages:{...(d=It.layout)==null?void 0:d.messages,...(l=a.layout)==null?void 0:l.messages,avatar:{...(f=(p=It.layout)==null?void 0:p.messages)==null?void 0:f.avatar,...(c=(h=a.layout)==null?void 0:h.messages)==null?void 0:c.avatar},timestamp:{...(u=(i=It.layout)==null?void 0:i.messages)==null?void 0:u.timestamp,...(F=(M=a.layout)==null?void 0:M.messages)==null?void 0:F.timestamp}},slots:{...(O=It.layout)==null?void 0:O.slots,...(v=a.layout)==null?void 0:v.slots}}}:It}var aH=()=>{let a=new Map,t=(s,o)=>(a.has(s)||a.set(s,new Set),a.get(s).add(o),()=>r(s,o)),r=(s,o)=>{var d;(d=a.get(s))==null||d.delete(o)};return{on:t,off:r,emit:(s,o)=>{var d;(d=a.get(s))==null||d.forEach(l=>{try{l(o)}catch(p){typeof console!="undefined"&&console.error("[AgentWidget] Event handler error:",p)}})}}};var Mk=a=>{let t=a.match(/```(?:json)?\s*([\s\S]*?)```/i);return t?t[1]:a},gk=a=>{let t=a.trim(),r=t.indexOf("{");if(r===-1)return null;let e=0;for(let s=r;s<t.length;s+=1){let o=t[s];if(o==="{"&&(e+=1),o==="}"&&(e-=1,e===0))return t.slice(r,s+1)}return null},X2=({text:a})=>{if(!a||!a.includes("{"))return null;try{let t=Mk(a),r=gk(t);if(!r)return null;let e=JSON.parse(r);if(!e||typeof e!="object"||!e.action)return null;let{action:s,...o}=e;return{type:String(s),payload:o,raw:e}}catch{return null}},hA=a=>typeof a=="string"?a:a==null?"":String(a),xa={message:a=>a.type!=="message"?void 0:{handled:!0,displayText:hA(a.payload.text)},messageAndClick:(a,t)=>{var s;if(a.type!=="message_and_click")return;let r=a.payload,e=hA(r.element);if(e&&((s=t.document)!=null&&s.querySelector)){let o=t.document.querySelector(e);o?setTimeout(()=>{o.click()},400):typeof console!="undefined"&&console.warn("[AgentWidget] Element not found for selector:",e)}return{handled:!0,displayText:hA(r.text)}}},rH=a=>Array.isArray(a)?a.map(t=>String(t)):[],J2=a=>{let t=new Set(rH(a.getMetadata().processedActionMessageIds)),r=()=>{t=new Set(rH(a.getMetadata().processedActionMessageIds))},e=()=>{let o=Array.from(t);a.updateMetadata(d=>({...d,processedActionMessageIds:o}))};return{process:o=>{if(o.streaming||o.message.role!=="assistant"||!o.text||t.has(o.message.id))return null;let d=typeof o.raw=="string"&&o.raw||typeof o.message.rawContent=="string"&&o.message.rawContent||typeof o.text=="string"&&o.text||null;!d&&typeof o.text=="string"&&o.text.trim().startsWith("{")&&typeof console!="undefined"&&console.warn("[AgentWidget] Structured response detected but no raw payload was provided. Ensure your stream parser returns { text, raw }.");let l=d?a.parsers.reduce((f,h)=>f||(h==null?void 0:h({text:d,message:o.message}))||null,null):null;if(!l)return null;t.add(o.message.id),e();let p={action:l,message:o.message};a.emit("action:detected",p);for(let f of a.handlers)if(f)try{let h=f(l,{message:o.message,metadata:a.getMetadata(),updateMetadata:a.updateMetadata,document:a.documentRef});if(!h)continue;if(h.handled){let c=h.persistMessage!==!1;return{text:h.displayText!==void 0?h.displayText:"",persist:c}}}catch(h){typeof console!="undefined"&&console.error("[AgentWidget] Action handler error:",h)}return{text:"",persist:!0}},syncFromMetadata:r}};var vk=a=>{if(!a)return null;try{return JSON.parse(a)}catch(t){return typeof console!="undefined"&&console.error("[AgentWidget] Failed to parse stored state:",t),null}},yk=a=>a.map(t=>({...t,streaming:!1})),kS=(a="vanilla-agent-state")=>{let t=()=>typeof window=="undefined"||!window.localStorage?null:window.localStorage;return{load:()=>{let r=t();return r?vk(r.getItem(a)):null},save:r=>{let e=t();if(e)try{let s={...r,messages:r.messages?yk(r.messages):void 0};e.setItem(a,JSON.stringify(s))}catch(s){typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",s)}},clear:()=>{let r=t();if(r)try{r.removeItem(a)}catch(e){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear stored state:",e)}}}};var iA=class{constructor(){this.components=new Map}register(t,r){this.components.has(t)&&console.warn(`[ComponentRegistry] Component "${t}" is already registered. Overwriting.`),this.components.set(t,r)}unregister(t){this.components.delete(t)}get(t){return this.components.get(t)}has(t){return this.components.has(t)}getAllNames(){return Array.from(this.components.keys())}clear(){this.components.clear()}registerAll(t){Object.entries(t).forEach(([r,e])=>{this.register(r,e)})}},P2=new iA;var V2=Ab(XS(),1);function wk(a){if(!a||typeof a!="object"||!("component"in a))return!1;let t=a.component;return typeof t=="string"&&t.length>0}function Ck(a,t){if(!wk(a))return null;let r=a.props&&typeof a.props=="object"&&a.props!==null?a.props:{};return{component:a.component,props:r,raw:t}}function LS(){let a=null,t=0;return{getExtractedDirective:()=>a,processChunk:r=>{let e=r.trim();if(!e.startsWith("{")&&!e.startsWith("["))return null;if(r.length<=t)return a;try{let s=(0,V2.parse)(r,V2.STR|V2.OBJ),o=Ck(s,r);o&&(a=o)}catch{}return t=r.length,a},reset:()=>{a=null,t=0}}}function oH(a){return typeof a=="object"&&a!==null&&"component"in a&&typeof a.component=="string"&&"props"in a&&typeof a.props=="object"}function TS(a,t){let{config:r,message:e,onPropsUpdate:s}=t,o=P2.get(a.component);if(!o)return console.warn(`[ComponentMiddleware] Component "${a.component}" not found in registry. Falling back to default rendering.`),null;let d={message:e,config:r,updateProps:l=>{s&&s(l)}};try{return o(a.props,d)}catch(l){return console.error(`[ComponentMiddleware] Error rendering component "${a.component}":`,l),null}}function sH(){let a=LS();return{processChunk:t=>a.processChunk(t),getDirective:()=>a.getExtractedDirective(),reset:()=>{a.reset()}}}function BS(a){if(!a.rawContent)return!1;try{let t=JSON.parse(a.rawContent);return typeof t=="object"&&t!==null&&"component"in t&&typeof t.component=="string"}catch{return!1}}function PS(a){if(!a.rawContent)return null;try{let t=JSON.parse(a.rawContent);if(typeof t=="object"&&t!==null&&"component"in t&&typeof t.component=="string")return{component:t.component,props:t.props&&typeof t.props=="object"&&t.props!==null?t.props:{},raw:a.rawContent}}catch{}return null}var R2="vanilla-agent-chat-history",Sk=30*1e3,fA=a=>!a||typeof a!="object"?{}:{...a},dH=a=>a.map(t=>({...t,streaming:!1})),lH=(a,t)=>r=>{var o,d,l;let e=(o=r.text)!=null?o:"",s=(d=r.message.rawContent)!=null?d:null;if(t){let p=t.process({text:e,raw:s!=null?s:e,message:r.message,streaming:r.streaming});p!==null&&(e=p.text,p.persist||(r.message.__skipPersist=!0))}return a!=null&&a.postprocessMessage?a.postprocessMessage({...r,text:e,raw:(l=s!=null?s:r.text)!=null?l:""}):ds(e)},VS=(a,t,r)=>{var lt,ut,Ft,ct,qt,ie,we,xA,mA,MA,gA,vA,yA,wA;(!a.id||a.id!=="vanilla-agent-root")&&(a.id="vanilla-agent-root");let e=HS(t),s=_2.getForInstance(e.plugins);e.components&&P2.registerAll(e.components);let o=aH(),d=(lt=e.storageAdapter)!=null?lt:kS(),l={},p=null;if(d!=null&&d.load)try{let n=d.load();if(n&&typeof n.then=="function")p=n;else if(n){let m=n;m.metadata&&(l=fA(m.metadata)),(ut=m.messages)!=null&&ut.length&&(e={...e,initialMessages:m.messages})}}catch(n){typeof console!="undefined"&&console.error("[AgentWidget] Failed to load stored state:",n)}let f=()=>l,h=n=>{var H;l=(H=n({...l}))!=null?H:{},Ue()},c=e.actionParsers&&e.actionParsers.length?e.actionParsers:[X2],i=e.actionHandlers&&e.actionHandlers.length?e.actionHandlers:[xa.message,xa.messageAndClick],u=J2({parsers:c,handlers:i,getMetadata:f,updateMetadata:h,emit:o.emit,documentRef:typeof document!="undefined"?document:null});u.syncFromMetadata();let M=(ct=(Ft=e.launcher)==null?void 0:Ft.enabled)!=null?ct:!0,F=(ie=(qt=e.launcher)==null?void 0:qt.autoExpand)!=null?ie:!1,O=F,v=M,C=M?F:!0,E=lH(e,u),S=(xA=(we=e.features)==null?void 0:we.showReasoning)!=null?xA:!0,G=(MA=(mA=e.features)==null?void 0:mA.showToolCalls)!=null?MA:!0,W=(gA=e.statusIndicator)!=null?gA:{},j=n=>{var m,H,I,V;return n==="idle"?(m=W.idleText)!=null?m:Kt.idle:n==="connecting"?(H=W.connectingText)!=null?H:Kt.connecting:n==="connected"?(I=W.connectedText)!=null?I:Kt.connected:n==="error"?(V=W.errorText)!=null?V:Kt.error:Kt[n]},{wrapper:Y,panel:b}=Kb(e),dt=jb(e,M),{container:X,body:Z,messagesWrapper:Q,suggestions:ht,textarea:ot,sendButton:z,sendButtonWrapper:_t,composerForm:jt,statusText:se,introTitle:Le,introSubtitle:Te,closeButton:U,iconHolder:mt,headerTitle:Ce,headerSubtitle:Se,header:Yt,footer:de}=dt,L=dt.micButton,Vt=dt.micButtonWrapper,fe=s.find(n=>n.renderHeader);if(fe!=null&&fe.renderHeader){let n=fe.renderHeader({config:e,defaultRenderer:()=>{let m=ra({config:e,showClose:M});return L2(X,m,e),m.header},onClose:()=>ne(!1,"user")});if(n){let m=X.querySelector(".tvw-border-b-cw-divider");m&&(m.replaceWith(n),Yt=n)}}let ue=s.find(n=>n.renderComposer);if(ue!=null&&ue.renderComposer){let n=ue.renderComposer({config:e,defaultRenderer:()=>T2({config:e}).footer,onSubmit:m=>{$&&!$.isStreaming()&&$.sendMessage(m)},disabled:!1});n&&(de.replaceWith(n),de=n)}(()=>{var I,V;let n=(V=(I=e.layout)==null?void 0:I.slots)!=null?V:{},m=at=>{switch(at){case"body-top":return X.querySelector(".tvw-rounded-2xl.tvw-bg-cw-surface.tvw-p-6")||null;case"messages":return Q;case"footer-top":return ht;case"composer":return jt;case"footer-bottom":return se;default:return null}},H=(at,P)=>{var w;switch(at){case"header-left":case"header-center":case"header-right":if(at==="header-left")Yt.insertBefore(P,Yt.firstChild);else if(at==="header-right")Yt.appendChild(P);else{let q=Yt.querySelector(".tvw-flex-col");q?(w=q.parentNode)==null||w.insertBefore(P,q.nextSibling):Yt.appendChild(P)}break;case"body-top":let _=Z.querySelector(".tvw-rounded-2xl.tvw-bg-cw-surface.tvw-p-6");_?_.replaceWith(P):Z.insertBefore(P,Z.firstChild);break;case"body-bottom":Z.appendChild(P);break;case"footer-top":ht.replaceWith(P);break;case"footer-bottom":se.replaceWith(P);break;default:break}};for(let[at,P]of Object.entries(n))if(P)try{let w=P({config:e,defaultContent:()=>m(at)});w&&H(at,w)}catch(w){typeof console!="undefined"&&console.error(`[AgentWidget] Error rendering slot "${at}":`,w)}})(),b.appendChild(X),a.appendChild(Y);let Ae=()=>{var Ut,xe,st,me,$e,Ne,De,la,Ge,pa,Me,Ze,_e,Q2,W2,z2;let n=(xe=(Ut=e.launcher)==null?void 0:Ut.sidebarMode)!=null?xe:!1,m=n||((me=(st=e.launcher)==null?void 0:st.fullHeight)!=null?me:!1),H=($e=e.theme)!=null?$e:{},I=(De=(Ne=e.launcher)==null?void 0:Ne.position)!=null?De:"bottom-left",V=I==="bottom-left"||I==="top-left",at=n?"none":"1px solid var(--tvw-cw-border)",P=n?V?"2px 0 12px rgba(0, 0, 0, 0.08)":"-2px 0 12px rgba(0, 0, 0, 0.08)":"0 25px 50px -12px rgba(0, 0, 0, 0.25)",w=n?"0":"16px",_=(la=H.panelBorder)!=null?la:at,q=(Ge=H.panelShadow)!=null?Ge:P,R=(pa=H.panelBorderRadius)!=null?pa:w;a.style.cssText="",Y.style.cssText="",b.style.cssText="",X.style.cssText="",Z.style.cssText="",de.style.cssText="";let N=(Ze=(Me=e==null?void 0:e.launcher)==null?void 0:Me.width)!=null?Ze:e==null?void 0:e.launcherWidth,Ot=N!=null?N:"min(400px, calc(100vw - 24px))";if(n||(b.style.width=Ot,b.style.maxWidth=Ot),b.style.boxShadow=q,b.style.borderRadius=R,X.style.border=_,X.style.borderRadius=R,m){let na=((_e=e.launcher)==null?void 0:_e.enabled)===!1;a.style.display="flex",a.style.flexDirection="column",a.style.height="100%",a.style.minHeight="0",Y.style.display="flex",Y.style.flexDirection="column",Y.style.flex="1 1 0%",Y.style.minHeight="0",Y.style.maxHeight="100%",Y.style.height="100%",na&&(Y.style.overflow="hidden"),b.style.display="flex",b.style.flexDirection="column",b.style.flex="1 1 0%",b.style.minHeight="0",b.style.maxHeight="100%",b.style.height="100%",b.style.overflow="hidden",X.style.display="flex",X.style.flexDirection="column",X.style.flex="1 1 0%",X.style.minHeight="0",X.style.maxHeight="100%",X.style.overflow="hidden",Z.style.flex="1 1 0%",Z.style.minHeight="0",Z.style.overflowY="auto",de.style.flexShrink="0"}if(Y.classList.remove("tvw-bottom-6","tvw-right-6","tvw-left-6","tvw-top-6","tvw-bottom-4","tvw-right-4","tvw-left-4","tvw-top-4"),n||((Q2=ke[I])!=null?Q2:ke["bottom-right"]).split(" ").forEach(ts=>Y.classList.add(ts)),n){let na=(z2=(W2=e.launcher)==null?void 0:W2.sidebarWidth)!=null?z2:"420px";Y.style.cssText=`
|
|
66
66
|
position: fixed !important;
|
|
67
67
|
top: 0 !important;
|
|
68
68
|
bottom: 0 !important;
|
|
@@ -102,7 +102,7 @@ lucide.createIcons({icons});\``);if(typeof e=="undefined")throw new Error("`crea
|
|
|
102
102
|
flex-shrink: 0 !important;
|
|
103
103
|
border-top: none !important;
|
|
104
104
|
padding: 8px 16px 12px 16px !important;
|
|
105
|
-
`}let bt="max-height: -moz-available !important; max-height: stretch !important;",pt=n?"":"padding-top: 1.25em !important;";Y.style.cssText+=bt+pt};Ae();let Dt=[],le=tH(ht),Xt=null,$,ce=!1,Qt=!0,Pt=0,Gt=0,J=null,kt=!1,Rt=0,Jt=!1,pe=125,Be=2e3,Ie=5,ye=50,Pe=new Map,it={active:!1,manuallyDeactivated:!1,lastUserMessageWasVoice:!1},oa=(yA=(vA=e.voiceRecognition)==null?void 0:vA.autoResume)!=null?yA:!1,qe=n=>{o.emit("voice:state",{active:it.active,source:n,timestamp:Date.now()})},Ct=()=>{h(n=>({...n,voiceState:{active:it.active,timestamp:Date.now(),manuallyDeactivated:it.manuallyDeactivated}}))},be=()=>{var I,V;if(((I=e.voiceRecognition)==null?void 0:I.enabled)===!1)return;let n=fA(l.voiceState),m=!!n.active,H=Number((V=n.timestamp)!=null?V:0);it.manuallyDeactivated=!!n.manuallyDeactivated,m&&Date.now()-H<Sk&&setTimeout(()=>{it.active||(it.manuallyDeactivated=!1,zt("restore"))},1e3)},Ve=()=>$?dH($.getMessages()).filter(n=>!n.__skipPersist):[];function Ue(n){if(!(d!=null&&d.save))return;let H={messages:n?dH(n):$?Ve():[],metadata:l};try{let I=d.save(H);I instanceof Promise&&I.catch(V=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",V)})}catch(I){typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",I)}}let He=(n=!1)=>{if(!Qt)return;let m=Date.now();kt&&m<Rt&&!n||(kt&&m>=Rt&&(kt=!1),!(!n&&!ce)&&(m-Gt<pe||(Gt=m,J&&cancelAnimationFrame(J),J=requestAnimationFrame(()=>{kt||!Qt||(Jt=!0,Z.scrollTop=Z.scrollHeight,Pt=Z.scrollTop,requestAnimationFrame(()=>{Jt=!1}),J=null)}))))},Fe=null,K2=()=>Y.querySelector("#vanilla-agent-scroll-container")||Z,j2=(n,m=500)=>{let H=n.scrollTop,I=n.clientHeight,V=n.scrollHeight,at=V-H;if(H+I>=V-2||Math.abs(at)<5)return;Fe!==null&&(cancelAnimationFrame(Fe),Fe=null);let w=performance.now(),_=R=>1-Math.pow(1-R,3),q=R=>{let N=n.scrollHeight;N!==V&&(V=N,at=V-H);let Ot=R-w,bt=Math.min(Ot/m,1),pt=_(bt),Ut=H+at*pt;n.scrollTop=Ut,bt<1?Fe=requestAnimationFrame(q):(n.scrollTop=n.scrollHeight,Fe=null)};Fe=requestAnimationFrame(q)},Y2=n=>{let m=new Map;n.forEach(H=>{let I=Pe.get(H.id);m.set(H.id,{streaming:H.streaming,role:H.role}),!I&&H.role==="assistant"&&o.emit("assistant:message",H),H.role==="assistant"&&(I!=null&&I.streaming)&&H.streaming===!1&&o.emit("assistant:complete",H)}),Pe.clear(),m.forEach((H,I)=>{Pe.set(I,H)})},sa=(n,m,H)=>{n.innerHTML="";let I=document.createDocumentFragment();m.forEach(w=>{var Ot,bt;let _=null,q=s.find(pt=>!!(w.variant==="reasoning"&&pt.renderReasoning||w.variant==="tool"&&pt.renderToolCall||!w.variant&&pt.renderMessage)),R=(Ot=e.layout)==null?void 0:Ot.messages;if(q)if(w.variant==="reasoning"&&w.reasoning&&q.renderReasoning){if(!S)return;_=q.renderReasoning({message:w,defaultRenderer:()=>sA(w),config:e})}else if(w.variant==="tool"&&w.toolCall&&q.renderToolCall){if(!G)return;_=q.renderToolCall({message:w,defaultRenderer:()=>lA(w,e),config:e})}else q.renderMessage&&(_=q.renderMessage({message:w,defaultRenderer:()=>{let pt=B2(w,H,R);return w.role!=="user"&&pA(pt,w,e,$),pt},config:e}));if(!_&&w.role==="assistant"&&!w.variant&&e.enableComponentStreaming!==!1&&BS(w)){let Ut=PS(w);if(Ut){let xe=TS(Ut,{config:e,message:w,transform:H});if(xe){let st=document.createElement("div");if(st.className=["vanilla-message-bubble","tvw-max-w-[85%]","tvw-rounded-2xl","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-p-4"].join(" "),st.setAttribute("data-message-id",w.id),w.content&&w.content.trim()){let me=document.createElement("div");me.className="tvw-mb-3 tvw-text-sm tvw-leading-relaxed",me.innerHTML=H({text:w.content,message:w,streaming:!!w.streaming,raw:w.rawContent}),st.appendChild(me)}st.appendChild(xe),_=st}}}if(!_)if(w.variant==="reasoning"&&w.reasoning){if(!S)return;_=sA(w)}else if(w.variant==="tool"&&w.toolCall){if(!G)return;_=lA(w,e)}else{let pt=(bt=e.layout)==null?void 0:bt.messages;pt!=null&&pt.renderUserMessage&&w.role==="user"?_=pt.renderUserMessage({message:w,config:e,streaming:!!w.streaming}):pt!=null&&pt.renderAssistantMessage&&w.role==="assistant"?_=pt.renderAssistantMessage({message:w,config:e,streaming:!!w.streaming}):_=B2(w,H,pt),w.role!=="user"&&_&&pA(_,w,e,$)}let N=document.createElement("div");N.className="tvw-flex",w.role==="user"&&N.classList.add("tvw-justify-end"),N.appendChild(_),I.appendChild(N)});let V=m.some(w=>w.role==="assistant"&&w.streaming),at=m[m.length-1],P=(at==null?void 0:at.role)==="assistant"&&!at.streaming;if(ce&&m.some(w=>w.role==="user")&&!V&&!P){let w=Z2(),_=document.createElement("div");_.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(" "),_.appendChild(w);let q=document.createElement("div");q.className="tvw-flex",q.appendChild(_),I.appendChild(q)}n.appendChild(I),requestAnimationFrame(()=>{requestAnimationFrame(()=>{let w=K2();j2(w)})})},da=()=>{M&&(C?(Y.classList.remove("tvw-pointer-events-none","tvw-opacity-0"),b.classList.remove("tvw-scale-95","tvw-opacity-0"),b.classList.add("tvw-scale-100","tvw-opacity-100"),g?g.element.style.display="none":B&&(B.style.display="none")):(Y.classList.add("tvw-pointer-events-none","tvw-opacity-0"),b.classList.remove("tvw-scale-100","tvw-opacity-100"),b.classList.add("tvw-scale-95","tvw-opacity-0"),g?g.element.style.display="":B&&(B.style.display="")))},ne=(n,m="user")=>{if(!M||C===n)return;let H=C;C=n,da(),C&&(yt(),He(!0));let I={open:C,source:m,timestamp:Date.now()};C&&!H?o.emit("widget:opened",I):!C&&H&&o.emit("widget:closed",I),o.emit("widget:state",{open:C,launcherEnabled:M,voiceActive:it.active,streaming:$.isStreaming()})},ma=n=>{z.disabled=n,L&&(L.disabled=n),le.buttons.forEach(m=>{m.disabled=n})},E2=()=>{var V,at,P,w,_,q,R,N,Ot,bt,pt,Ut,xe,st;Le.textContent=(at=(V=e.copy)==null?void 0:V.welcomeTitle)!=null?at:"Hello \u{1F44B}",Te.textContent=(w=(P=e.copy)==null?void 0:P.welcomeSubtitle)!=null?w:"Ask anything about your account or products.",ot.placeholder=(q=(_=e.copy)==null?void 0:_.inputPlaceholder)!=null?q:"How can I help...",((N=(R=e.sendButton)==null?void 0:R.useIcon)!=null?N:!1)||(z.textContent=(bt=(Ot=e.copy)==null?void 0:Ot.sendButtonLabel)!=null?bt:"Send");let m=(Ut=(pt=e.theme)==null?void 0:pt.inputFontFamily)!=null?Ut:"sans-serif",H=(st=(xe=e.theme)==null?void 0:xe.inputFontWeight)!=null?st:"400",I=me=>{switch(me){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'}};ot.style.fontFamily=I(m),ot.style.fontWeight=H};$=new ya(e,{onMessagesChanged(n){sa(Q,n,E),$&&(n.some(I=>I.role==="user")?le.render([],$,ot,n):le.render(e.suggestionChips,$,ot,n,e.suggestionChipsConfig)),He(!ce),Y2(n);let m=[...n].reverse().find(H=>H.role==="user");it.lastUserMessageWasVoice=!!(m!=null&&m.viaVoice),Ue(n)},onStatusChanged(n){var I;let m=(I=e.statusIndicator)!=null?I:{},H=V=>{var at,P,w,_;return V==="idle"?(at=m.idleText)!=null?at:Kt.idle:V==="connecting"?(P=m.connectingText)!=null?P:Kt.connecting:V==="connected"?(w=m.connectedText)!=null?w:Kt.connected:V==="error"?(_=m.errorText)!=null?_:Kt.error:Kt[V]};se.textContent=H(n)},onStreamingChanged(n){ce=n,ma(n),$&&sa(Q,$.getMessages(),E),n||He(!0)}}),p&&p.then(n=>{var m;n&&(n.metadata&&(l=fA(n.metadata),u.syncFromMetadata()),(m=n.messages)!=null&&m.length&&$.hydrateMessages(n.messages))}).catch(n=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to hydrate stored state:",n)});let F2=n=>{n.preventDefault();let m=ot.value.trim();m&&(ot.value="",$.sendMessage(m))},D2=n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),z.click())},y=null,K=!1,rt=null,vt=null,Wt=()=>typeof window=="undefined"?null:window.webkitSpeechRecognition||window.SpeechRecognition||null,zt=(n="user")=>{var at,P,w,_;if(K||$.isStreaming())return;let m=Wt();if(!m)return;y=new m;let I=(P=((at=e.voiceRecognition)!=null?at:{}).pauseDuration)!=null?P:2e3;y.continuous=!0,y.interimResults=!0,y.lang="en-US";let V=ot.value;y.onresult=q=>{let R="",N="";for(let bt=0;bt<q.results.length;bt++){let pt=q.results[bt],Ut=pt[0].transcript;pt.isFinal?R+=Ut+" ":N=Ut}let Ot=V+R+N;ot.value=Ot,rt&&clearTimeout(rt),(R||N)&&(rt=window.setTimeout(()=>{let bt=ot.value.trim();bt&&y&&K&&(ft(),ot.value="",$.sendMessage(bt,{viaVoice:!0}))},I))},y.onerror=q=>{q.error!=="no-speech"&&ft()},y.onend=()=>{if(K){let q=ot.value.trim();q&&q!==V.trim()&&(ot.value="",$.sendMessage(q,{viaVoice:!0})),ft()}};try{if(y.start(),K=!0,it.active=!0,n!=="system"&&(it.manuallyDeactivated=!1),qe(n),Ct(),L){vt={backgroundColor:L.style.backgroundColor,color:L.style.color,borderColor:L.style.borderColor};let q=(w=e.voiceRecognition)!=null?w:{},R=(_=q.recordingBackgroundColor)!=null?_:"#ef4444",N=q.recordingIconColor,Ot=q.recordingBorderColor;if(L.classList.add("tvw-voice-recording"),L.style.backgroundColor=R,N){L.style.color=N;let bt=L.querySelector("svg");bt&&bt.setAttribute("stroke",N)}Ot&&(L.style.borderColor=Ot),L.setAttribute("aria-label","Stop voice recognition")}}catch{ft("system")}},ft=(n="user")=>{if(K){if(K=!1,rt&&(clearTimeout(rt),rt=null),y){try{y.stop()}catch{}y=null}if(it.active=!1,qe(n),Ct(),L){if(L.classList.remove("tvw-voice-recording"),vt){L.style.backgroundColor=vt.backgroundColor,L.style.color=vt.color,L.style.borderColor=vt.borderColor;let m=L.querySelector("svg");m&&m.setAttribute("stroke",vt.color||"currentColor"),vt=null}L.setAttribute("aria-label","Start voice recognition")}}},T=(n,m)=>{var Ut,xe,st,me,$e,Ne,De;if(!(typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined")))return null;let I=x("div","tvw-send-button-wrapper"),V=x("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer");V.type="button",V.setAttribute("aria-label","Start voice recognition");let at=(Ut=n==null?void 0:n.iconName)!=null?Ut:"mic",P=(xe=m==null?void 0:m.size)!=null?xe:"40px",w=(st=n==null?void 0:n.iconSize)!=null?st:P,_=parseFloat(w)||24,q=(me=n==null?void 0:n.backgroundColor)!=null?me:m==null?void 0:m.backgroundColor,R=($e=n==null?void 0:n.iconColor)!=null?$e:m==null?void 0:m.textColor;V.style.width=w,V.style.height=w,V.style.minWidth=w,V.style.minHeight=w,V.style.fontSize="18px",V.style.lineHeight="1";let N=R||"currentColor",Ot=wt(at,_,N,1.5);Ot?(V.appendChild(Ot),V.style.color=N):(V.textContent="\u{1F3A4}",V.style.color=N),q?V.style.backgroundColor=q:V.classList.add("tvw-bg-cw-primary"),R?V.style.color=R:!R&&!(m!=null&&m.textColor)&&V.classList.add("tvw-text-white"),n!=null&&n.borderWidth&&(V.style.borderWidth=n.borderWidth,V.style.borderStyle="solid"),n!=null&&n.borderColor&&(V.style.borderColor=n.borderColor),n!=null&&n.paddingX&&(V.style.paddingLeft=n.paddingX,V.style.paddingRight=n.paddingX),n!=null&&n.paddingY&&(V.style.paddingTop=n.paddingY,V.style.paddingBottom=n.paddingY),I.appendChild(V);let bt=(Ne=n==null?void 0:n.tooltipText)!=null?Ne:"Start voice recognition";if(((De=n==null?void 0:n.showTooltip)!=null?De:!1)&&bt){let la=x("div","tvw-send-button-tooltip");la.textContent=bt,I.appendChild(la)}return{micButton:V,micButtonWrapper:I}},he=()=>{if(K){let n=ot.value.trim();it.manuallyDeactivated=!0,Ct(),ft("user"),n&&(ot.value="",$.sendMessage(n))}else it.manuallyDeactivated=!1,Ct(),zt("user")};L&&(L.addEventListener("click",he),Dt.push(()=>{ft("system"),L&&L.removeEventListener("click",he)}));let tt=o.on("assistant:complete",()=>{oa&&(it.active||it.manuallyDeactivated||oa==="assistant"&&!it.lastUserMessageWasVoice||setTimeout(()=>{!it.active&&!it.manuallyDeactivated&&zt("auto")},600))});Dt.push(tt);let A=()=>{ne(!C,"user")},g=null,B=null;if(M){let n=s.find(m=>m.renderLauncher);if(n!=null&&n.renderLauncher){let m=n.renderLauncher({config:e,defaultRenderer:()=>G2(e,A).element,onToggle:A});m&&(B=m)}B||(g=G2(e,A))}g?a.appendChild(g.element):B&&a.appendChild(B),da(),le.render(e.suggestionChips,$,ot,void 0,e.suggestionChipsConfig),E2(),ma($.isStreaming()),He(!0),be();let yt=()=>{var H,I,V,at,P,w;let n=(I=(H=e.launcher)==null?void 0:H.sidebarMode)!=null?I:!1,m=n||((at=(V=e.launcher)==null?void 0:V.fullHeight)!=null?at:!1);if(!M){b.style.height="",b.style.width="";return}if(!n){let _=(w=(P=e==null?void 0:e.launcher)==null?void 0:P.width)!=null?w:e==null?void 0:e.launcherWidth,q=_!=null?_:"min(400px, calc(100vw - 24px))";b.style.width=q,b.style.maxWidth=q}if(!m){let _=window.innerHeight,R=Math.max(200,_-64),N=Math.min(640,R);b.style.height=`${N}px`}};yt(),window.addEventListener("resize",yt),Dt.push(()=>window.removeEventListener("resize",yt)),Pt=Z.scrollTop;let Lt=()=>{let n=Z.scrollTop,m=Z.scrollHeight,H=Z.clientHeight,I=m-n-H,V=Math.abs(n-Pt);if(Pt=n,!Jt&&!(V<=Ie)){if(!Qt&&I<ye){kt=!1,Qt=!0;return}Qt&&I>ye&&(kt=!0,Rt=Date.now()+Be,Qt=!1)}};Z.addEventListener("scroll",Lt,{passive:!0}),Dt.push(()=>Z.removeEventListener("scroll",Lt)),Dt.push(()=>{J&&cancelAnimationFrame(J)});let te=()=>{U&&(Xt&&(U.removeEventListener("click",Xt),Xt=null),M?(U.style.display="",Xt=()=>{C=!1,da()},U.addEventListener("click",Xt)):U.style.display="none")};te(),(()=>{let{clearChatButton:n}=dt;n&&n.addEventListener("click",()=>{$.clearMessages();try{localStorage.removeItem(R2),e.debug&&console.log(`[AgentWidget] Cleared default localStorage key: ${R2}`)}catch(H){console.error("[AgentWidget] Failed to clear default localStorage:",H)}if(e.clearChatHistoryStorageKey&&e.clearChatHistoryStorageKey!==R2)try{localStorage.removeItem(e.clearChatHistoryStorageKey),e.debug&&console.log(`[AgentWidget] Cleared custom localStorage key: ${e.clearChatHistoryStorageKey}`)}catch(H){console.error("[AgentWidget] Failed to clear custom localStorage:",H)}let m=new CustomEvent("vanilla-agent:clear-chat",{detail:{timestamp:new Date().toISOString()}});if(window.dispatchEvent(m),d!=null&&d.clear)try{let H=d.clear();H instanceof Promise&&H.catch(I=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",I)})}catch(H){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",H)}l={},u.syncFromMetadata()})})(),jt.addEventListener("submit",F2),ot.addEventListener("keydown",D2),Dt.push(()=>{jt.removeEventListener("submit",F2),ot.removeEventListener("keydown",D2)}),Dt.push(()=>{$.cancel()}),g?Dt.push(()=>{g==null||g.destroy()}):B&&Dt.push(()=>{B==null||B.remove()});let St={update(n){var W2,z2,na,ts,CA,SA,AA,bA,HA,kA,LA,TA,BA,PA,VA,RA,EA,FA,DA,WA,zA,OA,IA,qA,UA,$A,NA,GA,ZA,_A,XA,JA,KA,jA,YA,QA,tb,eb,ab,rb,ob,sb,db,lb,pb,nb,hb,ib,fb,ub,cb,xb,mb,Mb,gb,vb,yb;let m=e.toolCall;e={...e,...n},KS(a,e),Ae();let H=_2.getForInstance(e.plugins);if(s.length=0,s.push(...H),M=(z2=(W2=e.launcher)==null?void 0:W2.enabled)!=null?z2:!0,F=(ts=(na=e.launcher)==null?void 0:na.autoExpand)!=null?ts:!1,S=(SA=(CA=e.features)==null?void 0:CA.showReasoning)!=null?SA:!0,G=(bA=(AA=e.features)==null?void 0:AA.showToolCalls)!=null?bA:!0,((HA=e.launcher)==null?void 0:HA.enabled)===!1&&g&&(g.destroy(),g=null),((kA=e.launcher)==null?void 0:kA.enabled)===!1&&B&&(B.remove(),B=null),((LA=e.launcher)==null?void 0:LA.enabled)!==!1&&!g&&!B){let k=s.find(Mt=>Mt.renderLauncher);if(k!=null&&k.renderLauncher){let Mt=k.renderLauncher({config:e,defaultRenderer:()=>G2(e,A).element,onToggle:A});Mt&&(B=Mt,a.appendChild(B))}B||(g=G2(e,A),a.appendChild(g.element))}g&&g.update(e),Ce&&((TA=e.launcher)==null?void 0:TA.title)!==void 0&&(Ce.textContent=e.launcher.title),Se&&((BA=e.launcher)==null?void 0:BA.subtitle)!==void 0&&(Se.textContent=e.launcher.subtitle),M!==v?M?ne(F,"auto"):(C=!0,da()):F!==O&&ne(F,"auto"),O=F,v=M,yt(),te(),JSON.stringify(n.toolCall)!==JSON.stringify(m)&&$&&sa(Q,$.getMessages(),E);let P=(PA=e.launcher)!=null?PA:{},w=(VA=P.headerIconHidden)!=null?VA:!1,_=P.headerIconName,q=(RA=P.headerIconSize)!=null?RA:"48px";if(mt){let k=X.querySelector(".tvw-border-b-cw-divider"),Mt=k==null?void 0:k.querySelector(".tvw-flex-col");if(w)mt.style.display="none",k&&Mt&&!k.contains(Mt)&&k.insertBefore(Mt,k.firstChild);else{if(mt.style.display="",mt.style.height=q,mt.style.width=q,k&&Mt&&(k.contains(mt)?mt.nextSibling!==Mt&&(mt.remove(),k.insertBefore(mt,Mt)):k.insertBefore(mt,Mt)),_){let Bt=parseFloat(q)||24,At=wt(_,Bt*.6,"#ffffff",2);At?mt.replaceChildren(At):mt.textContent=(EA=P.agentIconText)!=null?EA:"\u{1F4AC}"}else if(P.iconUrl){let Bt=mt.querySelector("img");if(Bt)Bt.src=P.iconUrl,Bt.style.height=q,Bt.style.width=q;else{let At=document.createElement("img");At.src=P.iconUrl,At.alt="",At.className="tvw-rounded-xl tvw-object-cover",At.style.height=q,At.style.width=q,mt.replaceChildren(At)}}else{let Bt=mt.querySelector("svg"),At=mt.querySelector("img");(Bt||At)&&mt.replaceChildren(),mt.textContent=(FA=P.agentIconText)!=null?FA:"\u{1F4AC}"}let et=mt.querySelector("img");et&&(et.style.height=q,et.style.width=q)}}if(U){let k=(DA=P.closeButtonSize)!=null?DA:"32px",Mt=(WA=P.closeButtonPlacement)!=null?WA:"inline";U.style.height=k,U.style.width=k;let{closeButtonWrapper:et}=dt,Bt=Mt==="top-right",At=et==null?void 0:et.classList.contains("tvw-absolute");if(et&&Bt!==At)if(et.remove(),Bt)et.className="tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50",X.style.position="relative",X.appendChild(et);else{let xt=(OA=(zA=P.clearChat)==null?void 0:zA.placement)!=null?OA:"inline",ae=(qA=(IA=P.clearChat)==null?void 0:IA.enabled)!=null?qA:!0;et.className=ae&&xt==="inline"?"":"tvw-ml-auto";let re=X.querySelector(".tvw-border-b-cw-divider");re&&re.appendChild(et)}if(P.closeButtonColor?(U.style.color=P.closeButtonColor,U.classList.remove("tvw-text-cw-muted")):(U.style.color="",U.classList.add("tvw-text-cw-muted")),P.closeButtonBackgroundColor?(U.style.backgroundColor=P.closeButtonBackgroundColor,U.classList.remove("hover:tvw-bg-gray-100")):(U.style.backgroundColor="",U.classList.add("hover:tvw-bg-gray-100")),P.closeButtonBorderWidth||P.closeButtonBorderColor){let xt=P.closeButtonBorderWidth||"0px",ae=P.closeButtonBorderColor||"transparent";U.style.border=`${xt} solid ${ae}`,U.classList.remove("tvw-border-none")}else U.style.border="",U.classList.add("tvw-border-none");P.closeButtonBorderRadius?(U.style.borderRadius=P.closeButtonBorderRadius,U.classList.remove("tvw-rounded-full")):(U.style.borderRadius="",U.classList.add("tvw-rounded-full")),P.closeButtonPaddingX?(U.style.paddingLeft=P.closeButtonPaddingX,U.style.paddingRight=P.closeButtonPaddingX):(U.style.paddingLeft="",U.style.paddingRight=""),P.closeButtonPaddingY?(U.style.paddingTop=P.closeButtonPaddingY,U.style.paddingBottom=P.closeButtonPaddingY):(U.style.paddingTop="",U.style.paddingBottom="");let ee=(UA=P.closeButtonIconName)!=null?UA:"x",Nt=($A=P.closeButtonIconText)!=null?$A:"\xD7";U.innerHTML="";let ge=wt(ee,"20px",P.closeButtonColor||"",2);ge?U.appendChild(ge):U.textContent=Nt;let Xe=(NA=P.closeButtonTooltipText)!=null?NA:"Close chat",Tt=(GA=P.closeButtonShowTooltip)!=null?GA:!0;if(U.setAttribute("aria-label",Xe),et&&(et._cleanupTooltip&&(et._cleanupTooltip(),delete et._cleanupTooltip),Tt&&Xe)){let xt=null,ae=()=>{if(xt||!U)return;xt=x("div","tvw-clear-chat-tooltip"),xt.textContent=Xe;let Ma=x("div");Ma.className="tvw-clear-chat-tooltip-arrow",xt.appendChild(Ma);let FS=U.getBoundingClientRect();xt.style.position="fixed",xt.style.left=`${FS.left+FS.width/2}px`,xt.style.top=`${FS.top-8}px`,xt.style.transform="translate(-50%, -100%)",document.body.appendChild(xt)},re=()=>{xt&&xt.parentNode&&(xt.parentNode.removeChild(xt),xt=null)};et.addEventListener("mouseenter",ae),et.addEventListener("mouseleave",re),U.addEventListener("focus",ae),U.addEventListener("blur",re),et._cleanupTooltip=()=>{re(),et&&(et.removeEventListener("mouseenter",ae),et.removeEventListener("mouseleave",re)),U&&(U.removeEventListener("focus",ae),U.removeEventListener("blur",re))}}}let{clearChatButton:R,clearChatButtonWrapper:N}=dt;if(R){let k=(ZA=P.clearChat)!=null?ZA:{},Mt=(_A=k.enabled)!=null?_A:!0,et=(XA=k.placement)!=null?XA:"inline";if(N){N.style.display=Mt?"":"none";let Bt=et==="top-right",At=N.classList.contains("tvw-absolute");if(Bt!==At&&Mt){if(N.remove(),Bt)N.className="tvw-absolute tvw-top-4 tvw-z-50",N.style.right="48px",X.style.position="relative",X.appendChild(N);else{N.className="tvw-relative tvw-ml-auto tvw-clear-chat-button-wrapper",N.style.right="";let Nt=X.querySelector(".tvw-border-b-cw-divider"),ge=dt.closeButtonWrapper;Nt&&ge&&ge.parentElement===Nt?Nt.insertBefore(N,ge):Nt&&Nt.appendChild(N)}let ee=dt.closeButtonWrapper;ee&&!ee.classList.contains("tvw-absolute")&&(Bt?ee.classList.add("tvw-ml-auto"):ee.classList.remove("tvw-ml-auto"))}}if(Mt){let Bt=(JA=k.size)!=null?JA:"32px";R.style.height=Bt,R.style.width=Bt;let At=(KA=k.iconName)!=null?KA:"refresh-cw",ee=(jA=k.iconColor)!=null?jA:"";R.innerHTML="";let Nt=wt(At,"20px",ee||"",2);if(Nt&&R.appendChild(Nt),ee?(R.style.color=ee,R.classList.remove("tvw-text-cw-muted")):(R.style.color="",R.classList.add("tvw-text-cw-muted")),k.backgroundColor?(R.style.backgroundColor=k.backgroundColor,R.classList.remove("hover:tvw-bg-gray-100")):(R.style.backgroundColor="",R.classList.add("hover:tvw-bg-gray-100")),k.borderWidth||k.borderColor){let Tt=k.borderWidth||"0px",xt=k.borderColor||"transparent";R.style.border=`${Tt} solid ${xt}`,R.classList.remove("tvw-border-none")}else R.style.border="",R.classList.add("tvw-border-none");k.borderRadius?(R.style.borderRadius=k.borderRadius,R.classList.remove("tvw-rounded-full")):(R.style.borderRadius="",R.classList.add("tvw-rounded-full")),k.paddingX?(R.style.paddingLeft=k.paddingX,R.style.paddingRight=k.paddingX):(R.style.paddingLeft="",R.style.paddingRight=""),k.paddingY?(R.style.paddingTop=k.paddingY,R.style.paddingBottom=k.paddingY):(R.style.paddingTop="",R.style.paddingBottom="");let ge=(YA=k.tooltipText)!=null?YA:"Clear chat",Xe=(QA=k.showTooltip)!=null?QA:!0;if(R.setAttribute("aria-label",ge),N&&(N._cleanupTooltip&&(N._cleanupTooltip(),delete N._cleanupTooltip),Xe&&ge)){let Tt=null,xt=()=>{if(Tt||!R)return;Tt=x("div","tvw-clear-chat-tooltip"),Tt.textContent=ge;let re=x("div");re.className="tvw-clear-chat-tooltip-arrow",Tt.appendChild(re);let Ma=R.getBoundingClientRect();Tt.style.position="fixed",Tt.style.left=`${Ma.left+Ma.width/2}px`,Tt.style.top=`${Ma.top-8}px`,Tt.style.transform="translate(-50%, -100%)",document.body.appendChild(Tt)},ae=()=>{Tt&&Tt.parentNode&&(Tt.parentNode.removeChild(Tt),Tt=null)};N.addEventListener("mouseenter",xt),N.addEventListener("mouseleave",ae),R.addEventListener("focus",xt),R.addEventListener("blur",ae),N._cleanupTooltip=()=>{ae(),N&&(N.removeEventListener("mouseenter",xt),N.removeEventListener("mouseleave",ae)),R&&(R.removeEventListener("focus",xt),R.removeEventListener("blur",ae))}}}}let Ot=e.actionParsers&&e.actionParsers.length?e.actionParsers:[X2],bt=e.actionHandlers&&e.actionHandlers.length?e.actionHandlers:[xa.message,xa.messageAndClick];u=J2({parsers:Ot,handlers:bt,getMetadata:f,updateMetadata:h,emit:o.emit,documentRef:typeof document!="undefined"?document:null}),E=lH(e,u),$.updateConfig(e),sa(Q,$.getMessages(),E),le.render(e.suggestionChips,$,ot,void 0,e.suggestionChipsConfig),E2(),ma($.isStreaming());let pt=((tb=e.voiceRecognition)==null?void 0:tb.enabled)===!0,Ut=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),xe=pt&&Ut;if(jt.classList.remove("tvw-gap-1","tvw-gap-3"),jt.classList.add(xe?"tvw-gap-1":"tvw-gap-3"),pt&&Ut)if(!L||!Vt){let k=T(e.voiceRecognition,e.sendButton);k&&(L=k.micButton,Vt=k.micButtonWrapper,jt.insertBefore(Vt,_t),L.addEventListener("click",he),L.disabled=$.isStreaming())}else{let k=(eb=e.voiceRecognition)!=null?eb:{},Mt=(ab=e.sendButton)!=null?ab:{},et=(rb=k.iconName)!=null?rb:"mic",Bt=(ob=Mt.size)!=null?ob:"40px",At=(sb=k.iconSize)!=null?sb:Bt,ee=parseFloat(At)||24;L.style.width=At,L.style.height=At,L.style.minWidth=At,L.style.minHeight=At;let Nt=(lb=(db=k.iconColor)!=null?db:Mt.textColor)!=null?lb:"currentColor";L.innerHTML="";let ge=wt(et,ee,Nt,2);ge?L.appendChild(ge):L.textContent="\u{1F3A4}";let Xe=(pb=k.backgroundColor)!=null?pb:Mt.backgroundColor;Xe?(L.style.backgroundColor=Xe,L.classList.remove("tvw-bg-cw-primary")):(L.style.backgroundColor="",L.classList.add("tvw-bg-cw-primary")),Nt?(L.style.color=Nt,L.classList.remove("tvw-text-white")):!Nt&&!Mt.textColor&&(L.style.color="",L.classList.add("tvw-text-white")),k.borderWidth?(L.style.borderWidth=k.borderWidth,L.style.borderStyle="solid"):(L.style.borderWidth="",L.style.borderStyle=""),k.borderColor?L.style.borderColor=k.borderColor:L.style.borderColor="",k.paddingX?(L.style.paddingLeft=k.paddingX,L.style.paddingRight=k.paddingX):(L.style.paddingLeft="",L.style.paddingRight=""),k.paddingY?(L.style.paddingTop=k.paddingY,L.style.paddingBottom=k.paddingY):(L.style.paddingTop="",L.style.paddingBottom="");let Tt=Vt==null?void 0:Vt.querySelector(".tvw-send-button-tooltip"),xt=(nb=k.tooltipText)!=null?nb:"Start voice recognition";if(((hb=k.showTooltip)!=null?hb:!1)&&xt)if(Tt)Tt.textContent=xt,Tt.style.display="";else{let re=document.createElement("div");re.className="tvw-send-button-tooltip",re.textContent=xt,Vt==null||Vt.insertBefore(re,L)}else Tt&&(Tt.style.display="none");Vt.style.display="",L.disabled=$.isStreaming()}else L&&Vt&&(Vt.style.display="none",K&&ft());let st=(ib=e.sendButton)!=null?ib:{},me=(fb=st.useIcon)!=null?fb:!1,$e=(ub=st.iconText)!=null?ub:"\u2191",Ne=st.iconName,De=(cb=st.tooltipText)!=null?cb:"Send message",la=(xb=st.showTooltip)!=null?xb:!1,Ge=(mb=st.size)!=null?mb:"40px",pa=st.backgroundColor,Me=st.textColor;if(me){if(z.style.width=Ge,z.style.height=Ge,z.style.minWidth=Ge,z.style.minHeight=Ge,z.style.fontSize="18px",z.style.lineHeight="1",z.innerHTML="",Ne){let k=parseFloat(Ge)||24,Mt=Me&&typeof Me=="string"&&Me.trim()?Me.trim():"currentColor",et=wt(Ne,k,Mt,2);et?(z.appendChild(et),z.style.color=Mt):(z.textContent=$e,Me?z.style.color=Me:z.classList.add("tvw-text-white"))}else z.textContent=$e,Me?z.style.color=Me:z.classList.add("tvw-text-white");z.className="tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer",pa?(z.style.backgroundColor=pa,z.classList.remove("tvw-bg-cw-primary")):z.classList.add("tvw-bg-cw-primary")}else z.textContent=(gb=(Mb=e.copy)==null?void 0:Mb.sendButtonLabel)!=null?gb:"Send",z.style.width="",z.style.height="",z.style.minWidth="",z.style.minHeight="",z.style.fontSize="",z.style.lineHeight="",z.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",pa?(z.style.backgroundColor=pa,z.classList.remove("tvw-bg-cw-accent")):z.classList.add("tvw-bg-cw-accent"),Me?z.style.color=Me:z.classList.add("tvw-text-white");st.borderWidth?(z.style.borderWidth=st.borderWidth,z.style.borderStyle="solid"):(z.style.borderWidth="",z.style.borderStyle=""),st.borderColor?z.style.borderColor=st.borderColor:z.style.borderColor="",st.paddingX?(z.style.paddingLeft=st.paddingX,z.style.paddingRight=st.paddingX):(z.style.paddingLeft="",z.style.paddingRight=""),st.paddingY?(z.style.paddingTop=st.paddingY,z.style.paddingBottom=st.paddingY):(z.style.paddingTop="",z.style.paddingBottom="");let Ze=_t==null?void 0:_t.querySelector(".tvw-send-button-tooltip");if(la&&De)if(Ze)Ze.textContent=De,Ze.style.display="";else{let k=document.createElement("div");k.className="tvw-send-button-tooltip",k.textContent=De,_t==null||_t.insertBefore(k,z)}else Ze&&(Ze.style.display="none");let _e=(vb=e.statusIndicator)!=null?vb:{},Q2=(yb=_e.visible)!=null?yb:!0;if(se.style.display=Q2?"":"none",$){let k=$.getStatus(),Mt=et=>{var Bt,At,ee,Nt;return et==="idle"?(Bt=_e.idleText)!=null?Bt:Kt.idle:et==="connecting"?(At=_e.connectingText)!=null?At:Kt.connecting:et==="connected"?(ee=_e.connectedText)!=null?ee:Kt.connected:et==="error"?(Nt=_e.errorText)!=null?Nt:Kt.error:Kt[et]};se.textContent=Mt(k)}},open(){M&&ne(!0,"api")},close(){M&&ne(!1,"api")},toggle(){M&&ne(!C,"api")},clearChat(){$.clearMessages();try{localStorage.removeItem(R2),e.debug&&console.log(`[AgentWidget] Cleared default localStorage key: ${R2}`)}catch(m){console.error("[AgentWidget] Failed to clear default localStorage:",m)}if(e.clearChatHistoryStorageKey&&e.clearChatHistoryStorageKey!==R2)try{localStorage.removeItem(e.clearChatHistoryStorageKey),e.debug&&console.log(`[AgentWidget] Cleared custom localStorage key: ${e.clearChatHistoryStorageKey}`)}catch(m){console.error("[AgentWidget] Failed to clear custom localStorage:",m)}let n=new CustomEvent("vanilla-agent:clear-chat",{detail:{timestamp:new Date().toISOString()}});if(window.dispatchEvent(n),d!=null&&d.clear)try{let m=d.clear();m instanceof Promise&&m.catch(H=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",H)})}catch(m){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",m)}l={},u.syncFromMetadata()},setMessage(n){return!ot||$.isStreaming()?!1:(!C&&M&&ne(!0,"system"),ot.value=n,ot.dispatchEvent(new Event("input",{bubbles:!0})),!0)},submitMessage(n){if($.isStreaming())return!1;let m=(n==null?void 0:n.trim())||ot.value.trim();return m?(!C&&M&&ne(!0,"system"),ot.value="",$.sendMessage(m),!0):!1},startVoiceRecognition(){return K||$.isStreaming()||!Wt()?!1:(!C&&M&&ne(!0,"system"),it.manuallyDeactivated=!1,Ct(),zt("user"),!0)},stopVoiceRecognition(){return K?(it.manuallyDeactivated=!0,Ct(),ft("user"),!0):!1},injectTestMessage(n){!C&&M&&ne(!0,"system"),$.injectTestEvent(n)},getMessages(){return $.getMessages()},getStatus(){return $.getStatus()},getPersistentMetadata(){return{...l}},updatePersistentMetadata(n){h(n)},on(n,m){return o.on(n,m)},off(n,m){o.off(n,m)},isOpen(){return M&&C},isVoiceActive(){return it.active},getState(){return{open:M&&C,launcherEnabled:M,voiceActive:it.active,streaming:$.isStreaming()}},destroy(){Dt.forEach(n=>n()),Y.remove(),g==null||g.destroy(),B==null||B.remove(),Xt&&U.removeEventListener("click",Xt)}};if((((wA=r==null?void 0:r.debugTools)!=null?wA:!1)||!!e.debug)&&typeof window!="undefined"){let n=window.AgentWidgetBrowser,m={controller:St,getMessages:St.getMessages,getStatus:St.getStatus,getMetadata:St.getPersistentMetadata,updateMetadata:St.updatePersistentMetadata,clearHistory:()=>St.clearChat(),setVoiceActive:H=>H?St.startVoiceRecognition():St.stopVoiceRecognition()};window.AgentWidgetBrowser=m,Dt.push(()=>{window.AgentWidgetBrowser===m&&(window.AgentWidgetBrowser=n)})}return St};var uA={},Ak=a=>{if(typeof window=="undefined"||typeof document=="undefined")throw new Error("Chat widget can only be mounted in a browser environment");if(typeof a=="string"){let t=document.querySelector(a);if(!t)throw new Error(`Chat widget target "${a}" was not found`);return t}return a},bk=()=>{try{if(typeof uA!="undefined"&&uA.url)return new URL("../widget.css",uA.url).href}catch{}return null},pH=a=>{let t=bk(),r=()=>{if(!(a instanceof ShadowRoot)||a.querySelector("link[data-vanilla-agent]"))return;let e=document.head.querySelector("link[data-vanilla-agent]");if(!e)return;let s=e.cloneNode(!0);a.insertBefore(s,a.firstChild)};if(a instanceof ShadowRoot)if(t){let e=document.createElement("link");e.rel="stylesheet",e.href=t,e.setAttribute("data-vanilla-agent","true"),a.insertBefore(e,a.firstChild)}else r();else if(!document.head.querySelector("link[data-vanilla-agent]")&&t){let s=document.createElement("link");s.rel="stylesheet",s.href=t,s.setAttribute("data-vanilla-agent","true"),document.head.appendChild(s)}},cA=a=>{var f,h,c,i;let t=Ak(a.target),r=document.createElement("div");r.className="vanilla-agent-host";let e=(c=(h=(f=a.config)==null?void 0:f.launcher)==null?void 0:h.enabled)!=null?c:!0;e||(r.style.height="100%",r.style.display="flex",r.style.flexDirection="column"),t.appendChild(r);let s=a.useShadowDom===!0,o,d;if(s){let u=r.attachShadow({mode:"open"});d=u,o=document.createElement("div"),o.id="vanilla-agent-root",e||(o.style.height="100%",o.style.display="flex",o.style.flexDirection="column",o.style.flex="1",o.style.minHeight="0"),u.appendChild(o),pH(u)}else d=r,o=document.createElement("div"),o.id="vanilla-agent-root",e||(o.style.height="100%",o.style.display="flex",o.style.flexDirection="column",o.style.flex="1",o.style.minHeight="0"),r.appendChild(o),pH(r);let l=VS(o,a.config,{debugTools:a.debugTools});(i=a.onReady)==null||i.call(a);let p={...l,host:r,destroy(){l.destroy(),r.remove(),a.windowKey&&typeof window!="undefined"&&delete window[a.windowKey]}};return a.windowKey&&typeof window!="undefined"&&(window[a.windowKey]=p),p};function Hk(a){if(!a)return null;let t=a.toString();return t.includes("createJsonStreamParser")||t.includes("partial-json")?"json":t.includes("createRegexJsonParser")||t.includes("regex")?"regex-json":t.includes("createXmlParser")||t.includes("<text>")?"xml":null}function RS(a){var t,r;return(r=(t=a.parserType)!=null?t:Hk(a.streamParser))!=null?r:"plain"}function nH(a,t="esm"){let r={...a};return delete r.postprocessMessage,delete r.initialMessages,t==="esm"?kk(r):t==="script-installer"?Bk(r):t==="script-advanced"?Vk(r):t==="react-component"?Lk(r):t==="react-advanced"?Tk(r):Pk(r)}function kk(a){let t=RS(a),r=t!=="plain",e=["import 'vanilla-agent/widget.css';","import { initAgentWidget, markdownPostprocessor } from 'vanilla-agent';","","initAgentWidget({"," target: 'body',"," config: {"];return a.apiUrl&&e.push(` apiUrl: "${a.apiUrl}",`),a.flowId&&e.push(` flowId: "${a.flowId}",`),r&&e.push(` parserType: "${t}",`),a.theme&&(e.push(" theme: {"),Object.entries(a.theme).forEach(([s,o])=>{e.push(` ${s}: "${o}",`)}),e.push(" },")),a.launcher&&(e.push(" launcher: {"),Object.entries(a.launcher).forEach(([s,o])=>{typeof o=="string"?e.push(` ${s}: "${o}",`):typeof o=="boolean"&&e.push(` ${s}: ${o},`)}),e.push(" },")),a.copy&&(e.push(" copy: {"),Object.entries(a.copy).forEach(([s,o])=>{e.push(` ${s}: "${o}",`)}),e.push(" },")),a.sendButton&&(e.push(" sendButton: {"),Object.entries(a.sendButton).forEach(([s,o])=>{typeof o=="string"?e.push(` ${s}: "${o}",`):typeof o=="boolean"&&e.push(` ${s}: ${o},`)}),e.push(" },")),a.voiceRecognition&&(e.push(" voiceRecognition: {"),Object.entries(a.voiceRecognition).forEach(([s,o])=>{typeof o=="string"?e.push(` ${s}: "${o}",`):typeof o=="boolean"?e.push(` ${s}: ${o},`):typeof o=="number"&&e.push(` ${s}: ${o},`)}),e.push(" },")),a.statusIndicator&&(e.push(" statusIndicator: {"),Object.entries(a.statusIndicator).forEach(([s,o])=>{typeof o=="string"?e.push(` ${s}: "${o}",`):typeof o=="boolean"&&e.push(` ${s}: ${o},`)}),e.push(" },")),a.features&&(e.push(" features: {"),Object.entries(a.features).forEach(([s,o])=>{e.push(` ${s}: ${o},`)}),e.push(" },")),a.suggestionChips&&a.suggestionChips.length>0&&(e.push(" suggestionChips: ["),a.suggestionChips.forEach(s=>{e.push(` "${s}",`)}),e.push(" ],")),a.suggestionChipsConfig&&(e.push(" suggestionChipsConfig: {"),a.suggestionChipsConfig.fontFamily&&e.push(` fontFamily: "${a.suggestionChipsConfig.fontFamily}",`),a.suggestionChipsConfig.fontWeight&&e.push(` fontWeight: "${a.suggestionChipsConfig.fontWeight}",`),a.suggestionChipsConfig.paddingX&&e.push(` paddingX: "${a.suggestionChipsConfig.paddingX}",`),a.suggestionChipsConfig.paddingY&&e.push(` paddingY: "${a.suggestionChipsConfig.paddingY}",`),e.push(" },")),a.debug&&e.push(` debug: ${a.debug},`),e.push(" postprocessMessage: ({ text }) => markdownPostprocessor(text)"),e.push(" }"),e.push("});"),e.join(`
|
|
105
|
+
`}let bt="max-height: -moz-available !important; max-height: stretch !important;",pt=n?"":"padding-top: 1.25em !important;";Y.style.cssText+=bt+pt};Ae(),KS(a,e);let Dt=[],le=tH(ht),Xt=null,$,ce=!1,Qt=!0,Pt=0,Gt=0,J=null,kt=!1,Rt=0,Jt=!1,pe=125,Be=2e3,Ie=5,ye=50,Pe=new Map,it={active:!1,manuallyDeactivated:!1,lastUserMessageWasVoice:!1},oa=(yA=(vA=e.voiceRecognition)==null?void 0:vA.autoResume)!=null?yA:!1,qe=n=>{o.emit("voice:state",{active:it.active,source:n,timestamp:Date.now()})},Ct=()=>{h(n=>({...n,voiceState:{active:it.active,timestamp:Date.now(),manuallyDeactivated:it.manuallyDeactivated}}))},be=()=>{var I,V;if(((I=e.voiceRecognition)==null?void 0:I.enabled)===!1)return;let n=fA(l.voiceState),m=!!n.active,H=Number((V=n.timestamp)!=null?V:0);it.manuallyDeactivated=!!n.manuallyDeactivated,m&&Date.now()-H<Sk&&setTimeout(()=>{it.active||(it.manuallyDeactivated=!1,zt("restore"))},1e3)},Ve=()=>$?dH($.getMessages()).filter(n=>!n.__skipPersist):[];function Ue(n){if(!(d!=null&&d.save))return;let H={messages:n?dH(n):$?Ve():[],metadata:l};try{let I=d.save(H);I instanceof Promise&&I.catch(V=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",V)})}catch(I){typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",I)}}let He=(n=!1)=>{if(!Qt)return;let m=Date.now();kt&&m<Rt&&!n||(kt&&m>=Rt&&(kt=!1),!(!n&&!ce)&&(m-Gt<pe||(Gt=m,J&&cancelAnimationFrame(J),J=requestAnimationFrame(()=>{kt||!Qt||(Jt=!0,Z.scrollTop=Z.scrollHeight,Pt=Z.scrollTop,requestAnimationFrame(()=>{Jt=!1}),J=null)}))))},Fe=null,K2=()=>Y.querySelector("#vanilla-agent-scroll-container")||Z,j2=(n,m=500)=>{let H=n.scrollTop,I=n.clientHeight,V=n.scrollHeight,at=V-H;if(H+I>=V-2||Math.abs(at)<5)return;Fe!==null&&(cancelAnimationFrame(Fe),Fe=null);let w=performance.now(),_=R=>1-Math.pow(1-R,3),q=R=>{let N=n.scrollHeight;N!==V&&(V=N,at=V-H);let Ot=R-w,bt=Math.min(Ot/m,1),pt=_(bt),Ut=H+at*pt;n.scrollTop=Ut,bt<1?Fe=requestAnimationFrame(q):(n.scrollTop=n.scrollHeight,Fe=null)};Fe=requestAnimationFrame(q)},Y2=n=>{let m=new Map;n.forEach(H=>{let I=Pe.get(H.id);m.set(H.id,{streaming:H.streaming,role:H.role}),!I&&H.role==="assistant"&&o.emit("assistant:message",H),H.role==="assistant"&&(I!=null&&I.streaming)&&H.streaming===!1&&o.emit("assistant:complete",H)}),Pe.clear(),m.forEach((H,I)=>{Pe.set(I,H)})},sa=(n,m,H)=>{n.innerHTML="";let I=document.createDocumentFragment();m.forEach(w=>{var Ot,bt;let _=null,q=s.find(pt=>!!(w.variant==="reasoning"&&pt.renderReasoning||w.variant==="tool"&&pt.renderToolCall||!w.variant&&pt.renderMessage)),R=(Ot=e.layout)==null?void 0:Ot.messages;if(q)if(w.variant==="reasoning"&&w.reasoning&&q.renderReasoning){if(!S)return;_=q.renderReasoning({message:w,defaultRenderer:()=>sA(w),config:e})}else if(w.variant==="tool"&&w.toolCall&&q.renderToolCall){if(!G)return;_=q.renderToolCall({message:w,defaultRenderer:()=>lA(w,e),config:e})}else q.renderMessage&&(_=q.renderMessage({message:w,defaultRenderer:()=>{let pt=B2(w,H,R);return w.role!=="user"&&pA(pt,w,e,$),pt},config:e}));if(!_&&w.role==="assistant"&&!w.variant&&e.enableComponentStreaming!==!1&&BS(w)){let Ut=PS(w);if(Ut){let xe=TS(Ut,{config:e,message:w,transform:H});if(xe){let st=document.createElement("div");if(st.className=["vanilla-message-bubble","tvw-max-w-[85%]","tvw-rounded-2xl","tvw-bg-cw-surface","tvw-border","tvw-border-cw-message-border","tvw-p-4"].join(" "),st.setAttribute("data-message-id",w.id),w.content&&w.content.trim()){let me=document.createElement("div");me.className="tvw-mb-3 tvw-text-sm tvw-leading-relaxed",me.innerHTML=H({text:w.content,message:w,streaming:!!w.streaming,raw:w.rawContent}),st.appendChild(me)}st.appendChild(xe),_=st}}}if(!_)if(w.variant==="reasoning"&&w.reasoning){if(!S)return;_=sA(w)}else if(w.variant==="tool"&&w.toolCall){if(!G)return;_=lA(w,e)}else{let pt=(bt=e.layout)==null?void 0:bt.messages;pt!=null&&pt.renderUserMessage&&w.role==="user"?_=pt.renderUserMessage({message:w,config:e,streaming:!!w.streaming}):pt!=null&&pt.renderAssistantMessage&&w.role==="assistant"?_=pt.renderAssistantMessage({message:w,config:e,streaming:!!w.streaming}):_=B2(w,H,pt),w.role!=="user"&&_&&pA(_,w,e,$)}let N=document.createElement("div");N.className="tvw-flex",w.role==="user"&&N.classList.add("tvw-justify-end"),N.appendChild(_),I.appendChild(N)});let V=m.some(w=>w.role==="assistant"&&w.streaming),at=m[m.length-1],P=(at==null?void 0:at.role)==="assistant"&&!at.streaming;if(ce&&m.some(w=>w.role==="user")&&!V&&!P){let w=Z2(),_=document.createElement("div");_.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(" "),_.appendChild(w);let q=document.createElement("div");q.className="tvw-flex",q.appendChild(_),I.appendChild(q)}n.appendChild(I),requestAnimationFrame(()=>{requestAnimationFrame(()=>{let w=K2();j2(w)})})},da=()=>{M&&(C?(Y.classList.remove("tvw-pointer-events-none","tvw-opacity-0"),b.classList.remove("tvw-scale-95","tvw-opacity-0"),b.classList.add("tvw-scale-100","tvw-opacity-100"),g?g.element.style.display="none":B&&(B.style.display="none")):(Y.classList.add("tvw-pointer-events-none","tvw-opacity-0"),b.classList.remove("tvw-scale-100","tvw-opacity-100"),b.classList.add("tvw-scale-95","tvw-opacity-0"),g?g.element.style.display="":B&&(B.style.display="")))},ne=(n,m="user")=>{if(!M||C===n)return;let H=C;C=n,da(),C&&(yt(),He(!0));let I={open:C,source:m,timestamp:Date.now()};C&&!H?o.emit("widget:opened",I):!C&&H&&o.emit("widget:closed",I),o.emit("widget:state",{open:C,launcherEnabled:M,voiceActive:it.active,streaming:$.isStreaming()})},ma=n=>{z.disabled=n,L&&(L.disabled=n),le.buttons.forEach(m=>{m.disabled=n})},E2=()=>{var V,at,P,w,_,q,R,N,Ot,bt,pt,Ut,xe,st;Le.textContent=(at=(V=e.copy)==null?void 0:V.welcomeTitle)!=null?at:"Hello \u{1F44B}",Te.textContent=(w=(P=e.copy)==null?void 0:P.welcomeSubtitle)!=null?w:"Ask anything about your account or products.",ot.placeholder=(q=(_=e.copy)==null?void 0:_.inputPlaceholder)!=null?q:"How can I help...",((N=(R=e.sendButton)==null?void 0:R.useIcon)!=null?N:!1)||(z.textContent=(bt=(Ot=e.copy)==null?void 0:Ot.sendButtonLabel)!=null?bt:"Send");let m=(Ut=(pt=e.theme)==null?void 0:pt.inputFontFamily)!=null?Ut:"sans-serif",H=(st=(xe=e.theme)==null?void 0:xe.inputFontWeight)!=null?st:"400",I=me=>{switch(me){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'}};ot.style.fontFamily=I(m),ot.style.fontWeight=H};$=new ya(e,{onMessagesChanged(n){sa(Q,n,E),$&&(n.some(I=>I.role==="user")?le.render([],$,ot,n):le.render(e.suggestionChips,$,ot,n,e.suggestionChipsConfig)),He(!ce),Y2(n);let m=[...n].reverse().find(H=>H.role==="user");it.lastUserMessageWasVoice=!!(m!=null&&m.viaVoice),Ue(n)},onStatusChanged(n){var I;let m=(I=e.statusIndicator)!=null?I:{},H=V=>{var at,P,w,_;return V==="idle"?(at=m.idleText)!=null?at:Kt.idle:V==="connecting"?(P=m.connectingText)!=null?P:Kt.connecting:V==="connected"?(w=m.connectedText)!=null?w:Kt.connected:V==="error"?(_=m.errorText)!=null?_:Kt.error:Kt[V]};se.textContent=H(n)},onStreamingChanged(n){ce=n,ma(n),$&&sa(Q,$.getMessages(),E),n||He(!0)}}),p&&p.then(n=>{var m;n&&(n.metadata&&(l=fA(n.metadata),u.syncFromMetadata()),(m=n.messages)!=null&&m.length&&$.hydrateMessages(n.messages))}).catch(n=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to hydrate stored state:",n)});let F2=n=>{n.preventDefault();let m=ot.value.trim();m&&(ot.value="",$.sendMessage(m))},D2=n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),z.click())},y=null,K=!1,rt=null,vt=null,Wt=()=>typeof window=="undefined"?null:window.webkitSpeechRecognition||window.SpeechRecognition||null,zt=(n="user")=>{var at,P,w,_;if(K||$.isStreaming())return;let m=Wt();if(!m)return;y=new m;let I=(P=((at=e.voiceRecognition)!=null?at:{}).pauseDuration)!=null?P:2e3;y.continuous=!0,y.interimResults=!0,y.lang="en-US";let V=ot.value;y.onresult=q=>{let R="",N="";for(let bt=0;bt<q.results.length;bt++){let pt=q.results[bt],Ut=pt[0].transcript;pt.isFinal?R+=Ut+" ":N=Ut}let Ot=V+R+N;ot.value=Ot,rt&&clearTimeout(rt),(R||N)&&(rt=window.setTimeout(()=>{let bt=ot.value.trim();bt&&y&&K&&(ft(),ot.value="",$.sendMessage(bt,{viaVoice:!0}))},I))},y.onerror=q=>{q.error!=="no-speech"&&ft()},y.onend=()=>{if(K){let q=ot.value.trim();q&&q!==V.trim()&&(ot.value="",$.sendMessage(q,{viaVoice:!0})),ft()}};try{if(y.start(),K=!0,it.active=!0,n!=="system"&&(it.manuallyDeactivated=!1),qe(n),Ct(),L){vt={backgroundColor:L.style.backgroundColor,color:L.style.color,borderColor:L.style.borderColor};let q=(w=e.voiceRecognition)!=null?w:{},R=(_=q.recordingBackgroundColor)!=null?_:"#ef4444",N=q.recordingIconColor,Ot=q.recordingBorderColor;if(L.classList.add("tvw-voice-recording"),L.style.backgroundColor=R,N){L.style.color=N;let bt=L.querySelector("svg");bt&&bt.setAttribute("stroke",N)}Ot&&(L.style.borderColor=Ot),L.setAttribute("aria-label","Stop voice recognition")}}catch{ft("system")}},ft=(n="user")=>{if(K){if(K=!1,rt&&(clearTimeout(rt),rt=null),y){try{y.stop()}catch{}y=null}if(it.active=!1,qe(n),Ct(),L){if(L.classList.remove("tvw-voice-recording"),vt){L.style.backgroundColor=vt.backgroundColor,L.style.color=vt.color,L.style.borderColor=vt.borderColor;let m=L.querySelector("svg");m&&m.setAttribute("stroke",vt.color||"currentColor"),vt=null}L.setAttribute("aria-label","Start voice recognition")}}},T=(n,m)=>{var Ut,xe,st,me,$e,Ne,De;if(!(typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined")))return null;let I=x("div","tvw-send-button-wrapper"),V=x("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer");V.type="button",V.setAttribute("aria-label","Start voice recognition");let at=(Ut=n==null?void 0:n.iconName)!=null?Ut:"mic",P=(xe=m==null?void 0:m.size)!=null?xe:"40px",w=(st=n==null?void 0:n.iconSize)!=null?st:P,_=parseFloat(w)||24,q=(me=n==null?void 0:n.backgroundColor)!=null?me:m==null?void 0:m.backgroundColor,R=($e=n==null?void 0:n.iconColor)!=null?$e:m==null?void 0:m.textColor;V.style.width=w,V.style.height=w,V.style.minWidth=w,V.style.minHeight=w,V.style.fontSize="18px",V.style.lineHeight="1";let N=R||"currentColor",Ot=wt(at,_,N,1.5);Ot?(V.appendChild(Ot),V.style.color=N):(V.textContent="\u{1F3A4}",V.style.color=N),q?V.style.backgroundColor=q:V.classList.add("tvw-bg-cw-primary"),R?V.style.color=R:!R&&!(m!=null&&m.textColor)&&V.classList.add("tvw-text-white"),n!=null&&n.borderWidth&&(V.style.borderWidth=n.borderWidth,V.style.borderStyle="solid"),n!=null&&n.borderColor&&(V.style.borderColor=n.borderColor),n!=null&&n.paddingX&&(V.style.paddingLeft=n.paddingX,V.style.paddingRight=n.paddingX),n!=null&&n.paddingY&&(V.style.paddingTop=n.paddingY,V.style.paddingBottom=n.paddingY),I.appendChild(V);let bt=(Ne=n==null?void 0:n.tooltipText)!=null?Ne:"Start voice recognition";if(((De=n==null?void 0:n.showTooltip)!=null?De:!1)&&bt){let la=x("div","tvw-send-button-tooltip");la.textContent=bt,I.appendChild(la)}return{micButton:V,micButtonWrapper:I}},he=()=>{if(K){let n=ot.value.trim();it.manuallyDeactivated=!0,Ct(),ft("user"),n&&(ot.value="",$.sendMessage(n))}else it.manuallyDeactivated=!1,Ct(),zt("user")};L&&(L.addEventListener("click",he),Dt.push(()=>{ft("system"),L&&L.removeEventListener("click",he)}));let tt=o.on("assistant:complete",()=>{oa&&(it.active||it.manuallyDeactivated||oa==="assistant"&&!it.lastUserMessageWasVoice||setTimeout(()=>{!it.active&&!it.manuallyDeactivated&&zt("auto")},600))});Dt.push(tt);let A=()=>{ne(!C,"user")},g=null,B=null;if(M){let n=s.find(m=>m.renderLauncher);if(n!=null&&n.renderLauncher){let m=n.renderLauncher({config:e,defaultRenderer:()=>G2(e,A).element,onToggle:A});m&&(B=m)}B||(g=G2(e,A))}g?a.appendChild(g.element):B&&a.appendChild(B),da(),le.render(e.suggestionChips,$,ot,void 0,e.suggestionChipsConfig),E2(),ma($.isStreaming()),He(!0),be();let yt=()=>{var H,I,V,at,P,w;let n=(I=(H=e.launcher)==null?void 0:H.sidebarMode)!=null?I:!1,m=n||((at=(V=e.launcher)==null?void 0:V.fullHeight)!=null?at:!1);if(!M){b.style.height="",b.style.width="";return}if(!n){let _=(w=(P=e==null?void 0:e.launcher)==null?void 0:P.width)!=null?w:e==null?void 0:e.launcherWidth,q=_!=null?_:"min(400px, calc(100vw - 24px))";b.style.width=q,b.style.maxWidth=q}if(!m){let _=window.innerHeight,R=Math.max(200,_-64),N=Math.min(640,R);b.style.height=`${N}px`}};yt(),window.addEventListener("resize",yt),Dt.push(()=>window.removeEventListener("resize",yt)),Pt=Z.scrollTop;let Lt=()=>{let n=Z.scrollTop,m=Z.scrollHeight,H=Z.clientHeight,I=m-n-H,V=Math.abs(n-Pt);if(Pt=n,!Jt&&!(V<=Ie)){if(!Qt&&I<ye){kt=!1,Qt=!0;return}Qt&&I>ye&&(kt=!0,Rt=Date.now()+Be,Qt=!1)}};Z.addEventListener("scroll",Lt,{passive:!0}),Dt.push(()=>Z.removeEventListener("scroll",Lt)),Dt.push(()=>{J&&cancelAnimationFrame(J)});let te=()=>{U&&(Xt&&(U.removeEventListener("click",Xt),Xt=null),M?(U.style.display="",Xt=()=>{C=!1,da()},U.addEventListener("click",Xt)):U.style.display="none")};te(),(()=>{let{clearChatButton:n}=dt;n&&n.addEventListener("click",()=>{$.clearMessages();try{localStorage.removeItem(R2),e.debug&&console.log(`[AgentWidget] Cleared default localStorage key: ${R2}`)}catch(H){console.error("[AgentWidget] Failed to clear default localStorage:",H)}if(e.clearChatHistoryStorageKey&&e.clearChatHistoryStorageKey!==R2)try{localStorage.removeItem(e.clearChatHistoryStorageKey),e.debug&&console.log(`[AgentWidget] Cleared custom localStorage key: ${e.clearChatHistoryStorageKey}`)}catch(H){console.error("[AgentWidget] Failed to clear custom localStorage:",H)}let m=new CustomEvent("vanilla-agent:clear-chat",{detail:{timestamp:new Date().toISOString()}});if(window.dispatchEvent(m),d!=null&&d.clear)try{let H=d.clear();H instanceof Promise&&H.catch(I=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",I)})}catch(H){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",H)}l={},u.syncFromMetadata()})})(),jt.addEventListener("submit",F2),ot.addEventListener("keydown",D2),Dt.push(()=>{jt.removeEventListener("submit",F2),ot.removeEventListener("keydown",D2)}),Dt.push(()=>{$.cancel()}),g?Dt.push(()=>{g==null||g.destroy()}):B&&Dt.push(()=>{B==null||B.remove()});let St={update(n){var W2,z2,na,ts,CA,SA,AA,bA,HA,kA,LA,TA,BA,PA,VA,RA,EA,FA,DA,WA,zA,OA,IA,qA,UA,$A,NA,GA,ZA,_A,XA,JA,KA,jA,YA,QA,tb,eb,ab,rb,ob,sb,db,lb,pb,nb,hb,ib,fb,ub,cb,xb,mb,Mb,gb,vb,yb;let m=e.toolCall;e={...e,...n},Ae(),KS(a,e);let H=_2.getForInstance(e.plugins);if(s.length=0,s.push(...H),M=(z2=(W2=e.launcher)==null?void 0:W2.enabled)!=null?z2:!0,F=(ts=(na=e.launcher)==null?void 0:na.autoExpand)!=null?ts:!1,S=(SA=(CA=e.features)==null?void 0:CA.showReasoning)!=null?SA:!0,G=(bA=(AA=e.features)==null?void 0:AA.showToolCalls)!=null?bA:!0,((HA=e.launcher)==null?void 0:HA.enabled)===!1&&g&&(g.destroy(),g=null),((kA=e.launcher)==null?void 0:kA.enabled)===!1&&B&&(B.remove(),B=null),((LA=e.launcher)==null?void 0:LA.enabled)!==!1&&!g&&!B){let k=s.find(Mt=>Mt.renderLauncher);if(k!=null&&k.renderLauncher){let Mt=k.renderLauncher({config:e,defaultRenderer:()=>G2(e,A).element,onToggle:A});Mt&&(B=Mt,a.appendChild(B))}B||(g=G2(e,A),a.appendChild(g.element))}g&&g.update(e),Ce&&((TA=e.launcher)==null?void 0:TA.title)!==void 0&&(Ce.textContent=e.launcher.title),Se&&((BA=e.launcher)==null?void 0:BA.subtitle)!==void 0&&(Se.textContent=e.launcher.subtitle),M!==v?M?ne(F,"auto"):(C=!0,da()):F!==O&&ne(F,"auto"),O=F,v=M,yt(),te(),JSON.stringify(n.toolCall)!==JSON.stringify(m)&&$&&sa(Q,$.getMessages(),E);let P=(PA=e.launcher)!=null?PA:{},w=(VA=P.headerIconHidden)!=null?VA:!1,_=P.headerIconName,q=(RA=P.headerIconSize)!=null?RA:"48px";if(mt){let k=X.querySelector(".tvw-border-b-cw-divider"),Mt=k==null?void 0:k.querySelector(".tvw-flex-col");if(w)mt.style.display="none",k&&Mt&&!k.contains(Mt)&&k.insertBefore(Mt,k.firstChild);else{if(mt.style.display="",mt.style.height=q,mt.style.width=q,k&&Mt&&(k.contains(mt)?mt.nextSibling!==Mt&&(mt.remove(),k.insertBefore(mt,Mt)):k.insertBefore(mt,Mt)),_){let Bt=parseFloat(q)||24,At=wt(_,Bt*.6,"#ffffff",2);At?mt.replaceChildren(At):mt.textContent=(EA=P.agentIconText)!=null?EA:"\u{1F4AC}"}else if(P.iconUrl){let Bt=mt.querySelector("img");if(Bt)Bt.src=P.iconUrl,Bt.style.height=q,Bt.style.width=q;else{let At=document.createElement("img");At.src=P.iconUrl,At.alt="",At.className="tvw-rounded-xl tvw-object-cover",At.style.height=q,At.style.width=q,mt.replaceChildren(At)}}else{let Bt=mt.querySelector("svg"),At=mt.querySelector("img");(Bt||At)&&mt.replaceChildren(),mt.textContent=(FA=P.agentIconText)!=null?FA:"\u{1F4AC}"}let et=mt.querySelector("img");et&&(et.style.height=q,et.style.width=q)}}if(U){let k=(DA=P.closeButtonSize)!=null?DA:"32px",Mt=(WA=P.closeButtonPlacement)!=null?WA:"inline";U.style.height=k,U.style.width=k;let{closeButtonWrapper:et}=dt,Bt=Mt==="top-right",At=et==null?void 0:et.classList.contains("tvw-absolute");if(et&&Bt!==At)if(et.remove(),Bt)et.className="tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50",X.style.position="relative",X.appendChild(et);else{let xt=(OA=(zA=P.clearChat)==null?void 0:zA.placement)!=null?OA:"inline",ae=(qA=(IA=P.clearChat)==null?void 0:IA.enabled)!=null?qA:!0;et.className=ae&&xt==="inline"?"":"tvw-ml-auto";let re=X.querySelector(".tvw-border-b-cw-divider");re&&re.appendChild(et)}if(P.closeButtonColor?(U.style.color=P.closeButtonColor,U.classList.remove("tvw-text-cw-muted")):(U.style.color="",U.classList.add("tvw-text-cw-muted")),P.closeButtonBackgroundColor?(U.style.backgroundColor=P.closeButtonBackgroundColor,U.classList.remove("hover:tvw-bg-gray-100")):(U.style.backgroundColor="",U.classList.add("hover:tvw-bg-gray-100")),P.closeButtonBorderWidth||P.closeButtonBorderColor){let xt=P.closeButtonBorderWidth||"0px",ae=P.closeButtonBorderColor||"transparent";U.style.border=`${xt} solid ${ae}`,U.classList.remove("tvw-border-none")}else U.style.border="",U.classList.add("tvw-border-none");P.closeButtonBorderRadius?(U.style.borderRadius=P.closeButtonBorderRadius,U.classList.remove("tvw-rounded-full")):(U.style.borderRadius="",U.classList.add("tvw-rounded-full")),P.closeButtonPaddingX?(U.style.paddingLeft=P.closeButtonPaddingX,U.style.paddingRight=P.closeButtonPaddingX):(U.style.paddingLeft="",U.style.paddingRight=""),P.closeButtonPaddingY?(U.style.paddingTop=P.closeButtonPaddingY,U.style.paddingBottom=P.closeButtonPaddingY):(U.style.paddingTop="",U.style.paddingBottom="");let ee=(UA=P.closeButtonIconName)!=null?UA:"x",Nt=($A=P.closeButtonIconText)!=null?$A:"\xD7";U.innerHTML="";let ge=wt(ee,"20px",P.closeButtonColor||"",2);ge?U.appendChild(ge):U.textContent=Nt;let Xe=(NA=P.closeButtonTooltipText)!=null?NA:"Close chat",Tt=(GA=P.closeButtonShowTooltip)!=null?GA:!0;if(U.setAttribute("aria-label",Xe),et&&(et._cleanupTooltip&&(et._cleanupTooltip(),delete et._cleanupTooltip),Tt&&Xe)){let xt=null,ae=()=>{if(xt||!U)return;xt=x("div","tvw-clear-chat-tooltip"),xt.textContent=Xe;let Ma=x("div");Ma.className="tvw-clear-chat-tooltip-arrow",xt.appendChild(Ma);let FS=U.getBoundingClientRect();xt.style.position="fixed",xt.style.left=`${FS.left+FS.width/2}px`,xt.style.top=`${FS.top-8}px`,xt.style.transform="translate(-50%, -100%)",document.body.appendChild(xt)},re=()=>{xt&&xt.parentNode&&(xt.parentNode.removeChild(xt),xt=null)};et.addEventListener("mouseenter",ae),et.addEventListener("mouseleave",re),U.addEventListener("focus",ae),U.addEventListener("blur",re),et._cleanupTooltip=()=>{re(),et&&(et.removeEventListener("mouseenter",ae),et.removeEventListener("mouseleave",re)),U&&(U.removeEventListener("focus",ae),U.removeEventListener("blur",re))}}}let{clearChatButton:R,clearChatButtonWrapper:N}=dt;if(R){let k=(ZA=P.clearChat)!=null?ZA:{},Mt=(_A=k.enabled)!=null?_A:!0,et=(XA=k.placement)!=null?XA:"inline";if(N){N.style.display=Mt?"":"none";let Bt=et==="top-right",At=N.classList.contains("tvw-absolute");if(Bt!==At&&Mt){if(N.remove(),Bt)N.className="tvw-absolute tvw-top-4 tvw-z-50",N.style.right="48px",X.style.position="relative",X.appendChild(N);else{N.className="tvw-relative tvw-ml-auto tvw-clear-chat-button-wrapper",N.style.right="";let Nt=X.querySelector(".tvw-border-b-cw-divider"),ge=dt.closeButtonWrapper;Nt&&ge&&ge.parentElement===Nt?Nt.insertBefore(N,ge):Nt&&Nt.appendChild(N)}let ee=dt.closeButtonWrapper;ee&&!ee.classList.contains("tvw-absolute")&&(Bt?ee.classList.add("tvw-ml-auto"):ee.classList.remove("tvw-ml-auto"))}}if(Mt){let Bt=(JA=k.size)!=null?JA:"32px";R.style.height=Bt,R.style.width=Bt;let At=(KA=k.iconName)!=null?KA:"refresh-cw",ee=(jA=k.iconColor)!=null?jA:"";R.innerHTML="";let Nt=wt(At,"20px",ee||"",2);if(Nt&&R.appendChild(Nt),ee?(R.style.color=ee,R.classList.remove("tvw-text-cw-muted")):(R.style.color="",R.classList.add("tvw-text-cw-muted")),k.backgroundColor?(R.style.backgroundColor=k.backgroundColor,R.classList.remove("hover:tvw-bg-gray-100")):(R.style.backgroundColor="",R.classList.add("hover:tvw-bg-gray-100")),k.borderWidth||k.borderColor){let Tt=k.borderWidth||"0px",xt=k.borderColor||"transparent";R.style.border=`${Tt} solid ${xt}`,R.classList.remove("tvw-border-none")}else R.style.border="",R.classList.add("tvw-border-none");k.borderRadius?(R.style.borderRadius=k.borderRadius,R.classList.remove("tvw-rounded-full")):(R.style.borderRadius="",R.classList.add("tvw-rounded-full")),k.paddingX?(R.style.paddingLeft=k.paddingX,R.style.paddingRight=k.paddingX):(R.style.paddingLeft="",R.style.paddingRight=""),k.paddingY?(R.style.paddingTop=k.paddingY,R.style.paddingBottom=k.paddingY):(R.style.paddingTop="",R.style.paddingBottom="");let ge=(YA=k.tooltipText)!=null?YA:"Clear chat",Xe=(QA=k.showTooltip)!=null?QA:!0;if(R.setAttribute("aria-label",ge),N&&(N._cleanupTooltip&&(N._cleanupTooltip(),delete N._cleanupTooltip),Xe&&ge)){let Tt=null,xt=()=>{if(Tt||!R)return;Tt=x("div","tvw-clear-chat-tooltip"),Tt.textContent=ge;let re=x("div");re.className="tvw-clear-chat-tooltip-arrow",Tt.appendChild(re);let Ma=R.getBoundingClientRect();Tt.style.position="fixed",Tt.style.left=`${Ma.left+Ma.width/2}px`,Tt.style.top=`${Ma.top-8}px`,Tt.style.transform="translate(-50%, -100%)",document.body.appendChild(Tt)},ae=()=>{Tt&&Tt.parentNode&&(Tt.parentNode.removeChild(Tt),Tt=null)};N.addEventListener("mouseenter",xt),N.addEventListener("mouseleave",ae),R.addEventListener("focus",xt),R.addEventListener("blur",ae),N._cleanupTooltip=()=>{ae(),N&&(N.removeEventListener("mouseenter",xt),N.removeEventListener("mouseleave",ae)),R&&(R.removeEventListener("focus",xt),R.removeEventListener("blur",ae))}}}}let Ot=e.actionParsers&&e.actionParsers.length?e.actionParsers:[X2],bt=e.actionHandlers&&e.actionHandlers.length?e.actionHandlers:[xa.message,xa.messageAndClick];u=J2({parsers:Ot,handlers:bt,getMetadata:f,updateMetadata:h,emit:o.emit,documentRef:typeof document!="undefined"?document:null}),E=lH(e,u),$.updateConfig(e),sa(Q,$.getMessages(),E),le.render(e.suggestionChips,$,ot,void 0,e.suggestionChipsConfig),E2(),ma($.isStreaming());let pt=((tb=e.voiceRecognition)==null?void 0:tb.enabled)===!0,Ut=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined"),xe=pt&&Ut;if(jt.classList.remove("tvw-gap-1","tvw-gap-3"),jt.classList.add(xe?"tvw-gap-1":"tvw-gap-3"),pt&&Ut)if(!L||!Vt){let k=T(e.voiceRecognition,e.sendButton);k&&(L=k.micButton,Vt=k.micButtonWrapper,jt.insertBefore(Vt,_t),L.addEventListener("click",he),L.disabled=$.isStreaming())}else{let k=(eb=e.voiceRecognition)!=null?eb:{},Mt=(ab=e.sendButton)!=null?ab:{},et=(rb=k.iconName)!=null?rb:"mic",Bt=(ob=Mt.size)!=null?ob:"40px",At=(sb=k.iconSize)!=null?sb:Bt,ee=parseFloat(At)||24;L.style.width=At,L.style.height=At,L.style.minWidth=At,L.style.minHeight=At;let Nt=(lb=(db=k.iconColor)!=null?db:Mt.textColor)!=null?lb:"currentColor";L.innerHTML="";let ge=wt(et,ee,Nt,2);ge?L.appendChild(ge):L.textContent="\u{1F3A4}";let Xe=(pb=k.backgroundColor)!=null?pb:Mt.backgroundColor;Xe?(L.style.backgroundColor=Xe,L.classList.remove("tvw-bg-cw-primary")):(L.style.backgroundColor="",L.classList.add("tvw-bg-cw-primary")),Nt?(L.style.color=Nt,L.classList.remove("tvw-text-white")):!Nt&&!Mt.textColor&&(L.style.color="",L.classList.add("tvw-text-white")),k.borderWidth?(L.style.borderWidth=k.borderWidth,L.style.borderStyle="solid"):(L.style.borderWidth="",L.style.borderStyle=""),k.borderColor?L.style.borderColor=k.borderColor:L.style.borderColor="",k.paddingX?(L.style.paddingLeft=k.paddingX,L.style.paddingRight=k.paddingX):(L.style.paddingLeft="",L.style.paddingRight=""),k.paddingY?(L.style.paddingTop=k.paddingY,L.style.paddingBottom=k.paddingY):(L.style.paddingTop="",L.style.paddingBottom="");let Tt=Vt==null?void 0:Vt.querySelector(".tvw-send-button-tooltip"),xt=(nb=k.tooltipText)!=null?nb:"Start voice recognition";if(((hb=k.showTooltip)!=null?hb:!1)&&xt)if(Tt)Tt.textContent=xt,Tt.style.display="";else{let re=document.createElement("div");re.className="tvw-send-button-tooltip",re.textContent=xt,Vt==null||Vt.insertBefore(re,L)}else Tt&&(Tt.style.display="none");Vt.style.display="",L.disabled=$.isStreaming()}else L&&Vt&&(Vt.style.display="none",K&&ft());let st=(ib=e.sendButton)!=null?ib:{},me=(fb=st.useIcon)!=null?fb:!1,$e=(ub=st.iconText)!=null?ub:"\u2191",Ne=st.iconName,De=(cb=st.tooltipText)!=null?cb:"Send message",la=(xb=st.showTooltip)!=null?xb:!1,Ge=(mb=st.size)!=null?mb:"40px",pa=st.backgroundColor,Me=st.textColor;if(me){if(z.style.width=Ge,z.style.height=Ge,z.style.minWidth=Ge,z.style.minHeight=Ge,z.style.fontSize="18px",z.style.lineHeight="1",z.innerHTML="",Ne){let k=parseFloat(Ge)||24,Mt=Me&&typeof Me=="string"&&Me.trim()?Me.trim():"currentColor",et=wt(Ne,k,Mt,2);et?(z.appendChild(et),z.style.color=Mt):(z.textContent=$e,Me?z.style.color=Me:z.classList.add("tvw-text-white"))}else z.textContent=$e,Me?z.style.color=Me:z.classList.add("tvw-text-white");z.className="tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer",pa?(z.style.backgroundColor=pa,z.classList.remove("tvw-bg-cw-primary")):z.classList.add("tvw-bg-cw-primary")}else z.textContent=(gb=(Mb=e.copy)==null?void 0:Mb.sendButtonLabel)!=null?gb:"Send",z.style.width="",z.style.height="",z.style.minWidth="",z.style.minHeight="",z.style.fontSize="",z.style.lineHeight="",z.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",pa?(z.style.backgroundColor=pa,z.classList.remove("tvw-bg-cw-accent")):z.classList.add("tvw-bg-cw-accent"),Me?z.style.color=Me:z.classList.add("tvw-text-white");st.borderWidth?(z.style.borderWidth=st.borderWidth,z.style.borderStyle="solid"):(z.style.borderWidth="",z.style.borderStyle=""),st.borderColor?z.style.borderColor=st.borderColor:z.style.borderColor="",st.paddingX?(z.style.paddingLeft=st.paddingX,z.style.paddingRight=st.paddingX):(z.style.paddingLeft="",z.style.paddingRight=""),st.paddingY?(z.style.paddingTop=st.paddingY,z.style.paddingBottom=st.paddingY):(z.style.paddingTop="",z.style.paddingBottom="");let Ze=_t==null?void 0:_t.querySelector(".tvw-send-button-tooltip");if(la&&De)if(Ze)Ze.textContent=De,Ze.style.display="";else{let k=document.createElement("div");k.className="tvw-send-button-tooltip",k.textContent=De,_t==null||_t.insertBefore(k,z)}else Ze&&(Ze.style.display="none");let _e=(vb=e.statusIndicator)!=null?vb:{},Q2=(yb=_e.visible)!=null?yb:!0;if(se.style.display=Q2?"":"none",$){let k=$.getStatus(),Mt=et=>{var Bt,At,ee,Nt;return et==="idle"?(Bt=_e.idleText)!=null?Bt:Kt.idle:et==="connecting"?(At=_e.connectingText)!=null?At:Kt.connecting:et==="connected"?(ee=_e.connectedText)!=null?ee:Kt.connected:et==="error"?(Nt=_e.errorText)!=null?Nt:Kt.error:Kt[et]};se.textContent=Mt(k)}},open(){M&&ne(!0,"api")},close(){M&&ne(!1,"api")},toggle(){M&&ne(!C,"api")},clearChat(){$.clearMessages();try{localStorage.removeItem(R2),e.debug&&console.log(`[AgentWidget] Cleared default localStorage key: ${R2}`)}catch(m){console.error("[AgentWidget] Failed to clear default localStorage:",m)}if(e.clearChatHistoryStorageKey&&e.clearChatHistoryStorageKey!==R2)try{localStorage.removeItem(e.clearChatHistoryStorageKey),e.debug&&console.log(`[AgentWidget] Cleared custom localStorage key: ${e.clearChatHistoryStorageKey}`)}catch(m){console.error("[AgentWidget] Failed to clear custom localStorage:",m)}let n=new CustomEvent("vanilla-agent:clear-chat",{detail:{timestamp:new Date().toISOString()}});if(window.dispatchEvent(n),d!=null&&d.clear)try{let m=d.clear();m instanceof Promise&&m.catch(H=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",H)})}catch(m){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",m)}l={},u.syncFromMetadata()},setMessage(n){return!ot||$.isStreaming()?!1:(!C&&M&&ne(!0,"system"),ot.value=n,ot.dispatchEvent(new Event("input",{bubbles:!0})),!0)},submitMessage(n){if($.isStreaming())return!1;let m=(n==null?void 0:n.trim())||ot.value.trim();return m?(!C&&M&&ne(!0,"system"),ot.value="",$.sendMessage(m),!0):!1},startVoiceRecognition(){return K||$.isStreaming()||!Wt()?!1:(!C&&M&&ne(!0,"system"),it.manuallyDeactivated=!1,Ct(),zt("user"),!0)},stopVoiceRecognition(){return K?(it.manuallyDeactivated=!0,Ct(),ft("user"),!0):!1},injectTestMessage(n){!C&&M&&ne(!0,"system"),$.injectTestEvent(n)},getMessages(){return $.getMessages()},getStatus(){return $.getStatus()},getPersistentMetadata(){return{...l}},updatePersistentMetadata(n){h(n)},on(n,m){return o.on(n,m)},off(n,m){o.off(n,m)},isOpen(){return M&&C},isVoiceActive(){return it.active},getState(){return{open:M&&C,launcherEnabled:M,voiceActive:it.active,streaming:$.isStreaming()}},destroy(){Dt.forEach(n=>n()),Y.remove(),g==null||g.destroy(),B==null||B.remove(),Xt&&U.removeEventListener("click",Xt)}};if((((wA=r==null?void 0:r.debugTools)!=null?wA:!1)||!!e.debug)&&typeof window!="undefined"){let n=window.AgentWidgetBrowser,m={controller:St,getMessages:St.getMessages,getStatus:St.getStatus,getMetadata:St.getPersistentMetadata,updateMetadata:St.updatePersistentMetadata,clearHistory:()=>St.clearChat(),setVoiceActive:H=>H?St.startVoiceRecognition():St.stopVoiceRecognition()};window.AgentWidgetBrowser=m,Dt.push(()=>{window.AgentWidgetBrowser===m&&(window.AgentWidgetBrowser=n)})}return St};var uA={},Ak=a=>{if(typeof window=="undefined"||typeof document=="undefined")throw new Error("Chat widget can only be mounted in a browser environment");if(typeof a=="string"){let t=document.querySelector(a);if(!t)throw new Error(`Chat widget target "${a}" was not found`);return t}return a},bk=()=>{try{if(typeof uA!="undefined"&&uA.url)return new URL("../widget.css",uA.url).href}catch{}return null},pH=a=>{let t=bk(),r=()=>{if(!(a instanceof ShadowRoot)||a.querySelector("link[data-vanilla-agent]"))return;let e=document.head.querySelector("link[data-vanilla-agent]");if(!e)return;let s=e.cloneNode(!0);a.insertBefore(s,a.firstChild)};if(a instanceof ShadowRoot)if(t){let e=document.createElement("link");e.rel="stylesheet",e.href=t,e.setAttribute("data-vanilla-agent","true"),a.insertBefore(e,a.firstChild)}else r();else if(!document.head.querySelector("link[data-vanilla-agent]")&&t){let s=document.createElement("link");s.rel="stylesheet",s.href=t,s.setAttribute("data-vanilla-agent","true"),document.head.appendChild(s)}},cA=a=>{var f,h,c,i;let t=Ak(a.target),r=document.createElement("div");r.className="vanilla-agent-host";let e=(c=(h=(f=a.config)==null?void 0:f.launcher)==null?void 0:h.enabled)!=null?c:!0;e||(r.style.height="100%",r.style.display="flex",r.style.flexDirection="column"),t.appendChild(r);let s=a.useShadowDom===!0,o,d;if(s){let u=r.attachShadow({mode:"open"});d=u,o=document.createElement("div"),o.id="vanilla-agent-root",e||(o.style.height="100%",o.style.display="flex",o.style.flexDirection="column",o.style.flex="1",o.style.minHeight="0"),u.appendChild(o),pH(u)}else d=r,o=document.createElement("div"),o.id="vanilla-agent-root",e||(o.style.height="100%",o.style.display="flex",o.style.flexDirection="column",o.style.flex="1",o.style.minHeight="0"),r.appendChild(o),pH(r);let l=VS(o,a.config,{debugTools:a.debugTools});(i=a.onReady)==null||i.call(a);let p={...l,host:r,destroy(){l.destroy(),r.remove(),a.windowKey&&typeof window!="undefined"&&delete window[a.windowKey]}};return a.windowKey&&typeof window!="undefined"&&(window[a.windowKey]=p),p};function Hk(a){if(!a)return null;let t=a.toString();return t.includes("createJsonStreamParser")||t.includes("partial-json")?"json":t.includes("createRegexJsonParser")||t.includes("regex")?"regex-json":t.includes("createXmlParser")||t.includes("<text>")?"xml":null}function RS(a){var t,r;return(r=(t=a.parserType)!=null?t:Hk(a.streamParser))!=null?r:"plain"}function nH(a,t="esm"){let r={...a};return delete r.postprocessMessage,delete r.initialMessages,t==="esm"?kk(r):t==="script-installer"?Bk(r):t==="script-advanced"?Vk(r):t==="react-component"?Lk(r):t==="react-advanced"?Tk(r):Pk(r)}function kk(a){let t=RS(a),r=t!=="plain",e=["import 'vanilla-agent/widget.css';","import { initAgentWidget, markdownPostprocessor } from 'vanilla-agent';","","initAgentWidget({"," target: 'body',"," config: {"];return a.apiUrl&&e.push(` apiUrl: "${a.apiUrl}",`),a.flowId&&e.push(` flowId: "${a.flowId}",`),r&&e.push(` parserType: "${t}",`),a.theme&&(e.push(" theme: {"),Object.entries(a.theme).forEach(([s,o])=>{e.push(` ${s}: "${o}",`)}),e.push(" },")),a.launcher&&(e.push(" launcher: {"),Object.entries(a.launcher).forEach(([s,o])=>{typeof o=="string"?e.push(` ${s}: "${o}",`):typeof o=="boolean"&&e.push(` ${s}: ${o},`)}),e.push(" },")),a.copy&&(e.push(" copy: {"),Object.entries(a.copy).forEach(([s,o])=>{e.push(` ${s}: "${o}",`)}),e.push(" },")),a.sendButton&&(e.push(" sendButton: {"),Object.entries(a.sendButton).forEach(([s,o])=>{typeof o=="string"?e.push(` ${s}: "${o}",`):typeof o=="boolean"&&e.push(` ${s}: ${o},`)}),e.push(" },")),a.voiceRecognition&&(e.push(" voiceRecognition: {"),Object.entries(a.voiceRecognition).forEach(([s,o])=>{typeof o=="string"?e.push(` ${s}: "${o}",`):typeof o=="boolean"?e.push(` ${s}: ${o},`):typeof o=="number"&&e.push(` ${s}: ${o},`)}),e.push(" },")),a.statusIndicator&&(e.push(" statusIndicator: {"),Object.entries(a.statusIndicator).forEach(([s,o])=>{typeof o=="string"?e.push(` ${s}: "${o}",`):typeof o=="boolean"&&e.push(` ${s}: ${o},`)}),e.push(" },")),a.features&&(e.push(" features: {"),Object.entries(a.features).forEach(([s,o])=>{e.push(` ${s}: ${o},`)}),e.push(" },")),a.suggestionChips&&a.suggestionChips.length>0&&(e.push(" suggestionChips: ["),a.suggestionChips.forEach(s=>{e.push(` "${s}",`)}),e.push(" ],")),a.suggestionChipsConfig&&(e.push(" suggestionChipsConfig: {"),a.suggestionChipsConfig.fontFamily&&e.push(` fontFamily: "${a.suggestionChipsConfig.fontFamily}",`),a.suggestionChipsConfig.fontWeight&&e.push(` fontWeight: "${a.suggestionChipsConfig.fontWeight}",`),a.suggestionChipsConfig.paddingX&&e.push(` paddingX: "${a.suggestionChipsConfig.paddingX}",`),a.suggestionChipsConfig.paddingY&&e.push(` paddingY: "${a.suggestionChipsConfig.paddingY}",`),e.push(" },")),a.debug&&e.push(` debug: ${a.debug},`),e.push(" postprocessMessage: ({ text }) => markdownPostprocessor(text)"),e.push(" }"),e.push("});"),e.join(`
|
|
106
106
|
`)}function Lk(a){let t=RS(a),r=t!=="plain",e=["// ChatWidget.tsx","'use client'; // Required for Next.js - remove for Vite/CRA","","import { useEffect } from 'react';","import 'vanilla-agent/widget.css';","import { initAgentWidget, markdownPostprocessor } from 'vanilla-agent';","import type { AgentWidgetInitHandle } from 'vanilla-agent';","","export function ChatWidget() {"," useEffect(() => {"," let handle: AgentWidgetInitHandle | null = null;",""," handle = initAgentWidget({"," target: 'body',"," config: {"];return a.apiUrl&&e.push(` apiUrl: "${a.apiUrl}",`),a.flowId&&e.push(` flowId: "${a.flowId}",`),r&&e.push(` parserType: "${t}",`),a.theme&&(e.push(" theme: {"),Object.entries(a.theme).forEach(([s,o])=>{e.push(` ${s}: "${o}",`)}),e.push(" },")),a.launcher&&(e.push(" launcher: {"),Object.entries(a.launcher).forEach(([s,o])=>{typeof o=="string"?e.push(` ${s}: "${o}",`):typeof o=="boolean"&&e.push(` ${s}: ${o},`)}),e.push(" },")),a.copy&&(e.push(" copy: {"),Object.entries(a.copy).forEach(([s,o])=>{e.push(` ${s}: "${o}",`)}),e.push(" },")),a.sendButton&&(e.push(" sendButton: {"),Object.entries(a.sendButton).forEach(([s,o])=>{typeof o=="string"?e.push(` ${s}: "${o}",`):typeof o=="boolean"&&e.push(` ${s}: ${o},`)}),e.push(" },")),a.voiceRecognition&&(e.push(" voiceRecognition: {"),Object.entries(a.voiceRecognition).forEach(([s,o])=>{typeof o=="string"?e.push(` ${s}: "${o}",`):typeof o=="boolean"?e.push(` ${s}: ${o},`):typeof o=="number"&&e.push(` ${s}: ${o},`)}),e.push(" },")),a.statusIndicator&&(e.push(" statusIndicator: {"),Object.entries(a.statusIndicator).forEach(([s,o])=>{typeof o=="string"?e.push(` ${s}: "${o}",`):typeof o=="boolean"&&e.push(` ${s}: ${o},`)}),e.push(" },")),a.features&&(e.push(" features: {"),Object.entries(a.features).forEach(([s,o])=>{e.push(` ${s}: ${o},`)}),e.push(" },")),a.suggestionChips&&a.suggestionChips.length>0&&(e.push(" suggestionChips: ["),a.suggestionChips.forEach(s=>{e.push(` "${s}",`)}),e.push(" ],")),a.suggestionChipsConfig&&(e.push(" suggestionChipsConfig: {"),a.suggestionChipsConfig.fontFamily&&e.push(` fontFamily: "${a.suggestionChipsConfig.fontFamily}",`),a.suggestionChipsConfig.fontWeight&&e.push(` fontWeight: "${a.suggestionChipsConfig.fontWeight}",`),a.suggestionChipsConfig.paddingX&&e.push(` paddingX: "${a.suggestionChipsConfig.paddingX}",`),a.suggestionChipsConfig.paddingY&&e.push(` paddingY: "${a.suggestionChipsConfig.paddingY}",`),e.push(" },")),a.debug&&e.push(` debug: ${a.debug},`),e.push(" postprocessMessage: ({ text }) => markdownPostprocessor(text)"),e.push(" }"),e.push(" });"),e.push(""),e.push(" // Cleanup on unmount"),e.push(" return () => {"),e.push(" if (handle) {"),e.push(" handle.destroy();"),e.push(" }"),e.push(" };"),e.push(" }, []);"),e.push(""),e.push(" return null; // Widget injects itself into the DOM"),e.push("}"),e.push(""),e.push("// Usage in your app:"),e.push("// import { ChatWidget } from './components/ChatWidget';"),e.push("//"),e.push("// export default function App() {"),e.push("// return ("),e.push("// <div>"),e.push("// {/* Your app content */}"),e.push("// <ChatWidget />"),e.push("// </div>"),e.push("// );"),e.push("// }"),e.join(`
|
|
107
107
|
`)}function Tk(a){let t=["// ChatWidgetAdvanced.tsx","'use client'; // Required for Next.js - remove for Vite/CRA","","import { useEffect } from 'react';","import 'vanilla-agent/widget.css';","import {"," initAgentWidget,"," createFlexibleJsonStreamParser,"," defaultJsonActionParser,"," defaultActionHandlers,"," markdownPostprocessor","} from 'vanilla-agent';","import type { AgentWidgetInitHandle } from 'vanilla-agent';","","const STORAGE_KEY = 'chat-widget-state';","const PROCESSED_ACTIONS_KEY = 'chat-widget-processed-actions';","","// Types for DOM elements","interface PageElement {"," type: string;"," tagName: string;"," selector: string;"," innerText: string;"," href?: string;","}","","interface DOMContext {"," page_elements: PageElement[];"," page_element_count: number;"," element_types: Record<string, number>;"," page_url: string;"," page_title: string;"," timestamp: string;","}","","// DOM context provider - extracts page elements for AI context","const collectDOMContext = (): DOMContext => {"," const selectors = {",` products: '[data-product-id], .product-card, .product-item, [role="article"]',`,` buttons: 'button, [role="button"], .btn',`," links: 'a[href]',"," inputs: 'input, textarea, select'"," };",""," const elements: PageElement[] = [];"," Object.entries(selectors).forEach(([type, selector]) => {"," document.querySelectorAll(selector).forEach((element) => {"," if (!(element instanceof HTMLElement)) return;"," "," // Exclude elements within the widget"," const widgetHost = element.closest('.vanilla-agent-host');"," if (widgetHost) return;"," "," const text = element.innerText?.trim();"," if (!text) return;",""," const selectorString ="," element.id ? `#${element.id}` :"," element.getAttribute('data-testid') ? `[data-testid=\"${element.getAttribute('data-testid')}\"]` :"," element.getAttribute('data-product-id') ? `[data-product-id=\"${element.getAttribute('data-product-id')}\"]` :"," element.tagName.toLowerCase();",""," const elementData: PageElement = {"," type,"," tagName: element.tagName.toLowerCase(),"," selector: selectorString,"," innerText: text.substring(0, 200)"," };",""," if (type === 'links' && element instanceof HTMLAnchorElement && element.href) {"," elementData.href = element.href;"," }",""," elements.push(elementData);"," });"," });",""," const counts = elements.reduce((acc, el) => {"," acc[el.type] = (acc[el.type] || 0) + 1;"," return acc;"," }, {} as Record<string, number>);",""," return {"," page_elements: elements.slice(0, 50),"," page_element_count: elements.length,"," element_types: counts,"," page_url: window.location.href,"," page_title: document.title,"," timestamp: new Date().toISOString()"," };","};","","export function ChatWidgetAdvanced() {"," useEffect(() => {"," let handle: AgentWidgetInitHandle | null = null;",""," // Load saved state"," const loadSavedMessages = () => {"," const savedState = localStorage.getItem(STORAGE_KEY);"," if (savedState) {"," try {"," const { messages } = JSON.parse(savedState);"," return messages || [];"," } catch (e) {"," console.error('Failed to load saved state:', e);"," }"," }"," return [];"," };",""," handle = initAgentWidget({"," target: 'body',"," config: {"];return a.apiUrl&&t.push(` apiUrl: "${a.apiUrl}",`),a.flowId&&t.push(` flowId: "${a.flowId}",`),a.theme&&(t.push(" theme: {"),Object.entries(a.theme).forEach(([r,e])=>{t.push(` ${r}: "${e}",`)}),t.push(" },")),a.launcher&&(t.push(" launcher: {"),Object.entries(a.launcher).forEach(([r,e])=>{typeof e=="string"?t.push(` ${r}: "${e}",`):typeof e=="boolean"&&t.push(` ${r}: ${e},`)}),t.push(" },")),a.copy&&(t.push(" copy: {"),Object.entries(a.copy).forEach(([r,e])=>{t.push(` ${r}: "${e}",`)}),t.push(" },")),a.sendButton&&(t.push(" sendButton: {"),Object.entries(a.sendButton).forEach(([r,e])=>{typeof e=="string"?t.push(` ${r}: "${e}",`):typeof e=="boolean"&&t.push(` ${r}: ${e},`)}),t.push(" },")),a.voiceRecognition&&(t.push(" voiceRecognition: {"),Object.entries(a.voiceRecognition).forEach(([r,e])=>{typeof e=="string"?t.push(` ${r}: "${e}",`):typeof e=="boolean"?t.push(` ${r}: ${e},`):typeof e=="number"&&t.push(` ${r}: ${e},`)}),t.push(" },")),a.statusIndicator&&(t.push(" statusIndicator: {"),Object.entries(a.statusIndicator).forEach(([r,e])=>{typeof e=="string"?t.push(` ${r}: "${e}",`):typeof e=="boolean"&&t.push(` ${r}: ${e},`)}),t.push(" },")),a.features&&(t.push(" features: {"),Object.entries(a.features).forEach(([r,e])=>{t.push(` ${r}: ${e},`)}),t.push(" },")),a.suggestionChips&&a.suggestionChips.length>0&&(t.push(" suggestionChips: ["),a.suggestionChips.forEach(r=>{t.push(` "${r}",`)}),t.push(" ],")),a.suggestionChipsConfig&&(t.push(" suggestionChipsConfig: {"),a.suggestionChipsConfig.fontFamily&&t.push(` fontFamily: "${a.suggestionChipsConfig.fontFamily}",`),a.suggestionChipsConfig.fontWeight&&t.push(` fontWeight: "${a.suggestionChipsConfig.fontWeight}",`),a.suggestionChipsConfig.paddingX&&t.push(` paddingX: "${a.suggestionChipsConfig.paddingX}",`),a.suggestionChipsConfig.paddingY&&t.push(` paddingY: "${a.suggestionChipsConfig.paddingY}",`),t.push(" },")),a.debug&&t.push(` debug: ${a.debug},`),t.push(" initialMessages: loadSavedMessages(),"),t.push(" // Flexible JSON stream parser for handling structured actions"),t.push(" streamParser: () => createFlexibleJsonStreamParser((parsed: any) => {"),t.push(" if (!parsed || typeof parsed !== 'object') return null;"),t.push(" // Extract display text based on action type"),t.push(" if (parsed.action === 'nav_then_click') return 'Navigating...';"),t.push(" if (parsed.action === 'message') return parsed.text || '';"),t.push(" if (parsed.action === 'message_and_click') return parsed.text || 'Processing...';"),t.push(" return parsed.text || null;"),t.push(" }),"),t.push(" // Action parsers to detect JSON actions in responses"),t.push(" actionParsers: ["),t.push(" defaultJsonActionParser,"),t.push(" // Custom parser for markdown-wrapped JSON"),t.push(" ({ text, message }: any) => {"),t.push(" const jsonSource = (message as any).rawContent || text || message.content;"),t.push(" if (!jsonSource || typeof jsonSource !== 'string') return null;"),t.push(" // Strip markdown code fences"),t.push(" let cleanJson = jsonSource"),t.push(" .replace(/^```(?:json)?\\s*\\n?/, '')"),t.push(" .replace(/\\n?```\\s*$/, '')"),t.push(" .trim();"),t.push(" if (!cleanJson.startsWith('{') || !cleanJson.endsWith('}')) return null;"),t.push(" try {"),t.push(" const parsed = JSON.parse(cleanJson);"),t.push(" if (parsed.action) return { type: parsed.action, payload: parsed };"),t.push(" } catch (e) { return null; }"),t.push(" return null;"),t.push(" }"),t.push(" ],"),t.push(" // Action handlers for navigation and other actions"),t.push(" actionHandlers: ["),t.push(" defaultActionHandlers.message,"),t.push(" defaultActionHandlers.messageAndClick,"),t.push(" // Handler for nav_then_click action"),t.push(" (action: any, context: any) => {"),t.push(" if (action.type !== 'nav_then_click') return;"),t.push(" const payload = action.payload || action.raw || {};"),t.push(" const url = payload?.page;"),t.push(" const text = payload?.on_load_text || 'Navigating...';"),t.push(" if (!url) return { handled: true, displayText: text };"),t.push(" // Check if already processed"),t.push(" const messageId = context.message?.id;"),t.push(" const processedActions = JSON.parse(localStorage.getItem(PROCESSED_ACTIONS_KEY) || '[]');"),t.push(" const actionKey = `nav_${messageId}_${url}`;"),t.push(" if (processedActions.includes(actionKey)) {"),t.push(" return { handled: true, displayText: text };"),t.push(" }"),t.push(" processedActions.push(actionKey);"),t.push(" localStorage.setItem(PROCESSED_ACTIONS_KEY, JSON.stringify(processedActions));"),t.push(" const targetUrl = url.startsWith('http') ? url : new URL(url, window.location.origin).toString();"),t.push(" window.location.href = targetUrl;"),t.push(" return { handled: true, displayText: text };"),t.push(" }"),t.push(" ],"),t.push(" postprocessMessage: ({ text }) => markdownPostprocessor(text),"),t.push(" requestMiddleware: ({ payload }) => {"),t.push(" return {"),t.push(" ...payload,"),t.push(" metadata: collectDOMContext()"),t.push(" };"),t.push(" }"),t.push(" }"),t.push(" });"),t.push(""),t.push(" // Save state on message events"),t.push(" const handleMessage = () => {"),t.push(" const session = handle?.getSession?.();"),t.push(" if (session) {"),t.push(" localStorage.setItem(STORAGE_KEY, JSON.stringify({"),t.push(" messages: session.messages,"),t.push(" timestamp: new Date().toISOString()"),t.push(" }));"),t.push(" }"),t.push(" };"),t.push(""),t.push(" // Clear state on clear chat"),t.push(" const handleClearChat = () => {"),t.push(" localStorage.removeItem(STORAGE_KEY);"),t.push(" localStorage.removeItem(PROCESSED_ACTIONS_KEY);"),t.push(" };"),t.push(""),t.push(" window.addEventListener('vanilla-agent:message', handleMessage);"),t.push(" window.addEventListener('vanilla-agent:clear-chat', handleClearChat);"),t.push(""),t.push(" // Cleanup on unmount"),t.push(" return () => {"),t.push(" window.removeEventListener('vanilla-agent:message', handleMessage);"),t.push(" window.removeEventListener('vanilla-agent:clear-chat', handleClearChat);"),t.push(" if (handle) {"),t.push(" handle.destroy();"),t.push(" }"),t.push(" };"),t.push(" }, []);"),t.push(""),t.push(" return null; // Widget injects itself into the DOM"),t.push("}"),t.push(""),t.push("// Usage: Collects DOM context for AI-powered navigation"),t.push("// Features:"),t.push("// - Extracts page elements (products, buttons, links)"),t.push("// - Persists chat history across page loads"),t.push("// - Handles navigation actions (nav_then_click)"),t.push("// - Processes structured JSON actions from AI"),t.push("//"),t.push("// Example usage in Next.js:"),t.push("// import { ChatWidgetAdvanced } from './components/ChatWidgetAdvanced';"),t.push("//"),t.push("// export default function RootLayout({ children }) {"),t.push("// return ("),t.push('// <html lang="en">'),t.push("// <body>"),t.push("// {children}"),t.push("// <ChatWidgetAdvanced />"),t.push("// </body>"),t.push("// </html>"),t.push("// );"),t.push("// }"),t.join(`
|
|
108
108
|
`)}function Bk(a){let t=RS(a),r=t!=="plain",e=["<script>"," window.siteAgentConfig = {"," target: 'body',"," config: {"];return a.apiUrl&&e.push(` apiUrl: "${a.apiUrl}",`),a.flowId&&e.push(` flowId: "${a.flowId}",`),r&&e.push(` parserType: "${t}",`),a.theme&&(e.push(" theme: {"),Object.entries(a.theme).forEach(([s,o])=>{e.push(` ${s}: "${o}",`)}),e.push(" },")),a.launcher&&(e.push(" launcher: {"),Object.entries(a.launcher).forEach(([s,o])=>{typeof o=="string"?e.push(` ${s}: "${o}",`):typeof o=="boolean"&&e.push(` ${s}: ${o},`)}),e.push(" },")),a.copy&&(e.push(" copy: {"),Object.entries(a.copy).forEach(([s,o])=>{e.push(` ${s}: "${o}",`)}),e.push(" },")),a.sendButton&&(e.push(" sendButton: {"),Object.entries(a.sendButton).forEach(([s,o])=>{typeof o=="string"?e.push(` ${s}: "${o}",`):typeof o=="boolean"&&e.push(` ${s}: ${o},`)}),e.push(" },")),a.voiceRecognition&&(e.push(" voiceRecognition: {"),Object.entries(a.voiceRecognition).forEach(([s,o])=>{typeof o=="string"?e.push(` ${s}: "${o}",`):typeof o=="boolean"?e.push(` ${s}: ${o},`):typeof o=="number"&&e.push(` ${s}: ${o},`)}),e.push(" },")),a.statusIndicator&&(e.push(" statusIndicator: {"),Object.entries(a.statusIndicator).forEach(([s,o])=>{typeof o=="string"?e.push(` ${s}: "${o}",`):typeof o=="boolean"&&e.push(` ${s}: ${o},`)}),e.push(" },")),a.features&&(e.push(" features: {"),Object.entries(a.features).forEach(([s,o])=>{e.push(` ${s}: ${o},`)}),e.push(" },")),a.suggestionChips&&a.suggestionChips.length>0&&(e.push(" suggestionChips: ["),a.suggestionChips.forEach(s=>{e.push(` "${s}",`)}),e.push(" ],")),a.suggestionChipsConfig&&(e.push(" suggestionChipsConfig: {"),a.suggestionChipsConfig.fontFamily&&e.push(` fontFamily: "${a.suggestionChipsConfig.fontFamily}",`),a.suggestionChipsConfig.fontWeight&&e.push(` fontWeight: "${a.suggestionChipsConfig.fontWeight}",`),a.suggestionChipsConfig.paddingX&&e.push(` paddingX: "${a.suggestionChipsConfig.paddingX}",`),a.suggestionChipsConfig.paddingY&&e.push(` paddingY: "${a.suggestionChipsConfig.paddingY}",`),e.push(" },")),a.debug&&e.push(` debug: ${a.debug},`),e.push(" postprocessMessage: ({ text }) => window.AgentWidget.markdownPostprocessor(text)"),e.push(" }"),e.push(" };"),e.push("</script>"),e.push('<script src="https://cdn.jsdelivr.net/npm/vanilla-agent@latest/dist/install.global.js"></script>'),e.join(`
|