@botbuddy/react 0.8.2 → 0.9.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/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');function xe(t,o){let[s,b]=react.useState({x:t,y:o}),m=react.useRef(false),f=react.useRef({x:0,y:0}),x=react.useRef(false),y=react.useCallback(l=>{m.current=true,x.current=false,f.current={x:l.clientX-s.x,y:l.clientY-s.y},l.target.setPointerCapture(l.pointerId);},[s]),v=react.useCallback(l=>{m.current&&(x.current=true,b({x:l.clientX-f.current.x,y:l.clientY-f.current.y}));},[]),u=react.useCallback(()=>{m.current=false;},[]);return {pos:s,onPointerDown:y,onPointerMove:v,onPointerUp:u,didDrag:x}}function me(t,o,s){let b=react.useRef(s);b.current=s,react.useEffect(()=>{if(!o)return;if(t.supabaseUrl){let f=t.supabaseUrl.replace(/^https:\/\//,"wss://").replace(/^http:\/\//,"ws://"),x=null,y=null,v=null,u=false,l=0,_=()=>{if(!u){try{x=new WebSocket(`${f}/realtime/v1/websocket?apikey=${t.anonKey}&vsn=1.0.0`);}catch{R();return}x.onopen=()=>{if(u||!x)return;let T={topic:`realtime:public:test_run_cases:test_run_id=eq.${o}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_run_cases",filter:`test_run_id=eq.${o}`}]}},ref:String(++l)};x.send(JSON.stringify(T));let n={topic:`realtime:public:test_runs:id=eq.${o}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_runs",filter:`id=eq.${o}`}]}},ref:String(++l)};x.send(JSON.stringify(n)),y=setInterval(()=>{x?.readyState===WebSocket.OPEN&&x.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++l)}));},3e4);},x.onmessage=T=>{try{JSON.parse(T.data).event==="postgres_changes"&&b.current();}catch{}},x.onclose=()=>{M(),u||(v=setTimeout(_,3e3));},x.onerror=()=>{x?.close();};}},M=()=>{y&&(clearInterval(y),y=null);},C=null,R=()=>{u||(C=setInterval(()=>b.current(),15e3));};return _(),()=>{u=true,M(),v&&clearTimeout(v),C&&clearInterval(C),x&&(x.onclose=null,x.onerror=null,x.close());}}let m=setInterval(()=>b.current(),15e3);return ()=>clearInterval(m)},[t.supabaseUrl,t.anonKey,o]);}function se(t,o){let s={apikey:t.anonKey};return o?s.Authorization=`Bearer ${o}`:t.apiKey?s.Authorization=`Bearer ${t.apiKey}`:s.Authorization=`Bearer ${t.anonKey}`,s}async function ct(t){if(t)return t;try{let o=await fetch("/.botbuddy-token",{cache:"no-store"});if(o.ok){let s=(await o.text()).trim();if(s.startsWith("public_"))return s}}catch{}try{let o=undefined?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(o&&typeof o=="string"&&o.startsWith("public_"))return o}catch{}return null}function be(t){let[o,s]=react.useState(null),[b,m]=react.useState("loading"),f=react.useCallback(async()=>{try{let u=await ct(t.testRunToken);if(!u){m("no-match"),s(null);return}if(!t.ticketId){m("no-match"),s(null);return}let l=new URLSearchParams;l.set("token",u),l.set("ticket_id",t.ticketId),l.set("app_slug",t.appSlug),t.environment&&l.set("environment",t.environment),t.testRunId&&l.set("test_run_id",t.testRunId),t.targetUrl&&l.set("target_url",t.targetUrl),t.version&&l.set("version",t.version),t.commitSha&&l.set("commit_sha",t.commitSha),t.prNumber&&l.set("pr_number",String(t.prNumber)),t.branchName&&l.set("branch_name",t.branchName);let _=await fetch(`${t.config.serverUrl}/widget/test-run?${l.toString()}`,{headers:se(t.config,t.authToken)});if(_.status===404){m("no-match"),s(null);return}if(_.status===401||_.status===403){m("error");return}if(!_.ok){m("error");return}let M=await _.json();s(M),m(M.status==="completed"?"completed":"ready");}catch{m("error");}},[t.config.serverUrl,t.config.anonKey,t.config.apiKey,t.authToken,t.appSlug,t.environment,t.ticketId,t.testRunId,t.testRunToken,t.targetUrl,t.version,t.commitSha,t.branchName,t.prNumber]);return react.useEffect(()=>{f();},[f]),me(t.config,o?.id,f),{run:o,widgetState:b,fetchRun:f,setVerdict:async(u,l,_,M="human")=>(s(R=>{if(!R)return null;let T=R.test_cases.map(d=>d.id===u?{...d,verdict:l,fail_reason:l==="fail"&&_||null,verdict_by_display_name:M,verdict_at:new Date().toISOString()}:d),n={total:T.length,pending:0,pass:0,fail:0,skip:0};return T.forEach(d=>{d.verdict in n&&n[d.verdict]++;}),{...R,test_cases:T,summary:n}}),(await fetch(`${t.config.serverUrl}/widget/test-cases/${u}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...se(t.config,t.authToken)},body:JSON.stringify({verdict:l,fail_reason:_,display_name:M})})).ok),markComplete:async()=>o?(s(l=>l?{...l,status:"completed"}:null),m("completed"),(await fetch(`${t.config.serverUrl}/widget/test-runs/${o.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...se(t.config,t.authToken)}})).ok):false,resetRun:async()=>{if(!o)return false;let u=await fetch(`${t.config.serverUrl}/widget/test-runs/${o.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...se(t.config,t.authToken)}});return u.ok&&f(),u.ok},setRun:s}}var ye="botbuddy-widget-auth-token",he="botbuddy-widget-auth-name";function ve(t){let[o,s]=react.useState(()=>{try{return localStorage.getItem(ye)}catch(y){return console.warn("Unable to read BotBuddy widget auth token",y),null}}),[b,m]=react.useState(()=>{try{return localStorage.getItem(he)}catch(y){return console.warn("Unable to read BotBuddy widget display name",y),null}});react.useEffect(()=>{let y=new URL(t).origin,v=u=>{if(u.origin===y&&u.data?.type==="botbuddy-widget-auth"&&u.data.token){let{token:l,displayName:_}=u.data;s(l),m(_||"human");try{localStorage.setItem(ye,l),_&&localStorage.setItem(he,_);}catch(M){console.warn("Unable to persist BotBuddy widget auth token",M);}}};return window.addEventListener("message",v),()=>window.removeEventListener("message",v)},[t]);let f=react.useCallback(()=>{let y=new URL("/widget-auth",t);y.searchParams.set("origin",window.location.origin);let v=420,u=520,l=window.screenX+(window.innerWidth-v)/2,_=window.screenY+(window.innerHeight-u)/2;window.open(y.toString(),"botbuddy-auth",`width=${v},height=${u},left=${l},top=${_},popup=yes`);},[t]),x=react.useCallback(()=>{s(null),m(null);try{localStorage.removeItem(ye),localStorage.removeItem(he);}catch(y){console.warn("Unable to clear BotBuddy widget auth token",y);}},[]);return {token:o,displayName:b,isAuthenticated:!!o,openLogin:f,logout:x}}function gt(t){let o=new Date(t),b=Date.now()-o.getTime();if(b<6e4)return "just now";if(b<36e5)return `${Math.floor(b/6e4)}m ago`;if(b<864e5)return `${Math.floor(b/36e5)}h ago`;let m=o.getDate(),f=o.toLocaleString("en",{month:"short"}),x=o.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${f} ${m}, ${x}`}var g=({d:t,className:o,size:s=14})=>jsxRuntime.jsx("svg",{className:o,width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:t})}),c={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",user:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2M12 3a4 4 0 1 0 0 8 4 4 0 0 0 0-8",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 ft(){let[t,o]=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,b=()=>s.classList.contains("dark")?"dark":s.classList.contains("light")?"light":null,m=b();m&&o(m);let f=window.matchMedia("(prefers-color-scheme: dark)"),x=v=>{let u=b();o(u||(v.matches?"dark":"light"));};f.addEventListener("change",x);let y=new MutationObserver(()=>{let v=b();o(v||(f.matches?"dark":"light"));});return y.observe(s,{attributes:true,attributeFilter:["class"]}),()=>{f.removeEventListener("change",x),y.disconnect();}},[]),t}function xt(t){let o=t==="dark";return {bg:o?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:o?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:o?"#e5e5e5":"#1a1a1a",textMuted:o?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:o?"#555":"#999",border:o?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:o?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:o?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:o?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:o?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:o?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:o?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:o?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:o?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:o?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:o?"#888":"#aaa",btnHover:o?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var mt={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},bt={pending:c.circle,pass:c.check,fail:c.x,skip:c.skip},Oe={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)"}},yt=t=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:o=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:t.bg,border:o?`1px solid ${t.greenBorder}`:`1px solid ${t.border}`,boxShadow:o?`0 4px 12px ${t.shadow}, 0 0 0 1px ${t.greenBorderSubtle}`:`0 4px 12px ${t.shadow}`,cursor:"pointer",fontSize:"9px",color:t.text}),card:(o,s)=>({width:`${o}px`,borderRadius:"8px",background:t.bg,border:s?`1px solid ${t.greenBorder}`:`1px solid ${t.border}`,boxShadow:s?`0 8px 24px ${t.shadow}, 0 0 0 1px ${t.greenBorderSubtle}`:`0 8px 24px ${t.shadow}`,overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:`1px solid ${t.borderSubtle}`},title:{fontSize:"10px",fontWeight:600,color:t.text,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:t.textMuted,display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:t.gripColor,display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:`1px solid ${t.borderSubtle}`},badge:o=>{let s=Oe[o]||Oe.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:t.borderSubtle,flexShrink:0},progressBar:o=>({height:"100%",width:`${o}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:o=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${o}15`,color:o,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${t.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(o,s)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:o?`${s}33`:"transparent",color:o?s:t.gripColor,transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:t.inputBg,border:`1px solid ${t.inputBorder}`,borderRadius:"4px",padding:"2px 6px",color:t.text,outline:"none"},humanBanner:{padding:"6px 12px",fontSize:"11px",fontWeight:600,color:t.green,borderBottom:`1px solid ${t.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",background:t.greenBg,cursor:"pointer",textDecoration:"none"}});function ht({config:t,appSlug:o,environment:s,seedUserSlug:b,authToken:m,tk:f}){let[x,y]=react.useState(null),[v,u]=react.useState(0),[l,_]=react.useState(false),[M,C]=react.useState(null),[R,T]=react.useState(false),n=react.useRef(null),d=react.useMemo(()=>b.split("/")[0].trim(),[b]),K=react.useCallback(async()=>{_(true),C(null);try{let $=new URLSearchParams({app_slug:o,seed_user_slug:d,environment:s}),E={apikey:t.anonKey};m?E.Authorization=`Bearer ${m}`:E.Authorization=`Bearer ${t.anonKey}`;let B=await fetch(`${t.serverUrl}/widget/totp-code?${$}`,{headers:E});if(!B.ok){let w=await B.json().catch(()=>({error:"Failed"}));if(B.status===404){C("No 2FA seed registered");return}C(w.error||"Failed to get code");return}let U=await B.json();y(U.code),u(U.remaining_seconds);try{await navigator.clipboard.writeText(U.code),T(!0),setTimeout(()=>T(!1),2e3);}catch{}n.current&&clearInterval(n.current);let V=U.remaining_seconds;n.current=setInterval(()=>{V--,V<=0?(n.current&&clearInterval(n.current),K()):u(V);},1e3);}catch{C("Network error");}finally{_(false);}},[t.serverUrl,t.anonKey,m,o,d,s]);return react.useEffect(()=>()=>{n.current&&clearInterval(n.current);},[]),M==="No 2FA seed registered"?null:x?jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"3px"},children:[jsxRuntime.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"3px 8px",borderRadius:"4px",background:`${f.purple}15`,border:`1px solid ${f.purple}40`,fontSize:"12px",fontFamily:"ui-monospace, monospace",fontWeight:700,color:f.purple,letterSpacing:"0.15em"},children:[jsxRuntime.jsx(g,{d:c.shield,size:11}),jsxRuntime.jsx("span",{children:x}),jsxRuntime.jsxs("span",{style:{fontSize:"8px",fontWeight:400,color:f.textMuted,letterSpacing:"0"},children:[v,"s"]})]}),jsxRuntime.jsx("button",{onClick:$=>{$.stopPropagation(),navigator.clipboard.writeText(x).then(()=>{T(true),setTimeout(()=>T(false),1500);});},style:{padding:"2px",background:"none",border:"none",cursor:"pointer",color:R?f.green:f.gripColor,fontSize:"8px"},title:"Copy code",children:R?jsxRuntime.jsx(g,{d:c.check,size:10}):jsxRuntime.jsx(g,{d:c.copy,size:10})})]}):jsxRuntime.jsxs("button",{onClick:$=>{$.stopPropagation(),K();},disabled:l,style:{display:"inline-flex",alignItems:"center",gap:"4px",marginTop:"3px",fontSize:"8px",padding:"2px 6px",borderRadius:"4px",background:`${f.purple}12`,color:f.purple,border:`1px solid ${f.purple}30`,cursor:l?"wait":"pointer",opacity:l?.6:1},children:[jsxRuntime.jsx(g,{d:c.shield,size:9}),l?"generating...":M||"Get 2FA code"]})}var Ke="botbuddy-widget-state";function vt({config:t,appSlug:o,environment:s,ticketId:b,testRunId:m,testRunToken:f,targetUrl:x,version:y,commitSha:v,prNumber:u,branchName:l,onNavigate:_,displayName:M="human",defaultMode:C="mini",defaultPosition:R}){let T=ft(),n=react.useMemo(()=>xt(T),[T]),d=react.useMemo(()=>yt(n),[n]),[K,$]=react.useState(false),[E,B]=react.useState(false),U=react.useRef(false),V=t.dashboardUrl||"https://app.bot-buddy.ai",w=ve(V),le=(()=>{try{let e=typeof window<"u"?localStorage.getItem(Ke):null;if(e)return JSON.parse(e)}catch{}return null})(),[j,Y]=react.useState(le?.mode||C),[de,re]=react.useState(""),[Ve,J]=react.useState(null),[_e,Se]=react.useState(null),[je,Ye]=react.useState(new Set),[N,we]=react.useState(""),Je=react.useCallback(e=>{Ye(p=>{let h=new Set(p);return h.has(e)?h.delete(e):h.add(e),h});},[]),Ge=le?.x??R?.x??16,qe=le?.y??R?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:P,onPointerDown:G,onPointerMove:q,onPointerUp:X,didDrag:pe}=xe(Ge,qe);react.useEffect(()=>{try{localStorage.setItem(Ke,JSON.stringify({mode:j,x:P.x,y:P.y}));}catch{}},[j,P.x,P.y]);let ke=react.useRef(w.isAuthenticated);react.useEffect(()=>{!ke.current&&w.isAuthenticated&&Y("max"),ke.current=w.isAuthenticated;},[w.isAuthenticated]);let Me="botbuddy-widget-max-size",Xe=()=>{try{let e=localStorage.getItem(Me);if(e)return JSON.parse(e)}catch{}return {w:340,h:500}},[Z,Te]=react.useState(Xe),Q=react.useRef(false),ee=react.useRef({x:0,y:0,w:0,h:0}),Ze=react.useCallback(e=>{e.stopPropagation(),Q.current=true,ee.current={x:e.clientX,y:e.clientY,w:Z.w,h:Z.h},e.target.setPointerCapture(e.pointerId);},[Z]),Qe=react.useCallback(e=>{if(!Q.current)return;let p=Math.max(280,Math.min(600,ee.current.w+(e.clientX-ee.current.x))),h=Math.max(300,Math.min(window.innerHeight*.9,ee.current.h+(e.clientY-ee.current.y)));Te({w:p,h});},[]),et=react.useCallback(()=>{Q.current&&(Q.current=false,Te(e=>(localStorage.setItem(Me,JSON.stringify(e)),e)));},[]),oe=x??(typeof window<"u"?window.location.href:void 0),ze=w.displayName||M,[W,Ce]=react.useState(null);react.useEffect(()=>{if(w.isAuthenticated)return;let e=new URLSearchParams;f&&e.set("token",f),b&&e.set("ticket_id",b),e.set("app_slug",o),s&&e.set("environment",s),m&&e.set("test_run_id",m),oe&&e.set("target_url",oe),y&&e.set("version",y),v&&e.set("commit_sha",v),u&&e.set("pr_number",String(u)),l&&e.set("branch_name",l),fetch(`${t.serverUrl}/widget/preview?${e}`,{headers:{apikey:t.anonKey}}).then(p=>p.json()).then(p=>Ce(p)).catch(()=>Ce(null));},[w.isAuthenticated,t.serverUrl,t.anonKey,o,s,b,m,f,oe,y,v,u,l]);let{run:a,widgetState:D,fetchRun:tt,setVerdict:Re,markComplete:nt,resetRun:rt}=be({config:t,appSlug:o,environment:s,ticketId:b,testRunId:m,testRunToken:f,targetUrl:oe,version:y,commitSha:v,prNumber:u?String(u):void 0,branchName:l,authToken:w.token}),ie=react.useCallback(async(e,p,h)=>{Se(e);try{await Re(e,p,h,ze);}finally{Se(null),J(null),re("");}},[Re,ze]),S=a?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},ot=S.total>0&&S.pending===0,A=D==="completed",ae=react.useMemo(()=>{let e=a?.test_cases||[];if(!N.trim())return e;let p=N.toLowerCase();return e.filter(h=>h.title.toLowerCase().includes(p)||h.description&&h.description.toLowerCase().includes(p)||h.url_path&&h.url_path.toLowerCase().includes(p)||h.seed_user&&h.seed_user.toLowerCase().includes(p))},[a?.test_cases,N]),$e=react.useMemo(()=>{let e=ae,p=a?.test_cases||[];if(new Set(p.map(z=>z.source_pr_number)).size<=1)return null;let I=[],te=new Map;e.forEach(z=>{let L=z.source_pr_number;te.has(L)||te.set(L,[]),te.get(L).push(z);});let it=[...te.keys()].sort((z,L)=>z===null?1:L===null?-1:L-z);for(let z of it){let L=te.get(z),ue={total:L.length,pass:0,fail:0,skip:0,pending:0};L.forEach(Ne=>{Ne.verdict in ue&&ue[Ne.verdict]++;}),I.push({key:z!=null?`pr-${z}`:"general",label:z!=null?`PR #${z}`:"General",cases:L,summary:ue});}return I.filter(z=>z.cases.length>0)},[ae,a?.test_cases]),Be=S.total>0?(S.pass+S.fail)/S.total*100:0,ce=react.useMemo(()=>{let e=a?.auto_tooltip_seconds??W?.auto_tooltip_seconds;return e!=null&&e>0?e*1e3:5e3},[a,W]),Pe=D==="ready"||D==="completed"||W?.enabled&&W.run;react.useEffect(()=>{if(!Pe||U.current||ce<=0)return;U.current=true,B(true);let e=window.setTimeout(()=>B(false),ce);return ()=>window.clearTimeout(e)},[Pe,ce]);let Ie=e=>jsxRuntime.jsxs("div",{style:d.caseRow,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsx("div",{style:{marginTop:"2px",flexShrink:0,color:mt[e.verdict]},children:_e===e.id?jsxRuntime.jsx(g,{d:c.loader,className:""}):jsxRuntime.jsx(g,{d:bt[e.verdict],className:""})}),jsxRuntime.jsxs("div",{style:{minWidth:0,flex:1},children:[jsxRuntime.jsx("div",{style:{fontSize:"10px",color:n.text,lineHeight:1.3},children:e.title}),e.description&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:n.gripColor,marginTop:"2px"},children:e.description}),e.seed_user&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:n.amber,marginTop:"3px",display:"flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",background:`${n.amber}12`,border:`1px solid ${n.amber}30`},children:[jsxRuntime.jsx(g,{d:c.key,size:10}),jsxRuntime.jsx("span",{children:e.seed_user})]}),(s??a?.environment)!=="production"&&(s??a?.environment)&&jsxRuntime.jsx(ht,{config:t,appSlug:o,environment:s??a?.environment,seedUserSlug:e.seed_user,authToken:w.token,tk:n})]}),e.url_path&&jsxRuntime.jsxs("a",{href:e.url_path,target:"_blank",rel:"noopener noreferrer",onClick:p=>{p.stopPropagation(),_&&(p.preventDefault(),_(e.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(g,{d:c.externalLink,size:10}),e.url_path]}),e.verdict==="fail"&&e.fail_reason&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:n.red,marginTop:"2px"},children:["\u2717 ",e.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(e.verdict===p){ie(e.id,"pending"),J(null);return}if(p==="fail"){J(e.id),re("");return}J(null),ie(e.id,p);},disabled:_e!==null,style:d.verdictBtn(e.verdict===p,p==="pass"?n.green:p==="fail"?n.red:n.amber),children:p.toUpperCase()},p)),e.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(g,{d:c.bot,size:8}),e.created_by_agent_name]}),e.verdict_by_display_name&&jsxRuntime.jsxs("span",{style:{fontSize:"8px",color:n.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[e.verdict_by_display_name,e.verdict_at&&jsxRuntime.jsx("span",{style:{opacity:.7},children:gt(e.verdict_at)})]})]}),Ve===e.id&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:de,onChange:p=>re(p.target.value),onKeyDown:p=>{p.key==="Enter"&&ie(e.id,"fail",de.trim()||void 0),p.key==="Escape"&&(J(null),re(""));},placeholder:"Reason (optional)...",style:d.input}),jsxRuntime.jsx("button",{onClick:()=>{ie(e.id,"fail",de.trim()||void 0);},style:d.verdictBtn(true,n.red),children:"\u2713"})]})]},e.id);if((D==="no-match"||D==="loading")&&!(!w.isAuthenticated&&W?.enabled&&W.run))return null;if(!w.isAuthenticated&&W?.enabled&&W.run){let e=W.run,p=e.summary,h=e.status==="completed";return jsxRuntime.jsx("div",{style:{...d.root,left:P.x,top:P.y},children:jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>$(true),onMouseLeave:()=>$(false),children:[jsxRuntime.jsxs("div",{style:{...d.pill(h),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:G,onPointerMove:q,onPointerUp:()=>{X();},children:[jsxRuntime.jsx(g,{d:c.grip,size:10,className:""}),e.ticket_id&&e.ticket_url?jsxRuntime.jsx("a",{href:e.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:I=>I.stopPropagation(),style:{color:n.amber,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:e.ticket_id}):null,e.pr_url?jsxRuntime.jsxs("a",{href:e.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:I=>I.stopPropagation(),style:{color:n.blue,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:["PR#",e.pr_number??e.pr_id]}):null,e.created_by_agent_name?e.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${e.codex_thread_id}`,onClick:I=>I.stopPropagation(),style:{color:n.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(g,{d:c.terminal,size:10}),e.created_by_agent_name]}):jsxRuntime.jsxs("span",{style:{color:n.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(g,{d:c.bot,size:10}),e.created_by_agent_name]}):null,jsxRuntime.jsxs("span",{style:h?{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:I=>{I.stopPropagation(),w.openLogin();},style:{color:n.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),(K||E)&&e.title&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"220px",maxWidth:"320px",padding:"10px 14px",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:"13px",fontWeight:700,color:n.text,lineHeight:1.3},children:e.title}),(e.description||e.intro_notes)&&jsxRuntime.jsx("div",{style:{fontSize:"11px",color:n.textMuted,marginTop:"6px",lineHeight:1.4},children:e.description||e.intro_notes}),jsxRuntime.jsx("div",{style:{marginTop:"6px",fontSize:"9px",color:n.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!w.isAuthenticated)return jsxRuntime.jsxs("div",{style:{...d.root,left:P.x,top:P.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:G,onPointerMove:q,onPointerUp:X,children:[jsxRuntime.jsx("div",{style:{...d.handle,borderBottom:"none"},children:jsxRuntime.jsxs("div",{style:d.sub,children:[jsxRuntime.jsx(g,{d:c.grip,size:10,className:""}),jsxRuntime.jsx(g,{d:c.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"}),jsxRuntime.jsx("button",{onClick:e=>{e.stopPropagation(),w.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"})]})]});let Le=()=>{pe.current||(B(false),Y(e=>e==="mini"?"max":"mini"));},We=({icon:e,onClick:p})=>jsxRuntime.jsx("button",{style:d.btn,onClick:h=>{h.stopPropagation(),p(h);},children:jsxRuntime.jsx(g,{d:e,className:""})}),Ue=()=>{if(!a?.assigned_human_display_name)return null;let e=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:n.green,display:"inline-block",flexShrink:0,boxShadow:`0 0 6px ${n.green}66`}}),jsxRuntime.jsx(g,{d:c.user,size:13}),jsxRuntime.jsx("span",{style:{flex:1},children:a.assigned_human_display_name}),a.codex_thread_id&&jsxRuntime.jsx(g,{d:c.externalLink,size:10})]});return a.codex_thread_id?jsxRuntime.jsx("a",{href:`codex://threads/${a.codex_thread_id}`,style:d.humanBanner,children:e}):jsxRuntime.jsx("div",{style:d.humanBanner,children:e})},De=()=>jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${n.borderSubtle}`,flexShrink:0},children:[a?.pr_url&&jsxRuntime.jsxs("a",{href:a.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.blue),textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:c.pr,size:12}),a.pr_number?`PR#${a.pr_number}`:a.pr_id||"PR",jsxRuntime.jsx(g,{d:c.externalLink,size:8})]}),a?.ticket_url&&jsxRuntime.jsxs("a",{href:a.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.amber),textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:c.ticket,size:12}),a.ticket_id||"Ticket",jsxRuntime.jsx(g,{d:c.externalLink,size:8})]}),a?.created_by_agent_name&&(a.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${a.codex_thread_id}`,style:{...d.link(n.purple),textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:c.bot,size:12}),a.created_by_agent_name,jsxRuntime.jsx(g,{d:c.externalLink,size:8})]}):jsxRuntime.jsxs("span",{style:{...d.link(n.purple)},children:[jsxRuntime.jsx(g,{d:c.bot,size:12}),a.created_by_agent_name]})),jsxRuntime.jsx("span",{style:{...d.badge(a?.environment||"custom"),marginLeft:"auto"},children:a?.environment})]}),Ee=()=>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("0.5.10");},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.jsx("span",{style:{color:n.versionNum},children:"v0.5.10"})]}),w.isAuthenticated&&jsxRuntime.jsx("button",{onClick:e=>{e.stopPropagation(),w.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",{style:{...d.root,left:P.x,top:P.y},children:[j==="mini"&&jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>$(true),onMouseLeave:()=>$(false),children:[jsxRuntime.jsxs("div",{style:{...d.pill(A),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:G,onPointerMove:q,onPointerUp:()=>{X(),pe.current||Le();},children:[jsxRuntime.jsx(g,{d:c.grip,size:10,className:""}),a?.ticket_id&&jsxRuntime.jsx("span",{style:{color:n.amber,fontWeight:600},children:a.ticket_id}),a?.pr_number&&jsxRuntime.jsxs("span",{style:{color:n.blue,fontWeight:600},children:["PR#",a.pr_number]}),a?.created_by_agent_name&&(a.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${a.codex_thread_id}`,onClick:e=>e.stopPropagation(),style:{color:n.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px",textDecoration:"none",cursor:"pointer"},children:[jsxRuntime.jsx(g,{d:c.terminal,size:10}),a.created_by_agent_name,jsxRuntime.jsx(g,{d:c.externalLink,size:8})]}):jsxRuntime.jsxs("span",{style:{color:n.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(g,{d:c.bot,size:10}),a.created_by_agent_name]})),jsxRuntime.jsxs("span",{style:A?{color:n.green}:void 0,children:[S.pass,"/",S.total]}),S.fail>0&&jsxRuntime.jsxs("span",{style:{color:n.red},children:[S.fail,"\u2717"]})]}),(K||E)&&a?.title&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"220px",maxWidth:"320px",padding:"10px 14px",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:"13px",fontWeight:700,color:n.text,lineHeight:1.3},children:a.title}),(a.description||a.intro_notes)&&jsxRuntime.jsx("div",{style:{fontSize:"11px",color:n.textMuted,marginTop:"6px",lineHeight:1.4},children:a.description||a.intro_notes})]})]}),j==="expanded"&&jsxRuntime.jsxs("div",{style:d.card(300,A),children:[jsxRuntime.jsx(Ue,{}),jsxRuntime.jsxs("div",{style:d.handle,onPointerDown:G,onPointerMove:q,onPointerUp:X,onClick:Le,children:[jsxRuntime.jsx(g,{d:c.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:d.title,children:a?.title}),jsxRuntime.jsx("div",{style:d.sub,children:a?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",a.branch_name]})})]}),jsxRuntime.jsx(g,{d:c.chevronUp,className:""}),jsxRuntime.jsx(We,{icon:c.minus,onClick:()=>{B(false),Y("mini");}})]}),jsxRuntime.jsxs("div",{style:d.stats,children:[jsxRuntime.jsxs("span",{style:{color:n.green},children:[S.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:n.red},children:[S.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:n.amber},children:[S.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:n.gripColor},children:[S.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:S.total})]}),a?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:n.gripColor,borderBottom:`1px solid ${n.borderSubtle}`,flexShrink:0},children:a.description}),jsxRuntime.jsx(De,{}),jsxRuntime.jsx(Ee,{}),jsxRuntime.jsx("div",{style:d.progress,children:jsxRuntime.jsx("div",{style:d.progressBar(Be)})})]}),j==="max"&&jsxRuntime.jsxs("div",{style:{...d.card(Z.w,A),height:Z.h,position:"relative"},children:[jsxRuntime.jsx(Ue,{}),jsxRuntime.jsxs("div",{style:d.handle,onPointerDown:G,onPointerMove:q,onPointerUp:X,onClick:()=>{pe.current||Y("expanded");},children:[jsxRuntime.jsx(g,{d:c.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:d.title,children:a?.title}),jsxRuntime.jsx("div",{style:d.sub,children:a?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",a.branch_name]})})]}),jsxRuntime.jsx(g,{d:c.chevronDown,className:""}),jsxRuntime.jsx(We,{icon:c.minus,onClick:()=>{B(false),Y("mini");}})]}),jsxRuntime.jsxs("div",{style:d.stats,children:[jsxRuntime.jsxs("span",{style:{color:n.green},children:[S.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:n.red},children:[S.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:n.amber},children:[S.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:n.gripColor},children:[S.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:S.total})]}),(a?.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(g,{d:c.search,size:11,className:""}),jsxRuntime.jsx("input",{value:N,onChange:e=>we(e.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:n.text,fontFamily:"monospace"}}),N&&jsxRuntime.jsx("button",{onClick:()=>we(""),style:{background:"none",border:"none",cursor:"pointer",color:n.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),D==="error"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsxRuntime.jsx(g,{d:c.alert,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:n.red},children:"Failed to load"}),jsxRuntime.jsx("button",{onClick:tt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),A&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg},children:[jsxRuntime.jsx(g,{d:c.checkAll,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",color:n.green,flex:1},children:"Run completed"}),jsxRuntime.jsx("button",{onClick:rt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),a?.intro_notes&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${n.borderSubtle}`,fontSize:"10px",color:n.textMuted,fontStyle:"italic",flexShrink:0},children:a.intro_notes}),D!=="error"&&jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(a?.test_cases||[]).length===0?jsxRuntime.jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:"No test cases"}):ae.length===0?jsxRuntime.jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:['No matches for "',N,'"']}):$e?$e.map(e=>{let p=je.has(e.key);return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>Je(e.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(g,{d:p?c.chevronDown:c.chevronUp,size:10,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",fontWeight:700,color:n.blue,flex:1,textAlign:"left"},children:e.label}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:n.green},children:[e.summary.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:n.red},children:[e.summary.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:n.gripColor},children:[e.summary.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{fontSize:"9px",color:n.textFaint},children:e.summary.total})]}),!p&&e.cases.map(h=>Ie(h))]},e.key)}):ae.map(e=>Ie(e))}),ot&&!A&&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:nt,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"})]}),jsxRuntime.jsx(De,{}),jsxRuntime.jsx(Ee,{}),jsxRuntime.jsx("div",{style:d.progress,children:jsxRuntime.jsx("div",{style:d.progressBar(Be)})}),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:Ze,onPointerMove:Qe,onPointerUp:et,onPointerEnter:e=>e.currentTarget.style.opacity="0.7",onPointerLeave:e=>{Q.current||(e.currentTarget.style.opacity="0.3");},children:jsxRuntime.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsxRuntime.jsx("path",{d:"M7 1v6H1",fill:"none",stroke:n.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}
2
- exports.TestRunWidget=vt;exports.useDraggable=xe;exports.useRealtimeRefresh=me;exports.useTestRun=be;exports.useWidgetAuth=ve;
1
+ 'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');function xe(t,o){let[l,b]=react.useState({x:t,y:o}),x=react.useRef(false),g=react.useRef({x:0,y:0}),S=react.useRef(false),h=react.useCallback(c=>{x.current=true,S.current=false,g.current={x:c.clientX-l.x,y:c.clientY-l.y},c.target.setPointerCapture(c.pointerId);},[l]),y=react.useCallback(c=>{x.current&&(S.current=true,b({x:c.clientX-g.current.x,y:c.clientY-g.current.y}));},[]),p=react.useCallback(()=>{x.current=false;},[]);return {pos:l,onPointerDown:h,onPointerMove:y,onPointerUp:p,didDrag:S}}function me(t,o,l){let b=react.useRef(l);b.current=l,react.useEffect(()=>{if(!o)return;if(t.supabaseUrl){let g=false,S=null,h=()=>{g||S||(S=setInterval(()=>b.current(),15e3));},y=null;try{let _=new URL(t.supabaseUrl),n=["localhost","127.0.0.1","::1"].includes(_.hostname);if(_.protocol==="http:"&&!n)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");_.protocol=_.protocol==="https:"?"wss:":"ws:",y=_.toString().replace(/\/$/,"");}catch{h();}let p=null,c=null,v=null,w=0,E=()=>{if(!(g||!y)){try{p=new WebSocket(`${y}/realtime/v1/websocket?apikey=${t.anonKey}&vsn=1.0.0`);}catch{h();return}p.onopen=()=>{if(g||!p)return;let _={topic:`realtime:public:test_run_cases:test_run_id=eq.${o}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_run_cases",filter:`test_run_id=eq.${o}`}]}},ref:String(++w)};p.send(JSON.stringify(_));let n={topic:`realtime:public:test_runs:id=eq.${o}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_runs",filter:`id=eq.${o}`}]}},ref:String(++w)};p.send(JSON.stringify(n)),c=setInterval(()=>{p?.readyState===WebSocket.OPEN&&p.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++w)}));},3e4);},p.onmessage=_=>{try{JSON.parse(_.data).event==="postgres_changes"&&b.current();}catch{}},p.onclose=()=>{R(),g||(v=setTimeout(E,3e3));},p.onerror=()=>{p?.close();};}},R=()=>{c&&(clearInterval(c),c=null);};return E(),()=>{g=true,R(),v&&clearTimeout(v),S&&clearInterval(S),p&&(p.onclose=null,p.onerror=null,p.close());}}let x=setInterval(()=>b.current(),15e3);return ()=>clearInterval(x)},[t.supabaseUrl,t.anonKey,o]);}function ae(t,o){let l={apikey:t.anonKey};return o?l.Authorization=`Bearer ${o}`:t.apiKey?l.Authorization=`Bearer ${t.apiKey}`:l.Authorization=`Bearer ${t.anonKey}`,l}async function ht(t){if(t)return t;try{let o=await fetch("/.botbuddy-token",{cache:"no-store"});if(o.ok){let l=(await o.text()).trim();if(l.startsWith("public_"))return l}}catch{}try{let o=undefined?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(o&&typeof o=="string"&&o.startsWith("public_"))return o}catch{}return null}function he(t){let[o,l]=react.useState(null),[b,x]=react.useState("loading"),g=react.useCallback(async()=>{try{let p=await ht(t.testRunToken);if(!p){x("no-match"),l(null);return}if(!t.ticketId){x("no-match"),l(null);return}let c=new URLSearchParams;c.set("token",p),c.set("ticket_id",t.ticketId),c.set("app_slug",t.appSlug),t.environment&&c.set("environment",t.environment),t.testRunId&&c.set("test_run_id",t.testRunId),t.targetUrl&&c.set("target_url",t.targetUrl),t.version&&c.set("version",t.version),t.commitSha&&c.set("commit_sha",t.commitSha),t.prNumber&&c.set("pr_number",String(t.prNumber)),t.branchName&&c.set("branch_name",t.branchName);let v=await fetch(`${t.config.serverUrl}/widget/test-run?${c.toString()}`,{headers:ae(t.config,t.authToken)});if(v.status===404){x("no-match"),l(null);return}if(v.status===401||v.status===403){x("error");return}if(!v.ok){x("error");return}let w=await v.json();l(w),x(w.status==="completed"?"completed":"ready");}catch{x("error");}},[t.config.serverUrl,t.config.anonKey,t.config.apiKey,t.authToken,t.appSlug,t.environment,t.ticketId,t.testRunId,t.testRunToken,t.targetUrl,t.version,t.commitSha,t.branchName,t.prNumber]);return react.useEffect(()=>{g();},[g]),me(t.config,o?.id,g),{run:o,widgetState:b,fetchRun:g,setVerdict:async(p,c,v,w="human")=>(l(R=>{if(!R)return null;let _=R.test_cases.map(s=>s.id===p?{...s,verdict:c,fail_reason:c==="fail"&&v||null,verdict_by_display_name:w,verdict_at:new Date().toISOString()}:s),n={total:_.length,pending:0,pass:0,fail:0,skip:0};return _.forEach(s=>{s.verdict in n&&n[s.verdict]++;}),{...R,test_cases:_,summary:n}}),(await fetch(`${t.config.serverUrl}/widget/test-cases/${p}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...ae(t.config,t.authToken)},body:JSON.stringify({verdict:c,fail_reason:v,display_name:w})})).ok),markComplete:async()=>o?(l(c=>c?{...c,status:"completed"}:null),x("completed"),(await fetch(`${t.config.serverUrl}/widget/test-runs/${o.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...ae(t.config,t.authToken)}})).ok):false,resetRun:async()=>{if(!o)return false;let p=await fetch(`${t.config.serverUrl}/widget/test-runs/${o.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...ae(t.config,t.authToken)}});return p.ok&&g(),p.ok},setRun:l}}var ye="botbuddy-widget-auth-token",ve="botbuddy-widget-auth-name";function _e(t){let[o,l]=react.useState(()=>{try{return localStorage.getItem(ye)}catch(h){return console.warn("Unable to read BotBuddy widget auth token",h),null}}),[b,x]=react.useState(()=>{try{return localStorage.getItem(ve)}catch(h){return console.warn("Unable to read BotBuddy widget display name",h),null}});react.useEffect(()=>{let h=new URL(t).origin,y=p=>{if(p.origin===h&&p.data?.type==="botbuddy-widget-auth"&&p.data.token){let{token:c,displayName:v}=p.data;l(c),x(v||"human");try{localStorage.setItem(ye,c),v&&localStorage.setItem(ve,v);}catch(w){console.warn("Unable to persist BotBuddy widget auth token",w);}}};return window.addEventListener("message",y),()=>window.removeEventListener("message",y)},[t]);let g=react.useCallback(()=>{let h=new URL("/widget-auth",t);h.searchParams.set("origin",window.location.origin);let y=420,p=520,c=window.screenX+(window.innerWidth-y)/2,v=window.screenY+(window.innerHeight-p)/2;window.open(h.toString(),"botbuddy-auth",`width=${y},height=${p},left=${c},top=${v},popup=yes`);},[t]),S=react.useCallback(()=>{l(null),x(null);try{localStorage.removeItem(ye),localStorage.removeItem(ve);}catch(h){console.warn("Unable to clear BotBuddy widget auth token",h);}},[]);return {token:o,displayName:b,isAuthenticated:!!o,openLogin:g,logout:S}}function vt(t){let o=new Date(t),b=Date.now()-o.getTime();if(b<6e4)return "just now";if(b<36e5)return `${Math.floor(b/6e4)}m ago`;if(b<864e5)return `${Math.floor(b/36e5)}h ago`;let x=o.getDate(),g=o.toLocaleString("en",{month:"short"}),S=o.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${g} ${x}, ${S}`}var f=({d:t,className:o,size:l=14})=>jsxRuntime.jsx("svg",{className:o,width:l,height:l,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:t})}),u={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",user:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2M12 3a4 4 0 1 0 0 8 4 4 0 0 0 0-8",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",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 _t(){let[t,o]=react.useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return react.useEffect(()=>{if(typeof window>"u")return;let l=document.documentElement,b=()=>l.classList.contains("dark")?"dark":l.classList.contains("light")?"light":null,x=b();x&&o(x);let g=window.matchMedia("(prefers-color-scheme: dark)"),S=y=>{let p=b();o(p||(y.matches?"dark":"light"));};g.addEventListener("change",S);let h=new MutationObserver(()=>{let y=b();o(y||(g.matches?"dark":"light"));});return h.observe(l,{attributes:true,attributeFilter:["class"]}),()=>{g.removeEventListener("change",S),h.disconnect();}},[]),t}function St(t){let o=t==="dark";return {bg:o?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:o?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:o?"#e5e5e5":"#1a1a1a",textMuted:o?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:o?"#555":"#999",border:o?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:o?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:o?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:o?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:o?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:o?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:o?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:o?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:o?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:o?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:o?"#888":"#aaa",btnHover:o?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var wt={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},kt={pending:u.circle,pass:u.check,fail:u.x,skip:u.skip},je={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)"}},Mt=t=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:o=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:t.bg,border:o?`1px solid ${t.greenBorder}`:`1px solid ${t.border}`,boxShadow:o?`0 4px 12px ${t.shadow}, 0 0 0 1px ${t.greenBorderSubtle}`:`0 4px 12px ${t.shadow}`,cursor:"pointer",fontSize:"9px",color:t.text}),card:(o,l)=>({width:`${o}px`,borderRadius:"8px",background:t.bg,border:l?`1px solid ${t.greenBorder}`:`1px solid ${t.border}`,boxShadow:l?`0 8px 24px ${t.shadow}, 0 0 0 1px ${t.greenBorderSubtle}`:`0 8px 24px ${t.shadow}`,overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:`1px solid ${t.borderSubtle}`},title:{fontSize:"10px",fontWeight:600,color:t.text,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:t.textMuted,display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:t.gripColor,display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:`1px solid ${t.borderSubtle}`},badge:o=>{let l=je[o]||je.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:l.bg,color:l.text,border:`1px solid ${l.border}`,lineHeight:"14px"}},progress:{height:"2px",background:t.borderSubtle,flexShrink:0},progressBar:o=>({height:"100%",width:`${o}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:o=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${o}15`,color:o,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${t.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(o,l)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:o?`${l}33`:"transparent",color:o?l:t.gripColor,transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:t.inputBg,border:`1px solid ${t.inputBorder}`,borderRadius:"4px",padding:"2px 6px",color:t.text,outline:"none"},humanBanner:{padding:"6px 12px",fontSize:"11px",fontWeight:600,color:t.green,borderBottom:`1px solid ${t.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",background:t.greenBg,cursor:"pointer",textDecoration:"none"}});function Tt(t){return t.split("/")[0].trim()}function Ye({config:t,appSlug:o,environment:l,seededUsers:b,authToken:x,tk:g,compact:S=false,onExpand:h}){let[y,p]=react.useState(false),[c,v]=react.useState(null),[w,E]=react.useState(null),[R,_]=react.useState(null),n=react.useCallback(async s=>{v(s),_(null);try{let C=new URLSearchParams({app_slug:o,seed_user_slug:s,environment:l}),M={apikey:t.anonKey};M.Authorization=`Bearer ${x||t.anonKey}`;let P=await fetch(`${t.serverUrl}/widget/totp-code?${C}`,{headers:M});if(!P.ok){let U=await P.json().catch(()=>({error:`HTTP ${P.status}`}));_(P.status===404?"No 2FA seed registered":U.error||"Failed");return}let D=await P.json();try{await navigator.clipboard.writeText(D.code);}catch{}E({slug:s,code:D.code}),window.setTimeout(()=>E(U=>U?.slug===s?null:U),2500),p(!1);}catch{_("Network error");}finally{v(null);}},[t.serverUrl,t.anonKey,x,o,l]);if(b.length===0)return null;if(S){let s=b.length>1;return jsxRuntime.jsxs("span",{onPointerDown:M=>M.stopPropagation(),onClick:M=>{if(M.stopPropagation(),s&&h){h();return}n(b[0]);},style:{display:"inline-flex",alignItems:"center",gap:"3px",color:g.purple,fontWeight:600,cursor:"pointer"},title:s?`${b.length} 2FA personas`:`Copy 2FA code for ${b[0]}`,children:[jsxRuntime.jsx(f,{d:u.shield,size:10}),w?jsxRuntime.jsx("span",{style:{letterSpacing:"0.1em"},children:w.code}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["2FA",s&&` \xB7${b.length}`]})]})}if(b.length===1){let s=b[0],C=c===s,M=w?.slug===s;return jsxRuntime.jsxs("button",{onClick:P=>{P.stopPropagation(),n(s);},disabled:C,style:{...Je(g.purple),cursor:C?"wait":"pointer",opacity:C?.6:1},title:R||`Copy 2FA code for ${s}`,children:[jsxRuntime.jsx(f,{d:u.shield,size:12}),M?`${w.code} \xB7 copied`:C?"\u2026":`2FA \xB7 ${s}`]})}return jsxRuntime.jsxs("span",{style:{position:"relative"},children:[jsxRuntime.jsxs("button",{onClick:s=>{s.stopPropagation(),p(C=>!C),_(null);},style:{...Je(g.purple),cursor:"pointer"},title:"Choose a persona to copy a 2FA code for",children:[jsxRuntime.jsx(f,{d:u.shield,size:12}),w?`${w.code} \xB7 copied`:`2FA \xB7 ${b.length}`,jsxRuntime.jsx(f,{d:y?u.chevronUp:u.chevronDown,size:8})]}),y&&jsxRuntime.jsxs("div",{onPointerDown:s=>s.stopPropagation(),style:{position:"absolute",bottom:"100%",left:0,marginBottom:4,background:g.bg,border:`1px solid ${g.border}`,borderRadius:6,boxShadow:`0 8px 24px ${g.shadow}`,padding:4,minWidth:180,zIndex:10},children:[b.map(s=>{let C=c===s;return jsxRuntime.jsxs("button",{onClick:M=>{M.stopPropagation(),n(s);},disabled:C,style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 8px",background:"transparent",border:"none",borderRadius:4,cursor:C?"wait":"pointer",fontSize:"10px",color:g.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},onMouseEnter:M=>M.currentTarget.style.background=g.btnHover,onMouseLeave:M=>M.currentTarget.style.background="transparent",children:[jsxRuntime.jsx(f,{d:u.shield,size:10}),jsxRuntime.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s}),C&&jsxRuntime.jsx("span",{style:{color:g.textMuted,fontSize:9},children:"\u2026"})]},s)}),R&&jsxRuntime.jsx("div",{style:{padding:"4px 8px",fontSize:9,color:g.red},children:R})]})]})}function Je(t){return {display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${t}15`,color:t,textDecoration:"none",border:`1px solid ${t}30`}}var qe="botbuddy-widget-state";function Ct({config:t,appSlug:o,environment:l,ticketId:b,testRunId:x,testRunToken:g,targetUrl:S,version:h,commitSha:y,prNumber:p,branchName:c,onNavigate:v,displayName:w="human",defaultMode:E="mini",defaultPosition:R}){let _=_t(),n=react.useMemo(()=>St(_),[_]),s=react.useMemo(()=>Mt(n),[n]),[C,M]=react.useState(false),[P,D]=react.useState(false),[U,j]=react.useState(false),Se=react.useRef(false),Xe=t.dashboardUrl||"https://app.bot-buddy.ai",T=_e(Xe),de=(()=>{try{let e=typeof window<"u"?localStorage.getItem(qe):null;if(e)return JSON.parse(e)}catch{}return null})(),[Y,F]=react.useState(de?.mode||E),[pe,re]=react.useState(""),[Ze,J]=react.useState(null),[we,ke]=react.useState(null),[Qe,et]=react.useState(new Set),[H,Me]=react.useState(""),tt=react.useCallback(e=>{et(d=>{let m=new Set(d);return m.has(e)?m.delete(e):m.add(e),m});},[]),nt=de?.x??R?.x??16,rt=de?.y??R?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:B,onPointerDown:q,onPointerMove:G,onPointerUp:X,didDrag:ce}=xe(nt,rt);react.useEffect(()=>{try{localStorage.setItem(qe,JSON.stringify({mode:Y,x:B.x,y:B.y}));}catch{}},[Y,B.x,B.y]);let Te=react.useRef(T.isAuthenticated);react.useEffect(()=>{!Te.current&&T.isAuthenticated&&F("max"),Te.current=T.isAuthenticated;},[T.isAuthenticated]);let Ce="botbuddy-widget-max-size",ot=()=>{try{let e=localStorage.getItem(Ce);if(e)return JSON.parse(e)}catch{}return {w:340,h:500}},[Z,ze]=react.useState(ot),Q=react.useRef(false),ee=react.useRef({x:0,y:0,w:0,h:0}),it=react.useCallback(e=>{e.stopPropagation(),Q.current=true,ee.current={x:e.clientX,y:e.clientY,w:Z.w,h:Z.h},e.target.setPointerCapture(e.pointerId);},[Z]),st=react.useCallback(e=>{if(!Q.current)return;let d=Math.max(280,Math.min(600,ee.current.w+(e.clientX-ee.current.x))),m=Math.max(300,Math.min(window.innerHeight*.9,ee.current.h+(e.clientY-ee.current.y)));ze({w:d,h:m});},[]),at=react.useCallback(()=>{Q.current&&(Q.current=false,ze(e=>(localStorage.setItem(Ce,JSON.stringify(e)),e)));},[]),oe=S??(typeof window<"u"?window.location.href:void 0),$e=T.displayName||w,[W,Re]=react.useState(null);react.useEffect(()=>{if(T.isAuthenticated)return;let e=new URLSearchParams;g&&e.set("token",g),b&&e.set("ticket_id",b),e.set("app_slug",o),l&&e.set("environment",l),x&&e.set("test_run_id",x),oe&&e.set("target_url",oe),h&&e.set("version",h),y&&e.set("commit_sha",y),p&&e.set("pr_number",String(p)),c&&e.set("branch_name",c),fetch(`${t.serverUrl}/widget/preview?${e}`,{headers:{apikey:t.anonKey}}).then(d=>d.json()).then(d=>Re(d)).catch(()=>Re(null));},[T.isAuthenticated,t.serverUrl,t.anonKey,o,l,b,x,g,oe,h,y,p,c]);let{run:a,widgetState:A,fetchRun:lt,setVerdict:Pe,markComplete:dt,resetRun:pt}=he({config:t,appSlug:o,environment:l,ticketId:b,testRunId:x,testRunToken:g,targetUrl:oe,version:h,commitSha:y,prNumber:p?String(p):void 0,branchName:c,authToken:T.token}),ie=react.useCallback(async(e,d,m)=>{ke(e);try{await Pe(e,d,m,$e);}finally{ke(null),J(null),re("");}},[Pe,$e]),k=a?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},ct=k.total>0&&k.pending===0,O=A==="completed",se=react.useMemo(()=>{let e=a?.test_cases||[];if(!H.trim())return e;let d=H.toLowerCase();return e.filter(m=>m.title.toLowerCase().includes(d)||m.description&&m.description.toLowerCase().includes(d)||m.url_path&&m.url_path.toLowerCase().includes(d)||m.seed_user&&m.seed_user.toLowerCase().includes(d))},[a?.test_cases,H]),Be=react.useMemo(()=>{let e=se,d=a?.test_cases||[];if(new Set(d.map($=>$.source_pr_number)).size<=1)return null;let I=[],te=new Map;e.forEach($=>{let L=$.source_pr_number;te.has(L)||te.set(L,[]),te.get(L).push($);});let ut=[...te.keys()].sort(($,L)=>$===null?1:L===null?-1:L-$);for(let $ of ut){let L=te.get($),ge={total:L.length,pass:0,fail:0,skip:0,pending:0};L.forEach(He=>{He.verdict in ge&&ge[He.verdict]++;}),I.push({key:$!=null?`pr-${$}`:"general",label:$!=null?`PR #${$}`:"General",cases:L,summary:ge});}return I.filter($=>$.cases.length>0)},[se,a?.test_cases]),Ie=k.total>0?(k.pass+k.fail)/k.total*100:0,N=l??a?.environment??null,Le=react.useMemo(()=>{if(!N||N==="production")return [];let e=a?.test_cases||[],d=new Set;for(let m of e)m.seed_user&&d.add(Tt(m.seed_user));return [...d]},[a?.test_cases,N]),ue=react.useMemo(()=>{let e=a?.auto_tooltip_seconds??W?.auto_tooltip_seconds;return e!=null&&e>0?e*1e3:5e3},[a,W]),We=A==="ready"||A==="completed"||W?.enabled&&W.run;react.useEffect(()=>{if(!We||Se.current||ue<=0)return;Se.current=true,D(true);let e=window.setTimeout(()=>D(false),ue);return ()=>window.clearTimeout(e)},[We,ue]);let Ee=e=>jsxRuntime.jsxs("div",{style:s.caseRow,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsx("div",{style:{marginTop:"2px",flexShrink:0,color:wt[e.verdict]},children:we===e.id?jsxRuntime.jsx(f,{d:u.loader,className:""}):jsxRuntime.jsx(f,{d:kt[e.verdict],className:""})}),jsxRuntime.jsxs("div",{style:{minWidth:0,flex:1},children:[jsxRuntime.jsx("div",{style:{fontSize:"10px",color:n.text,lineHeight:1.3},children:e.title}),e.description&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:n.gripColor,marginTop:"2px"},children:e.description}),e.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(f,{d:u.key,size:10}),jsxRuntime.jsx("span",{children:e.seed_user})]}),e.url_path&&jsxRuntime.jsxs("a",{href:e.url_path,target:"_blank",rel:"noopener noreferrer",onClick:d=>{d.stopPropagation(),v&&(d.preventDefault(),v(e.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(f,{d:u.externalLink,size:10}),e.url_path]}),e.verdict==="fail"&&e.fail_reason&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:n.red,marginTop:"2px"},children:["\u2717 ",e.fail_reason]})]})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(d=>jsxRuntime.jsx("button",{onClick:()=>{if(e.verdict===d){ie(e.id,"pending"),J(null);return}if(d==="fail"){J(e.id),re("");return}J(null),ie(e.id,d);},disabled:we!==null,style:s.verdictBtn(e.verdict===d,d==="pass"?n.green:d==="fail"?n.red:n.amber),children:d.toUpperCase()},d)),e.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(f,{d:u.bot,size:8}),e.created_by_agent_name]}),e.verdict_by_display_name&&jsxRuntime.jsxs("span",{style:{fontSize:"8px",color:n.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[e.verdict_by_display_name,e.verdict_at&&jsxRuntime.jsx("span",{style:{opacity:.7},children:vt(e.verdict_at)})]})]}),Ze===e.id&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:pe,onChange:d=>re(d.target.value),onKeyDown:d=>{d.key==="Enter"&&ie(e.id,"fail",pe.trim()||void 0),d.key==="Escape"&&(J(null),re(""));},placeholder:"Reason (optional)...",style:s.input}),jsxRuntime.jsx("button",{onClick:()=>{ie(e.id,"fail",pe.trim()||void 0);},style:s.verdictBtn(true,n.red),children:"\u2713"})]})]},e.id);if((A==="no-match"||A==="loading")&&!(!T.isAuthenticated&&W?.enabled&&W.run))return null;if(!T.isAuthenticated&&W?.enabled&&W.run){let e=W.run,d=e.summary,m=e.status==="completed";return jsxRuntime.jsx("div",{style:{...s.root,left:B.x,top:B.y},children:jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>M(true),onMouseLeave:()=>{M(false),j(false);},children:[jsxRuntime.jsxs("div",{style:{...s.pill(m),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:q,onPointerMove:G,onPointerUp:()=>{X();},children:[jsxRuntime.jsx(f,{d:u.grip,size:10,className:""}),e.ticket_id&&e.ticket_url?jsxRuntime.jsx("a",{href:e.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:I=>I.stopPropagation(),style:{color:n.amber,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:e.ticket_id}):null,e.pr_url?jsxRuntime.jsxs("a",{href:e.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:I=>I.stopPropagation(),style:{color:n.blue,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:["PR#",e.pr_number??e.pr_id]}):null,e.created_by_agent_name?e.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${e.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",onClick:I=>I.stopPropagation(),style:{color:n.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(f,{d:u.terminal,size:10}),e.created_by_agent_name]}):jsxRuntime.jsxs("span",{style:{color:n.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(f,{d:u.bot,size:10}),e.created_by_agent_name]}):null,jsxRuntime.jsxs("span",{style:m?{color:n.green}:void 0,children:[d.pass,"/",d.total]}),d.fail>0&&jsxRuntime.jsxs("span",{style:{color:n.red},children:[d.fail,"\u2717"]}),jsxRuntime.jsx("span",{onClick:I=>{I.stopPropagation(),T.openLogin();},style:{color:n.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!U&&(C||P)&&e.title&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"220px",maxWidth:"320px",padding:"10px 14px",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:"13px",fontWeight:700,color:n.text,lineHeight:1.3},children:e.title}),(e.description||e.intro_notes)&&jsxRuntime.jsx("div",{style:{fontSize:"11px",color:n.textMuted,marginTop:"6px",lineHeight:1.4},children:e.description||e.intro_notes}),jsxRuntime.jsx("div",{style:{marginTop:"6px",fontSize:"9px",color:n.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!T.isAuthenticated)return jsxRuntime.jsxs("div",{style:{...s.root,left:B.x,top:B.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:q,onPointerMove:G,onPointerUp:X,children:[jsxRuntime.jsx("div",{style:{...s.handle,borderBottom:"none"},children:jsxRuntime.jsxs("div",{style:s.sub,children:[jsxRuntime.jsx(f,{d:u.grip,size:10,className:""}),jsxRuntime.jsx(f,{d:u.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"}),jsxRuntime.jsx("button",{onClick:e=>{e.stopPropagation(),T.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"})]})]});let De=()=>{ce.current||(D(false),F(e=>{let d=e==="mini"?"max":"mini";return j(d==="mini"),d}));},Ue=({icon:e,onClick:d})=>jsxRuntime.jsx("button",{style:s.btn,onClick:m=>{m.stopPropagation(),d(m);},children:jsxRuntime.jsx(f,{d:e,className:""})}),Ae=()=>{if(!a?.assigned_human_display_name)return null;let e=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:n.green,display:"inline-block",flexShrink:0,boxShadow:`0 0 6px ${n.green}66`}}),jsxRuntime.jsx(f,{d:u.user,size:13}),jsxRuntime.jsx("span",{style:{flex:1},children:a.assigned_human_display_name}),a.codex_thread_id&&jsxRuntime.jsx(f,{d:u.externalLink,size:10})]});return a.codex_thread_id?jsxRuntime.jsx("a",{href:`codex://threads/${a.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:s.humanBanner,children:e}):jsxRuntime.jsx("div",{style:s.humanBanner,children:e})},Ne=()=>jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${n.borderSubtle}`,flexShrink:0},children:[a?.pr_url&&jsxRuntime.jsxs("a",{href:a.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...s.link(n.blue),textDecoration:"none"},children:[jsxRuntime.jsx(f,{d:u.pr,size:12}),a.pr_number?`PR#${a.pr_number}`:a.pr_id||"PR",jsxRuntime.jsx(f,{d:u.externalLink,size:8})]}),a?.ticket_url&&jsxRuntime.jsxs("a",{href:a.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...s.link(n.amber),textDecoration:"none"},children:[jsxRuntime.jsx(f,{d:u.ticket,size:12}),a.ticket_id||"Ticket",jsxRuntime.jsx(f,{d:u.externalLink,size:8})]}),a?.created_by_agent_name&&(a.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${a.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...s.link(n.purple),textDecoration:"none"},children:[jsxRuntime.jsx(f,{d:u.bot,size:12}),a.created_by_agent_name,jsxRuntime.jsx(f,{d:u.externalLink,size:8})]}):jsxRuntime.jsxs("span",{style:{...s.link(n.purple)},children:[jsxRuntime.jsx(f,{d:u.bot,size:12}),a.created_by_agent_name]})),N&&jsxRuntime.jsx(Ye,{config:t,appSlug:o,environment:N,seededUsers:Le,authToken:T.token,tk:n}),jsxRuntime.jsx("span",{style:{...s.badge(a?.environment||"custom"),marginLeft:"auto"},children:a?.environment})]}),Fe=()=>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("0.5.10");},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.jsx("span",{style:{color:n.versionNum},children:"v0.5.10"})]}),T.isAuthenticated&&jsxRuntime.jsx("button",{onClick:e=>{e.stopPropagation(),T.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",{style:{...s.root,left:B.x,top:B.y},children:[Y==="mini"&&jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>M(true),onMouseLeave:()=>{M(false),j(false);},children:[jsxRuntime.jsxs("div",{style:{...s.pill(O),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:q,onPointerMove:G,onPointerUp:()=>{X(),ce.current||De();},children:[jsxRuntime.jsx(f,{d:u.grip,size:10,className:""}),a?.ticket_id&&jsxRuntime.jsx("span",{style:{color:n.amber,fontWeight:600},children:a.ticket_id}),a?.pr_number&&jsxRuntime.jsxs("span",{style:{color:n.blue,fontWeight:600},children:["PR#",a.pr_number]}),a?.created_by_agent_name&&(a.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${a.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),style:{color:n.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px",textDecoration:"none",cursor:"pointer"},children:[jsxRuntime.jsx(f,{d:u.terminal,size:10}),a.created_by_agent_name,jsxRuntime.jsx(f,{d:u.externalLink,size:8})]}):jsxRuntime.jsxs("span",{style:{color:n.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsxRuntime.jsx(f,{d:u.bot,size:10}),a.created_by_agent_name]})),jsxRuntime.jsxs("span",{style:O?{color:n.green}:void 0,children:[k.pass,"/",k.total]}),k.fail>0&&jsxRuntime.jsxs("span",{style:{color:n.red},children:[k.fail,"\u2717"]}),N&&jsxRuntime.jsx(Ye,{config:t,appSlug:o,environment:N,seededUsers:Le,authToken:T.token,tk:n,compact:true,onExpand:()=>F("expanded")})]}),!U&&(C||P)&&a?.title&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"220px",maxWidth:"320px",padding:"10px 14px",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:"13px",fontWeight:700,color:n.text,lineHeight:1.3},children:a.title}),(a.description||a.intro_notes)&&jsxRuntime.jsx("div",{style:{fontSize:"11px",color:n.textMuted,marginTop:"6px",lineHeight:1.4},children:a.description||a.intro_notes})]})]}),Y==="expanded"&&jsxRuntime.jsxs("div",{style:s.card(300,O),children:[jsxRuntime.jsx(Ae,{}),jsxRuntime.jsxs("div",{style:s.handle,onPointerDown:q,onPointerMove:G,onPointerUp:X,onClick:De,children:[jsxRuntime.jsx(f,{d:u.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:s.title,children:a?.title}),jsxRuntime.jsx("div",{style:s.sub,children:a?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",a.branch_name]})})]}),jsxRuntime.jsx(f,{d:u.chevronUp,className:""}),jsxRuntime.jsx(Ue,{icon:u.minus,onClick:()=>{D(false),j(true),F("mini");}})]}),jsxRuntime.jsxs("div",{style:s.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})]}),a?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:n.gripColor,borderBottom:`1px solid ${n.borderSubtle}`,flexShrink:0},children:a.description}),jsxRuntime.jsx(Ne,{}),jsxRuntime.jsx(Fe,{}),jsxRuntime.jsx("div",{style:s.progress,children:jsxRuntime.jsx("div",{style:s.progressBar(Ie)})})]}),Y==="max"&&jsxRuntime.jsxs("div",{style:{...s.card(Z.w,O),height:Z.h,position:"relative"},children:[jsxRuntime.jsx(Ae,{}),jsxRuntime.jsxs("div",{style:s.handle,onPointerDown:q,onPointerMove:G,onPointerUp:X,onClick:()=>{ce.current||F("expanded");},children:[jsxRuntime.jsx(f,{d:u.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:s.title,children:a?.title}),jsxRuntime.jsx("div",{style:s.sub,children:a?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",a.branch_name]})})]}),jsxRuntime.jsx(f,{d:u.chevronDown,className:""}),jsxRuntime.jsx(Ue,{icon:u.minus,onClick:()=>{D(false),j(true),F("mini");}})]}),jsxRuntime.jsxs("div",{style:s.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})]}),(a?.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(f,{d:u.search,size:11,className:""}),jsxRuntime.jsx("input",{value:H,onChange:e=>Me(e.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:n.text,fontFamily:"monospace"}}),H&&jsxRuntime.jsx("button",{onClick:()=>Me(""),style:{background:"none",border:"none",cursor:"pointer",color:n.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),A==="error"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsxRuntime.jsx(f,{d:u.alert,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:n.red},children:"Failed to load"}),jsxRuntime.jsx("button",{onClick:lt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),O&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg},children:[jsxRuntime.jsx(f,{d:u.checkAll,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",color:n.green,flex:1},children:"Run completed"}),jsxRuntime.jsx("button",{onClick:pt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),a?.intro_notes&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${n.borderSubtle}`,fontSize:"10px",color:n.textMuted,fontStyle:"italic",flexShrink:0},children:a.intro_notes}),A!=="error"&&jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(a?.test_cases||[]).length===0?jsxRuntime.jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:"No test cases"}):se.length===0?jsxRuntime.jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:['No matches for "',H,'"']}):Be?Be.map(e=>{let d=Qe.has(e.key);return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("button",{onClick:()=>tt(e.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(f,{d:d?u.chevronDown:u.chevronUp,size:10,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",fontWeight:700,color:n.blue,flex:1,textAlign:"left"},children:e.label}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:n.green},children:[e.summary.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:n.red},children:[e.summary.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:n.gripColor},children:[e.summary.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{fontSize:"9px",color:n.textFaint},children:e.summary.total})]}),!d&&e.cases.map(m=>Ee(m))]},e.key)}):se.map(e=>Ee(e))}),ct&&!O&&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:dt,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"})]}),jsxRuntime.jsx(Ne,{}),jsxRuntime.jsx(Fe,{}),jsxRuntime.jsx("div",{style:s.progress,children:jsxRuntime.jsx("div",{style:s.progressBar(Ie)})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:0,right:0,width:16,height:16,cursor:"se-resize",zIndex:10,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:"2px",opacity:.3},onPointerDown:it,onPointerMove:st,onPointerUp:at,onPointerEnter:e=>e.currentTarget.style.opacity="0.7",onPointerLeave:e=>{Q.current||(e.currentTarget.style.opacity="0.3");},children:jsxRuntime.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsxRuntime.jsx("path",{d:"M7 1v6H1",fill:"none",stroke:n.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}
2
+ exports.TestRunWidget=Ct;exports.useDraggable=xe;exports.useRealtimeRefresh=me;exports.useTestRun=he;exports.useWidgetAuth=_e;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import {useState,useRef,useCallback,useEffect,useMemo}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';function xe(t,o){let[s,b]=useState({x:t,y:o}),m=useRef(false),f=useRef({x:0,y:0}),x=useRef(false),y=useCallback(l=>{m.current=true,x.current=false,f.current={x:l.clientX-s.x,y:l.clientY-s.y},l.target.setPointerCapture(l.pointerId);},[s]),v=useCallback(l=>{m.current&&(x.current=true,b({x:l.clientX-f.current.x,y:l.clientY-f.current.y}));},[]),u=useCallback(()=>{m.current=false;},[]);return {pos:s,onPointerDown:y,onPointerMove:v,onPointerUp:u,didDrag:x}}function me(t,o,s){let b=useRef(s);b.current=s,useEffect(()=>{if(!o)return;if(t.supabaseUrl){let f=t.supabaseUrl.replace(/^https:\/\//,"wss://").replace(/^http:\/\//,"ws://"),x=null,y=null,v=null,u=false,l=0,_=()=>{if(!u){try{x=new WebSocket(`${f}/realtime/v1/websocket?apikey=${t.anonKey}&vsn=1.0.0`);}catch{R();return}x.onopen=()=>{if(u||!x)return;let T={topic:`realtime:public:test_run_cases:test_run_id=eq.${o}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_run_cases",filter:`test_run_id=eq.${o}`}]}},ref:String(++l)};x.send(JSON.stringify(T));let n={topic:`realtime:public:test_runs:id=eq.${o}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_runs",filter:`id=eq.${o}`}]}},ref:String(++l)};x.send(JSON.stringify(n)),y=setInterval(()=>{x?.readyState===WebSocket.OPEN&&x.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++l)}));},3e4);},x.onmessage=T=>{try{JSON.parse(T.data).event==="postgres_changes"&&b.current();}catch{}},x.onclose=()=>{M(),u||(v=setTimeout(_,3e3));},x.onerror=()=>{x?.close();};}},M=()=>{y&&(clearInterval(y),y=null);},C=null,R=()=>{u||(C=setInterval(()=>b.current(),15e3));};return _(),()=>{u=true,M(),v&&clearTimeout(v),C&&clearInterval(C),x&&(x.onclose=null,x.onerror=null,x.close());}}let m=setInterval(()=>b.current(),15e3);return ()=>clearInterval(m)},[t.supabaseUrl,t.anonKey,o]);}function se(t,o){let s={apikey:t.anonKey};return o?s.Authorization=`Bearer ${o}`:t.apiKey?s.Authorization=`Bearer ${t.apiKey}`:s.Authorization=`Bearer ${t.anonKey}`,s}async function ct(t){if(t)return t;try{let o=await fetch("/.botbuddy-token",{cache:"no-store"});if(o.ok){let s=(await o.text()).trim();if(s.startsWith("public_"))return s}}catch{}try{let o=import.meta?.env?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(o&&typeof o=="string"&&o.startsWith("public_"))return o}catch{}return null}function be(t){let[o,s]=useState(null),[b,m]=useState("loading"),f=useCallback(async()=>{try{let u=await ct(t.testRunToken);if(!u){m("no-match"),s(null);return}if(!t.ticketId){m("no-match"),s(null);return}let l=new URLSearchParams;l.set("token",u),l.set("ticket_id",t.ticketId),l.set("app_slug",t.appSlug),t.environment&&l.set("environment",t.environment),t.testRunId&&l.set("test_run_id",t.testRunId),t.targetUrl&&l.set("target_url",t.targetUrl),t.version&&l.set("version",t.version),t.commitSha&&l.set("commit_sha",t.commitSha),t.prNumber&&l.set("pr_number",String(t.prNumber)),t.branchName&&l.set("branch_name",t.branchName);let _=await fetch(`${t.config.serverUrl}/widget/test-run?${l.toString()}`,{headers:se(t.config,t.authToken)});if(_.status===404){m("no-match"),s(null);return}if(_.status===401||_.status===403){m("error");return}if(!_.ok){m("error");return}let M=await _.json();s(M),m(M.status==="completed"?"completed":"ready");}catch{m("error");}},[t.config.serverUrl,t.config.anonKey,t.config.apiKey,t.authToken,t.appSlug,t.environment,t.ticketId,t.testRunId,t.testRunToken,t.targetUrl,t.version,t.commitSha,t.branchName,t.prNumber]);return useEffect(()=>{f();},[f]),me(t.config,o?.id,f),{run:o,widgetState:b,fetchRun:f,setVerdict:async(u,l,_,M="human")=>(s(R=>{if(!R)return null;let T=R.test_cases.map(d=>d.id===u?{...d,verdict:l,fail_reason:l==="fail"&&_||null,verdict_by_display_name:M,verdict_at:new Date().toISOString()}:d),n={total:T.length,pending:0,pass:0,fail:0,skip:0};return T.forEach(d=>{d.verdict in n&&n[d.verdict]++;}),{...R,test_cases:T,summary:n}}),(await fetch(`${t.config.serverUrl}/widget/test-cases/${u}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...se(t.config,t.authToken)},body:JSON.stringify({verdict:l,fail_reason:_,display_name:M})})).ok),markComplete:async()=>o?(s(l=>l?{...l,status:"completed"}:null),m("completed"),(await fetch(`${t.config.serverUrl}/widget/test-runs/${o.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...se(t.config,t.authToken)}})).ok):false,resetRun:async()=>{if(!o)return false;let u=await fetch(`${t.config.serverUrl}/widget/test-runs/${o.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...se(t.config,t.authToken)}});return u.ok&&f(),u.ok},setRun:s}}var ye="botbuddy-widget-auth-token",he="botbuddy-widget-auth-name";function ve(t){let[o,s]=useState(()=>{try{return localStorage.getItem(ye)}catch(y){return console.warn("Unable to read BotBuddy widget auth token",y),null}}),[b,m]=useState(()=>{try{return localStorage.getItem(he)}catch(y){return console.warn("Unable to read BotBuddy widget display name",y),null}});useEffect(()=>{let y=new URL(t).origin,v=u=>{if(u.origin===y&&u.data?.type==="botbuddy-widget-auth"&&u.data.token){let{token:l,displayName:_}=u.data;s(l),m(_||"human");try{localStorage.setItem(ye,l),_&&localStorage.setItem(he,_);}catch(M){console.warn("Unable to persist BotBuddy widget auth token",M);}}};return window.addEventListener("message",v),()=>window.removeEventListener("message",v)},[t]);let f=useCallback(()=>{let y=new URL("/widget-auth",t);y.searchParams.set("origin",window.location.origin);let v=420,u=520,l=window.screenX+(window.innerWidth-v)/2,_=window.screenY+(window.innerHeight-u)/2;window.open(y.toString(),"botbuddy-auth",`width=${v},height=${u},left=${l},top=${_},popup=yes`);},[t]),x=useCallback(()=>{s(null),m(null);try{localStorage.removeItem(ye),localStorage.removeItem(he);}catch(y){console.warn("Unable to clear BotBuddy widget auth token",y);}},[]);return {token:o,displayName:b,isAuthenticated:!!o,openLogin:f,logout:x}}function gt(t){let o=new Date(t),b=Date.now()-o.getTime();if(b<6e4)return "just now";if(b<36e5)return `${Math.floor(b/6e4)}m ago`;if(b<864e5)return `${Math.floor(b/36e5)}h ago`;let m=o.getDate(),f=o.toLocaleString("en",{month:"short"}),x=o.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${f} ${m}, ${x}`}var g=({d:t,className:o,size:s=14})=>jsx("svg",{className:o,width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:t})}),c={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",user:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2M12 3a4 4 0 1 0 0 8 4 4 0 0 0 0-8",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 ft(){let[t,o]=useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return useEffect(()=>{if(typeof window>"u")return;let s=document.documentElement,b=()=>s.classList.contains("dark")?"dark":s.classList.contains("light")?"light":null,m=b();m&&o(m);let f=window.matchMedia("(prefers-color-scheme: dark)"),x=v=>{let u=b();o(u||(v.matches?"dark":"light"));};f.addEventListener("change",x);let y=new MutationObserver(()=>{let v=b();o(v||(f.matches?"dark":"light"));});return y.observe(s,{attributes:true,attributeFilter:["class"]}),()=>{f.removeEventListener("change",x),y.disconnect();}},[]),t}function xt(t){let o=t==="dark";return {bg:o?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:o?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:o?"#e5e5e5":"#1a1a1a",textMuted:o?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:o?"#555":"#999",border:o?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:o?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:o?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:o?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:o?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:o?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:o?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:o?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:o?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:o?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:o?"#888":"#aaa",btnHover:o?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var mt={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},bt={pending:c.circle,pass:c.check,fail:c.x,skip:c.skip},Oe={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)"}},yt=t=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:o=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:t.bg,border:o?`1px solid ${t.greenBorder}`:`1px solid ${t.border}`,boxShadow:o?`0 4px 12px ${t.shadow}, 0 0 0 1px ${t.greenBorderSubtle}`:`0 4px 12px ${t.shadow}`,cursor:"pointer",fontSize:"9px",color:t.text}),card:(o,s)=>({width:`${o}px`,borderRadius:"8px",background:t.bg,border:s?`1px solid ${t.greenBorder}`:`1px solid ${t.border}`,boxShadow:s?`0 8px 24px ${t.shadow}, 0 0 0 1px ${t.greenBorderSubtle}`:`0 8px 24px ${t.shadow}`,overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:`1px solid ${t.borderSubtle}`},title:{fontSize:"10px",fontWeight:600,color:t.text,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:t.textMuted,display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:t.gripColor,display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:`1px solid ${t.borderSubtle}`},badge:o=>{let s=Oe[o]||Oe.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:t.borderSubtle,flexShrink:0},progressBar:o=>({height:"100%",width:`${o}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:o=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${o}15`,color:o,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${t.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(o,s)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:o?`${s}33`:"transparent",color:o?s:t.gripColor,transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:t.inputBg,border:`1px solid ${t.inputBorder}`,borderRadius:"4px",padding:"2px 6px",color:t.text,outline:"none"},humanBanner:{padding:"6px 12px",fontSize:"11px",fontWeight:600,color:t.green,borderBottom:`1px solid ${t.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",background:t.greenBg,cursor:"pointer",textDecoration:"none"}});function ht({config:t,appSlug:o,environment:s,seedUserSlug:b,authToken:m,tk:f}){let[x,y]=useState(null),[v,u]=useState(0),[l,_]=useState(false),[M,C]=useState(null),[R,T]=useState(false),n=useRef(null),d=useMemo(()=>b.split("/")[0].trim(),[b]),K=useCallback(async()=>{_(true),C(null);try{let $=new URLSearchParams({app_slug:o,seed_user_slug:d,environment:s}),E={apikey:t.anonKey};m?E.Authorization=`Bearer ${m}`:E.Authorization=`Bearer ${t.anonKey}`;let B=await fetch(`${t.serverUrl}/widget/totp-code?${$}`,{headers:E});if(!B.ok){let w=await B.json().catch(()=>({error:"Failed"}));if(B.status===404){C("No 2FA seed registered");return}C(w.error||"Failed to get code");return}let U=await B.json();y(U.code),u(U.remaining_seconds);try{await navigator.clipboard.writeText(U.code),T(!0),setTimeout(()=>T(!1),2e3);}catch{}n.current&&clearInterval(n.current);let V=U.remaining_seconds;n.current=setInterval(()=>{V--,V<=0?(n.current&&clearInterval(n.current),K()):u(V);},1e3);}catch{C("Network error");}finally{_(false);}},[t.serverUrl,t.anonKey,m,o,d,s]);return useEffect(()=>()=>{n.current&&clearInterval(n.current);},[]),M==="No 2FA seed registered"?null:x?jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"3px"},children:[jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"3px 8px",borderRadius:"4px",background:`${f.purple}15`,border:`1px solid ${f.purple}40`,fontSize:"12px",fontFamily:"ui-monospace, monospace",fontWeight:700,color:f.purple,letterSpacing:"0.15em"},children:[jsx(g,{d:c.shield,size:11}),jsx("span",{children:x}),jsxs("span",{style:{fontSize:"8px",fontWeight:400,color:f.textMuted,letterSpacing:"0"},children:[v,"s"]})]}),jsx("button",{onClick:$=>{$.stopPropagation(),navigator.clipboard.writeText(x).then(()=>{T(true),setTimeout(()=>T(false),1500);});},style:{padding:"2px",background:"none",border:"none",cursor:"pointer",color:R?f.green:f.gripColor,fontSize:"8px"},title:"Copy code",children:R?jsx(g,{d:c.check,size:10}):jsx(g,{d:c.copy,size:10})})]}):jsxs("button",{onClick:$=>{$.stopPropagation(),K();},disabled:l,style:{display:"inline-flex",alignItems:"center",gap:"4px",marginTop:"3px",fontSize:"8px",padding:"2px 6px",borderRadius:"4px",background:`${f.purple}12`,color:f.purple,border:`1px solid ${f.purple}30`,cursor:l?"wait":"pointer",opacity:l?.6:1},children:[jsx(g,{d:c.shield,size:9}),l?"generating...":M||"Get 2FA code"]})}var Ke="botbuddy-widget-state";function vt({config:t,appSlug:o,environment:s,ticketId:b,testRunId:m,testRunToken:f,targetUrl:x,version:y,commitSha:v,prNumber:u,branchName:l,onNavigate:_,displayName:M="human",defaultMode:C="mini",defaultPosition:R}){let T=ft(),n=useMemo(()=>xt(T),[T]),d=useMemo(()=>yt(n),[n]),[K,$]=useState(false),[E,B]=useState(false),U=useRef(false),V=t.dashboardUrl||"https://app.bot-buddy.ai",w=ve(V),le=(()=>{try{let e=typeof window<"u"?localStorage.getItem(Ke):null;if(e)return JSON.parse(e)}catch{}return null})(),[j,Y]=useState(le?.mode||C),[de,re]=useState(""),[Ve,J]=useState(null),[_e,Se]=useState(null),[je,Ye]=useState(new Set),[N,we]=useState(""),Je=useCallback(e=>{Ye(p=>{let h=new Set(p);return h.has(e)?h.delete(e):h.add(e),h});},[]),Ge=le?.x??R?.x??16,qe=le?.y??R?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:P,onPointerDown:G,onPointerMove:q,onPointerUp:X,didDrag:pe}=xe(Ge,qe);useEffect(()=>{try{localStorage.setItem(Ke,JSON.stringify({mode:j,x:P.x,y:P.y}));}catch{}},[j,P.x,P.y]);let ke=useRef(w.isAuthenticated);useEffect(()=>{!ke.current&&w.isAuthenticated&&Y("max"),ke.current=w.isAuthenticated;},[w.isAuthenticated]);let Me="botbuddy-widget-max-size",Xe=()=>{try{let e=localStorage.getItem(Me);if(e)return JSON.parse(e)}catch{}return {w:340,h:500}},[Z,Te]=useState(Xe),Q=useRef(false),ee=useRef({x:0,y:0,w:0,h:0}),Ze=useCallback(e=>{e.stopPropagation(),Q.current=true,ee.current={x:e.clientX,y:e.clientY,w:Z.w,h:Z.h},e.target.setPointerCapture(e.pointerId);},[Z]),Qe=useCallback(e=>{if(!Q.current)return;let p=Math.max(280,Math.min(600,ee.current.w+(e.clientX-ee.current.x))),h=Math.max(300,Math.min(window.innerHeight*.9,ee.current.h+(e.clientY-ee.current.y)));Te({w:p,h});},[]),et=useCallback(()=>{Q.current&&(Q.current=false,Te(e=>(localStorage.setItem(Me,JSON.stringify(e)),e)));},[]),oe=x??(typeof window<"u"?window.location.href:void 0),ze=w.displayName||M,[W,Ce]=useState(null);useEffect(()=>{if(w.isAuthenticated)return;let e=new URLSearchParams;f&&e.set("token",f),b&&e.set("ticket_id",b),e.set("app_slug",o),s&&e.set("environment",s),m&&e.set("test_run_id",m),oe&&e.set("target_url",oe),y&&e.set("version",y),v&&e.set("commit_sha",v),u&&e.set("pr_number",String(u)),l&&e.set("branch_name",l),fetch(`${t.serverUrl}/widget/preview?${e}`,{headers:{apikey:t.anonKey}}).then(p=>p.json()).then(p=>Ce(p)).catch(()=>Ce(null));},[w.isAuthenticated,t.serverUrl,t.anonKey,o,s,b,m,f,oe,y,v,u,l]);let{run:a,widgetState:D,fetchRun:tt,setVerdict:Re,markComplete:nt,resetRun:rt}=be({config:t,appSlug:o,environment:s,ticketId:b,testRunId:m,testRunToken:f,targetUrl:oe,version:y,commitSha:v,prNumber:u?String(u):void 0,branchName:l,authToken:w.token}),ie=useCallback(async(e,p,h)=>{Se(e);try{await Re(e,p,h,ze);}finally{Se(null),J(null),re("");}},[Re,ze]),S=a?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},ot=S.total>0&&S.pending===0,A=D==="completed",ae=useMemo(()=>{let e=a?.test_cases||[];if(!N.trim())return e;let p=N.toLowerCase();return e.filter(h=>h.title.toLowerCase().includes(p)||h.description&&h.description.toLowerCase().includes(p)||h.url_path&&h.url_path.toLowerCase().includes(p)||h.seed_user&&h.seed_user.toLowerCase().includes(p))},[a?.test_cases,N]),$e=useMemo(()=>{let e=ae,p=a?.test_cases||[];if(new Set(p.map(z=>z.source_pr_number)).size<=1)return null;let I=[],te=new Map;e.forEach(z=>{let L=z.source_pr_number;te.has(L)||te.set(L,[]),te.get(L).push(z);});let it=[...te.keys()].sort((z,L)=>z===null?1:L===null?-1:L-z);for(let z of it){let L=te.get(z),ue={total:L.length,pass:0,fail:0,skip:0,pending:0};L.forEach(Ne=>{Ne.verdict in ue&&ue[Ne.verdict]++;}),I.push({key:z!=null?`pr-${z}`:"general",label:z!=null?`PR #${z}`:"General",cases:L,summary:ue});}return I.filter(z=>z.cases.length>0)},[ae,a?.test_cases]),Be=S.total>0?(S.pass+S.fail)/S.total*100:0,ce=useMemo(()=>{let e=a?.auto_tooltip_seconds??W?.auto_tooltip_seconds;return e!=null&&e>0?e*1e3:5e3},[a,W]),Pe=D==="ready"||D==="completed"||W?.enabled&&W.run;useEffect(()=>{if(!Pe||U.current||ce<=0)return;U.current=true,B(true);let e=window.setTimeout(()=>B(false),ce);return ()=>window.clearTimeout(e)},[Pe,ce]);let Ie=e=>jsxs("div",{style:d.caseRow,children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsx("div",{style:{marginTop:"2px",flexShrink:0,color:mt[e.verdict]},children:_e===e.id?jsx(g,{d:c.loader,className:""}):jsx(g,{d:bt[e.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:n.text,lineHeight:1.3},children:e.title}),e.description&&jsx("div",{style:{fontSize:"9px",color:n.gripColor,marginTop:"2px"},children:e.description}),e.seed_user&&jsxs("div",{children:[jsxs("div",{style:{fontSize:"9px",color:n.amber,marginTop:"3px",display:"flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",background:`${n.amber}12`,border:`1px solid ${n.amber}30`},children:[jsx(g,{d:c.key,size:10}),jsx("span",{children:e.seed_user})]}),(s??a?.environment)!=="production"&&(s??a?.environment)&&jsx(ht,{config:t,appSlug:o,environment:s??a?.environment,seedUserSlug:e.seed_user,authToken:w.token,tk:n})]}),e.url_path&&jsxs("a",{href:e.url_path,target:"_blank",rel:"noopener noreferrer",onClick:p=>{p.stopPropagation(),_&&(p.preventDefault(),_(e.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(g,{d:c.externalLink,size:10}),e.url_path]}),e.verdict==="fail"&&e.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:n.red,marginTop:"2px"},children:["\u2717 ",e.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(e.verdict===p){ie(e.id,"pending"),J(null);return}if(p==="fail"){J(e.id),re("");return}J(null),ie(e.id,p);},disabled:_e!==null,style:d.verdictBtn(e.verdict===p,p==="pass"?n.green:p==="fail"?n.red:n.amber),children:p.toUpperCase()},p)),e.created_by_agent_name&&jsxs("span",{style:{fontSize:"8px",color:n.purple,marginLeft:"4px",display:"inline-flex",alignItems:"center",gap:"2px"},children:[jsx(g,{d:c.bot,size:8}),e.created_by_agent_name]}),e.verdict_by_display_name&&jsxs("span",{style:{fontSize:"8px",color:n.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[e.verdict_by_display_name,e.verdict_at&&jsx("span",{style:{opacity:.7},children:gt(e.verdict_at)})]})]}),Ve===e.id&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:de,onChange:p=>re(p.target.value),onKeyDown:p=>{p.key==="Enter"&&ie(e.id,"fail",de.trim()||void 0),p.key==="Escape"&&(J(null),re(""));},placeholder:"Reason (optional)...",style:d.input}),jsx("button",{onClick:()=>{ie(e.id,"fail",de.trim()||void 0);},style:d.verdictBtn(true,n.red),children:"\u2713"})]})]},e.id);if((D==="no-match"||D==="loading")&&!(!w.isAuthenticated&&W?.enabled&&W.run))return null;if(!w.isAuthenticated&&W?.enabled&&W.run){let e=W.run,p=e.summary,h=e.status==="completed";return jsx("div",{style:{...d.root,left:P.x,top:P.y},children:jsxs("div",{style:{position:"relative"},onMouseEnter:()=>$(true),onMouseLeave:()=>$(false),children:[jsxs("div",{style:{...d.pill(h),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:G,onPointerMove:q,onPointerUp:()=>{X();},children:[jsx(g,{d:c.grip,size:10,className:""}),e.ticket_id&&e.ticket_url?jsx("a",{href:e.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:I=>I.stopPropagation(),style:{color:n.amber,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:e.ticket_id}):null,e.pr_url?jsxs("a",{href:e.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:I=>I.stopPropagation(),style:{color:n.blue,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:["PR#",e.pr_number??e.pr_id]}):null,e.created_by_agent_name?e.codex_thread_id?jsxs("a",{href:`codex://threads/${e.codex_thread_id}`,onClick:I=>I.stopPropagation(),style:{color:n.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(g,{d:c.terminal,size:10}),e.created_by_agent_name]}):jsxs("span",{style:{color:n.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(g,{d:c.bot,size:10}),e.created_by_agent_name]}):null,jsxs("span",{style:h?{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:I=>{I.stopPropagation(),w.openLogin();},style:{color:n.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),(K||E)&&e.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"220px",maxWidth:"320px",padding:"10px 14px",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:"13px",fontWeight:700,color:n.text,lineHeight:1.3},children:e.title}),(e.description||e.intro_notes)&&jsx("div",{style:{fontSize:"11px",color:n.textMuted,marginTop:"6px",lineHeight:1.4},children:e.description||e.intro_notes}),jsx("div",{style:{marginTop:"6px",fontSize:"9px",color:n.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!w.isAuthenticated)return jsxs("div",{style:{...d.root,left:P.x,top:P.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:G,onPointerMove:q,onPointerUp:X,children:[jsx("div",{style:{...d.handle,borderBottom:"none"},children:jsxs("div",{style:d.sub,children:[jsx(g,{d:c.grip,size:10,className:""}),jsx(g,{d:c.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"}),jsx("button",{onClick:e=>{e.stopPropagation(),w.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"})]})]});let Le=()=>{pe.current||(B(false),Y(e=>e==="mini"?"max":"mini"));},We=({icon:e,onClick:p})=>jsx("button",{style:d.btn,onClick:h=>{h.stopPropagation(),p(h);},children:jsx(g,{d:e,className:""})}),Ue=()=>{if(!a?.assigned_human_display_name)return null;let e=jsxs(Fragment,{children:[jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:n.green,display:"inline-block",flexShrink:0,boxShadow:`0 0 6px ${n.green}66`}}),jsx(g,{d:c.user,size:13}),jsx("span",{style:{flex:1},children:a.assigned_human_display_name}),a.codex_thread_id&&jsx(g,{d:c.externalLink,size:10})]});return a.codex_thread_id?jsx("a",{href:`codex://threads/${a.codex_thread_id}`,style:d.humanBanner,children:e}):jsx("div",{style:d.humanBanner,children:e})},De=()=>jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${n.borderSubtle}`,flexShrink:0},children:[a?.pr_url&&jsxs("a",{href:a.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.blue),textDecoration:"none"},children:[jsx(g,{d:c.pr,size:12}),a.pr_number?`PR#${a.pr_number}`:a.pr_id||"PR",jsx(g,{d:c.externalLink,size:8})]}),a?.ticket_url&&jsxs("a",{href:a.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.amber),textDecoration:"none"},children:[jsx(g,{d:c.ticket,size:12}),a.ticket_id||"Ticket",jsx(g,{d:c.externalLink,size:8})]}),a?.created_by_agent_name&&(a.codex_thread_id?jsxs("a",{href:`codex://threads/${a.codex_thread_id}`,style:{...d.link(n.purple),textDecoration:"none"},children:[jsx(g,{d:c.bot,size:12}),a.created_by_agent_name,jsx(g,{d:c.externalLink,size:8})]}):jsxs("span",{style:{...d.link(n.purple)},children:[jsx(g,{d:c.bot,size:12}),a.created_by_agent_name]})),jsx("span",{style:{...d.badge(a?.environment||"custom"),marginLeft:"auto"},children:a?.environment})]}),Ee=()=>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("0.5.10");},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 ",jsx("span",{style:{color:n.versionNum},children:"v0.5.10"})]}),w.isAuthenticated&&jsx("button",{onClick:e=>{e.stopPropagation(),w.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",{style:{...d.root,left:P.x,top:P.y},children:[j==="mini"&&jsxs("div",{style:{position:"relative"},onMouseEnter:()=>$(true),onMouseLeave:()=>$(false),children:[jsxs("div",{style:{...d.pill(A),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:G,onPointerMove:q,onPointerUp:()=>{X(),pe.current||Le();},children:[jsx(g,{d:c.grip,size:10,className:""}),a?.ticket_id&&jsx("span",{style:{color:n.amber,fontWeight:600},children:a.ticket_id}),a?.pr_number&&jsxs("span",{style:{color:n.blue,fontWeight:600},children:["PR#",a.pr_number]}),a?.created_by_agent_name&&(a.codex_thread_id?jsxs("a",{href:`codex://threads/${a.codex_thread_id}`,onClick:e=>e.stopPropagation(),style:{color:n.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px",textDecoration:"none",cursor:"pointer"},children:[jsx(g,{d:c.terminal,size:10}),a.created_by_agent_name,jsx(g,{d:c.externalLink,size:8})]}):jsxs("span",{style:{color:n.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(g,{d:c.bot,size:10}),a.created_by_agent_name]})),jsxs("span",{style:A?{color:n.green}:void 0,children:[S.pass,"/",S.total]}),S.fail>0&&jsxs("span",{style:{color:n.red},children:[S.fail,"\u2717"]})]}),(K||E)&&a?.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"220px",maxWidth:"320px",padding:"10px 14px",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:"13px",fontWeight:700,color:n.text,lineHeight:1.3},children:a.title}),(a.description||a.intro_notes)&&jsx("div",{style:{fontSize:"11px",color:n.textMuted,marginTop:"6px",lineHeight:1.4},children:a.description||a.intro_notes})]})]}),j==="expanded"&&jsxs("div",{style:d.card(300,A),children:[jsx(Ue,{}),jsxs("div",{style:d.handle,onPointerDown:G,onPointerMove:q,onPointerUp:X,onClick:Le,children:[jsx(g,{d:c.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:d.title,children:a?.title}),jsx("div",{style:d.sub,children:a?.branch_name&&jsxs("span",{children:["\u2387 ",a.branch_name]})})]}),jsx(g,{d:c.chevronUp,className:""}),jsx(We,{icon:c.minus,onClick:()=>{B(false),Y("mini");}})]}),jsxs("div",{style:d.stats,children:[jsxs("span",{style:{color:n.green},children:[S.pass,"\u2713"]}),jsxs("span",{style:{color:n.red},children:[S.fail,"\u2717"]}),jsxs("span",{style:{color:n.amber},children:[S.skip,"\u23ED"]}),jsxs("span",{style:{color:n.gripColor},children:[S.pending,"\u25CC"]}),jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:S.total})]}),a?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:n.gripColor,borderBottom:`1px solid ${n.borderSubtle}`,flexShrink:0},children:a.description}),jsx(De,{}),jsx(Ee,{}),jsx("div",{style:d.progress,children:jsx("div",{style:d.progressBar(Be)})})]}),j==="max"&&jsxs("div",{style:{...d.card(Z.w,A),height:Z.h,position:"relative"},children:[jsx(Ue,{}),jsxs("div",{style:d.handle,onPointerDown:G,onPointerMove:q,onPointerUp:X,onClick:()=>{pe.current||Y("expanded");},children:[jsx(g,{d:c.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:d.title,children:a?.title}),jsx("div",{style:d.sub,children:a?.branch_name&&jsxs("span",{children:["\u2387 ",a.branch_name]})})]}),jsx(g,{d:c.chevronDown,className:""}),jsx(We,{icon:c.minus,onClick:()=>{B(false),Y("mini");}})]}),jsxs("div",{style:d.stats,children:[jsxs("span",{style:{color:n.green},children:[S.pass,"\u2713"]}),jsxs("span",{style:{color:n.red},children:[S.fail,"\u2717"]}),jsxs("span",{style:{color:n.amber},children:[S.skip,"\u23ED"]}),jsxs("span",{style:{color:n.gripColor},children:[S.pending,"\u25CC"]}),jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:S.total})]}),(a?.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(g,{d:c.search,size:11,className:""}),jsx("input",{value:N,onChange:e=>we(e.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:n.text,fontFamily:"monospace"}}),N&&jsx("button",{onClick:()=>we(""),style:{background:"none",border:"none",cursor:"pointer",color:n.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),D==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(g,{d:c.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:n.red},children:"Failed to load"}),jsx("button",{onClick:tt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),A&&jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg},children:[jsx(g,{d:c.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:n.green,flex:1},children:"Run completed"}),jsx("button",{onClick:rt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),a?.intro_notes&&jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${n.borderSubtle}`,fontSize:"10px",color:n.textMuted,fontStyle:"italic",flexShrink:0},children:a.intro_notes}),D!=="error"&&jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(a?.test_cases||[]).length===0?jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:"No test cases"}):ae.length===0?jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:['No matches for "',N,'"']}):$e?$e.map(e=>{let p=je.has(e.key);return jsxs("div",{children:[jsxs("button",{onClick:()=>Je(e.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(g,{d:p?c.chevronDown:c.chevronUp,size:10,className:""}),jsx("span",{style:{fontSize:"10px",fontWeight:700,color:n.blue,flex:1,textAlign:"left"},children:e.label}),jsxs("span",{style:{fontSize:"9px",color:n.green},children:[e.summary.pass,"\u2713"]}),jsxs("span",{style:{fontSize:"9px",color:n.red},children:[e.summary.fail,"\u2717"]}),jsxs("span",{style:{fontSize:"9px",color:n.gripColor},children:[e.summary.pending,"\u25CC"]}),jsx("span",{style:{fontSize:"9px",color:n.textFaint},children:e.summary.total})]}),!p&&e.cases.map(h=>Ie(h))]},e.key)}):ae.map(e=>Ie(e))}),ot&&!A&&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:nt,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"})]}),jsx(De,{}),jsx(Ee,{}),jsx("div",{style:d.progress,children:jsx("div",{style:d.progressBar(Be)})}),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:Ze,onPointerMove:Qe,onPointerUp:et,onPointerEnter:e=>e.currentTarget.style.opacity="0.7",onPointerLeave:e=>{Q.current||(e.currentTarget.style.opacity="0.3");},children:jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsx("path",{d:"M7 1v6H1",fill:"none",stroke:n.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}
2
- export{vt as TestRunWidget,xe as useDraggable,me as useRealtimeRefresh,be as useTestRun,ve as useWidgetAuth};
1
+ import {useState,useRef,useCallback,useEffect,useMemo}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';function xe(t,o){let[l,b]=useState({x:t,y:o}),x=useRef(false),g=useRef({x:0,y:0}),S=useRef(false),h=useCallback(c=>{x.current=true,S.current=false,g.current={x:c.clientX-l.x,y:c.clientY-l.y},c.target.setPointerCapture(c.pointerId);},[l]),y=useCallback(c=>{x.current&&(S.current=true,b({x:c.clientX-g.current.x,y:c.clientY-g.current.y}));},[]),p=useCallback(()=>{x.current=false;},[]);return {pos:l,onPointerDown:h,onPointerMove:y,onPointerUp:p,didDrag:S}}function me(t,o,l){let b=useRef(l);b.current=l,useEffect(()=>{if(!o)return;if(t.supabaseUrl){let g=false,S=null,h=()=>{g||S||(S=setInterval(()=>b.current(),15e3));},y=null;try{let _=new URL(t.supabaseUrl),n=["localhost","127.0.0.1","::1"].includes(_.hostname);if(_.protocol==="http:"&&!n)throw new Error("Realtime WebSocket requires HTTPS outside loopback hosts");_.protocol=_.protocol==="https:"?"wss:":"ws:",y=_.toString().replace(/\/$/,"");}catch{h();}let p=null,c=null,v=null,w=0,E=()=>{if(!(g||!y)){try{p=new WebSocket(`${y}/realtime/v1/websocket?apikey=${t.anonKey}&vsn=1.0.0`);}catch{h();return}p.onopen=()=>{if(g||!p)return;let _={topic:`realtime:public:test_run_cases:test_run_id=eq.${o}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_run_cases",filter:`test_run_id=eq.${o}`}]}},ref:String(++w)};p.send(JSON.stringify(_));let n={topic:`realtime:public:test_runs:id=eq.${o}`,event:"phx_join",payload:{config:{postgres_changes:[{event:"*",schema:"public",table:"test_runs",filter:`id=eq.${o}`}]}},ref:String(++w)};p.send(JSON.stringify(n)),c=setInterval(()=>{p?.readyState===WebSocket.OPEN&&p.send(JSON.stringify({topic:"phoenix",event:"heartbeat",payload:{},ref:String(++w)}));},3e4);},p.onmessage=_=>{try{JSON.parse(_.data).event==="postgres_changes"&&b.current();}catch{}},p.onclose=()=>{R(),g||(v=setTimeout(E,3e3));},p.onerror=()=>{p?.close();};}},R=()=>{c&&(clearInterval(c),c=null);};return E(),()=>{g=true,R(),v&&clearTimeout(v),S&&clearInterval(S),p&&(p.onclose=null,p.onerror=null,p.close());}}let x=setInterval(()=>b.current(),15e3);return ()=>clearInterval(x)},[t.supabaseUrl,t.anonKey,o]);}function ae(t,o){let l={apikey:t.anonKey};return o?l.Authorization=`Bearer ${o}`:t.apiKey?l.Authorization=`Bearer ${t.apiKey}`:l.Authorization=`Bearer ${t.anonKey}`,l}async function ht(t){if(t)return t;try{let o=await fetch("/.botbuddy-token",{cache:"no-store"});if(o.ok){let l=(await o.text()).trim();if(l.startsWith("public_"))return l}}catch{}try{let o=import.meta?.env?.VITE_BOTBUDDY_TEST_RUN_TOKEN;if(o&&typeof o=="string"&&o.startsWith("public_"))return o}catch{}return null}function he(t){let[o,l]=useState(null),[b,x]=useState("loading"),g=useCallback(async()=>{try{let p=await ht(t.testRunToken);if(!p){x("no-match"),l(null);return}if(!t.ticketId){x("no-match"),l(null);return}let c=new URLSearchParams;c.set("token",p),c.set("ticket_id",t.ticketId),c.set("app_slug",t.appSlug),t.environment&&c.set("environment",t.environment),t.testRunId&&c.set("test_run_id",t.testRunId),t.targetUrl&&c.set("target_url",t.targetUrl),t.version&&c.set("version",t.version),t.commitSha&&c.set("commit_sha",t.commitSha),t.prNumber&&c.set("pr_number",String(t.prNumber)),t.branchName&&c.set("branch_name",t.branchName);let v=await fetch(`${t.config.serverUrl}/widget/test-run?${c.toString()}`,{headers:ae(t.config,t.authToken)});if(v.status===404){x("no-match"),l(null);return}if(v.status===401||v.status===403){x("error");return}if(!v.ok){x("error");return}let w=await v.json();l(w),x(w.status==="completed"?"completed":"ready");}catch{x("error");}},[t.config.serverUrl,t.config.anonKey,t.config.apiKey,t.authToken,t.appSlug,t.environment,t.ticketId,t.testRunId,t.testRunToken,t.targetUrl,t.version,t.commitSha,t.branchName,t.prNumber]);return useEffect(()=>{g();},[g]),me(t.config,o?.id,g),{run:o,widgetState:b,fetchRun:g,setVerdict:async(p,c,v,w="human")=>(l(R=>{if(!R)return null;let _=R.test_cases.map(s=>s.id===p?{...s,verdict:c,fail_reason:c==="fail"&&v||null,verdict_by_display_name:w,verdict_at:new Date().toISOString()}:s),n={total:_.length,pending:0,pass:0,fail:0,skip:0};return _.forEach(s=>{s.verdict in n&&n[s.verdict]++;}),{...R,test_cases:_,summary:n}}),(await fetch(`${t.config.serverUrl}/widget/test-cases/${p}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...ae(t.config,t.authToken)},body:JSON.stringify({verdict:c,fail_reason:v,display_name:w})})).ok),markComplete:async()=>o?(l(c=>c?{...c,status:"completed"}:null),x("completed"),(await fetch(`${t.config.serverUrl}/widget/test-runs/${o.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...ae(t.config,t.authToken)}})).ok):false,resetRun:async()=>{if(!o)return false;let p=await fetch(`${t.config.serverUrl}/widget/test-runs/${o.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...ae(t.config,t.authToken)}});return p.ok&&g(),p.ok},setRun:l}}var ye="botbuddy-widget-auth-token",ve="botbuddy-widget-auth-name";function _e(t){let[o,l]=useState(()=>{try{return localStorage.getItem(ye)}catch(h){return console.warn("Unable to read BotBuddy widget auth token",h),null}}),[b,x]=useState(()=>{try{return localStorage.getItem(ve)}catch(h){return console.warn("Unable to read BotBuddy widget display name",h),null}});useEffect(()=>{let h=new URL(t).origin,y=p=>{if(p.origin===h&&p.data?.type==="botbuddy-widget-auth"&&p.data.token){let{token:c,displayName:v}=p.data;l(c),x(v||"human");try{localStorage.setItem(ye,c),v&&localStorage.setItem(ve,v);}catch(w){console.warn("Unable to persist BotBuddy widget auth token",w);}}};return window.addEventListener("message",y),()=>window.removeEventListener("message",y)},[t]);let g=useCallback(()=>{let h=new URL("/widget-auth",t);h.searchParams.set("origin",window.location.origin);let y=420,p=520,c=window.screenX+(window.innerWidth-y)/2,v=window.screenY+(window.innerHeight-p)/2;window.open(h.toString(),"botbuddy-auth",`width=${y},height=${p},left=${c},top=${v},popup=yes`);},[t]),S=useCallback(()=>{l(null),x(null);try{localStorage.removeItem(ye),localStorage.removeItem(ve);}catch(h){console.warn("Unable to clear BotBuddy widget auth token",h);}},[]);return {token:o,displayName:b,isAuthenticated:!!o,openLogin:g,logout:S}}function vt(t){let o=new Date(t),b=Date.now()-o.getTime();if(b<6e4)return "just now";if(b<36e5)return `${Math.floor(b/6e4)}m ago`;if(b<864e5)return `${Math.floor(b/36e5)}h ago`;let x=o.getDate(),g=o.toLocaleString("en",{month:"short"}),S=o.toLocaleString("en",{hour:"numeric",minute:"2-digit",hour12:true});return `${g} ${x}, ${S}`}var f=({d:t,className:o,size:l=14})=>jsx("svg",{className:o,width:l,height:l,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:t})}),u={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",user:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2M12 3a4 4 0 1 0 0 8 4 4 0 0 0 0-8",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",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 _t(){let[t,o]=useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return useEffect(()=>{if(typeof window>"u")return;let l=document.documentElement,b=()=>l.classList.contains("dark")?"dark":l.classList.contains("light")?"light":null,x=b();x&&o(x);let g=window.matchMedia("(prefers-color-scheme: dark)"),S=y=>{let p=b();o(p||(y.matches?"dark":"light"));};g.addEventListener("change",S);let h=new MutationObserver(()=>{let y=b();o(y||(g.matches?"dark":"light"));});return h.observe(l,{attributes:true,attributeFilter:["class"]}),()=>{g.removeEventListener("change",S),h.disconnect();}},[]),t}function St(t){let o=t==="dark";return {bg:o?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:o?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:o?"#e5e5e5":"#1a1a1a",textMuted:o?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:o?"#555":"#999",border:o?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:o?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:o?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:o?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:o?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:o?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:o?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:o?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:o?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:o?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:o?"#888":"#aaa",btnHover:o?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var wt={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},kt={pending:u.circle,pass:u.check,fail:u.x,skip:u.skip},je={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)"}},Mt=t=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:o=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:t.bg,border:o?`1px solid ${t.greenBorder}`:`1px solid ${t.border}`,boxShadow:o?`0 4px 12px ${t.shadow}, 0 0 0 1px ${t.greenBorderSubtle}`:`0 4px 12px ${t.shadow}`,cursor:"pointer",fontSize:"9px",color:t.text}),card:(o,l)=>({width:`${o}px`,borderRadius:"8px",background:t.bg,border:l?`1px solid ${t.greenBorder}`:`1px solid ${t.border}`,boxShadow:l?`0 8px 24px ${t.shadow}, 0 0 0 1px ${t.greenBorderSubtle}`:`0 8px 24px ${t.shadow}`,overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:`1px solid ${t.borderSubtle}`},title:{fontSize:"10px",fontWeight:600,color:t.text,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:t.textMuted,display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:t.gripColor,display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:`1px solid ${t.borderSubtle}`},badge:o=>{let l=je[o]||je.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:l.bg,color:l.text,border:`1px solid ${l.border}`,lineHeight:"14px"}},progress:{height:"2px",background:t.borderSubtle,flexShrink:0},progressBar:o=>({height:"100%",width:`${o}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:o=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${o}15`,color:o,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${t.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(o,l)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:o?`${l}33`:"transparent",color:o?l:t.gripColor,transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:t.inputBg,border:`1px solid ${t.inputBorder}`,borderRadius:"4px",padding:"2px 6px",color:t.text,outline:"none"},humanBanner:{padding:"6px 12px",fontSize:"11px",fontWeight:600,color:t.green,borderBottom:`1px solid ${t.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",background:t.greenBg,cursor:"pointer",textDecoration:"none"}});function Tt(t){return t.split("/")[0].trim()}function Ye({config:t,appSlug:o,environment:l,seededUsers:b,authToken:x,tk:g,compact:S=false,onExpand:h}){let[y,p]=useState(false),[c,v]=useState(null),[w,E]=useState(null),[R,_]=useState(null),n=useCallback(async s=>{v(s),_(null);try{let C=new URLSearchParams({app_slug:o,seed_user_slug:s,environment:l}),M={apikey:t.anonKey};M.Authorization=`Bearer ${x||t.anonKey}`;let P=await fetch(`${t.serverUrl}/widget/totp-code?${C}`,{headers:M});if(!P.ok){let U=await P.json().catch(()=>({error:`HTTP ${P.status}`}));_(P.status===404?"No 2FA seed registered":U.error||"Failed");return}let D=await P.json();try{await navigator.clipboard.writeText(D.code);}catch{}E({slug:s,code:D.code}),window.setTimeout(()=>E(U=>U?.slug===s?null:U),2500),p(!1);}catch{_("Network error");}finally{v(null);}},[t.serverUrl,t.anonKey,x,o,l]);if(b.length===0)return null;if(S){let s=b.length>1;return jsxs("span",{onPointerDown:M=>M.stopPropagation(),onClick:M=>{if(M.stopPropagation(),s&&h){h();return}n(b[0]);},style:{display:"inline-flex",alignItems:"center",gap:"3px",color:g.purple,fontWeight:600,cursor:"pointer"},title:s?`${b.length} 2FA personas`:`Copy 2FA code for ${b[0]}`,children:[jsx(f,{d:u.shield,size:10}),w?jsx("span",{style:{letterSpacing:"0.1em"},children:w.code}):jsxs(Fragment,{children:["2FA",s&&` \xB7${b.length}`]})]})}if(b.length===1){let s=b[0],C=c===s,M=w?.slug===s;return jsxs("button",{onClick:P=>{P.stopPropagation(),n(s);},disabled:C,style:{...Je(g.purple),cursor:C?"wait":"pointer",opacity:C?.6:1},title:R||`Copy 2FA code for ${s}`,children:[jsx(f,{d:u.shield,size:12}),M?`${w.code} \xB7 copied`:C?"\u2026":`2FA \xB7 ${s}`]})}return jsxs("span",{style:{position:"relative"},children:[jsxs("button",{onClick:s=>{s.stopPropagation(),p(C=>!C),_(null);},style:{...Je(g.purple),cursor:"pointer"},title:"Choose a persona to copy a 2FA code for",children:[jsx(f,{d:u.shield,size:12}),w?`${w.code} \xB7 copied`:`2FA \xB7 ${b.length}`,jsx(f,{d:y?u.chevronUp:u.chevronDown,size:8})]}),y&&jsxs("div",{onPointerDown:s=>s.stopPropagation(),style:{position:"absolute",bottom:"100%",left:0,marginBottom:4,background:g.bg,border:`1px solid ${g.border}`,borderRadius:6,boxShadow:`0 8px 24px ${g.shadow}`,padding:4,minWidth:180,zIndex:10},children:[b.map(s=>{let C=c===s;return jsxs("button",{onClick:M=>{M.stopPropagation(),n(s);},disabled:C,style:{display:"flex",alignItems:"center",gap:6,width:"100%",padding:"5px 8px",background:"transparent",border:"none",borderRadius:4,cursor:C?"wait":"pointer",fontSize:"10px",color:g.text,textAlign:"left",fontFamily:"ui-monospace, SFMono-Regular, monospace"},onMouseEnter:M=>M.currentTarget.style.background=g.btnHover,onMouseLeave:M=>M.currentTarget.style.background="transparent",children:[jsx(f,{d:u.shield,size:10}),jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s}),C&&jsx("span",{style:{color:g.textMuted,fontSize:9},children:"\u2026"})]},s)}),R&&jsx("div",{style:{padding:"4px 8px",fontSize:9,color:g.red},children:R})]})]})}function Je(t){return {display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${t}15`,color:t,textDecoration:"none",border:`1px solid ${t}30`}}var qe="botbuddy-widget-state";function Ct({config:t,appSlug:o,environment:l,ticketId:b,testRunId:x,testRunToken:g,targetUrl:S,version:h,commitSha:y,prNumber:p,branchName:c,onNavigate:v,displayName:w="human",defaultMode:E="mini",defaultPosition:R}){let _=_t(),n=useMemo(()=>St(_),[_]),s=useMemo(()=>Mt(n),[n]),[C,M]=useState(false),[P,D]=useState(false),[U,j]=useState(false),Se=useRef(false),Xe=t.dashboardUrl||"https://app.bot-buddy.ai",T=_e(Xe),de=(()=>{try{let e=typeof window<"u"?localStorage.getItem(qe):null;if(e)return JSON.parse(e)}catch{}return null})(),[Y,F]=useState(de?.mode||E),[pe,re]=useState(""),[Ze,J]=useState(null),[we,ke]=useState(null),[Qe,et]=useState(new Set),[H,Me]=useState(""),tt=useCallback(e=>{et(d=>{let m=new Set(d);return m.has(e)?m.delete(e):m.add(e),m});},[]),nt=de?.x??R?.x??16,rt=de?.y??R?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:B,onPointerDown:q,onPointerMove:G,onPointerUp:X,didDrag:ce}=xe(nt,rt);useEffect(()=>{try{localStorage.setItem(qe,JSON.stringify({mode:Y,x:B.x,y:B.y}));}catch{}},[Y,B.x,B.y]);let Te=useRef(T.isAuthenticated);useEffect(()=>{!Te.current&&T.isAuthenticated&&F("max"),Te.current=T.isAuthenticated;},[T.isAuthenticated]);let Ce="botbuddy-widget-max-size",ot=()=>{try{let e=localStorage.getItem(Ce);if(e)return JSON.parse(e)}catch{}return {w:340,h:500}},[Z,ze]=useState(ot),Q=useRef(false),ee=useRef({x:0,y:0,w:0,h:0}),it=useCallback(e=>{e.stopPropagation(),Q.current=true,ee.current={x:e.clientX,y:e.clientY,w:Z.w,h:Z.h},e.target.setPointerCapture(e.pointerId);},[Z]),st=useCallback(e=>{if(!Q.current)return;let d=Math.max(280,Math.min(600,ee.current.w+(e.clientX-ee.current.x))),m=Math.max(300,Math.min(window.innerHeight*.9,ee.current.h+(e.clientY-ee.current.y)));ze({w:d,h:m});},[]),at=useCallback(()=>{Q.current&&(Q.current=false,ze(e=>(localStorage.setItem(Ce,JSON.stringify(e)),e)));},[]),oe=S??(typeof window<"u"?window.location.href:void 0),$e=T.displayName||w,[W,Re]=useState(null);useEffect(()=>{if(T.isAuthenticated)return;let e=new URLSearchParams;g&&e.set("token",g),b&&e.set("ticket_id",b),e.set("app_slug",o),l&&e.set("environment",l),x&&e.set("test_run_id",x),oe&&e.set("target_url",oe),h&&e.set("version",h),y&&e.set("commit_sha",y),p&&e.set("pr_number",String(p)),c&&e.set("branch_name",c),fetch(`${t.serverUrl}/widget/preview?${e}`,{headers:{apikey:t.anonKey}}).then(d=>d.json()).then(d=>Re(d)).catch(()=>Re(null));},[T.isAuthenticated,t.serverUrl,t.anonKey,o,l,b,x,g,oe,h,y,p,c]);let{run:a,widgetState:A,fetchRun:lt,setVerdict:Pe,markComplete:dt,resetRun:pt}=he({config:t,appSlug:o,environment:l,ticketId:b,testRunId:x,testRunToken:g,targetUrl:oe,version:h,commitSha:y,prNumber:p?String(p):void 0,branchName:c,authToken:T.token}),ie=useCallback(async(e,d,m)=>{ke(e);try{await Pe(e,d,m,$e);}finally{ke(null),J(null),re("");}},[Pe,$e]),k=a?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},ct=k.total>0&&k.pending===0,O=A==="completed",se=useMemo(()=>{let e=a?.test_cases||[];if(!H.trim())return e;let d=H.toLowerCase();return e.filter(m=>m.title.toLowerCase().includes(d)||m.description&&m.description.toLowerCase().includes(d)||m.url_path&&m.url_path.toLowerCase().includes(d)||m.seed_user&&m.seed_user.toLowerCase().includes(d))},[a?.test_cases,H]),Be=useMemo(()=>{let e=se,d=a?.test_cases||[];if(new Set(d.map($=>$.source_pr_number)).size<=1)return null;let I=[],te=new Map;e.forEach($=>{let L=$.source_pr_number;te.has(L)||te.set(L,[]),te.get(L).push($);});let ut=[...te.keys()].sort(($,L)=>$===null?1:L===null?-1:L-$);for(let $ of ut){let L=te.get($),ge={total:L.length,pass:0,fail:0,skip:0,pending:0};L.forEach(He=>{He.verdict in ge&&ge[He.verdict]++;}),I.push({key:$!=null?`pr-${$}`:"general",label:$!=null?`PR #${$}`:"General",cases:L,summary:ge});}return I.filter($=>$.cases.length>0)},[se,a?.test_cases]),Ie=k.total>0?(k.pass+k.fail)/k.total*100:0,N=l??a?.environment??null,Le=useMemo(()=>{if(!N||N==="production")return [];let e=a?.test_cases||[],d=new Set;for(let m of e)m.seed_user&&d.add(Tt(m.seed_user));return [...d]},[a?.test_cases,N]),ue=useMemo(()=>{let e=a?.auto_tooltip_seconds??W?.auto_tooltip_seconds;return e!=null&&e>0?e*1e3:5e3},[a,W]),We=A==="ready"||A==="completed"||W?.enabled&&W.run;useEffect(()=>{if(!We||Se.current||ue<=0)return;Se.current=true,D(true);let e=window.setTimeout(()=>D(false),ue);return ()=>window.clearTimeout(e)},[We,ue]);let Ee=e=>jsxs("div",{style:s.caseRow,children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsx("div",{style:{marginTop:"2px",flexShrink:0,color:wt[e.verdict]},children:we===e.id?jsx(f,{d:u.loader,className:""}):jsx(f,{d:kt[e.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:n.text,lineHeight:1.3},children:e.title}),e.description&&jsx("div",{style:{fontSize:"9px",color:n.gripColor,marginTop:"2px"},children:e.description}),e.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(f,{d:u.key,size:10}),jsx("span",{children:e.seed_user})]}),e.url_path&&jsxs("a",{href:e.url_path,target:"_blank",rel:"noopener noreferrer",onClick:d=>{d.stopPropagation(),v&&(d.preventDefault(),v(e.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(f,{d:u.externalLink,size:10}),e.url_path]}),e.verdict==="fail"&&e.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:n.red,marginTop:"2px"},children:["\u2717 ",e.fail_reason]})]})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(d=>jsx("button",{onClick:()=>{if(e.verdict===d){ie(e.id,"pending"),J(null);return}if(d==="fail"){J(e.id),re("");return}J(null),ie(e.id,d);},disabled:we!==null,style:s.verdictBtn(e.verdict===d,d==="pass"?n.green:d==="fail"?n.red:n.amber),children:d.toUpperCase()},d)),e.created_by_agent_name&&jsxs("span",{style:{fontSize:"8px",color:n.purple,marginLeft:"4px",display:"inline-flex",alignItems:"center",gap:"2px"},children:[jsx(f,{d:u.bot,size:8}),e.created_by_agent_name]}),e.verdict_by_display_name&&jsxs("span",{style:{fontSize:"8px",color:n.textFaint,marginLeft:"auto",display:"inline-flex",alignItems:"center",gap:"3px"},children:[e.verdict_by_display_name,e.verdict_at&&jsx("span",{style:{opacity:.7},children:vt(e.verdict_at)})]})]}),Ze===e.id&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:pe,onChange:d=>re(d.target.value),onKeyDown:d=>{d.key==="Enter"&&ie(e.id,"fail",pe.trim()||void 0),d.key==="Escape"&&(J(null),re(""));},placeholder:"Reason (optional)...",style:s.input}),jsx("button",{onClick:()=>{ie(e.id,"fail",pe.trim()||void 0);},style:s.verdictBtn(true,n.red),children:"\u2713"})]})]},e.id);if((A==="no-match"||A==="loading")&&!(!T.isAuthenticated&&W?.enabled&&W.run))return null;if(!T.isAuthenticated&&W?.enabled&&W.run){let e=W.run,d=e.summary,m=e.status==="completed";return jsx("div",{style:{...s.root,left:B.x,top:B.y},children:jsxs("div",{style:{position:"relative"},onMouseEnter:()=>M(true),onMouseLeave:()=>{M(false),j(false);},children:[jsxs("div",{style:{...s.pill(m),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:q,onPointerMove:G,onPointerUp:()=>{X();},children:[jsx(f,{d:u.grip,size:10,className:""}),e.ticket_id&&e.ticket_url?jsx("a",{href:e.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:I=>I.stopPropagation(),style:{color:n.amber,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:e.ticket_id}):null,e.pr_url?jsxs("a",{href:e.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:I=>I.stopPropagation(),style:{color:n.blue,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:["PR#",e.pr_number??e.pr_id]}):null,e.created_by_agent_name?e.codex_thread_id?jsxs("a",{href:`codex://threads/${e.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",onClick:I=>I.stopPropagation(),style:{color:n.purple,textDecoration:"none",fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(f,{d:u.terminal,size:10}),e.created_by_agent_name]}):jsxs("span",{style:{color:n.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(f,{d:u.bot,size:10}),e.created_by_agent_name]}):null,jsxs("span",{style:m?{color:n.green}:void 0,children:[d.pass,"/",d.total]}),d.fail>0&&jsxs("span",{style:{color:n.red},children:[d.fail,"\u2717"]}),jsx("span",{onClick:I=>{I.stopPropagation(),T.openLogin();},style:{color:n.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),!U&&(C||P)&&e.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"220px",maxWidth:"320px",padding:"10px 14px",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:"13px",fontWeight:700,color:n.text,lineHeight:1.3},children:e.title}),(e.description||e.intro_notes)&&jsx("div",{style:{fontSize:"11px",color:n.textMuted,marginTop:"6px",lineHeight:1.4},children:e.description||e.intro_notes}),jsx("div",{style:{marginTop:"6px",fontSize:"9px",color:n.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!T.isAuthenticated)return jsxs("div",{style:{...s.root,left:B.x,top:B.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:q,onPointerMove:G,onPointerUp:X,children:[jsx("div",{style:{...s.handle,borderBottom:"none"},children:jsxs("div",{style:s.sub,children:[jsx(f,{d:u.grip,size:10,className:""}),jsx(f,{d:u.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"}),jsx("button",{onClick:e=>{e.stopPropagation(),T.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"})]})]});let De=()=>{ce.current||(D(false),F(e=>{let d=e==="mini"?"max":"mini";return j(d==="mini"),d}));},Ue=({icon:e,onClick:d})=>jsx("button",{style:s.btn,onClick:m=>{m.stopPropagation(),d(m);},children:jsx(f,{d:e,className:""})}),Ae=()=>{if(!a?.assigned_human_display_name)return null;let e=jsxs(Fragment,{children:[jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:n.green,display:"inline-block",flexShrink:0,boxShadow:`0 0 6px ${n.green}66`}}),jsx(f,{d:u.user,size:13}),jsx("span",{style:{flex:1},children:a.assigned_human_display_name}),a.codex_thread_id&&jsx(f,{d:u.externalLink,size:10})]});return a.codex_thread_id?jsx("a",{href:`codex://threads/${a.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:s.humanBanner,children:e}):jsx("div",{style:s.humanBanner,children:e})},Ne=()=>jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${n.borderSubtle}`,flexShrink:0},children:[a?.pr_url&&jsxs("a",{href:a.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...s.link(n.blue),textDecoration:"none"},children:[jsx(f,{d:u.pr,size:12}),a.pr_number?`PR#${a.pr_number}`:a.pr_id||"PR",jsx(f,{d:u.externalLink,size:8})]}),a?.ticket_url&&jsxs("a",{href:a.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...s.link(n.amber),textDecoration:"none"},children:[jsx(f,{d:u.ticket,size:12}),a.ticket_id||"Ticket",jsx(f,{d:u.externalLink,size:8})]}),a?.created_by_agent_name&&(a.codex_thread_id?jsxs("a",{href:`codex://threads/${a.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",style:{...s.link(n.purple),textDecoration:"none"},children:[jsx(f,{d:u.bot,size:12}),a.created_by_agent_name,jsx(f,{d:u.externalLink,size:8})]}):jsxs("span",{style:{...s.link(n.purple)},children:[jsx(f,{d:u.bot,size:12}),a.created_by_agent_name]})),N&&jsx(Ye,{config:t,appSlug:o,environment:N,seededUsers:Le,authToken:T.token,tk:n}),jsx("span",{style:{...s.badge(a?.environment||"custom"),marginLeft:"auto"},children:a?.environment})]}),Fe=()=>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("0.5.10");},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 ",jsx("span",{style:{color:n.versionNum},children:"v0.5.10"})]}),T.isAuthenticated&&jsx("button",{onClick:e=>{e.stopPropagation(),T.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",{style:{...s.root,left:B.x,top:B.y},children:[Y==="mini"&&jsxs("div",{style:{position:"relative"},onMouseEnter:()=>M(true),onMouseLeave:()=>{M(false),j(false);},children:[jsxs("div",{style:{...s.pill(O),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:q,onPointerMove:G,onPointerUp:()=>{X(),ce.current||De();},children:[jsx(f,{d:u.grip,size:10,className:""}),a?.ticket_id&&jsx("span",{style:{color:n.amber,fontWeight:600},children:a.ticket_id}),a?.pr_number&&jsxs("span",{style:{color:n.blue,fontWeight:600},children:["PR#",a.pr_number]}),a?.created_by_agent_name&&(a.codex_thread_id?jsxs("a",{href:`codex://threads/${a.codex_thread_id}`,target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),style:{color:n.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px",textDecoration:"none",cursor:"pointer"},children:[jsx(f,{d:u.terminal,size:10}),a.created_by_agent_name,jsx(f,{d:u.externalLink,size:8})]}):jsxs("span",{style:{color:n.purple,fontWeight:600,display:"inline-flex",alignItems:"center",gap:"3px"},children:[jsx(f,{d:u.bot,size:10}),a.created_by_agent_name]})),jsxs("span",{style:O?{color:n.green}:void 0,children:[k.pass,"/",k.total]}),k.fail>0&&jsxs("span",{style:{color:n.red},children:[k.fail,"\u2717"]}),N&&jsx(Ye,{config:t,appSlug:o,environment:N,seededUsers:Le,authToken:T.token,tk:n,compact:true,onExpand:()=>F("expanded")})]}),!U&&(C||P)&&a?.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"220px",maxWidth:"320px",padding:"10px 14px",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:"13px",fontWeight:700,color:n.text,lineHeight:1.3},children:a.title}),(a.description||a.intro_notes)&&jsx("div",{style:{fontSize:"11px",color:n.textMuted,marginTop:"6px",lineHeight:1.4},children:a.description||a.intro_notes})]})]}),Y==="expanded"&&jsxs("div",{style:s.card(300,O),children:[jsx(Ae,{}),jsxs("div",{style:s.handle,onPointerDown:q,onPointerMove:G,onPointerUp:X,onClick:De,children:[jsx(f,{d:u.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:s.title,children:a?.title}),jsx("div",{style:s.sub,children:a?.branch_name&&jsxs("span",{children:["\u2387 ",a.branch_name]})})]}),jsx(f,{d:u.chevronUp,className:""}),jsx(Ue,{icon:u.minus,onClick:()=>{D(false),j(true),F("mini");}})]}),jsxs("div",{style:s.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})]}),a?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:n.gripColor,borderBottom:`1px solid ${n.borderSubtle}`,flexShrink:0},children:a.description}),jsx(Ne,{}),jsx(Fe,{}),jsx("div",{style:s.progress,children:jsx("div",{style:s.progressBar(Ie)})})]}),Y==="max"&&jsxs("div",{style:{...s.card(Z.w,O),height:Z.h,position:"relative"},children:[jsx(Ae,{}),jsxs("div",{style:s.handle,onPointerDown:q,onPointerMove:G,onPointerUp:X,onClick:()=>{ce.current||F("expanded");},children:[jsx(f,{d:u.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:s.title,children:a?.title}),jsx("div",{style:s.sub,children:a?.branch_name&&jsxs("span",{children:["\u2387 ",a.branch_name]})})]}),jsx(f,{d:u.chevronDown,className:""}),jsx(Ue,{icon:u.minus,onClick:()=>{D(false),j(true),F("mini");}})]}),jsxs("div",{style:s.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})]}),(a?.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(f,{d:u.search,size:11,className:""}),jsx("input",{value:H,onChange:e=>Me(e.target.value),placeholder:"Filter test cases...",style:{flex:1,fontSize:"10px",background:"transparent",border:"none",outline:"none",color:n.text,fontFamily:"monospace"}}),H&&jsx("button",{onClick:()=>Me(""),style:{background:"none",border:"none",cursor:"pointer",color:n.textFaint,fontSize:"10px",padding:0},children:"\u2715"})]}),A==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(f,{d:u.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:n.red},children:"Failed to load"}),jsx("button",{onClick:lt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),O&&jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg},children:[jsx(f,{d:u.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:n.green,flex:1},children:"Run completed"}),jsx("button",{onClick:pt,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),a?.intro_notes&&jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${n.borderSubtle}`,fontSize:"10px",color:n.textMuted,fontStyle:"italic",flexShrink:0},children:a.intro_notes}),A!=="error"&&jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(a?.test_cases||[]).length===0?jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:"No test cases"}):se.length===0?jsxs("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:['No matches for "',H,'"']}):Be?Be.map(e=>{let d=Qe.has(e.key);return jsxs("div",{children:[jsxs("button",{onClick:()=>tt(e.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(f,{d:d?u.chevronDown:u.chevronUp,size:10,className:""}),jsx("span",{style:{fontSize:"10px",fontWeight:700,color:n.blue,flex:1,textAlign:"left"},children:e.label}),jsxs("span",{style:{fontSize:"9px",color:n.green},children:[e.summary.pass,"\u2713"]}),jsxs("span",{style:{fontSize:"9px",color:n.red},children:[e.summary.fail,"\u2717"]}),jsxs("span",{style:{fontSize:"9px",color:n.gripColor},children:[e.summary.pending,"\u25CC"]}),jsx("span",{style:{fontSize:"9px",color:n.textFaint},children:e.summary.total})]}),!d&&e.cases.map(m=>Ee(m))]},e.key)}):se.map(e=>Ee(e))}),ct&&!O&&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:dt,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"})]}),jsx(Ne,{}),jsx(Fe,{}),jsx("div",{style:s.progress,children:jsx("div",{style:s.progressBar(Ie)})}),jsx("div",{style:{position:"absolute",bottom:0,right:0,width:16,height:16,cursor:"se-resize",zIndex:10,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:"2px",opacity:.3},onPointerDown:it,onPointerMove:st,onPointerUp:at,onPointerEnter:e=>e.currentTarget.style.opacity="0.7",onPointerLeave:e=>{Q.current||(e.currentTarget.style.opacity="0.3");},children:jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsx("path",{d:"M7 1v6H1",fill:"none",stroke:n.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}
2
+ export{Ct as TestRunWidget,xe as useDraggable,me as useRealtimeRefresh,he as useTestRun,_e as useWidgetAuth};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botbuddy/react",
3
- "version": "0.8.2",
3
+ "version": "0.9.0",
4
4
  "description": "BotBuddy test coordination widgets for React — draggable, translucent overlays for human-in-the-loop QA",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -28,6 +28,8 @@
28
28
  "react-dom": ">=18"
29
29
  },
30
30
  "devDependencies": {
31
+ "@types/react": "^18.3.28",
32
+ "@types/react-dom": "^18.3.7",
31
33
  "react": "^18.3.1",
32
34
  "react-dom": "^18.3.1",
33
35
  "tsup": "^8.4.0",