@botbuddy/react 0.10.13 → 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 +34 -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,39 @@
|
|
|
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
|
+
|
|
18
|
+
## 0.11.0
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
- **The 2FA chip now lists every registered persona for the app + environment,
|
|
23
|
+
not just the `seed_user`s on the resolved run's cases (BOT-905).** The widget
|
|
24
|
+
fetches the full set of registered TOTP personas from a new
|
|
25
|
+
`GET /widget/totp-seeds` endpoint and merges them — deduped — with the
|
|
26
|
+
case-derived and local-file slugs. The chip therefore lights up (`2FA · N`)
|
|
27
|
+
even on a run with **zero** test cases, so a tester can mint an MFA code for
|
|
28
|
+
any seeded persona (e.g. `seed-vendor-admin@microsoft.seed.test`) without
|
|
29
|
+
first authoring throwaway cases that reference it. The fetch is gated to
|
|
30
|
+
authenticated, non-production requests; the raw `totp_secret` never crosses
|
|
31
|
+
the endpoint (only `seed_user_slug` + `expires_at`, expired rows filtered),
|
|
32
|
+
and production environments and hostnames are rejected server-side.
|
|
33
|
+
|
|
34
|
+
Consumers should mount the widget with the slug their seeds are keyed on
|
|
35
|
+
(Supply Guard: `appSlug="supplyspark-ent"`).
|
|
36
|
+
|
|
3
37
|
## 0.10.13
|
|
4
38
|
|
|
5
39
|
### Fixed
|
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 we=8;function Ke(e,r,s,p,c,a){let T=Math.max(we,c-s-we),S=Math.max(we,a-p-we);return {x:Math.min(Math.max(e,we),T),y:Math.min(Math.max(r,we),S)}}function Ve(e,r){let[s,p]=react.useState({x:e,y:r}),c=react.useRef(false),a=react.useRef({x:0,y:0}),T=react.useRef(false),S=react.useCallback(y=>{c.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=>{c.current&&(T.current=true,p({x:y.clientX-a.current.x,y:y.clientY-a.current.y}));},[]),b=react.useCallback(()=>{c.current=false;},[]);return {pos:s,setPos:p,onPointerDown:S,onPointerMove:_,onPointerUp:b,didDrag:T}}function Ye(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 h=new URL(e.supabaseUrl),n=["localhost","127.0.0.1","::1"].includes(h.hostname);if(h.protocol==="http:"&&!n)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");h.protocol=h.protocol==="https:"?"wss:":"ws:",_=h.toString().replace(/\/$/,"");}catch{S();}let b=null,y=null,D=null,V=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 h={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(++V)};b.send(JSON.stringify(h));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(++V)};b.send(JSON.stringify(n)),y=setInterval(()=>{b?.readyState===WebSocket.OPEN&&b.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++V)}));},3e4);},b.onmessage=h=>{try{JSON.parse(h.data).event==="postgres_changes"&&p.current();}catch{}},b.onclose=()=>{x(),a||(D=setTimeout(M,3e3));},b.onerror=()=>{b?.close();};}},x=()=>{y&&(clearInterval(y),y=null);};return M(),()=>{a=true,x(),D&&clearTimeout(D),T&&clearInterval(T),b&&(b.onclose=null,b.onerror=null,b.close());}}let c=setInterval(()=>p.current(),15e3);return ()=>clearInterval(c)},[e.supabaseUrl,e.anonKey,r]);}var jt="botbuddy:created-test-run:";function Kt(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function Vt(e){return `${jt}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",Kt(e.targetUrl),e.branchName||""].join("|"))}`}function $e(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 Yt(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 qe(e){let[r,s]=react.useState(null),[p,c]=react.useState("loading"),a=Vt(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 Yt(e.testRunToken);if(!x&&!_){c("no-match"),s(null);return}if(x&&!e.ticketId){c("no-match"),s(null);return}let h=new URLSearchParams;x&&h.set("token",x),e.ticketId&&h.set("ticket_id",e.ticketId),h.set("app_slug",e.appSlug),e.environment&&h.set("environment",e.environment),_&&h.set("test_run_id",_),e.targetUrl&&h.set("target_url",e.targetUrl),e.version&&h.set("version",e.version),e.commitSha&&h.set("commit_sha",e.commitSha),e.prNumber&&h.set("pr_number",String(e.prNumber)),e.branchName&&h.set("branch_name",e.branchName);let n=await fetch(`${e.config.serverUrl}/widget/test-run?${h.toString()}`,{headers:$e(e.config,e.authToken)});if(n.status===404){c("no-match"),s(null);return}if(n.status===401||n.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),c("error");return}if(!n.ok){c("error");return}let d=await n.json();if(!d||d.run===null){c("no-match"),s(null);return}b(d),c(d.status==="completed"?"completed":"ready");}catch{c("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]),Ye(e.config,r?.id,y),{run:r,widgetState:p,fetchRun:y,setVerdict:async(x,h,n,d="human")=>(s(W=>{if(!W)return null;let Y=W.test_cases.map(I=>I.id===x?{...I,verdict:h,fail_reason:h==="fail"&&n||null,verdict_by_display_name:d,verdict_at:new Date().toISOString()}:I),N={total:Y.length,pending:0,pass:0,fail:0,skip:0};return Y.forEach(I=>{I.verdict in N&&N[I.verdict]++;}),{...W,test_cases:Y,summary:N}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${x}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...$e(e.config,e.authToken)},body:JSON.stringify({verdict:h,fail_reason:n,display_name:d})})).ok),markComplete:async()=>r?(s(h=>h?{...h,status:"completed"}:null),c("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${r.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...$e(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",...$e(e.config,e.authToken)}});return x.ok&&y(),x.ok},setRun:b}}var Ze="botbuddy-widget-auth-token",Qe="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),c=JSON.parse(p);return typeof c.exp=="number"?c.exp*1e3:null}catch{return null}}var qt=2500,Gt=6e4;function et(e){let[r,s]=react.useState(()=>{try{return localStorage.getItem(Ze)}catch(M){return console.warn("Unable to read BotBuddy widget auth token",M),null}}),[p,c]=react.useState(()=>{try{return localStorage.getItem(Qe)}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&&c(x);try{localStorage.setItem(Ze,M),x&&localStorage.setItem(Qe,x);}catch(h){console.warn("Unable to persist BotBuddy widget auth token",h);}},[]);react.useEffect(()=>{let M=new URL(e).origin,x=h=>{h.origin===M&&h.data?.type==="botbuddy-widget-auth"&&h.data.token&&T(h.data.token,h.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 h=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 H=false,W=()=>{window.removeEventListener("message",Y),clearTimeout(N);try{d.remove();}catch{}a.current=null;},Y=I=>{if(I.origin===M){if(I.data?.type==="botbuddy-widget-auth-failed"){if(H)return;H=true,n(null),W();return}I.data?.type!=="botbuddy-widget-auth"||!I.data.token||H||(H=true,n(String(I.data.token)),W());}},N=setTimeout(()=>{H||(H=true,n(null),W());},qt);window.addEventListener("message",Y),document.body.appendChild(d);});return a.current=h,h},[e]);react.useEffect(()=>{if(!r)return;let M=Re(r);if(!M)return;let x=M-Date.now()-Gt,h=window.setTimeout(()=>{S();},Math.max(0,x));return ()=>window.clearTimeout(h)},[r,S]);let _=react.useCallback(()=>{let M=new URL("/widget-auth",e);M.searchParams.set("origin",window.location.origin);let x=420,h=520,n=window.screenX+(window.innerWidth-x)/2,d=window.screenY+(window.innerHeight-h)/2;window.open(M.toString(),"botbuddy-auth",`width=${x},height=${h},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 h=window.setTimeout(()=>b(n=>n+1),x);return ()=>window.clearTimeout(h)},[r]);let y=react.useCallback(()=>{s(null),c(null);try{localStorage.removeItem(Ze),localStorage.removeItem(Qe);}catch(M){console.warn("Unable to clear BotBuddy widget auth token",M);}},[]),D=Re(r),V=D!==null&&D<=Date.now();return {token:r,displayName:p,isAuthenticated:!!r,isExpired:V,openLogin:_,refreshNow:S,logout:y}}var We=null;function Xt(){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(Xt(),{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,c]of Object.entries(r))typeof c=="string"&&c.length>0&&(s[p]=c);return s}catch{return null}})(),We)}async function wt(e){return (await Ie())?.[e]??null}function Zt(e){let r=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),s="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",p=[],c=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,c+=5,c>=8&&(c-=8,p.push(a>>>c&255));}return Uint8Array.from(p)}async function St(e,r=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let s=Zt(e),p=new Uint8Array(s.byteLength);p.set(s);let c=Math.floor(r/1e3/30),a=new Uint8Array(8),T=Math.floor(c/4294967296),S=c>>>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),D=y[y.length-1]&15;return (((y[D]&127)<<24|(y[D+1]&255)<<16|(y[D+2]&255)<<8|y[D+3]&255)%1e6).toString().padStart(6,"0")}var kt="0.10.13";function en(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 c=r.getDate(),a=r.toLocaleString("en",{month:"short"}),T=r.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${a} ${c}, ${T}`}var v=({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})}),f={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 tn(){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,c=p();c&&r(c);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 nn(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 rn={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},on={pending:f.circle,pass:f.check,fail:f.x,skip:f.skip},_t={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)"}},sn=["app.supply-guard.io"];function an(e,r=[]){if(!e)return false;let s=e.toLowerCase();return [...sn,...r].map(c=>c.toLowerCase()).includes(s)}var ln=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=_t[r]||_t.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 Mt(e){return e.split("/")[0].trim()}async function dn(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:c,tk:a,compact:T=false,onExpand:S,onAuthExpired:_,refreshAuth:b,requestLogin:y,testRunId:D,testRunToken:V,ticketId:M,targetUrl:x,version:h,commitSha:n,prNumber:d,branchName:H}){let[W,Y]=react.useState(false),[N,I]=react.useState(null),[$,ke]=react.useState(null),[ie,m]=react.useState(null),[Ee,se]=react.useState(null),[Q,q]=react.useState(null),[G,ae]=react.useState(null);react.useEffect(()=>{s==="local"&&Ie();},[s]);let fe=react.useCallback(l=>{I(l),m(null),se(null),ae(null);let E=Re(c);if(s!=="local"&&y&&E!==null&&E<=Date.now()){q({slug:l,token:c||null}),ae(l),I(null),y();return}let R=C=>{m(C),se(l),window.setTimeout(()=>{se(P=>P===l?null:P),m(P=>P===C?null:P);},3e3);},k=new URLSearchParams({app_slug:r,seed_user_slug:l,environment:s});D&&k.set("test_run_id",D),V&&k.set("public_token",V),M&&k.set("ticket_id",M),x&&k.set("target_url",x),h&&k.set("version",h),n&&k.set("commit_sha",n),d&&k.set("pr_number",String(d)),H&&k.set("branch_name",H);let L=async C=>{let P={apikey:e.anonKey,Authorization:`Bearer ${C}`};try{let B=await fetch(`${e.serverUrl}/widget/totp-code?${k}`,{headers:P});if(!B.ok){let ue=await B.json().catch(()=>({error:`HTTP ${B.status}`}));return {ok:!1,status:B.status,error:ue.error||`HTTP ${B.status}`}}let J=await B.json();return {ok:!0,code:String(J.code)}}catch{return {ok:false,status:0,error:"Network error"}}},F=(async()=>{if(s==="local"){let B=await wt(l);if(B)try{return {ok:!0,code:await St(B)}}catch{}}let C=await L(c||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=F.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 F;if(!C.ok){C.status===401?(q({slug:l,token:c||null}),ae(l)):R(C.status===404?"No 2FA seed registered":C.error),I(null);return}let P=A?await A:false,B=P?true:await dn(C.code),J=P||B;ke({slug:l,code:C.code,copied:J}),window.setTimeout(()=>ke(ue=>ue?.slug===l?null:ue),J?2500:6e3),Y(false),I(null);})();},[e.serverUrl,e.anonKey,c,r,s,D,V,M,x,h,n,d,H,b,y]),re=react.useCallback(l=>{q({slug:l,token:c||null}),y?.();},[c,y]),he=react.useCallback(l=>{G===l?re(l):fe(l);},[G,re,fe]);react.useEffect(()=>{if(!Q||!c||c===Q.token)return;let l=Q.slug;q(null),fe(l);},[c,fe,Q]);let me=react.useRef(null),_e=react.useRef(null);if(react.useLayoutEffect(()=>{if(!W)return;let l=me.current,E=_e.current;if(!l||!E||typeof window>"u")return;let R=()=>{let k=l.getBoundingClientRect(),L=E.getBoundingClientRect(),F=window.innerWidth,A=window.innerHeight,C=k.left,P=k.top-L.height-6;P<8&&(P=k.bottom+6);let B=Math.max(8,F-L.width-8),J=Math.max(8,A-L.height-8);C=Math.min(Math.max(C,8),B),P=Math.min(Math.max(P,8),J),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);}},[W,p.length,ie]),react.useEffect(()=>{if(!W)return;let l=E=>{let R=E.target;_e.current?.contains(R)||me.current?.contains(R)||Y(false);};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[W]),p.length===0)return null;if(T){let l=p.length>1,E=p[0],R=!l&&G===E,k=B=>{if(B.stopPropagation(),l&&S){S();return}he(E);},L=!!Ee,F=!!$,A=F&&$.copied,C=F&&!$.copied,P=R?a.blue:L?a.red:A?a.green:C?a.amber:a.purple;return jsxRuntime.jsxs("span",{onPointerDown:B=>B.stopPropagation(),onPointerUp:B=>B.stopPropagation(),onPointerMove:B=>B.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(v,{d:R?f.key:L?f.alert:A?f.check:C?f.copy:f.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=N===l,R=$?.slug===l,k=R&&$.copied,L=R&&!$.copied,F=Ee===l,A=G===l,C=A?a.blue:F?a.red:k?a.green:L?a.amber:a.purple;return jsxRuntime.jsxs("button",{onClick:P=>{P.stopPropagation(),he(l);},disabled:E,style:{...Ct(C),cursor:E?"wait":"pointer",opacity:E?.6:1},title:A?"Sign in to BotBuddy to refresh 2FA":F?ie||"Failed":L?`Clipboard blocked \u2014 code: ${$.code}`:`Copy 2FA code for ${l}`,children:[jsxRuntime.jsx(v,{d:A?f.key:F?f.alert:k?f.check:L?f.copy:f.shield,size:12}),A?"Sign in":k?"Copied":L?$.code:F?"Failed":E?"\u2026":`2FA \xB7 ${l}`]})}let le=!!G&&!W,X=!!Ee&&!W,ye=!!$&&$.copied,xe=!!$&&!$.copied,Ue=le?a.blue:X?a.red:ye?a.green:xe?a.amber:a.purple,De=W&&typeof document<"u"?reactDom.createPortal(jsxRuntime.jsxs("div",{ref:_e,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=N===l,R=G===l;return jsxRuntime.jsxs("button",{onClick:k=>{k.stopPropagation(),he(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(v,{d:R?f.key:f.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:me,onClick:l=>{if(l.stopPropagation(),le&&G){re(G);return}Y(E=>!E),m(null),se(null);},style:{...Ct(Ue),cursor:"pointer"},title:le?"Sign in to BotBuddy to refresh 2FA":X?ie||"Failed":xe?`Clipboard blocked \u2014 code: ${$.code}`:"Choose a persona to copy a 2FA code for",children:[jsxRuntime.jsx(v,{d:le?f.key:X?f.alert:ye?f.check:xe?f.copy:f.shield,size:12}),le?"Sign in":ye?"Copied":xe?$.code:X?"Failed":`2FA \xB7 ${p.length}`,!le&&jsxRuntime.jsx(v,{d:W?f.chevronUp:f.chevronDown,size:8})]}),De]})}function Ct(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 Tt="botbuddy-widget-state";function cn({config:e,appSlug:r,environment:s,ticketId:p,testRunId:c,testRunToken:a,targetUrl:T,version:S,commitSha:_,prNumber:b,branchName:y,onNavigate:D,displayName:V="human",defaultMode:M="mini",defaultPosition:x}){let h=tn(),n=react.useMemo(()=>nn(h),[h]),d=react.useMemo(()=>ln(n),[n]),[H,W]=react.useState(false),[Y,N]=react.useState(false),[I,$]=react.useState(false),ke=react.useRef(false),ie=e.dashboardUrl||"https://app.bot-buddy.ai",m=et(ie),se=(()=>{try{let t=typeof window<"u"?localStorage.getItem(Tt):null;if(t)return JSON.parse(t)}catch{}return null})(),[Q,q]=react.useState(se?.mode||M),[G,ae]=react.useState(""),[fe,re]=react.useState(null),[he,me]=react.useState(null),[_e,le]=react.useState(new Set),[X,ye]=react.useState(""),xe=react.useCallback(t=>{le(u=>{let w=new Set(u);return w.has(t)?w.delete(t):w.add(t),w});},[]),Ue=se?.x??x?.x??16,De=se?.y??x?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:l,setPos:E,onPointerDown:R,onPointerMove:k,onPointerUp:L,didDrag:F}=Ve(Ue,De),A=react.useRef(null);react.useEffect(()=>{try{localStorage.setItem(Tt,JSON.stringify({mode:Q,x:l.x,y:l.y}));}catch{}},[Q,l.x,l.y]),react.useLayoutEffect(()=>{if(typeof window>"u")return;let t=A.current;if(!t)return;let u=t.getBoundingClientRect(),w=Ke(l.x,l.y,u.width,u.height,window.innerWidth,window.innerHeight);(w.x!==l.x||w.y!==l.y)&&E(w);}),react.useEffect(()=>{if(typeof window>"u")return;let t=()=>{let u=A.current;if(!u)return;let w=u.getBoundingClientRect(),K=Ke(l.x,l.y,w.width,w.height,window.innerWidth,window.innerHeight);(K.x!==l.x||K.y!==l.y)&&E(K);};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[l.x,l.y,E]);let C=react.useRef(m.isAuthenticated);react.useEffect(()=>{!C.current&&m.isAuthenticated&&q("max"),C.current=m.isAuthenticated;},[m.isAuthenticated]);let P="botbuddy-widget-max-size",B=()=>{try{let t=localStorage.getItem(P);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[J,ue]=react.useState(B),Me=react.useRef(false),Ce=react.useRef({x:0,y:0,w:0,h:0}),Pt=react.useCallback(t=>{t.stopPropagation(),Me.current=true,Ce.current={x:t.clientX,y:t.clientY,w:J.w,h:J.h},t.target.setPointerCapture(t.pointerId);},[J]),Et=react.useCallback(t=>{if(!Me.current)return;let u=Math.max(280,Math.min(600,Ce.current.w+(t.clientX-Ce.current.x))),w=Math.max(300,Math.min(window.innerHeight*.9,Ce.current.h+(t.clientY-Ce.current.y)));ue({w:u,h:w});},[]),Lt=react.useCallback(()=>{Me.current&&(Me.current=false,ue(t=>(localStorage.setItem(P,JSON.stringify(t)),t)));},[]),Z=T??(typeof window<"u"?window.location.href:void 0),tt=m.displayName||V,[oe,nt]=react.useState(null);react.useEffect(()=>{if(m.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),c&&t.set("test_run_id",c),Z&&t.set("target_url",Z),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(u=>u.json()).then(u=>nt(u)).catch(()=>nt(null));},[m.isAuthenticated,e.serverUrl,e.anonKey,r,s,p,c,a,Z,S,_,b,y]);let rt=react.useRef(false),Bt=react.useCallback(()=>{rt.current||m.logout();},[m.logout]),{run:g,widgetState:pe,fetchRun:zt,setVerdict:ot,markComplete:$t,resetRun:At,setRun:it}=qe({config:e,appSlug:r,environment:s,ticketId:p,testRunId:c,testRunToken:a,targetUrl:Z,version:S,commitSha:_,prNumber:b?String(b):void 0,branchName:y,authToken:m.token,onAuthExpired:Bt});rt.current=!!g;let[st,at]=react.useState([]),[Fe,lt]=react.useState(false),[dt,ct]=react.useState(null),[Wt,Le]=react.useState(false),be=an(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);react.useEffect(()=>{if((s??"local")!=="local"||be){at([]);return}let t=true;return Ie().then(u=>{t&&at(Object.keys(u||{}));}),()=>{t=false;}},[s,be]);let It=react.useCallback(async()=>{if(!(!m.isAuthenticated||!m.token)){lt(true),ct(null);try{let t=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${m.token}`},body:JSON.stringify({app_slug:r,environment:s||"local",target_url:Z,branch_name:y,commit_sha:_,pr_number:b,ticket_id:p,title:`${p||r} local validation`})}),u=await t.json().catch(()=>({}));if(!t.ok)throw new Error(u.error||`HTTP ${t.status}`);it(u),q("max");}catch(t){ct(t.message);}finally{lt(false);}}},[m.isAuthenticated,m.token,e.serverUrl,e.anonKey,r,s,Z,y,_,b,p,it]),Be=react.useCallback(async(t,u,w)=>{me(t);try{await ot(t,u,w,tt);}finally{me(null),re(null),ae("");}},[ot,tt]),U=g?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},Ut=U.total>0&&U.pending===0,ve=pe==="completed",ze=react.useMemo(()=>{let t=g?.test_cases||[];if(!X.trim())return t;let u=X.toLowerCase();return t.filter(w=>w.title.toLowerCase().includes(u)||w.description&&w.description.toLowerCase().includes(u)||w.url_path&&w.url_path.toLowerCase().includes(u)||w.seed_user&&w.seed_user.toLowerCase().includes(u))},[g?.test_cases,X]),ut=react.useMemo(()=>{let t=ze,u=g?.test_cases||[];if(new Set(u.map(O=>O.source_pr_number)).size<=1)return null;let K=[],Te=new Map;t.forEach(O=>{let ee=O.source_pr_number;Te.has(ee)||Te.set(ee,[]),Te.get(ee).push(O);});let Dt=[...Te.keys()].sort((O,ee)=>O===null?1:ee===null?-1:ee-O);for(let O of Dt){let ee=Te.get(O),Oe={total:ee.length,pass:0,fail:0,skip:0,pending:0};ee.forEach(bt=>{bt.verdict in Oe&&Oe[bt.verdict]++;}),K.push({key:O!=null?`pr-${O}`:"general",label:O!=null?`PR #${O}`:"General",cases:ee,summary:Oe});}return K.filter(O=>O.cases.length>0)},[ze,g?.test_cases]),pt=U.total>0?(U.pass+U.fail)/U.total*100:0,j=s??g?.environment??null,de=react.useMemo(()=>{if(!j||j==="production"||be)return [];let t=g?.test_cases||[],u=new Set;for(let w of t)w.seed_user&&u.add(Mt(w.seed_user));if(j==="local")for(let w of st)u.add(Mt(w));return [...u]},[g?.test_cases,j,st,be]),Ne=react.useMemo(()=>{let t=g?.auto_tooltip_seconds??oe?.auto_tooltip_seconds;return t!=null&&t>0?t*1e3:0},[g,oe]),gt=pe==="ready"||pe==="completed"||oe?.enabled&&oe.run;react.useEffect(()=>{if(!gt||ke.current||Ne<=0)return;ke.current=true,N(true);let t=window.setTimeout(()=>N(false),Ne);return ()=>window.clearTimeout(t)},[gt,Ne]);let ft=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:rn[t.verdict]},children:he===t.id?jsxRuntime.jsx(v,{d:f.loader,className:""}):jsxRuntime.jsx(v,{d:on[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(v,{d:f.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:u=>{u.stopPropagation(),D&&(u.preventDefault(),D(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(v,{d:f.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(u=>jsxRuntime.jsx("button",{onClick:()=>{if(t.verdict===u){Be(t.id,"pending"),re(null);return}if(u==="fail"){re(t.id),ae("");return}re(null),Be(t.id,u);},disabled:he!==null,style:d.verdictBtn(t.verdict===u,u==="pass"?n.green:u==="fail"?n.red:n.amber),children:u.toUpperCase()},u)),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(v,{d:f.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:en(t.verdict_at)})]})]}),fe===t.id&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:G,onChange:u=>ae(u.target.value),onKeyDown:u=>{u.key==="Enter"&&Be(t.id,"fail",G.trim()||void 0),u.key==="Escape"&&(re(null),ae(""));},placeholder:"Reason (optional)...",style:d.input}),jsxRuntime.jsx("button",{onClick:()=>{Be(t.id,"fail",G.trim()||void 0);},style:d.verdictBtn(true,n.red),children:"\u2713"})]})]},t.id);if((pe==="no-match"||pe==="loading")&&!(!m.isAuthenticated&&oe?.enabled&&oe.run)){if(!(j==="local"&&!be))return null}if(!m.isAuthenticated&&oe?.enabled&&oe.run){let t=oe.run,u=t.summary,w=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:()=>W(true),onMouseLeave:()=>{W(false),$(false),N(false);},children:[jsxRuntime.jsxs("div",{style:{...d.pill(w),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:R,onPointerMove:k,onPointerUp:()=>{L();},children:[jsxRuntime.jsx(v,{d:f.grip,size:10,className:""}),t.ticket_id&&t.ticket_url?jsxRuntime.jsx("a",{href:t.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:K=>K.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:K=>K.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:K=>K.stopPropagation(),style:{color:n.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(v,{d:f.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(v,{d:f.bot,size:10}),t.created_by_agent_name]}):null,jsxRuntime.jsxs("span",{style:w?{color:n.green}:void 0,children:[u.pass,"/",u.total]}),u.fail>0&&jsxRuntime.jsxs("span",{style:{color:n.red},children:[u.fail,"\u2717"]}),jsxRuntime.jsx("span",{onClick:K=>{K.stopPropagation(),m.openLogin();},style:{color:n.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!I&&(H||Y)&&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(!m.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(v,{d:f.grip,size:10,className:""}),jsxRuntime.jsx(v,{d:f.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"}),j==="local"&&de.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsxRuntime.jsx(Pe,{config:e,appSlug:r,environment:j,seededUsers:de,authToken:m.token,refreshAuth:m.refreshNow,requestLogin:m.openLogin,tk:n,testRunId:g?.id||c,testRunToken:a,ticketId:p,targetUrl:Z,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:m.logout})}),jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),m.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(!g&&j==="local"&&!be)return Wt?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:()=>{F.current||Le(false);},children:[jsxRuntime.jsx(v,{d:f.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(v,{d:f.chevronUp,className:""}),jsxRuntime.jsx("button",{style:d.btn,onClick:t=>{t.stopPropagation(),Le(false);},children:jsxRuntime.jsx(v,{d:f.minus,className:""})})]}),jsxRuntime.jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[de.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsxRuntime.jsx(Pe,{config:e,appSlug:r,environment:j,seededUsers:de,authToken:m.token,refreshAuth:m.refreshNow,requestLogin:m.openLogin,tk:n,testRunId:c,testRunToken:a,ticketId:p,targetUrl:Z,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:m.logout})}),jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),It();},disabled:Fe,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${n.green}`,background:`${n.green}22`,color:n.green,cursor:Fe?"wait":"pointer",width:"100%"},children:Fe?"Creating...":"Create test run for this branch"}),dt&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:n.red,marginTop:"8px"},children:dt})]})]})}):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(),F.current||Le(true);},children:[jsxRuntime.jsx(v,{d:f.grip,size:9,className:""}),jsxRuntime.jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),de.length>0&&jsxRuntime.jsx(Pe,{config:e,appSlug:r,environment:j,seededUsers:de,authToken:m.token,refreshAuth:m.refreshNow,requestLogin:m.openLogin,tk:n,compact:true,onExpand:()=>Le(true),testRunId:c,testRunToken:a,ticketId:p,targetUrl:Z,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:m.logout})]})});let ht=()=>{F.current||(N(false),q(t=>{let u=t==="mini"?"max":"mini";return $(u==="mini"),u}));},mt=({icon:t,onClick:u})=>jsxRuntime.jsx("button",{style:d.btn,onClick:w=>{w.stopPropagation(),u(w);},children:jsxRuntime.jsx(v,{d:t,className:""})}),yt=()=>jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${n.borderSubtle}`,flexShrink:0},children:[g?.pr_url&&jsxRuntime.jsxs("a",{href:g.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.blue),textDecoration:"none"},children:[jsxRuntime.jsx(v,{d:f.pr,size:12}),g.pr_number?`PR#${g.pr_number}`:g.pr_id||"PR",jsxRuntime.jsx(v,{d:f.externalLink,size:8})]}),g?.ticket_url&&jsxRuntime.jsxs("a",{href:g.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.amber),textDecoration:"none"},children:[jsxRuntime.jsx(v,{d:f.ticket,size:12}),g.ticket_id||"Ticket",jsxRuntime.jsx(v,{d:f.externalLink,size:8})]}),g?.created_by_agent_name&&(g.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${g.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.purple),textDecoration:"none"},children:[jsxRuntime.jsx(v,{d:f.bot,size:12}),g.created_by_agent_name,jsxRuntime.jsx(v,{d:f.externalLink,size:8})]}):jsxRuntime.jsxs("span",{style:{...d.link(n.purple)},children:[jsxRuntime.jsx(v,{d:f.bot,size:12}),g.created_by_agent_name]})),j&&jsxRuntime.jsx(Pe,{config:e,appSlug:r,environment:j,seededUsers:de,authToken:m.token,refreshAuth:m.refreshNow,requestLogin:m.openLogin,tk:n,testRunId:g?.id||c,testRunToken:a,ticketId:p,targetUrl:Z,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:m.logout}),jsxRuntime.jsx("span",{style:{...d.badge(g?.environment||"custom"),marginLeft:"auto"},children:g?.environment})]}),xt=()=>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(kt);},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",kt]})]}),m.isAuthenticated&&(m.isExpired?jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),m.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(),m.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:[Q==="mini"&&jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>W(true),onMouseLeave:()=>{W(false),$(false),N(false);},children:[jsxRuntime.jsxs("div",{style:{...d.pill(ve),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:R,onPointerMove:k,onPointerUp:()=>{L(),F.current||ht();},children:[jsxRuntime.jsx(v,{d:f.grip,size:9,className:""}),g?.ticket_id&&jsxRuntime.jsx("span",{style:{color:n.amber,fontWeight:600},children:g.ticket_id}),g?.pr_number&&jsxRuntime.jsxs("span",{style:{color:n.blue,fontWeight:600},children:["PR#",g.pr_number]}),jsxRuntime.jsxs("span",{style:ve?{color:n.green}:void 0,children:[U.pass,"/",U.total]}),U.fail>0&&jsxRuntime.jsxs("span",{style:{color:n.red},children:[U.fail,"\u2717"]}),j&&jsxRuntime.jsx(Pe,{config:e,appSlug:r,environment:j,seededUsers:de,authToken:m.token,refreshAuth:m.refreshNow,requestLogin:m.openLogin,tk:n,compact:true,onExpand:()=>q("expanded"),testRunId:g?.id||c,testRunToken:a,ticketId:p,targetUrl:Z,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:m.logout})]}),!I&&(H||Y)&&g?.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:g.title}),(g.description||g.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:g.description||g.intro_notes})]})]}),Q==="expanded"&&jsxRuntime.jsxs("div",{style:d.card(300,ve),children:[jsxRuntime.jsxs("div",{style:d.handle,onPointerDown:R,onPointerMove:k,onPointerUp:L,onClick:ht,children:[jsxRuntime.jsx(v,{d:f.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:d.title,children:g?.title}),jsxRuntime.jsx("div",{style:d.sub,children:g?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",g.branch_name]})})]}),jsxRuntime.jsx(v,{d:f.chevronUp,className:""}),jsxRuntime.jsx(mt,{icon:f.minus,onClick:()=>{N(false),$(true),q("mini");}})]}),jsxRuntime.jsxs("div",{style:d.stats,children:[jsxRuntime.jsxs("span",{style:{color:n.green},children:[U.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:n.red},children:[U.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:n.amber},children:[U.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:n.gripColor},children:[U.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:U.total})]}),g?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:n.gripColor,borderBottom:`1px solid ${n.borderSubtle}`,flexShrink:0},children:g.description}),yt(),xt(),jsxRuntime.jsx("div",{style:d.progress,children:jsxRuntime.jsx("div",{style:d.progressBar(pt)})})]}),Q==="max"&&jsxRuntime.jsxs("div",{style:{...d.card(J.w,ve),height:J.h,position:"relative"},children:[jsxRuntime.jsxs("div",{style:d.handle,onPointerDown:R,onPointerMove:k,onPointerUp:L,onClick:()=>{F.current||q("expanded");},children:[jsxRuntime.jsx(v,{d:f.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:d.title,children:g?.title}),jsxRuntime.jsx("div",{style:d.sub,children:g?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",g.branch_name]})})]}),jsxRuntime.jsx(v,{d:f.chevronDown,className:""}),jsxRuntime.jsx(mt,{icon:f.minus,onClick:()=>{N(false),$(true),q("mini");}})]}),jsxRuntime.jsxs("div",{style:d.stats,children:[jsxRuntime.jsxs("span",{style:{color:n.green},children:[U.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:n.red},children:[U.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:n.amber},children:[U.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:n.gripColor},children:[U.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:U.total})]}),g?.intro_notes&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${n.borderSubtle}`,fontSize:"10px",color:n.textMuted,fontStyle:"italic",flexShrink:0},children:g.intro_notes}),(g?.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(v,{d:f.search,size:11,className:""}),jsxRuntime.jsx("input",{value:X,onChange:t=>ye(t.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:n.text,fontFamily:"monospace"}}),X&&jsxRuntime.jsx("button",{onClick:()=>ye(""),style:{background:"none",border:"none",cursor:"pointer",color:n.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),pe==="error"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsxRuntime.jsx(v,{d:f.alert,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:n.red},children:"Failed to load"}),jsxRuntime.jsx("button",{onClick:zt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),ve&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg},children:[jsxRuntime.jsx(v,{d:f.checkAll,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",color:n.green,flex:1},children:"Run completed"}),jsxRuntime.jsx("button",{onClick:At,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),pe!=="error"&&jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(g?.test_cases||[]).length===0?jsxRuntime.jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:"No test cases"}):ze.length===0?jsxRuntime.jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:['No matches for "',X,'"']}):ut?ut.map(t=>{let u=_e.has(t.key);return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>xe(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(v,{d:u?f.chevronDown:f.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})]}),!u&&t.cases.map(w=>ft(w))]},t.key)}):ze.map(t=>ft(t))}),Ut&&!ve&&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:$t,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"})]}),yt(),xt(),jsxRuntime.jsx("div",{style:d.progress,children:jsxRuntime.jsx("div",{style:d.progressBar(pt)})}),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:Pt,onPointerMove:Et,onPointerUp:Lt,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{Me.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 we=8;function Ke(e,r,s,p,c,a){let T=Math.max(we,c-s-we),S=Math.max(we,a-p-we);return {x:Math.min(Math.max(e,we),T),y:Math.min(Math.max(r,we),S)}}function Ve(e,r){let[s,p]=useState({x:e,y:r}),c=useRef(false),a=useRef({x:0,y:0}),T=useRef(false),S=useCallback(y=>{c.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=>{c.current&&(T.current=true,p({x:y.clientX-a.current.x,y:y.clientY-a.current.y}));},[]),b=useCallback(()=>{c.current=false;},[]);return {pos:s,setPos:p,onPointerDown:S,onPointerMove:_,onPointerUp:b,didDrag:T}}function Ye(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 h=new URL(e.supabaseUrl),n=["localhost","127.0.0.1","::1"].includes(h.hostname);if(h.protocol==="http:"&&!n)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");h.protocol=h.protocol==="https:"?"wss:":"ws:",_=h.toString().replace(/\/$/,"");}catch{S();}let b=null,y=null,D=null,V=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 h={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(++V)};b.send(JSON.stringify(h));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(++V)};b.send(JSON.stringify(n)),y=setInterval(()=>{b?.readyState===WebSocket.OPEN&&b.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++V)}));},3e4);},b.onmessage=h=>{try{JSON.parse(h.data).event==="postgres_changes"&&p.current();}catch{}},b.onclose=()=>{x(),a||(D=setTimeout(M,3e3));},b.onerror=()=>{b?.close();};}},x=()=>{y&&(clearInterval(y),y=null);};return M(),()=>{a=true,x(),D&&clearTimeout(D),T&&clearInterval(T),b&&(b.onclose=null,b.onerror=null,b.close());}}let c=setInterval(()=>p.current(),15e3);return ()=>clearInterval(c)},[e.supabaseUrl,e.anonKey,r]);}var jt="botbuddy:created-test-run:";function Kt(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function Vt(e){return `${jt}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",Kt(e.targetUrl),e.branchName||""].join("|"))}`}function $e(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 Yt(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 qe(e){let[r,s]=useState(null),[p,c]=useState("loading"),a=Vt(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 Yt(e.testRunToken);if(!x&&!_){c("no-match"),s(null);return}if(x&&!e.ticketId){c("no-match"),s(null);return}let h=new URLSearchParams;x&&h.set("token",x),e.ticketId&&h.set("ticket_id",e.ticketId),h.set("app_slug",e.appSlug),e.environment&&h.set("environment",e.environment),_&&h.set("test_run_id",_),e.targetUrl&&h.set("target_url",e.targetUrl),e.version&&h.set("version",e.version),e.commitSha&&h.set("commit_sha",e.commitSha),e.prNumber&&h.set("pr_number",String(e.prNumber)),e.branchName&&h.set("branch_name",e.branchName);let n=await fetch(`${e.config.serverUrl}/widget/test-run?${h.toString()}`,{headers:$e(e.config,e.authToken)});if(n.status===404){c("no-match"),s(null);return}if(n.status===401||n.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),c("error");return}if(!n.ok){c("error");return}let d=await n.json();if(!d||d.run===null){c("no-match"),s(null);return}b(d),c(d.status==="completed"?"completed":"ready");}catch{c("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]),Ye(e.config,r?.id,y),{run:r,widgetState:p,fetchRun:y,setVerdict:async(x,h,n,d="human")=>(s(W=>{if(!W)return null;let Y=W.test_cases.map(I=>I.id===x?{...I,verdict:h,fail_reason:h==="fail"&&n||null,verdict_by_display_name:d,verdict_at:new Date().toISOString()}:I),N={total:Y.length,pending:0,pass:0,fail:0,skip:0};return Y.forEach(I=>{I.verdict in N&&N[I.verdict]++;}),{...W,test_cases:Y,summary:N}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${x}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...$e(e.config,e.authToken)},body:JSON.stringify({verdict:h,fail_reason:n,display_name:d})})).ok),markComplete:async()=>r?(s(h=>h?{...h,status:"completed"}:null),c("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${r.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...$e(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",...$e(e.config,e.authToken)}});return x.ok&&y(),x.ok},setRun:b}}var Ze="botbuddy-widget-auth-token",Qe="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),c=JSON.parse(p);return typeof c.exp=="number"?c.exp*1e3:null}catch{return null}}var qt=2500,Gt=6e4;function et(e){let[r,s]=useState(()=>{try{return localStorage.getItem(Ze)}catch(M){return console.warn("Unable to read BotBuddy widget auth token",M),null}}),[p,c]=useState(()=>{try{return localStorage.getItem(Qe)}catch(M){return console.warn("Unable to read BotBuddy widget display name",M),null}}),a=useRef(null),T=useCallback((M,x)=>{s(M),x&&c(x);try{localStorage.setItem(Ze,M),x&&localStorage.setItem(Qe,x);}catch(h){console.warn("Unable to persist BotBuddy widget auth token",h);}},[]);useEffect(()=>{let M=new URL(e).origin,x=h=>{h.origin===M&&h.data?.type==="botbuddy-widget-auth"&&h.data.token&&T(h.data.token,h.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 h=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 H=false,W=()=>{window.removeEventListener("message",Y),clearTimeout(N);try{d.remove();}catch{}a.current=null;},Y=I=>{if(I.origin===M){if(I.data?.type==="botbuddy-widget-auth-failed"){if(H)return;H=true,n(null),W();return}I.data?.type!=="botbuddy-widget-auth"||!I.data.token||H||(H=true,n(String(I.data.token)),W());}},N=setTimeout(()=>{H||(H=true,n(null),W());},qt);window.addEventListener("message",Y),document.body.appendChild(d);});return a.current=h,h},[e]);useEffect(()=>{if(!r)return;let M=Re(r);if(!M)return;let x=M-Date.now()-Gt,h=window.setTimeout(()=>{S();},Math.max(0,x));return ()=>window.clearTimeout(h)},[r,S]);let _=useCallback(()=>{let M=new URL("/widget-auth",e);M.searchParams.set("origin",window.location.origin);let x=420,h=520,n=window.screenX+(window.innerWidth-x)/2,d=window.screenY+(window.innerHeight-h)/2;window.open(M.toString(),"botbuddy-auth",`width=${x},height=${h},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 h=window.setTimeout(()=>b(n=>n+1),x);return ()=>window.clearTimeout(h)},[r]);let y=useCallback(()=>{s(null),c(null);try{localStorage.removeItem(Ze),localStorage.removeItem(Qe);}catch(M){console.warn("Unable to clear BotBuddy widget auth token",M);}},[]),D=Re(r),V=D!==null&&D<=Date.now();return {token:r,displayName:p,isAuthenticated:!!r,isExpired:V,openLogin:_,refreshNow:S,logout:y}}var We=null;function Xt(){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(Xt(),{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,c]of Object.entries(r))typeof c=="string"&&c.length>0&&(s[p]=c);return s}catch{return null}})(),We)}async function wt(e){return (await Ie())?.[e]??null}function Zt(e){let r=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),s="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",p=[],c=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,c+=5,c>=8&&(c-=8,p.push(a>>>c&255));}return Uint8Array.from(p)}async function St(e,r=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let s=Zt(e),p=new Uint8Array(s.byteLength);p.set(s);let c=Math.floor(r/1e3/30),a=new Uint8Array(8),T=Math.floor(c/4294967296),S=c>>>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),D=y[y.length-1]&15;return (((y[D]&127)<<24|(y[D+1]&255)<<16|(y[D+2]&255)<<8|y[D+3]&255)%1e6).toString().padStart(6,"0")}var kt="0.10.13";function en(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 c=r.getDate(),a=r.toLocaleString("en",{month:"short"}),T=r.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${a} ${c}, ${T}`}var v=({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})}),f={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 tn(){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,c=p();c&&r(c);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 nn(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 rn={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},on={pending:f.circle,pass:f.check,fail:f.x,skip:f.skip},_t={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)"}},sn=["app.supply-guard.io"];function an(e,r=[]){if(!e)return false;let s=e.toLowerCase();return [...sn,...r].map(c=>c.toLowerCase()).includes(s)}var ln=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=_t[r]||_t.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 Mt(e){return e.split("/")[0].trim()}async function dn(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:c,tk:a,compact:T=false,onExpand:S,onAuthExpired:_,refreshAuth:b,requestLogin:y,testRunId:D,testRunToken:V,ticketId:M,targetUrl:x,version:h,commitSha:n,prNumber:d,branchName:H}){let[W,Y]=useState(false),[N,I]=useState(null),[$,ke]=useState(null),[ie,m]=useState(null),[Ee,se]=useState(null),[Q,q]=useState(null),[G,ae]=useState(null);useEffect(()=>{s==="local"&&Ie();},[s]);let fe=useCallback(l=>{I(l),m(null),se(null),ae(null);let E=Re(c);if(s!=="local"&&y&&E!==null&&E<=Date.now()){q({slug:l,token:c||null}),ae(l),I(null),y();return}let R=C=>{m(C),se(l),window.setTimeout(()=>{se(P=>P===l?null:P),m(P=>P===C?null:P);},3e3);},k=new URLSearchParams({app_slug:r,seed_user_slug:l,environment:s});D&&k.set("test_run_id",D),V&&k.set("public_token",V),M&&k.set("ticket_id",M),x&&k.set("target_url",x),h&&k.set("version",h),n&&k.set("commit_sha",n),d&&k.set("pr_number",String(d)),H&&k.set("branch_name",H);let L=async C=>{let P={apikey:e.anonKey,Authorization:`Bearer ${C}`};try{let B=await fetch(`${e.serverUrl}/widget/totp-code?${k}`,{headers:P});if(!B.ok){let ue=await B.json().catch(()=>({error:`HTTP ${B.status}`}));return {ok:!1,status:B.status,error:ue.error||`HTTP ${B.status}`}}let J=await B.json();return {ok:!0,code:String(J.code)}}catch{return {ok:false,status:0,error:"Network error"}}},F=(async()=>{if(s==="local"){let B=await wt(l);if(B)try{return {ok:!0,code:await St(B)}}catch{}}let C=await L(c||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=F.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 F;if(!C.ok){C.status===401?(q({slug:l,token:c||null}),ae(l)):R(C.status===404?"No 2FA seed registered":C.error),I(null);return}let P=A?await A:false,B=P?true:await dn(C.code),J=P||B;ke({slug:l,code:C.code,copied:J}),window.setTimeout(()=>ke(ue=>ue?.slug===l?null:ue),J?2500:6e3),Y(false),I(null);})();},[e.serverUrl,e.anonKey,c,r,s,D,V,M,x,h,n,d,H,b,y]),re=useCallback(l=>{q({slug:l,token:c||null}),y?.();},[c,y]),he=useCallback(l=>{G===l?re(l):fe(l);},[G,re,fe]);useEffect(()=>{if(!Q||!c||c===Q.token)return;let l=Q.slug;q(null),fe(l);},[c,fe,Q]);let me=useRef(null),_e=useRef(null);if(useLayoutEffect(()=>{if(!W)return;let l=me.current,E=_e.current;if(!l||!E||typeof window>"u")return;let R=()=>{let k=l.getBoundingClientRect(),L=E.getBoundingClientRect(),F=window.innerWidth,A=window.innerHeight,C=k.left,P=k.top-L.height-6;P<8&&(P=k.bottom+6);let B=Math.max(8,F-L.width-8),J=Math.max(8,A-L.height-8);C=Math.min(Math.max(C,8),B),P=Math.min(Math.max(P,8),J),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);}},[W,p.length,ie]),useEffect(()=>{if(!W)return;let l=E=>{let R=E.target;_e.current?.contains(R)||me.current?.contains(R)||Y(false);};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[W]),p.length===0)return null;if(T){let l=p.length>1,E=p[0],R=!l&&G===E,k=B=>{if(B.stopPropagation(),l&&S){S();return}he(E);},L=!!Ee,F=!!$,A=F&&$.copied,C=F&&!$.copied,P=R?a.blue:L?a.red:A?a.green:C?a.amber:a.purple;return jsxs("span",{onPointerDown:B=>B.stopPropagation(),onPointerUp:B=>B.stopPropagation(),onPointerMove:B=>B.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(v,{d:R?f.key:L?f.alert:A?f.check:C?f.copy:f.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=N===l,R=$?.slug===l,k=R&&$.copied,L=R&&!$.copied,F=Ee===l,A=G===l,C=A?a.blue:F?a.red:k?a.green:L?a.amber:a.purple;return jsxs("button",{onClick:P=>{P.stopPropagation(),he(l);},disabled:E,style:{...Ct(C),cursor:E?"wait":"pointer",opacity:E?.6:1},title:A?"Sign in to BotBuddy to refresh 2FA":F?ie||"Failed":L?`Clipboard blocked \u2014 code: ${$.code}`:`Copy 2FA code for ${l}`,children:[jsx(v,{d:A?f.key:F?f.alert:k?f.check:L?f.copy:f.shield,size:12}),A?"Sign in":k?"Copied":L?$.code:F?"Failed":E?"\u2026":`2FA \xB7 ${l}`]})}let le=!!G&&!W,X=!!Ee&&!W,ye=!!$&&$.copied,xe=!!$&&!$.copied,Ue=le?a.blue:X?a.red:ye?a.green:xe?a.amber:a.purple,De=W&&typeof document<"u"?createPortal(jsxs("div",{ref:_e,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=N===l,R=G===l;return jsxs("button",{onClick:k=>{k.stopPropagation(),he(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(v,{d:R?f.key:f.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:me,onClick:l=>{if(l.stopPropagation(),le&&G){re(G);return}Y(E=>!E),m(null),se(null);},style:{...Ct(Ue),cursor:"pointer"},title:le?"Sign in to BotBuddy to refresh 2FA":X?ie||"Failed":xe?`Clipboard blocked \u2014 code: ${$.code}`:"Choose a persona to copy a 2FA code for",children:[jsx(v,{d:le?f.key:X?f.alert:ye?f.check:xe?f.copy:f.shield,size:12}),le?"Sign in":ye?"Copied":xe?$.code:X?"Failed":`2FA \xB7 ${p.length}`,!le&&jsx(v,{d:W?f.chevronUp:f.chevronDown,size:8})]}),De]})}function Ct(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 Tt="botbuddy-widget-state";function cn({config:e,appSlug:r,environment:s,ticketId:p,testRunId:c,testRunToken:a,targetUrl:T,version:S,commitSha:_,prNumber:b,branchName:y,onNavigate:D,displayName:V="human",defaultMode:M="mini",defaultPosition:x}){let h=tn(),n=useMemo(()=>nn(h),[h]),d=useMemo(()=>ln(n),[n]),[H,W]=useState(false),[Y,N]=useState(false),[I,$]=useState(false),ke=useRef(false),ie=e.dashboardUrl||"https://app.bot-buddy.ai",m=et(ie),se=(()=>{try{let t=typeof window<"u"?localStorage.getItem(Tt):null;if(t)return JSON.parse(t)}catch{}return null})(),[Q,q]=useState(se?.mode||M),[G,ae]=useState(""),[fe,re]=useState(null),[he,me]=useState(null),[_e,le]=useState(new Set),[X,ye]=useState(""),xe=useCallback(t=>{le(u=>{let w=new Set(u);return w.has(t)?w.delete(t):w.add(t),w});},[]),Ue=se?.x??x?.x??16,De=se?.y??x?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:l,setPos:E,onPointerDown:R,onPointerMove:k,onPointerUp:L,didDrag:F}=Ve(Ue,De),A=useRef(null);useEffect(()=>{try{localStorage.setItem(Tt,JSON.stringify({mode:Q,x:l.x,y:l.y}));}catch{}},[Q,l.x,l.y]),useLayoutEffect(()=>{if(typeof window>"u")return;let t=A.current;if(!t)return;let u=t.getBoundingClientRect(),w=Ke(l.x,l.y,u.width,u.height,window.innerWidth,window.innerHeight);(w.x!==l.x||w.y!==l.y)&&E(w);}),useEffect(()=>{if(typeof window>"u")return;let t=()=>{let u=A.current;if(!u)return;let w=u.getBoundingClientRect(),K=Ke(l.x,l.y,w.width,w.height,window.innerWidth,window.innerHeight);(K.x!==l.x||K.y!==l.y)&&E(K);};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[l.x,l.y,E]);let C=useRef(m.isAuthenticated);useEffect(()=>{!C.current&&m.isAuthenticated&&q("max"),C.current=m.isAuthenticated;},[m.isAuthenticated]);let P="botbuddy-widget-max-size",B=()=>{try{let t=localStorage.getItem(P);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[J,ue]=useState(B),Me=useRef(false),Ce=useRef({x:0,y:0,w:0,h:0}),Pt=useCallback(t=>{t.stopPropagation(),Me.current=true,Ce.current={x:t.clientX,y:t.clientY,w:J.w,h:J.h},t.target.setPointerCapture(t.pointerId);},[J]),Et=useCallback(t=>{if(!Me.current)return;let u=Math.max(280,Math.min(600,Ce.current.w+(t.clientX-Ce.current.x))),w=Math.max(300,Math.min(window.innerHeight*.9,Ce.current.h+(t.clientY-Ce.current.y)));ue({w:u,h:w});},[]),Lt=useCallback(()=>{Me.current&&(Me.current=false,ue(t=>(localStorage.setItem(P,JSON.stringify(t)),t)));},[]),Z=T??(typeof window<"u"?window.location.href:void 0),tt=m.displayName||V,[oe,nt]=useState(null);useEffect(()=>{if(m.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),c&&t.set("test_run_id",c),Z&&t.set("target_url",Z),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(u=>u.json()).then(u=>nt(u)).catch(()=>nt(null));},[m.isAuthenticated,e.serverUrl,e.anonKey,r,s,p,c,a,Z,S,_,b,y]);let rt=useRef(false),Bt=useCallback(()=>{rt.current||m.logout();},[m.logout]),{run:g,widgetState:pe,fetchRun:zt,setVerdict:ot,markComplete:$t,resetRun:At,setRun:it}=qe({config:e,appSlug:r,environment:s,ticketId:p,testRunId:c,testRunToken:a,targetUrl:Z,version:S,commitSha:_,prNumber:b?String(b):void 0,branchName:y,authToken:m.token,onAuthExpired:Bt});rt.current=!!g;let[st,at]=useState([]),[Fe,lt]=useState(false),[dt,ct]=useState(null),[Wt,Le]=useState(false),be=an(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);useEffect(()=>{if((s??"local")!=="local"||be){at([]);return}let t=true;return Ie().then(u=>{t&&at(Object.keys(u||{}));}),()=>{t=false;}},[s,be]);let It=useCallback(async()=>{if(!(!m.isAuthenticated||!m.token)){lt(true),ct(null);try{let t=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${m.token}`},body:JSON.stringify({app_slug:r,environment:s||"local",target_url:Z,branch_name:y,commit_sha:_,pr_number:b,ticket_id:p,title:`${p||r} local validation`})}),u=await t.json().catch(()=>({}));if(!t.ok)throw new Error(u.error||`HTTP ${t.status}`);it(u),q("max");}catch(t){ct(t.message);}finally{lt(false);}}},[m.isAuthenticated,m.token,e.serverUrl,e.anonKey,r,s,Z,y,_,b,p,it]),Be=useCallback(async(t,u,w)=>{me(t);try{await ot(t,u,w,tt);}finally{me(null),re(null),ae("");}},[ot,tt]),U=g?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},Ut=U.total>0&&U.pending===0,ve=pe==="completed",ze=useMemo(()=>{let t=g?.test_cases||[];if(!X.trim())return t;let u=X.toLowerCase();return t.filter(w=>w.title.toLowerCase().includes(u)||w.description&&w.description.toLowerCase().includes(u)||w.url_path&&w.url_path.toLowerCase().includes(u)||w.seed_user&&w.seed_user.toLowerCase().includes(u))},[g?.test_cases,X]),ut=useMemo(()=>{let t=ze,u=g?.test_cases||[];if(new Set(u.map(O=>O.source_pr_number)).size<=1)return null;let K=[],Te=new Map;t.forEach(O=>{let ee=O.source_pr_number;Te.has(ee)||Te.set(ee,[]),Te.get(ee).push(O);});let Dt=[...Te.keys()].sort((O,ee)=>O===null?1:ee===null?-1:ee-O);for(let O of Dt){let ee=Te.get(O),Oe={total:ee.length,pass:0,fail:0,skip:0,pending:0};ee.forEach(bt=>{bt.verdict in Oe&&Oe[bt.verdict]++;}),K.push({key:O!=null?`pr-${O}`:"general",label:O!=null?`PR #${O}`:"General",cases:ee,summary:Oe});}return K.filter(O=>O.cases.length>0)},[ze,g?.test_cases]),pt=U.total>0?(U.pass+U.fail)/U.total*100:0,j=s??g?.environment??null,de=useMemo(()=>{if(!j||j==="production"||be)return [];let t=g?.test_cases||[],u=new Set;for(let w of t)w.seed_user&&u.add(Mt(w.seed_user));if(j==="local")for(let w of st)u.add(Mt(w));return [...u]},[g?.test_cases,j,st,be]),Ne=useMemo(()=>{let t=g?.auto_tooltip_seconds??oe?.auto_tooltip_seconds;return t!=null&&t>0?t*1e3:0},[g,oe]),gt=pe==="ready"||pe==="completed"||oe?.enabled&&oe.run;useEffect(()=>{if(!gt||ke.current||Ne<=0)return;ke.current=true,N(true);let t=window.setTimeout(()=>N(false),Ne);return ()=>window.clearTimeout(t)},[gt,Ne]);let ft=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:rn[t.verdict]},children:he===t.id?jsx(v,{d:f.loader,className:""}):jsx(v,{d:on[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(v,{d:f.key,size:10}),jsx("span",{children:t.seed_user})]}),t.url_path&&jsxs("a",{href:t.url_path,target:"_blank",rel:"noopener noreferrer",onClick:u=>{u.stopPropagation(),D&&(u.preventDefault(),D(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(v,{d:f.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(u=>jsx("button",{onClick:()=>{if(t.verdict===u){Be(t.id,"pending"),re(null);return}if(u==="fail"){re(t.id),ae("");return}re(null),Be(t.id,u);},disabled:he!==null,style:d.verdictBtn(t.verdict===u,u==="pass"?n.green:u==="fail"?n.red:n.amber),children:u.toUpperCase()},u)),t.created_by_agent_name&&jsxs("span",{style:{fontSize:"8px",color:n.purple,marginLeft:"4px",display:"inline-flex",alignItems:"center",gap:"2px"},children:[jsx(v,{d:f.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:en(t.verdict_at)})]})]}),fe===t.id&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:G,onChange:u=>ae(u.target.value),onKeyDown:u=>{u.key==="Enter"&&Be(t.id,"fail",G.trim()||void 0),u.key==="Escape"&&(re(null),ae(""));},placeholder:"Reason (optional)...",style:d.input}),jsx("button",{onClick:()=>{Be(t.id,"fail",G.trim()||void 0);},style:d.verdictBtn(true,n.red),children:"\u2713"})]})]},t.id);if((pe==="no-match"||pe==="loading")&&!(!m.isAuthenticated&&oe?.enabled&&oe.run)){if(!(j==="local"&&!be))return null}if(!m.isAuthenticated&&oe?.enabled&&oe.run){let t=oe.run,u=t.summary,w=t.status==="completed";return jsx("div",{ref:A,style:{...d.root,left:l.x,top:l.y},children:jsxs("div",{style:{position:"relative"},onMouseEnter:()=>W(true),onMouseLeave:()=>{W(false),$(false),N(false);},children:[jsxs("div",{style:{...d.pill(w),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:R,onPointerMove:k,onPointerUp:()=>{L();},children:[jsx(v,{d:f.grip,size:10,className:""}),t.ticket_id&&t.ticket_url?jsx("a",{href:t.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:K=>K.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:K=>K.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:K=>K.stopPropagation(),style:{color:n.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(v,{d:f.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(v,{d:f.bot,size:10}),t.created_by_agent_name]}):null,jsxs("span",{style:w?{color:n.green}:void 0,children:[u.pass,"/",u.total]}),u.fail>0&&jsxs("span",{style:{color:n.red},children:[u.fail,"\u2717"]}),jsx("span",{onClick:K=>{K.stopPropagation(),m.openLogin();},style:{color:n.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!I&&(H||Y)&&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(!m.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(v,{d:f.grip,size:10,className:""}),jsx(v,{d:f.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"}),j==="local"&&de.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx(Pe,{config:e,appSlug:r,environment:j,seededUsers:de,authToken:m.token,refreshAuth:m.refreshNow,requestLogin:m.openLogin,tk:n,testRunId:g?.id||c,testRunToken:a,ticketId:p,targetUrl:Z,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:m.logout})}),jsx("button",{onClick:t=>{t.stopPropagation(),m.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(!g&&j==="local"&&!be)return Wt?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:()=>{F.current||Le(false);},children:[jsx(v,{d:f.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(v,{d:f.chevronUp,className:""}),jsx("button",{style:d.btn,onClick:t=>{t.stopPropagation(),Le(false);},children:jsx(v,{d:f.minus,className:""})})]}),jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[de.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx(Pe,{config:e,appSlug:r,environment:j,seededUsers:de,authToken:m.token,refreshAuth:m.refreshNow,requestLogin:m.openLogin,tk:n,testRunId:c,testRunToken:a,ticketId:p,targetUrl:Z,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:m.logout})}),jsx("button",{onClick:t=>{t.stopPropagation(),It();},disabled:Fe,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${n.green}`,background:`${n.green}22`,color:n.green,cursor:Fe?"wait":"pointer",width:"100%"},children:Fe?"Creating...":"Create test run for this branch"}),dt&&jsx("div",{style:{fontSize:"9px",color:n.red,marginTop:"8px"},children:dt})]})]})}):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(),F.current||Le(true);},children:[jsx(v,{d:f.grip,size:9,className:""}),jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),de.length>0&&jsx(Pe,{config:e,appSlug:r,environment:j,seededUsers:de,authToken:m.token,refreshAuth:m.refreshNow,requestLogin:m.openLogin,tk:n,compact:true,onExpand:()=>Le(true),testRunId:c,testRunToken:a,ticketId:p,targetUrl:Z,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:m.logout})]})});let ht=()=>{F.current||(N(false),q(t=>{let u=t==="mini"?"max":"mini";return $(u==="mini"),u}));},mt=({icon:t,onClick:u})=>jsx("button",{style:d.btn,onClick:w=>{w.stopPropagation(),u(w);},children:jsx(v,{d:t,className:""})}),yt=()=>jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${n.borderSubtle}`,flexShrink:0},children:[g?.pr_url&&jsxs("a",{href:g.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.blue),textDecoration:"none"},children:[jsx(v,{d:f.pr,size:12}),g.pr_number?`PR#${g.pr_number}`:g.pr_id||"PR",jsx(v,{d:f.externalLink,size:8})]}),g?.ticket_url&&jsxs("a",{href:g.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.amber),textDecoration:"none"},children:[jsx(v,{d:f.ticket,size:12}),g.ticket_id||"Ticket",jsx(v,{d:f.externalLink,size:8})]}),g?.created_by_agent_name&&(g.codex_thread_id?jsxs("a",{href:`codex://threads/${g.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.purple),textDecoration:"none"},children:[jsx(v,{d:f.bot,size:12}),g.created_by_agent_name,jsx(v,{d:f.externalLink,size:8})]}):jsxs("span",{style:{...d.link(n.purple)},children:[jsx(v,{d:f.bot,size:12}),g.created_by_agent_name]})),j&&jsx(Pe,{config:e,appSlug:r,environment:j,seededUsers:de,authToken:m.token,refreshAuth:m.refreshNow,requestLogin:m.openLogin,tk:n,testRunId:g?.id||c,testRunToken:a,ticketId:p,targetUrl:Z,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:m.logout}),jsx("span",{style:{...d.badge(g?.environment||"custom"),marginLeft:"auto"},children:g?.environment})]}),xt=()=>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(kt);},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",kt]})]}),m.isAuthenticated&&(m.isExpired?jsx("button",{onClick:t=>{t.stopPropagation(),m.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(),m.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:[Q==="mini"&&jsxs("div",{style:{position:"relative"},onMouseEnter:()=>W(true),onMouseLeave:()=>{W(false),$(false),N(false);},children:[jsxs("div",{style:{...d.pill(ve),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:R,onPointerMove:k,onPointerUp:()=>{L(),F.current||ht();},children:[jsx(v,{d:f.grip,size:9,className:""}),g?.ticket_id&&jsx("span",{style:{color:n.amber,fontWeight:600},children:g.ticket_id}),g?.pr_number&&jsxs("span",{style:{color:n.blue,fontWeight:600},children:["PR#",g.pr_number]}),jsxs("span",{style:ve?{color:n.green}:void 0,children:[U.pass,"/",U.total]}),U.fail>0&&jsxs("span",{style:{color:n.red},children:[U.fail,"\u2717"]}),j&&jsx(Pe,{config:e,appSlug:r,environment:j,seededUsers:de,authToken:m.token,refreshAuth:m.refreshNow,requestLogin:m.openLogin,tk:n,compact:true,onExpand:()=>q("expanded"),testRunId:g?.id||c,testRunToken:a,ticketId:p,targetUrl:Z,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:m.logout})]}),!I&&(H||Y)&&g?.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:g.title}),(g.description||g.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:g.description||g.intro_notes})]})]}),Q==="expanded"&&jsxs("div",{style:d.card(300,ve),children:[jsxs("div",{style:d.handle,onPointerDown:R,onPointerMove:k,onPointerUp:L,onClick:ht,children:[jsx(v,{d:f.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:d.title,children:g?.title}),jsx("div",{style:d.sub,children:g?.branch_name&&jsxs("span",{children:["\u2387 ",g.branch_name]})})]}),jsx(v,{d:f.chevronUp,className:""}),jsx(mt,{icon:f.minus,onClick:()=>{N(false),$(true),q("mini");}})]}),jsxs("div",{style:d.stats,children:[jsxs("span",{style:{color:n.green},children:[U.pass,"\u2713"]}),jsxs("span",{style:{color:n.red},children:[U.fail,"\u2717"]}),jsxs("span",{style:{color:n.amber},children:[U.skip,"\u23ED"]}),jsxs("span",{style:{color:n.gripColor},children:[U.pending,"\u25CC"]}),jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:U.total})]}),g?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:n.gripColor,borderBottom:`1px solid ${n.borderSubtle}`,flexShrink:0},children:g.description}),yt(),xt(),jsx("div",{style:d.progress,children:jsx("div",{style:d.progressBar(pt)})})]}),Q==="max"&&jsxs("div",{style:{...d.card(J.w,ve),height:J.h,position:"relative"},children:[jsxs("div",{style:d.handle,onPointerDown:R,onPointerMove:k,onPointerUp:L,onClick:()=>{F.current||q("expanded");},children:[jsx(v,{d:f.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:d.title,children:g?.title}),jsx("div",{style:d.sub,children:g?.branch_name&&jsxs("span",{children:["\u2387 ",g.branch_name]})})]}),jsx(v,{d:f.chevronDown,className:""}),jsx(mt,{icon:f.minus,onClick:()=>{N(false),$(true),q("mini");}})]}),jsxs("div",{style:d.stats,children:[jsxs("span",{style:{color:n.green},children:[U.pass,"\u2713"]}),jsxs("span",{style:{color:n.red},children:[U.fail,"\u2717"]}),jsxs("span",{style:{color:n.amber},children:[U.skip,"\u23ED"]}),jsxs("span",{style:{color:n.gripColor},children:[U.pending,"\u25CC"]}),jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:U.total})]}),g?.intro_notes&&jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${n.borderSubtle}`,fontSize:"10px",color:n.textMuted,fontStyle:"italic",flexShrink:0},children:g.intro_notes}),(g?.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(v,{d:f.search,size:11,className:""}),jsx("input",{value:X,onChange:t=>ye(t.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:n.text,fontFamily:"monospace"}}),X&&jsx("button",{onClick:()=>ye(""),style:{background:"none",border:"none",cursor:"pointer",color:n.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),pe==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(v,{d:f.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:n.red},children:"Failed to load"}),jsx("button",{onClick:zt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),ve&&jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg},children:[jsx(v,{d:f.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:n.green,flex:1},children:"Run completed"}),jsx("button",{onClick:At,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),pe!=="error"&&jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(g?.test_cases||[]).length===0?jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:"No test cases"}):ze.length===0?jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:['No matches for "',X,'"']}):ut?ut.map(t=>{let u=_e.has(t.key);return jsxs("div",{children:[jsxs("button",{onClick:()=>xe(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(v,{d:u?f.chevronDown:f.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})]}),!u&&t.cases.map(w=>ft(w))]},t.key)}):ze.map(t=>ft(t))}),Ut&&!ve&&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:$t,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"})]}),yt(),xt(),jsx("div",{style:d.progress,children:jsx("div",{style:d.progressBar(pt)})}),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:Pt,onPointerMove:Et,onPointerUp:Lt,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{Me.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