@botbuddy/react 0.10.11 → 0.10.13

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 CHANGED
@@ -1,5 +1,42 @@
1
1
  # @botbuddy/react — Changelog
2
2
 
3
+ ## 0.10.13
4
+
5
+ ### Fixed
6
+
7
+ - **2FA chip self-recovers in one click when the widget session has expired
8
+ (BOT-906).** The widget bearer is a ~1h Supabase access token with no refresh
9
+ token. When it expires, the previous "silent iframe refresh + deferred popup"
10
+ recovery could not work in a cross-site embed: browser third-party storage
11
+ partitioning gives the hidden `/widget-auth` iframe an empty, partitioned
12
+ `localStorage`, so it never sees the first-party BotBuddy session, and the
13
+ fallback `window.open` fired seconds after the click — outside transient user
14
+ activation — so the browser blocked it. The net effect was the long-standing
15
+ "I have to sign out and back in before 2FA works" symptom.
16
+
17
+ Now:
18
+ - **Pre-flight expiry check** — clicking the 2FA chip with an already-expired
19
+ token opens the first-party sign-in popup **synchronously inside the click
20
+ gesture** (so it isn't popup-blocked) and auto-retries the same persona once
21
+ a fresh token arrives.
22
+ - **Surprise 401** (token valid by the clock but rejected server-side, and
23
+ silent refresh can't recover) now surfaces a clickable **"Sign in"** retry
24
+ affordance instead of a popup that would be blocked; the user's click is a
25
+ fresh gesture that can open the popup.
26
+ - **Silent refresh fails fast** — `/widget-auth?silent=1` now posts an explicit
27
+ failure message, and the fallback timeout dropped from 8s to 2.5s, so a dead
28
+ cross-site refresh no longer stalls before the popup path.
29
+ - **Honest footer** — when the widget token is expired the footer offers
30
+ **"sign in"** (re-mint via popup) instead of only "sign out".
31
+
32
+ ## 0.10.12
33
+
34
+ ### Fixed
35
+
36
+ - **Widget footer version now matches the package release.** The visible
37
+ `BotBuddy v...` footer no longer reports the previous package version after
38
+ a patch release.
39
+
3
40
  ## 0.10.11
4
41
 
5
42
  ### Fixed
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var react=require('react'),reactDom=require('react-dom'),jsxRuntime=require('react/jsx-runtime');var he=8;function Fe(e,n,s,c,u,a){let R=Math.max(he,u-s-he),_=Math.max(he,a-c-he);return {x:Math.min(Math.max(e,he),R),y:Math.min(Math.max(n,he),_)}}function Ne(e,n){let[s,c]=react.useState({x:e,y:n}),u=react.useRef(false),a=react.useRef({x:0,y:0}),R=react.useRef(false),_=react.useCallback(l=>{u.current=true,R.current=false,a.current={x:l.clientX-s.x,y:l.clientY-s.y},l.target.setPointerCapture(l.pointerId);},[s]),C=react.useCallback(l=>{u.current&&(R.current=true,c({x:l.clientX-a.current.x,y:l.clientY-a.current.y}));},[]),y=react.useCallback(()=>{u.current=false;},[]);return {pos:s,setPos:c,onPointerDown:_,onPointerMove:C,onPointerUp:y,didDrag:R}}function Oe(e,n,s){let c=react.useRef(s);c.current=s,react.useEffect(()=>{if(!n)return;if(e.supabaseUrl){let a=false,R=null,_=()=>{a||R||(R=setInterval(()=>c.current(),15e3));},C=null;try{let v=new URL(e.supabaseUrl),r=["localhost","127.0.0.1","::1"].includes(v.hostname);if(v.protocol==="http:"&&!r)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");v.protocol=v.protocol==="https:"?"wss:":"ws:",C=v.toString().replace(/\/$/,"");}catch{_();}let y=null,l=null,T=null,E=0,U=()=>{if(!(a||!C)){try{y=new WebSocket(`${C}/realtime/v1/websocket?apikey=${e.anonKey}&vsn=1.0.0`);}catch{_();return}y.onopen=()=>{if(a||!y)return;let v={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(++E)};y.send(JSON.stringify(v));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(++E)};y.send(JSON.stringify(r)),l=setInterval(()=>{y?.readyState===WebSocket.OPEN&&y.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++E)}));},3e4);},y.onmessage=v=>{try{JSON.parse(v.data).event==="postgres_changes"&&c.current();}catch{}},y.onclose=()=>{x(),a||(T=setTimeout(U,3e3));},y.onerror=()=>{y?.close();};}},x=()=>{l&&(clearInterval(l),l=null);};return U(),()=>{a=true,x(),T&&clearTimeout(T),R&&clearInterval(R),y&&(y.onclose=null,y.onerror=null,y.close());}}let u=setInterval(()=>c.current(),15e3);return ()=>clearInterval(u)},[e.supabaseUrl,e.anonKey,n]);}var Ft="botbuddy:created-test-run:";function Nt(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function Ot(e){return `${Ft}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",Nt(e.targetUrl),e.branchName||""].join("|"))}`}function Pe(e,n){let s={apikey:e.anonKey};return n?s.Authorization=`Bearer ${n}`:e.apiKey?s.Authorization=`Bearer ${e.apiKey}`:s.Authorization=`Bearer ${e.anonKey}`,s}async function Ht(e){if(e)return e;try{let n=await fetch("/.botbuddy-token",{cache:"no-store"});if(n.ok){let s=(await n.text()).trim();if(s.startsWith("public_"))return s}}catch{}try{let n=undefined?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(n&&typeof n=="string"&&n.startsWith("public_"))return n}catch{}return null}function Ke(e){let[n,s]=react.useState(null),[c,u]=react.useState("loading"),a=Ot(e),[R,_]=react.useState(()=>{if(e.testRunId)return e.testRunId;try{return localStorage.getItem(a)||void 0}catch{return}}),C=e.testRunId||R,y=react.useCallback(x=>{if(s(x),!!x?.id){_(x.id);try{localStorage.setItem(a,x.id);}catch{}}},[a]),l=react.useCallback(async()=>{try{let x=await Ht(e.testRunToken);if(!x&&!C){u("no-match"),s(null);return}if(x&&!e.ticketId){u("no-match"),s(null);return}let v=new URLSearchParams;x&&v.set("token",x),e.ticketId&&v.set("ticket_id",e.ticketId),v.set("app_slug",e.appSlug),e.environment&&v.set("environment",e.environment),C&&v.set("test_run_id",C),e.targetUrl&&v.set("target_url",e.targetUrl),e.version&&v.set("version",e.version),e.commitSha&&v.set("commit_sha",e.commitSha),e.prNumber&&v.set("pr_number",String(e.prNumber)),e.branchName&&v.set("branch_name",e.branchName);let r=await fetch(`${e.config.serverUrl}/widget/test-run?${v.toString()}`,{headers:Pe(e.config,e.authToken)});if(r.status===404){u("no-match"),s(null);return}if(r.status===401||r.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),u("error");return}if(!r.ok){u("error");return}let p=await r.json();if(!p||p.run===null){u("no-match"),s(null);return}y(p),u(p.status==="completed"?"completed":"ready");}catch{u("error");}},[e.config.serverUrl,e.config.anonKey,e.config.apiKey,e.authToken,e.appSlug,e.environment,e.ticketId,C,e.testRunToken,e.targetUrl,e.version,e.commitSha,e.branchName,e.prNumber,e.onAuthExpired,y]);return react.useEffect(()=>{l();},[l]),Oe(e.config,n?.id,l),{run:n,widgetState:c,fetchRun:l,setVerdict:async(x,v,r,p="human")=>(s(A=>{if(!A)return null;let q=A.test_cases.map(j=>j.id===x?{...j,verdict:v,fail_reason:v==="fail"&&r||null,verdict_by_display_name:p,verdict_at:new Date().toISOString()}:j),O={total:q.length,pending:0,pass:0,fail:0,skip:0};return q.forEach(j=>{j.verdict in O&&O[j.verdict]++;}),{...A,test_cases:q,summary:O}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${x}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...Pe(e.config,e.authToken)},body:JSON.stringify({verdict:v,fail_reason:r,display_name:p})})).ok),markComplete:async()=>n?(s(v=>v?{...v,status:"completed"}:null),u("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${n.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...Pe(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!n)return false;let x=await fetch(`${e.config.serverUrl}/widget/test-runs/${n.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...Pe(e.config,e.authToken)}});return x.ok&&l(),x.ok},setRun:y}}var je="botbuddy-widget-auth-token",Ve="botbuddy-widget-auth-name";function jt(e){if(!e)return null;try{let n=e.split(".")[1];if(!n)return null;let s=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(n.length/4)*4,"="),c=atob(s),u=JSON.parse(c);return typeof u.exp=="number"?u.exp*1e3:null}catch{return null}}var Vt=8e3,Yt=6e4;function Ye(e){let[n,s]=react.useState(()=>{try{return localStorage.getItem(je)}catch(l){return console.warn("Unable to read BotBuddy widget auth token",l),null}}),[c,u]=react.useState(()=>{try{return localStorage.getItem(Ve)}catch(l){return console.warn("Unable to read BotBuddy widget display name",l),null}}),a=react.useRef(null),R=react.useCallback((l,T)=>{s(l),T&&u(T);try{localStorage.setItem(je,l),T&&localStorage.setItem(Ve,T);}catch(E){console.warn("Unable to persist BotBuddy widget auth token",E);}},[]);react.useEffect(()=>{let l=new URL(e).origin,T=E=>{E.origin===l&&E.data?.type==="botbuddy-widget-auth"&&E.data.token&&R(E.data.token,E.data.displayName||"human");};return window.addEventListener("message",T),()=>window.removeEventListener("message",T)},[e,R]);let _=react.useCallback(()=>{if(a.current)return a.current;if(typeof window>"u"||typeof document>"u")return Promise.resolve(null);let l=new URL(e).origin,T=new URL("/widget-auth",e);T.searchParams.set("silent","1"),T.searchParams.set("origin",window.location.origin);let E=new Promise(U=>{let x=document.createElement("iframe");x.setAttribute("aria-hidden","true"),x.style.position="fixed",x.style.width="1px",x.style.height="1px",x.style.opacity="0",x.style.pointerEvents="none",x.style.border="0",x.style.left="-9999px",x.style.top="-9999px",x.src=T.toString();let v=false,r=()=>{window.removeEventListener("message",p),clearTimeout(ee);try{x.remove();}catch{}a.current=null;},p=A=>{A.origin===l&&(A.data?.type!=="botbuddy-widget-auth"||!A.data.token||v||(v=true,U(String(A.data.token)),r()));},ee=setTimeout(()=>{v||(v=true,U(null),r());},Vt);window.addEventListener("message",p),document.body.appendChild(x);});return a.current=E,E},[e]);react.useEffect(()=>{if(!n)return;let l=jt(n);if(!l)return;let T=l-Date.now()-Yt,E=window.setTimeout(()=>{_();},Math.max(0,T));return ()=>window.clearTimeout(E)},[n,_]);let C=react.useCallback(()=>{let l=new URL("/widget-auth",e);l.searchParams.set("origin",window.location.origin);let T=420,E=520,U=window.screenX+(window.innerWidth-T)/2,x=window.screenY+(window.innerHeight-E)/2;window.open(l.toString(),"botbuddy-auth",`width=${T},height=${E},left=${U},top=${x},popup=yes`);},[e]),y=react.useCallback(()=>{s(null),u(null);try{localStorage.removeItem(je),localStorage.removeItem(Ve);}catch(l){console.warn("Unable to clear BotBuddy widget auth token",l);}},[]);return {token:n,displayName:c,isAuthenticated:!!n,openLogin:C,refreshNow:_,logout:y}}var Le=null;function qt(){try{if(typeof document<"u"){let e=document.querySelector("base[href]");if(e)return new URL(".botbuddy-totp.json",e.href).toString()}}catch{}return "/.botbuddy-totp.json"}function ze(){return Le||(Le=(async()=>{if(typeof fetch>"u")return null;try{let e=await fetch(qt(),{cache:"no-store"});if(!e.ok)return null;let n=await e.json();if(!n||typeof n!="object"||Array.isArray(n))return null;let s={};for(let[c,u]of Object.entries(n))typeof u=="string"&&u.length>0&&(s[c]=u);return s}catch{return null}})(),Le)}async function xt(e){return (await ze())?.[e]??null}function Jt(e){let n=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),s="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",c=[],u=0,a=0;for(let R of n){let _=s.indexOf(R);if(_<0)throw new Error("Invalid Base32 character in TOTP secret");a=a<<5|_,u+=5,u>=8&&(u-=8,c.push(a>>>u&255));}return Uint8Array.from(c)}async function bt(e,n=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let s=Jt(e),c=new Uint8Array(s.byteLength);c.set(s);let u=Math.floor(n/1e3/30),a=new Uint8Array(8),R=Math.floor(u/4294967296),_=u>>>0;a[0]=R>>>24&255,a[1]=R>>>16&255,a[2]=R>>>8&255,a[3]=R&255,a[4]=_>>>24&255,a[5]=_>>>16&255,a[6]=_>>>8&255,a[7]=_&255;let C=await crypto.subtle.importKey("raw",c,{name:"HMAC",hash:"SHA-1"},false,["sign"]),y=await crypto.subtle.sign("HMAC",C,a),l=new Uint8Array(y),T=l[l.length-1]&15;return (((l[T]&127)<<24|(l[T+1]&255)<<16|(l[T+2]&255)<<8|l[T+3]&255)%1e6).toString().padStart(6,"0")}function Xt(e){let n=new Date(e),c=Date.now()-n.getTime();if(c<6e4)return "just now";if(c<36e5)return `${Math.floor(c/6e4)}m ago`;if(c<864e5)return `${Math.floor(c/36e5)}h ago`;let u=n.getDate(),a=n.toLocaleString("en",{month:"short"}),R=n.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${a} ${u}, ${R}`}var S=({d:e,className:n,size:s=14})=>jsxRuntime.jsx("svg",{className:n,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 Zt(){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 s=document.documentElement,c=()=>s.classList.contains("dark")?"dark":s.classList.contains("light")?"light":null,u=c();u&&n(u);let a=window.matchMedia("(prefers-color-scheme: dark)"),R=C=>{let y=c();n(y||(C.matches?"dark":"light"));};a.addEventListener("change",R);let _=new MutationObserver(()=>{let C=c();n(C||(a.matches?"dark":"light"));});return _.observe(s,{attributes:true,attributeFilter:["class"]}),()=>{a.removeEventListener("change",R),_.disconnect();}},[]),e}function Qt(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 en={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},tn={pending:f.circle,pass:f.check,fail:f.x,skip:f.skip},vt={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)"}},nn=["app.supply-guard.io"];function rn(e,n=[]){if(!e)return false;let s=e.toLowerCase();return [...nn,...n].map(u=>u.toLowerCase()).includes(s)}var on=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,s)=>({width:`${n}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:n=>{let s=vt[n]||vt.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: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,s)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:n?`${s}33`:"transparent",color:n?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 wt(e){return e.split("/")[0].trim()}async function sn(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 s=document.execCommand("copy");return document.body.removeChild(n),s}catch{return false}}function _e({config:e,appSlug:n,environment:s,seededUsers:c,authToken:u,tk:a,compact:R=false,onExpand:_,onAuthExpired:C,refreshAuth:y,requestLogin:l,testRunId:T,testRunToken:E,ticketId:U,targetUrl:x,version:v,commitSha:r,prNumber:p,branchName:ee}){let[A,q]=react.useState(false),[O,j]=react.useState(null),[$,xe]=react.useState(null),[re,h]=react.useState(null),[Me,oe]=react.useState(null),[J,G]=react.useState(null);react.useEffect(()=>{s==="local"&&ze();},[s]);let te=react.useCallback(m=>{j(m),h(null),oe(null);let L=P=>{h(P),oe(m),window.setTimeout(()=>{oe(w=>w===m?null:w),h(w=>w===P?null:w);},3e3);},M=new URLSearchParams({app_slug:n,seed_user_slug:m,environment:s});T&&M.set("test_run_id",T),E&&M.set("public_token",E),U&&M.set("ticket_id",U),x&&M.set("target_url",x),v&&M.set("version",v),r&&M.set("commit_sha",r),p&&M.set("pr_number",String(p)),ee&&M.set("branch_name",ee);let D=async P=>{let w={apikey:e.anonKey,Authorization:`Bearer ${P}`};try{let z=await fetch(`${e.serverUrl}/widget/totp-code?${M}`,{headers:w});if(!z.ok){let V=await z.json().catch(()=>({error:`HTTP ${z.status}`}));return {ok:!1,status:z.status,error:V.error||`HTTP ${z.status}`}}let F=await z.json();return {ok:!0,code:String(F.code)}}catch{return {ok:false,status:0,error:"Network error"}}},I=(async()=>{if(s==="local"){let z=await xt(m);if(z)try{return {ok:!0,code:await bt(z)}}catch{}}let P=await D(u||e.anonKey);if(P.ok||P.status!==401||!y)return P;let w=await y();return w?D(w):{ok:false,status:401,error:"Sign in to BotBuddy to refresh 2FA"}})(),b=null;try{if(typeof ClipboardItem<"u"&&navigator.clipboard?.write){let P=I.then(w=>{if(!w.ok)throw new Error(w.error);return new Blob([w.code],{type:"text/plain"})});b=navigator.clipboard.write([new ClipboardItem({"text/plain":P})]).then(()=>!0).catch(()=>!1);}}catch{}(async()=>{let P=await I;if(!P.ok){P.status===401?(G({slug:m,token:u||null}),l?.(),L(P.error)):L(P.status===404?"No 2FA seed registered":P.error),j(null);return}let w=b?await b:false,z=w?true:await sn(P.code),F=w||z;xe({slug:m,code:P.code,copied:F}),window.setTimeout(()=>xe(V=>V?.slug===m?null:V),F?2500:6e3),q(false),j(null);})();},[e.serverUrl,e.anonKey,u,n,s,T,E,U,x,v,r,p,ee,y,l]);react.useEffect(()=>{if(!J||!u||u===J.token)return;let m=J.slug;G(null),te(m);},[u,te,J]);let ie=react.useRef(null),be=react.useRef(null);if(react.useLayoutEffect(()=>{if(!A)return;let m=ie.current,L=be.current;if(!m||!L||typeof window>"u")return;let M=()=>{let D=m.getBoundingClientRect(),I=L.getBoundingClientRect(),b=window.innerWidth,P=window.innerHeight,w=D.left,z=D.top-I.height-6;z<8&&(z=D.bottom+6);let F=Math.max(8,b-I.width-8),V=Math.max(8,P-I.height-8);w=Math.min(Math.max(w,8),F),z=Math.min(Math.max(z,8),V),L.style.left=`${Math.round(w)}px`,L.style.top=`${Math.round(z)}px`;};return M(),window.addEventListener("scroll",M,true),window.addEventListener("resize",M),()=>{window.removeEventListener("scroll",M,true),window.removeEventListener("resize",M);}},[A,c.length,re]),react.useEffect(()=>{if(!A)return;let m=L=>{let M=L.target;be.current?.contains(M)||ie.current?.contains(M)||q(false);};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[A]),c.length===0)return null;if(R){let m=c.length>1,L=w=>{if(w.stopPropagation(),m&&_){_();return}te(c[0]);},M=!!Me,D=!!$,I=D&&$.copied,b=D&&!$.copied,P=M?a.red:I?a.green:b?a.amber:a.purple;return jsxRuntime.jsxs("span",{onPointerDown:w=>w.stopPropagation(),onPointerUp:w=>w.stopPropagation(),onPointerMove:w=>w.stopPropagation(),onClick:L,style:{display:"inline-flex",alignItems:"center",gap:"3px",color:P,fontWeight:600,cursor:"pointer",letterSpacing:b?"0.08em":void 0},title:M?re||"Failed":b?`Clipboard blocked \u2014 code: ${$.code}`:m?`${c.length} 2FA personas`:`Copy 2FA code for ${c[0]}`,children:[jsxRuntime.jsx(S,{d:M?f.alert:I?f.check:b?f.copy:f.shield,size:10}),I?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Copied"}):b?jsxRuntime.jsx(jsxRuntime.Fragment,{children:$.code}):M?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Failed"}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["2FA",m&&` \xB7${c.length}`]})]})}if(c.length===1){let m=c[0],L=O===m,M=$?.slug===m,D=M&&$.copied,I=M&&!$.copied,b=Me===m,P=b?a.red:D?a.green:I?a.amber:a.purple;return jsxRuntime.jsxs("button",{onClick:w=>{w.stopPropagation(),te(m);},disabled:L,style:{...St(P),cursor:L?"wait":"pointer",opacity:L?.6:1},title:b?re||"Failed":I?`Clipboard blocked \u2014 code: ${$.code}`:`Copy 2FA code for ${m}`,children:[jsxRuntime.jsx(S,{d:b?f.alert:D?f.check:I?f.copy:f.shield,size:12}),D?"Copied":I?$.code:b?"Failed":L?"\u2026":`2FA \xB7 ${m}`]})}let X=!!Me&&!A,pe=!!$&&$.copied,ae=!!$&&!$.copied,$e=X?a.red:pe?a.green:ae?a.amber:a.purple,Be=A&&typeof document<"u"?reactDom.createPortal(jsxRuntime.jsxs("div",{ref:be,onPointerDown:m=>m.stopPropagation(),onMouseDown:m=>m.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:[c.map(m=>{let L=O===m;return jsxRuntime.jsxs("button",{onClick:M=>{M.stopPropagation(),te(m);},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:a.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},onMouseEnter:M=>M.currentTarget.style.background=a.btnHover,onMouseLeave:M=>M.currentTarget.style.background="transparent",children:[jsxRuntime.jsx(S,{d:f.shield,size:10}),jsxRuntime.jsx("span",{style:{flex:1,overflowWrap:"anywhere",lineHeight:1.3},children:m}),L&&jsxRuntime.jsx("span",{style:{color:a.textMuted,fontSize:9},children:"\u2026"})]},m)}),re&&jsxRuntime.jsx("div",{style:{padding:"4px 8px",fontSize:9,color:a.red},children:re})]}),document.body):null;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("button",{ref:ie,onClick:m=>{m.stopPropagation(),q(L=>!L),h(null),oe(null);},style:{...St($e),cursor:"pointer"},title:X?re||"Failed":ae?`Clipboard blocked \u2014 code: ${$.code}`:"Choose a persona to copy a 2FA code for",children:[jsxRuntime.jsx(S,{d:X?f.alert:pe?f.check:ae?f.copy:f.shield,size:12}),pe?"Copied":ae?$.code:X?"Failed":`2FA \xB7 ${c.length}`,jsxRuntime.jsx(S,{d:A?f.chevronUp:f.chevronDown,size:8})]}),Be]})}function St(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 kt="botbuddy-widget-state";function an({config:e,appSlug:n,environment:s,ticketId:c,testRunId:u,testRunToken:a,targetUrl:R,version:_,commitSha:C,prNumber:y,branchName:l,onNavigate:T,displayName:E="human",defaultMode:U="mini",defaultPosition:x}){let v=Zt(),r=react.useMemo(()=>Qt(v),[v]),p=react.useMemo(()=>on(r),[r]),[ee,A]=react.useState(false),[q,O]=react.useState(false),[j,$]=react.useState(false),xe=react.useRef(false),re=e.dashboardUrl||"https://app.bot-buddy.ai",h=Ye(re),oe=(()=>{try{let t=typeof window<"u"?localStorage.getItem(kt):null;if(t)return JSON.parse(t)}catch{}return null})(),[J,G]=react.useState(oe?.mode||U),[te,ie]=react.useState(""),[be,X]=react.useState(null),[pe,ae]=react.useState(null),[$e,Be]=react.useState(new Set),[m,L]=react.useState(""),M=react.useCallback(t=>{Be(d=>{let k=new Set(d);return k.has(t)?k.delete(t):k.add(t),k});},[]),D=oe?.x??x?.x??16,I=oe?.y??x?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:b,setPos:P,onPointerDown:w,onPointerMove:z,onPointerUp:F,didDrag:V}=Ne(D,I),le=react.useRef(null);react.useEffect(()=>{try{localStorage.setItem(kt,JSON.stringify({mode:J,x:b.x,y:b.y}));}catch{}},[J,b.x,b.y]),react.useLayoutEffect(()=>{if(typeof window>"u")return;let t=le.current;if(!t)return;let d=t.getBoundingClientRect(),k=Fe(b.x,b.y,d.width,d.height,window.innerWidth,window.innerHeight);(k.x!==b.x||k.y!==b.y)&&P(k);}),react.useEffect(()=>{if(typeof window>"u")return;let t=()=>{let d=le.current;if(!d)return;let k=d.getBoundingClientRect(),K=Fe(b.x,b.y,k.width,k.height,window.innerWidth,window.innerHeight);(K.x!==b.x||K.y!==b.y)&&P(K);};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[b.x,b.y,P]);let qe=react.useRef(h.isAuthenticated);react.useEffect(()=>{!qe.current&&h.isAuthenticated&&G("max"),qe.current=h.isAuthenticated;},[h.isAuthenticated]);let Je="botbuddy-widget-max-size",Mt=()=>{try{let t=localStorage.getItem(Je);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[ve,Ge]=react.useState(Mt),we=react.useRef(false),Se=react.useRef({x:0,y:0,w:0,h:0}),Tt=react.useCallback(t=>{t.stopPropagation(),we.current=true,Se.current={x:t.clientX,y:t.clientY,w:ve.w,h:ve.h},t.target.setPointerCapture(t.pointerId);},[ve]),Ct=react.useCallback(t=>{if(!we.current)return;let d=Math.max(280,Math.min(600,Se.current.w+(t.clientX-Se.current.x))),k=Math.max(300,Math.min(window.innerHeight*.9,Se.current.h+(t.clientY-Se.current.y)));Ge({w:d,h:k});},[]),Rt=react.useCallback(()=>{we.current&&(we.current=false,Ge(t=>(localStorage.setItem(Je,JSON.stringify(t)),t)));},[]),Y=R??(typeof window<"u"?window.location.href:void 0),Xe=h.displayName||E,[ne,Ze]=react.useState(null);react.useEffect(()=>{if(h.isAuthenticated)return;let t=new URLSearchParams;a&&t.set("token",a),c&&t.set("ticket_id",c),t.set("app_slug",n),s&&t.set("environment",s),u&&t.set("test_run_id",u),Y&&t.set("target_url",Y),_&&t.set("version",_),C&&t.set("commit_sha",C),y&&t.set("pr_number",String(y)),l&&t.set("branch_name",l),fetch(`${e.serverUrl}/widget/preview?${t}`,{headers:{apikey:e.anonKey}}).then(d=>d.json()).then(d=>Ze(d)).catch(()=>Ze(null));},[h.isAuthenticated,e.serverUrl,e.anonKey,n,s,c,u,a,Y,_,C,y,l]);let{run:g,widgetState:de,fetchRun:Pt,setVerdict:Qe,markComplete:Et,resetRun:Lt,setRun:et}=Ke({config:e,appSlug:n,environment:s,ticketId:c,testRunId:u,testRunToken:a,targetUrl:Y,version:_,commitSha:C,prNumber:y?String(y):void 0,branchName:l,authToken:h.token,onAuthExpired:h.logout}),[tt,nt]=react.useState([]),[Ae,rt]=react.useState(false),[ot,it]=react.useState(null),[zt,Te]=react.useState(false),ge=rn(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);react.useEffect(()=>{if((s??"local")!=="local"||ge){nt([]);return}let t=true;return ze().then(d=>{t&&nt(Object.keys(d||{}));}),()=>{t=false;}},[s,ge]);let $t=react.useCallback(async()=>{if(!(!h.isAuthenticated||!h.token)){rt(true),it(null);try{let t=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${h.token}`},body:JSON.stringify({app_slug:n,environment:s||"local",target_url:Y,branch_name:l,commit_sha:C,pr_number:y,ticket_id:c,title:`${c||n} local validation`})}),d=await t.json().catch(()=>({}));if(!t.ok)throw new Error(d.error||`HTTP ${t.status}`);et(d),G("max");}catch(t){it(t.message);}finally{rt(false);}}},[h.isAuthenticated,h.token,e.serverUrl,e.anonKey,n,s,Y,l,C,y,c,et]),Ce=react.useCallback(async(t,d,k)=>{ae(t);try{await Qe(t,d,k,Xe);}finally{ae(null),X(null),ie("");}},[Qe,Xe]),W=g?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},Bt=W.total>0&&W.pending===0,fe=de==="completed",Re=react.useMemo(()=>{let t=g?.test_cases||[];if(!m.trim())return t;let d=m.toLowerCase();return t.filter(k=>k.title.toLowerCase().includes(d)||k.description&&k.description.toLowerCase().includes(d)||k.url_path&&k.url_path.toLowerCase().includes(d)||k.seed_user&&k.seed_user.toLowerCase().includes(d))},[g?.test_cases,m]),st=react.useMemo(()=>{let t=Re,d=g?.test_cases||[];if(new Set(d.map(N=>N.source_pr_number)).size<=1)return null;let K=[],ke=new Map;t.forEach(N=>{let Z=N.source_pr_number;ke.has(Z)||ke.set(Z,[]),ke.get(Z).push(N);});let At=[...ke.keys()].sort((N,Z)=>N===null?1:Z===null?-1:Z-N);for(let N of At){let Z=ke.get(N),Ie={total:Z.length,pass:0,fail:0,skip:0,pending:0};Z.forEach(ft=>{ft.verdict in Ie&&Ie[ft.verdict]++;}),K.push({key:N!=null?`pr-${N}`:"general",label:N!=null?`PR #${N}`:"General",cases:Z,summary:Ie});}return K.filter(N=>N.cases.length>0)},[Re,g?.test_cases]),at=W.total>0?(W.pass+W.fail)/W.total*100:0,H=s??g?.environment??null,se=react.useMemo(()=>{if(!H||H==="production"||ge)return [];let t=g?.test_cases||[],d=new Set;for(let k of t)k.seed_user&&d.add(wt(k.seed_user));if(H==="local")for(let k of tt)d.add(wt(k));return [...d]},[g?.test_cases,H,tt,ge]),We=react.useMemo(()=>{let t=g?.auto_tooltip_seconds??ne?.auto_tooltip_seconds;return t!=null&&t>0?t*1e3:0},[g,ne]),lt=de==="ready"||de==="completed"||ne?.enabled&&ne.run;react.useEffect(()=>{if(!lt||xe.current||We<=0)return;xe.current=true,O(true);let t=window.setTimeout(()=>O(false),We);return ()=>window.clearTimeout(t)},[lt,We]);let dt=t=>jsxRuntime.jsxs("div",{style:p.caseRow,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsx("div",{style:{marginTop:"2px",flexShrink:0,color:en[t.verdict]},children:pe===t.id?jsxRuntime.jsx(S,{d:f.loader,className:""}):jsxRuntime.jsx(S,{d:tn[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: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:d=>{d.stopPropagation(),T&&(d.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:f.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(d=>jsxRuntime.jsx("button",{onClick:()=>{if(t.verdict===d){Ce(t.id,"pending"),X(null);return}if(d==="fail"){X(t.id),ie("");return}X(null),Ce(t.id,d);},disabled:pe!==null,style:p.verdictBtn(t.verdict===d,d==="pass"?r.green:d==="fail"?r.red:r.amber),children:d.toUpperCase()},d)),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:f.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:Xt(t.verdict_at)})]})]}),be===t.id&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:te,onChange:d=>ie(d.target.value),onKeyDown:d=>{d.key==="Enter"&&Ce(t.id,"fail",te.trim()||void 0),d.key==="Escape"&&(X(null),ie(""));},placeholder:"Reason (optional)...",style:p.input}),jsxRuntime.jsx("button",{onClick:()=>{Ce(t.id,"fail",te.trim()||void 0);},style:p.verdictBtn(true,r.red),children:"\u2713"})]})]},t.id);if((de==="no-match"||de==="loading")&&!(!h.isAuthenticated&&ne?.enabled&&ne.run)){if(!(H==="local"&&!ge))return null}if(!h.isAuthenticated&&ne?.enabled&&ne.run){let t=ne.run,d=t.summary,k=t.status==="completed";return jsxRuntime.jsx("div",{ref:le,style:{...p.root,left:b.x,top:b.y},children:jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>A(true),onMouseLeave:()=>{A(false),$(false),O(false);},children:[jsxRuntime.jsxs("div",{style:{...p.pill(k),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:w,onPointerMove:z,onPointerUp:()=>{F();},children:[jsxRuntime.jsx(S,{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: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:K=>K.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:K=>K.stopPropagation(),style:{color:r.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(S,{d:f.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:f.bot,size:10}),t.created_by_agent_name]}):null,jsxRuntime.jsxs("span",{style:k?{color:r.green}:void 0,children:[d.pass,"/",d.total]}),d.fail>0&&jsxRuntime.jsxs("span",{style:{color:r.red},children:[d.fail,"\u2717"]}),jsxRuntime.jsx("span",{onClick:K=>{K.stopPropagation(),h.openLogin();},style:{color:r.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!j&&(ee||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(!h.isAuthenticated)return jsxRuntime.jsxs("div",{ref:le,style:{...p.root,left:b.x,top:b.y,width:220,minHeight:0,cursor:"move",userSelect:"none",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`},onPointerDown:w,onPointerMove:z,onPointerUp:F,children:[jsxRuntime.jsx("div",{style:{...p.handle,borderBottom:"none"},children:jsxRuntime.jsxs("div",{style:p.sub,children:[jsxRuntime.jsx(S,{d:f.grip,size:10,className:""}),jsxRuntime.jsx(S,{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:r.textMuted,marginBottom:"8px"},children:"Sign in to access test cases"}),H==="local"&&se.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsxRuntime.jsx(_e,{config:e,appSlug:n,environment:H,seededUsers:se,authToken:h.token,refreshAuth:h.refreshNow,requestLogin:h.openLogin,tk:r,testRunId:g?.id||u,testRunToken:a,ticketId:c,targetUrl:Y,version:_,commitSha:C,prNumber:y,branchName:l,onAuthExpired:h.logout})}),jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),h.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(!g&&H==="local"&&!ge)return zt?jsxRuntime.jsx("div",{ref:le,style:{...p.root,left:b.x,top:b.y},children:jsxRuntime.jsxs("div",{style:p.card(240,false),children:[jsxRuntime.jsxs("div",{style:p.handle,onPointerDown:w,onPointerMove:z,onPointerUp:F,onClick:()=>{V.current||Te(false);},children:[jsxRuntime.jsx(S,{d:f.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:p.title,children:"BotBuddy"}),l&&jsxRuntime.jsx("div",{style:p.sub,children:jsxRuntime.jsxs("span",{children:["\u2387 ",l]})})]}),jsxRuntime.jsx(S,{d:f.chevronUp,className:""}),jsxRuntime.jsx("button",{style:p.btn,onClick:t=>{t.stopPropagation(),Te(false);},children:jsxRuntime.jsx(S,{d:f.minus,className:""})})]}),jsxRuntime.jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[se.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsxRuntime.jsx(_e,{config:e,appSlug:n,environment:H,seededUsers:se,authToken:h.token,refreshAuth:h.refreshNow,requestLogin:h.openLogin,tk:r,testRunId:u,testRunToken:a,ticketId:c,targetUrl:Y,version:_,commitSha:C,prNumber:y,branchName:l,onAuthExpired:h.logout})}),jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),$t();},disabled:Ae,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${r.green}`,background:`${r.green}22`,color:r.green,cursor:Ae?"wait":"pointer",width:"100%"},children:Ae?"Creating...":"Create test run for this branch"}),ot&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:r.red,marginTop:"8px"},children:ot})]})]})}):jsxRuntime.jsx("div",{ref:le,style:{...p.root,left:b.x,top:b.y},children:jsxRuntime.jsxs("div",{style:{...p.pill(false),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:w,onPointerMove:z,onPointerUp:()=>{F(),V.current||Te(true);},children:[jsxRuntime.jsx(S,{d:f.grip,size:9,className:""}),jsxRuntime.jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),se.length>0&&jsxRuntime.jsx(_e,{config:e,appSlug:n,environment:H,seededUsers:se,authToken:h.token,refreshAuth:h.refreshNow,requestLogin:h.openLogin,tk:r,compact:true,onExpand:()=>Te(true),testRunId:u,testRunToken:a,ticketId:c,targetUrl:Y,version:_,commitSha:C,prNumber:y,branchName:l,onAuthExpired:h.logout})]})});let ct=()=>{V.current||(O(false),G(t=>{let d=t==="mini"?"max":"mini";return $(d==="mini"),d}));},ut=({icon:t,onClick:d})=>jsxRuntime.jsx("button",{style:p.btn,onClick:k=>{k.stopPropagation(),d(k);},children:jsxRuntime.jsx(S,{d:t,className:""})}),pt=()=>jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${r.borderSubtle}`,flexShrink:0},children:[g?.pr_url&&jsxRuntime.jsxs("a",{href:g.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...p.link(r.blue),textDecoration:"none"},children:[jsxRuntime.jsx(S,{d:f.pr,size:12}),g.pr_number?`PR#${g.pr_number}`:g.pr_id||"PR",jsxRuntime.jsx(S,{d:f.externalLink,size:8})]}),g?.ticket_url&&jsxRuntime.jsxs("a",{href:g.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...p.link(r.amber),textDecoration:"none"},children:[jsxRuntime.jsx(S,{d:f.ticket,size:12}),g.ticket_id||"Ticket",jsxRuntime.jsx(S,{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:{...p.link(r.purple),textDecoration:"none"},children:[jsxRuntime.jsx(S,{d:f.bot,size:12}),g.created_by_agent_name,jsxRuntime.jsx(S,{d:f.externalLink,size:8})]}):jsxRuntime.jsxs("span",{style:{...p.link(r.purple)},children:[jsxRuntime.jsx(S,{d:f.bot,size:12}),g.created_by_agent_name]})),H&&jsxRuntime.jsx(_e,{config:e,appSlug:n,environment:H,seededUsers:se,authToken:h.token,refreshAuth:h.refreshNow,requestLogin:h.openLogin,tk:r,testRunId:g?.id||u,testRunToken:a,ticketId:c,targetUrl:Y,version:_,commitSha:C,prNumber:y,branchName:l,onAuthExpired:h.logout}),jsxRuntime.jsx("span",{style:{...p.badge(g?.environment||"custom"),marginLeft:"auto"},children:g?.environment})]}),gt=()=>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("0.10.10");},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.jsx("span",{style:{color:r.versionNum},children:"v0.10.10"})]}),h.isAuthenticated&&jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),h.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:le,style:{...p.root,left:b.x,top:b.y},children:[J==="mini"&&jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>A(true),onMouseLeave:()=>{A(false),$(false),O(false);},children:[jsxRuntime.jsxs("div",{style:{...p.pill(fe),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:w,onPointerMove:z,onPointerUp:()=>{F(),V.current||ct();},children:[jsxRuntime.jsx(S,{d:f.grip,size:9,className:""}),g?.ticket_id&&jsxRuntime.jsx("span",{style:{color:r.amber,fontWeight:600},children:g.ticket_id}),g?.pr_number&&jsxRuntime.jsxs("span",{style:{color:r.blue,fontWeight:600},children:["PR#",g.pr_number]}),jsxRuntime.jsxs("span",{style:fe?{color:r.green}:void 0,children:[W.pass,"/",W.total]}),W.fail>0&&jsxRuntime.jsxs("span",{style:{color:r.red},children:[W.fail,"\u2717"]}),H&&jsxRuntime.jsx(_e,{config:e,appSlug:n,environment:H,seededUsers:se,authToken:h.token,refreshAuth:h.refreshNow,requestLogin:h.openLogin,tk:r,compact:true,onExpand:()=>G("expanded"),testRunId:g?.id||u,testRunToken:a,ticketId:c,targetUrl:Y,version:_,commitSha:C,prNumber:y,branchName:l,onAuthExpired:h.logout})]}),!j&&(ee||q)&&g?.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:g.title}),(g.description||g.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:g.description||g.intro_notes})]})]}),J==="expanded"&&jsxRuntime.jsxs("div",{style:p.card(300,fe),children:[jsxRuntime.jsxs("div",{style:p.handle,onPointerDown:w,onPointerMove:z,onPointerUp:F,onClick:ct,children:[jsxRuntime.jsx(S,{d:f.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:p.title,children:g?.title}),jsxRuntime.jsx("div",{style:p.sub,children:g?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",g.branch_name]})})]}),jsxRuntime.jsx(S,{d:f.chevronUp,className:""}),jsxRuntime.jsx(ut,{icon:f.minus,onClick:()=>{O(false),$(true),G("mini");}})]}),jsxRuntime.jsxs("div",{style:p.stats,children:[jsxRuntime.jsxs("span",{style:{color:r.green},children:[W.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:r.red},children:[W.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:r.amber},children:[W.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:r.gripColor},children:[W.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:W.total})]}),g?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:r.gripColor,borderBottom:`1px solid ${r.borderSubtle}`,flexShrink:0},children:g.description}),pt(),gt(),jsxRuntime.jsx("div",{style:p.progress,children:jsxRuntime.jsx("div",{style:p.progressBar(at)})})]}),J==="max"&&jsxRuntime.jsxs("div",{style:{...p.card(ve.w,fe),height:ve.h,position:"relative"},children:[jsxRuntime.jsxs("div",{style:p.handle,onPointerDown:w,onPointerMove:z,onPointerUp:F,onClick:()=>{V.current||G("expanded");},children:[jsxRuntime.jsx(S,{d:f.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:p.title,children:g?.title}),jsxRuntime.jsx("div",{style:p.sub,children:g?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",g.branch_name]})})]}),jsxRuntime.jsx(S,{d:f.chevronDown,className:""}),jsxRuntime.jsx(ut,{icon:f.minus,onClick:()=>{O(false),$(true),G("mini");}})]}),jsxRuntime.jsxs("div",{style:p.stats,children:[jsxRuntime.jsxs("span",{style:{color:r.green},children:[W.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:r.red},children:[W.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:r.amber},children:[W.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:r.gripColor},children:[W.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:W.total})]}),g?.intro_notes&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${r.borderSubtle}`,fontSize:"10px",color:r.textMuted,fontStyle:"italic",flexShrink:0},children:g.intro_notes}),(g?.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:f.search,size:11,className:""}),jsxRuntime.jsx("input",{value:m,onChange:t=>L(t.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:r.text,fontFamily:"monospace"}}),m&&jsxRuntime.jsx("button",{onClick:()=>L(""),style:{background:"none",border:"none",cursor:"pointer",color:r.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),de==="error"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsxRuntime.jsx(S,{d:f.alert,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:r.red},children:"Failed to load"}),jsxRuntime.jsx("button",{onClick:Pt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),fe&&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:f.checkAll,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",color:r.green,flex:1},children:"Run completed"}),jsxRuntime.jsx("button",{onClick:Lt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),de!=="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:r.gripColor},children:"No test cases"}):Re.length===0?jsxRuntime.jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:['No matches for "',m,'"']}):st?st.map(t=>{let d=$e.has(t.key);return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>M(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:d?f.chevronDown:f.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})]}),!d&&t.cases.map(k=>dt(k))]},t.key)}):Re.map(t=>dt(t))}),Bt&&!fe&&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:Et,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"})]}),pt(),gt(),jsxRuntime.jsx("div",{style:p.progress,children:jsxRuntime.jsx("div",{style:p.progressBar(at)})}),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:Tt,onPointerMove:Ct,onPointerUp:Rt,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{we.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"})})})]})]})}
2
- exports.TestRunWidget=an;exports.useDraggable=Ne;exports.useRealtimeRefresh=Oe;exports.useTestRun=Ke;exports.useWidgetAuth=Ye;
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
+ exports.TestRunWidget=cn;exports.useDraggable=Ve;exports.useRealtimeRefresh=Ye;exports.useTestRun=qe;exports.useWidgetAuth=et;
package/dist/index.d.cts CHANGED
@@ -158,6 +158,15 @@ interface WidgetAuth {
158
158
  token: string | null;
159
159
  displayName: string | null;
160
160
  isAuthenticated: boolean;
161
+ /**
162
+ * True when a token is present but its JWT `exp` is in the past. The widget
163
+ * bearer is a ~1h Supabase access token with no refresh token, so an expired
164
+ * token can only be replaced by re-running the first-party /widget-auth
165
+ * popup. Callers use this to offer an honest "sign in" affordance instead of
166
+ * a "sign out" dead-end, and to open the popup synchronously inside a click
167
+ * gesture (a deferred window.open is popup-blocked). BOT-906.
168
+ */
169
+ isExpired: boolean;
161
170
  openLogin: () => void;
162
171
  /**
163
172
  * Attempt a silent token refresh via hidden iframe. Resolves with the new
package/dist/index.d.ts CHANGED
@@ -158,6 +158,15 @@ interface WidgetAuth {
158
158
  token: string | null;
159
159
  displayName: string | null;
160
160
  isAuthenticated: boolean;
161
+ /**
162
+ * True when a token is present but its JWT `exp` is in the past. The widget
163
+ * bearer is a ~1h Supabase access token with no refresh token, so an expired
164
+ * token can only be replaced by re-running the first-party /widget-auth
165
+ * popup. Callers use this to offer an honest "sign in" affordance instead of
166
+ * a "sign out" dead-end, and to open the popup synchronously inside a click
167
+ * gesture (a deferred window.open is popup-blocked). BOT-906.
168
+ */
169
+ isExpired: boolean;
161
170
  openLogin: () => void;
162
171
  /**
163
172
  * Attempt a silent token refresh via hidden iframe. Resolves with the new
package/dist/index.js CHANGED
@@ -1,2 +1,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 he=8;function Fe(e,n,s,c,u,a){let R=Math.max(he,u-s-he),_=Math.max(he,a-c-he);return {x:Math.min(Math.max(e,he),R),y:Math.min(Math.max(n,he),_)}}function Ne(e,n){let[s,c]=useState({x:e,y:n}),u=useRef(false),a=useRef({x:0,y:0}),R=useRef(false),_=useCallback(l=>{u.current=true,R.current=false,a.current={x:l.clientX-s.x,y:l.clientY-s.y},l.target.setPointerCapture(l.pointerId);},[s]),C=useCallback(l=>{u.current&&(R.current=true,c({x:l.clientX-a.current.x,y:l.clientY-a.current.y}));},[]),y=useCallback(()=>{u.current=false;},[]);return {pos:s,setPos:c,onPointerDown:_,onPointerMove:C,onPointerUp:y,didDrag:R}}function Oe(e,n,s){let c=useRef(s);c.current=s,useEffect(()=>{if(!n)return;if(e.supabaseUrl){let a=false,R=null,_=()=>{a||R||(R=setInterval(()=>c.current(),15e3));},C=null;try{let v=new URL(e.supabaseUrl),r=["localhost","127.0.0.1","::1"].includes(v.hostname);if(v.protocol==="http:"&&!r)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");v.protocol=v.protocol==="https:"?"wss:":"ws:",C=v.toString().replace(/\/$/,"");}catch{_();}let y=null,l=null,T=null,E=0,U=()=>{if(!(a||!C)){try{y=new WebSocket(`${C}/realtime/v1/websocket?apikey=${e.anonKey}&vsn=1.0.0`);}catch{_();return}y.onopen=()=>{if(a||!y)return;let v={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(++E)};y.send(JSON.stringify(v));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(++E)};y.send(JSON.stringify(r)),l=setInterval(()=>{y?.readyState===WebSocket.OPEN&&y.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++E)}));},3e4);},y.onmessage=v=>{try{JSON.parse(v.data).event==="postgres_changes"&&c.current();}catch{}},y.onclose=()=>{x(),a||(T=setTimeout(U,3e3));},y.onerror=()=>{y?.close();};}},x=()=>{l&&(clearInterval(l),l=null);};return U(),()=>{a=true,x(),T&&clearTimeout(T),R&&clearInterval(R),y&&(y.onclose=null,y.onerror=null,y.close());}}let u=setInterval(()=>c.current(),15e3);return ()=>clearInterval(u)},[e.supabaseUrl,e.anonKey,n]);}var Ft="botbuddy:created-test-run:";function Nt(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function Ot(e){return `${Ft}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",Nt(e.targetUrl),e.branchName||""].join("|"))}`}function Pe(e,n){let s={apikey:e.anonKey};return n?s.Authorization=`Bearer ${n}`:e.apiKey?s.Authorization=`Bearer ${e.apiKey}`:s.Authorization=`Bearer ${e.anonKey}`,s}async function Ht(e){if(e)return e;try{let n=await fetch("/.botbuddy-token",{cache:"no-store"});if(n.ok){let s=(await n.text()).trim();if(s.startsWith("public_"))return s}}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 Ke(e){let[n,s]=useState(null),[c,u]=useState("loading"),a=Ot(e),[R,_]=useState(()=>{if(e.testRunId)return e.testRunId;try{return localStorage.getItem(a)||void 0}catch{return}}),C=e.testRunId||R,y=useCallback(x=>{if(s(x),!!x?.id){_(x.id);try{localStorage.setItem(a,x.id);}catch{}}},[a]),l=useCallback(async()=>{try{let x=await Ht(e.testRunToken);if(!x&&!C){u("no-match"),s(null);return}if(x&&!e.ticketId){u("no-match"),s(null);return}let v=new URLSearchParams;x&&v.set("token",x),e.ticketId&&v.set("ticket_id",e.ticketId),v.set("app_slug",e.appSlug),e.environment&&v.set("environment",e.environment),C&&v.set("test_run_id",C),e.targetUrl&&v.set("target_url",e.targetUrl),e.version&&v.set("version",e.version),e.commitSha&&v.set("commit_sha",e.commitSha),e.prNumber&&v.set("pr_number",String(e.prNumber)),e.branchName&&v.set("branch_name",e.branchName);let r=await fetch(`${e.config.serverUrl}/widget/test-run?${v.toString()}`,{headers:Pe(e.config,e.authToken)});if(r.status===404){u("no-match"),s(null);return}if(r.status===401||r.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),u("error");return}if(!r.ok){u("error");return}let p=await r.json();if(!p||p.run===null){u("no-match"),s(null);return}y(p),u(p.status==="completed"?"completed":"ready");}catch{u("error");}},[e.config.serverUrl,e.config.anonKey,e.config.apiKey,e.authToken,e.appSlug,e.environment,e.ticketId,C,e.testRunToken,e.targetUrl,e.version,e.commitSha,e.branchName,e.prNumber,e.onAuthExpired,y]);return useEffect(()=>{l();},[l]),Oe(e.config,n?.id,l),{run:n,widgetState:c,fetchRun:l,setVerdict:async(x,v,r,p="human")=>(s(A=>{if(!A)return null;let q=A.test_cases.map(j=>j.id===x?{...j,verdict:v,fail_reason:v==="fail"&&r||null,verdict_by_display_name:p,verdict_at:new Date().toISOString()}:j),O={total:q.length,pending:0,pass:0,fail:0,skip:0};return q.forEach(j=>{j.verdict in O&&O[j.verdict]++;}),{...A,test_cases:q,summary:O}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${x}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...Pe(e.config,e.authToken)},body:JSON.stringify({verdict:v,fail_reason:r,display_name:p})})).ok),markComplete:async()=>n?(s(v=>v?{...v,status:"completed"}:null),u("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${n.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...Pe(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!n)return false;let x=await fetch(`${e.config.serverUrl}/widget/test-runs/${n.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...Pe(e.config,e.authToken)}});return x.ok&&l(),x.ok},setRun:y}}var je="botbuddy-widget-auth-token",Ve="botbuddy-widget-auth-name";function jt(e){if(!e)return null;try{let n=e.split(".")[1];if(!n)return null;let s=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(n.length/4)*4,"="),c=atob(s),u=JSON.parse(c);return typeof u.exp=="number"?u.exp*1e3:null}catch{return null}}var Vt=8e3,Yt=6e4;function Ye(e){let[n,s]=useState(()=>{try{return localStorage.getItem(je)}catch(l){return console.warn("Unable to read BotBuddy widget auth token",l),null}}),[c,u]=useState(()=>{try{return localStorage.getItem(Ve)}catch(l){return console.warn("Unable to read BotBuddy widget display name",l),null}}),a=useRef(null),R=useCallback((l,T)=>{s(l),T&&u(T);try{localStorage.setItem(je,l),T&&localStorage.setItem(Ve,T);}catch(E){console.warn("Unable to persist BotBuddy widget auth token",E);}},[]);useEffect(()=>{let l=new URL(e).origin,T=E=>{E.origin===l&&E.data?.type==="botbuddy-widget-auth"&&E.data.token&&R(E.data.token,E.data.displayName||"human");};return window.addEventListener("message",T),()=>window.removeEventListener("message",T)},[e,R]);let _=useCallback(()=>{if(a.current)return a.current;if(typeof window>"u"||typeof document>"u")return Promise.resolve(null);let l=new URL(e).origin,T=new URL("/widget-auth",e);T.searchParams.set("silent","1"),T.searchParams.set("origin",window.location.origin);let E=new Promise(U=>{let x=document.createElement("iframe");x.setAttribute("aria-hidden","true"),x.style.position="fixed",x.style.width="1px",x.style.height="1px",x.style.opacity="0",x.style.pointerEvents="none",x.style.border="0",x.style.left="-9999px",x.style.top="-9999px",x.src=T.toString();let v=false,r=()=>{window.removeEventListener("message",p),clearTimeout(ee);try{x.remove();}catch{}a.current=null;},p=A=>{A.origin===l&&(A.data?.type!=="botbuddy-widget-auth"||!A.data.token||v||(v=true,U(String(A.data.token)),r()));},ee=setTimeout(()=>{v||(v=true,U(null),r());},Vt);window.addEventListener("message",p),document.body.appendChild(x);});return a.current=E,E},[e]);useEffect(()=>{if(!n)return;let l=jt(n);if(!l)return;let T=l-Date.now()-Yt,E=window.setTimeout(()=>{_();},Math.max(0,T));return ()=>window.clearTimeout(E)},[n,_]);let C=useCallback(()=>{let l=new URL("/widget-auth",e);l.searchParams.set("origin",window.location.origin);let T=420,E=520,U=window.screenX+(window.innerWidth-T)/2,x=window.screenY+(window.innerHeight-E)/2;window.open(l.toString(),"botbuddy-auth",`width=${T},height=${E},left=${U},top=${x},popup=yes`);},[e]),y=useCallback(()=>{s(null),u(null);try{localStorage.removeItem(je),localStorage.removeItem(Ve);}catch(l){console.warn("Unable to clear BotBuddy widget auth token",l);}},[]);return {token:n,displayName:c,isAuthenticated:!!n,openLogin:C,refreshNow:_,logout:y}}var Le=null;function qt(){try{if(typeof document<"u"){let e=document.querySelector("base[href]");if(e)return new URL(".botbuddy-totp.json",e.href).toString()}}catch{}return "/.botbuddy-totp.json"}function ze(){return Le||(Le=(async()=>{if(typeof fetch>"u")return null;try{let e=await fetch(qt(),{cache:"no-store"});if(!e.ok)return null;let n=await e.json();if(!n||typeof n!="object"||Array.isArray(n))return null;let s={};for(let[c,u]of Object.entries(n))typeof u=="string"&&u.length>0&&(s[c]=u);return s}catch{return null}})(),Le)}async function xt(e){return (await ze())?.[e]??null}function Jt(e){let n=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),s="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",c=[],u=0,a=0;for(let R of n){let _=s.indexOf(R);if(_<0)throw new Error("Invalid Base32 character in TOTP secret");a=a<<5|_,u+=5,u>=8&&(u-=8,c.push(a>>>u&255));}return Uint8Array.from(c)}async function bt(e,n=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let s=Jt(e),c=new Uint8Array(s.byteLength);c.set(s);let u=Math.floor(n/1e3/30),a=new Uint8Array(8),R=Math.floor(u/4294967296),_=u>>>0;a[0]=R>>>24&255,a[1]=R>>>16&255,a[2]=R>>>8&255,a[3]=R&255,a[4]=_>>>24&255,a[5]=_>>>16&255,a[6]=_>>>8&255,a[7]=_&255;let C=await crypto.subtle.importKey("raw",c,{name:"HMAC",hash:"SHA-1"},false,["sign"]),y=await crypto.subtle.sign("HMAC",C,a),l=new Uint8Array(y),T=l[l.length-1]&15;return (((l[T]&127)<<24|(l[T+1]&255)<<16|(l[T+2]&255)<<8|l[T+3]&255)%1e6).toString().padStart(6,"0")}function Xt(e){let n=new Date(e),c=Date.now()-n.getTime();if(c<6e4)return "just now";if(c<36e5)return `${Math.floor(c/6e4)}m ago`;if(c<864e5)return `${Math.floor(c/36e5)}h ago`;let u=n.getDate(),a=n.toLocaleString("en",{month:"short"}),R=n.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${a} ${u}, ${R}`}var S=({d:e,className:n,size:s=14})=>jsx("svg",{className:n,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 Zt(){let[e,n]=useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return useEffect(()=>{if(typeof window>"u")return;let s=document.documentElement,c=()=>s.classList.contains("dark")?"dark":s.classList.contains("light")?"light":null,u=c();u&&n(u);let a=window.matchMedia("(prefers-color-scheme: dark)"),R=C=>{let y=c();n(y||(C.matches?"dark":"light"));};a.addEventListener("change",R);let _=new MutationObserver(()=>{let C=c();n(C||(a.matches?"dark":"light"));});return _.observe(s,{attributes:true,attributeFilter:["class"]}),()=>{a.removeEventListener("change",R),_.disconnect();}},[]),e}function Qt(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 en={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},tn={pending:f.circle,pass:f.check,fail:f.x,skip:f.skip},vt={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)"}},nn=["app.supply-guard.io"];function rn(e,n=[]){if(!e)return false;let s=e.toLowerCase();return [...nn,...n].map(u=>u.toLowerCase()).includes(s)}var on=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,s)=>({width:`${n}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:n=>{let s=vt[n]||vt.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: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,s)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:n?`${s}33`:"transparent",color:n?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 wt(e){return e.split("/")[0].trim()}async function sn(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 s=document.execCommand("copy");return document.body.removeChild(n),s}catch{return false}}function _e({config:e,appSlug:n,environment:s,seededUsers:c,authToken:u,tk:a,compact:R=false,onExpand:_,onAuthExpired:C,refreshAuth:y,requestLogin:l,testRunId:T,testRunToken:E,ticketId:U,targetUrl:x,version:v,commitSha:r,prNumber:p,branchName:ee}){let[A,q]=useState(false),[O,j]=useState(null),[$,xe]=useState(null),[re,h]=useState(null),[Me,oe]=useState(null),[J,G]=useState(null);useEffect(()=>{s==="local"&&ze();},[s]);let te=useCallback(m=>{j(m),h(null),oe(null);let L=P=>{h(P),oe(m),window.setTimeout(()=>{oe(w=>w===m?null:w),h(w=>w===P?null:w);},3e3);},M=new URLSearchParams({app_slug:n,seed_user_slug:m,environment:s});T&&M.set("test_run_id",T),E&&M.set("public_token",E),U&&M.set("ticket_id",U),x&&M.set("target_url",x),v&&M.set("version",v),r&&M.set("commit_sha",r),p&&M.set("pr_number",String(p)),ee&&M.set("branch_name",ee);let D=async P=>{let w={apikey:e.anonKey,Authorization:`Bearer ${P}`};try{let z=await fetch(`${e.serverUrl}/widget/totp-code?${M}`,{headers:w});if(!z.ok){let V=await z.json().catch(()=>({error:`HTTP ${z.status}`}));return {ok:!1,status:z.status,error:V.error||`HTTP ${z.status}`}}let F=await z.json();return {ok:!0,code:String(F.code)}}catch{return {ok:false,status:0,error:"Network error"}}},I=(async()=>{if(s==="local"){let z=await xt(m);if(z)try{return {ok:!0,code:await bt(z)}}catch{}}let P=await D(u||e.anonKey);if(P.ok||P.status!==401||!y)return P;let w=await y();return w?D(w):{ok:false,status:401,error:"Sign in to BotBuddy to refresh 2FA"}})(),b=null;try{if(typeof ClipboardItem<"u"&&navigator.clipboard?.write){let P=I.then(w=>{if(!w.ok)throw new Error(w.error);return new Blob([w.code],{type:"text/plain"})});b=navigator.clipboard.write([new ClipboardItem({"text/plain":P})]).then(()=>!0).catch(()=>!1);}}catch{}(async()=>{let P=await I;if(!P.ok){P.status===401?(G({slug:m,token:u||null}),l?.(),L(P.error)):L(P.status===404?"No 2FA seed registered":P.error),j(null);return}let w=b?await b:false,z=w?true:await sn(P.code),F=w||z;xe({slug:m,code:P.code,copied:F}),window.setTimeout(()=>xe(V=>V?.slug===m?null:V),F?2500:6e3),q(false),j(null);})();},[e.serverUrl,e.anonKey,u,n,s,T,E,U,x,v,r,p,ee,y,l]);useEffect(()=>{if(!J||!u||u===J.token)return;let m=J.slug;G(null),te(m);},[u,te,J]);let ie=useRef(null),be=useRef(null);if(useLayoutEffect(()=>{if(!A)return;let m=ie.current,L=be.current;if(!m||!L||typeof window>"u")return;let M=()=>{let D=m.getBoundingClientRect(),I=L.getBoundingClientRect(),b=window.innerWidth,P=window.innerHeight,w=D.left,z=D.top-I.height-6;z<8&&(z=D.bottom+6);let F=Math.max(8,b-I.width-8),V=Math.max(8,P-I.height-8);w=Math.min(Math.max(w,8),F),z=Math.min(Math.max(z,8),V),L.style.left=`${Math.round(w)}px`,L.style.top=`${Math.round(z)}px`;};return M(),window.addEventListener("scroll",M,true),window.addEventListener("resize",M),()=>{window.removeEventListener("scroll",M,true),window.removeEventListener("resize",M);}},[A,c.length,re]),useEffect(()=>{if(!A)return;let m=L=>{let M=L.target;be.current?.contains(M)||ie.current?.contains(M)||q(false);};return document.addEventListener("mousedown",m),()=>document.removeEventListener("mousedown",m)},[A]),c.length===0)return null;if(R){let m=c.length>1,L=w=>{if(w.stopPropagation(),m&&_){_();return}te(c[0]);},M=!!Me,D=!!$,I=D&&$.copied,b=D&&!$.copied,P=M?a.red:I?a.green:b?a.amber:a.purple;return jsxs("span",{onPointerDown:w=>w.stopPropagation(),onPointerUp:w=>w.stopPropagation(),onPointerMove:w=>w.stopPropagation(),onClick:L,style:{display:"inline-flex",alignItems:"center",gap:"3px",color:P,fontWeight:600,cursor:"pointer",letterSpacing:b?"0.08em":void 0},title:M?re||"Failed":b?`Clipboard blocked \u2014 code: ${$.code}`:m?`${c.length} 2FA personas`:`Copy 2FA code for ${c[0]}`,children:[jsx(S,{d:M?f.alert:I?f.check:b?f.copy:f.shield,size:10}),I?jsx(Fragment,{children:"Copied"}):b?jsx(Fragment,{children:$.code}):M?jsx(Fragment,{children:"Failed"}):jsxs(Fragment,{children:["2FA",m&&` \xB7${c.length}`]})]})}if(c.length===1){let m=c[0],L=O===m,M=$?.slug===m,D=M&&$.copied,I=M&&!$.copied,b=Me===m,P=b?a.red:D?a.green:I?a.amber:a.purple;return jsxs("button",{onClick:w=>{w.stopPropagation(),te(m);},disabled:L,style:{...St(P),cursor:L?"wait":"pointer",opacity:L?.6:1},title:b?re||"Failed":I?`Clipboard blocked \u2014 code: ${$.code}`:`Copy 2FA code for ${m}`,children:[jsx(S,{d:b?f.alert:D?f.check:I?f.copy:f.shield,size:12}),D?"Copied":I?$.code:b?"Failed":L?"\u2026":`2FA \xB7 ${m}`]})}let X=!!Me&&!A,pe=!!$&&$.copied,ae=!!$&&!$.copied,$e=X?a.red:pe?a.green:ae?a.amber:a.purple,Be=A&&typeof document<"u"?createPortal(jsxs("div",{ref:be,onPointerDown:m=>m.stopPropagation(),onMouseDown:m=>m.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:[c.map(m=>{let L=O===m;return jsxs("button",{onClick:M=>{M.stopPropagation(),te(m);},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:a.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},onMouseEnter:M=>M.currentTarget.style.background=a.btnHover,onMouseLeave:M=>M.currentTarget.style.background="transparent",children:[jsx(S,{d:f.shield,size:10}),jsx("span",{style:{flex:1,overflowWrap:"anywhere",lineHeight:1.3},children:m}),L&&jsx("span",{style:{color:a.textMuted,fontSize:9},children:"\u2026"})]},m)}),re&&jsx("div",{style:{padding:"4px 8px",fontSize:9,color:a.red},children:re})]}),document.body):null;return jsxs(Fragment,{children:[jsxs("button",{ref:ie,onClick:m=>{m.stopPropagation(),q(L=>!L),h(null),oe(null);},style:{...St($e),cursor:"pointer"},title:X?re||"Failed":ae?`Clipboard blocked \u2014 code: ${$.code}`:"Choose a persona to copy a 2FA code for",children:[jsx(S,{d:X?f.alert:pe?f.check:ae?f.copy:f.shield,size:12}),pe?"Copied":ae?$.code:X?"Failed":`2FA \xB7 ${c.length}`,jsx(S,{d:A?f.chevronUp:f.chevronDown,size:8})]}),Be]})}function St(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 kt="botbuddy-widget-state";function an({config:e,appSlug:n,environment:s,ticketId:c,testRunId:u,testRunToken:a,targetUrl:R,version:_,commitSha:C,prNumber:y,branchName:l,onNavigate:T,displayName:E="human",defaultMode:U="mini",defaultPosition:x}){let v=Zt(),r=useMemo(()=>Qt(v),[v]),p=useMemo(()=>on(r),[r]),[ee,A]=useState(false),[q,O]=useState(false),[j,$]=useState(false),xe=useRef(false),re=e.dashboardUrl||"https://app.bot-buddy.ai",h=Ye(re),oe=(()=>{try{let t=typeof window<"u"?localStorage.getItem(kt):null;if(t)return JSON.parse(t)}catch{}return null})(),[J,G]=useState(oe?.mode||U),[te,ie]=useState(""),[be,X]=useState(null),[pe,ae]=useState(null),[$e,Be]=useState(new Set),[m,L]=useState(""),M=useCallback(t=>{Be(d=>{let k=new Set(d);return k.has(t)?k.delete(t):k.add(t),k});},[]),D=oe?.x??x?.x??16,I=oe?.y??x?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:b,setPos:P,onPointerDown:w,onPointerMove:z,onPointerUp:F,didDrag:V}=Ne(D,I),le=useRef(null);useEffect(()=>{try{localStorage.setItem(kt,JSON.stringify({mode:J,x:b.x,y:b.y}));}catch{}},[J,b.x,b.y]),useLayoutEffect(()=>{if(typeof window>"u")return;let t=le.current;if(!t)return;let d=t.getBoundingClientRect(),k=Fe(b.x,b.y,d.width,d.height,window.innerWidth,window.innerHeight);(k.x!==b.x||k.y!==b.y)&&P(k);}),useEffect(()=>{if(typeof window>"u")return;let t=()=>{let d=le.current;if(!d)return;let k=d.getBoundingClientRect(),K=Fe(b.x,b.y,k.width,k.height,window.innerWidth,window.innerHeight);(K.x!==b.x||K.y!==b.y)&&P(K);};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[b.x,b.y,P]);let qe=useRef(h.isAuthenticated);useEffect(()=>{!qe.current&&h.isAuthenticated&&G("max"),qe.current=h.isAuthenticated;},[h.isAuthenticated]);let Je="botbuddy-widget-max-size",Mt=()=>{try{let t=localStorage.getItem(Je);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[ve,Ge]=useState(Mt),we=useRef(false),Se=useRef({x:0,y:0,w:0,h:0}),Tt=useCallback(t=>{t.stopPropagation(),we.current=true,Se.current={x:t.clientX,y:t.clientY,w:ve.w,h:ve.h},t.target.setPointerCapture(t.pointerId);},[ve]),Ct=useCallback(t=>{if(!we.current)return;let d=Math.max(280,Math.min(600,Se.current.w+(t.clientX-Se.current.x))),k=Math.max(300,Math.min(window.innerHeight*.9,Se.current.h+(t.clientY-Se.current.y)));Ge({w:d,h:k});},[]),Rt=useCallback(()=>{we.current&&(we.current=false,Ge(t=>(localStorage.setItem(Je,JSON.stringify(t)),t)));},[]),Y=R??(typeof window<"u"?window.location.href:void 0),Xe=h.displayName||E,[ne,Ze]=useState(null);useEffect(()=>{if(h.isAuthenticated)return;let t=new URLSearchParams;a&&t.set("token",a),c&&t.set("ticket_id",c),t.set("app_slug",n),s&&t.set("environment",s),u&&t.set("test_run_id",u),Y&&t.set("target_url",Y),_&&t.set("version",_),C&&t.set("commit_sha",C),y&&t.set("pr_number",String(y)),l&&t.set("branch_name",l),fetch(`${e.serverUrl}/widget/preview?${t}`,{headers:{apikey:e.anonKey}}).then(d=>d.json()).then(d=>Ze(d)).catch(()=>Ze(null));},[h.isAuthenticated,e.serverUrl,e.anonKey,n,s,c,u,a,Y,_,C,y,l]);let{run:g,widgetState:de,fetchRun:Pt,setVerdict:Qe,markComplete:Et,resetRun:Lt,setRun:et}=Ke({config:e,appSlug:n,environment:s,ticketId:c,testRunId:u,testRunToken:a,targetUrl:Y,version:_,commitSha:C,prNumber:y?String(y):void 0,branchName:l,authToken:h.token,onAuthExpired:h.logout}),[tt,nt]=useState([]),[Ae,rt]=useState(false),[ot,it]=useState(null),[zt,Te]=useState(false),ge=rn(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);useEffect(()=>{if((s??"local")!=="local"||ge){nt([]);return}let t=true;return ze().then(d=>{t&&nt(Object.keys(d||{}));}),()=>{t=false;}},[s,ge]);let $t=useCallback(async()=>{if(!(!h.isAuthenticated||!h.token)){rt(true),it(null);try{let t=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${h.token}`},body:JSON.stringify({app_slug:n,environment:s||"local",target_url:Y,branch_name:l,commit_sha:C,pr_number:y,ticket_id:c,title:`${c||n} local validation`})}),d=await t.json().catch(()=>({}));if(!t.ok)throw new Error(d.error||`HTTP ${t.status}`);et(d),G("max");}catch(t){it(t.message);}finally{rt(false);}}},[h.isAuthenticated,h.token,e.serverUrl,e.anonKey,n,s,Y,l,C,y,c,et]),Ce=useCallback(async(t,d,k)=>{ae(t);try{await Qe(t,d,k,Xe);}finally{ae(null),X(null),ie("");}},[Qe,Xe]),W=g?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},Bt=W.total>0&&W.pending===0,fe=de==="completed",Re=useMemo(()=>{let t=g?.test_cases||[];if(!m.trim())return t;let d=m.toLowerCase();return t.filter(k=>k.title.toLowerCase().includes(d)||k.description&&k.description.toLowerCase().includes(d)||k.url_path&&k.url_path.toLowerCase().includes(d)||k.seed_user&&k.seed_user.toLowerCase().includes(d))},[g?.test_cases,m]),st=useMemo(()=>{let t=Re,d=g?.test_cases||[];if(new Set(d.map(N=>N.source_pr_number)).size<=1)return null;let K=[],ke=new Map;t.forEach(N=>{let Z=N.source_pr_number;ke.has(Z)||ke.set(Z,[]),ke.get(Z).push(N);});let At=[...ke.keys()].sort((N,Z)=>N===null?1:Z===null?-1:Z-N);for(let N of At){let Z=ke.get(N),Ie={total:Z.length,pass:0,fail:0,skip:0,pending:0};Z.forEach(ft=>{ft.verdict in Ie&&Ie[ft.verdict]++;}),K.push({key:N!=null?`pr-${N}`:"general",label:N!=null?`PR #${N}`:"General",cases:Z,summary:Ie});}return K.filter(N=>N.cases.length>0)},[Re,g?.test_cases]),at=W.total>0?(W.pass+W.fail)/W.total*100:0,H=s??g?.environment??null,se=useMemo(()=>{if(!H||H==="production"||ge)return [];let t=g?.test_cases||[],d=new Set;for(let k of t)k.seed_user&&d.add(wt(k.seed_user));if(H==="local")for(let k of tt)d.add(wt(k));return [...d]},[g?.test_cases,H,tt,ge]),We=useMemo(()=>{let t=g?.auto_tooltip_seconds??ne?.auto_tooltip_seconds;return t!=null&&t>0?t*1e3:0},[g,ne]),lt=de==="ready"||de==="completed"||ne?.enabled&&ne.run;useEffect(()=>{if(!lt||xe.current||We<=0)return;xe.current=true,O(true);let t=window.setTimeout(()=>O(false),We);return ()=>window.clearTimeout(t)},[lt,We]);let dt=t=>jsxs("div",{style:p.caseRow,children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsx("div",{style:{marginTop:"2px",flexShrink:0,color:en[t.verdict]},children:pe===t.id?jsx(S,{d:f.loader,className:""}):jsx(S,{d:tn[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: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:d=>{d.stopPropagation(),T&&(d.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:f.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(d=>jsx("button",{onClick:()=>{if(t.verdict===d){Ce(t.id,"pending"),X(null);return}if(d==="fail"){X(t.id),ie("");return}X(null),Ce(t.id,d);},disabled:pe!==null,style:p.verdictBtn(t.verdict===d,d==="pass"?r.green:d==="fail"?r.red:r.amber),children:d.toUpperCase()},d)),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:f.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:Xt(t.verdict_at)})]})]}),be===t.id&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:te,onChange:d=>ie(d.target.value),onKeyDown:d=>{d.key==="Enter"&&Ce(t.id,"fail",te.trim()||void 0),d.key==="Escape"&&(X(null),ie(""));},placeholder:"Reason (optional)...",style:p.input}),jsx("button",{onClick:()=>{Ce(t.id,"fail",te.trim()||void 0);},style:p.verdictBtn(true,r.red),children:"\u2713"})]})]},t.id);if((de==="no-match"||de==="loading")&&!(!h.isAuthenticated&&ne?.enabled&&ne.run)){if(!(H==="local"&&!ge))return null}if(!h.isAuthenticated&&ne?.enabled&&ne.run){let t=ne.run,d=t.summary,k=t.status==="completed";return jsx("div",{ref:le,style:{...p.root,left:b.x,top:b.y},children:jsxs("div",{style:{position:"relative"},onMouseEnter:()=>A(true),onMouseLeave:()=>{A(false),$(false),O(false);},children:[jsxs("div",{style:{...p.pill(k),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:w,onPointerMove:z,onPointerUp:()=>{F();},children:[jsx(S,{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: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:K=>K.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:K=>K.stopPropagation(),style:{color:r.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(S,{d:f.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:f.bot,size:10}),t.created_by_agent_name]}):null,jsxs("span",{style:k?{color:r.green}:void 0,children:[d.pass,"/",d.total]}),d.fail>0&&jsxs("span",{style:{color:r.red},children:[d.fail,"\u2717"]}),jsx("span",{onClick:K=>{K.stopPropagation(),h.openLogin();},style:{color:r.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!j&&(ee||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(!h.isAuthenticated)return jsxs("div",{ref:le,style:{...p.root,left:b.x,top:b.y,width:220,minHeight:0,cursor:"move",userSelect:"none",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`},onPointerDown:w,onPointerMove:z,onPointerUp:F,children:[jsx("div",{style:{...p.handle,borderBottom:"none"},children:jsxs("div",{style:p.sub,children:[jsx(S,{d:f.grip,size:10,className:""}),jsx(S,{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:r.textMuted,marginBottom:"8px"},children:"Sign in to access test cases"}),H==="local"&&se.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx(_e,{config:e,appSlug:n,environment:H,seededUsers:se,authToken:h.token,refreshAuth:h.refreshNow,requestLogin:h.openLogin,tk:r,testRunId:g?.id||u,testRunToken:a,ticketId:c,targetUrl:Y,version:_,commitSha:C,prNumber:y,branchName:l,onAuthExpired:h.logout})}),jsx("button",{onClick:t=>{t.stopPropagation(),h.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(!g&&H==="local"&&!ge)return zt?jsx("div",{ref:le,style:{...p.root,left:b.x,top:b.y},children:jsxs("div",{style:p.card(240,false),children:[jsxs("div",{style:p.handle,onPointerDown:w,onPointerMove:z,onPointerUp:F,onClick:()=>{V.current||Te(false);},children:[jsx(S,{d:f.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:p.title,children:"BotBuddy"}),l&&jsx("div",{style:p.sub,children:jsxs("span",{children:["\u2387 ",l]})})]}),jsx(S,{d:f.chevronUp,className:""}),jsx("button",{style:p.btn,onClick:t=>{t.stopPropagation(),Te(false);},children:jsx(S,{d:f.minus,className:""})})]}),jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[se.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx(_e,{config:e,appSlug:n,environment:H,seededUsers:se,authToken:h.token,refreshAuth:h.refreshNow,requestLogin:h.openLogin,tk:r,testRunId:u,testRunToken:a,ticketId:c,targetUrl:Y,version:_,commitSha:C,prNumber:y,branchName:l,onAuthExpired:h.logout})}),jsx("button",{onClick:t=>{t.stopPropagation(),$t();},disabled:Ae,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${r.green}`,background:`${r.green}22`,color:r.green,cursor:Ae?"wait":"pointer",width:"100%"},children:Ae?"Creating...":"Create test run for this branch"}),ot&&jsx("div",{style:{fontSize:"9px",color:r.red,marginTop:"8px"},children:ot})]})]})}):jsx("div",{ref:le,style:{...p.root,left:b.x,top:b.y},children:jsxs("div",{style:{...p.pill(false),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:w,onPointerMove:z,onPointerUp:()=>{F(),V.current||Te(true);},children:[jsx(S,{d:f.grip,size:9,className:""}),jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),se.length>0&&jsx(_e,{config:e,appSlug:n,environment:H,seededUsers:se,authToken:h.token,refreshAuth:h.refreshNow,requestLogin:h.openLogin,tk:r,compact:true,onExpand:()=>Te(true),testRunId:u,testRunToken:a,ticketId:c,targetUrl:Y,version:_,commitSha:C,prNumber:y,branchName:l,onAuthExpired:h.logout})]})});let ct=()=>{V.current||(O(false),G(t=>{let d=t==="mini"?"max":"mini";return $(d==="mini"),d}));},ut=({icon:t,onClick:d})=>jsx("button",{style:p.btn,onClick:k=>{k.stopPropagation(),d(k);},children:jsx(S,{d:t,className:""})}),pt=()=>jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${r.borderSubtle}`,flexShrink:0},children:[g?.pr_url&&jsxs("a",{href:g.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...p.link(r.blue),textDecoration:"none"},children:[jsx(S,{d:f.pr,size:12}),g.pr_number?`PR#${g.pr_number}`:g.pr_id||"PR",jsx(S,{d:f.externalLink,size:8})]}),g?.ticket_url&&jsxs("a",{href:g.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...p.link(r.amber),textDecoration:"none"},children:[jsx(S,{d:f.ticket,size:12}),g.ticket_id||"Ticket",jsx(S,{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:{...p.link(r.purple),textDecoration:"none"},children:[jsx(S,{d:f.bot,size:12}),g.created_by_agent_name,jsx(S,{d:f.externalLink,size:8})]}):jsxs("span",{style:{...p.link(r.purple)},children:[jsx(S,{d:f.bot,size:12}),g.created_by_agent_name]})),H&&jsx(_e,{config:e,appSlug:n,environment:H,seededUsers:se,authToken:h.token,refreshAuth:h.refreshNow,requestLogin:h.openLogin,tk:r,testRunId:g?.id||u,testRunToken:a,ticketId:c,targetUrl:Y,version:_,commitSha:C,prNumber:y,branchName:l,onAuthExpired:h.logout}),jsx("span",{style:{...p.badge(g?.environment||"custom"),marginLeft:"auto"},children:g?.environment})]}),gt=()=>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("0.10.10");},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 ",jsx("span",{style:{color:r.versionNum},children:"v0.10.10"})]}),h.isAuthenticated&&jsx("button",{onClick:t=>{t.stopPropagation(),h.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:le,style:{...p.root,left:b.x,top:b.y},children:[J==="mini"&&jsxs("div",{style:{position:"relative"},onMouseEnter:()=>A(true),onMouseLeave:()=>{A(false),$(false),O(false);},children:[jsxs("div",{style:{...p.pill(fe),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:w,onPointerMove:z,onPointerUp:()=>{F(),V.current||ct();},children:[jsx(S,{d:f.grip,size:9,className:""}),g?.ticket_id&&jsx("span",{style:{color:r.amber,fontWeight:600},children:g.ticket_id}),g?.pr_number&&jsxs("span",{style:{color:r.blue,fontWeight:600},children:["PR#",g.pr_number]}),jsxs("span",{style:fe?{color:r.green}:void 0,children:[W.pass,"/",W.total]}),W.fail>0&&jsxs("span",{style:{color:r.red},children:[W.fail,"\u2717"]}),H&&jsx(_e,{config:e,appSlug:n,environment:H,seededUsers:se,authToken:h.token,refreshAuth:h.refreshNow,requestLogin:h.openLogin,tk:r,compact:true,onExpand:()=>G("expanded"),testRunId:g?.id||u,testRunToken:a,ticketId:c,targetUrl:Y,version:_,commitSha:C,prNumber:y,branchName:l,onAuthExpired:h.logout})]}),!j&&(ee||q)&&g?.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:g.title}),(g.description||g.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:g.description||g.intro_notes})]})]}),J==="expanded"&&jsxs("div",{style:p.card(300,fe),children:[jsxs("div",{style:p.handle,onPointerDown:w,onPointerMove:z,onPointerUp:F,onClick:ct,children:[jsx(S,{d:f.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:p.title,children:g?.title}),jsx("div",{style:p.sub,children:g?.branch_name&&jsxs("span",{children:["\u2387 ",g.branch_name]})})]}),jsx(S,{d:f.chevronUp,className:""}),jsx(ut,{icon:f.minus,onClick:()=>{O(false),$(true),G("mini");}})]}),jsxs("div",{style:p.stats,children:[jsxs("span",{style:{color:r.green},children:[W.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[W.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[W.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[W.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:W.total})]}),g?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:r.gripColor,borderBottom:`1px solid ${r.borderSubtle}`,flexShrink:0},children:g.description}),pt(),gt(),jsx("div",{style:p.progress,children:jsx("div",{style:p.progressBar(at)})})]}),J==="max"&&jsxs("div",{style:{...p.card(ve.w,fe),height:ve.h,position:"relative"},children:[jsxs("div",{style:p.handle,onPointerDown:w,onPointerMove:z,onPointerUp:F,onClick:()=>{V.current||G("expanded");},children:[jsx(S,{d:f.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:p.title,children:g?.title}),jsx("div",{style:p.sub,children:g?.branch_name&&jsxs("span",{children:["\u2387 ",g.branch_name]})})]}),jsx(S,{d:f.chevronDown,className:""}),jsx(ut,{icon:f.minus,onClick:()=>{O(false),$(true),G("mini");}})]}),jsxs("div",{style:p.stats,children:[jsxs("span",{style:{color:r.green},children:[W.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[W.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[W.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[W.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:W.total})]}),g?.intro_notes&&jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${r.borderSubtle}`,fontSize:"10px",color:r.textMuted,fontStyle:"italic",flexShrink:0},children:g.intro_notes}),(g?.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:f.search,size:11,className:""}),jsx("input",{value:m,onChange:t=>L(t.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:r.text,fontFamily:"monospace"}}),m&&jsx("button",{onClick:()=>L(""),style:{background:"none",border:"none",cursor:"pointer",color:r.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),de==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(S,{d:f.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:r.red},children:"Failed to load"}),jsx("button",{onClick:Pt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),fe&&jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg},children:[jsx(S,{d:f.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:r.green,flex:1},children:"Run completed"}),jsx("button",{onClick:Lt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),de!=="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:r.gripColor},children:"No test cases"}):Re.length===0?jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:['No matches for "',m,'"']}):st?st.map(t=>{let d=$e.has(t.key);return jsxs("div",{children:[jsxs("button",{onClick:()=>M(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:d?f.chevronDown:f.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})]}),!d&&t.cases.map(k=>dt(k))]},t.key)}):Re.map(t=>dt(t))}),Bt&&!fe&&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:Et,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"})]}),pt(),gt(),jsx("div",{style:p.progress,children:jsx("div",{style:p.progressBar(at)})}),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:Tt,onPointerMove:Ct,onPointerUp:Rt,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{we.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"})})})]})]})}
2
- export{an as TestRunWidget,Ne as useDraggable,Oe as useRealtimeRefresh,Ke as useTestRun,Ye as useWidgetAuth};
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
+ export{cn as TestRunWidget,Ve as useDraggable,Ye as useRealtimeRefresh,qe as useTestRun,et as useWidgetAuth};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botbuddy/react",
3
- "version": "0.10.11",
3
+ "version": "0.10.13",
4
4
  "description": "BotBuddy test coordination widgets for React — draggable, translucent overlays for human-in-the-loop QA",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",