"use strict";var SiteAgentInstaller=(()=>{var p=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var W=(a,i,d,e)=>{if(i&&typeof i=="object"||typeof i=="function")for(let r of b(i))!j.call(a,r)&&r!==d&&p(a,r,{get:()=>i[r],enumerable:!(e=y(i,r))||e.enumerable});return a};var T=a=>W(p({},"__esModule",{value:!0}),a);var v={};(function(){"use strict";if(window.__siteAgentInstallerLoaded)return;window.__siteAgentInstallerLoaded=!0;let i=(()=>{let n=document.currentScript;if(!n)return{};let t={},o=n.getAttribute("data-config");if(o)try{let c=JSON.parse(o);c.config?Object.assign(t,c):t.config=c}catch(c){console.error("Failed to parse data-config JSON:",c)}let s=n.getAttribute("data-runtype-token");s&&(t.clientToken=s);let l=n.getAttribute("data-flow-id");l&&(t.flowId=l);let u=n.getAttribute("data-api-url");return u&&(t.apiUrl=u),t})(),e={...window.siteAgentConfig||{},...i},r=e.version||"latest",w=e.cdn||"jsdelivr",m=e.autoInit!==!1,A=()=>{if(e.cssUrl&&e.jsUrl)return{cssUrl:e.cssUrl,jsUrl:e.jsUrl};let t=`/npm/@runtypelabs/persona@${r}/dist`;return w==="unpkg"?{cssUrl:`https://unpkg.com${t}/widget.css`,jsUrl:`https://unpkg.com${t}/index.global.js`}:{cssUrl:`https://cdn.jsdelivr.net${t}/widget.css`,jsUrl:`https://cdn.jsdelivr.net${t}/index.global.js`}},{cssUrl:g,jsUrl:f}=A(),C=()=>!!document.head.querySelector("link[data-persona]")||!!document.head.querySelector('link[href*="widget.css"]'),h=()=>!!window.AgentWidget,k=n=>{let t=!1,o=()=>{t||(t=!0,n())},s=()=>{typeof requestIdleCallback!="undefined"?requestIdleCallback(()=>{requestAnimationFrame(()=>{requestAnimationFrame(o)})},{timeout:3e3}):setTimeout(o,300)};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",s):s()},S=()=>new Promise((n,t)=>{if(C()){n();return}let o=document.createElement("link");o.rel="stylesheet",o.href=g,o.setAttribute("data-persona","true"),o.onload=()=>n(),o.onerror=()=>t(new Error(`Failed to load CSS from ${g}`)),document.head.appendChild(o)}),U=()=>new Promise((n,t)=>{if(h()){n();return}let o=document.createElement("script");o.src=f,o.async=!0,o.onload=()=>n(),o.onerror=()=>t(new Error(`Failed to load JS from ${f}`)),document.head.appendChild(o)}),I=()=>{var s;if(!window.AgentWidget||!window.AgentWidget.initAgentWidget){console.warn("AgentWidget not available. Make sure the script loaded successfully.");return}let n=e.target||"body",t={...e.config};if(e.apiUrl&&!t.apiUrl&&(t.apiUrl=e.apiUrl),e.clientToken&&!t.clientToken&&(t.clientToken=e.clientToken),e.flowId&&!t.flowId&&(t.flowId=e.flowId),!(!(t.apiUrl||t.clientToken)&&Object.keys(t).length===0)){!t.postprocessMessage&&window.AgentWidget.markdownPostprocessor&&(t.postprocessMessage=({text:l})=>window.AgentWidget.markdownPostprocessor(l));try{window.AgentWidget.initAgentWidget({target:n,config:t,useShadowDom:(s=e.useShadowDom)!=null?s:!1})}catch(l){console.error("Failed to initialize AgentWidget:",l)}}};k(async()=>{try{await S(),await U(),m&&(e.config||e.apiUrl||e.clientToken)&&setTimeout(I,0)}catch(n){console.error("Failed to install AgentWidget:",n)}})})();return T(v);})();
//# sourceMappingURL=install.global.js.map