@botbuddy/react 0.3.0 → 0.5.0

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