@botbuddy/react 0.5.2 → 0.5.3

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