@runtypelabs/persona 1.43.4 → 1.43.5

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.
@@ -106,7 +106,7 @@ lucide.createIcons({icons});\``);if(typeof t=="undefined")throw new Error("`crea
106
106
  flex-shrink: 0 !important;
107
107
  border-top: none !important;
108
108
  padding: 8px 16px 12px 16px !important;
109
- `}if(!O){let Pa="max-height: -moz-available !important; max-height: stretch !important;",Ea=l?"":"padding-top: 1.25em !important;";Bt.style.cssText+=Pa+Ea}};pe(),kS(r,t);let xe=[];W&&xe.push(()=>{ct!==null&&(cancelAnimationFrame(ct),ct=null),et==null||et.destroy(),et=null,_==null||_.destroy(),_=null,z=null});let _e=null,mn=()=>{_e&&(_e(),_e=null),t.colorScheme==="auto"&&(_e=yL(()=>{kS(r,t)}))};mn(),xe.push(()=>{_e&&(_e(),_e=null)});let ua=TL(Te),Qe=null,$,ma=!1,ra=!0,ka=0,xn=0,oa=null,sa=!1,$a=0,_a=!1,$n=125,_n=2e3,jn=5,gn=50,ja=new Map,Kt={active:!1,manuallyDeactivated:!1,lastUserMessageWasVoice:!1,lastUserMessageId:null},Mn=($A=(UA=t.voiceRecognition)==null?void 0:UA.autoResume)!=null?$A:!1,vn=l=>{o.emit("voice:state",{active:Kt.active,source:l,timestamp:Date.now()})},na=()=>{c(l=>({...l,voiceState:{active:Kt.active,timestamp:Date.now(),manuallyDeactivated:Kt.manuallyDeactivated}}))},Gn=()=>{var D,B;if(((D=t.voiceRecognition)==null?void 0:D.enabled)===!1)return;let l=bA(d.voiceState),v=!!l.active,P=Number((B=l.timestamp)!=null?B:0);Kt.manuallyDeactivated=!!l.manuallyDeactivated,v&&Date.now()-P<AP&&setTimeout(()=>{Kt.active||(Kt.manuallyDeactivated=!1,Vt("restore"))},1e3)},Zn=()=>$?IL($.getMessages()).filter(l=>!l.__skipPersist):[];function yn(l){if(!(n!=null&&n.save))return;let P={messages:l?IL(l):$?Zn():[],metadata:d};try{let D=n.save(P);D instanceof Promise&&D.catch(B=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",B)})}catch(D){typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",D)}}let Ha=(l=!1)=>{if(!ra)return;let v=Date.now();sa&&v<$a&&!l||(sa&&v>=$a&&(sa=!1),!(!l&&!ma)&&(v-xn<$n||(xn=v,oa&&cancelAnimationFrame(oa),oa=requestAnimationFrame(()=>{sa||!ra||(_a=!0,Rt.scrollTop=Rt.scrollHeight,ka=Rt.scrollTop,requestAnimationFrame(()=>{_a=!1}),oa=null)}))))},da=null,Xn=()=>Bt.querySelector("#persona-scroll-container")||Rt,Jn=(l,v=500)=>{let P=l.scrollTop,D=l.clientHeight,B=l.scrollHeight,Z=B-P;if(P+D>=B-2||Math.abs(Z)<5)return;da!==null&&(cancelAnimationFrame(da),da=null);let pt=performance.now(),Ht=It=>1-Math.pow(1-It,3),Ft=It=>{let qt=l.scrollHeight;qt!==B&&(B=qt,Z=B-P);let ot=It-pt,O=Math.min(ot/v,1),gt=Ht(O),vt=P+Z*gt;l.scrollTop=vt,O<1?da=requestAnimationFrame(Ft):(l.scrollTop=l.scrollHeight,da=null)};da=requestAnimationFrame(Ft)},Kn=l=>{let v=new Map;l.forEach(P=>{let D=ja.get(P.id);v.set(P.id,{streaming:P.streaming,role:P.role}),!D&&P.role==="assistant"&&o.emit("assistant:message",P),P.role==="assistant"&&(D!=null&&D.streaming)&&P.streaming===!1&&o.emit("assistant:complete",P)}),ja.clear(),v.forEach((P,D)=>{ja.set(D,P)})},La=(l,v,P)=>{var Ft,It,qt,ot;let D=document.createElement("div"),Z=(()=>{var gt;let O=s.find(vt=>vt.renderLoadingIndicator);if(O!=null&&O.renderLoadingIndicator)return O.renderLoadingIndicator;if((gt=t.loadingIndicator)!=null&&gt.render)return t.loadingIndicator.render})();v.forEach(O=>{var Me,Ie;let gt=null,vt=s.find(K=>!!(O.variant==="reasoning"&&K.renderReasoning||O.variant==="tool"&&K.renderToolCall||!O.variant&&K.renderMessage)),Qt=(Me=t.layout)==null?void 0:Me.messages;if(vt)if(O.variant==="reasoning"&&O.reasoning&&vt.renderReasoning){if(!L)return;gt=vt.renderReasoning({message:O,defaultRenderer:()=>uA(O),config:t})}else if(O.variant==="tool"&&O.toolCall&&vt.renderToolCall){if(!I)return;gt=vt.renderToolCall({message:O,defaultRenderer:()=>mA(O,t),config:t})}else vt.renderMessage&&(gt=vt.renderMessage({message:O,defaultRenderer:()=>{let K=dn(O,P,Qt,t.messageActions,Pe,{loadingIndicatorRenderer:Z,widgetConfig:t});return O.role!=="user"&&gA(K,O,t,$),K},config:t}));if(!gt&&O.role==="assistant"&&!O.variant&&t.enableComponentStreaming!==!1&&BS(O)){let Nt=RS(O);if(Nt){let ta=ES(Nt,{config:t,message:O,transform:P});if(ta){let Ke=document.createElement("div");if(Ke.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(" "),Ke.id=`bubble-${O.id}`,Ke.setAttribute("data-message-id",O.id),O.content&&O.content.trim()){let xa=document.createElement("div");xa.className="tvw-mb-3 tvw-text-sm tvw-leading-relaxed",xa.innerHTML=P({text:O.content,message:O,streaming:!!O.streaming,raw:O.rawContent}),Ke.appendChild(xa)}Ke.appendChild(ta),gt=Ke}}}if(!gt)if(O.variant==="reasoning"&&O.reasoning){if(!L)return;gt=uA(O)}else if(O.variant==="tool"&&O.toolCall){if(!I)return;gt=mA(O,t)}else{let K=(Ie=t.layout)==null?void 0:Ie.messages;K!=null&&K.renderUserMessage&&O.role==="user"?gt=K.renderUserMessage({message:O,config:t,streaming:!!O.streaming}):K!=null&&K.renderAssistantMessage&&O.role==="assistant"?gt=K.renderAssistantMessage({message:O,config:t,streaming:!!O.streaming}):gt=dn(O,P,K,t.messageActions,Pe,{loadingIndicatorRenderer:Z,widgetConfig:t}),O.role!=="user"&&gt&&gA(gt,O,t,$)}let Tt=document.createElement("div");Tt.className="tvw-flex",Tt.id=`wrapper-${O.id}`,Tt.setAttribute("data-wrapper-id",O.id),O.role==="user"&&Tt.classList.add("tvw-justify-end"),Tt.appendChild(gt),D.appendChild(Tt)});let wt=v.some(O=>O.role==="assistant"&&O.streaming),pt=v[v.length-1],Ht=(pt==null?void 0:pt.role)==="assistant"&&!pt.streaming;if(ma&&v.some(O=>O.role==="user")&&!wt&&!Ht){let O={config:t,streaming:!0,location:"standalone",defaultRenderer:qa},gt=s.find(Qt=>Qt.renderLoadingIndicator),vt=null;if(gt!=null&&gt.renderLoadingIndicator&&(vt=gt.renderLoadingIndicator(O)),vt===null&&((Ft=t.loadingIndicator)!=null&&Ft.render)&&(vt=t.loadingIndicator.render(O)),vt===null&&(vt=qa()),vt){let Qt=document.createElement("div"),Tt=((It=t.loadingIndicator)==null?void 0:It.showBubble)!==!1;Qt.className=Tt?["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(" "):["tvw-max-w-[85%]","tvw-text-sm","tvw-leading-relaxed","tvw-text-cw-primary"].join(" "),Qt.setAttribute("data-typing-indicator","true"),Qt.appendChild(vt);let Me=document.createElement("div");Me.className="tvw-flex",Me.id="wrapper-typing-indicator",Me.setAttribute("data-wrapper-id","typing-indicator"),Me.appendChild(Qt),D.appendChild(Me)}}if(!ma&&v.length>0){let O=v[v.length-1],gt={config:t,lastMessage:O,messageCount:v.length},vt=s.find(Tt=>Tt.renderIdleIndicator),Qt=null;if(vt!=null&&vt.renderIdleIndicator&&(Qt=vt.renderIdleIndicator(gt)),Qt===null&&((qt=t.loadingIndicator)!=null&&qt.renderIdle)&&(Qt=t.loadingIndicator.renderIdle(gt)),Qt){let Tt=document.createElement("div"),Me=((ot=t.loadingIndicator)==null?void 0:ot.showBubble)!==!1;Tt.className=Me?["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(" "):["tvw-max-w-[85%]","tvw-text-sm","tvw-leading-relaxed","tvw-text-cw-primary"].join(" "),Tt.setAttribute("data-idle-indicator","true"),Tt.appendChild(Qt);let Ie=document.createElement("div");Ie.className="tvw-flex",Ie.id="wrapper-idle-indicator",Ie.setAttribute("data-wrapper-id","idle-indicator"),Ie.appendChild(Tt),D.appendChild(Ie)}}CL(l,D),requestAnimationFrame(()=>{requestAnimationFrame(()=>{let O=Xn();Jn(O)})})},Ta=()=>{b&&(h?(Bt.classList.remove("tvw-pointer-events-none","tvw-opacity-0"),yt.classList.remove("tvw-scale-95","tvw-opacity-0"),yt.classList.add("tvw-scale-100","tvw-opacity-100"),F?F.element.style.display="none":k&&(k.style.display="none")):(Bt.classList.add("tvw-pointer-events-none","tvw-opacity-0"),yt.classList.remove("tvw-scale-100","tvw-opacity-100"),yt.classList.add("tvw-scale-95","tvw-opacity-0"),F?F.element.style.display="":k&&(k.style.display="")))},ne=(l,v="user")=>{if(!b||h===l)return;let P=h;h=l,Ta(),h&&(R(),Ha(!0));let D={open:h,source:v,timestamp:Date.now()};h&&!P?o.emit("widget:opened",D):!h&&P&&o.emit("widget:closed",D),o.emit("widget:state",{open:h,launcherEnabled:b,voiceActive:Kt.active,streaming:$.isStreaming()})},Ga=l=>{J.disabled=l,j&&(j.disabled=l),ua.buttons.forEach(v=>{v.disabled=l})},wn=()=>{var B,Z,wt,pt,Ht,Ft,It,qt,ot,O,gt,vt,Qt,Tt;$e.textContent=(Z=(B=t.copy)==null?void 0:B.welcomeTitle)!=null?Z:"Hello \u{1F44B}",we.textContent=(pt=(wt=t.copy)==null?void 0:wt.welcomeSubtitle)!=null?pt:"Ask anything about your account or products.",ut.placeholder=(Ft=(Ht=t.copy)==null?void 0:Ht.inputPlaceholder)!=null?Ft:"How can I help...",((qt=(It=t.sendButton)==null?void 0:It.useIcon)!=null?qt:!1)||(J.textContent=(O=(ot=t.copy)==null?void 0:ot.sendButtonLabel)!=null?O:"Send");let v=(vt=(gt=t.theme)==null?void 0:gt.inputFontFamily)!=null?vt:"sans-serif",P=(Tt=(Qt=t.theme)==null?void 0:Qt.inputFontWeight)!=null?Tt:"400",D=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'}};ut.style.fontFamily=D(v),ut.style.fontWeight=P};t.clientToken&&(t={...t,getStoredSessionId:()=>{let l=d.sessionId;return typeof l=="string"?l:null},setStoredSessionId:l=>{c(v=>({...v,sessionId:l}))}}),$=new Ka(t,{onMessagesChanged(l){La(se,l,E),$&&(l.some(B=>B.role==="user")?ua.render([],$,ut,l):ua.render(t.suggestionChips,$,ut,l,t.suggestionChipsConfig)),Ha(!ma),Kn(l);let v=[...l].reverse().find(D=>D.role==="user"),P=Kt.lastUserMessageId;v&&v.id!==P&&(Kt.lastUserMessageId=v.id,o.emit("user:message",v)),Kt.lastUserMessageWasVoice=!!(v!=null&&v.viaVoice),yn(l)},onStatusChanged(l){var D;let v=(D=t.statusIndicator)!=null?D:{},P=B=>{var Z,wt,pt,Ht;return B==="idle"?(Z=v.idleText)!=null?Z:De.idle:B==="connecting"?(wt=v.connectingText)!=null?wt:De.connecting:B==="connected"?(pt=v.connectedText)!=null?pt:De.connected:B==="error"?(Ht=v.errorText)!=null?Ht:De.error:De[B]};ye.textContent=P(l)},onStreamingChanged(l){ma=l,Ga(l),$&&La(se,$.getMessages(),E),l||Ha(!0)}}),_&&$.setSSEEventCallback((l,v)=>{_==null||_.push({id:`evt-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,type:l,timestamp:Date.now(),payload:JSON.stringify(v)})}),i&&i.then(l=>{var v;l&&(l.metadata&&(d=bA(l.metadata),y.syncFromMetadata()),(v=l.messages)!=null&&v.length&&$.hydrateMessages(l.messages))}).catch(l=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to hydrate stored state:",l)});let Cn=l=>{var B;l.preventDefault();let v=ut.value.trim(),P=(B=ht==null?void 0:ht.hasAttachments())!=null?B:!1;if(!v&&!P)return;let D;P&&(D=[],D.push(...ht.getContentParts()),v&&D.push(bS(v))),ut.value="",ut.style.height="auto",$.sendMessage(v,{contentParts:D}),P&&ht.clearAttachments()},bn=l=>{l.key==="Enter"&&!l.shiftKey&&(l.preventDefault(),J.click())},We=null,je=!1,la=null,q=null,kt=()=>typeof window=="undefined"?null:window.webkitSpeechRecognition||window.SpeechRecognition||null,Vt=(l="user")=>{var Z,wt,pt,Ht;if(je||$.isStreaming())return;let v=kt();if(!v)return;We=new v;let D=(wt=((Z=t.voiceRecognition)!=null?Z:{}).pauseDuration)!=null?wt:2e3;We.continuous=!0,We.interimResults=!0,We.lang="en-US";let B=ut.value;We.onresult=Ft=>{let It="",qt="";for(let O=0;O<Ft.results.length;O++){let gt=Ft.results[O],vt=gt[0].transcript;gt.isFinal?It+=vt+" ":qt=vt}let ot=B+It+qt;ut.value=ot,la&&clearTimeout(la),(It||qt)&&(la=window.setTimeout(()=>{let O=ut.value.trim();O&&We&&je&&(Gt(),ut.value="",ut.style.height="auto",$.sendMessage(O,{viaVoice:!0}))},D))},We.onerror=Ft=>{Ft.error!=="no-speech"&&Gt()},We.onend=()=>{if(je){let Ft=ut.value.trim();Ft&&Ft!==B.trim()&&(ut.value="",ut.style.height="auto",$.sendMessage(Ft,{viaVoice:!0})),Gt()}};try{if(We.start(),je=!0,Kt.active=!0,l!=="system"&&(Kt.manuallyDeactivated=!1),vn(l),na(),j){q={backgroundColor:j.style.backgroundColor,color:j.style.color,borderColor:j.style.borderColor};let Ft=(pt=t.voiceRecognition)!=null?pt:{},It=(Ht=Ft.recordingBackgroundColor)!=null?Ht:"#ef4444",qt=Ft.recordingIconColor,ot=Ft.recordingBorderColor;if(j.classList.add("tvw-voice-recording"),j.style.backgroundColor=It,qt){j.style.color=qt;let O=j.querySelector("svg");O&&O.setAttribute("stroke",qt)}ot&&(j.style.borderColor=ot),j.setAttribute("aria-label","Stop voice recognition")}}catch{Gt("system")}},Gt=(l="user")=>{if(je){if(je=!1,la&&(clearTimeout(la),la=null),We){try{We.stop()}catch{}We=null}if(Kt.active=!1,vn(l),na(),j){if(j.classList.remove("tvw-voice-recording"),q){j.style.backgroundColor=q.backgroundColor,j.style.color=q.color,j.style.borderColor=q.borderColor;let v=j.querySelector("svg");v&&v.setAttribute("stroke",q.color||"currentColor"),q=null}j.setAttribute("aria-label","Start voice recognition")}}},Ae=(l,v)=>{var vt,Qt,Tt,Me,Ie,K,Nt;if(!(typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined")))return null;let D=w("div","tvw-send-button-wrapper"),B=w("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 Z=(vt=l==null?void 0:l.iconName)!=null?vt:"mic",wt=(Qt=v==null?void 0:v.size)!=null?Qt:"40px",pt=(Tt=l==null?void 0:l.iconSize)!=null?Tt:wt,Ht=parseFloat(pt)||24,Ft=(Me=l==null?void 0:l.backgroundColor)!=null?Me:v==null?void 0:v.backgroundColor,It=(Ie=l==null?void 0:l.iconColor)!=null?Ie:v==null?void 0:v.textColor;B.style.width=pt,B.style.height=pt,B.style.minWidth=pt,B.style.minHeight=pt,B.style.fontSize="18px",B.style.lineHeight="1";let qt=It||"currentColor",ot=nt(Z,Ht,qt,1.5);ot?(B.appendChild(ot),B.style.color=qt):(B.textContent="\u{1F3A4}",B.style.color=qt),Ft?B.style.backgroundColor=Ft:B.classList.add("tvw-bg-cw-primary"),It?B.style.color=It:!It&&!(v!=null&&v.textColor)&&B.classList.add("tvw-text-white"),l!=null&&l.borderWidth&&(B.style.borderWidth=l.borderWidth,B.style.borderStyle="solid"),l!=null&&l.borderColor&&(B.style.borderColor=l.borderColor),l!=null&&l.paddingX&&(B.style.paddingLeft=l.paddingX,B.style.paddingRight=l.paddingX),l!=null&&l.paddingY&&(B.style.paddingTop=l.paddingY,B.style.paddingBottom=l.paddingY),D.appendChild(B);let O=(K=l==null?void 0:l.tooltipText)!=null?K:"Start voice recognition";if(((Nt=l==null?void 0:l.showTooltip)!=null?Nt:!1)&&O){let ta=w("div","tvw-send-button-tooltip");ta.textContent=O,D.appendChild(ta)}return{micButton:B,micButtonWrapper:D}},ke=()=>{if(je){let l=ut.value.trim();Kt.manuallyDeactivated=!0,na(),Gt("user"),l&&(ut.value="",ut.style.height="auto",$.sendMessage(l))}else Kt.manuallyDeactivated=!1,na(),Vt("user")};j&&(j.addEventListener("click",ke),xe.push(()=>{Gt("system"),j&&j.removeEventListener("click",ke)}));let de=o.on("assistant:complete",()=>{Mn&&(Kt.active||Kt.manuallyDeactivated||Mn==="assistant"&&!Kt.lastUserMessageWasVoice||setTimeout(()=>{!Kt.active&&!Kt.manuallyDeactivated&&Vt("auto")},600))});xe.push(de);let T=o.on("action:resubmit",()=>{setTimeout(()=>{$&&!$.isStreaming()&&$.continueConversation()},100)});xe.push(T);let Ot=()=>{ne(!h,"user")},F=null,k=null;if(b){let l=s.find(v=>v.renderLauncher);if(l!=null&&l.renderLauncher){let v=l.renderLauncher({config:t,defaultRenderer:()=>Wn(t,Ot).element,onToggle:Ot});v&&(k=v)}k||(F=Wn(t,Ot))}F?r.appendChild(F.element):k&&r.appendChild(k),Ta(),ua.render(t.suggestionChips,$,ut,void 0,t.suggestionChipsConfig),wn(),Ga($.isStreaming()),Ha(!0),Gn();let R=()=>{var P,D,B,Z,wt,pt,Ht,Ft;let l=(D=(P=t.launcher)==null?void 0:P.sidebarMode)!=null?D:!1,v=l||((Z=(B=t.launcher)==null?void 0:B.fullHeight)!=null?Z:!1);if(!b){yt.style.height="",yt.style.width="";return}if(!l){let It=(pt=(wt=t==null?void 0:t.launcher)==null?void 0:wt.width)!=null?pt:t==null?void 0:t.launcherWidth,qt=It!=null?It:"min(400px, calc(100vw - 24px))";yt.style.width=qt,yt.style.maxWidth=qt}if(!v){let It=window.innerHeight,qt=64,ot=(Ft=(Ht=t.launcher)==null?void 0:Ht.heightOffset)!=null?Ft:0,O=Math.max(200,It-qt),gt=Math.min(640,O),vt=Math.max(200,gt-ot);yt.style.height=`${vt}px`}};R(),window.addEventListener("resize",R),xe.push(()=>window.removeEventListener("resize",R)),ka=Rt.scrollTop;let lt=()=>{let l=Rt.scrollTop,v=Rt.scrollHeight,P=Rt.clientHeight,D=v-l-P,B=Math.abs(l-ka);if(ka=l,!_a&&!(B<=jn)){if(!ra&&D<gn){sa=!1,ra=!0;return}ra&&D>gn&&(sa=!0,$a=Date.now()+_n,ra=!1)}};Rt.addEventListener("scroll",lt,{passive:!0}),xe.push(()=>Rt.removeEventListener("scroll",lt)),xe.push(()=>{oa&&cancelAnimationFrame(oa)});let re=()=>{Q&&(Qe&&(Q.removeEventListener("click",Qe),Qe=null),b?(Q.style.display="",Qe=()=>{h=!1,Ta()},Q.addEventListener("click",Qe)):Q.style.display="none")};re(),(()=>{let{clearChatButton:l}=at;l&&l.addEventListener("click",()=>{$.clearMessages();try{localStorage.removeItem(un),t.debug&&console.log(`[AgentWidget] Cleared default localStorage key: ${un}`)}catch(P){console.error("[AgentWidget] Failed to clear default localStorage:",P)}if(t.clearChatHistoryStorageKey&&t.clearChatHistoryStorageKey!==un)try{localStorage.removeItem(t.clearChatHistoryStorageKey),t.debug&&console.log(`[AgentWidget] Cleared custom localStorage key: ${t.clearChatHistoryStorageKey}`)}catch(P){console.error("[AgentWidget] Failed to clear custom localStorage:",P)}let v=new CustomEvent("persona:clear-chat",{detail:{timestamp:new Date().toISOString()}});if(window.dispatchEvent(v),n!=null&&n.clear)try{let P=n.clear();P instanceof Promise&&P.catch(D=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",D)})}catch(P){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",P)}d={},y.syncFromMetadata(),_==null||_.clear(),et==null||et.update()})})(),me.addEventListener("submit",Cn),ut.addEventListener("keydown",bn),xe.push(()=>{me.removeEventListener("submit",Cn),ut.removeEventListener("keydown",bn)}),xe.push(()=>{$.cancel()}),F?xe.push(()=>{F==null||F.destroy()}):k&&xe.push(()=>{k==null||k.remove()});let Yt={update(l){var KA,YA,QA,tk,ek,ak,rk,ok,sk,nk,dk,lk,ik,pk,hk,ck,fk,uk,mk,xk,gk,Mk,vk,yk,wk,Ck,bk,Sk,Ak,kk,Hk,Lk,Tk,Pk,Ek,Bk,Rk,Vk,Fk,Ik,Dk,Wk,Ok,zk,qk,Nk,Uk,$k,_k,jk,Gk,Zk,Xk,Jk,Kk,Yk,Qk,tH,eH,aH,rH,oH,sH,nH,dH,lH,iH,pH,hH,cH,fH,uH,mH,xH,gH,MH,vH,yH,wH,CH,bH,SH,AH,kH,HH,LH;let v=t.toolCall,P=t.colorScheme;t={...t,...l},pe(),kS(r,t),t.colorScheme!==P&&mn();let D=qn.getForInstance(t.plugins);s.length=0,s.push(...D),b=(YA=(KA=t.launcher)==null?void 0:KA.enabled)!=null?YA:!0,A=(tk=(QA=t.launcher)==null?void 0:QA.autoExpand)!=null?tk:!1,L=(ak=(ek=t.features)==null?void 0:ek.showReasoning)!=null?ak:!0,I=(ok=(rk=t.features)==null?void 0:rk.showToolCalls)!=null?ok:!0;let B=W;if(W=(nk=(sk=t.features)==null?void 0:sk.showEventStreamToggle)!=null?nk:!1,W&&!B){if(_||(z=new zn(it),_=new On(st,z),z.open().then(()=>_==null?void 0:_.restore()).catch(()=>{}),$.setSSEEventCallback((V,Ct)=>{_.push({id:`evt-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,type:V,timestamp:Date.now(),payload:JSON.stringify(Ct)})})),!G&&tt){let V=(lk=(dk=t.features)==null?void 0:dk.eventStream)==null?void 0:lk.classNames,Ct="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 tvw-bg-transparent tvw-p-1"+(V!=null&&V.toggleButton?" "+V.toggleButton:"");G=w("button",Ct),G.style.width="28px",G.style.height="28px",G.type="button",G.setAttribute("aria-label","Event Stream"),G.title="Event Stream";let te=nt("activity","18px","currentColor",1.5);te&&G.appendChild(te);let xt=at.clearChatButtonWrapper,Et=at.closeButtonWrapper,ve=xt||Et;ve&&ve.parentNode===tt?tt.insertBefore(G,ve):tt.appendChild(G),G.addEventListener("click",()=>{Mt?Wt():bt()})}}else!W&&B&&(Wt(),G&&(G.remove(),G=null),_==null||_.clear(),z==null||z.destroy(),_=null,z=null);if(((ik=t.launcher)==null?void 0:ik.enabled)===!1&&F&&(F.destroy(),F=null),((pk=t.launcher)==null?void 0:pk.enabled)===!1&&k&&(k.remove(),k=null),((hk=t.launcher)==null?void 0:hk.enabled)!==!1&&!F&&!k){let V=s.find(Ct=>Ct.renderLauncher);if(V!=null&&V.renderLauncher){let Ct=V.renderLauncher({config:t,defaultRenderer:()=>Wn(t,Ot).element,onToggle:Ot});Ct&&(k=Ct,r.appendChild(k))}k||(F=Wn(t,Ot),r.appendChild(F.element))}F&&F.update(t),Ce&&((ck=t.launcher)==null?void 0:ck.title)!==void 0&&(Ce.textContent=t.launcher.title),be&&((fk=t.launcher)==null?void 0:fk.subtitle)!==void 0&&(be.textContent=t.launcher.subtitle);let Z=(uk=t.layout)==null?void 0:uk.header;if((Z==null?void 0:Z.layout)!==H&&tt){let V=Z?sn(t,Z,{showClose:b,onClose:()=>ne(!1,"user")}):ca({config:t,showClose:b,onClose:()=>ne(!1,"user")});tt.replaceWith(V.header),tt=V.header,Lt=V.iconHolder,Ce=V.headerTitle,be=V.headerSubtitle,Q=V.closeButton,H=Z==null?void 0:Z.layout}else if(Z&&(Lt&&(Lt.style.display=Z.showIcon===!1?"none":""),Ce&&(Ce.style.display=Z.showTitle===!1?"none":""),be&&(be.style.display=Z.showSubtitle===!1?"none":""),Q&&(Q.style.display=Z.showCloseButton===!1?"none":""),at.clearChatButtonWrapper)){let V=Z.showClearChat;if(V!==void 0){at.clearChatButtonWrapper.style.display=V?"":"none";let{closeButtonWrapper:Ct}=at;Ct&&!Ct.classList.contains("tvw-absolute")&&(V?Ct.classList.remove("tvw-ml-auto"):Ct.classList.add("tvw-ml-auto"))}}let pt=((mk=t.layout)==null?void 0:mk.showHeader)!==!1;tt&&(tt.style.display=pt?"":"none");let Ht=((xk=t.layout)==null?void 0:xk.showFooter)!==!1;Dt&&(Dt.style.display=Ht?"":"none"),b!==x?b?ne(A,"auto"):(h=!0,Ta()):A!==S&&ne(A,"auto"),S=A,x=b,R(),re(),JSON.stringify(l.toolCall)!==JSON.stringify(v)&&$&&La(se,$.getMessages(),E);let ot=(gk=t.launcher)!=null?gk:{},O=(Mk=ot.headerIconHidden)!=null?Mk:!1,gt=(yk=(vk=t.layout)==null?void 0:vk.header)==null?void 0:yk.showIcon,vt=O||gt===!1,Qt=ot.headerIconName,Tt=(wk=ot.headerIconSize)!=null?wk:"48px";if(Lt){let V=ft.querySelector(".tvw-border-b-cw-divider"),Ct=V==null?void 0:V.querySelector(".tvw-flex-col");if(vt)Lt.style.display="none",V&&Ct&&!V.contains(Ct)&&V.insertBefore(Ct,V.firstChild);else{if(Lt.style.display="",Lt.style.height=Tt,Lt.style.width=Tt,V&&Ct&&(V.contains(Lt)?Lt.nextSibling!==Ct&&(Lt.remove(),V.insertBefore(Lt,Ct)):V.insertBefore(Lt,Ct)),Qt){let xt=parseFloat(Tt)||24,Et=nt(Qt,xt*.6,"#ffffff",2);Et?Lt.replaceChildren(Et):Lt.textContent=(Ck=ot.agentIconText)!=null?Ck:"\u{1F4AC}"}else if(ot.iconUrl){let xt=Lt.querySelector("img");if(xt)xt.src=ot.iconUrl,xt.style.height=Tt,xt.style.width=Tt;else{let Et=document.createElement("img");Et.src=ot.iconUrl,Et.alt="",Et.className="tvw-rounded-xl tvw-object-cover",Et.style.height=Tt,Et.style.width=Tt,Lt.replaceChildren(Et)}}else{let xt=Lt.querySelector("svg"),Et=Lt.querySelector("img");(xt||Et)&&Lt.replaceChildren(),Lt.textContent=(bk=ot.agentIconText)!=null?bk:"\u{1F4AC}"}let te=Lt.querySelector("img");te&&(te.style.height=Tt,te.style.width=Tt)}}let Me=(Ak=(Sk=t.layout)==null?void 0:Sk.header)==null?void 0:Ak.showTitle,Ie=(Hk=(kk=t.layout)==null?void 0:kk.header)==null?void 0:Hk.showSubtitle;if(Ce&&(Ce.style.display=Me===!1?"none":""),be&&(be.style.display=Ie===!1?"none":""),Q){((Tk=(Lk=t.layout)==null?void 0:Lk.header)==null?void 0:Tk.showCloseButton)===!1?Q.style.display="none":Q.style.display="";let Ct=(Pk=ot.closeButtonSize)!=null?Pk:"32px",te=(Ek=ot.closeButtonPlacement)!=null?Ek:"inline";Q.style.height=Ct,Q.style.width=Ct;let{closeButtonWrapper:xt}=at,Et=te==="top-right",ve=xt==null?void 0:xt.classList.contains("tvw-absolute");if(xt&&Et!==ve)if(xt.remove(),Et)xt.className="tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50",ft.style.position="relative",ft.appendChild(xt);else{let St=(Rk=(Bk=ot.clearChat)==null?void 0:Bk.placement)!=null?Rk:"inline",Le=(Fk=(Vk=ot.clearChat)==null?void 0:Vk.enabled)!=null?Fk:!0;xt.className=Le&&St==="inline"?"":"tvw-ml-auto";let Ne=ft.querySelector(".tvw-border-b-cw-divider");Ne&&Ne.appendChild(xt)}if(ot.closeButtonColor?(Q.style.color=ot.closeButtonColor,Q.classList.remove("tvw-text-cw-muted")):(Q.style.color="",Q.classList.add("tvw-text-cw-muted")),ot.closeButtonBackgroundColor?(Q.style.backgroundColor=ot.closeButtonBackgroundColor,Q.classList.remove("hover:tvw-bg-gray-100")):(Q.style.backgroundColor="",Q.classList.add("hover:tvw-bg-gray-100")),ot.closeButtonBorderWidth||ot.closeButtonBorderColor){let St=ot.closeButtonBorderWidth||"0px",Le=ot.closeButtonBorderColor||"transparent";Q.style.border=`${St} solid ${Le}`,Q.classList.remove("tvw-border-none")}else Q.style.border="",Q.classList.add("tvw-border-none");ot.closeButtonBorderRadius?(Q.style.borderRadius=ot.closeButtonBorderRadius,Q.classList.remove("tvw-rounded-full")):(Q.style.borderRadius="",Q.classList.add("tvw-rounded-full")),ot.closeButtonPaddingX?(Q.style.paddingLeft=ot.closeButtonPaddingX,Q.style.paddingRight=ot.closeButtonPaddingX):(Q.style.paddingLeft="",Q.style.paddingRight=""),ot.closeButtonPaddingY?(Q.style.paddingTop=ot.closeButtonPaddingY,Q.style.paddingBottom=ot.closeButtonPaddingY):(Q.style.paddingTop="",Q.style.paddingBottom="");let Re=(Ik=ot.closeButtonIconName)!=null?Ik:"x",Ge=(Dk=ot.closeButtonIconText)!=null?Dk:"\xD7";Q.innerHTML="";let Oe=nt(Re,"20px",ot.closeButtonColor||"",2);Oe?Q.appendChild(Oe):Q.textContent=Ge;let ie=(Wk=ot.closeButtonTooltipText)!=null?Wk:"Close chat",Ze=(Ok=ot.closeButtonShowTooltip)!=null?Ok:!0;if(Q.setAttribute("aria-label",ie),xt&&(xt._cleanupTooltip&&(xt._cleanupTooltip(),delete xt._cleanupTooltip),Ze&&ie)){let St=null,Le=()=>{if(St||!Q)return;St=w("div","tvw-clear-chat-tooltip"),St.textContent=ie;let Ln=w("div");Ln.className="tvw-clear-chat-tooltip-arrow",St.appendChild(Ln);let Ba=Q.getBoundingClientRect();St.style.position="fixed",St.style.left=`${Ba.left+Ba.width/2}px`,St.style.top=`${Ba.top-8}px`,St.style.transform="translate(-50%, -100%)",document.body.appendChild(St)},Ne=()=>{St&&St.parentNode&&(St.parentNode.removeChild(St),St=null)};xt.addEventListener("mouseenter",Le),xt.addEventListener("mouseleave",Ne),Q.addEventListener("focus",Le),Q.addEventListener("blur",Ne),xt._cleanupTooltip=()=>{Ne(),xt&&(xt.removeEventListener("mouseenter",Le),xt.removeEventListener("mouseleave",Ne)),Q&&(Q.removeEventListener("focus",Le),Q.removeEventListener("blur",Ne))}}}let{clearChatButton:K,clearChatButtonWrapper:Nt}=at;if(K){let V=(zk=ot.clearChat)!=null?zk:{},Ct=(qk=V.enabled)!=null?qk:!0,te=(Uk=(Nk=t.layout)==null?void 0:Nk.header)==null?void 0:Uk.showClearChat,xt=te!==void 0?te:Ct,Et=($k=V.placement)!=null?$k:"inline";if(Nt){Nt.style.display=xt?"":"none";let{closeButtonWrapper:ve}=at;ve&&!ve.classList.contains("tvw-absolute")&&(xt?ve.classList.remove("tvw-ml-auto"):ve.classList.add("tvw-ml-auto"));let Re=Et==="top-right",Ge=Nt.classList.contains("tvw-absolute");if(Re!==Ge&&xt){if(Nt.remove(),Re)Nt.className="tvw-absolute tvw-top-4 tvw-z-50",Nt.style.right="48px",ft.style.position="relative",ft.appendChild(Nt);else{Nt.className="tvw-relative tvw-ml-auto tvw-clear-chat-button-wrapper",Nt.style.right="";let ie=ft.querySelector(".tvw-border-b-cw-divider"),Ze=at.closeButtonWrapper;ie&&Ze&&Ze.parentElement===ie?ie.insertBefore(Nt,Ze):ie&&ie.appendChild(Nt)}let Oe=at.closeButtonWrapper;Oe&&!Oe.classList.contains("tvw-absolute")&&(Re?Oe.classList.add("tvw-ml-auto"):Oe.classList.remove("tvw-ml-auto"))}}if(xt){let ve=(_k=V.size)!=null?_k:"32px";K.style.height=ve,K.style.width=ve;let Re=(jk=V.iconName)!=null?jk:"refresh-cw",Ge=(Gk=V.iconColor)!=null?Gk:"";K.innerHTML="";let Oe=nt(Re,"20px",Ge||"",2);if(Oe&&K.appendChild(Oe),Ge?(K.style.color=Ge,K.classList.remove("tvw-text-cw-muted")):(K.style.color="",K.classList.add("tvw-text-cw-muted")),V.backgroundColor?(K.style.backgroundColor=V.backgroundColor,K.classList.remove("hover:tvw-bg-gray-100")):(K.style.backgroundColor="",K.classList.add("hover:tvw-bg-gray-100")),V.borderWidth||V.borderColor){let St=V.borderWidth||"0px",Le=V.borderColor||"transparent";K.style.border=`${St} solid ${Le}`,K.classList.remove("tvw-border-none")}else K.style.border="",K.classList.add("tvw-border-none");V.borderRadius?(K.style.borderRadius=V.borderRadius,K.classList.remove("tvw-rounded-full")):(K.style.borderRadius="",K.classList.add("tvw-rounded-full")),V.paddingX?(K.style.paddingLeft=V.paddingX,K.style.paddingRight=V.paddingX):(K.style.paddingLeft="",K.style.paddingRight=""),V.paddingY?(K.style.paddingTop=V.paddingY,K.style.paddingBottom=V.paddingY):(K.style.paddingTop="",K.style.paddingBottom="");let ie=(Zk=V.tooltipText)!=null?Zk:"Clear chat",Ze=(Xk=V.showTooltip)!=null?Xk:!0;if(K.setAttribute("aria-label",ie),Nt&&(Nt._cleanupTooltip&&(Nt._cleanupTooltip(),delete Nt._cleanupTooltip),Ze&&ie)){let St=null,Le=()=>{if(St||!K)return;St=w("div","tvw-clear-chat-tooltip"),St.textContent=ie;let Ln=w("div");Ln.className="tvw-clear-chat-tooltip-arrow",St.appendChild(Ln);let Ba=K.getBoundingClientRect();St.style.position="fixed",St.style.left=`${Ba.left+Ba.width/2}px`,St.style.top=`${Ba.top-8}px`,St.style.transform="translate(-50%, -100%)",document.body.appendChild(St)},Ne=()=>{St&&St.parentNode&&(St.parentNode.removeChild(St),St=null)};Nt.addEventListener("mouseenter",Le),Nt.addEventListener("mouseleave",Ne),K.addEventListener("focus",Le),K.addEventListener("blur",Ne),Nt._cleanupTooltip=()=>{Ne(),Nt&&(Nt.removeEventListener("mouseenter",Le),Nt.removeEventListener("mouseleave",Ne)),K&&(K.removeEventListener("focus",Le),K.removeEventListener("blur",Ne))}}}}let ta=t.actionParsers&&t.actionParsers.length?t.actionParsers:[Nn],Ke=t.actionHandlers&&t.actionHandlers.length?t.actionHandlers:[Na.message,Na.messageAndClick];y=Un({parsers:ta,handlers:Ke,getSessionMetadata:m,updateSessionMetadata:c,emit:o.emit,documentRef:typeof document!="undefined"?document:null}),E=DL(t,y,C),$.updateConfig(t),La(se,$.getMessages(),E),ua.render(t.suggestionChips,$,ut,void 0,t.suggestionChipsConfig),wn(),Ga($.isStreaming());let xa=((Jk=t.voiceRecognition)==null?void 0:Jk.enabled)===!0,Yn=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined");if(xa&&Yn)if(!j||!ae){let V=Ae(t.voiceRecognition,t.sendButton);V&&(j=V.micButton,ae=V.micButtonWrapper,Be.insertBefore(ae,ue),j.addEventListener("click",ke),j.disabled=$.isStreaming())}else{let V=(Kk=t.voiceRecognition)!=null?Kk:{},Ct=(Yk=t.sendButton)!=null?Yk:{},te=(Qk=V.iconName)!=null?Qk:"mic",xt=(tH=Ct.size)!=null?tH:"40px",Et=(eH=V.iconSize)!=null?eH:xt,ve=parseFloat(Et)||24;j.style.width=Et,j.style.height=Et,j.style.minWidth=Et,j.style.minHeight=Et;let Re=(rH=(aH=V.iconColor)!=null?aH:Ct.textColor)!=null?rH:"currentColor";j.innerHTML="";let Ge=nt(te,ve,Re,2);Ge?j.appendChild(Ge):j.textContent="\u{1F3A4}";let Oe=(oH=V.backgroundColor)!=null?oH:Ct.backgroundColor;Oe?(j.style.backgroundColor=Oe,j.classList.remove("tvw-bg-cw-primary")):(j.style.backgroundColor="",j.classList.add("tvw-bg-cw-primary")),Re?(j.style.color=Re,j.classList.remove("tvw-text-white")):!Re&&!Ct.textColor&&(j.style.color="",j.classList.add("tvw-text-white")),V.borderWidth?(j.style.borderWidth=V.borderWidth,j.style.borderStyle="solid"):(j.style.borderWidth="",j.style.borderStyle=""),V.borderColor?j.style.borderColor=V.borderColor:j.style.borderColor="",V.paddingX?(j.style.paddingLeft=V.paddingX,j.style.paddingRight=V.paddingX):(j.style.paddingLeft="",j.style.paddingRight=""),V.paddingY?(j.style.paddingTop=V.paddingY,j.style.paddingBottom=V.paddingY):(j.style.paddingTop="",j.style.paddingBottom="");let ie=ae==null?void 0:ae.querySelector(".tvw-send-button-tooltip"),Ze=(sH=V.tooltipText)!=null?sH:"Start voice recognition";if(((nH=V.showTooltip)!=null?nH:!1)&&Ze)if(ie)ie.textContent=Ze,ie.style.display="";else{let Le=document.createElement("div");Le.className="tvw-send-button-tooltip",Le.textContent=Ze,ae==null||ae.insertBefore(Le,j)}else ie&&(ie.style.display="none");ae.style.display="",j.disabled=$.isStreaming()}else j&&ae&&(ae.style.display="none",je&&Gt());if(((dH=t.attachments)==null?void 0:dH.enabled)===!0)if(!X||!At){let V=(lH=t.attachments)!=null?lH:{},te=(pH=((iH=t.sendButton)!=null?iH:{}).size)!=null?pH:"40px";mt||(mt=w("div","tvw-attachment-previews tvw-flex tvw-flex-wrap tvw-gap-2 tvw-mb-2"),mt.style.display="none",me.insertBefore(mt,ut)),N||(N=document.createElement("input"),N.type="file",N.accept=((hH=V.allowedTypes)!=null?hH:Aa).join(","),N.multiple=((cH=V.maxFiles)!=null?cH:4)>1,N.style.display="none",N.setAttribute("aria-label","Attach files"),me.insertBefore(N,ut)),X=w("div","tvw-send-button-wrapper"),At=w("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer tvw-attachment-button"),At.type="button",At.setAttribute("aria-label",(fH=V.buttonTooltipText)!=null?fH:"Attach file");let xt=(uH=V.buttonIconName)!=null?uH:"paperclip",Et=te,ve=parseFloat(Et)||40,Re=Math.round(ve*.6);At.style.width=Et,At.style.height=Et,At.style.minWidth=Et,At.style.minHeight=Et,At.style.fontSize="18px",At.style.lineHeight="1",At.style.backgroundColor="transparent",At.style.color="var(--cw-primary, #111827)",At.style.border="none",At.style.borderRadius="6px",At.style.transition="background-color 0.15s ease",At.addEventListener("mouseenter",()=>{At.style.backgroundColor="rgba(0, 0, 0, 0.05)"}),At.addEventListener("mouseleave",()=>{At.style.backgroundColor="transparent"});let Ge=nt(xt,Re,"currentColor",1.5);Ge?At.appendChild(Ge):At.textContent="\u{1F4CE}",At.addEventListener("click",Ze=>{Ze.preventDefault(),N==null||N.click()}),X.appendChild(At);let Oe=(mH=V.buttonTooltipText)!=null?mH:"Attach file",ie=w("div","tvw-send-button-tooltip");ie.textContent=Oe,X.appendChild(ie),Fe.append(X),!ht&&N&&mt&&(ht=Oa.fromConfig(V),ht.setPreviewsContainer(mt),N.addEventListener("change",async()=>{ht&&(N!=null&&N.files)&&(await ht.handleFileSelect(N.files),N.value="")}))}else{X.style.display="";let V=(xH=t.attachments)!=null?xH:{};N&&(N.accept=((gH=V.allowedTypes)!=null?gH:Aa).join(","),N.multiple=((MH=V.maxFiles)!=null?MH:4)>1),ht&&ht.updateConfig({allowedTypes:V.allowedTypes,maxFileSize:V.maxFileSize,maxFiles:V.maxFiles})}else X&&(X.style.display="none"),ht&&ht.clearAttachments();let fe=(vH=t.sendButton)!=null?vH:{},Qn=(yH=fe.useIcon)!=null?yH:!1,Sn=(wH=fe.iconText)!=null?wH:"\u2191",Pa=fe.iconName,Ea=(CH=fe.tooltipText)!=null?CH:"Send message",jL=(bH=fe.showTooltip)!=null?bH:!1,An=(SH=fe.size)!=null?SH:"40px",t2=fe.backgroundColor,ea=fe.textColor;if(Qn){if(J.style.width=An,J.style.height=An,J.style.minWidth=An,J.style.minHeight=An,J.style.fontSize="18px",J.style.lineHeight="1",J.innerHTML="",Pa){let V=parseFloat(An)||24,Ct=ea&&typeof ea=="string"&&ea.trim()?ea.trim():"currentColor",te=nt(Pa,V,Ct,2);te?(J.appendChild(te),J.style.color=Ct):(J.textContent=Sn,ea?J.style.color=ea:J.classList.add("tvw-text-white"))}else J.textContent=Sn,ea?J.style.color=ea:J.classList.add("tvw-text-white");J.className="tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer",t2?(J.style.backgroundColor=t2,J.classList.remove("tvw-bg-cw-primary")):J.classList.add("tvw-bg-cw-primary")}else J.textContent=(kH=(AH=t.copy)==null?void 0:AH.sendButtonLabel)!=null?kH:"Send",J.style.width="",J.style.height="",J.style.minWidth="",J.style.minHeight="",J.style.fontSize="",J.style.lineHeight="",J.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",t2?(J.style.backgroundColor=t2,J.classList.remove("tvw-bg-cw-accent")):J.classList.add("tvw-bg-cw-accent"),ea?J.style.color=ea:J.classList.add("tvw-text-white");fe.borderWidth?(J.style.borderWidth=fe.borderWidth,J.style.borderStyle="solid"):(J.style.borderWidth="",J.style.borderStyle=""),fe.borderColor?J.style.borderColor=fe.borderColor:J.style.borderColor="",fe.paddingX?(J.style.paddingLeft=fe.paddingX,J.style.paddingRight=fe.paddingX):(J.style.paddingLeft="",J.style.paddingRight=""),fe.paddingY?(J.style.paddingTop=fe.paddingY,J.style.paddingBottom=fe.paddingY):(J.style.paddingTop="",J.style.paddingBottom="");let kn=ue==null?void 0:ue.querySelector(".tvw-send-button-tooltip");if(jL&&Ea)if(kn)kn.textContent=Ea,kn.style.display="";else{let V=document.createElement("div");V.className="tvw-send-button-tooltip",V.textContent=Ea,ue==null||ue.insertBefore(V,J)}else kn&&(kn.style.display="none");let Hn=(HH=t.statusIndicator)!=null?HH:{},GL=(LH=Hn.visible)!=null?LH:!0;if(ye.style.display=GL?"":"none",$){let V=$.getStatus(),Ct=te=>{var xt,Et,ve,Re;return te==="idle"?(xt=Hn.idleText)!=null?xt:De.idle:te==="connecting"?(Et=Hn.connectingText)!=null?Et:De.connecting:te==="connected"?(ve=Hn.connectedText)!=null?ve:De.connected:te==="error"?(Re=Hn.errorText)!=null?Re:De.error:De[te]};ye.textContent=Ct(V)}},open(){b&&ne(!0,"api")},close(){b&&ne(!1,"api")},toggle(){b&&ne(!h,"api")},clearChat(){$.clearMessages();try{localStorage.removeItem(un),t.debug&&console.log(`[AgentWidget] Cleared default localStorage key: ${un}`)}catch(v){console.error("[AgentWidget] Failed to clear default localStorage:",v)}if(t.clearChatHistoryStorageKey&&t.clearChatHistoryStorageKey!==un)try{localStorage.removeItem(t.clearChatHistoryStorageKey),t.debug&&console.log(`[AgentWidget] Cleared custom localStorage key: ${t.clearChatHistoryStorageKey}`)}catch(v){console.error("[AgentWidget] Failed to clear custom localStorage:",v)}let l=new CustomEvent("persona:clear-chat",{detail:{timestamp:new Date().toISOString()}});if(window.dispatchEvent(l),n!=null&&n.clear)try{let v=n.clear();v instanceof Promise&&v.catch(P=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",P)})}catch(v){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",v)}d={},y.syncFromMetadata(),_==null||_.clear(),et==null||et.update()},setMessage(l){return!ut||$.isStreaming()?!1:(!h&&b&&ne(!0,"system"),ut.value=l,ut.dispatchEvent(new Event("input",{bubbles:!0})),!0)},submitMessage(l){if($.isStreaming())return!1;let v=(l==null?void 0:l.trim())||ut.value.trim();return v?(!h&&b&&ne(!0,"system"),ut.value="",ut.style.height="auto",$.sendMessage(v),!0):!1},startVoiceRecognition(){return je||$.isStreaming()||!kt()?!1:(!h&&b&&ne(!0,"system"),Kt.manuallyDeactivated=!1,na(),Vt("user"),!0)},stopVoiceRecognition(){return je?(Kt.manuallyDeactivated=!0,na(),Gt("user"),!0):!1},injectMessage(l){return!h&&b&&ne(!0,"system"),$.injectMessage(l)},injectAssistantMessage(l){!h&&b&&ne(!0,"system");let v=$.injectAssistantMessage(l);return g&&(g=!1,M&&(clearTimeout(M),M=null),setTimeout(()=>{$&&!$.isStreaming()&&$.continueConversation()},100)),v},injectUserMessage(l){return!h&&b&&ne(!0,"system"),$.injectUserMessage(l)},injectSystemMessage(l){return!h&&b&&ne(!0,"system"),$.injectSystemMessage(l)},injectMessageBatch(l){return!h&&b&&ne(!0,"system"),$.injectMessageBatch(l)},injectTestMessage(l){!h&&b&&ne(!0,"system"),$.injectTestEvent(l)},__pushEventStreamEvent(l){_&&_.push({id:`evt-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,type:l.type,timestamp:Date.now(),payload:JSON.stringify(l.payload)})},showEventStream(){!W||!_||bt()},hideEventStream(){Mt&&Wt()},isEventStreamVisible(){return Mt},getMessages(){return $.getMessages()},getStatus(){return $.getStatus()},getPersistentMetadata(){return{...d}},updatePersistentMetadata(l){c(l)},on(l,v){return o.on(l,v)},off(l,v){o.off(l,v)},isOpen(){return b&&h},isVoiceActive(){return Kt.active},getState(){return{open:b&&h,launcherEnabled:b,voiceActive:Kt.active,streaming:$.isStreaming()}},showCSATFeedback(l){!h&&b&&ne(!0,"system");let v=se.querySelector(".tvw-feedback-container");v&&v.remove();let P=VS({onSubmit:async(D,B)=>{var Z;$.isClientTokenMode()&&await $.submitCSATFeedback(D,B),(Z=l==null?void 0:l.onSubmit)==null||Z.call(l,D,B)},onDismiss:l==null?void 0:l.onDismiss,...l});se.appendChild(P),P.scrollIntoView({behavior:"smooth",block:"end"})},showNPSFeedback(l){!h&&b&&ne(!0,"system");let v=se.querySelector(".tvw-feedback-container");v&&v.remove();let P=FS({onSubmit:async(D,B)=>{var Z;$.isClientTokenMode()&&await $.submitNPSFeedback(D,B),(Z=l==null?void 0:l.onSubmit)==null||Z.call(l,D,B)},onDismiss:l==null?void 0:l.onDismiss,...l});se.appendChild(P),P.scrollIntoView({behavior:"smooth",block:"end"})},async submitCSATFeedback(l,v){return $.submitCSATFeedback(l,v)},async submitNPSFeedback(l,v){return $.submitNPSFeedback(l,v)},destroy(){xe.forEach(l=>l()),Bt.remove(),F==null||F.destroy(),k==null||k.remove(),Qe&&Q.removeEventListener("click",Qe)}};if((((_A=a==null?void 0:a.debugTools)!=null?_A:!1)||!!t.debug)&&typeof window!="undefined"){let l=window.AgentWidgetBrowser,v={controller:Yt,getMessages:Yt.getMessages,getStatus:Yt.getStatus,getMetadata:Yt.getPersistentMetadata,updateMetadata:Yt.updatePersistentMetadata,clearHistory:()=>Yt.clearChat(),setVoiceActive:P=>P?Yt.startVoiceRecognition():Yt.stopVoiceRecognition()};window.AgentWidgetBrowser=v,xe.push(()=>{window.AgentWidgetBrowser===v&&(window.AgentWidgetBrowser=l)})}if(W&&typeof window!="undefined"){let l=r.getAttribute("data-persona-instance")||r.id||"persona-"+Math.random().toString(36).slice(2,8),v=D=>{let B=D.detail;(!(B!=null&&B.instanceId)||B.instanceId===l)&&Yt.showEventStream()},P=D=>{let B=D.detail;(!(B!=null&&B.instanceId)||B.instanceId===l)&&Yt.hideEventStream()};window.addEventListener("persona:showEventStream",v),window.addEventListener("persona:hideEventStream",P),xe.push(()=>{window.removeEventListener("persona:showEventStream",v),window.removeEventListener("persona:hideEventStream",P)})}let Ut=kP(t.persistState);if(Ut&&b){let l=HP(Ut.storage),v=`${Ut.keyPrefix}widget-open`,P=`${Ut.keyPrefix}widget-voice`,D=`${Ut.keyPrefix}widget-voice-mode`;if(l){let B=((jA=Ut.persist)==null?void 0:jA.openState)&&l.getItem(v)==="true",Z=((GA=Ut.persist)==null?void 0:GA.voiceState)&&l.getItem(P)==="true",wt=((ZA=Ut.persist)==null?void 0:ZA.voiceState)&&l.getItem(D)==="true";if(B&&setTimeout(()=>{Yt.open(),setTimeout(()=>{var pt;if(Z||wt)Yt.startVoiceRecognition();else if((pt=Ut.persist)!=null&&pt.focusInput){let Ht=r.querySelector("textarea");Ht&&Ht.focus()}},100)},0),(XA=Ut.persist)!=null&&XA.openState&&(o.on("widget:opened",()=>{l.setItem(v,"true")}),o.on("widget:closed",()=>{l.setItem(v,"false")})),(JA=Ut.persist)!=null&&JA.voiceState&&(o.on("voice:state",pt=>{l.setItem(P,pt.active?"true":"false")}),o.on("user:message",pt=>{l.setItem(D,pt.viaVoice?"true":"false")})),Ut.clearOnChatClear){let pt=()=>{l.removeItem(v),l.removeItem(P),l.removeItem(D)},Ht=()=>pt();window.addEventListener("persona:clear-chat",Ht),xe.push(()=>{window.removeEventListener("persona:clear-chat",Ht)})}}}return Yt};var SA={},LP=r=>{if(typeof window=="undefined"||typeof document=="undefined")throw new Error("Chat widget can only be mounted in a browser environment");if(typeof r=="string"){let e=document.querySelector(r);if(!e)throw new Error(`Chat widget target "${r}" was not found`);return e}return r},TP=()=>{try{if(typeof SA!="undefined"&&SA.url)return new URL("../widget.css",SA.url).href}catch{}return null},WL=r=>{let e=TP(),a=()=>{if(!(r instanceof ShadowRoot)||r.querySelector("link[data-persona]"))return;let t=document.head.querySelector("link[data-persona]");if(!t)return;let s=t.cloneNode(!0);r.insertBefore(s,r.firstChild)};if(r instanceof ShadowRoot)if(e){let t=document.createElement("link");t.rel="stylesheet",t.href=e,t.setAttribute("data-persona","true"),r.insertBefore(t,r.firstChild)}else a();else if(!document.head.querySelector("link[data-persona]")&&e){let s=document.createElement("link");s.rel="stylesheet",s.href=e,s.setAttribute("data-persona","true"),document.head.appendChild(s)}},AA=r=>{var f,m,c,p;let e=LP(r.target),a=document.createElement("div");a.className="persona-host";let t=(c=(m=(f=r.config)==null?void 0:f.launcher)==null?void 0:m.enabled)!=null?c:!0;t||(a.style.height="100%"),e.appendChild(a);let s=r.useShadowDom===!0,o,n;if(s){let u=a.attachShadow({mode:"open"});n=u,o=document.createElement("div"),o.id="persona-root",t||(o.style.height="100%",o.style.display="flex",o.style.flexDirection="column",o.style.flex="1",o.style.minHeight="0"),u.appendChild(o),WL(u)}else n=a,o=document.createElement("div"),o.id="persona-root",t||(o.style.height="100%",o.style.display="flex",o.style.flexDirection="column",o.style.flex="1",o.style.minHeight="0"),a.appendChild(o),WL(a);e.id&&o.setAttribute("data-persona-instance",e.id);let d=IS(o,r.config,{debugTools:r.debugTools});(p=r.onReady)==null||p.call(r);let i={...d,host:a,destroy(){d.destroy(),a.remove(),r.windowKey&&typeof window!="undefined"&&delete window[r.windowKey]}};return r.windowKey&&typeof window!="undefined"&&(window[r.windowKey]=i),i};var OL={name:"@runtypelabs/persona",version:"1.43.4",description:"Themeable, pluggable streaming agent widget for websites, in plain JS with support for voice input and reasoning / tool output.",type:"module",main:"dist/index.cjs",module:"dist/index.js",types:"dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js",require:"./dist/index.cjs"},"./widget.css":{import:"./widget.css",default:"./dist/widget.css"}},files:["dist","widget.css","src"],scripts:{build:"rimraf dist && npm run build:styles && npm run build:client && npm run build:installer","build:styles":`node -e "const fs=require('fs');fs.mkdirSync('dist',{recursive:true});fs.copyFileSync('src/styles/widget.css','dist/widget.css');"`,"build:client":'tsup src/index.ts --format esm,cjs,iife --global-name AgentWidget --minify --sourcemap --splitting false --dts --loader ".css=text"',"build:installer":"tsup src/install.ts --format iife --global-name SiteAgentInstaller --out-dir dist --minify --sourcemap --no-splitting",lint:"eslint . --ext .ts",typecheck:"tsc --noEmit",test:"vitest","test:ui":"vitest --ui","test:run":"vitest run"},dependencies:{idiomorph:"^0.7.4",lucide:"^0.552.0",marked:"^12.0.2","partial-json":"^0.1.7",zod:"^3.22.4"},devDependencies:{"@types/node":"^20.12.7","@typescript-eslint/eslint-plugin":"^7.0.0","@typescript-eslint/parser":"^7.0.0","@vitest/ui":"^4.0.9",eslint:"^8.57.0","eslint-config-prettier":"^9.1.0","fake-indexeddb":"^6.2.5",postcss:"^8.4.38",rimraf:"^5.0.5",tailwindcss:"^3.4.10",tsup:"^8.0.1",typescript:"^5.4.5",vitest:"^4.0.9"},engines:{node:">=18.17.0"},license:"MIT",keywords:["ai","chat","widget","streaming","typescript","persona","agent"],repository:{type:"git",url:"git+https://github.com/runtypelabs/persona.git",directory:"packages/widget"},bugs:{url:"https://github.com/runtypelabs/persona/issues"},homepage:"https://github.com/runtypelabs/persona/tree/main/packages/widget#readme",publishConfig:{access:"public"}};var Ua=OL.version;function fa(r){if(r!==void 0)return typeof r=="string"?r:Array.isArray(r)?`[${r.map(e=>e.toString()).join(", ")}]`:r.toString()}function EP(r){if(r)return{getHeaders:fa(r.getHeaders),onFeedback:fa(r.onFeedback),onCopy:fa(r.onCopy),requestMiddleware:fa(r.requestMiddleware),actionHandlers:fa(r.actionHandlers),actionParsers:fa(r.actionParsers),postprocessMessage:fa(r.postprocessMessage),contextProviders:fa(r.contextProviders),streamParser:fa(r.streamParser)}}var zL=`({ text, message }: any) => {
109
+ `}if(!O){let Pa="max-height: -moz-available !important; max-height: stretch !important;",Ea=l?"":"padding-top: 1.25em !important;";Bt.style.cssText+=Pa+Ea}};pe(),kS(r,t);let xe=[];W&&xe.push(()=>{ct!==null&&(cancelAnimationFrame(ct),ct=null),et==null||et.destroy(),et=null,_==null||_.destroy(),_=null,z=null});let _e=null,mn=()=>{_e&&(_e(),_e=null),t.colorScheme==="auto"&&(_e=yL(()=>{kS(r,t)}))};mn(),xe.push(()=>{_e&&(_e(),_e=null)});let ua=TL(Te),Qe=null,$,ma=!1,ra=!0,ka=0,xn=0,oa=null,sa=!1,$a=0,_a=!1,$n=125,_n=2e3,jn=5,gn=50,ja=new Map,Kt={active:!1,manuallyDeactivated:!1,lastUserMessageWasVoice:!1,lastUserMessageId:null},Mn=($A=(UA=t.voiceRecognition)==null?void 0:UA.autoResume)!=null?$A:!1,vn=l=>{o.emit("voice:state",{active:Kt.active,source:l,timestamp:Date.now()})},na=()=>{c(l=>({...l,voiceState:{active:Kt.active,timestamp:Date.now(),manuallyDeactivated:Kt.manuallyDeactivated}}))},Gn=()=>{var D,B;if(((D=t.voiceRecognition)==null?void 0:D.enabled)===!1)return;let l=bA(d.voiceState),v=!!l.active,P=Number((B=l.timestamp)!=null?B:0);Kt.manuallyDeactivated=!!l.manuallyDeactivated,v&&Date.now()-P<AP&&setTimeout(()=>{Kt.active||(Kt.manuallyDeactivated=!1,Vt("restore"))},1e3)},Zn=()=>$?IL($.getMessages()).filter(l=>!l.__skipPersist):[];function yn(l){if(!(n!=null&&n.save))return;let P={messages:l?IL(l):$?Zn():[],metadata:d};try{let D=n.save(P);D instanceof Promise&&D.catch(B=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",B)})}catch(D){typeof console!="undefined"&&console.error("[AgentWidget] Failed to persist state:",D)}}let Ha=(l=!1)=>{if(!ra)return;let v=Date.now();sa&&v<$a&&!l||(sa&&v>=$a&&(sa=!1),!(!l&&!ma)&&(v-xn<$n||(xn=v,oa&&cancelAnimationFrame(oa),oa=requestAnimationFrame(()=>{sa||!ra||(_a=!0,Rt.scrollTop=Rt.scrollHeight,ka=Rt.scrollTop,requestAnimationFrame(()=>{_a=!1}),oa=null)}))))},da=null,Xn=()=>Bt.querySelector("#persona-scroll-container")||Rt,Jn=(l,v=500)=>{let P=l.scrollTop,D=l.clientHeight,B=l.scrollHeight,Z=B-P;if(P+D>=B-2||Math.abs(Z)<5)return;da!==null&&(cancelAnimationFrame(da),da=null);let pt=performance.now(),Ht=It=>1-Math.pow(1-It,3),Ft=It=>{let qt=l.scrollHeight;qt!==B&&(B=qt,Z=B-P);let ot=It-pt,O=Math.min(ot/v,1),gt=Ht(O),vt=P+Z*gt;l.scrollTop=vt,O<1?da=requestAnimationFrame(Ft):(l.scrollTop=l.scrollHeight,da=null)};da=requestAnimationFrame(Ft)},Kn=l=>{let v=new Map;l.forEach(P=>{let D=ja.get(P.id);v.set(P.id,{streaming:P.streaming,role:P.role}),!D&&P.role==="assistant"&&o.emit("assistant:message",P),P.role==="assistant"&&(D!=null&&D.streaming)&&P.streaming===!1&&o.emit("assistant:complete",P)}),ja.clear(),v.forEach((P,D)=>{ja.set(D,P)})},La=(l,v,P)=>{var Ft,It,qt,ot;let D=document.createElement("div"),Z=(()=>{var gt;let O=s.find(vt=>vt.renderLoadingIndicator);if(O!=null&&O.renderLoadingIndicator)return O.renderLoadingIndicator;if((gt=t.loadingIndicator)!=null&&gt.render)return t.loadingIndicator.render})();v.forEach(O=>{var Me,Ie;let gt=null,vt=s.find(K=>!!(O.variant==="reasoning"&&K.renderReasoning||O.variant==="tool"&&K.renderToolCall||!O.variant&&K.renderMessage)),Qt=(Me=t.layout)==null?void 0:Me.messages;if(vt)if(O.variant==="reasoning"&&O.reasoning&&vt.renderReasoning){if(!L)return;gt=vt.renderReasoning({message:O,defaultRenderer:()=>uA(O),config:t})}else if(O.variant==="tool"&&O.toolCall&&vt.renderToolCall){if(!I)return;gt=vt.renderToolCall({message:O,defaultRenderer:()=>mA(O,t),config:t})}else vt.renderMessage&&(gt=vt.renderMessage({message:O,defaultRenderer:()=>{let K=dn(O,P,Qt,t.messageActions,Pe,{loadingIndicatorRenderer:Z,widgetConfig:t});return O.role!=="user"&&gA(K,O,t,$),K},config:t}));if(!gt&&O.role==="assistant"&&!O.variant&&t.enableComponentStreaming!==!1&&BS(O)){let Nt=RS(O);if(Nt){let ta=ES(Nt,{config:t,message:O,transform:P});if(ta){let Ke=document.createElement("div");if(Ke.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(" "),Ke.id=`bubble-${O.id}`,Ke.setAttribute("data-message-id",O.id),O.content&&O.content.trim()){let xa=document.createElement("div");xa.className="tvw-mb-3 tvw-text-sm tvw-leading-relaxed",xa.innerHTML=P({text:O.content,message:O,streaming:!!O.streaming,raw:O.rawContent}),Ke.appendChild(xa)}Ke.appendChild(ta),gt=Ke}}}if(!gt)if(O.variant==="reasoning"&&O.reasoning){if(!L)return;gt=uA(O)}else if(O.variant==="tool"&&O.toolCall){if(!I)return;gt=mA(O,t)}else{let K=(Ie=t.layout)==null?void 0:Ie.messages;K!=null&&K.renderUserMessage&&O.role==="user"?gt=K.renderUserMessage({message:O,config:t,streaming:!!O.streaming}):K!=null&&K.renderAssistantMessage&&O.role==="assistant"?gt=K.renderAssistantMessage({message:O,config:t,streaming:!!O.streaming}):gt=dn(O,P,K,t.messageActions,Pe,{loadingIndicatorRenderer:Z,widgetConfig:t}),O.role!=="user"&&gt&&gA(gt,O,t,$)}let Tt=document.createElement("div");Tt.className="tvw-flex",Tt.id=`wrapper-${O.id}`,Tt.setAttribute("data-wrapper-id",O.id),O.role==="user"&&Tt.classList.add("tvw-justify-end"),Tt.appendChild(gt),D.appendChild(Tt)});let wt=v.some(O=>O.role==="assistant"&&O.streaming),pt=v[v.length-1],Ht=(pt==null?void 0:pt.role)==="assistant"&&!pt.streaming;if(ma&&v.some(O=>O.role==="user")&&!wt&&!Ht){let O={config:t,streaming:!0,location:"standalone",defaultRenderer:qa},gt=s.find(Qt=>Qt.renderLoadingIndicator),vt=null;if(gt!=null&&gt.renderLoadingIndicator&&(vt=gt.renderLoadingIndicator(O)),vt===null&&((Ft=t.loadingIndicator)!=null&&Ft.render)&&(vt=t.loadingIndicator.render(O)),vt===null&&(vt=qa()),vt){let Qt=document.createElement("div"),Tt=((It=t.loadingIndicator)==null?void 0:It.showBubble)!==!1;Qt.className=Tt?["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(" "):["tvw-max-w-[85%]","tvw-text-sm","tvw-leading-relaxed","tvw-text-cw-primary"].join(" "),Qt.setAttribute("data-typing-indicator","true"),Qt.appendChild(vt);let Me=document.createElement("div");Me.className="tvw-flex",Me.id="wrapper-typing-indicator",Me.setAttribute("data-wrapper-id","typing-indicator"),Me.appendChild(Qt),D.appendChild(Me)}}if(!ma&&v.length>0){let O=v[v.length-1],gt={config:t,lastMessage:O,messageCount:v.length},vt=s.find(Tt=>Tt.renderIdleIndicator),Qt=null;if(vt!=null&&vt.renderIdleIndicator&&(Qt=vt.renderIdleIndicator(gt)),Qt===null&&((qt=t.loadingIndicator)!=null&&qt.renderIdle)&&(Qt=t.loadingIndicator.renderIdle(gt)),Qt){let Tt=document.createElement("div"),Me=((ot=t.loadingIndicator)==null?void 0:ot.showBubble)!==!1;Tt.className=Me?["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(" "):["tvw-max-w-[85%]","tvw-text-sm","tvw-leading-relaxed","tvw-text-cw-primary"].join(" "),Tt.setAttribute("data-idle-indicator","true"),Tt.appendChild(Qt);let Ie=document.createElement("div");Ie.className="tvw-flex",Ie.id="wrapper-idle-indicator",Ie.setAttribute("data-wrapper-id","idle-indicator"),Ie.appendChild(Tt),D.appendChild(Ie)}}CL(l,D),requestAnimationFrame(()=>{requestAnimationFrame(()=>{let O=Xn();Jn(O)})})},Ta=()=>{b&&(h?(Bt.classList.remove("tvw-pointer-events-none","tvw-opacity-0"),yt.classList.remove("tvw-scale-95","tvw-opacity-0"),yt.classList.add("tvw-scale-100","tvw-opacity-100"),F?F.element.style.display="none":k&&(k.style.display="none")):(Bt.classList.add("tvw-pointer-events-none","tvw-opacity-0"),yt.classList.remove("tvw-scale-100","tvw-opacity-100"),yt.classList.add("tvw-scale-95","tvw-opacity-0"),F?F.element.style.display="":k&&(k.style.display="")))},ne=(l,v="user")=>{if(!b||h===l)return;let P=h;h=l,Ta(),h&&(R(),Ha(!0));let D={open:h,source:v,timestamp:Date.now()};h&&!P?o.emit("widget:opened",D):!h&&P&&o.emit("widget:closed",D),o.emit("widget:state",{open:h,launcherEnabled:b,voiceActive:Kt.active,streaming:$.isStreaming()})},Ga=l=>{J.disabled=l,j&&(j.disabled=l),ua.buttons.forEach(v=>{v.disabled=l})},wn=()=>{var B,Z,wt,pt,Ht,Ft,It,qt,ot,O,gt,vt,Qt,Tt;$e.textContent=(Z=(B=t.copy)==null?void 0:B.welcomeTitle)!=null?Z:"Hello \u{1F44B}",we.textContent=(pt=(wt=t.copy)==null?void 0:wt.welcomeSubtitle)!=null?pt:"Ask anything about your account or products.",ut.placeholder=(Ft=(Ht=t.copy)==null?void 0:Ht.inputPlaceholder)!=null?Ft:"How can I help...",((qt=(It=t.sendButton)==null?void 0:It.useIcon)!=null?qt:!1)||(J.textContent=(O=(ot=t.copy)==null?void 0:ot.sendButtonLabel)!=null?O:"Send");let v=(vt=(gt=t.theme)==null?void 0:gt.inputFontFamily)!=null?vt:"sans-serif",P=(Tt=(Qt=t.theme)==null?void 0:Qt.inputFontWeight)!=null?Tt:"400",D=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'}};ut.style.fontFamily=D(v),ut.style.fontWeight=P};t.clientToken&&(t={...t,getStoredSessionId:()=>{let l=d.sessionId;return typeof l=="string"?l:null},setStoredSessionId:l=>{c(v=>({...v,sessionId:l}))}}),$=new Ka(t,{onMessagesChanged(l){La(se,l,E),$&&(l.some(B=>B.role==="user")?ua.render([],$,ut,l):ua.render(t.suggestionChips,$,ut,l,t.suggestionChipsConfig)),Ha(!ma),Kn(l);let v=[...l].reverse().find(D=>D.role==="user"),P=Kt.lastUserMessageId;v&&v.id!==P&&(Kt.lastUserMessageId=v.id,o.emit("user:message",v)),Kt.lastUserMessageWasVoice=!!(v!=null&&v.viaVoice),yn(l)},onStatusChanged(l){var D;let v=(D=t.statusIndicator)!=null?D:{},P=B=>{var Z,wt,pt,Ht;return B==="idle"?(Z=v.idleText)!=null?Z:De.idle:B==="connecting"?(wt=v.connectingText)!=null?wt:De.connecting:B==="connected"?(pt=v.connectedText)!=null?pt:De.connected:B==="error"?(Ht=v.errorText)!=null?Ht:De.error:De[B]};ye.textContent=P(l)},onStreamingChanged(l){ma=l,Ga(l),$&&La(se,$.getMessages(),E),l||Ha(!0)}}),t.clientToken&&$.initClientSession().catch(l=>{t.debug&&console.warn("[AgentWidget] Pre-init client session failed:",l)}),_&&$.setSSEEventCallback((l,v)=>{_==null||_.push({id:`evt-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,type:l,timestamp:Date.now(),payload:JSON.stringify(v)})}),i&&i.then(l=>{var v;l&&(l.metadata&&(d=bA(l.metadata),y.syncFromMetadata()),(v=l.messages)!=null&&v.length&&$.hydrateMessages(l.messages))}).catch(l=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to hydrate stored state:",l)});let Cn=l=>{var B;l.preventDefault();let v=ut.value.trim(),P=(B=ht==null?void 0:ht.hasAttachments())!=null?B:!1;if(!v&&!P)return;let D;P&&(D=[],D.push(...ht.getContentParts()),v&&D.push(bS(v))),ut.value="",ut.style.height="auto",$.sendMessage(v,{contentParts:D}),P&&ht.clearAttachments()},bn=l=>{l.key==="Enter"&&!l.shiftKey&&(l.preventDefault(),J.click())},We=null,je=!1,la=null,q=null,kt=()=>typeof window=="undefined"?null:window.webkitSpeechRecognition||window.SpeechRecognition||null,Vt=(l="user")=>{var Z,wt,pt,Ht;if(je||$.isStreaming())return;let v=kt();if(!v)return;We=new v;let D=(wt=((Z=t.voiceRecognition)!=null?Z:{}).pauseDuration)!=null?wt:2e3;We.continuous=!0,We.interimResults=!0,We.lang="en-US";let B=ut.value;We.onresult=Ft=>{let It="",qt="";for(let O=0;O<Ft.results.length;O++){let gt=Ft.results[O],vt=gt[0].transcript;gt.isFinal?It+=vt+" ":qt=vt}let ot=B+It+qt;ut.value=ot,la&&clearTimeout(la),(It||qt)&&(la=window.setTimeout(()=>{let O=ut.value.trim();O&&We&&je&&(Gt(),ut.value="",ut.style.height="auto",$.sendMessage(O,{viaVoice:!0}))},D))},We.onerror=Ft=>{Ft.error!=="no-speech"&&Gt()},We.onend=()=>{if(je){let Ft=ut.value.trim();Ft&&Ft!==B.trim()&&(ut.value="",ut.style.height="auto",$.sendMessage(Ft,{viaVoice:!0})),Gt()}};try{if(We.start(),je=!0,Kt.active=!0,l!=="system"&&(Kt.manuallyDeactivated=!1),vn(l),na(),j){q={backgroundColor:j.style.backgroundColor,color:j.style.color,borderColor:j.style.borderColor};let Ft=(pt=t.voiceRecognition)!=null?pt:{},It=(Ht=Ft.recordingBackgroundColor)!=null?Ht:"#ef4444",qt=Ft.recordingIconColor,ot=Ft.recordingBorderColor;if(j.classList.add("tvw-voice-recording"),j.style.backgroundColor=It,qt){j.style.color=qt;let O=j.querySelector("svg");O&&O.setAttribute("stroke",qt)}ot&&(j.style.borderColor=ot),j.setAttribute("aria-label","Stop voice recognition")}}catch{Gt("system")}},Gt=(l="user")=>{if(je){if(je=!1,la&&(clearTimeout(la),la=null),We){try{We.stop()}catch{}We=null}if(Kt.active=!1,vn(l),na(),j){if(j.classList.remove("tvw-voice-recording"),q){j.style.backgroundColor=q.backgroundColor,j.style.color=q.color,j.style.borderColor=q.borderColor;let v=j.querySelector("svg");v&&v.setAttribute("stroke",q.color||"currentColor"),q=null}j.setAttribute("aria-label","Start voice recognition")}}},Ae=(l,v)=>{var vt,Qt,Tt,Me,Ie,K,Nt;if(!(typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined")))return null;let D=w("div","tvw-send-button-wrapper"),B=w("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 Z=(vt=l==null?void 0:l.iconName)!=null?vt:"mic",wt=(Qt=v==null?void 0:v.size)!=null?Qt:"40px",pt=(Tt=l==null?void 0:l.iconSize)!=null?Tt:wt,Ht=parseFloat(pt)||24,Ft=(Me=l==null?void 0:l.backgroundColor)!=null?Me:v==null?void 0:v.backgroundColor,It=(Ie=l==null?void 0:l.iconColor)!=null?Ie:v==null?void 0:v.textColor;B.style.width=pt,B.style.height=pt,B.style.minWidth=pt,B.style.minHeight=pt,B.style.fontSize="18px",B.style.lineHeight="1";let qt=It||"currentColor",ot=nt(Z,Ht,qt,1.5);ot?(B.appendChild(ot),B.style.color=qt):(B.textContent="\u{1F3A4}",B.style.color=qt),Ft?B.style.backgroundColor=Ft:B.classList.add("tvw-bg-cw-primary"),It?B.style.color=It:!It&&!(v!=null&&v.textColor)&&B.classList.add("tvw-text-white"),l!=null&&l.borderWidth&&(B.style.borderWidth=l.borderWidth,B.style.borderStyle="solid"),l!=null&&l.borderColor&&(B.style.borderColor=l.borderColor),l!=null&&l.paddingX&&(B.style.paddingLeft=l.paddingX,B.style.paddingRight=l.paddingX),l!=null&&l.paddingY&&(B.style.paddingTop=l.paddingY,B.style.paddingBottom=l.paddingY),D.appendChild(B);let O=(K=l==null?void 0:l.tooltipText)!=null?K:"Start voice recognition";if(((Nt=l==null?void 0:l.showTooltip)!=null?Nt:!1)&&O){let ta=w("div","tvw-send-button-tooltip");ta.textContent=O,D.appendChild(ta)}return{micButton:B,micButtonWrapper:D}},ke=()=>{if(je){let l=ut.value.trim();Kt.manuallyDeactivated=!0,na(),Gt("user"),l&&(ut.value="",ut.style.height="auto",$.sendMessage(l))}else Kt.manuallyDeactivated=!1,na(),Vt("user")};j&&(j.addEventListener("click",ke),xe.push(()=>{Gt("system"),j&&j.removeEventListener("click",ke)}));let de=o.on("assistant:complete",()=>{Mn&&(Kt.active||Kt.manuallyDeactivated||Mn==="assistant"&&!Kt.lastUserMessageWasVoice||setTimeout(()=>{!Kt.active&&!Kt.manuallyDeactivated&&Vt("auto")},600))});xe.push(de);let T=o.on("action:resubmit",()=>{setTimeout(()=>{$&&!$.isStreaming()&&$.continueConversation()},100)});xe.push(T);let Ot=()=>{ne(!h,"user")},F=null,k=null;if(b){let l=s.find(v=>v.renderLauncher);if(l!=null&&l.renderLauncher){let v=l.renderLauncher({config:t,defaultRenderer:()=>Wn(t,Ot).element,onToggle:Ot});v&&(k=v)}k||(F=Wn(t,Ot))}F?r.appendChild(F.element):k&&r.appendChild(k),Ta(),ua.render(t.suggestionChips,$,ut,void 0,t.suggestionChipsConfig),wn(),Ga($.isStreaming()),Ha(!0),Gn();let R=()=>{var P,D,B,Z,wt,pt,Ht,Ft;let l=(D=(P=t.launcher)==null?void 0:P.sidebarMode)!=null?D:!1,v=l||((Z=(B=t.launcher)==null?void 0:B.fullHeight)!=null?Z:!1);if(!b){yt.style.height="",yt.style.width="";return}if(!l){let It=(pt=(wt=t==null?void 0:t.launcher)==null?void 0:wt.width)!=null?pt:t==null?void 0:t.launcherWidth,qt=It!=null?It:"min(400px, calc(100vw - 24px))";yt.style.width=qt,yt.style.maxWidth=qt}if(!v){let It=window.innerHeight,qt=64,ot=(Ft=(Ht=t.launcher)==null?void 0:Ht.heightOffset)!=null?Ft:0,O=Math.max(200,It-qt),gt=Math.min(640,O),vt=Math.max(200,gt-ot);yt.style.height=`${vt}px`}};R(),window.addEventListener("resize",R),xe.push(()=>window.removeEventListener("resize",R)),ka=Rt.scrollTop;let lt=()=>{let l=Rt.scrollTop,v=Rt.scrollHeight,P=Rt.clientHeight,D=v-l-P,B=Math.abs(l-ka);if(ka=l,!_a&&!(B<=jn)){if(!ra&&D<gn){sa=!1,ra=!0;return}ra&&D>gn&&(sa=!0,$a=Date.now()+_n,ra=!1)}};Rt.addEventListener("scroll",lt,{passive:!0}),xe.push(()=>Rt.removeEventListener("scroll",lt)),xe.push(()=>{oa&&cancelAnimationFrame(oa)});let re=()=>{Q&&(Qe&&(Q.removeEventListener("click",Qe),Qe=null),b?(Q.style.display="",Qe=()=>{h=!1,Ta()},Q.addEventListener("click",Qe)):Q.style.display="none")};re(),(()=>{let{clearChatButton:l}=at;l&&l.addEventListener("click",()=>{$.clearMessages();try{localStorage.removeItem(un),t.debug&&console.log(`[AgentWidget] Cleared default localStorage key: ${un}`)}catch(P){console.error("[AgentWidget] Failed to clear default localStorage:",P)}if(t.clearChatHistoryStorageKey&&t.clearChatHistoryStorageKey!==un)try{localStorage.removeItem(t.clearChatHistoryStorageKey),t.debug&&console.log(`[AgentWidget] Cleared custom localStorage key: ${t.clearChatHistoryStorageKey}`)}catch(P){console.error("[AgentWidget] Failed to clear custom localStorage:",P)}let v=new CustomEvent("persona:clear-chat",{detail:{timestamp:new Date().toISOString()}});if(window.dispatchEvent(v),n!=null&&n.clear)try{let P=n.clear();P instanceof Promise&&P.catch(D=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",D)})}catch(P){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",P)}d={},y.syncFromMetadata(),_==null||_.clear(),et==null||et.update()})})(),me.addEventListener("submit",Cn),ut.addEventListener("keydown",bn),xe.push(()=>{me.removeEventListener("submit",Cn),ut.removeEventListener("keydown",bn)}),xe.push(()=>{$.cancel()}),F?xe.push(()=>{F==null||F.destroy()}):k&&xe.push(()=>{k==null||k.remove()});let Yt={update(l){var KA,YA,QA,tk,ek,ak,rk,ok,sk,nk,dk,lk,ik,pk,hk,ck,fk,uk,mk,xk,gk,Mk,vk,yk,wk,Ck,bk,Sk,Ak,kk,Hk,Lk,Tk,Pk,Ek,Bk,Rk,Vk,Fk,Ik,Dk,Wk,Ok,zk,qk,Nk,Uk,$k,_k,jk,Gk,Zk,Xk,Jk,Kk,Yk,Qk,tH,eH,aH,rH,oH,sH,nH,dH,lH,iH,pH,hH,cH,fH,uH,mH,xH,gH,MH,vH,yH,wH,CH,bH,SH,AH,kH,HH,LH;let v=t.toolCall,P=t.colorScheme;t={...t,...l},pe(),kS(r,t),t.colorScheme!==P&&mn();let D=qn.getForInstance(t.plugins);s.length=0,s.push(...D),b=(YA=(KA=t.launcher)==null?void 0:KA.enabled)!=null?YA:!0,A=(tk=(QA=t.launcher)==null?void 0:QA.autoExpand)!=null?tk:!1,L=(ak=(ek=t.features)==null?void 0:ek.showReasoning)!=null?ak:!0,I=(ok=(rk=t.features)==null?void 0:rk.showToolCalls)!=null?ok:!0;let B=W;if(W=(nk=(sk=t.features)==null?void 0:sk.showEventStreamToggle)!=null?nk:!1,W&&!B){if(_||(z=new zn(it),_=new On(st,z),z.open().then(()=>_==null?void 0:_.restore()).catch(()=>{}),$.setSSEEventCallback((V,Ct)=>{_.push({id:`evt-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,type:V,timestamp:Date.now(),payload:JSON.stringify(Ct)})})),!G&&tt){let V=(lk=(dk=t.features)==null?void 0:dk.eventStream)==null?void 0:lk.classNames,Ct="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 tvw-bg-transparent tvw-p-1"+(V!=null&&V.toggleButton?" "+V.toggleButton:"");G=w("button",Ct),G.style.width="28px",G.style.height="28px",G.type="button",G.setAttribute("aria-label","Event Stream"),G.title="Event Stream";let te=nt("activity","18px","currentColor",1.5);te&&G.appendChild(te);let xt=at.clearChatButtonWrapper,Et=at.closeButtonWrapper,ve=xt||Et;ve&&ve.parentNode===tt?tt.insertBefore(G,ve):tt.appendChild(G),G.addEventListener("click",()=>{Mt?Wt():bt()})}}else!W&&B&&(Wt(),G&&(G.remove(),G=null),_==null||_.clear(),z==null||z.destroy(),_=null,z=null);if(((ik=t.launcher)==null?void 0:ik.enabled)===!1&&F&&(F.destroy(),F=null),((pk=t.launcher)==null?void 0:pk.enabled)===!1&&k&&(k.remove(),k=null),((hk=t.launcher)==null?void 0:hk.enabled)!==!1&&!F&&!k){let V=s.find(Ct=>Ct.renderLauncher);if(V!=null&&V.renderLauncher){let Ct=V.renderLauncher({config:t,defaultRenderer:()=>Wn(t,Ot).element,onToggle:Ot});Ct&&(k=Ct,r.appendChild(k))}k||(F=Wn(t,Ot),r.appendChild(F.element))}F&&F.update(t),Ce&&((ck=t.launcher)==null?void 0:ck.title)!==void 0&&(Ce.textContent=t.launcher.title),be&&((fk=t.launcher)==null?void 0:fk.subtitle)!==void 0&&(be.textContent=t.launcher.subtitle);let Z=(uk=t.layout)==null?void 0:uk.header;if((Z==null?void 0:Z.layout)!==H&&tt){let V=Z?sn(t,Z,{showClose:b,onClose:()=>ne(!1,"user")}):ca({config:t,showClose:b,onClose:()=>ne(!1,"user")});tt.replaceWith(V.header),tt=V.header,Lt=V.iconHolder,Ce=V.headerTitle,be=V.headerSubtitle,Q=V.closeButton,H=Z==null?void 0:Z.layout}else if(Z&&(Lt&&(Lt.style.display=Z.showIcon===!1?"none":""),Ce&&(Ce.style.display=Z.showTitle===!1?"none":""),be&&(be.style.display=Z.showSubtitle===!1?"none":""),Q&&(Q.style.display=Z.showCloseButton===!1?"none":""),at.clearChatButtonWrapper)){let V=Z.showClearChat;if(V!==void 0){at.clearChatButtonWrapper.style.display=V?"":"none";let{closeButtonWrapper:Ct}=at;Ct&&!Ct.classList.contains("tvw-absolute")&&(V?Ct.classList.remove("tvw-ml-auto"):Ct.classList.add("tvw-ml-auto"))}}let pt=((mk=t.layout)==null?void 0:mk.showHeader)!==!1;tt&&(tt.style.display=pt?"":"none");let Ht=((xk=t.layout)==null?void 0:xk.showFooter)!==!1;Dt&&(Dt.style.display=Ht?"":"none"),b!==x?b?ne(A,"auto"):(h=!0,Ta()):A!==S&&ne(A,"auto"),S=A,x=b,R(),re(),JSON.stringify(l.toolCall)!==JSON.stringify(v)&&$&&La(se,$.getMessages(),E);let ot=(gk=t.launcher)!=null?gk:{},O=(Mk=ot.headerIconHidden)!=null?Mk:!1,gt=(yk=(vk=t.layout)==null?void 0:vk.header)==null?void 0:yk.showIcon,vt=O||gt===!1,Qt=ot.headerIconName,Tt=(wk=ot.headerIconSize)!=null?wk:"48px";if(Lt){let V=ft.querySelector(".tvw-border-b-cw-divider"),Ct=V==null?void 0:V.querySelector(".tvw-flex-col");if(vt)Lt.style.display="none",V&&Ct&&!V.contains(Ct)&&V.insertBefore(Ct,V.firstChild);else{if(Lt.style.display="",Lt.style.height=Tt,Lt.style.width=Tt,V&&Ct&&(V.contains(Lt)?Lt.nextSibling!==Ct&&(Lt.remove(),V.insertBefore(Lt,Ct)):V.insertBefore(Lt,Ct)),Qt){let xt=parseFloat(Tt)||24,Et=nt(Qt,xt*.6,"#ffffff",2);Et?Lt.replaceChildren(Et):Lt.textContent=(Ck=ot.agentIconText)!=null?Ck:"\u{1F4AC}"}else if(ot.iconUrl){let xt=Lt.querySelector("img");if(xt)xt.src=ot.iconUrl,xt.style.height=Tt,xt.style.width=Tt;else{let Et=document.createElement("img");Et.src=ot.iconUrl,Et.alt="",Et.className="tvw-rounded-xl tvw-object-cover",Et.style.height=Tt,Et.style.width=Tt,Lt.replaceChildren(Et)}}else{let xt=Lt.querySelector("svg"),Et=Lt.querySelector("img");(xt||Et)&&Lt.replaceChildren(),Lt.textContent=(bk=ot.agentIconText)!=null?bk:"\u{1F4AC}"}let te=Lt.querySelector("img");te&&(te.style.height=Tt,te.style.width=Tt)}}let Me=(Ak=(Sk=t.layout)==null?void 0:Sk.header)==null?void 0:Ak.showTitle,Ie=(Hk=(kk=t.layout)==null?void 0:kk.header)==null?void 0:Hk.showSubtitle;if(Ce&&(Ce.style.display=Me===!1?"none":""),be&&(be.style.display=Ie===!1?"none":""),Q){((Tk=(Lk=t.layout)==null?void 0:Lk.header)==null?void 0:Tk.showCloseButton)===!1?Q.style.display="none":Q.style.display="";let Ct=(Pk=ot.closeButtonSize)!=null?Pk:"32px",te=(Ek=ot.closeButtonPlacement)!=null?Ek:"inline";Q.style.height=Ct,Q.style.width=Ct;let{closeButtonWrapper:xt}=at,Et=te==="top-right",ve=xt==null?void 0:xt.classList.contains("tvw-absolute");if(xt&&Et!==ve)if(xt.remove(),Et)xt.className="tvw-absolute tvw-top-4 tvw-right-4 tvw-z-50",ft.style.position="relative",ft.appendChild(xt);else{let St=(Rk=(Bk=ot.clearChat)==null?void 0:Bk.placement)!=null?Rk:"inline",Le=(Fk=(Vk=ot.clearChat)==null?void 0:Vk.enabled)!=null?Fk:!0;xt.className=Le&&St==="inline"?"":"tvw-ml-auto";let Ne=ft.querySelector(".tvw-border-b-cw-divider");Ne&&Ne.appendChild(xt)}if(ot.closeButtonColor?(Q.style.color=ot.closeButtonColor,Q.classList.remove("tvw-text-cw-muted")):(Q.style.color="",Q.classList.add("tvw-text-cw-muted")),ot.closeButtonBackgroundColor?(Q.style.backgroundColor=ot.closeButtonBackgroundColor,Q.classList.remove("hover:tvw-bg-gray-100")):(Q.style.backgroundColor="",Q.classList.add("hover:tvw-bg-gray-100")),ot.closeButtonBorderWidth||ot.closeButtonBorderColor){let St=ot.closeButtonBorderWidth||"0px",Le=ot.closeButtonBorderColor||"transparent";Q.style.border=`${St} solid ${Le}`,Q.classList.remove("tvw-border-none")}else Q.style.border="",Q.classList.add("tvw-border-none");ot.closeButtonBorderRadius?(Q.style.borderRadius=ot.closeButtonBorderRadius,Q.classList.remove("tvw-rounded-full")):(Q.style.borderRadius="",Q.classList.add("tvw-rounded-full")),ot.closeButtonPaddingX?(Q.style.paddingLeft=ot.closeButtonPaddingX,Q.style.paddingRight=ot.closeButtonPaddingX):(Q.style.paddingLeft="",Q.style.paddingRight=""),ot.closeButtonPaddingY?(Q.style.paddingTop=ot.closeButtonPaddingY,Q.style.paddingBottom=ot.closeButtonPaddingY):(Q.style.paddingTop="",Q.style.paddingBottom="");let Re=(Ik=ot.closeButtonIconName)!=null?Ik:"x",Ge=(Dk=ot.closeButtonIconText)!=null?Dk:"\xD7";Q.innerHTML="";let Oe=nt(Re,"20px",ot.closeButtonColor||"",2);Oe?Q.appendChild(Oe):Q.textContent=Ge;let ie=(Wk=ot.closeButtonTooltipText)!=null?Wk:"Close chat",Ze=(Ok=ot.closeButtonShowTooltip)!=null?Ok:!0;if(Q.setAttribute("aria-label",ie),xt&&(xt._cleanupTooltip&&(xt._cleanupTooltip(),delete xt._cleanupTooltip),Ze&&ie)){let St=null,Le=()=>{if(St||!Q)return;St=w("div","tvw-clear-chat-tooltip"),St.textContent=ie;let Ln=w("div");Ln.className="tvw-clear-chat-tooltip-arrow",St.appendChild(Ln);let Ba=Q.getBoundingClientRect();St.style.position="fixed",St.style.left=`${Ba.left+Ba.width/2}px`,St.style.top=`${Ba.top-8}px`,St.style.transform="translate(-50%, -100%)",document.body.appendChild(St)},Ne=()=>{St&&St.parentNode&&(St.parentNode.removeChild(St),St=null)};xt.addEventListener("mouseenter",Le),xt.addEventListener("mouseleave",Ne),Q.addEventListener("focus",Le),Q.addEventListener("blur",Ne),xt._cleanupTooltip=()=>{Ne(),xt&&(xt.removeEventListener("mouseenter",Le),xt.removeEventListener("mouseleave",Ne)),Q&&(Q.removeEventListener("focus",Le),Q.removeEventListener("blur",Ne))}}}let{clearChatButton:K,clearChatButtonWrapper:Nt}=at;if(K){let V=(zk=ot.clearChat)!=null?zk:{},Ct=(qk=V.enabled)!=null?qk:!0,te=(Uk=(Nk=t.layout)==null?void 0:Nk.header)==null?void 0:Uk.showClearChat,xt=te!==void 0?te:Ct,Et=($k=V.placement)!=null?$k:"inline";if(Nt){Nt.style.display=xt?"":"none";let{closeButtonWrapper:ve}=at;ve&&!ve.classList.contains("tvw-absolute")&&(xt?ve.classList.remove("tvw-ml-auto"):ve.classList.add("tvw-ml-auto"));let Re=Et==="top-right",Ge=Nt.classList.contains("tvw-absolute");if(Re!==Ge&&xt){if(Nt.remove(),Re)Nt.className="tvw-absolute tvw-top-4 tvw-z-50",Nt.style.right="48px",ft.style.position="relative",ft.appendChild(Nt);else{Nt.className="tvw-relative tvw-ml-auto tvw-clear-chat-button-wrapper",Nt.style.right="";let ie=ft.querySelector(".tvw-border-b-cw-divider"),Ze=at.closeButtonWrapper;ie&&Ze&&Ze.parentElement===ie?ie.insertBefore(Nt,Ze):ie&&ie.appendChild(Nt)}let Oe=at.closeButtonWrapper;Oe&&!Oe.classList.contains("tvw-absolute")&&(Re?Oe.classList.add("tvw-ml-auto"):Oe.classList.remove("tvw-ml-auto"))}}if(xt){let ve=(_k=V.size)!=null?_k:"32px";K.style.height=ve,K.style.width=ve;let Re=(jk=V.iconName)!=null?jk:"refresh-cw",Ge=(Gk=V.iconColor)!=null?Gk:"";K.innerHTML="";let Oe=nt(Re,"20px",Ge||"",2);if(Oe&&K.appendChild(Oe),Ge?(K.style.color=Ge,K.classList.remove("tvw-text-cw-muted")):(K.style.color="",K.classList.add("tvw-text-cw-muted")),V.backgroundColor?(K.style.backgroundColor=V.backgroundColor,K.classList.remove("hover:tvw-bg-gray-100")):(K.style.backgroundColor="",K.classList.add("hover:tvw-bg-gray-100")),V.borderWidth||V.borderColor){let St=V.borderWidth||"0px",Le=V.borderColor||"transparent";K.style.border=`${St} solid ${Le}`,K.classList.remove("tvw-border-none")}else K.style.border="",K.classList.add("tvw-border-none");V.borderRadius?(K.style.borderRadius=V.borderRadius,K.classList.remove("tvw-rounded-full")):(K.style.borderRadius="",K.classList.add("tvw-rounded-full")),V.paddingX?(K.style.paddingLeft=V.paddingX,K.style.paddingRight=V.paddingX):(K.style.paddingLeft="",K.style.paddingRight=""),V.paddingY?(K.style.paddingTop=V.paddingY,K.style.paddingBottom=V.paddingY):(K.style.paddingTop="",K.style.paddingBottom="");let ie=(Zk=V.tooltipText)!=null?Zk:"Clear chat",Ze=(Xk=V.showTooltip)!=null?Xk:!0;if(K.setAttribute("aria-label",ie),Nt&&(Nt._cleanupTooltip&&(Nt._cleanupTooltip(),delete Nt._cleanupTooltip),Ze&&ie)){let St=null,Le=()=>{if(St||!K)return;St=w("div","tvw-clear-chat-tooltip"),St.textContent=ie;let Ln=w("div");Ln.className="tvw-clear-chat-tooltip-arrow",St.appendChild(Ln);let Ba=K.getBoundingClientRect();St.style.position="fixed",St.style.left=`${Ba.left+Ba.width/2}px`,St.style.top=`${Ba.top-8}px`,St.style.transform="translate(-50%, -100%)",document.body.appendChild(St)},Ne=()=>{St&&St.parentNode&&(St.parentNode.removeChild(St),St=null)};Nt.addEventListener("mouseenter",Le),Nt.addEventListener("mouseleave",Ne),K.addEventListener("focus",Le),K.addEventListener("blur",Ne),Nt._cleanupTooltip=()=>{Ne(),Nt&&(Nt.removeEventListener("mouseenter",Le),Nt.removeEventListener("mouseleave",Ne)),K&&(K.removeEventListener("focus",Le),K.removeEventListener("blur",Ne))}}}}let ta=t.actionParsers&&t.actionParsers.length?t.actionParsers:[Nn],Ke=t.actionHandlers&&t.actionHandlers.length?t.actionHandlers:[Na.message,Na.messageAndClick];y=Un({parsers:ta,handlers:Ke,getSessionMetadata:m,updateSessionMetadata:c,emit:o.emit,documentRef:typeof document!="undefined"?document:null}),E=DL(t,y,C),$.updateConfig(t),La(se,$.getMessages(),E),ua.render(t.suggestionChips,$,ut,void 0,t.suggestionChipsConfig),wn(),Ga($.isStreaming());let xa=((Jk=t.voiceRecognition)==null?void 0:Jk.enabled)===!0,Yn=typeof window!="undefined"&&(typeof window.webkitSpeechRecognition!="undefined"||typeof window.SpeechRecognition!="undefined");if(xa&&Yn)if(!j||!ae){let V=Ae(t.voiceRecognition,t.sendButton);V&&(j=V.micButton,ae=V.micButtonWrapper,Be.insertBefore(ae,ue),j.addEventListener("click",ke),j.disabled=$.isStreaming())}else{let V=(Kk=t.voiceRecognition)!=null?Kk:{},Ct=(Yk=t.sendButton)!=null?Yk:{},te=(Qk=V.iconName)!=null?Qk:"mic",xt=(tH=Ct.size)!=null?tH:"40px",Et=(eH=V.iconSize)!=null?eH:xt,ve=parseFloat(Et)||24;j.style.width=Et,j.style.height=Et,j.style.minWidth=Et,j.style.minHeight=Et;let Re=(rH=(aH=V.iconColor)!=null?aH:Ct.textColor)!=null?rH:"currentColor";j.innerHTML="";let Ge=nt(te,ve,Re,2);Ge?j.appendChild(Ge):j.textContent="\u{1F3A4}";let Oe=(oH=V.backgroundColor)!=null?oH:Ct.backgroundColor;Oe?(j.style.backgroundColor=Oe,j.classList.remove("tvw-bg-cw-primary")):(j.style.backgroundColor="",j.classList.add("tvw-bg-cw-primary")),Re?(j.style.color=Re,j.classList.remove("tvw-text-white")):!Re&&!Ct.textColor&&(j.style.color="",j.classList.add("tvw-text-white")),V.borderWidth?(j.style.borderWidth=V.borderWidth,j.style.borderStyle="solid"):(j.style.borderWidth="",j.style.borderStyle=""),V.borderColor?j.style.borderColor=V.borderColor:j.style.borderColor="",V.paddingX?(j.style.paddingLeft=V.paddingX,j.style.paddingRight=V.paddingX):(j.style.paddingLeft="",j.style.paddingRight=""),V.paddingY?(j.style.paddingTop=V.paddingY,j.style.paddingBottom=V.paddingY):(j.style.paddingTop="",j.style.paddingBottom="");let ie=ae==null?void 0:ae.querySelector(".tvw-send-button-tooltip"),Ze=(sH=V.tooltipText)!=null?sH:"Start voice recognition";if(((nH=V.showTooltip)!=null?nH:!1)&&Ze)if(ie)ie.textContent=Ze,ie.style.display="";else{let Le=document.createElement("div");Le.className="tvw-send-button-tooltip",Le.textContent=Ze,ae==null||ae.insertBefore(Le,j)}else ie&&(ie.style.display="none");ae.style.display="",j.disabled=$.isStreaming()}else j&&ae&&(ae.style.display="none",je&&Gt());if(((dH=t.attachments)==null?void 0:dH.enabled)===!0)if(!X||!At){let V=(lH=t.attachments)!=null?lH:{},te=(pH=((iH=t.sendButton)!=null?iH:{}).size)!=null?pH:"40px";mt||(mt=w("div","tvw-attachment-previews tvw-flex tvw-flex-wrap tvw-gap-2 tvw-mb-2"),mt.style.display="none",me.insertBefore(mt,ut)),N||(N=document.createElement("input"),N.type="file",N.accept=((hH=V.allowedTypes)!=null?hH:Aa).join(","),N.multiple=((cH=V.maxFiles)!=null?cH:4)>1,N.style.display="none",N.setAttribute("aria-label","Attach files"),me.insertBefore(N,ut)),X=w("div","tvw-send-button-wrapper"),At=w("button","tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer tvw-attachment-button"),At.type="button",At.setAttribute("aria-label",(fH=V.buttonTooltipText)!=null?fH:"Attach file");let xt=(uH=V.buttonIconName)!=null?uH:"paperclip",Et=te,ve=parseFloat(Et)||40,Re=Math.round(ve*.6);At.style.width=Et,At.style.height=Et,At.style.minWidth=Et,At.style.minHeight=Et,At.style.fontSize="18px",At.style.lineHeight="1",At.style.backgroundColor="transparent",At.style.color="var(--cw-primary, #111827)",At.style.border="none",At.style.borderRadius="6px",At.style.transition="background-color 0.15s ease",At.addEventListener("mouseenter",()=>{At.style.backgroundColor="rgba(0, 0, 0, 0.05)"}),At.addEventListener("mouseleave",()=>{At.style.backgroundColor="transparent"});let Ge=nt(xt,Re,"currentColor",1.5);Ge?At.appendChild(Ge):At.textContent="\u{1F4CE}",At.addEventListener("click",Ze=>{Ze.preventDefault(),N==null||N.click()}),X.appendChild(At);let Oe=(mH=V.buttonTooltipText)!=null?mH:"Attach file",ie=w("div","tvw-send-button-tooltip");ie.textContent=Oe,X.appendChild(ie),Fe.append(X),!ht&&N&&mt&&(ht=Oa.fromConfig(V),ht.setPreviewsContainer(mt),N.addEventListener("change",async()=>{ht&&(N!=null&&N.files)&&(await ht.handleFileSelect(N.files),N.value="")}))}else{X.style.display="";let V=(xH=t.attachments)!=null?xH:{};N&&(N.accept=((gH=V.allowedTypes)!=null?gH:Aa).join(","),N.multiple=((MH=V.maxFiles)!=null?MH:4)>1),ht&&ht.updateConfig({allowedTypes:V.allowedTypes,maxFileSize:V.maxFileSize,maxFiles:V.maxFiles})}else X&&(X.style.display="none"),ht&&ht.clearAttachments();let fe=(vH=t.sendButton)!=null?vH:{},Qn=(yH=fe.useIcon)!=null?yH:!1,Sn=(wH=fe.iconText)!=null?wH:"\u2191",Pa=fe.iconName,Ea=(CH=fe.tooltipText)!=null?CH:"Send message",jL=(bH=fe.showTooltip)!=null?bH:!1,An=(SH=fe.size)!=null?SH:"40px",t2=fe.backgroundColor,ea=fe.textColor;if(Qn){if(J.style.width=An,J.style.height=An,J.style.minWidth=An,J.style.minHeight=An,J.style.fontSize="18px",J.style.lineHeight="1",J.innerHTML="",Pa){let V=parseFloat(An)||24,Ct=ea&&typeof ea=="string"&&ea.trim()?ea.trim():"currentColor",te=nt(Pa,V,Ct,2);te?(J.appendChild(te),J.style.color=Ct):(J.textContent=Sn,ea?J.style.color=ea:J.classList.add("tvw-text-white"))}else J.textContent=Sn,ea?J.style.color=ea:J.classList.add("tvw-text-white");J.className="tvw-rounded-button tvw-flex tvw-items-center tvw-justify-center disabled:tvw-opacity-50 tvw-cursor-pointer",t2?(J.style.backgroundColor=t2,J.classList.remove("tvw-bg-cw-primary")):J.classList.add("tvw-bg-cw-primary")}else J.textContent=(kH=(AH=t.copy)==null?void 0:AH.sendButtonLabel)!=null?kH:"Send",J.style.width="",J.style.height="",J.style.minWidth="",J.style.minHeight="",J.style.fontSize="",J.style.lineHeight="",J.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",t2?(J.style.backgroundColor=t2,J.classList.remove("tvw-bg-cw-accent")):J.classList.add("tvw-bg-cw-accent"),ea?J.style.color=ea:J.classList.add("tvw-text-white");fe.borderWidth?(J.style.borderWidth=fe.borderWidth,J.style.borderStyle="solid"):(J.style.borderWidth="",J.style.borderStyle=""),fe.borderColor?J.style.borderColor=fe.borderColor:J.style.borderColor="",fe.paddingX?(J.style.paddingLeft=fe.paddingX,J.style.paddingRight=fe.paddingX):(J.style.paddingLeft="",J.style.paddingRight=""),fe.paddingY?(J.style.paddingTop=fe.paddingY,J.style.paddingBottom=fe.paddingY):(J.style.paddingTop="",J.style.paddingBottom="");let kn=ue==null?void 0:ue.querySelector(".tvw-send-button-tooltip");if(jL&&Ea)if(kn)kn.textContent=Ea,kn.style.display="";else{let V=document.createElement("div");V.className="tvw-send-button-tooltip",V.textContent=Ea,ue==null||ue.insertBefore(V,J)}else kn&&(kn.style.display="none");let Hn=(HH=t.statusIndicator)!=null?HH:{},GL=(LH=Hn.visible)!=null?LH:!0;if(ye.style.display=GL?"":"none",$){let V=$.getStatus(),Ct=te=>{var xt,Et,ve,Re;return te==="idle"?(xt=Hn.idleText)!=null?xt:De.idle:te==="connecting"?(Et=Hn.connectingText)!=null?Et:De.connecting:te==="connected"?(ve=Hn.connectedText)!=null?ve:De.connected:te==="error"?(Re=Hn.errorText)!=null?Re:De.error:De[te]};ye.textContent=Ct(V)}},open(){b&&ne(!0,"api")},close(){b&&ne(!1,"api")},toggle(){b&&ne(!h,"api")},clearChat(){$.clearMessages();try{localStorage.removeItem(un),t.debug&&console.log(`[AgentWidget] Cleared default localStorage key: ${un}`)}catch(v){console.error("[AgentWidget] Failed to clear default localStorage:",v)}if(t.clearChatHistoryStorageKey&&t.clearChatHistoryStorageKey!==un)try{localStorage.removeItem(t.clearChatHistoryStorageKey),t.debug&&console.log(`[AgentWidget] Cleared custom localStorage key: ${t.clearChatHistoryStorageKey}`)}catch(v){console.error("[AgentWidget] Failed to clear custom localStorage:",v)}let l=new CustomEvent("persona:clear-chat",{detail:{timestamp:new Date().toISOString()}});if(window.dispatchEvent(l),n!=null&&n.clear)try{let v=n.clear();v instanceof Promise&&v.catch(P=>{typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",P)})}catch(v){typeof console!="undefined"&&console.error("[AgentWidget] Failed to clear storage adapter:",v)}d={},y.syncFromMetadata(),_==null||_.clear(),et==null||et.update()},setMessage(l){return!ut||$.isStreaming()?!1:(!h&&b&&ne(!0,"system"),ut.value=l,ut.dispatchEvent(new Event("input",{bubbles:!0})),!0)},submitMessage(l){if($.isStreaming())return!1;let v=(l==null?void 0:l.trim())||ut.value.trim();return v?(!h&&b&&ne(!0,"system"),ut.value="",ut.style.height="auto",$.sendMessage(v),!0):!1},startVoiceRecognition(){return je||$.isStreaming()||!kt()?!1:(!h&&b&&ne(!0,"system"),Kt.manuallyDeactivated=!1,na(),Vt("user"),!0)},stopVoiceRecognition(){return je?(Kt.manuallyDeactivated=!0,na(),Gt("user"),!0):!1},injectMessage(l){return!h&&b&&ne(!0,"system"),$.injectMessage(l)},injectAssistantMessage(l){!h&&b&&ne(!0,"system");let v=$.injectAssistantMessage(l);return g&&(g=!1,M&&(clearTimeout(M),M=null),setTimeout(()=>{$&&!$.isStreaming()&&$.continueConversation()},100)),v},injectUserMessage(l){return!h&&b&&ne(!0,"system"),$.injectUserMessage(l)},injectSystemMessage(l){return!h&&b&&ne(!0,"system"),$.injectSystemMessage(l)},injectMessageBatch(l){return!h&&b&&ne(!0,"system"),$.injectMessageBatch(l)},injectTestMessage(l){!h&&b&&ne(!0,"system"),$.injectTestEvent(l)},__pushEventStreamEvent(l){_&&_.push({id:`evt-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,type:l.type,timestamp:Date.now(),payload:JSON.stringify(l.payload)})},showEventStream(){!W||!_||bt()},hideEventStream(){Mt&&Wt()},isEventStreamVisible(){return Mt},getMessages(){return $.getMessages()},getStatus(){return $.getStatus()},getPersistentMetadata(){return{...d}},updatePersistentMetadata(l){c(l)},on(l,v){return o.on(l,v)},off(l,v){o.off(l,v)},isOpen(){return b&&h},isVoiceActive(){return Kt.active},getState(){return{open:b&&h,launcherEnabled:b,voiceActive:Kt.active,streaming:$.isStreaming()}},showCSATFeedback(l){!h&&b&&ne(!0,"system");let v=se.querySelector(".tvw-feedback-container");v&&v.remove();let P=VS({onSubmit:async(D,B)=>{var Z;$.isClientTokenMode()&&await $.submitCSATFeedback(D,B),(Z=l==null?void 0:l.onSubmit)==null||Z.call(l,D,B)},onDismiss:l==null?void 0:l.onDismiss,...l});se.appendChild(P),P.scrollIntoView({behavior:"smooth",block:"end"})},showNPSFeedback(l){!h&&b&&ne(!0,"system");let v=se.querySelector(".tvw-feedback-container");v&&v.remove();let P=FS({onSubmit:async(D,B)=>{var Z;$.isClientTokenMode()&&await $.submitNPSFeedback(D,B),(Z=l==null?void 0:l.onSubmit)==null||Z.call(l,D,B)},onDismiss:l==null?void 0:l.onDismiss,...l});se.appendChild(P),P.scrollIntoView({behavior:"smooth",block:"end"})},async submitCSATFeedback(l,v){return $.submitCSATFeedback(l,v)},async submitNPSFeedback(l,v){return $.submitNPSFeedback(l,v)},destroy(){xe.forEach(l=>l()),Bt.remove(),F==null||F.destroy(),k==null||k.remove(),Qe&&Q.removeEventListener("click",Qe)}};if((((_A=a==null?void 0:a.debugTools)!=null?_A:!1)||!!t.debug)&&typeof window!="undefined"){let l=window.AgentWidgetBrowser,v={controller:Yt,getMessages:Yt.getMessages,getStatus:Yt.getStatus,getMetadata:Yt.getPersistentMetadata,updateMetadata:Yt.updatePersistentMetadata,clearHistory:()=>Yt.clearChat(),setVoiceActive:P=>P?Yt.startVoiceRecognition():Yt.stopVoiceRecognition()};window.AgentWidgetBrowser=v,xe.push(()=>{window.AgentWidgetBrowser===v&&(window.AgentWidgetBrowser=l)})}if(W&&typeof window!="undefined"){let l=r.getAttribute("data-persona-instance")||r.id||"persona-"+Math.random().toString(36).slice(2,8),v=D=>{let B=D.detail;(!(B!=null&&B.instanceId)||B.instanceId===l)&&Yt.showEventStream()},P=D=>{let B=D.detail;(!(B!=null&&B.instanceId)||B.instanceId===l)&&Yt.hideEventStream()};window.addEventListener("persona:showEventStream",v),window.addEventListener("persona:hideEventStream",P),xe.push(()=>{window.removeEventListener("persona:showEventStream",v),window.removeEventListener("persona:hideEventStream",P)})}let Ut=kP(t.persistState);if(Ut&&b){let l=HP(Ut.storage),v=`${Ut.keyPrefix}widget-open`,P=`${Ut.keyPrefix}widget-voice`,D=`${Ut.keyPrefix}widget-voice-mode`;if(l){let B=((jA=Ut.persist)==null?void 0:jA.openState)&&l.getItem(v)==="true",Z=((GA=Ut.persist)==null?void 0:GA.voiceState)&&l.getItem(P)==="true",wt=((ZA=Ut.persist)==null?void 0:ZA.voiceState)&&l.getItem(D)==="true";if(B&&setTimeout(()=>{Yt.open(),setTimeout(()=>{var pt;if(Z||wt)Yt.startVoiceRecognition();else if((pt=Ut.persist)!=null&&pt.focusInput){let Ht=r.querySelector("textarea");Ht&&Ht.focus()}},100)},0),(XA=Ut.persist)!=null&&XA.openState&&(o.on("widget:opened",()=>{l.setItem(v,"true")}),o.on("widget:closed",()=>{l.setItem(v,"false")})),(JA=Ut.persist)!=null&&JA.voiceState&&(o.on("voice:state",pt=>{l.setItem(P,pt.active?"true":"false")}),o.on("user:message",pt=>{l.setItem(D,pt.viaVoice?"true":"false")})),Ut.clearOnChatClear){let pt=()=>{l.removeItem(v),l.removeItem(P),l.removeItem(D)},Ht=()=>pt();window.addEventListener("persona:clear-chat",Ht),xe.push(()=>{window.removeEventListener("persona:clear-chat",Ht)})}}}return Yt};var SA={},LP=r=>{if(typeof window=="undefined"||typeof document=="undefined")throw new Error("Chat widget can only be mounted in a browser environment");if(typeof r=="string"){let e=document.querySelector(r);if(!e)throw new Error(`Chat widget target "${r}" was not found`);return e}return r},TP=()=>{try{if(typeof SA!="undefined"&&SA.url)return new URL("../widget.css",SA.url).href}catch{}return null},WL=r=>{let e=TP(),a=()=>{if(!(r instanceof ShadowRoot)||r.querySelector("link[data-persona]"))return;let t=document.head.querySelector("link[data-persona]");if(!t)return;let s=t.cloneNode(!0);r.insertBefore(s,r.firstChild)};if(r instanceof ShadowRoot)if(e){let t=document.createElement("link");t.rel="stylesheet",t.href=e,t.setAttribute("data-persona","true"),r.insertBefore(t,r.firstChild)}else a();else if(!document.head.querySelector("link[data-persona]")&&e){let s=document.createElement("link");s.rel="stylesheet",s.href=e,s.setAttribute("data-persona","true"),document.head.appendChild(s)}},AA=r=>{var f,m,c,p;let e=LP(r.target),a=document.createElement("div");a.className="persona-host";let t=(c=(m=(f=r.config)==null?void 0:f.launcher)==null?void 0:m.enabled)!=null?c:!0;t||(a.style.height="100%"),e.appendChild(a);let s=r.useShadowDom===!0,o,n;if(s){let u=a.attachShadow({mode:"open"});n=u,o=document.createElement("div"),o.id="persona-root",t||(o.style.height="100%",o.style.display="flex",o.style.flexDirection="column",o.style.flex="1",o.style.minHeight="0"),u.appendChild(o),WL(u)}else n=a,o=document.createElement("div"),o.id="persona-root",t||(o.style.height="100%",o.style.display="flex",o.style.flexDirection="column",o.style.flex="1",o.style.minHeight="0"),a.appendChild(o),WL(a);e.id&&o.setAttribute("data-persona-instance",e.id);let d=IS(o,r.config,{debugTools:r.debugTools});(p=r.onReady)==null||p.call(r);let i={...d,host:a,destroy(){d.destroy(),a.remove(),r.windowKey&&typeof window!="undefined"&&delete window[r.windowKey]}};return r.windowKey&&typeof window!="undefined"&&(window[r.windowKey]=i),i};var OL={name:"@runtypelabs/persona",version:"1.43.5",description:"Themeable, pluggable streaming agent widget for websites, in plain JS with support for voice input and reasoning / tool output.",type:"module",main:"dist/index.cjs",module:"dist/index.js",types:"dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js",require:"./dist/index.cjs"},"./widget.css":{import:"./widget.css",default:"./dist/widget.css"}},files:["dist","widget.css","src"],scripts:{build:"rimraf dist && npm run build:styles && npm run build:client && npm run build:installer","build:styles":`node -e "const fs=require('fs');fs.mkdirSync('dist',{recursive:true});fs.copyFileSync('src/styles/widget.css','dist/widget.css');"`,"build:client":'tsup src/index.ts --format esm,cjs,iife --global-name AgentWidget --minify --sourcemap --splitting false --dts --loader ".css=text"',"build:installer":"tsup src/install.ts --format iife --global-name SiteAgentInstaller --out-dir dist --minify --sourcemap --no-splitting",lint:"eslint . --ext .ts",typecheck:"tsc --noEmit",test:"vitest","test:ui":"vitest --ui","test:run":"vitest run"},dependencies:{idiomorph:"^0.7.4",lucide:"^0.552.0",marked:"^12.0.2","partial-json":"^0.1.7",zod:"^3.22.4"},devDependencies:{"@types/node":"^20.12.7","@typescript-eslint/eslint-plugin":"^7.0.0","@typescript-eslint/parser":"^7.0.0","@vitest/ui":"^4.0.9",eslint:"^8.57.0","eslint-config-prettier":"^9.1.0","fake-indexeddb":"^6.2.5",postcss:"^8.4.38",rimraf:"^5.0.5",tailwindcss:"^3.4.10",tsup:"^8.0.1",typescript:"^5.4.5",vitest:"^4.0.9"},engines:{node:">=18.17.0"},license:"MIT",keywords:["ai","chat","widget","streaming","typescript","persona","agent"],repository:{type:"git",url:"git+https://github.com/runtypelabs/persona.git",directory:"packages/widget"},bugs:{url:"https://github.com/runtypelabs/persona/issues"},homepage:"https://github.com/runtypelabs/persona/tree/main/packages/widget#readme",publishConfig:{access:"public"}};var Ua=OL.version;function fa(r){if(r!==void 0)return typeof r=="string"?r:Array.isArray(r)?`[${r.map(e=>e.toString()).join(", ")}]`:r.toString()}function EP(r){if(r)return{getHeaders:fa(r.getHeaders),onFeedback:fa(r.onFeedback),onCopy:fa(r.onCopy),requestMiddleware:fa(r.requestMiddleware),actionHandlers:fa(r.actionHandlers),actionParsers:fa(r.actionParsers),postprocessMessage:fa(r.postprocessMessage),contextProviders:fa(r.contextProviders),streamParser:fa(r.streamParser)}}var zL=`({ text, message }: any) => {
110
110
  const jsonSource = (message as any).rawContent || text || message.content;
111
111
  if (!jsonSource || typeof jsonSource !== 'string') return null;
112
112
  let cleanJson = jsonSource