@botbuddy/react 0.11.0 → 0.12.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/CHANGELOG.md +15 -0
- package/dist/index.cjs +14 -2
- package/dist/index.d.cts +78 -1
- package/dist/index.d.ts +78 -1
- package/dist/index.js +14 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @botbuddy/react — Changelog
|
|
2
2
|
|
|
3
|
+
## 0.12.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **`ReleaseNotes` component and `useReleaseNotes` hook (BOT-3156).** Props:
|
|
8
|
+
`endpoint` (the BotBuddy release-notes feed URL), `getToken` (returns the
|
|
9
|
+
bearer) and optional `onNavigate` (receives app paths). Note bodies arrive as a
|
|
10
|
+
`bbrn-md-1` syntax tree and render as React elements; there is no raw-HTML
|
|
11
|
+
path. https links open in a new tab with `rel="noopener noreferrer"`; a link
|
|
12
|
+
that starts with one `/` calls `onNavigate` (plain clicks only) so the host
|
|
13
|
+
app routes it; any other link is not rendered. An empty feed shows "No release
|
|
14
|
+
notes yet."; a refused or unreachable feed shows "Release notes could not be
|
|
15
|
+
loaded." with a Retry button. Neither throws. `safeHref` and
|
|
16
|
+
`ReleaseNoteBody` are exported too. Styling props are a later release.
|
|
17
|
+
|
|
3
18
|
## 0.11.0
|
|
4
19
|
|
|
5
20
|
### Added
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
'use strict';var react=require('react'),reactDom=require('react-dom'),jsxRuntime=require('react/jsx-runtime');var Se=8;function Ve(e,r,s,p,u,a){let T=Math.max(Se,u-s-Se),S=Math.max(Se,a-p-Se);return {x:Math.min(Math.max(e,Se),T),y:Math.min(Math.max(r,Se),S)}}function Ye(e,r){let[s,p]=react.useState({x:e,y:r}),u=react.useRef(false),a=react.useRef({x:0,y:0}),T=react.useRef(false),S=react.useCallback(y=>{u.current=true,T.current=false,a.current={x:y.clientX-s.x,y:y.clientY-s.y},y.target.setPointerCapture(y.pointerId);},[s]),_=react.useCallback(y=>{u.current&&(T.current=true,p({x:y.clientX-a.current.x,y:y.clientY-a.current.y}));},[]),b=react.useCallback(()=>{u.current=false;},[]);return {pos:s,setPos:p,onPointerDown:S,onPointerMove:_,onPointerUp:b,didDrag:T}}function Je(e,r,s){let p=react.useRef(s);p.current=s,react.useEffect(()=>{if(!r)return;if(e.supabaseUrl){let a=false,T=null,S=()=>{a||T||(T=setInterval(()=>p.current(),15e3));},_=null;try{let m=new URL(e.supabaseUrl),n=["localhost","127.0.0.1","::1"].includes(m.hostname);if(m.protocol==="http:"&&!n)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");m.protocol=m.protocol==="https:"?"wss:":"ws:",_=m.toString().replace(/\/$/,"");}catch{S();}let b=null,y=null,F=null,Y=0,M=()=>{if(!(a||!_)){try{b=new WebSocket(`${_}/realtime/v1/websocket?apikey=${e.anonKey}&vsn=1.0.0`);}catch{S();return}b.onopen=()=>{if(a||!b)return;let m={topic:`realtime:public:test_run_cases:test_run_id=eq.${r}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_run_cases",filter:`test_run_id=eq.${r}`}]}},ref:String(++Y)};b.send(JSON.stringify(m));let n={topic:`realtime:public:test_runs:id=eq.${r}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_runs",filter:`id=eq.${r}`}]}},ref:String(++Y)};b.send(JSON.stringify(n)),y=setInterval(()=>{b?.readyState===WebSocket.OPEN&&b.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++Y)}));},3e4);},b.onmessage=m=>{try{JSON.parse(m.data).event==="postgres_changes"&&p.current();}catch{}},b.onclose=()=>{x(),a||(F=setTimeout(M,3e3));},b.onerror=()=>{b?.close();};}},x=()=>{y&&(clearInterval(y),y=null);};return M(),()=>{a=true,x(),F&&clearTimeout(F),T&&clearInterval(T),b&&(b.onclose=null,b.onerror=null,b.close());}}let u=setInterval(()=>p.current(),15e3);return ()=>clearInterval(u)},[e.supabaseUrl,e.anonKey,r]);}var Vt="botbuddy:created-test-run:";function Yt(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function Jt(e){return `${Vt}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",Yt(e.targetUrl),e.branchName||""].join("|"))}`}function Ae(e,r){let s={apikey:e.anonKey};return r?s.Authorization=`Bearer ${r}`:e.apiKey?s.Authorization=`Bearer ${e.apiKey}`:s.Authorization=`Bearer ${e.anonKey}`,s}async function qt(e){if(e)return e;try{let r=await fetch("/.botbuddy-token",{cache:"no-store"});if(r.ok){let s=(await r.text()).trim();if(s.startsWith("public_"))return s}}catch{}try{let r=undefined?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(r&&typeof r=="string"&&r.startsWith("public_"))return r}catch{}return null}function Ge(e){let[r,s]=react.useState(null),[p,u]=react.useState("loading"),a=Jt(e),[T,S]=react.useState(()=>{if(e.testRunId)return e.testRunId;try{return localStorage.getItem(a)||void 0}catch{return}}),_=e.testRunId||T,b=react.useCallback(x=>{if(s(x),!!x?.id){S(x.id);try{localStorage.setItem(a,x.id);}catch{}}},[a]),y=react.useCallback(async()=>{try{let x=await qt(e.testRunToken);if(!x&&!_){u("no-match"),s(null);return}if(x&&!e.ticketId){u("no-match"),s(null);return}let m=new URLSearchParams;x&&m.set("token",x),e.ticketId&&m.set("ticket_id",e.ticketId),m.set("app_slug",e.appSlug),e.environment&&m.set("environment",e.environment),_&&m.set("test_run_id",_),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 n=await fetch(`${e.config.serverUrl}/widget/test-run?${m.toString()}`,{headers:Ae(e.config,e.authToken)});if(n.status===404){u("no-match"),s(null);return}if(n.status===401||n.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),u("error");return}if(!n.ok){u("error");return}let d=await n.json();if(!d||d.run===null){u("no-match"),s(null);return}b(d),u(d.status==="completed"?"completed":"ready");}catch{u("error");}},[e.config.serverUrl,e.config.anonKey,e.config.apiKey,e.authToken,e.appSlug,e.environment,e.ticketId,_,e.testRunToken,e.targetUrl,e.version,e.commitSha,e.branchName,e.prNumber,e.onAuthExpired,b]);return react.useEffect(()=>{y();},[y]),Je(e.config,r?.id,y),{run:r,widgetState:p,fetchRun:y,setVerdict:async(x,m,n,d="human")=>(s(U=>{if(!U)return null;let J=U.test_cases.map(I=>I.id===x?{...I,verdict:m,fail_reason:m==="fail"&&n||null,verdict_by_display_name:d,verdict_at:new Date().toISOString()}:I),j={total:J.length,pending:0,pass:0,fail:0,skip:0};return J.forEach(I=>{I.verdict in j&&j[I.verdict]++;}),{...U,test_cases:J,summary:j}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${x}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...Ae(e.config,e.authToken)},body:JSON.stringify({verdict:m,fail_reason:n,display_name:d})})).ok),markComplete:async()=>r?(s(m=>m?{...m,status:"completed"}:null),u("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${r.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...Ae(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!r)return false;let x=await fetch(`${e.config.serverUrl}/widget/test-runs/${r.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...Ae(e.config,e.authToken)}});return x.ok&&y(),x.ok},setRun:b}}var Qe="botbuddy-widget-auth-token",et="botbuddy-widget-auth-name";function Re(e){if(!e)return null;try{let r=e.split(".")[1];if(!r)return null;let s=r.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(r.length/4)*4,"="),p=atob(s),u=JSON.parse(p);return typeof u.exp=="number"?u.exp*1e3:null}catch{return null}}var Xt=2500,Zt=6e4;function tt(e){let[r,s]=react.useState(()=>{try{return localStorage.getItem(Qe)}catch(M){return console.warn("Unable to read BotBuddy widget auth token",M),null}}),[p,u]=react.useState(()=>{try{return localStorage.getItem(et)}catch(M){return console.warn("Unable to read BotBuddy widget display name",M),null}}),a=react.useRef(null),T=react.useCallback((M,x)=>{s(M),x&&u(x);try{localStorage.setItem(Qe,M),x&&localStorage.setItem(et,x);}catch(m){console.warn("Unable to persist BotBuddy widget auth token",m);}},[]);react.useEffect(()=>{let M=new URL(e).origin,x=m=>{m.origin===M&&m.data?.type==="botbuddy-widget-auth"&&m.data.token&&T(m.data.token,m.data.displayName||"human");};return window.addEventListener("message",x),()=>window.removeEventListener("message",x)},[e,T]);let S=react.useCallback(()=>{if(a.current)return a.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 m=new Promise(n=>{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 V=false,U=()=>{window.removeEventListener("message",J),clearTimeout(j);try{d.remove();}catch{}a.current=null;},J=I=>{if(I.origin===M){if(I.data?.type==="botbuddy-widget-auth-failed"){if(V)return;V=true,n(null),U();return}I.data?.type!=="botbuddy-widget-auth"||!I.data.token||V||(V=true,n(String(I.data.token)),U());}},j=setTimeout(()=>{V||(V=true,n(null),U());},Xt);window.addEventListener("message",J),document.body.appendChild(d);});return a.current=m,m},[e]);react.useEffect(()=>{if(!r)return;let M=Re(r);if(!M)return;let x=M-Date.now()-Zt,m=window.setTimeout(()=>{S();},Math.max(0,x));return ()=>window.clearTimeout(m)},[r,S]);let _=react.useCallback(()=>{let M=new URL("/widget-auth",e);M.searchParams.set("origin",window.location.origin);let x=420,m=520,n=window.screenX+(window.innerWidth-x)/2,d=window.screenY+(window.innerHeight-m)/2;window.open(M.toString(),"botbuddy-auth",`width=${x},height=${m},left=${n},top=${d},popup=yes`);},[e]),[,b]=react.useState(0);react.useEffect(()=>{let M=Re(r);if(!M)return;let x=M-Date.now();if(x<=0)return;let m=window.setTimeout(()=>b(n=>n+1),x);return ()=>window.clearTimeout(m)},[r]);let y=react.useCallback(()=>{s(null),u(null);try{localStorage.removeItem(Qe),localStorage.removeItem(et);}catch(M){console.warn("Unable to clear BotBuddy widget auth token",M);}},[]),F=Re(r),Y=F!==null&&F<=Date.now();return {token:r,displayName:p,isAuthenticated:!!r,isExpired:Y,openLogin:_,refreshNow:S,logout:y}}var We=null;function Qt(){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 Ie(){return We||(We=(async()=>{if(typeof fetch>"u")return null;try{let e=await fetch(Qt(),{cache:"no-store"});if(!e.ok)return null;let r=await e.json();if(!r||typeof r!="object"||Array.isArray(r))return null;let s={};for(let[p,u]of Object.entries(r))typeof u=="string"&&u.length>0&&(s[p]=u);return s}catch{return null}})(),We)}async function Mt(e){return (await Ie())?.[e]??null}function en(e){let r=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),s="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",p=[],u=0,a=0;for(let T of r){let S=s.indexOf(T);if(S<0)throw new Error("Invalid Base32 character in TOTP secret");a=a<<5|S,u+=5,u>=8&&(u-=8,p.push(a>>>u&255));}return Uint8Array.from(p)}async function Ct(e,r=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let s=en(e),p=new Uint8Array(s.byteLength);p.set(s);let u=Math.floor(r/1e3/30),a=new Uint8Array(8),T=Math.floor(u/4294967296),S=u>>>0;a[0]=T>>>24&255,a[1]=T>>>16&255,a[2]=T>>>8&255,a[3]=T&255,a[4]=S>>>24&255,a[5]=S>>>16&255,a[6]=S>>>8&255,a[7]=S&255;let _=await crypto.subtle.importKey("raw",p,{name:"HMAC",hash:"SHA-1"},false,["sign"]),b=await crypto.subtle.sign("HMAC",_,a),y=new Uint8Array(b),F=y[y.length-1]&15;return (((y[F]&127)<<24|(y[F+1]&255)<<16|(y[F+2]&255)<<8|y[F+3]&255)%1e6).toString().padStart(6,"0")}var Tt="0.11.0";function nn(e){let r=new Date(e),p=Date.now()-r.getTime();if(p<6e4)return "just now";if(p<36e5)return `${Math.floor(p/6e4)}m ago`;if(p<864e5)return `${Math.floor(p/36e5)}h ago`;let u=r.getDate(),a=r.toLocaleString("en",{month:"short"}),T=r.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${a} ${u}, ${T}`}var w=({d:e,className:r,size:s=14})=>jsxRuntime.jsx("svg",{className:r,width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:e})}),h={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 rn(){let[e,r]=react.useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return react.useEffect(()=>{if(typeof window>"u")return;let s=document.documentElement,p=()=>s.classList.contains("dark")?"dark":s.classList.contains("light")?"light":null,u=p();u&&r(u);let a=window.matchMedia("(prefers-color-scheme: dark)"),T=_=>{let b=p();r(b||(_.matches?"dark":"light"));};a.addEventListener("change",T);let S=new MutationObserver(()=>{let _=p();r(_||(a.matches?"dark":"light"));});return S.observe(s,{attributes:true,attributeFilter:["class"]}),()=>{a.removeEventListener("change",T),S.disconnect();}},[]),e}function on(e){let r=e==="dark";return {bg:r?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:r?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:r?"#e5e5e5":"#1a1a1a",textMuted:r?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:r?"#555":"#999",border:r?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:r?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:r?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:r?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:r?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:r?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:r?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:r?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:r?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:r?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:r?"#888":"#aaa",btnHover:r?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var sn={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},an={pending:h.circle,pass:h.check,fail:h.x,skip:h.skip},Rt={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)"}},ln=["app.supply-guard.io"];function dn(e,r=[]){if(!e)return false;let s=e.toLowerCase();return [...ln,...r].map(u=>u.toLowerCase()).includes(s)}var cn=e=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:r=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:e.bg,border:r?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:r?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(r,s)=>({width:`${r}px`,borderRadius:"8px",background:e.bg,border:s?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:s?`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:r=>{let s=Rt[r]||Rt.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:s.bg,color:s.text,border:`1px solid ${s.border}`,lineHeight:"14px"}},progress:{height:"2px",background:e.borderSubtle,flexShrink:0},progressBar:r=>({height:"100%",width:`${r}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:r=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${r}15`,color:r,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(r,s)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:r?`${s}33`:"transparent",color:r?s: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 nt(e){return e.split("/")[0].trim()}async function un(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 r=document.createElement("textarea");r.value=e,r.setAttribute("readonly",""),r.style.position="fixed",r.style.top="0",r.style.left="0",r.style.opacity="0",r.style.pointerEvents="none",document.body.appendChild(r),r.focus(),r.select(),r.setSelectionRange(0,e.length);let s=document.execCommand("copy");return document.body.removeChild(r),s}catch{return false}}function Pe({config:e,appSlug:r,environment:s,seededUsers:p,authToken:u,tk:a,compact:T=false,onExpand:S,onAuthExpired:_,refreshAuth:b,requestLogin:y,testRunId:F,testRunToken:Y,ticketId:M,targetUrl:x,version:m,commitSha:n,prNumber:d,branchName:V}){let[U,J]=react.useState(false),[j,I]=react.useState(null),[$,_e]=react.useState(null),[ie,g]=react.useState(null),[Ee,se]=react.useState(null),[te,G]=react.useState(null),[X,ae]=react.useState(null);react.useEffect(()=>{s==="local"&&Ie();},[s]);let me=react.useCallback(l=>{I(l),g(null),se(null),ae(null);let E=Re(u);if(s!=="local"&&y&&E!==null&&E<=Date.now()){G({slug:l,token:u||null}),ae(l),I(null),y();return}let R=C=>{g(C),se(l),window.setTimeout(()=>{se(P=>P===l?null:P),g(P=>P===C?null:P);},3e3);},k=new URLSearchParams({app_slug:r,seed_user_slug:l,environment:s});F&&k.set("test_run_id",F),Y&&k.set("public_token",Y),M&&k.set("ticket_id",M),x&&k.set("target_url",x),m&&k.set("version",m),n&&k.set("commit_sha",n),d&&k.set("pr_number",String(d)),V&&k.set("branch_name",V);let L=async C=>{let P={apikey:e.anonKey,Authorization:`Bearer ${C}`};try{let z=await fetch(`${e.serverUrl}/widget/totp-code?${k}`,{headers:P});if(!z.ok){let ge=await z.json().catch(()=>({error:`HTTP ${z.status}`}));return {ok:!1,status:z.status,error:ge.error||`HTTP ${z.status}`}}let q=await z.json();return {ok:!0,code:String(q.code)}}catch{return {ok:false,status:0,error:"Network error"}}},N=(async()=>{if(s==="local"){let z=await Mt(l);if(z)try{return {ok:!0,code:await Ct(z)}}catch{}}let C=await L(u||e.anonKey);if(C.ok||C.status!==401||!b)return C;let P=await b();return P?L(P):{ok:false,status:401,error:"Sign in to BotBuddy to refresh 2FA"}})(),A=null;try{if(typeof ClipboardItem<"u"&&navigator.clipboard?.write){let C=N.then(P=>{if(!P.ok)throw new Error(P.error);return new Blob([P.code],{type:"text/plain"})});A=navigator.clipboard.write([new ClipboardItem({"text/plain":C})]).then(()=>!0).catch(()=>!1);}}catch{}(async()=>{let C=await N;if(!C.ok){C.status===401?(G({slug:l,token:u||null}),ae(l)):R(C.status===404?"No 2FA seed registered":C.error),I(null);return}let P=A?await A:false,z=P?true:await un(C.code),q=P||z;_e({slug:l,code:C.code,copied:q}),window.setTimeout(()=>_e(ge=>ge?.slug===l?null:ge),q?2500:6e3),J(false),I(null);})();},[e.serverUrl,e.anonKey,u,r,s,F,Y,M,x,m,n,d,V,b,y]),re=react.useCallback(l=>{G({slug:l,token:u||null}),y?.();},[u,y]),ye=react.useCallback(l=>{X===l?re(l):me(l);},[X,re,me]);react.useEffect(()=>{if(!te||!u||u===te.token)return;let l=te.slug;G(null),me(l);},[u,me,te]);let xe=react.useRef(null),Me=react.useRef(null);if(react.useLayoutEffect(()=>{if(!U)return;let l=xe.current,E=Me.current;if(!l||!E||typeof window>"u")return;let R=()=>{let k=l.getBoundingClientRect(),L=E.getBoundingClientRect(),N=window.innerWidth,A=window.innerHeight,C=k.left,P=k.top-L.height-6;P<8&&(P=k.bottom+6);let z=Math.max(8,N-L.width-8),q=Math.max(8,A-L.height-8);C=Math.min(Math.max(C,8),z),P=Math.min(Math.max(P,8),q),E.style.left=`${Math.round(C)}px`,E.style.top=`${Math.round(P)}px`;};return R(),window.addEventListener("scroll",R,true),window.addEventListener("resize",R),()=>{window.removeEventListener("scroll",R,true),window.removeEventListener("resize",R);}},[U,p.length,ie]),react.useEffect(()=>{if(!U)return;let l=E=>{let R=E.target;Me.current?.contains(R)||xe.current?.contains(R)||J(false);};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[U]),p.length===0)return null;if(T){let l=p.length>1,E=p[0],R=!l&&X===E,k=z=>{if(z.stopPropagation(),l&&S){S();return}ye(E);},L=!!Ee,N=!!$,A=N&&$.copied,C=N&&!$.copied,P=R?a.blue:L?a.red:A?a.green:C?a.amber:a.purple;return jsxRuntime.jsxs("span",{onPointerDown:z=>z.stopPropagation(),onPointerUp:z=>z.stopPropagation(),onPointerMove:z=>z.stopPropagation(),onClick:k,style:{display:"inline-flex",alignItems:"center",gap:"3px",color:P,fontWeight:600,cursor:"pointer",letterSpacing:C?"0.08em":void 0},title:R?"Sign in to BotBuddy to refresh 2FA":L?ie||"Failed":C?`Clipboard blocked \u2014 code: ${$.code}`:l?`${p.length} 2FA personas`:`Copy 2FA code for ${p[0]}`,children:[jsxRuntime.jsx(w,{d:R?h.key:L?h.alert:A?h.check:C?h.copy:h.shield,size:10}),R?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Sign in"}):A?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Copied"}):C?jsxRuntime.jsx(jsxRuntime.Fragment,{children:$.code}):L?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Failed"}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["2FA",l&&` \xB7${p.length}`]})]})}if(p.length===1){let l=p[0],E=j===l,R=$?.slug===l,k=R&&$.copied,L=R&&!$.copied,N=Ee===l,A=X===l,C=A?a.blue:N?a.red:k?a.green:L?a.amber:a.purple;return jsxRuntime.jsxs("button",{onClick:P=>{P.stopPropagation(),ye(l);},disabled:E,style:{...Pt(C),cursor:E?"wait":"pointer",opacity:E?.6:1},title:A?"Sign in to BotBuddy to refresh 2FA":N?ie||"Failed":L?`Clipboard blocked \u2014 code: ${$.code}`:`Copy 2FA code for ${l}`,children:[jsxRuntime.jsx(w,{d:A?h.key:N?h.alert:k?h.check:L?h.copy:h.shield,size:12}),A?"Sign in":k?"Copied":L?$.code:N?"Failed":E?"\u2026":`2FA \xB7 ${l}`]})}let le=!!X&&!U,Z=!!Ee&&!U,be=!!$&&$.copied,ve=!!$&&!$.copied,De=le?a.blue:Z?a.red:be?a.green:ve?a.amber:a.purple,Fe=U&&typeof document<"u"?reactDom.createPortal(jsxRuntime.jsxs("div",{ref:Me,onPointerDown:l=>l.stopPropagation(),onMouseDown:l=>l.stopPropagation(),style:{position:"fixed",left:-9999,top:-9999,background:a.bg,border:`1px solid ${a.border}`,borderRadius:6,boxShadow:`0 8px 24px ${a.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:[p.map(l=>{let E=j===l,R=X===l;return jsxRuntime.jsxs("button",{onClick:k=>{k.stopPropagation(),ye(l);},disabled:E,style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 8px",background:"transparent",border:"none",borderRadius:4,cursor:E?"wait":"pointer",fontSize:"10px",color:R?a.blue:a.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},title:R?"Sign in to BotBuddy to refresh 2FA":void 0,onMouseEnter:k=>k.currentTarget.style.background=a.btnHover,onMouseLeave:k=>k.currentTarget.style.background="transparent",children:[jsxRuntime.jsx(w,{d:R?h.key:h.shield,size:10}),jsxRuntime.jsx("span",{style:{flex:1,overflowWrap:"anywhere",lineHeight:1.3},children:l}),R?jsxRuntime.jsx("span",{style:{color:a.blue,fontSize:9},children:"Sign in"}):E?jsxRuntime.jsx("span",{style:{color:a.textMuted,fontSize:9},children:"\u2026"}):null]},l)}),ie&&jsxRuntime.jsx("div",{style:{padding:"4px 8px",fontSize:9,color:a.red},children:ie})]}),document.body):null;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("button",{ref:xe,onClick:l=>{if(l.stopPropagation(),le&&X){re(X);return}J(E=>!E),g(null),se(null);},style:{...Pt(De),cursor:"pointer"},title:le?"Sign in to BotBuddy to refresh 2FA":Z?ie||"Failed":ve?`Clipboard blocked \u2014 code: ${$.code}`:"Choose a persona to copy a 2FA code for",children:[jsxRuntime.jsx(w,{d:le?h.key:Z?h.alert:be?h.check:ve?h.copy:h.shield,size:12}),le?"Sign in":be?"Copied":ve?$.code:Z?"Failed":`2FA \xB7 ${p.length}`,!le&&jsxRuntime.jsx(w,{d:U?h.chevronUp:h.chevronDown,size:8})]}),Fe]})}function Pt(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 Et="botbuddy-widget-state";function pn({config:e,appSlug:r,environment:s,ticketId:p,testRunId:u,testRunToken:a,targetUrl:T,version:S,commitSha:_,prNumber:b,branchName:y,onNavigate:F,displayName:Y="human",defaultMode:M="mini",defaultPosition:x}){let m=rn(),n=react.useMemo(()=>on(m),[m]),d=react.useMemo(()=>cn(n),[n]),[V,U]=react.useState(false),[J,j]=react.useState(false),[I,$]=react.useState(false),_e=react.useRef(false),ie=e.dashboardUrl||"https://app.bot-buddy.ai",g=tt(ie),se=(()=>{try{let t=typeof window<"u"?localStorage.getItem(Et):null;if(t)return JSON.parse(t)}catch{}return null})(),[te,G]=react.useState(se?.mode||M),[X,ae]=react.useState(""),[me,re]=react.useState(null),[ye,xe]=react.useState(null),[Me,le]=react.useState(new Set),[Z,be]=react.useState(""),ve=react.useCallback(t=>{le(c=>{let v=new Set(c);return v.has(t)?v.delete(t):v.add(t),v});},[]),De=se?.x??x?.x??16,Fe=se?.y??x?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:l,setPos:E,onPointerDown:R,onPointerMove:k,onPointerUp:L,didDrag:N}=Ye(De,Fe),A=react.useRef(null);react.useEffect(()=>{try{localStorage.setItem(Et,JSON.stringify({mode:te,x:l.x,y:l.y}));}catch{}},[te,l.x,l.y]),react.useLayoutEffect(()=>{if(typeof window>"u")return;let t=A.current;if(!t)return;let c=t.getBoundingClientRect(),v=Ve(l.x,l.y,c.width,c.height,window.innerWidth,window.innerHeight);(v.x!==l.x||v.y!==l.y)&&E(v);}),react.useEffect(()=>{if(typeof window>"u")return;let t=()=>{let c=A.current;if(!c)return;let v=c.getBoundingClientRect(),W=Ve(l.x,l.y,v.width,v.height,window.innerWidth,window.innerHeight);(W.x!==l.x||W.y!==l.y)&&E(W);};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[l.x,l.y,E]);let C=react.useRef(g.isAuthenticated);react.useEffect(()=>{!C.current&&g.isAuthenticated&&G("max"),C.current=g.isAuthenticated;},[g.isAuthenticated]);let P="botbuddy-widget-max-size",z=()=>{try{let t=localStorage.getItem(P);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[q,ge]=react.useState(z),Ce=react.useRef(false),Te=react.useRef({x:0,y:0,w:0,h:0}),Bt=react.useCallback(t=>{t.stopPropagation(),Ce.current=true,Te.current={x:t.clientX,y:t.clientY,w:q.w,h:q.h},t.target.setPointerCapture(t.pointerId);},[q]),zt=react.useCallback(t=>{if(!Ce.current)return;let c=Math.max(280,Math.min(600,Te.current.w+(t.clientX-Te.current.x))),v=Math.max(300,Math.min(window.innerHeight*.9,Te.current.h+(t.clientY-Te.current.y)));ge({w:c,h:v});},[]),$t=react.useCallback(()=>{Ce.current&&(Ce.current=false,ge(t=>(localStorage.setItem(P,JSON.stringify(t)),t)));},[]),Q=T??(typeof window<"u"?window.location.href:void 0),rt=g.displayName||Y,[oe,ot]=react.useState(null);react.useEffect(()=>{if(g.isAuthenticated)return;let t=new URLSearchParams;a&&t.set("token",a),p&&t.set("ticket_id",p),t.set("app_slug",r),s&&t.set("environment",s),u&&t.set("test_run_id",u),Q&&t.set("target_url",Q),S&&t.set("version",S),_&&t.set("commit_sha",_),b&&t.set("pr_number",String(b)),y&&t.set("branch_name",y),fetch(`${e.serverUrl}/widget/preview?${t}`,{headers:{apikey:e.anonKey}}).then(c=>c.json()).then(c=>ot(c)).catch(()=>ot(null));},[g.isAuthenticated,e.serverUrl,e.anonKey,r,s,p,u,a,Q,S,_,b,y]);let it=react.useRef(false),At=react.useCallback(()=>{it.current||g.logout();},[g.logout]),{run:f,widgetState:fe,fetchRun:Ut,setVerdict:st,markComplete:Wt,resetRun:It,setRun:at}=Ge({config:e,appSlug:r,environment:s,ticketId:p,testRunId:u,testRunToken:a,targetUrl:Q,version:S,commitSha:_,prNumber:b?String(b):void 0,branchName:y,authToken:g.token,onAuthExpired:At});it.current=!!f;let[lt,dt]=react.useState([]),[ct,Le]=react.useState([]),[Ne,ut]=react.useState(false),[pt,gt]=react.useState(null),[Dt,Be]=react.useState(false),de=dn(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);react.useEffect(()=>{if((s??"local")!=="local"||de){dt([]);return}let t=true;return Ie().then(c=>{t&&dt(Object.keys(c||{}));}),()=>{t=false;}},[s,de]);let Ft=react.useCallback(async()=>{if(!(!g.isAuthenticated||!g.token)){ut(true),gt(null);try{let t=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${g.token}`},body:JSON.stringify({app_slug:r,environment:s||"local",target_url:Q,branch_name:y,commit_sha:_,pr_number:b,ticket_id:p,title:`${p||r} local validation`})}),c=await t.json().catch(()=>({}));if(!t.ok)throw new Error(c.error||`HTTP ${t.status}`);at(c),G("max");}catch(t){gt(t.message);}finally{ut(false);}}},[g.isAuthenticated,g.token,e.serverUrl,e.anonKey,r,s,Q,y,_,b,p,at]),ze=react.useCallback(async(t,c,v)=>{xe(t);try{await st(t,c,v,rt);}finally{xe(null),re(null),ae("");}},[st,rt]),D=f?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},Nt=D.total>0&&D.pending===0,we=fe==="completed",$e=react.useMemo(()=>{let t=f?.test_cases||[];if(!Z.trim())return t;let c=Z.toLowerCase();return t.filter(v=>v.title.toLowerCase().includes(c)||v.description&&v.description.toLowerCase().includes(c)||v.url_path&&v.url_path.toLowerCase().includes(c)||v.seed_user&&v.seed_user.toLowerCase().includes(c))},[f?.test_cases,Z]),ft=react.useMemo(()=>{let t=$e,c=f?.test_cases||[];if(new Set(c.map(K=>K.source_pr_number)).size<=1)return null;let W=[],ue=new Map;t.forEach(K=>{let H=K.source_pr_number;ue.has(H)||ue.set(H,[]),ue.get(H).push(K);});let St=[...ue.keys()].sort((K,H)=>K===null?1:H===null?-1:H-K);for(let K of St){let H=ue.get(K),He={total:H.length,pass:0,fail:0,skip:0,pending:0};H.forEach(kt=>{kt.verdict in He&&He[kt.verdict]++;}),W.push({key:K!=null?`pr-${K}`:"general",label:K!=null?`PR #${K}`:"General",cases:H,summary:He});}return W.filter(K=>K.cases.length>0)},[$e,f?.test_cases]),ht=D.total>0?(D.pass+D.fail)/D.total*100:0,O=s??f?.environment??null,ce=react.useMemo(()=>{if(!O||O==="production"||de)return [];let t=f?.test_cases||[],c=new Set;for(let v of t)v.seed_user&&c.add(nt(v.seed_user));if(O==="local")for(let v of lt)c.add(nt(v));for(let v of ct)c.add(nt(v));return [...c]},[f?.test_cases,O,lt,ct,de]);react.useEffect(()=>{if(!O||O==="production"||de||!g.isAuthenticated||!g.token){Le([]);return}let t=true,c=`${e.serverUrl}/widget/totp-seeds?${new URLSearchParams({app_slug:r,environment:O})}`,v=W=>fetch(c,{headers:{apikey:e.anonKey,Authorization:`Bearer ${W}`}});return (async()=>{try{let W=await v(g.token);if(W.status===401&&g.refreshNow){let H=await g.refreshNow();H&&(W=await v(H));}if(!t)return;if(!W.ok){Le([]);return}let ue=await W.json().catch(()=>null),K=(Array.isArray(ue?.seeds)?ue.seeds:[]).map(H=>H?.seed_user_slug).filter(H=>typeof H=="string"&&H.length>0);Le(K);}catch{t&&Le([]);}})(),()=>{t=false;}},[O,de,g.isAuthenticated,g.token,g.refreshNow,r,e.serverUrl,e.anonKey]);let Oe=react.useMemo(()=>{let t=f?.auto_tooltip_seconds??oe?.auto_tooltip_seconds;return t!=null&&t>0?t*1e3:0},[f,oe]),mt=fe==="ready"||fe==="completed"||oe?.enabled&&oe.run;react.useEffect(()=>{if(!mt||_e.current||Oe<=0)return;_e.current=true,j(true);let t=window.setTimeout(()=>j(false),Oe);return ()=>window.clearTimeout(t)},[mt,Oe]);let yt=t=>jsxRuntime.jsxs("div",{style:d.caseRow,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsx("div",{style:{marginTop:"2px",flexShrink:0,color:sn[t.verdict]},children:ye===t.id?jsxRuntime.jsx(w,{d:h.loader,className:""}):jsxRuntime.jsx(w,{d:an[t.verdict],className:""})}),jsxRuntime.jsxs("div",{style:{minWidth:0,flex:1},children:[jsxRuntime.jsx("div",{style:{fontSize:"10px",color:n.text,lineHeight:1.3},children:t.title}),t.description&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:n.gripColor,marginTop:"2px"},children:t.description}),t.seed_user&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:n.amber,marginTop:"3px",display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",background:`${n.amber}12`,border:`1px solid ${n.amber}30`},children:[jsxRuntime.jsx(w,{d:h.key,size:10}),jsxRuntime.jsx("span",{children:t.seed_user})]}),t.url_path&&jsxRuntime.jsxs("a",{href:t.url_path,target:"_blank",rel:"noopener noreferrer",onClick:c=>{c.stopPropagation(),F&&(c.preventDefault(),F(t.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:[jsxRuntime.jsx(w,{d:h.externalLink,size:10}),t.url_path]}),t.verdict==="fail"&&t.fail_reason&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:n.red,marginTop:"2px"},children:["\u2717 ",t.fail_reason]})]})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(c=>jsxRuntime.jsx("button",{onClick:()=>{if(t.verdict===c){ze(t.id,"pending"),re(null);return}if(c==="fail"){re(t.id),ae("");return}re(null),ze(t.id,c);},disabled:ye!==null,style:d.verdictBtn(t.verdict===c,c==="pass"?n.green:c==="fail"?n.red:n.amber),children:c.toUpperCase()},c)),t.created_by_agent_name&&jsxRuntime.jsxs("span",{style:{fontSize:"8px",color:n.purple,marginLeft:"4px",display:"inline-flex",alignItems:"center",gap:"2px"},children:[jsxRuntime.jsx(w,{d:h.bot,size:8}),t.created_by_agent_name]}),t.verdict_by_display_name&&jsxRuntime.jsxs("span",{style:{fontSize:"8px",color:n.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[t.verdict_by_display_name,t.verdict_at&&jsxRuntime.jsx("span",{style:{opacity:.7},children:nn(t.verdict_at)})]})]}),me===t.id&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:X,onChange:c=>ae(c.target.value),onKeyDown:c=>{c.key==="Enter"&&ze(t.id,"fail",X.trim()||void 0),c.key==="Escape"&&(re(null),ae(""));},placeholder:"Reason (optional)...",style:d.input}),jsxRuntime.jsx("button",{onClick:()=>{ze(t.id,"fail",X.trim()||void 0);},style:d.verdictBtn(true,n.red),children:"\u2713"})]})]},t.id);if((fe==="no-match"||fe==="loading")&&!(!g.isAuthenticated&&oe?.enabled&&oe.run)){if(!(O==="local"&&!de))return null}if(!g.isAuthenticated&&oe?.enabled&&oe.run){let t=oe.run,c=t.summary,v=t.status==="completed";return jsxRuntime.jsx("div",{ref:A,style:{...d.root,left:l.x,top:l.y},children:jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>U(true),onMouseLeave:()=>{U(false),$(false),j(false);},children:[jsxRuntime.jsxs("div",{style:{...d.pill(v),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:R,onPointerMove:k,onPointerUp:()=>{L();},children:[jsxRuntime.jsx(w,{d:h.grip,size:10,className:""}),t.ticket_id&&t.ticket_url?jsxRuntime.jsx("a",{href:t.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:n.amber,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:t.ticket_id}):null,t.pr_url?jsxRuntime.jsxs("a",{href:t.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:n.blue,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:["PR#",t.pr_number??t.pr_id]}):null,t.created_by_agent_name?t.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${t.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:n.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(w,{d:h.terminal,size:10}),t.created_by_agent_name]}):jsxRuntime.jsxs("span",{style:{color:n.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(w,{d:h.bot,size:10}),t.created_by_agent_name]}):null,jsxRuntime.jsxs("span",{style:v?{color:n.green}:void 0,children:[c.pass,"/",c.total]}),c.fail>0&&jsxRuntime.jsxs("span",{style:{color:n.red},children:[c.fail,"\u2717"]}),jsxRuntime.jsx("span",{onClick:W=>{W.stopPropagation(),g.openLogin();},style:{color:n.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!I&&(V||J)&&t.title&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsxRuntime.jsx("div",{style:{fontSize:"11px",fontWeight:700,color:n.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:t.title}),(t.description||t.intro_notes)&&jsxRuntime.jsx("div",{style:{fontSize:"10px",color:n.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:t.description||t.intro_notes}),jsxRuntime.jsx("div",{style:{marginTop:"4px",fontSize:"9px",color:n.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!g.isAuthenticated)return jsxRuntime.jsxs("div",{ref:A,style:{...d.root,left:l.x,top:l.y,width:220,minHeight:0,cursor:"move",userSelect:"none",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`},onPointerDown:R,onPointerMove:k,onPointerUp:L,children:[jsxRuntime.jsx("div",{style:{...d.handle,borderBottom:"none"},children:jsxRuntime.jsxs("div",{style:d.sub,children:[jsxRuntime.jsx(w,{d:h.grip,size:10,className:""}),jsxRuntime.jsx(w,{d:h.clipboard,size:12,className:""}),jsxRuntime.jsx("span",{style:{fontWeight:600},children:"BotBuddy"})]})}),jsxRuntime.jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[jsxRuntime.jsx("div",{style:{fontSize:"9px",color:n.textMuted,marginBottom:"8px"},children:"Sign in to access test cases"}),O==="local"&&ce.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsxRuntime.jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,testRunId:f?.id||u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout})}),jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),g.openLogin();},style:{fontSize:"10px",fontWeight:600,padding:"6px 16px",borderRadius:"6px",border:`1px solid ${n.green}`,background:`${n.green}22`,color:n.green,cursor:"pointer",width:"100%"},children:"Sign in to test"})]})]});if(!f&&O==="local"&&!de)return Dt?jsxRuntime.jsx("div",{ref:A,style:{...d.root,left:l.x,top:l.y},children:jsxRuntime.jsxs("div",{style:d.card(240,false),children:[jsxRuntime.jsxs("div",{style:d.handle,onPointerDown:R,onPointerMove:k,onPointerUp:L,onClick:()=>{N.current||Be(false);},children:[jsxRuntime.jsx(w,{d:h.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:d.title,children:"BotBuddy"}),y&&jsxRuntime.jsx("div",{style:d.sub,children:jsxRuntime.jsxs("span",{children:["\u2387 ",y]})})]}),jsxRuntime.jsx(w,{d:h.chevronUp,className:""}),jsxRuntime.jsx("button",{style:d.btn,onClick:t=>{t.stopPropagation(),Be(false);},children:jsxRuntime.jsx(w,{d:h.minus,className:""})})]}),jsxRuntime.jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[ce.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsxRuntime.jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,testRunId:u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout})}),jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),Ft();},disabled:Ne,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${n.green}`,background:`${n.green}22`,color:n.green,cursor:Ne?"wait":"pointer",width:"100%"},children:Ne?"Creating...":"Create test run for this branch"}),pt&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:n.red,marginTop:"8px"},children:pt})]})]})}):jsxRuntime.jsx("div",{ref:A,style:{...d.root,left:l.x,top:l.y},children:jsxRuntime.jsxs("div",{style:{...d.pill(false),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:R,onPointerMove:k,onPointerUp:()=>{L(),N.current||Be(true);},children:[jsxRuntime.jsx(w,{d:h.grip,size:9,className:""}),jsxRuntime.jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),ce.length>0&&jsxRuntime.jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,compact:true,onExpand:()=>Be(true),testRunId:u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout})]})});let xt=()=>{N.current||(j(false),G(t=>{let c=t==="mini"?"max":"mini";return $(c==="mini"),c}));},bt=({icon:t,onClick:c})=>jsxRuntime.jsx("button",{style:d.btn,onClick:v=>{v.stopPropagation(),c(v);},children:jsxRuntime.jsx(w,{d:t,className:""})}),vt=()=>jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${n.borderSubtle}`,flexShrink:0},children:[f?.pr_url&&jsxRuntime.jsxs("a",{href:f.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.blue),textDecoration:"none"},children:[jsxRuntime.jsx(w,{d:h.pr,size:12}),f.pr_number?`PR#${f.pr_number}`:f.pr_id||"PR",jsxRuntime.jsx(w,{d:h.externalLink,size:8})]}),f?.ticket_url&&jsxRuntime.jsxs("a",{href:f.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.amber),textDecoration:"none"},children:[jsxRuntime.jsx(w,{d:h.ticket,size:12}),f.ticket_id||"Ticket",jsxRuntime.jsx(w,{d:h.externalLink,size:8})]}),f?.created_by_agent_name&&(f.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${f.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.purple),textDecoration:"none"},children:[jsxRuntime.jsx(w,{d:h.bot,size:12}),f.created_by_agent_name,jsxRuntime.jsx(w,{d:h.externalLink,size:8})]}):jsxRuntime.jsxs("span",{style:{...d.link(n.purple)},children:[jsxRuntime.jsx(w,{d:h.bot,size:12}),f.created_by_agent_name]})),O&&jsxRuntime.jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,testRunId:f?.id||u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout}),jsxRuntime.jsx("span",{style:{...d.badge(f?.environment||"custom"),marginLeft:"auto"},children:f?.environment})]}),wt=()=>jsxRuntime.jsxs("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:`1px solid ${n.borderSubtle}`,background:n.bgSoft,flexShrink:0},children:[jsxRuntime.jsxs("button",{onClick:()=>{navigator.clipboard.writeText(Tt);},style:{fontSize:"9px",fontWeight:600,color:n.versionText,letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxRuntime.jsxs("span",{style:{color:n.versionNum},children:["v",Tt]})]}),g.isAuthenticated&&(g.isExpired?jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),g.openLogin();},style:{fontSize:"8px",color:n.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"}):jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),g.logout();},style:{fontSize:"8px",color:n.textFaint,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Sign out of widget",children:"sign out"}))]});return jsxRuntime.jsxs("div",{ref:A,style:{...d.root,left:l.x,top:l.y},children:[te==="mini"&&jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>U(true),onMouseLeave:()=>{U(false),$(false),j(false);},children:[jsxRuntime.jsxs("div",{style:{...d.pill(we),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:R,onPointerMove:k,onPointerUp:()=>{L(),N.current||xt();},children:[jsxRuntime.jsx(w,{d:h.grip,size:9,className:""}),f?.ticket_id&&jsxRuntime.jsx("span",{style:{color:n.amber,fontWeight:600},children:f.ticket_id}),f?.pr_number&&jsxRuntime.jsxs("span",{style:{color:n.blue,fontWeight:600},children:["PR#",f.pr_number]}),jsxRuntime.jsxs("span",{style:we?{color:n.green}:void 0,children:[D.pass,"/",D.total]}),D.fail>0&&jsxRuntime.jsxs("span",{style:{color:n.red},children:[D.fail,"\u2717"]}),O&&jsxRuntime.jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,compact:true,onExpand:()=>G("expanded"),testRunId:f?.id||u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout})]}),!I&&(V||J)&&f?.title&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsxRuntime.jsx("div",{style:{fontSize:"11px",fontWeight:700,color:n.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:f.title}),(f.description||f.intro_notes)&&jsxRuntime.jsx("div",{style:{fontSize:"10px",color:n.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:f.description||f.intro_notes})]})]}),te==="expanded"&&jsxRuntime.jsxs("div",{style:d.card(300,we),children:[jsxRuntime.jsxs("div",{style:d.handle,onPointerDown:R,onPointerMove:k,onPointerUp:L,onClick:xt,children:[jsxRuntime.jsx(w,{d:h.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:d.title,children:f?.title}),jsxRuntime.jsx("div",{style:d.sub,children:f?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",f.branch_name]})})]}),jsxRuntime.jsx(w,{d:h.chevronUp,className:""}),jsxRuntime.jsx(bt,{icon:h.minus,onClick:()=>{j(false),$(true),G("mini");}})]}),jsxRuntime.jsxs("div",{style:d.stats,children:[jsxRuntime.jsxs("span",{style:{color:n.green},children:[D.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:n.red},children:[D.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:n.amber},children:[D.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:n.gripColor},children:[D.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:D.total})]}),f?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:n.gripColor,borderBottom:`1px solid ${n.borderSubtle}`,flexShrink:0},children:f.description}),vt(),wt(),jsxRuntime.jsx("div",{style:d.progress,children:jsxRuntime.jsx("div",{style:d.progressBar(ht)})})]}),te==="max"&&jsxRuntime.jsxs("div",{style:{...d.card(q.w,we),height:q.h,position:"relative"},children:[jsxRuntime.jsxs("div",{style:d.handle,onPointerDown:R,onPointerMove:k,onPointerUp:L,onClick:()=>{N.current||G("expanded");},children:[jsxRuntime.jsx(w,{d:h.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:d.title,children:f?.title}),jsxRuntime.jsx("div",{style:d.sub,children:f?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",f.branch_name]})})]}),jsxRuntime.jsx(w,{d:h.chevronDown,className:""}),jsxRuntime.jsx(bt,{icon:h.minus,onClick:()=>{j(false),$(true),G("mini");}})]}),jsxRuntime.jsxs("div",{style:d.stats,children:[jsxRuntime.jsxs("span",{style:{color:n.green},children:[D.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:n.red},children:[D.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:n.amber},children:[D.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:n.gripColor},children:[D.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:D.total})]}),f?.intro_notes&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${n.borderSubtle}`,fontSize:"10px",color:n.textMuted,fontStyle:"italic",flexShrink:0},children:f.intro_notes}),(f?.test_cases||[]).length>5&&jsxRuntime.jsxs("div",{style:{padding:"4px 12px",borderBottom:`1px solid ${n.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[jsxRuntime.jsx(w,{d:h.search,size:11,className:""}),jsxRuntime.jsx("input",{value:Z,onChange:t=>be(t.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:n.text,fontFamily:"monospace"}}),Z&&jsxRuntime.jsx("button",{onClick:()=>be(""),style:{background:"none",border:"none",cursor:"pointer",color:n.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),fe==="error"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsxRuntime.jsx(w,{d:h.alert,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:n.red},children:"Failed to load"}),jsxRuntime.jsx("button",{onClick:Ut,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),we&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg},children:[jsxRuntime.jsx(w,{d:h.checkAll,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",color:n.green,flex:1},children:"Run completed"}),jsxRuntime.jsx("button",{onClick:It,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),fe!=="error"&&jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(f?.test_cases||[]).length===0?jsxRuntime.jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:"No test cases"}):$e.length===0?jsxRuntime.jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:['No matches for "',Z,'"']}):ft?ft.map(t=>{let c=Me.has(t.key);return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>ve(t.key),style:{width:"100%",display:"flex",alignItems:"center",gap:"6px",padding:"5px 12px",background:n.bgSoft,cursor:"pointer",border:"none",borderLeft:"none",borderRight:"none",borderBottomStyle:"solid",borderTopStyle:"solid",borderBottomWidth:"1px",borderTopWidth:"1px",borderBottomColor:n.borderSubtle,borderTopColor:n.borderSubtle,backgroundColor:n.bgSoft},children:[jsxRuntime.jsx(w,{d:c?h.chevronDown:h.chevronUp,size:10,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",fontWeight:700,color:n.blue,flex:1,textAlign:"left"},children:t.label}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:n.green},children:[t.summary.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:n.red},children:[t.summary.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:n.gripColor},children:[t.summary.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{fontSize:"9px",color:n.textFaint},children:t.summary.total})]}),!c&&t.cases.map(v=>yt(v))]},t.key)}):$e.map(t=>yt(t))}),Nt&&!we&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",borderTop:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg,display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsxRuntime.jsx("span",{style:{fontSize:"9px",color:n.green},children:"All resolved"}),jsxRuntime.jsx("button",{onClick:Wt,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:n.green,border:`1px solid ${n.greenBorderSubtle}`,cursor:"pointer"},children:"COMPLETE"})]}),vt(),wt(),jsxRuntime.jsx("div",{style:d.progress,children:jsxRuntime.jsx("div",{style:d.progressBar(ht)})}),jsxRuntime.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:Bt,onPointerMove:zt,onPointerUp:$t,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{Ce.current||(t.currentTarget.style.opacity="0.3");},children:jsxRuntime.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsxRuntime.jsx("path",{d:"M7 1v6H1",fill:"none",stroke:n.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}
|
|
2
|
-
|
|
1
|
+
'use strict';var react=require('react'),reactDom=require('react-dom'),jsxRuntime=require('react/jsx-runtime');var Se=8;function qe(e,n,i,d,a,s){let _=Math.max(Se,a-i-Se),k=Math.max(Se,s-d-Se);return {x:Math.min(Math.max(e,Se),_),y:Math.min(Math.max(n,Se),k)}}function Ge(e,n){let[i,d]=react.useState({x:e,y:n}),a=react.useRef(false),s=react.useRef({x:0,y:0}),_=react.useRef(false),k=react.useCallback(y=>{a.current=true,_.current=false,s.current={x:y.clientX-i.x,y:y.clientY-i.y},y.target.setPointerCapture(y.pointerId);},[i]),h=react.useCallback(y=>{a.current&&(_.current=true,d({x:y.clientX-s.current.x,y:y.clientY-s.current.y}));},[]),p=react.useCallback(()=>{a.current=false;},[]);return {pos:i,setPos:d,onPointerDown:k,onPointerMove:h,onPointerUp:p,didDrag:_}}function Xe(e,n,i){let d=react.useRef(i);d.current=i,react.useEffect(()=>{if(!n)return;if(e.supabaseUrl){let s=false,_=null,k=()=>{s||_||(_=setInterval(()=>d.current(),15e3));},h=null;try{let x=new URL(e.supabaseUrl),r=["localhost","127.0.0.1","::1"].includes(x.hostname);if(x.protocol==="http:"&&!r)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");x.protocol=x.protocol==="https:"?"wss:":"ws:",h=x.toString().replace(/\/$/,"");}catch{k();}let p=null,y=null,T=null,V=0,M=()=>{if(!(s||!h)){try{p=new WebSocket(`${h}/realtime/v1/websocket?apikey=${e.anonKey}&vsn=1.0.0`);}catch{k();return}p.onopen=()=>{if(s||!p)return;let x={topic:`realtime:public:test_run_cases:test_run_id=eq.${n}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_run_cases",filter:`test_run_id=eq.${n}`}]}},ref:String(++V)};p.send(JSON.stringify(x));let r={topic:`realtime:public:test_runs:id=eq.${n}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_runs",filter:`id=eq.${n}`}]}},ref:String(++V)};p.send(JSON.stringify(r)),y=setInterval(()=>{p?.readyState===WebSocket.OPEN&&p.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++V)}));},3e4);},p.onmessage=x=>{try{JSON.parse(x.data).event==="postgres_changes"&&d.current();}catch{}},p.onclose=()=>{v(),s||(T=setTimeout(M,3e3));},p.onerror=()=>{p?.close();};}},v=()=>{y&&(clearInterval(y),y=null);};return M(),()=>{s=true,v(),T&&clearTimeout(T),_&&clearInterval(_),p&&(p.onclose=null,p.onerror=null,p.close());}}let a=setInterval(()=>d.current(),15e3);return ()=>clearInterval(a)},[e.supabaseUrl,e.anonKey,n]);}var Qt="botbuddy:created-test-run:";function en(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function tn(e){return `${Qt}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",en(e.targetUrl),e.branchName||""].join("|"))}`}function Ue(e,n){let i={apikey:e.anonKey};return n?i.Authorization=`Bearer ${n}`:e.apiKey?i.Authorization=`Bearer ${e.apiKey}`:i.Authorization=`Bearer ${e.anonKey}`,i}async function nn(e){if(e)return e;try{let n=await fetch("/.botbuddy-token",{cache:"no-store"});if(n.ok){let i=(await n.text()).trim();if(i.startsWith("public_"))return i}}catch{}try{let n=undefined?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(n&&typeof n=="string"&&n.startsWith("public_"))return n}catch{}return null}function Qe(e){let[n,i]=react.useState(null),[d,a]=react.useState("loading"),s=tn(e),[_,k]=react.useState(()=>{if(e.testRunId)return e.testRunId;try{return localStorage.getItem(s)||void 0}catch{return}}),h=e.testRunId||_,p=react.useCallback(v=>{if(i(v),!!v?.id){k(v.id);try{localStorage.setItem(s,v.id);}catch{}}},[s]),y=react.useCallback(async()=>{try{let v=await nn(e.testRunToken);if(!v&&!h){a("no-match"),i(null);return}if(v&&!e.ticketId){a("no-match"),i(null);return}let x=new URLSearchParams;v&&x.set("token",v),e.ticketId&&x.set("ticket_id",e.ticketId),x.set("app_slug",e.appSlug),e.environment&&x.set("environment",e.environment),h&&x.set("test_run_id",h),e.targetUrl&&x.set("target_url",e.targetUrl),e.version&&x.set("version",e.version),e.commitSha&&x.set("commit_sha",e.commitSha),e.prNumber&&x.set("pr_number",String(e.prNumber)),e.branchName&&x.set("branch_name",e.branchName);let r=await fetch(`${e.config.serverUrl}/widget/test-run?${x.toString()}`,{headers:Ue(e.config,e.authToken)});if(r.status===404){a("no-match"),i(null);return}if(r.status===401||r.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),a("error");return}if(!r.ok){a("error");return}let u=await r.json();if(!u||u.run===null){a("no-match"),i(null);return}p(u),a(u.status==="completed"?"completed":"ready");}catch{a("error");}},[e.config.serverUrl,e.config.anonKey,e.config.apiKey,e.authToken,e.appSlug,e.environment,e.ticketId,h,e.testRunToken,e.targetUrl,e.version,e.commitSha,e.branchName,e.prNumber,e.onAuthExpired,p]);return react.useEffect(()=>{y();},[y]),Xe(e.config,n?.id,y),{run:n,widgetState:d,fetchRun:y,setVerdict:async(v,x,r,u="human")=>(i(U=>{if(!U)return null;let q=U.test_cases.map(I=>I.id===v?{...I,verdict:x,fail_reason:x==="fail"&&r||null,verdict_by_display_name:u,verdict_at:new Date().toISOString()}:I),Y={total:q.length,pending:0,pass:0,fail:0,skip:0};return q.forEach(I=>{I.verdict in Y&&Y[I.verdict]++;}),{...U,test_cases:q,summary:Y}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${v}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...Ue(e.config,e.authToken)},body:JSON.stringify({verdict:x,fail_reason:r,display_name:u})})).ok),markComplete:async()=>n?(i(x=>x?{...x,status:"completed"}:null),a("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${n.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...Ue(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!n)return false;let v=await fetch(`${e.config.serverUrl}/widget/test-runs/${n.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...Ue(e.config,e.authToken)}});return v.ok&&y(),v.ok},setRun:p}}var nt="botbuddy-widget-auth-token",rt="botbuddy-widget-auth-name";function Ee(e){if(!e)return null;try{let n=e.split(".")[1];if(!n)return null;let i=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(n.length/4)*4,"="),d=atob(i),a=JSON.parse(d);return typeof a.exp=="number"?a.exp*1e3:null}catch{return null}}var on=2500,sn=6e4;function ot(e){let[n,i]=react.useState(()=>{try{return localStorage.getItem(nt)}catch(M){return console.warn("Unable to read BotBuddy widget auth token",M),null}}),[d,a]=react.useState(()=>{try{return localStorage.getItem(rt)}catch(M){return console.warn("Unable to read BotBuddy widget display name",M),null}}),s=react.useRef(null),_=react.useCallback((M,v)=>{i(M),v&&a(v);try{localStorage.setItem(nt,M),v&&localStorage.setItem(rt,v);}catch(x){console.warn("Unable to persist BotBuddy widget auth token",x);}},[]);react.useEffect(()=>{let M=new URL(e).origin,v=x=>{x.origin===M&&x.data?.type==="botbuddy-widget-auth"&&x.data.token&&_(x.data.token,x.data.displayName||"human");};return window.addEventListener("message",v),()=>window.removeEventListener("message",v)},[e,_]);let k=react.useCallback(()=>{if(s.current)return s.current;if(typeof window>"u"||typeof document>"u")return Promise.resolve(null);let M=new URL(e).origin,v=new URL("/widget-auth",e);v.searchParams.set("silent","1"),v.searchParams.set("origin",window.location.origin);let x=new Promise(r=>{let u=document.createElement("iframe");u.setAttribute("aria-hidden","true"),u.style.position="fixed",u.style.width="1px",u.style.height="1px",u.style.opacity="0",u.style.pointerEvents="none",u.style.border="0",u.style.left="-9999px",u.style.top="-9999px",u.src=v.toString();let J=false,U=()=>{window.removeEventListener("message",q),clearTimeout(Y);try{u.remove();}catch{}s.current=null;},q=I=>{if(I.origin===M){if(I.data?.type==="botbuddy-widget-auth-failed"){if(J)return;J=true,r(null),U();return}I.data?.type!=="botbuddy-widget-auth"||!I.data.token||J||(J=true,r(String(I.data.token)),U());}},Y=setTimeout(()=>{J||(J=true,r(null),U());},on);window.addEventListener("message",q),document.body.appendChild(u);});return s.current=x,x},[e]);react.useEffect(()=>{if(!n)return;let M=Ee(n);if(!M)return;let v=M-Date.now()-sn,x=window.setTimeout(()=>{k();},Math.max(0,v));return ()=>window.clearTimeout(x)},[n,k]);let h=react.useCallback(()=>{let M=new URL("/widget-auth",e);M.searchParams.set("origin",window.location.origin);let v=420,x=520,r=window.screenX+(window.innerWidth-v)/2,u=window.screenY+(window.innerHeight-x)/2;window.open(M.toString(),"botbuddy-auth",`width=${v},height=${x},left=${r},top=${u},popup=yes`);},[e]),[,p]=react.useState(0);react.useEffect(()=>{let M=Ee(n);if(!M)return;let v=M-Date.now();if(v<=0)return;let x=window.setTimeout(()=>p(r=>r+1),v);return ()=>window.clearTimeout(x)},[n]);let y=react.useCallback(()=>{i(null),a(null);try{localStorage.removeItem(nt),localStorage.removeItem(rt);}catch(M){console.warn("Unable to clear BotBuddy widget auth token",M);}},[]),T=Ee(n),V=T!==null&&T<=Date.now();return {token:n,displayName:d,isAuthenticated:!!n,isExpired:V,openLogin:h,refreshNow:k,logout:y}}var Ie=null;function an(){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 Fe(){return Ie||(Ie=(async()=>{if(typeof fetch>"u")return null;try{let e=await fetch(an(),{cache:"no-store"});if(!e.ok)return null;let n=await e.json();if(!n||typeof n!="object"||Array.isArray(n))return null;let i={};for(let[d,a]of Object.entries(n))typeof a=="string"&&a.length>0&&(i[d]=a);return i}catch{return null}})(),Ie)}async function Pt(e){return (await Fe())?.[e]??null}function ln(e){let n=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),i="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",d=[],a=0,s=0;for(let _ of n){let k=i.indexOf(_);if(k<0)throw new Error("Invalid Base32 character in TOTP secret");s=s<<5|k,a+=5,a>=8&&(a-=8,d.push(s>>>a&255));}return Uint8Array.from(d)}async function Et(e,n=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let i=ln(e),d=new Uint8Array(i.byteLength);d.set(i);let a=Math.floor(n/1e3/30),s=new Uint8Array(8),_=Math.floor(a/4294967296),k=a>>>0;s[0]=_>>>24&255,s[1]=_>>>16&255,s[2]=_>>>8&255,s[3]=_&255,s[4]=k>>>24&255,s[5]=k>>>16&255,s[6]=k>>>8&255,s[7]=k&255;let h=await crypto.subtle.importKey("raw",d,{name:"HMAC",hash:"SHA-1"},false,["sign"]),p=await crypto.subtle.sign("HMAC",h,s),y=new Uint8Array(p),T=y[y.length-1]&15;return (((y[T]&127)<<24|(y[T+1]&255)<<16|(y[T+2]&255)<<8|y[T+3]&255)%1e6).toString().padStart(6,"0")}var Lt="0.11.0";function cn(e){let n=new Date(e),d=Date.now()-n.getTime();if(d<6e4)return "just now";if(d<36e5)return `${Math.floor(d/6e4)}m ago`;if(d<864e5)return `${Math.floor(d/36e5)}h ago`;let a=n.getDate(),s=n.toLocaleString("en",{month:"short"}),_=n.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${s} ${a}, ${_}`}var S=({d:e,className:n,size:i=14})=>jsxRuntime.jsx("svg",{className:n,width:i,height:i,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:e})}),m={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 un(){let[e,n]=react.useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return react.useEffect(()=>{if(typeof window>"u")return;let i=document.documentElement,d=()=>i.classList.contains("dark")?"dark":i.classList.contains("light")?"light":null,a=d();a&&n(a);let s=window.matchMedia("(prefers-color-scheme: dark)"),_=h=>{let p=d();n(p||(h.matches?"dark":"light"));};s.addEventListener("change",_);let k=new MutationObserver(()=>{let h=d();n(h||(s.matches?"dark":"light"));});return k.observe(i,{attributes:true,attributeFilter:["class"]}),()=>{s.removeEventListener("change",_),k.disconnect();}},[]),e}function pn(e){let n=e==="dark";return {bg:n?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:n?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:n?"#e5e5e5":"#1a1a1a",textMuted:n?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:n?"#555":"#999",border:n?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:n?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:n?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:n?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:n?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:n?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:n?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:n?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:n?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:n?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:n?"#888":"#aaa",btnHover:n?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var gn={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},fn={pending:m.circle,pass:m.check,fail:m.x,skip:m.skip},Nt={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)"}},bn=["app.supply-guard.io"];function mn(e,n=[]){if(!e)return false;let i=e.toLowerCase();return [...bn,...n].map(a=>a.toLowerCase()).includes(i)}var yn=e=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:n=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:e.bg,border:n?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:n?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(n,i)=>({width:`${n}px`,borderRadius:"8px",background:e.bg,border:i?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:i?`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:n=>{let i=Nt[n]||Nt.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:i.bg,color:i.text,border:`1px solid ${i.border}`,lineHeight:"14px"}},progress:{height:"2px",background:e.borderSubtle,flexShrink:0},progressBar:n=>({height:"100%",width:`${n}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:n=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${n}15`,color:n,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(n,i)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:n?`${i}33`:"transparent",color:n?i: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 it(e){return e.split("/")[0].trim()}async function hn(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 n=document.createElement("textarea");n.value=e,n.setAttribute("readonly",""),n.style.position="fixed",n.style.top="0",n.style.left="0",n.style.opacity="0",n.style.pointerEvents="none",document.body.appendChild(n),n.focus(),n.select(),n.setSelectionRange(0,e.length);let i=document.execCommand("copy");return document.body.removeChild(n),i}catch{return false}}function Le({config:e,appSlug:n,environment:i,seededUsers:d,authToken:a,tk:s,compact:_=false,onExpand:k,onAuthExpired:h,refreshAuth:p,requestLogin:y,testRunId:T,testRunToken:V,ticketId:M,targetUrl:v,version:x,commitSha:r,prNumber:u,branchName:J}){let[U,q]=react.useState(false),[Y,I]=react.useState(null),[$,Me]=react.useState(null),[se,f]=react.useState(null),[Ne,ae]=react.useState(null),[ne,X]=react.useState(null),[Z,le]=react.useState(null);react.useEffect(()=>{i==="local"&&Fe();},[i]);let ye=react.useCallback(c=>{I(c),f(null),ae(null),le(null);let L=Ee(a);if(i!=="local"&&y&&L!==null&&L<=Date.now()){X({slug:c,token:a||null}),le(c),I(null),y();return}let P=C=>{f(C),ae(c),window.setTimeout(()=>{ae(E=>E===c?null:E),f(E=>E===C?null:E);},3e3);},R=new URLSearchParams({app_slug:n,seed_user_slug:c,environment:i});T&&R.set("test_run_id",T),V&&R.set("public_token",V),M&&R.set("ticket_id",M),v&&R.set("target_url",v),x&&R.set("version",x),r&&R.set("commit_sha",r),u&&R.set("pr_number",String(u)),J&&R.set("branch_name",J);let N=async C=>{let E={apikey:e.anonKey,Authorization:`Bearer ${C}`};try{let z=await fetch(`${e.serverUrl}/widget/totp-code?${R}`,{headers:E});if(!z.ok){let fe=await z.json().catch(()=>({error:`HTTP ${z.status}`}));return {ok:!1,status:z.status,error:fe.error||`HTTP ${z.status}`}}let G=await z.json();return {ok:!0,code:String(G.code)}}catch{return {ok:false,status:0,error:"Network error"}}},D=(async()=>{if(i==="local"){let z=await Pt(c);if(z)try{return {ok:!0,code:await Et(z)}}catch{}}let C=await N(a||e.anonKey);if(C.ok||C.status!==401||!p)return C;let E=await p();return E?N(E):{ok:false,status:401,error:"Sign in to BotBuddy to refresh 2FA"}})(),A=null;try{if(typeof ClipboardItem<"u"&&navigator.clipboard?.write){let C=D.then(E=>{if(!E.ok)throw new Error(E.error);return new Blob([E.code],{type:"text/plain"})});A=navigator.clipboard.write([new ClipboardItem({"text/plain":C})]).then(()=>!0).catch(()=>!1);}}catch{}(async()=>{let C=await D;if(!C.ok){C.status===401?(X({slug:c,token:a||null}),le(c)):P(C.status===404?"No 2FA seed registered":C.error),I(null);return}let E=A?await A:false,z=E?true:await hn(C.code),G=E||z;Me({slug:c,code:C.code,copied:G}),window.setTimeout(()=>Me(fe=>fe?.slug===c?null:fe),G?2500:6e3),q(false),I(null);})();},[e.serverUrl,e.anonKey,a,n,i,T,V,M,v,x,r,u,J,p,y]),oe=react.useCallback(c=>{X({slug:c,token:a||null}),y?.();},[a,y]),he=react.useCallback(c=>{Z===c?oe(c):ye(c);},[Z,oe,ye]);react.useEffect(()=>{if(!ne||!a||a===ne.token)return;let c=ne.slug;X(null),ye(c);},[a,ye,ne]);let xe=react.useRef(null),Ce=react.useRef(null);if(react.useLayoutEffect(()=>{if(!U)return;let c=xe.current,L=Ce.current;if(!c||!L||typeof window>"u")return;let P=()=>{let R=c.getBoundingClientRect(),N=L.getBoundingClientRect(),D=window.innerWidth,A=window.innerHeight,C=R.left,E=R.top-N.height-6;E<8&&(E=R.bottom+6);let z=Math.max(8,D-N.width-8),G=Math.max(8,A-N.height-8);C=Math.min(Math.max(C,8),z),E=Math.min(Math.max(E,8),G),L.style.left=`${Math.round(C)}px`,L.style.top=`${Math.round(E)}px`;};return P(),window.addEventListener("scroll",P,true),window.addEventListener("resize",P),()=>{window.removeEventListener("scroll",P,true),window.removeEventListener("resize",P);}},[U,d.length,se]),react.useEffect(()=>{if(!U)return;let c=L=>{let P=L.target;Ce.current?.contains(P)||xe.current?.contains(P)||q(false);};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[U]),d.length===0)return null;if(_){let c=d.length>1,L=d[0],P=!c&&Z===L,R=z=>{if(z.stopPropagation(),c&&k){k();return}he(L);},N=!!Ne,D=!!$,A=D&&$.copied,C=D&&!$.copied,E=P?s.blue:N?s.red:A?s.green:C?s.amber:s.purple;return jsxRuntime.jsxs("span",{onPointerDown:z=>z.stopPropagation(),onPointerUp:z=>z.stopPropagation(),onPointerMove:z=>z.stopPropagation(),onClick:R,style:{display:"inline-flex",alignItems:"center",gap:"3px",color:E,fontWeight:600,cursor:"pointer",letterSpacing:C?"0.08em":void 0},title:P?"Sign in to BotBuddy to refresh 2FA":N?se||"Failed":C?`Clipboard blocked \u2014 code: ${$.code}`:c?`${d.length} 2FA personas`:`Copy 2FA code for ${d[0]}`,children:[jsxRuntime.jsx(S,{d:P?m.key:N?m.alert:A?m.check:C?m.copy:m.shield,size:10}),P?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Sign in"}):A?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Copied"}):C?jsxRuntime.jsx(jsxRuntime.Fragment,{children:$.code}):N?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Failed"}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["2FA",c&&` \xB7${d.length}`]})]})}if(d.length===1){let c=d[0],L=Y===c,P=$?.slug===c,R=P&&$.copied,N=P&&!$.copied,D=Ne===c,A=Z===c,C=A?s.blue:D?s.red:R?s.green:N?s.amber:s.purple;return jsxRuntime.jsxs("button",{onClick:E=>{E.stopPropagation(),he(c);},disabled:L,style:{...Bt(C),cursor:L?"wait":"pointer",opacity:L?.6:1},title:A?"Sign in to BotBuddy to refresh 2FA":D?se||"Failed":N?`Clipboard blocked \u2014 code: ${$.code}`:`Copy 2FA code for ${c}`,children:[jsxRuntime.jsx(S,{d:A?m.key:D?m.alert:R?m.check:N?m.copy:m.shield,size:12}),A?"Sign in":R?"Copied":N?$.code:D?"Failed":L?"\u2026":`2FA \xB7 ${c}`]})}let de=!!Z&&!U,Q=!!Ne&&!U,ve=!!$&&$.copied,we=!!$&&!$.copied,Oe=de?s.blue:Q?s.red:ve?s.green:we?s.amber:s.purple,He=U&&typeof document<"u"?reactDom.createPortal(jsxRuntime.jsxs("div",{ref:Ce,onPointerDown:c=>c.stopPropagation(),onMouseDown:c=>c.stopPropagation(),style:{position:"fixed",left:-9999,top:-9999,background:s.bg,border:`1px solid ${s.border}`,borderRadius:6,boxShadow:`0 8px 24px ${s.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:[d.map(c=>{let L=Y===c,P=Z===c;return jsxRuntime.jsxs("button",{onClick:R=>{R.stopPropagation(),he(c);},disabled:L,style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 8px",background:"transparent",border:"none",borderRadius:4,cursor:L?"wait":"pointer",fontSize:"10px",color:P?s.blue:s.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},title:P?"Sign in to BotBuddy to refresh 2FA":void 0,onMouseEnter:R=>R.currentTarget.style.background=s.btnHover,onMouseLeave:R=>R.currentTarget.style.background="transparent",children:[jsxRuntime.jsx(S,{d:P?m.key:m.shield,size:10}),jsxRuntime.jsx("span",{style:{flex:1,overflowWrap:"anywhere",lineHeight:1.3},children:c}),P?jsxRuntime.jsx("span",{style:{color:s.blue,fontSize:9},children:"Sign in"}):L?jsxRuntime.jsx("span",{style:{color:s.textMuted,fontSize:9},children:"\u2026"}):null]},c)}),se&&jsxRuntime.jsx("div",{style:{padding:"4px 8px",fontSize:9,color:s.red},children:se})]}),document.body):null;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("button",{ref:xe,onClick:c=>{if(c.stopPropagation(),de&&Z){oe(Z);return}q(L=>!L),f(null),ae(null);},style:{...Bt(Oe),cursor:"pointer"},title:de?"Sign in to BotBuddy to refresh 2FA":Q?se||"Failed":we?`Clipboard blocked \u2014 code: ${$.code}`:"Choose a persona to copy a 2FA code for",children:[jsxRuntime.jsx(S,{d:de?m.key:Q?m.alert:ve?m.check:we?m.copy:m.shield,size:12}),de?"Sign in":ve?"Copied":we?$.code:Q?"Failed":`2FA \xB7 ${d.length}`,!de&&jsxRuntime.jsx(S,{d:U?m.chevronUp:m.chevronDown,size:8})]}),He]})}function Bt(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 zt="botbuddy-widget-state";function xn({config:e,appSlug:n,environment:i,ticketId:d,testRunId:a,testRunToken:s,targetUrl:_,version:k,commitSha:h,prNumber:p,branchName:y,onNavigate:T,displayName:V="human",defaultMode:M="mini",defaultPosition:v}){let x=un(),r=react.useMemo(()=>pn(x),[x]),u=react.useMemo(()=>yn(r),[r]),[J,U]=react.useState(false),[q,Y]=react.useState(false),[I,$]=react.useState(false),Me=react.useRef(false),se=e.dashboardUrl||"https://app.bot-buddy.ai",f=ot(se),ae=(()=>{try{let t=typeof window<"u"?localStorage.getItem(zt):null;if(t)return JSON.parse(t)}catch{}return null})(),[ne,X]=react.useState(ae?.mode||M),[Z,le]=react.useState(""),[ye,oe]=react.useState(null),[he,xe]=react.useState(null),[Ce,de]=react.useState(new Set),[Q,ve]=react.useState(""),we=react.useCallback(t=>{de(g=>{let w=new Set(g);return w.has(t)?w.delete(t):w.add(t),w});},[]),Oe=ae?.x??v?.x??16,He=ae?.y??v?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:c,setPos:L,onPointerDown:P,onPointerMove:R,onPointerUp:N,didDrag:D}=Ge(Oe,He),A=react.useRef(null);react.useEffect(()=>{try{localStorage.setItem(zt,JSON.stringify({mode:ne,x:c.x,y:c.y}));}catch{}},[ne,c.x,c.y]),react.useLayoutEffect(()=>{if(typeof window>"u")return;let t=A.current;if(!t)return;let g=t.getBoundingClientRect(),w=qe(c.x,c.y,g.width,g.height,window.innerWidth,window.innerHeight);(w.x!==c.x||w.y!==c.y)&&L(w);}),react.useEffect(()=>{if(typeof window>"u")return;let t=()=>{let g=A.current;if(!g)return;let w=g.getBoundingClientRect(),W=qe(c.x,c.y,w.width,w.height,window.innerWidth,window.innerHeight);(W.x!==c.x||W.y!==c.y)&&L(W);};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[c.x,c.y,L]);let C=react.useRef(f.isAuthenticated);react.useEffect(()=>{!C.current&&f.isAuthenticated&&X("max"),C.current=f.isAuthenticated;},[f.isAuthenticated]);let E="botbuddy-widget-max-size",z=()=>{try{let t=localStorage.getItem(E);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[G,fe]=react.useState(z),Te=react.useRef(false),Pe=react.useRef({x:0,y:0,w:0,h:0}),It=react.useCallback(t=>{t.stopPropagation(),Te.current=true,Pe.current={x:t.clientX,y:t.clientY,w:G.w,h:G.h},t.target.setPointerCapture(t.pointerId);},[G]),Ft=react.useCallback(t=>{if(!Te.current)return;let g=Math.max(280,Math.min(600,Pe.current.w+(t.clientX-Pe.current.x))),w=Math.max(300,Math.min(window.innerHeight*.9,Pe.current.h+(t.clientY-Pe.current.y)));fe({w:g,h:w});},[]),Dt=react.useCallback(()=>{Te.current&&(Te.current=false,fe(t=>(localStorage.setItem(E,JSON.stringify(t)),t)));},[]),ee=_??(typeof window<"u"?window.location.href:void 0),at=f.displayName||V,[ie,lt]=react.useState(null);react.useEffect(()=>{if(f.isAuthenticated)return;let t=new URLSearchParams;s&&t.set("token",s),d&&t.set("ticket_id",d),t.set("app_slug",n),i&&t.set("environment",i),a&&t.set("test_run_id",a),ee&&t.set("target_url",ee),k&&t.set("version",k),h&&t.set("commit_sha",h),p&&t.set("pr_number",String(p)),y&&t.set("branch_name",y),fetch(`${e.serverUrl}/widget/preview?${t}`,{headers:{apikey:e.anonKey}}).then(g=>g.json()).then(g=>lt(g)).catch(()=>lt(null));},[f.isAuthenticated,e.serverUrl,e.anonKey,n,i,d,a,s,ee,k,h,p,y]);let dt=react.useRef(false),Ot=react.useCallback(()=>{dt.current||f.logout();},[f.logout]),{run:b,widgetState:be,fetchRun:Ht,setVerdict:ct,markComplete:Kt,resetRun:jt,setRun:ut}=Qe({config:e,appSlug:n,environment:i,ticketId:d,testRunId:a,testRunToken:s,targetUrl:ee,version:k,commitSha:h,prNumber:p?String(p):void 0,branchName:y,authToken:f.token,onAuthExpired:Ot});dt.current=!!b;let[pt,gt]=react.useState([]),[ft,Be]=react.useState([]),[Ke,bt]=react.useState(false),[mt,yt]=react.useState(null),[Vt,ze]=react.useState(false),ce=mn(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);react.useEffect(()=>{if((i??"local")!=="local"||ce){gt([]);return}let t=true;return Fe().then(g=>{t&>(Object.keys(g||{}));}),()=>{t=false;}},[i,ce]);let Yt=react.useCallback(async()=>{if(!(!f.isAuthenticated||!f.token)){bt(true),yt(null);try{let t=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${f.token}`},body:JSON.stringify({app_slug:n,environment:i||"local",target_url:ee,branch_name:y,commit_sha:h,pr_number:p,ticket_id:d,title:`${d||n} local validation`})}),g=await t.json().catch(()=>({}));if(!t.ok)throw new Error(g.error||`HTTP ${t.status}`);ut(g),X("max");}catch(t){yt(t.message);}finally{bt(false);}}},[f.isAuthenticated,f.token,e.serverUrl,e.anonKey,n,i,ee,y,h,p,d,ut]),$e=react.useCallback(async(t,g,w)=>{xe(t);try{await ct(t,g,w,at);}finally{xe(null),oe(null),le("");}},[ct,at]),F=b?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},Jt=F.total>0&&F.pending===0,ke=be==="completed",Ae=react.useMemo(()=>{let t=b?.test_cases||[];if(!Q.trim())return t;let g=Q.toLowerCase();return t.filter(w=>w.title.toLowerCase().includes(g)||w.description&&w.description.toLowerCase().includes(g)||w.url_path&&w.url_path.toLowerCase().includes(g)||w.seed_user&&w.seed_user.toLowerCase().includes(g))},[b?.test_cases,Q]),ht=react.useMemo(()=>{let t=Ae,g=b?.test_cases||[];if(new Set(g.map(K=>K.source_pr_number)).size<=1)return null;let W=[],pe=new Map;t.forEach(K=>{let H=K.source_pr_number;pe.has(H)||pe.set(H,[]),pe.get(H).push(K);});let Mt=[...pe.keys()].sort((K,H)=>K===null?1:H===null?-1:H-K);for(let K of Mt){let H=pe.get(K),Ve={total:H.length,pass:0,fail:0,skip:0,pending:0};H.forEach(Ct=>{Ct.verdict in Ve&&Ve[Ct.verdict]++;}),W.push({key:K!=null?`pr-${K}`:"general",label:K!=null?`PR #${K}`:"General",cases:H,summary:Ve});}return W.filter(K=>K.cases.length>0)},[Ae,b?.test_cases]),xt=F.total>0?(F.pass+F.fail)/F.total*100:0,O=i??b?.environment??null,ue=react.useMemo(()=>{if(!O||O==="production"||ce)return [];let t=b?.test_cases||[],g=new Set;for(let w of t)w.seed_user&&g.add(it(w.seed_user));if(O==="local")for(let w of pt)g.add(it(w));for(let w of ft)g.add(it(w));return [...g]},[b?.test_cases,O,pt,ft,ce]);react.useEffect(()=>{if(!O||O==="production"||ce||!f.isAuthenticated||!f.token){Be([]);return}let t=true,g=`${e.serverUrl}/widget/totp-seeds?${new URLSearchParams({app_slug:n,environment:O})}`,w=W=>fetch(g,{headers:{apikey:e.anonKey,Authorization:`Bearer ${W}`}});return (async()=>{try{let W=await w(f.token);if(W.status===401&&f.refreshNow){let H=await f.refreshNow();H&&(W=await w(H));}if(!t)return;if(!W.ok){Be([]);return}let pe=await W.json().catch(()=>null),K=(Array.isArray(pe?.seeds)?pe.seeds:[]).map(H=>H?.seed_user_slug).filter(H=>typeof H=="string"&&H.length>0);Be(K);}catch{t&&Be([]);}})(),()=>{t=false;}},[O,ce,f.isAuthenticated,f.token,f.refreshNow,n,e.serverUrl,e.anonKey]);let je=react.useMemo(()=>{let t=b?.auto_tooltip_seconds??ie?.auto_tooltip_seconds;return t!=null&&t>0?t*1e3:0},[b,ie]),vt=be==="ready"||be==="completed"||ie?.enabled&&ie.run;react.useEffect(()=>{if(!vt||Me.current||je<=0)return;Me.current=true,Y(true);let t=window.setTimeout(()=>Y(false),je);return ()=>window.clearTimeout(t)},[vt,je]);let wt=t=>jsxRuntime.jsxs("div",{style:u.caseRow,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsx("div",{style:{marginTop:"2px",flexShrink:0,color:gn[t.verdict]},children:he===t.id?jsxRuntime.jsx(S,{d:m.loader,className:""}):jsxRuntime.jsx(S,{d:fn[t.verdict],className:""})}),jsxRuntime.jsxs("div",{style:{minWidth:0,flex:1},children:[jsxRuntime.jsx("div",{style:{fontSize:"10px",color:r.text,lineHeight:1.3},children:t.title}),t.description&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:r.gripColor,marginTop:"2px"},children:t.description}),t.seed_user&&jsxRuntime.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:[jsxRuntime.jsx(S,{d:m.key,size:10}),jsxRuntime.jsx("span",{children:t.seed_user})]}),t.url_path&&jsxRuntime.jsxs("a",{href:t.url_path,target:"_blank",rel:"noopener noreferrer",onClick:g=>{g.stopPropagation(),T&&(g.preventDefault(),T(t.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:[jsxRuntime.jsx(S,{d:m.externalLink,size:10}),t.url_path]}),t.verdict==="fail"&&t.fail_reason&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:r.red,marginTop:"2px"},children:["\u2717 ",t.fail_reason]})]})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(g=>jsxRuntime.jsx("button",{onClick:()=>{if(t.verdict===g){$e(t.id,"pending"),oe(null);return}if(g==="fail"){oe(t.id),le("");return}oe(null),$e(t.id,g);},disabled:he!==null,style:u.verdictBtn(t.verdict===g,g==="pass"?r.green:g==="fail"?r.red:r.amber),children:g.toUpperCase()},g)),t.created_by_agent_name&&jsxRuntime.jsxs("span",{style:{fontSize:"8px",color:r.purple,marginLeft:"4px",display:"inline-flex",alignItems:"center",gap:"2px"},children:[jsxRuntime.jsx(S,{d:m.bot,size:8}),t.created_by_agent_name]}),t.verdict_by_display_name&&jsxRuntime.jsxs("span",{style:{fontSize:"8px",color:r.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[t.verdict_by_display_name,t.verdict_at&&jsxRuntime.jsx("span",{style:{opacity:.7},children:cn(t.verdict_at)})]})]}),ye===t.id&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:Z,onChange:g=>le(g.target.value),onKeyDown:g=>{g.key==="Enter"&&$e(t.id,"fail",Z.trim()||void 0),g.key==="Escape"&&(oe(null),le(""));},placeholder:"Reason (optional)...",style:u.input}),jsxRuntime.jsx("button",{onClick:()=>{$e(t.id,"fail",Z.trim()||void 0);},style:u.verdictBtn(true,r.red),children:"\u2713"})]})]},t.id);if((be==="no-match"||be==="loading")&&!(!f.isAuthenticated&&ie?.enabled&&ie.run)){if(!(O==="local"&&!ce))return null}if(!f.isAuthenticated&&ie?.enabled&&ie.run){let t=ie.run,g=t.summary,w=t.status==="completed";return jsxRuntime.jsx("div",{ref:A,style:{...u.root,left:c.x,top:c.y},children:jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>U(true),onMouseLeave:()=>{U(false),$(false),Y(false);},children:[jsxRuntime.jsxs("div",{style:{...u.pill(w),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:P,onPointerMove:R,onPointerUp:()=>{N();},children:[jsxRuntime.jsx(S,{d:m.grip,size:10,className:""}),t.ticket_id&&t.ticket_url?jsxRuntime.jsx("a",{href:t.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:r.amber,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:t.ticket_id}):null,t.pr_url?jsxRuntime.jsxs("a",{href:t.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:r.blue,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:["PR#",t.pr_number??t.pr_id]}):null,t.created_by_agent_name?t.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${t.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:r.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(S,{d:m.terminal,size:10}),t.created_by_agent_name]}):jsxRuntime.jsxs("span",{style:{color:r.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(S,{d:m.bot,size:10}),t.created_by_agent_name]}):null,jsxRuntime.jsxs("span",{style:w?{color:r.green}:void 0,children:[g.pass,"/",g.total]}),g.fail>0&&jsxRuntime.jsxs("span",{style:{color:r.red},children:[g.fail,"\u2717"]}),jsxRuntime.jsx("span",{onClick:W=>{W.stopPropagation(),f.openLogin();},style:{color:r.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!I&&(J||q)&&t.title&&jsxRuntime.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:[jsxRuntime.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:t.title}),(t.description||t.intro_notes)&&jsxRuntime.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:t.description||t.intro_notes}),jsxRuntime.jsx("div",{style:{marginTop:"4px",fontSize:"9px",color:r.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!f.isAuthenticated)return jsxRuntime.jsxs("div",{ref:A,style:{...u.root,left:c.x,top:c.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:P,onPointerMove:R,onPointerUp:N,children:[jsxRuntime.jsx("div",{style:{...u.handle,borderBottom:"none"},children:jsxRuntime.jsxs("div",{style:u.sub,children:[jsxRuntime.jsx(S,{d:m.grip,size:10,className:""}),jsxRuntime.jsx(S,{d:m.clipboard,size:12,className:""}),jsxRuntime.jsx("span",{style:{fontWeight:600},children:"BotBuddy"})]})}),jsxRuntime.jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[jsxRuntime.jsx("div",{style:{fontSize:"9px",color:r.textMuted,marginBottom:"8px"},children:"Sign in to access test cases"}),O==="local"&&ue.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsxRuntime.jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,testRunId:b?.id||a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:h,prNumber:p,branchName:y,onAuthExpired:f.logout})}),jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),f.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(!b&&O==="local"&&!ce)return Vt?jsxRuntime.jsx("div",{ref:A,style:{...u.root,left:c.x,top:c.y},children:jsxRuntime.jsxs("div",{style:u.card(240,false),children:[jsxRuntime.jsxs("div",{style:u.handle,onPointerDown:P,onPointerMove:R,onPointerUp:N,onClick:()=>{D.current||ze(false);},children:[jsxRuntime.jsx(S,{d:m.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:u.title,children:"BotBuddy"}),y&&jsxRuntime.jsx("div",{style:u.sub,children:jsxRuntime.jsxs("span",{children:["\u2387 ",y]})})]}),jsxRuntime.jsx(S,{d:m.chevronUp,className:""}),jsxRuntime.jsx("button",{style:u.btn,onClick:t=>{t.stopPropagation(),ze(false);},children:jsxRuntime.jsx(S,{d:m.minus,className:""})})]}),jsxRuntime.jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[ue.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsxRuntime.jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,testRunId:a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:h,prNumber:p,branchName:y,onAuthExpired:f.logout})}),jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),Yt();},disabled:Ke,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${r.green}`,background:`${r.green}22`,color:r.green,cursor:Ke?"wait":"pointer",width:"100%"},children:Ke?"Creating...":"Create test run for this branch"}),mt&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:r.red,marginTop:"8px"},children:mt})]})]})}):jsxRuntime.jsx("div",{ref:A,style:{...u.root,left:c.x,top:c.y},children:jsxRuntime.jsxs("div",{style:{...u.pill(false),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:P,onPointerMove:R,onPointerUp:()=>{N(),D.current||ze(true);},children:[jsxRuntime.jsx(S,{d:m.grip,size:9,className:""}),jsxRuntime.jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),ue.length>0&&jsxRuntime.jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,compact:true,onExpand:()=>ze(true),testRunId:a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:h,prNumber:p,branchName:y,onAuthExpired:f.logout})]})});let kt=()=>{D.current||(Y(false),X(t=>{let g=t==="mini"?"max":"mini";return $(g==="mini"),g}));},St=({icon:t,onClick:g})=>jsxRuntime.jsx("button",{style:u.btn,onClick:w=>{w.stopPropagation(),g(w);},children:jsxRuntime.jsx(S,{d:t,className:""})}),_t=()=>jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${r.borderSubtle}`,flexShrink:0},children:[b?.pr_url&&jsxRuntime.jsxs("a",{href:b.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...u.link(r.blue),textDecoration:"none"},children:[jsxRuntime.jsx(S,{d:m.pr,size:12}),b.pr_number?`PR#${b.pr_number}`:b.pr_id||"PR",jsxRuntime.jsx(S,{d:m.externalLink,size:8})]}),b?.ticket_url&&jsxRuntime.jsxs("a",{href:b.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...u.link(r.amber),textDecoration:"none"},children:[jsxRuntime.jsx(S,{d:m.ticket,size:12}),b.ticket_id||"Ticket",jsxRuntime.jsx(S,{d:m.externalLink,size:8})]}),b?.created_by_agent_name&&(b.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${b.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...u.link(r.purple),textDecoration:"none"},children:[jsxRuntime.jsx(S,{d:m.bot,size:12}),b.created_by_agent_name,jsxRuntime.jsx(S,{d:m.externalLink,size:8})]}):jsxRuntime.jsxs("span",{style:{...u.link(r.purple)},children:[jsxRuntime.jsx(S,{d:m.bot,size:12}),b.created_by_agent_name]})),O&&jsxRuntime.jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,testRunId:b?.id||a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:h,prNumber:p,branchName:y,onAuthExpired:f.logout}),jsxRuntime.jsx("span",{style:{...u.badge(b?.environment||"custom"),marginLeft:"auto"},children:b?.environment})]}),Rt=()=>jsxRuntime.jsxs("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:`1px solid ${r.borderSubtle}`,background:r.bgSoft,flexShrink:0},children:[jsxRuntime.jsxs("button",{onClick:()=>{navigator.clipboard.writeText(Lt);},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 ",jsxRuntime.jsxs("span",{style:{color:r.versionNum},children:["v",Lt]})]}),f.isAuthenticated&&(f.isExpired?jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),f.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"}):jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),f.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 jsxRuntime.jsxs("div",{ref:A,style:{...u.root,left:c.x,top:c.y},children:[ne==="mini"&&jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>U(true),onMouseLeave:()=>{U(false),$(false),Y(false);},children:[jsxRuntime.jsxs("div",{style:{...u.pill(ke),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:P,onPointerMove:R,onPointerUp:()=>{N(),D.current||kt();},children:[jsxRuntime.jsx(S,{d:m.grip,size:9,className:""}),b?.ticket_id&&jsxRuntime.jsx("span",{style:{color:r.amber,fontWeight:600},children:b.ticket_id}),b?.pr_number&&jsxRuntime.jsxs("span",{style:{color:r.blue,fontWeight:600},children:["PR#",b.pr_number]}),jsxRuntime.jsxs("span",{style:ke?{color:r.green}:void 0,children:[F.pass,"/",F.total]}),F.fail>0&&jsxRuntime.jsxs("span",{style:{color:r.red},children:[F.fail,"\u2717"]}),O&&jsxRuntime.jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,compact:true,onExpand:()=>X("expanded"),testRunId:b?.id||a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:h,prNumber:p,branchName:y,onAuthExpired:f.logout})]}),!I&&(J||q)&&b?.title&&jsxRuntime.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:[jsxRuntime.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:b.title}),(b.description||b.intro_notes)&&jsxRuntime.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:b.description||b.intro_notes})]})]}),ne==="expanded"&&jsxRuntime.jsxs("div",{style:u.card(300,ke),children:[jsxRuntime.jsxs("div",{style:u.handle,onPointerDown:P,onPointerMove:R,onPointerUp:N,onClick:kt,children:[jsxRuntime.jsx(S,{d:m.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:u.title,children:b?.title}),jsxRuntime.jsx("div",{style:u.sub,children:b?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",b.branch_name]})})]}),jsxRuntime.jsx(S,{d:m.chevronUp,className:""}),jsxRuntime.jsx(St,{icon:m.minus,onClick:()=>{Y(false),$(true),X("mini");}})]}),jsxRuntime.jsxs("div",{style:u.stats,children:[jsxRuntime.jsxs("span",{style:{color:r.green},children:[F.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:r.red},children:[F.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:r.amber},children:[F.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:r.gripColor},children:[F.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:F.total})]}),b?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:r.gripColor,borderBottom:`1px solid ${r.borderSubtle}`,flexShrink:0},children:b.description}),_t(),Rt(),jsxRuntime.jsx("div",{style:u.progress,children:jsxRuntime.jsx("div",{style:u.progressBar(xt)})})]}),ne==="max"&&jsxRuntime.jsxs("div",{style:{...u.card(G.w,ke),height:G.h,position:"relative"},children:[jsxRuntime.jsxs("div",{style:u.handle,onPointerDown:P,onPointerMove:R,onPointerUp:N,onClick:()=>{D.current||X("expanded");},children:[jsxRuntime.jsx(S,{d:m.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:u.title,children:b?.title}),jsxRuntime.jsx("div",{style:u.sub,children:b?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",b.branch_name]})})]}),jsxRuntime.jsx(S,{d:m.chevronDown,className:""}),jsxRuntime.jsx(St,{icon:m.minus,onClick:()=>{Y(false),$(true),X("mini");}})]}),jsxRuntime.jsxs("div",{style:u.stats,children:[jsxRuntime.jsxs("span",{style:{color:r.green},children:[F.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:r.red},children:[F.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:r.amber},children:[F.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:r.gripColor},children:[F.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:F.total})]}),b?.intro_notes&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${r.borderSubtle}`,fontSize:"10px",color:r.textMuted,fontStyle:"italic",flexShrink:0},children:b.intro_notes}),(b?.test_cases||[]).length>5&&jsxRuntime.jsxs("div",{style:{padding:"4px 12px",borderBottom:`1px solid ${r.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[jsxRuntime.jsx(S,{d:m.search,size:11,className:""}),jsxRuntime.jsx("input",{value:Q,onChange:t=>ve(t.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:r.text,fontFamily:"monospace"}}),Q&&jsxRuntime.jsx("button",{onClick:()=>ve(""),style:{background:"none",border:"none",cursor:"pointer",color:r.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),be==="error"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsxRuntime.jsx(S,{d:m.alert,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:r.red},children:"Failed to load"}),jsxRuntime.jsx("button",{onClick:Ht,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),ke&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg},children:[jsxRuntime.jsx(S,{d:m.checkAll,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",color:r.green,flex:1},children:"Run completed"}),jsxRuntime.jsx("button",{onClick:jt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),be!=="error"&&jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(b?.test_cases||[]).length===0?jsxRuntime.jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:"No test cases"}):Ae.length===0?jsxRuntime.jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:['No matches for "',Q,'"']}):ht?ht.map(t=>{let g=Ce.has(t.key);return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>we(t.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:[jsxRuntime.jsx(S,{d:g?m.chevronDown:m.chevronUp,size:10,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",fontWeight:700,color:r.blue,flex:1,textAlign:"left"},children:t.label}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:r.green},children:[t.summary.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:r.red},children:[t.summary.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:r.gripColor},children:[t.summary.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{fontSize:"9px",color:r.textFaint},children:t.summary.total})]}),!g&&t.cases.map(w=>wt(w))]},t.key)}):Ae.map(t=>wt(t))}),Jt&&!ke&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",borderTop:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg,display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsxRuntime.jsx("span",{style:{fontSize:"9px",color:r.green},children:"All resolved"}),jsxRuntime.jsx("button",{onClick:Kt,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"})]}),_t(),Rt(),jsxRuntime.jsx("div",{style:u.progress,children:jsxRuntime.jsx("div",{style:u.progressBar(xt)})}),jsxRuntime.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:It,onPointerMove:Ft,onPointerUp:Dt,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{Te.current||(t.currentTarget.style.opacity="0.3");},children:jsxRuntime.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsxRuntime.jsx("path",{d:"M7 1v6H1",fill:"none",stroke:r.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}function Sn(e){let n=e;return !!n&&typeof n=="object"&&typeof n.tenant=="string"&&Array.isArray(n.entries)&&n.entries.every(i=>!!i&&typeof i.id=="string"&&typeof i.title=="string"&&!!i.body&&Array.isArray(i.body.ast)&&Array.isArray(i.links))}function st({endpoint:e,getToken:n}){let[i,d]=react.useState({feed:null,error:null,loading:true}),[a,s]=react.useState(0),_=react.useRef(n);_.current=n,react.useEffect(()=>{let h=true;return d(p=>({...p,error:null,loading:true})),(async()=>{try{let p=await _.current(),y=await fetch(e,{headers:{authorization:`Bearer ${p}`}}),T=null;try{T=await y.json();}catch{T=null;}if(!h)return;if(y.ok)Sn(T)?d({feed:T,error:null,loading:!1}):d({feed:null,error:"invalid_feed",loading:!1});else {let V=T?.error;d({feed:null,error:typeof V=="string"?V:`http_${y.status}`,loading:!1});}}catch(p){h&&d({feed:null,error:p instanceof Error&&p.message||"unavailable",loading:false});}})(),()=>{h=false;}},[e,a]);let k=react.useCallback(()=>s(h=>h+1),[]);return {...i,reload:k}}function Ut(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 De(e,n=""){return e.map((i,d)=>{let a=`${n}${d}`;switch(i.t){case "text":return i.v;case "code":return jsxRuntime.jsx("code",{className:"bbrn-code",children:i.v},a);case "strong":return jsxRuntime.jsx("strong",{children:De(i.c,`${a}.`)},a);case "em":return jsxRuntime.jsx("em",{children:De(i.c,`${a}.`)},a);default:return null}})}function Wt({ast:e}){return jsxRuntime.jsx(jsxRuntime.Fragment,{children:e.map((n,i)=>n.t==="list"?jsxRuntime.jsx("ul",{className:"bbrn-list",children:n.items.map((d,a)=>jsxRuntime.jsx("li",{children:De(d)},a))},i):n.t==="p"?jsxRuntime.jsx("p",{className:"bbrn-p",children:De(n.c)},i):null)})}var _n=`@layer bbrn {
|
|
2
|
+
.bbrn-root{display:grid;gap:12px;color:inherit;font:inherit}
|
|
3
|
+
.bbrn-root .bbrn-entry{border:1px solid hsl(var(--border,214 32% 91%));border-radius:var(--radius,.5rem);padding:16px;background:hsl(var(--card,0 0% 100%))}
|
|
4
|
+
.bbrn-root .bbrn-head{display:flex;gap:8px;align-items:baseline;flex-wrap:wrap}
|
|
5
|
+
.bbrn-root .bbrn-title{font-weight:600;font-size:1rem;margin:0}
|
|
6
|
+
.bbrn-root .bbrn-badge{font-size:.75rem;border:1px solid currentColor;border-radius:999px;padding:0 8px}
|
|
7
|
+
.bbrn-root .bbrn-meta{color:hsl(var(--muted-foreground,215 16% 47%));font-size:.8rem}
|
|
8
|
+
.bbrn-root .bbrn-p{margin:.5em 0}
|
|
9
|
+
.bbrn-root .bbrn-list{margin:.5em 0;padding-left:1.25em;list-style:disc}
|
|
10
|
+
.bbrn-root .bbrn-code{font-family:ui-monospace,monospace;font-size:.85em;padding:0 4px;border-radius:4px;background:hsl(var(--muted,210 40% 96%))}
|
|
11
|
+
.bbrn-root .bbrn-links{display:flex;gap:12px;flex-wrap:wrap;margin-top:8px;font-size:.85rem}
|
|
12
|
+
.bbrn-root .bbrn-link{text-decoration:underline}
|
|
13
|
+
.bbrn-root .bbrn-retry{margin-left:8px;text-decoration:underline;background:none;border:0;padding:0;color:inherit;cursor:pointer;font:inherit}
|
|
14
|
+
}`;function Rn({endpoint:e,getToken:n,onNavigate:i}){let{feed:d,error:a,loading:s,reload:_}=st({endpoint:e,getToken:n}),k=h=>p=>{!i||p.defaultPrevented||p.button!==0||p.metaKey||p.ctrlKey||p.shiftKey||p.altKey||(p.preventDefault(),i(h));};return jsxRuntime.jsxs("section",{className:"bbrn-root","aria-label":"Release notes","aria-busy":s,"data-bbrn-audience":d?.audience,children:[jsxRuntime.jsx("style",{children:_n}),s&&!d&&jsxRuntime.jsx("p",{className:"bbrn-meta",role:"status",children:"Loading release notes\u2026"}),!s&&a&&jsxRuntime.jsxs("p",{className:"bbrn-meta",role:"alert","data-bbrn-error":a,children:["Release notes could not be loaded.",jsxRuntime.jsx("button",{type:"button",className:"bbrn-retry",onClick:_,children:"Retry"})]}),!a&&d&&d.entries.length===0&&jsxRuntime.jsxs("p",{className:"bbrn-meta",children:["No release notes yet. Submit one with ",jsxRuntime.jsx("code",{className:"bbrn-code",children:"bb release-notes submit"}),"."]}),!a&&d?.entries.map(h=>jsxRuntime.jsxs("article",{className:"bbrn-entry","data-entry-id":h.id,"data-source-key":h.source_key,children:[jsxRuntime.jsxs("div",{className:"bbrn-head",children:[jsxRuntime.jsx("h2",{className:"bbrn-title",children:h.title}),jsxRuntime.jsx("span",{className:"bbrn-badge","data-bbrn-type":h.type,children:h.type}),jsxRuntime.jsxs("span",{className:"bbrn-meta",children:[h.source_key," \xB7 ",h.state," \xB7 revision ",h.revision]})]}),jsxRuntime.jsx(Wt,{ast:h.body.ast}),h.links.length>0&&jsxRuntime.jsx("div",{className:"bbrn-links",children:h.links.map((p,y)=>{let T=Ut(p.url);return T?T.kind==="external"?jsxRuntime.jsx("a",{className:"bbrn-link",href:T.href,target:"_blank",rel:"noopener noreferrer","data-link-kind":p.kind??void 0,children:p.name},y):jsxRuntime.jsx("a",{className:"bbrn-link",href:T.href,onClick:k(T.href),"data-link-kind":p.kind??void 0,children:p.name},y):null})})]},h.id))]})}exports.ReleaseNoteBody=Wt;exports.ReleaseNotes=Rn;exports.TestRunWidget=xn;exports.safeHref=Ut;exports.useDraggable=Ge;exports.useRealtimeRefresh=Xe;exports.useReleaseNotes=st;exports.useTestRun=Qe;exports.useWidgetAuth=ot;
|
package/dist/index.d.cts
CHANGED
|
@@ -106,6 +106,71 @@ interface TestRunWidgetProps {
|
|
|
106
106
|
|
|
107
107
|
declare function TestRunWidget({ config, appSlug, environment, ticketId, testRunId, testRunToken, targetUrl, version, commitSha, prNumber, branchName, onNavigate, displayName, defaultMode, defaultPosition, }: TestRunWidgetProps): react_jsx_runtime.JSX.Element | null;
|
|
108
108
|
|
|
109
|
+
type ReleaseNoteInline = {
|
|
110
|
+
t: "text";
|
|
111
|
+
v: string;
|
|
112
|
+
} | {
|
|
113
|
+
t: "code";
|
|
114
|
+
v: string;
|
|
115
|
+
} | {
|
|
116
|
+
t: "strong";
|
|
117
|
+
c: ReleaseNoteInline[];
|
|
118
|
+
} | {
|
|
119
|
+
t: "em";
|
|
120
|
+
c: ReleaseNoteInline[];
|
|
121
|
+
};
|
|
122
|
+
type ReleaseNoteBlock = {
|
|
123
|
+
t: "p";
|
|
124
|
+
c: ReleaseNoteInline[];
|
|
125
|
+
} | {
|
|
126
|
+
t: "list";
|
|
127
|
+
items: ReleaseNoteInline[][];
|
|
128
|
+
};
|
|
129
|
+
interface ReleaseNoteBody$1 {
|
|
130
|
+
format: "bbrn-md-1";
|
|
131
|
+
source: string;
|
|
132
|
+
ast: ReleaseNoteBlock[];
|
|
133
|
+
}
|
|
134
|
+
interface ReleaseNoteLink {
|
|
135
|
+
name: string;
|
|
136
|
+
url: string;
|
|
137
|
+
kind: string | null;
|
|
138
|
+
}
|
|
139
|
+
interface ReleaseNoteEntry {
|
|
140
|
+
id: string;
|
|
141
|
+
source_key: string;
|
|
142
|
+
type: string;
|
|
143
|
+
state: string;
|
|
144
|
+
revision: number;
|
|
145
|
+
title: string;
|
|
146
|
+
body: ReleaseNoteBody$1;
|
|
147
|
+
links: ReleaseNoteLink[];
|
|
148
|
+
created_at: string;
|
|
149
|
+
updated_at: string;
|
|
150
|
+
}
|
|
151
|
+
interface ReleaseNotesFeed {
|
|
152
|
+
tenant: string;
|
|
153
|
+
audience: "internal";
|
|
154
|
+
entries: ReleaseNoteEntry[];
|
|
155
|
+
}
|
|
156
|
+
interface ReleaseNotesProps {
|
|
157
|
+
/** The feed URL, e.g. `${MCP_URL}/release-notes/feed?tenant=<slug>`. */
|
|
158
|
+
endpoint: string;
|
|
159
|
+
/** Returns the bearer for the feed (in BotBuddy, the signed-in session). */
|
|
160
|
+
getToken: () => Promise<string>;
|
|
161
|
+
/** Called with an app path (a link starting with one /) instead of a full page load. */
|
|
162
|
+
onNavigate?: (path: string) => void;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
declare function safeHref(url: string): {
|
|
166
|
+
kind: "external" | "internal";
|
|
167
|
+
href: string;
|
|
168
|
+
} | null;
|
|
169
|
+
declare function ReleaseNoteBody({ ast }: {
|
|
170
|
+
ast: ReleaseNoteBlock[];
|
|
171
|
+
}): react_jsx_runtime.JSX.Element;
|
|
172
|
+
declare function ReleaseNotes({ endpoint, getToken, onNavigate }: ReleaseNotesProps): react_jsx_runtime.JSX.Element;
|
|
173
|
+
|
|
109
174
|
declare function useDraggable(initialX: number, initialY: number): {
|
|
110
175
|
pos: {
|
|
111
176
|
x: number;
|
|
@@ -190,4 +255,16 @@ declare function useWidgetAuth(dashboardUrl: string): WidgetAuth;
|
|
|
190
255
|
*/
|
|
191
256
|
declare function useRealtimeRefresh(config: BotBuddyConfig, testRunId: string | null | undefined, onUpdate: () => void): void;
|
|
192
257
|
|
|
193
|
-
|
|
258
|
+
interface UseReleaseNotesOptions {
|
|
259
|
+
endpoint: string;
|
|
260
|
+
getToken: () => Promise<string>;
|
|
261
|
+
}
|
|
262
|
+
interface UseReleaseNotesState {
|
|
263
|
+
feed: ReleaseNotesFeed | null;
|
|
264
|
+
error: string | null;
|
|
265
|
+
loading: boolean;
|
|
266
|
+
reload: () => void;
|
|
267
|
+
}
|
|
268
|
+
declare function useReleaseNotes({ endpoint, getToken }: UseReleaseNotesOptions): UseReleaseNotesState;
|
|
269
|
+
|
|
270
|
+
export { type BotBuddyConfig, type ReleaseNoteBlock, ReleaseNoteBody, type ReleaseNoteBody$1 as ReleaseNoteBodyData, type ReleaseNoteEntry, type ReleaseNoteInline, type ReleaseNoteLink, ReleaseNotes, type ReleaseNotesFeed, type ReleaseNotesProps, type TestCase, type TestRun, type TestRunSummary, TestRunWidget, type TestRunWidgetProps, type UseReleaseNotesOptions, type UseReleaseNotesState, type Verdict, type WidgetMode, type WidgetState, safeHref, useDraggable, useRealtimeRefresh, useReleaseNotes, useTestRun, useWidgetAuth };
|
package/dist/index.d.ts
CHANGED
|
@@ -106,6 +106,71 @@ interface TestRunWidgetProps {
|
|
|
106
106
|
|
|
107
107
|
declare function TestRunWidget({ config, appSlug, environment, ticketId, testRunId, testRunToken, targetUrl, version, commitSha, prNumber, branchName, onNavigate, displayName, defaultMode, defaultPosition, }: TestRunWidgetProps): react_jsx_runtime.JSX.Element | null;
|
|
108
108
|
|
|
109
|
+
type ReleaseNoteInline = {
|
|
110
|
+
t: "text";
|
|
111
|
+
v: string;
|
|
112
|
+
} | {
|
|
113
|
+
t: "code";
|
|
114
|
+
v: string;
|
|
115
|
+
} | {
|
|
116
|
+
t: "strong";
|
|
117
|
+
c: ReleaseNoteInline[];
|
|
118
|
+
} | {
|
|
119
|
+
t: "em";
|
|
120
|
+
c: ReleaseNoteInline[];
|
|
121
|
+
};
|
|
122
|
+
type ReleaseNoteBlock = {
|
|
123
|
+
t: "p";
|
|
124
|
+
c: ReleaseNoteInline[];
|
|
125
|
+
} | {
|
|
126
|
+
t: "list";
|
|
127
|
+
items: ReleaseNoteInline[][];
|
|
128
|
+
};
|
|
129
|
+
interface ReleaseNoteBody$1 {
|
|
130
|
+
format: "bbrn-md-1";
|
|
131
|
+
source: string;
|
|
132
|
+
ast: ReleaseNoteBlock[];
|
|
133
|
+
}
|
|
134
|
+
interface ReleaseNoteLink {
|
|
135
|
+
name: string;
|
|
136
|
+
url: string;
|
|
137
|
+
kind: string | null;
|
|
138
|
+
}
|
|
139
|
+
interface ReleaseNoteEntry {
|
|
140
|
+
id: string;
|
|
141
|
+
source_key: string;
|
|
142
|
+
type: string;
|
|
143
|
+
state: string;
|
|
144
|
+
revision: number;
|
|
145
|
+
title: string;
|
|
146
|
+
body: ReleaseNoteBody$1;
|
|
147
|
+
links: ReleaseNoteLink[];
|
|
148
|
+
created_at: string;
|
|
149
|
+
updated_at: string;
|
|
150
|
+
}
|
|
151
|
+
interface ReleaseNotesFeed {
|
|
152
|
+
tenant: string;
|
|
153
|
+
audience: "internal";
|
|
154
|
+
entries: ReleaseNoteEntry[];
|
|
155
|
+
}
|
|
156
|
+
interface ReleaseNotesProps {
|
|
157
|
+
/** The feed URL, e.g. `${MCP_URL}/release-notes/feed?tenant=<slug>`. */
|
|
158
|
+
endpoint: string;
|
|
159
|
+
/** Returns the bearer for the feed (in BotBuddy, the signed-in session). */
|
|
160
|
+
getToken: () => Promise<string>;
|
|
161
|
+
/** Called with an app path (a link starting with one /) instead of a full page load. */
|
|
162
|
+
onNavigate?: (path: string) => void;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
declare function safeHref(url: string): {
|
|
166
|
+
kind: "external" | "internal";
|
|
167
|
+
href: string;
|
|
168
|
+
} | null;
|
|
169
|
+
declare function ReleaseNoteBody({ ast }: {
|
|
170
|
+
ast: ReleaseNoteBlock[];
|
|
171
|
+
}): react_jsx_runtime.JSX.Element;
|
|
172
|
+
declare function ReleaseNotes({ endpoint, getToken, onNavigate }: ReleaseNotesProps): react_jsx_runtime.JSX.Element;
|
|
173
|
+
|
|
109
174
|
declare function useDraggable(initialX: number, initialY: number): {
|
|
110
175
|
pos: {
|
|
111
176
|
x: number;
|
|
@@ -190,4 +255,16 @@ declare function useWidgetAuth(dashboardUrl: string): WidgetAuth;
|
|
|
190
255
|
*/
|
|
191
256
|
declare function useRealtimeRefresh(config: BotBuddyConfig, testRunId: string | null | undefined, onUpdate: () => void): void;
|
|
192
257
|
|
|
193
|
-
|
|
258
|
+
interface UseReleaseNotesOptions {
|
|
259
|
+
endpoint: string;
|
|
260
|
+
getToken: () => Promise<string>;
|
|
261
|
+
}
|
|
262
|
+
interface UseReleaseNotesState {
|
|
263
|
+
feed: ReleaseNotesFeed | null;
|
|
264
|
+
error: string | null;
|
|
265
|
+
loading: boolean;
|
|
266
|
+
reload: () => void;
|
|
267
|
+
}
|
|
268
|
+
declare function useReleaseNotes({ endpoint, getToken }: UseReleaseNotesOptions): UseReleaseNotesState;
|
|
269
|
+
|
|
270
|
+
export { type BotBuddyConfig, type ReleaseNoteBlock, ReleaseNoteBody, type ReleaseNoteBody$1 as ReleaseNoteBodyData, type ReleaseNoteEntry, type ReleaseNoteInline, type ReleaseNoteLink, ReleaseNotes, type ReleaseNotesFeed, type ReleaseNotesProps, type TestCase, type TestRun, type TestRunSummary, TestRunWidget, type TestRunWidgetProps, type UseReleaseNotesOptions, type UseReleaseNotesState, type Verdict, type WidgetMode, type WidgetState, safeHref, useDraggable, useRealtimeRefresh, useReleaseNotes, useTestRun, useWidgetAuth };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
import {useState,useRef,useCallback,useEffect,useMemo,useLayoutEffect}from'react';import {createPortal}from'react-dom';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Se=8;function Ve(e,r,s,p,u,a){let T=Math.max(Se,u-s-Se),S=Math.max(Se,a-p-Se);return {x:Math.min(Math.max(e,Se),T),y:Math.min(Math.max(r,Se),S)}}function Ye(e,r){let[s,p]=useState({x:e,y:r}),u=useRef(false),a=useRef({x:0,y:0}),T=useRef(false),S=useCallback(y=>{u.current=true,T.current=false,a.current={x:y.clientX-s.x,y:y.clientY-s.y},y.target.setPointerCapture(y.pointerId);},[s]),_=useCallback(y=>{u.current&&(T.current=true,p({x:y.clientX-a.current.x,y:y.clientY-a.current.y}));},[]),b=useCallback(()=>{u.current=false;},[]);return {pos:s,setPos:p,onPointerDown:S,onPointerMove:_,onPointerUp:b,didDrag:T}}function Je(e,r,s){let p=useRef(s);p.current=s,useEffect(()=>{if(!r)return;if(e.supabaseUrl){let a=false,T=null,S=()=>{a||T||(T=setInterval(()=>p.current(),15e3));},_=null;try{let m=new URL(e.supabaseUrl),n=["localhost","127.0.0.1","::1"].includes(m.hostname);if(m.protocol==="http:"&&!n)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");m.protocol=m.protocol==="https:"?"wss:":"ws:",_=m.toString().replace(/\/$/,"");}catch{S();}let b=null,y=null,F=null,Y=0,M=()=>{if(!(a||!_)){try{b=new WebSocket(`${_}/realtime/v1/websocket?apikey=${e.anonKey}&vsn=1.0.0`);}catch{S();return}b.onopen=()=>{if(a||!b)return;let m={topic:`realtime:public:test_run_cases:test_run_id=eq.${r}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_run_cases",filter:`test_run_id=eq.${r}`}]}},ref:String(++Y)};b.send(JSON.stringify(m));let n={topic:`realtime:public:test_runs:id=eq.${r}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_runs",filter:`id=eq.${r}`}]}},ref:String(++Y)};b.send(JSON.stringify(n)),y=setInterval(()=>{b?.readyState===WebSocket.OPEN&&b.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++Y)}));},3e4);},b.onmessage=m=>{try{JSON.parse(m.data).event==="postgres_changes"&&p.current();}catch{}},b.onclose=()=>{x(),a||(F=setTimeout(M,3e3));},b.onerror=()=>{b?.close();};}},x=()=>{y&&(clearInterval(y),y=null);};return M(),()=>{a=true,x(),F&&clearTimeout(F),T&&clearInterval(T),b&&(b.onclose=null,b.onerror=null,b.close());}}let u=setInterval(()=>p.current(),15e3);return ()=>clearInterval(u)},[e.supabaseUrl,e.anonKey,r]);}var Vt="botbuddy:created-test-run:";function Yt(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function Jt(e){return `${Vt}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",Yt(e.targetUrl),e.branchName||""].join("|"))}`}function Ae(e,r){let s={apikey:e.anonKey};return r?s.Authorization=`Bearer ${r}`:e.apiKey?s.Authorization=`Bearer ${e.apiKey}`:s.Authorization=`Bearer ${e.anonKey}`,s}async function qt(e){if(e)return e;try{let r=await fetch("/.botbuddy-token",{cache:"no-store"});if(r.ok){let s=(await r.text()).trim();if(s.startsWith("public_"))return s}}catch{}try{let r=import.meta?.env?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(r&&typeof r=="string"&&r.startsWith("public_"))return r}catch{}return null}function Ge(e){let[r,s]=useState(null),[p,u]=useState("loading"),a=Jt(e),[T,S]=useState(()=>{if(e.testRunId)return e.testRunId;try{return localStorage.getItem(a)||void 0}catch{return}}),_=e.testRunId||T,b=useCallback(x=>{if(s(x),!!x?.id){S(x.id);try{localStorage.setItem(a,x.id);}catch{}}},[a]),y=useCallback(async()=>{try{let x=await qt(e.testRunToken);if(!x&&!_){u("no-match"),s(null);return}if(x&&!e.ticketId){u("no-match"),s(null);return}let m=new URLSearchParams;x&&m.set("token",x),e.ticketId&&m.set("ticket_id",e.ticketId),m.set("app_slug",e.appSlug),e.environment&&m.set("environment",e.environment),_&&m.set("test_run_id",_),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 n=await fetch(`${e.config.serverUrl}/widget/test-run?${m.toString()}`,{headers:Ae(e.config,e.authToken)});if(n.status===404){u("no-match"),s(null);return}if(n.status===401||n.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),u("error");return}if(!n.ok){u("error");return}let d=await n.json();if(!d||d.run===null){u("no-match"),s(null);return}b(d),u(d.status==="completed"?"completed":"ready");}catch{u("error");}},[e.config.serverUrl,e.config.anonKey,e.config.apiKey,e.authToken,e.appSlug,e.environment,e.ticketId,_,e.testRunToken,e.targetUrl,e.version,e.commitSha,e.branchName,e.prNumber,e.onAuthExpired,b]);return useEffect(()=>{y();},[y]),Je(e.config,r?.id,y),{run:r,widgetState:p,fetchRun:y,setVerdict:async(x,m,n,d="human")=>(s(U=>{if(!U)return null;let J=U.test_cases.map(I=>I.id===x?{...I,verdict:m,fail_reason:m==="fail"&&n||null,verdict_by_display_name:d,verdict_at:new Date().toISOString()}:I),j={total:J.length,pending:0,pass:0,fail:0,skip:0};return J.forEach(I=>{I.verdict in j&&j[I.verdict]++;}),{...U,test_cases:J,summary:j}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${x}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...Ae(e.config,e.authToken)},body:JSON.stringify({verdict:m,fail_reason:n,display_name:d})})).ok),markComplete:async()=>r?(s(m=>m?{...m,status:"completed"}:null),u("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${r.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...Ae(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!r)return false;let x=await fetch(`${e.config.serverUrl}/widget/test-runs/${r.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...Ae(e.config,e.authToken)}});return x.ok&&y(),x.ok},setRun:b}}var Qe="botbuddy-widget-auth-token",et="botbuddy-widget-auth-name";function Re(e){if(!e)return null;try{let r=e.split(".")[1];if(!r)return null;let s=r.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(r.length/4)*4,"="),p=atob(s),u=JSON.parse(p);return typeof u.exp=="number"?u.exp*1e3:null}catch{return null}}var Xt=2500,Zt=6e4;function tt(e){let[r,s]=useState(()=>{try{return localStorage.getItem(Qe)}catch(M){return console.warn("Unable to read BotBuddy widget auth token",M),null}}),[p,u]=useState(()=>{try{return localStorage.getItem(et)}catch(M){return console.warn("Unable to read BotBuddy widget display name",M),null}}),a=useRef(null),T=useCallback((M,x)=>{s(M),x&&u(x);try{localStorage.setItem(Qe,M),x&&localStorage.setItem(et,x);}catch(m){console.warn("Unable to persist BotBuddy widget auth token",m);}},[]);useEffect(()=>{let M=new URL(e).origin,x=m=>{m.origin===M&&m.data?.type==="botbuddy-widget-auth"&&m.data.token&&T(m.data.token,m.data.displayName||"human");};return window.addEventListener("message",x),()=>window.removeEventListener("message",x)},[e,T]);let S=useCallback(()=>{if(a.current)return a.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 m=new Promise(n=>{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 V=false,U=()=>{window.removeEventListener("message",J),clearTimeout(j);try{d.remove();}catch{}a.current=null;},J=I=>{if(I.origin===M){if(I.data?.type==="botbuddy-widget-auth-failed"){if(V)return;V=true,n(null),U();return}I.data?.type!=="botbuddy-widget-auth"||!I.data.token||V||(V=true,n(String(I.data.token)),U());}},j=setTimeout(()=>{V||(V=true,n(null),U());},Xt);window.addEventListener("message",J),document.body.appendChild(d);});return a.current=m,m},[e]);useEffect(()=>{if(!r)return;let M=Re(r);if(!M)return;let x=M-Date.now()-Zt,m=window.setTimeout(()=>{S();},Math.max(0,x));return ()=>window.clearTimeout(m)},[r,S]);let _=useCallback(()=>{let M=new URL("/widget-auth",e);M.searchParams.set("origin",window.location.origin);let x=420,m=520,n=window.screenX+(window.innerWidth-x)/2,d=window.screenY+(window.innerHeight-m)/2;window.open(M.toString(),"botbuddy-auth",`width=${x},height=${m},left=${n},top=${d},popup=yes`);},[e]),[,b]=useState(0);useEffect(()=>{let M=Re(r);if(!M)return;let x=M-Date.now();if(x<=0)return;let m=window.setTimeout(()=>b(n=>n+1),x);return ()=>window.clearTimeout(m)},[r]);let y=useCallback(()=>{s(null),u(null);try{localStorage.removeItem(Qe),localStorage.removeItem(et);}catch(M){console.warn("Unable to clear BotBuddy widget auth token",M);}},[]),F=Re(r),Y=F!==null&&F<=Date.now();return {token:r,displayName:p,isAuthenticated:!!r,isExpired:Y,openLogin:_,refreshNow:S,logout:y}}var We=null;function Qt(){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 Ie(){return We||(We=(async()=>{if(typeof fetch>"u")return null;try{let e=await fetch(Qt(),{cache:"no-store"});if(!e.ok)return null;let r=await e.json();if(!r||typeof r!="object"||Array.isArray(r))return null;let s={};for(let[p,u]of Object.entries(r))typeof u=="string"&&u.length>0&&(s[p]=u);return s}catch{return null}})(),We)}async function Mt(e){return (await Ie())?.[e]??null}function en(e){let r=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),s="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",p=[],u=0,a=0;for(let T of r){let S=s.indexOf(T);if(S<0)throw new Error("Invalid Base32 character in TOTP secret");a=a<<5|S,u+=5,u>=8&&(u-=8,p.push(a>>>u&255));}return Uint8Array.from(p)}async function Ct(e,r=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let s=en(e),p=new Uint8Array(s.byteLength);p.set(s);let u=Math.floor(r/1e3/30),a=new Uint8Array(8),T=Math.floor(u/4294967296),S=u>>>0;a[0]=T>>>24&255,a[1]=T>>>16&255,a[2]=T>>>8&255,a[3]=T&255,a[4]=S>>>24&255,a[5]=S>>>16&255,a[6]=S>>>8&255,a[7]=S&255;let _=await crypto.subtle.importKey("raw",p,{name:"HMAC",hash:"SHA-1"},false,["sign"]),b=await crypto.subtle.sign("HMAC",_,a),y=new Uint8Array(b),F=y[y.length-1]&15;return (((y[F]&127)<<24|(y[F+1]&255)<<16|(y[F+2]&255)<<8|y[F+3]&255)%1e6).toString().padStart(6,"0")}var Tt="0.11.0";function nn(e){let r=new Date(e),p=Date.now()-r.getTime();if(p<6e4)return "just now";if(p<36e5)return `${Math.floor(p/6e4)}m ago`;if(p<864e5)return `${Math.floor(p/36e5)}h ago`;let u=r.getDate(),a=r.toLocaleString("en",{month:"short"}),T=r.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${a} ${u}, ${T}`}var w=({d:e,className:r,size:s=14})=>jsx("svg",{className:r,width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:e})}),h={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 rn(){let[e,r]=useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return useEffect(()=>{if(typeof window>"u")return;let s=document.documentElement,p=()=>s.classList.contains("dark")?"dark":s.classList.contains("light")?"light":null,u=p();u&&r(u);let a=window.matchMedia("(prefers-color-scheme: dark)"),T=_=>{let b=p();r(b||(_.matches?"dark":"light"));};a.addEventListener("change",T);let S=new MutationObserver(()=>{let _=p();r(_||(a.matches?"dark":"light"));});return S.observe(s,{attributes:true,attributeFilter:["class"]}),()=>{a.removeEventListener("change",T),S.disconnect();}},[]),e}function on(e){let r=e==="dark";return {bg:r?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:r?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:r?"#e5e5e5":"#1a1a1a",textMuted:r?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:r?"#555":"#999",border:r?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:r?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:r?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:r?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:r?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:r?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:r?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:r?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:r?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:r?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:r?"#888":"#aaa",btnHover:r?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var sn={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},an={pending:h.circle,pass:h.check,fail:h.x,skip:h.skip},Rt={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)"}},ln=["app.supply-guard.io"];function dn(e,r=[]){if(!e)return false;let s=e.toLowerCase();return [...ln,...r].map(u=>u.toLowerCase()).includes(s)}var cn=e=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:r=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:e.bg,border:r?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:r?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(r,s)=>({width:`${r}px`,borderRadius:"8px",background:e.bg,border:s?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:s?`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:r=>{let s=Rt[r]||Rt.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:s.bg,color:s.text,border:`1px solid ${s.border}`,lineHeight:"14px"}},progress:{height:"2px",background:e.borderSubtle,flexShrink:0},progressBar:r=>({height:"100%",width:`${r}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:r=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${r}15`,color:r,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(r,s)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:r?`${s}33`:"transparent",color:r?s: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 nt(e){return e.split("/")[0].trim()}async function un(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 r=document.createElement("textarea");r.value=e,r.setAttribute("readonly",""),r.style.position="fixed",r.style.top="0",r.style.left="0",r.style.opacity="0",r.style.pointerEvents="none",document.body.appendChild(r),r.focus(),r.select(),r.setSelectionRange(0,e.length);let s=document.execCommand("copy");return document.body.removeChild(r),s}catch{return false}}function Pe({config:e,appSlug:r,environment:s,seededUsers:p,authToken:u,tk:a,compact:T=false,onExpand:S,onAuthExpired:_,refreshAuth:b,requestLogin:y,testRunId:F,testRunToken:Y,ticketId:M,targetUrl:x,version:m,commitSha:n,prNumber:d,branchName:V}){let[U,J]=useState(false),[j,I]=useState(null),[$,_e]=useState(null),[ie,g]=useState(null),[Ee,se]=useState(null),[te,G]=useState(null),[X,ae]=useState(null);useEffect(()=>{s==="local"&&Ie();},[s]);let me=useCallback(l=>{I(l),g(null),se(null),ae(null);let E=Re(u);if(s!=="local"&&y&&E!==null&&E<=Date.now()){G({slug:l,token:u||null}),ae(l),I(null),y();return}let R=C=>{g(C),se(l),window.setTimeout(()=>{se(P=>P===l?null:P),g(P=>P===C?null:P);},3e3);},k=new URLSearchParams({app_slug:r,seed_user_slug:l,environment:s});F&&k.set("test_run_id",F),Y&&k.set("public_token",Y),M&&k.set("ticket_id",M),x&&k.set("target_url",x),m&&k.set("version",m),n&&k.set("commit_sha",n),d&&k.set("pr_number",String(d)),V&&k.set("branch_name",V);let L=async C=>{let P={apikey:e.anonKey,Authorization:`Bearer ${C}`};try{let z=await fetch(`${e.serverUrl}/widget/totp-code?${k}`,{headers:P});if(!z.ok){let ge=await z.json().catch(()=>({error:`HTTP ${z.status}`}));return {ok:!1,status:z.status,error:ge.error||`HTTP ${z.status}`}}let q=await z.json();return {ok:!0,code:String(q.code)}}catch{return {ok:false,status:0,error:"Network error"}}},N=(async()=>{if(s==="local"){let z=await Mt(l);if(z)try{return {ok:!0,code:await Ct(z)}}catch{}}let C=await L(u||e.anonKey);if(C.ok||C.status!==401||!b)return C;let P=await b();return P?L(P):{ok:false,status:401,error:"Sign in to BotBuddy to refresh 2FA"}})(),A=null;try{if(typeof ClipboardItem<"u"&&navigator.clipboard?.write){let C=N.then(P=>{if(!P.ok)throw new Error(P.error);return new Blob([P.code],{type:"text/plain"})});A=navigator.clipboard.write([new ClipboardItem({"text/plain":C})]).then(()=>!0).catch(()=>!1);}}catch{}(async()=>{let C=await N;if(!C.ok){C.status===401?(G({slug:l,token:u||null}),ae(l)):R(C.status===404?"No 2FA seed registered":C.error),I(null);return}let P=A?await A:false,z=P?true:await un(C.code),q=P||z;_e({slug:l,code:C.code,copied:q}),window.setTimeout(()=>_e(ge=>ge?.slug===l?null:ge),q?2500:6e3),J(false),I(null);})();},[e.serverUrl,e.anonKey,u,r,s,F,Y,M,x,m,n,d,V,b,y]),re=useCallback(l=>{G({slug:l,token:u||null}),y?.();},[u,y]),ye=useCallback(l=>{X===l?re(l):me(l);},[X,re,me]);useEffect(()=>{if(!te||!u||u===te.token)return;let l=te.slug;G(null),me(l);},[u,me,te]);let xe=useRef(null),Me=useRef(null);if(useLayoutEffect(()=>{if(!U)return;let l=xe.current,E=Me.current;if(!l||!E||typeof window>"u")return;let R=()=>{let k=l.getBoundingClientRect(),L=E.getBoundingClientRect(),N=window.innerWidth,A=window.innerHeight,C=k.left,P=k.top-L.height-6;P<8&&(P=k.bottom+6);let z=Math.max(8,N-L.width-8),q=Math.max(8,A-L.height-8);C=Math.min(Math.max(C,8),z),P=Math.min(Math.max(P,8),q),E.style.left=`${Math.round(C)}px`,E.style.top=`${Math.round(P)}px`;};return R(),window.addEventListener("scroll",R,true),window.addEventListener("resize",R),()=>{window.removeEventListener("scroll",R,true),window.removeEventListener("resize",R);}},[U,p.length,ie]),useEffect(()=>{if(!U)return;let l=E=>{let R=E.target;Me.current?.contains(R)||xe.current?.contains(R)||J(false);};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[U]),p.length===0)return null;if(T){let l=p.length>1,E=p[0],R=!l&&X===E,k=z=>{if(z.stopPropagation(),l&&S){S();return}ye(E);},L=!!Ee,N=!!$,A=N&&$.copied,C=N&&!$.copied,P=R?a.blue:L?a.red:A?a.green:C?a.amber:a.purple;return jsxs("span",{onPointerDown:z=>z.stopPropagation(),onPointerUp:z=>z.stopPropagation(),onPointerMove:z=>z.stopPropagation(),onClick:k,style:{display:"inline-flex",alignItems:"center",gap:"3px",color:P,fontWeight:600,cursor:"pointer",letterSpacing:C?"0.08em":void 0},title:R?"Sign in to BotBuddy to refresh 2FA":L?ie||"Failed":C?`Clipboard blocked \u2014 code: ${$.code}`:l?`${p.length} 2FA personas`:`Copy 2FA code for ${p[0]}`,children:[jsx(w,{d:R?h.key:L?h.alert:A?h.check:C?h.copy:h.shield,size:10}),R?jsx(Fragment,{children:"Sign in"}):A?jsx(Fragment,{children:"Copied"}):C?jsx(Fragment,{children:$.code}):L?jsx(Fragment,{children:"Failed"}):jsxs(Fragment,{children:["2FA",l&&` \xB7${p.length}`]})]})}if(p.length===1){let l=p[0],E=j===l,R=$?.slug===l,k=R&&$.copied,L=R&&!$.copied,N=Ee===l,A=X===l,C=A?a.blue:N?a.red:k?a.green:L?a.amber:a.purple;return jsxs("button",{onClick:P=>{P.stopPropagation(),ye(l);},disabled:E,style:{...Pt(C),cursor:E?"wait":"pointer",opacity:E?.6:1},title:A?"Sign in to BotBuddy to refresh 2FA":N?ie||"Failed":L?`Clipboard blocked \u2014 code: ${$.code}`:`Copy 2FA code for ${l}`,children:[jsx(w,{d:A?h.key:N?h.alert:k?h.check:L?h.copy:h.shield,size:12}),A?"Sign in":k?"Copied":L?$.code:N?"Failed":E?"\u2026":`2FA \xB7 ${l}`]})}let le=!!X&&!U,Z=!!Ee&&!U,be=!!$&&$.copied,ve=!!$&&!$.copied,De=le?a.blue:Z?a.red:be?a.green:ve?a.amber:a.purple,Fe=U&&typeof document<"u"?createPortal(jsxs("div",{ref:Me,onPointerDown:l=>l.stopPropagation(),onMouseDown:l=>l.stopPropagation(),style:{position:"fixed",left:-9999,top:-9999,background:a.bg,border:`1px solid ${a.border}`,borderRadius:6,boxShadow:`0 8px 24px ${a.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:[p.map(l=>{let E=j===l,R=X===l;return jsxs("button",{onClick:k=>{k.stopPropagation(),ye(l);},disabled:E,style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 8px",background:"transparent",border:"none",borderRadius:4,cursor:E?"wait":"pointer",fontSize:"10px",color:R?a.blue:a.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},title:R?"Sign in to BotBuddy to refresh 2FA":void 0,onMouseEnter:k=>k.currentTarget.style.background=a.btnHover,onMouseLeave:k=>k.currentTarget.style.background="transparent",children:[jsx(w,{d:R?h.key:h.shield,size:10}),jsx("span",{style:{flex:1,overflowWrap:"anywhere",lineHeight:1.3},children:l}),R?jsx("span",{style:{color:a.blue,fontSize:9},children:"Sign in"}):E?jsx("span",{style:{color:a.textMuted,fontSize:9},children:"\u2026"}):null]},l)}),ie&&jsx("div",{style:{padding:"4px 8px",fontSize:9,color:a.red},children:ie})]}),document.body):null;return jsxs(Fragment,{children:[jsxs("button",{ref:xe,onClick:l=>{if(l.stopPropagation(),le&&X){re(X);return}J(E=>!E),g(null),se(null);},style:{...Pt(De),cursor:"pointer"},title:le?"Sign in to BotBuddy to refresh 2FA":Z?ie||"Failed":ve?`Clipboard blocked \u2014 code: ${$.code}`:"Choose a persona to copy a 2FA code for",children:[jsx(w,{d:le?h.key:Z?h.alert:be?h.check:ve?h.copy:h.shield,size:12}),le?"Sign in":be?"Copied":ve?$.code:Z?"Failed":`2FA \xB7 ${p.length}`,!le&&jsx(w,{d:U?h.chevronUp:h.chevronDown,size:8})]}),Fe]})}function Pt(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 Et="botbuddy-widget-state";function pn({config:e,appSlug:r,environment:s,ticketId:p,testRunId:u,testRunToken:a,targetUrl:T,version:S,commitSha:_,prNumber:b,branchName:y,onNavigate:F,displayName:Y="human",defaultMode:M="mini",defaultPosition:x}){let m=rn(),n=useMemo(()=>on(m),[m]),d=useMemo(()=>cn(n),[n]),[V,U]=useState(false),[J,j]=useState(false),[I,$]=useState(false),_e=useRef(false),ie=e.dashboardUrl||"https://app.bot-buddy.ai",g=tt(ie),se=(()=>{try{let t=typeof window<"u"?localStorage.getItem(Et):null;if(t)return JSON.parse(t)}catch{}return null})(),[te,G]=useState(se?.mode||M),[X,ae]=useState(""),[me,re]=useState(null),[ye,xe]=useState(null),[Me,le]=useState(new Set),[Z,be]=useState(""),ve=useCallback(t=>{le(c=>{let v=new Set(c);return v.has(t)?v.delete(t):v.add(t),v});},[]),De=se?.x??x?.x??16,Fe=se?.y??x?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:l,setPos:E,onPointerDown:R,onPointerMove:k,onPointerUp:L,didDrag:N}=Ye(De,Fe),A=useRef(null);useEffect(()=>{try{localStorage.setItem(Et,JSON.stringify({mode:te,x:l.x,y:l.y}));}catch{}},[te,l.x,l.y]),useLayoutEffect(()=>{if(typeof window>"u")return;let t=A.current;if(!t)return;let c=t.getBoundingClientRect(),v=Ve(l.x,l.y,c.width,c.height,window.innerWidth,window.innerHeight);(v.x!==l.x||v.y!==l.y)&&E(v);}),useEffect(()=>{if(typeof window>"u")return;let t=()=>{let c=A.current;if(!c)return;let v=c.getBoundingClientRect(),W=Ve(l.x,l.y,v.width,v.height,window.innerWidth,window.innerHeight);(W.x!==l.x||W.y!==l.y)&&E(W);};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[l.x,l.y,E]);let C=useRef(g.isAuthenticated);useEffect(()=>{!C.current&&g.isAuthenticated&&G("max"),C.current=g.isAuthenticated;},[g.isAuthenticated]);let P="botbuddy-widget-max-size",z=()=>{try{let t=localStorage.getItem(P);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[q,ge]=useState(z),Ce=useRef(false),Te=useRef({x:0,y:0,w:0,h:0}),Bt=useCallback(t=>{t.stopPropagation(),Ce.current=true,Te.current={x:t.clientX,y:t.clientY,w:q.w,h:q.h},t.target.setPointerCapture(t.pointerId);},[q]),zt=useCallback(t=>{if(!Ce.current)return;let c=Math.max(280,Math.min(600,Te.current.w+(t.clientX-Te.current.x))),v=Math.max(300,Math.min(window.innerHeight*.9,Te.current.h+(t.clientY-Te.current.y)));ge({w:c,h:v});},[]),$t=useCallback(()=>{Ce.current&&(Ce.current=false,ge(t=>(localStorage.setItem(P,JSON.stringify(t)),t)));},[]),Q=T??(typeof window<"u"?window.location.href:void 0),rt=g.displayName||Y,[oe,ot]=useState(null);useEffect(()=>{if(g.isAuthenticated)return;let t=new URLSearchParams;a&&t.set("token",a),p&&t.set("ticket_id",p),t.set("app_slug",r),s&&t.set("environment",s),u&&t.set("test_run_id",u),Q&&t.set("target_url",Q),S&&t.set("version",S),_&&t.set("commit_sha",_),b&&t.set("pr_number",String(b)),y&&t.set("branch_name",y),fetch(`${e.serverUrl}/widget/preview?${t}`,{headers:{apikey:e.anonKey}}).then(c=>c.json()).then(c=>ot(c)).catch(()=>ot(null));},[g.isAuthenticated,e.serverUrl,e.anonKey,r,s,p,u,a,Q,S,_,b,y]);let it=useRef(false),At=useCallback(()=>{it.current||g.logout();},[g.logout]),{run:f,widgetState:fe,fetchRun:Ut,setVerdict:st,markComplete:Wt,resetRun:It,setRun:at}=Ge({config:e,appSlug:r,environment:s,ticketId:p,testRunId:u,testRunToken:a,targetUrl:Q,version:S,commitSha:_,prNumber:b?String(b):void 0,branchName:y,authToken:g.token,onAuthExpired:At});it.current=!!f;let[lt,dt]=useState([]),[ct,Le]=useState([]),[Ne,ut]=useState(false),[pt,gt]=useState(null),[Dt,Be]=useState(false),de=dn(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);useEffect(()=>{if((s??"local")!=="local"||de){dt([]);return}let t=true;return Ie().then(c=>{t&&dt(Object.keys(c||{}));}),()=>{t=false;}},[s,de]);let Ft=useCallback(async()=>{if(!(!g.isAuthenticated||!g.token)){ut(true),gt(null);try{let t=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${g.token}`},body:JSON.stringify({app_slug:r,environment:s||"local",target_url:Q,branch_name:y,commit_sha:_,pr_number:b,ticket_id:p,title:`${p||r} local validation`})}),c=await t.json().catch(()=>({}));if(!t.ok)throw new Error(c.error||`HTTP ${t.status}`);at(c),G("max");}catch(t){gt(t.message);}finally{ut(false);}}},[g.isAuthenticated,g.token,e.serverUrl,e.anonKey,r,s,Q,y,_,b,p,at]),ze=useCallback(async(t,c,v)=>{xe(t);try{await st(t,c,v,rt);}finally{xe(null),re(null),ae("");}},[st,rt]),D=f?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},Nt=D.total>0&&D.pending===0,we=fe==="completed",$e=useMemo(()=>{let t=f?.test_cases||[];if(!Z.trim())return t;let c=Z.toLowerCase();return t.filter(v=>v.title.toLowerCase().includes(c)||v.description&&v.description.toLowerCase().includes(c)||v.url_path&&v.url_path.toLowerCase().includes(c)||v.seed_user&&v.seed_user.toLowerCase().includes(c))},[f?.test_cases,Z]),ft=useMemo(()=>{let t=$e,c=f?.test_cases||[];if(new Set(c.map(K=>K.source_pr_number)).size<=1)return null;let W=[],ue=new Map;t.forEach(K=>{let H=K.source_pr_number;ue.has(H)||ue.set(H,[]),ue.get(H).push(K);});let St=[...ue.keys()].sort((K,H)=>K===null?1:H===null?-1:H-K);for(let K of St){let H=ue.get(K),He={total:H.length,pass:0,fail:0,skip:0,pending:0};H.forEach(kt=>{kt.verdict in He&&He[kt.verdict]++;}),W.push({key:K!=null?`pr-${K}`:"general",label:K!=null?`PR #${K}`:"General",cases:H,summary:He});}return W.filter(K=>K.cases.length>0)},[$e,f?.test_cases]),ht=D.total>0?(D.pass+D.fail)/D.total*100:0,O=s??f?.environment??null,ce=useMemo(()=>{if(!O||O==="production"||de)return [];let t=f?.test_cases||[],c=new Set;for(let v of t)v.seed_user&&c.add(nt(v.seed_user));if(O==="local")for(let v of lt)c.add(nt(v));for(let v of ct)c.add(nt(v));return [...c]},[f?.test_cases,O,lt,ct,de]);useEffect(()=>{if(!O||O==="production"||de||!g.isAuthenticated||!g.token){Le([]);return}let t=true,c=`${e.serverUrl}/widget/totp-seeds?${new URLSearchParams({app_slug:r,environment:O})}`,v=W=>fetch(c,{headers:{apikey:e.anonKey,Authorization:`Bearer ${W}`}});return (async()=>{try{let W=await v(g.token);if(W.status===401&&g.refreshNow){let H=await g.refreshNow();H&&(W=await v(H));}if(!t)return;if(!W.ok){Le([]);return}let ue=await W.json().catch(()=>null),K=(Array.isArray(ue?.seeds)?ue.seeds:[]).map(H=>H?.seed_user_slug).filter(H=>typeof H=="string"&&H.length>0);Le(K);}catch{t&&Le([]);}})(),()=>{t=false;}},[O,de,g.isAuthenticated,g.token,g.refreshNow,r,e.serverUrl,e.anonKey]);let Oe=useMemo(()=>{let t=f?.auto_tooltip_seconds??oe?.auto_tooltip_seconds;return t!=null&&t>0?t*1e3:0},[f,oe]),mt=fe==="ready"||fe==="completed"||oe?.enabled&&oe.run;useEffect(()=>{if(!mt||_e.current||Oe<=0)return;_e.current=true,j(true);let t=window.setTimeout(()=>j(false),Oe);return ()=>window.clearTimeout(t)},[mt,Oe]);let yt=t=>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:sn[t.verdict]},children:ye===t.id?jsx(w,{d:h.loader,className:""}):jsx(w,{d:an[t.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:n.text,lineHeight:1.3},children:t.title}),t.description&&jsx("div",{style:{fontSize:"9px",color:n.gripColor,marginTop:"2px"},children:t.description}),t.seed_user&&jsxs("div",{style:{fontSize:"9px",color:n.amber,marginTop:"3px",display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",background:`${n.amber}12`,border:`1px solid ${n.amber}30`},children:[jsx(w,{d:h.key,size:10}),jsx("span",{children:t.seed_user})]}),t.url_path&&jsxs("a",{href:t.url_path,target:"_blank",rel:"noopener noreferrer",onClick:c=>{c.stopPropagation(),F&&(c.preventDefault(),F(t.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(w,{d:h.externalLink,size:10}),t.url_path]}),t.verdict==="fail"&&t.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:n.red,marginTop:"2px"},children:["\u2717 ",t.fail_reason]})]})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(c=>jsx("button",{onClick:()=>{if(t.verdict===c){ze(t.id,"pending"),re(null);return}if(c==="fail"){re(t.id),ae("");return}re(null),ze(t.id,c);},disabled:ye!==null,style:d.verdictBtn(t.verdict===c,c==="pass"?n.green:c==="fail"?n.red:n.amber),children:c.toUpperCase()},c)),t.created_by_agent_name&&jsxs("span",{style:{fontSize:"8px",color:n.purple,marginLeft:"4px",display:"inline-flex",alignItems:"center",gap:"2px"},children:[jsx(w,{d:h.bot,size:8}),t.created_by_agent_name]}),t.verdict_by_display_name&&jsxs("span",{style:{fontSize:"8px",color:n.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[t.verdict_by_display_name,t.verdict_at&&jsx("span",{style:{opacity:.7},children:nn(t.verdict_at)})]})]}),me===t.id&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:X,onChange:c=>ae(c.target.value),onKeyDown:c=>{c.key==="Enter"&&ze(t.id,"fail",X.trim()||void 0),c.key==="Escape"&&(re(null),ae(""));},placeholder:"Reason (optional)...",style:d.input}),jsx("button",{onClick:()=>{ze(t.id,"fail",X.trim()||void 0);},style:d.verdictBtn(true,n.red),children:"\u2713"})]})]},t.id);if((fe==="no-match"||fe==="loading")&&!(!g.isAuthenticated&&oe?.enabled&&oe.run)){if(!(O==="local"&&!de))return null}if(!g.isAuthenticated&&oe?.enabled&&oe.run){let t=oe.run,c=t.summary,v=t.status==="completed";return jsx("div",{ref:A,style:{...d.root,left:l.x,top:l.y},children:jsxs("div",{style:{position:"relative"},onMouseEnter:()=>U(true),onMouseLeave:()=>{U(false),$(false),j(false);},children:[jsxs("div",{style:{...d.pill(v),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:R,onPointerMove:k,onPointerUp:()=>{L();},children:[jsx(w,{d:h.grip,size:10,className:""}),t.ticket_id&&t.ticket_url?jsx("a",{href:t.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:n.amber,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:t.ticket_id}):null,t.pr_url?jsxs("a",{href:t.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:n.blue,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:["PR#",t.pr_number??t.pr_id]}):null,t.created_by_agent_name?t.codex_thread_id?jsxs("a",{href:`codex://threads/${t.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:n.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(w,{d:h.terminal,size:10}),t.created_by_agent_name]}):jsxs("span",{style:{color:n.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(w,{d:h.bot,size:10}),t.created_by_agent_name]}):null,jsxs("span",{style:v?{color:n.green}:void 0,children:[c.pass,"/",c.total]}),c.fail>0&&jsxs("span",{style:{color:n.red},children:[c.fail,"\u2717"]}),jsx("span",{onClick:W=>{W.stopPropagation(),g.openLogin();},style:{color:n.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!I&&(V||J)&&t.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsx("div",{style:{fontSize:"11px",fontWeight:700,color:n.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:t.title}),(t.description||t.intro_notes)&&jsx("div",{style:{fontSize:"10px",color:n.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:t.description||t.intro_notes}),jsx("div",{style:{marginTop:"4px",fontSize:"9px",color:n.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!g.isAuthenticated)return jsxs("div",{ref:A,style:{...d.root,left:l.x,top:l.y,width:220,minHeight:0,cursor:"move",userSelect:"none",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`},onPointerDown:R,onPointerMove:k,onPointerUp:L,children:[jsx("div",{style:{...d.handle,borderBottom:"none"},children:jsxs("div",{style:d.sub,children:[jsx(w,{d:h.grip,size:10,className:""}),jsx(w,{d:h.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:n.textMuted,marginBottom:"8px"},children:"Sign in to access test cases"}),O==="local"&&ce.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,testRunId:f?.id||u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout})}),jsx("button",{onClick:t=>{t.stopPropagation(),g.openLogin();},style:{fontSize:"10px",fontWeight:600,padding:"6px 16px",borderRadius:"6px",border:`1px solid ${n.green}`,background:`${n.green}22`,color:n.green,cursor:"pointer",width:"100%"},children:"Sign in to test"})]})]});if(!f&&O==="local"&&!de)return Dt?jsx("div",{ref:A,style:{...d.root,left:l.x,top:l.y},children:jsxs("div",{style:d.card(240,false),children:[jsxs("div",{style:d.handle,onPointerDown:R,onPointerMove:k,onPointerUp:L,onClick:()=>{N.current||Be(false);},children:[jsx(w,{d:h.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:d.title,children:"BotBuddy"}),y&&jsx("div",{style:d.sub,children:jsxs("span",{children:["\u2387 ",y]})})]}),jsx(w,{d:h.chevronUp,className:""}),jsx("button",{style:d.btn,onClick:t=>{t.stopPropagation(),Be(false);},children:jsx(w,{d:h.minus,className:""})})]}),jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[ce.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,testRunId:u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout})}),jsx("button",{onClick:t=>{t.stopPropagation(),Ft();},disabled:Ne,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${n.green}`,background:`${n.green}22`,color:n.green,cursor:Ne?"wait":"pointer",width:"100%"},children:Ne?"Creating...":"Create test run for this branch"}),pt&&jsx("div",{style:{fontSize:"9px",color:n.red,marginTop:"8px"},children:pt})]})]})}):jsx("div",{ref:A,style:{...d.root,left:l.x,top:l.y},children:jsxs("div",{style:{...d.pill(false),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:R,onPointerMove:k,onPointerUp:()=>{L(),N.current||Be(true);},children:[jsx(w,{d:h.grip,size:9,className:""}),jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),ce.length>0&&jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,compact:true,onExpand:()=>Be(true),testRunId:u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout})]})});let xt=()=>{N.current||(j(false),G(t=>{let c=t==="mini"?"max":"mini";return $(c==="mini"),c}));},bt=({icon:t,onClick:c})=>jsx("button",{style:d.btn,onClick:v=>{v.stopPropagation(),c(v);},children:jsx(w,{d:t,className:""})}),vt=()=>jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${n.borderSubtle}`,flexShrink:0},children:[f?.pr_url&&jsxs("a",{href:f.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.blue),textDecoration:"none"},children:[jsx(w,{d:h.pr,size:12}),f.pr_number?`PR#${f.pr_number}`:f.pr_id||"PR",jsx(w,{d:h.externalLink,size:8})]}),f?.ticket_url&&jsxs("a",{href:f.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.amber),textDecoration:"none"},children:[jsx(w,{d:h.ticket,size:12}),f.ticket_id||"Ticket",jsx(w,{d:h.externalLink,size:8})]}),f?.created_by_agent_name&&(f.codex_thread_id?jsxs("a",{href:`codex://threads/${f.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.purple),textDecoration:"none"},children:[jsx(w,{d:h.bot,size:12}),f.created_by_agent_name,jsx(w,{d:h.externalLink,size:8})]}):jsxs("span",{style:{...d.link(n.purple)},children:[jsx(w,{d:h.bot,size:12}),f.created_by_agent_name]})),O&&jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,testRunId:f?.id||u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout}),jsx("span",{style:{...d.badge(f?.environment||"custom"),marginLeft:"auto"},children:f?.environment})]}),wt=()=>jsxs("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:`1px solid ${n.borderSubtle}`,background:n.bgSoft,flexShrink:0},children:[jsxs("button",{onClick:()=>{navigator.clipboard.writeText(Tt);},style:{fontSize:"9px",fontWeight:600,color:n.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:n.versionNum},children:["v",Tt]})]}),g.isAuthenticated&&(g.isExpired?jsx("button",{onClick:t=>{t.stopPropagation(),g.openLogin();},style:{fontSize:"8px",color:n.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:t=>{t.stopPropagation(),g.logout();},style:{fontSize:"8px",color:n.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:A,style:{...d.root,left:l.x,top:l.y},children:[te==="mini"&&jsxs("div",{style:{position:"relative"},onMouseEnter:()=>U(true),onMouseLeave:()=>{U(false),$(false),j(false);},children:[jsxs("div",{style:{...d.pill(we),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:R,onPointerMove:k,onPointerUp:()=>{L(),N.current||xt();},children:[jsx(w,{d:h.grip,size:9,className:""}),f?.ticket_id&&jsx("span",{style:{color:n.amber,fontWeight:600},children:f.ticket_id}),f?.pr_number&&jsxs("span",{style:{color:n.blue,fontWeight:600},children:["PR#",f.pr_number]}),jsxs("span",{style:we?{color:n.green}:void 0,children:[D.pass,"/",D.total]}),D.fail>0&&jsxs("span",{style:{color:n.red},children:[D.fail,"\u2717"]}),O&&jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,compact:true,onExpand:()=>G("expanded"),testRunId:f?.id||u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout})]}),!I&&(V||J)&&f?.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsx("div",{style:{fontSize:"11px",fontWeight:700,color:n.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:f.title}),(f.description||f.intro_notes)&&jsx("div",{style:{fontSize:"10px",color:n.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:f.description||f.intro_notes})]})]}),te==="expanded"&&jsxs("div",{style:d.card(300,we),children:[jsxs("div",{style:d.handle,onPointerDown:R,onPointerMove:k,onPointerUp:L,onClick:xt,children:[jsx(w,{d:h.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:d.title,children:f?.title}),jsx("div",{style:d.sub,children:f?.branch_name&&jsxs("span",{children:["\u2387 ",f.branch_name]})})]}),jsx(w,{d:h.chevronUp,className:""}),jsx(bt,{icon:h.minus,onClick:()=>{j(false),$(true),G("mini");}})]}),jsxs("div",{style:d.stats,children:[jsxs("span",{style:{color:n.green},children:[D.pass,"\u2713"]}),jsxs("span",{style:{color:n.red},children:[D.fail,"\u2717"]}),jsxs("span",{style:{color:n.amber},children:[D.skip,"\u23ED"]}),jsxs("span",{style:{color:n.gripColor},children:[D.pending,"\u25CC"]}),jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:D.total})]}),f?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:n.gripColor,borderBottom:`1px solid ${n.borderSubtle}`,flexShrink:0},children:f.description}),vt(),wt(),jsx("div",{style:d.progress,children:jsx("div",{style:d.progressBar(ht)})})]}),te==="max"&&jsxs("div",{style:{...d.card(q.w,we),height:q.h,position:"relative"},children:[jsxs("div",{style:d.handle,onPointerDown:R,onPointerMove:k,onPointerUp:L,onClick:()=>{N.current||G("expanded");},children:[jsx(w,{d:h.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:d.title,children:f?.title}),jsx("div",{style:d.sub,children:f?.branch_name&&jsxs("span",{children:["\u2387 ",f.branch_name]})})]}),jsx(w,{d:h.chevronDown,className:""}),jsx(bt,{icon:h.minus,onClick:()=>{j(false),$(true),G("mini");}})]}),jsxs("div",{style:d.stats,children:[jsxs("span",{style:{color:n.green},children:[D.pass,"\u2713"]}),jsxs("span",{style:{color:n.red},children:[D.fail,"\u2717"]}),jsxs("span",{style:{color:n.amber},children:[D.skip,"\u23ED"]}),jsxs("span",{style:{color:n.gripColor},children:[D.pending,"\u25CC"]}),jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:D.total})]}),f?.intro_notes&&jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${n.borderSubtle}`,fontSize:"10px",color:n.textMuted,fontStyle:"italic",flexShrink:0},children:f.intro_notes}),(f?.test_cases||[]).length>5&&jsxs("div",{style:{padding:"4px 12px",borderBottom:`1px solid ${n.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[jsx(w,{d:h.search,size:11,className:""}),jsx("input",{value:Z,onChange:t=>be(t.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:n.text,fontFamily:"monospace"}}),Z&&jsx("button",{onClick:()=>be(""),style:{background:"none",border:"none",cursor:"pointer",color:n.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),fe==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(w,{d:h.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:n.red},children:"Failed to load"}),jsx("button",{onClick:Ut,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),we&&jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg},children:[jsx(w,{d:h.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:n.green,flex:1},children:"Run completed"}),jsx("button",{onClick:It,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),fe!=="error"&&jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(f?.test_cases||[]).length===0?jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:"No test cases"}):$e.length===0?jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:['No matches for "',Z,'"']}):ft?ft.map(t=>{let c=Me.has(t.key);return jsxs("div",{children:[jsxs("button",{onClick:()=>ve(t.key),style:{width:"100%",display:"flex",alignItems:"center",gap:"6px",padding:"5px 12px",background:n.bgSoft,cursor:"pointer",border:"none",borderLeft:"none",borderRight:"none",borderBottomStyle:"solid",borderTopStyle:"solid",borderBottomWidth:"1px",borderTopWidth:"1px",borderBottomColor:n.borderSubtle,borderTopColor:n.borderSubtle,backgroundColor:n.bgSoft},children:[jsx(w,{d:c?h.chevronDown:h.chevronUp,size:10,className:""}),jsx("span",{style:{fontSize:"10px",fontWeight:700,color:n.blue,flex:1,textAlign:"left"},children:t.label}),jsxs("span",{style:{fontSize:"9px",color:n.green},children:[t.summary.pass,"\u2713"]}),jsxs("span",{style:{fontSize:"9px",color:n.red},children:[t.summary.fail,"\u2717"]}),jsxs("span",{style:{fontSize:"9px",color:n.gripColor},children:[t.summary.pending,"\u25CC"]}),jsx("span",{style:{fontSize:"9px",color:n.textFaint},children:t.summary.total})]}),!c&&t.cases.map(v=>yt(v))]},t.key)}):$e.map(t=>yt(t))}),Nt&&!we&&jsxs("div",{style:{padding:"6px 12px",borderTop:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg,display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsx("span",{style:{fontSize:"9px",color:n.green},children:"All resolved"}),jsx("button",{onClick:Wt,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:n.green,border:`1px solid ${n.greenBorderSubtle}`,cursor:"pointer"},children:"COMPLETE"})]}),vt(),wt(),jsx("div",{style:d.progress,children:jsx("div",{style:d.progressBar(ht)})}),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:Bt,onPointerMove:zt,onPointerUp:$t,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{Ce.current||(t.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:n.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}
|
|
2
|
-
|
|
1
|
+
import {useState,useRef,useCallback,useEffect,useMemo,useLayoutEffect}from'react';import {createPortal}from'react-dom';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Se=8;function qe(e,n,i,d,a,s){let _=Math.max(Se,a-i-Se),k=Math.max(Se,s-d-Se);return {x:Math.min(Math.max(e,Se),_),y:Math.min(Math.max(n,Se),k)}}function Ge(e,n){let[i,d]=useState({x:e,y:n}),a=useRef(false),s=useRef({x:0,y:0}),_=useRef(false),k=useCallback(y=>{a.current=true,_.current=false,s.current={x:y.clientX-i.x,y:y.clientY-i.y},y.target.setPointerCapture(y.pointerId);},[i]),h=useCallback(y=>{a.current&&(_.current=true,d({x:y.clientX-s.current.x,y:y.clientY-s.current.y}));},[]),p=useCallback(()=>{a.current=false;},[]);return {pos:i,setPos:d,onPointerDown:k,onPointerMove:h,onPointerUp:p,didDrag:_}}function Xe(e,n,i){let d=useRef(i);d.current=i,useEffect(()=>{if(!n)return;if(e.supabaseUrl){let s=false,_=null,k=()=>{s||_||(_=setInterval(()=>d.current(),15e3));},h=null;try{let x=new URL(e.supabaseUrl),r=["localhost","127.0.0.1","::1"].includes(x.hostname);if(x.protocol==="http:"&&!r)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");x.protocol=x.protocol==="https:"?"wss:":"ws:",h=x.toString().replace(/\/$/,"");}catch{k();}let p=null,y=null,T=null,V=0,M=()=>{if(!(s||!h)){try{p=new WebSocket(`${h}/realtime/v1/websocket?apikey=${e.anonKey}&vsn=1.0.0`);}catch{k();return}p.onopen=()=>{if(s||!p)return;let x={topic:`realtime:public:test_run_cases:test_run_id=eq.${n}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_run_cases",filter:`test_run_id=eq.${n}`}]}},ref:String(++V)};p.send(JSON.stringify(x));let r={topic:`realtime:public:test_runs:id=eq.${n}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_runs",filter:`id=eq.${n}`}]}},ref:String(++V)};p.send(JSON.stringify(r)),y=setInterval(()=>{p?.readyState===WebSocket.OPEN&&p.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++V)}));},3e4);},p.onmessage=x=>{try{JSON.parse(x.data).event==="postgres_changes"&&d.current();}catch{}},p.onclose=()=>{v(),s||(T=setTimeout(M,3e3));},p.onerror=()=>{p?.close();};}},v=()=>{y&&(clearInterval(y),y=null);};return M(),()=>{s=true,v(),T&&clearTimeout(T),_&&clearInterval(_),p&&(p.onclose=null,p.onerror=null,p.close());}}let a=setInterval(()=>d.current(),15e3);return ()=>clearInterval(a)},[e.supabaseUrl,e.anonKey,n]);}var Qt="botbuddy:created-test-run:";function en(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function tn(e){return `${Qt}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",en(e.targetUrl),e.branchName||""].join("|"))}`}function Ue(e,n){let i={apikey:e.anonKey};return n?i.Authorization=`Bearer ${n}`:e.apiKey?i.Authorization=`Bearer ${e.apiKey}`:i.Authorization=`Bearer ${e.anonKey}`,i}async function nn(e){if(e)return e;try{let n=await fetch("/.botbuddy-token",{cache:"no-store"});if(n.ok){let i=(await n.text()).trim();if(i.startsWith("public_"))return i}}catch{}try{let n=import.meta?.env?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(n&&typeof n=="string"&&n.startsWith("public_"))return n}catch{}return null}function Qe(e){let[n,i]=useState(null),[d,a]=useState("loading"),s=tn(e),[_,k]=useState(()=>{if(e.testRunId)return e.testRunId;try{return localStorage.getItem(s)||void 0}catch{return}}),h=e.testRunId||_,p=useCallback(v=>{if(i(v),!!v?.id){k(v.id);try{localStorage.setItem(s,v.id);}catch{}}},[s]),y=useCallback(async()=>{try{let v=await nn(e.testRunToken);if(!v&&!h){a("no-match"),i(null);return}if(v&&!e.ticketId){a("no-match"),i(null);return}let x=new URLSearchParams;v&&x.set("token",v),e.ticketId&&x.set("ticket_id",e.ticketId),x.set("app_slug",e.appSlug),e.environment&&x.set("environment",e.environment),h&&x.set("test_run_id",h),e.targetUrl&&x.set("target_url",e.targetUrl),e.version&&x.set("version",e.version),e.commitSha&&x.set("commit_sha",e.commitSha),e.prNumber&&x.set("pr_number",String(e.prNumber)),e.branchName&&x.set("branch_name",e.branchName);let r=await fetch(`${e.config.serverUrl}/widget/test-run?${x.toString()}`,{headers:Ue(e.config,e.authToken)});if(r.status===404){a("no-match"),i(null);return}if(r.status===401||r.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),a("error");return}if(!r.ok){a("error");return}let u=await r.json();if(!u||u.run===null){a("no-match"),i(null);return}p(u),a(u.status==="completed"?"completed":"ready");}catch{a("error");}},[e.config.serverUrl,e.config.anonKey,e.config.apiKey,e.authToken,e.appSlug,e.environment,e.ticketId,h,e.testRunToken,e.targetUrl,e.version,e.commitSha,e.branchName,e.prNumber,e.onAuthExpired,p]);return useEffect(()=>{y();},[y]),Xe(e.config,n?.id,y),{run:n,widgetState:d,fetchRun:y,setVerdict:async(v,x,r,u="human")=>(i(U=>{if(!U)return null;let q=U.test_cases.map(I=>I.id===v?{...I,verdict:x,fail_reason:x==="fail"&&r||null,verdict_by_display_name:u,verdict_at:new Date().toISOString()}:I),Y={total:q.length,pending:0,pass:0,fail:0,skip:0};return q.forEach(I=>{I.verdict in Y&&Y[I.verdict]++;}),{...U,test_cases:q,summary:Y}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${v}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...Ue(e.config,e.authToken)},body:JSON.stringify({verdict:x,fail_reason:r,display_name:u})})).ok),markComplete:async()=>n?(i(x=>x?{...x,status:"completed"}:null),a("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${n.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...Ue(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!n)return false;let v=await fetch(`${e.config.serverUrl}/widget/test-runs/${n.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...Ue(e.config,e.authToken)}});return v.ok&&y(),v.ok},setRun:p}}var nt="botbuddy-widget-auth-token",rt="botbuddy-widget-auth-name";function Ee(e){if(!e)return null;try{let n=e.split(".")[1];if(!n)return null;let i=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(n.length/4)*4,"="),d=atob(i),a=JSON.parse(d);return typeof a.exp=="number"?a.exp*1e3:null}catch{return null}}var on=2500,sn=6e4;function ot(e){let[n,i]=useState(()=>{try{return localStorage.getItem(nt)}catch(M){return console.warn("Unable to read BotBuddy widget auth token",M),null}}),[d,a]=useState(()=>{try{return localStorage.getItem(rt)}catch(M){return console.warn("Unable to read BotBuddy widget display name",M),null}}),s=useRef(null),_=useCallback((M,v)=>{i(M),v&&a(v);try{localStorage.setItem(nt,M),v&&localStorage.setItem(rt,v);}catch(x){console.warn("Unable to persist BotBuddy widget auth token",x);}},[]);useEffect(()=>{let M=new URL(e).origin,v=x=>{x.origin===M&&x.data?.type==="botbuddy-widget-auth"&&x.data.token&&_(x.data.token,x.data.displayName||"human");};return window.addEventListener("message",v),()=>window.removeEventListener("message",v)},[e,_]);let k=useCallback(()=>{if(s.current)return s.current;if(typeof window>"u"||typeof document>"u")return Promise.resolve(null);let M=new URL(e).origin,v=new URL("/widget-auth",e);v.searchParams.set("silent","1"),v.searchParams.set("origin",window.location.origin);let x=new Promise(r=>{let u=document.createElement("iframe");u.setAttribute("aria-hidden","true"),u.style.position="fixed",u.style.width="1px",u.style.height="1px",u.style.opacity="0",u.style.pointerEvents="none",u.style.border="0",u.style.left="-9999px",u.style.top="-9999px",u.src=v.toString();let J=false,U=()=>{window.removeEventListener("message",q),clearTimeout(Y);try{u.remove();}catch{}s.current=null;},q=I=>{if(I.origin===M){if(I.data?.type==="botbuddy-widget-auth-failed"){if(J)return;J=true,r(null),U();return}I.data?.type!=="botbuddy-widget-auth"||!I.data.token||J||(J=true,r(String(I.data.token)),U());}},Y=setTimeout(()=>{J||(J=true,r(null),U());},on);window.addEventListener("message",q),document.body.appendChild(u);});return s.current=x,x},[e]);useEffect(()=>{if(!n)return;let M=Ee(n);if(!M)return;let v=M-Date.now()-sn,x=window.setTimeout(()=>{k();},Math.max(0,v));return ()=>window.clearTimeout(x)},[n,k]);let h=useCallback(()=>{let M=new URL("/widget-auth",e);M.searchParams.set("origin",window.location.origin);let v=420,x=520,r=window.screenX+(window.innerWidth-v)/2,u=window.screenY+(window.innerHeight-x)/2;window.open(M.toString(),"botbuddy-auth",`width=${v},height=${x},left=${r},top=${u},popup=yes`);},[e]),[,p]=useState(0);useEffect(()=>{let M=Ee(n);if(!M)return;let v=M-Date.now();if(v<=0)return;let x=window.setTimeout(()=>p(r=>r+1),v);return ()=>window.clearTimeout(x)},[n]);let y=useCallback(()=>{i(null),a(null);try{localStorage.removeItem(nt),localStorage.removeItem(rt);}catch(M){console.warn("Unable to clear BotBuddy widget auth token",M);}},[]),T=Ee(n),V=T!==null&&T<=Date.now();return {token:n,displayName:d,isAuthenticated:!!n,isExpired:V,openLogin:h,refreshNow:k,logout:y}}var Ie=null;function an(){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 Fe(){return Ie||(Ie=(async()=>{if(typeof fetch>"u")return null;try{let e=await fetch(an(),{cache:"no-store"});if(!e.ok)return null;let n=await e.json();if(!n||typeof n!="object"||Array.isArray(n))return null;let i={};for(let[d,a]of Object.entries(n))typeof a=="string"&&a.length>0&&(i[d]=a);return i}catch{return null}})(),Ie)}async function Pt(e){return (await Fe())?.[e]??null}function ln(e){let n=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),i="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",d=[],a=0,s=0;for(let _ of n){let k=i.indexOf(_);if(k<0)throw new Error("Invalid Base32 character in TOTP secret");s=s<<5|k,a+=5,a>=8&&(a-=8,d.push(s>>>a&255));}return Uint8Array.from(d)}async function Et(e,n=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let i=ln(e),d=new Uint8Array(i.byteLength);d.set(i);let a=Math.floor(n/1e3/30),s=new Uint8Array(8),_=Math.floor(a/4294967296),k=a>>>0;s[0]=_>>>24&255,s[1]=_>>>16&255,s[2]=_>>>8&255,s[3]=_&255,s[4]=k>>>24&255,s[5]=k>>>16&255,s[6]=k>>>8&255,s[7]=k&255;let h=await crypto.subtle.importKey("raw",d,{name:"HMAC",hash:"SHA-1"},false,["sign"]),p=await crypto.subtle.sign("HMAC",h,s),y=new Uint8Array(p),T=y[y.length-1]&15;return (((y[T]&127)<<24|(y[T+1]&255)<<16|(y[T+2]&255)<<8|y[T+3]&255)%1e6).toString().padStart(6,"0")}var Lt="0.11.0";function cn(e){let n=new Date(e),d=Date.now()-n.getTime();if(d<6e4)return "just now";if(d<36e5)return `${Math.floor(d/6e4)}m ago`;if(d<864e5)return `${Math.floor(d/36e5)}h ago`;let a=n.getDate(),s=n.toLocaleString("en",{month:"short"}),_=n.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${s} ${a}, ${_}`}var S=({d:e,className:n,size:i=14})=>jsx("svg",{className:n,width:i,height:i,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:e})}),m={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 un(){let[e,n]=useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return useEffect(()=>{if(typeof window>"u")return;let i=document.documentElement,d=()=>i.classList.contains("dark")?"dark":i.classList.contains("light")?"light":null,a=d();a&&n(a);let s=window.matchMedia("(prefers-color-scheme: dark)"),_=h=>{let p=d();n(p||(h.matches?"dark":"light"));};s.addEventListener("change",_);let k=new MutationObserver(()=>{let h=d();n(h||(s.matches?"dark":"light"));});return k.observe(i,{attributes:true,attributeFilter:["class"]}),()=>{s.removeEventListener("change",_),k.disconnect();}},[]),e}function pn(e){let n=e==="dark";return {bg:n?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:n?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:n?"#e5e5e5":"#1a1a1a",textMuted:n?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:n?"#555":"#999",border:n?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:n?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:n?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:n?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:n?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:n?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:n?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:n?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:n?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:n?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:n?"#888":"#aaa",btnHover:n?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var gn={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},fn={pending:m.circle,pass:m.check,fail:m.x,skip:m.skip},Nt={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)"}},bn=["app.supply-guard.io"];function mn(e,n=[]){if(!e)return false;let i=e.toLowerCase();return [...bn,...n].map(a=>a.toLowerCase()).includes(i)}var yn=e=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:n=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:e.bg,border:n?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:n?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(n,i)=>({width:`${n}px`,borderRadius:"8px",background:e.bg,border:i?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:i?`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:n=>{let i=Nt[n]||Nt.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:i.bg,color:i.text,border:`1px solid ${i.border}`,lineHeight:"14px"}},progress:{height:"2px",background:e.borderSubtle,flexShrink:0},progressBar:n=>({height:"100%",width:`${n}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:n=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${n}15`,color:n,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(n,i)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:n?`${i}33`:"transparent",color:n?i: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 it(e){return e.split("/")[0].trim()}async function hn(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 n=document.createElement("textarea");n.value=e,n.setAttribute("readonly",""),n.style.position="fixed",n.style.top="0",n.style.left="0",n.style.opacity="0",n.style.pointerEvents="none",document.body.appendChild(n),n.focus(),n.select(),n.setSelectionRange(0,e.length);let i=document.execCommand("copy");return document.body.removeChild(n),i}catch{return false}}function Le({config:e,appSlug:n,environment:i,seededUsers:d,authToken:a,tk:s,compact:_=false,onExpand:k,onAuthExpired:h,refreshAuth:p,requestLogin:y,testRunId:T,testRunToken:V,ticketId:M,targetUrl:v,version:x,commitSha:r,prNumber:u,branchName:J}){let[U,q]=useState(false),[Y,I]=useState(null),[$,Me]=useState(null),[se,f]=useState(null),[Ne,ae]=useState(null),[ne,X]=useState(null),[Z,le]=useState(null);useEffect(()=>{i==="local"&&Fe();},[i]);let ye=useCallback(c=>{I(c),f(null),ae(null),le(null);let L=Ee(a);if(i!=="local"&&y&&L!==null&&L<=Date.now()){X({slug:c,token:a||null}),le(c),I(null),y();return}let P=C=>{f(C),ae(c),window.setTimeout(()=>{ae(E=>E===c?null:E),f(E=>E===C?null:E);},3e3);},R=new URLSearchParams({app_slug:n,seed_user_slug:c,environment:i});T&&R.set("test_run_id",T),V&&R.set("public_token",V),M&&R.set("ticket_id",M),v&&R.set("target_url",v),x&&R.set("version",x),r&&R.set("commit_sha",r),u&&R.set("pr_number",String(u)),J&&R.set("branch_name",J);let N=async C=>{let E={apikey:e.anonKey,Authorization:`Bearer ${C}`};try{let z=await fetch(`${e.serverUrl}/widget/totp-code?${R}`,{headers:E});if(!z.ok){let fe=await z.json().catch(()=>({error:`HTTP ${z.status}`}));return {ok:!1,status:z.status,error:fe.error||`HTTP ${z.status}`}}let G=await z.json();return {ok:!0,code:String(G.code)}}catch{return {ok:false,status:0,error:"Network error"}}},D=(async()=>{if(i==="local"){let z=await Pt(c);if(z)try{return {ok:!0,code:await Et(z)}}catch{}}let C=await N(a||e.anonKey);if(C.ok||C.status!==401||!p)return C;let E=await p();return E?N(E):{ok:false,status:401,error:"Sign in to BotBuddy to refresh 2FA"}})(),A=null;try{if(typeof ClipboardItem<"u"&&navigator.clipboard?.write){let C=D.then(E=>{if(!E.ok)throw new Error(E.error);return new Blob([E.code],{type:"text/plain"})});A=navigator.clipboard.write([new ClipboardItem({"text/plain":C})]).then(()=>!0).catch(()=>!1);}}catch{}(async()=>{let C=await D;if(!C.ok){C.status===401?(X({slug:c,token:a||null}),le(c)):P(C.status===404?"No 2FA seed registered":C.error),I(null);return}let E=A?await A:false,z=E?true:await hn(C.code),G=E||z;Me({slug:c,code:C.code,copied:G}),window.setTimeout(()=>Me(fe=>fe?.slug===c?null:fe),G?2500:6e3),q(false),I(null);})();},[e.serverUrl,e.anonKey,a,n,i,T,V,M,v,x,r,u,J,p,y]),oe=useCallback(c=>{X({slug:c,token:a||null}),y?.();},[a,y]),he=useCallback(c=>{Z===c?oe(c):ye(c);},[Z,oe,ye]);useEffect(()=>{if(!ne||!a||a===ne.token)return;let c=ne.slug;X(null),ye(c);},[a,ye,ne]);let xe=useRef(null),Ce=useRef(null);if(useLayoutEffect(()=>{if(!U)return;let c=xe.current,L=Ce.current;if(!c||!L||typeof window>"u")return;let P=()=>{let R=c.getBoundingClientRect(),N=L.getBoundingClientRect(),D=window.innerWidth,A=window.innerHeight,C=R.left,E=R.top-N.height-6;E<8&&(E=R.bottom+6);let z=Math.max(8,D-N.width-8),G=Math.max(8,A-N.height-8);C=Math.min(Math.max(C,8),z),E=Math.min(Math.max(E,8),G),L.style.left=`${Math.round(C)}px`,L.style.top=`${Math.round(E)}px`;};return P(),window.addEventListener("scroll",P,true),window.addEventListener("resize",P),()=>{window.removeEventListener("scroll",P,true),window.removeEventListener("resize",P);}},[U,d.length,se]),useEffect(()=>{if(!U)return;let c=L=>{let P=L.target;Ce.current?.contains(P)||xe.current?.contains(P)||q(false);};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[U]),d.length===0)return null;if(_){let c=d.length>1,L=d[0],P=!c&&Z===L,R=z=>{if(z.stopPropagation(),c&&k){k();return}he(L);},N=!!Ne,D=!!$,A=D&&$.copied,C=D&&!$.copied,E=P?s.blue:N?s.red:A?s.green:C?s.amber:s.purple;return jsxs("span",{onPointerDown:z=>z.stopPropagation(),onPointerUp:z=>z.stopPropagation(),onPointerMove:z=>z.stopPropagation(),onClick:R,style:{display:"inline-flex",alignItems:"center",gap:"3px",color:E,fontWeight:600,cursor:"pointer",letterSpacing:C?"0.08em":void 0},title:P?"Sign in to BotBuddy to refresh 2FA":N?se||"Failed":C?`Clipboard blocked \u2014 code: ${$.code}`:c?`${d.length} 2FA personas`:`Copy 2FA code for ${d[0]}`,children:[jsx(S,{d:P?m.key:N?m.alert:A?m.check:C?m.copy:m.shield,size:10}),P?jsx(Fragment,{children:"Sign in"}):A?jsx(Fragment,{children:"Copied"}):C?jsx(Fragment,{children:$.code}):N?jsx(Fragment,{children:"Failed"}):jsxs(Fragment,{children:["2FA",c&&` \xB7${d.length}`]})]})}if(d.length===1){let c=d[0],L=Y===c,P=$?.slug===c,R=P&&$.copied,N=P&&!$.copied,D=Ne===c,A=Z===c,C=A?s.blue:D?s.red:R?s.green:N?s.amber:s.purple;return jsxs("button",{onClick:E=>{E.stopPropagation(),he(c);},disabled:L,style:{...Bt(C),cursor:L?"wait":"pointer",opacity:L?.6:1},title:A?"Sign in to BotBuddy to refresh 2FA":D?se||"Failed":N?`Clipboard blocked \u2014 code: ${$.code}`:`Copy 2FA code for ${c}`,children:[jsx(S,{d:A?m.key:D?m.alert:R?m.check:N?m.copy:m.shield,size:12}),A?"Sign in":R?"Copied":N?$.code:D?"Failed":L?"\u2026":`2FA \xB7 ${c}`]})}let de=!!Z&&!U,Q=!!Ne&&!U,ve=!!$&&$.copied,we=!!$&&!$.copied,Oe=de?s.blue:Q?s.red:ve?s.green:we?s.amber:s.purple,He=U&&typeof document<"u"?createPortal(jsxs("div",{ref:Ce,onPointerDown:c=>c.stopPropagation(),onMouseDown:c=>c.stopPropagation(),style:{position:"fixed",left:-9999,top:-9999,background:s.bg,border:`1px solid ${s.border}`,borderRadius:6,boxShadow:`0 8px 24px ${s.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:[d.map(c=>{let L=Y===c,P=Z===c;return jsxs("button",{onClick:R=>{R.stopPropagation(),he(c);},disabled:L,style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 8px",background:"transparent",border:"none",borderRadius:4,cursor:L?"wait":"pointer",fontSize:"10px",color:P?s.blue:s.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},title:P?"Sign in to BotBuddy to refresh 2FA":void 0,onMouseEnter:R=>R.currentTarget.style.background=s.btnHover,onMouseLeave:R=>R.currentTarget.style.background="transparent",children:[jsx(S,{d:P?m.key:m.shield,size:10}),jsx("span",{style:{flex:1,overflowWrap:"anywhere",lineHeight:1.3},children:c}),P?jsx("span",{style:{color:s.blue,fontSize:9},children:"Sign in"}):L?jsx("span",{style:{color:s.textMuted,fontSize:9},children:"\u2026"}):null]},c)}),se&&jsx("div",{style:{padding:"4px 8px",fontSize:9,color:s.red},children:se})]}),document.body):null;return jsxs(Fragment,{children:[jsxs("button",{ref:xe,onClick:c=>{if(c.stopPropagation(),de&&Z){oe(Z);return}q(L=>!L),f(null),ae(null);},style:{...Bt(Oe),cursor:"pointer"},title:de?"Sign in to BotBuddy to refresh 2FA":Q?se||"Failed":we?`Clipboard blocked \u2014 code: ${$.code}`:"Choose a persona to copy a 2FA code for",children:[jsx(S,{d:de?m.key:Q?m.alert:ve?m.check:we?m.copy:m.shield,size:12}),de?"Sign in":ve?"Copied":we?$.code:Q?"Failed":`2FA \xB7 ${d.length}`,!de&&jsx(S,{d:U?m.chevronUp:m.chevronDown,size:8})]}),He]})}function Bt(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 zt="botbuddy-widget-state";function xn({config:e,appSlug:n,environment:i,ticketId:d,testRunId:a,testRunToken:s,targetUrl:_,version:k,commitSha:h,prNumber:p,branchName:y,onNavigate:T,displayName:V="human",defaultMode:M="mini",defaultPosition:v}){let x=un(),r=useMemo(()=>pn(x),[x]),u=useMemo(()=>yn(r),[r]),[J,U]=useState(false),[q,Y]=useState(false),[I,$]=useState(false),Me=useRef(false),se=e.dashboardUrl||"https://app.bot-buddy.ai",f=ot(se),ae=(()=>{try{let t=typeof window<"u"?localStorage.getItem(zt):null;if(t)return JSON.parse(t)}catch{}return null})(),[ne,X]=useState(ae?.mode||M),[Z,le]=useState(""),[ye,oe]=useState(null),[he,xe]=useState(null),[Ce,de]=useState(new Set),[Q,ve]=useState(""),we=useCallback(t=>{de(g=>{let w=new Set(g);return w.has(t)?w.delete(t):w.add(t),w});},[]),Oe=ae?.x??v?.x??16,He=ae?.y??v?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:c,setPos:L,onPointerDown:P,onPointerMove:R,onPointerUp:N,didDrag:D}=Ge(Oe,He),A=useRef(null);useEffect(()=>{try{localStorage.setItem(zt,JSON.stringify({mode:ne,x:c.x,y:c.y}));}catch{}},[ne,c.x,c.y]),useLayoutEffect(()=>{if(typeof window>"u")return;let t=A.current;if(!t)return;let g=t.getBoundingClientRect(),w=qe(c.x,c.y,g.width,g.height,window.innerWidth,window.innerHeight);(w.x!==c.x||w.y!==c.y)&&L(w);}),useEffect(()=>{if(typeof window>"u")return;let t=()=>{let g=A.current;if(!g)return;let w=g.getBoundingClientRect(),W=qe(c.x,c.y,w.width,w.height,window.innerWidth,window.innerHeight);(W.x!==c.x||W.y!==c.y)&&L(W);};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[c.x,c.y,L]);let C=useRef(f.isAuthenticated);useEffect(()=>{!C.current&&f.isAuthenticated&&X("max"),C.current=f.isAuthenticated;},[f.isAuthenticated]);let E="botbuddy-widget-max-size",z=()=>{try{let t=localStorage.getItem(E);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[G,fe]=useState(z),Te=useRef(false),Pe=useRef({x:0,y:0,w:0,h:0}),It=useCallback(t=>{t.stopPropagation(),Te.current=true,Pe.current={x:t.clientX,y:t.clientY,w:G.w,h:G.h},t.target.setPointerCapture(t.pointerId);},[G]),Ft=useCallback(t=>{if(!Te.current)return;let g=Math.max(280,Math.min(600,Pe.current.w+(t.clientX-Pe.current.x))),w=Math.max(300,Math.min(window.innerHeight*.9,Pe.current.h+(t.clientY-Pe.current.y)));fe({w:g,h:w});},[]),Dt=useCallback(()=>{Te.current&&(Te.current=false,fe(t=>(localStorage.setItem(E,JSON.stringify(t)),t)));},[]),ee=_??(typeof window<"u"?window.location.href:void 0),at=f.displayName||V,[ie,lt]=useState(null);useEffect(()=>{if(f.isAuthenticated)return;let t=new URLSearchParams;s&&t.set("token",s),d&&t.set("ticket_id",d),t.set("app_slug",n),i&&t.set("environment",i),a&&t.set("test_run_id",a),ee&&t.set("target_url",ee),k&&t.set("version",k),h&&t.set("commit_sha",h),p&&t.set("pr_number",String(p)),y&&t.set("branch_name",y),fetch(`${e.serverUrl}/widget/preview?${t}`,{headers:{apikey:e.anonKey}}).then(g=>g.json()).then(g=>lt(g)).catch(()=>lt(null));},[f.isAuthenticated,e.serverUrl,e.anonKey,n,i,d,a,s,ee,k,h,p,y]);let dt=useRef(false),Ot=useCallback(()=>{dt.current||f.logout();},[f.logout]),{run:b,widgetState:be,fetchRun:Ht,setVerdict:ct,markComplete:Kt,resetRun:jt,setRun:ut}=Qe({config:e,appSlug:n,environment:i,ticketId:d,testRunId:a,testRunToken:s,targetUrl:ee,version:k,commitSha:h,prNumber:p?String(p):void 0,branchName:y,authToken:f.token,onAuthExpired:Ot});dt.current=!!b;let[pt,gt]=useState([]),[ft,Be]=useState([]),[Ke,bt]=useState(false),[mt,yt]=useState(null),[Vt,ze]=useState(false),ce=mn(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);useEffect(()=>{if((i??"local")!=="local"||ce){gt([]);return}let t=true;return Fe().then(g=>{t&>(Object.keys(g||{}));}),()=>{t=false;}},[i,ce]);let Yt=useCallback(async()=>{if(!(!f.isAuthenticated||!f.token)){bt(true),yt(null);try{let t=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${f.token}`},body:JSON.stringify({app_slug:n,environment:i||"local",target_url:ee,branch_name:y,commit_sha:h,pr_number:p,ticket_id:d,title:`${d||n} local validation`})}),g=await t.json().catch(()=>({}));if(!t.ok)throw new Error(g.error||`HTTP ${t.status}`);ut(g),X("max");}catch(t){yt(t.message);}finally{bt(false);}}},[f.isAuthenticated,f.token,e.serverUrl,e.anonKey,n,i,ee,y,h,p,d,ut]),$e=useCallback(async(t,g,w)=>{xe(t);try{await ct(t,g,w,at);}finally{xe(null),oe(null),le("");}},[ct,at]),F=b?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},Jt=F.total>0&&F.pending===0,ke=be==="completed",Ae=useMemo(()=>{let t=b?.test_cases||[];if(!Q.trim())return t;let g=Q.toLowerCase();return t.filter(w=>w.title.toLowerCase().includes(g)||w.description&&w.description.toLowerCase().includes(g)||w.url_path&&w.url_path.toLowerCase().includes(g)||w.seed_user&&w.seed_user.toLowerCase().includes(g))},[b?.test_cases,Q]),ht=useMemo(()=>{let t=Ae,g=b?.test_cases||[];if(new Set(g.map(K=>K.source_pr_number)).size<=1)return null;let W=[],pe=new Map;t.forEach(K=>{let H=K.source_pr_number;pe.has(H)||pe.set(H,[]),pe.get(H).push(K);});let Mt=[...pe.keys()].sort((K,H)=>K===null?1:H===null?-1:H-K);for(let K of Mt){let H=pe.get(K),Ve={total:H.length,pass:0,fail:0,skip:0,pending:0};H.forEach(Ct=>{Ct.verdict in Ve&&Ve[Ct.verdict]++;}),W.push({key:K!=null?`pr-${K}`:"general",label:K!=null?`PR #${K}`:"General",cases:H,summary:Ve});}return W.filter(K=>K.cases.length>0)},[Ae,b?.test_cases]),xt=F.total>0?(F.pass+F.fail)/F.total*100:0,O=i??b?.environment??null,ue=useMemo(()=>{if(!O||O==="production"||ce)return [];let t=b?.test_cases||[],g=new Set;for(let w of t)w.seed_user&&g.add(it(w.seed_user));if(O==="local")for(let w of pt)g.add(it(w));for(let w of ft)g.add(it(w));return [...g]},[b?.test_cases,O,pt,ft,ce]);useEffect(()=>{if(!O||O==="production"||ce||!f.isAuthenticated||!f.token){Be([]);return}let t=true,g=`${e.serverUrl}/widget/totp-seeds?${new URLSearchParams({app_slug:n,environment:O})}`,w=W=>fetch(g,{headers:{apikey:e.anonKey,Authorization:`Bearer ${W}`}});return (async()=>{try{let W=await w(f.token);if(W.status===401&&f.refreshNow){let H=await f.refreshNow();H&&(W=await w(H));}if(!t)return;if(!W.ok){Be([]);return}let pe=await W.json().catch(()=>null),K=(Array.isArray(pe?.seeds)?pe.seeds:[]).map(H=>H?.seed_user_slug).filter(H=>typeof H=="string"&&H.length>0);Be(K);}catch{t&&Be([]);}})(),()=>{t=false;}},[O,ce,f.isAuthenticated,f.token,f.refreshNow,n,e.serverUrl,e.anonKey]);let je=useMemo(()=>{let t=b?.auto_tooltip_seconds??ie?.auto_tooltip_seconds;return t!=null&&t>0?t*1e3:0},[b,ie]),vt=be==="ready"||be==="completed"||ie?.enabled&&ie.run;useEffect(()=>{if(!vt||Me.current||je<=0)return;Me.current=true,Y(true);let t=window.setTimeout(()=>Y(false),je);return ()=>window.clearTimeout(t)},[vt,je]);let wt=t=>jsxs("div",{style:u.caseRow,children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsx("div",{style:{marginTop:"2px",flexShrink:0,color:gn[t.verdict]},children:he===t.id?jsx(S,{d:m.loader,className:""}):jsx(S,{d:fn[t.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:r.text,lineHeight:1.3},children:t.title}),t.description&&jsx("div",{style:{fontSize:"9px",color:r.gripColor,marginTop:"2px"},children:t.description}),t.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(S,{d:m.key,size:10}),jsx("span",{children:t.seed_user})]}),t.url_path&&jsxs("a",{href:t.url_path,target:"_blank",rel:"noopener noreferrer",onClick:g=>{g.stopPropagation(),T&&(g.preventDefault(),T(t.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(S,{d:m.externalLink,size:10}),t.url_path]}),t.verdict==="fail"&&t.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:r.red,marginTop:"2px"},children:["\u2717 ",t.fail_reason]})]})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(g=>jsx("button",{onClick:()=>{if(t.verdict===g){$e(t.id,"pending"),oe(null);return}if(g==="fail"){oe(t.id),le("");return}oe(null),$e(t.id,g);},disabled:he!==null,style:u.verdictBtn(t.verdict===g,g==="pass"?r.green:g==="fail"?r.red:r.amber),children:g.toUpperCase()},g)),t.created_by_agent_name&&jsxs("span",{style:{fontSize:"8px",color:r.purple,marginLeft:"4px",display:"inline-flex",alignItems:"center",gap:"2px"},children:[jsx(S,{d:m.bot,size:8}),t.created_by_agent_name]}),t.verdict_by_display_name&&jsxs("span",{style:{fontSize:"8px",color:r.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[t.verdict_by_display_name,t.verdict_at&&jsx("span",{style:{opacity:.7},children:cn(t.verdict_at)})]})]}),ye===t.id&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:Z,onChange:g=>le(g.target.value),onKeyDown:g=>{g.key==="Enter"&&$e(t.id,"fail",Z.trim()||void 0),g.key==="Escape"&&(oe(null),le(""));},placeholder:"Reason (optional)...",style:u.input}),jsx("button",{onClick:()=>{$e(t.id,"fail",Z.trim()||void 0);},style:u.verdictBtn(true,r.red),children:"\u2713"})]})]},t.id);if((be==="no-match"||be==="loading")&&!(!f.isAuthenticated&&ie?.enabled&&ie.run)){if(!(O==="local"&&!ce))return null}if(!f.isAuthenticated&&ie?.enabled&&ie.run){let t=ie.run,g=t.summary,w=t.status==="completed";return jsx("div",{ref:A,style:{...u.root,left:c.x,top:c.y},children:jsxs("div",{style:{position:"relative"},onMouseEnter:()=>U(true),onMouseLeave:()=>{U(false),$(false),Y(false);},children:[jsxs("div",{style:{...u.pill(w),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:P,onPointerMove:R,onPointerUp:()=>{N();},children:[jsx(S,{d:m.grip,size:10,className:""}),t.ticket_id&&t.ticket_url?jsx("a",{href:t.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:r.amber,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:t.ticket_id}):null,t.pr_url?jsxs("a",{href:t.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:r.blue,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:["PR#",t.pr_number??t.pr_id]}):null,t.created_by_agent_name?t.codex_thread_id?jsxs("a",{href:`codex://threads/${t.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:r.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(S,{d:m.terminal,size:10}),t.created_by_agent_name]}):jsxs("span",{style:{color:r.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(S,{d:m.bot,size:10}),t.created_by_agent_name]}):null,jsxs("span",{style:w?{color:r.green}:void 0,children:[g.pass,"/",g.total]}),g.fail>0&&jsxs("span",{style:{color:r.red},children:[g.fail,"\u2717"]}),jsx("span",{onClick:W=>{W.stopPropagation(),f.openLogin();},style:{color:r.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!I&&(J||q)&&t.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:t.title}),(t.description||t.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:t.description||t.intro_notes}),jsx("div",{style:{marginTop:"4px",fontSize:"9px",color:r.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!f.isAuthenticated)return jsxs("div",{ref:A,style:{...u.root,left:c.x,top:c.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:P,onPointerMove:R,onPointerUp:N,children:[jsx("div",{style:{...u.handle,borderBottom:"none"},children:jsxs("div",{style:u.sub,children:[jsx(S,{d:m.grip,size:10,className:""}),jsx(S,{d:m.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"}),O==="local"&&ue.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,testRunId:b?.id||a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:h,prNumber:p,branchName:y,onAuthExpired:f.logout})}),jsx("button",{onClick:t=>{t.stopPropagation(),f.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(!b&&O==="local"&&!ce)return Vt?jsx("div",{ref:A,style:{...u.root,left:c.x,top:c.y},children:jsxs("div",{style:u.card(240,false),children:[jsxs("div",{style:u.handle,onPointerDown:P,onPointerMove:R,onPointerUp:N,onClick:()=>{D.current||ze(false);},children:[jsx(S,{d:m.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:u.title,children:"BotBuddy"}),y&&jsx("div",{style:u.sub,children:jsxs("span",{children:["\u2387 ",y]})})]}),jsx(S,{d:m.chevronUp,className:""}),jsx("button",{style:u.btn,onClick:t=>{t.stopPropagation(),ze(false);},children:jsx(S,{d:m.minus,className:""})})]}),jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[ue.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,testRunId:a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:h,prNumber:p,branchName:y,onAuthExpired:f.logout})}),jsx("button",{onClick:t=>{t.stopPropagation(),Yt();},disabled:Ke,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${r.green}`,background:`${r.green}22`,color:r.green,cursor:Ke?"wait":"pointer",width:"100%"},children:Ke?"Creating...":"Create test run for this branch"}),mt&&jsx("div",{style:{fontSize:"9px",color:r.red,marginTop:"8px"},children:mt})]})]})}):jsx("div",{ref:A,style:{...u.root,left:c.x,top:c.y},children:jsxs("div",{style:{...u.pill(false),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:P,onPointerMove:R,onPointerUp:()=>{N(),D.current||ze(true);},children:[jsx(S,{d:m.grip,size:9,className:""}),jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),ue.length>0&&jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,compact:true,onExpand:()=>ze(true),testRunId:a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:h,prNumber:p,branchName:y,onAuthExpired:f.logout})]})});let kt=()=>{D.current||(Y(false),X(t=>{let g=t==="mini"?"max":"mini";return $(g==="mini"),g}));},St=({icon:t,onClick:g})=>jsx("button",{style:u.btn,onClick:w=>{w.stopPropagation(),g(w);},children:jsx(S,{d:t,className:""})}),_t=()=>jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${r.borderSubtle}`,flexShrink:0},children:[b?.pr_url&&jsxs("a",{href:b.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...u.link(r.blue),textDecoration:"none"},children:[jsx(S,{d:m.pr,size:12}),b.pr_number?`PR#${b.pr_number}`:b.pr_id||"PR",jsx(S,{d:m.externalLink,size:8})]}),b?.ticket_url&&jsxs("a",{href:b.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...u.link(r.amber),textDecoration:"none"},children:[jsx(S,{d:m.ticket,size:12}),b.ticket_id||"Ticket",jsx(S,{d:m.externalLink,size:8})]}),b?.created_by_agent_name&&(b.codex_thread_id?jsxs("a",{href:`codex://threads/${b.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...u.link(r.purple),textDecoration:"none"},children:[jsx(S,{d:m.bot,size:12}),b.created_by_agent_name,jsx(S,{d:m.externalLink,size:8})]}):jsxs("span",{style:{...u.link(r.purple)},children:[jsx(S,{d:m.bot,size:12}),b.created_by_agent_name]})),O&&jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,testRunId:b?.id||a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:h,prNumber:p,branchName:y,onAuthExpired:f.logout}),jsx("span",{style:{...u.badge(b?.environment||"custom"),marginLeft:"auto"},children:b?.environment})]}),Rt=()=>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(Lt);},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",Lt]})]}),f.isAuthenticated&&(f.isExpired?jsx("button",{onClick:t=>{t.stopPropagation(),f.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:t=>{t.stopPropagation(),f.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:A,style:{...u.root,left:c.x,top:c.y},children:[ne==="mini"&&jsxs("div",{style:{position:"relative"},onMouseEnter:()=>U(true),onMouseLeave:()=>{U(false),$(false),Y(false);},children:[jsxs("div",{style:{...u.pill(ke),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:P,onPointerMove:R,onPointerUp:()=>{N(),D.current||kt();},children:[jsx(S,{d:m.grip,size:9,className:""}),b?.ticket_id&&jsx("span",{style:{color:r.amber,fontWeight:600},children:b.ticket_id}),b?.pr_number&&jsxs("span",{style:{color:r.blue,fontWeight:600},children:["PR#",b.pr_number]}),jsxs("span",{style:ke?{color:r.green}:void 0,children:[F.pass,"/",F.total]}),F.fail>0&&jsxs("span",{style:{color:r.red},children:[F.fail,"\u2717"]}),O&&jsx(Le,{config:e,appSlug:n,environment:O,seededUsers:ue,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:r,compact:true,onExpand:()=>X("expanded"),testRunId:b?.id||a,testRunToken:s,ticketId:d,targetUrl:ee,version:k,commitSha:h,prNumber:p,branchName:y,onAuthExpired:f.logout})]}),!I&&(J||q)&&b?.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:b.title}),(b.description||b.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:b.description||b.intro_notes})]})]}),ne==="expanded"&&jsxs("div",{style:u.card(300,ke),children:[jsxs("div",{style:u.handle,onPointerDown:P,onPointerMove:R,onPointerUp:N,onClick:kt,children:[jsx(S,{d:m.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:u.title,children:b?.title}),jsx("div",{style:u.sub,children:b?.branch_name&&jsxs("span",{children:["\u2387 ",b.branch_name]})})]}),jsx(S,{d:m.chevronUp,className:""}),jsx(St,{icon:m.minus,onClick:()=>{Y(false),$(true),X("mini");}})]}),jsxs("div",{style:u.stats,children:[jsxs("span",{style:{color:r.green},children:[F.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[F.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[F.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[F.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:F.total})]}),b?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:r.gripColor,borderBottom:`1px solid ${r.borderSubtle}`,flexShrink:0},children:b.description}),_t(),Rt(),jsx("div",{style:u.progress,children:jsx("div",{style:u.progressBar(xt)})})]}),ne==="max"&&jsxs("div",{style:{...u.card(G.w,ke),height:G.h,position:"relative"},children:[jsxs("div",{style:u.handle,onPointerDown:P,onPointerMove:R,onPointerUp:N,onClick:()=>{D.current||X("expanded");},children:[jsx(S,{d:m.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:u.title,children:b?.title}),jsx("div",{style:u.sub,children:b?.branch_name&&jsxs("span",{children:["\u2387 ",b.branch_name]})})]}),jsx(S,{d:m.chevronDown,className:""}),jsx(St,{icon:m.minus,onClick:()=>{Y(false),$(true),X("mini");}})]}),jsxs("div",{style:u.stats,children:[jsxs("span",{style:{color:r.green},children:[F.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[F.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[F.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[F.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:F.total})]}),b?.intro_notes&&jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${r.borderSubtle}`,fontSize:"10px",color:r.textMuted,fontStyle:"italic",flexShrink:0},children:b.intro_notes}),(b?.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(S,{d:m.search,size:11,className:""}),jsx("input",{value:Q,onChange:t=>ve(t.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:r.text,fontFamily:"monospace"}}),Q&&jsx("button",{onClick:()=>ve(""),style:{background:"none",border:"none",cursor:"pointer",color:r.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),be==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(S,{d:m.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:r.red},children:"Failed to load"}),jsx("button",{onClick:Ht,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),ke&&jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg},children:[jsx(S,{d:m.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:r.green,flex:1},children:"Run completed"}),jsx("button",{onClick:jt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),be!=="error"&&jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(b?.test_cases||[]).length===0?jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:"No test cases"}):Ae.length===0?jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:['No matches for "',Q,'"']}):ht?ht.map(t=>{let g=Ce.has(t.key);return jsxs("div",{children:[jsxs("button",{onClick:()=>we(t.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(S,{d:g?m.chevronDown:m.chevronUp,size:10,className:""}),jsx("span",{style:{fontSize:"10px",fontWeight:700,color:r.blue,flex:1,textAlign:"left"},children:t.label}),jsxs("span",{style:{fontSize:"9px",color:r.green},children:[t.summary.pass,"\u2713"]}),jsxs("span",{style:{fontSize:"9px",color:r.red},children:[t.summary.fail,"\u2717"]}),jsxs("span",{style:{fontSize:"9px",color:r.gripColor},children:[t.summary.pending,"\u25CC"]}),jsx("span",{style:{fontSize:"9px",color:r.textFaint},children:t.summary.total})]}),!g&&t.cases.map(w=>wt(w))]},t.key)}):Ae.map(t=>wt(t))}),Jt&&!ke&&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:Kt,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"})]}),_t(),Rt(),jsx("div",{style:u.progress,children:jsx("div",{style:u.progressBar(xt)})}),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:It,onPointerMove:Ft,onPointerUp:Dt,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{Te.current||(t.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"})})})]})]})}function Sn(e){let n=e;return !!n&&typeof n=="object"&&typeof n.tenant=="string"&&Array.isArray(n.entries)&&n.entries.every(i=>!!i&&typeof i.id=="string"&&typeof i.title=="string"&&!!i.body&&Array.isArray(i.body.ast)&&Array.isArray(i.links))}function st({endpoint:e,getToken:n}){let[i,d]=useState({feed:null,error:null,loading:true}),[a,s]=useState(0),_=useRef(n);_.current=n,useEffect(()=>{let h=true;return d(p=>({...p,error:null,loading:true})),(async()=>{try{let p=await _.current(),y=await fetch(e,{headers:{authorization:`Bearer ${p}`}}),T=null;try{T=await y.json();}catch{T=null;}if(!h)return;if(y.ok)Sn(T)?d({feed:T,error:null,loading:!1}):d({feed:null,error:"invalid_feed",loading:!1});else {let V=T?.error;d({feed:null,error:typeof V=="string"?V:`http_${y.status}`,loading:!1});}}catch(p){h&&d({feed:null,error:p instanceof Error&&p.message||"unavailable",loading:false});}})(),()=>{h=false;}},[e,a]);let k=useCallback(()=>s(h=>h+1),[]);return {...i,reload:k}}function Ut(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 De(e,n=""){return e.map((i,d)=>{let a=`${n}${d}`;switch(i.t){case "text":return i.v;case "code":return jsx("code",{className:"bbrn-code",children:i.v},a);case "strong":return jsx("strong",{children:De(i.c,`${a}.`)},a);case "em":return jsx("em",{children:De(i.c,`${a}.`)},a);default:return null}})}function Wt({ast:e}){return jsx(Fragment,{children:e.map((n,i)=>n.t==="list"?jsx("ul",{className:"bbrn-list",children:n.items.map((d,a)=>jsx("li",{children:De(d)},a))},i):n.t==="p"?jsx("p",{className:"bbrn-p",children:De(n.c)},i):null)})}var _n=`@layer bbrn {
|
|
2
|
+
.bbrn-root{display:grid;gap:12px;color:inherit;font:inherit}
|
|
3
|
+
.bbrn-root .bbrn-entry{border:1px solid hsl(var(--border,214 32% 91%));border-radius:var(--radius,.5rem);padding:16px;background:hsl(var(--card,0 0% 100%))}
|
|
4
|
+
.bbrn-root .bbrn-head{display:flex;gap:8px;align-items:baseline;flex-wrap:wrap}
|
|
5
|
+
.bbrn-root .bbrn-title{font-weight:600;font-size:1rem;margin:0}
|
|
6
|
+
.bbrn-root .bbrn-badge{font-size:.75rem;border:1px solid currentColor;border-radius:999px;padding:0 8px}
|
|
7
|
+
.bbrn-root .bbrn-meta{color:hsl(var(--muted-foreground,215 16% 47%));font-size:.8rem}
|
|
8
|
+
.bbrn-root .bbrn-p{margin:.5em 0}
|
|
9
|
+
.bbrn-root .bbrn-list{margin:.5em 0;padding-left:1.25em;list-style:disc}
|
|
10
|
+
.bbrn-root .bbrn-code{font-family:ui-monospace,monospace;font-size:.85em;padding:0 4px;border-radius:4px;background:hsl(var(--muted,210 40% 96%))}
|
|
11
|
+
.bbrn-root .bbrn-links{display:flex;gap:12px;flex-wrap:wrap;margin-top:8px;font-size:.85rem}
|
|
12
|
+
.bbrn-root .bbrn-link{text-decoration:underline}
|
|
13
|
+
.bbrn-root .bbrn-retry{margin-left:8px;text-decoration:underline;background:none;border:0;padding:0;color:inherit;cursor:pointer;font:inherit}
|
|
14
|
+
}`;function Rn({endpoint:e,getToken:n,onNavigate:i}){let{feed:d,error:a,loading:s,reload:_}=st({endpoint:e,getToken:n}),k=h=>p=>{!i||p.defaultPrevented||p.button!==0||p.metaKey||p.ctrlKey||p.shiftKey||p.altKey||(p.preventDefault(),i(h));};return jsxs("section",{className:"bbrn-root","aria-label":"Release notes","aria-busy":s,"data-bbrn-audience":d?.audience,children:[jsx("style",{children:_n}),s&&!d&&jsx("p",{className:"bbrn-meta",role:"status",children:"Loading release notes\u2026"}),!s&&a&&jsxs("p",{className:"bbrn-meta",role:"alert","data-bbrn-error":a,children:["Release notes could not be loaded.",jsx("button",{type:"button",className:"bbrn-retry",onClick:_,children:"Retry"})]}),!a&&d&&d.entries.length===0&&jsxs("p",{className:"bbrn-meta",children:["No release notes yet. Submit one with ",jsx("code",{className:"bbrn-code",children:"bb release-notes submit"}),"."]}),!a&&d?.entries.map(h=>jsxs("article",{className:"bbrn-entry","data-entry-id":h.id,"data-source-key":h.source_key,children:[jsxs("div",{className:"bbrn-head",children:[jsx("h2",{className:"bbrn-title",children:h.title}),jsx("span",{className:"bbrn-badge","data-bbrn-type":h.type,children:h.type}),jsxs("span",{className:"bbrn-meta",children:[h.source_key," \xB7 ",h.state," \xB7 revision ",h.revision]})]}),jsx(Wt,{ast:h.body.ast}),h.links.length>0&&jsx("div",{className:"bbrn-links",children:h.links.map((p,y)=>{let T=Ut(p.url);return T?T.kind==="external"?jsx("a",{className:"bbrn-link",href:T.href,target:"_blank",rel:"noopener noreferrer","data-link-kind":p.kind??void 0,children:p.name},y):jsx("a",{className:"bbrn-link",href:T.href,onClick:k(T.href),"data-link-kind":p.kind??void 0,children:p.name},y):null})})]},h.id))]})}export{Wt as ReleaseNoteBody,Rn as ReleaseNotes,xn as TestRunWidget,Ut as safeHref,Ge as useDraggable,Xe as useRealtimeRefresh,st as useReleaseNotes,Qe as useTestRun,ot as useWidgetAuth};
|
package/package.json
CHANGED