@botbuddy/react 0.26.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,51 +1,51 @@
1
- import {useState,useRef,useCallback,useEffect,useMemo,useLayoutEffect,useId,useInsertionEffect,Component}from'react';import {createPortal}from'react-dom';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Oe=8;function St(e,t,n,a,s,l){let u=Math.max(Oe,s-n-Oe),p=Math.max(Oe,l-a-Oe);return {x:Math.min(Math.max(e,Oe),u),y:Math.min(Math.max(t,Oe),p)}}function _t(e,t){let[n,a]=useState({x:e,y:t}),s=useRef(false),l=useRef({x:0,y:0}),u=useRef(false),p=useCallback(b=>{s.current=true,u.current=false,l.current={x:b.clientX-n.x,y:b.clientY-n.y},b.target.setPointerCapture(b.pointerId);},[n]),w=useCallback(b=>{s.current&&(u.current=true,a({x:b.clientX-l.current.x,y:b.clientY-l.current.y}));},[]),c=useCallback(()=>{s.current=false;},[]);return {pos:n,setPos:a,onPointerDown:p,onPointerMove:w,onPointerUp:c,didDrag:u}}function Et(e,t,n){let a=useRef(n);a.current=n,useEffect(()=>{if(!t)return;if(e.supabaseUrl){let l=false,u=null,p=()=>{l||u||(u=setInterval(()=>a.current(),15e3));},w=null;try{let m=new URL(e.supabaseUrl),r=["localhost","127.0.0.1","::1"].includes(m.hostname);if(m.protocol==="http:"&&!r)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");m.protocol=m.protocol==="https:"?"wss:":"ws:",w=m.toString().replace(/\/$/,"");}catch{p();}let c=null,b=null,E=null,P=0,f=()=>{if(!(l||!w)){try{c=new WebSocket(`${w}/realtime/v1/websocket?apikey=${e.anonKey}&vsn=1.0.0`);}catch{p();return}c.onopen=()=>{if(l||!c)return;let m={topic:`realtime:public:test_run_cases:test_run_id=eq.${t}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_run_cases",filter:`test_run_id=eq.${t}`}]}},ref:String(++P)};c.send(JSON.stringify(m));let r={topic:`realtime:public:test_runs:id=eq.${t}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_runs",filter:`id=eq.${t}`}]}},ref:String(++P)};c.send(JSON.stringify(r)),b=setInterval(()=>{c?.readyState===WebSocket.OPEN&&c.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++P)}));},3e4);},c.onmessage=m=>{try{JSON.parse(m.data).event==="postgres_changes"&&a.current();}catch{}},c.onclose=()=>{h(),l||(E=setTimeout(f,3e3));},c.onerror=()=>{c?.close();};}},h=()=>{b&&(clearInterval(b),b=null);};return f(),()=>{l=true,h(),E&&clearTimeout(E),u&&clearInterval(u),c&&(c.onclose=null,c.onerror=null,c.close());}}let s=setInterval(()=>a.current(),15e3);return ()=>clearInterval(s)},[e.supabaseUrl,e.anonKey,t]);}var cr="botbuddy:created-test-run:";function dr(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function ur(e){return `${cr}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",dr(e.targetUrl),e.branchName||""].join("|"))}`}function it(e,t){let n={apikey:e.anonKey};return t?n.Authorization=`Bearer ${t}`:e.apiKey?n.Authorization=`Bearer ${e.apiKey}`:n.Authorization=`Bearer ${e.anonKey}`,n}async function pr(e){if(e)return e;try{let t=await fetch("/.botbuddy-token",{cache:"no-store"});if(t.ok){let n=(await t.text()).trim();if(n.startsWith("public_"))return n}}catch{}try{let t=import.meta?.env?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(t&&typeof t=="string"&&t.startsWith("public_"))return t}catch{}return null}function Ct(e){let[t,n]=useState(null),[a,s]=useState("loading"),l=ur(e),[u,p]=useState(()=>{if(e.testRunId)return e.testRunId;try{return localStorage.getItem(l)||void 0}catch{return}}),w=e.testRunId||u,c=useCallback(h=>{if(n(h),!!h?.id){p(h.id);try{localStorage.setItem(l,h.id);}catch{}}},[l]),b=useCallback(async()=>{try{let h=await pr(e.testRunToken);if(!h&&!w){s("no-match"),n(null);return}if(h&&!e.ticketId){s("no-match"),n(null);return}let m=new URLSearchParams;h&&m.set("token",h),e.ticketId&&m.set("ticket_id",e.ticketId),m.set("app_slug",e.appSlug),e.environment&&m.set("environment",e.environment),w&&m.set("test_run_id",w),e.targetUrl&&m.set("target_url",e.targetUrl),e.version&&m.set("version",e.version),e.commitSha&&m.set("commit_sha",e.commitSha),e.prNumber&&m.set("pr_number",String(e.prNumber)),e.branchName&&m.set("branch_name",e.branchName);let r=await fetch(`${e.config.serverUrl}/widget/test-run?${m.toString()}`,{headers:it(e.config,e.authToken)});if(r.status===404){s("no-match"),n(null);return}if(r.status===401||r.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),s("error");return}if(!r.ok){s("error");return}let d=await r.json();if(!d||d.run===null){s("no-match"),n(null);return}c(d),s(d.status==="completed"?"completed":"ready");}catch{s("error");}},[e.config.serverUrl,e.config.anonKey,e.config.apiKey,e.authToken,e.appSlug,e.environment,e.ticketId,w,e.testRunToken,e.targetUrl,e.version,e.commitSha,e.branchName,e.prNumber,e.onAuthExpired,c]);return useEffect(()=>{b();},[b]),Et(e.config,t?.id,b),{run:t,widgetState:a,fetchRun:b,setVerdict:async(h,m,r,d="human")=>(n(T=>{if(!T)return null;let B=T.test_cases.map(_=>_.id===h?{..._,verdict:m,fail_reason:m==="fail"&&r||null,verdict_by_display_name:d,verdict_at:new Date().toISOString()}:_),W={total:B.length,pending:0,pass:0,fail:0,skip:0};return B.forEach(_=>{_.verdict in W&&W[_.verdict]++;}),{...T,test_cases:B,summary:W}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${h}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...it(e.config,e.authToken)},body:JSON.stringify({verdict:m,fail_reason:r,display_name:d})})).ok),markComplete:async()=>t?(n(m=>m?{...m,status:"completed"}:null),s("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${t.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...it(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!t)return false;let h=await fetch(`${e.config.serverUrl}/widget/test-runs/${t.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...it(e.config,e.authToken)}});return h.ok&&b(),h.ok},setRun:c}}var Pt="botbuddy-widget-auth-token",At="botbuddy-widget-auth-name";function Ge(e){if(!e)return null;try{let t=e.split(".")[1];if(!t)return null;let n=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(t.length/4)*4,"="),a=atob(n),s=JSON.parse(a);return typeof s.exp=="number"?s.exp*1e3:null}catch{return null}}var gr=2500,fr=6e4;function Lt(e){let[t,n]=useState(()=>{try{return localStorage.getItem(Pt)}catch(f){return console.warn("Unable to read BotBuddy widget auth token",f),null}}),[a,s]=useState(()=>{try{return localStorage.getItem(At)}catch(f){return console.warn("Unable to read BotBuddy widget display name",f),null}}),l=useRef(null),u=useCallback((f,h)=>{n(f),h&&s(h);try{localStorage.setItem(Pt,f),h&&localStorage.setItem(At,h);}catch(m){console.warn("Unable to persist BotBuddy widget auth token",m);}},[]);useEffect(()=>{let f=new URL(e).origin,h=m=>{m.origin===f&&m.data?.type==="botbuddy-widget-auth"&&m.data.token&&u(m.data.token,m.data.displayName||"human");};return window.addEventListener("message",h),()=>window.removeEventListener("message",h)},[e,u]);let p=useCallback(()=>{if(l.current)return l.current;if(typeof window>"u"||typeof document>"u")return Promise.resolve(null);let f=new URL(e).origin,h=new URL("/widget-auth",e);h.searchParams.set("silent","1"),h.searchParams.set("origin",window.location.origin);let m=new Promise(r=>{let d=document.createElement("iframe");d.setAttribute("aria-hidden","true"),d.style.position="fixed",d.style.width="1px",d.style.height="1px",d.style.opacity="0",d.style.pointerEvents="none",d.style.border="0",d.style.left="-9999px",d.style.top="-9999px",d.src=h.toString();let k=false,T=()=>{window.removeEventListener("message",B),clearTimeout(W);try{d.remove();}catch{}l.current=null;},B=_=>{if(_.origin===f){if(_.data?.type==="botbuddy-widget-auth-failed"){if(k)return;k=true,r(null),T();return}_.data?.type!=="botbuddy-widget-auth"||!_.data.token||k||(k=true,r(String(_.data.token)),T());}},W=setTimeout(()=>{k||(k=true,r(null),T());},gr);window.addEventListener("message",B),document.body.appendChild(d);});return l.current=m,m},[e]);useEffect(()=>{if(!t)return;let f=Ge(t);if(!f)return;let h=f-Date.now()-fr,m=window.setTimeout(()=>{p();},Math.max(0,h));return ()=>window.clearTimeout(m)},[t,p]);let w=useCallback(()=>{let f=new URL("/widget-auth",e);f.searchParams.set("origin",window.location.origin);let h=420,m=520,r=window.screenX+(window.innerWidth-h)/2,d=window.screenY+(window.innerHeight-m)/2;window.open(f.toString(),"botbuddy-auth",`width=${h},height=${m},left=${r},top=${d},popup=yes`);},[e]),[,c]=useState(0);useEffect(()=>{let f=Ge(t);if(!f)return;let h=f-Date.now();if(h<=0)return;let m=window.setTimeout(()=>c(r=>r+1),h);return ()=>window.clearTimeout(m)},[t]);let b=useCallback(()=>{n(null),s(null);try{localStorage.removeItem(Pt),localStorage.removeItem(At);}catch(f){console.warn("Unable to clear BotBuddy widget auth token",f);}},[]),E=Ge(t),P=E!==null&&E<=Date.now();return {token:t,displayName:a,isAuthenticated:!!t,isExpired:P,openLogin:w,refreshNow:p,logout:b}}var ct=null;function mr(){try{if(typeof document<"u"){let e=document.querySelector("base[href]");if(e)return new URL(".botbuddy-totp.json",e.href).toString()}}catch{}return "/.botbuddy-totp.json"}function dt(){return ct||(ct=(async()=>{if(typeof fetch>"u")return null;try{let e=await fetch(mr(),{cache:"no-store"});if(!e.ok)return null;let t=await e.json();if(!t||typeof t!="object"||Array.isArray(t))return null;let n={};for(let[a,s]of Object.entries(t))typeof s=="string"&&s.length>0&&(n[a]=s);return n}catch{return null}})(),ct)}async function wn(e){return (await dt())?.[e]??null}function yr(e){let t=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),n="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",a=[],s=0,l=0;for(let u of t){let p=n.indexOf(u);if(p<0)throw new Error("Invalid Base32 character in TOTP secret");l=l<<5|p,s+=5,s>=8&&(s-=8,a.push(l>>>s&255));}return Uint8Array.from(a)}async function kn(e,t=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let n=yr(e),a=new Uint8Array(n.byteLength);a.set(n);let s=Math.floor(t/1e3/30),l=new Uint8Array(8),u=Math.floor(s/4294967296),p=s>>>0;l[0]=u>>>24&255,l[1]=u>>>16&255,l[2]=u>>>8&255,l[3]=u&255,l[4]=p>>>24&255,l[5]=p>>>16&255,l[6]=p>>>8&255,l[7]=p&255;let w=await crypto.subtle.importKey("raw",a,{name:"HMAC",hash:"SHA-1"},false,["sign"]),c=await crypto.subtle.sign("HMAC",w,l),b=new Uint8Array(c),E=b[b.length-1]&15;return (((b[E]&127)<<24|(b[E+1]&255)<<16|(b[E+2]&255)<<8|b[E+3]&255)%1e6).toString().padStart(6,"0")}var Rn="0.11.0";function xr(e){let t=new Date(e),a=Date.now()-t.getTime();if(a<6e4)return "just now";if(a<36e5)return `${Math.floor(a/6e4)}m ago`;if(a<864e5)return `${Math.floor(a/36e5)}h ago`;let s=t.getDate(),l=t.toLocaleString("en",{month:"short"}),u=t.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${l} ${s}, ${u}`}var A=({d:e,className:t,size:n=14})=>jsx("svg",{className:t,width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:e})}),N={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01",bot:"M12 8V4H8M2 14h2M20 14h2M15 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M9 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M18 10a6 6 0 0 0-12 0v4a6 6 0 0 0 12 0Z",terminal:"M4 17l6-6-6-6M12 19h8",key:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4",shield:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10",copy:"M20 9h-9a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2-2v-9a2 2 0 0 0-2-2ZM5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1",search:"M11 17.25a6.25 6.25 0 1 1 0-12.5 6.25 6.25 0 0 1 0 12.5ZM16 16l4.5 4.5"};function vr(){let[e,t]=useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return useEffect(()=>{if(typeof window>"u")return;let n=document.documentElement,a=()=>n.classList.contains("dark")?"dark":n.classList.contains("light")?"light":null,s=a();s&&t(s);let l=window.matchMedia("(prefers-color-scheme: dark)"),u=w=>{let c=a();t(c||(w.matches?"dark":"light"));};l.addEventListener("change",u);let p=new MutationObserver(()=>{let w=a();t(w||(l.matches?"dark":"light"));});return p.observe(n,{attributes:true,attributeFilter:["class"]}),()=>{l.removeEventListener("change",u),p.disconnect();}},[]),e}function wr(e){let t=e==="dark";return {bg:t?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:t?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:t?"#e5e5e5":"#1a1a1a",textMuted:t?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:t?"#555":"#999",border:t?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:t?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:t?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:t?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:t?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:t?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:t?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:t?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:t?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:t?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:t?"#888":"#aaa",btnHover:t?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var kr={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},Rr={pending:N.circle,pass:N.check,fail:N.x,skip:N.skip},Nn={local:{bg:"rgba(59,130,246,0.15)",text:"#60a5fa",border:"rgba(59,130,246,0.3)"},preview:{bg:"rgba(168,85,247,0.15)",text:"#c084fc",border:"rgba(168,85,247,0.3)"},staging:{bg:"rgba(245,158,11,0.15)",text:"#fbbf24",border:"rgba(245,158,11,0.3)"},production:{bg:"rgba(239,68,68,0.15)",text:"#f87171",border:"rgba(239,68,68,0.3)"},custom:{bg:"rgba(128,128,128,0.15)",text:"#888",border:"rgba(128,128,128,0.3)"}},Nr=["app.supply-guard.io"];function Sr(e,t=[]){if(!e)return false;let n=e.toLowerCase();return [...Nr,...t].map(s=>s.toLowerCase()).includes(n)}var _r=e=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:t=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:e.bg,border:t?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:t?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(t,n)=>({width:`${t}px`,borderRadius:"8px",background:e.bg,border:n?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:n?`0 8px 24px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 8px 24px ${e.shadow}`,overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:`1px solid ${e.borderSubtle}`},title:{fontSize:"10px",fontWeight:600,color:e.text,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:e.textMuted,display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:e.gripColor,display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:`1px solid ${e.borderSubtle}`},badge:t=>{let n=Nn[t]||Nn.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:n.bg,color:n.text,border:`1px solid ${n.border}`,lineHeight:"14px"}},progress:{height:"2px",background:e.borderSubtle,flexShrink:0},progressBar:t=>({height:"100%",width:`${t}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:t=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${t}15`,color:t,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(t,n)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:t?`${n}33`:"transparent",color:t?n:e.gripColor,transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:e.inputBg,border:`1px solid ${e.inputBorder}`,borderRadius:"4px",padding:"2px 6px",color:e.text,outline:"none"},humanBanner:{padding:"6px 12px",fontSize:"11px",fontWeight:600,color:e.green,borderBottom:`1px solid ${e.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",background:e.greenBg,cursor:"pointer",textDecoration:"none"}});function Bt(e){return e.split("/")[0].trim()}async function Er(e){try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}try{if(typeof document>"u")return !1;let t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.opacity="0",t.style.pointerEvents="none",document.body.appendChild(t),t.focus(),t.select(),t.setSelectionRange(0,e.length);let n=document.execCommand("copy");return document.body.removeChild(t),n}catch{return false}}function Je({config:e,appSlug:t,environment:n,seededUsers:a,authToken:s,tk:l,compact:u=false,onExpand:p,onAuthExpired:w,refreshAuth:c,requestLogin:b,testRunId:E,testRunToken:P,ticketId:f,targetUrl:h,version:m,commitSha:r,prNumber:d,branchName:k}){let[T,B]=useState(false),[W,_]=useState(null),[H,xe]=useState(null),[ue,v]=useState(null),[$e,M]=useState(null),[C,V]=useState(null),[Q,ee]=useState(null);useEffect(()=>{n==="local"&&dt();},[n]);let me=useCallback(y=>{_(y),v(null),M(null),ee(null);let D=Ge(s);if(n!=="local"&&b&&D!==null&&D<=Date.now()){V({slug:y,token:s||null}),ee(y),_(null),b();return}let F=I=>{v(I),M(y),window.setTimeout(()=>{M(U=>U===y?null:U),v(U=>U===I?null:U);},3e3);},z=new URLSearchParams({app_slug:t,seed_user_slug:y,environment:n});E&&z.set("test_run_id",E),P&&z.set("public_token",P),f&&z.set("ticket_id",f),h&&z.set("target_url",h),m&&z.set("version",m),r&&z.set("commit_sha",r),d&&z.set("pr_number",String(d)),k&&z.set("branch_name",k);let K=async I=>{let U={apikey:e.anonKey,Authorization:`Bearer ${I}`};try{let q=await fetch(`${e.serverUrl}/widget/totp-code?${z}`,{headers:U});if(!q.ok){let Me=await q.json().catch(()=>({error:`HTTP ${q.status}`}));return {ok:!1,status:q.status,error:Me.error||`HTTP ${q.status}`}}let le=await q.json();return {ok:!0,code:String(le.code)}}catch{return {ok:false,status:0,error:"Network error"}}},te=(async()=>{if(n==="local"){let q=await wn(y);if(q)try{return {ok:!0,code:await kn(q)}}catch{}}let I=await K(s||e.anonKey);if(I.ok||I.status!==401||!c)return I;let U=await c();return U?K(U):{ok:false,status:401,error:"Sign in to BotBuddy to refresh 2FA"}})(),G=null;try{if(typeof ClipboardItem<"u"&&navigator.clipboard?.write){let I=te.then(U=>{if(!U.ok)throw new Error(U.error);return new Blob([U.code],{type:"text/plain"})});G=navigator.clipboard.write([new ClipboardItem({"text/plain":I})]).then(()=>!0).catch(()=>!1);}}catch{}(async()=>{let I=await te;if(!I.ok){I.status===401?(V({slug:y,token:s||null}),ee(y)):F(I.status===404?"No 2FA seed registered":I.error),_(null);return}let U=G?await G:false,q=U?true:await Er(I.code),le=U||q;xe({slug:y,code:I.code,copied:le}),window.setTimeout(()=>xe(Me=>Me?.slug===y?null:Me),le?2500:6e3),B(false),_(null);})();},[e.serverUrl,e.anonKey,s,t,n,E,P,f,h,m,r,d,k,c,b]),ie=useCallback(y=>{V({slug:y,token:s||null}),b?.();},[s,b]),Be=useCallback(y=>{Q===y?ie(y):me(y);},[Q,ie,me]);useEffect(()=>{if(!C||!s||s===C.token)return;let y=C.slug;V(null),me(y);},[s,me,C]);let ze=useRef(null),Ke=useRef(null);if(useLayoutEffect(()=>{if(!T)return;let y=ze.current,D=Ke.current;if(!y||!D||typeof window>"u")return;let F=()=>{let z=y.getBoundingClientRect(),K=D.getBoundingClientRect(),te=window.innerWidth,G=window.innerHeight,I=z.left,U=z.top-K.height-6;U<8&&(U=z.bottom+6);let q=Math.max(8,te-K.width-8),le=Math.max(8,G-K.height-8);I=Math.min(Math.max(I,8),q),U=Math.min(Math.max(U,8),le),D.style.left=`${Math.round(I)}px`,D.style.top=`${Math.round(U)}px`;};return F(),window.addEventListener("scroll",F,true),window.addEventListener("resize",F),()=>{window.removeEventListener("scroll",F,true),window.removeEventListener("resize",F);}},[T,a.length,ue]),useEffect(()=>{if(!T)return;let y=D=>{let F=D.target;Ke.current?.contains(F)||ze.current?.contains(F)||B(false);};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[T]),a.length===0)return null;if(u){let y=a.length>1,D=a[0],F=!y&&Q===D,z=q=>{if(q.stopPropagation(),y&&p){p();return}Be(D);},K=!!$e,te=!!H,G=te&&H.copied,I=te&&!H.copied,U=F?l.blue:K?l.red:G?l.green:I?l.amber:l.purple;return jsxs("span",{onPointerDown:q=>q.stopPropagation(),onPointerUp:q=>q.stopPropagation(),onPointerMove:q=>q.stopPropagation(),onClick:z,style:{display:"inline-flex",alignItems:"center",gap:"3px",color:U,fontWeight:600,cursor:"pointer",letterSpacing:I?"0.08em":void 0},title:F?"Sign in to BotBuddy to refresh 2FA":K?ue||"Failed":I?`Clipboard blocked \u2014 code: ${H.code}`:y?`${a.length} 2FA personas`:`Copy 2FA code for ${a[0]}`,children:[jsx(A,{d:F?N.key:K?N.alert:G?N.check:I?N.copy:N.shield,size:10}),F?jsx(Fragment,{children:"Sign in"}):G?jsx(Fragment,{children:"Copied"}):I?jsx(Fragment,{children:H.code}):K?jsx(Fragment,{children:"Failed"}):jsxs(Fragment,{children:["2FA",y&&` \xB7${a.length}`]})]})}if(a.length===1){let y=a[0],D=W===y,F=H?.slug===y,z=F&&H.copied,K=F&&!H.copied,te=$e===y,G=Q===y,I=G?l.blue:te?l.red:z?l.green:K?l.amber:l.purple;return jsxs("button",{onClick:U=>{U.stopPropagation(),Be(y);},disabled:D,style:{...Sn(I),cursor:D?"wait":"pointer",opacity:D?.6:1},title:G?"Sign in to BotBuddy to refresh 2FA":te?ue||"Failed":K?`Clipboard blocked \u2014 code: ${H.code}`:`Copy 2FA code for ${y}`,children:[jsx(A,{d:G?N.key:te?N.alert:z?N.check:K?N.copy:N.shield,size:12}),G?"Sign in":z?"Copied":K?H.code:te?"Failed":D?"\u2026":`2FA \xB7 ${y}`]})}let Re=!!Q&&!T,pe=!!$e&&!T,Ie=!!H&&H.copied,Fe=!!H&&!H.copied,ht=Re?l.blue:pe?l.red:Ie?l.green:Fe?l.amber:l.purple,xt=T&&typeof document<"u"?createPortal(jsxs("div",{ref:Ke,onPointerDown:y=>y.stopPropagation(),onMouseDown:y=>y.stopPropagation(),style:{position:"fixed",left:-9999,top:-9999,background:l.bg,border:`1px solid ${l.border}`,borderRadius:6,boxShadow:`0 8px 24px ${l.shadow}`,padding:4,minWidth:220,maxWidth:typeof window<"u"?Math.min(420,window.innerWidth-16):420,zIndex:1e5,fontFamily:"ui-monospace, SFMono-Regular, monospace"},children:[a.map(y=>{let D=W===y,F=Q===y;return jsxs("button",{onClick:z=>{z.stopPropagation(),Be(y);},disabled:D,style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 8px",background:"transparent",border:"none",borderRadius:4,cursor:D?"wait":"pointer",fontSize:"10px",color:F?l.blue:l.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},title:F?"Sign in to BotBuddy to refresh 2FA":void 0,onMouseEnter:z=>z.currentTarget.style.background=l.btnHover,onMouseLeave:z=>z.currentTarget.style.background="transparent",children:[jsx(A,{d:F?N.key:N.shield,size:10}),jsx("span",{style:{flex:1,overflowWrap:"anywhere",lineHeight:1.3},children:y}),F?jsx("span",{style:{color:l.blue,fontSize:9},children:"Sign in"}):D?jsx("span",{style:{color:l.textMuted,fontSize:9},children:"\u2026"}):null]},y)}),ue&&jsx("div",{style:{padding:"4px 8px",fontSize:9,color:l.red},children:ue})]}),document.body):null;return jsxs(Fragment,{children:[jsxs("button",{ref:ze,onClick:y=>{if(y.stopPropagation(),Re&&Q){ie(Q);return}B(D=>!D),v(null),M(null);},style:{...Sn(ht),cursor:"pointer"},title:Re?"Sign in to BotBuddy to refresh 2FA":pe?ue||"Failed":Fe?`Clipboard blocked \u2014 code: ${H.code}`:"Choose a persona to copy a 2FA code for",children:[jsx(A,{d:Re?N.key:pe?N.alert:Ie?N.check:Fe?N.copy:N.shield,size:12}),Re?"Sign in":Ie?"Copied":Fe?H.code:pe?"Failed":`2FA \xB7 ${a.length}`,!Re&&jsx(A,{d:T?N.chevronUp:N.chevronDown,size:8})]}),xt]})}function Sn(e){return {display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${e}15`,color:e,textDecoration:"none",border:`1px solid ${e}30`}}var _n="botbuddy-widget-state";function Tr({config:e,appSlug:t,environment:n,ticketId:a,testRunId:s,testRunToken:l,targetUrl:u,version:p,commitSha:w,prNumber:c,branchName:b,onNavigate:E,displayName:P="human",defaultMode:f="mini",defaultPosition:h}){let m=vr(),r=useMemo(()=>wr(m),[m]),d=useMemo(()=>_r(r),[r]),[k,T]=useState(false),[B,W]=useState(false),[_,H]=useState(false),xe=useRef(false),ue=e.dashboardUrl||"https://app.bot-buddy.ai",v=Lt(ue),M=(()=>{try{let o=typeof window<"u"?localStorage.getItem(_n):null;if(o)return JSON.parse(o)}catch{}return null})(),[C,V]=useState(M?.mode||f),[Q,ee]=useState(""),[me,ie]=useState(null),[Be,ze]=useState(null),[Ke,Re]=useState(new Set),[pe,Ie]=useState(""),Fe=useCallback(o=>{Re(x=>{let $=new Set(x);return $.has(o)?$.delete(o):$.add(o),$});},[]),ht=M?.x??h?.x??16,xt=M?.y??h?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:y,setPos:D,onPointerDown:F,onPointerMove:z,onPointerUp:K,didDrag:te}=_t(ht,xt),G=useRef(null);useEffect(()=>{try{localStorage.setItem(_n,JSON.stringify({mode:C,x:y.x,y:y.y}));}catch{}},[C,y.x,y.y]),useLayoutEffect(()=>{if(typeof window>"u")return;let o=G.current;if(!o)return;let x=o.getBoundingClientRect(),$=St(y.x,y.y,x.width,x.height,window.innerWidth,window.innerHeight);($.x!==y.x||$.y!==y.y)&&D($);}),useEffect(()=>{if(typeof window>"u")return;let o=()=>{let x=G.current;if(!x)return;let $=x.getBoundingClientRect(),Y=St(y.x,y.y,$.width,$.height,window.innerWidth,window.innerHeight);(Y.x!==y.x||Y.y!==y.y)&&D(Y);};return window.addEventListener("resize",o),()=>window.removeEventListener("resize",o)},[y.x,y.y,D]);let I=useRef(v.isAuthenticated);useEffect(()=>{!I.current&&v.isAuthenticated&&V("max"),I.current=v.isAuthenticated;},[v.isAuthenticated]);let U="botbuddy-widget-max-size",q=()=>{try{let o=localStorage.getItem(U);if(o)return JSON.parse(o)}catch{}return {w:340,h:500}},[le,Me]=useState(q),je=useRef(false),qe=useRef({x:0,y:0,w:0,h:0}),Jn=useCallback(o=>{o.stopPropagation(),je.current=true,qe.current={x:o.clientX,y:o.clientY,w:le.w,h:le.h},o.target.setPointerCapture(o.pointerId);},[le]),Yn=useCallback(o=>{if(!je.current)return;let x=Math.max(280,Math.min(600,qe.current.w+(o.clientX-qe.current.x))),$=Math.max(300,Math.min(window.innerHeight*.9,qe.current.h+(o.clientY-qe.current.y)));Me({w:x,h:$});},[]),Xn=useCallback(()=>{je.current&&(je.current=false,Me(o=>(localStorage.setItem(U,JSON.stringify(o)),o)));},[]),be=u??(typeof window<"u"?window.location.href:void 0),Zt=v.displayName||P,[ve,Qt]=useState(null);useEffect(()=>{if(v.isAuthenticated)return;let o=new URLSearchParams;l&&o.set("token",l),a&&o.set("ticket_id",a),o.set("app_slug",t),n&&o.set("environment",n),s&&o.set("test_run_id",s),be&&o.set("target_url",be),p&&o.set("version",p),w&&o.set("commit_sha",w),c&&o.set("pr_number",String(c)),b&&o.set("branch_name",b),fetch(`${e.serverUrl}/widget/preview?${o}`,{headers:{apikey:e.anonKey}}).then(x=>x.json()).then(x=>Qt(x)).catch(()=>Qt(null));},[v.isAuthenticated,e.serverUrl,e.anonKey,t,n,a,s,l,be,p,w,c,b]);let en=useRef(false),Zn=useCallback(()=>{en.current||v.logout();},[v.logout]),{run:R,widgetState:Pe,fetchRun:Qn,setVerdict:tn,markComplete:er,resetRun:tr,setRun:nn}=Ct({config:e,appSlug:t,environment:n,ticketId:a,testRunId:s,testRunToken:l,targetUrl:be,version:p,commitSha:w,prNumber:c?String(c):void 0,branchName:b,authToken:v.token,onAuthExpired:Zn});en.current=!!R;let[rn,on]=useState([]),[sn,rt]=useState([]),[vt,an]=useState(false),[ln,cn]=useState(null),[nr,ot]=useState(false),Ne=Sr(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);useEffect(()=>{if((n??"local")!=="local"||Ne){on([]);return}let o=true;return dt().then(x=>{o&&on(Object.keys(x||{}));}),()=>{o=false;}},[n,Ne]);let rr=useCallback(async()=>{if(!(!v.isAuthenticated||!v.token)){an(true),cn(null);try{let o=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${v.token}`},body:JSON.stringify({app_slug:t,environment:n||"local",target_url:be,branch_name:b,commit_sha:w,pr_number:c,ticket_id:a,title:`${a||t} local validation`})}),x=await o.json().catch(()=>({}));if(!o.ok)throw new Error(x.error||`HTTP ${o.status}`);nn(x),V("max");}catch(o){cn(o.message);}finally{an(false);}}},[v.isAuthenticated,v.token,e.serverUrl,e.anonKey,t,n,be,b,w,c,a,nn]),st=useCallback(async(o,x,$)=>{ze(o);try{await tn(o,x,$,Zt);}finally{ze(null),ie(null),ee("");}},[tn,Zt]),X=R?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},or=X.total>0&&X.pending===0,Ue=Pe==="completed",at=useMemo(()=>{let o=R?.test_cases||[];if(!pe.trim())return o;let x=pe.toLowerCase();return o.filter($=>$.title.toLowerCase().includes(x)||$.description&&$.description.toLowerCase().includes(x)||$.url_path&&$.url_path.toLowerCase().includes(x)||$.seed_user&&$.seed_user.toLowerCase().includes(x))},[R?.test_cases,pe]),dn=useMemo(()=>{let o=at,x=R?.test_cases||[];if(new Set(x.map(oe=>oe.source_pr_number)).size<=1)return null;let Y=[],_e=new Map;o.forEach(oe=>{let re=oe.source_pr_number;_e.has(re)||_e.set(re,[]),_e.get(re).push(oe);});let hn=[..._e.keys()].sort((oe,re)=>oe===null?1:re===null?-1:re-oe);for(let oe of hn){let re=_e.get(oe),kt={total:re.length,pass:0,fail:0,skip:0,pending:0};re.forEach(xn=>{xn.verdict in kt&&kt[xn.verdict]++;}),Y.push({key:oe!=null?`pr-${oe}`:"general",label:oe!=null?`PR #${oe}`:"General",cases:re,summary:kt});}return Y.filter(oe=>oe.cases.length>0)},[at,R?.test_cases]),un=X.total>0?(X.pass+X.fail)/X.total*100:0,ne=n??R?.environment??null,Se=useMemo(()=>{if(!ne||ne==="production"||Ne)return [];let o=R?.test_cases||[],x=new Set;for(let $ of o)$.seed_user&&x.add(Bt($.seed_user));if(ne==="local")for(let $ of rn)x.add(Bt($));for(let $ of sn)x.add(Bt($));return [...x]},[R?.test_cases,ne,rn,sn,Ne]);useEffect(()=>{if(!ne||ne==="production"||Ne||!v.isAuthenticated||!v.token){rt([]);return}let o=true,x=`${e.serverUrl}/widget/totp-seeds?${new URLSearchParams({app_slug:t,environment:ne})}`,$=Y=>fetch(x,{headers:{apikey:e.anonKey,Authorization:`Bearer ${Y}`}});return (async()=>{try{let Y=await $(v.token);if(Y.status===401&&v.refreshNow){let re=await v.refreshNow();re&&(Y=await $(re));}if(!o)return;if(!Y.ok){rt([]);return}let _e=await Y.json().catch(()=>null),oe=(Array.isArray(_e?.seeds)?_e.seeds:[]).map(re=>re?.seed_user_slug).filter(re=>typeof re=="string"&&re.length>0);rt(oe);}catch{o&&rt([]);}})(),()=>{o=false;}},[ne,Ne,v.isAuthenticated,v.token,v.refreshNow,t,e.serverUrl,e.anonKey]);let wt=useMemo(()=>{let o=R?.auto_tooltip_seconds??ve?.auto_tooltip_seconds;return o!=null&&o>0?o*1e3:0},[R,ve]),pn=Pe==="ready"||Pe==="completed"||ve?.enabled&&ve.run;useEffect(()=>{if(!pn||xe.current||wt<=0)return;xe.current=true,W(true);let o=window.setTimeout(()=>W(false),wt);return ()=>window.clearTimeout(o)},[pn,wt]);let bn=o=>jsxs("div",{style:d.caseRow,children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsx("div",{style:{marginTop:"2px",flexShrink:0,color:kr[o.verdict]},children:Be===o.id?jsx(A,{d:N.loader,className:""}):jsx(A,{d:Rr[o.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:r.text,lineHeight:1.3},children:o.title}),o.description&&jsx("div",{style:{fontSize:"9px",color:r.gripColor,marginTop:"2px"},children:o.description}),o.seed_user&&jsxs("div",{style:{fontSize:"9px",color:r.amber,marginTop:"3px",display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",background:`${r.amber}12`,border:`1px solid ${r.amber}30`},children:[jsx(A,{d:N.key,size:10}),jsx("span",{children:o.seed_user})]}),o.url_path&&jsxs("a",{href:o.url_path,target:"_blank",rel:"noopener noreferrer",onClick:x=>{x.stopPropagation(),E&&(x.preventDefault(),E(o.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsx(A,{d:N.externalLink,size:10}),o.url_path]}),o.verdict==="fail"&&o.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:r.red,marginTop:"2px"},children:["\u2717 ",o.fail_reason]})]})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(x=>jsx("button",{onClick:()=>{if(o.verdict===x){st(o.id,"pending"),ie(null);return}if(x==="fail"){ie(o.id),ee("");return}ie(null),st(o.id,x);},disabled:Be!==null,style:d.verdictBtn(o.verdict===x,x==="pass"?r.green:x==="fail"?r.red:r.amber),children:x.toUpperCase()},x)),o.created_by_agent_name&&jsxs("span",{style:{fontSize:"8px",color:r.purple,marginLeft:"4px",display:"inline-flex",alignItems:"center",gap:"2px"},children:[jsx(A,{d:N.bot,size:8}),o.created_by_agent_name]}),o.verdict_by_display_name&&jsxs("span",{style:{fontSize:"8px",color:r.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[o.verdict_by_display_name,o.verdict_at&&jsx("span",{style:{opacity:.7},children:xr(o.verdict_at)})]})]}),me===o.id&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:Q,onChange:x=>ee(x.target.value),onKeyDown:x=>{x.key==="Enter"&&st(o.id,"fail",Q.trim()||void 0),x.key==="Escape"&&(ie(null),ee(""));},placeholder:"Reason (optional)...",style:d.input}),jsx("button",{onClick:()=>{st(o.id,"fail",Q.trim()||void 0);},style:d.verdictBtn(true,r.red),children:"\u2713"})]})]},o.id);if((Pe==="no-match"||Pe==="loading")&&!(!v.isAuthenticated&&ve?.enabled&&ve.run)){if(!(ne==="local"&&!Ne))return null}if(!v.isAuthenticated&&ve?.enabled&&ve.run){let o=ve.run,x=o.summary,$=o.status==="completed";return jsx("div",{ref:G,style:{...d.root,left:y.x,top:y.y},children:jsxs("div",{style:{position:"relative"},onMouseEnter:()=>T(true),onMouseLeave:()=>{T(false),H(false),W(false);},children:[jsxs("div",{style:{...d.pill($),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:F,onPointerMove:z,onPointerUp:()=>{K();},children:[jsx(A,{d:N.grip,size:10,className:""}),o.ticket_id&&o.ticket_url?jsx("a",{href:o.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:Y=>Y.stopPropagation(),style:{color:r.amber,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:o.ticket_id}):null,o.pr_url?jsxs("a",{href:o.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:Y=>Y.stopPropagation(),style:{color:r.blue,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:["PR#",o.pr_number??o.pr_id]}):null,o.created_by_agent_name?o.codex_thread_id?jsxs("a",{href:`codex://threads/${o.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",onClick:Y=>Y.stopPropagation(),style:{color:r.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(A,{d:N.terminal,size:10}),o.created_by_agent_name]}):jsxs("span",{style:{color:r.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(A,{d:N.bot,size:10}),o.created_by_agent_name]}):null,jsxs("span",{style:$?{color:r.green}:void 0,children:[x.pass,"/",x.total]}),x.fail>0&&jsxs("span",{style:{color:r.red},children:[x.fail,"\u2717"]}),jsx("span",{onClick:Y=>{Y.stopPropagation(),v.openLogin();},style:{color:r.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!_&&(k||B)&&o.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsx("div",{style:{fontSize:"11px",fontWeight:700,color:r.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:o.title}),(o.description||o.intro_notes)&&jsx("div",{style:{fontSize:"10px",color:r.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:o.description||o.intro_notes}),jsx("div",{style:{marginTop:"4px",fontSize:"9px",color:r.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!v.isAuthenticated)return jsxs("div",{ref:G,style:{...d.root,left:y.x,top:y.y,width:220,minHeight:0,cursor:"move",userSelect:"none",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`},onPointerDown:F,onPointerMove:z,onPointerUp:K,children:[jsx("div",{style:{...d.handle,borderBottom:"none"},children:jsxs("div",{style:d.sub,children:[jsx(A,{d:N.grip,size:10,className:""}),jsx(A,{d:N.clipboard,size:12,className:""}),jsx("span",{style:{fontWeight:600},children:"BotBuddy"})]})}),jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[jsx("div",{style:{fontSize:"9px",color:r.textMuted,marginBottom:"8px"},children:"Sign in to access test cases"}),ne==="local"&&Se.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx(Je,{config:e,appSlug:t,environment:ne,seededUsers:Se,authToken:v.token,refreshAuth:v.refreshNow,requestLogin:v.openLogin,tk:r,testRunId:R?.id||s,testRunToken:l,ticketId:a,targetUrl:be,version:p,commitSha:w,prNumber:c,branchName:b,onAuthExpired:v.logout})}),jsx("button",{onClick:o=>{o.stopPropagation(),v.openLogin();},style:{fontSize:"10px",fontWeight:600,padding:"6px 16px",borderRadius:"6px",border:`1px solid ${r.green}`,background:`${r.green}22`,color:r.green,cursor:"pointer",width:"100%"},children:"Sign in to test"})]})]});if(!R&&ne==="local"&&!Ne)return nr?jsx("div",{ref:G,style:{...d.root,left:y.x,top:y.y},children:jsxs("div",{style:d.card(240,false),children:[jsxs("div",{style:d.handle,onPointerDown:F,onPointerMove:z,onPointerUp:K,onClick:()=>{te.current||ot(false);},children:[jsx(A,{d:N.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:d.title,children:"BotBuddy"}),b&&jsx("div",{style:d.sub,children:jsxs("span",{children:["\u2387 ",b]})})]}),jsx(A,{d:N.chevronUp,className:""}),jsx("button",{style:d.btn,onClick:o=>{o.stopPropagation(),ot(false);},children:jsx(A,{d:N.minus,className:""})})]}),jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[Se.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx(Je,{config:e,appSlug:t,environment:ne,seededUsers:Se,authToken:v.token,refreshAuth:v.refreshNow,requestLogin:v.openLogin,tk:r,testRunId:s,testRunToken:l,ticketId:a,targetUrl:be,version:p,commitSha:w,prNumber:c,branchName:b,onAuthExpired:v.logout})}),jsx("button",{onClick:o=>{o.stopPropagation(),rr();},disabled:vt,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${r.green}`,background:`${r.green}22`,color:r.green,cursor:vt?"wait":"pointer",width:"100%"},children:vt?"Creating...":"Create test run for this branch"}),ln&&jsx("div",{style:{fontSize:"9px",color:r.red,marginTop:"8px"},children:ln})]})]})}):jsx("div",{ref:G,style:{...d.root,left:y.x,top:y.y},children:jsxs("div",{style:{...d.pill(false),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:F,onPointerMove:z,onPointerUp:()=>{K(),te.current||ot(true);},children:[jsx(A,{d:N.grip,size:9,className:""}),jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),Se.length>0&&jsx(Je,{config:e,appSlug:t,environment:ne,seededUsers:Se,authToken:v.token,refreshAuth:v.refreshNow,requestLogin:v.openLogin,tk:r,compact:true,onExpand:()=>ot(true),testRunId:s,testRunToken:l,ticketId:a,targetUrl:be,version:p,commitSha:w,prNumber:c,branchName:b,onAuthExpired:v.logout})]})});let gn=()=>{te.current||(W(false),V(o=>{let x=o==="mini"?"max":"mini";return H(x==="mini"),x}));},fn=({icon:o,onClick:x})=>jsx("button",{style:d.btn,onClick:$=>{$.stopPropagation(),x($);},children:jsx(A,{d:o,className:""})}),mn=()=>jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${r.borderSubtle}`,flexShrink:0},children:[R?.pr_url&&jsxs("a",{href:R.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(r.blue),textDecoration:"none"},children:[jsx(A,{d:N.pr,size:12}),R.pr_number?`PR#${R.pr_number}`:R.pr_id||"PR",jsx(A,{d:N.externalLink,size:8})]}),R?.ticket_url&&jsxs("a",{href:R.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(r.amber),textDecoration:"none"},children:[jsx(A,{d:N.ticket,size:12}),R.ticket_id||"Ticket",jsx(A,{d:N.externalLink,size:8})]}),R?.created_by_agent_name&&(R.codex_thread_id?jsxs("a",{href:`codex://threads/${R.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...d.link(r.purple),textDecoration:"none"},children:[jsx(A,{d:N.bot,size:12}),R.created_by_agent_name,jsx(A,{d:N.externalLink,size:8})]}):jsxs("span",{style:{...d.link(r.purple)},children:[jsx(A,{d:N.bot,size:12}),R.created_by_agent_name]})),ne&&jsx(Je,{config:e,appSlug:t,environment:ne,seededUsers:Se,authToken:v.token,refreshAuth:v.refreshNow,requestLogin:v.openLogin,tk:r,testRunId:R?.id||s,testRunToken:l,ticketId:a,targetUrl:be,version:p,commitSha:w,prNumber:c,branchName:b,onAuthExpired:v.logout}),jsx("span",{style:{...d.badge(R?.environment||"custom"),marginLeft:"auto"},children:R?.environment})]}),yn=()=>jsxs("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:`1px solid ${r.borderSubtle}`,background:r.bgSoft,flexShrink:0},children:[jsxs("button",{onClick:()=>{navigator.clipboard.writeText(Rn);},style:{fontSize:"9px",fontWeight:600,color:r.versionText,letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxs("span",{style:{color:r.versionNum},children:["v",Rn]})]}),v.isAuthenticated&&(v.isExpired?jsx("button",{onClick:o=>{o.stopPropagation(),v.openLogin();},style:{fontSize:"8px",color:r.blue,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Widget session expired \u2014 sign in to refresh",children:"sign in"}):jsx("button",{onClick:o=>{o.stopPropagation(),v.logout();},style:{fontSize:"8px",color:r.textFaint,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Sign out of widget",children:"sign out"}))]});return jsxs("div",{ref:G,style:{...d.root,left:y.x,top:y.y},children:[C==="mini"&&jsxs("div",{style:{position:"relative"},onMouseEnter:()=>T(true),onMouseLeave:()=>{T(false),H(false),W(false);},children:[jsxs("div",{style:{...d.pill(Ue),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:F,onPointerMove:z,onPointerUp:()=>{K(),te.current||gn();},children:[jsx(A,{d:N.grip,size:9,className:""}),R?.ticket_id&&jsx("span",{style:{color:r.amber,fontWeight:600},children:R.ticket_id}),R?.pr_number&&jsxs("span",{style:{color:r.blue,fontWeight:600},children:["PR#",R.pr_number]}),jsxs("span",{style:Ue?{color:r.green}:void 0,children:[X.pass,"/",X.total]}),X.fail>0&&jsxs("span",{style:{color:r.red},children:[X.fail,"\u2717"]}),ne&&jsx(Je,{config:e,appSlug:t,environment:ne,seededUsers:Se,authToken:v.token,refreshAuth:v.refreshNow,requestLogin:v.openLogin,tk:r,compact:true,onExpand:()=>V("expanded"),testRunId:R?.id||s,testRunToken:l,ticketId:a,targetUrl:be,version:p,commitSha:w,prNumber:c,branchName:b,onAuthExpired:v.logout})]}),!_&&(k||B)&&R?.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsx("div",{style:{fontSize:"11px",fontWeight:700,color:r.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:R.title}),(R.description||R.intro_notes)&&jsx("div",{style:{fontSize:"10px",color:r.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:R.description||R.intro_notes})]})]}),C==="expanded"&&jsxs("div",{style:d.card(300,Ue),children:[jsxs("div",{style:d.handle,onPointerDown:F,onPointerMove:z,onPointerUp:K,onClick:gn,children:[jsx(A,{d:N.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:d.title,children:R?.title}),jsx("div",{style:d.sub,children:R?.branch_name&&jsxs("span",{children:["\u2387 ",R.branch_name]})})]}),jsx(A,{d:N.chevronUp,className:""}),jsx(fn,{icon:N.minus,onClick:()=>{W(false),H(true),V("mini");}})]}),jsxs("div",{style:d.stats,children:[jsxs("span",{style:{color:r.green},children:[X.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[X.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[X.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[X.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:X.total})]}),R?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:r.gripColor,borderBottom:`1px solid ${r.borderSubtle}`,flexShrink:0},children:R.description}),mn(),yn(),jsx("div",{style:d.progress,children:jsx("div",{style:d.progressBar(un)})})]}),C==="max"&&jsxs("div",{style:{...d.card(le.w,Ue),height:le.h,position:"relative"},children:[jsxs("div",{style:d.handle,onPointerDown:F,onPointerMove:z,onPointerUp:K,onClick:()=>{te.current||V("expanded");},children:[jsx(A,{d:N.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:d.title,children:R?.title}),jsx("div",{style:d.sub,children:R?.branch_name&&jsxs("span",{children:["\u2387 ",R.branch_name]})})]}),jsx(A,{d:N.chevronDown,className:""}),jsx(fn,{icon:N.minus,onClick:()=>{W(false),H(true),V("mini");}})]}),jsxs("div",{style:d.stats,children:[jsxs("span",{style:{color:r.green},children:[X.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[X.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[X.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[X.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:X.total})]}),R?.intro_notes&&jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${r.borderSubtle}`,fontSize:"10px",color:r.textMuted,fontStyle:"italic",flexShrink:0},children:R.intro_notes}),(R?.test_cases||[]).length>5&&jsxs("div",{style:{padding:"4px 12px",borderBottom:`1px solid ${r.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[jsx(A,{d:N.search,size:11,className:""}),jsx("input",{value:pe,onChange:o=>Ie(o.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:r.text,fontFamily:"monospace"}}),pe&&jsx("button",{onClick:()=>Ie(""),style:{background:"none",border:"none",cursor:"pointer",color:r.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),Pe==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(A,{d:N.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:r.red},children:"Failed to load"}),jsx("button",{onClick:Qn,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),Ue&&jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg},children:[jsx(A,{d:N.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:r.green,flex:1},children:"Run completed"}),jsx("button",{onClick:tr,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),Pe!=="error"&&jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(R?.test_cases||[]).length===0?jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:"No test cases"}):at.length===0?jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:['No matches for "',pe,'"']}):dn?dn.map(o=>{let x=Ke.has(o.key);return jsxs("div",{children:[jsxs("button",{onClick:()=>Fe(o.key),style:{width:"100%",display:"flex",alignItems:"center",gap:"6px",padding:"5px 12px",background:r.bgSoft,cursor:"pointer",border:"none",borderLeft:"none",borderRight:"none",borderBottomStyle:"solid",borderTopStyle:"solid",borderBottomWidth:"1px",borderTopWidth:"1px",borderBottomColor:r.borderSubtle,borderTopColor:r.borderSubtle,backgroundColor:r.bgSoft},children:[jsx(A,{d:x?N.chevronDown:N.chevronUp,size:10,className:""}),jsx("span",{style:{fontSize:"10px",fontWeight:700,color:r.blue,flex:1,textAlign:"left"},children:o.label}),jsxs("span",{style:{fontSize:"9px",color:r.green},children:[o.summary.pass,"\u2713"]}),jsxs("span",{style:{fontSize:"9px",color:r.red},children:[o.summary.fail,"\u2717"]}),jsxs("span",{style:{fontSize:"9px",color:r.gripColor},children:[o.summary.pending,"\u25CC"]}),jsx("span",{style:{fontSize:"9px",color:r.textFaint},children:o.summary.total})]}),!x&&o.cases.map($=>bn($))]},o.key)}):at.map(o=>bn(o))}),or&&!Ue&&jsxs("div",{style:{padding:"6px 12px",borderTop:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg,display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsx("span",{style:{fontSize:"9px",color:r.green},children:"All resolved"}),jsx("button",{onClick:er,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:r.green,border:`1px solid ${r.greenBorderSubtle}`,cursor:"pointer"},children:"COMPLETE"})]}),mn(),yn(),jsx("div",{style:d.progress,children:jsx("div",{style:d.progressBar(un)})}),jsx("div",{style:{position:"absolute",bottom:0,right:0,width:16,height:16,cursor:"se-resize",zIndex:10,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:"2px",opacity:.3},onPointerDown:Jn,onPointerMove:Yn,onPointerUp:Xn,onPointerEnter:o=>o.currentTarget.style.opacity="0.7",onPointerLeave:o=>{je.current||(o.currentTarget.style.opacity="0.3");},children:jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsx("path",{d:"M7 1v6H1",fill:"none",stroke:r.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}var Pr=1e4,Ye=new Map;var ut=class extends Error{};async function Ar(e,t,n){let a={headers:{authorization:`Bearer ${t}`}};try{return await fetch(e,{...a,signal:n})}catch(s){if(s instanceof TypeError&&/signal/i.test(s.message)&&!n.aborted)return fetch(e,a);throw s}}function Lr(e){let t=e;return !!t&&typeof t=="object"&&typeof t.tenant=="string"&&Array.isArray(t.entries)&&t.entries.every(n=>!!n&&typeof n.id=="string"&&typeof n.title=="string"&&!!n.body&&Array.isArray(n.body.ast)&&Array.isArray(n.links))}function zt({endpoint:e,getToken:t,timeoutMs:n=Pr}){let[a,s]=useState(()=>({feed:null,error:null,loading:true,stale:false})),[l,u]=useState(0),p=useRef(t);p.current=t,useEffect(()=>{let c=new AbortController,b=true,E=false,P=setTimeout(()=>{E=true,c.abort();},n),f=new Promise((r,d)=>{c.signal.addEventListener("abort",()=>d(new Error("timeout")),{once:true});});f.catch(()=>{}),s(r=>({...r,error:null,loading:true}));let h=null,m=(r,d)=>{if(d&&Ye.delete(e),!b)return;let k=d||h===null?void 0:Ye.get(e)?.get(h);s({feed:k??null,error:r,loading:false,stale:!!k});};return (async()=>{try{let r;try{r=await Promise.race([Promise.resolve().then(()=>p.current()),f]);}catch(B){throw E||c.signal.aborted?B:new ut("token_unavailable")}h=r;let d=await Promise.race([Ar(e,r,c.signal),f]),k=d.status===401||d.status===403;k&&Ye.delete(e);let T=null;try{T=await Promise.race([d.json(),f]);}catch(B){if(E&&!k)throw B;T=null;}if(!b)return;if(d.ok)if(!Lr(T))m("invalid_feed",!1);else {let B=Ye.get(e)??new Map;B.set(r,T),Ye.set(e,B),s({feed:T,error:null,loading:!1,stale:!1});}else {let B=T?.error;m(typeof B=="string"?B:`http_${d.status}`,k);}}catch(r){r instanceof ut?m(r.message,true):m(E?"timeout":r instanceof Error&&r.message||"unavailable",false);}finally{clearTimeout(P);}})(),()=>{b=false,clearTimeout(P),c.abort();}},[e,l,n]);let w=useCallback(()=>u(c=>c+1),[]);return {...a,reload:w}}var It=["accent","fg","bg","muted","border","radius","font"],Br={accent:"hsl(var(--primary))",fg:"hsl(var(--foreground))",bg:"hsl(var(--card))",muted:"hsl(var(--muted-foreground))",border:"hsl(var(--border))",radius:"var(--radius)",font:"inherit"},Z=(e,t)=>t===void 0?`var(--bbrn-${e},var(--_bbrn-${e}))`:`var(--bbrn-${e},var(--_bbrn-${e},${t}))`,Te=Z("accent","currentColor"),ce=Z("muted","color-mix(in srgb,currentColor 72%,transparent)"),fe=Z("border","color-mix(in srgb,currentColor 22%,transparent)"),zr=`@layer bbrn{
2
- .bbrn-root{${It.filter(e=>e!=="font").map(e=>`--_bbrn-${e}:${Br[e]};`).join("")}display:grid;gap:12px;color:${Z("fg")};font-family:var(--bbrn-font)}
1
+ import {useState,useRef,useCallback,useEffect,useMemo,useLayoutEffect,useId,useInsertionEffect,Component}from'react';import {createPortal}from'react-dom';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Oe=8;function St(e,t,n,a,s,l){let g=Math.max(Oe,s-n-Oe),p=Math.max(Oe,l-a-Oe);return {x:Math.min(Math.max(e,Oe),g),y:Math.min(Math.max(t,Oe),p)}}function _t(e,t){let[n,a]=useState({x:e,y:t}),s=useRef(false),l=useRef({x:0,y:0}),g=useRef(false),p=useCallback(f=>{s.current=true,g.current=false,l.current={x:f.clientX-n.x,y:f.clientY-n.y},f.target.setPointerCapture(f.pointerId);},[n]),N=useCallback(f=>{s.current&&(g.current=true,a({x:f.clientX-l.current.x,y:f.clientY-l.current.y}));},[]),u=useCallback(()=>{s.current=false;},[]);return {pos:n,setPos:a,onPointerDown:p,onPointerMove:N,onPointerUp:u,didDrag:g}}var lr=15e3;function Et(e,t,n){let a=useRef(n);a.current=n,useEffect(()=>{if(!t)return;let s=setInterval(()=>a.current(),lr);return ()=>clearInterval(s)},[t]);}var cr="botbuddy:created-test-run:";function ur(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function pr(e){return `${cr}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",ur(e.targetUrl),e.branchName||""].join("|"))}`}function it(e,t){let n={apikey:e.anonKey};return t?n.Authorization=`Bearer ${t}`:e.apiKey?n.Authorization=`Bearer ${e.apiKey}`:n.Authorization=`Bearer ${e.anonKey}`,n}async function br(e){if(e)return e;try{let t=await fetch("/.botbuddy-token",{cache:"no-store"});if(t.ok){let n=(await t.text()).trim();if(n.startsWith("public_"))return n}}catch{}try{let t=import.meta?.env?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(t&&typeof t=="string"&&t.startsWith("public_"))return t}catch{}return null}function Tt(e){let[t,n]=useState(null),[a,s]=useState("loading"),l=pr(e),[g,p]=useState(()=>{if(e.testRunId)return e.testRunId;try{return localStorage.getItem(l)||void 0}catch{return}}),N=e.testRunId||g,u=useCallback(x=>{if(n(x),!!x?.id){p(x.id);try{localStorage.setItem(l,x.id);}catch{}}},[l]),f=useCallback(async()=>{try{let x=await br(e.testRunToken);if(!x&&!N){s("no-match"),n(null);return}if(x&&!e.ticketId){s("no-match"),n(null);return}let y=new URLSearchParams;x&&y.set("token",x),e.ticketId&&y.set("ticket_id",e.ticketId),y.set("app_slug",e.appSlug),e.environment&&y.set("environment",e.environment),N&&y.set("test_run_id",N),e.targetUrl&&y.set("target_url",e.targetUrl),e.version&&y.set("version",e.version),e.commitSha&&y.set("commit_sha",e.commitSha),e.prNumber&&y.set("pr_number",String(e.prNumber)),e.branchName&&y.set("branch_name",e.branchName);let r=await fetch(`${e.config.serverUrl}/widget/test-run?${y.toString()}`,{headers:it(e.config,e.authToken)});if(r.status===404){s("no-match"),n(null);return}if(r.status===401||r.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),s("error");return}if(!r.ok){s("error");return}let d=await r.json();if(!d||d.run===null){s("no-match"),n(null);return}u(d),s(d.status==="completed"?"completed":"ready");}catch{s("error");}},[e.config.serverUrl,e.config.anonKey,e.config.apiKey,e.authToken,e.appSlug,e.environment,e.ticketId,N,e.testRunToken,e.targetUrl,e.version,e.commitSha,e.branchName,e.prNumber,e.onAuthExpired,u]);return useEffect(()=>{f();},[f]),Et(e.config,t?.id,f),{run:t,widgetState:a,fetchRun:f,setVerdict:async(x,y,r,d="human")=>(n(C=>{if(!C)return null;let B=C.test_cases.map(_=>_.id===x?{..._,verdict:y,fail_reason:y==="fail"&&r||null,verdict_by_display_name:d,verdict_at:new Date().toISOString()}:_),H={total:B.length,pending:0,pass:0,fail:0,skip:0};return B.forEach(_=>{_.verdict in H&&H[_.verdict]++;}),{...C,test_cases:B,summary:H}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${x}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...it(e.config,e.authToken)},body:JSON.stringify({verdict:y,fail_reason:r,display_name:d})})).ok),markComplete:async()=>t?(n(y=>y?{...y,status:"completed"}:null),s("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${t.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...it(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!t)return false;let x=await fetch(`${e.config.serverUrl}/widget/test-runs/${t.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...it(e.config,e.authToken)}});return x.ok&&f(),x.ok},setRun:u}}var Pt="botbuddy-widget-auth-token",At="botbuddy-widget-auth-name";function Ge(e){if(!e)return null;try{let t=e.split(".")[1];if(!t)return null;let n=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(t.length/4)*4,"="),a=atob(n),s=JSON.parse(a);return typeof s.exp=="number"?s.exp*1e3:null}catch{return null}}var fr=2500,mr=6e4;function Lt(e){let[t,n]=useState(()=>{try{return localStorage.getItem(Pt)}catch(m){return console.warn("Unable to read BotBuddy widget auth token",m),null}}),[a,s]=useState(()=>{try{return localStorage.getItem(At)}catch(m){return console.warn("Unable to read BotBuddy widget display name",m),null}}),l=useRef(null),g=useCallback((m,x)=>{n(m),x&&s(x);try{localStorage.setItem(Pt,m),x&&localStorage.setItem(At,x);}catch(y){console.warn("Unable to persist BotBuddy widget auth token",y);}},[]);useEffect(()=>{let m=new URL(e).origin,x=y=>{y.origin===m&&y.data?.type==="botbuddy-widget-auth"&&y.data.token&&g(y.data.token,y.data.displayName||"human");};return window.addEventListener("message",x),()=>window.removeEventListener("message",x)},[e,g]);let p=useCallback(()=>{if(l.current)return l.current;if(typeof window>"u"||typeof document>"u")return Promise.resolve(null);let m=new URL(e).origin,x=new URL("/widget-auth",e);x.searchParams.set("silent","1"),x.searchParams.set("origin",window.location.origin);let y=new Promise(r=>{let d=document.createElement("iframe");d.setAttribute("aria-hidden","true"),d.style.position="fixed",d.style.width="1px",d.style.height="1px",d.style.opacity="0",d.style.pointerEvents="none",d.style.border="0",d.style.left="-9999px",d.style.top="-9999px",d.src=x.toString();let w=false,C=()=>{window.removeEventListener("message",B),clearTimeout(H);try{d.remove();}catch{}l.current=null;},B=_=>{if(_.origin===m){if(_.data?.type==="botbuddy-widget-auth-failed"){if(w)return;w=true,r(null),C();return}_.data?.type!=="botbuddy-widget-auth"||!_.data.token||w||(w=true,r(String(_.data.token)),C());}},H=setTimeout(()=>{w||(w=true,r(null),C());},fr);window.addEventListener("message",B),document.body.appendChild(d);});return l.current=y,y},[e]);useEffect(()=>{if(!t)return;let m=Ge(t);if(!m)return;let x=m-Date.now()-mr,y=window.setTimeout(()=>{p();},Math.max(0,x));return ()=>window.clearTimeout(y)},[t,p]);let N=useCallback(()=>{let m=new URL("/widget-auth",e);m.searchParams.set("origin",window.location.origin);let x=420,y=520,r=window.screenX+(window.innerWidth-x)/2,d=window.screenY+(window.innerHeight-y)/2;window.open(m.toString(),"botbuddy-auth",`width=${x},height=${y},left=${r},top=${d},popup=yes`);},[e]),[,u]=useState(0);useEffect(()=>{let m=Ge(t);if(!m)return;let x=m-Date.now();if(x<=0)return;let y=window.setTimeout(()=>u(r=>r+1),x);return ()=>window.clearTimeout(y)},[t]);let f=useCallback(()=>{n(null),s(null);try{localStorage.removeItem(Pt),localStorage.removeItem(At);}catch(m){console.warn("Unable to clear BotBuddy widget auth token",m);}},[]),E=Ge(t),L=E!==null&&E<=Date.now();return {token:t,displayName:a,isAuthenticated:!!t,isExpired:L,openLogin:N,refreshNow:p,logout:f}}var dt=null;function yr(){try{if(typeof document<"u"){let e=document.querySelector("base[href]");if(e)return new URL(".botbuddy-totp.json",e.href).toString()}}catch{}return "/.botbuddy-totp.json"}function ct(){return dt||(dt=(async()=>{if(typeof fetch>"u")return null;try{let e=await fetch(yr(),{cache:"no-store"});if(!e.ok)return null;let t=await e.json();if(!t||typeof t!="object"||Array.isArray(t))return null;let n={};for(let[a,s]of Object.entries(t))typeof s=="string"&&s.length>0&&(n[a]=s);return n}catch{return null}})(),dt)}async function wn(e){return (await ct())?.[e]??null}function hr(e){let t=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),n="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",a=[],s=0,l=0;for(let g of t){let p=n.indexOf(g);if(p<0)throw new Error("Invalid Base32 character in TOTP secret");l=l<<5|p,s+=5,s>=8&&(s-=8,a.push(l>>>s&255));}return Uint8Array.from(a)}async function kn(e,t=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let n=hr(e),a=new Uint8Array(n.byteLength);a.set(n);let s=Math.floor(t/1e3/30),l=new Uint8Array(8),g=Math.floor(s/4294967296),p=s>>>0;l[0]=g>>>24&255,l[1]=g>>>16&255,l[2]=g>>>8&255,l[3]=g&255,l[4]=p>>>24&255,l[5]=p>>>16&255,l[6]=p>>>8&255,l[7]=p&255;let N=await crypto.subtle.importKey("raw",a,{name:"HMAC",hash:"SHA-1"},false,["sign"]),u=await crypto.subtle.sign("HMAC",N,l),f=new Uint8Array(u),E=f[f.length-1]&15;return (((f[E]&127)<<24|(f[E+1]&255)<<16|(f[E+2]&255)<<8|f[E+3]&255)%1e6).toString().padStart(6,"0")}var Rn="0.11.0";function vr(e){let t=new Date(e),a=Date.now()-t.getTime();if(a<6e4)return "just now";if(a<36e5)return `${Math.floor(a/6e4)}m ago`;if(a<864e5)return `${Math.floor(a/36e5)}h ago`;let s=t.getDate(),l=t.toLocaleString("en",{month:"short"}),g=t.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${l} ${s}, ${g}`}var P=({d:e,className:t,size:n=14})=>jsx("svg",{className:t,width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:e})}),R={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01",bot:"M12 8V4H8M2 14h2M20 14h2M15 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M9 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M18 10a6 6 0 0 0-12 0v4a6 6 0 0 0 12 0Z",terminal:"M4 17l6-6-6-6M12 19h8",key:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4",shield:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10",copy:"M20 9h-9a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2-2v-9a2 2 0 0 0-2-2ZM5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1",search:"M11 17.25a6.25 6.25 0 1 1 0-12.5 6.25 6.25 0 0 1 0 12.5ZM16 16l4.5 4.5"};function wr(){let[e,t]=useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return useEffect(()=>{if(typeof window>"u")return;let n=document.documentElement,a=()=>n.classList.contains("dark")?"dark":n.classList.contains("light")?"light":null,s=a();s&&t(s);let l=window.matchMedia("(prefers-color-scheme: dark)"),g=N=>{let u=a();t(u||(N.matches?"dark":"light"));};l.addEventListener("change",g);let p=new MutationObserver(()=>{let N=a();t(N||(l.matches?"dark":"light"));});return p.observe(n,{attributes:true,attributeFilter:["class"]}),()=>{l.removeEventListener("change",g),p.disconnect();}},[]),e}function kr(e){let t=e==="dark";return {bg:t?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:t?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:t?"#e5e5e5":"#1a1a1a",textMuted:t?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:t?"#555":"#999",border:t?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:t?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:t?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:t?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:t?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:t?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:t?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:t?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:t?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:t?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:t?"#888":"#aaa",btnHover:t?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var Rr={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},Nr={pending:R.circle,pass:R.check,fail:R.x,skip:R.skip},Nn={local:{bg:"rgba(59,130,246,0.15)",text:"#60a5fa",border:"rgba(59,130,246,0.3)"},preview:{bg:"rgba(168,85,247,0.15)",text:"#c084fc",border:"rgba(168,85,247,0.3)"},staging:{bg:"rgba(245,158,11,0.15)",text:"#fbbf24",border:"rgba(245,158,11,0.3)"},production:{bg:"rgba(239,68,68,0.15)",text:"#f87171",border:"rgba(239,68,68,0.3)"},custom:{bg:"rgba(128,128,128,0.15)",text:"#888",border:"rgba(128,128,128,0.3)"}},Sr=["app.supply-guard.io"];function _r(e,t=[]){if(!e)return false;let n=e.toLowerCase();return [...Sr,...t].map(s=>s.toLowerCase()).includes(n)}var Er=e=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:t=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:e.bg,border:t?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:t?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(t,n)=>({width:`${t}px`,borderRadius:"8px",background:e.bg,border:n?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:n?`0 8px 24px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 8px 24px ${e.shadow}`,overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:`1px solid ${e.borderSubtle}`},title:{fontSize:"10px",fontWeight:600,color:e.text,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:e.textMuted,display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:e.gripColor,display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:`1px solid ${e.borderSubtle}`},badge:t=>{let n=Nn[t]||Nn.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:n.bg,color:n.text,border:`1px solid ${n.border}`,lineHeight:"14px"}},progress:{height:"2px",background:e.borderSubtle,flexShrink:0},progressBar:t=>({height:"100%",width:`${t}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:t=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${t}15`,color:t,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(t,n)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:t?`${n}33`:"transparent",color:t?n:e.gripColor,transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:e.inputBg,border:`1px solid ${e.inputBorder}`,borderRadius:"4px",padding:"2px 6px",color:e.text,outline:"none"},humanBanner:{padding:"6px 12px",fontSize:"11px",fontWeight:600,color:e.green,borderBottom:`1px solid ${e.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",background:e.greenBg,cursor:"pointer",textDecoration:"none"}});function Bt(e){return e.split("/")[0].trim()}async function Cr(e){try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}try{if(typeof document>"u")return !1;let t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.opacity="0",t.style.pointerEvents="none",document.body.appendChild(t),t.focus(),t.select(),t.setSelectionRange(0,e.length);let n=document.execCommand("copy");return document.body.removeChild(t),n}catch{return false}}function Ye({config:e,appSlug:t,environment:n,seededUsers:a,authToken:s,tk:l,compact:g=false,onExpand:p,onAuthExpired:N,refreshAuth:u,requestLogin:f,testRunId:E,testRunToken:L,ticketId:m,targetUrl:x,version:y,commitSha:r,prNumber:d,branchName:w}){let[C,B]=useState(false),[H,_]=useState(null),[W,xe]=useState(null),[ue,v]=useState(null),[$e,M]=useState(null),[T,V]=useState(null),[Q,ee]=useState(null);useEffect(()=>{n==="local"&&ct();},[n]);let me=useCallback(b=>{_(b),v(null),M(null),ee(null);let D=Ge(s);if(n!=="local"&&f&&D!==null&&D<=Date.now()){V({slug:b,token:s||null}),ee(b),_(null),f();return}let I=F=>{v(F),M(b),window.setTimeout(()=>{M(U=>U===b?null:U),v(U=>U===F?null:U);},3e3);},z=new URLSearchParams({app_slug:t,seed_user_slug:b,environment:n});E&&z.set("test_run_id",E),L&&z.set("public_token",L),m&&z.set("ticket_id",m),x&&z.set("target_url",x),y&&z.set("version",y),r&&z.set("commit_sha",r),d&&z.set("pr_number",String(d)),w&&z.set("branch_name",w);let K=async F=>{let U={apikey:e.anonKey,Authorization:`Bearer ${F}`};try{let q=await fetch(`${e.serverUrl}/widget/totp-code?${z}`,{headers:U});if(!q.ok){let Me=await q.json().catch(()=>({error:`HTTP ${q.status}`}));return {ok:!1,status:q.status,error:Me.error||`HTTP ${q.status}`}}let le=await q.json();return {ok:!0,code:String(le.code)}}catch{return {ok:false,status:0,error:"Network error"}}},te=(async()=>{if(n==="local"){let q=await wn(b);if(q)try{return {ok:!0,code:await kn(q)}}catch{}}let F=await K(s||e.anonKey);if(F.ok||F.status!==401||!u)return F;let U=await u();return U?K(U):{ok:false,status:401,error:"Sign in to BotBuddy to refresh 2FA"}})(),G=null;try{if(typeof ClipboardItem<"u"&&navigator.clipboard?.write){let F=te.then(U=>{if(!U.ok)throw new Error(U.error);return new Blob([U.code],{type:"text/plain"})});G=navigator.clipboard.write([new ClipboardItem({"text/plain":F})]).then(()=>!0).catch(()=>!1);}}catch{}(async()=>{let F=await te;if(!F.ok){F.status===401?(V({slug:b,token:s||null}),ee(b)):I(F.status===404?"No 2FA seed registered":F.error),_(null);return}let U=G?await G:false,q=U?true:await Cr(F.code),le=U||q;xe({slug:b,code:F.code,copied:le}),window.setTimeout(()=>xe(Me=>Me?.slug===b?null:Me),le?2500:6e3),B(false),_(null);})();},[e.serverUrl,e.anonKey,s,t,n,E,L,m,x,y,r,d,w,u,f]),ie=useCallback(b=>{V({slug:b,token:s||null}),f?.();},[s,f]),Be=useCallback(b=>{Q===b?ie(b):me(b);},[Q,ie,me]);useEffect(()=>{if(!T||!s||s===T.token)return;let b=T.slug;V(null),me(b);},[s,me,T]);let ze=useRef(null),Ke=useRef(null);if(useLayoutEffect(()=>{if(!C)return;let b=ze.current,D=Ke.current;if(!b||!D||typeof window>"u")return;let I=()=>{let z=b.getBoundingClientRect(),K=D.getBoundingClientRect(),te=window.innerWidth,G=window.innerHeight,F=z.left,U=z.top-K.height-6;U<8&&(U=z.bottom+6);let q=Math.max(8,te-K.width-8),le=Math.max(8,G-K.height-8);F=Math.min(Math.max(F,8),q),U=Math.min(Math.max(U,8),le),D.style.left=`${Math.round(F)}px`,D.style.top=`${Math.round(U)}px`;};return I(),window.addEventListener("scroll",I,true),window.addEventListener("resize",I),()=>{window.removeEventListener("scroll",I,true),window.removeEventListener("resize",I);}},[C,a.length,ue]),useEffect(()=>{if(!C)return;let b=D=>{let I=D.target;Ke.current?.contains(I)||ze.current?.contains(I)||B(false);};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[C]),a.length===0)return null;if(g){let b=a.length>1,D=a[0],I=!b&&Q===D,z=q=>{if(q.stopPropagation(),b&&p){p();return}Be(D);},K=!!$e,te=!!W,G=te&&W.copied,F=te&&!W.copied,U=I?l.blue:K?l.red:G?l.green:F?l.amber:l.purple;return jsxs("span",{onPointerDown:q=>q.stopPropagation(),onPointerUp:q=>q.stopPropagation(),onPointerMove:q=>q.stopPropagation(),onClick:z,style:{display:"inline-flex",alignItems:"center",gap:"3px",color:U,fontWeight:600,cursor:"pointer",letterSpacing:F?"0.08em":void 0},title:I?"Sign in to BotBuddy to refresh 2FA":K?ue||"Failed":F?`Clipboard blocked \u2014 code: ${W.code}`:b?`${a.length} 2FA personas`:`Copy 2FA code for ${a[0]}`,children:[jsx(P,{d:I?R.key:K?R.alert:G?R.check:F?R.copy:R.shield,size:10}),I?jsx(Fragment,{children:"Sign in"}):G?jsx(Fragment,{children:"Copied"}):F?jsx(Fragment,{children:W.code}):K?jsx(Fragment,{children:"Failed"}):jsxs(Fragment,{children:["2FA",b&&` \xB7${a.length}`]})]})}if(a.length===1){let b=a[0],D=H===b,I=W?.slug===b,z=I&&W.copied,K=I&&!W.copied,te=$e===b,G=Q===b,F=G?l.blue:te?l.red:z?l.green:K?l.amber:l.purple;return jsxs("button",{onClick:U=>{U.stopPropagation(),Be(b);},disabled:D,style:{...Sn(F),cursor:D?"wait":"pointer",opacity:D?.6:1},title:G?"Sign in to BotBuddy to refresh 2FA":te?ue||"Failed":K?`Clipboard blocked \u2014 code: ${W.code}`:`Copy 2FA code for ${b}`,children:[jsx(P,{d:G?R.key:te?R.alert:z?R.check:K?R.copy:R.shield,size:12}),G?"Sign in":z?"Copied":K?W.code:te?"Failed":D?"\u2026":`2FA \xB7 ${b}`]})}let Re=!!Q&&!C,pe=!!$e&&!C,Fe=!!W&&W.copied,Ie=!!W&&!W.copied,ht=Re?l.blue:pe?l.red:Fe?l.green:Ie?l.amber:l.purple,xt=C&&typeof document<"u"?createPortal(jsxs("div",{ref:Ke,onPointerDown:b=>b.stopPropagation(),onMouseDown:b=>b.stopPropagation(),style:{position:"fixed",left:-9999,top:-9999,background:l.bg,border:`1px solid ${l.border}`,borderRadius:6,boxShadow:`0 8px 24px ${l.shadow}`,padding:4,minWidth:220,maxWidth:typeof window<"u"?Math.min(420,window.innerWidth-16):420,zIndex:1e5,fontFamily:"ui-monospace, SFMono-Regular, monospace"},children:[a.map(b=>{let D=H===b,I=Q===b;return jsxs("button",{onClick:z=>{z.stopPropagation(),Be(b);},disabled:D,style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 8px",background:"transparent",border:"none",borderRadius:4,cursor:D?"wait":"pointer",fontSize:"10px",color:I?l.blue:l.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},title:I?"Sign in to BotBuddy to refresh 2FA":void 0,onMouseEnter:z=>z.currentTarget.style.background=l.btnHover,onMouseLeave:z=>z.currentTarget.style.background="transparent",children:[jsx(P,{d:I?R.key:R.shield,size:10}),jsx("span",{style:{flex:1,overflowWrap:"anywhere",lineHeight:1.3},children:b}),I?jsx("span",{style:{color:l.blue,fontSize:9},children:"Sign in"}):D?jsx("span",{style:{color:l.textMuted,fontSize:9},children:"\u2026"}):null]},b)}),ue&&jsx("div",{style:{padding:"4px 8px",fontSize:9,color:l.red},children:ue})]}),document.body):null;return jsxs(Fragment,{children:[jsxs("button",{ref:ze,onClick:b=>{if(b.stopPropagation(),Re&&Q){ie(Q);return}B(D=>!D),v(null),M(null);},style:{...Sn(ht),cursor:"pointer"},title:Re?"Sign in to BotBuddy to refresh 2FA":pe?ue||"Failed":Ie?`Clipboard blocked \u2014 code: ${W.code}`:"Choose a persona to copy a 2FA code for",children:[jsx(P,{d:Re?R.key:pe?R.alert:Fe?R.check:Ie?R.copy:R.shield,size:12}),Re?"Sign in":Fe?"Copied":Ie?W.code:pe?"Failed":`2FA \xB7 ${a.length}`,!Re&&jsx(P,{d:C?R.chevronUp:R.chevronDown,size:8})]}),xt]})}function Sn(e){return {display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${e}15`,color:e,textDecoration:"none",border:`1px solid ${e}30`}}var _n="botbuddy-widget-state";function Tr({config:e,appSlug:t,environment:n,ticketId:a,testRunId:s,testRunToken:l,targetUrl:g,version:p,commitSha:N,prNumber:u,branchName:f,onNavigate:E,displayName:L="human",defaultMode:m="mini",defaultPosition:x}){let y=wr(),r=useMemo(()=>kr(y),[y]),d=useMemo(()=>Er(r),[r]),[w,C]=useState(false),[B,H]=useState(false),[_,W]=useState(false),xe=useRef(false),ue=e.dashboardUrl||"https://app.bot-buddy.ai",v=Lt(ue),M=(()=>{try{let o=typeof window<"u"?localStorage.getItem(_n):null;if(o)return JSON.parse(o)}catch{}return null})(),[T,V]=useState(M?.mode||m),[Q,ee]=useState(""),[me,ie]=useState(null),[Be,ze]=useState(null),[Ke,Re]=useState(new Set),[pe,Fe]=useState(""),Ie=useCallback(o=>{Re(h=>{let $=new Set(h);return $.has(o)?$.delete(o):$.add(o),$});},[]),ht=M?.x??x?.x??16,xt=M?.y??x?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:b,setPos:D,onPointerDown:I,onPointerMove:z,onPointerUp:K,didDrag:te}=_t(ht,xt),G=useRef(null);useEffect(()=>{try{localStorage.setItem(_n,JSON.stringify({mode:T,x:b.x,y:b.y}));}catch{}},[T,b.x,b.y]),useLayoutEffect(()=>{if(typeof window>"u")return;let o=G.current;if(!o)return;let h=o.getBoundingClientRect(),$=St(b.x,b.y,h.width,h.height,window.innerWidth,window.innerHeight);($.x!==b.x||$.y!==b.y)&&D($);}),useEffect(()=>{if(typeof window>"u")return;let o=()=>{let h=G.current;if(!h)return;let $=h.getBoundingClientRect(),J=St(b.x,b.y,$.width,$.height,window.innerWidth,window.innerHeight);(J.x!==b.x||J.y!==b.y)&&D(J);};return window.addEventListener("resize",o),()=>window.removeEventListener("resize",o)},[b.x,b.y,D]);let F=useRef(v.isAuthenticated);useEffect(()=>{!F.current&&v.isAuthenticated&&V("max"),F.current=v.isAuthenticated;},[v.isAuthenticated]);let U="botbuddy-widget-max-size",q=()=>{try{let o=localStorage.getItem(U);if(o)return JSON.parse(o)}catch{}return {w:340,h:500}},[le,Me]=useState(q),je=useRef(false),qe=useRef({x:0,y:0,w:0,h:0}),Yn=useCallback(o=>{o.stopPropagation(),je.current=true,qe.current={x:o.clientX,y:o.clientY,w:le.w,h:le.h},o.target.setPointerCapture(o.pointerId);},[le]),Jn=useCallback(o=>{if(!je.current)return;let h=Math.max(280,Math.min(600,qe.current.w+(o.clientX-qe.current.x))),$=Math.max(300,Math.min(window.innerHeight*.9,qe.current.h+(o.clientY-qe.current.y)));Me({w:h,h:$});},[]),Xn=useCallback(()=>{je.current&&(je.current=false,Me(o=>(localStorage.setItem(U,JSON.stringify(o)),o)));},[]),be=g??(typeof window<"u"?window.location.href:void 0),Zt=v.displayName||L,[ve,Qt]=useState(null);useEffect(()=>{if(v.isAuthenticated)return;let o=new URLSearchParams;l&&o.set("token",l),a&&o.set("ticket_id",a),o.set("app_slug",t),n&&o.set("environment",n),s&&o.set("test_run_id",s),be&&o.set("target_url",be),p&&o.set("version",p),N&&o.set("commit_sha",N),u&&o.set("pr_number",String(u)),f&&o.set("branch_name",f),fetch(`${e.serverUrl}/widget/preview?${o}`,{headers:{apikey:e.anonKey}}).then(h=>h.json()).then(h=>Qt(h)).catch(()=>Qt(null));},[v.isAuthenticated,e.serverUrl,e.anonKey,t,n,a,s,l,be,p,N,u,f]);let en=useRef(false),Zn=useCallback(()=>{en.current||v.logout();},[v.logout]),{run:k,widgetState:Pe,fetchRun:Qn,setVerdict:tn,markComplete:er,resetRun:tr,setRun:nn}=Tt({config:e,appSlug:t,environment:n,ticketId:a,testRunId:s,testRunToken:l,targetUrl:be,version:p,commitSha:N,prNumber:u?String(u):void 0,branchName:f,authToken:v.token,onAuthExpired:Zn});en.current=!!k;let[rn,on]=useState([]),[sn,rt]=useState([]),[vt,an]=useState(false),[ln,dn]=useState(null),[nr,ot]=useState(false),Ne=_r(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);useEffect(()=>{if((n??"local")!=="local"||Ne){on([]);return}let o=true;return ct().then(h=>{o&&on(Object.keys(h||{}));}),()=>{o=false;}},[n,Ne]);let rr=useCallback(async()=>{if(!(!v.isAuthenticated||!v.token)){an(true),dn(null);try{let o=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${v.token}`},body:JSON.stringify({app_slug:t,environment:n||"local",target_url:be,branch_name:f,commit_sha:N,pr_number:u,ticket_id:a,title:`${a||t} local validation`})}),h=await o.json().catch(()=>({}));if(!o.ok)throw new Error(h.error||`HTTP ${o.status}`);nn(h),V("max");}catch(o){dn(o.message);}finally{an(false);}}},[v.isAuthenticated,v.token,e.serverUrl,e.anonKey,t,n,be,f,N,u,a,nn]),st=useCallback(async(o,h,$)=>{ze(o);try{await tn(o,h,$,Zt);}finally{ze(null),ie(null),ee("");}},[tn,Zt]),X=k?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},or=X.total>0&&X.pending===0,Ue=Pe==="completed",at=useMemo(()=>{let o=k?.test_cases||[];if(!pe.trim())return o;let h=pe.toLowerCase();return o.filter($=>$.title.toLowerCase().includes(h)||$.description&&$.description.toLowerCase().includes(h)||$.url_path&&$.url_path.toLowerCase().includes(h)||$.seed_user&&$.seed_user.toLowerCase().includes(h))},[k?.test_cases,pe]),cn=useMemo(()=>{let o=at,h=k?.test_cases||[];if(new Set(h.map(oe=>oe.source_pr_number)).size<=1)return null;let J=[],_e=new Map;o.forEach(oe=>{let re=oe.source_pr_number;_e.has(re)||_e.set(re,[]),_e.get(re).push(oe);});let hn=[..._e.keys()].sort((oe,re)=>oe===null?1:re===null?-1:re-oe);for(let oe of hn){let re=_e.get(oe),kt={total:re.length,pass:0,fail:0,skip:0,pending:0};re.forEach(xn=>{xn.verdict in kt&&kt[xn.verdict]++;}),J.push({key:oe!=null?`pr-${oe}`:"general",label:oe!=null?`PR #${oe}`:"General",cases:re,summary:kt});}return J.filter(oe=>oe.cases.length>0)},[at,k?.test_cases]),un=X.total>0?(X.pass+X.fail)/X.total*100:0,ne=n??k?.environment??null,Se=useMemo(()=>{if(!ne||ne==="production"||Ne)return [];let o=k?.test_cases||[],h=new Set;for(let $ of o)$.seed_user&&h.add(Bt($.seed_user));if(ne==="local")for(let $ of rn)h.add(Bt($));for(let $ of sn)h.add(Bt($));return [...h]},[k?.test_cases,ne,rn,sn,Ne]);useEffect(()=>{if(!ne||ne==="production"||Ne||!v.isAuthenticated||!v.token){rt([]);return}let o=true,h=`${e.serverUrl}/widget/totp-seeds?${new URLSearchParams({app_slug:t,environment:ne})}`,$=J=>fetch(h,{headers:{apikey:e.anonKey,Authorization:`Bearer ${J}`}});return (async()=>{try{let J=await $(v.token);if(J.status===401&&v.refreshNow){let re=await v.refreshNow();re&&(J=await $(re));}if(!o)return;if(!J.ok){rt([]);return}let _e=await J.json().catch(()=>null),oe=(Array.isArray(_e?.seeds)?_e.seeds:[]).map(re=>re?.seed_user_slug).filter(re=>typeof re=="string"&&re.length>0);rt(oe);}catch{o&&rt([]);}})(),()=>{o=false;}},[ne,Ne,v.isAuthenticated,v.token,v.refreshNow,t,e.serverUrl,e.anonKey]);let wt=useMemo(()=>{let o=k?.auto_tooltip_seconds??ve?.auto_tooltip_seconds;return o!=null&&o>0?o*1e3:0},[k,ve]),pn=Pe==="ready"||Pe==="completed"||ve?.enabled&&ve.run;useEffect(()=>{if(!pn||xe.current||wt<=0)return;xe.current=true,H(true);let o=window.setTimeout(()=>H(false),wt);return ()=>window.clearTimeout(o)},[pn,wt]);let bn=o=>jsxs("div",{style:d.caseRow,children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsx("div",{style:{marginTop:"2px",flexShrink:0,color:Rr[o.verdict]},children:Be===o.id?jsx(P,{d:R.loader,className:""}):jsx(P,{d:Nr[o.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:r.text,lineHeight:1.3},children:o.title}),o.description&&jsx("div",{style:{fontSize:"9px",color:r.gripColor,marginTop:"2px"},children:o.description}),o.seed_user&&jsxs("div",{style:{fontSize:"9px",color:r.amber,marginTop:"3px",display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",background:`${r.amber}12`,border:`1px solid ${r.amber}30`},children:[jsx(P,{d:R.key,size:10}),jsx("span",{children:o.seed_user})]}),o.url_path&&jsxs("a",{href:o.url_path,target:"_blank",rel:"noopener noreferrer",onClick:h=>{h.stopPropagation(),E&&(h.preventDefault(),E(o.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsx(P,{d:R.externalLink,size:10}),o.url_path]}),o.verdict==="fail"&&o.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:r.red,marginTop:"2px"},children:["\u2717 ",o.fail_reason]})]})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(h=>jsx("button",{onClick:()=>{if(o.verdict===h){st(o.id,"pending"),ie(null);return}if(h==="fail"){ie(o.id),ee("");return}ie(null),st(o.id,h);},disabled:Be!==null,style:d.verdictBtn(o.verdict===h,h==="pass"?r.green:h==="fail"?r.red:r.amber),children:h.toUpperCase()},h)),o.created_by_agent_name&&jsxs("span",{style:{fontSize:"8px",color:r.purple,marginLeft:"4px",display:"inline-flex",alignItems:"center",gap:"2px"},children:[jsx(P,{d:R.bot,size:8}),o.created_by_agent_name]}),o.verdict_by_display_name&&jsxs("span",{style:{fontSize:"8px",color:r.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[o.verdict_by_display_name,o.verdict_at&&jsx("span",{style:{opacity:.7},children:vr(o.verdict_at)})]})]}),me===o.id&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:Q,onChange:h=>ee(h.target.value),onKeyDown:h=>{h.key==="Enter"&&st(o.id,"fail",Q.trim()||void 0),h.key==="Escape"&&(ie(null),ee(""));},placeholder:"Reason (optional)...",style:d.input}),jsx("button",{onClick:()=>{st(o.id,"fail",Q.trim()||void 0);},style:d.verdictBtn(true,r.red),children:"\u2713"})]})]},o.id);if((Pe==="no-match"||Pe==="loading")&&!(!v.isAuthenticated&&ve?.enabled&&ve.run)){if(!(ne==="local"&&!Ne))return null}if(!v.isAuthenticated&&ve?.enabled&&ve.run){let o=ve.run,h=o.summary,$=o.status==="completed";return jsx("div",{ref:G,style:{...d.root,left:b.x,top:b.y},children:jsxs("div",{style:{position:"relative"},onMouseEnter:()=>C(true),onMouseLeave:()=>{C(false),W(false),H(false);},children:[jsxs("div",{style:{...d.pill($),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:I,onPointerMove:z,onPointerUp:()=>{K();},children:[jsx(P,{d:R.grip,size:10,className:""}),o.ticket_id&&o.ticket_url?jsx("a",{href:o.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:J=>J.stopPropagation(),style:{color:r.amber,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:o.ticket_id}):null,o.pr_url?jsxs("a",{href:o.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:J=>J.stopPropagation(),style:{color:r.blue,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:["PR#",o.pr_number??o.pr_id]}):null,o.created_by_agent_name?o.codex_thread_id?jsxs("a",{href:`codex://threads/${o.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",onClick:J=>J.stopPropagation(),style:{color:r.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(P,{d:R.terminal,size:10}),o.created_by_agent_name]}):jsxs("span",{style:{color:r.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(P,{d:R.bot,size:10}),o.created_by_agent_name]}):null,jsxs("span",{style:$?{color:r.green}:void 0,children:[h.pass,"/",h.total]}),h.fail>0&&jsxs("span",{style:{color:r.red},children:[h.fail,"\u2717"]}),jsx("span",{onClick:J=>{J.stopPropagation(),v.openLogin();},style:{color:r.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!_&&(w||B)&&o.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsx("div",{style:{fontSize:"11px",fontWeight:700,color:r.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:o.title}),(o.description||o.intro_notes)&&jsx("div",{style:{fontSize:"10px",color:r.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:o.description||o.intro_notes}),jsx("div",{style:{marginTop:"4px",fontSize:"9px",color:r.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!v.isAuthenticated)return jsxs("div",{ref:G,style:{...d.root,left:b.x,top:b.y,width:220,minHeight:0,cursor:"move",userSelect:"none",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`},onPointerDown:I,onPointerMove:z,onPointerUp:K,children:[jsx("div",{style:{...d.handle,borderBottom:"none"},children:jsxs("div",{style:d.sub,children:[jsx(P,{d:R.grip,size:10,className:""}),jsx(P,{d:R.clipboard,size:12,className:""}),jsx("span",{style:{fontWeight:600},children:"BotBuddy"})]})}),jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[jsx("div",{style:{fontSize:"9px",color:r.textMuted,marginBottom:"8px"},children:"Sign in to access test cases"}),ne==="local"&&Se.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx(Ye,{config:e,appSlug:t,environment:ne,seededUsers:Se,authToken:v.token,refreshAuth:v.refreshNow,requestLogin:v.openLogin,tk:r,testRunId:k?.id||s,testRunToken:l,ticketId:a,targetUrl:be,version:p,commitSha:N,prNumber:u,branchName:f,onAuthExpired:v.logout})}),jsx("button",{onClick:o=>{o.stopPropagation(),v.openLogin();},style:{fontSize:"10px",fontWeight:600,padding:"6px 16px",borderRadius:"6px",border:`1px solid ${r.green}`,background:`${r.green}22`,color:r.green,cursor:"pointer",width:"100%"},children:"Sign in to test"})]})]});if(!k&&ne==="local"&&!Ne)return nr?jsx("div",{ref:G,style:{...d.root,left:b.x,top:b.y},children:jsxs("div",{style:d.card(240,false),children:[jsxs("div",{style:d.handle,onPointerDown:I,onPointerMove:z,onPointerUp:K,onClick:()=>{te.current||ot(false);},children:[jsx(P,{d:R.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:d.title,children:"BotBuddy"}),f&&jsx("div",{style:d.sub,children:jsxs("span",{children:["\u2387 ",f]})})]}),jsx(P,{d:R.chevronUp,className:""}),jsx("button",{style:d.btn,onClick:o=>{o.stopPropagation(),ot(false);},children:jsx(P,{d:R.minus,className:""})})]}),jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[Se.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx(Ye,{config:e,appSlug:t,environment:ne,seededUsers:Se,authToken:v.token,refreshAuth:v.refreshNow,requestLogin:v.openLogin,tk:r,testRunId:s,testRunToken:l,ticketId:a,targetUrl:be,version:p,commitSha:N,prNumber:u,branchName:f,onAuthExpired:v.logout})}),jsx("button",{onClick:o=>{o.stopPropagation(),rr();},disabled:vt,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${r.green}`,background:`${r.green}22`,color:r.green,cursor:vt?"wait":"pointer",width:"100%"},children:vt?"Creating...":"Create test run for this branch"}),ln&&jsx("div",{style:{fontSize:"9px",color:r.red,marginTop:"8px"},children:ln})]})]})}):jsx("div",{ref:G,style:{...d.root,left:b.x,top:b.y},children:jsxs("div",{style:{...d.pill(false),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:I,onPointerMove:z,onPointerUp:()=>{K(),te.current||ot(true);},children:[jsx(P,{d:R.grip,size:9,className:""}),jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),Se.length>0&&jsx(Ye,{config:e,appSlug:t,environment:ne,seededUsers:Se,authToken:v.token,refreshAuth:v.refreshNow,requestLogin:v.openLogin,tk:r,compact:true,onExpand:()=>ot(true),testRunId:s,testRunToken:l,ticketId:a,targetUrl:be,version:p,commitSha:N,prNumber:u,branchName:f,onAuthExpired:v.logout})]})});let gn=()=>{te.current||(H(false),V(o=>{let h=o==="mini"?"max":"mini";return W(h==="mini"),h}));},fn=({icon:o,onClick:h})=>jsx("button",{style:d.btn,onClick:$=>{$.stopPropagation(),h($);},children:jsx(P,{d:o,className:""})}),mn=()=>jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${r.borderSubtle}`,flexShrink:0},children:[k?.pr_url&&jsxs("a",{href:k.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(r.blue),textDecoration:"none"},children:[jsx(P,{d:R.pr,size:12}),k.pr_number?`PR#${k.pr_number}`:k.pr_id||"PR",jsx(P,{d:R.externalLink,size:8})]}),k?.ticket_url&&jsxs("a",{href:k.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(r.amber),textDecoration:"none"},children:[jsx(P,{d:R.ticket,size:12}),k.ticket_id||"Ticket",jsx(P,{d:R.externalLink,size:8})]}),k?.created_by_agent_name&&(k.codex_thread_id?jsxs("a",{href:`codex://threads/${k.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...d.link(r.purple),textDecoration:"none"},children:[jsx(P,{d:R.bot,size:12}),k.created_by_agent_name,jsx(P,{d:R.externalLink,size:8})]}):jsxs("span",{style:{...d.link(r.purple)},children:[jsx(P,{d:R.bot,size:12}),k.created_by_agent_name]})),ne&&jsx(Ye,{config:e,appSlug:t,environment:ne,seededUsers:Se,authToken:v.token,refreshAuth:v.refreshNow,requestLogin:v.openLogin,tk:r,testRunId:k?.id||s,testRunToken:l,ticketId:a,targetUrl:be,version:p,commitSha:N,prNumber:u,branchName:f,onAuthExpired:v.logout}),jsx("span",{style:{...d.badge(k?.environment||"custom"),marginLeft:"auto"},children:k?.environment})]}),yn=()=>jsxs("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:`1px solid ${r.borderSubtle}`,background:r.bgSoft,flexShrink:0},children:[jsxs("button",{onClick:()=>{navigator.clipboard.writeText(Rn);},style:{fontSize:"9px",fontWeight:600,color:r.versionText,letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxs("span",{style:{color:r.versionNum},children:["v",Rn]})]}),v.isAuthenticated&&(v.isExpired?jsx("button",{onClick:o=>{o.stopPropagation(),v.openLogin();},style:{fontSize:"8px",color:r.blue,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Widget session expired \u2014 sign in to refresh",children:"sign in"}):jsx("button",{onClick:o=>{o.stopPropagation(),v.logout();},style:{fontSize:"8px",color:r.textFaint,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Sign out of widget",children:"sign out"}))]});return jsxs("div",{ref:G,style:{...d.root,left:b.x,top:b.y},children:[T==="mini"&&jsxs("div",{style:{position:"relative"},onMouseEnter:()=>C(true),onMouseLeave:()=>{C(false),W(false),H(false);},children:[jsxs("div",{style:{...d.pill(Ue),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:I,onPointerMove:z,onPointerUp:()=>{K(),te.current||gn();},children:[jsx(P,{d:R.grip,size:9,className:""}),k?.ticket_id&&jsx("span",{style:{color:r.amber,fontWeight:600},children:k.ticket_id}),k?.pr_number&&jsxs("span",{style:{color:r.blue,fontWeight:600},children:["PR#",k.pr_number]}),jsxs("span",{style:Ue?{color:r.green}:void 0,children:[X.pass,"/",X.total]}),X.fail>0&&jsxs("span",{style:{color:r.red},children:[X.fail,"\u2717"]}),ne&&jsx(Ye,{config:e,appSlug:t,environment:ne,seededUsers:Se,authToken:v.token,refreshAuth:v.refreshNow,requestLogin:v.openLogin,tk:r,compact:true,onExpand:()=>V("expanded"),testRunId:k?.id||s,testRunToken:l,ticketId:a,targetUrl:be,version:p,commitSha:N,prNumber:u,branchName:f,onAuthExpired:v.logout})]}),!_&&(w||B)&&k?.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsx("div",{style:{fontSize:"11px",fontWeight:700,color:r.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:k.title}),(k.description||k.intro_notes)&&jsx("div",{style:{fontSize:"10px",color:r.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:k.description||k.intro_notes})]})]}),T==="expanded"&&jsxs("div",{style:d.card(300,Ue),children:[jsxs("div",{style:d.handle,onPointerDown:I,onPointerMove:z,onPointerUp:K,onClick:gn,children:[jsx(P,{d:R.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:d.title,children:k?.title}),jsx("div",{style:d.sub,children:k?.branch_name&&jsxs("span",{children:["\u2387 ",k.branch_name]})})]}),jsx(P,{d:R.chevronUp,className:""}),jsx(fn,{icon:R.minus,onClick:()=>{H(false),W(true),V("mini");}})]}),jsxs("div",{style:d.stats,children:[jsxs("span",{style:{color:r.green},children:[X.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[X.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[X.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[X.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:X.total})]}),k?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:r.gripColor,borderBottom:`1px solid ${r.borderSubtle}`,flexShrink:0},children:k.description}),mn(),yn(),jsx("div",{style:d.progress,children:jsx("div",{style:d.progressBar(un)})})]}),T==="max"&&jsxs("div",{style:{...d.card(le.w,Ue),height:le.h,position:"relative"},children:[jsxs("div",{style:d.handle,onPointerDown:I,onPointerMove:z,onPointerUp:K,onClick:()=>{te.current||V("expanded");},children:[jsx(P,{d:R.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:d.title,children:k?.title}),jsx("div",{style:d.sub,children:k?.branch_name&&jsxs("span",{children:["\u2387 ",k.branch_name]})})]}),jsx(P,{d:R.chevronDown,className:""}),jsx(fn,{icon:R.minus,onClick:()=>{H(false),W(true),V("mini");}})]}),jsxs("div",{style:d.stats,children:[jsxs("span",{style:{color:r.green},children:[X.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[X.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[X.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[X.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:X.total})]}),k?.intro_notes&&jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${r.borderSubtle}`,fontSize:"10px",color:r.textMuted,fontStyle:"italic",flexShrink:0},children:k.intro_notes}),(k?.test_cases||[]).length>5&&jsxs("div",{style:{padding:"4px 12px",borderBottom:`1px solid ${r.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[jsx(P,{d:R.search,size:11,className:""}),jsx("input",{value:pe,onChange:o=>Fe(o.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:r.text,fontFamily:"monospace"}}),pe&&jsx("button",{onClick:()=>Fe(""),style:{background:"none",border:"none",cursor:"pointer",color:r.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),Pe==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(P,{d:R.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:r.red},children:"Failed to load"}),jsx("button",{onClick:Qn,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),Ue&&jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg},children:[jsx(P,{d:R.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:r.green,flex:1},children:"Run completed"}),jsx("button",{onClick:tr,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),Pe!=="error"&&jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(k?.test_cases||[]).length===0?jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:"No test cases"}):at.length===0?jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:['No matches for "',pe,'"']}):cn?cn.map(o=>{let h=Ke.has(o.key);return jsxs("div",{children:[jsxs("button",{onClick:()=>Ie(o.key),style:{width:"100%",display:"flex",alignItems:"center",gap:"6px",padding:"5px 12px",background:r.bgSoft,cursor:"pointer",border:"none",borderLeft:"none",borderRight:"none",borderBottomStyle:"solid",borderTopStyle:"solid",borderBottomWidth:"1px",borderTopWidth:"1px",borderBottomColor:r.borderSubtle,borderTopColor:r.borderSubtle,backgroundColor:r.bgSoft},children:[jsx(P,{d:h?R.chevronDown:R.chevronUp,size:10,className:""}),jsx("span",{style:{fontSize:"10px",fontWeight:700,color:r.blue,flex:1,textAlign:"left"},children:o.label}),jsxs("span",{style:{fontSize:"9px",color:r.green},children:[o.summary.pass,"\u2713"]}),jsxs("span",{style:{fontSize:"9px",color:r.red},children:[o.summary.fail,"\u2717"]}),jsxs("span",{style:{fontSize:"9px",color:r.gripColor},children:[o.summary.pending,"\u25CC"]}),jsx("span",{style:{fontSize:"9px",color:r.textFaint},children:o.summary.total})]}),!h&&o.cases.map($=>bn($))]},o.key)}):at.map(o=>bn(o))}),or&&!Ue&&jsxs("div",{style:{padding:"6px 12px",borderTop:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg,display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsx("span",{style:{fontSize:"9px",color:r.green},children:"All resolved"}),jsx("button",{onClick:er,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:r.green,border:`1px solid ${r.greenBorderSubtle}`,cursor:"pointer"},children:"COMPLETE"})]}),mn(),yn(),jsx("div",{style:d.progress,children:jsx("div",{style:d.progressBar(un)})}),jsx("div",{style:{position:"absolute",bottom:0,right:0,width:16,height:16,cursor:"se-resize",zIndex:10,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:"2px",opacity:.3},onPointerDown:Yn,onPointerMove:Jn,onPointerUp:Xn,onPointerEnter:o=>o.currentTarget.style.opacity="0.7",onPointerLeave:o=>{je.current||(o.currentTarget.style.opacity="0.3");},children:jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsx("path",{d:"M7 1v6H1",fill:"none",stroke:r.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}var Ar=1e4,Je=new Map;var ut=class extends Error{};async function Lr(e,t,n){let a={headers:{authorization:`Bearer ${t}`}};try{return await fetch(e,{...a,signal:n})}catch(s){if(s instanceof TypeError&&/signal/i.test(s.message)&&!n.aborted)return fetch(e,a);throw s}}function Br(e){let t=e;return !!t&&typeof t=="object"&&typeof t.tenant=="string"&&Array.isArray(t.entries)&&t.entries.every(n=>!!n&&typeof n.id=="string"&&typeof n.title=="string"&&!!n.body&&Array.isArray(n.body.ast)&&Array.isArray(n.links))}function zt({endpoint:e,getToken:t,timeoutMs:n=Ar}){let[a,s]=useState(()=>({feed:null,error:null,loading:true,stale:false})),[l,g]=useState(0),p=useRef(t);p.current=t,useEffect(()=>{let u=new AbortController,f=true,E=false,L=setTimeout(()=>{E=true,u.abort();},n),m=new Promise((r,d)=>{u.signal.addEventListener("abort",()=>d(new Error("timeout")),{once:true});});m.catch(()=>{}),s(r=>({...r,error:null,loading:true}));let x=null,y=(r,d)=>{if(d&&Je.delete(e),!f)return;let w=d||x===null?void 0:Je.get(e)?.get(x);s({feed:w??null,error:r,loading:false,stale:!!w});};return (async()=>{try{let r;try{r=await Promise.race([Promise.resolve().then(()=>p.current()),m]);}catch(B){throw E||u.signal.aborted?B:new ut("token_unavailable")}x=r;let d=await Promise.race([Lr(e,r,u.signal),m]),w=d.status===401||d.status===403;w&&Je.delete(e);let C=null;try{C=await Promise.race([d.json(),m]);}catch(B){if(E&&!w)throw B;C=null;}if(!f)return;if(d.ok)if(!Br(C))y("invalid_feed",!1);else {let B=Je.get(e)??new Map;B.set(r,C),Je.set(e,B),s({feed:C,error:null,loading:!1,stale:!1});}else {let B=C?.error;y(typeof B=="string"?B:`http_${d.status}`,w);}}catch(r){r instanceof ut?y(r.message,true):y(E?"timeout":r instanceof Error&&r.message||"unavailable",false);}finally{clearTimeout(L);}})(),()=>{f=false,clearTimeout(L),u.abort();}},[e,l,n]);let N=useCallback(()=>g(u=>u+1),[]);return {...a,reload:N}}var Ft=["accent","fg","bg","muted","border","radius","font"],zr={accent:"hsl(var(--primary))",fg:"hsl(var(--foreground))",bg:"hsl(var(--card))",muted:"hsl(var(--muted-foreground))",border:"hsl(var(--border))",radius:"var(--radius)",font:"inherit"},Z=(e,t)=>t===void 0?`var(--bbrn-${e},var(--_bbrn-${e}))`:`var(--bbrn-${e},var(--_bbrn-${e},${t}))`,Ce=Z("accent","currentColor"),de=Z("muted","color-mix(in srgb,currentColor 72%,transparent)"),fe=Z("border","color-mix(in srgb,currentColor 22%,transparent)"),Fr=`@layer bbrn{
2
+ .bbrn-root{${Ft.filter(e=>e!=="font").map(e=>`--_bbrn-${e}:${zr[e]};`).join("")}display:grid;gap:12px;color:${Z("fg")};font-family:var(--bbrn-font)}
3
3
  .bbrn-root .bbrn-entry{background:${Z("bg","transparent")};border:1px solid ${fe};border-radius:${Z("radius",".5rem")};padding:16px}
4
4
  .bbrn-root .bbrn-head{display:flex;gap:8px;align-items:baseline;flex-wrap:wrap}
5
5
  .bbrn-root .bbrn-title{font-weight:600;font-size:1rem;line-height:1.4;margin:0}
6
- .bbrn-root .bbrn-badge{font-size:.75rem;line-height:1.4;color:${Te};border:1px solid currentColor;border-radius:999px;padding:0 8px}
6
+ .bbrn-root .bbrn-badge{font-size:.75rem;line-height:1.4;color:${Ce};border:1px solid currentColor;border-radius:999px;padding:0 8px}
7
7
  .bbrn-root .bbrn-delivery{font-size:.75rem;line-height:1.4;border-radius:999px;padding:0 8px;background:color-mix(in srgb,${fe} 60%,transparent)}
8
- .bbrn-root .bbrn-meta,.bbrn-root .bbrn-status{color:${ce};font-size:.8rem;margin:0}
8
+ .bbrn-root .bbrn-meta,.bbrn-root .bbrn-status{color:${de};font-size:.8rem;margin:0}
9
9
  .bbrn-root .bbrn-p{margin:.5em 0}
10
10
  .bbrn-root .bbrn-list{margin:.5em 0;padding-left:1.25em;list-style:disc}
11
11
  .bbrn-root .bbrn-code{font-family:ui-monospace,monospace;font-size:.85em;padding:0 4px;border-radius:4px;background:color-mix(in srgb,${fe} 60%,transparent)}
12
12
  .bbrn-root .bbrn-links{display:flex;gap:12px;flex-wrap:wrap;margin-top:8px;font-size:.85rem}
13
- .bbrn-root .bbrn-link{color:${Te};text-decoration:underline}
13
+ .bbrn-root .bbrn-link{color:${Ce};text-decoration:underline}
14
14
  .bbrn-root .bbrn-tags{display:flex;gap:6px;flex-wrap:wrap;margin:8px 0 0;padding:0;list-style:none}
15
- .bbrn-root .bbrn-tag{font-size:.75rem;line-height:1.4;border:1px solid ${fe};border-radius:999px;padding:0 8px;color:${ce}}
15
+ .bbrn-root .bbrn-tag{font-size:.75rem;line-height:1.4;border:1px solid ${fe};border-radius:999px;padding:0 8px;color:${de}}
16
16
  .bbrn-root .bbrn-filters{display:flex;gap:12px;flex-wrap:wrap;align-items:center;font-size:.85rem}
17
17
  .bbrn-root .bbrn-pager{display:flex;gap:12px;font-size:.85rem}
18
18
  .bbrn-root .bbrn-pager .bbrn-retry{margin-left:0}
19
- .bbrn-root .bbrn-filter{display:inline-flex;gap:6px;align-items:center;color:${ce}}
19
+ .bbrn-root .bbrn-filter{display:inline-flex;gap:6px;align-items:center;color:${de}}
20
20
  .bbrn-root .bbrn-filter select{font:inherit;color:${Z("fg")};background:${Z("bg","transparent")};border:1px solid ${fe};border-radius:${Z("radius",".5rem")};padding:2px 6px;max-width:16rem}
21
- .bbrn-root.bbrn-whatsnew{display:inline-flex;align-items:center;justify-content:center;min-width:1.25rem;height:1.25rem;padding:0 6px;border-radius:999px;font-size:.7rem;font-weight:600;line-height:1;color:${Z("bg","Canvas")};background:${Te}}
21
+ .bbrn-root.bbrn-whatsnew{display:inline-flex;align-items:center;justify-content:center;min-width:1.25rem;height:1.25rem;padding:0 6px;border-radius:999px;font-size:.7rem;font-weight:600;line-height:1;color:${Z("bg","Canvas")};background:${Ce}}
22
22
  .bbrn-root.bbrn-announcement{gap:4px;max-width:22rem;background:${Z("bg","Canvas")};border:1px solid ${fe};border-radius:${Z("radius",".5rem")};padding:12px 16px;box-shadow:0 4px 16px color-mix(in srgb,currentColor 18%,transparent)}
23
23
  .bbrn-root.bbrn-announcement .bbrn-title{font-size:.9rem}
24
24
  .bbrn-root.bbrn-announcement .bbrn-links{margin-top:4px;align-items:center}
25
25
  .bbrn-root.bbrn-announcement .bbrn-retry{margin-left:0}
26
26
  .bbrn-root.bbrn-pack{gap:10px;font-size:.9rem}
27
- .bbrn-root .bbrn-pack-summary{cursor:pointer;color:${Te};font-size:.85rem;margin-top:8px}
27
+ .bbrn-root .bbrn-pack-summary{cursor:pointer;color:${Ce};font-size:.85rem;margin-top:8px}
28
28
  .bbrn-root .bbrn-pack-section{display:grid;gap:4px}
29
- .bbrn-root .bbrn-pack-heading{font-size:.8rem;font-weight:600;text-transform:uppercase;letter-spacing:.04em;color:${ce};margin:0}
29
+ .bbrn-root .bbrn-pack-heading{font-size:.8rem;font-weight:600;text-transform:uppercase;letter-spacing:.04em;color:${de};margin:0}
30
30
  .bbrn-root .bbrn-pack-field{display:grid;grid-template-columns:minmax(6rem,9rem) 1fr;gap:0 12px;align-items:baseline}
31
- .bbrn-root .bbrn-pack-label{color:${ce};font-size:.8rem}
31
+ .bbrn-root .bbrn-pack-label{color:${de};font-size:.8rem}
32
32
  .bbrn-root .bbrn-pack-value .bbrn-p:first-child,.bbrn-root .bbrn-pack-section>.bbrn-p:first-of-type{margin-top:0}
33
- .bbrn-root .bbrn-pack-hint{display:block;color:${ce};font-size:.75rem}
33
+ .bbrn-root .bbrn-pack-hint{display:block;color:${de};font-size:.75rem}
34
34
  .bbrn-root.bbrn-release{gap:16px 32px;font-size:14px;line-height:1.5;align-items:start}
35
35
  .bbrn-root .bbrn-release-main{display:grid;gap:20px;min-width:0}
36
36
  .bbrn-root .bbrn-id{font-family:ui-monospace,monospace;font-size:12px}
37
37
  .bbrn-root .bbrn-release-header{display:grid;gap:2px}
38
38
  .bbrn-root .bbrn-release-version{font-size:1.5rem;font-weight:600;line-height:1.25;margin:0;overflow-wrap:anywhere}
39
- .bbrn-root .bbrn-release-deployed{color:${ce};font-size:12px;margin:0}
39
+ .bbrn-root .bbrn-release-deployed{color:${de};font-size:12px;margin:0}
40
40
  .bbrn-root .bbrn-release-summary{margin:4px 0 0;font-weight:500}
41
41
  .bbrn-root .bbrn-release-section{display:grid;gap:8px}
42
- .bbrn-root .bbrn-release-section-heading{font-size:13px;font-weight:600;text-transform:uppercase;letter-spacing:.04em;color:${ce};margin:0;display:inline}
42
+ .bbrn-root .bbrn-release-section-heading{font-size:13px;font-weight:600;text-transform:uppercase;letter-spacing:.04em;color:${de};margin:0;display:inline}
43
43
  .bbrn-root .bbrn-release-fold>summary{cursor:pointer}
44
44
  .bbrn-root .bbrn-release-fold[open]>summary{margin-bottom:8px}
45
- .bbrn-root .bbrn-release-empty{color:${ce};margin:0}
45
+ .bbrn-root .bbrn-release-empty{color:${de};margin:0}
46
46
  .bbrn-root .bbrn-release-cards{display:grid;gap:12px}
47
47
  .bbrn-root .bbrn-release-card{display:grid;gap:6px;background:${Z("bg","transparent")};border:1px solid ${fe};border-radius:${Z("radius",".5rem")};padding:14px 16px}
48
- .bbrn-root .bbrn-release-card-head{display:flex;gap:8px;align-items:baseline;flex-wrap:wrap;color:${ce}}
48
+ .bbrn-root .bbrn-release-card-head{display:flex;gap:8px;align-items:baseline;flex-wrap:wrap;color:${de}}
49
49
  .bbrn-root .bbrn-release-type{font-weight:600;font-size:12px;color:${Z("fg")}}
50
50
  .bbrn-root .bbrn-release-card .bbrn-title a{color:inherit;text-decoration:none}
51
51
  .bbrn-root .bbrn-release-card .bbrn-title a:hover{text-decoration:underline}
@@ -53,21 +53,21 @@ import {useState,useRef,useCallback,useEffect,useMemo,useLayoutEffect,useId,useI
53
53
  .bbrn-root .bbrn-release-missing-row{display:flex;gap:12px;align-items:flex-start;justify-content:space-between;flex-wrap:wrap;padding:10px 14px}
54
54
  .bbrn-root .bbrn-release-missing-row+.bbrn-release-missing-row{border-top:1px solid ${fe}}
55
55
  .bbrn-root .bbrn-release-missing-text{display:grid;gap:2px;min-width:0;flex:1 1 16rem}
56
- .bbrn-root .bbrn-release-missing-text .bbrn-id{color:${ce}}
56
+ .bbrn-root .bbrn-release-missing-text .bbrn-id{color:${de}}
57
57
  .bbrn-root .bbrn-release-missing-title{overflow-wrap:anywhere}
58
58
  .bbrn-root .bbrn-release-missing-text .bbrn-meta{font-size:12px}
59
59
  .bbrn-root .bbrn-release-actions{display:flex;gap:6px;flex-shrink:0}
60
60
  .bbrn-root .bbrn-release-button{font:inherit;font-size:12px;line-height:1.5;padding:3px 10px;border:1px solid ${fe};border-radius:${Z("radius",".375rem")};background:transparent;color:inherit;text-decoration:none;cursor:pointer;white-space:nowrap}
61
- .bbrn-root .bbrn-release-button-primary{background:${Te};border-color:${Te};color:${Z("bg","Canvas")}}
62
- .bbrn-root .bbrn-release-facts-heading{font-size:13px;font-weight:600;text-transform:uppercase;letter-spacing:.04em;color:${ce};margin:0 0 6px}
61
+ .bbrn-root .bbrn-release-button-primary{background:${Ce};border-color:${Ce};color:${Z("bg","Canvas")}}
62
+ .bbrn-root .bbrn-release-facts-heading{font-size:13px;font-weight:600;text-transform:uppercase;letter-spacing:.04em;color:${de};margin:0 0 6px}
63
63
  .bbrn-root .bbrn-release-facts{display:grid;grid-template-columns:auto 1fr;gap:4px 12px;margin:0;font-size:12px}
64
- .bbrn-root .bbrn-release-facts dt{color:${ce}}
64
+ .bbrn-root .bbrn-release-facts dt{color:${de}}
65
65
  .bbrn-root .bbrn-release-facts dd{margin:0;overflow-wrap:anywhere}
66
- .bbrn-root .bbrn-release-facts-fold>summary{cursor:pointer;color:${Te};font-size:12px}
66
+ .bbrn-root .bbrn-release-facts-fold>summary{cursor:pointer;color:${Ce};font-size:12px}
67
67
  .bbrn-root .bbrn-release-facts-fold>summary~*{margin-top:8px}
68
68
  .bbrn-root .bbrn-release-rail{border-left:1px solid ${fe};padding-left:20px}
69
69
  @media (min-width:1280px){.bbrn-root.bbrn-release{grid-template-columns:minmax(0,1fr) 17rem}.bbrn-root .bbrn-release-facts-fold{display:none}}
70
70
  @media (max-width:1279.98px){.bbrn-root .bbrn-release-rail{display:none}}
71
- .bbrn-root .bbrn-retry{margin-left:8px;text-decoration:underline;background:none;border:0;padding:0;color:${Te};cursor:pointer;font:inherit}
72
- }`;function we(e=typeof document>"u"?void 0:document){if(!e?.head||e.head.querySelector("style[data-bbrn-styles]"))return;let t=e.createElement("style");t.setAttribute("data-bbrn-styles",""),t.textContent=zr,e.head.prepend(t);}function Xe(e){if(!e)return;let t={};for(let n of It){let a=e[n];typeof a=="string"&&a.trim()&&(t[`--bbrn-${n}`]=a);}return Object.keys(t).length?t:void 0}var Ir=/^https:\/\/[^/?#\s\\*]+\/?$/;function Ft(e,t){let n=We(e);if(!n)return null;if(n.kind==="external")return {href:n.href,external:true};if(t.inHostApp)return {href:n.href,external:false};let a=t.appOrigin;if(typeof a!="string"||!Ir.test(a))return null;let s=a.replace(/\/$/,"");return t.currentOrigin&&s===t.currentOrigin?{href:n.href,external:false}:{href:`${s}${n.href}`,external:true}}var Or=useInsertionEffect??useLayoutEffect,Dr=(...e)=>e.filter(Boolean).join(" "),he=e=>Array.isArray(e)&&e.length>0;function pt({label:e,level:t,children:n}){let a=`h${t}`;return jsxs("section",{className:"bbrn-pack-section","aria-label":e,children:[jsx(a,{className:"bbrn-pack-heading",children:e}),n]})}function He({label:e,children:t}){return jsxs("div",{className:"bbrn-pack-field",role:"group","aria-label":e,children:[jsx("span",{className:"bbrn-pack-label",children:e}),jsx("div",{className:"bbrn-pack-value",children:t})]})}function Ze({pack:e,appOrigin:t,currentOrigin:n,inHostApp:a,onNavigate:s,renderInternalLink:l,unresolvedHint:u,headingLevel:p=3,className:w}){Or(()=>{we();},[]);let c=e.tour,b=c?Ft(c.find_it,{appOrigin:t,currentOrigin:n,inHostApp:a}):null,E=c?c.where??c.find_it:"",P=m=>r=>{!s||r.defaultPrevented||r.button!==0||r.metaKey||r.ctrlKey||r.shiftKey||r.altKey||(r.preventDefault(),s(m));},f=c?b?b.external?jsx("a",{className:"bbrn-link",href:b.href,target:"_blank",rel:"noopener noreferrer",children:E}):l?l(b.href,E):jsx("a",{className:"bbrn-link",href:b.href,onClick:P(b.href),children:E}):jsxs(Fragment,{children:[c.where&&jsxs(Fragment,{children:[c.where," \xB7 "]}),jsx("code",{className:"bbrn-code",children:c.find_it}),u&&jsx("span",{className:"bbrn-pack-hint",children:u})]}):null,h=e.before;return jsxs("div",{className:Dr("bbrn-root bbrn-pack",w),"data-bbrn-pack":e.category||void 0,children:[(he(h)||he(e.after))&&jsxs(pt,{label:"What changed",level:p,children:[he(h)&&jsx(He,{label:"Before",children:jsx(de,{ast:h})}),he(e.after)&&jsx(He,{label:he(h)?"After":"Now",children:jsx(de,{ast:e.after})})]}),he(e.benefit)&&jsx(pt,{label:"Why it matters",level:p,children:jsx(de,{ast:e.benefit})}),he(e.ui)&&jsx(pt,{label:"Where it shows",level:p,children:jsx(de,{ast:e.ui})}),c&&jsxs(pt,{label:"Try it",level:p,children:[jsx(He,{label:"Where to find it",children:f}),he(c.try)&&jsx(He,{label:"Try",children:jsx(de,{ast:c.try})}),he(c.look_for)&&jsx(He,{label:"Look for",children:jsx(de,{ast:c.look_for})}),he(c.watch)&&jsx(He,{label:"Watch out",children:jsx(de,{ast:c.watch})})]})]})}function We(e){if(typeof e!="string"||/[\s\\]/.test(e))return null;if(e.startsWith("/"))return e.startsWith("//")?null:{kind:"internal",href:e};try{return new URL(e).protocol==="https:"?{kind:"external",href:e}:null}catch{return null}}function bt(e,t=""){return e.map((n,a)=>{let s=`${t}${a}`;switch(n.t){case "text":return n.v;case "code":return jsx("code",{className:"bbrn-code",children:n.v},s);case "strong":return jsx("strong",{children:bt(n.c,`${s}.`)},s);case "em":return jsx("em",{children:bt(n.c,`${s}.`)},s);default:return null}})}function de({ast:e}){return jsx(Fragment,{children:e.map((t,n)=>t.t==="list"?jsx("ul",{className:"bbrn-list",children:t.items.map((a,s)=>jsx("li",{children:bt(a)},s))},n):t.t==="p"?jsx("p",{className:"bbrn-p",children:bt(t.c)},n):null)})}var O=(...e)=>e.filter(Boolean).join(" ");function Mn(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:`${t.toISOString().slice(0,16).replace("T"," ")} UTC`}var Kr=useInsertionEffect??useLayoutEffect,Ot=class extends Component{constructor(){super(...arguments);this.state={failed:false,keys:this.props.resetKeys};}static getDerivedStateFromError(){return {failed:true}}static getDerivedStateFromProps(n,a){return n.resetKeys.length!==a.keys.length||n.resetKeys.some((l,u)=>!Object.is(l,a.keys[u]))?{failed:false,keys:n.resetKeys}:null}componentDidCatch(){}render(){return this.state.failed?this.props.fallback:this.props.children}};function jr(e,t,n=1){let a=Object.entries(t).filter(([,s])=>s).map(([s,l])=>`tag=${encodeURIComponent(`${s}:${l}`)}`);return n>1&&a.push(`page=${n}`),a.length===0?e:`${e}${e.includes("?")?"&":"?"}${a.join("&")}`}function qr({endpoint:e,getToken:t,onNavigate:n,theme:a,classNames:s,components:l,timeoutMs:u}){Kr(()=>{we();},[]);let[p,w]=useState({}),[c,b]=useState(1),E=M=>{b(1),w(M);},P=useMemo(()=>jr(e,p,c),[e,p,c]),{feed:f,error:h,loading:m,stale:r,reload:d}=zt({endpoint:P,getToken:t,timeoutMs:u}),[k,T]=useState(0),B=()=>{T(M=>M+1),d();},W=useMemo(()=>Xe(a),[a]),_=s??{},H=l?.Empty,xe=l?.Link,ue=M=>C=>{!n||C.defaultPrevented||C.button!==0||C.metaKey||C.ctrlKey||C.shiftKey||C.altKey||(C.preventDefault(),n(M));},v=Object.values(p).some(Boolean),$e=jsxs("p",{className:O("bbrn-status",_.status),role:"alert","data-bbrn-error":h??"render_failed",children:["Release notes could not be loaded.",jsx("button",{type:"button",className:O("bbrn-retry",_.retry),onClick:B,children:"Retry"}),v&&jsx("button",{type:"button",className:O("bbrn-retry",_.retry),onClick:()=>E({}),children:"Clear filters"})]});return jsxs("section",{className:O("bbrn-root",_.root),style:W,"aria-label":"Release notes","aria-busy":m,"data-bbrn-audience":f?.audience,children:[m&&!f&&jsx("p",{className:O("bbrn-status",_.status),role:"status",children:"Loading release notes\u2026"}),!m&&h&&!f&&$e,r&&jsxs("p",{className:O("bbrn-status",_.status),role:"status","data-bbrn-stale":"",children:["Showing the last loaded notes; they could not be refreshed.",jsx("button",{type:"button",className:O("bbrn-retry",_.retry),onClick:B,children:"Retry"})]}),f&&jsxs(Ot,{resetKeys:[f,H,xe,k],fallback:$e,children:[f.audience==="internal"&&f.notice&&jsx("p",{className:O("bbrn-status",_.status),role:"status","data-bbrn-notice":"production-freshness",children:f.notice}),(f.filters?.length??0)>0&&jsx("div",{className:O("bbrn-filters",_.filters),role:"group","aria-label":"Filter release notes",children:f.filters.map(M=>jsxs("label",{className:O("bbrn-filter",_.filter),"data-bbrn-filter":M.group,children:[M.label,jsxs("select",{value:p[M.group]??"",onChange:C=>{let V=C.target.value;E(Q=>({...Q,[M.group]:V}));},children:[jsx("option",{value:"",children:"All"}),M.values.map(C=>jsx("option",{value:C,children:C},C))]})]},M.group))}),f.entries.length===0&&v&&jsx("p",{className:O("bbrn-status",_.status),children:"No release notes match these filters."}),f.entries.length===0&&!v&&(H?jsx(H,{}):f.audience==="external"?jsx("p",{className:O("bbrn-status",_.status),children:"Nothing new yet."}):jsxs("p",{className:O("bbrn-status",_.status),children:["No release notes yet. Submit one with ",jsx("code",{className:"bbrn-code",children:"bb release-notes submit"}),"."]})),f.entries.map(M=>{let C="source_key"in M?M:null;return jsxs("article",{className:O("bbrn-entry",_.entry),"data-entry-id":M.id,"data-source-key":C?.source_key,children:[jsxs("div",{className:O("bbrn-head",_.head),children:[jsx("h2",{className:O("bbrn-title",_.title),children:M.title}),jsx("span",{className:O("bbrn-badge",_.badge),"data-bbrn-type":M.type,children:M.type}),C&&jsx("span",{className:O("bbrn-badge",_.badge),"data-bbrn-state":C.state,children:C.state_copy??C.state}),C&&jsxs("span",{className:O("bbrn-meta",_.meta),children:[C.source_key," \xB7 revision ",C.revision]}),C?.delivery_copy&&jsxs("span",{className:O("bbrn-delivery",_.delivery),"data-bbrn-delivery":C.delivery_badge,children:[C.delivery_copy,C.delivery_since&&jsxs(Fragment,{children:[" \xB7 since ",jsx("time",{dateTime:C.delivery_since,children:Mn(C.delivery_since)})]})]}),!C&&"version"in M&&M.version&&jsxs("span",{className:O("bbrn-delivery",_.delivery),"data-bbrn-delivery":"released",children:["Released in ",M.version,M.released_at&&jsxs(Fragment,{children:[" \xB7 ",jsx("time",{dateTime:M.released_at,children:Mn(M.released_at)})]})]})]}),jsx("div",{className:O("bbrn-body",_.body),children:jsx(de,{ast:M.body.ast})}),(M.tags?.length??0)>0&&jsx("ul",{className:O("bbrn-tags",_.tags),"aria-label":"Tags",children:M.tags.map(V=>jsx("li",{className:O("bbrn-tag",_.tag),"data-bbrn-tag-group":V.group,title:V.label,children:V.value},`${V.group}:${V.value}`))}),C?.pack&&f.audience==="internal"&&jsxs("details",{className:"bbrn-pack-details",children:[jsx("summary",{className:"bbrn-pack-summary",children:"What changed \xB7 Try it"}),jsx(Ze,{pack:C.pack,inHostApp:true,onNavigate:n,className:_.pack})]}),M.links.length>0&&jsx("div",{className:O("bbrn-links",_.links),children:M.links.map((V,Q)=>{let ee=We(V.url);if(!ee)return null;let me=O("bbrn-link",_.link),ie=V.kind??null;return xe?jsx(xe,{href:ee.href,external:ee.kind==="external",kind:ie,className:me,onClick:ee.kind==="internal"&&n?ue(ee.href):void 0,children:V.name},Q):ee.kind==="external"?jsx("a",{className:me,href:ee.href,target:"_blank",rel:"noopener noreferrer","data-link-kind":ie??void 0,children:V.name},Q):jsx("a",{className:me,href:ee.href,onClick:ue(ee.href),"data-link-kind":ie??void 0,children:V.name},Q)})})]},M.id)}),f.audience==="external"&&(f.page>1||f.next_page!==null)&&jsxs("nav",{className:O("bbrn-pager",_.pager),"aria-label":"Release note pages",children:[f.page>1&&jsx("button",{type:"button",className:O("bbrn-retry",_.retry),onClick:()=>b(f.page-1),children:"Newer notes"}),f.next_page!==null&&jsx("button",{type:"button",className:O("bbrn-retry",_.retry),onClick:()=>b(f.next_page),children:"Older notes"})]})]})]})}var Qe={customer:"Customer-facing",internal:"Internal",missing:"Missing a release note"},Wt="Nothing customer-facing in this release.",Gr="BotBuddy could not read this release's range from GitHub.";function An(e){let t=e;return t.audience==="external"?true:t.audience==="internal"?false:t.customer_facing===true}function Ht(e,t){let n=[],a=[];for(let s of e)(An(s)?n:a).push(s);return {customer:n,internal:a,missing:t.filter(s=>!s.has_note)}}var Pn=(e,t,n)=>`${e} ${e===1?t:n}`;function Vt(e){return e.pullRequests===0&&e.notes===0?`No changes since ${e.previousVersion}.`:e.notes===0&&e.missing>0?e.missing===1?"This release's pull request has no release note yet.":`None of this release's ${e.missing} pull requests has a release note yet.`:[Pn(e.pullRequests,"pull request","pull requests"),Pn(e.notes,"release note","release notes"),`${e.missing} missing`].join(" \xB7 ")}var Jr=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Ln(e){if(!e)return null;let t=new Date(e);if(Number.isNaN(t.getTime()))return null;let n=a=>String(a).padStart(2,"0");return `${t.getUTCDate()} ${Jr[t.getUTCMonth()]} ${t.getUTCFullYear()}, ${n(t.getUTCHours())}:${n(t.getUTCMinutes())} UTC`}function Kt(e){if(e.candidate)return `Candidate for ${e.environment} \xB7 not released yet`;let t=Ln(e.live_at);return t?`Deployed to ${e.environment} \xB7 ${t}`:`Deployed to ${e.environment}`}var Bn=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;function jt(e){return Bn.test(e.repository)&&/^[0-9a-f]{7,40}$/i.test(e.commit_sha)?`https://github.com/${e.repository}/commit/${e.commit_sha}`:null}function qt(e){return e.run_id&&/^\d+$/.test(e.run_id)&&Bn.test(e.repository)?`https://github.com/${e.repository}/actions/runs/${e.run_id}`:null}function Yr(e,t){let n=e.tickets[0]?.key??`${t}#${e.pr.number}`;return JSON.stringify({schema_version:1,source_key:n,type:"Feature",change:{repository:t,pr_number:e.pr.number},internal:{title:e.pr.title,body:"What changed and why, for the team. Rewrite this from the diff."}},null,2)}var to=useInsertionEffect??useLayoutEffect,zn=(...e)=>e.filter(Boolean).join(" "),et=({level:e,className:t,id:n,children:a})=>{let s=`h${e}`;return jsx(s,{id:n,className:t,children:a})},In=e=>typeof e=="string"&&e.startsWith("https://")?e:null;function Fn(e){return !(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)}function Gt({href:e,children:t,className:n}){let a=In(e);return a?jsx("a",{className:zn("bbrn-link",n),href:a,target:"_blank",rel:"noopener noreferrer",children:t}):jsx("span",{className:n,children:t})}function Un({facts:e,summary:t,headingLevel:n=1}){return jsxs("header",{className:"bbrn-release-header",children:[jsx(et,{level:n,className:"bbrn-release-version",children:e.version}),jsx("p",{className:"bbrn-release-deployed",children:Kt(e)}),jsx("p",{className:"bbrn-release-summary","data-bbrn-release-summary":"",children:t})]})}function Jt({facts:e,readinessHref:t,onNavigate:n,headingLevel:a=2}){let s=jt(e),l=qt(e),u=p=>w=>{!n||!Fn(w)||(w.preventDefault(),n(p));};return jsxs(Fragment,{children:[jsx(et,{level:a,className:"bbrn-release-facts-heading",children:"Release facts"}),jsxs("dl",{className:"bbrn-release-facts",children:[jsx("dt",{children:"Repository"}),jsx("dd",{className:"bbrn-id",children:e.repository}),jsx("dt",{children:"Environment"}),jsx("dd",{children:e.environment}),jsx("dt",{children:"Commit"}),jsx("dd",{className:"bbrn-id",children:jsx(Gt,{href:s,children:e.commit_sha.slice(0,7)})}),e.run_id&&jsxs(Fragment,{children:[jsx("dt",{children:"Run"}),jsx("dd",{className:"bbrn-id",children:jsx(Gt,{href:l,children:e.run_id})})]}),jsx("dt",{children:"Since"}),jsx("dd",{className:"bbrn-id",children:e.previous_version}),t&&jsxs(Fragment,{children:[jsx("dt",{children:"Readiness"}),jsx("dd",{children:jsx("a",{className:"bbrn-link",href:t,onClick:u(t),children:"Open"})})]})]})]})}function gt({title:e,count:t,folded:n=false,empty:a,headingLevel:s=2,children:l}){let u=useId(),p=`${e} (${t})`,w=t===0&&a?jsx("p",{className:"bbrn-release-empty",children:a}):l;return n?jsx("section",{className:"bbrn-release-section","aria-labelledby":u,"data-bbrn-release-section":e,children:jsxs("details",{className:"bbrn-release-fold",children:[jsx("summary",{children:jsx(et,{level:s,id:u,className:"bbrn-release-section-heading",children:p})}),w]})}):jsxs("section",{className:"bbrn-release-section","aria-labelledby":u,"data-bbrn-release-section":e,children:[jsx(et,{level:s,id:u,className:"bbrn-release-section-heading",children:p}),w]})}function no(e){let t=e.pull_requests;return Array.isArray(t)?t.flatMap(n=>typeof n?.number=="number"?[n.number]:[]):[]}function On({entry:e,href:t,onNavigate:n,appOrigin:a,currentOrigin:s,inHostApp:l,renderInternalLink:u,headingLevel:p=3}){let w=[e.source_key,...no(e).map(b=>`#${b}`)].join(" \xB7 "),c=b=>E=>{!n||!Fn(E)||(E.preventDefault(),n(b));};return jsxs("article",{className:"bbrn-release-card","data-entry-id":e.id,"data-source-key":e.source_key,children:[jsxs("div",{className:"bbrn-release-card-head",children:[jsx("span",{className:"bbrn-release-type","data-bbrn-type":e.type,children:e.type}),jsx("span",{className:"bbrn-id",children:w})]}),jsx(et,{level:p,className:"bbrn-title",children:t?jsx("a",{href:t,onClick:c(t),children:e.title}):e.title}),e.pack?jsx(Ze,{pack:e.pack,headingLevel:p===4?4:p+1,appOrigin:a,currentOrigin:s,inHostApp:l,onNavigate:n,renderInternalLink:u}):jsx("div",{className:"bbrn-release-card-body",children:jsx(de,{ast:e.body.ast})})]})}function Dn({pullRequests:e,onWriteNote:t,pageSize:n=50}){let[a,s]=useState(false),l=a?e:e.slice(0,n);return jsxs(Fragment,{children:[jsx("ul",{className:"bbrn-release-missing",children:l.map(u=>{let p=u.project?u.project.percent_complete===null?u.project.id:`${u.project.id} (${Math.round(u.project.percent_complete)}%)`:null,w=[p&&jsx(Gt,{href:u.project.url,children:p},"project"),u.author?.label&&jsx("span",{children:u.author.label},"author")].filter(Boolean),c=In(u.pr.url);return jsxs("li",{className:"bbrn-release-missing-row","data-pr-number":u.pr.number,children:[jsxs("div",{className:"bbrn-release-missing-text",children:[jsx("span",{className:"bbrn-id",children:[`#${u.pr.number}`,...u.tickets.map(b=>b.key)].join(" \xB7 ")}),jsx("span",{className:"bbrn-release-missing-title",children:u.pr.title}),w.length>0&&jsx("span",{className:"bbrn-meta",children:w.flatMap((b,E)=>E===0?[b]:[" \xB7 ",b])})]}),jsxs("div",{className:"bbrn-release-actions",children:[c&&jsx("a",{className:"bbrn-release-button",href:c,target:"_blank",rel:"noopener noreferrer",children:"Open PR"}),t&&jsx("button",{type:"button",className:"bbrn-release-button bbrn-release-button-primary",onClick:()=>t(u),children:"Write the note"})]})]},u.pr.number)})}),!a&&e.length>n&&jsx("button",{type:"button",className:"bbrn-retry",onClick:()=>s(true),children:`Show all ${e.length}`})]})}function ro({facts:e,entries:t,pullRequests:n,onWriteNote:a,noteHref:s,onNavigate:l,appOrigin:u,currentOrigin:p,inHostApp:w,renderInternalLink:c,readinessHref:b,top:E,headingLevel:P=1,missingPageSize:f,className:h}){to(()=>{we();},[]);let{customer:m,internal:r,missing:d}=Ht(t,n),k=Vt({pullRequests:n.length,notes:t.length,missing:d.length,previousVersion:e.previous_version}),T=P+1,B=W=>jsx(On,{entry:W,href:s?.(W)??null,onNavigate:l,appOrigin:u,currentOrigin:p,inHostApp:w,renderInternalLink:c,headingLevel:T===4?4:T+1},W.id);return jsxs("div",{className:zn("bbrn-root bbrn-release",h),"data-bbrn-release":"",children:[jsxs("div",{className:"bbrn-release-main",children:[E,jsx(Un,{facts:e,summary:k,headingLevel:P}),jsxs("details",{className:"bbrn-release-facts-fold","data-bbrn-release-facts":"folded",children:[jsx("summary",{children:"Release facts"}),jsx(Jt,{facts:e,readinessHref:b,onNavigate:l,headingLevel:T})]}),jsx(gt,{title:Qe.customer,count:m.length,empty:Wt,headingLevel:T,children:jsx("div",{className:"bbrn-release-cards",children:m.map(B)})}),r.length>0&&jsx(gt,{title:Qe.internal,count:r.length,folded:true,headingLevel:T,children:jsx("div",{className:"bbrn-release-cards",children:r.map(B)})}),d.length>0&&jsx(gt,{title:Qe.missing,count:d.length,headingLevel:T,children:jsx(Dn,{pullRequests:d,onWriteNote:a,pageSize:f})})]}),jsx("aside",{className:"bbrn-release-rail","aria-label":"Release facts","data-bbrn-release-facts":"rail",children:jsx(Jt,{facts:e,readinessHref:b,onNavigate:l,headingLevel:T})})]})}var Yt="bbrn-announcements",Ve=new Map,Xt=new Set;function so(e,t){return `bbrn-announcements:${e}:${t??""}`}function ao(e){if(!e)return null;try{let t=JSON.parse(e);if(!t||t.v!==1||!Array.isArray(t.seen)||!Array.isArray(t.prompted))return null;let n=a=>a.filter(s=>typeof s=="string");return {v:1,seen:n(t.seen),prompted:n(t.prompted),muted:t.muted===!0}}catch{return null}}function Vn(e){if(Xt.has(e)&&Ve.has(e))return Ve.get(e);try{let t=ao(window.localStorage.getItem(e));return t&&Ve.set(e,t),t??Ve.get(e)??null}catch{return Ve.get(e)??null}}function Kn(e,t){let n={...t,seen:t.seen.slice(-500),prompted:t.prompted.slice(-500)};Ve.set(e,n);try{window.localStorage.setItem(e,JSON.stringify(n)),Xt.delete(e);}catch{Xt.add(e);}try{window.dispatchEvent(new CustomEvent(Yt,{detail:e}));}catch{}}var nt=(e,t)=>Array.from(new Set([...e,...t]));function yt({feed:e,viewer:t}){let n=e?.announcements==="badge"||e?.announcements==="badge_and_prompt"?e.announcements:"off",a=useMemo(()=>n==="off"?[]:(Array.isArray(e?.announced)?e.announced:e?.entries??[]).filter(k=>!!k&&typeof k.id=="string"&&!!k.announcement),[e,n]),s=e?so(e.tenant,t):null,[l,u]=useState(0);useEffect(()=>{if(!s)return;let k=B=>{B.detail===s&&u(W=>W+1);},T=B=>{(B.key===s||B.key===null)&&u(W=>W+1);};return window.addEventListener(Yt,k),window.addEventListener("storage",T),()=>{window.removeEventListener(Yt,k),window.removeEventListener("storage",T);}},[s]);let p=useMemo(()=>a.map(k=>k.id),[a]),w=useMemo(()=>s?Vn(s):null,[s,l]),c=useMemo(()=>{if(!s||!e)return null;if(w)return w;let k=p.slice(1);return {v:1,seen:k,prompted:k,muted:false}},[s,e,w,p]);useEffect(()=>{s&&c&&!w&&Kn(s,c);},[s,c,w]);let b=c?p.filter(k=>!c.seen.includes(k)).length:0,E=n==="badge_and_prompt"&&c&&!c.muted?a.find(k=>!c.prompted.includes(k.id))??null:null,P=useCallback(k=>{if(!s)return;let T=Vn(s)??c??{v:1,seen:[],prompted:[],muted:false};Kn(s,k(T));},[s,c]),f=useCallback(()=>P(k=>({...k,seen:nt(k.seen,p)})),[P,p]),h=useCallback(()=>P(k=>({...k,prompted:nt(k.prompted,p)})),[P,p]),m=E?.id??null,r=useCallback(()=>P(k=>({...k,prompted:nt(k.prompted,p),seen:m?nt(k.seen,[m]):k.seen})),[P,p,m]),d=useCallback(()=>P(k=>({...k,muted:true,prompted:nt(k.prompted,p)})),[P,p]);return {mode:n,announced:a,unseenCount:b,prompt:E,markAllSeen:f,dismiss:h,act:r,mute:d}}var Gn=useInsertionEffect??useLayoutEffect,ke=(...e)=>e.filter(Boolean).join(" ");function co({feed:e,viewer:t,theme:n,classNames:a}){Gn(()=>{we();},[]);let{unseenCount:s}=yt({feed:e,viewer:t}),l=useMemo(()=>Xe(n),[n]);if(s===0)return null;let u=`${s} new release note${s===1?"":"s"}`;return jsx("span",{className:ke("bbrn-root bbrn-whatsnew",a?.root),style:l,"aria-label":u,title:u,"data-bbrn-whatsnew":"",children:jsx("span",{"aria-hidden":"true",children:s})})}function uo({feed:e,viewer:t,onNavigate:n,theme:a,classNames:s,heading:l="What's new"}){Gn(()=>{we();},[]);let{prompt:u,dismiss:p,act:w,mute:c}=yt({feed:e,viewer:t}),b=useMemo(()=>Xe(a),[a]);if(!u)return null;let E=u.announcement?.cta??null,P=E?We(E.url):null,f=s??{},h=r=>{r.key==="Escape"&&(r.stopPropagation(),p());},m=r=>{P?.kind==="internal"&&n&&!r.defaultPrevented&&r.button===0&&!r.metaKey&&!r.ctrlKey&&!r.shiftKey&&!r.altKey&&(r.preventDefault(),n(P.href)),w();};return jsxs("section",{className:ke("bbrn-root bbrn-announcement",f.root),style:b,role:"status","aria-live":"polite","aria-label":l,onKeyDown:h,"data-entry-id":u.id,children:[jsx("p",{className:ke("bbrn-meta",f.meta),children:l}),jsx("p",{className:ke("bbrn-title",f.title),children:u.title}),jsxs("div",{className:ke("bbrn-links",f.links),children:[E&&P&&(P.kind==="external"?jsx("a",{className:ke("bbrn-link",f.link),href:P.href,target:"_blank",rel:"noopener noreferrer",onClick:m,children:E.label}):jsx("a",{className:ke("bbrn-link",f.link),href:P.href,onClick:m,children:E.label})),jsx("button",{type:"button",className:ke("bbrn-retry",f.retry),onClick:p,children:"Dismiss"}),jsx("button",{type:"button",className:ke("bbrn-retry",f.retry),onClick:c,children:"Don't show again"})]})]})}
73
- export{Dn as MissingReleaseNotes,Wt as NOTHING_CUSTOMER_FACING,It as RELEASE_NOTES_TOKENS,Gr as RELEASE_RANGE_UNAVAILABLE,Qe as RELEASE_SECTION_TITLES,Jt as ReleaseFacts,Un as ReleaseHeader,de as ReleaseNoteBody,On as ReleaseNoteCard,Ze as ReleaseNotePack,qr as ReleaseNotes,uo as ReleaseNotesAnnouncement,co as ReleaseNotesBadge,gt as ReleaseSection,ro as ReleaseView,Tr as TestRunWidget,Ft as findItLink,An as isCustomerFacing,Yr as missingNoteDraft,jt as releaseCommitUrl,Kt as releaseDeployedLine,qt as releaseRunUrl,Ht as releaseSections,Vt as releaseSummary,Ln as releaseTime,We as safeHref,_t as useDraggable,Et as useRealtimeRefresh,yt as useReleaseNoteAnnouncements,zt as useReleaseNotes,Ct as useTestRun,Lt as useWidgetAuth};
71
+ .bbrn-root .bbrn-retry{margin-left:8px;text-decoration:underline;background:none;border:0;padding:0;color:${Ce};cursor:pointer;font:inherit}
72
+ }`;function we(e=typeof document>"u"?void 0:document){if(!e?.head||e.head.querySelector("style[data-bbrn-styles]"))return;let t=e.createElement("style");t.setAttribute("data-bbrn-styles",""),t.textContent=Fr,e.head.prepend(t);}function Xe(e){if(!e)return;let t={};for(let n of Ft){let a=e[n];typeof a=="string"&&a.trim()&&(t[`--bbrn-${n}`]=a);}return Object.keys(t).length?t:void 0}var Ir=/^https:\/\/[^/?#\s\\*]+\/?$/;function It(e,t){let n=He(e);if(!n)return null;if(n.kind==="external")return {href:n.href,external:true};if(t.inHostApp)return {href:n.href,external:false};let a=t.appOrigin;if(typeof a!="string"||!Ir.test(a))return null;let s=a.replace(/\/$/,"");return t.currentOrigin&&s===t.currentOrigin?{href:n.href,external:false}:{href:`${s}${n.href}`,external:true}}var Dr=useInsertionEffect??useLayoutEffect,Hr=(...e)=>e.filter(Boolean).join(" "),he=e=>Array.isArray(e)&&e.length>0;function pt({label:e,level:t,children:n}){let a=`h${t}`;return jsxs("section",{className:"bbrn-pack-section","aria-label":e,children:[jsx(a,{className:"bbrn-pack-heading",children:e}),n]})}function We({label:e,children:t}){return jsxs("div",{className:"bbrn-pack-field",role:"group","aria-label":e,children:[jsx("span",{className:"bbrn-pack-label",children:e}),jsx("div",{className:"bbrn-pack-value",children:t})]})}function Ze({pack:e,appOrigin:t,currentOrigin:n,inHostApp:a,onNavigate:s,renderInternalLink:l,unresolvedHint:g,headingLevel:p=3,className:N}){Dr(()=>{we();},[]);let u=e.tour,f=u?It(u.find_it,{appOrigin:t,currentOrigin:n,inHostApp:a}):null,E=u?u.where??u.find_it:"",L=y=>r=>{!s||r.defaultPrevented||r.button!==0||r.metaKey||r.ctrlKey||r.shiftKey||r.altKey||(r.preventDefault(),s(y));},m=u?f?f.external?jsx("a",{className:"bbrn-link",href:f.href,target:"_blank",rel:"noopener noreferrer",children:E}):l?l(f.href,E):jsx("a",{className:"bbrn-link",href:f.href,onClick:L(f.href),children:E}):jsxs(Fragment,{children:[u.where&&jsxs(Fragment,{children:[u.where," \xB7 "]}),jsx("code",{className:"bbrn-code",children:u.find_it}),g&&jsx("span",{className:"bbrn-pack-hint",children:g})]}):null,x=e.before;return jsxs("div",{className:Hr("bbrn-root bbrn-pack",N),"data-bbrn-pack":e.category||void 0,children:[(he(x)||he(e.after))&&jsxs(pt,{label:"What changed",level:p,children:[he(x)&&jsx(We,{label:"Before",children:jsx(ce,{ast:x})}),he(e.after)&&jsx(We,{label:he(x)?"After":"Now",children:jsx(ce,{ast:e.after})})]}),he(e.benefit)&&jsx(pt,{label:"Why it matters",level:p,children:jsx(ce,{ast:e.benefit})}),he(e.ui)&&jsx(pt,{label:"Where it shows",level:p,children:jsx(ce,{ast:e.ui})}),u&&jsxs(pt,{label:"Try it",level:p,children:[jsx(We,{label:"Where to find it",children:m}),he(u.try)&&jsx(We,{label:"Try",children:jsx(ce,{ast:u.try})}),he(u.look_for)&&jsx(We,{label:"Look for",children:jsx(ce,{ast:u.look_for})}),he(u.watch)&&jsx(We,{label:"Watch out",children:jsx(ce,{ast:u.watch})})]})]})}function He(e){if(typeof e!="string"||/[\s\\]/.test(e))return null;if(e.startsWith("/"))return e.startsWith("//")?null:{kind:"internal",href:e};try{return new URL(e).protocol==="https:"?{kind:"external",href:e}:null}catch{return null}}function bt(e,t=""){return e.map((n,a)=>{let s=`${t}${a}`;switch(n.t){case "text":return n.v;case "code":return jsx("code",{className:"bbrn-code",children:n.v},s);case "strong":return jsx("strong",{children:bt(n.c,`${s}.`)},s);case "em":return jsx("em",{children:bt(n.c,`${s}.`)},s);default:return null}})}function ce({ast:e}){return jsx(Fragment,{children:e.map((t,n)=>t.t==="list"?jsx("ul",{className:"bbrn-list",children:t.items.map((a,s)=>jsx("li",{children:bt(a)},s))},n):t.t==="p"?jsx("p",{className:"bbrn-p",children:bt(t.c)},n):null)})}var O=(...e)=>e.filter(Boolean).join(" ");function Mn(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:`${t.toISOString().slice(0,16).replace("T"," ")} UTC`}var jr=useInsertionEffect??useLayoutEffect,Ot=class extends Component{constructor(){super(...arguments);this.state={failed:false,keys:this.props.resetKeys};}static getDerivedStateFromError(){return {failed:true}}static getDerivedStateFromProps(n,a){return n.resetKeys.length!==a.keys.length||n.resetKeys.some((l,g)=>!Object.is(l,a.keys[g]))?{failed:false,keys:n.resetKeys}:null}componentDidCatch(){}render(){return this.state.failed?this.props.fallback:this.props.children}};function qr(e,t,n=1){let a=Object.entries(t).filter(([,s])=>s).map(([s,l])=>`tag=${encodeURIComponent(`${s}:${l}`)}`);return n>1&&a.push(`page=${n}`),a.length===0?e:`${e}${e.includes("?")?"&":"?"}${a.join("&")}`}function Gr({endpoint:e,getToken:t,onNavigate:n,theme:a,classNames:s,components:l,timeoutMs:g}){jr(()=>{we();},[]);let[p,N]=useState({}),[u,f]=useState(1),E=M=>{f(1),N(M);},L=useMemo(()=>qr(e,p,u),[e,p,u]),{feed:m,error:x,loading:y,stale:r,reload:d}=zt({endpoint:L,getToken:t,timeoutMs:g}),[w,C]=useState(0),B=()=>{C(M=>M+1),d();},H=useMemo(()=>Xe(a),[a]),_=s??{},W=l?.Empty,xe=l?.Link,ue=M=>T=>{!n||T.defaultPrevented||T.button!==0||T.metaKey||T.ctrlKey||T.shiftKey||T.altKey||(T.preventDefault(),n(M));},v=Object.values(p).some(Boolean),$e=jsxs("p",{className:O("bbrn-status",_.status),role:"alert","data-bbrn-error":x??"render_failed",children:["Release notes could not be loaded.",jsx("button",{type:"button",className:O("bbrn-retry",_.retry),onClick:B,children:"Retry"}),v&&jsx("button",{type:"button",className:O("bbrn-retry",_.retry),onClick:()=>E({}),children:"Clear filters"})]});return jsxs("section",{className:O("bbrn-root",_.root),style:H,"aria-label":"Release notes","aria-busy":y,"data-bbrn-audience":m?.audience,children:[y&&!m&&jsx("p",{className:O("bbrn-status",_.status),role:"status",children:"Loading release notes\u2026"}),!y&&x&&!m&&$e,r&&jsxs("p",{className:O("bbrn-status",_.status),role:"status","data-bbrn-stale":"",children:["Showing the last loaded notes; they could not be refreshed.",jsx("button",{type:"button",className:O("bbrn-retry",_.retry),onClick:B,children:"Retry"})]}),m&&jsxs(Ot,{resetKeys:[m,W,xe,w],fallback:$e,children:[m.audience==="internal"&&m.notice&&jsx("p",{className:O("bbrn-status",_.status),role:"status","data-bbrn-notice":"production-freshness",children:m.notice}),(m.filters?.length??0)>0&&jsx("div",{className:O("bbrn-filters",_.filters),role:"group","aria-label":"Filter release notes",children:m.filters.map(M=>jsxs("label",{className:O("bbrn-filter",_.filter),"data-bbrn-filter":M.group,children:[M.label,jsxs("select",{value:p[M.group]??"",onChange:T=>{let V=T.target.value;E(Q=>({...Q,[M.group]:V}));},children:[jsx("option",{value:"",children:"All"}),M.values.map(T=>jsx("option",{value:T,children:T},T))]})]},M.group))}),m.entries.length===0&&v&&jsx("p",{className:O("bbrn-status",_.status),children:"No release notes match these filters."}),m.entries.length===0&&!v&&(W?jsx(W,{}):m.audience==="external"?jsx("p",{className:O("bbrn-status",_.status),children:"Nothing new yet."}):jsxs("p",{className:O("bbrn-status",_.status),children:["No release notes yet. Submit one with ",jsx("code",{className:"bbrn-code",children:"bb release-notes submit"}),"."]})),m.entries.map(M=>{let T="source_key"in M?M:null;return jsxs("article",{className:O("bbrn-entry",_.entry),"data-entry-id":M.id,"data-source-key":T?.source_key,children:[jsxs("div",{className:O("bbrn-head",_.head),children:[jsx("h2",{className:O("bbrn-title",_.title),children:M.title}),jsx("span",{className:O("bbrn-badge",_.badge),"data-bbrn-type":M.type,children:M.type}),T&&jsx("span",{className:O("bbrn-badge",_.badge),"data-bbrn-state":T.state,children:T.state_copy??T.state}),T&&jsxs("span",{className:O("bbrn-meta",_.meta),children:[T.source_key," \xB7 revision ",T.revision]}),T?.delivery_copy&&jsxs("span",{className:O("bbrn-delivery",_.delivery),"data-bbrn-delivery":T.delivery_badge,children:[T.delivery_copy,T.delivery_since&&jsxs(Fragment,{children:[" \xB7 since ",jsx("time",{dateTime:T.delivery_since,children:Mn(T.delivery_since)})]})]}),!T&&"version"in M&&M.version&&jsxs("span",{className:O("bbrn-delivery",_.delivery),"data-bbrn-delivery":"released",children:["Released in ",M.version,M.released_at&&jsxs(Fragment,{children:[" \xB7 ",jsx("time",{dateTime:M.released_at,children:Mn(M.released_at)})]})]})]}),jsx("div",{className:O("bbrn-body",_.body),children:jsx(ce,{ast:M.body.ast})}),(M.tags?.length??0)>0&&jsx("ul",{className:O("bbrn-tags",_.tags),"aria-label":"Tags",children:M.tags.map(V=>jsx("li",{className:O("bbrn-tag",_.tag),"data-bbrn-tag-group":V.group,title:V.label,children:V.value},`${V.group}:${V.value}`))}),T?.pack&&m.audience==="internal"&&jsxs("details",{className:"bbrn-pack-details",children:[jsx("summary",{className:"bbrn-pack-summary",children:"What changed \xB7 Try it"}),jsx(Ze,{pack:T.pack,inHostApp:true,onNavigate:n,className:_.pack})]}),M.links.length>0&&jsx("div",{className:O("bbrn-links",_.links),children:M.links.map((V,Q)=>{let ee=He(V.url);if(!ee)return null;let me=O("bbrn-link",_.link),ie=V.kind??null;return xe?jsx(xe,{href:ee.href,external:ee.kind==="external",kind:ie,className:me,onClick:ee.kind==="internal"&&n?ue(ee.href):void 0,children:V.name},Q):ee.kind==="external"?jsx("a",{className:me,href:ee.href,target:"_blank",rel:"noopener noreferrer","data-link-kind":ie??void 0,children:V.name},Q):jsx("a",{className:me,href:ee.href,onClick:ue(ee.href),"data-link-kind":ie??void 0,children:V.name},Q)})})]},M.id)}),m.audience==="external"&&(m.page>1||m.next_page!==null)&&jsxs("nav",{className:O("bbrn-pager",_.pager),"aria-label":"Release note pages",children:[m.page>1&&jsx("button",{type:"button",className:O("bbrn-retry",_.retry),onClick:()=>f(m.page-1),children:"Newer notes"}),m.next_page!==null&&jsx("button",{type:"button",className:O("bbrn-retry",_.retry),onClick:()=>f(m.next_page),children:"Older notes"})]})]})]})}var Qe={customer:"Customer-facing",internal:"Internal",missing:"Missing a release note"},Ht="Nothing customer-facing in this release.",Yr="BotBuddy could not read this release's range from GitHub.";function An(e){let t=e;return t.audience==="external"?true:t.audience==="internal"?false:t.customer_facing===true}function Wt(e,t){let n=[],a=[];for(let s of e)(An(s)?n:a).push(s);return {customer:n,internal:a,missing:t.filter(s=>!s.has_note)}}var Pn=(e,t,n)=>`${e} ${e===1?t:n}`;function Vt(e){return e.pullRequests===0&&e.notes===0?`No changes since ${e.previousVersion}.`:e.notes===0&&e.missing>0?e.missing===1?"This release's pull request has no release note yet.":`None of this release's ${e.missing} pull requests has a release note yet.`:[Pn(e.pullRequests,"pull request","pull requests"),Pn(e.notes,"release note","release notes"),`${e.missing} missing`].join(" \xB7 ")}var Jr=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Ln(e){if(!e)return null;let t=new Date(e);if(Number.isNaN(t.getTime()))return null;let n=a=>String(a).padStart(2,"0");return `${t.getUTCDate()} ${Jr[t.getUTCMonth()]} ${t.getUTCFullYear()}, ${n(t.getUTCHours())}:${n(t.getUTCMinutes())} UTC`}function Kt(e){if(e.candidate)return `Candidate for ${e.environment} \xB7 not released yet`;let t=Ln(e.live_at);return t?`Deployed to ${e.environment} \xB7 ${t}`:`Deployed to ${e.environment}`}var Bn=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;function jt(e){return Bn.test(e.repository)&&/^[0-9a-f]{7,40}$/i.test(e.commit_sha)?`https://github.com/${e.repository}/commit/${e.commit_sha}`:null}function qt(e){return e.run_id&&/^\d+$/.test(e.run_id)&&Bn.test(e.repository)?`https://github.com/${e.repository}/actions/runs/${e.run_id}`:null}function Xr(e,t){let n=e.tickets[0]?.key??`${t}#${e.pr.number}`;return JSON.stringify({schema_version:1,source_key:n,type:"Feature",change:{repository:t,pr_number:e.pr.number},internal:{title:e.pr.title,body:"What changed and why, for the team. Rewrite this from the diff."}},null,2)}var no=useInsertionEffect??useLayoutEffect,zn=(...e)=>e.filter(Boolean).join(" "),et=({level:e,className:t,id:n,children:a})=>{let s=`h${e}`;return jsx(s,{id:n,className:t,children:a})},Fn=e=>typeof e=="string"&&e.startsWith("https://")?e:null;function In(e){return !(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)}function Gt({href:e,children:t,className:n}){let a=Fn(e);return a?jsx("a",{className:zn("bbrn-link",n),href:a,target:"_blank",rel:"noopener noreferrer",children:t}):jsx("span",{className:n,children:t})}function Un({facts:e,summary:t,headingLevel:n=1}){return jsxs("header",{className:"bbrn-release-header",children:[jsx(et,{level:n,className:"bbrn-release-version",children:e.version}),jsx("p",{className:"bbrn-release-deployed",children:Kt(e)}),jsx("p",{className:"bbrn-release-summary","data-bbrn-release-summary":"",children:t})]})}function Yt({facts:e,readinessHref:t,onNavigate:n,headingLevel:a=2}){let s=jt(e),l=qt(e),g=p=>N=>{!n||!In(N)||(N.preventDefault(),n(p));};return jsxs(Fragment,{children:[jsx(et,{level:a,className:"bbrn-release-facts-heading",children:"Release facts"}),jsxs("dl",{className:"bbrn-release-facts",children:[jsx("dt",{children:"Repository"}),jsx("dd",{className:"bbrn-id",children:e.repository}),jsx("dt",{children:"Environment"}),jsx("dd",{children:e.environment}),jsx("dt",{children:"Commit"}),jsx("dd",{className:"bbrn-id",children:jsx(Gt,{href:s,children:e.commit_sha.slice(0,7)})}),e.run_id&&jsxs(Fragment,{children:[jsx("dt",{children:"Run"}),jsx("dd",{className:"bbrn-id",children:jsx(Gt,{href:l,children:e.run_id})})]}),jsx("dt",{children:"Since"}),jsx("dd",{className:"bbrn-id",children:e.previous_version}),t&&jsxs(Fragment,{children:[jsx("dt",{children:"Readiness"}),jsx("dd",{children:jsx("a",{className:"bbrn-link",href:t,onClick:g(t),children:"Open"})})]})]})]})}function gt({title:e,count:t,folded:n=false,empty:a,headingLevel:s=2,children:l}){let g=useId(),p=`${e} (${t})`,N=t===0&&a?jsx("p",{className:"bbrn-release-empty",children:a}):l;return n?jsx("section",{className:"bbrn-release-section","aria-labelledby":g,"data-bbrn-release-section":e,children:jsxs("details",{className:"bbrn-release-fold",children:[jsx("summary",{children:jsx(et,{level:s,id:g,className:"bbrn-release-section-heading",children:p})}),N]})}):jsxs("section",{className:"bbrn-release-section","aria-labelledby":g,"data-bbrn-release-section":e,children:[jsx(et,{level:s,id:g,className:"bbrn-release-section-heading",children:p}),N]})}function ro(e){let t=e.pull_requests;return Array.isArray(t)?t.flatMap(n=>typeof n?.number=="number"?[n.number]:[]):[]}function On({entry:e,href:t,onNavigate:n,appOrigin:a,currentOrigin:s,inHostApp:l,renderInternalLink:g,headingLevel:p=3}){let N=[e.source_key,...ro(e).map(f=>`#${f}`)].join(" \xB7 "),u=f=>E=>{!n||!In(E)||(E.preventDefault(),n(f));};return jsxs("article",{className:"bbrn-release-card","data-entry-id":e.id,"data-source-key":e.source_key,children:[jsxs("div",{className:"bbrn-release-card-head",children:[jsx("span",{className:"bbrn-release-type","data-bbrn-type":e.type,children:e.type}),jsx("span",{className:"bbrn-id",children:N})]}),jsx(et,{level:p,className:"bbrn-title",children:t?jsx("a",{href:t,onClick:u(t),children:e.title}):e.title}),e.pack?jsx(Ze,{pack:e.pack,headingLevel:p===4?4:p+1,appOrigin:a,currentOrigin:s,inHostApp:l,onNavigate:n,renderInternalLink:g}):jsx("div",{className:"bbrn-release-card-body",children:jsx(ce,{ast:e.body.ast})})]})}function Dn({pullRequests:e,onWriteNote:t,pageSize:n=50}){let[a,s]=useState(false),l=a?e:e.slice(0,n);return jsxs(Fragment,{children:[jsx("ul",{className:"bbrn-release-missing",children:l.map(g=>{let p=g.project?g.project.percent_complete===null?g.project.id:`${g.project.id} (${Math.round(g.project.percent_complete)}%)`:null,N=[p&&jsx(Gt,{href:g.project.url,children:p},"project"),g.author?.label&&jsx("span",{children:g.author.label},"author")].filter(Boolean),u=Fn(g.pr.url);return jsxs("li",{className:"bbrn-release-missing-row","data-pr-number":g.pr.number,children:[jsxs("div",{className:"bbrn-release-missing-text",children:[jsx("span",{className:"bbrn-id",children:[`#${g.pr.number}`,...g.tickets.map(f=>f.key)].join(" \xB7 ")}),jsx("span",{className:"bbrn-release-missing-title",children:g.pr.title}),N.length>0&&jsx("span",{className:"bbrn-meta",children:N.flatMap((f,E)=>E===0?[f]:[" \xB7 ",f])})]}),jsxs("div",{className:"bbrn-release-actions",children:[u&&jsx("a",{className:"bbrn-release-button",href:u,target:"_blank",rel:"noopener noreferrer",children:"Open PR"}),t&&jsx("button",{type:"button",className:"bbrn-release-button bbrn-release-button-primary",onClick:()=>t(g),children:"Write the note"})]})]},g.pr.number)})}),!a&&e.length>n&&jsx("button",{type:"button",className:"bbrn-retry",onClick:()=>s(true),children:`Show all ${e.length}`})]})}function oo({facts:e,entries:t,pullRequests:n,onWriteNote:a,noteHref:s,onNavigate:l,appOrigin:g,currentOrigin:p,inHostApp:N,renderInternalLink:u,readinessHref:f,top:E,headingLevel:L=1,missingPageSize:m,className:x}){no(()=>{we();},[]);let{customer:y,internal:r,missing:d}=Wt(t,n),w=Vt({pullRequests:n.length,notes:t.length,missing:d.length,previousVersion:e.previous_version}),C=L+1,B=H=>jsx(On,{entry:H,href:s?.(H)??null,onNavigate:l,appOrigin:g,currentOrigin:p,inHostApp:N,renderInternalLink:u,headingLevel:C===4?4:C+1},H.id);return jsxs("div",{className:zn("bbrn-root bbrn-release",x),"data-bbrn-release":"",children:[jsxs("div",{className:"bbrn-release-main",children:[E,jsx(Un,{facts:e,summary:w,headingLevel:L}),jsxs("details",{className:"bbrn-release-facts-fold","data-bbrn-release-facts":"folded",children:[jsx("summary",{children:"Release facts"}),jsx(Yt,{facts:e,readinessHref:f,onNavigate:l,headingLevel:C})]}),jsx(gt,{title:Qe.customer,count:y.length,empty:Ht,headingLevel:C,children:jsx("div",{className:"bbrn-release-cards",children:y.map(B)})}),r.length>0&&jsx(gt,{title:Qe.internal,count:r.length,folded:true,headingLevel:C,children:jsx("div",{className:"bbrn-release-cards",children:r.map(B)})}),d.length>0&&jsx(gt,{title:Qe.missing,count:d.length,headingLevel:C,children:jsx(Dn,{pullRequests:d,onWriteNote:a,pageSize:m})})]}),jsx("aside",{className:"bbrn-release-rail","aria-label":"Release facts","data-bbrn-release-facts":"rail",children:jsx(Yt,{facts:e,readinessHref:f,onNavigate:l,headingLevel:C})})]})}var Jt="bbrn-announcements",Ve=new Map,Xt=new Set;function ao(e,t){return `bbrn-announcements:${e}:${t??""}`}function io(e){if(!e)return null;try{let t=JSON.parse(e);if(!t||t.v!==1||!Array.isArray(t.seen)||!Array.isArray(t.prompted))return null;let n=a=>a.filter(s=>typeof s=="string");return {v:1,seen:n(t.seen),prompted:n(t.prompted),muted:t.muted===!0}}catch{return null}}function Vn(e){if(Xt.has(e)&&Ve.has(e))return Ve.get(e);try{let t=io(window.localStorage.getItem(e));return t&&Ve.set(e,t),t??Ve.get(e)??null}catch{return Ve.get(e)??null}}function Kn(e,t){let n={...t,seen:t.seen.slice(-500),prompted:t.prompted.slice(-500)};Ve.set(e,n);try{window.localStorage.setItem(e,JSON.stringify(n)),Xt.delete(e);}catch{Xt.add(e);}try{window.dispatchEvent(new CustomEvent(Jt,{detail:e}));}catch{}}var nt=(e,t)=>Array.from(new Set([...e,...t]));function yt({feed:e,viewer:t}){let n=e?.announcements==="badge"||e?.announcements==="badge_and_prompt"?e.announcements:"off",a=useMemo(()=>n==="off"?[]:(Array.isArray(e?.announced)?e.announced:e?.entries??[]).filter(w=>!!w&&typeof w.id=="string"&&!!w.announcement),[e,n]),s=e?ao(e.tenant,t):null,[l,g]=useState(0);useEffect(()=>{if(!s)return;let w=B=>{B.detail===s&&g(H=>H+1);},C=B=>{(B.key===s||B.key===null)&&g(H=>H+1);};return window.addEventListener(Jt,w),window.addEventListener("storage",C),()=>{window.removeEventListener(Jt,w),window.removeEventListener("storage",C);}},[s]);let p=useMemo(()=>a.map(w=>w.id),[a]),N=useMemo(()=>s?Vn(s):null,[s,l]),u=useMemo(()=>{if(!s||!e)return null;if(N)return N;let w=p.slice(1);return {v:1,seen:w,prompted:w,muted:false}},[s,e,N,p]);useEffect(()=>{s&&u&&!N&&Kn(s,u);},[s,u,N]);let f=u?p.filter(w=>!u.seen.includes(w)).length:0,E=n==="badge_and_prompt"&&u&&!u.muted?a.find(w=>!u.prompted.includes(w.id))??null:null,L=useCallback(w=>{if(!s)return;let C=Vn(s)??u??{v:1,seen:[],prompted:[],muted:false};Kn(s,w(C));},[s,u]),m=useCallback(()=>L(w=>({...w,seen:nt(w.seen,p)})),[L,p]),x=useCallback(()=>L(w=>({...w,prompted:nt(w.prompted,p)})),[L,p]),y=E?.id??null,r=useCallback(()=>L(w=>({...w,prompted:nt(w.prompted,p),seen:y?nt(w.seen,[y]):w.seen})),[L,p,y]),d=useCallback(()=>L(w=>({...w,muted:true,prompted:nt(w.prompted,p)})),[L,p]);return {mode:n,announced:a,unseenCount:f,prompt:E,markAllSeen:m,dismiss:x,act:r,mute:d}}var Gn=useInsertionEffect??useLayoutEffect,ke=(...e)=>e.filter(Boolean).join(" ");function uo({feed:e,viewer:t,theme:n,classNames:a}){Gn(()=>{we();},[]);let{unseenCount:s}=yt({feed:e,viewer:t}),l=useMemo(()=>Xe(n),[n]);if(s===0)return null;let g=`${s} new release note${s===1?"":"s"}`;return jsx("span",{className:ke("bbrn-root bbrn-whatsnew",a?.root),style:l,"aria-label":g,title:g,"data-bbrn-whatsnew":"",children:jsx("span",{"aria-hidden":"true",children:s})})}function po({feed:e,viewer:t,onNavigate:n,theme:a,classNames:s,heading:l="What's new"}){Gn(()=>{we();},[]);let{prompt:g,dismiss:p,act:N,mute:u}=yt({feed:e,viewer:t}),f=useMemo(()=>Xe(a),[a]);if(!g)return null;let E=g.announcement?.cta??null,L=E?He(E.url):null,m=s??{},x=r=>{r.key==="Escape"&&(r.stopPropagation(),p());},y=r=>{L?.kind==="internal"&&n&&!r.defaultPrevented&&r.button===0&&!r.metaKey&&!r.ctrlKey&&!r.shiftKey&&!r.altKey&&(r.preventDefault(),n(L.href)),N();};return jsxs("section",{className:ke("bbrn-root bbrn-announcement",m.root),style:f,role:"status","aria-live":"polite","aria-label":l,onKeyDown:x,"data-entry-id":g.id,children:[jsx("p",{className:ke("bbrn-meta",m.meta),children:l}),jsx("p",{className:ke("bbrn-title",m.title),children:g.title}),jsxs("div",{className:ke("bbrn-links",m.links),children:[E&&L&&(L.kind==="external"?jsx("a",{className:ke("bbrn-link",m.link),href:L.href,target:"_blank",rel:"noopener noreferrer",onClick:y,children:E.label}):jsx("a",{className:ke("bbrn-link",m.link),href:L.href,onClick:y,children:E.label})),jsx("button",{type:"button",className:ke("bbrn-retry",m.retry),onClick:p,children:"Dismiss"}),jsx("button",{type:"button",className:ke("bbrn-retry",m.retry),onClick:u,children:"Don't show again"})]})]})}
73
+ export{Dn as MissingReleaseNotes,Ht as NOTHING_CUSTOMER_FACING,Ft as RELEASE_NOTES_TOKENS,Yr as RELEASE_RANGE_UNAVAILABLE,Qe as RELEASE_SECTION_TITLES,Yt as ReleaseFacts,Un as ReleaseHeader,ce as ReleaseNoteBody,On as ReleaseNoteCard,Ze as ReleaseNotePack,Gr as ReleaseNotes,po as ReleaseNotesAnnouncement,uo as ReleaseNotesBadge,gt as ReleaseSection,oo as ReleaseView,Tr as TestRunWidget,It as findItLink,An as isCustomerFacing,Xr as missingNoteDraft,jt as releaseCommitUrl,Kt as releaseDeployedLine,qt as releaseRunUrl,Wt as releaseSections,Vt as releaseSummary,Ln as releaseTime,He as safeHref,_t as useDraggable,Et as useRealtimeRefresh,yt as useReleaseNoteAnnouncements,zt as useReleaseNotes,Tt as useTestRun,Lt as useWidgetAuth};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botbuddy/react",
3
- "version": "0.26.0",
3
+ "version": "0.28.0",
4
4
  "description": "BotBuddy test coordination widgets for React — draggable, translucent overlays for human-in-the-loop QA",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",