@testver/testver 1.4.2 → 1.5.0

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.
Files changed (110) hide show
  1. package/LICENSE +88 -69
  2. package/README.md +6 -2
  3. package/bin/testver.js +9 -1
  4. package/dist/index.js +52650 -35771
  5. package/package.json +179 -178
  6. package/src/ui/static/agents/antigravity.svg +76 -0
  7. package/src/ui/static/agents/codex.svg +3 -0
  8. package/src/ui/static/agents/gemini.svg +1 -0
  9. package/src/ui/static/agents/opencode.svg +4 -0
  10. package/src/ui/static/agents/vscode.svg +17 -0
  11. package/src/ui/static/assets/AIPanel-RWO8Cd9w.js +32 -0
  12. package/src/ui/static/assets/AIRecordPanel-DnreS585.js +40 -0
  13. package/src/ui/static/assets/AIStreamUI-C1gHJtlF.js +9 -0
  14. package/src/ui/static/assets/{AITestGenPage-D3t2gPAA.js → AITestGenPage-C8bWUelu.js} +5 -5
  15. package/src/ui/static/assets/APITestingPage-DwL67hqL.js +19 -0
  16. package/src/ui/static/assets/AboutPage-CynLB95E.js +1 -0
  17. package/src/ui/static/assets/AccessTokensTab-BdevOmpE.js +1 -0
  18. package/src/ui/static/assets/AdvancedPage-BeM7aB8b.js +3 -0
  19. package/src/ui/static/assets/{AnalyticsPage-64mYNK2v.js → AnalyticsPage-C5ddYfRk.js} +1 -1
  20. package/src/ui/static/assets/AuditLogPage-DYcUdJoj.js +1 -0
  21. package/src/ui/static/assets/ChangesSummary-BjNMwGIZ.js +3 -0
  22. package/src/ui/static/assets/{CodeMapPage-B1ezmnlE.js → CodeMapPage-BQOEtv-R.js} +3 -3
  23. package/src/ui/static/assets/{ConfirmDialog-t7mpeeSN.js → ConfirmDialog-D_N9188T.js} +1 -1
  24. package/src/ui/static/assets/{CoveragePage-YMmCbiBk.js → CoveragePage-8bDSphY1.js} +2 -2
  25. package/src/ui/static/assets/{CronBuilder-Nk-K-_8I.js → CronBuilder-C7_JADb7.js} +1 -1
  26. package/src/ui/static/assets/{Dashboard-BDVxO2V4.js → Dashboard-B22yRPyV.js} +1 -1
  27. package/src/ui/static/assets/{DefectsPage-l8yGeCyR.js → DefectsPage-Arv4Ac-b.js} +72 -72
  28. package/src/ui/static/assets/{EmptyState-D1T3JWUr.js → EmptyState-BShNSbLf.js} +1 -1
  29. package/src/ui/static/assets/{ExportButton-Dt5RhL-h.js → ExportButton-xrS_AnfS.js} +1 -1
  30. package/src/ui/static/assets/{FileViewer-CrKgh_cB.js → FileViewer-Bcr9T1jW.js} +18 -18
  31. package/src/ui/static/assets/{GitPage-_4nCEzkJ.js → GitPage-DXL2Sv40.js} +12 -12
  32. package/src/ui/static/assets/{ImportExportPage-BcR7IQi9.js → ImportExportPage-BcjzRd7T.js} +36 -36
  33. package/src/ui/static/assets/{JiraPushDialog-C2sP4_4h.js → JiraPushDialog-DNYU9Ce0.js} +1 -1
  34. package/src/ui/static/assets/{KpiTile-inmeEsy3.js → KpiTile-BKlWqjgN.js} +1 -1
  35. package/src/ui/static/assets/{LiveExecutionView-D5BRe9jq.js → LiveExecutionView-1LlyEDEe.js} +1 -1
  36. package/src/ui/static/assets/{ManagePage-B8iG6Q0B.js → ManagePage-SvRQ6L19.js} +1 -1
  37. package/src/ui/static/assets/{MediaModal-C5n6sHYi.js → MediaModal-Dyy_iHl9.js} +1 -1
  38. package/src/ui/static/assets/MobileRunPicker-Cf5rm469.js +1 -0
  39. package/src/ui/static/assets/MobileRunTarget-C4M4YJJh.js +6 -0
  40. package/src/ui/static/assets/{ModuleExplorer-VGcmK167.js → ModuleExplorer-BKVbxFZK.js} +1 -1
  41. package/src/ui/static/assets/{OutputPage-B_1nPPxE.js → OutputPage-Bi-28tJi.js} +1 -1
  42. package/src/ui/static/assets/PipelinesPanel-BtO3iSJ4.js +1 -0
  43. package/src/ui/static/assets/{ProfilePage-y7tJNNFd.js → ProfilePage-BgZ4VDC-.js} +1 -1
  44. package/src/ui/static/assets/{ProjectExplorer-DbfGhRq0.js → ProjectExplorer-BVGbmVP7.js} +1 -1
  45. package/src/ui/static/assets/{RemoteFileStrip-WuRKtx_h.js → RemoteFileStrip-dzPInzgb.js} +1 -1
  46. package/src/ui/static/assets/{ReportCard-G52Q6-2i.js → ReportCard-LOf1PXlb.js} +2 -2
  47. package/src/ui/static/assets/{ReportFullView-Bt8UFP2J.js → ReportFullView-Ce4OI8lf.js} +1 -1
  48. package/src/ui/static/assets/{ReportsPage-DMtDi73Q.js → ReportsPage-DFxCQ8cY.js} +48 -48
  49. package/src/ui/static/assets/{ResultsPage-BI9jpK2N.js → ResultsPage-DD-uj8gk.js} +115 -115
  50. package/src/ui/static/assets/{RunState-ifC4zi6M.js → RunState-DDwFB4tA.js} +1 -1
  51. package/src/ui/static/assets/{RunTargets-C7vpCbck.js → RunTargets-CkIpY3v3.js} +1 -1
  52. package/src/ui/static/assets/ScriptMappingPage-DQQoR6sR.js +1 -0
  53. package/src/ui/static/assets/{SearchableDevicePicker-BYxYJNWl.js → SearchableDevicePicker-CenIxD7b.js} +1 -1
  54. package/src/ui/static/assets/{SettingsPage-DSISg7r7.js → SettingsPage-DAV_0y0m.js} +83 -83
  55. package/src/ui/static/assets/{SharedReportView-BOqKGJmR.js → SharedReportView-CqSLFKT1.js} +1 -1
  56. package/src/ui/static/assets/{SourcesPage-CgqtYGBi.js → SourcesPage-BvqC9oKw.js} +14 -14
  57. package/src/ui/static/assets/TestExplorerPage-Bdnll77k.js +7 -0
  58. package/src/ui/static/assets/{TestManagementPage-wqYTKP7W.js → TestManagementPage-CCNE688A.js} +10 -10
  59. package/src/ui/static/assets/{TestPlansPage-DOKX9p6z.js → TestPlansPage-T6D25i6-.js} +5 -5
  60. package/src/ui/static/assets/{TestverCreditsDetail-cSW0SpNx.js → TestverCreditsDetail-BKpt4oLW.js} +1 -1
  61. package/src/ui/static/assets/{TestverCreditsRing-DpMzl3h7.js → TestverCreditsRing-CoDk5eAS.js} +1 -1
  62. package/src/ui/static/assets/TestverMcpPage-Dte0qSXp.js +34 -0
  63. package/src/ui/static/assets/{UncommittedDiffViewer-BxS0zi-p.js → UncommittedDiffViewer-BNroxCoo.js} +2 -2
  64. package/src/ui/static/assets/{UserManagementPage-B5d0uDU_.js → UserManagementPage-BU4MuDJZ.js} +10 -10
  65. package/src/ui/static/assets/{WorkflowsPage-Bk0DFnFS.js → WorkflowsPage-BP5k7AqE.js} +83 -83
  66. package/src/ui/static/assets/clipboard-BIEd7Ccc.js +1 -0
  67. package/src/ui/static/assets/{hiddenLlmProviders-CdhhNa5G.js → hiddenLlmProviders-BPORgy-e.js} +1 -1
  68. package/src/ui/static/assets/index-BlA8ntjb.js +47 -0
  69. package/src/ui/static/assets/index-Co4_SlGD.css +1 -0
  70. package/src/ui/static/assets/{index-DpQhqcHv.js → index-DLmlY2Ol.js} +1 -1
  71. package/src/ui/static/assets/{reportMeta-AKcU_qwq.js → reportMeta-B9ZRW6ts.js} +1 -1
  72. package/src/ui/static/assets/runSelected-BoPm1sz-.js +1 -0
  73. package/src/ui/static/assets/{useChartTheme-BFz2QcND.js → useChartTheme-CTIe6M63.js} +1 -1
  74. package/src/ui/static/assets/{useDebouncedValue-BsHptIvX.js → useDebouncedValue-C9odz7b2.js} +1 -1
  75. package/src/ui/static/assets/{useFeatureFlags-DNkIctil.js → useFeatureFlags-B4Otsv-N.js} +1 -1
  76. package/src/ui/static/assets/{useJiraConnector-D5ysBBvz.js → useJiraConnector--JZhbYrT.js} +1 -1
  77. package/src/ui/static/assets/{useOwnership-U0AfKBRo.js → useOwnership-BhPOiYzy.js} +1 -1
  78. package/src/ui/static/assets/useSuites-GN_K2mHc.js +1 -0
  79. package/src/ui/static/assets/{useTabParam-ChbOedP1.js → useTabParam-CyYAP90W.js} +1 -1
  80. package/src/ui/static/assets/{useTestExplorer-DT8frjCK.js → useTestExplorer-BGhkGHKy.js} +1 -1
  81. package/src/ui/static/assets/{useTestLifecycle-OcwQaB1s.js → useTestLifecycle-DX5ES6x8.js} +1 -1
  82. package/src/ui/static/assets/{useTestManagement-Xm4Bcx3u.js → useTestManagement-ommXjx0q.js} +2 -2
  83. package/src/ui/static/assets/useTestResults-DWjvm8gm.js +1 -0
  84. package/src/ui/static/assets/{vendor-charts-DWFQlmCz.js → vendor-charts-By5uZ93z.js} +1 -1
  85. package/src/ui/static/assets/{vendor-flow-YGpC9U9I.js → vendor-flow-B61ZV-pm.js} +1 -1
  86. package/src/ui/static/assets/{vendor-icons-BKPiFyYV.js → vendor-icons-Cm92aSc5.js} +1426 -1421
  87. package/src/ui/static/assets/vendor-query-DkZSMtfn.js +1 -0
  88. package/src/ui/static/assets/{vendor-quill-W-RoQfb6.js → vendor-quill-xJF2Jvjc.js} +1 -1
  89. package/src/ui/static/assets/{vendor-react-CTbHBddL.js → vendor-react-DOVfxdUy.js} +1 -1
  90. package/src/ui/static/index.html +479 -479
  91. package/src/ui/static/assets/AIPanel-B_R-CbrF.js +0 -32
  92. package/src/ui/static/assets/AIRecordPanel-BRQWIU5h.js +0 -40
  93. package/src/ui/static/assets/AIStreamUI-C3D989_6.js +0 -9
  94. package/src/ui/static/assets/APITestingPage-Cmwkiiys.js +0 -19
  95. package/src/ui/static/assets/AboutPage-CjEqKB-q.js +0 -1
  96. package/src/ui/static/assets/AdvancedPage-4kAcpE8Y.js +0 -3
  97. package/src/ui/static/assets/AuditLogPage-BQjOzQje.js +0 -1
  98. package/src/ui/static/assets/ChangesSummary-CY_Vb27i.js +0 -2
  99. package/src/ui/static/assets/DiffViewer-BIU09a_i.js +0 -2
  100. package/src/ui/static/assets/MobileRunPicker-0h-N2c6d.js +0 -1
  101. package/src/ui/static/assets/MobileRunTarget-Bo_xekig.js +0 -6
  102. package/src/ui/static/assets/PipelinesPanel-PmmPu8pj.js +0 -1
  103. package/src/ui/static/assets/ScriptMappingPage-7vHuvhQw.js +0 -1
  104. package/src/ui/static/assets/TestExplorerPage-gYLhCD4d.js +0 -7
  105. package/src/ui/static/assets/index-BYVxKLrT.js +0 -47
  106. package/src/ui/static/assets/index-C2KJt7SI.css +0 -1
  107. package/src/ui/static/assets/runSelected-WlgnZcSF.js +0 -1
  108. package/src/ui/static/assets/useSuites-DyfN9HVv.js +0 -1
  109. package/src/ui/static/assets/useTestResults-D5EwGIX9.js +0 -1
  110. package/src/ui/static/assets/vendor-query-BrzmPFT3.js +0 -1
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-BYVxKLrT.js","assets/vendor-react-CTbHBddL.js","assets/vendor-query-BrzmPFT3.js","assets/vendor-icons-BKPiFyYV.js","assets/index-C2KJt7SI.css"])))=>i.map(i=>d[i]);
2
- import{r as s,j as e,n as yt,b as wt,u as Lt}from"./vendor-react-CTbHBddL.js";import{bv as Ft,aA as vt,b6 as ct,bw as Wt,bx as Ot,aN as Bt,a$ as Ut,aB as Ht,by as Xt,bz as Vt,bA as Yt,aV as Gt,aT as Kt,b4 as dt,bB as qt,bC as Jt,V as Qt,T as Zt,bD as es,a4 as ts}from"./index-BYVxKLrT.js";import{u as ss}from"./useTabParam-ChbOedP1.js";import{N as ut,a as st,A as rs,b7 as ns,bO as as,X as je,e as is,I as os,o as ls,ap as jt,K as kt,a2 as rt,ba as Fe,aa as ot,bP as cs,q as ds,bQ as us,bR as xs,aj as hs,al as fs,bS as ps,b9 as We,y as Be,J as lt,bT as ms,bU as gs,bV as bs,bW as ys,W as ws,w as vs,bX as js,bY as ks,aT as Ns,aU as Cs,a0 as ve,b8 as Ss,a6 as Nt,l as Rs,r as nt,aI as xt,bZ as Es,ac as Ts,ag as Ct,t as Ue,a9 as Ms,bt as $s,aJ as Ps,bw as As,S as zs,c as _s,f as Is,_ as Ds,aC as St,bx as Ls,Q as Fs,C as Ws,by as Os,b_ as Bs,b$ as Rt,ab as Et,c0 as Tt,v as Us,F as Hs,g as Xs,c1 as Vs,c2 as Mt,G as $t}from"./vendor-icons-BKPiFyYV.js";import{f as Ys}from"./formatDate-T65-Y6Mi.js";import{C as Gs}from"./ConfirmDialog-t7mpeeSN.js";import{a as Pt}from"./DiffViewer-BIU09a_i.js";import{M as Ks}from"./MediaModal-C5n6sHYi.js";function qs({subscribe:t,send:i,isStreaming:a}){const[r,x]=ss("nctab",["network","console"],"console"),[n,f]=s.useState([]),[c,l]=s.useState([]),[d,p]=s.useState(!1),[E,m]=s.useState(!1),[v,T]=s.useState(""),[R,_]=s.useState("all"),[h,w]=s.useState(!0),u=s.useRef(null),b=s.useRef(null),y=s.useCallback(k=>{if(k.type==="screencast-network-request"){const L=k.entry;f(M=>{const C=M.findIndex(W=>W.id===L.id);if(C>=0){const W=[...M];return W[C]={...W[C],...L},W}const H=[...M,L];return H.length>500?H.slice(-500):H});return}if(k.type==="screencast-network-response"){const L=k.entry;f(M=>{const C=M.findIndex(W=>W.id===L.id);if(C>=0){const W=[...M];return W[C]={...W[C],...L},W}const H=[...M,L];return H.length>500?H.slice(-500):H});return}if(k.type==="screencast-console-message"){const L=k.entry;l(M=>{const C=[...M,L];return C.length>500?C.slice(-500):C});return}},[]);s.useEffect(()=>t(y),[t,y]),s.useEffect(()=>{if(!h)return;const k=r==="network"?u:b;k.current&&(k.current.scrollTop=k.current.scrollHeight)},[n,c,r,h]);const A=()=>{d?(i({type:"screencast-network-disable"}),p(!1)):(i({type:"screencast-network-enable"}),p(!0))},z=()=>{E?(i({type:"screencast-console-disable"}),m(!1)):(i({type:"screencast-console-enable"}),m(!0))};s.useEffect(()=>{a&&!d&&(i({type:"screencast-network-enable"}),p(!0)),a&&!E&&(i({type:"screencast-console-enable"}),m(!0))},[a]);const X=v?n.filter(k=>k.url.toLowerCase().includes(v.toLowerCase())||k.method.toLowerCase().includes(v.toLowerCase())):n,F=R==="all"?c:c.filter(k=>k.level===R);return e.jsxs("div",{className:"flex flex-col h-full bg-surface-0 border-t border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-0.5 px-2 py-1 border-b border-white/5 bg-surface-1 flex-shrink-0",children:[e.jsxs("button",{onClick:()=>x("network"),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-[11px] font-medium transition-colors ${r==="network"?"bg-blue-500/15 text-blue-300":"text-gray-500 hover:text-gray-400"}`,children:[e.jsx(ut,{size:11}),"Network",n.length>0&&e.jsx("span",{className:"text-[9px] px-1 rounded-full bg-blue-500/20 text-blue-400",children:n.length})]}),e.jsxs("button",{onClick:()=>x("console"),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-[11px] font-medium transition-colors ${r==="console"?"bg-purple-500/15 text-purple-300":"text-gray-500 hover:text-gray-400"}`,children:[e.jsx(st,{size:11}),"Console",c.filter(k=>k.level==="error").length>0&&e.jsx("span",{className:"text-[9px] px-1 rounded-full bg-red-500/20 text-red-400",children:c.filter(k=>k.level==="error").length})]}),e.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[r==="network"&&e.jsx("button",{onClick:A,className:`text-[10px] px-1.5 py-0.5 rounded transition-colors ${d?"text-emerald-400 bg-emerald-500/10":"text-gray-500 hover:text-gray-400"}`,children:d?"ON":"OFF"}),r==="console"&&e.jsx("button",{onClick:z,className:`text-[10px] px-1.5 py-0.5 rounded transition-colors ${E?"text-emerald-400 bg-emerald-500/10":"text-gray-500 hover:text-gray-400"}`,children:E?"ON":"OFF"}),e.jsx("button",{onClick:()=>w(!h),className:`p-1 rounded transition-colors ${h?"text-brand-400":"text-gray-600"}`,title:h?"Auto-scroll ON":"Auto-scroll OFF",children:e.jsx(rs,{size:10})}),e.jsx("button",{onClick:()=>{r==="network"?f([]):l([])},className:"p-1 rounded text-gray-600 hover:text-gray-400 transition-colors",title:"Clear",children:e.jsx(ns,{size:10})})]})]}),r==="network"&&e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 border-b border-white/5 bg-surface-1/50",children:[e.jsx(as,{size:10,className:"text-gray-600"}),e.jsx("input",{type:"text",value:v,onChange:k=>T(k.target.value),placeholder:"Filter by URL or method...",className:"flex-1 bg-transparent text-[11px] text-gray-300 placeholder-gray-600 outline-none"}),v&&e.jsx("button",{onClick:()=>T(""),className:"text-gray-500 hover:text-gray-400",children:e.jsx(je,{size:10})})]}),r==="console"&&e.jsxs("div",{className:"flex items-center gap-1 px-2 py-1 border-b border-white/5 bg-surface-1/50",children:[e.jsx(Ee,{label:"All",active:R==="all",onClick:()=>_("all")}),e.jsx(Ee,{label:"Errors",active:R==="error",onClick:()=>_("error"),color:"red"}),e.jsx(Ee,{label:"Warnings",active:R==="warn",onClick:()=>_("warn"),color:"amber"}),e.jsx(Ee,{label:"Info",active:R==="info",onClick:()=>_("info"),color:"blue"}),e.jsx(Ee,{label:"Log",active:R==="log",onClick:()=>_("log")})]}),e.jsx("div",{className:"flex-1 overflow-hidden",children:r==="network"?e.jsx("div",{ref:u,className:"h-full overflow-y-auto",children:X.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-gray-600 gap-2",children:[e.jsx(ut,{size:20}),e.jsx("span",{className:"text-[11px]",children:d?"Waiting for requests...":"Enable network monitoring to capture requests"})]}):e.jsxs("table",{className:"w-full text-[11px]",children:[e.jsx("thead",{className:"sticky top-0 bg-surface-1 z-10",children:e.jsxs("tr",{className:"text-gray-500 text-left",children:[e.jsx("th",{className:"px-2 py-1 font-medium w-14",children:"Method"}),e.jsx("th",{className:"px-2 py-1 font-medium w-14",children:"Status"}),e.jsx("th",{className:"px-2 py-1 font-medium",children:"URL"}),e.jsx("th",{className:"px-2 py-1 font-medium w-16",children:"Type"}),e.jsx("th",{className:"px-2 py-1 font-medium w-16 text-right",children:"Time"})]})}),e.jsx("tbody",{children:X.map(k=>e.jsx(Js,{entry:k},k.id+(k.status||"")))})]})}):e.jsx("div",{ref:b,className:"h-full overflow-y-auto font-mono",children:F.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-gray-600 gap-2",children:[e.jsx(st,{size:20}),e.jsx("span",{className:"text-[11px] font-sans",children:E?"Waiting for console output...":"Enable console monitoring to capture logs"})]}):F.map((k,L)=>e.jsx(Qs,{entry:k},`${k.timestamp}-${L}`))})})]})}function Js({entry:t}){const i=t.failed||t.status&&t.status>=400?"text-red-400":t.status&&t.status>=300?"text-amber-400":t.status?"text-emerald-400":"text-gray-500",a=t.method==="POST"?"text-amber-400":t.method==="PUT"?"text-blue-400":t.method==="DELETE"?"text-red-400":t.method==="PATCH"?"text-purple-400":"text-gray-400";let r=t.url;try{const n=new URL(t.url);r=n.pathname+n.search}catch{}const x=t.mimeType?t.mimeType.replace("application/","").replace("text/","").split(";")[0]:"";return e.jsxs("tr",{className:"border-b border-white/[0.02] hover:bg-white/[0.02] transition-colors",children:[e.jsx("td",{className:`px-2 py-0.5 font-medium ${a}`,children:t.method}),e.jsx("td",{className:`px-2 py-0.5 ${i}`,children:t.failed?"ERR":t.status||"..."}),e.jsx("td",{className:"px-2 py-0.5 text-gray-300 truncate max-w-0",title:t.url,children:r}),e.jsx("td",{className:"px-2 py-0.5 text-gray-600 truncate",children:x}),e.jsx("td",{className:"px-2 py-0.5 text-gray-500 text-right",children:t.duration!=null?`${t.duration}ms`:"..."})]})}function Qs({entry:t}){const i={error:{bg:"bg-red-500/5",border:"border-red-500/20",text:"text-red-300",icon:e.jsx(jt,{size:10})},warn:{bg:"bg-amber-500/5",border:"border-amber-500/20",text:"text-amber-300",icon:e.jsx(ls,{size:10})},info:{bg:"bg-blue-500/5",border:"border-blue-500/10",text:"text-blue-300",icon:e.jsx(os,{size:10})},debug:{bg:"bg-gray-500/5",border:"border-white/5",text:"text-gray-400",icon:e.jsx(is,{size:10})},log:{bg:"",border:"border-white/[0.02]",text:"text-gray-300",icon:null}},a=i[t.level]||i.log,r=new Date(t.timestamp).toLocaleTimeString("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"});return e.jsxs("div",{className:`flex items-start gap-2 px-2 py-0.5 border-b ${a.border} ${a.bg} text-[11px]`,children:[e.jsx("span",{className:"text-gray-600 flex-shrink-0 tabular-nums",children:r}),a.icon&&e.jsx("span",{className:a.text+" flex-shrink-0 mt-0.5",children:a.icon}),e.jsx("span",{className:`${a.text} break-all flex-1 whitespace-pre-wrap`,children:t.text}),t.source&&e.jsxs("span",{className:"text-gray-700 flex-shrink-0 truncate max-w-[120px]",title:t.source,children:[t.source.split("/").pop(),t.lineNumber!=null?`:${t.lineNumber}`:""]})]})}function Ee({label:t,active:i,onClick:a,color:r}){const n=r?{red:i?"bg-red-500/20 text-red-300":"text-gray-500",amber:i?"bg-amber-500/20 text-amber-300":"text-gray-500",blue:i?"bg-blue-500/20 text-blue-300":"text-gray-500"}[r]||"":i?"bg-white/10 text-gray-300":"text-gray-500";return e.jsx("button",{onClick:a,className:`px-1.5 py-0.5 rounded text-[10px] font-medium transition-colors hover:text-gray-300 ${n}`,children:t})}const Zs=800,er=2e3,ht=3e3;function tr({subscribe:t,canvasWidth:i,canvasHeight:a,viewportWidth:r,viewportHeight:x,enabled:n}){const f=s.useRef(null),c=s.useRef([]),[l,d]=s.useState(null),[p,E]=s.useState(null),m=s.useRef(0),v=s.useRef(0),T=s.useCallback((h,w)=>{const u=i/r,b=a/x;return{x:h*u,y:w*b}},[i,a,r,x]),R=s.useCallback(h=>{if(n&&h.type==="ai-cursor-action"){const w={id:`action-${Date.now()}-${Math.random()}`,type:h.action||"action",toolName:h.toolName,selector:h.selector,text:h.text,url:h.url,x:h.x,y:h.y,timestamp:Date.now()};if(d(w),setTimeout(()=>{d(u=>(u==null?void 0:u.id)===w.id?null:u)},er),w.type==="click"&&w.x!==void 0&&w.y!==void 0){const u=T(w.x,w.y);c.current.push({id:w.id,x:u.x,y:u.y,startTime:Date.now(),duration:Zs}),E({x:w.x,y:w.y}),m.current=Date.now()}["hover","type","select"].includes(w.type)&&w.x!==void 0&&w.y!==void 0&&(E({x:w.x,y:w.y}),m.current=Date.now())}},[n,T]);if(s.useEffect(()=>t(R),[t,R]),s.useEffect(()=>{if(!n)return;const h=()=>{const w=f.current;if(!w){v.current=requestAnimationFrame(h);return}(w.width!==i||w.height!==a)&&(w.width=i,w.height=a);const u=w.getContext("2d");if(!u){v.current=requestAnimationFrame(h);return}u.clearRect(0,0,w.width,w.height);const b=Date.now();c.current=c.current.filter(y=>b-y.startTime<y.duration);for(const y of c.current){const z=(b-y.startTime)/y.duration,F=30*z,k=1-z;u.beginPath(),u.arc(y.x,y.y,F,0,Math.PI*2),u.strokeStyle=`rgba(168, 85, 247, ${k*.8})`,u.lineWidth=2.5,u.stroke(),u.beginPath(),u.arc(y.x,y.y,F*.4,0,Math.PI*2),u.fillStyle=`rgba(168, 85, 247, ${k*.3})`,u.fill(),z<.3&&(u.beginPath(),u.arc(y.x,y.y,3,0,Math.PI*2),u.fillStyle=`rgba(168, 85, 247, ${(1-z/.3)*.9})`,u.fill())}if(p){const y=b-m.current;if(y<ht){const A=Math.max(0,1-y/ht),z=T(p.x,p.y),X=12;u.strokeStyle=`rgba(168, 85, 247, ${A*.9})`,u.lineWidth=1.5,u.beginPath(),u.moveTo(z.x-X,z.y),u.lineTo(z.x+X,z.y),u.stroke(),u.beginPath(),u.moveTo(z.x,z.y-X),u.lineTo(z.x,z.y+X),u.stroke();const F=b%1e3/1e3,k=6+Math.sin(F*Math.PI*2)*2;u.beginPath(),u.arc(z.x,z.y,k,0,Math.PI*2),u.strokeStyle=`rgba(168, 85, 247, ${A*.5})`,u.lineWidth=1,u.stroke()}}v.current=requestAnimationFrame(h)};return v.current=requestAnimationFrame(h),()=>{v.current&&cancelAnimationFrame(v.current)}},[n,i,a,p,T]),!n)return null;const _=h=>{switch(h.type){case"click":return`Click ${h.selector||""}`.trim();case"type":return`Type "${(h.text||"").slice(0,30)}${(h.text||"").length>30?"...":""}"`;case"hover":return`Hover ${h.selector||""}`.trim();case"navigate":return`Navigate → ${(h.url||"").slice(0,40)}`;case"select":return`Select ${h.selector||""}`.trim();case"key":return`Press ${h.text||"key"}`;case"screenshot":return"Taking screenshot";case"scroll":return"Scrolling";case"wait":return`Waiting for ${h.selector||"element"}`;case"launch":return"Launching browser";case"close":return"Closing browser";default:return h.toolName}};return e.jsxs(e.Fragment,{children:[e.jsx("canvas",{ref:f,className:"absolute inset-0 pointer-events-none z-10",style:{width:"100%",height:"100%"}}),l&&e.jsx("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 z-20 pointer-events-none animate-in fade-in slide-in-from-top-1 duration-200",children:e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded-full bg-gray-900/95 border border-purple-400/40 shadow-lg shadow-black/40 backdrop-blur-md",children:[e.jsx(sr,{type:l.type}),e.jsx("span",{className:"text-[11px] font-semibold text-white whitespace-nowrap max-w-[280px] truncate drop-shadow-sm",children:_(l)})]})})]})}function sr({type:t}){const a="text-purple-300";switch(t){case"click":return e.jsxs("svg",{width:12,height:12,viewBox:"0 0 16 16",className:a,fill:"currentColor",children:[e.jsx("circle",{cx:"8",cy:"8",r:"3"}),e.jsx("circle",{cx:"8",cy:"8",r:"7",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})]});case"type":return e.jsxs("svg",{width:12,height:12,viewBox:"0 0 16 16",className:a,fill:"currentColor",children:[e.jsx("rect",{x:"2",y:"4",width:"12",height:"8",rx:"1",fill:"none",stroke:"currentColor",strokeWidth:"1.5"}),e.jsx("line",{x1:"5",y1:"7",x2:"11",y2:"7",stroke:"currentColor",strokeWidth:"1"}),e.jsx("line",{x1:"5",y1:"9",x2:"9",y2:"9",stroke:"currentColor",strokeWidth:"1"})]});case"navigate":return e.jsx("svg",{width:12,height:12,viewBox:"0 0 16 16",className:a,fill:"currentColor",children:e.jsx("path",{d:"M3 8h10M10 5l3 3-3 3",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})});case"hover":return e.jsx("svg",{width:12,height:12,viewBox:"0 0 16 16",className:a,fill:"currentColor",children:e.jsx("path",{d:"M4 2l8 6-4 1-2 4z",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})});default:return e.jsx("svg",{width:12,height:12,viewBox:"0 0 16 16",className:a,fill:"currentColor",children:e.jsx("circle",{cx:"8",cy:"8",r:"2"})})}}const rr=[{label:"Mobile",icon:lt,width:375,height:812},{label:"Tablet",icon:ms,width:768,height:1024},{label:"Desktop",icon:We,width:1280,height:720},{label:"Full HD",icon:We,width:1920,height:1080}],at="testver-live-view-focus";function Fr(){window.dispatchEvent(new Event(at))}function At({browserStatus:t,sessionEpoch:i=0,subscribe:a,send:r,isPiP:x,onTogglePiP:n,onCloseBrowser:f,userControlOnly:c=!1}){var B,K;const[l,d]=s.useState(!1),[p,E]=s.useState(!1),[m,v]=s.useState({width:1280,height:720}),[T,R]=s.useState(""),[_,h]=s.useState(""),[w,u]=s.useState(0),[b,y]=s.useState(c?"user":"ai"),A=s.useRef(b);A.current=b;const[z,X]=s.useState(!1),[F,k]=s.useState(null),[L,M]=s.useState("default"),[C,H]=s.useState(!1),[W,Q]=s.useState(!1),[O,ke]=s.useState(200),[U,He]=s.useState(!c),[Y,Ne]=s.useState(!1),[J,Ce]=s.useState(!1),G=s.useRef(null),ce=s.useRef(null),Z=s.useRef(null),he=s.useRef(null),ee=s.useRef(0),pe=s.useRef(null),de=s.useRef(null);s.useEffect(()=>{const o=()=>{var $;A.current==="user"&&(($=de.current)==null||$.focus({preventScroll:!0}))};return window.addEventListener(at,o),()=>window.removeEventListener(at,o)},[]);const ne=s.useRef(0);s.useEffect(()=>{he.current||(he.current=new Image)},[]),s.useEffect(()=>(pe.current=setInterval(()=>{u(ee.current),ee.current=0},1e3),()=>{pe.current&&clearInterval(pe.current)}),[]);const Se=s.useRef(0),me=s.useRef(i),Me=s.useRef(t.active);Me.current=t.active;const $e=s.useRef(l);$e.current=l;const Pe=s.useCallback(()=>{var S,D;Se.current++;const o=G.current;o&&((S=o.getContext("2d"))==null||S.clearRect(0,0,o.width,o.height));const $=ce.current;$&&((D=$.getContext("2d"))==null||D.clearRect(0,0,$.width,$.height)),k(null)},[]);s.useEffect(()=>{const o=i!==me.current;me.current=i,t.active?o?(Pe(),fe()):!l&&!p&&fe():l&&(ae(),Pe())},[t.active,i]);const fe=s.useCallback(async()=>{E(!0);try{const o=await Ft();v({width:o.width,height:o.height}),r({type:"screencast-start",options:{quality:50}}),d(!0)}catch{r({type:"screencast-start",options:{quality:50}}),d(!0)}E(!1)},[r]),ae=s.useCallback(()=>{r({type:"screencast-stop"}),d(!1),u(0)},[r]),se=s.useRef(null),Ae=s.useCallback(()=>{se.current&&clearTimeout(se.current),se.current=setTimeout(()=>{se.current=null,Me.current&&!$e.current&&fe()},600)},[fe]);s.useEffect(()=>()=>{se.current&&clearTimeout(se.current)},[]);const ze=s.useCallback(o=>{if(o.type==="screencast-frame"){const $=o.data,S=o.metadata;S&&v(V=>V.width!==S.width||V.height!==S.height?{width:S.width,height:S.height}:V);const D=he.current;if(!D)return;const re=Se.current;D.onload=()=>{var oe;if(re!==Se.current)return;const V=G.current;V&&((V.width!==((S==null?void 0:S.width)||m.width)||V.height!==((S==null?void 0:S.height)||m.height))&&(V.width=(S==null?void 0:S.width)||m.width,V.height=(S==null?void 0:S.height)||m.height),Z.current||(Z.current=V.getContext("2d")),(oe=Z.current)==null||oe.drawImage(D,0,0,V.width,V.height),ee.current++)},D.src=`data:image/jpeg;base64,${$}`;return}if(o.type==="screencast-viewport"){v({width:o.width,height:o.height});return}if(o.type==="screencast-stopped"){d(!1),u(0),Ae();return}if(o.type==="screencast-error"){d(!1),E(!1),Ae();return}if(o.type==="screencast-highlight"){k(o.highlight);return}if(o.type==="browser-tab-switched"){o.url&&R(o.url),h("");return}if(o.type==="screencast-url-changed"){o.url&&R(o.url),o.title&&h(o.title);return}if(o.type==="screencast-cursor"){M(o.cursor||"default");return}if(o.type==="ai-orchestrator-paused"){Ne(!0);return}if(o.type==="ai-orchestrator-resumed"){Ne(!1);return}if(o.type==="ai-fix-tool"){Ce(!0);return}if(o.type==="ai-fix-done"||o.type==="ai-fix-error"){Ce(!1),Ne(!1);return}},[m]);s.useEffect(()=>a(ze),[a,ze]),s.useEffect(()=>{t.url&&R(t.url)},[t.url]),s.useEffect(()=>{h("")},[i,t.active]),s.useEffect(()=>{const o=ce.current;if(!o)return;const $=G.current;if(!$)return;(o.width!==$.width||o.height!==$.height)&&(o.width=$.width,o.height=$.height);const S=o.getContext("2d");if(S&&(S.clearRect(0,0,o.width,o.height),F&&z)){const D=F;S.fillStyle="rgba(59, 130, 246, 0.1)",S.fillRect(D.x,D.y,D.width,D.height),S.strokeStyle="rgba(59, 130, 246, 0.7)",S.lineWidth=2,S.setLineDash([]),S.strokeRect(D.x,D.y,D.width,D.height);const re=`${D.tagName}${D.id?"#"+D.id:""}${D.className?"."+D.className.split(" ")[0]:""}`;S.font="11px monospace";const V=S.measureText(re).width,oe=D.x,be=D.y>18?D.y-4:D.y+D.height+14;S.fillStyle="rgba(30, 41, 59, 0.9)",S.fillRect(oe,be-12,V+8,16),S.fillStyle="#93c5fd",S.fillText(re,oe+4,be)}},[F,z]);const q=s.useCallback((o,$)=>{const S=G.current;if(!S)return{x:0,y:0};const D=S.getBoundingClientRect(),re=o-D.left,V=$-D.top,oe=m.width/D.width,be=m.height/D.height;return{x:Math.round(re*oe),y:Math.round(V*be)}},[m]),te=o=>{let $=0;return o.altKey&&($|=1),o.ctrlKey&&($|=2),o.metaKey&&($|=4),o.shiftKey&&($|=8),$},Re=o=>o.button===2?"right":o.button===1?"middle":"left",Xe=s.useCallback(o=>{var D;if(b!=="user")return;o.preventDefault(),(D=de.current)==null||D.focus();const{x:$,y:S}=q(o.clientX,o.clientY);r({type:"screencast-mouse",mouseType:"mousePressed",x:$,y:S,button:Re(o),clickCount:o.detail||1,modifiers:te(o)})},[b,q,r]),Ve=s.useCallback(o=>{if(b!=="user")return;o.preventDefault();const{x:$,y:S}=q(o.clientX,o.clientY);r({type:"screencast-mouse",mouseType:"mouseReleased",x:$,y:S,button:Re(o),clickCount:o.detail||1,modifiers:te(o)})},[b,q,r]),Ye=s.useCallback(o=>{if(b!=="user")return;const $=Date.now();if($-ne.current<50)return;ne.current=$;const{x:S,y:D}=q(o.clientX,o.clientY);z&&r({type:"screencast-hover",x:S,y:D}),r({type:"screencast-mouse",mouseType:"mouseMoved",x:S,y:D,button:"none",modifiers:te(o)})},[b,q,r,z]),ie=s.useCallback(()=>{z&&k(null)},[z]),ge=s.useCallback(o=>{o.preventDefault()},[]),Ge=s.useCallback(o=>{if(b!=="user")return;o.preventDefault();const{x:$,y:S}=q(o.clientX,o.clientY);r({type:"screencast-mouse",mouseType:"mousePressed",x:$,y:S,button:"left",clickCount:2,modifiers:te(o)}),r({type:"screencast-mouse",mouseType:"mouseReleased",x:$,y:S,button:"left",clickCount:2,modifiers:te(o)})},[b,q,r]),Ke=s.useCallback(o=>{b==="user"&&o.target.tagName!=="INPUT"&&(o.preventDefault(),r({type:"screencast-key",keyType:"keyDown",key:o.key,code:o.code,text:o.key.length===1?o.key:void 0,modifiers:te(o)}))},[b,r]),qe=s.useCallback(o=>{b==="user"&&o.target.tagName!=="INPUT"&&(o.preventDefault(),r({type:"screencast-key",keyType:"keyUp",key:o.key,code:o.code,modifiers:te(o)}))},[b,r]),Je=s.useCallback(o=>{if(b!=="user")return;o.preventDefault();const{x:$,y:S}=q(o.clientX,o.clientY);r({type:"screencast-scroll",x:$,y:S,deltaX:o.deltaX,deltaY:o.deltaY})},[b,q,r]),_e=o=>{if(o.preventDefault(),!T.trim())return;let $=T.trim();$.match(/^https?:\/\//)||($=`https://${$}`),r({type:"screencast-navigate",url:$})},g=o=>{r({type:"screencast-tab",index:o})},N=(o,$)=>{r({type:"screencast-resize-viewport",width:o,height:$}),H(!1)},j=s.useRef(!1);s.useEffect(()=>{const o=S=>{if(!j.current||!de.current)return;const re=de.current.getBoundingClientRect().bottom-S.clientY;ke(Math.min(400,Math.max(100,re)))},$=()=>{j.current=!1,document.body.style.cursor="",document.body.style.userSelect=""};return window.addEventListener("mousemove",o),window.addEventListener("mouseup",$),()=>{window.removeEventListener("mousemove",o),window.removeEventListener("mouseup",$)}},[]);const P=t.tabs||[],I=m.width/m.height;return e.jsxs("div",{ref:de,className:"flex flex-col h-full bg-surface-0 outline-none",tabIndex:0,onKeyDown:Ke,onKeyUp:qe,children:[e.jsxs("div",{className:"flex items-center gap-0.5 px-2 py-1 border-b border-white/5 bg-surface-1 flex-shrink-0 overflow-x-auto",children:[P.map(o=>e.jsxs("button",{onClick:()=>g(o.index),className:`flex items-center gap-1.5 px-2.5 py-1 rounded-t-lg text-[11px] max-w-[150px] truncate flex-shrink-0 transition-colors ${o.active?"bg-surface-0 text-gray-200 border-t border-x border-white/10":"text-gray-500 hover:text-gray-300 hover:bg-white/5"}`,title:o.url,children:[e.jsx(kt,{size:10,className:"flex-shrink-0"}),e.jsx("span",{className:"truncate",children:o.active&&_||o.title||`Tab ${o.index+1}`})]},o.index)),P.length===0&&e.jsx("span",{className:"text-[11px] text-gray-600 px-2",children:"No tabs"}),e.jsxs("div",{className:"ml-auto flex items-center gap-1 flex-shrink-0",children:[J&&e.jsx("button",{onClick:()=>{r(Y?{type:"screencast-resume"}:{type:"screencast-pause"})},className:`flex items-center gap-1 px-2.5 py-1 rounded-md text-[10px] font-semibold transition-colors ${Y?"bg-emerald-600 text-white border border-emerald-400/50 hover:bg-emerald-500 shadow-sm shadow-emerald-500/20":"bg-orange-600 text-white border border-orange-400/50 hover:bg-orange-500 shadow-sm shadow-orange-500/20"}`,title:Y?"Resume AI execution":"Pause AI execution",children:Y?e.jsxs(e.Fragment,{children:[e.jsx(rt,{size:10})," Resume"]}):e.jsxs(e.Fragment,{children:[e.jsx(Fe,{size:10})," Pause"]})}),!c&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>He(!U),className:`p-1 rounded transition-colors ${U?"text-purple-400 bg-purple-500/15":"text-gray-500 hover:text-gray-400 hover:bg-white/5"}`,title:U?"Disable watch mode overlay":"Enable watch mode overlay",children:e.jsx(ot,{size:11})}),e.jsx("div",{className:"w-px h-3 bg-white/10"}),e.jsxs("button",{onClick:()=>y("ai"),className:`flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${b==="ai"?"bg-purple-500/20 text-purple-300 border border-purple-500/30":"text-gray-500 hover:text-gray-400"}`,title:"AI is controlling the browser",children:[e.jsx(cs,{size:10})," AI"]}),e.jsxs("button",{onClick:()=>y("user"),className:`flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${b==="user"?"bg-brand-500/20 text-brand-300 border border-brand-500/30":"text-gray-500 hover:text-gray-400"}`,title:"You are controlling the browser",children:[e.jsx(ds,{size:10})," User"]})]}),n&&e.jsxs("button",{onClick:n,className:`flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${x?"text-brand-400 bg-brand-500/15":"text-gray-500 hover:text-gray-400"}`,title:x?"Exit Picture-in-Picture":"Picture-in-Picture",children:[e.jsx(us,{size:11})," PiP"]}),f&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-px h-3 bg-white/10"}),e.jsxs("button",{onClick:f,className:"flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-medium text-red-400/70 hover:text-red-400 hover:bg-red-500/10 transition-colors",title:"Close browser session",children:[e.jsx(xs,{size:10})," Close"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b border-white/5 bg-surface-1 flex-shrink-0",children:[e.jsx("button",{onClick:()=>r({type:"screencast-go-back"}),className:"p-1 rounded hover:bg-white/5 text-gray-500 hover:text-gray-400 transition-colors",title:"Go back",children:e.jsx(hs,{size:12})}),e.jsx("button",{onClick:()=>r({type:"screencast-go-forward"}),className:"p-1 rounded hover:bg-white/5 text-gray-500 hover:text-gray-400 transition-colors",title:"Go forward",children:e.jsx(fs,{size:12})}),e.jsx("button",{onClick:()=>r({type:"screencast-navigate",url:t.url||""}),className:"p-1 rounded hover:bg-white/5 text-gray-500 hover:text-gray-400 transition-colors",children:e.jsx(ps,{size:12})}),e.jsx("form",{onSubmit:_e,className:"flex-1",children:e.jsx("input",{type:"text",value:T,onChange:o=>R(o.target.value),placeholder:"Enter URL...",className:"w-full px-2.5 py-1 rounded-lg bg-surface-2 border border-white/5 text-xs text-gray-300 placeholder-gray-600 focus:outline-none focus:border-brand-500/30"})}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>H(!C),className:"flex items-center gap-1 px-1.5 py-1 rounded text-[10px] text-gray-500 hover:text-gray-400 hover:bg-white/5 transition-colors",title:"Viewport presets",children:[e.jsx(We,{size:11}),e.jsx(Be,{size:9})]}),C&&e.jsx("div",{className:"absolute right-0 top-full mt-1 bg-surface-1 border border-white/10 rounded-lg z-50 py-1 w-40",children:rr.map(o=>{const $=o.icon,S=m.width===o.width&&m.height===o.height;return e.jsxs("button",{onClick:()=>N(o.width,o.height),className:`w-full text-left px-3 py-1.5 text-[11px] flex items-center gap-2 transition-colors ${S?"text-brand-300 bg-brand-500/10":"text-gray-300 hover:bg-white/5"}`,children:[e.jsx($,{size:11,className:"flex-shrink-0"}),e.jsx("span",{children:o.label}),e.jsxs("span",{className:"ml-auto text-gray-600 text-[10px]",children:[o.width,"x",o.height]})]},o.label)})})]}),e.jsx("button",{onClick:()=>X(!z),className:`p-1 rounded transition-colors ${z?"text-blue-400 bg-blue-500/15":"text-gray-500 hover:text-gray-400 hover:bg-white/5"}`,title:z?"Disable element highlight":"Enable element highlight",children:e.jsx(gs,{size:12})}),e.jsx("button",{onClick:()=>Q(!W),className:`p-1 rounded transition-colors ${W?"text-purple-400 bg-purple-500/15":"text-gray-500 hover:text-gray-400 hover:bg-white/5"}`,title:W?"Hide DevTools":"Show DevTools",children:W?e.jsx(bs,{size:12}):e.jsx(ys,{size:12})})]}),e.jsx("div",{className:"flex-1 overflow-hidden bg-black/50 flex items-center justify-center relative min-h-0",children:l?e.jsxs("div",{className:"relative max-w-full max-h-full",style:{aspectRatio:`${I}`},children:[e.jsx("canvas",{ref:G,className:"max-w-full max-h-full block",style:{aspectRatio:`${I}`,cursor:b==="user"?L:"not-allowed"},onMouseDown:Xe,onMouseUp:Ve,onMouseMove:Ye,onMouseLeave:ie,onDoubleClick:Ge,onContextMenu:ge,onWheel:Je}),z&&e.jsx("canvas",{ref:ce,className:"absolute inset-0 pointer-events-none max-w-full max-h-full",style:{aspectRatio:`${I}`}}),U&&G.current&&e.jsx(tr,{subscribe:a,canvasWidth:((B=G.current)==null?void 0:B.width)||m.width,canvasHeight:((K=G.current)==null?void 0:K.height)||m.height,viewportWidth:m.width,viewportHeight:m.height,enabled:U}),Y&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center z-30",style:{pointerEvents:"none",background:"rgba(0, 0, 0, 0.15)"},children:e.jsxs("div",{className:"flex items-center gap-4 px-5 py-3 rounded-2xl border",style:{pointerEvents:"auto",background:"rgba(20, 20, 30, 0.7)",borderColor:"rgba(251, 191, 36, 0.5)",boxShadow:"0 4px 20px rgba(0,0,0,0.4)"},children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-orange-500/25 flex items-center justify-center flex-shrink-0",children:e.jsx(Fe,{size:20,className:"text-orange-400"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-base font-bold text-white",children:"AI Paused"}),e.jsx("div",{className:"text-xs mt-0.5",style:{color:"#ffffff"},children:"Execution paused before next action"})]}),e.jsxs("button",{onClick:()=>r({type:"screencast-resume"}),className:"ml-3 flex items-center gap-1.5 px-4 py-2 rounded-lg bg-emerald-600 text-white text-sm font-semibold hover:bg-emerald-500 transition-colors shadow-md shadow-emerald-500/20",children:[e.jsx(rt,{size:14})," Resume"]})]})})]}):p?e.jsxs("div",{className:"flex flex-col items-center gap-3 text-gray-500",children:[e.jsx("div",{className:"w-8 h-8 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),e.jsx("span",{className:"text-xs",children:"Connecting to browser..."})]}):e.jsxs("div",{className:"flex flex-col items-center gap-3 text-gray-600",children:[e.jsx(We,{size:32}),e.jsx("span",{className:"text-xs",children:"No live view available"}),e.jsx("span",{className:"text-[10px] text-gray-700",children:"Launch a browser to see it here"})]})}),W&&l&&e.jsxs(e.Fragment,{children:[e.jsx("div",{onMouseDown:o=>{o.preventDefault(),j.current=!0,document.body.style.cursor="row-resize",document.body.style.userSelect="none"},className:"h-1 flex-shrink-0 cursor-row-resize bg-white/5 hover:bg-brand-500/40 active:bg-brand-500/40 transition-colors"}),e.jsx("div",{className:"flex-shrink-0 overflow-hidden",style:{height:`${O}px`},children:e.jsx(qs,{subscribe:a,send:r,isStreaming:l})})]}),e.jsxs("div",{className:"flex items-center justify-between px-2.5 py-1 border-t border-white/5 bg-surface-1 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[l?e.jsx(ws,{size:10,className:"text-emerald-400"}):e.jsx(vs,{size:10,className:"text-gray-600"}),e.jsx("span",{className:`text-[10px] ${l?"text-emerald-400":"text-gray-600"}`,children:l?"Live":"Offline"})]}),l&&e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-[10px] text-gray-500",children:[w," fps"]}),e.jsxs("span",{className:"text-[10px] text-gray-600",children:[m.width,"x",m.height]})]}),z&&F&&e.jsxs("span",{className:"text-[10px] text-blue-400 font-mono truncate max-w-[200px]",children:["<",F.tagName,F.id?`#${F.id}`:"",">"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[Y&&e.jsx("span",{className:"text-[10px] text-orange-300 font-semibold animate-pulse",children:"AI Paused"}),J&&!Y&&e.jsx("span",{className:"text-[10px] text-purple-300 font-medium",children:"AI Working"}),b==="user"&&e.jsx("span",{className:"text-[10px] text-brand-400 font-medium",children:"Interactive Mode"}),l&&e.jsx("button",{onClick:ae,className:"text-[10px] text-gray-500 hover:text-gray-400 transition-colors",children:"Disconnect"}),!l&&t.active&&e.jsx("button",{onClick:fe,className:"text-[10px] text-brand-400 hover:text-brand-300 transition-colors",children:"Connect"})]})]})]})}function Wr({children:t,userControlOnly:i=!1}){const{subscribe:a,send:r}=yt(),[x,n]=s.useState({active:!1}),[f,c]=s.useState(50),[l,d]=s.useState(!1),[p,E]=s.useState({w:480,h:360}),[m,v]=s.useState({x:-1,y:-1}),[T,R]=s.useState(!1),[_,h]=s.useState(0),w=s.useRef(!1),u=s.useRef(null),b=s.useRef(null);s.useEffect(()=>{vt().then(()=>ct()).then(L=>{L.active&&n({active:!0,url:L.url||"",title:L.title||"",tabs:L.tabs||[]})}).catch(()=>{})},[]),s.useEffect(()=>{if(!x.active)return;const L=setInterval(()=>{Wt().catch(()=>{})},300*1e3);return()=>clearInterval(L)},[x.active]);const y=s.useCallback((L=0)=>{const M=()=>{ct().then(C=>{C.active&&n({active:!0,url:C.url||"",title:C.title||"",tabs:C.tabs||[]})}).catch(()=>{})};L>0?setTimeout(M,L):M()},[]);s.useEffect(()=>a(M=>{if(M.type==="browser-launched"){n(C=>({...C,active:!0,url:M.url||C.url||""})),h(C=>C+1),y(300);return}if(M.type==="browser-closed"){n({active:!1}),R(!0),b.current&&clearTimeout(b.current),b.current=setTimeout(()=>R(!1),4e3);return}if(M.type==="browser-tab-switched"){n(C=>({...C,active:!0,url:M.url||C.url||"",title:M.title||C.title||"",tabs:M.tabs||C.tabs||[]}));return}if(M.type==="screencast-url-changed"){n(C=>({...C,url:M.url||C.url||"",title:M.title||C.title||""}));return}if(M.type==="ai-fix-browser-action"){n(C=>({...C,active:!0,url:M.url||C.url||"",title:M.title||C.title||""}));return}if(M.type==="ai-fix-screenshot"){M.url&&n(C=>({...C,url:M.url||C.url||"",title:M.title||C.title||""}));return}if(M.type==="recorder-status"&&M.status==="recording"){n(C=>({...C,active:!0,url:M.url||C.url||""})),y(500);return}if(M.type==="recorder-status"&&M.status==="reset"){y(200);return}if(M.type==="ai-fix-tool"&&M.phase==="complete"){if(M.toolName==="browser_launch"){n(C=>({...C,active:!0})),h(C=>C+1),y(300);return}if(M.toolName==="browser_close"){n({active:!1});return}}}),[a,y]);const A=s.useCallback(L=>{L.preventDefault(),w.current=!0,document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);s.useEffect(()=>{const L=C=>{if(!w.current||!u.current)return;const H=u.current.getBoundingClientRect(),Q=100-(C.clientX-H.left)/H.width*100;c(Math.min(75,Math.max(25,Q)))},M=()=>{w.current&&(w.current=!1,document.body.style.cursor="",document.body.style.userSelect="")};return window.addEventListener("mousemove",L),window.addEventListener("mouseup",M),()=>{window.removeEventListener("mousemove",L),window.removeEventListener("mouseup",M)}},[]);const z=s.useCallback(()=>{d(L=>!L)},[]),X=s.useCallback(async()=>{try{await Ot()}catch{r({type:"screencast-close-browser"})}},[r]);s.useEffect(()=>()=>{b.current&&clearTimeout(b.current)},[]);const F=x.active,k=F&&!l;return e.jsxs("div",{ref:u,className:"flex h-full overflow-hidden relative",children:[e.jsx("div",{className:"flex-shrink-0 overflow-hidden",style:{width:k?`${100-f}%`:"100%"},children:t}),k&&e.jsx("div",{onMouseDown:A,className:"w-1 flex-shrink-0 cursor-col-resize bg-white/5 hover:bg-brand-500/40 active:bg-brand-500/40 transition-colors relative group",children:e.jsx("div",{className:"absolute inset-y-0 -left-1 -right-1"})}),k&&e.jsx("div",{className:"flex-shrink-0 overflow-hidden flex flex-col",style:{width:`${f}%`},children:e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(At,{browserStatus:x,sessionEpoch:_,subscribe:a,send:r,isPiP:!1,onTogglePiP:z,onCloseBrowser:X,userControlOnly:i})})}),F&&l&&e.jsx(nr,{browserStatus:x,sessionEpoch:_,subscribe:a,send:r,size:p,onSizeChange:E,pos:m,onPosChange:v,onTogglePiP:z,onCloseBrowser:X,containerRef:u,userControlOnly:i}),T&&e.jsx("div",{className:"absolute bottom-4 left-1/2 -translate-x-1/2 z-50 animate-fade-in",children:e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-2.5 rounded-xl bg-surface-1 border border-white/10 shadow-lg shadow-black/30",children:[e.jsx(js,{size:16,className:"text-red-400 flex-shrink-0"}),e.jsx("span",{className:"text-sm text-gray-300 font-medium",children:"Browser session closed"}),e.jsx("button",{onClick:()=>R(!1),className:"p-0.5 rounded hover:bg-white/10 text-gray-500 hover:text-gray-400 transition-colors ml-1",children:e.jsx(je,{size:12})})]})})]})}function nr({browserStatus:t,sessionEpoch:i,subscribe:a,send:r,size:x,onSizeChange:n,pos:f,onPosChange:c,onTogglePiP:l,onCloseBrowser:d,containerRef:p,userControlOnly:E=!1}){const m=s.useRef(null),v=s.useRef(!1),T=s.useRef(!1),R=s.useRef({x:0,y:0}),[_,h]=s.useState(!1),w=s.useRef(x),u=s.useCallback(()=>{if(f.x>=0&&f.y>=0)return f;const F=p.current;if(!F)return{x:20,y:20};const k=F.getBoundingClientRect();return{x:k.width-x.w-16,y:k.height-x.h-16}},[f,x,p]),b=s.useCallback(F=>{if(_)return;F.preventDefault(),v.current=!0;const k=u();R.current={x:F.clientX-k.x,y:F.clientY-k.y},document.body.style.cursor="grabbing",document.body.style.userSelect="none"},[u,_]),y=s.useCallback(F=>{F.preventDefault(),F.stopPropagation(),T.current=!0,document.body.style.cursor="nwse-resize",document.body.style.userSelect="none"},[]);s.useEffect(()=>{const F=L=>{if(v.current){const M=p.current,C=L.clientX-R.current.x,H=L.clientY-R.current.y;if(M){const W=M.getBoundingClientRect(),Q=60,O=Math.min(Math.max(-x.w+Q,C),W.width-Q),ke=Math.min(Math.max(0,H),W.height-Q);c({x:O,y:ke})}else c({x:Math.max(0,C),y:Math.max(0,H)})}if(T.current&&m.current){const M=m.current.getBoundingClientRect(),C=p.current,H=C?C.getBoundingClientRect().width-16:1200,W=C?C.getBoundingClientRect().height-16:800,Q=Math.min(H,Math.max(320,L.clientX-M.left)),O=Math.min(W,Math.max(240,L.clientY-M.top));n({w:Q,h:O})}},k=()=>{v.current=!1,T.current=!1,document.body.style.cursor="",document.body.style.userSelect=""};return window.addEventListener("mousemove",F),window.addEventListener("mouseup",k),()=>{window.removeEventListener("mousemove",F),window.removeEventListener("mouseup",k)}},[c,n]);const A=()=>{if(_)n(w.current),h(!1);else{w.current=x;const F=p.current;if(F){const k=F.getBoundingClientRect();n({w:k.width-32,h:k.height-32}),c({x:16,y:16})}h(!0)}},z=u(),X=x;return e.jsxs("div",{ref:m,className:"absolute z-50 rounded-xl overflow-hidden border border-white/10 shadow-2xl shadow-black/50 bg-surface-0",style:{left:z.x,top:z.y,width:X.w,height:X.h},children:[e.jsxs("div",{onMouseDown:b,className:"flex items-center gap-2 px-2 py-1 bg-surface-1 border-b border-white/5 cursor-grab active:cursor-grabbing flex-shrink-0",children:[e.jsx(ks,{size:10,className:"text-gray-600"}),e.jsx("span",{className:"text-[10px] text-gray-400 font-medium flex-1",children:"Live Browser"}),e.jsx("button",{onClick:A,className:"p-0.5 rounded hover:bg-white/10 text-gray-500 hover:text-gray-400 transition-colors",children:_?e.jsx(Ns,{size:10}):e.jsx(Cs,{size:10})}),e.jsx("button",{onClick:l,className:"p-0.5 rounded hover:bg-white/10 text-gray-500 hover:text-gray-400 transition-colors",children:e.jsx(je,{size:10})})]}),e.jsx("div",{className:"h-[calc(100%-24px)]",children:e.jsx(At,{browserStatus:t,sessionEpoch:i,subscribe:a,send:r,isPiP:!0,onTogglePiP:l,onCloseBrowser:d,userControlOnly:E})}),!_&&e.jsx("div",{onMouseDown:y,className:"absolute bottom-0 right-0 w-4 h-4 cursor-nwse-resize",style:{background:"linear-gradient(135deg, transparent 50%, rgba(255,255,255,0.1) 50%)"}})]})}function ar({actions:t,onActionAdded:i,onStopped:a,onCancel:r}){const[x,n]=s.useState(""),[f,c]=s.useState(!1),[l,d]=s.useState(null),p=async()=>{if(x.trim()){c(!0),d(null);try{const m=await Ut(x);i(m.action),n("")}catch(m){d(m.message)}finally{c(!1)}}},E=async()=>{c(!0),d(null);try{const m=await Bt({testName:`Recorded ${Ys(new Date)}`,formatter:"wdio-appium-ts"});a(m)}catch(m){d(m.message)}finally{c(!1)}};return e.jsxs("div",{className:"border-t border-white/[0.05] bg-surface-1 flex flex-col",style:{maxHeight:280},children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 text-[11px] border-b border-white/[0.05]",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-red-500/15 text-red-300",children:[e.jsx("span",{className:"w-1 h-1 rounded-full bg-red-400 animate-pulse"}),"REC"]}),e.jsxs("span",{className:"text-gray-400",children:[t.length," action",t.length===1?"":"s"]}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{type:"button",onClick:r,disabled:f,className:"px-2 py-0.5 rounded text-gray-400 hover:text-gray-200 hover:bg-white/5 disabled:opacity-40",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:E,disabled:f||t.length===0,className:"inline-flex items-center gap-1 px-2 py-0.5 rounded bg-emerald-500/15 text-emerald-300 hover:bg-emerald-500/25 disabled:opacity-40",title:"Stop recording and generate test file",children:[f?e.jsx(ve,{size:11,className:"animate-spin"}):e.jsx(Ss,{size:10}),"Stop & Generate"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-3 py-2 space-y-1 text-[11px]",children:t.length===0?e.jsx("div",{className:"text-gray-500 italic",children:"Tap on the device screen above to record actions. Each tap finds the underlying element and stores a ranked locator set for the generated test."}):t.map(m=>e.jsx(ir,{action:m},m.index))}),e.jsxs("div",{className:"border-t border-white/[0.05] px-3 py-1.5 flex items-center gap-2",children:[e.jsx("input",{type:"text",value:x,onChange:m=>n(m.target.value),onKeyDown:m=>{m.key==="Enter"&&(m.preventDefault(),p())},disabled:f,placeholder:"Type text into the last tapped field…",className:"flex-1 bg-transparent border border-white/10 rounded px-2 py-1 text-[11px] text-gray-200 placeholder-gray-600 focus:outline-none focus:border-indigo-400/50"}),e.jsx("button",{type:"button",onClick:p,disabled:f||!x.trim(),className:"p-1 rounded text-indigo-300 hover:text-indigo-200 hover:bg-indigo-500/10 disabled:opacity-40",title:"Send text (Enter)",children:f?e.jsx(ve,{size:11,className:"animate-spin"}):e.jsx(Nt,{size:11})})]}),l&&e.jsxs("div",{className:"px-3 py-1 border-t border-white/[0.05] text-[11px] text-red-300 flex items-center gap-1",children:[e.jsx(Rs,{size:11}),l]})]})}function ir({action:t}){const i=t.type==="tap"?"👆":t.type==="type"?"⌨️":t.type==="swipe"?"↔︎":"⏎";return e.jsxs("div",{className:"flex items-start gap-1.5 text-gray-300",children:[e.jsxs("span",{className:"text-gray-500 tabular-nums w-5 text-right",children:[t.index+1,"."]}),e.jsx("span",{children:i}),e.jsxs("span",{className:"flex-1 break-all",children:[t.description,t.primary&&e.jsxs("span",{className:"text-gray-500 ml-1",children:["(",t.primary.strategy,"=",t.primary.value.slice(0,32),t.primary.value.length>32?"…":"",")"]})]})]})}function or({result:t,onDismiss:i}){return e.jsxs("div",{className:"border-t border-white/[0.05] bg-surface-1 px-3 py-2 text-[11px] space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-emerald-300",children:[e.jsx(nt,{size:12}),e.jsx("span",{className:"font-medium",children:"Test generated"})]}),e.jsxs("div",{className:"text-gray-400 flex items-start gap-1.5",children:[e.jsx(xt,{size:11,className:"mt-0.5 flex-shrink-0"}),e.jsx("code",{className:"break-all text-[10px]",children:t.specPath})]}),e.jsxs("div",{className:"text-gray-400 flex items-start gap-1.5",children:[e.jsx(xt,{size:11,className:"mt-0.5 flex-shrink-0 opacity-60"}),e.jsx("code",{className:"break-all text-[10px] opacity-80",children:t.healingPath})]}),e.jsxs("div",{className:"text-gray-500",children:["Wrote ",t.actions.length," action",t.actions.length===1?"":"s"," as a WDIO + Appium TypeScript spec. The companion ",e.jsx("code",{children:".healing.json"})," stores the full ranked locator set so the healing pipeline can recover from UI changes."]}),e.jsx("div",{className:"flex gap-2 pt-1",children:e.jsxs("button",{type:"button",onClick:i,className:"px-2 py-0.5 rounded text-gray-300 hover:bg-white/5 inline-flex items-center gap-1",children:[e.jsx(Es,{size:10})," Done"]})})]})}function ft(t,i,a){let r=null;const x=[];let n=0;for(const f of t){if(n=Math.max(n,ye(f.bounds)),i<f.bounds.x1||i>=f.bounds.x2||a<f.bounds.y1||a>=f.bounds.y2)continue;x.push(f);const c=(f.bounds.x2-f.bounds.x1)*(f.bounds.y2-f.bounds.y1);(!r||f.depth>r.depth||f.depth===r.depth&&c<ye(r.bounds))&&(r=f)}if(r&&!Qe(r)){const f=r;let c=null;for(const d of x)d===f||!Qe(d)||n&&ye(d.bounds)>n*.4||(!c||d.depth>c.depth||d.depth===c.depth&&ye(d.bounds)<ye(c.bounds))&&(c=d);if(c)return c;const l=x.filter(d=>d!==f&&d.depth<f.depth&&d.depth>=f.depth-4&&f.path.startsWith(d.path+"/")).sort((d,p)=>p.depth-d.depth);for(const d of l){if(n&&ye(d.bounds)>n*.4)break;if(Qe(d)||d.attrs.clickable==="true")return d}}return r}function Qe(t){const i=t.attrs["resource-id"]||"",a=[t.attrs["content-desc"],t.attrs.text,t.attrs.name,t.attrs.label,t.attrs.accessibilityIdentifier];return i.includes(":id/")&&!i.startsWith("android:")||a.some(r=>!!(r&&r.trim()))}function ye(t){return Math.max(0,t.x2-t.x1)*Math.max(0,t.y2-t.y1)}function we(t,i){const a=i==="android"?t.attrs.text||t.attrs["content-desc"]:t.attrs.label||t.attrs.name;if(a&&a.trim())return`"${a.slice(0,40)}"`;const r=t.attrs["resource-id"];return r?`#${r.split("/").pop()||r}`:t.tag.split(".").pop()||t.tag}function lr(t,i){const a=[];let r=t.path;for(a.unshift(t);;){const x=r.lastIndexOf("/");if(x<=0)break;r=r.slice(0,x);const n=i.find(f=>f.path===r);if(!n||(a.unshift(n),a.length>12))break}return a}function pt(t,i,a){const r=[],x=(c,l)=>i.filter(d=>d.attrs[c]===l).length===1,n=c=>i.filter(l=>l.attrs.text===c).length===1;if(a==="android"){const c=t.attrs["content-desc"];c&&c.trim()&&x("content-desc",c)&&r.push({strategy:"accessibility-id",value:c});const l=t.attrs["resource-id"];l&&l.includes(":id/")&&x("resource-id",l)&&r.push({strategy:"id",value:l});const d=t.attrs.text;d&&d.trim()&&n(d)&&r.push({strategy:"xpath",value:`//${t.tag}[@text=${mt(d)}]`}),l&&l.includes(":id/")&&r.push({strategy:"-android-uiautomator",value:`new UiSelector().resourceId("${l.replace(/"/g,'\\"')}")`}),r.push({strategy:"xpath",value:t.path})}else{const c=t.attrs.name||t.attrs.accessibilityIdentifier;c&&c.trim()&&r.push({strategy:"accessibility-id",value:c});const l=t.attrs.label;l&&l.trim()&&r.push({strategy:"xpath",value:`//${t.tag}[@label=${mt(l)}]`}),c&&c.trim()&&r.push({strategy:"-ios-class-chain",value:`**/${t.tag}[\`name == "${c.replace(/"/g,'\\"')}"\`]`}),r.push({strategy:"xpath",value:t.path})}const f=new Set;return r.filter(c=>{const l=`${c.strategy}:${c.value}`;return f.has(l)?!1:(f.add(l),!0)})}function mt(t){return t.includes("'")?t.includes('"')?`concat(${t.split("'").map(i=>`'${i}'`).join(`, "'", `)})`:`"${t}"`:`'${t}'`}function cr(t,i){const a=[];a.push({type:"visible",label:"Is visible",group:"visibility",editable:!1}),a.push({type:"hidden",label:"Is hidden",group:"visibility",editable:!1}),(t.attrs.enabled==="true"||t.attrs.enabled==="false"||t.attrs.clickable)&&(a.push({type:"enabled",label:"Is enabled",group:"state",editable:!1}),a.push({type:"disabled",label:"Is disabled",group:"state",editable:!1}));const r=i==="android"?t.attrs.text||t.attrs["content-desc"]:t.attrs.label||t.attrs.name||t.attrs.value;return r&&r.trim()?a.push({type:"text",label:`Has text "${r.length>30?r.slice(0,30)+"…":r}"`,expectedValue:r,group:"text",editable:!0}):a.push({type:"text",label:"Has text (custom)…",expectedValue:"",group:"text",editable:!0}),a.push({type:"attribute",label:"Has attribute (custom)…",expectedValue:"",group:"attribute",editable:!0}),a}const Ze=300,et=440,ue=12;function dr({element:t,platform:i,anchorX:a,anchorY:r,onSubmit:x,onCancel:n}){const f=s.useRef(null),[c]=s.useState(()=>cr(t,i)),[l,d]=s.useState(null),[p,E]=s.useState(""),[m,v]=s.useState({left:a,top:r});s.useEffect(()=>{const u=A=>{var z;(z=f.current)!=null&&z.contains(A.target)||n()},b=A=>{A.key==="Escape"&&n()},y=setTimeout(()=>document.addEventListener("mousedown",u),0);return document.addEventListener("keydown",b),()=>{clearTimeout(y),document.removeEventListener("mousedown",u),document.removeEventListener("keydown",b)}},[n]),s.useLayoutEffect(()=>{const u=window.innerWidth,b=window.innerHeight;let y=a+8,A=r+8;y+Ze+ue>u&&(y=Math.max(ue,a-Ze-8)),A+et+ue>b&&(A=Math.max(ue,r-et-8)),y<ue&&(y=ue),A<ue&&(A=ue),v({left:y,top:A})},[a,r]);const T={visibility:c.filter(u=>u.group==="visibility"),state:c.filter(u=>u.group==="state"),text:c.filter(u=>u.group==="text"),attribute:c.filter(u=>u.group==="attribute")},R=we(t,i),_=u=>{if(u.editable){d(u.type),E(u.expectedValue??"");return}x({type:u.type,expectedValue:u.expectedValue,label:R})},h=u=>{x({type:u.type,expectedValue:p,label:R})},w=e.jsxs("div",{ref:f,style:{position:"fixed",left:m.left,top:m.top,width:Ze,maxHeight:et},className:"z-[1000] rounded-xl border border-white/10 bg-surface-1 text-gray-200 shadow-2xl shadow-black/60 overflow-hidden flex flex-col backdrop-blur-md",role:"menu","aria-label":"Choose assertion",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 border-b border-white/10 bg-gradient-to-r from-emerald-500/15 via-green-500/10 to-transparent",children:[e.jsx("div",{className:"flex items-center justify-center w-6 h-6 rounded-md bg-emerald-500/20 border border-emerald-500/30 flex-shrink-0",children:e.jsx(Ts,{size:12,className:"text-emerald-300"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-emerald-200 font-bold leading-none",children:"Assert on"}),e.jsx("div",{className:"text-[12px] font-medium text-gray-100 truncate mt-0.5",children:R})]}),e.jsx("button",{onClick:n,className:"p-1 rounded-md text-gray-500 hover:text-gray-200 hover:bg-white/10 transition-colors","aria-label":"Close menu",children:e.jsx(je,{size:13})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto py-1.5 bg-surface-1",children:["visibility","state","text","attribute"].map(u=>{const b=T[u];return b.length===0?null:e.jsxs("div",{className:"py-1",children:[e.jsx("div",{className:"px-3 pb-1 pt-1 text-[10px] uppercase tracking-wider text-gray-500 font-semibold",children:ur[u]}),b.map(y=>e.jsx("div",{children:l===y.type?e.jsxs("div",{className:"px-3 py-2.5 bg-emerald-500/[0.04] border-y border-emerald-500/10",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[e.jsx(gt,{group:y.group}),e.jsx("span",{className:"text-[11px] text-gray-200 font-medium",children:y.type==="attribute"?"Attribute name → value":"Expected text"})]}),e.jsx("input",{type:"text",autoFocus:!0,value:p,onChange:A=>E(A.target.value),onKeyDown:A=>{A.key==="Enter"&&(A.preventDefault(),h(y)),A.key==="Escape"&&(A.preventDefault(),d(null))},placeholder:y.type==="attribute"?"e.g. enabled=true":"expected text…",className:"w-full bg-surface-0 border border-white/15 rounded-md px-2.5 py-1.5 text-[12px] text-gray-100 placeholder-gray-600 focus:outline-none focus:border-emerald-400/60 focus:ring-1 focus:ring-emerald-400/20"}),e.jsxs("div",{className:"flex justify-end gap-1.5 mt-1.5",children:[e.jsx("button",{onClick:()=>d(null),className:"px-2.5 py-1 rounded-md text-[11px] text-gray-400 hover:bg-white/5",children:"Cancel"}),e.jsxs("button",{onClick:()=>h(y),disabled:!p.trim()&&y.type!=="text",className:"inline-flex items-center gap-1 px-2.5 py-1 rounded-md text-[11px] bg-emerald-500/20 text-emerald-200 border border-emerald-500/30 hover:bg-emerald-500/30 disabled:opacity-40 transition-colors",children:[e.jsx(Ct,{size:10})," Record"]})]})]}):e.jsxs("button",{type:"button",onClick:()=>_(y),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left text-[12px] text-gray-200 hover:bg-emerald-500/10 hover:text-emerald-200 transition-colors group",children:[e.jsx(gt,{group:y.group}),e.jsx("span",{className:"flex-1 truncate",children:y.label}),e.jsx(Ue,{size:11,className:"text-gray-600 group-hover:text-emerald-300 opacity-0 group-hover:opacity-100 transition-opacity"})]})},y.type+y.label))]},u)})}),e.jsxs("div",{className:"px-3 py-1.5 border-t border-white/10 bg-surface-2/40 text-[10px] text-gray-500 flex items-center justify-between",children:[e.jsxs("span",{children:["Press ",e.jsx("kbd",{className:"px-1 py-0.5 rounded bg-white/10 text-gray-300 text-[9px] font-mono",children:"Esc"})," to close"]}),e.jsxs("span",{className:"text-gray-600",children:[c.length," option",c.length===1?"":"s"]})]})]});return wt.createPortal(w,document.body)}const ur={visibility:"Visibility",state:"State",text:"Text content",attribute:"Attributes"};function gt({group:t}){const i="text-gray-500";return t==="visibility"?e.jsx(ot,{size:12,className:i}):t==="state"?e.jsx(Ms,{size:12,className:i}):t==="text"?e.jsx($s,{size:12,className:i}):e.jsx(Ps,{size:12,className:i})}const tt=400,Ie=520,le=16;function xr({element:t,allElements:i,platform:a,anchorX:r,anchorY:x,onSubmit:n,onCancel:f}){const c=s.useRef(null),[l,d]=s.useState(""),[p,E]=s.useState({left:r,top:x}),m=lr(t,i),v=we(t,a),T=m.map(h=>`${De(h.tag)}${we(h,a)===De(h.tag)?"":` ${we(h,a)}`}`).join(" > ");s.useEffect(()=>{const h=b=>{var y;(y=c.current)!=null&&y.contains(b.target)||f()},w=b=>{b.key==="Escape"&&f()},u=setTimeout(()=>document.addEventListener("mousedown",h),0);return document.addEventListener("keydown",w),()=>{clearTimeout(u),document.removeEventListener("mousedown",h),document.removeEventListener("keydown",w)}},[f]),s.useLayoutEffect(()=>{const h=window.innerWidth,w=window.innerHeight;let u=r+12,b=x+12;u+tt+le>h&&(u=Math.max(le,r-tt-12)),b+Ie+le>w&&(b=Math.max(le,Math.min(w-Ie-le,x-Ie/2))),u<le&&(u=le),b<le&&(b=le),E({left:u,top:b})},[r,x]);const R=()=>{const h=l.trim();h&&n(h,T,v)},_=e.jsx(e.Fragment,{children:e.jsxs("div",{ref:c,style:{position:"fixed",left:p.left,top:p.top,width:tt,maxHeight:Ie},className:"z-[1000] rounded-xl border border-white/10 bg-surface-1 text-gray-200 shadow-2xl shadow-black/70 overflow-hidden flex flex-col",role:"dialog","aria-label":"Annotate element",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-white/10 bg-gradient-to-r from-purple-500/15 via-violet-500/10 to-transparent",children:[e.jsx("div",{className:"flex items-center justify-center w-7 h-7 rounded-md bg-purple-500/20 border border-purple-500/30 flex-shrink-0",children:e.jsx(As,{size:13,className:"text-purple-300"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-purple-200 font-bold leading-none",children:"Annotate element"}),e.jsx("div",{className:"text-[13px] font-medium text-gray-100 truncate mt-0.5",children:v})]}),e.jsx("button",{onClick:f,className:"p-1.5 rounded-md text-gray-500 hover:text-gray-200 hover:bg-white/10 transition-colors","aria-label":"Close dialog",children:e.jsx(je,{size:14})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-4 py-3 space-y-3.5 bg-surface-1",children:[e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-gray-500 font-semibold mb-1.5",children:[e.jsx(zs,{size:10,className:"text-purple-400"}),"Selected"]}),e.jsxs("div",{className:"rounded-lg border border-white/10 bg-surface-2/60 p-2.5 space-y-1",children:[e.jsx("div",{className:"text-[12px] text-purple-200 font-medium",children:v}),e.jsx("div",{className:"text-[11px] text-gray-500 font-mono",children:t.tag}),e.jsx(hr,{attrs:t.attrs,platform:a})]})]}),e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-gray-500 font-semibold mb-1.5",children:[e.jsx(_s,{size:10,className:"text-purple-400"}),"Hierarchy",e.jsxs("span",{className:"text-gray-600 font-normal normal-case tracking-normal",children:["(",m.length," level",m.length===1?"":"s",")"]})]}),e.jsx("div",{className:"rounded-lg border border-white/10 bg-surface-2/60 p-2.5 font-mono text-[11px] leading-relaxed",children:m.map((h,w)=>{const u=w===m.length-1,b=we(h,a),y=b!==De(h.tag);return e.jsxs("div",{style:{paddingLeft:w*12},className:`flex items-baseline gap-1 truncate ${u?"text-purple-200":"text-gray-400"}`,children:[e.jsx("span",{className:"text-gray-600",children:w===0?"":"└─"}),e.jsx("span",{className:u?"font-semibold":"",children:De(h.tag)}),y&&e.jsx("span",{className:"text-gray-500 truncate",children:b})]},h.path)})})]}),e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center justify-between text-[10px] uppercase tracking-wider text-gray-500 font-semibold mb-1.5",children:[e.jsx("span",{children:"Your note"}),e.jsx("span",{className:"text-gray-600 font-normal normal-case tracking-normal",children:"required"})]}),e.jsx("textarea",{autoFocus:!0,value:l,onChange:h=>d(h.target.value),onKeyDown:h=>{h.key==="Enter"&&(h.metaKey||h.ctrlKey)&&(h.preventDefault(),R())},placeholder:"What about this element matters? (intent, edge case, expectation…)",rows:4,className:"w-full bg-surface-0 border border-white/15 rounded-lg px-3 py-2 text-[12px] text-gray-100 placeholder-gray-600 focus:outline-none focus:border-purple-400/60 focus:ring-1 focus:ring-purple-400/20 resize-none leading-relaxed"}),e.jsxs("div",{className:"text-[10px] text-gray-600 mt-1",children:[e.jsx("kbd",{className:"px-1 py-0.5 rounded bg-white/10 text-gray-300 text-[9px] font-mono",children:"⌘/Ctrl + Enter"}),e.jsx("span",{className:"ml-1",children:"to save"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 px-4 py-2.5 border-t border-white/10 bg-surface-2/50",children:[e.jsx("button",{onClick:f,className:"px-3 py-1.5 rounded-md text-[12px] text-gray-300 hover:bg-white/5 transition-colors",children:"Cancel"}),e.jsxs("button",{onClick:R,disabled:!l.trim(),className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md text-[12px] font-medium bg-purple-500/20 text-purple-200 border border-purple-500/30 hover:bg-purple-500/30 disabled:opacity-40 disabled:cursor-not-allowed transition-colors",children:[e.jsx(Ct,{size:12})," Save annotation"]})]})]})});return wt.createPortal(_,document.body)}function De(t){return t.split(".").pop()||t}function hr({attrs:t,platform:i}){const r=(i==="android"?["text","content-desc","resource-id","class"]:["name","label","value","accessibilityIdentifier"]).filter(x=>t[x]);return r.length===0?null:e.jsx("div",{className:"space-y-0.5 mt-1 pt-1.5 border-t border-white/[0.05]",children:r.map(x=>e.jsxs("div",{className:"text-[10px] font-mono flex items-baseline gap-1",children:[e.jsx(Ue,{size:9,className:"text-gray-600 flex-shrink-0 mt-0.5"}),e.jsx("span",{className:"text-gray-500",children:x}),e.jsx("span",{className:"text-gray-600",children:"="}),e.jsx("span",{className:"text-gray-300 truncate",children:t[x]})]},x))})}const fr=60;function pr({session:t,onSessionEnded:i}){const[a,r]=s.useState(null),[x,n]=s.useState(!1),[f,c]=s.useState(null),[l,d]=s.useState(null),[p,E]=s.useState(null),[m,v]=s.useState(!1),[T,R]=s.useState(!1),[_,h]=s.useState([]),[w,u]=s.useState(null),[b,y]=s.useState(!1),[A,z]=s.useState(!1),X=s.useRef(!1),F=s.useRef(0),k=s.useRef(!1),L=s.useRef([]),M=s.useRef(null),C=s.useRef(null),H=s.useRef(null),W=s.useRef(!1),Q=s.useRef(null),[O,ke]=s.useState(!1),[U,He]=s.useState(!1),[Y,Ne]=s.useState([]),[J,Ce]=s.useState(null),[G,ce]=s.useState(null),[Z,he]=s.useState(null);s.useEffect(()=>{Ht().then(g=>{g.recording&&(R(!0),z(!0))}).catch(()=>{})},[]),s.useEffect(()=>{const g=N=>{const j=N.detail;j&&(R(j.recording),j.recording&&j.owner&&j.owner!=="mobile-live-view"&&z(!0),j.recording||z(!1))};return window.addEventListener("testver-mobile-recording-changed",g),()=>window.removeEventListener("testver-mobile-recording-changed",g)},[]);const ee=s.useCallback(async()=>{try{const g=await Xt();Ne(g.elements)}catch{}},[]),pe=s.useRef(!1),de=s.useRef(!1);s.useEffect(()=>{const g=()=>{const j=window.__testver_mobile_assert_mode===!0,P=window.__testver_mobile_annotate_mode===!0;ke(j),He(P),(j&&!pe.current||P&&!de.current)&&ee(),pe.current=j,de.current=P},N=setInterval(g,250);return g(),()=>clearInterval(N)},[ee]),s.useEffect(()=>{if(!O&&!U)return;const g=setInterval(()=>void ee(),3e3);return()=>clearInterval(g)},[O,U,ee]),s.useEffect(()=>{const g=()=>{!O&&!U||setTimeout(()=>void ee(),500)};return window.addEventListener("testver-mobile-action",g),()=>window.removeEventListener("testver-mobile-action",g)},[O,U,ee]);const ne=s.useCallback(async()=>{if(X.current)return;X.current=!0;const g=Date.now();try{const N=await Vt({timeoutMs:15e3,since:F.current||void 0});if(N.unchanged){d(null);return}F.current=N.capturedAt||0,r(N.image),c(null),d(null);const j=Date.now(),P=L.current;for(P.push(j);P.length>8;)P.shift();const I=P.length>1?(P[P.length-1]-P[0])/1e3:0,B=P.length>1&&I>0?(P.length-1)/I:0;E({lastMs:j-g,fps:B})}catch(N){const j=N.message;if(Yt(N)){c(null),d(N.status===503&&j?j:"The device is slow to respond — still waiting for a frame…");return}/HTTP 404/i.test(j)?(c("Session ended."),r(null),i()):c(j)}finally{X.current=!1}},[i]);s.useEffect(()=>{if(x)return;let g=!1,N=null;const j=t.providerId==="local-appium"&&t.platform==="android",P=async()=>{if(g)return;const I=typeof document<"u"&&document.visibilityState==="hidden"||X.current||!j&&(k.current||window.__testver_mobile_action_in_flight===!0);I||await ne(),!g&&(N=setTimeout(P,I?150:fr))};return P(),()=>{g=!0,N&&clearTimeout(N)}},[x,ne,t.providerId,t.platform]);const[Se,me]=s.useState(!1),Me=async()=>{v(!0);try{await Qt()}catch{}finally{i()}},$e=s.useCallback(async()=>{y(!0);try{const g=await Gt();R(!0),h(g.actions),u(null),window.dispatchEvent(new CustomEvent("testver-mobile-recording-changed",{detail:{recording:!0,owner:"mobile-live-view"}}))}catch(g){c(`Could not start recording: ${g.message}`)}finally{y(!1)}},[]),Pe=s.useCallback(()=>{R(!1),h([]),Kt().catch(()=>{})},[]),fe=s.useCallback(g=>{R(!1),u(g),h([])},[]),ae=s.useCallback(g=>{try{const j=Math.min(1,800/g.naturalWidth),P=Math.round(g.naturalWidth*j),I=Math.round(g.naturalHeight*j),B=document.createElement("canvas");B.width=P,B.height=I;const K=B.getContext("2d");return K?(K.drawImage(g,0,0,P,I),{dataUrl:B.toDataURL("image/jpeg",.55),width:P,height:I,deviceWidth:g.naturalWidth,deviceHeight:g.naturalHeight}):null}catch{return null}},[]);s.useEffect(()=>(window.__testver_capture_mobile_frame=()=>{const g=M.current;return g?ae(g):null},()=>{try{delete window.__testver_capture_mobile_frame}catch{}}),[ae]);const se=g=>{const N=M.current;if(!N)return null;const j=N.getBoundingClientRect(),P=(g.clientX-j.left)/j.width,I=(g.clientY-j.top)/j.height;return{deviceX:Math.round(P*N.naturalWidth),deviceY:Math.round(I*N.naturalHeight),imgRect:j}},Ae=s.useCallback(g=>{if(!O&&!U||Y.length===0)return;const N=se(g);if(!N)return;const j=ft(Y,N.deviceX,N.deviceY);(j==null?void 0:j.path)!==(J==null?void 0:J.path)&&Ce(j)},[O,U,Y,J]),ze=s.useCallback(()=>{Ce(null)},[]),q=s.useCallback(async()=>{const{getStoredToken:g,getClientId:N}=await dt(async()=>{const{getStoredToken:B,getClientId:K}=await import("./index-BYVxKLrT.js").then(o=>o.iF);return{getStoredToken:B,getClientId:K}},__vite__mapDeps([0,1,2,3,4])),j=g(),P=N(),I={"Content-Type":"application/json"};return j&&(I.Authorization=`Bearer ${j}`),P&&(I["X-Client-Id"]=P),I},[]),te=s.useCallback(()=>{T&&(Q.current&&clearTimeout(Q.current),Q.current=setTimeout(async()=>{try{const g=await q();await fetch("/api/mobile/recording/prime-source",{method:"POST",headers:g})}catch{}},450))},[T,q]);s.useEffect(()=>{T&&te()},[T,te]);const Re=s.useCallback(async(g,N)=>{k.current=!0,y(!0);try{const j=await q(),P=JSON.stringify({fromX:g.x,fromY:g.y,toX:N.x,toY:N.y,durationMs:300}),I=window.__testver_mobile_record_paused===!0,B=T&&!I,o=await fetch(B?"/api/mobile/recording/swipe":"/api/mobile/session/swipe",{method:"POST",headers:j,body:P}),$=await o.json().catch(()=>({}));if(!o.ok)throw new Error(($==null?void 0:$.error)||`HTTP ${o.status}`);B&&$.action&&(A||h(S=>[...S,$.action]),window.dispatchEvent(new CustomEvent("testver-mobile-action",{detail:{action:$.action}})))}catch(j){c(`Swipe failed: ${j.message}`)}finally{y(!1),k.current=!1,await ne(),te()}},[T,A,q,ne,te]),Xe=s.useCallback(g=>{if(O||U)return;const N=se(g);N&&(H.current={deviceX:N.deviceX,deviceY:N.deviceY,clientX:g.clientX,clientY:g.clientY,t:Date.now()})},[O,U]),Ve=s.useCallback(g=>{const N=H.current;if(H.current=null,!N||O||U)return;const j=se(g);if(!j)return;const P=g.clientX-N.clientX,I=g.clientY-N.clientY;Math.hypot(P,I)>=12&&(W.current=!0,Re({x:N.deviceX,y:N.deviceY},{x:j.deviceX,y:j.deviceY}))},[O,U,Re]),Ye=s.useCallback(async g=>{if(W.current){W.current=!1;return}if(!T)return;const N=se(g);if(!N)return;if(window.__testver_mobile_record_paused===!0){k.current=!0,y(!0);try{const I=await q(),B=await fetch("/api/mobile/session/tap",{method:"POST",headers:I,body:JSON.stringify({x:N.deviceX,y:N.deviceY})}),K=await B.json().catch(()=>({}));if(!B.ok)throw new Error((K==null?void 0:K.error)||`HTTP ${B.status}`)}catch(I){c(`Tap failed: ${I.message}`)}finally{y(!1),k.current=!1,ne()}return}if(O||U){const I=Y.length>0?ft(Y,N.deviceX,N.deviceY):null;if(!I){c("No accessibility element at that point. Refreshing tree…"),await ee();return}O&&ce({el:I,x:g.clientX,y:g.clientY}),U&&he({el:I,x:g.clientX,y:g.clientY});return}const j=M.current,P=ae(j);k.current=!0,y(!0);try{const{getStoredToken:I,getClientId:B}=await dt(async()=>{const{getStoredToken:V,getClientId:oe}=await import("./index-BYVxKLrT.js").then(be=>be.iF);return{getStoredToken:V,getClientId:oe}},__vite__mapDeps([0,1,2,3,4])),K=I(),o=B(),$={"Content-Type":"application/json"};K&&($.Authorization=`Bearer ${K}`),o&&($["X-Client-Id"]=o);const S=await fetch("/api/mobile/recording/tap",{method:"POST",headers:$,body:JSON.stringify({x:N.deviceX,y:N.deviceY,screenshot:P==null?void 0:P.dataUrl,screenshotSize:P?{width:P.width,height:P.height}:void 0,deviceSize:P?{width:P.deviceWidth,height:P.deviceHeight}:void 0})}),D=await S.json();if(!S.ok)throw new Error((D==null?void 0:D.error)||`HTTP ${S.status}`);const re=D.action;A||h(V=>[...V,re]),window.dispatchEvent(new CustomEvent("testver-mobile-action",{detail:{action:re}})),(O||U)&&ee()}catch(I){c(`Tap recording failed: ${I.message}`)}finally{y(!1),k.current=!1,ne(),te()}},[T,A,ne,ae,O,U,Y,ee,q]),ie=t.platform==="ios"?"ios":"android",ge=s.useCallback(g=>{const N=M.current;if(!N)return{screenshot:void 0,screenshotSize:void 0,elementRect:void 0};const j=ae(N);if(!j)return{screenshot:void 0,screenshotSize:void 0,elementRect:void 0};const P=j.width/j.deviceWidth,I=j.height/j.deviceHeight;return{screenshot:j.dataUrl,screenshotSize:{width:j.width,height:j.height},elementRect:{x:Math.round(g.bounds.x1*P),y:Math.round(g.bounds.y1*I),width:Math.round((g.bounds.x2-g.bounds.x1)*P),height:Math.round((g.bounds.y2-g.bounds.y1)*I)}}},[ae]),Ge=s.useCallback(async g=>{if(!G)return;const N=pt(G.el,Y,ie);if(N.length===0){c("Could not derive a stable locator for that element."),ce(null);return}k.current=!0;try{const j=ge(G.el),{action:P}=await qt({locator:N[0],ranked:N,elementAttrs:G.el.attrs,elementLabel:g.label,assertType:g.type,expectedValue:g.expectedValue,...j});A||h(I=>[...I,P]),window.dispatchEvent(new CustomEvent("testver-mobile-action",{detail:{action:P}}))}catch(j){c(`Assertion failed: ${j.message}`)}finally{k.current=!1,ce(null)}},[G,Y,ie,A,ge]),Ke=s.useCallback(async(g,N,j)=>{if(!Z)return;const P=pt(Z.el,Y,ie);k.current=!0;try{const I=ge(Z.el),{action:B}=await Jt({text:g,locator:P[0],ranked:P,elementAttrs:Z.el.attrs,elementLabel:j,elementHierarchy:N,...I});A||h(K=>[...K,B]),window.dispatchEvent(new CustomEvent("testver-mobile-action",{detail:{action:B}}))}catch(I){c(`Annotation failed: ${I.message}`)}finally{k.current=!1,he(null)}},[Z,Y,ie,A,ge]),qe=s.useCallback(g=>{h(N=>[...N,g])},[]),Je=x,_e=s.useMemo(()=>a?`data:image/png;base64,${a}`:null,[a]);return e.jsxs("div",{className:"h-full flex flex-col bg-surface-0 border-l border-white/[0.05]",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-white/[0.05] bg-surface-1",children:[e.jsx(lt,{size:13,className:"text-indigo-400"}),e.jsx("span",{className:"text-xs font-medium text-gray-200",children:t.device}),e.jsx("span",{className:"text-[10px] text-gray-500",children:"·"}),e.jsx("span",{className:"text-[10px] text-gray-500 uppercase",children:t.platform}),e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-emerald-500/10 text-[10px] text-emerald-300 ml-1",children:[e.jsx("span",{className:"w-1 h-1 rounded-full bg-emerald-400 animate-pulse"}),"LIVE"]}),e.jsx("div",{className:"flex-1"}),!A&&!T&&e.jsxs("button",{type:"button",onClick:$e,disabled:b,className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] text-red-300 hover:bg-red-500/10 disabled:opacity-40",title:"Start AI Record — capture taps and types as a runnable test",children:[b?e.jsx(ve,{size:10,className:"animate-spin"}):e.jsx(Is,{size:10,className:"fill-red-400 text-red-400"}),"Record"]}),T&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] bg-red-500/15 text-red-300",children:[e.jsx("span",{className:"w-1 h-1 rounded-full bg-red-400 animate-pulse"}),"RECORDING"]}),t.liveViewUrl&&e.jsx("a",{href:t.liveViewUrl,target:"_blank",rel:"noreferrer",className:"p-1 rounded text-gray-400 hover:text-gray-200 hover:bg-white/5",title:"Open provider dashboard in a new tab",children:e.jsx(Ds,{size:11})}),e.jsx("button",{type:"button",onClick:()=>n(g=>!g),className:"p-1 rounded text-gray-400 hover:text-gray-200 hover:bg-white/5",title:x?"Resume live view":"Pause live view",children:x?e.jsx(rt,{size:11}):e.jsx(Fe,{size:11})}),e.jsx("button",{type:"button",onClick:()=>me(!0),disabled:m,className:"p-1 rounded text-red-300 hover:text-red-200 hover:bg-red-500/10 disabled:opacity-40",title:"End session",children:e.jsx(je,{size:11})}),e.jsx(Gs,{open:Se,title:"End mobile session?",description:(T?"A recording is in progress — ending the session stops it. Steps captured so far remain in the panel, but no further actions can be recorded. ":"")+`This disconnects "${t.device}" and closes the Appium session. `+(t.providerId==="local-appium"?"Starting again boots a fresh session on the device.":"Starting again boots a fresh cloud session, which takes a moment and consumes provider device minutes."),confirmLabel:"End session",cancelLabel:"Keep session",onConfirm:()=>{me(!1),Me()},onCancel:()=>me(!1)})]}),e.jsx("div",{className:"flex-1 flex items-center justify-center p-1 overflow-hidden min-h-0",children:e.jsxs("div",{ref:C,className:`relative rounded-[18px] border ${T?O?"border-green-500/40":U?"border-purple-500/40":"border-red-500/40 shadow-red-500/10":"border-white/10"} bg-black overflow-hidden shadow-2xl shadow-black/40 inline-flex h-full max-w-full`,children:[_e?e.jsx("img",{ref:M,src:_e,alt:"Mobile device live view",className:`block h-full w-auto max-w-full max-h-full ${T?O||U?"cursor-pointer":"cursor-crosshair":"cursor-default"}`,style:{imageRendering:"auto"},draggable:!1,onClick:Ye,onMouseDown:Xe,onMouseUp:Ve,onMouseMove:Ae,onMouseLeave:ze}):e.jsx("div",{className:"flex flex-col items-center justify-center w-[200px] h-[400px] text-gray-500 text-xs gap-2",children:Je?e.jsxs(e.Fragment,{children:[e.jsx(Fe,{size:20}),e.jsx("span",{children:"Paused"})]}):e.jsxs(e.Fragment,{children:[e.jsx(ve,{size:20,className:"animate-spin"}),e.jsx("span",{className:"text-center px-4",children:l??"Loading first frame…"})]})}),(O||U)&&J&&M.current&&(()=>{const g=M.current,N=g.clientWidth/g.naturalWidth,j=g.clientHeight/g.naturalHeight;return e.jsx("div",{className:`absolute pointer-events-none border-2 rounded-sm ${O?"border-green-400 bg-green-400/15 shadow-[0_0_0_2px_rgba(34,197,94,0.25)]":"border-purple-400 bg-purple-400/15 shadow-[0_0_0_2px_rgba(168,85,247,0.25)]"}`,style:{left:Math.round(J.bounds.x1*N),top:Math.round(J.bounds.y1*j),width:Math.round((J.bounds.x2-J.bounds.x1)*N),height:Math.round((J.bounds.y2-J.bounds.y1)*j)},children:e.jsxs("div",{className:`absolute -top-5 left-0 px-1.5 py-0.5 rounded text-[10px] font-medium whitespace-nowrap ${O?"bg-green-500 text-white":"bg-purple-500 text-white"}`,children:[we(J,ie)," · ",J.tag.split(".").pop()]})})})(),G&&e.jsx(dr,{element:G.el,platform:ie,anchorX:G.x,anchorY:G.y,onSubmit:Ge,onCancel:()=>ce(null)}),Z&&e.jsx(xr,{element:Z.el,allElements:Y,platform:ie,anchorX:Z.x,anchorY:Z.y,onSubmit:Ke,onCancel:()=>he(null)})]})}),e.jsx("div",{className:"px-3 py-1.5 border-t border-white/[0.05] bg-surface-1 text-[10px] flex items-center gap-2",children:f?e.jsx("span",{className:"text-red-400",children:f}):p&&!x?e.jsxs("span",{className:"text-gray-500 tabular-nums",children:[p.fps.toFixed(1)," fps · ",p.lastMs," ms",T&&(window.__testver_mobile_record_paused===!0?" · paused: taps are not recorded":" · click screen to capture tap")]}):e.jsx("span",{className:"text-gray-500",children:x?"Polling paused.":a?"Polling…":l?"Waiting for the device…":"Polling…"})}),T&&!A&&e.jsx(ar,{actions:_,onActionAdded:qe,onStopped:fe,onCancel:Pe}),w&&e.jsx(or,{result:w,onDismiss:()=>u(null)})]})}const mr=32,gr=24,br=60;function Or({children:t}){const i=yt(),[a,r]=s.useState(null),[x,n]=s.useState(mr),[f,c]=s.useState(null),[l,d]=s.useState(null),[p,E]=s.useState(()=>Date.now());s.useEffect(()=>{if(!l)return;const _=setInterval(()=>E(Date.now()),1e3);return()=>clearInterval(_)},[l]);const m=s.useRef(!1),v=s.useRef(null);s.useEffect(()=>{vt().then(()=>Zt()).then(_=>{_.session&&r(_.session)}).catch(()=>{})},[]),s.useEffect(()=>i!=null&&i.subscribe?i.subscribe(h=>{if(h.type==="mobile-session-started"){const w=h.session;w&&r(w);return}if(h.type==="mobile-session-closed"){r(null),c(null),d(null);return}if(h.type==="mobile-session-expiring"){const w=h,u=Math.max(1,Number(w.secondsLeft)||60);E(Date.now()),d({reason:w.reason==="lifetime"?"lifetime":"idle",endsAt:Date.now()+u*1e3});return}if(h.type==="mobile-session-locked"){const w=h;c({runId:String(w.runId||""),ownerLabel:String(w.ownerLabel||"Test run")});return}if(h.type==="mobile-session-unlocked"){c(null);return}}):void 0,[i]);const T=s.useCallback(_=>{_.preventDefault(),m.current=!0,document.body.style.cursor="col-resize",document.body.style.userSelect="none"},[]);s.useEffect(()=>{const _=w=>{if(!m.current||!v.current)return;const u=v.current.getBoundingClientRect(),y=100-(w.clientX-u.left)/u.width*100;n(Math.min(br,Math.max(gr,y)))},h=()=>{m.current&&(m.current=!1,document.body.style.cursor="",document.body.style.userSelect="")};return window.addEventListener("mousemove",_),window.addEventListener("mouseup",h),()=>{window.removeEventListener("mousemove",_),window.removeEventListener("mouseup",h)}},[]);const R=a!==null;return e.jsxs("div",{ref:v,className:"flex h-full overflow-hidden relative",children:[e.jsx("div",{className:"flex-shrink-0 overflow-hidden",style:{width:R?`${100-x}%`:"100%"},children:t}),R&&e.jsxs(e.Fragment,{children:[e.jsx("div",{onMouseDown:T,className:"w-1 flex-shrink-0 cursor-col-resize bg-white/5 hover:bg-indigo-500/40 active:bg-indigo-500/40 transition-colors relative",children:e.jsx("div",{className:"absolute inset-y-0 -left-1 -right-1"})}),e.jsxs("div",{className:"flex-shrink-0 overflow-hidden relative",style:{width:`${x}%`},children:[e.jsx(pr,{session:a,onSessionEnded:()=>r(null)}),l&&e.jsxs("div",{role:"alert",className:"absolute left-2 right-2 top-2 z-40 px-3 py-2 rounded-lg bg-amber-500/20 border border-amber-500/40 text-amber-900 dark:text-amber-100 text-xs backdrop-blur flex items-start gap-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"font-semibold",children:[l.reason==="idle"?"Idle cloud session":"Session time limit"," — closes in ",Math.max(0,Math.ceil((l.endsAt-p)/1e3)),"s"]}),e.jsx("div",{className:"text-[10px] opacity-80 mt-0.5",children:l.reason==="idle"?"Nothing was done on the device for a while, and cloud devices bill by the minute.":"This cloud session has reached its maximum duration. Start a new session to continue."})]}),l.reason==="idle"?e.jsx("button",{type:"button",onClick:()=>{es().catch(()=>{}),d(null)},className:"flex-shrink-0 px-2 py-1 rounded-md bg-amber-500/30 hover:bg-amber-500/40 font-medium",children:"Keep session open"}):e.jsx("button",{type:"button",onClick:()=>d(null),"aria-label":"Dismiss",className:"flex-shrink-0 px-1.5 py-0.5 rounded hover:bg-amber-500/30",children:"×"})]}),f&&e.jsxs("div",{className:"absolute inset-0 z-30 flex flex-col pointer-events-none",children:[e.jsxs("div",{className:"pointer-events-auto mx-2 mt-2 px-3 py-2 rounded-lg bg-amber-500/20 border border-amber-500/40 text-amber-100 text-xs backdrop-blur flex items-start gap-2",children:[e.jsxs("span",{className:"relative flex h-2 w-2 mt-1 flex-shrink-0",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-amber-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-amber-400"})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-semibold",children:"Test driving this session"}),e.jsxs("div",{className:"text-[10px] opacity-80 mt-0.5",children:[f.ownerLabel," — your taps are paused so they don't conflict with the test's commands. Resumes automatically when the run ends."]})]})]}),e.jsx("div",{className:"flex-1 pointer-events-auto cursor-not-allowed"})]})]})]})]})}function Br({size:t=7,className:i=""}){return e.jsx("span",{role:"status","aria-label":"AI is working",className:`inline-flex items-center gap-[5px] ${i}`,children:[0,1,2].map(a=>e.jsx("span",{style:{width:t,height:t,animationDelay:`${a*.16}s`},className:"block rounded-full bg-[#8A8A8A] dark:bg-[#C8C8C8] ai-thinking-dot shadow-[0_0_4px_rgba(150,150,150,0.45)]"},a))})}function Ur({pending:t,queuedCount:i=0,onAllow:a,onAlwaysAllow:r,onDeny:x}){return e.jsx("div",{className:"rounded-xl border border-amber-500/40 bg-white dark:bg-surface-1 p-4 shadow-2xl",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(St,{size:18,className:"text-amber-500 dark:text-amber-400 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"text-sm font-semibold text-gray-800 dark:text-gray-200",children:t.prompt?"Over to you":"Permission required"}),i>0&&e.jsxs("span",{className:"text-[10px] text-gray-500",children:["+",i," more queued"]})]}),e.jsx("div",{className:"text-xs text-gray-600 dark:text-gray-400 mb-1",children:t.prompt??e.jsxs(e.Fragment,{children:["AI wants to run ",e.jsx("span",{className:"font-mono text-amber-600 dark:text-amber-300",children:t.toolName})]})}),!t.prompt&&(t.fullPath||t.args)&&e.jsx("div",{className:"w-full text-[11px] text-gray-700 dark:text-gray-300 font-mono break-all max-h-20 overflow-auto mb-2 px-3 py-2 rounded-md bg-gray-100 dark:bg-gray-500/20",title:t.fullPath||t.args,children:t.fullPath||t.args}),e.jsxs("div",{className:"flex items-center gap-2 mt-3",children:[e.jsx("button",{onClick:x,className:"px-3 py-1.5 rounded-md text-xs font-medium bg-gray-100 hover:bg-gray-200 text-gray-700 border border-gray-300 dark:bg-gray-500/15 dark:text-gray-300 dark:border-gray-500/25 dark:hover:bg-gray-500/25 transition-colors",children:t.prompt?"Skip":"Deny"}),e.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[t.allowRemember!==!1&&e.jsxs("button",{onClick:r,title:`Auto-approve all future ${t.toolName} calls in this session`,className:"px-3 py-1.5 rounded-md text-xs font-medium bg-brand-500/10 hover:bg-brand-500/20 text-brand-600 border border-brand-500/30 dark:bg-brand-500/15 dark:text-brand-300 dark:border-brand-500/25 dark:hover:bg-brand-500/25 transition-colors",children:["Always allow ",t.toolName]}),e.jsx("button",{onClick:a,className:"px-3 py-1.5 rounded-md text-xs font-medium bg-emerald-500/15 hover:bg-emerald-500/25 text-emerald-700 border border-emerald-500/40 dark:bg-emerald-500/20 dark:text-emerald-300 dark:border-emerald-500/30 dark:hover:bg-emerald-500/30 transition-colors",children:t.confirmLabel??"Allow"})]})]})]})]})})}const yr=(t,i=80)=>t.length>i?`${t.slice(0,i-1)}…`:t,xe=t=>t.replace(/^(browser|mobile|api)_/,"").replace(/_/g," ");function Te(t,i,a){const r=(i||"").trim(),x=r?yr(r):"",n=(f,c,l)=>({past:x?`${f} ${x}`:`${f} ${l}`,present:x?`${c} ${x}`:`${c} ${l}`});switch(t){case"read_file":return{category:"read",icon:"read",target:r,...n("Read","Reading","a file")};case"list_directory":return{category:"list",icon:"list",target:r,...n("Listed","Listing","a folder")};case"glob_search":return{category:"search",icon:"search",target:r,...n("Searched for","Searching for","files")};case"grep":return{category:"search",icon:"search",target:r,...n("Searched for","Searching for","text")};case"file_exists":return{category:"check",icon:"search",target:r,...n("Checked","Checking","a path")};case"write_file":return(a==null?void 0:a.diffType)==="new"?{category:"create",icon:"create",target:r,...n("Created","Creating","a file")}:a?{category:"edit",icon:"edit",target:r,...n("Edited","Editing","a file")}:{category:"edit",icon:"edit",target:r,...n("Wrote","Writing","a file")};case"edit_file":return{category:"edit",icon:"edit",target:r,...n("Edited","Editing","a file")};case"find_replace":return{category:"replace",icon:"edit",target:r,...n("Replaced text in","Replacing text in","files")};case"delete_file":return{category:"delete",icon:"delete",target:r,...n("Deleted","Deleting","a file")};case"create_directory":return{category:"mkdir",icon:"folder",target:r,...n("Created folder","Creating folder","")};case"run_command":return{category:"command",icon:"command",target:r,...n("Ran","Running","a command")};case"run_tests":return{category:"tests",icon:"tests",target:r,past:x?`Ran tests: ${x}`:"Ran the tests",present:x?`Running tests: ${x}`:"Running the tests"};case"browser_navigate":return{category:"browser",icon:"browser",target:r,...n("Opened","Opening","a page")};case"browser_click":return{category:"browser",icon:"browser",target:r,...n("Clicked","Clicking","an element")};case"browser_type":return{category:"browser",icon:"browser",target:r,...n("Typed into","Typing into","a field")};case"browser_snapshot":return{category:"browser",icon:"browser",target:r,past:"Read the page",present:"Reading the page"};case"browser_screenshot":return{category:"browser",icon:"browser",target:r,past:"Took a screenshot",present:"Taking a screenshot"};case"app_knowledge":return{category:"other",icon:"knowledge",target:r,past:"Looked up app knowledge",present:"Looking up app knowledge"};case"generate_test_code":return{category:"create",icon:"create",target:r,past:"Generated test code",present:"Generating test code"}}return t.startsWith("browser_")?{category:"browser",icon:"browser",target:r,past:`Browser: ${xe(t)}`,present:`Browser: ${xe(t)}`}:t.startsWith("mobile_")?{category:"mobile",icon:"mobile",target:r,past:`App: ${xe(t)}`,present:`App: ${xe(t)}`}:t.startsWith("api_")?{category:"api",icon:"api",target:r,past:`API: ${xe(t)}`,present:`API: ${xe(t)}`}:/report|dashboard|chart|document/.test(t)?{category:"report",icon:"report",target:r,past:`Built ${xe(t).replace(/^(build|generate|save|get) /,"")}`,present:`Building ${xe(t).replace(/^(build|generate|save|get) /,"")}`}:{category:"other",icon:"tool",target:r,past:`Used ${t}`,present:`Using ${t}`}}const wr=t=>t.replace(/\\/g,"/").split("/").filter(Boolean).pop()||t;function vr(t){var f,c,l;const i=[],a=new Map,r=new Map;for(const d of t){const p=d.tool?Te(d.tool.toolName,d.tool.args,d.diff):{category:((f=d.diff)==null?void 0:f.diffType)==="new"?"create":((c=d.diff)==null?void 0:c.diffType)==="deleted"?"delete":"edit",target:(l=d.diff)==null?void 0:l.filePath};a.has(p.category)||i.push(p.category),a.set(p.category,(a.get(p.category)??0)+1),r.set(p.category,p.target||"")}const x=(d,p)=>{const E=r.get(d)?wr(r.get(d)):"",m=(v,T)=>p===1&&E?`${v} ${E}`:`${v} ${p} ${T}${p===1?"":"s"}`;switch(d){case"read":return m("read","file");case"list":return m("listed","folder");case"search":return`searched ${p} pattern${p===1?"":"s"}`;case"check":return`checked ${p} path${p===1?"":"s"}`;case"create":return m("created","file");case"edit":return m("edited","file");case"delete":return m("deleted","file");case"mkdir":return`created ${p} folder${p===1?"":"s"}`;case"replace":return`replaced text ${p===1?"once":`${p} times`}`;case"command":return`ran ${p} command${p===1?"":"s"}`;case"tests":return p===1?"ran the tests":`ran the tests ${p} times`;case"browser":return`took ${p} browser action${p===1?"":"s"}`;case"api":return`made ${p} API call${p===1?"":"s"}`;case"mobile":return`took ${p} app action${p===1?"":"s"}`;case"report":return`built ${p} report${p===1?"":"s"}`;default:return`used ${p} tool${p===1?"":"s"}`}},n=i.map(d=>x(d,a.get(d))).join(", ");return n?n.charAt(0).toUpperCase()+n.slice(1):"Worked"}function jr(t){var f,c;const i=new Map;let a=0,r=0;for(const l of t)l.diff&&!l.diff.netNoChange&&i.set(l.diff.filePath,l.diff),((f=l.tool)==null?void 0:f.phase)==="error"&&a++,((c=l.tool)==null?void 0:c.phase)==="denied"&&r++;let x=0,n=0;for(const l of i.values())x+=l.linesAdded??0,n+=l.linesRemoved??0;return{added:x,removed:n,failed:a,denied:r}}const kr=new Set(["write_file","edit_file","delete_file"]),bt=t=>t.replace(/\\/g,"/").replace(/^\.\//,"").trim();function Nr(t,i){const a=bt(t),r=bt(i);return!a||!r?!1:a===r||a.endsWith(`/${r}`)||r.endsWith(`/${a}`)}function Cr(t){const i=new Map;let a;for(const n of t){if(n.omitted){a={count:((a==null?void 0:a.count)??0)+n.omitted.count,examples:[...(a==null?void 0:a.examples)??[],...n.omitted.examples].slice(0,5)};continue}if(!n.filePath)continue;if(n.netNoChange){i.delete(n.filePath);continue}const f=i.get(n.filePath),c=(f==null?void 0:f.diffType)==="new"&&n.diffType!=="deleted"?"new":n.diffType==="new"||n.diffType==="deleted"?n.diffType:"modified";i.has(n.filePath)&&i.delete(n.filePath),i.set(n.filePath,{filePath:n.filePath,diffType:c,diff:n.diff,linesAdded:n.linesAdded??0,linesRemoved:n.linesRemoved??0,via:n.via,unavailable:n.unavailable})}const r=[];for(const n of t)n.filePath&&!r.includes(n.filePath)&&r.push(n.filePath);const x=r.filter(n=>i.has(n)).map(n=>i.get(n));return a?{files:x,omitted:a}:{files:x}}function Hr(t,i){var d,p;const a=[];let r=null,x=[],n=[],f=0;const c=()=>{r=null},l=E=>{if(c(),E&&n.length){const{files:m,omitted:v}=Cr(n);(m.length||v)&&a.push({kind:"changes",id:`changes-${f}`,files:m,...v?{omitted:v}:{}})}n=[],x=[],f++};for(const E of t){if(i.isTurnStart(E)){l(!0),a.push({kind:"entry",entry:E});continue}if((d=i.isInvisible)!=null&&d.call(i,E))continue;const m=i.toolOf(E);if(m&&!((p=i.isStandalone)!=null&&p.call(i,E))){r||(r={kind:"group",id:`group-${E.id}`,steps:[],running:!1},x.push(r),a.push(r)),r.steps.push({tool:m});continue}const v=i.diffOf(E);if(v){if(n.push(v),v.via==="detected"||v.omitted||v.netNoChange)continue;let T;for(let R=x.length-1;R>=0&&!T;R--){const _=x[R].steps;for(let h=_.length-1;h>=0;h--){const w=_[h];if(w.tool&&!w.diff&&kr.has(w.tool.toolName)&&Nr(w.tool.args,v.filePath)){T=w;break}}}T?T.diff=v:r?r.steps.push({diff:v}):(r={kind:"group",id:`group-${E.id}`,steps:[{diff:v}],running:!1},x.push(r),a.push(r));continue}c(),a.push({kind:"entry",entry:E})}if(l(!i.streaming),i.streaming)for(let E=a.length-1;E>=0;E--){const m=a[E];if(m.kind==="group"){m.running=m.steps.some(v=>{var T;return((T=v.tool)==null?void 0:T.phase)==="start"});break}}return a}const Sr={read:Xs,list:Hs,search:Us,create:Tt,edit:Et,delete:Rt,folder:Bs,command:st,tests:Os,browser:kt,api:Nt,mobile:lt,report:Ws,knowledge:Fs,tool:Ls},Rr=t=>{const i=Math.max(0,Math.round(t/1e3));return i<60?`${i} s`:`${Math.floor(i/60)}m ${String(i%60).padStart(2,"0")}s`};function zt({added:t,removed:i}){return!t&&!i?null:e.jsxs("span",{className:"flex items-center gap-1 text-[12px] font-mono tabular-nums flex-shrink-0",children:[e.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400",children:["+",t]}),e.jsxs("span",{className:"text-red-600 dark:text-red-400",children:["−",i]})]})}function Er({step:t,detail:i}){if(t.diff)return t.diff.unavailable||!t.diff.diff?e.jsx("div",{className:"ml-9 mr-4 mt-1 mb-1.5 rounded-lg border border-gray-200 dark:border-white/5 bg-gray-50 dark:bg-black/20 px-3 py-2 text-[13px] text-gray-500",children:t.diff.unavailable==="binary"?"Binary file — no text diff to show.":t.diff.unavailable==="large"?"Too large to show here.":"No line changes."}):e.jsx("div",{className:"ml-9 mr-4 mt-1 mb-1.5 rounded-lg max-h-[360px] overflow-auto border border-gray-200 dark:border-white/5 bg-gray-50 dark:bg-black/30",children:e.jsx(Pt,{diff:t.diff.diff})});if(!t.tool)return null;if(i)return e.jsx(e.Fragment,{children:i(t.tool)});const a=t.tool;return e.jsxs("div",{className:"ml-9 mr-4 mt-1 mb-1.5 max-h-[240px] overflow-auto rounded-lg bg-gray-50 dark:bg-black/30 border border-gray-200 dark:border-white/5 p-2.5",children:[a.args&&e.jsx("div",{className:"text-[12px] font-mono text-gray-500 mb-1 break-all",children:a.args}),a.result&&e.jsx("div",{className:"text-[12px] font-mono text-gray-600 dark:text-gray-400 break-all whitespace-pre-wrap",children:a.result.slice(0,2e3)}),a.error&&e.jsx("div",{className:"text-[12px] font-mono text-red-500 dark:text-red-400 break-all",children:a.error})]})}function Tr({step:t,running:i,detail:a}){var m,v,T,R,_;const[r,x]=s.useState(!1),n=t.tool,f=n?Te(n.toolName,n.args,t.diff):{icon:((m=t.diff)==null?void 0:m.diffType)==="new"?"create":((v=t.diff)==null?void 0:v.diffType)==="deleted"?"delete":"edit",past:`${((T=t.diff)==null?void 0:T.diffType)==="new"?"Created":((R=t.diff)==null?void 0:R.diffType)==="deleted"?"Deleted":"Changed"} ${((_=t.diff)==null?void 0:_.filePath)??""}`,present:""},c=Sr[f.icon],l=(n==null?void 0:n.phase)==="start",d=l&&i?f.present:f.past,p=!!(t.diff||n!=null&&n.args||n!=null&&n.result||n!=null&&n.error),E=n?n.phase==="start"?i?e.jsx(ve,{size:14,className:"text-blue-500 dark:text-blue-400 animate-spin flex-shrink-0"}):e.jsx(Vs,{size:14,className:"text-gray-400 flex-shrink-0","aria-label":"Stopped"}):n.phase==="complete"?e.jsx(nt,{size:14,className:"text-emerald-500 dark:text-emerald-400 flex-shrink-0"}):n.phase==="error"?e.jsx(jt,{size:14,className:"text-red-500 dark:text-red-400 flex-shrink-0"}):e.jsx(St,{size:14,className:"text-amber-500 dark:text-amber-400 flex-shrink-0"}):e.jsx(nt,{size:14,className:"text-emerald-500 dark:text-emerald-400 flex-shrink-0"});return e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>p&&!l&&x(h=>!h),className:`flex w-full max-w-full items-center gap-2 pl-9 pr-4 py-1 text-left rounded-md transition-colors ${p&&!l?"hover:bg-gray-100/70 dark:hover:bg-white/[0.03] cursor-pointer":"cursor-default"}`,children:[E,e.jsx(c,{size:14,className:"text-gray-400 dark:text-gray-500 flex-shrink-0"}),e.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400 truncate min-w-0",title:d,children:d}),t.diff&&!t.diff.unavailable&&e.jsx(zt,{added:t.diff.linesAdded??0,removed:t.diff.linesRemoved??0}),(n==null?void 0:n.phase)==="error"&&n.error&&e.jsx("span",{className:"text-[13px] text-red-500 dark:text-red-400 truncate max-w-[320px]",title:n.error,children:n.error}),(n==null?void 0:n.phase)==="denied"&&e.jsx("span",{className:"text-[13px] text-amber-600 dark:text-amber-400 flex-shrink-0",children:"not allowed"}),p&&!l&&(r?e.jsx(Be,{size:13,className:"text-gray-400 flex-shrink-0"}):e.jsx(Ue,{size:13,className:"text-gray-400 flex-shrink-0"}))]}),r&&e.jsx(Er,{step:t,detail:a})]})}function Xr({group:t,detail:i,className:a=""}){var h,w,u;const[r,x]=s.useState(!1),[n,f]=s.useState(()=>Date.now()),{running:c,steps:l}=t;s.useEffect(()=>{if(!c)return;const b=setInterval(()=>f(Date.now()),1e3);return()=>clearInterval(b)},[c]);const d=jr(l),p=(w=(h=l.find(b=>{var y;return(y=b.tool)==null?void 0:y.startedAt}))==null?void 0:h.tool)==null?void 0:w.startedAt,E=l.reduce((b,y)=>{var A;return(A=y.tool)!=null&&A.endedAt&&(!b||y.tool.endedAt>b)?y.tool.endedAt:b},void 0),m=p?(c?n:E??p)-p:void 0,v=l.filter(b=>!b.tool||b.tool.phase!=="start").length,T=(u=[...l].reverse().find(b=>{var y;return((y=b.tool)==null?void 0:y.phase)==="start"}))==null?void 0:u.tool,R=l.length===1?l[0]:null,_=R!=null&&R.tool?Te(R.tool.toolName,R.tool.args,R.diff).past:R!=null&&R.diff?`${R.diff.diffType==="new"?"Created":R.diff.diffType==="deleted"?"Deleted":"Changed"} ${R.diff.filePath}`:vr(l);return e.jsxs("div",{className:a,children:[e.jsxs("button",{type:"button",onClick:()=>x(b=>!b),"aria-expanded":r,className:"flex max-w-full items-center gap-2 px-4 py-1 rounded-lg text-left transition-colors hover:bg-gray-100/70 dark:hover:bg-white/[0.03]",children:[c?e.jsx(ve,{size:14,className:"text-blue-500 dark:text-blue-400 animate-spin flex-shrink-0"}):r?e.jsx(Be,{size:14,className:"text-gray-400 flex-shrink-0"}):e.jsx(Ue,{size:14,className:"text-gray-400 flex-shrink-0"}),c&&T?e.jsx("span",{className:"text-sm text-blue-600 dark:text-blue-300 truncate min-w-0",title:Te(T.toolName,T.args).present,children:Te(T.toolName,T.args).present}):e.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400 truncate min-w-0",title:_,children:_}),e.jsx(zt,{added:d.added,removed:d.removed}),d.failed>0&&e.jsxs("span",{className:"text-[11px] px-1.5 py-0.5 rounded-full bg-red-500/10 text-red-600 dark:text-red-400 border border-red-500/20 flex-shrink-0",children:[d.failed," failed"]}),d.denied>0&&e.jsxs("span",{className:"text-[11px] px-1.5 py-0.5 rounded-full bg-amber-500/10 text-amber-600 dark:text-amber-400 border border-amber-500/20 flex-shrink-0",children:[d.denied," not allowed"]}),(c||l.length>1||m!==void 0&&m>=1e3)&&e.jsxs("span",{className:"text-[13px] text-gray-400 dark:text-gray-500 flex-shrink-0 tabular-nums",children:[c?`· ${v} done`:l.length>1?`· ${l.length} steps`:"",m!==void 0&&m>=1e3?` · ${Rr(m)}`:""]})]}),r&&e.jsx("div",{className:"mt-0.5 mb-1 space-y-0.5",children:l.map((b,y)=>{var A,z;return e.jsx(Tr,{step:b,running:c,detail:i},((A=b.tool)==null?void 0:A.id)??((z=b.diff)==null?void 0:z.id)??y)})})]})}const Le=6,_t=t=>t.reduce((i,a)=>({added:i.added+a.linesAdded,removed:i.removed+a.linesRemoved}),{added:0,removed:0});function it({type:t,size:i=13}){return t==="new"?e.jsx(Tt,{size:i,className:"text-emerald-500 flex-shrink-0"}):t==="deleted"?e.jsx(Rt,{size:i,className:"text-red-500 flex-shrink-0"}):e.jsx(Et,{size:i,className:"text-amber-500 flex-shrink-0"})}function It({file:t}){return e.jsxs(e.Fragment,{children:[t.diffType!=="modified"&&e.jsx("span",{className:`text-[11px] px-1.5 py-0.5 rounded-full border flex-shrink-0 ${t.diffType==="new"?"bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-emerald-500/20":"bg-red-500/10 text-red-600 dark:text-red-400 border-red-500/20"}`,children:t.diffType==="new"?"New":"Deleted"}),t.via==="detected"&&e.jsx("span",{className:"text-[11px] px-1.5 py-0.5 rounded-full border border-gray-300 dark:border-white/10 text-gray-500 flex-shrink-0",title:"Changed by a command or a bulk replace the AI ran — found by comparing git status before and after",children:"by a command"})]})}function Dt({path:t,strong:i=!0}){const a=t.lastIndexOf("/"),r=a>=0?t.slice(0,a+1):"",x=a>=0?t.slice(a+1):t;return e.jsxs("span",{className:"font-mono text-[13px] truncate min-w-0",title:t,children:[r&&e.jsx("span",{className:"text-gray-400 dark:text-gray-500",children:r}),e.jsx("span",{className:i?"text-gray-800 dark:text-gray-100 font-medium":"text-gray-700 dark:text-gray-300",children:x})]})}function Oe({added:t,removed:i}){return e.jsxs("span",{className:"flex items-center gap-1 text-[12px] font-mono tabular-nums flex-shrink-0",children:[e.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400",children:["+",t]}),e.jsxs("span",{className:"text-red-600 dark:text-red-400",children:["−",i]})]})}function Mr({files:t,omitted:i,initialPath:a,onClose:r,onOpenGit:x}){const[n,f]=s.useState(()=>Math.max(0,t.findIndex(d=>d.filePath===a))),c=_t(t),l=t[n];return s.useEffect(()=>{const d=p=>{p.key==="ArrowDown"?(f(E=>Math.min(t.length-1,E+1)),p.preventDefault()):p.key==="ArrowUp"&&(f(E=>Math.max(0,E-1)),p.preventDefault())};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[t.length]),e.jsx(Ks,{title:"Review changes",subtitle:`${t.length} file${t.length===1?"":"s"} · +${c.added} −${c.removed}`,icon:e.jsx("span",{className:"rounded-md bg-brand-500/15 p-1.5 text-brand-500 dark:text-brand-300",children:e.jsx(Mt,{size:14})}),onClose:r,toolbar:x&&e.jsxs("button",{onClick:x,className:"flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-xs font-medium text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",title:"Stage and commit these changes on the Git screen",children:[e.jsx($t,{size:14})," Open in Git"]}),footer:e.jsx(e.Fragment,{children:"↑ ↓ move between files · Esc closes"}),children:e.jsxs("div",{className:"absolute inset-0 flex",children:[e.jsxs("div",{className:"w-72 flex-shrink-0 overflow-y-auto border-r border-gray-200 dark:border-white/5 py-1.5",role:"listbox","aria-label":"Changed files",children:[t.map((d,p)=>e.jsxs("button",{role:"option","aria-selected":p===n,onClick:()=>f(p),className:`flex w-full items-center gap-2 px-3 py-1.5 text-left transition-colors ${p===n?"bg-brand-500/10 dark:bg-brand-500/15":"hover:bg-gray-100 dark:hover:bg-white/[0.04]"}`,children:[e.jsx(it,{type:d.diffType,size:12}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[13px] text-gray-700 dark:text-gray-300",title:d.filePath,children:d.filePath.split("/").pop()}),!d.unavailable&&e.jsx(Oe,{added:d.linesAdded,removed:d.linesRemoved})]},d.filePath)),i&&i.count>0&&e.jsxs("p",{className:"px-3 py-2 text-[12px] text-gray-500",children:["…and ",i.count," more file",i.count===1?"":"s"," changed by commands, not listed."]})]}),e.jsx("div",{className:"flex min-w-0 flex-1 flex-col",children:l?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 border-b border-gray-200 dark:border-white/5 px-4 py-2",children:[e.jsx(it,{type:l.diffType}),e.jsx(Dt,{path:l.filePath}),e.jsx(It,{file:l}),!l.unavailable&&e.jsx(Oe,{added:l.linesAdded,removed:l.linesRemoved})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto bg-gray-50 dark:bg-black/20",children:l.unavailable||!l.diff?e.jsx("p",{className:"p-6 text-sm text-gray-500",children:l.unavailable==="binary"?"Binary file — there is no text diff to show.":l.unavailable==="large"?"This file is too large to show a diff here. Open it on the Git screen.":"No line changes."}):e.jsx(Pt,{diff:l.diff,className:"py-1"})})]}):e.jsx("p",{className:"p-6 text-sm text-gray-500",children:"No files."})})]})})}function Vr({item:t}){const i=Lt(),a=ts(),[r,x]=s.useState(!1),[n,f]=s.useState(null),{files:c,omitted:l}=t,d=s.useMemo(()=>_t(c),[c]),p=r?c:c.slice(0,Le),E=c.length+((l==null?void 0:l.count)??0),m=()=>{f(null),i("/git")};return e.jsxs("div",{className:"mx-4 my-2 max-w-3xl rounded-xl border border-gray-200 dark:border-white/10 bg-gray-50/70 dark:bg-white/[0.03]",children:[e.jsxs("div",{className:"flex items-center gap-3 px-3.5 py-2.5",children:[e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-white dark:bg-white/[0.06] border border-gray-200 dark:border-white/10 flex-shrink-0",children:e.jsx(Mt,{size:16,className:"text-gray-600 dark:text-gray-300"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"text-sm font-semibold text-gray-800 dark:text-gray-100",children:["Changed ",E," file",E===1?"":"s"]}),e.jsx(Oe,{added:d.added,removed:d.removed})]}),a&&e.jsxs("button",{onClick:m,className:"flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[13px] font-medium text-gray-600 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",title:"Stage and commit these changes on the Git screen",children:[e.jsx($t,{size:14})," Open in Git"]}),c.length>0&&e.jsxs("button",{onClick:()=>f({}),className:"flex items-center gap-1.5 rounded-lg border border-gray-300 dark:border-white/15 bg-white dark:bg-white/[0.04] px-3 py-1.5 text-[13px] font-semibold text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-white/10 transition-colors",children:[e.jsx(ot,{size:14})," Review"]})]}),c.length>0&&e.jsxs("div",{className:"border-t border-gray-200 dark:border-white/5 py-1",children:[p.map(v=>e.jsxs("button",{onClick:()=>f({path:v.filePath}),className:"flex w-full items-center gap-2 px-3.5 py-1.5 text-left transition-colors hover:bg-gray-100/80 dark:hover:bg-white/[0.04]",title:"Review this file",children:[e.jsx(it,{type:v.diffType,size:14}),e.jsx(Dt,{path:v.filePath,strong:!1}),e.jsx(It,{file:v}),e.jsx("span",{className:"ml-auto flex items-center gap-2",children:v.unavailable?e.jsx("span",{className:"text-[12px] text-gray-400",children:v.unavailable==="binary"?"binary":"too large"}):e.jsx(Oe,{added:v.linesAdded,removed:v.linesRemoved})})]},v.filePath)),c.length>Le&&e.jsxs("button",{onClick:()=>x(v=>!v),className:"flex items-center gap-1 px-3.5 py-1 text-[13px] font-medium text-brand-500 dark:text-brand-300 hover:underline",children:[e.jsx(Be,{size:11,className:r?"rotate-180":""}),r?"Show fewer":`Show ${c.length-Le} more file${c.length-Le===1?"":"s"}`]})]}),l&&l.count>0&&e.jsxs("p",{className:"border-t border-gray-200 dark:border-white/5 px-3.5 py-1.5 text-[13px] text-gray-500",children:[c.length>0?"…and ":"",l.count," ",c.length>0?"more ":"","file",l.count===1?"":"s"," changed by commands",l.examples.length>0&&e.jsxs(e.Fragment,{children:[" (for example ",e.jsx("span",{className:"font-mono",children:l.examples.slice(0,2).join(", ")}),")"]}),a?e.jsxs(e.Fragment,{children:[" ","— see the Git screen for all of them."]}):"."]}),n&&e.jsx(Mr,{files:c,omitted:l,initialPath:n.path,onClose:()=>f(null),onOpenGit:a?m:void 0})]})}export{Br as A,Vr as C,Wr as L,Ur as P,Xr as T,Or as a,Hr as b,Fr as f};
@@ -1,2 +0,0 @@
1
- import{r as m,j as e}from"./vendor-react-CTbHBddL.js";import{dW as u}from"./index-BYVxKLrT.js";import{y as b,t as N,c0 as w,b$ as j,ab as y}from"./vendor-icons-BKPiFyYV.js";function g(){const[d,n]=m.useState(()=>u());return m.useEffect(()=>{const a=new MutationObserver(()=>n(u()));return a.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>a.disconnect()},[]),d}function k(d){const n=[];let a=0,x=0,i=!1;for(const s of d.split(`
2
- `)){if(!i&&(s.startsWith("--- ")||s.startsWith("+++ ")||s.startsWith("diff ")||s.startsWith("index ")||s==="---"||s==="+++"))continue;if(s.startsWith("diff --git ")){i=!1;continue}const l=s.match(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@/);if(l){i=!0,a=parseInt(l[1],10),x=parseInt(l[2],10),n.push({kind:"hunk",oldNo:null,newNo:null,text:s});continue}s.startsWith("+")?n.push({kind:"add",oldNo:null,newNo:x++,text:s.slice(1)}):s.startsWith("-")?n.push({kind:"del",oldNo:a++,newNo:null,text:s.slice(1)}):n.push({kind:"ctx",oldNo:a++,newNo:x++,text:s.startsWith(" ")?s.slice(1):s})}const r=n[n.length-1];return r&&r.kind==="ctx"&&r.text===""&&n.pop(),n}function v({diff:d,className:n=""}){const a=g()==="light",x=k(d),i=r=>r==="hunk"?a?{row:"bg-indigo-50/70",gutter:"bg-indigo-50/70 text-indigo-400",text:"text-indigo-600"}:{row:"bg-indigo-500/[0.07]",gutter:"bg-indigo-500/[0.07] text-indigo-500/70",text:"text-indigo-300/80"}:r==="add"?a?{row:"bg-emerald-50",gutter:"bg-emerald-100/70 text-emerald-600/70",text:"text-emerald-800"}:{row:"bg-emerald-500/[0.09]",gutter:"bg-emerald-500/[0.14] text-emerald-400/60",text:"text-emerald-200"}:r==="del"?a?{row:"bg-red-50",gutter:"bg-red-100/70 text-red-600/70",text:"text-red-800"}:{row:"bg-red-500/[0.09]",gutter:"bg-red-500/[0.14] text-red-400/60",text:"text-red-200"}:a?{row:"",gutter:"bg-gray-50 text-gray-400",text:"text-gray-600"}:{row:"",gutter:"bg-white/[0.02] text-gray-600",text:"text-gray-400"};return e.jsx("div",{className:`min-w-max font-mono text-[11px] leading-[1.55] ${n}`,children:x.map((r,s)=>{const l=i(r.kind);if(r.kind==="hunk")return e.jsxs("div",{className:`flex ${l.row}`,children:[e.jsx("span",{className:`sticky left-0 w-[84px] flex-shrink-0 px-2 select-none ${l.gutter}`}),e.jsx("span",{className:`px-2 whitespace-pre ${l.text}`,children:r.text})]},s);const t=r.kind==="add"?"+":r.kind==="del"?"−":" ";return e.jsxs("div",{className:`flex ${l.row}`,children:[e.jsxs("span",{className:`sticky left-0 flex-shrink-0 flex select-none ${l.gutter}`,children:[e.jsx("span",{className:"w-10 text-right pr-2 tabular-nums",children:r.oldNo??""}),e.jsx("span",{className:"w-10 text-right pr-2 tabular-nums",children:r.newNo??""}),e.jsx("span",{className:"w-4 text-center",children:t})]}),e.jsx("span",{className:`pl-2 pr-4 whitespace-pre ${l.text}`,children:r.text||" "})]},s)})})}function P({diffs:d}){const[n,a]=m.useState({}),i=g()==="light";if(d.length===0)return null;const r=t=>{a(o=>({...o,[t]:!o[t]}))},s=i?"hover:bg-gray-100/70":"hover:bg-white/[0.04]",l=i?"bg-gray-50 border border-gray-200":"bg-black/30 border border-white/5";return e.jsx("div",{className:"mt-2",children:e.jsx("div",{className:"space-y-0.5",children:d.map((t,o)=>{const f=n[o]??!1,c=t.filePath.lastIndexOf("/"),h=c>=0?t.filePath.slice(0,c+1):"",p=c>=0?t.filePath.slice(c+1):t.filePath;return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>r(o),className:`inline-flex max-w-full items-center gap-2 px-4 py-1.5 rounded-lg transition-colors text-left ${s}`,title:t.filePath,children:[f?e.jsx(b,{size:12,className:"text-gray-500 flex-shrink-0"}):e.jsx(N,{size:12,className:"text-gray-500 flex-shrink-0"}),t.diffType==="new"?e.jsx(w,{size:13,className:"text-emerald-500 flex-shrink-0"}):t.diffType==="deleted"?e.jsx(j,{size:13,className:"text-red-500 flex-shrink-0"}):e.jsx(y,{size:13,className:"text-amber-500 flex-shrink-0"}),e.jsxs("span",{className:"text-xs font-mono truncate min-w-0",children:[h&&e.jsx("span",{className:i?"text-gray-400":"text-gray-600",children:h}),e.jsx("span",{className:i?"text-gray-900 font-medium":"text-gray-100 font-medium",children:p})]}),e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] font-mono tabular-nums flex-shrink-0",children:[t.linesAdded>0&&e.jsxs("span",{className:i?"text-emerald-600":"text-emerald-400",children:["+",t.linesAdded]}),t.linesRemoved>0&&e.jsxs("span",{className:i?"text-red-600":"text-red-400",children:["−",t.linesRemoved]})]}),e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full border flex-shrink-0 ${t.diffType==="new"?"bg-emerald-500/10 text-emerald-500 border-emerald-500/20":t.diffType==="deleted"?"bg-red-500/10 text-red-500 border-red-500/20":"bg-amber-500/10 text-amber-500 border-amber-500/20"}`,children:t.diffType==="new"?"New":t.diffType==="deleted"?"Deleted":"Modified"})]}),f&&e.jsx("div",{className:`mx-4 mt-1 mb-1 rounded-lg max-h-[420px] overflow-auto ${l}`,children:e.jsx(v,{diff:t.diff})})]},`${t.filePath}-${t.timestamp}`)})})})}export{P as D,v as a};
@@ -1 +0,0 @@
1
- import{r as o,j as t}from"./vendor-react-CTbHBddL.js";import{y as P,z as S,A as I}from"./index-BYVxKLrT.js";import{M as E}from"./MobileRunTarget-Bo_xekig.js";import{J as N,at as C}from"./vendor-icons-BKPiFyYV.js";const L={browserstack:"BrowserStack",saucelabs:"Sauce Labs",lambdatest:"LambdaTest","local-appium":"Local Devices"};function $({disabled:p,initial:e,compact:u=!1,onChange:y}){const[c,x]=o.useState([]),[l,f]=o.useState(!1),[s,n]=o.useState((e==null?void 0:e.cloudProvider)||""),[a,j]=o.useState({deviceName:(e==null?void 0:e.deviceName)||"",platformName:(e==null?void 0:e.platformName)==="iOS"?"iOS":"Android",platformVersion:(e==null?void 0:e.platformVersion)||"",appId:(e==null?void 0:e.appId)||"",appPath:(e==null?void 0:e.appPath)||""}),[h,g]=o.useState();o.useEffect(()=>{P().then(r=>x(r.providers.filter(d=>d.enabled&&d.id!=="testver-grid"))).catch(()=>x([])),S().then(({config:r})=>f(!!r.enabled)).catch(()=>f(!1))},[]),o.useEffect(()=>{s||(l?n("local-appium"):c.length>0&&n(c[0].id))},[l,c,s]),o.useEffect(()=>{if(!s){g(void 0);return}let r=!1;const d=()=>{I().then(w=>{if(r)return;const m=w.ticket;g(m&&!m.claimed&&Date.now()<m.expiresAt?m.sessionId:void 0)}).catch(()=>{})};d();const k=window.setInterval(d,5e3);return()=>{r=!0,window.clearInterval(k)}},[s]);const b=c.length===0&&!l;if(o.useEffect(()=>{const r=!!s&&!!a.deviceName&&(!!a.appId||!!a.appPath.trim()),d=s?{cloudProvider:s,deviceName:a.deviceName,platformName:a.platformName,platformVersion:a.platformVersion,appId:a.appId,appPath:a.appPath,reuseSessionId:h}:null;y({payload:d,active:!!s,blocked:b,ready:r})},[s,a,h,b]),b)return t.jsxs("div",{className:"mt-3 flex items-start gap-2.5 px-3.5 py-3 rounded-xl border border-amber-500/25 bg-amber-500/10 text-sm text-amber-700 dark:text-amber-200",children:[t.jsx(N,{size:15,className:"mt-0.5 flex-shrink-0 text-amber-600 dark:text-amber-300"}),t.jsxs("span",{children:["No device target available. To run this test, connect a local device or enable a cloud device grid in ",t.jsx("span",{className:"font-semibold",children:"Connectors"}),"."]})]});const v=u?"flex items-center gap-1 px-2.5 py-1 text-xs rounded-lg border transition-colors":"flex items-center gap-1.5 px-2.5 h-8 text-xs rounded-lg border transition-colors",i=12;return t.jsxs("div",{className:u?"space-y-2":"mt-3 space-y-2",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:`${u?"text-xs":"text-sm"} text-gray-400`,children:"Run on:"}),t.jsxs("div",{className:"flex gap-1.5 flex-wrap",children:[c.map(r=>t.jsxs("button",{onClick:()=>n(r.id),disabled:p,className:`${v} ${s===r.id?"border-blue-500/50 bg-blue-500/10 text-blue-300 font-medium":"border-white/5 bg-surface-2 text-gray-400 hover:text-gray-300 hover:border-white/10"} disabled:opacity-50`,children:[t.jsx(C,{size:i}),L[r.id]||r.id]},r.id)),l&&t.jsxs("button",{onClick:()=>n("local-appium"),disabled:p,className:`${v} ${s==="local-appium"?"border-gray-300 dark:border-white/25 bg-gray-100/70 dark:bg-white/[0.08] text-gray-800 dark:text-gray-100 font-medium":"border-white/5 bg-surface-2 text-gray-400 hover:text-gray-300 hover:border-white/10"} disabled:opacity-50`,children:[t.jsx(N,{size:i}),"Local Devices"]})]})]}),s&&t.jsx(E,{providerId:s,disabled:p,value:a,onChange:j})]})}export{$ as M};
@@ -1,6 +0,0 @@
1
- import{r as i,j as e}from"./vendor-react-CTbHBddL.js";import{T as O,bz as _,bA as V,U as B,S as E,X as H}from"./index-BYVxKLrT.js";import{J as M,_ as K,a0 as U,dh as X,y as J,ag as W,bd as Y}from"./vendor-icons-BKPiFyYV.js";import{a as z}from"./formatDate-T65-Y6Mi.js";import{S as q,L as G}from"./SearchableDevicePicker-BYxYJNWl.js";const P=1e3;function ae({testRunning:c,hideHeader:j=!1}){const[s,h]=i.useState(null),[x,A]=i.useState(null),[v,m]=i.useState(null),[N,w]=i.useState(null),[b,k]=i.useState(!1),[g,f]=i.useState(P),y=i.useRef(null),o=i.useRef(0),d=i.useRef(c);i.useEffect(()=>{d.current=c},[c]),i.useEffect(()=>{let l=!1;return O().then(p=>{l||h(p.session)}).catch(()=>{}),()=>{l=!0}},[]),i.useEffect(()=>{let l=!1;const p=async()=>{if(!l)try{const r=await _({timeoutMs:15e3,since:o.current||void 0});!l&&r.unchanged?m(null):l||(o.current=r.capturedAt||0,A(r.image),m(null),k(!!r.delayed),r.dashboardUrl&&w(r.dashboardUrl),f(d.current?500:P))}catch(r){!l&&V(r)?(m(null),f(P)):l||(m(r.message),f(Math.min(g*2,d.current?4e3:1e4)))}finally{l||(y.current=window.setTimeout(p,g))}};return p(),()=>{l=!0,y.current&&window.clearTimeout(y.current)}},[]);const S=!s;return e.jsxs("div",{className:"h-full flex flex-col bg-surface-1",children:[!j&&e.jsxs("div",{className:"px-3 py-2 border-b border-white/5 flex items-center gap-2",children:[e.jsx(M,{size:13,className:"text-indigo-300"}),e.jsx("span",{className:"text-xs font-medium text-gray-200",children:c?"Live Device — Execution view":"Live Device"}),s&&e.jsx("span",{className:"text-[10px] text-gray-500 truncate",children:s.device}),b&&x&&e.jsx("span",{className:"text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400/80 border border-amber-500/20 flex-shrink-0",title:"Cloud preview frames are captured between test commands and are a few seconds behind the device. Use the provider link for their real-time view.",children:"~few sec behind"}),e.jsx("div",{className:"flex-1"}),((s==null?void 0:s.dashboardUrl)||N)&&e.jsxs("a",{href:(s==null?void 0:s.dashboardUrl)||N,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[10px] text-indigo-300 hover:text-indigo-200",title:"Open the cloud provider's session view — their stream is real-time",children:["Live on provider ",e.jsx(K,{size:9})]})]}),e.jsx("div",{className:"flex-1 overflow-hidden relative flex items-center justify-center bg-black/40",children:S&&!c?e.jsxs("div",{className:"text-center px-4 py-8",children:[e.jsx(M,{size:28,className:"text-gray-600 mx-auto mb-2"}),e.jsx("p",{className:"text-xs text-gray-400",children:"No active mobile session"}),e.jsx("p",{className:"text-[10px] text-gray-600 mt-1",children:"Click Run to start a test (a device session opens automatically), or connect a device in AI Assistant."}),v&&e.jsx("p",{className:"text-[10px] text-red-400 mt-2",children:v})]}):x?e.jsx("img",{src:`data:image/png;base64,${x}`,alt:"Live device",className:"max-h-full max-w-full object-contain",style:c?{filter:"saturate(0.85) brightness(0.95)"}:void 0}):e.jsxs("div",{className:"flex flex-col items-center gap-2 text-xs text-gray-500 px-4 py-8 text-center",children:[e.jsx(U,{size:14,className:"animate-spin"}),e.jsx("span",{children:"Waiting for the test's device session…"}),e.jsx("span",{className:"text-[10px] text-gray-600",children:"First frame appears within a few seconds of session creation."})]})})]})}function ie({providerId:c,disabled:j,value:s,onChange:h}){const[x,A]=i.useState([]),[v,m]=i.useState(!1),[N,w]=i.useState(null),[b,k]=i.useState([]),[g,f]=i.useState(null),[y,o]=i.useState(!1),[d,S]=i.useState(!1),[l,p]=i.useState(null),r=i.useRef(null);i.useEffect(()=>{let t=!1;return m(!0),w(null),B(c).then(a=>{t||A(a.devices||[])}).catch(a=>{t||w(a.message)}).finally(()=>{t||m(!1)}),()=>{t=!0}},[c]),i.useEffect(()=>{let t=!1;return E().then(a=>{t||k(a.apps||[])}).catch(a=>{t||f(a.message)}),()=>{t=!0}},[]);const $=i.useMemo(()=>{if(!s.deviceName)return"";const t=x.find(a=>(a.rawDeviceKey===s.deviceName||a.name===s.deviceName)&&a.os===s.platformVersion);return t?t.id:""},[x,s.deviceName,s.platformVersion]),n=i.useMemo(()=>b.find(t=>t.id===s.appId)??null,[b,s.appId]),L=n?n.label||n.filename:s.appPath.trim()?s.appPath.trim():"Pick app or upload…",D=(()=>{if(n){const t=(n.size/1048576).toFixed(1),a=n.kind==="ipa"?"iOS":"Android",u=n.uploadedAt?z(n.uploadedAt):"";return[n.label||n.filename,n.filename,`${a} · ${t} MB${u?` · uploaded ${u}`:""}`].join(`
2
- `)}return s.appPath.trim()?s.appPath.trim():"Pick app or upload…"})(),C=t=>{h({...s,deviceName:c==="local-appium"?t.rawDeviceKey:t.name,platformName:t.platform==="ios"?"iOS":"Android",platformVersion:t.os})},I=t=>{h({...s,appId:t.id,appPath:""}),o(!1)},R=()=>{h({...s,appId:"",appPath:""}),o(!1)},T=async t=>{S(!0),f(null),p(0);try{const a=await H(t,void 0,F=>p(F)),u=await E();k(u.apps||[]),h({...s,appId:a.id,appPath:""}),o(!1)}catch(a){f(a.message)}finally{S(!1),p(null),r.current&&(r.current.value="")}};return e.jsxs("div",{className:"mt-2 flex items-center gap-2 flex-wrap max-w-full min-w-0",children:[e.jsx("span",{title:"Mobile device target",className:"flex-shrink-0",children:e.jsx(M,{size:13,className:"text-indigo-400 dark:text-indigo-300"})}),e.jsx("div",{className:"flex-1 min-w-[13rem]",children:e.jsx(q,{devices:x,selectedId:$,onSelect:C,loading:v,disabled:j,errorText:N,placeholder:"Select a device…",emptyText:c==="local-appium"?G:void 0,variant:"compact"})}),e.jsxs("div",{className:"relative flex-1 min-w-[13rem]",children:[e.jsxs("button",{type:"button",disabled:j||d,onClick:()=>o(!y),title:`${D?D+`
3
-
4
- `:""}Shared app library — apps uploaded in AI Assistant / AI Record appear here. Uploads are cached by SHA-256, so repeat runs skip re-upload.`,className:"w-full h-8 flex items-center justify-between gap-1.5 px-2.5 text-xs rounded-lg bg-white dark:bg-white/[0.04] border border-gray-200 dark:border-white/10 text-gray-800 dark:text-gray-200 hover:border-gray-300 dark:hover:border-white/20 transition-colors disabled:opacity-50",children:[e.jsxs("span",{className:"flex items-center gap-1.5 truncate min-w-0",children:[e.jsx(X,{size:11,className:`flex-shrink-0 ${n?"text-indigo-500 dark:text-indigo-300":"text-gray-500"}`}),e.jsx("span",{className:`truncate ${n||s.appPath.trim()?"":"text-gray-500"}`,children:d?`Uploading… ${l!==null?Math.round(l*100)+"%":""}`:L})]}),d?e.jsx(U,{size:11,className:"animate-spin flex-shrink-0 text-gray-500"}):e.jsx(J,{size:11,className:"flex-shrink-0 text-gray-500"})]}),y&&!d&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>o(!1)}),e.jsxs("div",{className:"absolute top-full left-0 mt-1 w-full max-h-72 bg-surface-1 border border-white/10 rounded-lg shadow-xl z-40 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-1 overflow-y-auto py-1",children:[g&&e.jsx("div",{className:"px-3 py-2 text-xs text-red-300",children:g}),!g&&b.length===0&&e.jsx("div",{className:"px-3 py-2 text-xs text-gray-500",children:"No apps in the library yet — upload an .apk or .ipa below."}),b.map(t=>{const a=t.id===s.appId;return e.jsxs("button",{onClick:()=>I(t),title:`${t.label||t.filename}
5
- ${t.filename}
6
- ${t.kind==="ipa"?"iOS":"Android"} · ${(t.size/1024/1024).toFixed(1)} MB${t.uploadedAt?` · uploaded ${z(t.uploadedAt)}`:""}`,className:`w-full flex items-center justify-between gap-2 px-3 py-1.5 text-xs transition-colors ${a?"bg-indigo-500/15 text-indigo-200":"text-gray-300 hover:bg-white/5"}`,children:[e.jsxs("span",{className:"flex items-center gap-1.5 truncate",children:[a&&e.jsx(W,{size:11,className:"text-indigo-300 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:t.label||t.filename})]}),e.jsxs("span",{className:"text-[10px] text-gray-500 flex-shrink-0",children:[t.kind," · ",(t.size/1024/1024).toFixed(1)," MB"]})]},t.id)}),s.appId&&e.jsx("button",{onClick:R,className:"w-full text-left px-3 py-1.5 text-xs text-gray-500 hover:bg-white/5 border-t border-white/5",children:"Clear selection"})]}),e.jsxs("div",{className:"border-t border-white/10 px-2 py-1.5 bg-surface-1/50",children:[e.jsxs("button",{type:"button",onClick:t=>{var a;t.stopPropagation(),(a=r.current)==null||a.click()},className:"w-full flex items-center justify-center gap-1.5 px-2 py-1.5 text-[11px] rounded-md bg-indigo-500/10 text-indigo-300 hover:bg-indigo-500/20 transition-colors",children:[e.jsx(Y,{size:11})," ",e.jsx("span",{title:"Android: .apk or .aab · real iPhone / iPad: .ipa · iOS simulator: the .app zipped",children:"Upload app build"})]}),e.jsx("p",{className:"mt-1.5 px-1 text-[10px] text-gray-500 leading-relaxed",children:"Shared with AI Assistant + AI Record — apps uploaded there appear here. Uploads are cached by SHA-256, so repeat runs skip re-upload."})]})]})]})]}),e.jsx("input",{ref:r,type:"file",accept:".apk,.aab,.ipa,.zip,application/vnd.android.package-archive,application/zip,application/octet-stream",className:"hidden",onChange:t=>{var u;const a=(u=t.target.files)==null?void 0:u[0];a&&T(a)}})]})}export{ie as M,ae as R};
@@ -1 +0,0 @@
1
- import{j as e,r as l}from"./vendor-react-CTbHBddL.js";import{a as it,u as K}from"./vendor-query-BrzmPFT3.js";import{R as ot,Q as ct}from"./RunState-ifC4zi6M.js";import{a8 as dt,cL as xt,cM as mt,cN as ht,ck as ut,cO as pt,cP as Qe,cQ as gt,cR as bt,cS as yt,cT as ft,cU as Ze,cV as vt,cW as jt,cX as Nt,cY as wt,cZ as kt,c_ as Ct,c$ as St}from"./index-BYVxKLrT.js";import{C as Te}from"./ConfirmDialog-t7mpeeSN.js";import{u as It,T as De}from"./RunTargets-C7vpCbck.js";import{u as Tt,b as zt,a as Se}from"./useTabParam-ChbOedP1.js";import{G as Le,X as $e,a0 as Y,cm as He,as as Rt,b4 as Ye,o as Ae,aI as Ee,b6 as Et,b7 as Pt,a8 as Ge,aZ as $t,cE as ue,v as Fe,R as At,cF as Mt,_ as Je,b8 as Lt,cG as Ht,ag as Ie,ah as Oe}from"./vendor-icons-BKPiFyYV.js";const qt="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20128%20128'%3e%3cpath%20fill='%232088ff'%20d='M26.666%200C11.97%200%200%2011.97%200%2026.666c0%2012.87%209.181%2023.651%2021.334%2026.13v37.87c0%2011.77%209.68%2021.334%2021.332%2021.334h.195c1.302%209.023%209.1%2016%2018.473%2016C71.612%20128%2080%20119.612%2080%20109.334s-8.388-18.668-18.666-18.668c-9.372%200-17.17%206.977-18.473%2016h-.195c-8.737%200-16-7.152-16-16V63.779a18.514%2018.514%200%200%200%2013.24%205.555h2.955c1.303%209.023%209.1%2016%2018.473%2016%209.372%200%2017.169-6.977%2018.47-16h11.057c1.303%209.023%209.1%2016%2018.473%2016%2010.278%200%2018.666-8.39%2018.666-18.668C128%2056.388%20119.612%2048%20109.334%2048c-9.373%200-17.171%206.977-18.473%2016H79.805c-1.301-9.023-9.098-16-18.471-16s-17.171%206.977-18.473%2016h-2.955c-6.433%200-11.793-4.589-12.988-10.672%2014.58-.136%2026.416-12.05%2026.416-26.662C53.334%2011.97%2041.362%200%2026.666%200zm0%205.334A21.292%2021.292%200%200%201%2048%2026.666%2021.294%2021.294%200%200%201%2026.666%2048%2021.292%2021.292%200%200%201%205.334%2026.666%2021.29%2021.29%200%200%201%2026.666%205.334zm-5.215%207.541C18.67%2012.889%2016%2015.123%2016%2018.166v17.043c0%204.043%204.709%206.663%208.145%204.533l13.634-8.455c3.257-2.02%203.274-7.002.032-9.045l-13.635-8.59a5.024%205.024%200%200%200-2.725-.777zm-.117%205.291%2013.635%208.588-13.635%208.455V18.166zm40%2035.168a13.29%2013.29%200%200%201%2013.332%2013.332A13.293%2013.293%200%200%201%2061.334%2080%2013.294%2013.294%200%200%201%2048%2066.666a13.293%2013.293%200%200%201%2013.334-13.332zm48%200a13.29%2013.29%200%200%201%2013.332%2013.332A13.293%2013.293%200%200%201%20109.334%2080%2013.294%2013.294%200%200%201%2096%2066.666a13.293%2013.293%200%200%201%2013.334-13.332zm-42.568%206.951a2.667%202.667%200%200%200-1.887.78l-6.3%206.294-2.093-2.084a2.667%202.667%200%200%200-3.771.006%202.667%202.667%200%200%200%20.008%203.772l3.974%203.96a2.667%202.667%200%200%200%203.766-.001l8.185-8.174a2.667%202.667%200%200%200%20.002-3.772%202.667%202.667%200%200%200-1.884-.78zm48%200a2.667%202.667%200%200%200-1.887.78l-6.3%206.294-2.093-2.084a2.667%202.667%200%200%200-3.771.006%202.667%202.667%200%200%200%20.008%203.772l3.974%203.96a2.667%202.667%200%200%200%203.766-.001l8.185-8.174a2.667%202.667%200%200%200%20.002-3.772%202.667%202.667%200%200%200-1.884-.78zM61.334%2096a13.293%2013.293%200%200%201%2013.332%2013.334%2013.29%2013.29%200%200%201-13.332%2013.332A13.293%2013.293%200%200%201%2048%20109.334%2013.294%2013.294%200%200%201%2061.334%2096zM56%20105.334c-2.193%200-4%201.807-4%204%200%202.195%201.808%204%204%204s4-1.805%204-4c0-2.193-1.807-4-4-4zm10.666%200c-2.193%200-4%201.807-4%204%200%202.195%201.808%204%204%204s4-1.805%204-4c0-2.193-1.807-4-4-4zM56%20108c.75%200%201.334.585%201.334%201.334%200%20.753-.583%201.332-1.334%201.332-.75%200-1.334-.58-1.334-1.332%200-.75.585-1.334%201.334-1.334zm10.666%200c.75%200%201.334.585%201.334%201.334%200%20.753-.583%201.332-1.334%201.332-.75%200-1.332-.58-1.332-1.332%200-.75.583-1.334%201.332-1.334z'/%3e%3cpath%20fill='%2379b8ff'%20d='M109.334%2090.666c-9.383%200-17.188%206.993-18.477%2016.031a2.667%202.667%200%200%200-.265-.011l-2.7.09a2.667%202.667%200%200%200-2.578%202.751%202.667%202.667%200%200%200%202.752%202.578l2.7-.087a2.667%202.667%200%200%200%20.097-.006C92.17%20121.029%2099.965%20128%20109.334%20128c10.278%200%2018.666-8.388%2018.666-18.666s-8.388-18.668-18.666-18.668zm0%205.334a13.293%2013.293%200%200%201%2013.332%2013.334%2013.29%2013.29%200%200%201-13.332%2013.332A13.293%2013.293%200%200%201%2096%20109.334%2013.294%2013.294%200%200%201%20109.334%2096z'/%3e%3c/svg%3e",Ft="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20128%20128'%20xml:space='preserve'%3e%3cpath%20fill='%23E24329'%20d='m124.755%2051.382-.177-.452L107.47%206.282a4.459%204.459%200%200%200-1.761-2.121%204.581%204.581%200%200%200-5.236.281%204.578%204.578%200%200%200-1.518%202.304L87.404%2042.088H40.629L29.077%206.746a4.492%204.492%200%200%200-1.518-2.31%204.581%204.581%200%200%200-5.236-.281%204.502%204.502%200%200%200-1.761%202.121L3.422%2050.904l-.17.452c-5.059%2013.219-.763%2028.192%2010.537%2036.716l.059.046.157.111%2026.061%2019.516%2012.893%209.758%207.854%205.93a5.283%205.283%200%200%200%206.388%200l7.854-5.93%2012.893-9.758%2026.218-19.634.065-.052c11.273-8.526%2015.562-23.472%2010.524-36.677z'/%3e%3cpath%20fill='%23FC6D26'%20d='m124.755%2051.382-.177-.452a57.79%2057.79%200%200%200-23.005%2010.341L64%2089.682c12.795%209.68%2023.934%2018.09%2023.934%2018.09l26.218-19.634.065-.052c11.291-8.527%2015.586-23.488%2010.538-36.704z'/%3e%3cpath%20fill='%23FCA326'%20d='m40.066%20107.771%2012.893%209.758%207.854%205.93a5.283%205.283%200%200%200%206.388%200l7.854-5.93%2012.893-9.758s-11.152-8.436-23.947-18.09a18379.202%2018379.202%200%200%200-23.935%2018.09z'/%3e%3cpath%20fill='%23FC6D26'%20d='M26.42%2061.271A57.73%2057.73%200%200%200%203.422%2050.904l-.17.452c-5.059%2013.219-.763%2028.192%2010.537%2036.716l.059.046.157.111%2026.061%2019.516L64%2089.655%2026.42%2061.271z'/%3e%3c/svg%3e",Ot="/assets/jenkins-CWiA3Rta.svg",Bt="data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='utf-8'?%3e%3c!--%20Uploaded%20to:%20SVG%20Repo,%20www.svgrepo.com,%20Generator:%20SVG%20Repo%20Mixer%20Tools%20--%3e%3csvg%20width='800px'%20height='800px'%20viewBox='0%200%2032%2032'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3cdefs%3e%3cmask%20id='a'%20x='1.455'%20y='1.455'%20width='29.091'%20height='29.091'%20maskUnits='userSpaceOnUse'%3e%3cpath%20d='M5.7,20.974l1.464-1.565,1.819,1.819L7.5,22.707,9.293,24.5l1.479-1.479L12.6,24.852,11.151,26.3l4.242,4.242h6.667a1.212,1.212,0,0,0,1.212-1.212v-9.7l6.195-4.129a2.425,2.425,0,0,0,1.078-2.016V2.667a1.212,1.212,0,0,0-1.212-1.212H18.509a2.425,2.425,0,0,0-2.016,1.078L12.364,8.727h-9.7A1.212,1.212,0,0,0,1.455,9.94v6.666Z'%20style='fill:%23fff'/%3e%3cpath%20d='M3.636,23.273H1.455v7.273H8.727V28.364H3.636Z'%20style='fill:%23fff'/%3e%3c/mask%3e%3clinearGradient%20id='b'%20x1='0.069'%20y1='31.569'%20x2='1.069'%20y2='31.569'%20gradientTransform='matrix(0,%2029.091,%2029.091,%200,%20-902.364,%20-0.545)'%20gradientUnits='userSpaceOnUse'%3e%3cstop%20offset='0'%20stop-color='%23ffffff'/%3e%3cstop%20offset='1'%20stop-color='%23ffffff'%20stop-opacity='0'/%3e%3c/linearGradient%3e%3clinearGradient%20id='c'%20x1='0.069'%20y1='31.194'%20x2='1.069'%20y2='31.194'%20xlink:href='%23b'/%3e%3c/defs%3e%3ctitle%3efile_type_azurepipelines%3c/title%3e%3cg%20style='mask:url(%23a)'%3e%3cpath%20d='M1.455,23.273H3.636v5.091H8.727v2.182H1.455Z'%20style='fill:%2391b0f2'/%3e%3cpath%20d='M1.455,9.939v6.667L5.7,20.974,7.515,19.03l5.455,5.455L11.151,26.3l4.242,4.242h6.667a1.212,1.212,0,0,0,1.212-1.212v-9.7L12.364,8.727h-9.7A1.212,1.212,0,0,0,1.455,9.939Z'%20style='fill:%230f46bd'/%3e%3cpath%20d='M6,18.249,17.212,1.455H30.545V14.788L13.751,26Z'%20style='fill:%23062aa9'/%3e%3cpath%20d='M6.7,18.952a1.212,1.212,0,0,1-.151-1.53l9.94-14.889a2.424,2.424,0,0,1,2.016-1.078H29.333a1.212,1.212,0,0,1,1.212,1.212V13.492a2.424,2.424,0,0,1-1.078,2.016l-14.889,9.94a1.212,1.212,0,0,1-1.53-.151Z'%20style='fill:%232560e0'/%3e%3cpath%20d='M7.5,22.707l9.255-9.255,1.792,1.792L9.293,24.5Z'%20style='fill:%230a44c2'/%3e%3cpath%20d='M7.5,22.707l9.255-9.255,1.792,1.792L9.293,24.5Z'%20style='fill:%23729af2'/%3e%3cpath%20d='M10.772,23.02,8.98,21.228l7.776-7.775,1.792,1.792Z'%20style='fill:%234c80f0'/%3e%3cpath%20d='M23.273,12.364a3.636,3.636,0,1,0-3.636-3.636A3.636,3.636,0,0,0,23.273,12.364Z'%20style='fill:%230a44c2'/%3e%3cpath%20d='M23.273,12.364a3.636,3.636,0,1,0-3.636-3.636A3.636,3.636,0,0,0,23.273,12.364Z'%20style='fill:%2391b0f2'/%3e%3cg%20style='opacity:0.20000000298023224'%3e%3cpath%20d='M5.7,20.974l1.464-1.565,1.819,1.819L7.5,22.707,9.293,24.5l1.479-1.479L12.6,24.852,11.151,26.3l4.242,4.242h6.667a1.212,1.212,0,0,0,1.212-1.212v-9.7l6.195-4.129a2.425,2.425,0,0,0,1.078-2.016V2.667a1.212,1.212,0,0,0-1.212-1.212H18.509a2.425,2.425,0,0,0-2.016,1.078L12.364,8.727h-9.7A1.212,1.212,0,0,0,1.455,9.94v6.666Z'%20style='fill:url(%23b)'/%3e%3cpath%20d='M3.636,23.273H1.455v7.273H8.727V28.364H3.636Z'%20style='fill:url(%23c)'/%3e%3c/g%3e%3c/g%3e%3c/svg%3e",_t="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20128%20128'%3e%3cdefs%3e%3clinearGradient%20id='bitbucket-original-a'%20gradientUnits='userSpaceOnUse'%20x1='28.593'%20y1='14.226'%20x2='16.672'%20y2='23.532'%20gradientTransform='scale(4)'%3e%3cstop%20offset='.176'%20stop-color='%230052cc'/%3e%3cstop%20offset='1'%20stop-color='%232684ff'/%3e%3c/linearGradient%3e%3c/defs%3e%3cpath%20d='M19.082%2020c-1.918%200-3.355%201.758-3.039%203.516l12.95%2079.289c.32%202.078%202.077%203.515%204.155%203.515h62.66c1.442%200%202.72-1.12%203.04-2.558l13.109-80.086c.316-1.918-1.121-3.516-3.039-3.516zM74.07%2077.227H54.09l-5.278-28.293h30.215zm0%200'%20fill='%232684ff'/%3e%3cpath%20d='M107.64%2048.934H78.868L74.07%2077.227H54.09l-23.5%2027.972s1.12.961%202.719.961h62.66c1.441%200%202.719-1.12%203.039-2.558zm0%200'%20fill='url(%23bitbucket-original-a)'/%3e%3c/svg%3e",Ut="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20128%20128'%3e%3cpath%20fill='%23343434'%20d='M47.809%2064c0-8.45%206.847-15.23%2015.23-15.23%208.387%200%2015.234%206.847%2015.234%2015.23S71.426%2079.23%2063.04%2079.23c-8.383%200-15.23-6.847-15.23-15.23zm15.23-64C33.152%200%208.13%2020.48%201.023%2048.129c-.062.191-.062.383-.062.64a3.07%203.07%200%20003.07%203.07h25.793c1.215%200%202.305-.702%202.75-1.792%205.313-11.52%2016.961-19.582%2030.465-19.582%2018.496%200%2033.535%2015.039%2033.535%2033.535%200%2018.496-15.039%2033.535-33.535%2033.535-13.504%200-25.152-8-30.465-19.582-.511-1.023-1.535-1.793-2.75-1.793H4.031a3.07%203.07%200%2000-3.07%203.07c0%20.196.062.387.062.641C8.063%20107.52%2033.153%20128%2063.04%20128c35.328%200%2064-28.672%2064-64s-28.672-64-64-64zm0%200'/%3e%3c/svg%3e",Dt={"github-actions":qt,"gitlab-ci":Ft,jenkins:Ot,"azure-pipelines":Bt,bitbucket:_t,circleci:Ut},Gt={circleci:!0};function Kt({platform:s,size:i=16,className:n=""}){const a=Dt[s];return a?e.jsx("img",{src:a,alt:"","aria-hidden":"true",width:i,height:i,style:{width:i,height:i},className:`flex-shrink-0 object-contain ${Gt[s]?"dark:invert":""} ${n}`}):null}async function Xe(s){var i;try{if((i=navigator.clipboard)!=null&&i.writeText)return await navigator.clipboard.writeText(s),!0}catch{}try{const n=document.createElement("textarea");n.value=s,n.setAttribute("readonly",""),n.style.position="fixed",n.style.opacity="0",document.body.appendChild(n),n.select();const a=document.execCommand("copy");return document.body.removeChild(n),a}catch{return!1}}const Pe={queued:"bg-amber-500/10 border-amber-500/30 text-amber-300",running:"bg-blue-500/10 border-blue-500/30 text-blue-300",passed:"bg-emerald-500/10 border-emerald-500/30 text-emerald-300",failed:"bg-red-500/10 border-red-500/30 text-red-300",cancelled:"bg-white/5 border-white/10 text-gray-400",error:"bg-red-500/10 border-red-500/30 text-red-300"},et={command:"Command",suite:"Suite",cycle:"Cycle"};function V(s){if(!s)return"—";const i=Date.now()-new Date(s).getTime(),n=Math.floor(i/6e4);if(n<1)return"just now";if(n<60)return`${n}m ago`;const a=Math.floor(n/60);return a<24?`${a}h ago`:`${Math.floor(a/24)}d ago`}function tt(s){if(!s)return"";const i=new Date(s).getTime()-Date.now();if(i<=0)return"expired";const n=i/864e5;return n>=1?`expires in ${Math.round(n)}d`:`expires in ${Math.max(1,Math.floor(i/36e5))}h`}function pe(s){if(!s||s<=0)return"—";const i=Math.round(s/1e3);if(i<60)return`${i}s`;const n=Math.floor(i/60);return n<60?`${n}m ${i%60}s`:`${Math.floor(n/60)}h ${n%60}m`}function st(s){return s>=90?"text-emerald-400":s>=70?"text-amber-400":"text-red-400"}function at(s){let i;try{i=new URL(s)}catch{return"Enter a full address, e.g. https://testver.example.com"}return/^https?:$/.test(i.protocol)?/^(localhost|127\.|0\.0\.0\.0|\[?::1\]?)/i.test(i.hostname)?"This is a local address — CI runners in the cloud cannot reach it. Use the address your CI runners reach this server at.":i.protocol==="http:"?"Plain http — the CI token travels unencrypted. Use https when CI reaches this server over the internet.":null:"Use an http(s) address"}function Be(s){const i=l.useRef(s);i.current=s,l.useEffect(()=>{const n=a=>{a.key==="Escape"&&i.current()};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[])}function Re({what:s,error:i,onRetry:n}){return e.jsxs("div",{role:"alert",className:"px-4 py-3 rounded-xl bg-red-500/10 border border-red-500/30 text-sm text-red-300 flex items-center gap-3",children:[e.jsx(Ae,{size:15,className:"flex-shrink-0"}),e.jsxs("span",{className:"flex-1",children:["Could not load ",s,": ",(i==null?void 0:i.message)||String(i)]}),e.jsxs("button",{onClick:n,className:"flex items-center gap-1 px-2.5 py-1 rounded-lg border border-red-500/30 hover:bg-red-500/10 text-xs font-medium",children:[e.jsx(At,{size:12})," Retry"]})]})}function rt({message:s,onDismiss:i}){return s?e.jsxs("div",{role:"alert",className:"mb-4 px-3 py-2.5 rounded-xl bg-red-500/10 border border-red-500/30 text-sm text-red-300 flex items-start gap-2",children:[e.jsx(Ae,{size:15,className:"flex-shrink-0 mt-0.5"}),e.jsx("span",{className:"flex-1",children:s}),e.jsx("button",{onClick:i,"aria-label":"Dismiss error",className:"text-red-300 hover:text-red-200",children:e.jsx($e,{size:14})})]}):null}function ls(){var je,ie,Ne,we;const s=it(),{hasRole:i}=dt(),n=i("tester"),a=i("admin"),[o,w]=Tt("tab",["dashboard","pipelines","ci-runs","tokens","trace"],"dashboard"),x=zt(),N=K({queryKey:["ci-pipelines"],queryFn:xt}),g=K({queryKey:["ci-tokens"],queryFn:mt}),v=K({queryKey:["ci-runs"],queryFn:()=>ht(200),refetchInterval:t=>{var u;return(((u=t.state.data)==null?void 0:u.runs)||[]).some(f=>f.state==="running"||f.state==="queued")?1e4:3e4}}),{data:b}=K({queryKey:["suites"],queryFn:ut}),c=K({queryKey:["ci-analytics"],queryFn:pt,refetchInterval:3e4}),d=c.data,j=((je=N.data)==null?void 0:je.pipelines)||[],P=((ie=g.data)==null?void 0:ie.tokens)||[],F=P.filter(t=>!t.revoked),$=P.filter(t=>t.revoked),S=((Ne=v.data)==null?void 0:Ne.runs)||[],O=(b==null?void 0:b.suites)||[],h=[...new Set(j.filter(t=>t.target.type==="cycle"&&t.target.cycleId).map(t=>t.target.cycleId))],{data:R}=K({queryKey:["ci-cycle-names",h.join(",")],enabled:h.length>0,queryFn:async()=>{const t=await Promise.all(h.map(async u=>{try{const f=await Qe(u);return[u,{name:f==null?void 0:f.name,planId:f==null?void 0:f.planId}]}catch{return[u,null]}}));return Object.fromEntries(t)}}),[A]=Se("state"),[k]=Se("pipeline"),[B]=Se("branch"),[M]=Se("env"),L=S.filter(t=>(!A||t.state===A)&&(!k||t.mappingName===k)&&(!B||(t.branch||"").toLowerCase().includes(B.toLowerCase()))&&(!M||(t.environment||"").toLowerCase()===M.toLowerCase())),_=!!(A||k||B||M),ce=()=>x({state:null,pipeline:null,branch:null,env:null}),[se,I]=l.useState(0),[z,ae]=l.useState(20);l.useEffect(()=>{I(0)},[A,k,B,M]);const E=Math.max(1,Math.ceil(L.length/z)),T=Math.min(se,E-1),re=L.slice(T*z,(T+1)*z),[ne,G]=l.useState(null),[W,m]=l.useState(null),[y,J]=l.useState(null),[ge,le]=l.useState(null),[Q,de]=l.useState(null),[X,p]=l.useState(null),[be,ye]=l.useState(!1),[fe,U]=l.useState(null),[Me,ee]=l.useState(null),ve=t=>{var u;return(u=O.find(f=>f.id===t))==null?void 0:u.name},Z=()=>{s.invalidateQueries({queryKey:["ci-pipelines"]}),s.invalidateQueries({queryKey:["ci-tokens"]}),s.invalidateQueries({queryKey:["ci-runs"]}),s.invalidateQueries({queryKey:["ci-analytics"]})},ze=async t=>{try{await Ze({...t,enabled:!t.enabled}),Z()}catch(u){U((u==null?void 0:u.message)||String(u))}},q=[{id:"dashboard",label:"Dashboard",icon:e.jsx(He,{size:15})},{id:"pipelines",label:"Pipelines",icon:e.jsx(Le,{size:15})},{id:"tokens",label:"CI Tokens",icon:e.jsx(Ge,{size:15})},{id:"ci-runs",label:"CI Runs",icon:e.jsx(ue,{size:15})},{id:"trace",label:"Trace",icon:e.jsx(Fe,{size:15})}];return e.jsxs("div",{className:"h-full flex flex-col bg-surface-0 text-gray-200 animate-fade-in",children:[e.jsx("div",{className:"border-b border-white/5 bg-surface-1",children:e.jsxs("div",{className:"max-w-[1400px] mx-auto w-full px-6 py-6",children:[e.jsxs("h1",{className:"text-2xl font-bold text-gray-100 flex items-center gap-3",children:[e.jsx(Le,{size:24,className:"text-brand-300"}),"CI/CD Pipelines"]}),e.jsx("p",{className:"text-sm text-gray-400 mt-1",children:"Your CI/CD pipelines trigger test runs that execute on this Testver server and gate the build on the verdict"})]})}),e.jsx("div",{className:"border-b border-white/5 bg-surface-1",children:e.jsx("div",{role:"tablist","aria-label":"CI/CD Pipelines sections",className:"max-w-[1400px] mx-auto w-full px-6 flex gap-1",children:q.map(t=>e.jsxs("button",{role:"tab","aria-selected":o===t.id,onClick:()=>w(t.id),className:`flex items-center gap-2 px-4 py-3 text-sm font-medium border-b-2 transition-colors ${o===t.id?"border-brand-400 text-brand-300":"border-transparent text-gray-400 hover:text-gray-200 hover:border-white/10"}`,children:[t.icon,t.label]},t.id))})}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:e.jsxs("div",{className:"max-w-[1400px] mx-auto w-full px-6 py-6 space-y-8",children:[fe&&e.jsxs("div",{role:"alert",className:"px-4 py-3 rounded-xl bg-red-500/10 border border-red-500/30 text-sm text-red-300 flex items-center justify-between",children:[e.jsx("span",{children:fe}),e.jsx("button",{onClick:()=>U(null),"aria-label":"Dismiss error",className:"text-red-300 hover:text-red-200",children:e.jsx($e,{size:14})})]}),o==="pipelines"&&e.jsxs("div",{className:"px-4 py-3 rounded-xl bg-brand-500/10 border border-brand-500/25 text-sm text-gray-300",children:[e.jsx("b",{className:"text-brand-300",children:"Delegated execution:"})," CI pipelines trigger runs that execute ",e.jsx("b",{children:"on this Testver server"}),", then gate the build on the verdict. Map a pipeline to a suite, cycle, or command, create a CI token, and wire your workflow — from CI or any terminal via"," ",e.jsx("code",{className:"text-brand-300",children:"testver trigger"}),"."]}),o==="dashboard"&&c.isLoading&&e.jsxs("div",{className:"py-12 text-center text-gray-500 text-sm",children:[e.jsx(Y,{size:16,className:"animate-spin inline mr-2"}),"Loading the dashboard…"]}),o==="dashboard"&&c.isError&&e.jsx(Re,{what:"the CI dashboard",error:c.error,onRetry:()=>c.refetch()}),o==="dashboard"&&d&&d.totals.runs===0&&e.jsxs("div",{className:"py-16 text-center rounded-xl border border-dashed border-white/10",children:[e.jsx(He,{size:32,className:"mx-auto text-gray-600 mb-3"}),e.jsx("p",{className:"text-base font-medium text-gray-300 mb-1",children:"No CI runs yet"}),e.jsx("p",{className:"text-sm text-gray-500 max-w-md mx-auto mb-4",children:"Create a pipeline mapping and a CI token, then trigger a run from your pipeline or any terminal. The dashboard lights up with pass rates, trends, and insights from the first run."}),e.jsx("button",{onClick:()=>w("pipelines"),className:"px-4 py-2 rounded-xl text-sm font-medium bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:"Set up a Pipeline →"})]}),o==="dashboard"&&d&&d.totals.runs>0&&e.jsxs("section",{children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-100 flex items-center gap-2 mb-3",children:[e.jsx(He,{size:17,className:"text-emerald-300"})," Overview"]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 mb-3",children:[e.jsxs("div",{className:"px-4 py-3 rounded-xl bg-surface-1 border border-white/5",children:[e.jsx("div",{className:"text-xs text-gray-500 uppercase tracking-wide",children:"CI Runs"}),e.jsx("div",{className:"text-xl font-semibold text-gray-100 mt-0.5",children:d.totals.runs})]}),e.jsxs("div",{className:"px-4 py-3 rounded-xl bg-surface-1 border border-white/5",title:"Passed ÷ (passed + failed + errored). A run that errored — lost, timed out or ran no tests — counts against it; cancelled runs don't count.",children:[e.jsx("div",{className:"text-xs text-gray-500 uppercase tracking-wide",children:"Pass Rate"}),e.jsxs("div",{className:`text-xl font-semibold mt-0.5 ${st(d.totals.passRate)}`,children:[d.totals.passRate,"%"]}),(d.totals.errored||0)>0&&e.jsxs("div",{className:"text-xs text-gray-500 mt-0.5",children:[d.totals.errored," errored"]})]}),e.jsxs("div",{className:"px-4 py-3 rounded-xl bg-surface-1 border border-white/5",children:[e.jsxs("div",{className:"text-xs text-gray-500 uppercase tracking-wide flex items-center gap-1",children:[e.jsx(Rt,{size:11})," Avg Duration"]}),e.jsx("div",{className:"text-xl font-semibold text-gray-100 mt-0.5",children:pe(d.totals.avgDurationMs)})]}),e.jsxs("div",{className:"px-4 py-3 rounded-xl bg-surface-1 border border-white/5",children:[e.jsx("div",{className:"text-xs text-gray-500 uppercase tracking-wide",children:"Active / Queued"}),e.jsx("div",{className:`text-xl font-semibold mt-0.5 ${d.totals.active>0?"text-blue-300":"text-gray-100"}`,children:d.totals.active})]})]}),d.trend.length>1&&e.jsxs("div",{className:"px-4 py-3 rounded-xl bg-surface-1 border border-white/5",children:[e.jsx("div",{className:"text-xs text-gray-500 uppercase tracking-wide mb-2",children:"Recent verdicts (oldest → newest)"}),e.jsx("div",{className:"flex items-end gap-1 h-14",role:"list","aria-label":"Recent CI verdicts",children:d.trend.map((t,u)=>{const f=d.trend.length,xe=Math.max(...d.trend.map(H=>H.durationMs||0),1),te=30+Math.round((t.durationMs||0)/xe*70),oe=t.state==="passed"?"bg-emerald-400/70":t.state==="error"?"bg-amber-400/80":"bg-red-400/80",D=u<f/4?"left-0":u>3*f/4?"right-0":"left-1/2 -translate-x-1/2",ke=`${t.mapping||"CI run"}: ${t.state}${t.summary?`, ${t.summary.passed} of ${t.summary.total} passed`:""}, ${V(t.at)}`,Ce=`block w-full rounded-sm transition-opacity hover:opacity-80 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-400 ${oe}`;return e.jsxs("div",{role:"listitem",className:"relative flex-1 max-w-[14px] h-full flex items-end",onMouseEnter:()=>ee(u),onMouseLeave:()=>ee(H=>H===u?null:H),children:[t.runId?e.jsx("a",{href:`/results?runId=${encodeURIComponent(t.runId)}`,target:"_blank",rel:"noopener noreferrer","aria-label":`${ke} — open the report`,onFocus:()=>ee(u),onBlur:()=>ee(H=>H===u?null:H),className:Ce,style:{height:`${te}%`}}):e.jsx("span",{tabIndex:0,"aria-label":ke,onFocus:()=>ee(u),onBlur:()=>ee(H=>H===u?null:H),className:Ce,style:{height:`${te}%`}}),Me===u&&e.jsxs("div",{className:`absolute bottom-full mb-2 ${D} z-50 pointer-events-none w-64 rounded-xl bg-surface-1 border border-white/10 shadow-xl shadow-black/30 p-3.5 text-left`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2.5",children:[e.jsx("span",{className:"text-sm font-semibold text-gray-100 truncate",children:t.mapping||"CI run"}),e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full border flex-shrink-0 ${Pe[t.state]||Pe.failed}`,children:t.state})]}),e.jsxs("div",{className:"space-y-1.5 text-xs",children:[t.branch&&e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{className:"text-gray-500",children:"Branch"}),e.jsx("span",{className:"text-gray-200 truncate",children:t.branch})]}),t.summary&&e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{className:"text-gray-500",children:"Result"}),e.jsxs("span",{className:"text-gray-200",children:[e.jsx("span",{className:"text-emerald-400",children:t.summary.passed})," / ",t.summary.total," passed",t.summary.failed>0&&e.jsxs("span",{className:"text-red-400",children:[" · ",t.summary.failed," failed"]})]})]}),t.error&&e.jsx("div",{className:"text-amber-300 line-clamp-2",children:t.error}),e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{className:"text-gray-500",children:"Duration"}),e.jsx("span",{className:"text-gray-200",children:pe(t.durationMs)})]}),e.jsxs("div",{className:"flex justify-between gap-3",children:[e.jsx("span",{className:"text-gray-500",children:"When"}),e.jsxs("span",{className:"text-gray-200",children:[V(t.at)," · ",new Date(t.at).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})]})]})]}),t.runId&&e.jsx("div",{className:"mt-2.5 pt-2 border-t border-white/10 text-xs text-brand-300",children:"Click the bar to open the full report →"})]})]},t.ciRunId)})})]})]}),o==="pipelines"&&e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-100 flex items-center gap-2",children:[e.jsx(Le,{size:17,className:"text-brand-300"})," Pipeline Mappings"]}),n&&e.jsxs("button",{onClick:()=>G({enabled:!0,target:{type:"suite"}}),className:"flex items-center gap-1.5 px-3.5 py-2 rounded-xl text-sm font-medium bg-brand-600 hover:bg-brand-500 text-white transition-colors",children:[e.jsx(Ye,{size:14})," New Mapping"]})]}),N.isError?e.jsx(Re,{what:"pipeline mappings",error:N.error,onRetry:()=>N.refetch()}):N.isLoading?e.jsxs("div",{className:"py-8 text-center text-gray-500 text-sm",children:[e.jsx(Y,{size:16,className:"animate-spin inline mr-2"}),"Loading…"]}):j.length===0?e.jsxs("div",{className:"py-10 text-center rounded-xl border border-dashed border-white/10 text-sm text-gray-500",children:["No pipeline mappings yet — ",n?"create one to let CI (or the CLI) trigger runs on this server.":"a tester or admin can create one."]}):e.jsx("div",{className:"space-y-2",children:j.map(t=>{var te,me,oe;const u=t.target.type==="suite"?ve(t.target.suiteId):void 0,f=t.target.type==="cycle"&&t.target.cycleId?R==null?void 0:R[t.target.cycleId]:void 0,xe=t.target.type==="suite"&&O.length>0&&!u||t.target.type==="cycle"&&f===null;return e.jsxs("div",{className:`flex items-center gap-3 px-4 py-3 rounded-xl bg-surface-1 border border-white/5 ${t.enabled?"":"opacity-60"}`,children:[e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-brand-500/15 text-brand-300 border border-brand-500/25 flex-shrink-0",children:et[t.target.type]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-medium text-gray-200",children:t.name}),!t.enabled&&e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-white/5 text-gray-500",children:"disabled"}),t.previousNames&&t.previousNames.length>0&&e.jsxs("span",{className:"text-xs text-gray-500",title:"CI files that still use an old name keep triggering this mapping",children:["also answers to ",t.previousNames.map(D=>`"${D}"`).join(", "),n&&e.jsx("button",{onClick:async()=>{try{await gt(t.id),Z()}catch(D){U((D==null?void 0:D.message)||String(D))}},className:"ml-1.5 text-brand-300 hover:text-brand-200 underline-offset-2 hover:underline",children:"Forget old names"})]})]}),e.jsxs("div",{className:"text-sm text-gray-400 truncate",children:[t.target.type==="command"&&e.jsx("code",{children:t.target.command}),t.target.type==="suite"&&e.jsxs(e.Fragment,{children:["→ ",u||e.jsx("code",{children:t.target.suiteId})]}),t.target.type==="cycle"&&e.jsxs(e.Fragment,{children:["→ ",f!=null&&f.name?`Cycle "${f.name}"`:e.jsxs(e.Fragment,{children:["Cycle ",e.jsx("code",{children:t.target.cycleId})]})]}),xe&&e.jsxs("span",{className:"ml-2 text-amber-400",children:[e.jsx(Ae,{size:12,className:"inline -mt-0.5"})," no longer exists — triggers will fail"]}),((te=t.overrides)==null?void 0:te.environment)&&e.jsxs("span",{className:"ml-2",children:["env: ",t.overrides.environment]}),((me=t.overrides)==null?void 0:me.browser)&&e.jsxs("span",{className:"ml-2",children:["browser: ",t.overrides.browser]}),((oe=t.statusPush)==null?void 0:oe.enabled)&&e.jsxs("span",{className:"ml-2 text-brand-400/80",children:["PR status → ",t.statusPush.provider]}),e.jsxs("span",{className:"ml-2",children:["· last triggered ",V(t.lastTriggeredAt)]})]})]}),n&&e.jsx("button",{onClick:()=>void ze(t),role:"switch","aria-checked":t.enabled,"aria-label":`${t.enabled?"Disable":"Enable"} ${t.name}`,title:t.enabled?"Enabled — click to disable":"Disabled — click to enable",className:`relative w-9 h-5 rounded-full transition-colors flex-shrink-0 ${t.enabled?"bg-brand-500":"bg-surface-3 border border-white/10"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform ${t.enabled?"translate-x-4":""}`})}),n&&e.jsx("button",{onClick:()=>J(t),title:"Get pipeline config + CLI snippet","aria-label":`Wire ${t.name} into CI`,className:"p-2 rounded-lg text-gray-400 hover:text-brand-300 hover:bg-white/5 transition-colors",children:e.jsx(Ee,{size:15})}),n&&e.jsx("button",{onClick:()=>G(t),title:"Edit","aria-label":`Edit ${t.name}`,className:"p-2 rounded-lg text-gray-400 hover:text-gray-200 hover:bg-white/5 transition-colors",children:e.jsx(Et,{size:15})}),n&&e.jsx("button",{onClick:()=>m(t),title:"Delete","aria-label":`Delete ${t.name}`,className:"p-2 rounded-lg text-gray-400 hover:text-red-300 hover:bg-white/5 transition-colors",children:e.jsx(Pt,{size:15})})]},t.id)})})]}),o==="tokens"&&e.jsxs("section",{children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-100 flex items-center gap-2 mb-1",children:[e.jsx(Ge,{size:17,className:"text-amber-300"})," CI Tokens"]}),e.jsxs("p",{className:"text-sm text-gray-400 mb-3",children:["Machine tokens for the Gate API. Store one as ",e.jsx("code",{children:"TESTVER_CI_TOKEN"})," in your CI platform's secrets. The value is shown ",e.jsx("b",{children:"once"})," at creation. A token triggers only the pipeline mappings it is scoped to — ad-hoc suites, cycles and commands need a token that allows them."]}),a?e.jsx(Vt,{pipelines:j,onCreated:t=>{le(t),Z()}}):e.jsx("p",{className:"text-sm text-gray-500 mb-3 px-3 py-2 rounded-lg bg-surface-2 border border-white/5",children:"Only admins can create or revoke CI tokens."}),g.isError?e.jsx(Re,{what:"CI tokens",error:g.error,onRetry:()=>g.refetch()}):g.isLoading?e.jsxs("div",{className:"py-6 text-center text-gray-500 text-sm",children:[e.jsx(Y,{size:16,className:"animate-spin inline mr-2"}),"Loading…"]}):F.length===0?e.jsxs("div",{className:"py-8 text-center rounded-xl border border-dashed border-white/10 text-sm text-gray-500",children:["No active CI tokens.",a?" Create one above, then add it to your CI platform's secrets.":""]}):e.jsx("div",{className:"space-y-1.5",children:F.map(t=>e.jsx(Ke,{token:t,pipelines:j,onRevoke:a?()=>de({id:t.id,name:t.name}):void 0},t.id))}),$.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("button",{onClick:()=>ye(t=>!t),"aria-expanded":be,className:"text-sm text-gray-500 hover:text-gray-300",children:[be?"▾":"▸"," Revoked tokens (",$.length,")"]}),be&&e.jsx("div",{className:"space-y-1.5 mt-2",children:$.map(t=>e.jsx(Ke,{token:t,pipelines:j},t.id))})]})]}),o==="dashboard"&&d&&(d.perPipeline.length>0||d.perBranch.length>0)&&e.jsxs("section",{children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-100 flex items-center gap-2 mb-3",children:[e.jsx($t,{size:17,className:"text-purple-300"})," Insights"]}),e.jsx("p",{className:"text-sm text-gray-500 -mt-2 mb-3",children:"Click a row to see its runs."}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-3",children:[e.jsx(qe,{title:"By Pipeline",rows:d.perPipeline,onSelect:t=>x({tab:"ci-runs",pipeline:t,branch:null,env:null,state:null})}),e.jsx(qe,{title:"By Branch",rows:d.perBranch,onSelect:t=>x({tab:"ci-runs",branch:t,pipeline:null,env:null,state:null})}),e.jsx(qe,{title:"By Environment",rows:d.perEnvironment,onSelect:t=>x({tab:"ci-runs",env:t,pipeline:null,branch:null,state:null})})]})]}),o==="trace"&&e.jsx(Yt,{}),o==="dashboard"&&d&&d.totals.runs>0&&e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-100 flex items-center gap-2",children:[e.jsx(ue,{size:17,className:"text-blue-300"})," Recent CI Runs",e.jsx("span",{className:"text-sm text-gray-500 font-normal",children:"(last 5)"})]}),e.jsx("button",{onClick:()=>w("ci-runs"),className:"text-sm text-brand-300 hover:text-brand-200 font-medium",children:"View all runs →"})]}),e.jsx(We,{runs:S.slice(0,5),onCancel:n?p:void 0})]}),o==="ci-runs"&&e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3 flex-wrap gap-2",children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-100 flex items-center gap-2",children:[e.jsx(ue,{size:17,className:"text-blue-300"})," CI Runs",e.jsxs("span",{className:"text-sm text-gray-500 font-normal",children:[_?`${L.length} of ${S.length}`:`${S.length} total`,(((we=v.data)==null?void 0:we.total)||0)>S.length&&` (latest ${S.length} of ${v.data.total})`]})]}),S.length>0&&e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsxs("select",{value:A||"",onChange:t=>x({state:t.target.value||null}),"aria-label":"Filter by state",className:"px-2.5 py-1.5 rounded-lg bg-surface-2 border border-white/10 text-sm text-gray-900 dark:text-gray-200 focus:outline-none",children:[e.jsx("option",{value:"",children:"All states"}),["running","queued","passed","failed","cancelled","error"].map(t=>e.jsx("option",{value:t,children:t},t))]}),e.jsxs("select",{value:k||"",onChange:t=>x({pipeline:t.target.value||null}),"aria-label":"Filter by pipeline",className:"px-2.5 py-1.5 rounded-lg bg-surface-2 border border-white/10 text-sm text-gray-900 dark:text-gray-200 focus:outline-none",children:[e.jsx("option",{value:"",children:"All pipelines"}),[...new Set(S.map(t=>t.mappingName).filter(Boolean))].map(t=>e.jsx("option",{value:t,children:t},t))]}),e.jsxs("select",{value:M||"",onChange:t=>x({env:t.target.value||null}),"aria-label":"Filter by environment",className:"px-2.5 py-1.5 rounded-lg bg-surface-2 border border-white/10 text-sm text-gray-900 dark:text-gray-200 focus:outline-none",children:[e.jsx("option",{value:"",children:"All environments"}),[...new Set(S.map(t=>t.environment).filter(Boolean))].map(t=>e.jsx("option",{value:t,children:t},t))]}),e.jsx("input",{value:B||"",onChange:t=>x({branch:t.target.value||null}),placeholder:"Branch…","aria-label":"Filter by branch",className:"px-2.5 py-1.5 rounded-lg bg-surface-2 border border-white/10 text-sm text-gray-200 placeholder-gray-600 focus:outline-none w-32"}),_&&e.jsx("button",{onClick:ce,className:"text-sm text-gray-500 hover:text-gray-300 px-1.5",title:"Clear all filters",children:"✕ Clear"})]})]}),v.isError?e.jsx(Re,{what:"CI runs",error:v.error,onRetry:()=>v.refetch()}):v.isLoading?e.jsxs("div",{className:"py-8 text-center text-gray-500 text-sm",children:[e.jsx(Y,{size:16,className:"animate-spin inline mr-2"}),"Loading…"]}):S.length===0?e.jsxs("div",{className:"py-10 text-center rounded-xl border border-dashed border-white/10 text-sm text-gray-500",children:["No CI-triggered runs yet. Trigger one with ",e.jsx("code",{children:'testver trigger --mapping "…"'})," or from your pipeline."]}):e.jsxs(e.Fragment,{children:[e.jsx(We,{runs:re,emptyNote:"No runs match the filters.",onCancel:n?p:void 0}),E>1&&e.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2.5 mt-2 rounded-xl border border-white/5 bg-surface-1 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-gray-500",children:[e.jsx("span",{children:"Rows per page:"}),e.jsx("select",{value:z,onChange:t=>{ae(Number(t.target.value)),I(0)},"aria-label":"Rows per page",className:"bg-surface-2 border border-white/10 rounded px-2 py-1 text-gray-900 dark:text-gray-200 focus:outline-none focus:border-brand-500/40",children:[10,20,50,100].map(t=>e.jsx("option",{value:t,children:t},t))})]}),e.jsxs("div",{className:"flex items-center gap-2 text-gray-500",children:[e.jsxs("span",{children:["Showing ",T*z+1,"–",Math.min((T+1)*z,L.length)," of ",L.length," run",L.length===1?"":"s"]}),e.jsxs("div",{className:"flex items-center gap-1 ml-2",children:[e.jsx("button",{onClick:()=>I(0),disabled:T===0,title:"First page","aria-label":"First page",className:"px-2 py-1 rounded hover:bg-white/5 disabled:opacity-30 disabled:cursor-not-allowed text-gray-400",children:"«"}),e.jsx("button",{onClick:()=>I(t=>Math.max(0,t-1)),disabled:T===0,title:"Previous page",className:"px-2 py-1 rounded hover:bg-white/5 disabled:opacity-30 disabled:cursor-not-allowed text-gray-400",children:"‹ Prev"}),e.jsxs("span",{className:"px-2 text-gray-400",children:["Page ",e.jsx("span",{className:"text-gray-900 dark:text-gray-200 font-medium",children:T+1})," of ",E]}),e.jsx("button",{onClick:()=>I(t=>Math.min(E-1,t+1)),disabled:T>=E-1,title:"Next page",className:"px-2 py-1 rounded hover:bg-white/5 disabled:opacity-30 disabled:cursor-not-allowed text-gray-400",children:"Next ›"}),e.jsx("button",{onClick:()=>I(E-1),disabled:T>=E-1,title:"Last page","aria-label":"Last page",className:"px-2 py-1 rounded hover:bg-white/5 disabled:opacity-30 disabled:cursor-not-allowed text-gray-400",children:"»"})]})]})]})]})]})]})}),ne&&e.jsx(Qt,{mapping:ne,suites:O,onClose:()=>G(null),onSaved:()=>{G(null),Z()}}),y&&e.jsx(Zt,{mapping:y,hasToken:F.length>0,onOpenTokens:()=>{J(null),w("tokens")},onClose:()=>J(null)}),ge&&e.jsx(Wt,{raw:ge.raw,token:ge.token,pipelines:j,onClose:()=>le(null)}),W&&e.jsx(Te,{open:!0,title:`Delete mapping "${W.name}"?`,description:"CI jobs and scripts triggering this mapping name will start failing with 404. This does not affect past runs.",confirmLabel:"Delete",variant:"danger",onCancel:()=>m(null),onConfirm:async()=>{try{await bt(W.id),Z()}catch(t){U((t==null?void 0:t.message)||String(t))}m(null)}}),Q&&e.jsx(Te,{open:!0,title:`Revoke token "${Q.name}"?`,description:"Every CI job or script using this token immediately loses access. This cannot be undone.",confirmLabel:"Revoke",variant:"danger",onCancel:()=>de(null),onConfirm:async()=>{try{await yt(Q.id),Z()}catch(t){U((t==null?void 0:t.message)||String(t))}de(null)}}),X&&e.jsx(Te,{open:!0,title:`Cancel this ${X.mappingName||"CI"} run?`,description:X.state==="queued"?'It leaves the queue and its CI job fails with "cancelled".':'The tests stop on the Testver server and the CI job fails with "cancelled".',confirmLabel:"Cancel run",variant:"danger",onCancel:()=>p(null),onConfirm:async()=>{try{await ft(X.id),Z()}catch(t){U((t==null?void 0:t.message)||String(t))}p(null)}})]})}function nt(s,i){const n=s==null?void 0:s.mappingIds,a=n?n.length===0?"no pipeline mappings":n.map(w=>{var x;return((x=i.find(N=>N.id===w))==null?void 0:x.name)||"a deleted mapping"}).join(", "):"all pipeline mappings",o=(s==null?void 0:s.adHoc)??"none";return o==="commands"?`${a} + ad-hoc suites, cycles and shell commands`:o==="suites"?`${a} + ad-hoc suites and cycles`:a}function Ke({token:s,pipelines:i,onRevoke:n}){var o;const a=!!s.expiresAt&&new Date(s.expiresAt).getTime()<=Date.now();return e.jsxs("div",{className:`flex items-center gap-3 px-4 py-2.5 rounded-xl bg-surface-1 border border-white/5 text-sm ${s.revoked||a?"opacity-70":""}`,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium text-gray-200",children:s.name}),e.jsxs("code",{className:"text-xs text-gray-500",children:[s.prefix,"…"]}),s.revoked&&e.jsxs("span",{className:"text-xs px-1.5 py-0.5 rounded bg-white/5 text-gray-500",children:["revoked ",V(s.revokedAt),s.revokedBy?` by ${s.revokedBy}`:""]}),!s.revoked&&s.expiresAt&&e.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded ${a?"bg-red-500/10 text-red-300":"bg-white/5 text-gray-400"}`,children:tt(s.expiresAt)}),(((o=s.scope)==null?void 0:o.adHoc)??"none")==="commands"&&!s.revoked&&e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-300",title:"Can run any shell command on this server",children:"runs commands"})]}),e.jsxs("div",{className:"text-xs text-gray-500 mt-0.5 truncate",children:["Triggers ",nt(s.scope,i)]})]}),e.jsxs("span",{className:"text-sm text-gray-500 whitespace-nowrap",children:["created ",V(s.createdAt),s.createdBy?` by ${s.createdBy}`:""," · last used ",V(s.lastUsedAt)]}),n&&e.jsx("button",{onClick:n,title:"Revoke","aria-label":`Revoke ${s.name}`,className:"p-1.5 rounded-lg text-red-400 hover:text-red-600 dark:hover:text-red-500 hover:bg-red-500/10 transition-colors",children:e.jsx(Mt,{size:15})})]})}function Vt({pipelines:s,onCreated:i}){const[n,a]=l.useState(""),[o,w]=l.useState(!0),[x,N]=l.useState([]),[g,v]=l.useState("none"),[b,c]=l.useState("365"),[d,j]=l.useState(!1),[P,F]=l.useState(null),$=!!n.trim()&&!d&&(o||x.length>0||g!=="none"),S=async()=>{if($){j(!0),F(null);try{const h=await kt({name:n.trim(),scope:{mappingIds:o?void 0:x,adHoc:g},expiresInDays:b?Number(b):void 0});a(""),N([]),w(!0),v("none"),i(h)}catch(h){F((h==null?void 0:h.message)||String(h))}finally{j(!1)}}};return e.jsxs("div",{className:"mb-4 p-4 rounded-xl bg-surface-1 border border-white/5 space-y-3",children:[e.jsxs("div",{className:"flex items-end gap-2 flex-wrap",children:[e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-xs text-gray-500",children:"Name"}),e.jsx("input",{value:n,onChange:h=>a(h.target.value),maxLength:60,onKeyDown:h=>{h.key==="Enter"&&S()},placeholder:"e.g. github-pr-gate",className:"px-3 py-2 rounded-xl bg-surface-2 border border-white/10 text-sm text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/50 w-64"})]}),e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-xs text-gray-500",children:"Expires"}),e.jsxs("select",{value:b,onChange:h=>c(h.target.value),className:"px-3 py-2 rounded-xl bg-surface-2 border border-white/10 text-sm text-gray-900 dark:text-gray-200 focus:outline-none focus:border-brand-500/50",children:[e.jsx("option",{value:"30",children:"in 30 days"}),e.jsx("option",{value:"90",children:"in 90 days"}),e.jsx("option",{value:"365",children:"in 1 year"}),e.jsx("option",{value:"",children:"never"})]})]}),e.jsxs("button",{disabled:!$,onClick:()=>void S(),className:"flex items-center gap-1.5 px-3.5 py-2 rounded-xl text-sm font-medium bg-brand-600 hover:bg-brand-500 text-white transition-colors disabled:opacity-50",children:[d?e.jsx(Y,{size:14,className:"animate-spin"}):e.jsx(Ye,{size:14})," Create Token"]})]}),e.jsxs("fieldset",{children:[e.jsx("legend",{className:"text-xs text-gray-500 mb-1",children:"May trigger"}),e.jsxs("div",{className:"flex flex-col gap-1.5 text-sm text-gray-300",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:"tok-scope",checked:o,onChange:()=>w(!0),className:"accent-brand-500"}),"Every pipeline mapping"]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:"tok-scope",checked:!o,onChange:()=>w(!1),className:"accent-brand-500"}),"Only these mappings:"]}),!o&&e.jsxs("div",{className:"ml-6 flex flex-wrap gap-x-4 gap-y-1",children:[s.length===0&&e.jsx("span",{className:"text-xs text-gray-500",children:"No mappings yet."}),s.map(h=>e.jsxs("label",{className:"flex items-center gap-1.5 text-sm",children:[e.jsx("input",{type:"checkbox",checked:x.includes(h.id),className:"accent-brand-500",onChange:R=>N(A=>R.target.checked?[...A,h.id]:A.filter(k=>k!==h.id))}),h.name]},h.id))]})]})]}),e.jsxs("fieldset",{children:[e.jsxs("legend",{className:"text-xs text-gray-500 mb-1",children:["Ad-hoc targets (CLI ",e.jsx("code",{children:"--suite"})," / ",e.jsx("code",{children:"--cycle"})," / ",e.jsx("code",{children:"--command"}),")"]}),e.jsx("div",{className:"flex flex-wrap gap-x-4 gap-y-1.5 text-sm text-gray-300",children:[["none","Not allowed"],["suites","Any suite or cycle"],["commands","Suites, cycles and shell commands"]].map(([h,R])=>e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:"tok-adhoc",checked:g===h,onChange:()=>v(h),className:"accent-brand-500"}),R]},h))}),g==="commands"&&e.jsx("p",{className:"mt-1.5 text-xs px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/25 text-amber-300",children:"⚠ Anyone holding this token can run any shell command on this Testver server. Prefer a pipeline mapping with a fixed command, and only allow this for a trusted, private pipeline."})]}),P&&e.jsx("p",{role:"alert",className:"text-sm text-red-300",children:P})]})}function Wt({raw:s,token:i,pipelines:n,onClose:a}){const[o,w]=l.useState(null),[x,N]=l.useState(!1),g=()=>{o==="ok"?a():N(!0)};Be(g);const v=window.location.origin,b=at(v);return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4",children:[e.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"new-token-title",className:"w-full max-w-xl rounded-2xl bg-surface-1 border border-white/10 p-6",children:[e.jsxs("h3",{id:"new-token-title",className:"text-base font-semibold text-gray-100 mb-2",children:['CI token "',i.name,'" created']}),e.jsx("p",{className:"text-xs text-amber-300 mb-3",children:"Copy it now — this is the only time it will be shown."}),e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 rounded-xl bg-surface-2 border border-white/10",children:[e.jsx("code",{className:"text-xs text-gray-200 break-all flex-1 select-all",children:s}),e.jsx("button",{onClick:async()=>{w(await Xe(s)?"ok":"fail")},"aria-label":"Copy the token",className:"p-1.5 rounded-lg text-gray-400 hover:text-gray-200",children:o==="ok"?e.jsx(Ie,{size:14,className:"text-emerald-400"}):e.jsx(Oe,{size:14})})]}),o==="fail"&&e.jsx("p",{role:"alert",className:"text-xs text-red-300 mt-1.5",children:"Copying isn't available here — select the token above and copy it by hand."}),e.jsxs("div",{className:"mt-4 text-sm text-gray-400 space-y-1.5",children:[e.jsx("p",{className:"font-medium text-gray-300",children:"Next:"}),e.jsxs("ol",{className:"list-decimal ml-5 space-y-1",children:[e.jsxs("li",{children:["Add it to your CI platform's secrets as ",e.jsx("code",{children:"TESTVER_CI_TOKEN"}),"."]}),e.jsxs("li",{children:["Open a pipeline mapping's ",e.jsx(Ee,{size:12,className:"inline -mt-0.5"})," ",e.jsx("b",{children:"Wire into CI"})," to generate the pipeline file."]}),e.jsxs("li",{children:["CI reaches this server at ",b?e.jsxs("span",{className:"text-amber-300",children:["the address your CI runners can reach (this page's address, ",e.jsx("code",{children:v}),", is local)"]}):e.jsx("code",{children:v}),"."]})]}),e.jsxs("p",{className:"text-xs text-gray-500",children:["It may trigger ",nt(i.scope,n),i.expiresAt?` · ${tt(i.expiresAt)}`:" · never expires","."]})]}),e.jsx("div",{className:"mt-4 text-right",children:e.jsx("button",{onClick:g,className:"px-4 py-2 rounded-xl text-sm font-medium bg-brand-600 hover:bg-brand-500 text-white",children:"Done"})})]}),x&&e.jsx(Te,{open:!0,title:"Close without copying the token?",description:"It cannot be shown again — you would have to create a new token.",confirmLabel:"Close",variant:"danger",onCancel:()=>N(!1),onConfirm:a})]})}function Qt({mapping:s,suites:i,onClose:n,onSaved:a}){var Ne,we,t,u,f,xe,te,me,oe,D,ke,Ce,H,_e,Ue;Be(n);const[o,w]=l.useState(s.name||""),[x,N]=l.useState(((Ne=s.target)==null?void 0:Ne.type)||"suite"),[g,v]=l.useState(((we=s.target)==null?void 0:we.command)||""),[b,c]=l.useState(((t=s.target)==null?void 0:t.suiteId)||""),[d,j]=l.useState(""),[P,F]=l.useState(((u=s.target)==null?void 0:u.cycleId)||""),[$,S]=l.useState(((f=s.overrides)==null?void 0:f.environment)||""),[O,h]=l.useState(((xe=s.overrides)==null?void 0:xe.browser)||""),[R,A]=l.useState(s.autoHeal||"inherit"),[k,B]=l.useState(s.timeoutMinutes?String(s.timeoutMinutes):""),[M,L]=l.useState(!!((te=s.statusPush)!=null&&te.enabled)),[_,ce]=l.useState(((me=s.statusPush)==null?void 0:me.provider)||"github"),[se,I]=l.useState(((oe=s.statusPush)==null?void 0:oe.repo)||""),[z,ae]=l.useState(s.statusPush?"••••••••":""),[E,T]=l.useState(((D=s.statusPush)==null?void 0:D.baseUrl)||""),[re,ne]=l.useState(s.enabled!==!1),[G,W]=l.useState(!1),[m,y]=l.useState(null),J={github:"owner/repo",gitlab:"group/project (or numeric id)","azure-devops":"org/project/repo",bitbucket:"workspace/repo"},ge={github:"PAT with repo:status (classic) or Commit statuses read/write (fine-grained)",gitlab:"Access token with api scope","azure-devops":"PAT with Code (Status) scope",bitbucket:"username:app_password with Repositories:Write (or a workspace access token)"},le=s.statusPush,Q=!!le&&(le.provider!==_||(le.baseUrl||"")!==E.trim()),de=z==="••••••••";l.useEffect(()=>{Q&&de&&ae("")},[Q,de]);const{data:X}=K({queryKey:["tm-plans"],queryFn:()=>vt(),enabled:x==="cycle"});K({queryKey:["ci-cycle-plan",(ke=s.target)==null?void 0:ke.cycleId],enabled:x==="cycle"&&!!((Ce=s.target)!=null&&Ce.cycleId)&&!d,queryFn:async()=>{const r=await Qe(s.target.cycleId).catch(()=>null);return r!=null&&r.planId&&j(r.planId),(r==null?void 0:r.planId)||null}});const{data:p}=K({queryKey:["tm-cycles",d],queryFn:()=>jt(d),enabled:x==="cycle"&&!!d}),be=((p==null?void 0:p.cycles)||[]).map(r=>r.id).join(","),{data:ye}=K({queryKey:["cycle-automation-counts",d,be],enabled:x==="cycle"&&!!d&&(((H=p==null?void 0:p.cycles)==null?void 0:H.length)||0)>0,queryFn:async()=>{const r=await Promise.all(p.cycles.map(async C=>{try{const he=await Nt(C.id);return[C.id,(he.executions||[]).filter(lt=>lt.hasMappedScript).length]}catch{return[C.id,-1]}}));return Object.fromEntries(r)}}),fe=r=>ye==null?void 0:ye[r],U=((p==null?void 0:p.cycles)||[]).filter(r=>(fe(r.id)??1)!==0).length,{browserOpts:Me,envOpts:ee}=It(),ve=!!o.trim()&&!/^[A-Za-z0-9][A-Za-z0-9 ._-]*$/.test(o.trim()),Z=!!s.id&&!!s.name&&o.trim()!==s.name,ze=k.trim()!==""&&!(Number.isInteger(Number(k))&&Number(k)>=1&&Number(k)<=1440),q=[];o.trim()?ve&&q.push("a valid name"):q.push("a name"),x==="command"&&!g.trim()&&q.push("the command"),x==="suite"&&!b&&q.push("a suite"),x==="cycle"&&!P&&q.push("a cycle"),ze&&q.push("a timeout between 1 and 1440 minutes"),M&&!se.trim()&&q.push("the repository for status push"),M&&!z.trim()&&q.push(Q?"the access token for the new git host":"the status push access token");const je=q.length===0,ie="w-full px-3 py-2 rounded-xl bg-surface-2 border border-white/10 text-sm text-gray-900 dark:text-gray-200 focus:outline-none focus:border-brand-500/50";return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4",children:e.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"mapping-modal-title",className:"w-full max-w-2xl rounded-2xl bg-surface-1 border border-white/10 p-6 max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h3",{id:"mapping-modal-title",className:"text-base font-semibold text-gray-100",children:[s.id?"Edit":"New"," Pipeline Mapping"]}),e.jsx("button",{onClick:n,"aria-label":"Close",className:"text-gray-500 hover:text-gray-300",children:e.jsx($e,{size:16})})]}),e.jsx(rt,{message:m,onDismiss:()=>y(null)}),e.jsx("label",{htmlFor:"mapping-name",className:"block text-sm font-medium text-gray-300 mb-1",children:"Mapping name (the trigger key)"}),e.jsx("input",{id:"mapping-name",value:o,onChange:r=>w(r.target.value),placeholder:'e.g. "pr-gate-main"',maxLength:60,className:`w-full px-3 py-2 rounded-xl bg-surface-2 border text-sm text-gray-200 placeholder-gray-600 focus:outline-none mb-1 ${ve?"border-red-500/50 focus:border-red-500/70":"border-white/10 focus:border-brand-500/50"}`}),ve?e.jsx("p",{className:"text-xs text-red-400 mb-3",children:"This name can only contain letters, numbers, spaces, dots, dashes, and underscores — and must start with a letter or number. Special characters would break the generated CI config files."}):Z?e.jsxs("p",{className:"text-xs text-amber-300 mb-3",children:['CI files that use "',s.name,'" keep working — Testver remembers the old name. Update them to "',o.trim(),'" when you can, then forget the old name from the mapping list.']}):e.jsxs("p",{className:"text-xs text-gray-500 mb-3",children:["Your CI pipeline uses this exact name to trigger the run — e.g. ",e.jsxs("code",{children:['testver trigger --mapping "',o.trim()||"pr-gate-main",'"']}),". Allowed: letters, numbers, spaces, dots, dashes, underscores."]}),e.jsx("span",{className:"block text-sm font-medium text-gray-300 mb-1.5",children:"Execution target"}),e.jsx("div",{className:"flex gap-1.5 mb-3",role:"group","aria-label":"Execution target",children:["suite","cycle","command"].map(r=>e.jsx("button",{onClick:()=>N(r),"aria-pressed":x===r,className:`px-3.5 py-1.5 rounded-lg text-sm font-medium transition-colors ${x===r?"bg-brand-600 text-white":"bg-surface-2 text-gray-400 hover:text-gray-200"}`,children:et[r]},r))}),x==="suite"&&e.jsxs("select",{value:b,onChange:r=>c(r.target.value),className:`${ie} mb-4`,"aria-label":"Suite",children:[e.jsx("option",{value:"",children:"Select a suite…"}),i.map(r=>{var C;return e.jsxs("option",{value:r.id,children:[r.name," (",((C=r.tests)==null?void 0:C.length)||0," tests)"]},r.id)}),b&&!i.some(r=>r.id===b)&&e.jsxs("option",{value:b,children:["(deleted suite ",b,")"]})]}),x==="cycle"&&e.jsxs("div",{className:"grid grid-cols-2 gap-2 mb-4",children:[e.jsxs("select",{value:d,onChange:r=>{j(r.target.value),F("")},className:ie,"aria-label":"Test plan",children:[e.jsx("option",{value:"",children:"Select a plan…"}),((X==null?void 0:X.plans)||[]).map(r=>e.jsx("option",{value:r.id,children:r.name},r.id))]}),e.jsxs("select",{value:P,onChange:r=>F(r.target.value),className:ie,disabled:!d,"aria-label":"Test cycle",children:[e.jsx("option",{value:"",children:d?"Select a cycle…":"Pick a plan first"}),((p==null?void 0:p.cycles)||[]).map(r=>{const C=fe(r.id),he=C===0;return e.jsxs("option",{value:r.id,disabled:he,children:[r.name,C===void 0||C===-1?"":he?" — no automated scripts":` (${C} automated)`]},r.id)})]}),d&&(((_e=p==null?void 0:p.cycles)==null?void 0:_e.length)||0)>0&&U>0&&e.jsxs("p",{className:"col-span-2 text-xs text-gray-500",children:["CI triggers run a cycle's ",e.jsx("b",{className:"text-gray-400",children:"mapped automation scripts"})," — cycles without any are disabled here (",U," of ",p.cycles.length," cycle",p.cycles.length!==1?"s":""," in this plan ",U===1?"has":"have"," automated scripts). Map scripts under Script Mapping to enable a cycle."]}),d&&(((Ue=p==null?void 0:p.cycles)==null?void 0:Ue.length)||0)>0&&U===0&&e.jsx("p",{className:"col-span-2 text-xs px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/25 text-amber-300",children:"⚠ None of this plan's cycles have mapped automation scripts — a CI trigger would fail. Pick a different plan or map automation scripts first (Script Mapping screen)."})]}),x==="command"&&e.jsx("textarea",{value:g,onChange:r=>v(r.target.value),rows:2,"aria-label":"Command",placeholder:"npx playwright test --grep @smoke",className:"w-full px-3 py-2 rounded-xl bg-surface-2 border border-white/10 text-sm text-gray-200 font-mono placeholder-gray-600 focus:outline-none focus:border-brand-500/50 mb-4"}),e.jsxs("span",{className:"block text-sm font-medium text-gray-300 mb-1.5",children:["Overrides ",e.jsxs("span",{className:"text-gray-600",children:["(optional — ",x==="command"?"the browser / environment entries from Settings → Run Commands":`defaults come from the ${x}'s saved settings`,")"]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mb-4",children:[e.jsxs("div",{children:[e.jsx("span",{className:"block text-xs text-gray-500 mb-1",children:"Environment"}),e.jsx(De,{isEnv:!0,value:$,onChange:S,options:ee})]}),e.jsxs("div",{children:[e.jsx("span",{className:"block text-xs text-gray-500 mb-1",children:"Browser"}),e.jsx(De,{isEnv:!1,value:O,onChange:h,options:Me})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-xs text-gray-500 mb-1",children:"Time limit (minutes)"}),e.jsx("input",{value:k,onChange:r=>B(r.target.value.replace(/[^0-9]/g,"")),inputMode:"numeric",placeholder:"240",className:`w-full px-3 py-2 rounded-xl bg-surface-2 border text-sm text-gray-200 placeholder-gray-600 focus:outline-none ${ze?"border-red-500/50":"border-white/10 focus:border-brand-500/50"}`})]})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("p",{className:"text-sm text-gray-300 mb-1",children:"Auto-Heal on this pipeline"}),e.jsx("div",{className:"inline-flex rounded-lg border border-white/10 bg-surface-2 overflow-hidden",role:"group","aria-label":"Auto-Heal on this pipeline",children:[["inherit","Inherit"],["off","Off"],["heal","Heal only"],["heal-regate","Heal + re-gate"]].map(([r,C],he)=>e.jsx("button",{type:"button",onClick:()=>A(r),className:`px-3 py-1.5 text-xs font-medium transition-colors ${he>0?"border-l border-white/10":""} ${R===r?"bg-purple-500/15 text-purple-600 dark:text-purple-300":"text-gray-500 hover:text-gray-300 hover:bg-white/5"}`,"aria-pressed":R===r,children:C},r))}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[e.jsx("b",{children:"Heal only"})," keeps the build result and heals in the workspace's mode (Suggest when the workspace is Off). ",e.jsx("b",{children:"Heal + re-gate"})," always keeps verified fixes (Auto) and holds the gate until healing finishes, so a fully-healed run turns the build green, labeled as auto-healed."," ",e.jsx("b",{children:"Inherit"})," follows Settings → General."]})]}),e.jsxs("label",{className:"flex items-start gap-2 text-sm text-gray-300 mb-2",children:[e.jsx("input",{type:"checkbox",checked:M,onChange:r=>L(r.target.checked),className:"accent-brand-500 mt-0.5"}),e.jsxs("span",{children:["Push commit statuses to the git host (PR decoration)",e.jsx("span",{className:"block text-xs text-gray-500",children:"Testver posts queued → running → success/failure statuses on the triggering commit, so PRs show the verdict — this is what enables the fire-and-forget CI job mode."})]})]}),M&&e.jsxs("div",{className:"ml-6 mb-3 space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("select",{value:_,onChange:r=>ce(r.target.value),className:ie,"aria-label":"Git host",children:[e.jsx("option",{value:"github",children:"GitHub"}),e.jsx("option",{value:"gitlab",children:"GitLab"}),e.jsx("option",{value:"azure-devops",children:"Azure DevOps"}),e.jsx("option",{value:"bitbucket",children:"Bitbucket"})]}),e.jsx("input",{value:se,onChange:r=>I(r.target.value),placeholder:J[_],"aria-label":"Repository",className:"px-3 py-2 rounded-xl bg-surface-2 border border-white/10 text-sm text-gray-200 font-mono placeholder-gray-600 focus:outline-none"})]}),e.jsx("input",{value:z,onChange:r=>ae(r.target.value),type:"password",autoComplete:"new-password","aria-label":"Access token",placeholder:le&&!Q?"Token saved — type to replace":"Access token",className:"w-full px-3 py-2 rounded-xl bg-surface-2 border border-white/10 text-sm text-gray-200 placeholder-gray-600 focus:outline-none"}),Q&&e.jsx("p",{className:"text-xs text-amber-300",children:"The git host changed — enter the access token for it. The saved token is not sent to a different host."}),e.jsxs("p",{className:"text-xs text-gray-600 -mt-1",children:[ge[_],". Stored encrypted on this server, never returned to the browser."]}),e.jsx("input",{value:E,onChange:r=>T(r.target.value),"aria-label":"Self-hosted base URL",placeholder:"Self-hosted base URL (optional — GHE / self-managed GitLab / Azure Server)",className:"w-full px-3 py-2 rounded-xl bg-surface-2 border border-white/10 text-sm text-gray-200 placeholder-gray-600 focus:outline-none"})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-300 mb-5",children:[e.jsx("input",{type:"checkbox",checked:re,onChange:r=>ne(r.target.checked),className:"accent-brand-500"}),"Enabled (triggers are rejected while disabled)"]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[!je&&e.jsxs("span",{className:"text-xs text-gray-500 mr-auto",children:["Still needed: ",q.join(", ")]}),e.jsx("button",{onClick:n,className:"px-4 py-2 rounded-xl text-sm text-gray-400 hover:text-gray-200",children:"Cancel"}),e.jsxs("button",{disabled:!je||G,onClick:async()=>{var r;W(!0),y(null);try{await Ze({id:s.id,name:o.trim(),target:{type:x,command:x==="command"?g.trim():void 0,suiteId:x==="suite"?b:void 0,cycleId:x==="cycle"?P||((r=s.target)==null?void 0:r.cycleId):void 0},overrides:$||O?{environment:$||void 0,browser:O||void 0}:void 0,autoHeal:R,timeoutMinutes:k.trim()?Number(k):void 0,statusPush:M?{enabled:!0,provider:_,repo:se.trim(),token:z.trim(),baseUrl:E.trim()||void 0}:void 0,enabled:re}),a()}catch(C){y((C==null?void 0:C.message)||String(C)),W(!1)}},className:"flex items-center gap-1.5 px-4 py-2 rounded-xl text-sm font-medium bg-brand-600 hover:bg-brand-500 text-white disabled:opacity-50",children:[G&&e.jsx(Y,{size:13,className:"animate-spin"}),s.id?"Save Changes":"Create Mapping"]})]})]})})}const Ve=[{id:"github-actions",label:"GitHub Actions",note:"Add TESTVER_CI_TOKEN as a repository secret (Settings → Secrets and variables → Actions). Pull requests report on their own commit."},{id:"gitlab-ci",label:"GitLab CI",note:"Add TESTVER_CI_TOKEN as a masked CI/CD variable. This file is the repo's .gitlab-ci.yml — saving replaces any existing pipeline. Merge requests are gated once (no duplicate branch pipeline)."},{id:"jenkins",label:"Jenkins",note:`Add a Secret Text credential with id "testver-ci-token", then set the job's Script Path to Jenkinsfile.testver-gate. The agent needs curl + jq.`,branchNote:"Jenkins decides which branches build in the job settings — the branch list is not used."},{id:"azure-pipelines",label:"Azure Pipelines",note:`Create a pipeline from azure-testver-gate.yml (Pipelines → New → Existing Azure Pipelines YAML file), then add TESTVER_CI_TOKEN as a secret variable ("Keep this value secret"). PR builds report on the PR's own commit.`},{id:"bitbucket",label:"Bitbucket",note:"Add TESTVER_CI_TOKEN as a SECURED repository variable (Repository settings → Repository variables). This is the repo's bitbucket-pipelines.yml — saving replaces any existing pipeline."},{id:"circleci",label:"CircleCI",note:"Add TESTVER_CI_TOKEN as a project environment variable (Project Settings → Environment Variables). This is the repo's .circleci/config.yml — saving replaces any existing config.",branchNote:'CircleCI filters by the pushed branch: listing branches means only those are gated — pull request branches too need "*" to be gated.'}];function Zt({mapping:s,hasToken:i,onOpenTokens:n,onClose:a}){var W;Be(a);const[o,w]=l.useState(window.location.origin),[x,N]=l.useState("github-actions"),[g,v]=l.useState(!1),[b,c]=l.useState("main"),[d,j]=l.useState(null),[P,F]=l.useState(".github/workflows/testver-gate.yml"),[$,S]=l.useState(!1),[O,h]=l.useState(!1),[R,A]=l.useState(!1),[k,B]=l.useState(!1),[M,L]=l.useState(!1),[_,ce]=l.useState(null),[se,I]=l.useState(null),z=l.useMemo(()=>at(o),[o]),ae=b.split(",").map(m=>m.trim()).filter(Boolean),E=Ve.find(m=>m.id===x),T=()=>{j(null),B(!1),I(null)},re=`npx -y testver trigger --server ${o} --mapping "${s.name}"`,ne=async(m,y)=>{await Xe(y)?(ce(m),setTimeout(()=>ce(J=>J===m?null:J),1500)):I("Copying isn't available here — select the text and copy it by hand.")},G=async m=>{if(d){A(!0),I(null);try{await St({filePath:P,content:d,overwrite:m}),B(!0)}catch(y){(y==null?void 0:y.status)===409?L(!0):I((y==null?void 0:y.message)||String(y))}finally{A(!1)}}};return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4",children:[e.jsxs("div",{role:"dialog","aria-modal":"true","aria-labelledby":"wire-modal-title",className:"w-full max-w-5xl rounded-2xl bg-surface-1 border border-white/10 p-6 max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h3",{id:"wire-modal-title",className:"text-base font-semibold text-gray-100",children:['Wire "',s.name,'" into CI']}),e.jsx("button",{onClick:a,"aria-label":"Close",className:"text-gray-500 hover:text-gray-300",children:e.jsx($e,{size:16})})]}),e.jsx(rt,{message:se,onDismiss:()=>I(null)}),!i&&e.jsxs("div",{className:"mb-4 px-3 py-2.5 rounded-xl bg-amber-500/10 border border-amber-500/25 text-sm text-amber-300 flex items-center gap-3",children:[e.jsx(Ae,{size:15,className:"flex-shrink-0"}),e.jsxs("span",{className:"flex-1",children:["There is no active CI token yet — the pipeline needs one in its secrets as ",e.jsx("code",{children:"TESTVER_CI_TOKEN"}),"."]}),e.jsx("button",{onClick:n,className:"px-2.5 py-1 rounded-lg border border-amber-500/30 hover:bg-amber-500/10 text-xs font-medium whitespace-nowrap",children:"Go to CI Tokens"})]}),e.jsxs("label",{htmlFor:"wire-server-url",className:"block text-sm font-medium text-gray-300 mb-1",children:["Testver server URL ",e.jsx("span",{className:"text-gray-600",children:"(must be reachable from CI runners)"})]}),e.jsx("input",{id:"wire-server-url",value:o,onChange:m=>{w(m.target.value.trim()),T()},className:`w-full px-3 py-2 rounded-xl bg-surface-2 border text-sm text-gray-200 focus:outline-none mb-1 ${z?"border-amber-500/40":"border-white/10 focus:border-brand-500/50"}`}),z?e.jsxs("p",{className:"text-xs text-amber-300 mb-4",children:["⚠ ",z]}):e.jsx("div",{className:"mb-4"}),e.jsxs("span",{className:"block text-sm font-medium text-gray-300 mb-1 flex items-center gap-1.5",children:[e.jsx(Ht,{size:13})," From any terminal / script (exit 0 passed · 1 failed · 2 no verdict)"]}),e.jsxs("div",{className:"flex items-start gap-2 px-3 py-2.5 rounded-xl bg-surface-2 border border-white/10 mb-1",children:[e.jsx("pre",{className:"text-xs text-gray-300 whitespace-pre-wrap break-all flex-1 m-0",children:re}),e.jsx("button",{onClick:()=>void ne("cli",re),"aria-label":"Copy the CLI command",className:"p-1.5 rounded-lg text-gray-400 hover:text-gray-200",children:_==="cli"?e.jsx(Ie,{size:14,className:"text-emerald-400"}):e.jsx(Oe,{size:14})})]}),e.jsxs("p",{className:"text-xs text-gray-600 mb-4",children:["Needs Node.js (npx fetches the ",e.jsx("code",{children:"testver"})," CLI). Auth: set ",e.jsx("code",{children:"TESTVER_CI_TOKEN"})," (or pass ",e.jsx("code",{children:"--token"}),")."," ","Add ",e.jsx("code",{children:"--sha <commit> --branch <name>"})," to record the commit on the run (Trace, PR status)."," ","Add ",e.jsx("code",{children:"--no-wait"})," to return right away and let the commit status carry the verdict."]}),e.jsxs("span",{className:"block text-sm font-medium text-gray-300 mb-1.5 flex items-center gap-1.5",children:[e.jsx(Ee,{size:14})," Pipeline config",e.jsx("span",{className:"font-normal text-gray-500",children:"— the CI job triggers Testver and gates on the verdict; nothing is installed on the runner"})]}),e.jsx("span",{className:"block text-xs font-medium text-gray-500 uppercase tracking-wide mb-1.5",children:"Platform"}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2 mb-4",children:Ve.map(m=>{const y=x===m.id;return e.jsxs("button",{onClick:()=>{N(m.id),T()},"aria-pressed":y,className:`relative flex items-center gap-2.5 px-3 py-2.5 rounded-xl border text-sm font-medium transition-colors text-left ${y?"bg-brand-500/10 border-brand-500 text-gray-900 dark:text-gray-100":"bg-surface-1 border-white/10 text-gray-600 dark:text-gray-300 hover:border-white/25 hover:bg-surface-2"}`,children:[e.jsx(Kt,{platform:m.id,size:18}),e.jsx("span",{className:"truncate",children:m.label}),y&&e.jsx(Ie,{size:14,className:"ml-auto text-brand-500 flex-shrink-0"})]},m.id)})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mb-3",children:[e.jsxs("div",{children:[e.jsx("span",{className:"block text-xs font-medium text-gray-500 uppercase tracking-wide mb-1.5",children:"Gate mode"}),e.jsx("div",{className:"inline-flex p-1 rounded-xl bg-surface-2 border border-white/10",children:[{id:!1,label:"Wait & gate",hint:"exit code"},{id:!0,label:"Fire-and-forget",hint:"status push-back"}].map(m=>{const y=g===m.id;return e.jsxs("button",{onClick:()=>{v(m.id),T()},"aria-pressed":y,className:`px-3.5 py-2 rounded-lg text-sm font-medium transition-colors ${y?"bg-brand-600 text-white shadow-sm":"text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-200"}`,children:[m.label,e.jsxs("span",{className:`ml-1.5 text-xs ${y?"text-white/70":"text-gray-500"}`,children:["(",m.hint,")"]})]},String(m.id))})})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"block text-xs font-medium text-gray-500 uppercase tracking-wide mb-1.5",children:"Branches"}),e.jsx("input",{value:b,onChange:m=>{c(m.target.value),T()},placeholder:"main, release/* ( * = every branch)",className:"w-full px-3 py-2 rounded-xl bg-surface-2 border border-white/10 text-sm text-gray-200 font-mono placeholder-gray-600 focus:outline-none focus:border-brand-500/50"}),e.jsx("span",{className:"block text-xs text-gray-500 mt-1",children:E.branchNote||"Pushes to these branches, and pull requests targeting them, run the gate. Comma-separated; * = every branch."})]})]}),g&&e.jsxs("p",{className:"text-xs mb-2 px-3 py-2 rounded-lg border bg-amber-500/10 border-amber-500/25 text-amber-300",children:["The job triggers and exits immediately — the PR verdict comes from the commit status Testver pushes.",(W=s.statusPush)!=null&&W.enabled?" Status push-back is configured on this mapping. ✓":' ⚠ Enable "Push commit statuses" on this mapping first, or the PR will never get a verdict.']}),e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-3",children:[e.jsxs("p",{className:"flex-1 text-sm text-gray-500 dark:text-gray-400 leading-relaxed px-3 py-2 rounded-lg bg-surface-2 border border-white/5",children:[e.jsx("span",{className:"font-medium text-gray-700 dark:text-gray-300",children:"Setup: "}),E.note]}),e.jsxs("button",{disabled:O||ae.length===0,onClick:async()=>{h(!0),B(!1),I(null);try{const m=await wt({platform:x,options:{branches:ae,delegate:{mapping:s.name,serverUrl:o,noWait:g}}});j(m.content),F(m.filePath),S(!!m.exists)}catch(m){I((m==null?void 0:m.message)||String(m))}finally{h(!1)}},className:"flex items-center gap-1.5 px-4 py-2.5 rounded-xl text-sm font-medium bg-brand-600 hover:bg-brand-500 text-white disabled:opacity-50 flex-shrink-0 transition-colors",children:[O?e.jsx(Y,{size:14,className:"animate-spin"}):e.jsx(Ee,{size:14}),d?"Regenerate":"Generate Config"]})]}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative",children:[e.jsx("pre",{className:"px-3 py-2.5 rounded-xl bg-surface-2 border border-white/10 text-xs text-gray-300 overflow-auto max-h-80 whitespace-pre",children:d}),e.jsx("button",{onClick:()=>void ne("yaml",d),"aria-label":"Copy the pipeline config",className:"absolute top-2 right-2 p-1.5 rounded-lg bg-surface-1 text-gray-400 hover:text-gray-200",children:_==="yaml"?e.jsx(Ie,{size:14,className:"text-emerald-400"}):e.jsx(Oe,{size:14})})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 mt-3",children:[e.jsxs("span",{className:"text-xs text-gray-600",children:["Saves to ",e.jsx("code",{children:P})," in this project — commit & push it (token setup: see the note above).",$&&e.jsx("span",{className:"text-amber-300",children:" That file already exists — saving replaces it."})]}),e.jsxs("button",{disabled:R||k,onClick:()=>$?L(!0):void G(!1),className:"flex items-center gap-1.5 px-3.5 py-2 rounded-xl text-sm font-medium bg-emerald-600 hover:bg-emerald-500 text-white disabled:opacity-60 flex-shrink-0",children:[R?e.jsx(Y,{size:13,className:"animate-spin"}):k?e.jsx(Ie,{size:13}):null,k?"Saved to project":"Save to project"]})]})]})]}),M&&e.jsx(Te,{open:!0,title:`Replace ${P}?`,description:"This file already exists in the project. Saving replaces its whole content with the Testver gate — anything else in it is lost (git still has the previous version).",confirmLabel:"Replace file",variant:"danger",onCancel:()=>L(!1),onConfirm:()=>{L(!1),G(!0)}})]})}function qe({title:s,rows:i,onSelect:n}){return e.jsxs("div",{className:"rounded-xl bg-surface-1 border border-white/5 overflow-hidden",children:[e.jsx("div",{className:"px-4 py-2.5 text-xs font-semibold text-gray-400 uppercase tracking-wide border-b border-white/5",children:s}),i.length===0?e.jsx("div",{className:"px-4 py-5 text-center text-xs text-gray-600",children:"No data yet"}):e.jsx("table",{className:"w-full text-sm",children:e.jsx("tbody",{children:i.slice(0,6).map(a=>e.jsxs("tr",{onClick:n?()=>n(a.key):void 0,className:`border-t border-white/5 first:border-t-0 ${n?"cursor-pointer hover:bg-white/[0.04] transition-colors":""}`,children:[e.jsx("td",{className:"px-4 py-2 text-gray-200 truncate max-w-[120px]",title:a.key,children:n?e.jsx("button",{onClick:o=>{o.stopPropagation(),n(a.key)},"aria-label":`Show runs for ${a.key}`,className:"text-left truncate max-w-full hover:text-brand-300 focus:outline-none focus-visible:underline",children:a.key}):a.key}),e.jsxs("td",{className:"px-2 py-2 text-gray-500 whitespace-nowrap",children:[a.runs," run",a.runs!==1?"s":""]}),e.jsxs("td",{className:`px-2 py-2 font-medium whitespace-nowrap ${st(a.passRate)}`,title:(a.errored||0)>0?`${a.errored} errored run(s) count against the pass rate`:void 0,children:[a.passRate,"%"]}),e.jsx("td",{className:"px-2 py-2 text-gray-500 whitespace-nowrap",children:pe(a.avgDurationMs)}),e.jsx("td",{className:"px-3 py-2 text-right",children:e.jsx("span",{className:`inline-block w-2 h-2 rounded-full ${a.lastState==="passed"?"bg-emerald-400":a.lastState==="failed"||a.lastState==="error"?"bg-red-400":a.lastState==="running"?"bg-sky-400 animate-pulse":a.lastState==="queued"?"border border-dashed border-gray-400 bg-transparent":"bg-gray-500"}`,title:`last: ${a.lastState} · ${V(a.lastAt)}`,"aria-label":`last run ${a.lastState}`})})]},a.key))})})]})}function Yt(){const[s,i]=Se("q"),[n,a]=l.useState(s||""),[o,w]=l.useState(null),[x,N]=l.useState(!1),[g,v]=l.useState(null),b=async(c=n)=>{const d=c.trim();if(d.length<2){v("Enter at least 2 characters — a commit sha (6 or more) or a branch name");return}N(!0),v(null),d!==s&&i(d);try{w(await Ct(d))}catch(j){v((j==null?void 0:j.message)||String(j)),w(null)}finally{N(!1)}};return l.useEffect(()=>{s&&!o&&b(s)},[]),e.jsxs("section",{children:[e.jsxs("h2",{className:"text-base font-semibold text-gray-100 flex items-center gap-2 mb-1",children:[e.jsx(Fe,{size:17,className:"text-amber-300"})," Trace a Deploy"]}),e.jsx("p",{className:"text-sm text-gray-400 mb-3",children:"Paste a commit sha (6 or more characters) or a branch name from a deploy to see every run that gated it — the CI verdicts plus any manual verification runs on the same commit."}),e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("input",{value:n,onChange:c=>a(c.target.value),onKeyDown:c=>{c.key==="Enter"&&b()},placeholder:"e.g. 2f812c2 or release/2.4","aria-label":"Commit sha or branch",className:"px-3 py-2 rounded-xl bg-surface-2 border border-white/10 text-sm text-gray-200 font-mono placeholder-gray-600 focus:outline-none focus:border-brand-500/50 w-80"}),e.jsxs("button",{onClick:()=>void b(),disabled:x,className:"flex items-center gap-1.5 px-3.5 py-2 rounded-xl text-sm font-medium bg-brand-600 hover:bg-brand-500 text-white transition-colors disabled:opacity-50",children:[x?e.jsx(Y,{size:14,className:"animate-spin"}):e.jsx(Fe,{size:14})," Trace"]})]}),g&&e.jsx("div",{role:"alert",className:"px-3 py-2 rounded-lg bg-red-500/10 border border-red-500/30 text-xs text-red-300 mb-3",children:g}),o&&e.jsxs("div",{className:"space-y-1.5",children:[o.ciRuns.length===0&&o.otherRuns.length===0&&e.jsxs("div",{className:"px-4 py-4 rounded-xl border border-dashed border-white/10 text-sm text-gray-500 text-center",children:["No runs found for ",e.jsx("code",{children:o.query}),".",o.hint?` ${o.hint}.`:""]}),o.ciRuns.map(c=>e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 rounded-xl bg-surface-1 border border-white/5 text-sm",children:[e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full border flex-shrink-0 ${Pe[c.state]}`,children:c.state}),e.jsx("span",{className:"text-gray-200 font-medium",children:c.mappingName}),c.buildNumber&&e.jsxs("span",{className:"text-gray-500 text-xs",children:["#",c.buildNumber]}),e.jsxs("span",{className:"text-sm text-gray-400",children:[c.branch,c.sha?` · ${c.sha.slice(0,7)}`:""]}),c.summary&&e.jsxs("span",{className:"text-sm text-gray-300",children:[e.jsx("span",{className:"text-emerald-400",children:c.summary.passed}),"/",c.summary.total," passed"]}),c.error&&e.jsx("span",{className:"text-xs text-red-300 truncate max-w-[280px]",title:c.error,children:c.error}),e.jsxs("span",{className:"text-sm text-gray-500 ml-auto",children:[V(c.createdAt)," · ",pe(c.durationMs)]}),c.buildUrl&&e.jsx("a",{href:c.buildUrl,target:"_blank",rel:"noopener noreferrer",title:"CI build","aria-label":"Open the CI build",className:"p-1.5 rounded-lg text-gray-500 hover:text-gray-200 hover:bg-white/5",children:e.jsx(Je,{size:13})}),c.runId&&e.jsx("a",{href:`/results?runId=${encodeURIComponent(c.runId)}`,target:"_blank",rel:"noopener noreferrer",title:"Testver report","aria-label":"Open the Testver report",className:"p-1.5 rounded-lg text-brand-400 hover:text-brand-300 hover:bg-white/5",children:e.jsx(ue,{size:13})})]},c.id)),o.otherRuns.map(c=>e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 rounded-xl bg-surface-1 border border-white/5 text-sm opacity-90",children:[e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full border bg-white/5 border-white/10 text-gray-400 flex-shrink-0",children:c.origin||"run"}),e.jsx("span",{className:"text-xs text-gray-400 flex-shrink-0",children:c.status}),e.jsx("span",{className:"text-gray-200",children:c.label||c.runId}),e.jsxs("span",{className:"text-sm text-gray-400",children:[c.gitBranch,c.gitCommitSha?` · ${c.gitCommitSha.slice(0,7)}`:""]}),c.summary&&e.jsxs("span",{className:"text-sm text-gray-300",children:[e.jsx("span",{className:"text-emerald-400",children:c.summary.passed}),"/",c.summary.total," passed"]}),e.jsxs("span",{className:"text-sm text-gray-500 ml-auto",children:[V(c.startTime)," · ",pe(c.duration)]}),e.jsx("a",{href:`/results?runId=${encodeURIComponent(c.runId)}`,target:"_blank",rel:"noopener noreferrer",title:"Testver report","aria-label":"Open the Testver report",className:"p-1.5 rounded-lg text-brand-400 hover:text-brand-300 hover:bg-white/5",children:e.jsx(ue,{size:13})})]},c.runId)),o.searched&&e.jsxs("p",{className:"text-xs text-gray-600 pt-1",children:["Searched the latest ",o.searched.ciRuns," CI runs and ",o.searched.otherRuns," other runs."]})]})]})}function We({runs:s,emptyNote:i,onCancel:n}){return e.jsx("div",{className:"rounded-xl border border-white/5 overflow-hidden bg-surface-1",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-xs text-gray-500 uppercase tracking-wide border-b border-white/5",children:[e.jsx("th",{className:"px-4 py-2.5",children:"State"}),e.jsx("th",{className:"px-4 py-2.5",children:"Pipeline"}),e.jsx("th",{className:"px-4 py-2.5",children:"Branch / Commit"}),e.jsx("th",{className:"px-4 py-2.5",children:"Result"}),e.jsx("th",{className:"px-4 py-2.5",children:"Duration"}),e.jsx("th",{className:"px-4 py-2.5",children:"Triggered"}),e.jsx("th",{className:"px-4 py-2.5 text-right",children:"Links"})]})}),e.jsxs("tbody",{children:[s.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-4 py-6 text-center text-sm text-gray-500",children:i||"No runs."})}),s.map(a=>e.jsxs("tr",{className:"border-t border-white/5 align-top",children:[e.jsx("td",{className:"px-4 py-2.5",children:a.state==="running"?e.jsx(ot,{size:"sm"}):a.state==="queued"?e.jsx(ct,{size:"sm",position:a.queuePosition||void 0}):e.jsx("span",{className:`inline-flex items-center gap-1.5 text-xs px-2 py-0.5 rounded-full border capitalize ${Pe[a.state]}`,children:a.state})}),e.jsxs("td",{className:"px-4 py-2.5 text-gray-200",children:[a.mappingName||"—",a.buildNumber&&e.jsxs("span",{className:"text-gray-500 ml-1.5",children:["#",a.buildNumber]})]}),e.jsxs("td",{className:"px-4 py-2.5 text-gray-300 text-sm",children:[a.branch||"—",a.sha&&e.jsx("code",{className:"ml-1.5 text-gray-500",children:a.sha.slice(0,7)})]}),e.jsxs("td",{className:"px-4 py-2.5 text-sm text-gray-300 max-w-[320px]",children:[a.summary&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-emerald-400",children:a.summary.passed})," / ",a.summary.total," passed",a.summary.failed>0&&e.jsxs("span",{className:"text-red-400 ml-1",children:["(",a.summary.failed," failed)"]})]}),a.error&&e.jsx("span",{className:"block text-xs text-red-300 mt-0.5 line-clamp-2",title:a.error,children:a.error}),!a.summary&&!a.error&&"—",a.pushWarning&&e.jsxs("span",{className:"block text-xs text-amber-400/80 mt-0.5 line-clamp-2",title:a.pushWarning,children:["PR status not posted: ",a.pushWarning]}),a.autoHeal&&e.jsxs("span",{className:"block text-[11px] mt-0.5 space-x-2",children:[a.autoHeal.healed>0&&e.jsxs("span",{className:"text-emerald-600 dark:text-emerald-300",title:"Locator repaired, verified by re-run, and kept — the summary above counts the original failure",children:["✦ ",a.autoHeal.healed," healed & verified"]}),a.autoHeal.suggested>0&&e.jsxs("span",{className:"text-purple-600 dark:text-purple-300",title:"A verified fix is waiting — open the run in Results and click Apply fix",children:[a.autoHeal.suggested," fix",a.autoHeal.suggested>1?"es":""," ready"]}),a.autoHeal.reverted>0&&e.jsxs("span",{className:"text-amber-600 dark:text-amber-300",title:"A repair was tried but failed verification — files were restored",children:[a.autoHeal.reverted," reverted"]})]})]}),e.jsx("td",{className:"px-4 py-2.5 text-sm text-gray-400",title:"Time on the Testver server (queue wait not included)",children:pe(a.durationMs)}),e.jsxs("td",{className:"px-4 py-2.5 text-sm text-gray-400",children:[V(a.createdAt)," by ",a.triggeredBy]}),e.jsxs("td",{className:"px-4 py-2.5 text-right whitespace-nowrap",children:[n&&(a.state==="queued"||a.state==="running")&&e.jsx("button",{onClick:()=>n(a),title:"Cancel this run","aria-label":`Cancel the ${a.mappingName||"CI"} run`,className:"inline-flex p-1.5 rounded-lg text-red-400 hover:text-red-500 hover:bg-red-500/10",children:e.jsx(Lt,{size:13})}),a.buildUrl&&e.jsx("a",{href:a.buildUrl,target:"_blank",rel:"noopener noreferrer",title:"Open CI build","aria-label":"Open the CI build",className:"inline-flex p-1.5 rounded-lg text-gray-500 hover:text-gray-200 hover:bg-white/5",children:e.jsx(Je,{size:13})}),a.runId&&e.jsx("a",{href:`/results?runId=${encodeURIComponent(a.runId)}`,target:"_blank",rel:"noopener noreferrer",title:"Open Testver report","aria-label":"Open the Testver report",className:"inline-flex p-1.5 rounded-lg text-brand-400 hover:text-brand-300 hover:bg-white/5",children:e.jsx(ue,{size:13})})]})]},a.id))]})]})})}export{ls as PipelinesPage};