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