@botbuddy/react 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');function q(e,o){let[s,v]=react.useState({x:e,y:o}),x=react.useRef(false),g=react.useRef({x:0,y:0}),y=react.useRef(false),h=react.useCallback(p=>{x.current=true,y.current=false,g.current={x:p.clientX-s.x,y:p.clientY-s.y},p.target.setPointerCapture(p.pointerId);},[s]),m=react.useCallback(p=>{x.current&&(y.current=true,v({x:p.clientX-g.current.x,y:p.clientY-g.current.y}));},[]),c=react.useCallback(()=>{x.current=false;},[]);return {pos:s,onPointerDown:h,onPointerMove:m,onPointerUp:c,didDrag:y}}function X(e,o){let s={apikey:e.anonKey};return o?s.Authorization=`Bearer ${o}`:e.apiKey?s.Authorization=`Bearer ${e.apiKey}`:s.Authorization=`Bearer ${e.anonKey}`,s}function Q(e){let[o,s]=react.useState(null),[v,x]=react.useState("loading"),g=react.useCallback(async()=>{try{let c=new URLSearchParams;e.testRunId&&c.set("test_run_id",e.testRunId),e.targetUrl&&c.set("target_url",e.targetUrl),c.set("app_slug",e.appSlug),c.set("environment",e.environment),e.version&&c.set("version",e.version),e.commitSha&&c.set("commit_sha",e.commitSha),e.prNumber&&c.set("pr_number",String(e.prNumber)),e.branchName&&c.set("branch_name",e.branchName);let p=await fetch(`${e.config.serverUrl}/widget/test-run?${c.toString()}`,{headers:X(e.config,e.authToken)});if(p.status===404){x("no-match"),s(null);return}if(p.status===401||p.status===403){x("error");return}if(!p.ok){x("error");return}let w=await p.json();s(w),x(w.status==="completed"?"completed":"ready");}catch{x("error");}},[e.config.serverUrl,e.config.anonKey,e.config.apiKey,e.authToken,e.appSlug,e.environment,e.testRunId,e.targetUrl,e.version,e.commitSha,e.branchName,e.prNumber]);return react.useEffect(()=>{g();},[g]),{run:o,widgetState:v,fetchRun:g,setVerdict:async(c,p,w,R="human")=>(s(n=>{if(!n)return null;let d=n.test_cases.map(_=>_.id===c?{..._,verdict:p,fail_reason:p==="fail"&&w||null,verdict_by_display_name:R,verdict_at:new Date().toISOString()}:_),k={total:d.length,pending:0,pass:0,fail:0,skip:0};return d.forEach(_=>{_.verdict in k&&k[_.verdict]++;}),{...n,test_cases:d,summary:k}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${c}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...X(e.config,e.authToken)},body:JSON.stringify({verdict:p,fail_reason:w,display_name:R})})).ok),markComplete:async()=>o?(s(p=>p?{...p,status:"completed"}:null),x("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${o.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...X(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!o)return false;let c=await fetch(`${e.config.serverUrl}/widget/test-runs/${o.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...X(e.config,e.authToken)}});return c.ok&&g(),c.ok},setRun:s}}var ee="botbuddy-widget-auth-token",te="botbuddy-widget-auth-name";function ne(e){let[o,s]=react.useState(()=>{try{return localStorage.getItem(ee)}catch{return null}}),[v,x]=react.useState(()=>{try{return localStorage.getItem(te)}catch{return null}});react.useEffect(()=>{let h=m=>{if(m.data?.type==="botbuddy-widget-auth"&&m.data.token){let{token:c,displayName:p}=m.data;s(c),x(p||"human");try{localStorage.setItem(ee,c),p&&localStorage.setItem(te,p);}catch{}}};return window.addEventListener("message",h),()=>window.removeEventListener("message",h)},[]);let g=react.useCallback(()=>{let h=`${e}/widget-auth`,m=420,c=520,p=window.screenX+(window.innerWidth-m)/2,w=window.screenY+(window.innerHeight-c)/2;window.open(h,"botbuddy-auth",`width=${m},height=${c},left=${p},top=${w},popup=yes`);},[e]),y=react.useCallback(()=>{s(null),x(null);try{localStorage.removeItem(ee),localStorage.removeItem(te);}catch{}},[]);return {token:o,displayName:v,isAuthenticated:!!o,openLogin:g,logout:y}}var u=({d:e,className:o,size:s=14})=>jsxRuntime.jsx("svg",{className:o,width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:e})}),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",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"};function Ue(){let[e,o]=react.useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return react.useEffect(()=>{if(typeof window>"u")return;let s=document.documentElement,v=()=>s.classList.contains("dark")?"dark":s.classList.contains("light")?"light":null,x=v();x&&o(x);let g=window.matchMedia("(prefers-color-scheme: dark)"),y=m=>{let c=v();o(c||(m.matches?"dark":"light"));};g.addEventListener("change",y);let h=new MutationObserver(()=>{let m=v();o(m||(g.matches?"dark":"light"));});return h.observe(s,{attributes:true,attributeFilter:["class"]}),()=>{g.removeEventListener("change",y),h.disconnect();}},[]),e}function Ae(e){let o=e==="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 Fe={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},He={pending:l.circle,pass:l.check,fail:l.x,skip:l.skip},Se={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)"}},Ve=e=>({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:e.bg,border:o?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:o?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(o,s)=>({width:`${o}px`,borderRadius:"8px",background:e.bg,border:s?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:s?`0 8px 24px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 8px 24px ${e.shadow}`,overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:`1px solid ${e.borderSubtle}`},title:{fontSize:"10px",fontWeight:600,color:e.text,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:e.textMuted,display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:e.gripColor,display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:`1px solid ${e.borderSubtle}`},badge:o=>{let s=Se[o]||Se.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:s.bg,color:s.text,border:`1px solid ${s.border}`,lineHeight:"14px"}},progress:{height:"2px",background:e.borderSubtle,flexShrink:0},progressBar: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 ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(o,s)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:o?`${s}33`:"transparent",color:o?s:e.gripColor,transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:e.inputBg,border:`1px solid ${e.inputBorder}`,borderRadius:"4px",padding:"2px 6px",color:e.text,outline:"none"},humanBanner:{padding:"6px 12px",fontSize:"11px",fontWeight:600,color:e.green,borderBottom:`1px solid ${e.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",background:e.greenBg,cursor:"pointer",textDecoration:"none"}});function Ke({config:e,appSlug:o,environment:s,seedUserSlug:v,authToken:x,tk:g}){let[y,h]=react.useState(null),[m,c]=react.useState(0),[p,w]=react.useState(false),[R,T]=react.useState(null),[n,d]=react.useState(false),k=react.useRef(null),_=react.useMemo(()=>v.split("/")[0].trim(),[v]),V=react.useCallback(async()=>{w(true),T(null);try{let S=new URLSearchParams({app_slug:o,seed_user_slug:_,environment:s}),K={apikey:e.anonKey};x?K.Authorization=`Bearer ${x}`:K.Authorization=`Bearer ${e.anonKey}`;let C=await fetch(`${e.serverUrl}/widget/totp-code?${S}`,{headers:K});if(!C.ok){let I=await C.json().catch(()=>({error:"Failed"}));if(C.status===404){T("No 2FA seed registered");return}T(I.error||"Failed to get code");return}let z=await C.json();h(z.code),c(z.remaining_seconds);try{await navigator.clipboard.writeText(z.code),d(!0),setTimeout(()=>d(!1),2e3);}catch{}k.current&&clearInterval(k.current);let $=z.remaining_seconds;k.current=setInterval(()=>{$--,$<=0?(k.current&&clearInterval(k.current),V()):c($);},1e3);}catch{T("Network error");}finally{w(false);}},[e.serverUrl,e.anonKey,x,o,_,s]);return react.useEffect(()=>()=>{k.current&&clearInterval(k.current);},[]),R==="No 2FA seed registered"?null:y?jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"3px"},children:[jsxRuntime.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"3px 8px",borderRadius:"4px",background:`${g.purple}15`,border:`1px solid ${g.purple}40`,fontSize:"12px",fontFamily:"ui-monospace, monospace",fontWeight:700,color:g.purple,letterSpacing:"0.15em"},children:[jsxRuntime.jsx(u,{d:l.shield,size:11}),jsxRuntime.jsx("span",{children:y}),jsxRuntime.jsxs("span",{style:{fontSize:"8px",fontWeight:400,color:g.textMuted,letterSpacing:"0"},children:[m,"s"]})]}),jsxRuntime.jsx("button",{onClick:S=>{S.stopPropagation(),navigator.clipboard.writeText(y).then(()=>{d(true),setTimeout(()=>d(false),1500);});},style:{padding:"2px",background:"none",border:"none",cursor:"pointer",color:n?g.green:g.gripColor,fontSize:"8px"},title:"Copy code",children:n?jsxRuntime.jsx(u,{d:l.check,size:10}):jsxRuntime.jsx(u,{d:l.copy,size:10})})]}):jsxRuntime.jsxs("button",{onClick:S=>{S.stopPropagation(),V();},disabled:p,style:{display:"inline-flex",alignItems:"center",gap:"4px",marginTop:"3px",fontSize:"8px",padding:"2px 6px",borderRadius:"4px",background:`${g.purple}12`,color:g.purple,border:`1px solid ${g.purple}30`,cursor:p?"wait":"pointer",opacity:p?.6:1},children:[jsxRuntime.jsx(u,{d:l.shield,size:9}),p?"generating...":R||"Get 2FA code"]})}var ke="botbuddy-widget-state";function Oe({config:e,appSlug:o,environment:s,testRunId:v,targetUrl:x,version:g,commitSha:y,prNumber:h,branchName:m,onNavigate:c,displayName:p="human",defaultMode:w="mini",defaultPosition:R}){let T=Ue(),n=react.useMemo(()=>Ae(T),[T]),d=react.useMemo(()=>Ve(n),[n]),[k,_]=react.useState(false),V=e.dashboardUrl||"https://botbuddy.lovable.app",S=ne(V),C=(()=>{try{let r=typeof window<"u"?localStorage.getItem(ke):null;if(r)return JSON.parse(r)}catch{}return null})(),[z,$]=react.useState(C?.mode||w),[I,N]=react.useState(""),[we,P]=react.useState(null),[ae,se]=react.useState(null),_e=C?.x??R?.x??16,Me=C?.y??R?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:B,onPointerDown:O,onPointerMove:Y,onPointerUp:j,didDrag:J}=q(_e,Me);react.useEffect(()=>{try{localStorage.setItem(ke,JSON.stringify({mode:z,x:B.x,y:B.y}));}catch{}},[z,B.x,B.y]);let de="botbuddy-widget-max-size",ze=()=>{try{let r=localStorage.getItem(de);if(r)return JSON.parse(r)}catch{}return {w:340,h:500}},[E,le]=react.useState(ze),D=react.useRef(false),U=react.useRef({x:0,y:0,w:0,h:0}),Re=react.useCallback(r=>{r.stopPropagation(),D.current=true,U.current={x:r.clientX,y:r.clientY,w:E.w,h:E.h},r.target.setPointerCapture(r.pointerId);},[E]),Te=react.useCallback(r=>{if(!D.current)return;let b=Math.max(280,Math.min(600,U.current.w+(r.clientX-U.current.x))),W=Math.max(300,Math.min(window.innerHeight*.9,U.current.h+(r.clientY-U.current.y)));le({w:b,h:W});},[]),Ce=react.useCallback(()=>{D.current&&(D.current=false,le(r=>(localStorage.setItem(de,JSON.stringify(r)),r)));},[]),$e=x??(typeof window<"u"?window.location.href:void 0),pe=S.displayName||p,{run:a,widgetState:A,fetchRun:Be,setVerdict:ce,markComplete:Ie,resetRun:Pe}=Q({config:e,appSlug:o,environment:s,testRunId:v,targetUrl:$e,version:g,commitSha:y,prNumber:h?String(h):void 0,branchName:m,authToken:S.token}),F=react.useCallback(async(r,b,W)=>{se(r);try{await ce(r,b,W,pe);}finally{se(null),P(null),N("");}},[ce,pe]),f=a?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},Le=f.total>0&&f.pending===0,L=A==="completed",ue=f.total>0?(f.pass+f.fail)/f.total*100:0;if(A==="no-match"||A==="loading")return null;if(!S.isAuthenticated)return jsxRuntime.jsxs("div",{style:{...d.root,left:B.x,top:B.y,width:220,minHeight:0,cursor:"move",userSelect:"none",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`},onPointerDown:O,onPointerMove:Y,onPointerUp:j,children:[jsxRuntime.jsx("div",{style:{...d.handle,borderBottom:"none"},children:jsxRuntime.jsxs("div",{style:d.sub,children:[jsxRuntime.jsx(u,{d:l.grip,size:10,className:""}),jsxRuntime.jsx(u,{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:r=>{r.stopPropagation(),S.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 ge=()=>{J.current||$(r=>r==="mini"?"expanded":r==="expanded"?"max":"mini");},xe=({icon:r,onClick:b})=>jsxRuntime.jsx("button",{style:d.btn,onClick:W=>{W.stopPropagation(),b(W);},children:jsxRuntime.jsx(u,{d:r,className:""})}),fe=()=>{if(!a?.assigned_human_display_name)return null;let r=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(u,{d:l.user,size:13}),jsxRuntime.jsx("span",{style:{flex:1},children:a.assigned_human_display_name}),a.codex_thread_id&&jsxRuntime.jsx(u,{d:l.externalLink,size:10})]});return a.codex_thread_id?jsxRuntime.jsx("a",{href:`codex://threads/${a.codex_thread_id}`,style:d.humanBanner,children:r}):jsxRuntime.jsx("div",{style:d.humanBanner,children:r})},be=()=>jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${n.borderSubtle}`,flexShrink:0},children:[a?.pr_url&&jsxRuntime.jsxs("a",{href:a.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.blue),textDecoration:"none"},children:[jsxRuntime.jsx(u,{d:l.pr,size:12}),a.pr_id||"PR",jsxRuntime.jsx(u,{d:l.externalLink,size:8})]}),a?.ticket_url&&jsxRuntime.jsxs("a",{href:a.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.amber),textDecoration:"none"},children:[jsxRuntime.jsx(u,{d:l.ticket,size:12}),a.ticket_id||"Ticket",jsxRuntime.jsx(u,{d:l.externalLink,size:8})]}),a?.created_by_agent_name&&(a.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${a.codex_thread_id}`,style:{...d.link(n.purple),textDecoration:"none"},children:[jsxRuntime.jsx(u,{d:l.bot,size:12}),a.created_by_agent_name,jsxRuntime.jsx(u,{d:l.externalLink,size:8})]}):jsxRuntime.jsxs("span",{style:{...d.link(n.purple)},children:[jsxRuntime.jsx(u,{d:l.bot,size:12}),a.created_by_agent_name]})),jsxRuntime.jsx("span",{style:{...d.badge(a?.environment||"custom"),marginLeft:"auto"},children:a?.environment})]}),me=()=>jsxRuntime.jsxs("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:`1px solid ${n.borderSubtle}`,background:n.bgSoft,flexShrink:0},children:[jsxRuntime.jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.5.1");},style:{fontSize:"9px",fontWeight:600,color:n.versionText,letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxRuntime.jsx("span",{style:{color:n.versionNum},children:"v0.5.1"})]}),S.isAuthenticated&&jsxRuntime.jsx("button",{onClick:r=>{r.stopPropagation(),S.logout();},style:{fontSize:"8px",color:n.textFaint,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Sign out of widget",children:"sign out"})]});return jsxRuntime.jsxs("div",{style:{...d.root,left:B.x,top:B.y},children:[z==="mini"&&jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>_(true),onMouseLeave:()=>_(false),children:[jsxRuntime.jsxs("div",{style:d.pill(L),onPointerDown:O,onPointerMove:Y,onPointerUp:()=>{j(),J.current||ge();},children:[L?jsxRuntime.jsx(u,{d:l.checkAll,className:""}):jsxRuntime.jsx(u,{d:l.clipboard,className:""}),jsxRuntime.jsxs("span",{style:L?{color:n.green}:void 0,children:[f.pass,"/",f.total]}),f.fail>0&&jsxRuntime.jsxs("span",{style:{color:n.red},children:[f.fail,"\u2717"]}),f.skip>0&&jsxRuntime.jsxs("span",{style:{color:n.amber},children:[f.skip,"\u23ED"]})]}),k&&(a?.ticket_id||a?.pr_id||a?.title)&&jsxRuntime.jsxs("div",{style:{position:"absolute",bottom:"calc(100% + 8px)",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:[a?.title&&jsxRuntime.jsx("div",{style:{fontSize:"13px",fontWeight:700,color:n.text,marginBottom:"6px",lineHeight:1.3},children:a.title}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[a?.ticket_id&&a?.ticket_url&&jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",fontWeight:600,color:n.amber},children:[jsxRuntime.jsx(u,{d:l.ticket,size:14}),a.ticket_id]}),a?.pr_id&&a?.pr_url&&jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",fontWeight:600,color:n.blue},children:[jsxRuntime.jsx(u,{d:l.pr,size:14}),"PR ",a.pr_number??a.pr_id]})]})]})]}),z==="expanded"&&jsxRuntime.jsxs("div",{style:d.card(300,L),children:[jsxRuntime.jsx(fe,{}),jsxRuntime.jsxs("div",{style:d.handle,onPointerDown:O,onPointerMove:Y,onPointerUp:j,onClick:ge,children:[jsxRuntime.jsx(u,{d:l.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:d.title,children:a?.title}),jsxRuntime.jsx("div",{style:d.sub,children:a?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",a.branch_name]})})]}),jsxRuntime.jsx(u,{d:l.chevronUp,className:""}),jsxRuntime.jsx(xe,{icon:l.minus,onClick:()=>$("mini")})]}),jsxRuntime.jsxs("div",{style:d.stats,children:[jsxRuntime.jsxs("span",{style:{color:n.green},children:[f.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:n.red},children:[f.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:n.amber},children:[f.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:n.gripColor},children:[f.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:f.total})]}),a?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:n.gripColor,borderBottom:`1px solid ${n.borderSubtle}`,flexShrink:0},children:a.description}),jsxRuntime.jsx(be,{}),jsxRuntime.jsx(me,{}),jsxRuntime.jsx("div",{style:d.progress,children:jsxRuntime.jsx("div",{style:d.progressBar(ue)})})]}),z==="max"&&jsxRuntime.jsxs("div",{style:{...d.card(E.w,L),height:E.h,position:"relative"},children:[jsxRuntime.jsx(fe,{}),jsxRuntime.jsxs("div",{style:d.handle,onPointerDown:O,onPointerMove:Y,onPointerUp:j,onClick:()=>{J.current||$("expanded");},children:[jsxRuntime.jsx(u,{d:l.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:d.title,children:a?.title}),jsxRuntime.jsx("div",{style:d.sub,children:a?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",a.branch_name]})})]}),jsxRuntime.jsx(u,{d:l.chevronDown,className:""}),jsxRuntime.jsx(xe,{icon:l.minus,onClick:()=>$("mini")})]}),jsxRuntime.jsxs("div",{style:d.stats,children:[jsxRuntime.jsxs("span",{style:{color:n.green},children:[f.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:n.red},children:[f.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:n.amber},children:[f.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:n.gripColor},children:[f.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:f.total})]}),A==="error"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsxRuntime.jsx(u,{d:l.alert,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:n.red},children:"Failed to load"}),jsxRuntime.jsx("button",{onClick:Be,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),L&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg},children:[jsxRuntime.jsx(u,{d:l.checkAll,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",color:n.green,flex:1},children:"Run completed"}),jsxRuntime.jsx("button",{onClick:Pe,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),a?.intro_notes&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${n.borderSubtle}`,fontSize:"10px",color:n.textMuted,fontStyle:"italic",flexShrink:0},children:a.intro_notes}),A!=="error"&&jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(a?.test_cases||[]).length===0?jsxRuntime.jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:"No test cases"}):(a?.test_cases||[]).map(r=>jsxRuntime.jsxs("div",{style:d.caseRow,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsx("div",{style:{marginTop:"2px",flexShrink:0,color:Fe[r.verdict]},children:ae===r.id?jsxRuntime.jsx(u,{d:l.loader,className:""}):jsxRuntime.jsx(u,{d:He[r.verdict],className:""})}),jsxRuntime.jsxs("div",{style:{minWidth:0,flex:1},children:[jsxRuntime.jsx("div",{style:{fontSize:"10px",color:n.text,lineHeight:1.3},children:r.title}),r.description&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:n.gripColor,marginTop:"2px"},children:r.description}),r.seed_user&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:n.amber,marginTop:"3px",display:"flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",background:`${n.amber}12`,border:`1px solid ${n.amber}30`},children:[jsxRuntime.jsx(u,{d:l.key,size:10}),jsxRuntime.jsx("span",{children:r.seed_user})]}),s!=="production"&&jsxRuntime.jsx(Ke,{config:e,appSlug:o,environment:s,seedUserSlug:r.seed_user,authToken:S.token,tk:n})]}),r.url_path&&jsxRuntime.jsxs("a",{href:r.url_path,target:"_blank",rel:"noopener noreferrer",onClick:b=>{b.stopPropagation(),c&&(b.preventDefault(),c(r.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsxRuntime.jsx(u,{d:l.externalLink,size:10}),r.url_path]}),r.verdict==="fail"&&r.fail_reason&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:n.red,marginTop:"2px"},children:["\u2717 ",r.fail_reason]})]})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(b=>jsxRuntime.jsx("button",{onClick:()=>{if(r.verdict===b){F(r.id,"pending"),P(null);return}if(b==="fail"){F(r.id,"fail"),P(r.id),N("");return}P(null),F(r.id,b);},disabled:ae!==null,style:d.verdictBtn(r.verdict===b,b==="pass"?n.green:b==="fail"?n.red:n.amber),children:b.toUpperCase()},b)),r.verdict_by_display_name&&jsxRuntime.jsx("span",{style:{fontSize:"8px",color:n.textFaint,marginLeft:"auto"},children:r.verdict_by_display_name})]}),we===r.id&&r.verdict==="fail"&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:I,onChange:b=>N(b.target.value),onKeyDown:b=>{b.key==="Enter"&&I.trim()&&(F(r.id,"fail",I),P(null),N("")),b.key==="Escape"&&(P(null),N(""));},placeholder:"Reason (optional)...",style:d.input}),jsxRuntime.jsx("button",{onClick:()=>{I.trim()&&F(r.id,"fail",I),P(null),N("");},style:d.verdictBtn(true,n.red),children:"\u2713"})]})]},r.id))}),Le&&!L&&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:Ie,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:n.green,border:`1px solid ${n.greenBorderSubtle}`,cursor:"pointer"},children:"COMPLETE"})]}),jsxRuntime.jsx(be,{}),jsxRuntime.jsx(me,{}),jsxRuntime.jsx("div",{style:d.progress,children:jsxRuntime.jsx("div",{style:d.progressBar(ue)})}),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:Re,onPointerMove:Te,onPointerUp:Ce,onPointerEnter:r=>r.currentTarget.style.opacity="0.7",onPointerLeave:r=>{D.current||(r.currentTarget.style.opacity="0.3");},children:jsxRuntime.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsxRuntime.jsx("path",{d:"M7 1v6H1",fill:"none",stroke:n.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}
2
- exports.TestRunWidget=Oe;exports.useDraggable=q;exports.useTestRun=Q;exports.useWidgetAuth=ne;
1
+ 'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');function te(e,i){let[a,S]=react.useState({x:e,y:i}),f=react.useRef(false),x=react.useRef({x:0,y:0}),h=react.useRef(false),v=react.useCallback(c=>{f.current=true,h.current=false,x.current={x:c.clientX-a.x,y:c.clientY-a.y},c.target.setPointerCapture(c.pointerId);},[a]),m=react.useCallback(c=>{f.current&&(h.current=true,S({x:c.clientX-x.current.x,y:c.clientY-x.current.y}));},[]),g=react.useCallback(()=>{f.current=false;},[]);return {pos:a,onPointerDown:v,onPointerMove:m,onPointerUp:g,didDrag:h}}function G(e,i){let a={apikey:e.anonKey};return i?a.Authorization=`Bearer ${i}`:e.apiKey?a.Authorization=`Bearer ${e.apiKey}`:a.Authorization=`Bearer ${e.anonKey}`,a}function ne(e){let[i,a]=react.useState(null),[S,f]=react.useState("loading"),x=react.useCallback(async()=>{try{let g=new URLSearchParams;e.testRunId&&g.set("test_run_id",e.testRunId),e.targetUrl&&g.set("target_url",e.targetUrl),g.set("app_slug",e.appSlug),g.set("environment",e.environment),e.version&&g.set("version",e.version),e.commitSha&&g.set("commit_sha",e.commitSha),e.prNumber&&g.set("pr_number",String(e.prNumber)),e.branchName&&g.set("branch_name",e.branchName);let c=await fetch(`${e.config.serverUrl}/widget/test-run?${g.toString()}`,{headers:G(e.config,e.authToken)});if(c.status===404){f("no-match"),a(null);return}if(c.status===401||c.status===403){f("error");return}if(!c.ok){f("error");return}let M=await c.json();a(M),f(M.status==="completed"?"completed":"ready");}catch{f("error");}},[e.config.serverUrl,e.config.anonKey,e.config.apiKey,e.authToken,e.appSlug,e.environment,e.testRunId,e.targetUrl,e.version,e.commitSha,e.branchName,e.prNumber]);return react.useEffect(()=>{x();},[x]),{run:i,widgetState:S,fetchRun:x,setVerdict:async(g,c,M,C="human")=>(a(r=>{if(!r)return null;let l=r.test_cases.map(w=>w.id===g?{...w,verdict:c,fail_reason:c==="fail"&&M||null,verdict_by_display_name:C,verdict_at:new Date().toISOString()}:w),k={total:l.length,pending:0,pass:0,fail:0,skip:0};return l.forEach(w=>{w.verdict in k&&k[w.verdict]++;}),{...r,test_cases:l,summary:k}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${g}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...G(e.config,e.authToken)},body:JSON.stringify({verdict:c,fail_reason:M,display_name:C})})).ok),markComplete:async()=>i?(a(c=>c?{...c,status:"completed"}:null),f("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${i.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...G(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!i)return false;let g=await fetch(`${e.config.serverUrl}/widget/test-runs/${i.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...G(e.config,e.authToken)}});return g.ok&&x(),g.ok},setRun:a}}var re="botbuddy-widget-auth-token",oe="botbuddy-widget-auth-name";function ie(e){let[i,a]=react.useState(()=>{try{return localStorage.getItem(re)}catch{return null}}),[S,f]=react.useState(()=>{try{return localStorage.getItem(oe)}catch{return null}});react.useEffect(()=>{let v=m=>{if(m.data?.type==="botbuddy-widget-auth"&&m.data.token){let{token:g,displayName:c}=m.data;a(g),f(c||"human");try{localStorage.setItem(re,g),c&&localStorage.setItem(oe,c);}catch{}}};return window.addEventListener("message",v),()=>window.removeEventListener("message",v)},[]);let x=react.useCallback(()=>{let v=`${e}/widget-auth`,m=420,g=520,c=window.screenX+(window.innerWidth-m)/2,M=window.screenY+(window.innerHeight-g)/2;window.open(v,"botbuddy-auth",`width=${m},height=${g},left=${c},top=${M},popup=yes`);},[e]),h=react.useCallback(()=>{a(null),f(null);try{localStorage.removeItem(re),localStorage.removeItem(oe);}catch{}},[]);return {token:i,displayName:S,isAuthenticated:!!i,openLogin:x,logout:h}}var p=({d:e,className:i,size:a=14})=>jsxRuntime.jsx("svg",{className:i,width:a,height:a,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:e})}),d={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01",user:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2M12 3a4 4 0 1 0 0 8 4 4 0 0 0 0-8",bot:"M12 8V4H8M2 14h2M20 14h2M15 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M9 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M18 10a6 6 0 0 0-12 0v4a6 6 0 0 0 12 0Z",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"};function Fe(){let[e,i]=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,S=()=>a.classList.contains("dark")?"dark":a.classList.contains("light")?"light":null,f=S();f&&i(f);let x=window.matchMedia("(prefers-color-scheme: dark)"),h=m=>{let g=S();i(g||(m.matches?"dark":"light"));};x.addEventListener("change",h);let v=new MutationObserver(()=>{let m=S();i(m||(x.matches?"dark":"light"));});return v.observe(a,{attributes:true,attributeFilter:["class"]}),()=>{x.removeEventListener("change",h),v.disconnect();}},[]),e}function He(e){let i=e==="dark";return {bg:i?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:i?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:i?"#e5e5e5":"#1a1a1a",textMuted:i?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:i?"#555":"#999",border:i?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:i?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:i?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:i?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:i?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:i?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:i?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:i?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:i?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:i?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:i?"#888":"#aaa",btnHover:i?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var Ke={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},Ve={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},_e={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)"}},Oe=e=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:i=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:e.bg,border:i?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:i?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(i,a)=>({width:`${i}px`,borderRadius:"8px",background:e.bg,border:a?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:a?`0 8px 24px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 8px 24px ${e.shadow}`,overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:`1px solid ${e.borderSubtle}`},title:{fontSize:"10px",fontWeight:600,color:e.text,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:e.textMuted,display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:e.gripColor,display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:`1px solid ${e.borderSubtle}`},badge:i=>{let a=_e[i]||_e.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:e.borderSubtle,flexShrink:0},progressBar:i=>({height:"100%",width:`${i}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:i=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${i}15`,color:i,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(i,a)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:i?`${a}33`:"transparent",color:i?a:e.gripColor,transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:e.inputBg,border:`1px solid ${e.inputBorder}`,borderRadius:"4px",padding:"2px 6px",color:e.text,outline:"none"},humanBanner:{padding:"6px 12px",fontSize:"11px",fontWeight:600,color:e.green,borderBottom:`1px solid ${e.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",background:e.greenBg,cursor:"pointer",textDecoration:"none"}});function Ye({config:e,appSlug:i,environment:a,seedUserSlug:S,authToken:f,tk:x}){let[h,v]=react.useState(null),[m,g]=react.useState(0),[c,M]=react.useState(false),[C,$]=react.useState(null),[r,l]=react.useState(false),k=react.useRef(null),w=react.useMemo(()=>S.split("/")[0].trim(),[S]),j=react.useCallback(async()=>{M(true),$(null);try{let y=new URLSearchParams({app_slug:i,seed_user_slug:w,environment:a}),X={apikey:e.anonKey};f?X.Authorization=`Bearer ${f}`:X.Authorization=`Bearer ${e.anonKey}`;let B=await fetch(`${e.serverUrl}/widget/totp-code?${y}`,{headers:X});if(!B.ok){let I=await B.json().catch(()=>({error:"Failed"}));if(B.status===404){$("No 2FA seed registered");return}$(I.error||"Failed to get code");return}let z=await B.json();v(z.code),g(z.remaining_seconds);try{await navigator.clipboard.writeText(z.code),l(!0),setTimeout(()=>l(!1),2e3);}catch{}k.current&&clearInterval(k.current);let P=z.remaining_seconds;k.current=setInterval(()=>{P--,P<=0?(k.current&&clearInterval(k.current),j()):g(P);},1e3);}catch{$("Network error");}finally{M(false);}},[e.serverUrl,e.anonKey,f,i,w,a]);return react.useEffect(()=>()=>{k.current&&clearInterval(k.current);},[]),C==="No 2FA seed registered"?null:h?jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"3px"},children:[jsxRuntime.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"3px 8px",borderRadius:"4px",background:`${x.purple}15`,border:`1px solid ${x.purple}40`,fontSize:"12px",fontFamily:"ui-monospace, monospace",fontWeight:700,color:x.purple,letterSpacing:"0.15em"},children:[jsxRuntime.jsx(p,{d:d.shield,size:11}),jsxRuntime.jsx("span",{children:h}),jsxRuntime.jsxs("span",{style:{fontSize:"8px",fontWeight:400,color:x.textMuted,letterSpacing:"0"},children:[m,"s"]})]}),jsxRuntime.jsx("button",{onClick:y=>{y.stopPropagation(),navigator.clipboard.writeText(h).then(()=>{l(true),setTimeout(()=>l(false),1500);});},style:{padding:"2px",background:"none",border:"none",cursor:"pointer",color:r?x.green:x.gripColor,fontSize:"8px"},title:"Copy code",children:r?jsxRuntime.jsx(p,{d:d.check,size:10}):jsxRuntime.jsx(p,{d:d.copy,size:10})})]}):jsxRuntime.jsxs("button",{onClick:y=>{y.stopPropagation(),j();},disabled:c,style:{display:"inline-flex",alignItems:"center",gap:"4px",marginTop:"3px",fontSize:"8px",padding:"2px 6px",borderRadius:"4px",background:`${x.purple}12`,color:x.purple,border:`1px solid ${x.purple}30`,cursor:c?"wait":"pointer",opacity:c?.6:1},children:[jsxRuntime.jsx(p,{d:d.shield,size:9}),c?"generating...":C||"Get 2FA code"]})}var Me="botbuddy-widget-state";function je({config:e,appSlug:i,environment:a,testRunId:S,targetUrl:f,version:x,commitSha:h,prNumber:v,branchName:m,onNavigate:g,displayName:c="human",defaultMode:M="mini",defaultPosition:C}){let $=Fe(),r=react.useMemo(()=>He($),[$]),l=react.useMemo(()=>Oe(r),[r]),[k,w]=react.useState(false),j=e.dashboardUrl||"https://botbuddy.lovable.app",y=ie(j),B=(()=>{try{let n=typeof window<"u"?localStorage.getItem(Me):null;if(n)return JSON.parse(n)}catch{}return null})(),[z,P]=react.useState(B?.mode||M),[I,E]=react.useState(""),[ze,L]=react.useState(null),[le,de]=react.useState(null),Re=B?.x??C?.x??16,Te=B?.y??C?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:R,onPointerDown:N,onPointerMove:U,onPointerUp:D,didDrag:J}=te(Re,Te);react.useEffect(()=>{try{localStorage.setItem(Me,JSON.stringify({mode:z,x:R.x,y:R.y}));}catch{}},[z,R.x,R.y]);let pe="botbuddy-widget-max-size",Ce=()=>{try{let n=localStorage.getItem(pe);if(n)return JSON.parse(n)}catch{}return {w:340,h:500}},[A,ce]=react.useState(Ce),F=react.useRef(false),H=react.useRef({x:0,y:0,w:0,h:0}),$e=react.useCallback(n=>{n.stopPropagation(),F.current=true,H.current={x:n.clientX,y:n.clientY,w:A.w,h:A.h},n.target.setPointerCapture(n.pointerId);},[A]),Be=react.useCallback(n=>{if(!F.current)return;let u=Math.max(280,Math.min(600,H.current.w+(n.clientX-H.current.x))),T=Math.max(300,Math.min(window.innerHeight*.9,H.current.h+(n.clientY-H.current.y)));ce({w:u,h:T});},[]),Pe=react.useCallback(()=>{F.current&&(F.current=false,ce(n=>(localStorage.setItem(pe,JSON.stringify(n)),n)));},[]),Z=f??(typeof window<"u"?window.location.href:void 0),ue=y.displayName||c,[K,ge]=react.useState(null);react.useEffect(()=>{if(y.isAuthenticated)return;let n=new URLSearchParams;S&&n.set("test_run_id",S),Z&&n.set("target_url",Z),n.set("app_slug",i),n.set("environment",a),x&&n.set("version",x),h&&n.set("commit_sha",h),v&&n.set("pr_number",String(v)),m&&n.set("branch_name",m),fetch(`${e.serverUrl}/widget/preview?${n}`,{headers:{apikey:e.anonKey}}).then(u=>u.json()).then(u=>ge(u)).catch(()=>ge(null));},[y.isAuthenticated,e.serverUrl,e.anonKey,i,a,S,Z,x,h,v,m]);let{run:s,widgetState:V,fetchRun:Ie,setVerdict:xe,markComplete:Le,resetRun:We}=ne({config:e,appSlug:i,environment:a,testRunId:S,targetUrl:Z,version:x,commitSha:h,prNumber:v?String(v):void 0,branchName:m,authToken:y.token}),O=react.useCallback(async(n,u,T)=>{de(n);try{await xe(n,u,T,ue);}finally{de(null),L(null),E("");}},[xe,ue]),b=s?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},Ee=b.total>0&&b.pending===0,W=V==="completed",fe=b.total>0?(b.pass+b.fail)/b.total*100:0;if((V==="no-match"||V==="loading")&&!(!y.isAuthenticated&&K?.enabled&&K.run))return null;if(!y.isAuthenticated&&K?.enabled&&K.run){let n=K.run,u=n.summary,T=n.status==="completed";return jsxRuntime.jsx("div",{style:{...l.root,left:R.x,top:R.y},children:jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>w(true),onMouseLeave:()=>w(false),children:[jsxRuntime.jsxs("div",{style:l.pill(T),onPointerDown:N,onPointerMove:U,onPointerUp:()=>{D(),J.current||y.openLogin();},children:[T?jsxRuntime.jsx(p,{d:d.checkAll,className:""}):jsxRuntime.jsx(p,{d:d.clipboard,className:""}),jsxRuntime.jsxs("span",{style:T?{color:r.green}:void 0,children:[u.pass,"/",u.total]}),u.fail>0&&jsxRuntime.jsxs("span",{style:{color:r.red},children:[u.fail,"\u2717"]}),u.skip>0&&jsxRuntime.jsxs("span",{style:{color:r.amber},children:[u.skip,"\u23ED"]})]}),k&&jsxRuntime.jsxs("div",{style:{position:"absolute",bottom:"calc(100% + 8px)",left:0,minWidth:"220px",maxWidth:"320px",padding:"10px 14px",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[n.title&&jsxRuntime.jsx("div",{style:{fontSize:"13px",fontWeight:700,color:r.text,marginBottom:"6px",lineHeight:1.3},children:n.title}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[n.ticket_id&&n.ticket_url&&jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",fontWeight:600,color:r.amber},children:[jsxRuntime.jsx(p,{d:d.ticket,size:14}),n.ticket_id]}),n.pr_id&&n.pr_url&&jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",fontWeight:600,color:r.blue},children:[jsxRuntime.jsx(p,{d:d.pr,size:14}),"PR ",n.pr_number??n.pr_id]})]}),jsxRuntime.jsx("div",{style:{marginTop:"8px",fontSize:"9px",color:r.textMuted,borderTop:`1px solid ${r.borderSubtle}`,paddingTop:"6px"},children:"Click to sign in & start testing"})]})]})})}if(!y.isAuthenticated)return jsxRuntime.jsxs("div",{style:{...l.root,left:R.x,top:R.y,width:220,minHeight:0,cursor:"move",userSelect:"none",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`},onPointerDown:N,onPointerMove:U,onPointerUp:D,children:[jsxRuntime.jsx("div",{style:{...l.handle,borderBottom:"none"},children:jsxRuntime.jsxs("div",{style:l.sub,children:[jsxRuntime.jsx(p,{d:d.grip,size:10,className:""}),jsxRuntime.jsx(p,{d:d.clipboard,size:12,className:""}),jsxRuntime.jsx("span",{style:{fontWeight:600},children:"BotBuddy"})]})}),jsxRuntime.jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[jsxRuntime.jsx("div",{style:{fontSize:"9px",color:r.textMuted,marginBottom:"8px"},children:"Sign in to access test cases"}),jsxRuntime.jsx("button",{onClick:n=>{n.stopPropagation(),y.openLogin();},style:{fontSize:"10px",fontWeight:600,padding:"6px 16px",borderRadius:"6px",border:`1px solid ${r.green}`,background:`${r.green}22`,color:r.green,cursor:"pointer",width:"100%"},children:"Sign in to test"})]})]});let be=()=>{J.current||P(n=>n==="mini"?"expanded":n==="expanded"?"max":"mini");},me=({icon:n,onClick:u})=>jsxRuntime.jsx("button",{style:l.btn,onClick:T=>{T.stopPropagation(),u(T);},children:jsxRuntime.jsx(p,{d:n,className:""})}),ye=()=>{if(!s?.assigned_human_display_name)return null;let n=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:r.green,display:"inline-block",flexShrink:0,boxShadow:`0 0 6px ${r.green}66`}}),jsxRuntime.jsx(p,{d:d.user,size:13}),jsxRuntime.jsx("span",{style:{flex:1},children:s.assigned_human_display_name}),s.codex_thread_id&&jsxRuntime.jsx(p,{d:d.externalLink,size:10})]});return s.codex_thread_id?jsxRuntime.jsx("a",{href:`codex://threads/${s.codex_thread_id}`,style:l.humanBanner,children:n}):jsxRuntime.jsx("div",{style:l.humanBanner,children:n})},he=()=>jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${r.borderSubtle}`,flexShrink:0},children:[s?.pr_url&&jsxRuntime.jsxs("a",{href:s.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...l.link(r.blue),textDecoration:"none"},children:[jsxRuntime.jsx(p,{d:d.pr,size:12}),s.pr_id||"PR",jsxRuntime.jsx(p,{d:d.externalLink,size:8})]}),s?.ticket_url&&jsxRuntime.jsxs("a",{href:s.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...l.link(r.amber),textDecoration:"none"},children:[jsxRuntime.jsx(p,{d:d.ticket,size:12}),s.ticket_id||"Ticket",jsxRuntime.jsx(p,{d:d.externalLink,size:8})]}),s?.created_by_agent_name&&(s.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${s.codex_thread_id}`,style:{...l.link(r.purple),textDecoration:"none"},children:[jsxRuntime.jsx(p,{d:d.bot,size:12}),s.created_by_agent_name,jsxRuntime.jsx(p,{d:d.externalLink,size:8})]}):jsxRuntime.jsxs("span",{style:{...l.link(r.purple)},children:[jsxRuntime.jsx(p,{d:d.bot,size:12}),s.created_by_agent_name]})),jsxRuntime.jsx("span",{style:{...l.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 ${r.borderSubtle}`,background:r.bgSoft,flexShrink:0},children:[jsxRuntime.jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.5.2");},style:{fontSize:"9px",fontWeight:600,color:r.versionText,letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxRuntime.jsx("span",{style:{color:r.versionNum},children:"v0.5.2"})]}),y.isAuthenticated&&jsxRuntime.jsx("button",{onClick:n=>{n.stopPropagation(),y.logout();},style:{fontSize:"8px",color:r.textFaint,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Sign out of widget",children:"sign out"})]});return jsxRuntime.jsxs("div",{style:{...l.root,left:R.x,top:R.y},children:[z==="mini"&&jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>w(true),onMouseLeave:()=>w(false),children:[jsxRuntime.jsxs("div",{style:l.pill(W),onPointerDown:N,onPointerMove:U,onPointerUp:()=>{D(),J.current||be();},children:[W?jsxRuntime.jsx(p,{d:d.checkAll,className:""}):jsxRuntime.jsx(p,{d:d.clipboard,className:""}),jsxRuntime.jsxs("span",{style:W?{color:r.green}:void 0,children:[b.pass,"/",b.total]}),b.fail>0&&jsxRuntime.jsxs("span",{style:{color:r.red},children:[b.fail,"\u2717"]}),b.skip>0&&jsxRuntime.jsxs("span",{style:{color:r.amber},children:[b.skip,"\u23ED"]})]}),k&&(s?.ticket_id||s?.pr_id||s?.title)&&jsxRuntime.jsxs("div",{style:{position:"absolute",bottom:"calc(100% + 8px)",left:0,minWidth:"220px",maxWidth:"320px",padding:"10px 14px",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[s?.title&&jsxRuntime.jsx("div",{style:{fontSize:"13px",fontWeight:700,color:r.text,marginBottom:"6px",lineHeight:1.3},children:s.title}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[s?.ticket_id&&s?.ticket_url&&jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",fontWeight:600,color:r.amber},children:[jsxRuntime.jsx(p,{d:d.ticket,size:14}),s.ticket_id]}),s?.pr_id&&s?.pr_url&&jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",fontWeight:600,color:r.blue},children:[jsxRuntime.jsx(p,{d:d.pr,size:14}),"PR ",s.pr_number??s.pr_id]})]})]})]}),z==="expanded"&&jsxRuntime.jsxs("div",{style:l.card(300,W),children:[jsxRuntime.jsx(ye,{}),jsxRuntime.jsxs("div",{style:l.handle,onPointerDown:N,onPointerMove:U,onPointerUp:D,onClick:be,children:[jsxRuntime.jsx(p,{d:d.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:l.title,children:s?.title}),jsxRuntime.jsx("div",{style:l.sub,children:s?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",s.branch_name]})})]}),jsxRuntime.jsx(p,{d:d.chevronUp,className:""}),jsxRuntime.jsx(me,{icon:d.minus,onClick:()=>P("mini")})]}),jsxRuntime.jsxs("div",{style:l.stats,children:[jsxRuntime.jsxs("span",{style:{color:r.green},children:[b.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:r.red},children:[b.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:r.amber},children:[b.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:r.gripColor},children:[b.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:b.total})]}),s?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:r.gripColor,borderBottom:`1px solid ${r.borderSubtle}`,flexShrink:0},children:s.description}),jsxRuntime.jsx(he,{}),jsxRuntime.jsx(ve,{}),jsxRuntime.jsx("div",{style:l.progress,children:jsxRuntime.jsx("div",{style:l.progressBar(fe)})})]}),z==="max"&&jsxRuntime.jsxs("div",{style:{...l.card(A.w,W),height:A.h,position:"relative"},children:[jsxRuntime.jsx(ye,{}),jsxRuntime.jsxs("div",{style:l.handle,onPointerDown:N,onPointerMove:U,onPointerUp:D,onClick:()=>{J.current||P("expanded");},children:[jsxRuntime.jsx(p,{d:d.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:l.title,children:s?.title}),jsxRuntime.jsx("div",{style:l.sub,children:s?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",s.branch_name]})})]}),jsxRuntime.jsx(p,{d:d.chevronDown,className:""}),jsxRuntime.jsx(me,{icon:d.minus,onClick:()=>P("mini")})]}),jsxRuntime.jsxs("div",{style:l.stats,children:[jsxRuntime.jsxs("span",{style:{color:r.green},children:[b.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:r.red},children:[b.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:r.amber},children:[b.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:r.gripColor},children:[b.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:b.total})]}),V==="error"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsxRuntime.jsx(p,{d:d.alert,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:r.red},children:"Failed to load"}),jsxRuntime.jsx("button",{onClick:Ie,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),W&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg},children:[jsxRuntime.jsx(p,{d:d.checkAll,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",color:r.green,flex:1},children:"Run completed"}),jsxRuntime.jsx("button",{onClick:We,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),s?.intro_notes&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${r.borderSubtle}`,fontSize:"10px",color:r.textMuted,fontStyle:"italic",flexShrink:0},children:s.intro_notes}),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:r.gripColor},children:"No test cases"}):(s?.test_cases||[]).map(n=>jsxRuntime.jsxs("div",{style:l.caseRow,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsx("div",{style:{marginTop:"2px",flexShrink:0,color:Ke[n.verdict]},children:le===n.id?jsxRuntime.jsx(p,{d:d.loader,className:""}):jsxRuntime.jsx(p,{d:Ve[n.verdict],className:""})}),jsxRuntime.jsxs("div",{style:{minWidth:0,flex:1},children:[jsxRuntime.jsx("div",{style:{fontSize:"10px",color:r.text,lineHeight:1.3},children:n.title}),n.description&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:r.gripColor,marginTop:"2px"},children:n.description}),n.seed_user&&jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:r.amber,marginTop:"3px",display:"flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",background:`${r.amber}12`,border:`1px solid ${r.amber}30`},children:[jsxRuntime.jsx(p,{d:d.key,size:10}),jsxRuntime.jsx("span",{children:n.seed_user})]}),a!=="production"&&jsxRuntime.jsx(Ye,{config:e,appSlug:i,environment:a,seedUserSlug:n.seed_user,authToken:y.token,tk:r})]}),n.url_path&&jsxRuntime.jsxs("a",{href:n.url_path,target:"_blank",rel:"noopener noreferrer",onClick:u=>{u.stopPropagation(),g&&(u.preventDefault(),g(n.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsxRuntime.jsx(p,{d:d.externalLink,size:10}),n.url_path]}),n.verdict==="fail"&&n.fail_reason&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:r.red,marginTop:"2px"},children:["\u2717 ",n.fail_reason]})]})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(u=>jsxRuntime.jsx("button",{onClick:()=>{if(n.verdict===u){O(n.id,"pending"),L(null);return}if(u==="fail"){O(n.id,"fail"),L(n.id),E("");return}L(null),O(n.id,u);},disabled:le!==null,style:l.verdictBtn(n.verdict===u,u==="pass"?r.green:u==="fail"?r.red:r.amber),children:u.toUpperCase()},u)),n.verdict_by_display_name&&jsxRuntime.jsx("span",{style:{fontSize:"8px",color:r.textFaint,marginLeft:"auto"},children:n.verdict_by_display_name})]}),ze===n.id&&n.verdict==="fail"&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:I,onChange:u=>E(u.target.value),onKeyDown:u=>{u.key==="Enter"&&I.trim()&&(O(n.id,"fail",I),L(null),E("")),u.key==="Escape"&&(L(null),E(""));},placeholder:"Reason (optional)...",style:l.input}),jsxRuntime.jsx("button",{onClick:()=>{I.trim()&&O(n.id,"fail",I),L(null),E("");},style:l.verdictBtn(true,r.red),children:"\u2713"})]})]},n.id))}),Ee&&!W&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",borderTop:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg,display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsxRuntime.jsx("span",{style:{fontSize:"9px",color:r.green},children:"All resolved"}),jsxRuntime.jsx("button",{onClick:Le,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:r.green,border:`1px solid ${r.greenBorderSubtle}`,cursor:"pointer"},children:"COMPLETE"})]}),jsxRuntime.jsx(he,{}),jsxRuntime.jsx(ve,{}),jsxRuntime.jsx("div",{style:l.progress,children:jsxRuntime.jsx("div",{style:l.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:$e,onPointerMove:Be,onPointerUp:Pe,onPointerEnter:n=>n.currentTarget.style.opacity="0.7",onPointerLeave:n=>{F.current||(n.currentTarget.style.opacity="0.3");},children:jsxRuntime.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsxRuntime.jsx("path",{d:"M7 1v6H1",fill:"none",stroke:r.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}
2
+ exports.TestRunWidget=je;exports.useDraggable=te;exports.useTestRun=ne;exports.useWidgetAuth=ie;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import {useState,useRef,useCallback,useEffect,useMemo}from'react';import {jsxs,jsx,Fragment}from'react/jsx-runtime';function q(e,o){let[s,v]=useState({x:e,y:o}),x=useRef(false),g=useRef({x:0,y:0}),y=useRef(false),h=useCallback(p=>{x.current=true,y.current=false,g.current={x:p.clientX-s.x,y:p.clientY-s.y},p.target.setPointerCapture(p.pointerId);},[s]),m=useCallback(p=>{x.current&&(y.current=true,v({x:p.clientX-g.current.x,y:p.clientY-g.current.y}));},[]),c=useCallback(()=>{x.current=false;},[]);return {pos:s,onPointerDown:h,onPointerMove:m,onPointerUp:c,didDrag:y}}function X(e,o){let s={apikey:e.anonKey};return o?s.Authorization=`Bearer ${o}`:e.apiKey?s.Authorization=`Bearer ${e.apiKey}`:s.Authorization=`Bearer ${e.anonKey}`,s}function Q(e){let[o,s]=useState(null),[v,x]=useState("loading"),g=useCallback(async()=>{try{let c=new URLSearchParams;e.testRunId&&c.set("test_run_id",e.testRunId),e.targetUrl&&c.set("target_url",e.targetUrl),c.set("app_slug",e.appSlug),c.set("environment",e.environment),e.version&&c.set("version",e.version),e.commitSha&&c.set("commit_sha",e.commitSha),e.prNumber&&c.set("pr_number",String(e.prNumber)),e.branchName&&c.set("branch_name",e.branchName);let p=await fetch(`${e.config.serverUrl}/widget/test-run?${c.toString()}`,{headers:X(e.config,e.authToken)});if(p.status===404){x("no-match"),s(null);return}if(p.status===401||p.status===403){x("error");return}if(!p.ok){x("error");return}let w=await p.json();s(w),x(w.status==="completed"?"completed":"ready");}catch{x("error");}},[e.config.serverUrl,e.config.anonKey,e.config.apiKey,e.authToken,e.appSlug,e.environment,e.testRunId,e.targetUrl,e.version,e.commitSha,e.branchName,e.prNumber]);return useEffect(()=>{g();},[g]),{run:o,widgetState:v,fetchRun:g,setVerdict:async(c,p,w,R="human")=>(s(n=>{if(!n)return null;let d=n.test_cases.map(_=>_.id===c?{..._,verdict:p,fail_reason:p==="fail"&&w||null,verdict_by_display_name:R,verdict_at:new Date().toISOString()}:_),k={total:d.length,pending:0,pass:0,fail:0,skip:0};return d.forEach(_=>{_.verdict in k&&k[_.verdict]++;}),{...n,test_cases:d,summary:k}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${c}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...X(e.config,e.authToken)},body:JSON.stringify({verdict:p,fail_reason:w,display_name:R})})).ok),markComplete:async()=>o?(s(p=>p?{...p,status:"completed"}:null),x("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${o.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...X(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!o)return false;let c=await fetch(`${e.config.serverUrl}/widget/test-runs/${o.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...X(e.config,e.authToken)}});return c.ok&&g(),c.ok},setRun:s}}var ee="botbuddy-widget-auth-token",te="botbuddy-widget-auth-name";function ne(e){let[o,s]=useState(()=>{try{return localStorage.getItem(ee)}catch{return null}}),[v,x]=useState(()=>{try{return localStorage.getItem(te)}catch{return null}});useEffect(()=>{let h=m=>{if(m.data?.type==="botbuddy-widget-auth"&&m.data.token){let{token:c,displayName:p}=m.data;s(c),x(p||"human");try{localStorage.setItem(ee,c),p&&localStorage.setItem(te,p);}catch{}}};return window.addEventListener("message",h),()=>window.removeEventListener("message",h)},[]);let g=useCallback(()=>{let h=`${e}/widget-auth`,m=420,c=520,p=window.screenX+(window.innerWidth-m)/2,w=window.screenY+(window.innerHeight-c)/2;window.open(h,"botbuddy-auth",`width=${m},height=${c},left=${p},top=${w},popup=yes`);},[e]),y=useCallback(()=>{s(null),x(null);try{localStorage.removeItem(ee),localStorage.removeItem(te);}catch{}},[]);return {token:o,displayName:v,isAuthenticated:!!o,openLogin:g,logout:y}}var u=({d:e,className:o,size:s=14})=>jsx("svg",{className:o,width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:e})}),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",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"};function Ue(){let[e,o]=useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return useEffect(()=>{if(typeof window>"u")return;let s=document.documentElement,v=()=>s.classList.contains("dark")?"dark":s.classList.contains("light")?"light":null,x=v();x&&o(x);let g=window.matchMedia("(prefers-color-scheme: dark)"),y=m=>{let c=v();o(c||(m.matches?"dark":"light"));};g.addEventListener("change",y);let h=new MutationObserver(()=>{let m=v();o(m||(g.matches?"dark":"light"));});return h.observe(s,{attributes:true,attributeFilter:["class"]}),()=>{g.removeEventListener("change",y),h.disconnect();}},[]),e}function Ae(e){let o=e==="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 Fe={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},He={pending:l.circle,pass:l.check,fail:l.x,skip:l.skip},Se={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)"}},Ve=e=>({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:e.bg,border:o?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:o?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(o,s)=>({width:`${o}px`,borderRadius:"8px",background:e.bg,border:s?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:s?`0 8px 24px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 8px 24px ${e.shadow}`,overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:`1px solid ${e.borderSubtle}`},title:{fontSize:"10px",fontWeight:600,color:e.text,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:e.textMuted,display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:e.gripColor,display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:`1px solid ${e.borderSubtle}`},badge:o=>{let s=Se[o]||Se.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:s.bg,color:s.text,border:`1px solid ${s.border}`,lineHeight:"14px"}},progress:{height:"2px",background:e.borderSubtle,flexShrink:0},progressBar: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 ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(o,s)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:o?`${s}33`:"transparent",color:o?s:e.gripColor,transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:e.inputBg,border:`1px solid ${e.inputBorder}`,borderRadius:"4px",padding:"2px 6px",color:e.text,outline:"none"},humanBanner:{padding:"6px 12px",fontSize:"11px",fontWeight:600,color:e.green,borderBottom:`1px solid ${e.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",background:e.greenBg,cursor:"pointer",textDecoration:"none"}});function Ke({config:e,appSlug:o,environment:s,seedUserSlug:v,authToken:x,tk:g}){let[y,h]=useState(null),[m,c]=useState(0),[p,w]=useState(false),[R,T]=useState(null),[n,d]=useState(false),k=useRef(null),_=useMemo(()=>v.split("/")[0].trim(),[v]),V=useCallback(async()=>{w(true),T(null);try{let S=new URLSearchParams({app_slug:o,seed_user_slug:_,environment:s}),K={apikey:e.anonKey};x?K.Authorization=`Bearer ${x}`:K.Authorization=`Bearer ${e.anonKey}`;let C=await fetch(`${e.serverUrl}/widget/totp-code?${S}`,{headers:K});if(!C.ok){let I=await C.json().catch(()=>({error:"Failed"}));if(C.status===404){T("No 2FA seed registered");return}T(I.error||"Failed to get code");return}let z=await C.json();h(z.code),c(z.remaining_seconds);try{await navigator.clipboard.writeText(z.code),d(!0),setTimeout(()=>d(!1),2e3);}catch{}k.current&&clearInterval(k.current);let $=z.remaining_seconds;k.current=setInterval(()=>{$--,$<=0?(k.current&&clearInterval(k.current),V()):c($);},1e3);}catch{T("Network error");}finally{w(false);}},[e.serverUrl,e.anonKey,x,o,_,s]);return useEffect(()=>()=>{k.current&&clearInterval(k.current);},[]),R==="No 2FA seed registered"?null:y?jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"3px"},children:[jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"3px 8px",borderRadius:"4px",background:`${g.purple}15`,border:`1px solid ${g.purple}40`,fontSize:"12px",fontFamily:"ui-monospace, monospace",fontWeight:700,color:g.purple,letterSpacing:"0.15em"},children:[jsx(u,{d:l.shield,size:11}),jsx("span",{children:y}),jsxs("span",{style:{fontSize:"8px",fontWeight:400,color:g.textMuted,letterSpacing:"0"},children:[m,"s"]})]}),jsx("button",{onClick:S=>{S.stopPropagation(),navigator.clipboard.writeText(y).then(()=>{d(true),setTimeout(()=>d(false),1500);});},style:{padding:"2px",background:"none",border:"none",cursor:"pointer",color:n?g.green:g.gripColor,fontSize:"8px"},title:"Copy code",children:n?jsx(u,{d:l.check,size:10}):jsx(u,{d:l.copy,size:10})})]}):jsxs("button",{onClick:S=>{S.stopPropagation(),V();},disabled:p,style:{display:"inline-flex",alignItems:"center",gap:"4px",marginTop:"3px",fontSize:"8px",padding:"2px 6px",borderRadius:"4px",background:`${g.purple}12`,color:g.purple,border:`1px solid ${g.purple}30`,cursor:p?"wait":"pointer",opacity:p?.6:1},children:[jsx(u,{d:l.shield,size:9}),p?"generating...":R||"Get 2FA code"]})}var ke="botbuddy-widget-state";function Oe({config:e,appSlug:o,environment:s,testRunId:v,targetUrl:x,version:g,commitSha:y,prNumber:h,branchName:m,onNavigate:c,displayName:p="human",defaultMode:w="mini",defaultPosition:R}){let T=Ue(),n=useMemo(()=>Ae(T),[T]),d=useMemo(()=>Ve(n),[n]),[k,_]=useState(false),V=e.dashboardUrl||"https://botbuddy.lovable.app",S=ne(V),C=(()=>{try{let r=typeof window<"u"?localStorage.getItem(ke):null;if(r)return JSON.parse(r)}catch{}return null})(),[z,$]=useState(C?.mode||w),[I,N]=useState(""),[we,P]=useState(null),[ae,se]=useState(null),_e=C?.x??R?.x??16,Me=C?.y??R?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:B,onPointerDown:O,onPointerMove:Y,onPointerUp:j,didDrag:J}=q(_e,Me);useEffect(()=>{try{localStorage.setItem(ke,JSON.stringify({mode:z,x:B.x,y:B.y}));}catch{}},[z,B.x,B.y]);let de="botbuddy-widget-max-size",ze=()=>{try{let r=localStorage.getItem(de);if(r)return JSON.parse(r)}catch{}return {w:340,h:500}},[E,le]=useState(ze),D=useRef(false),U=useRef({x:0,y:0,w:0,h:0}),Re=useCallback(r=>{r.stopPropagation(),D.current=true,U.current={x:r.clientX,y:r.clientY,w:E.w,h:E.h},r.target.setPointerCapture(r.pointerId);},[E]),Te=useCallback(r=>{if(!D.current)return;let b=Math.max(280,Math.min(600,U.current.w+(r.clientX-U.current.x))),W=Math.max(300,Math.min(window.innerHeight*.9,U.current.h+(r.clientY-U.current.y)));le({w:b,h:W});},[]),Ce=useCallback(()=>{D.current&&(D.current=false,le(r=>(localStorage.setItem(de,JSON.stringify(r)),r)));},[]),$e=x??(typeof window<"u"?window.location.href:void 0),pe=S.displayName||p,{run:a,widgetState:A,fetchRun:Be,setVerdict:ce,markComplete:Ie,resetRun:Pe}=Q({config:e,appSlug:o,environment:s,testRunId:v,targetUrl:$e,version:g,commitSha:y,prNumber:h?String(h):void 0,branchName:m,authToken:S.token}),F=useCallback(async(r,b,W)=>{se(r);try{await ce(r,b,W,pe);}finally{se(null),P(null),N("");}},[ce,pe]),f=a?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},Le=f.total>0&&f.pending===0,L=A==="completed",ue=f.total>0?(f.pass+f.fail)/f.total*100:0;if(A==="no-match"||A==="loading")return null;if(!S.isAuthenticated)return jsxs("div",{style:{...d.root,left:B.x,top:B.y,width:220,minHeight:0,cursor:"move",userSelect:"none",borderRadius:"8px",background:n.bg,border:`1px solid ${n.border}`,boxShadow:`0 8px 24px ${n.shadow}`},onPointerDown:O,onPointerMove:Y,onPointerUp:j,children:[jsx("div",{style:{...d.handle,borderBottom:"none"},children:jsxs("div",{style:d.sub,children:[jsx(u,{d:l.grip,size:10,className:""}),jsx(u,{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:r=>{r.stopPropagation(),S.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 ge=()=>{J.current||$(r=>r==="mini"?"expanded":r==="expanded"?"max":"mini");},xe=({icon:r,onClick:b})=>jsx("button",{style:d.btn,onClick:W=>{W.stopPropagation(),b(W);},children:jsx(u,{d:r,className:""})}),fe=()=>{if(!a?.assigned_human_display_name)return null;let r=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(u,{d:l.user,size:13}),jsx("span",{style:{flex:1},children:a.assigned_human_display_name}),a.codex_thread_id&&jsx(u,{d:l.externalLink,size:10})]});return a.codex_thread_id?jsx("a",{href:`codex://threads/${a.codex_thread_id}`,style:d.humanBanner,children:r}):jsx("div",{style:d.humanBanner,children:r})},be=()=>jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${n.borderSubtle}`,flexShrink:0},children:[a?.pr_url&&jsxs("a",{href:a.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.blue),textDecoration:"none"},children:[jsx(u,{d:l.pr,size:12}),a.pr_id||"PR",jsx(u,{d:l.externalLink,size:8})]}),a?.ticket_url&&jsxs("a",{href:a.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...d.link(n.amber),textDecoration:"none"},children:[jsx(u,{d:l.ticket,size:12}),a.ticket_id||"Ticket",jsx(u,{d:l.externalLink,size:8})]}),a?.created_by_agent_name&&(a.codex_thread_id?jsxs("a",{href:`codex://threads/${a.codex_thread_id}`,style:{...d.link(n.purple),textDecoration:"none"},children:[jsx(u,{d:l.bot,size:12}),a.created_by_agent_name,jsx(u,{d:l.externalLink,size:8})]}):jsxs("span",{style:{...d.link(n.purple)},children:[jsx(u,{d:l.bot,size:12}),a.created_by_agent_name]})),jsx("span",{style:{...d.badge(a?.environment||"custom"),marginLeft:"auto"},children:a?.environment})]}),me=()=>jsxs("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:`1px solid ${n.borderSubtle}`,background:n.bgSoft,flexShrink:0},children:[jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.5.1");},style:{fontSize:"9px",fontWeight:600,color:n.versionText,letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsx("span",{style:{color:n.versionNum},children:"v0.5.1"})]}),S.isAuthenticated&&jsx("button",{onClick:r=>{r.stopPropagation(),S.logout();},style:{fontSize:"8px",color:n.textFaint,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Sign out of widget",children:"sign out"})]});return jsxs("div",{style:{...d.root,left:B.x,top:B.y},children:[z==="mini"&&jsxs("div",{style:{position:"relative"},onMouseEnter:()=>_(true),onMouseLeave:()=>_(false),children:[jsxs("div",{style:d.pill(L),onPointerDown:O,onPointerMove:Y,onPointerUp:()=>{j(),J.current||ge();},children:[L?jsx(u,{d:l.checkAll,className:""}):jsx(u,{d:l.clipboard,className:""}),jsxs("span",{style:L?{color:n.green}:void 0,children:[f.pass,"/",f.total]}),f.fail>0&&jsxs("span",{style:{color:n.red},children:[f.fail,"\u2717"]}),f.skip>0&&jsxs("span",{style:{color:n.amber},children:[f.skip,"\u23ED"]})]}),k&&(a?.ticket_id||a?.pr_id||a?.title)&&jsxs("div",{style:{position:"absolute",bottom:"calc(100% + 8px)",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:[a?.title&&jsx("div",{style:{fontSize:"13px",fontWeight:700,color:n.text,marginBottom:"6px",lineHeight:1.3},children:a.title}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[a?.ticket_id&&a?.ticket_url&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",fontWeight:600,color:n.amber},children:[jsx(u,{d:l.ticket,size:14}),a.ticket_id]}),a?.pr_id&&a?.pr_url&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",fontWeight:600,color:n.blue},children:[jsx(u,{d:l.pr,size:14}),"PR ",a.pr_number??a.pr_id]})]})]})]}),z==="expanded"&&jsxs("div",{style:d.card(300,L),children:[jsx(fe,{}),jsxs("div",{style:d.handle,onPointerDown:O,onPointerMove:Y,onPointerUp:j,onClick:ge,children:[jsx(u,{d:l.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:d.title,children:a?.title}),jsx("div",{style:d.sub,children:a?.branch_name&&jsxs("span",{children:["\u2387 ",a.branch_name]})})]}),jsx(u,{d:l.chevronUp,className:""}),jsx(xe,{icon:l.minus,onClick:()=>$("mini")})]}),jsxs("div",{style:d.stats,children:[jsxs("span",{style:{color:n.green},children:[f.pass,"\u2713"]}),jsxs("span",{style:{color:n.red},children:[f.fail,"\u2717"]}),jsxs("span",{style:{color:n.amber},children:[f.skip,"\u23ED"]}),jsxs("span",{style:{color:n.gripColor},children:[f.pending,"\u25CC"]}),jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:f.total})]}),a?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:n.gripColor,borderBottom:`1px solid ${n.borderSubtle}`,flexShrink:0},children:a.description}),jsx(be,{}),jsx(me,{}),jsx("div",{style:d.progress,children:jsx("div",{style:d.progressBar(ue)})})]}),z==="max"&&jsxs("div",{style:{...d.card(E.w,L),height:E.h,position:"relative"},children:[jsx(fe,{}),jsxs("div",{style:d.handle,onPointerDown:O,onPointerMove:Y,onPointerUp:j,onClick:()=>{J.current||$("expanded");},children:[jsx(u,{d:l.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:d.title,children:a?.title}),jsx("div",{style:d.sub,children:a?.branch_name&&jsxs("span",{children:["\u2387 ",a.branch_name]})})]}),jsx(u,{d:l.chevronDown,className:""}),jsx(xe,{icon:l.minus,onClick:()=>$("mini")})]}),jsxs("div",{style:d.stats,children:[jsxs("span",{style:{color:n.green},children:[f.pass,"\u2713"]}),jsxs("span",{style:{color:n.red},children:[f.fail,"\u2717"]}),jsxs("span",{style:{color:n.amber},children:[f.skip,"\u23ED"]}),jsxs("span",{style:{color:n.gripColor},children:[f.pending,"\u25CC"]}),jsx("span",{style:{color:n.textFaint,marginLeft:"auto"},children:f.total})]}),A==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(u,{d:l.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:n.red},children:"Failed to load"}),jsx("button",{onClick:Be,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),L&&jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${n.greenBorderSubtle}`,background:n.greenBg},children:[jsx(u,{d:l.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:n.green,flex:1},children:"Run completed"}),jsx("button",{onClick:Pe,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),a?.intro_notes&&jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${n.borderSubtle}`,fontSize:"10px",color:n.textMuted,fontStyle:"italic",flexShrink:0},children:a.intro_notes}),A!=="error"&&jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(a?.test_cases||[]).length===0?jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:n.gripColor},children:"No test cases"}):(a?.test_cases||[]).map(r=>jsxs("div",{style:d.caseRow,children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsx("div",{style:{marginTop:"2px",flexShrink:0,color:Fe[r.verdict]},children:ae===r.id?jsx(u,{d:l.loader,className:""}):jsx(u,{d:He[r.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:n.text,lineHeight:1.3},children:r.title}),r.description&&jsx("div",{style:{fontSize:"9px",color:n.gripColor,marginTop:"2px"},children:r.description}),r.seed_user&&jsxs("div",{children:[jsxs("div",{style:{fontSize:"9px",color:n.amber,marginTop:"3px",display:"flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",background:`${n.amber}12`,border:`1px solid ${n.amber}30`},children:[jsx(u,{d:l.key,size:10}),jsx("span",{children:r.seed_user})]}),s!=="production"&&jsx(Ke,{config:e,appSlug:o,environment:s,seedUserSlug:r.seed_user,authToken:S.token,tk:n})]}),r.url_path&&jsxs("a",{href:r.url_path,target:"_blank",rel:"noopener noreferrer",onClick:b=>{b.stopPropagation(),c&&(b.preventDefault(),c(r.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsx(u,{d:l.externalLink,size:10}),r.url_path]}),r.verdict==="fail"&&r.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:n.red,marginTop:"2px"},children:["\u2717 ",r.fail_reason]})]})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(b=>jsx("button",{onClick:()=>{if(r.verdict===b){F(r.id,"pending"),P(null);return}if(b==="fail"){F(r.id,"fail"),P(r.id),N("");return}P(null),F(r.id,b);},disabled:ae!==null,style:d.verdictBtn(r.verdict===b,b==="pass"?n.green:b==="fail"?n.red:n.amber),children:b.toUpperCase()},b)),r.verdict_by_display_name&&jsx("span",{style:{fontSize:"8px",color:n.textFaint,marginLeft:"auto"},children:r.verdict_by_display_name})]}),we===r.id&&r.verdict==="fail"&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:I,onChange:b=>N(b.target.value),onKeyDown:b=>{b.key==="Enter"&&I.trim()&&(F(r.id,"fail",I),P(null),N("")),b.key==="Escape"&&(P(null),N(""));},placeholder:"Reason (optional)...",style:d.input}),jsx("button",{onClick:()=>{I.trim()&&F(r.id,"fail",I),P(null),N("");},style:d.verdictBtn(true,n.red),children:"\u2713"})]})]},r.id))}),Le&&!L&&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:Ie,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:n.green,border:`1px solid ${n.greenBorderSubtle}`,cursor:"pointer"},children:"COMPLETE"})]}),jsx(be,{}),jsx(me,{}),jsx("div",{style:d.progress,children:jsx("div",{style:d.progressBar(ue)})}),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:Re,onPointerMove:Te,onPointerUp:Ce,onPointerEnter:r=>r.currentTarget.style.opacity="0.7",onPointerLeave:r=>{D.current||(r.currentTarget.style.opacity="0.3");},children:jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsx("path",{d:"M7 1v6H1",fill:"none",stroke:n.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}
2
- export{Oe as TestRunWidget,q as useDraggable,Q as useTestRun,ne as useWidgetAuth};
1
+ import {useState,useRef,useCallback,useEffect,useMemo}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';function te(e,i){let[a,S]=useState({x:e,y:i}),f=useRef(false),x=useRef({x:0,y:0}),h=useRef(false),v=useCallback(c=>{f.current=true,h.current=false,x.current={x:c.clientX-a.x,y:c.clientY-a.y},c.target.setPointerCapture(c.pointerId);},[a]),m=useCallback(c=>{f.current&&(h.current=true,S({x:c.clientX-x.current.x,y:c.clientY-x.current.y}));},[]),g=useCallback(()=>{f.current=false;},[]);return {pos:a,onPointerDown:v,onPointerMove:m,onPointerUp:g,didDrag:h}}function G(e,i){let a={apikey:e.anonKey};return i?a.Authorization=`Bearer ${i}`:e.apiKey?a.Authorization=`Bearer ${e.apiKey}`:a.Authorization=`Bearer ${e.anonKey}`,a}function ne(e){let[i,a]=useState(null),[S,f]=useState("loading"),x=useCallback(async()=>{try{let g=new URLSearchParams;e.testRunId&&g.set("test_run_id",e.testRunId),e.targetUrl&&g.set("target_url",e.targetUrl),g.set("app_slug",e.appSlug),g.set("environment",e.environment),e.version&&g.set("version",e.version),e.commitSha&&g.set("commit_sha",e.commitSha),e.prNumber&&g.set("pr_number",String(e.prNumber)),e.branchName&&g.set("branch_name",e.branchName);let c=await fetch(`${e.config.serverUrl}/widget/test-run?${g.toString()}`,{headers:G(e.config,e.authToken)});if(c.status===404){f("no-match"),a(null);return}if(c.status===401||c.status===403){f("error");return}if(!c.ok){f("error");return}let M=await c.json();a(M),f(M.status==="completed"?"completed":"ready");}catch{f("error");}},[e.config.serverUrl,e.config.anonKey,e.config.apiKey,e.authToken,e.appSlug,e.environment,e.testRunId,e.targetUrl,e.version,e.commitSha,e.branchName,e.prNumber]);return useEffect(()=>{x();},[x]),{run:i,widgetState:S,fetchRun:x,setVerdict:async(g,c,M,C="human")=>(a(r=>{if(!r)return null;let l=r.test_cases.map(w=>w.id===g?{...w,verdict:c,fail_reason:c==="fail"&&M||null,verdict_by_display_name:C,verdict_at:new Date().toISOString()}:w),k={total:l.length,pending:0,pass:0,fail:0,skip:0};return l.forEach(w=>{w.verdict in k&&k[w.verdict]++;}),{...r,test_cases:l,summary:k}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${g}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...G(e.config,e.authToken)},body:JSON.stringify({verdict:c,fail_reason:M,display_name:C})})).ok),markComplete:async()=>i?(a(c=>c?{...c,status:"completed"}:null),f("completed"),(await fetch(`${e.config.serverUrl}/widget/test-runs/${i.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...G(e.config,e.authToken)}})).ok):false,resetRun:async()=>{if(!i)return false;let g=await fetch(`${e.config.serverUrl}/widget/test-runs/${i.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...G(e.config,e.authToken)}});return g.ok&&x(),g.ok},setRun:a}}var re="botbuddy-widget-auth-token",oe="botbuddy-widget-auth-name";function ie(e){let[i,a]=useState(()=>{try{return localStorage.getItem(re)}catch{return null}}),[S,f]=useState(()=>{try{return localStorage.getItem(oe)}catch{return null}});useEffect(()=>{let v=m=>{if(m.data?.type==="botbuddy-widget-auth"&&m.data.token){let{token:g,displayName:c}=m.data;a(g),f(c||"human");try{localStorage.setItem(re,g),c&&localStorage.setItem(oe,c);}catch{}}};return window.addEventListener("message",v),()=>window.removeEventListener("message",v)},[]);let x=useCallback(()=>{let v=`${e}/widget-auth`,m=420,g=520,c=window.screenX+(window.innerWidth-m)/2,M=window.screenY+(window.innerHeight-g)/2;window.open(v,"botbuddy-auth",`width=${m},height=${g},left=${c},top=${M},popup=yes`);},[e]),h=useCallback(()=>{a(null),f(null);try{localStorage.removeItem(re),localStorage.removeItem(oe);}catch{}},[]);return {token:i,displayName:S,isAuthenticated:!!i,openLogin:x,logout:h}}var p=({d:e,className:i,size:a=14})=>jsx("svg",{className:i,width:a,height:a,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:e})}),d={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01",user:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2M12 3a4 4 0 1 0 0 8 4 4 0 0 0 0-8",bot:"M12 8V4H8M2 14h2M20 14h2M15 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M9 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M18 10a6 6 0 0 0-12 0v4a6 6 0 0 0 12 0Z",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"};function Fe(){let[e,i]=useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return useEffect(()=>{if(typeof window>"u")return;let a=document.documentElement,S=()=>a.classList.contains("dark")?"dark":a.classList.contains("light")?"light":null,f=S();f&&i(f);let x=window.matchMedia("(prefers-color-scheme: dark)"),h=m=>{let g=S();i(g||(m.matches?"dark":"light"));};x.addEventListener("change",h);let v=new MutationObserver(()=>{let m=S();i(m||(x.matches?"dark":"light"));});return v.observe(a,{attributes:true,attributeFilter:["class"]}),()=>{x.removeEventListener("change",h),v.disconnect();}},[]),e}function He(e){let i=e==="dark";return {bg:i?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:i?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:i?"#e5e5e5":"#1a1a1a",textMuted:i?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:i?"#555":"#999",border:i?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:i?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:i?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:i?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:i?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:i?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:i?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:i?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:i?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:i?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:i?"#888":"#aaa",btnHover:i?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var Ke={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},Ve={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},_e={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)"}},Oe=e=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:i=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:e.bg,border:i?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:i?`0 4px 12px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 4px 12px ${e.shadow}`,cursor:"pointer",fontSize:"9px",color:e.text}),card:(i,a)=>({width:`${i}px`,borderRadius:"8px",background:e.bg,border:a?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:a?`0 8px 24px ${e.shadow}, 0 0 0 1px ${e.greenBorderSubtle}`:`0 8px 24px ${e.shadow}`,overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:`1px solid ${e.borderSubtle}`},title:{fontSize:"10px",fontWeight:600,color:e.text,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:e.textMuted,display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:e.gripColor,display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:`1px solid ${e.borderSubtle}`},badge:i=>{let a=_e[i]||_e.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:e.borderSubtle,flexShrink:0},progressBar:i=>({height:"100%",width:`${i}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:i=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${i}15`,color:i,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${e.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(i,a)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:i?`${a}33`:"transparent",color:i?a:e.gripColor,transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:e.inputBg,border:`1px solid ${e.inputBorder}`,borderRadius:"4px",padding:"2px 6px",color:e.text,outline:"none"},humanBanner:{padding:"6px 12px",fontSize:"11px",fontWeight:600,color:e.green,borderBottom:`1px solid ${e.borderSubtle}`,display:"flex",alignItems:"center",gap:"6px",background:e.greenBg,cursor:"pointer",textDecoration:"none"}});function Ye({config:e,appSlug:i,environment:a,seedUserSlug:S,authToken:f,tk:x}){let[h,v]=useState(null),[m,g]=useState(0),[c,M]=useState(false),[C,$]=useState(null),[r,l]=useState(false),k=useRef(null),w=useMemo(()=>S.split("/")[0].trim(),[S]),j=useCallback(async()=>{M(true),$(null);try{let y=new URLSearchParams({app_slug:i,seed_user_slug:w,environment:a}),X={apikey:e.anonKey};f?X.Authorization=`Bearer ${f}`:X.Authorization=`Bearer ${e.anonKey}`;let B=await fetch(`${e.serverUrl}/widget/totp-code?${y}`,{headers:X});if(!B.ok){let I=await B.json().catch(()=>({error:"Failed"}));if(B.status===404){$("No 2FA seed registered");return}$(I.error||"Failed to get code");return}let z=await B.json();v(z.code),g(z.remaining_seconds);try{await navigator.clipboard.writeText(z.code),l(!0),setTimeout(()=>l(!1),2e3);}catch{}k.current&&clearInterval(k.current);let P=z.remaining_seconds;k.current=setInterval(()=>{P--,P<=0?(k.current&&clearInterval(k.current),j()):g(P);},1e3);}catch{$("Network error");}finally{M(false);}},[e.serverUrl,e.anonKey,f,i,w,a]);return useEffect(()=>()=>{k.current&&clearInterval(k.current);},[]),C==="No 2FA seed registered"?null:h?jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"3px"},children:[jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"3px 8px",borderRadius:"4px",background:`${x.purple}15`,border:`1px solid ${x.purple}40`,fontSize:"12px",fontFamily:"ui-monospace, monospace",fontWeight:700,color:x.purple,letterSpacing:"0.15em"},children:[jsx(p,{d:d.shield,size:11}),jsx("span",{children:h}),jsxs("span",{style:{fontSize:"8px",fontWeight:400,color:x.textMuted,letterSpacing:"0"},children:[m,"s"]})]}),jsx("button",{onClick:y=>{y.stopPropagation(),navigator.clipboard.writeText(h).then(()=>{l(true),setTimeout(()=>l(false),1500);});},style:{padding:"2px",background:"none",border:"none",cursor:"pointer",color:r?x.green:x.gripColor,fontSize:"8px"},title:"Copy code",children:r?jsx(p,{d:d.check,size:10}):jsx(p,{d:d.copy,size:10})})]}):jsxs("button",{onClick:y=>{y.stopPropagation(),j();},disabled:c,style:{display:"inline-flex",alignItems:"center",gap:"4px",marginTop:"3px",fontSize:"8px",padding:"2px 6px",borderRadius:"4px",background:`${x.purple}12`,color:x.purple,border:`1px solid ${x.purple}30`,cursor:c?"wait":"pointer",opacity:c?.6:1},children:[jsx(p,{d:d.shield,size:9}),c?"generating...":C||"Get 2FA code"]})}var Me="botbuddy-widget-state";function je({config:e,appSlug:i,environment:a,testRunId:S,targetUrl:f,version:x,commitSha:h,prNumber:v,branchName:m,onNavigate:g,displayName:c="human",defaultMode:M="mini",defaultPosition:C}){let $=Fe(),r=useMemo(()=>He($),[$]),l=useMemo(()=>Oe(r),[r]),[k,w]=useState(false),j=e.dashboardUrl||"https://botbuddy.lovable.app",y=ie(j),B=(()=>{try{let n=typeof window<"u"?localStorage.getItem(Me):null;if(n)return JSON.parse(n)}catch{}return null})(),[z,P]=useState(B?.mode||M),[I,E]=useState(""),[ze,L]=useState(null),[le,de]=useState(null),Re=B?.x??C?.x??16,Te=B?.y??C?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:R,onPointerDown:N,onPointerMove:U,onPointerUp:D,didDrag:J}=te(Re,Te);useEffect(()=>{try{localStorage.setItem(Me,JSON.stringify({mode:z,x:R.x,y:R.y}));}catch{}},[z,R.x,R.y]);let pe="botbuddy-widget-max-size",Ce=()=>{try{let n=localStorage.getItem(pe);if(n)return JSON.parse(n)}catch{}return {w:340,h:500}},[A,ce]=useState(Ce),F=useRef(false),H=useRef({x:0,y:0,w:0,h:0}),$e=useCallback(n=>{n.stopPropagation(),F.current=true,H.current={x:n.clientX,y:n.clientY,w:A.w,h:A.h},n.target.setPointerCapture(n.pointerId);},[A]),Be=useCallback(n=>{if(!F.current)return;let u=Math.max(280,Math.min(600,H.current.w+(n.clientX-H.current.x))),T=Math.max(300,Math.min(window.innerHeight*.9,H.current.h+(n.clientY-H.current.y)));ce({w:u,h:T});},[]),Pe=useCallback(()=>{F.current&&(F.current=false,ce(n=>(localStorage.setItem(pe,JSON.stringify(n)),n)));},[]),Z=f??(typeof window<"u"?window.location.href:void 0),ue=y.displayName||c,[K,ge]=useState(null);useEffect(()=>{if(y.isAuthenticated)return;let n=new URLSearchParams;S&&n.set("test_run_id",S),Z&&n.set("target_url",Z),n.set("app_slug",i),n.set("environment",a),x&&n.set("version",x),h&&n.set("commit_sha",h),v&&n.set("pr_number",String(v)),m&&n.set("branch_name",m),fetch(`${e.serverUrl}/widget/preview?${n}`,{headers:{apikey:e.anonKey}}).then(u=>u.json()).then(u=>ge(u)).catch(()=>ge(null));},[y.isAuthenticated,e.serverUrl,e.anonKey,i,a,S,Z,x,h,v,m]);let{run:s,widgetState:V,fetchRun:Ie,setVerdict:xe,markComplete:Le,resetRun:We}=ne({config:e,appSlug:i,environment:a,testRunId:S,targetUrl:Z,version:x,commitSha:h,prNumber:v?String(v):void 0,branchName:m,authToken:y.token}),O=useCallback(async(n,u,T)=>{de(n);try{await xe(n,u,T,ue);}finally{de(null),L(null),E("");}},[xe,ue]),b=s?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},Ee=b.total>0&&b.pending===0,W=V==="completed",fe=b.total>0?(b.pass+b.fail)/b.total*100:0;if((V==="no-match"||V==="loading")&&!(!y.isAuthenticated&&K?.enabled&&K.run))return null;if(!y.isAuthenticated&&K?.enabled&&K.run){let n=K.run,u=n.summary,T=n.status==="completed";return jsx("div",{style:{...l.root,left:R.x,top:R.y},children:jsxs("div",{style:{position:"relative"},onMouseEnter:()=>w(true),onMouseLeave:()=>w(false),children:[jsxs("div",{style:l.pill(T),onPointerDown:N,onPointerMove:U,onPointerUp:()=>{D(),J.current||y.openLogin();},children:[T?jsx(p,{d:d.checkAll,className:""}):jsx(p,{d:d.clipboard,className:""}),jsxs("span",{style:T?{color:r.green}:void 0,children:[u.pass,"/",u.total]}),u.fail>0&&jsxs("span",{style:{color:r.red},children:[u.fail,"\u2717"]}),u.skip>0&&jsxs("span",{style:{color:r.amber},children:[u.skip,"\u23ED"]})]}),k&&jsxs("div",{style:{position:"absolute",bottom:"calc(100% + 8px)",left:0,minWidth:"220px",maxWidth:"320px",padding:"10px 14px",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[n.title&&jsx("div",{style:{fontSize:"13px",fontWeight:700,color:r.text,marginBottom:"6px",lineHeight:1.3},children:n.title}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[n.ticket_id&&n.ticket_url&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",fontWeight:600,color:r.amber},children:[jsx(p,{d:d.ticket,size:14}),n.ticket_id]}),n.pr_id&&n.pr_url&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",fontWeight:600,color:r.blue},children:[jsx(p,{d:d.pr,size:14}),"PR ",n.pr_number??n.pr_id]})]}),jsx("div",{style:{marginTop:"8px",fontSize:"9px",color:r.textMuted,borderTop:`1px solid ${r.borderSubtle}`,paddingTop:"6px"},children:"Click to sign in & start testing"})]})]})})}if(!y.isAuthenticated)return jsxs("div",{style:{...l.root,left:R.x,top:R.y,width:220,minHeight:0,cursor:"move",userSelect:"none",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`},onPointerDown:N,onPointerMove:U,onPointerUp:D,children:[jsx("div",{style:{...l.handle,borderBottom:"none"},children:jsxs("div",{style:l.sub,children:[jsx(p,{d:d.grip,size:10,className:""}),jsx(p,{d:d.clipboard,size:12,className:""}),jsx("span",{style:{fontWeight:600},children:"BotBuddy"})]})}),jsxs("div",{style:{padding:"12px 14px",textAlign:"center"},children:[jsx("div",{style:{fontSize:"9px",color:r.textMuted,marginBottom:"8px"},children:"Sign in to access test cases"}),jsx("button",{onClick:n=>{n.stopPropagation(),y.openLogin();},style:{fontSize:"10px",fontWeight:600,padding:"6px 16px",borderRadius:"6px",border:`1px solid ${r.green}`,background:`${r.green}22`,color:r.green,cursor:"pointer",width:"100%"},children:"Sign in to test"})]})]});let be=()=>{J.current||P(n=>n==="mini"?"expanded":n==="expanded"?"max":"mini");},me=({icon:n,onClick:u})=>jsx("button",{style:l.btn,onClick:T=>{T.stopPropagation(),u(T);},children:jsx(p,{d:n,className:""})}),ye=()=>{if(!s?.assigned_human_display_name)return null;let n=jsxs(Fragment,{children:[jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:r.green,display:"inline-block",flexShrink:0,boxShadow:`0 0 6px ${r.green}66`}}),jsx(p,{d:d.user,size:13}),jsx("span",{style:{flex:1},children:s.assigned_human_display_name}),s.codex_thread_id&&jsx(p,{d:d.externalLink,size:10})]});return s.codex_thread_id?jsx("a",{href:`codex://threads/${s.codex_thread_id}`,style:l.humanBanner,children:n}):jsx("div",{style:l.humanBanner,children:n})},he=()=>jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${r.borderSubtle}`,flexShrink:0},children:[s?.pr_url&&jsxs("a",{href:s.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...l.link(r.blue),textDecoration:"none"},children:[jsx(p,{d:d.pr,size:12}),s.pr_id||"PR",jsx(p,{d:d.externalLink,size:8})]}),s?.ticket_url&&jsxs("a",{href:s.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...l.link(r.amber),textDecoration:"none"},children:[jsx(p,{d:d.ticket,size:12}),s.ticket_id||"Ticket",jsx(p,{d:d.externalLink,size:8})]}),s?.created_by_agent_name&&(s.codex_thread_id?jsxs("a",{href:`codex://threads/${s.codex_thread_id}`,style:{...l.link(r.purple),textDecoration:"none"},children:[jsx(p,{d:d.bot,size:12}),s.created_by_agent_name,jsx(p,{d:d.externalLink,size:8})]}):jsxs("span",{style:{...l.link(r.purple)},children:[jsx(p,{d:d.bot,size:12}),s.created_by_agent_name]})),jsx("span",{style:{...l.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 ${r.borderSubtle}`,background:r.bgSoft,flexShrink:0},children:[jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.5.2");},style:{fontSize:"9px",fontWeight:600,color:r.versionText,letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsx("span",{style:{color:r.versionNum},children:"v0.5.2"})]}),y.isAuthenticated&&jsx("button",{onClick:n=>{n.stopPropagation(),y.logout();},style:{fontSize:"8px",color:r.textFaint,background:"none",border:"none",cursor:"pointer",marginLeft:"8px",padding:"0 4px",textDecoration:"underline"},title:"Sign out of widget",children:"sign out"})]});return jsxs("div",{style:{...l.root,left:R.x,top:R.y},children:[z==="mini"&&jsxs("div",{style:{position:"relative"},onMouseEnter:()=>w(true),onMouseLeave:()=>w(false),children:[jsxs("div",{style:l.pill(W),onPointerDown:N,onPointerMove:U,onPointerUp:()=>{D(),J.current||be();},children:[W?jsx(p,{d:d.checkAll,className:""}):jsx(p,{d:d.clipboard,className:""}),jsxs("span",{style:W?{color:r.green}:void 0,children:[b.pass,"/",b.total]}),b.fail>0&&jsxs("span",{style:{color:r.red},children:[b.fail,"\u2717"]}),b.skip>0&&jsxs("span",{style:{color:r.amber},children:[b.skip,"\u23ED"]})]}),k&&(s?.ticket_id||s?.pr_id||s?.title)&&jsxs("div",{style:{position:"absolute",bottom:"calc(100% + 8px)",left:0,minWidth:"220px",maxWidth:"320px",padding:"10px 14px",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[s?.title&&jsx("div",{style:{fontSize:"13px",fontWeight:700,color:r.text,marginBottom:"6px",lineHeight:1.3},children:s.title}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"4px"},children:[s?.ticket_id&&s?.ticket_url&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",fontWeight:600,color:r.amber},children:[jsx(p,{d:d.ticket,size:14}),s.ticket_id]}),s?.pr_id&&s?.pr_url&&jsxs("div",{style:{display:"flex",alignItems:"center",gap:"6px",fontSize:"12px",fontWeight:600,color:r.blue},children:[jsx(p,{d:d.pr,size:14}),"PR ",s.pr_number??s.pr_id]})]})]})]}),z==="expanded"&&jsxs("div",{style:l.card(300,W),children:[jsx(ye,{}),jsxs("div",{style:l.handle,onPointerDown:N,onPointerMove:U,onPointerUp:D,onClick:be,children:[jsx(p,{d:d.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:l.title,children:s?.title}),jsx("div",{style:l.sub,children:s?.branch_name&&jsxs("span",{children:["\u2387 ",s.branch_name]})})]}),jsx(p,{d:d.chevronUp,className:""}),jsx(me,{icon:d.minus,onClick:()=>P("mini")})]}),jsxs("div",{style:l.stats,children:[jsxs("span",{style:{color:r.green},children:[b.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[b.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[b.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[b.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:b.total})]}),s?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:r.gripColor,borderBottom:`1px solid ${r.borderSubtle}`,flexShrink:0},children:s.description}),jsx(he,{}),jsx(ve,{}),jsx("div",{style:l.progress,children:jsx("div",{style:l.progressBar(fe)})})]}),z==="max"&&jsxs("div",{style:{...l.card(A.w,W),height:A.h,position:"relative"},children:[jsx(ye,{}),jsxs("div",{style:l.handle,onPointerDown:N,onPointerMove:U,onPointerUp:D,onClick:()=>{J.current||P("expanded");},children:[jsx(p,{d:d.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:l.title,children:s?.title}),jsx("div",{style:l.sub,children:s?.branch_name&&jsxs("span",{children:["\u2387 ",s.branch_name]})})]}),jsx(p,{d:d.chevronDown,className:""}),jsx(me,{icon:d.minus,onClick:()=>P("mini")})]}),jsxs("div",{style:l.stats,children:[jsxs("span",{style:{color:r.green},children:[b.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[b.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[b.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[b.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:b.total})]}),V==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(p,{d:d.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:r.red},children:"Failed to load"}),jsx("button",{onClick:Ie,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),W&&jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg},children:[jsx(p,{d:d.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:r.green,flex:1},children:"Run completed"}),jsx("button",{onClick:We,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),s?.intro_notes&&jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${r.borderSubtle}`,fontSize:"10px",color:r.textMuted,fontStyle:"italic",flexShrink:0},children:s.intro_notes}),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:r.gripColor},children:"No test cases"}):(s?.test_cases||[]).map(n=>jsxs("div",{style:l.caseRow,children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsx("div",{style:{marginTop:"2px",flexShrink:0,color:Ke[n.verdict]},children:le===n.id?jsx(p,{d:d.loader,className:""}):jsx(p,{d:Ve[n.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:r.text,lineHeight:1.3},children:n.title}),n.description&&jsx("div",{style:{fontSize:"9px",color:r.gripColor,marginTop:"2px"},children:n.description}),n.seed_user&&jsxs("div",{children:[jsxs("div",{style:{fontSize:"9px",color:r.amber,marginTop:"3px",display:"flex",alignItems:"center",gap:"4px",padding:"2px 6px",borderRadius:"4px",background:`${r.amber}12`,border:`1px solid ${r.amber}30`},children:[jsx(p,{d:d.key,size:10}),jsx("span",{children:n.seed_user})]}),a!=="production"&&jsx(Ye,{config:e,appSlug:i,environment:a,seedUserSlug:n.seed_user,authToken:y.token,tk:r})]}),n.url_path&&jsxs("a",{href:n.url_path,target:"_blank",rel:"noopener noreferrer",onClick:u=>{u.stopPropagation(),g&&(u.preventDefault(),g(n.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsx(p,{d:d.externalLink,size:10}),n.url_path]}),n.verdict==="fail"&&n.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:r.red,marginTop:"2px"},children:["\u2717 ",n.fail_reason]})]})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(u=>jsx("button",{onClick:()=>{if(n.verdict===u){O(n.id,"pending"),L(null);return}if(u==="fail"){O(n.id,"fail"),L(n.id),E("");return}L(null),O(n.id,u);},disabled:le!==null,style:l.verdictBtn(n.verdict===u,u==="pass"?r.green:u==="fail"?r.red:r.amber),children:u.toUpperCase()},u)),n.verdict_by_display_name&&jsx("span",{style:{fontSize:"8px",color:r.textFaint,marginLeft:"auto"},children:n.verdict_by_display_name})]}),ze===n.id&&n.verdict==="fail"&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:I,onChange:u=>E(u.target.value),onKeyDown:u=>{u.key==="Enter"&&I.trim()&&(O(n.id,"fail",I),L(null),E("")),u.key==="Escape"&&(L(null),E(""));},placeholder:"Reason (optional)...",style:l.input}),jsx("button",{onClick:()=>{I.trim()&&O(n.id,"fail",I),L(null),E("");},style:l.verdictBtn(true,r.red),children:"\u2713"})]})]},n.id))}),Ee&&!W&&jsxs("div",{style:{padding:"6px 12px",borderTop:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg,display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsx("span",{style:{fontSize:"9px",color:r.green},children:"All resolved"}),jsx("button",{onClick:Le,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:r.green,border:`1px solid ${r.greenBorderSubtle}`,cursor:"pointer"},children:"COMPLETE"})]}),jsx(he,{}),jsx(ve,{}),jsx("div",{style:l.progress,children:jsx("div",{style:l.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:$e,onPointerMove:Be,onPointerUp:Pe,onPointerEnter:n=>n.currentTarget.style.opacity="0.7",onPointerLeave:n=>{F.current||(n.currentTarget.style.opacity="0.3");},children:jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsx("path",{d:"M7 1v6H1",fill:"none",stroke:r.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}
2
+ export{je as TestRunWidget,te as useDraggable,ne as useTestRun,ie as useWidgetAuth};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botbuddy/react",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "BotBuddy test coordination widgets for React — draggable, translucent overlays for human-in-the-loop QA",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",