@botbuddy/react 0.10.13 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/index.cjs +2 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @botbuddy/react — Changelog
|
|
2
2
|
|
|
3
|
+
## 0.11.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **The 2FA chip now lists every registered persona for the app + environment,
|
|
8
|
+
not just the `seed_user`s on the resolved run's cases (BOT-905).** The widget
|
|
9
|
+
fetches the full set of registered TOTP personas from a new
|
|
10
|
+
`GET /widget/totp-seeds` endpoint and merges them — deduped — with the
|
|
11
|
+
case-derived and local-file slugs. The chip therefore lights up (`2FA · N`)
|
|
12
|
+
even on a run with **zero** test cases, so a tester can mint an MFA code for
|
|
13
|
+
any seeded persona (e.g. `seed-vendor-admin@microsoft.seed.test`) without
|
|
14
|
+
first authoring throwaway cases that reference it. The fetch is gated to
|
|
15
|
+
authenticated, non-production requests; the raw `totp_secret` never crosses
|
|
16
|
+
the endpoint (only `seed_user_slug` + `expires_at`, expired rows filtered),
|
|
17
|
+
and production environments and hostnames are rejected server-side.
|
|
18
|
+
|
|
19
|
+
Consumers should mount the widget with the slug their seeds are keyed on
|
|
20
|
+
(Supply Guard: `appSlug="supplyspark-ent"`).
|
|
21
|
+
|
|
3
22
|
## 0.10.13
|
|
4
23
|
|
|
5
24
|
### 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 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=
|
|
1
|
+
'use strict';var react=require('react'),reactDom=require('react-dom'),jsxRuntime=require('react/jsx-runtime');var Se=8;function Ve(e,r,s,p,u,a){let T=Math.max(Se,u-s-Se),S=Math.max(Se,a-p-Se);return {x:Math.min(Math.max(e,Se),T),y:Math.min(Math.max(r,Se),S)}}function Ye(e,r){let[s,p]=react.useState({x:e,y:r}),u=react.useRef(false),a=react.useRef({x:0,y:0}),T=react.useRef(false),S=react.useCallback(y=>{u.current=true,T.current=false,a.current={x:y.clientX-s.x,y:y.clientY-s.y},y.target.setPointerCapture(y.pointerId);},[s]),_=react.useCallback(y=>{u.current&&(T.current=true,p({x:y.clientX-a.current.x,y:y.clientY-a.current.y}));},[]),b=react.useCallback(()=>{u.current=false;},[]);return {pos:s,setPos:p,onPointerDown:S,onPointerMove:_,onPointerUp:b,didDrag:T}}function Je(e,r,s){let p=react.useRef(s);p.current=s,react.useEffect(()=>{if(!r)return;if(e.supabaseUrl){let a=false,T=null,S=()=>{a||T||(T=setInterval(()=>p.current(),15e3));},_=null;try{let m=new URL(e.supabaseUrl),n=["localhost","127.0.0.1","::1"].includes(m.hostname);if(m.protocol==="http:"&&!n)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");m.protocol=m.protocol==="https:"?"wss:":"ws:",_=m.toString().replace(/\/$/,"");}catch{S();}let b=null,y=null,F=null,Y=0,M=()=>{if(!(a||!_)){try{b=new WebSocket(`${_}/realtime/v1/websocket?apikey=${e.anonKey}&vsn=1.0.0`);}catch{S();return}b.onopen=()=>{if(a||!b)return;let m={topic:`realtime:public:test_run_cases:test_run_id=eq.${r}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_run_cases",filter:`test_run_id=eq.${r}`}]}},ref:String(++Y)};b.send(JSON.stringify(m));let n={topic:`realtime:public:test_runs:id=eq.${r}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_runs",filter:`id=eq.${r}`}]}},ref:String(++Y)};b.send(JSON.stringify(n)),y=setInterval(()=>{b?.readyState===WebSocket.OPEN&&b.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++Y)}));},3e4);},b.onmessage=m=>{try{JSON.parse(m.data).event==="postgres_changes"&&p.current();}catch{}},b.onclose=()=>{x(),a||(F=setTimeout(M,3e3));},b.onerror=()=>{b?.close();};}},x=()=>{y&&(clearInterval(y),y=null);};return M(),()=>{a=true,x(),F&&clearTimeout(F),T&&clearInterval(T),b&&(b.onclose=null,b.onerror=null,b.close());}}let u=setInterval(()=>p.current(),15e3);return ()=>clearInterval(u)},[e.supabaseUrl,e.anonKey,r]);}var Vt="botbuddy:created-test-run:";function Yt(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function Jt(e){return `${Vt}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",Yt(e.targetUrl),e.branchName||""].join("|"))}`}function Ae(e,r){let s={apikey:e.anonKey};return r?s.Authorization=`Bearer ${r}`:e.apiKey?s.Authorization=`Bearer ${e.apiKey}`:s.Authorization=`Bearer ${e.anonKey}`,s}async function qt(e){if(e)return e;try{let r=await fetch("/.botbuddy-token",{cache:"no-store"});if(r.ok){let s=(await r.text()).trim();if(s.startsWith("public_"))return s}}catch{}try{let r=undefined?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(r&&typeof r=="string"&&r.startsWith("public_"))return r}catch{}return null}function Ge(e){let[r,s]=react.useState(null),[p,u]=react.useState("loading"),a=Jt(e),[T,S]=react.useState(()=>{if(e.testRunId)return e.testRunId;try{return localStorage.getItem(a)||void 0}catch{return}}),_=e.testRunId||T,b=react.useCallback(x=>{if(s(x),!!x?.id){S(x.id);try{localStorage.setItem(a,x.id);}catch{}}},[a]),y=react.useCallback(async()=>{try{let x=await qt(e.testRunToken);if(!x&&!_){u("no-match"),s(null);return}if(x&&!e.ticketId){u("no-match"),s(null);return}let m=new URLSearchParams;x&&m.set("token",x),e.ticketId&&m.set("ticket_id",e.ticketId),m.set("app_slug",e.appSlug),e.environment&&m.set("environment",e.environment),_&&m.set("test_run_id",_),e.targetUrl&&m.set("target_url",e.targetUrl),e.version&&m.set("version",e.version),e.commitSha&&m.set("commit_sha",e.commitSha),e.prNumber&&m.set("pr_number",String(e.prNumber)),e.branchName&&m.set("branch_name",e.branchName);let n=await fetch(`${e.config.serverUrl}/widget/test-run?${m.toString()}`,{headers:Ae(e.config,e.authToken)});if(n.status===404){u("no-match"),s(null);return}if(n.status===401||n.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),u("error");return}if(!n.ok){u("error");return}let d=await n.json();if(!d||d.run===null){u("no-match"),s(null);return}b(d),u(d.status==="completed"?"completed":"ready");}catch{u("error");}},[e.config.serverUrl,e.config.anonKey,e.config.apiKey,e.authToken,e.appSlug,e.environment,e.ticketId,_,e.testRunToken,e.targetUrl,e.version,e.commitSha,e.branchName,e.prNumber,e.onAuthExpired,b]);return react.useEffect(()=>{y();},[y]),Je(e.config,r?.id,y),{run:r,widgetState:p,fetchRun:y,setVerdict:async(x,m,n,d="human")=>(s(U=>{if(!U)return null;let J=U.test_cases.map(I=>I.id===x?{...I,verdict:m,fail_reason:m==="fail"&&n||null,verdict_by_display_name:d,verdict_at:new Date().toISOString()}:I),j={total:J.length,pending:0,pass:0,fail:0,skip:0};return J.forEach(I=>{I.verdict in j&&j[I.verdict]++;}),{...U,test_cases:J,summary:j}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${x}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...Ae(e.config,e.authToken)},body:JSON.stringify({verdict:m,fail_reason:n,display_name:d})})).ok),markComplete:async()=>r?(s(m=>m?{...m,status:"completed"}:null),u("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${r.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...Ae(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!r)return false;let x=await fetch(`${e.config.serverUrl}/widget/test-runs/${r.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...Ae(e.config,e.authToken)}});return x.ok&&y(),x.ok},setRun:b}}var Qe="botbuddy-widget-auth-token",et="botbuddy-widget-auth-name";function Re(e){if(!e)return null;try{let r=e.split(".")[1];if(!r)return null;let s=r.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(r.length/4)*4,"="),p=atob(s),u=JSON.parse(p);return typeof u.exp=="number"?u.exp*1e3:null}catch{return null}}var Xt=2500,Zt=6e4;function tt(e){let[r,s]=react.useState(()=>{try{return localStorage.getItem(Qe)}catch(M){return console.warn("Unable to read BotBuddy widget auth token",M),null}}),[p,u]=react.useState(()=>{try{return localStorage.getItem(et)}catch(M){return console.warn("Unable to read BotBuddy widget display name",M),null}}),a=react.useRef(null),T=react.useCallback((M,x)=>{s(M),x&&u(x);try{localStorage.setItem(Qe,M),x&&localStorage.setItem(et,x);}catch(m){console.warn("Unable to persist BotBuddy widget auth token",m);}},[]);react.useEffect(()=>{let M=new URL(e).origin,x=m=>{m.origin===M&&m.data?.type==="botbuddy-widget-auth"&&m.data.token&&T(m.data.token,m.data.displayName||"human");};return window.addEventListener("message",x),()=>window.removeEventListener("message",x)},[e,T]);let S=react.useCallback(()=>{if(a.current)return a.current;if(typeof window>"u"||typeof document>"u")return Promise.resolve(null);let M=new URL(e).origin,x=new URL("/widget-auth",e);x.searchParams.set("silent","1"),x.searchParams.set("origin",window.location.origin);let m=new Promise(n=>{let d=document.createElement("iframe");d.setAttribute("aria-hidden","true"),d.style.position="fixed",d.style.width="1px",d.style.height="1px",d.style.opacity="0",d.style.pointerEvents="none",d.style.border="0",d.style.left="-9999px",d.style.top="-9999px",d.src=x.toString();let V=false,U=()=>{window.removeEventListener("message",J),clearTimeout(j);try{d.remove();}catch{}a.current=null;},J=I=>{if(I.origin===M){if(I.data?.type==="botbuddy-widget-auth-failed"){if(V)return;V=true,n(null),U();return}I.data?.type!=="botbuddy-widget-auth"||!I.data.token||V||(V=true,n(String(I.data.token)),U());}},j=setTimeout(()=>{V||(V=true,n(null),U());},Xt);window.addEventListener("message",J),document.body.appendChild(d);});return a.current=m,m},[e]);react.useEffect(()=>{if(!r)return;let M=Re(r);if(!M)return;let x=M-Date.now()-Zt,m=window.setTimeout(()=>{S();},Math.max(0,x));return ()=>window.clearTimeout(m)},[r,S]);let _=react.useCallback(()=>{let M=new URL("/widget-auth",e);M.searchParams.set("origin",window.location.origin);let x=420,m=520,n=window.screenX+(window.innerWidth-x)/2,d=window.screenY+(window.innerHeight-m)/2;window.open(M.toString(),"botbuddy-auth",`width=${x},height=${m},left=${n},top=${d},popup=yes`);},[e]),[,b]=react.useState(0);react.useEffect(()=>{let M=Re(r);if(!M)return;let x=M-Date.now();if(x<=0)return;let m=window.setTimeout(()=>b(n=>n+1),x);return ()=>window.clearTimeout(m)},[r]);let y=react.useCallback(()=>{s(null),u(null);try{localStorage.removeItem(Qe),localStorage.removeItem(et);}catch(M){console.warn("Unable to clear BotBuddy widget auth token",M);}},[]),F=Re(r),Y=F!==null&&F<=Date.now();return {token:r,displayName:p,isAuthenticated:!!r,isExpired:Y,openLogin:_,refreshNow:S,logout:y}}var We=null;function Qt(){try{if(typeof document<"u"){let e=document.querySelector("base[href]");if(e)return new URL(".botbuddy-totp.json",e.href).toString()}}catch{}return "/.botbuddy-totp.json"}function Ie(){return We||(We=(async()=>{if(typeof fetch>"u")return null;try{let e=await fetch(Qt(),{cache:"no-store"});if(!e.ok)return null;let r=await e.json();if(!r||typeof r!="object"||Array.isArray(r))return null;let s={};for(let[p,u]of Object.entries(r))typeof u=="string"&&u.length>0&&(s[p]=u);return s}catch{return null}})(),We)}async function Mt(e){return (await Ie())?.[e]??null}function en(e){let r=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),s="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",p=[],u=0,a=0;for(let T of r){let S=s.indexOf(T);if(S<0)throw new Error("Invalid Base32 character in TOTP secret");a=a<<5|S,u+=5,u>=8&&(u-=8,p.push(a>>>u&255));}return Uint8Array.from(p)}async function Ct(e,r=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let s=en(e),p=new Uint8Array(s.byteLength);p.set(s);let u=Math.floor(r/1e3/30),a=new Uint8Array(8),T=Math.floor(u/4294967296),S=u>>>0;a[0]=T>>>24&255,a[1]=T>>>16&255,a[2]=T>>>8&255,a[3]=T&255,a[4]=S>>>24&255,a[5]=S>>>16&255,a[6]=S>>>8&255,a[7]=S&255;let _=await crypto.subtle.importKey("raw",p,{name:"HMAC",hash:"SHA-1"},false,["sign"]),b=await crypto.subtle.sign("HMAC",_,a),y=new Uint8Array(b),F=y[y.length-1]&15;return (((y[F]&127)<<24|(y[F+1]&255)<<16|(y[F+2]&255)<<8|y[F+3]&255)%1e6).toString().padStart(6,"0")}var Tt="0.11.0";function nn(e){let r=new Date(e),p=Date.now()-r.getTime();if(p<6e4)return "just now";if(p<36e5)return `${Math.floor(p/6e4)}m ago`;if(p<864e5)return `${Math.floor(p/36e5)}h ago`;let u=r.getDate(),a=r.toLocaleString("en",{month:"short"}),T=r.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${a} ${u}, ${T}`}var w=({d:e,className:r,size:s=14})=>jsxRuntime.jsx("svg",{className:r,width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:e})}),h={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01",bot:"M12 8V4H8M2 14h2M20 14h2M15 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M9 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M18 10a6 6 0 0 0-12 0v4a6 6 0 0 0 12 0Z",terminal:"M4 17l6-6-6-6M12 19h8",key:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4",shield:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10",copy:"M20 9h-9a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2-2v-9a2 2 0 0 0-2-2ZM5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1",search:"M11 17.25a6.25 6.25 0 1 1 0-12.5 6.25 6.25 0 0 1 0 12.5ZM16 16l4.5 4.5"};function rn(){let[e,r]=react.useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return react.useEffect(()=>{if(typeof window>"u")return;let s=document.documentElement,p=()=>s.classList.contains("dark")?"dark":s.classList.contains("light")?"light":null,u=p();u&&r(u);let a=window.matchMedia("(prefers-color-scheme: dark)"),T=_=>{let b=p();r(b||(_.matches?"dark":"light"));};a.addEventListener("change",T);let S=new MutationObserver(()=>{let _=p();r(_||(a.matches?"dark":"light"));});return S.observe(s,{attributes:true,attributeFilter:["class"]}),()=>{a.removeEventListener("change",T),S.disconnect();}},[]),e}function on(e){let r=e==="dark";return {bg:r?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:r?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:r?"#e5e5e5":"#1a1a1a",textMuted:r?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:r?"#555":"#999",border:r?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:r?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:r?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:r?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:r?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:r?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:r?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:r?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:r?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:r?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:r?"#888":"#aaa",btnHover:r?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var sn={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},an={pending:h.circle,pass:h.check,fail:h.x,skip:h.skip},Rt={local:{bg:"rgba(59,130,246,0.15)",text:"#60a5fa",border:"rgba(59,130,246,0.3)"},preview:{bg:"rgba(168,85,247,0.15)",text:"#c084fc",border:"rgba(168,85,247,0.3)"},staging:{bg:"rgba(245,158,11,0.15)",text:"#fbbf24",border:"rgba(245,158,11,0.3)"},production:{bg:"rgba(239,68,68,0.15)",text:"#f87171",border:"rgba(239,68,68,0.3)"},custom:{bg:"rgba(128,128,128,0.15)",text:"#888",border:"rgba(128,128,128,0.3)"}},ln=["app.supply-guard.io"];function dn(e,r=[]){if(!e)return false;let s=e.toLowerCase();return [...ln,...r].map(u=>u.toLowerCase()).includes(s)}var cn=e=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:r=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:e.bg,border:r?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:r?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(r,s)=>({width:`${r}px`,borderRadius:"8px",background:e.bg,border:s?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:s?`0 8px 24px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 8px 24px ${e.shadow}`,overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:`1px solid ${e.borderSubtle}`},title:{fontSize:"10px",fontWeight:600,color:e.text,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:e.textMuted,display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:e.gripColor,display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:`1px solid ${e.borderSubtle}`},badge:r=>{let s=Rt[r]||Rt.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:s.bg,color:s.text,border:`1px solid ${s.border}`,lineHeight:"14px"}},progress:{height:"2px",background:e.borderSubtle,flexShrink:0},progressBar:r=>({height:"100%",width:`${r}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:r=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${r}15`,color:r,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(r,s)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:r?`${s}33`:"transparent",color:r?s:e.gripColor,transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:e.inputBg,border:`1px solid ${e.inputBorder}`,borderRadius:"4px",padding:"2px 6px",color:e.text,outline:"none"},humanBanner:{padding:"6px 12px",fontSize:"11px",fontWeight:600,color:e.green,borderBottom:`1px solid ${e.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",background:e.greenBg,cursor:"pointer",textDecoration:"none"}});function nt(e){return e.split("/")[0].trim()}async function un(e){try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}try{if(typeof document>"u")return !1;let r=document.createElement("textarea");r.value=e,r.setAttribute("readonly",""),r.style.position="fixed",r.style.top="0",r.style.left="0",r.style.opacity="0",r.style.pointerEvents="none",document.body.appendChild(r),r.focus(),r.select(),r.setSelectionRange(0,e.length);let s=document.execCommand("copy");return document.body.removeChild(r),s}catch{return false}}function Pe({config:e,appSlug:r,environment:s,seededUsers:p,authToken:u,tk:a,compact:T=false,onExpand:S,onAuthExpired:_,refreshAuth:b,requestLogin:y,testRunId:F,testRunToken:Y,ticketId:M,targetUrl:x,version:m,commitSha:n,prNumber:d,branchName:V}){let[U,J]=react.useState(false),[j,I]=react.useState(null),[$,_e]=react.useState(null),[ie,g]=react.useState(null),[Ee,se]=react.useState(null),[te,G]=react.useState(null),[X,ae]=react.useState(null);react.useEffect(()=>{s==="local"&&Ie();},[s]);let me=react.useCallback(l=>{I(l),g(null),se(null),ae(null);let E=Re(u);if(s!=="local"&&y&&E!==null&&E<=Date.now()){G({slug:l,token:u||null}),ae(l),I(null),y();return}let R=C=>{g(C),se(l),window.setTimeout(()=>{se(P=>P===l?null:P),g(P=>P===C?null:P);},3e3);},k=new URLSearchParams({app_slug:r,seed_user_slug:l,environment:s});F&&k.set("test_run_id",F),Y&&k.set("public_token",Y),M&&k.set("ticket_id",M),x&&k.set("target_url",x),m&&k.set("version",m),n&&k.set("commit_sha",n),d&&k.set("pr_number",String(d)),V&&k.set("branch_name",V);let L=async C=>{let P={apikey:e.anonKey,Authorization:`Bearer ${C}`};try{let z=await fetch(`${e.serverUrl}/widget/totp-code?${k}`,{headers:P});if(!z.ok){let ge=await z.json().catch(()=>({error:`HTTP ${z.status}`}));return {ok:!1,status:z.status,error:ge.error||`HTTP ${z.status}`}}let q=await z.json();return {ok:!0,code:String(q.code)}}catch{return {ok:false,status:0,error:"Network error"}}},N=(async()=>{if(s==="local"){let z=await Mt(l);if(z)try{return {ok:!0,code:await Ct(z)}}catch{}}let C=await L(u||e.anonKey);if(C.ok||C.status!==401||!b)return C;let P=await b();return P?L(P):{ok:false,status:401,error:"Sign in to BotBuddy to refresh 2FA"}})(),A=null;try{if(typeof ClipboardItem<"u"&&navigator.clipboard?.write){let C=N.then(P=>{if(!P.ok)throw new Error(P.error);return new Blob([P.code],{type:"text/plain"})});A=navigator.clipboard.write([new ClipboardItem({"text/plain":C})]).then(()=>!0).catch(()=>!1);}}catch{}(async()=>{let C=await N;if(!C.ok){C.status===401?(G({slug:l,token:u||null}),ae(l)):R(C.status===404?"No 2FA seed registered":C.error),I(null);return}let P=A?await A:false,z=P?true:await un(C.code),q=P||z;_e({slug:l,code:C.code,copied:q}),window.setTimeout(()=>_e(ge=>ge?.slug===l?null:ge),q?2500:6e3),J(false),I(null);})();},[e.serverUrl,e.anonKey,u,r,s,F,Y,M,x,m,n,d,V,b,y]),re=react.useCallback(l=>{G({slug:l,token:u||null}),y?.();},[u,y]),ye=react.useCallback(l=>{X===l?re(l):me(l);},[X,re,me]);react.useEffect(()=>{if(!te||!u||u===te.token)return;let l=te.slug;G(null),me(l);},[u,me,te]);let xe=react.useRef(null),Me=react.useRef(null);if(react.useLayoutEffect(()=>{if(!U)return;let l=xe.current,E=Me.current;if(!l||!E||typeof window>"u")return;let R=()=>{let k=l.getBoundingClientRect(),L=E.getBoundingClientRect(),N=window.innerWidth,A=window.innerHeight,C=k.left,P=k.top-L.height-6;P<8&&(P=k.bottom+6);let z=Math.max(8,N-L.width-8),q=Math.max(8,A-L.height-8);C=Math.min(Math.max(C,8),z),P=Math.min(Math.max(P,8),q),E.style.left=`${Math.round(C)}px`,E.style.top=`${Math.round(P)}px`;};return R(),window.addEventListener("scroll",R,true),window.addEventListener("resize",R),()=>{window.removeEventListener("scroll",R,true),window.removeEventListener("resize",R);}},[U,p.length,ie]),react.useEffect(()=>{if(!U)return;let l=E=>{let R=E.target;Me.current?.contains(R)||xe.current?.contains(R)||J(false);};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[U]),p.length===0)return null;if(T){let l=p.length>1,E=p[0],R=!l&&X===E,k=z=>{if(z.stopPropagation(),l&&S){S();return}ye(E);},L=!!Ee,N=!!$,A=N&&$.copied,C=N&&!$.copied,P=R?a.blue:L?a.red:A?a.green:C?a.amber:a.purple;return jsxRuntime.jsxs("span",{onPointerDown:z=>z.stopPropagation(),onPointerUp:z=>z.stopPropagation(),onPointerMove:z=>z.stopPropagation(),onClick:k,style:{display:"inline-flex",alignItems:"center",gap:"3px",color:P,fontWeight:600,cursor:"pointer",letterSpacing:C?"0.08em":void 0},title:R?"Sign in to BotBuddy to refresh 2FA":L?ie||"Failed":C?`Clipboard blocked \u2014 code: ${$.code}`:l?`${p.length} 2FA personas`:`Copy 2FA code for ${p[0]}`,children:[jsxRuntime.jsx(w,{d:R?h.key:L?h.alert:A?h.check:C?h.copy:h.shield,size:10}),R?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Sign in"}):A?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Copied"}):C?jsxRuntime.jsx(jsxRuntime.Fragment,{children:$.code}):L?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Failed"}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["2FA",l&&` \xB7${p.length}`]})]})}if(p.length===1){let l=p[0],E=j===l,R=$?.slug===l,k=R&&$.copied,L=R&&!$.copied,N=Ee===l,A=X===l,C=A?a.blue:N?a.red:k?a.green:L?a.amber:a.purple;return jsxRuntime.jsxs("button",{onClick:P=>{P.stopPropagation(),ye(l);},disabled:E,style:{...Pt(C),cursor:E?"wait":"pointer",opacity:E?.6:1},title:A?"Sign in to BotBuddy to refresh 2FA":N?ie||"Failed":L?`Clipboard blocked \u2014 code: ${$.code}`:`Copy 2FA code for ${l}`,children:[jsxRuntime.jsx(w,{d:A?h.key:N?h.alert:k?h.check:L?h.copy:h.shield,size:12}),A?"Sign in":k?"Copied":L?$.code:N?"Failed":E?"\u2026":`2FA \xB7 ${l}`]})}let le=!!X&&!U,Z=!!Ee&&!U,be=!!$&&$.copied,ve=!!$&&!$.copied,De=le?a.blue:Z?a.red:be?a.green:ve?a.amber:a.purple,Fe=U&&typeof document<"u"?reactDom.createPortal(jsxRuntime.jsxs("div",{ref:Me,onPointerDown:l=>l.stopPropagation(),onMouseDown:l=>l.stopPropagation(),style:{position:"fixed",left:-9999,top:-9999,background:a.bg,border:`1px solid ${a.border}`,borderRadius:6,boxShadow:`0 8px 24px ${a.shadow}`,padding:4,minWidth:220,maxWidth:typeof window<"u"?Math.min(420,window.innerWidth-16):420,zIndex:1e5,fontFamily:"ui-monospace, SFMono-Regular, monospace"},children:[p.map(l=>{let E=j===l,R=X===l;return jsxRuntime.jsxs("button",{onClick:k=>{k.stopPropagation(),ye(l);},disabled:E,style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 8px",background:"transparent",border:"none",borderRadius:4,cursor:E?"wait":"pointer",fontSize:"10px",color:R?a.blue:a.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},title:R?"Sign in to BotBuddy to refresh 2FA":void 0,onMouseEnter:k=>k.currentTarget.style.background=a.btnHover,onMouseLeave:k=>k.currentTarget.style.background="transparent",children:[jsxRuntime.jsx(w,{d:R?h.key:h.shield,size:10}),jsxRuntime.jsx("span",{style:{flex:1,overflowWrap:"anywhere",lineHeight:1.3},children:l}),R?jsxRuntime.jsx("span",{style:{color:a.blue,fontSize:9},children:"Sign in"}):E?jsxRuntime.jsx("span",{style:{color:a.textMuted,fontSize:9},children:"\u2026"}):null]},l)}),ie&&jsxRuntime.jsx("div",{style:{padding:"4px 8px",fontSize:9,color:a.red},children:ie})]}),document.body):null;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("button",{ref:xe,onClick:l=>{if(l.stopPropagation(),le&&X){re(X);return}J(E=>!E),g(null),se(null);},style:{...Pt(De),cursor:"pointer"},title:le?"Sign in to BotBuddy to refresh 2FA":Z?ie||"Failed":ve?`Clipboard blocked \u2014 code: ${$.code}`:"Choose a persona to copy a 2FA code for",children:[jsxRuntime.jsx(w,{d:le?h.key:Z?h.alert:be?h.check:ve?h.copy:h.shield,size:12}),le?"Sign in":be?"Copied":ve?$.code:Z?"Failed":`2FA \xB7 ${p.length}`,!le&&jsxRuntime.jsx(w,{d:U?h.chevronUp:h.chevronDown,size:8})]}),Fe]})}function Pt(e){return {display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${e}15`,color:e,textDecoration:"none",border:`1px solid ${e}30`}}var Et="botbuddy-widget-state";function pn({config:e,appSlug:r,environment:s,ticketId:p,testRunId:u,testRunToken:a,targetUrl:T,version:S,commitSha:_,prNumber:b,branchName:y,onNavigate:F,displayName:Y="human",defaultMode:M="mini",defaultPosition:x}){let m=rn(),n=react.useMemo(()=>on(m),[m]),d=react.useMemo(()=>cn(n),[n]),[V,U]=react.useState(false),[J,j]=react.useState(false),[I,$]=react.useState(false),_e=react.useRef(false),ie=e.dashboardUrl||"https://app.bot-buddy.ai",g=tt(ie),se=(()=>{try{let t=typeof window<"u"?localStorage.getItem(Et):null;if(t)return JSON.parse(t)}catch{}return null})(),[te,G]=react.useState(se?.mode||M),[X,ae]=react.useState(""),[me,re]=react.useState(null),[ye,xe]=react.useState(null),[Me,le]=react.useState(new Set),[Z,be]=react.useState(""),ve=react.useCallback(t=>{le(c=>{let v=new Set(c);return v.has(t)?v.delete(t):v.add(t),v});},[]),De=se?.x??x?.x??16,Fe=se?.y??x?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:l,setPos:E,onPointerDown:R,onPointerMove:k,onPointerUp:L,didDrag:N}=Ye(De,Fe),A=react.useRef(null);react.useEffect(()=>{try{localStorage.setItem(Et,JSON.stringify({mode:te,x:l.x,y:l.y}));}catch{}},[te,l.x,l.y]),react.useLayoutEffect(()=>{if(typeof window>"u")return;let t=A.current;if(!t)return;let c=t.getBoundingClientRect(),v=Ve(l.x,l.y,c.width,c.height,window.innerWidth,window.innerHeight);(v.x!==l.x||v.y!==l.y)&&E(v);}),react.useEffect(()=>{if(typeof window>"u")return;let t=()=>{let c=A.current;if(!c)return;let v=c.getBoundingClientRect(),W=Ve(l.x,l.y,v.width,v.height,window.innerWidth,window.innerHeight);(W.x!==l.x||W.y!==l.y)&&E(W);};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[l.x,l.y,E]);let C=react.useRef(g.isAuthenticated);react.useEffect(()=>{!C.current&&g.isAuthenticated&&G("max"),C.current=g.isAuthenticated;},[g.isAuthenticated]);let P="botbuddy-widget-max-size",z=()=>{try{let t=localStorage.getItem(P);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[q,ge]=react.useState(z),Ce=react.useRef(false),Te=react.useRef({x:0,y:0,w:0,h:0}),Bt=react.useCallback(t=>{t.stopPropagation(),Ce.current=true,Te.current={x:t.clientX,y:t.clientY,w:q.w,h:q.h},t.target.setPointerCapture(t.pointerId);},[q]),zt=react.useCallback(t=>{if(!Ce.current)return;let c=Math.max(280,Math.min(600,Te.current.w+(t.clientX-Te.current.x))),v=Math.max(300,Math.min(window.innerHeight*.9,Te.current.h+(t.clientY-Te.current.y)));ge({w:c,h:v});},[]),$t=react.useCallback(()=>{Ce.current&&(Ce.current=false,ge(t=>(localStorage.setItem(P,JSON.stringify(t)),t)));},[]),Q=T??(typeof window<"u"?window.location.href:void 0),rt=g.displayName||Y,[oe,ot]=react.useState(null);react.useEffect(()=>{if(g.isAuthenticated)return;let t=new URLSearchParams;a&&t.set("token",a),p&&t.set("ticket_id",p),t.set("app_slug",r),s&&t.set("environment",s),u&&t.set("test_run_id",u),Q&&t.set("target_url",Q),S&&t.set("version",S),_&&t.set("commit_sha",_),b&&t.set("pr_number",String(b)),y&&t.set("branch_name",y),fetch(`${e.serverUrl}/widget/preview?${t}`,{headers:{apikey:e.anonKey}}).then(c=>c.json()).then(c=>ot(c)).catch(()=>ot(null));},[g.isAuthenticated,e.serverUrl,e.anonKey,r,s,p,u,a,Q,S,_,b,y]);let it=react.useRef(false),At=react.useCallback(()=>{it.current||g.logout();},[g.logout]),{run:f,widgetState:fe,fetchRun:Ut,setVerdict:st,markComplete:Wt,resetRun:It,setRun:at}=Ge({config:e,appSlug:r,environment:s,ticketId:p,testRunId:u,testRunToken:a,targetUrl:Q,version:S,commitSha:_,prNumber:b?String(b):void 0,branchName:y,authToken:g.token,onAuthExpired:At});it.current=!!f;let[lt,dt]=react.useState([]),[ct,Le]=react.useState([]),[Ne,ut]=react.useState(false),[pt,gt]=react.useState(null),[Dt,Be]=react.useState(false),de=dn(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);react.useEffect(()=>{if((s??"local")!=="local"||de){dt([]);return}let t=true;return Ie().then(c=>{t&&dt(Object.keys(c||{}));}),()=>{t=false;}},[s,de]);let Ft=react.useCallback(async()=>{if(!(!g.isAuthenticated||!g.token)){ut(true),gt(null);try{let t=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${g.token}`},body:JSON.stringify({app_slug:r,environment:s||"local",target_url:Q,branch_name:y,commit_sha:_,pr_number:b,ticket_id:p,title:`${p||r} local validation`})}),c=await t.json().catch(()=>({}));if(!t.ok)throw new Error(c.error||`HTTP ${t.status}`);at(c),G("max");}catch(t){gt(t.message);}finally{ut(false);}}},[g.isAuthenticated,g.token,e.serverUrl,e.anonKey,r,s,Q,y,_,b,p,at]),ze=react.useCallback(async(t,c,v)=>{xe(t);try{await st(t,c,v,rt);}finally{xe(null),re(null),ae("");}},[st,rt]),D=f?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},Nt=D.total>0&&D.pending===0,we=fe==="completed",$e=react.useMemo(()=>{let t=f?.test_cases||[];if(!Z.trim())return t;let c=Z.toLowerCase();return t.filter(v=>v.title.toLowerCase().includes(c)||v.description&&v.description.toLowerCase().includes(c)||v.url_path&&v.url_path.toLowerCase().includes(c)||v.seed_user&&v.seed_user.toLowerCase().includes(c))},[f?.test_cases,Z]),ft=react.useMemo(()=>{let t=$e,c=f?.test_cases||[];if(new Set(c.map(K=>K.source_pr_number)).size<=1)return null;let W=[],ue=new Map;t.forEach(K=>{let H=K.source_pr_number;ue.has(H)||ue.set(H,[]),ue.get(H).push(K);});let St=[...ue.keys()].sort((K,H)=>K===null?1:H===null?-1:H-K);for(let K of St){let H=ue.get(K),He={total:H.length,pass:0,fail:0,skip:0,pending:0};H.forEach(kt=>{kt.verdict in He&&He[kt.verdict]++;}),W.push({key:K!=null?`pr-${K}`:"general",label:K!=null?`PR #${K}`:"General",cases:H,summary:He});}return W.filter(K=>K.cases.length>0)},[$e,f?.test_cases]),ht=D.total>0?(D.pass+D.fail)/D.total*100:0,O=s??f?.environment??null,ce=react.useMemo(()=>{if(!O||O==="production"||de)return [];let t=f?.test_cases||[],c=new Set;for(let v of t)v.seed_user&&c.add(nt(v.seed_user));if(O==="local")for(let v of lt)c.add(nt(v));for(let v of ct)c.add(nt(v));return [...c]},[f?.test_cases,O,lt,ct,de]);react.useEffect(()=>{if(!O||O==="production"||de||!g.isAuthenticated||!g.token){Le([]);return}let t=true,c=`${e.serverUrl}/widget/totp-seeds?${new URLSearchParams({app_slug:r,environment:O})}`,v=W=>fetch(c,{headers:{apikey:e.anonKey,Authorization:`Bearer ${W}`}});return (async()=>{try{let W=await v(g.token);if(W.status===401&&g.refreshNow){let H=await g.refreshNow();H&&(W=await v(H));}if(!t)return;if(!W.ok){Le([]);return}let ue=await W.json().catch(()=>null),K=(Array.isArray(ue?.seeds)?ue.seeds:[]).map(H=>H?.seed_user_slug).filter(H=>typeof H=="string"&&H.length>0);Le(K);}catch{t&&Le([]);}})(),()=>{t=false;}},[O,de,g.isAuthenticated,g.token,g.refreshNow,r,e.serverUrl,e.anonKey]);let Oe=react.useMemo(()=>{let t=f?.auto_tooltip_seconds??oe?.auto_tooltip_seconds;return t!=null&&t>0?t*1e3:0},[f,oe]),mt=fe==="ready"||fe==="completed"||oe?.enabled&&oe.run;react.useEffect(()=>{if(!mt||_e.current||Oe<=0)return;_e.current=true,j(true);let t=window.setTimeout(()=>j(false),Oe);return ()=>window.clearTimeout(t)},[mt,Oe]);let yt=t=>jsxRuntime.jsxs("div",{style:d.caseRow,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsx("div",{style:{marginTop:"2px",flexShrink:0,color:sn[t.verdict]},children:ye===t.id?jsxRuntime.jsx(w,{d:h.loader,className:""}):jsxRuntime.jsx(w,{d:an[t.verdict],className:""})}),jsxRuntime.jsxs("div",{style:{minWidth:0,flex:1},children:[jsxRuntime.jsx("div",{style:{fontSize:"10px",color:n.text,lineHeight:1.3},children:t.title}),t.description&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:n.gripColor,marginTop:"2px"},children:t.description}),t.seed_user&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:n.amber,marginTop:"3px",display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",background:`${n.amber}12`,border:`1px solid ${n.amber}30`},children:[jsxRuntime.jsx(w,{d:h.key,size:10}),jsxRuntime.jsx("span",{children:t.seed_user})]}),t.url_path&&jsxRuntime.jsxs("a",{href:t.url_path,target:"_blank",rel:"noopener noreferrer",onClick:c=>{c.stopPropagation(),F&&(c.preventDefault(),F(t.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsxRuntime.jsx(w,{d:h.externalLink,size:10}),t.url_path]}),t.verdict==="fail"&&t.fail_reason&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:n.red,marginTop:"2px"},children:["\u2717 ",t.fail_reason]})]})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(c=>jsxRuntime.jsx("button",{onClick:()=>{if(t.verdict===c){ze(t.id,"pending"),re(null);return}if(c==="fail"){re(t.id),ae("");return}re(null),ze(t.id,c);},disabled:ye!==null,style:d.verdictBtn(t.verdict===c,c==="pass"?n.green:c==="fail"?n.red:n.amber),children:c.toUpperCase()},c)),t.created_by_agent_name&&jsxRuntime.jsxs("span",{style:{fontSize:"8px",color:n.purple,marginLeft:"4px",display:"inline-flex",alignItems:"center",gap:"2px"},children:[jsxRuntime.jsx(w,{d:h.bot,size:8}),t.created_by_agent_name]}),t.verdict_by_display_name&&jsxRuntime.jsxs("span",{style:{fontSize:"8px",color:n.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[t.verdict_by_display_name,t.verdict_at&&jsxRuntime.jsx("span",{style:{opacity:.7},children:nn(t.verdict_at)})]})]}),me===t.id&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:X,onChange:c=>ae(c.target.value),onKeyDown:c=>{c.key==="Enter"&&ze(t.id,"fail",X.trim()||void 0),c.key==="Escape"&&(re(null),ae(""));},placeholder:"Reason (optional)...",style:d.input}),jsxRuntime.jsx("button",{onClick:()=>{ze(t.id,"fail",X.trim()||void 0);},style:d.verdictBtn(true,n.red),children:"\u2713"})]})]},t.id);if((fe==="no-match"||fe==="loading")&&!(!g.isAuthenticated&&oe?.enabled&&oe.run)){if(!(O==="local"&&!de))return null}if(!g.isAuthenticated&&oe?.enabled&&oe.run){let t=oe.run,c=t.summary,v=t.status==="completed";return jsxRuntime.jsx("div",{ref:A,style:{...d.root,left:l.x,top:l.y},children:jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>U(true),onMouseLeave:()=>{U(false),$(false),j(false);},children:[jsxRuntime.jsxs("div",{style:{...d.pill(v),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:R,onPointerMove:k,onPointerUp:()=>{L();},children:[jsxRuntime.jsx(w,{d:h.grip,size:10,className:""}),t.ticket_id&&t.ticket_url?jsxRuntime.jsx("a",{href:t.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:n.amber,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:t.ticket_id}):null,t.pr_url?jsxRuntime.jsxs("a",{href:t.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:n.blue,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:["PR#",t.pr_number??t.pr_id]}):null,t.created_by_agent_name?t.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${t.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:n.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(w,{d:h.terminal,size:10}),t.created_by_agent_name]}):jsxRuntime.jsxs("span",{style:{color:n.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(w,{d:h.bot,size:10}),t.created_by_agent_name]}):null,jsxRuntime.jsxs("span",{style:v?{color:n.green}:void 0,children:[c.pass,"/",c.total]}),c.fail>0&&jsxRuntime.jsxs("span",{style:{color:n.red},children:[c.fail,"\u2717"]}),jsxRuntime.jsx("span",{onClick:W=>{W.stopPropagation(),g.openLogin();},style:{color:n.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!I&&(V||J)&&t.title&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsxRuntime.jsx("div",{style:{fontSize:"11px",fontWeight:700,color:n.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:t.title}),(t.description||t.intro_notes)&&jsxRuntime.jsx("div",{style:{fontSize:"10px",color:n.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:t.description||t.intro_notes}),jsxRuntime.jsx("div",{style:{marginTop:"4px",fontSize:"9px",color:n.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!g.isAuthenticated)return jsxRuntime.jsxs("div",{ref:A,style:{...d.root,left:l.x,top:l.y,width:220,minHeight:0,cursor:"move",userSelect:"none",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`},onPointerDown:R,onPointerMove:k,onPointerUp:L,children:[jsxRuntime.jsx("div",{style:{...d.handle,borderBottom:"none"},children:jsxRuntime.jsxs("div",{style:d.sub,children:[jsxRuntime.jsx(w,{d:h.grip,size:10,className:""}),jsxRuntime.jsx(w,{d:h.clipboard,size:12,className:""}),jsxRuntime.jsx("span",{style:{fontWeight:600},children:"BotBuddy"})]})}),jsxRuntime.jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[jsxRuntime.jsx("div",{style:{fontSize:"9px",color:n.textMuted,marginBottom:"8px"},children:"Sign in to access test cases"}),O==="local"&&ce.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsxRuntime.jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,testRunId:f?.id||u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout})}),jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),g.openLogin();},style:{fontSize:"10px",fontWeight:600,padding:"6px 16px",borderRadius:"6px",border:`1px solid ${n.green}`,background:`${n.green}22`,color:n.green,cursor:"pointer",width:"100%"},children:"Sign in to test"})]})]});if(!f&&O==="local"&&!de)return Dt?jsxRuntime.jsx("div",{ref:A,style:{...d.root,left:l.x,top:l.y},children:jsxRuntime.jsxs("div",{style:d.card(240,false),children:[jsxRuntime.jsxs("div",{style:d.handle,onPointerDown:R,onPointerMove:k,onPointerUp:L,onClick:()=>{N.current||Be(false);},children:[jsxRuntime.jsx(w,{d:h.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:d.title,children:"BotBuddy"}),y&&jsxRuntime.jsx("div",{style:d.sub,children:jsxRuntime.jsxs("span",{children:["\u2387 ",y]})})]}),jsxRuntime.jsx(w,{d:h.chevronUp,className:""}),jsxRuntime.jsx("button",{style:d.btn,onClick:t=>{t.stopPropagation(),Be(false);},children:jsxRuntime.jsx(w,{d:h.minus,className:""})})]}),jsxRuntime.jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[ce.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsxRuntime.jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,testRunId:u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout})}),jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),Ft();},disabled:Ne,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${n.green}`,background:`${n.green}22`,color:n.green,cursor:Ne?"wait":"pointer",width:"100%"},children:Ne?"Creating...":"Create test run for this branch"}),pt&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:n.red,marginTop:"8px"},children:pt})]})]})}):jsxRuntime.jsx("div",{ref:A,style:{...d.root,left:l.x,top:l.y},children:jsxRuntime.jsxs("div",{style:{...d.pill(false),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:R,onPointerMove:k,onPointerUp:()=>{L(),N.current||Be(true);},children:[jsxRuntime.jsx(w,{d:h.grip,size:9,className:""}),jsxRuntime.jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),ce.length>0&&jsxRuntime.jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,compact:true,onExpand:()=>Be(true),testRunId:u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout})]})});let xt=()=>{N.current||(j(false),G(t=>{let c=t==="mini"?"max":"mini";return $(c==="mini"),c}));},bt=({icon:t,onClick:c})=>jsxRuntime.jsx("button",{style:d.btn,onClick:v=>{v.stopPropagation(),c(v);},children:jsxRuntime.jsx(w,{d:t,className:""})}),vt=()=>jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${n.borderSubtle}`,flexShrink:0},children:[f?.pr_url&&jsxRuntime.jsxs("a",{href:f.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.blue),textDecoration:"none"},children:[jsxRuntime.jsx(w,{d:h.pr,size:12}),f.pr_number?`PR#${f.pr_number}`:f.pr_id||"PR",jsxRuntime.jsx(w,{d:h.externalLink,size:8})]}),f?.ticket_url&&jsxRuntime.jsxs("a",{href:f.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.amber),textDecoration:"none"},children:[jsxRuntime.jsx(w,{d:h.ticket,size:12}),f.ticket_id||"Ticket",jsxRuntime.jsx(w,{d:h.externalLink,size:8})]}),f?.created_by_agent_name&&(f.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${f.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.purple),textDecoration:"none"},children:[jsxRuntime.jsx(w,{d:h.bot,size:12}),f.created_by_agent_name,jsxRuntime.jsx(w,{d:h.externalLink,size:8})]}):jsxRuntime.jsxs("span",{style:{...d.link(n.purple)},children:[jsxRuntime.jsx(w,{d:h.bot,size:12}),f.created_by_agent_name]})),O&&jsxRuntime.jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,testRunId:f?.id||u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout}),jsxRuntime.jsx("span",{style:{...d.badge(f?.environment||"custom"),marginLeft:"auto"},children:f?.environment})]}),wt=()=>jsxRuntime.jsxs("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:`1px solid ${n.borderSubtle}`,background:n.bgSoft,flexShrink:0},children:[jsxRuntime.jsxs("button",{onClick:()=>{navigator.clipboard.writeText(Tt);},style:{fontSize:"9px",fontWeight:600,color:n.versionText,letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxRuntime.jsxs("span",{style:{color:n.versionNum},children:["v",Tt]})]}),g.isAuthenticated&&(g.isExpired?jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),g.openLogin();},style:{fontSize:"8px",color:n.blue,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Widget session expired \u2014 sign in to refresh",children:"sign in"}):jsxRuntime.jsx("button",{onClick:t=>{t.stopPropagation(),g.logout();},style:{fontSize:"8px",color:n.textFaint,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Sign out of widget",children:"sign out"}))]});return jsxRuntime.jsxs("div",{ref:A,style:{...d.root,left:l.x,top:l.y},children:[te==="mini"&&jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>U(true),onMouseLeave:()=>{U(false),$(false),j(false);},children:[jsxRuntime.jsxs("div",{style:{...d.pill(we),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:R,onPointerMove:k,onPointerUp:()=>{L(),N.current||xt();},children:[jsxRuntime.jsx(w,{d:h.grip,size:9,className:""}),f?.ticket_id&&jsxRuntime.jsx("span",{style:{color:n.amber,fontWeight:600},children:f.ticket_id}),f?.pr_number&&jsxRuntime.jsxs("span",{style:{color:n.blue,fontWeight:600},children:["PR#",f.pr_number]}),jsxRuntime.jsxs("span",{style:we?{color:n.green}:void 0,children:[D.pass,"/",D.total]}),D.fail>0&&jsxRuntime.jsxs("span",{style:{color:n.red},children:[D.fail,"\u2717"]}),O&&jsxRuntime.jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,compact:true,onExpand:()=>G("expanded"),testRunId:f?.id||u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout})]}),!I&&(V||J)&&f?.title&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsxRuntime.jsx("div",{style:{fontSize:"11px",fontWeight:700,color:n.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:f.title}),(f.description||f.intro_notes)&&jsxRuntime.jsx("div",{style:{fontSize:"10px",color:n.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:f.description||f.intro_notes})]})]}),te==="expanded"&&jsxRuntime.jsxs("div",{style:d.card(300,we),children:[jsxRuntime.jsxs("div",{style:d.handle,onPointerDown:R,onPointerMove:k,onPointerUp:L,onClick:xt,children:[jsxRuntime.jsx(w,{d:h.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:d.title,children:f?.title}),jsxRuntime.jsx("div",{style:d.sub,children:f?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",f.branch_name]})})]}),jsxRuntime.jsx(w,{d:h.chevronUp,className:""}),jsxRuntime.jsx(bt,{icon:h.minus,onClick:()=>{j(false),$(true),G("mini");}})]}),jsxRuntime.jsxs("div",{style:d.stats,children:[jsxRuntime.jsxs("span",{style:{color:n.green},children:[D.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:n.red},children:[D.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:n.amber},children:[D.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:n.gripColor},children:[D.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:D.total})]}),f?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:n.gripColor,borderBottom:`1px solid ${n.borderSubtle}`,flexShrink:0},children:f.description}),vt(),wt(),jsxRuntime.jsx("div",{style:d.progress,children:jsxRuntime.jsx("div",{style:d.progressBar(ht)})})]}),te==="max"&&jsxRuntime.jsxs("div",{style:{...d.card(q.w,we),height:q.h,position:"relative"},children:[jsxRuntime.jsxs("div",{style:d.handle,onPointerDown:R,onPointerMove:k,onPointerUp:L,onClick:()=>{N.current||G("expanded");},children:[jsxRuntime.jsx(w,{d:h.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:d.title,children:f?.title}),jsxRuntime.jsx("div",{style:d.sub,children:f?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",f.branch_name]})})]}),jsxRuntime.jsx(w,{d:h.chevronDown,className:""}),jsxRuntime.jsx(bt,{icon:h.minus,onClick:()=>{j(false),$(true),G("mini");}})]}),jsxRuntime.jsxs("div",{style:d.stats,children:[jsxRuntime.jsxs("span",{style:{color:n.green},children:[D.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:n.red},children:[D.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:n.amber},children:[D.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:n.gripColor},children:[D.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:D.total})]}),f?.intro_notes&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${n.borderSubtle}`,fontSize:"10px",color:n.textMuted,fontStyle:"italic",flexShrink:0},children:f.intro_notes}),(f?.test_cases||[]).length>5&&jsxRuntime.jsxs("div",{style:{padding:"4px 12px",borderBottom:`1px solid ${n.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[jsxRuntime.jsx(w,{d:h.search,size:11,className:""}),jsxRuntime.jsx("input",{value:Z,onChange:t=>be(t.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:n.text,fontFamily:"monospace"}}),Z&&jsxRuntime.jsx("button",{onClick:()=>be(""),style:{background:"none",border:"none",cursor:"pointer",color:n.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),fe==="error"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsxRuntime.jsx(w,{d:h.alert,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:n.red},children:"Failed to load"}),jsxRuntime.jsx("button",{onClick:Ut,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),we&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg},children:[jsxRuntime.jsx(w,{d:h.checkAll,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",color:n.green,flex:1},children:"Run completed"}),jsxRuntime.jsx("button",{onClick:It,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),fe!=="error"&&jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(f?.test_cases||[]).length===0?jsxRuntime.jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:"No test cases"}):$e.length===0?jsxRuntime.jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:['No matches for "',Z,'"']}):ft?ft.map(t=>{let c=Me.has(t.key);return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>ve(t.key),style:{width:"100%",display:"flex",alignItems:"center",gap:"6px",padding:"5px 12px",background:n.bgSoft,cursor:"pointer",border:"none",borderLeft:"none",borderRight:"none",borderBottomStyle:"solid",borderTopStyle:"solid",borderBottomWidth:"1px",borderTopWidth:"1px",borderBottomColor:n.borderSubtle,borderTopColor:n.borderSubtle,backgroundColor:n.bgSoft},children:[jsxRuntime.jsx(w,{d:c?h.chevronDown:h.chevronUp,size:10,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",fontWeight:700,color:n.blue,flex:1,textAlign:"left"},children:t.label}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:n.green},children:[t.summary.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:n.red},children:[t.summary.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:n.gripColor},children:[t.summary.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{fontSize:"9px",color:n.textFaint},children:t.summary.total})]}),!c&&t.cases.map(v=>yt(v))]},t.key)}):$e.map(t=>yt(t))}),Nt&&!we&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",borderTop:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg,display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsxRuntime.jsx("span",{style:{fontSize:"9px",color:n.green},children:"All resolved"}),jsxRuntime.jsx("button",{onClick:Wt,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:n.green,border:`1px solid ${n.greenBorderSubtle}`,cursor:"pointer"},children:"COMPLETE"})]}),vt(),wt(),jsxRuntime.jsx("div",{style:d.progress,children:jsxRuntime.jsx("div",{style:d.progressBar(ht)})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:0,right:0,width:16,height:16,cursor:"se-resize",zIndex:10,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:"2px",opacity:.3},onPointerDown:Bt,onPointerMove:zt,onPointerUp:$t,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{Ce.current||(t.currentTarget.style.opacity="0.3");},children:jsxRuntime.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsxRuntime.jsx("path",{d:"M7 1v6H1",fill:"none",stroke:n.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}
|
|
2
|
+
exports.TestRunWidget=pn;exports.useDraggable=Ye;exports.useRealtimeRefresh=Je;exports.useTestRun=Ge;exports.useWidgetAuth=tt;
|
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 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{
|
|
1
|
+
import {useState,useRef,useCallback,useEffect,useMemo,useLayoutEffect}from'react';import {createPortal}from'react-dom';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Se=8;function Ve(e,r,s,p,u,a){let T=Math.max(Se,u-s-Se),S=Math.max(Se,a-p-Se);return {x:Math.min(Math.max(e,Se),T),y:Math.min(Math.max(r,Se),S)}}function Ye(e,r){let[s,p]=useState({x:e,y:r}),u=useRef(false),a=useRef({x:0,y:0}),T=useRef(false),S=useCallback(y=>{u.current=true,T.current=false,a.current={x:y.clientX-s.x,y:y.clientY-s.y},y.target.setPointerCapture(y.pointerId);},[s]),_=useCallback(y=>{u.current&&(T.current=true,p({x:y.clientX-a.current.x,y:y.clientY-a.current.y}));},[]),b=useCallback(()=>{u.current=false;},[]);return {pos:s,setPos:p,onPointerDown:S,onPointerMove:_,onPointerUp:b,didDrag:T}}function Je(e,r,s){let p=useRef(s);p.current=s,useEffect(()=>{if(!r)return;if(e.supabaseUrl){let a=false,T=null,S=()=>{a||T||(T=setInterval(()=>p.current(),15e3));},_=null;try{let m=new URL(e.supabaseUrl),n=["localhost","127.0.0.1","::1"].includes(m.hostname);if(m.protocol==="http:"&&!n)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");m.protocol=m.protocol==="https:"?"wss:":"ws:",_=m.toString().replace(/\/$/,"");}catch{S();}let b=null,y=null,F=null,Y=0,M=()=>{if(!(a||!_)){try{b=new WebSocket(`${_}/realtime/v1/websocket?apikey=${e.anonKey}&vsn=1.0.0`);}catch{S();return}b.onopen=()=>{if(a||!b)return;let m={topic:`realtime:public:test_run_cases:test_run_id=eq.${r}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_run_cases",filter:`test_run_id=eq.${r}`}]}},ref:String(++Y)};b.send(JSON.stringify(m));let n={topic:`realtime:public:test_runs:id=eq.${r}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_runs",filter:`id=eq.${r}`}]}},ref:String(++Y)};b.send(JSON.stringify(n)),y=setInterval(()=>{b?.readyState===WebSocket.OPEN&&b.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++Y)}));},3e4);},b.onmessage=m=>{try{JSON.parse(m.data).event==="postgres_changes"&&p.current();}catch{}},b.onclose=()=>{x(),a||(F=setTimeout(M,3e3));},b.onerror=()=>{b?.close();};}},x=()=>{y&&(clearInterval(y),y=null);};return M(),()=>{a=true,x(),F&&clearTimeout(F),T&&clearInterval(T),b&&(b.onclose=null,b.onerror=null,b.close());}}let u=setInterval(()=>p.current(),15e3);return ()=>clearInterval(u)},[e.supabaseUrl,e.anonKey,r]);}var Vt="botbuddy:created-test-run:";function Yt(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function Jt(e){return `${Vt}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",Yt(e.targetUrl),e.branchName||""].join("|"))}`}function Ae(e,r){let s={apikey:e.anonKey};return r?s.Authorization=`Bearer ${r}`:e.apiKey?s.Authorization=`Bearer ${e.apiKey}`:s.Authorization=`Bearer ${e.anonKey}`,s}async function qt(e){if(e)return e;try{let r=await fetch("/.botbuddy-token",{cache:"no-store"});if(r.ok){let s=(await r.text()).trim();if(s.startsWith("public_"))return s}}catch{}try{let r=import.meta?.env?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(r&&typeof r=="string"&&r.startsWith("public_"))return r}catch{}return null}function Ge(e){let[r,s]=useState(null),[p,u]=useState("loading"),a=Jt(e),[T,S]=useState(()=>{if(e.testRunId)return e.testRunId;try{return localStorage.getItem(a)||void 0}catch{return}}),_=e.testRunId||T,b=useCallback(x=>{if(s(x),!!x?.id){S(x.id);try{localStorage.setItem(a,x.id);}catch{}}},[a]),y=useCallback(async()=>{try{let x=await qt(e.testRunToken);if(!x&&!_){u("no-match"),s(null);return}if(x&&!e.ticketId){u("no-match"),s(null);return}let m=new URLSearchParams;x&&m.set("token",x),e.ticketId&&m.set("ticket_id",e.ticketId),m.set("app_slug",e.appSlug),e.environment&&m.set("environment",e.environment),_&&m.set("test_run_id",_),e.targetUrl&&m.set("target_url",e.targetUrl),e.version&&m.set("version",e.version),e.commitSha&&m.set("commit_sha",e.commitSha),e.prNumber&&m.set("pr_number",String(e.prNumber)),e.branchName&&m.set("branch_name",e.branchName);let n=await fetch(`${e.config.serverUrl}/widget/test-run?${m.toString()}`,{headers:Ae(e.config,e.authToken)});if(n.status===404){u("no-match"),s(null);return}if(n.status===401||n.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),u("error");return}if(!n.ok){u("error");return}let d=await n.json();if(!d||d.run===null){u("no-match"),s(null);return}b(d),u(d.status==="completed"?"completed":"ready");}catch{u("error");}},[e.config.serverUrl,e.config.anonKey,e.config.apiKey,e.authToken,e.appSlug,e.environment,e.ticketId,_,e.testRunToken,e.targetUrl,e.version,e.commitSha,e.branchName,e.prNumber,e.onAuthExpired,b]);return useEffect(()=>{y();},[y]),Je(e.config,r?.id,y),{run:r,widgetState:p,fetchRun:y,setVerdict:async(x,m,n,d="human")=>(s(U=>{if(!U)return null;let J=U.test_cases.map(I=>I.id===x?{...I,verdict:m,fail_reason:m==="fail"&&n||null,verdict_by_display_name:d,verdict_at:new Date().toISOString()}:I),j={total:J.length,pending:0,pass:0,fail:0,skip:0};return J.forEach(I=>{I.verdict in j&&j[I.verdict]++;}),{...U,test_cases:J,summary:j}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${x}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...Ae(e.config,e.authToken)},body:JSON.stringify({verdict:m,fail_reason:n,display_name:d})})).ok),markComplete:async()=>r?(s(m=>m?{...m,status:"completed"}:null),u("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${r.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...Ae(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!r)return false;let x=await fetch(`${e.config.serverUrl}/widget/test-runs/${r.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...Ae(e.config,e.authToken)}});return x.ok&&y(),x.ok},setRun:b}}var Qe="botbuddy-widget-auth-token",et="botbuddy-widget-auth-name";function Re(e){if(!e)return null;try{let r=e.split(".")[1];if(!r)return null;let s=r.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(r.length/4)*4,"="),p=atob(s),u=JSON.parse(p);return typeof u.exp=="number"?u.exp*1e3:null}catch{return null}}var Xt=2500,Zt=6e4;function tt(e){let[r,s]=useState(()=>{try{return localStorage.getItem(Qe)}catch(M){return console.warn("Unable to read BotBuddy widget auth token",M),null}}),[p,u]=useState(()=>{try{return localStorage.getItem(et)}catch(M){return console.warn("Unable to read BotBuddy widget display name",M),null}}),a=useRef(null),T=useCallback((M,x)=>{s(M),x&&u(x);try{localStorage.setItem(Qe,M),x&&localStorage.setItem(et,x);}catch(m){console.warn("Unable to persist BotBuddy widget auth token",m);}},[]);useEffect(()=>{let M=new URL(e).origin,x=m=>{m.origin===M&&m.data?.type==="botbuddy-widget-auth"&&m.data.token&&T(m.data.token,m.data.displayName||"human");};return window.addEventListener("message",x),()=>window.removeEventListener("message",x)},[e,T]);let S=useCallback(()=>{if(a.current)return a.current;if(typeof window>"u"||typeof document>"u")return Promise.resolve(null);let M=new URL(e).origin,x=new URL("/widget-auth",e);x.searchParams.set("silent","1"),x.searchParams.set("origin",window.location.origin);let m=new Promise(n=>{let d=document.createElement("iframe");d.setAttribute("aria-hidden","true"),d.style.position="fixed",d.style.width="1px",d.style.height="1px",d.style.opacity="0",d.style.pointerEvents="none",d.style.border="0",d.style.left="-9999px",d.style.top="-9999px",d.src=x.toString();let V=false,U=()=>{window.removeEventListener("message",J),clearTimeout(j);try{d.remove();}catch{}a.current=null;},J=I=>{if(I.origin===M){if(I.data?.type==="botbuddy-widget-auth-failed"){if(V)return;V=true,n(null),U();return}I.data?.type!=="botbuddy-widget-auth"||!I.data.token||V||(V=true,n(String(I.data.token)),U());}},j=setTimeout(()=>{V||(V=true,n(null),U());},Xt);window.addEventListener("message",J),document.body.appendChild(d);});return a.current=m,m},[e]);useEffect(()=>{if(!r)return;let M=Re(r);if(!M)return;let x=M-Date.now()-Zt,m=window.setTimeout(()=>{S();},Math.max(0,x));return ()=>window.clearTimeout(m)},[r,S]);let _=useCallback(()=>{let M=new URL("/widget-auth",e);M.searchParams.set("origin",window.location.origin);let x=420,m=520,n=window.screenX+(window.innerWidth-x)/2,d=window.screenY+(window.innerHeight-m)/2;window.open(M.toString(),"botbuddy-auth",`width=${x},height=${m},left=${n},top=${d},popup=yes`);},[e]),[,b]=useState(0);useEffect(()=>{let M=Re(r);if(!M)return;let x=M-Date.now();if(x<=0)return;let m=window.setTimeout(()=>b(n=>n+1),x);return ()=>window.clearTimeout(m)},[r]);let y=useCallback(()=>{s(null),u(null);try{localStorage.removeItem(Qe),localStorage.removeItem(et);}catch(M){console.warn("Unable to clear BotBuddy widget auth token",M);}},[]),F=Re(r),Y=F!==null&&F<=Date.now();return {token:r,displayName:p,isAuthenticated:!!r,isExpired:Y,openLogin:_,refreshNow:S,logout:y}}var We=null;function Qt(){try{if(typeof document<"u"){let e=document.querySelector("base[href]");if(e)return new URL(".botbuddy-totp.json",e.href).toString()}}catch{}return "/.botbuddy-totp.json"}function Ie(){return We||(We=(async()=>{if(typeof fetch>"u")return null;try{let e=await fetch(Qt(),{cache:"no-store"});if(!e.ok)return null;let r=await e.json();if(!r||typeof r!="object"||Array.isArray(r))return null;let s={};for(let[p,u]of Object.entries(r))typeof u=="string"&&u.length>0&&(s[p]=u);return s}catch{return null}})(),We)}async function Mt(e){return (await Ie())?.[e]??null}function en(e){let r=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),s="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",p=[],u=0,a=0;for(let T of r){let S=s.indexOf(T);if(S<0)throw new Error("Invalid Base32 character in TOTP secret");a=a<<5|S,u+=5,u>=8&&(u-=8,p.push(a>>>u&255));}return Uint8Array.from(p)}async function Ct(e,r=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let s=en(e),p=new Uint8Array(s.byteLength);p.set(s);let u=Math.floor(r/1e3/30),a=new Uint8Array(8),T=Math.floor(u/4294967296),S=u>>>0;a[0]=T>>>24&255,a[1]=T>>>16&255,a[2]=T>>>8&255,a[3]=T&255,a[4]=S>>>24&255,a[5]=S>>>16&255,a[6]=S>>>8&255,a[7]=S&255;let _=await crypto.subtle.importKey("raw",p,{name:"HMAC",hash:"SHA-1"},false,["sign"]),b=await crypto.subtle.sign("HMAC",_,a),y=new Uint8Array(b),F=y[y.length-1]&15;return (((y[F]&127)<<24|(y[F+1]&255)<<16|(y[F+2]&255)<<8|y[F+3]&255)%1e6).toString().padStart(6,"0")}var Tt="0.11.0";function nn(e){let r=new Date(e),p=Date.now()-r.getTime();if(p<6e4)return "just now";if(p<36e5)return `${Math.floor(p/6e4)}m ago`;if(p<864e5)return `${Math.floor(p/36e5)}h ago`;let u=r.getDate(),a=r.toLocaleString("en",{month:"short"}),T=r.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${a} ${u}, ${T}`}var w=({d:e,className:r,size:s=14})=>jsx("svg",{className:r,width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:e})}),h={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01",bot:"M12 8V4H8M2 14h2M20 14h2M15 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M9 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M18 10a6 6 0 0 0-12 0v4a6 6 0 0 0 12 0Z",terminal:"M4 17l6-6-6-6M12 19h8",key:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4",shield:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10",copy:"M20 9h-9a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2-2v-9a2 2 0 0 0-2-2ZM5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1",search:"M11 17.25a6.25 6.25 0 1 1 0-12.5 6.25 6.25 0 0 1 0 12.5ZM16 16l4.5 4.5"};function rn(){let[e,r]=useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return useEffect(()=>{if(typeof window>"u")return;let s=document.documentElement,p=()=>s.classList.contains("dark")?"dark":s.classList.contains("light")?"light":null,u=p();u&&r(u);let a=window.matchMedia("(prefers-color-scheme: dark)"),T=_=>{let b=p();r(b||(_.matches?"dark":"light"));};a.addEventListener("change",T);let S=new MutationObserver(()=>{let _=p();r(_||(a.matches?"dark":"light"));});return S.observe(s,{attributes:true,attributeFilter:["class"]}),()=>{a.removeEventListener("change",T),S.disconnect();}},[]),e}function on(e){let r=e==="dark";return {bg:r?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:r?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:r?"#e5e5e5":"#1a1a1a",textMuted:r?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:r?"#555":"#999",border:r?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:r?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:r?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:r?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:r?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:r?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:r?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:r?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:r?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:r?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:r?"#888":"#aaa",btnHover:r?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var sn={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},an={pending:h.circle,pass:h.check,fail:h.x,skip:h.skip},Rt={local:{bg:"rgba(59,130,246,0.15)",text:"#60a5fa",border:"rgba(59,130,246,0.3)"},preview:{bg:"rgba(168,85,247,0.15)",text:"#c084fc",border:"rgba(168,85,247,0.3)"},staging:{bg:"rgba(245,158,11,0.15)",text:"#fbbf24",border:"rgba(245,158,11,0.3)"},production:{bg:"rgba(239,68,68,0.15)",text:"#f87171",border:"rgba(239,68,68,0.3)"},custom:{bg:"rgba(128,128,128,0.15)",text:"#888",border:"rgba(128,128,128,0.3)"}},ln=["app.supply-guard.io"];function dn(e,r=[]){if(!e)return false;let s=e.toLowerCase();return [...ln,...r].map(u=>u.toLowerCase()).includes(s)}var cn=e=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:r=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:e.bg,border:r?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:r?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(r,s)=>({width:`${r}px`,borderRadius:"8px",background:e.bg,border:s?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:s?`0 8px 24px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 8px 24px ${e.shadow}`,overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:`1px solid ${e.borderSubtle}`},title:{fontSize:"10px",fontWeight:600,color:e.text,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:e.textMuted,display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:e.gripColor,display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:`1px solid ${e.borderSubtle}`},badge:r=>{let s=Rt[r]||Rt.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:s.bg,color:s.text,border:`1px solid ${s.border}`,lineHeight:"14px"}},progress:{height:"2px",background:e.borderSubtle,flexShrink:0},progressBar:r=>({height:"100%",width:`${r}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:r=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${r}15`,color:r,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(r,s)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:r?`${s}33`:"transparent",color:r?s:e.gripColor,transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:e.inputBg,border:`1px solid ${e.inputBorder}`,borderRadius:"4px",padding:"2px 6px",color:e.text,outline:"none"},humanBanner:{padding:"6px 12px",fontSize:"11px",fontWeight:600,color:e.green,borderBottom:`1px solid ${e.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",background:e.greenBg,cursor:"pointer",textDecoration:"none"}});function nt(e){return e.split("/")[0].trim()}async function un(e){try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}try{if(typeof document>"u")return !1;let r=document.createElement("textarea");r.value=e,r.setAttribute("readonly",""),r.style.position="fixed",r.style.top="0",r.style.left="0",r.style.opacity="0",r.style.pointerEvents="none",document.body.appendChild(r),r.focus(),r.select(),r.setSelectionRange(0,e.length);let s=document.execCommand("copy");return document.body.removeChild(r),s}catch{return false}}function Pe({config:e,appSlug:r,environment:s,seededUsers:p,authToken:u,tk:a,compact:T=false,onExpand:S,onAuthExpired:_,refreshAuth:b,requestLogin:y,testRunId:F,testRunToken:Y,ticketId:M,targetUrl:x,version:m,commitSha:n,prNumber:d,branchName:V}){let[U,J]=useState(false),[j,I]=useState(null),[$,_e]=useState(null),[ie,g]=useState(null),[Ee,se]=useState(null),[te,G]=useState(null),[X,ae]=useState(null);useEffect(()=>{s==="local"&&Ie();},[s]);let me=useCallback(l=>{I(l),g(null),se(null),ae(null);let E=Re(u);if(s!=="local"&&y&&E!==null&&E<=Date.now()){G({slug:l,token:u||null}),ae(l),I(null),y();return}let R=C=>{g(C),se(l),window.setTimeout(()=>{se(P=>P===l?null:P),g(P=>P===C?null:P);},3e3);},k=new URLSearchParams({app_slug:r,seed_user_slug:l,environment:s});F&&k.set("test_run_id",F),Y&&k.set("public_token",Y),M&&k.set("ticket_id",M),x&&k.set("target_url",x),m&&k.set("version",m),n&&k.set("commit_sha",n),d&&k.set("pr_number",String(d)),V&&k.set("branch_name",V);let L=async C=>{let P={apikey:e.anonKey,Authorization:`Bearer ${C}`};try{let z=await fetch(`${e.serverUrl}/widget/totp-code?${k}`,{headers:P});if(!z.ok){let ge=await z.json().catch(()=>({error:`HTTP ${z.status}`}));return {ok:!1,status:z.status,error:ge.error||`HTTP ${z.status}`}}let q=await z.json();return {ok:!0,code:String(q.code)}}catch{return {ok:false,status:0,error:"Network error"}}},N=(async()=>{if(s==="local"){let z=await Mt(l);if(z)try{return {ok:!0,code:await Ct(z)}}catch{}}let C=await L(u||e.anonKey);if(C.ok||C.status!==401||!b)return C;let P=await b();return P?L(P):{ok:false,status:401,error:"Sign in to BotBuddy to refresh 2FA"}})(),A=null;try{if(typeof ClipboardItem<"u"&&navigator.clipboard?.write){let C=N.then(P=>{if(!P.ok)throw new Error(P.error);return new Blob([P.code],{type:"text/plain"})});A=navigator.clipboard.write([new ClipboardItem({"text/plain":C})]).then(()=>!0).catch(()=>!1);}}catch{}(async()=>{let C=await N;if(!C.ok){C.status===401?(G({slug:l,token:u||null}),ae(l)):R(C.status===404?"No 2FA seed registered":C.error),I(null);return}let P=A?await A:false,z=P?true:await un(C.code),q=P||z;_e({slug:l,code:C.code,copied:q}),window.setTimeout(()=>_e(ge=>ge?.slug===l?null:ge),q?2500:6e3),J(false),I(null);})();},[e.serverUrl,e.anonKey,u,r,s,F,Y,M,x,m,n,d,V,b,y]),re=useCallback(l=>{G({slug:l,token:u||null}),y?.();},[u,y]),ye=useCallback(l=>{X===l?re(l):me(l);},[X,re,me]);useEffect(()=>{if(!te||!u||u===te.token)return;let l=te.slug;G(null),me(l);},[u,me,te]);let xe=useRef(null),Me=useRef(null);if(useLayoutEffect(()=>{if(!U)return;let l=xe.current,E=Me.current;if(!l||!E||typeof window>"u")return;let R=()=>{let k=l.getBoundingClientRect(),L=E.getBoundingClientRect(),N=window.innerWidth,A=window.innerHeight,C=k.left,P=k.top-L.height-6;P<8&&(P=k.bottom+6);let z=Math.max(8,N-L.width-8),q=Math.max(8,A-L.height-8);C=Math.min(Math.max(C,8),z),P=Math.min(Math.max(P,8),q),E.style.left=`${Math.round(C)}px`,E.style.top=`${Math.round(P)}px`;};return R(),window.addEventListener("scroll",R,true),window.addEventListener("resize",R),()=>{window.removeEventListener("scroll",R,true),window.removeEventListener("resize",R);}},[U,p.length,ie]),useEffect(()=>{if(!U)return;let l=E=>{let R=E.target;Me.current?.contains(R)||xe.current?.contains(R)||J(false);};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[U]),p.length===0)return null;if(T){let l=p.length>1,E=p[0],R=!l&&X===E,k=z=>{if(z.stopPropagation(),l&&S){S();return}ye(E);},L=!!Ee,N=!!$,A=N&&$.copied,C=N&&!$.copied,P=R?a.blue:L?a.red:A?a.green:C?a.amber:a.purple;return jsxs("span",{onPointerDown:z=>z.stopPropagation(),onPointerUp:z=>z.stopPropagation(),onPointerMove:z=>z.stopPropagation(),onClick:k,style:{display:"inline-flex",alignItems:"center",gap:"3px",color:P,fontWeight:600,cursor:"pointer",letterSpacing:C?"0.08em":void 0},title:R?"Sign in to BotBuddy to refresh 2FA":L?ie||"Failed":C?`Clipboard blocked \u2014 code: ${$.code}`:l?`${p.length} 2FA personas`:`Copy 2FA code for ${p[0]}`,children:[jsx(w,{d:R?h.key:L?h.alert:A?h.check:C?h.copy:h.shield,size:10}),R?jsx(Fragment,{children:"Sign in"}):A?jsx(Fragment,{children:"Copied"}):C?jsx(Fragment,{children:$.code}):L?jsx(Fragment,{children:"Failed"}):jsxs(Fragment,{children:["2FA",l&&` \xB7${p.length}`]})]})}if(p.length===1){let l=p[0],E=j===l,R=$?.slug===l,k=R&&$.copied,L=R&&!$.copied,N=Ee===l,A=X===l,C=A?a.blue:N?a.red:k?a.green:L?a.amber:a.purple;return jsxs("button",{onClick:P=>{P.stopPropagation(),ye(l);},disabled:E,style:{...Pt(C),cursor:E?"wait":"pointer",opacity:E?.6:1},title:A?"Sign in to BotBuddy to refresh 2FA":N?ie||"Failed":L?`Clipboard blocked \u2014 code: ${$.code}`:`Copy 2FA code for ${l}`,children:[jsx(w,{d:A?h.key:N?h.alert:k?h.check:L?h.copy:h.shield,size:12}),A?"Sign in":k?"Copied":L?$.code:N?"Failed":E?"\u2026":`2FA \xB7 ${l}`]})}let le=!!X&&!U,Z=!!Ee&&!U,be=!!$&&$.copied,ve=!!$&&!$.copied,De=le?a.blue:Z?a.red:be?a.green:ve?a.amber:a.purple,Fe=U&&typeof document<"u"?createPortal(jsxs("div",{ref:Me,onPointerDown:l=>l.stopPropagation(),onMouseDown:l=>l.stopPropagation(),style:{position:"fixed",left:-9999,top:-9999,background:a.bg,border:`1px solid ${a.border}`,borderRadius:6,boxShadow:`0 8px 24px ${a.shadow}`,padding:4,minWidth:220,maxWidth:typeof window<"u"?Math.min(420,window.innerWidth-16):420,zIndex:1e5,fontFamily:"ui-monospace, SFMono-Regular, monospace"},children:[p.map(l=>{let E=j===l,R=X===l;return jsxs("button",{onClick:k=>{k.stopPropagation(),ye(l);},disabled:E,style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 8px",background:"transparent",border:"none",borderRadius:4,cursor:E?"wait":"pointer",fontSize:"10px",color:R?a.blue:a.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},title:R?"Sign in to BotBuddy to refresh 2FA":void 0,onMouseEnter:k=>k.currentTarget.style.background=a.btnHover,onMouseLeave:k=>k.currentTarget.style.background="transparent",children:[jsx(w,{d:R?h.key:h.shield,size:10}),jsx("span",{style:{flex:1,overflowWrap:"anywhere",lineHeight:1.3},children:l}),R?jsx("span",{style:{color:a.blue,fontSize:9},children:"Sign in"}):E?jsx("span",{style:{color:a.textMuted,fontSize:9},children:"\u2026"}):null]},l)}),ie&&jsx("div",{style:{padding:"4px 8px",fontSize:9,color:a.red},children:ie})]}),document.body):null;return jsxs(Fragment,{children:[jsxs("button",{ref:xe,onClick:l=>{if(l.stopPropagation(),le&&X){re(X);return}J(E=>!E),g(null),se(null);},style:{...Pt(De),cursor:"pointer"},title:le?"Sign in to BotBuddy to refresh 2FA":Z?ie||"Failed":ve?`Clipboard blocked \u2014 code: ${$.code}`:"Choose a persona to copy a 2FA code for",children:[jsx(w,{d:le?h.key:Z?h.alert:be?h.check:ve?h.copy:h.shield,size:12}),le?"Sign in":be?"Copied":ve?$.code:Z?"Failed":`2FA \xB7 ${p.length}`,!le&&jsx(w,{d:U?h.chevronUp:h.chevronDown,size:8})]}),Fe]})}function Pt(e){return {display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${e}15`,color:e,textDecoration:"none",border:`1px solid ${e}30`}}var Et="botbuddy-widget-state";function pn({config:e,appSlug:r,environment:s,ticketId:p,testRunId:u,testRunToken:a,targetUrl:T,version:S,commitSha:_,prNumber:b,branchName:y,onNavigate:F,displayName:Y="human",defaultMode:M="mini",defaultPosition:x}){let m=rn(),n=useMemo(()=>on(m),[m]),d=useMemo(()=>cn(n),[n]),[V,U]=useState(false),[J,j]=useState(false),[I,$]=useState(false),_e=useRef(false),ie=e.dashboardUrl||"https://app.bot-buddy.ai",g=tt(ie),se=(()=>{try{let t=typeof window<"u"?localStorage.getItem(Et):null;if(t)return JSON.parse(t)}catch{}return null})(),[te,G]=useState(se?.mode||M),[X,ae]=useState(""),[me,re]=useState(null),[ye,xe]=useState(null),[Me,le]=useState(new Set),[Z,be]=useState(""),ve=useCallback(t=>{le(c=>{let v=new Set(c);return v.has(t)?v.delete(t):v.add(t),v});},[]),De=se?.x??x?.x??16,Fe=se?.y??x?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:l,setPos:E,onPointerDown:R,onPointerMove:k,onPointerUp:L,didDrag:N}=Ye(De,Fe),A=useRef(null);useEffect(()=>{try{localStorage.setItem(Et,JSON.stringify({mode:te,x:l.x,y:l.y}));}catch{}},[te,l.x,l.y]),useLayoutEffect(()=>{if(typeof window>"u")return;let t=A.current;if(!t)return;let c=t.getBoundingClientRect(),v=Ve(l.x,l.y,c.width,c.height,window.innerWidth,window.innerHeight);(v.x!==l.x||v.y!==l.y)&&E(v);}),useEffect(()=>{if(typeof window>"u")return;let t=()=>{let c=A.current;if(!c)return;let v=c.getBoundingClientRect(),W=Ve(l.x,l.y,v.width,v.height,window.innerWidth,window.innerHeight);(W.x!==l.x||W.y!==l.y)&&E(W);};return window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[l.x,l.y,E]);let C=useRef(g.isAuthenticated);useEffect(()=>{!C.current&&g.isAuthenticated&&G("max"),C.current=g.isAuthenticated;},[g.isAuthenticated]);let P="botbuddy-widget-max-size",z=()=>{try{let t=localStorage.getItem(P);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[q,ge]=useState(z),Ce=useRef(false),Te=useRef({x:0,y:0,w:0,h:0}),Bt=useCallback(t=>{t.stopPropagation(),Ce.current=true,Te.current={x:t.clientX,y:t.clientY,w:q.w,h:q.h},t.target.setPointerCapture(t.pointerId);},[q]),zt=useCallback(t=>{if(!Ce.current)return;let c=Math.max(280,Math.min(600,Te.current.w+(t.clientX-Te.current.x))),v=Math.max(300,Math.min(window.innerHeight*.9,Te.current.h+(t.clientY-Te.current.y)));ge({w:c,h:v});},[]),$t=useCallback(()=>{Ce.current&&(Ce.current=false,ge(t=>(localStorage.setItem(P,JSON.stringify(t)),t)));},[]),Q=T??(typeof window<"u"?window.location.href:void 0),rt=g.displayName||Y,[oe,ot]=useState(null);useEffect(()=>{if(g.isAuthenticated)return;let t=new URLSearchParams;a&&t.set("token",a),p&&t.set("ticket_id",p),t.set("app_slug",r),s&&t.set("environment",s),u&&t.set("test_run_id",u),Q&&t.set("target_url",Q),S&&t.set("version",S),_&&t.set("commit_sha",_),b&&t.set("pr_number",String(b)),y&&t.set("branch_name",y),fetch(`${e.serverUrl}/widget/preview?${t}`,{headers:{apikey:e.anonKey}}).then(c=>c.json()).then(c=>ot(c)).catch(()=>ot(null));},[g.isAuthenticated,e.serverUrl,e.anonKey,r,s,p,u,a,Q,S,_,b,y]);let it=useRef(false),At=useCallback(()=>{it.current||g.logout();},[g.logout]),{run:f,widgetState:fe,fetchRun:Ut,setVerdict:st,markComplete:Wt,resetRun:It,setRun:at}=Ge({config:e,appSlug:r,environment:s,ticketId:p,testRunId:u,testRunToken:a,targetUrl:Q,version:S,commitSha:_,prNumber:b?String(b):void 0,branchName:y,authToken:g.token,onAuthExpired:At});it.current=!!f;let[lt,dt]=useState([]),[ct,Le]=useState([]),[Ne,ut]=useState(false),[pt,gt]=useState(null),[Dt,Be]=useState(false),de=dn(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);useEffect(()=>{if((s??"local")!=="local"||de){dt([]);return}let t=true;return Ie().then(c=>{t&&dt(Object.keys(c||{}));}),()=>{t=false;}},[s,de]);let Ft=useCallback(async()=>{if(!(!g.isAuthenticated||!g.token)){ut(true),gt(null);try{let t=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${g.token}`},body:JSON.stringify({app_slug:r,environment:s||"local",target_url:Q,branch_name:y,commit_sha:_,pr_number:b,ticket_id:p,title:`${p||r} local validation`})}),c=await t.json().catch(()=>({}));if(!t.ok)throw new Error(c.error||`HTTP ${t.status}`);at(c),G("max");}catch(t){gt(t.message);}finally{ut(false);}}},[g.isAuthenticated,g.token,e.serverUrl,e.anonKey,r,s,Q,y,_,b,p,at]),ze=useCallback(async(t,c,v)=>{xe(t);try{await st(t,c,v,rt);}finally{xe(null),re(null),ae("");}},[st,rt]),D=f?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},Nt=D.total>0&&D.pending===0,we=fe==="completed",$e=useMemo(()=>{let t=f?.test_cases||[];if(!Z.trim())return t;let c=Z.toLowerCase();return t.filter(v=>v.title.toLowerCase().includes(c)||v.description&&v.description.toLowerCase().includes(c)||v.url_path&&v.url_path.toLowerCase().includes(c)||v.seed_user&&v.seed_user.toLowerCase().includes(c))},[f?.test_cases,Z]),ft=useMemo(()=>{let t=$e,c=f?.test_cases||[];if(new Set(c.map(K=>K.source_pr_number)).size<=1)return null;let W=[],ue=new Map;t.forEach(K=>{let H=K.source_pr_number;ue.has(H)||ue.set(H,[]),ue.get(H).push(K);});let St=[...ue.keys()].sort((K,H)=>K===null?1:H===null?-1:H-K);for(let K of St){let H=ue.get(K),He={total:H.length,pass:0,fail:0,skip:0,pending:0};H.forEach(kt=>{kt.verdict in He&&He[kt.verdict]++;}),W.push({key:K!=null?`pr-${K}`:"general",label:K!=null?`PR #${K}`:"General",cases:H,summary:He});}return W.filter(K=>K.cases.length>0)},[$e,f?.test_cases]),ht=D.total>0?(D.pass+D.fail)/D.total*100:0,O=s??f?.environment??null,ce=useMemo(()=>{if(!O||O==="production"||de)return [];let t=f?.test_cases||[],c=new Set;for(let v of t)v.seed_user&&c.add(nt(v.seed_user));if(O==="local")for(let v of lt)c.add(nt(v));for(let v of ct)c.add(nt(v));return [...c]},[f?.test_cases,O,lt,ct,de]);useEffect(()=>{if(!O||O==="production"||de||!g.isAuthenticated||!g.token){Le([]);return}let t=true,c=`${e.serverUrl}/widget/totp-seeds?${new URLSearchParams({app_slug:r,environment:O})}`,v=W=>fetch(c,{headers:{apikey:e.anonKey,Authorization:`Bearer ${W}`}});return (async()=>{try{let W=await v(g.token);if(W.status===401&&g.refreshNow){let H=await g.refreshNow();H&&(W=await v(H));}if(!t)return;if(!W.ok){Le([]);return}let ue=await W.json().catch(()=>null),K=(Array.isArray(ue?.seeds)?ue.seeds:[]).map(H=>H?.seed_user_slug).filter(H=>typeof H=="string"&&H.length>0);Le(K);}catch{t&&Le([]);}})(),()=>{t=false;}},[O,de,g.isAuthenticated,g.token,g.refreshNow,r,e.serverUrl,e.anonKey]);let Oe=useMemo(()=>{let t=f?.auto_tooltip_seconds??oe?.auto_tooltip_seconds;return t!=null&&t>0?t*1e3:0},[f,oe]),mt=fe==="ready"||fe==="completed"||oe?.enabled&&oe.run;useEffect(()=>{if(!mt||_e.current||Oe<=0)return;_e.current=true,j(true);let t=window.setTimeout(()=>j(false),Oe);return ()=>window.clearTimeout(t)},[mt,Oe]);let yt=t=>jsxs("div",{style:d.caseRow,children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsx("div",{style:{marginTop:"2px",flexShrink:0,color:sn[t.verdict]},children:ye===t.id?jsx(w,{d:h.loader,className:""}):jsx(w,{d:an[t.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:n.text,lineHeight:1.3},children:t.title}),t.description&&jsx("div",{style:{fontSize:"9px",color:n.gripColor,marginTop:"2px"},children:t.description}),t.seed_user&&jsxs("div",{style:{fontSize:"9px",color:n.amber,marginTop:"3px",display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",background:`${n.amber}12`,border:`1px solid ${n.amber}30`},children:[jsx(w,{d:h.key,size:10}),jsx("span",{children:t.seed_user})]}),t.url_path&&jsxs("a",{href:t.url_path,target:"_blank",rel:"noopener noreferrer",onClick:c=>{c.stopPropagation(),F&&(c.preventDefault(),F(t.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsx(w,{d:h.externalLink,size:10}),t.url_path]}),t.verdict==="fail"&&t.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:n.red,marginTop:"2px"},children:["\u2717 ",t.fail_reason]})]})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(c=>jsx("button",{onClick:()=>{if(t.verdict===c){ze(t.id,"pending"),re(null);return}if(c==="fail"){re(t.id),ae("");return}re(null),ze(t.id,c);},disabled:ye!==null,style:d.verdictBtn(t.verdict===c,c==="pass"?n.green:c==="fail"?n.red:n.amber),children:c.toUpperCase()},c)),t.created_by_agent_name&&jsxs("span",{style:{fontSize:"8px",color:n.purple,marginLeft:"4px",display:"inline-flex",alignItems:"center",gap:"2px"},children:[jsx(w,{d:h.bot,size:8}),t.created_by_agent_name]}),t.verdict_by_display_name&&jsxs("span",{style:{fontSize:"8px",color:n.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[t.verdict_by_display_name,t.verdict_at&&jsx("span",{style:{opacity:.7},children:nn(t.verdict_at)})]})]}),me===t.id&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:X,onChange:c=>ae(c.target.value),onKeyDown:c=>{c.key==="Enter"&&ze(t.id,"fail",X.trim()||void 0),c.key==="Escape"&&(re(null),ae(""));},placeholder:"Reason (optional)...",style:d.input}),jsx("button",{onClick:()=>{ze(t.id,"fail",X.trim()||void 0);},style:d.verdictBtn(true,n.red),children:"\u2713"})]})]},t.id);if((fe==="no-match"||fe==="loading")&&!(!g.isAuthenticated&&oe?.enabled&&oe.run)){if(!(O==="local"&&!de))return null}if(!g.isAuthenticated&&oe?.enabled&&oe.run){let t=oe.run,c=t.summary,v=t.status==="completed";return jsx("div",{ref:A,style:{...d.root,left:l.x,top:l.y},children:jsxs("div",{style:{position:"relative"},onMouseEnter:()=>U(true),onMouseLeave:()=>{U(false),$(false),j(false);},children:[jsxs("div",{style:{...d.pill(v),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:R,onPointerMove:k,onPointerUp:()=>{L();},children:[jsx(w,{d:h.grip,size:10,className:""}),t.ticket_id&&t.ticket_url?jsx("a",{href:t.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:n.amber,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:t.ticket_id}):null,t.pr_url?jsxs("a",{href:t.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:n.blue,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:["PR#",t.pr_number??t.pr_id]}):null,t.created_by_agent_name?t.codex_thread_id?jsxs("a",{href:`codex://threads/${t.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.stopPropagation(),style:{color:n.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(w,{d:h.terminal,size:10}),t.created_by_agent_name]}):jsxs("span",{style:{color:n.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(w,{d:h.bot,size:10}),t.created_by_agent_name]}):null,jsxs("span",{style:v?{color:n.green}:void 0,children:[c.pass,"/",c.total]}),c.fail>0&&jsxs("span",{style:{color:n.red},children:[c.fail,"\u2717"]}),jsx("span",{onClick:W=>{W.stopPropagation(),g.openLogin();},style:{color:n.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!I&&(V||J)&&t.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsx("div",{style:{fontSize:"11px",fontWeight:700,color:n.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:t.title}),(t.description||t.intro_notes)&&jsx("div",{style:{fontSize:"10px",color:n.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:t.description||t.intro_notes}),jsx("div",{style:{marginTop:"4px",fontSize:"9px",color:n.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!g.isAuthenticated)return jsxs("div",{ref:A,style:{...d.root,left:l.x,top:l.y,width:220,minHeight:0,cursor:"move",userSelect:"none",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`},onPointerDown:R,onPointerMove:k,onPointerUp:L,children:[jsx("div",{style:{...d.handle,borderBottom:"none"},children:jsxs("div",{style:d.sub,children:[jsx(w,{d:h.grip,size:10,className:""}),jsx(w,{d:h.clipboard,size:12,className:""}),jsx("span",{style:{fontWeight:600},children:"BotBuddy"})]})}),jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[jsx("div",{style:{fontSize:"9px",color:n.textMuted,marginBottom:"8px"},children:"Sign in to access test cases"}),O==="local"&&ce.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,testRunId:f?.id||u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout})}),jsx("button",{onClick:t=>{t.stopPropagation(),g.openLogin();},style:{fontSize:"10px",fontWeight:600,padding:"6px 16px",borderRadius:"6px",border:`1px solid ${n.green}`,background:`${n.green}22`,color:n.green,cursor:"pointer",width:"100%"},children:"Sign in to test"})]})]});if(!f&&O==="local"&&!de)return Dt?jsx("div",{ref:A,style:{...d.root,left:l.x,top:l.y},children:jsxs("div",{style:d.card(240,false),children:[jsxs("div",{style:d.handle,onPointerDown:R,onPointerMove:k,onPointerUp:L,onClick:()=>{N.current||Be(false);},children:[jsx(w,{d:h.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:d.title,children:"BotBuddy"}),y&&jsx("div",{style:d.sub,children:jsxs("span",{children:["\u2387 ",y]})})]}),jsx(w,{d:h.chevronUp,className:""}),jsx("button",{style:d.btn,onClick:t=>{t.stopPropagation(),Be(false);},children:jsx(w,{d:h.minus,className:""})})]}),jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[ce.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,testRunId:u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout})}),jsx("button",{onClick:t=>{t.stopPropagation(),Ft();},disabled:Ne,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${n.green}`,background:`${n.green}22`,color:n.green,cursor:Ne?"wait":"pointer",width:"100%"},children:Ne?"Creating...":"Create test run for this branch"}),pt&&jsx("div",{style:{fontSize:"9px",color:n.red,marginTop:"8px"},children:pt})]})]})}):jsx("div",{ref:A,style:{...d.root,left:l.x,top:l.y},children:jsxs("div",{style:{...d.pill(false),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:R,onPointerMove:k,onPointerUp:()=>{L(),N.current||Be(true);},children:[jsx(w,{d:h.grip,size:9,className:""}),jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),ce.length>0&&jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,compact:true,onExpand:()=>Be(true),testRunId:u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout})]})});let xt=()=>{N.current||(j(false),G(t=>{let c=t==="mini"?"max":"mini";return $(c==="mini"),c}));},bt=({icon:t,onClick:c})=>jsx("button",{style:d.btn,onClick:v=>{v.stopPropagation(),c(v);},children:jsx(w,{d:t,className:""})}),vt=()=>jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${n.borderSubtle}`,flexShrink:0},children:[f?.pr_url&&jsxs("a",{href:f.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.blue),textDecoration:"none"},children:[jsx(w,{d:h.pr,size:12}),f.pr_number?`PR#${f.pr_number}`:f.pr_id||"PR",jsx(w,{d:h.externalLink,size:8})]}),f?.ticket_url&&jsxs("a",{href:f.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.amber),textDecoration:"none"},children:[jsx(w,{d:h.ticket,size:12}),f.ticket_id||"Ticket",jsx(w,{d:h.externalLink,size:8})]}),f?.created_by_agent_name&&(f.codex_thread_id?jsxs("a",{href:`codex://threads/${f.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.purple),textDecoration:"none"},children:[jsx(w,{d:h.bot,size:12}),f.created_by_agent_name,jsx(w,{d:h.externalLink,size:8})]}):jsxs("span",{style:{...d.link(n.purple)},children:[jsx(w,{d:h.bot,size:12}),f.created_by_agent_name]})),O&&jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,testRunId:f?.id||u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout}),jsx("span",{style:{...d.badge(f?.environment||"custom"),marginLeft:"auto"},children:f?.environment})]}),wt=()=>jsxs("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:`1px solid ${n.borderSubtle}`,background:n.bgSoft,flexShrink:0},children:[jsxs("button",{onClick:()=>{navigator.clipboard.writeText(Tt);},style:{fontSize:"9px",fontWeight:600,color:n.versionText,letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxs("span",{style:{color:n.versionNum},children:["v",Tt]})]}),g.isAuthenticated&&(g.isExpired?jsx("button",{onClick:t=>{t.stopPropagation(),g.openLogin();},style:{fontSize:"8px",color:n.blue,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Widget session expired \u2014 sign in to refresh",children:"sign in"}):jsx("button",{onClick:t=>{t.stopPropagation(),g.logout();},style:{fontSize:"8px",color:n.textFaint,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Sign out of widget",children:"sign out"}))]});return jsxs("div",{ref:A,style:{...d.root,left:l.x,top:l.y},children:[te==="mini"&&jsxs("div",{style:{position:"relative"},onMouseEnter:()=>U(true),onMouseLeave:()=>{U(false),$(false),j(false);},children:[jsxs("div",{style:{...d.pill(we),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:R,onPointerMove:k,onPointerUp:()=>{L(),N.current||xt();},children:[jsx(w,{d:h.grip,size:9,className:""}),f?.ticket_id&&jsx("span",{style:{color:n.amber,fontWeight:600},children:f.ticket_id}),f?.pr_number&&jsxs("span",{style:{color:n.blue,fontWeight:600},children:["PR#",f.pr_number]}),jsxs("span",{style:we?{color:n.green}:void 0,children:[D.pass,"/",D.total]}),D.fail>0&&jsxs("span",{style:{color:n.red},children:[D.fail,"\u2717"]}),O&&jsx(Pe,{config:e,appSlug:r,environment:O,seededUsers:ce,authToken:g.token,refreshAuth:g.refreshNow,requestLogin:g.openLogin,tk:n,compact:true,onExpand:()=>G("expanded"),testRunId:f?.id||u,testRunToken:a,ticketId:p,targetUrl:Q,version:S,commitSha:_,prNumber:b,branchName:y,onAuthExpired:g.logout})]}),!I&&(V||J)&&f?.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsx("div",{style:{fontSize:"11px",fontWeight:700,color:n.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:f.title}),(f.description||f.intro_notes)&&jsx("div",{style:{fontSize:"10px",color:n.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:f.description||f.intro_notes})]})]}),te==="expanded"&&jsxs("div",{style:d.card(300,we),children:[jsxs("div",{style:d.handle,onPointerDown:R,onPointerMove:k,onPointerUp:L,onClick:xt,children:[jsx(w,{d:h.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:d.title,children:f?.title}),jsx("div",{style:d.sub,children:f?.branch_name&&jsxs("span",{children:["\u2387 ",f.branch_name]})})]}),jsx(w,{d:h.chevronUp,className:""}),jsx(bt,{icon:h.minus,onClick:()=>{j(false),$(true),G("mini");}})]}),jsxs("div",{style:d.stats,children:[jsxs("span",{style:{color:n.green},children:[D.pass,"\u2713"]}),jsxs("span",{style:{color:n.red},children:[D.fail,"\u2717"]}),jsxs("span",{style:{color:n.amber},children:[D.skip,"\u23ED"]}),jsxs("span",{style:{color:n.gripColor},children:[D.pending,"\u25CC"]}),jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:D.total})]}),f?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:n.gripColor,borderBottom:`1px solid ${n.borderSubtle}`,flexShrink:0},children:f.description}),vt(),wt(),jsx("div",{style:d.progress,children:jsx("div",{style:d.progressBar(ht)})})]}),te==="max"&&jsxs("div",{style:{...d.card(q.w,we),height:q.h,position:"relative"},children:[jsxs("div",{style:d.handle,onPointerDown:R,onPointerMove:k,onPointerUp:L,onClick:()=>{N.current||G("expanded");},children:[jsx(w,{d:h.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:d.title,children:f?.title}),jsx("div",{style:d.sub,children:f?.branch_name&&jsxs("span",{children:["\u2387 ",f.branch_name]})})]}),jsx(w,{d:h.chevronDown,className:""}),jsx(bt,{icon:h.minus,onClick:()=>{j(false),$(true),G("mini");}})]}),jsxs("div",{style:d.stats,children:[jsxs("span",{style:{color:n.green},children:[D.pass,"\u2713"]}),jsxs("span",{style:{color:n.red},children:[D.fail,"\u2717"]}),jsxs("span",{style:{color:n.amber},children:[D.skip,"\u23ED"]}),jsxs("span",{style:{color:n.gripColor},children:[D.pending,"\u25CC"]}),jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:D.total})]}),f?.intro_notes&&jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${n.borderSubtle}`,fontSize:"10px",color:n.textMuted,fontStyle:"italic",flexShrink:0},children:f.intro_notes}),(f?.test_cases||[]).length>5&&jsxs("div",{style:{padding:"4px 12px",borderBottom:`1px solid ${n.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[jsx(w,{d:h.search,size:11,className:""}),jsx("input",{value:Z,onChange:t=>be(t.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:n.text,fontFamily:"monospace"}}),Z&&jsx("button",{onClick:()=>be(""),style:{background:"none",border:"none",cursor:"pointer",color:n.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),fe==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(w,{d:h.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:n.red},children:"Failed to load"}),jsx("button",{onClick:Ut,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),we&&jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg},children:[jsx(w,{d:h.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:n.green,flex:1},children:"Run completed"}),jsx("button",{onClick:It,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),fe!=="error"&&jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(f?.test_cases||[]).length===0?jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:"No test cases"}):$e.length===0?jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:['No matches for "',Z,'"']}):ft?ft.map(t=>{let c=Me.has(t.key);return jsxs("div",{children:[jsxs("button",{onClick:()=>ve(t.key),style:{width:"100%",display:"flex",alignItems:"center",gap:"6px",padding:"5px 12px",background:n.bgSoft,cursor:"pointer",border:"none",borderLeft:"none",borderRight:"none",borderBottomStyle:"solid",borderTopStyle:"solid",borderBottomWidth:"1px",borderTopWidth:"1px",borderBottomColor:n.borderSubtle,borderTopColor:n.borderSubtle,backgroundColor:n.bgSoft},children:[jsx(w,{d:c?h.chevronDown:h.chevronUp,size:10,className:""}),jsx("span",{style:{fontSize:"10px",fontWeight:700,color:n.blue,flex:1,textAlign:"left"},children:t.label}),jsxs("span",{style:{fontSize:"9px",color:n.green},children:[t.summary.pass,"\u2713"]}),jsxs("span",{style:{fontSize:"9px",color:n.red},children:[t.summary.fail,"\u2717"]}),jsxs("span",{style:{fontSize:"9px",color:n.gripColor},children:[t.summary.pending,"\u25CC"]}),jsx("span",{style:{fontSize:"9px",color:n.textFaint},children:t.summary.total})]}),!c&&t.cases.map(v=>yt(v))]},t.key)}):$e.map(t=>yt(t))}),Nt&&!we&&jsxs("div",{style:{padding:"6px 12px",borderTop:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg,display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsx("span",{style:{fontSize:"9px",color:n.green},children:"All resolved"}),jsx("button",{onClick:Wt,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:n.green,border:`1px solid ${n.greenBorderSubtle}`,cursor:"pointer"},children:"COMPLETE"})]}),vt(),wt(),jsx("div",{style:d.progress,children:jsx("div",{style:d.progressBar(ht)})}),jsx("div",{style:{position:"absolute",bottom:0,right:0,width:16,height:16,cursor:"se-resize",zIndex:10,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:"2px",opacity:.3},onPointerDown:Bt,onPointerMove:zt,onPointerUp:$t,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{Ce.current||(t.currentTarget.style.opacity="0.3");},children:jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsx("path",{d:"M7 1v6H1",fill:"none",stroke:n.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}
|
|
2
|
+
export{pn as TestRunWidget,Ye as useDraggable,Je as useRealtimeRefresh,Ge as useTestRun,tt as useWidgetAuth};
|
package/package.json
CHANGED