@botbuddy/react 0.5.4 → 0.5.6

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