@testver/testver 1.4.1 → 1.4.3

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 (102) hide show
  1. package/README.md +3 -1
  2. package/bin/testver.js +1 -1
  3. package/dist/index.js +1943 -1190
  4. package/package.json +2 -1
  5. package/src/ui/static/assets/AIPanel-KQFq4c0Q.js +32 -0
  6. package/src/ui/static/assets/AIRecordPanel-CAs8fXyS.js +40 -0
  7. package/src/ui/static/assets/AIStreamUI-p_sMTEDQ.js +9 -0
  8. package/src/ui/static/assets/{AITestGenPage-Cg21-P1W.js → AITestGenPage-CHaHfmu4.js} +5 -5
  9. package/src/ui/static/assets/APITestingPage-BSGJY_hd.js +19 -0
  10. package/src/ui/static/assets/{AboutPage-yJLCr2_q.js → AboutPage-CDa24SCJ.js} +1 -1
  11. package/src/ui/static/assets/AdvancedPage-BqXP0FLg.js +3 -0
  12. package/src/ui/static/assets/{AnalyticsPage-gTPFsiLZ.js → AnalyticsPage-Lm8noJqC.js} +1 -1
  13. package/src/ui/static/assets/{AuditLogPage-DE45E_PV.js → AuditLogPage-BvldSIik.js} +1 -1
  14. package/src/ui/static/assets/ChangesSummary-Cu0_4Ucf.js +3 -0
  15. package/src/ui/static/assets/{CodeMapPage-DgU6ZYBO.js → CodeMapPage-uEjuo3fk.js} +3 -3
  16. package/src/ui/static/assets/{ConfirmDialog-DNU3qoAP.js → ConfirmDialog-DtotgVmI.js} +1 -1
  17. package/src/ui/static/assets/{CoveragePage-BpTjgcdV.js → CoveragePage-jNkQJA1P.js} +2 -2
  18. package/src/ui/static/assets/{CronBuilder-DsnX-vRr.js → CronBuilder-D2fERHt9.js} +1 -1
  19. package/src/ui/static/assets/Dashboard-BaIj_IdQ.js +1 -0
  20. package/src/ui/static/assets/{DefectsPage-BtMNbq6Z.js → DefectsPage-DH0njYFG.js} +3 -3
  21. package/src/ui/static/assets/{EmptyState-BH_aDO0P.js → EmptyState-utxlJ0fu.js} +1 -1
  22. package/src/ui/static/assets/{ExportButton-Ce_MxnM1.js → ExportButton-ouKqn9CU.js} +1 -1
  23. package/src/ui/static/assets/{FileViewer-iYL0lxyY.js → FileViewer-mU3JloJ6.js} +5 -5
  24. package/src/ui/static/assets/{GitPage-CQqV8JBC.js → GitPage-TrX-RqNC.js} +5 -5
  25. package/src/ui/static/assets/{ImportExportPage-DXk7Koaq.js → ImportExportPage-CIhK_raX.js} +1 -1
  26. package/src/ui/static/assets/{JiraPushDialog-CqftoLh8.js → JiraPushDialog-DgEZS-0u.js} +1 -1
  27. package/src/ui/static/assets/KpiTile-BHLE3HVj.js +1 -0
  28. package/src/ui/static/assets/{LiveExecutionView-BD0wE8sz.js → LiveExecutionView-CaIf7Jux.js} +1 -1
  29. package/src/ui/static/assets/{ManagePage-B8iG6Q0B.js → ManagePage-SvRQ6L19.js} +1 -1
  30. package/src/ui/static/assets/{MediaModal-DiSINwmh.js → MediaModal-DNM45Uz2.js} +1 -1
  31. package/src/ui/static/assets/{MobileRunPicker-BNs2lZFf.js → MobileRunPicker-DFKm6_nU.js} +1 -1
  32. package/src/ui/static/assets/{MobileRunTarget-D2Nqcj10.js → MobileRunTarget-DHDoDZ_F.js} +3 -3
  33. package/src/ui/static/assets/{ModuleExplorer-BmkoQrHb.js → ModuleExplorer-rni7JbsL.js} +1 -1
  34. package/src/ui/static/assets/{OutputPage-Dcsr7cmr.js → OutputPage-Cn2WCpJ6.js} +1 -1
  35. package/src/ui/static/assets/PipelinesPanel-D6zWcLtD.js +1 -0
  36. package/src/ui/static/assets/{ProfilePage-ByshrcwC.js → ProfilePage-BKNdkSnx.js} +1 -1
  37. package/src/ui/static/assets/{ProjectExplorer-B9B___ij.js → ProjectExplorer-5e7J8t-o.js} +1 -1
  38. package/src/ui/static/assets/{RemoteFileStrip-DbPnaZ-v.js → RemoteFileStrip-C1S2aclP.js} +1 -1
  39. package/src/ui/static/assets/ReportCard-D4EElEe9.js +2 -0
  40. package/src/ui/static/assets/ReportFullView-2w2ysKRg.js +1 -0
  41. package/src/ui/static/assets/ReportsPage-9Fx-IEwV.js +48 -0
  42. package/src/ui/static/assets/ResultsPage-DPkfGh-K.js +115 -0
  43. package/src/ui/static/assets/RunState-CRuS_bC2.js +1 -0
  44. package/src/ui/static/assets/{RunTargets-C7Vqd4TU.js → RunTargets-CPKBrefj.js} +1 -1
  45. package/src/ui/static/assets/{ScriptMappingPage-BrANeHv0.js → ScriptMappingPage-C3K_uyf0.js} +1 -1
  46. package/src/ui/static/assets/{SearchableDevicePicker-CFJ_DUAA.js → SearchableDevicePicker-DubIldKj.js} +1 -1
  47. package/src/ui/static/assets/{SettingsPage-BwOiebKG.js → SettingsPage-BuZrrlW2.js} +1 -1
  48. package/src/ui/static/assets/SharedReportView-ig5hECRk.js +1 -0
  49. package/src/ui/static/assets/{SourcesPage-C_QVQwiA.js → SourcesPage-BPkqRqkC.js} +1 -1
  50. package/src/ui/static/assets/TestExplorerPage-C_jl93GR.js +7 -0
  51. package/src/ui/static/assets/{TestManagementPage-Ch4PthuU.js → TestManagementPage-DJiWpCne.js} +1 -1
  52. package/src/ui/static/assets/TestPlansPage-G1lvK1C0.js +5 -0
  53. package/src/ui/static/assets/{TestverCreditsDetail-cSW0SpNx.js → TestverCreditsDetail-BKpt4oLW.js} +1 -1
  54. package/src/ui/static/assets/{TestverCreditsRing-CUsMGEe3.js → TestverCreditsRing-CEBSy3w3.js} +1 -1
  55. package/src/ui/static/assets/{UncommittedDiffViewer-B5HSURk8.js → UncommittedDiffViewer-FKvUZcRi.js} +2 -2
  56. package/src/ui/static/assets/{UserManagementPage-BjY3ftxf.js → UserManagementPage-gDGhaHE4.js} +3 -3
  57. package/src/ui/static/assets/{WorkflowsPage-BUu-LjZ8.js → WorkflowsPage-BACdnU-1.js} +17 -17
  58. package/src/ui/static/assets/{hiddenLlmProviders-setxgY_B.js → hiddenLlmProviders-DzwaR-b9.js} +1 -1
  59. package/src/ui/static/assets/index-D6sQYc_0.js +47 -0
  60. package/src/ui/static/assets/{index-DpQhqcHv.js → index-DLmlY2Ol.js} +1 -1
  61. package/src/ui/static/assets/index-aInN0yoR.css +1 -0
  62. package/src/ui/static/assets/reportMeta-3kxT7BIT.js +1 -0
  63. package/src/ui/static/assets/{useChartTheme-BFz2QcND.js → useChartTheme-CTIe6M63.js} +1 -1
  64. package/src/ui/static/assets/{useDebouncedValue-BsHptIvX.js → useDebouncedValue-C9odz7b2.js} +1 -1
  65. package/src/ui/static/assets/{useFeatureFlags-DqhngqgG.js → useFeatureFlags-DrhvBp0C.js} +1 -1
  66. package/src/ui/static/assets/{useJiraConnector-TM1Rfj1s.js → useJiraConnector-Dwj69Rfh.js} +1 -1
  67. package/src/ui/static/assets/useOwnership-C1CmzcvJ.js +1 -0
  68. package/src/ui/static/assets/useSuites-V0AxZYex.js +1 -0
  69. package/src/ui/static/assets/{useTabParam-ChbOedP1.js → useTabParam-CyYAP90W.js} +1 -1
  70. package/src/ui/static/assets/{useTestExplorer-HqvURJAc.js → useTestExplorer-CUqC18DV.js} +1 -1
  71. package/src/ui/static/assets/{useTestLifecycle-CL7-zz0Q.js → useTestLifecycle-C2S_vaX2.js} +1 -1
  72. package/src/ui/static/assets/{useTestManagement-ZTA1_VUm.js → useTestManagement-DW6AW2mt.js} +2 -2
  73. package/src/ui/static/assets/useTestResults-yjH1aUy-.js +1 -0
  74. package/src/ui/static/assets/{vendor-charts-DWFQlmCz.js → vendor-charts-By5uZ93z.js} +1 -1
  75. package/src/ui/static/assets/{vendor-flow-YGpC9U9I.js → vendor-flow-B61ZV-pm.js} +1 -1
  76. package/src/ui/static/assets/{vendor-icons-B0wLOBoh.js → vendor-icons-D_Dmmj8d.js} +277 -282
  77. package/src/ui/static/assets/vendor-query-DkZSMtfn.js +1 -0
  78. package/src/ui/static/assets/{vendor-quill-W-RoQfb6.js → vendor-quill-xJF2Jvjc.js} +1 -1
  79. package/src/ui/static/assets/{vendor-react-CTbHBddL.js → vendor-react-DOVfxdUy.js} +1 -1
  80. package/src/ui/static/index.html +5 -5
  81. package/src/ui/static/assets/AIPanel-D09Ni3a4.js +0 -32
  82. package/src/ui/static/assets/AIRecordPanel-DZtUZnRe.js +0 -40
  83. package/src/ui/static/assets/AIStreamUI-BsxKziYG.js +0 -9
  84. package/src/ui/static/assets/APITestingPage-Cdc8EZz2.js +0 -19
  85. package/src/ui/static/assets/AdvancedPage-DB-6sJ6s.js +0 -3
  86. package/src/ui/static/assets/ChangesSummary-C-7oi_sx.js +0 -2
  87. package/src/ui/static/assets/Dashboard-DRWbVyTb.js +0 -1
  88. package/src/ui/static/assets/DiffViewer-DPglzjPH.js +0 -2
  89. package/src/ui/static/assets/PipelinesPanel-CMMXCSda.js +0 -1
  90. package/src/ui/static/assets/ReportCard-BbNfk85h.js +0 -2
  91. package/src/ui/static/assets/ReportFullView-Cg1rggho.js +0 -1
  92. package/src/ui/static/assets/ReportsPage-CFv3OAhe.js +0 -48
  93. package/src/ui/static/assets/ResultsPage-B4LwZH-R.js +0 -115
  94. package/src/ui/static/assets/SharedReportView-BAbW1WOs.js +0 -1
  95. package/src/ui/static/assets/TestExplorerPage-BRRWtwde.js +0 -7
  96. package/src/ui/static/assets/TestPlansPage-Bno2vpGd.js +0 -5
  97. package/src/ui/static/assets/index-B0klHYbO.css +0 -1
  98. package/src/ui/static/assets/index-DtBWNlVD.js +0 -47
  99. package/src/ui/static/assets/useOwnership-eW6Egd7X.js +0 -1
  100. package/src/ui/static/assets/useSuites-CvtMGakZ.js +0 -1
  101. package/src/ui/static/assets/useTestResults-Bm-JyMhB.js +0 -1
  102. package/src/ui/static/assets/vendor-query-BrzmPFT3.js +0 -1
@@ -1,40 +0,0 @@
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
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
- ${j.map((O,Lt)=>` ${Lt+1}. ${O}`).join(`
5
- `)}`),b.size>0&&q.push(`Files created/modified:
6
- ${[...b].map(O=>` - ${O}`).join(`
7
- `)}`),F.length>0&&q.push(`Conversation history (in order):
8
- ${F.join(`
9
-
10
- `)}`);const me=q.length>0?q.join(`
11
-
12
- `):void 0,Wt=/\.(spec|test|e2e)\.(ts|js|tsx|jsx|mjs|cjs)$|(^|[\\/])test_[^\\/]+\.py$|_test\.py$|\.feature$|(Test|Tests|IT|Spec)\.(java|kt|rb|cs)$/,Ss=xe.filter(O=>O.kind==="file-diff").map(O=>O.filePath).filter(Boolean).find(O=>Wt.test(O))||(fe&&ge?ge:void 0);try{await ja({requestId:i,prompt:o,proceedAfterAnalysis:h,previousContext:me,model:it||void 0,provider:lt||void 0,testFilePath:Ss})}catch(O){ae(O.message),le(!1),Rt(!1),Xe.current=null,h&&Ut(!0),Y("done")}},[Qe,De,B,xe,it,lt,fe,ge]),G=s.useCallback(async()=>{le(!0),Rt(!0),ae(null),ye(null),Ue(!1);const i=bs.current,o=(g==null?void 0:g.device)||"device",h=[{kind:"system",id:`sys-start-${Date.now()}`,message:`Recording started — ${o}`},...i.map((F,q)=>({kind:"recorded-action",id:`rec-${F.index}`,stepNum:q+1,actionType:F.type,description:F.description,screenshot:F.screenshot,screenshotSize:F.screenshotSize,elementRect:F.elementRect})),{kind:"system",id:`sys-stop-${Date.now()}`,message:`Recording stopped — ${i.length} action${i.length===1?"":"s"} captured`},{kind:"system",id:`system-${Date.now()}`,message:"Analyzing your project patterns and recorded actions…"}];Be(h),Ye(null),Ut(!0);const b=`mobile-recorder-${Date.now()}`;Xe.current=b,xs(b),Y("generating");const j=Ge||`recorded-${new Date().toISOString().slice(0,16).replace(/[:.]/g,"-")}`;_s(j);try{await Na({requestId:b,testName:j,model:it||void 0,provider:lt||void 0,mergeMode:fe,targetTestFile:fe?ge:void 0,targetTestName:fe&&Ae?Ae:void 0,insertPosition:fe?Se:void 0,userGuidance:fe&&Se==="auto"?We:void 0,settings:kt,analyzeOnly:!0})}catch(F){ae(F.message),Y("stopped"),le(!1),Rt(!1),Xe.current=null}},[fe,Ge,ge,Ae,Se,We,it,lt,g,kt]);s.useEffect(()=>{if(!ge||!Ae){wt([]);return}if(Ce!=null&&Ce.suites){const i=h=>h.replace(/\\/g,"/"),o=Ce.suites.find(h=>i(h.file)===i(ge));if(o){const h=o.tests.find(b=>b.name===Ae);if(h!=null&&h.steps&&h.steps.length>0){wt(h.steps.map(b=>({keyword:b.keyword,name:b.name})));return}}}ts(!0),ka(ge,Ae).then(i=>{i!=null&&i.humanSteps&&Array.isArray(i.humanSteps)&&i.humanSteps.length>0?wt(i.humanSteps.map(o=>({keyword:o.keyword,name:o.name}))):wt([])}).catch(()=>wt([])).finally(()=>ts(!1))},[ge,Ae,Ce]);const Le=s.useMemo(()=>us,[us]),Gt=ce||Fs||B.length===0||!fe&&!Ge.trim()||fe&&(!ge||!Ae)||fe&&Se==="auto"&&!We.trim(),nt=s.useCallback(async()=>{try{await un()}catch{}ee([]),te(null),Fe(new Set),ie(!1),W(0),$(0),cs(null),bt(null),ae(null),ye(null),ue(!1),R(!1),X(!1),Ue(!1),Pt(null),Y("setup");try{const i=await an();Z(i.session??null)}catch{Z(null)}window.dispatchEvent(new CustomEvent("testver-mobile-recording-changed",{detail:{recording:!1,owner:"recorder-page"}}))},[]);s.useCallback(async()=>{le(!0);try{await Sa()}catch{}Z(null),await nt(),le(!1)},[nt]);const is=async()=>{try{if(Oe!=null&&Oe.id){const o=await qr(Oe.id);if(o.recording.actions.length>0){await xn(o.recording.actions,o.recording.sessionInfo),ee(o.recording.actions),W(Date.now()-(o.recording.durationMs||0)),X(!1),It(null),rt.current=Oe.id,Y("stopped");return}}const i=await on();ee(i.actions),W(i.startedAt||Date.now()),X(!1),Y("stopped")}catch(i){ae(i.message)}},St=async()=>{try{await un()}catch{}if(Oe!=null&&Oe.id){try{await In(Oe.id)}catch{}je.invalidateQueries({queryKey:["mobile-recording-history"]})}It(null),X(!1)},Pr=async i=>{te(i.settings||null),Fe(new Set);try{await xn(i.actions,i.sessionInfo,i.settings||null)}catch(h){console.warn("[MobileRecorder] Failed to hydrate backend on load:",h)}ee(i.actions),W(Date.now()),rt.current=i.id;const o=i.status==="generated";if(o){bt({status:"loaded",specPath:i.generatedSpecPath||"(not generated)",healingPath:i.generatedHealingPath||"(not generated)",specSource:"",healingJson:"",actions:i.actions});const h=Array.isArray(i.fullTimeline)&&i.fullTimeline.length>0?i.fullTimeline:[{kind:"system",id:`sys-load-${i.id}`,message:`Loaded "${i.name}" — ${i.actions.length} recorded step${i.actions.length===1?"":"s"}. (Generated before transcript history was saved, so the AI conversation isn't available for this recording.)`}];Be(h),Ut(!1),_s(i.name||null),Ye(i.outcome==="failed"?"failed":i.outcome==="stopped"?"stopped":"success"),Ue(!0),Y("done")}else Be([]),Ue(!1),Y("stopped");ye(o?`Loaded generated "${i.name}" — read-only view (${i.actions.length} step${i.actions.length===1?"":"s"}). Click "New Recording" to start fresh.`:`Loaded "${i.name}" — ${i.actions.length} step${i.actions.length===1?"":"s"}. You can edit, reorder, delete, or generate code.`)};$e.current=()=>t==null?void 0:t(P,{actionCount:B.length,durationMs:re.current,paused:J,assertMode:se,annotateMode:y}),s.useEffect(()=>{t==null||t(P,{actionCount:B.length,durationMs:re.current,paused:J,assertMode:se,annotateMode:y})},[P,B.length,J,se,y,t]),s.useEffect(()=>{n&&n({stop:Vs,pause:lr,resume:Ws,reset:nt,generate:_,addMoreSteps:cr,toggleAssert:dr,toggleAnnotate:ur,openHistory:()=>xt(!0)})},[Vs,lr,Ws,nt,_,cr,dr,ur,n]);const js=d.find(i=>i.id===N),mr=!(js!=null&&js.hasCredentials);if(P==="setup"||P==="starting")return e.jsxs("div",{className:"relative h-full overflow-y-auto bg-white dark:bg-transparent",children:[e.jsx(Hr,{open:ar,onClose:()=>xt(!1),onLoad:Pr}),ke&&e.jsx(Kr,{screenshot:ke.screenshot,screenshotSize:ke.screenshotSize,elementRect:ke.elementRect,step:ke.step,description:ke.description,onClose:()=>Pt(null)}),e.jsxs("div",{className:"max-w-5xl mx-auto mt-8 space-y-6 px-4 pb-12",children:[m&&e.jsx("div",{className:"bg-amber-500/5 border border-amber-500/20 rounded-xl p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-amber-500/15 flex items-center justify-center flex-shrink-0",children:e.jsx(vr,{size:20,className:"text-amber-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-amber-300",children:"Unsaved Draft Found"}),e.jsx("div",{className:"text-xs text-gray-400 mt-0.5",children:"A recording from this session is still in memory."})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs("button",{onClick:is,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium bg-amber-500/20 text-amber-300 border border-amber-500/30 hover:bg-amber-500/30 transition-colors",children:[e.jsx(Ts,{size:12})," Resume Draft"]}),e.jsx("button",{onClick:St,className:"p-1.5 rounded-lg text-gray-500 hover:text-red-400 hover:bg-red-500/10",title:"Discard draft",children:e.jsx(Es,{size:14})})]})]})}),e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-red-500/10 border border-red-500/20 mx-auto",children:e.jsx(ht,{size:28,className:"text-red-400"})}),e.jsx("h2",{className:"text-xl font-semibold text-gray-200",children:"Record Mobile App Interactions"}),e.jsx("p",{className:"text-[15px] text-gray-500 max-w-5xl mx-auto leading-relaxed",children:"Pick a local or cloud device and an installed build. Testver launches an Appium session and you tap on the live screen to capture actions — from simple taps to complex multi-step scenarios. We then generate a runnable test that follows your project's framework design patterns with reusable page objects and helpers, plus a healing manifest so brittle locators self-recover."})]}),e.jsxs("div",{className:"max-w-xl mx-auto w-full space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-gray-400",children:"Provider"}),e.jsx(Rn,{value:N,onChange:i=>p(i),options:d.map(i=>({value:i.id,label:`${i.displayName}${i.hasCredentials?"":" (no credentials)"}`,disabled:!i.hasCredentials}))}),mr&&e.jsxs("p",{className:"text-[12px] text-amber-300 flex items-center gap-1",children:[e.jsx($s,{size:11}),"Add credentials in Connectors → ",(js==null?void 0:js.displayName)??"provider"," first."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-gray-400",children:"Device"}),e.jsx(Io,{devices:A,selectedId:k,onSelect:i=>T(i.id),loading:H,disabled:mr,onRefresh:()=>void Us(N),placeholder:mr?"(add creds in Connectors)":"Pick device",emptyText:N==="local-appium"?Po:void 0,variant:"runner"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-gray-400",children:"App"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Rn,{value:S,onChange:L,placeholder:E.length===0?"No apps uploaded yet":"Pick app",options:E.map(i=>({value:i.id,label:`${i.label||i.filename} · ${i.kind.toUpperCase()} · ${(i.size/1024/1024).toFixed(1)} MB`}))}),e.jsxs("button",{type:"button",onClick:()=>{var i;return(i=oe.current)==null?void 0:i.click()},disabled:ce,className:"flex items-center gap-1.5 px-3 rounded-lg border border-red-500/30 bg-red-500/10 hover:bg-red-500/20 text-red-300 text-sm disabled:opacity-40",children:[e.jsx(qn,{size:13})," Upload"]}),e.jsx("input",{ref:oe,type:"file",accept:".apk,.aab,.ipa,.zip,application/vnd.android.package-archive,application/zip,application/octet-stream",hidden:!0,onChange:i=>{var h;const o=(h=i.target.files)==null?void 0:h[0];o&&Er(o),i.target.value=""}})]}),V!==null&&e.jsx("div",{className:"h-1 bg-white/[0.04] rounded",children:e.jsx("div",{className:"h-full bg-red-400 rounded transition-[width] duration-200",style:{width:`${Math.round(V*100)}%`}})})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${g?"bg-emerald-400":"bg-gray-600"}`}),g?`Session is running on ${g.device} — recording will reuse it`:"A new mobile session will be launched for recording"]}),e.jsxs("button",{onClick:Mr,disabled:ce||P==="starting"||mr||!k||!S,className:"w-full flex items-center justify-center gap-2 px-5 py-3 rounded-lg text-[15px] font-semibold bg-red-500/20 text-red-300 border border-red-500/30 hover:bg-red-500/30 transition-colors disabled:opacity-50",children:[P==="starting"?e.jsx(ve,{size:18,className:"animate-spin"}):e.jsx(ht,{size:18,className:"fill-red-400 text-red-400"}),"Start Recording"]}),(et||tt)&&e.jsxs("div",{className:`text-[12px] flex items-start gap-1.5 ${et?"text-red-300":"text-gray-400"}`,children:[et?e.jsx($s,{size:12,className:"mt-0.5 flex-shrink-0"}):e.jsx(ft,{size:12,className:"mt-0.5 flex-shrink-0"}),e.jsx("span",{children:et||tt})]})]})]})]});if(P==="recording"||P==="stopped"||P==="generating"){const i=P==="recording"||P==="stopped";return e.jsxs("div",{className:"relative h-full flex flex-col bg-white dark:bg-transparent",children:[e.jsx(Hr,{open:ar,onClose:()=>xt(!1),onLoad:Pr}),nr&&e.jsx("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center bg-black/60 backdrop-blur-sm p-4",onClick:()=>Mt(!1),children:e.jsxs("div",{className:"w-[440px] max-w-full rounded-xl border border-white/10 bg-surface-1 text-gray-700 dark:text-gray-200 shadow-2xl shadow-black/70 overflow-hidden flex flex-col",role:"dialog","aria-label":"Play back recording",onClick:o=>o.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-white/10 bg-gradient-to-r from-brand-500/15 via-indigo-500/10 to-transparent",children:[e.jsx("div",{className:"flex items-center justify-center w-7 h-7 rounded-md bg-brand-500/20 border border-brand-500/30 flex-shrink-0",children:e.jsx(Ts,{size:13,className:"text-brand-300"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-brand-700 dark:text-brand-200 font-bold leading-none",children:"Play back recording"}),e.jsxs("div",{className:"text-[13px] font-medium text-gray-800 dark:text-gray-100 truncate mt-0.5",children:[B.length," step",B.length===1?"":"s"]})]}),e.jsx("button",{onClick:()=>Mt(!1),className:"p-1.5 rounded-md text-gray-500 hover:text-gray-200 hover:bg-white/10 transition-colors","aria-label":"Close dialog",children:e.jsx(gt,{size:14})})]}),e.jsxs("div",{className:"px-4 py-3 space-y-2 bg-surface-1",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-gray-500 font-semibold mb-0.5",children:"Start from"}),e.jsxs("button",{onClick:()=>void Dt(!0),className:"w-full flex items-start gap-3 rounded-lg border border-white/10 bg-surface-2/60 p-3 text-left hover:border-brand-400/50 hover:bg-brand-500/10 transition-colors group",children:[e.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-md bg-brand-500/15 border border-brand-500/25 flex-shrink-0",children:e.jsx(kr,{size:15,className:"text-brand-300"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium text-gray-800 dark:text-gray-100",children:"Restart app, then play"}),e.jsx("div",{className:"text-[11px] text-gray-500 leading-relaxed mt-0.5",children:"Relaunches the app to a fresh start so the replay runs from its first screen — most reliable."})]})]}),e.jsxs("button",{onClick:()=>void Dt(!1),className:"w-full flex items-start gap-3 rounded-lg border border-white/10 bg-surface-2/60 p-3 text-left hover:border-indigo-400/50 hover:bg-indigo-500/10 transition-colors group",children:[e.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-md bg-indigo-500/15 border border-indigo-500/25 flex-shrink-0",children:e.jsx(Gr,{size:15,className:"text-indigo-300"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[13px] font-medium text-gray-800 dark:text-gray-100",children:"Play from current screen"}),e.jsx("div",{className:"text-[11px] text-gray-500 leading-relaxed mt-0.5",children:"Replays from wherever the app is right now — use when you've already navigated to the start."})]})]})]}),e.jsx("div",{className:"flex items-center justify-end gap-2 px-4 py-2.5 border-t border-white/10 bg-surface-2/50",children:e.jsx("button",{onClick:()=>Mt(!1),className:"px-3 py-1.5 rounded-md text-[12px] text-gray-600 dark:text-gray-300 hover:bg-black/5 dark:hover:bg-white/5 transition-colors",children:"Cancel"})})]})}),e.jsx(Zn,{open:!!Ne,mode:(Ne==null?void 0:Ne.mode)||"add",initial:Ne==null?void 0:Ne.initial,replaceCount:ze.size,onCancel:()=>Me(null),onSave:r}),ke&&e.jsx(Kr,{screenshot:ke.screenshot,screenshotSize:ke.screenshotSize,elementRect:ke.elementRect,step:ke.step,description:ke.description,onClose:()=>Pt(null)}),P==="recording"&&e.jsx("div",{className:"px-4 py-2 text-[12px] bg-surface-1/60 border-b border-white/5 flex items-center gap-2",children:se?e.jsxs(e.Fragment,{children:[e.jsx(zs,{size:13,className:"text-green-400"}),e.jsx("span",{className:"text-green-300 font-medium",children:"Assert mode"}),e.jsx("span",{className:"text-gray-500",children:"— click an element to capture an assertion (won't tap the device)"})]}):y?e.jsxs(e.Fragment,{children:[e.jsx(Qs,{size:13,className:"text-purple-400"}),e.jsx("span",{className:"text-purple-300 font-medium",children:"Annotate mode"}),e.jsx("span",{className:"text-gray-500",children:"— type a note below to attach intent to the next step"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Gr,{size:13,className:"text-indigo-400"}),e.jsx("span",{className:"text-gray-400",children:J?"Paused — you can still use the app on the device; nothing is recorded until you resume.":"Click on the device screen to record taps. Type below to record text input."})]})}),P==="generating"&&e.jsxs("div",{className:"flex-shrink-0 px-4 py-3 border-b border-white/5 bg-surface-1 flex items-center gap-2",children:[e.jsx("button",{onClick:()=>xt(!0),className:"p-1.5 -ml-1.5 rounded-lg text-gray-500 hover:text-gray-300 hover:bg-white/5 transition-colors",title:"Recording History",children:e.jsx(Sr,{size:16})}),De&&!ce?e.jsxs(e.Fragment,{children:[e.jsx(Qt,{size:14,className:"text-amber-400"}),e.jsxs("span",{className:"text-sm font-semibold text-amber-300",children:["Waiting for your input",jt?` — ${jt}`:""]})]}):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:"Generating Code…"})]})]}),P==="generating"?e.jsx(Nn,{entries:xe,busy:ce,onOpenScreenshot:o=>Pt(o)}):e.jsxs("div",{ref:Os,onScroll:Gs,className:"flex-1 overflow-y-auto p-3 space-y-0.5",children:[B.length===0?e.jsx("div",{className:"text-center text-gray-500 text-sm mt-10",children:"No actions yet. Tap on the device on the right to capture your first step."}):B.map((o,h)=>{var b;return e.jsxs("div",{children:[P==="stopped"&&h===0&&e.jsx(Sn,{label:"Insert a custom step before step 1",onInsert:()=>Me({mode:"add",afterIndex:null})}),e.jsx(ai,{action:o,stepNum:h+1,selectable:P==="stopped"&&o.type!=="custom",selected:ze.has(o.index),anySelected:ze.size>0,onToggleSelect:()=>Fe(j=>{const F=new Set(j);return F.has(o.index)?F.delete(o.index):F.add(o.index),F}),onEditCustom:()=>Me({mode:"edit",editIndex:o.index,initial:{instruction:o.instruction||o.description,customKind:o.customKind,references:o.references,outputs:o.outputs}}),onRestore:P==="stopped"&&((b=o.replaces)!=null&&b.length)?()=>void a(o.index):void 0,valuePicker:i&&o.type==="type"&&!o.secretEnv?e.jsx(ea,{current:o.valueFrom,options:c.get(o.index)||[],onPick:j=>void x(o.index,j)}):null,playbackStatus:rr[o.index],canMutate:i,isEditing:st===o.index,editingDescription:Ot,onEditChange:ut,onStartEdit:()=>Ir(o),onSaveEdit:()=>void pr(),onCancelEdit:()=>as(null),onDelete:()=>void zr(o.index),isDragging:ir===h,isDropTarget:ms===h,dropPosition:hs,wasJustDropped:Ks===o.index,onDragStart:K(h),onDragOver:ne(h),onDragLeave:Q(h),onDrop:de(h),onDragEnd:Re,onOpenScreenshot:()=>{o.screenshot&&Pt({screenshot:o.screenshot,screenshotSize:o.screenshotSize,elementRect:o.elementRect,step:h+1,description:o.description})}}),P==="stopped"&&e.jsx(Sn,{label:`Insert a custom step after step ${h+1}`,onInsert:()=>Me({mode:"add",afterIndex:o.index})})]},o.index)}),i&&e.jsx("div",{className:"pt-2",children:e.jsxs("button",{type:"button",onClick:()=>Me({mode:"add"}),disabled:ce,className:"inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-xs font-medium border border-dashed border-indigo-500/35 text-indigo-700 dark:text-indigo-300 hover:bg-indigo-500/10 disabled:opacity-50",title:"A step that is not a tap on the device — use an existing login, read an email, test data, an API call…",children:[e.jsx(Ht,{size:12})," Add custom step"]})})]}),P==="recording"&&e.jsx("div",{className:"border-t border-white/[0.05] bg-surface-1",children:y?e.jsxs("div",{className:"px-3 py-2 flex items-center gap-2",children:[e.jsx(Tr,{size:12,className:"text-purple-400"}),e.jsx("input",{type:"text",value:zt,onChange:o=>Nt(o.target.value),onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),xr())},disabled:ce,placeholder:"Add a note — describes the intent of the next step…",className:"flex-1 bg-transparent border border-white/10 rounded px-2 py-1 text-sm text-gray-200 placeholder-gray-600 focus:outline-none focus:border-purple-400/40"}),e.jsx("button",{type:"button",onClick:xr,disabled:ce||!zt.trim(),className:"p-1.5 rounded text-purple-300 hover:text-purple-200 hover:bg-purple-500/10 disabled:opacity-40",children:e.jsx(Ys,{size:12})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-3 py-2 flex items-center gap-2",children:[e.jsx("input",{type:"text",value:Ee,onChange:o=>dt(o.target.value),onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),ws())},disabled:ce||J,placeholder:J?"Recording paused…":"Type text — auto-targets the last tapped field…",className:"flex-1 bg-transparent border border-white/10 rounded px-2 py-1 text-sm text-gray-200 placeholder-gray-600 focus:outline-none focus:border-red-400/40"}),e.jsx("button",{type:"button",onClick:ws,disabled:ce||J||!Ee.trim(),className:"p-1.5 rounded text-red-300 hover:text-red-200 hover:bg-red-500/10 disabled:opacity-40",children:ce?e.jsx(ve,{size:12,className:"animate-spin"}):e.jsx(Ys,{size:12})})]}),e.jsxs("div",{className:"px-3 pb-2 flex items-center gap-1.5 text-[11px]",children:[e.jsx("span",{className:"text-gray-500 mr-1",children:"Keys:"}),e.jsx(Cs,{label:"Enter",hint:"↵",onClick:()=>qt("enter"),disabled:ce,paused:J}),e.jsx(Cs,{label:"Back",hint:"←",onClick:()=>qt("back"),disabled:ce,paused:J}),e.jsx(Cs,{label:"Home",hint:"⌂",onClick:()=>qt("home"),disabled:ce,paused:J}),e.jsx(Cs,{label:"Vol +",hint:"🔊",onClick:()=>qt("volume_up"),disabled:ce,paused:J}),e.jsx(Cs,{label:"Vol −",hint:"🔉",onClick:()=>qt("volume_down"),disabled:ce,paused:J}),e.jsx(Cs,{label:"Power",hint:"⏻",onClick:()=>qt("power"),disabled:ce,paused:J})]})]})}),P==="stopped"&&e.jsxs("div",{className:"flex-shrink-0 px-4 py-3 border-t border-white/5 bg-surface-1 space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex gap-1 p-0.5 bg-surface-2 rounded-lg",children:[e.jsx("button",{onClick:()=>{$t(!1),_e(""),vt(""),yt("")},className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${fe?"text-gray-500 hover:text-gray-300":"bg-brand-500/15 text-brand-300 shadow-sm"}`,children:"New Test"}),e.jsx("button",{onClick:()=>{$t(!0)},className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${fe?"bg-indigo-500/15 text-indigo-300 shadow-sm":"text-gray-500 hover:text-gray-300"}`,children:"Add to Existing Test"})]}),fe&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-gray-500 uppercase tracking-wider mb-1 block",children:"Insert Position"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Cn,{active:Se==="auto",onClick:()=>He("auto"),children:"Guide AI"}),e.jsx(Cn,{active:Se==="append",onClick:()=>He("append"),children:"Append At End"})]})]}),!fe&&e.jsxs("div",{children:[e.jsxs("label",{className:"text-[10px] text-gray-500 uppercase tracking-wider mb-1 block",children:["Test Name ",e.jsx("span",{className:"text-red-400",children:"*"})]}),e.jsx("input",{type:"text",value:Ge,onChange:o=>Pe(o.target.value),placeholder:"Test name (e.g. login-flow-test)",disabled:ce,className:"w-full px-3 py-2 rounded-lg bg-surface-2 border border-white/5 text-xs text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/40 disabled:opacity-40"}),Rr(Ge)&&e.jsx("p",{className:"mt-1 text-[11px] text-amber-600 dark:text-amber-400/90",children:Rr(Ge)})]}),fe&&e.jsxs("div",{className:"space-y-2 p-3 rounded-lg bg-indigo-500/5 border border-indigo-500/15",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"text-[10px] text-gray-500 uppercase tracking-wider mb-1 block",children:["Target Test ",e.jsx("span",{className:"text-red-400",children:"*"})]}),e.jsx(ii,{selectedFile:ge,selectedTest:Ae,open:Jt,setOpen:Ve,search:Zt,setSearch:ot,expanded:Kt,setExpanded:Is,suites:(Ce==null?void 0:Ce.suites)??[],loading:!Ce,onPick:(o,h)=>{_e(o),vt(h),Ve(!1),ot("")}})]}),Se==="auto"&&e.jsxs("div",{children:[e.jsxs("label",{className:"text-[10px] text-gray-500 uppercase tracking-wider mb-1 block",children:["Guide AI ",e.jsx("span",{className:"text-red-400",children:"*"}),Ae?e.jsx("span",{className:"normal-case text-gray-600 ml-1",children:"(type @ to reference recorded steps or target test cases)"}):e.jsx("span",{className:"normal-case text-gray-600 ml-1",children:"— select a test first"})]}),Ae?e.jsxs("div",{className:"relative",children:[e.jsx("textarea",{ref:Ps,value:We,onChange:o=>{yt(o.target.value);const h=o.target;h.style.height="auto",h.style.height=`${h.scrollHeight}px`},onKeyUp:o=>{const h=o.currentTarget,b=h.value,j=h.selectionStart??b.length,F=b.slice(0,j),q=F.lastIndexOf("@");if(q>=0&&(q===0||F[q-1]===" "||F[q-1]===`
13
- `)){const me=F.slice(q+1);if(!me.includes("]")){sr(me.toLowerCase()),Ke(!0);return}}Ke(!1)},onKeyDown:o=>{o.key==="Escape"&&ct&&(o.preventDefault(),Ke(!1))},placeholder:'e.g., Insert after @[#3 tap "Settings"] and add cart validation...',rows:1,disabled:ce,className:"w-full px-3 py-2 rounded-lg bg-surface-2 border border-white/10 text-xs text-gray-200 placeholder-gray-600 focus:outline-none focus:border-indigo-500/40 resize-none overflow-hidden disabled:opacity-40",style:{minHeight:"32px",maxHeight:"52px",overflowY:We.split(`
14
- `).length>2||We.length>100?"auto":"hidden"}}),ct&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>Ke(!1)}),e.jsx("div",{className:"absolute bottom-full left-0 w-full mb-1 max-h-44 overflow-y-auto bg-surface-1 border border-indigo-500/20 rounded-lg shadow-xl z-40 py-1",children:(()=>{const o=Le.filter(h=>!Bt||h.keyword.toLowerCase().includes(Bt)||h.name.toLowerCase().includes(Bt));return Le.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-gray-600 text-center",children:"No steps or test cases to reference"}):o.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-gray-600 text-center",children:"No matching steps"}):o.map((h,b)=>e.jsxs("button",{onClick:()=>{const j=Ps.current;if(!j)return;const F=j.selectionStart||0,q=We.slice(0,F),me=q.lastIndexOf("@"),Wt=We.slice(F),ks=`@[${h.keyword} ${h.name}]`,Ss=q.slice(0,me)+ks+" "+Wt;yt(Ss),Ke(!1),setTimeout(()=>{j.focus();const O=me+ks.length+1;j.setSelectionRange(O,O)},50)},className:"w-full text-left px-3 py-1.5 text-xs transition-colors hover:bg-indigo-500/10 flex items-center gap-2",children:[e.jsx("span",{className:"text-indigo-400 font-semibold flex-shrink-0 w-14 text-right",children:h.keyword}),e.jsx("span",{className:"text-gray-300 truncate",children:h.name})]},`${h.keyword}-${b}`))})()})]})]}):e.jsx("div",{className:"w-full px-3 py-3 rounded-lg bg-surface-2/50 border border-white/5 text-xs text-gray-600 text-center",children:"Select a test above to enable AI guidance with @-step references"})]})]})]}),ze.size>0&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-indigo-500/10 border border-indigo-500/25",children:[e.jsxs("span",{className:"text-xs text-gray-300 flex-1",children:[ze.size," step",ze.size===1?"":"s"," selected"]}),e.jsxs("button",{type:"button",onClick:()=>Me({mode:"replace"}),className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium bg-indigo-600 hover:bg-indigo-500 text-white",children:[e.jsx(Ht,{size:12})," Replace with custom step"]}),e.jsx("button",{type:"button",onClick:()=>Fe(new Set),className:"px-2 py-1 rounded-md text-xs text-gray-400 hover:text-gray-200",children:"Clear"})]}),e.jsx(ta,{settings:kt,onChange:M,inputs:B.filter(o=>o.type==="type"&&!o.secretEnv).map(o=>({id:String(o.index),value:o.text,valueFrom:o.valueFrom})),onMatch:o=>{for(const h of o)x(Number(h.id),h.valueFrom)},disabled:ce}),e.jsxs("div",{className:"flex items-center gap-2",children:[si,lt==="testver"&&e.jsx(Vr,{refreshSignal:ds}),e.jsx(Yr,{providerModels:Tt,selectedProvider:lt,selectedModel:it,onPick:At}),e.jsxs("button",{onClick:G,disabled:Gt,title:"LLM generation — reads project, matches your code style",className:`flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg text-sm font-semibold transition-colors disabled:opacity-50 ${fe?"bg-indigo-500/20 text-indigo-300 border border-indigo-500/30 hover:bg-indigo-500/30":"bg-brand-500/20 text-brand-300 border border-brand-500/30 hover:bg-brand-500/30"}`,children:[ds?e.jsx(ve,{size:14,className:"animate-spin"}):e.jsx(Js,{size:14}),fe?"Merge & Generate":"Generate Test Code"]})]})]}),P==="generating"&&Je&&e.jsx("div",{className:"sticky bottom-[92px] z-20 px-4 pointer-events-none",children:e.jsx("div",{className:"pointer-events-auto",children:e.jsx(Wr,{pending:Je,queuedCount:ns.current.length,onAllow:()=>be(!0,!1),onAlwaysAllow:()=>be(!0,!0),onDeny:()=>be(!1,!1)})})}),P==="generating"&&e.jsxs("div",{className:"sticky bottom-0 border-t border-white/10 bg-surface-1 px-4 py-3 mt-2",children:[ce&&e.jsx("div",{className:"flex items-center pl-1 pb-3",children:e.jsx(Wn,{})}),e.jsxs("div",{className:"flex items-end gap-2 rounded-lg bg-white border border-gray-300 pr-2 focus-within:border-brand-500/60 transition-colors",children:[e.jsx("textarea",{value:Qe,onChange:o=>{ss(o.target.value);const h=o.target;h.style.height="auto",h.style.height=`${Math.min(h.scrollHeight,120)}px`},onKeyDown:o=>{o.key==="Enter"&&!o.shiftKey&&(o.preventDefault(),!ce&&(Qe.trim()||De)&&mt())},placeholder:ce?"AI is working... click stop to cancel":De?"Review the analysis above. Press Enter to proceed or type feedback...":"Request changes to the generated code...",rows:1,disabled:ce,className:"flex-1 px-3 py-2 bg-transparent text-sm text-gray-800 placeholder-gray-400 focus:outline-none resize-none overflow-hidden disabled:opacity-50 leading-5",style:{minHeight:"36px",maxHeight:"120px"}}),e.jsx("div",{className:"flex-shrink-0 pb-1.5",children:ce?e.jsx("button",{onClick:qe,title:"Stop generation",className:"flex items-center justify-center w-6 h-6 rounded-full bg-gray-400 hover:bg-gray-500 transition-colors",children:e.jsx(at,{size:10,className:"fill-gray-900 text-gray-900",strokeWidth:0})}):e.jsx("button",{onClick:mt,disabled:!Qe.trim()&&!De,className:"flex items-center justify-center w-7 h-7 rounded-md text-brand-400 hover:bg-brand-500/15 transition-colors disabled:opacity-30 disabled:cursor-not-allowed",children:e.jsx(Ys,{size:14})})})]}),e.jsx("p",{className:"text-[10px] text-gray-600 mt-1.5",children:ce?"Click the stop button to cancel the current generation":De?"Press Enter to proceed with code generation · Or type feedback to modify the approach":"Press Enter to send · Shift+Enter for new line · AI has full context of the previous generation"})]}),(et||tt)&&P!=="generating"&&e.jsxs("div",{className:`px-3 py-1.5 border-t border-white/[0.05] text-[11px] flex items-center gap-1.5 ${et?"text-red-300":"text-gray-500"}`,children:[et?e.jsx($s,{size:11}):e.jsx(ft,{size:11}),et||tt]})]})}const Dr=xe.length>0,Ns=De?{icon:Qt,color:"amber",label:"Waiting for your input"}:Ds==="failed"?{icon:Ms,color:"red",label:"Generation Failed"}:Ds==="stopped"?{icon:at,color:"gray",label:"Stopped"}:{icon:ft,color:"emerald",label:"Code Generated"},aa=Ns.icon,oa=jt?` — ${jt}`:"";return e.jsxs("div",{className:"relative h-full flex flex-col bg-white dark:bg-transparent",children:[e.jsx(Hr,{open:ar,onClose:()=>xt(!1),onLoad:Pr}),ke&&e.jsx(Kr,{screenshot:ke.screenshot,screenshotSize:ke.screenshotSize,elementRect:ke.elementRect,step:ke.step,description:ke.description,onClose:()=>Pt(null)}),e.jsxs("div",{className:"px-4 py-3 border-b border-white/5 bg-surface-1 flex items-center gap-3",children:[e.jsx("button",{onClick:()=>xt(!0),className:"p-1.5 -ml-1.5 rounded-lg text-gray-500 hover:text-gray-300 hover:bg-white/5 transition-colors",title:"Recording History",children:e.jsx(Sr,{size:16})}),e.jsx(aa,{size:16,className:`text-${Ns.color}-400 ${Ns.color==="gray"?"fill-gray-400":""}`,strokeWidth:Ns.color==="gray"?0:2}),e.jsxs("span",{className:`text-sm font-semibold text-${Ns.color}-300`,children:[Ns.label,oa]}),e.jsx("span",{className:"text-[12px] text-gray-500",children:"·"}),e.jsxs("span",{className:"text-[12px] text-gray-400",children:[B.length," steps"]}),e.jsx("div",{className:"flex-1"}),(he==null?void 0:he.specSource)&&e.jsxs("button",{onClick:async()=>{he!=null&&he.specSource&&await navigator.clipboard.writeText(he.specSource)},className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium bg-white/5 border border-white/10 text-gray-300 hover:bg-white/10",children:[e.jsx(yo,{size:12})," Copy spec"]}),e.jsxs("button",{onClick:nt,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium bg-red-500/15 text-red-300 border border-red-500/30 hover:bg-red-500/25",children:[e.jsx(kr,{size:12})," New Recording"]})]}),he&&he.specPath&&he.specPath!=="(see AI Assistant tab for written files)"&&he.specPath!=="(not generated)"&&e.jsxs("div",{className:"px-4 py-3 border-b border-white/5 bg-surface-1/40 space-y-1 text-[12px]",children:[e.jsxs("div",{className:"flex items-start gap-2 text-gray-300",children:[e.jsx(vr,{size:13,className:"mt-0.5 text-indigo-400 flex-shrink-0"}),e.jsx("code",{className:"break-all",children:he.specPath})]}),he.healingPath&&he.healingPath!=="(see AI Assistant tab for written files)"&&e.jsxs("div",{className:"flex items-start gap-2 text-gray-400",children:[e.jsx(vr,{size:13,className:"mt-0.5 opacity-60 flex-shrink-0"}),e.jsx("code",{className:"break-all opacity-80",children:he.healingPath})]})]}),Dr?e.jsx(Nn,{entries:xe,busy:ce,onOpenScreenshot:i=>Pt(i)}):e.jsx("div",{className:"flex-1 overflow-auto bg-[#0b0d11]",children:e.jsx("pre",{className:"px-4 py-3 text-[12px] leading-relaxed text-gray-300 font-mono whitespace-pre",children:(he==null?void 0:he.specSource)??"(empty)"})}),Dr&&Je&&e.jsx("div",{className:"sticky bottom-[92px] z-20 px-4 pointer-events-none",children:e.jsx("div",{className:"pointer-events-auto",children:e.jsx(Wr,{pending:Je,queuedCount:ns.current.length,onAllow:()=>be(!0,!1),onAlwaysAllow:()=>be(!0,!0),onDeny:()=>be(!1,!1)})})}),Dr&&e.jsxs("div",{className:"border-t border-white/10 bg-surface-1 px-4 py-3 mt-2",children:[e.jsxs("div",{className:"flex items-end gap-2 rounded-lg bg-white border border-gray-300 pr-2 focus-within:border-brand-500/60 transition-colors",children:[e.jsx("textarea",{value:Qe,onChange:i=>{ss(i.target.value);const o=i.target;o.style.height="auto",o.style.height=`${Math.min(o.scrollHeight,120)}px`},onKeyDown:i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),!ce&&(Qe.trim()||De)&&mt())},placeholder:ce?"AI is working... click stop to cancel":De?"Review the analysis above. Press Enter to proceed or type feedback...":"Request changes to the generated code...",rows:1,disabled:ce,className:"flex-1 px-3 py-2 bg-transparent text-sm text-gray-800 placeholder-gray-400 focus:outline-none resize-none overflow-hidden disabled:opacity-50 leading-5",style:{minHeight:"36px",maxHeight:"120px"}}),e.jsx("div",{className:"flex-shrink-0 pb-1.5",children:ce?e.jsx("button",{onClick:qe,title:"Stop generation",className:"flex items-center justify-center w-6 h-6 rounded-full bg-gray-400 hover:bg-gray-500 transition-colors",children:e.jsx(at,{size:10,className:"fill-gray-900 text-gray-900",strokeWidth:0})}):e.jsx("button",{onClick:mt,disabled:!Qe.trim()&&!De,className:"flex items-center justify-center w-7 h-7 rounded-md text-brand-400 hover:bg-brand-500/15 transition-colors disabled:opacity-30 disabled:cursor-not-allowed",children:e.jsx(Ys,{size:14})})})]}),e.jsx("p",{className:"text-[10px] text-gray-600 mt-1.5",children:ce?"Click the stop button to cancel the current generation":De?"Press Enter to proceed with code generation · Or type feedback to modify the approach":"Press Enter to send · Shift+Enter for new line · AI has full context of the previous generation"})]})]})}const ni={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-violet-500",custom:"border-l-indigo-500"};function Sn({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"})]})})}function ai({action:t,stepNum:n,canMutate:u,isEditing:d,editingDescription:l,onEditChange:N,onStartEdit:p,onSaveEdit:A,onCancelEdit:I,onDelete:E,isDragging:C,isDropTarget:k,dropPosition:T,wasJustDropped:S,onDragStart:L,onDragOver:H,onDragLeave:D,onDrop:V,onDragEnd:U,onOpenScreenshot:oe,playbackStatus:P,selectable:Y=!1,selected:g=!1,anySelected:Z=!1,onToggleSelect:B,onEditCustom:ee,onRestore:J,valuePicker:ie}){var R,v,W;const se=ni[t.type]||"border-l-gray-500",ue=t.type==="tap"?Nr:t.type==="type"?As:t.type==="swipe"?Zr:t.type==="assertion"?zs:t.type==="annotation"?Tr:t.type==="custom"?Ht:en,y=t.type==="custom";return e.jsxs("div",{draggable:u,onDragStart:L,onDragOver:H,onDragLeave:D,onDrop:V,onDragEnd:U,className:`relative flex items-center gap-2.5 px-3 py-2 rounded-r-lg border-l-[3px] ${se}
15
- hover:bg-black/[0.04] dark:hover:bg-white/[0.06]
16
- group transition-all duration-500
17
- ${P==="running"?"ring-2 ring-brand-400/70 bg-brand-500/[0.10] shadow-[0_0_16px_rgba(99,102,241,0.35)]":""}
18
- ${P==="done"?"bg-emerald-500/[0.07]":""}
19
- ${P==="error"?"bg-red-500/[0.08] ring-1 ring-red-500/40":""}
20
- ${C?"opacity-50 ring-2 ring-blue-400/60 shadow-[0_0_18px_rgba(96,165,250,0.45)] bg-blue-500/[0.06]":""}
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
- ${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
- `),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:
25
-
26
- "${r}"
27
-
28
- Acknowledge their feedback briefly, incorporate the changes into your plan, then proceed with the implementation — write the code, run the test, fix any failures, and provide a summary.`:r;$e(""),Ue(!0),w(null),ut(),le.current="",Ee.current=null,dt.current=!1,Ce.current=!0,Fe.current=!0,a&&m(!1);const M=`recorder-followup-${Date.now()}`;Nt(M),A("generating"),C(_=>[..._,{kind:"user",id:te(),text:r||(a?"Looks good, proceed!":"")}]);const c=E.filter(_=>_.kind==="file-diff").filter(_=>!_.via&&!_.omitted&&!_.netNoChange&&_.diffType!=="deleted"&&!!_.filePath).map(_=>_.filePath),z=c.find(_=>yi.test(_))||(U&&P?P:void 0)||c[0],K=new Set,ne=[],Q=[];for(const _ of E)if(_.kind==="recorded-action")ne.push(_.actionType==="custom"?`custom step: ${_.instruction||_.description}${(Re=_.outputs)!=null&&Re.length?` (saves ${_.outputs.map(be=>`{${be}}`).join(", ")})`:""}`:`${_.actionType}: ${_.description}${_.valueFrom?` (uses {${_.valueFrom}})`:""}`);else if(_.kind==="file-diff"&&_.filePath&&!_.netNoChange)K.add(_.filePath);else if(_.kind==="user")Q.push(`User: ${_.text}`);else if(_.kind==="text"&&_.text){const be=String(_.text);Q.push(`Assistant: ${be.length>2e3?be.substring(0,2e3)+"... [truncated]":be}`)}else if(_.kind==="tool"){if(_.phase==="start")continue;const be=_.args?` ${String(_.args).substring(0,100)}`:"";let qe="";if(_.phase==="complete"){const mt=_.result?String(_.result):"";qe=mt?` → ${mt.length>300?mt.substring(0,300)+"... [truncated]":mt}`:" → (no output)"}else _.phase==="error"?qe=` → ERROR: ${_.error?String(_.error).substring(0,300):"failed"}`:_.phase==="denied"&&(qe=" → DENIED by user");Q.push(`[Tool ${_.phase}] ${_.toolName}${be}${qe}`)}else _.kind==="error"&&Q.push(`[Stream Error] ${_.text}`);const de=[];ne.length>0&&de.push(`Recorded steps (${ne.length}):
29
- ${ne.map((_,be)=>` ${be+1}. ${_}`).join(`
30
- `)}`),K.size>0&&de.push(`Files created/modified:
31
- ${[...K].map(_=>` - ${_}`).join(`
32
- `)}`),Q.length>0&&de.push(`Conversation history (in order):
33
- ${Q.join(`
34
-
35
- `)}`);try{await ro({requestId:M,prompt:f,testFilePath:z,previousContext:de.length>0?de.join(`
36
- `):void 0,model:ye||void 0,provider:tt||void 0,proceedAfterAnalysis:a,sessionId:At||void 0})}catch(_){C(be=>[...be,{kind:"error",id:te(),text:`Failed to start follow-up: ${_}`}]),Ue(!1),Nt(null),a&&m(!0),A("done")}},Gs=(r,a=!1)=>{st&&(n({type:"ai-fix-permission-response",permissionId:st.permissionId,granted:r,remember:r&&a}),as(Er()))},Er=()=>Ot.current.shift()||null,Mr=async r=>{const a=k.current.find(x=>x.id===r&&x.kind==="recorded-action");if(a){Ps(r);try{const x=await Ja();if(!(x!=null&&x.success)||!x.element)return;const f=x.description||a.description,c=`${a.actionType==="click"?"Click":a.actionType==="hover"?"Hover over":a.actionType==="fill"?"Enter":a.actionType==="dblclick"?"Double-click":a.actionType==="select"?"Select":a.actionType==="check"?"Check":a.actionType==="uncheck"?"Uncheck":a.actionType} '${f}'${a.value&&!a.secretEnv?` with "${a.value}"`:""}`;C(z=>z.map(K=>K.id===r&&K.kind==="recorded-action"?{...K,description:c,selector:x.selector}:K));try{await Lr(r,{selector:x.selector,locators:x.locators,domContext:x.domContext,elementMeta:x.elementMeta,description:c})}catch(z){C(K=>K.map(ne=>ne.id===r?a:ne)),u("error",`Couldn't update the step — it was left as it was. ${z}`)}}catch(x){u("error",`Re-inspect failed: ${x}`)}finally{Ps(null)}}},lr=async r=>{const a=k.current.findIndex(f=>f.id===r),x=a>=0?k.current[a]:void 0;C(f=>f.filter(M=>M.id!==r)),Pe(f=>Math.max(0,f-1));try{await Za(r)}catch(f){x&&(C(M=>{if(M.some(z=>z.id===r))return M;const c=[...M];return c.splice(Math.min(a,c.length),0,x),c}),Pe(M=>M+1)),u("error",`Couldn't remove the step — it was put back. ${f}`)}},Ws=r=>{const a=k.current;C(r);const x=r.filter(f=>f.kind==="recorded-action").map(f=>f.id);eo(x).catch(f=>{C(a),u("error",`Couldn't reorder the steps — the previous order was restored. ${f}`)})},Vs=(r,a)=>{const x=k.current,f=x.findIndex(K=>K.id===r);if(f<0)return;let M=f+a;for(;M>=0&&M<x.length&&x[M].kind!=="recorded-action";)M+=a;if(M<0||M>=x.length)return;const c=[...x],[z]=c.splice(f,1);c.splice(M,0,z),Ws(c),requestAnimationFrame(()=>{var K;return(K=document.querySelector(`[data-action-id="${r}"]`))==null?void 0:K.focus()})},Dt=r=>Ae(r),cr=(r,a,x)=>{const f=[...r];if(x===null){const M=f.findIndex(c=>c.kind==="recorded-action");f.splice(M>=0?M:f.length,0,a)}else{const M=x?f.findIndex(c=>c.id===x):-1;M>=0?f.splice(M+1,0,a):f.push(a)}return f},dr=async r=>{const a=ot;if(a){if(a.mode==="add"){const x=await ao(r,a.afterId),f=Vt(x.action,te);C(M=>cr(M,f,a.afterId)),Pe(M=>M+1)}else if(a.mode==="edit"&&a.editId){const x=await Lr(a.editId,{instruction:r.instruction,customKind:r.customKind,references:r.references||[],outputs:r.outputs||[]}),f=x.action?Vt(x.action,te):null;C(M=>M.map(c=>c.id===a.editId&&c.kind==="recorded-action"?{...c,...f?{description:f.description,instruction:f.instruction,customKind:f.customKind,references:f.references,outputs:f.outputs}:{}}:c))}else if(a.mode==="replace"){const x=[...vt],f=await oo(x,r),M=Vt(f.action,te),c=new Set(x);C(z=>{const K=z.findIndex(Q=>c.has(Q.id));Is.current.set(M.id,z.filter(Q=>c.has(Q.id)));const ne=z.filter(Q=>!c.has(Q.id));return ne.splice(K>=0?Math.min(K,ne.length):ne.length,0,M),ne}),Pe(z=>Math.max(0,z-x.length+1)),Kt(new Set)}Ae(null)}},ur=async r=>{try{const a=await Xa(r),x=Is.current.get(r),f=x&&x.length===a.actions.length?x:a.actions.map(M=>Vt(M,te));Is.current.delete(r),C(M=>{const c=M.findIndex(Q=>Q.id===r);if(c<0)return M;const z=[...M];if(!a.order)return z.splice(c,1,...f),z;z.splice(c,1);let K=c;const ne=new Map(a.order.map((Q,de)=>[Q,de]));for(const Q of[...f].sort((de,Re)=>(ne.get(de.id)??0)-(ne.get(Re.id)??0))){const de=ne.get(Q.id)??-1,Re=de>0?a.order[de-1]:null,_=Re?z.findIndex(qe=>qe.id===Re):-1,be=_>=0?_+1:Math.min(K,z.length);z.splice(be,0,Q),K=be+1}return z}),Pe(M=>M-1+f.length)}catch(a){u("error",`Couldn't put the steps back: ${a}`)}},vs=async(r,a)=>{const x=k.current.find(f=>f.id===r&&f.kind==="recorded-action");C(f=>f.map(M=>M.id===r&&M.kind==="recorded-action"?{...M,valueFrom:a||void 0}:M));try{await Lr(r,{valueFrom:a})}catch(f){C(M=>M.map(c=>c.id===r&&c.kind==="recorded-action"?{...c,valueFrom:x==null?void 0:x.valueFrom}:c)),u("error",`Couldn't change the step: ${f}`)}},ws=s.useRef(null),qt=r=>{Zt(r),ws.current&&clearTimeout(ws.current),ws.current=setTimeout(()=>{to(r).catch(()=>{})},500)},xr=s.useMemo(()=>{var M;const r=new Map,a=[],x=(((M=Ve==null?void 0:Ve.testData)==null?void 0:M.columns)||[]).map(c=>({name:`data.${c}`,source:"data",detail:Ve.testData.file}));let f=0;for(const c of E)if(c.kind==="recorded-action"&&(f++,r.set(c.id,[...a,...x]),c.actionType==="custom"))for(const z of c.outputs||[])a.push({name:z,source:"step",detail:`saved by step ${f}`});return r},[E,Ve]),Ft=r=>Kt(a=>{const x=new Set(a);return x.has(r)?x.delete(r):x.add(r),x}),zr=async()=>{await Va().catch(()=>{}),A("setup"),C([]),Pe(0),$t(0),_e(!1),Se.current=0,He.current=0,L(""),V(""),ut(),Nt(null),Ue(!1),et(!1),Oe(-1),le.current="",Ee.current=null,$e(""),m(!1),w(null),je(!1),Me(!1),yt(!0),Zt(null),Kt(new Set),Ce.current=!1,Jt.current=null,ct(null),dt.current=!1},Ir=p==="recording"||p==="generating"||p==="playback";return it==="mobile"?e.jsx(ci,{showHistory:es,setShowHistory:ts,recorderMode:it,setRecorderMode:lt}):e.jsxs($o,{userControlOnly:!0,children:[e.jsxs("div",{className:"h-full flex flex-col relative bg-white dark:bg-transparent",children:[e.jsx("div",{ref:Ar,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:()=>ts(!es),className:`flex-shrink-0 p-1.5 rounded-lg transition-colors ${es?"bg-brand-500/15 text-brand-300":"text-gray-500 hover:text-gray-300 hover:bg-white/5"}`,"aria-label":"Recording History","aria-expanded":es,title:"Recording History",children:e.jsx(Sr,{size:16})}),p==="recording"?e.jsxs(e.Fragment,{children:[ge?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:pi(fe)}),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:Ge})]}):p==="playback"?e.jsxs(e.Fragment,{children:[e.jsx(Ts,{size:14,className:"text-cyan-400 fill-cyan-400"}),e.jsx("span",{className:"text-sm font-semibold text-cyan-300",children:"Replaying..."}),e.jsxs("span",{className:"text-xs px-1.5 py-0.5 rounded-full bg-cyan-500/10 text-cyan-400 border border-cyan-500/20 ml-1",children:[xt,"/",It]})]}):p==="generating"?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:"Generating Code..."})]}):p==="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:[Ge," action",Ge!==1?"s":""]})]}):p==="done"?$?e.jsxs(e.Fragment,{children:[e.jsx(Qt,{size:14,className:"flex-shrink-0 text-amber-400"}),e.jsxs("span",{className:"text-sm font-semibold text-amber-300 truncate",title:D||void 0,children:["Waiting for your input",D?` — ${D}`:""]})]}):X==="failed"?e.jsxs(e.Fragment,{children:[e.jsx(Ms,{size:14,className:"flex-shrink-0 text-red-400"}),e.jsxs("span",{className:"text-sm font-semibold text-red-300 truncate",title:D||void 0,children:["Generation Failed",D?` — ${D}`:""]})]}):X==="stopped"?e.jsxs(e.Fragment,{children:[e.jsx(at,{size:12,className:"flex-shrink-0 text-gray-400 fill-gray-400",strokeWidth:0}),e.jsxs("span",{className:"text-sm font-semibold text-gray-300 truncate",title:D||void 0,children:["Stopped",D?` — ${D}`:""]})]}):e.jsxs(e.Fragment,{children:[e.jsx(ft,{size:14,className:"flex-shrink-0 text-emerald-400"}),e.jsxs("span",{className:"text-sm font-semibold text-emerald-300 truncate",title:D||void 0,children:["Code Generated",D?` — ${D}`:""]})]}):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:"Browser Recorder"})]}),Tt.isAmbiguous&&e.jsx("div",{className:"ml-2 flex-shrink-0",children:e.jsx(Qn,{value:it,onChange:lt,disabled:Ir})})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[p==="recording"&&e.jsxs(e.Fragment,{children:[!ge&&e.jsxs(e.Fragment,{children:[e.jsx(Ct,{label:we?"Exit assertion mode":"Add an assertion",hint:we?void 0:"Click an element in the browser to check it, instead of clicking it",shortcut:we?"Esc":void 0,children:e.jsxs("button",{"aria-label":we?"Exit assertion mode":"Add an assertion",onClick:async()=>{try{Ne&&(await mn(!1),Me(!1)),await fn(!we),je(!we),we||gn()}catch{}},className:`flex items-center gap-1 px-2 py-1.5 rounded-lg text-xs font-medium transition-colors ${we?"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}),we&&e.jsx("span",{children:"ON"})]})}),e.jsx(Ct,{label:Ne?"Exit annotate mode":"Annotate a step",hint:Ne?void 0:"Select an element or an area and describe the action or check you want — even a complex one — and the AI will implement it for you",shortcut:Ne?"Esc":void 0,children:e.jsxs("button",{"aria-label":Ne?"Exit annotate mode":"Annotate a step",onClick:async()=>{try{we&&(await fn(!1),je(!1)),await mn(!Ne),Me(!Ne),Ne||gn()}catch{}},className:`flex items-center gap-1 px-2 py-1.5 rounded-lg text-xs font-medium transition-colors ${Ne?"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}),Ne&&e.jsx("span",{children:"ON"})]})})]}),e.jsx(Ct,{label:"Add custom step",hint:"A step that is not a click in the app — reuse a login, read an email, test data…",children:e.jsx("button",{onClick:()=>Dt({mode:"add"}),className:"flex items-center gap-1 px-2 py-1.5 rounded-lg text-xs font-medium bg-surface-2 text-gray-400 border border-white/5 hover:text-indigo-500 hover:bg-indigo-500/10 hover:border-indigo-500/20 transition-colors","aria-label":"Add custom step",children:e.jsx(Ht,{size:14})})}),e.jsx(Ct,{label:ge?"Resume recording":"Pause recording",hint:ge?"Your actions are recorded again":"Use the page freely — nothing is recorded until you resume",children:e.jsx("button",{"aria-label":ge?"Resume recording":"Pause recording",onClick:ge?Pt:ke,className:`flex items-center justify-center w-8 h-8 rounded-lg transition-colors ${ge?"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:ge?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:gs,disabled:_s,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:_s?e.jsx(ve,{size:14,className:"animate-spin"}):e.jsx(at,{size:14})})})]}),(p==="stopped"||p==="done")&&e.jsxs(e.Fragment,{children:[p==="stopped"&&e.jsx(Xs,{tone:"indigo",compact:xs,icon:e.jsx(Ht,{size:13}),label:"Custom Step",hint:"Add a custom step at the end — or hover between two steps to insert one there",onClick:()=>Dt({mode:"add"})}),p==="stopped"&&e.jsx(Xs,{tone:"brand",compact:xs,icon:e.jsx(tr,{size:13}),label:"Add More Steps",hint:We?"Continue recording — add more steps to this recording":"This recording can no longer be continued (opened from History, or its browser was closed) — start a new recording to add steps",disabled:!We,onClick:bs}),e.jsx(Xs,{compact:xs,icon:e.jsx(kr,{size:13}),label:"New Recording",hint:"Start over with a new recording (this one stays in History)",onClick:zr})]})]})]})}),e.jsxs("div",{ref:ze,onScroll:fs,className:`flex-1 overflow-y-auto p-4 space-y-3 transition-all duration-200 ${es?"ml-[280px]":""}`,children:[p==="setup"&&e.jsxs("div",{className:"max-w-xl mx-auto mt-8 space-y-6",children:[Ke&&e.jsx("div",{className:"bg-amber-500/5 border border-amber-500/20 rounded-xl p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-amber-500/15 flex items-center justify-center flex-shrink-0",children:e.jsx(vr,{size:20,className:"text-amber-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-amber-300",children:"Unsaved Draft Found"}),e.jsxs("div",{className:"text-xs text-gray-400 mt-0.5",children:[Ke.actionCount||((pr=Ke.actions)==null?void 0:pr.length)||0," steps recorded",Ke.url?` on ${Ke.url}`:""]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs("button",{onClick:()=>{ys(Ke),Bt(null)},className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium bg-amber-500/20 text-amber-300 border border-amber-500/30 hover:bg-amber-500/30 transition-colors",children:[e.jsx(Ts,{size:12})," Resume Draft"]}),e.jsx("button",{onClick:()=>{Or(Ke.id||wt()).catch(()=>{}),Bt(null)},className:"p-1.5 rounded-lg text-gray-500 hover:text-red-400 hover:bg-red-500/10 transition-colors",title:"Discard draft",children:e.jsx(Es,{size:14})})]})]})}),e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-red-500/10 border border-red-500/20 mx-auto",children:e.jsx(ht,{size:28,className:"text-red-400"})}),e.jsx("h2",{className:"text-xl font-semibold text-gray-200",children:"Record Browser Interactions"}),e.jsx("p",{className:"text-[15px] text-gray-500 max-w-md mx-auto",children:"Record your browser interactions, then let AI generate reusable test code that follows your project's existing patterns and conventions."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"text-sm font-medium text-gray-400",children:["Starting URL ",e.jsx("span",{className:"text-red-400",children:"*"})]}),e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex-1 relative",children:[e.jsx(tn,{size:16,className:"absolute left-3.5 top-1/2 -translate-y-1/2 text-gray-500"}),e.jsx("input",{type:"text",value:S,onChange:r=>{L(r.target.value),jt(null)},placeholder:"https://example.com","aria-invalid":S.trim()!==""&&!H,className:`w-full pl-10 pr-3.5 py-2.5 rounded-lg bg-surface-2 border text-[15px] text-gray-200 placeholder-gray-600 focus:outline-none focus:ring-1 ${S.trim()!==""&&!H?"border-red-500/40 focus:border-red-500/50 focus:ring-red-500/20":"border-white/5 focus:border-brand-500/40 focus:ring-brand-500/20"}`,onKeyDown:r=>{r.key==="Enter"&&!Je&&Bs()}})]})}),S.trim()!==""&&!H?e.jsx("p",{className:"text-xs text-red-400",children:"Enter a valid URL starting with http:// or https:// (e.g. https://example.com)."}):e.jsx("p",{className:"text-xs text-gray-500",children:"Required — the page the recording opens in. Recording starts once a valid URL is entered."})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${nr?"bg-emerald-400":"bg-gray-600"}`}),nr?"Browser is running — recording will use the current session":"A new browser will be launched for recording"]}),e.jsxs("button",{onClick:Bs,disabled:Je||!H,title:H?void 0:"Enter a valid starting URL to begin recording",className:"w-full flex items-center justify-center gap-2 px-5 py-3 rounded-lg text-[15px] font-semibold bg-red-500/20 text-red-300 border border-red-500/30 hover:bg-red-500/30 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:[Je?e.jsx(ve,{size:18,className:"animate-spin"}):e.jsx(ht,{size:18,className:"fill-red-400 text-red-400"}),"Start Recording"]}),ns&&e.jsxs("p",{role:"alert",className:"flex items-start gap-1.5 text-sm text-red-600 dark:text-red-400",children:[e.jsx($s,{size:15,className:"mt-0.5 flex-shrink-0"}),e.jsxs("span",{children:["Couldn't start recording: ",ns]})]})]}),p!=="setup"&&e.jsx("div",{className:"space-y-0.5",children:To(E,{toolOf:r=>r.kind==="tool"?r:null,diffOf:r=>r.kind==="file-diff"?r:null,isTurnStart:r=>r.kind==="user",isInvisible:r=>r.kind==="text"&&!r.text.trim(),streaming:p==="generating"}).map(r=>{var f,M,c,z;if(r.kind==="group")return e.jsx(Ao,{group:r,className:"!-my-1"},r.id);if(r.kind==="changes")return e.jsx(Eo,{item:r},r.id);const a=r.entry,x=T.get(a.id)??0;if(a.kind==="recorded-action"){const K=E.slice(0,x+1).filter(G=>G.kind==="recorded-action").length,ne=ui[a.actionType]||"border-l-gray-500",Q=xi.has(a.actionType),de=Ye===x,Re=ss===x&&Ye!==x,_=a.actionType==="custom",be=p==="stopped"&&!_,qe=vt.has(a.id),mt=(p==="stopped"||p==="recording")&&$n.has(a.actionType)&&!a.secretEnv;return e.jsxs("div",{children:[p==="stopped"&&K===1&&e.jsx(En,{label:"Insert a custom step before step 1",onInsert:()=>Dt({mode:"add",afterId:null})}),e.jsxs("div",{draggable:p==="stopped",onDragStart:G=>{Qe(x),G.dataTransfer.effectAllowed="move";try{const Le=document.createElement("div");Le.style.cssText="position:absolute;top:-9999px;width:200px;padding:6px 12px;background:#1e293b;color:#e2e8f0;border-radius:6px;font-size:12px;border-left:3px solid #3b82f6;",Le.textContent=a.description.substring(0,40),document.body.appendChild(Le),G.dataTransfer.setDragImage(Le,100,15),setTimeout(()=>Le.remove(),0)}catch{}},onDragOver:G=>{G.preventDefault(),G.dataTransfer.dropEffect="move";const Le=Date.now();if(Le-ps.current<50)return;ps.current=Le;const Gt=G.currentTarget.getBoundingClientRect(),nt=Gt.top+Gt.height/2,is=G.clientY<nt?"above":"below";(ss!==x||Et!==is)&&(Xe(x),Fs(is))},onDragLeave:()=>{ss===x&&Xe(null)},onDrop:G=>{var Le;if(G.preventDefault(),Ye!==null&&Ye!==x){const Gt=(Le=E[Ye])==null?void 0:Le.id,nt=[...E],[is]=nt.splice(Ye,1);if(is){let St=x;Ye<x?St=Et==="above"?x-1:x:St=Et==="above"?x:x+1,St=Math.max(0,Math.min(St,nt.length)),nt.splice(St,0,is),Ws(nt)}Gt&&(rr(Gt),setTimeout(()=>{const St=document.querySelector(`[data-action-id="${Gt}"]`);St&&St.scrollIntoView({behavior:"smooth",block:"nearest"})},50),setTimeout(()=>rr(null),3e3))}Qe(null),Xe(null)},onDragEnd:()=>{Qe(null),Xe(null)},tabIndex:p==="stopped"?0:void 0,"aria-label":`Step ${K}: ${a.description}${p==="stopped"?" — Alt+Up or Alt+Down to move":""}`,onKeyDown:G=>{p!=="stopped"||!G.altKey||G.target!==G.currentTarget||(G.key==="ArrowUp"?(G.preventDefault(),Vs(a.id,-1)):G.key==="ArrowDown"&&(G.preventDefault(),Vs(a.id,1)))},"data-action-id":a.id,className:`relative flex items-center gap-2.5 px-3 py-2 rounded-r-lg border-l-[3px] ${ne} ${qe?"bg-indigo-500/[0.07]":""} hover:bg-black/[0.04] dark:hover:bg-white/[0.06] focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/50 group ${de?"cursor-grabbing":"cursor-default"} ${de?"opacity-30":"transition-colors duration-100"} ${rs===a.id?"ring-2 ring-blue-400 bg-blue-500/5 animate-pulse":""}`,children:[Re&&Et==="above"&&e.jsx("div",{className:"absolute -top-[2px] left-0 right-0 h-[3px] bg-blue-500 rounded-full z-10",children:e.jsx("div",{className:"absolute -left-1 -top-[3px] w-[9px] h-[9px] rounded-full bg-blue-500"})}),Re&&Et==="below"&&e.jsx("div",{className:"absolute -bottom-[2px] left-0 right-0 h-[3px] bg-blue-500 rounded-full z-10",children:e.jsx("div",{className:"absolute -left-1 -top-[3px] w-[9px] h-[9px] rounded-full bg-blue-500"})}),p==="stopped"&&e.jsx("span",{className:"flex-shrink-0 w-4 flex items-center justify-center",onMouseDown:G=>G.stopPropagation(),children:be&&e.jsx("input",{type:"checkbox",checked:qe,onChange:()=>Ft(a.id),onClick:G=>G.stopPropagation(),"aria-label":`Select step ${K} (to replace it with a custom step)`,title:"Select to replace with a custom step",className:`cursor-pointer accent-indigo-500 ${vt.size>0||qe?"opacity-100":"opacity-0 group-hover:opacity-100 focus:opacity-100"}`})}),e.jsx("span",{className:"flex-shrink-0 w-6 text-center text-xs font-bold text-gray-500",children:K}),a.screenshot?e.jsx("button",{draggable:!1,onMouseDown:G=>G.stopPropagation(),onDragStart:G=>{G.preventDefault(),G.stopPropagation()},className:"flex-shrink-0 w-9 h-7 rounded overflow-hidden border border-white/10 hover:border-brand-400/50 transition-colors relative",onClick:G=>{G.stopPropagation(),Be({screenshot:a.screenshot,elementRect:a.elementRect,description:a.description,step:K})},title:"View screenshot",children:e.jsx("img",{src:a.screenshot,alt:"",className:"w-full h-full object-cover"})}):e.jsx("div",{className:"flex-shrink-0 w-9 h-7 rounded bg-surface-2 border border-white/5 flex items-center justify-center",children:e.jsx(Ur,{type:a.actionType})}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[e.jsx("div",{className:"flex-shrink-0 w-6 h-6 rounded flex items-center justify-center",children:e.jsx(Ur,{type:a.actionType,size:16})}),Q&&e.jsx("span",{className:`flex-shrink-0 text-[9px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded ${a.actionType==="annotate"?"text-violet-400 bg-violet-500/10":a.actionType==="assert"?"text-green-400 bg-green-500/10":a.actionType==="custom"?"text-indigo-600 dark:text-indigo-300 bg-indigo-500/10":"text-purple-400 bg-purple-500/10"}`,children:a.actionType}),e.jsx("span",{className:"text-sm text-gray-200 truncate",title:_?a.instruction:void 0,children:_&&a.instruction||a.description}),_&&!!((f=a.references)!=null&&f.length)&&e.jsxs("span",{className:"flex-shrink-0 inline-flex items-center gap-1 text-[10px] text-gray-500",title:a.references.map(G=>G.label).join(`
37
- `),children:[e.jsx($r,{kind:a.references[0].kind,size:11}),a.references.length>1?`${a.references.length} refs`:a.references[0].label]}),_&&((M=a.outputs)==null?void 0:M.map(G=>e.jsx("span",{className:"flex-shrink-0 px-1.5 py-0.5 rounded bg-indigo-500/10 text-[10px] font-mono text-indigo-700 dark:text-indigo-300",title:"A value this step saves for later steps",children:`→ {${G}}`},G))),_&&!!((c=a.replaces)!=null&&c.length)&&e.jsxs("span",{className:"flex-shrink-0 text-[10px] text-gray-500",title:a.replaces.map(G=>G.description).join(`
38
- `),children:["replaces ",a.replaces.length," step",a.replaces.length===1?"":"s"]}),a.valueFrom&&e.jsx("span",{className:"flex-shrink-0 px-1.5 py-0.5 rounded bg-teal-500/10 text-[10px] font-mono text-teal-700 dark:text-teal-300",title:"This step uses a value instead of what was typed while recording",children:`uses {${a.valueFrom}}`})]}),sr===a.id&&e.jsxs("div",{className:"flex-shrink-0 flex items-center gap-1 px-2 py-0.5 rounded-full bg-blue-500/15 border border-blue-500/25 animate-pulse",children:[e.jsx(Qs,{size:10,className:"text-blue-400"}),e.jsx("span",{className:"text-[10px] text-blue-400 font-medium",children:"Pick..."})]}),(p==="recording"||p==="stopped")&&e.jsxs("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 focus-within:opacity-100 transition-opacity",draggable:!1,onMouseDown:G=>G.stopPropagation(),onDragStart:G=>{G.preventDefault(),G.stopPropagation()},children:[_&&e.jsx("button",{onClick:G=>{G.stopPropagation(),Dt({mode:"edit",editId:a.id,initial:{instruction:a.instruction||a.description,customKind:a.customKind,references:a.references,outputs:a.outputs}})},title:"Edit custom step","aria-label":"Edit custom step",className:"p-1.5 rounded text-gray-500 hover:text-indigo-500 hover:bg-black/[0.06] dark:hover:bg-white/10 transition-colors",children:e.jsx(jo,{size:14})}),_&&!!((z=a.replaces)!=null&&z.length)&&p==="stopped"&&e.jsx("button",{onClick:G=>{G.stopPropagation(),ur(a.id)},title:`Put the ${a.replaces.length} replaced step${a.replaces.length===1?"":"s"} back`,"aria-label":"Put the replaced steps back",className:"p-1.5 rounded text-gray-500 hover:text-amber-500 hover:bg-black/[0.06] dark:hover:bg-white/10 transition-colors",children:e.jsx(Gn,{size:14})}),mt&&e.jsx(ea,{current:a.valueFrom,options:xr.get(a.id)||[],onPick:G=>vs(a.id,G)}),a.actionType!=="annotate"&&!_&&e.jsx("button",{onClick:G=>{G.stopPropagation(),Mr(a.id)},disabled:!!sr,title:"Re-inspect element","aria-label":"Re-inspect element",className:"p-1.5 rounded text-gray-500 hover:text-blue-500 dark:hover:text-blue-400 hover:bg-black/[0.06] dark:hover:bg-white/10 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:e.jsx(Qs,{size:14})}),e.jsx("button",{onClick:G=>{G.stopPropagation(),lr(a.id)},title:"Remove step","aria-label":"Remove step",className:"p-1.5 rounded text-gray-500 hover:text-red-500 dark:hover:text-red-400 hover:bg-red-500/10 transition-colors",children:e.jsx(Es,{size:14})})]})]}),p==="stopped"&&e.jsx(En,{label:`Insert a custom step after step ${K}`,onInsert:()=>Dt({mode:"add",afterId:a.id})})]},a.id)}if(a.kind==="system")return 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:a.text})]},a.id);if(a.kind==="text")return 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:a.text})})},a.id);if(a.kind==="playback-action"){const K=a.status==="running"?e.jsx(ve,{size:11,className:"animate-spin text-cyan-400"}):a.status==="done"?e.jsx(ft,{size:11,className:"text-emerald-400"}):a.status==="error"?e.jsx(Ms,{size:11,className:"text-red-400"}):e.jsx(Qt,{size:11,className:"text-gray-500"});return e.jsxs("div",{className:"flex items-center gap-2 px-4 py-1",children:[K,e.jsx("div",{className:"w-5 h-5 rounded-md bg-cyan-500/10 flex items-center justify-center flex-shrink-0 border border-cyan-500/20",children:e.jsx(Ur,{type:a.actionType})}),e.jsx("span",{className:"text-xs text-gray-400",children:a.description}),a.status==="error"&&e.jsx("span",{className:"text-[10px] text-red-400 ml-auto",children:"failed"})]},a.id)}return a.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 break-words",children:a.text})},a.id):a.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:a.text})]},a.id):null})})]}),p==="stopped"&&e.jsxs("div",{className:"flex-shrink-0 px-4 py-3 border-t border-white/5 bg-surface-1 space-y-3",children:[vt.size>0&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-indigo-500/10 border border-indigo-500/25",children:[e.jsxs("span",{className:"text-xs text-gray-300 flex-1",children:[vt.size," step",vt.size===1?"":"s"," selected"]}),e.jsxs("button",{onClick:()=>Dt({mode:"replace"}),className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium bg-indigo-600 hover:bg-indigo-500 text-white",children:[e.jsx(Ht,{size:12})," Replace with custom step"]}),e.jsx("button",{onClick:()=>Kt(new Set),className:"px-2 py-1 rounded-md text-xs text-gray-400 hover:text-gray-200",children:"Clear"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex gap-1 p-0.5 bg-surface-2 rounded-lg",children:[e.jsx("button",{"aria-pressed":!U,onClick:()=>{oe(!1),Y(""),Z(""),W("")},className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${U?"text-gray-500 hover:text-gray-300":"bg-brand-500/15 text-brand-300 shadow-sm"}`,children:"New Test"}),e.jsx("button",{"aria-pressed":U,onClick:()=>oe(!0),className:`flex-1 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${U?"bg-indigo-500/15 text-indigo-300 shadow-sm":"text-gray-500 hover:text-gray-300"}`,children:"Add to Existing Test"})]}),U&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-gray-500 uppercase tracking-wider mb-1 block",children:"Insert Position"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("label",{className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs cursor-pointer transition-colors focus-within:ring-2 focus-within:ring-indigo-500/40 ${B==="auto"?"bg-indigo-500/15 text-indigo-300 border border-indigo-500/20":"bg-surface-2 text-gray-400 border border-white/5"}`,children:[e.jsx("input",{type:"radio",name:"insertPos",value:"auto",checked:B==="auto",onChange:()=>ee("auto"),className:"sr-only"}),"Guide AI"]}),e.jsxs("label",{className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs cursor-pointer transition-colors focus-within:ring-2 focus-within:ring-indigo-500/40 ${B==="append"?"bg-indigo-500/15 text-indigo-300 border border-indigo-500/20":"bg-surface-2 text-gray-400 border border-white/5"}`,children:[e.jsx("input",{type:"radio",name:"insertPos",value:"append",checked:B==="append",onChange:()=>ee("append"),className:"sr-only"}),"Append At End"]})]})]}),!U&&e.jsxs("div",{children:[e.jsxs("label",{className:"text-[10px] text-gray-500 uppercase tracking-wider mb-1 block",children:["Test Name ",e.jsx("span",{className:"text-red-400",children:"*"})]}),e.jsx("input",{type:"text",value:D,onChange:r=>V(r.target.value),placeholder:"Test name (e.g. login-flow-test)",className:"w-full px-3 py-2 rounded-lg bg-surface-2 border border-white/5 text-xs text-gray-200 placeholder-gray-600 focus:outline-none focus:border-brand-500/40"}),Rr(D)&&e.jsx("p",{className:"mt-1 text-[11px] text-amber-600 dark:text-amber-400/90",children:Rr(D)})]}),U&&e.jsxs("div",{className:"space-y-2 p-3 rounded-lg bg-indigo-500/5 border border-indigo-500/15",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"text-[10px] text-gray-500 uppercase tracking-wider mb-1 block",children:["Target Test ",e.jsx("span",{className:"text-red-400",children:"*"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:()=>ie(!J),"aria-haspopup":"listbox","aria-expanded":J,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:g?e.jsxs("div",{title:g,children:[e.jsx("span",{className:"text-gray-800 dark:text-gray-200",children:Rs(g)}),e.jsx("span",{className:"text-[10px] text-gray-500 block mt-0.5 truncate",children:P})]}):e.jsx("span",{className:"text-gray-400 dark:text-gray-600",children:"Select a test..."})}),J&&(N==null?void 0:N.suites)&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>ie(!1)}),e.jsxs("div",{className:"absolute bottom-full left-0 w-full bg-surface-1 border border-white/10 rounded-lg shadow-xl z-40 overflow-hidden",onKeyDown:r=>{r.key==="Escape"&&(r.stopPropagation(),ie(!1))},children:[e.jsx("div",{className:"px-2 py-2 border-b border-white/5",children:e.jsx("input",{type:"text",value:se,onChange:r=>ue(r.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.jsx("div",{className:"max-h-52 overflow-y-auto",children:N.suites.filter(r=>{const a=se.toLowerCase();return a?Yt(r.name,a)||r.file.toLowerCase().includes(a)||r.tests.some(x=>Yt(x.name,a)):!0}).map(r=>{const a=r.file,x=se.toLowerCase(),f=y.has(a)||!!x,M=x?r.tests.filter(c=>Yt(c.name,x)||Yt(r.name,x)):r.tests;return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>R(c=>{const z=new Set(c);return z.has(a)?z.delete(a):z.add(a),z}),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 ${f?"":"-rotate-90"}`}),e.jsx("span",{className:"text-gray-300 font-medium truncate",title:r.name,children:Rs(r.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:r.tests.length})]}),f&&M.map((c,z)=>e.jsx("button",{onClick:()=>{Y(r.file),Z(c.name),ie(!1),ue("")},className:`w-full text-left pl-8 pr-3 py-1.5 text-xs transition-colors ${P===r.file&&g===c.name?"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:c.name,children:Rs(c.name)})},z))]},a)})})]})]})]})]}),B==="auto"&&e.jsxs("div",{children:[e.jsxs("label",{className:"text-[10px] text-gray-500 uppercase tracking-wider mb-1 block",children:["Guide AI ",e.jsx("span",{className:"text-red-400",children:"*"}),g?e.jsx("span",{className:"normal-case text-gray-600 ml-1",children:"(type @ to reference test steps)"}):e.jsx("span",{className:"normal-case text-gray-600 ml-1",children:"— select a test first"})]}),g?e.jsxs("div",{className:"relative",children:[e.jsx("textarea",{ref:cs,value:v,onChange:r=>{W(r.target.value);const a=r.target;a.style.height="auto",a.style.height=`${a.scrollHeight}px`},onKeyUp:r=>{const a=r.currentTarget,x=a.value,f=a.selectionStart??x.length,M=x.slice(0,f),c=M.lastIndexOf("@");if(c>=0&&(c===0||M[c-1]===" "||M[c-1]===`
39
- `)){const z=M.slice(c+1);if(!z.includes("]")){sn(z.toLowerCase()),Ie(!0);return}}Ie(!1)},onKeyDown:r=>{r.key==="Escape"&&pe&&(r.preventDefault(),Ie(!1))},placeholder:"e.g., Insert after @Given I am on the homepage and add cart validation...",rows:1,className:"w-full px-3 py-2 rounded-lg bg-surface-2 border border-white/10 text-xs text-gray-200 placeholder-gray-600 focus:outline-none focus:border-indigo-500/40 resize-none overflow-hidden",style:{minHeight:"32px",maxHeight:"52px",overflowY:v.split(`
40
- `).length>2||v.length>100?"auto":"hidden"}}),pe&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>Ie(!1)}),e.jsxs("div",{className:"absolute bottom-full left-0 w-full max-h-44 overflow-y-auto bg-surface-1 border border-indigo-500/20 rounded-lg shadow-xl z-40 py-1",children:[he.filter(r=>!Xt||r.keyword.toLowerCase().includes(Xt)||r.name.toLowerCase().includes(Xt)).map((r,a)=>e.jsxs("button",{onClick:()=>{const x=cs.current;if(!x)return;const f=x.selectionStart||0,M=v.slice(0,f),c=M.lastIndexOf("@"),z=v.slice(f),K=`@[${r.keyword} ${r.name}]`,ne=M.slice(0,c)+K+" "+z;W(ne),Ie(!1),setTimeout(()=>{x.focus();const Q=c+K.length+1;x.setSelectionRange(Q,Q)},50)},className:"w-full text-left px-3 py-1.5 text-xs transition-colors hover:bg-indigo-500/10 flex items-center gap-2",children:[e.jsx("span",{className:"text-indigo-400 font-semibold flex-shrink-0 w-14 text-right",children:r.keyword}),e.jsx("span",{className:"text-gray-300 truncate",children:r.name})]},a)),ds&&e.jsx("div",{className:"px-3 py-2 text-xs text-gray-500 text-center",children:"Loading steps..."}),!ds&&he.length===0&&e.jsx("div",{className:"px-3 py-2 text-xs text-gray-600 text-center",children:"No steps found for this test"}),!ds&&he.length>0&&he.filter(r=>!Xt||r.keyword.toLowerCase().includes(Xt)||r.name.toLowerCase().includes(Xt)).length===0&&e.jsx("div",{className:"px-3 py-2 text-xs text-gray-600 text-center",children:"No matching steps"})]})]})]}):e.jsx("div",{className:"w-full px-3 py-3 rounded-lg bg-surface-2/50 border border-white/5 text-xs text-gray-600 text-center",children:"Select a test above to enable AI guidance with step references"})]})]})]}),e.jsx(ta,{settings:Ve,onChange:qt,inputs:E.filter(r=>r.kind==="recorded-action"&&$n.has(r.actionType)&&!r.secretEnv).map(r=>({id:r.id,value:r.actionType==="navigate"?r.url:r.value,valueFrom:r.valueFrom})),onMatch:r=>{for(const a of r)vs(a.id,a.valueFrom)},disabled:Te}),e.jsxs("div",{className:"flex gap-2",children:[di,tt==="testver"&&e.jsx(Vr,{refreshSignal:Te,align:"left"}),e.jsx(Yr,{providerModels:ae,selectedProvider:tt,selectedModel:ye,onPick:ce}),e.jsxs("button",{onClick:Us,disabled:Te||Ge===0||!U&&!D.trim()||U&&(!P||!g)||U&&B==="auto"&&!v.trim(),className:`flex-1 flex items-center justify-center gap-2 px-4 py-2.5 rounded-lg text-sm font-semibold transition-colors disabled:opacity-50 ${U?"bg-indigo-500/20 text-indigo-300 border border-indigo-500/30 hover:bg-indigo-500/30":"bg-brand-500/20 text-brand-300 border border-brand-500/30 hover:bg-brand-500/30"}`,children:[Te?e.jsx(ve,{size:14,className:"animate-spin"}):e.jsx(Js,{size:14}),U?"Merge & Generate":"Generate Test Code"]})]})]}),p==="playback"&&It>0&&e.jsx("div",{className:"flex-shrink-0 px-4 py-2 border-t border-white/5 bg-surface-1",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ve,{size:12,className:"animate-spin text-cyan-400"}),e.jsx("div",{className:"flex-1",children:e.jsx("div",{className:"h-1.5 bg-surface-2 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-cyan-500 rounded-full transition-all duration-300",style:{width:`${xt/It*100}%`}})})}),e.jsxs("span",{className:"text-[10px] text-gray-500 font-mono",children:[xt,"/",It]})]})}),st&&e.jsx("div",{className:"sticky bottom-[92px] z-20 px-4 pointer-events-none",children:e.jsx("div",{className:"pointer-events-auto",children:e.jsx(Wr,{pending:st,queuedCount:Ot.current.length,onAllow:()=>Gs(!0,!1),onAlwaysAllow:()=>Gs(!0,!0),onDeny:()=>Gs(!1,!1)})})}),(p==="done"||p==="generating")&&e.jsxs("div",{className:"sticky bottom-0 border-t border-white/10 bg-surface-1 px-4 py-3 mt-2",children:[Te&&e.jsx("div",{className:"flex items-center pl-1 pb-3",children:e.jsx(Wn,{})}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0 pb-0.5",children:[tt==="testver"&&e.jsx(Vr,{refreshSignal:Te,align:"left"}),e.jsx(Yr,{providerModels:ae,selectedProvider:tt,selectedModel:ye,onPick:ce,disabled:Te,size:"sm",title:"Select model for follow-up generation"})]}),e.jsxs("div",{className:"flex-1 flex items-end gap-2 rounded-lg bg-white border border-gray-300 pr-2 focus-within:border-brand-500/60 transition-colors",children:[e.jsx("textarea",{value:re,onChange:r=>{$e(r.target.value);const a=r.target;a.style.height="auto",a.style.height=`${Math.min(a.scrollHeight,120)}px`},onKeyDown:r=>{r.key==="Enter"&&!r.shiftKey&&(r.preventDefault(),!Te&&(re.trim()||$)&&qs())},"aria-label":"Message to the AI",placeholder:Te?"AI is working... click stop to cancel":$?"Review the analysis above. Press Enter to proceed or type feedback...":"Request changes to the generated code...",rows:1,disabled:Te,className:"flex-1 px-3 py-2 bg-transparent text-sm text-gray-800 placeholder-gray-400 focus:outline-none resize-none overflow-hidden disabled:opacity-50 leading-5",style:{minHeight:"36px",maxHeight:"120px"}}),e.jsx("div",{className:"flex-shrink-0 pb-1.5",children:Te?e.jsx("button",{onClick:Os,title:"Stop generation","aria-label":"Stop generation",className:"flex items-center justify-center w-6 h-6 rounded-full bg-gray-400 hover:bg-gray-500 transition-colors",children:e.jsx(at,{size:10,className:"fill-gray-900 text-gray-900",strokeWidth:0})}):e.jsx("button",{onClick:qs,"aria-label":$&&!re.trim()?"Proceed":"Send",title:$&&!re.trim()?"Proceed":"Send",disabled:!re.trim()&&!$,className:"flex items-center justify-center w-7 h-7 rounded-md text-brand-400 hover:bg-brand-500/15 transition-colors disabled:opacity-30 disabled:cursor-not-allowed",children:e.jsx(Ys,{size:14})})})]})]}),e.jsx("p",{className:"text-[10px] text-gray-600 mt-1.5",children:Te?"Click the stop button to cancel the current generation":$?"Press Enter to proceed with code generation · Or type feedback to modify the approach":"Press Enter to send · Shift+Enter for new line · AI has full context of the previous generation"})]})]})," ",es&&e.jsx("div",{className:"absolute left-0 top-[49px] bottom-0 w-[280px] z-[30] bg-white dark:bg-surface-1 border-r border-gray-200 dark:border-white/10 shadow-xl overflow-y-auto",children:e.jsx(Oo,{onLoadSession:ys,onClose:()=>ts(!1),activeSessionId:At})}),e.jsx(Zn,{open:!!ot,mode:(ot==null?void 0:ot.mode)||"add",initial:ot==null?void 0:ot.initial,replaceCount:vt.size,onCancel:()=>Ae(null),onSave:dr}),xe&&e.jsxs("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/70 backdrop-blur-sm",onClick:()=>Be(null)}),e.jsxs("div",{role:"dialog","aria-modal":"true","aria-label":`Step ${xe.step} screenshot`,className:"relative z-10 bg-surface-1 rounded-xl border border-white/10 shadow-2xl max-w-[90vw] max-h-[90vh] overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-white/5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"w-7 h-7 rounded-full bg-brand-500/15 flex items-center justify-center text-xs font-bold text-brand-400",children:xe.step}),e.jsx("span",{className:"text-sm text-gray-200",children:xe.description})]}),e.jsx("button",{ref:Ds,onClick:()=>Be(null),"aria-label":"Close screenshot",className:"text-gray-400 hover:text-gray-200 p-1",children:e.jsx(gt,{size:18})})]}),e.jsx("div",{className:"flex-1 overflow-auto p-4 flex items-center justify-center bg-black/20",children:e.jsxs("div",{className:"relative inline-block rounded-lg overflow-hidden border border-white/10",children:[e.jsx("img",{src:xe.screenshot,alt:"Element screenshot",className:"block max-w-full max-h-[75vh]",onLoad:r=>Ut({src:xe.screenshot,w:r.currentTarget.naturalWidth,h:r.currentTarget.naturalHeight})}),xe.elementRect&&xe.elementRect.clipW&&bi(De,xe.screenshot,xe.elementRect)&&e.jsx("div",{className:"absolute inset-0 pointer-events-none",children:e.jsx("div",{className:"absolute border-2 border-blue-400 rounded-sm",style:{left:`${xe.elementRect.x/xe.elementRect.clipW*100}%`,top:`${xe.elementRect.y/xe.elementRect.clipH*100}%`,width:`${xe.elementRect.width/xe.elementRect.clipW*100}%`,height:`${xe.elementRect.height/xe.elementRect.clipH*100}%`,backgroundColor:"transparent",boxShadow:"0 0 0 9999px rgba(0,0,0,0.35)"}})})]})})]})]})]})}function Ki(){return e.jsx("div",{className:"flex-1 flex flex-col overflow-hidden h-full",children:e.jsx(ki,{})})}export{Ki as AIRecordPanel};