@botbuddy/react 0.5.11 → 0.5.12
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 ae(t,o){let[a,S]=react.useState({x:t,y:o}),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-a.x,y:p.clientY-a.y},p.target.setPointerCapture(p.pointerId);},[a]),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:a,onPointerDown:v,onPointerMove:b,onPointerUp:c,didDrag:h}}function ne(t,o){let a={apikey:t.anonKey};return o?a.Authorization=`Bearer ${o}`:t.apiKey?a.Authorization=`Bearer ${t.apiKey}`:a.Authorization=`Bearer ${t.anonKey}`,a}function se(t){let[o,a]=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:ne(t.config,t.authToken)});if(p.status===404){f("no-match"),a(null);return}if(p.status===401||p.status===403){f("error");return}if(!p.ok){f("error");return}let M=await p.json();a(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:o,widgetState:S,fetchRun:x,setVerdict:async(c,p,M,C="human")=>(a(r=>{if(!r)return null;let l=r.test_cases.map(w=>w.id===c?{...w,verdict:p,fail_reason:p==="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(`${t.config.serverUrl}/widget/test-cases/${c}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...ne(t.config,t.authToken)},body:JSON.stringify({verdict:p,fail_reason:M,display_name:C})})).ok),markComplete:async()=>o?(a(p=>p?{...p,status:"completed"}:null),f("completed"),(await fetch(`${t.config.serverUrl}/widget/test-runs/${o.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...ne(t.config,t.authToken)}})).ok):false,resetRun:async()=>{if(!o)return false;let c=await fetch(`${t.config.serverUrl}/widget/test-runs/${o.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...ne(t.config,t.authToken)}});return c.ok&&x(),c.ok},setRun:a}}var le="botbuddy-widget-auth-token",de="botbuddy-widget-auth-name";function pe(t){let[o,a]=react.useState(()=>{try{return localStorage.getItem(le)}catch{return null}}),[S,f]=react.useState(()=>{try{return localStorage.getItem(de)}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;a(c),f(p||"human");try{localStorage.setItem(le,c),p&&localStorage.setItem(de,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(()=>{a(null),f(null);try{localStorage.removeItem(le),localStorage.removeItem(de);}catch{}},[]);return {token:o,displayName:S,isAuthenticated:!!o,openLogin:x,logout:h}}var g=({d:t,className:o,size:a=14})=>jsxRuntime.jsx("svg",{className:o,width:a,height:a,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d: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 je(){let[t,o]=react.useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return react.useEffect(()=>{if(typeof window>"u")return;let a=document.documentElement,S=()=>a.classList.contains("dark")?"dark":a.classList.contains("light")?"light":null,f=S();f&&o(f);let x=window.matchMedia("(prefers-color-scheme: dark)"),h=b=>{let c=S();o(c||(b.matches?"dark":"light"));};x.addEventListener("change",h);let v=new MutationObserver(()=>{let b=S();o(b||(x.matches?"dark":"light"));});return v.observe(a,{attributes:true,attributeFilter:["class"]}),()=>{x.removeEventListener("change",h),v.disconnect();}},[]),t}function Xe(t){let o=t==="dark";return {bg:o?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:o?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:o?"#e5e5e5":"#1a1a1a",textMuted:o?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:o?"#555":"#999",border:o?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:o?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:o?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:o?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:o?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:o?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:o?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:o?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:o?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:o?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:o?"#888":"#aaa",btnHover:o?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var Je={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},Ze={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)"}},Ge=t=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:o=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:t.bg,border:o?`1px solid ${t.greenBorder}`:`1px solid ${t.border}`,boxShadow:o?`0 4px 12px ${t.shadow}, 0 0 0 1px ${t.greenBorderSubtle}`:`0 4px 12px ${t.shadow}`,cursor:"pointer",fontSize:"9px",color:t.text}),card:(o,a)=>({width:`${o}px`,borderRadius:"8px",background:t.bg,border:a?`1px solid ${t.greenBorder}`:`1px solid ${t.border}`,boxShadow:a?`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:o=>{let a=$e[o]||$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:t.borderSubtle,flexShrink:0},progressBar:o=>({height:"100%",width:`${o}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:o=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${o}15`,color:o,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${t.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(o,a)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:o?`${a}33`:"transparent",color:o?a: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 qe({config:t,appSlug:o,environment:a,seedUserSlug:S,authToken:f,tk:x}){let[h,v]=react.useState(null),[b,c]=react.useState(0),[p,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]),N=react.useCallback(async()=>{M(true),$(null);try{let z=new URLSearchParams({app_slug:o,seed_user_slug:w,environment:a}),L={apikey:t.anonKey};f?L.Authorization=`Bearer ${f}`:L.Authorization=`Bearer ${t.anonKey}`;let D=await fetch(`${t.serverUrl}/widget/totp-code?${z}`,{headers:L});if(!D.ok){let F=await D.json().catch(()=>({error:"Failed"}));if(D.status===404){$("No 2FA seed registered");return}$(F.error||"Failed to get code");return}let m=await D.json();v(m.code),c(m.remaining_seconds);try{await navigator.clipboard.writeText(m.code),l(!0),setTimeout(()=>l(!1),2e3);}catch{}k.current&&clearInterval(k.current);let ee=m.remaining_seconds;k.current=setInterval(()=>{ee--,ee<=0?(k.current&&clearInterval(k.current),N()):c(ee);},1e3);}catch{$("Network error");}finally{M(false);}},[t.serverUrl,t.anonKey,f,o,w,a]);return react.useEffect(()=>()=>{k.current&&clearInterval(k.current);},[]),C==="No 2FA seed registered"?null:h?jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"3px"},children:[jsxRuntime.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"3px 8px",borderRadius:"4px",background:`${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:z=>{z.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:z=>{z.stopPropagation(),N();},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...":C||"Get 2FA code"]})}var Pe="botbuddy-widget-state";function Qe({config:t,appSlug:o,environment:a,testRunId:S,targetUrl:f,version:x,commitSha:h,prNumber:v,branchName:b,onNavigate:c,displayName:p="human",defaultMode:M="mini",defaultPosition:C}){let $=je(),r=react.useMemo(()=>Xe($),[$]),l=react.useMemo(()=>Ge(r),[r]),[k,w]=react.useState(false),[N,z]=react.useState(false),L=react.useRef(false),D=t.dashboardUrl||"https://botbuddy.lovable.app",m=pe(D),F=(()=>{try{let e=typeof window<"u"?localStorage.getItem(Pe):null;if(e)return JSON.parse(e)}catch{}return null})(),[H,K]=react.useState(F?.mode||M),[V,E]=react.useState(""),[Be,P]=react.useState(null),[ue,ge]=react.useState(null),Ie=F?.x??C?.x??16,We=F?.y??C?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:T,onPointerDown:O,onPointerMove:Y,onPointerUp:j,didDrag:re}=ae(Ie,We);react.useEffect(()=>{try{localStorage.setItem(Pe,JSON.stringify({mode:H,x:T.x,y:T.y}));}catch{}},[H,T.x,T.y]);let xe=react.useRef(m.isAuthenticated);react.useEffect(()=>{!xe.current&&m.isAuthenticated&&K("max"),xe.current=m.isAuthenticated;},[m.isAuthenticated]);let fe="botbuddy-widget-max-size",Le=()=>{try{let e=localStorage.getItem(fe);if(e)return JSON.parse(e)}catch{}return {w:340,h:500}},[X,be]=react.useState(Le),J=react.useRef(false),Z=react.useRef({x:0,y:0,w:0,h:0}),De=react.useCallback(e=>{e.stopPropagation(),J.current=true,Z.current={x:e.clientX,y:e.clientY,w:X.w,h:X.h},e.target.setPointerCapture(e.pointerId);},[X]),Ee=react.useCallback(e=>{if(!J.current)return;let u=Math.max(280,Math.min(600,Z.current.w+(e.clientX-Z.current.x))),R=Math.max(300,Math.min(window.innerHeight*.9,Z.current.h+(e.clientY-Z.current.y)));be({w:u,h:R});},[]),Ae=react.useCallback(()=>{J.current&&(J.current=false,be(e=>(localStorage.setItem(fe,JSON.stringify(e)),e)));},[]),te=f??(typeof window<"u"?window.location.href:void 0),me=m.displayName||p,[B,ye]=react.useState(null);react.useEffect(()=>{if(m.isAuthenticated)return;let e=new URLSearchParams;S&&e.set("test_run_id",S),te&&e.set("target_url",te),e.set("app_slug",o),e.set("environment",a),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=>ye(u)).catch(()=>ye(null));},[m.isAuthenticated,t.serverUrl,t.anonKey,o,a,S,te,x,h,v,b]);let{run:s,widgetState:I,fetchRun:Ue,setVerdict:he,markComplete:Ne,resetRun:Fe}=se({config:t,appSlug:o,environment:a,testRunId:S,targetUrl:te,version:x,commitSha:h,prNumber:v?String(v):void 0,branchName:b,authToken:m.token}),G=react.useCallback(async(e,u,R)=>{ge(e);try{await he(e,u,R,me);}finally{ge(null),P(null),E("");}},[he,me]),y=s?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},He=y.total>0&&y.pending===0,A=I==="completed",ve=y.total>0?(y.pass+y.fail)/y.total*100:0,Se=I==="ready"||I==="completed"||B?.enabled&&B.run;if(react.useEffect(()=>{if(!Se||L.current)return;L.current=true,z(true);let e=window.setTimeout(()=>z(false),5e3);return ()=>window.clearTimeout(e)},[Se]),(I==="no-match"||I==="loading")&&!(!m.isAuthenticated&&B?.enabled&&B.run))return null;if(!m.isAuthenticated&&B?.enabled&&B.run){let e=B.run,u=e.summary,R=e.status==="completed";return jsxRuntime.jsx("div",{style:{...l.root,left:T.x,top:T.y},children:jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>w(true),onMouseLeave:()=>w(false),children:[jsxRuntime.jsxs("div",{style:{...l.pill(R),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:O,onPointerMove:Y,onPointerUp:()=>{j();},children:[jsxRuntime.jsx(g,{d:d.grip,size:10,className:""}),e.ticket_id&&e.ticket_url?jsxRuntime.jsx("a",{href:e.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.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:W=>W.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:W=>W.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",{onClick:W=>{W.stopPropagation(),m.openLogin();},style:{color:r.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),(k||N)&&e.title&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",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||e.intro_notes)&&jsxRuntime.jsx("div",{style:{fontSize:"11px",color:r.textMuted,marginTop:"6px",lineHeight:1.4},children:e.description||e.intro_notes}),jsxRuntime.jsx("div",{style:{marginTop:"6px",fontSize:"9px",color:r.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!m.isAuthenticated)return jsxRuntime.jsxs("div",{style:{...l.root,left:T.x,top:T.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:O,onPointerMove:Y,onPointerUp:j,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(),m.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 ke=()=>{re.current||(z(false),K(e=>e==="mini"?"max":"mini"));},we=({icon:e,onClick:u})=>jsxRuntime.jsx("button",{style:l.btn,onClick:R=>{R.stopPropagation(),u(R);},children:jsxRuntime.jsx(g,{d:e,className:""})}),_e=()=>{if(!s?.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:s.assigned_human_display_name}),s.codex_thread_id&&jsxRuntime.jsx(g,{d:d.externalLink,size:10})]});return s.codex_thread_id?jsxRuntime.jsx("a",{href:`codex://threads/${s.codex_thread_id}`,style:l.humanBanner,children:e}):jsxRuntime.jsx("div",{style:l.humanBanner,children:e})},Me=()=>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(g,{d:d.pr,size:12}),s.pr_id||"PR",jsxRuntime.jsx(g,{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(g,{d:d.ticket,size:12}),s.ticket_id||"Ticket",jsxRuntime.jsx(g,{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(g,{d:d.bot,size:12}),s.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}),s.created_by_agent_name]})),jsxRuntime.jsx("span",{style:{...l.badge(s?.environment||"custom"),marginLeft:"auto"},children:s?.environment})]}),ze=()=>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.10");},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.10"})]}),m.isAuthenticated&&jsxRuntime.jsx("button",{onClick:e=>{e.stopPropagation(),m.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:T.x,top:T.y},children:[H==="mini"&&jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>w(true),onMouseLeave:()=>w(false),children:[jsxRuntime.jsxs("div",{style:{...l.pill(A),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:O,onPointerMove:Y,onPointerUp:()=>{j(),re.current||ke();},children:[jsxRuntime.jsx(g,{d:d.grip,size:10,className:""}),s?.ticket_id&&jsxRuntime.jsx("span",{style:{color:r.amber,fontWeight:600},children:s.ticket_id}),s?.pr_number&&jsxRuntime.jsxs("span",{style:{color:r.blue,fontWeight:600},children:["PR#",s.pr_number]}),s?.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}),s.created_by_agent_name]}),jsxRuntime.jsxs("span",{style:A?{color:r.green}:void 0,children:[y.pass,"/",y.total]}),y.fail>0&&jsxRuntime.jsxs("span",{style:{color:r.red},children:[y.fail,"\u2717"]})]}),(k||N)&&s?.title&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"220px",maxWidth:"320px",padding:"10px 14px",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsxRuntime.jsx("div",{style:{fontSize:"13px",fontWeight:700,color:r.text,lineHeight:1.3},children:s.title}),(s.description||s.intro_notes)&&jsxRuntime.jsx("div",{style:{fontSize:"11px",color:r.textMuted,marginTop:"6px",lineHeight:1.4},children:s.description||s.intro_notes})]})]}),H==="expanded"&&jsxRuntime.jsxs("div",{style:l.card(300,A),children:[jsxRuntime.jsx(_e,{}),jsxRuntime.jsxs("div",{style:l.handle,onPointerDown:O,onPointerMove:Y,onPointerUp:j,onClick:ke,children:[jsxRuntime.jsx(g,{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(g,{d:d.chevronUp,className:""}),jsxRuntime.jsx(we,{icon:d.minus,onClick:()=>K("mini")})]}),jsxRuntime.jsxs("div",{style:l.stats,children:[jsxRuntime.jsxs("span",{style:{color:r.green},children:[y.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:r.red},children:[y.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:r.amber},children:[y.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:r.gripColor},children:[y.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:y.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(Me,{}),jsxRuntime.jsx(ze,{}),jsxRuntime.jsx("div",{style:l.progress,children:jsxRuntime.jsx("div",{style:l.progressBar(ve)})})]}),H==="max"&&jsxRuntime.jsxs("div",{style:{...l.card(X.w,A),height:X.h,position:"relative"},children:[jsxRuntime.jsx(_e,{}),jsxRuntime.jsxs("div",{style:l.handle,onPointerDown:O,onPointerMove:Y,onPointerUp:j,onClick:()=>{re.current||K("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:s?.title}),jsxRuntime.jsx("div",{style:l.sub,children:s?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",s.branch_name]})})]}),jsxRuntime.jsx(g,{d:d.chevronDown,className:""}),jsxRuntime.jsx(we,{icon:d.minus,onClick:()=>K("mini")})]}),jsxRuntime.jsxs("div",{style:l.stats,children:[jsxRuntime.jsxs("span",{style:{color:r.green},children:[y.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:r.red},children:[y.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:r.amber},children:[y.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:r.gripColor},children:[y.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:y.total})]}),I==="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:Ue,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),A&&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:Fe,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}),I!=="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(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:Je[e.verdict]},children:ue===e.id?jsxRuntime.jsx(g,{d:d.loader,className:""}):jsxRuntime.jsx(g,{d:Ze[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})]}),a!=="production"&&jsxRuntime.jsx(qe,{config:t,appSlug:o,environment:a,seedUserSlug:e.seed_user,authToken:m.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){G(e.id,"pending"),P(null);return}if(u==="fail"){G(e.id,"fail"),P(e.id),E("");return}P(null),G(e.id,u);},disabled:ue!==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})]}),Be===e.id&&e.verdict==="fail"&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:V,onChange:u=>E(u.target.value),onKeyDown:u=>{u.key==="Enter"&&V.trim()&&(G(e.id,"fail",V),P(null),E("")),u.key==="Escape"&&(P(null),E(""));},placeholder:"Reason (optional)...",style:l.input}),jsxRuntime.jsx("button",{onClick:()=>{V.trim()&&G(e.id,"fail",V),P(null),E("");},style:l.verdictBtn(true,r.red),children:"\u2713"})]})]},e.id))}),He&&!A&&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:Ne,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(Me,{}),jsxRuntime.jsx(ze,{}),jsxRuntime.jsx("div",{style:l.progress,children:jsxRuntime.jsx("div",{style:l.progressBar(ve)})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:0,right:0,width:16,height:16,cursor:"se-resize",zIndex:10,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:"2px",opacity:.3},onPointerDown:De,onPointerMove:Ee,onPointerUp:Ae,onPointerEnter:e=>e.currentTarget.style.opacity="0.7",onPointerLeave:e=>{J.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=
|
|
1
|
+
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');function le(t,o){let[s,S]=react.useState({x:t,y:o}),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 ne(t,o){let s={apikey:t.anonKey};return o?s.Authorization=`Bearer ${o}`:t.apiKey?s.Authorization=`Bearer ${t.apiKey}`:s.Authorization=`Bearer ${t.anonKey}`,s}function de(t){let[o,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:ne(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:o,widgetState:S,fetchRun:x,setVerdict:async(c,p,M,$="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:$,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",...ne(t.config,t.authToken)},body:JSON.stringify({verdict:p,fail_reason:M,display_name:$})})).ok),markComplete:async()=>o?(s(p=>p?{...p,status:"completed"}:null),f("completed"),(await fetch(`${t.config.serverUrl}/widget/test-runs/${o.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...ne(t.config,t.authToken)}})).ok):false,resetRun:async()=>{if(!o)return false;let c=await fetch(`${t.config.serverUrl}/widget/test-runs/${o.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...ne(t.config,t.authToken)}});return c.ok&&x(),c.ok},setRun:s}}var pe="botbuddy-widget-auth-token",ce="botbuddy-widget-auth-name";function ue(t){let[o,s]=react.useState(()=>{try{return localStorage.getItem(pe)}catch{return null}}),[S,f]=react.useState(()=>{try{return localStorage.getItem(ce)}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(pe,c),p&&localStorage.setItem(ce,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(pe),localStorage.removeItem(ce);}catch{}},[]);return {token:o,displayName:S,isAuthenticated:!!o,openLogin:x,logout:h}}var g=({d:t,className:o,size:s=14})=>jsxRuntime.jsx("svg",{className:o,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 Xe(){let[t,o]=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&&o(f);let x=window.matchMedia("(prefers-color-scheme: dark)"),h=b=>{let c=S();o(c||(b.matches?"dark":"light"));};x.addEventListener("change",h);let v=new MutationObserver(()=>{let b=S();o(b||(x.matches?"dark":"light"));});return v.observe(s,{attributes:true,attributeFilter:["class"]}),()=>{x.removeEventListener("change",h),v.disconnect();}},[]),t}function Je(t){let o=t==="dark";return {bg:o?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:o?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:o?"#e5e5e5":"#1a1a1a",textMuted:o?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:o?"#555":"#999",border:o?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:o?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:o?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:o?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:o?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:o?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:o?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:o?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:o?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:o?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:o?"#888":"#aaa",btnHover:o?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var Ze={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},Ge={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},Pe={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)"}},qe=t=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:o=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:t.bg,border:o?`1px solid ${t.greenBorder}`:`1px solid ${t.border}`,boxShadow:o?`0 4px 12px ${t.shadow}, 0 0 0 1px ${t.greenBorderSubtle}`:`0 4px 12px ${t.shadow}`,cursor:"pointer",fontSize:"9px",color:t.text}),card:(o,s)=>({width:`${o}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:o=>{let s=Pe[o]||Pe.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:o=>({height:"100%",width:`${o}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:o=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${o}15`,color:o,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${t.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(o,s)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:o?`${s}33`:"transparent",color:o?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 Qe({config:t,appSlug:o,environment:s,seedUserSlug:S,authToken:f,tk:x}){let[h,v]=react.useState(null),[b,c]=react.useState(0),[p,M]=react.useState(false),[$,P]=react.useState(null),[r,l]=react.useState(false),_=react.useRef(null),k=react.useMemo(()=>S.split("/")[0].trim(),[S]),N=react.useCallback(async()=>{M(true),P(null);try{let z=new URLSearchParams({app_slug:o,seed_user_slug:k,environment:s}),L={apikey:t.anonKey};f?L.Authorization=`Bearer ${f}`:L.Authorization=`Bearer ${t.anonKey}`;let D=await fetch(`${t.serverUrl}/widget/totp-code?${z}`,{headers:L});if(!D.ok){let F=await D.json().catch(()=>({error:"Failed"}));if(D.status===404){P("No 2FA seed registered");return}P(F.error||"Failed to get code");return}let m=await D.json();v(m.code),c(m.remaining_seconds);try{await navigator.clipboard.writeText(m.code),l(!0),setTimeout(()=>l(!1),2e3);}catch{}_.current&&clearInterval(_.current);let ee=m.remaining_seconds;_.current=setInterval(()=>{ee--,ee<=0?(_.current&&clearInterval(_.current),N()):c(ee);},1e3);}catch{P("Network error");}finally{M(false);}},[t.serverUrl,t.anonKey,f,o,k,s]);return react.useEffect(()=>()=>{_.current&&clearInterval(_.current);},[]),$==="No 2FA seed registered"?null:h?jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"3px"},children:[jsxRuntime.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"3px 8px",borderRadius:"4px",background:`${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:z=>{z.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:z=>{z.stopPropagation(),N();},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...":$||"Get 2FA code"]})}var Be="botbuddy-widget-state";function et({config:t,appSlug:o,environment:s,testRunId:S,targetUrl:f,version:x,commitSha:h,prNumber:v,branchName:b,onNavigate:c,displayName:p="human",defaultMode:M="mini",defaultPosition:$}){let P=Xe(),r=react.useMemo(()=>Je(P),[P]),l=react.useMemo(()=>qe(r),[r]),[_,k]=react.useState(false),[N,z]=react.useState(false),L=react.useRef(false),D=t.dashboardUrl||"https://botbuddy.lovable.app",m=ue(D),F=(()=>{try{let e=typeof window<"u"?localStorage.getItem(Be):null;if(e)return JSON.parse(e)}catch{}return null})(),[H,V]=react.useState(F?.mode||M),[K,E]=react.useState(""),[Ie,B]=react.useState(null),[ge,xe]=react.useState(null),We=F?.x??$?.x??16,Le=F?.y??$?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:T,onPointerDown:O,onPointerMove:Y,onPointerUp:j,didDrag:oe}=le(We,Le);react.useEffect(()=>{try{localStorage.setItem(Be,JSON.stringify({mode:H,x:T.x,y:T.y}));}catch{}},[H,T.x,T.y]);let fe=react.useRef(m.isAuthenticated);react.useEffect(()=>{!fe.current&&m.isAuthenticated&&V("max"),fe.current=m.isAuthenticated;},[m.isAuthenticated]);let be="botbuddy-widget-max-size",De=()=>{try{let e=localStorage.getItem(be);if(e)return JSON.parse(e)}catch{}return {w:340,h:500}},[X,me]=react.useState(De),J=react.useRef(false),Z=react.useRef({x:0,y:0,w:0,h:0}),Ee=react.useCallback(e=>{e.stopPropagation(),J.current=true,Z.current={x:e.clientX,y:e.clientY,w:X.w,h:X.h},e.target.setPointerCapture(e.pointerId);},[X]),Ae=react.useCallback(e=>{if(!J.current)return;let u=Math.max(280,Math.min(600,Z.current.w+(e.clientX-Z.current.x))),C=Math.max(300,Math.min(window.innerHeight*.9,Z.current.h+(e.clientY-Z.current.y)));me({w:u,h:C});},[]),Ue=react.useCallback(()=>{J.current&&(J.current=false,me(e=>(localStorage.setItem(be,JSON.stringify(e)),e)));},[]),te=f??(typeof window<"u"?window.location.href:void 0),ye=m.displayName||p,[R,he]=react.useState(null);react.useEffect(()=>{if(m.isAuthenticated)return;let e=new URLSearchParams;S&&e.set("test_run_id",S),te&&e.set("target_url",te),e.set("app_slug",o),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=>he(u)).catch(()=>he(null));},[m.isAuthenticated,t.serverUrl,t.anonKey,o,s,S,te,x,h,v,b]);let{run:a,widgetState:I,fetchRun:Ne,setVerdict:ve,markComplete:Fe,resetRun:He}=de({config:t,appSlug:o,environment:s,testRunId:S,targetUrl:te,version:x,commitSha:h,prNumber:v?String(v):void 0,branchName:b,authToken:m.token}),G=react.useCallback(async(e,u,C)=>{xe(e);try{await ve(e,u,C,ye);}finally{xe(null),B(null),E("");}},[ve,ye]),y=a?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},Ve=y.total>0&&y.pending===0,A=I==="completed",Se=y.total>0?(y.pass+y.fail)/y.total*100:0,ie=react.useMemo(()=>{let e=a?.auto_tooltip_seconds??R?.auto_tooltip_seconds;return e!=null&&e>0?e*1e3:5e3},[a,R]),_e=I==="ready"||I==="completed"||R?.enabled&&R.run;if(react.useEffect(()=>{if(!_e||L.current||ie<=0)return;L.current=true,z(true);let e=window.setTimeout(()=>z(false),ie);return ()=>window.clearTimeout(e)},[_e,ie]),(I==="no-match"||I==="loading")&&!(!m.isAuthenticated&&R?.enabled&&R.run))return null;if(!m.isAuthenticated&&R?.enabled&&R.run){let e=R.run,u=e.summary,C=e.status==="completed";return jsxRuntime.jsx("div",{style:{...l.root,left:T.x,top:T.y},children:jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>k(true),onMouseLeave:()=>k(false),children:[jsxRuntime.jsxs("div",{style:{...l.pill(C),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:O,onPointerMove:Y,onPointerUp:()=>{j();},children:[jsxRuntime.jsx(g,{d:d.grip,size:10,className:""}),e.ticket_id&&e.ticket_url?jsxRuntime.jsx("a",{href:e.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.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:W=>W.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:W=>W.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:C?{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",{onClick:W=>{W.stopPropagation(),m.openLogin();},style:{color:r.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),(_||N)&&e.title&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",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||e.intro_notes)&&jsxRuntime.jsx("div",{style:{fontSize:"11px",color:r.textMuted,marginTop:"6px",lineHeight:1.4},children:e.description||e.intro_notes}),jsxRuntime.jsx("div",{style:{marginTop:"6px",fontSize:"9px",color:r.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!m.isAuthenticated)return jsxRuntime.jsxs("div",{style:{...l.root,left:T.x,top:T.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:O,onPointerMove:Y,onPointerUp:j,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(),m.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 ke=()=>{oe.current||(z(false),V(e=>e==="mini"?"max":"mini"));},we=({icon:e,onClick:u})=>jsxRuntime.jsx("button",{style:l.btn,onClick:C=>{C.stopPropagation(),u(C);},children:jsxRuntime.jsx(g,{d:e,className:""})}),Me=()=>{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})},ze=()=>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})]}),Te=()=>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.10");},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.10"})]}),m.isAuthenticated&&jsxRuntime.jsx("button",{onClick:e=>{e.stopPropagation(),m.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:T.x,top:T.y},children:[H==="mini"&&jsxRuntime.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>k(true),onMouseLeave:()=>k(false),children:[jsxRuntime.jsxs("div",{style:{...l.pill(A),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:O,onPointerMove:Y,onPointerUp:()=>{j(),oe.current||ke();},children:[jsxRuntime.jsx(g,{d:d.grip,size:10,className:""}),a?.ticket_id&&jsxRuntime.jsx("span",{style:{color:r.amber,fontWeight:600},children:a.ticket_id}),a?.pr_number&&jsxRuntime.jsxs("span",{style:{color:r.blue,fontWeight:600},children:["PR#",a.pr_number]}),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]}),jsxRuntime.jsxs("span",{style:A?{color:r.green}:void 0,children:[y.pass,"/",y.total]}),y.fail>0&&jsxRuntime.jsxs("span",{style:{color:r.red},children:[y.fail,"\u2717"]})]}),(_||N)&&a?.title&&jsxRuntime.jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",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||a.intro_notes)&&jsxRuntime.jsx("div",{style:{fontSize:"11px",color:r.textMuted,marginTop:"6px",lineHeight:1.4},children:a.description||a.intro_notes})]})]}),H==="expanded"&&jsxRuntime.jsxs("div",{style:l.card(300,A),children:[jsxRuntime.jsx(Me,{}),jsxRuntime.jsxs("div",{style:l.handle,onPointerDown:O,onPointerMove:Y,onPointerUp:j,onClick:ke,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(we,{icon:d.minus,onClick:()=>V("mini")})]}),jsxRuntime.jsxs("div",{style:l.stats,children:[jsxRuntime.jsxs("span",{style:{color:r.green},children:[y.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:r.red},children:[y.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:r.amber},children:[y.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:r.gripColor},children:[y.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:y.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(ze,{}),jsxRuntime.jsx(Te,{}),jsxRuntime.jsx("div",{style:l.progress,children:jsxRuntime.jsx("div",{style:l.progressBar(Se)})})]}),H==="max"&&jsxRuntime.jsxs("div",{style:{...l.card(X.w,A),height:X.h,position:"relative"},children:[jsxRuntime.jsx(Me,{}),jsxRuntime.jsxs("div",{style:l.handle,onPointerDown:O,onPointerMove:Y,onPointerUp:j,onClick:()=>{oe.current||V("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(we,{icon:d.minus,onClick:()=>V("mini")})]}),jsxRuntime.jsxs("div",{style:l.stats,children:[jsxRuntime.jsxs("span",{style:{color:r.green},children:[y.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:r.red},children:[y.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:r.amber},children:[y.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:r.gripColor},children:[y.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:y.total})]}),I==="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:Ne,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),A&&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:He,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}),I!=="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:Ze[e.verdict]},children:ge===e.id?jsxRuntime.jsx(g,{d:d.loader,className:""}):jsxRuntime.jsx(g,{d:Ge[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(Qe,{config:t,appSlug:o,environment:s,seedUserSlug:e.seed_user,authToken:m.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){G(e.id,"pending"),B(null);return}if(u==="fail"){G(e.id,"fail"),B(e.id),E("");return}B(null),G(e.id,u);},disabled:ge!==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})]}),Ie===e.id&&e.verdict==="fail"&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:K,onChange:u=>E(u.target.value),onKeyDown:u=>{u.key==="Enter"&&K.trim()&&(G(e.id,"fail",K),B(null),E("")),u.key==="Escape"&&(B(null),E(""));},placeholder:"Reason (optional)...",style:l.input}),jsxRuntime.jsx("button",{onClick:()=>{K.trim()&&G(e.id,"fail",K),B(null),E("");},style:l.verdictBtn(true,r.red),children:"\u2713"})]})]},e.id))}),Ve&&!A&&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:Fe,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(ze,{}),jsxRuntime.jsx(Te,{}),jsxRuntime.jsx("div",{style:l.progress,children:jsxRuntime.jsx("div",{style:l.progressBar(Se)})}),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:Ee,onPointerMove:Ae,onPointerUp:Ue,onPointerEnter:e=>e.currentTarget.style.opacity="0.7",onPointerLeave:e=>{J.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=et;exports.useDraggable=le;exports.useTestRun=de;exports.useWidgetAuth=ue;
|
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 ae(t,o){let[a,S]=useState({x:t,y:o}),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-a.x,y:p.clientY-a.y},p.target.setPointerCapture(p.pointerId);},[a]),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:a,onPointerDown:v,onPointerMove:b,onPointerUp:c,didDrag:h}}function ne(t,o){let a={apikey:t.anonKey};return o?a.Authorization=`Bearer ${o}`:t.apiKey?a.Authorization=`Bearer ${t.apiKey}`:a.Authorization=`Bearer ${t.anonKey}`,a}function se(t){let[o,a]=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:ne(t.config,t.authToken)});if(p.status===404){f("no-match"),a(null);return}if(p.status===401||p.status===403){f("error");return}if(!p.ok){f("error");return}let M=await p.json();a(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:o,widgetState:S,fetchRun:x,setVerdict:async(c,p,M,C="human")=>(a(r=>{if(!r)return null;let l=r.test_cases.map(w=>w.id===c?{...w,verdict:p,fail_reason:p==="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(`${t.config.serverUrl}/widget/test-cases/${c}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",...ne(t.config,t.authToken)},body:JSON.stringify({verdict:p,fail_reason:M,display_name:C})})).ok),markComplete:async()=>o?(a(p=>p?{...p,status:"completed"}:null),f("completed"),(await fetch(`${t.config.serverUrl}/widget/test-runs/${o.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...ne(t.config,t.authToken)}})).ok):false,resetRun:async()=>{if(!o)return false;let c=await fetch(`${t.config.serverUrl}/widget/test-runs/${o.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...ne(t.config,t.authToken)}});return c.ok&&x(),c.ok},setRun:a}}var le="botbuddy-widget-auth-token",de="botbuddy-widget-auth-name";function pe(t){let[o,a]=useState(()=>{try{return localStorage.getItem(le)}catch{return null}}),[S,f]=useState(()=>{try{return localStorage.getItem(de)}catch{return null}});useEffect(()=>{let v=b=>{if(b.data?.type==="botbuddy-widget-auth"&&b.data.token){let{token:c,displayName:p}=b.data;a(c),f(p||"human");try{localStorage.setItem(le,c),p&&localStorage.setItem(de,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(()=>{a(null),f(null);try{localStorage.removeItem(le),localStorage.removeItem(de);}catch{}},[]);return {token:o,displayName:S,isAuthenticated:!!o,openLogin:x,logout:h}}var g=({d:t,className:o,size:a=14})=>jsx("svg",{className:o,width:a,height:a,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d: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 je(){let[t,o]=useState(()=>typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");return useEffect(()=>{if(typeof window>"u")return;let a=document.documentElement,S=()=>a.classList.contains("dark")?"dark":a.classList.contains("light")?"light":null,f=S();f&&o(f);let x=window.matchMedia("(prefers-color-scheme: dark)"),h=b=>{let c=S();o(c||(b.matches?"dark":"light"));};x.addEventListener("change",h);let v=new MutationObserver(()=>{let b=S();o(b||(x.matches?"dark":"light"));});return v.observe(a,{attributes:true,attributeFilter:["class"]}),()=>{x.removeEventListener("change",h),v.disconnect();}},[]),t}function Xe(t){let o=t==="dark";return {bg:o?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:o?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:o?"#e5e5e5":"#1a1a1a",textMuted:o?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:o?"#555":"#999",border:o?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:o?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:o?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:o?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:o?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:o?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:o?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:o?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:o?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:o?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:o?"#888":"#aaa",btnHover:o?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var Je={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},Ze={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)"}},Ge=t=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:o=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:t.bg,border:o?`1px solid ${t.greenBorder}`:`1px solid ${t.border}`,boxShadow:o?`0 4px 12px ${t.shadow}, 0 0 0 1px ${t.greenBorderSubtle}`:`0 4px 12px ${t.shadow}`,cursor:"pointer",fontSize:"9px",color:t.text}),card:(o,a)=>({width:`${o}px`,borderRadius:"8px",background:t.bg,border:a?`1px solid ${t.greenBorder}`:`1px solid ${t.border}`,boxShadow:a?`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:o=>{let a=$e[o]||$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:t.borderSubtle,flexShrink:0},progressBar:o=>({height:"100%",width:`${o}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:o=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${o}15`,color:o,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${t.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(o,a)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:o?`${a}33`:"transparent",color:o?a: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 qe({config:t,appSlug:o,environment:a,seedUserSlug:S,authToken:f,tk:x}){let[h,v]=useState(null),[b,c]=useState(0),[p,M]=useState(false),[C,$]=useState(null),[r,l]=useState(false),k=useRef(null),w=useMemo(()=>S.split("/")[0].trim(),[S]),N=useCallback(async()=>{M(true),$(null);try{let z=new URLSearchParams({app_slug:o,seed_user_slug:w,environment:a}),L={apikey:t.anonKey};f?L.Authorization=`Bearer ${f}`:L.Authorization=`Bearer ${t.anonKey}`;let D=await fetch(`${t.serverUrl}/widget/totp-code?${z}`,{headers:L});if(!D.ok){let F=await D.json().catch(()=>({error:"Failed"}));if(D.status===404){$("No 2FA seed registered");return}$(F.error||"Failed to get code");return}let m=await D.json();v(m.code),c(m.remaining_seconds);try{await navigator.clipboard.writeText(m.code),l(!0),setTimeout(()=>l(!1),2e3);}catch{}k.current&&clearInterval(k.current);let ee=m.remaining_seconds;k.current=setInterval(()=>{ee--,ee<=0?(k.current&&clearInterval(k.current),N()):c(ee);},1e3);}catch{$("Network error");}finally{M(false);}},[t.serverUrl,t.anonKey,f,o,w,a]);return useEffect(()=>()=>{k.current&&clearInterval(k.current);},[]),C==="No 2FA seed registered"?null:h?jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"3px"},children:[jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"3px 8px",borderRadius:"4px",background:`${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:z=>{z.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:z=>{z.stopPropagation(),N();},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...":C||"Get 2FA code"]})}var Pe="botbuddy-widget-state";function Qe({config:t,appSlug:o,environment:a,testRunId:S,targetUrl:f,version:x,commitSha:h,prNumber:v,branchName:b,onNavigate:c,displayName:p="human",defaultMode:M="mini",defaultPosition:C}){let $=je(),r=useMemo(()=>Xe($),[$]),l=useMemo(()=>Ge(r),[r]),[k,w]=useState(false),[N,z]=useState(false),L=useRef(false),D=t.dashboardUrl||"https://botbuddy.lovable.app",m=pe(D),F=(()=>{try{let e=typeof window<"u"?localStorage.getItem(Pe):null;if(e)return JSON.parse(e)}catch{}return null})(),[H,K]=useState(F?.mode||M),[V,E]=useState(""),[Be,P]=useState(null),[ue,ge]=useState(null),Ie=F?.x??C?.x??16,We=F?.y??C?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:T,onPointerDown:O,onPointerMove:Y,onPointerUp:j,didDrag:re}=ae(Ie,We);useEffect(()=>{try{localStorage.setItem(Pe,JSON.stringify({mode:H,x:T.x,y:T.y}));}catch{}},[H,T.x,T.y]);let xe=useRef(m.isAuthenticated);useEffect(()=>{!xe.current&&m.isAuthenticated&&K("max"),xe.current=m.isAuthenticated;},[m.isAuthenticated]);let fe="botbuddy-widget-max-size",Le=()=>{try{let e=localStorage.getItem(fe);if(e)return JSON.parse(e)}catch{}return {w:340,h:500}},[X,be]=useState(Le),J=useRef(false),Z=useRef({x:0,y:0,w:0,h:0}),De=useCallback(e=>{e.stopPropagation(),J.current=true,Z.current={x:e.clientX,y:e.clientY,w:X.w,h:X.h},e.target.setPointerCapture(e.pointerId);},[X]),Ee=useCallback(e=>{if(!J.current)return;let u=Math.max(280,Math.min(600,Z.current.w+(e.clientX-Z.current.x))),R=Math.max(300,Math.min(window.innerHeight*.9,Z.current.h+(e.clientY-Z.current.y)));be({w:u,h:R});},[]),Ae=useCallback(()=>{J.current&&(J.current=false,be(e=>(localStorage.setItem(fe,JSON.stringify(e)),e)));},[]),te=f??(typeof window<"u"?window.location.href:void 0),me=m.displayName||p,[B,ye]=useState(null);useEffect(()=>{if(m.isAuthenticated)return;let e=new URLSearchParams;S&&e.set("test_run_id",S),te&&e.set("target_url",te),e.set("app_slug",o),e.set("environment",a),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=>ye(u)).catch(()=>ye(null));},[m.isAuthenticated,t.serverUrl,t.anonKey,o,a,S,te,x,h,v,b]);let{run:s,widgetState:I,fetchRun:Ue,setVerdict:he,markComplete:Ne,resetRun:Fe}=se({config:t,appSlug:o,environment:a,testRunId:S,targetUrl:te,version:x,commitSha:h,prNumber:v?String(v):void 0,branchName:b,authToken:m.token}),G=useCallback(async(e,u,R)=>{ge(e);try{await he(e,u,R,me);}finally{ge(null),P(null),E("");}},[he,me]),y=s?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},He=y.total>0&&y.pending===0,A=I==="completed",ve=y.total>0?(y.pass+y.fail)/y.total*100:0,Se=I==="ready"||I==="completed"||B?.enabled&&B.run;if(useEffect(()=>{if(!Se||L.current)return;L.current=true,z(true);let e=window.setTimeout(()=>z(false),5e3);return ()=>window.clearTimeout(e)},[Se]),(I==="no-match"||I==="loading")&&!(!m.isAuthenticated&&B?.enabled&&B.run))return null;if(!m.isAuthenticated&&B?.enabled&&B.run){let e=B.run,u=e.summary,R=e.status==="completed";return jsx("div",{style:{...l.root,left:T.x,top:T.y},children:jsxs("div",{style:{position:"relative"},onMouseEnter:()=>w(true),onMouseLeave:()=>w(false),children:[jsxs("div",{style:{...l.pill(R),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:O,onPointerMove:Y,onPointerUp:()=>{j();},children:[jsx(g,{d:d.grip,size:10,className:""}),e.ticket_id&&e.ticket_url?jsx("a",{href:e.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.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:W=>W.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:W=>W.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",{onClick:W=>{W.stopPropagation(),m.openLogin();},style:{color:r.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),(k||N)&&e.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",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||e.intro_notes)&&jsx("div",{style:{fontSize:"11px",color:r.textMuted,marginTop:"6px",lineHeight:1.4},children:e.description||e.intro_notes}),jsx("div",{style:{marginTop:"6px",fontSize:"9px",color:r.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!m.isAuthenticated)return jsxs("div",{style:{...l.root,left:T.x,top:T.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:O,onPointerMove:Y,onPointerUp:j,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(),m.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 ke=()=>{re.current||(z(false),K(e=>e==="mini"?"max":"mini"));},we=({icon:e,onClick:u})=>jsx("button",{style:l.btn,onClick:R=>{R.stopPropagation(),u(R);},children:jsx(g,{d:e,className:""})}),_e=()=>{if(!s?.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:s.assigned_human_display_name}),s.codex_thread_id&&jsx(g,{d:d.externalLink,size:10})]});return s.codex_thread_id?jsx("a",{href:`codex://threads/${s.codex_thread_id}`,style:l.humanBanner,children:e}):jsx("div",{style:l.humanBanner,children:e})},Me=()=>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(g,{d:d.pr,size:12}),s.pr_id||"PR",jsx(g,{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(g,{d:d.ticket,size:12}),s.ticket_id||"Ticket",jsx(g,{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(g,{d:d.bot,size:12}),s.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}),s.created_by_agent_name]})),jsx("span",{style:{...l.badge(s?.environment||"custom"),marginLeft:"auto"},children:s?.environment})]}),ze=()=>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.10");},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.10"})]}),m.isAuthenticated&&jsx("button",{onClick:e=>{e.stopPropagation(),m.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:T.x,top:T.y},children:[H==="mini"&&jsxs("div",{style:{position:"relative"},onMouseEnter:()=>w(true),onMouseLeave:()=>w(false),children:[jsxs("div",{style:{...l.pill(A),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:O,onPointerMove:Y,onPointerUp:()=>{j(),re.current||ke();},children:[jsx(g,{d:d.grip,size:10,className:""}),s?.ticket_id&&jsx("span",{style:{color:r.amber,fontWeight:600},children:s.ticket_id}),s?.pr_number&&jsxs("span",{style:{color:r.blue,fontWeight:600},children:["PR#",s.pr_number]}),s?.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}),s.created_by_agent_name]}),jsxs("span",{style:A?{color:r.green}:void 0,children:[y.pass,"/",y.total]}),y.fail>0&&jsxs("span",{style:{color:r.red},children:[y.fail,"\u2717"]})]}),(k||N)&&s?.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",left:0,minWidth:"220px",maxWidth:"320px",padding:"10px 14px",borderRadius:"8px",background:r.bg,border:`1px solid ${r.border}`,boxShadow:`0 8px 24px ${r.shadow}`,pointerEvents:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},children:[jsx("div",{style:{fontSize:"13px",fontWeight:700,color:r.text,lineHeight:1.3},children:s.title}),(s.description||s.intro_notes)&&jsx("div",{style:{fontSize:"11px",color:r.textMuted,marginTop:"6px",lineHeight:1.4},children:s.description||s.intro_notes})]})]}),H==="expanded"&&jsxs("div",{style:l.card(300,A),children:[jsx(_e,{}),jsxs("div",{style:l.handle,onPointerDown:O,onPointerMove:Y,onPointerUp:j,onClick:ke,children:[jsx(g,{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(g,{d:d.chevronUp,className:""}),jsx(we,{icon:d.minus,onClick:()=>K("mini")})]}),jsxs("div",{style:l.stats,children:[jsxs("span",{style:{color:r.green},children:[y.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[y.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[y.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[y.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:y.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(Me,{}),jsx(ze,{}),jsx("div",{style:l.progress,children:jsx("div",{style:l.progressBar(ve)})})]}),H==="max"&&jsxs("div",{style:{...l.card(X.w,A),height:X.h,position:"relative"},children:[jsx(_e,{}),jsxs("div",{style:l.handle,onPointerDown:O,onPointerMove:Y,onPointerUp:j,onClick:()=>{re.current||K("expanded");},children:[jsx(g,{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(g,{d:d.chevronDown,className:""}),jsx(we,{icon:d.minus,onClick:()=>K("mini")})]}),jsxs("div",{style:l.stats,children:[jsxs("span",{style:{color:r.green},children:[y.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[y.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[y.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[y.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:y.total})]}),I==="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:Ue,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),A&&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:Fe,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}),I!=="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(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:Je[e.verdict]},children:ue===e.id?jsx(g,{d:d.loader,className:""}):jsx(g,{d:Ze[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})]}),a!=="production"&&jsx(qe,{config:t,appSlug:o,environment:a,seedUserSlug:e.seed_user,authToken:m.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){G(e.id,"pending"),P(null);return}if(u==="fail"){G(e.id,"fail"),P(e.id),E("");return}P(null),G(e.id,u);},disabled:ue!==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})]}),Be===e.id&&e.verdict==="fail"&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:V,onChange:u=>E(u.target.value),onKeyDown:u=>{u.key==="Enter"&&V.trim()&&(G(e.id,"fail",V),P(null),E("")),u.key==="Escape"&&(P(null),E(""));},placeholder:"Reason (optional)...",style:l.input}),jsx("button",{onClick:()=>{V.trim()&&G(e.id,"fail",V),P(null),E("");},style:l.verdictBtn(true,r.red),children:"\u2713"})]})]},e.id))}),He&&!A&&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:Ne,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(Me,{}),jsx(ze,{}),jsx("div",{style:l.progress,children:jsx("div",{style:l.progressBar(ve)})}),jsx("div",{style:{position:"absolute",bottom:0,right:0,width:16,height:16,cursor:"se-resize",zIndex:10,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:"2px",opacity:.3},onPointerDown:De,onPointerMove:Ee,onPointerUp:Ae,onPointerEnter:e=>e.currentTarget.style.opacity="0.7",onPointerLeave:e=>{J.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{
|
|
1
|
+
import {useState,useRef,useCallback,useEffect,useMemo}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';function le(t,o){let[s,S]=useState({x:t,y:o}),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 ne(t,o){let s={apikey:t.anonKey};return o?s.Authorization=`Bearer ${o}`:t.apiKey?s.Authorization=`Bearer ${t.apiKey}`:s.Authorization=`Bearer ${t.anonKey}`,s}function de(t){let[o,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:ne(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:o,widgetState:S,fetchRun:x,setVerdict:async(c,p,M,$="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:$,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",...ne(t.config,t.authToken)},body:JSON.stringify({verdict:p,fail_reason:M,display_name:$})})).ok),markComplete:async()=>o?(s(p=>p?{...p,status:"completed"}:null),f("completed"),(await fetch(`${t.config.serverUrl}/widget/test-runs/${o.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",...ne(t.config,t.authToken)}})).ok):false,resetRun:async()=>{if(!o)return false;let c=await fetch(`${t.config.serverUrl}/widget/test-runs/${o.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",...ne(t.config,t.authToken)}});return c.ok&&x(),c.ok},setRun:s}}var pe="botbuddy-widget-auth-token",ce="botbuddy-widget-auth-name";function ue(t){let[o,s]=useState(()=>{try{return localStorage.getItem(pe)}catch{return null}}),[S,f]=useState(()=>{try{return localStorage.getItem(ce)}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(pe,c),p&&localStorage.setItem(ce,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(pe),localStorage.removeItem(ce);}catch{}},[]);return {token:o,displayName:S,isAuthenticated:!!o,openLogin:x,logout:h}}var g=({d:t,className:o,size:s=14})=>jsx("svg",{className:o,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 Xe(){let[t,o]=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&&o(f);let x=window.matchMedia("(prefers-color-scheme: dark)"),h=b=>{let c=S();o(c||(b.matches?"dark":"light"));};x.addEventListener("change",h);let v=new MutationObserver(()=>{let b=S();o(b||(x.matches?"dark":"light"));});return v.observe(s,{attributes:true,attributeFilter:["class"]}),()=>{x.removeEventListener("change",h),v.disconnect();}},[]),t}function Je(t){let o=t==="dark";return {bg:o?"rgb(30,30,30)":"rgb(255,255,255)",bgSoft:o?"rgba(255,255,255,0.02)":"rgba(0,0,0,0.02)",text:o?"#e5e5e5":"#1a1a1a",textMuted:o?"rgba(255,255,255,0.4)":"rgba(0,0,0,0.45)",textFaint:o?"#555":"#999",border:o?"rgba(255,255,255,0.15)":"rgba(0,0,0,0.12)",borderSubtle:o?"rgba(255,255,255,0.06)":"rgba(0,0,0,0.06)",shadow:o?"rgba(0,0,0,0.4)":"rgba(0,0,0,0.12)",inputBg:o?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.04)",inputBorder:o?"rgba(255,255,255,0.1)":"rgba(0,0,0,0.12)",green:"#34d399",greenBg:o?"rgba(52,211,153,0.05)":"rgba(52,211,153,0.08)",greenBorder:o?"rgba(52,211,153,0.6)":"rgba(52,211,153,0.5)",greenBorderSubtle:o?"rgba(52,211,153,0.2)":"rgba(52,211,153,0.15)",red:"#f87171",amber:"#f59e0b",blue:"#60a5fa",purple:"#a78bfa",versionText:o?"rgba(255,255,255,0.5)":"rgba(0,0,0,0.35)",versionNum:o?"rgba(255,255,255,0.3)":"rgba(0,0,0,0.2)",gripColor:o?"#888":"#aaa",btnHover:o?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)"}}var Ze={pending:"#888",pass:"#34d399",fail:"#f87171",skip:"#f59e0b"},Ge={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},Pe={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)"}},qe=t=>({root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:o=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:t.bg,border:o?`1px solid ${t.greenBorder}`:`1px solid ${t.border}`,boxShadow:o?`0 4px 12px ${t.shadow}, 0 0 0 1px ${t.greenBorderSubtle}`:`0 4px 12px ${t.shadow}`,cursor:"pointer",fontSize:"9px",color:t.text}),card:(o,s)=>({width:`${o}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:o=>{let s=Pe[o]||Pe.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:o=>({height:"100%",width:`${o}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:o=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${o}15`,color:o,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:`1px solid ${t.borderSubtle}`,transition:"background 0.15s"},verdictBtn:(o,s)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:o?`${s}33`:"transparent",color:o?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 Qe({config:t,appSlug:o,environment:s,seedUserSlug:S,authToken:f,tk:x}){let[h,v]=useState(null),[b,c]=useState(0),[p,M]=useState(false),[$,P]=useState(null),[r,l]=useState(false),_=useRef(null),k=useMemo(()=>S.split("/")[0].trim(),[S]),N=useCallback(async()=>{M(true),P(null);try{let z=new URLSearchParams({app_slug:o,seed_user_slug:k,environment:s}),L={apikey:t.anonKey};f?L.Authorization=`Bearer ${f}`:L.Authorization=`Bearer ${t.anonKey}`;let D=await fetch(`${t.serverUrl}/widget/totp-code?${z}`,{headers:L});if(!D.ok){let F=await D.json().catch(()=>({error:"Failed"}));if(D.status===404){P("No 2FA seed registered");return}P(F.error||"Failed to get code");return}let m=await D.json();v(m.code),c(m.remaining_seconds);try{await navigator.clipboard.writeText(m.code),l(!0),setTimeout(()=>l(!1),2e3);}catch{}_.current&&clearInterval(_.current);let ee=m.remaining_seconds;_.current=setInterval(()=>{ee--,ee<=0?(_.current&&clearInterval(_.current),N()):c(ee);},1e3);}catch{P("Network error");}finally{M(false);}},[t.serverUrl,t.anonKey,f,o,k,s]);return useEffect(()=>()=>{_.current&&clearInterval(_.current);},[]),$==="No 2FA seed registered"?null:h?jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"3px"},children:[jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"3px 8px",borderRadius:"4px",background:`${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:z=>{z.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:z=>{z.stopPropagation(),N();},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...":$||"Get 2FA code"]})}var Be="botbuddy-widget-state";function et({config:t,appSlug:o,environment:s,testRunId:S,targetUrl:f,version:x,commitSha:h,prNumber:v,branchName:b,onNavigate:c,displayName:p="human",defaultMode:M="mini",defaultPosition:$}){let P=Xe(),r=useMemo(()=>Je(P),[P]),l=useMemo(()=>qe(r),[r]),[_,k]=useState(false),[N,z]=useState(false),L=useRef(false),D=t.dashboardUrl||"https://botbuddy.lovable.app",m=ue(D),F=(()=>{try{let e=typeof window<"u"?localStorage.getItem(Be):null;if(e)return JSON.parse(e)}catch{}return null})(),[H,V]=useState(F?.mode||M),[K,E]=useState(""),[Ie,B]=useState(null),[ge,xe]=useState(null),We=F?.x??$?.x??16,Le=F?.y??$?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:T,onPointerDown:O,onPointerMove:Y,onPointerUp:j,didDrag:oe}=le(We,Le);useEffect(()=>{try{localStorage.setItem(Be,JSON.stringify({mode:H,x:T.x,y:T.y}));}catch{}},[H,T.x,T.y]);let fe=useRef(m.isAuthenticated);useEffect(()=>{!fe.current&&m.isAuthenticated&&V("max"),fe.current=m.isAuthenticated;},[m.isAuthenticated]);let be="botbuddy-widget-max-size",De=()=>{try{let e=localStorage.getItem(be);if(e)return JSON.parse(e)}catch{}return {w:340,h:500}},[X,me]=useState(De),J=useRef(false),Z=useRef({x:0,y:0,w:0,h:0}),Ee=useCallback(e=>{e.stopPropagation(),J.current=true,Z.current={x:e.clientX,y:e.clientY,w:X.w,h:X.h},e.target.setPointerCapture(e.pointerId);},[X]),Ae=useCallback(e=>{if(!J.current)return;let u=Math.max(280,Math.min(600,Z.current.w+(e.clientX-Z.current.x))),C=Math.max(300,Math.min(window.innerHeight*.9,Z.current.h+(e.clientY-Z.current.y)));me({w:u,h:C});},[]),Ue=useCallback(()=>{J.current&&(J.current=false,me(e=>(localStorage.setItem(be,JSON.stringify(e)),e)));},[]),te=f??(typeof window<"u"?window.location.href:void 0),ye=m.displayName||p,[R,he]=useState(null);useEffect(()=>{if(m.isAuthenticated)return;let e=new URLSearchParams;S&&e.set("test_run_id",S),te&&e.set("target_url",te),e.set("app_slug",o),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=>he(u)).catch(()=>he(null));},[m.isAuthenticated,t.serverUrl,t.anonKey,o,s,S,te,x,h,v,b]);let{run:a,widgetState:I,fetchRun:Ne,setVerdict:ve,markComplete:Fe,resetRun:He}=de({config:t,appSlug:o,environment:s,testRunId:S,targetUrl:te,version:x,commitSha:h,prNumber:v?String(v):void 0,branchName:b,authToken:m.token}),G=useCallback(async(e,u,C)=>{xe(e);try{await ve(e,u,C,ye);}finally{xe(null),B(null),E("");}},[ve,ye]),y=a?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},Ve=y.total>0&&y.pending===0,A=I==="completed",Se=y.total>0?(y.pass+y.fail)/y.total*100:0,ie=useMemo(()=>{let e=a?.auto_tooltip_seconds??R?.auto_tooltip_seconds;return e!=null&&e>0?e*1e3:5e3},[a,R]),_e=I==="ready"||I==="completed"||R?.enabled&&R.run;if(useEffect(()=>{if(!_e||L.current||ie<=0)return;L.current=true,z(true);let e=window.setTimeout(()=>z(false),ie);return ()=>window.clearTimeout(e)},[_e,ie]),(I==="no-match"||I==="loading")&&!(!m.isAuthenticated&&R?.enabled&&R.run))return null;if(!m.isAuthenticated&&R?.enabled&&R.run){let e=R.run,u=e.summary,C=e.status==="completed";return jsx("div",{style:{...l.root,left:T.x,top:T.y},children:jsxs("div",{style:{position:"relative"},onMouseEnter:()=>k(true),onMouseLeave:()=>k(false),children:[jsxs("div",{style:{...l.pill(C),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:O,onPointerMove:Y,onPointerUp:()=>{j();},children:[jsx(g,{d:d.grip,size:10,className:""}),e.ticket_id&&e.ticket_url?jsx("a",{href:e.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:W=>W.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:W=>W.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:W=>W.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:C?{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",{onClick:W=>{W.stopPropagation(),m.openLogin();},style:{color:r.textMuted,fontWeight:400,cursor:"pointer",textDecoration:"underline",textUnderlineOffset:"2px"},children:"Sign in"})]}),(_||N)&&e.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",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||e.intro_notes)&&jsx("div",{style:{fontSize:"11px",color:r.textMuted,marginTop:"6px",lineHeight:1.4},children:e.description||e.intro_notes}),jsx("div",{style:{marginTop:"6px",fontSize:"9px",color:r.textFaint},children:'Click "Sign in" to start testing'})]})]})})}if(!m.isAuthenticated)return jsxs("div",{style:{...l.root,left:T.x,top:T.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:O,onPointerMove:Y,onPointerUp:j,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(),m.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 ke=()=>{oe.current||(z(false),V(e=>e==="mini"?"max":"mini"));},we=({icon:e,onClick:u})=>jsx("button",{style:l.btn,onClick:C=>{C.stopPropagation(),u(C);},children:jsx(g,{d:e,className:""})}),Me=()=>{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})},ze=()=>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})]}),Te=()=>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.10");},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.10"})]}),m.isAuthenticated&&jsx("button",{onClick:e=>{e.stopPropagation(),m.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:T.x,top:T.y},children:[H==="mini"&&jsxs("div",{style:{position:"relative"},onMouseEnter:()=>k(true),onMouseLeave:()=>k(false),children:[jsxs("div",{style:{...l.pill(A),gap:"8px",padding:"5px 10px",fontSize:"10px"},onPointerDown:O,onPointerMove:Y,onPointerUp:()=>{j(),oe.current||ke();},children:[jsx(g,{d:d.grip,size:10,className:""}),a?.ticket_id&&jsx("span",{style:{color:r.amber,fontWeight:600},children:a.ticket_id}),a?.pr_number&&jsxs("span",{style:{color:r.blue,fontWeight:600},children:["PR#",a.pr_number]}),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]}),jsxs("span",{style:A?{color:r.green}:void 0,children:[y.pass,"/",y.total]}),y.fail>0&&jsxs("span",{style:{color:r.red},children:[y.fail,"\u2717"]})]}),(_||N)&&a?.title&&jsxs("div",{style:{position:"absolute",top:"calc(100% + 6px)",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||a.intro_notes)&&jsx("div",{style:{fontSize:"11px",color:r.textMuted,marginTop:"6px",lineHeight:1.4},children:a.description||a.intro_notes})]})]}),H==="expanded"&&jsxs("div",{style:l.card(300,A),children:[jsx(Me,{}),jsxs("div",{style:l.handle,onPointerDown:O,onPointerMove:Y,onPointerUp:j,onClick:ke,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(we,{icon:d.minus,onClick:()=>V("mini")})]}),jsxs("div",{style:l.stats,children:[jsxs("span",{style:{color:r.green},children:[y.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[y.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[y.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[y.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:y.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(ze,{}),jsx(Te,{}),jsx("div",{style:l.progress,children:jsx("div",{style:l.progressBar(Se)})})]}),H==="max"&&jsxs("div",{style:{...l.card(X.w,A),height:X.h,position:"relative"},children:[jsx(Me,{}),jsxs("div",{style:l.handle,onPointerDown:O,onPointerMove:Y,onPointerUp:j,onClick:()=>{oe.current||V("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(we,{icon:d.minus,onClick:()=>V("mini")})]}),jsxs("div",{style:l.stats,children:[jsxs("span",{style:{color:r.green},children:[y.pass,"\u2713"]}),jsxs("span",{style:{color:r.red},children:[y.fail,"\u2717"]}),jsxs("span",{style:{color:r.amber},children:[y.skip,"\u23ED"]}),jsxs("span",{style:{color:r.gripColor},children:[y.pending,"\u25CC"]}),jsx("span",{style:{color:r.textFaint,marginLeft:"auto"},children:y.total})]}),I==="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:Ne,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),A&&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:He,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}),I!=="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:Ze[e.verdict]},children:ge===e.id?jsx(g,{d:d.loader,className:""}):jsx(g,{d:Ge[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(Qe,{config:t,appSlug:o,environment:s,seedUserSlug:e.seed_user,authToken:m.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){G(e.id,"pending"),B(null);return}if(u==="fail"){G(e.id,"fail"),B(e.id),E("");return}B(null),G(e.id,u);},disabled:ge!==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})]}),Ie===e.id&&e.verdict==="fail"&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:K,onChange:u=>E(u.target.value),onKeyDown:u=>{u.key==="Enter"&&K.trim()&&(G(e.id,"fail",K),B(null),E("")),u.key==="Escape"&&(B(null),E(""));},placeholder:"Reason (optional)...",style:l.input}),jsx("button",{onClick:()=>{K.trim()&&G(e.id,"fail",K),B(null),E("");},style:l.verdictBtn(true,r.red),children:"\u2713"})]})]},e.id))}),Ve&&!A&&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:Fe,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(ze,{}),jsx(Te,{}),jsx("div",{style:l.progress,children:jsx("div",{style:l.progressBar(Se)})}),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:Ee,onPointerMove:Ae,onPointerUp:Ue,onPointerEnter:e=>e.currentTarget.style.opacity="0.7",onPointerLeave:e=>{J.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{et as TestRunWidget,le as useDraggable,de as useTestRun,ue as useWidgetAuth};
|
package/package.json
CHANGED