@testver/testver 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/README.md +3 -1
  2. package/bin/testver.js +1 -1
  3. package/dist/index.js +770 -391
  4. package/package.json +2 -1
  5. package/src/ui/static/assets/{AIPanel-D09Ni3a4.js → AIPanel-B_R-CbrF.js} +2 -2
  6. package/src/ui/static/assets/{AIRecordPanel-DZtUZnRe.js → AIRecordPanel-BRQWIU5h.js} +3 -3
  7. package/src/ui/static/assets/{AIStreamUI-BsxKziYG.js → AIStreamUI-C3D989_6.js} +3 -3
  8. package/src/ui/static/assets/{AITestGenPage-Cg21-P1W.js → AITestGenPage-D3t2gPAA.js} +5 -5
  9. package/src/ui/static/assets/{APITestingPage-Cdc8EZz2.js → APITestingPage-Cmwkiiys.js} +1 -1
  10. package/src/ui/static/assets/{AboutPage-yJLCr2_q.js → AboutPage-CjEqKB-q.js} +1 -1
  11. package/src/ui/static/assets/AdvancedPage-4kAcpE8Y.js +3 -0
  12. package/src/ui/static/assets/{AnalyticsPage-gTPFsiLZ.js → AnalyticsPage-64mYNK2v.js} +1 -1
  13. package/src/ui/static/assets/{AuditLogPage-DE45E_PV.js → AuditLogPage-BQjOzQje.js} +1 -1
  14. package/src/ui/static/assets/{ChangesSummary-C-7oi_sx.js → ChangesSummary-CY_Vb27i.js} +2 -2
  15. package/src/ui/static/assets/{CodeMapPage-DgU6ZYBO.js → CodeMapPage-B1ezmnlE.js} +3 -3
  16. package/src/ui/static/assets/{ConfirmDialog-DNU3qoAP.js → ConfirmDialog-t7mpeeSN.js} +1 -1
  17. package/src/ui/static/assets/{CoveragePage-BpTjgcdV.js → CoveragePage-YMmCbiBk.js} +2 -2
  18. package/src/ui/static/assets/{CronBuilder-DsnX-vRr.js → CronBuilder-Nk-K-_8I.js} +1 -1
  19. package/src/ui/static/assets/Dashboard-BDVxO2V4.js +1 -0
  20. package/src/ui/static/assets/{DefectsPage-BtMNbq6Z.js → DefectsPage-l8yGeCyR.js} +1 -1
  21. package/src/ui/static/assets/{DiffViewer-DPglzjPH.js → DiffViewer-BIU09a_i.js} +1 -1
  22. package/src/ui/static/assets/{EmptyState-BH_aDO0P.js → EmptyState-D1T3JWUr.js} +1 -1
  23. package/src/ui/static/assets/{ExportButton-Ce_MxnM1.js → ExportButton-Dt5RhL-h.js} +1 -1
  24. package/src/ui/static/assets/{FileViewer-iYL0lxyY.js → FileViewer-CrKgh_cB.js} +5 -5
  25. package/src/ui/static/assets/{GitPage-CQqV8JBC.js → GitPage-_4nCEzkJ.js} +5 -5
  26. package/src/ui/static/assets/{ImportExportPage-DXk7Koaq.js → ImportExportPage-BcR7IQi9.js} +1 -1
  27. package/src/ui/static/assets/{JiraPushDialog-CqftoLh8.js → JiraPushDialog-C2sP4_4h.js} +1 -1
  28. package/src/ui/static/assets/KpiTile-inmeEsy3.js +1 -0
  29. package/src/ui/static/assets/{LiveExecutionView-BD0wE8sz.js → LiveExecutionView-D5BRe9jq.js} +1 -1
  30. package/src/ui/static/assets/{MediaModal-DiSINwmh.js → MediaModal-C5n6sHYi.js} +1 -1
  31. package/src/ui/static/assets/{MobileRunPicker-BNs2lZFf.js → MobileRunPicker-0h-N2c6d.js} +1 -1
  32. package/src/ui/static/assets/{MobileRunTarget-D2Nqcj10.js → MobileRunTarget-Bo_xekig.js} +1 -1
  33. package/src/ui/static/assets/{ModuleExplorer-BmkoQrHb.js → ModuleExplorer-VGcmK167.js} +1 -1
  34. package/src/ui/static/assets/{OutputPage-Dcsr7cmr.js → OutputPage-B_1nPPxE.js} +1 -1
  35. package/src/ui/static/assets/PipelinesPanel-PmmPu8pj.js +1 -0
  36. package/src/ui/static/assets/{ProfilePage-ByshrcwC.js → ProfilePage-y7tJNNFd.js} +1 -1
  37. package/src/ui/static/assets/{ProjectExplorer-B9B___ij.js → ProjectExplorer-DbfGhRq0.js} +1 -1
  38. package/src/ui/static/assets/{RemoteFileStrip-DbPnaZ-v.js → RemoteFileStrip-WuRKtx_h.js} +1 -1
  39. package/src/ui/static/assets/ReportCard-G52Q6-2i.js +2 -0
  40. package/src/ui/static/assets/ReportFullView-Bt8UFP2J.js +1 -0
  41. package/src/ui/static/assets/ReportsPage-DMtDi73Q.js +48 -0
  42. package/src/ui/static/assets/ResultsPage-BI9jpK2N.js +115 -0
  43. package/src/ui/static/assets/RunState-ifC4zi6M.js +1 -0
  44. package/src/ui/static/assets/{RunTargets-C7Vqd4TU.js → RunTargets-C7vpCbck.js} +1 -1
  45. package/src/ui/static/assets/{ScriptMappingPage-BrANeHv0.js → ScriptMappingPage-7vHuvhQw.js} +1 -1
  46. package/src/ui/static/assets/{SearchableDevicePicker-CFJ_DUAA.js → SearchableDevicePicker-BYxYJNWl.js} +1 -1
  47. package/src/ui/static/assets/{SettingsPage-BwOiebKG.js → SettingsPage-DSISg7r7.js} +1 -1
  48. package/src/ui/static/assets/SharedReportView-BOqKGJmR.js +1 -0
  49. package/src/ui/static/assets/{SourcesPage-C_QVQwiA.js → SourcesPage-CgqtYGBi.js} +1 -1
  50. package/src/ui/static/assets/TestExplorerPage-gYLhCD4d.js +7 -0
  51. package/src/ui/static/assets/{TestManagementPage-Ch4PthuU.js → TestManagementPage-wqYTKP7W.js} +2 -2
  52. package/src/ui/static/assets/TestPlansPage-DOKX9p6z.js +5 -0
  53. package/src/ui/static/assets/{TestverCreditsRing-CUsMGEe3.js → TestverCreditsRing-DpMzl3h7.js} +1 -1
  54. package/src/ui/static/assets/{UncommittedDiffViewer-B5HSURk8.js → UncommittedDiffViewer-BxS0zi-p.js} +1 -1
  55. package/src/ui/static/assets/{UserManagementPage-BjY3ftxf.js → UserManagementPage-B5d0uDU_.js} +2 -2
  56. package/src/ui/static/assets/{WorkflowsPage-BUu-LjZ8.js → WorkflowsPage-Bk0DFnFS.js} +17 -17
  57. package/src/ui/static/assets/{hiddenLlmProviders-setxgY_B.js → hiddenLlmProviders-CdhhNa5G.js} +1 -1
  58. package/src/ui/static/assets/index-BYVxKLrT.js +47 -0
  59. package/src/ui/static/assets/index-C2KJt7SI.css +1 -0
  60. package/src/ui/static/assets/reportMeta-AKcU_qwq.js +1 -0
  61. package/src/ui/static/assets/{useFeatureFlags-DqhngqgG.js → useFeatureFlags-DNkIctil.js} +1 -1
  62. package/src/ui/static/assets/{useJiraConnector-TM1Rfj1s.js → useJiraConnector-D5ysBBvz.js} +1 -1
  63. package/src/ui/static/assets/{useOwnership-eW6Egd7X.js → useOwnership-U0AfKBRo.js} +1 -1
  64. package/src/ui/static/assets/{useSuites-CvtMGakZ.js → useSuites-DyfN9HVv.js} +1 -1
  65. package/src/ui/static/assets/{useTestExplorer-HqvURJAc.js → useTestExplorer-DT8frjCK.js} +1 -1
  66. package/src/ui/static/assets/{useTestLifecycle-CL7-zz0Q.js → useTestLifecycle-OcwQaB1s.js} +1 -1
  67. package/src/ui/static/assets/{useTestManagement-ZTA1_VUm.js → useTestManagement-Xm4Bcx3u.js} +2 -2
  68. package/src/ui/static/assets/useTestResults-D5EwGIX9.js +1 -0
  69. package/src/ui/static/assets/{vendor-icons-B0wLOBoh.js → vendor-icons-BKPiFyYV.js} +1 -1
  70. package/src/ui/static/index.html +3 -3
  71. package/src/ui/static/assets/AdvancedPage-DB-6sJ6s.js +0 -3
  72. package/src/ui/static/assets/Dashboard-DRWbVyTb.js +0 -1
  73. package/src/ui/static/assets/PipelinesPanel-CMMXCSda.js +0 -1
  74. package/src/ui/static/assets/ReportCard-BbNfk85h.js +0 -2
  75. package/src/ui/static/assets/ReportFullView-Cg1rggho.js +0 -1
  76. package/src/ui/static/assets/ReportsPage-CFv3OAhe.js +0 -48
  77. package/src/ui/static/assets/ResultsPage-B4LwZH-R.js +0 -115
  78. package/src/ui/static/assets/SharedReportView-BAbW1WOs.js +0 -1
  79. package/src/ui/static/assets/TestExplorerPage-BRRWtwde.js +0 -7
  80. package/src/ui/static/assets/TestPlansPage-Bno2vpGd.js +0 -5
  81. package/src/ui/static/assets/index-B0klHYbO.css +0 -1
  82. package/src/ui/static/assets/index-DtBWNlVD.js +0 -47
  83. package/src/ui/static/assets/useTestResults-Bm-JyMhB.js +0 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-DtBWNlVD.js","assets/vendor-react-CTbHBddL.js","assets/vendor-query-BrzmPFT3.js","assets/vendor-icons-B0wLOBoh.js","assets/index-B0klHYbO.css"])))=>i.map(i=>d[i]);
2
- import{r as s,j as e,b as er,n as Mn}from"./vendor-react-CTbHBddL.js";import{b as Qr,aq as ia,ar as Or,as as la,at as zn,au as ca,av as In,aw as da,ax as qr,a7 as ua,ay as Pn,az as rn,aA as Dn,Q as xa,S as nn,T as an,aB as on,aC as pa,aD as ln,U as ma,aE as cn,aF as fa,aG as ha,aH as Fr,aI as gr,aJ as ga,aK as ba,aL as dn,aM as ya,aN as va,aO as br,aP as wa,aQ as ja,aR as Na,aS as ka,aT as un,V as Sa,aU as xn,X as Ca,W as Ra,aV as $a,aW as Ta,aX as Aa,aY as Ea,aZ as Ma,a_ as za,a$ as Ia,b0 as Pa,b1 as Da,b2 as Fa,b3 as La,x as Fn,b4 as _a,b5 as wr,b6 as Ha,b7 as Ka,b8 as Ba,b9 as pn,ba as mn,bb as fn,bc as Ua,bd as Oa,be as qa,bf as Ga,bg as Wa,bh as Va,bi as Ya,bj as Qa,bk as Xa,bl as Lr,bm as Ja,bn as Za,bo as eo,bp as to,bq as so,br as ro,bs as no,bt as ao,bu as oo}from"./index-DtBWNlVD.js";import{t as Yt,f as Rs}from"./formatTestName-BKd2Uqhs.js";import{a as Ln,f as _r}from"./formatDate-T65-Y6Mi.js";import{a as Xr,u as _n,c as jr}from"./vendor-query-BrzmPFT3.js";import{C as Hn}from"./ConfirmDialog-DNU3qoAP.js";import{u as Qt,X as gt,v as Jr,a3 as ve,bo as Kn,bt as As,bu as Bn,b9 as Es,a5 as at,a2 as Ms,r as ft,f as ht,Z as Un,S as Js,l as $s,bv as Nr,bw as Zr,ag as zs,bx as Tr,ap as en,aE as On,y as ls,by as io,K as tn,J as Gr,a6 as Zs,bz as lo,bA as co,bB as uo,a8 as Ht,bC as xo,bD as po,bE as mo,bF as fo,bG as ho,aI as go,ak as hn,b6 as tr,bH as bo,aK as vr,a7 as Ts,be as qn,ar as kr,bI as Qs,b0 as Sr,aa as Ys,al as yo,bJ as vo,bK as Gn,bL as wo,bb as Cr,b8 as jo,ae as No,bM as ko,bN as So,bO as Co}from"./vendor-icons-B0wLOBoh.js";import{P as Wr,A as Wn,a as Ro,L as $o,f as gn,b as To,T as Ao,C as Eo}from"./ChangesSummary-C-7oi_sx.js";import{A as Vn}from"./AIStreamUI-BsxKziYG.js";import{D as Mo}from"./DiffViewer-DPglzjPH.js";import{H as zo,P as bn}from"./hiddenLlmProviders-setxgY_B.js";import{T as Vr}from"./TestverCreditsRing-CUsMGEe3.js";import{S as Io,L as Po}from"./SearchableDevicePicker-CFJ_DUAA.js";import{u as Yn}from"./useTestExplorer-HqvURJAc.js";import"./useTabParam-ChbOedP1.js";import"./MediaModal-DiSINwmh.js";const Do="\"'`“”‘’„‟‚‛«»‹›"'",Fo="?*+()[]{}|^$\\&<>%!;",Lo=t=>t.charCodeAt(0)<32||t.charCodeAt(0)===127;function _o(t){let n="";for(const u of t)Do.includes(u)||(u==="&"?n+=" and ":u==="%"?n+=" percent ":u==="+"?n+=" plus ":u===";"?n+=", ":Fo.includes(u)||Lo(u)?n+=" ":n+=u);return n.replace(/\s+/g," ").replace(/ ([,:.])/g,"$1").replace(/,(?=[,:])/g,"").trim().replace(/^[,:.\-\s]+|[,:\-\s]+$/g,"")}function Rr(t){const n=t.trim();if(!n)return null;const u=_o(n);return u===n.replace(/\s+/g," ")?null:u?`Saved as “${u}” — quotes and characters like ? * ( ) & stop a test from being run by name.`:"Use letters or numbers — quotes and characters like ? * ( ) & stop a test from being run by name."}const yn={recorded:{icon:e.jsx(ht,{size:14,className:"text-amber-400"}),label:"Recorded"},generated:{icon:e.jsx(ft,{size:14,className:"text-emerald-400"}),label:"Generated"},implemented:{icon:e.jsx(Un,{size:14,className:"text-blue-400"}),label:"Implemented"},draft:{icon:e.jsx(ht,{size:14,className:"text-gray-400"}),label:"Draft"}},vn={success:{icon:e.jsx(ft,{size:14,className:"text-emerald-400"}),label:"Generated"},failed:{icon:e.jsx(Ms,{size:14,className:"text-red-400"}),label:"Failed"},stopped:{icon:e.jsx(at,{size:12,className:"text-gray-400 fill-gray-400",strokeWidth:0}),label:"Stopped"}};function Ho(t){return t.outcome&&vn[t.outcome]?vn[t.outcome]:yn[t.status]||yn.recorded}function Ko(t){const n=Date.now()-t;return n<6e4?"Just now":n<36e5?`${Math.floor(n/6e4)}m ago`:n<864e5?`${Math.floor(n/36e5)}h ago`:n<6048e5?`${Math.floor(n/864e5)}d ago`:Ln(t)}function Bo(t){const n=new Date,u=new Date(n.getFullYear(),n.getMonth(),n.getDate()).getTime(),d=u-864e5,l=u-7*864e5,N={Today:[],Yesterday:[],"This Week":[],Earlier:[]};for(const p of t){const A=p.createdAt;A>=u?N.Today.push(p):A>=d?N.Yesterday.push(p):A>=l?N["This Week"].push(p):N.Earlier.push(p)}return Object.entries(N).filter(([,p])=>p.length>0).map(([p,A])=>({label:p,items:A}))}const Uo=["login","checkout","search","smoke","regression","e2e","navigation","form"];function Oo({onLoadSession:t,onClose:n,activeSessionId:u}){const d=Xr(),{toast:l}=Qr(),[N,p]=s.useState(""),[A,I]=s.useState(null),[E,C]=s.useState(!1),k=s.useRef({}),[T,S]=s.useState(null),[L,H]=s.useState(null),[D,V]=s.useState(""),[U,oe]=s.useState(null),[P,Y]=s.useState(""),[g,Z]=s.useState(null),{data:B,isLoading:ee}=_n({queryKey:["recording-history"],queryFn:()=>ia()}),J=jr({mutationFn:Or,onSuccess:()=>d.invalidateQueries({queryKey:["recording-history"]})}),ie=jr({mutationFn:({id:$,data:m})=>la($,m),onSuccess:()=>d.invalidateQueries({queryKey:["recording-history"]})}),se=s.useMemo(()=>{const $=(B==null?void 0:B.sessions)||[];return Array.isArray($)?$.filter(m=>m.status!=="draft"):[]},[B]),ue=s.useMemo(()=>{let $=se;if(N){const m=N.toLowerCase();$=$.filter(X=>(X.name||"").toLowerCase().includes(m)||(X.url||"").toLowerCase().includes(m))}return T&&($=$.filter(m=>Array.isArray(m.tags)&&m.tags.includes(T))),$},[se,N,T]),y=s.useMemo(()=>{const $=new Set;return se.forEach(m=>{Array.isArray(m.tags)&&m.tags.forEach(X=>$.add(X))}),Array.from($).sort()},[se]),R=s.useMemo(()=>{const $=new Set([...Uo,...y]);return Array.from($).sort()},[y]),v=s.useMemo(()=>Bo(ue),[ue]),W=async $=>{try{const m=await zn($);m&&t(m)}catch(m){l("error",`Couldn't open the recording: ${m}`)}},re=($,m)=>{const X=se.find(pe=>pe.id===$);if(!X)return;const w=Array.isArray(X.tags)?X.tags:[];w.includes(m)||(ie.mutate({id:$,data:{tags:[...w,m]}}),H(null),V(""))},$e=($,m)=>{const X=se.find(pe=>pe.id===$);if(!X)return;const w=Array.isArray(X.tags)?X.tags:[];ie.mutate({id:$,data:{tags:w.filter(pe=>pe!==m)}})};return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Qt,{size:16,className:"text-brand-400"}),e.jsx("span",{className:"text-sm font-semibold text-gray-200",children:"Recording History"}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-brand-500/10 text-brand-400 border border-brand-500/20",children:se.length})]}),e.jsx("button",{onClick:n,"aria-label":"Close history",className:"p-1 rounded hover:bg-white/10 text-gray-400 hover:text-gray-200",children:e.jsx(gt,{size:16})})]}),e.jsxs("div",{className:"px-4 py-2 space-y-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Jr,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{type:"text",value:N,onChange:$=>p($.target.value),placeholder:"Search recordings...",className:"w-full pl-8 pr-3 py-1.5 rounded-lg bg-surface-2 border border-white/5 text-xs text-gray-200 placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),y.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx("button",{onClick:()=>S(null),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${T?"text-gray-500 bg-surface-2 border border-white/5 hover:text-gray-300":"bg-brand-500/15 text-brand-300 border border-brand-500/25"}`,children:"All"}),y.map($=>e.jsx("button",{onClick:()=>S(T===$?null:$),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${T===$?"bg-brand-500/15 text-brand-300 border border-brand-500/25":"text-gray-500 bg-surface-2 border border-white/5 hover:text-gray-300"}`,children:$},$))]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-1",children:ee?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(ve,{size:20,className:"text-brand-400 animate-spin"})}):v.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Qt,{size:32,className:"text-gray-600 mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-gray-500",children:"No recordings yet"}),e.jsx("p",{className:"text-xs text-gray-600 mt-1",children:"Start a recording to see it here"})]}):v.map($=>e.jsxs("div",{className:"mb-3",children:[e.jsx("div",{className:"px-2 py-1",children:e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-gray-600",children:$.label})}),$.items.map(m=>{const X=Ho(m);return e.jsxs("div",{role:"button",tabIndex:0,"aria-label":`Open recording ${m.name}`,"aria-current":u===m.id?"true":void 0,className:`flex items-center gap-2 px-2 py-2 rounded-lg cursor-pointer group transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/50 ${u===m.id?"bg-brand-500/10":"hover:bg-gray-100 dark:hover:bg-gray-800"}`,onClick:()=>W(m.id),onKeyDown:w=>{w.target===w.currentTarget&&(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),W(m.id))},children:[X.icon,e.jsxs("div",{className:"flex-1 min-w-0",children:[U===m.id?e.jsx("input",{type:"text",value:P,onChange:w=>Y(w.target.value),onClick:w=>w.stopPropagation(),onBlur:()=>{P.trim()&&P.trim()!==m.name&&ie.mutate({id:m.id,data:{name:P.trim()}}),oe(null)},onKeyDown:w=>{w.key==="Enter"&&w.target.blur(),w.key==="Escape"&&oe(null)},autoFocus:!0,className:"text-sm text-gray-200 bg-surface-2 border border-brand-500/30 rounded px-1.5 py-0.5 w-full focus:outline-none focus:ring-1 focus:ring-brand-500"}):e.jsx("div",{className:"text-sm text-gray-200 truncate cursor-text",onDoubleClick:w=>{w.stopPropagation(),oe(m.id),Y(m.name)},title:"Double-click to rename",children:m.name}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[e.jsxs("span",{children:[m.actionCount," steps"]}),e.jsx("span",{children:Ko(m.createdAt)})]}),Array.isArray(m.tags)&&m.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",onClick:w=>w.stopPropagation(),children:m.tags.map(w=>e.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0 rounded-full text-[9px] font-medium bg-brand-500/10 text-brand-400 border border-brand-500/20",children:[w,e.jsx("button",{onClick:()=>Z({type:"remove-tag",sessionId:m.id,tag:w}),className:"hover:text-red-400 ml-0.5",title:`Remove tag "${w}"`,children:e.jsx(gt,{size:8})})]},w))}),L===m.id&&e.jsxs("div",{className:"mt-1 flex flex-wrap gap-1",onClick:w=>w.stopPropagation(),children:[R.filter(w=>!(m.tags||[]).includes(w)).map(w=>e.jsxs("button",{onClick:()=>re(m.id,w),className:"px-1.5 py-0 rounded-full text-[9px] text-gray-500 bg-surface-2 border border-white/5 hover:text-brand-400 hover:border-brand-500/20",children:["+ ",w]},w)),e.jsx("input",{type:"text",value:D,onChange:w=>V(w.target.value),placeholder:"custom...",className:"w-16 px-1 py-0 rounded text-[9px] bg-surface-2 border border-white/5 text-gray-200 placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500",onClick:w=>w.stopPropagation(),onKeyDown:w=>{w.key==="Enter"&&D.trim()&&re(m.id,D.trim().toLowerCase())}}),e.jsx("button",{onClick:w=>{w.stopPropagation(),H(null),V("")},className:"text-[9px] text-gray-500 hover:text-gray-300",children:"Done"})]})]}),e.jsxs("div",{className:"flex-shrink-0 relative",onClick:w=>w.stopPropagation(),children:[e.jsx("button",{ref:w=>{k.current[m.id]=w},onClick:()=>{if(A===m.id)I(null);else{const w=k.current[m.id];if(w){const pe=w.getBoundingClientRect(),Ie=window.innerHeight-pe.bottom;C(Ie<160)}I(m.id)}},className:"opacity-0 group-hover:opacity-100 p-1 rounded hover:bg-white/10 text-gray-500 hover:text-gray-300",children:e.jsx(Kn,{size:14})}),A===m.id&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>I(null)}),e.jsxs("div",{className:`absolute right-0 z-[60] rounded-lg shadow-xl py-1 w-[180px] bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 ${E?"bottom-full mb-1":"top-full mt-1"}`,children:[e.jsxs("button",{onClick:()=>{oe(m.id),Y(m.name),I(null)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-white/10 whitespace-nowrap",children:[e.jsx(As,{size:14})," Rename"]}),e.jsxs("button",{onClick:()=>{H(L===m.id?null:m.id),I(null)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-white/10 whitespace-nowrap",children:[e.jsx(Bn,{size:14})," Add Tags"]}),e.jsxs("button",{onClick:()=>{Z({type:"delete-session",sessionId:m.id,sessionName:m.name}),I(null)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-red-500 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 whitespace-nowrap",children:[e.jsx(Es,{size:14})," Delete"]})]})]})]})]},m.id)})]},$.label))}),e.jsx(Hn,{open:!!g,title:(g==null?void 0:g.type)==="delete-session"?"Delete recording?":(g==null?void 0:g.type)==="remove-tag"?"Remove tag?":"",description:(g==null?void 0:g.type)==="delete-session"?`Are you sure you want to delete "${g.sessionName||"this recording"}"? This will permanently remove the recorded actions, generated code history, and conversation. This action cannot be undone.`:(g==null?void 0:g.type)==="remove-tag"?`Are you sure you want to remove the tag "${g.tag}" from this recording? You can add it back later.`:"",confirmLabel:(g==null?void 0:g.type)==="delete-session"?"Delete":"Remove",onCancel:()=>Z(null),onConfirm:()=>{(g==null?void 0:g.type)==="delete-session"?J.mutate(g.sessionId):(g==null?void 0:g.type)==="remove-tag"&&$e(g.sessionId,g.tag),Z(null)}})]})}function Ct({label:t,hint:n,shortcut:u,children:d}){const l=s.useRef(null),N=s.useRef(null),[p,A]=s.useState(null),[I,E]=s.useState(null),C=()=>{var S;const T=(S=l.current)==null?void 0:S.getBoundingClientRect();T&&A(T)},k=()=>{A(null),E(null)};return s.useLayoutEffect(()=>{if(!p||!N.current)return;const T=N.current.getBoundingClientRect(),S=8,L=p.bottom+S+T.height<=window.innerHeight-8||p.top-S-T.height<8,H=p.left+p.width/2,D=Math.max(8,Math.min(H-T.width/2,window.innerWidth-T.width-8));E({left:D,top:L?p.bottom+S:p.top-S-T.height,below:L,arrowX:Math.max(10,Math.min(H-D,T.width-10))})},[p,t,n,u]),e.jsxs("span",{ref:l,className:"inline-flex",onMouseEnter:C,onMouseLeave:k,onFocus:C,onBlur:k,children:[d,p&&er.createPortal(e.jsxs("span",{ref:N,role:"tooltip",style:I?{left:I.left,top:I.top}:{left:0,top:0,visibility:"hidden"},className:"pointer-events-none fixed z-[75] animate-tooltip-in",children:[I&&e.jsx("span",{style:{left:I.arrowX},className:`absolute -translate-x-1/2 w-2 h-2 bg-[#111827] rotate-45 ring-1 ring-white/10 ${I.below?"-top-1":"-bottom-1"}`}),e.jsxs("span",{className:"relative flex flex-col gap-0.5 max-w-[260px] px-2.5 py-1.5 rounded-md bg-[#111827] text-white shadow-lg shadow-black/50 ring-1 ring-white/10",children:[e.jsxs("span",{className:"flex items-center gap-2 text-xs font-medium whitespace-nowrap",children:[t,u&&e.jsx("kbd",{className:"px-1 py-px rounded bg-white/15 text-[10px] font-mono font-normal text-white/90",children:u})]}),n&&e.jsx("span",{className:"text-[11px] leading-snug text-white/70",children:n})]})]}),document.body)]})}const wn={recorded:{icon:e.jsx(ht,{size:14,className:"text-amber-400"}),label:"Recorded"},generated:{icon:e.jsx(ft,{size:14,className:"text-emerald-400"}),label:"Generated"},implemented:{icon:e.jsx(Un,{size:14,className:"text-blue-400"}),label:"Implemented"},draft:{icon:e.jsx(ht,{size:14,className:"text-gray-400"}),label:"Draft"}},jn={success:{icon:e.jsx(ft,{size:14,className:"text-emerald-400"}),label:"Generated"},failed:{icon:e.jsx(Ms,{size:14,className:"text-red-400"}),label:"Failed"},stopped:{icon:e.jsx(at,{size:12,className:"text-gray-400 fill-gray-400",strokeWidth:0}),label:"Stopped"}};function qo(t){return t.outcome&&jn[t.outcome]?jn[t.outcome]:wn[t.status]||wn.recorded}function Go(t){const n=Date.now()-t;return n<6e4?"Just now":n<36e5?`${Math.floor(n/6e4)}m ago`:n<864e5?`${Math.floor(n/36e5)}h ago`:n<6048e5?`${Math.floor(n/864e5)}d ago`:Ln(t)}function Wo(t){const n=new Date,u=new Date(n.getFullYear(),n.getMonth(),n.getDate()).getTime(),d=u-864e5,l=u-7*864e5,N={Today:[],Yesterday:[],"This Week":[],Earlier:[]};for(const p of t){const A=p.createdAt;A>=u?N.Today.push(p):A>=d?N.Yesterday.push(p):A>=l?N["This Week"].push(p):N.Earlier.push(p)}return Object.entries(N).filter(([,p])=>p.length>0).map(([p,A])=>({label:p,items:A}))}const Vo=["login","checkout","search","smoke","regression","e2e","navigation","form"];function Hr({open:t,onClose:n,onLoad:u,activeSessionId:d}){const l=Xr(),[N,p]=s.useState(""),[A,I]=s.useState(null),[E,C]=s.useState(!1),k=s.useRef({}),[T,S]=s.useState(null),[L,H]=s.useState(null),[D,V]=s.useState(""),[U,oe]=s.useState(null),[P,Y]=s.useState(""),[g,Z]=s.useState(null),{data:B,isLoading:ee}=_n({queryKey:["mobile-recording-history"],queryFn:()=>ca({limit:500}),enabled:t,refetchInterval:t?1e4:!1}),J=jr({mutationFn:In,onSuccess:()=>l.invalidateQueries({queryKey:["mobile-recording-history"]})}),ie=jr({mutationFn:({id:$,data:m})=>da($,m),onSuccess:()=>l.invalidateQueries({queryKey:["mobile-recording-history"]})}),se=s.useMemo(()=>{const $=(B==null?void 0:B.recordings)||[];return Array.isArray($)?$.filter(m=>m.status!=="draft"):[]},[B]),ue=s.useMemo(()=>{let $=se;if(N){const m=N.toLowerCase();$=$.filter(X=>(X.name||"").toLowerCase().includes(m)||(X.url||"").toLowerCase().includes(m)||(X.device||"").toLowerCase().includes(m))}return T&&($=$.filter(m=>Array.isArray(m.tags)&&m.tags.includes(T))),$},[se,N,T]),y=s.useMemo(()=>{const $=new Set;return se.forEach(m=>{Array.isArray(m.tags)&&m.tags.forEach(X=>$.add(X))}),Array.from($).sort()},[se]),R=s.useMemo(()=>{const $=new Set([...Vo,...y]);return Array.from($).sort()},[y]),v=s.useMemo(()=>Wo(ue),[ue]),W=async $=>{try{const m=await qr($);m!=null&&m.recording&&(u(m.recording),n())}catch{}},re=($,m)=>{const X=se.find(pe=>pe.id===$);if(!X)return;const w=Array.isArray(X.tags)?X.tags:[];w.includes(m)||(ie.mutate({id:$,data:{tags:[...w,m]}}),H(null),V(""))},$e=($,m)=>{const X=se.find(pe=>pe.id===$);if(!X)return;const w=Array.isArray(X.tags)?X.tags:[];ie.mutate({id:$,data:{tags:w.filter(pe=>pe!==m)}})};return t?e.jsxs("div",{className:"absolute inset-y-0 left-0 w-[300px] bg-surface-1 border-r border-white/10 z-40 flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Qt,{size:16,className:"text-brand-400"}),e.jsx("span",{className:"text-sm font-semibold text-gray-200",children:"Recording History"}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-brand-500/10 text-brand-400 border border-brand-500/20",children:se.length})]}),e.jsx("button",{onClick:n,className:"p-1 rounded hover:bg-white/10 text-gray-400 hover:text-gray-200",children:e.jsx(gt,{size:16})})]}),e.jsxs("div",{className:"px-4 py-2 space-y-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Jr,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{type:"text",value:N,onChange:$=>p($.target.value),placeholder:"Search recordings...",className:"w-full pl-8 pr-3 py-1.5 rounded-lg bg-surface-2 border border-white/5 text-xs text-gray-200 placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),y.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx("button",{onClick:()=>S(null),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${T?"text-gray-500 bg-surface-2 border border-white/5 hover:text-gray-300":"bg-brand-500/15 text-brand-300 border border-brand-500/25"}`,children:"All"}),y.map($=>e.jsx("button",{onClick:()=>S(T===$?null:$),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${T===$?"bg-brand-500/15 text-brand-300 border border-brand-500/25":"text-gray-500 bg-surface-2 border border-white/5 hover:text-gray-300"}`,children:$},$))]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-1",children:ee?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(ve,{size:20,className:"text-brand-400 animate-spin"})}):v.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Qt,{size:32,className:"text-gray-600 mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-gray-500",children:"No recordings yet"}),e.jsx("p",{className:"text-xs text-gray-600 mt-1",children:"Start a recording to see it here"})]}):v.map($=>e.jsxs("div",{className:"mb-3",children:[e.jsx("div",{className:"px-2 py-1",children:e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-gray-600",children:$.label})}),$.items.map(m=>{const X=qo(m);return e.jsxs("div",{className:`flex items-center gap-2 px-2 py-2 rounded-lg cursor-pointer group transition-colors ${d===m.id?"bg-brand-500/10":"hover:bg-gray-100 dark:hover:bg-gray-800"}`,onClick:()=>W(m.id),children:[X.icon,e.jsxs("div",{className:"flex-1 min-w-0",children:[U===m.id?e.jsx("input",{type:"text",value:P,onChange:w=>Y(w.target.value),onClick:w=>w.stopPropagation(),onBlur:()=>{P.trim()&&P.trim()!==m.name&&ie.mutate({id:m.id,data:{name:P.trim()}}),oe(null)},onKeyDown:w=>{w.key==="Enter"&&w.target.blur(),w.key==="Escape"&&oe(null)},autoFocus:!0,className:"text-sm text-gray-200 bg-surface-2 border border-brand-500/30 rounded px-1.5 py-0.5 w-full focus:outline-none focus:ring-1 focus:ring-brand-500"}):e.jsx("div",{className:"text-sm text-gray-200 truncate cursor-text",onDoubleClick:w=>{w.stopPropagation(),oe(m.id),Y(m.name)},title:"Double-click to rename",children:m.name}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[e.jsxs("span",{children:[m.actionCount," steps"]}),e.jsx("span",{children:Go(m.createdAt)})]}),Array.isArray(m.tags)&&m.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",onClick:w=>w.stopPropagation(),children:m.tags.map(w=>e.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0 rounded-full text-[9px] font-medium bg-brand-500/10 text-brand-400 border border-brand-500/20",children:[w,e.jsx("button",{onClick:()=>Z({type:"remove-tag",sessionId:m.id,tag:w}),className:"hover:text-red-400 ml-0.5",title:`Remove tag "${w}"`,children:e.jsx(gt,{size:8})})]},w))}),L===m.id&&e.jsxs("div",{className:"mt-1 flex flex-wrap gap-1",onClick:w=>w.stopPropagation(),children:[R.filter(w=>!(m.tags||[]).includes(w)).map(w=>e.jsxs("button",{onClick:()=>re(m.id,w),className:"px-1.5 py-0 rounded-full text-[9px] text-gray-500 bg-surface-2 border border-white/5 hover:text-brand-400 hover:border-brand-500/20",children:["+ ",w]},w)),e.jsx("input",{type:"text",value:D,onChange:w=>V(w.target.value),placeholder:"custom...",className:"w-16 px-1 py-0 rounded text-[9px] bg-surface-2 border border-white/5 text-gray-200 placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500",onClick:w=>w.stopPropagation(),onKeyDown:w=>{w.key==="Enter"&&D.trim()&&re(m.id,D.trim().toLowerCase())}}),e.jsx("button",{onClick:w=>{w.stopPropagation(),H(null),V("")},className:"text-[9px] text-gray-500 hover:text-gray-300",children:"Done"})]})]}),e.jsxs("div",{className:"flex-shrink-0 relative",onClick:w=>w.stopPropagation(),children:[e.jsx("button",{ref:w=>{k.current[m.id]=w},onClick:()=>{if(A===m.id)I(null);else{const w=k.current[m.id];if(w){const pe=w.getBoundingClientRect(),Ie=window.innerHeight-pe.bottom;C(Ie<160)}I(m.id)}},className:"opacity-0 group-hover:opacity-100 p-1 rounded hover:bg-white/10 text-gray-500 hover:text-gray-300",children:e.jsx(Kn,{size:14})}),A===m.id&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>I(null)}),e.jsxs("div",{className:`absolute right-0 z-[60] rounded-lg shadow-xl py-1 w-[180px] bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 ${E?"bottom-full mb-1":"top-full mt-1"}`,children:[e.jsxs("button",{onClick:()=>{oe(m.id),Y(m.name),I(null)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-white/10 whitespace-nowrap",children:[e.jsx(As,{size:14})," Rename"]}),e.jsxs("button",{onClick:()=>{H(L===m.id?null:m.id),I(null)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-white/10 whitespace-nowrap",children:[e.jsx(Bn,{size:14})," Add Tags"]}),e.jsxs("button",{onClick:()=>{Z({type:"delete-session",sessionId:m.id,sessionName:m.name}),I(null)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-red-500 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 whitespace-nowrap",children:[e.jsx(Es,{size:14})," Delete"]})]})]})]})]},m.id)})]},$.label))}),e.jsx(Hn,{open:!!g,title:(g==null?void 0:g.type)==="delete-session"?"Delete recording?":(g==null?void 0:g.type)==="remove-tag"?"Remove tag?":"",description:(g==null?void 0:g.type)==="delete-session"?`Are you sure you want to delete "${g.sessionName||"this recording"}"? This will permanently remove the recorded actions, generated code, and healing manifest references. This action cannot be undone.`:(g==null?void 0:g.type)==="remove-tag"?`Are you sure you want to remove the tag "${g.tag}" from this recording? You can add it back later.`:"",confirmLabel:(g==null?void 0:g.type)==="delete-session"?"Delete":"Remove",onCancel:()=>Z(null),onConfirm:()=>{(g==null?void 0:g.type)==="delete-session"?J.mutate(g.sessionId):(g==null?void 0:g.type)==="remove-tag"&&$e(g.sessionId,g.tag),Z(null)}})]}):null}function Kr({screenshot:t,screenshotSize:n,elementRect:u,step:d,description:l,onClose:N}){const p=s.useRef(null),[A,I]=s.useState(null);s.useEffect(()=>{const k=T=>{T.key==="Escape"&&N()};return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[N]),s.useLayoutEffect(()=>{if(!p.current)return;const k=()=>{var L;const S=(L=p.current)==null?void 0:L.getBoundingClientRect();S&&I({width:S.width,height:S.height})};k(),window.addEventListener("resize",k);const T=setInterval(k,250);return()=>{window.removeEventListener("resize",k),clearInterval(T)}},[]);const E=(()=>{if(!u||!n||!A)return null;const k=A.width/n.width,T=A.height/n.height;return{left:u.x*k,top:u.y*T,width:u.width*k,height:u.height*T}})(),C=e.jsx("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/70 backdrop-blur-sm",onClick:N,role:"dialog","aria-label":`Step ${d} screenshot`,children:e.jsxs("div",{className:"relative max-w-[92vw] max-h-[92vh] flex flex-col",onClick:k=>k.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-surface-1 border border-white/10 rounded-t-lg",children:[e.jsx("span",{className:"inline-flex items-center justify-center w-6 h-6 rounded bg-blue-500/20 text-blue-300 text-[11px] font-bold",children:d}),e.jsx("span",{className:"text-[13px] text-gray-200 truncate flex-1",children:l}),e.jsx("button",{onClick:N,className:"p-1.5 rounded-md text-gray-400 hover:text-gray-100 hover:bg-white/10 transition-colors","aria-label":"Close preview",children:e.jsx(gt,{size:14})})]}),e.jsxs("div",{className:"relative bg-black border border-t-0 border-white/10 rounded-b-lg overflow-hidden flex items-center justify-center",children:[e.jsx("img",{ref:p,src:t,alt:l,className:"block max-w-[92vw] max-h-[82vh] w-auto h-auto",draggable:!1}),E&&e.jsx("div",{className:"absolute pointer-events-none border-[3px] border-red-400 rounded-sm",style:{left:E.left,top:E.top,width:E.width,height:E.height,boxShadow:"0 0 0 9999px rgba(0,0,0,0.35), 0 0 18px rgba(239,68,68,0.5), inset 0 0 0 1px rgba(255,255,255,0.45)"}})]}),e.jsxs("div",{className:"absolute bottom-2 left-1/2 -translate-x-1/2 text-[10px] text-gray-400 bg-black/60 px-2 py-1 rounded",children:["Press ",e.jsx("kbd",{className:"px-1 py-0.5 rounded bg-white/10 text-gray-200 text-[9px] font-mono",children:"Esc"})," or click outside to close"]})]})});return er.createPortal(C,document.body)}function Nn({entries:t,busy:n,onPermission:u,onOpenScreenshot:d}){const l=s.useRef(null);return s.useEffect(()=>{l.current&&(l.current.scrollTop=l.current.scrollHeight)},[t,n]),t.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center text-gray-500 text-sm gap-2",children:n?e.jsxs(e.Fragment,{children:[e.jsx(ve,{size:14,className:"animate-spin"}),"Waiting for the AI to start…"]}):e.jsx(e.Fragment,{children:"No output yet."})}):e.jsxs("div",{ref:l,className:"flex-1 overflow-y-auto p-4 space-y-1",children:[t.map(N=>e.jsx(Yo,{entry:N,onPermission:u,onOpenScreenshot:d},N.id)),n&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-gray-500 mt-3 px-4",children:[e.jsx(ve,{size:11,className:"animate-spin"}),"Streaming…"]})]})}function Yo({entry:t,onPermission:n,onOpenScreenshot:u}){return t.kind==="recorded-action"?e.jsx(Xo,{entry:t,onOpenScreenshot:u}):t.kind==="system"?e.jsxs("div",{className:"flex items-start gap-2 px-4 py-2",children:[e.jsx(Js,{size:12,className:"text-brand-400 mt-0.5 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-gray-400",children:t.message})]}):t.kind==="status"?e.jsxs("div",{className:"flex items-start gap-2 px-4 py-1",children:[e.jsx(Js,{size:10,className:"text-gray-500 mt-0.5 flex-shrink-0"}),e.jsx("span",{className:"text-[11px] text-gray-500 italic",children:t.message})]}):t.kind==="text"?e.jsx("div",{className:"flex items-start",children:e.jsx("div",{className:"px-4 py-2.5 min-w-0 max-w-[85%] overflow-hidden text-sm text-gray-300",children:e.jsx(Vn,{text:t.content})})}):t.kind==="tool"?e.jsx(Jo,{entry:t}):t.kind==="file-diff"?e.jsx("div",{className:"py-1",children:e.jsx(Mo,{diffs:[{filePath:t.filePath,diffType:t.diffType??"modified",diff:t.diff,linesAdded:t.linesAdded??0,linesRemoved:t.linesRemoved??0,timestamp:Date.now()}]})}):t.kind==="permission"&&n?e.jsx(Zo,{entry:t,onPermission:n}):t.kind==="permission"?null:t.kind==="error"?e.jsxs("div",{className:"flex items-start gap-2 px-4 py-2",children:[e.jsx($s,{size:12,className:"text-red-400 mt-0.5 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-red-400",children:t.message})]}):t.kind==="user"?e.jsx("div",{className:"flex justify-end px-4 py-2",children:e.jsx("div",{className:"max-w-[75%] rounded-2xl rounded-tr-md px-4 py-2.5 bg-brand-600/90 text-white text-[13px] leading-relaxed shadow-sm whitespace-pre-wrap",children:t.text})}):null}const Qo={tap:"border-l-blue-500",type:"border-l-emerald-500",swipe:"border-l-purple-500",pressKey:"border-l-amber-500",assertion:"border-l-green-500",annotation:"border-l-fuchsia-500"};function Xo({entry:t,onOpenScreenshot:n}){const u=t.actionType==="tap"?Nr:t.actionType==="type"?As:t.actionType==="swipe"?Zr:t.actionType==="assertion"?zs:t.actionType==="annotation"?Tr:en,d=Qo[t.actionType]||"border-l-gray-500";return e.jsxs("div",{className:`flex items-center gap-2.5 mx-3 my-0.5 pl-2 pr-2 py-1 rounded-r-md border-l-[3px] ${d} bg-black/[0.02] dark:bg-white/[0.02] hover:bg-black/[0.05] dark:hover:bg-white/[0.06] transition-colors duration-100`,children:[e.jsx("span",{className:"text-[11px] text-gray-500 w-4 text-right tabular-nums flex-shrink-0",children:t.stepNum}),t.screenshot?e.jsx("button",{type:"button",onClick:()=>n==null?void 0:n({screenshot:t.screenshot,screenshotSize:t.screenshotSize,elementRect:t.elementRect,step:t.stepNum,description:t.description}),className:"flex-shrink-0 rounded overflow-hidden border border-black/10 dark:border-white/10 hover:ring-2 hover:ring-brand-400/50 transition-all",title:"View screenshot",children:e.jsx("img",{src:t.screenshot,alt:"",className:"w-7 h-11 object-cover object-top"})}):e.jsx("div",{className:"w-7 h-11 rounded bg-black/5 dark:bg-white/5 flex items-center justify-center flex-shrink-0",children:e.jsx(u,{size:12,className:"text-gray-500"})}),e.jsx(u,{size:13,className:"text-gray-500 dark:text-gray-400 flex-shrink-0"}),(t.actionType==="assertion"||t.actionType==="annotation")&&e.jsx("span",{className:`flex-shrink-0 text-[9px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded ${t.actionType==="annotation"?"text-violet-600 dark:text-violet-400 bg-violet-500/10":"text-green-600 dark:text-green-400 bg-green-500/10"}`,children:t.actionType==="annotation"?"annotate":"assert"}),e.jsx("span",{className:"text-[13px] text-gray-700 dark:text-gray-300 truncate",children:t.description})]})}function Jo({entry:t}){const[n,u]=s.useState(!1),d=t.phase==="start"?e.jsx(ve,{size:11,className:"animate-spin text-blue-400"}):t.phase==="complete"?e.jsx(ft,{size:11,className:"text-emerald-400"}):t.phase==="error"?e.jsx(Ms,{size:11,className:"text-red-400"}):e.jsx(On,{size:11,className:"text-amber-400"}),l=!!(t.result||t.error||t.args);return e.jsxs("div",{className:"my-0.5",children:[e.jsxs("button",{onClick:()=>l&&u(N=>!N),className:`inline-flex max-w-full items-center gap-2 px-4 py-1.5 rounded-lg text-left transition-colors ${l?"hover:bg-white/[0.03] cursor-pointer":"cursor-default"}`,children:[d,e.jsx("span",{className:"text-[11px] font-mono text-gray-500",children:t.toolName}),t.phase==="error"&&t.error&&e.jsx("span",{className:"text-[10px] text-red-400 truncate max-w-[200px]",children:t.error}),l&&t.phase!=="start"&&e.jsx(ls,{size:10,className:`text-gray-600 transition-transform ${n?"rotate-180":""}`})]}),n&&l&&e.jsxs("div",{className:"mt-1 max-h-[200px] overflow-auto rounded-lg bg-black/30 border border-white/5 p-2.5",children:[t.args&&e.jsx("div",{className:"text-[10px] font-mono text-gray-500 mb-1 break-all",children:t.args}),t.result&&e.jsx("div",{className:"text-[10px] font-mono text-gray-400 break-all whitespace-pre-wrap",children:String(t.result).slice(0,2e3)}),t.error&&e.jsx("div",{className:"text-[10px] font-mono text-red-400 break-all",children:t.error})]})]})}function Zo({entry:t,onPermission:n}){return e.jsxs("div",{className:"mx-3 my-2 rounded-lg border border-amber-500/30 bg-amber-500/[0.08] p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-amber-200 font-semibold",children:[e.jsx(On,{size:12}),e.jsx("span",{children:"AI wants to use a tool that requires permission"})]}),e.jsxs("div",{className:"text-[12px] text-gray-200",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[e.jsx(io,{size:11,className:"text-gray-500"}),e.jsx("code",{className:"font-mono",children:t.toolName})]}),t.args&&e.jsx("pre",{className:"text-[10px] bg-surface-2 border border-white/5 rounded px-2 py-1 text-gray-300 whitespace-pre-wrap break-all max-h-32 overflow-y-auto",children:t.args}),t.fullPath&&e.jsx("div",{className:"text-[10px] text-gray-500 mt-1 font-mono truncate",children:t.fullPath})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>n(t.permissionId,!0,!1),className:"px-2.5 py-1 rounded-md bg-emerald-500/20 text-emerald-200 border border-emerald-500/40 hover:bg-emerald-500/30 text-[11px] font-medium",children:"Allow once"}),e.jsx("button",{type:"button",onClick:()=>n(t.permissionId,!0,!0),className:"px-2.5 py-1 rounded-md bg-emerald-500/10 text-emerald-300 border border-emerald-500/30 hover:bg-emerald-500/20 text-[11px]",children:"Always allow"}),e.jsx("button",{type:"button",onClick:()=>n(t.permissionId,!1,!1),className:"px-2.5 py-1 rounded-md bg-red-500/15 text-red-300 border border-red-500/30 hover:bg-red-500/25 text-[11px]",children:"Deny"})]})]})}function Qn({value:t,onChange:n,disabled:u=!1}){const d=u?"Finish or stop the current recording first":void 0;return e.jsxs("div",{role:"radiogroup","aria-label":"Recorder",className:`inline-flex rounded-lg border border-white/10 bg-white/5 p-0.5 text-xs ${u?"opacity-50":""}`,title:d,children:[e.jsxs("button",{type:"button",role:"radio","aria-checked":t==="web",disabled:u,onClick:()=>n("web"),className:`inline-flex items-center gap-1 px-2 py-1 rounded-md transition-colors disabled:cursor-not-allowed ${t==="web"?"bg-red-500/20 text-red-300":"text-gray-400 hover:text-gray-200"}`,title:d||"Record browser interactions",children:[e.jsx(tn,{size:12}),"Web"]}),e.jsxs("button",{type:"button",role:"radio","aria-checked":t==="mobile",disabled:u,onClick:()=>n("mobile"),className:`inline-flex items-center gap-1 px-2 py-1 rounded-md transition-colors disabled:cursor-not-allowed ${t==="mobile"?"bg-indigo-500/20 text-indigo-300":"text-gray-400 hover:text-gray-200"}`,title:d||"Record mobile app interactions",children:[e.jsx(Gr,{size:12}),"Mobile"]})]})}function Xn(t){const[n,u]=s.useState([]),[d,l]=s.useState((t==null?void 0:t.provider)||""),[N,p]=s.useState(t!=null&&t.provider&&t.model||""),A=s.useRef(!!(t!=null&&t.provider));return s.useEffect(()=>{let E=!0;return ua().then(C=>{var L;if(!E)return;const k=[],T=C.effectiveProvider||C.defaultProvider;for(const[H,D]of Object.entries(C.providers||{})){if(zo.has(H))continue;const V=D;if(!V.hasApiKey&&!V.isLocal)continue;if(H==="testver"){k.push({provider:H,models:[""]});continue}const U=Array.isArray(V.models)&&V.models.length>0?V.models:[V.model].filter(Boolean);U.length>0&&k.push({provider:H,models:U})}u(k);const S=(L=C.providers)==null?void 0:L[T];S&&!A.current&&(l(T),p(T==="testver"?"":S.activeModel||S.model||""))}).catch(()=>{}),()=>{E=!1}},[]),{providerModels:n,selectedProvider:d,selectedModel:N,select:(E,C)=>{l(E),p(C)},setSelectedProvider:l,setSelectedModel:p}}function Yr({providerModels:t,selectedProvider:n,selectedModel:u,onPick:d,disabled:l=!1,title:N="Select model for code generation",size:p="md"}){const[A,I]=s.useState(!1),E=s.useRef(null);if(s.useEffect(()=>{if(!A)return;const k=T=>{var S;T.key==="Escape"&&(T.stopPropagation(),I(!1),(S=E.current)==null||S.focus())};return document.addEventListener("keydown",k,!0),()=>document.removeEventListener("keydown",k,!0)},[A]),s.useEffect(()=>{l&&I(!1)},[l]),t.length===0)return null;const C=n==="testver"?"Testver":u||"Model";return e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsxs("button",{ref:E,type:"button",onClick:()=>I(k=>!k),disabled:l,"aria-haspopup":"listbox","aria-expanded":A,"aria-label":`Model: ${C}`,className:`flex items-center gap-1.5 px-2.5 ${p==="sm"?"py-2":"py-2.5"} rounded-lg text-xs font-mono text-gray-400 bg-white dark:bg-white/[0.04] border border-gray-200 dark:border-white/10 hover:border-gray-300 dark:hover:border-white/20 hover:text-gray-200 transition-colors max-w-[180px] disabled:opacity-50`,title:N,children:[e.jsx(bn,{provider:n,size:14}),e.jsx("span",{className:"truncate",children:C}),e.jsx(ls,{size:11,className:`flex-shrink-0 transition-transform ${A?"rotate-180":""}`})]}),A&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>I(!1)}),e.jsx("div",{role:"listbox","aria-label":"Models",className:"absolute bottom-full left-0 mb-1 w-64 bg-surface-1 border border-white/10 rounded-xl shadow-xl z-50 py-1 max-h-72 overflow-y-auto",children:t.map(k=>e.jsxs("div",{role:"group","aria-label":k.provider,children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 text-[10px] text-gray-600 uppercase tracking-wider font-semibold border-b border-white/5",children:[e.jsx(bn,{provider:k.provider,size:14}),k.provider]}),k.models.map(T=>{const S=T===u&&k.provider===n;return e.jsxs("button",{type:"button",role:"option","aria-selected":S,onClick:()=>{var L;d(k.provider,T),I(!1),(L=E.current)==null||L.focus()},className:`w-full flex items-center gap-2 px-3 py-2 text-left text-sm font-mono transition-colors ${S?"bg-brand-500/10 text-brand-300":"text-gray-400 hover:bg-brand-500/10 hover:text-gray-200"}`,children:[S&&e.jsx(ft,{size:12,className:"text-brand-400 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:k.provider==="testver"?"Testver — managed model":T})]},`${k.provider}-${T}`)})]},k.provider))})]})]})}const ei={indigo:"bg-indigo-500/10 text-indigo-700 dark:text-indigo-300 border-indigo-500/25 hover:bg-indigo-500/20",brand:"bg-brand-500/15 text-brand-300 border-brand-500/25 hover:bg-brand-500/25",ghost:"bg-transparent text-gray-400 border-white/10 hover:text-gray-200 hover:bg-surface-2"};function Xs({icon:t,label:n,hint:u,onClick:d,disabled:l=!1,compact:N=!1,tone:p="ghost"}){return e.jsx(Ct,{label:n,hint:u,children:e.jsxs("button",{type:"button",onClick:d,disabled:l,"aria-label":n,className:`inline-flex items-center justify-center gap-1.5 h-8 rounded-lg border text-xs font-medium whitespace-nowrap transition-colors
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,b as er,n as Mn}from"./vendor-react-CTbHBddL.js";import{b as Qr,aq as ia,ar as Or,as as la,at as zn,au as ca,av as In,aw as da,ax as qr,a7 as ua,ay as Pn,az as rn,aA as Dn,Q as xa,S as nn,T as an,aB as on,aC as pa,aD as ln,U as ma,aE as cn,aF as fa,aG as ha,aH as Fr,aI as gr,aJ as ga,aK as ba,aL as dn,aM as ya,aN as va,aO as br,aP as wa,aQ as ja,aR as Na,aS as ka,aT as un,V as Sa,aU as xn,X as Ca,W as Ra,aV as $a,aW as Ta,aX as Aa,aY as Ea,aZ as Ma,a_ as za,a$ as Ia,b0 as Pa,b1 as Da,b2 as Fa,b3 as La,x as Fn,b4 as _a,b5 as wr,b6 as Ha,b7 as Ka,b8 as Ba,b9 as pn,ba as mn,bb as fn,bc as Ua,bd as Oa,be as qa,bf as Ga,bg as Wa,bh as Va,bi as Ya,bj as Qa,bk as Xa,bl as Lr,bm as Ja,bn as Za,bo as eo,bp as to,bq as so,br as ro,bs as no,bt as ao,bu as oo}from"./index-BYVxKLrT.js";import{t as Yt,f as Rs}from"./formatTestName-BKd2Uqhs.js";import{a as Ln,f as _r}from"./formatDate-T65-Y6Mi.js";import{a as Xr,u as _n,c as jr}from"./vendor-query-BrzmPFT3.js";import{C as Hn}from"./ConfirmDialog-t7mpeeSN.js";import{u as Qt,X as gt,v as Jr,a0 as ve,bn as Kn,bs as As,bt as Bn,b7 as Es,b8 as at,ap as Ms,r as ft,f as ht,Z as Un,S as Js,l as $s,bu as Nr,bv as Zr,ac as zs,bw as Tr,al as en,aC as On,y as ls,bx as io,K as tn,J as Gr,a1 as Zs,by as lo,bz as co,bA as uo,a4 as Ht,bB as xo,bC as po,bD as mo,bE as fo,bF as ho,aG as go,ag as hn,b4 as tr,bG as bo,aI as vr,a2 as Ts,bd as qn,an as kr,bH as Qs,a_ as Sr,a6 as Ys,ah as yo,bI as vo,bJ as Gn,bK as wo,ba as Cr,b6 as jo,aa as No,bL as ko,bM as So,bN as Co}from"./vendor-icons-BKPiFyYV.js";import{P as Wr,A as Wn,a as Ro,L as $o,f as gn,b as To,T as Ao,C as Eo}from"./ChangesSummary-CY_Vb27i.js";import{A as Vn}from"./AIStreamUI-C3D989_6.js";import{D as Mo}from"./DiffViewer-BIU09a_i.js";import{H as zo,P as bn}from"./hiddenLlmProviders-CdhhNa5G.js";import{T as Vr}from"./TestverCreditsRing-DpMzl3h7.js";import{S as Io,L as Po}from"./SearchableDevicePicker-BYxYJNWl.js";import{u as Yn}from"./useTestExplorer-DT8frjCK.js";import"./useTabParam-ChbOedP1.js";import"./MediaModal-C5n6sHYi.js";const Do="\"'`“”‘’„‟‚‛«»‹›"'",Fo="?*+()[]{}|^$\\&<>%!;",Lo=t=>t.charCodeAt(0)<32||t.charCodeAt(0)===127;function _o(t){let n="";for(const u of t)Do.includes(u)||(u==="&"?n+=" and ":u==="%"?n+=" percent ":u==="+"?n+=" plus ":u===";"?n+=", ":Fo.includes(u)||Lo(u)?n+=" ":n+=u);return n.replace(/\s+/g," ").replace(/ ([,:.])/g,"$1").replace(/,(?=[,:])/g,"").trim().replace(/^[,:.\-\s]+|[,:\-\s]+$/g,"")}function Rr(t){const n=t.trim();if(!n)return null;const u=_o(n);return u===n.replace(/\s+/g," ")?null:u?`Saved as “${u}” — quotes and characters like ? * ( ) & stop a test from being run by name.`:"Use letters or numbers — quotes and characters like ? * ( ) & stop a test from being run by name."}const yn={recorded:{icon:e.jsx(ht,{size:14,className:"text-amber-400"}),label:"Recorded"},generated:{icon:e.jsx(ft,{size:14,className:"text-emerald-400"}),label:"Generated"},implemented:{icon:e.jsx(Un,{size:14,className:"text-blue-400"}),label:"Implemented"},draft:{icon:e.jsx(ht,{size:14,className:"text-gray-400"}),label:"Draft"}},vn={success:{icon:e.jsx(ft,{size:14,className:"text-emerald-400"}),label:"Generated"},failed:{icon:e.jsx(Ms,{size:14,className:"text-red-400"}),label:"Failed"},stopped:{icon:e.jsx(at,{size:12,className:"text-gray-400 fill-gray-400",strokeWidth:0}),label:"Stopped"}};function Ho(t){return t.outcome&&vn[t.outcome]?vn[t.outcome]:yn[t.status]||yn.recorded}function Ko(t){const n=Date.now()-t;return n<6e4?"Just now":n<36e5?`${Math.floor(n/6e4)}m ago`:n<864e5?`${Math.floor(n/36e5)}h ago`:n<6048e5?`${Math.floor(n/864e5)}d ago`:Ln(t)}function Bo(t){const n=new Date,u=new Date(n.getFullYear(),n.getMonth(),n.getDate()).getTime(),d=u-864e5,l=u-7*864e5,N={Today:[],Yesterday:[],"This Week":[],Earlier:[]};for(const p of t){const A=p.createdAt;A>=u?N.Today.push(p):A>=d?N.Yesterday.push(p):A>=l?N["This Week"].push(p):N.Earlier.push(p)}return Object.entries(N).filter(([,p])=>p.length>0).map(([p,A])=>({label:p,items:A}))}const Uo=["login","checkout","search","smoke","regression","e2e","navigation","form"];function Oo({onLoadSession:t,onClose:n,activeSessionId:u}){const d=Xr(),{toast:l}=Qr(),[N,p]=s.useState(""),[A,I]=s.useState(null),[E,C]=s.useState(!1),k=s.useRef({}),[T,S]=s.useState(null),[L,H]=s.useState(null),[D,V]=s.useState(""),[U,oe]=s.useState(null),[P,Y]=s.useState(""),[g,Z]=s.useState(null),{data:B,isLoading:ee}=_n({queryKey:["recording-history"],queryFn:()=>ia()}),J=jr({mutationFn:Or,onSuccess:()=>d.invalidateQueries({queryKey:["recording-history"]})}),ie=jr({mutationFn:({id:$,data:m})=>la($,m),onSuccess:()=>d.invalidateQueries({queryKey:["recording-history"]})}),se=s.useMemo(()=>{const $=(B==null?void 0:B.sessions)||[];return Array.isArray($)?$.filter(m=>m.status!=="draft"):[]},[B]),ue=s.useMemo(()=>{let $=se;if(N){const m=N.toLowerCase();$=$.filter(X=>(X.name||"").toLowerCase().includes(m)||(X.url||"").toLowerCase().includes(m))}return T&&($=$.filter(m=>Array.isArray(m.tags)&&m.tags.includes(T))),$},[se,N,T]),y=s.useMemo(()=>{const $=new Set;return se.forEach(m=>{Array.isArray(m.tags)&&m.tags.forEach(X=>$.add(X))}),Array.from($).sort()},[se]),R=s.useMemo(()=>{const $=new Set([...Uo,...y]);return Array.from($).sort()},[y]),v=s.useMemo(()=>Bo(ue),[ue]),W=async $=>{try{const m=await zn($);m&&t(m)}catch(m){l("error",`Couldn't open the recording: ${m}`)}},re=($,m)=>{const X=se.find(pe=>pe.id===$);if(!X)return;const w=Array.isArray(X.tags)?X.tags:[];w.includes(m)||(ie.mutate({id:$,data:{tags:[...w,m]}}),H(null),V(""))},$e=($,m)=>{const X=se.find(pe=>pe.id===$);if(!X)return;const w=Array.isArray(X.tags)?X.tags:[];ie.mutate({id:$,data:{tags:w.filter(pe=>pe!==m)}})};return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Qt,{size:16,className:"text-brand-400"}),e.jsx("span",{className:"text-sm font-semibold text-gray-200",children:"Recording History"}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-brand-500/10 text-brand-400 border border-brand-500/20",children:se.length})]}),e.jsx("button",{onClick:n,"aria-label":"Close history",className:"p-1 rounded hover:bg-white/10 text-gray-400 hover:text-gray-200",children:e.jsx(gt,{size:16})})]}),e.jsxs("div",{className:"px-4 py-2 space-y-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Jr,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{type:"text",value:N,onChange:$=>p($.target.value),placeholder:"Search recordings...",className:"w-full pl-8 pr-3 py-1.5 rounded-lg bg-surface-2 border border-white/5 text-xs text-gray-200 placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),y.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx("button",{onClick:()=>S(null),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${T?"text-gray-500 bg-surface-2 border border-white/5 hover:text-gray-300":"bg-brand-500/15 text-brand-300 border border-brand-500/25"}`,children:"All"}),y.map($=>e.jsx("button",{onClick:()=>S(T===$?null:$),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${T===$?"bg-brand-500/15 text-brand-300 border border-brand-500/25":"text-gray-500 bg-surface-2 border border-white/5 hover:text-gray-300"}`,children:$},$))]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-1",children:ee?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(ve,{size:20,className:"text-brand-400 animate-spin"})}):v.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Qt,{size:32,className:"text-gray-600 mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-gray-500",children:"No recordings yet"}),e.jsx("p",{className:"text-xs text-gray-600 mt-1",children:"Start a recording to see it here"})]}):v.map($=>e.jsxs("div",{className:"mb-3",children:[e.jsx("div",{className:"px-2 py-1",children:e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-gray-600",children:$.label})}),$.items.map(m=>{const X=Ho(m);return e.jsxs("div",{role:"button",tabIndex:0,"aria-label":`Open recording ${m.name}`,"aria-current":u===m.id?"true":void 0,className:`flex items-center gap-2 px-2 py-2 rounded-lg cursor-pointer group transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/50 ${u===m.id?"bg-brand-500/10":"hover:bg-gray-100 dark:hover:bg-gray-800"}`,onClick:()=>W(m.id),onKeyDown:w=>{w.target===w.currentTarget&&(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),W(m.id))},children:[X.icon,e.jsxs("div",{className:"flex-1 min-w-0",children:[U===m.id?e.jsx("input",{type:"text",value:P,onChange:w=>Y(w.target.value),onClick:w=>w.stopPropagation(),onBlur:()=>{P.trim()&&P.trim()!==m.name&&ie.mutate({id:m.id,data:{name:P.trim()}}),oe(null)},onKeyDown:w=>{w.key==="Enter"&&w.target.blur(),w.key==="Escape"&&oe(null)},autoFocus:!0,className:"text-sm text-gray-200 bg-surface-2 border border-brand-500/30 rounded px-1.5 py-0.5 w-full focus:outline-none focus:ring-1 focus:ring-brand-500"}):e.jsx("div",{className:"text-sm text-gray-200 truncate cursor-text",onDoubleClick:w=>{w.stopPropagation(),oe(m.id),Y(m.name)},title:"Double-click to rename",children:m.name}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[e.jsxs("span",{children:[m.actionCount," steps"]}),e.jsx("span",{children:Ko(m.createdAt)})]}),Array.isArray(m.tags)&&m.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",onClick:w=>w.stopPropagation(),children:m.tags.map(w=>e.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0 rounded-full text-[9px] font-medium bg-brand-500/10 text-brand-400 border border-brand-500/20",children:[w,e.jsx("button",{onClick:()=>Z({type:"remove-tag",sessionId:m.id,tag:w}),className:"hover:text-red-400 ml-0.5",title:`Remove tag "${w}"`,children:e.jsx(gt,{size:8})})]},w))}),L===m.id&&e.jsxs("div",{className:"mt-1 flex flex-wrap gap-1",onClick:w=>w.stopPropagation(),children:[R.filter(w=>!(m.tags||[]).includes(w)).map(w=>e.jsxs("button",{onClick:()=>re(m.id,w),className:"px-1.5 py-0 rounded-full text-[9px] text-gray-500 bg-surface-2 border border-white/5 hover:text-brand-400 hover:border-brand-500/20",children:["+ ",w]},w)),e.jsx("input",{type:"text",value:D,onChange:w=>V(w.target.value),placeholder:"custom...",className:"w-16 px-1 py-0 rounded text-[9px] bg-surface-2 border border-white/5 text-gray-200 placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500",onClick:w=>w.stopPropagation(),onKeyDown:w=>{w.key==="Enter"&&D.trim()&&re(m.id,D.trim().toLowerCase())}}),e.jsx("button",{onClick:w=>{w.stopPropagation(),H(null),V("")},className:"text-[9px] text-gray-500 hover:text-gray-300",children:"Done"})]})]}),e.jsxs("div",{className:"flex-shrink-0 relative",onClick:w=>w.stopPropagation(),children:[e.jsx("button",{ref:w=>{k.current[m.id]=w},onClick:()=>{if(A===m.id)I(null);else{const w=k.current[m.id];if(w){const pe=w.getBoundingClientRect(),Ie=window.innerHeight-pe.bottom;C(Ie<160)}I(m.id)}},className:"opacity-0 group-hover:opacity-100 p-1 rounded hover:bg-white/10 text-gray-500 hover:text-gray-300",children:e.jsx(Kn,{size:14})}),A===m.id&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>I(null)}),e.jsxs("div",{className:`absolute right-0 z-[60] rounded-lg shadow-xl py-1 w-[180px] bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 ${E?"bottom-full mb-1":"top-full mt-1"}`,children:[e.jsxs("button",{onClick:()=>{oe(m.id),Y(m.name),I(null)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-white/10 whitespace-nowrap",children:[e.jsx(As,{size:14})," Rename"]}),e.jsxs("button",{onClick:()=>{H(L===m.id?null:m.id),I(null)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-white/10 whitespace-nowrap",children:[e.jsx(Bn,{size:14})," Add Tags"]}),e.jsxs("button",{onClick:()=>{Z({type:"delete-session",sessionId:m.id,sessionName:m.name}),I(null)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-red-500 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 whitespace-nowrap",children:[e.jsx(Es,{size:14})," Delete"]})]})]})]})]},m.id)})]},$.label))}),e.jsx(Hn,{open:!!g,title:(g==null?void 0:g.type)==="delete-session"?"Delete recording?":(g==null?void 0:g.type)==="remove-tag"?"Remove tag?":"",description:(g==null?void 0:g.type)==="delete-session"?`Are you sure you want to delete "${g.sessionName||"this recording"}"? This will permanently remove the recorded actions, generated code history, and conversation. This action cannot be undone.`:(g==null?void 0:g.type)==="remove-tag"?`Are you sure you want to remove the tag "${g.tag}" from this recording? You can add it back later.`:"",confirmLabel:(g==null?void 0:g.type)==="delete-session"?"Delete":"Remove",onCancel:()=>Z(null),onConfirm:()=>{(g==null?void 0:g.type)==="delete-session"?J.mutate(g.sessionId):(g==null?void 0:g.type)==="remove-tag"&&$e(g.sessionId,g.tag),Z(null)}})]})}function Ct({label:t,hint:n,shortcut:u,children:d}){const l=s.useRef(null),N=s.useRef(null),[p,A]=s.useState(null),[I,E]=s.useState(null),C=()=>{var S;const T=(S=l.current)==null?void 0:S.getBoundingClientRect();T&&A(T)},k=()=>{A(null),E(null)};return s.useLayoutEffect(()=>{if(!p||!N.current)return;const T=N.current.getBoundingClientRect(),S=8,L=p.bottom+S+T.height<=window.innerHeight-8||p.top-S-T.height<8,H=p.left+p.width/2,D=Math.max(8,Math.min(H-T.width/2,window.innerWidth-T.width-8));E({left:D,top:L?p.bottom+S:p.top-S-T.height,below:L,arrowX:Math.max(10,Math.min(H-D,T.width-10))})},[p,t,n,u]),e.jsxs("span",{ref:l,className:"inline-flex",onMouseEnter:C,onMouseLeave:k,onFocus:C,onBlur:k,children:[d,p&&er.createPortal(e.jsxs("span",{ref:N,role:"tooltip",style:I?{left:I.left,top:I.top}:{left:0,top:0,visibility:"hidden"},className:"pointer-events-none fixed z-[75] animate-tooltip-in",children:[I&&e.jsx("span",{style:{left:I.arrowX},className:`absolute -translate-x-1/2 w-2 h-2 bg-[#111827] rotate-45 ring-1 ring-white/10 ${I.below?"-top-1":"-bottom-1"}`}),e.jsxs("span",{className:"relative flex flex-col gap-0.5 max-w-[260px] px-2.5 py-1.5 rounded-md bg-[#111827] text-white shadow-lg shadow-black/50 ring-1 ring-white/10",children:[e.jsxs("span",{className:"flex items-center gap-2 text-xs font-medium whitespace-nowrap",children:[t,u&&e.jsx("kbd",{className:"px-1 py-px rounded bg-white/15 text-[10px] font-mono font-normal text-white/90",children:u})]}),n&&e.jsx("span",{className:"text-[11px] leading-snug text-white/70",children:n})]})]}),document.body)]})}const wn={recorded:{icon:e.jsx(ht,{size:14,className:"text-amber-400"}),label:"Recorded"},generated:{icon:e.jsx(ft,{size:14,className:"text-emerald-400"}),label:"Generated"},implemented:{icon:e.jsx(Un,{size:14,className:"text-blue-400"}),label:"Implemented"},draft:{icon:e.jsx(ht,{size:14,className:"text-gray-400"}),label:"Draft"}},jn={success:{icon:e.jsx(ft,{size:14,className:"text-emerald-400"}),label:"Generated"},failed:{icon:e.jsx(Ms,{size:14,className:"text-red-400"}),label:"Failed"},stopped:{icon:e.jsx(at,{size:12,className:"text-gray-400 fill-gray-400",strokeWidth:0}),label:"Stopped"}};function qo(t){return t.outcome&&jn[t.outcome]?jn[t.outcome]:wn[t.status]||wn.recorded}function Go(t){const n=Date.now()-t;return n<6e4?"Just now":n<36e5?`${Math.floor(n/6e4)}m ago`:n<864e5?`${Math.floor(n/36e5)}h ago`:n<6048e5?`${Math.floor(n/864e5)}d ago`:Ln(t)}function Wo(t){const n=new Date,u=new Date(n.getFullYear(),n.getMonth(),n.getDate()).getTime(),d=u-864e5,l=u-7*864e5,N={Today:[],Yesterday:[],"This Week":[],Earlier:[]};for(const p of t){const A=p.createdAt;A>=u?N.Today.push(p):A>=d?N.Yesterday.push(p):A>=l?N["This Week"].push(p):N.Earlier.push(p)}return Object.entries(N).filter(([,p])=>p.length>0).map(([p,A])=>({label:p,items:A}))}const Vo=["login","checkout","search","smoke","regression","e2e","navigation","form"];function Hr({open:t,onClose:n,onLoad:u,activeSessionId:d}){const l=Xr(),[N,p]=s.useState(""),[A,I]=s.useState(null),[E,C]=s.useState(!1),k=s.useRef({}),[T,S]=s.useState(null),[L,H]=s.useState(null),[D,V]=s.useState(""),[U,oe]=s.useState(null),[P,Y]=s.useState(""),[g,Z]=s.useState(null),{data:B,isLoading:ee}=_n({queryKey:["mobile-recording-history"],queryFn:()=>ca({limit:500}),enabled:t,refetchInterval:t?1e4:!1}),J=jr({mutationFn:In,onSuccess:()=>l.invalidateQueries({queryKey:["mobile-recording-history"]})}),ie=jr({mutationFn:({id:$,data:m})=>da($,m),onSuccess:()=>l.invalidateQueries({queryKey:["mobile-recording-history"]})}),se=s.useMemo(()=>{const $=(B==null?void 0:B.recordings)||[];return Array.isArray($)?$.filter(m=>m.status!=="draft"):[]},[B]),ue=s.useMemo(()=>{let $=se;if(N){const m=N.toLowerCase();$=$.filter(X=>(X.name||"").toLowerCase().includes(m)||(X.url||"").toLowerCase().includes(m)||(X.device||"").toLowerCase().includes(m))}return T&&($=$.filter(m=>Array.isArray(m.tags)&&m.tags.includes(T))),$},[se,N,T]),y=s.useMemo(()=>{const $=new Set;return se.forEach(m=>{Array.isArray(m.tags)&&m.tags.forEach(X=>$.add(X))}),Array.from($).sort()},[se]),R=s.useMemo(()=>{const $=new Set([...Vo,...y]);return Array.from($).sort()},[y]),v=s.useMemo(()=>Wo(ue),[ue]),W=async $=>{try{const m=await qr($);m!=null&&m.recording&&(u(m.recording),n())}catch{}},re=($,m)=>{const X=se.find(pe=>pe.id===$);if(!X)return;const w=Array.isArray(X.tags)?X.tags:[];w.includes(m)||(ie.mutate({id:$,data:{tags:[...w,m]}}),H(null),V(""))},$e=($,m)=>{const X=se.find(pe=>pe.id===$);if(!X)return;const w=Array.isArray(X.tags)?X.tags:[];ie.mutate({id:$,data:{tags:w.filter(pe=>pe!==m)}})};return t?e.jsxs("div",{className:"absolute inset-y-0 left-0 w-[300px] bg-surface-1 border-r border-white/10 z-40 flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Qt,{size:16,className:"text-brand-400"}),e.jsx("span",{className:"text-sm font-semibold text-gray-200",children:"Recording History"}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-brand-500/10 text-brand-400 border border-brand-500/20",children:se.length})]}),e.jsx("button",{onClick:n,className:"p-1 rounded hover:bg-white/10 text-gray-400 hover:text-gray-200",children:e.jsx(gt,{size:16})})]}),e.jsxs("div",{className:"px-4 py-2 space-y-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Jr,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{type:"text",value:N,onChange:$=>p($.target.value),placeholder:"Search recordings...",className:"w-full pl-8 pr-3 py-1.5 rounded-lg bg-surface-2 border border-white/5 text-xs text-gray-200 placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500"})]}),y.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx("button",{onClick:()=>S(null),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${T?"text-gray-500 bg-surface-2 border border-white/5 hover:text-gray-300":"bg-brand-500/15 text-brand-300 border border-brand-500/25"}`,children:"All"}),y.map($=>e.jsx("button",{onClick:()=>S(T===$?null:$),className:`px-2 py-0.5 rounded-full text-[10px] font-medium transition-colors ${T===$?"bg-brand-500/15 text-brand-300 border border-brand-500/25":"text-gray-500 bg-surface-2 border border-white/5 hover:text-gray-300"}`,children:$},$))]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-1",children:ee?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(ve,{size:20,className:"text-brand-400 animate-spin"})}):v.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Qt,{size:32,className:"text-gray-600 mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-gray-500",children:"No recordings yet"}),e.jsx("p",{className:"text-xs text-gray-600 mt-1",children:"Start a recording to see it here"})]}):v.map($=>e.jsxs("div",{className:"mb-3",children:[e.jsx("div",{className:"px-2 py-1",children:e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider text-gray-600",children:$.label})}),$.items.map(m=>{const X=qo(m);return e.jsxs("div",{className:`flex items-center gap-2 px-2 py-2 rounded-lg cursor-pointer group transition-colors ${d===m.id?"bg-brand-500/10":"hover:bg-gray-100 dark:hover:bg-gray-800"}`,onClick:()=>W(m.id),children:[X.icon,e.jsxs("div",{className:"flex-1 min-w-0",children:[U===m.id?e.jsx("input",{type:"text",value:P,onChange:w=>Y(w.target.value),onClick:w=>w.stopPropagation(),onBlur:()=>{P.trim()&&P.trim()!==m.name&&ie.mutate({id:m.id,data:{name:P.trim()}}),oe(null)},onKeyDown:w=>{w.key==="Enter"&&w.target.blur(),w.key==="Escape"&&oe(null)},autoFocus:!0,className:"text-sm text-gray-200 bg-surface-2 border border-brand-500/30 rounded px-1.5 py-0.5 w-full focus:outline-none focus:ring-1 focus:ring-brand-500"}):e.jsx("div",{className:"text-sm text-gray-200 truncate cursor-text",onDoubleClick:w=>{w.stopPropagation(),oe(m.id),Y(m.name)},title:"Double-click to rename",children:m.name}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[e.jsxs("span",{children:[m.actionCount," steps"]}),e.jsx("span",{children:Go(m.createdAt)})]}),Array.isArray(m.tags)&&m.tags.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",onClick:w=>w.stopPropagation(),children:m.tags.map(w=>e.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0 rounded-full text-[9px] font-medium bg-brand-500/10 text-brand-400 border border-brand-500/20",children:[w,e.jsx("button",{onClick:()=>Z({type:"remove-tag",sessionId:m.id,tag:w}),className:"hover:text-red-400 ml-0.5",title:`Remove tag "${w}"`,children:e.jsx(gt,{size:8})})]},w))}),L===m.id&&e.jsxs("div",{className:"mt-1 flex flex-wrap gap-1",onClick:w=>w.stopPropagation(),children:[R.filter(w=>!(m.tags||[]).includes(w)).map(w=>e.jsxs("button",{onClick:()=>re(m.id,w),className:"px-1.5 py-0 rounded-full text-[9px] text-gray-500 bg-surface-2 border border-white/5 hover:text-brand-400 hover:border-brand-500/20",children:["+ ",w]},w)),e.jsx("input",{type:"text",value:D,onChange:w=>V(w.target.value),placeholder:"custom...",className:"w-16 px-1 py-0 rounded text-[9px] bg-surface-2 border border-white/5 text-gray-200 placeholder:text-gray-600 focus:outline-none focus:ring-1 focus:ring-brand-500",onClick:w=>w.stopPropagation(),onKeyDown:w=>{w.key==="Enter"&&D.trim()&&re(m.id,D.trim().toLowerCase())}}),e.jsx("button",{onClick:w=>{w.stopPropagation(),H(null),V("")},className:"text-[9px] text-gray-500 hover:text-gray-300",children:"Done"})]})]}),e.jsxs("div",{className:"flex-shrink-0 relative",onClick:w=>w.stopPropagation(),children:[e.jsx("button",{ref:w=>{k.current[m.id]=w},onClick:()=>{if(A===m.id)I(null);else{const w=k.current[m.id];if(w){const pe=w.getBoundingClientRect(),Ie=window.innerHeight-pe.bottom;C(Ie<160)}I(m.id)}},className:"opacity-0 group-hover:opacity-100 p-1 rounded hover:bg-white/10 text-gray-500 hover:text-gray-300",children:e.jsx(Kn,{size:14})}),A===m.id&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>I(null)}),e.jsxs("div",{className:`absolute right-0 z-[60] rounded-lg shadow-xl py-1 w-[180px] bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 ${E?"bottom-full mb-1":"top-full mt-1"}`,children:[e.jsxs("button",{onClick:()=>{oe(m.id),Y(m.name),I(null)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-white/10 whitespace-nowrap",children:[e.jsx(As,{size:14})," Rename"]}),e.jsxs("button",{onClick:()=>{H(L===m.id?null:m.id),I(null)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-white/10 whitespace-nowrap",children:[e.jsx(Bn,{size:14})," Add Tags"]}),e.jsxs("button",{onClick:()=>{Z({type:"delete-session",sessionId:m.id,sessionName:m.name}),I(null)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-red-500 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-500/10 whitespace-nowrap",children:[e.jsx(Es,{size:14})," Delete"]})]})]})]})]},m.id)})]},$.label))}),e.jsx(Hn,{open:!!g,title:(g==null?void 0:g.type)==="delete-session"?"Delete recording?":(g==null?void 0:g.type)==="remove-tag"?"Remove tag?":"",description:(g==null?void 0:g.type)==="delete-session"?`Are you sure you want to delete "${g.sessionName||"this recording"}"? This will permanently remove the recorded actions, generated code, and healing manifest references. This action cannot be undone.`:(g==null?void 0:g.type)==="remove-tag"?`Are you sure you want to remove the tag "${g.tag}" from this recording? You can add it back later.`:"",confirmLabel:(g==null?void 0:g.type)==="delete-session"?"Delete":"Remove",onCancel:()=>Z(null),onConfirm:()=>{(g==null?void 0:g.type)==="delete-session"?J.mutate(g.sessionId):(g==null?void 0:g.type)==="remove-tag"&&$e(g.sessionId,g.tag),Z(null)}})]}):null}function Kr({screenshot:t,screenshotSize:n,elementRect:u,step:d,description:l,onClose:N}){const p=s.useRef(null),[A,I]=s.useState(null);s.useEffect(()=>{const k=T=>{T.key==="Escape"&&N()};return document.addEventListener("keydown",k),()=>document.removeEventListener("keydown",k)},[N]),s.useLayoutEffect(()=>{if(!p.current)return;const k=()=>{var L;const S=(L=p.current)==null?void 0:L.getBoundingClientRect();S&&I({width:S.width,height:S.height})};k(),window.addEventListener("resize",k);const T=setInterval(k,250);return()=>{window.removeEventListener("resize",k),clearInterval(T)}},[]);const E=(()=>{if(!u||!n||!A)return null;const k=A.width/n.width,T=A.height/n.height;return{left:u.x*k,top:u.y*T,width:u.width*k,height:u.height*T}})(),C=e.jsx("div",{className:"fixed inset-0 z-[1100] flex items-center justify-center bg-black/70 backdrop-blur-sm",onClick:N,role:"dialog","aria-label":`Step ${d} screenshot`,children:e.jsxs("div",{className:"relative max-w-[92vw] max-h-[92vh] flex flex-col",onClick:k=>k.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-surface-1 border border-white/10 rounded-t-lg",children:[e.jsx("span",{className:"inline-flex items-center justify-center w-6 h-6 rounded bg-blue-500/20 text-blue-300 text-[11px] font-bold",children:d}),e.jsx("span",{className:"text-[13px] text-gray-200 truncate flex-1",children:l}),e.jsx("button",{onClick:N,className:"p-1.5 rounded-md text-gray-400 hover:text-gray-100 hover:bg-white/10 transition-colors","aria-label":"Close preview",children:e.jsx(gt,{size:14})})]}),e.jsxs("div",{className:"relative bg-black border border-t-0 border-white/10 rounded-b-lg overflow-hidden flex items-center justify-center",children:[e.jsx("img",{ref:p,src:t,alt:l,className:"block max-w-[92vw] max-h-[82vh] w-auto h-auto",draggable:!1}),E&&e.jsx("div",{className:"absolute pointer-events-none border-[3px] border-red-400 rounded-sm",style:{left:E.left,top:E.top,width:E.width,height:E.height,boxShadow:"0 0 0 9999px rgba(0,0,0,0.35), 0 0 18px rgba(239,68,68,0.5), inset 0 0 0 1px rgba(255,255,255,0.45)"}})]}),e.jsxs("div",{className:"absolute bottom-2 left-1/2 -translate-x-1/2 text-[10px] text-gray-400 bg-black/60 px-2 py-1 rounded",children:["Press ",e.jsx("kbd",{className:"px-1 py-0.5 rounded bg-white/10 text-gray-200 text-[9px] font-mono",children:"Esc"})," or click outside to close"]})]})});return er.createPortal(C,document.body)}function Nn({entries:t,busy:n,onPermission:u,onOpenScreenshot:d}){const l=s.useRef(null);return s.useEffect(()=>{l.current&&(l.current.scrollTop=l.current.scrollHeight)},[t,n]),t.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center text-gray-500 text-sm gap-2",children:n?e.jsxs(e.Fragment,{children:[e.jsx(ve,{size:14,className:"animate-spin"}),"Waiting for the AI to start…"]}):e.jsx(e.Fragment,{children:"No output yet."})}):e.jsxs("div",{ref:l,className:"flex-1 overflow-y-auto p-4 space-y-1",children:[t.map(N=>e.jsx(Yo,{entry:N,onPermission:u,onOpenScreenshot:d},N.id)),n&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-gray-500 mt-3 px-4",children:[e.jsx(ve,{size:11,className:"animate-spin"}),"Streaming…"]})]})}function Yo({entry:t,onPermission:n,onOpenScreenshot:u}){return t.kind==="recorded-action"?e.jsx(Xo,{entry:t,onOpenScreenshot:u}):t.kind==="system"?e.jsxs("div",{className:"flex items-start gap-2 px-4 py-2",children:[e.jsx(Js,{size:12,className:"text-brand-400 mt-0.5 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-gray-400",children:t.message})]}):t.kind==="status"?e.jsxs("div",{className:"flex items-start gap-2 px-4 py-1",children:[e.jsx(Js,{size:10,className:"text-gray-500 mt-0.5 flex-shrink-0"}),e.jsx("span",{className:"text-[11px] text-gray-500 italic",children:t.message})]}):t.kind==="text"?e.jsx("div",{className:"flex items-start",children:e.jsx("div",{className:"px-4 py-2.5 min-w-0 max-w-[85%] overflow-hidden text-sm text-gray-300",children:e.jsx(Vn,{text:t.content})})}):t.kind==="tool"?e.jsx(Jo,{entry:t}):t.kind==="file-diff"?e.jsx("div",{className:"py-1",children:e.jsx(Mo,{diffs:[{filePath:t.filePath,diffType:t.diffType??"modified",diff:t.diff,linesAdded:t.linesAdded??0,linesRemoved:t.linesRemoved??0,timestamp:Date.now()}]})}):t.kind==="permission"&&n?e.jsx(Zo,{entry:t,onPermission:n}):t.kind==="permission"?null:t.kind==="error"?e.jsxs("div",{className:"flex items-start gap-2 px-4 py-2",children:[e.jsx($s,{size:12,className:"text-red-400 mt-0.5 flex-shrink-0"}),e.jsx("span",{className:"text-xs text-red-400",children:t.message})]}):t.kind==="user"?e.jsx("div",{className:"flex justify-end px-4 py-2",children:e.jsx("div",{className:"max-w-[75%] rounded-2xl rounded-tr-md px-4 py-2.5 bg-brand-600/90 text-white text-[13px] leading-relaxed shadow-sm whitespace-pre-wrap",children:t.text})}):null}const Qo={tap:"border-l-blue-500",type:"border-l-emerald-500",swipe:"border-l-purple-500",pressKey:"border-l-amber-500",assertion:"border-l-green-500",annotation:"border-l-fuchsia-500"};function Xo({entry:t,onOpenScreenshot:n}){const u=t.actionType==="tap"?Nr:t.actionType==="type"?As:t.actionType==="swipe"?Zr:t.actionType==="assertion"?zs:t.actionType==="annotation"?Tr:en,d=Qo[t.actionType]||"border-l-gray-500";return e.jsxs("div",{className:`flex items-center gap-2.5 mx-3 my-0.5 pl-2 pr-2 py-1 rounded-r-md border-l-[3px] ${d} bg-black/[0.02] dark:bg-white/[0.02] hover:bg-black/[0.05] dark:hover:bg-white/[0.06] transition-colors duration-100`,children:[e.jsx("span",{className:"text-[11px] text-gray-500 w-4 text-right tabular-nums flex-shrink-0",children:t.stepNum}),t.screenshot?e.jsx("button",{type:"button",onClick:()=>n==null?void 0:n({screenshot:t.screenshot,screenshotSize:t.screenshotSize,elementRect:t.elementRect,step:t.stepNum,description:t.description}),className:"flex-shrink-0 rounded overflow-hidden border border-black/10 dark:border-white/10 hover:ring-2 hover:ring-brand-400/50 transition-all",title:"View screenshot",children:e.jsx("img",{src:t.screenshot,alt:"",className:"w-7 h-11 object-cover object-top"})}):e.jsx("div",{className:"w-7 h-11 rounded bg-black/5 dark:bg-white/5 flex items-center justify-center flex-shrink-0",children:e.jsx(u,{size:12,className:"text-gray-500"})}),e.jsx(u,{size:13,className:"text-gray-500 dark:text-gray-400 flex-shrink-0"}),(t.actionType==="assertion"||t.actionType==="annotation")&&e.jsx("span",{className:`flex-shrink-0 text-[9px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded ${t.actionType==="annotation"?"text-violet-600 dark:text-violet-400 bg-violet-500/10":"text-green-600 dark:text-green-400 bg-green-500/10"}`,children:t.actionType==="annotation"?"annotate":"assert"}),e.jsx("span",{className:"text-[13px] text-gray-700 dark:text-gray-300 truncate",children:t.description})]})}function Jo({entry:t}){const[n,u]=s.useState(!1),d=t.phase==="start"?e.jsx(ve,{size:11,className:"animate-spin text-blue-400"}):t.phase==="complete"?e.jsx(ft,{size:11,className:"text-emerald-400"}):t.phase==="error"?e.jsx(Ms,{size:11,className:"text-red-400"}):e.jsx(On,{size:11,className:"text-amber-400"}),l=!!(t.result||t.error||t.args);return e.jsxs("div",{className:"my-0.5",children:[e.jsxs("button",{onClick:()=>l&&u(N=>!N),className:`inline-flex max-w-full items-center gap-2 px-4 py-1.5 rounded-lg text-left transition-colors ${l?"hover:bg-white/[0.03] cursor-pointer":"cursor-default"}`,children:[d,e.jsx("span",{className:"text-[11px] font-mono text-gray-500",children:t.toolName}),t.phase==="error"&&t.error&&e.jsx("span",{className:"text-[10px] text-red-400 truncate max-w-[200px]",children:t.error}),l&&t.phase!=="start"&&e.jsx(ls,{size:10,className:`text-gray-600 transition-transform ${n?"rotate-180":""}`})]}),n&&l&&e.jsxs("div",{className:"mt-1 max-h-[200px] overflow-auto rounded-lg bg-black/30 border border-white/5 p-2.5",children:[t.args&&e.jsx("div",{className:"text-[10px] font-mono text-gray-500 mb-1 break-all",children:t.args}),t.result&&e.jsx("div",{className:"text-[10px] font-mono text-gray-400 break-all whitespace-pre-wrap",children:String(t.result).slice(0,2e3)}),t.error&&e.jsx("div",{className:"text-[10px] font-mono text-red-400 break-all",children:t.error})]})]})}function Zo({entry:t,onPermission:n}){return e.jsxs("div",{className:"mx-3 my-2 rounded-lg border border-amber-500/30 bg-amber-500/[0.08] p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-amber-200 font-semibold",children:[e.jsx(On,{size:12}),e.jsx("span",{children:"AI wants to use a tool that requires permission"})]}),e.jsxs("div",{className:"text-[12px] text-gray-200",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[e.jsx(io,{size:11,className:"text-gray-500"}),e.jsx("code",{className:"font-mono",children:t.toolName})]}),t.args&&e.jsx("pre",{className:"text-[10px] bg-surface-2 border border-white/5 rounded px-2 py-1 text-gray-300 whitespace-pre-wrap break-all max-h-32 overflow-y-auto",children:t.args}),t.fullPath&&e.jsx("div",{className:"text-[10px] text-gray-500 mt-1 font-mono truncate",children:t.fullPath})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>n(t.permissionId,!0,!1),className:"px-2.5 py-1 rounded-md bg-emerald-500/20 text-emerald-200 border border-emerald-500/40 hover:bg-emerald-500/30 text-[11px] font-medium",children:"Allow once"}),e.jsx("button",{type:"button",onClick:()=>n(t.permissionId,!0,!0),className:"px-2.5 py-1 rounded-md bg-emerald-500/10 text-emerald-300 border border-emerald-500/30 hover:bg-emerald-500/20 text-[11px]",children:"Always allow"}),e.jsx("button",{type:"button",onClick:()=>n(t.permissionId,!1,!1),className:"px-2.5 py-1 rounded-md bg-red-500/15 text-red-300 border border-red-500/30 hover:bg-red-500/25 text-[11px]",children:"Deny"})]})]})}function Qn({value:t,onChange:n,disabled:u=!1}){const d=u?"Finish or stop the current recording first":void 0;return e.jsxs("div",{role:"radiogroup","aria-label":"Recorder",className:`inline-flex rounded-lg border border-white/10 bg-white/5 p-0.5 text-xs ${u?"opacity-50":""}`,title:d,children:[e.jsxs("button",{type:"button",role:"radio","aria-checked":t==="web",disabled:u,onClick:()=>n("web"),className:`inline-flex items-center gap-1 px-2 py-1 rounded-md transition-colors disabled:cursor-not-allowed ${t==="web"?"bg-red-500/20 text-red-300":"text-gray-400 hover:text-gray-200"}`,title:d||"Record browser interactions",children:[e.jsx(tn,{size:12}),"Web"]}),e.jsxs("button",{type:"button",role:"radio","aria-checked":t==="mobile",disabled:u,onClick:()=>n("mobile"),className:`inline-flex items-center gap-1 px-2 py-1 rounded-md transition-colors disabled:cursor-not-allowed ${t==="mobile"?"bg-indigo-500/20 text-indigo-300":"text-gray-400 hover:text-gray-200"}`,title:d||"Record mobile app interactions",children:[e.jsx(Gr,{size:12}),"Mobile"]})]})}function Xn(t){const[n,u]=s.useState([]),[d,l]=s.useState((t==null?void 0:t.provider)||""),[N,p]=s.useState(t!=null&&t.provider&&t.model||""),A=s.useRef(!!(t!=null&&t.provider));return s.useEffect(()=>{let E=!0;return ua().then(C=>{var L;if(!E)return;const k=[],T=C.effectiveProvider||C.defaultProvider;for(const[H,D]of Object.entries(C.providers||{})){if(zo.has(H))continue;const V=D;if(!V.hasApiKey&&!V.isLocal)continue;if(H==="testver"){k.push({provider:H,models:[""]});continue}const U=Array.isArray(V.models)&&V.models.length>0?V.models:[V.model].filter(Boolean);U.length>0&&k.push({provider:H,models:U})}u(k);const S=(L=C.providers)==null?void 0:L[T];S&&!A.current&&(l(T),p(T==="testver"?"":S.activeModel||S.model||""))}).catch(()=>{}),()=>{E=!1}},[]),{providerModels:n,selectedProvider:d,selectedModel:N,select:(E,C)=>{l(E),p(C)},setSelectedProvider:l,setSelectedModel:p}}function Yr({providerModels:t,selectedProvider:n,selectedModel:u,onPick:d,disabled:l=!1,title:N="Select model for code generation",size:p="md"}){const[A,I]=s.useState(!1),E=s.useRef(null);if(s.useEffect(()=>{if(!A)return;const k=T=>{var S;T.key==="Escape"&&(T.stopPropagation(),I(!1),(S=E.current)==null||S.focus())};return document.addEventListener("keydown",k,!0),()=>document.removeEventListener("keydown",k,!0)},[A]),s.useEffect(()=>{l&&I(!1)},[l]),t.length===0)return null;const C=n==="testver"?"Testver":u||"Model";return e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsxs("button",{ref:E,type:"button",onClick:()=>I(k=>!k),disabled:l,"aria-haspopup":"listbox","aria-expanded":A,"aria-label":`Model: ${C}`,className:`flex items-center gap-1.5 px-2.5 ${p==="sm"?"py-2":"py-2.5"} rounded-lg text-xs font-mono text-gray-400 bg-white dark:bg-white/[0.04] border border-gray-200 dark:border-white/10 hover:border-gray-300 dark:hover:border-white/20 hover:text-gray-200 transition-colors max-w-[180px] disabled:opacity-50`,title:N,children:[e.jsx(bn,{provider:n,size:14}),e.jsx("span",{className:"truncate",children:C}),e.jsx(ls,{size:11,className:`flex-shrink-0 transition-transform ${A?"rotate-180":""}`})]}),A&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>I(!1)}),e.jsx("div",{role:"listbox","aria-label":"Models",className:"absolute bottom-full left-0 mb-1 w-64 bg-surface-1 border border-white/10 rounded-xl shadow-xl z-50 py-1 max-h-72 overflow-y-auto",children:t.map(k=>e.jsxs("div",{role:"group","aria-label":k.provider,children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 text-[10px] text-gray-600 uppercase tracking-wider font-semibold border-b border-white/5",children:[e.jsx(bn,{provider:k.provider,size:14}),k.provider]}),k.models.map(T=>{const S=T===u&&k.provider===n;return e.jsxs("button",{type:"button",role:"option","aria-selected":S,onClick:()=>{var L;d(k.provider,T),I(!1),(L=E.current)==null||L.focus()},className:`w-full flex items-center gap-2 px-3 py-2 text-left text-sm font-mono transition-colors ${S?"bg-brand-500/10 text-brand-300":"text-gray-400 hover:bg-brand-500/10 hover:text-gray-200"}`,children:[S&&e.jsx(ft,{size:12,className:"text-brand-400 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:k.provider==="testver"?"Testver — managed model":T})]},`${k.provider}-${T}`)})]},k.provider))})]})]})}const ei={indigo:"bg-indigo-500/10 text-indigo-700 dark:text-indigo-300 border-indigo-500/25 hover:bg-indigo-500/20",brand:"bg-brand-500/15 text-brand-300 border-brand-500/25 hover:bg-brand-500/25",ghost:"bg-transparent text-gray-400 border-white/10 hover:text-gray-200 hover:bg-surface-2"};function Xs({icon:t,label:n,hint:u,onClick:d,disabled:l=!1,compact:N=!1,tone:p="ghost"}){return e.jsx(Ct,{label:n,hint:u,children:e.jsxs("button",{type:"button",onClick:d,disabled:l,"aria-label":n,className:`inline-flex items-center justify-center gap-1.5 h-8 rounded-lg border text-xs font-medium whitespace-nowrap transition-colors
3
3
  disabled:opacity-40 disabled:pointer-events-none ${N?"w-8":"px-3"} ${ei[p]}`,children:[t,!N&&e.jsx("span",{children:n})]})})}function $r({kind:t,size:n=12}){return t==="data"?e.jsx(Zs,{size:n,className:"text-teal-500 flex-shrink-0"}):t==="test"?e.jsx(lo,{size:n,className:"text-blue-500 flex-shrink-0"}):t==="step"?e.jsx(co,{size:n,className:"text-violet-500 flex-shrink-0"}):e.jsx(uo,{size:n,className:"text-indigo-500 flex-shrink-0"})}function kn(t,n){const u=t.slice(0,n),d=/(^|[\s(])@([^\s@]{0,60})$/.exec(u);return d?{start:u.length-d[2].length-1,query:d[2]}:null}function Jn({value:t,onChange:n,references:u,onReferencesChange:d,placeholder:l,rows:N=3,autoFocus:p=!1,kinds:A,ariaLabel:I,onSubmit:E,textareaRef:C,size:k="md"}){const T=s.useRef(null),S=C??T,[L,H]=s.useState(null),[D,V]=s.useState([]),[U,oe]=s.useState(!1),[P,Y]=s.useState(0),g=s.useRef(0),Z=s.useRef(null),[B,ee]=s.useState(null),J=()=>{const y=S.current;if(!y)return;const R=y.getBoundingClientRect(),v=260,W=window.innerHeight-R.bottom-12,re=R.top-12,$e=W<Math.min(v,180)&&re>W;ee($e?{left:R.left,width:R.width,bottom:window.innerHeight-R.top+4,maxHeight:Math.min(v,re)}:{left:R.left,width:R.width,top:R.bottom+4,maxHeight:Math.max(120,Math.min(v,W))})};s.useLayoutEffect(()=>{if(!L){ee(null);return}J()},[L!==null,t]),s.useEffect(()=>{if(!L)return;const y=R=>{var v;(v=Z.current)!=null&&v.contains(R.target)||J()};return window.addEventListener("scroll",y,!0),window.addEventListener("resize",y),()=>{window.removeEventListener("scroll",y,!0),window.removeEventListener("resize",y)}},[L!==null]),s.useEffect(()=>{var y,R;(R=(y=Z.current)==null?void 0:y.querySelector('[aria-selected="true"]'))==null||R.scrollIntoView({block:"nearest"})},[P]),s.useEffect(()=>{var y;p&&((y=S.current)==null||y.focus())},[p,S]),s.useEffect(()=>{if(!L){V([]);return}const y=++g.current;oe(!0);const R=setTimeout(()=>{Pn(L.query,A,20).then(v=>{g.current===y&&(V(v.items||[]),Y(0))}).catch(()=>{g.current===y&&V([])}).finally(()=>{g.current===y&&oe(!1)})},150);return()=>clearTimeout(R)},[L==null?void 0:L.query,L!==null]);const ie=(y,R)=>{n(y),H(kn(y,R))},se=y=>{const R=S.current;if(!R||!L)return;const v=R.selectionStart??t.length,W=`@${y.kind==="method"&&y.name?y.className?`${y.className}.${y.name}`:y.name:y.label} `,re=t.slice(0,L.start)+W+t.slice(v);n(re);const{detail:$e,...$}=y;u.some(m=>m.kind===y.kind&&m.label===y.label)||d([...u,$]),H(null),requestAnimationFrame(()=>{R.focus();const m=L.start+W.length;R.setSelectionRange(m,m)})},ue=y=>{if(L&&D.length>0){if(y.key==="ArrowDown"){y.preventDefault(),Y(R=>(R+1)%D.length);return}if(y.key==="ArrowUp"){y.preventDefault(),Y(R=>(R-1+D.length)%D.length);return}if(y.key==="Enter"||y.key==="Tab"){y.preventDefault(),se(D[P]);return}}if(L&&y.key==="Escape"){y.preventDefault(),y.stopPropagation(),H(null);return}y.key==="Enter"&&(y.ctrlKey||y.metaKey)&&E&&(y.preventDefault(),E())};return e.jsxs("div",{className:"relative",children:[e.jsx("textarea",{ref:S,value:t,rows:N,"aria-label":I,placeholder:l,onChange:y=>ie(y.target.value,y.target.selectionStart??y.target.value.length),onClick:y=>H(kn(t,y.target.selectionStart??t.length)),onKeyDown:ue,onBlur:()=>setTimeout(()=>H(null),150),className:`w-full rounded-lg bg-surface-2 border border-white/10 text-gray-200 placeholder-gray-500 focus:outline-none focus:border-brand-500/50 resize-y ${k==="lg"?"px-4 py-3 text-[15px] leading-relaxed":"px-3 py-2 text-sm"}`}),L&&B&&er.createPortal(e.jsxs("div",{ref:Z,role:"listbox","aria-label":"Project code and data",onMouseDown:y=>y.preventDefault(),style:{left:B.left,width:B.width,top:B.top,bottom:B.bottom,maxHeight:B.maxHeight},className:"fixed z-[90] overflow-y-auto rounded-lg border border-white/10 bg-surface-1 shadow-xl py-1",children:[U&&D.length===0&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-gray-500",children:[e.jsx(ve,{size:12,className:"animate-spin"})," Searching the project…"]}),!U&&D.length===0&&e.jsx("div",{className:"px-3 py-2 text-xs text-gray-500",children:L.query?`Nothing in the project matches "${L.query}".`:"Type a name to search page objects, helpers, tests and test data."}),D.map((y,R)=>e.jsxs("button",{type:"button",role:"option","aria-selected":R===P,onMouseDown:v=>{v.preventDefault(),se(y)},onMouseEnter:()=>Y(R),className:`w-full flex items-start gap-2 px-3 py-1.5 text-left ${R===P?"bg-brand-500/10":"hover:bg-white/5"}`,children:[e.jsx("span",{className:"mt-0.5",children:e.jsx($r,{kind:y.kind,size:k==="lg"?14:12})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:`block font-mono text-gray-200 truncate ${k==="lg"?"text-sm":"text-xs"}`,children:y.label}),e.jsx("span",{className:`block text-gray-500 truncate ${k==="lg"?"text-xs":"text-[10px]"}`,children:y.detail})]})]},`${y.kind}:${y.label}:${y.file}`))]}),document.body),u.length>0&&e.jsx("div",{className:`flex flex-wrap mt-1.5 ${k==="lg"?"gap-1.5":"gap-1"}`,children:u.map(y=>e.jsxs("span",{className:`inline-flex items-center gap-1 max-w-full rounded border border-white/10 bg-surface-2 text-gray-300 ${k==="lg"?"px-2 py-1 text-xs":"px-1.5 py-0.5 text-[11px]"}`,title:y.file?`${y.file}${y.line?`:${y.line}`:""}`:y.label,children:[e.jsx($r,{kind:y.kind,size:k==="lg"?13:11}),e.jsx("span",{className:"font-mono truncate",children:y.label}),e.jsx("button",{type:"button","aria-label":`Remove reference ${y.label}`,onClick:()=>d(u.filter(R=>!(R.kind===y.kind&&R.label===y.label))),className:"text-gray-500 hover:text-red-400",children:e.jsx(gt,{size:10})})]},`${y.kind}:${y.label}`))})]})}const yr=[{kind:"reuse",label:"Use existing step",icon:e.jsx(xo,{size:15}),placeholder:"e.g. Log in as Admin using @LoginPage.loginAs"},{kind:"data",label:"Test data",icon:e.jsx(Zs,{size:15}),placeholder:"e.g. Pick the first in-stock product from @data/products.json"},{kind:"email",label:"Email / code",icon:e.jsx(po,{size:15}),placeholder:'e.g. Read the latest email with subject "Reset password" and keep its link'},{kind:"api",label:"API / setup",icon:e.jsx(mo,{size:15}),placeholder:"e.g. Create a user with POST /api/users and keep its id"},{kind:"wait",label:"Wait for",icon:e.jsx(fo,{size:15}),placeholder:'e.g. Wait until the order status shows "Shipped" (up to 60 s)'},{kind:"custom",label:"Custom",icon:e.jsx(ho,{size:15}),placeholder:"Describe what the test does at this point…"}],Br=[{value:"link",label:"the link in it",name:"emailLink"},{value:"code",label:"the verification code",name:"emailCode"},{value:"text",label:"its text",name:"emailText"}],ti=/^[A-Za-z_][A-Za-z0-9_]{0,63}$/;function Zn({open:t,mode:n,initial:u,replaceCount:d=0,onCancel:l,onSave:N}){const[p,A]=s.useState("custom"),[I,E]=s.useState(""),[C,k]=s.useState([]),[T,S]=s.useState(""),[L,H]=s.useState(""),[D,V]=s.useState(""),[U,oe]=s.useState("link"),[P,Y]=s.useState(!1),[g,Z]=s.useState(null),B=s.useRef(null);s.useEffect(()=>{t&&(A((u==null?void 0:u.customKind)||"custom"),E((u==null?void 0:u.instruction)||""),k((u==null?void 0:u.references)||[]),S(((u==null?void 0:u.outputs)||[]).join(", ")),H(""),V(""),oe("link"),Y(!1),Z(null))},[t]),s.useEffect(()=>{if(!t)return;const v=W=>{W.key==="Escape"&&!P&&l()};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[t,P,l]);const ee=(v,W,re)=>{const $e=Br.find(pe=>pe.value===re),$=v.trim()?` with subject containing "${v.trim()}"`:"",m=W.trim()?` sent to ${W.trim()}`:"";E(`Read the latest email${m}${$} and keep ${$e.label}`);const X=T.split(",").map(pe=>pe.trim()).filter(Boolean),w=Br.map(pe=>pe.name);(X.length===0||X.every(pe=>w.includes(pe)))&&S($e.name)};if(!t)return null;const J=T.split(",").map(v=>v.trim().replace(/^\{+|\}+$/g,"")).filter(Boolean),ie=J.find(v=>!ti.test(v)),se=I.trim().length>0&&!ie&&!P,ue=n==="edit"?"Edit custom step":n==="replace"?`Replace ${d} step${d===1?"":"s"} with a custom step`:"Add custom step",y=yr.find(v=>v.kind===p)??yr[yr.length-1],R=async()=>{if(se){Y(!0),Z(null);try{await N({instruction:I.trim(),customKind:p,references:C,outputs:J})}catch(v){Z(String((v==null?void 0:v.message)||v).replace(/^Error:\s*/,"")),Y(!1)}}};return er.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[80] flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60",onClick:()=>!P&&l()}),e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":ue,className:"relative w-[820px] max-w-[94vw] max-h-[92vh] flex flex-col bg-surface-1 rounded-2xl border border-white/10 shadow-2xl",children:[e.jsxs("div",{className:"flex items-start gap-4 px-7 pt-7 pb-5",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-indigo-500/15 flex items-center justify-center flex-shrink-0",children:e.jsx(Ht,{size:22,className:"text-indigo-500"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-xl font-semibold text-gray-100",children:ue}),e.jsx("p",{className:"text-sm text-gray-400 mt-1 leading-relaxed",children:n==="replace"?"The AI does this instead of the selected steps. They stay on the step as reference, and you can put them back.":"Something the test does that is not a click in the app. The AI writes the code for it at this position — reusing your project's code where it can."})]}),e.jsx("button",{type:"button",onClick:l,disabled:P,"aria-label":"Close",className:"p-1.5 rounded-lg text-gray-400 hover:text-gray-200 hover:bg-white/5",children:e.jsx(gt,{size:18})})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-7 pb-1",children:[e.jsx("div",{role:"radiogroup","aria-label":"Kind of step",className:"grid grid-cols-2 sm:grid-cols-3 gap-2 mb-5",children:yr.map(v=>e.jsxs("button",{type:"button",role:"radio","aria-checked":p===v.kind,onClick:()=>{var W;A(v.kind),v.kind==="email"&&!I.trim()&&ee(L,D,U),(W=B.current)==null||W.focus()},className:`flex items-center gap-2.5 px-3.5 py-2.5 rounded-lg text-sm font-medium border transition-colors ${p===v.kind?"bg-indigo-500/10 border-indigo-500/50 text-indigo-700 dark:text-indigo-300 ring-1 ring-indigo-500/20":"bg-surface-2 border-white/10 text-gray-400 hover:text-gray-200 hover:border-white/20"}`,children:[v.icon,v.label]},v.kind))}),p==="email"&&e.jsxs("div",{className:"grid grid-cols-3 gap-3 mb-5",children:[e.jsxs("label",{className:"text-xs font-medium text-gray-500",children:["Subject contains",e.jsx("input",{value:L,onChange:v=>{H(v.target.value),ee(v.target.value,D,U)},placeholder:"Reset password",className:"mt-1 w-full px-3 py-2 rounded-lg bg-surface-2 border border-white/10 text-sm text-gray-200 focus:outline-none focus:border-brand-500/50"})]}),e.jsxs("label",{className:"text-xs font-medium text-gray-500",children:["Sent to (optional)",e.jsx("input",{value:D,onChange:v=>{V(v.target.value),ee(L,v.target.value,U)},placeholder:"the new user",className:"mt-1 w-full px-3 py-2 rounded-lg bg-surface-2 border border-white/10 text-sm text-gray-200 focus:outline-none focus:border-brand-500/50"})]}),e.jsxs("label",{className:"text-xs font-medium text-gray-500",children:["Keep",e.jsx("select",{"aria-label":"Keep",value:U,onChange:v=>{const W=v.target.value;oe(W),ee(L,D,W)},className:"mt-1 w-full px-3 py-2 rounded-lg bg-surface-2 border border-white/10 text-sm text-gray-200 focus:outline-none focus:border-brand-500/50",children:Br.map(v=>e.jsx("option",{value:v.value,children:v.label},v.value))})]})]}),e.jsxs("label",{className:"block text-sm font-medium text-gray-300 mb-2",children:["What the step does ",e.jsx("span",{className:"text-red-400",children:"*"})]}),e.jsx(Jn,{textareaRef:B,value:I,onChange:E,references:C,onReferencesChange:k,placeholder:y.placeholder,rows:p==="email"?3:5,size:"lg",autoFocus:!0,ariaLabel:"What the step does",onSubmit:R}),e.jsxs("p",{className:"text-xs text-gray-500 mt-2",children:["Type ",e.jsx("kbd",{className:"px-1.5 py-0.5 rounded bg-surface-2 border border-white/10 font-mono",children:"@"})," to point at a page object, helper, test or test-data file in your project."]}),e.jsxs("label",{className:"block text-sm font-medium text-gray-300 mt-5 mb-2",children:["Saves values for later steps ",e.jsx("span",{className:"font-normal text-gray-500",children:"(optional)"})]}),e.jsx("input",{"aria-label":"Saves values for later steps",value:T,onChange:v=>S(v.target.value),placeholder:"e.g. resetLink, otpCode","aria-invalid":!!ie,className:`w-full px-4 py-2.5 rounded-lg bg-surface-2 border text-[15px] font-mono text-gray-200 placeholder-gray-500 focus:outline-none ${ie?"border-red-500/50":"border-white/10 focus:border-brand-500/50"}`}),e.jsx("p",{className:`text-xs mt-2 leading-relaxed ${ie?"text-red-500 dark:text-red-400":"text-gray-500"}`,children:ie?`"${ie}" can't be a value name — use letters, digits and _ (for example resetLink).`:"Names of what this step produces (a link, a code, an id). Later recorded steps can use them instead of the value you typed while recording."}),g&&e.jsx("p",{role:"alert",className:"mt-4 text-sm text-red-600 dark:text-red-400",children:g})]}),e.jsxs("div",{className:"flex gap-3 justify-end px-7 py-5 border-t border-black/5 dark:border-white/5",children:[e.jsx("button",{type:"button",onClick:l,disabled:P,className:"px-5 py-2.5 text-[15px] rounded-lg bg-surface-2 hover:bg-surface-3 text-gray-300",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:R,disabled:!se,className:"inline-flex items-center gap-2 px-5 py-2.5 text-[15px] rounded-lg bg-indigo-600 hover:bg-indigo-500 text-white font-medium shadow-sm disabled:opacity-50 disabled:cursor-not-allowed",children:[P&&e.jsx(ve,{size:14,className:"animate-spin"}),n==="edit"?"Save":n==="replace"?"Replace steps":"Add step"]})]})]})]}),document.body)}function ea({current:t,options:n,onPick:u,disabled:d=!1}){const[l,N]=s.useState(!1),[p,A]=s.useState(null),I=s.useRef(null),E=s.useRef(null),C=()=>{var S;if(l){N(!1);return}const T=(S=I.current)==null?void 0:S.getBoundingClientRect();if(T){const H=Math.max(8,Math.min(T.right-288,window.innerWidth-288-8)),D=window.innerHeight-T.bottom;A(D<260&&T.top>D?{left:H,bottom:window.innerHeight-T.top+4}:{left:H,top:T.bottom+4})}N(!0)};s.useEffect(()=>{if(!l)return;const T=H=>{var D;H.key==="Escape"&&(H.stopPropagation(),N(!1),(D=I.current)==null||D.focus())},S=H=>{var D,V;!((D=E.current)!=null&&D.contains(H.target))&&!((V=I.current)!=null&&V.contains(H.target))&&N(!1)},L=H=>{var D;(D=E.current)!=null&&D.contains(H.target)||N(!1)};return document.addEventListener("keydown",T,!0),document.addEventListener("mousedown",S),window.addEventListener("scroll",L,!0),window.addEventListener("resize",L),()=>{document.removeEventListener("keydown",T,!0),document.removeEventListener("mousedown",S),window.removeEventListener("scroll",L,!0),window.removeEventListener("resize",L)}},[l]);const k=T=>{var S;u(T),N(!1),(S=I.current)==null||S.focus()};return e.jsxs("div",{className:"relative",children:[e.jsx("button",{ref:I,type:"button",disabled:d,onClick:T=>{T.stopPropagation(),C()},title:"Use a value for this step","aria-label":"Use a value for this step","aria-haspopup":"listbox","aria-expanded":l,className:`p-1.5 rounded transition-colors disabled:opacity-40 ${t?"text-indigo-500":"text-gray-500 hover:text-indigo-500"} hover:bg-black/[0.06] dark:hover:bg-white/10`,children:e.jsx(go,{size:14})}),l&&p&&er.createPortal(e.jsxs("div",{ref:E,role:"listbox","aria-label":"Values",onClick:T=>T.stopPropagation(),style:{left:p.left,top:p.top,bottom:p.bottom},className:"fixed z-[70] w-72 max-h-72 overflow-y-auto rounded-lg border border-white/10 bg-surface-1 shadow-xl py-1",children:[e.jsx("div",{className:"px-3 py-1.5 text-[10px] uppercase tracking-wider text-gray-500 font-semibold",children:"This step uses"}),e.jsxs("button",{type:"button",role:"option","aria-selected":!t,onClick:()=>k(null),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left text-xs text-gray-300 hover:bg-white/5",children:[e.jsx("span",{className:"w-3",children:!t&&e.jsx(hn,{size:12,className:"text-brand-500"})}),"The value recorded (as typed)"]}),n.length===0&&e.jsx("div",{className:"px-3 py-2 text-[11px] text-gray-500",children:"No values yet — a custom step before this one can save one (e.g. a link from an email), or add test data when generating."}),n.map(T=>e.jsxs("button",{type:"button",role:"option","aria-selected":t===T.name,onClick:()=>k(T.name),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left hover:bg-white/5",children:[e.jsx("span",{className:"w-3",children:t===T.name&&e.jsx(hn,{size:12,className:"text-brand-500"})}),T.source==="data"?e.jsx(Zs,{size:12,className:"text-teal-500 flex-shrink-0"}):e.jsx(Ht,{size:12,className:"text-indigo-500 flex-shrink-0"}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-xs font-mono text-gray-200 truncate",children:`{${T.name}}`}),e.jsx("span",{className:"block text-[10px] text-gray-500 truncate",children:T.detail})]})]},T.name))]}),document.body)]})}function ta({settings:t,onChange:n,inputs:u,onMatch:d,disabled:l=!1}){var ie,se,ue,y;const[N,p]=s.useState(!1),[A,I]=s.useState(""),[E,C]=s.useState([]),[k,T]=s.useState(!1),[S,L]=s.useState(!1),[H,D]=s.useState(null),[V,U]=s.useState(null),[oe,P]=s.useState(!!((ie=t==null?void 0:t.before)!=null&&ie.text)),Y=s.useRef(null),g=t==null?void 0:t.testData,Z=s.useRef(t);Z.current=t;const B=R=>{const v={...Z.current||{},...R};v.testData||delete v.testData,(!v.before||!v.before.text.trim())&&delete v.before;const W=v.testData||v.before?v:null;Z.current=W,n(W)};s.useEffect(()=>{if(!N)return;let R=!0;T(!0);const v=setTimeout(()=>{Pn(A,["data"],25).then(W=>{R&&C(W.items||[])}).catch(()=>{R&&C([])}).finally(()=>{R&&T(!1)})},150);return()=>{R=!1,clearTimeout(v)}},[N,A]),s.useEffect(()=>{var R;N&&((R=Y.current)==null||R.focus())},[N]),s.useEffect(()=>{if(!(g!=null&&g.file)){U(null);return}let R=!0;return rn(g.file).then(v=>{R&&U({columns:v.columns,values:v.firstRow,rowCount:v.rowCount})}).catch(()=>{R&&U(null)}),()=>{R=!1}},[g==null?void 0:g.file]);const ee=async R=>{L(!0),D(null);try{const v=await rn(R);B({testData:{file:v.file,columns:v.columns,perRow:!1}}),U({columns:v.columns,values:v.firstRow,rowCount:v.rowCount}),p(!1),I("")}catch(v){D(String((v==null?void 0:v.message)||v).replace(/^Error:\s*/,""))}finally{L(!1)}},J=[];if(V)for(const R of u){if(R.valueFrom||!R.value)continue;const v=V.values.findIndex(W=>W&&W===R.value);v>=0&&J.push({id:R.id,valueFrom:`data.${V.columns[v]}`})}return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center justify-between mb-1",children:e.jsxs("span",{className:"text-[10px] text-gray-500 uppercase tracking-wider",children:["Test data ",e.jsx("span",{className:"normal-case",children:"(optional)"})]})}),!g&&!N&&e.jsxs("button",{type:"button",disabled:l,onClick:()=>p(!0),className:"inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-xs border border-dashed border-white/15 text-gray-400 hover:text-gray-200 hover:border-white/30 disabled:opacity-50",children:[e.jsx(tr,{size:12})," Read the data from a file"]}),N&&e.jsxs("div",{className:"rounded-lg border border-white/10 bg-surface-2",children:[e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 border-b border-white/5",children:[e.jsx(Jr,{size:12,className:"text-gray-500"}),e.jsx("input",{ref:Y,value:A,onChange:R=>I(R.target.value),placeholder:"Search test-data files…",onKeyDown:R=>{R.key==="Escape"&&(R.stopPropagation(),p(!1))},"aria-label":"Search test-data files",className:"flex-1 bg-transparent text-xs text-gray-200 placeholder-gray-500 focus:outline-none"}),e.jsx("button",{type:"button","aria-label":"Cancel",onClick:()=>p(!1),className:"text-gray-500 hover:text-gray-200",children:e.jsx(gt,{size:12})})]}),e.jsxs("div",{className:"max-h-44 overflow-y-auto py-1",children:[(k||S)&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 text-xs text-gray-500",children:[e.jsx(ve,{size:12,className:"animate-spin"})," ",S?"Reading columns…":"Searching…"]}),!k&&E.length===0&&e.jsxs("div",{className:"px-3 py-2 text-xs text-gray-500",children:["No test-data files found",A?` for "${A}"`:"",". Files show up here once the Data Map has scanned them."]}),E.map(R=>e.jsxs("button",{type:"button",onClick:()=>ee(R.file||R.label),disabled:S,className:"w-full flex items-start gap-2 px-3 py-1.5 text-left hover:bg-white/5",children:[e.jsx(Zs,{size:12,className:"text-teal-500 mt-0.5 flex-shrink-0"}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-xs font-mono text-gray-200 truncate",children:R.label}),e.jsx("span",{className:"block text-[10px] text-gray-500 truncate",children:R.detail})]})]},R.label))]})]}),H&&e.jsx("p",{role:"alert",className:"text-xs text-red-600 dark:text-red-400 mt-1",children:H}),g&&e.jsxs("div",{className:"rounded-lg border border-teal-500/25 bg-teal-500/5 px-3 py-2 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Zs,{size:13,className:"text-teal-500 flex-shrink-0"}),e.jsx("span",{className:"text-xs font-mono text-gray-200 truncate flex-1",title:g.file,children:g.file}),e.jsx("button",{type:"button",disabled:l,"aria-label":"Remove test data",onClick:()=>B({testData:void 0}),className:"text-gray-500 hover:text-red-400",children:e.jsx(gt,{size:13})})]}),!!((se=g.columns)!=null&&se.length)&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[g.columns.slice(0,10).map(R=>e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-surface-2 border border-white/10 text-[10px] font-mono text-gray-400",children:`data.${R}`},R)),g.columns.length>10&&e.jsxs("span",{className:"text-[10px] text-gray-500",children:["+",g.columns.length-10," more"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-4 gap-y-1",children:[e.jsxs("label",{className:"inline-flex items-center gap-1.5 text-xs text-gray-400 cursor-pointer",children:[e.jsx("input",{type:"checkbox",disabled:l,checked:!!g.perRow,onChange:R=>B({testData:{...g,perRow:R.target.checked}})}),"Run the test once per row",V!=null&&V.rowCount?` (${V.rowCount})`:""]}),J.length>0&&e.jsxs("button",{type:"button",disabled:l,onClick:()=>d(J),className:"inline-flex items-center gap-1 text-xs text-teal-600 dark:text-teal-400 hover:underline",children:[e.jsx(bo,{size:12})," Use the data for ",J.length," recorded value",J.length===1?"":"s"]})]})]})]}),e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>P(R=>!R),"aria-expanded":oe,className:"inline-flex items-center gap-1 text-[10px] text-gray-500 uppercase tracking-wider hover:text-gray-300",children:[e.jsx(ls,{size:11,className:`transition-transform ${oe?"":"-rotate-90"}`}),"Before the test ",e.jsx("span",{className:"normal-case",children:"(optional)"})]}),oe&&e.jsx("div",{className:"mt-1",children:e.jsx(Jn,{value:((ue=t==null?void 0:t.before)==null?void 0:ue.text)||"",onChange:R=>{var v,W;return B({before:{text:R,references:(W=(v=Z.current)==null?void 0:v.before)==null?void 0:W.references}})},references:((y=t==null?void 0:t.before)==null?void 0:y.references)||[],onReferencesChange:R=>{var v,W;return B({before:{text:((W=(v=Z.current)==null?void 0:v.before)==null?void 0:W.text)||"",references:R}})},placeholder:"e.g. Start logged in as a Manager using @loginAs",rows:2,ariaLabel:"Before the test"})})]})]})}const si=!1;function ri({onPhaseChange:t,registerControls:n}){const{toast:u}=Qr(),[d,l]=s.useState([]),[N,p]=s.useState("browserstack"),[A,I]=s.useState([]),[E,C]=s.useState([]),[k,T]=s.useState(""),[S,L]=s.useState(""),[H,D]=s.useState(!1),[V,U]=s.useState(null),oe=s.useRef(null),[P,Y]=s.useState("setup"),[g,Z]=s.useState(null),[B,ee]=s.useState([]),[J,ie]=s.useState(!1),[se,ue]=s.useState(!1),[y,R]=s.useState(!1),[v,W]=s.useState(0),re=s.useRef(0),$e=s.useRef(()=>{}),$=s.useCallback(i=>{const o=Math.floor(i/1e3)!==Math.floor(re.current/1e3);re.current=i,o&&$e.current()},[]),[m,X]=s.useState(!1),[w,pe]=s.useState([]),[Ie,Xt]=s.useState("wdio-appium-ts"),[sn,cs]=s.useState(null),[he,bt]=s.useState(null),[ds,Rt]=s.useState(!1),[fe,$t]=s.useState(!1),[Ge,Pe]=s.useState(""),[ge,_e]=s.useState(""),[Se,He]=s.useState("auto"),[We,yt]=s.useState(""),{data:Ce}=Yn(),[Jt,Ve]=s.useState(!1),[Zt,ot]=s.useState(""),[Ae,vt]=s.useState(""),[Kt,Is]=s.useState(new Set),[us,wt]=s.useState([]),[es,ts]=s.useState(!1),{providerModels:Tt,selectedModel:it,selectedProvider:lt,select:At}=Xn(),[ct,Ke]=s.useState(!1),[Bt,sr]=s.useState(""),Ps=s.useRef(null),[xe,Be]=s.useState([]),[Ar,xs]=s.useState(null),[De,Ut]=s.useState(!1),[Ds,Ye]=s.useState(null),[Qe,ss]=s.useState(""),Xe=s.useRef(null),Et=s.useRef([]);s.useEffect(()=>{Et.current=xe},[xe]);const[Fs,rs]=s.useState(!1),[rr,ps]=s.useState({}),[nr,Mt]=s.useState(!1),[Je,Ls]=s.useState(null),ns=s.useRef([]),[jt,_s]=s.useState(null),Hs=s.useRef(null);s.useEffect(()=>{Hs.current=jt},[jt]);const[Te,Ue]=s.useState(!1),Ze=Mn(),[et,ae]=s.useState(null),[tt,ye]=s.useState(null),[ce,le]=s.useState(!1),[Ee,dt]=s.useState(""),[zt,Nt]=s.useState(""),[st,as]=s.useState(null),[Ot,ut]=s.useState(""),[ar,xt]=s.useState(!1),[Oe,It]=s.useState(null),rt=s.useRef(null),we=s.useRef(0),je=Xr(),[Ne,Me]=s.useState(null),[ze,Fe]=s.useState(new Set),[kt,te]=s.useState(null),os=s.useRef(null),[ms,fs]=s.useState(null),[hs,or]=s.useState("above"),[ir,pt]=s.useState(null),[Ks,Bs]=s.useState(null),gs=s.useRef(null),[ke,Pt]=s.useState(null);s.useEffect(()=>{(async()=>{try{await Dn().catch(()=>null);const[i,o,h,b,j]=await Promise.all([xa(),nn(),an().catch(()=>({session:null})),on().catch(()=>({recording:!1,startedAt:0,actions:[]})),pa().catch(()=>({formatters:[]}))]);if(l(i.providers),C(o.apps),pe(j.formatters),h.session&&Z(h.session),b.recording&&b.actions&&b.actions.length>0)ee(b.actions),W(b.startedAt),Y("recording"),te(b.settings||null),rt.current=ln();else try{const q=await qr(ln());q.recording&&q.recording.status==="draft"&&q.recording.actionCount>0&&(It({id:q.recording.id,name:q.recording.name,actionCount:q.recording.actionCount,url:q.recording.url||q.recording.device}),X(!0))}catch{}const F=i.providers.find(q=>q.hasCredentials&&q.enabled);F&&p(F.id)}catch(i){ae(i.message)}})()},[]);const bs=s.useRef([]);s.useEffect(()=>{bs.current=B},[B]);const ys=s.useRef(null);s.useEffect(()=>{ys.current=g},[g]),s.useEffect(()=>{if(P!=="recording"||J)return;const i=()=>{var j,F;if(bs.current.length===0)return;const b=rt.current||Fr();rt.current=b,gr({id:b,name:`Draft — ${((j=ys.current)==null?void 0:j.device)||"mobile recording"}`,status:"draft",url:(F=ys.current)==null?void 0:F.device}).then(()=>je.invalidateQueries({queryKey:["mobile-recording-history"]})).catch(()=>{})},o=setTimeout(i,1500),h=setInterval(i,1e4);return()=>{clearTimeout(o),clearInterval(h)}},[P,J,je]);const Us=s.useCallback(async i=>{D(!0),ae(null);try{const h=[...(await ma(i)).devices].sort((j,F)=>j.realMobile!==F.realMobile?j.realMobile?-1:1:j.name.localeCompare(F.name));I(h);const b=h.filter(j=>!j.unavailableReason);if(!k||!h.some(j=>j.id===k)){const j=b.find(F=>F.realMobile&&/iphone 15/i.test(F.name))||b.find(F=>F.realMobile&&/pixel/i.test(F.name))||b[0];T((j==null?void 0:j.id)??"")}}catch(o){ae(o.message),I([])}finally{D(!1)}},[k]);s.useEffect(()=>{const i=d.find(o=>o.id===N);i!=null&&i.hasCredentials?Us(N):I([])},[N,d,Us]),s.useEffect(()=>{if(P!=="recording"||J||v===0)return;const i=setInterval(()=>$(Date.now()-v),250);return()=>clearInterval(i)},[P,J,v]);const Os=s.useRef(null),qs=s.useRef(!0),Gs=()=>{const i=Os.current;i&&(qs.current=i.scrollHeight-i.scrollTop-i.clientHeight<120)};s.useEffect(()=>{const i=Os.current;!i||P!=="recording"||!qs.current||requestAnimationFrame(()=>{i.scrollTo({top:i.scrollHeight,behavior:"smooth"})})},[B.length,P]),s.useEffect(()=>{const i=o=>{const h=o.detail;h!=null&&h.action&&(ee(b=>b.some(j=>j.index===h.action.index)?b:[...b,h.action]),h.action.type==="assertion"&&(ue(!1),dn(!1).catch(()=>{})))};return window.addEventListener("testver-mobile-action",i),()=>window.removeEventListener("testver-mobile-action",i)},[]),s.useEffect(()=>{window.__testver_mobile_record_paused=J},[J]),s.useEffect(()=>{window.__testver_mobile_assert_mode=se,window.__testver_mobile_annotate_mode=y},[se,y]);const Er=async i=>{le(!0),ae(null),U(0),ye(`Uploading ${i.name}…`);try{const o=await Ca(i,void 0,b=>U(b)),h=await nn();C(h.apps),L(o.id),ye(`Added ${i.name}.`)}catch(o){ae(o.message),ye(null)}finally{le(!1),U(null)}},Mr=async()=>{const i=A.find(o=>o.id===k);if(!i){ae("Pick a device first.");return}if(!S){ae("Pick or upload an app first.");return}le(!0),Y("starting"),ae(null),ye(N==="local-appium"?"Starting local device session — this may take a moment.":"Starting cloud session — this may take 30–60 s on first launch.");try{let o=g;o||(o=(await Ra({provider:N,deviceKey:i.rawDeviceKey,osVersion:i.os,platform:i.platform,appId:S,sessionName:"Testver AI Record"})).session,Z(o));const h=await $a();rt.current=Fr(),we.current=0,te(null),Fe(new Set),ee(h.actions),W(h.startedAt),$(0),ie(!1),ue(!1),R(!1),cs(null),bt(null),X(!1),Y("recording"),ye(`Recording on ${i.name} (${i.os}). Click on the device to capture taps.`),window.dispatchEvent(new CustomEvent("testver-mobile-recording-changed",{detail:{recording:!0,owner:"recorder-page"}}))}catch(o){ae(o.message),ye(null),Y("setup")}finally{le(!1)}},lr=s.useCallback(()=>{ie(!0),we.current=Date.now(),ye("Recording paused."),cn(!0).catch(i=>{ie(!1),we.current=0,ae(`Couldn't pause the recording: ${i.message}`)})},[]),Ws=s.useCallback(()=>{const i=we.current;i&&W(o=>o&&o+(Date.now()-i)),we.current=0,ie(!1),ye("Recording resumed."),cn(!1).catch(o=>{ie(!0),we.current=Date.now(),ae(`Couldn't resume the recording: ${o.message}`)})},[]),Vs=s.useCallback(async()=>{le(!0),ae(null);try{try{const o=await fa();Array.isArray(o.actions)&&ee(o.actions)}catch{}we.current=0,ie(!1),window.dispatchEvent(new CustomEvent("testver-mobile-recording-changed",{detail:{recording:!1,owner:"recorder-page"}}));const i=await ha({testName:`Recorded ${_r(new Date)}`,formatter:Ie});if(cs(i),Y("stopped"),ye(`${B.length} step${B.length===1?"":"s"} captured. Review or generate.`),B.length>0){const o=rt.current||Fr();rt.current=o;try{await gr({id:o,name:`Recorded — ${(g==null?void 0:g.device)||_r(new Date)}`,status:"recorded",url:g==null?void 0:g.device}),je.invalidateQueries({queryKey:["mobile-recording-history"]})}catch(h){console.warn("[MobileRecorder] Failed to persist on Stop:",h)}}}catch(i){ae(i.message)}finally{le(!1)}},[B.length,Ie,g,je]),Dt=s.useCallback(async i=>{if(!(Fs||bs.current.length===0)){Mt(!1),ae(null),ps({}),rs(!0),ye(i?"Restarting the app, then replaying recorded steps…":"Replaying recorded steps from the current screen…");try{await ga(1,i)}catch(o){rs(!1),ae(`Playback failed: ${o.message}`)}}},[Fs]),cr=s.useCallback(async()=>{le(!0);try{const i=await ba();ee(i.actions),i.startedAt&&W(i.startedAt),we.current=0,ie(!1),Y("recording"),ye("Recording resumed — capture additional steps."),window.dispatchEvent(new CustomEvent("testver-mobile-recording-changed",{detail:{recording:!0,owner:"recorder-page"}}))}catch(i){ae(i.message)}finally{le(!1)}},[]),dr=s.useCallback(async()=>{const i=!se;try{await dn(i),ue(i),i&&R(!1)}catch(o){ae(o.message)}},[se]),ur=s.useCallback(async()=>{const i=!y;try{await ya(i),R(i),i&&ue(!1)}catch(o){ae(o.message)}},[y]),vs=i=>{try{window.dispatchEvent(new CustomEvent("testver-mobile-action",{detail:{action:i}}))}catch{}},ws=async()=>{if(Ee.trim()){le(!0),ae(null),window.__testver_mobile_action_in_flight=!0;try{const i=await Ia(Ee);ee(o=>[...o,i.action]),vs(i.action),dt("")}catch(i){ae(i.message)}finally{le(!1),window.__testver_mobile_action_in_flight=!1}}},qt=async i=>{le(!0),ae(null),window.__testver_mobile_action_in_flight=!0;try{if(J){await Pa(i);return}const o=await Da(i);ee(h=>[...h,o.action]),vs(o.action)}catch(o){ae(o.message)}finally{le(!1),window.__testver_mobile_action_in_flight=!1}},xr=async()=>{if(zt.trim()){le(!0);try{const i=await za(zt);ee(o=>[...o,i.action]),vs(i.action),Nt("")}catch(i){ae(i.message)}finally{le(!1)}}},Ft=s.useCallback(async()=>{const i=rt.current;if(i)try{await gr({id:i}),je.invalidateQueries({queryKey:["mobile-recording-history"]})}catch(o){console.warn("[MobileRecorder] persist after mutation failed:",o)}},[je]),zr=async i=>{le(!0);try{await Ea(i),ee(o=>o.filter(h=>h.index!==i)),await Ft()}catch(o){ae(o.message)}finally{le(!1)}},Ir=i=>{as(i.index),ut(i.description)},pr=async()=>{if(st!==null){try{const i=await br(st,{description:Ot});ee(o=>o.map(h=>h.index===st?i.action:h)),await Ft()}catch(i){ae(i.message)}as(null)}},r=async i=>{const o=Ne;if(o){if(o.mode==="add"){const h=await Ta(i,o.afterIndex);ee(b=>{const j=[...b];if(o.afterIndex===null)j.unshift(h.action);else{const F=o.afterIndex!==void 0?j.findIndex(q=>q.index===o.afterIndex):-1;F>=0?j.splice(F+1,0,h.action):j.push(h.action)}return j})}else if(o.mode==="edit"&&o.editIndex!==void 0){const h=await br(o.editIndex,{instruction:i.instruction,customKind:i.customKind,references:i.references||[],outputs:i.outputs||[]});ee(b=>b.map(j=>j.index===o.editIndex?h.action:j))}else if(o.mode==="replace"){const h=[...ze],b=await Aa(h,i);ee(j=>{const F=new Set(h),q=j.findIndex(Wt=>F.has(Wt.index)),me=j.filter(Wt=>!F.has(Wt.index));return me.splice(q>=0?Math.min(q,me.length):me.length,0,b.action),me}),Fe(new Set)}Me(null),await Ft()}},a=async i=>{try{const o=await Ma(i);ee(h=>{const b=h.findIndex(me=>me.index===i);if(b<0)return h;const j=[...h];if(j.splice(b,1,...o.actions),!o.order)return j;const F=new Map(j.map(me=>[me.index,me])),q=o.order.map(me=>F.get(me)).filter(me=>!!me);return q.length===j.length?q:j}),await Ft()}catch(o){ae(o.message)}},x=async(i,o)=>{try{const h=await br(i,{valueFrom:o});ee(b=>b.map(j=>j.index===i?h.action:j)),await Ft()}catch(h){ae(h.message)}},f=s.useRef(null),M=i=>{te(i),f.current&&clearTimeout(f.current),f.current=setTimeout(()=>{Fa(i).then(()=>Ft()).catch(()=>{})},500)},c=s.useMemo(()=>{var b;const i=new Map,o=[],h=(((b=kt==null?void 0:kt.testData)==null?void 0:b.columns)||[]).map(j=>({name:`data.${j}`,source:"data",detail:kt.testData.file}));return B.forEach((j,F)=>{if(i.set(j.index,[...o,...h]),j.type==="custom")for(const q of j.outputs||[])o.push({name:q,source:"step",detail:`saved by step ${F+1}`})}),i},[B,kt]),z=async i=>{try{const o=await La(i);ee(o.actions),await Ft()}catch(o){ae(o.message)}},K=i=>o=>{os.current=i,pt(i),o.dataTransfer.effectAllowed="move";try{const h=B[i];if(h){const b=document.createElement("div");b.style.cssText="position:absolute;top:-9999px;padding:6px 10px;background:#1e293b;color:#e2e8f0;border-radius:6px;font-size:12px;border-left:3px solid #3b82f6;box-shadow:0 4px 12px rgba(0,0,0,0.4);max-width:240px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;",b.textContent=`#${i+1} ${h.description.slice(0,60)}`,document.body.appendChild(b),o.dataTransfer.setDragImage(b,12,12),setTimeout(()=>b.remove(),0)}}catch{}},ne=i=>o=>{o.preventDefault(),o.dataTransfer.dropEffect="move";const h=o.currentTarget.getBoundingClientRect(),b=h.top+h.height/2,j=o.clientY<b?"above":"below";(ms!==i||hs!==j)&&(fs(i),or(j))},Q=i=>()=>{ms===i&&fs(null)},de=i=>async o=>{o.preventDefault();const h=os.current;if(os.current=null,pt(null),fs(null),h===null||h===i)return;const b=B[h],j=B.map(me=>me.index),[F]=j.splice(h,1);let q=i;h<i?q=hs==="above"?i-1:i:q=hs==="above"?i:i+1,q=Math.max(0,Math.min(q,j.length)),j.splice(q,0,F),await z(j),b&&(gs.current&&clearTimeout(gs.current),Bs(b.index),gs.current=setTimeout(()=>{Bs(null),gs.current=null},2500))},Re=()=>{os.current=null,pt(null),fs(null)},_=s.useCallback(async()=>{le(!0),Y("generating"),ae(null);try{const i=await va({testName:`Recorded ${_r(new Date)}`,formatter:Ie});bt(i),Y("done"),ye(`Saved to ${i.specPath}`),je.invalidateQueries({queryKey:["mobile-recording-history"]})}catch(i){ae(i.message),Y("stopped")}finally{le(!1)}},[Ie,je]);s.useEffect(()=>Ze!=null&&Ze.subscribe?Ze.subscribe(o=>{var h;if(!(!o||typeof o!="object")&&!(o.requestId&&o.requestId!==Xe.current))switch(o.type){case"mobile-session-started":{const b=o.session;b&&Z(b);break}case"mobile-session-closed":{Z(null);const b=o.reason;typeof b=="string"&&b&&u("info",b);break}case"mobile-recorded-action":{const b=o.action;if(b){if(!b.screenshot)try{const j=(h=window.__testver_capture_mobile_frame)==null?void 0:h.call(window);if(j!=null&&j.dataUrl){if(b.screenshot=j.dataUrl,b.screenshotSize={width:j.width,height:j.height},b.elementRect&&j.deviceWidth>0&&j.deviceHeight>0){const F=j.width/j.deviceWidth,q=j.height/j.deviceHeight;b.elementRect={x:Math.round(b.elementRect.x*F),y:Math.round(b.elementRect.y*q),width:Math.round(b.elementRect.width*F),height:Math.round(b.elementRect.height*q)}}br(b.index,{screenshot:b.screenshot,screenshotSize:b.screenshotSize,elementRect:b.elementRect}).catch(()=>{})}}catch{}window.dispatchEvent(new CustomEvent("testver-mobile-action",{detail:{action:b}}))}break}case"ai-fix-stream":{const b=typeof o.content=="string"?o.content:"";if(!b)return;Be(j=>{const F=j[j.length-1];return(F==null?void 0:F.kind)==="text"?[...j.slice(0,-1),{...F,content:F.content+b}]:[...j,{kind:"text",id:`text-${Date.now()}-${j.length}`,content:b}]});break}case"ai-fix-tool":{const b=o.phase;Be(j=>{if(b!=="start")for(let F=j.length-1;F>=0;F--){const q=j[F];if(q.kind==="tool"&&q.toolName===o.toolName&&q.phase==="start"){const me=[...j];return me[F]={...q,phase:b,result:o.result,error:o.error},me}}return[...j,{kind:"tool",id:`tool-${Date.now()}-${j.length}`,phase:b,toolName:String(o.toolName||"tool"),args:typeof o.args=="string"?o.args:o.args?JSON.stringify(o.args,null,2):void 0,result:typeof o.result=="string"?o.result:void 0,error:typeof o.error=="string"?o.error:void 0}]});break}case"ai-fix-file-diff":{Be(b=>[...b,{kind:"file-diff",id:`diff-${Date.now()}-${b.length}`,filePath:String(o.filePath||""),diffType:o.diffType,diff:typeof o.diff=="string"?o.diff:"",linesAdded:typeof o.linesAdded=="number"?o.linesAdded:void 0,linesRemoved:typeof o.linesRemoved=="number"?o.linesRemoved:void 0}]);break}case"ai-fix-permission":{const b={permissionId:String(o.permissionId),toolName:String(o.toolName||"tool"),args:typeof o.args=="string"?o.args:o.args?JSON.stringify(o.args,null,2):"",fullPath:typeof o.fullPath=="string"?o.fullPath:void 0};Ls(j=>j?(ns.current.push(b),j):b);break}case"ai-fix-status":break;case"ai-fix-error":{Be(b=>[...b,{kind:"error",id:`err-${Date.now()}-${b.length}`,message:String(o.message||"Unknown error")}]);break}case"ai-fix-done":{le(!1),Rt(!1),Ut(b=>{if(b)return b;const j=[/test result:\s*fail/i,/all\s+\d+\s+attempts\s+(exhausted|failed)/i,/attempts\s+exhausted/i,/could not.*(?:fix|make).*(?:pass|work)/i,/reached maximum tool iterations/i],F=Et.current;let q=0;for(let O=F.length-1;O>=0;O--)if(F[O].kind==="user"){q=O+1;break}const ks=F.slice(q).some(O=>O.kind==="error"||O.kind==="text"&&typeof O.content=="string"&&j.some(Lt=>Lt.test(O.content)))?"failed":"success";Ye(O=>O??ks);const Ss=rt.current;return Ss?gr({id:Ss,name:Hs.current||void 0,status:"generated",outcome:ks,fullTimeline:Et.current}).catch(()=>{}).finally(()=>je.invalidateQueries({queryKey:["mobile-recording-history"]})):je.invalidateQueries({queryKey:["mobile-recording-history"]}),b}),Y("done");break}case"mobile-playback":{const b=o;if(b.action&&typeof b.index=="number"){const j=b.status==="ok"?"done":b.status==="error"?"error":"running";ps(F=>({...F,[b.index]:j}))}else b.status==="started"?(rs(!0),ps({})):b.status==="done"?(rs(!1),ye("Playback complete.")):b.status==="error"&&(rs(!1),ae(b.error||"Playback failed."));break}}}):void 0,[Ze,je,u]);const be=s.useCallback((i,o=!1)=>{!Je||!(Ze!=null&&Ze.send)||(Ze.send({type:"ai-fix-permission-response",permissionId:Je.permissionId,granted:i,remember:i&&o}),Ls(ns.current.shift()||null))},[Je,Ze]),qe=s.useCallback(async()=>{const i=Xe.current;if(i){try{await wa(i)}catch{}Ye("stopped"),Xe.current=null,Ut(!1),le(!1),Rt(!1),Y("done")}},[]),mt=s.useCallback(async()=>{const i=`mobile-recorder-followup-${Date.now()}`,o=Qe.trim(),h=De&&!o;ss(""),le(!0),Rt(!0),Ut(!1),Xe.current=i,xs(i),Be(O=>[...O,h?{kind:"system",id:`system-confirm-${Date.now()}-${O.length}`,message:"✓ Confirmed — executing the plan"}:{kind:"user",id:`user-${Date.now()}-${O.length}`,text:o}]),Y("generating");const b=new Set,j=[],F=[];for(const O of B)j.push(`${O.type}: ${O.description}`);for(const O of xe)if(O.kind==="file-diff")b.add(O.filePath);else if(O.kind==="user")F.push(`User: ${O.text}`);else if(O.kind==="text"&&O.content){const Lt=String(O.content);F.push(`Assistant: ${Lt.length>2e3?Lt.substring(0,2e3)+"... [truncated]":Lt}`)}else if(O.kind==="tool"){if(O.phase==="start")continue;const Lt=O.args?` ${String(O.args).substring(0,100)}`:"";let fr="";if(O.phase==="complete"){const hr=O.result?String(O.result):"";fr=hr?` → ${hr.length>300?hr.substring(0,300)+"... [truncated]":hr}`:" → (no output)"}else O.phase==="error"?fr=` → ERROR: ${O.error?String(O.error).substring(0,300):"failed"}`:O.phase==="denied"&&(fr=" → DENIED by user");F.push(`[Tool ${O.phase}] ${O.toolName}${Lt}${fr}`)}else O.kind==="error"&&F.push(`[Stream Error] ${O.message}`);const q=[];j.length>0&&q.push(`Recorded steps (${j.length}):
4
4
  ${j.map((O,Lt)=>` ${Lt+1}. ${O}`).join(`
5
5
  `)}`),b.size>0&&q.push(`Files created/modified:
@@ -21,7 +21,7 @@ ${F.join(`
21
21
  ${S?"ring-2 ring-blue-400/80 shadow-[0_0_24px_rgba(96,165,250,0.55)] bg-blue-500/[0.10] scale-[1.005] z-10":""}
22
22
  ${u?"cursor-grab active:cursor-grabbing":""}`,children:[k&&!C&&T==="above"&&e.jsx("div",{className:"absolute -top-[2px] left-0 right-0 h-[3px] bg-blue-500 rounded-full z-10 shadow-[0_0_6px_rgba(59,130,246,0.6)]",children:e.jsx("div",{className:"absolute -left-1 -top-[3px] w-[9px] h-[9px] rounded-full bg-blue-500"})}),k&&!C&&T==="below"&&e.jsx("div",{className:"absolute -bottom-[2px] left-0 right-0 h-[3px] bg-blue-500 rounded-full z-10 shadow-[0_0_6px_rgba(59,130,246,0.6)]",children:e.jsx("div",{className:"absolute -left-1 -top-[3px] w-[9px] h-[9px] rounded-full bg-blue-500"})}),Y&&e.jsx("input",{type:"checkbox",checked:g,onChange:()=>B==null?void 0:B(),onMouseDown:re=>re.stopPropagation(),"aria-label":`Select step ${n} (to replace it with a custom step)`,title:"Select to replace with a custom step",className:`flex-shrink-0 cursor-pointer accent-indigo-500 ${Z||g?"opacity-100":"opacity-0 group-hover:opacity-100 focus:opacity-100"}`}),u&&e.jsx(vo,{size:11,className:"text-gray-600 opacity-0 group-hover:opacity-100 flex-shrink-0"}),e.jsx("span",{className:"flex-shrink-0 w-6 text-center text-xs font-bold text-gray-500 group-hover:text-gray-800 dark:group-hover:text-gray-300",children:n}),e.jsx(oi,{action:t,onOpen:oe,Fallback:ue}),e.jsx("div",{className:"flex-1 min-w-0",children:d?e.jsx("input",{type:"text",value:l,autoFocus:!0,onChange:re=>N(re.target.value),onKeyDown:re=>{re.key==="Enter"&&(re.preventDefault(),A()),re.key==="Escape"&&(re.preventDefault(),I())},onBlur:A,className:"w-full bg-transparent border border-indigo-400/50 rounded px-1.5 py-0.5 text-[13px] text-gray-200 focus:outline-none"}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[y&&e.jsx("span",{className:"flex-shrink-0 text-[9px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded text-indigo-600 dark:text-indigo-300 bg-indigo-500/10",children:"custom"}),e.jsx("div",{className:"text-[13px] text-gray-200 group-hover:text-gray-900 dark:group-hover:text-gray-100 truncate transition-colors",title:y?t.instruction:void 0,children:y&&t.instruction||t.description})]}),(y||t.valueFrom)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1 mt-0.5",children:[y&&!!((R=t.references)!=null&&R.length)&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] text-gray-500",title:t.references.map(re=>re.label).join(`
23
23
  `),children:[e.jsx($r,{kind:t.references[0].kind,size:11}),t.references.length>1?`${t.references.length} refs`:t.references[0].label]}),y&&((v=t.outputs)==null?void 0:v.map(re=>e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-indigo-500/10 text-[10px] font-mono text-indigo-700 dark:text-indigo-300",children:`→ {${re}}`},re))),y&&!!((W=t.replaces)!=null&&W.length)&&e.jsxs("span",{className:"text-[10px] text-gray-500",title:t.replaces.map(re=>re.description).join(`
24
- `),children:["replaces ",t.replaces.length," step",t.replaces.length===1?"":"s"]}),t.valueFrom&&e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-teal-500/10 text-[10px] font-mono text-teal-700 dark:text-teal-300",children:`uses {${t.valueFrom}}`})]}),t.primary&&e.jsxs("div",{className:"text-[11px] text-gray-500 group-hover:text-gray-700 dark:group-hover:text-gray-400 truncate transition-colors",children:[e.jsxs("span",{children:[t.primary.strategy,"="]}),e.jsx("code",{children:t.primary.value})]})]})}),u&&!d&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-0 group-hover:opacity-100 focus-within:opacity-100",children:ie}),J&&e.jsx("button",{type:"button",onClick:J,className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-1.5 rounded text-gray-500 hover:text-amber-500 hover:bg-black/[0.06] dark:hover:bg-white/10 transition-colors",title:"Put the replaced steps back","aria-label":"Put the replaced steps back",children:e.jsx(Gn,{size:12})}),e.jsx("button",{type:"button",onClick:y&&ee?ee:p,className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-1.5 rounded text-gray-500 hover:text-indigo-500 dark:hover:text-indigo-400 hover:bg-black/[0.06] dark:hover:bg-white/10 transition-colors",title:y?"Edit custom step":"Edit description","aria-label":y?"Edit custom step":"Edit description",children:e.jsx(wo,{size:12})}),e.jsx("button",{type:"button",onClick:E,className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-1.5 rounded text-gray-500 hover:text-red-500 dark:hover:text-red-400 hover:bg-red-500/10 transition-colors",title:"Delete step","aria-label":"Delete step",children:e.jsx(Es,{size:12})})]})]})}function oi({action:t,onOpen:n,Fallback:u}){if(!t.screenshot)return e.jsx("div",{className:"flex-shrink-0 w-[48px] h-[64px] rounded-md bg-surface-2 border border-white/5 flex items-center justify-center",children:e.jsx(u,{size:16,className:"text-gray-400"})});let N,p=null;const A=t.screenshotSize,I=t.elementRect;if(A&&I&&I.width>0&&I.height>0){const E=I.height,k=Math.min(4,64*.65/Math.max(20,E)),T=A.width*k,S=A.height*k,L=(I.x+I.width/2)*k,H=(I.y+I.height/2)*k,D=48/2-L,V=64/2-H;N={width:48,height:64,backgroundImage:`url(${t.screenshot})`,backgroundSize:`${T}px ${S}px`,backgroundPosition:`${D}px ${V}px`,backgroundRepeat:"no-repeat",backgroundColor:"#000"},p={left:I.x*k+D,top:I.y*k+V,width:I.width*k,height:I.height*k}}else if(A){const E=Math.min(48/A.width,64/A.height),C=A.width*E,k=A.height*E;N={width:48,height:64,backgroundImage:`url(${t.screenshot})`,backgroundSize:`${C}px ${k}px`,backgroundPosition:"center",backgroundRepeat:"no-repeat",backgroundColor:"#000"}}else N={width:48,height:64,backgroundImage:`url(${t.screenshot})`,backgroundSize:"cover",backgroundPosition:"center",backgroundColor:"#000"};return e.jsxs("button",{type:"button",onClick:E=>{E.stopPropagation(),n()},onMouseDown:E=>E.stopPropagation(),onDragStart:E=>{E.preventDefault(),E.stopPropagation()},draggable:!1,title:"Click to view full screenshot",className:"flex-shrink-0 relative rounded-md border border-white/10 hover:border-blue-400/60 hover:shadow-[0_0_10px_rgba(96,165,250,0.35)] overflow-hidden transition-all",style:{width:48,height:64},children:[e.jsx("div",{style:N}),p&&e.jsx("div",{className:"absolute pointer-events-none border-[2px] border-red-400 rounded-[2px]",style:{...p,boxShadow:"0 0 0 1px rgba(255,255,255,0.4), 0 0 6px rgba(239,68,68,0.6)"}})]})}function Cs({label:t,hint:n,onClick:u,disabled:d,paused:l}){return e.jsxs("button",{type:"button",onClick:u,disabled:d,className:"inline-flex items-center gap-1 px-2 py-0.5 rounded border border-white/10 bg-surface-2 text-gray-300 hover:bg-white/10 hover:text-gray-100 disabled:opacity-40 disabled:cursor-not-allowed",title:l?`Press ${t} (not recorded while paused)`:`Record ${t} key press`,children:[n&&e.jsx("span",{className:"text-gray-500",children:n}),e.jsx("span",{children:t})]})}function Cn({active:t,onClick:n,children:u}){return e.jsxs("label",{onClick:n,className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs cursor-pointer transition-colors ${t?"bg-indigo-500/15 text-indigo-300 border border-indigo-500/20":"bg-surface-2 text-gray-400 border border-white/5 hover:text-gray-300"}`,children:[e.jsx("input",{type:"radio",checked:t,onChange:n,className:"hidden"}),u]})}function ii({selectedFile:t,selectedTest:n,open:u,setOpen:d,search:l,setSearch:N,expanded:p,setExpanded:A,suites:I,loading:E,onPick:C}){const k=l.toLowerCase().trim(),T=s.useMemo(()=>k?I.filter(S=>Yt(S.name,k)||S.file.toLowerCase().includes(k)||S.tests.some(L=>Yt(L.name,k))):I,[I,k]);return e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",onClick:()=>d(!u),className:"w-full px-3 py-2 rounded-lg bg-white dark:bg-white/[0.04] border border-gray-200 dark:border-white/10 text-xs text-left focus:outline-none focus:border-indigo-500/40 transition-colors",children:n?e.jsxs("div",{title:n,children:[e.jsx("span",{className:"text-gray-800 dark:text-gray-200",children:Rs(n)}),e.jsx("span",{className:"text-[10px] text-gray-500 block mt-0.5 truncate",children:t})]}):e.jsx("span",{className:"text-gray-400 dark:text-gray-600",children:"Select a test…"})}),u&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>d(!1)}),e.jsxs("div",{className:"absolute bottom-full left-0 w-full mb-1 bg-surface-1 border border-white/10 rounded-lg shadow-xl z-40 overflow-hidden",children:[e.jsx("div",{className:"px-2 py-2 border-b border-white/5",children:e.jsx("input",{type:"text",value:l,onChange:S=>N(S.target.value),placeholder:"Search suites and tests…",className:"w-full px-2.5 py-1.5 rounded-md bg-surface-2 border border-white/10 text-xs text-gray-200 placeholder-gray-600 focus:outline-none",autoFocus:!0})}),e.jsxs("div",{className:"max-h-52 overflow-y-auto",children:[E&&T.length===0&&e.jsxs("div",{className:"flex items-center justify-center py-4 text-[11px] text-gray-500 gap-1.5",children:[e.jsx(ve,{size:11,className:"animate-spin"})," Loading tests…"]}),!E&&T.length===0&&e.jsxs("div",{className:"text-center text-[11px] text-gray-500 py-4 px-3",children:["No tests found in the project. Add a test file under a recognized test directory (e.g. ",e.jsx("code",{className:"text-gray-400",children:"tests/"}),") and it'll appear here."]}),T.map(S=>{const L=S.file,H=p.has(L)||!!k,D=k?S.tests.filter(U=>Yt(U.name,k)||Yt(S.name,k)):S.tests,V=()=>A(U=>{const oe=new Set(U);return oe.has(L)?oe.delete(L):oe.add(L),oe});return e.jsxs("div",{children:[e.jsxs("button",{onClick:V,className:"w-full text-left px-3 py-2 text-xs hover:bg-white/5 flex items-center gap-2 transition-colors",children:[e.jsx(ls,{size:11,className:`text-gray-500 transition-transform ${H?"":"-rotate-90"}`}),e.jsx("span",{className:"text-gray-300 font-medium truncate",title:S.name,children:Rs(S.name)}),e.jsx("span",{className:"text-[10px] text-gray-500 bg-surface-2 px-1.5 py-0.5 rounded-full ml-1.5 flex-shrink-0",children:S.tests.length})]}),H&&D.map((U,oe)=>{const P=t===S.file&&n===U.name;return e.jsx("button",{onClick:()=>C(S.file,U.name),className:`w-full text-left pl-8 pr-3 py-1.5 text-xs transition-colors ${P?"bg-indigo-500/10 text-indigo-300":"text-gray-400 hover:bg-white/5 hover:text-gray-200"}`,children:e.jsx("span",{className:"truncate block",title:U.name,children:Rs(U.name)})},oe)})]},L)})]})]})]})]})}function Rn({value:t,onChange:n,options:u,placeholder:d,disabled:l,dense:N}){return e.jsxs("div",{className:`relative ${N?"":"flex-1"}`,children:[e.jsxs("select",{value:t,onChange:p=>n(p.target.value),disabled:l,className:`appearance-none bg-surface-2 border border-white/5 rounded-lg ${N?"px-2 py-1 pr-7 text-[12px]":"w-full px-3 py-2.5 pr-8 text-[15px]"} text-gray-200 focus:outline-none focus:border-red-500/40 focus:ring-1 focus:ring-red-500/20 disabled:opacity-40`,children:[d&&e.jsx("option",{value:"",disabled:!0,children:d}),u.map(p=>e.jsx("option",{value:p.value,disabled:p.disabled,children:p.label},p.value))]}),e.jsx(ls,{size:N?11:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 pointer-events-none"})]})}function sa(t,n){const[u,d]=s.useState(!1);return s.useEffect(()=>{const l=t.current;if(!l||typeof ResizeObserver>"u")return;const N=()=>d(l.getBoundingClientRect().width<n);N();const p=new ResizeObserver(N);return p.observe(l),()=>p.disconnect()},[t,n]),u}function li(t){const n=Math.floor(t/1e3),u=Math.floor(n/60).toString().padStart(2,"0"),d=(n%60).toString().padStart(2,"0");return`${u}:${d}`}function ci({recorderMode:t,setRecorderMode:n}){const u=Fn(),[d,l]=s.useState("setup"),[N,p]=s.useState(0),[A,I]=s.useState(0),[E,C]=s.useState(!1),[k,T]=s.useState(!1),[S,L]=s.useState(!1),H=s.useRef(null),D=s.useRef(null),V=sa(D,640),[U,oe]=s.useState(!1),P=s.useCallback((ue,y)=>{l(ue),p(y.actionCount),I(y.durationMs),C(y.paused),T(y.assertMode),L(y.annotateMode)},[]),Y=s.useCallback(ue=>{H.current=ue},[]),g=()=>{H.current&&(E?(H.current.resume(),C(!1)):(H.current.pause(),C(!0)))},Z=ue=>async()=>{if(H.current){oe(!0);try{await ue()}finally{oe(!1)}}},B=Z(()=>H.current.stop()),ee=Z(()=>H.current.reset()),J=Z(()=>H.current.addMoreSteps()),ie=Z(()=>H.current.toggleAssert()),se=Z(()=>H.current.toggleAnnotate());return e.jsx(Ro,{children:e.jsxs("div",{className:"h-full flex flex-col relative",children:[d!=="generating"&&d!=="done"&&e.jsx("div",{ref:D,className:"flex-shrink-0 px-4 py-3 border-b border-white/5 bg-surface-1",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("button",{onClick:()=>{var ue;return(ue=H.current)==null?void 0:ue.openHistory()},className:"flex-shrink-0 p-1.5 rounded-lg text-gray-500 hover:text-gray-300 hover:bg-white/5 transition-colors",title:"Recording History","aria-label":"Recording History",children:e.jsx(Sr,{size:16})}),d==="recording"?e.jsxs(e.Fragment,{children:[E?e.jsxs(e.Fragment,{children:[e.jsx(Cr,{size:14,className:"text-amber-400"}),e.jsx("span",{className:"text-sm font-semibold text-amber-400",children:"Paused"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"relative flex h-3 w-3",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-red-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-3 w-3 bg-red-500"})]}),e.jsx("span",{className:"text-sm font-semibold text-red-400",children:"Recording"})]}),e.jsx("span",{className:"text-xs text-gray-500 font-mono",children:li(A)}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-red-500/10 text-red-400 border border-red-500/20",children:N})]}):d==="starting"?e.jsxs(e.Fragment,{children:[e.jsx(ve,{size:14,className:"animate-spin text-brand-400"}),e.jsx("span",{className:"text-sm font-semibold text-brand-300",children:"Starting session…"})]}):d==="stopped"?e.jsxs(e.Fragment,{children:[e.jsx(at,{size:14,className:"flex-shrink-0 text-amber-400"}),e.jsx("span",{className:"text-sm font-semibold text-amber-300 truncate",children:"Recording Stopped"}),e.jsxs("span",{className:"flex-shrink-0 whitespace-nowrap text-xs px-2 py-0.5 rounded-full bg-amber-500/10 text-amber-400 border border-amber-500/20",children:[N," action",N!==1?"s":""]})]}):e.jsxs(e.Fragment,{children:[e.jsx(ht,{size:14,className:"text-gray-400"}),e.jsx("span",{className:"text-sm font-semibold text-gray-300",children:"Mobile Recorder"})]}),u.isAmbiguous&&e.jsx("div",{className:"ml-2 flex-shrink-0",children:e.jsx(Qn,{value:t,onChange:n,disabled:d==="recording"||d==="starting"})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[d==="recording"&&e.jsxs(e.Fragment,{children:[!E&&e.jsxs(e.Fragment,{children:[e.jsx(Ct,{label:k?"Exit assertion mode":"Add an assertion",hint:k?void 0:"Tap an element on the device to check it, instead of tapping it",children:e.jsxs("button",{"aria-label":k?"Exit assertion mode":"Add an assertion",onClick:ie,disabled:U,className:`flex items-center gap-1 px-2 py-1.5 rounded-lg text-xs font-medium transition-colors ${k?"bg-green-500/25 text-green-300 border border-green-500/40 shadow-[0_0_8px_rgba(16,185,129,0.15)]":"bg-surface-2 text-gray-400 border border-white/5 hover:text-green-300 hover:bg-green-500/10 hover:border-green-500/20"}`,children:[e.jsx(zs,{size:14}),k&&e.jsx("span",{children:"ON"})]})}),e.jsx(Ct,{label:S?"Exit annotate mode":"Annotate a step",hint:S?void 0:"Describe the action or check you want next — even a complex one — and the AI will implement it for you",children:e.jsxs("button",{"aria-label":S?"Exit annotate mode":"Annotate a step",onClick:se,disabled:U,className:`flex items-center gap-1 px-2 py-1.5 rounded-lg text-xs font-medium transition-colors ${S?"bg-purple-500/25 text-purple-300 border border-purple-500/40 shadow-[0_0_8px_rgba(139,92,246,0.15)]":"bg-surface-2 text-gray-400 border border-white/5 hover:text-purple-300 hover:bg-purple-500/10 hover:border-purple-500/20"}`,children:[e.jsx(Qs,{size:14}),S&&e.jsx("span",{children:"ON"})]})})]}),e.jsx(Ct,{label:E?"Resume recording":"Pause recording",hint:E?"Your taps are recorded again":"Use the device freely — nothing is recorded until you resume",children:e.jsx("button",{onClick:g,"aria-label":E?"Resume recording":"Pause recording",className:`flex items-center justify-center w-8 h-8 rounded-lg transition-colors ${E?"bg-amber-500/20 text-amber-300 border border-amber-500/30 hover:bg-amber-500/30":"bg-surface-2 text-gray-400 border border-white/5 hover:text-amber-300 hover:bg-amber-500/10 hover:border-amber-500/20"}`,children:E?e.jsx(Ts,{size:14}):e.jsx(Cr,{size:14})})}),e.jsx(Ct,{label:"Stop recording",hint:"Then review the steps and generate the test",children:e.jsx("button",{onClick:B,disabled:U,className:"flex items-center justify-center w-8 h-8 rounded-lg bg-red-500/20 text-red-300 border border-red-500/30 hover:bg-red-500/30 transition-colors disabled:opacity-50","aria-label":"Stop recording",children:U?e.jsx(ve,{size:14,className:"animate-spin"}):e.jsx(at,{size:14})})})]}),d==="stopped"&&e.jsxs(e.Fragment,{children:[e.jsx(Xs,{tone:"brand",compact:V,icon:e.jsx(tr,{size:13}),label:"Add More Steps",hint:"Continue recording — add more steps to this recording",disabled:U,onClick:J}),e.jsx(Xs,{compact:V,icon:e.jsx(kr,{size:13}),label:"New Recording",hint:"Start over with a new recording (this one stays in History)",disabled:U,onClick:ee})]})]})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto transition-all duration-200",children:e.jsx(ri,{onPhaseChange:P,registerControls:Y})})]})})}const di=!1,ui={click:"border-l-blue-500",dblclick:"border-l-blue-500",fill:"border-l-amber-500",type:"border-l-amber-500",hover:"border-l-purple-500",select:"border-l-cyan-500",check:"border-l-emerald-500",uncheck:"border-l-emerald-500",assert:"border-l-green-500",annotate:"border-l-violet-500",navigate:"border-l-gray-500",press:"border-l-slate-500",upload:"border-l-teal-500",drag:"border-l-indigo-500",dialog:"border-l-orange-500",custom:"border-l-indigo-500"},xi=new Set(["annotate","assert","hover","dialog","custom"]),$n=new Set(["fill","type","select","navigate"]);function pi(t){const n=Math.floor(t/60),u=t%60;return`${n}:${u.toString().padStart(2,"0")}`}function Ur({type:t,size:n=12}){const u={click:e.jsx(Nr,{size:n,className:"text-blue-400"}),dblclick:e.jsx(Nr,{size:n,className:"text-blue-300"}),fill:e.jsx(As,{size:n,className:"text-emerald-400"}),type:e.jsx(As,{size:n,className:"text-emerald-400"}),press:e.jsx(Co,{size:n,className:"text-amber-400"}),navigate:e.jsx(tn,{size:n,className:"text-purple-400"}),select:e.jsx(So,{size:n,className:"text-cyan-400"}),check:e.jsx(ko,{size:n,className:"text-emerald-400"}),uncheck:e.jsx(at,{size:n,className:"text-gray-400"}),hover:e.jsx(en,{size:n,className:"text-purple-400"}),scroll:e.jsx(ls,{size:n,className:"text-gray-400"}),assert:e.jsx(zs,{size:n,className:"text-green-400"}),annotate:e.jsx(No,{size:n,className:"text-violet-400"}),upload:e.jsx(qn,{size:n,className:"text-teal-400"}),drag:e.jsx(Zr,{size:n,className:"text-indigo-400"}),dialog:e.jsx(Tr,{size:n,className:"text-orange-400"}),custom:e.jsx(Ht,{size:n,className:"text-indigo-500"})};return e.jsx(e.Fragment,{children:u[t]||e.jsx(ht,{size:n-2,className:"text-gray-500"})})}function Vt(t,n){return{kind:"recorded-action",id:t.id||n(),actionType:t.type||t.actionType,description:t.description||t.type||t.actionType,selector:t.selector,value:t.value,url:t.url,secretEnv:t.secretEnv,timestamp:t.timestamp||Date.now(),assertType:t.assertType,expectedValue:t.expectedValue,screenshot:t.screenshot,elementRect:t.elementRect,...t.screenshot&&t.screenshotCrop?{screenshotCrop:t.screenshotCrop}:{},...t.instruction?{instruction:t.instruction}:{},...t.customKind?{customKind:t.customKind}:{},...Array.isArray(t.references)&&t.references.length?{references:t.references}:{},...Array.isArray(t.outputs)&&t.outputs.length?{outputs:t.outputs}:{},...Array.isArray(t.replaces)&&t.replaces.length?{replaces:t.replaces.map(u=>({id:u.id,type:u.type,description:u.description}))}:{},...t.valueFrom?{valueFrom:t.valueFrom}:{}}}function ra(t){var n,u;return{...t.instruction?{instruction:t.instruction}:{},...t.customKind?{customKind:t.customKind}:{},...(n=t.references)!=null&&n.length?{references:t.references}:{},...(u=t.outputs)!=null&&u.length?{outputs:t.outputs}:{},...t.valueFrom?{valueFrom:t.valueFrom}:{}}}function Tn(t){return t.filter(n=>n.kind==="recorded-action").map(n=>({id:n.id,type:n.actionType,description:n.description,selector:n.selector,value:n.value,url:n.url,timestamp:n.timestamp,assertType:n.assertType,expectedValue:n.expectedValue,screenshot:n.screenshot,elementRect:n.elementRect,...n.screenshotCrop?{screenshotCrop:n.screenshotCrop}:{},...ra(n)}))}function mi(t){return t.map(n=>{switch(n.kind){case"recorded-action":return{kind:n.kind,id:n.id,actionType:n.actionType,description:n.description,selector:n.selector,value:n.value,url:n.url,timestamp:n.timestamp,assertType:n.assertType,expectedValue:n.expectedValue,elementRect:n.elementRect,...ra(n)};case"text":return{kind:n.kind,id:n.id,text:n.text};case"tool":return{kind:n.kind,id:n.id,phase:n.phase,toolName:n.toolName,args:n.args,result:n.result,error:n.error,startedAt:n.startedAt,endedAt:n.endedAt};case"file-diff":return{kind:n.kind,id:n.id,filePath:n.filePath,diffType:n.diffType,diff:n.diff,linesAdded:n.linesAdded,linesRemoved:n.linesRemoved,via:n.via,unavailable:n.unavailable,netNoChange:n.netNoChange,omitted:n.omitted};case"error":case"user":case"system":return{kind:n.kind,id:n.id,text:n.text};default:return{kind:n.kind,id:n.id}}})}function fi(t,n){const u=new Map((t.actions||[]).filter(d=>d==null?void 0:d.id).map(d=>[d.id,d]));return(t.fullTimeline||[]).map(d=>{if(d.kind==="recorded-action"){const l=u.get(d.id);return Vt({...d,screenshot:d.screenshot||(l==null?void 0:l.screenshot),elementRect:d.elementRect||(l==null?void 0:l.elementRect),screenshotCrop:d.screenshot?d.screenshotCrop:l==null?void 0:l.screenshotCrop},n)}return d.kind==="text"?{kind:"text",id:d.id||n(),text:d.text||"",done:!0}:d.kind==="tool"?{kind:"tool",id:d.id||n(),toolId:d.toolId||`${d.toolName}::${d.args||""}`,phase:d.phase||"complete",toolName:d.toolName||"",args:d.args||"",result:d.result,error:d.error,startedAt:d.startedAt,endedAt:d.endedAt}:d.kind==="file-diff"?{kind:"file-diff",id:d.id||n(),filePath:d.filePath||"",diffType:d.diffType||"modified",diff:d.diff||"",linesAdded:d.linesAdded||0,linesRemoved:d.linesRemoved||0,via:d.via,unavailable:d.unavailable,netNoChange:d.netNoChange,omitted:d.omitted}:d.kind==="error"?{kind:"error",id:d.id||n(),text:d.text||""}:d.kind==="user"?{kind:"user",id:d.id||n(),text:d.text||""}:{kind:"system",id:d.id||n(),text:d.text||""}})}const hi=[/test result:\s*fail/i,/all\s+\d+\s+attempts\s+(exhausted|failed)/i,/attempts\s+exhausted/i,/could not.*(?:fix|make).*(?:pass|work)/i,/reached maximum tool iterations/i];function gi(t,n){if(n==="failed"||n==="stopped")return n;let u=0;for(let d=t.length-1;d>=0;d--)if(t[d].kind==="user"){u=d+1;break}for(const d of t.slice(u))if(d.kind==="error"||d.kind==="text"&&d.text&&hi.some(l=>l.test(d.text)))return"failed";return"success"}function bi(t,n,u){return!t||t.src!==n?!1:Math.abs(t.w-u.clipW)<=2&&Math.abs(t.h-u.clipH)<=2}function An(t,n){return new Promise(u=>{const d=new Image;d.onload=()=>{try{const l=document.createElement("canvas");l.width=n.clipW,l.height=n.clipH;const N=l.getContext("2d");if(!N){u(t);return}const p=d.naturalWidth/n.vpW,A=d.naturalHeight/n.vpH;N.drawImage(d,n.clipX*p,n.clipY*A,n.clipW*p,n.clipH*A,0,0,n.clipW,n.clipH),u(l.toDataURL("image/jpeg",.8))}catch{u(t)}},d.onerror=()=>u(t),d.src=t})}const yi=/\.(spec|test|e2e|cy)\.(ts|js|tsx|jsx|mjs|cjs)$|(^|[\\/])test_[^\\/]+\.py$|_test\.py$|\.(feature|robot)$|(Test|Tests|IT|Spec)\.(java|kt|rb|cs)$/;function En({onInsert:t,label:n}){return e.jsx("div",{className:"group/ins relative h-2 flex items-center",children:e.jsxs("button",{type:"button",onClick:t,"aria-label":n,title:n,className:"absolute left-10 right-3 -top-1 h-4 flex items-center opacity-0 group-hover/ins:opacity-100 focus-visible:opacity-100 transition-opacity focus:outline-none",children:[e.jsx("span",{className:"flex-1 h-px bg-indigo-500/50"}),e.jsxs("span",{className:"mx-1 inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full bg-indigo-500/15 text-[10px] font-medium text-indigo-700 dark:text-indigo-300",children:[e.jsx(tr,{size:10})," Custom step"]}),e.jsx("span",{className:"flex-1 h-px bg-indigo-500/50"})]})})}let _t=null;const vi=2e4,wi=/^(recorder-|ai-fix-|browser-(closed|launched)$)/;function ji(t,n){na();const u={clientId:wr(),state:t,buffer:[],overflow:!1,stop:null,replayed:!1};try{u.stop=n(d=>{if(wi.test(String((d==null?void 0:d.type)||""))){if(u.buffer.length>=vi){u.overflow=!0;return}u.buffer.push(d)}})}catch{}_t=u}function Ni(){const t=_t;if(!t)return null;const n=wr();return t.clientId&&n&&t.clientId!==n?null:t}function na(){var t;try{(t=_t==null?void 0:_t.stop)==null||t.call(_t)}catch{}_t=null}function ki(){var pr;const{subscribe:t,send:n}=Mn(),{toast:u}=Qr(),[d]=s.useState(Ni),l=d==null?void 0:d.state,{data:N}=Yn(),[p,A]=s.useState((l==null?void 0:l.phase)??"setup"),I=s.useRef(p);I.current=p;const[E,C]=s.useState((l==null?void 0:l.timeline)??[]),k=s.useRef(E);k.current=E;const T=s.useMemo(()=>new Map(E.map((r,a)=>[r.id,a])),[E]),[S,L]=s.useState((l==null?void 0:l.startUrl)??""),H=(()=>{const r=S.trim();if(!/^https?:\/\//i.test(r))return!1;try{return!!new URL(r).hostname}catch{return!1}})(),[D,V]=s.useState((l==null?void 0:l.testName)??""),[U,oe]=s.useState((l==null?void 0:l.mergeMode)??!1),[P,Y]=s.useState((l==null?void 0:l.targetTestFile)??""),[g,Z]=s.useState((l==null?void 0:l.targetTestName)??""),[B,ee]=s.useState((l==null?void 0:l.insertPosition)??"auto"),[J,ie]=s.useState(!1),[se,ue]=s.useState(""),[y,R]=s.useState(new Set),[v,W]=s.useState((l==null?void 0:l.userGuidance)??""),[re,$e]=s.useState((l==null?void 0:l.followUpPrompt)??""),[$,m]=s.useState((l==null?void 0:l.awaitingConfirmation)??!1),[X,w]=s.useState((l==null?void 0:l.genOutcome)??null),[pe,Ie]=s.useState(!1),[Xt,sn]=s.useState(""),cs=s.useRef(null),[he,bt]=s.useState([]),[ds,Rt]=s.useState(!1);s.useEffect(()=>{if(!P||!g){bt([]);return}if(N!=null&&N.suites){const r=N.suites.find(a=>a.file===P||a.file.replace(/\\/g,"/")===P.replace(/\\/g,"/"));if(r){const a=r.tests.find(x=>x.name===g);if(a!=null&&a.steps&&a.steps.length>0){bt(a.steps.map(x=>({keyword:x.keyword,name:x.name})));return}}}Rt(!0),_a(async()=>{const{getTestSourceByName:r}=await import("./index-DtBWNlVD.js").then(a=>a.iF);return{getTestSourceByName:r}},__vite__mapDeps([0,1,2,3,4])).then(({getTestSourceByName:r})=>{r(P,g).then(a=>{a!=null&&a.humanSteps&&a.humanSteps.length>0?bt(a.humanSteps.map(x=>({keyword:x.keyword,name:x.name}))):bt([])}).catch(()=>bt([])).finally(()=>Rt(!1))})},[P,g,N]);const[fe,$t]=s.useState((l==null?void 0:l.elapsedTime)??0),[Ge,Pe]=s.useState((l==null?void 0:l.actionCount)??0),[ge,_e]=s.useState((l==null?void 0:l.isPaused)??!1),Se=s.useRef((l==null?void 0:l.startTime)??0),He=s.useRef((l==null?void 0:l.pausedAt)??0),[We,yt]=s.useState((l==null?void 0:l.canAddSteps)??!0),Ce=s.useRef((l==null?void 0:l.executed)??!1),Jt=s.useRef((l==null?void 0:l.lastSavedRun)??null),[Ve,Zt]=s.useState((l==null?void 0:l.testSettings)??null),[ot,Ae]=s.useState(null),[vt,Kt]=s.useState(new Set),Is=s.useRef(new Map),us=s.useRef(`draft-${wr()||`local-${Math.random().toString(36).slice(2,10)}`}`),wt=()=>{const r=wr();return r&&!us.current.startsWith(`draft-${r}`)&&(us.current=`draft-${r}`),us.current},[es,ts]=s.useState(!1),Tt=Fn(),[it,lt]=s.useState(Tt.mode==="mobile"?"mobile":"web");s.useEffect(()=>{Tt.isLoading||(Tt.mode==="mobile"&&it!=="mobile"?lt("mobile"):Tt.mode==="web"&&it!=="web"&&lt("web"))},[Tt.mode,Tt.isLoading]);const[At,ct]=s.useState((l==null?void 0:l.activeSessionId)??null),[Ke,Bt]=s.useState(null),[sr,Ps]=s.useState(null),[xe,Be]=s.useState(null),Ar=s.useRef(null),xs=sa(Ar,640),[De,Ut]=s.useState(null),Ds=s.useRef(null),[Ye,Qe]=s.useState(null),[ss,Xe]=s.useState(null),[Et,Fs]=s.useState("below"),[rs,rr]=s.useState(null),ps=s.useRef(0),[nr,Mt]=s.useState(!1),[Je,Ls]=s.useState(!1),[ns,jt]=s.useState(null),[_s,Hs]=s.useState(!1),[Te,Ue]=s.useState((l==null?void 0:l.genLoading)??!1),[Ze,et]=s.useState((l==null?void 0:l.playbackLoading)??!1),{providerModels:ae,selectedProvider:tt,selectedModel:ye,select:ce}=Xn(l?{provider:l.selectedProvider,model:l.selectedModel}:void 0),le=s.useRef((l==null?void 0:l.streamText)??""),Ee=s.useRef((l==null?void 0:l.streamTextId)??null),dt=s.useRef((l==null?void 0:l.loadedFromHistory)??!1),zt=s.useRef((l==null?void 0:l.currentRequestId)??null),Nt=r=>{zt.current=r},[st,as]=s.useState((l==null?void 0:l.pendingPermission)??null),Ot=s.useRef((l==null?void 0:l.permissionQueue)??[]),ut=()=>{as(null),Ot.current=[]},[ar]=s.useState(1),[xt,Oe]=s.useState((l==null?void 0:l.playbackIndex)??-1),[It,rt]=s.useState((l==null?void 0:l.playbackTotal)??0),[we,je]=s.useState((l==null?void 0:l.assertActive)??!1),[Ne,Me]=s.useState((l==null?void 0:l.annotateActive)??!1),ze=s.useRef(null),Fe=s.useRef(!0),kt=s.useRef(0),te=()=>`rec-${Date.now().toString(36)}-${++kt.current}`,os=s.useRef({});os.current={phase:p,timeline:E,startUrl:S,testName:D,mergeMode:U,targetTestFile:P,targetTestName:g,insertPosition:B,userGuidance:v,followUpPrompt:re,awaitingConfirmation:$,genOutcome:X,elapsedTime:fe,actionCount:Ge,isPaused:ge,activeSessionId:At,genLoading:Te,pendingPermission:st,assertActive:we,annotateActive:Ne,canAddSteps:We,selectedProvider:tt,selectedModel:ye,playbackLoading:Ze,playbackIndex:xt,playbackTotal:It,testSettings:Ve};const ms=s.useRef(t);ms.current=t,s.useEffect(()=>()=>{ji({...os.current,currentRequestId:zt.current,permissionQueue:Ot.current,streamText:le.current,streamTextId:Ee.current,loadedFromHistory:dt.current,executed:Ce.current,lastSavedRun:Jt.current,startTime:Se.current,pausedAt:He.current},ms.current)},[]),s.useEffect(()=>{const r=ze.current;r&&Fe.current&&(r.scrollTop=r.scrollHeight)},[E]);const fs=()=>{const r=ze.current;r&&(Fe.current=r.scrollHeight-r.scrollTop-r.clientHeight<120)};s.useEffect(()=>{st&&ze.current&&(Fe.current=!0,requestAnimationFrame(()=>{ze.current&&(ze.current.scrollTop=ze.current.scrollHeight)}))},[st]),s.useEffect(()=>{var a;if(!xe)return;(a=Ds.current)==null||a.focus();const r=x=>{x.key==="Escape"&&Be(null)};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[xe]),s.useEffect(()=>{Ha().then(r=>Mt(r.active)).catch(()=>Mt(!1))},[p]);const hs=async r=>{let a=[];try{a=(await Ua()).actions||[]}catch{}const x=a.map(f=>Vt(f,te));C([{kind:"system",id:te(),text:r.recording?"Recording in progress — picked up where you left off":"Recording restored"},...x]),Pe(r.actionCount??x.length),$t(Math.floor((r.duration||0)/1e3)),r.startUrl&&L(r.startUrl),Zt(r.settings||null),r.sessionId&&ct(r.sessionId),r.recording?(Se.current=Date.now()-(r.duration||0),He.current=r.paused?Date.now():0,_e(!!r.paused),A("recording")):(yt(r.canAddSteps!==!1),A("stopped"))};s.useEffect(()=>{if(d&&d.state.phase!=="setup")return;let r=!0;return(async()=>{var a;await Dn().catch(()=>null);try{const x=await Ka();r&&(x.recording||x.hasSession)&&await hs(x)}catch{}if(!(!r||I.current!=="setup"))for(const x of[wt(),...Ba().map(f=>`draft-${f}`),"draft-current"])try{const f=await zn(x);if(f&&((a=f.actions)==null?void 0:a.length)>0){r&&Bt(f);break}}catch{}})(),()=>{r=!1}},[]),s.useEffect(()=>{if(p!=="recording")return;if(Se.current||(Se.current=Date.now()),ge){He.current||(He.current=Date.now());return}He.current&&(Se.current+=Date.now()-He.current,He.current=0);const r=()=>$t(Math.floor((Date.now()-Se.current)/1e3));r();const a=setInterval(r,1e3);return()=>clearInterval(a)},[p,ge]);const or=s.useRef(fe);or.current=fe;const ir=s.useRef(S);ir.current=S,s.useEffect(()=>{if(p!=="recording")return;const r=setInterval(()=>{var M;const a=Tn(k.current);if(a.length===0)return;const x=((M=a.find(c=>c.type==="navigate"))==null?void 0:M.url)||ir.current||"";let f="recording";try{x&&(f=new URL(x).hostname)}catch{}pn({id:wt(),name:`Draft — ${f}`,url:x,status:"draft",actions:a,duration:or.current*1e3}).catch(()=>{})},1e4);return()=>clearInterval(r)},[p]),s.useEffect(()=>{var K,ne;if(p!=="done"||$)return;const r=gi(E,X);if(r!==X&&w(r),dt.current){dt.current=!1;return}if(!Ce.current)return;const a=Tn(E);if(a.length===0)return;const x=`${At}:${E.length}:${(K=E[E.length-1])==null?void 0:K.id}`;if(Jt.current===x)return;Jt.current=x;const f=((ne=a.find(Q=>Q.type==="navigate"))==null?void 0:ne.url)||S||"",M=At||`session-${Date.now()}`;let c="test";try{f&&(c=new URL(f).hostname)}catch{c="unknown"}const z=(U&&g?g:"")||D||`Recording — ${c}`;pn({id:M,name:z,rename:!!(U&&g||D),url:f,status:"generated",outcome:r,actionCount:a.length,actions:a,fullTimeline:mi(E),duration:fe*1e3,settings:Ve||null}).then(()=>{At||ct(M)}).catch(()=>{})},[p,$]);const pt=s.useCallback(()=>{if(le.current&&Ee.current){const r=Ee.current,a=le.current;C(x=>{const f=x.findIndex(M=>M.id===r);if(f>=0){const M=[...x];return M[f]={kind:"text",id:r,text:a,done:!0},M}return x})}le.current="",Ee.current=null},[]),Ks=s.useRef(new Set);s.useEffect(()=>{for(const r of E){if(r.kind!=="recorded-action"||!r.screenshot||!r.screenshotCrop)continue;const a=`${r.id}:${r.screenshot.length}`;if(Ks.current.has(a))continue;Ks.current.add(a);const{id:x,screenshot:f,screenshotCrop:M}=r;An(f,M).then(c=>{Ks.current.delete(a),c!==f&&C(z=>z.map(K=>{if(K.id!==x||K.kind!=="recorded-action"||K.screenshot!==f)return K;const{screenshotCrop:ne,...Q}=K;return{...Q,screenshot:c}}))})}},[E]),s.useEffect(()=>{var x;const r=f=>{if(f.type==="recorder-action"){const c=f.action,z=c.id||te();if(typeof z=="string"&&z.endsWith("-screenshot")){const K=z.replace("-screenshot",""),ne=Q=>C(de=>de.map(Re=>Re.id===K&&Re.kind==="recorded-action"?{...Re,screenshot:Q,elementRect:c.elementRect}:Re));c.screenshotCrop&&c.screenshot?An(c.screenshot,c.screenshotCrop).then(ne):ne(c.screenshot);return}if(typeof z=="string"&&z.endsWith("-update")){C(K=>{const ne=[...K];for(let Q=ne.length-1;Q>=0;Q--){const de=ne[Q];if(de.kind==="recorded-action"&&de.actionType==="fill"){ne[Q]={...de,description:c.description||de.description,value:c.value??de.value};break}}return ne});return}C(K=>[...K,Vt({...c,id:z},te)]),Pe(K=>K+1),c.type==="annotate"&&Me(!1),c.type==="assert"&&je(!1);return}if(f.type==="recorder-annotate-mode"&&Me(!!f.active),f.type==="recorder-assert-mode"){je(!!f.active);return}if(f.type==="browser-closed"){Mt(!1),I.current==="recording"&&(C(c=>[...c,{kind:"system",id:te(),text:"Browser closed — recording stopped"}]),A("stopped"),je(!1),Me(!1)),yt(!1);return}if(f.type==="browser-launched"){Mt(!0);return}if(f.type==="recorder-status"){if(f.status==="recording")A("recording"),_e(!1),Se.current||(Se.current=Date.now());else if(f.status==="paused")_e(!0);else if(f.status==="stopped"){A("stopped"),_e(!1);const c=f;c.sessionId&&ct(c.sessionId),typeof c.actionCount=="number"&&Pe(c.actionCount)}else f.status==="reset"&&(A("setup"),C([]),Pe(0),$t(0),ut(),m(!1),w(null),ct(null));return}if(f.type==="recorder-playback"){const c=f;c.status==="started"?(A("playback"),Oe(0),rt(c.totalActions||0),C(z=>[...z,{kind:"system",id:te(),text:`Playback started — replaying ${c.totalActions} action(s)...`}])):c.status==="action"?(Oe(c.index+1),C(z=>[...z,{kind:"playback-action",id:te(),actionType:c.actionType||"action",description:c.description||`Action ${c.index+1}`,status:"done"}])):c.status==="action-error"?C(z=>[...z,{kind:"playback-action",id:te(),actionType:c.actionType||"action",description:c.description||`Action ${c.index+1}`,status:"error"}]):c.status==="done"?(A("stopped"),et(!1),C(z=>[...z,{kind:"system",id:te(),text:`Playback complete — ${c.replayed||0} of ${c.total||0} actions replayed${c.errors?` (${c.errors} errors)`:""}`}])):c.status==="error"&&(A("stopped"),et(!1),C(z=>[...z,{kind:"error",id:te(),text:`Playback failed: ${c.error||"Unknown error"}`}]));return}const M=f.requestId;if(!(!M||M!==zt.current))if(f.type==="ai-fix-stream"){const c=f.content;if(Ee.current){le.current+=c;const z=Ee.current,K=le.current;C(ne=>{const Q=ne.findIndex(de=>de.id===z);if(Q>=0){const de=[...ne];return de[Q]={kind:"text",id:z,text:K},de}return ne})}else{const z=te();Ee.current=z,le.current=c,C(K=>[...K,{kind:"text",id:z,text:c}])}}else if(f.type==="ai-fix-tool"){const c=f,z=`${c.toolName}::${c.args||""}`;c.phase==="start"?(pt(),C(K=>[...K,{kind:"tool",id:te(),toolId:z,phase:"start",toolName:c.toolName,args:c.args||"",startedAt:Date.now()}])):C(K=>{const ne=[...K].reverse().findIndex(Q=>Q.kind==="tool"&&Q.toolId===z&&Q.phase==="start");if(ne>=0){const Q=K.length-1-ne,de=[...K];return de[Q]={...de[Q],phase:c.phase,result:c.result,error:c.error,endedAt:Date.now()},de}return[...K,{kind:"tool",id:te(),toolId:z,phase:c.phase,toolName:c.toolName,args:c.args||"",result:c.result,error:c.error}]})}else if(f.type==="ai-fix-file-diff"){const c=f;pt(),C(z=>[...z,{kind:"file-diff",id:te(),filePath:c.filePath,diffType:c.diffType,diff:c.diff,linesAdded:c.linesAdded,linesRemoved:c.linesRemoved,via:c.via==="detected"?"detected":void 0,unavailable:c.unavailable,netNoChange:c.netNoChange===!0||void 0}])}else if(f.type==="ai-fix-file-changes-omitted"){const c=f;C(z=>[...z,{kind:"file-diff",id:te(),filePath:"",diffType:"modified",diff:"",via:"detected",omitted:{count:Number(c.count)||0,examples:Array.isArray(c.examples)?c.examples:[]}}])}else if(f.type==="ai-fix-permission"){const c=f,z={permissionId:c.permissionId,toolName:c.toolName,args:c.args||"",fullPath:c.fullPath||void 0};pt(),as(K=>K?(Ot.current.push(z),K):z)}else f.type==="ai-fix-done"?(pt(),ut(),A("done"),Ue(!1)):f.type==="ai-fix-error"&&(pt(),C(c=>[...c,{kind:"error",id:te(),text:f.message||"Unknown error"}]),ut(),m(!1),A("done"),Ue(!1),w("failed"))},a=t(r);if(d&&!d.replayed){d.replayed=!0;try{(x=d.stop)==null||x.call(d)}catch{}d.stop=null;for(const f of d.buffer.splice(0))try{r(f)}catch{}d.overflow&&C(f=>[...f,{kind:"system",id:te(),text:"Some live updates were missed while this screen was closed."}])}return _t&&na(),a},[t,pt]);const Bs=async()=>{if(!H||Je)return;Ls(!0),jt(null);const r=te();C([{kind:"system",id:r,text:S?`Recording started — navigating to ${S}`:"Recording started — interact with the browser"}]),Pe(0);try{await Qa({url:S.trim(),browser:"chromium",headless:!1}),A("recording"),_e(!1),$t(0),Se.current=Date.now(),He.current=0,Fe.current=!0,yt(!0),w(null),m(!1),Zt(null),Kt(new Set),Ce.current=!1,ct(null),dt.current=!1}catch(a){C([]);const x=String((a==null?void 0:a.message)||a).replace(/^Error:\s*/,"");jt(x),u("error",`Couldn't start recording: ${x}`)}finally{Ls(!1)}},gs=async()=>{Hs(!0);try{const r=await Ga();if(C(a=>[...a,{kind:"system",id:te(),text:`Recording stopped — ${r.actionCount} action(s) captured in ${(r.duration/1e3).toFixed(1)}s`}]),A("stopped"),_e(!1),je(!1),Me(!1),yt(!0),Bt(null),Or(wt()).catch(()=>{}),r.sessionId&&ct(r.sessionId),!D&&r.actions.length>0){const a=r.actions.find(x=>x.type==="navigate");if(a!=null&&a.url)try{const x=new URL(a.url).hostname.replace(/\./g,"-");V(`${x}-test`)}catch{}}}catch(r){C(a=>[...a,{kind:"error",id:te(),text:`Failed to stop recording: ${r}`}])}finally{Hs(!1)}},ke=async()=>{try{await qa(),_e(!0),C(r=>[...r,{kind:"system",id:te(),text:"⏸ Recording paused — interact freely without recording"}])}catch(r){u("error",`Couldn't pause the recording: ${r}`)}},Pt=async()=>{try{await Oa(),_e(!1),C(r=>[...r,{kind:"system",id:te(),text:"▶ Recording resumed"}])}catch(r){u("error",`Couldn't resume the recording: ${r}`)}},bs=async()=>{try{const r=await Wa();r!=null&&r.success&&(Se.current=Date.now()-fe*1e3,He.current=0,A("recording"),_e(!1),C(a=>[...a,{kind:"system",id:te(),text:"➕ Adding more steps to the recording"}]))}catch(r){C(a=>[...a,{kind:"system",id:te(),text:`Failed to resume recording: ${r}`}])}},ys=async r=>{var M;if(I.current==="recording"||I.current==="generating"||I.current==="playback"){u("info",I.current==="generating"?"Wait for the generation to finish (or stop it) before opening another recording.":"Stop the current recording before opening another one.");return}let a=!1,x=r.settings||null;try{const c=await Ya(r.id);a=!!c.canAddSteps,c.settings!==void 0&&(x=c.settings||null)}catch(c){u("error",`Couldn't open the recording: ${c}`);return}if(dt.current=!0,Ce.current=!1,Jt.current=null,ct(r.id||null),ts(!1),yt(a),Zt(x),Kt(new Set),Pe(r.actionCount||((M=r.actions)==null?void 0:M.length)||0),$t(Math.round((r.duration||0)/1e3)),r.name&&V(r.name),w(r.outcome||null),m(!1),ut(),Nt(null),Fe.current=!0,r.fullTimeline&&r.fullTimeline.length>0){A(r.status==="completed"||r.status==="generated"?"done":"stopped"),C(fi(r,te));return}A("stopped");const f=r.actions||[];C([{kind:"system",id:te(),text:`Loaded recording: ${r.name} (${f.length} actions)`},...f.map(c=>Vt(c,te))])},Us=async()=>{if(Te)return;Ue(!0),ut(),le.current="",Ee.current=null,w(null),dt.current=!1,Ce.current=!1,Fe.current=!0;const r=`recorder-${Date.now()}`;Nt(r),A("generating"),m(!0),C(a=>[...a,{kind:"system",id:te(),text:U?`Analyzing project to merge recorded actions into — ${P}...`:"Analyzing your project patterns and recorded actions..."}]);try{await so({requestId:r,testName:D||"recorded test",model:ye||void 0,provider:tt||void 0,mergeMode:U||void 0,targetTestFile:U?P:void 0,insertPosition:U?B:void 0,userGuidance:U&&v.trim()?v.trim():void 0,sessionId:At||void 0,analyzeOnly:!0,settings:Ve})}catch(a){C(x=>[...x,{kind:"error",id:te(),text:`Failed to start code generation: ${a}`}]),Ue(!1),m(!1),Nt(null),A("stopped")}},Os=async()=>{const r=zt.current;r&&(pt(),Nt(null),ut(),m(!1),A("done"),Ue(!1),w("stopped"),C(a=>[...a,{kind:"system",id:te(),text:"Generation stopped by user"}]),no({requestId:r}).catch(()=>{}))},qs=async()=>{var Re;if(Te)return;const r=re.trim();if(!r&&!$)return;const a=$,x=!r||/^(proceed|ok|yes|go|continue|looks good|lgtm|sure|do it|go ahead)$/i.test(r),f=a&&x?'The user approved the analysis. Proceed with the implementation now — write the code, run the test, fix any failures, and provide a summary. Start with a brief acknowledgment like "Great, let me implement this now." before writing code.':a&&r?`The user reviewed your analysis and has this feedback:
24
+ `),children:["replaces ",t.replaces.length," step",t.replaces.length===1?"":"s"]}),t.valueFrom&&e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-teal-500/10 text-[10px] font-mono text-teal-700 dark:text-teal-300",children:`uses {${t.valueFrom}}`})]}),t.primary&&e.jsxs("div",{className:"text-[11px] text-gray-500 group-hover:text-gray-700 dark:group-hover:text-gray-400 truncate transition-colors",children:[e.jsxs("span",{children:[t.primary.strategy,"="]}),e.jsx("code",{children:t.primary.value})]})]})}),u&&!d&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-0 group-hover:opacity-100 focus-within:opacity-100",children:ie}),J&&e.jsx("button",{type:"button",onClick:J,className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-1.5 rounded text-gray-500 hover:text-amber-500 hover:bg-black/[0.06] dark:hover:bg-white/10 transition-colors",title:"Put the replaced steps back","aria-label":"Put the replaced steps back",children:e.jsx(Gn,{size:12})}),e.jsx("button",{type:"button",onClick:y&&ee?ee:p,className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-1.5 rounded text-gray-500 hover:text-indigo-500 dark:hover:text-indigo-400 hover:bg-black/[0.06] dark:hover:bg-white/10 transition-colors",title:y?"Edit custom step":"Edit description","aria-label":y?"Edit custom step":"Edit description",children:e.jsx(wo,{size:12})}),e.jsx("button",{type:"button",onClick:E,className:"opacity-0 group-hover:opacity-100 focus-visible:opacity-100 p-1.5 rounded text-gray-500 hover:text-red-500 dark:hover:text-red-400 hover:bg-red-500/10 transition-colors",title:"Delete step","aria-label":"Delete step",children:e.jsx(Es,{size:12})})]})]})}function oi({action:t,onOpen:n,Fallback:u}){if(!t.screenshot)return e.jsx("div",{className:"flex-shrink-0 w-[48px] h-[64px] rounded-md bg-surface-2 border border-white/5 flex items-center justify-center",children:e.jsx(u,{size:16,className:"text-gray-400"})});let N,p=null;const A=t.screenshotSize,I=t.elementRect;if(A&&I&&I.width>0&&I.height>0){const E=I.height,k=Math.min(4,64*.65/Math.max(20,E)),T=A.width*k,S=A.height*k,L=(I.x+I.width/2)*k,H=(I.y+I.height/2)*k,D=48/2-L,V=64/2-H;N={width:48,height:64,backgroundImage:`url(${t.screenshot})`,backgroundSize:`${T}px ${S}px`,backgroundPosition:`${D}px ${V}px`,backgroundRepeat:"no-repeat",backgroundColor:"#000"},p={left:I.x*k+D,top:I.y*k+V,width:I.width*k,height:I.height*k}}else if(A){const E=Math.min(48/A.width,64/A.height),C=A.width*E,k=A.height*E;N={width:48,height:64,backgroundImage:`url(${t.screenshot})`,backgroundSize:`${C}px ${k}px`,backgroundPosition:"center",backgroundRepeat:"no-repeat",backgroundColor:"#000"}}else N={width:48,height:64,backgroundImage:`url(${t.screenshot})`,backgroundSize:"cover",backgroundPosition:"center",backgroundColor:"#000"};return e.jsxs("button",{type:"button",onClick:E=>{E.stopPropagation(),n()},onMouseDown:E=>E.stopPropagation(),onDragStart:E=>{E.preventDefault(),E.stopPropagation()},draggable:!1,title:"Click to view full screenshot",className:"flex-shrink-0 relative rounded-md border border-white/10 hover:border-blue-400/60 hover:shadow-[0_0_10px_rgba(96,165,250,0.35)] overflow-hidden transition-all",style:{width:48,height:64},children:[e.jsx("div",{style:N}),p&&e.jsx("div",{className:"absolute pointer-events-none border-[2px] border-red-400 rounded-[2px]",style:{...p,boxShadow:"0 0 0 1px rgba(255,255,255,0.4), 0 0 6px rgba(239,68,68,0.6)"}})]})}function Cs({label:t,hint:n,onClick:u,disabled:d,paused:l}){return e.jsxs("button",{type:"button",onClick:u,disabled:d,className:"inline-flex items-center gap-1 px-2 py-0.5 rounded border border-white/10 bg-surface-2 text-gray-300 hover:bg-white/10 hover:text-gray-100 disabled:opacity-40 disabled:cursor-not-allowed",title:l?`Press ${t} (not recorded while paused)`:`Record ${t} key press`,children:[n&&e.jsx("span",{className:"text-gray-500",children:n}),e.jsx("span",{children:t})]})}function Cn({active:t,onClick:n,children:u}){return e.jsxs("label",{onClick:n,className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs cursor-pointer transition-colors ${t?"bg-indigo-500/15 text-indigo-300 border border-indigo-500/20":"bg-surface-2 text-gray-400 border border-white/5 hover:text-gray-300"}`,children:[e.jsx("input",{type:"radio",checked:t,onChange:n,className:"hidden"}),u]})}function ii({selectedFile:t,selectedTest:n,open:u,setOpen:d,search:l,setSearch:N,expanded:p,setExpanded:A,suites:I,loading:E,onPick:C}){const k=l.toLowerCase().trim(),T=s.useMemo(()=>k?I.filter(S=>Yt(S.name,k)||S.file.toLowerCase().includes(k)||S.tests.some(L=>Yt(L.name,k))):I,[I,k]);return e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",onClick:()=>d(!u),className:"w-full px-3 py-2 rounded-lg bg-white dark:bg-white/[0.04] border border-gray-200 dark:border-white/10 text-xs text-left focus:outline-none focus:border-indigo-500/40 transition-colors",children:n?e.jsxs("div",{title:n,children:[e.jsx("span",{className:"text-gray-800 dark:text-gray-200",children:Rs(n)}),e.jsx("span",{className:"text-[10px] text-gray-500 block mt-0.5 truncate",children:t})]}):e.jsx("span",{className:"text-gray-400 dark:text-gray-600",children:"Select a test…"})}),u&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>d(!1)}),e.jsxs("div",{className:"absolute bottom-full left-0 w-full mb-1 bg-surface-1 border border-white/10 rounded-lg shadow-xl z-40 overflow-hidden",children:[e.jsx("div",{className:"px-2 py-2 border-b border-white/5",children:e.jsx("input",{type:"text",value:l,onChange:S=>N(S.target.value),placeholder:"Search suites and tests…",className:"w-full px-2.5 py-1.5 rounded-md bg-surface-2 border border-white/10 text-xs text-gray-200 placeholder-gray-600 focus:outline-none",autoFocus:!0})}),e.jsxs("div",{className:"max-h-52 overflow-y-auto",children:[E&&T.length===0&&e.jsxs("div",{className:"flex items-center justify-center py-4 text-[11px] text-gray-500 gap-1.5",children:[e.jsx(ve,{size:11,className:"animate-spin"})," Loading tests…"]}),!E&&T.length===0&&e.jsxs("div",{className:"text-center text-[11px] text-gray-500 py-4 px-3",children:["No tests found in the project. Add a test file under a recognized test directory (e.g. ",e.jsx("code",{className:"text-gray-400",children:"tests/"}),") and it'll appear here."]}),T.map(S=>{const L=S.file,H=p.has(L)||!!k,D=k?S.tests.filter(U=>Yt(U.name,k)||Yt(S.name,k)):S.tests,V=()=>A(U=>{const oe=new Set(U);return oe.has(L)?oe.delete(L):oe.add(L),oe});return e.jsxs("div",{children:[e.jsxs("button",{onClick:V,className:"w-full text-left px-3 py-2 text-xs hover:bg-white/5 flex items-center gap-2 transition-colors",children:[e.jsx(ls,{size:11,className:`text-gray-500 transition-transform ${H?"":"-rotate-90"}`}),e.jsx("span",{className:"text-gray-300 font-medium truncate",title:S.name,children:Rs(S.name)}),e.jsx("span",{className:"text-[10px] text-gray-500 bg-surface-2 px-1.5 py-0.5 rounded-full ml-1.5 flex-shrink-0",children:S.tests.length})]}),H&&D.map((U,oe)=>{const P=t===S.file&&n===U.name;return e.jsx("button",{onClick:()=>C(S.file,U.name),className:`w-full text-left pl-8 pr-3 py-1.5 text-xs transition-colors ${P?"bg-indigo-500/10 text-indigo-300":"text-gray-400 hover:bg-white/5 hover:text-gray-200"}`,children:e.jsx("span",{className:"truncate block",title:U.name,children:Rs(U.name)})},oe)})]},L)})]})]})]})]})}function Rn({value:t,onChange:n,options:u,placeholder:d,disabled:l,dense:N}){return e.jsxs("div",{className:`relative ${N?"":"flex-1"}`,children:[e.jsxs("select",{value:t,onChange:p=>n(p.target.value),disabled:l,className:`appearance-none bg-surface-2 border border-white/5 rounded-lg ${N?"px-2 py-1 pr-7 text-[12px]":"w-full px-3 py-2.5 pr-8 text-[15px]"} text-gray-200 focus:outline-none focus:border-red-500/40 focus:ring-1 focus:ring-red-500/20 disabled:opacity-40`,children:[d&&e.jsx("option",{value:"",disabled:!0,children:d}),u.map(p=>e.jsx("option",{value:p.value,disabled:p.disabled,children:p.label},p.value))]}),e.jsx(ls,{size:N?11:14,className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 pointer-events-none"})]})}function sa(t,n){const[u,d]=s.useState(!1);return s.useEffect(()=>{const l=t.current;if(!l||typeof ResizeObserver>"u")return;const N=()=>d(l.getBoundingClientRect().width<n);N();const p=new ResizeObserver(N);return p.observe(l),()=>p.disconnect()},[t,n]),u}function li(t){const n=Math.floor(t/1e3),u=Math.floor(n/60).toString().padStart(2,"0"),d=(n%60).toString().padStart(2,"0");return`${u}:${d}`}function ci({recorderMode:t,setRecorderMode:n}){const u=Fn(),[d,l]=s.useState("setup"),[N,p]=s.useState(0),[A,I]=s.useState(0),[E,C]=s.useState(!1),[k,T]=s.useState(!1),[S,L]=s.useState(!1),H=s.useRef(null),D=s.useRef(null),V=sa(D,640),[U,oe]=s.useState(!1),P=s.useCallback((ue,y)=>{l(ue),p(y.actionCount),I(y.durationMs),C(y.paused),T(y.assertMode),L(y.annotateMode)},[]),Y=s.useCallback(ue=>{H.current=ue},[]),g=()=>{H.current&&(E?(H.current.resume(),C(!1)):(H.current.pause(),C(!0)))},Z=ue=>async()=>{if(H.current){oe(!0);try{await ue()}finally{oe(!1)}}},B=Z(()=>H.current.stop()),ee=Z(()=>H.current.reset()),J=Z(()=>H.current.addMoreSteps()),ie=Z(()=>H.current.toggleAssert()),se=Z(()=>H.current.toggleAnnotate());return e.jsx(Ro,{children:e.jsxs("div",{className:"h-full flex flex-col relative",children:[d!=="generating"&&d!=="done"&&e.jsx("div",{ref:D,className:"flex-shrink-0 px-4 py-3 border-b border-white/5 bg-surface-1",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("button",{onClick:()=>{var ue;return(ue=H.current)==null?void 0:ue.openHistory()},className:"flex-shrink-0 p-1.5 rounded-lg text-gray-500 hover:text-gray-300 hover:bg-white/5 transition-colors",title:"Recording History","aria-label":"Recording History",children:e.jsx(Sr,{size:16})}),d==="recording"?e.jsxs(e.Fragment,{children:[E?e.jsxs(e.Fragment,{children:[e.jsx(Cr,{size:14,className:"text-amber-400"}),e.jsx("span",{className:"text-sm font-semibold text-amber-400",children:"Paused"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"relative flex h-3 w-3",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-red-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-3 w-3 bg-red-500"})]}),e.jsx("span",{className:"text-sm font-semibold text-red-400",children:"Recording"})]}),e.jsx("span",{className:"text-xs text-gray-500 font-mono",children:li(A)}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-red-500/10 text-red-400 border border-red-500/20",children:N})]}):d==="starting"?e.jsxs(e.Fragment,{children:[e.jsx(ve,{size:14,className:"animate-spin text-brand-400"}),e.jsx("span",{className:"text-sm font-semibold text-brand-300",children:"Starting session…"})]}):d==="stopped"?e.jsxs(e.Fragment,{children:[e.jsx(at,{size:14,className:"flex-shrink-0 text-amber-400"}),e.jsx("span",{className:"text-sm font-semibold text-amber-300 truncate",children:"Recording Stopped"}),e.jsxs("span",{className:"flex-shrink-0 whitespace-nowrap text-xs px-2 py-0.5 rounded-full bg-amber-500/10 text-amber-400 border border-amber-500/20",children:[N," action",N!==1?"s":""]})]}):e.jsxs(e.Fragment,{children:[e.jsx(ht,{size:14,className:"text-gray-400"}),e.jsx("span",{className:"text-sm font-semibold text-gray-300",children:"Mobile Recorder"})]}),u.isAmbiguous&&e.jsx("div",{className:"ml-2 flex-shrink-0",children:e.jsx(Qn,{value:t,onChange:n,disabled:d==="recording"||d==="starting"})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[d==="recording"&&e.jsxs(e.Fragment,{children:[!E&&e.jsxs(e.Fragment,{children:[e.jsx(Ct,{label:k?"Exit assertion mode":"Add an assertion",hint:k?void 0:"Tap an element on the device to check it, instead of tapping it",children:e.jsxs("button",{"aria-label":k?"Exit assertion mode":"Add an assertion",onClick:ie,disabled:U,className:`flex items-center gap-1 px-2 py-1.5 rounded-lg text-xs font-medium transition-colors ${k?"bg-green-500/25 text-green-300 border border-green-500/40 shadow-[0_0_8px_rgba(16,185,129,0.15)]":"bg-surface-2 text-gray-400 border border-white/5 hover:text-green-300 hover:bg-green-500/10 hover:border-green-500/20"}`,children:[e.jsx(zs,{size:14}),k&&e.jsx("span",{children:"ON"})]})}),e.jsx(Ct,{label:S?"Exit annotate mode":"Annotate a step",hint:S?void 0:"Describe the action or check you want next — even a complex one — and the AI will implement it for you",children:e.jsxs("button",{"aria-label":S?"Exit annotate mode":"Annotate a step",onClick:se,disabled:U,className:`flex items-center gap-1 px-2 py-1.5 rounded-lg text-xs font-medium transition-colors ${S?"bg-purple-500/25 text-purple-300 border border-purple-500/40 shadow-[0_0_8px_rgba(139,92,246,0.15)]":"bg-surface-2 text-gray-400 border border-white/5 hover:text-purple-300 hover:bg-purple-500/10 hover:border-purple-500/20"}`,children:[e.jsx(Qs,{size:14}),S&&e.jsx("span",{children:"ON"})]})})]}),e.jsx(Ct,{label:E?"Resume recording":"Pause recording",hint:E?"Your taps are recorded again":"Use the device freely — nothing is recorded until you resume",children:e.jsx("button",{onClick:g,"aria-label":E?"Resume recording":"Pause recording",className:`flex items-center justify-center w-8 h-8 rounded-lg transition-colors ${E?"bg-amber-500/20 text-amber-300 border border-amber-500/30 hover:bg-amber-500/30":"bg-surface-2 text-gray-400 border border-white/5 hover:text-amber-300 hover:bg-amber-500/10 hover:border-amber-500/20"}`,children:E?e.jsx(Ts,{size:14}):e.jsx(Cr,{size:14})})}),e.jsx(Ct,{label:"Stop recording",hint:"Then review the steps and generate the test",children:e.jsx("button",{onClick:B,disabled:U,className:"flex items-center justify-center w-8 h-8 rounded-lg bg-red-500/20 text-red-300 border border-red-500/30 hover:bg-red-500/30 transition-colors disabled:opacity-50","aria-label":"Stop recording",children:U?e.jsx(ve,{size:14,className:"animate-spin"}):e.jsx(at,{size:14})})})]}),d==="stopped"&&e.jsxs(e.Fragment,{children:[e.jsx(Xs,{tone:"brand",compact:V,icon:e.jsx(tr,{size:13}),label:"Add More Steps",hint:"Continue recording — add more steps to this recording",disabled:U,onClick:J}),e.jsx(Xs,{compact:V,icon:e.jsx(kr,{size:13}),label:"New Recording",hint:"Start over with a new recording (this one stays in History)",disabled:U,onClick:ee})]})]})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto transition-all duration-200",children:e.jsx(ri,{onPhaseChange:P,registerControls:Y})})]})})}const di=!1,ui={click:"border-l-blue-500",dblclick:"border-l-blue-500",fill:"border-l-amber-500",type:"border-l-amber-500",hover:"border-l-purple-500",select:"border-l-cyan-500",check:"border-l-emerald-500",uncheck:"border-l-emerald-500",assert:"border-l-green-500",annotate:"border-l-violet-500",navigate:"border-l-gray-500",press:"border-l-slate-500",upload:"border-l-teal-500",drag:"border-l-indigo-500",dialog:"border-l-orange-500",custom:"border-l-indigo-500"},xi=new Set(["annotate","assert","hover","dialog","custom"]),$n=new Set(["fill","type","select","navigate"]);function pi(t){const n=Math.floor(t/60),u=t%60;return`${n}:${u.toString().padStart(2,"0")}`}function Ur({type:t,size:n=12}){const u={click:e.jsx(Nr,{size:n,className:"text-blue-400"}),dblclick:e.jsx(Nr,{size:n,className:"text-blue-300"}),fill:e.jsx(As,{size:n,className:"text-emerald-400"}),type:e.jsx(As,{size:n,className:"text-emerald-400"}),press:e.jsx(Co,{size:n,className:"text-amber-400"}),navigate:e.jsx(tn,{size:n,className:"text-purple-400"}),select:e.jsx(So,{size:n,className:"text-cyan-400"}),check:e.jsx(ko,{size:n,className:"text-emerald-400"}),uncheck:e.jsx(at,{size:n,className:"text-gray-400"}),hover:e.jsx(en,{size:n,className:"text-purple-400"}),scroll:e.jsx(ls,{size:n,className:"text-gray-400"}),assert:e.jsx(zs,{size:n,className:"text-green-400"}),annotate:e.jsx(No,{size:n,className:"text-violet-400"}),upload:e.jsx(qn,{size:n,className:"text-teal-400"}),drag:e.jsx(Zr,{size:n,className:"text-indigo-400"}),dialog:e.jsx(Tr,{size:n,className:"text-orange-400"}),custom:e.jsx(Ht,{size:n,className:"text-indigo-500"})};return e.jsx(e.Fragment,{children:u[t]||e.jsx(ht,{size:n-2,className:"text-gray-500"})})}function Vt(t,n){return{kind:"recorded-action",id:t.id||n(),actionType:t.type||t.actionType,description:t.description||t.type||t.actionType,selector:t.selector,value:t.value,url:t.url,secretEnv:t.secretEnv,timestamp:t.timestamp||Date.now(),assertType:t.assertType,expectedValue:t.expectedValue,screenshot:t.screenshot,elementRect:t.elementRect,...t.screenshot&&t.screenshotCrop?{screenshotCrop:t.screenshotCrop}:{},...t.instruction?{instruction:t.instruction}:{},...t.customKind?{customKind:t.customKind}:{},...Array.isArray(t.references)&&t.references.length?{references:t.references}:{},...Array.isArray(t.outputs)&&t.outputs.length?{outputs:t.outputs}:{},...Array.isArray(t.replaces)&&t.replaces.length?{replaces:t.replaces.map(u=>({id:u.id,type:u.type,description:u.description}))}:{},...t.valueFrom?{valueFrom:t.valueFrom}:{}}}function ra(t){var n,u;return{...t.instruction?{instruction:t.instruction}:{},...t.customKind?{customKind:t.customKind}:{},...(n=t.references)!=null&&n.length?{references:t.references}:{},...(u=t.outputs)!=null&&u.length?{outputs:t.outputs}:{},...t.valueFrom?{valueFrom:t.valueFrom}:{}}}function Tn(t){return t.filter(n=>n.kind==="recorded-action").map(n=>({id:n.id,type:n.actionType,description:n.description,selector:n.selector,value:n.value,url:n.url,timestamp:n.timestamp,assertType:n.assertType,expectedValue:n.expectedValue,screenshot:n.screenshot,elementRect:n.elementRect,...n.screenshotCrop?{screenshotCrop:n.screenshotCrop}:{},...ra(n)}))}function mi(t){return t.map(n=>{switch(n.kind){case"recorded-action":return{kind:n.kind,id:n.id,actionType:n.actionType,description:n.description,selector:n.selector,value:n.value,url:n.url,timestamp:n.timestamp,assertType:n.assertType,expectedValue:n.expectedValue,elementRect:n.elementRect,...ra(n)};case"text":return{kind:n.kind,id:n.id,text:n.text};case"tool":return{kind:n.kind,id:n.id,phase:n.phase,toolName:n.toolName,args:n.args,result:n.result,error:n.error,startedAt:n.startedAt,endedAt:n.endedAt};case"file-diff":return{kind:n.kind,id:n.id,filePath:n.filePath,diffType:n.diffType,diff:n.diff,linesAdded:n.linesAdded,linesRemoved:n.linesRemoved,via:n.via,unavailable:n.unavailable,netNoChange:n.netNoChange,omitted:n.omitted};case"error":case"user":case"system":return{kind:n.kind,id:n.id,text:n.text};default:return{kind:n.kind,id:n.id}}})}function fi(t,n){const u=new Map((t.actions||[]).filter(d=>d==null?void 0:d.id).map(d=>[d.id,d]));return(t.fullTimeline||[]).map(d=>{if(d.kind==="recorded-action"){const l=u.get(d.id);return Vt({...d,screenshot:d.screenshot||(l==null?void 0:l.screenshot),elementRect:d.elementRect||(l==null?void 0:l.elementRect),screenshotCrop:d.screenshot?d.screenshotCrop:l==null?void 0:l.screenshotCrop},n)}return d.kind==="text"?{kind:"text",id:d.id||n(),text:d.text||"",done:!0}:d.kind==="tool"?{kind:"tool",id:d.id||n(),toolId:d.toolId||`${d.toolName}::${d.args||""}`,phase:d.phase||"complete",toolName:d.toolName||"",args:d.args||"",result:d.result,error:d.error,startedAt:d.startedAt,endedAt:d.endedAt}:d.kind==="file-diff"?{kind:"file-diff",id:d.id||n(),filePath:d.filePath||"",diffType:d.diffType||"modified",diff:d.diff||"",linesAdded:d.linesAdded||0,linesRemoved:d.linesRemoved||0,via:d.via,unavailable:d.unavailable,netNoChange:d.netNoChange,omitted:d.omitted}:d.kind==="error"?{kind:"error",id:d.id||n(),text:d.text||""}:d.kind==="user"?{kind:"user",id:d.id||n(),text:d.text||""}:{kind:"system",id:d.id||n(),text:d.text||""}})}const hi=[/test result:\s*fail/i,/all\s+\d+\s+attempts\s+(exhausted|failed)/i,/attempts\s+exhausted/i,/could not.*(?:fix|make).*(?:pass|work)/i,/reached maximum tool iterations/i];function gi(t,n){if(n==="failed"||n==="stopped")return n;let u=0;for(let d=t.length-1;d>=0;d--)if(t[d].kind==="user"){u=d+1;break}for(const d of t.slice(u))if(d.kind==="error"||d.kind==="text"&&d.text&&hi.some(l=>l.test(d.text)))return"failed";return"success"}function bi(t,n,u){return!t||t.src!==n?!1:Math.abs(t.w-u.clipW)<=2&&Math.abs(t.h-u.clipH)<=2}function An(t,n){return new Promise(u=>{const d=new Image;d.onload=()=>{try{const l=document.createElement("canvas");l.width=n.clipW,l.height=n.clipH;const N=l.getContext("2d");if(!N){u(t);return}const p=d.naturalWidth/n.vpW,A=d.naturalHeight/n.vpH;N.drawImage(d,n.clipX*p,n.clipY*A,n.clipW*p,n.clipH*A,0,0,n.clipW,n.clipH),u(l.toDataURL("image/jpeg",.8))}catch{u(t)}},d.onerror=()=>u(t),d.src=t})}const yi=/\.(spec|test|e2e|cy)\.(ts|js|tsx|jsx|mjs|cjs)$|(^|[\\/])test_[^\\/]+\.py$|_test\.py$|\.(feature|robot)$|(Test|Tests|IT|Spec)\.(java|kt|rb|cs)$/;function En({onInsert:t,label:n}){return e.jsx("div",{className:"group/ins relative h-2 flex items-center",children:e.jsxs("button",{type:"button",onClick:t,"aria-label":n,title:n,className:"absolute left-10 right-3 -top-1 h-4 flex items-center opacity-0 group-hover/ins:opacity-100 focus-visible:opacity-100 transition-opacity focus:outline-none",children:[e.jsx("span",{className:"flex-1 h-px bg-indigo-500/50"}),e.jsxs("span",{className:"mx-1 inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full bg-indigo-500/15 text-[10px] font-medium text-indigo-700 dark:text-indigo-300",children:[e.jsx(tr,{size:10})," Custom step"]}),e.jsx("span",{className:"flex-1 h-px bg-indigo-500/50"})]})})}let _t=null;const vi=2e4,wi=/^(recorder-|ai-fix-|browser-(closed|launched)$)/;function ji(t,n){na();const u={clientId:wr(),state:t,buffer:[],overflow:!1,stop:null,replayed:!1};try{u.stop=n(d=>{if(wi.test(String((d==null?void 0:d.type)||""))){if(u.buffer.length>=vi){u.overflow=!0;return}u.buffer.push(d)}})}catch{}_t=u}function Ni(){const t=_t;if(!t)return null;const n=wr();return t.clientId&&n&&t.clientId!==n?null:t}function na(){var t;try{(t=_t==null?void 0:_t.stop)==null||t.call(_t)}catch{}_t=null}function ki(){var pr;const{subscribe:t,send:n}=Mn(),{toast:u}=Qr(),[d]=s.useState(Ni),l=d==null?void 0:d.state,{data:N}=Yn(),[p,A]=s.useState((l==null?void 0:l.phase)??"setup"),I=s.useRef(p);I.current=p;const[E,C]=s.useState((l==null?void 0:l.timeline)??[]),k=s.useRef(E);k.current=E;const T=s.useMemo(()=>new Map(E.map((r,a)=>[r.id,a])),[E]),[S,L]=s.useState((l==null?void 0:l.startUrl)??""),H=(()=>{const r=S.trim();if(!/^https?:\/\//i.test(r))return!1;try{return!!new URL(r).hostname}catch{return!1}})(),[D,V]=s.useState((l==null?void 0:l.testName)??""),[U,oe]=s.useState((l==null?void 0:l.mergeMode)??!1),[P,Y]=s.useState((l==null?void 0:l.targetTestFile)??""),[g,Z]=s.useState((l==null?void 0:l.targetTestName)??""),[B,ee]=s.useState((l==null?void 0:l.insertPosition)??"auto"),[J,ie]=s.useState(!1),[se,ue]=s.useState(""),[y,R]=s.useState(new Set),[v,W]=s.useState((l==null?void 0:l.userGuidance)??""),[re,$e]=s.useState((l==null?void 0:l.followUpPrompt)??""),[$,m]=s.useState((l==null?void 0:l.awaitingConfirmation)??!1),[X,w]=s.useState((l==null?void 0:l.genOutcome)??null),[pe,Ie]=s.useState(!1),[Xt,sn]=s.useState(""),cs=s.useRef(null),[he,bt]=s.useState([]),[ds,Rt]=s.useState(!1);s.useEffect(()=>{if(!P||!g){bt([]);return}if(N!=null&&N.suites){const r=N.suites.find(a=>a.file===P||a.file.replace(/\\/g,"/")===P.replace(/\\/g,"/"));if(r){const a=r.tests.find(x=>x.name===g);if(a!=null&&a.steps&&a.steps.length>0){bt(a.steps.map(x=>({keyword:x.keyword,name:x.name})));return}}}Rt(!0),_a(async()=>{const{getTestSourceByName:r}=await import("./index-BYVxKLrT.js").then(a=>a.iF);return{getTestSourceByName:r}},__vite__mapDeps([0,1,2,3,4])).then(({getTestSourceByName:r})=>{r(P,g).then(a=>{a!=null&&a.humanSteps&&a.humanSteps.length>0?bt(a.humanSteps.map(x=>({keyword:x.keyword,name:x.name}))):bt([])}).catch(()=>bt([])).finally(()=>Rt(!1))})},[P,g,N]);const[fe,$t]=s.useState((l==null?void 0:l.elapsedTime)??0),[Ge,Pe]=s.useState((l==null?void 0:l.actionCount)??0),[ge,_e]=s.useState((l==null?void 0:l.isPaused)??!1),Se=s.useRef((l==null?void 0:l.startTime)??0),He=s.useRef((l==null?void 0:l.pausedAt)??0),[We,yt]=s.useState((l==null?void 0:l.canAddSteps)??!0),Ce=s.useRef((l==null?void 0:l.executed)??!1),Jt=s.useRef((l==null?void 0:l.lastSavedRun)??null),[Ve,Zt]=s.useState((l==null?void 0:l.testSettings)??null),[ot,Ae]=s.useState(null),[vt,Kt]=s.useState(new Set),Is=s.useRef(new Map),us=s.useRef(`draft-${wr()||`local-${Math.random().toString(36).slice(2,10)}`}`),wt=()=>{const r=wr();return r&&!us.current.startsWith(`draft-${r}`)&&(us.current=`draft-${r}`),us.current},[es,ts]=s.useState(!1),Tt=Fn(),[it,lt]=s.useState(Tt.mode==="mobile"?"mobile":"web");s.useEffect(()=>{Tt.isLoading||(Tt.mode==="mobile"&&it!=="mobile"?lt("mobile"):Tt.mode==="web"&&it!=="web"&&lt("web"))},[Tt.mode,Tt.isLoading]);const[At,ct]=s.useState((l==null?void 0:l.activeSessionId)??null),[Ke,Bt]=s.useState(null),[sr,Ps]=s.useState(null),[xe,Be]=s.useState(null),Ar=s.useRef(null),xs=sa(Ar,640),[De,Ut]=s.useState(null),Ds=s.useRef(null),[Ye,Qe]=s.useState(null),[ss,Xe]=s.useState(null),[Et,Fs]=s.useState("below"),[rs,rr]=s.useState(null),ps=s.useRef(0),[nr,Mt]=s.useState(!1),[Je,Ls]=s.useState(!1),[ns,jt]=s.useState(null),[_s,Hs]=s.useState(!1),[Te,Ue]=s.useState((l==null?void 0:l.genLoading)??!1),[Ze,et]=s.useState((l==null?void 0:l.playbackLoading)??!1),{providerModels:ae,selectedProvider:tt,selectedModel:ye,select:ce}=Xn(l?{provider:l.selectedProvider,model:l.selectedModel}:void 0),le=s.useRef((l==null?void 0:l.streamText)??""),Ee=s.useRef((l==null?void 0:l.streamTextId)??null),dt=s.useRef((l==null?void 0:l.loadedFromHistory)??!1),zt=s.useRef((l==null?void 0:l.currentRequestId)??null),Nt=r=>{zt.current=r},[st,as]=s.useState((l==null?void 0:l.pendingPermission)??null),Ot=s.useRef((l==null?void 0:l.permissionQueue)??[]),ut=()=>{as(null),Ot.current=[]},[ar]=s.useState(1),[xt,Oe]=s.useState((l==null?void 0:l.playbackIndex)??-1),[It,rt]=s.useState((l==null?void 0:l.playbackTotal)??0),[we,je]=s.useState((l==null?void 0:l.assertActive)??!1),[Ne,Me]=s.useState((l==null?void 0:l.annotateActive)??!1),ze=s.useRef(null),Fe=s.useRef(!0),kt=s.useRef(0),te=()=>`rec-${Date.now().toString(36)}-${++kt.current}`,os=s.useRef({});os.current={phase:p,timeline:E,startUrl:S,testName:D,mergeMode:U,targetTestFile:P,targetTestName:g,insertPosition:B,userGuidance:v,followUpPrompt:re,awaitingConfirmation:$,genOutcome:X,elapsedTime:fe,actionCount:Ge,isPaused:ge,activeSessionId:At,genLoading:Te,pendingPermission:st,assertActive:we,annotateActive:Ne,canAddSteps:We,selectedProvider:tt,selectedModel:ye,playbackLoading:Ze,playbackIndex:xt,playbackTotal:It,testSettings:Ve};const ms=s.useRef(t);ms.current=t,s.useEffect(()=>()=>{ji({...os.current,currentRequestId:zt.current,permissionQueue:Ot.current,streamText:le.current,streamTextId:Ee.current,loadedFromHistory:dt.current,executed:Ce.current,lastSavedRun:Jt.current,startTime:Se.current,pausedAt:He.current},ms.current)},[]),s.useEffect(()=>{const r=ze.current;r&&Fe.current&&(r.scrollTop=r.scrollHeight)},[E]);const fs=()=>{const r=ze.current;r&&(Fe.current=r.scrollHeight-r.scrollTop-r.clientHeight<120)};s.useEffect(()=>{st&&ze.current&&(Fe.current=!0,requestAnimationFrame(()=>{ze.current&&(ze.current.scrollTop=ze.current.scrollHeight)}))},[st]),s.useEffect(()=>{var a;if(!xe)return;(a=Ds.current)==null||a.focus();const r=x=>{x.key==="Escape"&&Be(null)};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[xe]),s.useEffect(()=>{Ha().then(r=>Mt(r.active)).catch(()=>Mt(!1))},[p]);const hs=async r=>{let a=[];try{a=(await Ua()).actions||[]}catch{}const x=a.map(f=>Vt(f,te));C([{kind:"system",id:te(),text:r.recording?"Recording in progress — picked up where you left off":"Recording restored"},...x]),Pe(r.actionCount??x.length),$t(Math.floor((r.duration||0)/1e3)),r.startUrl&&L(r.startUrl),Zt(r.settings||null),r.sessionId&&ct(r.sessionId),r.recording?(Se.current=Date.now()-(r.duration||0),He.current=r.paused?Date.now():0,_e(!!r.paused),A("recording")):(yt(r.canAddSteps!==!1),A("stopped"))};s.useEffect(()=>{if(d&&d.state.phase!=="setup")return;let r=!0;return(async()=>{var a;await Dn().catch(()=>null);try{const x=await Ka();r&&(x.recording||x.hasSession)&&await hs(x)}catch{}if(!(!r||I.current!=="setup"))for(const x of[wt(),...Ba().map(f=>`draft-${f}`),"draft-current"])try{const f=await zn(x);if(f&&((a=f.actions)==null?void 0:a.length)>0){r&&Bt(f);break}}catch{}})(),()=>{r=!1}},[]),s.useEffect(()=>{if(p!=="recording")return;if(Se.current||(Se.current=Date.now()),ge){He.current||(He.current=Date.now());return}He.current&&(Se.current+=Date.now()-He.current,He.current=0);const r=()=>$t(Math.floor((Date.now()-Se.current)/1e3));r();const a=setInterval(r,1e3);return()=>clearInterval(a)},[p,ge]);const or=s.useRef(fe);or.current=fe;const ir=s.useRef(S);ir.current=S,s.useEffect(()=>{if(p!=="recording")return;const r=setInterval(()=>{var M;const a=Tn(k.current);if(a.length===0)return;const x=((M=a.find(c=>c.type==="navigate"))==null?void 0:M.url)||ir.current||"";let f="recording";try{x&&(f=new URL(x).hostname)}catch{}pn({id:wt(),name:`Draft — ${f}`,url:x,status:"draft",actions:a,duration:or.current*1e3}).catch(()=>{})},1e4);return()=>clearInterval(r)},[p]),s.useEffect(()=>{var K,ne;if(p!=="done"||$)return;const r=gi(E,X);if(r!==X&&w(r),dt.current){dt.current=!1;return}if(!Ce.current)return;const a=Tn(E);if(a.length===0)return;const x=`${At}:${E.length}:${(K=E[E.length-1])==null?void 0:K.id}`;if(Jt.current===x)return;Jt.current=x;const f=((ne=a.find(Q=>Q.type==="navigate"))==null?void 0:ne.url)||S||"",M=At||`session-${Date.now()}`;let c="test";try{f&&(c=new URL(f).hostname)}catch{c="unknown"}const z=(U&&g?g:"")||D||`Recording — ${c}`;pn({id:M,name:z,rename:!!(U&&g||D),url:f,status:"generated",outcome:r,actionCount:a.length,actions:a,fullTimeline:mi(E),duration:fe*1e3,settings:Ve||null}).then(()=>{At||ct(M)}).catch(()=>{})},[p,$]);const pt=s.useCallback(()=>{if(le.current&&Ee.current){const r=Ee.current,a=le.current;C(x=>{const f=x.findIndex(M=>M.id===r);if(f>=0){const M=[...x];return M[f]={kind:"text",id:r,text:a,done:!0},M}return x})}le.current="",Ee.current=null},[]),Ks=s.useRef(new Set);s.useEffect(()=>{for(const r of E){if(r.kind!=="recorded-action"||!r.screenshot||!r.screenshotCrop)continue;const a=`${r.id}:${r.screenshot.length}`;if(Ks.current.has(a))continue;Ks.current.add(a);const{id:x,screenshot:f,screenshotCrop:M}=r;An(f,M).then(c=>{Ks.current.delete(a),c!==f&&C(z=>z.map(K=>{if(K.id!==x||K.kind!=="recorded-action"||K.screenshot!==f)return K;const{screenshotCrop:ne,...Q}=K;return{...Q,screenshot:c}}))})}},[E]),s.useEffect(()=>{var x;const r=f=>{if(f.type==="recorder-action"){const c=f.action,z=c.id||te();if(typeof z=="string"&&z.endsWith("-screenshot")){const K=z.replace("-screenshot",""),ne=Q=>C(de=>de.map(Re=>Re.id===K&&Re.kind==="recorded-action"?{...Re,screenshot:Q,elementRect:c.elementRect}:Re));c.screenshotCrop&&c.screenshot?An(c.screenshot,c.screenshotCrop).then(ne):ne(c.screenshot);return}if(typeof z=="string"&&z.endsWith("-update")){C(K=>{const ne=[...K];for(let Q=ne.length-1;Q>=0;Q--){const de=ne[Q];if(de.kind==="recorded-action"&&de.actionType==="fill"){ne[Q]={...de,description:c.description||de.description,value:c.value??de.value};break}}return ne});return}C(K=>[...K,Vt({...c,id:z},te)]),Pe(K=>K+1),c.type==="annotate"&&Me(!1),c.type==="assert"&&je(!1);return}if(f.type==="recorder-annotate-mode"&&Me(!!f.active),f.type==="recorder-assert-mode"){je(!!f.active);return}if(f.type==="browser-closed"){Mt(!1),I.current==="recording"&&(C(c=>[...c,{kind:"system",id:te(),text:"Browser closed — recording stopped"}]),A("stopped"),je(!1),Me(!1)),yt(!1);return}if(f.type==="browser-launched"){Mt(!0);return}if(f.type==="recorder-status"){if(f.status==="recording")A("recording"),_e(!1),Se.current||(Se.current=Date.now());else if(f.status==="paused")_e(!0);else if(f.status==="stopped"){A("stopped"),_e(!1);const c=f;c.sessionId&&ct(c.sessionId),typeof c.actionCount=="number"&&Pe(c.actionCount)}else f.status==="reset"&&(A("setup"),C([]),Pe(0),$t(0),ut(),m(!1),w(null),ct(null));return}if(f.type==="recorder-playback"){const c=f;c.status==="started"?(A("playback"),Oe(0),rt(c.totalActions||0),C(z=>[...z,{kind:"system",id:te(),text:`Playback started — replaying ${c.totalActions} action(s)...`}])):c.status==="action"?(Oe(c.index+1),C(z=>[...z,{kind:"playback-action",id:te(),actionType:c.actionType||"action",description:c.description||`Action ${c.index+1}`,status:"done"}])):c.status==="action-error"?C(z=>[...z,{kind:"playback-action",id:te(),actionType:c.actionType||"action",description:c.description||`Action ${c.index+1}`,status:"error"}]):c.status==="done"?(A("stopped"),et(!1),C(z=>[...z,{kind:"system",id:te(),text:`Playback complete — ${c.replayed||0} of ${c.total||0} actions replayed${c.errors?` (${c.errors} errors)`:""}`}])):c.status==="error"&&(A("stopped"),et(!1),C(z=>[...z,{kind:"error",id:te(),text:`Playback failed: ${c.error||"Unknown error"}`}]));return}const M=f.requestId;if(!(!M||M!==zt.current))if(f.type==="ai-fix-stream"){const c=f.content;if(Ee.current){le.current+=c;const z=Ee.current,K=le.current;C(ne=>{const Q=ne.findIndex(de=>de.id===z);if(Q>=0){const de=[...ne];return de[Q]={kind:"text",id:z,text:K},de}return ne})}else{const z=te();Ee.current=z,le.current=c,C(K=>[...K,{kind:"text",id:z,text:c}])}}else if(f.type==="ai-fix-tool"){const c=f,z=`${c.toolName}::${c.args||""}`;c.phase==="start"?(pt(),C(K=>[...K,{kind:"tool",id:te(),toolId:z,phase:"start",toolName:c.toolName,args:c.args||"",startedAt:Date.now()}])):C(K=>{const ne=[...K].reverse().findIndex(Q=>Q.kind==="tool"&&Q.toolId===z&&Q.phase==="start");if(ne>=0){const Q=K.length-1-ne,de=[...K];return de[Q]={...de[Q],phase:c.phase,result:c.result,error:c.error,endedAt:Date.now()},de}return[...K,{kind:"tool",id:te(),toolId:z,phase:c.phase,toolName:c.toolName,args:c.args||"",result:c.result,error:c.error}]})}else if(f.type==="ai-fix-file-diff"){const c=f;pt(),C(z=>[...z,{kind:"file-diff",id:te(),filePath:c.filePath,diffType:c.diffType,diff:c.diff,linesAdded:c.linesAdded,linesRemoved:c.linesRemoved,via:c.via==="detected"?"detected":void 0,unavailable:c.unavailable,netNoChange:c.netNoChange===!0||void 0}])}else if(f.type==="ai-fix-file-changes-omitted"){const c=f;C(z=>[...z,{kind:"file-diff",id:te(),filePath:"",diffType:"modified",diff:"",via:"detected",omitted:{count:Number(c.count)||0,examples:Array.isArray(c.examples)?c.examples:[]}}])}else if(f.type==="ai-fix-permission"){const c=f,z={permissionId:c.permissionId,toolName:c.toolName,args:c.args||"",fullPath:c.fullPath||void 0};pt(),as(K=>K?(Ot.current.push(z),K):z)}else f.type==="ai-fix-done"?(pt(),ut(),A("done"),Ue(!1)):f.type==="ai-fix-error"&&(pt(),C(c=>[...c,{kind:"error",id:te(),text:f.message||"Unknown error"}]),ut(),m(!1),A("done"),Ue(!1),w("failed"))},a=t(r);if(d&&!d.replayed){d.replayed=!0;try{(x=d.stop)==null||x.call(d)}catch{}d.stop=null;for(const f of d.buffer.splice(0))try{r(f)}catch{}d.overflow&&C(f=>[...f,{kind:"system",id:te(),text:"Some live updates were missed while this screen was closed."}])}return _t&&na(),a},[t,pt]);const Bs=async()=>{if(!H||Je)return;Ls(!0),jt(null);const r=te();C([{kind:"system",id:r,text:S?`Recording started — navigating to ${S}`:"Recording started — interact with the browser"}]),Pe(0);try{await Qa({url:S.trim(),browser:"chromium",headless:!1}),A("recording"),_e(!1),$t(0),Se.current=Date.now(),He.current=0,Fe.current=!0,yt(!0),w(null),m(!1),Zt(null),Kt(new Set),Ce.current=!1,ct(null),dt.current=!1}catch(a){C([]);const x=String((a==null?void 0:a.message)||a).replace(/^Error:\s*/,"");jt(x),u("error",`Couldn't start recording: ${x}`)}finally{Ls(!1)}},gs=async()=>{Hs(!0);try{const r=await Ga();if(C(a=>[...a,{kind:"system",id:te(),text:`Recording stopped — ${r.actionCount} action(s) captured in ${(r.duration/1e3).toFixed(1)}s`}]),A("stopped"),_e(!1),je(!1),Me(!1),yt(!0),Bt(null),Or(wt()).catch(()=>{}),r.sessionId&&ct(r.sessionId),!D&&r.actions.length>0){const a=r.actions.find(x=>x.type==="navigate");if(a!=null&&a.url)try{const x=new URL(a.url).hostname.replace(/\./g,"-");V(`${x}-test`)}catch{}}}catch(r){C(a=>[...a,{kind:"error",id:te(),text:`Failed to stop recording: ${r}`}])}finally{Hs(!1)}},ke=async()=>{try{await qa(),_e(!0),C(r=>[...r,{kind:"system",id:te(),text:"⏸ Recording paused — interact freely without recording"}])}catch(r){u("error",`Couldn't pause the recording: ${r}`)}},Pt=async()=>{try{await Oa(),_e(!1),C(r=>[...r,{kind:"system",id:te(),text:"▶ Recording resumed"}])}catch(r){u("error",`Couldn't resume the recording: ${r}`)}},bs=async()=>{try{const r=await Wa();r!=null&&r.success&&(Se.current=Date.now()-fe*1e3,He.current=0,A("recording"),_e(!1),C(a=>[...a,{kind:"system",id:te(),text:"➕ Adding more steps to the recording"}]))}catch(r){C(a=>[...a,{kind:"system",id:te(),text:`Failed to resume recording: ${r}`}])}},ys=async r=>{var M;if(I.current==="recording"||I.current==="generating"||I.current==="playback"){u("info",I.current==="generating"?"Wait for the generation to finish (or stop it) before opening another recording.":"Stop the current recording before opening another one.");return}let a=!1,x=r.settings||null;try{const c=await Ya(r.id);a=!!c.canAddSteps,c.settings!==void 0&&(x=c.settings||null)}catch(c){u("error",`Couldn't open the recording: ${c}`);return}if(dt.current=!0,Ce.current=!1,Jt.current=null,ct(r.id||null),ts(!1),yt(a),Zt(x),Kt(new Set),Pe(r.actionCount||((M=r.actions)==null?void 0:M.length)||0),$t(Math.round((r.duration||0)/1e3)),r.name&&V(r.name),w(r.outcome||null),m(!1),ut(),Nt(null),Fe.current=!0,r.fullTimeline&&r.fullTimeline.length>0){A(r.status==="completed"||r.status==="generated"?"done":"stopped"),C(fi(r,te));return}A("stopped");const f=r.actions||[];C([{kind:"system",id:te(),text:`Loaded recording: ${r.name} (${f.length} actions)`},...f.map(c=>Vt(c,te))])},Us=async()=>{if(Te)return;Ue(!0),ut(),le.current="",Ee.current=null,w(null),dt.current=!1,Ce.current=!1,Fe.current=!0;const r=`recorder-${Date.now()}`;Nt(r),A("generating"),m(!0),C(a=>[...a,{kind:"system",id:te(),text:U?`Analyzing project to merge recorded actions into — ${P}...`:"Analyzing your project patterns and recorded actions..."}]);try{await so({requestId:r,testName:D||"recorded test",model:ye||void 0,provider:tt||void 0,mergeMode:U||void 0,targetTestFile:U?P:void 0,insertPosition:U?B:void 0,userGuidance:U&&v.trim()?v.trim():void 0,sessionId:At||void 0,analyzeOnly:!0,settings:Ve})}catch(a){C(x=>[...x,{kind:"error",id:te(),text:`Failed to start code generation: ${a}`}]),Ue(!1),m(!1),Nt(null),A("stopped")}},Os=async()=>{const r=zt.current;r&&(pt(),Nt(null),ut(),m(!1),A("done"),Ue(!1),w("stopped"),C(a=>[...a,{kind:"system",id:te(),text:"Generation stopped by user"}]),no({requestId:r}).catch(()=>{}))},qs=async()=>{var Re;if(Te)return;const r=re.trim();if(!r&&!$)return;const a=$,x=!r||/^(proceed|ok|yes|go|continue|looks good|lgtm|sure|do it|go ahead)$/i.test(r),f=a&&x?'The user approved the analysis. Proceed with the implementation now — write the code, run the test, fix any failures, and provide a summary. Start with a brief acknowledgment like "Great, let me implement this now." before writing code.':a&&r?`The user reviewed your analysis and has this feedback:
25
25
 
26
26
  "${r}"
27
27