@botbuddy/react 0.9.1 → 0.9.3

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