(function(){const c=window.chirpsConfig;if(!c||!c.assistantId){console.error("Chirps: Missing assistantId in chirpsConfig");return}const a=function(){const n=document.currentScript;if(n&&n.src)return new URL(n.src).origin;const t=document.getElementsByTagName("script");for(let s=0;s{if(!r)return"/";let e=r.toLowerCase().trim();if(e.includes("://"))try{e=new URL(e).pathname}catch{e=e.replace(/^https?:\/\/[^\/]+/,"")}return e==="*"||e==="/*"?"/*":(e.startsWith("/")||(e="/"+e),e.length>1&&e.endsWith("/")&&!e.endsWith("/*")&&(e=e.replace(/\/+$/,"")),e||"/")},i=s(n),o=s(t);if(i===o)return!0;if(i.endsWith("/*")){const r=i.slice(0,-2)||"/";return r==="/"?!0:o===r||o.startsWith(r+"/")}return!1}function h(n){const t=n.pageVisibility;if(!t||!t.mode||t.mode==="all")return!0;const s=window.location.pathname,i=(t.paths||[]).filter(r=>r.trim());if(i.length===0)return t.mode==="exclude";const o=i.some(r=>u(r,s));return t.mode==="include"?o:t.mode==="exclude"?!o:!0}const d=`${a}/api/assistants/${c.assistantId}/widget-config`;fetch(d).then(n=>{if(!n.ok)throw new Error(`HTTP error! status: ${n.status}`);return n.json()}).then(n=>{if(!h(n))return;const t=document.createElement("script");t.src=`${a}/widget.js?t=${Date.now()}`,t.async=!0,t.onload=()=>{window.ChirpsWidget&&window.ChirpsWidget.init({assistantId:c.assistantId,config:n,apiBase:a})},document.head.appendChild(t)}).catch(n=>{console.error(`[Chirps] Failed to load from ${d}:`,n)})})();