@botbuddy/react 0.2.5 → 0.2.8

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 +1,2 @@
1
- 'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');function A(n,p){let[f,T]=react.useState({x:n,y:p}),b=react.useRef(false),x=react.useRef({x:0,y:0}),_=react.useRef(false),z=react.useCallback(c=>{b.current=true,_.current=false,x.current={x:c.clientX-f.x,y:c.clientY-f.y},c.target.setPointerCapture(c.pointerId);},[f]),E=react.useCallback(c=>{b.current&&(_.current=true,T({x:c.clientX-x.current.x,y:c.clientY-x.current.y}));},[]),a=react.useCallback(()=>{b.current=false;},[]);return {pos:f,onPointerDown:z,onPointerMove:E,onPointerUp:a,didDrag:_}}function j(n){let[p,f]=react.useState(null),[T,b]=react.useState("loading"),x=react.useCallback(async()=>{try{let a=new URLSearchParams;n.testRunId&&a.set("test_run_id",n.testRunId),n.targetUrl&&a.set("target_url",n.targetUrl),a.set("app_slug",n.appSlug),a.set("environment",n.environment),n.version&&a.set("version",n.version),n.commitSha&&a.set("commit_sha",n.commitSha),n.prNumber&&a.set("pr_number",String(n.prNumber)),n.branchName&&a.set("branch_name",n.branchName);let c=await fetch(`${n.config.serverUrl}/widget/test-run?${a.toString()}`,{headers:{Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});if(c.status===404){b("no-match"),f(null);return}if(!c.ok){b("error");return}let v=await c.json();f(v),b(v.status==="completed"?"completed":"ready");}catch{b("error");}},[n.config.serverUrl,n.config.anonKey,n.appSlug,n.environment,n.testRunId,n.targetUrl,n.version,n.commitSha,n.branchName]);return react.useEffect(()=>{x();},[x]),{run:p,widgetState:T,fetchRun:x,setVerdict:async(a,c,v,C="human")=>(f(h=>{if(!h)return null;let y=h.test_cases.map(u=>u.id===a?{...u,verdict:c,fail_reason:c==="fail"&&v||null,verdict_by_display_name:C,verdict_at:new Date().toISOString()}:u),m={total:y.length,pending:0,pass:0,fail:0,skip:0};return y.forEach(u=>{u.verdict in m&&m[u.verdict]++;}),{...h,test_cases:y,summary:m}}),(await fetch(`${n.config.serverUrl}/widget/test-cases/${a}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey},body:JSON.stringify({verdict:c,fail_reason:v,display_name:C})})).ok),markComplete:async()=>{if(!p)return false;let a=await fetch(`${n.config.serverUrl}/widget/test-runs/${p.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});return a.ok&&x(),a.ok},resetRun:async()=>{if(!p)return false;let a=await fetch(`${n.config.serverUrl}/widget/test-runs/${p.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});return a.ok&&x(),a.ok},setRun:f}}var g=({d:n,className:p})=>jsxRuntime.jsx("svg",{className:p,width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:n})}),d={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01"};var he={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},te={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)"}},o={root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:n=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:"rgb(30,30,30)",border:n?"1px solid rgba(52,211,153,0.6)":"1px solid rgba(255,255,255,0.15)",boxShadow:n?"0 4px 12px rgba(0,0,0,0.3), 0 0 0 1px rgba(52,211,153,0.2)":"0 4px 12px rgba(0,0,0,0.3)",cursor:"pointer",fontSize:"9px",color:"#e5e5e5"}),card:(n,p)=>({width:`${n}px`,borderRadius:"8px",background:"rgb(30,30,30)",border:p?"1px solid rgba(52,211,153,0.6)":"1px solid rgba(255,255,255,0.15)",boxShadow:p?"0 8px 24px rgba(0,0,0,0.4), 0 0 0 1px rgba(52,211,153,0.2)":"0 8px 24px rgba(0,0,0,0.4)",overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:"1px solid rgba(255,255,255,0.06)"},title:{fontSize:"10px",fontWeight:600,color:"#e5e5e5",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:"rgba(255,255,255,0.4)",display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:"#888",display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:"1px solid rgba(255,255,255,0.06)"},badge:n=>{let p=te[n]||te.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:p.bg,color:p.text,border:`1px solid ${p.border}`,lineHeight:"14px"}},progress:{height:"2px",background:"rgba(255,255,255,0.06)",flexShrink:0},progressBar:n=>({height:"100%",width:`${n}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:n=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${n}15`,color:n,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:"1px solid rgba(255,255,255,0.06)",transition:"background 0.15s"},verdictBtn:(n,p)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:n?`${p}33`:"transparent",color:n?p:"#888",transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:"rgba(0,0,0,0.3)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"4px",padding:"2px 6px",color:"#e5e5e5",outline:"none"}},re="botbuddy-widget-state";function ke({config:n,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:_,prNumber:z,branchName:E,onNavigate:a,displayName:c="human",defaultMode:v="expanded",defaultPosition:C}){let h=(()=>{try{let t=typeof window<"u"?localStorage.getItem(re):null;if(t)return JSON.parse(t)}catch{}return null})(),[y,m]=react.useState(h?.mode||v),[u,w]=react.useState(""),[oe,k]=react.useState(null),[Y,F]=react.useState(null),ae=h?.x??C?.x??16,se=h?.y??C?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:M,onPointerDown:U,onPointerMove:$,onPointerUp:V,didDrag:K}=A(ae,se);react.useEffect(()=>{try{localStorage.setItem(re,JSON.stringify({mode:y,x:M.x,y:M.y}));}catch{}},[y,M.x,M.y]);let J="botbuddy-widget-max-size",le=()=>{try{let t=localStorage.getItem(J);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[I,X]=react.useState(le),P=react.useRef(false),B=react.useRef({x:0,y:0,w:0,h:0}),de=react.useCallback(t=>{t.stopPropagation(),P.current=true,B.current={x:t.clientX,y:t.clientY,w:I.w,h:I.h},t.target.setPointerCapture(t.pointerId);},[I]),pe=react.useCallback(t=>{if(!P.current)return;let l=Math.max(280,Math.min(600,B.current.w+(t.clientX-B.current.x))),R=Math.max(300,Math.min(window.innerHeight*.9,B.current.h+(t.clientY-B.current.y)));X({w:l,h:R});},[]),ce=react.useCallback(()=>{P.current&&(P.current=false,X(t=>(localStorage.setItem(J,JSON.stringify(t)),t)));},[]),{run:i,widgetState:N,fetchRun:ge,setVerdict:Z,markComplete:ue,resetRun:fe}=j({config:n,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:_,prNumber:z?String(z):void 0,branchName:E}),D=react.useCallback(async(t,l,R)=>{F(t);try{await Z(t,l,R,c);}finally{F(null),k(null),w("");}},[Z,c]),s=i?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},xe=s.total>0&&s.pending===0,S=N==="completed",G=s.total>0?(s.pass+s.fail)/s.total*100:0;if(N==="no-match"||N==="loading")return null;let q=()=>{K.current||m(t=>t==="mini"?"expanded":t==="expanded"?"max":"mini");},Q=({icon:t,onClick:l})=>jsxRuntime.jsx("button",{style:o.btn,onClick:R=>{R.stopPropagation(),l(R);},children:jsxRuntime.jsx(g,{d:t,className:""})});return jsxRuntime.jsxs("div",{style:{...o.root,left:M.x,top:M.y},children:[y==="mini"&&jsxRuntime.jsxs("div",{style:o.pill(S),onPointerDown:U,onPointerMove:$,onPointerUp:()=>{V(),K.current||q();},children:[S?jsxRuntime.jsx(g,{d:d.checkAll,className:""}):jsxRuntime.jsx(g,{d:d.clipboard,className:""}),jsxRuntime.jsxs("span",{style:S?{color:"#34d399"}:void 0,children:[s.pass,"/",s.total]}),s.fail>0&&jsxRuntime.jsxs("span",{style:{color:"#f87171"},children:[s.fail,"\u2717"]}),s.skip>0&&jsxRuntime.jsxs("span",{style:{color:"#f59e0b"},children:[s.skip,"\u23ED"]}),i?.pr_url&&jsxRuntime.jsxs("span",{style:{...o.link("#60a5fa"),pointerEvents:"none",textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.pr,className:""}),i.pr_id||"PR"]}),i?.ticket_url&&jsxRuntime.jsxs("span",{style:{...o.link("#fbbf24"),pointerEvents:"none",textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.ticket,className:""}),i.ticket_id||"TKT"]})]}),y==="expanded"&&jsxRuntime.jsxs("div",{style:o.card(300,S),children:[i?.assigned_human_display_name&&jsxRuntime.jsxs("div",{style:{padding:"4px 12px",fontSize:"9px",color:"#34d399",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:"4px",background:"rgba(52,211,153,0.05)"},children:[jsxRuntime.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"#34d399",display:"inline-block",flexShrink:0}}),i.assigned_human_display_name]}),jsxRuntime.jsxs("div",{style:o.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:q,children:[jsxRuntime.jsx(g,{d:d.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:o.title,children:i?.title}),jsxRuntime.jsxs("div",{style:o.sub,children:[i?.created_by_agent_name&&jsxRuntime.jsxs("span",{children:["\u{1F916} ",i.created_by_agent_name]}),i?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",i.branch_name]})]})]}),jsxRuntime.jsx(g,{d:d.chevronUp,className:""}),jsxRuntime.jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxRuntime.jsxs("div",{style:o.stats,children:[jsxRuntime.jsxs("span",{style:{color:"#34d399"},children:[s.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:"#f87171"},children:[s.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:"#f59e0b"},children:[s.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:"#888"},children:[s.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:"#555",marginLeft:"auto"},children:s.total})]}),i?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:"#888",borderBottom:"1px solid rgba(255,255,255,0.06)",flexShrink:0},children:i.description}),jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:"1px solid rgba(255,255,255,0.06)"},children:[i?.pr_url&&jsxRuntime.jsxs("a",{href:i.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...o.link("#60a5fa"),textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.pr,className:""}),i.pr_id||"PR"]}),i?.ticket_url&&jsxRuntime.jsxs("a",{href:i.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...o.link("#fbbf24"),textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.ticket,className:""}),i.ticket_id||"Ticket"]}),jsxRuntime.jsx("span",{style:{...o.badge(i?.environment||"custom"),marginLeft:"auto"},children:i?.environment})]}),jsxRuntime.jsx("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:"1px solid rgba(255,255,255,0.06)",background:"rgba(255,255,255,0.02)"},children:jsxRuntime.jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.2.4");},style:{fontSize:"9px",fontWeight:600,color:"rgba(255,255,255,0.5)",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:"rgba(255,255,255,0.3)"},children:"v0.2.4"})]})}),jsxRuntime.jsx("div",{style:o.progress,children:jsxRuntime.jsx("div",{style:o.progressBar(G)})})]}),y==="max"&&jsxRuntime.jsxs("div",{style:{...o.card(I.w,S),height:I.h,position:"relative"},children:[i?.assigned_human_display_name&&jsxRuntime.jsxs("div",{style:{padding:"4px 12px",fontSize:"9px",color:"#34d399",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:"4px",background:"rgba(52,211,153,0.05)"},children:[jsxRuntime.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"#34d399",display:"inline-block",flexShrink:0}}),i.assigned_human_display_name]}),jsxRuntime.jsxs("div",{style:o.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:()=>{K.current||m("expanded");},children:[jsxRuntime.jsx(g,{d:d.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:o.title,children:i?.title}),jsxRuntime.jsxs("div",{style:o.sub,children:[i?.created_by_agent_name&&jsxRuntime.jsxs("span",{children:["\u{1F916} ",i.created_by_agent_name]}),i?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",i.branch_name]})]})]}),jsxRuntime.jsx(g,{d:d.chevronDown,className:""}),jsxRuntime.jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxRuntime.jsxs("div",{style:o.stats,children:[jsxRuntime.jsxs("span",{style:{color:"#34d399"},children:[s.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:"#f87171"},children:[s.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:"#f59e0b"},children:[s.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:"#888"},children:[s.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:"#555",marginLeft:"auto"},children:s.total})]}),N==="error"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsxRuntime.jsx(g,{d:d.alert,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:"#f87171"},children:"Failed to load"}),jsxRuntime.jsx("button",{onClick:ge,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),S&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:"1px solid rgba(52,211,153,0.2)",background:"rgba(52,211,153,0.05)"},children:[jsxRuntime.jsx(g,{d:d.checkAll,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",color:"#34d399",flex:1},children:"Run completed"}),jsxRuntime.jsx("button",{onClick:fe,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),i?.intro_notes&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",borderBottom:"1px solid rgba(255,255,255,0.06)",fontSize:"10px",color:"rgba(255,255,255,0.4)",fontStyle:"italic",flexShrink:0},children:i.intro_notes}),N!=="error"&&jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(i?.test_cases||[]).length===0?jsxRuntime.jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:"#888"},children:"No test cases"}):(i?.test_cases||[]).map(t=>jsxRuntime.jsxs("div",{style:o.caseRow,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsx("div",{style:{marginTop:"2px",flexShrink:0},children:Y===t.id?jsxRuntime.jsx(g,{d:d.loader,className:""}):jsxRuntime.jsx(g,{d:he[t.verdict],className:""})}),jsxRuntime.jsxs("div",{style:{minWidth:0,flex:1},children:[jsxRuntime.jsx("div",{style:{fontSize:"10px",color:"#e5e5e5",lineHeight:1.3},children:t.title}),t.description&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:"#888",marginTop:"2px"},children:t.description}),t.url_path&&jsxRuntime.jsxs("a",{href:t.url_path,target:"_blank",rel:"noopener noreferrer",onClick:l=>{l.stopPropagation(),a&&(l.preventDefault(),a(t.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsxRuntime.jsx(g,{d:d.externalLink,className:""}),t.url_path]}),t.verdict==="fail"&&t.fail_reason&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:"#f87171",marginTop:"2px"},children:["\u2717 ",t.fail_reason]})]})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(l=>jsxRuntime.jsx("button",{onClick:()=>{if(t.verdict===l){D(t.id,"pending"),k(null);return}if(l==="fail"){D(t.id,"fail"),k(t.id),w("");return}k(null),D(t.id,l);},disabled:Y!==null,style:o.verdictBtn(t.verdict===l,l==="pass"?"#34d399":l==="fail"?"#f87171":"#f59e0b"),children:l.toUpperCase()},l)),t.verdict_by_display_name&&jsxRuntime.jsx("span",{style:{fontSize:"8px",color:"#555",marginLeft:"auto"},children:t.verdict_by_display_name})]}),oe===t.id&&t.verdict==="fail"&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:u,onChange:l=>w(l.target.value),onKeyDown:l=>{l.key==="Enter"&&u.trim()&&(D(t.id,"fail",u),k(null),w("")),l.key==="Escape"&&(k(null),w(""));},placeholder:"Reason (optional)...",style:o.input}),jsxRuntime.jsx("button",{onClick:()=>{u.trim()&&D(t.id,"fail",u),k(null),w("");},style:o.verdictBtn(true,"#f87171"),children:"\u2713"})]})]},t.id))}),xe&&!S&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",borderTop:"1px solid rgba(52,211,153,0.2)",background:"rgba(52,211,153,0.05)",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsxRuntime.jsx("span",{style:{fontSize:"9px",color:"#34d399"},children:"All resolved"}),jsxRuntime.jsx("button",{onClick:ue,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:"#34d399",border:"1px solid rgba(52,211,153,0.3)",cursor:"pointer"},children:"COMPLETE"})]}),jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:"1px solid rgba(255,255,255,0.06)",flexShrink:0},children:[i?.pr_url&&jsxRuntime.jsxs("a",{href:i.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...o.link("#60a5fa"),textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.pr,className:""}),i.pr_id||"PR"]}),i?.ticket_url&&jsxRuntime.jsxs("a",{href:i.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...o.link("#fbbf24"),textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.ticket,className:""}),i.ticket_id||"Ticket"]}),i?.created_by_agent_name&&jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:"#888"},children:["by ",i.created_by_agent_name]}),jsxRuntime.jsx("span",{style:{...o.badge(i?.environment||"custom"),marginLeft:"auto"},children:i?.environment})]}),jsxRuntime.jsx("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:"1px solid rgba(255,255,255,0.06)",background:"rgba(255,255,255,0.02)",flexShrink:0},children:jsxRuntime.jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.2.4");},style:{fontSize:"9px",fontWeight:600,color:"rgba(255,255,255,0.5)",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:"rgba(255,255,255,0.3)"},children:"v0.2.4"})]})}),jsxRuntime.jsx("div",{style:o.progress,children:jsxRuntime.jsx("div",{style:o.progressBar(G)})}),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:de,onPointerMove:pe,onPointerUp:ce,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{P.current||(t.currentTarget.style.opacity="0.3");},children:jsxRuntime.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsxRuntime.jsx("path",{d:"M7 1v6H1",fill:"none",stroke:"#888",strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}exports.TestRunWidget=ke;exports.useDraggable=A;exports.useTestRun=j;
1
+ 'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');function j(e,o){let[l,y]=react.useState({x:e,y:o}),b=react.useRef(false),f=react.useRef({x:0,y:0}),h=react.useRef(false),S=react.useCallback(x=>{b.current=true,h.current=false,f.current={x:x.clientX-l.x,y:x.clientY-l.y},x.target.setPointerCapture(x.pointerId);},[l]),v=react.useCallback(x=>{b.current&&(h.current=true,y({x:x.clientX-f.current.x,y:x.clientY-f.current.y}));},[]),p=react.useCallback(()=>{b.current=false;},[]);return {pos:l,onPointerDown:S,onPointerMove:v,onPointerUp:p,didDrag:h}}function J(e){let[o,l]=react.useState(null),[y,b]=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 x=await fetch(`${e.config.serverUrl}/widget/test-run?${p.toString()}`,{headers:{Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});if(x.status===404){b("no-match"),l(null);return}if(!x.ok){b("error");return}let k=await x.json();l(k),b(k.status==="completed"?"completed":"ready");}catch{b("error");}},[e.config.serverUrl,e.config.anonKey,e.appSlug,e.environment,e.testRunId,e.targetUrl,e.version,e.commitSha,e.branchName]);return react.useEffect(()=>{f();},[f]),{run:o,widgetState:y,fetchRun:f,setVerdict:async(p,x,k,T="human")=>(l(r=>{if(!r)return null;let s=r.test_cases.map(m=>m.id===p?{...m,verdict:x,fail_reason:x==="fail"&&k||null,verdict_by_display_name:T,verdict_at:new Date().toISOString()}:m),E={total:s.length,pending:0,pass:0,fail:0,skip:0};return s.forEach(m=>{m.verdict in E&&E[m.verdict]++;}),{...r,test_cases:s,summary:E}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${p}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey},body:JSON.stringify({verdict:x,fail_reason:k,display_name:T})})).ok),markComplete:async()=>{if(!o)return false;let p=await fetch(`${e.config.serverUrl}/widget/test-runs/${o.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});return p.ok&&f(),p.ok},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",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});return p.ok&&f(),p.ok},setRun:l}}var c=({d:e,className:o,size:l=14})=>jsxRuntime.jsx("svg",{className:o,width:l,height:l,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:e})}),d={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01",user:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2M12 3a4 4 0 1 0 0 8 4 4 0 0 0 0-8",bot:"M12 8V4H8M2 14h2M20 14h2M15 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M9 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M18 10a6 6 0 0 0-12 0v4a6 6 0 0 0 12 0Z"};function Re(){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 l=document.documentElement,y=()=>l.classList.contains("dark")?"dark":l.classList.contains("light")?"light":null,b=y();b&&o(b);let f=window.matchMedia("(prefers-color-scheme: dark)"),h=v=>{let p=y();o(p||(v.matches?"dark":"light"));};f.addEventListener("change",h);let S=new MutationObserver(()=>{let v=y();o(v||(f.matches?"dark":"light"));});return S.observe(l,{attributes:true,attributeFilter:["class"]}),()=>{f.removeEventListener("change",h),S.disconnect();}},[]),e}function ze(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 Ce={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},Te={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},de={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)"}},Be=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,l)=>({width:`${o}px`,borderRadius:"8px",background:e.bg,border:l?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:l?`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 l=de[o]||de.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:l.bg,color:l.text,border:`1px solid ${l.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,l)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:o?`${l}33`:"transparent",color:o?l: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"}}),pe="botbuddy-widget-state";function $e({config:e,appSlug:o,environment:l,testRunId:y,targetUrl:b,version:f,commitSha:h,prNumber:S,branchName:v,onNavigate:p,displayName:x="human",defaultMode:k="expanded",defaultPosition:T}){let H=Re(),r=react.useMemo(()=>ze(H),[H]),s=react.useMemo(()=>Be(r),[r]),m=(()=>{try{let t=typeof window<"u"?localStorage.getItem(pe):null;if(t)return JSON.parse(t)}catch{}return null})(),[B,W]=react.useState(m?.mode||k),[$,_]=react.useState(""),[ge,w]=react.useState(null),[X,Z]=react.useState(null),ue=m?.x??T?.x??16,xe=m?.y??T?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:R,onPointerDown:V,onPointerMove:F,onPointerUp:O,didDrag:K}=j(ue,xe);react.useEffect(()=>{try{localStorage.setItem(pe,JSON.stringify({mode:B,x:R.x,y:R.y}));}catch{}},[B,R.x,R.y]);let q="botbuddy-widget-max-size",fe=()=>{try{let t=localStorage.getItem(q);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[P,G]=react.useState(fe),I=react.useRef(false),L=react.useRef({x:0,y:0,w:0,h:0}),be=react.useCallback(t=>{t.stopPropagation(),I.current=true,L.current={x:t.clientX,y:t.clientY,w:P.w,h:P.h},t.target.setPointerCapture(t.pointerId);},[P]),me=react.useCallback(t=>{if(!I.current)return;let u=Math.max(280,Math.min(600,L.current.w+(t.clientX-L.current.x))),z=Math.max(300,Math.min(window.innerHeight*.9,L.current.h+(t.clientY-L.current.y)));G({w:u,h:z});},[]),ye=react.useCallback(()=>{I.current&&(I.current=false,G(t=>(localStorage.setItem(q,JSON.stringify(t)),t)));},[]),{run:a,widgetState:D,fetchRun:he,setVerdict:Q,markComplete:ve,resetRun:Se}=J({config:e,appSlug:o,environment:l,testRunId:y,targetUrl:b,version:f,commitSha:h,prNumber:S?String(S):void 0,branchName:v}),N=react.useCallback(async(t,u,z)=>{Z(t);try{await Q(t,u,z,x);}finally{Z(null),w(null),_("");}},[Q,x]),g=a?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},ke=g.total>0&&g.pending===0,M=D==="completed",ee=g.total>0?(g.pass+g.fail)/g.total*100:0;if(D==="no-match"||D==="loading")return null;let ne=()=>{K.current||W(t=>t==="mini"?"expanded":t==="expanded"?"max":"mini");},te=({icon:t,onClick:u})=>jsxRuntime.jsx("button",{style:s.btn,onClick:z=>{z.stopPropagation(),u(z);},children:jsxRuntime.jsx(c,{d:t,className:""})}),re=()=>{if(!a?.assigned_human_display_name)return null;let t=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:r.green,display:"inline-block",flexShrink:0,boxShadow:`0 0 6px ${r.green}66`}}),jsxRuntime.jsx(c,{d:d.user,size:13}),jsxRuntime.jsx("span",{style:{flex:1},children:a.assigned_human_display_name}),a.codex_thread_id&&jsxRuntime.jsx(c,{d:d.externalLink,size:10})]});return a.codex_thread_id?jsxRuntime.jsx("a",{href:`codex://threads/${a.codex_thread_id}`,style:s.humanBanner,children:t}):jsxRuntime.jsx("div",{style:s.humanBanner,children:t})},oe=()=>jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${r.borderSubtle}`,flexShrink:0},children:[a?.pr_url&&jsxRuntime.jsxs("a",{href:a.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...s.link(r.blue),textDecoration:"none"},children:[jsxRuntime.jsx(c,{d:d.pr,size:12}),a.pr_id||"PR",jsxRuntime.jsx(c,{d:d.externalLink,size:8})]}),a?.ticket_url&&jsxRuntime.jsxs("a",{href:a.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...s.link(r.amber),textDecoration:"none"},children:[jsxRuntime.jsx(c,{d:d.ticket,size:12}),a.ticket_id||"Ticket",jsxRuntime.jsx(c,{d:d.externalLink,size:8})]}),a?.created_by_agent_name&&(a.codex_thread_id?jsxRuntime.jsxs("a",{href:`codex://threads/${a.codex_thread_id}`,style:{...s.link(r.purple),textDecoration:"none"},children:[jsxRuntime.jsx(c,{d:d.bot,size:12}),a.created_by_agent_name,jsxRuntime.jsx(c,{d:d.externalLink,size:8})]}):jsxRuntime.jsxs("span",{style:{...s.link(r.purple)},children:[jsxRuntime.jsx(c,{d:d.bot,size:12}),a.created_by_agent_name]})),jsxRuntime.jsx("span",{style:{...s.badge(a?.environment||"custom"),marginLeft:"auto"},children:a?.environment})]}),ie=()=>jsxRuntime.jsx("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:`1px solid ${r.borderSubtle}`,background:r.bgSoft,flexShrink:0},children:jsxRuntime.jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.2.8");},style:{fontSize:"9px",fontWeight:600,color:r.versionText,letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxRuntime.jsx("span",{style:{color:r.versionNum},children:"v0.2.8"})]})});return jsxRuntime.jsxs("div",{style:{...s.root,left:R.x,top:R.y},children:[B==="mini"&&jsxRuntime.jsxs("div",{style:s.pill(M),onPointerDown:V,onPointerMove:F,onPointerUp:()=>{O(),K.current||ne();},children:[M?jsxRuntime.jsx(c,{d:d.checkAll,className:""}):jsxRuntime.jsx(c,{d:d.clipboard,className:""}),jsxRuntime.jsxs("span",{style:M?{color:r.green}:void 0,children:[g.pass,"/",g.total]}),g.fail>0&&jsxRuntime.jsxs("span",{style:{color:r.red},children:[g.fail,"\u2717"]}),g.skip>0&&jsxRuntime.jsxs("span",{style:{color:r.amber},children:[g.skip,"\u23ED"]}),a?.pr_url&&jsxRuntime.jsxs("span",{style:{...s.link(r.blue),pointerEvents:"none",textDecoration:"none"},children:[jsxRuntime.jsx(c,{d:d.pr,className:""}),a.pr_id||"PR"]}),a?.ticket_url&&jsxRuntime.jsxs("span",{style:{...s.link(r.amber),pointerEvents:"none",textDecoration:"none"},children:[jsxRuntime.jsx(c,{d:d.ticket,className:""}),a.ticket_id||"TKT"]})]}),B==="expanded"&&jsxRuntime.jsxs("div",{style:s.card(300,M),children:[jsxRuntime.jsx(re,{}),jsxRuntime.jsxs("div",{style:s.handle,onPointerDown:V,onPointerMove:F,onPointerUp:O,onClick:ne,children:[jsxRuntime.jsx(c,{d:d.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:s.title,children:a?.title}),jsxRuntime.jsx("div",{style:s.sub,children:a?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",a.branch_name]})})]}),jsxRuntime.jsx(c,{d:d.chevronUp,className:""}),jsxRuntime.jsx(te,{icon:d.minus,onClick:()=>W("mini")})]}),jsxRuntime.jsxs("div",{style:s.stats,children:[jsxRuntime.jsxs("span",{style:{color:r.green},children:[g.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:r.red},children:[g.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:r.amber},children:[g.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:r.gripColor},children:[g.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:g.total})]}),a?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:r.gripColor,borderBottom:`1px solid ${r.borderSubtle}`,flexShrink:0},children:a.description}),jsxRuntime.jsx(oe,{}),jsxRuntime.jsx(ie,{}),jsxRuntime.jsx("div",{style:s.progress,children:jsxRuntime.jsx("div",{style:s.progressBar(ee)})})]}),B==="max"&&jsxRuntime.jsxs("div",{style:{...s.card(P.w,M),height:P.h,position:"relative"},children:[jsxRuntime.jsx(re,{}),jsxRuntime.jsxs("div",{style:s.handle,onPointerDown:V,onPointerMove:F,onPointerUp:O,onClick:()=>{K.current||W("expanded");},children:[jsxRuntime.jsx(c,{d:d.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:s.title,children:a?.title}),jsxRuntime.jsx("div",{style:s.sub,children:a?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",a.branch_name]})})]}),jsxRuntime.jsx(c,{d:d.chevronDown,className:""}),jsxRuntime.jsx(te,{icon:d.minus,onClick:()=>W("mini")})]}),jsxRuntime.jsxs("div",{style:s.stats,children:[jsxRuntime.jsxs("span",{style:{color:r.green},children:[g.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:r.red},children:[g.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:r.amber},children:[g.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:r.gripColor},children:[g.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:g.total})]}),D==="error"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsxRuntime.jsx(c,{d:d.alert,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:r.red},children:"Failed to load"}),jsxRuntime.jsx("button",{onClick:he,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),M&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg},children:[jsxRuntime.jsx(c,{d:d.checkAll,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",color:r.green,flex:1},children:"Run completed"}),jsxRuntime.jsx("button",{onClick:Se,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),a?.intro_notes&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${r.borderSubtle}`,fontSize:"10px",color:r.textMuted,fontStyle:"italic",flexShrink:0},children:a.intro_notes}),D!=="error"&&jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(a?.test_cases||[]).length===0?jsxRuntime.jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:"No test cases"}):(a?.test_cases||[]).map(t=>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:Ce[t.verdict]},children:X===t.id?jsxRuntime.jsx(c,{d:d.loader,className:""}):jsxRuntime.jsx(c,{d:Te[t.verdict],className:""})}),jsxRuntime.jsxs("div",{style:{minWidth:0,flex:1},children:[jsxRuntime.jsx("div",{style:{fontSize:"10px",color:r.text,lineHeight:1.3},children:t.title}),t.description&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:r.gripColor,marginTop:"2px"},children:t.description}),t.url_path&&jsxRuntime.jsxs("a",{href:t.url_path,target:"_blank",rel:"noopener noreferrer",onClick:u=>{u.stopPropagation(),p&&(u.preventDefault(),p(t.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsxRuntime.jsx(c,{d:d.externalLink,size:10}),t.url_path]}),t.verdict==="fail"&&t.fail_reason&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:r.red,marginTop:"2px"},children:["\u2717 ",t.fail_reason]})]})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(u=>jsxRuntime.jsx("button",{onClick:()=>{if(t.verdict===u){N(t.id,"pending"),w(null);return}if(u==="fail"){N(t.id,"fail"),w(t.id),_("");return}w(null),N(t.id,u);},disabled:X!==null,style:s.verdictBtn(t.verdict===u,u==="pass"?r.green:u==="fail"?r.red:r.amber),children:u.toUpperCase()},u)),t.verdict_by_display_name&&jsxRuntime.jsx("span",{style:{fontSize:"8px",color:r.textFaint,marginLeft:"auto"},children:t.verdict_by_display_name})]}),ge===t.id&&t.verdict==="fail"&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:$,onChange:u=>_(u.target.value),onKeyDown:u=>{u.key==="Enter"&&$.trim()&&(N(t.id,"fail",$),w(null),_("")),u.key==="Escape"&&(w(null),_(""));},placeholder:"Reason (optional)...",style:s.input}),jsxRuntime.jsx("button",{onClick:()=>{$.trim()&&N(t.id,"fail",$),w(null),_("");},style:s.verdictBtn(true,r.red),children:"\u2713"})]})]},t.id))}),ke&&!M&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",borderTop:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg,display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsxRuntime.jsx("span",{style:{fontSize:"9px",color:r.green},children:"All resolved"}),jsxRuntime.jsx("button",{onClick:ve,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:r.green,border:`1px solid ${r.greenBorderSubtle}`,cursor:"pointer"},children:"COMPLETE"})]}),jsxRuntime.jsx(oe,{}),jsxRuntime.jsx(ie,{}),jsxRuntime.jsx("div",{style:s.progress,children:jsxRuntime.jsx("div",{style:s.progressBar(ee)})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:0,right:0,width:16,height:16,cursor:"se-resize",zIndex:10,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:"2px",opacity:.3},onPointerDown:be,onPointerMove:me,onPointerUp:ye,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{I.current||(t.currentTarget.style.opacity="0.3");},children:jsxRuntime.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsxRuntime.jsx("path",{d:"M7 1v6H1",fill:"none",stroke:r.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}
2
+ exports.TestRunWidget=$e;exports.useDraggable=j;exports.useTestRun=J;
package/dist/index.d.cts CHANGED
@@ -21,6 +21,7 @@ interface TestRun {
21
21
  pr_url: string | null;
22
22
  pr_number: number | null;
23
23
  summary: TestRunSummary;
24
+ codex_thread_id: string | null;
24
25
  test_cases: TestCase[];
25
26
  }
26
27
  interface TestRunSummary {
package/dist/index.d.ts CHANGED
@@ -21,6 +21,7 @@ interface TestRun {
21
21
  pr_url: string | null;
22
22
  pr_number: number | null;
23
23
  summary: TestRunSummary;
24
+ codex_thread_id: string | null;
24
25
  test_cases: TestCase[];
25
26
  }
26
27
  interface TestRunSummary {
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
- import {useState,useRef,useCallback,useEffect}from'react';import {jsxs,jsx}from'react/jsx-runtime';function A(n,p){let[f,T]=useState({x:n,y:p}),b=useRef(false),x=useRef({x:0,y:0}),_=useRef(false),z=useCallback(c=>{b.current=true,_.current=false,x.current={x:c.clientX-f.x,y:c.clientY-f.y},c.target.setPointerCapture(c.pointerId);},[f]),E=useCallback(c=>{b.current&&(_.current=true,T({x:c.clientX-x.current.x,y:c.clientY-x.current.y}));},[]),a=useCallback(()=>{b.current=false;},[]);return {pos:f,onPointerDown:z,onPointerMove:E,onPointerUp:a,didDrag:_}}function j(n){let[p,f]=useState(null),[T,b]=useState("loading"),x=useCallback(async()=>{try{let a=new URLSearchParams;n.testRunId&&a.set("test_run_id",n.testRunId),n.targetUrl&&a.set("target_url",n.targetUrl),a.set("app_slug",n.appSlug),a.set("environment",n.environment),n.version&&a.set("version",n.version),n.commitSha&&a.set("commit_sha",n.commitSha),n.prNumber&&a.set("pr_number",String(n.prNumber)),n.branchName&&a.set("branch_name",n.branchName);let c=await fetch(`${n.config.serverUrl}/widget/test-run?${a.toString()}`,{headers:{Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});if(c.status===404){b("no-match"),f(null);return}if(!c.ok){b("error");return}let v=await c.json();f(v),b(v.status==="completed"?"completed":"ready");}catch{b("error");}},[n.config.serverUrl,n.config.anonKey,n.appSlug,n.environment,n.testRunId,n.targetUrl,n.version,n.commitSha,n.branchName]);return useEffect(()=>{x();},[x]),{run:p,widgetState:T,fetchRun:x,setVerdict:async(a,c,v,C="human")=>(f(h=>{if(!h)return null;let y=h.test_cases.map(u=>u.id===a?{...u,verdict:c,fail_reason:c==="fail"&&v||null,verdict_by_display_name:C,verdict_at:new Date().toISOString()}:u),m={total:y.length,pending:0,pass:0,fail:0,skip:0};return y.forEach(u=>{u.verdict in m&&m[u.verdict]++;}),{...h,test_cases:y,summary:m}}),(await fetch(`${n.config.serverUrl}/widget/test-cases/${a}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey},body:JSON.stringify({verdict:c,fail_reason:v,display_name:C})})).ok),markComplete:async()=>{if(!p)return false;let a=await fetch(`${n.config.serverUrl}/widget/test-runs/${p.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});return a.ok&&x(),a.ok},resetRun:async()=>{if(!p)return false;let a=await fetch(`${n.config.serverUrl}/widget/test-runs/${p.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});return a.ok&&x(),a.ok},setRun:f}}var g=({d:n,className:p})=>jsx("svg",{className:p,width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:n})}),d={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01"};var he={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},te={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)"}},o={root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:n=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:"rgb(30,30,30)",border:n?"1px solid rgba(52,211,153,0.6)":"1px solid rgba(255,255,255,0.15)",boxShadow:n?"0 4px 12px rgba(0,0,0,0.3), 0 0 0 1px rgba(52,211,153,0.2)":"0 4px 12px rgba(0,0,0,0.3)",cursor:"pointer",fontSize:"9px",color:"#e5e5e5"}),card:(n,p)=>({width:`${n}px`,borderRadius:"8px",background:"rgb(30,30,30)",border:p?"1px solid rgba(52,211,153,0.6)":"1px solid rgba(255,255,255,0.15)",boxShadow:p?"0 8px 24px rgba(0,0,0,0.4), 0 0 0 1px rgba(52,211,153,0.2)":"0 8px 24px rgba(0,0,0,0.4)",overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:"1px solid rgba(255,255,255,0.06)"},title:{fontSize:"10px",fontWeight:600,color:"#e5e5e5",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:"rgba(255,255,255,0.4)",display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:"#888",display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:"1px solid rgba(255,255,255,0.06)"},badge:n=>{let p=te[n]||te.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:p.bg,color:p.text,border:`1px solid ${p.border}`,lineHeight:"14px"}},progress:{height:"2px",background:"rgba(255,255,255,0.06)",flexShrink:0},progressBar:n=>({height:"100%",width:`${n}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:n=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${n}15`,color:n,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:"1px solid rgba(255,255,255,0.06)",transition:"background 0.15s"},verdictBtn:(n,p)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:n?`${p}33`:"transparent",color:n?p:"#888",transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:"rgba(0,0,0,0.3)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"4px",padding:"2px 6px",color:"#e5e5e5",outline:"none"}},re="botbuddy-widget-state";function ke({config:n,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:_,prNumber:z,branchName:E,onNavigate:a,displayName:c="human",defaultMode:v="expanded",defaultPosition:C}){let h=(()=>{try{let t=typeof window<"u"?localStorage.getItem(re):null;if(t)return JSON.parse(t)}catch{}return null})(),[y,m]=useState(h?.mode||v),[u,w]=useState(""),[oe,k]=useState(null),[Y,F]=useState(null),ae=h?.x??C?.x??16,se=h?.y??C?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:M,onPointerDown:U,onPointerMove:$,onPointerUp:V,didDrag:K}=A(ae,se);useEffect(()=>{try{localStorage.setItem(re,JSON.stringify({mode:y,x:M.x,y:M.y}));}catch{}},[y,M.x,M.y]);let J="botbuddy-widget-max-size",le=()=>{try{let t=localStorage.getItem(J);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[I,X]=useState(le),P=useRef(false),B=useRef({x:0,y:0,w:0,h:0}),de=useCallback(t=>{t.stopPropagation(),P.current=true,B.current={x:t.clientX,y:t.clientY,w:I.w,h:I.h},t.target.setPointerCapture(t.pointerId);},[I]),pe=useCallback(t=>{if(!P.current)return;let l=Math.max(280,Math.min(600,B.current.w+(t.clientX-B.current.x))),R=Math.max(300,Math.min(window.innerHeight*.9,B.current.h+(t.clientY-B.current.y)));X({w:l,h:R});},[]),ce=useCallback(()=>{P.current&&(P.current=false,X(t=>(localStorage.setItem(J,JSON.stringify(t)),t)));},[]),{run:i,widgetState:N,fetchRun:ge,setVerdict:Z,markComplete:ue,resetRun:fe}=j({config:n,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:_,prNumber:z?String(z):void 0,branchName:E}),D=useCallback(async(t,l,R)=>{F(t);try{await Z(t,l,R,c);}finally{F(null),k(null),w("");}},[Z,c]),s=i?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},xe=s.total>0&&s.pending===0,S=N==="completed",G=s.total>0?(s.pass+s.fail)/s.total*100:0;if(N==="no-match"||N==="loading")return null;let q=()=>{K.current||m(t=>t==="mini"?"expanded":t==="expanded"?"max":"mini");},Q=({icon:t,onClick:l})=>jsx("button",{style:o.btn,onClick:R=>{R.stopPropagation(),l(R);},children:jsx(g,{d:t,className:""})});return jsxs("div",{style:{...o.root,left:M.x,top:M.y},children:[y==="mini"&&jsxs("div",{style:o.pill(S),onPointerDown:U,onPointerMove:$,onPointerUp:()=>{V(),K.current||q();},children:[S?jsx(g,{d:d.checkAll,className:""}):jsx(g,{d:d.clipboard,className:""}),jsxs("span",{style:S?{color:"#34d399"}:void 0,children:[s.pass,"/",s.total]}),s.fail>0&&jsxs("span",{style:{color:"#f87171"},children:[s.fail,"\u2717"]}),s.skip>0&&jsxs("span",{style:{color:"#f59e0b"},children:[s.skip,"\u23ED"]}),i?.pr_url&&jsxs("span",{style:{...o.link("#60a5fa"),pointerEvents:"none",textDecoration:"none"},children:[jsx(g,{d:d.pr,className:""}),i.pr_id||"PR"]}),i?.ticket_url&&jsxs("span",{style:{...o.link("#fbbf24"),pointerEvents:"none",textDecoration:"none"},children:[jsx(g,{d:d.ticket,className:""}),i.ticket_id||"TKT"]})]}),y==="expanded"&&jsxs("div",{style:o.card(300,S),children:[i?.assigned_human_display_name&&jsxs("div",{style:{padding:"4px 12px",fontSize:"9px",color:"#34d399",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:"4px",background:"rgba(52,211,153,0.05)"},children:[jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"#34d399",display:"inline-block",flexShrink:0}}),i.assigned_human_display_name]}),jsxs("div",{style:o.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:q,children:[jsx(g,{d:d.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:o.title,children:i?.title}),jsxs("div",{style:o.sub,children:[i?.created_by_agent_name&&jsxs("span",{children:["\u{1F916} ",i.created_by_agent_name]}),i?.branch_name&&jsxs("span",{children:["\u2387 ",i.branch_name]})]})]}),jsx(g,{d:d.chevronUp,className:""}),jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxs("div",{style:o.stats,children:[jsxs("span",{style:{color:"#34d399"},children:[s.pass,"\u2713"]}),jsxs("span",{style:{color:"#f87171"},children:[s.fail,"\u2717"]}),jsxs("span",{style:{color:"#f59e0b"},children:[s.skip,"\u23ED"]}),jsxs("span",{style:{color:"#888"},children:[s.pending,"\u25CC"]}),jsx("span",{style:{color:"#555",marginLeft:"auto"},children:s.total})]}),i?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:"#888",borderBottom:"1px solid rgba(255,255,255,0.06)",flexShrink:0},children:i.description}),jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:"1px solid rgba(255,255,255,0.06)"},children:[i?.pr_url&&jsxs("a",{href:i.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...o.link("#60a5fa"),textDecoration:"none"},children:[jsx(g,{d:d.pr,className:""}),i.pr_id||"PR"]}),i?.ticket_url&&jsxs("a",{href:i.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...o.link("#fbbf24"),textDecoration:"none"},children:[jsx(g,{d:d.ticket,className:""}),i.ticket_id||"Ticket"]}),jsx("span",{style:{...o.badge(i?.environment||"custom"),marginLeft:"auto"},children:i?.environment})]}),jsx("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:"1px solid rgba(255,255,255,0.06)",background:"rgba(255,255,255,0.02)"},children:jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.2.4");},style:{fontSize:"9px",fontWeight:600,color:"rgba(255,255,255,0.5)",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:"rgba(255,255,255,0.3)"},children:"v0.2.4"})]})}),jsx("div",{style:o.progress,children:jsx("div",{style:o.progressBar(G)})})]}),y==="max"&&jsxs("div",{style:{...o.card(I.w,S),height:I.h,position:"relative"},children:[i?.assigned_human_display_name&&jsxs("div",{style:{padding:"4px 12px",fontSize:"9px",color:"#34d399",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:"4px",background:"rgba(52,211,153,0.05)"},children:[jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"#34d399",display:"inline-block",flexShrink:0}}),i.assigned_human_display_name]}),jsxs("div",{style:o.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:()=>{K.current||m("expanded");},children:[jsx(g,{d:d.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:o.title,children:i?.title}),jsxs("div",{style:o.sub,children:[i?.created_by_agent_name&&jsxs("span",{children:["\u{1F916} ",i.created_by_agent_name]}),i?.branch_name&&jsxs("span",{children:["\u2387 ",i.branch_name]})]})]}),jsx(g,{d:d.chevronDown,className:""}),jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxs("div",{style:o.stats,children:[jsxs("span",{style:{color:"#34d399"},children:[s.pass,"\u2713"]}),jsxs("span",{style:{color:"#f87171"},children:[s.fail,"\u2717"]}),jsxs("span",{style:{color:"#f59e0b"},children:[s.skip,"\u23ED"]}),jsxs("span",{style:{color:"#888"},children:[s.pending,"\u25CC"]}),jsx("span",{style:{color:"#555",marginLeft:"auto"},children:s.total})]}),N==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(g,{d:d.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:"#f87171"},children:"Failed to load"}),jsx("button",{onClick:ge,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),S&&jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:"1px solid rgba(52,211,153,0.2)",background:"rgba(52,211,153,0.05)"},children:[jsx(g,{d:d.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:"#34d399",flex:1},children:"Run completed"}),jsx("button",{onClick:fe,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),i?.intro_notes&&jsx("div",{style:{padding:"6px 12px",borderBottom:"1px solid rgba(255,255,255,0.06)",fontSize:"10px",color:"rgba(255,255,255,0.4)",fontStyle:"italic",flexShrink:0},children:i.intro_notes}),N!=="error"&&jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(i?.test_cases||[]).length===0?jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:"#888"},children:"No test cases"}):(i?.test_cases||[]).map(t=>jsxs("div",{style:o.caseRow,children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsx("div",{style:{marginTop:"2px",flexShrink:0},children:Y===t.id?jsx(g,{d:d.loader,className:""}):jsx(g,{d:he[t.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:"#e5e5e5",lineHeight:1.3},children:t.title}),t.description&&jsx("div",{style:{fontSize:"9px",color:"#888",marginTop:"2px"},children:t.description}),t.url_path&&jsxs("a",{href:t.url_path,target:"_blank",rel:"noopener noreferrer",onClick:l=>{l.stopPropagation(),a&&(l.preventDefault(),a(t.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsx(g,{d:d.externalLink,className:""}),t.url_path]}),t.verdict==="fail"&&t.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:"#f87171",marginTop:"2px"},children:["\u2717 ",t.fail_reason]})]})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(l=>jsx("button",{onClick:()=>{if(t.verdict===l){D(t.id,"pending"),k(null);return}if(l==="fail"){D(t.id,"fail"),k(t.id),w("");return}k(null),D(t.id,l);},disabled:Y!==null,style:o.verdictBtn(t.verdict===l,l==="pass"?"#34d399":l==="fail"?"#f87171":"#f59e0b"),children:l.toUpperCase()},l)),t.verdict_by_display_name&&jsx("span",{style:{fontSize:"8px",color:"#555",marginLeft:"auto"},children:t.verdict_by_display_name})]}),oe===t.id&&t.verdict==="fail"&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:u,onChange:l=>w(l.target.value),onKeyDown:l=>{l.key==="Enter"&&u.trim()&&(D(t.id,"fail",u),k(null),w("")),l.key==="Escape"&&(k(null),w(""));},placeholder:"Reason (optional)...",style:o.input}),jsx("button",{onClick:()=>{u.trim()&&D(t.id,"fail",u),k(null),w("");},style:o.verdictBtn(true,"#f87171"),children:"\u2713"})]})]},t.id))}),xe&&!S&&jsxs("div",{style:{padding:"6px 12px",borderTop:"1px solid rgba(52,211,153,0.2)",background:"rgba(52,211,153,0.05)",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsx("span",{style:{fontSize:"9px",color:"#34d399"},children:"All resolved"}),jsx("button",{onClick:ue,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:"#34d399",border:"1px solid rgba(52,211,153,0.3)",cursor:"pointer"},children:"COMPLETE"})]}),jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:"1px solid rgba(255,255,255,0.06)",flexShrink:0},children:[i?.pr_url&&jsxs("a",{href:i.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...o.link("#60a5fa"),textDecoration:"none"},children:[jsx(g,{d:d.pr,className:""}),i.pr_id||"PR"]}),i?.ticket_url&&jsxs("a",{href:i.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...o.link("#fbbf24"),textDecoration:"none"},children:[jsx(g,{d:d.ticket,className:""}),i.ticket_id||"Ticket"]}),i?.created_by_agent_name&&jsxs("span",{style:{fontSize:"9px",color:"#888"},children:["by ",i.created_by_agent_name]}),jsx("span",{style:{...o.badge(i?.environment||"custom"),marginLeft:"auto"},children:i?.environment})]}),jsx("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:"1px solid rgba(255,255,255,0.06)",background:"rgba(255,255,255,0.02)",flexShrink:0},children:jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.2.4");},style:{fontSize:"9px",fontWeight:600,color:"rgba(255,255,255,0.5)",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:"rgba(255,255,255,0.3)"},children:"v0.2.4"})]})}),jsx("div",{style:o.progress,children:jsx("div",{style:o.progressBar(G)})}),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:de,onPointerMove:pe,onPointerUp:ce,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{P.current||(t.currentTarget.style.opacity="0.3");},children:jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsx("path",{d:"M7 1v6H1",fill:"none",stroke:"#888",strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}export{ke as TestRunWidget,A as useDraggable,j as useTestRun};
1
+ import {useState,useRef,useCallback,useEffect,useMemo}from'react';import {jsxs,jsx,Fragment}from'react/jsx-runtime';function j(e,o){let[l,y]=useState({x:e,y:o}),b=useRef(false),f=useRef({x:0,y:0}),h=useRef(false),S=useCallback(x=>{b.current=true,h.current=false,f.current={x:x.clientX-l.x,y:x.clientY-l.y},x.target.setPointerCapture(x.pointerId);},[l]),v=useCallback(x=>{b.current&&(h.current=true,y({x:x.clientX-f.current.x,y:x.clientY-f.current.y}));},[]),p=useCallback(()=>{b.current=false;},[]);return {pos:l,onPointerDown:S,onPointerMove:v,onPointerUp:p,didDrag:h}}function J(e){let[o,l]=useState(null),[y,b]=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 x=await fetch(`${e.config.serverUrl}/widget/test-run?${p.toString()}`,{headers:{Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});if(x.status===404){b("no-match"),l(null);return}if(!x.ok){b("error");return}let k=await x.json();l(k),b(k.status==="completed"?"completed":"ready");}catch{b("error");}},[e.config.serverUrl,e.config.anonKey,e.appSlug,e.environment,e.testRunId,e.targetUrl,e.version,e.commitSha,e.branchName]);return useEffect(()=>{f();},[f]),{run:o,widgetState:y,fetchRun:f,setVerdict:async(p,x,k,T="human")=>(l(r=>{if(!r)return null;let s=r.test_cases.map(m=>m.id===p?{...m,verdict:x,fail_reason:x==="fail"&&k||null,verdict_by_display_name:T,verdict_at:new Date().toISOString()}:m),E={total:s.length,pending:0,pass:0,fail:0,skip:0};return s.forEach(m=>{m.verdict in E&&E[m.verdict]++;}),{...r,test_cases:s,summary:E}}),(await fetch(`${e.config.serverUrl}/widget/test-cases/${p}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey},body:JSON.stringify({verdict:x,fail_reason:k,display_name:T})})).ok),markComplete:async()=>{if(!o)return false;let p=await fetch(`${e.config.serverUrl}/widget/test-runs/${o.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});return p.ok&&f(),p.ok},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",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});return p.ok&&f(),p.ok},setRun:l}}var c=({d:e,className:o,size:l=14})=>jsx("svg",{className:o,width:l,height:l,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:e})}),d={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01",user:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2M12 3a4 4 0 1 0 0 8 4 4 0 0 0 0-8",bot:"M12 8V4H8M2 14h2M20 14h2M15 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M9 13a1 1 0 1 0 0 2 1 1 0 0 0 0-2M18 10a6 6 0 0 0-12 0v4a6 6 0 0 0 12 0Z"};function Re(){let[e,o]=useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return useEffect(()=>{if(typeof window>"u")return;let l=document.documentElement,y=()=>l.classList.contains("dark")?"dark":l.classList.contains("light")?"light":null,b=y();b&&o(b);let f=window.matchMedia("(prefers-color-scheme: dark)"),h=v=>{let p=y();o(p||(v.matches?"dark":"light"));};f.addEventListener("change",h);let S=new MutationObserver(()=>{let v=y();o(v||(f.matches?"dark":"light"));});return S.observe(l,{attributes:true,attributeFilter:["class"]}),()=>{f.removeEventListener("change",h),S.disconnect();}},[]),e}function ze(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 Ce={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},Te={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},de={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)"}},Be=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,l)=>({width:`${o}px`,borderRadius:"8px",background:e.bg,border:l?`1px solid ${e.greenBorder}`:`1px solid ${e.border}`,boxShadow:l?`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 l=de[o]||de.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:l.bg,color:l.text,border:`1px solid ${l.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,l)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:o?`${l}33`:"transparent",color:o?l: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"}}),pe="botbuddy-widget-state";function $e({config:e,appSlug:o,environment:l,testRunId:y,targetUrl:b,version:f,commitSha:h,prNumber:S,branchName:v,onNavigate:p,displayName:x="human",defaultMode:k="expanded",defaultPosition:T}){let H=Re(),r=useMemo(()=>ze(H),[H]),s=useMemo(()=>Be(r),[r]),m=(()=>{try{let t=typeof window<"u"?localStorage.getItem(pe):null;if(t)return JSON.parse(t)}catch{}return null})(),[B,W]=useState(m?.mode||k),[$,_]=useState(""),[ge,w]=useState(null),[X,Z]=useState(null),ue=m?.x??T?.x??16,xe=m?.y??T?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:R,onPointerDown:V,onPointerMove:F,onPointerUp:O,didDrag:K}=j(ue,xe);useEffect(()=>{try{localStorage.setItem(pe,JSON.stringify({mode:B,x:R.x,y:R.y}));}catch{}},[B,R.x,R.y]);let q="botbuddy-widget-max-size",fe=()=>{try{let t=localStorage.getItem(q);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[P,G]=useState(fe),I=useRef(false),L=useRef({x:0,y:0,w:0,h:0}),be=useCallback(t=>{t.stopPropagation(),I.current=true,L.current={x:t.clientX,y:t.clientY,w:P.w,h:P.h},t.target.setPointerCapture(t.pointerId);},[P]),me=useCallback(t=>{if(!I.current)return;let u=Math.max(280,Math.min(600,L.current.w+(t.clientX-L.current.x))),z=Math.max(300,Math.min(window.innerHeight*.9,L.current.h+(t.clientY-L.current.y)));G({w:u,h:z});},[]),ye=useCallback(()=>{I.current&&(I.current=false,G(t=>(localStorage.setItem(q,JSON.stringify(t)),t)));},[]),{run:a,widgetState:D,fetchRun:he,setVerdict:Q,markComplete:ve,resetRun:Se}=J({config:e,appSlug:o,environment:l,testRunId:y,targetUrl:b,version:f,commitSha:h,prNumber:S?String(S):void 0,branchName:v}),N=useCallback(async(t,u,z)=>{Z(t);try{await Q(t,u,z,x);}finally{Z(null),w(null),_("");}},[Q,x]),g=a?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},ke=g.total>0&&g.pending===0,M=D==="completed",ee=g.total>0?(g.pass+g.fail)/g.total*100:0;if(D==="no-match"||D==="loading")return null;let ne=()=>{K.current||W(t=>t==="mini"?"expanded":t==="expanded"?"max":"mini");},te=({icon:t,onClick:u})=>jsx("button",{style:s.btn,onClick:z=>{z.stopPropagation(),u(z);},children:jsx(c,{d:t,className:""})}),re=()=>{if(!a?.assigned_human_display_name)return null;let t=jsxs(Fragment,{children:[jsx("span",{style:{width:7,height:7,borderRadius:"50%",background:r.green,display:"inline-block",flexShrink:0,boxShadow:`0 0 6px ${r.green}66`}}),jsx(c,{d:d.user,size:13}),jsx("span",{style:{flex:1},children:a.assigned_human_display_name}),a.codex_thread_id&&jsx(c,{d:d.externalLink,size:10})]});return a.codex_thread_id?jsx("a",{href:`codex://threads/${a.codex_thread_id}`,style:s.humanBanner,children:t}):jsx("div",{style:s.humanBanner,children:t})},oe=()=>jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:`1px solid ${r.borderSubtle}`,flexShrink:0},children:[a?.pr_url&&jsxs("a",{href:a.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...s.link(r.blue),textDecoration:"none"},children:[jsx(c,{d:d.pr,size:12}),a.pr_id||"PR",jsx(c,{d:d.externalLink,size:8})]}),a?.ticket_url&&jsxs("a",{href:a.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...s.link(r.amber),textDecoration:"none"},children:[jsx(c,{d:d.ticket,size:12}),a.ticket_id||"Ticket",jsx(c,{d:d.externalLink,size:8})]}),a?.created_by_agent_name&&(a.codex_thread_id?jsxs("a",{href:`codex://threads/${a.codex_thread_id}`,style:{...s.link(r.purple),textDecoration:"none"},children:[jsx(c,{d:d.bot,size:12}),a.created_by_agent_name,jsx(c,{d:d.externalLink,size:8})]}):jsxs("span",{style:{...s.link(r.purple)},children:[jsx(c,{d:d.bot,size:12}),a.created_by_agent_name]})),jsx("span",{style:{...s.badge(a?.environment||"custom"),marginLeft:"auto"},children:a?.environment})]}),ie=()=>jsx("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:`1px solid ${r.borderSubtle}`,background:r.bgSoft,flexShrink:0},children:jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.2.8");},style:{fontSize:"9px",fontWeight:600,color:r.versionText,letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsx("span",{style:{color:r.versionNum},children:"v0.2.8"})]})});return jsxs("div",{style:{...s.root,left:R.x,top:R.y},children:[B==="mini"&&jsxs("div",{style:s.pill(M),onPointerDown:V,onPointerMove:F,onPointerUp:()=>{O(),K.current||ne();},children:[M?jsx(c,{d:d.checkAll,className:""}):jsx(c,{d:d.clipboard,className:""}),jsxs("span",{style:M?{color:r.green}:void 0,children:[g.pass,"/",g.total]}),g.fail>0&&jsxs("span",{style:{color:r.red},children:[g.fail,"\u2717"]}),g.skip>0&&jsxs("span",{style:{color:r.amber},children:[g.skip,"\u23ED"]}),a?.pr_url&&jsxs("span",{style:{...s.link(r.blue),pointerEvents:"none",textDecoration:"none"},children:[jsx(c,{d:d.pr,className:""}),a.pr_id||"PR"]}),a?.ticket_url&&jsxs("span",{style:{...s.link(r.amber),pointerEvents:"none",textDecoration:"none"},children:[jsx(c,{d:d.ticket,className:""}),a.ticket_id||"TKT"]})]}),B==="expanded"&&jsxs("div",{style:s.card(300,M),children:[jsx(re,{}),jsxs("div",{style:s.handle,onPointerDown:V,onPointerMove:F,onPointerUp:O,onClick:ne,children:[jsx(c,{d:d.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:s.title,children:a?.title}),jsx("div",{style:s.sub,children:a?.branch_name&&jsxs("span",{children:["\u2387 ",a.branch_name]})})]}),jsx(c,{d:d.chevronUp,className:""}),jsx(te,{icon:d.minus,onClick:()=>W("mini")})]}),jsxs("div",{style:s.stats,children:[jsxs("span",{style:{color:r.green},children:[g.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[g.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[g.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[g.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:g.total})]}),a?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:r.gripColor,borderBottom:`1px solid ${r.borderSubtle}`,flexShrink:0},children:a.description}),jsx(oe,{}),jsx(ie,{}),jsx("div",{style:s.progress,children:jsx("div",{style:s.progressBar(ee)})})]}),B==="max"&&jsxs("div",{style:{...s.card(P.w,M),height:P.h,position:"relative"},children:[jsx(re,{}),jsxs("div",{style:s.handle,onPointerDown:V,onPointerMove:F,onPointerUp:O,onClick:()=>{K.current||W("expanded");},children:[jsx(c,{d:d.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:s.title,children:a?.title}),jsx("div",{style:s.sub,children:a?.branch_name&&jsxs("span",{children:["\u2387 ",a.branch_name]})})]}),jsx(c,{d:d.chevronDown,className:""}),jsx(te,{icon:d.minus,onClick:()=>W("mini")})]}),jsxs("div",{style:s.stats,children:[jsxs("span",{style:{color:r.green},children:[g.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[g.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[g.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[g.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:g.total})]}),D==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(c,{d:d.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:r.red},children:"Failed to load"}),jsx("button",{onClick:he,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),M&&jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg},children:[jsx(c,{d:d.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:r.green,flex:1},children:"Run completed"}),jsx("button",{onClick:Se,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),a?.intro_notes&&jsx("div",{style:{padding:"6px 12px",borderBottom:`1px solid ${r.borderSubtle}`,fontSize:"10px",color:r.textMuted,fontStyle:"italic",flexShrink:0},children:a.intro_notes}),D!=="error"&&jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(a?.test_cases||[]).length===0?jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:r.gripColor},children:"No test cases"}):(a?.test_cases||[]).map(t=>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:Ce[t.verdict]},children:X===t.id?jsx(c,{d:d.loader,className:""}):jsx(c,{d:Te[t.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:r.text,lineHeight:1.3},children:t.title}),t.description&&jsx("div",{style:{fontSize:"9px",color:r.gripColor,marginTop:"2px"},children:t.description}),t.url_path&&jsxs("a",{href:t.url_path,target:"_blank",rel:"noopener noreferrer",onClick:u=>{u.stopPropagation(),p&&(u.preventDefault(),p(t.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsx(c,{d:d.externalLink,size:10}),t.url_path]}),t.verdict==="fail"&&t.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:r.red,marginTop:"2px"},children:["\u2717 ",t.fail_reason]})]})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(u=>jsx("button",{onClick:()=>{if(t.verdict===u){N(t.id,"pending"),w(null);return}if(u==="fail"){N(t.id,"fail"),w(t.id),_("");return}w(null),N(t.id,u);},disabled:X!==null,style:s.verdictBtn(t.verdict===u,u==="pass"?r.green:u==="fail"?r.red:r.amber),children:u.toUpperCase()},u)),t.verdict_by_display_name&&jsx("span",{style:{fontSize:"8px",color:r.textFaint,marginLeft:"auto"},children:t.verdict_by_display_name})]}),ge===t.id&&t.verdict==="fail"&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:$,onChange:u=>_(u.target.value),onKeyDown:u=>{u.key==="Enter"&&$.trim()&&(N(t.id,"fail",$),w(null),_("")),u.key==="Escape"&&(w(null),_(""));},placeholder:"Reason (optional)...",style:s.input}),jsx("button",{onClick:()=>{$.trim()&&N(t.id,"fail",$),w(null),_("");},style:s.verdictBtn(true,r.red),children:"\u2713"})]})]},t.id))}),ke&&!M&&jsxs("div",{style:{padding:"6px 12px",borderTop:`1px solid ${r.greenBorderSubtle}`,background:r.greenBg,display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsx("span",{style:{fontSize:"9px",color:r.green},children:"All resolved"}),jsx("button",{onClick:ve,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:r.green,border:`1px solid ${r.greenBorderSubtle}`,cursor:"pointer"},children:"COMPLETE"})]}),jsx(oe,{}),jsx(ie,{}),jsx("div",{style:s.progress,children:jsx("div",{style:s.progressBar(ee)})}),jsx("div",{style:{position:"absolute",bottom:0,right:0,width:16,height:16,cursor:"se-resize",zIndex:10,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:"2px",opacity:.3},onPointerDown:be,onPointerMove:me,onPointerUp:ye,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{I.current||(t.currentTarget.style.opacity="0.3");},children:jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsx("path",{d:"M7 1v6H1",fill:"none",stroke:r.gripColor,strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}
2
+ export{$e as TestRunWidget,j as useDraggable,J as useTestRun};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botbuddy/react",
3
- "version": "0.2.5",
3
+ "version": "0.2.8",
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",