@botbuddy/react 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +9 -0
- package/dist/index.cjs +16 -11
- package/dist/index.d.cts +24 -3
- package/dist/index.d.ts +24 -3
- package/dist/index.js +16 -11
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @botbuddy/react — Changelog
|
|
2
2
|
|
|
3
|
+
## 0.17.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **`ReleaseNotes` tag chips and filters (BOT-3164).** Each entry's `tags`
|
|
8
|
+
render as chips; the feed's `filters` render as one select per group with
|
|
9
|
+
only the values the server offers. Choosing a value re-reads the feed with
|
|
10
|
+
`tag=<group>:<value>`, so the server decides which notes match. New class
|
|
11
|
+
slots `tags`, `tag`, `filters`, `filter`. New types `ReleaseNoteTag` and
|
|
12
|
+
`ReleaseNoteFilter`; `ReleaseNoteEntry.tags` and `ReleaseNotesFeed.filters`
|
|
13
|
+
are optional, so older servers still render.
|
|
14
|
+
|
|
3
15
|
## 0.16.0
|
|
4
16
|
|
|
5
17
|
### Added
|
package/README.md
CHANGED
|
@@ -198,6 +198,15 @@ readable on a light or a dark page.
|
|
|
198
198
|
| `link` | each link |
|
|
199
199
|
| `status` | the loading, empty, unavailable and stale lines |
|
|
200
200
|
| `retry` | the Retry buttons |
|
|
201
|
+
| `tags` | the list of tag chips under a note (BOT-3164) |
|
|
202
|
+
| `tag` | each tag chip (`data-bbrn-tag-group` names its group) |
|
|
203
|
+
| `filters` | the row of filter controls above the notes |
|
|
204
|
+
| `filter` | each filter (a label around a `<select>`) |
|
|
205
|
+
|
|
206
|
+
Tags and filters come from the feed: the server applies the tenant's view
|
|
207
|
+
settings, so a hidden group never reaches the component, and a filter lists
|
|
208
|
+
only values a visible note carries. Choosing a value re-reads the feed with
|
|
209
|
+
`tag=<group>:<value>`.
|
|
201
210
|
|
|
202
211
|
`components` replaces whole parts:
|
|
203
212
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
'use strict';var react=require('react'),reactDom=require('react-dom'),jsxRuntime=require('react/jsx-runtime');var Te=8;function Qe(e,t,s,d,a,l){let R=Math.max(Te,a-s-Te),v=Math.max(Te,l-d-Te);return {x:Math.min(Math.max(e,Te),R),y:Math.min(Math.max(t,Te),v)}}function et(e,t){let[s,d]=react.useState({x:e,y:t}),a=react.useRef(false),l=react.useRef({x:0,y:0}),R=react.useRef(false),v=react.useCallback(h=>{a.current=true,R.current=false,l.current={x:h.clientX-s.x,y:h.clientY-s.y},h.target.setPointerCapture(h.pointerId);},[s]),T=react.useCallback(h=>{a.current&&(R.current=true,d({x:h.clientX-l.current.x,y:h.clientY-l.current.y}));},[]),y=react.useCallback(()=>{a.current=false;},[]);return {pos:s,setPos:d,onPointerDown:v,onPointerMove:T,onPointerUp:y,didDrag:R}}function tt(e,t,s){let d=react.useRef(s);d.current=s,react.useEffect(()=>{if(!t)return;if(e.supabaseUrl){let l=false,R=null,v=()=>{l||R||(R=setInterval(()=>d.current(),15e3));},T=null;try{let g=new URL(e.supabaseUrl),n=["localhost","127.0.0.1","::1"].includes(g.hostname);if(g.protocol==="http:"&&!n)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");g.protocol=g.protocol==="https:"?"wss:":"ws:",T=g.toString().replace(/\/$/,"");}catch{v();}let y=null,h=null,B=null,j=0,S=()=>{if(!(l||!T)){try{y=new WebSocket(`${T}/realtime/v1/websocket?apikey=${e.anonKey}&vsn=1.0.0`);}catch{v();return}y.onopen=()=>{if(l||!y)return;let g={topic:`realtime:public:test_run_cases:test_run_id=eq.${t}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_run_cases",filter:`test_run_id=eq.${t}`}]}},ref:String(++j)};y.send(JSON.stringify(g));let n={topic:`realtime:public:test_runs:id=eq.${t}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_runs",filter:`id=eq.${t}`}]}},ref:String(++j)};y.send(JSON.stringify(n)),h=setInterval(()=>{y?.readyState===WebSocket.OPEN&&y.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++j)}));},3e4);},y.onmessage=g=>{try{JSON.parse(g.data).event==="postgres_changes"&&d.current();}catch{}},y.onclose=()=>{x(),l||(B=setTimeout(S,3e3));},y.onerror=()=>{y?.close();};}},x=()=>{h&&(clearInterval(h),h=null);};return S(),()=>{l=true,x(),B&&clearTimeout(B),R&&clearInterval(R),y&&(y.onclose=null,y.onerror=null,y.close());}}let a=setInterval(()=>d.current(),15e3);return ()=>clearInterval(a)},[e.supabaseUrl,e.anonKey,t]);}var un="botbuddy:created-test-run:";function pn(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function gn(e){return `${un}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",pn(e.targetUrl),e.branchName||""].join("|"))}`}function Fe(e,t){let s={apikey:e.anonKey};return t?s.Authorization=`Bearer ${t}`:e.apiKey?s.Authorization=`Bearer ${e.apiKey}`:s.Authorization=`Bearer ${e.anonKey}`,s}async function fn(e){if(e)return e;try{let t=await fetch("/.botbuddy-token",{cache:"no-store"});if(t.ok){let s=(await t.text()).trim();if(s.startsWith("public_"))return s}}catch{}try{let t=undefined?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(t&&typeof t=="string"&&t.startsWith("public_"))return t}catch{}return null}function rt(e){let[t,s]=react.useState(null),[d,a]=react.useState("loading"),l=gn(e),[R,v]=react.useState(()=>{if(e.testRunId)return e.testRunId;try{return localStorage.getItem(l)||void 0}catch{return}}),T=e.testRunId||R,y=react.useCallback(x=>{if(s(x),!!x?.id){v(x.id);try{localStorage.setItem(l,x.id);}catch{}}},[l]),h=react.useCallback(async()=>{try{let x=await fn(e.testRunToken);if(!x&&!T){a("no-match"),s(null);return}if(x&&!e.ticketId){a("no-match"),s(null);return}let g=new URLSearchParams;x&&g.set("token",x),e.ticketId&&g.set("ticket_id",e.ticketId),g.set("app_slug",e.appSlug),e.environment&&g.set("environment",e.environment),T&&g.set("test_run_id",T),e.targetUrl&&g.set("target_url",e.targetUrl),e.version&&g.set("version",e.version),e.commitSha&&g.set("commit_sha",e.commitSha),e.prNumber&&g.set("pr_number",String(e.prNumber)),e.branchName&&g.set("branch_name",e.branchName);let n=await fetch(`${e.config.serverUrl}/widget/test-run?${g.toString()}`,{headers:Fe(e.config,e.authToken)});if(n.status===404){a("no-match"),s(null);return}if(n.status===401||n.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),a("error");return}if(!n.ok){a("error");return}let i=await n.json();if(!i||i.run===null){a("no-match"),s(null);return}y(i),a(i.status==="completed"?"completed":"ready");}catch{a("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,y]);return react.useEffect(()=>{h();},[h]),tt(e.config,t?.id,h),{run:t,widgetState:d,fetchRun:h,setVerdict:async(x,g,n,i="human")=>(s(N=>{if(!N)return null;let z=N.test_cases.map(C=>C.id===x?{...C,verdict:g,fail_reason:g==="fail"&&n||null,verdict_by_display_name:i,verdict_at:new Date().toISOString()}:C),k={total:z.length,pending:0,pass:0,fail:0,skip:0};return z.forEach(C=>{C.verdict in k&&k[C.verdict]++;}),{...N,test_cases:z,summary:k}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${x}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...Fe(e.config,e.authToken)},body:JSON.stringify({verdict:g,fail_reason:n,display_name:i})})).ok),markComplete:async()=>t?(s(g=>g?{...g,status:"completed"}:null),a("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${t.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...Fe(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!t)return false;let x=await fetch(`${e.config.serverUrl}/widget/test-runs/${t.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...Fe(e.config,e.authToken)}});return x.ok&&h(),x.ok},setRun:y}}var it="botbuddy-widget-auth-token",at="botbuddy-widget-auth-name";function Le(e){if(!e)return null;try{let t=e.split(".")[1];if(!t)return null;let s=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(t.length/4)*4,"="),d=atob(s),a=JSON.parse(d);return typeof a.exp=="number"?a.exp*1e3:null}catch{return null}}var mn=2500,yn=6e4;function lt(e){let[t,s]=react.useState(()=>{try{return localStorage.getItem(it)}catch(S){return console.warn("Unable to read BotBuddy widget auth token",S),null}}),[d,a]=react.useState(()=>{try{return localStorage.getItem(at)}catch(S){return console.warn("Unable to read BotBuddy widget display name",S),null}}),l=react.useRef(null),R=react.useCallback((S,x)=>{s(S),x&&a(x);try{localStorage.setItem(it,S),x&&localStorage.setItem(at,x);}catch(g){console.warn("Unable to persist BotBuddy widget auth token",g);}},[]);react.useEffect(()=>{let S=new URL(e).origin,x=g=>{g.origin===S&&g.data?.type==="botbuddy-widget-auth"&&g.data.token&&R(g.data.token,g.data.displayName||"human");};return window.addEventListener("message",x),()=>window.removeEventListener("message",x)},[e,R]);let v=react.useCallback(()=>{if(l.current)return l.current;if(typeof window>"u"||typeof document>"u")return Promise.resolve(null);let S=new URL(e).origin,x=new URL("/widget-auth",e);x.searchParams.set("silent","1"),x.searchParams.set("origin",window.location.origin);let g=new Promise(n=>{let i=document.createElement("iframe");i.setAttribute("aria-hidden","true"),i.style.position="fixed",i.style.width="1px",i.style.height="1px",i.style.opacity="0",i.style.pointerEvents="none",i.style.border="0",i.style.left="-9999px",i.style.top="-9999px",i.src=x.toString();let U=false,N=()=>{window.removeEventListener("message",z),clearTimeout(k);try{i.remove();}catch{}l.current=null;},z=C=>{if(C.origin===S){if(C.data?.type==="botbuddy-widget-auth-failed"){if(U)return;U=true,n(null),N();return}C.data?.type!=="botbuddy-widget-auth"||!C.data.token||U||(U=true,n(String(C.data.token)),N());}},k=setTimeout(()=>{U||(U=true,n(null),N());},mn);window.addEventListener("message",z),document.body.appendChild(i);});return l.current=g,g},[e]);react.useEffect(()=>{if(!t)return;let S=Le(t);if(!S)return;let x=S-Date.now()-yn,g=window.setTimeout(()=>{v();},Math.max(0,x));return ()=>window.clearTimeout(g)},[t,v]);let T=react.useCallback(()=>{let S=new URL("/widget-auth",e);S.searchParams.set("origin",window.location.origin);let x=420,g=520,n=window.screenX+(window.innerWidth-x)/2,i=window.screenY+(window.innerHeight-g)/2;window.open(S.toString(),"botbuddy-auth",`width=${x},height=${g},left=${n},top=${i},popup=yes`);},[e]),[,y]=react.useState(0);react.useEffect(()=>{let S=Le(t);if(!S)return;let x=S-Date.now();if(x<=0)return;let g=window.setTimeout(()=>y(n=>n+1),x);return ()=>window.clearTimeout(g)},[t]);let h=react.useCallback(()=>{s(null),a(null);try{localStorage.removeItem(it),localStorage.removeItem(at);}catch(S){console.warn("Unable to clear BotBuddy widget auth token",S);}},[]),B=Le(t),j=B!==null&&B<=Date.now();return {token:t,displayName:d,isAuthenticated:!!t,isExpired:j,openLogin:T,refreshNow:v,logout:h}}var Oe=null;function hn(){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 He(){return Oe||(Oe=(async()=>{if(typeof fetch>"u")return null;try{let e=await fetch(hn(),{cache:"no-store"});if(!e.ok)return null;let t=await e.json();if(!t||typeof t!="object"||Array.isArray(t))return null;let s={};for(let[d,a]of Object.entries(t))typeof a=="string"&&a.length>0&&(s[d]=a);return s}catch{return null}})(),Oe)}async function Ut(e){return (await He())?.[e]??null}function xn(e){let t=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),s="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",d=[],a=0,l=0;for(let R of t){let v=s.indexOf(R);if(v<0)throw new Error("Invalid Base32 character in TOTP secret");l=l<<5|v,a+=5,a>=8&&(a-=8,d.push(l>>>a&255));}return Uint8Array.from(d)}async function It(e,t=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let s=xn(e),d=new Uint8Array(s.byteLength);d.set(s);let a=Math.floor(t/1e3/30),l=new Uint8Array(8),R=Math.floor(a/4294967296),v=a>>>0;l[0]=R>>>24&255,l[1]=R>>>16&255,l[2]=R>>>8&255,l[3]=R&255,l[4]=v>>>24&255,l[5]=v>>>16&255,l[6]=v>>>8&255,l[7]=v&255;let T=await crypto.subtle.importKey("raw",d,{name:"HMAC",hash:"SHA-1"},false,["sign"]),y=await crypto.subtle.sign("HMAC",T,l),h=new Uint8Array(y),B=h[h.length-1]&15;return (((h[B]&127)<<24|(h[B+1]&255)<<16|(h[B+2]&255)<<8|h[B+3]&255)%1e6).toString().padStart(6,"0")}var Wt="0.11.0";function wn(e){let t=new Date(e),d=Date.now()-t.getTime();if(d<6e4)return "just now";if(d<36e5)return `${Math.floor(d/6e4)}m ago`;if(d<864e5)return `${Math.floor(d/36e5)}h ago`;let a=t.getDate(),l=t.toLocaleString("en",{month:"short"}),R=t.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${l} ${a}, ${R}`}var _=({d:e,className:t,size:s=14})=>jsxRuntime.jsx("svg",{className:t,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})}),m={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01",bot:"M12 8V4H8M2 14h2M20 14h2M15 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M9 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M18 10a6 6 0 0 0-12 0v4a6 6 0 0 0 12 0Z",terminal:"M4 17l6-6-6-6M12 19h8",key:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4",shield:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10",copy:"M20 9h-9a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2-2v-9a2 2 0 0 0-2-2ZM5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1",search:"M11 17.25a6.25 6.25 0 1 1 0-12.5 6.25 6.25 0 0 1 0 12.5ZM16 16l4.5 4.5"};function kn(){let[e,t]=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,d=()=>s.classList.contains("dark")?"dark":s.classList.contains("light")?"light":null,a=d();a&&t(a);let l=window.matchMedia("(prefers-color-scheme: dark)"),R=T=>{let y=d();t(y||(T.matches?"dark":"light"));};l.addEventListener("change",R);let v=new MutationObserver(()=>{let T=d();t(T||(l.matches?"dark":"light"));});return v.observe(s,{attributes:true,attributeFilter:["class"]}),()=>{l.removeEventListener("change",R),v.disconnect();}},[]),e}function Sn(e){let t=e==="dark";return {bg:t?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:t?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:t?"#e5e5e5":"#1a1a1a",textMuted:t?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:t?"#555":"#999",border:t?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:t?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:t?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:t?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:t?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:t?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:t?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:t?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:t?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:t?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:t?"#888":"#aaa",btnHover:t?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var _n={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},Rn={pending:m.circle,pass:m.check,fail:m.x,skip:m.skip},Ft={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)"}},Tn=["app.supply-guard.io"];function Cn(e,t=[]){if(!e)return false;let s=e.toLowerCase();return [...Tn,...t].map(a=>a.toLowerCase()).includes(s)}var Mn=e=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:t=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:e.bg,border:t?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:t?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(t,s)=>({width:`${t}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:t=>{let s=Ft[t]||Ft.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:t=>({height:"100%",width:`${t}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:t=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${t}15`,color:t,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(t,s)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:t?`${s}33`:"transparent",color:t?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 dt(e){return e.split("/")[0].trim()}async function En(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 t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.opacity="0",t.style.pointerEvents="none",document.body.appendChild(t),t.focus(),t.select(),t.setSelectionRange(0,e.length);let s=document.execCommand("copy");return document.body.removeChild(t),s}catch{return false}}function $e({config:e,appSlug:t,environment:s,seededUsers:d,authToken:a,tk:l,compact:R=false,onExpand:v,onAuthExpired:T,refreshAuth:y,requestLogin:h,testRunId:B,testRunToken:j,ticketId:S,targetUrl:x,version:g,commitSha:n,prNumber:i,branchName:U}){let[N,z]=react.useState(false),[k,C]=react.useState(null),[A,X]=react.useState(null),[Q,f]=react.useState(null),[ze,ce]=react.useState(null),[se,ee]=react.useState(null),[te,ue]=react.useState(null);react.useEffect(()=>{s==="local"&&He();},[s]);let ve=react.useCallback(u=>{C(u),f(null),ce(null),ue(null);let $=Le(a);if(s!=="local"&&h&&$!==null&&$<=Date.now()){ee({slug:u,token:a||null}),ue(u),C(null),h();return}let P=E=>{f(E),ce(u),window.setTimeout(()=>{ce(L=>L===u?null:L),f(L=>L===E?null:L);},3e3);},M=new URLSearchParams({app_slug:t,seed_user_slug:u,environment:s});B&&M.set("test_run_id",B),j&&M.set("public_token",j),S&&M.set("ticket_id",S),x&&M.set("target_url",x),g&&M.set("version",g),n&&M.set("commit_sha",n),i&&M.set("pr_number",String(i)),U&&M.set("branch_name",U);let I=async E=>{let L={apikey:e.anonKey,Authorization:`Bearer ${E}`};try{let F=await fetch(`${e.serverUrl}/widget/totp-code?${M}`,{headers:L});if(!F.ok){let ye=await F.json().catch(()=>({error:`HTTP ${F.status}`}));return {ok:!1,status:F.status,error:ye.error||`HTTP ${F.status}`}}let Z=await F.json();return {ok:!0,code:String(Z.code)}}catch{return {ok:false,status:0,error:"Network error"}}},V=(async()=>{if(s==="local"){let F=await Ut(u);if(F)try{return {ok:!0,code:await It(F)}}catch{}}let E=await I(a||e.anonKey);if(E.ok||E.status!==401||!y)return E;let L=await y();return L?I(L):{ok:false,status:401,error:"Sign in to BotBuddy to refresh 2FA"}})(),D=null;try{if(typeof ClipboardItem<"u"&&navigator.clipboard?.write){let E=V.then(L=>{if(!L.ok)throw new Error(L.error);return new Blob([L.code],{type:"text/plain"})});D=navigator.clipboard.write([new ClipboardItem({"text/plain":E})]).then(()=>!0).catch(()=>!1);}}catch{}(async()=>{let E=await V;if(!E.ok){E.status===401?(ee({slug:u,token:a||null}),ue(u)):P(E.status===404?"No 2FA seed registered":E.error),C(null);return}let L=D?await D:false,F=L?true:await En(E.code),Z=L||F;X({slug:u,code:E.code,copied:Z}),window.setTimeout(()=>X(ye=>ye?.slug===u?null:ye),Z?2500:6e3),z(false),C(null);})();},[e.serverUrl,e.anonKey,a,t,s,B,j,S,x,g,n,i,U,y,h]),le=react.useCallback(u=>{ee({slug:u,token:a||null}),h?.();},[a,h]),we=react.useCallback(u=>{te===u?le(u):ve(u);},[te,le,ve]);react.useEffect(()=>{if(!se||!a||a===se.token)return;let u=se.slug;ee(null),ve(u);},[a,ve,se]);let ke=react.useRef(null),Ee=react.useRef(null);if(react.useLayoutEffect(()=>{if(!N)return;let u=ke.current,$=Ee.current;if(!u||!$||typeof window>"u")return;let P=()=>{let M=u.getBoundingClientRect(),I=$.getBoundingClientRect(),V=window.innerWidth,D=window.innerHeight,E=M.left,L=M.top-I.height-6;L<8&&(L=M.bottom+6);let F=Math.max(8,V-I.width-8),Z=Math.max(8,D-I.height-8);E=Math.min(Math.max(E,8),F),L=Math.min(Math.max(L,8),Z),$.style.left=`${Math.round(E)}px`,$.style.top=`${Math.round(L)}px`;};return P(),window.addEventListener("scroll",P,true),window.addEventListener("resize",P),()=>{window.removeEventListener("scroll",P,true),window.removeEventListener("resize",P);}},[N,d.length,Q]),react.useEffect(()=>{if(!N)return;let u=$=>{let P=$.target;Ee.current?.contains(P)||ke.current?.contains(P)||z(false);};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[N]),d.length===0)return null;if(R){let u=d.length>1,$=d[0],P=!u&&te===$,M=F=>{if(F.stopPropagation(),u&&v){v();return}we($);},I=!!ze,V=!!A,D=V&&A.copied,E=V&&!A.copied,L=P?l.blue:I?l.red:D?l.green:E?l.amber:l.purple;return jsxRuntime.jsxs("span",{onPointerDown:F=>F.stopPropagation(),onPointerUp:F=>F.stopPropagation(),onPointerMove:F=>F.stopPropagation(),onClick:M,style:{display:"inline-flex",alignItems:"center",gap:"3px",color:L,fontWeight:600,cursor:"pointer",letterSpacing:E?"0.08em":void 0},title:P?"Sign in to BotBuddy to refresh 2FA":I?Q||"Failed":E?`Clipboard blocked \u2014 code: ${A.code}`:u?`${d.length} 2FA personas`:`Copy 2FA code for ${d[0]}`,children:[jsxRuntime.jsx(_,{d:P?m.key:I?m.alert:D?m.check:E?m.copy:m.shield,size:10}),P?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Sign in"}):D?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Copied"}):E?jsxRuntime.jsx(jsxRuntime.Fragment,{children:A.code}):I?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Failed"}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["2FA",u&&` \xB7${d.length}`]})]})}if(d.length===1){let u=d[0],$=k===u,P=A?.slug===u,M=P&&A.copied,I=P&&!A.copied,V=ze===u,D=te===u,E=D?l.blue:V?l.red:M?l.green:I?l.amber:l.purple;return jsxRuntime.jsxs("button",{onClick:L=>{L.stopPropagation(),we(u);},disabled:$,style:{...Dt(E),cursor:$?"wait":"pointer",opacity:$?.6:1},title:D?"Sign in to BotBuddy to refresh 2FA":V?Q||"Failed":I?`Clipboard blocked \u2014 code: ${A.code}`:`Copy 2FA code for ${u}`,children:[jsxRuntime.jsx(_,{d:D?m.key:V?m.alert:M?m.check:I?m.copy:m.shield,size:12}),D?"Sign in":M?"Copied":I?A.code:V?"Failed":$?"\u2026":`2FA \xB7 ${u}`]})}let pe=!!te&&!N,ne=!!ze&&!N,Se=!!A&&A.copied,_e=!!A&&!A.copied,Ve=pe?l.blue:ne?l.red:Se?l.green:_e?l.amber:l.purple,Ye=N&&typeof document<"u"?reactDom.createPortal(jsxRuntime.jsxs("div",{ref:Ee,onPointerDown:u=>u.stopPropagation(),onMouseDown:u=>u.stopPropagation(),style:{position:"fixed",left:-9999,top:-9999,background:l.bg,border:`1px solid ${l.border}`,borderRadius:6,boxShadow:`0 8px 24px ${l.shadow}`,padding:4,minWidth:220,maxWidth:typeof window<"u"?Math.min(420,window.innerWidth-16):420,zIndex:1e5,fontFamily:"ui-monospace, SFMono-Regular, monospace"},children:[d.map(u=>{let $=k===u,P=te===u;return jsxRuntime.jsxs("button",{onClick:M=>{M.stopPropagation(),we(u);},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:P?l.blue:l.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},title:P?"Sign in to BotBuddy to refresh 2FA":void 0,onMouseEnter:M=>M.currentTarget.style.background=l.btnHover,onMouseLeave:M=>M.currentTarget.style.background="transparent",children:[jsxRuntime.jsx(_,{d:P?m.key:m.shield,size:10}),jsxRuntime.jsx("span",{style:{flex:1,overflowWrap:"anywhere",lineHeight:1.3},children:u}),P?jsxRuntime.jsx("span",{style:{color:l.blue,fontSize:9},children:"Sign in"}):$?jsxRuntime.jsx("span",{style:{color:l.textMuted,fontSize:9},children:"\u2026"}):null]},u)}),Q&&jsxRuntime.jsx("div",{style:{padding:"4px 8px",fontSize:9,color:l.red},children:Q})]}),document.body):null;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("button",{ref:ke,onClick:u=>{if(u.stopPropagation(),pe&&te){le(te);return}z($=>!$),f(null),ce(null);},style:{...Dt(Ve),cursor:"pointer"},title:pe?"Sign in to BotBuddy to refresh 2FA":ne?Q||"Failed":_e?`Clipboard blocked \u2014 code: ${A.code}`:"Choose a persona to copy a 2FA code for",children:[jsxRuntime.jsx(_,{d:pe?m.key:ne?m.alert:Se?m.check:_e?m.copy:m.shield,size:12}),pe?"Sign in":Se?"Copied":_e?A.code:ne?"Failed":`2FA \xB7 ${d.length}`,!pe&&jsxRuntime.jsx(_,{d:N?m.chevronUp:m.chevronDown,size:8})]}),Ye]})}function Dt(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 Ot="botbuddy-widget-state";function Nn({config:e,appSlug:t,environment:s,ticketId:d,testRunId:a,testRunToken:l,targetUrl:R,version:v,commitSha:T,prNumber:y,branchName:h,onNavigate:B,displayName:j="human",defaultMode:S="mini",defaultPosition:x}){let g=kn(),n=react.useMemo(()=>Sn(g),[g]),i=react.useMemo(()=>Mn(n),[n]),[U,N]=react.useState(false),[z,k]=react.useState(false),[C,A]=react.useState(false),X=react.useRef(false),Q=e.dashboardUrl||"https://app.bot-buddy.ai",f=lt(Q),ce=(()=>{try{let r=typeof window<"u"?localStorage.getItem(Ot):null;if(r)return JSON.parse(r)}catch{}return null})(),[se,ee]=react.useState(ce?.mode||S),[te,ue]=react.useState(""),[ve,le]=react.useState(null),[we,ke]=react.useState(null),[Ee,pe]=react.useState(new Set),[ne,Se]=react.useState(""),_e=react.useCallback(r=>{pe(p=>{let w=new Set(p);return w.has(r)?w.delete(r):w.add(r),w});},[]),Ve=ce?.x??x?.x??16,Ye=ce?.y??x?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:u,setPos:$,onPointerDown:P,onPointerMove:M,onPointerUp:I,didDrag:V}=et(Ve,Ye),D=react.useRef(null);react.useEffect(()=>{try{localStorage.setItem(Ot,JSON.stringify({mode:se,x:u.x,y:u.y}));}catch{}},[se,u.x,u.y]),react.useLayoutEffect(()=>{if(typeof window>"u")return;let r=D.current;if(!r)return;let p=r.getBoundingClientRect(),w=Qe(u.x,u.y,p.width,p.height,window.innerWidth,window.innerHeight);(w.x!==u.x||w.y!==u.y)&&$(w);}),react.useEffect(()=>{if(typeof window>"u")return;let r=()=>{let p=D.current;if(!p)return;let w=p.getBoundingClientRect(),H=Qe(u.x,u.y,w.width,w.height,window.innerWidth,window.innerHeight);(H.x!==u.x||H.y!==u.y)&&$(H);};return window.addEventListener("resize",r),()=>window.removeEventListener("resize",r)},[u.x,u.y,$]);let E=react.useRef(f.isAuthenticated);react.useEffect(()=>{!E.current&&f.isAuthenticated&&ee("max"),E.current=f.isAuthenticated;},[f.isAuthenticated]);let L="botbuddy-widget-max-size",F=()=>{try{let r=localStorage.getItem(L);if(r)return JSON.parse(r)}catch{}return {w:340,h:500}},[Z,ye]=react.useState(F),Ne=react.useRef(false),Pe=react.useRef({x:0,y:0,w:0,h:0}),Gt=react.useCallback(r=>{r.stopPropagation(),Ne.current=true,Pe.current={x:r.clientX,y:r.clientY,w:Z.w,h:Z.h},r.target.setPointerCapture(r.pointerId);},[Z]),Xt=react.useCallback(r=>{if(!Ne.current)return;let p=Math.max(280,Math.min(600,Pe.current.w+(r.clientX-Pe.current.x))),w=Math.max(300,Math.min(window.innerHeight*.9,Pe.current.h+(r.clientY-Pe.current.y)));ye({w:p,h:w});},[]),Zt=react.useCallback(()=>{Ne.current&&(Ne.current=false,ye(r=>(localStorage.setItem(L,JSON.stringify(r)),r)));},[]),re=R??(typeof window<"u"?window.location.href:void 0),bt=f.displayName||j,[de,mt]=react.useState(null);react.useEffect(()=>{if(f.isAuthenticated)return;let r=new URLSearchParams;l&&r.set("token",l),d&&r.set("ticket_id",d),r.set("app_slug",t),s&&r.set("environment",s),a&&r.set("test_run_id",a),re&&r.set("target_url",re),v&&r.set("version",v),T&&r.set("commit_sha",T),y&&r.set("pr_number",String(y)),h&&r.set("branch_name",h),fetch(`${e.serverUrl}/widget/preview?${r}`,{headers:{apikey:e.anonKey}}).then(p=>p.json()).then(p=>mt(p)).catch(()=>mt(null));},[f.isAuthenticated,e.serverUrl,e.anonKey,t,s,d,a,l,re,v,T,y,h]);let yt=react.useRef(false),Qt=react.useCallback(()=>{yt.current||f.logout();},[f.logout]),{run:b,widgetState:he,fetchRun:en,setVerdict:ht,markComplete:tn,resetRun:nn,setRun:xt}=rt({config:e,appSlug:t,environment:s,ticketId:d,testRunId:a,testRunToken:l,targetUrl:re,version:v,commitSha:T,prNumber:y?String(y):void 0,branchName:h,authToken:f.token,onAuthExpired:Qt});yt.current=!!b;let[vt,wt]=react.useState([]),[kt,Ae]=react.useState([]),[qe,St]=react.useState(false),[_t,Rt]=react.useState(null),[rn,Ue]=react.useState(false),ge=Cn(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);react.useEffect(()=>{if((s??"local")!=="local"||ge){wt([]);return}let r=true;return He().then(p=>{r&&wt(Object.keys(p||{}));}),()=>{r=false;}},[s,ge]);let on=react.useCallback(async()=>{if(!(!f.isAuthenticated||!f.token)){St(true),Rt(null);try{let r=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${f.token}`},body:JSON.stringify({app_slug:t,environment:s||"local",target_url:re,branch_name:h,commit_sha:T,pr_number:y,ticket_id:d,title:`${d||t} local validation`})}),p=await r.json().catch(()=>({}));if(!r.ok)throw new Error(p.error||`HTTP ${r.status}`);xt(p),ee("max");}catch(r){Rt(r.message);}finally{St(false);}}},[f.isAuthenticated,f.token,e.serverUrl,e.anonKey,t,s,re,h,T,y,d,xt]),Ie=react.useCallback(async(r,p,w)=>{ke(r);try{await ht(r,p,w,bt);}finally{ke(null),le(null),ue("");}},[ht,bt]),K=b?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},sn=K.total>0&&K.pending===0,Re=he==="completed",We=react.useMemo(()=>{let r=b?.test_cases||[];if(!ne.trim())return r;let p=ne.toLowerCase();return r.filter(w=>w.title.toLowerCase().includes(p)||w.description&&w.description.toLowerCase().includes(p)||w.url_path&&w.url_path.toLowerCase().includes(p)||w.seed_user&&w.seed_user.toLowerCase().includes(p))},[b?.test_cases,ne]),Tt=react.useMemo(()=>{let r=We,p=b?.test_cases||[];if(new Set(p.map(J=>J.source_pr_number)).size<=1)return null;let H=[],be=new Map;r.forEach(J=>{let q=J.source_pr_number;be.has(q)||be.set(q,[]),be.get(q).push(J);});let Bt=[...be.keys()].sort((J,q)=>J===null?1:q===null?-1:q-J);for(let J of Bt){let q=be.get(J),Ge={total:q.length,pass:0,fail:0,skip:0,pending:0};q.forEach(zt=>{zt.verdict in Ge&&Ge[zt.verdict]++;}),H.push({key:J!=null?`pr-${J}`:"general",label:J!=null?`PR #${J}`:"General",cases:q,summary:Ge});}return H.filter(J=>J.cases.length>0)},[We,b?.test_cases]),Ct=K.total>0?(K.pass+K.fail)/K.total*100:0,Y=s??b?.environment??null,fe=react.useMemo(()=>{if(!Y||Y==="production"||ge)return [];let r=b?.test_cases||[],p=new Set;for(let w of r)w.seed_user&&p.add(dt(w.seed_user));if(Y==="local")for(let w of vt)p.add(dt(w));for(let w of kt)p.add(dt(w));return [...p]},[b?.test_cases,Y,vt,kt,ge]);react.useEffect(()=>{if(!Y||Y==="production"||ge||!f.isAuthenticated||!f.token){Ae([]);return}let r=true,p=`${e.serverUrl}/widget/totp-seeds?${new URLSearchParams({app_slug:t,environment:Y})}`,w=H=>fetch(p,{headers:{apikey:e.anonKey,Authorization:`Bearer ${H}`}});return (async()=>{try{let H=await w(f.token);if(H.status===401&&f.refreshNow){let q=await f.refreshNow();q&&(H=await w(q));}if(!r)return;if(!H.ok){Ae([]);return}let be=await H.json().catch(()=>null),J=(Array.isArray(be?.seeds)?be.seeds:[]).map(q=>q?.seed_user_slug).filter(q=>typeof q=="string"&&q.length>0);Ae(J);}catch{r&&Ae([]);}})(),()=>{r=false;}},[Y,ge,f.isAuthenticated,f.token,f.refreshNow,t,e.serverUrl,e.anonKey]);let Je=react.useMemo(()=>{let r=b?.auto_tooltip_seconds??de?.auto_tooltip_seconds;return r!=null&&r>0?r*1e3:0},[b,de]),Mt=he==="ready"||he==="completed"||de?.enabled&&de.run;react.useEffect(()=>{if(!Mt||X.current||Je<=0)return;X.current=true,k(true);let r=window.setTimeout(()=>k(false),Je);return ()=>window.clearTimeout(r)},[Mt,Je]);let Et=r=>jsxRuntime.jsxs("div",{style:i.caseRow,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsx("div",{style:{marginTop:"2px",flexShrink:0,color:_n[r.verdict]},children:we===r.id?jsxRuntime.jsx(_,{d:m.loader,className:""}):jsxRuntime.jsx(_,{d:Rn[r.verdict],className:""})}),jsxRuntime.jsxs("div",{style:{minWidth:0,flex:1},children:[jsxRuntime.jsx("div",{style:{fontSize:"10px",color:n.text,lineHeight:1.3},children:r.title}),r.description&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:n.gripColor,marginTop:"2px"},children:r.description}),r.seed_user&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:n.amber,marginTop:"3px",display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",background:`${n.amber}12`,border:`1px solid ${n.amber}30`},children:[jsxRuntime.jsx(_,{d:m.key,size:10}),jsxRuntime.jsx("span",{children:r.seed_user})]}),r.url_path&&jsxRuntime.jsxs("a",{href:r.url_path,target:"_blank",rel:"noopener noreferrer",onClick:p=>{p.stopPropagation(),B&&(p.preventDefault(),B(r.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(_,{d:m.externalLink,size:10}),r.url_path]}),r.verdict==="fail"&&r.fail_reason&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:n.red,marginTop:"2px"},children:["\u2717 ",r.fail_reason]})]})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(p=>jsxRuntime.jsx("button",{onClick:()=>{if(r.verdict===p){Ie(r.id,"pending"),le(null);return}if(p==="fail"){le(r.id),ue("");return}le(null),Ie(r.id,p);},disabled:we!==null,style:i.verdictBtn(r.verdict===p,p==="pass"?n.green:p==="fail"?n.red:n.amber),children:p.toUpperCase()},p)),r.created_by_agent_name&&jsxRuntime.jsxs("span",{style:{fontSize:"8px",color:n.purple,marginLeft:"4px",display:"inline-flex",alignItems:"center",gap:"2px"},children:[jsxRuntime.jsx(_,{d:m.bot,size:8}),r.created_by_agent_name]}),r.verdict_by_display_name&&jsxRuntime.jsxs("span",{style:{fontSize:"8px",color:n.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[r.verdict_by_display_name,r.verdict_at&&jsxRuntime.jsx("span",{style:{opacity:.7},children:wn(r.verdict_at)})]})]}),ve===r.id&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:te,onChange:p=>ue(p.target.value),onKeyDown:p=>{p.key==="Enter"&&Ie(r.id,"fail",te.trim()||void 0),p.key==="Escape"&&(le(null),ue(""));},placeholder:"Reason (optional)...",style:i.input}),jsxRuntime.jsx("button",{onClick:()=>{Ie(r.id,"fail",te.trim()||void 0);},style:i.verdictBtn(true,n.red),children:"\u2713"})]})]},r.id);if((he==="no-match"||he==="loading")&&!(!f.isAuthenticated&&de?.enabled&&de.run)){if(!(Y==="local"&&!ge))return null}if(!f.isAuthenticated&&de?.enabled&&de.run){let r=de.run,p=r.summary,w=r.status==="completed";return jsxRuntime.jsx("div",{ref:D,style:{...i.root,left:u.x,top:u.y},children:jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>N(true),onMouseLeave:()=>{N(false),A(false),k(false);},children:[jsxRuntime.jsxs("div",{style:{...i.pill(w),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:P,onPointerMove:M,onPointerUp:()=>{I();},children:[jsxRuntime.jsx(_,{d:m.grip,size:10,className:""}),r.ticket_id&&r.ticket_url?jsxRuntime.jsx("a",{href:r.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:H=>H.stopPropagation(),style:{color:n.amber,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:r.ticket_id}):null,r.pr_url?jsxRuntime.jsxs("a",{href:r.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:H=>H.stopPropagation(),style:{color:n.blue,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:["PR#",r.pr_number??r.pr_id]}):null,r.created_by_agent_name?r.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${r.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",onClick:H=>H.stopPropagation(),style:{color:n.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(_,{d:m.terminal,size:10}),r.created_by_agent_name]}):jsxRuntime.jsxs("span",{style:{color:n.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(_,{d:m.bot,size:10}),r.created_by_agent_name]}):null,jsxRuntime.jsxs("span",{style:w?{color:n.green}:void 0,children:[p.pass,"/",p.total]}),p.fail>0&&jsxRuntime.jsxs("span",{style:{color:n.red},children:[p.fail,"\u2717"]}),jsxRuntime.jsx("span",{onClick:H=>{H.stopPropagation(),f.openLogin();},style:{color:n.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!C&&(U||z)&&r.title&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsxRuntime.jsx("div",{style:{fontSize:"11px",fontWeight:700,color:n.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:r.title}),(r.description||r.intro_notes)&&jsxRuntime.jsx("div",{style:{fontSize:"10px",color:n.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:r.description||r.intro_notes}),jsxRuntime.jsx("div",{style:{marginTop:"4px",fontSize:"9px",color:n.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!f.isAuthenticated)return jsxRuntime.jsxs("div",{ref:D,style:{...i.root,left:u.x,top:u.y,width:220,minHeight:0,cursor:"move",userSelect:"none",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`},onPointerDown:P,onPointerMove:M,onPointerUp:I,children:[jsxRuntime.jsx("div",{style:{...i.handle,borderBottom:"none"},children:jsxRuntime.jsxs("div",{style:i.sub,children:[jsxRuntime.jsx(_,{d:m.grip,size:10,className:""}),jsxRuntime.jsx(_,{d:m.clipboard,size:12,className:""}),jsxRuntime.jsx("span",{style:{fontWeight:600},children:"BotBuddy"})]})}),jsxRuntime.jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[jsxRuntime.jsx("div",{style:{fontSize:"9px",color:n.textMuted,marginBottom:"8px"},children:"Sign in to access test cases"}),Y==="local"&&fe.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsxRuntime.jsx($e,{config:e,appSlug:t,environment:Y,seededUsers:fe,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:n,testRunId:b?.id||a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:T,prNumber:y,branchName:h,onAuthExpired:f.logout})}),jsxRuntime.jsx("button",{onClick:r=>{r.stopPropagation(),f.openLogin();},style:{fontSize:"10px",fontWeight:600,padding:"6px 16px",borderRadius:"6px",border:`1px solid ${n.green}`,background:`${n.green}22`,color:n.green,cursor:"pointer",width:"100%"},children:"Sign in to test"})]})]});if(!b&&Y==="local"&&!ge)return rn?jsxRuntime.jsx("div",{ref:D,style:{...i.root,left:u.x,top:u.y},children:jsxRuntime.jsxs("div",{style:i.card(240,false),children:[jsxRuntime.jsxs("div",{style:i.handle,onPointerDown:P,onPointerMove:M,onPointerUp:I,onClick:()=>{V.current||Ue(false);},children:[jsxRuntime.jsx(_,{d:m.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:i.title,children:"BotBuddy"}),h&&jsxRuntime.jsx("div",{style:i.sub,children:jsxRuntime.jsxs("span",{children:["\u2387 ",h]})})]}),jsxRuntime.jsx(_,{d:m.chevronUp,className:""}),jsxRuntime.jsx("button",{style:i.btn,onClick:r=>{r.stopPropagation(),Ue(false);},children:jsxRuntime.jsx(_,{d:m.minus,className:""})})]}),jsxRuntime.jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[fe.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsxRuntime.jsx($e,{config:e,appSlug:t,environment:Y,seededUsers:fe,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:n,testRunId:a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:T,prNumber:y,branchName:h,onAuthExpired:f.logout})}),jsxRuntime.jsx("button",{onClick:r=>{r.stopPropagation(),on();},disabled:qe,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${n.green}`,background:`${n.green}22`,color:n.green,cursor:qe?"wait":"pointer",width:"100%"},children:qe?"Creating...":"Create test run for this branch"}),_t&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:n.red,marginTop:"8px"},children:_t})]})]})}):jsxRuntime.jsx("div",{ref:D,style:{...i.root,left:u.x,top:u.y},children:jsxRuntime.jsxs("div",{style:{...i.pill(false),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:P,onPointerMove:M,onPointerUp:()=>{I(),V.current||Ue(true);},children:[jsxRuntime.jsx(_,{d:m.grip,size:9,className:""}),jsxRuntime.jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),fe.length>0&&jsxRuntime.jsx($e,{config:e,appSlug:t,environment:Y,seededUsers:fe,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:n,compact:true,onExpand:()=>Ue(true),testRunId:a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:T,prNumber:y,branchName:h,onAuthExpired:f.logout})]})});let Nt=()=>{V.current||(k(false),ee(r=>{let p=r==="mini"?"max":"mini";return A(p==="mini"),p}));},Pt=({icon:r,onClick:p})=>jsxRuntime.jsx("button",{style:i.btn,onClick:w=>{w.stopPropagation(),p(w);},children:jsxRuntime.jsx(_,{d:r,className:""})}),Lt=()=>jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${n.borderSubtle}`,flexShrink:0},children:[b?.pr_url&&jsxRuntime.jsxs("a",{href:b.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link(n.blue),textDecoration:"none"},children:[jsxRuntime.jsx(_,{d:m.pr,size:12}),b.pr_number?`PR#${b.pr_number}`:b.pr_id||"PR",jsxRuntime.jsx(_,{d:m.externalLink,size:8})]}),b?.ticket_url&&jsxRuntime.jsxs("a",{href:b.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link(n.amber),textDecoration:"none"},children:[jsxRuntime.jsx(_,{d:m.ticket,size:12}),b.ticket_id||"Ticket",jsxRuntime.jsx(_,{d:m.externalLink,size:8})]}),b?.created_by_agent_name&&(b.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${b.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...i.link(n.purple),textDecoration:"none"},children:[jsxRuntime.jsx(_,{d:m.bot,size:12}),b.created_by_agent_name,jsxRuntime.jsx(_,{d:m.externalLink,size:8})]}):jsxRuntime.jsxs("span",{style:{...i.link(n.purple)},children:[jsxRuntime.jsx(_,{d:m.bot,size:12}),b.created_by_agent_name]})),Y&&jsxRuntime.jsx($e,{config:e,appSlug:t,environment:Y,seededUsers:fe,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:n,testRunId:b?.id||a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:T,prNumber:y,branchName:h,onAuthExpired:f.logout}),jsxRuntime.jsx("span",{style:{...i.badge(b?.environment||"custom"),marginLeft:"auto"},children:b?.environment})]}),$t=()=>jsxRuntime.jsxs("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:`1px solid ${n.borderSubtle}`,background:n.bgSoft,flexShrink:0},children:[jsxRuntime.jsxs("button",{onClick:()=>{navigator.clipboard.writeText(Wt);},style:{fontSize:"9px",fontWeight:600,color:n.versionText,letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxRuntime.jsxs("span",{style:{color:n.versionNum},children:["v",Wt]})]}),f.isAuthenticated&&(f.isExpired?jsxRuntime.jsx("button",{onClick:r=>{r.stopPropagation(),f.openLogin();},style:{fontSize:"8px",color:n.blue,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Widget session expired \u2014 sign in to refresh",children:"sign in"}):jsxRuntime.jsx("button",{onClick:r=>{r.stopPropagation(),f.logout();},style:{fontSize:"8px",color:n.textFaint,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Sign out of widget",children:"sign out"}))]});return jsxRuntime.jsxs("div",{ref:D,style:{...i.root,left:u.x,top:u.y},children:[se==="mini"&&jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>N(true),onMouseLeave:()=>{N(false),A(false),k(false);},children:[jsxRuntime.jsxs("div",{style:{...i.pill(Re),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:P,onPointerMove:M,onPointerUp:()=>{I(),V.current||Nt();},children:[jsxRuntime.jsx(_,{d:m.grip,size:9,className:""}),b?.ticket_id&&jsxRuntime.jsx("span",{style:{color:n.amber,fontWeight:600},children:b.ticket_id}),b?.pr_number&&jsxRuntime.jsxs("span",{style:{color:n.blue,fontWeight:600},children:["PR#",b.pr_number]}),jsxRuntime.jsxs("span",{style:Re?{color:n.green}:void 0,children:[K.pass,"/",K.total]}),K.fail>0&&jsxRuntime.jsxs("span",{style:{color:n.red},children:[K.fail,"\u2717"]}),Y&&jsxRuntime.jsx($e,{config:e,appSlug:t,environment:Y,seededUsers:fe,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:n,compact:true,onExpand:()=>ee("expanded"),testRunId:b?.id||a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:T,prNumber:y,branchName:h,onAuthExpired:f.logout})]}),!C&&(U||z)&&b?.title&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsxRuntime.jsx("div",{style:{fontSize:"11px",fontWeight:700,color:n.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:b.title}),(b.description||b.intro_notes)&&jsxRuntime.jsx("div",{style:{fontSize:"10px",color:n.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:b.description||b.intro_notes})]})]}),se==="expanded"&&jsxRuntime.jsxs("div",{style:i.card(300,Re),children:[jsxRuntime.jsxs("div",{style:i.handle,onPointerDown:P,onPointerMove:M,onPointerUp:I,onClick:Nt,children:[jsxRuntime.jsx(_,{d:m.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:i.title,children:b?.title}),jsxRuntime.jsx("div",{style:i.sub,children:b?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",b.branch_name]})})]}),jsxRuntime.jsx(_,{d:m.chevronUp,className:""}),jsxRuntime.jsx(Pt,{icon:m.minus,onClick:()=>{k(false),A(true),ee("mini");}})]}),jsxRuntime.jsxs("div",{style:i.stats,children:[jsxRuntime.jsxs("span",{style:{color:n.green},children:[K.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:n.red},children:[K.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:n.amber},children:[K.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:n.gripColor},children:[K.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:K.total})]}),b?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:n.gripColor,borderBottom:`1px solid ${n.borderSubtle}`,flexShrink:0},children:b.description}),Lt(),$t(),jsxRuntime.jsx("div",{style:i.progress,children:jsxRuntime.jsx("div",{style:i.progressBar(Ct)})})]}),se==="max"&&jsxRuntime.jsxs("div",{style:{...i.card(Z.w,Re),height:Z.h,position:"relative"},children:[jsxRuntime.jsxs("div",{style:i.handle,onPointerDown:P,onPointerMove:M,onPointerUp:I,onClick:()=>{V.current||ee("expanded");},children:[jsxRuntime.jsx(_,{d:m.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:i.title,children:b?.title}),jsxRuntime.jsx("div",{style:i.sub,children:b?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",b.branch_name]})})]}),jsxRuntime.jsx(_,{d:m.chevronDown,className:""}),jsxRuntime.jsx(Pt,{icon:m.minus,onClick:()=>{k(false),A(true),ee("mini");}})]}),jsxRuntime.jsxs("div",{style:i.stats,children:[jsxRuntime.jsxs("span",{style:{color:n.green},children:[K.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:n.red},children:[K.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:n.amber},children:[K.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:n.gripColor},children:[K.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:K.total})]}),b?.intro_notes&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${n.borderSubtle}`,fontSize:"10px",color:n.textMuted,fontStyle:"italic",flexShrink:0},children:b.intro_notes}),(b?.test_cases||[]).length>5&&jsxRuntime.jsxs("div",{style:{padding:"4px 12px",borderBottom:`1px solid ${n.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[jsxRuntime.jsx(_,{d:m.search,size:11,className:""}),jsxRuntime.jsx("input",{value:ne,onChange:r=>Se(r.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:n.text,fontFamily:"monospace"}}),ne&&jsxRuntime.jsx("button",{onClick:()=>Se(""),style:{background:"none",border:"none",cursor:"pointer",color:n.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),he==="error"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsxRuntime.jsx(_,{d:m.alert,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:n.red},children:"Failed to load"}),jsxRuntime.jsx("button",{onClick:en,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),Re&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg},children:[jsxRuntime.jsx(_,{d:m.checkAll,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",color:n.green,flex:1},children:"Run completed"}),jsxRuntime.jsx("button",{onClick:nn,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),he!=="error"&&jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(b?.test_cases||[]).length===0?jsxRuntime.jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:"No test cases"}):We.length===0?jsxRuntime.jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:['No matches for "',ne,'"']}):Tt?Tt.map(r=>{let p=Ee.has(r.key);return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>_e(r.key),style:{width:"100%",display:"flex",alignItems:"center",gap:"6px",padding:"5px 12px",background:n.bgSoft,cursor:"pointer",border:"none",borderLeft:"none",borderRight:"none",borderBottomStyle:"solid",borderTopStyle:"solid",borderBottomWidth:"1px",borderTopWidth:"1px",borderBottomColor:n.borderSubtle,borderTopColor:n.borderSubtle,backgroundColor:n.bgSoft},children:[jsxRuntime.jsx(_,{d:p?m.chevronDown:m.chevronUp,size:10,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",fontWeight:700,color:n.blue,flex:1,textAlign:"left"},children:r.label}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:n.green},children:[r.summary.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:n.red},children:[r.summary.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:n.gripColor},children:[r.summary.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{fontSize:"9px",color:n.textFaint},children:r.summary.total})]}),!p&&r.cases.map(w=>Et(w))]},r.key)}):We.map(r=>Et(r))}),sn&&!Re&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",borderTop:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg,display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsxRuntime.jsx("span",{style:{fontSize:"9px",color:n.green},children:"All resolved"}),jsxRuntime.jsx("button",{onClick:tn,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:n.green,border:`1px solid ${n.greenBorderSubtle}`,cursor:"pointer"},children:"COMPLETE"})]}),Lt(),$t(),jsxRuntime.jsx("div",{style:i.progress,children:jsxRuntime.jsx("div",{style:i.progressBar(Ct)})}),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:Gt,onPointerMove:Xt,onPointerUp:Zt,onPointerEnter:r=>r.currentTarget.style.opacity="0.7",onPointerLeave:r=>{Ne.current||(r.currentTarget.style.opacity="0.3");},children:jsxRuntime.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsxRuntime.jsx("path",{d:"M7 1v6H1",fill:"none",stroke:n.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}var Bn=1e4,Be=new Map;var Ke=class extends Error{};async function zn(e,t,s){let d={headers:{authorization:`Bearer ${t}`}};try{return await fetch(e,{...d,signal:s})}catch(a){if(a instanceof TypeError&&/signal/i.test(a.message)&&!s.aborted)return fetch(e,d);throw a}}function An(e){let t=e;return !!t&&typeof t=="object"&&typeof t.tenant=="string"&&Array.isArray(t.entries)&&t.entries.every(s=>!!s&&typeof s.id=="string"&&typeof s.title=="string"&&!!s.body&&Array.isArray(s.body.ast)&&Array.isArray(s.links))}function ct({endpoint:e,getToken:t,timeoutMs:s=Bn}){let[d,a]=react.useState(()=>({feed:null,error:null,loading:true,stale:false})),[l,R]=react.useState(0),v=react.useRef(t);v.current=t,react.useEffect(()=>{let y=new AbortController,h=true,B=false,j=setTimeout(()=>{B=true,y.abort();},s),S=new Promise((n,i)=>{y.signal.addEventListener("abort",()=>i(new Error("timeout")),{once:true});});S.catch(()=>{}),a(n=>({...n,error:null,loading:true}));let x=null,g=(n,i)=>{if(i&&Be.delete(e),!h)return;let U=i||x===null?void 0:Be.get(e)?.get(x);a({feed:U??null,error:n,loading:false,stale:!!U});};return (async()=>{try{let n;try{n=await Promise.race([Promise.resolve().then(()=>v.current()),S]);}catch(z){throw B||y.signal.aborted?z:new Ke("token_unavailable")}x=n;let i=await Promise.race([zn(e,n,y.signal),S]),U=i.status===401||i.status===403;U&&Be.delete(e);let N=null;try{N=await Promise.race([i.json(),S]);}catch(z){if(B&&!U)throw z;N=null;}if(!h)return;if(i.ok)if(!An(N))g("invalid_feed",!1);else {let z=Be.get(e)??new Map;z.set(n,N),Be.set(e,z),a({feed:N,error:null,loading:!1,stale:!1});}else {let z=N?.error;g(typeof z=="string"?z:`http_${i.status}`,U);}}catch(n){n instanceof Ke?g(n.message,true):g(B?"timeout":n instanceof Error&&n.message||"unavailable",false);}finally{clearTimeout(j);}})(),()=>{h=false,clearTimeout(j),y.abort();}},[e,l,s]);let T=react.useCallback(()=>R(y=>y+1),[]);return {...d,reload:T}}var gt=["accent","fg","bg","muted","border","radius","font"],Un={accent:"hsl(var(--primary))",fg:"hsl(var(--foreground))",bg:"hsl(var(--card))",muted:"hsl(var(--muted-foreground))",border:"hsl(var(--border))",radius:"var(--radius)",font:"inherit"},Me=(e,t)=>t===void 0?`var(--bbrn-${e},var(--_bbrn-${e}))`:`var(--bbrn-${e},var(--_bbrn-${e},${t}))`,ut=Me("accent","currentColor"),In=Me("muted","color-mix(in srgb,currentColor 72%,transparent)"),pt=Me("border","color-mix(in srgb,currentColor 22%,transparent)"),Wn=`@layer bbrn{
|
|
2
|
-
.bbrn-root{${
|
|
3
|
-
.bbrn-root .bbrn-entry{background:${
|
|
1
|
+
'use strict';var react=require('react'),reactDom=require('react-dom'),jsxRuntime=require('react/jsx-runtime');var Me=8;function et(e,t,s,l,i,d){let T=Math.max(Me,i-s-Me),w=Math.max(Me,d-l-Me);return {x:Math.min(Math.max(e,Me),T),y:Math.min(Math.max(t,Me),w)}}function tt(e,t){let[s,l]=react.useState({x:e,y:t}),i=react.useRef(false),d=react.useRef({x:0,y:0}),T=react.useRef(false),w=react.useCallback(f=>{i.current=true,T.current=false,d.current={x:f.clientX-s.x,y:f.clientY-s.y},f.target.setPointerCapture(f.pointerId);},[s]),C=react.useCallback(f=>{i.current&&(T.current=true,l({x:f.clientX-d.current.x,y:f.clientY-d.current.y}));},[]),h=react.useCallback(()=>{i.current=false;},[]);return {pos:s,setPos:l,onPointerDown:w,onPointerMove:C,onPointerUp:h,didDrag:T}}function nt(e,t,s){let l=react.useRef(s);l.current=s,react.useEffect(()=>{if(!t)return;if(e.supabaseUrl){let d=false,T=null,w=()=>{d||T||(T=setInterval(()=>l.current(),15e3));},C=null;try{let b=new URL(e.supabaseUrl),r=["localhost","127.0.0.1","::1"].includes(b.hostname);if(b.protocol==="http:"&&!r)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");b.protocol=b.protocol==="https:"?"wss:":"ws:",C=b.toString().replace(/\/$/,"");}catch{w();}let h=null,f=null,L=null,j=0,_=()=>{if(!(d||!C)){try{h=new WebSocket(`${C}/realtime/v1/websocket?apikey=${e.anonKey}&vsn=1.0.0`);}catch{w();return}h.onopen=()=>{if(d||!h)return;let b={topic:`realtime:public:test_run_cases:test_run_id=eq.${t}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_run_cases",filter:`test_run_id=eq.${t}`}]}},ref:String(++j)};h.send(JSON.stringify(b));let r={topic:`realtime:public:test_runs:id=eq.${t}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_runs",filter:`id=eq.${t}`}]}},ref:String(++j)};h.send(JSON.stringify(r)),f=setInterval(()=>{h?.readyState===WebSocket.OPEN&&h.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++j)}));},3e4);},h.onmessage=b=>{try{JSON.parse(b.data).event==="postgres_changes"&&l.current();}catch{}},h.onclose=()=>{x(),d||(L=setTimeout(_,3e3));},h.onerror=()=>{h?.close();};}},x=()=>{f&&(clearInterval(f),f=null);};return _(),()=>{d=true,x(),L&&clearTimeout(L),T&&clearInterval(T),h&&(h.onclose=null,h.onerror=null,h.close());}}let i=setInterval(()=>l.current(),15e3);return ()=>clearInterval(i)},[e.supabaseUrl,e.anonKey,t]);}var fn="botbuddy:created-test-run:";function bn(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function mn(e){return `${fn}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",bn(e.targetUrl),e.branchName||""].join("|"))}`}function De(e,t){let s={apikey:e.anonKey};return t?s.Authorization=`Bearer ${t}`:e.apiKey?s.Authorization=`Bearer ${e.apiKey}`:s.Authorization=`Bearer ${e.anonKey}`,s}async function yn(e){if(e)return e;try{let t=await fetch("/.botbuddy-token",{cache:"no-store"});if(t.ok){let s=(await t.text()).trim();if(s.startsWith("public_"))return s}}catch{}try{let t=undefined?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(t&&typeof t=="string"&&t.startsWith("public_"))return t}catch{}return null}function ot(e){let[t,s]=react.useState(null),[l,i]=react.useState("loading"),d=mn(e),[T,w]=react.useState(()=>{if(e.testRunId)return e.testRunId;try{return localStorage.getItem(d)||void 0}catch{return}}),C=e.testRunId||T,h=react.useCallback(x=>{if(s(x),!!x?.id){w(x.id);try{localStorage.setItem(d,x.id);}catch{}}},[d]),f=react.useCallback(async()=>{try{let x=await yn(e.testRunToken);if(!x&&!C){i("no-match"),s(null);return}if(x&&!e.ticketId){i("no-match"),s(null);return}let b=new URLSearchParams;x&&b.set("token",x),e.ticketId&&b.set("ticket_id",e.ticketId),b.set("app_slug",e.appSlug),e.environment&&b.set("environment",e.environment),C&&b.set("test_run_id",C),e.targetUrl&&b.set("target_url",e.targetUrl),e.version&&b.set("version",e.version),e.commitSha&&b.set("commit_sha",e.commitSha),e.prNumber&&b.set("pr_number",String(e.prNumber)),e.branchName&&b.set("branch_name",e.branchName);let r=await fetch(`${e.config.serverUrl}/widget/test-run?${b.toString()}`,{headers:De(e.config,e.authToken)});if(r.status===404){i("no-match"),s(null);return}if(r.status===401||r.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),i("error");return}if(!r.ok){i("error");return}let c=await r.json();if(!c||c.run===null){i("no-match"),s(null);return}h(c),i(c.status==="completed"?"completed":"ready");}catch{i("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,h]);return react.useEffect(()=>{f();},[f]),nt(e.config,t?.id,f),{run:t,widgetState:l,fetchRun:f,setVerdict:async(x,b,r,c="human")=>(s(v=>{if(!v)return null;let B=v.test_cases.map(W=>W.id===x?{...W,verdict:b,fail_reason:b==="fail"&&r||null,verdict_by_display_name:c,verdict_at:new Date().toISOString()}:W),V={total:B.length,pending:0,pass:0,fail:0,skip:0};return B.forEach(W=>{W.verdict in V&&V[W.verdict]++;}),{...v,test_cases:B,summary:V}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${x}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...De(e.config,e.authToken)},body:JSON.stringify({verdict:b,fail_reason:r,display_name:c})})).ok),markComplete:async()=>t?(s(b=>b?{...b,status:"completed"}:null),i("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${t.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...De(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!t)return false;let x=await fetch(`${e.config.serverUrl}/widget/test-runs/${t.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...De(e.config,e.authToken)}});return x.ok&&f(),x.ok},setRun:h}}var at="botbuddy-widget-auth-token",lt="botbuddy-widget-auth-name";function Le(e){if(!e)return null;try{let t=e.split(".")[1];if(!t)return null;let s=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(t.length/4)*4,"="),l=atob(s),i=JSON.parse(l);return typeof i.exp=="number"?i.exp*1e3:null}catch{return null}}var xn=2500,vn=6e4;function dt(e){let[t,s]=react.useState(()=>{try{return localStorage.getItem(at)}catch(_){return console.warn("Unable to read BotBuddy widget auth token",_),null}}),[l,i]=react.useState(()=>{try{return localStorage.getItem(lt)}catch(_){return console.warn("Unable to read BotBuddy widget display name",_),null}}),d=react.useRef(null),T=react.useCallback((_,x)=>{s(_),x&&i(x);try{localStorage.setItem(at,_),x&&localStorage.setItem(lt,x);}catch(b){console.warn("Unable to persist BotBuddy widget auth token",b);}},[]);react.useEffect(()=>{let _=new URL(e).origin,x=b=>{b.origin===_&&b.data?.type==="botbuddy-widget-auth"&&b.data.token&&T(b.data.token,b.data.displayName||"human");};return window.addEventListener("message",x),()=>window.removeEventListener("message",x)},[e,T]);let w=react.useCallback(()=>{if(d.current)return d.current;if(typeof window>"u"||typeof document>"u")return Promise.resolve(null);let _=new URL(e).origin,x=new URL("/widget-auth",e);x.searchParams.set("silent","1"),x.searchParams.set("origin",window.location.origin);let b=new Promise(r=>{let c=document.createElement("iframe");c.setAttribute("aria-hidden","true"),c.style.position="fixed",c.style.width="1px",c.style.height="1px",c.style.opacity="0",c.style.pointerEvents="none",c.style.border="0",c.style.left="-9999px",c.style.top="-9999px",c.src=x.toString();let F=false,v=()=>{window.removeEventListener("message",B),clearTimeout(V);try{c.remove();}catch{}d.current=null;},B=W=>{if(W.origin===_){if(W.data?.type==="botbuddy-widget-auth-failed"){if(F)return;F=true,r(null),v();return}W.data?.type!=="botbuddy-widget-auth"||!W.data.token||F||(F=true,r(String(W.data.token)),v());}},V=setTimeout(()=>{F||(F=true,r(null),v());},xn);window.addEventListener("message",B),document.body.appendChild(c);});return d.current=b,b},[e]);react.useEffect(()=>{if(!t)return;let _=Le(t);if(!_)return;let x=_-Date.now()-vn,b=window.setTimeout(()=>{w();},Math.max(0,x));return ()=>window.clearTimeout(b)},[t,w]);let C=react.useCallback(()=>{let _=new URL("/widget-auth",e);_.searchParams.set("origin",window.location.origin);let x=420,b=520,r=window.screenX+(window.innerWidth-x)/2,c=window.screenY+(window.innerHeight-b)/2;window.open(_.toString(),"botbuddy-auth",`width=${x},height=${b},left=${r},top=${c},popup=yes`);},[e]),[,h]=react.useState(0);react.useEffect(()=>{let _=Le(t);if(!_)return;let x=_-Date.now();if(x<=0)return;let b=window.setTimeout(()=>h(r=>r+1),x);return ()=>window.clearTimeout(b)},[t]);let f=react.useCallback(()=>{s(null),i(null);try{localStorage.removeItem(at),localStorage.removeItem(lt);}catch(_){console.warn("Unable to clear BotBuddy widget auth token",_);}},[]),L=Le(t),j=L!==null&&L<=Date.now();return {token:t,displayName:l,isAuthenticated:!!t,isExpired:j,openLogin:C,refreshNow:w,logout:f}}var He=null;function wn(){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 Ke(){return He||(He=(async()=>{if(typeof fetch>"u")return null;try{let e=await fetch(wn(),{cache:"no-store"});if(!e.ok)return null;let t=await e.json();if(!t||typeof t!="object"||Array.isArray(t))return null;let s={};for(let[l,i]of Object.entries(t))typeof i=="string"&&i.length>0&&(s[l]=i);return s}catch{return null}})(),He)}async function It(e){return (await Ke())?.[e]??null}function kn(e){let t=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),s="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",l=[],i=0,d=0;for(let T of t){let w=s.indexOf(T);if(w<0)throw new Error("Invalid Base32 character in TOTP secret");d=d<<5|w,i+=5,i>=8&&(i-=8,l.push(d>>>i&255));}return Uint8Array.from(l)}async function Ft(e,t=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let s=kn(e),l=new Uint8Array(s.byteLength);l.set(s);let i=Math.floor(t/1e3/30),d=new Uint8Array(8),T=Math.floor(i/4294967296),w=i>>>0;d[0]=T>>>24&255,d[1]=T>>>16&255,d[2]=T>>>8&255,d[3]=T&255,d[4]=w>>>24&255,d[5]=w>>>16&255,d[6]=w>>>8&255,d[7]=w&255;let C=await crypto.subtle.importKey("raw",l,{name:"HMAC",hash:"SHA-1"},false,["sign"]),h=await crypto.subtle.sign("HMAC",C,d),f=new Uint8Array(h),L=f[f.length-1]&15;return (((f[L]&127)<<24|(f[L+1]&255)<<16|(f[L+2]&255)<<8|f[L+3]&255)%1e6).toString().padStart(6,"0")}var Wt="0.11.0";function _n(e){let t=new Date(e),l=Date.now()-t.getTime();if(l<6e4)return "just now";if(l<36e5)return `${Math.floor(l/6e4)}m ago`;if(l<864e5)return `${Math.floor(l/36e5)}h ago`;let i=t.getDate(),d=t.toLocaleString("en",{month:"short"}),T=t.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${d} ${i}, ${T}`}var R=({d:e,className:t,size:s=14})=>jsxRuntime.jsx("svg",{className:t,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})}),y={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01",bot:"M12 8V4H8M2 14h2M20 14h2M15 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M9 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M18 10a6 6 0 0 0-12 0v4a6 6 0 0 0 12 0Z",terminal:"M4 17l6-6-6-6M12 19h8",key:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4",shield:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10",copy:"M20 9h-9a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2-2v-9a2 2 0 0 0-2-2ZM5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1",search:"M11 17.25a6.25 6.25 0 1 1 0-12.5 6.25 6.25 0 0 1 0 12.5ZM16 16l4.5 4.5"};function Rn(){let[e,t]=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,l=()=>s.classList.contains("dark")?"dark":s.classList.contains("light")?"light":null,i=l();i&&t(i);let d=window.matchMedia("(prefers-color-scheme: dark)"),T=C=>{let h=l();t(h||(C.matches?"dark":"light"));};d.addEventListener("change",T);let w=new MutationObserver(()=>{let C=l();t(C||(d.matches?"dark":"light"));});return w.observe(s,{attributes:true,attributeFilter:["class"]}),()=>{d.removeEventListener("change",T),w.disconnect();}},[]),e}function Tn(e){let t=e==="dark";return {bg:t?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:t?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:t?"#e5e5e5":"#1a1a1a",textMuted:t?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:t?"#555":"#999",border:t?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:t?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:t?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:t?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:t?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:t?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:t?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:t?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:t?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:t?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:t?"#888":"#aaa",btnHover:t?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var Cn={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},Mn={pending:y.circle,pass:y.check,fail:y.x,skip:y.skip},Dt={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 En(e,t=[]){if(!e)return false;let s=e.toLowerCase();return [...Nn,...t].map(i=>i.toLowerCase()).includes(s)}var $n=e=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:t=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:e.bg,border:t?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:t?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(t,s)=>({width:`${t}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:t=>{let s=Dt[t]||Dt.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:t=>({height:"100%",width:`${t}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:t=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${t}15`,color:t,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(t,s)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:t?`${s}33`:"transparent",color:t?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 ct(e){return e.split("/")[0].trim()}async function Pn(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 t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.opacity="0",t.style.pointerEvents="none",document.body.appendChild(t),t.focus(),t.select(),t.setSelectionRange(0,e.length);let s=document.execCommand("copy");return document.body.removeChild(t),s}catch{return false}}function Be({config:e,appSlug:t,environment:s,seededUsers:l,authToken:i,tk:d,compact:T=false,onExpand:w,onAuthExpired:C,refreshAuth:h,requestLogin:f,testRunId:L,testRunToken:j,ticketId:_,targetUrl:x,version:b,commitSha:r,prNumber:c,branchName:F}){let[v,B]=react.useState(false),[V,W]=react.useState(null),[A,pe]=react.useState(null),[S,a]=react.useState(null),[ae,Y]=react.useState(null),[ee,Q]=react.useState(null),[ne,ge]=react.useState(null);react.useEffect(()=>{s==="local"&&Ke();},[s]);let ke=react.useCallback(p=>{W(p),a(null),Y(null),ge(null);let z=Le(i);if(s!=="local"&&f&&z!==null&&z<=Date.now()){Q({slug:p,token:i||null}),ge(p),W(null),f();return}let E=N=>{a(N),Y(p),window.setTimeout(()=>{Y($=>$===p?null:$),a($=>$===N?null:$);},3e3);},M=new URLSearchParams({app_slug:t,seed_user_slug:p,environment:s});L&&M.set("test_run_id",L),j&&M.set("public_token",j),_&&M.set("ticket_id",_),x&&M.set("target_url",x),b&&M.set("version",b),r&&M.set("commit_sha",r),c&&M.set("pr_number",String(c)),F&&M.set("branch_name",F);let U=async N=>{let $={apikey:e.anonKey,Authorization:`Bearer ${N}`};try{let D=await fetch(`${e.serverUrl}/widget/totp-code?${M}`,{headers:$});if(!D.ok){let xe=await D.json().catch(()=>({error:`HTTP ${D.status}`}));return {ok:!1,status:D.status,error:xe.error||`HTTP ${D.status}`}}let te=await D.json();return {ok:!0,code:String(te.code)}}catch{return {ok:false,status:0,error:"Network error"}}},J=(async()=>{if(s==="local"){let D=await It(p);if(D)try{return {ok:!0,code:await Ft(D)}}catch{}}let N=await U(i||e.anonKey);if(N.ok||N.status!==401||!h)return N;let $=await h();return $?U($):{ok:false,status:401,error:"Sign in to BotBuddy to refresh 2FA"}})(),H=null;try{if(typeof ClipboardItem<"u"&&navigator.clipboard?.write){let N=J.then($=>{if(!$.ok)throw new Error($.error);return new Blob([$.code],{type:"text/plain"})});H=navigator.clipboard.write([new ClipboardItem({"text/plain":N})]).then(()=>!0).catch(()=>!1);}}catch{}(async()=>{let N=await J;if(!N.ok){N.status===401?(Q({slug:p,token:i||null}),ge(p)):E(N.status===404?"No 2FA seed registered":N.error),W(null);return}let $=H?await H:false,D=$?true:await Pn(N.code),te=$||D;pe({slug:p,code:N.code,copied:te}),window.setTimeout(()=>pe(xe=>xe?.slug===p?null:xe),te?2500:6e3),B(false),W(null);})();},[e.serverUrl,e.anonKey,i,t,s,L,j,_,x,b,r,c,F,h,f]),de=react.useCallback(p=>{Q({slug:p,token:i||null}),f?.();},[i,f]),Se=react.useCallback(p=>{ne===p?de(p):ke(p);},[ne,de,ke]);react.useEffect(()=>{if(!ee||!i||i===ee.token)return;let p=ee.slug;Q(null),ke(p);},[i,ke,ee]);let _e=react.useRef(null),Ee=react.useRef(null);if(react.useLayoutEffect(()=>{if(!v)return;let p=_e.current,z=Ee.current;if(!p||!z||typeof window>"u")return;let E=()=>{let M=p.getBoundingClientRect(),U=z.getBoundingClientRect(),J=window.innerWidth,H=window.innerHeight,N=M.left,$=M.top-U.height-6;$<8&&($=M.bottom+6);let D=Math.max(8,J-U.width-8),te=Math.max(8,H-U.height-8);N=Math.min(Math.max(N,8),D),$=Math.min(Math.max($,8),te),z.style.left=`${Math.round(N)}px`,z.style.top=`${Math.round($)}px`;};return E(),window.addEventListener("scroll",E,true),window.addEventListener("resize",E),()=>{window.removeEventListener("scroll",E,true),window.removeEventListener("resize",E);}},[v,l.length,S]),react.useEffect(()=>{if(!v)return;let p=z=>{let E=z.target;Ee.current?.contains(E)||_e.current?.contains(E)||B(false);};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[v]),l.length===0)return null;if(T){let p=l.length>1,z=l[0],E=!p&&ne===z,M=D=>{if(D.stopPropagation(),p&&w){w();return}Se(z);},U=!!ae,J=!!A,H=J&&A.copied,N=J&&!A.copied,$=E?d.blue:U?d.red:H?d.green:N?d.amber:d.purple;return jsxRuntime.jsxs("span",{onPointerDown:D=>D.stopPropagation(),onPointerUp:D=>D.stopPropagation(),onPointerMove:D=>D.stopPropagation(),onClick:M,style:{display:"inline-flex",alignItems:"center",gap:"3px",color:$,fontWeight:600,cursor:"pointer",letterSpacing:N?"0.08em":void 0},title:E?"Sign in to BotBuddy to refresh 2FA":U?S||"Failed":N?`Clipboard blocked \u2014 code: ${A.code}`:p?`${l.length} 2FA personas`:`Copy 2FA code for ${l[0]}`,children:[jsxRuntime.jsx(R,{d:E?y.key:U?y.alert:H?y.check:N?y.copy:y.shield,size:10}),E?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Sign in"}):H?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Copied"}):N?jsxRuntime.jsx(jsxRuntime.Fragment,{children:A.code}):U?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Failed"}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["2FA",p&&` \xB7${l.length}`]})]})}if(l.length===1){let p=l[0],z=V===p,E=A?.slug===p,M=E&&A.copied,U=E&&!A.copied,J=ae===p,H=ne===p,N=H?d.blue:J?d.red:M?d.green:U?d.amber:d.purple;return jsxRuntime.jsxs("button",{onClick:$=>{$.stopPropagation(),Se(p);},disabled:z,style:{...Ot(N),cursor:z?"wait":"pointer",opacity:z?.6:1},title:H?"Sign in to BotBuddy to refresh 2FA":J?S||"Failed":U?`Clipboard blocked \u2014 code: ${A.code}`:`Copy 2FA code for ${p}`,children:[jsxRuntime.jsx(R,{d:H?y.key:J?y.alert:M?y.check:U?y.copy:y.shield,size:12}),H?"Sign in":M?"Copied":U?A.code:J?"Failed":z?"\u2026":`2FA \xB7 ${p}`]})}let fe=!!ne&&!v,oe=!!ae&&!v,Re=!!A&&A.copied,Te=!!A&&!A.copied,Ye=fe?d.blue:oe?d.red:Re?d.green:Te?d.amber:d.purple,qe=v&&typeof document<"u"?reactDom.createPortal(jsxRuntime.jsxs("div",{ref:Ee,onPointerDown:p=>p.stopPropagation(),onMouseDown:p=>p.stopPropagation(),style:{position:"fixed",left:-9999,top:-9999,background:d.bg,border:`1px solid ${d.border}`,borderRadius:6,boxShadow:`0 8px 24px ${d.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:[l.map(p=>{let z=V===p,E=ne===p;return jsxRuntime.jsxs("button",{onClick:M=>{M.stopPropagation(),Se(p);},disabled:z,style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 8px",background:"transparent",border:"none",borderRadius:4,cursor:z?"wait":"pointer",fontSize:"10px",color:E?d.blue:d.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},title:E?"Sign in to BotBuddy to refresh 2FA":void 0,onMouseEnter:M=>M.currentTarget.style.background=d.btnHover,onMouseLeave:M=>M.currentTarget.style.background="transparent",children:[jsxRuntime.jsx(R,{d:E?y.key:y.shield,size:10}),jsxRuntime.jsx("span",{style:{flex:1,overflowWrap:"anywhere",lineHeight:1.3},children:p}),E?jsxRuntime.jsx("span",{style:{color:d.blue,fontSize:9},children:"Sign in"}):z?jsxRuntime.jsx("span",{style:{color:d.textMuted,fontSize:9},children:"\u2026"}):null]},p)}),S&&jsxRuntime.jsx("div",{style:{padding:"4px 8px",fontSize:9,color:d.red},children:S})]}),document.body):null;return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("button",{ref:_e,onClick:p=>{if(p.stopPropagation(),fe&&ne){de(ne);return}B(z=>!z),a(null),Y(null);},style:{...Ot(Ye),cursor:"pointer"},title:fe?"Sign in to BotBuddy to refresh 2FA":oe?S||"Failed":Te?`Clipboard blocked \u2014 code: ${A.code}`:"Choose a persona to copy a 2FA code for",children:[jsxRuntime.jsx(R,{d:fe?y.key:oe?y.alert:Re?y.check:Te?y.copy:y.shield,size:12}),fe?"Sign in":Re?"Copied":Te?A.code:oe?"Failed":`2FA \xB7 ${l.length}`,!fe&&jsxRuntime.jsx(R,{d:v?y.chevronUp:y.chevronDown,size:8})]}),qe]})}function Ot(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 Ht="botbuddy-widget-state";function Ln({config:e,appSlug:t,environment:s,ticketId:l,testRunId:i,testRunToken:d,targetUrl:T,version:w,commitSha:C,prNumber:h,branchName:f,onNavigate:L,displayName:j="human",defaultMode:_="mini",defaultPosition:x}){let b=Rn(),r=react.useMemo(()=>Tn(b),[b]),c=react.useMemo(()=>$n(r),[r]),[F,v]=react.useState(false),[B,V]=react.useState(false),[W,A]=react.useState(false),pe=react.useRef(false),S=e.dashboardUrl||"https://app.bot-buddy.ai",a=dt(S),Y=(()=>{try{let n=typeof window<"u"?localStorage.getItem(Ht):null;if(n)return JSON.parse(n)}catch{}return null})(),[ee,Q]=react.useState(Y?.mode||_),[ne,ge]=react.useState(""),[ke,de]=react.useState(null),[Se,_e]=react.useState(null),[Ee,fe]=react.useState(new Set),[oe,Re]=react.useState(""),Te=react.useCallback(n=>{fe(g=>{let k=new Set(g);return k.has(n)?k.delete(n):k.add(n),k});},[]),Ye=Y?.x??x?.x??16,qe=Y?.y??x?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:p,setPos:z,onPointerDown:E,onPointerMove:M,onPointerUp:U,didDrag:J}=tt(Ye,qe),H=react.useRef(null);react.useEffect(()=>{try{localStorage.setItem(Ht,JSON.stringify({mode:ee,x:p.x,y:p.y}));}catch{}},[ee,p.x,p.y]),react.useLayoutEffect(()=>{if(typeof window>"u")return;let n=H.current;if(!n)return;let g=n.getBoundingClientRect(),k=et(p.x,p.y,g.width,g.height,window.innerWidth,window.innerHeight);(k.x!==p.x||k.y!==p.y)&&z(k);}),react.useEffect(()=>{if(typeof window>"u")return;let n=()=>{let g=H.current;if(!g)return;let k=g.getBoundingClientRect(),K=et(p.x,p.y,k.width,k.height,window.innerWidth,window.innerHeight);(K.x!==p.x||K.y!==p.y)&&z(K);};return window.addEventListener("resize",n),()=>window.removeEventListener("resize",n)},[p.x,p.y,z]);let N=react.useRef(a.isAuthenticated);react.useEffect(()=>{!N.current&&a.isAuthenticated&&Q("max"),N.current=a.isAuthenticated;},[a.isAuthenticated]);let $="botbuddy-widget-max-size",D=()=>{try{let n=localStorage.getItem($);if(n)return JSON.parse(n)}catch{}return {w:340,h:500}},[te,xe]=react.useState(D),$e=react.useRef(false),Pe=react.useRef({x:0,y:0,w:0,h:0}),Qt=react.useCallback(n=>{n.stopPropagation(),$e.current=true,Pe.current={x:n.clientX,y:n.clientY,w:te.w,h:te.h},n.target.setPointerCapture(n.pointerId);},[te]),en=react.useCallback(n=>{if(!$e.current)return;let g=Math.max(280,Math.min(600,Pe.current.w+(n.clientX-Pe.current.x))),k=Math.max(300,Math.min(window.innerHeight*.9,Pe.current.h+(n.clientY-Pe.current.y)));xe({w:g,h:k});},[]),tn=react.useCallback(()=>{$e.current&&($e.current=false,xe(n=>(localStorage.setItem($,JSON.stringify(n)),n)));},[]),se=T??(typeof window<"u"?window.location.href:void 0),mt=a.displayName||j,[ce,yt]=react.useState(null);react.useEffect(()=>{if(a.isAuthenticated)return;let n=new URLSearchParams;d&&n.set("token",d),l&&n.set("ticket_id",l),n.set("app_slug",t),s&&n.set("environment",s),i&&n.set("test_run_id",i),se&&n.set("target_url",se),w&&n.set("version",w),C&&n.set("commit_sha",C),h&&n.set("pr_number",String(h)),f&&n.set("branch_name",f),fetch(`${e.serverUrl}/widget/preview?${n}`,{headers:{apikey:e.anonKey}}).then(g=>g.json()).then(g=>yt(g)).catch(()=>yt(null));},[a.isAuthenticated,e.serverUrl,e.anonKey,t,s,l,i,d,se,w,C,h,f]);let ht=react.useRef(false),nn=react.useCallback(()=>{ht.current||a.logout();},[a.logout]),{run:m,widgetState:ve,fetchRun:rn,setVerdict:xt,markComplete:on,resetRun:sn,setRun:vt}=ot({config:e,appSlug:t,environment:s,ticketId:l,testRunId:i,testRunToken:d,targetUrl:se,version:w,commitSha:C,prNumber:h?String(h):void 0,branchName:f,authToken:a.token,onAuthExpired:nn});ht.current=!!m;let[wt,kt]=react.useState([]),[St,Ue]=react.useState([]),[Je,_t]=react.useState(false),[Rt,Tt]=react.useState(null),[an,Ie]=react.useState(false),be=En(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);react.useEffect(()=>{if((s??"local")!=="local"||be){kt([]);return}let n=true;return Ke().then(g=>{n&&kt(Object.keys(g||{}));}),()=>{n=false;}},[s,be]);let ln=react.useCallback(async()=>{if(!(!a.isAuthenticated||!a.token)){_t(true),Tt(null);try{let n=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${a.token}`},body:JSON.stringify({app_slug:t,environment:s||"local",target_url:se,branch_name:f,commit_sha:C,pr_number:h,ticket_id:l,title:`${l||t} local validation`})}),g=await n.json().catch(()=>({}));if(!n.ok)throw new Error(g.error||`HTTP ${n.status}`);vt(g),Q("max");}catch(n){Tt(n.message);}finally{_t(false);}}},[a.isAuthenticated,a.token,e.serverUrl,e.anonKey,t,s,se,f,C,h,l,vt]),Fe=react.useCallback(async(n,g,k)=>{_e(n);try{await xt(n,g,k,mt);}finally{_e(null),de(null),ge("");}},[xt,mt]),q=m?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},dn=q.total>0&&q.pending===0,Ce=ve==="completed",We=react.useMemo(()=>{let n=m?.test_cases||[];if(!oe.trim())return n;let g=oe.toLowerCase();return n.filter(k=>k.title.toLowerCase().includes(g)||k.description&&k.description.toLowerCase().includes(g)||k.url_path&&k.url_path.toLowerCase().includes(g)||k.seed_user&&k.seed_user.toLowerCase().includes(g))},[m?.test_cases,oe]),Ct=react.useMemo(()=>{let n=We,g=m?.test_cases||[];if(new Set(g.map(Z=>Z.source_pr_number)).size<=1)return null;let K=[],ye=new Map;n.forEach(Z=>{let X=Z.source_pr_number;ye.has(X)||ye.set(X,[]),ye.get(X).push(Z);});let zt=[...ye.keys()].sort((Z,X)=>Z===null?1:X===null?-1:X-Z);for(let Z of zt){let X=ye.get(Z),Xe={total:X.length,pass:0,fail:0,skip:0,pending:0};X.forEach(At=>{At.verdict in Xe&&Xe[At.verdict]++;}),K.push({key:Z!=null?`pr-${Z}`:"general",label:Z!=null?`PR #${Z}`:"General",cases:X,summary:Xe});}return K.filter(Z=>Z.cases.length>0)},[We,m?.test_cases]),Mt=q.total>0?(q.pass+q.fail)/q.total*100:0,G=s??m?.environment??null,me=react.useMemo(()=>{if(!G||G==="production"||be)return [];let n=m?.test_cases||[],g=new Set;for(let k of n)k.seed_user&&g.add(ct(k.seed_user));if(G==="local")for(let k of wt)g.add(ct(k));for(let k of St)g.add(ct(k));return [...g]},[m?.test_cases,G,wt,St,be]);react.useEffect(()=>{if(!G||G==="production"||be||!a.isAuthenticated||!a.token){Ue([]);return}let n=true,g=`${e.serverUrl}/widget/totp-seeds?${new URLSearchParams({app_slug:t,environment:G})}`,k=K=>fetch(g,{headers:{apikey:e.anonKey,Authorization:`Bearer ${K}`}});return (async()=>{try{let K=await k(a.token);if(K.status===401&&a.refreshNow){let X=await a.refreshNow();X&&(K=await k(X));}if(!n)return;if(!K.ok){Ue([]);return}let ye=await K.json().catch(()=>null),Z=(Array.isArray(ye?.seeds)?ye.seeds:[]).map(X=>X?.seed_user_slug).filter(X=>typeof X=="string"&&X.length>0);Ue(Z);}catch{n&&Ue([]);}})(),()=>{n=false;}},[G,be,a.isAuthenticated,a.token,a.refreshNow,t,e.serverUrl,e.anonKey]);let Ge=react.useMemo(()=>{let n=m?.auto_tooltip_seconds??ce?.auto_tooltip_seconds;return n!=null&&n>0?n*1e3:0},[m,ce]),Nt=ve==="ready"||ve==="completed"||ce?.enabled&&ce.run;react.useEffect(()=>{if(!Nt||pe.current||Ge<=0)return;pe.current=true,V(true);let n=window.setTimeout(()=>V(false),Ge);return ()=>window.clearTimeout(n)},[Nt,Ge]);let Et=n=>jsxRuntime.jsxs("div",{style:c.caseRow,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsx("div",{style:{marginTop:"2px",flexShrink:0,color:Cn[n.verdict]},children:Se===n.id?jsxRuntime.jsx(R,{d:y.loader,className:""}):jsxRuntime.jsx(R,{d:Mn[n.verdict],className:""})}),jsxRuntime.jsxs("div",{style:{minWidth:0,flex:1},children:[jsxRuntime.jsx("div",{style:{fontSize:"10px",color:r.text,lineHeight:1.3},children:n.title}),n.description&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:r.gripColor,marginTop:"2px"},children:n.description}),n.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(R,{d:y.key,size:10}),jsxRuntime.jsx("span",{children:n.seed_user})]}),n.url_path&&jsxRuntime.jsxs("a",{href:n.url_path,target:"_blank",rel:"noopener noreferrer",onClick:g=>{g.stopPropagation(),L&&(g.preventDefault(),L(n.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(R,{d:y.externalLink,size:10}),n.url_path]}),n.verdict==="fail"&&n.fail_reason&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:r.red,marginTop:"2px"},children:["\u2717 ",n.fail_reason]})]})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(g=>jsxRuntime.jsx("button",{onClick:()=>{if(n.verdict===g){Fe(n.id,"pending"),de(null);return}if(g==="fail"){de(n.id),ge("");return}de(null),Fe(n.id,g);},disabled:Se!==null,style:c.verdictBtn(n.verdict===g,g==="pass"?r.green:g==="fail"?r.red:r.amber),children:g.toUpperCase()},g)),n.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(R,{d:y.bot,size:8}),n.created_by_agent_name]}),n.verdict_by_display_name&&jsxRuntime.jsxs("span",{style:{fontSize:"8px",color:r.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[n.verdict_by_display_name,n.verdict_at&&jsxRuntime.jsx("span",{style:{opacity:.7},children:_n(n.verdict_at)})]})]}),ke===n.id&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:ne,onChange:g=>ge(g.target.value),onKeyDown:g=>{g.key==="Enter"&&Fe(n.id,"fail",ne.trim()||void 0),g.key==="Escape"&&(de(null),ge(""));},placeholder:"Reason (optional)...",style:c.input}),jsxRuntime.jsx("button",{onClick:()=>{Fe(n.id,"fail",ne.trim()||void 0);},style:c.verdictBtn(true,r.red),children:"\u2713"})]})]},n.id);if((ve==="no-match"||ve==="loading")&&!(!a.isAuthenticated&&ce?.enabled&&ce.run)){if(!(G==="local"&&!be))return null}if(!a.isAuthenticated&&ce?.enabled&&ce.run){let n=ce.run,g=n.summary,k=n.status==="completed";return jsxRuntime.jsx("div",{ref:H,style:{...c.root,left:p.x,top:p.y},children:jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>v(true),onMouseLeave:()=>{v(false),A(false),V(false);},children:[jsxRuntime.jsxs("div",{style:{...c.pill(k),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:E,onPointerMove:M,onPointerUp:()=>{U();},children:[jsxRuntime.jsx(R,{d:y.grip,size:10,className:""}),n.ticket_id&&n.ticket_url?jsxRuntime.jsx("a",{href:n.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:n.ticket_id}):null,n.pr_url?jsxRuntime.jsxs("a",{href:n.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#",n.pr_number??n.pr_id]}):null,n.created_by_agent_name?n.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${n.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(R,{d:y.terminal,size:10}),n.created_by_agent_name]}):jsxRuntime.jsxs("span",{style:{color:r.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(R,{d:y.bot,size:10}),n.created_by_agent_name]}):null,jsxRuntime.jsxs("span",{style:k?{color:r.green}:void 0,children:[g.pass,"/",g.total]}),g.fail>0&&jsxRuntime.jsxs("span",{style:{color:r.red},children:[g.fail,"\u2717"]}),jsxRuntime.jsx("span",{onClick:K=>{K.stopPropagation(),a.openLogin();},style:{color:r.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!W&&(F||B)&&n.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:n.title}),(n.description||n.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:n.description||n.intro_notes}),jsxRuntime.jsx("div",{style:{marginTop:"4px",fontSize:"9px",color:r.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!a.isAuthenticated)return jsxRuntime.jsxs("div",{ref:H,style:{...c.root,left:p.x,top:p.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:E,onPointerMove:M,onPointerUp:U,children:[jsxRuntime.jsx("div",{style:{...c.handle,borderBottom:"none"},children:jsxRuntime.jsxs("div",{style:c.sub,children:[jsxRuntime.jsx(R,{d:y.grip,size:10,className:""}),jsxRuntime.jsx(R,{d:y.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"}),G==="local"&&me.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsxRuntime.jsx(Be,{config:e,appSlug:t,environment:G,seededUsers:me,authToken:a.token,refreshAuth:a.refreshNow,requestLogin:a.openLogin,tk:r,testRunId:m?.id||i,testRunToken:d,ticketId:l,targetUrl:se,version:w,commitSha:C,prNumber:h,branchName:f,onAuthExpired:a.logout})}),jsxRuntime.jsx("button",{onClick:n=>{n.stopPropagation(),a.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(!m&&G==="local"&&!be)return an?jsxRuntime.jsx("div",{ref:H,style:{...c.root,left:p.x,top:p.y},children:jsxRuntime.jsxs("div",{style:c.card(240,false),children:[jsxRuntime.jsxs("div",{style:c.handle,onPointerDown:E,onPointerMove:M,onPointerUp:U,onClick:()=>{J.current||Ie(false);},children:[jsxRuntime.jsx(R,{d:y.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:c.title,children:"BotBuddy"}),f&&jsxRuntime.jsx("div",{style:c.sub,children:jsxRuntime.jsxs("span",{children:["\u2387 ",f]})})]}),jsxRuntime.jsx(R,{d:y.chevronUp,className:""}),jsxRuntime.jsx("button",{style:c.btn,onClick:n=>{n.stopPropagation(),Ie(false);},children:jsxRuntime.jsx(R,{d:y.minus,className:""})})]}),jsxRuntime.jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[me.length>0&&jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsxRuntime.jsx(Be,{config:e,appSlug:t,environment:G,seededUsers:me,authToken:a.token,refreshAuth:a.refreshNow,requestLogin:a.openLogin,tk:r,testRunId:i,testRunToken:d,ticketId:l,targetUrl:se,version:w,commitSha:C,prNumber:h,branchName:f,onAuthExpired:a.logout})}),jsxRuntime.jsx("button",{onClick:n=>{n.stopPropagation(),ln();},disabled:Je,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${r.green}`,background:`${r.green}22`,color:r.green,cursor:Je?"wait":"pointer",width:"100%"},children:Je?"Creating...":"Create test run for this branch"}),Rt&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:r.red,marginTop:"8px"},children:Rt})]})]})}):jsxRuntime.jsx("div",{ref:H,style:{...c.root,left:p.x,top:p.y},children:jsxRuntime.jsxs("div",{style:{...c.pill(false),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:E,onPointerMove:M,onPointerUp:()=>{U(),J.current||Ie(true);},children:[jsxRuntime.jsx(R,{d:y.grip,size:9,className:""}),jsxRuntime.jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),me.length>0&&jsxRuntime.jsx(Be,{config:e,appSlug:t,environment:G,seededUsers:me,authToken:a.token,refreshAuth:a.refreshNow,requestLogin:a.openLogin,tk:r,compact:true,onExpand:()=>Ie(true),testRunId:i,testRunToken:d,ticketId:l,targetUrl:se,version:w,commitSha:C,prNumber:h,branchName:f,onAuthExpired:a.logout})]})});let $t=()=>{J.current||(V(false),Q(n=>{let g=n==="mini"?"max":"mini";return A(g==="mini"),g}));},Pt=({icon:n,onClick:g})=>jsxRuntime.jsx("button",{style:c.btn,onClick:k=>{k.stopPropagation(),g(k);},children:jsxRuntime.jsx(R,{d:n,className:""})}),Lt=()=>jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${r.borderSubtle}`,flexShrink:0},children:[m?.pr_url&&jsxRuntime.jsxs("a",{href:m.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...c.link(r.blue),textDecoration:"none"},children:[jsxRuntime.jsx(R,{d:y.pr,size:12}),m.pr_number?`PR#${m.pr_number}`:m.pr_id||"PR",jsxRuntime.jsx(R,{d:y.externalLink,size:8})]}),m?.ticket_url&&jsxRuntime.jsxs("a",{href:m.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...c.link(r.amber),textDecoration:"none"},children:[jsxRuntime.jsx(R,{d:y.ticket,size:12}),m.ticket_id||"Ticket",jsxRuntime.jsx(R,{d:y.externalLink,size:8})]}),m?.created_by_agent_name&&(m.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${m.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...c.link(r.purple),textDecoration:"none"},children:[jsxRuntime.jsx(R,{d:y.bot,size:12}),m.created_by_agent_name,jsxRuntime.jsx(R,{d:y.externalLink,size:8})]}):jsxRuntime.jsxs("span",{style:{...c.link(r.purple)},children:[jsxRuntime.jsx(R,{d:y.bot,size:12}),m.created_by_agent_name]})),G&&jsxRuntime.jsx(Be,{config:e,appSlug:t,environment:G,seededUsers:me,authToken:a.token,refreshAuth:a.refreshNow,requestLogin:a.openLogin,tk:r,testRunId:m?.id||i,testRunToken:d,ticketId:l,targetUrl:se,version:w,commitSha:C,prNumber:h,branchName:f,onAuthExpired:a.logout}),jsxRuntime.jsx("span",{style:{...c.badge(m?.environment||"custom"),marginLeft:"auto"},children:m?.environment})]}),Bt=()=>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(Wt);},style:{fontSize:"9px",fontWeight:600,color:r.versionText,letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxRuntime.jsxs("span",{style:{color:r.versionNum},children:["v",Wt]})]}),a.isAuthenticated&&(a.isExpired?jsxRuntime.jsx("button",{onClick:n=>{n.stopPropagation(),a.openLogin();},style:{fontSize:"8px",color:r.blue,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Widget session expired \u2014 sign in to refresh",children:"sign in"}):jsxRuntime.jsx("button",{onClick:n=>{n.stopPropagation(),a.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:H,style:{...c.root,left:p.x,top:p.y},children:[ee==="mini"&&jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>v(true),onMouseLeave:()=>{v(false),A(false),V(false);},children:[jsxRuntime.jsxs("div",{style:{...c.pill(Ce),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:E,onPointerMove:M,onPointerUp:()=>{U(),J.current||$t();},children:[jsxRuntime.jsx(R,{d:y.grip,size:9,className:""}),m?.ticket_id&&jsxRuntime.jsx("span",{style:{color:r.amber,fontWeight:600},children:m.ticket_id}),m?.pr_number&&jsxRuntime.jsxs("span",{style:{color:r.blue,fontWeight:600},children:["PR#",m.pr_number]}),jsxRuntime.jsxs("span",{style:Ce?{color:r.green}:void 0,children:[q.pass,"/",q.total]}),q.fail>0&&jsxRuntime.jsxs("span",{style:{color:r.red},children:[q.fail,"\u2717"]}),G&&jsxRuntime.jsx(Be,{config:e,appSlug:t,environment:G,seededUsers:me,authToken:a.token,refreshAuth:a.refreshNow,requestLogin:a.openLogin,tk:r,compact:true,onExpand:()=>Q("expanded"),testRunId:m?.id||i,testRunToken:d,ticketId:l,targetUrl:se,version:w,commitSha:C,prNumber:h,branchName:f,onAuthExpired:a.logout})]}),!W&&(F||B)&&m?.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:m.title}),(m.description||m.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:m.description||m.intro_notes})]})]}),ee==="expanded"&&jsxRuntime.jsxs("div",{style:c.card(300,Ce),children:[jsxRuntime.jsxs("div",{style:c.handle,onPointerDown:E,onPointerMove:M,onPointerUp:U,onClick:$t,children:[jsxRuntime.jsx(R,{d:y.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:c.title,children:m?.title}),jsxRuntime.jsx("div",{style:c.sub,children:m?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",m.branch_name]})})]}),jsxRuntime.jsx(R,{d:y.chevronUp,className:""}),jsxRuntime.jsx(Pt,{icon:y.minus,onClick:()=>{V(false),A(true),Q("mini");}})]}),jsxRuntime.jsxs("div",{style:c.stats,children:[jsxRuntime.jsxs("span",{style:{color:r.green},children:[q.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:r.red},children:[q.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:r.amber},children:[q.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:r.gripColor},children:[q.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:q.total})]}),m?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:r.gripColor,borderBottom:`1px solid ${r.borderSubtle}`,flexShrink:0},children:m.description}),Lt(),Bt(),jsxRuntime.jsx("div",{style:c.progress,children:jsxRuntime.jsx("div",{style:c.progressBar(Mt)})})]}),ee==="max"&&jsxRuntime.jsxs("div",{style:{...c.card(te.w,Ce),height:te.h,position:"relative"},children:[jsxRuntime.jsxs("div",{style:c.handle,onPointerDown:E,onPointerMove:M,onPointerUp:U,onClick:()=>{J.current||Q("expanded");},children:[jsxRuntime.jsx(R,{d:y.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:c.title,children:m?.title}),jsxRuntime.jsx("div",{style:c.sub,children:m?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",m.branch_name]})})]}),jsxRuntime.jsx(R,{d:y.chevronDown,className:""}),jsxRuntime.jsx(Pt,{icon:y.minus,onClick:()=>{V(false),A(true),Q("mini");}})]}),jsxRuntime.jsxs("div",{style:c.stats,children:[jsxRuntime.jsxs("span",{style:{color:r.green},children:[q.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:r.red},children:[q.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:r.amber},children:[q.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:r.gripColor},children:[q.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:q.total})]}),m?.intro_notes&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${r.borderSubtle}`,fontSize:"10px",color:r.textMuted,fontStyle:"italic",flexShrink:0},children:m.intro_notes}),(m?.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(R,{d:y.search,size:11,className:""}),jsxRuntime.jsx("input",{value:oe,onChange:n=>Re(n.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:r.text,fontFamily:"monospace"}}),oe&&jsxRuntime.jsx("button",{onClick:()=>Re(""),style:{background:"none",border:"none",cursor:"pointer",color:r.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),ve==="error"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsxRuntime.jsx(R,{d:y.alert,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:r.red},children:"Failed to load"}),jsxRuntime.jsx("button",{onClick:rn,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),Ce&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg},children:[jsxRuntime.jsx(R,{d:y.checkAll,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",color:r.green,flex:1},children:"Run completed"}),jsxRuntime.jsx("button",{onClick:sn,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),ve!=="error"&&jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(m?.test_cases||[]).length===0?jsxRuntime.jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:"No test cases"}):We.length===0?jsxRuntime.jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:['No matches for "',oe,'"']}):Ct?Ct.map(n=>{let g=Ee.has(n.key);return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>Te(n.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(R,{d:g?y.chevronDown:y.chevronUp,size:10,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",fontWeight:700,color:r.blue,flex:1,textAlign:"left"},children:n.label}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:r.green},children:[n.summary.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:r.red},children:[n.summary.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:r.gripColor},children:[n.summary.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{fontSize:"9px",color:r.textFaint},children:n.summary.total})]}),!g&&n.cases.map(k=>Et(k))]},n.key)}):We.map(n=>Et(n))}),dn&&!Ce&&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:on,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"})]}),Lt(),Bt(),jsxRuntime.jsx("div",{style:c.progress,children:jsxRuntime.jsx("div",{style:c.progressBar(Mt)})}),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:Qt,onPointerMove:en,onPointerUp:tn,onPointerEnter:n=>n.currentTarget.style.opacity="0.7",onPointerLeave:n=>{$e.current||(n.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"})})})]})]})}var Un=1e4,ze=new Map;var je=class extends Error{};async function In(e,t,s){let l={headers:{authorization:`Bearer ${t}`}};try{return await fetch(e,{...l,signal:s})}catch(i){if(i instanceof TypeError&&/signal/i.test(i.message)&&!s.aborted)return fetch(e,l);throw i}}function Fn(e){let t=e;return !!t&&typeof t=="object"&&typeof t.tenant=="string"&&Array.isArray(t.entries)&&t.entries.every(s=>!!s&&typeof s.id=="string"&&typeof s.title=="string"&&!!s.body&&Array.isArray(s.body.ast)&&Array.isArray(s.links))}function ut({endpoint:e,getToken:t,timeoutMs:s=Un}){let[l,i]=react.useState(()=>({feed:null,error:null,loading:true,stale:false})),[d,T]=react.useState(0),w=react.useRef(t);w.current=t,react.useEffect(()=>{let h=new AbortController,f=true,L=false,j=setTimeout(()=>{L=true,h.abort();},s),_=new Promise((r,c)=>{h.signal.addEventListener("abort",()=>c(new Error("timeout")),{once:true});});_.catch(()=>{}),i(r=>({...r,error:null,loading:true}));let x=null,b=(r,c)=>{if(c&&ze.delete(e),!f)return;let F=c||x===null?void 0:ze.get(e)?.get(x);i({feed:F??null,error:r,loading:false,stale:!!F});};return (async()=>{try{let r;try{r=await Promise.race([Promise.resolve().then(()=>w.current()),_]);}catch(B){throw L||h.signal.aborted?B:new je("token_unavailable")}x=r;let c=await Promise.race([In(e,r,h.signal),_]),F=c.status===401||c.status===403;F&&ze.delete(e);let v=null;try{v=await Promise.race([c.json(),_]);}catch(B){if(L&&!F)throw B;v=null;}if(!f)return;if(c.ok)if(!Fn(v))b("invalid_feed",!1);else {let B=ze.get(e)??new Map;B.set(r,v),ze.set(e,B),i({feed:v,error:null,loading:!1,stale:!1});}else {let B=v?.error;b(typeof B=="string"?B:`http_${c.status}`,F);}}catch(r){r instanceof je?b(r.message,true):b(L?"timeout":r instanceof Error&&r.message||"unavailable",false);}finally{clearTimeout(j);}})(),()=>{f=false,clearTimeout(j),h.abort();}},[e,d,s]);let C=react.useCallback(()=>T(h=>h+1),[]);return {...l,reload:C}}var ft=["accent","fg","bg","muted","border","radius","font"],Wn={accent:"hsl(var(--primary))",fg:"hsl(var(--foreground))",bg:"hsl(var(--card))",muted:"hsl(var(--muted-foreground))",border:"hsl(var(--border))",radius:"var(--radius)",font:"inherit"},ue=(e,t)=>t===void 0?`var(--bbrn-${e},var(--_bbrn-${e}))`:`var(--bbrn-${e},var(--_bbrn-${e},${t}))`,pt=ue("accent","currentColor"),gt=ue("muted","color-mix(in srgb,currentColor 72%,transparent)"),Ae=ue("border","color-mix(in srgb,currentColor 22%,transparent)"),Dn=`@layer bbrn{
|
|
2
|
+
.bbrn-root{${ft.filter(e=>e!=="font").map(e=>`--_bbrn-${e}:${Wn[e]};`).join("")}display:grid;gap:12px;color:${ue("fg")};font-family:var(--bbrn-font)}
|
|
3
|
+
.bbrn-root .bbrn-entry{background:${ue("bg","transparent")};border:1px solid ${Ae};border-radius:${ue("radius",".5rem")};padding:16px}
|
|
4
4
|
.bbrn-root .bbrn-head{display:flex;gap:8px;align-items:baseline;flex-wrap:wrap}
|
|
5
5
|
.bbrn-root .bbrn-title{font-weight:600;font-size:1rem;line-height:1.4;margin:0}
|
|
6
|
-
.bbrn-root .bbrn-badge{font-size:.75rem;line-height:1.4;color:${
|
|
7
|
-
.bbrn-root .bbrn-delivery{font-size:.75rem;line-height:1.4;border-radius:999px;padding:0 8px;background:color-mix(in srgb,${
|
|
8
|
-
.bbrn-root .bbrn-meta,.bbrn-root .bbrn-status{color:${
|
|
6
|
+
.bbrn-root .bbrn-badge{font-size:.75rem;line-height:1.4;color:${pt};border:1px solid currentColor;border-radius:999px;padding:0 8px}
|
|
7
|
+
.bbrn-root .bbrn-delivery{font-size:.75rem;line-height:1.4;border-radius:999px;padding:0 8px;background:color-mix(in srgb,${Ae} 60%,transparent)}
|
|
8
|
+
.bbrn-root .bbrn-meta,.bbrn-root .bbrn-status{color:${gt};font-size:.8rem;margin:0}
|
|
9
9
|
.bbrn-root .bbrn-p{margin:.5em 0}
|
|
10
10
|
.bbrn-root .bbrn-list{margin:.5em 0;padding-left:1.25em;list-style:disc}
|
|
11
|
-
.bbrn-root .bbrn-code{font-family:ui-monospace,monospace;font-size:.85em;padding:0 4px;border-radius:4px;background:color-mix(in srgb,${
|
|
11
|
+
.bbrn-root .bbrn-code{font-family:ui-monospace,monospace;font-size:.85em;padding:0 4px;border-radius:4px;background:color-mix(in srgb,${Ae} 60%,transparent)}
|
|
12
12
|
.bbrn-root .bbrn-links{display:flex;gap:12px;flex-wrap:wrap;margin-top:8px;font-size:.85rem}
|
|
13
|
-
.bbrn-root .bbrn-link{color:${
|
|
14
|
-
.bbrn-root .bbrn-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
.bbrn-root .bbrn-link{color:${pt};text-decoration:underline}
|
|
14
|
+
.bbrn-root .bbrn-tags{display:flex;gap:6px;flex-wrap:wrap;margin:8px 0 0;padding:0;list-style:none}
|
|
15
|
+
.bbrn-root .bbrn-tag{font-size:.75rem;line-height:1.4;border:1px solid ${Ae};border-radius:999px;padding:0 8px;color:${gt}}
|
|
16
|
+
.bbrn-root .bbrn-filters{display:flex;gap:12px;flex-wrap:wrap;align-items:center;font-size:.85rem}
|
|
17
|
+
.bbrn-root .bbrn-filter{display:inline-flex;gap:6px;align-items:center;color:${gt}}
|
|
18
|
+
.bbrn-root .bbrn-filter select{font:inherit;color:${ue("fg")};background:${ue("bg","transparent")};border:1px solid ${Ae};border-radius:${ue("radius",".5rem")};padding:2px 6px;max-width:16rem}
|
|
19
|
+
.bbrn-root .bbrn-retry{margin-left:8px;text-decoration:underline;background:none;border:0;padding:0;color:${pt};cursor:pointer;font:inherit}
|
|
20
|
+
}`;function Vt(e=typeof document>"u"?void 0:document){if(!e?.head||e.head.querySelector("style[data-bbrn-styles]"))return;let t=e.createElement("style");t.setAttribute("data-bbrn-styles",""),t.textContent=Dn,e.head.prepend(t);}function Yt(e){if(!e)return;let t={};for(let s of ft){let l=e[s];typeof l=="string"&&l.trim()&&(t[`--bbrn-${s}`]=l);}return Object.keys(t).length?t:void 0}function Gt(e){if(typeof e!="string"||/[\s\\]/.test(e))return null;if(e.startsWith("/"))return e.startsWith("//")?null:{kind:"internal",href:e};try{return new URL(e).protocol==="https:"?{kind:"external",href:e}:null}catch{return null}}function Ve(e,t=""){return e.map((s,l)=>{let i=`${t}${l}`;switch(s.t){case "text":return s.v;case "code":return jsxRuntime.jsx("code",{className:"bbrn-code",children:s.v},i);case "strong":return jsxRuntime.jsx("strong",{children:Ve(s.c,`${i}.`)},i);case "em":return jsxRuntime.jsx("em",{children:Ve(s.c,`${i}.`)},i);default:return null}})}function Xt({ast:e}){return jsxRuntime.jsx(jsxRuntime.Fragment,{children:e.map((t,s)=>t.t==="list"?jsxRuntime.jsx("ul",{className:"bbrn-list",children:t.items.map((l,i)=>jsxRuntime.jsx("li",{children:Ve(l)},i))},s):t.t==="p"?jsxRuntime.jsx("p",{className:"bbrn-p",children:Ve(t.c)},s):null)})}var O=(...e)=>e.filter(Boolean).join(" ");function jn(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:`${t.toISOString().slice(0,16).replace("T"," ")} UTC`}var Vn=react.useInsertionEffect??react.useLayoutEffect,bt=class extends react.Component{constructor(){super(...arguments);this.state={failed:false,keys:this.props.resetKeys};}static getDerivedStateFromError(){return {failed:true}}static getDerivedStateFromProps(s,l){return s.resetKeys.length!==l.keys.length||s.resetKeys.some((d,T)=>!Object.is(d,l.keys[T]))?{failed:false,keys:s.resetKeys}:null}componentDidCatch(){}render(){return this.state.failed?this.props.fallback:this.props.children}};function Yn(e,t){let s=Object.entries(t).filter(([,l])=>l).map(([l,i])=>`tag=${encodeURIComponent(`${l}:${i}`)}`);return s.length===0?e:`${e}${e.includes("?")?"&":"?"}${s.join("&")}`}function qn({endpoint:e,getToken:t,onNavigate:s,theme:l,classNames:i,components:d,timeoutMs:T}){Vn(()=>{Vt();},[]);let[w,C]=react.useState({}),h=react.useMemo(()=>Yn(e,w),[e,w]),{feed:f,error:L,loading:j,stale:_,reload:x}=ut({endpoint:h,getToken:t,timeoutMs:T}),[b,r]=react.useState(0),c=()=>{r(S=>S+1),x();},F=react.useMemo(()=>Yt(l),[l]),v=i??{},B=d?.Empty,V=d?.Link,W=S=>a=>{!s||a.defaultPrevented||a.button!==0||a.metaKey||a.ctrlKey||a.shiftKey||a.altKey||(a.preventDefault(),s(S));},A=Object.values(w).some(Boolean),pe=jsxRuntime.jsxs("p",{className:O("bbrn-status",v.status),role:"alert","data-bbrn-error":L??"render_failed",children:["Release notes could not be loaded.",jsxRuntime.jsx("button",{type:"button",className:O("bbrn-retry",v.retry),onClick:c,children:"Retry"}),A&&jsxRuntime.jsx("button",{type:"button",className:O("bbrn-retry",v.retry),onClick:()=>C({}),children:"Clear filters"})]});return jsxRuntime.jsxs("section",{className:O("bbrn-root",v.root),style:F,"aria-label":"Release notes","aria-busy":j,"data-bbrn-audience":f?.audience,children:[j&&!f&&jsxRuntime.jsx("p",{className:O("bbrn-status",v.status),role:"status",children:"Loading release notes\u2026"}),!j&&L&&!f&&pe,_&&jsxRuntime.jsxs("p",{className:O("bbrn-status",v.status),role:"status","data-bbrn-stale":"",children:["Showing the last loaded notes; they could not be refreshed.",jsxRuntime.jsx("button",{type:"button",className:O("bbrn-retry",v.retry),onClick:c,children:"Retry"})]}),f&&jsxRuntime.jsxs(bt,{resetKeys:[f,B,V,b],fallback:pe,children:[(f.filters?.length??0)>0&&jsxRuntime.jsx("div",{className:O("bbrn-filters",v.filters),role:"group","aria-label":"Filter release notes",children:f.filters.map(S=>jsxRuntime.jsxs("label",{className:O("bbrn-filter",v.filter),"data-bbrn-filter":S.group,children:[S.label,jsxRuntime.jsxs("select",{value:w[S.group]??"",onChange:a=>{let ae=a.target.value;C(Y=>({...Y,[S.group]:ae}));},children:[jsxRuntime.jsx("option",{value:"",children:"All"}),S.values.map(a=>jsxRuntime.jsx("option",{value:a,children:a},a))]})]},S.group))}),f.entries.length===0&&A&&jsxRuntime.jsx("p",{className:O("bbrn-status",v.status),children:"No release notes match these filters."}),f.entries.length===0&&!A&&(B?jsxRuntime.jsx(B,{}):jsxRuntime.jsxs("p",{className:O("bbrn-status",v.status),children:["No release notes yet. Submit one with ",jsxRuntime.jsx("code",{className:"bbrn-code",children:"bb release-notes submit"}),"."]})),f.entries.map(S=>jsxRuntime.jsxs("article",{className:O("bbrn-entry",v.entry),"data-entry-id":S.id,"data-source-key":S.source_key,children:[jsxRuntime.jsxs("div",{className:O("bbrn-head",v.head),children:[jsxRuntime.jsx("h2",{className:O("bbrn-title",v.title),children:S.title}),jsxRuntime.jsx("span",{className:O("bbrn-badge",v.badge),"data-bbrn-type":S.type,children:S.type}),jsxRuntime.jsx("span",{className:O("bbrn-badge",v.badge),"data-bbrn-state":S.state,children:S.state}),jsxRuntime.jsxs("span",{className:O("bbrn-meta",v.meta),children:[S.source_key," \xB7 revision ",S.revision]}),S.delivery_copy&&jsxRuntime.jsxs("span",{className:O("bbrn-delivery",v.delivery),"data-bbrn-delivery":S.delivery_badge,children:[S.delivery_copy,S.delivery_since&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[" \xB7 since ",jsxRuntime.jsx("time",{dateTime:S.delivery_since,children:jn(S.delivery_since)})]})]})]}),jsxRuntime.jsx("div",{className:O("bbrn-body",v.body),children:jsxRuntime.jsx(Xt,{ast:S.body.ast})}),(S.tags?.length??0)>0&&jsxRuntime.jsx("ul",{className:O("bbrn-tags",v.tags),"aria-label":"Tags",children:S.tags.map(a=>jsxRuntime.jsx("li",{className:O("bbrn-tag",v.tag),"data-bbrn-tag-group":a.group,title:a.label,children:a.value},`${a.group}:${a.value}`))}),S.links.length>0&&jsxRuntime.jsx("div",{className:O("bbrn-links",v.links),children:S.links.map((a,ae)=>{let Y=Gt(a.url);if(!Y)return null;let ee=O("bbrn-link",v.link),Q=a.kind??null;return V?jsxRuntime.jsx(V,{href:Y.href,external:Y.kind==="external",kind:Q,className:ee,onClick:Y.kind==="internal"&&s?W(Y.href):void 0,children:a.name},ae):Y.kind==="external"?jsxRuntime.jsx("a",{className:ee,href:Y.href,target:"_blank",rel:"noopener noreferrer","data-link-kind":Q??void 0,children:a.name},ae):jsxRuntime.jsx("a",{className:ee,href:Y.href,onClick:W(Y.href),"data-link-kind":Q??void 0,children:a.name},ae)})})]},S.id))]})]})}
|
|
21
|
+
exports.RELEASE_NOTES_TOKENS=ft;exports.ReleaseNoteBody=Xt;exports.ReleaseNotes=qn;exports.TestRunWidget=Ln;exports.safeHref=Gt;exports.useDraggable=tt;exports.useRealtimeRefresh=nt;exports.useReleaseNotes=ut;exports.useTestRun=ot;exports.useWidgetAuth=dt;
|
package/dist/index.d.cts
CHANGED
|
@@ -137,6 +137,18 @@ interface ReleaseNoteLink {
|
|
|
137
137
|
url: string;
|
|
138
138
|
kind: string | null;
|
|
139
139
|
}
|
|
140
|
+
/** BOT-3164: one tag shown on a note (a hidden group never arrives). */
|
|
141
|
+
interface ReleaseNoteTag {
|
|
142
|
+
group: string;
|
|
143
|
+
label: string;
|
|
144
|
+
value: string;
|
|
145
|
+
}
|
|
146
|
+
/** BOT-3164: one filter control, with only values a visible note carries. */
|
|
147
|
+
interface ReleaseNoteFilter {
|
|
148
|
+
group: string;
|
|
149
|
+
label: string;
|
|
150
|
+
values: string[];
|
|
151
|
+
}
|
|
140
152
|
/** BOT-3169: `draft_on_your_branch` (local) and `in_this_preview` (preview) mark the viewer's own branch drafts. BOT-3167: `in_staging`. */
|
|
141
153
|
type ReleaseNoteDeliveryBadge = "not_bound" | "draft_on_branch" | "draft_on_pr" | "merged" | "draft_on_your_branch" | "in_this_preview" | "in_staging";
|
|
142
154
|
interface ReleaseNoteEntry {
|
|
@@ -148,6 +160,8 @@ interface ReleaseNoteEntry {
|
|
|
148
160
|
title: string;
|
|
149
161
|
body: ReleaseNoteBody$1;
|
|
150
162
|
links: ReleaseNoteLink[];
|
|
163
|
+
/** BOT-3164: the tags this audience may see, in group order. Absent from older servers. */
|
|
164
|
+
tags?: ReleaseNoteTag[];
|
|
151
165
|
/** BOT-3162: where the note's change is (branch, pull request, merged). */
|
|
152
166
|
delivery_badge: ReleaseNoteDeliveryBadge;
|
|
153
167
|
/** BOT-3162: the label to show, e.g. "Draft on PR #12". */
|
|
@@ -159,8 +173,15 @@ interface ReleaseNoteEntry {
|
|
|
159
173
|
}
|
|
160
174
|
interface ReleaseNotesFeed {
|
|
161
175
|
tenant: string;
|
|
162
|
-
audience: "internal";
|
|
176
|
+
audience: "internal" | "external";
|
|
163
177
|
entries: ReleaseNoteEntry[];
|
|
178
|
+
/** BOT-3164: the filters the server offers for this audience. Absent from older servers. */
|
|
179
|
+
filters?: ReleaseNoteFilter[];
|
|
180
|
+
/** BOT-3164: the applied filters, echoed by the server. */
|
|
181
|
+
selected?: Array<{
|
|
182
|
+
group: string;
|
|
183
|
+
value: string;
|
|
184
|
+
}>;
|
|
164
185
|
}
|
|
165
186
|
/**
|
|
166
187
|
* BOT-3159 depth 1: design tokens. Each key is written as the `--bbrn-<key>`
|
|
@@ -171,7 +192,7 @@ type ReleaseNotesTheme = Partial<Record<ReleaseNotesToken, string>>;
|
|
|
171
192
|
type ReleaseNotesToken = "accent" | "fg" | "bg" | "muted" | "border" | "radius" | "font";
|
|
172
193
|
/** BOT-3159 depth 2: class names added (never replacing the `bbrn-*` class) to each part. */
|
|
173
194
|
type ReleaseNotesClassNames = Partial<Record<ReleaseNotesSlot, string>>;
|
|
174
|
-
type ReleaseNotesSlot = "root" | "entry" | "head" | "title" | "badge" | "delivery" | "meta" | "body" | "links" | "link" | "status" | "retry";
|
|
195
|
+
type ReleaseNotesSlot = "root" | "entry" | "head" | "title" | "badge" | "delivery" | "meta" | "body" | "links" | "link" | "status" | "retry" | "tags" | "tag" | "filters" | "filter";
|
|
175
196
|
/** Props the `components.Link` override receives. `className` already holds the link slot. */
|
|
176
197
|
interface ReleaseNoteLinkProps {
|
|
177
198
|
href: string;
|
|
@@ -317,4 +338,4 @@ declare function useReleaseNotes({ endpoint, getToken, timeoutMs }: UseReleaseNo
|
|
|
317
338
|
|
|
318
339
|
declare const RELEASE_NOTES_TOKENS: readonly ReleaseNotesToken[];
|
|
319
340
|
|
|
320
|
-
export { type BotBuddyConfig, RELEASE_NOTES_TOKENS, type ReleaseNoteBlock, ReleaseNoteBody, type ReleaseNoteBody$1 as ReleaseNoteBodyData, type ReleaseNoteEntry, type ReleaseNoteInline, type ReleaseNoteLink, type ReleaseNoteLinkProps, ReleaseNotes, type ReleaseNotesClassNames, type ReleaseNotesComponents, type ReleaseNotesFeed, type ReleaseNotesProps, type ReleaseNotesSlot, type ReleaseNotesTheme, type ReleaseNotesToken, type TestCase, type TestRun, type TestRunSummary, TestRunWidget, type TestRunWidgetProps, type UseReleaseNotesOptions, type UseReleaseNotesState, type Verdict, type WidgetMode, type WidgetState, safeHref, useDraggable, useRealtimeRefresh, useReleaseNotes, useTestRun, useWidgetAuth };
|
|
341
|
+
export { type BotBuddyConfig, RELEASE_NOTES_TOKENS, type ReleaseNoteBlock, ReleaseNoteBody, type ReleaseNoteBody$1 as ReleaseNoteBodyData, type ReleaseNoteEntry, type ReleaseNoteFilter, type ReleaseNoteInline, type ReleaseNoteLink, type ReleaseNoteLinkProps, type ReleaseNoteTag, ReleaseNotes, type ReleaseNotesClassNames, type ReleaseNotesComponents, type ReleaseNotesFeed, type ReleaseNotesProps, type ReleaseNotesSlot, type ReleaseNotesTheme, type ReleaseNotesToken, type TestCase, type TestRun, type TestRunSummary, TestRunWidget, type TestRunWidgetProps, type UseReleaseNotesOptions, type UseReleaseNotesState, type Verdict, type WidgetMode, type WidgetState, safeHref, useDraggable, useRealtimeRefresh, useReleaseNotes, useTestRun, useWidgetAuth };
|
package/dist/index.d.ts
CHANGED
|
@@ -137,6 +137,18 @@ interface ReleaseNoteLink {
|
|
|
137
137
|
url: string;
|
|
138
138
|
kind: string | null;
|
|
139
139
|
}
|
|
140
|
+
/** BOT-3164: one tag shown on a note (a hidden group never arrives). */
|
|
141
|
+
interface ReleaseNoteTag {
|
|
142
|
+
group: string;
|
|
143
|
+
label: string;
|
|
144
|
+
value: string;
|
|
145
|
+
}
|
|
146
|
+
/** BOT-3164: one filter control, with only values a visible note carries. */
|
|
147
|
+
interface ReleaseNoteFilter {
|
|
148
|
+
group: string;
|
|
149
|
+
label: string;
|
|
150
|
+
values: string[];
|
|
151
|
+
}
|
|
140
152
|
/** BOT-3169: `draft_on_your_branch` (local) and `in_this_preview` (preview) mark the viewer's own branch drafts. BOT-3167: `in_staging`. */
|
|
141
153
|
type ReleaseNoteDeliveryBadge = "not_bound" | "draft_on_branch" | "draft_on_pr" | "merged" | "draft_on_your_branch" | "in_this_preview" | "in_staging";
|
|
142
154
|
interface ReleaseNoteEntry {
|
|
@@ -148,6 +160,8 @@ interface ReleaseNoteEntry {
|
|
|
148
160
|
title: string;
|
|
149
161
|
body: ReleaseNoteBody$1;
|
|
150
162
|
links: ReleaseNoteLink[];
|
|
163
|
+
/** BOT-3164: the tags this audience may see, in group order. Absent from older servers. */
|
|
164
|
+
tags?: ReleaseNoteTag[];
|
|
151
165
|
/** BOT-3162: where the note's change is (branch, pull request, merged). */
|
|
152
166
|
delivery_badge: ReleaseNoteDeliveryBadge;
|
|
153
167
|
/** BOT-3162: the label to show, e.g. "Draft on PR #12". */
|
|
@@ -159,8 +173,15 @@ interface ReleaseNoteEntry {
|
|
|
159
173
|
}
|
|
160
174
|
interface ReleaseNotesFeed {
|
|
161
175
|
tenant: string;
|
|
162
|
-
audience: "internal";
|
|
176
|
+
audience: "internal" | "external";
|
|
163
177
|
entries: ReleaseNoteEntry[];
|
|
178
|
+
/** BOT-3164: the filters the server offers for this audience. Absent from older servers. */
|
|
179
|
+
filters?: ReleaseNoteFilter[];
|
|
180
|
+
/** BOT-3164: the applied filters, echoed by the server. */
|
|
181
|
+
selected?: Array<{
|
|
182
|
+
group: string;
|
|
183
|
+
value: string;
|
|
184
|
+
}>;
|
|
164
185
|
}
|
|
165
186
|
/**
|
|
166
187
|
* BOT-3159 depth 1: design tokens. Each key is written as the `--bbrn-<key>`
|
|
@@ -171,7 +192,7 @@ type ReleaseNotesTheme = Partial<Record<ReleaseNotesToken, string>>;
|
|
|
171
192
|
type ReleaseNotesToken = "accent" | "fg" | "bg" | "muted" | "border" | "radius" | "font";
|
|
172
193
|
/** BOT-3159 depth 2: class names added (never replacing the `bbrn-*` class) to each part. */
|
|
173
194
|
type ReleaseNotesClassNames = Partial<Record<ReleaseNotesSlot, string>>;
|
|
174
|
-
type ReleaseNotesSlot = "root" | "entry" | "head" | "title" | "badge" | "delivery" | "meta" | "body" | "links" | "link" | "status" | "retry";
|
|
195
|
+
type ReleaseNotesSlot = "root" | "entry" | "head" | "title" | "badge" | "delivery" | "meta" | "body" | "links" | "link" | "status" | "retry" | "tags" | "tag" | "filters" | "filter";
|
|
175
196
|
/** Props the `components.Link` override receives. `className` already holds the link slot. */
|
|
176
197
|
interface ReleaseNoteLinkProps {
|
|
177
198
|
href: string;
|
|
@@ -317,4 +338,4 @@ declare function useReleaseNotes({ endpoint, getToken, timeoutMs }: UseReleaseNo
|
|
|
317
338
|
|
|
318
339
|
declare const RELEASE_NOTES_TOKENS: readonly ReleaseNotesToken[];
|
|
319
340
|
|
|
320
|
-
export { type BotBuddyConfig, RELEASE_NOTES_TOKENS, type ReleaseNoteBlock, ReleaseNoteBody, type ReleaseNoteBody$1 as ReleaseNoteBodyData, type ReleaseNoteEntry, type ReleaseNoteInline, type ReleaseNoteLink, type ReleaseNoteLinkProps, ReleaseNotes, type ReleaseNotesClassNames, type ReleaseNotesComponents, type ReleaseNotesFeed, type ReleaseNotesProps, type ReleaseNotesSlot, type ReleaseNotesTheme, type ReleaseNotesToken, type TestCase, type TestRun, type TestRunSummary, TestRunWidget, type TestRunWidgetProps, type UseReleaseNotesOptions, type UseReleaseNotesState, type Verdict, type WidgetMode, type WidgetState, safeHref, useDraggable, useRealtimeRefresh, useReleaseNotes, useTestRun, useWidgetAuth };
|
|
341
|
+
export { type BotBuddyConfig, RELEASE_NOTES_TOKENS, type ReleaseNoteBlock, ReleaseNoteBody, type ReleaseNoteBody$1 as ReleaseNoteBodyData, type ReleaseNoteEntry, type ReleaseNoteFilter, type ReleaseNoteInline, type ReleaseNoteLink, type ReleaseNoteLinkProps, type ReleaseNoteTag, ReleaseNotes, type ReleaseNotesClassNames, type ReleaseNotesComponents, type ReleaseNotesFeed, type ReleaseNotesProps, type ReleaseNotesSlot, type ReleaseNotesTheme, type ReleaseNotesToken, type TestCase, type TestRun, type TestRunSummary, TestRunWidget, type TestRunWidgetProps, type UseReleaseNotesOptions, type UseReleaseNotesState, type Verdict, type WidgetMode, type WidgetState, safeHref, useDraggable, useRealtimeRefresh, useReleaseNotes, useTestRun, useWidgetAuth };
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import {useState,useRef,useCallback,useEffect,useMemo,useLayoutEffect,useInsertionEffect,Component}from'react';import {createPortal}from'react-dom';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Te=8;function Qe(e,t,s,d,a,l){let R=Math.max(Te,a-s-Te),v=Math.max(Te,l-d-Te);return {x:Math.min(Math.max(e,Te),R),y:Math.min(Math.max(t,Te),v)}}function et(e,t){let[s,d]=useState({x:e,y:t}),a=useRef(false),l=useRef({x:0,y:0}),R=useRef(false),v=useCallback(h=>{a.current=true,R.current=false,l.current={x:h.clientX-s.x,y:h.clientY-s.y},h.target.setPointerCapture(h.pointerId);},[s]),T=useCallback(h=>{a.current&&(R.current=true,d({x:h.clientX-l.current.x,y:h.clientY-l.current.y}));},[]),y=useCallback(()=>{a.current=false;},[]);return {pos:s,setPos:d,onPointerDown:v,onPointerMove:T,onPointerUp:y,didDrag:R}}function tt(e,t,s){let d=useRef(s);d.current=s,useEffect(()=>{if(!t)return;if(e.supabaseUrl){let l=false,R=null,v=()=>{l||R||(R=setInterval(()=>d.current(),15e3));},T=null;try{let g=new URL(e.supabaseUrl),n=["localhost","127.0.0.1","::1"].includes(g.hostname);if(g.protocol==="http:"&&!n)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");g.protocol=g.protocol==="https:"?"wss:":"ws:",T=g.toString().replace(/\/$/,"");}catch{v();}let y=null,h=null,B=null,j=0,S=()=>{if(!(l||!T)){try{y=new WebSocket(`${T}/realtime/v1/websocket?apikey=${e.anonKey}&vsn=1.0.0`);}catch{v();return}y.onopen=()=>{if(l||!y)return;let g={topic:`realtime:public:test_run_cases:test_run_id=eq.${t}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_run_cases",filter:`test_run_id=eq.${t}`}]}},ref:String(++j)};y.send(JSON.stringify(g));let n={topic:`realtime:public:test_runs:id=eq.${t}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_runs",filter:`id=eq.${t}`}]}},ref:String(++j)};y.send(JSON.stringify(n)),h=setInterval(()=>{y?.readyState===WebSocket.OPEN&&y.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++j)}));},3e4);},y.onmessage=g=>{try{JSON.parse(g.data).event==="postgres_changes"&&d.current();}catch{}},y.onclose=()=>{x(),l||(B=setTimeout(S,3e3));},y.onerror=()=>{y?.close();};}},x=()=>{h&&(clearInterval(h),h=null);};return S(),()=>{l=true,x(),B&&clearTimeout(B),R&&clearInterval(R),y&&(y.onclose=null,y.onerror=null,y.close());}}let a=setInterval(()=>d.current(),15e3);return ()=>clearInterval(a)},[e.supabaseUrl,e.anonKey,t]);}var un="botbuddy:created-test-run:";function pn(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function gn(e){return `${un}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",pn(e.targetUrl),e.branchName||""].join("|"))}`}function Fe(e,t){let s={apikey:e.anonKey};return t?s.Authorization=`Bearer ${t}`:e.apiKey?s.Authorization=`Bearer ${e.apiKey}`:s.Authorization=`Bearer ${e.anonKey}`,s}async function fn(e){if(e)return e;try{let t=await fetch("/.botbuddy-token",{cache:"no-store"});if(t.ok){let s=(await t.text()).trim();if(s.startsWith("public_"))return s}}catch{}try{let t=import.meta?.env?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(t&&typeof t=="string"&&t.startsWith("public_"))return t}catch{}return null}function rt(e){let[t,s]=useState(null),[d,a]=useState("loading"),l=gn(e),[R,v]=useState(()=>{if(e.testRunId)return e.testRunId;try{return localStorage.getItem(l)||void 0}catch{return}}),T=e.testRunId||R,y=useCallback(x=>{if(s(x),!!x?.id){v(x.id);try{localStorage.setItem(l,x.id);}catch{}}},[l]),h=useCallback(async()=>{try{let x=await fn(e.testRunToken);if(!x&&!T){a("no-match"),s(null);return}if(x&&!e.ticketId){a("no-match"),s(null);return}let g=new URLSearchParams;x&&g.set("token",x),e.ticketId&&g.set("ticket_id",e.ticketId),g.set("app_slug",e.appSlug),e.environment&&g.set("environment",e.environment),T&&g.set("test_run_id",T),e.targetUrl&&g.set("target_url",e.targetUrl),e.version&&g.set("version",e.version),e.commitSha&&g.set("commit_sha",e.commitSha),e.prNumber&&g.set("pr_number",String(e.prNumber)),e.branchName&&g.set("branch_name",e.branchName);let n=await fetch(`${e.config.serverUrl}/widget/test-run?${g.toString()}`,{headers:Fe(e.config,e.authToken)});if(n.status===404){a("no-match"),s(null);return}if(n.status===401||n.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),a("error");return}if(!n.ok){a("error");return}let i=await n.json();if(!i||i.run===null){a("no-match"),s(null);return}y(i),a(i.status==="completed"?"completed":"ready");}catch{a("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,y]);return useEffect(()=>{h();},[h]),tt(e.config,t?.id,h),{run:t,widgetState:d,fetchRun:h,setVerdict:async(x,g,n,i="human")=>(s(N=>{if(!N)return null;let z=N.test_cases.map(C=>C.id===x?{...C,verdict:g,fail_reason:g==="fail"&&n||null,verdict_by_display_name:i,verdict_at:new Date().toISOString()}:C),k={total:z.length,pending:0,pass:0,fail:0,skip:0};return z.forEach(C=>{C.verdict in k&&k[C.verdict]++;}),{...N,test_cases:z,summary:k}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${x}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...Fe(e.config,e.authToken)},body:JSON.stringify({verdict:g,fail_reason:n,display_name:i})})).ok),markComplete:async()=>t?(s(g=>g?{...g,status:"completed"}:null),a("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${t.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...Fe(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!t)return false;let x=await fetch(`${e.config.serverUrl}/widget/test-runs/${t.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...Fe(e.config,e.authToken)}});return x.ok&&h(),x.ok},setRun:y}}var it="botbuddy-widget-auth-token",at="botbuddy-widget-auth-name";function Le(e){if(!e)return null;try{let t=e.split(".")[1];if(!t)return null;let s=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(t.length/4)*4,"="),d=atob(s),a=JSON.parse(d);return typeof a.exp=="number"?a.exp*1e3:null}catch{return null}}var mn=2500,yn=6e4;function lt(e){let[t,s]=useState(()=>{try{return localStorage.getItem(it)}catch(S){return console.warn("Unable to read BotBuddy widget auth token",S),null}}),[d,a]=useState(()=>{try{return localStorage.getItem(at)}catch(S){return console.warn("Unable to read BotBuddy widget display name",S),null}}),l=useRef(null),R=useCallback((S,x)=>{s(S),x&&a(x);try{localStorage.setItem(it,S),x&&localStorage.setItem(at,x);}catch(g){console.warn("Unable to persist BotBuddy widget auth token",g);}},[]);useEffect(()=>{let S=new URL(e).origin,x=g=>{g.origin===S&&g.data?.type==="botbuddy-widget-auth"&&g.data.token&&R(g.data.token,g.data.displayName||"human");};return window.addEventListener("message",x),()=>window.removeEventListener("message",x)},[e,R]);let v=useCallback(()=>{if(l.current)return l.current;if(typeof window>"u"||typeof document>"u")return Promise.resolve(null);let S=new URL(e).origin,x=new URL("/widget-auth",e);x.searchParams.set("silent","1"),x.searchParams.set("origin",window.location.origin);let g=new Promise(n=>{let i=document.createElement("iframe");i.setAttribute("aria-hidden","true"),i.style.position="fixed",i.style.width="1px",i.style.height="1px",i.style.opacity="0",i.style.pointerEvents="none",i.style.border="0",i.style.left="-9999px",i.style.top="-9999px",i.src=x.toString();let U=false,N=()=>{window.removeEventListener("message",z),clearTimeout(k);try{i.remove();}catch{}l.current=null;},z=C=>{if(C.origin===S){if(C.data?.type==="botbuddy-widget-auth-failed"){if(U)return;U=true,n(null),N();return}C.data?.type!=="botbuddy-widget-auth"||!C.data.token||U||(U=true,n(String(C.data.token)),N());}},k=setTimeout(()=>{U||(U=true,n(null),N());},mn);window.addEventListener("message",z),document.body.appendChild(i);});return l.current=g,g},[e]);useEffect(()=>{if(!t)return;let S=Le(t);if(!S)return;let x=S-Date.now()-yn,g=window.setTimeout(()=>{v();},Math.max(0,x));return ()=>window.clearTimeout(g)},[t,v]);let T=useCallback(()=>{let S=new URL("/widget-auth",e);S.searchParams.set("origin",window.location.origin);let x=420,g=520,n=window.screenX+(window.innerWidth-x)/2,i=window.screenY+(window.innerHeight-g)/2;window.open(S.toString(),"botbuddy-auth",`width=${x},height=${g},left=${n},top=${i},popup=yes`);},[e]),[,y]=useState(0);useEffect(()=>{let S=Le(t);if(!S)return;let x=S-Date.now();if(x<=0)return;let g=window.setTimeout(()=>y(n=>n+1),x);return ()=>window.clearTimeout(g)},[t]);let h=useCallback(()=>{s(null),a(null);try{localStorage.removeItem(it),localStorage.removeItem(at);}catch(S){console.warn("Unable to clear BotBuddy widget auth token",S);}},[]),B=Le(t),j=B!==null&&B<=Date.now();return {token:t,displayName:d,isAuthenticated:!!t,isExpired:j,openLogin:T,refreshNow:v,logout:h}}var Oe=null;function hn(){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 He(){return Oe||(Oe=(async()=>{if(typeof fetch>"u")return null;try{let e=await fetch(hn(),{cache:"no-store"});if(!e.ok)return null;let t=await e.json();if(!t||typeof t!="object"||Array.isArray(t))return null;let s={};for(let[d,a]of Object.entries(t))typeof a=="string"&&a.length>0&&(s[d]=a);return s}catch{return null}})(),Oe)}async function Ut(e){return (await He())?.[e]??null}function xn(e){let t=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),s="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",d=[],a=0,l=0;for(let R of t){let v=s.indexOf(R);if(v<0)throw new Error("Invalid Base32 character in TOTP secret");l=l<<5|v,a+=5,a>=8&&(a-=8,d.push(l>>>a&255));}return Uint8Array.from(d)}async function It(e,t=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let s=xn(e),d=new Uint8Array(s.byteLength);d.set(s);let a=Math.floor(t/1e3/30),l=new Uint8Array(8),R=Math.floor(a/4294967296),v=a>>>0;l[0]=R>>>24&255,l[1]=R>>>16&255,l[2]=R>>>8&255,l[3]=R&255,l[4]=v>>>24&255,l[5]=v>>>16&255,l[6]=v>>>8&255,l[7]=v&255;let T=await crypto.subtle.importKey("raw",d,{name:"HMAC",hash:"SHA-1"},false,["sign"]),y=await crypto.subtle.sign("HMAC",T,l),h=new Uint8Array(y),B=h[h.length-1]&15;return (((h[B]&127)<<24|(h[B+1]&255)<<16|(h[B+2]&255)<<8|h[B+3]&255)%1e6).toString().padStart(6,"0")}var Wt="0.11.0";function wn(e){let t=new Date(e),d=Date.now()-t.getTime();if(d<6e4)return "just now";if(d<36e5)return `${Math.floor(d/6e4)}m ago`;if(d<864e5)return `${Math.floor(d/36e5)}h ago`;let a=t.getDate(),l=t.toLocaleString("en",{month:"short"}),R=t.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${l} ${a}, ${R}`}var _=({d:e,className:t,size:s=14})=>jsx("svg",{className:t,width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:e})}),m={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01",bot:"M12 8V4H8M2 14h2M20 14h2M15 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M9 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M18 10a6 6 0 0 0-12 0v4a6 6 0 0 0 12 0Z",terminal:"M4 17l6-6-6-6M12 19h8",key:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4",shield:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10",copy:"M20 9h-9a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2-2v-9a2 2 0 0 0-2-2ZM5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1",search:"M11 17.25a6.25 6.25 0 1 1 0-12.5 6.25 6.25 0 0 1 0 12.5ZM16 16l4.5 4.5"};function kn(){let[e,t]=useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return useEffect(()=>{if(typeof window>"u")return;let s=document.documentElement,d=()=>s.classList.contains("dark")?"dark":s.classList.contains("light")?"light":null,a=d();a&&t(a);let l=window.matchMedia("(prefers-color-scheme: dark)"),R=T=>{let y=d();t(y||(T.matches?"dark":"light"));};l.addEventListener("change",R);let v=new MutationObserver(()=>{let T=d();t(T||(l.matches?"dark":"light"));});return v.observe(s,{attributes:true,attributeFilter:["class"]}),()=>{l.removeEventListener("change",R),v.disconnect();}},[]),e}function Sn(e){let t=e==="dark";return {bg:t?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:t?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:t?"#e5e5e5":"#1a1a1a",textMuted:t?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:t?"#555":"#999",border:t?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:t?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:t?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:t?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:t?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:t?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:t?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:t?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:t?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:t?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:t?"#888":"#aaa",btnHover:t?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var _n={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},Rn={pending:m.circle,pass:m.check,fail:m.x,skip:m.skip},Ft={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)"}},Tn=["app.supply-guard.io"];function Cn(e,t=[]){if(!e)return false;let s=e.toLowerCase();return [...Tn,...t].map(a=>a.toLowerCase()).includes(s)}var Mn=e=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:t=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:e.bg,border:t?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:t?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(t,s)=>({width:`${t}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:t=>{let s=Ft[t]||Ft.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:t=>({height:"100%",width:`${t}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:t=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${t}15`,color:t,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(t,s)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:t?`${s}33`:"transparent",color:t?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 dt(e){return e.split("/")[0].trim()}async function En(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 t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.opacity="0",t.style.pointerEvents="none",document.body.appendChild(t),t.focus(),t.select(),t.setSelectionRange(0,e.length);let s=document.execCommand("copy");return document.body.removeChild(t),s}catch{return false}}function $e({config:e,appSlug:t,environment:s,seededUsers:d,authToken:a,tk:l,compact:R=false,onExpand:v,onAuthExpired:T,refreshAuth:y,requestLogin:h,testRunId:B,testRunToken:j,ticketId:S,targetUrl:x,version:g,commitSha:n,prNumber:i,branchName:U}){let[N,z]=useState(false),[k,C]=useState(null),[A,X]=useState(null),[Q,f]=useState(null),[ze,ce]=useState(null),[se,ee]=useState(null),[te,ue]=useState(null);useEffect(()=>{s==="local"&&He();},[s]);let ve=useCallback(u=>{C(u),f(null),ce(null),ue(null);let $=Le(a);if(s!=="local"&&h&&$!==null&&$<=Date.now()){ee({slug:u,token:a||null}),ue(u),C(null),h();return}let P=E=>{f(E),ce(u),window.setTimeout(()=>{ce(L=>L===u?null:L),f(L=>L===E?null:L);},3e3);},M=new URLSearchParams({app_slug:t,seed_user_slug:u,environment:s});B&&M.set("test_run_id",B),j&&M.set("public_token",j),S&&M.set("ticket_id",S),x&&M.set("target_url",x),g&&M.set("version",g),n&&M.set("commit_sha",n),i&&M.set("pr_number",String(i)),U&&M.set("branch_name",U);let I=async E=>{let L={apikey:e.anonKey,Authorization:`Bearer ${E}`};try{let F=await fetch(`${e.serverUrl}/widget/totp-code?${M}`,{headers:L});if(!F.ok){let ye=await F.json().catch(()=>({error:`HTTP ${F.status}`}));return {ok:!1,status:F.status,error:ye.error||`HTTP ${F.status}`}}let Z=await F.json();return {ok:!0,code:String(Z.code)}}catch{return {ok:false,status:0,error:"Network error"}}},V=(async()=>{if(s==="local"){let F=await Ut(u);if(F)try{return {ok:!0,code:await It(F)}}catch{}}let E=await I(a||e.anonKey);if(E.ok||E.status!==401||!y)return E;let L=await y();return L?I(L):{ok:false,status:401,error:"Sign in to BotBuddy to refresh 2FA"}})(),D=null;try{if(typeof ClipboardItem<"u"&&navigator.clipboard?.write){let E=V.then(L=>{if(!L.ok)throw new Error(L.error);return new Blob([L.code],{type:"text/plain"})});D=navigator.clipboard.write([new ClipboardItem({"text/plain":E})]).then(()=>!0).catch(()=>!1);}}catch{}(async()=>{let E=await V;if(!E.ok){E.status===401?(ee({slug:u,token:a||null}),ue(u)):P(E.status===404?"No 2FA seed registered":E.error),C(null);return}let L=D?await D:false,F=L?true:await En(E.code),Z=L||F;X({slug:u,code:E.code,copied:Z}),window.setTimeout(()=>X(ye=>ye?.slug===u?null:ye),Z?2500:6e3),z(false),C(null);})();},[e.serverUrl,e.anonKey,a,t,s,B,j,S,x,g,n,i,U,y,h]),le=useCallback(u=>{ee({slug:u,token:a||null}),h?.();},[a,h]),we=useCallback(u=>{te===u?le(u):ve(u);},[te,le,ve]);useEffect(()=>{if(!se||!a||a===se.token)return;let u=se.slug;ee(null),ve(u);},[a,ve,se]);let ke=useRef(null),Ee=useRef(null);if(useLayoutEffect(()=>{if(!N)return;let u=ke.current,$=Ee.current;if(!u||!$||typeof window>"u")return;let P=()=>{let M=u.getBoundingClientRect(),I=$.getBoundingClientRect(),V=window.innerWidth,D=window.innerHeight,E=M.left,L=M.top-I.height-6;L<8&&(L=M.bottom+6);let F=Math.max(8,V-I.width-8),Z=Math.max(8,D-I.height-8);E=Math.min(Math.max(E,8),F),L=Math.min(Math.max(L,8),Z),$.style.left=`${Math.round(E)}px`,$.style.top=`${Math.round(L)}px`;};return P(),window.addEventListener("scroll",P,true),window.addEventListener("resize",P),()=>{window.removeEventListener("scroll",P,true),window.removeEventListener("resize",P);}},[N,d.length,Q]),useEffect(()=>{if(!N)return;let u=$=>{let P=$.target;Ee.current?.contains(P)||ke.current?.contains(P)||z(false);};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[N]),d.length===0)return null;if(R){let u=d.length>1,$=d[0],P=!u&&te===$,M=F=>{if(F.stopPropagation(),u&&v){v();return}we($);},I=!!ze,V=!!A,D=V&&A.copied,E=V&&!A.copied,L=P?l.blue:I?l.red:D?l.green:E?l.amber:l.purple;return jsxs("span",{onPointerDown:F=>F.stopPropagation(),onPointerUp:F=>F.stopPropagation(),onPointerMove:F=>F.stopPropagation(),onClick:M,style:{display:"inline-flex",alignItems:"center",gap:"3px",color:L,fontWeight:600,cursor:"pointer",letterSpacing:E?"0.08em":void 0},title:P?"Sign in to BotBuddy to refresh 2FA":I?Q||"Failed":E?`Clipboard blocked \u2014 code: ${A.code}`:u?`${d.length} 2FA personas`:`Copy 2FA code for ${d[0]}`,children:[jsx(_,{d:P?m.key:I?m.alert:D?m.check:E?m.copy:m.shield,size:10}),P?jsx(Fragment,{children:"Sign in"}):D?jsx(Fragment,{children:"Copied"}):E?jsx(Fragment,{children:A.code}):I?jsx(Fragment,{children:"Failed"}):jsxs(Fragment,{children:["2FA",u&&` \xB7${d.length}`]})]})}if(d.length===1){let u=d[0],$=k===u,P=A?.slug===u,M=P&&A.copied,I=P&&!A.copied,V=ze===u,D=te===u,E=D?l.blue:V?l.red:M?l.green:I?l.amber:l.purple;return jsxs("button",{onClick:L=>{L.stopPropagation(),we(u);},disabled:$,style:{...Dt(E),cursor:$?"wait":"pointer",opacity:$?.6:1},title:D?"Sign in to BotBuddy to refresh 2FA":V?Q||"Failed":I?`Clipboard blocked \u2014 code: ${A.code}`:`Copy 2FA code for ${u}`,children:[jsx(_,{d:D?m.key:V?m.alert:M?m.check:I?m.copy:m.shield,size:12}),D?"Sign in":M?"Copied":I?A.code:V?"Failed":$?"\u2026":`2FA \xB7 ${u}`]})}let pe=!!te&&!N,ne=!!ze&&!N,Se=!!A&&A.copied,_e=!!A&&!A.copied,Ve=pe?l.blue:ne?l.red:Se?l.green:_e?l.amber:l.purple,Ye=N&&typeof document<"u"?createPortal(jsxs("div",{ref:Ee,onPointerDown:u=>u.stopPropagation(),onMouseDown:u=>u.stopPropagation(),style:{position:"fixed",left:-9999,top:-9999,background:l.bg,border:`1px solid ${l.border}`,borderRadius:6,boxShadow:`0 8px 24px ${l.shadow}`,padding:4,minWidth:220,maxWidth:typeof window<"u"?Math.min(420,window.innerWidth-16):420,zIndex:1e5,fontFamily:"ui-monospace, SFMono-Regular, monospace"},children:[d.map(u=>{let $=k===u,P=te===u;return jsxs("button",{onClick:M=>{M.stopPropagation(),we(u);},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:P?l.blue:l.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},title:P?"Sign in to BotBuddy to refresh 2FA":void 0,onMouseEnter:M=>M.currentTarget.style.background=l.btnHover,onMouseLeave:M=>M.currentTarget.style.background="transparent",children:[jsx(_,{d:P?m.key:m.shield,size:10}),jsx("span",{style:{flex:1,overflowWrap:"anywhere",lineHeight:1.3},children:u}),P?jsx("span",{style:{color:l.blue,fontSize:9},children:"Sign in"}):$?jsx("span",{style:{color:l.textMuted,fontSize:9},children:"\u2026"}):null]},u)}),Q&&jsx("div",{style:{padding:"4px 8px",fontSize:9,color:l.red},children:Q})]}),document.body):null;return jsxs(Fragment,{children:[jsxs("button",{ref:ke,onClick:u=>{if(u.stopPropagation(),pe&&te){le(te);return}z($=>!$),f(null),ce(null);},style:{...Dt(Ve),cursor:"pointer"},title:pe?"Sign in to BotBuddy to refresh 2FA":ne?Q||"Failed":_e?`Clipboard blocked \u2014 code: ${A.code}`:"Choose a persona to copy a 2FA code for",children:[jsx(_,{d:pe?m.key:ne?m.alert:Se?m.check:_e?m.copy:m.shield,size:12}),pe?"Sign in":Se?"Copied":_e?A.code:ne?"Failed":`2FA \xB7 ${d.length}`,!pe&&jsx(_,{d:N?m.chevronUp:m.chevronDown,size:8})]}),Ye]})}function Dt(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 Ot="botbuddy-widget-state";function Nn({config:e,appSlug:t,environment:s,ticketId:d,testRunId:a,testRunToken:l,targetUrl:R,version:v,commitSha:T,prNumber:y,branchName:h,onNavigate:B,displayName:j="human",defaultMode:S="mini",defaultPosition:x}){let g=kn(),n=useMemo(()=>Sn(g),[g]),i=useMemo(()=>Mn(n),[n]),[U,N]=useState(false),[z,k]=useState(false),[C,A]=useState(false),X=useRef(false),Q=e.dashboardUrl||"https://app.bot-buddy.ai",f=lt(Q),ce=(()=>{try{let r=typeof window<"u"?localStorage.getItem(Ot):null;if(r)return JSON.parse(r)}catch{}return null})(),[se,ee]=useState(ce?.mode||S),[te,ue]=useState(""),[ve,le]=useState(null),[we,ke]=useState(null),[Ee,pe]=useState(new Set),[ne,Se]=useState(""),_e=useCallback(r=>{pe(p=>{let w=new Set(p);return w.has(r)?w.delete(r):w.add(r),w});},[]),Ve=ce?.x??x?.x??16,Ye=ce?.y??x?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:u,setPos:$,onPointerDown:P,onPointerMove:M,onPointerUp:I,didDrag:V}=et(Ve,Ye),D=useRef(null);useEffect(()=>{try{localStorage.setItem(Ot,JSON.stringify({mode:se,x:u.x,y:u.y}));}catch{}},[se,u.x,u.y]),useLayoutEffect(()=>{if(typeof window>"u")return;let r=D.current;if(!r)return;let p=r.getBoundingClientRect(),w=Qe(u.x,u.y,p.width,p.height,window.innerWidth,window.innerHeight);(w.x!==u.x||w.y!==u.y)&&$(w);}),useEffect(()=>{if(typeof window>"u")return;let r=()=>{let p=D.current;if(!p)return;let w=p.getBoundingClientRect(),H=Qe(u.x,u.y,w.width,w.height,window.innerWidth,window.innerHeight);(H.x!==u.x||H.y!==u.y)&&$(H);};return window.addEventListener("resize",r),()=>window.removeEventListener("resize",r)},[u.x,u.y,$]);let E=useRef(f.isAuthenticated);useEffect(()=>{!E.current&&f.isAuthenticated&&ee("max"),E.current=f.isAuthenticated;},[f.isAuthenticated]);let L="botbuddy-widget-max-size",F=()=>{try{let r=localStorage.getItem(L);if(r)return JSON.parse(r)}catch{}return {w:340,h:500}},[Z,ye]=useState(F),Ne=useRef(false),Pe=useRef({x:0,y:0,w:0,h:0}),Gt=useCallback(r=>{r.stopPropagation(),Ne.current=true,Pe.current={x:r.clientX,y:r.clientY,w:Z.w,h:Z.h},r.target.setPointerCapture(r.pointerId);},[Z]),Xt=useCallback(r=>{if(!Ne.current)return;let p=Math.max(280,Math.min(600,Pe.current.w+(r.clientX-Pe.current.x))),w=Math.max(300,Math.min(window.innerHeight*.9,Pe.current.h+(r.clientY-Pe.current.y)));ye({w:p,h:w});},[]),Zt=useCallback(()=>{Ne.current&&(Ne.current=false,ye(r=>(localStorage.setItem(L,JSON.stringify(r)),r)));},[]),re=R??(typeof window<"u"?window.location.href:void 0),bt=f.displayName||j,[de,mt]=useState(null);useEffect(()=>{if(f.isAuthenticated)return;let r=new URLSearchParams;l&&r.set("token",l),d&&r.set("ticket_id",d),r.set("app_slug",t),s&&r.set("environment",s),a&&r.set("test_run_id",a),re&&r.set("target_url",re),v&&r.set("version",v),T&&r.set("commit_sha",T),y&&r.set("pr_number",String(y)),h&&r.set("branch_name",h),fetch(`${e.serverUrl}/widget/preview?${r}`,{headers:{apikey:e.anonKey}}).then(p=>p.json()).then(p=>mt(p)).catch(()=>mt(null));},[f.isAuthenticated,e.serverUrl,e.anonKey,t,s,d,a,l,re,v,T,y,h]);let yt=useRef(false),Qt=useCallback(()=>{yt.current||f.logout();},[f.logout]),{run:b,widgetState:he,fetchRun:en,setVerdict:ht,markComplete:tn,resetRun:nn,setRun:xt}=rt({config:e,appSlug:t,environment:s,ticketId:d,testRunId:a,testRunToken:l,targetUrl:re,version:v,commitSha:T,prNumber:y?String(y):void 0,branchName:h,authToken:f.token,onAuthExpired:Qt});yt.current=!!b;let[vt,wt]=useState([]),[kt,Ae]=useState([]),[qe,St]=useState(false),[_t,Rt]=useState(null),[rn,Ue]=useState(false),ge=Cn(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);useEffect(()=>{if((s??"local")!=="local"||ge){wt([]);return}let r=true;return He().then(p=>{r&&wt(Object.keys(p||{}));}),()=>{r=false;}},[s,ge]);let on=useCallback(async()=>{if(!(!f.isAuthenticated||!f.token)){St(true),Rt(null);try{let r=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${f.token}`},body:JSON.stringify({app_slug:t,environment:s||"local",target_url:re,branch_name:h,commit_sha:T,pr_number:y,ticket_id:d,title:`${d||t} local validation`})}),p=await r.json().catch(()=>({}));if(!r.ok)throw new Error(p.error||`HTTP ${r.status}`);xt(p),ee("max");}catch(r){Rt(r.message);}finally{St(false);}}},[f.isAuthenticated,f.token,e.serverUrl,e.anonKey,t,s,re,h,T,y,d,xt]),Ie=useCallback(async(r,p,w)=>{ke(r);try{await ht(r,p,w,bt);}finally{ke(null),le(null),ue("");}},[ht,bt]),K=b?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},sn=K.total>0&&K.pending===0,Re=he==="completed",We=useMemo(()=>{let r=b?.test_cases||[];if(!ne.trim())return r;let p=ne.toLowerCase();return r.filter(w=>w.title.toLowerCase().includes(p)||w.description&&w.description.toLowerCase().includes(p)||w.url_path&&w.url_path.toLowerCase().includes(p)||w.seed_user&&w.seed_user.toLowerCase().includes(p))},[b?.test_cases,ne]),Tt=useMemo(()=>{let r=We,p=b?.test_cases||[];if(new Set(p.map(J=>J.source_pr_number)).size<=1)return null;let H=[],be=new Map;r.forEach(J=>{let q=J.source_pr_number;be.has(q)||be.set(q,[]),be.get(q).push(J);});let Bt=[...be.keys()].sort((J,q)=>J===null?1:q===null?-1:q-J);for(let J of Bt){let q=be.get(J),Ge={total:q.length,pass:0,fail:0,skip:0,pending:0};q.forEach(zt=>{zt.verdict in Ge&&Ge[zt.verdict]++;}),H.push({key:J!=null?`pr-${J}`:"general",label:J!=null?`PR #${J}`:"General",cases:q,summary:Ge});}return H.filter(J=>J.cases.length>0)},[We,b?.test_cases]),Ct=K.total>0?(K.pass+K.fail)/K.total*100:0,Y=s??b?.environment??null,fe=useMemo(()=>{if(!Y||Y==="production"||ge)return [];let r=b?.test_cases||[],p=new Set;for(let w of r)w.seed_user&&p.add(dt(w.seed_user));if(Y==="local")for(let w of vt)p.add(dt(w));for(let w of kt)p.add(dt(w));return [...p]},[b?.test_cases,Y,vt,kt,ge]);useEffect(()=>{if(!Y||Y==="production"||ge||!f.isAuthenticated||!f.token){Ae([]);return}let r=true,p=`${e.serverUrl}/widget/totp-seeds?${new URLSearchParams({app_slug:t,environment:Y})}`,w=H=>fetch(p,{headers:{apikey:e.anonKey,Authorization:`Bearer ${H}`}});return (async()=>{try{let H=await w(f.token);if(H.status===401&&f.refreshNow){let q=await f.refreshNow();q&&(H=await w(q));}if(!r)return;if(!H.ok){Ae([]);return}let be=await H.json().catch(()=>null),J=(Array.isArray(be?.seeds)?be.seeds:[]).map(q=>q?.seed_user_slug).filter(q=>typeof q=="string"&&q.length>0);Ae(J);}catch{r&&Ae([]);}})(),()=>{r=false;}},[Y,ge,f.isAuthenticated,f.token,f.refreshNow,t,e.serverUrl,e.anonKey]);let Je=useMemo(()=>{let r=b?.auto_tooltip_seconds??de?.auto_tooltip_seconds;return r!=null&&r>0?r*1e3:0},[b,de]),Mt=he==="ready"||he==="completed"||de?.enabled&&de.run;useEffect(()=>{if(!Mt||X.current||Je<=0)return;X.current=true,k(true);let r=window.setTimeout(()=>k(false),Je);return ()=>window.clearTimeout(r)},[Mt,Je]);let Et=r=>jsxs("div",{style:i.caseRow,children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsx("div",{style:{marginTop:"2px",flexShrink:0,color:_n[r.verdict]},children:we===r.id?jsx(_,{d:m.loader,className:""}):jsx(_,{d:Rn[r.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:n.text,lineHeight:1.3},children:r.title}),r.description&&jsx("div",{style:{fontSize:"9px",color:n.gripColor,marginTop:"2px"},children:r.description}),r.seed_user&&jsxs("div",{style:{fontSize:"9px",color:n.amber,marginTop:"3px",display:"inline-flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",background:`${n.amber}12`,border:`1px solid ${n.amber}30`},children:[jsx(_,{d:m.key,size:10}),jsx("span",{children:r.seed_user})]}),r.url_path&&jsxs("a",{href:r.url_path,target:"_blank",rel:"noopener noreferrer",onClick:p=>{p.stopPropagation(),B&&(p.preventDefault(),B(r.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(_,{d:m.externalLink,size:10}),r.url_path]}),r.verdict==="fail"&&r.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:n.red,marginTop:"2px"},children:["\u2717 ",r.fail_reason]})]})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(p=>jsx("button",{onClick:()=>{if(r.verdict===p){Ie(r.id,"pending"),le(null);return}if(p==="fail"){le(r.id),ue("");return}le(null),Ie(r.id,p);},disabled:we!==null,style:i.verdictBtn(r.verdict===p,p==="pass"?n.green:p==="fail"?n.red:n.amber),children:p.toUpperCase()},p)),r.created_by_agent_name&&jsxs("span",{style:{fontSize:"8px",color:n.purple,marginLeft:"4px",display:"inline-flex",alignItems:"center",gap:"2px"},children:[jsx(_,{d:m.bot,size:8}),r.created_by_agent_name]}),r.verdict_by_display_name&&jsxs("span",{style:{fontSize:"8px",color:n.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[r.verdict_by_display_name,r.verdict_at&&jsx("span",{style:{opacity:.7},children:wn(r.verdict_at)})]})]}),ve===r.id&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:te,onChange:p=>ue(p.target.value),onKeyDown:p=>{p.key==="Enter"&&Ie(r.id,"fail",te.trim()||void 0),p.key==="Escape"&&(le(null),ue(""));},placeholder:"Reason (optional)...",style:i.input}),jsx("button",{onClick:()=>{Ie(r.id,"fail",te.trim()||void 0);},style:i.verdictBtn(true,n.red),children:"\u2713"})]})]},r.id);if((he==="no-match"||he==="loading")&&!(!f.isAuthenticated&&de?.enabled&&de.run)){if(!(Y==="local"&&!ge))return null}if(!f.isAuthenticated&&de?.enabled&&de.run){let r=de.run,p=r.summary,w=r.status==="completed";return jsx("div",{ref:D,style:{...i.root,left:u.x,top:u.y},children:jsxs("div",{style:{position:"relative"},onMouseEnter:()=>N(true),onMouseLeave:()=>{N(false),A(false),k(false);},children:[jsxs("div",{style:{...i.pill(w),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:P,onPointerMove:M,onPointerUp:()=>{I();},children:[jsx(_,{d:m.grip,size:10,className:""}),r.ticket_id&&r.ticket_url?jsx("a",{href:r.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:H=>H.stopPropagation(),style:{color:n.amber,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:r.ticket_id}):null,r.pr_url?jsxs("a",{href:r.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:H=>H.stopPropagation(),style:{color:n.blue,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:["PR#",r.pr_number??r.pr_id]}):null,r.created_by_agent_name?r.codex_thread_id?jsxs("a",{href:`codex://threads/${r.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",onClick:H=>H.stopPropagation(),style:{color:n.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(_,{d:m.terminal,size:10}),r.created_by_agent_name]}):jsxs("span",{style:{color:n.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(_,{d:m.bot,size:10}),r.created_by_agent_name]}):null,jsxs("span",{style:w?{color:n.green}:void 0,children:[p.pass,"/",p.total]}),p.fail>0&&jsxs("span",{style:{color:n.red},children:[p.fail,"\u2717"]}),jsx("span",{onClick:H=>{H.stopPropagation(),f.openLogin();},style:{color:n.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!C&&(U||z)&&r.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsx("div",{style:{fontSize:"11px",fontWeight:700,color:n.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:r.title}),(r.description||r.intro_notes)&&jsx("div",{style:{fontSize:"10px",color:n.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:r.description||r.intro_notes}),jsx("div",{style:{marginTop:"4px",fontSize:"9px",color:n.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!f.isAuthenticated)return jsxs("div",{ref:D,style:{...i.root,left:u.x,top:u.y,width:220,minHeight:0,cursor:"move",userSelect:"none",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`},onPointerDown:P,onPointerMove:M,onPointerUp:I,children:[jsx("div",{style:{...i.handle,borderBottom:"none"},children:jsxs("div",{style:i.sub,children:[jsx(_,{d:m.grip,size:10,className:""}),jsx(_,{d:m.clipboard,size:12,className:""}),jsx("span",{style:{fontWeight:600},children:"BotBuddy"})]})}),jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[jsx("div",{style:{fontSize:"9px",color:n.textMuted,marginBottom:"8px"},children:"Sign in to access test cases"}),Y==="local"&&fe.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx($e,{config:e,appSlug:t,environment:Y,seededUsers:fe,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:n,testRunId:b?.id||a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:T,prNumber:y,branchName:h,onAuthExpired:f.logout})}),jsx("button",{onClick:r=>{r.stopPropagation(),f.openLogin();},style:{fontSize:"10px",fontWeight:600,padding:"6px 16px",borderRadius:"6px",border:`1px solid ${n.green}`,background:`${n.green}22`,color:n.green,cursor:"pointer",width:"100%"},children:"Sign in to test"})]})]});if(!b&&Y==="local"&&!ge)return rn?jsx("div",{ref:D,style:{...i.root,left:u.x,top:u.y},children:jsxs("div",{style:i.card(240,false),children:[jsxs("div",{style:i.handle,onPointerDown:P,onPointerMove:M,onPointerUp:I,onClick:()=>{V.current||Ue(false);},children:[jsx(_,{d:m.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:i.title,children:"BotBuddy"}),h&&jsx("div",{style:i.sub,children:jsxs("span",{children:["\u2387 ",h]})})]}),jsx(_,{d:m.chevronUp,className:""}),jsx("button",{style:i.btn,onClick:r=>{r.stopPropagation(),Ue(false);},children:jsx(_,{d:m.minus,className:""})})]}),jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[fe.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx($e,{config:e,appSlug:t,environment:Y,seededUsers:fe,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:n,testRunId:a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:T,prNumber:y,branchName:h,onAuthExpired:f.logout})}),jsx("button",{onClick:r=>{r.stopPropagation(),on();},disabled:qe,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${n.green}`,background:`${n.green}22`,color:n.green,cursor:qe?"wait":"pointer",width:"100%"},children:qe?"Creating...":"Create test run for this branch"}),_t&&jsx("div",{style:{fontSize:"9px",color:n.red,marginTop:"8px"},children:_t})]})]})}):jsx("div",{ref:D,style:{...i.root,left:u.x,top:u.y},children:jsxs("div",{style:{...i.pill(false),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:P,onPointerMove:M,onPointerUp:()=>{I(),V.current||Ue(true);},children:[jsx(_,{d:m.grip,size:9,className:""}),jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),fe.length>0&&jsx($e,{config:e,appSlug:t,environment:Y,seededUsers:fe,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:n,compact:true,onExpand:()=>Ue(true),testRunId:a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:T,prNumber:y,branchName:h,onAuthExpired:f.logout})]})});let Nt=()=>{V.current||(k(false),ee(r=>{let p=r==="mini"?"max":"mini";return A(p==="mini"),p}));},Pt=({icon:r,onClick:p})=>jsx("button",{style:i.btn,onClick:w=>{w.stopPropagation(),p(w);},children:jsx(_,{d:r,className:""})}),Lt=()=>jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${n.borderSubtle}`,flexShrink:0},children:[b?.pr_url&&jsxs("a",{href:b.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link(n.blue),textDecoration:"none"},children:[jsx(_,{d:m.pr,size:12}),b.pr_number?`PR#${b.pr_number}`:b.pr_id||"PR",jsx(_,{d:m.externalLink,size:8})]}),b?.ticket_url&&jsxs("a",{href:b.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link(n.amber),textDecoration:"none"},children:[jsx(_,{d:m.ticket,size:12}),b.ticket_id||"Ticket",jsx(_,{d:m.externalLink,size:8})]}),b?.created_by_agent_name&&(b.codex_thread_id?jsxs("a",{href:`codex://threads/${b.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...i.link(n.purple),textDecoration:"none"},children:[jsx(_,{d:m.bot,size:12}),b.created_by_agent_name,jsx(_,{d:m.externalLink,size:8})]}):jsxs("span",{style:{...i.link(n.purple)},children:[jsx(_,{d:m.bot,size:12}),b.created_by_agent_name]})),Y&&jsx($e,{config:e,appSlug:t,environment:Y,seededUsers:fe,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:n,testRunId:b?.id||a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:T,prNumber:y,branchName:h,onAuthExpired:f.logout}),jsx("span",{style:{...i.badge(b?.environment||"custom"),marginLeft:"auto"},children:b?.environment})]}),$t=()=>jsxs("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:`1px solid ${n.borderSubtle}`,background:n.bgSoft,flexShrink:0},children:[jsxs("button",{onClick:()=>{navigator.clipboard.writeText(Wt);},style:{fontSize:"9px",fontWeight:600,color:n.versionText,letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxs("span",{style:{color:n.versionNum},children:["v",Wt]})]}),f.isAuthenticated&&(f.isExpired?jsx("button",{onClick:r=>{r.stopPropagation(),f.openLogin();},style:{fontSize:"8px",color:n.blue,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Widget session expired \u2014 sign in to refresh",children:"sign in"}):jsx("button",{onClick:r=>{r.stopPropagation(),f.logout();},style:{fontSize:"8px",color:n.textFaint,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Sign out of widget",children:"sign out"}))]});return jsxs("div",{ref:D,style:{...i.root,left:u.x,top:u.y},children:[se==="mini"&&jsxs("div",{style:{position:"relative"},onMouseEnter:()=>N(true),onMouseLeave:()=>{N(false),A(false),k(false);},children:[jsxs("div",{style:{...i.pill(Re),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:P,onPointerMove:M,onPointerUp:()=>{I(),V.current||Nt();},children:[jsx(_,{d:m.grip,size:9,className:""}),b?.ticket_id&&jsx("span",{style:{color:n.amber,fontWeight:600},children:b.ticket_id}),b?.pr_number&&jsxs("span",{style:{color:n.blue,fontWeight:600},children:["PR#",b.pr_number]}),jsxs("span",{style:Re?{color:n.green}:void 0,children:[K.pass,"/",K.total]}),K.fail>0&&jsxs("span",{style:{color:n.red},children:[K.fail,"\u2717"]}),Y&&jsx($e,{config:e,appSlug:t,environment:Y,seededUsers:fe,authToken:f.token,refreshAuth:f.refreshNow,requestLogin:f.openLogin,tk:n,compact:true,onExpand:()=>ee("expanded"),testRunId:b?.id||a,testRunToken:l,ticketId:d,targetUrl:re,version:v,commitSha:T,prNumber:y,branchName:h,onAuthExpired:f.logout})]}),!C&&(U||z)&&b?.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"180px",maxWidth:"260px",padding:"8px 12px",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsx("div",{style:{fontSize:"11px",fontWeight:700,color:n.text,lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical"},children:b.title}),(b.description||b.intro_notes)&&jsx("div",{style:{fontSize:"10px",color:n.textMuted,marginTop:"4px",lineHeight:1.35,overflow:"hidden",textOverflow:"ellipsis",display:"-webkit-box",WebkitLineClamp:3,WebkitBoxOrient:"vertical"},children:b.description||b.intro_notes})]})]}),se==="expanded"&&jsxs("div",{style:i.card(300,Re),children:[jsxs("div",{style:i.handle,onPointerDown:P,onPointerMove:M,onPointerUp:I,onClick:Nt,children:[jsx(_,{d:m.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:i.title,children:b?.title}),jsx("div",{style:i.sub,children:b?.branch_name&&jsxs("span",{children:["\u2387 ",b.branch_name]})})]}),jsx(_,{d:m.chevronUp,className:""}),jsx(Pt,{icon:m.minus,onClick:()=>{k(false),A(true),ee("mini");}})]}),jsxs("div",{style:i.stats,children:[jsxs("span",{style:{color:n.green},children:[K.pass,"\u2713"]}),jsxs("span",{style:{color:n.red},children:[K.fail,"\u2717"]}),jsxs("span",{style:{color:n.amber},children:[K.skip,"\u23ED"]}),jsxs("span",{style:{color:n.gripColor},children:[K.pending,"\u25CC"]}),jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:K.total})]}),b?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:n.gripColor,borderBottom:`1px solid ${n.borderSubtle}`,flexShrink:0},children:b.description}),Lt(),$t(),jsx("div",{style:i.progress,children:jsx("div",{style:i.progressBar(Ct)})})]}),se==="max"&&jsxs("div",{style:{...i.card(Z.w,Re),height:Z.h,position:"relative"},children:[jsxs("div",{style:i.handle,onPointerDown:P,onPointerMove:M,onPointerUp:I,onClick:()=>{V.current||ee("expanded");},children:[jsx(_,{d:m.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:i.title,children:b?.title}),jsx("div",{style:i.sub,children:b?.branch_name&&jsxs("span",{children:["\u2387 ",b.branch_name]})})]}),jsx(_,{d:m.chevronDown,className:""}),jsx(Pt,{icon:m.minus,onClick:()=>{k(false),A(true),ee("mini");}})]}),jsxs("div",{style:i.stats,children:[jsxs("span",{style:{color:n.green},children:[K.pass,"\u2713"]}),jsxs("span",{style:{color:n.red},children:[K.fail,"\u2717"]}),jsxs("span",{style:{color:n.amber},children:[K.skip,"\u23ED"]}),jsxs("span",{style:{color:n.gripColor},children:[K.pending,"\u25CC"]}),jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:K.total})]}),b?.intro_notes&&jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${n.borderSubtle}`,fontSize:"10px",color:n.textMuted,fontStyle:"italic",flexShrink:0},children:b.intro_notes}),(b?.test_cases||[]).length>5&&jsxs("div",{style:{padding:"4px 12px",borderBottom:`1px solid ${n.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",flexShrink:0},children:[jsx(_,{d:m.search,size:11,className:""}),jsx("input",{value:ne,onChange:r=>Se(r.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:n.text,fontFamily:"monospace"}}),ne&&jsx("button",{onClick:()=>Se(""),style:{background:"none",border:"none",cursor:"pointer",color:n.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),he==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(_,{d:m.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:n.red},children:"Failed to load"}),jsx("button",{onClick:en,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),Re&&jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg},children:[jsx(_,{d:m.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:n.green,flex:1},children:"Run completed"}),jsx("button",{onClick:nn,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),he!=="error"&&jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(b?.test_cases||[]).length===0?jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:"No test cases"}):We.length===0?jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:['No matches for "',ne,'"']}):Tt?Tt.map(r=>{let p=Ee.has(r.key);return jsxs("div",{children:[jsxs("button",{onClick:()=>_e(r.key),style:{width:"100%",display:"flex",alignItems:"center",gap:"6px",padding:"5px 12px",background:n.bgSoft,cursor:"pointer",border:"none",borderLeft:"none",borderRight:"none",borderBottomStyle:"solid",borderTopStyle:"solid",borderBottomWidth:"1px",borderTopWidth:"1px",borderBottomColor:n.borderSubtle,borderTopColor:n.borderSubtle,backgroundColor:n.bgSoft},children:[jsx(_,{d:p?m.chevronDown:m.chevronUp,size:10,className:""}),jsx("span",{style:{fontSize:"10px",fontWeight:700,color:n.blue,flex:1,textAlign:"left"},children:r.label}),jsxs("span",{style:{fontSize:"9px",color:n.green},children:[r.summary.pass,"\u2713"]}),jsxs("span",{style:{fontSize:"9px",color:n.red},children:[r.summary.fail,"\u2717"]}),jsxs("span",{style:{fontSize:"9px",color:n.gripColor},children:[r.summary.pending,"\u25CC"]}),jsx("span",{style:{fontSize:"9px",color:n.textFaint},children:r.summary.total})]}),!p&&r.cases.map(w=>Et(w))]},r.key)}):We.map(r=>Et(r))}),sn&&!Re&&jsxs("div",{style:{padding:"6px 12px",borderTop:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg,display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsx("span",{style:{fontSize:"9px",color:n.green},children:"All resolved"}),jsx("button",{onClick:tn,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:n.green,border:`1px solid ${n.greenBorderSubtle}`,cursor:"pointer"},children:"COMPLETE"})]}),Lt(),$t(),jsx("div",{style:i.progress,children:jsx("div",{style:i.progressBar(Ct)})}),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:Gt,onPointerMove:Xt,onPointerUp:Zt,onPointerEnter:r=>r.currentTarget.style.opacity="0.7",onPointerLeave:r=>{Ne.current||(r.currentTarget.style.opacity="0.3");},children:jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsx("path",{d:"M7 1v6H1",fill:"none",stroke:n.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}var Bn=1e4,Be=new Map;var Ke=class extends Error{};async function zn(e,t,s){let d={headers:{authorization:`Bearer ${t}`}};try{return await fetch(e,{...d,signal:s})}catch(a){if(a instanceof TypeError&&/signal/i.test(a.message)&&!s.aborted)return fetch(e,d);throw a}}function An(e){let t=e;return !!t&&typeof t=="object"&&typeof t.tenant=="string"&&Array.isArray(t.entries)&&t.entries.every(s=>!!s&&typeof s.id=="string"&&typeof s.title=="string"&&!!s.body&&Array.isArray(s.body.ast)&&Array.isArray(s.links))}function ct({endpoint:e,getToken:t,timeoutMs:s=Bn}){let[d,a]=useState(()=>({feed:null,error:null,loading:true,stale:false})),[l,R]=useState(0),v=useRef(t);v.current=t,useEffect(()=>{let y=new AbortController,h=true,B=false,j=setTimeout(()=>{B=true,y.abort();},s),S=new Promise((n,i)=>{y.signal.addEventListener("abort",()=>i(new Error("timeout")),{once:true});});S.catch(()=>{}),a(n=>({...n,error:null,loading:true}));let x=null,g=(n,i)=>{if(i&&Be.delete(e),!h)return;let U=i||x===null?void 0:Be.get(e)?.get(x);a({feed:U??null,error:n,loading:false,stale:!!U});};return (async()=>{try{let n;try{n=await Promise.race([Promise.resolve().then(()=>v.current()),S]);}catch(z){throw B||y.signal.aborted?z:new Ke("token_unavailable")}x=n;let i=await Promise.race([zn(e,n,y.signal),S]),U=i.status===401||i.status===403;U&&Be.delete(e);let N=null;try{N=await Promise.race([i.json(),S]);}catch(z){if(B&&!U)throw z;N=null;}if(!h)return;if(i.ok)if(!An(N))g("invalid_feed",!1);else {let z=Be.get(e)??new Map;z.set(n,N),Be.set(e,z),a({feed:N,error:null,loading:!1,stale:!1});}else {let z=N?.error;g(typeof z=="string"?z:`http_${i.status}`,U);}}catch(n){n instanceof Ke?g(n.message,true):g(B?"timeout":n instanceof Error&&n.message||"unavailable",false);}finally{clearTimeout(j);}})(),()=>{h=false,clearTimeout(j),y.abort();}},[e,l,s]);let T=useCallback(()=>R(y=>y+1),[]);return {...d,reload:T}}var gt=["accent","fg","bg","muted","border","radius","font"],Un={accent:"hsl(var(--primary))",fg:"hsl(var(--foreground))",bg:"hsl(var(--card))",muted:"hsl(var(--muted-foreground))",border:"hsl(var(--border))",radius:"var(--radius)",font:"inherit"},Me=(e,t)=>t===void 0?`var(--bbrn-${e},var(--_bbrn-${e}))`:`var(--bbrn-${e},var(--_bbrn-${e},${t}))`,ut=Me("accent","currentColor"),In=Me("muted","color-mix(in srgb,currentColor 72%,transparent)"),pt=Me("border","color-mix(in srgb,currentColor 22%,transparent)"),Wn=`@layer bbrn{
|
|
2
|
-
.bbrn-root{${
|
|
3
|
-
.bbrn-root .bbrn-entry{background:${
|
|
1
|
+
import {useState,useRef,useCallback,useEffect,useMemo,useLayoutEffect,useInsertionEffect,Component}from'react';import {createPortal}from'react-dom';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var Me=8;function et(e,t,s,l,i,d){let T=Math.max(Me,i-s-Me),w=Math.max(Me,d-l-Me);return {x:Math.min(Math.max(e,Me),T),y:Math.min(Math.max(t,Me),w)}}function tt(e,t){let[s,l]=useState({x:e,y:t}),i=useRef(false),d=useRef({x:0,y:0}),T=useRef(false),w=useCallback(f=>{i.current=true,T.current=false,d.current={x:f.clientX-s.x,y:f.clientY-s.y},f.target.setPointerCapture(f.pointerId);},[s]),C=useCallback(f=>{i.current&&(T.current=true,l({x:f.clientX-d.current.x,y:f.clientY-d.current.y}));},[]),h=useCallback(()=>{i.current=false;},[]);return {pos:s,setPos:l,onPointerDown:w,onPointerMove:C,onPointerUp:h,didDrag:T}}function nt(e,t,s){let l=useRef(s);l.current=s,useEffect(()=>{if(!t)return;if(e.supabaseUrl){let d=false,T=null,w=()=>{d||T||(T=setInterval(()=>l.current(),15e3));},C=null;try{let b=new URL(e.supabaseUrl),r=["localhost","127.0.0.1","::1"].includes(b.hostname);if(b.protocol==="http:"&&!r)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");b.protocol=b.protocol==="https:"?"wss:":"ws:",C=b.toString().replace(/\/$/,"");}catch{w();}let h=null,f=null,L=null,j=0,_=()=>{if(!(d||!C)){try{h=new WebSocket(`${C}/realtime/v1/websocket?apikey=${e.anonKey}&vsn=1.0.0`);}catch{w();return}h.onopen=()=>{if(d||!h)return;let b={topic:`realtime:public:test_run_cases:test_run_id=eq.${t}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_run_cases",filter:`test_run_id=eq.${t}`}]}},ref:String(++j)};h.send(JSON.stringify(b));let r={topic:`realtime:public:test_runs:id=eq.${t}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_runs",filter:`id=eq.${t}`}]}},ref:String(++j)};h.send(JSON.stringify(r)),f=setInterval(()=>{h?.readyState===WebSocket.OPEN&&h.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++j)}));},3e4);},h.onmessage=b=>{try{JSON.parse(b.data).event==="postgres_changes"&&l.current();}catch{}},h.onclose=()=>{x(),d||(L=setTimeout(_,3e3));},h.onerror=()=>{h?.close();};}},x=()=>{f&&(clearInterval(f),f=null);};return _(),()=>{d=true,x(),L&&clearTimeout(L),T&&clearInterval(T),h&&(h.onclose=null,h.onerror=null,h.close());}}let i=setInterval(()=>l.current(),15e3);return ()=>clearInterval(i)},[e.supabaseUrl,e.anonKey,t]);}var fn="botbuddy:created-test-run:";function bn(e){if(!e)return "";try{return new URL(e).origin}catch{return e}}function mn(e){return `${fn}${encodeURIComponent([e.appSlug,e.environment||"",e.ticketId||"",bn(e.targetUrl),e.branchName||""].join("|"))}`}function De(e,t){let s={apikey:e.anonKey};return t?s.Authorization=`Bearer ${t}`:e.apiKey?s.Authorization=`Bearer ${e.apiKey}`:s.Authorization=`Bearer ${e.anonKey}`,s}async function yn(e){if(e)return e;try{let t=await fetch("/.botbuddy-token",{cache:"no-store"});if(t.ok){let s=(await t.text()).trim();if(s.startsWith("public_"))return s}}catch{}try{let t=import.meta?.env?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(t&&typeof t=="string"&&t.startsWith("public_"))return t}catch{}return null}function ot(e){let[t,s]=useState(null),[l,i]=useState("loading"),d=mn(e),[T,w]=useState(()=>{if(e.testRunId)return e.testRunId;try{return localStorage.getItem(d)||void 0}catch{return}}),C=e.testRunId||T,h=useCallback(x=>{if(s(x),!!x?.id){w(x.id);try{localStorage.setItem(d,x.id);}catch{}}},[d]),f=useCallback(async()=>{try{let x=await yn(e.testRunToken);if(!x&&!C){i("no-match"),s(null);return}if(x&&!e.ticketId){i("no-match"),s(null);return}let b=new URLSearchParams;x&&b.set("token",x),e.ticketId&&b.set("ticket_id",e.ticketId),b.set("app_slug",e.appSlug),e.environment&&b.set("environment",e.environment),C&&b.set("test_run_id",C),e.targetUrl&&b.set("target_url",e.targetUrl),e.version&&b.set("version",e.version),e.commitSha&&b.set("commit_sha",e.commitSha),e.prNumber&&b.set("pr_number",String(e.prNumber)),e.branchName&&b.set("branch_name",e.branchName);let r=await fetch(`${e.config.serverUrl}/widget/test-run?${b.toString()}`,{headers:De(e.config,e.authToken)});if(r.status===404){i("no-match"),s(null);return}if(r.status===401||r.status===403){e.authToken&&e.onAuthExpired&&e.onAuthExpired(),i("error");return}if(!r.ok){i("error");return}let c=await r.json();if(!c||c.run===null){i("no-match"),s(null);return}h(c),i(c.status==="completed"?"completed":"ready");}catch{i("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,h]);return useEffect(()=>{f();},[f]),nt(e.config,t?.id,f),{run:t,widgetState:l,fetchRun:f,setVerdict:async(x,b,r,c="human")=>(s(v=>{if(!v)return null;let B=v.test_cases.map(W=>W.id===x?{...W,verdict:b,fail_reason:b==="fail"&&r||null,verdict_by_display_name:c,verdict_at:new Date().toISOString()}:W),V={total:B.length,pending:0,pass:0,fail:0,skip:0};return B.forEach(W=>{W.verdict in V&&V[W.verdict]++;}),{...v,test_cases:B,summary:V}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${x}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...De(e.config,e.authToken)},body:JSON.stringify({verdict:b,fail_reason:r,display_name:c})})).ok),markComplete:async()=>t?(s(b=>b?{...b,status:"completed"}:null),i("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${t.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...De(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!t)return false;let x=await fetch(`${e.config.serverUrl}/widget/test-runs/${t.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...De(e.config,e.authToken)}});return x.ok&&f(),x.ok},setRun:h}}var at="botbuddy-widget-auth-token",lt="botbuddy-widget-auth-name";function Le(e){if(!e)return null;try{let t=e.split(".")[1];if(!t)return null;let s=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(t.length/4)*4,"="),l=atob(s),i=JSON.parse(l);return typeof i.exp=="number"?i.exp*1e3:null}catch{return null}}var xn=2500,vn=6e4;function dt(e){let[t,s]=useState(()=>{try{return localStorage.getItem(at)}catch(_){return console.warn("Unable to read BotBuddy widget auth token",_),null}}),[l,i]=useState(()=>{try{return localStorage.getItem(lt)}catch(_){return console.warn("Unable to read BotBuddy widget display name",_),null}}),d=useRef(null),T=useCallback((_,x)=>{s(_),x&&i(x);try{localStorage.setItem(at,_),x&&localStorage.setItem(lt,x);}catch(b){console.warn("Unable to persist BotBuddy widget auth token",b);}},[]);useEffect(()=>{let _=new URL(e).origin,x=b=>{b.origin===_&&b.data?.type==="botbuddy-widget-auth"&&b.data.token&&T(b.data.token,b.data.displayName||"human");};return window.addEventListener("message",x),()=>window.removeEventListener("message",x)},[e,T]);let w=useCallback(()=>{if(d.current)return d.current;if(typeof window>"u"||typeof document>"u")return Promise.resolve(null);let _=new URL(e).origin,x=new URL("/widget-auth",e);x.searchParams.set("silent","1"),x.searchParams.set("origin",window.location.origin);let b=new Promise(r=>{let c=document.createElement("iframe");c.setAttribute("aria-hidden","true"),c.style.position="fixed",c.style.width="1px",c.style.height="1px",c.style.opacity="0",c.style.pointerEvents="none",c.style.border="0",c.style.left="-9999px",c.style.top="-9999px",c.src=x.toString();let F=false,v=()=>{window.removeEventListener("message",B),clearTimeout(V);try{c.remove();}catch{}d.current=null;},B=W=>{if(W.origin===_){if(W.data?.type==="botbuddy-widget-auth-failed"){if(F)return;F=true,r(null),v();return}W.data?.type!=="botbuddy-widget-auth"||!W.data.token||F||(F=true,r(String(W.data.token)),v());}},V=setTimeout(()=>{F||(F=true,r(null),v());},xn);window.addEventListener("message",B),document.body.appendChild(c);});return d.current=b,b},[e]);useEffect(()=>{if(!t)return;let _=Le(t);if(!_)return;let x=_-Date.now()-vn,b=window.setTimeout(()=>{w();},Math.max(0,x));return ()=>window.clearTimeout(b)},[t,w]);let C=useCallback(()=>{let _=new URL("/widget-auth",e);_.searchParams.set("origin",window.location.origin);let x=420,b=520,r=window.screenX+(window.innerWidth-x)/2,c=window.screenY+(window.innerHeight-b)/2;window.open(_.toString(),"botbuddy-auth",`width=${x},height=${b},left=${r},top=${c},popup=yes`);},[e]),[,h]=useState(0);useEffect(()=>{let _=Le(t);if(!_)return;let x=_-Date.now();if(x<=0)return;let b=window.setTimeout(()=>h(r=>r+1),x);return ()=>window.clearTimeout(b)},[t]);let f=useCallback(()=>{s(null),i(null);try{localStorage.removeItem(at),localStorage.removeItem(lt);}catch(_){console.warn("Unable to clear BotBuddy widget auth token",_);}},[]),L=Le(t),j=L!==null&&L<=Date.now();return {token:t,displayName:l,isAuthenticated:!!t,isExpired:j,openLogin:C,refreshNow:w,logout:f}}var He=null;function wn(){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 Ke(){return He||(He=(async()=>{if(typeof fetch>"u")return null;try{let e=await fetch(wn(),{cache:"no-store"});if(!e.ok)return null;let t=await e.json();if(!t||typeof t!="object"||Array.isArray(t))return null;let s={};for(let[l,i]of Object.entries(t))typeof i=="string"&&i.length>0&&(s[l]=i);return s}catch{return null}})(),He)}async function It(e){return (await Ke())?.[e]??null}function kn(e){let t=e.replace(/=+$/,"").replace(/\s+/g,"").toUpperCase(),s="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",l=[],i=0,d=0;for(let T of t){let w=s.indexOf(T);if(w<0)throw new Error("Invalid Base32 character in TOTP secret");d=d<<5|w,i+=5,i>=8&&(i-=8,l.push(d>>>i&255));}return Uint8Array.from(l)}async function Ft(e,t=Date.now()){if(typeof crypto>"u"||!crypto.subtle)throw new Error("Web Crypto unavailable");let s=kn(e),l=new Uint8Array(s.byteLength);l.set(s);let i=Math.floor(t/1e3/30),d=new Uint8Array(8),T=Math.floor(i/4294967296),w=i>>>0;d[0]=T>>>24&255,d[1]=T>>>16&255,d[2]=T>>>8&255,d[3]=T&255,d[4]=w>>>24&255,d[5]=w>>>16&255,d[6]=w>>>8&255,d[7]=w&255;let C=await crypto.subtle.importKey("raw",l,{name:"HMAC",hash:"SHA-1"},false,["sign"]),h=await crypto.subtle.sign("HMAC",C,d),f=new Uint8Array(h),L=f[f.length-1]&15;return (((f[L]&127)<<24|(f[L+1]&255)<<16|(f[L+2]&255)<<8|f[L+3]&255)%1e6).toString().padStart(6,"0")}var Wt="0.11.0";function _n(e){let t=new Date(e),l=Date.now()-t.getTime();if(l<6e4)return "just now";if(l<36e5)return `${Math.floor(l/6e4)}m ago`;if(l<864e5)return `${Math.floor(l/36e5)}h ago`;let i=t.getDate(),d=t.toLocaleString("en",{month:"short"}),T=t.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${d} ${i}, ${T}`}var R=({d:e,className:t,size:s=14})=>jsx("svg",{className:t,width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:e})}),y={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01",bot:"M12 8V4H8M2 14h2M20 14h2M15 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M9 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M18 10a6 6 0 0 0-12 0v4a6 6 0 0 0 12 0Z",terminal:"M4 17l6-6-6-6M12 19h8",key:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4",shield:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10",copy:"M20 9h-9a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2-2v-9a2 2 0 0 0-2-2ZM5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1",search:"M11 17.25a6.25 6.25 0 1 1 0-12.5 6.25 6.25 0 0 1 0 12.5ZM16 16l4.5 4.5"};function Rn(){let[e,t]=useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return useEffect(()=>{if(typeof window>"u")return;let s=document.documentElement,l=()=>s.classList.contains("dark")?"dark":s.classList.contains("light")?"light":null,i=l();i&&t(i);let d=window.matchMedia("(prefers-color-scheme: dark)"),T=C=>{let h=l();t(h||(C.matches?"dark":"light"));};d.addEventListener("change",T);let w=new MutationObserver(()=>{let C=l();t(C||(d.matches?"dark":"light"));});return w.observe(s,{attributes:true,attributeFilter:["class"]}),()=>{d.removeEventListener("change",T),w.disconnect();}},[]),e}function Tn(e){let t=e==="dark";return {bg:t?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:t?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:t?"#e5e5e5":"#1a1a1a",textMuted:t?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:t?"#555":"#999",border:t?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:t?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:t?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:t?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:t?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:t?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:t?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:t?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:t?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:t?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:t?"#888":"#aaa",btnHover:t?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var Cn={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},Mn={pending:y.circle,pass:y.check,fail:y.x,skip:y.skip},Dt={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 En(e,t=[]){if(!e)return false;let s=e.toLowerCase();return [...Nn,...t].map(i=>i.toLowerCase()).includes(s)}var $n=e=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:t=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:e.bg,border:t?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:t?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(t,s)=>({width:`${t}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:t=>{let s=Dt[t]||Dt.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:t=>({height:"100%",width:`${t}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:t=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${t}15`,color:t,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(t,s)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:t?`${s}33`:"transparent",color:t?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 ct(e){return e.split("/")[0].trim()}async function Pn(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 t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.opacity="0",t.style.pointerEvents="none",document.body.appendChild(t),t.focus(),t.select(),t.setSelectionRange(0,e.length);let s=document.execCommand("copy");return document.body.removeChild(t),s}catch{return false}}function Be({config:e,appSlug:t,environment:s,seededUsers:l,authToken:i,tk:d,compact:T=false,onExpand:w,onAuthExpired:C,refreshAuth:h,requestLogin:f,testRunId:L,testRunToken:j,ticketId:_,targetUrl:x,version:b,commitSha:r,prNumber:c,branchName:F}){let[v,B]=useState(false),[V,W]=useState(null),[A,pe]=useState(null),[S,a]=useState(null),[ae,Y]=useState(null),[ee,Q]=useState(null),[ne,ge]=useState(null);useEffect(()=>{s==="local"&&Ke();},[s]);let ke=useCallback(p=>{W(p),a(null),Y(null),ge(null);let z=Le(i);if(s!=="local"&&f&&z!==null&&z<=Date.now()){Q({slug:p,token:i||null}),ge(p),W(null),f();return}let E=N=>{a(N),Y(p),window.setTimeout(()=>{Y($=>$===p?null:$),a($=>$===N?null:$);},3e3);},M=new URLSearchParams({app_slug:t,seed_user_slug:p,environment:s});L&&M.set("test_run_id",L),j&&M.set("public_token",j),_&&M.set("ticket_id",_),x&&M.set("target_url",x),b&&M.set("version",b),r&&M.set("commit_sha",r),c&&M.set("pr_number",String(c)),F&&M.set("branch_name",F);let U=async N=>{let $={apikey:e.anonKey,Authorization:`Bearer ${N}`};try{let D=await fetch(`${e.serverUrl}/widget/totp-code?${M}`,{headers:$});if(!D.ok){let xe=await D.json().catch(()=>({error:`HTTP ${D.status}`}));return {ok:!1,status:D.status,error:xe.error||`HTTP ${D.status}`}}let te=await D.json();return {ok:!0,code:String(te.code)}}catch{return {ok:false,status:0,error:"Network error"}}},J=(async()=>{if(s==="local"){let D=await It(p);if(D)try{return {ok:!0,code:await Ft(D)}}catch{}}let N=await U(i||e.anonKey);if(N.ok||N.status!==401||!h)return N;let $=await h();return $?U($):{ok:false,status:401,error:"Sign in to BotBuddy to refresh 2FA"}})(),H=null;try{if(typeof ClipboardItem<"u"&&navigator.clipboard?.write){let N=J.then($=>{if(!$.ok)throw new Error($.error);return new Blob([$.code],{type:"text/plain"})});H=navigator.clipboard.write([new ClipboardItem({"text/plain":N})]).then(()=>!0).catch(()=>!1);}}catch{}(async()=>{let N=await J;if(!N.ok){N.status===401?(Q({slug:p,token:i||null}),ge(p)):E(N.status===404?"No 2FA seed registered":N.error),W(null);return}let $=H?await H:false,D=$?true:await Pn(N.code),te=$||D;pe({slug:p,code:N.code,copied:te}),window.setTimeout(()=>pe(xe=>xe?.slug===p?null:xe),te?2500:6e3),B(false),W(null);})();},[e.serverUrl,e.anonKey,i,t,s,L,j,_,x,b,r,c,F,h,f]),de=useCallback(p=>{Q({slug:p,token:i||null}),f?.();},[i,f]),Se=useCallback(p=>{ne===p?de(p):ke(p);},[ne,de,ke]);useEffect(()=>{if(!ee||!i||i===ee.token)return;let p=ee.slug;Q(null),ke(p);},[i,ke,ee]);let _e=useRef(null),Ee=useRef(null);if(useLayoutEffect(()=>{if(!v)return;let p=_e.current,z=Ee.current;if(!p||!z||typeof window>"u")return;let E=()=>{let M=p.getBoundingClientRect(),U=z.getBoundingClientRect(),J=window.innerWidth,H=window.innerHeight,N=M.left,$=M.top-U.height-6;$<8&&($=M.bottom+6);let D=Math.max(8,J-U.width-8),te=Math.max(8,H-U.height-8);N=Math.min(Math.max(N,8),D),$=Math.min(Math.max($,8),te),z.style.left=`${Math.round(N)}px`,z.style.top=`${Math.round($)}px`;};return E(),window.addEventListener("scroll",E,true),window.addEventListener("resize",E),()=>{window.removeEventListener("scroll",E,true),window.removeEventListener("resize",E);}},[v,l.length,S]),useEffect(()=>{if(!v)return;let p=z=>{let E=z.target;Ee.current?.contains(E)||_e.current?.contains(E)||B(false);};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[v]),l.length===0)return null;if(T){let p=l.length>1,z=l[0],E=!p&&ne===z,M=D=>{if(D.stopPropagation(),p&&w){w();return}Se(z);},U=!!ae,J=!!A,H=J&&A.copied,N=J&&!A.copied,$=E?d.blue:U?d.red:H?d.green:N?d.amber:d.purple;return jsxs("span",{onPointerDown:D=>D.stopPropagation(),onPointerUp:D=>D.stopPropagation(),onPointerMove:D=>D.stopPropagation(),onClick:M,style:{display:"inline-flex",alignItems:"center",gap:"3px",color:$,fontWeight:600,cursor:"pointer",letterSpacing:N?"0.08em":void 0},title:E?"Sign in to BotBuddy to refresh 2FA":U?S||"Failed":N?`Clipboard blocked \u2014 code: ${A.code}`:p?`${l.length} 2FA personas`:`Copy 2FA code for ${l[0]}`,children:[jsx(R,{d:E?y.key:U?y.alert:H?y.check:N?y.copy:y.shield,size:10}),E?jsx(Fragment,{children:"Sign in"}):H?jsx(Fragment,{children:"Copied"}):N?jsx(Fragment,{children:A.code}):U?jsx(Fragment,{children:"Failed"}):jsxs(Fragment,{children:["2FA",p&&` \xB7${l.length}`]})]})}if(l.length===1){let p=l[0],z=V===p,E=A?.slug===p,M=E&&A.copied,U=E&&!A.copied,J=ae===p,H=ne===p,N=H?d.blue:J?d.red:M?d.green:U?d.amber:d.purple;return jsxs("button",{onClick:$=>{$.stopPropagation(),Se(p);},disabled:z,style:{...Ot(N),cursor:z?"wait":"pointer",opacity:z?.6:1},title:H?"Sign in to BotBuddy to refresh 2FA":J?S||"Failed":U?`Clipboard blocked \u2014 code: ${A.code}`:`Copy 2FA code for ${p}`,children:[jsx(R,{d:H?y.key:J?y.alert:M?y.check:U?y.copy:y.shield,size:12}),H?"Sign in":M?"Copied":U?A.code:J?"Failed":z?"\u2026":`2FA \xB7 ${p}`]})}let fe=!!ne&&!v,oe=!!ae&&!v,Re=!!A&&A.copied,Te=!!A&&!A.copied,Ye=fe?d.blue:oe?d.red:Re?d.green:Te?d.amber:d.purple,qe=v&&typeof document<"u"?createPortal(jsxs("div",{ref:Ee,onPointerDown:p=>p.stopPropagation(),onMouseDown:p=>p.stopPropagation(),style:{position:"fixed",left:-9999,top:-9999,background:d.bg,border:`1px solid ${d.border}`,borderRadius:6,boxShadow:`0 8px 24px ${d.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:[l.map(p=>{let z=V===p,E=ne===p;return jsxs("button",{onClick:M=>{M.stopPropagation(),Se(p);},disabled:z,style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 8px",background:"transparent",border:"none",borderRadius:4,cursor:z?"wait":"pointer",fontSize:"10px",color:E?d.blue:d.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},title:E?"Sign in to BotBuddy to refresh 2FA":void 0,onMouseEnter:M=>M.currentTarget.style.background=d.btnHover,onMouseLeave:M=>M.currentTarget.style.background="transparent",children:[jsx(R,{d:E?y.key:y.shield,size:10}),jsx("span",{style:{flex:1,overflowWrap:"anywhere",lineHeight:1.3},children:p}),E?jsx("span",{style:{color:d.blue,fontSize:9},children:"Sign in"}):z?jsx("span",{style:{color:d.textMuted,fontSize:9},children:"\u2026"}):null]},p)}),S&&jsx("div",{style:{padding:"4px 8px",fontSize:9,color:d.red},children:S})]}),document.body):null;return jsxs(Fragment,{children:[jsxs("button",{ref:_e,onClick:p=>{if(p.stopPropagation(),fe&&ne){de(ne);return}B(z=>!z),a(null),Y(null);},style:{...Ot(Ye),cursor:"pointer"},title:fe?"Sign in to BotBuddy to refresh 2FA":oe?S||"Failed":Te?`Clipboard blocked \u2014 code: ${A.code}`:"Choose a persona to copy a 2FA code for",children:[jsx(R,{d:fe?y.key:oe?y.alert:Re?y.check:Te?y.copy:y.shield,size:12}),fe?"Sign in":Re?"Copied":Te?A.code:oe?"Failed":`2FA \xB7 ${l.length}`,!fe&&jsx(R,{d:v?y.chevronUp:y.chevronDown,size:8})]}),qe]})}function Ot(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 Ht="botbuddy-widget-state";function Ln({config:e,appSlug:t,environment:s,ticketId:l,testRunId:i,testRunToken:d,targetUrl:T,version:w,commitSha:C,prNumber:h,branchName:f,onNavigate:L,displayName:j="human",defaultMode:_="mini",defaultPosition:x}){let b=Rn(),r=useMemo(()=>Tn(b),[b]),c=useMemo(()=>$n(r),[r]),[F,v]=useState(false),[B,V]=useState(false),[W,A]=useState(false),pe=useRef(false),S=e.dashboardUrl||"https://app.bot-buddy.ai",a=dt(S),Y=(()=>{try{let n=typeof window<"u"?localStorage.getItem(Ht):null;if(n)return JSON.parse(n)}catch{}return null})(),[ee,Q]=useState(Y?.mode||_),[ne,ge]=useState(""),[ke,de]=useState(null),[Se,_e]=useState(null),[Ee,fe]=useState(new Set),[oe,Re]=useState(""),Te=useCallback(n=>{fe(g=>{let k=new Set(g);return k.has(n)?k.delete(n):k.add(n),k});},[]),Ye=Y?.x??x?.x??16,qe=Y?.y??x?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:p,setPos:z,onPointerDown:E,onPointerMove:M,onPointerUp:U,didDrag:J}=tt(Ye,qe),H=useRef(null);useEffect(()=>{try{localStorage.setItem(Ht,JSON.stringify({mode:ee,x:p.x,y:p.y}));}catch{}},[ee,p.x,p.y]),useLayoutEffect(()=>{if(typeof window>"u")return;let n=H.current;if(!n)return;let g=n.getBoundingClientRect(),k=et(p.x,p.y,g.width,g.height,window.innerWidth,window.innerHeight);(k.x!==p.x||k.y!==p.y)&&z(k);}),useEffect(()=>{if(typeof window>"u")return;let n=()=>{let g=H.current;if(!g)return;let k=g.getBoundingClientRect(),K=et(p.x,p.y,k.width,k.height,window.innerWidth,window.innerHeight);(K.x!==p.x||K.y!==p.y)&&z(K);};return window.addEventListener("resize",n),()=>window.removeEventListener("resize",n)},[p.x,p.y,z]);let N=useRef(a.isAuthenticated);useEffect(()=>{!N.current&&a.isAuthenticated&&Q("max"),N.current=a.isAuthenticated;},[a.isAuthenticated]);let $="botbuddy-widget-max-size",D=()=>{try{let n=localStorage.getItem($);if(n)return JSON.parse(n)}catch{}return {w:340,h:500}},[te,xe]=useState(D),$e=useRef(false),Pe=useRef({x:0,y:0,w:0,h:0}),Qt=useCallback(n=>{n.stopPropagation(),$e.current=true,Pe.current={x:n.clientX,y:n.clientY,w:te.w,h:te.h},n.target.setPointerCapture(n.pointerId);},[te]),en=useCallback(n=>{if(!$e.current)return;let g=Math.max(280,Math.min(600,Pe.current.w+(n.clientX-Pe.current.x))),k=Math.max(300,Math.min(window.innerHeight*.9,Pe.current.h+(n.clientY-Pe.current.y)));xe({w:g,h:k});},[]),tn=useCallback(()=>{$e.current&&($e.current=false,xe(n=>(localStorage.setItem($,JSON.stringify(n)),n)));},[]),se=T??(typeof window<"u"?window.location.href:void 0),mt=a.displayName||j,[ce,yt]=useState(null);useEffect(()=>{if(a.isAuthenticated)return;let n=new URLSearchParams;d&&n.set("token",d),l&&n.set("ticket_id",l),n.set("app_slug",t),s&&n.set("environment",s),i&&n.set("test_run_id",i),se&&n.set("target_url",se),w&&n.set("version",w),C&&n.set("commit_sha",C),h&&n.set("pr_number",String(h)),f&&n.set("branch_name",f),fetch(`${e.serverUrl}/widget/preview?${n}`,{headers:{apikey:e.anonKey}}).then(g=>g.json()).then(g=>yt(g)).catch(()=>yt(null));},[a.isAuthenticated,e.serverUrl,e.anonKey,t,s,l,i,d,se,w,C,h,f]);let ht=useRef(false),nn=useCallback(()=>{ht.current||a.logout();},[a.logout]),{run:m,widgetState:ve,fetchRun:rn,setVerdict:xt,markComplete:on,resetRun:sn,setRun:vt}=ot({config:e,appSlug:t,environment:s,ticketId:l,testRunId:i,testRunToken:d,targetUrl:se,version:w,commitSha:C,prNumber:h?String(h):void 0,branchName:f,authToken:a.token,onAuthExpired:nn});ht.current=!!m;let[wt,kt]=useState([]),[St,Ue]=useState([]),[Je,_t]=useState(false),[Rt,Tt]=useState(null),[an,Ie]=useState(false),be=En(typeof window<"u"?window.location.hostname:void 0,e.productionHostnames||[]);useEffect(()=>{if((s??"local")!=="local"||be){kt([]);return}let n=true;return Ke().then(g=>{n&&kt(Object.keys(g||{}));}),()=>{n=false;}},[s,be]);let ln=useCallback(async()=>{if(!(!a.isAuthenticated||!a.token)){_t(true),Tt(null);try{let n=await fetch(`${e.serverUrl}/widget/test-runs`,{method:"POST",headers:{"Content-Type":"application/json",apikey:e.anonKey,Authorization:`Bearer ${a.token}`},body:JSON.stringify({app_slug:t,environment:s||"local",target_url:se,branch_name:f,commit_sha:C,pr_number:h,ticket_id:l,title:`${l||t} local validation`})}),g=await n.json().catch(()=>({}));if(!n.ok)throw new Error(g.error||`HTTP ${n.status}`);vt(g),Q("max");}catch(n){Tt(n.message);}finally{_t(false);}}},[a.isAuthenticated,a.token,e.serverUrl,e.anonKey,t,s,se,f,C,h,l,vt]),Fe=useCallback(async(n,g,k)=>{_e(n);try{await xt(n,g,k,mt);}finally{_e(null),de(null),ge("");}},[xt,mt]),q=m?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},dn=q.total>0&&q.pending===0,Ce=ve==="completed",We=useMemo(()=>{let n=m?.test_cases||[];if(!oe.trim())return n;let g=oe.toLowerCase();return n.filter(k=>k.title.toLowerCase().includes(g)||k.description&&k.description.toLowerCase().includes(g)||k.url_path&&k.url_path.toLowerCase().includes(g)||k.seed_user&&k.seed_user.toLowerCase().includes(g))},[m?.test_cases,oe]),Ct=useMemo(()=>{let n=We,g=m?.test_cases||[];if(new Set(g.map(Z=>Z.source_pr_number)).size<=1)return null;let K=[],ye=new Map;n.forEach(Z=>{let X=Z.source_pr_number;ye.has(X)||ye.set(X,[]),ye.get(X).push(Z);});let zt=[...ye.keys()].sort((Z,X)=>Z===null?1:X===null?-1:X-Z);for(let Z of zt){let X=ye.get(Z),Xe={total:X.length,pass:0,fail:0,skip:0,pending:0};X.forEach(At=>{At.verdict in Xe&&Xe[At.verdict]++;}),K.push({key:Z!=null?`pr-${Z}`:"general",label:Z!=null?`PR #${Z}`:"General",cases:X,summary:Xe});}return K.filter(Z=>Z.cases.length>0)},[We,m?.test_cases]),Mt=q.total>0?(q.pass+q.fail)/q.total*100:0,G=s??m?.environment??null,me=useMemo(()=>{if(!G||G==="production"||be)return [];let n=m?.test_cases||[],g=new Set;for(let k of n)k.seed_user&&g.add(ct(k.seed_user));if(G==="local")for(let k of wt)g.add(ct(k));for(let k of St)g.add(ct(k));return [...g]},[m?.test_cases,G,wt,St,be]);useEffect(()=>{if(!G||G==="production"||be||!a.isAuthenticated||!a.token){Ue([]);return}let n=true,g=`${e.serverUrl}/widget/totp-seeds?${new URLSearchParams({app_slug:t,environment:G})}`,k=K=>fetch(g,{headers:{apikey:e.anonKey,Authorization:`Bearer ${K}`}});return (async()=>{try{let K=await k(a.token);if(K.status===401&&a.refreshNow){let X=await a.refreshNow();X&&(K=await k(X));}if(!n)return;if(!K.ok){Ue([]);return}let ye=await K.json().catch(()=>null),Z=(Array.isArray(ye?.seeds)?ye.seeds:[]).map(X=>X?.seed_user_slug).filter(X=>typeof X=="string"&&X.length>0);Ue(Z);}catch{n&&Ue([]);}})(),()=>{n=false;}},[G,be,a.isAuthenticated,a.token,a.refreshNow,t,e.serverUrl,e.anonKey]);let Ge=useMemo(()=>{let n=m?.auto_tooltip_seconds??ce?.auto_tooltip_seconds;return n!=null&&n>0?n*1e3:0},[m,ce]),Nt=ve==="ready"||ve==="completed"||ce?.enabled&&ce.run;useEffect(()=>{if(!Nt||pe.current||Ge<=0)return;pe.current=true,V(true);let n=window.setTimeout(()=>V(false),Ge);return ()=>window.clearTimeout(n)},[Nt,Ge]);let Et=n=>jsxs("div",{style:c.caseRow,children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsx("div",{style:{marginTop:"2px",flexShrink:0,color:Cn[n.verdict]},children:Se===n.id?jsx(R,{d:y.loader,className:""}):jsx(R,{d:Mn[n.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:r.text,lineHeight:1.3},children:n.title}),n.description&&jsx("div",{style:{fontSize:"9px",color:r.gripColor,marginTop:"2px"},children:n.description}),n.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(R,{d:y.key,size:10}),jsx("span",{children:n.seed_user})]}),n.url_path&&jsxs("a",{href:n.url_path,target:"_blank",rel:"noopener noreferrer",onClick:g=>{g.stopPropagation(),L&&(g.preventDefault(),L(n.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(R,{d:y.externalLink,size:10}),n.url_path]}),n.verdict==="fail"&&n.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:r.red,marginTop:"2px"},children:["\u2717 ",n.fail_reason]})]})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(g=>jsx("button",{onClick:()=>{if(n.verdict===g){Fe(n.id,"pending"),de(null);return}if(g==="fail"){de(n.id),ge("");return}de(null),Fe(n.id,g);},disabled:Se!==null,style:c.verdictBtn(n.verdict===g,g==="pass"?r.green:g==="fail"?r.red:r.amber),children:g.toUpperCase()},g)),n.created_by_agent_name&&jsxs("span",{style:{fontSize:"8px",color:r.purple,marginLeft:"4px",display:"inline-flex",alignItems:"center",gap:"2px"},children:[jsx(R,{d:y.bot,size:8}),n.created_by_agent_name]}),n.verdict_by_display_name&&jsxs("span",{style:{fontSize:"8px",color:r.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[n.verdict_by_display_name,n.verdict_at&&jsx("span",{style:{opacity:.7},children:_n(n.verdict_at)})]})]}),ke===n.id&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:ne,onChange:g=>ge(g.target.value),onKeyDown:g=>{g.key==="Enter"&&Fe(n.id,"fail",ne.trim()||void 0),g.key==="Escape"&&(de(null),ge(""));},placeholder:"Reason (optional)...",style:c.input}),jsx("button",{onClick:()=>{Fe(n.id,"fail",ne.trim()||void 0);},style:c.verdictBtn(true,r.red),children:"\u2713"})]})]},n.id);if((ve==="no-match"||ve==="loading")&&!(!a.isAuthenticated&&ce?.enabled&&ce.run)){if(!(G==="local"&&!be))return null}if(!a.isAuthenticated&&ce?.enabled&&ce.run){let n=ce.run,g=n.summary,k=n.status==="completed";return jsx("div",{ref:H,style:{...c.root,left:p.x,top:p.y},children:jsxs("div",{style:{position:"relative"},onMouseEnter:()=>v(true),onMouseLeave:()=>{v(false),A(false),V(false);},children:[jsxs("div",{style:{...c.pill(k),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:E,onPointerMove:M,onPointerUp:()=>{U();},children:[jsx(R,{d:y.grip,size:10,className:""}),n.ticket_id&&n.ticket_url?jsx("a",{href:n.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:n.ticket_id}):null,n.pr_url?jsxs("a",{href:n.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#",n.pr_number??n.pr_id]}):null,n.created_by_agent_name?n.codex_thread_id?jsxs("a",{href:`codex://threads/${n.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(R,{d:y.terminal,size:10}),n.created_by_agent_name]}):jsxs("span",{style:{color:r.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(R,{d:y.bot,size:10}),n.created_by_agent_name]}):null,jsxs("span",{style:k?{color:r.green}:void 0,children:[g.pass,"/",g.total]}),g.fail>0&&jsxs("span",{style:{color:r.red},children:[g.fail,"\u2717"]}),jsx("span",{onClick:K=>{K.stopPropagation(),a.openLogin();},style:{color:r.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!W&&(F||B)&&n.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:n.title}),(n.description||n.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:n.description||n.intro_notes}),jsx("div",{style:{marginTop:"4px",fontSize:"9px",color:r.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!a.isAuthenticated)return jsxs("div",{ref:H,style:{...c.root,left:p.x,top:p.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:E,onPointerMove:M,onPointerUp:U,children:[jsx("div",{style:{...c.handle,borderBottom:"none"},children:jsxs("div",{style:c.sub,children:[jsx(R,{d:y.grip,size:10,className:""}),jsx(R,{d:y.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"}),G==="local"&&me.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx(Be,{config:e,appSlug:t,environment:G,seededUsers:me,authToken:a.token,refreshAuth:a.refreshNow,requestLogin:a.openLogin,tk:r,testRunId:m?.id||i,testRunToken:d,ticketId:l,targetUrl:se,version:w,commitSha:C,prNumber:h,branchName:f,onAuthExpired:a.logout})}),jsx("button",{onClick:n=>{n.stopPropagation(),a.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(!m&&G==="local"&&!be)return an?jsx("div",{ref:H,style:{...c.root,left:p.x,top:p.y},children:jsxs("div",{style:c.card(240,false),children:[jsxs("div",{style:c.handle,onPointerDown:E,onPointerMove:M,onPointerUp:U,onClick:()=>{J.current||Ie(false);},children:[jsx(R,{d:y.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:c.title,children:"BotBuddy"}),f&&jsx("div",{style:c.sub,children:jsxs("span",{children:["\u2387 ",f]})})]}),jsx(R,{d:y.chevronUp,className:""}),jsx("button",{style:c.btn,onClick:n=>{n.stopPropagation(),Ie(false);},children:jsx(R,{d:y.minus,className:""})})]}),jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[me.length>0&&jsx("div",{style:{display:"flex",justifyContent:"center",marginBottom:"8px"},children:jsx(Be,{config:e,appSlug:t,environment:G,seededUsers:me,authToken:a.token,refreshAuth:a.refreshNow,requestLogin:a.openLogin,tk:r,testRunId:i,testRunToken:d,ticketId:l,targetUrl:se,version:w,commitSha:C,prNumber:h,branchName:f,onAuthExpired:a.logout})}),jsx("button",{onClick:n=>{n.stopPropagation(),ln();},disabled:Je,style:{fontSize:"10px",fontWeight:600,padding:"6px 12px",borderRadius:"6px",border:`1px solid ${r.green}`,background:`${r.green}22`,color:r.green,cursor:Je?"wait":"pointer",width:"100%"},children:Je?"Creating...":"Create test run for this branch"}),Rt&&jsx("div",{style:{fontSize:"9px",color:r.red,marginTop:"8px"},children:Rt})]})]})}):jsx("div",{ref:H,style:{...c.root,left:p.x,top:p.y},children:jsxs("div",{style:{...c.pill(false),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:E,onPointerMove:M,onPointerUp:()=>{U(),J.current||Ie(true);},children:[jsx(R,{d:y.grip,size:9,className:""}),jsx("span",{style:{fontWeight:600},children:"BotBuddy"}),me.length>0&&jsx(Be,{config:e,appSlug:t,environment:G,seededUsers:me,authToken:a.token,refreshAuth:a.refreshNow,requestLogin:a.openLogin,tk:r,compact:true,onExpand:()=>Ie(true),testRunId:i,testRunToken:d,ticketId:l,targetUrl:se,version:w,commitSha:C,prNumber:h,branchName:f,onAuthExpired:a.logout})]})});let $t=()=>{J.current||(V(false),Q(n=>{let g=n==="mini"?"max":"mini";return A(g==="mini"),g}));},Pt=({icon:n,onClick:g})=>jsx("button",{style:c.btn,onClick:k=>{k.stopPropagation(),g(k);},children:jsx(R,{d:n,className:""})}),Lt=()=>jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${r.borderSubtle}`,flexShrink:0},children:[m?.pr_url&&jsxs("a",{href:m.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...c.link(r.blue),textDecoration:"none"},children:[jsx(R,{d:y.pr,size:12}),m.pr_number?`PR#${m.pr_number}`:m.pr_id||"PR",jsx(R,{d:y.externalLink,size:8})]}),m?.ticket_url&&jsxs("a",{href:m.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...c.link(r.amber),textDecoration:"none"},children:[jsx(R,{d:y.ticket,size:12}),m.ticket_id||"Ticket",jsx(R,{d:y.externalLink,size:8})]}),m?.created_by_agent_name&&(m.codex_thread_id?jsxs("a",{href:`codex://threads/${m.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...c.link(r.purple),textDecoration:"none"},children:[jsx(R,{d:y.bot,size:12}),m.created_by_agent_name,jsx(R,{d:y.externalLink,size:8})]}):jsxs("span",{style:{...c.link(r.purple)},children:[jsx(R,{d:y.bot,size:12}),m.created_by_agent_name]})),G&&jsx(Be,{config:e,appSlug:t,environment:G,seededUsers:me,authToken:a.token,refreshAuth:a.refreshNow,requestLogin:a.openLogin,tk:r,testRunId:m?.id||i,testRunToken:d,ticketId:l,targetUrl:se,version:w,commitSha:C,prNumber:h,branchName:f,onAuthExpired:a.logout}),jsx("span",{style:{...c.badge(m?.environment||"custom"),marginLeft:"auto"},children:m?.environment})]}),Bt=()=>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(Wt);},style:{fontSize:"9px",fontWeight:600,color:r.versionText,letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxs("span",{style:{color:r.versionNum},children:["v",Wt]})]}),a.isAuthenticated&&(a.isExpired?jsx("button",{onClick:n=>{n.stopPropagation(),a.openLogin();},style:{fontSize:"8px",color:r.blue,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Widget session expired \u2014 sign in to refresh",children:"sign in"}):jsx("button",{onClick:n=>{n.stopPropagation(),a.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:H,style:{...c.root,left:p.x,top:p.y},children:[ee==="mini"&&jsxs("div",{style:{position:"relative"},onMouseEnter:()=>v(true),onMouseLeave:()=>{v(false),A(false),V(false);},children:[jsxs("div",{style:{...c.pill(Ce),gap:"6px",padding:"3px 8px",fontSize:"9px"},onPointerDown:E,onPointerMove:M,onPointerUp:()=>{U(),J.current||$t();},children:[jsx(R,{d:y.grip,size:9,className:""}),m?.ticket_id&&jsx("span",{style:{color:r.amber,fontWeight:600},children:m.ticket_id}),m?.pr_number&&jsxs("span",{style:{color:r.blue,fontWeight:600},children:["PR#",m.pr_number]}),jsxs("span",{style:Ce?{color:r.green}:void 0,children:[q.pass,"/",q.total]}),q.fail>0&&jsxs("span",{style:{color:r.red},children:[q.fail,"\u2717"]}),G&&jsx(Be,{config:e,appSlug:t,environment:G,seededUsers:me,authToken:a.token,refreshAuth:a.refreshNow,requestLogin:a.openLogin,tk:r,compact:true,onExpand:()=>Q("expanded"),testRunId:m?.id||i,testRunToken:d,ticketId:l,targetUrl:se,version:w,commitSha:C,prNumber:h,branchName:f,onAuthExpired:a.logout})]}),!W&&(F||B)&&m?.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:m.title}),(m.description||m.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:m.description||m.intro_notes})]})]}),ee==="expanded"&&jsxs("div",{style:c.card(300,Ce),children:[jsxs("div",{style:c.handle,onPointerDown:E,onPointerMove:M,onPointerUp:U,onClick:$t,children:[jsx(R,{d:y.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:c.title,children:m?.title}),jsx("div",{style:c.sub,children:m?.branch_name&&jsxs("span",{children:["\u2387 ",m.branch_name]})})]}),jsx(R,{d:y.chevronUp,className:""}),jsx(Pt,{icon:y.minus,onClick:()=>{V(false),A(true),Q("mini");}})]}),jsxs("div",{style:c.stats,children:[jsxs("span",{style:{color:r.green},children:[q.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[q.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[q.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[q.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:q.total})]}),m?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:r.gripColor,borderBottom:`1px solid ${r.borderSubtle}`,flexShrink:0},children:m.description}),Lt(),Bt(),jsx("div",{style:c.progress,children:jsx("div",{style:c.progressBar(Mt)})})]}),ee==="max"&&jsxs("div",{style:{...c.card(te.w,Ce),height:te.h,position:"relative"},children:[jsxs("div",{style:c.handle,onPointerDown:E,onPointerMove:M,onPointerUp:U,onClick:()=>{J.current||Q("expanded");},children:[jsx(R,{d:y.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:c.title,children:m?.title}),jsx("div",{style:c.sub,children:m?.branch_name&&jsxs("span",{children:["\u2387 ",m.branch_name]})})]}),jsx(R,{d:y.chevronDown,className:""}),jsx(Pt,{icon:y.minus,onClick:()=>{V(false),A(true),Q("mini");}})]}),jsxs("div",{style:c.stats,children:[jsxs("span",{style:{color:r.green},children:[q.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[q.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[q.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[q.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:q.total})]}),m?.intro_notes&&jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${r.borderSubtle}`,fontSize:"10px",color:r.textMuted,fontStyle:"italic",flexShrink:0},children:m.intro_notes}),(m?.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(R,{d:y.search,size:11,className:""}),jsx("input",{value:oe,onChange:n=>Re(n.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:r.text,fontFamily:"monospace"}}),oe&&jsx("button",{onClick:()=>Re(""),style:{background:"none",border:"none",cursor:"pointer",color:r.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),ve==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(R,{d:y.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:r.red},children:"Failed to load"}),jsx("button",{onClick:rn,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),Ce&&jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg},children:[jsx(R,{d:y.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:r.green,flex:1},children:"Run completed"}),jsx("button",{onClick:sn,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),ve!=="error"&&jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(m?.test_cases||[]).length===0?jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:"No test cases"}):We.length===0?jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:['No matches for "',oe,'"']}):Ct?Ct.map(n=>{let g=Ee.has(n.key);return jsxs("div",{children:[jsxs("button",{onClick:()=>Te(n.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(R,{d:g?y.chevronDown:y.chevronUp,size:10,className:""}),jsx("span",{style:{fontSize:"10px",fontWeight:700,color:r.blue,flex:1,textAlign:"left"},children:n.label}),jsxs("span",{style:{fontSize:"9px",color:r.green},children:[n.summary.pass,"\u2713"]}),jsxs("span",{style:{fontSize:"9px",color:r.red},children:[n.summary.fail,"\u2717"]}),jsxs("span",{style:{fontSize:"9px",color:r.gripColor},children:[n.summary.pending,"\u25CC"]}),jsx("span",{style:{fontSize:"9px",color:r.textFaint},children:n.summary.total})]}),!g&&n.cases.map(k=>Et(k))]},n.key)}):We.map(n=>Et(n))}),dn&&!Ce&&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:on,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"})]}),Lt(),Bt(),jsx("div",{style:c.progress,children:jsx("div",{style:c.progressBar(Mt)})}),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:Qt,onPointerMove:en,onPointerUp:tn,onPointerEnter:n=>n.currentTarget.style.opacity="0.7",onPointerLeave:n=>{$e.current||(n.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"})})})]})]})}var Un=1e4,ze=new Map;var je=class extends Error{};async function In(e,t,s){let l={headers:{authorization:`Bearer ${t}`}};try{return await fetch(e,{...l,signal:s})}catch(i){if(i instanceof TypeError&&/signal/i.test(i.message)&&!s.aborted)return fetch(e,l);throw i}}function Fn(e){let t=e;return !!t&&typeof t=="object"&&typeof t.tenant=="string"&&Array.isArray(t.entries)&&t.entries.every(s=>!!s&&typeof s.id=="string"&&typeof s.title=="string"&&!!s.body&&Array.isArray(s.body.ast)&&Array.isArray(s.links))}function ut({endpoint:e,getToken:t,timeoutMs:s=Un}){let[l,i]=useState(()=>({feed:null,error:null,loading:true,stale:false})),[d,T]=useState(0),w=useRef(t);w.current=t,useEffect(()=>{let h=new AbortController,f=true,L=false,j=setTimeout(()=>{L=true,h.abort();},s),_=new Promise((r,c)=>{h.signal.addEventListener("abort",()=>c(new Error("timeout")),{once:true});});_.catch(()=>{}),i(r=>({...r,error:null,loading:true}));let x=null,b=(r,c)=>{if(c&&ze.delete(e),!f)return;let F=c||x===null?void 0:ze.get(e)?.get(x);i({feed:F??null,error:r,loading:false,stale:!!F});};return (async()=>{try{let r;try{r=await Promise.race([Promise.resolve().then(()=>w.current()),_]);}catch(B){throw L||h.signal.aborted?B:new je("token_unavailable")}x=r;let c=await Promise.race([In(e,r,h.signal),_]),F=c.status===401||c.status===403;F&&ze.delete(e);let v=null;try{v=await Promise.race([c.json(),_]);}catch(B){if(L&&!F)throw B;v=null;}if(!f)return;if(c.ok)if(!Fn(v))b("invalid_feed",!1);else {let B=ze.get(e)??new Map;B.set(r,v),ze.set(e,B),i({feed:v,error:null,loading:!1,stale:!1});}else {let B=v?.error;b(typeof B=="string"?B:`http_${c.status}`,F);}}catch(r){r instanceof je?b(r.message,true):b(L?"timeout":r instanceof Error&&r.message||"unavailable",false);}finally{clearTimeout(j);}})(),()=>{f=false,clearTimeout(j),h.abort();}},[e,d,s]);let C=useCallback(()=>T(h=>h+1),[]);return {...l,reload:C}}var ft=["accent","fg","bg","muted","border","radius","font"],Wn={accent:"hsl(var(--primary))",fg:"hsl(var(--foreground))",bg:"hsl(var(--card))",muted:"hsl(var(--muted-foreground))",border:"hsl(var(--border))",radius:"var(--radius)",font:"inherit"},ue=(e,t)=>t===void 0?`var(--bbrn-${e},var(--_bbrn-${e}))`:`var(--bbrn-${e},var(--_bbrn-${e},${t}))`,pt=ue("accent","currentColor"),gt=ue("muted","color-mix(in srgb,currentColor 72%,transparent)"),Ae=ue("border","color-mix(in srgb,currentColor 22%,transparent)"),Dn=`@layer bbrn{
|
|
2
|
+
.bbrn-root{${ft.filter(e=>e!=="font").map(e=>`--_bbrn-${e}:${Wn[e]};`).join("")}display:grid;gap:12px;color:${ue("fg")};font-family:var(--bbrn-font)}
|
|
3
|
+
.bbrn-root .bbrn-entry{background:${ue("bg","transparent")};border:1px solid ${Ae};border-radius:${ue("radius",".5rem")};padding:16px}
|
|
4
4
|
.bbrn-root .bbrn-head{display:flex;gap:8px;align-items:baseline;flex-wrap:wrap}
|
|
5
5
|
.bbrn-root .bbrn-title{font-weight:600;font-size:1rem;line-height:1.4;margin:0}
|
|
6
|
-
.bbrn-root .bbrn-badge{font-size:.75rem;line-height:1.4;color:${
|
|
7
|
-
.bbrn-root .bbrn-delivery{font-size:.75rem;line-height:1.4;border-radius:999px;padding:0 8px;background:color-mix(in srgb,${
|
|
8
|
-
.bbrn-root .bbrn-meta,.bbrn-root .bbrn-status{color:${
|
|
6
|
+
.bbrn-root .bbrn-badge{font-size:.75rem;line-height:1.4;color:${pt};border:1px solid currentColor;border-radius:999px;padding:0 8px}
|
|
7
|
+
.bbrn-root .bbrn-delivery{font-size:.75rem;line-height:1.4;border-radius:999px;padding:0 8px;background:color-mix(in srgb,${Ae} 60%,transparent)}
|
|
8
|
+
.bbrn-root .bbrn-meta,.bbrn-root .bbrn-status{color:${gt};font-size:.8rem;margin:0}
|
|
9
9
|
.bbrn-root .bbrn-p{margin:.5em 0}
|
|
10
10
|
.bbrn-root .bbrn-list{margin:.5em 0;padding-left:1.25em;list-style:disc}
|
|
11
|
-
.bbrn-root .bbrn-code{font-family:ui-monospace,monospace;font-size:.85em;padding:0 4px;border-radius:4px;background:color-mix(in srgb,${
|
|
11
|
+
.bbrn-root .bbrn-code{font-family:ui-monospace,monospace;font-size:.85em;padding:0 4px;border-radius:4px;background:color-mix(in srgb,${Ae} 60%,transparent)}
|
|
12
12
|
.bbrn-root .bbrn-links{display:flex;gap:12px;flex-wrap:wrap;margin-top:8px;font-size:.85rem}
|
|
13
|
-
.bbrn-root .bbrn-link{color:${
|
|
14
|
-
.bbrn-root .bbrn-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
.bbrn-root .bbrn-link{color:${pt};text-decoration:underline}
|
|
14
|
+
.bbrn-root .bbrn-tags{display:flex;gap:6px;flex-wrap:wrap;margin:8px 0 0;padding:0;list-style:none}
|
|
15
|
+
.bbrn-root .bbrn-tag{font-size:.75rem;line-height:1.4;border:1px solid ${Ae};border-radius:999px;padding:0 8px;color:${gt}}
|
|
16
|
+
.bbrn-root .bbrn-filters{display:flex;gap:12px;flex-wrap:wrap;align-items:center;font-size:.85rem}
|
|
17
|
+
.bbrn-root .bbrn-filter{display:inline-flex;gap:6px;align-items:center;color:${gt}}
|
|
18
|
+
.bbrn-root .bbrn-filter select{font:inherit;color:${ue("fg")};background:${ue("bg","transparent")};border:1px solid ${Ae};border-radius:${ue("radius",".5rem")};padding:2px 6px;max-width:16rem}
|
|
19
|
+
.bbrn-root .bbrn-retry{margin-left:8px;text-decoration:underline;background:none;border:0;padding:0;color:${pt};cursor:pointer;font:inherit}
|
|
20
|
+
}`;function Vt(e=typeof document>"u"?void 0:document){if(!e?.head||e.head.querySelector("style[data-bbrn-styles]"))return;let t=e.createElement("style");t.setAttribute("data-bbrn-styles",""),t.textContent=Dn,e.head.prepend(t);}function Yt(e){if(!e)return;let t={};for(let s of ft){let l=e[s];typeof l=="string"&&l.trim()&&(t[`--bbrn-${s}`]=l);}return Object.keys(t).length?t:void 0}function Gt(e){if(typeof e!="string"||/[\s\\]/.test(e))return null;if(e.startsWith("/"))return e.startsWith("//")?null:{kind:"internal",href:e};try{return new URL(e).protocol==="https:"?{kind:"external",href:e}:null}catch{return null}}function Ve(e,t=""){return e.map((s,l)=>{let i=`${t}${l}`;switch(s.t){case "text":return s.v;case "code":return jsx("code",{className:"bbrn-code",children:s.v},i);case "strong":return jsx("strong",{children:Ve(s.c,`${i}.`)},i);case "em":return jsx("em",{children:Ve(s.c,`${i}.`)},i);default:return null}})}function Xt({ast:e}){return jsx(Fragment,{children:e.map((t,s)=>t.t==="list"?jsx("ul",{className:"bbrn-list",children:t.items.map((l,i)=>jsx("li",{children:Ve(l)},i))},s):t.t==="p"?jsx("p",{className:"bbrn-p",children:Ve(t.c)},s):null)})}var O=(...e)=>e.filter(Boolean).join(" ");function jn(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:`${t.toISOString().slice(0,16).replace("T"," ")} UTC`}var Vn=useInsertionEffect??useLayoutEffect,bt=class extends Component{constructor(){super(...arguments);this.state={failed:false,keys:this.props.resetKeys};}static getDerivedStateFromError(){return {failed:true}}static getDerivedStateFromProps(s,l){return s.resetKeys.length!==l.keys.length||s.resetKeys.some((d,T)=>!Object.is(d,l.keys[T]))?{failed:false,keys:s.resetKeys}:null}componentDidCatch(){}render(){return this.state.failed?this.props.fallback:this.props.children}};function Yn(e,t){let s=Object.entries(t).filter(([,l])=>l).map(([l,i])=>`tag=${encodeURIComponent(`${l}:${i}`)}`);return s.length===0?e:`${e}${e.includes("?")?"&":"?"}${s.join("&")}`}function qn({endpoint:e,getToken:t,onNavigate:s,theme:l,classNames:i,components:d,timeoutMs:T}){Vn(()=>{Vt();},[]);let[w,C]=useState({}),h=useMemo(()=>Yn(e,w),[e,w]),{feed:f,error:L,loading:j,stale:_,reload:x}=ut({endpoint:h,getToken:t,timeoutMs:T}),[b,r]=useState(0),c=()=>{r(S=>S+1),x();},F=useMemo(()=>Yt(l),[l]),v=i??{},B=d?.Empty,V=d?.Link,W=S=>a=>{!s||a.defaultPrevented||a.button!==0||a.metaKey||a.ctrlKey||a.shiftKey||a.altKey||(a.preventDefault(),s(S));},A=Object.values(w).some(Boolean),pe=jsxs("p",{className:O("bbrn-status",v.status),role:"alert","data-bbrn-error":L??"render_failed",children:["Release notes could not be loaded.",jsx("button",{type:"button",className:O("bbrn-retry",v.retry),onClick:c,children:"Retry"}),A&&jsx("button",{type:"button",className:O("bbrn-retry",v.retry),onClick:()=>C({}),children:"Clear filters"})]});return jsxs("section",{className:O("bbrn-root",v.root),style:F,"aria-label":"Release notes","aria-busy":j,"data-bbrn-audience":f?.audience,children:[j&&!f&&jsx("p",{className:O("bbrn-status",v.status),role:"status",children:"Loading release notes\u2026"}),!j&&L&&!f&&pe,_&&jsxs("p",{className:O("bbrn-status",v.status),role:"status","data-bbrn-stale":"",children:["Showing the last loaded notes; they could not be refreshed.",jsx("button",{type:"button",className:O("bbrn-retry",v.retry),onClick:c,children:"Retry"})]}),f&&jsxs(bt,{resetKeys:[f,B,V,b],fallback:pe,children:[(f.filters?.length??0)>0&&jsx("div",{className:O("bbrn-filters",v.filters),role:"group","aria-label":"Filter release notes",children:f.filters.map(S=>jsxs("label",{className:O("bbrn-filter",v.filter),"data-bbrn-filter":S.group,children:[S.label,jsxs("select",{value:w[S.group]??"",onChange:a=>{let ae=a.target.value;C(Y=>({...Y,[S.group]:ae}));},children:[jsx("option",{value:"",children:"All"}),S.values.map(a=>jsx("option",{value:a,children:a},a))]})]},S.group))}),f.entries.length===0&&A&&jsx("p",{className:O("bbrn-status",v.status),children:"No release notes match these filters."}),f.entries.length===0&&!A&&(B?jsx(B,{}):jsxs("p",{className:O("bbrn-status",v.status),children:["No release notes yet. Submit one with ",jsx("code",{className:"bbrn-code",children:"bb release-notes submit"}),"."]})),f.entries.map(S=>jsxs("article",{className:O("bbrn-entry",v.entry),"data-entry-id":S.id,"data-source-key":S.source_key,children:[jsxs("div",{className:O("bbrn-head",v.head),children:[jsx("h2",{className:O("bbrn-title",v.title),children:S.title}),jsx("span",{className:O("bbrn-badge",v.badge),"data-bbrn-type":S.type,children:S.type}),jsx("span",{className:O("bbrn-badge",v.badge),"data-bbrn-state":S.state,children:S.state}),jsxs("span",{className:O("bbrn-meta",v.meta),children:[S.source_key," \xB7 revision ",S.revision]}),S.delivery_copy&&jsxs("span",{className:O("bbrn-delivery",v.delivery),"data-bbrn-delivery":S.delivery_badge,children:[S.delivery_copy,S.delivery_since&&jsxs(Fragment,{children:[" \xB7 since ",jsx("time",{dateTime:S.delivery_since,children:jn(S.delivery_since)})]})]})]}),jsx("div",{className:O("bbrn-body",v.body),children:jsx(Xt,{ast:S.body.ast})}),(S.tags?.length??0)>0&&jsx("ul",{className:O("bbrn-tags",v.tags),"aria-label":"Tags",children:S.tags.map(a=>jsx("li",{className:O("bbrn-tag",v.tag),"data-bbrn-tag-group":a.group,title:a.label,children:a.value},`${a.group}:${a.value}`))}),S.links.length>0&&jsx("div",{className:O("bbrn-links",v.links),children:S.links.map((a,ae)=>{let Y=Gt(a.url);if(!Y)return null;let ee=O("bbrn-link",v.link),Q=a.kind??null;return V?jsx(V,{href:Y.href,external:Y.kind==="external",kind:Q,className:ee,onClick:Y.kind==="internal"&&s?W(Y.href):void 0,children:a.name},ae):Y.kind==="external"?jsx("a",{className:ee,href:Y.href,target:"_blank",rel:"noopener noreferrer","data-link-kind":Q??void 0,children:a.name},ae):jsx("a",{className:ee,href:Y.href,onClick:W(Y.href),"data-link-kind":Q??void 0,children:a.name},ae)})})]},S.id))]})]})}
|
|
21
|
+
export{ft as RELEASE_NOTES_TOKENS,Xt as ReleaseNoteBody,qn as ReleaseNotes,Ln as TestRunWidget,Gt as safeHref,tt as useDraggable,nt as useRealtimeRefresh,ut as useReleaseNotes,ot as useTestRun,dt as useWidgetAuth};
|
package/package.json
CHANGED