@botbuddy/react 0.10.10 → 0.10.11

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