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