@botbuddy/react 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');function A(n,p){let[f,R]=react.useState({x:n,y:p}),y=react.useRef(false),x=react.useRef({x:0,y:0}),w=react.useRef(false),N=react.useCallback(g=>{y.current=true,w.current=false,x.current={x:g.clientX-f.x,y:g.clientY-f.y},g.target.setPointerCapture(g.pointerId);},[f]),T=react.useCallback(g=>{y.current&&(w.current=true,R({x:g.clientX-x.current.x,y:g.clientY-x.current.y}));},[]),a=react.useCallback(()=>{y.current=false;},[]);return {pos:f,onPointerDown:N,onPointerMove:T,onPointerUp:a,didDrag:w}}function Y(n){let[p,f]=react.useState(null),[R,y]=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.branchName&&a.set("branch_name",n.branchName);let g=await fetch(`${n.config.serverUrl}/widget/test-run?${a.toString()}`,{headers:{Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});if(g.status===404){y("no-match"),f(null);return}if(!g.ok){y("error");return}let v=await g.json();f(v),y(v.status==="completed"?"completed":"ready");}catch{y("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:R,fetchRun:x,setVerdict:async(a,g,v,E="human")=>(f(b=>{if(!b)return null;let h=b.test_cases.map(u=>u.id===a?{...u,verdict:g,fail_reason:g==="fail"&&v||null,verdict_by_display_name:E,verdict_at:new Date().toISOString()}:u),m={total:h.length,pending:0,pass:0,fail:0,skip:0};return h.forEach(u=>{u.verdict in m&&m[u.verdict]++;}),{...b,test_cases:h,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:g,fail_reason:v,display_name:E})})).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 c=({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 ve={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},ne={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)"}},i={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=ne[n]||ne.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 he({config:n,appSlug:p,environment:f,testRunId:R,targetUrl:y,version:x,commitSha:w,branchName:N,onNavigate:T,displayName:a="human",defaultMode:g="expanded",defaultPosition:v}){let W=(()=>{try{let t=typeof window<"u"?localStorage.getItem(re):null;if(t)return JSON.parse(t)}catch{}return null})(),[b,h]=react.useState(W?.mode||g),[m,u]=react.useState(""),[oe,k]=react.useState(null),[j,F]=react.useState(null),ie=W?.x??v?.x??16,ae=W?.y??v?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:_,onPointerDown:U,onPointerMove:$,onPointerUp:V,didDrag:H}=A(ie,ae);react.useEffect(()=>{try{localStorage.setItem(re,JSON.stringify({mode:b,x:_.x,y:_.y}));}catch{}},[b,_.x,_.y]);let J="botbuddy-widget-max-size",se=()=>{try{let t=localStorage.getItem(J);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[z,X]=react.useState(se),C=react.useRef(false),P=react.useRef({x:0,y:0,w:0,h:0}),le=react.useCallback(t=>{t.stopPropagation(),C.current=true,P.current={x:t.clientX,y:t.clientY,w:z.w,h:z.h},t.target.setPointerCapture(t.pointerId);},[z]),de=react.useCallback(t=>{if(!C.current)return;let l=Math.max(280,Math.min(600,P.current.w+(t.clientX-P.current.x))),M=Math.max(300,Math.min(window.innerHeight*.9,P.current.h+(t.clientY-P.current.y)));X({w:l,h:M});},[]),pe=react.useCallback(()=>{C.current&&(C.current=false,X(t=>(localStorage.setItem(J,JSON.stringify(t)),t)));},[]),{run:o,widgetState:I,fetchRun:ce,setVerdict:Z,markComplete:ge,resetRun:ue}=Y({config:n,appSlug:p,environment:f,testRunId:R,targetUrl:y,version:x,commitSha:w,branchName:N}),B=react.useCallback(async(t,l,M)=>{F(t);try{await Z(t,l,M,a);}finally{F(null),k(null),u("");}},[Z,a]),s=o?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},fe=s.total>0&&s.pending===0,S=I==="completed",G=s.total>0?(s.pass+s.fail)/s.total*100:0;if(I==="no-match"||I==="loading")return null;let q=()=>{H.current||h(t=>t==="mini"||t==="expanded"?"max":"mini");},Q=({icon:t,onClick:l})=>jsxRuntime.jsx("button",{style:i.btn,onClick:M=>{M.stopPropagation(),l(M);},children:jsxRuntime.jsx(c,{d:t,className:""})});return jsxRuntime.jsxs("div",{style:{...i.root,left:_.x,top:_.y},children:[b==="mini"&&jsxRuntime.jsxs("div",{style:i.pill(S),onPointerDown:U,onPointerMove:$,onPointerUp:()=>{V(),H.current||q();},children:[S?jsxRuntime.jsx(c,{d:d.checkAll,className:""}):jsxRuntime.jsx(c,{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"]}),o?.pr_url&&jsxRuntime.jsxs("span",{style:{...i.link("#60a5fa"),pointerEvents:"none",textDecoration:"none"},children:[jsxRuntime.jsx(c,{d:d.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxRuntime.jsxs("span",{style:{...i.link("#fbbf24"),pointerEvents:"none",textDecoration:"none"},children:[jsxRuntime.jsx(c,{d:d.ticket,className:""}),o.ticket_id||"TKT"]})]}),b==="expanded"&&jsxRuntime.jsxs("div",{style:i.card(300,S),children:[jsxRuntime.jsxs("div",{style:i.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:q,children:[jsxRuntime.jsx(c,{d:d.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:i.title,children:o?.title}),o?.branch_name&&jsxRuntime.jsxs("div",{style:i.sub,children:["\u2387 ",o.branch_name]})]}),jsxRuntime.jsx(c,{d:d.chevronUp,className:""}),jsxRuntime.jsx(Q,{icon:d.minus,onClick:()=>h("mini")})]}),jsxRuntime.jsxs("div",{style:i.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})]}),o?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:"#888",borderBottom:"1px solid rgba(255,255,255,0.06)",flexShrink:0},children:o.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:[o?.pr_url&&jsxRuntime.jsxs("a",{href:o.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#60a5fa"),textDecoration:"none"},children:[jsxRuntime.jsx(c,{d:d.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxRuntime.jsxs("a",{href:o.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#fbbf24"),textDecoration:"none"},children:[jsxRuntime.jsx(c,{d:d.ticket,className:""}),o.ticket_id||"Ticket"]}),jsxRuntime.jsx("span",{style:{...i.badge(o?.environment||"custom"),marginLeft:"auto"},children:o?.environment}),jsxRuntime.jsx("span",{style:{fontSize:"7px",color:"rgba(255,255,255,0.2)",letterSpacing:"0.05em"},children:"BotBuddy"})]}),jsxRuntime.jsx("div",{style:i.progress,children:jsxRuntime.jsx("div",{style:i.progressBar(G)})})]}),b==="max"&&jsxRuntime.jsxs("div",{style:{...i.card(z.w,S),height:z.h,position:"relative"},children:[jsxRuntime.jsxs("div",{style:i.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:()=>{H.current||h("expanded");},children:[jsxRuntime.jsx(c,{d:d.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:i.title,children:o?.title}),o?.branch_name&&jsxRuntime.jsxs("div",{style:i.sub,children:["\u2387 ",o.branch_name]})]}),jsxRuntime.jsx(c,{d:d.chevronDown,className:""}),jsxRuntime.jsx(Q,{icon:d.minus,onClick:()=>h("mini")})]}),jsxRuntime.jsxs("div",{style:i.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==="error"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsxRuntime.jsx(c,{d:d.alert,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:"#f87171"},children:"Failed to load"}),jsxRuntime.jsx("button",{onClick:ce,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(c,{d:d.checkAll,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",color:"#34d399",flex:1},children:"Run completed"}),jsxRuntime.jsx("button",{onClick:ue,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),o?.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:o.intro_notes}),I!=="error"&&jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(o?.test_cases||[]).length===0?jsxRuntime.jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:"#888"},children:"No test cases"}):(o?.test_cases||[]).map(t=>jsxRuntime.jsxs("div",{style:i.caseRow,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsx("div",{style:{marginTop:"2px",flexShrink:0},children:j===t.id?jsxRuntime.jsx(c,{d:d.loader,className:""}):jsxRuntime.jsx(c,{d:ve[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(),T&&(l.preventDefault(),T(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,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){B(t.id,"pending"),k(null);return}if(l==="fail"){B(t.id,"fail"),k(t.id),u("");return}k(null),B(t.id,l);},disabled:j!==null,style:i.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:m,onChange:l=>u(l.target.value),onKeyDown:l=>{l.key==="Enter"&&m.trim()&&(B(t.id,"fail",m),k(null),u("")),l.key==="Escape"&&(k(null),u(""));},placeholder:"Reason (optional)...",style:i.input}),jsxRuntime.jsx("button",{onClick:()=>{m.trim()&&B(t.id,"fail",m),k(null),u("");},style:i.verdictBtn(true,"#f87171"),children:"\u2713"})]})]},t.id))}),fe&&!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:ge,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:[o?.pr_url&&jsxRuntime.jsxs("a",{href:o.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#60a5fa"),textDecoration:"none"},children:[jsxRuntime.jsx(c,{d:d.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxRuntime.jsxs("a",{href:o.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#fbbf24"),textDecoration:"none"},children:[jsxRuntime.jsx(c,{d:d.ticket,className:""}),o.ticket_id||"Ticket"]}),o?.created_by_agent_name&&jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:"#888"},children:["by ",o.created_by_agent_name]}),jsxRuntime.jsx("span",{style:{...i.badge(o?.environment||"custom"),marginLeft:"auto"},children:o?.environment}),jsxRuntime.jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.1.9");},style:{fontSize:"7px",color:"rgba(255,255,255,0.7)",letterSpacing:"0.05em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"2px",padding:0},title:"Copy version",children:["BotBuddy v0.1.9",jsxRuntime.jsxs("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),jsxRuntime.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})]})]}),jsxRuntime.jsx("div",{style:i.progress,children:jsxRuntime.jsx("div",{style:i.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:le,onPointerMove:de,onPointerUp:pe,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{C.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=he;exports.useDraggable=A;exports.useTestRun=Y;
1
+ 'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');function A(e,p){let[f,T]=react.useState({x:e,y:p}),b=react.useRef(false),x=react.useRef({x:0,y:0}),w=react.useRef(false),z=react.useCallback(c=>{b.current=true,w.current=false,x.current={x:c.clientX-f.x,y:c.clientY-f.y},c.target.setPointerCapture(c.pointerId);},[f]),L=react.useCallback(c=>{b.current&&(w.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:L,onPointerUp:a,didDrag:w}}function Y(e){let[p,f]=react.useState(null),[T,b]=react.useState("loading"),x=react.useCallback(async()=>{try{let a=new URLSearchParams;e.testRunId&&a.set("test_run_id",e.testRunId),e.targetUrl&&a.set("target_url",e.targetUrl),a.set("app_slug",e.appSlug),a.set("environment",e.environment),e.version&&a.set("version",e.version),e.commitSha&&a.set("commit_sha",e.commitSha),e.prNumber&&a.set("pr_number",String(e.prNumber)),e.branchName&&a.set("branch_name",e.branchName);let c=await fetch(`${e.config.serverUrl}/widget/test-run?${a.toString()}`,{headers:{Authorization:`Bearer ${e.config.anonKey}`,apikey:e.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");}},[e.config.serverUrl,e.config.anonKey,e.appSlug,e.environment,e.testRunId,e.targetUrl,e.version,e.commitSha,e.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(`${e.config.serverUrl}/widget/test-cases/${a}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey},body:JSON.stringify({verdict:c,fail_reason:v,display_name:C})})).ok),markComplete:async()=>{if(!p)return false;let a=await fetch(`${e.config.serverUrl}/widget/test-runs/${p.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});return a.ok&&x(),a.ok},resetRun:async()=>{if(!p)return false;let a=await fetch(`${e.config.serverUrl}/widget/test-runs/${p.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});return a.ok&&x(),a.ok},setRun:f}}var g=({d:e,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: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"};var he={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},ne={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)"}},i={root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:e=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:"rgb(30,30,30)",border:e?"1px solid rgba(52,211,153,0.6)":"1px solid rgba(255,255,255,0.15)",boxShadow:e?"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:(e,p)=>({width:`${e}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:e=>{let p=ne[e]||ne.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:e=>({height:"100%",width:`${e}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:e=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${e}15`,color:e,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:"1px solid rgba(255,255,255,0.06)",transition:"background 0.15s"},verdictBtn:(e,p)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:e?`${p}33`:"transparent",color:e?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:e,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:w,prNumber:z,branchName:L,onNavigate:a,displayName:c="human",defaultMode:v="expanded",defaultPosition:C}){let h=(()=>{try{let n=typeof window<"u"?localStorage.getItem(re):null;if(n)return JSON.parse(n)}catch{}return null})(),[y,m]=react.useState(h?.mode||v),[u,_]=react.useState(""),[ie,k]=react.useState(null),[j,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:H}=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 n=localStorage.getItem(J);if(n)return JSON.parse(n)}catch{}return {w:340,h:500}},[P,X]=react.useState(le),I=react.useRef(false),B=react.useRef({x:0,y:0,w:0,h:0}),de=react.useCallback(n=>{n.stopPropagation(),I.current=true,B.current={x:n.clientX,y:n.clientY,w:P.w,h:P.h},n.target.setPointerCapture(n.pointerId);},[P]),pe=react.useCallback(n=>{if(!I.current)return;let l=Math.max(280,Math.min(600,B.current.w+(n.clientX-B.current.x))),R=Math.max(300,Math.min(window.innerHeight*.9,B.current.h+(n.clientY-B.current.y)));X({w:l,h:R});},[]),ce=react.useCallback(()=>{I.current&&(I.current=false,X(n=>(localStorage.setItem(J,JSON.stringify(n)),n)));},[]),{run:o,widgetState:N,fetchRun:ge,setVerdict:Z,markComplete:ue,resetRun:fe}=Y({config:e,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:w,prNumber:z?String(z):void 0,branchName:L}),D=react.useCallback(async(n,l,R)=>{F(n);try{await Z(n,l,R,c);}finally{F(null),k(null),_("");}},[Z,c]),s=o?.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=()=>{H.current||m(n=>n==="mini"||n==="expanded"?"max":"mini");},Q=({icon:n,onClick:l})=>jsxRuntime.jsx("button",{style:i.btn,onClick:R=>{R.stopPropagation(),l(R);},children:jsxRuntime.jsx(g,{d:n,className:""})});return jsxRuntime.jsxs("div",{style:{...i.root,left:M.x,top:M.y},children:[y==="mini"&&jsxRuntime.jsxs("div",{style:i.pill(S),onPointerDown:U,onPointerMove:$,onPointerUp:()=>{V(),H.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"]}),o?.pr_url&&jsxRuntime.jsxs("span",{style:{...i.link("#60a5fa"),pointerEvents:"none",textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxRuntime.jsxs("span",{style:{...i.link("#fbbf24"),pointerEvents:"none",textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.ticket,className:""}),o.ticket_id||"TKT"]})]}),y==="expanded"&&jsxRuntime.jsxs("div",{style:i.card(300,S),children:[jsxRuntime.jsxs("div",{style:i.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:i.title,children:o?.title}),o?.branch_name&&jsxRuntime.jsxs("div",{style:i.sub,children:["\u2387 ",o.branch_name]})]}),jsxRuntime.jsx(g,{d:d.chevronUp,className:""}),jsxRuntime.jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxRuntime.jsxs("div",{style:i.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})]}),o?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:"#888",borderBottom:"1px solid rgba(255,255,255,0.06)",flexShrink:0},children:o.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:[o?.pr_url&&jsxRuntime.jsxs("a",{href:o.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#60a5fa"),textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxRuntime.jsxs("a",{href:o.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#fbbf24"),textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.ticket,className:""}),o.ticket_id||"Ticket"]}),jsxRuntime.jsx("span",{style:{...i.badge(o?.environment||"custom"),marginLeft:"auto"},children:o?.environment}),jsxRuntime.jsx("span",{style:{fontSize:"7px",color:"rgba(255,255,255,0.2)",letterSpacing:"0.05em"},children:"BotBuddy"})]}),jsxRuntime.jsx("div",{style:i.progress,children:jsxRuntime.jsx("div",{style:i.progressBar(G)})})]}),y==="max"&&jsxRuntime.jsxs("div",{style:{...i.card(P.w,S),height:P.h,position:"relative"},children:[jsxRuntime.jsxs("div",{style:i.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:()=>{H.current||m("expanded");},children:[jsxRuntime.jsx(g,{d:d.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:i.title,children:o?.title}),o?.branch_name&&jsxRuntime.jsxs("div",{style:i.sub,children:["\u2387 ",o.branch_name]})]}),jsxRuntime.jsx(g,{d:d.chevronDown,className:""}),jsxRuntime.jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxRuntime.jsxs("div",{style:i.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"})]}),o?.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:o.intro_notes}),N!=="error"&&jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(o?.test_cases||[]).length===0?jsxRuntime.jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:"#888"},children:"No test cases"}):(o?.test_cases||[]).map(n=>jsxRuntime.jsxs("div",{style:i.caseRow,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsx("div",{style:{marginTop:"2px",flexShrink:0},children:j===n.id?jsxRuntime.jsx(g,{d:d.loader,className:""}):jsxRuntime.jsx(g,{d:he[n.verdict],className:""})}),jsxRuntime.jsxs("div",{style:{minWidth:0,flex:1},children:[jsxRuntime.jsx("div",{style:{fontSize:"10px",color:"#e5e5e5",lineHeight:1.3},children:n.title}),n.description&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:"#888",marginTop:"2px"},children:n.description}),n.url_path&&jsxRuntime.jsxs("a",{href:n.url_path,target:"_blank",rel:"noopener noreferrer",onClick:l=>{l.stopPropagation(),a&&(l.preventDefault(),a(n.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsxRuntime.jsx(g,{d:d.externalLink,className:""}),n.url_path]}),n.verdict==="fail"&&n.fail_reason&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:"#f87171",marginTop:"2px"},children:["\u2717 ",n.fail_reason]})]})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(l=>jsxRuntime.jsx("button",{onClick:()=>{if(n.verdict===l){D(n.id,"pending"),k(null);return}if(l==="fail"){D(n.id,"fail"),k(n.id),_("");return}k(null),D(n.id,l);},disabled:j!==null,style:i.verdictBtn(n.verdict===l,l==="pass"?"#34d399":l==="fail"?"#f87171":"#f59e0b"),children:l.toUpperCase()},l)),n.verdict_by_display_name&&jsxRuntime.jsx("span",{style:{fontSize:"8px",color:"#555",marginLeft:"auto"},children:n.verdict_by_display_name})]}),ie===n.id&&n.verdict==="fail"&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:u,onChange:l=>_(l.target.value),onKeyDown:l=>{l.key==="Enter"&&u.trim()&&(D(n.id,"fail",u),k(null),_("")),l.key==="Escape"&&(k(null),_(""));},placeholder:"Reason (optional)...",style:i.input}),jsxRuntime.jsx("button",{onClick:()=>{u.trim()&&D(n.id,"fail",u),k(null),_("");},style:i.verdictBtn(true,"#f87171"),children:"\u2713"})]})]},n.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:[o?.pr_url&&jsxRuntime.jsxs("a",{href:o.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#60a5fa"),textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxRuntime.jsxs("a",{href:o.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#fbbf24"),textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.ticket,className:""}),o.ticket_id||"Ticket"]}),o?.created_by_agent_name&&jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:"#888"},children:["by ",o.created_by_agent_name]}),jsxRuntime.jsx("span",{style:{...i.badge(o?.environment||"custom"),marginLeft:"auto"},children:o?.environment}),jsxRuntime.jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.2.1");},style:{fontSize:"7px",color:"rgba(255,255,255,0.7)",letterSpacing:"0.05em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"2px",padding:0},title:"Copy version",children:["BotBuddy v0.2.1",jsxRuntime.jsxs("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),jsxRuntime.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})]})]}),jsxRuntime.jsx("div",{style:i.progress,children:jsxRuntime.jsx("div",{style:i.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:n=>n.currentTarget.style.opacity="0.7",onPointerLeave:n=>{I.current||(n.currentTarget.style.opacity="0.3");},children:jsxRuntime.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsxRuntime.jsx("path",{d:"M7 1v6H1",fill:"none",stroke:"#888",strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}exports.TestRunWidget=ke;exports.useDraggable=A;exports.useTestRun=Y;
package/dist/index.d.cts CHANGED
@@ -69,6 +69,8 @@ interface TestRunWidgetProps {
69
69
  version?: string;
70
70
  /** Match by commit SHA */
71
71
  commitSha?: string;
72
+ /** Match by PR number (most stable identifier for preview deployments) */
73
+ prNumber?: number | string;
72
74
  /** Match by branch name */
73
75
  branchName?: string;
74
76
  /** Callback when user clicks a test case URL */
@@ -84,7 +86,7 @@ interface TestRunWidgetProps {
84
86
  };
85
87
  }
86
88
 
87
- declare function TestRunWidget({ config, appSlug, environment, testRunId, targetUrl, version, commitSha, branchName, onNavigate, displayName, defaultMode, defaultPosition, }: TestRunWidgetProps): react_jsx_runtime.JSX.Element | null;
89
+ declare function TestRunWidget({ config, appSlug, environment, testRunId, targetUrl, version, commitSha, prNumber, branchName, onNavigate, displayName, defaultMode, defaultPosition, }: TestRunWidgetProps): react_jsx_runtime.JSX.Element | null;
88
90
 
89
91
  declare function useDraggable(initialX: number, initialY: number): {
90
92
  pos: {
@@ -105,6 +107,7 @@ interface UseTestRunOptions {
105
107
  targetUrl?: string;
106
108
  version?: string;
107
109
  commitSha?: string;
110
+ prNumber?: number | string;
108
111
  branchName?: string;
109
112
  }
110
113
  declare function useTestRun(opts: UseTestRunOptions): {
package/dist/index.d.ts CHANGED
@@ -69,6 +69,8 @@ interface TestRunWidgetProps {
69
69
  version?: string;
70
70
  /** Match by commit SHA */
71
71
  commitSha?: string;
72
+ /** Match by PR number (most stable identifier for preview deployments) */
73
+ prNumber?: number | string;
72
74
  /** Match by branch name */
73
75
  branchName?: string;
74
76
  /** Callback when user clicks a test case URL */
@@ -84,7 +86,7 @@ interface TestRunWidgetProps {
84
86
  };
85
87
  }
86
88
 
87
- declare function TestRunWidget({ config, appSlug, environment, testRunId, targetUrl, version, commitSha, branchName, onNavigate, displayName, defaultMode, defaultPosition, }: TestRunWidgetProps): react_jsx_runtime.JSX.Element | null;
89
+ declare function TestRunWidget({ config, appSlug, environment, testRunId, targetUrl, version, commitSha, prNumber, branchName, onNavigate, displayName, defaultMode, defaultPosition, }: TestRunWidgetProps): react_jsx_runtime.JSX.Element | null;
88
90
 
89
91
  declare function useDraggable(initialX: number, initialY: number): {
90
92
  pos: {
@@ -105,6 +107,7 @@ interface UseTestRunOptions {
105
107
  targetUrl?: string;
106
108
  version?: string;
107
109
  commitSha?: string;
110
+ prNumber?: number | string;
108
111
  branchName?: string;
109
112
  }
110
113
  declare function useTestRun(opts: UseTestRunOptions): {
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import {useState,useRef,useCallback,useEffect}from'react';import {jsxs,jsx}from'react/jsx-runtime';function A(n,p){let[f,R]=useState({x:n,y:p}),y=useRef(false),x=useRef({x:0,y:0}),w=useRef(false),N=useCallback(g=>{y.current=true,w.current=false,x.current={x:g.clientX-f.x,y:g.clientY-f.y},g.target.setPointerCapture(g.pointerId);},[f]),T=useCallback(g=>{y.current&&(w.current=true,R({x:g.clientX-x.current.x,y:g.clientY-x.current.y}));},[]),a=useCallback(()=>{y.current=false;},[]);return {pos:f,onPointerDown:N,onPointerMove:T,onPointerUp:a,didDrag:w}}function Y(n){let[p,f]=useState(null),[R,y]=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.branchName&&a.set("branch_name",n.branchName);let g=await fetch(`${n.config.serverUrl}/widget/test-run?${a.toString()}`,{headers:{Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});if(g.status===404){y("no-match"),f(null);return}if(!g.ok){y("error");return}let v=await g.json();f(v),y(v.status==="completed"?"completed":"ready");}catch{y("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:R,fetchRun:x,setVerdict:async(a,g,v,E="human")=>(f(b=>{if(!b)return null;let h=b.test_cases.map(u=>u.id===a?{...u,verdict:g,fail_reason:g==="fail"&&v||null,verdict_by_display_name:E,verdict_at:new Date().toISOString()}:u),m={total:h.length,pending:0,pass:0,fail:0,skip:0};return h.forEach(u=>{u.verdict in m&&m[u.verdict]++;}),{...b,test_cases:h,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:g,fail_reason:v,display_name:E})})).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 c=({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 ve={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},ne={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)"}},i={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=ne[n]||ne.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 he({config:n,appSlug:p,environment:f,testRunId:R,targetUrl:y,version:x,commitSha:w,branchName:N,onNavigate:T,displayName:a="human",defaultMode:g="expanded",defaultPosition:v}){let W=(()=>{try{let t=typeof window<"u"?localStorage.getItem(re):null;if(t)return JSON.parse(t)}catch{}return null})(),[b,h]=useState(W?.mode||g),[m,u]=useState(""),[oe,k]=useState(null),[j,F]=useState(null),ie=W?.x??v?.x??16,ae=W?.y??v?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:_,onPointerDown:U,onPointerMove:$,onPointerUp:V,didDrag:H}=A(ie,ae);useEffect(()=>{try{localStorage.setItem(re,JSON.stringify({mode:b,x:_.x,y:_.y}));}catch{}},[b,_.x,_.y]);let J="botbuddy-widget-max-size",se=()=>{try{let t=localStorage.getItem(J);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[z,X]=useState(se),C=useRef(false),P=useRef({x:0,y:0,w:0,h:0}),le=useCallback(t=>{t.stopPropagation(),C.current=true,P.current={x:t.clientX,y:t.clientY,w:z.w,h:z.h},t.target.setPointerCapture(t.pointerId);},[z]),de=useCallback(t=>{if(!C.current)return;let l=Math.max(280,Math.min(600,P.current.w+(t.clientX-P.current.x))),M=Math.max(300,Math.min(window.innerHeight*.9,P.current.h+(t.clientY-P.current.y)));X({w:l,h:M});},[]),pe=useCallback(()=>{C.current&&(C.current=false,X(t=>(localStorage.setItem(J,JSON.stringify(t)),t)));},[]),{run:o,widgetState:I,fetchRun:ce,setVerdict:Z,markComplete:ge,resetRun:ue}=Y({config:n,appSlug:p,environment:f,testRunId:R,targetUrl:y,version:x,commitSha:w,branchName:N}),B=useCallback(async(t,l,M)=>{F(t);try{await Z(t,l,M,a);}finally{F(null),k(null),u("");}},[Z,a]),s=o?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},fe=s.total>0&&s.pending===0,S=I==="completed",G=s.total>0?(s.pass+s.fail)/s.total*100:0;if(I==="no-match"||I==="loading")return null;let q=()=>{H.current||h(t=>t==="mini"||t==="expanded"?"max":"mini");},Q=({icon:t,onClick:l})=>jsx("button",{style:i.btn,onClick:M=>{M.stopPropagation(),l(M);},children:jsx(c,{d:t,className:""})});return jsxs("div",{style:{...i.root,left:_.x,top:_.y},children:[b==="mini"&&jsxs("div",{style:i.pill(S),onPointerDown:U,onPointerMove:$,onPointerUp:()=>{V(),H.current||q();},children:[S?jsx(c,{d:d.checkAll,className:""}):jsx(c,{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"]}),o?.pr_url&&jsxs("span",{style:{...i.link("#60a5fa"),pointerEvents:"none",textDecoration:"none"},children:[jsx(c,{d:d.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxs("span",{style:{...i.link("#fbbf24"),pointerEvents:"none",textDecoration:"none"},children:[jsx(c,{d:d.ticket,className:""}),o.ticket_id||"TKT"]})]}),b==="expanded"&&jsxs("div",{style:i.card(300,S),children:[jsxs("div",{style:i.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:q,children:[jsx(c,{d:d.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:i.title,children:o?.title}),o?.branch_name&&jsxs("div",{style:i.sub,children:["\u2387 ",o.branch_name]})]}),jsx(c,{d:d.chevronUp,className:""}),jsx(Q,{icon:d.minus,onClick:()=>h("mini")})]}),jsxs("div",{style:i.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})]}),o?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:"#888",borderBottom:"1px solid rgba(255,255,255,0.06)",flexShrink:0},children:o.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:[o?.pr_url&&jsxs("a",{href:o.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#60a5fa"),textDecoration:"none"},children:[jsx(c,{d:d.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxs("a",{href:o.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#fbbf24"),textDecoration:"none"},children:[jsx(c,{d:d.ticket,className:""}),o.ticket_id||"Ticket"]}),jsx("span",{style:{...i.badge(o?.environment||"custom"),marginLeft:"auto"},children:o?.environment}),jsx("span",{style:{fontSize:"7px",color:"rgba(255,255,255,0.2)",letterSpacing:"0.05em"},children:"BotBuddy"})]}),jsx("div",{style:i.progress,children:jsx("div",{style:i.progressBar(G)})})]}),b==="max"&&jsxs("div",{style:{...i.card(z.w,S),height:z.h,position:"relative"},children:[jsxs("div",{style:i.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:()=>{H.current||h("expanded");},children:[jsx(c,{d:d.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:i.title,children:o?.title}),o?.branch_name&&jsxs("div",{style:i.sub,children:["\u2387 ",o.branch_name]})]}),jsx(c,{d:d.chevronDown,className:""}),jsx(Q,{icon:d.minus,onClick:()=>h("mini")})]}),jsxs("div",{style:i.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==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(c,{d:d.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:"#f87171"},children:"Failed to load"}),jsx("button",{onClick:ce,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(c,{d:d.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:"#34d399",flex:1},children:"Run completed"}),jsx("button",{onClick:ue,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),o?.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:o.intro_notes}),I!=="error"&&jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(o?.test_cases||[]).length===0?jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:"#888"},children:"No test cases"}):(o?.test_cases||[]).map(t=>jsxs("div",{style:i.caseRow,children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsx("div",{style:{marginTop:"2px",flexShrink:0},children:j===t.id?jsx(c,{d:d.loader,className:""}):jsx(c,{d:ve[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(),T&&(l.preventDefault(),T(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,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){B(t.id,"pending"),k(null);return}if(l==="fail"){B(t.id,"fail"),k(t.id),u("");return}k(null),B(t.id,l);},disabled:j!==null,style:i.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:m,onChange:l=>u(l.target.value),onKeyDown:l=>{l.key==="Enter"&&m.trim()&&(B(t.id,"fail",m),k(null),u("")),l.key==="Escape"&&(k(null),u(""));},placeholder:"Reason (optional)...",style:i.input}),jsx("button",{onClick:()=>{m.trim()&&B(t.id,"fail",m),k(null),u("");},style:i.verdictBtn(true,"#f87171"),children:"\u2713"})]})]},t.id))}),fe&&!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:ge,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:[o?.pr_url&&jsxs("a",{href:o.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#60a5fa"),textDecoration:"none"},children:[jsx(c,{d:d.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxs("a",{href:o.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#fbbf24"),textDecoration:"none"},children:[jsx(c,{d:d.ticket,className:""}),o.ticket_id||"Ticket"]}),o?.created_by_agent_name&&jsxs("span",{style:{fontSize:"9px",color:"#888"},children:["by ",o.created_by_agent_name]}),jsx("span",{style:{...i.badge(o?.environment||"custom"),marginLeft:"auto"},children:o?.environment}),jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.1.9");},style:{fontSize:"7px",color:"rgba(255,255,255,0.7)",letterSpacing:"0.05em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"2px",padding:0},title:"Copy version",children:["BotBuddy v0.1.9",jsxs("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})]})]}),jsx("div",{style:i.progress,children:jsx("div",{style:i.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:le,onPointerMove:de,onPointerUp:pe,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{C.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{he as TestRunWidget,A as useDraggable,Y as useTestRun};
1
+ import {useState,useRef,useCallback,useEffect}from'react';import {jsxs,jsx}from'react/jsx-runtime';function A(e,p){let[f,T]=useState({x:e,y:p}),b=useRef(false),x=useRef({x:0,y:0}),w=useRef(false),z=useCallback(c=>{b.current=true,w.current=false,x.current={x:c.clientX-f.x,y:c.clientY-f.y},c.target.setPointerCapture(c.pointerId);},[f]),L=useCallback(c=>{b.current&&(w.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:L,onPointerUp:a,didDrag:w}}function Y(e){let[p,f]=useState(null),[T,b]=useState("loading"),x=useCallback(async()=>{try{let a=new URLSearchParams;e.testRunId&&a.set("test_run_id",e.testRunId),e.targetUrl&&a.set("target_url",e.targetUrl),a.set("app_slug",e.appSlug),a.set("environment",e.environment),e.version&&a.set("version",e.version),e.commitSha&&a.set("commit_sha",e.commitSha),e.prNumber&&a.set("pr_number",String(e.prNumber)),e.branchName&&a.set("branch_name",e.branchName);let c=await fetch(`${e.config.serverUrl}/widget/test-run?${a.toString()}`,{headers:{Authorization:`Bearer ${e.config.anonKey}`,apikey:e.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");}},[e.config.serverUrl,e.config.anonKey,e.appSlug,e.environment,e.testRunId,e.targetUrl,e.version,e.commitSha,e.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(`${e.config.serverUrl}/widget/test-cases/${a}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey},body:JSON.stringify({verdict:c,fail_reason:v,display_name:C})})).ok),markComplete:async()=>{if(!p)return false;let a=await fetch(`${e.config.serverUrl}/widget/test-runs/${p.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});return a.ok&&x(),a.ok},resetRun:async()=>{if(!p)return false;let a=await fetch(`${e.config.serverUrl}/widget/test-runs/${p.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});return a.ok&&x(),a.ok},setRun:f}}var g=({d:e,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: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"};var he={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},ne={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)"}},i={root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:e=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:"rgb(30,30,30)",border:e?"1px solid rgba(52,211,153,0.6)":"1px solid rgba(255,255,255,0.15)",boxShadow:e?"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:(e,p)=>({width:`${e}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:e=>{let p=ne[e]||ne.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:e=>({height:"100%",width:`${e}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:e=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${e}15`,color:e,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:"1px solid rgba(255,255,255,0.06)",transition:"background 0.15s"},verdictBtn:(e,p)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:e?`${p}33`:"transparent",color:e?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:e,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:w,prNumber:z,branchName:L,onNavigate:a,displayName:c="human",defaultMode:v="expanded",defaultPosition:C}){let h=(()=>{try{let n=typeof window<"u"?localStorage.getItem(re):null;if(n)return JSON.parse(n)}catch{}return null})(),[y,m]=useState(h?.mode||v),[u,_]=useState(""),[ie,k]=useState(null),[j,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:H}=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 n=localStorage.getItem(J);if(n)return JSON.parse(n)}catch{}return {w:340,h:500}},[P,X]=useState(le),I=useRef(false),B=useRef({x:0,y:0,w:0,h:0}),de=useCallback(n=>{n.stopPropagation(),I.current=true,B.current={x:n.clientX,y:n.clientY,w:P.w,h:P.h},n.target.setPointerCapture(n.pointerId);},[P]),pe=useCallback(n=>{if(!I.current)return;let l=Math.max(280,Math.min(600,B.current.w+(n.clientX-B.current.x))),R=Math.max(300,Math.min(window.innerHeight*.9,B.current.h+(n.clientY-B.current.y)));X({w:l,h:R});},[]),ce=useCallback(()=>{I.current&&(I.current=false,X(n=>(localStorage.setItem(J,JSON.stringify(n)),n)));},[]),{run:o,widgetState:N,fetchRun:ge,setVerdict:Z,markComplete:ue,resetRun:fe}=Y({config:e,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:w,prNumber:z?String(z):void 0,branchName:L}),D=useCallback(async(n,l,R)=>{F(n);try{await Z(n,l,R,c);}finally{F(null),k(null),_("");}},[Z,c]),s=o?.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=()=>{H.current||m(n=>n==="mini"||n==="expanded"?"max":"mini");},Q=({icon:n,onClick:l})=>jsx("button",{style:i.btn,onClick:R=>{R.stopPropagation(),l(R);},children:jsx(g,{d:n,className:""})});return jsxs("div",{style:{...i.root,left:M.x,top:M.y},children:[y==="mini"&&jsxs("div",{style:i.pill(S),onPointerDown:U,onPointerMove:$,onPointerUp:()=>{V(),H.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"]}),o?.pr_url&&jsxs("span",{style:{...i.link("#60a5fa"),pointerEvents:"none",textDecoration:"none"},children:[jsx(g,{d:d.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxs("span",{style:{...i.link("#fbbf24"),pointerEvents:"none",textDecoration:"none"},children:[jsx(g,{d:d.ticket,className:""}),o.ticket_id||"TKT"]})]}),y==="expanded"&&jsxs("div",{style:i.card(300,S),children:[jsxs("div",{style:i.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:i.title,children:o?.title}),o?.branch_name&&jsxs("div",{style:i.sub,children:["\u2387 ",o.branch_name]})]}),jsx(g,{d:d.chevronUp,className:""}),jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxs("div",{style:i.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})]}),o?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:"#888",borderBottom:"1px solid rgba(255,255,255,0.06)",flexShrink:0},children:o.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:[o?.pr_url&&jsxs("a",{href:o.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#60a5fa"),textDecoration:"none"},children:[jsx(g,{d:d.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxs("a",{href:o.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#fbbf24"),textDecoration:"none"},children:[jsx(g,{d:d.ticket,className:""}),o.ticket_id||"Ticket"]}),jsx("span",{style:{...i.badge(o?.environment||"custom"),marginLeft:"auto"},children:o?.environment}),jsx("span",{style:{fontSize:"7px",color:"rgba(255,255,255,0.2)",letterSpacing:"0.05em"},children:"BotBuddy"})]}),jsx("div",{style:i.progress,children:jsx("div",{style:i.progressBar(G)})})]}),y==="max"&&jsxs("div",{style:{...i.card(P.w,S),height:P.h,position:"relative"},children:[jsxs("div",{style:i.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:()=>{H.current||m("expanded");},children:[jsx(g,{d:d.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:i.title,children:o?.title}),o?.branch_name&&jsxs("div",{style:i.sub,children:["\u2387 ",o.branch_name]})]}),jsx(g,{d:d.chevronDown,className:""}),jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxs("div",{style:i.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"})]}),o?.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:o.intro_notes}),N!=="error"&&jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(o?.test_cases||[]).length===0?jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:"#888"},children:"No test cases"}):(o?.test_cases||[]).map(n=>jsxs("div",{style:i.caseRow,children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsx("div",{style:{marginTop:"2px",flexShrink:0},children:j===n.id?jsx(g,{d:d.loader,className:""}):jsx(g,{d:he[n.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:"#e5e5e5",lineHeight:1.3},children:n.title}),n.description&&jsx("div",{style:{fontSize:"9px",color:"#888",marginTop:"2px"},children:n.description}),n.url_path&&jsxs("a",{href:n.url_path,target:"_blank",rel:"noopener noreferrer",onClick:l=>{l.stopPropagation(),a&&(l.preventDefault(),a(n.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsx(g,{d:d.externalLink,className:""}),n.url_path]}),n.verdict==="fail"&&n.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:"#f87171",marginTop:"2px"},children:["\u2717 ",n.fail_reason]})]})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(l=>jsx("button",{onClick:()=>{if(n.verdict===l){D(n.id,"pending"),k(null);return}if(l==="fail"){D(n.id,"fail"),k(n.id),_("");return}k(null),D(n.id,l);},disabled:j!==null,style:i.verdictBtn(n.verdict===l,l==="pass"?"#34d399":l==="fail"?"#f87171":"#f59e0b"),children:l.toUpperCase()},l)),n.verdict_by_display_name&&jsx("span",{style:{fontSize:"8px",color:"#555",marginLeft:"auto"},children:n.verdict_by_display_name})]}),ie===n.id&&n.verdict==="fail"&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:u,onChange:l=>_(l.target.value),onKeyDown:l=>{l.key==="Enter"&&u.trim()&&(D(n.id,"fail",u),k(null),_("")),l.key==="Escape"&&(k(null),_(""));},placeholder:"Reason (optional)...",style:i.input}),jsx("button",{onClick:()=>{u.trim()&&D(n.id,"fail",u),k(null),_("");},style:i.verdictBtn(true,"#f87171"),children:"\u2713"})]})]},n.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:[o?.pr_url&&jsxs("a",{href:o.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#60a5fa"),textDecoration:"none"},children:[jsx(g,{d:d.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxs("a",{href:o.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#fbbf24"),textDecoration:"none"},children:[jsx(g,{d:d.ticket,className:""}),o.ticket_id||"Ticket"]}),o?.created_by_agent_name&&jsxs("span",{style:{fontSize:"9px",color:"#888"},children:["by ",o.created_by_agent_name]}),jsx("span",{style:{...i.badge(o?.environment||"custom"),marginLeft:"auto"},children:o?.environment}),jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.2.1");},style:{fontSize:"7px",color:"rgba(255,255,255,0.7)",letterSpacing:"0.05em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"2px",padding:0},title:"Copy version",children:["BotBuddy v0.2.1",jsxs("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})]})]}),jsx("div",{style:i.progress,children:jsx("div",{style:i.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:n=>n.currentTarget.style.opacity="0.7",onPointerLeave:n=>{I.current||(n.currentTarget.style.opacity="0.3");},children:jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsx("path",{d:"M7 1v6H1",fill:"none",stroke:"#888",strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}export{ke as TestRunWidget,A as useDraggable,Y as useTestRun};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@botbuddy/react",
3
- "version": "0.2.1",
4
- "description": "BotBuddy test coordination widgets for React — draggable, translucent overlays for human-in-the-loop QA",
3
+ "version": "0.2.2",
4
+ "description": "BotBuddy test coordination widgets for React \u2014 draggable, translucent overlays for human-in-the-loop QA",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
@@ -13,7 +13,10 @@
13
13
  "require": "./dist/index.cjs"
14
14
  }
15
15
  },
16
- "files": ["dist", "README.md"],
16
+ "files": [
17
+ "dist",
18
+ "README.md"
19
+ ],
17
20
  "sideEffects": false,
18
21
  "scripts": {
19
22
  "build": "tsup",
@@ -30,10 +33,17 @@
30
33
  "tsup": "^8.4.0",
31
34
  "typescript": "^5.8.3"
32
35
  },
33
- "keywords": ["botbuddy", "testing", "qa", "widget", "react", "overlay"],
36
+ "keywords": [
37
+ "botbuddy",
38
+ "testing",
39
+ "qa",
40
+ "widget",
41
+ "react",
42
+ "overlay"
43
+ ],
34
44
  "license": "MIT",
35
45
  "repository": {
36
46
  "type": "git",
37
47
  "url": "https://github.com/botbuddy/react"
38
48
  }
39
- }
49
+ }